element.js 59 KB

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