PageSourceSearch

https://maestriartifex.com/wp-includes/js/dist/shortcode.js

js maestriartifex.com collected 2026-10-08 03:32:45 UTC 14,578 bytes, 525 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.