PluginProbe
Gutenberg / 13.9.0
Gutenberg v13.9.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / element / index.js

index.js in Gutenberg 13.9.0, at build/element/index.js

1,698 lines 57.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/define property getters */
8 /******/ (() => {
9 /******/ // define getter functions for harmony exports
10 /******/ __webpack_require__.d = (exports, definition) => {
11 /******/ for(var key in definition) {
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14 /******/ }
15 /******/ }
16 /******/ };
17 /******/ })();
18 /******/
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */
20 /******/ (() => {
21 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22 /******/ })();
23 /******/
24 /******/ /* webpack/runtime/make namespace object */
25 /******/ (() => {
26 /******/ // define __esModule on exports
27 /******/ __webpack_require__.r = (exports) => {
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30 /******/ }
31 /******/ Object.defineProperty(exports, '__esModule', { value: true });
32 /******/ };
33 /******/ })();
34 /******/
35 /************************************************************************/
36 var __webpack_exports__ = {};
37 // ESM COMPAT FLAG
38 __webpack_require__.r(__webpack_exports__);
39
40 // EXPORTS
41 __webpack_require__.d(__webpack_exports__, {
42 "Children": () => (/* reexport */ external_React_namespaceObject.Children),
43 "Component": () => (/* reexport */ external_React_namespaceObject.Component),
44 "Fragment": () => (/* reexport */ external_React_namespaceObject.Fragment),
45 "Platform": () => (/* reexport */ platform),
46 "RawHTML": () => (/* reexport */ RawHTML),
47 "StrictMode": () => (/* reexport */ external_React_namespaceObject.StrictMode),
48 "Suspense": () => (/* reexport */ external_React_namespaceObject.Suspense),
49 "cloneElement": () => (/* reexport */ external_React_namespaceObject.cloneElement),
50 "concatChildren": () => (/* reexport */ concatChildren),
51 "createContext": () => (/* reexport */ external_React_namespaceObject.createContext),
52 "createElement": () => (/* reexport */ external_React_namespaceObject.createElement),
53 "createInterpolateElement": () => (/* reexport */ create_interpolate_element),
54 "createPortal": () => (/* reexport */ external_ReactDOM_namespaceObject.createPortal),
55 "createRef": () => (/* reexport */ external_React_namespaceObject.createRef),
56 "findDOMNode": () => (/* reexport */ external_ReactDOM_namespaceObject.findDOMNode),
57 "forwardRef": () => (/* reexport */ external_React_namespaceObject.forwardRef),
58 "hydrate": () => (/* reexport */ external_ReactDOM_namespaceObject.hydrate),
59 "isEmptyElement": () => (/* reexport */ isEmptyElement),
60 "isValidElement": () => (/* reexport */ external_React_namespaceObject.isValidElement),
61 "lazy": () => (/* reexport */ external_React_namespaceObject.lazy),
62 "memo": () => (/* reexport */ external_React_namespaceObject.memo),
63 "render": () => (/* reexport */ external_ReactDOM_namespaceObject.render),
64 "renderToString": () => (/* reexport */ serialize),
65 "switchChildrenNodeName": () => (/* reexport */ switchChildrenNodeName),
66 "unmountComponentAtNode": () => (/* reexport */ external_ReactDOM_namespaceObject.unmountComponentAtNode),
67 "useCallback": () => (/* reexport */ external_React_namespaceObject.useCallback),
68 "useContext": () => (/* reexport */ external_React_namespaceObject.useContext),
69 "useDebugValue": () => (/* reexport */ external_React_namespaceObject.useDebugValue),
70 "useEffect": () => (/* reexport */ external_React_namespaceObject.useEffect),
71 "useImperativeHandle": () => (/* reexport */ external_React_namespaceObject.useImperativeHandle),
72 "useLayoutEffect": () => (/* reexport */ external_React_namespaceObject.useLayoutEffect),
73 "useMemo": () => (/* reexport */ external_React_namespaceObject.useMemo),
74 "useReducer": () => (/* reexport */ external_React_namespaceObject.useReducer),
75 "useRef": () => (/* reexport */ external_React_namespaceObject.useRef),
76 "useState": () => (/* reexport */ external_React_namespaceObject.useState)
77 });
78
79 ;// CONCATENATED MODULE: external "React"
80 const external_React_namespaceObject = window["React"];
81 ;// CONCATENATED MODULE: ./packages/element/build-module/create-interpolate-element.js
82 /**
83 * Internal dependencies
84 */
85
86 /** @typedef {import('./react').WPElement} WPElement */
87
88 let indoc, offset, output, stack;
89 /**
90 * Matches tags in the localized string
91 *
92 * This is used for extracting the tag pattern groups for parsing the localized
93 * string and along with the map converting it to a react element.
94 *
95 * There are four references extracted using this tokenizer:
96 *
97 * match: Full match of the tag (i.e. <strong>, </strong>, <br/>)
98 * isClosing: The closing slash, if it exists.
99 * name: The name portion of the tag (strong, br) (if )
100 * isSelfClosed: The slash on a self closing tag, if it exists.
101 *
102 * @type {RegExp}
103 */
104
105 const tokenizer = /<(\/)?(\w+)\s*(\/)?>/g;
106 /**
107 * The stack frame tracking parse progress.
108 *
109 * @typedef Frame
110 *
111 * @property {WPElement} element A parent element which may still have
112 * @property {number} tokenStart Offset at which parent element first
113 * appears.
114 * @property {number} tokenLength Length of string marking start of parent
115 * element.
116 * @property {number} [prevOffset] Running offset at which parsing should
117 * continue.
118 * @property {number} [leadingTextStart] Offset at which last closing element
119 * finished, used for finding text between
120 * elements.
121 * @property {WPElement[]} children Children.
122 */
123
124 /**
125 * Tracks recursive-descent parse state.
126 *
127 * This is a Stack frame holding parent elements until all children have been
128 * parsed.
129 *
130 * @private
131 * @param {WPElement} element A parent element which may still have
132 * nested children not yet parsed.
133 * @param {number} tokenStart Offset at which parent element first
134 * appears.
135 * @param {number} tokenLength Length of string marking start of parent
136 * element.
137 * @param {number} [prevOffset] Running offset at which parsing should
138 * continue.
139 * @param {number} [leadingTextStart] Offset at which last closing element
140 * finished, used for finding text between
141 * elements.
142 *
143 * @return {Frame} The stack frame tracking parse progress.
144 */
145
146 function createFrame(element, tokenStart, tokenLength, prevOffset, leadingTextStart) {
147 return {
148 element,
149 tokenStart,
150 tokenLength,
151 prevOffset,
152 leadingTextStart,
153 children: []
154 };
155 }
156 /**
157 * This function creates an interpolated element from a passed in string with
158 * specific tags matching how the string should be converted to an element via
159 * the conversion map value.
160 *
161 * @example
162 * For example, for the given string:
163 *
164 * "This is a <span>string</span> with <a>a link</a> and a self-closing
165 * <CustomComponentB/> tag"
166 *
167 * You would have something like this as the conversionMap value:
168 *
169 * ```js
170 * {
171 * span: <span />,
172 * a: <a href={ 'https://github.com' } />,
173 * CustomComponentB: <CustomComponent />,
174 * }
175 * ```
176 *
177 * @param {string} interpolatedString The interpolation string to be parsed.
178 * @param {Object} conversionMap The map used to convert the string to
179 * a react element.
180 * @throws {TypeError}
181 * @return {WPElement} A wp element.
182 */
183
184
185 const createInterpolateElement = (interpolatedString, conversionMap) => {
186 indoc = interpolatedString;
187 offset = 0;
188 output = [];
189 stack = [];
190 tokenizer.lastIndex = 0;
191
192 if (!isValidConversionMap(conversionMap)) {
193 throw new TypeError('The conversionMap provided is not valid. It must be an object with values that are WPElements');
194 }
195
196 do {// twiddle our thumbs
197 } while (proceed(conversionMap));
198
199 return (0,external_React_namespaceObject.createElement)(external_React_namespaceObject.Fragment, null, ...output);
200 };
201 /**
202 * Validate conversion map.
203 *
204 * A map is considered valid if it's an object and every value in the object
205 * is a WPElement
206 *
207 * @private
208 *
209 * @param {Object} conversionMap The map being validated.
210 *
211 * @return {boolean} True means the map is valid.
212 */
213
214
215 const isValidConversionMap = conversionMap => {
216 const isObject = typeof conversionMap === 'object';
217 const values = isObject && Object.values(conversionMap);
218 return isObject && values.length && values.every(element => (0,external_React_namespaceObject.isValidElement)(element));
219 };
220 /**
221 * This is the iterator over the matches in the string.
222 *
223 * @private
224 *
225 * @param {Object} conversionMap The conversion map for the string.
226 *
227 * @return {boolean} true for continuing to iterate, false for finished.
228 */
229
230
231 function proceed(conversionMap) {
232 const next = nextToken();
233 const [tokenType, name, startOffset, tokenLength] = next;
234 const stackDepth = stack.length;
235 const leadingTextStart = startOffset > offset ? offset : null;
236
237 if (!conversionMap[name]) {
238 addText();
239 return false;
240 }
241
242 switch (tokenType) {
243 case 'no-more-tokens':
244 if (stackDepth !== 0) {
245 const {
246 leadingTextStart: stackLeadingText,
247 tokenStart
248 } = stack.pop();
249 output.push(indoc.substr(stackLeadingText, tokenStart));
250 }
251
252 addText();
253 return false;
254
255 case 'self-closed':
256 if (0 === stackDepth) {
257 if (null !== leadingTextStart) {
258 output.push(indoc.substr(leadingTextStart, startOffset - leadingTextStart));
259 }
260
261 output.push(conversionMap[name]);
262 offset = startOffset + tokenLength;
263 return true;
264 } // Otherwise we found an inner element.
265
266
267 addChild(createFrame(conversionMap[name], startOffset, tokenLength));
268 offset = startOffset + tokenLength;
269 return true;
270
271 case 'opener':
272 stack.push(createFrame(conversionMap[name], startOffset, tokenLength, startOffset + tokenLength, leadingTextStart));
273 offset = startOffset + tokenLength;
274 return true;
275
276 case 'closer':
277 // If we're not nesting then this is easy - close the block.
278 if (1 === stackDepth) {
279 closeOuterElement(startOffset);
280 offset = startOffset + tokenLength;
281 return true;
282 } // Otherwise we're nested and we have to close out the current
283 // block and add it as a innerBlock to the parent.
284
285
286 const stackTop = stack.pop();
287 const text = indoc.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset);
288 stackTop.children.push(text);
289 stackTop.prevOffset = startOffset + tokenLength;
290 const frame = createFrame(stackTop.element, stackTop.tokenStart, stackTop.tokenLength, startOffset + tokenLength);
291 frame.children = stackTop.children;
292 addChild(frame);
293 offset = startOffset + tokenLength;
294 return true;
295
296 default:
297 addText();
298 return false;
299 }
300 }
301 /**
302 * Grabs the next token match in the string and returns it's details.
303 *
304 * @private
305 *
306 * @return {Array} An array of details for the token matched.
307 */
308
309
310 function nextToken() {
311 const matches = tokenizer.exec(indoc); // We have no more tokens.
312
313 if (null === matches) {
314 return ['no-more-tokens'];
315 }
316
317 const startedAt = matches.index;
318 const [match, isClosing, name, isSelfClosed] = matches;
319 const length = match.length;
320
321 if (isSelfClosed) {
322 return ['self-closed', name, startedAt, length];
323 }
324
325 if (isClosing) {
326 return ['closer', name, startedAt, length];
327 }
328
329 return ['opener', name, startedAt, length];
330 }
331 /**
332 * Pushes text extracted from the indoc string to the output stack given the
333 * current rawLength value and offset (if rawLength is provided ) or the
334 * indoc.length and offset.
335 *
336 * @private
337 */
338
339
340 function addText() {
341 const length = indoc.length - offset;
342
343 if (0 === length) {
344 return;
345 }
346
347 output.push(indoc.substr(offset, length));
348 }
349 /**
350 * Pushes a child element to the associated parent element's children for the
351 * parent currently active in the stack.
352 *
353 * @private
354 *
355 * @param {Frame} frame The Frame containing the child element and it's
356 * token information.
357 */
358
359
360 function addChild(frame) {
361 const {
362 element,
363 tokenStart,
364 tokenLength,
365 prevOffset,
366 children
367 } = frame;
368 const parent = stack[stack.length - 1];
369 const text = indoc.substr(parent.prevOffset, tokenStart - parent.prevOffset);
370
371 if (text) {
372 parent.children.push(text);
373 }
374
375 parent.children.push((0,external_React_namespaceObject.cloneElement)(element, null, ...children));
376 parent.prevOffset = prevOffset ? prevOffset : tokenStart + tokenLength;
377 }
378 /**
379 * This is called for closing tags. It creates the element currently active in
380 * the stack.
381 *
382 * @private
383 *
384 * @param {number} endOffset Offset at which the closing tag for the element
385 * begins in the string. If this is greater than the
386 * prevOffset attached to the element, then this
387 * helps capture any remaining nested text nodes in
388 * the element.
389 */
390
391
392 function closeOuterElement(endOffset) {
393 const {
394 element,
395 leadingTextStart,
396 prevOffset,
397 tokenStart,
398 children
399 } = stack.pop();
400 const text = endOffset ? indoc.substr(prevOffset, endOffset - prevOffset) : indoc.substr(prevOffset);
401
402 if (text) {
403 children.push(text);
404 }
405
406 if (null !== leadingTextStart) {
407 output.push(indoc.substr(leadingTextStart, tokenStart - leadingTextStart));
408 }
409
410 output.push((0,external_React_namespaceObject.cloneElement)(element, null, ...children));
411 }
412
413 /* harmony default export */ const create_interpolate_element = (createInterpolateElement);
414
415 ;// CONCATENATED MODULE: ./packages/element/build-module/react.js
416 /**
417 * External dependencies
418 */
419 // eslint-disable-next-line @typescript-eslint/no-restricted-imports
420
421 /**
422 * Object containing a React element.
423 *
424 * @typedef {import('react').ReactElement} WPElement
425 */
426
427 /**
428 * Object containing a React component.
429 *
430 * @typedef {import('react').ComponentType} WPComponent
431 */
432
433 /**
434 * Object containing a React synthetic event.
435 *
436 * @typedef {import('react').SyntheticEvent} WPSyntheticEvent
437 */
438
439 /**
440 * Object that provides utilities for dealing with React children.
441 */
442
443
444 /**
445 * Creates a copy of an element with extended props.
446 *
447 * @param {WPElement} element Element
448 * @param {?Object} props Props to apply to cloned element
449 *
450 * @return {WPElement} Cloned element.
451 */
452
453
454 /**
455 * A base class to create WordPress Components (Refs, state and lifecycle hooks)
456 */
457
458
459 /**
460 * Creates a context object containing two components: a provider and consumer.
461 *
462 * @param {Object} defaultValue A default data stored in the context.
463 *
464 * @return {Object} Context object.
465 */
466
467
468 /**
469 * Returns a new element of given type. Type can be either a string tag name or
470 * another function which itself returns an element.
471 *
472 * @param {?(string|Function)} type Tag name or element creator
473 * @param {Object} props Element properties, either attribute
474 * set to apply to DOM node or values to
475 * pass through to element creator
476 * @param {...WPElement} children Descendant elements
477 *
478 * @return {WPElement} Element.
479 */
480
481
482 /**
483 * Returns an object tracking a reference to a rendered element via its
484 * `current` property as either a DOMElement or Element, dependent upon the
485 * type of element rendered with the ref attribute.
486 *
487 * @return {Object} Ref object.
488 */
489
490
491 /**
492 * Component enhancer used to enable passing a ref to its wrapped component.
493 * Pass a function argument which receives `props` and `ref` as its arguments,
494 * returning an element using the forwarded ref. The return value is a new
495 * component which forwards its ref.
496 *
497 * @param {Function} forwarder Function passed `props` and `ref`, expected to
498 * return an element.
499 *
500 * @return {WPComponent} Enhanced component.
501 */
502
503
504 /**
505 * A component which renders its children without any wrapping element.
506 */
507
508
509 /**
510 * Checks if an object is a valid WPElement.
511 *
512 * @param {Object} objectToCheck The object to be checked.
513 *
514 * @return {boolean} true if objectToTest is a valid WPElement and false otherwise.
515 */
516
517
518 /**
519 * @see https://reactjs.org/docs/react-api.html#reactmemo
520 */
521
522
523 /**
524 * Component that activates additional checks and warnings for its descendants.
525 */
526
527
528 /**
529 * @see https://reactjs.org/docs/hooks-reference.html#usecallback
530 */
531
532
533 /**
534 * @see https://reactjs.org/docs/hooks-reference.html#usecontext
535 */
536
537
538 /**
539 * @see https://reactjs.org/docs/hooks-reference.html#usedebugvalue
540 */
541
542
543 /**
544 * @see https://reactjs.org/docs/hooks-reference.html#useeffect
545 */
546
547
548 /**
549 * @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle
550 */
551
552
553 /**
554 * @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect
555 */
556
557
558 /**
559 * @see https://reactjs.org/docs/hooks-reference.html#usememo
560 */
561
562
563 /**
564 * @see https://reactjs.org/docs/hooks-reference.html#usereducer
565 */
566
567
568 /**
569 * @see https://reactjs.org/docs/hooks-reference.html#useref
570 */
571
572
573 /**
574 * @see https://reactjs.org/docs/hooks-reference.html#usestate
575 */
576
577
578 /**
579 * @see https://reactjs.org/docs/react-api.html#reactlazy
580 */
581
582
583 /**
584 * @see https://reactjs.org/docs/react-api.html#reactsuspense
585 */
586
587
588 /**
589 * Concatenate two or more React children objects.
590 *
591 * @param {...?Object} childrenArguments Array of children arguments (array of arrays/strings/objects) to concatenate.
592 *
593 * @return {Array} The concatenated value.
594 */
595
596 function concatChildren() {
597 for (var _len = arguments.length, childrenArguments = new Array(_len), _key = 0; _key < _len; _key++) {
598 childrenArguments[_key] = arguments[_key];
599 }
600
601 return childrenArguments.reduce((accumulator, children, i) => {
602 external_React_namespaceObject.Children.forEach(children, (child, j) => {
603 if (child && 'string' !== typeof child) {
604 child = (0,external_React_namespaceObject.cloneElement)(child, {
605 key: [i, j].join()
606 });
607 }
608
609 accumulator.push(child);
610 });
611 return accumulator;
612 }, []);
613 }
614 /**
615 * Switches the nodeName of all the elements in the children object.
616 *
617 * @param {?Object} children Children object.
618 * @param {string} nodeName Node name.
619 *
620 * @return {?Object} The updated children object.
621 */
622
623 function switchChildrenNodeName(children, nodeName) {
624 return children && external_React_namespaceObject.Children.map(children, (elt, index) => {
625 if (typeof (elt === null || elt === void 0 ? void 0 : elt.valueOf()) === 'string') {
626 return (0,external_React_namespaceObject.createElement)(nodeName, {
627 key: index
628 }, elt);
629 }
630
631 const {
632 children: childrenProp,
633 ...props
634 } = elt.props;
635 return (0,external_React_namespaceObject.createElement)(nodeName, {
636 key: index,
637 ...props
638 }, childrenProp);
639 });
640 }
641
642 ;// CONCATENATED MODULE: external "ReactDOM"
643 const external_ReactDOM_namespaceObject = window["ReactDOM"];
644 ;// CONCATENATED MODULE: ./packages/element/build-module/react-platform.js
645 /**
646 * External dependencies
647 */
648
649 /**
650 * Creates a portal into which a component can be rendered.
651 *
652 * @see https://github.com/facebook/react/issues/10309#issuecomment-318433235
653 *
654 * @param {import('./react').WPElement} child Any renderable child, such as an element,
655 * string, or fragment.
656 * @param {HTMLElement} container DOM node into which element should be rendered.
657 */
658
659
660 /**
661 * Finds the dom node of a React component.
662 *
663 * @param {import('./react').WPComponent} component Component's instance.
664 */
665
666
667 /**
668 * Renders a given element into the target DOM node.
669 *
670 * @param {import('./react').WPElement} element Element to render.
671 * @param {HTMLElement} target DOM node into which element should be rendered.
672 */
673
674
675 /**
676 * Hydrates a given element into the target DOM node.
677 *
678 * @param {import('./react').WPElement} element Element to hydrate.
679 * @param {HTMLElement} target DOM node into which element should be hydrated.
680 */
681
682
683 /**
684 * Removes any mounted element from the target DOM node.
685 *
686 * @param {Element} target DOM node in which element is to be removed
687 */
688
689
690
691 ;// CONCATENATED MODULE: ./packages/element/build-module/utils.js
692 /**
693 * Checks if the provided WP element is empty.
694 *
695 * @param {*} element WP element to check.
696 * @return {boolean} True when an element is considered empty.
697 */
698 const isEmptyElement = element => {
699 if (typeof element === 'number') {
700 return false;
701 }
702
703 if (typeof (element === null || element === void 0 ? void 0 : element.valueOf()) === 'string' || Array.isArray(element)) {
704 return !element.length;
705 }
706
707 return !element;
708 };
709
710 ;// CONCATENATED MODULE: ./packages/element/build-module/platform.js
711 /**
712 * Parts of this source were derived and modified from react-native-web,
713 * released under the MIT license.
714 *
715 * Copyright (c) 2016-present, Nicolas Gallagher.
716 * Copyright (c) 2015-present, Facebook, Inc.
717 *
718 */
719 const Platform = {
720 OS: 'web',
721 select: spec => 'web' in spec ? spec.web : spec.default,
722 isWeb: true
723 };
724 /**
725 * Component used to detect the current Platform being used.
726 * Use Platform.OS === 'web' to detect if running on web enviroment.
727 *
728 * This is the same concept as the React Native implementation.
729 *
730 * @see https://facebook.github.io/react-native/docs/platform-specific-code#platform-module
731 *
732 * Here is an example of how to use the select method:
733 * @example
734 * ```js
735 * import { Platform } from '@wordpress/element';
736 *
737 * const placeholderLabel = Platform.select( {
738 * native: __( 'Add media' ),
739 * web: __( 'Drag images, upload new ones or select files from your library.' ),
740 * } );
741 * ```
742 */
743
744 /* harmony default export */ const platform = (Platform);
745
746 ;// CONCATENATED MODULE: ./node_modules/is-plain-obj/index.js
747 function isPlainObject(value) {
748 if (typeof value !== 'object' || value === null) {
749 return false;
750 }
751
752 const prototype = Object.getPrototypeOf(value);
753 return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
754 }
755
756 ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.js
757 /*! *****************************************************************************
758 Copyright (c) Microsoft Corporation.
759
760 Permission to use, copy, modify, and/or distribute this software for any
761 purpose with or without fee is hereby granted.
762
763 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
764 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
765 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
766 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
767 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
768 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
769 PERFORMANCE OF THIS SOFTWARE.
770 ***************************************************************************** */
771 /* global Reflect, Promise */
772
773 var extendStatics = function(d, b) {
774 extendStatics = Object.setPrototypeOf ||
775 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
776 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
777 return extendStatics(d, b);
778 };
779
780 function __extends(d, b) {
781 if (typeof b !== "function" && b !== null)
782 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
783 extendStatics(d, b);
784 function __() { this.constructor = d; }
785 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
786 }
787
788 var __assign = function() {
789 __assign = Object.assign || function __assign(t) {
790 for (var s, i = 1, n = arguments.length; i < n; i++) {
791 s = arguments[i];
792 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
793 }
794 return t;
795 }
796 return __assign.apply(this, arguments);
797 }
798
799 function __rest(s, e) {
800 var t = {};
801 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
802 t[p] = s[p];
803 if (s != null && typeof Object.getOwnPropertySymbols === "function")
804 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
805 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
806 t[p[i]] = s[p[i]];
807 }
808 return t;
809 }
810
811 function __decorate(decorators, target, key, desc) {
812 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
813 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
814 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
815 return c > 3 && r && Object.defineProperty(target, key, r), r;
816 }
817
818 function __param(paramIndex, decorator) {
819 return function (target, key) { decorator(target, key, paramIndex); }
820 }
821
822 function __metadata(metadataKey, metadataValue) {
823 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
824 }
825
826 function __awaiter(thisArg, _arguments, P, generator) {
827 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
828 return new (P || (P = Promise))(function (resolve, reject) {
829 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
830 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
831 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
832 step((generator = generator.apply(thisArg, _arguments || [])).next());
833 });
834 }
835
836 function __generator(thisArg, body) {
837 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
838 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
839 function verb(n) { return function (v) { return step([n, v]); }; }
840 function step(op) {
841 if (f) throw new TypeError("Generator is already executing.");
842 while (_) try {
843 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
844 if (y = 0, t) op = [op[0] & 2, t.value];
845 switch (op[0]) {
846 case 0: case 1: t = op; break;
847 case 4: _.label++; return { value: op[1], done: false };
848 case 5: _.label++; y = op[1]; op = [0]; continue;
849 case 7: op = _.ops.pop(); _.trys.pop(); continue;
850 default:
851 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
852 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
853 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
854 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
855 if (t[2]) _.ops.pop();
856 _.trys.pop(); continue;
857 }
858 op = body.call(thisArg, _);
859 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
860 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
861 }
862 }
863
864 var __createBinding = Object.create ? (function(o, m, k, k2) {
865 if (k2 === undefined) k2 = k;
866 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
867 }) : (function(o, m, k, k2) {
868 if (k2 === undefined) k2 = k;
869 o[k2] = m[k];
870 });
871
872 function __exportStar(m, o) {
873 for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
874 }
875
876 function __values(o) {
877 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
878 if (m) return m.call(o);
879 if (o && typeof o.length === "number") return {
880 next: function () {
881 if (o && i >= o.length) o = void 0;
882 return { value: o && o[i++], done: !o };
883 }
884 };
885 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
886 }
887
888 function __read(o, n) {
889 var m = typeof Symbol === "function" && o[Symbol.iterator];
890 if (!m) return o;
891 var i = m.call(o), r, ar = [], e;
892 try {
893 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
894 }
895 catch (error) { e = { error: error }; }
896 finally {
897 try {
898 if (r && !r.done && (m = i["return"])) m.call(i);
899 }
900 finally { if (e) throw e.error; }
901 }
902 return ar;
903 }
904
905 /** @deprecated */
906 function __spread() {
907 for (var ar = [], i = 0; i < arguments.length; i++)
908 ar = ar.concat(__read(arguments[i]));
909 return ar;
910 }
911
912 /** @deprecated */
913 function __spreadArrays() {
914 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
915 for (var r = Array(s), k = 0, i = 0; i < il; i++)
916 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
917 r[k] = a[j];
918 return r;
919 }
920
921 function __spreadArray(to, from, pack) {
922 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
923 if (ar || !(i in from)) {
924 if (!ar) ar = Array.prototype.slice.call(from, 0, i);
925 ar[i] = from[i];
926 }
927 }
928 return to.concat(ar || from);
929 }
930
931 function __await(v) {
932 return this instanceof __await ? (this.v = v, this) : new __await(v);
933 }
934
935 function __asyncGenerator(thisArg, _arguments, generator) {
936 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
937 var g = generator.apply(thisArg, _arguments || []), i, q = [];
938 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
939 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
940 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
941 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
942 function fulfill(value) { resume("next", value); }
943 function reject(value) { resume("throw", value); }
944 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
945 }
946
947 function __asyncDelegator(o) {
948 var i, p;
949 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
950 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
951 }
952
953 function __asyncValues(o) {
954 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
955 var m = o[Symbol.asyncIterator], i;
956 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
957 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
958 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
959 }
960
961 function __makeTemplateObject(cooked, raw) {
962 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
963 return cooked;
964 };
965
966 var __setModuleDefault = Object.create ? (function(o, v) {
967 Object.defineProperty(o, "default", { enumerable: true, value: v });
968 }) : function(o, v) {
969 o["default"] = v;
970 };
971
972 function __importStar(mod) {
973 if (mod && mod.__esModule) return mod;
974 var result = {};
975 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
976 __setModuleDefault(result, mod);
977 return result;
978 }
979
980 function __importDefault(mod) {
981 return (mod && mod.__esModule) ? mod : { default: mod };
982 }
983
984 function __classPrivateFieldGet(receiver, state, kind, f) {
985 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
986 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
987 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
988 }
989
990 function __classPrivateFieldSet(receiver, state, value, kind, f) {
991 if (kind === "m") throw new TypeError("Private method is not writable");
992 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
993 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
994 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
995 }
996
997 ;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js
998 /**
999 * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
1000 */
1001 var SUPPORTED_LOCALE = {
1002 tr: {
1003 regexp: /\u0130|\u0049|\u0049\u0307/g,
1004 map: {
1005 İ: "\u0069",
1006 I: "\u0131",
1007 : "\u0069",
1008 },
1009 },
1010 az: {
1011 regexp: /\u0130/g,
1012 map: {
1013 İ: "\u0069",
1014 I: "\u0131",
1015 : "\u0069",
1016 },
1017 },
1018 lt: {
1019 regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
1020 map: {
1021 I: "\u0069\u0307",
1022 J: "\u006A\u0307",
1023 Į: "\u012F\u0307",
1024 Ì: "\u0069\u0307\u0300",
1025 Í: "\u0069\u0307\u0301",
1026 Ĩ: "\u0069\u0307\u0303",
1027 },
1028 },
1029 };
1030 /**
1031 * Localized lower case.
1032 */
1033 function localeLowerCase(str, locale) {
1034 var lang = SUPPORTED_LOCALE[locale.toLowerCase()];
1035 if (lang)
1036 return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; }));
1037 return lowerCase(str);
1038 }
1039 /**
1040 * Lower case as a function.
1041 */
1042 function lowerCase(str) {
1043 return str.toLowerCase();
1044 }
1045
1046 ;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js
1047
1048 // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
1049 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
1050 // Remove all non-word characters.
1051 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
1052 /**
1053 * Normalize the string into something other libraries can manipulate easier.
1054 */
1055 function noCase(input, options) {
1056 if (options === void 0) { options = {}; }
1057 var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
1058 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
1059 var start = 0;
1060 var end = result.length;
1061 // Trim the delimiter from around the output string.
1062 while (result.charAt(start) === "\0")
1063 start++;
1064 while (result.charAt(end - 1) === "\0")
1065 end--;
1066 // Transform each token independently.
1067 return result.slice(start, end).split("\0").map(transform).join(delimiter);
1068 }
1069 /**
1070 * Replace `re` in the input string with the replacement value.
1071 */
1072 function replace(input, re, value) {
1073 if (re instanceof RegExp)
1074 return input.replace(re, value);
1075 return re.reduce(function (input, re) { return input.replace(re, value); }, input);
1076 }
1077
1078 ;// CONCATENATED MODULE: ./node_modules/dot-case/dist.es2015/index.js
1079
1080
1081 function dotCase(input, options) {
1082 if (options === void 0) { options = {}; }
1083 return noCase(input, __assign({ delimiter: "." }, options));
1084 }
1085
1086 ;// CONCATENATED MODULE: ./node_modules/param-case/dist.es2015/index.js
1087
1088
1089 function paramCase(input, options) {
1090 if (options === void 0) { options = {}; }
1091 return dotCase(input, __assign({ delimiter: "-" }, options));
1092 }
1093
1094 ;// CONCATENATED MODULE: external ["wp","escapeHtml"]
1095 const external_wp_escapeHtml_namespaceObject = window["wp"]["escapeHtml"];
1096 ;// CONCATENATED MODULE: ./packages/element/build-module/raw-html.js
1097 /**
1098 * Internal dependencies
1099 */
1100 // Disable reason: JSDoc linter doesn't seem to parse the union (`&`) correctly.
1101
1102 /** @typedef {{children: string} & import('react').ComponentPropsWithoutRef<'div'>} RawHTMLProps */
1103
1104 /**
1105 * Component used as equivalent of Fragment with unescaped HTML, in cases where
1106 * it is desirable to render dangerous HTML without needing a wrapper element.
1107 * To preserve additional props, a `div` wrapper _will_ be created if any props
1108 * aside from `children` are passed.
1109 *
1110 * @param {RawHTMLProps} props Children should be a string of HTML or an array
1111 * of strings. Other props will be passed through
1112 * to the div wrapper.
1113 *
1114 * @return {JSX.Element} Dangerously-rendering component.
1115 */
1116
1117 function RawHTML(_ref) {
1118 let {
1119 children,
1120 ...props
1121 } = _ref;
1122 let rawHtml = ''; // Cast children as an array, and concatenate each element if it is a string.
1123
1124 external_React_namespaceObject.Children.toArray(children).forEach(child => {
1125 if (typeof child === 'string' && child.trim() !== '') {
1126 rawHtml += child;
1127 }
1128 }); // The `div` wrapper will be stripped by the `renderElement` serializer in
1129 // `./serialize.js` unless there are non-children props present.
1130
1131 return (0,external_React_namespaceObject.createElement)('div', {
1132 dangerouslySetInnerHTML: {
1133 __html: rawHtml
1134 },
1135 ...props
1136 });
1137 }
1138
1139 ;// CONCATENATED MODULE: ./packages/element/build-module/serialize.js
1140 /**
1141 * Parts of this source were derived and modified from fast-react-render,
1142 * released under the MIT license.
1143 *
1144 * https://github.com/alt-j/fast-react-render
1145 *
1146 * Copyright (c) 2016 Andrey Morozov
1147 *
1148 * Permission is hereby granted, free of charge, to any person obtaining a copy
1149 * of this software and associated documentation files (the "Software"), to deal
1150 * in the Software without restriction, including without limitation the rights
1151 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1152 * copies of the Software, and to permit persons to whom the Software is
1153 * furnished to do so, subject to the following conditions:
1154 *
1155 * The above copyright notice and this permission notice shall be included in
1156 * all copies or substantial portions of the Software.
1157 *
1158 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1159 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1160 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1161 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1162 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1163 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1164 * THE SOFTWARE.
1165 */
1166
1167 /**
1168 * External dependencies
1169 */
1170
1171
1172 /**
1173 * WordPress dependencies
1174 */
1175
1176
1177 /**
1178 * Internal dependencies
1179 */
1180
1181
1182
1183 /** @typedef {import('./react').WPElement} WPElement */
1184
1185 const {
1186 Provider,
1187 Consumer
1188 } = (0,external_React_namespaceObject.createContext)(undefined);
1189 const ForwardRef = (0,external_React_namespaceObject.forwardRef)(() => {
1190 return null;
1191 });
1192 /**
1193 * Valid attribute types.
1194 *
1195 * @type {Set<string>}
1196 */
1197
1198 const ATTRIBUTES_TYPES = new Set(['string', 'boolean', 'number']);
1199 /**
1200 * Element tags which can be self-closing.
1201 *
1202 * @type {Set<string>}
1203 */
1204
1205 const SELF_CLOSING_TAGS = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
1206 /**
1207 * Boolean attributes are attributes whose presence as being assigned is
1208 * meaningful, even if only empty.
1209 *
1210 * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
1211 * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3
1212 *
1213 * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]
1214 * .filter( ( tr ) => tr.lastChild.textContent.indexOf( 'Boolean attribute' ) !== -1 )
1215 * .reduce( ( result, tr ) => Object.assign( result, {
1216 * [ tr.firstChild.textContent.trim() ]: true
1217 * } ), {} ) ).sort();
1218 *
1219 * @type {Set<string>}
1220 */
1221
1222 const BOOLEAN_ATTRIBUTES = new Set(['allowfullscreen', 'allowpaymentrequest', 'allowusermedia', 'async', 'autofocus', 'autoplay', 'checked', 'controls', 'default', 'defer', 'disabled', 'download', 'formnovalidate', 'hidden', 'ismap', 'itemscope', 'loop', 'multiple', 'muted', 'nomodule', 'novalidate', 'open', 'playsinline', 'readonly', 'required', 'reversed', 'selected', 'typemustmatch']);
1223 /**
1224 * Enumerated attributes are attributes which must be of a specific value form.
1225 * Like boolean attributes, these are meaningful if specified, even if not of a
1226 * valid enumerated value.
1227 *
1228 * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute
1229 * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3
1230 *
1231 * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]
1232 * .filter( ( tr ) => /^("(.+?)";?\s*)+/.test( tr.lastChild.textContent.trim() ) )
1233 * .reduce( ( result, tr ) => Object.assign( result, {
1234 * [ tr.firstChild.textContent.trim() ]: true
1235 * } ), {} ) ).sort();
1236 *
1237 * Some notable omissions:
1238 *
1239 * - `alt`: https://blog.whatwg.org/omit-alt
1240 *
1241 * @type {Set<string>}
1242 */
1243
1244 const ENUMERATED_ATTRIBUTES = new Set(['autocapitalize', 'autocomplete', 'charset', 'contenteditable', 'crossorigin', 'decoding', 'dir', 'draggable', 'enctype', 'formenctype', 'formmethod', 'http-equiv', 'inputmode', 'kind', 'method', 'preload', 'scope', 'shape', 'spellcheck', 'translate', 'type', 'wrap']);
1245 /**
1246 * Set of CSS style properties which support assignment of unitless numbers.
1247 * Used in rendering of style properties, where `px` unit is assumed unless
1248 * property is included in this set or value is zero.
1249 *
1250 * Generated via:
1251 *
1252 * Object.entries( document.createElement( 'div' ).style )
1253 * .filter( ( [ key ] ) => (
1254 * ! /^(webkit|ms|moz)/.test( key ) &&
1255 * ( e.style[ key ] = 10 ) &&
1256 * e.style[ key ] === '10'
1257 * ) )
1258 * .map( ( [ key ] ) => key )
1259 * .sort();
1260 *
1261 * @type {Set<string>}
1262 */
1263
1264 const CSS_PROPERTIES_SUPPORTS_UNITLESS = new Set(['animation', 'animationIterationCount', 'baselineShift', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'columnCount', 'cx', 'cy', 'fillOpacity', 'flexGrow', 'flexShrink', 'floodOpacity', 'fontWeight', 'gridColumnEnd', 'gridColumnStart', 'gridRowEnd', 'gridRowStart', 'lineHeight', 'opacity', 'order', 'orphans', 'r', 'rx', 'ry', 'shapeImageThreshold', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'tabSize', 'widows', 'x', 'y', 'zIndex', 'zoom']);
1265 /**
1266 * Returns true if the specified string is prefixed by one of an array of
1267 * possible prefixes.
1268 *
1269 * @param {string} string String to check.
1270 * @param {string[]} prefixes Possible prefixes.
1271 *
1272 * @return {boolean} Whether string has prefix.
1273 */
1274
1275 function hasPrefix(string, prefixes) {
1276 return prefixes.some(prefix => string.indexOf(prefix) === 0);
1277 }
1278 /**
1279 * Returns true if the given prop name should be ignored in attributes
1280 * serialization, or false otherwise.
1281 *
1282 * @param {string} attribute Attribute to check.
1283 *
1284 * @return {boolean} Whether attribute should be ignored.
1285 */
1286
1287 function isInternalAttribute(attribute) {
1288 return 'key' === attribute || 'children' === attribute;
1289 }
1290 /**
1291 * Returns the normal form of the element's attribute value for HTML.
1292 *
1293 * @param {string} attribute Attribute name.
1294 * @param {*} value Non-normalized attribute value.
1295 *
1296 * @return {*} Normalized attribute value.
1297 */
1298
1299
1300 function getNormalAttributeValue(attribute, value) {
1301 switch (attribute) {
1302 case 'style':
1303 return renderStyle(value);
1304 }
1305
1306 return value;
1307 }
1308 /**
1309 * This is a map of all SVG attributes that have dashes. Map(lower case prop => dashed lower case attribute).
1310 * We need this to render e.g strokeWidth as stroke-width.
1311 *
1312 * List from: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute.
1313 */
1314
1315
1316 const SVG_ATTRIBUTE_WITH_DASHES_LIST = ['accentHeight', 'alignmentBaseline', 'arabicForm', 'baselineShift', 'capHeight', 'clipPath', 'clipRule', 'colorInterpolation', 'colorInterpolationFilters', 'colorProfile', 'colorRendering', 'dominantBaseline', 'enableBackground', 'fillOpacity', 'fillRule', 'floodColor', 'floodOpacity', 'fontFamily', 'fontSize', 'fontSizeAdjust', 'fontStretch', 'fontStyle', 'fontVariant', 'fontWeight', 'glyphName', 'glyphOrientationHorizontal', 'glyphOrientationVertical', 'horizAdvX', 'horizOriginX', 'imageRendering', 'letterSpacing', 'lightingColor', 'markerEnd', 'markerMid', 'markerStart', 'overlinePosition', 'overlineThickness', 'paintOrder', 'panose1', 'pointerEvents', 'renderingIntent', 'shapeRendering', 'stopColor', 'stopOpacity', 'strikethroughPosition', 'strikethroughThickness', 'strokeDasharray', 'strokeDashoffset', 'strokeLinecap', 'strokeLinejoin', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'textAnchor', 'textDecoration', 'textRendering', 'underlinePosition', 'underlineThickness', 'unicodeBidi', 'unicodeRange', 'unitsPerEm', 'vAlphabetic', 'vHanging', 'vIdeographic', 'vMathematical', 'vectorEffect', 'vertAdvY', 'vertOriginX', 'vertOriginY', 'wordSpacing', 'writingMode', 'xmlnsXlink', 'xHeight'].reduce((map, attribute) => {
1317 // The keys are lower-cased for more robust lookup.
1318 map[attribute.toLowerCase()] = attribute;
1319 return map;
1320 }, {});
1321 /**
1322 * This is a map of all case-sensitive SVG attributes. Map(lowercase key => proper case attribute).
1323 * The keys are lower-cased for more robust lookup.
1324 * Note that this list only contains attributes that contain at least one capital letter.
1325 * Lowercase attributes don't need mapping, since we lowercase all attributes by default.
1326 */
1327
1328 const CASE_SENSITIVE_SVG_ATTRIBUTES = ['allowReorder', 'attributeName', 'attributeType', 'autoReverse', 'baseFrequency', 'baseProfile', 'calcMode', 'clipPathUnits', 'contentScriptType', 'contentStyleType', 'diffuseConstant', 'edgeMode', 'externalResourcesRequired', 'filterRes', 'filterUnits', 'glyphRef', 'gradientTransform', 'gradientUnits', 'kernelMatrix', 'kernelUnitLength', 'keyPoints', 'keySplines', 'keyTimes', 'lengthAdjust', 'limitingConeAngle', 'markerHeight', 'markerUnits', 'markerWidth', 'maskContentUnits', 'maskUnits', 'numOctaves', 'pathLength', 'patternContentUnits', 'patternTransform', 'patternUnits', 'pointsAtX', 'pointsAtY', 'pointsAtZ', 'preserveAlpha', 'preserveAspectRatio', 'primitiveUnits', 'refX', 'refY', 'repeatCount', 'repeatDur', 'requiredExtensions', 'requiredFeatures', 'specularConstant', 'specularExponent', 'spreadMethod', 'startOffset', 'stdDeviation', 'stitchTiles', 'suppressContentEditableWarning', 'suppressHydrationWarning', 'surfaceScale', 'systemLanguage', 'tableValues', 'targetX', 'targetY', 'textLength', 'viewBox', 'viewTarget', 'xChannelSelector', 'yChannelSelector'].reduce((map, attribute) => {
1329 // The keys are lower-cased for more robust lookup.
1330 map[attribute.toLowerCase()] = attribute;
1331 return map;
1332 }, {});
1333 /**
1334 * This is a map of all SVG attributes that have colons.
1335 * Keys are lower-cased and stripped of their colons for more robust lookup.
1336 */
1337
1338 const SVG_ATTRIBUTES_WITH_COLONS = ['xlink:actuate', 'xlink:arcrole', 'xlink:href', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type', 'xml:base', 'xml:lang', 'xml:space', 'xmlns:xlink'].reduce((map, attribute) => {
1339 map[attribute.replace(':', '').toLowerCase()] = attribute;
1340 return map;
1341 }, {});
1342 /**
1343 * Returns the normal form of the element's attribute name for HTML.
1344 *
1345 * @param {string} attribute Non-normalized attribute name.
1346 *
1347 * @return {string} Normalized attribute name.
1348 */
1349
1350 function getNormalAttributeName(attribute) {
1351 switch (attribute) {
1352 case 'htmlFor':
1353 return 'for';
1354
1355 case 'className':
1356 return 'class';
1357 }
1358
1359 const attributeLowerCase = attribute.toLowerCase();
1360
1361 if (CASE_SENSITIVE_SVG_ATTRIBUTES[attributeLowerCase]) {
1362 return CASE_SENSITIVE_SVG_ATTRIBUTES[attributeLowerCase];
1363 } else if (SVG_ATTRIBUTE_WITH_DASHES_LIST[attributeLowerCase]) {
1364 return paramCase(SVG_ATTRIBUTE_WITH_DASHES_LIST[attributeLowerCase]);
1365 } else if (SVG_ATTRIBUTES_WITH_COLONS[attributeLowerCase]) {
1366 return SVG_ATTRIBUTES_WITH_COLONS[attributeLowerCase];
1367 }
1368
1369 return attributeLowerCase;
1370 }
1371 /**
1372 * Returns the normal form of the style property name for HTML.
1373 *
1374 * - Converts property names to kebab-case, e.g. 'backgroundColor' → 'background-color'
1375 * - Leaves custom attributes alone, e.g. '--myBackgroundColor' → '--myBackgroundColor'
1376 * - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' → '-moz-transform'
1377 *
1378 * @param {string} property Property name.
1379 *
1380 * @return {string} Normalized property name.
1381 */
1382
1383
1384 function getNormalStylePropertyName(property) {
1385 if (property.startsWith('--')) {
1386 return property;
1387 }
1388
1389 if (hasPrefix(property, ['ms', 'O', 'Moz', 'Webkit'])) {
1390 return '-' + paramCase(property);
1391 }
1392
1393 return paramCase(property);
1394 }
1395 /**
1396 * Returns the normal form of the style property value for HTML. Appends a
1397 * default pixel unit if numeric, not a unitless property, and not zero.
1398 *
1399 * @param {string} property Property name.
1400 * @param {*} value Non-normalized property value.
1401 *
1402 * @return {*} Normalized property value.
1403 */
1404
1405
1406 function getNormalStylePropertyValue(property, value) {
1407 if (typeof value === 'number' && 0 !== value && !CSS_PROPERTIES_SUPPORTS_UNITLESS.has(property)) {
1408 return value + 'px';
1409 }
1410
1411 return value;
1412 }
1413 /**
1414 * Serializes a React element to string.
1415 *
1416 * @param {import('react').ReactNode} element Element to serialize.
1417 * @param {Object} [context] Context object.
1418 * @param {Object} [legacyContext] Legacy context object.
1419 *
1420 * @return {string} Serialized element.
1421 */
1422
1423
1424 function renderElement(element, context) {
1425 let legacyContext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1426
1427 if (null === element || undefined === element || false === element) {
1428 return '';
1429 }
1430
1431 if (Array.isArray(element)) {
1432 return renderChildren(element, context, legacyContext);
1433 }
1434
1435 switch (typeof element) {
1436 case 'string':
1437 return (0,external_wp_escapeHtml_namespaceObject.escapeHTML)(element);
1438
1439 case 'number':
1440 return element.toString();
1441 }
1442
1443 const {
1444 type,
1445 props
1446 } =
1447 /** @type {{type?: any, props?: any}} */
1448 element;
1449
1450 switch (type) {
1451 case external_React_namespaceObject.StrictMode:
1452 case external_React_namespaceObject.Fragment:
1453 return renderChildren(props.children, context, legacyContext);
1454
1455 case RawHTML:
1456 const {
1457 children,
1458 ...wrapperProps
1459 } = props;
1460 return renderNativeComponent(!Object.keys(wrapperProps).length ? null : 'div', { ...wrapperProps,
1461 dangerouslySetInnerHTML: {
1462 __html: children
1463 }
1464 }, context, legacyContext);
1465 }
1466
1467 switch (typeof type) {
1468 case 'string':
1469 return renderNativeComponent(type, props, context, legacyContext);
1470
1471 case 'function':
1472 if (type.prototype && typeof type.prototype.render === 'function') {
1473 return renderComponent(type, props, context, legacyContext);
1474 }
1475
1476 return renderElement(type(props, legacyContext), context, legacyContext);
1477 }
1478
1479 switch (type && type.$$typeof) {
1480 case Provider.$$typeof:
1481 return renderChildren(props.children, props.value, legacyContext);
1482
1483 case Consumer.$$typeof:
1484 return renderElement(props.children(context || type._currentValue), context, legacyContext);
1485
1486 case ForwardRef.$$typeof:
1487 return renderElement(type.render(props), context, legacyContext);
1488 }
1489
1490 return '';
1491 }
1492 /**
1493 * Serializes a native component type to string.
1494 *
1495 * @param {?string} type Native component type to serialize, or null if
1496 * rendering as fragment of children content.
1497 * @param {Object} props Props object.
1498 * @param {Object} [context] Context object.
1499 * @param {Object} [legacyContext] Legacy context object.
1500 *
1501 * @return {string} Serialized element.
1502 */
1503
1504 function renderNativeComponent(type, props, context) {
1505 let legacyContext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1506 let content = '';
1507
1508 if (type === 'textarea' && props.hasOwnProperty('value')) {
1509 // Textarea children can be assigned as value prop. If it is, render in
1510 // place of children. Ensure to omit so it is not assigned as attribute
1511 // as well.
1512 content = renderChildren(props.value, context, legacyContext);
1513 const {
1514 value,
1515 ...restProps
1516 } = props;
1517 props = restProps;
1518 } else if (props.dangerouslySetInnerHTML && typeof props.dangerouslySetInnerHTML.__html === 'string') {
1519 // Dangerous content is left unescaped.
1520 content = props.dangerouslySetInnerHTML.__html;
1521 } else if (typeof props.children !== 'undefined') {
1522 content = renderChildren(props.children, context, legacyContext);
1523 }
1524
1525 if (!type) {
1526 return content;
1527 }
1528
1529 const attributes = renderAttributes(props);
1530
1531 if (SELF_CLOSING_TAGS.has(type)) {
1532 return '<' + type + attributes + '/>';
1533 }
1534
1535 return '<' + type + attributes + '>' + content + '</' + type + '>';
1536 }
1537 /** @typedef {import('./react').WPComponent} WPComponent */
1538
1539 /**
1540 * Serializes a non-native component type to string.
1541 *
1542 * @param {WPComponent} Component Component type to serialize.
1543 * @param {Object} props Props object.
1544 * @param {Object} [context] Context object.
1545 * @param {Object} [legacyContext] Legacy context object.
1546 *
1547 * @return {string} Serialized element
1548 */
1549
1550 function renderComponent(Component, props, context) {
1551 let legacyContext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1552 const instance = new
1553 /** @type {import('react').ComponentClass} */
1554 Component(props, legacyContext);
1555
1556 if (typeof // Ignore reason: Current prettier reformats parens and mangles type assertion
1557 // prettier-ignore
1558
1559 /** @type {{getChildContext?: () => unknown}} */
1560 instance.getChildContext === 'function') {
1561 Object.assign(legacyContext,
1562 /** @type {{getChildContext?: () => unknown}} */
1563 instance.getChildContext());
1564 }
1565
1566 const html = renderElement(instance.render(), context, legacyContext);
1567 return html;
1568 }
1569 /**
1570 * Serializes an array of children to string.
1571 *
1572 * @param {import('react').ReactNodeArray} children Children to serialize.
1573 * @param {Object} [context] Context object.
1574 * @param {Object} [legacyContext] Legacy context object.
1575 *
1576 * @return {string} Serialized children.
1577 */
1578
1579 function renderChildren(children, context) {
1580 let legacyContext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1581 let result = '';
1582 children = Array.isArray(children) ? children : [children];
1583
1584 for (let i = 0; i < children.length; i++) {
1585 const child = children[i];
1586 result += renderElement(child, context, legacyContext);
1587 }
1588
1589 return result;
1590 }
1591 /**
1592 * Renders a props object as a string of HTML attributes.
1593 *
1594 * @param {Object} props Props object.
1595 *
1596 * @return {string} Attributes string.
1597 */
1598
1599
1600 function renderAttributes(props) {
1601 let result = '';
1602
1603 for (const key in props) {
1604 const attribute = getNormalAttributeName(key);
1605
1606 if (!(0,external_wp_escapeHtml_namespaceObject.isValidAttributeName)(attribute)) {
1607 continue;
1608 }
1609
1610 let value = getNormalAttributeValue(key, props[key]); // If value is not of serializeable type, skip.
1611
1612 if (!ATTRIBUTES_TYPES.has(typeof value)) {
1613 continue;
1614 } // Don't render internal attribute names.
1615
1616
1617 if (isInternalAttribute(key)) {
1618 continue;
1619 }
1620
1621 const isBooleanAttribute = BOOLEAN_ATTRIBUTES.has(attribute); // Boolean attribute should be omitted outright if its value is false.
1622
1623 if (isBooleanAttribute && value === false) {
1624 continue;
1625 }
1626
1627 const isMeaningfulAttribute = isBooleanAttribute || hasPrefix(key, ['data-', 'aria-']) || ENUMERATED_ATTRIBUTES.has(attribute); // Only write boolean value as attribute if meaningful.
1628
1629 if (typeof value === 'boolean' && !isMeaningfulAttribute) {
1630 continue;
1631 }
1632
1633 result += ' ' + attribute; // Boolean attributes should write attribute name, but without value.
1634 // Mere presence of attribute name is effective truthiness.
1635
1636 if (isBooleanAttribute) {
1637 continue;
1638 }
1639
1640 if (typeof value === 'string') {
1641 value = (0,external_wp_escapeHtml_namespaceObject.escapeAttribute)(value);
1642 }
1643
1644 result += '="' + value + '"';
1645 }
1646
1647 return result;
1648 }
1649 /**
1650 * Renders a style object as a string attribute value.
1651 *
1652 * @param {Object} style Style object.
1653 *
1654 * @return {string} Style attribute value.
1655 */
1656
1657 function renderStyle(style) {
1658 // Only generate from object, e.g. tolerate string value.
1659 if (!isPlainObject(style)) {
1660 return style;
1661 }
1662
1663 let result;
1664
1665 for (const property in style) {
1666 const value = style[property];
1667
1668 if (null === value || undefined === value) {
1669 continue;
1670 }
1671
1672 if (result) {
1673 result += ';';
1674 } else {
1675 result = '';
1676 }
1677
1678 const normalName = getNormalStylePropertyName(property);
1679 const normalValue = getNormalStylePropertyValue(property, value);
1680 result += normalName + ':' + normalValue;
1681 }
1682
1683 return result;
1684 }
1685 /* harmony default export */ const serialize = (renderElement);
1686
1687 ;// CONCATENATED MODULE: ./packages/element/build-module/index.js
1688
1689
1690
1691
1692
1693
1694
1695
1696 (window.wp = window.wp || {}).element = __webpack_exports__;
1697 /******/ })()
1698 ;