oniguruma-to-es
Advanced tools
Comparing version 0.8.1 to 0.9.0
@@ -1,2 +0,92 @@ | ||
var OnigurumaToES=(()=>{var he=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var Pt=Object.prototype.hasOwnProperty;var Nt=(e,t)=>{for(var r in t)he(e,r,{get:t[r],enumerable:!0})},Rt=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Mt(t))!Pt.call(e,n)&&n!==r&&he(e,n,{get:()=>t[n],enumerable:!(s=It(t,n))||s.enumerable});return e};var Ot=e=>Rt(he({},"__esModule",{value:!0}),e);var en={};Nt(en,{EmulatedRegExp:()=>ee,toDetails:()=>vt,toOnigurumaAst:()=>Jr,toRegExp:()=>Yr});var y=String.fromCodePoint,h=String.raw,Oe=(()=>{try{new RegExp("(?<n>)|(?<n>)")}catch{return!1}return!0})(),Ue=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),Te=(()=>{try{new RegExp("","v")}catch{return!1}return!0})();function D(e,{enable:t,disable:r}){return{dotAll:!r?.dotAll&&!!(t?.dotAll||e.dotAll),ignoreCase:!r?.ignoreCase&&!!(t?.ignoreCase||e.ignoreCase)}}function L(e,t,r){return e.has(t)||e.set(t,r),e.get(t)}function W(e,t){return de[e]>=de[t]}function v(e,t){if(!e)throw new Error(t??"Value expected");return e}var de={ES2025:2025,ES2024:2024,ES2018:2018},Ut={auto:"auto",ES2025:"ES2025",ES2024:"ES2024",ES2018:"ES2018"};function re(e){if(e?.target!==void 0&&!Ut[e.target])throw new Error(`Unexpected target "${e.target}"`);let t={accuracy:"default",avoidSubclass:!1,flags:"",global:!1,hasIndices:!1,maxRecursionDepth:5,target:"auto",verbose:!1,...e,rules:{allowOrphanBackrefs:!1,allowUnhandledGAnchors:!1,asciiWordBoundaries:!1,captureGroup:!1,...e?.rules}};return t.target==="auto"&&(t.target=Oe&&Ue?"ES2025":Te?"ES2024":"ES2018"),t}var Tt=new Set([y(304),y(305)]);function me(e){if(Tt.has(e))return[e];let t=new Set,r=e.toLowerCase(),s=r.toUpperCase(),n=Vt.get(r),a=Lt.get(r),o=Bt.get(r);return[...s].length===1&&t.add(s),o&&t.add(o),n&&t.add(n),t.add(r),a&&t.add(a),[...t]}var we=new Set(["C","Other","Cc","Control","cntrl","Cf","Format","Cn","Unassigned","Co","Private_Use","Cs","Surrogate","L","Letter","LC","Cased_Letter","Ll","Lowercase_Letter","Lm","Modifier_Letter","Lo","Other_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter","M","Mark","Combining_Mark","Mc","Spacing_Mark","Me","Enclosing_Mark","Mn","Nonspacing_Mark","N","Number","Nd","Decimal_Number","digit","Nl","Letter_Number","No","Other_Number","P","Punctuation","punct","Pc","Connector_Punctuation","Pd","Dash_Punctuation","Pe","Close_Punctuation","Pf","Final_Punctuation","Pi","Initial_Punctuation","Po","Other_Punctuation","Ps","Open_Punctuation","S","Symbol","Sc","Currency_Symbol","Sk","Modifier_Symbol","Sm","Math_Symbol","So","Other_Symbol","Z","Separator","Zl","Line_Separator","Zp","Paragraph_Separator","Zs","Space_Separator","ASCII","ASCII_Hex_Digit","AHex","Alphabetic","Alpha","Any","Assigned","Bidi_Control","Bidi_C","Bidi_Mirrored","Bidi_M","Case_Ignorable","CI","Cased","Changes_When_Casefolded","CWCF","Changes_When_Casemapped","CWCM","Changes_When_Lowercased","CWL","Changes_When_NFKC_Casefolded","CWKCF","Changes_When_Titlecased","CWT","Changes_When_Uppercased","CWU","Dash","Default_Ignorable_Code_Point","DI","Deprecated","Dep","Diacritic","Dia","Emoji","Emoji_Component","EComp","Emoji_Modifier","EMod","Emoji_Modifier_Base","EBase","Emoji_Presentation","EPres","Extended_Pictographic","ExtPict","Extender","Ext","Grapheme_Base","Gr_Base","Grapheme_Extend","Gr_Ext","Hex_Digit","Hex","IDS_Binary_Operator","IDSB","IDS_Trinary_Operator","IDST","ID_Continue","IDC","ID_Start","IDS","Ideographic","Ideo","Join_Control","Join_C","Logical_Order_Exception","LOE","Lowercase","Lower","Math","Noncharacter_Code_Point","NChar","Pattern_Syntax","Pat_Syn","Pattern_White_Space","Pat_WS","Quotation_Mark","QMark","Radical","Regional_Indicator","RI","Sentence_Terminal","STerm","Soft_Dotted","SD","Terminal_Punctuation","Term","Unified_Ideograph","UIdeo","Uppercase","Upper","Variation_Selector","VS","White_Space","space","XID_Continue","XIDC","XID_Start","XIDS"]),ke=new Map;for(let e of we)ke.set(K(e),e);var Dt=new Set(["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji","RGI_Emoji_Flag_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence"]),ye=new Map;for(let e of Dt)ye.set(K(e),e);var De=new Set("Dogr Dogra Gong Gunjala_Gondi Hanifi_Rohingya Maka Makasar Medefaidrin Medf Old_Sogdian Rohg Sogd Sogdian Sogo Extended_Pictographic Elym Elymaic Hmnp Nand Nandinagari Nyiakeng_Puachue_Hmong Wancho Wcho Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi EBase EComp EMod EPres ExtPict Cpmn Cypro_Minoan Old_Uyghur Ougr Tangsa Tnsa Toto Vith Vithkuqi Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sunu Sunuwar Todhri Todr Tulu_Tigalari Tutg Unknown Zzzz".split(" ")),Lt=new Map([["s",y(383)],[y(383),"s"]]),Bt=new Map([[y(223),y(7838)],[y(107),y(8490)],[y(229),y(8491)],[y(969),y(8486)]]),Vt=new Map([R(453),R(456),R(459),R(498),...Ce(8072,8079),...Ce(8088,8095),...Ce(8104,8111),R(8124),R(8140),R(8188)]),ne=new Map([["alnum",h`[\p{Alpha}\p{Nd}]`],["alpha",h`\p{Alpha}`],["ascii",h`\p{ASCII}`],["blank",h`[\p{Zs}\t]`],["cntrl",h`\p{cntrl}`],["digit",h`\p{Nd}`],["graph",h`[\P{space}&&\P{cntrl}&&\P{Cn}&&\P{Cs}]`],["lower",h`\p{Lower}`],["print",h`[[\P{space}&&\P{cntrl}&&\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}`]]),Le=new Set(["alnum","blank","graph","print","word","xdigit"]);function jt(e,t){let r=[];for(let s=e;s<=t;s++)r.push(s);return r}function K(e){return e.replace(/[- _]+/g,"").toLowerCase()}function R(e){let t=y(e);return[t.toLowerCase(),t]}function Ce(e,t){return jt(e,t).map(r=>R(r))}var Ee=new Set(["Lower","Lowercase","Upper","Uppercase","Ll","Lowercase_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter"]);var d={Alternator:"Alternator",Assertion:"Assertion",Backreference:"Backreference",Character:"Character",CharacterClassClose:"CharacterClassClose",CharacterClassHyphen:"CharacterClassHyphen",CharacterClassIntersector:"CharacterClassIntersector",CharacterClassOpen:"CharacterClassOpen",CharacterSet:"CharacterSet",Directive:"Directive",GroupClose:"GroupClose",GroupOpen:"GroupOpen",Subroutine:"Subroutine",Quantifier:"Quantifier",VariableLengthCharacterSet:"VariableLengthCharacterSet",EscapedNumber:"EscapedNumber"},A={any:"any",digit:"digit",dot:"dot",hex:"hex",non_newline:"non_newline",posix:"posix",property:"property",space:"space",word:"word"},H={flags:"flags",keep:"keep"},x={atomic:"atomic",capturing:"capturing",group:"group",lookahead:"lookahead",lookbehind:"lookbehind"},Be=new Map([["a",7],["b",8],["e",27],["f",12],["n",10],["r",13],["t",9],["v",11]]),je=h`\[\^?`,We=`c.? | C(?:-.?)?|${h`[pP]\{(?:\^?[\x20\w]+\})?`}|${h`x[89A-Fa-f]\p{AHex}(?:\\x[89A-Fa-f]\p{AHex})*`}|${h`u(?:\p{AHex}{4})? | x\{[^\}]*\}? | x\p{AHex}{0,2}`}|${h`o\{[^\}]*\}?`}|${h`\d{1,3}`}`,Ke=/[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/,se=new RegExp(h` | ||
var OnigurumaToES=(()=>{var he=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Mt=Object.prototype.hasOwnProperty;var Nt=(e,t)=>{for(var r in t)he(e,r,{get:t[r],enumerable:!0})},Pt=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Gt(t))!Mt.call(e,n)&&n!==r&&he(e,n,{get:()=>t[n],enumerable:!(s=It(t,n))||s.enumerable});return e};var Rt=e=>Pt(he({},"__esModule",{value:!0}),e);var en={};Nt(en,{EmulatedRegExp:()=>te,toDetails:()=>_t,toOnigurumaAst:()=>Jr,toRegExp:()=>Yr});var x=String.fromCodePoint,h=String.raw,Oe=(()=>{try{new RegExp("(?<n>)|(?<n>)")}catch{return!1}return!0})(),De=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),Te=(()=>{try{new RegExp("","v")}catch{return!1}return!0})();function L(e,{enable:t,disable:r}){return{dotAll:!r?.dotAll&&!!(t?.dotAll||e.dotAll),ignoreCase:!r?.ignoreCase&&!!(t?.ignoreCase||e.ignoreCase)}}function B(e,t,r){return e.has(t)||e.set(t,r),e.get(t)}function H(e,t){return de[e]>=de[t]}function I(e,t){if(!e)throw new Error(t??"Value expected");return e}var de={ES2025:2025,ES2024:2024,ES2018:2018},Ut={auto:"auto",ES2025:"ES2025",ES2024:"ES2024",ES2018:"ES2018"};function ne(e){if(e?.target!==void 0&&!Ut[e.target])throw new Error(`Unexpected target "${e.target}"`);let t={accuracy:"default",avoidSubclass:!1,flags:"",global:!1,hasIndices:!1,maxRecursionDepth:5,target:"auto",verbose:!1,...e,rules:{allowOrphanBackrefs:!1,asciiWordBoundaries:!1,captureGroup:!1,ignoreUnsupportedGAnchors:!1,...e?.rules}};return t.target==="auto"&&(t.target=Oe&&De?"ES2025":Te?"ES2024":"ES2018"),t}var Ot=new Set([x(304),x(305)]);function me(e){if(Ot.has(e))return[e];let t=new Set,r=e.toLowerCase(),s=r.toUpperCase(),n=Bt.get(r),a=Tt.get(r),o=Lt.get(r);return[...s].length===1&&t.add(s),o&&t.add(o),n&&t.add(n),t.add(r),a&&t.add(a),[...t]}var we=new Set(`C Other | ||
Cc Control cntrl | ||
Cf Format | ||
Cn Unassigned | ||
Co Private_Use | ||
Cs Surrogate | ||
L Letter | ||
LC Cased_Letter | ||
Ll Lowercase_Letter | ||
Lm Modifier_Letter | ||
Lo Other_Letter | ||
Lt Titlecase_Letter | ||
Lu Uppercase_Letter | ||
M Mark Combining_Mark | ||
Mc Spacing_Mark | ||
Me Enclosing_Mark | ||
Mn Nonspacing_Mark | ||
N Number | ||
Nd Decimal_Number digit | ||
Nl Letter_Number | ||
No Other_Number | ||
P Punctuation punct | ||
Pc Connector_Punctuation | ||
Pd Dash_Punctuation | ||
Pe Close_Punctuation | ||
Pf Final_Punctuation | ||
Pi Initial_Punctuation | ||
Po Other_Punctuation | ||
Ps Open_Punctuation | ||
S Symbol | ||
Sc Currency_Symbol | ||
Sk Modifier_Symbol | ||
Sm Math_Symbol | ||
So Other_Symbol | ||
Z Separator | ||
Zl Line_Separator | ||
Zp Paragraph_Separator | ||
Zs Space_Separator | ||
ASCII | ||
ASCII_Hex_Digit AHex | ||
Alphabetic Alpha | ||
Any | ||
Assigned | ||
Bidi_Control Bidi_C | ||
Bidi_Mirrored Bidi_M | ||
Case_Ignorable CI | ||
Cased | ||
Changes_When_Casefolded CWCF | ||
Changes_When_Casemapped CWCM | ||
Changes_When_Lowercased CWL | ||
Changes_When_NFKC_Casefolded CWKCF | ||
Changes_When_Titlecased CWT | ||
Changes_When_Uppercased CWU | ||
Dash | ||
Default_Ignorable_Code_Point DI | ||
Deprecated Dep | ||
Diacritic Dia | ||
Emoji | ||
Emoji_Component EComp | ||
Emoji_Modifier EMod | ||
Emoji_Modifier_Base EBase | ||
Emoji_Presentation EPres | ||
Extended_Pictographic ExtPict | ||
Extender Ext | ||
Grapheme_Base Gr_Base | ||
Grapheme_Extend Gr_Ext | ||
Hex_Digit Hex | ||
IDS_Binary_Operator IDSB | ||
IDS_Trinary_Operator IDST | ||
ID_Continue IDC | ||
ID_Start IDS | ||
Ideographic Ideo | ||
Join_Control Join_C | ||
Logical_Order_Exception LOE | ||
Lowercase Lower | ||
Math | ||
Noncharacter_Code_Point NChar | ||
Pattern_Syntax Pat_Syn | ||
Pattern_White_Space Pat_WS | ||
Quotation_Mark QMark | ||
Radical | ||
Regional_Indicator RI | ||
Sentence_Terminal STerm | ||
Soft_Dotted SD | ||
Terminal_Punctuation Term | ||
Unified_Ideograph UIdeo | ||
Uppercase Upper | ||
Variation_Selector VS | ||
White_Space space | ||
XID_Continue XIDC | ||
XID_Start XIDS`.split(/\s/)),ke=new Map;for(let e of we)ke.set(K(e),e);var Dt=new Set(["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji","RGI_Emoji_Flag_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence"]),ye=new Map;for(let e of Dt)ye.set(K(e),e);var Tt=new Map([["s",x(383)],[x(383),"s"]]),Lt=new Map([[x(223),x(7838)],[x(107),x(8490)],[x(229),x(8491)],[x(969),x(8486)]]),Bt=new Map([U(453),U(456),U(459),U(498),...Ce(8072,8079),...Ce(8088,8095),...Ce(8104,8111),U(8124),U(8140),U(8188)]),se=new Map([["alnum",h`[\p{Alpha}\p{Nd}]`],["alpha",h`\p{Alpha}`],["ascii",h`\p{ASCII}`],["blank",h`[\p{Zs}\t]`],["cntrl",h`\p{cntrl}`],["digit",h`\p{Nd}`],["graph",h`[\P{space}&&\P{cntrl}&&\P{Cn}&&\P{Cs}]`],["lower",h`\p{Lower}`],["print",h`[[\P{space}&&\P{cntrl}&&\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}`]]),Le=new Set(["alnum","blank","graph","print","word","xdigit"]);function Vt(e,t){let r=[];for(let s=e;s<=t;s++)r.push(s);return r}function K(e){return e.replace(/[- _]+/g,"").toLowerCase()}function U(e){let t=x(e);return[t.toLowerCase(),t]}function Ce(e,t){return Vt(e,t).map(r=>U(r))}var be=new Set(["Lower","Lowercase","Upper","Uppercase","Ll","Lowercase_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter"]);var d={Alternator:"Alternator",Assertion:"Assertion",Backreference:"Backreference",Character:"Character",CharacterClassClose:"CharacterClassClose",CharacterClassHyphen:"CharacterClassHyphen",CharacterClassIntersector:"CharacterClassIntersector",CharacterClassOpen:"CharacterClassOpen",CharacterSet:"CharacterSet",Directive:"Directive",GroupClose:"GroupClose",GroupOpen:"GroupOpen",Subroutine:"Subroutine",Quantifier:"Quantifier",VariableLengthCharacterSet:"VariableLengthCharacterSet",EscapedNumber:"EscapedNumber"},E={any:"any",digit:"digit",dot:"dot",hex:"hex",non_newline:"non_newline",posix:"posix",property:"property",space:"space",word:"word"},Q={flags:"flags",keep:"keep"},A={atomic:"atomic",capturing:"capturing",group:"group",lookahead:"lookahead",lookbehind:"lookbehind"},Be=new Map([["a",7],["b",8],["e",27],["f",12],["n",10],["r",13],["t",9],["v",11]]),je=h`\[\^?`,We=`c.? | C(?:-.?)?|${h`[pP]\{(?:\^?[\x20\w]+\})?`}|${h`x[89A-Fa-f]\p{AHex}(?:\\x[89A-Fa-f]\p{AHex})*`}|${h`u(?:\p{AHex}{4})? | x\{[^\}]*\}? | x\p{AHex}{0,2}`}|${h`o\{[^\}]*\}?`}|${h`\d{1,3}`}`,He=/[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/,ae=new RegExp(h` | ||
\\ (?: | ||
@@ -16,6 +106,6 @@ ${We} | ||
)?)? | ||
| ${Ke.source} | ||
| ${He.source} | ||
| ${je} | ||
| . | ||
`.replace(/\s+/g,""),"gsu"),be=new RegExp(h` | ||
`.replace(/\s+/g,""),"gsu"),xe=new RegExp(h` | ||
\\ (?: | ||
@@ -29,4 +119,4 @@ ${We} | ||
| . | ||
`.replace(/\s+/g,""),"gsu");function z(e,t="",r){if(r={captureGroup:!1,...r},typeof e!="string")throw new Error("String expected as pattern");if(!/^[imxDSW]*$/.test(t))throw new Error(`Flags "${t}" includes unsupported value`);let s=t.includes("x"),n=[s],a={captureGroup:r.captureGroup,getCurrentModX:()=>n.at(-1),numOpenGroups:0,popModX(){n.pop()},pushModX(f){n.push(f)},replaceCurrentModX(f){n[n.length-1]=f}},o=[],i;for(se.lastIndex=0;i=se.exec(e);){let f=Wt(a,e,i[0],se.lastIndex);f.tokens?o.push(...f.tokens):f.token&&o.push(f.token),f.lastIndex!==void 0&&(se.lastIndex=f.lastIndex)}let c=[],p=0;o.forEach(f=>{f.type===d.GroupOpen&&(f.kind===x.capturing?f.number=++p:f.raw==="("&&c.push(f))}),p||c.forEach((f,w)=>{f.kind=x.capturing,f.number=w+1});let l=p||c.length;return o=o.map(f=>f.type===d.EscapedNumber?Yt(f,l):f).flat(),{tokens:o,flags:{ignoreCase:t.includes("i"),dotAll:t.includes("m"),extended:s,digitIsAscii:t.includes("D"),spaceIsAscii:t.includes("S"),wordIsAscii:t.includes("W")},rules:r}}function Wt(e,t,r,s){let[n,a,o]=r;if(n==="["){let i=Kt(t,r,s);return{tokens:i.tokens,lastIndex:i.lastIndex}}if(n==="\\"){if("AbBGzZ".includes(a))return{token:C(d.Assertion,r,{kind:r})};if(/^\\g[<']/.test(r)){if(!/^\\g(?:<[^>]+>|'[^']+')$/.test(r))throw new Error(`Invalid group name "${r}"`);return{token:C(d.Subroutine,r)}}if(/^\\k[<']/.test(r)){if(!/^\\k(?:<[^>]+>|'[^']+')$/.test(r))throw new Error(`Invalid group name "${r}"`);return{token:C(d.Backreference,r)}}if(a==="K")return{token:C(d.Directive,r,{kind:H.keep})};if(a==="N")return{token:C(d.CharacterSet,r,{kind:A.non_newline})};if(a==="O")return{token:C(d.CharacterSet,r,{kind:A.any})};if("RX".includes(a))return{token:C(d.VariableLengthCharacterSet,r,{kind:r})};if("yY".includes(a))throw new Error(`Unsupported grapheme boundary "${r}"`);let i=He(r,{inCharClass:!1});return Array.isArray(i)?{tokens:i}:{token:i}}if(n==="("){if(o==="#"){if(t[s]!==")")throw new Error('Unclosed comment group "(?#"');return{lastIndex:s+1}}if("-imx".includes(o))return{token:Qt(r,e)};if(e.pushModX(e.getCurrentModX()),e.numOpenGroups++,r==="("&&!e.captureGroup||r==="(?:")return{token:C(d.GroupOpen,r,{kind:x.group})};if(r==="(?>")return{token:C(d.GroupOpen,r,{kind:x.atomic})};if(r==="(?="||r==="(?!"||r==="(?<="||r==="(?<!")return{token:C(d.GroupOpen,r,{kind:o==="<"?x.lookbehind:x.lookahead,negate:r.endsWith("!")})};if(o==="<"||o==="'"||r==="("&&e.captureGroup){let i=C(d.GroupOpen,r,{kind:x.capturing});return r!=="("&&(i.name=r.slice(3,-1)),{token:i}}throw o==="("?new Error(`Unsupported conditional "${r}"`):o==="~"?new Error(`Unsupported absence operator "${r}"`):r==="(?"?new Error("Invalid group"):new Error(`Unexpected group "${r}"`)}if(r===")"){if(e.popModX(),e.numOpenGroups--,e.numOpenGroups<0)throw new Error('Unmatched ")"');return{token:C(d.GroupClose,r)}}if(r==="#"&&e.getCurrentModX()){let i=t.indexOf(` | ||
`,s);return{lastIndex:i===-1?t.length:i}}if(/^\s$/.test(r)&&e.getCurrentModX()){let i=/\s+/y;return i.lastIndex=s,{lastIndex:i.exec(t)?i.lastIndex:s}}return r==="."?{token:C(d.CharacterSet,r,{kind:A.dot})}:r==="^"||r==="$"?{token:C(d.Assertion,r,{kind:r})}:r==="|"?{token:C(d.Alternator,r)}:Ke.test(r)?{token:qt(r)}:(ze(r),{token:C(d.Character,r,{value:r.codePointAt(0)})})}function Kt(e,t,r){let s=[C(d.CharacterClassOpen,t,{negate:t[1]==="^"})],n=1,a;for(be.lastIndex=r;a=be.exec(e);){let o=a[0];if(o[0]==="["&&o[1]!==":")n++,s.push(C(d.CharacterClassOpen,o,{negate:o[1]==="^"}));else if(o==="]"){if(s.at(-1).type===d.CharacterClassOpen)s.push(C(d.Character,o,{value:93}));else if(n--,s.push(C(d.CharacterClassClose,o)),!n)break}else{let i=Ht(o);Array.isArray(i)?s.push(...i):s.push(i)}}return{tokens:s,lastIndex:be.lastIndex||e.length}}function Ht(e){if(e[0]==="\\")return He(e,{inCharClass:!0});if(e[0]==="["){let t=/\[:(?<negate>\^?)(?<name>[a-z]+):\]/.exec(e);if(!t||!ne.get(t.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return C(d.CharacterSet,e,{kind:A.posix,negate:!!t.groups.negate,value:t.groups.name})}return e==="-"?C(d.CharacterClassHyphen,e):e==="&&"?C(d.CharacterClassIntersector,e):(ze(e),C(d.Character,e,{value:e.codePointAt(0)}))}function He(e,{inCharClass:t}){let r=e[1];if(r==="c"||r==="C")return zt(e);if("dDhHsSwW".includes(r))return Xt(e);if(e.startsWith(h`\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");return Zt(e)}if(/^\\x[89A-Fa-f]\p{AHex}/u.test(e))try{let s=e.split(/\\x/).slice(1).map(i=>parseInt(i,16)),n=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}).decode(new Uint8Array(s)),a=new TextEncoder;return[...n].map(i=>{let c=[...a.encode(i)].map(p=>`\\x${p.toString(16)}`).join("");return C(d.Character,c,{value:i.codePointAt(0)})})}catch{throw new Error(`Multibyte code "${e}" incomplete or invalid in Oniguruma`)}if(r==="u"||r==="x")return C(d.Character,e,{value:Jt(e)});if(Be.has(r))return C(d.Character,e,{value:Be.get(r)});if(/\d/.test(r))return C(d.EscapedNumber,e,{inCharClass:t});if(e==="\\")throw new Error(h`Incomplete escape "\"`);if(r==="M")throw new Error(`Unsupported meta "${e}"`);if([...e].length===2)return C(d.Character,e,{value:e.codePointAt(1)});throw new Error(`Unexpected escape "${e}"`)}function C(e,t,r){return{type:e,raw:t,...r}}function zt(e){let t=e[1]==="c"?e[2]:e[3];if(!t||!/[A-Za-z]/.test(t))throw new Error(`Unsupported control character "${e}"`);return C(d.Character,e,{value:t.toUpperCase().codePointAt(0)-64})}function Qt(e,t){let{on:r,off:s}=/^\(\?(?<on>[imx]*)(?:-(?<off>[imx\-]*))?/.exec(e).groups;s??="";let n=(t.getCurrentModX()||r.includes("x"))&&!s.includes("x"),a=Ve(r),o=Ve(s),i={};if(a&&(i.enable=a),o&&(i.disable=o),e.endsWith(")"))return t.replaceCurrentModX(n),C(d.Directive,e,{kind:H.flags,flags:i});if(e.endsWith(":")){t.pushModX(n),t.numOpenGroups++;let c=C(d.GroupOpen,e,{kind:x.group});return(a||o)&&(c.flags=i),c}throw new Error(`Unexpected flag modifier "${e}"`)}function qt(e){let t={};if(e[0]==="{"){let{min:r,max:s}=/^\{(?<min>\d*)(?:,(?<max>\d*))?/.exec(e).groups,n=1e5;if(+r>n||+s>n)throw new Error("Quantifier value unsupported in Oniguruma");t.min=+r,t.max=s===void 0?+r:s===""?1/0:+s,t.greedy=!e.endsWith("?"),t.possessive=!1}else t.min=e[0]==="+"?1:0,t.max=e[0]==="?"?1:1/0,t.greedy=e[1]!=="?",t.possessive=e[1]==="+";return C(d.Quantifier,e,t)}function Xt(e){let t=e[1].toLowerCase();return C(d.CharacterSet,e,{kind:{d:A.digit,h:A.hex,s:A.space,w:A.word}[t],negate:e[1]!==t})}function Zt(e){let{p:t,neg:r,value:s}=/^\\(?<p>[pP])\{(?<neg>\^?)(?<value>[ \w]+)/.exec(e).groups,n=t==="P"&&!r||t==="p"&&!!r;return C(d.CharacterSet,e,{kind:A.property,negate:n,value:s})}function Ve(e){let t={};return e.includes("i")&&(t.ignoreCase=!0),e.includes("m")&&(t.dotAll=!0),e.includes("x")&&(t.extended=!0),Object.keys(t).length?t:null}function Jt(e){if(/^(?:\\u(?!\p{AHex}{4})|\\x(?!\p{AHex}{1,2}|\{\p{AHex}{1,8}\}))/u.test(e))throw new Error(`Incomplete or invalid escape "${e}"`);let t=e[2]==="{"?/^\\x\{\s*(?<hex>\p{AHex}+)/u.exec(e).groups.hex:e.slice(2),r=parseInt(t,16);if(r>1310719)throw new Error(`Invalid out of range "${e}"`);if(r>1114111)throw new Error(`Invalid out of range in JS "${e}"`);return r}function Yt(e,t){let{raw:r,inCharClass:s}=e,n=r.slice(1);if(!s&&(n!=="0"&&n.length===1||n[0]!=="0"&&+n<=t))return[C(d.Backreference,r)];let a=[],o=n.match(/^[0-7]+|\d/g);for(let i=0;i<o.length;i++){let c=o[i],p;if(i===0&&c!=="8"&&c!=="9"){if(p=parseInt(c,8),p>127)throw new Error(h`Octal encoded byte above 177 unsupported "${r}"`)}else p=c.codePointAt(0);a.push(C(d.Character,(i===0?"\\":"")+c,{value:p}))}return a}function ze(e){if([...e].length!==1)throw new Error(`Expected "${e}" to be a single code point`)}function Q({alternatives:e},t){return e.length===1&&e[0].elements.length===1&&(!t||t(e[0].elements[0]))}function I({type:e,kind:t}){return e===u.Assertion&&(t===m.lookahead||t===m.lookbehind)}function ae({type:e,min:t}){return e===u.Assertion||e===u.Directive||e===u.Quantifier&&!t}function M(e,t,r){let s=e.node;for(;s.parent;)s=s.parent;function n(o,i){for(let c=0;c<o.length;c++){let p=a(o[c],i,c,o);c=Math.max(-1,c+p)}}function a(o,i=null,c=null,p=null){let l=0,f=!1,w={node:o,parent:i,key:c,container:p,ast:s,remove(){v(p,"Container expected").splice(Math.max(0,c+l),1),l-=1},removeAllNextSiblings(){return v(p,"Container expected").splice(c+1)},removeAllPrevSiblings(){let _=c+l;return l-=_,v(p,"Container expected").splice(0,Math.max(0,_))},replaceWith(_){tr(_,i),p?p[Math.max(0,c+l)]=_:i[c]=_},skip(){f=!0}},g=er(o).find(_=>!!r[_]),E=g&&r[g],b=typeof E=="function"?E:E?.enter,$=E?.exit;if(b?.(w,t),!f)switch(o.type){case u.Regex:a(o.pattern,o,"pattern"),a(o.flags,o,"flags");break;case u.Alternative:case u.CharacterClass:n(o.elements,o);break;case u.Assertion:I(o)&&n(o.alternatives,o);break;case u.Backreference:case u.Character:case u.CharacterSet:case u.Directive:case u.Flags:case u.Recursion:case u.Subroutine:case u.VariableLengthCharacterSet:break;case u.CapturingGroup:case u.Group:case u.Pattern:n(o.alternatives,o);break;case u.CharacterClassIntersection:n(o.classes,o);break;case u.CharacterClassRange:a(o.min,o,"min"),a(o.max,o,"max");break;case u.Quantifier:a(o.element,o,"element");break;default:throw new Error(`Unexpected node type "${o.type}"`)}return $?.(w,t),l}a(e.node,e.parent,e.key,e.container)}var Qe={AnyGroup:"AnyGroup",AnyNode:"AnyNode"};function er(e){let{type:t}=e,r=[Qe.AnyNode];return(t===u.CapturingGroup||t===u.Group||I(e))&&r.push(Qe.AnyGroup),r.push(t),r}function tr(e,t){"parent"in t&&(e.parent=t)}var u={Alternative:"Alternative",Assertion:"Assertion",Backreference:"Backreference",CapturingGroup:"CapturingGroup",Character:"Character",CharacterClass:"CharacterClass",CharacterClassIntersection:"CharacterClassIntersection",CharacterClassRange:"CharacterClassRange",CharacterSet:"CharacterSet",Directive:"Directive",Flags:"Flags",Group:"Group",Pattern:"Pattern",Quantifier:"Quantifier",Regex:"Regex",Subroutine:"Subroutine",VariableLengthCharacterSet:"VariableLengthCharacterSet",Recursion:"Recursion"},m={line_end:"line_end",line_start:"line_start",lookahead:"lookahead",lookbehind:"lookbehind",search_start:"search_start",string_end:"string_end",string_end_newline:"string_end_newline",string_start:"string_start",word_boundary:"word_boundary"},k=A,X=H,q={grapheme:"grapheme",newline:"newline"};function Z({tokens:e,flags:t,rules:r},s){let n={skipBackrefValidation:!1,skipPropertyNameValidation:!1,verbose:!1,...s},a={capturingGroups:[],current:0,hasNumberedRef:!1,namedGroupsByName:new Map,parent:null,skipBackrefValidation:n.skipBackrefValidation,skipPropertyNameValidation:n.skipPropertyNameValidation,subroutines:[],token:null,tokens:e,verbose:n.verbose,walk:o};function o(g,E){let b=e[a.current];switch(a.parent=g,a.token=b,a.current++,b.type){case d.Alternator:return O();case d.Assertion:return Ze(b);case d.Backreference:return rr(a);case d.Character:return Je(b.value);case d.CharacterClassHyphen:return nr(a,E);case d.CharacterClassOpen:return sr(a,E);case d.CharacterSet:return ar(a);case d.Directive:return fr(b);case d.GroupOpen:return or(a,E);case d.Quantifier:return ir(a);case d.Subroutine:return cr(a);case d.VariableLengthCharacterSet:return wr(b.kind);default:throw new Error(`Unexpected token type "${b.type}"`)}}let i=Cr(hr(),gr(t)),c=i.pattern.alternatives[0];for(;a.current<e.length;){let g=o(c,{});g.type===u.Alternative?(i.pattern.alternatives.push(g),c=g):c.elements.push(g)}let{capturingGroups:p,hasNumberedRef:l,namedGroupsByName:f,subroutines:w}=a;if(l&&f.size&&!r.captureGroup)throw new Error("Numbered backref/subroutine not allowed when using named capture");for(let{ref:g}of w)if(typeof g=="number"){if(g>p.length)throw new Error("Subroutine uses a group number that's not defined")}else if(f.has(g)){if(f.get(g).length>1)throw new Error(h`Subroutine uses a duplicate group name "\g<${g}>"`)}else throw new Error(h`Subroutine uses a group name that's not defined "\g<${g}>"`);return M({node:i},null,{AnyNode({node:g,parent:E}){g.parent=E}}),i}function rr(e){let{raw:t}=e.token,r=/^\\k[<']/.test(t),s=r?t.slice(3,-1):t.slice(1),n=(a,o=!1)=>{let i=e.capturingGroups.length,c=!1;if(a>i)if(e.skipBackrefValidation)c=!0;else throw new Error(`Not enough capturing groups defined to the left "${t}"`);return e.hasNumberedRef=!0,oe(o?i+1-a:a,{orphan:c})};if(r){let a=/^(?<sign>-?)0*(?<num>[1-9]\d*)$/.exec(s);if(a)return n(+a.groups.num,!!a.groups.sign);if(/[-+]/.test(s))throw new Error(`Invalid backref name "${t}"`);if(!e.namedGroupsByName.has(s))throw new Error(`Group name not defined to the left "${t}"`);return oe(s)}return n(+s)}function nr(e,t){let{parent:r,tokens:s,walk:n}=e,a=r.elements.at(-1),o=s[e.current];if(a&&a.type!==u.CharacterClass&&a.type!==u.CharacterClassRange&&o&&o.type!==d.CharacterClassOpen&&o.type!==d.CharacterClassClose&&o.type!==d.CharacterClassIntersector){let i=n(r,t);if(a.type===u.Character&&i.type===u.Character)return r.elements.pop(),pr(a,i);throw new Error("Invalid character class range")}return Je(45)}function sr(e,t){let{token:r,tokens:s,verbose:n,walk:a}=e,o=s[e.current],i=Ae({negate:r.negate}),c=i.elements[0],p=qe(o);for(;p.type!==d.CharacterClassClose;){if(p.type===d.CharacterClassIntersector)c.classes.push(Ae({negate:!1,baseOnly:!0})),e.current++;else{let l=c.classes.at(-1);l.elements.push(a(l,t))}p=qe(s[e.current],o)}if(n||br(c),c.classes.length===1){let l=c.classes[0];l.negate=i.negate!==l.negate,i=l}return e.current++,i}function ar({token:e,skipPropertyNameValidation:t}){let{kind:r,negate:s,value:n}=e;if(r===A.property){let a=K(n);if(Le.has(a))r=A.posix,n=a;else return B(n,{negate:s,skipPropertyNameValidation:t})}return r===A.posix?{type:u.CharacterSet,kind:k.posix,negate:s,value:n}:ie(r,{negate:s})}function or(e,t){let{token:r,tokens:s,capturingGroups:n,namedGroupsByName:a,verbose:o,walk:i}=e,c=ur(r);c.type===u.CapturingGroup&&(n.push(c),c.name&&L(a,c.name,[]).push(c));let p=Xe(s[e.current]);for(;p.type!==d.GroupClose;){if(p.type===d.Alternator)c.alternatives.push(O()),e.current++;else{let l=c.alternatives.at(-1);l.elements.push(i(l,t))}p=Xe(s[e.current])}return o||(c=yr(c)),e.current++,c}function ir({token:e,parent:t}){let{min:r,max:s,greedy:n,possessive:a}=e,o=t.elements.at(-1);if(!o||o.type===u.Assertion||o.type===u.Directive)throw new Error("Quantifier requires a repeatable token");let i=dr(o,r,s,n,a);return t.elements.pop(),i}function cr(e){let{token:t,capturingGroups:r,subroutines:s}=e,n=t.raw.slice(3,-1),a=/^(?<sign>[-+]?)0*(?<num>[1-9]\d*)$/.exec(n);if(a){let i=+a.groups.num,c=r.length;if(e.hasNumberedRef=!0,n={"":i,"+":c+i,"-":c+1-i}[a.groups.sign],n<1)throw new Error("Invalid subroutine number")}else n==="0"&&(n=0);let o=mr(n);return s.push(o),o}function O(){return{type:u.Alternative,elements:[]}}function Ze({type:e,kind:t,negate:r}){if(e===d.GroupOpen)return ce({behind:t===x.lookbehind,negate:r});let s=v({"^":m.line_start,$:m.line_end,"\\A":m.string_start,"\\b":m.word_boundary,"\\B":m.word_boundary,"\\G":m.search_start,"\\z":m.string_end,"\\Z":m.string_end_newline}[t],`Unexpected assertion kind "${t}"`),n={type:u.Assertion,kind:s};return s===m.word_boundary&&(n.negate=t===h`\B`),n}function oe(e,t){let r=!!t?.orphan;return{type:u.Backreference,...r&&{orphan:r},ref:e}}function ur(e){let{kind:t,number:r,name:s,flags:n}=e;switch(t){case x.atomic:return P({atomic:!0});case x.capturing:return xe(r,s);case x.group:return P({flags:n});case x.lookahead:case x.lookbehind:return Ze(e);default:throw new Error(`Unexpected group kind "${t}"`)}}function xe(e,t){let r=t!==void 0;if(r&&!Er(t))throw new Error(`Group name "${t}" invalid in Oniguruma`);return{type:u.CapturingGroup,number:e,...r&&{name:t},alternatives:[O()]}}function Je(e){return{type:u.Character,value:e}}function Ae(e){let t={baseOnly:!1,negate:!1,...e};return{type:u.CharacterClass,negate:t.negate,elements:t.baseOnly?[]:[lr()]}}function lr(){return{type:u.CharacterClassIntersection,classes:[Ae({negate:!1,baseOnly:!0})]}}function pr(e,t){if(t.value<e.value)throw new Error("Character class range out of order");return{type:u.CharacterClassRange,min:e,max:t}}function ie(e,{negate:t}){let r={type:u.CharacterSet,kind:v(k[e],`Unexpected character set kind "${e}"`)};return(e===A.digit||e===A.hex||e===A.space||e===A.word)&&(r.negate=t),r}function fr({kind:e,flags:t}){let r={type:u.Directive,kind:v(X[e],`Unexpected directive kind "${e}"`)};return e===H.flags&&(r.flags=t),r}function gr({ignoreCase:e,dotAll:t,extended:r,digitIsAscii:s,spaceIsAscii:n,wordIsAscii:a}){return{type:u.Flags,ignoreCase:e,dotAll:t,extended:r,digitIsAscii:s,spaceIsAscii:n,wordIsAscii:a}}function P(e){let t=e?.atomic,r=e?.flags;return{type:u.Group,...t&&{atomic:t},...r&&{flags:r},alternatives:[O()]}}function ce(e){let t={behind:!1,negate:!1,...e};return{type:u.Assertion,kind:t.behind?m.lookbehind:m.lookahead,negate:t.negate,alternatives:[O()]}}function hr(){return{type:u.Pattern,alternatives:[O()]}}function dr(e,t,r,s,n){if(r<t)throw new Error("Quantifier range out of order");return{type:u.Quantifier,min:t,max:r,greedy:s,possessive:n,element:e}}function Cr(e,t){return{type:u.Regex,pattern:e,flags:t}}function mr(e){return{type:u.Subroutine,ref:e}}function B(e,t){let r={negate:!1,skipPropertyNameValidation:!1,...t};return{type:u.CharacterSet,kind:k.property,value:r.skipPropertyNameValidation?e:kr(e),negate:r.negate}}function wr(e){return{type:u.VariableLengthCharacterSet,kind:v({"\\R":q.newline,"\\X":q.grapheme}[e],`Unexpected varcharset kind "${e}"`)}}function kr(e){let t=K(e);if(ye.has(t))throw new Error(h`Unicode property "\p{${e}}" unsupported in Oniguruma`);let r=ke.get(t);return r||e.trim().replace(/\s+/g,"_").replace(/[A-Z][a-z]+(?=[A-Z])/g,"$&_").replace(/[A-Za-z]+/g,s=>s[0].toUpperCase()+s.slice(1).toLowerCase())}function yr(e){let t=e.alternatives[0].elements[0];return e.type===u.Group&&Q(e,r=>r.type===u.Group)&&!(e.atomic&&t.flags)&&!(e.flags&&(t.atomic||t.flags))?(e.atomic?t.atomic=!0:e.flags&&(t.flags=e.flags),t):e}function Er(e){return!/^(?:[-\d]|$)/.test(e)}function br(e){for(let t=0;t<e.classes.length;t++){let r=e.classes[t],s=r.elements[0];r.elements.length===1&&s.type===u.CharacterClass&&(e.classes[t]=s,s.negate=r.negate!==s.negate)}}function qe(e,t){return v(e,`${t?.value===93?"Empty":"Unclosed"} character class`)}function Xe(e){return v(e,"Unclosed group")}var S=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function U(e,t,r,s){let n=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),a=[!1],o=0,i="";for(let c of e.matchAll(n)){let{0:p,groups:{$skip:l}}=c;if(!l&&(!s||s===S.DEFAULT==!o)){r instanceof Function?i+=r(c,{context:o?S.CHAR_CLASS:S.DEFAULT,negated:a[a.length-1]}):i+=r;continue}p[0]==="["?(o++,a.push(p[1]==="^")):p==="]"&&o&&(o--,a.pop()),i+=p}return i}function Ye(e,t,r,s){U(e,t,r,s)}function Ar(e,t,r=0,s){if(!new RegExp(t,"su").test(e))return null;let n=new RegExp(`${t}|(?<$skip>\\\\?.)`,"gsu");n.lastIndex=r;let a=0,o;for(;o=n.exec(e);){let{0:i,groups:{$skip:c}}=o;if(!c&&(!s||s===S.DEFAULT==!a))return o;i==="["?a++:i==="]"&&a&&a--,n.lastIndex==o.index&&n.lastIndex++}return null}function J(e,t,r){return!!Ar(e,t,0,r)}function et(e,t){let r=/\\?./gsu;r.lastIndex=t;let s=e.length,n=0,a=1,o;for(;o=r.exec(e);){let[i]=o;if(i==="[")n++;else if(n)i==="]"&&n--;else if(i==="(")a++;else if(i===")"&&(a--,!a)){s=o.index;break}}return e.slice(t,s)}var ue="$E$",Y=class e extends RegExp{_captureMap;constructor(t,r,s){if(t instanceof RegExp&&s)throw new Error("Cannot provide options when copying regexp");let n;s?.useEmulationGroups&&({expression:t,captureMap:n}=xr(t)),super(t,r),n?this._captureMap=n:t instanceof e&&(this._captureMap=t._captureMap)}exec(t){let r=RegExp.prototype.exec.call(this,t);if(!r||!this._captureMap)return r;let s=[...r];r.length=1;let n;this.hasIndices&&(n=[...r.indices],r.indices.length=1);for(let a=1;a<s.length;a++)this._captureMap[a]&&(r.push(s[a]),this.hasIndices&&r.indices.push(n[a]));return r}};function xr(e){let t=ue.replace(/\$/g,"\\$"),r=[!0];return e=U(e,String.raw`\((?:(?!\?)|\?<(?![=!])[^>]+>)(?<mark>${t})?`,({0:s,groups:{mark:n}})=>n?(r.push(!1),s.slice(0,-ue.length)):(r.push(!0),s),S.DEFAULT),{captureMap:r,expression:e}}var tt=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;function rt(e,t,r,s){return e.slice(0,t)+s+e.slice(t+r.length)}var nt=new RegExp(String.raw`(?<noncapturingStart>${tt})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`,"gsu");function _e(e,t){if(!/\(\?>/.test(e))return e;let r="(?>",s=`(?:(?=(${t?.useEmulationGroups?ue:""}`,n=[0],a=0,o=0,i=NaN,c;do{c=!1;let p=0,l=0,f=!1,w;for(nt.lastIndex=Number.isNaN(i)?0:i+s.length;w=nt.exec(e);){let{0:g,index:E,groups:{capturingStart:b,noncapturingStart:$}}=w;if(g==="[")p++;else if(p)g==="]"&&p--;else if(g===r&&!f)i=E,f=!0;else if(f&&$)l++;else if(b)f?l++:(a++,n.push(a+o));else if(g===")"&&f){if(!l){o++,e=`${e.slice(0,i)}${s}${e.slice(i+r.length,E)}))<$$${o+a}>)${e.slice(E+1)}`,c=!0;break}l--}}}while(c);return e=U(e,String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,({0:p,groups:{backrefNum:l,wrappedBackrefNum:f}})=>{if(l){let w=+l;if(w>n.length-1)throw new Error(`Backref "${p}" greater than number of captures`);return`\\${n[w]}`}return`\\${f}`},S.DEFAULT),e}var st=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,Se=new RegExp(String.raw` | ||
`.replace(/\s+/g,""),"gsu");function X(e,t="",r){if(r={captureGroup:!1,...r},typeof e!="string")throw new Error("String expected as pattern");if(!/^[imxDSW]*$/.test(t))throw new Error(`Flags "${t}" includes unsupported value`);let s=t.includes("x"),n=[s],a={captureGroup:r.captureGroup,getCurrentModX:()=>n.at(-1),numOpenGroups:0,popModX(){n.pop()},pushModX(f){n.push(f)},replaceCurrentModX(f){n[n.length-1]=f}},o=[],i;for(ae.lastIndex=0;i=ae.exec(e);){let f=jt(a,e,i[0],ae.lastIndex);f.tokens?o.push(...f.tokens):f.token&&o.push(f.token),f.lastIndex!==void 0&&(ae.lastIndex=f.lastIndex)}let c=[],p=0;o.forEach(f=>{f.type===d.GroupOpen&&(f.kind===A.capturing?f.number=++p:f.raw==="("&&c.push(f))}),p||c.forEach((f,w)=>{f.kind=A.capturing,f.number=w+1});let l=p||c.length;return o=o.map(f=>f.type===d.EscapedNumber?Jt(f,l):f).flat(),{tokens:o,flags:{ignoreCase:t.includes("i"),dotAll:t.includes("m"),extended:s,digitIsAscii:t.includes("D"),spaceIsAscii:t.includes("S"),wordIsAscii:t.includes("W")},rules:r}}function jt(e,t,r,s){let[n,a,o]=r;if(n==="["){let i=Wt(t,r,s);return{tokens:i.tokens,lastIndex:i.lastIndex}}if(n==="\\"){if("AbBGzZ".includes(a))return{token:C(d.Assertion,r,{kind:r})};if(/^\\g[<']/.test(r)){if(!/^\\g(?:<[^>]+>|'[^']+')$/.test(r))throw new Error(`Invalid group name "${r}"`);return{token:C(d.Subroutine,r)}}if(/^\\k[<']/.test(r)){if(!/^\\k(?:<[^>]+>|'[^']+')$/.test(r))throw new Error(`Invalid group name "${r}"`);return{token:C(d.Backreference,r)}}if(a==="K")return{token:C(d.Directive,r,{kind:Q.keep})};if(a==="N")return{token:C(d.CharacterSet,r,{kind:E.non_newline})};if(a==="O")return{token:C(d.CharacterSet,r,{kind:E.any})};if("RX".includes(a))return{token:C(d.VariableLengthCharacterSet,r,{kind:r})};if("yY".includes(a))throw new Error(`Unsupported grapheme boundary "${r}"`);let i=Ke(r,{inCharClass:!1});return Array.isArray(i)?{tokens:i}:{token:i}}if(n==="("){if(o==="#"){if(t[s]!==")")throw new Error('Unclosed comment group "(?#"');return{lastIndex:s+1}}if("-imx".includes(o))return{token:Qt(r,e)};if(e.pushModX(e.getCurrentModX()),e.numOpenGroups++,r==="("&&!e.captureGroup||r==="(?:")return{token:C(d.GroupOpen,r,{kind:A.group})};if(r==="(?>")return{token:C(d.GroupOpen,r,{kind:A.atomic})};if(r==="(?="||r==="(?!"||r==="(?<="||r==="(?<!")return{token:C(d.GroupOpen,r,{kind:o==="<"?A.lookbehind:A.lookahead,negate:r.endsWith("!")})};if(o==="<"||o==="'"||r==="("&&e.captureGroup){let i=C(d.GroupOpen,r,{kind:A.capturing});return r!=="("&&(i.name=r.slice(3,-1)),{token:i}}throw o==="("?new Error(`Unsupported conditional "${r}"`):o==="~"?new Error(`Unsupported absence operator "${r}"`):r==="(?"?new Error("Invalid group"):new Error(`Unexpected group "${r}"`)}if(r===")"){if(e.popModX(),e.numOpenGroups--,e.numOpenGroups<0)throw new Error('Unmatched ")"');return{token:C(d.GroupClose,r)}}if(r==="#"&&e.getCurrentModX()){let i=t.indexOf(` | ||
`,s);return{lastIndex:i===-1?t.length:i}}if(/^\s$/.test(r)&&e.getCurrentModX()){let i=/\s+/y;return i.lastIndex=s,{lastIndex:i.exec(t)?i.lastIndex:s}}return r==="."?{token:C(d.CharacterSet,r,{kind:E.dot})}:r==="^"||r==="$"?{token:C(d.Assertion,r,{kind:r})}:r==="|"?{token:C(d.Alternator,r)}:He.test(r)?{token:Xt(r)}:(Qe(r),{token:C(d.Character,r,{value:r.codePointAt(0)})})}function Wt(e,t,r){let s=[C(d.CharacterClassOpen,t,{negate:t[1]==="^"})],n=1,a;for(xe.lastIndex=r;a=xe.exec(e);){let o=a[0];if(o[0]==="["&&o[1]!==":")n++,s.push(C(d.CharacterClassOpen,o,{negate:o[1]==="^"}));else if(o==="]"){if(s.at(-1).type===d.CharacterClassOpen)s.push(C(d.Character,o,{value:93}));else if(n--,s.push(C(d.CharacterClassClose,o)),!n)break}else{let i=Ht(o);Array.isArray(i)?s.push(...i):s.push(i)}}return{tokens:s,lastIndex:xe.lastIndex||e.length}}function Ht(e){if(e[0]==="\\")return Ke(e,{inCharClass:!0});if(e[0]==="["){let t=/\[:(?<negate>\^?)(?<name>[a-z]+):\]/.exec(e);if(!t||!se.get(t.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return C(d.CharacterSet,e,{kind:E.posix,negate:!!t.groups.negate,value:t.groups.name})}return e==="-"?C(d.CharacterClassHyphen,e):e==="&&"?C(d.CharacterClassIntersector,e):(Qe(e),C(d.Character,e,{value:e.codePointAt(0)}))}function Ke(e,{inCharClass:t}){let r=e[1];if(r==="c"||r==="C")return Kt(e);if("dDhHsSwW".includes(r))return qt(e);if(e.startsWith(h`\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");return zt(e)}if(/^\\x[89A-Fa-f]\p{AHex}/u.test(e))try{let s=e.split(/\\x/).slice(1).map(i=>parseInt(i,16)),n=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}).decode(new Uint8Array(s)),a=new TextEncoder;return[...n].map(i=>{let c=[...a.encode(i)].map(p=>`\\x${p.toString(16)}`).join("");return C(d.Character,c,{value:i.codePointAt(0)})})}catch{throw new Error(`Multibyte code "${e}" incomplete or invalid in Oniguruma`)}if(r==="u"||r==="x")return C(d.Character,e,{value:Zt(e)});if(Be.has(r))return C(d.Character,e,{value:Be.get(r)});if(/\d/.test(r))return C(d.EscapedNumber,e,{inCharClass:t});if(e==="\\")throw new Error(h`Incomplete escape "\"`);if(r==="M")throw new Error(`Unsupported meta "${e}"`);if([...e].length===2)return C(d.Character,e,{value:e.codePointAt(1)});throw new Error(`Unexpected escape "${e}"`)}function C(e,t,r){return{type:e,raw:t,...r}}function Kt(e){let t=e[1]==="c"?e[2]:e[3];if(!t||!/[A-Za-z]/.test(t))throw new Error(`Unsupported control character "${e}"`);return C(d.Character,e,{value:t.toUpperCase().codePointAt(0)-64})}function Qt(e,t){let{on:r,off:s}=/^\(\?(?<on>[imx]*)(?:-(?<off>[imx\-]*))?/.exec(e).groups;s??="";let n=(t.getCurrentModX()||r.includes("x"))&&!s.includes("x"),a=Ve(r),o=Ve(s),i={};if(a&&(i.enable=a),o&&(i.disable=o),e.endsWith(")"))return t.replaceCurrentModX(n),C(d.Directive,e,{kind:Q.flags,flags:i});if(e.endsWith(":")){t.pushModX(n),t.numOpenGroups++;let c=C(d.GroupOpen,e,{kind:A.group});return(a||o)&&(c.flags=i),c}throw new Error(`Unexpected flag modifier "${e}"`)}function Xt(e){let t={};if(e[0]==="{"){let{min:r,max:s}=/^\{(?<min>\d*)(?:,(?<max>\d*))?/.exec(e).groups,n=1e5;if(+r>n||+s>n)throw new Error("Quantifier value unsupported in Oniguruma");t.min=+r,t.max=s===void 0?+r:s===""?1/0:+s,t.greedy=!e.endsWith("?"),t.possessive=!1}else t.min=e[0]==="+"?1:0,t.max=e[0]==="?"?1:1/0,t.greedy=e[1]!=="?",t.possessive=e[1]==="+";return C(d.Quantifier,e,t)}function qt(e){let t=e[1].toLowerCase();return C(d.CharacterSet,e,{kind:{d:E.digit,h:E.hex,s:E.space,w:E.word}[t],negate:e[1]!==t})}function zt(e){let{p:t,neg:r,value:s}=/^\\(?<p>[pP])\{(?<neg>\^?)(?<value>[ \w]+)/.exec(e).groups,n=t==="P"&&!r||t==="p"&&!!r;return C(d.CharacterSet,e,{kind:E.property,negate:n,value:s})}function Ve(e){let t={};return e.includes("i")&&(t.ignoreCase=!0),e.includes("m")&&(t.dotAll=!0),e.includes("x")&&(t.extended=!0),Object.keys(t).length?t:null}function Zt(e){if(/^(?:\\u(?!\p{AHex}{4})|\\x(?!\p{AHex}{1,2}|\{\p{AHex}{1,8}\}))/u.test(e))throw new Error(`Incomplete or invalid escape "${e}"`);let t=e[2]==="{"?/^\\x\{\s*(?<hex>\p{AHex}+)/u.exec(e).groups.hex:e.slice(2),r=parseInt(t,16);if(r>1310719)throw new Error(`Invalid out of range "${e}"`);if(r>1114111)throw new Error(`Invalid out of range in JS "${e}"`);return r}function Jt(e,t){let{raw:r,inCharClass:s}=e,n=r.slice(1);if(!s&&(n!=="0"&&n.length===1||n[0]!=="0"&&+n<=t))return[C(d.Backreference,r)];let a=[],o=n.match(/^[0-7]+|\d/g);for(let i=0;i<o.length;i++){let c=o[i],p;if(i===0&&c!=="8"&&c!=="9"){if(p=parseInt(c,8),p>127)throw new Error(h`Octal encoded byte above 177 unsupported "${r}"`)}else p=c.codePointAt(0);a.push(C(d.Character,(i===0?"\\":"")+c,{value:p}))}return a}function Qe(e){if([...e].length!==1)throw new Error(`Expected "${e}" to be a single code point`)}function q({alternatives:e},t){return e.length===1&&e[0].elements.length===1&&(!t||t(e[0].elements[0]))}function M({type:e,kind:t}){return e===u.Assertion&&(t===m.lookahead||t===m.lookbehind)}function oe({type:e,min:t}){return e===u.Assertion||e===u.Directive||e===u.Quantifier&&!t}function N(e,t,r){let s=e.node;for(;s.parent;)s=s.parent;function n(o,i){for(let c=0;c<o.length;c++){let p=a(o[c],i,c,o);c=Math.max(-1,c+p)}}function a(o,i=null,c=null,p=null){let l=0,f=!1,w={node:o,parent:i,key:c,container:p,ast:s,remove(){I(p,"Container expected").splice(Math.max(0,c+l),1),l-=1},removeAllNextSiblings(){return I(p,"Container expected").splice(c+1)},removeAllPrevSiblings(){let _=c+l;return l-=_,I(p,"Container expected").splice(0,Math.max(0,_))},replaceWith(_){er(_,i),p?p[Math.max(0,c+l)]=_:i[c]=_},skip(){f=!0}},g=Yt(o).find(_=>!!r[_]),y=g&&r[g],b=typeof y=="function"?y:y?.enter,F=y?.exit;if(b?.(w,t),!f)switch(o.type){case u.Regex:a(o.pattern,o,"pattern"),a(o.flags,o,"flags");break;case u.Alternative:case u.CharacterClass:n(o.elements,o);break;case u.Assertion:M(o)&&n(o.alternatives,o);break;case u.Backreference:case u.Character:case u.CharacterSet:case u.Directive:case u.Flags:case u.Recursion:case u.Subroutine:case u.VariableLengthCharacterSet:break;case u.CapturingGroup:case u.Group:case u.Pattern:n(o.alternatives,o);break;case u.CharacterClassIntersection:n(o.classes,o);break;case u.CharacterClassRange:a(o.min,o,"min"),a(o.max,o,"max");break;case u.Quantifier:a(o.element,o,"element");break;default:throw new Error(`Unexpected node type "${o.type}"`)}return F?.(w,t),l}a(e.node,e.parent,e.key,e.container)}var Xe={AnyGroup:"AnyGroup",AnyNode:"AnyNode"};function Yt(e){let{type:t}=e,r=[Xe.AnyNode];return(t===u.CapturingGroup||t===u.Group||M(e))&&r.push(Xe.AnyGroup),r.push(t),r}function er(e,t){"parent"in t&&(e.parent=t)}var u={Alternative:"Alternative",Assertion:"Assertion",Backreference:"Backreference",CapturingGroup:"CapturingGroup",Character:"Character",CharacterClass:"CharacterClass",CharacterClassIntersection:"CharacterClassIntersection",CharacterClassRange:"CharacterClassRange",CharacterSet:"CharacterSet",Directive:"Directive",Flags:"Flags",Group:"Group",Pattern:"Pattern",Quantifier:"Quantifier",Regex:"Regex",Subroutine:"Subroutine",VariableLengthCharacterSet:"VariableLengthCharacterSet",Recursion:"Recursion"},m={line_end:"line_end",line_start:"line_start",lookahead:"lookahead",lookbehind:"lookbehind",search_start:"search_start",string_end:"string_end",string_end_newline:"string_end_newline",string_start:"string_start",word_boundary:"word_boundary"},k=E,Z=Q,z={grapheme:"grapheme",newline:"newline"};function J({tokens:e,flags:t,rules:r},s){let n={skipBackrefValidation:!1,skipPropertyNameValidation:!1,verbose:!1,...s},a={capturingGroups:[],current:0,hasNumberedRef:!1,namedGroupsByName:new Map,parent:null,skipBackrefValidation:n.skipBackrefValidation,skipPropertyNameValidation:n.skipPropertyNameValidation,subroutines:[],token:null,tokens:e,verbose:n.verbose,walk:o};function o(g,y){let b=e[a.current];switch(a.parent=g,a.token=b,a.current++,b.type){case d.Alternator:return O();case d.Assertion:return Ze(b);case d.Backreference:return tr(a);case d.Character:return Je(b.value);case d.CharacterClassHyphen:return rr(a,y);case d.CharacterClassOpen:return nr(a,y);case d.CharacterSet:return sr(a);case d.Directive:return pr(b);case d.GroupOpen:return ar(a,y);case d.Quantifier:return or(a);case d.Subroutine:return ir(a);case d.VariableLengthCharacterSet:return mr(b.kind);default:throw new Error(`Unexpected token type "${b.type}"`)}}let i=dr(gr(),fr(t)),c=i.pattern.alternatives[0];for(;a.current<e.length;){let g=o(c,{});g.type===u.Alternative?(i.pattern.alternatives.push(g),c=g):c.elements.push(g)}let{capturingGroups:p,hasNumberedRef:l,namedGroupsByName:f,subroutines:w}=a;if(l&&f.size&&!r.captureGroup)throw new Error("Numbered backref/subroutine not allowed when using named capture");for(let{ref:g}of w)if(typeof g=="number"){if(g>p.length)throw new Error("Subroutine uses a group number that's not defined")}else if(f.has(g)){if(f.get(g).length>1)throw new Error(h`Subroutine uses a duplicate group name "\g<${g}>"`)}else throw new Error(h`Subroutine uses a group name that's not defined "\g<${g}>"`);return N({node:i},null,{AnyNode({node:g,parent:y}){g.parent=y}}),i}function tr(e){let{raw:t}=e.token,r=/^\\k[<']/.test(t),s=r?t.slice(3,-1):t.slice(1),n=(a,o=!1)=>{let i=e.capturingGroups.length,c=!1;if(a>i)if(e.skipBackrefValidation)c=!0;else throw new Error(`Not enough capturing groups defined to the left "${t}"`);return e.hasNumberedRef=!0,ie(o?i+1-a:a,{orphan:c})};if(r){let a=/^(?<sign>-?)0*(?<num>[1-9]\d*)$/.exec(s);if(a)return n(+a.groups.num,!!a.groups.sign);if(/[-+]/.test(s))throw new Error(`Invalid backref name "${t}"`);if(!e.namedGroupsByName.has(s))throw new Error(`Group name not defined to the left "${t}"`);return ie(s)}return n(+s)}function rr(e,t){let{parent:r,tokens:s,walk:n}=e,a=r.elements.at(-1),o=s[e.current];if(a&&a.type!==u.CharacterClass&&a.type!==u.CharacterClassRange&&o&&o.type!==d.CharacterClassOpen&&o.type!==d.CharacterClassClose&&o.type!==d.CharacterClassIntersector){let i=n(r,t);if(a.type===u.Character&&i.type===u.Character)return r.elements.pop(),lr(a,i);throw new Error("Invalid character class range")}return Je(45)}function nr(e,t){let{token:r,tokens:s,verbose:n,walk:a}=e,o=s[e.current],i=Ee({negate:r.negate}),c=i.elements[0],p=qe(o);for(;p.type!==d.CharacterClassClose;){if(p.type===d.CharacterClassIntersector)c.classes.push(Ee({negate:!1,baseOnly:!0})),e.current++;else{let l=c.classes.at(-1);l.elements.push(a(l,t))}p=qe(s[e.current],o)}if(n||br(c),c.classes.length===1){let l=c.classes[0];l.negate=i.negate!==l.negate,i=l}return e.current++,i}function sr({token:e,skipPropertyNameValidation:t}){let{kind:r,negate:s,value:n}=e;if(r===E.property){let a=K(n);if(Le.has(a))r=E.posix,n=a;else return V(n,{negate:s,skipPropertyNameValidation:t})}return r===E.posix?{type:u.CharacterSet,kind:k.posix,negate:s,value:n}:ce(r,{negate:s})}function ar(e,t){let{token:r,tokens:s,capturingGroups:n,namedGroupsByName:a,verbose:o,walk:i}=e,c=cr(r);c.type===u.CapturingGroup&&(n.push(c),c.name&&B(a,c.name,[]).push(c));let p=ze(s[e.current]);for(;p.type!==d.GroupClose;){if(p.type===d.Alternator)c.alternatives.push(O()),e.current++;else{let l=c.alternatives.at(-1);l.elements.push(i(l,t))}p=ze(s[e.current])}return o||(c=kr(c)),e.current++,c}function or({token:e,parent:t}){let{min:r,max:s,greedy:n,possessive:a}=e,o=t.elements.at(-1);if(!o||o.type===u.Assertion||o.type===u.Directive)throw new Error("Quantifier requires a repeatable token");let i=hr(o,r,s,n,a);return t.elements.pop(),i}function ir(e){let{token:t,capturingGroups:r,subroutines:s}=e,n=t.raw.slice(3,-1),a=/^(?<sign>[-+]?)0*(?<num>[1-9]\d*)$/.exec(n);if(a){let i=+a.groups.num,c=r.length;if(e.hasNumberedRef=!0,n={"":i,"+":c+i,"-":c+1-i}[a.groups.sign],n<1)throw new Error("Invalid subroutine number")}else n==="0"&&(n=0);let o=Cr(n);return s.push(o),o}function O(){return{type:u.Alternative,elements:[]}}function Ze({type:e,kind:t,negate:r}){if(e===d.GroupOpen)return ue({behind:t===A.lookbehind,negate:r});let s=I({"^":m.line_start,$:m.line_end,"\\A":m.string_start,"\\b":m.word_boundary,"\\B":m.word_boundary,"\\G":m.search_start,"\\z":m.string_end,"\\Z":m.string_end_newline}[t],`Unexpected assertion kind "${t}"`),n={type:u.Assertion,kind:s};return s===m.word_boundary&&(n.negate=t===h`\B`),n}function ie(e,t){let r=!!t?.orphan;return{type:u.Backreference,...r&&{orphan:r},ref:e}}function cr(e){let{kind:t,number:r,name:s,flags:n}=e;switch(t){case A.atomic:return P({atomic:!0});case A.capturing:return Ae(r,s);case A.group:return P({flags:n});case A.lookahead:case A.lookbehind:return Ze(e);default:throw new Error(`Unexpected group kind "${t}"`)}}function Ae(e,t){let r=t!==void 0;if(r&&!yr(t))throw new Error(`Group name "${t}" invalid in Oniguruma`);return{type:u.CapturingGroup,number:e,...r&&{name:t},alternatives:[O()]}}function Je(e){return{type:u.Character,value:e}}function Ee(e){let t={baseOnly:!1,negate:!1,...e};return{type:u.CharacterClass,negate:t.negate,elements:t.baseOnly?[]:[ur()]}}function ur(){return{type:u.CharacterClassIntersection,classes:[Ee({negate:!1,baseOnly:!0})]}}function lr(e,t){if(t.value<e.value)throw new Error("Character class range out of order");return{type:u.CharacterClassRange,min:e,max:t}}function ce(e,{negate:t}){let r={type:u.CharacterSet,kind:I(k[e],`Unexpected character set kind "${e}"`)};return(e===E.digit||e===E.hex||e===E.space||e===E.word)&&(r.negate=t),r}function pr({kind:e,flags:t}){let r={type:u.Directive,kind:I(Z[e],`Unexpected directive kind "${e}"`)};return e===Q.flags&&(r.flags=t),r}function fr({ignoreCase:e,dotAll:t,extended:r,digitIsAscii:s,spaceIsAscii:n,wordIsAscii:a}){return{type:u.Flags,ignoreCase:e,dotAll:t,extended:r,digitIsAscii:s,spaceIsAscii:n,wordIsAscii:a}}function P(e){let t=e?.atomic,r=e?.flags;return{type:u.Group,...t&&{atomic:t},...r&&{flags:r},alternatives:[O()]}}function ue(e){let t={behind:!1,negate:!1,...e};return{type:u.Assertion,kind:t.behind?m.lookbehind:m.lookahead,negate:t.negate,alternatives:[O()]}}function gr(){return{type:u.Pattern,alternatives:[O()]}}function hr(e,t,r,s,n){if(r<t)throw new Error("Quantifier range out of order");return{type:u.Quantifier,min:t,max:r,greedy:s,possessive:n,element:e}}function dr(e,t){return{type:u.Regex,pattern:e,flags:t}}function Cr(e){return{type:u.Subroutine,ref:e}}function V(e,t){let r={negate:!1,skipPropertyNameValidation:!1,...t};return{type:u.CharacterSet,kind:k.property,value:r.skipPropertyNameValidation?e:wr(e),negate:r.negate}}function mr(e){return{type:u.VariableLengthCharacterSet,kind:I({"\\R":z.newline,"\\X":z.grapheme}[e],`Unexpected varcharset kind "${e}"`)}}function wr(e){let t=K(e);if(ye.has(t))throw new Error(h`Unicode property "\p{${e}}" unsupported in Oniguruma`);let r=ke.get(t);return r||e.trim().replace(/\s+/g,"_").replace(/[A-Z][a-z]+(?=[A-Z])/g,"$&_").replace(/[A-Za-z]+/g,s=>s[0].toUpperCase()+s.slice(1).toLowerCase())}function kr(e){let t=e.alternatives[0].elements[0];return e.type===u.Group&&q(e,r=>r.type===u.Group)&&!(e.atomic&&t.flags)&&!(e.flags&&(t.atomic||t.flags))?(e.atomic?t.atomic=!0:e.flags&&(t.flags=e.flags),t):e}function yr(e){return!/^(?:[-\d]|$)/.test(e)}function br(e){for(let t=0;t<e.classes.length;t++){let r=e.classes[t],s=r.elements[0];r.elements.length===1&&s.type===u.CharacterClass&&(e.classes[t]=s,s.negate=r.negate!==s.negate)}}function qe(e,t){return I(e,`${t?.value===93?"Empty":"Unclosed"} character class`)}function ze(e){return I(e,"Unclosed group")}var S=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function T(e,t,r,s){let n=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),a=[!1],o=0,i="";for(let c of e.matchAll(n)){let{0:p,groups:{$skip:l}}=c;if(!l&&(!s||s===S.DEFAULT==!o)){r instanceof Function?i+=r(c,{context:o?S.CHAR_CLASS:S.DEFAULT,negated:a[a.length-1]}):i+=r;continue}p[0]==="["?(o++,a.push(p[1]==="^")):p==="]"&&o&&(o--,a.pop()),i+=p}return i}function Ye(e,t,r,s){T(e,t,r,s)}function xr(e,t,r=0,s){if(!new RegExp(t,"su").test(e))return null;let n=new RegExp(`${t}|(?<$skip>\\\\?.)`,"gsu");n.lastIndex=r;let a=0,o;for(;o=n.exec(e);){let{0:i,groups:{$skip:c}}=o;if(!c&&(!s||s===S.DEFAULT==!a))return o;i==="["?a++:i==="]"&&a&&a--,n.lastIndex==o.index&&n.lastIndex++}return null}function Y(e,t,r){return!!xr(e,t,0,r)}function et(e,t){let r=/\\?./gsu;r.lastIndex=t;let s=e.length,n=0,a=1,o;for(;o=r.exec(e);){let[i]=o;if(i==="[")n++;else if(n)i==="]"&&n--;else if(i==="(")a++;else if(i===")"&&(a--,!a)){s=o.index;break}}return e.slice(t,s)}var v="$E$",ee=class e extends RegExp{_captureMap;_namesByIndex;constructor(t,r,s){if(t instanceof RegExp&&s)throw new Error("Cannot provide options when copying a regexp");let n=!!s?.useEmulationGroups,a=n?Er(t):null;super(a?.expression||t,r);let o=n?a:t instanceof e?t:null;o&&(this._captureMap=o._captureMap,this._namesByIndex=o._namesByIndex)}exec(t){let r=RegExp.prototype.exec.call(this,t);if(!r||!this._captureMap)return r;let s=[...r];r.length=1;let n;this.hasIndices&&(n=[...r.indices],r.indices.length=1);for(let a=1;a<s.length;a++)if(this._captureMap[a].exclude){let o=this._captureMap[a].transfer;if(o&&r.length>o){r[o]=s[a];let i=this._namesByIndex[o];i&&(r.groups[i]=s[a],this.hasIndices&&(r.indices.groups[i]=n[a])),this.hasIndices&&(r.indices[o]=n[a])}}else r.push(s[a]),this.hasIndices&&r.indices.push(n[a]);return r}};function Er(e){let t=v.replace(/\$/g,"\\$"),r=[{exclude:!1}],s={0:""},n=0;return e=T(e,String.raw`\((?:(?!\?)|\?<(?![=!])(?<name>[^>]+)>)(?<mark>(?:\$(?<transfer>[1-9]\d*))?${t})?`,({0:a,groups:{name:o,mark:i,transfer:c}})=>i?(r.push({exclude:!0,transfer:c&&+c}),a.slice(0,-i.length)):(n++,o&&(s[n]=o),r.push({exclude:!1}),a),S.DEFAULT),{_captureMap:r,_namesByIndex:s,expression:e}}var tt=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;function rt(e,t,r,s){return e.slice(0,t)+s+e.slice(t+r.length)}var nt=new RegExp(String.raw`(?<noncapturingStart>${tt})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`,"gsu");function $e(e,t){if(!/\(\?>/.test(e))return e;let r="(?>",s=`(?:(?=(${t?.useEmulationGroups?v:""}`,n=[0],a=0,o=0,i=NaN,c;do{c=!1;let p=0,l=0,f=!1,w;for(nt.lastIndex=Number.isNaN(i)?0:i+s.length;w=nt.exec(e);){let{0:g,index:y,groups:{capturingStart:b,noncapturingStart:F}}=w;if(g==="[")p++;else if(p)g==="]"&&p--;else if(g===r&&!f)i=y,f=!0;else if(f&&F)l++;else if(b)f?l++:(a++,n.push(a+o));else if(g===")"&&f){if(!l){o++,e=`${e.slice(0,i)}${s}${e.slice(i+r.length,y)}))<$$${o+a}>)${e.slice(y+1)}`,c=!0;break}l--}}}while(c);return e=T(e,String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,({0:p,groups:{backrefNum:l,wrappedBackrefNum:f}})=>{if(l){let w=+l;if(w>n.length-1)throw new Error(`Backref "${p}" greater than number of captures`);return`\\${n[w]}`}return`\\${f}`},S.DEFAULT),e}var st=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,Se=new RegExp(String.raw` | ||
\\(?: \d+ | ||
@@ -46,5 +136,5 @@ | c[A-Za-z] | ||
| \\?. | ||
`.replace(/\s+/g,""),"gsu");function $e(e){if(!new RegExp(`${st}\\+`).test(e))return e;let t=[],r=null,s=null,n="",a=0,o;for(Se.lastIndex=0;o=Se.exec(e);){let{0:i,index:c,groups:{qBase:p,qMod:l,invalidQ:f}}=o;if(i==="[")a||(s=c),a++;else if(i==="]")a?a--:s=null;else if(!a)if(l==="+"&&n&&!n.startsWith("(")){if(f)throw new Error(`Invalid quantifier "${i}"`);let w=-1;if(/^\{\d+\}$/.test(p))e=rt(e,c+p.length,l,"");else{if(n===")"||n==="]"){let g=n===")"?r:s;if(g===null)throw new Error(`Invalid unmatched "${n}"`);e=`${e.slice(0,g)}(?>${e.slice(g,c)}${p})${e.slice(c+i.length)}`}else e=`${e.slice(0,c-n.length)}(?>${n}${p})${e.slice(c+i.length)}`;w+=4}Se.lastIndex+=w}else i[0]==="("?t.push(c):i===")"&&(r=t.length?t.pop():null);n=i}return e}var ee=class e extends Y{#e;constructor(t,r,s){let n={useEmulationGroups:!1,strategy:null,...s};super(t,r,{useEmulationGroups:n.useEmulationGroups}),n.strategy?this.#e=n.strategy:t instanceof e&&(this.#e=t.#e)}exec(t){let r=super.exec,s=this.global||this.sticky,n=this.lastIndex,a=this.#e;if(a==="line_or_search_start"&&s&&this.lastIndex){this.lastIndex=0;let o=r.call(this,t.slice(n));return o&&Sr(t,this,o,n),o}if(a==="not_search_start"){let o=r.call(this,t);if(o?.index===n){let i=s?this:new RegExp(this.source,`g${this.flags}`);i.lastIndex=o.index+1,o=r.call(i,t)}return o}return r.call(this,t)}};function Sr(e,t,r,s){if(r.input=e,r.index+=s,t.lastIndex+=s,t.hasIndices){let n=r.indices;for(let o=0;o<n.length;o++){let i=n[o];n[o]=[i[0]+s,i[1]+s]}let a=n.groups;a&&Object.keys(a).forEach(o=>{let i=a[o];a[o]=[i[0]+s,i[1]+s]})}}function at(e){let t=e.pattern.alternatives,r=t[0].elements[0];if(t.length>1||!r)return null;let s=Q(e.pattern,o=>o.type===u.CapturingGroup||o.type===u.Group)&&r.alternatives.length===1,n=s?r.alternatives[0]:t[0],a=s?n.elements[0]:r;if(!a)return null;if((a.type===u.CapturingGroup||a.type===u.Group)&&a.alternatives.length===2&&a.alternatives[0].elements.length===1&&a.alternatives[1].elements.length===1){let o=a.alternatives[0].elements[0],i=a.alternatives[1].elements[0];if(o.kind===m.line_start&&i.kind===m.search_start||o.kind===m.search_start&&i.kind===m.line_start)return o.kind===m.line_start?a.alternatives.pop():a.alternatives.shift(),"line_or_search_start"}if(le(a,{negate:!0}))return a.parent.elements.shift(),"not_search_start";for(let o=0;o<n.elements.length;o++){let i=n.elements[o];if(!ae(i))break;if(le(i,{negate:!0}))return n.elements.splice(o,1),"not_search_start"}return null}function le(e,t){return I(e)&&e.negate===t.negate&&Q(e,r=>r.kind===m.search_start)}var ve=String.raw,ot=ve`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`,it=ve`\u{E0061}-\u{E007A}`,ct=()=>new RegExp(ve`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${it}]{2}[\u{E0030}-\u{E0039}${it}]{1,3}\u{E007F}|${ot}(?:\u200D${ot})*`,"gu");function lt(e,t){let r={accuracy:"default",allowUnhandledGAnchors:!1,asciiWordBoundaries:!1,avoidSubclass:!1,bestEffortTarget:"ES2025",...t},s=r.avoidSubclass?null:at(e),n={accuracy:r.accuracy,allowUnhandledGAnchors:r.allowUnhandledGAnchors,asciiWordBoundaries:r.asciiWordBoundaries,flagDirectivesByAlt:new Map,minTargetEs2024:W(r.bestEffortTarget,"ES2024"),subroutineRefMap:new Map,supportedGNodes:new Set,digitIsAscii:e.flags.digitIsAscii,spaceIsAscii:e.flags.spaceIsAscii,wordIsAscii:e.flags.wordIsAscii};M({node:e},n,pt);let 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:n.subroutineRefMap};M({node:e},o,ft);let i={groupsByName:o.groupsByName,highestOrphanBackref:0,numCapturesToLeft:0,reffedNodesByReferencer:o.reffedNodesByReferencer};return M({node:e},i,_r),s&&(e._strategy=s),e}var pt={Alternative:{enter({node:e,parent:t,key:r},{flagDirectivesByAlt:s}){let n=e.elements.filter(a=>a.kind===X.flags);for(let a=r+1;a<t.alternatives.length;a++){let o=t.alternatives[a];L(s,o,[]).push(...n)}},exit({node:e},{flagDirectivesByAlt:t}){if(t.get(e)?.length){let r=dt(t.get(e));if(r){let s=te(P({flags:r}),e.elements);s.parent=e,e.elements=[s]}}}},Assertion({node:e,ast:t,remove:r,replaceWith:s},{allowUnhandledGAnchors:n,asciiWordBoundaries:a,supportedGNodes:o,wordIsAscii:i}){let{kind:c,negate:p}=e;if(c===m.line_end)s(F(h`(?=\z|\n)`));else if(c===m.line_start)s(F(h`(?<=\A|\n(?!\z))`));else if(c===m.search_start){if(o.has(e))t.flags.sticky=!0;else if(!n)throw new Error(h`Uses "\G" in a way that's unsupported`);r()}else if(c===m.string_end_newline)s(F(h`(?=\n?\z)`));else if(c===m.word_boundary&&!i&&!a){let l=`(?:(?<=${N})(?!${N})|(?<!${N})(?=${N}))`,f=`(?:(?<=${N})(?=${N})|(?<!${N})(?!${N}))`;s(F(p?f:l))}},CapturingGroup({node:e},{subroutineRefMap:t}){let{name:r,number:s}=e;if(r&&!Ir(r))throw new Error(`Group name "${r}" invalid in JS`);t.set(s,e),r&&t.set(r,e)},CharacterSet({node:e,replaceWith:t},{accuracy:r,minTargetEs2024:s,digitIsAscii:n,spaceIsAscii:a,wordIsAscii:o}){let{kind:i,negate:c,value:p}=e;if(n&&(i===k.digit||p==="digit")){t(ie(k.digit,{negate:c}));return}if(a&&(i===k.space||p==="space")){t(Fe(F($r),c));return}if(o&&(i===k.word||p==="word")){t(ie(k.word,{negate:c}));return}if(i===k.any)t(B("Any"));else if(i===k.digit)t(B("Nd",{negate:c}));else if(i===k.hex)t(B("AHex",{negate:c}));else if(i===k.non_newline)t(F(h`[^\n]`));else if(i===k.space)t(B("space",{negate:c}));else if(i===k.word)t(Fe(F(N),c));else if(i===k.property)we.has(p)||(e.key="sc");else if(i===k.posix)if(!s&&(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-${y(l.codePointAt(0)-1)}${y(l.codePointAt(2)+1)}-\u{10FFFF}`),t(F(`[${l}]`))}else t(Fe(F(ne.get(p)),c))},Directive(e,t){let{node:r,parent:s,ast:n,remove:a,replaceWith:o,removeAllPrevSiblings:i,removeAllNextSiblings:c}=e,{kind:p,flags:l}=r;if(p===X.flags)if(!l.enable&&!l.disable)a();else{let f=te(P({flags:l}),c());o(f),kt(f,e,t,pt)}else if(p===X.keep){if(s.parent!==n.pattern||n.pattern.alternatives.length>1)throw new Error(h`Uses "\K" in a way that's unsupported`);o(te(ce({behind:!0}),i()))}},Flags({node:e,parent:t}){["digitIsAscii","extended","spaceIsAscii","wordIsAscii"].forEach(r=>delete e[r]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;let{enable:t,disable:r}=e.flags;t?.extended&&delete t.extended,r?.extended&&delete r.extended,t?.dotAll&&r?.dotAll&&delete t.dotAll,t?.ignoreCase&&r?.ignoreCase&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable,r&&!Object.keys(r).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},Pattern({node:e},{allowUnhandledGAnchors:t,supportedGNodes:r}){let s=[],n=!1,a=!1;for(let o of e.alternatives){let i=mt(o.elements);i?(n=!0,Array.isArray(i)?s.push(...i):s.push(i)):a=!0}if(n){if(!a)s.forEach(o=>r.add(o));else if(!t)throw new Error(h`Uses "\G" in a way that's unsupported`)}},Quantifier({node:e}){if(e.element.type===u.Quantifier){let t=te(P(),[e.element]);t.parent=e,e.element=t}},VariableLengthCharacterSet({node:e,replaceWith:t},{accuracy:r,minTargetEs2024:s}){let{kind:n}=e;if(n===q.newline)t(F(`(?>\r | ||
`.replace(/\s+/g,""),"gsu");function _e(e){if(!new RegExp(`${st}\\+`).test(e))return e;let t=[],r=null,s=null,n="",a=0,o;for(Se.lastIndex=0;o=Se.exec(e);){let{0:i,index:c,groups:{qBase:p,qMod:l,invalidQ:f}}=o;if(i==="[")a||(s=c),a++;else if(i==="]")a?a--:s=null;else if(!a)if(l==="+"&&n&&!n.startsWith("(")){if(f)throw new Error(`Invalid quantifier "${i}"`);let w=-1;if(/^\{\d+\}$/.test(p))e=rt(e,c+p.length,l,"");else{if(n===")"||n==="]"){let g=n===")"?r:s;if(g===null)throw new Error(`Invalid unmatched "${n}"`);e=`${e.slice(0,g)}(?>${e.slice(g,c)}${p})${e.slice(c+i.length)}`}else e=`${e.slice(0,c-n.length)}(?>${n}${p})${e.slice(c+i.length)}`;w+=4}Se.lastIndex+=w}else i[0]==="("?t.push(c):i===")"&&(r=t.length?t.pop():null);n=i}return e}var te=class e extends ee{#e;constructor(t,r,s){let n={useEmulationGroups:!1,strategy:null,...s};super(t,r,{useEmulationGroups:n.useEmulationGroups}),n.strategy?this.#e=n.strategy:t instanceof e&&(this.#e=t.#e)}exec(t){let r=super.exec,s=this.global||this.sticky,n=this.lastIndex,a=this.#e;if(a==="line_or_search_start"&&s&&this.lastIndex){this.lastIndex=0;let o=r.call(this,t.slice(n));return o&&Ar(t,this,o,n),o}if(a==="not_search_start"){let o=r.call(this,t);if(o?.index===n){let i=s?this:new RegExp(this.source,`g${this.flags}`);i.lastIndex=o.index+1,o=r.call(i,t)}return o}return r.call(this,t)}};function Ar(e,t,r,s){if(r.input=e,r.index+=s,t.lastIndex+=s,t.hasIndices){let n=r.indices;for(let o=0;o<n.length;o++){let i=n[o];n[o]=[i[0]+s,i[1]+s]}let a=n.groups;a&&Object.keys(a).forEach(o=>{let i=a[o];a[o]=[i[0]+s,i[1]+s]})}}function at(e){let t=e.pattern.alternatives,r=t[0].elements[0];if(t.length>1||!r)return null;let s=q(e.pattern,o=>o.type===u.CapturingGroup||o.type===u.Group)&&r.alternatives.length===1,n=s?r.alternatives[0]:t[0],a=s?n.elements[0]:r;if(!a)return null;if((a.type===u.CapturingGroup||a.type===u.Group)&&a.alternatives.length===2&&a.alternatives[0].elements.length===1&&a.alternatives[1].elements.length===1){let o=a.alternatives[0].elements[0],i=a.alternatives[1].elements[0];if(o.kind===m.line_start&&i.kind===m.search_start||o.kind===m.search_start&&i.kind===m.line_start)return o.kind===m.line_start?a.alternatives.pop():a.alternatives.shift(),"line_or_search_start"}if(le(a,{negate:!0}))return a.parent.elements.shift(),"not_search_start";for(let o=0;o<n.elements.length;o++){let i=n.elements[o];if(!oe(i))break;if(le(i,{negate:!0}))return n.elements.splice(o,1),"not_search_start"}return null}function le(e,t){return M(e)&&e.negate===t.negate&&q(e,r=>r.kind===m.search_start)}var ve=String.raw,ot=ve`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`,it=ve`\u{E0061}-\u{E007A}`,ct=()=>new RegExp(ve`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${it}]{2}[\u{E0030}-\u{E0039}${it}]{1,3}\u{E007F}|${ot}(?:\u200D${ot})*`,"gu");function lt(e,t){let r={accuracy:"default",asciiWordBoundaries:!1,avoidSubclass:!1,bestEffortTarget:"ES2025",ignoreUnsupportedGAnchors:!1,...t},s=r.avoidSubclass?null:at(e),n={accuracy:r.accuracy,asciiWordBoundaries:r.asciiWordBoundaries,flagDirectivesByAlt:new Map,ignoreUnsupportedGAnchors:r.ignoreUnsupportedGAnchors,minTargetEs2024:H(r.bestEffortTarget,"ES2024"),subroutineRefMap:new Map,supportedGNodes:new Set,digitIsAscii:e.flags.digitIsAscii,spaceIsAscii:e.flags.spaceIsAscii,wordIsAscii:e.flags.wordIsAscii};N({node:e},n,pt);let 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:n.subroutineRefMap};N({node:e},o,ft);let i={groupsByName:o.groupsByName,highestOrphanBackref:0,numCapturesToLeft:0,reffedNodesByReferencer:o.reffedNodesByReferencer};return N({node:e},i,Sr),s&&(e._strategy=s),e}var pt={Alternative:{enter({node:e,parent:t,key:r},{flagDirectivesByAlt:s}){let n=e.elements.filter(a=>a.kind===Z.flags);for(let a=r+1;a<t.alternatives.length;a++){let o=t.alternatives[a];B(s,o,[]).push(...n)}},exit({node:e},{flagDirectivesByAlt:t}){if(t.get(e)?.length){let r=dt(t.get(e));if(r){let s=re(P({flags:r}),e.elements);s.parent=e,e.elements=[s]}}}},Assertion({node:e,ast:t,remove:r,replaceWith:s},{asciiWordBoundaries:n,ignoreUnsupportedGAnchors:a,supportedGNodes:o,wordIsAscii:i}){let{kind:c,negate:p}=e;if(c===m.line_end)s(G(h`(?=\z|\n)`));else if(c===m.line_start)s(G(h`(?<=\A|\n(?!\z))`));else if(c===m.search_start){if(o.has(e))t.flags.sticky=!0;else if(!a)throw new Error(h`Uses "\G" in a way that's unsupported`);r()}else if(c===m.string_end_newline)s(G(h`(?=\n?\z)`));else if(c===m.word_boundary&&!i&&!n){let l=`(?:(?<=${R})(?!${R})|(?<!${R})(?=${R}))`,f=`(?:(?<=${R})(?=${R})|(?<!${R})(?!${R}))`;s(G(p?f:l))}},CapturingGroup({node:e},{subroutineRefMap:t}){let{name:r,number:s}=e;if(r&&!Ir(r))throw new Error(`Group name "${r}" invalid in JS`);t.set(s,e),r&&t.set(r,e)},CharacterSet({node:e,replaceWith:t},{accuracy:r,minTargetEs2024:s,digitIsAscii:n,spaceIsAscii:a,wordIsAscii:o}){let{kind:i,negate:c,value:p}=e;if(n&&(i===k.digit||p==="digit")){t(ce(k.digit,{negate:c}));return}if(a&&(i===k.space||p==="space")){t(Fe(G($r),c));return}if(o&&(i===k.word||p==="word")){t(ce(k.word,{negate:c}));return}if(i===k.any)t(V("Any"));else if(i===k.digit)t(V("Nd",{negate:c}));else if(i===k.hex)t(V("AHex",{negate:c}));else if(i===k.non_newline)t(G(h`[^\n]`));else if(i===k.space)t(V("space",{negate:c}));else if(i===k.word)t(Fe(G(R),c));else if(i===k.property)we.has(p)||(e.key="sc");else if(i===k.posix)if(!s&&(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-${x(l.codePointAt(0)-1)}${x(l.codePointAt(2)+1)}-\u{10FFFF}`),t(G(`[${l}]`))}else t(Fe(G(se.get(p)),c))},Directive(e,t){let{node:r,parent:s,ast:n,remove:a,replaceWith:o,removeAllPrevSiblings:i,removeAllNextSiblings:c}=e,{kind:p,flags:l}=r;if(p===Z.flags)if(!l.enable&&!l.disable)a();else{let f=re(P({flags:l}),c());o(f),kt(f,e,t,pt)}else if(p===Z.keep){if(s.parent!==n.pattern||n.pattern.alternatives.length>1)throw new Error(h`Uses "\K" in a way that's unsupported`);o(re(ue({behind:!0}),i()))}},Flags({node:e,parent:t}){["digitIsAscii","extended","spaceIsAscii","wordIsAscii"].forEach(r=>delete e[r]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;let{enable:t,disable:r}=e.flags;t?.extended&&delete t.extended,r?.extended&&delete r.extended,t?.dotAll&&r?.dotAll&&delete t.dotAll,t?.ignoreCase&&r?.ignoreCase&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable,r&&!Object.keys(r).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},Pattern({node:e},{ignoreUnsupportedGAnchors:t,supportedGNodes:r}){let s=[],n=!1,a=!1;for(let o of e.alternatives){let i=mt(o.elements);i?(n=!0,Array.isArray(i)?s.push(...i):s.push(i)):a=!0}if(n){if(!a)s.forEach(o=>r.add(o));else if(!t)throw new Error(h`Uses "\G" in a way that's unsupported`)}},Quantifier({node:e}){if(e.element.type===u.Quantifier){let t=re(P(),[e.element]);t.parent=e,e.element=t}},VariableLengthCharacterSet({node:e,replaceWith:t},{accuracy:r,minTargetEs2024:s}){let{kind:n}=e;if(n===z.newline)t(G(`(?>\r | ||
?|[ | ||
\v\f\x85\u2028\u2029])`));else if(n===q.grapheme){if(r==="strict")throw new Error(h`Use of "\X" requires non-strict accuracy`);let a=s?h`\p{RGI_Emoji}`:ct().source.replace(/\\u\{/g,"\\x{");t(F(h`(?>\r\n|${a}|\P{M}\p{M}*)`,{skipPropertyNameValidation:!0}))}else throw new Error(`Unexpected varcharset kind "${n}"`)}},ft={Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByReferencer:r}){let{orphan:s,ref:n}=e;s||r.set(e,[...t.get(n).map(({node:a})=>a)])},Recursion({node:e,parent:t},{reffedNodesByReferencer:r}){let{ref:s}=e,n=t;for(;(n=n.parent)&&!(n.type===u.CapturingGroup&&(n.name===s||n.number===s)););r.set(e,n)},CapturingGroup:{enter({node:e,replaceWith:t,skip:r},{groupOriginByCopy:s,groupsByName:n,multiplexCapturesToLeftByRef:a,openRefs:o,reffedNodesByReferencer:i}){let c=s.get(e);if(c&&o.has(e.number)){let l=ut(e.number);i.set(l,o.get(e.number)),t(l),r();return}o.set(e.number,e),a.set(e.number,[]),e.name&&L(a,e.name,[]);let p=a.get(e.name??e.number);for(let l=0;l<p.length;l++){let f=p[l];if(c===f.node||c&&c===f.origin||e===f.origin){p.splice(l,1);break}}if(a.get(e.number).push({node:e,origin:c}),e.name&&a.get(e.name).push({node:e,origin:c}),e.name){let l=L(n,e.name,new Map);for(let f of l.values())!f.hasDuplicateNameToRemove&>(f.node,e,{ancestorsParticipate:!0})&&(f.hasDuplicateNameToRemove=!0);n.get(e.name).set(e,{node:e})}},exit({node:e},{openRefs:t}){t.delete(e.number)}},Group:{enter({node:e},t){t.prevFlags=t.currentFlags,e.flags&&(t.currentFlags=D(t.currentFlags,e.flags))},exit(e,t){t.currentFlags=t.prevFlags}},Subroutine(e,t){let{node:r,replaceWith:s}=e,{ref:n}=r,a=t.subroutineRefMap.get(n),o=n===0,i=o?ut(0):ht(a,t.groupOriginByCopy,null),c=i;if(!o){let p=dt(Fr(a,f=>f.type===u.Group&&!!f.flags)),l=p?D(t.globalFlags,p):t.globalFlags;vr(l,t.currentFlags)||(c=te(P({flags:Gr(l)}),[i]))}s(c),o||kt(c,e,t,ft)}},_r={Backreference({node:e,replaceWith:t},r){if(e.orphan){r.highestOrphanBackref=Math.max(r.highestOrphanBackref,e.ref);return}let n=r.reffedNodesByReferencer.get(e).filter(a=>gt(a,e,{ancestorsParticipate:!1}));if(!n.length)t(ce({negate:!0}));else if(n.length>1){let a=n.map(o=>pe(O(),[oe(o.number)]));t(pe(P(),a))}else e.ref=n[0].number},CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,e.name&&t.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Recursion({node:e},t){e.ref!==0&&(e.ref=t.reffedNodesByReferencer.get(e).number)},Regex:{exit({node:e},t){let r=Math.max(t.highestOrphanBackref-t.numCapturesToLeft,0);for(let s=0;s<r;s++){let n=xe();e.pattern.alternatives.at(-1).elements.push(n)}}}},$r="[ -\r ]",N=h`[\p{L}\p{M}\p{N}\p{Pc}]`;function pe(e,t){return t.forEach(r=>r.parent=e),e[Ge(e)]=t,e}function vr(e,t){return e.dotAll===t.dotAll&&e.ignoreCase===t.ignoreCase}function gt(e,t,{ancestorsParticipate:r}){let s=t;do{if(s.type===u.Pattern)return!1;if(s.type===u.Alternative)continue;if(s===e)return r;let n=Ct(s.parent);for(let a of n){if(a===s)break;if(a===e||wt(a,e))return!0}}while(s=s.parent);throw new Error("Unexpected path")}function ht(e,t,r,s){let n=Array.isArray(e)?[]:{};for(let[a,o]of Object.entries(e))a==="parent"?n.parent=Array.isArray(r)?s:r:o&&typeof o=="object"?n[a]=ht(o,t,n,r):(a==="type"&&o===u.CapturingGroup&&t.set(n,t.get(e)??e),n[a]=o);return n}function ut(e){return{type:u.Recursion,ref:e}}function Fr(e,t){let r=[];for(;e=e.parent;)(!t||t(e))&&r.push(e);return r}function Ge(e){for(let t of["alternatives","classes","elements"])if(e[t])return t;return null}function dt(e){let t=["dotAll","ignoreCase"],r={enable:{},disable:{}};return e.forEach(({flags:s})=>{t.forEach(n=>{s.enable?.[n]&&(delete r.disable[n],r.enable[n]=!0),s.disable?.[n]&&(r.disable[n]=!0)})}),Object.keys(r.enable).length||delete r.enable,Object.keys(r.disable).length||delete r.disable,r.enable||r.disable?r:null}function Gr({dotAll:e,ignoreCase:t}){let r={};return(e||t)&&(r.enable={},e&&(r.enable.dotAll=!0),t&&(r.enable.ignoreCase=!0)),(!e||!t)&&(r.disable={},!e&&(r.disable.dotAll=!0),!t&&(r.disable.ignoreCase=!0)),r}function Ct(e){if(!e)throw new Error("Node expected");if(e.type===u.Quantifier)return[e.element];let t=Ge(e);return t&&e[t]}function mt(e){let t=e.find(r=>r.kind===m.search_start||le(r,{negate:!1})||!ae(r));if(!t)return null;if(t.kind===m.search_start)return t;if(I(t))return t.alternatives[0].elements[0];if(t.type===u.Group||t.type===u.CapturingGroup){let r=[];for(let s of t.alternatives){let n=mt(s.elements);if(!n)return null;Array.isArray(n)?r.push(...n):r.push(n)}return r}return null}function wt(e,t){let r=Ct(e)??[];for(let s of r)if(s===t||wt(s,t))return!0;return!1}function Ir(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function F(e,t){let s=Z(z(e),t).pattern.alternatives;return s.length>1||s[0].elements.length>1?pe(P(),s):s[0].elements[0]}function te(e,t){let r=Ge(e);return e[r][0].parent=e,t&&pe(e[r][0],t),e}function Fe(e,t){return e.negate=t,e}function kt(e,{parent:t,key:r,container:s},n,a){M({node:e,parent:t,key:r,container:s},n,a)}function Et(e,t){let r=re(t),s=W(r.target,"ES2024"),n=W(r.target,"ES2025"),a=r.maxRecursionDepth;if(a!==null&&(!Number.isInteger(a)||a<2||a>100))throw new Error("Invalid maxRecursionDepth; use 2-100 or null");let o=null,i=null;if(!n){let g=[e.flags.ignoreCase];M({node:e},{getCurrentModI:()=>g.at(-1),popModI(){g.pop()},pushModI(E){g.push(E)},setHasCasedChar(){g.at(-1)?o=!0:i=!0}},Mr)}let c={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||o)&&!i)},p=null,l={accuracy:r.accuracy,appliedGlobalFlags:c,captureFlagIMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},groupNames:new Set,inCharClass:!1,lastNode:p,maxRecursionDepth:a,useAppliedIgnoreCase:!!(!n&&o&&i),useDuplicateNames:n,useFlagMods:n,useFlagV:s,usePostEs2018Properties:s,verbose:r.verbose};function f(g){switch(l.lastNode=p,p=g,g.type){case u.Regex:return{pattern:f(g.pattern),flags:f(g.flags),options:{...g.options}};case u.Alternative:return g.elements.map(f).join("");case u.Assertion:return Ur(g,l,f);case u.Backreference:return Tr(g,l);case u.CapturingGroup:return Dr(g,l,f);case u.Character:return Lr(g,l);case u.CharacterClass:return Br(g,l,f);case u.CharacterClassIntersection:if(!l.useFlagV)throw new Error("Use of class intersection requires min target ES2024");return g.classes.map(f).join("&&");case u.CharacterClassRange:return Vr(g,l);case u.CharacterSet:return jr(g,l);case u.Flags:return Wr(g,l);case u.Group:return Kr(g,l,f);case u.Pattern:return g.alternatives.map(f).join("|");case u.Quantifier:return f(g.element)+qr(g);case u.Recursion:return Hr(g,l);default:throw new Error(`Unexpected node type "${g.type}"`)}}let w=f(e);return s||(delete w.options.force.v,w.options.disable.v=!0,w.options.unicodeSetsPlugin=null),w}var Mr={AnyGroup:{enter({node:e},t){let r=t.getCurrentModI();t.pushModI(e.flags?D({ignoreCase:r},e.flags).ignoreCase:r)},exit(e,t){t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){Ie(y(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),bt(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind===k.property&&Ee.has(e.value)&&t.setHasCasedChar()}},Pr=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),Nr=new Set(["-","\\","]","^","["]),Rr=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),yt=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`]]),Or=/^\p{Cased}$/u;function Ie(e){return Or.test(e)}function Ur(e,t,r){let{kind:s,negate:n,alternatives:a}=e;if(I(e))return`(?${`${s===m.lookahead?"":"<"}${n?"!":"="}`}${a.map(r).join("|")})`;if(s===m.string_end)return"$";if(s===m.string_start)return"^";if(s===m.word_boundary)return n?h`\B`:h`\b`;throw new Error(`Unexpected assertion kind "${s}"`)}function Tr({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&t.accuracy==="strict"&&t.currentFlags.ignoreCase&&!t.captureFlagIMap.get(e))throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");return"\\"+e}function Dr({name:e,number:t,alternatives:r},s,n){return e&&(s.groupNames.has(e)?s.useDuplicateNames||(e=null):s.groupNames.add(e)),s.captureFlagIMap.set(t,s.currentFlags.ignoreCase),`(${e?`?<${e}>`:""}${r.map(n).join("|")})`}function Lr({value:e},t){let r=y(e),s=V(e,{isAfterBackref:t.lastNode.type===u.Backreference,inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(s!==r)return s;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&Ie(r)){let n=me(r);return t.inCharClass?n.join(""):n.length>1?`[${n.join("")}]`:n[0]}return r}function Br({negate:e,parent:t,elements:r},s,n){let a=()=>`[${e?"^":""}${r.map(n).join("")}]`;if(!s.inCharClass){s.inCharClass=!0;let i=a();return s.inCharClass=!1,i}let o=r[0].type;if(!e&&(!s.useFlagV||!s.verbose)&&t.type===u.CharacterClass&&o!==u.CharacterClassIntersection||!s.verbose&&t.type===u.CharacterClassIntersection&&r.length===1&&o!==u.CharacterClass&&o!==u.CharacterClassRange)return r.map(n).join("");if(!s.useFlagV&&t.type===u.CharacterClass)throw new Error("Use of nested character class requires min target ES2024");return a()}function Vr(e,t){let r=e.min.value,s=e.max.value,n={isAfterBackref:!1,inCharClass:!0,useFlagV:t.useFlagV},a=V(r,n),o=V(s,n),i="";if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){let c=bt(e);zr(c).forEach(l=>{i+=Array.isArray(l)?`${V(l[0],n)}-${V(l[1],n)}`:V(l,n)})}return`${a}-${o}${i}`}function jr({kind:e,negate:t,value:r,key:s},n){if(e===k.dot)return n.currentFlags.dotAll?n.appliedGlobalFlags.dotAll||n.useFlagMods?".":"[^]":h`[^\n]`;if(e===k.digit)return t?h`\D`:h`\d`;if(e===k.property){if(!n.usePostEs2018Properties&&De.has(r))throw new Error(`Unicode property "${r}" unavailable in target ES2018`);if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase&&Ee.has(r))throw new Error(`Unicode property "${r}" can't be case-insensitive when other chars have specific case`);return`${t?h`\P`:h`\p`}{${s?`${s}=`:""}${r}}`}if(e===k.word)return t?h`\W`:h`\w`;throw new Error(`Unexpected character set kind "${e}"`)}function Wr(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")}function Kr({atomic:e,flags:t,parent:r,alternatives:s},n,a){let o=n.currentFlags;t&&(n.currentFlags=D(o,t));let i=s.map(a).join("|"),c=!n.verbose&&s.length===1&&r.type!==u.Quantifier&&!e&&(!n.useFlagMods||!t)?i:`(?${Qr(e,t,n.useFlagMods)}${i})`;return n.currentFlags=o,c}function Hr({ref:e},t){let r=t.maxRecursionDepth;if(!r)throw new Error("Use of recursion disabled");if(t.accuracy==="strict")throw new Error("Use of recursion requires non-strict accuracy due to depth limit");return e===0?`(?R=${r})`:h`\g<${e}&R=${r}>`}function bt(e,t){let r=!!t?.firstOnly,s=e.min.value,n=e.max.value,a=[];if(s<65&&(n===65535||n>=131071)||s===65536&&n>=131071)return a;for(let o=s;o<=n;o++){let i=y(o);if(!Ie(i))continue;let c=me(i).filter(p=>{let l=p.codePointAt(0);return l<s||l>n});if(c.length&&(a.push(...c),r))break}return a}function V(e,{isAfterBackref:t,inCharClass:r,useFlagV:s}){if(yt.has(e))return yt.get(e);if(e<32||e>126&&e<160||e>262143||t&&Xr(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;let n=r?s?Rr:Nr:Pr,a=y(e);return(n.has(a)?"\\":"")+a}function zr(e){let t=e.map(n=>n.codePointAt(0)).sort((n,a)=>n-a),r=[],s=null;for(let n=0;n<t.length;n++)t[n+1]===t[n]+1?s??=t[n]:s===null?r.push(t[n]):(r.push([s,t[n]]),s=null);return r}function Qr(e,t,r){if(e)return">";let s="";if(t&&r){let{enable:n,disable:a}=t;s=(n?.ignoreCase?"i":"")+(n?.dotAll?"s":"")+(a?"-":"")+(a?.ignoreCase?"i":"")+(a?.dotAll?"s":"")}return`${s}:`}function qr({min:e,max:t,greedy:r,possessive:s}){let n;return!e&&t===1?n="?":!e&&t===1/0?n="*":e===1&&t===1/0?n="+":e===t?n=`{${e}}`:n=`{${e},${t===1/0?"":t}}`,n+(s?"+":r?"":"?")}function Xr(e){return e>47&&e<58}var G=String.raw,Zr=G`\\g<(?<gRNameOrNum>[^>&]+)&R=(?<gRDepth>[^>]+)>`,Pe=G`\(\?R=(?<rDepth>[^\)]+)\)|${Zr}`,fe=G`\(\?<(?![=!])(?<captureName>[^>]+)>`,T=new RegExp(G`${fe}|${Pe}|\(\?|\\?.`,"gsu"),Me="Cannot use multiple overlapping recursions",At="$E$";function $t(e,t){if(!new RegExp(Pe,"su").test(e))return e;if(J(e,G`\(\?\(DEFINE\)`,S.DEFAULT))throw new Error("DEFINE groups cannot be used with recursion");let r=!!t?.useEmulationGroups,s=J(e,G`\\[1-9]`,S.DEFAULT),n=new Map,a=[],o=!1,i=0,c=0,p;for(T.lastIndex=0;p=T.exec(e);){let{0:l,groups:{captureName:f,rDepth:w,gRNameOrNum:g,gRDepth:E}}=p;if(l==="[")i++;else if(i)l==="]"&&i--;else if(w){if(xt(w),o)throw new Error(Me);if(s)throw new Error("Numbered backrefs cannot be used with global recursion");let b=e.slice(0,p.index),$=e.slice(T.lastIndex);if(J($,Pe,S.DEFAULT))throw new Error(Me);return St(b,$,+w,!1,r)}else if(g){xt(E);let b=!1;for(let j of a)if(j.name===g||j.num===+g){if(b=!0,j.hasRecursedWithin)throw new Error(Me);break}if(!b)throw new Error(G`Recursive \g cannot be used outside the referenced group "\g<${g}&R=${E}>"`);let $=n.get(g),_=et(e,$);if(s&&J(_,G`${fe}|\((?!\?)`,S.DEFAULT))throw new Error("Numbered backrefs cannot be used with recursion of capturing groups");let ge=e.slice($,p.index),Ne=_.slice(ge.length+l.length),Re=St(ge,Ne,+E,!0,r),Ft=e.slice(0,$),Gt=e.slice($+_.length);e=`${Ft}${Re}${Gt}`,T.lastIndex+=Re.length-l.length-ge.length-Ne.length,a.forEach(j=>j.hasRecursedWithin=!0),o=!0}else if(f)c++,n.set(String(c),T.lastIndex),n.set(f,T.lastIndex),a.push({num:c,name:f});else if(l.startsWith("(")){let b=l==="(";b&&(c++,n.set(String(c),T.lastIndex)),a.push(b?{num:c}:{})}else l===")"&&a.pop()}return e}function xt(e){let t=`Max depth must be integer between 2 and 100; used ${e}`;if(!/^[1-9]\d*$/.test(e))throw new Error(t);if(e=+e,e<2||e>100)throw new Error(t)}function St(e,t,r,s,n){let a=new Set;s&&Ye(e+t,fe,({groups:{captureName:i}})=>{a.add(i)},S.DEFAULT);let o=r-1;return`${e}${_t(`(?:${e}`,o,s?a:null,"forward",n)}(?:)${_t(`${t})`,o,s?a:null,"backward",n)}${t}`}function _t(e,t,r,s,n){let o=c=>s==="backward"?t-c+2-1:c+2,i="";for(let c=0;c<t;c++){let p=o(c);i+=U(e,G`${fe}|\\k<(?<backref>[^>]+)>${n?G`|\((?!\?)`:""}`,({0:l,groups:{captureName:f,backref:w}})=>{if(w&&r&&!r.has(w))return l;if(l==="(")return`(${At}`;let g=`_$${p}`;return f?`(?<${f}${g}>${n?At:""}`:G`\k<${w}${g}>`},S.DEFAULT)}return i}function vt(e,t){let r=re(t),s=z(e,r.flags,{captureGroup:r.rules.captureGroup}),n=Z(s,{skipBackrefValidation:r.rules.allowOrphanBackrefs,verbose:r.verbose}),a=lt(n,{accuracy:r.accuracy,allowUnhandledGAnchors:r.rules.allowUnhandledGAnchors,asciiWordBoundaries:r.rules.asciiWordBoundaries,avoidSubclass:r.avoidSubclass,bestEffortTarget:r.target}),o=Et(a,r),i={useEmulationGroups:!r.avoidSubclass},c={pattern:_e($e($t(o.pattern,i)),i),flags:`${r.hasIndices?"d":""}${r.global?"g":""}${o.flags}${o.options.disable.v?"u":"v"}`},l=c.pattern.includes("$E$")&&!r.avoidSubclass;return(l||a._strategy)&&(c.subclass={useEmulationGroups:l,strategy:a._strategy??null}),c}function Jr(e,t){let r=t?.flags??"",s=t?.rules?.captureGroup??!1;return Z(z(e,r,{captureGroup:s}))}function Yr(e,t){let r=vt(e,t);return r.subclass?new ee(r.pattern,r.flags,r.subclass):new RegExp(r.pattern,r.flags)}return Ot(en);})(); | ||
\v\f\x85\u2028\u2029])`));else if(n===z.grapheme){if(r==="strict")throw new Error(h`Use of "\X" requires non-strict accuracy`);let a=s?h`\p{RGI_Emoji}`:ct().source.replace(/\\u\{/g,"\\x{");t(G(h`(?>\r\n|${a}|\P{M}\p{M}*)`,{skipPropertyNameValidation:!0}))}else throw new Error(`Unexpected varcharset kind "${n}"`)}},ft={Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByReferencer:r}){let{orphan:s,ref:n}=e;s||r.set(e,[...t.get(n).map(({node:a})=>a)])},CapturingGroup:{enter({node:e,replaceWith:t,skip:r},{groupOriginByCopy:s,groupsByName:n,multiplexCapturesToLeftByRef:a,openRefs:o,reffedNodesByReferencer:i}){let c=s.get(e);if(c&&o.has(e.number)){let l=ut(e.number);i.set(l,o.get(e.number)),t(l),r();return}o.set(e.number,e),a.set(e.number,[]),e.name&&B(a,e.name,[]);let p=a.get(e.name??e.number);for(let l=0;l<p.length;l++){let f=p[l];if(c===f.node||c&&c===f.origin||e===f.origin){p.splice(l,1);break}}if(a.get(e.number).push({node:e,origin:c}),e.name&&a.get(e.name).push({node:e,origin:c}),e.name){let l=B(n,e.name,new Map),f=!1;if(c)f=!0;else for(let w of l.values())if(!w.hasDuplicateNameToRemove&>(w.node,e,{ancestorsParticipate:!0})){f=!0;break}n.get(e.name).set(e,{node:e,hasDuplicateNameToRemove:f})}c&&(e._originNumber=c.number)},exit({node:e},{openRefs:t}){t.delete(e.number)}},Group:{enter({node:e},t){t.prevFlags=t.currentFlags,e.flags&&(t.currentFlags=L(t.currentFlags,e.flags))},exit(e,t){t.currentFlags=t.prevFlags}},Recursion({node:e,parent:t},{reffedNodesByReferencer:r}){let{ref:s}=e,n=t;for(;(n=n.parent)&&!(n.type===u.CapturingGroup&&(n.name===s||n.number===s)););r.set(e,n)},Subroutine(e,t){let{node:r,replaceWith:s}=e,{ref:n}=r,a=t.subroutineRefMap.get(n),o=n===0,i=o?ut(0):ht(a,t.groupOriginByCopy,null),c=i;if(!o){let p=dt(vr(a,f=>f.type===u.Group&&!!f.flags)),l=p?L(t.globalFlags,p):t.globalFlags;_r(l,t.currentFlags)||(c=re(P({flags:Fr(l)}),[i]))}s(c),o||kt(c,e,t,ft)}},Sr={Backreference({node:e,replaceWith:t},r){if(e.orphan){r.highestOrphanBackref=Math.max(r.highestOrphanBackref,e.ref);return}let n=r.reffedNodesByReferencer.get(e).filter(a=>gt(a,e,{ancestorsParticipate:!1}));if(!n.length)t(ue({negate:!0}));else if(n.length>1){let a=n.map(o=>pe(O(),[ie(o.number)]));t(pe(P(),a))}else e.ref=n[0].number},CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,e.name&&t.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Recursion({node:e},t){e.ref!==0&&(e.ref=t.reffedNodesByReferencer.get(e).number)},Regex:{exit({node:e},t){let r=Math.max(t.highestOrphanBackref-t.numCapturesToLeft,0);for(let s=0;s<r;s++){let n=Ae();e.pattern.alternatives.at(-1).elements.push(n)}}}},$r="[ -\r ]",R=h`[\p{L}\p{M}\p{N}\p{Pc}]`;function pe(e,t){return t.forEach(r=>r.parent=e),e[Ie(e)]=t,e}function _r(e,t){return e.dotAll===t.dotAll&&e.ignoreCase===t.ignoreCase}function gt(e,t,{ancestorsParticipate:r}){let s=t;do{if(s.type===u.Pattern)return!1;if(s.type===u.Alternative)continue;if(s===e)return r;let n=Ct(s.parent);for(let a of n){if(a===s)break;if(a===e||wt(a,e))return!0}}while(s=s.parent);throw new Error("Unexpected path")}function ht(e,t,r,s){let n=Array.isArray(e)?[]:{};for(let[a,o]of Object.entries(e))a==="parent"?n.parent=Array.isArray(r)?s:r:o&&typeof o=="object"?n[a]=ht(o,t,n,r):(a==="type"&&o===u.CapturingGroup&&t.set(n,t.get(e)??e),n[a]=o);return n}function ut(e){return{type:u.Recursion,ref:e}}function vr(e,t){let r=[];for(;e=e.parent;)(!t||t(e))&&r.push(e);return r}function Ie(e){for(let t of["alternatives","classes","elements"])if(e[t])return t;return null}function dt(e){let t=["dotAll","ignoreCase"],r={enable:{},disable:{}};return e.forEach(({flags:s})=>{t.forEach(n=>{s.enable?.[n]&&(delete r.disable[n],r.enable[n]=!0),s.disable?.[n]&&(r.disable[n]=!0)})}),Object.keys(r.enable).length||delete r.enable,Object.keys(r.disable).length||delete r.disable,r.enable||r.disable?r:null}function Fr({dotAll:e,ignoreCase:t}){let r={};return(e||t)&&(r.enable={},e&&(r.enable.dotAll=!0),t&&(r.enable.ignoreCase=!0)),(!e||!t)&&(r.disable={},!e&&(r.disable.dotAll=!0),!t&&(r.disable.ignoreCase=!0)),r}function Ct(e){if(!e)throw new Error("Node expected");if(e.type===u.Quantifier)return[e.element];let t=Ie(e);return t&&e[t]}function mt(e){let t=e.find(r=>r.kind===m.search_start||le(r,{negate:!1})||!oe(r));if(!t)return null;if(t.kind===m.search_start)return t;if(M(t))return t.alternatives[0].elements[0];if(t.type===u.Group||t.type===u.CapturingGroup){let r=[];for(let s of t.alternatives){let n=mt(s.elements);if(!n)return null;Array.isArray(n)?r.push(...n):r.push(n)}return r}return null}function wt(e,t){let r=Ct(e)??[];for(let s of r)if(s===t||wt(s,t))return!0;return!1}function Ir(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function G(e,t){let s=J(X(e),t).pattern.alternatives;return s.length>1||s[0].elements.length>1?pe(P(),s):s[0].elements[0]}function re(e,t){let r=Ie(e);return e[r][0].parent=e,t&&pe(e[r][0],t),e}function Fe(e,t){return e.negate=t,e}function kt(e,{parent:t,key:r,container:s},n,a){N({node:e,parent:t,key:r,container:s},n,a)}function bt(e,t){let r=ne(t),s=H(r.target,"ES2024"),n=H(r.target,"ES2025"),a=r.maxRecursionDepth;if(a!==null&&(!Number.isInteger(a)||a<2||a>100))throw new Error("Invalid maxRecursionDepth; use 2-100 or null");let o=null,i=null;if(!n){let g=[e.flags.ignoreCase];N({node:e},{getCurrentModI:()=>g.at(-1),popModI(){g.pop()},pushModI(y){g.push(y)},setHasCasedChar(){g.at(-1)?o=!0:i=!0}},Gr)}let c={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||o)&&!i)},p=null,l={accuracy:r.accuracy,appliedGlobalFlags:c,avoidSubclass:r.avoidSubclass,captureMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},groupNames:new Set,inCharClass:!1,lastNode:p,maxRecursionDepth:a,useAppliedIgnoreCase:!!(!n&&o&&i),useDuplicateNames:n,useFlagMods:n,useFlagV:s,verbose:r.verbose};function f(g){switch(l.lastNode=p,p=g,g.type){case u.Regex:return{pattern:f(g.pattern),flags:f(g.flags),options:{...g.options}};case u.Alternative:return g.elements.map(f).join("");case u.Assertion:return Ur(g,l,f);case u.Backreference:return Or(g,l);case u.CapturingGroup:return Dr(g,l,f);case u.Character:return Tr(g,l);case u.CharacterClass:return Lr(g,l,f);case u.CharacterClassIntersection:if(!l.useFlagV)throw new Error("Use of class intersection requires min target ES2024");return g.classes.map(f).join("&&");case u.CharacterClassRange:return Br(g,l);case u.CharacterSet:return Vr(g,l);case u.Flags:return jr(g,l);case u.Group:return Wr(g,l,f);case u.Pattern:return g.alternatives.map(f).join("|");case u.Quantifier:return f(g.element)+Xr(g);case u.Recursion:return Hr(g,l);default:throw new Error(`Unexpected node type "${g.type}"`)}}let w=f(e);return s||(delete w.options.force.v,w.options.disable.v=!0,w.options.unicodeSetsPlugin=null),w}var Gr={AnyGroup:{enter({node:e},t){let r=t.getCurrentModI();t.pushModI(e.flags?L({ignoreCase:r},e.flags).ignoreCase:r)},exit(e,t){t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){Ge(x(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),xt(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind===k.property&&be.has(e.value)&&t.setHasCasedChar()}},Mr=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),Nr=new Set(["-","\\","]","^","["]),Pr=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),yt=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`]]),Rr=/^\p{Cased}$/u;function Ge(e){return Rr.test(e)}function Ur(e,t,r){let{kind:s,negate:n,alternatives:a}=e;if(M(e))return`(?${`${s===m.lookahead?"":"<"}${n?"!":"="}`}${a.map(r).join("|")})`;if(s===m.string_end)return"$";if(s===m.string_start)return"^";if(s===m.word_boundary)return n?h`\B`:h`\b`;throw new Error(`Unexpected assertion kind "${s}"`)}function Or({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&t.accuracy==="strict"&&t.currentFlags.ignoreCase&&!t.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}function Dr({name:e,number:t,alternatives:r,_originNumber:s},n,a){return e&&(n.groupNames.has(e)?n.useDuplicateNames||(e=null):n.groupNames.add(e)),n.captureMap.set(t,{ignoreCase:n.currentFlags.ignoreCase}),`(${e?`?<${e}>`:""}${!n.avoidSubclass&&s?`${s<t?`$${s}`:""}${v}`:""}${r.map(a).join("|")})`}function Tr({value:e},t){let r=x(e),s=j(e,{isAfterBackref:t.lastNode.type===u.Backreference,inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(s!==r)return s;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&Ge(r)){let n=me(r);return t.inCharClass?n.join(""):n.length>1?`[${n.join("")}]`:n[0]}return r}function Lr({negate:e,parent:t,elements:r},s,n){let a=()=>`[${e?"^":""}${r.map(n).join("")}]`;if(!s.inCharClass){s.inCharClass=!0;let i=a();return s.inCharClass=!1,i}let o=r[0].type;if(!e&&(!s.useFlagV||!s.verbose)&&t.type===u.CharacterClass&&o!==u.CharacterClassIntersection||!s.verbose&&t.type===u.CharacterClassIntersection&&r.length===1&&o!==u.CharacterClass&&o!==u.CharacterClassRange)return r.map(n).join("");if(!s.useFlagV&&t.type===u.CharacterClass)throw new Error("Use of nested character class requires min target ES2024");return a()}function Br(e,t){let r=e.min.value,s=e.max.value,n={isAfterBackref:!1,inCharClass:!0,useFlagV:t.useFlagV},a=j(r,n),o=j(s,n),i="";if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){let c=xt(e);Kr(c).forEach(l=>{i+=Array.isArray(l)?`${j(l[0],n)}-${j(l[1],n)}`:j(l,n)})}return`${a}-${o}${i}`}function Vr({kind:e,negate:t,value:r,key:s},n){if(e===k.dot)return n.currentFlags.dotAll?n.appliedGlobalFlags.dotAll||n.useFlagMods?".":"[^]":h`[^\n]`;if(e===k.digit)return t?h`\D`:h`\d`;if(e===k.property){if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase&&be.has(r))throw new Error(`Unicode property "${r}" can't be case-insensitive when other chars have specific case`);return`${t?h`\P`:h`\p`}{${s?`${s}=`:""}${r}}`}if(e===k.word)return t?h`\W`:h`\w`;throw new Error(`Unexpected character set kind "${e}"`)}function jr(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")}function Wr({atomic:e,flags:t,parent:r,alternatives:s},n,a){let o=n.currentFlags;t&&(n.currentFlags=L(o,t));let i=s.map(a).join("|"),c=!n.verbose&&s.length===1&&r.type!==u.Quantifier&&!e&&(!n.useFlagMods||!t)?i:`(?${Qr(e,t,n.useFlagMods)}${i})`;return n.currentFlags=o,c}function Hr({ref:e},t){let r=t.maxRecursionDepth;if(!r)throw new Error("Use of recursion disabled");if(t.accuracy==="strict")throw new Error("Use of recursion requires non-strict accuracy due to depth limit");return e===0?`(?R=${r})`:h`\g<${e}&R=${r}>`}function xt(e,t){let r=!!t?.firstOnly,s=e.min.value,n=e.max.value,a=[];if(s<65&&(n===65535||n>=131071)||s===65536&&n>=131071)return a;for(let o=s;o<=n;o++){let i=x(o);if(!Ge(i))continue;let c=me(i).filter(p=>{let l=p.codePointAt(0);return l<s||l>n});if(c.length&&(a.push(...c),r))break}return a}function j(e,{isAfterBackref:t,inCharClass:r,useFlagV:s}){if(yt.has(e))return yt.get(e);if(e<32||e>126&&e<160||e>262143||t&&qr(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;let n=r?s?Pr:Nr:Mr,a=x(e);return(n.has(a)?"\\":"")+a}function Kr(e){let t=e.map(n=>n.codePointAt(0)).sort((n,a)=>n-a),r=[],s=null;for(let n=0;n<t.length;n++)t[n+1]===t[n]+1?s??=t[n]:s===null?r.push(t[n]):(r.push([s,t[n]]),s=null);return r}function Qr(e,t,r){if(e)return">";let s="";if(t&&r){let{enable:n,disable:a}=t;s=(n?.ignoreCase?"i":"")+(n?.dotAll?"s":"")+(a?"-":"")+(a?.ignoreCase?"i":"")+(a?.dotAll?"s":"")}return`${s}:`}function Xr({min:e,max:t,greedy:r,possessive:s}){let n;return!e&&t===1?n="?":!e&&t===1/0?n="*":e===1&&t===1/0?n="+":e===t?n=`{${e}}`:n=`{${e},${t===1/0?"":t}}`,n+(s?"+":r?"":"?")}function qr(e){return e>47&&e<58}var $=String.raw,zr=$`\\g<(?<gRNameOrNum>[^>&]+)&R=(?<gRDepth>[^>]+)>`,Ne=$`\(\?R=(?<rDepth>[^\)]+)\)|${zr}`,fe=$`\(\?<(?![=!])(?<captureName>[^>]+)>`,D=new RegExp($`${fe}|${Ne}|\(\?|\\?.`,"gsu"),Me="Cannot use multiple overlapping recursions",Pe=new RegExp($`(?:\$[1-9]\d*)?${v.replace(/\$/g,$`\$`)}`,"y");function $t(e,t){if(!new RegExp(Ne,"su").test(e))return e;if(Y(e,$`\(\?\(DEFINE\)`,S.DEFAULT))throw new Error("DEFINE groups cannot be used with recursion");let r=!!t?.useEmulationGroups,s=Y(e,$`\\[1-9]`,S.DEFAULT),n=new Map,a=[],o=!1,i=0,c=0,p;for(D.lastIndex=0;p=D.exec(e);){let{0:l,groups:{captureName:f,rDepth:w,gRNameOrNum:g,gRDepth:y}}=p;if(l==="[")i++;else if(i)l==="]"&&i--;else if(w){if(Et(w),o)throw new Error(Me);if(s)throw new Error("Numbered backrefs cannot be used with global recursion");let b=e.slice(0,p.index),F=e.slice(D.lastIndex);if(Y(F,Ne,S.DEFAULT))throw new Error(Me);return At(b,F,+w,!1,r)}else if(g){Et(y);let b=!1;for(let W of a)if(W.name===g||W.num===+g){if(b=!0,W.hasRecursedWithin)throw new Error(Me);break}if(!b)throw new Error($`Recursive \g cannot be used outside the referenced group "\g<${g}&R=${y}>"`);let F=n.get(g),_=et(e,F);if(s&&Y(_,$`${fe}|\((?!\?)`,S.DEFAULT))throw new Error("Numbered backrefs cannot be used with recursion of capturing groups");let ge=e.slice(F,p.index),Re=_.slice(ge.length+l.length),Ue=At(ge,Re,+y,!0,r),vt=e.slice(0,F),Ft=e.slice(F+_.length);e=`${vt}${Ue}${Ft}`,D.lastIndex+=Ue.length-l.length-ge.length-Re.length,a.forEach(W=>W.hasRecursedWithin=!0),o=!0}else if(f)c++,n.set(String(c),D.lastIndex),n.set(f,D.lastIndex),a.push({num:c,name:f});else if(l.startsWith("(")){let b=l==="(";b&&(c++,n.set(String(c),D.lastIndex+(r?Zr(e,D.lastIndex):0))),a.push(b?{num:c}:{})}else l===")"&&a.pop()}return e}function Et(e){let t=`Max depth must be integer between 2 and 100; used ${e}`;if(!/^[1-9]\d*$/.test(e))throw new Error(t);if(e=+e,e<2||e>100)throw new Error(t)}function At(e,t,r,s,n){let a=new Set;s&&Ye(e+t,fe,({groups:{captureName:i}})=>{a.add(i)},S.DEFAULT);let o=r-1;return`${e}${St(`(?:${e}`,o,s?a:null,"forward",n)}(?:)${St(`${t})`,o,s?a:null,"backward",n)}${t}`}function St(e,t,r,s,n){let o=c=>s==="backward"?t-c+2-1:c+2,i="";for(let c=0;c<t;c++){let p=o(c);i+=T(e,$`${fe}|\\k<(?<backref>[^>]+)>${n?$`|(?<unnamed>\()(?!\?)(?:${Pe.source})?`:""}`,({0:l,index:f,groups:{captureName:w,backref:g,unnamed:y}})=>{if(g&&r&&!r.has(g))return l;if(y)return`(${v}`;let b=`_$${p}`;return w?`(?<${w}${b}>${n?v:""}`:$`\k<${g}${b}>`},S.DEFAULT)}return i}function Zr(e,t){Pe.lastIndex=t;let r=Pe.exec(e);return r?r[0].length:0}function _t(e,t){let r=ne(t),s=r.avoidSubclass,n=X(e,r.flags,{captureGroup:r.rules.captureGroup}),a=J(n,{skipBackrefValidation:r.rules.allowOrphanBackrefs,verbose:r.verbose}),o=lt(a,{accuracy:r.accuracy,asciiWordBoundaries:r.rules.asciiWordBoundaries,avoidSubclass:s,bestEffortTarget:r.target,ignoreUnsupportedGAnchors:r.rules.ignoreUnsupportedGAnchors}),i=bt(o,r),c={useEmulationGroups:!s},p={pattern:$e(_e($t(i.pattern,c)),c),flags:`${r.hasIndices?"d":""}${r.global?"g":""}${i.flags}${i.options.disable.v?"u":"v"}`},l=!s&&p.pattern.includes(v);return(l||o._strategy)&&(p.subclass={useEmulationGroups:l,strategy:o._strategy??null}),p}function Jr(e,t){let r=t?.flags??"",s=t?.rules?.captureGroup??!1;return J(X(e,r,{captureGroup:s}))}function Yr(e,t){let r=_t(e,t);return r.subclass?new te(r.pattern,r.flags,r.subclass):new RegExp(r.pattern,r.flags)}return Rt(en);})(); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "oniguruma-to-es", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"description": "Convert Oniguruma patterns to native JavaScript RegExp", | ||
@@ -18,3 +18,3 @@ "author": "Steven Levithan", | ||
"bundle:global": "esbuild src/index.js --global-name=OnigurumaToES --bundle --minify --sourcemap --outfile=dist/index.min.js", | ||
"bundle:esm": "esbuild src/index.js --format=esm --bundle --sourcemap --outfile=dist/index.mjs", | ||
"bundle:esm": "esbuild src/index.js --format=esm --bundle --sourcemap --external:emoji-regex-xs --external:regex --external:regex-recursion --outfile=dist/index.mjs", | ||
"types": "tsc src/index.js --rootDir src --declaration --allowJs --emitDeclarationOnly --outDir types", | ||
@@ -41,3 +41,2 @@ "prebuild": "rm -rf dist/* types/*", | ||
"oniguruma", | ||
"onigmo", | ||
"textmate-grammar", | ||
@@ -48,11 +47,11 @@ "transpiler" | ||
"emoji-regex-xs": "^1.0.0", | ||
"regex": "^5.0.2", | ||
"regex-recursion": "^5.0.0" | ||
"regex": "^5.1.1", | ||
"regex-recursion": "^5.1.1" | ||
}, | ||
"devDependencies": { | ||
"esbuild": "^0.24.0", | ||
"esbuild": "^0.24.2", | ||
"jasmine": "^5.5.0", | ||
"typescript": "^5.7.2", | ||
"typescript": "~5.7.2", | ||
"vscode-oniguruma": "^2.0.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Oniguruma-To-ES | ||
# Oniguruma-To-ES (鬼車➟ES) | ||
@@ -7,3 +7,3 @@ [![npm version][npm-version-src]][npm-version-href] | ||
An **[Oniguruma](https://github.com/kkos/oniguruma) to JavaScript regex transpiler** that runs in the browser and on your server. Use it to: | ||
An **[Oniguruma](https://github.com/kkos/oniguruma) to JavaScript regex translator** that runs in the browser and on your server. Use it to: | ||
@@ -18,4 +18,6 @@ - Take advantage of Oniguruma's many extended regex features in JavaScript. | ||
Oniguruma-To-ES deeply understands the hundreds of large and small differences between Oniguruma and JavaScript regex syntax and behavior, across multiple JavaScript version targets. It's *obsessive* about ensuring that the emulated features it supports have **exactly the same behavior**, even in extreme edge cases. And it's been battle-tested on thousands of real-world Oniguruma regexes used in TextMate grammars (via the Shiki library). A few uncommon features can't be perfectly emulated and allow rare differences, but if you don't want to allow this, you can set the `accuracy` option to throw for such patterns (see details below). | ||
Oniguruma-To-ES deeply understands the hundreds of large and small differences between Oniguruma and JavaScript regex syntax and behavior, across multiple JavaScript version targets. It's *obsessive* about ensuring that the emulated features it supports have **exactly the same behavior**, even in extreme edge cases. And it's been battle-tested on thousands of real-world Oniguruma regexes used in TextMate grammars (via the Shiki library). | ||
Depending on features used, Oniguruma-To-ES might use advanced emulation via a `RegExp` subclass (that remains a native JavaScript regular expression). A few uncommon features can't be perfectly emulated and allow rare differences, but if you don't want to allow this, you can set the `accuracy` option to throw for such patterns (see details below). | ||
## 📜 Contents | ||
@@ -28,3 +30,3 @@ | ||
- [Unsupported features](#-unsupported-features) | ||
- [Unicode / mixed case-sensitivity](#️-unicode--mixed-case-sensitivity) | ||
- [Unicode](#️-unicode) | ||
@@ -85,5 +87,5 @@ ## 🕹️ Install and use | ||
allowOrphanBackrefs?: boolean; | ||
allowUnhandledGAnchors?: boolean; | ||
asciiWordBoundaries?: boolean; | ||
captureGroup?: boolean; | ||
ignoreUnsupportedGAnchors?: boolean; | ||
}; | ||
@@ -180,3 +182,3 @@ target?: 'auto' | 'ES2025' | 'ES2024' | 'ES2018'; | ||
- An error is thrown for certain patterns that are not emulatable without a subclass. | ||
- When the regex can still be emulated accurately, *subpattern* match details (accessed via properties of match objects returned when using the regex) might differ from Oniguruma. | ||
- When the regex can still be emulated accurately, *subpattern* match details (accessed via properties of match results when using the regex) might differ from Oniguruma. | ||
@@ -223,6 +225,6 @@ ### `flags` | ||
- `allowOrphanBackrefs`: Useful with TextMate grammars that merge backreferences across patterns. | ||
- `allowUnhandledGAnchors`: Removes unsupported uses of `\G`, rather than erroring. | ||
- Oniguruma-To-ES uses a variety of strategies to accurately emulate many common uses of `\G`. When using this option, if a `\G` is found that doesn't have a known emulation strategy, the `\G` is simply removed. This might lead to some false positive matches, but is useful for non-critical matching (like syntax highlighting) when having some mismatches is better than not working. | ||
- `asciiWordBoundaries`: Use ASCII-based `\b` and `\B`, which increases search performance of generated regexes. | ||
- `captureGroup`: Oniguruma option `ONIG_OPTION_CAPTURE_GROUP`. Unnamed captures and numbered calls allowed when using named capture. | ||
- `ignoreUnsupportedGAnchors`: Removes unsupported uses of `\G`, rather than erroring. | ||
- Oniguruma-To-ES uses a variety of strategies to accurately emulate many common uses of `\G`. When using this option, if a `\G` is found that doesn't have a known emulation strategy, the `\G` is simply removed. This might lead to some false positive matches, but is useful for non-critical matching (like syntax highlighting) when having some mismatches is better than not working. | ||
@@ -239,3 +241,3 @@ ### `target` | ||
- `ES2018`: Uses JS flag `u`. | ||
- Emulation restrictions: Character class intersection, nested negated character classes, and Unicode properties added after ES2018 are not allowed. | ||
- Emulation restrictions: Character class intersection and nested negated character classes are not allowed. | ||
- Generated regexes might use ES2018 features that require Node.js 10 or a browser version released during 2018 to 2023 (in Safari's case). Minimum requirement for any regex is Node.js 6 or a 2016-era browser. | ||
@@ -525,4 +527,4 @@ - `ES2024`: Uses JS flag `v`. | ||
</td> | ||
<td align="middle">✅<sup>[1]</sup></td> | ||
<td align="middle">✅</td> | ||
<td align="middle">✅</td> | ||
<td> | ||
@@ -539,3 +541,3 @@ ✔ Binary properties<br> | ||
✔ Error for props of strings<br> | ||
❌ Blocks (wontfix<sup>[2]</sup>)<br> | ||
❌ Blocks (wontfix<sup>[1]</sup>)<br> | ||
</td> | ||
@@ -602,3 +604,3 @@ </tr> | ||
</td> | ||
<td align="middle">☑️<sup>[3]</sup></td> | ||
<td align="middle">☑️<sup>[2]</sup></td> | ||
<td align="middle">✅</td> | ||
@@ -612,3 +614,3 @@ <td> | ||
<td><code>[…[…]]</code></td> | ||
<td align="middle">☑️<sup>[4]</sup></td> | ||
<td align="middle">☑️<sup>[3]</sup></td> | ||
<td align="middle">✅</td> | ||
@@ -665,3 +667,3 @@ <td> | ||
<td> | ||
● Common uses supported<br> | ||
● Common uses supported<sup>[4]</sup><br> | ||
</td> | ||
@@ -946,10 +948,10 @@ </tr> | ||
The table above doesn't include all aspects that Oniguruma-To-ES emulates (including error handling, most aspects that work the same as in JavaScript, and many aspects of non-JavaScript features that work the same in the other regex flavors that support them). | ||
The table above doesn't include all aspects that Oniguruma-To-ES emulates (including error handling, most aspects that work the same as in JavaScript, and many aspects of non-JavaScript features that work the same in the other regex flavors that support them). Where applicable, Oniguruma-To-ES follows the latest version of Oniguruma (currently 6.9.9). | ||
### Footnotes | ||
1. Target `ES2018` doesn't allow using Unicode property names added in JavaScript specifications after ES2018. | ||
2. Unicode blocks (which in Oniguruma are used with an `In…` prefix) are easily emulatable but their character data would significantly increase library weight. They're also a flawed and arguably unuseful feature, given the ability to use Unicode scripts and other properties. | ||
3. With target `ES2018`, the specific POSIX classes `[:graph:]` and `[:print:]` use ASCII-based versions rather than the Unicode versions available for target `ES2024` and later, and they result in an error if using strict `accuracy`. | ||
4. Target `ES2018` doesn't support nested *negated* character classes. | ||
1. Unicode blocks (which in Oniguruma are used with an `In…` prefix) are easily emulatable but their character data would significantly increase library weight. They're also a flawed and arguably unuseful feature, given the ability to use Unicode scripts and other properties. | ||
2. With target `ES2018`, the specific POSIX classes `[:graph:]` and `[:print:]` use ASCII-based versions rather than the Unicode versions available for target `ES2024` and later, and they result in an error if using strict `accuracy`. | ||
3. Target `ES2018` doesn't support nested *negated* character classes. | ||
4. Examples of supported uses of `\G` include `\G…`, `\G…|\G…`, `(?<=…)\G…`, `(^|\G)…`, `(?!\G)…`, and many others. | ||
5. It's not an error for *numbered* backreferences to come before their referenced group in Oniguruma, but an error is the best path for Oniguruma-To-ES because (1) most placements are mistakes and can never match (based on the Oniguruma behavior for backreferences to nonparticipating groups), (2) erroring matches the behavior of named backreferences, and (3) the edge cases where they're matchable rely on rules for backreference resetting within quantified groups that are different in JavaScript and aren't emulatable. Note that it's not a backreference in the first place if using `\10` or higher and not as many capturing groups are defined to the left (it's an octal or identity escape). | ||
@@ -960,3 +962,3 @@ 6. The recursion depth limit is specified by option `maxRecursionDepth`. Overlapping recursions and the use of backreferences when the recursed subpattern contains captures aren't yet supported. Patterns that would error in Oniguruma due to triggering infinite recursion might find a match in Oniguruma-To-ES since recursion is bounded (future versions will detect this and error at transpilation time). | ||
The following don't yet have any support, and throw errors. They're all infrequently-used features, with most being *extremely* rare. Note that Oniguruma-To-ES can handle 99.9% of real-world Oniguruma regexes, based on patterns used in a large [collection](https://github.com/shikijs/textmate-grammars-themes/tree/main/packages/tm-grammars/grammars) of TextMate grammars. | ||
The following don't yet have any support, and throw errors. They're all infrequently-used features, with most being *extremely* rare. Note that Oniguruma-To-ES can handle ~99.9% of real-world Oniguruma regexes, based on patterns used in a large [collection](https://github.com/shikijs/textmate-grammars-themes/tree/main/packages/tm-grammars/grammars) of TextMate grammars. | ||
@@ -976,16 +978,18 @@ - Supportable: | ||
## ㊗️ Unicode / mixed case-sensitivity | ||
<a name="unicode"></a> | ||
## ㊗️ Unicode | ||
Oniguruma-To-ES fully supports mixed case-sensitivity (and handles the Unicode edge cases) regardless of JavaScript [target](#target). It also restricts Unicode properties to those supported by Oniguruma and the target JavaScript version. | ||
Oniguruma-To-ES fully supports mixed case-sensitivity (ex: `(?i)a(?-i)a`) and handles the Unicode edge cases regardless of JavaScript [target](#target). | ||
Oniguruma-To-ES focuses on being lightweight to make it better for use in browsers. This is partly achieved by not including heavyweight Unicode character data, which imposes a couple of minor/rare restrictions: | ||
Oniguruma-To-ES focuses on being lightweight to make it better for use in browsers. This is partly achieved by not including heavyweight Unicode character data, which imposes a few minor/rare restrictions: | ||
- Character class intersection and nested negated character classes are unsupported with target `ES2018`. Use target `ES2024` or later if you need support for these features. | ||
- Character class intersection and nested negated character classes are unsupported with target `ES2018`. Use target `ES2024` (supported by Node.js 20 and 2023-era browsers) or later if you need support for these features. | ||
- With targets before `ES2025`, a handful of Unicode properties that target a specific character case (ex: `\p{Lower}`) can't be used case-insensitively in patterns that contain other characters with a specific case that are used case-sensitively. | ||
- In other words, almost every usage is fine, including `A\p{Lower}`, `(?i:A\p{Lower})`, `(?i:A)\p{Lower}`, `(?i:A(?-i:\p{Lower}))`, and `\w(?i:\p{Lower})`, but not `A(?i:\p{Lower})`. | ||
- Using these properties case-insensitively is basically never done intentionally, so you're unlikely to encounter this error unless it's catching a mistake. | ||
- Oniguruma-To-ES uses the version of Unicode supported natively by your JavaScript environment. Using Unicode properties via `\p{…}` that require a later version of Unicode than the environment supports results in a runtime error. This is an extreme edge case since modern JavaScript environments support recent versions of Unicode, often ahead of Oniguruma itself. | ||
## 👀 Similar projects | ||
[JsRegex](https://github.com/jaynetics/js_regex) transpiles [Onigmo](https://github.com/k-takata/Onigmo) regexes to JavaScript (Onigmo is a fork of Oniguruma with mostly shared syntax and behavior). It's written in Ruby and relies on the [Regexp::Parser](https://github.com/ammar/regexp_parser) Ruby gem, which means regexes must be pre-transpiled on the server to use them in JavaScript. Note that JsRegex doesn't always translate edge case behavior differences. | ||
[JsRegex](https://github.com/jaynetics/js_regex) transpiles [Onigmo](https://github.com/k-takata/Onigmo) regexes to JavaScript (Onigmo is a fork of Oniguruma with similar syntax and behavior). It's written in Ruby and relies on the [Regexp::Parser](https://github.com/ammar/regexp_parser) Ruby gem, which means regexes must be pre-transpiled on the server to use them in JavaScript. Note that JsRegex doesn't always translate edge case behavior differences. | ||
@@ -992,0 +996,0 @@ ## 🏷️ About |
@@ -10,5 +10,5 @@ export type OnigurumaToEsOptions = { | ||
allowOrphanBackrefs?: boolean; | ||
allowUnhandledGAnchors?: boolean; | ||
asciiWordBoundaries?: boolean; | ||
captureGroup?: boolean; | ||
ignoreUnsupportedGAnchors?: boolean; | ||
}; | ||
@@ -29,5 +29,5 @@ target?: "auto" | "ES2025" | "ES2024" | "ES2018"; | ||
allowOrphanBackrefs?: boolean; | ||
allowUnhandledGAnchors?: boolean; | ||
asciiWordBoundaries?: boolean; | ||
captureGroup?: boolean; | ||
ignoreUnsupportedGAnchors?: boolean; | ||
}; | ||
@@ -34,0 +34,0 @@ target?: keyof Target; |
@@ -32,6 +32,6 @@ export type RegexAst = { | ||
accuracy?: keyof Accuracy; | ||
allowUnhandledGAnchors?: boolean; | ||
asciiWordBoundaries?: boolean; | ||
avoidSubclass?: boolean; | ||
bestEffortTarget?: keyof Target; | ||
ignoreUnsupportedGAnchors?: boolean; | ||
}} [options] | ||
@@ -42,6 +42,6 @@ @returns {RegexAst} | ||
accuracy?: "default" | "strict"; | ||
allowUnhandledGAnchors?: boolean; | ||
asciiWordBoundaries?: boolean; | ||
avoidSubclass?: boolean; | ||
bestEffortTarget?: "auto" | "ES2025" | "ES2024" | "ES2018"; | ||
ignoreUnsupportedGAnchors?: boolean; | ||
}): RegexAst; |
@@ -5,3 +5,2 @@ export function getIgnoreCaseMatchChars(char: any): any[]; | ||
export const JsUnicodePropertiesOfStringsMap: any; | ||
export const JsUnicodePropertiesPostEs2018: any; | ||
export const PosixClassesMap: any; | ||
@@ -8,0 +7,0 @@ export const PosixProperties: any; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
997
636224
3734
Updatedregex@^5.1.1
Updatedregex-recursion@^5.1.1