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 |
19 | 2 |
/******/ var __webpack_modules__ = ({ |
3 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4 |
/***/ 2058: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5 |
/***/ ((module, exports, __webpack_require__) => { |
9 | 6 |
|
7 |
var __WEBPACK_AMD_DEFINE_RESULT__;/* global window, exports, define */ |
|
8 |
||
9 |
!function() { |
|
10 |
'use strict' |
|
11 |
||
12 |
var re = { |
|
13 |
not_string: /[^s]/, |
|
14 |
not_bool: /[^t]/, |
|
15 |
not_type: /[^T]/, |
|
16 |
not_primitive: /[^v]/, |
|
17 |
number: /[diefg]/, |
|
18 |
numeric_arg: /[bcdiefguxX]/, |
|
19 |
json: /[j]/, |
|
20 |
not_json: /[^j]/, |
|
21 |
text: /^[^\x25]+/, |
|
22 |
modulo: /^\x25{2}/, |
|
23 |
placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/, |
|
24 |
key: /^([a-z_][a-z_\d]*)/i, |
|
25 |
key_access: /^\.([a-z_][a-z_\d]*)/i, |
|
26 |
index_access: /^\[(\d+)\]/, |
|
27 |
sign: /^[+-]/ |
|
28 |
} |
|
29 |
||
30 |
function sprintf(key) { |
|
31 |
// `arguments` is not an array, but should be fine for this call |
|
32 |
return sprintf_format(sprintf_parse(key), arguments) |
|
33 |
} |
|
34 |
||
35 |
function vsprintf(fmt, argv) { |
|
36 |
return sprintf.apply(null, [fmt].concat(argv || [])) |
|
37 |
} |
|
38 |
||
39 |
function sprintf_format(parse_tree, argv) { |
|
40 |
var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign |
|
41 |
for (i = 0; i < tree_length; i++) { |
|
42 |
if (typeof parse_tree[i] === 'string') { |
|
43 |
output += parse_tree[i] |
|
44 |
} |
|
45 |
else if (typeof parse_tree[i] === 'object') { |
|
46 |
ph = parse_tree[i] // convenience purposes only |
|
47 |
if (ph.keys) { // keyword argument |
|
48 |
arg = argv[cursor] |
|
49 |
for (k = 0; k < ph.keys.length; k++) { |
|
50 |
if (arg == undefined) { |
|
51 |
throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1])) |
|
52 |
} |
|
53 |
arg = arg[ph.keys[k]] |
|
54 |
} |
|
55 |
} |
|
56 |
else if (ph.param_no) { // positional argument (explicit) |
|
57 |
arg = argv[ph.param_no] |
|
58 |
} |
|
59 |
else { // positional argument (implicit) |
|
60 |
arg = argv[cursor++] |
|
61 |
} |
|
62 |
||
63 |
if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) { |
|
64 |
arg = arg() |
|
65 |
} |
|
66 |
||
67 |
if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) { |
|
68 |
throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg)) |
|
69 |
} |
|
70 |
||
71 |
if (re.number.test(ph.type)) { |
|
72 |
is_positive = arg >= 0 |
|
73 |
} |
|
74 |
||
75 |
switch (ph.type) { |
|
76 |
case 'b': |
|
77 |
arg = parseInt(arg, 10).toString(2) |
|
78 |
break |
|
79 |
case 'c': |
|
80 |
arg = String.fromCharCode(parseInt(arg, 10)) |
|
81 |
break |
|
82 |
case 'd': |
|
83 |
case 'i': |
|
84 |
arg = parseInt(arg, 10) |
|
85 |
break |
|
86 |
case 'j': |
|
87 |
arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0) |
|
88 |
break |
|
89 |
case 'e': |
|
90 |
arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential() |
|
91 |
break |
|
92 |
case 'f': |
|
93 |
arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg) |
|
94 |
break |
|
95 |
case 'g': |
|
96 |
arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg) |
|
97 |
break |
|
98 |
case 'o': |
|
99 |
arg = (parseInt(arg, 10) >>> 0).toString(8) |
|
100 |
break |
|
101 |
case 's': |
|
102 |
arg = String(arg) |
|
103 |
arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
|
104 |
break |
|
105 |
case 't': |
|
106 |
arg = String(!!arg) |
|
107 |
arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
|
108 |
break |
|
109 |
case 'T': |
|
110 |
arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase() |
|
111 |
arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
|
112 |
break |
|
113 |
case 'u': |
|
114 |
arg = parseInt(arg, 10) >>> 0 |
|
115 |
break |
|
116 |
case 'v': |
|
117 |
arg = arg.valueOf() |
|
118 |
arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
|
119 |
break |
|
120 |
case 'x': |
|
121 |
arg = (parseInt(arg, 10) >>> 0).toString(16) |
|
122 |
break |
|
123 |
case 'X': |
|
124 |
arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase() |
|
125 |
break |
|
126 |
} |
|
127 |
if (re.json.test(ph.type)) { |
|
128 |
output += arg |
|
129 |
} |
|
130 |
else { |
|
131 |
if (re.number.test(ph.type) && (!is_positive || ph.sign)) { |
|
132 |
sign = is_positive ? '+' : '-' |
|
133 |
arg = arg.toString().replace(re.sign, '') |
|
134 |
} |
|
135 |
else { |
|
136 |
sign = '' |
|
137 |
} |
|
138 |
pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' ' |
|
139 |
pad_length = ph.width - (sign + arg).length |
|
140 |
pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : '' |
|
141 |
output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg) |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
return output |
|
146 |
} |
|
147 |
||
148 |
var sprintf_cache = Object.create(null) |
|
149 |
||
150 |
function sprintf_parse(fmt) { |
|
151 |
if (sprintf_cache[fmt]) { |
|
152 |
return sprintf_cache[fmt] |
|
153 |
} |
|
154 |
||
155 |
var _fmt = fmt, match, parse_tree = [], arg_names = 0 |
|
156 |
while (_fmt) { |
|
157 |
if ((match = re.text.exec(_fmt)) !== null) { |
|
158 |
parse_tree.push(match[0]) |
|
159 |
} |
|
160 |
else if ((match = re.modulo.exec(_fmt)) !== null) { |
|
161 |
parse_tree.push('%') |
|
162 |
} |
|
163 |
else if ((match = re.placeholder.exec(_fmt)) !== null) { |
|
164 |
if (match[2]) { |
|
165 |
arg_names |= 1 |
|
166 |
var field_list = [], replacement_field = match[2], field_match = [] |
|
167 |
if ((field_match = re.key.exec(replacement_field)) !== null) { |
|
168 |
field_list.push(field_match[1]) |
|
169 |
while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { |
|
170 |
if ((field_match = re.key_access.exec(replacement_field)) !== null) { |
|
171 |
field_list.push(field_match[1]) |
|
172 |
} |
|
173 |
else if ((field_match = re.index_access.exec(replacement_field)) !== null) { |
|
174 |
field_list.push(field_match[1]) |
|
175 |
} |
|
176 |
else { |
|
177 |
throw new SyntaxError('[sprintf] failed to parse named argument key') |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
else { |
|
182 |
throw new SyntaxError('[sprintf] failed to parse named argument key') |
|
183 |
} |
|
184 |
match[2] = field_list |
|
185 |
} |
|
186 |
else { |
|
187 |
arg_names |= 2 |
|
188 |
} |
|
189 |
if (arg_names === 3) { |
|
190 |
throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported') |
|
191 |
} |
|
192 |
||
193 |
parse_tree.push( |
|
194 |
{ |
|
195 |
placeholder: match[0], |
|
196 |
param_no: match[1], |
|
197 |
keys: match[2], |
|
198 |
sign: match[3], |
|
199 |
pad_char: match[4], |
|
200 |
align: match[5], |
|
201 |
width: match[6], |
|
202 |
precision: match[7], |
|
203 |
type: match[8] |
|
204 |
} |
|
205 |
) |
|
206 |
} |
|
207 |
else { |
|
208 |
throw new SyntaxError('[sprintf] unexpected placeholder') |
|
209 |
} |
|
210 |
_fmt = _fmt.substring(match[0].length) |
|
211 |
} |
|
212 |
return sprintf_cache[fmt] = parse_tree |
|
213 |
} |
|
214 |
||
215 |
/** |
|
216 |
* export to either browser or node.js |
|
217 |
*/ |
|
218 |
/* eslint-disable quote-props */ |
|
219 |
if (true) { |
|
19 | 220 |
exports.sprintf = sprintf |
221 |
exports.vsprintf = vsprintf |
|
9 | 222 |
} |
223 |
if (typeof window !== 'undefined') { |
|
224 |
window['sprintf'] = sprintf |
|
225 |
window['vsprintf'] = vsprintf |
|
226 |
||
227 |
if (true) { |
|
228 |
!(__WEBPACK_AMD_DEFINE_RESULT__ = (function() { |
|
229 |
return { |
|
230 |
'sprintf': sprintf, |
|
231 |
'vsprintf': vsprintf |
|
232 |
} |
|
233 |
}).call(exports, __webpack_require__, exports, module), |
|
19 | 234 |
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) |
9 | 235 |
} |
236 |
} |
|
237 |
/* eslint-enable quote-props */ |
|
238 |
}(); // eslint-disable-line |
|
239 |
||
240 |
||
19 | 241 |
/***/ }) |
18 | 242 |
|
19 | 243 |
/******/ }); |
244 |
/************************************************************************/ |
|
245 |
/******/ // The module cache |
|
246 |
/******/ var __webpack_module_cache__ = {}; |
|
247 |
/******/ |
|
248 |
/******/ // The require function |
|
249 |
/******/ function __webpack_require__(moduleId) { |
|
250 |
/******/ // Check if module is in cache |
|
251 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
|
252 |
/******/ if (cachedModule !== undefined) { |
|
253 |
/******/ return cachedModule.exports; |
|
254 |
/******/ } |
|
255 |
/******/ // Create a new module (and put it into the cache) |
|
256 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
|
257 |
/******/ // no module.id needed |
|
258 |
/******/ // no module.loaded needed |
|
259 |
/******/ exports: {} |
|
260 |
/******/ }; |
|
261 |
/******/ |
|
262 |
/******/ // Execute the module function |
|
263 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
|
264 |
/******/ |
|
265 |
/******/ // Return the exports of the module |
|
266 |
/******/ return module.exports; |
|
267 |
/******/ } |
|
268 |
/******/ |
|
269 |
/************************************************************************/ |
|
270 |
/******/ /* webpack/runtime/compat get default export */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
271 |
/******/ (() => { |
19 | 272 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
/******/ __webpack_require__.n = (module) => { |
19 | 274 |
/******/ var getter = module && module.__esModule ? |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
275 |
/******/ () => (module['default']) : |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
276 |
/******/ () => (module); |
19 | 277 |
/******/ __webpack_require__.d(getter, { a: getter }); |
278 |
/******/ return getter; |
|
279 |
/******/ }; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
280 |
/******/ })(); |
19 | 281 |
/******/ |
282 |
/******/ /* webpack/runtime/define property getters */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
283 |
/******/ (() => { |
19 | 284 |
/******/ // define getter functions for harmony exports |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
285 |
/******/ __webpack_require__.d = (exports, definition) => { |
19 | 286 |
/******/ for(var key in definition) { |
287 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
|
288 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
|
289 |
/******/ } |
|
290 |
/******/ } |
|
291 |
/******/ }; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
292 |
/******/ })(); |
19 | 293 |
/******/ |
294 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
295 |
/******/ (() => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
296 |
/******/ __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
|
297 |
/******/ })(); |
19 | 298 |
/******/ |
299 |
/******/ /* webpack/runtime/make namespace object */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
300 |
/******/ (() => { |
19 | 301 |
/******/ // define __esModule on exports |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
302 |
/******/ __webpack_require__.r = (exports) => { |
19 | 303 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
304 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
305 |
/******/ } |
|
306 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
307 |
/******/ }; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
308 |
/******/ })(); |
19 | 309 |
/******/ |
310 |
/************************************************************************/ |
|
311 |
var __webpack_exports__ = {}; |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
312 |
// This entry needs to be wrapped in an IIFE because it needs to be in strict mode. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
313 |
(() => { |
9 | 314 |
"use strict"; |
16 | 315 |
// ESM COMPAT FLAG |
316 |
__webpack_require__.r(__webpack_exports__); |
|
317 |
||
318 |
// EXPORTS |
|
19 | 319 |
__webpack_require__.d(__webpack_exports__, { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
320 |
__: () => (/* reexport */ __), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
_n: () => (/* reexport */ _n), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
322 |
_nx: () => (/* reexport */ _nx), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
323 |
_x: () => (/* reexport */ _x), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
324 |
createI18n: () => (/* reexport */ createI18n), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
325 |
defaultI18n: () => (/* reexport */ default_i18n), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
326 |
getLocaleData: () => (/* reexport */ getLocaleData), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
327 |
hasTranslation: () => (/* reexport */ hasTranslation), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
328 |
isRTL: () => (/* reexport */ isRTL), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
329 |
resetLocaleData: () => (/* reexport */ resetLocaleData), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
330 |
setLocaleData: () => (/* reexport */ setLocaleData), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
331 |
sprintf: () => (/* reexport */ sprintf_sprintf), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
332 |
subscribe: () => (/* reexport */ subscribe) |
19 | 333 |
}); |
16 | 334 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
335 |
;// ./node_modules/memize/dist/index.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
336 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
337 |
* Memize options object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
338 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
* @typedef MemizeOptions |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
340 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
341 |
* @property {number} [maxSize] Maximum size of the cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
342 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
343 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
344 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
345 |
* Internal cache entry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
346 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
347 |
* @typedef MemizeCacheNode |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
348 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
349 |
* @property {?MemizeCacheNode|undefined} [prev] Previous node. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
350 |
* @property {?MemizeCacheNode|undefined} [next] Next node. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
351 |
* @property {Array<*>} args Function arguments for cache |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
352 |
* entry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
353 |
* @property {*} val Function result. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
354 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
355 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
356 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
357 |
* Properties of the enhanced function for controlling cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
358 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
359 |
* @typedef MemizeMemoizedFunction |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
360 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
361 |
* @property {()=>void} clear Clear the cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
362 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
363 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
364 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
365 |
* Accepts a function to be memoized, and returns a new memoized function, with |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
366 |
* optional options. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
367 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
368 |
* @template {(...args: any[]) => any} F |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
369 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
370 |
* @param {F} fn Function to memoize. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
371 |
* @param {MemizeOptions} [options] Options object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
372 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
373 |
* @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
375 |
function memize(fn, options) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
376 |
var size = 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
377 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
378 |
/** @type {?MemizeCacheNode|undefined} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
379 |
var head; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
380 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
381 |
/** @type {?MemizeCacheNode|undefined} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
382 |
var tail; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
383 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
384 |
options = options || {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
385 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
386 |
function memoized(/* ...args */) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
387 |
var node = head, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
388 |
len = arguments.length, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
389 |
args, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
390 |
i; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
391 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
392 |
searchCache: while (node) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
// Perform a shallow equality test to confirm that whether the node |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
394 |
// under test is a candidate for the arguments passed. Two arrays |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
395 |
// are shallowly equal if their length matches and each entry is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
396 |
// strictly equal between the two sets. Avoid abstracting to a |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
397 |
// function which could incur an arguments leaking deoptimization. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
398 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
399 |
// Check whether node arguments match arguments length |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
400 |
if (node.args.length !== arguments.length) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
401 |
node = node.next; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
402 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
403 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
404 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
405 |
// Check whether node arguments match arguments values |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
406 |
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
|
407 |
if (node.args[i] !== arguments[i]) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
408 |
node = node.next; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
409 |
continue searchCache; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
411 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
412 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
// At this point we can assume we've found a match |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
// Surface matched node to head if not already |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
416 |
if (node !== head) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
// As tail, shift to previous. Must only shift if not also |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
// head, since if both head and tail, there is no previous. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
if (node === tail) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
tail = node.prev; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
// Adjust siblings to point to each other. If node was tail, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
// this also handles new tail's empty `next` assignment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
425 |
/** @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
|
426 |
if (node.next) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
node.next.prev = node.prev; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
429 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
430 |
node.next = head; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
431 |
node.prev = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
432 |
/** @type {MemizeCacheNode} */ (head).prev = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
433 |
head = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
434 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
435 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
436 |
// Return immediately |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
437 |
return node.val; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
438 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
439 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
440 |
// No cached value found. Continue to insertion phase: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
441 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
442 |
// Create a copy of arguments (avoid leaking deoptimization) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
443 |
args = new Array(len); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
444 |
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
|
445 |
args[i] = arguments[i]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
446 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
447 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
448 |
node = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
449 |
args: args, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
450 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
451 |
// Generate the result from original function |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
452 |
val: fn.apply(null, args), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
453 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
454 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
455 |
// Don't need to check whether node is already head, since it would |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
456 |
// have been returned above already if it was |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
457 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
458 |
// Shift existing head down list |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
459 |
if (head) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
460 |
head.prev = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
461 |
node.next = head; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
462 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
463 |
// If no head, follows that there's no tail (at initial or reset) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
464 |
tail = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
465 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
466 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
467 |
// Trim tail if we're reached max size and are pending cache insertion |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
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
|
469 |
tail = /** @type {MemizeCacheNode} */ (tail).prev; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
470 |
/** @type {MemizeCacheNode} */ (tail).next = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
471 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
472 |
size++; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
473 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
474 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
475 |
head = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
476 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
477 |
return node.val; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
478 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
479 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
480 |
memoized.clear = function () { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
481 |
head = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
482 |
tail = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
483 |
size = 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
484 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
485 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
486 |
// Ignore reason: There's not a clear solution to create an intersection of |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
487 |
// the function with additional properties, where the goal is to retain the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
488 |
// function signature of the incoming argument and add control properties |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
// on the return value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
490 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
491 |
// @ts-ignore |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
492 |
return memoized; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
493 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
494 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
495 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
496 |
|
16 | 497 |
// EXTERNAL MODULE: ./node_modules/sprintf-js/src/sprintf.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
498 |
var sprintf = __webpack_require__(2058); |
16 | 499 |
var sprintf_default = /*#__PURE__*/__webpack_require__.n(sprintf); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
500 |
;// ./node_modules/@wordpress/i18n/build-module/sprintf.js |
16 | 501 |
/** |
502 |
* External dependencies |
|
503 |
*/ |
|
504 |
||
505 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
506 |
|
16 | 507 |
/** |
508 |
* Log to console, once per message; or more precisely, per referentially equal |
|
509 |
* argument set. Because Jed throws errors, we log these to the console instead |
|
510 |
* to avoid crashing the application. |
|
511 |
* |
|
512 |
* @param {...*} args Arguments to pass to `console.error` |
|
513 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
514 |
const logErrorOnce = memize(console.error); // eslint-disable-line no-console |
16 | 515 |
|
516 |
/** |
|
517 |
* Returns a formatted string. If an error occurs in applying the format, the |
|
518 |
* original format string is returned. |
|
519 |
* |
|
19 | 520 |
* @param {string} format The format of the string to generate. |
521 |
* @param {...*} args Arguments to apply to the format. |
|
16 | 522 |
* |
18 | 523 |
* @see https://www.npmjs.com/package/sprintf-js |
16 | 524 |
* |
525 |
* @return {string} The formatted string. |
|
526 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
527 |
function sprintf_sprintf(format, ...args) { |
16 | 528 |
try { |
19 | 529 |
return sprintf_default().sprintf(format, ...args); |
16 | 530 |
} catch (error) { |
19 | 531 |
if (error instanceof Error) { |
532 |
logErrorOnce('sprintf error: \n\n' + error.toString()); |
|
533 |
} |
|
16 | 534 |
return format; |
9 | 535 |
} |
536 |
} |
|
537 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
538 |
;// ./node_modules/@tannin/postfix/index.js |
9 | 539 |
var PRECEDENCE, OPENERS, TERMINATORS, PATTERN; |
540 |
||
541 |
/** |
|
542 |
* Operator precedence mapping. |
|
543 |
* |
|
544 |
* @type {Object} |
|
545 |
*/ |
|
546 |
PRECEDENCE = { |
|
547 |
'(': 9, |
|
548 |
'!': 8, |
|
549 |
'*': 7, |
|
550 |
'/': 7, |
|
551 |
'%': 7, |
|
552 |
'+': 6, |
|
553 |
'-': 6, |
|
554 |
'<': 5, |
|
555 |
'<=': 5, |
|
556 |
'>': 5, |
|
557 |
'>=': 5, |
|
558 |
'==': 4, |
|
559 |
'!=': 4, |
|
560 |
'&&': 3, |
|
561 |
'||': 2, |
|
562 |
'?': 1, |
|
563 |
'?:': 1, |
|
564 |
}; |
|
565 |
||
566 |
/** |
|
567 |
* Characters which signal pair opening, to be terminated by terminators. |
|
568 |
* |
|
569 |
* @type {string[]} |
|
570 |
*/ |
|
571 |
OPENERS = [ '(', '?' ]; |
|
572 |
||
573 |
/** |
|
574 |
* Characters which signal pair termination, the value an array with the |
|
575 |
* opener as its first member. The second member is an optional operator |
|
576 |
* replacement to push to the stack. |
|
577 |
* |
|
578 |
* @type {string[]} |
|
579 |
*/ |
|
580 |
TERMINATORS = { |
|
581 |
')': [ '(' ], |
|
582 |
':': [ '?', '?:' ], |
|
583 |
}; |
|
584 |
||
585 |
/** |
|
586 |
* Pattern matching operators and openers. |
|
587 |
* |
|
588 |
* @type {RegExp} |
|
589 |
*/ |
|
590 |
PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/; |
|
591 |
||
592 |
/** |
|
593 |
* Given a C expression, returns the equivalent postfix (Reverse Polish) |
|
594 |
* notation terms as an array. |
|
595 |
* |
|
596 |
* If a postfix string is desired, simply `.join( ' ' )` the result. |
|
597 |
* |
|
598 |
* @example |
|
599 |
* |
|
600 |
* ```js |
|
601 |
* import postfix from '@tannin/postfix'; |
|
602 |
* |
|
603 |
* postfix( 'n > 1' ); |
|
604 |
* // ⇒ [ 'n', '1', '>' ] |
|
605 |
* ``` |
|
606 |
* |
|
607 |
* @param {string} expression C expression. |
|
608 |
* |
|
609 |
* @return {string[]} Postfix terms. |
|
610 |
*/ |
|
611 |
function postfix( expression ) { |
|
612 |
var terms = [], |
|
613 |
stack = [], |
|
614 |
match, operator, term, element; |
|
615 |
||
616 |
while ( ( match = expression.match( PATTERN ) ) ) { |
|
617 |
operator = match[ 0 ]; |
|
618 |
||
619 |
// Term is the string preceding the operator match. It may contain |
|
620 |
// whitespace, and may be empty (if operator is at beginning). |
|
621 |
term = expression.substr( 0, match.index ).trim(); |
|
622 |
if ( term ) { |
|
623 |
terms.push( term ); |
|
624 |
} |
|
625 |
||
626 |
while ( ( element = stack.pop() ) ) { |
|
627 |
if ( TERMINATORS[ operator ] ) { |
|
628 |
if ( TERMINATORS[ operator ][ 0 ] === element ) { |
|
629 |
// Substitution works here under assumption that because |
|
630 |
// the assigned operator will no longer be a terminator, it |
|
631 |
// will be pushed to the stack during the condition below. |
|
632 |
operator = TERMINATORS[ operator ][ 1 ] || operator; |
|
633 |
break; |
|
634 |
} |
|
635 |
} else if ( OPENERS.indexOf( element ) >= 0 || PRECEDENCE[ element ] < PRECEDENCE[ operator ] ) { |
|
636 |
// Push to stack if either an opener or when pop reveals an |
|
637 |
// element of lower precedence. |
|
638 |
stack.push( element ); |
|
639 |
break; |
|
640 |
} |
|
641 |
||
642 |
// For each popped from stack, push to terms. |
|
643 |
terms.push( element ); |
|
644 |
} |
|
645 |
||
646 |
if ( ! TERMINATORS[ operator ] ) { |
|
647 |
stack.push( operator ); |
|
648 |
} |
|
649 |
||
650 |
// Slice matched fragment from expression to continue match. |
|
651 |
expression = expression.substr( match.index + operator.length ); |
|
652 |
} |
|
653 |
||
654 |
// Push remainder of operand, if exists, to terms. |
|
655 |
expression = expression.trim(); |
|
656 |
if ( expression ) { |
|
657 |
terms.push( expression ); |
|
658 |
} |
|
659 |
||
660 |
// Pop remaining items from stack into terms. |
|
661 |
return terms.concat( stack.reverse() ); |
|
662 |
} |
|
663 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
664 |
;// ./node_modules/@tannin/evaluate/index.js |
9 | 665 |
/** |
666 |
* Operator callback functions. |
|
667 |
* |
|
668 |
* @type {Object} |
|
669 |
*/ |
|
670 |
var OPERATORS = { |
|
671 |
'!': function( a ) { |
|
672 |
return ! a; |
|
673 |
}, |
|
674 |
'*': function( a, b ) { |
|
675 |
return a * b; |
|
676 |
}, |
|
677 |
'/': function( a, b ) { |
|
678 |
return a / b; |
|
679 |
}, |
|
680 |
'%': function( a, b ) { |
|
681 |
return a % b; |
|
682 |
}, |
|
683 |
'+': function( a, b ) { |
|
684 |
return a + b; |
|
685 |
}, |
|
686 |
'-': function( a, b ) { |
|
687 |
return a - b; |
|
688 |
}, |
|
689 |
'<': function( a, b ) { |
|
690 |
return a < b; |
|
691 |
}, |
|
692 |
'<=': function( a, b ) { |
|
693 |
return a <= b; |
|
694 |
}, |
|
695 |
'>': function( a, b ) { |
|
696 |
return a > b; |
|
697 |
}, |
|
698 |
'>=': function( a, b ) { |
|
699 |
return a >= b; |
|
700 |
}, |
|
701 |
'==': function( a, b ) { |
|
702 |
return a === b; |
|
703 |
}, |
|
704 |
'!=': function( a, b ) { |
|
705 |
return a !== b; |
|
706 |
}, |
|
707 |
'&&': function( a, b ) { |
|
708 |
return a && b; |
|
709 |
}, |
|
710 |
'||': function( a, b ) { |
|
711 |
return a || b; |
|
712 |
}, |
|
713 |
'?:': function( a, b, c ) { |
|
714 |
if ( a ) { |
|
715 |
throw b; |
|
716 |
} |
|
717 |
||
718 |
return c; |
|
719 |
}, |
|
720 |
}; |
|
721 |
||
722 |
/** |
|
723 |
* Given an array of postfix terms and operand variables, returns the result of |
|
724 |
* the postfix evaluation. |
|
725 |
* |
|
726 |
* @example |
|
727 |
* |
|
728 |
* ```js |
|
729 |
* import evaluate from '@tannin/evaluate'; |
|
730 |
* |
|
731 |
* // 3 + 4 * 5 / 6 ⇒ '3 4 5 * 6 / +' |
|
732 |
* const terms = [ '3', '4', '5', '*', '6', '/', '+' ]; |
|
733 |
* |
|
734 |
* evaluate( terms, {} ); |
|
735 |
* // ⇒ 6.333333333333334 |
|
736 |
* ``` |
|
737 |
* |
|
738 |
* @param {string[]} postfix Postfix terms. |
|
739 |
* @param {Object} variables Operand variables. |
|
740 |
* |
|
741 |
* @return {*} Result of evaluation. |
|
742 |
*/ |
|
19 | 743 |
function evaluate( postfix, variables ) { |
9 | 744 |
var stack = [], |
745 |
i, j, args, getOperatorResult, term, value; |
|
746 |
||
747 |
for ( i = 0; i < postfix.length; i++ ) { |
|
748 |
term = postfix[ i ]; |
|
749 |
||
750 |
getOperatorResult = OPERATORS[ term ]; |
|
751 |
if ( getOperatorResult ) { |
|
752 |
// Pop from stack by number of function arguments. |
|
753 |
j = getOperatorResult.length; |
|
754 |
args = Array( j ); |
|
755 |
while ( j-- ) { |
|
756 |
args[ j ] = stack.pop(); |
|
757 |
} |
|
758 |
||
759 |
try { |
|
760 |
value = getOperatorResult.apply( null, args ); |
|
761 |
} catch ( earlyReturn ) { |
|
762 |
return earlyReturn; |
|
763 |
} |
|
764 |
} else if ( variables.hasOwnProperty( term ) ) { |
|
765 |
value = variables[ term ]; |
|
766 |
} else { |
|
767 |
value = +term; |
|
768 |
} |
|
769 |
||
770 |
stack.push( value ); |
|
771 |
} |
|
772 |
||
773 |
return stack[ 0 ]; |
|
774 |
} |
|
775 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
776 |
;// ./node_modules/@tannin/compile/index.js |
9 | 777 |
|
778 |
||
779 |
||
780 |
/** |
|
781 |
* Given a C expression, returns a function which can be called to evaluate its |
|
782 |
* result. |
|
783 |
* |
|
784 |
* @example |
|
785 |
* |
|
786 |
* ```js |
|
787 |
* import compile from '@tannin/compile'; |
|
788 |
* |
|
789 |
* const evaluate = compile( 'n > 1' ); |
|
790 |
* |
|
791 |
* evaluate( { n: 2 } ); |
|
792 |
* // ⇒ true |
|
793 |
* ``` |
|
794 |
* |
|
795 |
* @param {string} expression C expression. |
|
796 |
* |
|
16 | 797 |
* @return {(variables?:{[variable:string]:*})=>*} Compiled evaluator. |
9 | 798 |
*/ |
799 |
function compile( expression ) { |
|
800 |
var terms = postfix( expression ); |
|
801 |
||
802 |
return function( variables ) { |
|
19 | 803 |
return evaluate( terms, variables ); |
9 | 804 |
}; |
805 |
} |
|
806 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
807 |
;// ./node_modules/@tannin/plural-forms/index.js |
9 | 808 |
|
809 |
||
810 |
/** |
|
811 |
* Given a C expression, returns a function which, when called with a value, |
|
812 |
* evaluates the result with the value assumed to be the "n" variable of the |
|
813 |
* expression. The result will be coerced to its numeric equivalent. |
|
814 |
* |
|
815 |
* @param {string} expression C expression. |
|
816 |
* |
|
817 |
* @return {Function} Evaluator function. |
|
818 |
*/ |
|
819 |
function pluralForms( expression ) { |
|
820 |
var evaluate = compile( expression ); |
|
821 |
||
822 |
return function( n ) { |
|
823 |
return +evaluate( { n: n } ); |
|
824 |
}; |
|
825 |
} |
|
826 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
827 |
;// ./node_modules/tannin/index.js |
9 | 828 |
|
829 |
||
830 |
/** |
|
831 |
* Tannin constructor options. |
|
832 |
* |
|
16 | 833 |
* @typedef {Object} TanninOptions |
834 |
* |
|
835 |
* @property {string} [contextDelimiter] Joiner in string lookup with context. |
|
836 |
* @property {Function} [onMissingKey] Callback to invoke when key missing. |
|
837 |
*/ |
|
838 |
||
839 |
/** |
|
840 |
* Domain metadata. |
|
841 |
* |
|
842 |
* @typedef {Object} TanninDomainMetadata |
|
9 | 843 |
* |
16 | 844 |
* @property {string} [domain] Domain name. |
845 |
* @property {string} [lang] Language code. |
|
846 |
* @property {(string|Function)} [plural_forms] Plural forms expression or |
|
847 |
* function evaluator. |
|
848 |
*/ |
|
849 |
||
850 |
/** |
|
851 |
* Domain translation pair respectively representing the singular and plural |
|
852 |
* translation. |
|
9 | 853 |
* |
16 | 854 |
* @typedef {[string,string]} TanninTranslation |
855 |
*/ |
|
856 |
||
857 |
/** |
|
858 |
* Locale data domain. The key is used as reference for lookup, the value an |
|
859 |
* array of two string entries respectively representing the singular and plural |
|
860 |
* translation. |
|
861 |
* |
|
862 |
* @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain |
|
863 |
*/ |
|
864 |
||
865 |
/** |
|
866 |
* Jed-formatted locale data. |
|
867 |
* |
|
868 |
* @see http://messageformat.github.io/Jed/ |
|
869 |
* |
|
870 |
* @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData |
|
9 | 871 |
*/ |
872 |
||
873 |
/** |
|
874 |
* Default Tannin constructor options. |
|
875 |
* |
|
876 |
* @type {TanninOptions} |
|
877 |
*/ |
|
878 |
var DEFAULT_OPTIONS = { |
|
879 |
contextDelimiter: '\u0004', |
|
880 |
onMissingKey: null, |
|
881 |
}; |
|
882 |
||
883 |
/** |
|
884 |
* Given a specific locale data's config `plural_forms` value, returns the |
|
885 |
* expression. |
|
886 |
* |
|
887 |
* @example |
|
888 |
* |
|
889 |
* ``` |
|
890 |
* getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)' |
|
891 |
* ``` |
|
892 |
* |
|
893 |
* @param {string} pf Locale data plural forms. |
|
894 |
* |
|
895 |
* @return {string} Plural forms expression. |
|
896 |
*/ |
|
897 |
function getPluralExpression( pf ) { |
|
898 |
var parts, i, part; |
|
899 |
||
900 |
parts = pf.split( ';' ); |
|
901 |
||
902 |
for ( i = 0; i < parts.length; i++ ) { |
|
903 |
part = parts[ i ].trim(); |
|
904 |
if ( part.indexOf( 'plural=' ) === 0 ) { |
|
905 |
return part.substr( 7 ); |
|
906 |
} |
|
907 |
} |
|
908 |
} |
|
909 |
||
910 |
/** |
|
911 |
* Tannin constructor. |
|
912 |
* |
|
16 | 913 |
* @class |
914 |
* |
|
915 |
* @param {TanninLocaleData} data Jed-formatted locale data. |
|
916 |
* @param {TanninOptions} [options] Tannin options. |
|
9 | 917 |
*/ |
918 |
function Tannin( data, options ) { |
|
919 |
var key; |
|
920 |
||
16 | 921 |
/** |
922 |
* Jed-formatted locale data. |
|
923 |
* |
|
924 |
* @name Tannin#data |
|
925 |
* @type {TanninLocaleData} |
|
926 |
*/ |
|
9 | 927 |
this.data = data; |
16 | 928 |
|
929 |
/** |
|
930 |
* Plural forms function cache, keyed by plural forms string. |
|
931 |
* |
|
932 |
* @name Tannin#pluralForms |
|
933 |
* @type {Object<string,Function>} |
|
934 |
*/ |
|
9 | 935 |
this.pluralForms = {}; |
936 |
||
16 | 937 |
/** |
938 |
* Effective options for instance, including defaults. |
|
939 |
* |
|
940 |
* @name Tannin#options |
|
941 |
* @type {TanninOptions} |
|
942 |
*/ |
|
9 | 943 |
this.options = {}; |
16 | 944 |
|
9 | 945 |
for ( key in DEFAULT_OPTIONS ) { |
16 | 946 |
this.options[ key ] = options !== undefined && key in options |
947 |
? options[ key ] |
|
948 |
: DEFAULT_OPTIONS[ key ]; |
|
9 | 949 |
} |
950 |
} |
|
951 |
||
952 |
/** |
|
953 |
* Returns the plural form index for the given domain and value. |
|
954 |
* |
|
955 |
* @param {string} domain Domain on which to calculate plural form. |
|
956 |
* @param {number} n Value for which plural form is to be calculated. |
|
957 |
* |
|
958 |
* @return {number} Plural form index. |
|
959 |
*/ |
|
960 |
Tannin.prototype.getPluralForm = function( domain, n ) { |
|
961 |
var getPluralForm = this.pluralForms[ domain ], |
|
962 |
config, plural, pf; |
|
963 |
||
964 |
if ( ! getPluralForm ) { |
|
965 |
config = this.data[ domain ][ '' ]; |
|
966 |
||
967 |
pf = ( |
|
968 |
config[ 'Plural-Forms' ] || |
|
969 |
config[ 'plural-forms' ] || |
|
16 | 970 |
// Ignore reason: As known, there's no way to document the empty |
971 |
// string property on a key to guarantee this as metadata. |
|
972 |
// @ts-ignore |
|
9 | 973 |
config.plural_forms |
974 |
); |
|
975 |
||
976 |
if ( typeof pf !== 'function' ) { |
|
977 |
plural = getPluralExpression( |
|
978 |
config[ 'Plural-Forms' ] || |
|
979 |
config[ 'plural-forms' ] || |
|
16 | 980 |
// Ignore reason: As known, there's no way to document the empty |
981 |
// string property on a key to guarantee this as metadata. |
|
982 |
// @ts-ignore |
|
9 | 983 |
config.plural_forms |
984 |
); |
|
985 |
||
986 |
pf = pluralForms( plural ); |
|
987 |
} |
|
988 |
||
989 |
getPluralForm = this.pluralForms[ domain ] = pf; |
|
990 |
} |
|
991 |
||
992 |
return getPluralForm( n ); |
|
993 |
}; |
|
994 |
||
995 |
/** |
|
996 |
* Translate a string. |
|
997 |
* |
|
16 | 998 |
* @param {string} domain Translation domain. |
999 |
* @param {string|void} context Context distinguishing terms of the same name. |
|
1000 |
* @param {string} singular Primary key for translation lookup. |
|
1001 |
* @param {string=} plural Fallback value used for non-zero plural |
|
1002 |
* form index. |
|
1003 |
* @param {number=} n Value to use in calculating plural form. |
|
9 | 1004 |
* |
1005 |
* @return {string} Translated string. |
|
1006 |
*/ |
|
1007 |
Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) { |
|
1008 |
var index, key, entry; |
|
1009 |
||
1010 |
if ( n === undefined ) { |
|
1011 |
// Default to singular. |
|
1012 |
index = 0; |
|
1013 |
} else { |
|
1014 |
// Find index by evaluating plural form for value. |
|
1015 |
index = this.getPluralForm( domain, n ); |
|
1016 |
} |
|
1017 |
||
1018 |
key = singular; |
|
1019 |
||
1020 |
// If provided, context is prepended to key with delimiter. |
|
1021 |
if ( context ) { |
|
1022 |
key = context + this.options.contextDelimiter + singular; |
|
1023 |
} |
|
1024 |
||
1025 |
entry = this.data[ domain ][ key ]; |
|
1026 |
||
1027 |
// Verify not only that entry exists, but that the intended index is within |
|
1028 |
// range and non-empty. |
|
1029 |
if ( entry && entry[ index ] ) { |
|
1030 |
return entry[ index ]; |
|
1031 |
} |
|
1032 |
||
1033 |
if ( this.options.onMissingKey ) { |
|
1034 |
this.options.onMissingKey( singular, domain ); |
|
1035 |
} |
|
1036 |
||
1037 |
// If entry not found, fall back to singular vs. plural with zero index |
|
1038 |
// representing the singular value. |
|
1039 |
return index === 0 ? singular : plural; |
|
1040 |
}; |
|
1041 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1042 |
;// ./node_modules/@wordpress/i18n/build-module/create-i18n.js |
9 | 1043 |
/** |
1044 |
* External dependencies |
|
1045 |
*/ |
|
1046 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1047 |
|
16 | 1048 |
/** |
1049 |
* @typedef {Record<string,any>} LocaleData |
|
1050 |
*/ |
|
9 | 1051 |
|
1052 |
/** |
|
1053 |
* Default locale data to use for Tannin domain when not otherwise provided. |
|
1054 |
* Assumes an English plural forms expression. |
|
1055 |
* |
|
16 | 1056 |
* @type {LocaleData} |
9 | 1057 |
*/ |
18 | 1058 |
const DEFAULT_LOCALE_DATA = { |
9 | 1059 |
'': { |
16 | 1060 |
/** @param {number} n */ |
18 | 1061 |
plural_forms(n) { |
16 | 1062 |
return n === 1 ? 0 : 1; |
1063 |
} |
|
9 | 1064 |
} |
1065 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1066 |
|
18 | 1067 |
/* |
1068 |
* Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`, |
|
1069 |
* `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`. |
|
1070 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1071 |
const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/; |
18 | 1072 |
|
1073 |
/** |
|
1074 |
* @typedef {(domain?: string) => LocaleData} GetLocaleData |
|
1075 |
* |
|
1076 |
* Returns locale data by domain in a |
|
1077 |
* Jed-formatted JSON object shape. |
|
1078 |
* |
|
1079 |
* @see http://messageformat.github.io/Jed/ |
|
1080 |
*/ |
|
1081 |
/** |
|
1082 |
* @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData |
|
1083 |
* |
|
19 | 1084 |
* Merges locale data into the Tannin instance by domain. Note that this |
1085 |
* function will overwrite the domain configuration. Accepts data in a |
|
1086 |
* Jed-formatted JSON object shape. |
|
1087 |
* |
|
1088 |
* @see http://messageformat.github.io/Jed/ |
|
1089 |
*/ |
|
1090 |
/** |
|
1091 |
* @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData |
|
1092 |
* |
|
1093 |
* Merges locale data into the Tannin instance by domain. Note that this |
|
1094 |
* function will also merge the domain configuration. Accepts data in a |
|
18 | 1095 |
* Jed-formatted JSON object shape. |
1096 |
* |
|
1097 |
* @see http://messageformat.github.io/Jed/ |
|
1098 |
*/ |
|
1099 |
/** |
|
1100 |
* @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData |
|
1101 |
* |
|
1102 |
* Resets all current Tannin instance locale data and sets the specified |
|
1103 |
* locale data for the domain. Accepts data in a Jed-formatted JSON object shape. |
|
1104 |
* |
|
1105 |
* @see http://messageformat.github.io/Jed/ |
|
1106 |
*/ |
|
1107 |
/** @typedef {() => void} SubscribeCallback */ |
|
1108 |
/** @typedef {() => void} UnsubscribeCallback */ |
|
1109 |
/** |
|
1110 |
* @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe |
|
1111 |
* |
|
1112 |
* Subscribes to changes of locale data |
|
1113 |
*/ |
|
1114 |
/** |
|
1115 |
* @typedef {(domain?: string) => string} GetFilterDomain |
|
1116 |
* Retrieve the domain to use when calling domain-specific filters. |
|
1117 |
*/ |
|
1118 |
/** |
|
1119 |
* @typedef {(text: string, domain?: string) => string} __ |
|
1120 |
* |
|
1121 |
* Retrieve the translation of text. |
|
1122 |
* |
|
1123 |
* @see https://developer.wordpress.org/reference/functions/__/ |
|
1124 |
*/ |
|
1125 |
/** |
|
1126 |
* @typedef {(text: string, context: string, domain?: string) => string} _x |
|
1127 |
* |
|
1128 |
* Retrieve translated string with gettext context. |
|
1129 |
* |
|
1130 |
* @see https://developer.wordpress.org/reference/functions/_x/ |
|
1131 |
*/ |
|
1132 |
/** |
|
1133 |
* @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n |
|
1134 |
* |
|
1135 |
* Translates and retrieves the singular or plural form based on the supplied |
|
1136 |
* number. |
|
1137 |
* |
|
1138 |
* @see https://developer.wordpress.org/reference/functions/_n/ |
|
1139 |
*/ |
|
1140 |
/** |
|
1141 |
* @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx |
|
1142 |
* |
|
1143 |
* Translates and retrieves the singular or plural form based on the supplied |
|
1144 |
* number, with gettext context. |
|
1145 |
* |
|
1146 |
* @see https://developer.wordpress.org/reference/functions/_nx/ |
|
1147 |
*/ |
|
1148 |
/** |
|
1149 |
* @typedef {() => boolean} IsRtl |
|
1150 |
* |
|
1151 |
* Check if current locale is RTL. |
|
1152 |
* |
|
1153 |
* **RTL (Right To Left)** is a locale property indicating that text is written from right to left. |
|
1154 |
* For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common |
|
1155 |
* language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages, |
|
1156 |
* including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`). |
|
1157 |
*/ |
|
1158 |
/** |
|
1159 |
* @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation |
|
1160 |
* |
|
1161 |
* Check if there is a translation for a given string in singular form. |
|
1162 |
*/ |
|
1163 |
/** @typedef {import('@wordpress/hooks').Hooks} Hooks */ |
|
1164 |
||
9 | 1165 |
/** |
16 | 1166 |
* An i18n instance |
9 | 1167 |
* |
18 | 1168 |
* @typedef I18n |
19 | 1169 |
* @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape. |
1170 |
* @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this |
|
1171 |
* function will overwrite the domain configuration. Accepts data in a |
|
1172 |
* Jed-formatted JSON object shape. |
|
1173 |
* @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this |
|
1174 |
* function will also merge the domain configuration. Accepts data in a |
|
18 | 1175 |
* Jed-formatted JSON object shape. |
1176 |
* @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified |
|
1177 |
* locale data for the domain. Accepts data in a Jed-formatted JSON object shape. |
|
19 | 1178 |
* @property {Subscribe} subscribe Subscribes to changes of Tannin locale data. |
1179 |
* @property {__} __ Retrieve the translation of text. |
|
1180 |
* @property {_x} _x Retrieve translated string with gettext context. |
|
1181 |
* @property {_n} _n Translates and retrieves the singular or plural form based on the supplied |
|
18 | 1182 |
* number. |
19 | 1183 |
* @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied |
18 | 1184 |
* number, with gettext context. |
19 | 1185 |
* @property {IsRtl} isRTL Check if current locale is RTL. |
1186 |
* @property {HasTranslation} hasTranslation Check if there is a translation for a given string. |
|
16 | 1187 |
*/ |
1188 |
||
1189 |
/** |
|
1190 |
* Create an i18n instance |
|
1191 |
* |
|
19 | 1192 |
* @param {LocaleData} [initialData] Locale data configuration. |
1193 |
* @param {string} [initialDomain] Domain for which configuration applies. |
|
1194 |
* @param {Hooks} [hooks] Hooks implementation. |
|
1195 |
* |
|
1196 |
* @return {I18n} I18n instance. |
|
9 | 1197 |
*/ |
18 | 1198 |
const createI18n = (initialData, initialDomain, hooks) => { |
16 | 1199 |
/** |
1200 |
* The underlying instance of Tannin to which exported functions interface. |
|
1201 |
* |
|
1202 |
* @type {Tannin} |
|
1203 |
*/ |
|
18 | 1204 |
const tannin = new Tannin({}); |
1205 |
const listeners = new Set(); |
|
1206 |
const notifyListeners = () => { |
|
1207 |
listeners.forEach(listener => listener()); |
|
1208 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1209 |
|
16 | 1210 |
/** |
18 | 1211 |
* Subscribe to changes of locale data. |
16 | 1212 |
* |
18 | 1213 |
* @param {SubscribeCallback} callback Subscription callback. |
1214 |
* @return {UnsubscribeCallback} Unsubscribe callback. |
|
1215 |
*/ |
|
1216 |
const subscribe = callback => { |
|
1217 |
listeners.add(callback); |
|
1218 |
return () => listeners.delete(callback); |
|
1219 |
}; |
|
1220 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1221 |
/** @type {GetLocaleData} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1222 |
const getLocaleData = (domain = 'default') => tannin.data[domain]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1223 |
|
18 | 1224 |
/** |
1225 |
* @param {LocaleData} [data] |
|
19 | 1226 |
* @param {string} [domain] |
16 | 1227 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1228 |
const doSetLocaleData = (data, domain = 'default') => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1229 |
tannin.data[domain] = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1230 |
...tannin.data[domain], |
18 | 1231 |
...data |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1232 |
}; |
16 | 1233 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1234 |
// Populate default domain configuration (supported locale date which omits |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1235 |
// a plural forms expression). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1236 |
tannin.data[domain][''] = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1237 |
...DEFAULT_LOCALE_DATA[''], |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1238 |
...tannin.data[domain]?.[''] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1239 |
}; |
19 | 1240 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1241 |
// Clean up cached plural forms functions cache as it might be updated. |
19 | 1242 |
delete tannin.pluralForms[domain]; |
18 | 1243 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1244 |
|
18 | 1245 |
/** @type {SetLocaleData} */ |
1246 |
const setLocaleData = (data, domain) => { |
|
1247 |
doSetLocaleData(data, domain); |
|
1248 |
notifyListeners(); |
|
1249 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1250 |
|
19 | 1251 |
/** @type {AddLocaleData} */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1252 |
const addLocaleData = (data, domain = 'default') => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1253 |
tannin.data[domain] = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1254 |
...tannin.data[domain], |
19 | 1255 |
...data, |
1256 |
// Populate default domain configuration (supported locale date which omits |
|
1257 |
// a plural forms expression). |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1258 |
'': { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1259 |
...DEFAULT_LOCALE_DATA[''], |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1260 |
...tannin.data[domain]?.[''], |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1261 |
...data?.[''] |
19 | 1262 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1263 |
}; |
19 | 1264 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1265 |
// Clean up cached plural forms functions cache as it might be updated. |
19 | 1266 |
delete tannin.pluralForms[domain]; |
1267 |
notifyListeners(); |
|
1268 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1269 |
|
18 | 1270 |
/** @type {ResetLocaleData} */ |
1271 |
const resetLocaleData = (data, domain) => { |
|
1272 |
// Reset all current Tannin locale data. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1273 |
tannin.data = {}; |
18 | 1274 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1275 |
// Reset cached plural forms functions cache. |
18 | 1276 |
tannin.pluralForms = {}; |
1277 |
setLocaleData(data, domain); |
|
16 | 1278 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1279 |
|
16 | 1280 |
/** |
1281 |
* Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not |
|
1282 |
* otherwise previously assigned. |
|
1283 |
* |
|
1284 |
* @param {string|undefined} domain Domain to retrieve the translated text. |
|
1285 |
* @param {string|undefined} context Context information for the translators. |
|
1286 |
* @param {string} single Text to translate if non-plural. Used as |
|
1287 |
* fallback return value on a caught error. |
|
1288 |
* @param {string} [plural] The text to be used if the number is |
|
1289 |
* plural. |
|
1290 |
* @param {number} [number] The number to compare against to use |
|
1291 |
* either the singular or plural form. |
|
1292 |
* |
|
1293 |
* @return {string} The translated string. |
|
1294 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1295 |
const dcnpgettext = (domain = 'default', context, single, plural, number) => { |
16 | 1296 |
if (!tannin.data[domain]) { |
19 | 1297 |
// Use `doSetLocaleData` to set silently, without notifying listeners. |
18 | 1298 |
doSetLocaleData(undefined, domain); |
16 | 1299 |
} |
1300 |
return tannin.dcnpgettext(domain, context, single, plural, number); |
|
1301 |
}; |
|
18 | 1302 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1303 |
/** @type {GetFilterDomain} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1304 |
const getFilterDomain = (domain = 'default') => domain; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1305 |
|
18 | 1306 |
/** @type {__} */ |
1307 |
const __ = (text, domain) => { |
|
1308 |
let translation = dcnpgettext(domain, undefined, text); |
|
1309 |
if (!hooks) { |
|
1310 |
return translation; |
|
1311 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1312 |
|
18 | 1313 |
/** |
1314 |
* Filters text with its translation. |
|
1315 |
* |
|
1316 |
* @param {string} translation Translated text. |
|
1317 |
* @param {string} text Text to translate. |
|
1318 |
* @param {string} domain Text domain. Unique identifier for retrieving translated strings. |
|
1319 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1320 |
translation = /** @type {string} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1321 |
/** @type {*} */hooks.applyFilters('i18n.gettext', translation, text, domain); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1322 |
return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain); |
16 | 1323 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1324 |
|
18 | 1325 |
/** @type {_x} */ |
1326 |
const _x = (text, context, domain) => { |
|
1327 |
let translation = dcnpgettext(domain, context, text); |
|
1328 |
if (!hooks) { |
|
1329 |
return translation; |
|
1330 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1331 |
|
18 | 1332 |
/** |
1333 |
* Filters text with its translation based on context information. |
|
1334 |
* |
|
1335 |
* @param {string} translation Translated text. |
|
1336 |
* @param {string} text Text to translate. |
|
1337 |
* @param {string} context Context information for the translators. |
|
1338 |
* @param {string} domain Text domain. Unique identifier for retrieving translated strings. |
|
1339 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1340 |
translation = /** @type {string} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1341 |
/** @type {*} */hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1342 |
return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain); |
18 | 1343 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1344 |
|
18 | 1345 |
/** @type {_n} */ |
1346 |
const _n = (single, plural, number, domain) => { |
|
1347 |
let translation = dcnpgettext(domain, undefined, single, plural, number); |
|
1348 |
if (!hooks) { |
|
1349 |
return translation; |
|
1350 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1351 |
|
18 | 1352 |
/** |
1353 |
* Filters the singular or plural form of a string. |
|
1354 |
* |
|
1355 |
* @param {string} translation Translated text. |
|
1356 |
* @param {string} single The text to be used if the number is singular. |
|
1357 |
* @param {string} plural The text to be used if the number is plural. |
|
1358 |
* @param {string} number The number to compare against to use either the singular or plural form. |
|
1359 |
* @param {string} domain Text domain. Unique identifier for retrieving translated strings. |
|
1360 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1361 |
translation = /** @type {string} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1362 |
/** @type {*} */hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1363 |
return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain); |
16 | 1364 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1365 |
|
18 | 1366 |
/** @type {_nx} */ |
1367 |
const _nx = (single, plural, number, context, domain) => { |
|
1368 |
let translation = dcnpgettext(domain, context, single, plural, number); |
|
1369 |
if (!hooks) { |
|
1370 |
return translation; |
|
1371 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1372 |
|
18 | 1373 |
/** |
1374 |
* Filters the singular or plural form of a string with gettext context. |
|
1375 |
* |
|
1376 |
* @param {string} translation Translated text. |
|
1377 |
* @param {string} single The text to be used if the number is singular. |
|
1378 |
* @param {string} plural The text to be used if the number is plural. |
|
1379 |
* @param {string} number The number to compare against to use either the singular or plural form. |
|
1380 |
* @param {string} context Context information for the translators. |
|
1381 |
* @param {string} domain Text domain. Unique identifier for retrieving translated strings. |
|
1382 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1383 |
translation = /** @type {string} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1384 |
/** @type {*} */hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1385 |
return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain); |
16 | 1386 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1387 |
|
18 | 1388 |
/** @type {IsRtl} */ |
1389 |
const isRTL = () => { |
|
1390 |
return 'rtl' === _x('ltr', 'text direction'); |
|
1391 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1392 |
|
18 | 1393 |
/** @type {HasTranslation} */ |
1394 |
const hasTranslation = (single, context, domain) => { |
|
1395 |
const key = context ? context + '\u0004' + single : single; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1396 |
let result = !!tannin.data?.[domain !== null && domain !== void 0 ? domain : 'default']?.[key]; |
18 | 1397 |
if (hooks) { |
1398 |
/** |
|
1399 |
* Filters the presence of a translation in the locale data. |
|
1400 |
* |
|
1401 |
* @param {boolean} hasTranslation Whether the translation is present or not.. |
|
19 | 1402 |
* @param {string} single The singular form of the translated text (used as key in locale data) |
1403 |
* @param {string} context Context information for the translators. |
|
1404 |
* @param {string} domain Text domain. Unique identifier for retrieving translated strings. |
|
18 | 1405 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1406 |
result = /** @type { boolean } */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1407 |
/** @type {*} */hooks.applyFilters('i18n.has_translation', result, single, context, domain); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1408 |
result = /** @type { boolean } */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1409 |
/** @type {*} */hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain); |
18 | 1410 |
} |
1411 |
return result; |
|
16 | 1412 |
}; |
1413 |
if (initialData) { |
|
1414 |
setLocaleData(initialData, initialDomain); |
|
1415 |
} |
|
18 | 1416 |
if (hooks) { |
1417 |
/** |
|
1418 |
* @param {string} hookName |
|
1419 |
*/ |
|
1420 |
const onHookAddedOrRemoved = hookName => { |
|
1421 |
if (I18N_HOOK_REGEXP.test(hookName)) { |
|
1422 |
notifyListeners(); |
|
1423 |
} |
|
1424 |
}; |
|
1425 |
hooks.addAction('hookAdded', 'core/i18n', onHookAddedOrRemoved); |
|
1426 |
hooks.addAction('hookRemoved', 'core/i18n', onHookAddedOrRemoved); |
|
1427 |
} |
|
16 | 1428 |
return { |
18 | 1429 |
getLocaleData, |
1430 |
setLocaleData, |
|
19 | 1431 |
addLocaleData, |
18 | 1432 |
resetLocaleData, |
1433 |
subscribe, |
|
1434 |
__, |
|
1435 |
_x, |
|
1436 |
_n, |
|
1437 |
_nx, |
|
1438 |
isRTL, |
|
1439 |
hasTranslation |
|
16 | 1440 |
}; |
1441 |
}; |
|
1442 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1443 |
;// external ["wp","hooks"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1444 |
const external_wp_hooks_namespaceObject = window["wp"]["hooks"]; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1445 |
;// ./node_modules/@wordpress/i18n/build-module/default-i18n.js |
16 | 1446 |
/** |
1447 |
* Internal dependencies |
|
1448 |
*/ |
|
1449 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1450 |
|
18 | 1451 |
/** |
1452 |
* WordPress dependencies |
|
1453 |
*/ |
|
1454 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1455 |
const i18n = createI18n(undefined, undefined, external_wp_hooks_namespaceObject.defaultHooks); |
18 | 1456 |
|
1457 |
/** |
|
1458 |
* Default, singleton instance of `I18n`. |
|
1459 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1460 |
/* harmony default export */ const default_i18n = (i18n); |
18 | 1461 |
|
16 | 1462 |
/* |
1463 |
* Comments in this file are duplicated from ./i18n due to |
|
1464 |
* https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722 |
|
1465 |
*/ |
|
9 | 1466 |
|
1467 |
/** |
|
16 | 1468 |
* @typedef {import('./create-i18n').LocaleData} LocaleData |
18 | 1469 |
* @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback |
1470 |
* @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback |
|
9 | 1471 |
*/ |
1472 |
||
1473 |
/** |
|
18 | 1474 |
* Returns locale data by domain in a Jed-formatted JSON object shape. |
1475 |
* |
|
1476 |
* @see http://messageformat.github.io/Jed/ |
|
1477 |
* |
|
1478 |
* @param {string} [domain] Domain for which to get the data. |
|
1479 |
* @return {LocaleData} Locale data. |
|
1480 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1481 |
const getLocaleData = i18n.getLocaleData.bind(i18n); |
18 | 1482 |
|
1483 |
/** |
|
9 | 1484 |
* Merges locale data into the Tannin instance by domain. Accepts data in a |
1485 |
* Jed-formatted JSON object shape. |
|
1486 |
* |
|
1487 |
* @see http://messageformat.github.io/Jed/ |
|
1488 |
* |
|
16 | 1489 |
* @param {LocaleData} [data] Locale data configuration. |
1490 |
* @param {string} [domain] Domain for which configuration applies. |
|
9 | 1491 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1492 |
const setLocaleData = i18n.setLocaleData.bind(i18n); |
9 | 1493 |
|
18 | 1494 |
/** |
1495 |
* Resets all current Tannin instance locale data and sets the specified |
|
1496 |
* locale data for the domain. Accepts data in a Jed-formatted JSON object shape. |
|
1497 |
* |
|
1498 |
* @see http://messageformat.github.io/Jed/ |
|
1499 |
* |
|
1500 |
* @param {LocaleData} [data] Locale data configuration. |
|
1501 |
* @param {string} [domain] Domain for which configuration applies. |
|
1502 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1503 |
const resetLocaleData = i18n.resetLocaleData.bind(i18n); |
18 | 1504 |
|
1505 |
/** |
|
1506 |
* Subscribes to changes of locale data |
|
1507 |
* |
|
1508 |
* @param {SubscribeCallback} callback Subscription callback |
|
1509 |
* @return {UnsubscribeCallback} Unsubscribe callback |
|
1510 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1511 |
const subscribe = i18n.subscribe.bind(i18n); |
18 | 1512 |
|
9 | 1513 |
/** |
1514 |
* Retrieve the translation of text. |
|
1515 |
* |
|
1516 |
* @see https://developer.wordpress.org/reference/functions/__/ |
|
1517 |
* |
|
16 | 1518 |
* @param {string} text Text to translate. |
1519 |
* @param {string} [domain] Domain to retrieve the translated text. |
|
9 | 1520 |
* |
1521 |
* @return {string} Translated text. |
|
1522 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1523 |
const __ = i18n.__.bind(i18n); |
9 | 1524 |
|
1525 |
/** |
|
1526 |
* Retrieve translated string with gettext context. |
|
1527 |
* |
|
1528 |
* @see https://developer.wordpress.org/reference/functions/_x/ |
|
1529 |
* |
|
16 | 1530 |
* @param {string} text Text to translate. |
1531 |
* @param {string} context Context information for the translators. |
|
1532 |
* @param {string} [domain] Domain to retrieve the translated text. |
|
9 | 1533 |
* |
1534 |
* @return {string} Translated context string without pipe. |
|
1535 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1536 |
const _x = i18n._x.bind(i18n); |
9 | 1537 |
|
1538 |
/** |
|
1539 |
* Translates and retrieves the singular or plural form based on the supplied |
|
1540 |
* number. |
|
1541 |
* |
|
1542 |
* @see https://developer.wordpress.org/reference/functions/_n/ |
|
1543 |
* |
|
16 | 1544 |
* @param {string} single The text to be used if the number is singular. |
1545 |
* @param {string} plural The text to be used if the number is plural. |
|
1546 |
* @param {number} number The number to compare against to use either the |
|
1547 |
* singular or plural form. |
|
1548 |
* @param {string} [domain] Domain to retrieve the translated text. |
|
9 | 1549 |
* |
1550 |
* @return {string} The translated singular or plural form. |
|
1551 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1552 |
const _n = i18n._n.bind(i18n); |
9 | 1553 |
|
1554 |
/** |
|
1555 |
* Translates and retrieves the singular or plural form based on the supplied |
|
1556 |
* number, with gettext context. |
|
1557 |
* |
|
1558 |
* @see https://developer.wordpress.org/reference/functions/_nx/ |
|
1559 |
* |
|
16 | 1560 |
* @param {string} single The text to be used if the number is singular. |
1561 |
* @param {string} plural The text to be used if the number is plural. |
|
1562 |
* @param {number} number The number to compare against to use either the |
|
9 | 1563 |
* singular or plural form. |
16 | 1564 |
* @param {string} context Context information for the translators. |
1565 |
* @param {string} [domain] Domain to retrieve the translated text. |
|
9 | 1566 |
* |
1567 |
* @return {string} The translated singular or plural form. |
|
1568 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1569 |
const _nx = i18n._nx.bind(i18n); |
9 | 1570 |
|
1571 |
/** |
|
16 | 1572 |
* Check if current locale is RTL. |
9 | 1573 |
* |
16 | 1574 |
* **RTL (Right To Left)** is a locale property indicating that text is written from right to left. |
1575 |
* For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common |
|
1576 |
* language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages, |
|
1577 |
* including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`). |
|
9 | 1578 |
* |
16 | 1579 |
* @return {boolean} Whether locale is RTL. |
9 | 1580 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1581 |
const isRTL = i18n.isRTL.bind(i18n); |
9 | 1582 |
|
18 | 1583 |
/** |
1584 |
* Check if there is a translation for a given string (in singular form). |
|
1585 |
* |
|
19 | 1586 |
* @param {string} single Singular form of the string to look up. |
18 | 1587 |
* @param {string} [context] Context information for the translators. |
19 | 1588 |
* @param {string} [domain] Domain to retrieve the translated text. |
18 | 1589 |
* @return {boolean} Whether the translation exists or not. |
1590 |
*/ |
|
19 | 1591 |
const hasTranslation = i18n.hasTranslation.bind(i18n); |
9 | 1592 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1593 |
;// ./node_modules/@wordpress/i18n/build-module/index.js |
16 | 1594 |
|
1595 |
||
1596 |
||
9 | 1597 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1598 |
})(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1599 |
|
19 | 1600 |
(window.wp = window.wp || {}).i18n = __webpack_exports__; |
1601 |
/******/ })() |
|
1602 |
; |