You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

554 lines
15 KiB

1 year ago
  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. /************************************************************************/
  25. var __webpack_exports__ = {};
  26. // EXPORTS
  27. __webpack_require__.d(__webpack_exports__, {
  28. "default": function() { return /* binding */ build_module; }
  29. });
  30. // UNUSED EXPORTS: attrs, fromMatch, next, regexp, replace, string
  31. ;// CONCATENATED MODULE: ./node_modules/memize/dist/index.js
  32. /**
  33. * Memize options object.
  34. *
  35. * @typedef MemizeOptions
  36. *
  37. * @property {number} [maxSize] Maximum size of the cache.
  38. */
  39. /**
  40. * Internal cache entry.
  41. *
  42. * @typedef MemizeCacheNode
  43. *
  44. * @property {?MemizeCacheNode|undefined} [prev] Previous node.
  45. * @property {?MemizeCacheNode|undefined} [next] Next node.
  46. * @property {Array<*>} args Function arguments for cache
  47. * entry.
  48. * @property {*} val Function result.
  49. */
  50. /**
  51. * Properties of the enhanced function for controlling cache.
  52. *
  53. * @typedef MemizeMemoizedFunction
  54. *
  55. * @property {()=>void} clear Clear the cache.
  56. */
  57. /**
  58. * Accepts a function to be memoized, and returns a new memoized function, with
  59. * optional options.
  60. *
  61. * @template {(...args: any[]) => any} F
  62. *
  63. * @param {F} fn Function to memoize.
  64. * @param {MemizeOptions} [options] Options object.
  65. *
  66. * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function.
  67. */
  68. function memize(fn, options) {
  69. var size = 0;
  70. /** @type {?MemizeCacheNode|undefined} */
  71. var head;
  72. /** @type {?MemizeCacheNode|undefined} */
  73. var tail;
  74. options = options || {};
  75. function memoized(/* ...args */) {
  76. var node = head,
  77. len = arguments.length,
  78. args,
  79. i;
  80. searchCache: while (node) {
  81. // Perform a shallow equality test to confirm that whether the node
  82. // under test is a candidate for the arguments passed. Two arrays
  83. // are shallowly equal if their length matches and each entry is
  84. // strictly equal between the two sets. Avoid abstracting to a
  85. // function which could incur an arguments leaking deoptimization.
  86. // Check whether node arguments match arguments length
  87. if (node.args.length !== arguments.length) {
  88. node = node.next;
  89. continue;
  90. }
  91. // Check whether node arguments match arguments values
  92. for (i = 0; i < len; i++) {
  93. if (node.args[i] !== arguments[i]) {
  94. node = node.next;
  95. continue searchCache;
  96. }
  97. }
  98. // At this point we can assume we've found a match
  99. // Surface matched node to head if not already
  100. if (node !== head) {
  101. // As tail, shift to previous. Must only shift if not also
  102. // head, since if both head and tail, there is no previous.
  103. if (node === tail) {
  104. tail = node.prev;
  105. }
  106. // Adjust siblings to point to each other. If node was tail,
  107. // this also handles new tail's empty `next` assignment.
  108. /** @type {MemizeCacheNode} */ (node.prev).next = node.next;
  109. if (node.next) {
  110. node.next.prev = node.prev;
  111. }
  112. node.next = head;
  113. node.prev = null;
  114. /** @type {MemizeCacheNode} */ (head).prev = node;
  115. head = node;
  116. }
  117. // Return immediately
  118. return node.val;
  119. }
  120. // No cached value found. Continue to insertion phase:
  121. // Create a copy of arguments (avoid leaking deoptimization)
  122. args = new Array(len);
  123. for (i = 0; i < len; i++) {
  124. args[i] = arguments[i];
  125. }
  126. node = {
  127. args: args,
  128. // Generate the result from original function
  129. val: fn.apply(null, args),
  130. };
  131. // Don't need to check whether node is already head, since it would
  132. // have been returned above already if it was
  133. // Shift existing head down list
  134. if (head) {
  135. head.prev = node;
  136. node.next = head;
  137. } else {
  138. // If no head, follows that there's no tail (at initial or reset)
  139. tail = node;
  140. }
  141. // Trim tail if we're reached max size and are pending cache insertion
  142. if (size === /** @type {MemizeOptions} */ (options).maxSize) {
  143. tail = /** @type {MemizeCacheNode} */ (tail).prev;
  144. /** @type {MemizeCacheNode} */ (tail).next = null;
  145. } else {
  146. size++;
  147. }
  148. head = node;
  149. return node.val;
  150. }
  151. memoized.clear = function () {
  152. head = null;
  153. tail = null;
  154. size = 0;
  155. };
  156. // Ignore reason: There's not a clear solution to create an intersection of
  157. // the function with additional properties, where the goal is to retain the
  158. // function signature of the incoming argument and add control properties
  159. // on the return value.
  160. // @ts-ignore
  161. return memoized;
  162. }
  163. ;// CONCATENATED MODULE: ./node_modules/@wordpress/shortcode/build-module/index.js
  164. /**
  165. * External dependencies
  166. */
  167. /**
  168. * Shortcode attributes object.
  169. *
  170. * @typedef {Object} WPShortcodeAttrs
  171. *
  172. * @property {Object} named Object with named attributes.
  173. * @property {Array} numeric Array with numeric attributes.
  174. */
  175. /**
  176. * Shortcode object.
  177. *
  178. * @typedef {Object} WPShortcode
  179. *
  180. * @property {string} tag Shortcode tag.
  181. * @property {WPShortcodeAttrs} attrs Shortcode attributes.
  182. * @property {string} content Shortcode content.
  183. * @property {string} type Shortcode type: `self-closing`,
  184. * `closed`, or `single`.
  185. */
  186. /**
  187. * @typedef {Object} WPShortcodeMatch
  188. *
  189. * @property {number} index Index the shortcode is found at.
  190. * @property {string} content Matched content.
  191. * @property {WPShortcode} shortcode Shortcode instance of the match.
  192. */
  193. /**
  194. * Find the next matching shortcode.
  195. *
  196. * @param {string} tag Shortcode tag.
  197. * @param {string} text Text to search.
  198. * @param {number} index Index to start search from.
  199. *
  200. * @return {WPShortcodeMatch | undefined} Matched information.
  201. */
  202. function next(tag, text, index = 0) {
  203. const re = regexp(tag);
  204. re.lastIndex = index;
  205. const match = re.exec(text);
  206. if (!match) {
  207. return;
  208. }
  209. // If we matched an escaped shortcode, try again.
  210. if ('[' === match[1] && ']' === match[7]) {
  211. return next(tag, text, re.lastIndex);
  212. }
  213. const result = {
  214. index: match.index,
  215. content: match[0],
  216. shortcode: fromMatch(match)
  217. };
  218. // If we matched a leading `[`, strip it from the match and increment the
  219. // index accordingly.
  220. if (match[1]) {
  221. result.content = result.content.slice(1);
  222. result.index++;
  223. }
  224. // If we matched a trailing `]`, strip it from the match.
  225. if (match[7]) {
  226. result.content = result.content.slice(0, -1);
  227. }
  228. return result;
  229. }
  230. /**
  231. * Replace matching shortcodes in a block of text.
  232. *
  233. * @param {string} tag Shortcode tag.
  234. * @param {string} text Text to search.
  235. * @param {Function} callback Function to process the match and return
  236. * replacement string.
  237. *
  238. * @return {string} Text with shortcodes replaced.
  239. */
  240. function replace(tag, text, callback) {
  241. return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
  242. // If both extra brackets exist, the shortcode has been properly
  243. // escaped.
  244. if (left === '[' && right === ']') {
  245. return match;
  246. }
  247. // Create the match object and pass it through the callback.
  248. const result = callback(fromMatch(arguments));
  249. // Make sure to return any of the extra brackets if they weren't used to
  250. // escape the shortcode.
  251. return result || result === '' ? left + result + right : match;
  252. });
  253. }
  254. /**
  255. * Generate a string from shortcode parameters.
  256. *
  257. * Creates a shortcode instance and returns a string.
  258. *
  259. * Accepts the same `options` as the `shortcode()` constructor, containing a
  260. * `tag` string, a string or object of `attrs`, a boolean indicating whether to
  261. * format the shortcode using a `single` tag, and a `content` string.
  262. *
  263. * @param {Object} options
  264. *
  265. * @return {string} String representation of the shortcode.
  266. */
  267. function string(options) {
  268. return new shortcode(options).string();
  269. }
  270. /**
  271. * Generate a RegExp to identify a shortcode.
  272. *
  273. * The base regex is functionally equivalent to the one found in
  274. * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
  275. *
  276. * Capture groups:
  277. *
  278. * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
  279. * 2. The shortcode name
  280. * 3. The shortcode argument list
  281. * 4. The self closing `/`
  282. * 5. The content of a shortcode when it wraps some content.
  283. * 6. The closing tag.
  284. * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
  285. *
  286. * @param {string} tag Shortcode tag.
  287. *
  288. * @return {RegExp} Shortcode RegExp.
  289. */
  290. function regexp(tag) {
  291. return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
  292. }
  293. /**
  294. * Parse shortcode attributes.
  295. *
  296. * Shortcodes accept many types of attributes. These can chiefly be divided into
  297. * named and numeric attributes:
  298. *
  299. * Named attributes are assigned on a key/value basis, while numeric attributes
  300. * are treated as an array.
  301. *
  302. * Named attributes can be formatted as either `name="value"`, `name='value'`,
  303. * or `name=value`. Numeric attributes can be formatted as `"value"` or just
  304. * `value`.
  305. *
  306. * @param {string} text Serialised shortcode attributes.
  307. *
  308. * @return {WPShortcodeAttrs} Parsed shortcode attributes.
  309. */
  310. const attrs = memize(text => {
  311. const named = {};
  312. const numeric = [];
  313. // This regular expression is reused from `shortcode_parse_atts()` in
  314. // `wp-includes/shortcodes.php`.
  315. //
  316. // Capture groups:
  317. //
  318. // 1. An attribute name, that corresponds to...
  319. // 2. a value in double quotes.
  320. // 3. An attribute name, that corresponds to...
  321. // 4. a value in single quotes.
  322. // 5. An attribute name, that corresponds to...
  323. // 6. an unquoted value.
  324. // 7. A numeric attribute in double quotes.
  325. // 8. A numeric attribute in single quotes.
  326. // 9. An unquoted numeric attribute.
  327. const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g;
  328. // Map zero-width spaces to actual spaces.
  329. text = text.replace(/[\u00a0\u200b]/g, ' ');
  330. let match;
  331. // Match and normalize attributes.
  332. while (match = pattern.exec(text)) {
  333. if (match[1]) {
  334. named[match[1].toLowerCase()] = match[2];
  335. } else if (match[3]) {
  336. named[match[3].toLowerCase()] = match[4];
  337. } else if (match[5]) {
  338. named[match[5].toLowerCase()] = match[6];
  339. } else if (match[7]) {
  340. numeric.push(match[7]);
  341. } else if (match[8]) {
  342. numeric.push(match[8]);
  343. } else if (match[9]) {
  344. numeric.push(match[9]);
  345. }
  346. }
  347. return {
  348. named,
  349. numeric
  350. };
  351. });
  352. /**
  353. * Generate a Shortcode Object from a RegExp match.
  354. *
  355. * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
  356. * by `regexp()`. `match` can also be set to the `arguments` from a callback
  357. * passed to `regexp.replace()`.
  358. *
  359. * @param {Array} match Match array.
  360. *
  361. * @return {WPShortcode} Shortcode instance.
  362. */
  363. function fromMatch(match) {
  364. let type;
  365. if (match[4]) {
  366. type = 'self-closing';
  367. } else if (match[6]) {
  368. type = 'closed';
  369. } else {
  370. type = 'single';
  371. }
  372. return new shortcode({
  373. tag: match[2],
  374. attrs: match[3],
  375. type,
  376. content: match[5]
  377. });
  378. }
  379. /**
  380. * Creates a shortcode instance.
  381. *
  382. * To access a raw representation of a shortcode, pass an `options` object,
  383. * containing a `tag` string, a string or object of `attrs`, a string indicating
  384. * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a
  385. * `content` string.
  386. *
  387. * @param {Object} options Options as described.
  388. *
  389. * @return {WPShortcode} Shortcode instance.
  390. */
  391. const shortcode = Object.assign(function (options) {
  392. const {
  393. tag,
  394. attrs: attributes,
  395. type,
  396. content
  397. } = options || {};
  398. Object.assign(this, {
  399. tag,
  400. type,
  401. content
  402. });
  403. // Ensure we have a correctly formatted `attrs` object.
  404. this.attrs = {
  405. named: {},
  406. numeric: []
  407. };
  408. if (!attributes) {
  409. return;
  410. }
  411. const attributeTypes = ['named', 'numeric'];
  412. // Parse a string of attributes.
  413. if (typeof attributes === 'string') {
  414. this.attrs = attrs(attributes);
  415. // Identify a correctly formatted `attrs` object.
  416. } else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
  417. this.attrs = attributes;
  418. // Handle a flat object of attributes.
  419. } else {
  420. Object.entries(attributes).forEach(([key, value]) => {
  421. this.set(key, value);
  422. });
  423. }
  424. }, {
  425. next,
  426. replace,
  427. string,
  428. regexp,
  429. attrs,
  430. fromMatch
  431. });
  432. Object.assign(shortcode.prototype, {
  433. /**
  434. * Get a shortcode attribute.
  435. *
  436. * Automatically detects whether `attr` is named or numeric and routes it
  437. * accordingly.
  438. *
  439. * @param {(number|string)} attr Attribute key.
  440. *
  441. * @return {string} Attribute value.
  442. */
  443. get(attr) {
  444. return this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr];
  445. },
  446. /**
  447. * Set a shortcode attribute.
  448. *
  449. * Automatically detects whether `attr` is named or numeric and routes it
  450. * accordingly.
  451. *
  452. * @param {(number|string)} attr Attribute key.
  453. * @param {string} value Attribute value.
  454. *
  455. * @return {WPShortcode} Shortcode instance.
  456. */
  457. set(attr, value) {
  458. this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value;
  459. return this;
  460. },
  461. /**
  462. * Transform the shortcode into a string.
  463. *
  464. * @return {string} String representation of the shortcode.
  465. */
  466. string() {
  467. let text = '[' + this.tag;
  468. this.attrs.numeric.forEach(value => {
  469. if (/\s/.test(value)) {
  470. text += ' "' + value + '"';
  471. } else {
  472. text += ' ' + value;
  473. }
  474. });
  475. Object.entries(this.attrs.named).forEach(([name, value]) => {
  476. text += ' ' + name + '="' + value + '"';
  477. });
  478. // If the tag is marked as `single` or `self-closing`, close the tag and
  479. // ignore any additional content.
  480. if ('single' === this.type) {
  481. return text + ']';
  482. } else if ('self-closing' === this.type) {
  483. return text + ' /]';
  484. }
  485. // Complete the opening tag.
  486. text += ']';
  487. if (this.content) {
  488. text += this.content;
  489. }
  490. // Add the closing tag.
  491. return text + '[/' + this.tag + ']';
  492. }
  493. });
  494. /* harmony default export */ var build_module = (shortcode);
  495. (window.wp = window.wp || {}).shortcode = __webpack_exports__["default"];
  496. /******/ })()
  497. ;