@fldr/ui 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/.build-complete +1 -1
  2. package/dist/ai/schemas.d.ts +18 -18
  3. package/dist/chunks/{code-nj2nu6qzxhz6qnkk.js → code-hp2x28uiufmk3elz.js} +2 -4
  4. package/dist/chunks/highlighter-mouttug0tu8xg1i8.js +1364 -0
  5. package/dist/code/server.d.ts +4 -89
  6. package/dist/code/server.js +3 -136
  7. package/dist/code.d.ts +53 -70
  8. package/dist/code.js +186 -327
  9. package/dist/command-line/cli.js +0 -0
  10. package/dist/command-line/commands/add.js +0 -0
  11. package/dist/command-line/commands/ai.js +0 -0
  12. package/dist/command-line/commands/blocks.js +0 -0
  13. package/dist/command-line/commands/doc.js +0 -0
  14. package/dist/command-line/commands/init.js +0 -0
  15. package/dist/command-line/commands/ls.js +0 -0
  16. package/dist/components/code.d.ts +1 -1
  17. package/dist/components/code.js +1 -1
  18. package/dist/highlighter-BT3TakhJ.d.ts +13 -0
  19. package/dist/{index-B9niVl3r.d.ts → index-CNL6VDYZ.d.ts} +2 -4
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/styles/kumo-binding.css +1 -0
  23. package/dist/styles/kumo-standalone.css +1 -1
  24. package/dist/styles/kumo.css +20 -38
  25. package/dist/styles/theme-code.css +142 -0
  26. package/dist/styles/theme-fldr.css +429 -15
  27. package/dist/theming.d.ts +71 -32
  28. package/dist/theming.js +162 -17
  29. package/package.json +2 -4
  30. package/scripts/css-build.ts +1 -0
  31. package/scripts/publish-fldr.ts +62 -10
  32. package/scripts/theme-generator/index.ts +15 -5
  33. package/dist/chunks/bash-jpzh6zbf5237424t.js +0 -3
  34. package/dist/chunks/core-n0de50o00ej2ecfe.js +0 -7177
  35. package/dist/chunks/css-j501gxq1am2gnikh.js +0 -4
  36. package/dist/chunks/diff-g2re0kj6fh27rgg5.js +0 -4
  37. package/dist/chunks/engine-javascript-e9xj8hhz9xfqhpnu.js +0 -3118
  38. package/dist/chunks/engine-oniguruma-ias56ildu01gf939.js +0 -389
  39. package/dist/chunks/github-light-hir7yctc38258pwt.js +0 -5
  40. package/dist/chunks/graphql-n9vlzkvcp2j19p7a.js +0 -16
  41. package/dist/chunks/hcl-ohpfnrffs96hzyj5.js +0 -4
  42. package/dist/chunks/html-nimj6ljkkifnc9ni.js +0 -12
  43. package/dist/chunks/javascript-b6fq9bl50fdj6813.js +0 -4
  44. package/dist/chunks/json-h2g0z143t3cs13d7.js +0 -4
  45. package/dist/chunks/jsonc-jxlzvingck161eej.js +0 -4
  46. package/dist/chunks/jsx-jp7a33937sef92sn.js +0 -4
  47. package/dist/chunks/markdown-eybeqjr58vfygtz1.js +0 -4
  48. package/dist/chunks/python-nrpnmxq4r6yp6fcd.js +0 -4
  49. package/dist/chunks/shellscript-i4m7lo8wi0f5bl8b.js +0 -4
  50. package/dist/chunks/sql-hqp2eekl7qhmxe92.js +0 -4
  51. package/dist/chunks/toml-oyqrgosuct25x413.js +0 -4
  52. package/dist/chunks/tsx-pem8x69upvmibv6l.js +0 -4
  53. package/dist/chunks/typescript-pe5y016phdwbgws7.js +0 -4
  54. package/dist/chunks/vesper-g839e590k3dxnwh3.js +0 -5
  55. package/dist/chunks/wasm-cpasy0o9lsjrm39j.js +0 -8
  56. package/dist/chunks/yaml-kzk5ddyekbyha04v.js +0 -4
  57. package/dist/types-C6in2C8V.d.ts +0 -135
@@ -1,3118 +0,0 @@
1
- "use client";
2
- //#region ../../node_modules/.pnpm/@shikijs+engine-javascript@4.3.1/node_modules/@shikijs/engine-javascript/dist/scanner-DX8LRFGE.mjs
3
- const MAX = 4294967295;
4
- var JavaScriptScanner = class {
5
- patterns;
6
- options;
7
- regexps;
8
- constructor(patterns, options = {}) {
9
- this.patterns = patterns;
10
- this.options = options;
11
- const { forgiving = false, cache, regexConstructor } = options;
12
- if (!regexConstructor) throw new Error("Option `regexConstructor` is not provided");
13
- this.regexps = patterns.map((p) => {
14
- if (typeof p !== "string") return p;
15
- const cached = cache?.get(p);
16
- if (cached) {
17
- if (cached instanceof RegExp) return cached;
18
- if (forgiving) return null;
19
- throw cached;
20
- }
21
- try {
22
- const regex = regexConstructor(p);
23
- cache?.set(p, regex);
24
- return regex;
25
- } catch (e) {
26
- cache?.set(p, e);
27
- if (forgiving) return null;
28
- throw e;
29
- }
30
- });
31
- }
32
- findNextMatchSync(string, startPosition, _options) {
33
- const str = typeof string === "string" ? string : string.content;
34
- const pending = [];
35
- function toResult(index, match, offset = 0) {
36
- return {
37
- index,
38
- captureIndices: match.indices.map((indice) => {
39
- if (indice == null) return {
40
- start: MAX,
41
- end: MAX,
42
- length: 0
43
- };
44
- return {
45
- start: indice[0] + offset,
46
- end: indice[1] + offset,
47
- length: indice[1] - indice[0]
48
- };
49
- })
50
- };
51
- }
52
- for (let i = 0; i < this.regexps.length; i++) {
53
- const regexp = this.regexps[i];
54
- if (!regexp) continue;
55
- try {
56
- regexp.lastIndex = startPosition;
57
- const match = regexp.exec(str);
58
- if (!match) continue;
59
- if (match.index === startPosition) return toResult(i, match, 0);
60
- pending.push([
61
- i,
62
- match,
63
- 0
64
- ]);
65
- } catch (e) {
66
- if (this.options.forgiving) continue;
67
- throw e;
68
- }
69
- }
70
- if (pending.length) {
71
- const minIndex = Math.min(...pending.map((m) => m[1].index));
72
- for (const [i, match, offset] of pending) if (match.index === minIndex) return toResult(i, match, offset);
73
- }
74
- return null;
75
- }
76
- };
77
- //#endregion
78
- //#region ../../node_modules/.pnpm/oniguruma-parser@0.12.2/node_modules/oniguruma-parser/dist/utils.js
79
- function r$2(e) {
80
- if ([...e].length !== 1) throw new Error(`Expected "${e}" to be a single code point`);
81
- return e.codePointAt(0);
82
- }
83
- function l$1(e, t, n) {
84
- return e.has(t) || e.set(t, n), e.get(t);
85
- }
86
- const i = /* @__PURE__ */ new Set([
87
- "alnum",
88
- "alpha",
89
- "ascii",
90
- "blank",
91
- "cntrl",
92
- "digit",
93
- "graph",
94
- "lower",
95
- "print",
96
- "punct",
97
- "space",
98
- "upper",
99
- "word",
100
- "xdigit"
101
- ]);
102
- const o$1 = String.raw;
103
- function u(e, t) {
104
- if (e == null) throw new Error(t ?? "Value expected");
105
- return e;
106
- }
107
- //#endregion
108
- //#region ../../node_modules/.pnpm/oniguruma-parser@0.12.2/node_modules/oniguruma-parser/dist/tokenizer/tokenize.js
109
- const m$1 = o$1`\[\^?`;
110
- const b$1 = `c.? | C(?:-.?)?|${o$1`[pP]\{(?:\^?[-\x20_]*[A-Za-z][-\x20\w]*\})?`}|${o$1`x[89A-Fa-f]\p{AHex}(?:\\x[89A-Fa-f]\p{AHex})*`}|${o$1`u(?:\p{AHex}{4})? | x\{[^\}]*\}? | x\p{AHex}{0,2}`}|${o$1`o\{[^\}]*\}?`}|${o$1`\d{1,3}`}`;
111
- const y$1 = /[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/;
112
- const C$1 = new RegExp(o$1`
113
- \\ (?:
114
- ${b$1}
115
- | [gk]<[^>]*>?
116
- | [gk]'[^']*'?
117
- | .
118
- )
119
- | \( (?:
120
- \? (?:
121
- [:=!>({]
122
- | <[=!]
123
- | <[^>]*>
124
- | '[^']*'
125
- | ~\|?
126
- | #(?:[^)\\]|\\.?)*
127
- | [^:)]*[:)]
128
- )?
129
- | \*[^\)]*\)?
130
- )?
131
- | (?:${y$1.source})+
132
- | ${m$1}
133
- | .
134
- `.replace(/\s+/g, ""), "gsu");
135
- const T$1 = new RegExp(o$1`
136
- \\ (?:
137
- ${b$1}
138
- | .
139
- )
140
- | \[:(?:\^?\p{Alpha}+|\^):\]
141
- | ${m$1}
142
- | &&
143
- | .
144
- `.replace(/\s+/g, ""), "gsu");
145
- function M$1(e, n = {}) {
146
- const t = {
147
- flags: "",
148
- ...n,
149
- rules: {
150
- captureGroup: !1,
151
- singleline: !1,
152
- ...n.rules
153
- }
154
- };
155
- if (typeof e != "string") throw new Error("String expected as pattern");
156
- const o = Y(t.flags), s = [o.extended], a = {
157
- captureGroup: t.rules.captureGroup,
158
- getCurrentModX() {
159
- return s.at(-1);
160
- },
161
- numOpenGroups: 0,
162
- popModX() {
163
- s.pop();
164
- },
165
- pushModX(u) {
166
- s.push(u);
167
- },
168
- replaceCurrentModX(u) {
169
- s[s.length - 1] = u;
170
- },
171
- singleline: t.rules.singleline
172
- };
173
- let r = [], i;
174
- for (C$1.lastIndex = 0; i = C$1.exec(e);) {
175
- const u = F$1(a, e, i[0], C$1.lastIndex);
176
- u.tokens ? r.push(...u.tokens) : u.token && r.push(u.token), u.lastIndex !== void 0 && (C$1.lastIndex = u.lastIndex);
177
- }
178
- const l = [];
179
- let c = 0;
180
- r.filter((u) => u.type === "GroupOpen").forEach((u) => {
181
- u.kind === "capturing" ? u.number = ++c : u.raw === "(" && l.push(u);
182
- }), c || l.forEach((u, S) => {
183
- u.kind = "capturing", u.number = S + 1;
184
- });
185
- const g = c || l.length;
186
- return {
187
- tokens: r.map((u) => u.type === "EscapedNumber" ? ee$1(u, g) : u).flat(),
188
- flags: o
189
- };
190
- }
191
- function F$1(e, n, t, o) {
192
- const [s, a] = t;
193
- if (t === "[" || t === "[^") {
194
- const r = K$1(n, t, o);
195
- return {
196
- tokens: r.tokens,
197
- lastIndex: r.lastIndex
198
- };
199
- }
200
- if (s === "\\") {
201
- if ("AbBGyYzZ".includes(a)) return { token: w$1(t, t) };
202
- if (/^\\g[<']/.test(t)) {
203
- if (!/^\\g(?:<[^>]+>|'[^']+')$/.test(t)) throw new Error(`Invalid group name "${t}"`);
204
- return { token: R$1(t) };
205
- }
206
- if (/^\\k[<']/.test(t)) {
207
- if (!/^\\k(?:<[^>]+>|'[^']+')$/.test(t)) throw new Error(`Invalid group name "${t}"`);
208
- return { token: A$1(t) };
209
- }
210
- if (a === "K") return { token: I$1("keep", t) };
211
- if (a === "N" || a === "R") return { token: k$1("newline", t, { negate: a === "N" }) };
212
- if (a === "O") return { token: k$1("any", t) };
213
- if (a === "X") return { token: k$1("text_segment", t) };
214
- const r = x$1(t, { inCharClass: !1 });
215
- return Array.isArray(r) ? { tokens: r } : { token: r };
216
- }
217
- if (s === "(") {
218
- if (a === "*") return { token: j(t) };
219
- if (t === "(?{") throw new Error(`Unsupported callout "${t}"`);
220
- if (t.startsWith("(?#")) {
221
- if (n[o] !== ")") throw new Error("Unclosed comment group \"(?#\"");
222
- return { lastIndex: o + 1 };
223
- }
224
- if (/^\(\?[-imx]+[:)]$/.test(t)) return { token: L$1(t, e) };
225
- if (e.pushModX(e.getCurrentModX()), e.numOpenGroups++, t === "(" && !e.captureGroup || t === "(?:") return { token: f("group", t) };
226
- if (t === "(?>") return { token: f("atomic", t) };
227
- if (t === "(?=" || t === "(?!" || t === "(?<=" || t === "(?<!") return { token: f(t[2] === "<" ? "lookbehind" : "lookahead", t, { negate: t.endsWith("!") }) };
228
- if (t === "(" && e.captureGroup || t.startsWith("(?<") && t.endsWith(">") || t.startsWith("(?'") && t.endsWith("'")) return { token: f("capturing", t, { ...t !== "(" && { name: t.slice(3, -1) } }) };
229
- if (t.startsWith("(?~")) {
230
- if (t === "(?~|") throw new Error(`Unsupported absence function kind "${t}"`);
231
- return { token: f("absence_repeater", t) };
232
- }
233
- throw t === "(?(" ? /* @__PURE__ */ new Error(`Unsupported conditional "${t}"`) : /* @__PURE__ */ new Error(`Invalid or unsupported group option "${t}"`);
234
- }
235
- if (t === ")") {
236
- if (e.popModX(), e.numOpenGroups--, e.numOpenGroups < 0) throw new Error("Unmatched \")\"");
237
- return { token: Q$1(t) };
238
- }
239
- if (e.getCurrentModX()) {
240
- if (t === "#") {
241
- const r = n.indexOf(`
242
- `, o);
243
- return { lastIndex: r === -1 ? n.length : r };
244
- }
245
- if (/^\s$/.test(t)) {
246
- const r = /\s+/y;
247
- return r.lastIndex = o, { lastIndex: r.exec(n) ? r.lastIndex : o };
248
- }
249
- }
250
- if (t === ".") return { token: k$1("dot", t) };
251
- if (t === "^" || t === "$") return { token: w$1(e.singleline ? {
252
- "^": o$1`\A`,
253
- $: o$1`\Z`
254
- }[t] : t, t) };
255
- return t === "|" ? { token: P$1(t) } : y$1.test(t) ? { tokens: te$1(t) } : { token: d(r$2(t), t) };
256
- }
257
- function K$1(e, n, t) {
258
- const o = [E$1(n[1] === "^", n)];
259
- let s = 1, a;
260
- for (T$1.lastIndex = t; a = T$1.exec(e);) {
261
- const r = a[0];
262
- if (r[0] === "[" && r[1] !== ":") s++, o.push(E$1(r[1] === "^", r));
263
- else if (r === "]") {
264
- if (o.at(-1).type === "CharacterClassOpen") o.push(d(93, r));
265
- else if (s--, o.push(z$1(r)), !s) break;
266
- } else {
267
- const i = X$1(r);
268
- Array.isArray(i) ? o.push(...i) : o.push(i);
269
- }
270
- }
271
- return {
272
- tokens: o,
273
- lastIndex: T$1.lastIndex || e.length
274
- };
275
- }
276
- function X$1(e) {
277
- if (e[0] === "\\") return x$1(e, { inCharClass: !0 });
278
- if (e[0] === "[") {
279
- const n = /\[:(?<negate>\^?)(?<name>[a-z]+):\]/.exec(e);
280
- if (!n || !i.has(n.groups.name)) throw new Error(`Invalid POSIX class "${e}"`);
281
- return k$1("posix", e, {
282
- value: n.groups.name,
283
- negate: !!n.groups.negate
284
- });
285
- }
286
- return e === "-" ? U$1(e) : e === "&&" ? H(e) : d(r$2(e), e);
287
- }
288
- function x$1(e, { inCharClass: n }) {
289
- const t = e[1];
290
- if (t === "c" || t === "C") return Z(e);
291
- if ("dDhHsSwW".includes(t)) return q(e);
292
- if (e.startsWith(o$1`\o{`)) throw new Error(`Incomplete, invalid, or unsupported octal code point "${e}"`);
293
- if (/^\\[pP]\{/.test(e)) {
294
- if (e.length === 3) throw new Error(`Incomplete or invalid Unicode property "${e}"`);
295
- return V$1(e);
296
- }
297
- if (/^\\x[89A-Fa-f]\p{AHex}/u.test(e)) try {
298
- const o = e.split(/\\x/).slice(1).map((i) => parseInt(i, 16)), s = new TextDecoder("utf-8", {
299
- ignoreBOM: !0,
300
- fatal: !0
301
- }).decode(new Uint8Array(o)), a = new TextEncoder();
302
- return [...s].map((i) => {
303
- const l = [...a.encode(i)].map((c) => `\\x${c.toString(16)}`).join("");
304
- return d(r$2(i), l);
305
- });
306
- } catch {
307
- throw new Error(`Multibyte code "${e}" incomplete or invalid in Oniguruma`);
308
- }
309
- if (t === "u" || t === "x") return d(J$1(e), e);
310
- if ($$1.has(t)) return d($$1.get(t), e);
311
- if (/\d/.test(t)) return W$1(n, e);
312
- if (e === "\\") throw new Error(o$1`Incomplete escape "\"`);
313
- if (t === "M") throw new Error(`Unsupported meta "${e}"`);
314
- if ([...e].length === 2) return d(e.codePointAt(1), e);
315
- throw new Error(`Unexpected escape "${e}"`);
316
- }
317
- function P$1(e) {
318
- return {
319
- type: "Alternator",
320
- raw: e
321
- };
322
- }
323
- function w$1(e, n) {
324
- return {
325
- type: "Assertion",
326
- kind: e,
327
- raw: n
328
- };
329
- }
330
- function A$1(e) {
331
- return {
332
- type: "Backreference",
333
- raw: e
334
- };
335
- }
336
- function d(e, n) {
337
- return {
338
- type: "Character",
339
- value: e,
340
- raw: n
341
- };
342
- }
343
- function z$1(e) {
344
- return {
345
- type: "CharacterClassClose",
346
- raw: e
347
- };
348
- }
349
- function U$1(e) {
350
- return {
351
- type: "CharacterClassHyphen",
352
- raw: e
353
- };
354
- }
355
- function H(e) {
356
- return {
357
- type: "CharacterClassIntersector",
358
- raw: e
359
- };
360
- }
361
- function E$1(e, n) {
362
- return {
363
- type: "CharacterClassOpen",
364
- negate: e,
365
- raw: n
366
- };
367
- }
368
- function k$1(e, n, t = {}) {
369
- return {
370
- type: "CharacterSet",
371
- kind: e,
372
- ...t,
373
- raw: n
374
- };
375
- }
376
- function I$1(e, n, t = {}) {
377
- return e === "keep" ? {
378
- type: "Directive",
379
- kind: e,
380
- raw: n
381
- } : {
382
- type: "Directive",
383
- kind: e,
384
- flags: u(t.flags),
385
- raw: n
386
- };
387
- }
388
- function W$1(e, n) {
389
- return {
390
- type: "EscapedNumber",
391
- inCharClass: e,
392
- raw: n
393
- };
394
- }
395
- function Q$1(e) {
396
- return {
397
- type: "GroupClose",
398
- raw: e
399
- };
400
- }
401
- function f(e, n, t = {}) {
402
- return {
403
- type: "GroupOpen",
404
- kind: e,
405
- ...t,
406
- raw: n
407
- };
408
- }
409
- function D$1(e, n, t, o) {
410
- return {
411
- type: "NamedCallout",
412
- kind: e,
413
- tag: n,
414
- arguments: t,
415
- raw: o
416
- };
417
- }
418
- function _$1(e, n, t, o) {
419
- return {
420
- type: "Quantifier",
421
- kind: e,
422
- min: n,
423
- max: t,
424
- raw: o
425
- };
426
- }
427
- function R$1(e) {
428
- return {
429
- type: "Subroutine",
430
- raw: e
431
- };
432
- }
433
- const B$1 = /* @__PURE__ */ new Set([
434
- "COUNT",
435
- "CMP",
436
- "ERROR",
437
- "FAIL",
438
- "MAX",
439
- "MISMATCH",
440
- "SKIP",
441
- "TOTAL_COUNT"
442
- ]);
443
- const $$1 = /* @__PURE__ */ new Map([
444
- ["a", 7],
445
- ["b", 8],
446
- ["e", 27],
447
- ["f", 12],
448
- ["n", 10],
449
- ["r", 13],
450
- ["t", 9],
451
- ["v", 11]
452
- ]);
453
- function Z(e) {
454
- const n = e[1] === "c" ? e[2] : e[3];
455
- if (!n || !/[A-Za-z]/.test(n)) throw new Error(`Unsupported control character "${e}"`);
456
- return d(r$2(n.toUpperCase()) - 64, e);
457
- }
458
- function L$1(e, n) {
459
- let { on: t, off: o } = /^\(\?(?<on>[imx]*)(?:-(?<off>[-imx]*))?/.exec(e).groups;
460
- o ??= "";
461
- const s = (n.getCurrentModX() || t.includes("x")) && !o.includes("x"), a = v(t), r = v(o), i = {};
462
- if (a && (i.enable = a), r && (i.disable = r), e.endsWith(")")) return n.replaceCurrentModX(s), I$1("flags", e, { flags: i });
463
- if (e.endsWith(":")) return n.pushModX(s), n.numOpenGroups++, f("group", e, { ...(a || r) && { flags: i } });
464
- throw new Error(`Unexpected flag modifier "${e}"`);
465
- }
466
- function j(e) {
467
- const n = /\(\*(?<name>[A-Za-z_]\w*)?(?:\[(?<tag>(?:[A-Za-z_]\w*)?)\])?(?:\{(?<args>[^}]*)\})?\)/.exec(e);
468
- if (!n) throw new Error(`Incomplete or invalid named callout "${e}"`);
469
- const { name: t, tag: o, args: s } = n.groups;
470
- if (!t) throw new Error(`Invalid named callout "${e}"`);
471
- if (o === "") throw new Error(`Named callout tag with empty value not allowed "${e}"`);
472
- const a = s ? s.split(",").filter((g) => g !== "").map((g) => /^[+-]?\d+$/.test(g) ? +g : g) : [], [r, i, l] = a, c = B$1.has(t) ? t.toLowerCase() : "custom";
473
- switch (c) {
474
- case "fail":
475
- case "mismatch":
476
- case "skip":
477
- if (a.length > 0) throw new Error(`Named callout arguments not allowed "${a}"`);
478
- break;
479
- case "error":
480
- if (a.length > 1) throw new Error(`Named callout allows only one argument "${a}"`);
481
- if (typeof r == "string") throw new Error(`Named callout argument must be a number "${r}"`);
482
- break;
483
- case "max":
484
- if (!a.length || a.length > 2) throw new Error(`Named callout must have one or two arguments "${a}"`);
485
- if (typeof r == "string" && !/^[A-Za-z_]\w*$/.test(r)) throw new Error(`Named callout argument one must be a tag or number "${r}"`);
486
- if (a.length === 2 && (typeof i == "number" || !/^[<>X]$/.test(i))) throw new Error(`Named callout optional argument two must be '<', '>', or 'X' "${i}"`);
487
- break;
488
- case "count":
489
- case "total_count":
490
- if (a.length > 1) throw new Error(`Named callout allows only one argument "${a}"`);
491
- if (a.length === 1 && (typeof r == "number" || !/^[<>X]$/.test(r))) throw new Error(`Named callout optional argument must be '<', '>', or 'X' "${r}"`);
492
- break;
493
- case "cmp":
494
- if (a.length !== 3) throw new Error(`Named callout must have three arguments "${a}"`);
495
- if (typeof r == "string" && !/^[A-Za-z_]\w*$/.test(r)) throw new Error(`Named callout argument one must be a tag or number "${r}"`);
496
- if (typeof i == "number" || !/^(?:[<>!=]=|[<>])$/.test(i)) throw new Error(`Named callout argument two must be '==', '!=', '>', '<', '>=', or '<=' "${i}"`);
497
- if (typeof l == "string" && !/^[A-Za-z_]\w*$/.test(l)) throw new Error(`Named callout argument three must be a tag or number "${l}"`);
498
- break;
499
- case "custom": throw new Error(`Undefined callout name "${t}"`);
500
- default: throw new Error(`Unexpected named callout kind "${c}"`);
501
- }
502
- return D$1(c, o ?? null, s?.split(",") ?? null, e);
503
- }
504
- function O$1(e) {
505
- let n = null, t, o;
506
- if (e[0] === "{") {
507
- const { minStr: s, maxStr: a } = /^\{(?<minStr>\d*)(?:,(?<maxStr>\d*))?/.exec(e).groups, r = 1e5;
508
- if (+s > r || a && +a > r) throw new Error("Quantifier value unsupported in Oniguruma");
509
- if (t = +s, o = a === void 0 ? +s : a === "" ? 1 / 0 : +a, t > o && (n = "possessive", [t, o] = [o, t]), e.endsWith("?")) {
510
- if (n === "possessive") throw new Error("Unsupported possessive interval quantifier chain with \"?\"");
511
- n = "lazy";
512
- } else n || (n = "greedy");
513
- } else t = e[0] === "+" ? 1 : 0, o = e[0] === "?" ? 1 : 1 / 0, n = e[1] === "+" ? "possessive" : e[1] === "?" ? "lazy" : "greedy";
514
- return _$1(n, t, o, e);
515
- }
516
- function q(e) {
517
- const n = e[1].toLowerCase();
518
- return k$1({
519
- d: "digit",
520
- h: "hex",
521
- s: "space",
522
- w: "word"
523
- }[n], e, { negate: e[1] !== n });
524
- }
525
- function V$1(e) {
526
- const { p: n, neg: t, value: o } = /^\\(?<p>[pP])\{(?<neg>\^?)(?<value>[^}]+)/.exec(e).groups;
527
- return k$1("property", e, {
528
- value: o,
529
- negate: n === "P" && !t || n === "p" && !!t
530
- });
531
- }
532
- function v(e) {
533
- const n = {};
534
- return e.includes("i") && (n.ignoreCase = !0), e.includes("m") && (n.dotAll = !0), e.includes("x") && (n.extended = !0), Object.keys(n).length ? n : null;
535
- }
536
- function Y(e) {
537
- const n = {
538
- ignoreCase: !1,
539
- dotAll: !1,
540
- extended: !1,
541
- digitIsAscii: !1,
542
- posixIsAscii: !1,
543
- spaceIsAscii: !1,
544
- wordIsAscii: !1,
545
- textSegmentMode: null
546
- };
547
- for (let t = 0; t < e.length; t++) {
548
- const o = e[t];
549
- if (!"imxDPSWy".includes(o)) throw new Error(`Invalid flag "${o}"`);
550
- if (o === "y") {
551
- if (!/^y{[gw]}/.test(e.slice(t))) throw new Error("Invalid or unspecified flag \"y\" mode");
552
- n.textSegmentMode = e[t + 2] === "g" ? "grapheme" : "word", t += 3;
553
- continue;
554
- }
555
- n[{
556
- i: "ignoreCase",
557
- m: "dotAll",
558
- x: "extended",
559
- D: "digitIsAscii",
560
- P: "posixIsAscii",
561
- S: "spaceIsAscii",
562
- W: "wordIsAscii"
563
- }[o]] = !0;
564
- }
565
- return n;
566
- }
567
- function J$1(e) {
568
- if (/^(?:\\u(?!\p{AHex}{4})|\\x(?!\p{AHex}{1,2}|\{\p{AHex}{1,8}\}))/u.test(e)) throw new Error(`Incomplete or invalid escape "${e}"`);
569
- const n = e[2] === "{" ? /^\\x\{\s*(?<hex>\p{AHex}+)/u.exec(e).groups.hex : e.slice(2);
570
- return parseInt(n, 16);
571
- }
572
- function ee$1(e, n) {
573
- const { raw: t, inCharClass: o } = e, s = t.slice(1);
574
- if (!o && (s !== "0" && s.length === 1 || s[0] !== "0" && +s <= n)) return [A$1(t)];
575
- const a = [], r = s.match(/^[0-7]+|\d/g);
576
- for (let i = 0; i < r.length; i++) {
577
- const l = r[i];
578
- let c;
579
- if (i === 0 && l !== "8" && l !== "9") {
580
- if (c = parseInt(l, 8), c > 127) throw new Error(o$1`Octal encoded byte above 177 unsupported "${t}"`);
581
- } else c = r$2(l);
582
- a.push(d(c, (i === 0 ? "\\" : "") + l));
583
- }
584
- return a;
585
- }
586
- function te$1(e) {
587
- const n = [], t = new RegExp(y$1, "gy");
588
- let o;
589
- for (; o = t.exec(e);) {
590
- const s = o[0];
591
- if (s[0] === "{") {
592
- const a = /^\{(?<min>\d+),(?<max>\d+)\}\??$/.exec(s);
593
- if (a) {
594
- const { min: r, max: i } = a.groups;
595
- if (+r > +i && s.endsWith("?")) {
596
- t.lastIndex--, n.push(O$1(s.slice(0, -1)));
597
- continue;
598
- }
599
- }
600
- }
601
- n.push(O$1(s));
602
- }
603
- return n;
604
- }
605
- //#endregion
606
- //#region ../../node_modules/.pnpm/oniguruma-parser@0.12.2/node_modules/oniguruma-parser/dist/parser/node-utils.js
607
- function o(e, t) {
608
- if (!Array.isArray(e.body)) throw new Error("Expected node with body array");
609
- if (e.body.length !== 1) return !1;
610
- const r = e.body[0];
611
- return !t || Object.keys(t).every((n) => t[n] === r[n]);
612
- }
613
- function s(e) {
614
- return y.has(e.type);
615
- }
616
- const y = /* @__PURE__ */ new Set([
617
- "AbsenceFunction",
618
- "Backreference",
619
- "CapturingGroup",
620
- "Character",
621
- "CharacterClass",
622
- "CharacterSet",
623
- "Group",
624
- "Quantifier",
625
- "Subroutine"
626
- ]);
627
- //#endregion
628
- //#region ../../node_modules/.pnpm/oniguruma-parser@0.12.2/node_modules/oniguruma-parser/dist/parser/parse.js
629
- function J(e, r = {}) {
630
- const n = {
631
- flags: "",
632
- normalizeUnknownPropertyNames: !1,
633
- skipBackrefValidation: !1,
634
- skipLookbehindValidation: !1,
635
- skipPropertyNameValidation: !1,
636
- unicodePropertyMap: null,
637
- ...r,
638
- rules: {
639
- captureGroup: !1,
640
- singleline: !1,
641
- ...r.rules
642
- }
643
- }, o = M$1(e, {
644
- flags: n.flags,
645
- rules: {
646
- captureGroup: n.rules.captureGroup,
647
- singleline: n.rules.singleline
648
- }
649
- }), i = (p, N) => {
650
- const u = o.tokens[t.nextIndex];
651
- switch (t.parent = p, t.nextIndex++, u.type) {
652
- case "Alternator": return b();
653
- case "Assertion": return W(u);
654
- case "Backreference": return X(u, t);
655
- case "Character": return m(u.value, { useLastValid: !!N.isCheckingRangeEnd });
656
- case "CharacterClassHyphen": return ee(u, t, N);
657
- case "CharacterClassOpen": return re(u, t, N);
658
- case "CharacterSet": return ne(u, t);
659
- case "Directive": return I(u.kind, { flags: u.flags });
660
- case "GroupOpen": return te(u, t, N);
661
- case "NamedCallout": return U(u.kind, u.tag, u.arguments);
662
- case "Quantifier": return oe(u, t);
663
- case "Subroutine": return ae(u, t);
664
- default: throw new Error(`Unexpected token type "${u.type}"`);
665
- }
666
- }, t = {
667
- capturingGroups: [],
668
- hasNumberedRef: !1,
669
- namedGroupsByName: /* @__PURE__ */ new Map(),
670
- nextIndex: 0,
671
- normalizeUnknownPropertyNames: n.normalizeUnknownPropertyNames,
672
- parent: null,
673
- skipBackrefValidation: n.skipBackrefValidation,
674
- skipLookbehindValidation: n.skipLookbehindValidation,
675
- skipPropertyNameValidation: n.skipPropertyNameValidation,
676
- subroutines: [],
677
- tokens: o.tokens,
678
- unicodePropertyMap: n.unicodePropertyMap,
679
- walk: i
680
- }, d = B(T(o.flags));
681
- let s = d.body[0];
682
- for (; t.nextIndex < o.tokens.length;) {
683
- const p = i(s, {});
684
- p.type === "Alternative" ? (d.body.push(p), s = p) : s.body.push(p);
685
- }
686
- const { capturingGroups: a, hasNumberedRef: l, namedGroupsByName: c, subroutines: f } = t;
687
- if (l && c.size && !n.rules.captureGroup) throw new Error("Numbered backref/subroutine not allowed when using named capture");
688
- for (const { ref: p } of f) if (typeof p == "number") {
689
- if (p > a.length) throw new Error("Subroutine uses a group number that's not defined");
690
- p && (a[p - 1].isSubroutined = !0);
691
- } else if (c.has(p)) {
692
- if (c.get(p).length > 1) throw new Error(o$1`Subroutine uses a duplicate group name "\g<${p}>"`);
693
- c.get(p)[0].isSubroutined = !0;
694
- } else throw new Error(o$1`Subroutine uses a group name that's not defined "\g<${p}>"`);
695
- return d;
696
- }
697
- function W({ kind: e }) {
698
- return F(u({
699
- "^": "line_start",
700
- $: "line_end",
701
- "\\A": "string_start",
702
- "\\b": "word_boundary",
703
- "\\B": "word_boundary",
704
- "\\G": "search_start",
705
- "\\y": "text_segment_boundary",
706
- "\\Y": "text_segment_boundary",
707
- "\\z": "string_end",
708
- "\\Z": "string_end_newline"
709
- }[e], `Unexpected assertion kind "${e}"`), { negate: e === o$1`\B` || e === o$1`\Y` });
710
- }
711
- function X({ raw: e }, r) {
712
- const n = /^\\k[<']/.test(e), o = n ? e.slice(3, -1) : e.slice(1), i = (t, d = !1) => {
713
- const s = r.capturingGroups.length;
714
- let a = !1;
715
- if (t > s) if (r.skipBackrefValidation) a = !0;
716
- else throw new Error(`Not enough capturing groups defined to the left "${e}"`);
717
- return r.hasNumberedRef = !0, k(d ? s + 1 - t : t, { orphan: a });
718
- };
719
- if (n) {
720
- const t = /^(?<sign>-?)0*(?<num>[1-9]\d*)$/.exec(o);
721
- if (t) return i(+t.groups.num, !!t.groups.sign);
722
- if (/[-+]/.test(o)) throw new Error(`Invalid backref name "${e}"`);
723
- if (!r.namedGroupsByName.has(o)) throw new Error(`Group name not defined to the left "${e}"`);
724
- return k(o);
725
- }
726
- return i(+o);
727
- }
728
- function ee(e, r, n) {
729
- const { tokens: o, walk: i } = r, t = r.parent, d = t.body.at(-1), s = o[r.nextIndex];
730
- if (!n.isCheckingRangeEnd && d && d.type !== "CharacterClass" && d.type !== "CharacterClassRange" && s && s.type !== "CharacterClassOpen" && s.type !== "CharacterClassClose" && s.type !== "CharacterClassIntersector") {
731
- const a = i(t, {
732
- ...n,
733
- isCheckingRangeEnd: !0
734
- });
735
- if (d.type === "Character" && a.type === "Character") return t.body.pop(), L(d, a);
736
- throw new Error("Invalid character class range");
737
- }
738
- return m(r$2("-"));
739
- }
740
- function re({ negate: e }, r, n) {
741
- const { tokens: o, walk: i } = r, t = [C()], d = o[r.nextIndex];
742
- let s = z(d);
743
- for (; s.type !== "CharacterClassClose";) {
744
- if (s.type === "CharacterClassIntersector") t.push(C()), r.nextIndex++;
745
- else {
746
- const l = t.at(-1);
747
- l.body.push(i(l, n));
748
- }
749
- s = z(o[r.nextIndex], d);
750
- }
751
- const a = C({ negate: e });
752
- return t.length === 1 ? a.body = t[0].body : (a.kind = "intersection", a.body = t.map((l) => l.body.length === 1 ? l.body[0] : l)), r.nextIndex++, a;
753
- }
754
- function ne({ kind: e, negate: r, value: n }, o) {
755
- const { normalizeUnknownPropertyNames: i$1, skipPropertyNameValidation: t, unicodePropertyMap: d } = o;
756
- if (e === "property") {
757
- const s = w(n);
758
- if (i.has(s) && !d?.has(s)) e = "posix", n = s;
759
- else return Q(n, {
760
- negate: r,
761
- normalizeUnknownPropertyNames: i$1,
762
- skipPropertyNameValidation: t,
763
- unicodePropertyMap: d
764
- });
765
- }
766
- return e === "posix" ? R(n, { negate: r }) : E(e, { negate: r });
767
- }
768
- function te(e, r, n) {
769
- const { tokens: o, capturingGroups: i, namedGroupsByName: t, skipLookbehindValidation: d, walk: s } = r, a = ie(e), l = a.type === "AbsenceFunction", c = $(a), f = c && a.negate;
770
- if (a.type === "CapturingGroup" && (i.push(a), a.name && l$1(t, a.name, []).push(a)), l && n.isInAbsenceFunction) throw new Error("Nested absence function not supported by Oniguruma");
771
- let p = D(o[r.nextIndex]);
772
- for (; p.type !== "GroupClose";) {
773
- if (p.type === "Alternator") a.body.push(b()), r.nextIndex++;
774
- else {
775
- const N = a.body.at(-1), u = s(N, {
776
- ...n,
777
- isInAbsenceFunction: n.isInAbsenceFunction || l,
778
- isInLookbehind: n.isInLookbehind || c,
779
- isInNegLookbehind: n.isInNegLookbehind || f
780
- });
781
- if (N.body.push(u), (c || n.isInLookbehind) && !d) {
782
- const v = "Lookbehind includes a pattern not allowed by Oniguruma";
783
- if (f || n.isInNegLookbehind) {
784
- if (M(u) || u.type === "CapturingGroup") throw new Error(v);
785
- } else if (M(u) || $(u) && u.negate) throw new Error(v);
786
- }
787
- }
788
- p = D(o[r.nextIndex]);
789
- }
790
- return r.nextIndex++, a;
791
- }
792
- function oe({ kind: e, min: r, max: n }, o) {
793
- const i = o.parent, t = i.body.at(-1);
794
- if (!t || !s(t)) throw new Error("Quantifier requires a repeatable token");
795
- const d = _(e, r, n, t);
796
- return i.body.pop(), d;
797
- }
798
- function ae({ raw: e }, r) {
799
- const { capturingGroups: n, subroutines: o } = r;
800
- let i = e.slice(3, -1);
801
- const t = /^(?<sign>[-+]?)0*(?<num>[1-9]\d*)$/.exec(i);
802
- if (t) {
803
- const s = +t.groups.num, a = n.length;
804
- if (r.hasNumberedRef = !0, i = {
805
- "": s,
806
- "+": a + s,
807
- "-": a + 1 - s
808
- }[t.groups.sign], i < 1) throw new Error("Invalid subroutine number");
809
- } else i === "0" && (i = 0);
810
- const d = O(i);
811
- return o.push(d), d;
812
- }
813
- function G(e, r) {
814
- if (e !== "repeater") throw new Error(`Unexpected absence function kind "${e}"`);
815
- return {
816
- type: "AbsenceFunction",
817
- kind: e,
818
- body: h(r?.body)
819
- };
820
- }
821
- function b(e) {
822
- return {
823
- type: "Alternative",
824
- body: V(e?.body)
825
- };
826
- }
827
- function F(e, r) {
828
- const n = {
829
- type: "Assertion",
830
- kind: e
831
- };
832
- return (e === "word_boundary" || e === "text_segment_boundary") && (n.negate = !!r?.negate), n;
833
- }
834
- function k(e, r) {
835
- const n = !!r?.orphan;
836
- return {
837
- type: "Backreference",
838
- ref: e,
839
- ...n && { orphan: n }
840
- };
841
- }
842
- function P(e, r) {
843
- const n = {
844
- name: void 0,
845
- isSubroutined: !1,
846
- ...r
847
- };
848
- if (n.name !== void 0 && !se(n.name)) throw new Error(`Group name "${n.name}" invalid in Oniguruma`);
849
- return {
850
- type: "CapturingGroup",
851
- number: e,
852
- ...n.name && { name: n.name },
853
- ...n.isSubroutined && { isSubroutined: n.isSubroutined },
854
- body: h(r?.body)
855
- };
856
- }
857
- function m(e, r) {
858
- const n = {
859
- useLastValid: !1,
860
- ...r
861
- };
862
- if (e > 1114111) {
863
- const o = e.toString(16);
864
- if (n.useLastValid) e = 1114111;
865
- else throw e > 1310719 ? /* @__PURE__ */ new Error(`Invalid code point out of range "\\x{${o}}"`) : /* @__PURE__ */ new Error(`Invalid code point out of range in JS "\\x{${o}}"`);
866
- }
867
- return {
868
- type: "Character",
869
- value: e
870
- };
871
- }
872
- function C(e) {
873
- const r = {
874
- kind: "union",
875
- negate: !1,
876
- ...e
877
- };
878
- return {
879
- type: "CharacterClass",
880
- kind: r.kind,
881
- negate: r.negate,
882
- body: V(e?.body)
883
- };
884
- }
885
- function L(e, r) {
886
- if (r.value < e.value) throw new Error("Character class range out of order");
887
- return {
888
- type: "CharacterClassRange",
889
- min: e,
890
- max: r
891
- };
892
- }
893
- function E(e, r) {
894
- const n = !!r?.negate, o = {
895
- type: "CharacterSet",
896
- kind: e
897
- };
898
- return (e === "digit" || e === "hex" || e === "newline" || e === "space" || e === "word") && (o.negate = n), (e === "text_segment" || e === "newline" && !n) && (o.variableLength = !0), o;
899
- }
900
- function I(e, r = {}) {
901
- if (e === "keep") return {
902
- type: "Directive",
903
- kind: e
904
- };
905
- if (e === "flags") return {
906
- type: "Directive",
907
- kind: e,
908
- flags: u(r.flags)
909
- };
910
- throw new Error(`Unexpected directive kind "${e}"`);
911
- }
912
- function T(e) {
913
- return {
914
- type: "Flags",
915
- ...e
916
- };
917
- }
918
- function A(e) {
919
- const r = e?.atomic, n = e?.flags;
920
- if (r && n) throw new Error("Atomic group cannot have flags");
921
- return {
922
- type: "Group",
923
- ...r && { atomic: r },
924
- ...n && { flags: n },
925
- body: h(e?.body)
926
- };
927
- }
928
- function K(e) {
929
- const r = {
930
- behind: !1,
931
- negate: !1,
932
- ...e
933
- };
934
- return {
935
- type: "LookaroundAssertion",
936
- kind: r.behind ? "lookbehind" : "lookahead",
937
- negate: r.negate,
938
- body: h(e?.body)
939
- };
940
- }
941
- function U(e, r, n) {
942
- return {
943
- type: "NamedCallout",
944
- kind: e,
945
- tag: r,
946
- arguments: n
947
- };
948
- }
949
- function R(e, r) {
950
- const n = !!r?.negate;
951
- if (!i.has(e)) throw new Error(`Invalid POSIX class "${e}"`);
952
- return {
953
- type: "CharacterSet",
954
- kind: "posix",
955
- value: e,
956
- negate: n
957
- };
958
- }
959
- function _(e, r, n, o) {
960
- if (r > n) throw new Error("Invalid reversed quantifier range");
961
- return {
962
- type: "Quantifier",
963
- kind: e,
964
- min: r,
965
- max: n,
966
- body: o
967
- };
968
- }
969
- function B(e, r) {
970
- return {
971
- type: "Regex",
972
- body: h(r?.body),
973
- flags: e
974
- };
975
- }
976
- function O(e) {
977
- return {
978
- type: "Subroutine",
979
- ref: e
980
- };
981
- }
982
- function Q(e, r) {
983
- const n = {
984
- negate: !1,
985
- normalizeUnknownPropertyNames: !1,
986
- skipPropertyNameValidation: !1,
987
- unicodePropertyMap: null,
988
- ...r
989
- };
990
- let o = n.unicodePropertyMap?.get(w(e));
991
- if (!o) {
992
- if (n.normalizeUnknownPropertyNames) o = de(e);
993
- else if (n.unicodePropertyMap && !n.skipPropertyNameValidation) throw new Error(o$1`Invalid Unicode property "\p{${e}}"`);
994
- }
995
- return {
996
- type: "CharacterSet",
997
- kind: "property",
998
- value: o ?? e,
999
- negate: n.negate
1000
- };
1001
- }
1002
- function ie({ flags: e, kind: r, name: n, negate: o, number: i }) {
1003
- switch (r) {
1004
- case "absence_repeater": return G("repeater");
1005
- case "atomic": return A({ atomic: !0 });
1006
- case "capturing": return P(i, { name: n });
1007
- case "group": return A({ flags: e });
1008
- case "lookahead":
1009
- case "lookbehind": return K({
1010
- behind: r === "lookbehind",
1011
- negate: o
1012
- });
1013
- default: throw new Error(`Unexpected group kind "${r}"`);
1014
- }
1015
- }
1016
- function h(e) {
1017
- if (e === void 0) e = [b()];
1018
- else if (!Array.isArray(e) || !e.length || !e.every((r) => r.type === "Alternative")) throw new Error("Invalid body; expected array of one or more Alternative nodes");
1019
- return e;
1020
- }
1021
- function V(e) {
1022
- if (e === void 0) e = [];
1023
- else if (!Array.isArray(e) || !e.every((r) => !!r.type)) throw new Error("Invalid body; expected array of nodes");
1024
- return e;
1025
- }
1026
- function M(e) {
1027
- return e.type === "LookaroundAssertion" && e.kind === "lookahead";
1028
- }
1029
- function $(e) {
1030
- return e.type === "LookaroundAssertion" && e.kind === "lookbehind";
1031
- }
1032
- function se(e) {
1033
- return /^[\p{Alpha}\p{Pc}][^)]*$/u.test(e);
1034
- }
1035
- function de(e) {
1036
- return e.trim().replace(/[- _]+/g, "_").replace(/[A-Z][a-z]+(?=[A-Z])/g, "$&_").replace(/[A-Za-z]+/g, (r) => r[0].toUpperCase() + r.slice(1).toLowerCase());
1037
- }
1038
- function w(e) {
1039
- return e.replace(/[- _]+/g, "").toLowerCase();
1040
- }
1041
- function z(e, r) {
1042
- const n = r;
1043
- return u(e, `Unclosed character class${n?.type === "Character" && n.value === 93 && n.raw === "]" ? " (started with \"]\")" : ""}`);
1044
- }
1045
- function D(e) {
1046
- return u(e, "Unclosed group");
1047
- }
1048
- //#endregion
1049
- //#region ../../node_modules/.pnpm/oniguruma-parser@0.12.2/node_modules/oniguruma-parser/dist/traverser/traverse.js
1050
- function S(a, v, N = null) {
1051
- function b(e, s) {
1052
- for (let t = 0; t < e.length; t++) {
1053
- const r = n(e[t], s, t, e);
1054
- t = Math.max(-1, t + r);
1055
- }
1056
- }
1057
- function n(e, s = null, t = null, r = null) {
1058
- let i = 0, c = !1;
1059
- const d = {
1060
- node: e,
1061
- parent: s,
1062
- key: t,
1063
- container: r,
1064
- root: a,
1065
- remove() {
1066
- x(r).splice(Math.max(0, l(t) + i), 1), i--, c = !0;
1067
- },
1068
- removeAllNextSiblings() {
1069
- return x(r).splice(l(t) + 1);
1070
- },
1071
- removeAllPrevSiblings() {
1072
- const o = l(t) + i;
1073
- return i -= o, x(r).splice(0, Math.max(0, o));
1074
- },
1075
- replaceWith(o, m = {}) {
1076
- const y = !!m.traverse;
1077
- r ? r[Math.max(0, l(t) + i)] = o : u(s, "Can't replace root node")[t] = o, y && n(o, s, t, r), c = !0;
1078
- },
1079
- replaceWithMultiple(o, m = {}) {
1080
- const y = !!m.traverse;
1081
- if (x(r).splice(Math.max(0, l(t) + i), 1, ...o), i += o.length - 1, y) {
1082
- let g = 0;
1083
- for (let p = 0; p < o.length; p++) g += n(o[p], s, l(t) + p + g, r);
1084
- }
1085
- c = !0;
1086
- },
1087
- skip() {
1088
- c = !0;
1089
- }
1090
- }, { type: f } = e, u$1 = v["*"], h = v[f], R = typeof u$1 == "function" ? u$1 : u$1?.enter, P = typeof h == "function" ? h : h?.enter;
1091
- if (R?.(d, N), P?.(d, N), !c) switch (f) {
1092
- case "AbsenceFunction":
1093
- case "Alternative":
1094
- case "CapturingGroup":
1095
- case "CharacterClass":
1096
- case "Group":
1097
- case "LookaroundAssertion":
1098
- b(e.body, e);
1099
- break;
1100
- case "Assertion":
1101
- case "Backreference":
1102
- case "Character":
1103
- case "CharacterSet":
1104
- case "Directive":
1105
- case "Flags":
1106
- case "NamedCallout":
1107
- case "Subroutine": break;
1108
- case "CharacterClassRange":
1109
- n(e.min, e, "min"), n(e.max, e, "max");
1110
- break;
1111
- case "Quantifier":
1112
- n(e.body, e, "body");
1113
- break;
1114
- case "Regex":
1115
- b(e.body, e), n(e.flags, e, "flags");
1116
- break;
1117
- default: throw new Error(`Unexpected node type "${f}"`);
1118
- }
1119
- return h?.exit?.(d, N), u$1?.exit?.(d, N), i;
1120
- }
1121
- return n(a), a;
1122
- }
1123
- function x(a) {
1124
- if (!Array.isArray(a)) throw new Error("Container expected");
1125
- return a;
1126
- }
1127
- function l(a) {
1128
- if (typeof a != "number") throw new Error("Numeric key expected");
1129
- return a;
1130
- }
1131
- //#endregion
1132
- //#region ../../node_modules/.pnpm/regex@6.1.0/node_modules/regex/src/utils-internals.js
1133
- const noncapturingDelim = String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;
1134
- /**
1135
- Updates the array in place by incrementing each value greater than or equal to the threshold.
1136
- @param {Array<number>} arr
1137
- @param {number} threshold
1138
- */
1139
- function incrementIfAtLeast$1(arr, threshold) {
1140
- for (let i = 0; i < arr.length; i++) if (arr[i] >= threshold) arr[i]++;
1141
- }
1142
- /**
1143
- @param {string} str
1144
- @param {number} pos
1145
- @param {string} oldValue
1146
- @param {string} newValue
1147
- @returns {string}
1148
- */
1149
- function spliceStr(str, pos, oldValue, newValue) {
1150
- return str.slice(0, pos) + newValue + str.slice(pos + oldValue.length);
1151
- }
1152
- //#endregion
1153
- //#region ../../node_modules/.pnpm/regex-utilities@2.3.0/node_modules/regex-utilities/src/index.js
1154
- const Context = Object.freeze({
1155
- DEFAULT: "DEFAULT",
1156
- CHAR_CLASS: "CHAR_CLASS"
1157
- });
1158
- /**
1159
- Replaces all unescaped instances of a regex pattern in the given context, using a replacement
1160
- string or callback.
1161
-
1162
- Doesn't skip over complete multicharacter tokens (only `\` plus its folowing char) so must be used
1163
- with knowledge of what's safe to do given regex syntax. Assumes UnicodeSets-mode syntax.
1164
- @param {string} expression Search target
1165
- @param {string} needle Search as a regex pattern, with flags `su` applied
1166
- @param {string | (match: RegExpExecArray, details: {
1167
- context: 'DEFAULT' | 'CHAR_CLASS';
1168
- negated: boolean;
1169
- }) => string} replacement
1170
- @param {'DEFAULT' | 'CHAR_CLASS'} [context] All contexts if not specified
1171
- @returns {string} Updated expression
1172
- @example
1173
- const str = '.\\.\\\\.[[\\.].].';
1174
- replaceUnescaped(str, '\\.', '@');
1175
- // → '@\\.\\\\@[[\\.]@]@'
1176
- replaceUnescaped(str, '\\.', '@', Context.DEFAULT);
1177
- // → '@\\.\\\\@[[\\.].]@'
1178
- replaceUnescaped(str, '\\.', '@', Context.CHAR_CLASS);
1179
- // → '.\\.\\\\.[[\\.]@].'
1180
- */
1181
- function replaceUnescaped(expression, needle, replacement, context) {
1182
- const re = new RegExp(String.raw`${needle}|(?<$skip>\[\^?|\\?.)`, "gsu");
1183
- const negated = [false];
1184
- let numCharClassesOpen = 0;
1185
- let result = "";
1186
- for (const match of expression.matchAll(re)) {
1187
- const { 0: m, groups: { $skip } } = match;
1188
- if (!$skip && (!context || context === Context.DEFAULT === !numCharClassesOpen)) {
1189
- if (replacement instanceof Function) result += replacement(match, {
1190
- context: numCharClassesOpen ? Context.CHAR_CLASS : Context.DEFAULT,
1191
- negated: negated[negated.length - 1]
1192
- });
1193
- else result += replacement;
1194
- continue;
1195
- }
1196
- if (m[0] === "[") {
1197
- numCharClassesOpen++;
1198
- negated.push(m[1] === "^");
1199
- } else if (m === "]" && numCharClassesOpen) {
1200
- numCharClassesOpen--;
1201
- negated.pop();
1202
- }
1203
- result += m;
1204
- }
1205
- return result;
1206
- }
1207
- /**
1208
- Runs a callback for each unescaped instance of a regex pattern in the given context.
1209
-
1210
- Doesn't skip over complete multicharacter tokens (only `\` plus its folowing char) so must be used
1211
- with knowledge of what's safe to do given regex syntax. Assumes UnicodeSets-mode syntax.
1212
- @param {string} expression Search target
1213
- @param {string} needle Search as a regex pattern, with flags `su` applied
1214
- @param {(match: RegExpExecArray, details: {
1215
- context: 'DEFAULT' | 'CHAR_CLASS';
1216
- negated: boolean;
1217
- }) => void} callback
1218
- @param {'DEFAULT' | 'CHAR_CLASS'} [context] All contexts if not specified
1219
- */
1220
- function forEachUnescaped(expression, needle, callback, context) {
1221
- replaceUnescaped(expression, needle, callback, context);
1222
- }
1223
- /**
1224
- Returns a match object for the first unescaped instance of a regex pattern in the given context, or
1225
- `null`.
1226
-
1227
- Doesn't skip over complete multicharacter tokens (only `\` plus its folowing char) so must be used
1228
- with knowledge of what's safe to do given regex syntax. Assumes UnicodeSets-mode syntax.
1229
- @param {string} expression Search target
1230
- @param {string} needle Search as a regex pattern, with flags `su` applied
1231
- @param {number} [pos] Offset to start the search
1232
- @param {'DEFAULT' | 'CHAR_CLASS'} [context] All contexts if not specified
1233
- @returns {RegExpExecArray | null}
1234
- */
1235
- function execUnescaped(expression, needle, pos = 0, context) {
1236
- if (!new RegExp(needle, "su").test(expression)) return null;
1237
- const re = new RegExp(`${needle}|(?<$skip>\\\\?.)`, "gsu");
1238
- re.lastIndex = pos;
1239
- let numCharClassesOpen = 0;
1240
- let match;
1241
- while (match = re.exec(expression)) {
1242
- const { 0: m, groups: { $skip } } = match;
1243
- if (!$skip && (!context || context === Context.DEFAULT === !numCharClassesOpen)) return match;
1244
- if (m === "[") numCharClassesOpen++;
1245
- else if (m === "]" && numCharClassesOpen) numCharClassesOpen--;
1246
- if (re.lastIndex == match.index) re.lastIndex++;
1247
- }
1248
- return null;
1249
- }
1250
- /**
1251
- Checks whether an unescaped instance of a regex pattern appears in the given context.
1252
-
1253
- Doesn't skip over complete multicharacter tokens (only `\` plus its folowing char) so must be used
1254
- with knowledge of what's safe to do given regex syntax. Assumes UnicodeSets-mode syntax.
1255
- @param {string} expression Search target
1256
- @param {string} needle Search as a regex pattern, with flags `su` applied
1257
- @param {'DEFAULT' | 'CHAR_CLASS'} [context] All contexts if not specified
1258
- @returns {boolean} Whether the pattern was found
1259
- */
1260
- function hasUnescaped(expression, needle, context) {
1261
- return !!execUnescaped(expression, needle, 0, context);
1262
- }
1263
- /**
1264
- Extracts the full contents of a group (subpattern) from the given expression, accounting for
1265
- escaped characters, nested groups, and character classes. The group is identified by the position
1266
- where its contents start (the string index just after the group's opening delimiter). Returns the
1267
- rest of the string if the group is unclosed.
1268
-
1269
- Assumes UnicodeSets-mode syntax.
1270
- @param {string} expression Search target
1271
- @param {number} contentsStartPos
1272
- @returns {string}
1273
- */
1274
- function getGroupContents(expression, contentsStartPos) {
1275
- const token = /\\?./gsu;
1276
- token.lastIndex = contentsStartPos;
1277
- let contentsEndPos = expression.length;
1278
- let numCharClassesOpen = 0;
1279
- let numGroupsOpen = 1;
1280
- let match;
1281
- while (match = token.exec(expression)) {
1282
- const [m] = match;
1283
- if (m === "[") numCharClassesOpen++;
1284
- else if (!numCharClassesOpen) {
1285
- if (m === "(") numGroupsOpen++;
1286
- else if (m === ")") {
1287
- numGroupsOpen--;
1288
- if (!numGroupsOpen) {
1289
- contentsEndPos = match.index;
1290
- break;
1291
- }
1292
- }
1293
- } else if (m === "]") numCharClassesOpen--;
1294
- }
1295
- return expression.slice(contentsStartPos, contentsEndPos);
1296
- }
1297
- //#endregion
1298
- //#region ../../node_modules/.pnpm/regex@6.1.0/node_modules/regex/src/atomic.js
1299
- /**
1300
- @import {PluginData, PluginResult} from './regex.js';
1301
- */
1302
- const atomicPluginToken = new RegExp(String.raw`(?<noncapturingStart>${noncapturingDelim})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`, "gsu");
1303
- /**
1304
- Apply transformations for atomic groups: `(?>…)`.
1305
- @param {string} expression
1306
- @param {PluginData} [data]
1307
- @returns {Required<PluginResult>}
1308
- */
1309
- function atomic(expression, data) {
1310
- const hiddenCaptures = data?.hiddenCaptures ?? [];
1311
- let captureTransfers = data?.captureTransfers ?? /* @__PURE__ */ new Map();
1312
- if (!/\(\?>/.test(expression)) return {
1313
- pattern: expression,
1314
- captureTransfers,
1315
- hiddenCaptures
1316
- };
1317
- const aGDelim = "(?>";
1318
- const emulatedAGDelim = "(?:(?=(";
1319
- const captureNumMap = [0];
1320
- const addedHiddenCaptures = [];
1321
- let numCapturesBeforeAG = 0;
1322
- let numAGs = 0;
1323
- let aGPos = NaN;
1324
- let hasProcessedAG;
1325
- do {
1326
- hasProcessedAG = false;
1327
- let numCharClassesOpen = 0;
1328
- let numGroupsOpenInAG = 0;
1329
- let inAG = false;
1330
- let match;
1331
- atomicPluginToken.lastIndex = Number.isNaN(aGPos) ? 0 : aGPos + 7;
1332
- while (match = atomicPluginToken.exec(expression)) {
1333
- const { 0: m, index, groups: { capturingStart, noncapturingStart } } = match;
1334
- if (m === "[") numCharClassesOpen++;
1335
- else if (!numCharClassesOpen) {
1336
- if (m === aGDelim && !inAG) {
1337
- aGPos = index;
1338
- inAG = true;
1339
- } else if (inAG && noncapturingStart) numGroupsOpenInAG++;
1340
- else if (capturingStart) {
1341
- if (inAG) numGroupsOpenInAG++;
1342
- else {
1343
- numCapturesBeforeAG++;
1344
- captureNumMap.push(numCapturesBeforeAG + numAGs);
1345
- }
1346
- } else if (m === ")" && inAG) {
1347
- if (!numGroupsOpenInAG) {
1348
- numAGs++;
1349
- const addedCaptureNum = numCapturesBeforeAG + numAGs;
1350
- expression = `${expression.slice(0, aGPos)}${emulatedAGDelim}${expression.slice(aGPos + 3, index)}))<$$${addedCaptureNum}>)${expression.slice(index + 1)}`;
1351
- hasProcessedAG = true;
1352
- addedHiddenCaptures.push(addedCaptureNum);
1353
- incrementIfAtLeast$1(hiddenCaptures, addedCaptureNum);
1354
- if (captureTransfers.size) {
1355
- const newCaptureTransfers = /* @__PURE__ */ new Map();
1356
- captureTransfers.forEach((from, to) => {
1357
- newCaptureTransfers.set(to >= addedCaptureNum ? to + 1 : to, from.map((f) => f >= addedCaptureNum ? f + 1 : f));
1358
- });
1359
- captureTransfers = newCaptureTransfers;
1360
- }
1361
- break;
1362
- }
1363
- numGroupsOpenInAG--;
1364
- }
1365
- } else if (m === "]") numCharClassesOpen--;
1366
- }
1367
- } while (hasProcessedAG);
1368
- hiddenCaptures.push(...addedHiddenCaptures);
1369
- expression = replaceUnescaped(expression, String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`, ({ 0: m, groups: { backrefNum, wrappedBackrefNum } }) => {
1370
- if (backrefNum) {
1371
- const bNum = +backrefNum;
1372
- if (bNum > captureNumMap.length - 1) throw new Error(`Backref "${m}" greater than number of captures`);
1373
- return `\\${captureNumMap[bNum]}`;
1374
- }
1375
- return `\\${wrappedBackrefNum}`;
1376
- }, Context.DEFAULT);
1377
- return {
1378
- pattern: expression,
1379
- captureTransfers,
1380
- hiddenCaptures
1381
- };
1382
- }
1383
- const baseQuantifier = String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`;
1384
- const possessivePluginToken = new RegExp(String.raw`
1385
- \\(?: \d+
1386
- | c[A-Za-z]
1387
- | [gk]<[^>]+>
1388
- | [pPu]\{[^\}]+\}
1389
- | u[A-Fa-f\d]{4}
1390
- | x[A-Fa-f\d]{2}
1391
- )
1392
- | \((?: \? (?: [:=!>]
1393
- | <(?:[=!]|[^>]+>)
1394
- | [A-Za-z\-]+:
1395
- | \(DEFINE\)
1396
- ))?
1397
- | (?<qBase>${baseQuantifier})(?<qMod>[?+]?)(?<invalidQ>[?*+\{]?)
1398
- | \\?.
1399
- `.replace(/\s+/g, ""), "gsu");
1400
- /**
1401
- Transform posessive quantifiers into atomic groups. The posessessive quantifiers are:
1402
- `?+`, `*+`, `++`, `{N}+`, `{N,}+`, `{N,N}+`.
1403
- This follows Java, PCRE, Perl, and Python.
1404
- Possessive quantifiers in Oniguruma and Onigmo are only: `?+`, `*+`, `++`.
1405
- @param {string} expression
1406
- @returns {PluginResult}
1407
- */
1408
- function possessive(expression) {
1409
- if (!new RegExp(`${baseQuantifier}\\+`).test(expression)) return { pattern: expression };
1410
- const openGroupIndices = [];
1411
- let lastGroupIndex = null;
1412
- let lastCharClassIndex = null;
1413
- let lastToken = "";
1414
- let numCharClassesOpen = 0;
1415
- let match;
1416
- possessivePluginToken.lastIndex = 0;
1417
- while (match = possessivePluginToken.exec(expression)) {
1418
- const { 0: m, index, groups: { qBase, qMod, invalidQ } } = match;
1419
- if (m === "[") {
1420
- if (!numCharClassesOpen) lastCharClassIndex = index;
1421
- numCharClassesOpen++;
1422
- } else if (m === "]") {
1423
- if (numCharClassesOpen) numCharClassesOpen--;
1424
- else lastCharClassIndex = null;
1425
- } else if (!numCharClassesOpen) {
1426
- if (qMod === "+" && lastToken && !lastToken.startsWith("(")) {
1427
- if (invalidQ) throw new Error(`Invalid quantifier "${m}"`);
1428
- let charsAdded = -1;
1429
- if (/^\{\d+\}$/.test(qBase)) expression = spliceStr(expression, index + qBase.length, qMod, "");
1430
- else {
1431
- if (lastToken === ")" || lastToken === "]") {
1432
- const nodeIndex = lastToken === ")" ? lastGroupIndex : lastCharClassIndex;
1433
- if (nodeIndex === null) throw new Error(`Invalid unmatched "${lastToken}"`);
1434
- expression = `${expression.slice(0, nodeIndex)}(?>${expression.slice(nodeIndex, index)}${qBase})${expression.slice(index + m.length)}`;
1435
- } else expression = `${expression.slice(0, index - lastToken.length)}(?>${lastToken}${qBase})${expression.slice(index + m.length)}`;
1436
- charsAdded += 4;
1437
- }
1438
- possessivePluginToken.lastIndex += charsAdded;
1439
- } else if (m[0] === "(") openGroupIndices.push(index);
1440
- else if (m === ")") lastGroupIndex = openGroupIndices.length ? openGroupIndices.pop() : null;
1441
- }
1442
- lastToken = m;
1443
- }
1444
- return { pattern: expression };
1445
- }
1446
- //#endregion
1447
- //#region ../../node_modules/.pnpm/regex-recursion@6.0.2/node_modules/regex-recursion/src/index.js
1448
- const r$1 = String.raw;
1449
- const recursiveToken = r$1`\(\?R=(?<rDepth>[^\)]+)\)|${r$1`\\g<(?<gRNameOrNum>[^>&]+)&R=(?<gRDepth>[^>]+)>`}`;
1450
- const namedCaptureDelim = r$1`\(\?<(?![=!])(?<captureName>[^>]+)>`;
1451
- const captureDelim = r$1`${namedCaptureDelim}|(?<unnamed>\()(?!\?)`;
1452
- const token = new RegExp(r$1`${namedCaptureDelim}|${recursiveToken}|\(\?|\\?.`, "gsu");
1453
- const overlappingRecursionMsg = "Cannot use multiple overlapping recursions";
1454
- /**
1455
- @param {string} pattern
1456
- @param {{
1457
- flags?: string;
1458
- captureTransfers?: Map<number, Array<number>>;
1459
- hiddenCaptures?: Array<number>;
1460
- mode?: 'plugin' | 'external';
1461
- }} [data]
1462
- @returns {{
1463
- pattern: string;
1464
- captureTransfers: Map<number, Array<number>>;
1465
- hiddenCaptures: Array<number>;
1466
- }}
1467
- */
1468
- function recursion(pattern, data) {
1469
- const { hiddenCaptures, mode } = {
1470
- hiddenCaptures: [],
1471
- mode: "plugin",
1472
- ...data
1473
- };
1474
- let captureTransfers = data?.captureTransfers ?? /* @__PURE__ */ new Map();
1475
- if (!new RegExp(recursiveToken, "su").test(pattern)) return {
1476
- pattern,
1477
- captureTransfers,
1478
- hiddenCaptures
1479
- };
1480
- if (mode === "plugin" && hasUnescaped(pattern, r$1`\(\?\(DEFINE\)`, Context.DEFAULT)) throw new Error("DEFINE groups cannot be used with recursion");
1481
- const addedHiddenCaptures = [];
1482
- const hasNumberedBackref = hasUnescaped(pattern, r$1`\\[1-9]`, Context.DEFAULT);
1483
- const groupContentsStartPos = /* @__PURE__ */ new Map();
1484
- const openGroups = [];
1485
- let hasRecursed = false;
1486
- let numCharClassesOpen = 0;
1487
- let numCapturesPassed = 0;
1488
- let match;
1489
- token.lastIndex = 0;
1490
- while (match = token.exec(pattern)) {
1491
- const { 0: m, groups: { captureName, rDepth, gRNameOrNum, gRDepth } } = match;
1492
- if (m === "[") numCharClassesOpen++;
1493
- else if (!numCharClassesOpen) {
1494
- if (rDepth) {
1495
- assertMaxInBounds(rDepth);
1496
- if (hasRecursed) throw new Error(overlappingRecursionMsg);
1497
- if (hasNumberedBackref) throw new Error(`${mode === "external" ? "Backrefs" : "Numbered backrefs"} cannot be used with global recursion`);
1498
- const left = pattern.slice(0, match.index);
1499
- const right = pattern.slice(token.lastIndex);
1500
- if (hasUnescaped(right, recursiveToken, Context.DEFAULT)) throw new Error(overlappingRecursionMsg);
1501
- const reps = +rDepth - 1;
1502
- pattern = makeRecursive(left, right, reps, false, hiddenCaptures, addedHiddenCaptures, numCapturesPassed);
1503
- captureTransfers = mapCaptureTransfers(captureTransfers, left, reps, addedHiddenCaptures.length, 0, numCapturesPassed);
1504
- break;
1505
- } else if (gRNameOrNum) {
1506
- assertMaxInBounds(gRDepth);
1507
- let isWithinReffedGroup = false;
1508
- for (const g of openGroups) if (g.name === gRNameOrNum || g.num === +gRNameOrNum) {
1509
- isWithinReffedGroup = true;
1510
- if (g.hasRecursedWithin) throw new Error(overlappingRecursionMsg);
1511
- break;
1512
- }
1513
- if (!isWithinReffedGroup) throw new Error(r$1`Recursive \g cannot be used outside the referenced group "${mode === "external" ? gRNameOrNum : r$1`\g<${gRNameOrNum}&R=${gRDepth}>`}"`);
1514
- const startPos = groupContentsStartPos.get(gRNameOrNum);
1515
- const groupContents = getGroupContents(pattern, startPos);
1516
- if (hasNumberedBackref && hasUnescaped(groupContents, r$1`${namedCaptureDelim}|\((?!\?)`, Context.DEFAULT)) throw new Error(`${mode === "external" ? "Backrefs" : "Numbered backrefs"} cannot be used with recursion of capturing groups`);
1517
- const groupContentsLeft = pattern.slice(startPos, match.index);
1518
- const groupContentsRight = groupContents.slice(groupContentsLeft.length + m.length);
1519
- const numAddedHiddenCapturesPreExpansion = addedHiddenCaptures.length;
1520
- const reps = +gRDepth - 1;
1521
- const expansion = makeRecursive(groupContentsLeft, groupContentsRight, reps, true, hiddenCaptures, addedHiddenCaptures, numCapturesPassed);
1522
- captureTransfers = mapCaptureTransfers(captureTransfers, groupContentsLeft, reps, addedHiddenCaptures.length - numAddedHiddenCapturesPreExpansion, numAddedHiddenCapturesPreExpansion, numCapturesPassed);
1523
- pattern = `${pattern.slice(0, startPos)}${expansion}${pattern.slice(startPos + groupContents.length)}`;
1524
- token.lastIndex += expansion.length - m.length - groupContentsLeft.length - groupContentsRight.length;
1525
- openGroups.forEach((g) => g.hasRecursedWithin = true);
1526
- hasRecursed = true;
1527
- } else if (captureName) {
1528
- numCapturesPassed++;
1529
- groupContentsStartPos.set(String(numCapturesPassed), token.lastIndex);
1530
- groupContentsStartPos.set(captureName, token.lastIndex);
1531
- openGroups.push({
1532
- num: numCapturesPassed,
1533
- name: captureName
1534
- });
1535
- } else if (m[0] === "(") {
1536
- const isUnnamedCapture = m === "(";
1537
- if (isUnnamedCapture) {
1538
- numCapturesPassed++;
1539
- groupContentsStartPos.set(String(numCapturesPassed), token.lastIndex);
1540
- }
1541
- openGroups.push(isUnnamedCapture ? { num: numCapturesPassed } : {});
1542
- } else if (m === ")") openGroups.pop();
1543
- } else if (m === "]") numCharClassesOpen--;
1544
- }
1545
- hiddenCaptures.push(...addedHiddenCaptures);
1546
- return {
1547
- pattern,
1548
- captureTransfers,
1549
- hiddenCaptures
1550
- };
1551
- }
1552
- /**
1553
- @param {string} max
1554
- */
1555
- function assertMaxInBounds(max) {
1556
- const errMsg = `Max depth must be integer between 2 and 100; used ${max}`;
1557
- if (!/^[1-9]\d*$/.test(max)) throw new Error(errMsg);
1558
- max = +max;
1559
- if (max < 2 || max > 100) throw new Error(errMsg);
1560
- }
1561
- /**
1562
- @param {string} left
1563
- @param {string} right
1564
- @param {number} reps
1565
- @param {boolean} isSubpattern
1566
- @param {Array<number>} hiddenCaptures
1567
- @param {Array<number>} addedHiddenCaptures
1568
- @param {number} numCapturesPassed
1569
- @returns {string}
1570
- */
1571
- function makeRecursive(left, right, reps, isSubpattern, hiddenCaptures, addedHiddenCaptures, numCapturesPassed) {
1572
- const namesInRecursed = /* @__PURE__ */ new Set();
1573
- if (isSubpattern) forEachUnescaped(left + right, namedCaptureDelim, ({ groups: { captureName } }) => {
1574
- namesInRecursed.add(captureName);
1575
- }, Context.DEFAULT);
1576
- const rest = [
1577
- reps,
1578
- isSubpattern ? namesInRecursed : null,
1579
- hiddenCaptures,
1580
- addedHiddenCaptures,
1581
- numCapturesPassed
1582
- ];
1583
- return `${left}${repeatWithDepth(`(?:${left}`, "forward", ...rest)}(?:)${repeatWithDepth(`${right})`, "backward", ...rest)}${right}`;
1584
- }
1585
- /**
1586
- @param {string} pattern
1587
- @param {'forward' | 'backward'} direction
1588
- @param {number} reps
1589
- @param {Set<string> | null} namesInRecursed
1590
- @param {Array<number>} hiddenCaptures
1591
- @param {Array<number>} addedHiddenCaptures
1592
- @param {number} numCapturesPassed
1593
- @returns {string}
1594
- */
1595
- function repeatWithDepth(pattern, direction, reps, namesInRecursed, hiddenCaptures, addedHiddenCaptures, numCapturesPassed) {
1596
- const startNum = 2;
1597
- const getDepthNum = (i) => direction === "forward" ? i + startNum : reps - i + startNum - 1;
1598
- let result = "";
1599
- for (let i = 0; i < reps; i++) {
1600
- const depthNum = getDepthNum(i);
1601
- result += replaceUnescaped(pattern, r$1`${captureDelim}|\\k<(?<backref>[^>]+)>`, ({ 0: m, groups: { captureName, unnamed, backref } }) => {
1602
- if (backref && namesInRecursed && !namesInRecursed.has(backref)) return m;
1603
- const suffix = `_$${depthNum}`;
1604
- if (unnamed || captureName) {
1605
- const addedCaptureNum = numCapturesPassed + addedHiddenCaptures.length + 1;
1606
- addedHiddenCaptures.push(addedCaptureNum);
1607
- incrementIfAtLeast(hiddenCaptures, addedCaptureNum);
1608
- return unnamed ? m : `(?<${captureName}${suffix}>`;
1609
- }
1610
- return r$1`\k<${backref}${suffix}>`;
1611
- }, Context.DEFAULT);
1612
- }
1613
- return result;
1614
- }
1615
- /**
1616
- Updates the array in place by incrementing each value greater than or equal to the threshold.
1617
- @param {Array<number>} arr
1618
- @param {number} threshold
1619
- */
1620
- function incrementIfAtLeast(arr, threshold) {
1621
- for (let i = 0; i < arr.length; i++) if (arr[i] >= threshold) arr[i]++;
1622
- }
1623
- /**
1624
- @param {Map<number, Array<number>>} captureTransfers
1625
- @param {string} left
1626
- @param {number} reps
1627
- @param {number} numCapturesAddedInExpansion
1628
- @param {number} numAddedHiddenCapturesPreExpansion
1629
- @param {number} numCapturesPassed
1630
- @returns {Map<number, Array<number>>}
1631
- */
1632
- function mapCaptureTransfers(captureTransfers, left, reps, numCapturesAddedInExpansion, numAddedHiddenCapturesPreExpansion, numCapturesPassed) {
1633
- if (captureTransfers.size && numCapturesAddedInExpansion) {
1634
- let numCapturesInLeft = 0;
1635
- forEachUnescaped(left, captureDelim, () => numCapturesInLeft++, Context.DEFAULT);
1636
- const recursionDelimCaptureNum = numCapturesPassed - numCapturesInLeft + numAddedHiddenCapturesPreExpansion;
1637
- const newCaptureTransfers = /* @__PURE__ */ new Map();
1638
- captureTransfers.forEach((from, to) => {
1639
- const numCapturesInRight = (numCapturesAddedInExpansion - numCapturesInLeft * reps) / reps;
1640
- const numCapturesAddedInLeft = numCapturesInLeft * reps;
1641
- const newTo = to > recursionDelimCaptureNum + numCapturesInLeft ? to + numCapturesAddedInExpansion : to;
1642
- const newFrom = [];
1643
- for (const f of from) if (f <= recursionDelimCaptureNum) newFrom.push(f);
1644
- else if (f > recursionDelimCaptureNum + numCapturesInLeft + numCapturesInRight) newFrom.push(f + numCapturesAddedInExpansion);
1645
- else if (f <= recursionDelimCaptureNum + numCapturesInLeft) for (let i = 0; i <= reps; i++) newFrom.push(f + numCapturesInLeft * i);
1646
- else for (let i = 0; i <= reps; i++) newFrom.push(f + numCapturesAddedInLeft + numCapturesInRight * i);
1647
- newCaptureTransfers.set(newTo, newFrom);
1648
- });
1649
- return newCaptureTransfers;
1650
- }
1651
- return captureTransfers;
1652
- }
1653
- //#endregion
1654
- //#region ../../node_modules/.pnpm/oniguruma-to-es@4.3.6/node_modules/oniguruma-to-es/dist/esm/index.js
1655
- var cp = String.fromCodePoint;
1656
- var r = String.raw;
1657
- var envFlags = {};
1658
- var globalRegExp = globalThis.RegExp;
1659
- envFlags.flagGroups = (() => {
1660
- try {
1661
- new globalRegExp("(?i:)");
1662
- } catch {
1663
- return false;
1664
- }
1665
- return true;
1666
- })();
1667
- envFlags.unicodeSets = (() => {
1668
- try {
1669
- new globalRegExp("[[]]", "v");
1670
- } catch {
1671
- return false;
1672
- }
1673
- return true;
1674
- })();
1675
- envFlags.bugFlagVLiteralHyphenIsRange = envFlags.unicodeSets ? (() => {
1676
- try {
1677
- new globalRegExp(r`[\d\-a]`, "v");
1678
- } catch {
1679
- return true;
1680
- }
1681
- return false;
1682
- })() : false;
1683
- envFlags.bugNestedClassIgnoresNegation = envFlags.unicodeSets && new globalRegExp("[[^a]]", "v").test("a");
1684
- function getNewCurrentFlags(current, { enable, disable }) {
1685
- return {
1686
- dotAll: !disable?.dotAll && !!(enable?.dotAll || current.dotAll),
1687
- ignoreCase: !disable?.ignoreCase && !!(enable?.ignoreCase || current.ignoreCase)
1688
- };
1689
- }
1690
- function getOrInsert(map, key, defaultValue) {
1691
- if (!map.has(key)) map.set(key, defaultValue);
1692
- return map.get(key);
1693
- }
1694
- function isMinTarget(target, min) {
1695
- return EsVersion[target] >= EsVersion[min];
1696
- }
1697
- function throwIfNullish(value, msg) {
1698
- if (value == null) throw new Error(msg ?? "Value expected");
1699
- return value;
1700
- }
1701
- var EsVersion = {
1702
- ES2025: 2025,
1703
- ES2024: 2024,
1704
- ES2018: 2018
1705
- };
1706
- var Target = (
1707
- /** @type {const} */
1708
- {
1709
- auto: "auto",
1710
- ES2025: "ES2025",
1711
- ES2024: "ES2024",
1712
- ES2018: "ES2018"
1713
- });
1714
- function getOptions(options = {}) {
1715
- if ({}.toString.call(options) !== "[object Object]") throw new Error("Unexpected options");
1716
- if (options.target !== void 0 && !Target[options.target]) throw new Error(`Unexpected target "${options.target}"`);
1717
- const opts = {
1718
- accuracy: "default",
1719
- avoidSubclass: false,
1720
- flags: "",
1721
- global: false,
1722
- hasIndices: false,
1723
- lazyCompileLength: Infinity,
1724
- target: "auto",
1725
- verbose: false,
1726
- ...options,
1727
- rules: {
1728
- allowOrphanBackrefs: false,
1729
- asciiWordBoundaries: false,
1730
- captureGroup: false,
1731
- recursionLimit: 20,
1732
- singleline: false,
1733
- ...options.rules
1734
- }
1735
- };
1736
- if (opts.target === "auto") opts.target = envFlags.flagGroups ? "ES2025" : envFlags.unicodeSets ? "ES2024" : "ES2018";
1737
- return opts;
1738
- }
1739
- var asciiSpaceChar = "[ -\r ]";
1740
- var CharsWithoutIgnoreCaseExpansion = /* @__PURE__ */ new Set([cp(304), cp(305)]);
1741
- var defaultWordChar = r`[\p{L}\p{M}\p{N}\p{Pc}]`;
1742
- function getIgnoreCaseMatchChars(char) {
1743
- if (CharsWithoutIgnoreCaseExpansion.has(char)) return [char];
1744
- const set = /* @__PURE__ */ new Set();
1745
- const lower = char.toLowerCase();
1746
- const upper = lower.toUpperCase();
1747
- const title = LowerToTitleCaseMap.get(lower);
1748
- const altLower = LowerToAlternativeLowerCaseMap.get(lower);
1749
- const altUpper = LowerToAlternativeUpperCaseMap.get(lower);
1750
- if ([...upper].length === 1) set.add(upper);
1751
- altUpper && set.add(altUpper);
1752
- title && set.add(title);
1753
- set.add(lower);
1754
- altLower && set.add(altLower);
1755
- return [...set];
1756
- }
1757
- var JsUnicodePropertyMap = /* @__PURE__ */ new Map(`C Other
1758
- Cc Control cntrl
1759
- Cf Format
1760
- Cn Unassigned
1761
- Co Private_Use
1762
- Cs Surrogate
1763
- L Letter
1764
- LC Cased_Letter
1765
- Ll Lowercase_Letter
1766
- Lm Modifier_Letter
1767
- Lo Other_Letter
1768
- Lt Titlecase_Letter
1769
- Lu Uppercase_Letter
1770
- M Mark Combining_Mark
1771
- Mc Spacing_Mark
1772
- Me Enclosing_Mark
1773
- Mn Nonspacing_Mark
1774
- N Number
1775
- Nd Decimal_Number digit
1776
- Nl Letter_Number
1777
- No Other_Number
1778
- P Punctuation punct
1779
- Pc Connector_Punctuation
1780
- Pd Dash_Punctuation
1781
- Pe Close_Punctuation
1782
- Pf Final_Punctuation
1783
- Pi Initial_Punctuation
1784
- Po Other_Punctuation
1785
- Ps Open_Punctuation
1786
- S Symbol
1787
- Sc Currency_Symbol
1788
- Sk Modifier_Symbol
1789
- Sm Math_Symbol
1790
- So Other_Symbol
1791
- Z Separator
1792
- Zl Line_Separator
1793
- Zp Paragraph_Separator
1794
- Zs Space_Separator
1795
- ASCII
1796
- ASCII_Hex_Digit AHex
1797
- Alphabetic Alpha
1798
- Any
1799
- Assigned
1800
- Bidi_Control Bidi_C
1801
- Bidi_Mirrored Bidi_M
1802
- Case_Ignorable CI
1803
- Cased
1804
- Changes_When_Casefolded CWCF
1805
- Changes_When_Casemapped CWCM
1806
- Changes_When_Lowercased CWL
1807
- Changes_When_NFKC_Casefolded CWKCF
1808
- Changes_When_Titlecased CWT
1809
- Changes_When_Uppercased CWU
1810
- Dash
1811
- Default_Ignorable_Code_Point DI
1812
- Deprecated Dep
1813
- Diacritic Dia
1814
- Emoji
1815
- Emoji_Component EComp
1816
- Emoji_Modifier EMod
1817
- Emoji_Modifier_Base EBase
1818
- Emoji_Presentation EPres
1819
- Extended_Pictographic ExtPict
1820
- Extender Ext
1821
- Grapheme_Base Gr_Base
1822
- Grapheme_Extend Gr_Ext
1823
- Hex_Digit Hex
1824
- IDS_Binary_Operator IDSB
1825
- IDS_Trinary_Operator IDST
1826
- ID_Continue IDC
1827
- ID_Start IDS
1828
- Ideographic Ideo
1829
- Join_Control Join_C
1830
- Logical_Order_Exception LOE
1831
- Lowercase Lower
1832
- Math
1833
- Noncharacter_Code_Point NChar
1834
- Pattern_Syntax Pat_Syn
1835
- Pattern_White_Space Pat_WS
1836
- Quotation_Mark QMark
1837
- Radical
1838
- Regional_Indicator RI
1839
- Sentence_Terminal STerm
1840
- Soft_Dotted SD
1841
- Terminal_Punctuation Term
1842
- Unified_Ideograph UIdeo
1843
- Uppercase Upper
1844
- Variation_Selector VS
1845
- White_Space space
1846
- XID_Continue XIDC
1847
- XID_Start XIDS`.split(/\s/).map((p) => [w(p), p]));
1848
- var LowerToAlternativeLowerCaseMap = /* @__PURE__ */ new Map([["s", cp(383)], [cp(383), "s"]]);
1849
- var LowerToAlternativeUpperCaseMap = /* @__PURE__ */ new Map([
1850
- [cp(223), cp(7838)],
1851
- [cp(107), cp(8490)],
1852
- [cp(229), cp(8491)],
1853
- [cp(969), cp(8486)]
1854
- ]);
1855
- var LowerToTitleCaseMap = new Map([
1856
- titleEntry(453),
1857
- titleEntry(456),
1858
- titleEntry(459),
1859
- titleEntry(498),
1860
- ...titleRange(8072, 8079),
1861
- ...titleRange(8088, 8095),
1862
- ...titleRange(8104, 8111),
1863
- titleEntry(8124),
1864
- titleEntry(8140),
1865
- titleEntry(8188)
1866
- ]);
1867
- var PosixClassMap = /* @__PURE__ */ new Map([
1868
- ["alnum", r`[\p{Alpha}\p{Nd}]`],
1869
- ["alpha", r`\p{Alpha}`],
1870
- ["ascii", r`\p{ASCII}`],
1871
- ["blank", r`[\p{Zs}\t]`],
1872
- ["cntrl", r`\p{Cc}`],
1873
- ["digit", r`\p{Nd}`],
1874
- ["graph", r`[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]`],
1875
- ["lower", r`\p{Lower}`],
1876
- ["print", r`[[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]\p{Zs}]`],
1877
- ["punct", r`[\p{P}\p{S}]`],
1878
- ["space", r`\p{space}`],
1879
- ["upper", r`\p{Upper}`],
1880
- ["word", r`[\p{Alpha}\p{M}\p{Nd}\p{Pc}]`],
1881
- ["xdigit", r`\p{AHex}`]
1882
- ]);
1883
- function range(start, end) {
1884
- const range2 = [];
1885
- for (let i = start; i <= end; i++) range2.push(i);
1886
- return range2;
1887
- }
1888
- function titleEntry(codePoint) {
1889
- const char = cp(codePoint);
1890
- return [char.toLowerCase(), char];
1891
- }
1892
- function titleRange(start, end) {
1893
- return range(start, end).map((codePoint) => titleEntry(codePoint));
1894
- }
1895
- var UnicodePropertiesWithSpecificCase = /* @__PURE__ */ new Set([
1896
- "Lower",
1897
- "Lowercase",
1898
- "Upper",
1899
- "Uppercase",
1900
- "Ll",
1901
- "Lowercase_Letter",
1902
- "Lt",
1903
- "Titlecase_Letter",
1904
- "Lu",
1905
- "Uppercase_Letter"
1906
- ]);
1907
- function transform(ast, options) {
1908
- const opts = {
1909
- accuracy: "default",
1910
- asciiWordBoundaries: false,
1911
- avoidSubclass: false,
1912
- bestEffortTarget: "ES2025",
1913
- ...options
1914
- };
1915
- addParentProperties(ast);
1916
- const firstPassState = {
1917
- accuracy: opts.accuracy,
1918
- asciiWordBoundaries: opts.asciiWordBoundaries,
1919
- avoidSubclass: opts.avoidSubclass,
1920
- flagDirectivesByAlt: /* @__PURE__ */ new Map(),
1921
- jsGroupNameMap: /* @__PURE__ */ new Map(),
1922
- minTargetEs2024: isMinTarget(opts.bestEffortTarget, "ES2024"),
1923
- passedLookbehind: false,
1924
- strategy: null,
1925
- subroutineRefMap: /* @__PURE__ */ new Map(),
1926
- supportedGNodes: /* @__PURE__ */ new Set(),
1927
- digitIsAscii: ast.flags.digitIsAscii,
1928
- spaceIsAscii: ast.flags.spaceIsAscii,
1929
- wordIsAscii: ast.flags.wordIsAscii
1930
- };
1931
- S(ast, FirstPassVisitor, firstPassState);
1932
- const globalFlags = {
1933
- dotAll: ast.flags.dotAll,
1934
- ignoreCase: ast.flags.ignoreCase
1935
- };
1936
- const secondPassState = {
1937
- currentFlags: globalFlags,
1938
- prevFlags: null,
1939
- globalFlags,
1940
- groupOriginByCopy: /* @__PURE__ */ new Map(),
1941
- groupsByName: /* @__PURE__ */ new Map(),
1942
- multiplexCapturesToLeftByRef: /* @__PURE__ */ new Map(),
1943
- openRefs: /* @__PURE__ */ new Map(),
1944
- reffedNodesByReferencer: /* @__PURE__ */ new Map(),
1945
- subroutineRefMap: firstPassState.subroutineRefMap
1946
- };
1947
- S(ast, SecondPassVisitor, secondPassState);
1948
- S(ast, ThirdPassVisitor, {
1949
- groupsByName: secondPassState.groupsByName,
1950
- highestOrphanBackref: 0,
1951
- numCapturesToLeft: 0,
1952
- reffedNodesByReferencer: secondPassState.reffedNodesByReferencer
1953
- });
1954
- ast._originMap = secondPassState.groupOriginByCopy;
1955
- ast._strategy = firstPassState.strategy;
1956
- return ast;
1957
- }
1958
- var FirstPassVisitor = {
1959
- AbsenceFunction({ node, parent, replaceWith }) {
1960
- const { body, kind } = node;
1961
- if (kind === "repeater") {
1962
- const innerGroup = A();
1963
- innerGroup.body[0].body.push(K({
1964
- negate: true,
1965
- body
1966
- }), Q("Any"));
1967
- const outerGroup = A();
1968
- outerGroup.body[0].body.push(_("greedy", 0, Infinity, innerGroup));
1969
- replaceWith(setParentDeep(outerGroup, parent), { traverse: true });
1970
- } else throw new Error(`Unsupported absence function "(?~|"`);
1971
- },
1972
- Alternative: {
1973
- enter({ node, parent, key }, { flagDirectivesByAlt }) {
1974
- const flagDirectives = node.body.filter((el) => el.kind === "flags");
1975
- for (let i = key + 1; i < parent.body.length; i++) {
1976
- const forwardSiblingAlt = parent.body[i];
1977
- getOrInsert(flagDirectivesByAlt, forwardSiblingAlt, []).push(...flagDirectives);
1978
- }
1979
- },
1980
- exit({ node }, { flagDirectivesByAlt }) {
1981
- if (flagDirectivesByAlt.get(node)?.length) {
1982
- const flags = getCombinedFlagModsFromFlagNodes(flagDirectivesByAlt.get(node));
1983
- if (flags) {
1984
- const flagGroup = A({ flags });
1985
- flagGroup.body[0].body = node.body;
1986
- node.body = [setParentDeep(flagGroup, node)];
1987
- }
1988
- }
1989
- }
1990
- },
1991
- Assertion({ node, parent, key, container, root, remove, replaceWith }, state) {
1992
- const { kind, negate } = node;
1993
- const { asciiWordBoundaries, avoidSubclass, supportedGNodes, wordIsAscii } = state;
1994
- if (kind === "text_segment_boundary") throw new Error(`Unsupported text segment boundary "\\${negate ? "Y" : "y"}"`);
1995
- else if (kind === "line_end") replaceWith(setParentDeep(K({ body: [b({ body: [F("string_end")] }), b({ body: [m(10)] })] }), parent));
1996
- else if (kind === "line_start") replaceWith(setParentDeep(parseFragment(r`(?<=\A|\n(?!\z))`, { skipLookbehindValidation: true }), parent));
1997
- else if (kind === "search_start") {
1998
- if (supportedGNodes.has(node)) {
1999
- root.flags.sticky = true;
2000
- remove();
2001
- } else {
2002
- const prev = container[key - 1];
2003
- if (prev && isAlwaysNonZeroLength(prev)) replaceWith(setParentDeep(K({ negate: true }), parent));
2004
- else if (avoidSubclass) throw new Error(r`Uses "\G" in a way that requires a subclass`);
2005
- else {
2006
- replaceWith(setParent(F("string_start"), parent));
2007
- state.strategy = "clip_search";
2008
- }
2009
- }
2010
- } else if (kind === "string_end" || kind === "string_start") {} else if (kind === "string_end_newline") replaceWith(setParentDeep(parseFragment(r`(?=\n?\z)`), parent));
2011
- else if (kind === "word_boundary") {
2012
- if (!wordIsAscii && !asciiWordBoundaries) {
2013
- const b = `(?:(?<=${defaultWordChar})(?!${defaultWordChar})|(?<!${defaultWordChar})(?=${defaultWordChar}))`;
2014
- const B = `(?:(?<=${defaultWordChar})(?=${defaultWordChar})|(?<!${defaultWordChar})(?!${defaultWordChar}))`;
2015
- replaceWith(setParentDeep(parseFragment(negate ? B : b), parent));
2016
- }
2017
- } else throw new Error(`Unexpected assertion kind "${kind}"`);
2018
- },
2019
- Backreference({ node }, { jsGroupNameMap }) {
2020
- let { ref } = node;
2021
- if (typeof ref === "string" && !isValidJsGroupName(ref)) {
2022
- ref = getAndStoreJsGroupName(ref, jsGroupNameMap);
2023
- node.ref = ref;
2024
- }
2025
- },
2026
- CapturingGroup({ node }, { jsGroupNameMap, subroutineRefMap }) {
2027
- let { name } = node;
2028
- if (name && !isValidJsGroupName(name)) {
2029
- name = getAndStoreJsGroupName(name, jsGroupNameMap);
2030
- node.name = name;
2031
- }
2032
- subroutineRefMap.set(node.number, node);
2033
- if (name) subroutineRefMap.set(name, node);
2034
- },
2035
- CharacterClassRange({ node, parent, replaceWith }) {
2036
- if (parent.kind === "intersection") replaceWith(setParentDeep(C({ body: [node] }), parent), { traverse: true });
2037
- },
2038
- CharacterSet({ node, parent, replaceWith }, { accuracy, minTargetEs2024, digitIsAscii, spaceIsAscii, wordIsAscii }) {
2039
- const { kind, negate, value } = node;
2040
- if (digitIsAscii && (kind === "digit" || value === "digit")) {
2041
- replaceWith(setParent(E("digit", { negate }), parent));
2042
- return;
2043
- }
2044
- if (spaceIsAscii && (kind === "space" || value === "space")) {
2045
- replaceWith(setParentDeep(setNegate(parseFragment(asciiSpaceChar), negate), parent));
2046
- return;
2047
- }
2048
- if (wordIsAscii && (kind === "word" || value === "word")) {
2049
- replaceWith(setParent(E("word", { negate }), parent));
2050
- return;
2051
- }
2052
- if (kind === "any") replaceWith(setParent(Q("Any"), parent));
2053
- else if (kind === "digit") replaceWith(setParent(Q("Nd", { negate }), parent));
2054
- else if (kind === "dot") {} else if (kind === "text_segment") {
2055
- if (accuracy === "strict") throw new Error(r`Use of "\X" requires non-strict accuracy`);
2056
- const eBase = "\\p{Emoji}(?:\\p{EMod}|\\uFE0F\\u20E3?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})?";
2057
- const emoji = r`\p{RI}{2}|${eBase}(?:\u200D${eBase})*`;
2058
- replaceWith(setParentDeep(parseFragment(r`(?>\r\n|${minTargetEs2024 ? r`\p{RGI_Emoji}` : emoji}|\P{M}\p{M}*)`, { skipPropertyNameValidation: true }), parent));
2059
- } else if (kind === "hex") replaceWith(setParent(Q("AHex", { negate }), parent));
2060
- else if (kind === "newline") replaceWith(setParentDeep(parseFragment(negate ? "[^\n]" : "(?>\r\n?|[\n\v\f…\u2028\u2029])"), parent));
2061
- else if (kind === "posix") {
2062
- if (!minTargetEs2024 && (value === "graph" || value === "print")) {
2063
- if (accuracy === "strict") throw new Error(`POSIX class "${value}" requires min target ES2024 or non-strict accuracy`);
2064
- let ascii = {
2065
- graph: "!-~",
2066
- print: " -~"
2067
- }[value];
2068
- if (negate) ascii = `\0-${cp(ascii.codePointAt(0) - 1)}${cp(ascii.codePointAt(2) + 1)}-\u{10FFFF}`;
2069
- replaceWith(setParentDeep(parseFragment(`[${ascii}]`), parent));
2070
- } else replaceWith(setParentDeep(setNegate(parseFragment(PosixClassMap.get(value)), negate), parent));
2071
- } else if (kind === "property") {
2072
- if (!JsUnicodePropertyMap.has(w(value))) node.key = "sc";
2073
- } else if (kind === "space") replaceWith(setParent(Q("space", { negate }), parent));
2074
- else if (kind === "word") replaceWith(setParentDeep(setNegate(parseFragment(defaultWordChar), negate), parent));
2075
- else throw new Error(`Unexpected character set kind "${kind}"`);
2076
- },
2077
- Directive({ node, parent, root, remove, replaceWith, removeAllPrevSiblings, removeAllNextSiblings }) {
2078
- const { kind, flags } = node;
2079
- if (kind === "flags") {
2080
- if (!flags.enable && !flags.disable) remove();
2081
- else {
2082
- const flagGroup = A({ flags });
2083
- flagGroup.body[0].body = removeAllNextSiblings();
2084
- replaceWith(setParentDeep(flagGroup, parent), { traverse: true });
2085
- }
2086
- } else if (kind === "keep") {
2087
- const firstAlt = root.body[0];
2088
- const topLevel = root.body.length === 1 && o(firstAlt, { type: "Group" }) && firstAlt.body[0].body.length === 1 ? firstAlt.body[0] : root;
2089
- if (parent.parent !== topLevel || topLevel.body.length > 1) throw new Error(r`Uses "\K" in a way that's unsupported`);
2090
- const lookbehind = K({ behind: true });
2091
- lookbehind.body[0].body = removeAllPrevSiblings();
2092
- replaceWith(setParentDeep(lookbehind, parent));
2093
- } else throw new Error(`Unexpected directive kind "${kind}"`);
2094
- },
2095
- Flags({ node, parent }) {
2096
- if (node.posixIsAscii) throw new Error("Unsupported flag \"P\"");
2097
- if (node.textSegmentMode === "word") throw new Error("Unsupported flag \"y{w}\"");
2098
- [
2099
- "digitIsAscii",
2100
- "extended",
2101
- "posixIsAscii",
2102
- "spaceIsAscii",
2103
- "wordIsAscii",
2104
- "textSegmentMode"
2105
- ].forEach((f) => delete node[f]);
2106
- Object.assign(node, {
2107
- global: false,
2108
- hasIndices: false,
2109
- multiline: false,
2110
- sticky: node.sticky ?? false
2111
- });
2112
- parent.options = {
2113
- disable: {
2114
- x: true,
2115
- n: true
2116
- },
2117
- force: { v: true }
2118
- };
2119
- },
2120
- Group({ node }) {
2121
- if (!node.flags) return;
2122
- const { enable, disable } = node.flags;
2123
- enable?.extended && delete enable.extended;
2124
- disable?.extended && delete disable.extended;
2125
- enable?.dotAll && disable?.dotAll && delete enable.dotAll;
2126
- enable?.ignoreCase && disable?.ignoreCase && delete enable.ignoreCase;
2127
- enable && !Object.keys(enable).length && delete node.flags.enable;
2128
- disable && !Object.keys(disable).length && delete node.flags.disable;
2129
- !node.flags.enable && !node.flags.disable && delete node.flags;
2130
- },
2131
- LookaroundAssertion({ node }, state) {
2132
- const { kind } = node;
2133
- if (kind === "lookbehind") state.passedLookbehind = true;
2134
- },
2135
- NamedCallout({ node, parent, replaceWith }) {
2136
- const { kind } = node;
2137
- if (kind === "fail") replaceWith(setParentDeep(K({ negate: true }), parent));
2138
- else throw new Error(`Unsupported named callout "(*${kind.toUpperCase()}"`);
2139
- },
2140
- Quantifier({ node }) {
2141
- if (node.body.type === "Quantifier") {
2142
- const group = A();
2143
- group.body[0].body.push(node.body);
2144
- node.body = setParentDeep(group, node);
2145
- }
2146
- },
2147
- Regex: {
2148
- enter({ node }, { supportedGNodes }) {
2149
- const leadingGs = [];
2150
- let hasAltWithLeadG = false;
2151
- let hasAltWithoutLeadG = false;
2152
- for (const alt of node.body) if (alt.body.length === 1 && alt.body[0].kind === "search_start") alt.body.pop();
2153
- else {
2154
- const leadingG = getLeadingG(alt.body);
2155
- if (leadingG) {
2156
- hasAltWithLeadG = true;
2157
- Array.isArray(leadingG) ? leadingGs.push(...leadingG) : leadingGs.push(leadingG);
2158
- } else hasAltWithoutLeadG = true;
2159
- }
2160
- if (hasAltWithLeadG && !hasAltWithoutLeadG) leadingGs.forEach((g) => supportedGNodes.add(g));
2161
- },
2162
- exit(_, { accuracy, passedLookbehind, strategy }) {
2163
- if (accuracy === "strict" && passedLookbehind && strategy) throw new Error(r`Uses "\G" in a way that requires non-strict accuracy`);
2164
- }
2165
- },
2166
- Subroutine({ node }, { jsGroupNameMap }) {
2167
- let { ref } = node;
2168
- if (typeof ref === "string" && !isValidJsGroupName(ref)) {
2169
- ref = getAndStoreJsGroupName(ref, jsGroupNameMap);
2170
- node.ref = ref;
2171
- }
2172
- }
2173
- };
2174
- var SecondPassVisitor = {
2175
- Backreference({ node }, { multiplexCapturesToLeftByRef, reffedNodesByReferencer }) {
2176
- const { orphan, ref } = node;
2177
- if (!orphan) reffedNodesByReferencer.set(node, [...multiplexCapturesToLeftByRef.get(ref).map(({ node: node2 }) => node2)]);
2178
- },
2179
- CapturingGroup: {
2180
- enter({ node, parent, replaceWith, skip }, { groupOriginByCopy, groupsByName, multiplexCapturesToLeftByRef, openRefs, reffedNodesByReferencer }) {
2181
- const origin = groupOriginByCopy.get(node);
2182
- if (origin && openRefs.has(node.number)) {
2183
- const recursion2 = setParent(createRecursion(node.number), parent);
2184
- reffedNodesByReferencer.set(recursion2, openRefs.get(node.number));
2185
- replaceWith(recursion2);
2186
- return;
2187
- }
2188
- openRefs.set(node.number, node);
2189
- multiplexCapturesToLeftByRef.set(node.number, []);
2190
- if (node.name) getOrInsert(multiplexCapturesToLeftByRef, node.name, []);
2191
- const multiplexNodes = multiplexCapturesToLeftByRef.get(node.name ?? node.number);
2192
- for (let i = 0; i < multiplexNodes.length; i++) {
2193
- const multiplex = multiplexNodes[i];
2194
- if (origin === multiplex.node || origin && origin === multiplex.origin || node === multiplex.origin) {
2195
- multiplexNodes.splice(i, 1);
2196
- break;
2197
- }
2198
- }
2199
- multiplexCapturesToLeftByRef.get(node.number).push({
2200
- node,
2201
- origin
2202
- });
2203
- if (node.name) multiplexCapturesToLeftByRef.get(node.name).push({
2204
- node,
2205
- origin
2206
- });
2207
- if (node.name) {
2208
- const groupsWithSameName = getOrInsert(groupsByName, node.name, /* @__PURE__ */ new Map());
2209
- let hasDuplicateNameToRemove = false;
2210
- if (origin) hasDuplicateNameToRemove = true;
2211
- else for (const groupInfo of groupsWithSameName.values()) if (!groupInfo.hasDuplicateNameToRemove) {
2212
- hasDuplicateNameToRemove = true;
2213
- break;
2214
- }
2215
- groupsByName.get(node.name).set(node, {
2216
- node,
2217
- hasDuplicateNameToRemove
2218
- });
2219
- }
2220
- },
2221
- exit({ node }, { openRefs }) {
2222
- if (openRefs.get(node.number) === node) openRefs.delete(node.number);
2223
- }
2224
- },
2225
- Group: {
2226
- enter({ node }, state) {
2227
- state.prevFlags = state.currentFlags;
2228
- if (node.flags) state.currentFlags = getNewCurrentFlags(state.currentFlags, node.flags);
2229
- },
2230
- exit(_, state) {
2231
- state.currentFlags = state.prevFlags;
2232
- }
2233
- },
2234
- Subroutine({ node, parent, replaceWith }, state) {
2235
- const { isRecursive, ref } = node;
2236
- if (isRecursive) {
2237
- let reffed = parent;
2238
- while (reffed = reffed.parent) if (reffed.type === "CapturingGroup" && (reffed.name === ref || reffed.number === ref)) break;
2239
- state.reffedNodesByReferencer.set(node, reffed);
2240
- return;
2241
- }
2242
- const reffedGroupNode = state.subroutineRefMap.get(ref);
2243
- const isGlobalRecursion = ref === 0;
2244
- const expandedSubroutine = isGlobalRecursion ? createRecursion(0) : cloneCapturingGroup(reffedGroupNode, state.groupOriginByCopy, null);
2245
- let replacement = expandedSubroutine;
2246
- if (!isGlobalRecursion) {
2247
- const reffedGroupFlagMods = getCombinedFlagModsFromFlagNodes(getAllParents(reffedGroupNode, (p) => p.type === "Group" && !!p.flags));
2248
- const reffedGroupFlags = reffedGroupFlagMods ? getNewCurrentFlags(state.globalFlags, reffedGroupFlagMods) : state.globalFlags;
2249
- if (!areFlagsEqual(reffedGroupFlags, state.currentFlags)) {
2250
- replacement = A({ flags: getFlagModsFromFlags(reffedGroupFlags) });
2251
- replacement.body[0].body.push(expandedSubroutine);
2252
- }
2253
- }
2254
- replaceWith(setParentDeep(replacement, parent), { traverse: !isGlobalRecursion });
2255
- }
2256
- };
2257
- var ThirdPassVisitor = {
2258
- Backreference({ node, parent, replaceWith }, state) {
2259
- if (node.orphan) {
2260
- state.highestOrphanBackref = Math.max(state.highestOrphanBackref, node.ref);
2261
- return;
2262
- }
2263
- const participants = state.reffedNodesByReferencer.get(node).filter((reffed) => canParticipateWithNode(reffed, node));
2264
- if (!participants.length) replaceWith(setParentDeep(K({ negate: true }), parent));
2265
- else if (participants.length > 1) replaceWith(setParentDeep(A({
2266
- atomic: true,
2267
- body: participants.reverse().map((reffed) => b({ body: [k(reffed.number)] }))
2268
- }), parent));
2269
- else node.ref = participants[0].number;
2270
- },
2271
- CapturingGroup({ node }, state) {
2272
- node.number = ++state.numCapturesToLeft;
2273
- if (node.name) {
2274
- if (state.groupsByName.get(node.name).get(node).hasDuplicateNameToRemove) delete node.name;
2275
- }
2276
- },
2277
- Regex: { exit({ node }, state) {
2278
- const numCapsNeeded = Math.max(state.highestOrphanBackref - state.numCapturesToLeft, 0);
2279
- for (let i = 0; i < numCapsNeeded; i++) {
2280
- const emptyCapture = P();
2281
- node.body.at(-1).body.push(emptyCapture);
2282
- }
2283
- } },
2284
- Subroutine({ node }, state) {
2285
- if (!node.isRecursive || node.ref === 0) return;
2286
- node.ref = state.reffedNodesByReferencer.get(node).number;
2287
- }
2288
- };
2289
- function addParentProperties(root) {
2290
- S(root, { "*"({ node, parent }) {
2291
- node.parent = parent;
2292
- } });
2293
- }
2294
- function areFlagsEqual(a, b) {
2295
- return a.dotAll === b.dotAll && a.ignoreCase === b.ignoreCase;
2296
- }
2297
- function canParticipateWithNode(capture, node) {
2298
- let rightmostPoint = node;
2299
- do {
2300
- if (rightmostPoint.type === "Regex") return false;
2301
- if (rightmostPoint.type === "Alternative") continue;
2302
- if (rightmostPoint === capture) return false;
2303
- const kidsOfParent = getKids(rightmostPoint.parent);
2304
- for (const kid of kidsOfParent) {
2305
- if (kid === rightmostPoint) break;
2306
- if (kid === capture || isAncestorOf(kid, capture)) return true;
2307
- }
2308
- } while (rightmostPoint = rightmostPoint.parent);
2309
- throw new Error("Unexpected path");
2310
- }
2311
- function cloneCapturingGroup(obj, originMap, up, up2) {
2312
- const store = Array.isArray(obj) ? [] : {};
2313
- for (const [key, value] of Object.entries(obj)) if (key === "parent") store.parent = Array.isArray(up) ? up2 : up;
2314
- else if (value && typeof value === "object") store[key] = cloneCapturingGroup(value, originMap, store, up);
2315
- else {
2316
- if (key === "type" && value === "CapturingGroup") originMap.set(store, originMap.get(obj) ?? obj);
2317
- store[key] = value;
2318
- }
2319
- return store;
2320
- }
2321
- function createRecursion(ref) {
2322
- const node = O(ref);
2323
- node.isRecursive = true;
2324
- return node;
2325
- }
2326
- function getAllParents(node, filterFn) {
2327
- const results = [];
2328
- while (node = node.parent) if (!filterFn || filterFn(node)) results.push(node);
2329
- return results;
2330
- }
2331
- function getAndStoreJsGroupName(name, map) {
2332
- if (map.has(name)) return map.get(name);
2333
- const jsName = `$${map.size}_${name.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/gu, "_")}`;
2334
- map.set(name, jsName);
2335
- return jsName;
2336
- }
2337
- function getCombinedFlagModsFromFlagNodes(flagNodes) {
2338
- const flagProps = ["dotAll", "ignoreCase"];
2339
- const combinedFlags = {
2340
- enable: {},
2341
- disable: {}
2342
- };
2343
- flagNodes.forEach(({ flags }) => {
2344
- flagProps.forEach((prop) => {
2345
- if (flags.enable?.[prop]) {
2346
- delete combinedFlags.disable[prop];
2347
- combinedFlags.enable[prop] = true;
2348
- }
2349
- if (flags.disable?.[prop]) combinedFlags.disable[prop] = true;
2350
- });
2351
- });
2352
- if (!Object.keys(combinedFlags.enable).length) delete combinedFlags.enable;
2353
- if (!Object.keys(combinedFlags.disable).length) delete combinedFlags.disable;
2354
- if (combinedFlags.enable || combinedFlags.disable) return combinedFlags;
2355
- return null;
2356
- }
2357
- function getFlagModsFromFlags({ dotAll, ignoreCase }) {
2358
- const mods = {};
2359
- if (dotAll || ignoreCase) {
2360
- mods.enable = {};
2361
- dotAll && (mods.enable.dotAll = true);
2362
- ignoreCase && (mods.enable.ignoreCase = true);
2363
- }
2364
- if (!dotAll || !ignoreCase) {
2365
- mods.disable = {};
2366
- !dotAll && (mods.disable.dotAll = true);
2367
- !ignoreCase && (mods.disable.ignoreCase = true);
2368
- }
2369
- return mods;
2370
- }
2371
- function getKids(node) {
2372
- if (!node) throw new Error("Node expected");
2373
- const { body } = node;
2374
- return Array.isArray(body) ? body : body ? [body] : null;
2375
- }
2376
- function getLeadingG(els) {
2377
- const firstToConsider = els.find((el) => el.kind === "search_start" || isLoneGLookaround(el, { negate: false }) || !isAlwaysZeroLength(el));
2378
- if (!firstToConsider) return null;
2379
- if (firstToConsider.kind === "search_start") return firstToConsider;
2380
- if (firstToConsider.type === "LookaroundAssertion") return firstToConsider.body[0].body[0];
2381
- if (firstToConsider.type === "CapturingGroup" || firstToConsider.type === "Group") {
2382
- const gNodesForGroup = [];
2383
- for (const alt of firstToConsider.body) {
2384
- const leadingG = getLeadingG(alt.body);
2385
- if (!leadingG) return null;
2386
- Array.isArray(leadingG) ? gNodesForGroup.push(...leadingG) : gNodesForGroup.push(leadingG);
2387
- }
2388
- return gNodesForGroup;
2389
- }
2390
- return null;
2391
- }
2392
- function isAncestorOf(node, descendant) {
2393
- const kids = getKids(node) ?? [];
2394
- for (const kid of kids) if (kid === descendant || isAncestorOf(kid, descendant)) return true;
2395
- return false;
2396
- }
2397
- function isAlwaysZeroLength({ type }) {
2398
- return type === "Assertion" || type === "Directive" || type === "LookaroundAssertion";
2399
- }
2400
- function isAlwaysNonZeroLength(node) {
2401
- const types = [
2402
- "Character",
2403
- "CharacterClass",
2404
- "CharacterSet"
2405
- ];
2406
- return types.includes(node.type) || node.type === "Quantifier" && node.min && types.includes(node.body.type);
2407
- }
2408
- function isLoneGLookaround(node, options) {
2409
- const opts = {
2410
- negate: null,
2411
- ...options
2412
- };
2413
- return node.type === "LookaroundAssertion" && (opts.negate === null || node.negate === opts.negate) && node.body.length === 1 && o(node.body[0], {
2414
- type: "Assertion",
2415
- kind: "search_start"
2416
- });
2417
- }
2418
- function isValidJsGroupName(name) {
2419
- return /^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(name);
2420
- }
2421
- function parseFragment(pattern, options) {
2422
- const alts = J(pattern, {
2423
- ...options,
2424
- unicodePropertyMap: JsUnicodePropertyMap
2425
- }).body;
2426
- if (alts.length > 1 || alts[0].body.length > 1) return A({ body: alts });
2427
- return alts[0].body[0];
2428
- }
2429
- function setNegate(node, negate) {
2430
- node.negate = negate;
2431
- return node;
2432
- }
2433
- function setParent(node, parent) {
2434
- node.parent = parent;
2435
- return node;
2436
- }
2437
- function setParentDeep(node, parent) {
2438
- addParentProperties(node);
2439
- node.parent = parent;
2440
- return node;
2441
- }
2442
- function generate(ast, options) {
2443
- const opts = getOptions(options);
2444
- const minTargetEs2024 = isMinTarget(opts.target, "ES2024");
2445
- const minTargetEs2025 = isMinTarget(opts.target, "ES2025");
2446
- const recursionLimit = opts.rules.recursionLimit;
2447
- if (!Number.isInteger(recursionLimit) || recursionLimit < 2 || recursionLimit > 20) throw new Error("Invalid recursionLimit; use 2-20");
2448
- let hasCaseInsensitiveNode = null;
2449
- let hasCaseSensitiveNode = null;
2450
- if (!minTargetEs2025) {
2451
- const iStack = [ast.flags.ignoreCase];
2452
- S(ast, FlagModifierVisitor, {
2453
- getCurrentModI: () => iStack.at(-1),
2454
- popModI() {
2455
- iStack.pop();
2456
- },
2457
- pushModI(isIOn) {
2458
- iStack.push(isIOn);
2459
- },
2460
- setHasCasedChar() {
2461
- if (iStack.at(-1)) hasCaseInsensitiveNode = true;
2462
- else hasCaseSensitiveNode = true;
2463
- }
2464
- });
2465
- }
2466
- const appliedGlobalFlags = {
2467
- dotAll: ast.flags.dotAll,
2468
- ignoreCase: !!((ast.flags.ignoreCase || hasCaseInsensitiveNode) && !hasCaseSensitiveNode)
2469
- };
2470
- let lastNode = ast;
2471
- const state = {
2472
- accuracy: opts.accuracy,
2473
- appliedGlobalFlags,
2474
- captureMap: /* @__PURE__ */ new Map(),
2475
- currentFlags: {
2476
- dotAll: ast.flags.dotAll,
2477
- ignoreCase: ast.flags.ignoreCase
2478
- },
2479
- inCharClass: false,
2480
- lastNode,
2481
- originMap: ast._originMap,
2482
- recursionLimit,
2483
- useAppliedIgnoreCase: !!(!minTargetEs2025 && hasCaseInsensitiveNode && hasCaseSensitiveNode),
2484
- useFlagMods: minTargetEs2025,
2485
- useFlagV: minTargetEs2024,
2486
- verbose: opts.verbose
2487
- };
2488
- function gen(node) {
2489
- state.lastNode = lastNode;
2490
- lastNode = node;
2491
- return throwIfNullish(generator[node.type], `Unexpected node type "${node.type}"`)(node, state, gen);
2492
- }
2493
- const result = {
2494
- pattern: ast.body.map(gen).join("|"),
2495
- flags: gen(ast.flags),
2496
- options: { ...ast.options }
2497
- };
2498
- if (!minTargetEs2024) {
2499
- delete result.options.force.v;
2500
- result.options.disable.v = true;
2501
- result.options.unicodeSetsPlugin = null;
2502
- }
2503
- result._captureTransfers = /* @__PURE__ */ new Map();
2504
- result._hiddenCaptures = [];
2505
- state.captureMap.forEach((value, key) => {
2506
- if (value.hidden) result._hiddenCaptures.push(key);
2507
- if (value.transferTo) getOrInsert(result._captureTransfers, value.transferTo, []).push(key);
2508
- });
2509
- return result;
2510
- }
2511
- var FlagModifierVisitor = {
2512
- "*": {
2513
- enter({ node }, state) {
2514
- if (isAnyGroup(node)) {
2515
- const currentModI = state.getCurrentModI();
2516
- state.pushModI(node.flags ? getNewCurrentFlags({ ignoreCase: currentModI }, node.flags).ignoreCase : currentModI);
2517
- }
2518
- },
2519
- exit({ node }, state) {
2520
- if (isAnyGroup(node)) state.popModI();
2521
- }
2522
- },
2523
- Backreference(_, state) {
2524
- state.setHasCasedChar();
2525
- },
2526
- Character({ node }, state) {
2527
- if (charHasCase(cp(node.value))) state.setHasCasedChar();
2528
- },
2529
- CharacterClassRange({ node, skip }, state) {
2530
- skip();
2531
- if (getCasesOutsideCharClassRange(node, { firstOnly: true }).length) state.setHasCasedChar();
2532
- },
2533
- CharacterSet({ node }, state) {
2534
- if (node.kind === "property" && UnicodePropertiesWithSpecificCase.has(node.value)) state.setHasCasedChar();
2535
- }
2536
- };
2537
- var generator = {
2538
- /**
2539
- @param {AlternativeNode} node
2540
- */
2541
- Alternative({ body }, _, gen) {
2542
- return body.map(gen).join("");
2543
- },
2544
- /**
2545
- @param {AssertionNode} node
2546
- */
2547
- Assertion({ kind, negate }) {
2548
- if (kind === "string_end") return "$";
2549
- if (kind === "string_start") return "^";
2550
- if (kind === "word_boundary") return negate ? r`\B` : r`\b`;
2551
- throw new Error(`Unexpected assertion kind "${kind}"`);
2552
- },
2553
- /**
2554
- @param {BackreferenceNode} node
2555
- */
2556
- Backreference({ ref }, state) {
2557
- if (typeof ref !== "number") throw new Error("Unexpected named backref in transformed AST");
2558
- if (!state.useFlagMods && state.accuracy === "strict" && state.currentFlags.ignoreCase && !state.captureMap.get(ref).ignoreCase) throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");
2559
- return "\\" + ref;
2560
- },
2561
- /**
2562
- @param {CapturingGroupNode} node
2563
- */
2564
- CapturingGroup(node, state, gen) {
2565
- const { body, name, number } = node;
2566
- const data = { ignoreCase: state.currentFlags.ignoreCase };
2567
- const origin = state.originMap.get(node);
2568
- if (origin) {
2569
- data.hidden = true;
2570
- if (number > origin.number) data.transferTo = origin.number;
2571
- }
2572
- state.captureMap.set(number, data);
2573
- return `(${name ? `?<${name}>` : ""}${body.map(gen).join("|")})`;
2574
- },
2575
- /**
2576
- @param {CharacterNode} node
2577
- */
2578
- Character({ value }, state) {
2579
- const char = cp(value);
2580
- const escaped = getCharEscape(value, {
2581
- escDigit: state.lastNode.type === "Backreference",
2582
- inCharClass: state.inCharClass,
2583
- useFlagV: state.useFlagV
2584
- });
2585
- if (escaped !== char) return escaped;
2586
- if (state.useAppliedIgnoreCase && state.currentFlags.ignoreCase && charHasCase(char)) {
2587
- const cases = getIgnoreCaseMatchChars(char);
2588
- return state.inCharClass ? cases.join("") : cases.length > 1 ? `[${cases.join("")}]` : cases[0];
2589
- }
2590
- return char;
2591
- },
2592
- /**
2593
- @param {CharacterClassNode} node
2594
- */
2595
- CharacterClass(node, state, gen) {
2596
- const { kind, negate, parent } = node;
2597
- let { body } = node;
2598
- if (kind === "intersection" && !state.useFlagV) throw new Error("Use of character class intersection requires min target ES2024");
2599
- if (envFlags.bugFlagVLiteralHyphenIsRange && state.useFlagV && body.some(isLiteralHyphen)) body = [m(45), ...body.filter((kid) => !isLiteralHyphen(kid))];
2600
- const genClass = () => `[${negate ? "^" : ""}${body.map(gen).join(kind === "intersection" ? "&&" : "")}]`;
2601
- if (!state.inCharClass) {
2602
- if ((!state.useFlagV || envFlags.bugNestedClassIgnoresNegation) && !negate) {
2603
- const negatedChildClasses = body.filter((kid) => kid.type === "CharacterClass" && kid.kind === "union" && kid.negate);
2604
- if (negatedChildClasses.length) {
2605
- const group = A();
2606
- const groupFirstAlt = group.body[0];
2607
- group.parent = parent;
2608
- groupFirstAlt.parent = group;
2609
- body = body.filter((kid) => !negatedChildClasses.includes(kid));
2610
- node.body = body;
2611
- if (body.length) {
2612
- node.parent = groupFirstAlt;
2613
- groupFirstAlt.body.push(node);
2614
- } else group.body.pop();
2615
- negatedChildClasses.forEach((cc) => {
2616
- const newAlt = b({ body: [cc] });
2617
- cc.parent = newAlt;
2618
- newAlt.parent = group;
2619
- group.body.push(newAlt);
2620
- });
2621
- return gen(group);
2622
- }
2623
- }
2624
- state.inCharClass = true;
2625
- const result = genClass();
2626
- state.inCharClass = false;
2627
- return result;
2628
- }
2629
- const firstEl = body[0];
2630
- if (kind === "union" && !negate && firstEl && ((!state.useFlagV || !state.verbose) && parent.kind === "union" && !(envFlags.bugFlagVLiteralHyphenIsRange && state.useFlagV) || !state.verbose && parent.kind === "intersection" && body.length === 1 && firstEl.type !== "CharacterClassRange")) return body.map(gen).join("");
2631
- if (!state.useFlagV && parent.type === "CharacterClass") throw new Error("Uses nested character class in a way that requires min target ES2024");
2632
- return genClass();
2633
- },
2634
- /**
2635
- @param {CharacterClassRangeNode} node
2636
- */
2637
- CharacterClassRange(node, state) {
2638
- const min = node.min.value;
2639
- const max = node.max.value;
2640
- const escOpts = {
2641
- escDigit: false,
2642
- inCharClass: true,
2643
- useFlagV: state.useFlagV
2644
- };
2645
- const minStr = getCharEscape(min, escOpts);
2646
- const maxStr = getCharEscape(max, escOpts);
2647
- const extraChars = /* @__PURE__ */ new Set();
2648
- if (state.useAppliedIgnoreCase && state.currentFlags.ignoreCase) getCodePointRangesFromChars(getCasesOutsideCharClassRange(node)).forEach((value) => {
2649
- extraChars.add(Array.isArray(value) ? `${getCharEscape(value[0], escOpts)}-${getCharEscape(value[1], escOpts)}` : getCharEscape(value, escOpts));
2650
- });
2651
- return `${minStr}-${maxStr}${[...extraChars].join("")}`;
2652
- },
2653
- /**
2654
- @param {CharacterSetNode} node
2655
- */
2656
- CharacterSet({ kind, negate, value, key }, state) {
2657
- if (kind === "dot") return state.currentFlags.dotAll ? state.appliedGlobalFlags.dotAll || state.useFlagMods ? "." : "[^]" : r`[^\n]`;
2658
- if (kind === "digit") return negate ? r`\D` : r`\d`;
2659
- if (kind === "property") {
2660
- if (state.useAppliedIgnoreCase && state.currentFlags.ignoreCase && UnicodePropertiesWithSpecificCase.has(value)) throw new Error(`Unicode property "${value}" can't be case-insensitive when other chars have specific case`);
2661
- return `${negate ? r`\P` : r`\p`}{${key ? `${key}=` : ""}${value}}`;
2662
- }
2663
- if (kind === "word") return negate ? r`\W` : r`\w`;
2664
- throw new Error(`Unexpected character set kind "${kind}"`);
2665
- },
2666
- /**
2667
- @param {FlagsNode} node
2668
- */
2669
- Flags(node, state) {
2670
- return (state.appliedGlobalFlags.ignoreCase ? "i" : "") + (node.dotAll ? "s" : "") + (node.sticky ? "y" : "");
2671
- },
2672
- /**
2673
- @param {GroupNode} node
2674
- */
2675
- Group({ atomic: atomic2, body, flags, parent }, state, gen) {
2676
- const currentFlags = state.currentFlags;
2677
- if (flags) state.currentFlags = getNewCurrentFlags(currentFlags, flags);
2678
- const contents = body.map(gen).join("|");
2679
- const result = !state.verbose && body.length === 1 && parent.type !== "Quantifier" && !atomic2 && (!state.useFlagMods || !flags) ? contents : `(?${getGroupPrefix(atomic2, flags, state.useFlagMods)}${contents})`;
2680
- state.currentFlags = currentFlags;
2681
- return result;
2682
- },
2683
- /**
2684
- @param {LookaroundAssertionNode} node
2685
- */
2686
- LookaroundAssertion({ body, kind, negate }, _, gen) {
2687
- return `(?${`${kind === "lookahead" ? "" : "<"}${negate ? "!" : "="}`}${body.map(gen).join("|")})`;
2688
- },
2689
- /**
2690
- @param {QuantifierNode} node
2691
- */
2692
- Quantifier(node, _, gen) {
2693
- return gen(node.body) + getQuantifierStr(node);
2694
- },
2695
- /**
2696
- @param {SubroutineNode & {isRecursive: true}} node
2697
- */
2698
- Subroutine({ isRecursive, ref }, state) {
2699
- if (!isRecursive) throw new Error("Unexpected non-recursive subroutine in transformed AST");
2700
- const limit = state.recursionLimit;
2701
- return ref === 0 ? `(?R=${limit})` : r`\g<${ref}&R=${limit}>`;
2702
- }
2703
- };
2704
- var BaseEscapeChars = /* @__PURE__ */ new Set([
2705
- "$",
2706
- "(",
2707
- ")",
2708
- "*",
2709
- "+",
2710
- ".",
2711
- "?",
2712
- "[",
2713
- "\\",
2714
- "]",
2715
- "^",
2716
- "{",
2717
- "|",
2718
- "}"
2719
- ]);
2720
- var CharClassEscapeChars = /* @__PURE__ */ new Set([
2721
- "-",
2722
- "\\",
2723
- "]",
2724
- "^",
2725
- "["
2726
- ]);
2727
- var CharClassEscapeCharsFlagV = /* @__PURE__ */ new Set([
2728
- "(",
2729
- ")",
2730
- "-",
2731
- "/",
2732
- "[",
2733
- "\\",
2734
- "]",
2735
- "^",
2736
- "{",
2737
- "|",
2738
- "}",
2739
- "!",
2740
- "#",
2741
- "$",
2742
- "%",
2743
- "&",
2744
- "*",
2745
- "+",
2746
- ",",
2747
- ".",
2748
- ":",
2749
- ";",
2750
- "<",
2751
- "=",
2752
- ">",
2753
- "?",
2754
- "@",
2755
- "`",
2756
- "~"
2757
- ]);
2758
- var CharCodeEscapeMap = /* @__PURE__ */ new Map([
2759
- [9, r`\t`],
2760
- [10, r`\n`],
2761
- [11, r`\v`],
2762
- [12, r`\f`],
2763
- [13, r`\r`],
2764
- [8232, r`\u2028`],
2765
- [8233, r`\u2029`],
2766
- [65279, r`\uFEFF`]
2767
- ]);
2768
- var casedRe = /^\p{Cased}$/u;
2769
- function charHasCase(char) {
2770
- return casedRe.test(char);
2771
- }
2772
- function getCasesOutsideCharClassRange(node, options) {
2773
- const firstOnly = !!options?.firstOnly;
2774
- const min = node.min.value;
2775
- const max = node.max.value;
2776
- const found = [];
2777
- if (min < 65 && (max === 65535 || max >= 131071) || min === 65536 && max >= 131071) return found;
2778
- for (let i = min; i <= max; i++) {
2779
- const char = cp(i);
2780
- if (!charHasCase(char)) continue;
2781
- const charsOutsideRange = getIgnoreCaseMatchChars(char).filter((caseOfChar) => {
2782
- const num = caseOfChar.codePointAt(0);
2783
- return num < min || num > max;
2784
- });
2785
- if (charsOutsideRange.length) {
2786
- found.push(...charsOutsideRange);
2787
- if (firstOnly) break;
2788
- }
2789
- }
2790
- return found;
2791
- }
2792
- function getCharEscape(codePoint, { escDigit, inCharClass, useFlagV }) {
2793
- if (CharCodeEscapeMap.has(codePoint)) return CharCodeEscapeMap.get(codePoint);
2794
- if (codePoint < 32 || codePoint > 126 && codePoint < 160 || codePoint > 262143 || escDigit && isDigitCharCode(codePoint)) return codePoint > 255 ? `\\u{${codePoint.toString(16).toUpperCase()}}` : `\\x${codePoint.toString(16).toUpperCase().padStart(2, "0")}`;
2795
- const escapeChars = inCharClass ? useFlagV ? CharClassEscapeCharsFlagV : CharClassEscapeChars : BaseEscapeChars;
2796
- const char = cp(codePoint);
2797
- return (escapeChars.has(char) ? "\\" : "") + char;
2798
- }
2799
- function getCodePointRangesFromChars(chars) {
2800
- const codePoints = chars.map((char) => char.codePointAt(0)).sort((a, b) => a - b);
2801
- const values = [];
2802
- let start = null;
2803
- for (let i = 0; i < codePoints.length; i++) if (codePoints[i + 1] === codePoints[i] + 1) start ??= codePoints[i];
2804
- else if (start === null) values.push(codePoints[i]);
2805
- else {
2806
- values.push([start, codePoints[i]]);
2807
- start = null;
2808
- }
2809
- return values;
2810
- }
2811
- function getGroupPrefix(atomic2, flagMods, useFlagMods) {
2812
- if (atomic2) return ">";
2813
- let mods = "";
2814
- if (flagMods && useFlagMods) {
2815
- const { enable, disable } = flagMods;
2816
- mods = (enable?.ignoreCase ? "i" : "") + (enable?.dotAll ? "s" : "") + (disable ? "-" : "") + (disable?.ignoreCase ? "i" : "") + (disable?.dotAll ? "s" : "");
2817
- }
2818
- return `${mods}:`;
2819
- }
2820
- function getQuantifierStr({ kind, max, min }) {
2821
- let base;
2822
- if (!min && max === 1) base = "?";
2823
- else if (!min && max === Infinity) base = "*";
2824
- else if (min === 1 && max === Infinity) base = "+";
2825
- else if (min === max) base = `{${min}}`;
2826
- else base = `{${min},${max === Infinity ? "" : max}}`;
2827
- return base + {
2828
- greedy: "",
2829
- lazy: "?",
2830
- possessive: "+"
2831
- }[kind];
2832
- }
2833
- function isAnyGroup({ type }) {
2834
- return type === "CapturingGroup" || type === "Group" || type === "LookaroundAssertion";
2835
- }
2836
- function isDigitCharCode(value) {
2837
- return value > 47 && value < 58;
2838
- }
2839
- function isLiteralHyphen({ type, value }) {
2840
- return type === "Character" && value === 45;
2841
- }
2842
- var EmulatedRegExp = class _EmulatedRegExp extends RegExp {
2843
- /**
2844
- @type {Map<number, {
2845
- hidden?: true;
2846
- transferTo?: number;
2847
- }>}
2848
- */
2849
- #captureMap = /* @__PURE__ */ new Map();
2850
- /**
2851
- @type {RegExp | EmulatedRegExp | null}
2852
- */
2853
- #compiled = null;
2854
- /**
2855
- @type {string}
2856
- */
2857
- #pattern;
2858
- /**
2859
- @type {Map<number, string>?}
2860
- */
2861
- #nameMap = null;
2862
- /**
2863
- @type {string?}
2864
- */
2865
- #strategy = null;
2866
- /**
2867
- Can be used to serialize the instance.
2868
- @type {EmulatedRegExpOptions}
2869
- */
2870
- rawOptions = {};
2871
- get source() {
2872
- return this.#pattern || "(?:)";
2873
- }
2874
- /**
2875
- @overload
2876
- @param {string} pattern
2877
- @param {string} [flags]
2878
- @param {EmulatedRegExpOptions} [options]
2879
- */
2880
- /**
2881
- @overload
2882
- @param {EmulatedRegExp} pattern
2883
- @param {string} [flags]
2884
- */
2885
- constructor(pattern, flags, options) {
2886
- const lazyCompile = !!options?.lazyCompile;
2887
- if (pattern instanceof RegExp) {
2888
- if (options) throw new Error("Cannot provide options when copying a regexp");
2889
- const re = pattern;
2890
- super(re, flags);
2891
- this.#pattern = re.source;
2892
- if (re instanceof _EmulatedRegExp) {
2893
- this.#captureMap = re.#captureMap;
2894
- this.#nameMap = re.#nameMap;
2895
- this.#strategy = re.#strategy;
2896
- this.rawOptions = re.rawOptions;
2897
- }
2898
- } else {
2899
- const opts = {
2900
- hiddenCaptures: [],
2901
- strategy: null,
2902
- transfers: [],
2903
- ...options
2904
- };
2905
- super(lazyCompile ? "" : pattern, flags);
2906
- this.#pattern = pattern;
2907
- this.#captureMap = createCaptureMap(opts.hiddenCaptures, opts.transfers);
2908
- this.#strategy = opts.strategy;
2909
- this.rawOptions = options ?? {};
2910
- }
2911
- if (!lazyCompile) this.#compiled = this;
2912
- }
2913
- /**
2914
- Called internally by all String/RegExp methods that use regexes.
2915
- @override
2916
- @param {string} str
2917
- @returns {RegExpExecArray?}
2918
- */
2919
- exec(str) {
2920
- if (!this.#compiled) {
2921
- const { lazyCompile, ...rest } = this.rawOptions;
2922
- this.#compiled = new _EmulatedRegExp(this.#pattern, this.flags, rest);
2923
- }
2924
- const useLastIndex = this.global || this.sticky;
2925
- const pos = this.lastIndex;
2926
- if (this.#strategy === "clip_search" && useLastIndex && pos) {
2927
- this.lastIndex = 0;
2928
- const match = this.#execCore(str.slice(pos));
2929
- if (match) {
2930
- adjustMatchDetailsForOffset(match, pos, str, this.hasIndices);
2931
- this.lastIndex += pos;
2932
- }
2933
- return match;
2934
- }
2935
- return this.#execCore(str);
2936
- }
2937
- /**
2938
- Adds support for hidden and transfer captures.
2939
- @param {string} str
2940
- @returns
2941
- */
2942
- #execCore(str) {
2943
- this.#compiled.lastIndex = this.lastIndex;
2944
- const match = super.exec.call(this.#compiled, str);
2945
- this.lastIndex = this.#compiled.lastIndex;
2946
- if (!match || !this.#captureMap.size) return match;
2947
- const matchCopy = [...match];
2948
- match.length = 1;
2949
- let indicesCopy;
2950
- if (this.hasIndices) {
2951
- indicesCopy = [...match.indices];
2952
- match.indices.length = 1;
2953
- }
2954
- const mappedNums = [0];
2955
- for (let i = 1; i < matchCopy.length; i++) {
2956
- const { hidden, transferTo } = this.#captureMap.get(i) ?? {};
2957
- if (hidden) mappedNums.push(null);
2958
- else {
2959
- mappedNums.push(match.length);
2960
- match.push(matchCopy[i]);
2961
- if (this.hasIndices) match.indices.push(indicesCopy[i]);
2962
- }
2963
- if (transferTo && matchCopy[i] !== void 0) {
2964
- const to = mappedNums[transferTo];
2965
- if (!to) throw new Error(`Invalid capture transfer to "${to}"`);
2966
- match[to] = matchCopy[i];
2967
- if (this.hasIndices) match.indices[to] = indicesCopy[i];
2968
- if (match.groups) {
2969
- if (!this.#nameMap) this.#nameMap = createNameMap(this.source);
2970
- const name = this.#nameMap.get(transferTo);
2971
- if (name) {
2972
- match.groups[name] = matchCopy[i];
2973
- if (this.hasIndices) match.indices.groups[name] = indicesCopy[i];
2974
- }
2975
- }
2976
- }
2977
- }
2978
- return match;
2979
- }
2980
- };
2981
- function adjustMatchDetailsForOffset(match, offset, input, hasIndices) {
2982
- match.index += offset;
2983
- match.input = input;
2984
- if (hasIndices) {
2985
- const indices = match.indices;
2986
- for (let i = 0; i < indices.length; i++) {
2987
- const arr = indices[i];
2988
- if (arr) indices[i] = [arr[0] + offset, arr[1] + offset];
2989
- }
2990
- const groupIndices = indices.groups;
2991
- if (groupIndices) Object.keys(groupIndices).forEach((key) => {
2992
- const arr = groupIndices[key];
2993
- if (arr) groupIndices[key] = [arr[0] + offset, arr[1] + offset];
2994
- });
2995
- }
2996
- }
2997
- function createCaptureMap(hiddenCaptures, transfers) {
2998
- const captureMap = /* @__PURE__ */ new Map();
2999
- for (const num of hiddenCaptures) captureMap.set(num, { hidden: true });
3000
- for (const [to, from] of transfers) for (const num of from) getOrInsert(captureMap, num, {}).transferTo = to;
3001
- return captureMap;
3002
- }
3003
- function createNameMap(pattern) {
3004
- const re = /(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu;
3005
- const map = /* @__PURE__ */ new Map();
3006
- let numCharClassesOpen = 0;
3007
- let numCaptures = 0;
3008
- let match;
3009
- while (match = re.exec(pattern)) {
3010
- const { 0: m, groups: { capture, name } } = match;
3011
- if (m === "[") numCharClassesOpen++;
3012
- else if (!numCharClassesOpen) {
3013
- if (capture) {
3014
- numCaptures++;
3015
- if (name) map.set(numCaptures, name);
3016
- }
3017
- } else if (m === "]") numCharClassesOpen--;
3018
- }
3019
- return map;
3020
- }
3021
- function toRegExp(pattern, options) {
3022
- const d = toRegExpDetails(pattern, options);
3023
- if (d.options) return new EmulatedRegExp(d.pattern, d.flags, d.options);
3024
- return new RegExp(d.pattern, d.flags);
3025
- }
3026
- function toRegExpDetails(pattern, options) {
3027
- const opts = getOptions(options);
3028
- const regexPlusAst = transform(J(pattern, {
3029
- flags: opts.flags,
3030
- normalizeUnknownPropertyNames: true,
3031
- rules: {
3032
- captureGroup: opts.rules.captureGroup,
3033
- singleline: opts.rules.singleline
3034
- },
3035
- skipBackrefValidation: opts.rules.allowOrphanBackrefs,
3036
- unicodePropertyMap: JsUnicodePropertyMap
3037
- }), {
3038
- accuracy: opts.accuracy,
3039
- asciiWordBoundaries: opts.rules.asciiWordBoundaries,
3040
- avoidSubclass: opts.avoidSubclass,
3041
- bestEffortTarget: opts.target
3042
- });
3043
- const generated = generate(regexPlusAst, opts);
3044
- const recursionResult = recursion(generated.pattern, {
3045
- captureTransfers: generated._captureTransfers,
3046
- hiddenCaptures: generated._hiddenCaptures,
3047
- mode: "external"
3048
- });
3049
- const atomicResult = atomic(possessive(recursionResult.pattern).pattern, {
3050
- captureTransfers: recursionResult.captureTransfers,
3051
- hiddenCaptures: recursionResult.hiddenCaptures
3052
- });
3053
- const details = {
3054
- pattern: atomicResult.pattern,
3055
- flags: `${opts.hasIndices ? "d" : ""}${opts.global ? "g" : ""}${generated.flags}${generated.options.disable.v ? "u" : "v"}`
3056
- };
3057
- if (opts.avoidSubclass) {
3058
- if (opts.lazyCompileLength !== Infinity) throw new Error("Lazy compilation requires subclass");
3059
- } else {
3060
- const hiddenCaptures = atomicResult.hiddenCaptures.sort((a, b) => a - b);
3061
- const transfers = Array.from(atomicResult.captureTransfers);
3062
- const strategy = regexPlusAst._strategy;
3063
- const lazyCompile = details.pattern.length >= opts.lazyCompileLength;
3064
- if (hiddenCaptures.length || transfers.length || strategy || lazyCompile) details.options = {
3065
- ...hiddenCaptures.length && { hiddenCaptures },
3066
- ...transfers.length && { transfers },
3067
- ...strategy && { strategy },
3068
- ...lazyCompile && { lazyCompile }
3069
- };
3070
- }
3071
- return details;
3072
- }
3073
- //#endregion
3074
- //#region ../../node_modules/.pnpm/@shikijs+engine-javascript@4.3.1/node_modules/@shikijs/engine-javascript/dist/engine-compile.mjs
3075
- /**
3076
- * The default regex constructor for the JavaScript RegExp engine.
3077
- */
3078
- function defaultJavaScriptRegexConstructor(pattern, options) {
3079
- return toRegExp(pattern, {
3080
- global: true,
3081
- hasIndices: true,
3082
- lazyCompileLength: 3e3,
3083
- rules: {
3084
- allowOrphanBackrefs: true,
3085
- asciiWordBoundaries: true,
3086
- captureGroup: true,
3087
- recursionLimit: 5,
3088
- singleline: true
3089
- },
3090
- ...options
3091
- });
3092
- }
3093
- /**
3094
- * Use the modern JavaScript RegExp engine to implement the OnigScanner.
3095
- *
3096
- * As Oniguruma supports some features that can't be emulated using native JavaScript regexes, some
3097
- * patterns are not supported. Errors will be thrown when parsing TextMate grammars with
3098
- * unsupported patterns, and when the grammar includes patterns that use invalid Oniguruma syntax.
3099
- * Set `forgiving` to `true` to ignore these errors and skip any unsupported or invalid patterns.
3100
- */
3101
- function createJavaScriptRegexEngine(options = {}) {
3102
- const _options = {
3103
- target: "auto",
3104
- cache: /* @__PURE__ */ new Map(),
3105
- ...options
3106
- };
3107
- _options.regexConstructor ||= (pattern) => defaultJavaScriptRegexConstructor(pattern, { target: _options.target });
3108
- return {
3109
- createScanner(patterns) {
3110
- return new JavaScriptScanner(patterns, _options);
3111
- },
3112
- createString(s) {
3113
- return { content: s };
3114
- }
3115
- };
3116
- }
3117
- //#endregion
3118
- export { createJavaScriptRegexEngine };