function x(e){if([...e].length!==1)throw new Error(`Expected "${e}" to be a single code point`);return e.codePointAt(0)}function re(e,r,n){return e.has(r)||e.set(r,n),e.get(r)}const M=new Set(["alnum","alpha","ascii","blank","cntrl","digit","graph","lower","print","punct","space","upper","word","xdigit"]),h=String.raw;function $(e,r){if(e==null)throw new Error(r??"Value expected");return e}const Q=h`\[\^?`,T=`c.? | C(?:-.?)?|${h`[pP]\{(?:\^?[-\x20_]*[A-Za-z][-\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}`}`,U=/[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/,I=new RegExp(h`
  \\ (?:
    ${T}
    | [gk]<[^>]*>?
    | [gk]'[^']*'?
    | .
  )
  | \( (?:
    \? (?:
      [:=!>({]
      | <[=!]
      | <[^>]*>
      | '[^']*'
      | ~\|?
      | #(?:[^)\\]|\\.?)*
      | [^:)]*[:)]
    )?
    | \*[^\)]*\)?
  )?
  | (?:${U.source})+
  | ${Q}
  | .
`.replace(/\s+/g,""),"gsu"),G=new RegExp(h`
  \\ (?:
    ${T}
    | .
  )
  | \[:(?:\^?\p{Alpha}+|\^):\]
  | ${Q}
  | &&
  | .
`.replace(/\s+/g,""),"gsu");function te(e,r={}){const n={flags:"",...r,rules:{captureGroup:!1,singleline:!1,...r.rules}};if(typeof e!="string")throw new Error("String expected as pattern");const o=$e(n.flags),i=[o.extended],t={captureGroup:n.rules.captureGroup,getCurrentModX(){return i.at(-1)},numOpenGroups:0,popModX(){i.pop()},pushModX(c){i.push(c)},replaceCurrentModX(c){i[i.length-1]=c},singleline:n.rules.singleline};let a=[],s;for(I.lastIndex=0;s=I.exec(e);){const c=oe(t,e,s[0],I.lastIndex);c.tokens?a.push(...c.tokens):c.token&&a.push(c.token),c.lastIndex!==void 0&&(I.lastIndex=c.lastIndex)}const u=[];let l=0;a.filter(c=>c.type==="GroupOpen").forEach(c=>{c.kind==="capturing"?c.number=++l:c.raw==="("&&u.push(c)}),l||u.forEach((c,d)=>{c.kind="capturing",c.number=d+1});const f=l||u.length;return{tokens:a.map(c=>c.type==="EscapedNumber"?Ee(c,f):c).flat(),flags:o}}function oe(e,r,n,o){const[i,t]=n;if(n==="["||n==="[^"){const a=ae(r,n,o);return{tokens:a.tokens,lastIndex:a.lastIndex}}if(i==="\\"){if("AbBGyYzZ".includes(t))return{token:L(n,n)};if(/^\\g[<']/.test(n)){if(!/^\\g(?:<[^>]+>|'[^']+')$/.test(n))throw new Error(`Invalid group name "${n}"`);return{token:ge(n)}}if(/^\\k[<']/.test(n)){if(!/^\\k(?:<[^>]+>|'[^']+')$/.test(n))throw new Error(`Invalid group name "${n}"`);return{token:q(n)}}if(t==="K")return{token:K("keep",n)};if(t==="N"||t==="R")return{token:y("newline",n,{negate:t==="N"})};if(t==="O")return{token:y("any",n)};if(t==="X")return{token:y("text_segment",n)};const a=j(n,{inCharClass:!1});return Array.isArray(a)?{tokens:a}:{token:a}}if(i==="("){if(t==="*")return{token:ke(n)};if(n==="(?{")throw new Error(`Unsupported callout "${n}"`);if(n.startsWith("(?#")){if(r[o]!==")")throw new Error('Unclosed comment group "(?#"');return{lastIndex:o+1}}if(/^\(\?[-imx]+[:)]$/.test(n))return{token:ye(n,e)};if(e.pushModX(e.getCurrentModX()),e.numOpenGroups++,n==="("&&!e.captureGroup||n==="(?:")return{token:b("group",n)};if(n==="(?>")return{token:b("atomic",n)};if(n==="(?="||n==="(?!"||n==="(?<="||n==="(?<!")return{token:b(n[2]==="<"?"lookbehind":"lookahead",n,{negate:n.endsWith("!")})};if(n==="("&&e.captureGroup||n.startsWith("(?<")&&n.endsWith(">")||n.startsWith("(?'")&&n.endsWith("'"))return{token:b("capturing",n,{...n!=="("&&{name:n.slice(3,-1)}})};if(n.startsWith("(?~")){if(n==="(?~|")throw new Error(`Unsupported absence function kind "${n}"`);return{token:b("absence_repeater",n)}}throw n==="(?("?new Error(`Unsupported conditional "${n}"`):new Error(`Invalid or unsupported group option "${n}"`)}if(n===")"){if(e.popModX(),e.numOpenGroups--,e.numOpenGroups<0)throw new Error('Unmatched ")"');return{token:de(n)}}if(e.getCurrentModX()){if(n==="#"){const a=r.indexOf(`
`,o);return{lastIndex:a===-1?r.length:a}}if(/^\s$/.test(n)){const a=/\s+/y;return a.lastIndex=o,{lastIndex:a.exec(r)?a.lastIndex:o}}}if(n===".")return{token:y("dot",n)};if(n==="^"||n==="$"){const a=e.singleline?{"^":h`\A`,$:h`\Z`}[n]:n;return{token:L(a,n)}}return n==="|"?{token:se(n)}:U.test(n)?{tokens:Ae(n)}:{token:m(x(n),n)}}function ae(e,r,n){const o=[z(r[1]==="^",r)];let i=1,t;for(G.lastIndex=n;t=G.exec(e);){const a=t[0];if(a[0]==="["&&a[1]!==":")i++,o.push(z(a[1]==="^",a));else if(a==="]"){if(o.at(-1).type==="CharacterClassOpen")o.push(m(93,a));else if(i--,o.push(ue(a)),!i)break}else{const s=ie(a);Array.isArray(s)?o.push(...s):o.push(s)}}return{tokens:o,lastIndex:G.lastIndex||e.length}}function ie(e){if(e[0]==="\\")return j(e,{inCharClass:!0});if(e[0]==="["){const r=/\[:(?<negate>\^?)(?<name>[a-z]+):\]/.exec(e);if(!r||!M.has(r.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return y("posix",e,{value:r.groups.name,negate:!!r.groups.negate})}return e==="-"?ce(e):e==="&&"?le(e):m(x(e),e)}function j(e,{inCharClass:r}){const n=e[1];if(n==="c"||n==="C")return me(e);if("dDhHsSwW".includes(n))return be(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 "${e}"`);return xe(e)}if(new RegExp("^\\\\x[89A-Fa-f]\\p{AHex}","u").test(e))try{const o=e.split(/\\x/).slice(1).map(a=>parseInt(a,16)),i=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}).decode(new Uint8Array(o)),t=new TextEncoder;return[...i].map(a=>{const s=[...t.encode(a)].map(u=>`\\x${u.toString(16)}`).join("");return m(x(a),s)})}catch{throw new Error(`Multibyte code "${e}" incomplete or invalid in Oniguruma`)}if(n==="u"||n==="x")return m(Ce(e),e);if(R.has(n))return m(R.get(n),e);if(/\d/.test(n))return pe(r,e);if(e==="\\")throw new Error(h`Incomplete escape "\"`);if(n==="M")throw new Error(`Unsupported meta "${e}"`);if([...e].length===2)return m(e.codePointAt(1),e);throw new Error(`Unexpected escape "${e}"`)}function se(e){return{type:"Alternator",raw:e}}function L(e,r){return{type:"Assertion",kind:e,raw:r}}function q(e){return{type:"Backreference",raw:e}}function m(e,r){return{type:"Character",value:e,raw:r}}function ue(e){return{type:"CharacterClassClose",raw:e}}function ce(e){return{type:"CharacterClassHyphen",raw:e}}function le(e){return{type:"CharacterClassIntersector",raw:e}}function z(e,r){return{type:"CharacterClassOpen",negate:e,raw:r}}function y(e,r,n={}){return{type:"CharacterSet",kind:e,...n,raw:r}}function K(e,r,n={}){return e==="keep"?{type:"Directive",kind:e,raw:r}:{type:"Directive",kind:e,flags:$(n.flags),raw:r}}function pe(e,r){return{type:"EscapedNumber",inCharClass:e,raw:r}}function de(e){return{type:"GroupClose",raw:e}}function b(e,r,n={}){return{type:"GroupOpen",kind:e,...n,raw:r}}function fe(e,r,n,o){return{type:"NamedCallout",kind:e,tag:r,arguments:n,raw:o}}function he(e,r,n,o){return{type:"Quantifier",kind:e,min:r,max:n,raw:o}}function ge(e){return{type:"Subroutine",raw:e}}const we=new Set(["COUNT","CMP","ERROR","FAIL","MAX","MISMATCH","SKIP","TOTAL_COUNT"]),R=new Map([["a",7],["b",8],["e",27],["f",12],["n",10],["r",13],["t",9],["v",11]]);function me(e){const r=e[1]==="c"?e[2]:e[3];if(!r||!/[A-Za-z]/.test(r))throw new Error(`Unsupported control character "${e}"`);return m(x(r.toUpperCase())-64,e)}function ye(e,r){let{on:n,off:o}=/^\(\?(?<on>[imx]*)(?:-(?<off>[-imx]*))?/.exec(e).groups;o??="";const i=(r.getCurrentModX()||n.includes("x"))&&!o.includes("x"),t=X(n),a=X(o),s={};if(t&&(s.enable=t),a&&(s.disable=a),e.endsWith(")"))return r.replaceCurrentModX(i),K("flags",e,{flags:s});if(e.endsWith(":"))return r.pushModX(i),r.numOpenGroups++,b("group",e,{...(t||a)&&{flags:s}});throw new Error(`Unexpected flag modifier "${e}"`)}function ke(e){const r=/\(\*(?<name>[A-Za-z_]\w*)?(?:\[(?<tag>(?:[A-Za-z_]\w*)?)\])?(?:\{(?<args>[^}]*)\})?\)/.exec(e);if(!r)throw new Error(`Incomplete or invalid named callout "${e}"`);const{name:n,tag:o,args:i}=r.groups;if(!n)throw new Error(`Invalid named callout "${e}"`);if(o==="")throw new Error(`Named callout tag with empty value not allowed "${e}"`);const t=i?i.split(",").filter(f=>f!=="").map(f=>/^[+-]?\d+$/.test(f)?+f:f):[],[a,s,u]=t,l=we.has(n)?n.toLowerCase():"custom";switch(l){case"fail":case"mismatch":case"skip":if(t.length>0)throw new Error(`Named callout arguments not allowed "${t}"`);break;case"error":if(t.length>1)throw new Error(`Named callout allows only one argument "${t}"`);if(typeof a=="string")throw new Error(`Named callout argument must be a number "${a}"`);break;case"max":if(!t.length||t.length>2)throw new Error(`Named callout must have one or two arguments "${t}"`);if(typeof a=="string"&&!/^[A-Za-z_]\w*$/.test(a))throw new Error(`Named callout argument one must be a tag or number "${a}"`);if(t.length===2&&(typeof s=="number"||!/^[<>X]$/.test(s)))throw new Error(`Named callout optional argument two must be '<', '>', or 'X' "${s}"`);break;case"count":case"total_count":if(t.length>1)throw new Error(`Named callout allows only one argument "${t}"`);if(t.length===1&&(typeof a=="number"||!/^[<>X]$/.test(a)))throw new Error(`Named callout optional argument must be '<', '>', or 'X' "${a}"`);break;case"cmp":if(t.length!==3)throw new Error(`Named callout must have three arguments "${t}"`);if(typeof a=="string"&&!/^[A-Za-z_]\w*$/.test(a))throw new Error(`Named callout argument one must be a tag or number "${a}"`);if(typeof s=="number"||!/^(?:[<>!=]=|[<>])$/.test(s))throw new Error(`Named callout argument two must be '==', '!=', '>', '<', '>=', or '<=' "${s}"`);if(typeof u=="string"&&!/^[A-Za-z_]\w*$/.test(u))throw new Error(`Named callout argument three must be a tag or number "${u}"`);break;case"custom":throw new Error(`Undefined callout name "${n}"`);default:throw new Error(`Unexpected named callout kind "${l}"`)}return fe(l,o??null,i?.split(",")??null,e)}function V(e){let r=null,n,o;if(e[0]==="{"){const{minStr:i,maxStr:t}=/^\{(?<minStr>\d*)(?:,(?<maxStr>\d*))?/.exec(e).groups,a=1e5;if(+i>a||t&&+t>a)throw new Error("Quantifier value unsupported in Oniguruma");if(n=+i,o=t===void 0?+i:t===""?1/0:+t,n>o&&(r="possessive",[n,o]=[o,n]),e.endsWith("?")){if(r==="possessive")throw new Error('Unsupported possessive interval quantifier chain with "?"');r="lazy"}else r||(r="greedy")}else n=e[0]==="+"?1:0,o=e[0]==="?"?1:1/0,r=e[1]==="+"?"possessive":e[1]==="?"?"lazy":"greedy";return he(r,n,o,e)}function be(e){const r=e[1].toLowerCase();return y({d:"digit",h:"hex",s:"space",w:"word"}[r],e,{negate:e[1]!==r})}function xe(e){const{p:r,neg:n,value:o}=/^\\(?<p>[pP])\{(?<neg>\^?)(?<value>[^}]+)/.exec(e).groups;return y("property",e,{value:o,negate:r==="P"&&!n||r==="p"&&!!n})}function X(e){const r={};return e.includes("i")&&(r.ignoreCase=!0),e.includes("m")&&(r.dotAll=!0),e.includes("x")&&(r.extended=!0),Object.keys(r).length?r:null}function $e(e){const r={ignoreCase:!1,dotAll:!1,extended:!1,digitIsAscii:!1,posixIsAscii:!1,spaceIsAscii:!1,wordIsAscii:!1,textSegmentMode:null};for(let n=0;n<e.length;n++){const o=e[n];if(!"imxDPSWy".includes(o))throw new Error(`Invalid flag "${o}"`);if(o==="y"){if(!/^y{[gw]}/.test(e.slice(n)))throw new Error('Invalid or unspecified flag "y" mode');r.textSegmentMode=e[n+2]==="g"?"grapheme":"word",n+=3;continue}r[{i:"ignoreCase",m:"dotAll",x:"extended",D:"digitIsAscii",P:"posixIsAscii",S:"spaceIsAscii",W:"wordIsAscii"}[o]]=!0}return r}function Ce(e){if(new RegExp("^(?:\\\\u(?!\\p{AHex}{4})|\\\\x(?!\\p{AHex}{1,2}|\\{\\p{AHex}{1,8}\\}))","u").test(e))throw new Error(`Incomplete or invalid escape "${e}"`);const r=e[2]==="{"?new RegExp("^\\\\x\\{\\s*(?<hex>\\p{AHex}+)","u").exec(e).groups.hex:e.slice(2);return parseInt(r,16)}function Ee(e,r){const{raw:n,inCharClass:o}=e,i=n.slice(1);if(!o&&(i!=="0"&&i.length===1||i[0]!=="0"&&+i<=r))return[q(n)];const t=[],a=i.match(/^[0-7]+|\d/g);for(let s=0;s<a.length;s++){const u=a[s];let l;if(s===0&&u!=="8"&&u!=="9"){if(l=parseInt(u,8),l>127)throw new Error(h`Octal encoded byte above 177 unsupported "${n}"`)}else l=x(u);t.push(m(l,(s===0?"\\":"")+u))}return t}function Ae(e){const r=[],n=new RegExp(U,"gy");let o;for(;o=n.exec(e);){const i=o[0];if(i[0]==="{"){const t=/^\{(?<min>\d+),(?<max>\d+)\}\??$/.exec(i);if(t){const{min:a,max:s}=t.groups;if(+a>+s&&i.endsWith("?")){n.lastIndex--,r.push(V(i.slice(0,-1)));continue}}}r.push(V(i))}return r}function Je(e,r){if(!Array.isArray(e.body))throw new Error("Expected node with body array");if(e.body.length!==1)return!1;const n=e.body[0];return!r||Object.keys(r).every(o=>r[o]===n[o])}function Ie(e){return ve.has(e.type)}const ve=new Set(["AbsenceFunction","Backreference","CapturingGroup","Character","CharacterClass","CharacterSet","Group","Quantifier","Subroutine"]);function en(e,r={}){const n={flags:"",normalizeUnknownPropertyNames:!1,skipBackrefValidation:!1,skipLookbehindValidation:!1,skipPropertyNameValidation:!1,unicodePropertyMap:null,...r,rules:{captureGroup:!1,singleline:!1,...r.rules}},o=te(e,{flags:n.flags,rules:{captureGroup:n.rules.captureGroup,singleline:n.rules.singleline}}),i=(d,g)=>{const p=o.tokens[t.nextIndex];switch(t.parent=d,t.nextIndex++,p.type){case"Alternator":return _();case"Assertion":return Ne(p);case"Backreference":return Se(p,t);case"Character":return Y(p.value,{useLastValid:!!g.isCheckingRangeEnd});case"CharacterClassHyphen":return Ge(p,t,g);case"CharacterClassOpen":return Pe(p,t,g);case"CharacterSet":return Me(p,t);case"Directive":return Be(p.kind,{flags:p.flags});case"GroupOpen":return Ue(p,t,g);case"NamedCallout":return He(p.kind,p.tag,p.arguments);case"Quantifier":return _e(p,t);case"Subroutine":return Oe(p,t);default:throw new Error(`Unexpected token type "${p.type}"`)}},t={capturingGroups:[],hasNumberedRef:!1,namedGroupsByName:new Map,nextIndex:0,normalizeUnknownPropertyNames:n.normalizeUnknownPropertyNames,parent:null,skipBackrefValidation:n.skipBackrefValidation,skipLookbehindValidation:n.skipLookbehindValidation,skipPropertyNameValidation:n.skipPropertyNameValidation,subroutines:[],tokens:o.tokens,unicodePropertyMap:n.unicodePropertyMap,walk:i},a=Qe(We(o.flags));let s=a.body[0];for(;t.nextIndex<o.tokens.length;){const d=i(s,{});d.type==="Alternative"?(a.body.push(d),s=d):s.body.push(d)}const{capturingGroups:u,hasNumberedRef:l,namedGroupsByName:f,subroutines:c}=t;if(l&&f.size&&!n.rules.captureGroup)throw new Error("Numbered backref/subroutine not allowed when using named capture");for(const{ref:d}of c)if(typeof d=="number"){if(d>u.length)throw new Error("Subroutine uses a group number that's not defined");d&&(u[d-1].isSubroutined=!0)}else if(f.has(d)){if(f.get(d).length>1)throw new Error(h`Subroutine uses a duplicate group name "\g<${d}>"`);f.get(d)[0].isSubroutined=!0}else throw new Error(h`Subroutine uses a group name that's not defined "\g<${d}>"`);return a}function Ne({kind:e}){return ze($({"^":"line_start",$:"line_end","\\A":"string_start","\\b":"word_boundary","\\B":"word_boundary","\\G":"search_start","\\y":"text_segment_boundary","\\Y":"text_segment_boundary","\\z":"string_end","\\Z":"string_end_newline"}[e],`Unexpected assertion kind "${e}"`),{negate:e===h`\B`||e===h`\Y`})}function Se({raw:e},r){const n=/^\\k[<']/.test(e),o=n?e.slice(3,-1):e.slice(1),i=(t,a=!1)=>{const s=r.capturingGroups.length;let u=!1;if(t>s)if(r.skipBackrefValidation)u=!0;else throw new Error(`Not enough capturing groups defined to the left "${e}"`);return r.hasNumberedRef=!0,B(a?s+1-t:t,{orphan:u})};if(n){const t=/^(?<sign>-?)0*(?<num>[1-9]\d*)$/.exec(o);if(t)return i(+t.groups.num,!!t.groups.sign);if(/[-+]/.test(o))throw new Error(`Invalid backref name "${e}"`);if(!r.namedGroupsByName.has(o))throw new Error(`Group name not defined to the left "${e}"`);return B(o)}return i(+o)}function Ge(e,r,n){const{tokens:o,walk:i}=r,t=r.parent,a=t.body.at(-1),s=o[r.nextIndex];if(!n.isCheckingRangeEnd&&a&&a.type!=="CharacterClass"&&a.type!=="CharacterClassRange"&&s&&s.type!=="CharacterClassOpen"&&s.type!=="CharacterClassClose"&&s.type!=="CharacterClassIntersector"){const u=i(t,{...n,isCheckingRangeEnd:!0});if(a.type==="Character"&&u.type==="Character")return t.body.pop(),Ve(a,u);throw new Error("Invalid character class range")}return Y(x("-"))}function Pe({negate:e},r,n){const{tokens:o,walk:i}=r,t=o[r.nextIndex],a=[P()];let s=Z(t);for(;s.type!=="CharacterClassClose";){if(s.type==="CharacterClassIntersector")a.push(P()),r.nextIndex++;else{const l=a.at(-1);l.body.push(i(l,n))}s=Z(o[r.nextIndex],t)}const u=P({negate:e});return a.length===1?u.body=a[0].body:(u.kind="intersection",u.body=a.map(l=>l.body.length===1?l.body[0]:l)),r.nextIndex++,u}function Me({kind:e,negate:r,value:n},o){const{normalizeUnknownPropertyNames:i,skipPropertyNameValidation:t,unicodePropertyMap:a}=o;if(e==="property"){const s=ee(n);if(M.has(s)&&!a?.has(s))e="posix",n=s;else return je(n,{negate:r,normalizeUnknownPropertyNames:i,skipPropertyNameValidation:t,unicodePropertyMap:a})}return e==="posix"?Ze(n,{negate:r}):Xe(e,{negate:r})}function Ue(e,r,n){const{tokens:o,capturingGroups:i,namedGroupsByName:t,skipLookbehindValidation:a,walk:s}=r,u=qe(e),l=u.type==="AbsenceFunction",f=H(u),c=f&&u.negate;if(u.type==="CapturingGroup"&&(i.push(u),u.name&&re(t,u.name,[]).push(u)),l&&n.isInAbsenceFunction)throw new Error("Nested absence function not supported by Oniguruma");let d=D(o[r.nextIndex]);for(;d.type!=="GroupClose";){if(d.type==="Alternator")u.body.push(_()),r.nextIndex++;else{const g=u.body.at(-1),p=s(g,{...n,isInAbsenceFunction:n.isInAbsenceFunction||l,isInLookbehind:n.isInLookbehind||f,isInNegLookbehind:n.isInNegLookbehind||c});if(g.body.push(p),(f||n.isInLookbehind)&&!a){const E="Lookbehind includes a pattern not allowed by Oniguruma";if(c||n.isInNegLookbehind){if(F(p)||p.type==="CapturingGroup")throw new Error(E)}else if(F(p)||H(p)&&p.negate)throw new Error(E)}}d=D(o[r.nextIndex])}return r.nextIndex++,u}function _e({kind:e,min:r,max:n},o){const i=o.parent,t=i.body.at(-1);if(!t||!Ie(t))throw new Error("Quantifier requires a repeatable token");const a=De(e,r,n,t);return i.body.pop(),a}function Oe({raw:e},r){const{capturingGroups:n,subroutines:o}=r;let i=e.slice(3,-1);const t=/^(?<sign>[-+]?)0*(?<num>[1-9]\d*)$/.exec(i);if(t){const s=+t.groups.num,u=n.length;if(r.hasNumberedRef=!0,i={"":s,"+":u+s,"-":u+1-s}[t.groups.sign],i<1)throw new Error("Invalid subroutine number")}else i==="0"&&(i=0);const a=Te(i);return o.push(a),a}function Le(e,r){return{type:"AbsenceFunction",kind:e,body:C(r?.body)}}function _(e){return{type:"Alternative",body:J(e?.body)}}function ze(e,r){const n={type:"Assertion",kind:e};return(e==="word_boundary"||e==="text_segment_boundary")&&(n.negate=!!r?.negate),n}function B(e,r){const n=!!r?.orphan;return{type:"Backreference",ref:e,...n&&{orphan:n}}}function Re(e,r){const n={name:void 0,isSubroutined:!1,...r};if(n.name!==void 0&&!Ke(n.name))throw new Error(`Group name "${n.name}" invalid in Oniguruma`);return{type:"CapturingGroup",number:e,...n.name&&{name:n.name},...n.isSubroutined&&{isSubroutined:n.isSubroutined},body:C(r?.body)}}function Y(e,r){const n={useLastValid:!1,...r};if(e>1114111){const o=e.toString(16);if(n.useLastValid)e=1114111;else throw e>1310719?new Error(`Invalid code point out of range "\\x{${o}}"`):new Error(`Invalid code point out of range in JS "\\x{${o}}"`)}return{type:"Character",value:e}}function P(e){const r={kind:"union",negate:!1,...e};return{type:"CharacterClass",kind:r.kind,negate:r.negate,body:J(e?.body)}}function Ve(e,r){if(r.value<e.value)throw new Error("Character class range out of order");return{type:"CharacterClassRange",min:e,max:r}}function Xe(e,r){const n=!!r?.negate,o={type:"CharacterSet",kind:e};return(e==="digit"||e==="hex"||e==="newline"||e==="space"||e==="word")&&(o.negate=n),(e==="text_segment"||e==="newline"&&!n)&&(o.variableLength=!0),o}function Be(e,r={}){if(e==="keep")return{type:"Directive",kind:e};if(e==="flags")return{type:"Directive",kind:e,flags:$(r.flags)};throw new Error(`Unexpected directive kind "${e}"`)}function We(e){return{type:"Flags",...e}}function W(e){const r=e?.atomic,n=e?.flags;if(r&&n)throw new Error("Atomic group cannot have flags");return{type:"Group",...r&&{atomic:r},...n&&{flags:n},body:C(e?.body)}}function Fe(e){const r={behind:!1,negate:!1,...e};return{type:"LookaroundAssertion",kind:r.behind?"lookbehind":"lookahead",negate:r.negate,body:C(e?.body)}}function He(e,r,n){return{type:"NamedCallout",kind:e,tag:r,arguments:n}}function Ze(e,r){const n=!!r?.negate;if(!M.has(e))throw new Error(`Invalid POSIX class "${e}"`);return{type:"CharacterSet",kind:"posix",value:e,negate:n}}function De(e,r,n,o){if(r>n)throw new Error("Invalid reversed quantifier range");return{type:"Quantifier",kind:e,min:r,max:n,body:o}}function Qe(e,r){return{type:"Regex",body:C(r?.body),flags:e}}function Te(e){return{type:"Subroutine",ref:e}}function je(e,r){const n={negate:!1,normalizeUnknownPropertyNames:!1,skipPropertyNameValidation:!1,unicodePropertyMap:null,...r};let o=n.unicodePropertyMap?.get(ee(e));if(!o){if(n.normalizeUnknownPropertyNames)o=Ye(e);else if(n.unicodePropertyMap&&!n.skipPropertyNameValidation)throw new Error(h`Invalid Unicode property "\p{${e}}"`)}return{type:"CharacterSet",kind:"property",value:o??e,negate:n.negate}}function qe({flags:e,kind:r,name:n,negate:o,number:i}){switch(r){case"absence_repeater":return Le("repeater");case"atomic":return W({atomic:!0});case"capturing":return Re(i,{name:n});case"group":return W({flags:e});case"lookahead":case"lookbehind":return Fe({behind:r==="lookbehind",negate:o});default:throw new Error(`Unexpected group kind "${r}"`)}}function C(e){if(e===void 0)e=[_()];else if(!Array.isArray(e)||!e.length||!e.every(r=>r.type==="Alternative"))throw new Error("Invalid body; expected array of one or more Alternative nodes");return e}function J(e){if(e===void 0)e=[];else if(!Array.isArray(e)||!e.every(r=>!!r.type))throw new Error("Invalid body; expected array of nodes");return e}function F(e){return e.type==="LookaroundAssertion"&&e.kind==="lookahead"}function H(e){return e.type==="LookaroundAssertion"&&e.kind==="lookbehind"}function Ke(e){return/^[\p{Alpha}\p{Pc}][^)]*$/u.test(e)}function Ye(e){return e.trim().replace(/[- _]+/g,"_").replace(/[A-Z][a-z]+(?=[A-Z])/g,"$&_").replace(/[A-Za-z]+/g,r=>r[0].toUpperCase()+r.slice(1).toLowerCase())}function ee(e){return e.replace(/[- _]+/g,"").toLowerCase()}function Z(e,r){return $(e,`${r?.type==="Character"&&r.value===93?"Empty":"Unclosed"} character class`)}function D(e){return $(e,"Unclosed group")}function nn(e,r,n=null){function o(t,a){for(let s=0;s<t.length;s++){const u=i(t[s],a,s,t);s=Math.max(-1,s+u)}}function i(t,a=null,s=null,u=null){let l=0,f=!1;const c={node:t,parent:a,key:s,container:u,root:e,remove(){v(u).splice(Math.max(0,k(s)+l),1),l--,f=!0},removeAllNextSiblings(){return v(u).splice(k(s)+1)},removeAllPrevSiblings(){const w=k(s)+l;return l-=w,v(u).splice(0,Math.max(0,w))},replaceWith(w,N={}){const S=!!N.traverse;u?u[Math.max(0,k(s)+l)]=w:$(a,"Can't replace root node")[s]=w,S&&i(w,a,s,u),f=!0},replaceWithMultiple(w,N={}){const S=!!N.traverse;if(v(u).splice(Math.max(0,k(s)+l),1,...w),l+=w.length-1,S){let O=0;for(let A=0;A<w.length;A++)O+=i(w[A],a,k(s)+A+O,u)}f=!0},skip(){f=!0}},{type:d}=t,g=r["*"],p=r[d],E=typeof g=="function"?g:g?.enter,ne=typeof p=="function"?p:p?.enter;if(E?.(c,n),ne?.(c,n),!f)switch(d){case"AbsenceFunction":case"CapturingGroup":case"Group":o(t.body,t);break;case"Alternative":case"CharacterClass":o(t.body,t);break;case"Assertion":case"Backreference":case"Character":case"CharacterSet":case"Directive":case"Flags":case"NamedCallout":case"Subroutine":break;case"CharacterClassRange":i(t.min,t,"min"),i(t.max,t,"max");break;case"LookaroundAssertion":o(t.body,t);break;case"Quantifier":i(t.body,t,"body");break;case"Regex":o(t.body,t),i(t.flags,t,"flags");break;default:throw new Error(`Unexpected node type "${d}"`)}return p?.exit?.(c,n),g?.exit?.(c,n),l}return i(e),e}function v(e){if(!Array.isArray(e))throw new Error("Container expected");return e}function k(e){if(typeof e!="number")throw new Error("Numeric key expected");return e}export{W as A,P as C,Xe as E,ze as F,en as J,Fe as K,Te as O,Re as P,je as Q,nn as S,De as _,_ as b,B as k,Y as m,Je as o,ee as w};
