author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1 |
/******/ (() => { // webpackBootstrap |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2 |
/******/ "use strict"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3 |
/******/ // The require scope |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4 |
/******/ var __webpack_require__ = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5 |
/******/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6 |
/************************************************************************/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7 |
/******/ /* webpack/runtime/define property getters */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8 |
/******/ (() => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9 |
/******/ // define getter functions for harmony exports |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
10 |
/******/ __webpack_require__.d = (exports, definition) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
11 |
/******/ for(var key in definition) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
12 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
13 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
14 |
/******/ } |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
15 |
/******/ } |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
16 |
/******/ }; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
17 |
/******/ })(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
18 |
/******/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
19 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
20 |
/******/ (() => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
21 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
22 |
/******/ })(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
23 |
/******/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
24 |
/************************************************************************/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
25 |
var __webpack_exports__ = {}; |
9 | 26 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
// EXPORTS |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
28 |
__webpack_require__.d(__webpack_exports__, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
29 |
"default": () => (/* binding */ build_module) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
30 |
}); |
9 | 31 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
// UNUSED EXPORTS: attrs, fromMatch, next, regexp, replace, string |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
34 |
;// ./node_modules/memize/dist/index.js |
16 | 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 |
*/ |
|
9 | 54 |
|
16 | 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 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
* @template {(...args: any[]) => any} F |
16 | 68 |
* |
69 |
* @param {F} fn Function to memoize. |
|
70 |
* @param {MemizeOptions} [options] Options object. |
|
71 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
72 |
* @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function. |
16 | 73 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
74 |
function memize(fn, options) { |
16 | 75 |
var size = 0; |
76 |
||
77 |
/** @type {?MemizeCacheNode|undefined} */ |
|
78 |
var head; |
|
79 |
||
80 |
/** @type {?MemizeCacheNode|undefined} */ |
|
81 |
var tail; |
|
82 |
||
83 |
options = options || {}; |
|
9 | 84 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
85 |
function memoized(/* ...args */) { |
9 | 86 |
var node = head, |
87 |
len = arguments.length, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
88 |
args, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
89 |
i; |
9 | 90 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
91 |
searchCache: while (node) { |
9 | 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 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
99 |
if (node.args.length !== arguments.length) { |
9 | 100 |
node = node.next; |
101 |
continue; |
|
102 |
} |
|
103 |
||
104 |
// Check whether node arguments match arguments values |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
105 |
for (i = 0; i < len; i++) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
106 |
if (node.args[i] !== arguments[i]) { |
9 | 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 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
if (node !== head) { |
9 | 116 |
// As tail, shift to previous. Must only shift if not also |
117 |
// head, since if both head and tail, there is no previous. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
118 |
if (node === tail) { |
9 | 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. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
/** @type {MemizeCacheNode} */ (node.prev).next = node.next; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
if (node.next) { |
9 | 126 |
node.next.prev = node.prev; |
127 |
} |
|
128 |
||
129 |
node.next = head; |
|
130 |
node.prev = null; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
/** @type {MemizeCacheNode} */ (head).prev = node; |
9 | 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) |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
args = new Array(len); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
for (i = 0; i < len; i++) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
144 |
args[i] = arguments[i]; |
9 | 145 |
} |
146 |
||
147 |
node = { |
|
148 |
args: args, |
|
149 |
||
150 |
// Generate the result from original function |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
151 |
val: fn.apply(null, args), |
9 | 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 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
158 |
if (head) { |
9 | 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 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
167 |
if (size === /** @type {MemizeOptions} */ (options).maxSize) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
168 |
tail = /** @type {MemizeCacheNode} */ (tail).prev; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
169 |
/** @type {MemizeCacheNode} */ (tail).next = null; |
9 | 170 |
} else { |
171 |
size++; |
|
172 |
} |
|
173 |
||
174 |
head = node; |
|
175 |
||
176 |
return node.val; |
|
177 |
} |
|
178 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
memoized.clear = function () { |
9 | 180 |
head = null; |
181 |
tail = null; |
|
182 |
size = 0; |
|
183 |
}; |
|
184 |
||
16 | 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 |
|
9 | 191 |
return memoized; |
16 | 192 |
} |
193 |
||
9 | 194 |
|
195 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
196 |
;// ./node_modules/@wordpress/shortcode/build-module/index.js |
19 | 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 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
210 |
* @return {import('./types').ShortcodeMatch | undefined} Matched information. |
19 | 211 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
212 |
function next(tag, text, index = 0) { |
19 | 213 |
const re = regexp(tag); |
214 |
re.lastIndex = index; |
|
215 |
const match = re.exec(text); |
|
216 |
if (!match) { |
|
217 |
return; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
218 |
} |
19 | 219 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
220 |
// If we matched an escaped shortcode, try again. |
19 | 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) |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
228 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
229 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
230 |
// If we matched a leading `[`, strip it from the match and increment the |
19 | 231 |
// index accordingly. |
232 |
if (match[1]) { |
|
233 |
result.content = result.content.slice(1); |
|
234 |
result.index++; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
235 |
} |
19 | 236 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
237 |
// If we matched a trailing `]`, strip it from the match. |
19 | 238 |
if (match[7]) { |
239 |
result.content = result.content.slice(0, -1); |
|
240 |
} |
|
241 |
return result; |
|
242 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
243 |
|
19 | 244 |
/** |
245 |
* Replace matching shortcodes in a block of text. |
|
246 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
247 |
* @param {string} tag Shortcode tag. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
248 |
* @param {string} text Text to search. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
249 |
* @param {import('./types').ReplaceCallback} callback Function to process the match and return |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
250 |
* replacement string. |
19 | 251 |
* |
252 |
* @return {string} Text with shortcodes replaced. |
|
253 |
*/ |
|
254 |
function 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; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
260 |
} |
19 | 261 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
262 |
// Create the match object and pass it through the callback. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
263 |
const result = callback(fromMatch(arguments)); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
264 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
// Make sure to return any of the extra brackets if they weren't used to |
19 | 266 |
// escape the shortcode. |
267 |
return result || result === '' ? left + result + right : match; |
|
268 |
}); |
|
269 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
270 |
|
19 | 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 |
*/ |
|
284 |
function string(options) { |
|
285 |
return new shortcode(options).string(); |
|
286 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
287 |
|
19 | 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 |
*/ |
|
308 |
function regexp(tag) { |
|
309 |
return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g'); |
|
310 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
311 |
|
19 | 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 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
327 |
* @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes. |
19 | 328 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
329 |
const attrs = memize(text => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
330 |
const named = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
331 |
const numeric = []; |
19 | 332 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
333 |
// This regular expression is reused from `shortcode_parse_atts()` in |
19 | 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. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
347 |
const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g; |
19 | 348 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
349 |
// Map zero-width spaces to actual spaces. |
19 | 350 |
text = text.replace(/[\u00a0\u200b]/g, ' '); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
351 |
let match; |
19 | 352 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
353 |
// Match and normalize attributes. |
19 | 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 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
|
19 | 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 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
382 |
* @param {import('./types').Match} match Match array. |
19 | 383 |
* |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
384 |
* @return {InstanceType<import('./types').shortcode>} Shortcode instance. |
19 | 385 |
*/ |
386 |
function 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 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
402 |
|
19 | 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 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
411 |
* @type {import('./types').shortcode} Shortcode instance. |
19 | 412 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
const shortcode = Object.assign(function (options) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
const { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
tag, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
416 |
attrs: attributes, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
type, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
content |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
} = options || {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
Object.assign(this, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
tag, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
type, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
content |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
}); |
19 | 425 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
426 |
// Ensure we have a correctly formatted `attrs` object. |
19 | 427 |
this.attrs = { |
428 |
named: {}, |
|
429 |
numeric: [] |
|
430 |
}; |
|
431 |
if (!attributes) { |
|
432 |
return; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
433 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
434 |
const attributeTypes = ['named', 'numeric']; |
19 | 435 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
436 |
// Parse a string of attributes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
437 |
if (typeof attributes === 'string') { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
438 |
this.attrs = attrs(attributes); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
439 |
// Identify a correctly formatted `attrs` object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
440 |
} else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
441 |
this.attrs = attributes; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
442 |
// Handle a flat object of attributes. |
19 | 443 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
444 |
Object.entries(attributes).forEach(([key, value]) => { |
19 | 445 |
this.set(key, value); |
446 |
}); |
|
447 |
} |
|
448 |
}, { |
|
449 |
next, |
|
450 |
replace, |
|
451 |
string, |
|
452 |
regexp, |
|
453 |
attrs, |
|
454 |
fromMatch |
|
455 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
456 |
Object.assign(shortcode.prototype, { |
19 | 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) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
return this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr]; |
19 | 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 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
479 |
* @return {InstanceType< import('./types').shortcode >} Shortcode instance. |
19 | 480 |
*/ |
481 |
set(attr, value) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
482 |
this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value; |
19 | 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; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
492 |
this.attrs.numeric.forEach(value => { |
19 | 493 |
if (/\s/.test(value)) { |
494 |
text += ' "' + value + '"'; |
|
495 |
} else { |
|
496 |
text += ' ' + value; |
|
497 |
} |
|
498 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
499 |
Object.entries(this.attrs.named).forEach(([name, value]) => { |
19 | 500 |
text += ' ' + name + '="' + value + '"'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
501 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
502 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
503 |
// If the tag is marked as `single` or `self-closing`, close the tag and |
19 | 504 |
// ignore any additional content. |
505 |
if ('single' === this.type) { |
|
506 |
return text + ']'; |
|
507 |
} else if ('self-closing' === this.type) { |
|
508 |
return text + ' /]'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
509 |
} |
19 | 510 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
511 |
// Complete the opening tag. |
19 | 512 |
text += ']'; |
513 |
if (this.content) { |
|
514 |
text += this.content; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
515 |
} |
19 | 516 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
517 |
// Add the closing tag. |
19 | 518 |
return text + '[/' + this.tag + ']'; |
519 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
520 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
521 |
/* harmony default export */ const build_module = (shortcode); |
19 | 522 |
|
523 |
(window.wp = window.wp || {}).shortcode = __webpack_exports__["default"]; |
|
524 |
/******/ })() |
|
525 |
; |