@kitnai/chat 0.1.0 → 0.3.0

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.
@@ -1,94 +1,6 @@
1
- var Fr = Object.defineProperty;
2
- var Gr = Object.getPrototypeOf;
3
- var Pr = Reflect.get;
4
- var De = (e) => {
5
- throw TypeError(e);
6
- };
7
- var Rr = (e, r, t) => r in e ? Fr(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
8
- var se = (e, r, t) => Rr(e, typeof r != "symbol" ? r + "" : r, t), ye = (e, r, t) => r.has(e) || De("Cannot " + t);
9
- var E = (e, r, t) => (ye(e, r, "read from private field"), t ? t.call(e) : r.get(e)), z = (e, r, t) => r.has(e) ? De("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(e) : r.set(e, t), M = (e, r, t, n) => (ye(e, r, "write to private field"), n ? n.call(e, t) : r.set(e, t), t), Ce = (e, r, t) => (ye(e, r, "access private method"), t);
10
- var Te = (e, r, t) => Pr(Gr(e), t, r);
11
- var ar = class {
12
- constructor(e, r = {}) {
13
- se(this, "patterns");
14
- se(this, "options");
15
- se(this, "regexps");
16
- this.patterns = e, this.options = r;
17
- const { forgiving: t = !1, cache: n, regexConstructor: s } = r;
18
- if (!s) throw new Error("Option `regexConstructor` is not provided");
19
- this.regexps = e.map((o) => {
20
- if (typeof o != "string") return o;
21
- const a = n == null ? void 0 : n.get(o);
22
- if (a) {
23
- if (a instanceof RegExp) return a;
24
- if (t) return null;
25
- throw a;
26
- }
27
- try {
28
- const i = s(o);
29
- return n == null || n.set(o, i), i;
30
- } catch (i) {
31
- if (n == null || n.set(o, i), t) return null;
32
- throw i;
33
- }
34
- });
35
- }
36
- findNextMatchSync(e, r, t) {
37
- const n = typeof e == "string" ? e : e.content, s = [];
38
- function o(a, i, u = 0) {
39
- return {
40
- index: a,
41
- captureIndices: i.indices.map((c) => c == null ? {
42
- start: 4294967295,
43
- end: 4294967295,
44
- length: 0
45
- } : {
46
- start: c[0] + u,
47
- end: c[1] + u,
48
- length: c[1] - c[0]
49
- })
50
- };
51
- }
52
- for (let a = 0; a < this.regexps.length; a++) {
53
- const i = this.regexps[a];
54
- if (i)
55
- try {
56
- i.lastIndex = r;
57
- const u = i.exec(n);
58
- if (!u) continue;
59
- if (u.index === r) return o(a, u, 0);
60
- s.push([
61
- a,
62
- u,
63
- 0
64
- ]);
65
- } catch (u) {
66
- if (this.options.forgiving) continue;
67
- throw u;
68
- }
69
- }
70
- if (s.length) {
71
- const a = Math.min(...s.map((i) => i[1].index));
72
- for (const [i, u, c] of s) if (u.index === a) return o(i, u, c);
73
- }
74
- return null;
75
- }
76
- };
77
- function re(e) {
78
- if ([...e].length !== 1) throw new Error(`Expected "${e}" to be a single code point`);
79
- return e.codePointAt(0);
80
- }
81
- function Ur(e, r, t) {
82
- return e.has(r) || e.set(r, t), e.get(r);
83
- }
84
- const Fe = /* @__PURE__ */ new Set(["alnum", "alpha", "ascii", "blank", "cntrl", "digit", "graph", "lower", "print", "punct", "space", "upper", "word", "xdigit"]), x = String.raw;
85
- function te(e, r) {
86
- if (e == null) throw new Error(r ?? "Value expected");
87
- return e;
88
- }
89
- const ir = x`\[\^?`, ur = `c.? | C(?:-.?)?|${x`[pP]\{(?:\^?[-\x20_]*[A-Za-z][-\x20\w]*\})?`}|${x`x[89A-Fa-f]\p{AHex}(?:\\x[89A-Fa-f]\p{AHex})*`}|${x`u(?:\p{AHex}{4})? | x\{[^\}]*\}? | x\p{AHex}{0,2}`}|${x`o\{[^\}]*\}?`}|${x`\d{1,3}`}`, Ge = /[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/, ce = new RegExp(x`
1
+ var Pn=Object.defineProperty,Fn=Object.getPrototypeOf,Un=Reflect.get,De=e=>{throw TypeError(e)},Bn=(e,n,t)=>n in e?Pn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,ie=(e,n,t)=>Bn(e,typeof n!="symbol"?n+"":n,t),me=(e,n,t)=>n.has(e)||De("Cannot "+t),E=(e,n,t)=>(me(e,n,"read from private field"),t?t.call(e):n.get(e)),X=(e,n,t)=>n.has(e)?De("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(e):n.set(e,t),L=(e,n,t,r)=>(me(e,n,"write to private field"),r?r.call(e,t):n.set(e,t),t),Oe=(e,n,t)=>(me(e,n,"access private method"),t),Gn=(e,n,t)=>Un(Fn(e),t,n),be=class{constructor(e,n={}){ie(this,"patterns"),ie(this,"options"),ie(this,"regexps"),this.patterns=e,this.options=n;const{forgiving:t=!1,cache:r,regexConstructor:a}=n;if(!a)throw new Error("Option `regexConstructor` is not provided");this.regexps=e.map(o=>{if(typeof o!="string")return o;const s=r?.get(o);if(s){if(s instanceof RegExp)return s;if(t)return null;throw s}try{const i=a(o);return r?.set(o,i),i}catch(i){if(r?.set(o,i),t)return null;throw i}})}findNextMatchSync(e,n,t){const r=typeof e=="string"?e:e.content,a=[];function o(s,i,u=0){return{index:s,captureIndices:i.indices.map(c=>c==null?{start:4294967295,end:4294967295,length:0}:{start:c[0]+u,end:c[1]+u,length:c[1]-c[0]})}}for(let s=0;s<this.regexps.length;s++){const i=this.regexps[s];if(i)try{i.lastIndex=n;const u=i.exec(r);if(!u)continue;if(u.index===n)return o(s,u,0);a.push([s,u,0])}catch(u){if(this.options.forgiving)continue;throw u}}if(a.length){const s=Math.min(...a.map(i=>i[1].index));for(const[i,u,c]of a)if(u.index===s)return o(i,u,c)}return null}};function Z(e){if([...e].length!==1)throw new Error(`Expected "${e}" to be a single code point`);return e.codePointAt(0)}function Dn(e,n,t){return e.has(n)||e.set(n,t),e.get(n)}const Ce=new Set(["alnum","alpha","ascii","blank","cntrl","digit","graph","lower","print","punct","space","upper","word","xdigit"]),x=String.raw;function Q(e,n){if(e==null)throw new Error(n??"Value expected");return e}const Te=x`\[\^?`,We=`c.? | C(?:-.?)?|${x`[pP]\{(?:\^?[-\x20_]*[A-Za-z][-\x20\w]*\})?`}|${x`x[89A-Fa-f]\p{AHex}(?:\\x[89A-Fa-f]\p{AHex})*`}|${x`u(?:\p{AHex}{4})? | x\{[^\}]*\}? | x\p{AHex}{0,2}`}|${x`o\{[^\}]*\}?`}|${x`\d{1,3}`}`,xe=/[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/,ue=new RegExp(x`
90
2
  \\ (?:
91
- ${ur}
3
+ ${We}
92
4
  | [gk]<[^>]*>?
93
5
  | [gk]'[^']*'?
94
6
  | .
@@ -105,823 +17,20 @@ const ir = x`\[\^?`, ur = `c.? | C(?:-.?)?|${x`[pP]\{(?:\^?[-\x20_]*[A-Za-z][-\x
105
17
  )?
106
18
  | \*[^\)]*\)?
107
19
  )?
108
- | (?:${Ge.source})+
109
- | ${ir}
20
+ | (?:${xe.source})+
21
+ | ${Te}
110
22
  | .
111
- `.replace(/\s+/g, ""), "gsu"), be = new RegExp(x`
23
+ `.replace(/\s+/g,""),"gsu"),ke=new RegExp(x`
112
24
  \\ (?:
113
- ${ur}
25
+ ${We}
114
26
  | .
115
27
  )
116
28
  | \[:(?:\^?\p{Alpha}+|\^):\]
117
- | ${ir}
29
+ | ${Te}
118
30
  | &&
119
31
  | .
120
- `.replace(/\s+/g, ""), "gsu");
121
- function Or(e, r = {}) {
122
- const t = { flags: "", ...r, rules: { captureGroup: !1, singleline: !1, ...r.rules } };
123
- if (typeof e != "string") throw new Error("String expected as pattern");
124
- const n = nt(t.flags), s = [n.extended], o = { captureGroup: t.rules.captureGroup, getCurrentModX() {
125
- return s.at(-1);
126
- }, numOpenGroups: 0, popModX() {
127
- s.pop();
128
- }, pushModX(l) {
129
- s.push(l);
130
- }, replaceCurrentModX(l) {
131
- s[s.length - 1] = l;
132
- }, singleline: t.rules.singleline };
133
- let a = [], i;
134
- for (ce.lastIndex = 0; i = ce.exec(e); ) {
135
- const l = Dr(o, e, i[0], ce.lastIndex);
136
- l.tokens ? a.push(...l.tokens) : l.token && a.push(l.token), l.lastIndex !== void 0 && (ce.lastIndex = l.lastIndex);
137
- }
138
- const u = [];
139
- let c = 0;
140
- a.filter((l) => l.type === "GroupOpen").forEach((l) => {
141
- l.kind === "capturing" ? l.number = ++c : l.raw === "(" && u.push(l);
142
- }), c || u.forEach((l, f) => {
143
- l.kind = "capturing", l.number = f + 1;
144
- });
145
- const p = c || u.length;
146
- return { tokens: a.map((l) => l.type === "EscapedNumber" ? ot(l, p) : l).flat(), flags: n };
147
- }
148
- function Dr(e, r, t, n) {
149
- const [s, o] = t;
150
- if (t === "[" || t === "[^") {
151
- const a = Tr(r, t, n);
152
- return { tokens: a.tokens, lastIndex: a.lastIndex };
153
- }
154
- if (s === "\\") {
155
- if ("AbBGyYzZ".includes(o)) return { token: Be(t, t) };
156
- if (/^\\g[<']/.test(t)) {
157
- if (!/^\\g(?:<[^>]+>|'[^']+')$/.test(t)) throw new Error(`Invalid group name "${t}"`);
158
- return { token: qr(t) };
159
- }
160
- if (/^\\k[<']/.test(t)) {
161
- if (!/^\\k(?:<[^>]+>|'[^']+')$/.test(t)) throw new Error(`Invalid group name "${t}"`);
162
- return { token: lr(t) };
163
- }
164
- if (o === "K") return { token: pr("keep", t) };
165
- if (o === "N" || o === "R") return { token: j("newline", t, { negate: o === "N" }) };
166
- if (o === "O") return { token: j("any", t) };
167
- if (o === "X") return { token: j("text_segment", t) };
168
- const a = cr(t, { inCharClass: !1 });
169
- return Array.isArray(a) ? { tokens: a } : { token: a };
170
- }
171
- if (s === "(") {
172
- if (o === "*") return { token: et(t) };
173
- if (t === "(?{") throw new Error(`Unsupported callout "${t}"`);
174
- if (t.startsWith("(?#")) {
175
- if (r[n] !== ")") throw new Error('Unclosed comment group "(?#"');
176
- return { lastIndex: n + 1 };
177
- }
178
- if (/^\(\?[-imx]+[:)]$/.test(t)) return { token: Yr(t, e) };
179
- if (e.pushModX(e.getCurrentModX()), e.numOpenGroups++, t === "(" && !e.captureGroup || t === "(?:") return { token: Y("group", t) };
180
- if (t === "(?>") return { token: Y("atomic", t) };
181
- if (t === "(?=" || t === "(?!" || t === "(?<=" || t === "(?<!") return { token: Y(t[2] === "<" ? "lookbehind" : "lookahead", t, { negate: t.endsWith("!") }) };
182
- if (t === "(" && e.captureGroup || t.startsWith("(?<") && t.endsWith(">") || t.startsWith("(?'") && t.endsWith("'")) return { token: Y("capturing", t, { ...t !== "(" && { name: t.slice(3, -1) } }) };
183
- if (t.startsWith("(?~")) {
184
- if (t === "(?~|") throw new Error(`Unsupported absence function kind "${t}"`);
185
- return { token: Y("absence_repeater", t) };
186
- }
187
- throw t === "(?(" ? new Error(`Unsupported conditional "${t}"`) : new Error(`Invalid or unsupported group option "${t}"`);
188
- }
189
- if (t === ")") {
190
- if (e.popModX(), e.numOpenGroups--, e.numOpenGroups < 0) throw new Error('Unmatched ")"');
191
- return { token: Xr(t) };
192
- }
193
- if (e.getCurrentModX()) {
194
- if (t === "#") {
195
- const a = r.indexOf(`
196
- `, n);
197
- return { lastIndex: a === -1 ? r.length : a };
198
- }
199
- if (/^\s$/.test(t)) {
200
- const a = /\s+/y;
201
- return a.lastIndex = n, { lastIndex: a.exec(r) ? a.lastIndex : n };
202
- }
203
- }
204
- if (t === ".") return { token: j("dot", t) };
205
- if (t === "^" || t === "$") {
206
- const a = e.singleline ? { "^": x`\A`, $: x`\Z` }[t] : t;
207
- return { token: Be(a, t) };
208
- }
209
- return t === "|" ? { token: Vr(t) } : Ge.test(t) ? { tokens: at(t) } : { token: R(re(t), t) };
210
- }
211
- function Tr(e, r, t) {
212
- const n = [Ve(r[1] === "^", r)];
213
- let s = 1, o;
214
- for (be.lastIndex = t; o = be.exec(e); ) {
215
- const a = o[0];
216
- if (a[0] === "[" && a[1] !== ":") s++, n.push(Ve(a[1] === "^", a));
217
- else if (a === "]") {
218
- if (n.at(-1).type === "CharacterClassOpen") n.push(R(93, a));
219
- else if (s--, n.push(zr(a)), !s) break;
220
- } else {
221
- const i = Br(a);
222
- Array.isArray(i) ? n.push(...i) : n.push(i);
223
- }
224
- }
225
- return { tokens: n, lastIndex: be.lastIndex || e.length };
226
- }
227
- function Br(e) {
228
- if (e[0] === "\\") return cr(e, { inCharClass: !0 });
229
- if (e[0] === "[") {
230
- const r = /\[:(?<negate>\^?)(?<name>[a-z]+):\]/.exec(e);
231
- if (!r || !Fe.has(r.groups.name)) throw new Error(`Invalid POSIX class "${e}"`);
232
- return j("posix", e, { value: r.groups.name, negate: !!r.groups.negate });
233
- }
234
- return e === "-" ? Wr(e) : e === "&&" ? Hr(e) : R(re(e), e);
235
- }
236
- function cr(e, { inCharClass: r }) {
237
- const t = e[1];
238
- if (t === "c" || t === "C") return Kr(e);
239
- if ("dDhHsSwW".includes(t)) return rt(e);
240
- if (e.startsWith(x`\o{`)) throw new Error(`Incomplete, invalid, or unsupported octal code point "${e}"`);
241
- if (/^\\[pP]\{/.test(e)) {
242
- if (e.length === 3) throw new Error(`Incomplete or invalid Unicode property "${e}"`);
243
- return tt(e);
244
- }
245
- if (new RegExp("^\\\\x[89A-Fa-f]\\p{AHex}", "u").test(e)) try {
246
- const n = e.split(/\\x/).slice(1).map((a) => parseInt(a, 16)), s = new TextDecoder("utf-8", { ignoreBOM: !0, fatal: !0 }).decode(new Uint8Array(n)), o = new TextEncoder();
247
- return [...s].map((a) => {
248
- const i = [...o.encode(a)].map((u) => `\\x${u.toString(16)}`).join("");
249
- return R(re(a), i);
250
- });
251
- } catch {
252
- throw new Error(`Multibyte code "${e}" incomplete or invalid in Oniguruma`);
253
- }
254
- if (t === "u" || t === "x") return R(st(e), e);
255
- if (ze.has(t)) return R(ze.get(t), e);
256
- if (/\d/.test(t)) return jr(r, e);
257
- if (e === "\\") throw new Error(x`Incomplete escape "\"`);
258
- if (t === "M") throw new Error(`Unsupported meta "${e}"`);
259
- if ([...e].length === 2) return R(e.codePointAt(1), e);
260
- throw new Error(`Unexpected escape "${e}"`);
261
- }
262
- function Vr(e) {
263
- return { type: "Alternator", raw: e };
264
- }
265
- function Be(e, r) {
266
- return { type: "Assertion", kind: e, raw: r };
267
- }
268
- function lr(e) {
269
- return { type: "Backreference", raw: e };
270
- }
271
- function R(e, r) {
272
- return { type: "Character", value: e, raw: r };
273
- }
274
- function zr(e) {
275
- return { type: "CharacterClassClose", raw: e };
276
- }
277
- function Wr(e) {
278
- return { type: "CharacterClassHyphen", raw: e };
279
- }
280
- function Hr(e) {
281
- return { type: "CharacterClassIntersector", raw: e };
282
- }
283
- function Ve(e, r) {
284
- return { type: "CharacterClassOpen", negate: e, raw: r };
285
- }
286
- function j(e, r, t = {}) {
287
- return { type: "CharacterSet", kind: e, ...t, raw: r };
288
- }
289
- function pr(e, r, t = {}) {
290
- return e === "keep" ? { type: "Directive", kind: e, raw: r } : { type: "Directive", kind: e, flags: te(t.flags), raw: r };
291
- }
292
- function jr(e, r) {
293
- return { type: "EscapedNumber", inCharClass: e, raw: r };
294
- }
295
- function Xr(e) {
296
- return { type: "GroupClose", raw: e };
297
- }
298
- function Y(e, r, t = {}) {
299
- return { type: "GroupOpen", kind: e, ...t, raw: r };
300
- }
301
- function Zr(e, r, t, n) {
302
- return { type: "NamedCallout", kind: e, tag: r, arguments: t, raw: n };
303
- }
304
- function Qr(e, r, t, n) {
305
- return { type: "Quantifier", kind: e, min: r, max: t, raw: n };
306
- }
307
- function qr(e) {
308
- return { type: "Subroutine", raw: e };
309
- }
310
- const Jr = /* @__PURE__ */ new Set(["COUNT", "CMP", "ERROR", "FAIL", "MAX", "MISMATCH", "SKIP", "TOTAL_COUNT"]), ze = /* @__PURE__ */ new Map([["a", 7], ["b", 8], ["e", 27], ["f", 12], ["n", 10], ["r", 13], ["t", 9], ["v", 11]]);
311
- function Kr(e) {
312
- const r = e[1] === "c" ? e[2] : e[3];
313
- if (!r || !/[A-Za-z]/.test(r)) throw new Error(`Unsupported control character "${e}"`);
314
- return R(re(r.toUpperCase()) - 64, e);
315
- }
316
- function Yr(e, r) {
317
- let { on: t, off: n } = /^\(\?(?<on>[imx]*)(?:-(?<off>[-imx]*))?/.exec(e).groups;
318
- n ?? (n = "");
319
- const s = (r.getCurrentModX() || t.includes("x")) && !n.includes("x"), o = He(t), a = He(n), i = {};
320
- if (o && (i.enable = o), a && (i.disable = a), e.endsWith(")")) return r.replaceCurrentModX(s), pr("flags", e, { flags: i });
321
- if (e.endsWith(":")) return r.pushModX(s), r.numOpenGroups++, Y("group", e, { ...(o || a) && { flags: i } });
322
- throw new Error(`Unexpected flag modifier "${e}"`);
323
- }
324
- function et(e) {
325
- const r = /\(\*(?<name>[A-Za-z_]\w*)?(?:\[(?<tag>(?:[A-Za-z_]\w*)?)\])?(?:\{(?<args>[^}]*)\})?\)/.exec(e);
326
- if (!r) throw new Error(`Incomplete or invalid named callout "${e}"`);
327
- const { name: t, tag: n, args: s } = r.groups;
328
- if (!t) throw new Error(`Invalid named callout "${e}"`);
329
- if (n === "") throw new Error(`Named callout tag with empty value not allowed "${e}"`);
330
- const o = s ? s.split(",").filter((p) => p !== "").map((p) => /^[+-]?\d+$/.test(p) ? +p : p) : [], [a, i, u] = o, c = Jr.has(t) ? t.toLowerCase() : "custom";
331
- switch (c) {
332
- case "fail":
333
- case "mismatch":
334
- case "skip":
335
- if (o.length > 0) throw new Error(`Named callout arguments not allowed "${o}"`);
336
- break;
337
- case "error":
338
- if (o.length > 1) throw new Error(`Named callout allows only one argument "${o}"`);
339
- if (typeof a == "string") throw new Error(`Named callout argument must be a number "${a}"`);
340
- break;
341
- case "max":
342
- if (!o.length || o.length > 2) throw new Error(`Named callout must have one or two arguments "${o}"`);
343
- if (typeof a == "string" && !/^[A-Za-z_]\w*$/.test(a)) throw new Error(`Named callout argument one must be a tag or number "${a}"`);
344
- if (o.length === 2 && (typeof i == "number" || !/^[<>X]$/.test(i))) throw new Error(`Named callout optional argument two must be '<', '>', or 'X' "${i}"`);
345
- break;
346
- case "count":
347
- case "total_count":
348
- if (o.length > 1) throw new Error(`Named callout allows only one argument "${o}"`);
349
- if (o.length === 1 && (typeof a == "number" || !/^[<>X]$/.test(a))) throw new Error(`Named callout optional argument must be '<', '>', or 'X' "${a}"`);
350
- break;
351
- case "cmp":
352
- if (o.length !== 3) throw new Error(`Named callout must have three arguments "${o}"`);
353
- if (typeof a == "string" && !/^[A-Za-z_]\w*$/.test(a)) throw new Error(`Named callout argument one must be a tag or number "${a}"`);
354
- if (typeof i == "number" || !/^(?:[<>!=]=|[<>])$/.test(i)) throw new Error(`Named callout argument two must be '==', '!=', '>', '<', '>=', or '<=' "${i}"`);
355
- if (typeof u == "string" && !/^[A-Za-z_]\w*$/.test(u)) throw new Error(`Named callout argument three must be a tag or number "${u}"`);
356
- break;
357
- case "custom":
358
- throw new Error(`Undefined callout name "${t}"`);
359
- default:
360
- throw new Error(`Unexpected named callout kind "${c}"`);
361
- }
362
- return Zr(c, n ?? null, (s == null ? void 0 : s.split(",")) ?? null, e);
363
- }
364
- function We(e) {
365
- let r = null, t, n;
366
- if (e[0] === "{") {
367
- const { minStr: s, maxStr: o } = /^\{(?<minStr>\d*)(?:,(?<maxStr>\d*))?/.exec(e).groups, a = 1e5;
368
- if (+s > a || o && +o > a) throw new Error("Quantifier value unsupported in Oniguruma");
369
- if (t = +s, n = o === void 0 ? +s : o === "" ? 1 / 0 : +o, t > n && (r = "possessive", [t, n] = [n, t]), e.endsWith("?")) {
370
- if (r === "possessive") throw new Error('Unsupported possessive interval quantifier chain with "?"');
371
- r = "lazy";
372
- } else r || (r = "greedy");
373
- } else t = e[0] === "+" ? 1 : 0, n = e[0] === "?" ? 1 : 1 / 0, r = e[1] === "+" ? "possessive" : e[1] === "?" ? "lazy" : "greedy";
374
- return Qr(r, t, n, e);
375
- }
376
- function rt(e) {
377
- const r = e[1].toLowerCase();
378
- return j({ d: "digit", h: "hex", s: "space", w: "word" }[r], e, { negate: e[1] !== r });
379
- }
380
- function tt(e) {
381
- const { p: r, neg: t, value: n } = /^\\(?<p>[pP])\{(?<neg>\^?)(?<value>[^}]+)/.exec(e).groups;
382
- return j("property", e, { value: n, negate: r === "P" && !t || r === "p" && !!t });
383
- }
384
- function He(e) {
385
- const r = {};
386
- return e.includes("i") && (r.ignoreCase = !0), e.includes("m") && (r.dotAll = !0), e.includes("x") && (r.extended = !0), Object.keys(r).length ? r : null;
387
- }
388
- function nt(e) {
389
- const r = { ignoreCase: !1, dotAll: !1, extended: !1, digitIsAscii: !1, posixIsAscii: !1, spaceIsAscii: !1, wordIsAscii: !1, textSegmentMode: null };
390
- for (let t = 0; t < e.length; t++) {
391
- const n = e[t];
392
- if (!"imxDPSWy".includes(n)) throw new Error(`Invalid flag "${n}"`);
393
- if (n === "y") {
394
- if (!/^y{[gw]}/.test(e.slice(t))) throw new Error('Invalid or unspecified flag "y" mode');
395
- r.textSegmentMode = e[t + 2] === "g" ? "grapheme" : "word", t += 3;
396
- continue;
397
- }
398
- r[{ i: "ignoreCase", m: "dotAll", x: "extended", D: "digitIsAscii", P: "posixIsAscii", S: "spaceIsAscii", W: "wordIsAscii" }[n]] = !0;
399
- }
400
- return r;
401
- }
402
- function st(e) {
403
- if (new RegExp("^(?:\\\\u(?!\\p{AHex}{4})|\\\\x(?!\\p{AHex}{1,2}|\\{\\p{AHex}{1,8}\\}))", "u").test(e)) throw new Error(`Incomplete or invalid escape "${e}"`);
404
- const r = e[2] === "{" ? new RegExp("^\\\\x\\{\\s*(?<hex>\\p{AHex}+)", "u").exec(e).groups.hex : e.slice(2);
405
- return parseInt(r, 16);
406
- }
407
- function ot(e, r) {
408
- const { raw: t, inCharClass: n } = e, s = t.slice(1);
409
- if (!n && (s !== "0" && s.length === 1 || s[0] !== "0" && +s <= r)) return [lr(t)];
410
- const o = [], a = s.match(/^[0-7]+|\d/g);
411
- for (let i = 0; i < a.length; i++) {
412
- const u = a[i];
413
- let c;
414
- if (i === 0 && u !== "8" && u !== "9") {
415
- if (c = parseInt(u, 8), c > 127) throw new Error(x`Octal encoded byte above 177 unsupported "${t}"`);
416
- } else c = re(u);
417
- o.push(R(c, (i === 0 ? "\\" : "") + u));
418
- }
419
- return o;
420
- }
421
- function at(e) {
422
- const r = [], t = new RegExp(Ge, "gy");
423
- let n;
424
- for (; n = t.exec(e); ) {
425
- const s = n[0];
426
- if (s[0] === "{") {
427
- const o = /^\{(?<min>\d+),(?<max>\d+)\}\??$/.exec(s);
428
- if (o) {
429
- const { min: a, max: i } = o.groups;
430
- if (+a > +i && s.endsWith("?")) {
431
- t.lastIndex--, r.push(We(s.slice(0, -1)));
432
- continue;
433
- }
434
- }
435
- }
436
- r.push(We(s));
437
- }
438
- return r;
439
- }
440
- function fr(e, r) {
441
- if (!Array.isArray(e.body)) throw new Error("Expected node with body array");
442
- if (e.body.length !== 1) return !1;
443
- const t = e.body[0];
444
- return !r || Object.keys(r).every((n) => r[n] === t[n]);
445
- }
446
- function it(e) {
447
- return ut.has(e.type);
448
- }
449
- const ut = /* @__PURE__ */ new Set(["AbsenceFunction", "Backreference", "CapturingGroup", "Character", "CharacterClass", "CharacterSet", "Group", "Quantifier", "Subroutine"]);
450
- function dr(e, r = {}) {
451
- const t = { flags: "", normalizeUnknownPropertyNames: !1, skipBackrefValidation: !1, skipLookbehindValidation: !1, skipPropertyNameValidation: !1, unicodePropertyMap: null, ...r, rules: { captureGroup: !1, singleline: !1, ...r.rules } }, n = Or(e, { flags: t.flags, rules: { captureGroup: t.rules.captureGroup, singleline: t.rules.singleline } }), s = (f, g) => {
452
- const d = n.tokens[o.nextIndex];
453
- switch (o.parent = f, o.nextIndex++, d.type) {
454
- case "Alternator":
455
- return Q();
456
- case "Assertion":
457
- return ct(d);
458
- case "Backreference":
459
- return lt(d, o);
460
- case "Character":
461
- return ge(d.value, { useLastValid: !!g.isCheckingRangeEnd });
462
- case "CharacterClassHyphen":
463
- return pt(d, o, g);
464
- case "CharacterClassOpen":
465
- return ft(d, o, g);
466
- case "CharacterSet":
467
- return dt(d, o);
468
- case "Directive":
469
- return Ct(d.kind, { flags: d.flags });
470
- case "GroupOpen":
471
- return gt(d, o, g);
472
- case "NamedCallout":
473
- return xt(d.kind, d.tag, d.arguments);
474
- case "Quantifier":
475
- return ht(d, o);
476
- case "Subroutine":
477
- return wt(d, o);
478
- default:
479
- throw new Error(`Unexpected token type "${d.type}"`);
480
- }
481
- }, o = { capturingGroups: [], hasNumberedRef: !1, namedGroupsByName: /* @__PURE__ */ new Map(), nextIndex: 0, normalizeUnknownPropertyNames: t.normalizeUnknownPropertyNames, parent: null, skipBackrefValidation: t.skipBackrefValidation, skipLookbehindValidation: t.skipLookbehindValidation, skipPropertyNameValidation: t.skipPropertyNameValidation, subroutines: [], tokens: n.tokens, unicodePropertyMap: t.unicodePropertyMap, walk: s }, a = Et(bt(n.flags));
482
- let i = a.body[0];
483
- for (; o.nextIndex < n.tokens.length; ) {
484
- const f = s(i, {});
485
- f.type === "Alternative" ? (a.body.push(f), i = f) : i.body.push(f);
486
- }
487
- const { capturingGroups: u, hasNumberedRef: c, namedGroupsByName: p, subroutines: l } = o;
488
- if (c && p.size && !t.rules.captureGroup) throw new Error("Numbered backref/subroutine not allowed when using named capture");
489
- for (const { ref: f } of l) if (typeof f == "number") {
490
- if (f > u.length) throw new Error("Subroutine uses a group number that's not defined");
491
- f && (u[f - 1].isSubroutined = !0);
492
- } else if (p.has(f)) {
493
- if (p.get(f).length > 1) throw new Error(x`Subroutine uses a duplicate group name "\g<${f}>"`);
494
- p.get(f)[0].isSubroutined = !0;
495
- } else throw new Error(x`Subroutine uses a group name that's not defined "\g<${f}>"`);
496
- return a;
497
- }
498
- function ct({ kind: e }) {
499
- return Se(te({ "^": "line_start", $: "line_end", "\\A": "string_start", "\\b": "word_boundary", "\\B": "word_boundary", "\\G": "search_start", "\\y": "text_segment_boundary", "\\Y": "text_segment_boundary", "\\z": "string_end", "\\Z": "string_end_newline" }[e], `Unexpected assertion kind "${e}"`), { negate: e === x`\B` || e === x`\Y` });
500
- }
501
- function lt({ raw: e }, r) {
502
- const t = /^\\k[<']/.test(e), n = t ? e.slice(3, -1) : e.slice(1), s = (o, a = !1) => {
503
- const i = r.capturingGroups.length;
504
- let u = !1;
505
- if (o > i) if (r.skipBackrefValidation) u = !0;
506
- else throw new Error(`Not enough capturing groups defined to the left "${e}"`);
507
- return r.hasNumberedRef = !0, ve(a ? i + 1 - o : o, { orphan: u });
508
- };
509
- if (t) {
510
- const o = /^(?<sign>-?)0*(?<num>[1-9]\d*)$/.exec(n);
511
- if (o) return s(+o.groups.num, !!o.groups.sign);
512
- if (/[-+]/.test(n)) throw new Error(`Invalid backref name "${e}"`);
513
- if (!r.namedGroupsByName.has(n)) throw new Error(`Group name not defined to the left "${e}"`);
514
- return ve(n);
515
- }
516
- return s(+n);
517
- }
518
- function pt(e, r, t) {
519
- const { tokens: n, walk: s } = r, o = r.parent, a = o.body.at(-1), i = n[r.nextIndex];
520
- if (!t.isCheckingRangeEnd && a && a.type !== "CharacterClass" && a.type !== "CharacterClassRange" && i && i.type !== "CharacterClassOpen" && i.type !== "CharacterClassClose" && i.type !== "CharacterClassIntersector") {
521
- const u = s(o, { ...t, isCheckingRangeEnd: !0 });
522
- if (a.type === "Character" && u.type === "Character") return o.body.pop(), yt(a, u);
523
- throw new Error("Invalid character class range");
524
- }
525
- return ge(re("-"));
526
- }
527
- function ft({ negate: e }, r, t) {
528
- const { tokens: n, walk: s } = r, o = [fe()], a = n[r.nextIndex];
529
- let i = Ze(a);
530
- for (; i.type !== "CharacterClassClose"; ) {
531
- if (i.type === "CharacterClassIntersector") o.push(fe()), r.nextIndex++;
532
- else {
533
- const c = o.at(-1);
534
- c.body.push(s(c, t));
535
- }
536
- i = Ze(n[r.nextIndex], a);
537
- }
538
- const u = fe({ negate: e });
539
- return o.length === 1 ? u.body = o[0].body : (u.kind = "intersection", u.body = o.map((c) => c.body.length === 1 ? c.body[0] : c)), r.nextIndex++, u;
540
- }
541
- function dt({ kind: e, negate: r, value: t }, n) {
542
- const { normalizeUnknownPropertyNames: s, skipPropertyNameValidation: o, unicodePropertyMap: a } = n;
543
- if (e === "property") {
544
- const i = he(t);
545
- if (Fe.has(i) && !(a != null && a.has(i))) e = "posix", t = i;
546
- else return ee(t, { negate: r, normalizeUnknownPropertyNames: s, skipPropertyNameValidation: o, unicodePropertyMap: a });
547
- }
548
- return e === "posix" ? kt(t, { negate: r }) : _e(e, { negate: r });
549
- }
550
- function gt(e, r, t) {
551
- const { tokens: n, capturingGroups: s, namedGroupsByName: o, skipLookbehindValidation: a, walk: i } = r, u = $t(e), c = u.type === "AbsenceFunction", p = Xe(u), l = p && u.negate;
552
- if (u.type === "CapturingGroup" && (s.push(u), u.name && Ur(o, u.name, []).push(u)), c && t.isInAbsenceFunction) throw new Error("Nested absence function not supported by Oniguruma");
553
- let f = Qe(n[r.nextIndex]);
554
- for (; f.type !== "GroupClose"; ) {
555
- if (f.type === "Alternator") u.body.push(Q()), r.nextIndex++;
556
- else {
557
- const g = u.body.at(-1), d = i(g, { ...t, isInAbsenceFunction: t.isInAbsenceFunction || c, isInLookbehind: t.isInLookbehind || p, isInNegLookbehind: t.isInNegLookbehind || l });
558
- if (g.body.push(d), (p || t.isInLookbehind) && !a) {
559
- const w = "Lookbehind includes a pattern not allowed by Oniguruma";
560
- if (l || t.isInNegLookbehind) {
561
- if (je(d) || d.type === "CapturingGroup") throw new Error(w);
562
- } else if (je(d) || Xe(d) && d.negate) throw new Error(w);
563
- }
564
- }
565
- f = Qe(n[r.nextIndex]);
566
- }
567
- return r.nextIndex++, u;
568
- }
569
- function ht({ kind: e, min: r, max: t }, n) {
570
- const s = n.parent, o = s.body.at(-1);
571
- if (!o || !it(o)) throw new Error("Quantifier requires a repeatable token");
572
- const a = hr(e, r, t, o);
573
- return s.body.pop(), a;
574
- }
575
- function wt({ raw: e }, r) {
576
- const { capturingGroups: t, subroutines: n } = r;
577
- let s = e.slice(3, -1);
578
- const o = /^(?<sign>[-+]?)0*(?<num>[1-9]\d*)$/.exec(s);
579
- if (o) {
580
- const i = +o.groups.num, u = t.length;
581
- if (r.hasNumberedRef = !0, s = { "": i, "+": u + i, "-": u + 1 - i }[o.groups.sign], s < 1) throw new Error("Invalid subroutine number");
582
- } else s === "0" && (s = 0);
583
- const a = wr(s);
584
- return n.push(a), a;
585
- }
586
- function mt(e, r) {
587
- return { type: "AbsenceFunction", kind: e, body: ue(r == null ? void 0 : r.body) };
588
- }
589
- function Q(e) {
590
- return { type: "Alternative", body: mr(e == null ? void 0 : e.body) };
591
- }
592
- function Se(e, r) {
593
- const t = { type: "Assertion", kind: e };
594
- return (e === "word_boundary" || e === "text_segment_boundary") && (t.negate = !!(r != null && r.negate)), t;
595
- }
596
- function ve(e, r) {
597
- const t = !!(r != null && r.orphan);
598
- return { type: "Backreference", ref: e, ...t && { orphan: t } };
599
- }
600
- function gr(e, r) {
601
- const t = { name: void 0, isSubroutined: !1, ...r };
602
- if (t.name !== void 0 && !At(t.name)) throw new Error(`Group name "${t.name}" invalid in Oniguruma`);
603
- return { type: "CapturingGroup", number: e, ...t.name && { name: t.name }, ...t.isSubroutined && { isSubroutined: t.isSubroutined }, body: ue(r == null ? void 0 : r.body) };
604
- }
605
- function ge(e, r) {
606
- const t = { useLastValid: !1, ...r };
607
- if (e > 1114111) {
608
- const n = e.toString(16);
609
- if (t.useLastValid) e = 1114111;
610
- else throw e > 1310719 ? new Error(`Invalid code point out of range "\\x{${n}}"`) : new Error(`Invalid code point out of range in JS "\\x{${n}}"`);
611
- }
612
- return { type: "Character", value: e };
613
- }
614
- function fe(e) {
615
- const r = { kind: "union", negate: !1, ...e };
616
- return { type: "CharacterClass", kind: r.kind, negate: r.negate, body: mr(e == null ? void 0 : e.body) };
617
- }
618
- function yt(e, r) {
619
- if (r.value < e.value) throw new Error("Character class range out of order");
620
- return { type: "CharacterClassRange", min: e, max: r };
621
- }
622
- function _e(e, r) {
623
- const t = !!(r != null && r.negate), n = { type: "CharacterSet", kind: e };
624
- return (e === "digit" || e === "hex" || e === "newline" || e === "space" || e === "word") && (n.negate = t), (e === "text_segment" || e === "newline" && !t) && (n.variableLength = !0), n;
625
- }
626
- function Ct(e, r = {}) {
627
- if (e === "keep") return { type: "Directive", kind: e };
628
- if (e === "flags") return { type: "Directive", kind: e, flags: te(r.flags) };
629
- throw new Error(`Unexpected directive kind "${e}"`);
630
- }
631
- function bt(e) {
632
- return { type: "Flags", ...e };
633
- }
634
- function N(e) {
635
- const r = e == null ? void 0 : e.atomic, t = e == null ? void 0 : e.flags;
636
- if (r && t) throw new Error("Atomic group cannot have flags");
637
- return { type: "Group", ...r && { atomic: r }, ...t && { flags: t }, body: ue(e == null ? void 0 : e.body) };
638
- }
639
- function H(e) {
640
- const r = { behind: !1, negate: !1, ...e };
641
- return { type: "LookaroundAssertion", kind: r.behind ? "lookbehind" : "lookahead", negate: r.negate, body: ue(e == null ? void 0 : e.body) };
642
- }
643
- function xt(e, r, t) {
644
- return { type: "NamedCallout", kind: e, tag: r, arguments: t };
645
- }
646
- function kt(e, r) {
647
- const t = !!(r != null && r.negate);
648
- if (!Fe.has(e)) throw new Error(`Invalid POSIX class "${e}"`);
649
- return { type: "CharacterSet", kind: "posix", value: e, negate: t };
650
- }
651
- function hr(e, r, t, n) {
652
- if (r > t) throw new Error("Invalid reversed quantifier range");
653
- return { type: "Quantifier", kind: e, min: r, max: t, body: n };
654
- }
655
- function Et(e, r) {
656
- return { type: "Regex", body: ue(r == null ? void 0 : r.body), flags: e };
657
- }
658
- function wr(e) {
659
- return { type: "Subroutine", ref: e };
660
- }
661
- function ee(e, r) {
662
- var s;
663
- const t = { negate: !1, normalizeUnknownPropertyNames: !1, skipPropertyNameValidation: !1, unicodePropertyMap: null, ...r };
664
- let n = (s = t.unicodePropertyMap) == null ? void 0 : s.get(he(e));
665
- if (!n) {
666
- if (t.normalizeUnknownPropertyNames) n = It(e);
667
- else if (t.unicodePropertyMap && !t.skipPropertyNameValidation) throw new Error(x`Invalid Unicode property "\p{${e}}"`);
668
- }
669
- return { type: "CharacterSet", kind: "property", value: n ?? e, negate: t.negate };
670
- }
671
- function $t({ flags: e, kind: r, name: t, negate: n, number: s }) {
672
- switch (r) {
673
- case "absence_repeater":
674
- return mt("repeater");
675
- case "atomic":
676
- return N({ atomic: !0 });
677
- case "capturing":
678
- return gr(s, { name: t });
679
- case "group":
680
- return N({ flags: e });
681
- case "lookahead":
682
- case "lookbehind":
683
- return H({ behind: r === "lookbehind", negate: n });
684
- default:
685
- throw new Error(`Unexpected group kind "${r}"`);
686
- }
687
- }
688
- function ue(e) {
689
- if (e === void 0) e = [Q()];
690
- 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");
691
- return e;
692
- }
693
- function mr(e) {
694
- if (e === void 0) e = [];
695
- else if (!Array.isArray(e) || !e.every((r) => !!r.type)) throw new Error("Invalid body; expected array of nodes");
696
- return e;
697
- }
698
- function je(e) {
699
- return e.type === "LookaroundAssertion" && e.kind === "lookahead";
700
- }
701
- function Xe(e) {
702
- return e.type === "LookaroundAssertion" && e.kind === "lookbehind";
703
- }
704
- function At(e) {
705
- return /^[\p{Alpha}\p{Pc}][^)]*$/u.test(e);
706
- }
707
- function It(e) {
708
- 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());
709
- }
710
- function he(e) {
711
- return e.replace(/[- _]+/g, "").toLowerCase();
712
- }
713
- function Ze(e, r) {
714
- const t = r;
715
- return te(e, `Unclosed character class${(t == null ? void 0 : t.type) === "Character" && t.value === 93 && t.raw === "]" ? ' (started with "]")' : ""}`);
716
- }
717
- function Qe(e) {
718
- return te(e, "Unclosed group");
719
- }
720
- function oe(e, r, t = null) {
721
- function n(o, a) {
722
- for (let i = 0; i < o.length; i++) {
723
- const u = s(o[i], a, i, o);
724
- i = Math.max(-1, i + u);
725
- }
726
- }
727
- function s(o, a = null, i = null, u = null) {
728
- var $, A;
729
- let c = 0, p = !1;
730
- const l = { node: o, parent: a, key: i, container: u, root: e, remove() {
731
- le(u).splice(Math.max(0, J(i) + c), 1), c--, p = !0;
732
- }, removeAllNextSiblings() {
733
- return le(u).splice(J(i) + 1);
734
- }, removeAllPrevSiblings() {
735
- const y = J(i) + c;
736
- return c -= y, le(u).splice(0, Math.max(0, y));
737
- }, replaceWith(y, k = {}) {
738
- const v = !!k.traverse;
739
- u ? u[Math.max(0, J(i) + c)] = y : te(a, "Can't replace root node")[i] = y, v && s(y, a, i, u), p = !0;
740
- }, replaceWithMultiple(y, k = {}) {
741
- const v = !!k.traverse;
742
- if (le(u).splice(Math.max(0, J(i) + c), 1, ...y), c += y.length - 1, v) {
743
- let V = 0;
744
- for (let _ = 0; _ < y.length; _++) V += s(y[_], a, J(i) + _ + V, u);
745
- }
746
- p = !0;
747
- }, skip() {
748
- p = !0;
749
- } }, { type: f } = o, g = r["*"], d = r[f], w = typeof g == "function" ? g : g == null ? void 0 : g.enter, m = typeof d == "function" ? d : d == null ? void 0 : d.enter;
750
- if (w == null || w(l, t), m == null || m(l, t), !p) switch (f) {
751
- case "AbsenceFunction":
752
- case "Alternative":
753
- case "CapturingGroup":
754
- case "CharacterClass":
755
- case "Group":
756
- case "LookaroundAssertion":
757
- n(o.body, o);
758
- break;
759
- case "Assertion":
760
- case "Backreference":
761
- case "Character":
762
- case "CharacterSet":
763
- case "Directive":
764
- case "Flags":
765
- case "NamedCallout":
766
- case "Subroutine":
767
- break;
768
- case "CharacterClassRange":
769
- s(o.min, o, "min"), s(o.max, o, "max");
770
- break;
771
- case "Quantifier":
772
- s(o.body, o, "body");
773
- break;
774
- case "Regex":
775
- n(o.body, o), s(o.flags, o, "flags");
776
- break;
777
- default:
778
- throw new Error(`Unexpected node type "${f}"`);
779
- }
780
- return ($ = d == null ? void 0 : d.exit) == null || $.call(d, l, t), (A = g == null ? void 0 : g.exit) == null || A.call(g, l, t), c;
781
- }
782
- return s(e), e;
783
- }
784
- function le(e) {
785
- if (!Array.isArray(e)) throw new Error("Container expected");
786
- return e;
787
- }
788
- function J(e) {
789
- if (typeof e != "number") throw new Error("Numeric key expected");
790
- return e;
791
- }
792
- const St = String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;
793
- function vt(e, r) {
794
- for (let t = 0; t < e.length; t++)
795
- e[t] >= r && e[t]++;
796
- }
797
- function _t(e, r, t, n) {
798
- return e.slice(0, r) + n + e.slice(r + t.length);
799
- }
800
- const S = Object.freeze({
801
- DEFAULT: "DEFAULT",
802
- CHAR_CLASS: "CHAR_CLASS"
803
- });
804
- function Pe(e, r, t, n) {
805
- const s = new RegExp(String.raw`${r}|(?<$skip>\[\^?|\\?.)`, "gsu"), o = [!1];
806
- let a = 0, i = "";
807
- for (const u of e.matchAll(s)) {
808
- const { 0: c, groups: { $skip: p } } = u;
809
- if (!p && (!n || n === S.DEFAULT == !a)) {
810
- t instanceof Function ? i += t(u, {
811
- context: a ? S.CHAR_CLASS : S.DEFAULT,
812
- negated: o[o.length - 1]
813
- }) : i += t;
814
- continue;
815
- }
816
- c[0] === "[" ? (a++, o.push(c[1] === "^")) : c === "]" && a && (a--, o.pop()), i += c;
817
- }
818
- return i;
819
- }
820
- function yr(e, r, t, n) {
821
- Pe(e, r, t, n);
822
- }
823
- function Mt(e, r, t = 0, n) {
824
- if (!new RegExp(r, "su").test(e))
825
- return null;
826
- const s = new RegExp(`${r}|(?<$skip>\\\\?.)`, "gsu");
827
- s.lastIndex = t;
828
- let o = 0, a;
829
- for (; a = s.exec(e); ) {
830
- const { 0: i, groups: { $skip: u } } = a;
831
- if (!u && (!n || n === S.DEFAULT == !o))
832
- return a;
833
- i === "[" ? o++ : i === "]" && o && o--, s.lastIndex == a.index && s.lastIndex++;
834
- }
835
- return null;
836
- }
837
- function pe(e, r, t) {
838
- return !!Mt(e, r, 0, t);
839
- }
840
- function Nt(e, r) {
841
- const t = /\\?./gsu;
842
- t.lastIndex = r;
843
- let n = e.length, s = 0, o = 1, a;
844
- for (; a = t.exec(e); ) {
845
- const [i] = a;
846
- if (i === "[")
847
- s++;
848
- else if (s)
849
- i === "]" && s--;
850
- else if (i === "(")
851
- o++;
852
- else if (i === ")" && (o--, !o)) {
853
- n = a.index;
854
- break;
855
- }
856
- }
857
- return e.slice(r, n);
858
- }
859
- const qe = new RegExp(String.raw`(?<noncapturingStart>${St})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`, "gsu");
860
- function Lt(e, r) {
861
- const t = (r == null ? void 0 : r.hiddenCaptures) ?? [];
862
- let n = (r == null ? void 0 : r.captureTransfers) ?? /* @__PURE__ */ new Map();
863
- if (!/\(\?>/.test(e))
864
- return {
865
- pattern: e,
866
- captureTransfers: n,
867
- hiddenCaptures: t
868
- };
869
- const s = "(?>", o = "(?:(?=(", a = [0], i = [];
870
- let u = 0, c = 0, p = NaN, l;
871
- do {
872
- l = !1;
873
- let f = 0, g = 0, d = !1, w;
874
- for (qe.lastIndex = Number.isNaN(p) ? 0 : p + o.length; w = qe.exec(e); ) {
875
- const { 0: m, index: $, groups: { capturingStart: A, noncapturingStart: y } } = w;
876
- if (m === "[")
877
- f++;
878
- else if (f)
879
- m === "]" && f--;
880
- else if (m === s && !d)
881
- p = $, d = !0;
882
- else if (d && y)
883
- g++;
884
- else if (A)
885
- d ? g++ : (u++, a.push(u + c));
886
- else if (m === ")" && d) {
887
- if (!g) {
888
- c++;
889
- const k = u + c;
890
- if (e = `${e.slice(0, p)}${o}${e.slice(p + s.length, $)}))<$$${k}>)${e.slice($ + 1)}`, l = !0, i.push(k), vt(t, k), n.size) {
891
- const v = /* @__PURE__ */ new Map();
892
- n.forEach((V, _) => {
893
- v.set(
894
- _ >= k ? _ + 1 : _,
895
- V.map((q) => q >= k ? q + 1 : q)
896
- );
897
- }), n = v;
898
- }
899
- break;
900
- }
901
- g--;
902
- }
903
- }
904
- } while (l);
905
- return t.push(...i), e = Pe(
906
- e,
907
- String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,
908
- ({ 0: f, groups: { backrefNum: g, wrappedBackrefNum: d } }) => {
909
- if (g) {
910
- const w = +g;
911
- if (w > a.length - 1)
912
- throw new Error(`Backref "${f}" greater than number of captures`);
913
- return `\\${a[w]}`;
914
- }
915
- return `\\${d}`;
916
- },
917
- S.DEFAULT
918
- ), {
919
- pattern: e,
920
- captureTransfers: n,
921
- hiddenCaptures: t
922
- };
923
- }
924
- const Cr = String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`, xe = new RegExp(String.raw`
32
+ `.replace(/\s+/g,""),"gsu");function On(e,n={}){const t={flags:"",...n,rules:{captureGroup:!1,singleline:!1,...n.rules}};if(typeof e!="string")throw new Error("String expected as pattern");const r=at(t.flags),a=[r.extended],o={captureGroup:t.rules.captureGroup,getCurrentModX(){return a.at(-1)},numOpenGroups:0,popModX(){a.pop()},pushModX(l){a.push(l)},replaceCurrentModX(l){a[a.length-1]=l},singleline:t.rules.singleline};let s=[],i;for(ue.lastIndex=0;i=ue.exec(e);){const l=Tn(o,e,i[0],ue.lastIndex);l.tokens?s.push(...l.tokens):l.token&&s.push(l.token),l.lastIndex!==void 0&&(ue.lastIndex=l.lastIndex)}const u=[];let c=0;s.filter(l=>l.type==="GroupOpen").forEach(l=>{l.kind==="capturing"?l.number=++c:l.raw==="("&&u.push(l)}),c||u.forEach((l,d)=>{l.kind="capturing",l.number=d+1});const p=c||u.length;return{tokens:s.map(l=>l.type==="EscapedNumber"?it(l,p):l).flat(),flags:r}}function Tn(e,n,t,r){const[a,o]=t;if(t==="["||t==="[^"){const s=Wn(n,t,r);return{tokens:s.tokens,lastIndex:s.lastIndex}}if(a==="\\"){if("AbBGyYzZ".includes(o))return{token:Ve(t,t)};if(/^\\g[<']/.test(t)){if(!/^\\g(?:<[^>]+>|'[^']+')$/.test(t))throw new Error(`Invalid group name "${t}"`);return{token:Kn(t)}}if(/^\\k[<']/.test(t)){if(!/^\\k(?:<[^>]+>|'[^']+')$/.test(t))throw new Error(`Invalid group name "${t}"`);return{token:je(t)}}if(o==="K")return{token:Xe("keep",t)};if(o==="N"||o==="R")return{token:O("newline",t,{negate:o==="N"})};if(o==="O")return{token:O("any",t)};if(o==="X")return{token:O("text_segment",t)};const s=ze(t,{inCharClass:!1});return Array.isArray(s)?{tokens:s}:{token:s}}if(a==="("){if(o==="*")return{token:tt(t)};if(t==="(?{")throw new Error(`Unsupported callout "${t}"`);if(t.startsWith("(?#")){if(n[r]!==")")throw new Error('Unclosed comment group "(?#"');return{lastIndex:r+1}}if(/^\(\?[-imx]+[:)]$/.test(t))return{token:nt(t,e)};if(e.pushModX(e.getCurrentModX()),e.numOpenGroups++,t==="("&&!e.captureGroup||t==="(?:")return{token:q("group",t)};if(t==="(?>")return{token:q("atomic",t)};if(t==="(?="||t==="(?!"||t==="(?<="||t==="(?<!")return{token:q(t[2]==="<"?"lookbehind":"lookahead",t,{negate:t.endsWith("!")})};if(t==="("&&e.captureGroup||t.startsWith("(?<")&&t.endsWith(">")||t.startsWith("(?'")&&t.endsWith("'"))return{token:q("capturing",t,{...t!=="("&&{name:t.slice(3,-1)}})};if(t.startsWith("(?~")){if(t==="(?~|")throw new Error(`Unsupported absence function kind "${t}"`);return{token:q("absence_repeater",t)}}throw t==="(?("?new Error(`Unsupported conditional "${t}"`):new Error(`Invalid or unsupported group option "${t}"`)}if(t===")"){if(e.popModX(),e.numOpenGroups--,e.numOpenGroups<0)throw new Error('Unmatched ")"');return{token:Qn(t)}}if(e.getCurrentModX()){if(t==="#"){const s=n.indexOf(`
33
+ `,r);return{lastIndex:s===-1?n.length:s}}if(/^\s$/.test(t)){const s=/\s+/y;return s.lastIndex=r,{lastIndex:s.exec(n)?s.lastIndex:r}}}if(t===".")return{token:O("dot",t)};if(t==="^"||t==="$"){const s=e.singleline?{"^":x`\A`,$:x`\Z`}[t]:t;return{token:Ve(s,t)}}return t==="|"?{token:Vn(t)}:xe.test(t)?{tokens:ut(t)}:{token:R(Z(t),t)}}function Wn(e,n,t){const r=[He(n[1]==="^",n)];let a=1,o;for(ke.lastIndex=t;o=ke.exec(e);){const s=o[0];if(s[0]==="["&&s[1]!==":")a++,r.push(He(s[1]==="^",s));else if(s==="]"){if(r.at(-1).type==="CharacterClassOpen")r.push(R(93,s));else if(a--,r.push(jn(s)),!a)break}else{const i=zn(s);Array.isArray(i)?r.push(...i):r.push(i)}}return{tokens:r,lastIndex:ke.lastIndex||e.length}}function zn(e){if(e[0]==="\\")return ze(e,{inCharClass:!0});if(e[0]==="["){const n=/\[:(?<negate>\^?)(?<name>[a-z]+):\]/.exec(e);if(!n||!Ce.has(n.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return O("posix",e,{value:n.groups.name,negate:!!n.groups.negate})}return e==="-"?Hn(e):e==="&&"?Xn(e):R(Z(e),e)}function ze(e,{inCharClass:n}){const t=e[1];if(t==="c"||t==="C")return et(e);if("dDhHsSwW".includes(t))return rt(e);if(e.startsWith(x`\o{`))throw new Error(`Incomplete, invalid, or unsupported octal code point "${e}"`);if(/^\\[pP]\{/.test(e)){if(e.length===3)throw new Error(`Incomplete or invalid Unicode property "${e}"`);return ot(e)}if(new RegExp("^\\\\x[89A-Fa-f]\\p{AHex}","u").test(e))try{const r=e.split(/\\x/).slice(1).map(s=>parseInt(s,16)),a=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}).decode(new Uint8Array(r)),o=new TextEncoder;return[...a].map(s=>{const i=[...o.encode(s)].map(u=>`\\x${u.toString(16)}`).join("");return R(Z(s),i)})}catch{throw new Error(`Multibyte code "${e}" incomplete or invalid in Oniguruma`)}if(t==="u"||t==="x")return R(st(e),e);if(Ze.has(t))return R(Ze.get(t),e);if(/\d/.test(t))return Zn(n,e);if(e==="\\")throw new Error(x`Incomplete escape "\"`);if(t==="M")throw new Error(`Unsupported meta "${e}"`);if([...e].length===2)return R(e.codePointAt(1),e);throw new Error(`Unexpected escape "${e}"`)}function Vn(e){return{type:"Alternator",raw:e}}function Ve(e,n){return{type:"Assertion",kind:e,raw:n}}function je(e){return{type:"Backreference",raw:e}}function R(e,n){return{type:"Character",value:e,raw:n}}function jn(e){return{type:"CharacterClassClose",raw:e}}function Hn(e){return{type:"CharacterClassHyphen",raw:e}}function Xn(e){return{type:"CharacterClassIntersector",raw:e}}function He(e,n){return{type:"CharacterClassOpen",negate:e,raw:n}}function O(e,n,t={}){return{type:"CharacterSet",kind:e,...t,raw:n}}function Xe(e,n,t={}){return e==="keep"?{type:"Directive",kind:e,raw:n}:{type:"Directive",kind:e,flags:Q(t.flags),raw:n}}function Zn(e,n){return{type:"EscapedNumber",inCharClass:e,raw:n}}function Qn(e){return{type:"GroupClose",raw:e}}function q(e,n,t={}){return{type:"GroupOpen",kind:e,...t,raw:n}}function qn(e,n,t,r){return{type:"NamedCallout",kind:e,tag:n,arguments:t,raw:r}}function Jn(e,n,t,r){return{type:"Quantifier",kind:e,min:n,max:t,raw:r}}function Kn(e){return{type:"Subroutine",raw:e}}const Yn=new Set(["COUNT","CMP","ERROR","FAIL","MAX","MISMATCH","SKIP","TOTAL_COUNT"]),Ze=new Map([["a",7],["b",8],["e",27],["f",12],["n",10],["r",13],["t",9],["v",11]]);function et(e){const n=e[1]==="c"?e[2]:e[3];if(!n||!/[A-Za-z]/.test(n))throw new Error(`Unsupported control character "${e}"`);return R(Z(n.toUpperCase())-64,e)}function nt(e,n){let{on:t,off:r}=/^\(\?(?<on>[imx]*)(?:-(?<off>[-imx]*))?/.exec(e).groups;r??(r="");const a=(n.getCurrentModX()||t.includes("x"))&&!r.includes("x"),o=qe(t),s=qe(r),i={};if(o&&(i.enable=o),s&&(i.disable=s),e.endsWith(")"))return n.replaceCurrentModX(a),Xe("flags",e,{flags:i});if(e.endsWith(":"))return n.pushModX(a),n.numOpenGroups++,q("group",e,{...(o||s)&&{flags:i}});throw new Error(`Unexpected flag modifier "${e}"`)}function tt(e){const n=/\(\*(?<name>[A-Za-z_]\w*)?(?:\[(?<tag>(?:[A-Za-z_]\w*)?)\])?(?:\{(?<args>[^}]*)\})?\)/.exec(e);if(!n)throw new Error(`Incomplete or invalid named callout "${e}"`);const{name:t,tag:r,args:a}=n.groups;if(!t)throw new Error(`Invalid named callout "${e}"`);if(r==="")throw new Error(`Named callout tag with empty value not allowed "${e}"`);const o=a?a.split(",").filter(p=>p!=="").map(p=>/^[+-]?\d+$/.test(p)?+p:p):[],[s,i,u]=o,c=Yn.has(t)?t.toLowerCase():"custom";switch(c){case"fail":case"mismatch":case"skip":if(o.length>0)throw new Error(`Named callout arguments not allowed "${o}"`);break;case"error":if(o.length>1)throw new Error(`Named callout allows only one argument "${o}"`);if(typeof s=="string")throw new Error(`Named callout argument must be a number "${s}"`);break;case"max":if(!o.length||o.length>2)throw new Error(`Named callout must have one or two arguments "${o}"`);if(typeof s=="string"&&!/^[A-Za-z_]\w*$/.test(s))throw new Error(`Named callout argument one must be a tag or number "${s}"`);if(o.length===2&&(typeof i=="number"||!/^[<>X]$/.test(i)))throw new Error(`Named callout optional argument two must be '<', '>', or 'X' "${i}"`);break;case"count":case"total_count":if(o.length>1)throw new Error(`Named callout allows only one argument "${o}"`);if(o.length===1&&(typeof s=="number"||!/^[<>X]$/.test(s)))throw new Error(`Named callout optional argument must be '<', '>', or 'X' "${s}"`);break;case"cmp":if(o.length!==3)throw new Error(`Named callout must have three arguments "${o}"`);if(typeof s=="string"&&!/^[A-Za-z_]\w*$/.test(s))throw new Error(`Named callout argument one must be a tag or number "${s}"`);if(typeof i=="number"||!/^(?:[<>!=]=|[<>])$/.test(i))throw new Error(`Named callout argument two must be '==', '!=', '>', '<', '>=', or '<=' "${i}"`);if(typeof u=="string"&&!/^[A-Za-z_]\w*$/.test(u))throw new Error(`Named callout argument three must be a tag or number "${u}"`);break;case"custom":throw new Error(`Undefined callout name "${t}"`);default:throw new Error(`Unexpected named callout kind "${c}"`)}return qn(c,r??null,a?.split(",")??null,e)}function Qe(e){let n=null,t,r;if(e[0]==="{"){const{minStr:a,maxStr:o}=/^\{(?<minStr>\d*)(?:,(?<maxStr>\d*))?/.exec(e).groups,s=1e5;if(+a>s||o&&+o>s)throw new Error("Quantifier value unsupported in Oniguruma");if(t=+a,r=o===void 0?+a:o===""?1/0:+o,t>r&&(n="possessive",[t,r]=[r,t]),e.endsWith("?")){if(n==="possessive")throw new Error('Unsupported possessive interval quantifier chain with "?"');n="lazy"}else n||(n="greedy")}else t=e[0]==="+"?1:0,r=e[0]==="?"?1:1/0,n=e[1]==="+"?"possessive":e[1]==="?"?"lazy":"greedy";return Jn(n,t,r,e)}function rt(e){const n=e[1].toLowerCase();return O({d:"digit",h:"hex",s:"space",w:"word"}[n],e,{negate:e[1]!==n})}function ot(e){const{p:n,neg:t,value:r}=/^\\(?<p>[pP])\{(?<neg>\^?)(?<value>[^}]+)/.exec(e).groups;return O("property",e,{value:r,negate:n==="P"&&!t||n==="p"&&!!t})}function qe(e){const n={};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}function at(e){const n={ignoreCase:!1,dotAll:!1,extended:!1,digitIsAscii:!1,posixIsAscii:!1,spaceIsAscii:!1,wordIsAscii:!1,textSegmentMode:null};for(let t=0;t<e.length;t++){const r=e[t];if(!"imxDPSWy".includes(r))throw new Error(`Invalid flag "${r}"`);if(r==="y"){if(!/^y{[gw]}/.test(e.slice(t)))throw new Error('Invalid or unspecified flag "y" mode');n.textSegmentMode=e[t+2]==="g"?"grapheme":"word",t+=3;continue}n[{i:"ignoreCase",m:"dotAll",x:"extended",D:"digitIsAscii",P:"posixIsAscii",S:"spaceIsAscii",W:"wordIsAscii"}[r]]=!0}return n}function st(e){if(new RegExp("^(?:\\\\u(?!\\p{AHex}{4})|\\\\x(?!\\p{AHex}{1,2}|\\{\\p{AHex}{1,8}\\}))","u").test(e))throw new Error(`Incomplete or invalid escape "${e}"`);const n=e[2]==="{"?new RegExp("^\\\\x\\{\\s*(?<hex>\\p{AHex}+)","u").exec(e).groups.hex:e.slice(2);return parseInt(n,16)}function it(e,n){const{raw:t,inCharClass:r}=e,a=t.slice(1);if(!r&&(a!=="0"&&a.length===1||a[0]!=="0"&&+a<=n))return[je(t)];const o=[],s=a.match(/^[0-7]+|\d/g);for(let i=0;i<s.length;i++){const u=s[i];let c;if(i===0&&u!=="8"&&u!=="9"){if(c=parseInt(u,8),c>127)throw new Error(x`Octal encoded byte above 177 unsupported "${t}"`)}else c=Z(u);o.push(R(c,(i===0?"\\":"")+u))}return o}function ut(e){const n=[],t=new RegExp(xe,"gy");let r;for(;r=t.exec(e);){const a=r[0];if(a[0]==="{"){const o=/^\{(?<min>\d+),(?<max>\d+)\}\??$/.exec(a);if(o){const{min:s,max:i}=o.groups;if(+s>+i&&a.endsWith("?")){t.lastIndex--,n.push(Qe(a.slice(0,-1)));continue}}}n.push(Qe(a))}return n}function Je(e,n){if(!Array.isArray(e.body))throw new Error("Expected node with body array");if(e.body.length!==1)return!1;const t=e.body[0];return!n||Object.keys(n).every(r=>n[r]===t[r])}function ct(e){return lt.has(e.type)}const lt=new Set(["AbsenceFunction","Backreference","CapturingGroup","Character","CharacterClass","CharacterSet","Group","Quantifier","Subroutine"]);function Ke(e,n={}){const t={flags:"",normalizeUnknownPropertyNames:!1,skipBackrefValidation:!1,skipLookbehindValidation:!1,skipPropertyNameValidation:!1,unicodePropertyMap:null,...n,rules:{captureGroup:!1,singleline:!1,...n.rules}},r=On(e,{flags:t.flags,rules:{captureGroup:t.rules.captureGroup,singleline:t.rules.singleline}}),a=(d,g)=>{const f=r.tokens[o.nextIndex];switch(o.parent=d,o.nextIndex++,f.type){case"Alternator":return T();case"Assertion":return pt(f);case"Backreference":return dt(f,o);case"Character":return ce(f.value,{useLastValid:!!g.isCheckingRangeEnd});case"CharacterClassHyphen":return ft(f,o,g);case"CharacterClassOpen":return gt(f,o,g);case"CharacterSet":return ht(f,o);case"Directive":return xt(f.kind,{flags:f.flags});case"GroupOpen":return wt(f,o,g);case"NamedCallout":return Et(f.kind,f.tag,f.arguments);case"Quantifier":return yt(f,o);case"Subroutine":return mt(f,o);default:throw new Error(`Unexpected token type "${f.type}"`)}},o={capturingGroups:[],hasNumberedRef:!1,namedGroupsByName:new Map,nextIndex:0,normalizeUnknownPropertyNames:t.normalizeUnknownPropertyNames,parent:null,skipBackrefValidation:t.skipBackrefValidation,skipLookbehindValidation:t.skipLookbehindValidation,skipPropertyNameValidation:t.skipPropertyNameValidation,subroutines:[],tokens:r.tokens,unicodePropertyMap:t.unicodePropertyMap,walk:a},s=$t(kt(r.flags));let i=s.body[0];for(;o.nextIndex<r.tokens.length;){const d=a(i,{});d.type==="Alternative"?(s.body.push(d),i=d):i.body.push(d)}const{capturingGroups:u,hasNumberedRef:c,namedGroupsByName:p,subroutines:l}=o;if(c&&p.size&&!t.rules.captureGroup)throw new Error("Numbered backref/subroutine not allowed when using named capture");for(const{ref:d}of l)if(typeof d=="number"){if(d>u.length)throw new Error("Subroutine uses a group number that's not defined");d&&(u[d-1].isSubroutined=!0)}else if(p.has(d)){if(p.get(d).length>1)throw new Error(x`Subroutine uses a duplicate group name "\g<${d}>"`);p.get(d)[0].isSubroutined=!0}else throw new Error(x`Subroutine uses a group name that's not defined "\g<${d}>"`);return s}function pt({kind:e}){return Ee(Q({"^":"line_start",$:"line_end","\\A":"string_start","\\b":"word_boundary","\\B":"word_boundary","\\G":"search_start","\\y":"text_segment_boundary","\\Y":"text_segment_boundary","\\z":"string_end","\\Z":"string_end_newline"}[e],`Unexpected assertion kind "${e}"`),{negate:e===x`\B`||e===x`\Y`})}function dt({raw:e},n){const t=/^\\k[<']/.test(e),r=t?e.slice(3,-1):e.slice(1),a=(o,s=!1)=>{const i=n.capturingGroups.length;let u=!1;if(o>i)if(n.skipBackrefValidation)u=!0;else throw new Error(`Not enough capturing groups defined to the left "${e}"`);return n.hasNumberedRef=!0,ve(s?i+1-o:o,{orphan:u})};if(t){const o=/^(?<sign>-?)0*(?<num>[1-9]\d*)$/.exec(r);if(o)return a(+o.groups.num,!!o.groups.sign);if(/[-+]/.test(r))throw new Error(`Invalid backref name "${e}"`);if(!n.namedGroupsByName.has(r))throw new Error(`Group name not defined to the left "${e}"`);return ve(r)}return a(+r)}function ft(e,n,t){const{tokens:r,walk:a}=n,o=n.parent,s=o.body.at(-1),i=r[n.nextIndex];if(!t.isCheckingRangeEnd&&s&&s.type!=="CharacterClass"&&s.type!=="CharacterClassRange"&&i&&i.type!=="CharacterClassOpen"&&i.type!=="CharacterClassClose"&&i.type!=="CharacterClassIntersector"){const u=a(o,{...t,isCheckingRangeEnd:!0});if(s.type==="Character"&&u.type==="Character")return o.body.pop(),Ct(s,u);throw new Error("Invalid character class range")}return ce(Z("-"))}function gt({negate:e},n,t){const{tokens:r,walk:a}=n,o=[le()],s=r[n.nextIndex];let i=an(s);for(;i.type!=="CharacterClassClose";){if(i.type==="CharacterClassIntersector")o.push(le()),n.nextIndex++;else{const c=o.at(-1);c.body.push(a(c,t))}i=an(r[n.nextIndex],s)}const u=le({negate:e});return o.length===1?u.body=o[0].body:(u.kind="intersection",u.body=o.map(c=>c.body.length===1?c.body[0]:c)),n.nextIndex++,u}function ht({kind:e,negate:n,value:t},r){const{normalizeUnknownPropertyNames:a,skipPropertyNameValidation:o,unicodePropertyMap:s}=r;if(e==="property"){const i=pe(t);if(Ce.has(i)&&!(s!=null&&s.has(i)))e="posix",t=i;else return J(t,{negate:n,normalizeUnknownPropertyNames:a,skipPropertyNameValidation:o,unicodePropertyMap:s})}return e==="posix"?vt(t,{negate:n}):$e(e,{negate:n})}function wt(e,n,t){const{tokens:r,capturingGroups:a,namedGroupsByName:o,skipLookbehindValidation:s,walk:i}=n,u=At(e),c=u.type==="AbsenceFunction",p=on(u),l=p&&u.negate;if(u.type==="CapturingGroup"&&(a.push(u),u.name&&Dn(o,u.name,[]).push(u)),c&&t.isInAbsenceFunction)throw new Error("Nested absence function not supported by Oniguruma");let d=sn(r[n.nextIndex]);for(;d.type!=="GroupClose";){if(d.type==="Alternator")u.body.push(T()),n.nextIndex++;else{const g=u.body.at(-1),f=i(g,{...t,isInAbsenceFunction:t.isInAbsenceFunction||c,isInLookbehind:t.isInLookbehind||p,isInNegLookbehind:t.isInNegLookbehind||l});if(g.body.push(f),(p||t.isInLookbehind)&&!s){const w="Lookbehind includes a pattern not allowed by Oniguruma";if(l||t.isInNegLookbehind){if(rn(f)||f.type==="CapturingGroup")throw new Error(w)}else if(rn(f)||on(f)&&f.negate)throw new Error(w)}}d=sn(r[n.nextIndex])}return n.nextIndex++,u}function yt({kind:e,min:n,max:t},r){const a=r.parent,o=a.body.at(-1);if(!o||!ct(o))throw new Error("Quantifier requires a repeatable token");const s=en(e,n,t,o);return a.body.pop(),s}function mt({raw:e},n){const{capturingGroups:t,subroutines:r}=n;let a=e.slice(3,-1);const o=/^(?<sign>[-+]?)0*(?<num>[1-9]\d*)$/.exec(a);if(o){const i=+o.groups.num,u=t.length;if(n.hasNumberedRef=!0,a={"":i,"+":u+i,"-":u+1-i}[o.groups.sign],a<1)throw new Error("Invalid subroutine number")}else a==="0"&&(a=0);const s=nn(a);return r.push(s),s}function bt(e,n){return{type:"AbsenceFunction",kind:e,body:re(n?.body)}}function T(e){return{type:"Alternative",body:tn(e?.body)}}function Ee(e,n){const t={type:"Assertion",kind:e};return(e==="word_boundary"||e==="text_segment_boundary")&&(t.negate=!!(n!=null&&n.negate)),t}function ve(e,n){const t=!!(n!=null&&n.orphan);return{type:"Backreference",ref:e,...t&&{orphan:t}}}function Ye(e,n){const t={name:void 0,isSubroutined:!1,...n};if(t.name!==void 0&&!It(t.name))throw new Error(`Group name "${t.name}" invalid in Oniguruma`);return{type:"CapturingGroup",number:e,...t.name&&{name:t.name},...t.isSubroutined&&{isSubroutined:t.isSubroutined},body:re(n?.body)}}function ce(e,n){const t={useLastValid:!1,...n};if(e>1114111){const r=e.toString(16);if(t.useLastValid)e=1114111;else throw e>1310719?new Error(`Invalid code point out of range "\\x{${r}}"`):new Error(`Invalid code point out of range in JS "\\x{${r}}"`)}return{type:"Character",value:e}}function le(e){const n={kind:"union",negate:!1,...e};return{type:"CharacterClass",kind:n.kind,negate:n.negate,body:tn(e?.body)}}function Ct(e,n){if(n.value<e.value)throw new Error("Character class range out of order");return{type:"CharacterClassRange",min:e,max:n}}function $e(e,n){const t=!!(n!=null&&n.negate),r={type:"CharacterSet",kind:e};return(e==="digit"||e==="hex"||e==="newline"||e==="space"||e==="word")&&(r.negate=t),(e==="text_segment"||e==="newline"&&!t)&&(r.variableLength=!0),r}function xt(e,n={}){if(e==="keep")return{type:"Directive",kind:e};if(e==="flags")return{type:"Directive",kind:e,flags:Q(n.flags)};throw new Error(`Unexpected directive kind "${e}"`)}function kt(e){return{type:"Flags",...e}}function _(e){const n=e?.atomic,t=e?.flags;if(n&&t)throw new Error("Atomic group cannot have flags");return{type:"Group",...n&&{atomic:n},...t&&{flags:t},body:re(e?.body)}}function W(e){const n={behind:!1,negate:!1,...e};return{type:"LookaroundAssertion",kind:n.behind?"lookbehind":"lookahead",negate:n.negate,body:re(e?.body)}}function Et(e,n,t){return{type:"NamedCallout",kind:e,tag:n,arguments:t}}function vt(e,n){const t=!!(n!=null&&n.negate);if(!Ce.has(e))throw new Error(`Invalid POSIX class "${e}"`);return{type:"CharacterSet",kind:"posix",value:e,negate:t}}function en(e,n,t,r){if(n>t)throw new Error("Invalid reversed quantifier range");return{type:"Quantifier",kind:e,min:n,max:t,body:r}}function $t(e,n){return{type:"Regex",body:re(n?.body),flags:e}}function nn(e){return{type:"Subroutine",ref:e}}function J(e,n){var t;const r={negate:!1,normalizeUnknownPropertyNames:!1,skipPropertyNameValidation:!1,unicodePropertyMap:null,...n};let a=(t=r.unicodePropertyMap)==null?void 0:t.get(pe(e));if(!a){if(r.normalizeUnknownPropertyNames)a=St(e);else if(r.unicodePropertyMap&&!r.skipPropertyNameValidation)throw new Error(x`Invalid Unicode property "\p{${e}}"`)}return{type:"CharacterSet",kind:"property",value:a??e,negate:r.negate}}function At({flags:e,kind:n,name:t,negate:r,number:a}){switch(n){case"absence_repeater":return bt("repeater");case"atomic":return _({atomic:!0});case"capturing":return Ye(a,{name:t});case"group":return _({flags:e});case"lookahead":case"lookbehind":return W({behind:n==="lookbehind",negate:r});default:throw new Error(`Unexpected group kind "${n}"`)}}function re(e){if(e===void 0)e=[T()];else if(!Array.isArray(e)||!e.length||!e.every(n=>n.type==="Alternative"))throw new Error("Invalid body; expected array of one or more Alternative nodes");return e}function tn(e){if(e===void 0)e=[];else if(!Array.isArray(e)||!e.every(n=>!!n.type))throw new Error("Invalid body; expected array of nodes");return e}function rn(e){return e.type==="LookaroundAssertion"&&e.kind==="lookahead"}function on(e){return e.type==="LookaroundAssertion"&&e.kind==="lookbehind"}function It(e){return/^[\p{Alpha}\p{Pc}][^)]*$/u.test(e)}function St(e){return e.trim().replace(/[- _]+/g,"_").replace(/[A-Z][a-z]+(?=[A-Z])/g,"$&_").replace(/[A-Za-z]+/g,n=>n[0].toUpperCase()+n.slice(1).toLowerCase())}function pe(e){return e.replace(/[- _]+/g,"").toLowerCase()}function an(e,n){const t=n;return Q(e,`Unclosed character class${t?.type==="Character"&&t.value===93&&t.raw==="]"?' (started with "]")':""}`)}function sn(e){return Q(e,"Unclosed group")}function oe(e,n,t=null){function r(o,s){for(let i=0;i<o.length;i++){const u=a(o[i],s,i,o);i=Math.max(-1,i+u)}}function a(o,s=null,i=null,u=null){var c,p;let l=0,d=!1;const g={node:o,parent:s,key:i,container:u,root:e,remove(){de(u).splice(Math.max(0,K(i)+l),1),l--,d=!0},removeAllNextSiblings(){return de(u).splice(K(i)+1)},removeAllPrevSiblings(){const m=K(i)+l;return l-=m,de(u).splice(0,Math.max(0,m))},replaceWith(m,k={}){const I=!!k.traverse;u?u[Math.max(0,K(i)+l)]=m:Q(s,"Can't replace root node")[i]=m,I&&a(m,s,i,u),d=!0},replaceWithMultiple(m,k={}){const I=!!k.traverse;if(de(u).splice(Math.max(0,K(i)+l),1,...m),l+=m.length-1,I){let D=0;for(let S=0;S<m.length;S++)D+=a(m[S],s,K(i)+S+D,u)}d=!0},skip(){d=!0}},{type:f}=o,w=n["*"],y=n[f],N=typeof w=="function"?w:w?.enter,v=typeof y=="function"?y:y?.enter;if(N?.(g,t),v?.(g,t),!d)switch(f){case"AbsenceFunction":case"Alternative":case"CapturingGroup":case"CharacterClass":case"Group":case"LookaroundAssertion":r(o.body,o);break;case"Assertion":case"Backreference":case"Character":case"CharacterSet":case"Directive":case"Flags":case"NamedCallout":case"Subroutine":break;case"CharacterClassRange":a(o.min,o,"min"),a(o.max,o,"max");break;case"Quantifier":a(o.body,o,"body");break;case"Regex":r(o.body,o),a(o.flags,o,"flags");break;default:throw new Error(`Unexpected node type "${f}"`)}return(c=y?.exit)==null||c.call(y,g,t),(p=w?.exit)==null||p.call(w,g,t),l}return a(e),e}function de(e){if(!Array.isArray(e))throw new Error("Container expected");return e}function K(e){if(typeof e!="number")throw new Error("Numeric key expected");return e}const _t=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;function Mt(e,n){for(let t=0;t<e.length;t++)e[t]>=n&&e[t]++}function Nt(e,n,t,r){return e.slice(0,n)+r+e.slice(n+t.length)}const $=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function Ae(e,n,t,r){const a=new RegExp(String.raw`${n}|(?<$skip>\[\^?|\\?.)`,"gsu"),o=[!1];let s=0,i="";for(const u of e.matchAll(a)){const{0:c,groups:{$skip:p}}=u;if(!p&&(!r||r===$.DEFAULT==!s)){t instanceof Function?i+=t(u,{context:s?$.CHAR_CLASS:$.DEFAULT,negated:o[o.length-1]}):i+=t;continue}c[0]==="["?(s++,o.push(c[1]==="^")):c==="]"&&s&&(s--,o.pop()),i+=c}return i}function un(e,n,t,r){Ae(e,n,t,r)}function Lt(e,n,t=0,r){if(!new RegExp(n,"su").test(e))return null;const a=new RegExp(`${n}|(?<$skip>\\\\?.)`,"gsu");a.lastIndex=t;let o=0,s;for(;s=a.exec(e);){const{0:i,groups:{$skip:u}}=s;if(!u&&(!r||r===$.DEFAULT==!o))return s;i==="["?o++:i==="]"&&o&&o--,a.lastIndex==s.index&&a.lastIndex++}return null}function fe(e,n,t){return!!Lt(e,n,0,t)}function Rt(e,n){const t=/\\?./gsu;t.lastIndex=n;let r=e.length,a=0,o=1,s;for(;s=t.exec(e);){const[i]=s;if(i==="[")a++;else if(a)i==="]"&&a--;else if(i==="(")o++;else if(i===")"&&(o--,!o)){r=s.index;break}}return e.slice(n,r)}const cn=new RegExp(String.raw`(?<noncapturingStart>${_t})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`,"gsu");function Pt(e,n){const t=n?.hiddenCaptures??[];let r=n?.captureTransfers??new Map;if(!/\(\?>/.test(e))return{pattern:e,captureTransfers:r,hiddenCaptures:t};const a="(?>",o="(?:(?=(",s=[0],i=[];let u=0,c=0,p=NaN,l;do{l=!1;let d=0,g=0,f=!1,w;for(cn.lastIndex=Number.isNaN(p)?0:p+o.length;w=cn.exec(e);){const{0:y,index:N,groups:{capturingStart:v,noncapturingStart:m}}=w;if(y==="[")d++;else if(d)y==="]"&&d--;else if(y===a&&!f)p=N,f=!0;else if(f&&m)g++;else if(v)f?g++:(u++,s.push(u+c));else if(y===")"&&f){if(!g){c++;const k=u+c;if(e=`${e.slice(0,p)}${o}${e.slice(p+a.length,N)}))<$$${k}>)${e.slice(N+1)}`,l=!0,i.push(k),Mt(t,k),r.size){const I=new Map;r.forEach((D,S)=>{I.set(S>=k?S+1:S,D.map(H=>H>=k?H+1:H))}),r=I}break}g--}}}while(l);return t.push(...i),e=Ae(e,String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,({0:d,groups:{backrefNum:g,wrappedBackrefNum:f}})=>{if(g){const w=+g;if(w>s.length-1)throw new Error(`Backref "${d}" greater than number of captures`);return`\\${s[w]}`}return`\\${f}`},$.DEFAULT),{pattern:e,captureTransfers:r,hiddenCaptures:t}}const ln=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,Ie=new RegExp(String.raw`
925
34
  \\(?: \d+
926
35
  | c[A-Za-z]
927
36
  | [gk]<[^>]+>
@@ -934,342 +43,9 @@ const Cr = String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`, xe = new RegExp(String.raw`
934
43
  | [A-Za-z\-]+:
935
44
  | \(DEFINE\)
936
45
  ))?
937
- | (?<qBase>${Cr})(?<qMod>[?+]?)(?<invalidQ>[?*+\{]?)
46
+ | (?<qBase>${ln})(?<qMod>[?+]?)(?<invalidQ>[?*+\{]?)
938
47
  | \\?.
939
- `.replace(/\s+/g, ""), "gsu");
940
- function Ft(e) {
941
- if (!new RegExp(`${Cr}\\+`).test(e))
942
- return {
943
- pattern: e
944
- };
945
- const r = [];
946
- let t = null, n = null, s = "", o = 0, a;
947
- for (xe.lastIndex = 0; a = xe.exec(e); ) {
948
- const { 0: i, index: u, groups: { qBase: c, qMod: p, invalidQ: l } } = a;
949
- if (i === "[")
950
- o || (n = u), o++;
951
- else if (i === "]")
952
- o ? o-- : n = null;
953
- else if (!o)
954
- if (p === "+" && s && !s.startsWith("(")) {
955
- if (l)
956
- throw new Error(`Invalid quantifier "${i}"`);
957
- let f = -1;
958
- if (/^\{\d+\}$/.test(c))
959
- e = _t(e, u + c.length, p, "");
960
- else {
961
- if (s === ")" || s === "]") {
962
- const g = s === ")" ? t : n;
963
- if (g === null)
964
- throw new Error(`Invalid unmatched "${s}"`);
965
- e = `${e.slice(0, g)}(?>${e.slice(g, u)}${c})${e.slice(u + i.length)}`;
966
- } else
967
- e = `${e.slice(0, u - s.length)}(?>${s}${c})${e.slice(u + i.length)}`;
968
- f += 4;
969
- }
970
- xe.lastIndex += f;
971
- } else i[0] === "(" ? r.push(u) : i === ")" && (t = r.length ? r.pop() : null);
972
- s = i;
973
- }
974
- return {
975
- pattern: e
976
- };
977
- }
978
- const I = String.raw, Gt = I`\\g<(?<gRNameOrNum>[^>&]+)&R=(?<gRDepth>[^>]+)>`, Me = I`\(\?R=(?<rDepth>[^\)]+)\)|${Gt}`, we = I`\(\?<(?![=!])(?<captureName>[^>]+)>`, br = I`${we}|(?<unnamed>\()(?!\?)`, W = new RegExp(I`${we}|${Me}|\(\?|\\?.`, "gsu"), ke = "Cannot use multiple overlapping recursions";
979
- function Pt(e, r) {
980
- const { hiddenCaptures: t, mode: n } = {
981
- hiddenCaptures: [],
982
- mode: "plugin",
983
- ...r
984
- };
985
- let s = (r == null ? void 0 : r.captureTransfers) ?? /* @__PURE__ */ new Map();
986
- if (!new RegExp(Me, "su").test(e))
987
- return {
988
- pattern: e,
989
- captureTransfers: s,
990
- hiddenCaptures: t
991
- };
992
- if (n === "plugin" && pe(e, I`\(\?\(DEFINE\)`, S.DEFAULT))
993
- throw new Error("DEFINE groups cannot be used with recursion");
994
- const o = [], a = pe(e, I`\\[1-9]`, S.DEFAULT), i = /* @__PURE__ */ new Map(), u = [];
995
- let c = !1, p = 0, l = 0, f;
996
- for (W.lastIndex = 0; f = W.exec(e); ) {
997
- const { 0: g, groups: { captureName: d, rDepth: w, gRNameOrNum: m, gRDepth: $ } } = f;
998
- if (g === "[")
999
- p++;
1000
- else if (p)
1001
- g === "]" && p--;
1002
- else if (w) {
1003
- if (Je(w), c)
1004
- throw new Error(ke);
1005
- if (a)
1006
- throw new Error(
1007
- // When used in `external` mode by transpilers other than Regex+, backrefs might have
1008
- // gone through conversion from named to numbered, so avoid a misleading error
1009
- `${n === "external" ? "Backrefs" : "Numbered backrefs"} cannot be used with global recursion`
1010
- );
1011
- const A = e.slice(0, f.index), y = e.slice(W.lastIndex);
1012
- if (pe(y, Me, S.DEFAULT))
1013
- throw new Error(ke);
1014
- const k = +w - 1;
1015
- e = Ke(
1016
- A,
1017
- y,
1018
- k,
1019
- !1,
1020
- t,
1021
- o,
1022
- l
1023
- ), s = er(
1024
- s,
1025
- A,
1026
- k,
1027
- o.length,
1028
- 0,
1029
- l
1030
- );
1031
- break;
1032
- } else if (m) {
1033
- Je($);
1034
- let A = !1;
1035
- for (const ne of u)
1036
- if (ne.name === m || ne.num === +m) {
1037
- if (A = !0, ne.hasRecursedWithin)
1038
- throw new Error(ke);
1039
- break;
1040
- }
1041
- if (!A)
1042
- throw new Error(I`Recursive \g cannot be used outside the referenced group "${n === "external" ? m : I`\g<${m}&R=${$}>`}"`);
1043
- const y = i.get(m), k = Nt(e, y);
1044
- if (a && pe(k, I`${we}|\((?!\?)`, S.DEFAULT))
1045
- throw new Error(
1046
- // When used in `external` mode by transpilers other than Regex+, backrefs might have
1047
- // gone through conversion from named to numbered, so avoid a misleading error
1048
- `${n === "external" ? "Backrefs" : "Numbered backrefs"} cannot be used with recursion of capturing groups`
1049
- );
1050
- const v = e.slice(y, f.index), V = k.slice(v.length + g.length), _ = o.length, q = +$ - 1, Oe = Ke(
1051
- v,
1052
- V,
1053
- q,
1054
- !0,
1055
- t,
1056
- o,
1057
- l
1058
- );
1059
- s = er(
1060
- s,
1061
- v,
1062
- q,
1063
- o.length - _,
1064
- _,
1065
- l
1066
- );
1067
- const Nr = e.slice(0, y), Lr = e.slice(y + k.length);
1068
- e = `${Nr}${Oe}${Lr}`, W.lastIndex += Oe.length - g.length - v.length - V.length, u.forEach((ne) => ne.hasRecursedWithin = !0), c = !0;
1069
- } else if (d)
1070
- l++, i.set(String(l), W.lastIndex), i.set(d, W.lastIndex), u.push({
1071
- num: l,
1072
- name: d
1073
- });
1074
- else if (g[0] === "(") {
1075
- const A = g === "(";
1076
- A && (l++, i.set(String(l), W.lastIndex)), u.push(A ? { num: l } : {});
1077
- } else g === ")" && u.pop();
1078
- }
1079
- return t.push(...o), {
1080
- pattern: e,
1081
- captureTransfers: s,
1082
- hiddenCaptures: t
1083
- };
1084
- }
1085
- function Je(e) {
1086
- const r = `Max depth must be integer between 2 and 100; used ${e}`;
1087
- if (!/^[1-9]\d*$/.test(e))
1088
- throw new Error(r);
1089
- if (e = +e, e < 2 || e > 100)
1090
- throw new Error(r);
1091
- }
1092
- function Ke(e, r, t, n, s, o, a) {
1093
- const i = /* @__PURE__ */ new Set();
1094
- n && yr(e + r, we, ({ groups: { captureName: c } }) => {
1095
- i.add(c);
1096
- }, S.DEFAULT);
1097
- const u = [
1098
- t,
1099
- n ? i : null,
1100
- s,
1101
- o,
1102
- a
1103
- ];
1104
- return `${e}${Ye(`(?:${e}`, "forward", ...u)}(?:)${Ye(`${r})`, "backward", ...u)}${r}`;
1105
- }
1106
- function Ye(e, r, t, n, s, o, a) {
1107
- const u = (p) => r === "forward" ? p + 2 : t - p + 2 - 1;
1108
- let c = "";
1109
- for (let p = 0; p < t; p++) {
1110
- const l = u(p);
1111
- c += Pe(
1112
- e,
1113
- I`${br}|\\k<(?<backref>[^>]+)>`,
1114
- ({ 0: f, groups: { captureName: g, unnamed: d, backref: w } }) => {
1115
- if (w && n && !n.has(w))
1116
- return f;
1117
- const m = `_$${l}`;
1118
- if (d || g) {
1119
- const $ = a + o.length + 1;
1120
- return o.push($), Rt(s, $), d ? f : `(?<${g}${m}>`;
1121
- }
1122
- return I`\k<${w}${m}>`;
1123
- },
1124
- S.DEFAULT
1125
- );
1126
- }
1127
- return c;
1128
- }
1129
- function Rt(e, r) {
1130
- for (let t = 0; t < e.length; t++)
1131
- e[t] >= r && e[t]++;
1132
- }
1133
- function er(e, r, t, n, s, o) {
1134
- if (e.size && n) {
1135
- let a = 0;
1136
- yr(r, br, () => a++, S.DEFAULT);
1137
- const i = o - a + s, u = /* @__PURE__ */ new Map();
1138
- return e.forEach((c, p) => {
1139
- const l = (n - a * t) / t, f = a * t, g = p > i + a ? p + n : p, d = [];
1140
- for (const w of c)
1141
- if (w <= i)
1142
- d.push(w);
1143
- else if (w > i + a + l)
1144
- d.push(w + n);
1145
- else if (w <= i + a)
1146
- for (let m = 0; m <= t; m++)
1147
- d.push(w + a * m);
1148
- else
1149
- for (let m = 0; m <= t; m++)
1150
- d.push(w + f + l * m);
1151
- u.set(g, d);
1152
- }), u;
1153
- }
1154
- return e;
1155
- }
1156
- var b = String.fromCodePoint, h = String.raw, L = {}, me = globalThis.RegExp;
1157
- L.flagGroups = (() => {
1158
- try {
1159
- new me("(?i:)");
1160
- } catch {
1161
- return !1;
1162
- }
1163
- return !0;
1164
- })();
1165
- L.unicodeSets = (() => {
1166
- try {
1167
- new me("[[]]", "v");
1168
- } catch {
1169
- return !1;
1170
- }
1171
- return !0;
1172
- })();
1173
- L.bugFlagVLiteralHyphenIsRange = L.unicodeSets ? (() => {
1174
- try {
1175
- new me(h`[\d\-a]`, "v");
1176
- } catch {
1177
- return !0;
1178
- }
1179
- return !1;
1180
- })() : !1;
1181
- L.bugNestedClassIgnoresNegation = L.unicodeSets && new me("[[^a]]", "v").test("a");
1182
- function de(e, { enable: r, disable: t }) {
1183
- return {
1184
- dotAll: !(t != null && t.dotAll) && !!(r != null && r.dotAll || e.dotAll),
1185
- ignoreCase: !(t != null && t.ignoreCase) && !!(r != null && r.ignoreCase || e.ignoreCase)
1186
- };
1187
- }
1188
- function ae(e, r, t) {
1189
- return e.has(r) || e.set(r, t), e.get(r);
1190
- }
1191
- function Ne(e, r) {
1192
- return rr[e] >= rr[r];
1193
- }
1194
- function Ut(e, r) {
1195
- if (e == null)
1196
- throw new Error(r ?? "Value expected");
1197
- return e;
1198
- }
1199
- var rr = {
1200
- ES2025: 2025,
1201
- ES2024: 2024,
1202
- ES2018: 2018
1203
- }, Ot = (
1204
- /** @type {const} */
1205
- {
1206
- auto: "auto",
1207
- ES2025: "ES2025",
1208
- ES2024: "ES2024",
1209
- ES2018: "ES2018"
1210
- }
1211
- );
1212
- function xr(e = {}) {
1213
- if ({}.toString.call(e) !== "[object Object]")
1214
- throw new Error("Unexpected options");
1215
- if (e.target !== void 0 && !Ot[e.target])
1216
- throw new Error(`Unexpected target "${e.target}"`);
1217
- const r = {
1218
- // Sets the level of emulation rigor/strictness.
1219
- accuracy: "default",
1220
- // Disables advanced emulation that relies on returning a `RegExp` subclass, resulting in
1221
- // certain patterns not being emulatable.
1222
- avoidSubclass: !1,
1223
- // Oniguruma flags; a string with `i`, `m`, `x`, `D`, `S`, `W`, `y{g}` in any order (all
1224
- // optional). Oniguruma's `m` is equivalent to JavaScript's `s` (`dotAll`).
1225
- flags: "",
1226
- // Include JavaScript flag `g` (`global`) in the result.
1227
- global: !1,
1228
- // Include JavaScript flag `d` (`hasIndices`) in the result.
1229
- hasIndices: !1,
1230
- // Delay regex construction until first use if the transpiled pattern is at least this length.
1231
- lazyCompileLength: 1 / 0,
1232
- // JavaScript version used for generated regexes. Using `auto` detects the best value based on
1233
- // your environment. Later targets allow faster processing, simpler generated source, and
1234
- // support for additional features.
1235
- target: "auto",
1236
- // Disables minifications that simplify the pattern without changing the meaning.
1237
- verbose: !1,
1238
- ...e,
1239
- // Advanced options that override standard behavior, error checking, and flags when enabled.
1240
- rules: {
1241
- // Useful with TextMate grammars that merge backreferences across patterns.
1242
- allowOrphanBackrefs: !1,
1243
- // Use ASCII `\b` and `\B`, which increases search performance of generated regexes.
1244
- asciiWordBoundaries: !1,
1245
- // Allow unnamed captures and numbered calls (backreferences and subroutines) when using
1246
- // named capture. This is Oniguruma option `ONIG_OPTION_CAPTURE_GROUP`; on by default in
1247
- // `vscode-oniguruma`.
1248
- captureGroup: !1,
1249
- // Change the recursion depth limit from Oniguruma's `20` to an integer `2`–`20`.
1250
- recursionLimit: 20,
1251
- // `^` as `\A`; `$` as`\Z`. Improves search performance of generated regexes without changing
1252
- // the meaning if searching line by line. This is Oniguruma option `ONIG_OPTION_SINGLELINE`.
1253
- singleline: !1,
1254
- ...e.rules
1255
- }
1256
- };
1257
- return r.target === "auto" && (r.target = L.flagGroups ? "ES2025" : L.unicodeSets ? "ES2024" : "ES2018"), r;
1258
- }
1259
- var Dt = "[ -\r ]", Tt = /* @__PURE__ */ new Set([
1260
- b(304),
1261
- // İ
1262
- b(305)
1263
- // ı
1264
- ]), F = h`[\p{L}\p{M}\p{N}\p{Pc}]`;
1265
- function kr(e) {
1266
- if (Tt.has(e))
1267
- return [e];
1268
- const r = /* @__PURE__ */ new Set(), t = e.toLowerCase(), n = t.toUpperCase(), s = zt.get(t), o = Bt.get(t), a = Vt.get(t);
1269
- return [...n].length === 1 && r.add(n), a && r.add(a), s && r.add(s), r.add(t), o && r.add(o), [...r];
1270
- }
1271
- var Re = /* @__PURE__ */ new Map(
1272
- `C Other
48
+ `.replace(/\s+/g,""),"gsu");function Ft(e){if(!new RegExp(`${ln}\\+`).test(e))return{pattern:e};const n=[];let t=null,r=null,a="",o=0,s;for(Ie.lastIndex=0;s=Ie.exec(e);){const{0:i,index:u,groups:{qBase:c,qMod:p,invalidQ:l}}=s;if(i==="[")o||(r=u),o++;else if(i==="]")o?o--:r=null;else if(!o)if(p==="+"&&a&&!a.startsWith("(")){if(l)throw new Error(`Invalid quantifier "${i}"`);let d=-1;if(/^\{\d+\}$/.test(c))e=Nt(e,u+c.length,p,"");else{if(a===")"||a==="]"){const g=a===")"?t:r;if(g===null)throw new Error(`Invalid unmatched "${a}"`);e=`${e.slice(0,g)}(?>${e.slice(g,u)}${c})${e.slice(u+i.length)}`}else e=`${e.slice(0,u-a.length)}(?>${a}${c})${e.slice(u+i.length)}`;d+=4}Ie.lastIndex+=d}else i[0]==="("?n.push(u):i===")"&&(t=n.length?n.pop():null);a=i}return{pattern:e}}const A=String.raw,Ut=A`\\g<(?<gRNameOrNum>[^>&]+)&R=(?<gRDepth>[^>]+)>`,Se=A`\(\?R=(?<rDepth>[^\)]+)\)|${Ut}`,ge=A`\(\?<(?![=!])(?<captureName>[^>]+)>`,pn=A`${ge}|(?<unnamed>\()(?!\?)`,z=new RegExp(A`${ge}|${Se}|\(\?|\\?.`,"gsu"),_e="Cannot use multiple overlapping recursions";function Bt(e,n){const{hiddenCaptures:t,mode:r}={hiddenCaptures:[],mode:"plugin",...n};let a=n?.captureTransfers??new Map;if(!new RegExp(Se,"su").test(e))return{pattern:e,captureTransfers:a,hiddenCaptures:t};if(r==="plugin"&&fe(e,A`\(\?\(DEFINE\)`,$.DEFAULT))throw new Error("DEFINE groups cannot be used with recursion");const o=[],s=fe(e,A`\\[1-9]`,$.DEFAULT),i=new Map,u=[];let c=!1,p=0,l=0,d;for(z.lastIndex=0;d=z.exec(e);){const{0:g,groups:{captureName:f,rDepth:w,gRNameOrNum:y,gRDepth:N}}=d;if(g==="[")p++;else if(p)g==="]"&&p--;else if(w){if(dn(w),c)throw new Error(_e);if(s)throw new Error(`${r==="external"?"Backrefs":"Numbered backrefs"} cannot be used with global recursion`);const v=e.slice(0,d.index),m=e.slice(z.lastIndex);if(fe(m,Se,$.DEFAULT))throw new Error(_e);const k=+w-1;e=fn(v,m,k,!1,t,o,l),a=hn(a,v,k,o.length,0,l);break}else if(y){dn(N);let v=!1;for(const te of u)if(te.name===y||te.num===+y){if(v=!0,te.hasRecursedWithin)throw new Error(_e);break}if(!v)throw new Error(A`Recursive \g cannot be used outside the referenced group "${r==="external"?y:A`\g<${y}&R=${N}>`}"`);const m=i.get(y),k=Rt(e,m);if(s&&fe(k,A`${ge}|\((?!\?)`,$.DEFAULT))throw new Error(`${r==="external"?"Backrefs":"Numbered backrefs"} cannot be used with recursion of capturing groups`);const I=e.slice(m,d.index),D=k.slice(I.length+g.length),S=o.length,H=+N-1,Ge=fn(I,D,H,!0,t,o,l);a=hn(a,I,H,o.length-S,S,l);const Ln=e.slice(0,m),Rn=e.slice(m+k.length);e=`${Ln}${Ge}${Rn}`,z.lastIndex+=Ge.length-g.length-I.length-D.length,u.forEach(te=>te.hasRecursedWithin=!0),c=!0}else if(f)l++,i.set(String(l),z.lastIndex),i.set(f,z.lastIndex),u.push({num:l,name:f});else if(g[0]==="("){const v=g==="(";v&&(l++,i.set(String(l),z.lastIndex)),u.push(v?{num:l}:{})}else g===")"&&u.pop()}return t.push(...o),{pattern:e,captureTransfers:a,hiddenCaptures:t}}function dn(e){const n=`Max depth must be integer between 2 and 100; used ${e}`;if(!/^[1-9]\d*$/.test(e))throw new Error(n);if(e=+e,e<2||e>100)throw new Error(n)}function fn(e,n,t,r,a,o,s){const i=new Set;r&&un(e+n,ge,({groups:{captureName:c}})=>{i.add(c)},$.DEFAULT);const u=[t,r?i:null,a,o,s];return`${e}${gn(`(?:${e}`,"forward",...u)}(?:)${gn(`${n})`,"backward",...u)}${n}`}function gn(e,n,t,r,a,o,s){const i=c=>n==="forward"?c+2:t-c+2-1;let u="";for(let c=0;c<t;c++){const p=i(c);u+=Ae(e,A`${pn}|\\k<(?<backref>[^>]+)>`,({0:l,groups:{captureName:d,unnamed:g,backref:f}})=>{if(f&&r&&!r.has(f))return l;const w=`_$${p}`;if(g||d){const y=s+o.length+1;return o.push(y),Gt(a,y),g?l:`(?<${d}${w}>`}return A`\k<${f}${w}>`},$.DEFAULT)}return u}function Gt(e,n){for(let t=0;t<e.length;t++)e[t]>=n&&e[t]++}function hn(e,n,t,r,a,o){if(e.size&&r){let s=0;un(n,pn,()=>s++,$.DEFAULT);const i=o-s+a,u=new Map;return e.forEach((c,p)=>{const l=(r-s*t)/t,d=s*t,g=p>i+s?p+r:p,f=[];for(const w of c)if(w<=i)f.push(w);else if(w>i+s+l)f.push(w+r);else if(w<=i+s)for(let y=0;y<=t;y++)f.push(w+s*y);else for(let y=0;y<=t;y++)f.push(w+d+l*y);u.set(g,f)}),u}return e}var C=String.fromCodePoint,h=String.raw,M={},he=globalThis.RegExp;M.flagGroups=(()=>{try{new he("(?i:)")}catch{return!1}return!0})(),M.unicodeSets=(()=>{try{new he("[[]]","v")}catch{return!1}return!0})(),M.bugFlagVLiteralHyphenIsRange=M.unicodeSets?(()=>{try{new he(h`[\d\-a]`,"v")}catch{return!0}return!1})():!1,M.bugNestedClassIgnoresNegation=M.unicodeSets&&new he("[[^a]]","v").test("a");function we(e,{enable:n,disable:t}){return{dotAll:!(t!=null&&t.dotAll)&&!!(n!=null&&n.dotAll||e.dotAll),ignoreCase:!(t!=null&&t.ignoreCase)&&!!(n!=null&&n.ignoreCase||e.ignoreCase)}}function ae(e,n,t){return e.has(n)||e.set(n,t),e.get(n)}function Me(e,n){return wn[e]>=wn[n]}function Dt(e,n){if(e==null)throw new Error(n??"Value expected");return e}var wn={ES2025:2025,ES2024:2024,ES2018:2018},Ot={auto:"auto",ES2025:"ES2025",ES2024:"ES2024",ES2018:"ES2018"};function yn(e={}){if({}.toString.call(e)!=="[object Object]")throw new Error("Unexpected options");if(e.target!==void 0&&!Ot[e.target])throw new Error(`Unexpected target "${e.target}"`);const n={accuracy:"default",avoidSubclass:!1,flags:"",global:!1,hasIndices:!1,lazyCompileLength:1/0,target:"auto",verbose:!1,...e,rules:{allowOrphanBackrefs:!1,asciiWordBoundaries:!1,captureGroup:!1,recursionLimit:20,singleline:!1,...e.rules}};return n.target==="auto"&&(n.target=M.flagGroups?"ES2025":M.unicodeSets?"ES2024":"ES2018"),n}var Tt="[ -\r ]",Wt=new Set([C(304),C(305)]),P=h`[\p{L}\p{M}\p{N}\p{Pc}]`;function mn(e){if(Wt.has(e))return[e];const n=new Set,t=e.toLowerCase(),r=t.toUpperCase(),a=jt.get(t),o=zt.get(t),s=Vt.get(t);return[...r].length===1&&n.add(r),s&&n.add(s),a&&n.add(a),n.add(t),o&&n.add(o),[...n]}var Ne=new Map(`C Other
1273
49
  Cc Control cntrl
1274
50
  Cf Format
1275
51
  Cn Unassigned
@@ -1359,1285 +135,7 @@ Uppercase Upper
1359
135
  Variation_Selector VS
1360
136
  White_Space space
1361
137
  XID_Continue XIDC
1362
- XID_Start XIDS`.split(/\s/).map((e) => [he(e), e])
1363
- ), Bt = /* @__PURE__ */ new Map([
1364
- ["s", b(383)],
1365
- // s, ſ
1366
- [b(383), "s"]
1367
- // ſ, s
1368
- ]), Vt = /* @__PURE__ */ new Map([
1369
- [b(223), b(7838)],
1370
- // ß, ẞ
1371
- [b(107), b(8490)],
1372
- // k, K (Kelvin)
1373
- [b(229), b(8491)],
1374
- // å, Å (Angstrom)
1375
- [b(969), b(8486)]
1376
- // ω, Ω (Ohm)
1377
- ]), zt = new Map([
1378
- U(453),
1379
- U(456),
1380
- U(459),
1381
- U(498),
1382
- ...Ee(8072, 8079),
1383
- ...Ee(8088, 8095),
1384
- ...Ee(8104, 8111),
1385
- U(8124),
1386
- U(8140),
1387
- U(8188)
1388
- ]), Wt = /* @__PURE__ */ new Map([
1389
- ["alnum", h`[\p{Alpha}\p{Nd}]`],
1390
- ["alpha", h`\p{Alpha}`],
1391
- ["ascii", h`\p{ASCII}`],
1392
- ["blank", h`[\p{Zs}\t]`],
1393
- ["cntrl", h`\p{Cc}`],
1394
- ["digit", h`\p{Nd}`],
1395
- ["graph", h`[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]`],
1396
- ["lower", h`\p{Lower}`],
1397
- ["print", h`[[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]\p{Zs}]`],
1398
- ["punct", h`[\p{P}\p{S}]`],
1399
- // Updated value from Onig 6.9.9; changed from Unicode `\p{punct}`
1400
- ["space", h`\p{space}`],
1401
- ["upper", h`\p{Upper}`],
1402
- ["word", h`[\p{Alpha}\p{M}\p{Nd}\p{Pc}]`],
1403
- ["xdigit", h`\p{AHex}`]
1404
- ]);
1405
- function Ht(e, r) {
1406
- const t = [];
1407
- for (let n = e; n <= r; n++)
1408
- t.push(n);
1409
- return t;
1410
- }
1411
- function U(e) {
1412
- const r = b(e);
1413
- return [r.toLowerCase(), r];
1414
- }
1415
- function Ee(e, r) {
1416
- return Ht(e, r).map((t) => U(t));
1417
- }
1418
- var Er = /* @__PURE__ */ new Set([
1419
- "Lower",
1420
- "Lowercase",
1421
- "Upper",
1422
- "Uppercase",
1423
- "Ll",
1424
- "Lowercase_Letter",
1425
- "Lt",
1426
- "Titlecase_Letter",
1427
- "Lu",
1428
- "Uppercase_Letter"
1429
- // The `Changes_When_*` properties (and their aliases) could be included, but they're very rare.
1430
- // Some other properties include a handful of chars with specific cases only, but these chars are
1431
- // generally extreme edge cases and using such properties case insensitively generally produces
1432
- // undesired behavior anyway
1433
- ]);
1434
- function jt(e, r) {
1435
- const t = {
1436
- // A couple edge cases exist where options `accuracy` and `bestEffortTarget` are used:
1437
- // - `CharacterSet` kind `text_segment` (`\X`): An exact representation would require heavy
1438
- // Unicode data; a best-effort approximation requires knowing the target.
1439
- // - `CharacterSet` kind `posix` with values `graph` and `print`: Their complex Unicode
1440
- // representations would be hard to change to ASCII versions after the fact in the generator
1441
- // based on `target`/`accuracy`, so produce the appropriate structure here.
1442
- accuracy: "default",
1443
- asciiWordBoundaries: !1,
1444
- avoidSubclass: !1,
1445
- bestEffortTarget: "ES2025",
1446
- ...r
1447
- };
1448
- $r(e);
1449
- const n = {
1450
- accuracy: t.accuracy,
1451
- asciiWordBoundaries: t.asciiWordBoundaries,
1452
- avoidSubclass: t.avoidSubclass,
1453
- flagDirectivesByAlt: /* @__PURE__ */ new Map(),
1454
- jsGroupNameMap: /* @__PURE__ */ new Map(),
1455
- minTargetEs2024: Ne(t.bestEffortTarget, "ES2024"),
1456
- passedLookbehind: !1,
1457
- strategy: null,
1458
- // Subroutines can appear before the groups they ref, so collect reffed nodes for a second pass
1459
- subroutineRefMap: /* @__PURE__ */ new Map(),
1460
- supportedGNodes: /* @__PURE__ */ new Set(),
1461
- digitIsAscii: e.flags.digitIsAscii,
1462
- spaceIsAscii: e.flags.spaceIsAscii,
1463
- wordIsAscii: e.flags.wordIsAscii
1464
- };
1465
- oe(e, Xt, n);
1466
- const s = {
1467
- dotAll: e.flags.dotAll,
1468
- ignoreCase: e.flags.ignoreCase
1469
- }, o = {
1470
- currentFlags: s,
1471
- prevFlags: null,
1472
- globalFlags: s,
1473
- groupOriginByCopy: /* @__PURE__ */ new Map(),
1474
- groupsByName: /* @__PURE__ */ new Map(),
1475
- multiplexCapturesToLeftByRef: /* @__PURE__ */ new Map(),
1476
- openRefs: /* @__PURE__ */ new Map(),
1477
- reffedNodesByReferencer: /* @__PURE__ */ new Map(),
1478
- subroutineRefMap: n.subroutineRefMap
1479
- };
1480
- oe(e, Zt, o);
1481
- const a = {
1482
- groupsByName: o.groupsByName,
1483
- highestOrphanBackref: 0,
1484
- numCapturesToLeft: 0,
1485
- reffedNodesByReferencer: o.reffedNodesByReferencer
1486
- };
1487
- return oe(e, Qt, a), e._originMap = o.groupOriginByCopy, e._strategy = n.strategy, e;
1488
- }
1489
- var Xt = {
1490
- AbsenceFunction({ node: e, parent: r, replaceWith: t }) {
1491
- const { body: n, kind: s } = e;
1492
- if (s === "repeater") {
1493
- const o = N();
1494
- o.body[0].body.push(
1495
- // Insert own alts as `body`
1496
- H({ negate: !0, body: n }),
1497
- ee("Any")
1498
- );
1499
- const a = N();
1500
- a.body[0].body.push(
1501
- hr("greedy", 0, 1 / 0, o)
1502
- ), t(C(a, r), { traverse: !0 });
1503
- } else
1504
- throw new Error('Unsupported absence function "(?~|"');
1505
- },
1506
- Alternative: {
1507
- enter({ node: e, parent: r, key: t }, { flagDirectivesByAlt: n }) {
1508
- const s = e.body.filter((o) => o.kind === "flags");
1509
- for (let o = t + 1; o < r.body.length; o++) {
1510
- const a = r.body[o];
1511
- ae(n, a, []).push(...s);
1512
- }
1513
- },
1514
- exit({ node: e }, { flagDirectivesByAlt: r }) {
1515
- var t;
1516
- if ((t = r.get(e)) != null && t.length) {
1517
- const n = Ir(r.get(e));
1518
- if (n) {
1519
- const s = N({ flags: n });
1520
- s.body[0].body = e.body, e.body = [C(s, e)];
1521
- }
1522
- }
1523
- }
1524
- },
1525
- Assertion({ node: e, parent: r, key: t, container: n, root: s, remove: o, replaceWith: a }, i) {
1526
- const { kind: u, negate: c } = e, { asciiWordBoundaries: p, avoidSubclass: l, supportedGNodes: f, wordIsAscii: g } = i;
1527
- if (u === "text_segment_boundary")
1528
- throw new Error(`Unsupported text segment boundary "\\${c ? "Y" : "y"}"`);
1529
- if (u === "line_end")
1530
- a(C(H({ body: [
1531
- Q({ body: [Se("string_end")] }),
1532
- Q({ body: [ge(10)] })
1533
- // `\n`
1534
- ] }), r));
1535
- else if (u === "line_start")
1536
- a(C(G(h`(?<=\A|\n(?!\z))`, { skipLookbehindValidation: !0 }), r));
1537
- else if (u === "search_start")
1538
- if (f.has(e))
1539
- s.flags.sticky = !0, o();
1540
- else {
1541
- const d = n[t - 1];
1542
- if (d && rn(d))
1543
- a(C(H({ negate: !0 }), r));
1544
- else {
1545
- if (l)
1546
- throw new Error(h`Uses "\G" in a way that requires a subclass`);
1547
- a(O(Se("string_start"), r)), i.strategy = "clip_search";
1548
- }
1549
- }
1550
- else if (!(u === "string_end" || u === "string_start")) if (u === "string_end_newline")
1551
- a(C(G(h`(?=\n?\z)`), r));
1552
- else if (u === "word_boundary") {
1553
- if (!g && !p) {
1554
- const d = `(?:(?<=${F})(?!${F})|(?<!${F})(?=${F}))`, w = `(?:(?<=${F})(?=${F})|(?<!${F})(?!${F}))`;
1555
- a(C(G(c ? w : d), r));
1556
- }
1557
- } else
1558
- throw new Error(`Unexpected assertion kind "${u}"`);
1559
- },
1560
- Backreference({ node: e }, { jsGroupNameMap: r }) {
1561
- let { ref: t } = e;
1562
- typeof t == "string" && !Ae(t) && (t = $e(t, r), e.ref = t);
1563
- },
1564
- CapturingGroup({ node: e }, { jsGroupNameMap: r, subroutineRefMap: t }) {
1565
- let { name: n } = e;
1566
- n && !Ae(n) && (n = $e(n, r), e.name = n), t.set(e.number, e), n && t.set(n, e);
1567
- },
1568
- CharacterClassRange({ node: e, parent: r, replaceWith: t }) {
1569
- if (r.kind === "intersection") {
1570
- const n = fe({ body: [e] });
1571
- t(C(n, r), { traverse: !0 });
1572
- }
1573
- },
1574
- CharacterSet({ node: e, parent: r, replaceWith: t }, { accuracy: n, minTargetEs2024: s, digitIsAscii: o, spaceIsAscii: a, wordIsAscii: i }) {
1575
- const { kind: u, negate: c, value: p } = e;
1576
- if (o && (u === "digit" || p === "digit")) {
1577
- t(O(_e("digit", { negate: c }), r));
1578
- return;
1579
- }
1580
- if (a && (u === "space" || p === "space")) {
1581
- t(C(Ie(G(Dt), c), r));
1582
- return;
1583
- }
1584
- if (i && (u === "word" || p === "word")) {
1585
- t(O(_e("word", { negate: c }), r));
1586
- return;
1587
- }
1588
- if (u === "any")
1589
- t(O(ee("Any"), r));
1590
- else if (u === "digit")
1591
- t(O(ee("Nd", { negate: c }), r));
1592
- else if (u !== "dot") if (u === "text_segment") {
1593
- if (n === "strict")
1594
- throw new Error(h`Use of "\X" requires non-strict accuracy`);
1595
- const l = "\\p{Emoji}(?:\\p{EMod}|\\uFE0F\\u20E3?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})?", f = h`\p{RI}{2}|${l}(?:\u200D${l})*`;
1596
- t(C(G(
1597
- // Close approximation of an extended grapheme cluster; see <unicode.org/reports/tr29/>
1598
- h`(?>\r\n|${s ? h`\p{RGI_Emoji}` : f}|\P{M}\p{M}*)`,
1599
- // Allow JS property `RGI_Emoji` through
1600
- { skipPropertyNameValidation: !0 }
1601
- ), r));
1602
- } else if (u === "hex")
1603
- t(O(ee("AHex", { negate: c }), r));
1604
- else if (u === "newline")
1605
- t(C(G(c ? `[^
1606
- ]` : `(?>\r
138
+ XID_Start XIDS`.split(/\s/).map(e=>[pe(e),e])),zt=new Map([["s",C(383)],[C(383),"s"]]),Vt=new Map([[C(223),C(7838)],[C(107),C(8490)],[C(229),C(8491)],[C(969),C(8486)]]),jt=new Map([U(453),U(456),U(459),U(498),...Le(8072,8079),...Le(8088,8095),...Le(8104,8111),U(8124),U(8140),U(8188)]),Ht=new Map([["alnum",h`[\p{Alpha}\p{Nd}]`],["alpha",h`\p{Alpha}`],["ascii",h`\p{ASCII}`],["blank",h`[\p{Zs}\t]`],["cntrl",h`\p{Cc}`],["digit",h`\p{Nd}`],["graph",h`[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]`],["lower",h`\p{Lower}`],["print",h`[[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]\p{Zs}]`],["punct",h`[\p{P}\p{S}]`],["space",h`\p{space}`],["upper",h`\p{Upper}`],["word",h`[\p{Alpha}\p{M}\p{Nd}\p{Pc}]`],["xdigit",h`\p{AHex}`]]);function Xt(e,n){const t=[];for(let r=e;r<=n;r++)t.push(r);return t}function U(e){const n=C(e);return[n.toLowerCase(),n]}function Le(e,n){return Xt(e,n).map(t=>U(t))}var bn=new Set(["Lower","Lowercase","Upper","Uppercase","Ll","Lowercase_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter"]);function Zt(e,n){const t={accuracy:"default",asciiWordBoundaries:!1,avoidSubclass:!1,bestEffortTarget:"ES2025",...n};Cn(e);const r={accuracy:t.accuracy,asciiWordBoundaries:t.asciiWordBoundaries,avoidSubclass:t.avoidSubclass,flagDirectivesByAlt:new Map,jsGroupNameMap:new Map,minTargetEs2024:Me(t.bestEffortTarget,"ES2024"),passedLookbehind:!1,strategy:null,subroutineRefMap:new Map,supportedGNodes:new Set,digitIsAscii:e.flags.digitIsAscii,spaceIsAscii:e.flags.spaceIsAscii,wordIsAscii:e.flags.wordIsAscii};oe(e,Qt,r);const a={dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},o={currentFlags:a,prevFlags:null,globalFlags:a,groupOriginByCopy:new Map,groupsByName:new Map,multiplexCapturesToLeftByRef:new Map,openRefs:new Map,reffedNodesByReferencer:new Map,subroutineRefMap:r.subroutineRefMap};oe(e,qt,o);const s={groupsByName:o.groupsByName,highestOrphanBackref:0,numCapturesToLeft:0,reffedNodesByReferencer:o.reffedNodesByReferencer};return oe(e,Jt,s),e._originMap=o.groupOriginByCopy,e._strategy=r.strategy,e}var Qt={AbsenceFunction({node:e,parent:n,replaceWith:t}){const{body:r,kind:a}=e;if(a==="repeater"){const o=_();o.body[0].body.push(W({negate:!0,body:r}),J("Any"));const s=_();s.body[0].body.push(en("greedy",0,1/0,o)),t(b(s,n),{traverse:!0})}else throw new Error('Unsupported absence function "(?~|"')},Alternative:{enter({node:e,parent:n,key:t},{flagDirectivesByAlt:r}){const a=e.body.filter(o=>o.kind==="flags");for(let o=t+1;o<n.body.length;o++){const s=n.body[o];ae(r,s,[]).push(...a)}},exit({node:e},{flagDirectivesByAlt:n}){var t;if((t=n.get(e))!=null&&t.length){const r=En(n.get(e));if(r){const a=_({flags:r});a.body[0].body=e.body,e.body=[b(a,e)]}}}},Assertion({node:e,parent:n,key:t,container:r,root:a,remove:o,replaceWith:s},i){const{kind:u,negate:c}=e,{asciiWordBoundaries:p,avoidSubclass:l,supportedGNodes:d,wordIsAscii:g}=i;if(u==="text_segment_boundary")throw new Error(`Unsupported text segment boundary "\\${c?"Y":"y"}"`);if(u==="line_end")s(b(W({body:[T({body:[Ee("string_end")]}),T({body:[ce(10)]})]}),n));else if(u==="line_start")s(b(F(h`(?<=\A|\n(?!\z))`,{skipLookbehindValidation:!0}),n));else if(u==="search_start")if(d.has(e))a.flags.sticky=!0,o();else{const f=r[t-1];if(f&&rr(f))s(b(W({negate:!0}),n));else{if(l)throw new Error(h`Uses "\G" in a way that requires a subclass`);s(B(Ee("string_start"),n)),i.strategy="clip_search"}}else if(!(u==="string_end"||u==="string_start"))if(u==="string_end_newline")s(b(F(h`(?=\n?\z)`),n));else if(u==="word_boundary"){if(!g&&!p){const f=`(?:(?<=${P})(?!${P})|(?<!${P})(?=${P}))`,w=`(?:(?<=${P})(?=${P})|(?<!${P})(?!${P}))`;s(b(F(c?w:f),n))}}else throw new Error(`Unexpected assertion kind "${u}"`)},Backreference({node:e},{jsGroupNameMap:n}){let{ref:t}=e;typeof t=="string"&&!Pe(t)&&(t=Re(t,n),e.ref=t)},CapturingGroup({node:e},{jsGroupNameMap:n,subroutineRefMap:t}){let{name:r}=e;r&&!Pe(r)&&(r=Re(r,n),e.name=r),t.set(e.number,e),r&&t.set(r,e)},CharacterClassRange({node:e,parent:n,replaceWith:t}){if(n.kind==="intersection"){const r=le({body:[e]});t(b(r,n),{traverse:!0})}},CharacterSet({node:e,parent:n,replaceWith:t},{accuracy:r,minTargetEs2024:a,digitIsAscii:o,spaceIsAscii:s,wordIsAscii:i}){const{kind:u,negate:c,value:p}=e;if(o&&(u==="digit"||p==="digit")){t(B($e("digit",{negate:c}),n));return}if(s&&(u==="space"||p==="space")){t(b(Fe(F(Tt),c),n));return}if(i&&(u==="word"||p==="word")){t(B($e("word",{negate:c}),n));return}if(u==="any")t(B(J("Any"),n));else if(u==="digit")t(B(J("Nd",{negate:c}),n));else if(u!=="dot")if(u==="text_segment"){if(r==="strict")throw new Error(h`Use of "\X" requires non-strict accuracy`);const l="\\p{Emoji}(?:\\p{EMod}|\\uFE0F\\u20E3?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})?",d=h`\p{RI}{2}|${l}(?:\u200D${l})*`;t(b(F(h`(?>\r\n|${a?h`\p{RGI_Emoji}`:d}|\P{M}\p{M}*)`,{skipPropertyNameValidation:!0}),n))}else if(u==="hex")t(B(J("AHex",{negate:c}),n));else if(u==="newline")t(b(F(c?`[^
139
+ ]`:`(?>\r
1607
140
  ?|[
1608
- \v\f…\u2028\u2029])`), r));
1609
- else if (u === "posix")
1610
- if (!s && (p === "graph" || p === "print")) {
1611
- if (n === "strict")
1612
- throw new Error(`POSIX class "${p}" requires min target ES2024 or non-strict accuracy`);
1613
- let l = {
1614
- graph: "!-~",
1615
- print: " -~"
1616
- }[p];
1617
- c && (l = `\0-${b(l.codePointAt(0) - 1)}${b(l.codePointAt(2) + 1)}-􏿿`), t(C(G(`[${l}]`), r));
1618
- } else
1619
- t(C(Ie(G(Wt.get(p)), c), r));
1620
- else if (u === "property")
1621
- Re.has(he(p)) || (e.key = "sc");
1622
- else if (u === "space")
1623
- t(O(ee("space", { negate: c }), r));
1624
- else if (u === "word")
1625
- t(C(Ie(G(F), c), r));
1626
- else
1627
- throw new Error(`Unexpected character set kind "${u}"`);
1628
- },
1629
- Directive({ node: e, parent: r, root: t, remove: n, replaceWith: s, removeAllPrevSiblings: o, removeAllNextSiblings: a }) {
1630
- const { kind: i, flags: u } = e;
1631
- if (i === "flags")
1632
- if (!u.enable && !u.disable)
1633
- n();
1634
- else {
1635
- const c = N({ flags: u });
1636
- c.body[0].body = a(), s(C(c, r), { traverse: !0 });
1637
- }
1638
- else if (i === "keep") {
1639
- const c = t.body[0], l = t.body.length === 1 && // Not emulatable if within a `CapturingGroup`
1640
- fr(c, { type: "Group" }) && c.body[0].body.length === 1 ? c.body[0] : t;
1641
- if (r.parent !== l || l.body.length > 1)
1642
- throw new Error(h`Uses "\K" in a way that's unsupported`);
1643
- const f = H({ behind: !0 });
1644
- f.body[0].body = o(), s(C(f, r));
1645
- } else
1646
- throw new Error(`Unexpected directive kind "${i}"`);
1647
- },
1648
- Flags({ node: e, parent: r }) {
1649
- if (e.posixIsAscii)
1650
- throw new Error('Unsupported flag "P"');
1651
- if (e.textSegmentMode === "word")
1652
- throw new Error('Unsupported flag "y{w}"');
1653
- [
1654
- "digitIsAscii",
1655
- // Flag D
1656
- "extended",
1657
- // Flag x
1658
- "posixIsAscii",
1659
- // Flag P
1660
- "spaceIsAscii",
1661
- // Flag S
1662
- "wordIsAscii",
1663
- // Flag W
1664
- "textSegmentMode"
1665
- // Flag y{g} or y{w}
1666
- ].forEach((t) => delete e[t]), Object.assign(e, {
1667
- // JS flag g; no Onig equiv
1668
- global: !1,
1669
- // JS flag d; no Onig equiv
1670
- hasIndices: !1,
1671
- // JS flag m; no Onig equiv but its behavior is always on in Onig. Onig's only line break
1672
- // char is line feed, unlike JS, so this flag isn't used since it would produce inaccurate
1673
- // results (also allows `^` and `$` to be used in the generator for string start and end)
1674
- multiline: !1,
1675
- // JS flag y; no Onig equiv, but used for `\G` emulation
1676
- sticky: e.sticky ?? !1
1677
- // Note: Regex+ doesn't allow explicitly adding flags it handles implicitly, so leave out
1678
- // properties `unicode` (JS flag u) and `unicodeSets` (JS flag v). Keep the existing values
1679
- // for `ignoreCase` (flag i) and `dotAll` (JS flag s, but Onig flag m)
1680
- }), r.options = {
1681
- disable: {
1682
- // Onig uses different rules for flag x than Regex+, so disable the implicit flag
1683
- x: !0,
1684
- // Onig has no flag to control "named capture only" mode but contextually applies its
1685
- // behavior when named capturing is used, so disable Regex+'s implicit flag for it
1686
- n: !0
1687
- },
1688
- force: {
1689
- // Always add flag v because we're generating an AST that relies on it (it enables JS
1690
- // support for Onig features nested classes, intersection, Unicode properties, etc.).
1691
- // However, the generator might disable flag v based on its `target` option
1692
- v: !0
1693
- }
1694
- };
1695
- },
1696
- Group({ node: e }) {
1697
- if (!e.flags)
1698
- return;
1699
- const { enable: r, disable: t } = e.flags;
1700
- r != null && r.extended && delete r.extended, t != null && t.extended && delete t.extended, r != null && r.dotAll && (t != null && t.dotAll) && delete r.dotAll, r != null && r.ignoreCase && (t != null && t.ignoreCase) && delete r.ignoreCase, r && !Object.keys(r).length && delete e.flags.enable, t && !Object.keys(t).length && delete e.flags.disable, !e.flags.enable && !e.flags.disable && delete e.flags;
1701
- },
1702
- LookaroundAssertion({ node: e }, r) {
1703
- const { kind: t } = e;
1704
- t === "lookbehind" && (r.passedLookbehind = !0);
1705
- },
1706
- NamedCallout({ node: e, parent: r, replaceWith: t }) {
1707
- const { kind: n } = e;
1708
- if (n === "fail")
1709
- t(C(H({ negate: !0 }), r));
1710
- else
1711
- throw new Error(`Unsupported named callout "(*${n.toUpperCase()}"`);
1712
- },
1713
- Quantifier({ node: e }) {
1714
- if (e.body.type === "Quantifier") {
1715
- const r = N();
1716
- r.body[0].body.push(e.body), e.body = C(r, e);
1717
- }
1718
- },
1719
- Regex: {
1720
- enter({ node: e }, { supportedGNodes: r }) {
1721
- const t = [];
1722
- let n = !1, s = !1;
1723
- for (const o of e.body)
1724
- if (o.body.length === 1 && o.body[0].kind === "search_start")
1725
- o.body.pop();
1726
- else {
1727
- const a = vr(o.body);
1728
- a ? (n = !0, Array.isArray(a) ? t.push(...a) : t.push(a)) : s = !0;
1729
- }
1730
- n && !s && t.forEach((o) => r.add(o));
1731
- },
1732
- exit(e, { accuracy: r, passedLookbehind: t, strategy: n }) {
1733
- if (r === "strict" && t && n)
1734
- throw new Error(h`Uses "\G" in a way that requires non-strict accuracy`);
1735
- }
1736
- },
1737
- Subroutine({ node: e }, { jsGroupNameMap: r }) {
1738
- let { ref: t } = e;
1739
- typeof t == "string" && !Ae(t) && (t = $e(t, r), e.ref = t);
1740
- }
1741
- }, Zt = {
1742
- Backreference({ node: e }, { multiplexCapturesToLeftByRef: r, reffedNodesByReferencer: t }) {
1743
- const { orphan: n, ref: s } = e;
1744
- n || t.set(e, [...r.get(s).map(({ node: o }) => o)]);
1745
- },
1746
- CapturingGroup: {
1747
- enter({
1748
- node: e,
1749
- parent: r,
1750
- replaceWith: t,
1751
- skip: n
1752
- }, {
1753
- groupOriginByCopy: s,
1754
- groupsByName: o,
1755
- multiplexCapturesToLeftByRef: a,
1756
- openRefs: i,
1757
- reffedNodesByReferencer: u
1758
- }) {
1759
- const c = s.get(e);
1760
- if (c && i.has(e.number)) {
1761
- const l = O(tr(e.number), r);
1762
- u.set(l, i.get(e.number)), t(l);
1763
- return;
1764
- }
1765
- i.set(e.number, e), a.set(e.number, []), e.name && ae(a, e.name, []);
1766
- const p = a.get(e.name ?? e.number);
1767
- for (let l = 0; l < p.length; l++) {
1768
- const f = p[l];
1769
- if (
1770
- // This group is from subroutine expansion, and there's a multiplex value from either the
1771
- // origin node or a prior subroutine expansion group with the same origin
1772
- c === f.node || c && c === f.origin || // This group is not from subroutine expansion, and it comes after a subroutine expansion
1773
- // group that refers to this group
1774
- e === f.origin
1775
- ) {
1776
- p.splice(l, 1);
1777
- break;
1778
- }
1779
- }
1780
- if (a.get(e.number).push({ node: e, origin: c }), e.name && a.get(e.name).push({ node: e, origin: c }), e.name) {
1781
- const l = ae(o, e.name, /* @__PURE__ */ new Map());
1782
- let f = !1;
1783
- if (c)
1784
- f = !0;
1785
- else
1786
- for (const g of l.values())
1787
- if (!g.hasDuplicateNameToRemove) {
1788
- f = !0;
1789
- break;
1790
- }
1791
- o.get(e.name).set(e, { node: e, hasDuplicateNameToRemove: f });
1792
- }
1793
- },
1794
- exit({ node: e }, { openRefs: r }) {
1795
- r.get(e.number) === e && r.delete(e.number);
1796
- }
1797
- },
1798
- Group: {
1799
- enter({ node: e }, r) {
1800
- r.prevFlags = r.currentFlags, e.flags && (r.currentFlags = de(r.currentFlags, e.flags));
1801
- },
1802
- exit(e, r) {
1803
- r.currentFlags = r.prevFlags;
1804
- }
1805
- },
1806
- Subroutine({ node: e, parent: r, replaceWith: t }, n) {
1807
- const { isRecursive: s, ref: o } = e;
1808
- if (s) {
1809
- let p = r;
1810
- for (; (p = p.parent) && !(p.type === "CapturingGroup" && (p.name === o || p.number === o)); )
1811
- ;
1812
- n.reffedNodesByReferencer.set(e, p);
1813
- return;
1814
- }
1815
- const a = n.subroutineRefMap.get(o), i = o === 0, u = i ? tr(0) : (
1816
- // The reffed group might itself contain subroutines, which are expanded during sub-traversal
1817
- Ar(a, n.groupOriginByCopy, null)
1818
- );
1819
- let c = u;
1820
- if (!i) {
1821
- const p = Ir(Kt(
1822
- a,
1823
- (f) => f.type === "Group" && !!f.flags
1824
- )), l = p ? de(n.globalFlags, p) : n.globalFlags;
1825
- qt(l, n.currentFlags) || (c = N({
1826
- flags: Yt(l)
1827
- }), c.body[0].body.push(u));
1828
- }
1829
- t(C(c, r), { traverse: !i });
1830
- }
1831
- }, Qt = {
1832
- Backreference({ node: e, parent: r, replaceWith: t }, n) {
1833
- if (e.orphan) {
1834
- n.highestOrphanBackref = Math.max(n.highestOrphanBackref, e.ref);
1835
- return;
1836
- }
1837
- const o = n.reffedNodesByReferencer.get(e).filter((a) => Jt(a, e));
1838
- if (!o.length)
1839
- t(C(H({ negate: !0 }), r));
1840
- else if (o.length > 1) {
1841
- const a = N({
1842
- atomic: !0,
1843
- body: o.reverse().map((i) => Q({
1844
- body: [ve(i.number)]
1845
- }))
1846
- });
1847
- t(C(a, r));
1848
- } else
1849
- e.ref = o[0].number;
1850
- },
1851
- CapturingGroup({ node: e }, r) {
1852
- e.number = ++r.numCapturesToLeft, e.name && r.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove && delete e.name;
1853
- },
1854
- Regex: {
1855
- exit({ node: e }, r) {
1856
- const t = Math.max(r.highestOrphanBackref - r.numCapturesToLeft, 0);
1857
- for (let n = 0; n < t; n++) {
1858
- const s = gr();
1859
- e.body.at(-1).body.push(s);
1860
- }
1861
- }
1862
- },
1863
- Subroutine({ node: e }, r) {
1864
- !e.isRecursive || e.ref === 0 || (e.ref = r.reffedNodesByReferencer.get(e).number);
1865
- }
1866
- };
1867
- function $r(e) {
1868
- oe(e, {
1869
- "*"({ node: r, parent: t }) {
1870
- r.parent = t;
1871
- }
1872
- });
1873
- }
1874
- function qt(e, r) {
1875
- return e.dotAll === r.dotAll && e.ignoreCase === r.ignoreCase;
1876
- }
1877
- function Jt(e, r) {
1878
- let t = r;
1879
- do {
1880
- if (t.type === "Regex")
1881
- return !1;
1882
- if (t.type === "Alternative")
1883
- continue;
1884
- if (t === e)
1885
- return !1;
1886
- const n = Sr(t.parent);
1887
- for (const s of n) {
1888
- if (s === t)
1889
- break;
1890
- if (s === e || _r(s, e))
1891
- return !0;
1892
- }
1893
- } while (t = t.parent);
1894
- throw new Error("Unexpected path");
1895
- }
1896
- function Ar(e, r, t, n) {
1897
- const s = Array.isArray(e) ? [] : {};
1898
- for (const [o, a] of Object.entries(e))
1899
- o === "parent" ? s.parent = Array.isArray(t) ? n : t : a && typeof a == "object" ? s[o] = Ar(a, r, s, t) : (o === "type" && a === "CapturingGroup" && r.set(s, r.get(e) ?? e), s[o] = a);
1900
- return s;
1901
- }
1902
- function tr(e) {
1903
- const r = wr(e);
1904
- return r.isRecursive = !0, r;
1905
- }
1906
- function Kt(e, r) {
1907
- const t = [];
1908
- for (; e = e.parent; )
1909
- (!r || r(e)) && t.push(e);
1910
- return t;
1911
- }
1912
- function $e(e, r) {
1913
- if (r.has(e))
1914
- return r.get(e);
1915
- const t = `$${r.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug, "_")}`;
1916
- return r.set(e, t), t;
1917
- }
1918
- function Ir(e) {
1919
- const r = ["dotAll", "ignoreCase"], t = { enable: {}, disable: {} };
1920
- return e.forEach(({ flags: n }) => {
1921
- r.forEach((s) => {
1922
- var o, a;
1923
- (o = n.enable) != null && o[s] && (delete t.disable[s], t.enable[s] = !0), (a = n.disable) != null && a[s] && (t.disable[s] = !0);
1924
- });
1925
- }), Object.keys(t.enable).length || delete t.enable, Object.keys(t.disable).length || delete t.disable, t.enable || t.disable ? t : null;
1926
- }
1927
- function Yt({ dotAll: e, ignoreCase: r }) {
1928
- const t = {};
1929
- return (e || r) && (t.enable = {}, e && (t.enable.dotAll = !0), r && (t.enable.ignoreCase = !0)), (!e || !r) && (t.disable = {}, !e && (t.disable.dotAll = !0), !r && (t.disable.ignoreCase = !0)), t;
1930
- }
1931
- function Sr(e) {
1932
- if (!e)
1933
- throw new Error("Node expected");
1934
- const { body: r } = e;
1935
- return Array.isArray(r) ? r : r ? [r] : null;
1936
- }
1937
- function vr(e) {
1938
- const r = e.find((t) => t.kind === "search_start" || tn(t, { negate: !1 }) || !en(t));
1939
- if (!r)
1940
- return null;
1941
- if (r.kind === "search_start")
1942
- return r;
1943
- if (r.type === "LookaroundAssertion")
1944
- return r.body[0].body[0];
1945
- if (r.type === "CapturingGroup" || r.type === "Group") {
1946
- const t = [];
1947
- for (const n of r.body) {
1948
- const s = vr(n.body);
1949
- if (!s)
1950
- return null;
1951
- Array.isArray(s) ? t.push(...s) : t.push(s);
1952
- }
1953
- return t;
1954
- }
1955
- return null;
1956
- }
1957
- function _r(e, r) {
1958
- const t = Sr(e) ?? [];
1959
- for (const n of t)
1960
- if (n === r || _r(n, r))
1961
- return !0;
1962
- return !1;
1963
- }
1964
- function en({ type: e }) {
1965
- return e === "Assertion" || e === "Directive" || e === "LookaroundAssertion";
1966
- }
1967
- function rn(e) {
1968
- const r = [
1969
- "Character",
1970
- "CharacterClass",
1971
- "CharacterSet"
1972
- ];
1973
- return r.includes(e.type) || e.type === "Quantifier" && e.min && r.includes(e.body.type);
1974
- }
1975
- function tn(e, r) {
1976
- const t = {
1977
- negate: null,
1978
- ...r
1979
- };
1980
- return e.type === "LookaroundAssertion" && (t.negate === null || e.negate === t.negate) && e.body.length === 1 && fr(e.body[0], {
1981
- type: "Assertion",
1982
- kind: "search_start"
1983
- });
1984
- }
1985
- function Ae(e) {
1986
- return /^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e);
1987
- }
1988
- function G(e, r) {
1989
- const n = dr(e, {
1990
- ...r,
1991
- // Providing a custom set of Unicode property names avoids converting some JS Unicode
1992
- // properties (ex: `\p{Alpha}`) to Onig POSIX classes
1993
- unicodePropertyMap: Re
1994
- }).body;
1995
- return n.length > 1 || n[0].body.length > 1 ? N({ body: n }) : n[0].body[0];
1996
- }
1997
- function Ie(e, r) {
1998
- return e.negate = r, e;
1999
- }
2000
- function O(e, r) {
2001
- return e.parent = r, e;
2002
- }
2003
- function C(e, r) {
2004
- return $r(e), e.parent = r, e;
2005
- }
2006
- function nn(e, r) {
2007
- const t = xr(r), n = Ne(t.target, "ES2024"), s = Ne(t.target, "ES2025"), o = t.rules.recursionLimit;
2008
- if (!Number.isInteger(o) || o < 2 || o > 20)
2009
- throw new Error("Invalid recursionLimit; use 2-20");
2010
- let a = null, i = null;
2011
- if (!s) {
2012
- const g = [e.flags.ignoreCase];
2013
- oe(e, sn, {
2014
- getCurrentModI: () => g.at(-1),
2015
- popModI() {
2016
- g.pop();
2017
- },
2018
- pushModI(d) {
2019
- g.push(d);
2020
- },
2021
- setHasCasedChar() {
2022
- g.at(-1) ? a = !0 : i = !0;
2023
- }
2024
- });
2025
- }
2026
- const u = {
2027
- dotAll: e.flags.dotAll,
2028
- // - Turn global flag i on if a case insensitive node was used and no case sensitive nodes were
2029
- // used (to avoid unnecessary node expansion).
2030
- // - Turn global flag i off if a case sensitive node was used (since case sensitivity can't be
2031
- // forced without the use of ES2025 flag groups)
2032
- ignoreCase: !!((e.flags.ignoreCase || a) && !i)
2033
- };
2034
- let c = e;
2035
- const p = {
2036
- accuracy: t.accuracy,
2037
- appliedGlobalFlags: u,
2038
- captureMap: /* @__PURE__ */ new Map(),
2039
- currentFlags: {
2040
- dotAll: e.flags.dotAll,
2041
- ignoreCase: e.flags.ignoreCase
2042
- },
2043
- inCharClass: !1,
2044
- lastNode: c,
2045
- originMap: e._originMap,
2046
- recursionLimit: o,
2047
- useAppliedIgnoreCase: !!(!s && a && i),
2048
- useFlagMods: s,
2049
- useFlagV: n,
2050
- verbose: t.verbose
2051
- };
2052
- function l(g) {
2053
- return p.lastNode = c, c = g, Ut(on[g.type], `Unexpected node type "${g.type}"`)(g, p, l);
2054
- }
2055
- const f = {
2056
- pattern: e.body.map(l).join("|"),
2057
- // Could reset `lastNode` at this point via `lastNode = ast`, but it isn't needed by flags
2058
- flags: l(e.flags),
2059
- options: { ...e.options }
2060
- };
2061
- return n || (delete f.options.force.v, f.options.disable.v = !0, f.options.unicodeSetsPlugin = null), f._captureTransfers = /* @__PURE__ */ new Map(), f._hiddenCaptures = [], p.captureMap.forEach((g, d) => {
2062
- g.hidden && f._hiddenCaptures.push(d), g.transferTo && ae(f._captureTransfers, g.transferTo, []).push(d);
2063
- }), f;
2064
- }
2065
- var sn = {
2066
- "*": {
2067
- enter({ node: e }, r) {
2068
- if (sr(e)) {
2069
- const t = r.getCurrentModI();
2070
- r.pushModI(
2071
- e.flags ? de({ ignoreCase: t }, e.flags).ignoreCase : t
2072
- );
2073
- }
2074
- },
2075
- exit({ node: e }, r) {
2076
- sr(e) && r.popModI();
2077
- }
2078
- },
2079
- Backreference(e, r) {
2080
- r.setHasCasedChar();
2081
- },
2082
- Character({ node: e }, r) {
2083
- Ue(b(e.value)) && r.setHasCasedChar();
2084
- },
2085
- CharacterClassRange({ node: e, skip: r }, t) {
2086
- r(), Mr(e, { firstOnly: !0 }).length && t.setHasCasedChar();
2087
- },
2088
- CharacterSet({ node: e }, r) {
2089
- e.kind === "property" && Er.has(e.value) && r.setHasCasedChar();
2090
- }
2091
- }, on = {
2092
- /**
2093
- @param {AlternativeNode} node
2094
- */
2095
- Alternative({ body: e }, r, t) {
2096
- return e.map(t).join("");
2097
- },
2098
- /**
2099
- @param {AssertionNode} node
2100
- */
2101
- Assertion({ kind: e, negate: r }) {
2102
- if (e === "string_end")
2103
- return "$";
2104
- if (e === "string_start")
2105
- return "^";
2106
- if (e === "word_boundary")
2107
- return r ? h`\B` : h`\b`;
2108
- throw new Error(`Unexpected assertion kind "${e}"`);
2109
- },
2110
- /**
2111
- @param {BackreferenceNode} node
2112
- */
2113
- Backreference({ ref: e }, r) {
2114
- if (typeof e != "number")
2115
- throw new Error("Unexpected named backref in transformed AST");
2116
- if (!r.useFlagMods && r.accuracy === "strict" && r.currentFlags.ignoreCase && !r.captureMap.get(e).ignoreCase)
2117
- throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");
2118
- return "\\" + e;
2119
- },
2120
- /**
2121
- @param {CapturingGroupNode} node
2122
- */
2123
- CapturingGroup(e, r, t) {
2124
- const { body: n, name: s, number: o } = e, a = { ignoreCase: r.currentFlags.ignoreCase }, i = r.originMap.get(e);
2125
- return i && (a.hidden = !0, o > i.number && (a.transferTo = i.number)), r.captureMap.set(o, a), `(${s ? `?<${s}>` : ""}${n.map(t).join("|")})`;
2126
- },
2127
- /**
2128
- @param {CharacterNode} node
2129
- */
2130
- Character({ value: e }, r) {
2131
- const t = b(e), n = K(e, {
2132
- escDigit: r.lastNode.type === "Backreference",
2133
- inCharClass: r.inCharClass,
2134
- useFlagV: r.useFlagV
2135
- });
2136
- if (n !== t)
2137
- return n;
2138
- if (r.useAppliedIgnoreCase && r.currentFlags.ignoreCase && Ue(t)) {
2139
- const s = kr(t);
2140
- return r.inCharClass ? s.join("") : s.length > 1 ? `[${s.join("")}]` : s[0];
2141
- }
2142
- return t;
2143
- },
2144
- /**
2145
- @param {CharacterClassNode} node
2146
- */
2147
- CharacterClass(e, r, t) {
2148
- const { kind: n, negate: s, parent: o } = e;
2149
- let { body: a } = e;
2150
- if (n === "intersection" && !r.useFlagV)
2151
- throw new Error("Use of character class intersection requires min target ES2024");
2152
- L.bugFlagVLiteralHyphenIsRange && r.useFlagV && a.some(or) && (a = [ge(45), ...a.filter((c) => !or(c))]);
2153
- const i = () => `[${s ? "^" : ""}${a.map(t).join(n === "intersection" ? "&&" : "")}]`;
2154
- if (!r.inCharClass) {
2155
- if (
2156
- // Already established `kind !== 'intersection'` if `!state.useFlagV`; don't check again
2157
- (!r.useFlagV || L.bugNestedClassIgnoresNegation) && !s
2158
- ) {
2159
- const p = a.filter(
2160
- (l) => l.type === "CharacterClass" && l.kind === "union" && l.negate
2161
- );
2162
- if (p.length) {
2163
- const l = N(), f = l.body[0];
2164
- return l.parent = o, f.parent = l, a = a.filter((g) => !p.includes(g)), e.body = a, a.length ? (e.parent = f, f.body.push(e)) : l.body.pop(), p.forEach((g) => {
2165
- const d = Q({ body: [g] });
2166
- g.parent = d, d.parent = l, l.body.push(d);
2167
- }), t(l);
2168
- }
2169
- }
2170
- r.inCharClass = !0;
2171
- const c = i();
2172
- return r.inCharClass = !1, c;
2173
- }
2174
- const u = a[0];
2175
- if (
2176
- // Already established that the parent is a char class via `inCharClass`; don't check again
2177
- n === "union" && !s && u && // Allows many nested classes to work with `target` ES2018 which doesn't support nesting
2178
- ((!r.useFlagV || !r.verbose) && o.kind === "union" && !(L.bugFlagVLiteralHyphenIsRange && r.useFlagV) || !r.verbose && o.kind === "intersection" && // JS doesn't allow intersection with union or ranges
2179
- a.length === 1 && u.type !== "CharacterClassRange")
2180
- )
2181
- return a.map(t).join("");
2182
- if (!r.useFlagV && o.type === "CharacterClass")
2183
- throw new Error("Uses nested character class in a way that requires min target ES2024");
2184
- return i();
2185
- },
2186
- /**
2187
- @param {CharacterClassRangeNode} node
2188
- */
2189
- CharacterClassRange(e, r) {
2190
- const t = e.min.value, n = e.max.value, s = {
2191
- escDigit: !1,
2192
- inCharClass: !0,
2193
- useFlagV: r.useFlagV
2194
- }, o = K(t, s), a = K(n, s), i = /* @__PURE__ */ new Set();
2195
- if (r.useAppliedIgnoreCase && r.currentFlags.ignoreCase) {
2196
- const u = Mr(e);
2197
- pn(u).forEach((p) => {
2198
- i.add(
2199
- Array.isArray(p) ? `${K(p[0], s)}-${K(p[1], s)}` : K(p, s)
2200
- );
2201
- });
2202
- }
2203
- return `${o}-${a}${[...i].join("")}`;
2204
- },
2205
- /**
2206
- @param {CharacterSetNode} node
2207
- */
2208
- CharacterSet({ kind: e, negate: r, value: t, key: n }, s) {
2209
- if (e === "dot")
2210
- return s.currentFlags.dotAll ? s.appliedGlobalFlags.dotAll || s.useFlagMods ? "." : "[^]" : (
2211
- // Onig's only line break char is line feed, unlike JS
2212
- h`[^\n]`
2213
- );
2214
- if (e === "digit")
2215
- return r ? h`\D` : h`\d`;
2216
- if (e === "property") {
2217
- if (s.useAppliedIgnoreCase && s.currentFlags.ignoreCase && Er.has(t))
2218
- throw new Error(`Unicode property "${t}" can't be case-insensitive when other chars have specific case`);
2219
- return `${r ? h`\P` : h`\p`}{${n ? `${n}=` : ""}${t}}`;
2220
- }
2221
- if (e === "word")
2222
- return r ? h`\W` : h`\w`;
2223
- throw new Error(`Unexpected character set kind "${e}"`);
2224
- },
2225
- /**
2226
- @param {FlagsNode} node
2227
- */
2228
- Flags(e, r) {
2229
- return (
2230
- // The transformer should never turn on the properties for flags d, g, m since Onig doesn't
2231
- // have equivs. Flag m is never used since Onig uses different line break chars than JS
2232
- // (node.hasIndices ? 'd' : '') +
2233
- // (node.global ? 'g' : '') +
2234
- // (node.multiline ? 'm' : '') +
2235
- (r.appliedGlobalFlags.ignoreCase ? "i" : "") + (e.dotAll ? "s" : "") + (e.sticky ? "y" : "")
2236
- );
2237
- },
2238
- /**
2239
- @param {GroupNode} node
2240
- */
2241
- Group({ atomic: e, body: r, flags: t, parent: n }, s, o) {
2242
- const a = s.currentFlags;
2243
- t && (s.currentFlags = de(a, t));
2244
- const i = r.map(o).join("|"), u = !s.verbose && r.length === 1 && // Single alt
2245
- n.type !== "Quantifier" && !e && (!s.useFlagMods || !t) ? i : `(?${fn(e, t, s.useFlagMods)}${i})`;
2246
- return s.currentFlags = a, u;
2247
- },
2248
- /**
2249
- @param {LookaroundAssertionNode} node
2250
- */
2251
- LookaroundAssertion({ body: e, kind: r, negate: t }, n, s) {
2252
- return `(?${`${r === "lookahead" ? "" : "<"}${t ? "!" : "="}`}${e.map(s).join("|")})`;
2253
- },
2254
- /**
2255
- @param {QuantifierNode} node
2256
- */
2257
- Quantifier(e, r, t) {
2258
- return t(e.body) + dn(e);
2259
- },
2260
- /**
2261
- @param {SubroutineNode & {isRecursive: true}} node
2262
- */
2263
- Subroutine({ isRecursive: e, ref: r }, t) {
2264
- if (!e)
2265
- throw new Error("Unexpected non-recursive subroutine in transformed AST");
2266
- const n = t.recursionLimit;
2267
- return r === 0 ? `(?R=${n})` : h`\g<${r}&R=${n}>`;
2268
- }
2269
- }, an = /* @__PURE__ */ new Set([
2270
- "$",
2271
- "(",
2272
- ")",
2273
- "*",
2274
- "+",
2275
- ".",
2276
- "?",
2277
- "[",
2278
- "\\",
2279
- "]",
2280
- "^",
2281
- "{",
2282
- "|",
2283
- "}"
2284
- ]), un = /* @__PURE__ */ new Set([
2285
- "-",
2286
- "\\",
2287
- "]",
2288
- "^",
2289
- // Literal `[` doesn't require escaping with flag u, but this can help work around regex source
2290
- // linters and regex syntax processors that expect unescaped `[` to create a nested class
2291
- "["
2292
- ]), cn = /* @__PURE__ */ new Set([
2293
- "(",
2294
- ")",
2295
- "-",
2296
- "/",
2297
- "[",
2298
- "\\",
2299
- "]",
2300
- "^",
2301
- "{",
2302
- "|",
2303
- "}",
2304
- // Double punctuators; also includes already-listed `-` and `^`
2305
- "!",
2306
- "#",
2307
- "$",
2308
- "%",
2309
- "&",
2310
- "*",
2311
- "+",
2312
- ",",
2313
- ".",
2314
- ":",
2315
- ";",
2316
- "<",
2317
- "=",
2318
- ">",
2319
- "?",
2320
- "@",
2321
- "`",
2322
- "~"
2323
- ]), nr = /* @__PURE__ */ new Map([
2324
- [9, h`\t`],
2325
- // horizontal tab
2326
- [10, h`\n`],
2327
- // line feed
2328
- [11, h`\v`],
2329
- // vertical tab
2330
- [12, h`\f`],
2331
- // form feed
2332
- [13, h`\r`],
2333
- // carriage return
2334
- [8232, h`\u2028`],
2335
- // line separator
2336
- [8233, h`\u2029`],
2337
- // paragraph separator
2338
- [65279, h`\uFEFF`]
2339
- // ZWNBSP/BOM
2340
- ]), ln = new RegExp("^\\p{Cased}$", "u");
2341
- function Ue(e) {
2342
- return ln.test(e);
2343
- }
2344
- function Mr(e, r) {
2345
- const t = !!(r != null && r.firstOnly), n = e.min.value, s = e.max.value, o = [];
2346
- if (n < 65 && (s === 65535 || s >= 131071) || n === 65536 && s >= 131071)
2347
- return o;
2348
- for (let a = n; a <= s; a++) {
2349
- const i = b(a);
2350
- if (!Ue(i))
2351
- continue;
2352
- const u = kr(i).filter((c) => {
2353
- const p = c.codePointAt(0);
2354
- return p < n || p > s;
2355
- });
2356
- if (u.length && (o.push(...u), t))
2357
- break;
2358
- }
2359
- return o;
2360
- }
2361
- function K(e, { escDigit: r, inCharClass: t, useFlagV: n }) {
2362
- if (nr.has(e))
2363
- return nr.get(e);
2364
- if (
2365
- // Control chars, etc.; condition modeled on the Chrome developer console's display for strings
2366
- e < 32 || e > 126 && e < 160 || // Unicode planes 4-16; unassigned, special purpose, and private use area
2367
- e > 262143 || // Avoid corrupting a preceding backref by immediately following it with a literal digit
2368
- r && gn(e)
2369
- )
2370
- return e > 255 ? `\\u{${e.toString(16).toUpperCase()}}` : `\\x${e.toString(16).toUpperCase().padStart(2, "0")}`;
2371
- const s = t ? n ? cn : un : an, o = b(e);
2372
- return (s.has(o) ? "\\" : "") + o;
2373
- }
2374
- function pn(e) {
2375
- const r = e.map((s) => s.codePointAt(0)).sort((s, o) => s - o), t = [];
2376
- let n = null;
2377
- for (let s = 0; s < r.length; s++)
2378
- r[s + 1] === r[s] + 1 ? n ?? (n = r[s]) : n === null ? t.push(r[s]) : (t.push([n, r[s]]), n = null);
2379
- return t;
2380
- }
2381
- function fn(e, r, t) {
2382
- if (e)
2383
- return ">";
2384
- let n = "";
2385
- if (r && t) {
2386
- const { enable: s, disable: o } = r;
2387
- n = (s != null && s.ignoreCase ? "i" : "") + (s != null && s.dotAll ? "s" : "") + (o ? "-" : "") + (o != null && o.ignoreCase ? "i" : "") + (o != null && o.dotAll ? "s" : "");
2388
- }
2389
- return `${n}:`;
2390
- }
2391
- function dn({ kind: e, max: r, min: t }) {
2392
- let n;
2393
- return !t && r === 1 ? n = "?" : !t && r === 1 / 0 ? n = "*" : t === 1 && r === 1 / 0 ? n = "+" : t === r ? n = `{${t}}` : n = `{${t},${r === 1 / 0 ? "" : r}}`, n + {
2394
- greedy: "",
2395
- lazy: "?",
2396
- possessive: "+"
2397
- }[e];
2398
- }
2399
- function sr({ type: e }) {
2400
- return e === "CapturingGroup" || e === "Group" || e === "LookaroundAssertion";
2401
- }
2402
- function gn(e) {
2403
- return e > 47 && e < 58;
2404
- }
2405
- function or({ type: e, value: r }) {
2406
- return e === "Character" && r === 45;
2407
- }
2408
- var D, P, X, T, Z, ie, Le, B, hn = (B = class extends RegExp {
2409
- /**
2410
- @overload
2411
- @param {string} pattern
2412
- @param {string} [flags]
2413
- @param {EmulatedRegExpOptions} [options]
2414
- */
2415
- /**
2416
- @overload
2417
- @param {EmulatedRegExp} pattern
2418
- @param {string} [flags]
2419
- */
2420
- constructor(t, n, s) {
2421
- var r = (...Sn) => (super(...Sn), z(this, ie), /**
2422
- @type {Map<number, {
2423
- hidden?: true;
2424
- transferTo?: number;
2425
- }>}
2426
- */
2427
- z(this, D, /* @__PURE__ */ new Map()), /**
2428
- @type {RegExp | EmulatedRegExp | null}
2429
- */
2430
- z(this, P, null), /**
2431
- @type {string}
2432
- */
2433
- z(this, X), /**
2434
- @type {Map<number, string>?}
2435
- */
2436
- z(this, T, null), /**
2437
- @type {string?}
2438
- */
2439
- z(this, Z, null), /**
2440
- Can be used to serialize the instance.
2441
- @type {EmulatedRegExpOptions}
2442
- */
2443
- se(this, "rawOptions", {}), this);
2444
- const o = !!(s != null && s.lazyCompile);
2445
- if (t instanceof RegExp) {
2446
- if (s)
2447
- throw new Error("Cannot provide options when copying a regexp");
2448
- const a = t;
2449
- r(a, n), M(this, X, a.source), a instanceof B && (M(this, D, E(a, D)), M(this, T, E(a, T)), M(this, Z, E(a, Z)), this.rawOptions = a.rawOptions);
2450
- } else {
2451
- const a = {
2452
- hiddenCaptures: [],
2453
- strategy: null,
2454
- transfers: [],
2455
- ...s
2456
- };
2457
- r(o ? "" : t, n), M(this, X, t), M(this, D, mn(a.hiddenCaptures, a.transfers)), M(this, Z, a.strategy), this.rawOptions = s ?? {};
2458
- }
2459
- o || M(this, P, this);
2460
- }
2461
- // Override the getter with one that works with lazy-compiled regexes
2462
- get source() {
2463
- return E(this, X) || "(?:)";
2464
- }
2465
- /**
2466
- Called internally by all String/RegExp methods that use regexes.
2467
- @override
2468
- @param {string} str
2469
- @returns {RegExpExecArray?}
2470
- */
2471
- exec(t) {
2472
- if (!E(this, P)) {
2473
- const { lazyCompile: o, ...a } = this.rawOptions;
2474
- M(this, P, new B(E(this, X), this.flags, a));
2475
- }
2476
- const n = this.global || this.sticky, s = this.lastIndex;
2477
- if (E(this, Z) === "clip_search" && n && s) {
2478
- this.lastIndex = 0;
2479
- const o = Ce(this, ie, Le).call(this, t.slice(s));
2480
- return o && (wn(o, s, t, this.hasIndices), this.lastIndex += s), o;
2481
- }
2482
- return Ce(this, ie, Le).call(this, t);
2483
- }
2484
- }, D = new WeakMap(), P = new WeakMap(), X = new WeakMap(), T = new WeakMap(), Z = new WeakMap(), ie = new WeakSet(), /**
2485
- Adds support for hidden and transfer captures.
2486
- @param {string} str
2487
- @returns
2488
- */
2489
- Le = function(t) {
2490
- E(this, P).lastIndex = this.lastIndex;
2491
- const n = Te(B.prototype, this, "exec").call(E(this, P), t);
2492
- if (this.lastIndex = E(this, P).lastIndex, !n || !E(this, D).size)
2493
- return n;
2494
- const s = [...n];
2495
- n.length = 1;
2496
- let o;
2497
- this.hasIndices && (o = [...n.indices], n.indices.length = 1);
2498
- const a = [0];
2499
- for (let i = 1; i < s.length; i++) {
2500
- const { hidden: u, transferTo: c } = E(this, D).get(i) ?? {};
2501
- if (u ? a.push(null) : (a.push(n.length), n.push(s[i]), this.hasIndices && n.indices.push(o[i])), c && s[i] !== void 0) {
2502
- const p = a[c];
2503
- if (!p)
2504
- throw new Error(`Invalid capture transfer to "${p}"`);
2505
- if (n[p] = s[i], this.hasIndices && (n.indices[p] = o[i]), n.groups) {
2506
- E(this, T) || M(this, T, yn(this.source));
2507
- const l = E(this, T).get(c);
2508
- l && (n.groups[l] = s[i], this.hasIndices && (n.indices.groups[l] = o[i]));
2509
- }
2510
- }
2511
- }
2512
- return n;
2513
- }, B);
2514
- function wn(e, r, t, n) {
2515
- if (e.index += r, e.input = t, n) {
2516
- const s = e.indices;
2517
- for (let a = 0; a < s.length; a++) {
2518
- const i = s[a];
2519
- i && (s[a] = [i[0] + r, i[1] + r]);
2520
- }
2521
- const o = s.groups;
2522
- o && Object.keys(o).forEach((a) => {
2523
- const i = o[a];
2524
- i && (o[a] = [i[0] + r, i[1] + r]);
2525
- });
2526
- }
2527
- }
2528
- function mn(e, r) {
2529
- const t = /* @__PURE__ */ new Map();
2530
- for (const n of e)
2531
- t.set(n, {
2532
- hidden: !0
2533
- });
2534
- for (const [n, s] of r)
2535
- for (const o of s)
2536
- ae(t, o, {}).transferTo = n;
2537
- return t;
2538
- }
2539
- function yn(e) {
2540
- const r = /(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu, t = /* @__PURE__ */ new Map();
2541
- let n = 0, s = 0, o;
2542
- for (; o = r.exec(e); ) {
2543
- const { 0: a, groups: { capture: i, name: u } } = o;
2544
- a === "[" ? n++ : n ? a === "]" && n-- : i && (s++, u && t.set(s, u));
2545
- }
2546
- return t;
2547
- }
2548
- function Cn(e, r) {
2549
- const t = bn(e, r);
2550
- return t.options ? new hn(t.pattern, t.flags, t.options) : new RegExp(t.pattern, t.flags);
2551
- }
2552
- function bn(e, r) {
2553
- const t = xr(r), n = dr(e, {
2554
- flags: t.flags,
2555
- normalizeUnknownPropertyNames: !0,
2556
- rules: {
2557
- captureGroup: t.rules.captureGroup,
2558
- singleline: t.rules.singleline
2559
- },
2560
- skipBackrefValidation: t.rules.allowOrphanBackrefs,
2561
- unicodePropertyMap: Re
2562
- }), s = jt(n, {
2563
- accuracy: t.accuracy,
2564
- asciiWordBoundaries: t.rules.asciiWordBoundaries,
2565
- avoidSubclass: t.avoidSubclass,
2566
- bestEffortTarget: t.target
2567
- }), o = nn(s, t), a = Pt(o.pattern, {
2568
- captureTransfers: o._captureTransfers,
2569
- hiddenCaptures: o._hiddenCaptures,
2570
- mode: "external"
2571
- }), i = Ft(a.pattern), u = Lt(i.pattern, {
2572
- captureTransfers: a.captureTransfers,
2573
- hiddenCaptures: a.hiddenCaptures
2574
- }), c = {
2575
- pattern: u.pattern,
2576
- flags: `${t.hasIndices ? "d" : ""}${t.global ? "g" : ""}${o.flags}${o.options.disable.v ? "u" : "v"}`
2577
- };
2578
- if (t.avoidSubclass) {
2579
- if (t.lazyCompileLength !== 1 / 0)
2580
- throw new Error("Lazy compilation requires subclass");
2581
- } else {
2582
- const p = u.hiddenCaptures.sort((d, w) => d - w), l = Array.from(u.captureTransfers), f = s._strategy, g = c.pattern.length >= t.lazyCompileLength;
2583
- (p.length || l.length || f || g) && (c.options = {
2584
- ...p.length && { hiddenCaptures: p },
2585
- ...l.length && { transfers: l },
2586
- ...f && { strategy: f },
2587
- ...g && { lazyCompile: g }
2588
- });
2589
- }
2590
- return c;
2591
- }
2592
- function xn(e, r) {
2593
- return Cn(e, {
2594
- global: !0,
2595
- hasIndices: !0,
2596
- lazyCompileLength: 3e3,
2597
- rules: {
2598
- allowOrphanBackrefs: !0,
2599
- asciiWordBoundaries: !0,
2600
- captureGroup: !0,
2601
- recursionLimit: 5,
2602
- singleline: !0
2603
- },
2604
- ...r
2605
- });
2606
- }
2607
- function En(e = {}) {
2608
- const r = {
2609
- target: "auto",
2610
- cache: /* @__PURE__ */ new Map(),
2611
- ...e
2612
- };
2613
- return r.regexConstructor || (r.regexConstructor = (t) => xn(t, { target: r.target })), {
2614
- createScanner(t) {
2615
- return new ar(t, r);
2616
- },
2617
- createString(t) {
2618
- return { content: t };
2619
- }
2620
- };
2621
- }
2622
- function $n() {
2623
- const e = {
2624
- cache: /* @__PURE__ */ new Map(),
2625
- regexConstructor: () => {
2626
- throw new Error("JavaScriptRawEngine: only support precompiled grammar");
2627
- }
2628
- };
2629
- return {
2630
- createScanner(r) {
2631
- return new ar(r, e);
2632
- },
2633
- createString(r) {
2634
- return { content: r };
2635
- }
2636
- };
2637
- }
2638
- export {
2639
- ar as JavaScriptScanner,
2640
- $n as createJavaScriptRawEngine,
2641
- En as createJavaScriptRegexEngine,
2642
- xn as defaultJavaScriptRegexConstructor
2643
- };
141
+ \v\f\x85\u2028\u2029])`),n));else if(u==="posix")if(!a&&(p==="graph"||p==="print")){if(r==="strict")throw new Error(`POSIX class "${p}" requires min target ES2024 or non-strict accuracy`);let l={graph:"!-~",print:" -~"}[p];c&&(l=`\0-${C(l.codePointAt(0)-1)}${C(l.codePointAt(2)+1)}-\u{10FFFF}`),t(b(F(`[${l}]`),n))}else t(b(Fe(F(Ht.get(p)),c),n));else if(u==="property")Ne.has(pe(p))||(e.key="sc");else if(u==="space")t(B(J("space",{negate:c}),n));else if(u==="word")t(b(Fe(F(P),c),n));else throw new Error(`Unexpected character set kind "${u}"`)},Directive({node:e,parent:n,root:t,remove:r,replaceWith:a,removeAllPrevSiblings:o,removeAllNextSiblings:s}){const{kind:i,flags:u}=e;if(i==="flags")if(!u.enable&&!u.disable)r();else{const c=_({flags:u});c.body[0].body=s(),a(b(c,n),{traverse:!0})}else if(i==="keep"){const c=t.body[0],p=t.body.length===1&&Je(c,{type:"Group"})&&c.body[0].body.length===1?c.body[0]:t;if(n.parent!==p||p.body.length>1)throw new Error(h`Uses "\K" in a way that's unsupported`);const l=W({behind:!0});l.body[0].body=o(),a(b(l,n))}else throw new Error(`Unexpected directive kind "${i}"`)},Flags({node:e,parent:n}){if(e.posixIsAscii)throw new Error('Unsupported flag "P"');if(e.textSegmentMode==="word")throw new Error('Unsupported flag "y{w}"');["digitIsAscii","extended","posixIsAscii","spaceIsAscii","wordIsAscii","textSegmentMode"].forEach(t=>delete e[t]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),n.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;const{enable:n,disable:t}=e.flags;n!=null&&n.extended&&delete n.extended,t!=null&&t.extended&&delete t.extended,n!=null&&n.dotAll&&t!=null&&t.dotAll&&delete n.dotAll,n!=null&&n.ignoreCase&&t!=null&&t.ignoreCase&&delete n.ignoreCase,n&&!Object.keys(n).length&&delete e.flags.enable,t&&!Object.keys(t).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},LookaroundAssertion({node:e},n){const{kind:t}=e;t==="lookbehind"&&(n.passedLookbehind=!0)},NamedCallout({node:e,parent:n,replaceWith:t}){const{kind:r}=e;if(r==="fail")t(b(W({negate:!0}),n));else throw new Error(`Unsupported named callout "(*${r.toUpperCase()}"`)},Quantifier({node:e}){if(e.body.type==="Quantifier"){const n=_();n.body[0].body.push(e.body),e.body=b(n,e)}},Regex:{enter({node:e},{supportedGNodes:n}){const t=[];let r=!1,a=!1;for(const o of e.body)if(o.body.length===1&&o.body[0].kind==="search_start")o.body.pop();else{const s=$n(o.body);s?(r=!0,Array.isArray(s)?t.push(...s):t.push(s)):a=!0}r&&!a&&t.forEach(o=>n.add(o))},exit(e,{accuracy:n,passedLookbehind:t,strategy:r}){if(n==="strict"&&t&&r)throw new Error(h`Uses "\G" in a way that requires non-strict accuracy`)}},Subroutine({node:e},{jsGroupNameMap:n}){let{ref:t}=e;typeof t=="string"&&!Pe(t)&&(t=Re(t,n),e.ref=t)}},qt={Backreference({node:e},{multiplexCapturesToLeftByRef:n,reffedNodesByReferencer:t}){const{orphan:r,ref:a}=e;r||t.set(e,[...n.get(a).map(({node:o})=>o)])},CapturingGroup:{enter({node:e,parent:n,replaceWith:t,skip:r},{groupOriginByCopy:a,groupsByName:o,multiplexCapturesToLeftByRef:s,openRefs:i,reffedNodesByReferencer:u}){const c=a.get(e);if(c&&i.has(e.number)){const l=B(kn(e.number),n);u.set(l,i.get(e.number)),t(l);return}i.set(e.number,e),s.set(e.number,[]),e.name&&ae(s,e.name,[]);const p=s.get(e.name??e.number);for(let l=0;l<p.length;l++){const d=p[l];if(c===d.node||c&&c===d.origin||e===d.origin){p.splice(l,1);break}}if(s.get(e.number).push({node:e,origin:c}),e.name&&s.get(e.name).push({node:e,origin:c}),e.name){const l=ae(o,e.name,new Map);let d=!1;if(c)d=!0;else for(const g of l.values())if(!g.hasDuplicateNameToRemove){d=!0;break}o.get(e.name).set(e,{node:e,hasDuplicateNameToRemove:d})}},exit({node:e},{openRefs:n}){n.get(e.number)===e&&n.delete(e.number)}},Group:{enter({node:e},n){n.prevFlags=n.currentFlags,e.flags&&(n.currentFlags=we(n.currentFlags,e.flags))},exit(e,n){n.currentFlags=n.prevFlags}},Subroutine({node:e,parent:n,replaceWith:t},r){const{isRecursive:a,ref:o}=e;if(a){let p=n;for(;(p=p.parent)&&!(p.type==="CapturingGroup"&&(p.name===o||p.number===o)););r.reffedNodesByReferencer.set(e,p);return}const s=r.subroutineRefMap.get(o),i=o===0,u=i?kn(0):xn(s,r.groupOriginByCopy,null);let c=u;if(!i){const p=En(er(s,d=>d.type==="Group"&&!!d.flags)),l=p?we(r.globalFlags,p):r.globalFlags;Kt(l,r.currentFlags)||(c=_({flags:nr(l)}),c.body[0].body.push(u))}t(b(c,n),{traverse:!i})}},Jt={Backreference({node:e,parent:n,replaceWith:t},r){if(e.orphan){r.highestOrphanBackref=Math.max(r.highestOrphanBackref,e.ref);return}const a=r.reffedNodesByReferencer.get(e).filter(o=>Yt(o,e));if(!a.length)t(b(W({negate:!0}),n));else if(a.length>1){const o=_({atomic:!0,body:a.reverse().map(s=>T({body:[ve(s.number)]}))});t(b(o,n))}else e.ref=a[0].number},CapturingGroup({node:e},n){e.number=++n.numCapturesToLeft,e.name&&n.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Regex:{exit({node:e},n){const t=Math.max(n.highestOrphanBackref-n.numCapturesToLeft,0);for(let r=0;r<t;r++){const a=Ye();e.body.at(-1).body.push(a)}}},Subroutine({node:e},n){!e.isRecursive||e.ref===0||(e.ref=n.reffedNodesByReferencer.get(e).number)}};function Cn(e){oe(e,{"*"({node:n,parent:t}){n.parent=t}})}function Kt(e,n){return e.dotAll===n.dotAll&&e.ignoreCase===n.ignoreCase}function Yt(e,n){let t=n;do{if(t.type==="Regex")return!1;if(t.type==="Alternative")continue;if(t===e)return!1;const r=vn(t.parent);for(const a of r){if(a===t)break;if(a===e||An(a,e))return!0}}while(t=t.parent);throw new Error("Unexpected path")}function xn(e,n,t,r){const a=Array.isArray(e)?[]:{};for(const[o,s]of Object.entries(e))o==="parent"?a.parent=Array.isArray(t)?r:t:s&&typeof s=="object"?a[o]=xn(s,n,a,t):(o==="type"&&s==="CapturingGroup"&&n.set(a,n.get(e)??e),a[o]=s);return a}function kn(e){const n=nn(e);return n.isRecursive=!0,n}function er(e,n){const t=[];for(;e=e.parent;)(!n||n(e))&&t.push(e);return t}function Re(e,n){if(n.has(e))return n.get(e);const t=`$${n.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug,"_")}`;return n.set(e,t),t}function En(e){const n=["dotAll","ignoreCase"],t={enable:{},disable:{}};return e.forEach(({flags:r})=>{n.forEach(a=>{var o,s;(o=r.enable)!=null&&o[a]&&(delete t.disable[a],t.enable[a]=!0),(s=r.disable)!=null&&s[a]&&(t.disable[a]=!0)})}),Object.keys(t.enable).length||delete t.enable,Object.keys(t.disable).length||delete t.disable,t.enable||t.disable?t:null}function nr({dotAll:e,ignoreCase:n}){const t={};return(e||n)&&(t.enable={},e&&(t.enable.dotAll=!0),n&&(t.enable.ignoreCase=!0)),(!e||!n)&&(t.disable={},!e&&(t.disable.dotAll=!0),!n&&(t.disable.ignoreCase=!0)),t}function vn(e){if(!e)throw new Error("Node expected");const{body:n}=e;return Array.isArray(n)?n:n?[n]:null}function $n(e){const n=e.find(t=>t.kind==="search_start"||or(t,{negate:!1})||!tr(t));if(!n)return null;if(n.kind==="search_start")return n;if(n.type==="LookaroundAssertion")return n.body[0].body[0];if(n.type==="CapturingGroup"||n.type==="Group"){const t=[];for(const r of n.body){const a=$n(r.body);if(!a)return null;Array.isArray(a)?t.push(...a):t.push(a)}return t}return null}function An(e,n){const t=vn(e)??[];for(const r of t)if(r===n||An(r,n))return!0;return!1}function tr({type:e}){return e==="Assertion"||e==="Directive"||e==="LookaroundAssertion"}function rr(e){const n=["Character","CharacterClass","CharacterSet"];return n.includes(e.type)||e.type==="Quantifier"&&e.min&&n.includes(e.body.type)}function or(e,n){const t={negate:null,...n};return e.type==="LookaroundAssertion"&&(t.negate===null||e.negate===t.negate)&&e.body.length===1&&Je(e.body[0],{type:"Assertion",kind:"search_start"})}function Pe(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function F(e,n){const t=Ke(e,{...n,unicodePropertyMap:Ne}).body;return t.length>1||t[0].body.length>1?_({body:t}):t[0].body[0]}function Fe(e,n){return e.negate=n,e}function B(e,n){return e.parent=n,e}function b(e,n){return Cn(e),e.parent=n,e}function ar(e,n){const t=yn(n),r=Me(t.target,"ES2024"),a=Me(t.target,"ES2025"),o=t.rules.recursionLimit;if(!Number.isInteger(o)||o<2||o>20)throw new Error("Invalid recursionLimit; use 2-20");let s=null,i=null;if(!a){const g=[e.flags.ignoreCase];oe(e,sr,{getCurrentModI:()=>g.at(-1),popModI(){g.pop()},pushModI(f){g.push(f)},setHasCasedChar(){g.at(-1)?s=!0:i=!0}})}const u={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||s)&&!i)};let c=e;const p={accuracy:t.accuracy,appliedGlobalFlags:u,captureMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},inCharClass:!1,lastNode:c,originMap:e._originMap,recursionLimit:o,useAppliedIgnoreCase:!!(!a&&s&&i),useFlagMods:a,useFlagV:r,verbose:t.verbose};function l(g){return p.lastNode=c,c=g,Dt(ir[g.type],`Unexpected node type "${g.type}"`)(g,p,l)}const d={pattern:e.body.map(l).join("|"),flags:l(e.flags),options:{...e.options}};return r||(delete d.options.force.v,d.options.disable.v=!0,d.options.unicodeSetsPlugin=null),d._captureTransfers=new Map,d._hiddenCaptures=[],p.captureMap.forEach((g,f)=>{g.hidden&&d._hiddenCaptures.push(f),g.transferTo&&ae(d._captureTransfers,g.transferTo,[]).push(f)}),d}var sr={"*":{enter({node:e},n){if(_n(e)){const t=n.getCurrentModI();n.pushModI(e.flags?we({ignoreCase:t},e.flags).ignoreCase:t)}},exit({node:e},n){_n(e)&&n.popModI()}},Backreference(e,n){n.setHasCasedChar()},Character({node:e},n){Ue(C(e.value))&&n.setHasCasedChar()},CharacterClassRange({node:e,skip:n},t){n(),Sn(e,{firstOnly:!0}).length&&t.setHasCasedChar()},CharacterSet({node:e},n){e.kind==="property"&&bn.has(e.value)&&n.setHasCasedChar()}},ir={Alternative({body:e},n,t){return e.map(t).join("")},Assertion({kind:e,negate:n}){if(e==="string_end")return"$";if(e==="string_start")return"^";if(e==="word_boundary")return n?h`\B`:h`\b`;throw new Error(`Unexpected assertion kind "${e}"`)},Backreference({ref:e},n){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!n.useFlagMods&&n.accuracy==="strict"&&n.currentFlags.ignoreCase&&!n.captureMap.get(e).ignoreCase)throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");return"\\"+e},CapturingGroup(e,n,t){const{body:r,name:a,number:o}=e,s={ignoreCase:n.currentFlags.ignoreCase},i=n.originMap.get(e);return i&&(s.hidden=!0,o>i.number&&(s.transferTo=i.number)),n.captureMap.set(o,s),`(${a?`?<${a}>`:""}${r.map(t).join("|")})`},Character({value:e},n){const t=C(e),r=Y(e,{escDigit:n.lastNode.type==="Backreference",inCharClass:n.inCharClass,useFlagV:n.useFlagV});if(r!==t)return r;if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase&&Ue(t)){const a=mn(t);return n.inCharClass?a.join(""):a.length>1?`[${a.join("")}]`:a[0]}return t},CharacterClass(e,n,t){const{kind:r,negate:a,parent:o}=e;let{body:s}=e;if(r==="intersection"&&!n.useFlagV)throw new Error("Use of character class intersection requires min target ES2024");M.bugFlagVLiteralHyphenIsRange&&n.useFlagV&&s.some(Mn)&&(s=[ce(45),...s.filter(c=>!Mn(c))]);const i=()=>`[${a?"^":""}${s.map(t).join(r==="intersection"?"&&":"")}]`;if(!n.inCharClass){if((!n.useFlagV||M.bugNestedClassIgnoresNegation)&&!a){const p=s.filter(l=>l.type==="CharacterClass"&&l.kind==="union"&&l.negate);if(p.length){const l=_(),d=l.body[0];return l.parent=o,d.parent=l,s=s.filter(g=>!p.includes(g)),e.body=s,s.length?(e.parent=d,d.body.push(e)):l.body.pop(),p.forEach(g=>{const f=T({body:[g]});g.parent=f,f.parent=l,l.body.push(f)}),t(l)}}n.inCharClass=!0;const c=i();return n.inCharClass=!1,c}const u=s[0];if(r==="union"&&!a&&u&&((!n.useFlagV||!n.verbose)&&o.kind==="union"&&!(M.bugFlagVLiteralHyphenIsRange&&n.useFlagV)||!n.verbose&&o.kind==="intersection"&&s.length===1&&u.type!=="CharacterClassRange"))return s.map(t).join("");if(!n.useFlagV&&o.type==="CharacterClass")throw new Error("Uses nested character class in a way that requires min target ES2024");return i()},CharacterClassRange(e,n){const t=e.min.value,r=e.max.value,a={escDigit:!1,inCharClass:!0,useFlagV:n.useFlagV},o=Y(t,a),s=Y(r,a),i=new Set;if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase){const u=Sn(e);dr(u).forEach(c=>{i.add(Array.isArray(c)?`${Y(c[0],a)}-${Y(c[1],a)}`:Y(c,a))})}return`${o}-${s}${[...i].join("")}`},CharacterSet({kind:e,negate:n,value:t,key:r},a){if(e==="dot")return a.currentFlags.dotAll?a.appliedGlobalFlags.dotAll||a.useFlagMods?".":"[^]":h`[^\n]`;if(e==="digit")return n?h`\D`:h`\d`;if(e==="property"){if(a.useAppliedIgnoreCase&&a.currentFlags.ignoreCase&&bn.has(t))throw new Error(`Unicode property "${t}" can't be case-insensitive when other chars have specific case`);return`${n?h`\P`:h`\p`}{${r?`${r}=`:""}${t}}`}if(e==="word")return n?h`\W`:h`\w`;throw new Error(`Unexpected character set kind "${e}"`)},Flags(e,n){return(n.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")},Group({atomic:e,body:n,flags:t,parent:r},a,o){const s=a.currentFlags;t&&(a.currentFlags=we(s,t));const i=n.map(o).join("|"),u=!a.verbose&&n.length===1&&r.type!=="Quantifier"&&!e&&(!a.useFlagMods||!t)?i:`(?${fr(e,t,a.useFlagMods)}${i})`;return a.currentFlags=s,u},LookaroundAssertion({body:e,kind:n,negate:t},r,a){return`(?${`${n==="lookahead"?"":"<"}${t?"!":"="}`}${e.map(a).join("|")})`},Quantifier(e,n,t){return t(e.body)+gr(e)},Subroutine({isRecursive:e,ref:n},t){if(!e)throw new Error("Unexpected non-recursive subroutine in transformed AST");const r=t.recursionLimit;return n===0?`(?R=${r})`:h`\g<${n}&R=${r}>`}},ur=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),cr=new Set(["-","\\","]","^","["]),lr=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),In=new Map([[9,h`\t`],[10,h`\n`],[11,h`\v`],[12,h`\f`],[13,h`\r`],[8232,h`\u2028`],[8233,h`\u2029`],[65279,h`\uFEFF`]]),pr=new RegExp("^\\p{Cased}$","u");function Ue(e){return pr.test(e)}function Sn(e,n){const t=!!(n!=null&&n.firstOnly),r=e.min.value,a=e.max.value,o=[];if(r<65&&(a===65535||a>=131071)||r===65536&&a>=131071)return o;for(let s=r;s<=a;s++){const i=C(s);if(!Ue(i))continue;const u=mn(i).filter(c=>{const p=c.codePointAt(0);return p<r||p>a});if(u.length&&(o.push(...u),t))break}return o}function Y(e,{escDigit:n,inCharClass:t,useFlagV:r}){if(In.has(e))return In.get(e);if(e<32||e>126&&e<160||e>262143||n&&hr(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;const a=t?r?lr:cr:ur,o=C(e);return(a.has(o)?"\\":"")+o}function dr(e){const n=e.map(a=>a.codePointAt(0)).sort((a,o)=>a-o),t=[];let r=null;for(let a=0;a<n.length;a++)n[a+1]===n[a]+1?r??(r=n[a]):r===null?t.push(n[a]):(t.push([r,n[a]]),r=null);return t}function fr(e,n,t){if(e)return">";let r="";if(n&&t){const{enable:a,disable:o}=n;r=(a!=null&&a.ignoreCase?"i":"")+(a!=null&&a.dotAll?"s":"")+(o?"-":"")+(o!=null&&o.ignoreCase?"i":"")+(o!=null&&o.dotAll?"s":"")}return`${r}:`}function gr({kind:e,max:n,min:t}){let r;return!t&&n===1?r="?":!t&&n===1/0?r="*":t===1&&n===1/0?r="+":t===n?r=`{${t}}`:r=`{${t},${n===1/0?"":n}}`,r+{greedy:"",lazy:"?",possessive:"+"}[e]}function _n({type:e}){return e==="CapturingGroup"||e==="Group"||e==="LookaroundAssertion"}function hr(e){return e>47&&e<58}function Mn({type:e,value:n}){return e==="Character"&&n===45}var V,G,ee,j,ne,ye,Be,se,wr=(se=class extends RegExp{constructor(e,n,t){var r=(...o)=>(super(...o),X(this,ye),X(this,V,new Map),X(this,G,null),X(this,ee),X(this,j,null),X(this,ne,null),ie(this,"rawOptions",{}),this);const a=!!(t!=null&&t.lazyCompile);if(e instanceof RegExp){if(t)throw new Error("Cannot provide options when copying a regexp");const o=e;r(o,n),L(this,ee,o.source),o instanceof se&&(L(this,V,E(o,V)),L(this,j,E(o,j)),L(this,ne,E(o,ne)),this.rawOptions=o.rawOptions)}else{const o={hiddenCaptures:[],strategy:null,transfers:[],...t};r(a?"":e,n),L(this,ee,e),L(this,V,mr(o.hiddenCaptures,o.transfers)),L(this,ne,o.strategy),this.rawOptions=t??{}}a||L(this,G,this)}get source(){return E(this,ee)||"(?:)"}exec(e){if(!E(this,G)){const{lazyCompile:r,...a}=this.rawOptions;L(this,G,new se(E(this,ee),this.flags,a))}const n=this.global||this.sticky,t=this.lastIndex;if(E(this,ne)==="clip_search"&&n&&t){this.lastIndex=0;const r=Oe(this,ye,Be).call(this,e.slice(t));return r&&(yr(r,t,e,this.hasIndices),this.lastIndex+=t),r}return Oe(this,ye,Be).call(this,e)}},V=new WeakMap,G=new WeakMap,ee=new WeakMap,j=new WeakMap,ne=new WeakMap,ye=new WeakSet,Be=function(e){E(this,G).lastIndex=this.lastIndex;const n=Gn(se.prototype,this,"exec").call(E(this,G),e);if(this.lastIndex=E(this,G).lastIndex,!n||!E(this,V).size)return n;const t=[...n];n.length=1;let r;this.hasIndices&&(r=[...n.indices],n.indices.length=1);const a=[0];for(let o=1;o<t.length;o++){const{hidden:s,transferTo:i}=E(this,V).get(o)??{};if(s?a.push(null):(a.push(n.length),n.push(t[o]),this.hasIndices&&n.indices.push(r[o])),i&&t[o]!==void 0){const u=a[i];if(!u)throw new Error(`Invalid capture transfer to "${u}"`);if(n[u]=t[o],this.hasIndices&&(n.indices[u]=r[o]),n.groups){E(this,j)||L(this,j,br(this.source));const c=E(this,j).get(i);c&&(n.groups[c]=t[o],this.hasIndices&&(n.indices.groups[c]=r[o]))}}}return n},se);function yr(e,n,t,r){if(e.index+=n,e.input=t,r){const a=e.indices;for(let s=0;s<a.length;s++){const i=a[s];i&&(a[s]=[i[0]+n,i[1]+n])}const o=a.groups;o&&Object.keys(o).forEach(s=>{const i=o[s];i&&(o[s]=[i[0]+n,i[1]+n])})}}function mr(e,n){const t=new Map;for(const r of e)t.set(r,{hidden:!0});for(const[r,a]of n)for(const o of a)ae(t,o,{}).transferTo=r;return t}function br(e){const n=/(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu,t=new Map;let r=0,a=0,o;for(;o=n.exec(e);){const{0:s,groups:{capture:i,name:u}}=o;s==="["?r++:r?s==="]"&&r--:i&&(a++,u&&t.set(a,u))}return t}function Cr(e,n){const t=xr(e,n);return t.options?new wr(t.pattern,t.flags,t.options):new RegExp(t.pattern,t.flags)}function xr(e,n){const t=yn(n),r=Ke(e,{flags:t.flags,normalizeUnknownPropertyNames:!0,rules:{captureGroup:t.rules.captureGroup,singleline:t.rules.singleline},skipBackrefValidation:t.rules.allowOrphanBackrefs,unicodePropertyMap:Ne}),a=Zt(r,{accuracy:t.accuracy,asciiWordBoundaries:t.rules.asciiWordBoundaries,avoidSubclass:t.avoidSubclass,bestEffortTarget:t.target}),o=ar(a,t),s=Bt(o.pattern,{captureTransfers:o._captureTransfers,hiddenCaptures:o._hiddenCaptures,mode:"external"}),i=Ft(s.pattern),u=Pt(i.pattern,{captureTransfers:s.captureTransfers,hiddenCaptures:s.hiddenCaptures}),c={pattern:u.pattern,flags:`${t.hasIndices?"d":""}${t.global?"g":""}${o.flags}${o.options.disable.v?"u":"v"}`};if(t.avoidSubclass){if(t.lazyCompileLength!==1/0)throw new Error("Lazy compilation requires subclass")}else{const p=u.hiddenCaptures.sort((f,w)=>f-w),l=Array.from(u.captureTransfers),d=a._strategy,g=c.pattern.length>=t.lazyCompileLength;(p.length||l.length||d||g)&&(c.options={...p.length&&{hiddenCaptures:p},...l.length&&{transfers:l},...d&&{strategy:d},...g&&{lazyCompile:g}})}return c}function Nn(e,n){return Cr(e,{global:!0,hasIndices:!0,lazyCompileLength:3e3,rules:{allowOrphanBackrefs:!0,asciiWordBoundaries:!0,captureGroup:!0,recursionLimit:5,singleline:!0},...n})}function kr(e={}){const n={target:"auto",cache:new Map,...e};return n.regexConstructor||(n.regexConstructor=t=>Nn(t,{target:n.target})),{createScanner(t){return new be(t,n)},createString(t){return{content:t}}}}function Er(){const e={cache:new Map,regexConstructor:()=>{throw new Error("JavaScriptRawEngine: only support precompiled grammar")}};return{createScanner(n){return new be(n,e)},createString(n){return{content:n}}}}export{be as JavaScriptScanner,Er as createJavaScriptRawEngine,kr as createJavaScriptRegexEngine,Nn as defaultJavaScriptRegexConstructor};