34 |
62 |
35 /** |
63 /** |
36 * Accepts a function to be memoized, and returns a new memoized function, with |
64 * Accepts a function to be memoized, and returns a new memoized function, with |
37 * optional options. |
65 * optional options. |
38 * |
66 * |
39 * @template {Function} F |
67 * @template {(...args: any[]) => any} F |
40 * |
68 * |
41 * @param {F} fn Function to memoize. |
69 * @param {F} fn Function to memoize. |
42 * @param {MemizeOptions} [options] Options object. |
70 * @param {MemizeOptions} [options] Options object. |
43 * |
71 * |
44 * @return {F & MemizeMemoizedFunction} Memoized function. |
72 * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function. |
45 */ |
73 */ |
46 function memize( fn, options ) { |
74 function memize(fn, options) { |
47 var size = 0; |
75 var size = 0; |
48 |
76 |
49 /** @type {?MemizeCacheNode|undefined} */ |
77 /** @type {?MemizeCacheNode|undefined} */ |
50 var head; |
78 var head; |
51 |
79 |
52 /** @type {?MemizeCacheNode|undefined} */ |
80 /** @type {?MemizeCacheNode|undefined} */ |
53 var tail; |
81 var tail; |
54 |
82 |
55 options = options || {}; |
83 options = options || {}; |
56 |
84 |
57 function memoized( /* ...args */ ) { |
85 function memoized(/* ...args */) { |
58 var node = head, |
86 var node = head, |
59 len = arguments.length, |
87 len = arguments.length, |
60 args, i; |
88 args, |
61 |
89 i; |
62 searchCache: while ( node ) { |
90 |
|
91 searchCache: while (node) { |
63 // Perform a shallow equality test to confirm that whether the node |
92 // Perform a shallow equality test to confirm that whether the node |
64 // under test is a candidate for the arguments passed. Two arrays |
93 // under test is a candidate for the arguments passed. Two arrays |
65 // are shallowly equal if their length matches and each entry is |
94 // are shallowly equal if their length matches and each entry is |
66 // strictly equal between the two sets. Avoid abstracting to a |
95 // strictly equal between the two sets. Avoid abstracting to a |
67 // function which could incur an arguments leaking deoptimization. |
96 // function which could incur an arguments leaking deoptimization. |
68 |
97 |
69 // Check whether node arguments match arguments length |
98 // Check whether node arguments match arguments length |
70 if ( node.args.length !== arguments.length ) { |
99 if (node.args.length !== arguments.length) { |
71 node = node.next; |
100 node = node.next; |
72 continue; |
101 continue; |
73 } |
102 } |
74 |
103 |
75 // Check whether node arguments match arguments values |
104 // Check whether node arguments match arguments values |
76 for ( i = 0; i < len; i++ ) { |
105 for (i = 0; i < len; i++) { |
77 if ( node.args[ i ] !== arguments[ i ] ) { |
106 if (node.args[i] !== arguments[i]) { |
78 node = node.next; |
107 node = node.next; |
79 continue searchCache; |
108 continue searchCache; |
80 } |
109 } |
81 } |
110 } |
82 |
111 |
83 // At this point we can assume we've found a match |
112 // At this point we can assume we've found a match |
84 |
113 |
85 // Surface matched node to head if not already |
114 // Surface matched node to head if not already |
86 if ( node !== head ) { |
115 if (node !== head) { |
87 // As tail, shift to previous. Must only shift if not also |
116 // As tail, shift to previous. Must only shift if not also |
88 // head, since if both head and tail, there is no previous. |
117 // head, since if both head and tail, there is no previous. |
89 if ( node === tail ) { |
118 if (node === tail) { |
90 tail = node.prev; |
119 tail = node.prev; |
91 } |
120 } |
92 |
121 |
93 // Adjust siblings to point to each other. If node was tail, |
122 // Adjust siblings to point to each other. If node was tail, |
94 // this also handles new tail's empty `next` assignment. |
123 // this also handles new tail's empty `next` assignment. |
95 /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next; |
124 /** @type {MemizeCacheNode} */ (node.prev).next = node.next; |
96 if ( node.next ) { |
125 if (node.next) { |
97 node.next.prev = node.prev; |
126 node.next.prev = node.prev; |
98 } |
127 } |
99 |
128 |
100 node.next = head; |
129 node.next = head; |
101 node.prev = null; |
130 node.prev = null; |
102 /** @type {MemizeCacheNode} */ ( head ).prev = node; |
131 /** @type {MemizeCacheNode} */ (head).prev = node; |
103 head = node; |
132 head = node; |
104 } |
133 } |
105 |
134 |
106 // Return immediately |
135 // Return immediately |
107 return node.val; |
136 return node.val; |
108 } |
137 } |
109 |
138 |
110 // No cached value found. Continue to insertion phase: |
139 // No cached value found. Continue to insertion phase: |
111 |
140 |
112 // Create a copy of arguments (avoid leaking deoptimization) |
141 // Create a copy of arguments (avoid leaking deoptimization) |
113 args = new Array( len ); |
142 args = new Array(len); |
114 for ( i = 0; i < len; i++ ) { |
143 for (i = 0; i < len; i++) { |
115 args[ i ] = arguments[ i ]; |
144 args[i] = arguments[i]; |
116 } |
145 } |
117 |
146 |
118 node = { |
147 node = { |
119 args: args, |
148 args: args, |
120 |
149 |
121 // Generate the result from original function |
150 // Generate the result from original function |
122 val: fn.apply( null, args ), |
151 val: fn.apply(null, args), |
123 }; |
152 }; |
124 |
153 |
125 // Don't need to check whether node is already head, since it would |
154 // Don't need to check whether node is already head, since it would |
126 // have been returned above already if it was |
155 // have been returned above already if it was |
127 |
156 |
128 // Shift existing head down list |
157 // Shift existing head down list |
129 if ( head ) { |
158 if (head) { |
130 head.prev = node; |
159 head.prev = node; |
131 node.next = head; |
160 node.next = head; |
132 } else { |
161 } else { |
133 // If no head, follows that there's no tail (at initial or reset) |
162 // If no head, follows that there's no tail (at initial or reset) |
134 tail = node; |
163 tail = node; |
135 } |
164 } |
136 |
165 |
137 // Trim tail if we're reached max size and are pending cache insertion |
166 // Trim tail if we're reached max size and are pending cache insertion |
138 if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) { |
167 if (size === /** @type {MemizeOptions} */ (options).maxSize) { |
139 tail = /** @type {MemizeCacheNode} */ ( tail ).prev; |
168 tail = /** @type {MemizeCacheNode} */ (tail).prev; |
140 /** @type {MemizeCacheNode} */ ( tail ).next = null; |
169 /** @type {MemizeCacheNode} */ (tail).next = null; |
141 } else { |
170 } else { |
142 size++; |
171 size++; |
143 } |
172 } |
144 |
173 |
145 head = node; |
174 head = node; |
146 |
175 |
147 return node.val; |
176 return node.val; |
148 } |
177 } |
149 |
178 |
150 memoized.clear = function() { |
179 memoized.clear = function () { |
151 head = null; |
180 head = null; |
152 tail = null; |
181 tail = null; |
153 size = 0; |
182 size = 0; |
154 }; |
183 }; |
155 |
184 |
156 if ( false ) {} |
|
157 |
|
158 // Ignore reason: There's not a clear solution to create an intersection of |
185 // Ignore reason: There's not a clear solution to create an intersection of |
159 // the function with additional properties, where the goal is to retain the |
186 // the function with additional properties, where the goal is to retain the |
160 // function signature of the incoming argument and add control properties |
187 // function signature of the incoming argument and add control properties |
161 // on the return value. |
188 // on the return value. |
162 |
189 |
163 // @ts-ignore |
190 // @ts-ignore |
164 return memoized; |
191 return memoized; |
165 } |
192 } |
166 |
193 |
167 module.exports = memize; |
194 |
168 |
195 |
169 |
|
170 /***/ }) |
|
171 |
|
172 /******/ }); |
|
173 /************************************************************************/ |
|
174 /******/ // The module cache |
|
175 /******/ var __webpack_module_cache__ = {}; |
|
176 /******/ |
|
177 /******/ // The require function |
|
178 /******/ function __webpack_require__(moduleId) { |
|
179 /******/ // Check if module is in cache |
|
180 /******/ var cachedModule = __webpack_module_cache__[moduleId]; |
|
181 /******/ if (cachedModule !== undefined) { |
|
182 /******/ return cachedModule.exports; |
|
183 /******/ } |
|
184 /******/ // Create a new module (and put it into the cache) |
|
185 /******/ var module = __webpack_module_cache__[moduleId] = { |
|
186 /******/ // no module.id needed |
|
187 /******/ // no module.loaded needed |
|
188 /******/ exports: {} |
|
189 /******/ }; |
|
190 /******/ |
|
191 /******/ // Execute the module function |
|
192 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
|
193 /******/ |
|
194 /******/ // Return the exports of the module |
|
195 /******/ return module.exports; |
|
196 /******/ } |
|
197 /******/ |
|
198 /************************************************************************/ |
|
199 /******/ /* webpack/runtime/compat get default export */ |
|
200 /******/ !function() { |
|
201 /******/ // getDefaultExport function for compatibility with non-harmony modules |
|
202 /******/ __webpack_require__.n = function(module) { |
|
203 /******/ var getter = module && module.__esModule ? |
|
204 /******/ function() { return module['default']; } : |
|
205 /******/ function() { return module; }; |
|
206 /******/ __webpack_require__.d(getter, { a: getter }); |
|
207 /******/ return getter; |
|
208 /******/ }; |
|
209 /******/ }(); |
|
210 /******/ |
|
211 /******/ /* webpack/runtime/define property getters */ |
|
212 /******/ !function() { |
|
213 /******/ // define getter functions for harmony exports |
|
214 /******/ __webpack_require__.d = function(exports, definition) { |
|
215 /******/ for(var key in definition) { |
|
216 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
|
217 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
|
218 /******/ } |
|
219 /******/ } |
|
220 /******/ }; |
|
221 /******/ }(); |
|
222 /******/ |
|
223 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
224 /******/ !function() { |
|
225 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
|
226 /******/ }(); |
|
227 /******/ |
|
228 /************************************************************************/ |
|
229 var __webpack_exports__ = {}; |
|
230 // This entry need to be wrapped in an IIFE because it need to be in strict mode. |
|
231 !function() { |
|
232 "use strict"; |
|
233 |
|
234 // EXPORTS |
|
235 __webpack_require__.d(__webpack_exports__, { |
|
236 "default": function() { return /* binding */ build_module; } |
|
237 }); |
|
238 |
|
239 // UNUSED EXPORTS: attrs, fromMatch, next, regexp, replace, string |
|
240 |
|
241 ;// CONCATENATED MODULE: external "lodash" |
|
242 var external_lodash_namespaceObject = window["lodash"]; |
|
243 // EXTERNAL MODULE: ./node_modules/memize/index.js |
|
244 var memize = __webpack_require__(9756); |
|
245 var memize_default = /*#__PURE__*/__webpack_require__.n(memize); |
|
246 ;// CONCATENATED MODULE: ./node_modules/@wordpress/shortcode/build-module/index.js |
196 ;// CONCATENATED MODULE: ./node_modules/@wordpress/shortcode/build-module/index.js |
247 /** |
197 /** |
248 * External dependencies |
198 * External dependencies |
249 */ |
199 */ |
250 |
200 |
283 * |
233 * |
284 * @param {string} tag Shortcode tag. |
234 * @param {string} tag Shortcode tag. |
285 * @param {string} text Text to search. |
235 * @param {string} text Text to search. |
286 * @param {number} index Index to start search from. |
236 * @param {number} index Index to start search from. |
287 * |
237 * |
288 * @return {?WPShortcodeMatch} Matched information. |
238 * @return {WPShortcodeMatch | undefined} Matched information. |
289 */ |
239 */ |
290 |
240 function next(tag, text, index = 0) { |
291 function next(tag, text) { |
|
292 let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; |
|
293 const re = regexp(tag); |
241 const re = regexp(tag); |
294 re.lastIndex = index; |
242 re.lastIndex = index; |
295 const match = re.exec(text); |
243 const match = re.exec(text); |
296 |
|
297 if (!match) { |
244 if (!match) { |
298 return; |
245 return; |
299 } // If we matched an escaped shortcode, try again. |
246 } |
300 |
247 |
301 |
248 // If we matched an escaped shortcode, try again. |
302 if ('[' === match[1] && ']' === match[7]) { |
249 if ('[' === match[1] && ']' === match[7]) { |
303 return next(tag, text, re.lastIndex); |
250 return next(tag, text, re.lastIndex); |
304 } |
251 } |
305 |
|
306 const result = { |
252 const result = { |
307 index: match.index, |
253 index: match.index, |
308 content: match[0], |
254 content: match[0], |
309 shortcode: fromMatch(match) |
255 shortcode: fromMatch(match) |
310 }; // If we matched a leading `[`, strip it from the match and increment the |
256 }; |
|
257 |
|
258 // If we matched a leading `[`, strip it from the match and increment the |
311 // index accordingly. |
259 // index accordingly. |
312 |
|
313 if (match[1]) { |
260 if (match[1]) { |
314 result.content = result.content.slice(1); |
261 result.content = result.content.slice(1); |
315 result.index++; |
262 result.index++; |
316 } // If we matched a trailing `]`, strip it from the match. |
263 } |
317 |
264 |
318 |
265 // If we matched a trailing `]`, strip it from the match. |
319 if (match[7]) { |
266 if (match[7]) { |
320 result.content = result.content.slice(0, -1); |
267 result.content = result.content.slice(0, -1); |
321 } |
268 } |
322 |
|
323 return result; |
269 return result; |
324 } |
270 } |
|
271 |
325 /** |
272 /** |
326 * Replace matching shortcodes in a block of text. |
273 * Replace matching shortcodes in a block of text. |
327 * |
274 * |
328 * @param {string} tag Shortcode tag. |
275 * @param {string} tag Shortcode tag. |
329 * @param {string} text Text to search. |
276 * @param {string} text Text to search. |
330 * @param {Function} callback Function to process the match and return |
277 * @param {Function} callback Function to process the match and return |
331 * replacement string. |
278 * replacement string. |
332 * |
279 * |
333 * @return {string} Text with shortcodes replaced. |
280 * @return {string} Text with shortcodes replaced. |
334 */ |
281 */ |
335 |
|
336 function replace(tag, text, callback) { |
282 function replace(tag, text, callback) { |
337 return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) { |
283 return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) { |
338 // If both extra brackets exist, the shortcode has been properly |
284 // If both extra brackets exist, the shortcode has been properly |
339 // escaped. |
285 // escaped. |
340 if (left === '[' && right === ']') { |
286 if (left === '[' && right === ']') { |
341 return match; |
287 return match; |
342 } // Create the match object and pass it through the callback. |
288 } |
343 |
289 |
344 |
290 // Create the match object and pass it through the callback. |
345 const result = callback(fromMatch(arguments)); // Make sure to return any of the extra brackets if they weren't used to |
291 const result = callback(fromMatch(arguments)); |
|
292 |
|
293 // Make sure to return any of the extra brackets if they weren't used to |
346 // escape the shortcode. |
294 // escape the shortcode. |
347 |
|
348 return result || result === '' ? left + result + right : match; |
295 return result || result === '' ? left + result + right : match; |
349 }); |
296 }); |
350 } |
297 } |
|
298 |
351 /** |
299 /** |
352 * Generate a string from shortcode parameters. |
300 * Generate a string from shortcode parameters. |
353 * |
301 * |
354 * Creates a shortcode instance and returns a string. |
302 * Creates a shortcode instance and returns a string. |
355 * |
303 * |
490 * |
438 * |
491 * @param {Object} options Options as described. |
439 * @param {Object} options Options as described. |
492 * |
440 * |
493 * @return {WPShortcode} Shortcode instance. |
441 * @return {WPShortcode} Shortcode instance. |
494 */ |
442 */ |
495 |
443 const shortcode = Object.assign(function (options) { |
496 const shortcode = (0,external_lodash_namespaceObject.extend)(function (options) { |
444 const { |
497 (0,external_lodash_namespaceObject.extend)(this, (0,external_lodash_namespaceObject.pick)(options || {}, 'tag', 'attrs', 'type', 'content')); |
445 tag, |
498 const attributes = this.attrs; // Ensure we have a correctly formatted `attrs` object. |
446 attrs: attributes, |
499 |
447 type, |
|
448 content |
|
449 } = options || {}; |
|
450 Object.assign(this, { |
|
451 tag, |
|
452 type, |
|
453 content |
|
454 }); |
|
455 |
|
456 // Ensure we have a correctly formatted `attrs` object. |
500 this.attrs = { |
457 this.attrs = { |
501 named: {}, |
458 named: {}, |
502 numeric: [] |
459 numeric: [] |
503 }; |
460 }; |
504 |
|
505 if (!attributes) { |
461 if (!attributes) { |
506 return; |
462 return; |
507 } // Parse a string of attributes. |
463 } |
508 |
464 const attributeTypes = ['named', 'numeric']; |
509 |
465 |
510 if ((0,external_lodash_namespaceObject.isString)(attributes)) { |
466 // Parse a string of attributes. |
511 this.attrs = attrs(attributes); // Identify a correctly formatted `attrs` object. |
467 if (typeof attributes === 'string') { |
512 } else if ((0,external_lodash_namespaceObject.isEqual)(Object.keys(attributes), ['named', 'numeric'])) { |
468 this.attrs = attrs(attributes); |
513 this.attrs = attributes; // Handle a flat object of attributes. |
469 // Identify a correctly formatted `attrs` object. |
|
470 } else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) { |
|
471 this.attrs = attributes; |
|
472 // Handle a flat object of attributes. |
514 } else { |
473 } else { |
515 (0,external_lodash_namespaceObject.forEach)(attributes, (value, key) => { |
474 Object.entries(attributes).forEach(([key, value]) => { |
516 this.set(key, value); |
475 this.set(key, value); |
517 }); |
476 }); |
518 } |
477 } |
519 }, { |
478 }, { |
520 next, |
479 next, |
549 * @param {string} value Attribute value. |
507 * @param {string} value Attribute value. |
550 * |
508 * |
551 * @return {WPShortcode} Shortcode instance. |
509 * @return {WPShortcode} Shortcode instance. |
552 */ |
510 */ |
553 set(attr, value) { |
511 set(attr, value) { |
554 this.attrs[(0,external_lodash_namespaceObject.isNumber)(attr) ? 'numeric' : 'named'][attr] = value; |
512 this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value; |
555 return this; |
513 return this; |
556 }, |
514 }, |
557 |
|
558 /** |
515 /** |
559 * Transform the shortcode into a string. |
516 * Transform the shortcode into a string. |
560 * |
517 * |
561 * @return {string} String representation of the shortcode. |
518 * @return {string} String representation of the shortcode. |
562 */ |
519 */ |
563 string() { |
520 string() { |
564 let text = '[' + this.tag; |
521 let text = '[' + this.tag; |
565 (0,external_lodash_namespaceObject.forEach)(this.attrs.numeric, value => { |
522 this.attrs.numeric.forEach(value => { |
566 if (/\s/.test(value)) { |
523 if (/\s/.test(value)) { |
567 text += ' "' + value + '"'; |
524 text += ' "' + value + '"'; |
568 } else { |
525 } else { |
569 text += ' ' + value; |
526 text += ' ' + value; |
570 } |
527 } |
571 }); |
528 }); |
572 (0,external_lodash_namespaceObject.forEach)(this.attrs.named, (value, name) => { |
529 Object.entries(this.attrs.named).forEach(([name, value]) => { |
573 text += ' ' + name + '="' + value + '"'; |
530 text += ' ' + name + '="' + value + '"'; |
574 }); // If the tag is marked as `single` or `self-closing`, close the tag and |
531 }); |
|
532 |
|
533 // If the tag is marked as `single` or `self-closing`, close the tag and |
575 // ignore any additional content. |
534 // ignore any additional content. |
576 |
|
577 if ('single' === this.type) { |
535 if ('single' === this.type) { |
578 return text + ']'; |
536 return text + ']'; |
579 } else if ('self-closing' === this.type) { |
537 } else if ('self-closing' === this.type) { |
580 return text + ' /]'; |
538 return text + ' /]'; |
581 } // Complete the opening tag. |
539 } |
582 |
540 |
583 |
541 // Complete the opening tag. |
584 text += ']'; |
542 text += ']'; |
585 |
|
586 if (this.content) { |
543 if (this.content) { |
587 text += this.content; |
544 text += this.content; |
588 } // Add the closing tag. |
545 } |
589 |
546 |
590 |
547 // Add the closing tag. |
591 return text + '[/' + this.tag + ']'; |
548 return text + '[/' + this.tag + ']'; |
592 } |
549 } |
593 |
|
594 }); |
550 }); |
595 /* harmony default export */ var build_module = (shortcode); |
551 /* harmony default export */ const build_module = (shortcode); |
596 |
552 |
597 }(); |
|
598 (window.wp = window.wp || {}).shortcode = __webpack_exports__["default"]; |
553 (window.wp = window.wp || {}).shortcode = __webpack_exports__["default"]; |
599 /******/ })() |
554 /******/ })() |
600 ; |
555 ; |