@polagram/core 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,17 @@
1
- (function(T,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(T=typeof globalThis<"u"?globalThis:T||self,F(T.PolagramCore={}))})(this,(function(T){"use strict";const F={"->":{type:"sync",style:{line:"solid",head:"open"}},"->>":{type:"sync",style:{line:"solid",head:"arrow"}},"-->":{type:"reply",style:{line:"dotted",head:"open"}},"-->>":{type:"reply",style:{line:"dotted",head:"arrow"}},"-)":{type:"async",style:{line:"solid",head:"async"}},"--)":{type:"async",style:{line:"dotted",head:"async"}},"-x":{type:"destroy",style:{line:"solid",head:"cross"}},"--x":{type:"destroy",style:{line:"dotted",head:"cross"}}},Rt=Object.entries(F).reduce((t,[e,n])=>{const r=JSON.stringify({type:n.type,style:n.style});return t[r]=e,t},{});function Lt(t,e){const n=JSON.stringify({type:t,style:e});return Rt[n]||"->>"}class pe{constructor(e){this.visitor=e}traverse(e){this.visitor.visitRoot(e)}dispatchEvent(e){switch(e.kind){case"message":this.visitor.visitMessage(e);break;case"fragment":this.visitor.visitFragment(e);break;case"note":this.visitor.visitNote(e);break;case"activation":this.visitor.visitActivation(e);break;case"divider":this.visitor.visitDivider(e);break;case"spacer":this.visitor.visitSpacer(e);break;case"ref":this.visitor.visitReference(e);break}}dispatchEvents(e){for(const n of e)this.dispatchEvent(n)}}class le{lines=[];indentLevel=0;traverser;constructor(){this.traverser=new pe(this)}visitParticipantGroup(e){}generate(e){return this.lines=[],this.indentLevel=0,this.traverser.traverse(e),this.lines.join(`
2
- `)}visitRoot(e){this.lines.push("sequenceDiagram"),this.indentLevel++,e.meta?.title&&this.add(`title ${e.meta.title}`);const n=new Map;for(const i of e.participants)n.set(i.id,[]);for(const i of e.groups)for(const s of i.participantIds){const o=n.get(s);o&&o.push(i)}const r=[];for(const i of e.participants){const s=n.get(i.id)||[];let o=0;const a=Math.min(r.length,s.length);for(let c=0;c<a&&r[c]===s[c];c++)o++;for(;r.length>o;)this.indentLevel--,this.add("end"),r.pop();for(let c=o;c<s.length;c++){const h=s[c];let p="box";h.style?.backgroundColor&&(p+=` ${h.style.backgroundColor}`),h.name&&(p+=` ${h.name}`),this.add(p),this.indentLevel++,r.push(h)}this.visitParticipant(i)}for(;r.length>0;)this.indentLevel--,this.add("end"),r.pop();this.traverser.dispatchEvents(e.events)}visitParticipant(e){const n=e.type==="actor"?"actor":"participant",r=e.name;e.id===e.name?this.add(`${n} ${e.id}`):this.add(`${n} ${e.id} as ${r}`)}visitMessage(e){const n=e.from??"[*]",r=e.to??"[*]",i=Lt(e.type,e.style);let s="";e.lifecycle?.activateTarget&&(s+="+"),e.lifecycle?.deactivateSource&&(s+="-"),this.add(`${n}${i}${s}${r}: ${e.text}`)}visitFragment(e){if(e.branches.length===0)return;const n=e.branches[0],r=n.condition?` ${n.condition}`:"";this.add(`${e.operator}${r}`),this.indent(()=>{this.traverser.dispatchEvents(n.events)});let i="else";e.operator==="par"?i="and":e.operator==="critical"&&(i="option");for(let s=1;s<e.branches.length;s++){const o=e.branches[s],a=o.condition?` ${o.condition}`:"";this.add(`${i}${a}`),this.indent(()=>{this.traverser.dispatchEvents(o.events)})}this.add("end")}visitNote(e){const n=e.position;let r="";e.participantIds.length>0&&(r=e.participantIds.join(","),n!=="over"?r=` of ${r}`:r=` ${r}`),this.add(`note ${n}${r}: ${e.text}`)}visitActivation(e){this.add(`${e.action} ${e.participantId}`)}visitDivider(e){this.add(`%% == ${e.text||""} ==`)}visitSpacer(e){this.add(`...${e.text||""}...`)}visitReference(e){this.add(`%% ref: ${e.text}`)}add(e){const n=" ".repeat(this.indentLevel);this.lines.push(`${n}${e}`)}indent(e){this.indentLevel++,e(),this.indentLevel--}}class de{lines=[];traverser;constructor(){this.traverser=new pe(this)}generate(e){return this.lines=[],this.traverser.traverse(e),this.lines.join(`
3
- `)}visitRoot(e){this.add("@startuml"),e.meta.title&&this.add(`title ${e.meta.title}`);const n=new Map;for(const i of e.participants)n.set(i.id,[]);for(const i of e.groups)for(const s of i.participantIds){const o=n.get(s);o&&o.push(i)}const r=[];for(const i of e.participants){const s=n.get(i.id)||[];let o=0;const a=Math.min(r.length,s.length);for(let c=0;c<a&&r[c]===s[c];c++)o++;for(;r.length>o;)this.add("end box"),r.pop();for(let c=o;c<s.length;c++){const h=s[c],p=h.style?.backgroundColor?` ${h.style.backgroundColor}`:"",d=h.name?` "${h.name}"`:"";this.add(`box${d}${p}`),r.push(h)}this.visitParticipant(i)}for(;r.length>0;)this.add("end box"),r.pop();this.traverser.dispatchEvents(e.events),this.add("@enduml")}visitParticipant(e){e.name===e.id?this.add(`${e.type} ${e.id}`):this.add(`${e.type} "${e.name}" as ${e.id}`)}visitParticipantGroup(e){}visitMessage(e){const n=e.from||"[*]",r=e.to||"[*]";let i="->";e.type==="reply"?i="-->":e.type==="async"&&(i="->>"),this.add(`${n} ${i} ${r}: ${e.text}`)}visitFragment(e){const n=e.operator;e.branches.forEach((r,i)=>{i===0?this.add(`${n} ${r.condition||""}`.trim()):this.add(`else ${r.condition||""}`.trim()),this.traverser.dispatchEvents(r.events)}),this.add("end")}visitNote(e){const n=e.position||"over",r=e.participantIds.join(", ");let i="";e.participantIds.length>0?n==="over"?i=`note over ${r}`:i=`note ${n} of ${r}`:i=`note ${n}`,this.add(i),e.text.split(`
4
- `).forEach(s=>{this.add(` ${s}`)}),this.add("end note")}visitActivation(e){this.add(`${e.action} ${e.participantId}`)}visitDivider(e){e.text?this.add(`== ${e.text} ==`):this.add("====")}visitSpacer(e){this.add("|||")}visitReference(e){const n=e.participantIds.join(", ");this.add(`ref over ${n}: ${e.text}`)}add(e){this.lines.push(e)}}class Oe{constructor(e){this.input=e,this.readChar()}position=0;readPosition=0;ch="";line=1;column=0;getInput(){return this.input}readChar(){this.readPosition>=this.input.length?this.ch="":this.ch=this.input[this.readPosition],this.position=this.readPosition,this.readPosition+=1,this.column+=1,this.ch===`
5
- `&&(this.line+=1,this.column=0)}peekChar(){return this.readPosition>=this.input.length?"":this.input[this.readPosition]}skipWhitespace(){for(;this.ch===" "||this.ch===" "||this.ch==="\r";)this.readChar()}readWhile(e){const n=this.position;for(;e(this.ch);)this.readChar();return this.input.slice(n,this.position)}isLetter(e){return"a"<=e&&e<="z"||"A"<=e&&e<="Z"||e==="_"?!0:e.charCodeAt(0)>127?!/[\s\d]/.test(e):!1}isDigit(e){return"0"<=e&&e<="9"}readIdentifier(){const e=this.position;for(;this.isLetter(this.ch)||this.isDigit(this.ch);)this.readChar();return this.input.slice(e,this.position)}readQuotedString(){const e=this.position+1;for(this.readChar();this.ch!=='"'&&this.ch!==""&&this.ch!==`
6
- `;)this.readChar();const n=this.input.slice(e,this.position);return this.readChar(),n}createToken(e,n,r,i){return{type:e,literal:n,line:this.line,column:i,start:r,end:this.position>r?this.position:r+n.length}}}let Dt=class extends Oe{nextToken(){if(this.skipWhitespace(),this.ch==="%"&&this.peekChar()==="%")return this.skipComment(),this.nextToken();const e=this.position,n=this.column;let r;switch(this.ch){case":":r=this.newToken("COLON",this.ch,e,n);break;case",":r=this.newToken("COMMA",this.ch,e,n);break;case"+":r=this.newToken("PLUS",this.ch,e,n);break;case"-":if(this.isArrowStart()){const i=this.readArrow();return r=this.newToken("ARROW",i,e,n),r}else r=this.newToken("MINUS",this.ch,e,n);break;case'"':{const i=this.readString();return r=this.newToken("STRING",i,e,n),r}case`
7
- `:r=this.newToken("NEWLINE",this.ch,e,n);break;case"":r=this.newToken("EOF","",e,n);break;default:if(this.isLetter(this.ch)){const i=this.readIdentifier(),s=this.lookupIdent(i);return this.newToken(s,i,e,n)}else if(this.isDigit(this.ch)){const i=this.readNumber();return this.newToken("IDENTIFIER",i,e,n)}else r=this.newToken("UNKNOWN",this.ch,e,n)}return this.readChar(),r}newToken(e,n,r,i){return{type:e,literal:n,line:this.line,column:i,start:r,end:this.position>r?this.position:r+n.length}}readNumber(){const e=this.position;for(;this.isDigit(this.ch);)this.readChar();return this.input.slice(e,this.position)}readString(){const e=this.position+1;for(this.readChar();this.ch!=='"'&&this.ch!==""&&this.ch!==`
8
- `;)this.readChar();const n=this.input.slice(e,this.position);return this.ch,this.readChar(),n}isArrowStart(){if(this.ch!=="-")return!1;const e=this.peekChar();return e===">"||e==="-"||e===")"||e==="x"}readArrow(){if(this.input.slice(this.position,this.position+4)==="-->>")return this.readMulti(4),"-->>";const n=this.input.slice(this.position,this.position+3);if(n==="-->"||n==="--)"||n==="->>"||n==="--x")return this.readMulti(3),n;const r=this.input.slice(this.position,this.position+2);return r==="->"||r==="-)"||r==="-x"?(this.readMulti(2),r):"-"}readMulti(e){for(let n=0;n<e;n++)this.readChar()}skipComment(){for(;this.ch!==`
9
- `&&this.ch!=="";)this.readChar()}lookupIdent(e){return{sequencediagram:"SEQUENCE_DIAGRAM",participant:"PARTICIPANT",actor:"ACTOR",loop:"LOOP",alt:"ALT",opt:"OPT",end:"END",else:"ELSE",note:"NOTE",left:"LEFT",right:"RIGHT",over:"OVER",of:"OF",as:"AS",title:"TITLE",activate:"ACTIVATE",deactivate:"DEACTIVATE",box:"BOX",par:"PAR",and:"AND",break:"BREAK",critical:"CRITICAL",option:"OPTION",rect:"RECT"}[e.toLowerCase()]||"IDENTIFIER"}};class Pe{constructor(e){this.lexer=e,this.advance(),this.advance()}currToken;peekToken;advance(){this.currToken=this.peekToken,this.peekToken=this.lexer.nextToken()}curTokenIs(e){return this.currToken.type===e}peekTokenIs(e){return this.peekToken.type===e}expectPeek(e){return this.peekTokenIs(e)?(this.advance(),!0):!1}isCurrentToken(e){return this.currToken.type===e}isCurrentTokenOneOf(e){return e.includes(this.currToken.type)}getCurrentTokenType(){return this.currToken.type}}let xt=class extends Pe{currentGroup=null;idCounters={evt:0,frag:0,br:0,note:0,group:0};parse(){const e={kind:"root",meta:{version:"1.0.0",source:"unknown"},participants:[],groups:[],events:[]};return e.events=this.parseBlock(e),e}parseBlock(e,n=[]){const r=[];for(;!this.isCurrentToken("EOF");){const i=this.getCurrentTokenType();if(n.includes(i))return r;if(i==="NEWLINE"){this.advance();continue}if(i==="SEQUENCE_DIAGRAM"){e.meta.source="mermaid",this.advance();continue}if(i==="TITLE"){this.advance(),e.meta.title=this.readRestOfLine();continue}if(i==="BOX"){const s=this.parseGroup(e);r.push(...s);continue}if(i==="PARTICIPANT"||i==="ACTOR"){this.parseParticipant(e);continue}if(i==="LOOP"||i==="ALT"||i==="OPT"||i==="PAR"||i==="BREAK"||i==="CRITICAL"||i==="RECT"){r.push(this.parseFragment(e));continue}if(i==="NOTE"){r.push(this.parseNote(e));continue}if(i==="ACTIVATE"||i==="DEACTIVATE"){r.push(this.parseActivation(e));continue}if(this.isParticipantToken(this.currToken)){const s=this.parseMessage(e);if(s){r.push(s);continue}}this.advance()}return r}isParticipantToken(e){return e.type==="IDENTIFIER"||e.type==="STRING"}parseGroup(e){this.advance();const n=this.readRestOfLine().trim();let r=n,i;const s=n.split(/\s+/);if(s.length>0){const h=s[0];(h.startsWith("#")||["rgb","rgba","transparent","aqua","grey","gray","purple","red","blue","green"].includes(h.toLowerCase()))&&(i=h,r=s.slice(1).join(" "))}r||(r=`Group ${this.idCounters.group+1}`);const o={kind:"group",id:this.generateId("group"),name:r,type:"box",participantIds:[],style:i?{backgroundColor:i}:void 0};e.groups.push(o);const a=this.currentGroup;this.currentGroup=o;const c=this.parseBlock(e,["END"]);return this.currentGroup=a,this.isCurrentToken("END")&&this.advance(),c}parseFragment(e){const n=this.getCurrentTokenType();let r="loop";n==="ALT"&&(r="alt"),n==="OPT"&&(r="opt"),n==="PAR"&&(r="par"),n==="BREAK"&&(r="break"),n==="CRITICAL"&&(r="critical"),n==="RECT"&&(r="rect"),this.advance();const i=this.readRestOfLine(),s=[];let o;r==="par"?o=["END","ELSE","AND"]:r==="critical"?o=["END","OPTION"]:o=["END","ELSE"];const a=this.parseBlock(e,o);for(s.push({id:this.generateId("br"),condition:i,events:a});this.isCurrentToken("AND");){this.advance();const c=this.readRestOfLine(),h=this.parseBlock(e,["END","AND"]);s.push({id:this.generateId("br"),condition:c,events:h})}for(;this.isCurrentToken("OPTION");){this.advance();const c=this.readRestOfLine(),h=this.parseBlock(e,["END","OPTION"]);s.push({id:this.generateId("br"),condition:c,events:h})}for(;this.isCurrentToken("ELSE");){this.advance();const c=this.readRestOfLine(),h=this.parseBlock(e,["END","ELSE"]);s.push({id:this.generateId("br"),condition:c,events:h})}return this.isCurrentToken("END")&&this.advance(),{kind:"fragment",id:this.generateId("frag"),operator:r,branches:s}}parseParticipant(e){const n=this.currToken.type==="ACTOR";this.advance();let r="",i="";if(this.isParticipantToken(this.currToken)&&(r=this.currToken.literal,i=r,this.advance()),this.currToken.type==="AS"){this.advance();const o=this.readRestOfLine().trim();o&&(i=o)}const s=e.participants.find(o=>o.id===r);s?(i!==r&&(s.name=i),n&&(s.type="actor")):e.participants.push({id:r,name:i,type:n?"actor":"participant"}),this.currentGroup&&(this.currentGroup.participantIds.includes(r)||this.currentGroup.participantIds.push(r))}parseNote(e){this.advance();let n="over";this.currToken.type==="LEFT"?(n="left",this.advance()):this.currToken.type==="RIGHT"?(n="right",this.advance()):this.currToken.type==="OVER"&&(n="over",this.advance()),this.currToken.type==="OF"&&this.advance();const r=[];for(;this.isParticipantToken(this.currToken)&&(r.push(this.currToken.literal),this.ensureParticipant(e,this.currToken.literal),this.advance(),this.currToken.type==="COMMA");)this.advance();let i="";return this.currToken.type==="COLON"&&(this.advance(),i=this.readRestOfLine()),{kind:"note",id:this.generateId("note"),position:n,participantIds:r,text:i}}parseActivation(e){const n=this.currToken.type==="ACTIVATE"?"activate":"deactivate";this.advance();let r="";return this.isParticipantToken(this.currToken)&&(r=this.currToken.literal,this.ensureParticipant(e,r),this.advance()),{kind:"activation",participantId:r,action:n}}parseMessage(e){if(this.peekToken.type!=="ARROW")return null;const n=this.currToken.literal;if(this.ensureParticipant(e,n),this.advance(),this.currToken.type!=="ARROW")return null;const r=this.currToken.literal;this.advance();let i=!1,s=!1;if(this.isCurrentToken("PLUS")&&(i=!0,this.advance()),this.isCurrentToken("MINUS")&&(s=!0,this.advance()),!this.isParticipantToken(this.currToken))return null;const o=this.currToken.literal;this.ensureParticipant(e,o),this.advance();let a="";this.isCurrentToken("COLON")&&(this.advance(),a=this.readRestOfLine());const{type:c,style:h}=this.resolveArrow(r);return{kind:"message",id:this.generateId("evt"),from:n,to:o,text:a,type:c,style:h,lifecycle:i||s?{activateTarget:i,deactivateSource:s}:void 0}}resolveArrow(e){const n=F[e];return n||{type:"sync",style:{line:"solid",head:"arrow"}}}generateId(e){return this.idCounters[e]++,`${e}_${this.idCounters[e]}`}readRestOfLine(){if(this.isCurrentToken("NEWLINE")||this.isCurrentToken("EOF"))return"";const e=this.currToken.start;let n=this.currToken.end;for(;!this.isCurrentToken("NEWLINE")&&!this.isCurrentToken("EOF");)n=this.currToken.end,this.advance();return this.lexer.getInput().slice(e,n)}ensureParticipant(e,n){e.participants.find(r=>r.id===n)||e.participants.push({id:n,name:n,type:"participant"})}};const Ft={parse:t=>{const e=new Dt(t);return new xt(e).parse()}};class jt extends Oe{nextToken(){this.skipWhitespace();const e=this.position,n=this.column;let r;switch(this.ch){case`
10
- `:r=this.newToken("NEWLINE",this.ch,e,n);break;case"@":this.peekString("startuml")?(this.readMulti(9),r=this.newToken("START_UML","@startuml",e,n)):this.peekString("enduml")?(this.readMulti(7),r=this.newToken("END_UML","@enduml",e,n)):r=this.newToken("UNKNOWN",this.ch,e,n);break;case",":r=this.newToken("COMMA",",",e,n);break;case'"':{const i=this.readString();return this.newToken("STRING",i,e,n)}case":":r=this.newToken("COLON",":",e,n);break;case"-":{const i=this.readArrow();i?r=this.newToken("ARROW",i,e,n):r=this.newToken("UNKNOWN",this.ch,e,n);break}case"=":{if(this.peekExact("=")){const i=this.readDivider();return this.newToken("DIVIDER",i,e,n)}r=this.newToken("UNKNOWN",this.ch,e,n);break}case"":r=this.newToken("EOF","",e,n);break;default:if(this.isLetter(this.ch)){const i=this.readIdentifier(),s=this.lookupIdent(i);return this.newToken(s,i,e,n)}else r=this.newToken("UNKNOWN",this.ch,e,n)}return this.readChar(),r}newToken(e,n,r,i){const s=this.position===r?r+n.length:this.position;return{type:e,literal:n,line:this.line,column:i,start:r,end:s}}readString(){const e=this.position+1;for(this.readChar();this.ch!=='"'&&this.ch!==""&&this.ch!==`
11
- `;)this.readChar();const n=this.input.slice(e,this.position);return this.readChar(),n}lookupIdent(e){return{title:"TITLE",participant:"PARTICIPANT",actor:"ACTOR",database:"DATABASE",as:"AS",activate:"ACTIVATE",deactivate:"DEACTIVATE",note:"NOTE",left:"LEFT",right:"RIGHT",over:"OVER",of:"OF",alt:"ALT",opt:"OPT",loop:"LOOP",else:"ELSE",end:"END",box:"BOX",boundary:"BOUNDARY",control:"CONTROL",entity:"ENTITY",collections:"COLLECTIONS",queue:"QUEUE","@startuml":"START_UML","@enduml":"END_UML"}[e]||"IDENTIFIER"}readArrow(){return this.peekString("->")?(this.readMulti(2),"-->"):this.peekExact(">")?(this.readMulti(1),"->"):null}peekExact(e){return this.input[this.position+1]===e}peekString(e){for(let n=0;n<e.length;n++)if(this.input[this.position+1+n]!==e[n])return!1;return!0}readRestOfLine(){const e=this.position;for(;this.input[this.position]!==`
12
- `&&this.input[this.position]!==""&&this.position<this.input.length;)this.readChar();return this.input.slice(e,this.position).trim()}readMulti(e){for(let n=0;n<e;n++)this.readChar()}readDivider(){const n=this.readRestOfLine().match(/^==\s*(.*?)\s*==$/);return n?n[1]:""}}class Mt extends Pe{isTokenType(e){return this.currToken.type===e}parse(){const e={kind:"root",meta:{version:"1.0.0",source:"plantuml"},participants:[],groups:[],events:[]};for(;this.currToken.type!=="EOF";){if(this.currToken.type==="START_UML"){this.advance();continue}if(this.currToken.type==="END_UML"){this.advance();continue}if(this.currToken.type==="TITLE"){this.advance(),e.meta.title=this.readRestOfLine().trim();continue}if(["PARTICIPANT","ACTOR","DATABASE","BOUNDARY","CONTROL","ENTITY","COLLECTIONS","QUEUE"].includes(this.currToken.type)){this.parseParticipant(e);continue}if(this.currToken.type==="DIVIDER"){const n={kind:"divider",id:`div_${e.events.length+1}`,text:this.currToken.literal||void 0};e.events.push(n),this.advance();continue}if(this.isParticipantToken(this.currToken)){const n=this.parseMessage(e);if(n){e.events.push(n);continue}}if(this.currToken.type==="ACTIVATE"||this.currToken.type==="DEACTIVATE"){const n=this.parseActivation(e);n&&e.events.push(n);continue}if(this.currToken.type==="NOTE"){const n=this.parseNote(e);n&&e.events.push(n);continue}if(["ALT","OPT","LOOP"].includes(this.currToken.type)){const n=this.parseFragment(e);n&&e.events.push(n);continue}if(this.currToken.type==="END")return e;if(this.currToken.type==="BOX"){const n=this.parseGroup(e);n&&e.groups.push(n);continue}this.advance()}return e}parseGroup(e){this.advance();let n="",r;this.currToken.type==="STRING"&&(n=this.currToken.literal,this.advance()),this.currToken.type==="UNKNOWN"&&this.currToken.literal==="#"&&(this.advance(),this.isTokenType("IDENTIFIER")&&(r=`#${this.currToken.literal}`,this.advance()));const i=[];for(;this.currToken.type!=="EOF";){if(this.currToken.type==="END"){this.advance(),this.isTokenType("BOX")&&this.advance();break}if(["PARTICIPANT","ACTOR","DATABASE","BOUNDARY","CONTROL","ENTITY","COLLECTIONS","QUEUE"].includes(this.currToken.type)){const s=e.participants.length;this.parseParticipant(e);const o=e.participants.length;o>s&&i.push(e.participants[o-1].id);continue}if(this.currToken.type==="IDENTIFIER"){this.advance();continue}this.advance()}return{kind:"group",id:`group_${e.groups.length+1}`,name:n,type:"box",participantIds:i,style:r?{backgroundColor:r}:void 0}}parseFragment(e){const n="fragment",r=this.currToken.literal.toLowerCase();this.advance();const i=this.readRestOfLine().trim(),s=[];let o=[];const a={id:`br_${s.length+1}`,condition:i,events:o};for(s.push(a);this.currToken.type!=="EOF";){if(this.currToken.type==="END"){this.advance();break}if(this.currToken.type==="ELSE"){this.advance();const h=this.readRestOfLine().trim();o=[],s.push({id:`br_${s.length+1}`,condition:h,events:o});continue}if(this.currToken.type==="NEWLINE"){this.advance();continue}const c=this.parseStatement(e);c&&o.push(c)}return{kind:n,id:`frag_${e.events.length+1}`,operator:r,branches:s}}parseStatement(e){if(["PARTICIPANT","ACTOR","DATABASE","BOUNDARY","CONTROL","ENTITY","COLLECTIONS","QUEUE"].includes(this.currToken.type))return this.parseParticipant(e),null;if(this.isParticipantToken(this.currToken)){const n=this.parseMessage(e);if(n)return n}return this.currToken.type==="ACTIVATE"||this.currToken.type==="DEACTIVATE"?this.parseActivation(e):this.currToken.type==="NOTE"?this.parseNote(e):["ALT","OPT","LOOP"].includes(this.currToken.type)?this.parseFragment(e):(this.advance(),null)}parseNote(e){this.advance();let n="over";this.currToken.type==="LEFT"?(n="left",this.advance()):this.currToken.type==="RIGHT"?(n="right",this.advance()):this.currToken.type==="OVER"&&(n="over",this.advance()),this.currToken.type==="OF"&&this.advance();const r=[];for(;this.isParticipantToken(this.currToken)&&(r.push(this.currToken.literal),this.ensureParticipant(e,this.currToken.literal),this.advance(),this.currToken.type==="COMMA");)this.advance();let i="";if(this.currToken.type==="COLON")this.advance(),i=this.readRestOfLine().trim();else{this.currToken.type==="NEWLINE"&&this.advance();const s=this.currToken.start;let o=s;for(;this.currToken.type!=="EOF";){if(this.currToken.type==="END"&&this.peekToken.type==="NOTE"){o=this.currToken.start,this.advance(),this.advance();break}this.advance()}i=this.lexer.getInput().slice(s,o).trim()}return{kind:"note",id:`note_${e.events.length+1}`,position:n,participantIds:r,text:i}}parseActivation(e){const n=this.currToken.type==="ACTIVATE"?"activate":"deactivate";this.advance();let r="";if(this.isParticipantToken(this.currToken))r=this.currToken.literal,this.ensureParticipant(e,r),this.advance();else return null;return{kind:"activation",participantId:r,action:n}}isParticipantToken(e){return e.type==="IDENTIFIER"||e.type==="STRING"}parseMessage(e){if(this.peekToken.type!=="ARROW")return null;const n=this.currToken.literal;this.ensureParticipant(e,n),this.advance();const r=this.currToken.literal;if(this.advance(),!this.isParticipantToken(this.currToken))return null;const i=this.currToken.literal;this.ensureParticipant(e,i),this.advance();let s="";this.currToken.type==="COLON"&&(this.advance(),s=this.readRestOfLine().trim());let o="sync",a={line:"solid",head:"arrow"};return r==="-->"?(o="reply",a={line:"dotted",head:"arrow"}):r==="->"&&(o="sync",a={line:"solid",head:"arrow"}),{kind:"message",id:`msg_${e.events.length+1}`,from:n,to:i,text:s,type:o,style:a}}ensureParticipant(e,n){e.participants.find(r=>r.id===n)||e.participants.push({id:n,name:n,type:"participant"})}parseParticipant(e){const n=this.currToken.type;let r="participant";n==="ACTOR"&&(r="actor"),n==="DATABASE"&&(r="database"),n==="BOUNDARY"&&(r="boundary"),n==="CONTROL"&&(r="control"),n==="ENTITY"&&(r="entity"),n==="COLLECTIONS"&&(r="collections"),n==="QUEUE"&&(r="queue"),this.advance();let i="",s="";(this.currToken.type==="STRING"||this.currToken.type==="IDENTIFIER")&&(i=this.currToken.literal,s=i,this.advance()),this.currToken.type==="AS"&&(this.advance(),this.isTokenType("IDENTIFIER")&&(s=this.currToken.literal,this.advance())),e.participants.push({id:s,name:i,type:r})}readRestOfLine(){if(this.currToken.type==="NEWLINE"||this.currToken.type==="EOF")return"";const e=this.currToken.start;let n=this.currToken.end;for(;!this.isTokenType("NEWLINE")&&!this.isTokenType("EOF");)n=this.currToken.end,this.advance();return this.lexer.getInput().slice(e,n).trim()}}const Ut={parse:t=>{const e=new jt(t);return new Mt(e).parse()}},Gt={".puml":"plantuml",".plantuml":"plantuml",".pu":"plantuml",".mmd":"mermaid",".mermaid":"mermaid"},Vt=[{pattern:/^\s*@startuml/m,format:"plantuml"},{pattern:/^\s*sequenceDiagram/m,format:"mermaid"}],fe={detect(t,e){const n=fe.detectByExtension(t);return n||fe.detectByContent(e)},detectByExtension(t){const e=t.toLowerCase().match(/\.[^.]+$/)?.[0];return e&&Gt[e]||null},detectByContent(t){for(const{pattern:e,format:n}of Vt)if(e.test(t))return n;return null},getDefaultExtension(t){switch(t){case"plantuml":return".puml";case"mermaid":return".mmd"}}},X=new Map;X.set("mermaid",Ft),X.set("plantuml",Ut);const Se={register(t,e){X.set(t,e)},getParser(t){const e=X.get(t);if(!e)throw new Error(`Parser for language '${t}' not found.`);return e}};class B{transform(e){const n=this.mapEvents(e.events);return{...e,events:n}}mapEvents(e){return e.flatMap(n=>this.visitEvent(n))}visitEvent(e){return e.kind==="fragment"?this.visitFragment(e):[e]}visitFragment(e){const n=e.branches.map(r=>this.visitBranch(r));return[{...e,branches:n}]}visitBranch(e){return{...e,events:this.mapEvents(e.events)}}}class Bt extends B{visitFragment(e){const n=super.visitFragment(e);if(n.length===0)return[];const r=n[0],i=r.branches.filter(s=>s.events.length>0);return i.length===0?[]:[{...r,branches:i}]}}class Jt{transform(e){const n=this.collectUsedParticipants(e.events),r=e.participants.filter(s=>n.has(s.id)),i=e.groups.map(s=>({...s,participantIds:s.participantIds.filter(o=>n.has(o))})).filter(s=>s.participantIds.length>0);return{...e,participants:r,groups:i}}collectUsedParticipants(e){const n=new Set;function r(i){for(const s of i)switch(s.kind){case"message":s.from&&n.add(s.from),s.to&&n.add(s.to);break;case"fragment":for(const o of s.branches)r(o.events);break;case"activation":n.add(s.participantId);break;case"note":s.participantIds.forEach(o=>{n.add(o)});break;case"ref":s.participantIds.forEach(o=>{n.add(o)});break}}return r(e),n}}class Q{matchBranch(e,n,r){return!(n.operator&&!(Array.isArray(n.operator)?n.operator:[n.operator]).includes(r)||n.condition&&(!e.condition||!this.matchText(e.condition,n.condition)))}matchParticipant(e,n){return!(n.id&&!this.matchText(e.id,n.id)||n.name&&!this.matchText(e.name,n.name)||n.stereotype&&e.stereotype&&!this.matchText(e.stereotype,n.stereotype))}matchMessage(e,n){return!(n.text&&!this.matchText(e.text,n.text)||n.from&&e.from&&!this.matchText(e.from,n.from)||n.to&&e.to&&!this.matchText(e.to,n.to))}matchGroup(e,n){return!(n.name&&e.name&&!this.matchText(e.name,n.name))}matchText(e,n){if(typeof n=="string")return e===n;if(n instanceof RegExp)return n.test(e);if(typeof n=="object"&&n.pattern){const r=n.flags||"";return new RegExp(n.pattern,r).test(e)}return!1}}class Wt extends B{constructor(e){super(),this.layer=e}matcher=new Q;targetParticipantIds=new Set;transform(e){return this.resolveTargetParticipants(e),super.transform(e)}resolveTargetParticipants(e){this.targetParticipantIds.clear();const n=this.layer.selector;e.participants.forEach(r=>{this.matcher.matchParticipant(r,n)&&this.targetParticipantIds.add(r.id)})}visitEvent(e){if(e.kind==="message"){const n=e;if(!this.isRelatedToParticipant(n))return[]}if(e.kind==="note"&&!e.participantIds.some(i=>this.targetParticipantIds.has(i)))return[];if(e.kind==="activation"){const n=e;if(!this.targetParticipantIds.has(n.participantId))return[]}return super.visitEvent(e)}isRelatedToParticipant(e){return!!(e.from&&this.targetParticipantIds.has(e.from)||e.to&&this.targetParticipantIds.has(e.to))}}class Kt extends B{constructor(e){super(),this.layer=e}matcher=new Q;mergedParticipantIds=new Set;targetParticipantId="";transform(e){const n=this.layer.selector,r=[];if(e.participants.forEach(d=>{this.matcher.matchParticipant(d,n)&&r.push(d)}),r.length===0)return e;this.mergedParticipantIds=new Set(r.map(d=>d.id));const i=this.layer.into||{};let s=i.id,o=i.name;s||(o?s=o.replace(/[^a-zA-Z0-9-_]/g,"_"):s=r.map(d=>d.id).join("_")),o||(o=s),this.targetParticipantId=s;const a=[],h=!e.participants.some(d=>d.id===s&&!this.mergedParticipantIds.has(d.id));let p=!1;for(const d of e.participants){if(this.mergedParticipantIds.has(d.id)){if(h&&!p){const f={id:s||"",name:o||"",type:"participant"};a.push(f),p=!0}continue}d.id,a.push(d)}return e.participants=a,super.transform(e)}visitEvent(e){if(e.kind==="message")return this.transformMessage(e);if(e.kind==="note")return this.transformNote(e);if(e.kind==="activation")return this.transformActivation(e);if(e.kind==="fragment"){const n=super.visitEvent(e);return n.length>0&&n[0].kind==="fragment"&&n[0].branches.every(s=>s.events.length===0)?[]:n}return super.visitEvent(e)}transformMessage(e){let n=e.from,r=e.to;return n&&this.mergedParticipantIds.has(n)&&(n=this.targetParticipantId),r&&this.mergedParticipantIds.has(r)&&(r=this.targetParticipantId),n===this.targetParticipantId&&r===this.targetParticipantId?[]:[{...e,from:n,to:r}]}transformNote(e){const n=new Set;let r=!1;for(const o of e.participantIds)this.mergedParticipantIds.has(o)?(n.add(this.targetParticipantId),r=!0):n.add(o);if(!r)return[e];const i=Array.from(n);return e.participantIds.every(o=>this.mergedParticipantIds.has(o))?[]:[{...e,participantIds:i}]}transformActivation(e){return this.mergedParticipantIds.has(e.participantId)?[]:[e]}}class Yt extends B{constructor(e){super(),this.layer=e}matcher=new Q;removedParticipantIds=new Set;transform(e){const n=this.layer.selector;return n.kind==="participant"&&(e.participants.forEach(r=>{this.matcher.matchParticipant(r,n)&&this.removedParticipantIds.add(r.id)}),e.participants=e.participants.filter(r=>!this.removedParticipantIds.has(r.id))),n.kind==="group"&&(e.groups=e.groups.filter(r=>!this.matcher.matchGroup(r,n))),super.transform(e)}visitEvent(e){const n=this.layer.selector;if(n.kind==="message"&&e.kind==="message"&&this.matcher.matchMessage(e,n))return[];if(n.kind==="participant"){if(e.kind==="message"){const r=e;if(this.isRelatedToRemovedParticipant(r))return[]}if(e.kind==="note"&&e.participantIds.some(s=>this.removedParticipantIds.has(s)))return[];if(e.kind==="activation"){const r=e;if(this.removedParticipantIds.has(r.participantId))return[]}}return super.visitEvent(e)}isRelatedToRemovedParticipant(e){return!!(e.from&&this.removedParticipantIds.has(e.from)||e.to&&this.removedParticipantIds.has(e.to))}}class qt extends B{constructor(e){super(),this.layer=e}matcher=new Q;visitFragment(e){const n=e.branches.find(r=>this.matcher.matchBranch(r,this.layer.selector,e.operator));return n?this.mapEvents(n.events):super.visitFragment(e)}}class Xt{factories=new Map;constructor(){this.registerTyped("resolve",e=>new qt(e)),this.registerTyped("focus",e=>new Wt(e)),this.registerTyped("remove",e=>new Yt(e)),this.registerTyped("merge",e=>new Kt(e))}registerTyped(e,n){this.factories.set(e,n)}register(e,n){this.factories.set(e,n)}get(e){const n=this.factories.get(e.action);return n?n(e):null}has(e){return this.factories.has(e)}}const Ne=new Xt;class H{transform(e,n){let r=e;for(const i of n){const s=Ne.get(i);s?r=s.transform(r):console.warn(`Unknown action: ${i.action}`)}return r=new Bt().transform(r),r=new Jt().transform(r),r}}class Qt{constructor(){}static init(e,n="mermaid"){const i=Se.getParser(n).parse(e);return new Ae(i,n)}}class Ae{ast;layers=[];sourceFormat;constructor(e,n="mermaid"){this.ast=e,this.sourceFormat=n}focusParticipant(e){return this.layers.push({action:"focus",selector:this.normalizeParticipantSelector(e)}),this}removeParticipant(e){return this.layers.push({action:"remove",selector:this.normalizeParticipantSelector(e)}),this}removeMessage(e){return this.layers.push({action:"remove",selector:this.normalizeMessageSelector(e)}),this}removeGroup(e){return this.layers.push({action:"remove",selector:this.normalizeGroupSelector(e)}),this}resolveFragment(e){return this.layers.push({action:"resolve",selector:this.normalizeFragmentSelector(e)}),this}applyLens(e){return this.layers.push(...e.layers),this}toMermaid(){const n=new H().transform(this.ast,this.layers);return new le().generate(n)}toPlantUML(){const n=new H().transform(this.ast,this.layers);return new de().generate(n)}toAST(){return new H().transform(this.ast,this.layers)}getSourceFormat(){return this.sourceFormat}normalizeParticipantSelector(e){return this.isTextMatcher(e)?{kind:"participant",name:e}:{kind:"participant",...e}}normalizeMessageSelector(e){return this.isTextMatcher(e)?{kind:"message",text:e}:{kind:"message",...e}}normalizeGroupSelector(e){return this.isTextMatcher(e)?{kind:"group",name:e}:{kind:"group",...e}}normalizeFragmentSelector(e){return this.isTextMatcher(e)?{kind:"fragment",condition:e}:{kind:"fragment",...e}}isTextMatcher(e){return typeof e=="string"||e instanceof RegExp||typeof e=="object"&&e!==null&&"pattern"in e&&!("kind"in e)}}const j=new Map;j.set("mermaid",()=>new le),j.set("plantuml",()=>new de);const Ht={register(t,e){j.set(t,e)},getGenerator(t){const e=j.get(t);if(!e)throw new Error(`Generator for language '${t}' not found.`);return e()},hasGenerator(t){return j.has(t)},getLanguages(){return Array.from(j.keys())}};function u(t,e,n){function r(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(t))return;a._zod.traits.add(t),e(a,c);const h=o.prototype,p=Object.keys(h);for(let d=0;d<p.length;d++){const f=p[d];f in a||(a[f]=h[f].bind(a))}}const i=n?.Parent??Object;class s extends i{}Object.defineProperty(s,"name",{value:t});function o(a){var c;const h=n?.Parent?new s:this;r(h,a),(c=h._zod).deferred??(c.deferred=[]);for(const p of h._zod.deferred)p();return h}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(t)}),Object.defineProperty(o,"name",{value:t}),o}class M extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Ze extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Ce={};function C(t){return Ce}function Re(t){const e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,i])=>e.indexOf(+r)===-1).map(([r,i])=>i)}function me(t,e){return typeof e=="bigint"?e.toString():e}function ee(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function ge(t){return t==null}function ve(t){const e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}function en(t,e){const n=(t.toString().split(".")[1]||"").length,r=e.toString();let i=(r.split(".")[1]||"").length;if(i===0&&/\d?e-\d?/.test(r)){const c=r.match(/\d?e-(\d?)/);c?.[1]&&(i=Number.parseInt(c[1]))}const s=n>i?n:i,o=Number.parseInt(t.toFixed(s).replace(".","")),a=Number.parseInt(e.toFixed(s).replace(".",""));return o%a/10**s}const Le=Symbol("evaluating");function m(t,e,n){let r;Object.defineProperty(t,e,{get(){if(r!==Le)return r===void 0&&(r=Le,r=n()),r},set(i){Object.defineProperty(t,e,{value:i})},configurable:!0})}function R(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function L(...t){const e={};for(const n of t){const r=Object.getOwnPropertyDescriptors(n);Object.assign(e,r)}return Object.defineProperties({},e)}function De(t){return JSON.stringify(t)}function tn(t){return t.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const xe="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function J(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const nn=ee(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function W(t){if(J(t)===!1)return!1;const e=t.constructor;if(e===void 0||typeof e!="function")return!0;const n=e.prototype;return!(J(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Fe(t){return W(t)?{...t}:Array.isArray(t)?[...t]:t}const rn=new Set(["string","number","symbol"]);function U(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function N(t,e,n){const r=new t._zod.constr(e??t._zod.def);return(!e||n?.parent)&&(r._zod.parent=t),r}function l(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function sn(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const on={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function an(t,e){const n=t._zod.def,r=L(t._zod.def,{get shape(){const i={};for(const s in e){if(!(s in n.shape))throw new Error(`Unrecognized key: "${s}"`);e[s]&&(i[s]=n.shape[s])}return R(this,"shape",i),i},checks:[]});return N(t,r)}function cn(t,e){const n=t._zod.def,r=L(t._zod.def,{get shape(){const i={...t._zod.def.shape};for(const s in e){if(!(s in n.shape))throw new Error(`Unrecognized key: "${s}"`);e[s]&&delete i[s]}return R(this,"shape",i),i},checks:[]});return N(t,r)}function un(t,e){if(!W(e))throw new Error("Invalid input to extend: expected a plain object");const n=t._zod.def.checks;if(n&&n.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const i=L(t._zod.def,{get shape(){const s={...t._zod.def.shape,...e};return R(this,"shape",s),s},checks:[]});return N(t,i)}function hn(t,e){if(!W(e))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...t._zod.def,get shape(){const r={...t._zod.def.shape,...e};return R(this,"shape",r),r},checks:t._zod.def.checks};return N(t,n)}function pn(t,e){const n=L(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e._zod.def.shape};return R(this,"shape",r),r},get catchall(){return e._zod.def.catchall},checks:[]});return N(t,n)}function ln(t,e,n){const r=L(e._zod.def,{get shape(){const i=e._zod.def.shape,s={...i};if(n)for(const o in n){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(s[o]=t?new t({type:"optional",innerType:i[o]}):i[o])}else for(const o in i)s[o]=t?new t({type:"optional",innerType:i[o]}):i[o];return R(this,"shape",s),s},checks:[]});return N(e,r)}function dn(t,e,n){const r=L(e._zod.def,{get shape(){const i=e._zod.def.shape,s={...i};if(n)for(const o in n){if(!(o in s))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(s[o]=new t({type:"nonoptional",innerType:i[o]}))}else for(const o in i)s[o]=new t({type:"nonoptional",innerType:i[o]});return R(this,"shape",s),s},checks:[]});return N(e,r)}function G(t,e=0){if(t.aborted===!0)return!0;for(let n=e;n<t.issues.length;n++)if(t.issues[n]?.continue!==!0)return!0;return!1}function je(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function te(t){return typeof t=="string"?t:t?.message}function D(t,e,n){const r={...t,path:t.path??[]};if(!t.message){const i=te(t.inst?._zod.def?.error?.(t))??te(e?.error?.(t))??te(n.customError?.(t))??te(n.localeError?.(t))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,e?.reportInput||delete r.input,r}function _e(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function K(...t){const[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}const Me=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,me,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Ue=u("$ZodError",Me),Ge=u("$ZodError",Me,{Parent:Error});function fn(t,e=n=>n.message){const n={},r=[];for(const i of t.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(e(i))):r.push(e(i));return{formErrors:r,fieldErrors:n}}function mn(t,e=n=>n.message){const n={_errors:[]},r=i=>{for(const s of i.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(o=>r({issues:o}));else if(s.code==="invalid_key")r({issues:s.issues});else if(s.code==="invalid_element")r({issues:s.issues});else if(s.path.length===0)n._errors.push(e(s));else{let o=n,a=0;for(;a<s.path.length;){const c=s.path[a];a===s.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(e(s))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return r(t),n}const ke=t=>(e,n,r,i)=>{const s=r?Object.assign(r,{async:!1}):{async:!1},o=e._zod.run({value:n,issues:[]},s);if(o instanceof Promise)throw new M;if(o.issues.length){const a=new(i?.Err??t)(o.issues.map(c=>D(c,s,C())));throw xe(a,i?.callee),a}return o.value},ye=t=>async(e,n,r,i)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let o=e._zod.run({value:n,issues:[]},s);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new(i?.Err??t)(o.issues.map(c=>D(c,s,C())));throw xe(a,i?.callee),a}return o.value},ne=t=>(e,n,r)=>{const i=r?{...r,async:!1}:{async:!1},s=e._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new M;return s.issues.length?{success:!1,error:new(t??Ue)(s.issues.map(o=>D(o,i,C())))}:{success:!0,data:s.value}},gn=ne(Ge),re=t=>async(e,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let s=e._zod.run({value:n,issues:[]},i);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new t(s.issues.map(o=>D(o,i,C())))}:{success:!0,data:s.value}},vn=re(Ge),_n=t=>(e,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ke(t)(e,n,i)},kn=t=>(e,n,r)=>ke(t)(e,n,r),yn=t=>async(e,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ye(t)(e,n,i)},Tn=t=>async(e,n,r)=>ye(t)(e,n,r),wn=t=>(e,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ne(t)(e,n,i)},bn=t=>(e,n,r)=>ne(t)(e,n,r),En=t=>async(e,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return re(t)(e,n,i)},In=t=>async(e,n,r)=>re(t)(e,n,r),zn=/^[cC][^\s-]{8,}$/,$n=/^[0-9a-z]+$/,On=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Pn=/^[0-9a-vA-V]{20}$/,Sn=/^[A-Za-z0-9]{27}$/,Nn=/^[a-zA-Z0-9_-]{21}$/,An=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Zn=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ve=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Cn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Rn="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Ln(){return new RegExp(Rn,"u")}const Dn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,xn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Fn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,jn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Mn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Be=/^[A-Za-z0-9_-]*$/,Un=/^\+(?:[0-9]){6,14}[0-9]$/,Je="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Gn=new RegExp(`^${Je}$`);function We(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Vn(t){return new RegExp(`^${We(t)}$`)}function Bn(t){const e=We({precision:t.precision}),n=["Z"];t.local&&n.push(""),t.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${e}(?:${n.join("|")})`;return new RegExp(`^${Je}T(?:${r})$`)}const Jn=t=>{const e=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},Wn=/^-?\d+$/,Kn=/^-?\d+(?:\.\d+)?/,Yn=/^[^A-Z]*$/,qn=/^[^a-z]*$/,E=u("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),Ke={number:"number",bigint:"bigint",object:"date"},Ye=u("$ZodCheckLessThan",(t,e)=>{E.init(t,e);const n=Ke[typeof e.value];t._zod.onattach.push(r=>{const i=r._zod.bag,s=(e.inclusive?i.maximum:i.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<s&&(e.inclusive?i.maximum=e.value:i.exclusiveMaximum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:n,code:"too_big",maximum:e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),qe=u("$ZodCheckGreaterThan",(t,e)=>{E.init(t,e);const n=Ke[typeof e.value];t._zod.onattach.push(r=>{const i=r._zod.bag,s=(e.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>s&&(e.inclusive?i.minimum=e.value:i.exclusiveMinimum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:n,code:"too_small",minimum:e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Xn=u("$ZodCheckMultipleOf",(t,e)=>{E.init(t,e),t._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=e.value)}),t._zod.check=n=>{if(typeof n.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%e.value===BigInt(0):en(n.value,e.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:e.value,input:n.value,inst:t,continue:!e.abort})}}),Qn=u("$ZodCheckNumberFormat",(t,e)=>{E.init(t,e),e.format=e.format||"float64";const n=e.format?.includes("int"),r=n?"int":"number",[i,s]=on[e.format];t._zod.onattach.push(o=>{const a=o._zod.bag;a.format=e.format,a.minimum=i,a.maximum=s,n&&(a.pattern=Wn)}),t._zod.check=o=>{const a=o.value;if(n){if(!Number.isInteger(a)){o.issues.push({expected:r,format:e.format,code:"invalid_type",continue:!1,input:a,inst:t});return}if(!Number.isSafeInteger(a)){a>0?o.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,continue:!e.abort}):o.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,continue:!e.abort});return}}a<i&&o.issues.push({origin:"number",input:a,code:"too_small",minimum:i,inclusive:!0,inst:t,continue:!e.abort}),a>s&&o.issues.push({origin:"number",input:a,code:"too_big",maximum:s,inst:t})}}),Hn=u("$ZodCheckMaxLength",(t,e)=>{var n;E.init(t,e),(n=t._zod.def).when??(n.when=r=>{const i=r.value;return!ge(i)&&i.length!==void 0}),t._zod.onattach.push(r=>{const i=r._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<i&&(r._zod.bag.maximum=e.maximum)}),t._zod.check=r=>{const i=r.value;if(i.length<=e.maximum)return;const o=_e(i);r.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:i,inst:t,continue:!e.abort})}}),er=u("$ZodCheckMinLength",(t,e)=>{var n;E.init(t,e),(n=t._zod.def).when??(n.when=r=>{const i=r.value;return!ge(i)&&i.length!==void 0}),t._zod.onattach.push(r=>{const i=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>i&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{const i=r.value;if(i.length>=e.minimum)return;const o=_e(i);r.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:i,inst:t,continue:!e.abort})}}),tr=u("$ZodCheckLengthEquals",(t,e)=>{var n;E.init(t,e),(n=t._zod.def).when??(n.when=r=>{const i=r.value;return!ge(i)&&i.length!==void 0}),t._zod.onattach.push(r=>{const i=r._zod.bag;i.minimum=e.length,i.maximum=e.length,i.length=e.length}),t._zod.check=r=>{const i=r.value,s=i.length;if(s===e.length)return;const o=_e(i),a=s>e.length;r.issues.push({origin:o,...a?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),ie=u("$ZodCheckStringFormat",(t,e)=>{var n,r;E.init(t,e),t._zod.onattach.push(i=>{const s=i._zod.bag;s.format=e.format,e.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(e.pattern))}),e.pattern?(n=t._zod).check??(n.check=i=>{e.pattern.lastIndex=0,!e.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:e.format,input:i.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(r=t._zod).check??(r.check=()=>{})}),nr=u("$ZodCheckRegex",(t,e)=>{ie.init(t,e),t._zod.check=n=>{e.pattern.lastIndex=0,!e.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),rr=u("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=Yn),ie.init(t,e)}),ir=u("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=qn),ie.init(t,e)}),sr=u("$ZodCheckIncludes",(t,e)=>{E.init(t,e);const n=U(e.includes),r=new RegExp(typeof e.position=="number"?`^.{${e.position}}${n}`:n);e.pattern=r,t._zod.onattach.push(i=>{const s=i._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),t._zod.check=i=>{i.value.includes(e.includes,e.position)||i.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:i.value,inst:t,continue:!e.abort})}}),or=u("$ZodCheckStartsWith",(t,e)=>{E.init(t,e);const n=new RegExp(`^${U(e.prefix)}.*`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),t._zod.check=r=>{r.value.startsWith(e.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:r.value,inst:t,continue:!e.abort})}}),ar=u("$ZodCheckEndsWith",(t,e)=>{E.init(t,e);const n=new RegExp(`.*${U(e.suffix)}$`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),t._zod.check=r=>{r.value.endsWith(e.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:r.value,inst:t,continue:!e.abort})}}),cr=u("$ZodCheckOverwrite",(t,e)=>{E.init(t,e),t._zod.check=n=>{n.value=e.tx(n.value)}});class ur{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const r=e.split(`
13
- `).filter(o=>o),i=Math.min(...r.map(o=>o.length-o.trimStart().length)),s=r.map(o=>o.slice(i)).map(o=>" ".repeat(this.indent*2)+o);for(const o of s)this.content.push(o)}compile(){const e=Function,n=this?.args,i=[...(this?.content??[""]).map(s=>` ${s}`)];return new e(...n,i.join(`
14
- `))}}const hr={major:4,minor:2,patch:1},k=u("$ZodType",(t,e)=>{var n;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=hr;const r=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&r.unshift(t);for(const i of r)for(const s of i._zod.onattach)s(t);if(r.length===0)(n=t._zod).deferred??(n.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{const i=(o,a,c)=>{let h=G(o),p;for(const d of a){if(d._zod.def.when){if(!d._zod.def.when(o))continue}else if(h)continue;const f=o.issues.length,_=d._zod.check(o);if(_ instanceof Promise&&c?.async===!1)throw new M;if(p||_ instanceof Promise)p=(p??Promise.resolve()).then(async()=>{await _,o.issues.length!==f&&(h||(h=G(o,f)))});else{if(o.issues.length===f)continue;h||(h=G(o,f))}}return p?p.then(()=>o):o},s=(o,a,c)=>{if(G(o))return o.aborted=!0,o;const h=i(a,r,c);if(h instanceof Promise){if(c.async===!1)throw new M;return h.then(p=>t._zod.parse(p,c))}return t._zod.parse(h,c)};t._zod.run=(o,a)=>{if(a.skipChecks)return t._zod.parse(o,a);if(a.direction==="backward"){const h=t._zod.parse({value:o.value,issues:[]},{...a,skipChecks:!0});return h instanceof Promise?h.then(p=>s(p,o,a)):s(h,o,a)}const c=t._zod.parse(o,a);if(c instanceof Promise){if(a.async===!1)throw new M;return c.then(h=>i(h,r,a))}return i(c,r,a)}}t["~standard"]={validate:i=>{try{const s=gn(t,i);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return vn(t,i).then(o=>o.success?{value:o.data}:{issues:o.error?.issues})}},vendor:"zod",version:1}}),Te=u("$ZodString",(t,e)=>{k.init(t,e),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??Jn(t._zod.bag),t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:t}),n}}),g=u("$ZodStringFormat",(t,e)=>{ie.init(t,e),Te.init(t,e)}),pr=u("$ZodGUID",(t,e)=>{e.pattern??(e.pattern=Zn),g.init(t,e)}),lr=u("$ZodUUID",(t,e)=>{if(e.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[e.version];if(r===void 0)throw new Error(`Invalid UUID version: "${e.version}"`);e.pattern??(e.pattern=Ve(r))}else e.pattern??(e.pattern=Ve());g.init(t,e)}),dr=u("$ZodEmail",(t,e)=>{e.pattern??(e.pattern=Cn),g.init(t,e)}),fr=u("$ZodURL",(t,e)=>{g.init(t,e),t._zod.check=n=>{try{const r=n.value.trim(),i=new URL(r);e.hostname&&(e.hostname.lastIndex=0,e.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:e.hostname.source,input:n.value,inst:t,continue:!e.abort})),e.protocol&&(e.protocol.lastIndex=0,e.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:n.value,inst:t,continue:!e.abort})),e.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:t,continue:!e.abort})}}}),mr=u("$ZodEmoji",(t,e)=>{e.pattern??(e.pattern=Ln()),g.init(t,e)}),gr=u("$ZodNanoID",(t,e)=>{e.pattern??(e.pattern=Nn),g.init(t,e)}),vr=u("$ZodCUID",(t,e)=>{e.pattern??(e.pattern=zn),g.init(t,e)}),_r=u("$ZodCUID2",(t,e)=>{e.pattern??(e.pattern=$n),g.init(t,e)}),kr=u("$ZodULID",(t,e)=>{e.pattern??(e.pattern=On),g.init(t,e)}),yr=u("$ZodXID",(t,e)=>{e.pattern??(e.pattern=Pn),g.init(t,e)}),Tr=u("$ZodKSUID",(t,e)=>{e.pattern??(e.pattern=Sn),g.init(t,e)}),wr=u("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=Bn(e)),g.init(t,e)}),br=u("$ZodISODate",(t,e)=>{e.pattern??(e.pattern=Gn),g.init(t,e)}),Er=u("$ZodISOTime",(t,e)=>{e.pattern??(e.pattern=Vn(e)),g.init(t,e)}),Ir=u("$ZodISODuration",(t,e)=>{e.pattern??(e.pattern=An),g.init(t,e)}),zr=u("$ZodIPv4",(t,e)=>{e.pattern??(e.pattern=Dn),g.init(t,e),t._zod.bag.format="ipv4"}),$r=u("$ZodIPv6",(t,e)=>{e.pattern??(e.pattern=xn),g.init(t,e),t._zod.bag.format="ipv6",t._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:t,continue:!e.abort})}}}),Or=u("$ZodCIDRv4",(t,e)=>{e.pattern??(e.pattern=Fn),g.init(t,e)}),Pr=u("$ZodCIDRv6",(t,e)=>{e.pattern??(e.pattern=jn),g.init(t,e),t._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[i,s]=r;if(!s)throw new Error;const o=Number(s);if(`${o}`!==s)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${i}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:t,continue:!e.abort})}}});function Xe(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const Sr=u("$ZodBase64",(t,e)=>{e.pattern??(e.pattern=Mn),g.init(t,e),t._zod.bag.contentEncoding="base64",t._zod.check=n=>{Xe(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:t,continue:!e.abort})}});function Nr(t){if(!Be.test(t))return!1;const e=t.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=e.padEnd(Math.ceil(e.length/4)*4,"=");return Xe(n)}const Ar=u("$ZodBase64URL",(t,e)=>{e.pattern??(e.pattern=Be),g.init(t,e),t._zod.bag.contentEncoding="base64url",t._zod.check=n=>{Nr(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:t,continue:!e.abort})}}),Zr=u("$ZodE164",(t,e)=>{e.pattern??(e.pattern=Un),g.init(t,e)});function Cr(t,e=null){try{const n=t.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const i=JSON.parse(atob(r));return!("typ"in i&&i?.typ!=="JWT"||!i.alg||e&&(!("alg"in i)||i.alg!==e))}catch{return!1}}const Rr=u("$ZodJWT",(t,e)=>{g.init(t,e),t._zod.check=n=>{Cr(n.value,e.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:t,continue:!e.abort})}}),Qe=u("$ZodNumber",(t,e)=>{k.init(t,e),t._zod.pattern=t._zod.bag.pattern??Kn,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=Number(n.value)}catch{}const i=n.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return n;const s=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:t,...s?{received:s}:{}}),n}}),Lr=u("$ZodNumberFormat",(t,e)=>{Qn.init(t,e),Qe.init(t,e)}),Dr=u("$ZodUnknown",(t,e)=>{k.init(t,e),t._zod.parse=n=>n}),xr=u("$ZodNever",(t,e)=>{k.init(t,e),t._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:t}),n)});function He(t,e,n){t.issues.length&&e.issues.push(...je(n,t.issues)),e.value[n]=t.value}const Fr=u("$ZodArray",(t,e)=>{k.init(t,e),t._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:t}),n;n.value=Array(i.length);const s=[];for(let o=0;o<i.length;o++){const a=i[o],c=e.element._zod.run({value:a,issues:[]},r);c instanceof Promise?s.push(c.then(h=>He(h,n,o))):He(c,n,o)}return s.length?Promise.all(s).then(()=>n):n}});function se(t,e,n,r){t.issues.length&&e.issues.push(...je(n,t.issues)),t.value===void 0?n in r&&(e.value[n]=void 0):e.value[n]=t.value}function et(t){const e=Object.keys(t.shape);for(const r of e)if(!t.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=sn(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}}function tt(t,e,n,r,i,s){const o=[],a=i.keySet,c=i.catchall._zod,h=c.def.type;for(const p in e){if(a.has(p))continue;if(h==="never"){o.push(p);continue}const d=c.run({value:e[p],issues:[]},r);d instanceof Promise?t.push(d.then(f=>se(f,n,p,e))):se(d,n,p,e)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:e,inst:s}),t.length?Promise.all(t).then(()=>n):n}const jr=u("$ZodObject",(t,e)=>{if(k.init(t,e),!Object.getOwnPropertyDescriptor(e,"shape")?.get){const a=e.shape;Object.defineProperty(e,"shape",{get:()=>{const c={...a};return Object.defineProperty(e,"shape",{value:c}),c}})}const r=ee(()=>et(e));m(t._zod,"propValues",()=>{const a=e.shape,c={};for(const h in a){const p=a[h]._zod;if(p.values){c[h]??(c[h]=new Set);for(const d of p.values)c[h].add(d)}}return c});const i=J,s=e.catchall;let o;t._zod.parse=(a,c)=>{o??(o=r.value);const h=a.value;if(!i(h))return a.issues.push({expected:"object",code:"invalid_type",input:h,inst:t}),a;a.value={};const p=[],d=o.shape;for(const f of o.keys){const $=d[f]._zod.run({value:h[f],issues:[]},c);$ instanceof Promise?p.push($.then($e=>se($e,a,f,h))):se($,a,f,h)}return s?tt(p,h,a,c,r.value,t):p.length?Promise.all(p).then(()=>a):a}}),Mr=u("$ZodObjectJIT",(t,e)=>{jr.init(t,e);const n=t._zod.parse,r=ee(()=>et(e)),i=f=>{const _=new ur(["shape","payload","ctx"]),$=r.value,$e=S=>{const P=De(S);return`shape[${P}]._zod.run({ value: input[${P}], issues: [] }, ctx)`};_.write("const input = payload.value;");const Ct=Object.create(null);let Mo=0;for(const S of $.keys)Ct[S]=`key_${Mo++}`;_.write("const newResult = {};");for(const S of $.keys){const P=Ct[S],q=De(S);_.write(`const ${P} = ${$e(S)};`),_.write(`
1
+ (function(T,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(T=typeof globalThis<"u"?globalThis:T||self,F(T.PolagramCore={}))})(this,(function(T){"use strict";const F={"->":{type:"sync",style:{line:"solid",head:"open"}},"->>":{type:"sync",style:{line:"solid",head:"arrow"}},"-->":{type:"reply",style:{line:"dotted",head:"open"}},"-->>":{type:"reply",style:{line:"dotted",head:"arrow"}},"-)":{type:"async",style:{line:"solid",head:"async"}},"--)":{type:"async",style:{line:"dotted",head:"async"}},"-x":{type:"destroy",style:{line:"solid",head:"cross"}},"--x":{type:"destroy",style:{line:"dotted",head:"cross"}}},Rt=Object.entries(F).reduce((t,[e,r])=>{const n=JSON.stringify({type:r.type,style:r.style});return t[n]=e,t},{});function xt(t,e){const r=JSON.stringify({type:t,style:e});return Rt[r]||"->>"}class he{constructor(e){this.visitor=e}traverse(e){this.visitor.visitRoot(e)}dispatchEvent(e){switch(e.kind){case"message":this.visitor.visitMessage(e);break;case"fragment":this.visitor.visitFragment(e);break;case"note":this.visitor.visitNote(e);break;case"activation":this.visitor.visitActivation(e);break;case"divider":this.visitor.visitDivider(e);break;case"spacer":this.visitor.visitSpacer(e);break;case"ref":this.visitor.visitReference(e);break}}dispatchEvents(e){for(const r of e)this.dispatchEvent(r)}}class le{lines=[];indentLevel=0;traverser;constructor(){this.traverser=new he(this)}visitParticipantGroup(e){}generate(e){return this.lines=[],this.indentLevel=0,this.traverser.traverse(e),this.lines.join(`
2
+ `)}visitRoot(e){this.lines.push("sequenceDiagram"),this.indentLevel++,e.meta?.title&&this.add(`title ${e.meta.title}`);const r=new Map;for(const i of e.participants)r.set(i.id,[]);for(const i of e.groups)for(const s of i.participantIds){const o=r.get(s);o&&o.push(i)}const n=[];for(const i of e.participants){const s=r.get(i.id)||[];let o=0;const a=Math.min(n.length,s.length);for(let c=0;c<a&&n[c]===s[c];c++)o++;for(;n.length>o;)this.indentLevel--,this.add("end"),n.pop();for(let c=o;c<s.length;c++){const p=s[c];let h="box";p.style?.backgroundColor&&(h+=` ${p.style.backgroundColor}`),p.name&&(h+=` ${p.name}`),this.add(h),this.indentLevel++,n.push(p)}this.visitParticipant(i)}for(;n.length>0;)this.indentLevel--,this.add("end"),n.pop();this.traverser.dispatchEvents(e.events)}visitParticipant(e){const r=e.type==="actor"?"actor":"participant",n=e.name;e.id===e.name?this.add(`${r} ${e.id}`):this.add(`${r} ${e.id} as ${n}`)}visitMessage(e){const r=e.from??"[*]",n=e.to??"[*]",i=xt(e.type,e.style);let s="";e.lifecycle?.activateTarget&&(s+="+"),e.lifecycle?.deactivateSource&&(s+="-"),this.add(`${r}${i}${s}${n}: ${e.text}`)}visitFragment(e){if(e.branches.length===0)return;const r=e.branches[0],n=r.condition?` ${r.condition}`:"";this.add(`${e.operator}${n}`),this.indent(()=>{this.traverser.dispatchEvents(r.events)});let i="else";e.operator==="par"?i="and":e.operator==="critical"&&(i="option");for(let s=1;s<e.branches.length;s++){const o=e.branches[s],a=o.condition?` ${o.condition}`:"";this.add(`${i}${a}`),this.indent(()=>{this.traverser.dispatchEvents(o.events)})}this.add("end")}visitNote(e){const r=e.position;let n="";e.participantIds.length>0&&(n=e.participantIds.join(","),r!=="over"?n=` of ${n}`:n=` ${n}`),this.add(`note ${r}${n}: ${e.text}`)}visitActivation(e){this.add(`${e.action} ${e.participantId}`)}visitDivider(e){this.add(`%% == ${e.text||""} ==`)}visitSpacer(e){this.add(`...${e.text||""}...`)}visitReference(e){this.add(`%% ref: ${e.text}`)}add(e){const r=" ".repeat(this.indentLevel);this.lines.push(`${r}${e}`)}indent(e){this.indentLevel++,e(),this.indentLevel--}}class de{lines=[];traverser;constructor(){this.traverser=new he(this)}generate(e){return this.lines=[],this.traverser.traverse(e),this.lines.join(`
3
+ `)}visitRoot(e){this.add("@startuml"),e.meta.title&&this.add(`title ${e.meta.title}`);const r=new Map;for(const i of e.participants)r.set(i.id,[]);for(const i of e.groups)for(const s of i.participantIds){const o=r.get(s);o&&o.push(i)}const n=[];for(const i of e.participants){const s=r.get(i.id)||[];let o=0;const a=Math.min(n.length,s.length);for(let c=0;c<a&&n[c]===s[c];c++)o++;for(;n.length>o;)this.add("end box"),n.pop();for(let c=o;c<s.length;c++){const p=s[c],h=p.style?.backgroundColor?` ${p.style.backgroundColor}`:"",d=p.name?` "${p.name}"`:"";this.add(`box${d}${h}`),n.push(p)}this.visitParticipant(i)}for(;n.length>0;)this.add("end box"),n.pop();this.traverser.dispatchEvents(e.events),this.add("@enduml")}visitParticipant(e){e.name===e.id?this.add(`${e.type} ${e.id}`):this.add(`${e.type} "${e.name}" as ${e.id}`)}visitParticipantGroup(e){}visitMessage(e){const r=e.from||"[*]",n=e.to||"[*]";let i="->";e.type==="reply"?i="-->":e.type==="async"&&(i="->>"),this.add(`${r} ${i} ${n}: ${e.text}`)}visitFragment(e){const r=e.operator;e.branches.forEach((n,i)=>{i===0?this.add(`${r} ${n.condition||""}`.trim()):this.add(`else ${n.condition||""}`.trim()),this.traverser.dispatchEvents(n.events)}),this.add("end")}visitNote(e){const r=e.position||"over",n=e.participantIds.join(", ");let i="";e.participantIds.length>0?r==="over"?i=`note over ${n}`:i=`note ${r} of ${n}`:i=`note ${r}`,this.add(i),e.text.split(`
4
+ `).forEach(s=>{this.add(` ${s}`)}),this.add("end note")}visitActivation(e){this.add(`${e.action} ${e.participantId}`)}visitDivider(e){e.text?this.add(`== ${e.text} ==`):this.add("====")}visitSpacer(e){this.add("|||")}visitReference(e){const r=e.participantIds.join(", ");this.add(`ref over ${r}: ${e.text}`)}add(e){this.lines.push(e)}}class Oe{constructor(e){this.input=e,this.readChar()}position=0;readPosition=0;ch="";line=1;column=0;getInput(){return this.input}readChar(){this.readPosition>=this.input.length?this.ch="":this.ch=this.input[this.readPosition],this.position=this.readPosition,this.readPosition+=1,this.column+=1,this.ch===`
5
+ `&&(this.line+=1,this.column=0)}peekChar(){return this.readPosition>=this.input.length?"":this.input[this.readPosition]}skipWhitespace(){for(;this.ch===" "||this.ch===" "||this.ch==="\r";)this.readChar()}readWhile(e){const r=this.position;for(;e(this.ch);)this.readChar();return this.input.slice(r,this.position)}isLetter(e){return"a"<=e&&e<="z"||"A"<=e&&e<="Z"||e==="_"?!0:e.charCodeAt(0)>127?!/[\s\d]/.test(e):!1}isDigit(e){return"0"<=e&&e<="9"}readIdentifier(){const e=this.position;for(;this.isLetter(this.ch)||this.isDigit(this.ch);)this.readChar();return this.input.slice(e,this.position)}readQuotedString(){const e=this.position+1;for(this.readChar();this.ch!=='"'&&this.ch!==""&&this.ch!==`
6
+ `;)this.readChar();const r=this.input.slice(e,this.position);return this.readChar(),r}createToken(e,r,n,i){return{type:e,literal:r,line:this.line,column:i,start:n,end:this.position>n?this.position:n+r.length}}}let Lt=class extends Oe{nextToken(){if(this.skipWhitespace(),this.ch==="%"&&this.peekChar()==="%")return this.skipComment(),this.nextToken();const e=this.position,r=this.column;let n;switch(this.ch){case":":n=this.newToken("COLON",this.ch,e,r);break;case",":n=this.newToken("COMMA",this.ch,e,r);break;case"+":n=this.newToken("PLUS",this.ch,e,r);break;case"-":if(this.isArrowStart()){const i=this.readArrow();return n=this.newToken("ARROW",i,e,r),n}else n=this.newToken("MINUS",this.ch,e,r);break;case'"':{const i=this.readString();return n=this.newToken("STRING",i,e,r),n}case`
7
+ `:n=this.newToken("NEWLINE",this.ch,e,r);break;case"":n=this.newToken("EOF","",e,r);break;default:if(this.isLetter(this.ch)){const i=this.readIdentifier(),s=this.lookupIdent(i);return this.newToken(s,i,e,r)}else if(this.isDigit(this.ch)){const i=this.readNumber();return this.newToken("IDENTIFIER",i,e,r)}else n=this.newToken("UNKNOWN",this.ch,e,r)}return this.readChar(),n}newToken(e,r,n,i){return{type:e,literal:r,line:this.line,column:i,start:n,end:this.position>n?this.position:n+r.length}}readNumber(){const e=this.position;for(;this.isDigit(this.ch);)this.readChar();return this.input.slice(e,this.position)}readString(){const e=this.position+1;for(this.readChar();this.ch!=='"'&&this.ch!==""&&this.ch!==`
8
+ `;)this.readChar();const r=this.input.slice(e,this.position);return this.ch,this.readChar(),r}isArrowStart(){if(this.ch!=="-")return!1;const e=this.peekChar();return e===">"||e==="-"||e===")"||e==="x"}readArrow(){if(this.input.slice(this.position,this.position+4)==="-->>")return this.readMulti(4),"-->>";const r=this.input.slice(this.position,this.position+3);if(r==="-->"||r==="--)"||r==="->>"||r==="--x")return this.readMulti(3),r;const n=this.input.slice(this.position,this.position+2);return n==="->"||n==="-)"||n==="-x"?(this.readMulti(2),n):"-"}readMulti(e){for(let r=0;r<e;r++)this.readChar()}skipComment(){for(;this.ch!==`
9
+ `&&this.ch!=="";)this.readChar()}lookupIdent(e){return{sequencediagram:"SEQUENCE_DIAGRAM",participant:"PARTICIPANT",actor:"ACTOR",loop:"LOOP",alt:"ALT",opt:"OPT",end:"END",else:"ELSE",note:"NOTE",left:"LEFT",right:"RIGHT",over:"OVER",of:"OF",as:"AS",title:"TITLE",activate:"ACTIVATE",deactivate:"DEACTIVATE",box:"BOX",par:"PAR",and:"AND",break:"BREAK",critical:"CRITICAL",option:"OPTION",rect:"RECT"}[e.toLowerCase()]||"IDENTIFIER"}};class Pe{constructor(e){this.lexer=e,this.advance(),this.advance()}currToken;peekToken;advance(){this.currToken=this.peekToken,this.peekToken=this.lexer.nextToken()}curTokenIs(e){return this.currToken.type===e}peekTokenIs(e){return this.peekToken.type===e}expectPeek(e){return this.peekTokenIs(e)?(this.advance(),!0):!1}isCurrentToken(e){return this.currToken.type===e}isCurrentTokenOneOf(e){return e.includes(this.currToken.type)}getCurrentTokenType(){return this.currToken.type}}let Dt=class extends Pe{currentGroup=null;idCounters={evt:0,frag:0,br:0,note:0,group:0};parse(){const e={kind:"root",meta:{version:"1.0.0",source:"unknown"},participants:[],groups:[],events:[]};return e.events=this.parseBlock(e),e}parseBlock(e,r=[]){const n=[];for(;!this.isCurrentToken("EOF");){const i=this.getCurrentTokenType();if(r.includes(i))return n;if(i==="NEWLINE"){this.advance();continue}if(i==="SEQUENCE_DIAGRAM"){e.meta.source="mermaid",this.advance();continue}if(i==="TITLE"){this.advance(),e.meta.title=this.readRestOfLine();continue}if(i==="BOX"){const s=this.parseGroup(e);n.push(...s);continue}if(i==="PARTICIPANT"||i==="ACTOR"){this.parseParticipant(e);continue}if(i==="LOOP"||i==="ALT"||i==="OPT"||i==="PAR"||i==="BREAK"||i==="CRITICAL"||i==="RECT"){n.push(this.parseFragment(e));continue}if(i==="NOTE"){n.push(this.parseNote(e));continue}if(i==="ACTIVATE"||i==="DEACTIVATE"){n.push(this.parseActivation(e));continue}if(this.isParticipantToken(this.currToken)){const s=this.parseMessage(e);if(s){n.push(s);continue}}this.advance()}return n}isParticipantToken(e){return e.type==="IDENTIFIER"||e.type==="STRING"}parseGroup(e){this.advance();const r=this.readRestOfLine().trim();let n=r,i;const s=r.split(/\s+/);if(s.length>0){const p=s[0];(p.startsWith("#")||["rgb","rgba","transparent","aqua","grey","gray","purple","red","blue","green"].includes(p.toLowerCase()))&&(i=p,n=s.slice(1).join(" "))}n||(n=`Group ${this.idCounters.group+1}`);const o={kind:"group",id:this.generateId("group"),name:n,type:"box",participantIds:[],style:i?{backgroundColor:i}:void 0};e.groups.push(o);const a=this.currentGroup;this.currentGroup=o;const c=this.parseBlock(e,["END"]);return this.currentGroup=a,this.isCurrentToken("END")&&this.advance(),c}parseFragment(e){const r=this.getCurrentTokenType();let n="loop";r==="ALT"&&(n="alt"),r==="OPT"&&(n="opt"),r==="PAR"&&(n="par"),r==="BREAK"&&(n="break"),r==="CRITICAL"&&(n="critical"),r==="RECT"&&(n="rect"),this.advance();const i=this.readRestOfLine(),s=[];let o;n==="par"?o=["END","ELSE","AND"]:n==="critical"?o=["END","OPTION"]:o=["END","ELSE"];const a=this.parseBlock(e,o);for(s.push({id:this.generateId("br"),condition:i,events:a});this.isCurrentToken("AND");){this.advance();const c=this.readRestOfLine(),p=this.parseBlock(e,["END","AND"]);s.push({id:this.generateId("br"),condition:c,events:p})}for(;this.isCurrentToken("OPTION");){this.advance();const c=this.readRestOfLine(),p=this.parseBlock(e,["END","OPTION"]);s.push({id:this.generateId("br"),condition:c,events:p})}for(;this.isCurrentToken("ELSE");){this.advance();const c=this.readRestOfLine(),p=this.parseBlock(e,["END","ELSE"]);s.push({id:this.generateId("br"),condition:c,events:p})}return this.isCurrentToken("END")&&this.advance(),{kind:"fragment",id:this.generateId("frag"),operator:n,branches:s}}parseParticipant(e){const r=this.currToken.type==="ACTOR";this.advance();let n="",i="";if(this.isParticipantToken(this.currToken)&&(n=this.currToken.literal,i=n,this.advance()),this.currToken.type==="AS"){this.advance();const o=this.readRestOfLine().trim();o&&(i=o)}const s=e.participants.find(o=>o.id===n);s?(i!==n&&(s.name=i),r&&(s.type="actor")):e.participants.push({id:n,name:i,type:r?"actor":"participant"}),this.currentGroup&&(this.currentGroup.participantIds.includes(n)||this.currentGroup.participantIds.push(n))}parseNote(e){this.advance();let r="over";this.currToken.type==="LEFT"?(r="left",this.advance()):this.currToken.type==="RIGHT"?(r="right",this.advance()):this.currToken.type==="OVER"&&(r="over",this.advance()),this.currToken.type==="OF"&&this.advance();const n=[];for(;this.isParticipantToken(this.currToken)&&(n.push(this.currToken.literal),this.ensureParticipant(e,this.currToken.literal),this.advance(),this.currToken.type==="COMMA");)this.advance();let i="";return this.currToken.type==="COLON"&&(this.advance(),i=this.readRestOfLine()),{kind:"note",id:this.generateId("note"),position:r,participantIds:n,text:i}}parseActivation(e){const r=this.currToken.type==="ACTIVATE"?"activate":"deactivate";this.advance();let n="";return this.isParticipantToken(this.currToken)&&(n=this.currToken.literal,this.ensureParticipant(e,n),this.advance()),{kind:"activation",participantId:n,action:r}}parseMessage(e){if(this.peekToken.type!=="ARROW")return null;const r=this.currToken.literal;if(this.ensureParticipant(e,r),this.advance(),this.currToken.type!=="ARROW")return null;const n=this.currToken.literal;this.advance();let i=!1,s=!1;if(this.isCurrentToken("PLUS")&&(i=!0,this.advance()),this.isCurrentToken("MINUS")&&(s=!0,this.advance()),!this.isParticipantToken(this.currToken))return null;const o=this.currToken.literal;this.ensureParticipant(e,o),this.advance();let a="";this.isCurrentToken("COLON")&&(this.advance(),a=this.readRestOfLine());const{type:c,style:p}=this.resolveArrow(n);return{kind:"message",id:this.generateId("evt"),from:r,to:o,text:a,type:c,style:p,lifecycle:i||s?{activateTarget:i,deactivateSource:s}:void 0}}resolveArrow(e){const r=F[e];return r||{type:"sync",style:{line:"solid",head:"arrow"}}}generateId(e){return this.idCounters[e]++,`${e}_${this.idCounters[e]}`}readRestOfLine(){if(this.isCurrentToken("NEWLINE")||this.isCurrentToken("EOF"))return"";const e=this.currToken.start;let r=this.currToken.end;for(;!this.isCurrentToken("NEWLINE")&&!this.isCurrentToken("EOF");)r=this.currToken.end,this.advance();return this.lexer.getInput().slice(e,r)}ensureParticipant(e,r){e.participants.find(n=>n.id===r)||e.participants.push({id:r,name:r,type:"participant"})}};const Ft={parse:t=>{const e=new Lt(t);return new Dt(e).parse()}};class Mt extends Oe{nextToken(){this.skipWhitespace();const e=this.position,r=this.column;let n;switch(this.ch){case`
10
+ `:n=this.newToken("NEWLINE",this.ch,e,r);break;case"@":this.peekString("startuml")?(this.readMulti(9),n=this.newToken("START_UML","@startuml",e,r)):this.peekString("enduml")?(this.readMulti(7),n=this.newToken("END_UML","@enduml",e,r)):n=this.newToken("UNKNOWN",this.ch,e,r);break;case",":n=this.newToken("COMMA",",",e,r);break;case'"':{const i=this.readString();return this.newToken("STRING",i,e,r)}case":":n=this.newToken("COLON",":",e,r);break;case"-":{const i=this.readArrow();i?n=this.newToken("ARROW",i,e,r):n=this.newToken("UNKNOWN",this.ch,e,r);break}case"=":{if(this.peekExact("=")){const i=this.readDivider();return this.newToken("DIVIDER",i,e,r)}n=this.newToken("UNKNOWN",this.ch,e,r);break}case"":n=this.newToken("EOF","",e,r);break;default:if(this.isLetter(this.ch)){const i=this.readIdentifier(),s=this.lookupIdent(i);return this.newToken(s,i,e,r)}else n=this.newToken("UNKNOWN",this.ch,e,r)}return this.readChar(),n}newToken(e,r,n,i){const s=this.position===n?n+r.length:this.position;return{type:e,literal:r,line:this.line,column:i,start:n,end:s}}readString(){const e=this.position+1;for(this.readChar();this.ch!=='"'&&this.ch!==""&&this.ch!==`
11
+ `;)this.readChar();const r=this.input.slice(e,this.position);return this.readChar(),r}lookupIdent(e){return{title:"TITLE",participant:"PARTICIPANT",actor:"ACTOR",database:"DATABASE",as:"AS",activate:"ACTIVATE",deactivate:"DEACTIVATE",note:"NOTE",left:"LEFT",right:"RIGHT",over:"OVER",of:"OF",alt:"ALT",opt:"OPT",loop:"LOOP",else:"ELSE",end:"END",box:"BOX",boundary:"BOUNDARY",control:"CONTROL",entity:"ENTITY",collections:"COLLECTIONS",queue:"QUEUE","@startuml":"START_UML","@enduml":"END_UML"}[e]||"IDENTIFIER"}readArrow(){return this.peekString("->")?(this.readMulti(2),"-->"):this.peekExact(">")?(this.readMulti(1),"->"):null}peekExact(e){return this.input[this.position+1]===e}peekString(e){for(let r=0;r<e.length;r++)if(this.input[this.position+1+r]!==e[r])return!1;return!0}readRestOfLine(){const e=this.position;for(;this.input[this.position]!==`
12
+ `&&this.input[this.position]!==""&&this.position<this.input.length;)this.readChar();return this.input.slice(e,this.position).trim()}readMulti(e){for(let r=0;r<e;r++)this.readChar()}readDivider(){const r=this.readRestOfLine().match(/^==\s*(.*?)\s*==$/);return r?r[1]:""}}class jt extends Pe{isTokenType(e){return this.currToken.type===e}parse(){const e={kind:"root",meta:{version:"1.0.0",source:"plantuml"},participants:[],groups:[],events:[]};for(;this.currToken.type!=="EOF";){if(this.currToken.type==="START_UML"){this.advance();continue}if(this.currToken.type==="END_UML"){this.advance();continue}if(this.currToken.type==="TITLE"){this.advance(),e.meta.title=this.readRestOfLine().trim();continue}if(["PARTICIPANT","ACTOR","DATABASE","BOUNDARY","CONTROL","ENTITY","COLLECTIONS","QUEUE"].includes(this.currToken.type)){this.parseParticipant(e);continue}if(this.currToken.type==="DIVIDER"){const r={kind:"divider",id:`div_${e.events.length+1}`,text:this.currToken.literal||void 0};e.events.push(r),this.advance();continue}if(this.isParticipantToken(this.currToken)){const r=this.parseMessage(e);if(r){e.events.push(r);continue}}if(this.currToken.type==="ACTIVATE"||this.currToken.type==="DEACTIVATE"){const r=this.parseActivation(e);r&&e.events.push(r);continue}if(this.currToken.type==="NOTE"){const r=this.parseNote(e);r&&e.events.push(r);continue}if(["ALT","OPT","LOOP"].includes(this.currToken.type)){const r=this.parseFragment(e);r&&e.events.push(r);continue}if(this.currToken.type==="END")return e;if(this.currToken.type==="BOX"){const r=this.parseGroup(e);r&&e.groups.push(r);continue}this.advance()}return e}parseGroup(e){this.advance();let r="",n;this.currToken.type==="STRING"&&(r=this.currToken.literal,this.advance()),this.currToken.type==="UNKNOWN"&&this.currToken.literal==="#"&&(this.advance(),this.isTokenType("IDENTIFIER")&&(n=`#${this.currToken.literal}`,this.advance()));const i=[];for(;this.currToken.type!=="EOF";){if(this.currToken.type==="END"){this.advance(),this.isTokenType("BOX")&&this.advance();break}if(["PARTICIPANT","ACTOR","DATABASE","BOUNDARY","CONTROL","ENTITY","COLLECTIONS","QUEUE"].includes(this.currToken.type)){const s=e.participants.length;this.parseParticipant(e);const o=e.participants.length;o>s&&i.push(e.participants[o-1].id);continue}if(this.currToken.type==="IDENTIFIER"){this.advance();continue}this.advance()}return{kind:"group",id:`group_${e.groups.length+1}`,name:r,type:"box",participantIds:i,style:n?{backgroundColor:n}:void 0}}parseFragment(e){const r="fragment",n=this.currToken.literal.toLowerCase();this.advance();const i=this.readRestOfLine().trim(),s=[];let o=[];const a={id:`br_${s.length+1}`,condition:i,events:o};for(s.push(a);this.currToken.type!=="EOF";){if(this.currToken.type==="END"){this.advance();break}if(this.currToken.type==="ELSE"){this.advance();const p=this.readRestOfLine().trim();o=[],s.push({id:`br_${s.length+1}`,condition:p,events:o});continue}if(this.currToken.type==="NEWLINE"){this.advance();continue}const c=this.parseStatement(e);c&&o.push(c)}return{kind:r,id:`frag_${e.events.length+1}`,operator:n,branches:s}}parseStatement(e){if(["PARTICIPANT","ACTOR","DATABASE","BOUNDARY","CONTROL","ENTITY","COLLECTIONS","QUEUE"].includes(this.currToken.type))return this.parseParticipant(e),null;if(this.isParticipantToken(this.currToken)){const r=this.parseMessage(e);if(r)return r}return this.currToken.type==="ACTIVATE"||this.currToken.type==="DEACTIVATE"?this.parseActivation(e):this.currToken.type==="NOTE"?this.parseNote(e):["ALT","OPT","LOOP"].includes(this.currToken.type)?this.parseFragment(e):(this.advance(),null)}parseNote(e){this.advance();let r="over";this.currToken.type==="LEFT"?(r="left",this.advance()):this.currToken.type==="RIGHT"?(r="right",this.advance()):this.currToken.type==="OVER"&&(r="over",this.advance()),this.currToken.type==="OF"&&this.advance();const n=[];for(;this.isParticipantToken(this.currToken)&&(n.push(this.currToken.literal),this.ensureParticipant(e,this.currToken.literal),this.advance(),this.currToken.type==="COMMA");)this.advance();let i="";if(this.currToken.type==="COLON")this.advance(),i=this.readRestOfLine().trim();else{this.currToken.type==="NEWLINE"&&this.advance();const s=this.currToken.start;let o=s;for(;this.currToken.type!=="EOF";){if(this.currToken.type==="END"&&this.peekToken.type==="NOTE"){o=this.currToken.start,this.advance(),this.advance();break}this.advance()}i=this.lexer.getInput().slice(s,o).trim()}return{kind:"note",id:`note_${e.events.length+1}`,position:r,participantIds:n,text:i}}parseActivation(e){const r=this.currToken.type==="ACTIVATE"?"activate":"deactivate";this.advance();let n="";if(this.isParticipantToken(this.currToken))n=this.currToken.literal,this.ensureParticipant(e,n),this.advance();else return null;return{kind:"activation",participantId:n,action:r}}isParticipantToken(e){return e.type==="IDENTIFIER"||e.type==="STRING"}parseMessage(e){if(this.peekToken.type!=="ARROW")return null;const r=this.currToken.literal;this.ensureParticipant(e,r),this.advance();const n=this.currToken.literal;if(this.advance(),!this.isParticipantToken(this.currToken))return null;const i=this.currToken.literal;this.ensureParticipant(e,i),this.advance();let s="";this.currToken.type==="COLON"&&(this.advance(),s=this.readRestOfLine().trim());let o="sync",a={line:"solid",head:"arrow"};return n==="-->"?(o="reply",a={line:"dotted",head:"arrow"}):n==="->"&&(o="sync",a={line:"solid",head:"arrow"}),{kind:"message",id:`msg_${e.events.length+1}`,from:r,to:i,text:s,type:o,style:a}}ensureParticipant(e,r){e.participants.find(n=>n.id===r)||e.participants.push({id:r,name:r,type:"participant"})}parseParticipant(e){const r=this.currToken.type;let n="participant";r==="ACTOR"&&(n="actor"),r==="DATABASE"&&(n="database"),r==="BOUNDARY"&&(n="boundary"),r==="CONTROL"&&(n="control"),r==="ENTITY"&&(n="entity"),r==="COLLECTIONS"&&(n="collections"),r==="QUEUE"&&(n="queue"),this.advance();let i="",s="";(this.currToken.type==="STRING"||this.currToken.type==="IDENTIFIER")&&(i=this.currToken.literal,s=i,this.advance()),this.currToken.type==="AS"&&(this.advance(),this.isTokenType("IDENTIFIER")&&(s=this.currToken.literal,this.advance())),e.participants.push({id:s,name:i,type:n})}readRestOfLine(){if(this.currToken.type==="NEWLINE"||this.currToken.type==="EOF")return"";const e=this.currToken.start;let r=this.currToken.end;for(;!this.isTokenType("NEWLINE")&&!this.isTokenType("EOF");)r=this.currToken.end,this.advance();return this.lexer.getInput().slice(e,r).trim()}}const Ut={parse:t=>{const e=new Mt(t);return new jt(e).parse()}},Gt={".puml":"plantuml",".plantuml":"plantuml",".pu":"plantuml",".mmd":"mermaid",".mermaid":"mermaid"},Vt=[{pattern:/^\s*@startuml/m,format:"plantuml"},{pattern:/^\s*sequenceDiagram/m,format:"mermaid"}],fe={detect(t,e){const r=fe.detectByExtension(t);return r||fe.detectByContent(e)},detectByExtension(t){const e=t.toLowerCase().match(/\.[^.]+$/)?.[0];return e&&Gt[e]||null},detectByContent(t){for(const{pattern:e,format:r}of Vt)if(e.test(t))return r;return null},getDefaultExtension(t){switch(t){case"plantuml":return".puml";case"mermaid":return".mmd"}}},X=new Map;X.set("mermaid",Ft),X.set("plantuml",Ut);const Se={register(t,e){X.set(t,e)},getParser(t){const e=X.get(t);if(!e)throw new Error(`Parser for language '${t}' not found.`);return e}};class B{transform(e){const r=this.mapEvents(e.events);return{...e,events:r}}mapEvents(e){return e.flatMap(r=>this.visitEvent(r))}visitEvent(e){return e.kind==="fragment"?this.visitFragment(e):[e]}visitFragment(e){const r=e.branches.map(n=>this.visitBranch(n));return[{...e,branches:r}]}visitBranch(e){return{...e,events:this.mapEvents(e.events)}}}class Bt extends B{visitFragment(e){const r=super.visitFragment(e);if(r.length===0)return[];const n=r[0],i=n.branches.filter(s=>s.events.length>0);return i.length===0?[]:[{...n,branches:i}]}}class Jt{transform(e){const r=this.collectUsedParticipants(e.events),n=e.participants.filter(s=>r.has(s.id)),i=e.groups.map(s=>({...s,participantIds:s.participantIds.filter(o=>r.has(o))})).filter(s=>s.participantIds.length>0);return{...e,participants:n,groups:i}}collectUsedParticipants(e){const r=new Set;function n(i){for(const s of i)switch(s.kind){case"message":s.from&&r.add(s.from),s.to&&r.add(s.to);break;case"fragment":for(const o of s.branches)n(o.events);break;case"activation":r.add(s.participantId);break;case"note":s.participantIds.forEach(o=>{r.add(o)});break;case"ref":s.participantIds.forEach(o=>{r.add(o)});break}}return n(e),r}}class Q{matchBranch(e,r,n){return!(r.operator&&!(Array.isArray(r.operator)?r.operator:[r.operator]).includes(n)||r.condition&&(!e.condition||!this.matchText(e.condition,r.condition)))}matchParticipant(e,r){return!(r.id&&!this.matchText(e.id,r.id)||r.name&&!this.matchText(e.name,r.name)||r.stereotype&&e.stereotype&&!this.matchText(e.stereotype,r.stereotype))}matchMessage(e,r){return!(r.text&&!this.matchText(e.text,r.text)||r.from&&e.from&&!this.matchText(e.from,r.from)||r.to&&e.to&&!this.matchText(e.to,r.to))}matchGroup(e,r){return!(r.name&&e.name&&!this.matchText(e.name,r.name))}matchText(e,r){if(typeof r=="string")return e===r;if(r instanceof RegExp)return r.test(e);if(typeof r=="object"&&r.pattern){const n=r.flags||"";return new RegExp(r.pattern,n).test(e)}return!1}}class Wt extends B{constructor(e){super(),this.layer=e}matcher=new Q;targetParticipantIds=new Set;transform(e){return this.resolveTargetParticipants(e),super.transform(e)}resolveTargetParticipants(e){this.targetParticipantIds.clear();const r=this.layer.selector;e.participants.forEach(n=>{this.matcher.matchParticipant(n,r)&&this.targetParticipantIds.add(n.id)})}visitEvent(e){if(e.kind==="message"){const r=e;if(!this.isRelatedToParticipant(r))return[]}if(e.kind==="note"||e.kind==="ref")return this.filterMultiParticipantNode(e);if(e.kind==="activation"){const r=e;if(!this.targetParticipantIds.has(r.participantId))return[]}return super.visitEvent(e)}filterMultiParticipantNode(e){const r=e.participantIds.filter(n=>this.targetParticipantIds.has(n));return r.length===0?[]:[{...e,participantIds:r}]}isRelatedToParticipant(e){return!!(e.from&&this.targetParticipantIds.has(e.from)||e.to&&this.targetParticipantIds.has(e.to))}}class Kt extends B{constructor(e){super(),this.layer=e}matcher=new Q;mergedParticipantIds=new Set;targetParticipantId="";transform(e){const r=this.layer.selector,n=[];if(e.participants.forEach(d=>{this.matcher.matchParticipant(d,r)&&n.push(d)}),n.length===0)return e;this.mergedParticipantIds=new Set(n.map(d=>d.id));const i=this.layer.into||{};let s=i.id,o=i.name;s||(o?s=o.replace(/[^a-zA-Z0-9-_]/g,"_"):s=n.map(d=>d.id).join("_")),o||(o=s),this.targetParticipantId=s;const a=[],p=!e.participants.some(d=>d.id===s&&!this.mergedParticipantIds.has(d.id));let h=!1;for(const d of e.participants){if(this.mergedParticipantIds.has(d.id)){if(p&&!h){const f={id:s||"",name:o||"",type:"participant"};a.push(f),h=!0}continue}d.id,a.push(d)}return e.participants=a,e.groups=e.groups.map(d=>{const f=new Set;return d.participantIds.forEach(g=>{this.mergedParticipantIds.has(g)?f.add(this.targetParticipantId):f.add(g)}),{...d,participantIds:Array.from(f)}}),super.transform(e)}visitEvent(e){if(e.kind==="message")return this.transformMessage(e);if(e.kind==="note"||e.kind==="ref")return this.transformMultiParticipantNode(e);if(e.kind==="activation")return this.transformActivation(e);if(e.kind==="fragment"){const r=super.visitEvent(e);return r.length>0&&r[0].kind==="fragment"&&r[0].branches.every(s=>s.events.length===0)?[]:r}return super.visitEvent(e)}transformMessage(e){let r=e.from,n=e.to;return r&&this.mergedParticipantIds.has(r)&&(r=this.targetParticipantId),n&&this.mergedParticipantIds.has(n)&&(n=this.targetParticipantId),r===this.targetParticipantId&&n===this.targetParticipantId?[]:[{...e,from:r,to:n}]}transformMultiParticipantNode(e){const r=new Set;let n=!1;for(const s of e.participantIds)this.mergedParticipantIds.has(s)?(r.add(this.targetParticipantId),n=!0):r.add(s);if(!n)return[e];const i=Array.from(r);return[{...e,participantIds:i}]}transformActivation(e){return this.mergedParticipantIds.has(e.participantId)?[]:[e]}}class Yt extends B{constructor(e){super(),this.layer=e}matcher=new Q;removedParticipantIds=new Set;transform(e){const r=this.layer.selector;return r.kind==="participant"&&(e.participants.forEach(n=>{this.matcher.matchParticipant(n,r)&&this.removedParticipantIds.add(n.id)}),e.participants=e.participants.filter(n=>!this.removedParticipantIds.has(n.id))),r.kind==="group"&&(e.groups=e.groups.filter(n=>!this.matcher.matchGroup(n,r))),super.transform(e)}visitEvent(e){const r=this.layer.selector;if(r.kind==="message"&&e.kind==="message"&&this.matcher.matchMessage(e,r))return[];if(r.kind==="participant"){if(e.kind==="message"){const n=e;if(this.isRelatedToRemovedParticipant(n))return[]}if(e.kind==="note"||e.kind==="ref")return this.filterMultiParticipantNode(e);if(e.kind==="activation"){const n=e;if(this.removedParticipantIds.has(n.participantId))return[]}}return super.visitEvent(e)}filterMultiParticipantNode(e){const r=e.participantIds.filter(n=>!this.removedParticipantIds.has(n));return r.length===0?[]:[{...e,participantIds:r}]}isRelatedToRemovedParticipant(e){return!!(e.from&&this.removedParticipantIds.has(e.from)||e.to&&this.removedParticipantIds.has(e.to))}}class qt extends B{constructor(e){super(),this.layer=e}matcher=new Q;visitFragment(e){const r=e.branches.find(n=>this.matcher.matchBranch(n,this.layer.selector,e.operator));return r?this.mapEvents(r.events):super.visitFragment(e)}}class Xt{factories=new Map;constructor(){this.registerTyped("resolve",e=>new qt(e)),this.registerTyped("focus",e=>new Wt(e)),this.registerTyped("remove",e=>new Yt(e)),this.registerTyped("merge",e=>new Kt(e))}registerTyped(e,r){this.factories.set(e,r)}register(e,r){this.factories.set(e,r)}get(e){const r=this.factories.get(e.action);return r?r(e):null}has(e){return this.factories.has(e)}}const Ne=new Xt;class H{transform(e,r){let n=e;for(const i of r){const s=Ne.get(i);s?n=s.transform(n):console.warn(`Unknown action: ${i.action}`)}return n=new Bt().transform(n),n=new Jt().transform(n),n}}class Qt{constructor(){}static init(e,r="mermaid"){const i=Se.getParser(r).parse(e);return new Ae(i,r)}}class Ae{ast;layers=[];sourceFormat;constructor(e,r="mermaid"){this.ast=e,this.sourceFormat=r}focusParticipant(e){return this.layers.push({action:"focus",selector:this.normalizeParticipantSelector(e)}),this}removeParticipant(e){return this.layers.push({action:"remove",selector:this.normalizeParticipantSelector(e)}),this}removeMessage(e){return this.layers.push({action:"remove",selector:this.normalizeMessageSelector(e)}),this}removeGroup(e){return this.layers.push({action:"remove",selector:this.normalizeGroupSelector(e)}),this}resolveFragment(e){return this.layers.push({action:"resolve",selector:this.normalizeFragmentSelector(e)}),this}applyLens(e){return this.layers.push(...e.layers),this}toMermaid(){const r=new H().transform(this.ast,this.layers);return new le().generate(r)}toPlantUML(){const r=new H().transform(this.ast,this.layers);return new de().generate(r)}toAST(){return new H().transform(this.ast,this.layers)}getSourceFormat(){return this.sourceFormat}normalizeParticipantSelector(e){return this.isTextMatcher(e)?{kind:"participant",name:e}:{kind:"participant",...e}}normalizeMessageSelector(e){return this.isTextMatcher(e)?{kind:"message",text:e}:{kind:"message",...e}}normalizeGroupSelector(e){return this.isTextMatcher(e)?{kind:"group",name:e}:{kind:"group",...e}}normalizeFragmentSelector(e){return this.isTextMatcher(e)?{kind:"fragment",condition:e}:{kind:"fragment",...e}}isTextMatcher(e){return typeof e=="string"||e instanceof RegExp||typeof e=="object"&&e!==null&&"pattern"in e&&!("kind"in e)}}const M=new Map;M.set("mermaid",()=>new le),M.set("plantuml",()=>new de);const Ht={register(t,e){M.set(t,e)},getGenerator(t){const e=M.get(t);if(!e)throw new Error(`Generator for language '${t}' not found.`);return e()},hasGenerator(t){return M.has(t)},getLanguages(){return Array.from(M.keys())}};function u(t,e,r){function n(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(t))return;a._zod.traits.add(t),e(a,c);const p=o.prototype,h=Object.keys(p);for(let d=0;d<h.length;d++){const f=h[d];f in a||(a[f]=p[f].bind(a))}}const i=r?.Parent??Object;class s extends i{}Object.defineProperty(s,"name",{value:t});function o(a){var c;const p=r?.Parent?new s:this;n(p,a),(c=p._zod).deferred??(c.deferred=[]);for(const h of p._zod.deferred)h();return p}return Object.defineProperty(o,"init",{value:n}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>r?.Parent&&a instanceof r.Parent?!0:a?._zod?.traits?.has(t)}),Object.defineProperty(o,"name",{value:t}),o}class j extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Ze extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Ce={};function C(t){return Ce}function Re(t){const e=Object.values(t).filter(n=>typeof n=="number");return Object.entries(t).filter(([n,i])=>e.indexOf(+n)===-1).map(([n,i])=>i)}function me(t,e){return typeof e=="bigint"?e.toString():e}function ee(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function ge(t){return t==null}function ve(t){const e=t.startsWith("^")?1:0,r=t.endsWith("$")?t.length-1:t.length;return t.slice(e,r)}function er(t,e){const r=(t.toString().split(".")[1]||"").length,n=e.toString();let i=(n.split(".")[1]||"").length;if(i===0&&/\d?e-\d?/.test(n)){const c=n.match(/\d?e-(\d?)/);c?.[1]&&(i=Number.parseInt(c[1]))}const s=r>i?r:i,o=Number.parseInt(t.toFixed(s).replace(".","")),a=Number.parseInt(e.toFixed(s).replace(".",""));return o%a/10**s}const xe=Symbol("evaluating");function m(t,e,r){let n;Object.defineProperty(t,e,{get(){if(n!==xe)return n===void 0&&(n=xe,n=r()),n},set(i){Object.defineProperty(t,e,{value:i})},configurable:!0})}function R(t,e,r){Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0})}function x(...t){const e={};for(const r of t){const n=Object.getOwnPropertyDescriptors(r);Object.assign(e,n)}return Object.defineProperties({},e)}function Le(t){return JSON.stringify(t)}function tr(t){return t.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const De="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function J(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const rr=ee(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function W(t){if(J(t)===!1)return!1;const e=t.constructor;if(e===void 0||typeof e!="function")return!0;const r=e.prototype;return!(J(r)===!1||Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)}function Fe(t){return W(t)?{...t}:Array.isArray(t)?[...t]:t}const nr=new Set(["string","number","symbol"]);function U(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function N(t,e,r){const n=new t._zod.constr(e??t._zod.def);return(!e||r?.parent)&&(n._zod.parent=t),n}function l(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function ir(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const sr={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function or(t,e){const r=t._zod.def,n=x(t._zod.def,{get shape(){const i={};for(const s in e){if(!(s in r.shape))throw new Error(`Unrecognized key: "${s}"`);e[s]&&(i[s]=r.shape[s])}return R(this,"shape",i),i},checks:[]});return N(t,n)}function ar(t,e){const r=t._zod.def,n=x(t._zod.def,{get shape(){const i={...t._zod.def.shape};for(const s in e){if(!(s in r.shape))throw new Error(`Unrecognized key: "${s}"`);e[s]&&delete i[s]}return R(this,"shape",i),i},checks:[]});return N(t,n)}function cr(t,e){if(!W(e))throw new Error("Invalid input to extend: expected a plain object");const r=t._zod.def.checks;if(r&&r.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const i=x(t._zod.def,{get shape(){const s={...t._zod.def.shape,...e};return R(this,"shape",s),s},checks:[]});return N(t,i)}function ur(t,e){if(!W(e))throw new Error("Invalid input to safeExtend: expected a plain object");const r={...t._zod.def,get shape(){const n={...t._zod.def.shape,...e};return R(this,"shape",n),n},checks:t._zod.def.checks};return N(t,r)}function pr(t,e){const r=x(t._zod.def,{get shape(){const n={...t._zod.def.shape,...e._zod.def.shape};return R(this,"shape",n),n},get catchall(){return e._zod.def.catchall},checks:[]});return N(t,r)}function hr(t,e,r){const n=x(e._zod.def,{get shape(){const i=e._zod.def.shape,s={...i};if(r)for(const o in r){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);r[o]&&(s[o]=t?new t({type:"optional",innerType:i[o]}):i[o])}else for(const o in i)s[o]=t?new t({type:"optional",innerType:i[o]}):i[o];return R(this,"shape",s),s},checks:[]});return N(e,n)}function lr(t,e,r){const n=x(e._zod.def,{get shape(){const i=e._zod.def.shape,s={...i};if(r)for(const o in r){if(!(o in s))throw new Error(`Unrecognized key: "${o}"`);r[o]&&(s[o]=new t({type:"nonoptional",innerType:i[o]}))}else for(const o in i)s[o]=new t({type:"nonoptional",innerType:i[o]});return R(this,"shape",s),s},checks:[]});return N(e,n)}function G(t,e=0){if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(t.issues[r]?.continue!==!0)return!0;return!1}function Me(t,e){return e.map(r=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(t),r})}function te(t){return typeof t=="string"?t:t?.message}function L(t,e,r){const n={...t,path:t.path??[]};if(!t.message){const i=te(t.inst?._zod.def?.error?.(t))??te(e?.error?.(t))??te(r.customError?.(t))??te(r.localeError?.(t))??"Invalid input";n.message=i}return delete n.inst,delete n.continue,e?.reportInput||delete n.input,n}function _e(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function K(...t){const[e,r,n]=t;return typeof e=="string"?{message:e,code:"custom",input:r,inst:n}:{...e}}const je=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,me,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Ue=u("$ZodError",je),Ge=u("$ZodError",je,{Parent:Error});function dr(t,e=r=>r.message){const r={},n=[];for(const i of t.issues)i.path.length>0?(r[i.path[0]]=r[i.path[0]]||[],r[i.path[0]].push(e(i))):n.push(e(i));return{formErrors:n,fieldErrors:r}}function fr(t,e=r=>r.message){const r={_errors:[]},n=i=>{for(const s of i.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(o=>n({issues:o}));else if(s.code==="invalid_key")n({issues:s.issues});else if(s.code==="invalid_element")n({issues:s.issues});else if(s.path.length===0)r._errors.push(e(s));else{let o=r,a=0;for(;a<s.path.length;){const c=s.path[a];a===s.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(e(s))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return n(t),r}const ke=t=>(e,r,n,i)=>{const s=n?Object.assign(n,{async:!1}):{async:!1},o=e._zod.run({value:r,issues:[]},s);if(o instanceof Promise)throw new j;if(o.issues.length){const a=new(i?.Err??t)(o.issues.map(c=>L(c,s,C())));throw De(a,i?.callee),a}return o.value},ye=t=>async(e,r,n,i)=>{const s=n?Object.assign(n,{async:!0}):{async:!0};let o=e._zod.run({value:r,issues:[]},s);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new(i?.Err??t)(o.issues.map(c=>L(c,s,C())));throw De(a,i?.callee),a}return o.value},re=t=>(e,r,n)=>{const i=n?{...n,async:!1}:{async:!1},s=e._zod.run({value:r,issues:[]},i);if(s instanceof Promise)throw new j;return s.issues.length?{success:!1,error:new(t??Ue)(s.issues.map(o=>L(o,i,C())))}:{success:!0,data:s.value}},mr=re(Ge),ne=t=>async(e,r,n)=>{const i=n?Object.assign(n,{async:!0}):{async:!0};let s=e._zod.run({value:r,issues:[]},i);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new t(s.issues.map(o=>L(o,i,C())))}:{success:!0,data:s.value}},gr=ne(Ge),vr=t=>(e,r,n)=>{const i=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return ke(t)(e,r,i)},_r=t=>(e,r,n)=>ke(t)(e,r,n),kr=t=>async(e,r,n)=>{const i=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return ye(t)(e,r,i)},yr=t=>async(e,r,n)=>ye(t)(e,r,n),Tr=t=>(e,r,n)=>{const i=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return re(t)(e,r,i)},br=t=>(e,r,n)=>re(t)(e,r,n),wr=t=>async(e,r,n)=>{const i=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return ne(t)(e,r,i)},Ir=t=>async(e,r,n)=>ne(t)(e,r,n),Er=/^[cC][^\s-]{8,}$/,zr=/^[0-9a-z]+$/,$r=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Or=/^[0-9a-vA-V]{20}$/,Pr=/^[A-Za-z0-9]{27}$/,Sr=/^[a-zA-Z0-9_-]{21}$/,Nr=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Ar=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ve=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Zr=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Cr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Rr(){return new RegExp(Cr,"u")}const xr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Lr=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Dr=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Fr=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Mr=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Be=/^[A-Za-z0-9_-]*$/,jr=/^\+(?:[0-9]){6,14}[0-9]$/,Je="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Ur=new RegExp(`^${Je}$`);function We(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Gr(t){return new RegExp(`^${We(t)}$`)}function Vr(t){const e=We({precision:t.precision}),r=["Z"];t.local&&r.push(""),t.offset&&r.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const n=`${e}(?:${r.join("|")})`;return new RegExp(`^${Je}T(?:${n})$`)}const Br=t=>{const e=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},Jr=/^-?\d+$/,Wr=/^-?\d+(?:\.\d+)?/,Kr=/^[^A-Z]*$/,Yr=/^[^a-z]*$/,I=u("$ZodCheck",(t,e)=>{var r;t._zod??(t._zod={}),t._zod.def=e,(r=t._zod).onattach??(r.onattach=[])}),Ke={number:"number",bigint:"bigint",object:"date"},Ye=u("$ZodCheckLessThan",(t,e)=>{I.init(t,e);const r=Ke[typeof e.value];t._zod.onattach.push(n=>{const i=n._zod.bag,s=(e.inclusive?i.maximum:i.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<s&&(e.inclusive?i.maximum=e.value:i.exclusiveMaximum=e.value)}),t._zod.check=n=>{(e.inclusive?n.value<=e.value:n.value<e.value)||n.issues.push({origin:r,code:"too_big",maximum:e.value,input:n.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),qe=u("$ZodCheckGreaterThan",(t,e)=>{I.init(t,e);const r=Ke[typeof e.value];t._zod.onattach.push(n=>{const i=n._zod.bag,s=(e.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>s&&(e.inclusive?i.minimum=e.value:i.exclusiveMinimum=e.value)}),t._zod.check=n=>{(e.inclusive?n.value>=e.value:n.value>e.value)||n.issues.push({origin:r,code:"too_small",minimum:e.value,input:n.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),qr=u("$ZodCheckMultipleOf",(t,e)=>{I.init(t,e),t._zod.onattach.push(r=>{var n;(n=r._zod.bag).multipleOf??(n.multipleOf=e.value)}),t._zod.check=r=>{if(typeof r.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof r.value=="bigint"?r.value%e.value===BigInt(0):er(r.value,e.value)===0)||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:e.value,input:r.value,inst:t,continue:!e.abort})}}),Xr=u("$ZodCheckNumberFormat",(t,e)=>{I.init(t,e),e.format=e.format||"float64";const r=e.format?.includes("int"),n=r?"int":"number",[i,s]=sr[e.format];t._zod.onattach.push(o=>{const a=o._zod.bag;a.format=e.format,a.minimum=i,a.maximum=s,r&&(a.pattern=Jr)}),t._zod.check=o=>{const a=o.value;if(r){if(!Number.isInteger(a)){o.issues.push({expected:n,format:e.format,code:"invalid_type",continue:!1,input:a,inst:t});return}if(!Number.isSafeInteger(a)){a>0?o.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:n,continue:!e.abort}):o.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:n,continue:!e.abort});return}}a<i&&o.issues.push({origin:"number",input:a,code:"too_small",minimum:i,inclusive:!0,inst:t,continue:!e.abort}),a>s&&o.issues.push({origin:"number",input:a,code:"too_big",maximum:s,inst:t})}}),Qr=u("$ZodCheckMaxLength",(t,e)=>{var r;I.init(t,e),(r=t._zod.def).when??(r.when=n=>{const i=n.value;return!ge(i)&&i.length!==void 0}),t._zod.onattach.push(n=>{const i=n._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<i&&(n._zod.bag.maximum=e.maximum)}),t._zod.check=n=>{const i=n.value;if(i.length<=e.maximum)return;const o=_e(i);n.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:i,inst:t,continue:!e.abort})}}),Hr=u("$ZodCheckMinLength",(t,e)=>{var r;I.init(t,e),(r=t._zod.def).when??(r.when=n=>{const i=n.value;return!ge(i)&&i.length!==void 0}),t._zod.onattach.push(n=>{const i=n._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>i&&(n._zod.bag.minimum=e.minimum)}),t._zod.check=n=>{const i=n.value;if(i.length>=e.minimum)return;const o=_e(i);n.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:i,inst:t,continue:!e.abort})}}),en=u("$ZodCheckLengthEquals",(t,e)=>{var r;I.init(t,e),(r=t._zod.def).when??(r.when=n=>{const i=n.value;return!ge(i)&&i.length!==void 0}),t._zod.onattach.push(n=>{const i=n._zod.bag;i.minimum=e.length,i.maximum=e.length,i.length=e.length}),t._zod.check=n=>{const i=n.value,s=i.length;if(s===e.length)return;const o=_e(i),a=s>e.length;n.issues.push({origin:o,...a?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:n.value,inst:t,continue:!e.abort})}}),ie=u("$ZodCheckStringFormat",(t,e)=>{var r,n;I.init(t,e),t._zod.onattach.push(i=>{const s=i._zod.bag;s.format=e.format,e.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(e.pattern))}),e.pattern?(r=t._zod).check??(r.check=i=>{e.pattern.lastIndex=0,!e.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:e.format,input:i.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(n=t._zod).check??(n.check=()=>{})}),tn=u("$ZodCheckRegex",(t,e)=>{ie.init(t,e),t._zod.check=r=>{e.pattern.lastIndex=0,!e.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),rn=u("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=Kr),ie.init(t,e)}),nn=u("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=Yr),ie.init(t,e)}),sn=u("$ZodCheckIncludes",(t,e)=>{I.init(t,e);const r=U(e.includes),n=new RegExp(typeof e.position=="number"?`^.{${e.position}}${r}`:r);e.pattern=n,t._zod.onattach.push(i=>{const s=i._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=i=>{i.value.includes(e.includes,e.position)||i.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:i.value,inst:t,continue:!e.abort})}}),on=u("$ZodCheckStartsWith",(t,e)=>{I.init(t,e);const r=new RegExp(`^${U(e.prefix)}.*`);e.pattern??(e.pattern=r),t._zod.onattach.push(n=>{const i=n._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),t._zod.check=n=>{n.value.startsWith(e.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:n.value,inst:t,continue:!e.abort})}}),an=u("$ZodCheckEndsWith",(t,e)=>{I.init(t,e);const r=new RegExp(`.*${U(e.suffix)}$`);e.pattern??(e.pattern=r),t._zod.onattach.push(n=>{const i=n._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),t._zod.check=n=>{n.value.endsWith(e.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:n.value,inst:t,continue:!e.abort})}}),cn=u("$ZodCheckOverwrite",(t,e)=>{I.init(t,e),t._zod.check=r=>{r.value=e.tx(r.value)}});class un{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const n=e.split(`
13
+ `).filter(o=>o),i=Math.min(...n.map(o=>o.length-o.trimStart().length)),s=n.map(o=>o.slice(i)).map(o=>" ".repeat(this.indent*2)+o);for(const o of s)this.content.push(o)}compile(){const e=Function,r=this?.args,i=[...(this?.content??[""]).map(s=>` ${s}`)];return new e(...r,i.join(`
14
+ `))}}const pn={major:4,minor:2,patch:1},k=u("$ZodType",(t,e)=>{var r;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=pn;const n=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&n.unshift(t);for(const i of n)for(const s of i._zod.onattach)s(t);if(n.length===0)(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{const i=(o,a,c)=>{let p=G(o),h;for(const d of a){if(d._zod.def.when){if(!d._zod.def.when(o))continue}else if(p)continue;const f=o.issues.length,g=d._zod.check(o);if(g instanceof Promise&&c?.async===!1)throw new j;if(h||g instanceof Promise)h=(h??Promise.resolve()).then(async()=>{await g,o.issues.length!==f&&(p||(p=G(o,f)))});else{if(o.issues.length===f)continue;p||(p=G(o,f))}}return h?h.then(()=>o):o},s=(o,a,c)=>{if(G(o))return o.aborted=!0,o;const p=i(a,n,c);if(p instanceof Promise){if(c.async===!1)throw new j;return p.then(h=>t._zod.parse(h,c))}return t._zod.parse(p,c)};t._zod.run=(o,a)=>{if(a.skipChecks)return t._zod.parse(o,a);if(a.direction==="backward"){const p=t._zod.parse({value:o.value,issues:[]},{...a,skipChecks:!0});return p instanceof Promise?p.then(h=>s(h,o,a)):s(p,o,a)}const c=t._zod.parse(o,a);if(c instanceof Promise){if(a.async===!1)throw new j;return c.then(p=>i(p,n,a))}return i(c,n,a)}}t["~standard"]={validate:i=>{try{const s=mr(t,i);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return gr(t,i).then(o=>o.success?{value:o.data}:{issues:o.error?.issues})}},vendor:"zod",version:1}}),Te=u("$ZodString",(t,e)=>{k.init(t,e),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??Br(t._zod.bag),t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:t}),r}}),v=u("$ZodStringFormat",(t,e)=>{ie.init(t,e),Te.init(t,e)}),hn=u("$ZodGUID",(t,e)=>{e.pattern??(e.pattern=Ar),v.init(t,e)}),ln=u("$ZodUUID",(t,e)=>{if(e.version){const n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[e.version];if(n===void 0)throw new Error(`Invalid UUID version: "${e.version}"`);e.pattern??(e.pattern=Ve(n))}else e.pattern??(e.pattern=Ve());v.init(t,e)}),dn=u("$ZodEmail",(t,e)=>{e.pattern??(e.pattern=Zr),v.init(t,e)}),fn=u("$ZodURL",(t,e)=>{v.init(t,e),t._zod.check=r=>{try{const n=r.value.trim(),i=new URL(n);e.hostname&&(e.hostname.lastIndex=0,e.hostname.test(i.hostname)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:e.hostname.source,input:r.value,inst:t,continue:!e.abort})),e.protocol&&(e.protocol.lastIndex=0,e.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:r.value,inst:t,continue:!e.abort})),e.normalize?r.value=i.href:r.value=n;return}catch{r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:t,continue:!e.abort})}}}),mn=u("$ZodEmoji",(t,e)=>{e.pattern??(e.pattern=Rr()),v.init(t,e)}),gn=u("$ZodNanoID",(t,e)=>{e.pattern??(e.pattern=Sr),v.init(t,e)}),vn=u("$ZodCUID",(t,e)=>{e.pattern??(e.pattern=Er),v.init(t,e)}),_n=u("$ZodCUID2",(t,e)=>{e.pattern??(e.pattern=zr),v.init(t,e)}),kn=u("$ZodULID",(t,e)=>{e.pattern??(e.pattern=$r),v.init(t,e)}),yn=u("$ZodXID",(t,e)=>{e.pattern??(e.pattern=Or),v.init(t,e)}),Tn=u("$ZodKSUID",(t,e)=>{e.pattern??(e.pattern=Pr),v.init(t,e)}),bn=u("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=Vr(e)),v.init(t,e)}),wn=u("$ZodISODate",(t,e)=>{e.pattern??(e.pattern=Ur),v.init(t,e)}),In=u("$ZodISOTime",(t,e)=>{e.pattern??(e.pattern=Gr(e)),v.init(t,e)}),En=u("$ZodISODuration",(t,e)=>{e.pattern??(e.pattern=Nr),v.init(t,e)}),zn=u("$ZodIPv4",(t,e)=>{e.pattern??(e.pattern=xr),v.init(t,e),t._zod.bag.format="ipv4"}),$n=u("$ZodIPv6",(t,e)=>{e.pattern??(e.pattern=Lr),v.init(t,e),t._zod.bag.format="ipv6",t._zod.check=r=>{try{new URL(`http://[${r.value}]`)}catch{r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:t,continue:!e.abort})}}}),On=u("$ZodCIDRv4",(t,e)=>{e.pattern??(e.pattern=Dr),v.init(t,e)}),Pn=u("$ZodCIDRv6",(t,e)=>{e.pattern??(e.pattern=Fr),v.init(t,e),t._zod.check=r=>{const n=r.value.split("/");try{if(n.length!==2)throw new Error;const[i,s]=n;if(!s)throw new Error;const o=Number(s);if(`${o}`!==s)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${i}]`)}catch{r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:t,continue:!e.abort})}}});function Xe(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const Sn=u("$ZodBase64",(t,e)=>{e.pattern??(e.pattern=Mr),v.init(t,e),t._zod.bag.contentEncoding="base64",t._zod.check=r=>{Xe(r.value)||r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:t,continue:!e.abort})}});function Nn(t){if(!Be.test(t))return!1;const e=t.replace(/[-_]/g,n=>n==="-"?"+":"/"),r=e.padEnd(Math.ceil(e.length/4)*4,"=");return Xe(r)}const An=u("$ZodBase64URL",(t,e)=>{e.pattern??(e.pattern=Be),v.init(t,e),t._zod.bag.contentEncoding="base64url",t._zod.check=r=>{Nn(r.value)||r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:t,continue:!e.abort})}}),Zn=u("$ZodE164",(t,e)=>{e.pattern??(e.pattern=jr),v.init(t,e)});function Cn(t,e=null){try{const r=t.split(".");if(r.length!==3)return!1;const[n]=r;if(!n)return!1;const i=JSON.parse(atob(n));return!("typ"in i&&i?.typ!=="JWT"||!i.alg||e&&(!("alg"in i)||i.alg!==e))}catch{return!1}}const Rn=u("$ZodJWT",(t,e)=>{v.init(t,e),t._zod.check=r=>{Cn(r.value,e.alg)||r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:t,continue:!e.abort})}}),Qe=u("$ZodNumber",(t,e)=>{k.init(t,e),t._zod.pattern=t._zod.bag.pattern??Wr,t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=Number(r.value)}catch{}const i=r.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return r;const s=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return r.issues.push({expected:"number",code:"invalid_type",input:i,inst:t,...s?{received:s}:{}}),r}}),xn=u("$ZodNumberFormat",(t,e)=>{Xr.init(t,e),Qe.init(t,e)}),Ln=u("$ZodUnknown",(t,e)=>{k.init(t,e),t._zod.parse=r=>r}),Dn=u("$ZodNever",(t,e)=>{k.init(t,e),t._zod.parse=(r,n)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:t}),r)});function He(t,e,r){t.issues.length&&e.issues.push(...Me(r,t.issues)),e.value[r]=t.value}const Fn=u("$ZodArray",(t,e)=>{k.init(t,e),t._zod.parse=(r,n)=>{const i=r.value;if(!Array.isArray(i))return r.issues.push({expected:"array",code:"invalid_type",input:i,inst:t}),r;r.value=Array(i.length);const s=[];for(let o=0;o<i.length;o++){const a=i[o],c=e.element._zod.run({value:a,issues:[]},n);c instanceof Promise?s.push(c.then(p=>He(p,r,o))):He(c,r,o)}return s.length?Promise.all(s).then(()=>r):r}});function se(t,e,r,n){t.issues.length&&e.issues.push(...Me(r,t.issues)),t.value===void 0?r in n&&(e.value[r]=void 0):e.value[r]=t.value}function et(t){const e=Object.keys(t.shape);for(const n of e)if(!t.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const r=ir(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(r)}}function tt(t,e,r,n,i,s){const o=[],a=i.keySet,c=i.catchall._zod,p=c.def.type;for(const h in e){if(a.has(h))continue;if(p==="never"){o.push(h);continue}const d=c.run({value:e[h],issues:[]},n);d instanceof Promise?t.push(d.then(f=>se(f,r,h,e))):se(d,r,h,e)}return o.length&&r.issues.push({code:"unrecognized_keys",keys:o,input:e,inst:s}),t.length?Promise.all(t).then(()=>r):r}const Mn=u("$ZodObject",(t,e)=>{if(k.init(t,e),!Object.getOwnPropertyDescriptor(e,"shape")?.get){const a=e.shape;Object.defineProperty(e,"shape",{get:()=>{const c={...a};return Object.defineProperty(e,"shape",{value:c}),c}})}const n=ee(()=>et(e));m(t._zod,"propValues",()=>{const a=e.shape,c={};for(const p in a){const h=a[p]._zod;if(h.values){c[p]??(c[p]=new Set);for(const d of h.values)c[p].add(d)}}return c});const i=J,s=e.catchall;let o;t._zod.parse=(a,c)=>{o??(o=n.value);const p=a.value;if(!i(p))return a.issues.push({expected:"object",code:"invalid_type",input:p,inst:t}),a;a.value={};const h=[],d=o.shape;for(const f of o.keys){const $=d[f]._zod.run({value:p[f],issues:[]},c);$ instanceof Promise?h.push($.then($e=>se($e,a,f,p))):se($,a,f,p)}return s?tt(h,p,a,c,n.value,t):h.length?Promise.all(h).then(()=>a):a}}),jn=u("$ZodObjectJIT",(t,e)=>{Mn.init(t,e);const r=t._zod.parse,n=ee(()=>et(e)),i=f=>{const g=new un(["shape","payload","ctx"]),$=n.value,$e=S=>{const P=Le(S);return`shape[${P}]._zod.run({ value: input[${P}], issues: [] }, ctx)`};g.write("const input = payload.value;");const Ct=Object.create(null);let jo=0;for(const S of $.keys)Ct[S]=`key_${jo++}`;g.write("const newResult = {};");for(const S of $.keys){const P=Ct[S],q=Le(S);g.write(`const ${P} = ${$e(S)};`),g.write(`
15
15
  if (${P}.issues.length) {
16
16
  payload.issues = payload.issues.concat(${P}.issues.map(iss => ({
17
17
  ...iss,
@@ -28,8 +28,38 @@
28
28
  newResult[${q}] = ${P}.value;
29
29
  }
30
30
 
31
- `)}_.write("payload.value = newResult;"),_.write("return payload;");const Uo=_.compile();return(S,P)=>Uo(f,S,P)};let s;const o=J,a=!Ce.jitless,h=a&&nn.value,p=e.catchall;let d;t._zod.parse=(f,_)=>{d??(d=r.value);const $=f.value;return o($)?a&&h&&_?.async===!1&&_.jitless!==!0?(s||(s=i(e.shape)),f=s(f,_),p?tt([],$,f,_,d,t):f):n(f,_):(f.issues.push({expected:"object",code:"invalid_type",input:$,inst:t}),f)}});function nt(t,e,n,r){for(const s of t)if(s.issues.length===0)return e.value=s.value,e;const i=t.filter(s=>!G(s));return i.length===1?(e.value=i[0].value,i[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:n,errors:t.map(s=>s.issues.map(o=>D(o,r,C())))}),e)}const rt=u("$ZodUnion",(t,e)=>{k.init(t,e),m(t._zod,"optin",()=>e.options.some(i=>i._zod.optin==="optional")?"optional":void 0),m(t._zod,"optout",()=>e.options.some(i=>i._zod.optout==="optional")?"optional":void 0),m(t._zod,"values",()=>{if(e.options.every(i=>i._zod.values))return new Set(e.options.flatMap(i=>Array.from(i._zod.values)))}),m(t._zod,"pattern",()=>{if(e.options.every(i=>i._zod.pattern)){const i=e.options.map(s=>s._zod.pattern);return new RegExp(`^(${i.map(s=>ve(s.source)).join("|")})$`)}});const n=e.options.length===1,r=e.options[0]._zod.run;t._zod.parse=(i,s)=>{if(n)return r(i,s);let o=!1;const a=[];for(const c of e.options){const h=c._zod.run({value:i.value,issues:[]},s);if(h instanceof Promise)a.push(h),o=!0;else{if(h.issues.length===0)return h;a.push(h)}}return o?Promise.all(a).then(c=>nt(c,i,t,s)):nt(a,i,t,s)}}),Ur=u("$ZodDiscriminatedUnion",(t,e)=>{e.inclusive=!1,rt.init(t,e);const n=t._zod.parse;m(t._zod,"propValues",()=>{const i={};for(const s of e.options){const o=s._zod.propValues;if(!o||Object.keys(o).length===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(s)}"`);for(const[a,c]of Object.entries(o)){i[a]||(i[a]=new Set);for(const h of c)i[a].add(h)}}return i});const r=ee(()=>{const i=e.options,s=new Map;for(const o of i){const a=o._zod.propValues?.[e.discriminator];if(!a||a.size===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(o)}"`);for(const c of a){if(s.has(c))throw new Error(`Duplicate discriminator value "${String(c)}"`);s.set(c,o)}}return s});t._zod.parse=(i,s)=>{const o=i.value;if(!J(o))return i.issues.push({code:"invalid_type",expected:"object",input:o,inst:t}),i;const a=r.value.get(o?.[e.discriminator]);return a?a._zod.run(i,s):e.unionFallback?n(i,s):(i.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:e.discriminator,input:o,path:[e.discriminator],inst:t}),i)}}),Gr=u("$ZodIntersection",(t,e)=>{k.init(t,e),t._zod.parse=(n,r)=>{const i=n.value,s=e.left._zod.run({value:i,issues:[]},r),o=e.right._zod.run({value:i,issues:[]},r);return s instanceof Promise||o instanceof Promise?Promise.all([s,o]).then(([c,h])=>it(n,c,h)):it(n,s,o)}});function we(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(W(t)&&W(e)){const n=Object.keys(e),r=Object.keys(t).filter(s=>n.indexOf(s)!==-1),i={...t,...e};for(const s of r){const o=we(t[s],e[s]);if(!o.valid)return{valid:!1,mergeErrorPath:[s,...o.mergeErrorPath]};i[s]=o.data}return{valid:!0,data:i}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<t.length;r++){const i=t[r],s=e[r],o=we(i,s);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function it(t,e,n){if(e.issues.length&&t.issues.push(...e.issues),n.issues.length&&t.issues.push(...n.issues),G(t))return t;const r=we(e.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return t.value=r.data,t}const Vr=u("$ZodEnum",(t,e)=>{k.init(t,e);const n=Re(e.entries),r=new Set(n);t._zod.values=r,t._zod.pattern=new RegExp(`^(${n.filter(i=>rn.has(typeof i)).map(i=>typeof i=="string"?U(i):i.toString()).join("|")})$`),t._zod.parse=(i,s)=>{const o=i.value;return r.has(o)||i.issues.push({code:"invalid_value",values:n,input:o,inst:t}),i}}),Br=u("$ZodLiteral",(t,e)=>{if(k.init(t,e),e.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(e.values);t._zod.values=n,t._zod.pattern=new RegExp(`^(${e.values.map(r=>typeof r=="string"?U(r):r?U(r.toString()):String(r)).join("|")})$`),t._zod.parse=(r,i)=>{const s=r.value;return n.has(s)||r.issues.push({code:"invalid_value",values:e.values,input:s,inst:t}),r}}),Jr=u("$ZodTransform",(t,e)=>{k.init(t,e),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Ze(t.constructor.name);const i=e.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(o=>(n.value=o,n));if(i instanceof Promise)throw new M;return n.value=i,n}});function st(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const Wr=u("$ZodOptional",(t,e)=>{k.init(t,e),t._zod.optin="optional",t._zod.optout="optional",m(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),m(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${ve(n.source)})?$`):void 0}),t._zod.parse=(n,r)=>{if(e.innerType._zod.optin==="optional"){const i=e.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>st(s,n.value)):st(i,n.value)}return n.value===void 0?n:e.innerType._zod.run(n,r)}}),Kr=u("$ZodNullable",(t,e)=>{k.init(t,e),m(t._zod,"optin",()=>e.innerType._zod.optin),m(t._zod,"optout",()=>e.innerType._zod.optout),m(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${ve(n.source)}|null)$`):void 0}),m(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(n,r)=>n.value===null?n:e.innerType._zod.run(n,r)}),Yr=u("$ZodDefault",(t,e)=>{k.init(t,e),t._zod.optin="optional",m(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);if(n.value===void 0)return n.value=e.defaultValue,n;const i=e.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>ot(s,e)):ot(i,e)}});function ot(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const qr=u("$ZodPrefault",(t,e)=>{k.init(t,e),t._zod.optin="optional",m(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=e.defaultValue),e.innerType._zod.run(n,r))}),Xr=u("$ZodNonOptional",(t,e)=>{k.init(t,e),m(t._zod,"values",()=>{const n=e.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),t._zod.parse=(n,r)=>{const i=e.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>at(s,t)):at(i,t)}});function at(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const Qr=u("$ZodCatch",(t,e)=>{k.init(t,e),m(t._zod,"optin",()=>e.innerType._zod.optin),m(t._zod,"optout",()=>e.innerType._zod.optout),m(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const i=e.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>(n.value=s.value,s.issues.length&&(n.value=e.catchValue({...n,error:{issues:s.issues.map(o=>D(o,r,C()))},input:n.value}),n.issues=[]),n)):(n.value=i.value,i.issues.length&&(n.value=e.catchValue({...n,error:{issues:i.issues.map(s=>D(s,r,C()))},input:n.value}),n.issues=[]),n)}}),Hr=u("$ZodPipe",(t,e)=>{k.init(t,e),m(t._zod,"values",()=>e.in._zod.values),m(t._zod,"optin",()=>e.in._zod.optin),m(t._zod,"optout",()=>e.out._zod.optout),m(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=e.out._zod.run(n,r);return s instanceof Promise?s.then(o=>oe(o,e.in,r)):oe(s,e.in,r)}const i=e.in._zod.run(n,r);return i instanceof Promise?i.then(s=>oe(s,e.out,r)):oe(i,e.out,r)}});function oe(t,e,n){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},n)}const ei=u("$ZodReadonly",(t,e)=>{k.init(t,e),m(t._zod,"propValues",()=>e.innerType._zod.propValues),m(t._zod,"values",()=>e.innerType._zod.values),m(t._zod,"optin",()=>e.innerType?._zod?.optin),m(t._zod,"optout",()=>e.innerType?._zod?.optout),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const i=e.innerType._zod.run(n,r);return i instanceof Promise?i.then(ct):ct(i)}});function ct(t){return t.value=Object.freeze(t.value),t}const ti=u("$ZodCustom",(t,e)=>{E.init(t,e),k.init(t,e),t._zod.parse=(n,r)=>n,t._zod.check=n=>{const r=n.value,i=e.fn(r);if(i instanceof Promise)return i.then(s=>ut(s,n,r,t));ut(i,n,r,t)}});function ut(t,e,n,r){if(!t){const i={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(i.params=r._zod.def.params),e.issues.push(K(i))}}var ht;class ni{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...n){const r=n[0];if(this._map.set(e,r),r&&typeof r=="object"&&"id"in r){if(this._idmap.has(r.id))throw new Error(`ID ${r.id} already exists in the registry`);this._idmap.set(r.id,e)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const n=this._map.get(e);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(e),this}get(e){const n=e._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const i={...r,...this._map.get(e)};return Object.keys(i).length?i:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function ri(){return new ni}(ht=globalThis).__zod_globalRegistry??(ht.__zod_globalRegistry=ri());const Y=globalThis.__zod_globalRegistry;function ii(t,e){return new t({type:"string",...l(e)})}function si(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...l(e)})}function pt(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...l(e)})}function oi(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...l(e)})}function ai(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...l(e)})}function ci(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...l(e)})}function ui(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...l(e)})}function hi(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...l(e)})}function pi(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...l(e)})}function li(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...l(e)})}function di(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...l(e)})}function fi(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...l(e)})}function mi(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...l(e)})}function gi(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...l(e)})}function vi(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...l(e)})}function _i(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...l(e)})}function ki(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...l(e)})}function yi(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...l(e)})}function Ti(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...l(e)})}function wi(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...l(e)})}function bi(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...l(e)})}function Ei(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...l(e)})}function Ii(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...l(e)})}function zi(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...l(e)})}function $i(t,e){return new t({type:"string",format:"date",check:"string_format",...l(e)})}function Oi(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...l(e)})}function Pi(t,e){return new t({type:"string",format:"duration",check:"string_format",...l(e)})}function Si(t,e){return new t({type:"number",checks:[],...l(e)})}function Ni(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...l(e)})}function Ai(t){return new t({type:"unknown"})}function Zi(t,e){return new t({type:"never",...l(e)})}function lt(t,e){return new Ye({check:"less_than",...l(e),value:t,inclusive:!1})}function be(t,e){return new Ye({check:"less_than",...l(e),value:t,inclusive:!0})}function dt(t,e){return new qe({check:"greater_than",...l(e),value:t,inclusive:!1})}function Ee(t,e){return new qe({check:"greater_than",...l(e),value:t,inclusive:!0})}function ft(t,e){return new Xn({check:"multiple_of",...l(e),value:t})}function mt(t,e){return new Hn({check:"max_length",...l(e),maximum:t})}function ae(t,e){return new er({check:"min_length",...l(e),minimum:t})}function gt(t,e){return new tr({check:"length_equals",...l(e),length:t})}function Ci(t,e){return new nr({check:"string_format",format:"regex",...l(e),pattern:t})}function Ri(t){return new rr({check:"string_format",format:"lowercase",...l(t)})}function Li(t){return new ir({check:"string_format",format:"uppercase",...l(t)})}function Di(t,e){return new sr({check:"string_format",format:"includes",...l(e),includes:t})}function xi(t,e){return new or({check:"string_format",format:"starts_with",...l(e),prefix:t})}function Fi(t,e){return new ar({check:"string_format",format:"ends_with",...l(e),suffix:t})}function V(t){return new cr({check:"overwrite",tx:t})}function ji(t){return V(e=>e.normalize(t))}function Mi(){return V(t=>t.trim())}function Ui(){return V(t=>t.toLowerCase())}function Gi(){return V(t=>t.toUpperCase())}function Vi(){return V(t=>tn(t))}function Bi(t,e,n){return new t({type:"array",element:e,...l(n)})}function Ji(t,e,n){return new t({type:"custom",check:"custom",fn:e,...l(n)})}function Wi(t){const e=Ki(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(K(r,n.value,e._zod.def));else{const i=r;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=e),i.continue??(i.continue=!e._zod.def.abort),n.issues.push(K(i))}},t(n.value,n)));return e}function Ki(t,e){const n=new E({check:"custom",...l(e)});return n._zod.check=t,n}function vt(t){let e=t?.target??"draft-2020-12";return e==="draft-4"&&(e="draft-04"),e==="draft-7"&&(e="draft-07"),{processors:t.processors??{},metadataRegistry:t?.metadata??Y,target:e,unrepresentable:t?.unrepresentable??"throw",override:t?.override??(()=>{}),io:t?.io??"output",counter:0,seen:new Map,cycles:t?.cycles??"ref",reused:t?.reused??"inline",external:t?.external??void 0}}function w(t,e,n={path:[],schemaPath:[]}){var r;const i=t._zod.def,s=e.seen.get(t);if(s)return s.count++,n.schemaPath.includes(t)&&(s.cycle=n.path),s.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};e.seen.set(t,o);const a=t._zod.toJSONSchema?.();if(a)o.schema=a;else{const p={...n,schemaPath:[...n.schemaPath,t],path:n.path},d=t._zod.parent;if(d)o.ref=d,w(d,e,p),e.seen.get(d).isParent=!0;else if(t._zod.processJSONSchema)t._zod.processJSONSchema(e,o.schema,p);else{const f=o.schema,_=e.processors[i.type];if(!_)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);_(t,e,f,p)}}const c=e.metadataRegistry.get(t);return c&&Object.assign(o.schema,c),e.io==="input"&&b(t)&&(delete o.schema.examples,delete o.schema.default),e.io==="input"&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,e.seen.get(t).schema}function _t(t,e){const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=s=>{const o=t.target==="draft-2020-12"?"$defs":"definitions";if(t.external){const p=t.external.registry.get(s[0])?.id,d=t.external.uri??(_=>_);if(p)return{ref:d(p)};const f=s[1].defId??s[1].schema.id??`schema${t.counter++}`;return s[1].defId=f,{defId:f,ref:`${d("__shared")}#/${o}/${f}`}}if(s[1]===n)return{ref:"#"};const c=`#/${o}/`,h=s[1].schema.id??`__schema${t.counter++}`;return{defId:h,ref:c+h}},i=s=>{if(s[1].schema.$ref)return;const o=s[1],{ref:a,defId:c}=r(s);o.def={...o.schema},c&&(o.defId=c);const h=o.schema;for(const p in h)delete h[p];h.$ref=a};if(t.cycles==="throw")for(const s of t.seen.entries()){const o=s[1];if(o.cycle)throw new Error(`Cycle detected: #/${o.cycle?.join("/")}/<root>
31
+ `)}g.write("payload.value = newResult;"),g.write("return payload;");const Uo=g.compile();return(S,P)=>Uo(f,S,P)};let s;const o=J,a=!Ce.jitless,p=a&&rr.value,h=e.catchall;let d;t._zod.parse=(f,g)=>{d??(d=n.value);const $=f.value;return o($)?a&&p&&g?.async===!1&&g.jitless!==!0?(s||(s=i(e.shape)),f=s(f,g),h?tt([],$,f,g,d,t):f):r(f,g):(f.issues.push({expected:"object",code:"invalid_type",input:$,inst:t}),f)}});function rt(t,e,r,n){for(const s of t)if(s.issues.length===0)return e.value=s.value,e;const i=t.filter(s=>!G(s));return i.length===1?(e.value=i[0].value,i[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:r,errors:t.map(s=>s.issues.map(o=>L(o,n,C())))}),e)}const nt=u("$ZodUnion",(t,e)=>{k.init(t,e),m(t._zod,"optin",()=>e.options.some(i=>i._zod.optin==="optional")?"optional":void 0),m(t._zod,"optout",()=>e.options.some(i=>i._zod.optout==="optional")?"optional":void 0),m(t._zod,"values",()=>{if(e.options.every(i=>i._zod.values))return new Set(e.options.flatMap(i=>Array.from(i._zod.values)))}),m(t._zod,"pattern",()=>{if(e.options.every(i=>i._zod.pattern)){const i=e.options.map(s=>s._zod.pattern);return new RegExp(`^(${i.map(s=>ve(s.source)).join("|")})$`)}});const r=e.options.length===1,n=e.options[0]._zod.run;t._zod.parse=(i,s)=>{if(r)return n(i,s);let o=!1;const a=[];for(const c of e.options){const p=c._zod.run({value:i.value,issues:[]},s);if(p instanceof Promise)a.push(p),o=!0;else{if(p.issues.length===0)return p;a.push(p)}}return o?Promise.all(a).then(c=>rt(c,i,t,s)):rt(a,i,t,s)}}),Un=u("$ZodDiscriminatedUnion",(t,e)=>{e.inclusive=!1,nt.init(t,e);const r=t._zod.parse;m(t._zod,"propValues",()=>{const i={};for(const s of e.options){const o=s._zod.propValues;if(!o||Object.keys(o).length===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(s)}"`);for(const[a,c]of Object.entries(o)){i[a]||(i[a]=new Set);for(const p of c)i[a].add(p)}}return i});const n=ee(()=>{const i=e.options,s=new Map;for(const o of i){const a=o._zod.propValues?.[e.discriminator];if(!a||a.size===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(o)}"`);for(const c of a){if(s.has(c))throw new Error(`Duplicate discriminator value "${String(c)}"`);s.set(c,o)}}return s});t._zod.parse=(i,s)=>{const o=i.value;if(!J(o))return i.issues.push({code:"invalid_type",expected:"object",input:o,inst:t}),i;const a=n.value.get(o?.[e.discriminator]);return a?a._zod.run(i,s):e.unionFallback?r(i,s):(i.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:e.discriminator,input:o,path:[e.discriminator],inst:t}),i)}}),Gn=u("$ZodIntersection",(t,e)=>{k.init(t,e),t._zod.parse=(r,n)=>{const i=r.value,s=e.left._zod.run({value:i,issues:[]},n),o=e.right._zod.run({value:i,issues:[]},n);return s instanceof Promise||o instanceof Promise?Promise.all([s,o]).then(([c,p])=>it(r,c,p)):it(r,s,o)}});function be(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(W(t)&&W(e)){const r=Object.keys(e),n=Object.keys(t).filter(s=>r.indexOf(s)!==-1),i={...t,...e};for(const s of n){const o=be(t[s],e[s]);if(!o.valid)return{valid:!1,mergeErrorPath:[s,...o.mergeErrorPath]};i[s]=o.data}return{valid:!0,data:i}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const r=[];for(let n=0;n<t.length;n++){const i=t[n],s=e[n],o=be(i,s);if(!o.valid)return{valid:!1,mergeErrorPath:[n,...o.mergeErrorPath]};r.push(o.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function it(t,e,r){if(e.issues.length&&t.issues.push(...e.issues),r.issues.length&&t.issues.push(...r.issues),G(t))return t;const n=be(e.value,r.value);if(!n.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(n.mergeErrorPath)}`);return t.value=n.data,t}const Vn=u("$ZodEnum",(t,e)=>{k.init(t,e);const r=Re(e.entries),n=new Set(r);t._zod.values=n,t._zod.pattern=new RegExp(`^(${r.filter(i=>nr.has(typeof i)).map(i=>typeof i=="string"?U(i):i.toString()).join("|")})$`),t._zod.parse=(i,s)=>{const o=i.value;return n.has(o)||i.issues.push({code:"invalid_value",values:r,input:o,inst:t}),i}}),Bn=u("$ZodLiteral",(t,e)=>{if(k.init(t,e),e.values.length===0)throw new Error("Cannot create literal schema with no valid values");const r=new Set(e.values);t._zod.values=r,t._zod.pattern=new RegExp(`^(${e.values.map(n=>typeof n=="string"?U(n):n?U(n.toString()):String(n)).join("|")})$`),t._zod.parse=(n,i)=>{const s=n.value;return r.has(s)||n.issues.push({code:"invalid_value",values:e.values,input:s,inst:t}),n}}),Jn=u("$ZodTransform",(t,e)=>{k.init(t,e),t._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Ze(t.constructor.name);const i=e.transform(r.value,r);if(n.async)return(i instanceof Promise?i:Promise.resolve(i)).then(o=>(r.value=o,r));if(i instanceof Promise)throw new j;return r.value=i,r}});function st(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const Wn=u("$ZodOptional",(t,e)=>{k.init(t,e),t._zod.optin="optional",t._zod.optout="optional",m(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),m(t._zod,"pattern",()=>{const r=e.innerType._zod.pattern;return r?new RegExp(`^(${ve(r.source)})?$`):void 0}),t._zod.parse=(r,n)=>{if(e.innerType._zod.optin==="optional"){const i=e.innerType._zod.run(r,n);return i instanceof Promise?i.then(s=>st(s,r.value)):st(i,r.value)}return r.value===void 0?r:e.innerType._zod.run(r,n)}}),Kn=u("$ZodNullable",(t,e)=>{k.init(t,e),m(t._zod,"optin",()=>e.innerType._zod.optin),m(t._zod,"optout",()=>e.innerType._zod.optout),m(t._zod,"pattern",()=>{const r=e.innerType._zod.pattern;return r?new RegExp(`^(${ve(r.source)}|null)$`):void 0}),m(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(r,n)=>r.value===null?r:e.innerType._zod.run(r,n)}),Yn=u("$ZodDefault",(t,e)=>{k.init(t,e),t._zod.optin="optional",m(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);if(r.value===void 0)return r.value=e.defaultValue,r;const i=e.innerType._zod.run(r,n);return i instanceof Promise?i.then(s=>ot(s,e)):ot(i,e)}});function ot(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const qn=u("$ZodPrefault",(t,e)=>{k.init(t,e),t._zod.optin="optional",m(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>(n.direction==="backward"||r.value===void 0&&(r.value=e.defaultValue),e.innerType._zod.run(r,n))}),Xn=u("$ZodNonOptional",(t,e)=>{k.init(t,e),m(t._zod,"values",()=>{const r=e.innerType._zod.values;return r?new Set([...r].filter(n=>n!==void 0)):void 0}),t._zod.parse=(r,n)=>{const i=e.innerType._zod.run(r,n);return i instanceof Promise?i.then(s=>at(s,t)):at(i,t)}});function at(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const Qn=u("$ZodCatch",(t,e)=>{k.init(t,e),m(t._zod,"optin",()=>e.innerType._zod.optin),m(t._zod,"optout",()=>e.innerType._zod.optout),m(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);const i=e.innerType._zod.run(r,n);return i instanceof Promise?i.then(s=>(r.value=s.value,s.issues.length&&(r.value=e.catchValue({...r,error:{issues:s.issues.map(o=>L(o,n,C()))},input:r.value}),r.issues=[]),r)):(r.value=i.value,i.issues.length&&(r.value=e.catchValue({...r,error:{issues:i.issues.map(s=>L(s,n,C()))},input:r.value}),r.issues=[]),r)}}),Hn=u("$ZodPipe",(t,e)=>{k.init(t,e),m(t._zod,"values",()=>e.in._zod.values),m(t._zod,"optin",()=>e.in._zod.optin),m(t._zod,"optout",()=>e.out._zod.optout),m(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(r,n)=>{if(n.direction==="backward"){const s=e.out._zod.run(r,n);return s instanceof Promise?s.then(o=>oe(o,e.in,n)):oe(s,e.in,n)}const i=e.in._zod.run(r,n);return i instanceof Promise?i.then(s=>oe(s,e.out,n)):oe(i,e.out,n)}});function oe(t,e,r){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},r)}const ei=u("$ZodReadonly",(t,e)=>{k.init(t,e),m(t._zod,"propValues",()=>e.innerType._zod.propValues),m(t._zod,"values",()=>e.innerType._zod.values),m(t._zod,"optin",()=>e.innerType?._zod?.optin),m(t._zod,"optout",()=>e.innerType?._zod?.optout),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);const i=e.innerType._zod.run(r,n);return i instanceof Promise?i.then(ct):ct(i)}});function ct(t){return t.value=Object.freeze(t.value),t}const ti=u("$ZodCustom",(t,e)=>{I.init(t,e),k.init(t,e),t._zod.parse=(r,n)=>r,t._zod.check=r=>{const n=r.value,i=e.fn(n);if(i instanceof Promise)return i.then(s=>ut(s,r,n,t));ut(i,r,n,t)}});function ut(t,e,r,n){if(!t){const i={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};n._zod.def.params&&(i.params=n._zod.def.params),e.issues.push(K(i))}}var pt;class ri{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...r){const n=r[0];if(this._map.set(e,n),n&&typeof n=="object"&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const r=this._map.get(e);return r&&typeof r=="object"&&"id"in r&&this._idmap.delete(r.id),this._map.delete(e),this}get(e){const r=e._zod.parent;if(r){const n={...this.get(r)??{}};delete n.id;const i={...n,...this._map.get(e)};return Object.keys(i).length?i:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function ni(){return new ri}(pt=globalThis).__zod_globalRegistry??(pt.__zod_globalRegistry=ni());const Y=globalThis.__zod_globalRegistry;function ii(t,e){return new t({type:"string",...l(e)})}function si(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...l(e)})}function ht(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...l(e)})}function oi(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...l(e)})}function ai(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...l(e)})}function ci(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...l(e)})}function ui(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...l(e)})}function pi(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...l(e)})}function hi(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...l(e)})}function li(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...l(e)})}function di(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...l(e)})}function fi(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...l(e)})}function mi(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...l(e)})}function gi(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...l(e)})}function vi(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...l(e)})}function _i(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...l(e)})}function ki(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...l(e)})}function yi(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...l(e)})}function Ti(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...l(e)})}function bi(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...l(e)})}function wi(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...l(e)})}function Ii(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...l(e)})}function Ei(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...l(e)})}function zi(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...l(e)})}function $i(t,e){return new t({type:"string",format:"date",check:"string_format",...l(e)})}function Oi(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...l(e)})}function Pi(t,e){return new t({type:"string",format:"duration",check:"string_format",...l(e)})}function Si(t,e){return new t({type:"number",checks:[],...l(e)})}function Ni(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...l(e)})}function Ai(t){return new t({type:"unknown"})}function Zi(t,e){return new t({type:"never",...l(e)})}function lt(t,e){return new Ye({check:"less_than",...l(e),value:t,inclusive:!1})}function we(t,e){return new Ye({check:"less_than",...l(e),value:t,inclusive:!0})}function dt(t,e){return new qe({check:"greater_than",...l(e),value:t,inclusive:!1})}function Ie(t,e){return new qe({check:"greater_than",...l(e),value:t,inclusive:!0})}function ft(t,e){return new qr({check:"multiple_of",...l(e),value:t})}function mt(t,e){return new Qr({check:"max_length",...l(e),maximum:t})}function ae(t,e){return new Hr({check:"min_length",...l(e),minimum:t})}function gt(t,e){return new en({check:"length_equals",...l(e),length:t})}function Ci(t,e){return new tn({check:"string_format",format:"regex",...l(e),pattern:t})}function Ri(t){return new rn({check:"string_format",format:"lowercase",...l(t)})}function xi(t){return new nn({check:"string_format",format:"uppercase",...l(t)})}function Li(t,e){return new sn({check:"string_format",format:"includes",...l(e),includes:t})}function Di(t,e){return new on({check:"string_format",format:"starts_with",...l(e),prefix:t})}function Fi(t,e){return new an({check:"string_format",format:"ends_with",...l(e),suffix:t})}function V(t){return new cn({check:"overwrite",tx:t})}function Mi(t){return V(e=>e.normalize(t))}function ji(){return V(t=>t.trim())}function Ui(){return V(t=>t.toLowerCase())}function Gi(){return V(t=>t.toUpperCase())}function Vi(){return V(t=>tr(t))}function Bi(t,e,r){return new t({type:"array",element:e,...l(r)})}function Ji(t,e,r){return new t({type:"custom",check:"custom",fn:e,...l(r)})}function Wi(t){const e=Ki(r=>(r.addIssue=n=>{if(typeof n=="string")r.issues.push(K(n,r.value,e._zod.def));else{const i=n;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=r.value),i.inst??(i.inst=e),i.continue??(i.continue=!e._zod.def.abort),r.issues.push(K(i))}},t(r.value,r)));return e}function Ki(t,e){const r=new I({check:"custom",...l(e)});return r._zod.check=t,r}function vt(t){let e=t?.target??"draft-2020-12";return e==="draft-4"&&(e="draft-04"),e==="draft-7"&&(e="draft-07"),{processors:t.processors??{},metadataRegistry:t?.metadata??Y,target:e,unrepresentable:t?.unrepresentable??"throw",override:t?.override??(()=>{}),io:t?.io??"output",counter:0,seen:new Map,cycles:t?.cycles??"ref",reused:t?.reused??"inline",external:t?.external??void 0}}function b(t,e,r={path:[],schemaPath:[]}){var n;const i=t._zod.def,s=e.seen.get(t);if(s)return s.count++,r.schemaPath.includes(t)&&(s.cycle=r.path),s.schema;const o={schema:{},count:1,cycle:void 0,path:r.path};e.seen.set(t,o);const a=t._zod.toJSONSchema?.();if(a)o.schema=a;else{const h={...r,schemaPath:[...r.schemaPath,t],path:r.path},d=t._zod.parent;if(d)o.ref=d,b(d,e,h),e.seen.get(d).isParent=!0;else if(t._zod.processJSONSchema)t._zod.processJSONSchema(e,o.schema,h);else{const f=o.schema,g=e.processors[i.type];if(!g)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);g(t,e,f,h)}}const c=e.metadataRegistry.get(t);return c&&Object.assign(o.schema,c),e.io==="input"&&w(t)&&(delete o.schema.examples,delete o.schema.default),e.io==="input"&&o.schema._prefault&&((n=o.schema).default??(n.default=o.schema._prefault)),delete o.schema._prefault,e.seen.get(t).schema}function _t(t,e){const r=t.seen.get(e);if(!r)throw new Error("Unprocessed schema. This is a bug in Zod.");const n=s=>{const o=t.target==="draft-2020-12"?"$defs":"definitions";if(t.external){const h=t.external.registry.get(s[0])?.id,d=t.external.uri??(g=>g);if(h)return{ref:d(h)};const f=s[1].defId??s[1].schema.id??`schema${t.counter++}`;return s[1].defId=f,{defId:f,ref:`${d("__shared")}#/${o}/${f}`}}if(s[1]===r)return{ref:"#"};const c=`#/${o}/`,p=s[1].schema.id??`__schema${t.counter++}`;return{defId:p,ref:c+p}},i=s=>{if(s[1].schema.$ref)return;const o=s[1],{ref:a,defId:c}=n(s);o.def={...o.schema},c&&(o.defId=c);const p=o.schema;for(const h in p)delete p[h];p.$ref=a};if(t.cycles==="throw")for(const s of t.seen.entries()){const o=s[1];if(o.cycle)throw new Error(`Cycle detected: #/${o.cycle?.join("/")}/<root>
32
32
 
33
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const s of t.seen.entries()){const o=s[1];if(e===s[0]){i(s);continue}if(t.external){const c=t.external.registry.get(s[0])?.id;if(e!==s[0]&&c){i(s);continue}}if(t.metadataRegistry.get(s[0])?.id){i(s);continue}if(o.cycle){i(s);continue}if(o.count>1&&t.reused==="ref"){i(s);continue}}}function kt(t,e){const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=o=>{const a=t.seen.get(o),c=a.def??a.schema,h={...c};if(a.ref===null)return;const p=a.ref;if(a.ref=null,p){r(p);const d=t.seen.get(p).schema;d.$ref&&(t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0")?(c.allOf=c.allOf??[],c.allOf.push(d)):(Object.assign(c,d),Object.assign(c,h))}a.isParent||t.override({zodSchema:o,jsonSchema:c,path:a.path??[]})};for(const o of[...t.seen.entries()].reverse())r(o[0]);const i={};if(t.target==="draft-2020-12"?i.$schema="https://json-schema.org/draft/2020-12/schema":t.target==="draft-07"?i.$schema="http://json-schema.org/draft-07/schema#":t.target==="draft-04"?i.$schema="http://json-schema.org/draft-04/schema#":t.target,t.external?.uri){const o=t.external.registry.get(e)?.id;if(!o)throw new Error("Schema is missing an `id` property");i.$id=t.external.uri(o)}Object.assign(i,n.def??n.schema);const s=t.external?.defs??{};for(const o of t.seen.entries()){const a=o[1];a.def&&a.defId&&(s[a.defId]=a.def)}t.external||Object.keys(s).length>0&&(t.target==="draft-2020-12"?i.$defs=s:i.definitions=s);try{const o=JSON.parse(JSON.stringify(i));return Object.defineProperty(o,"~standard",{value:{...e["~standard"],jsonSchema:{input:ce(e,"input"),output:ce(e,"output")}},enumerable:!1,writable:!1}),o}catch{throw new Error("Error converting schema to JSON.")}}function b(t,e){const n=e??{seen:new Set};if(n.seen.has(t))return!1;n.seen.add(t);const r=t._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return b(r.element,n);if(r.type==="set")return b(r.valueType,n);if(r.type==="lazy")return b(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return b(r.innerType,n);if(r.type==="intersection")return b(r.left,n)||b(r.right,n);if(r.type==="record"||r.type==="map")return b(r.keyType,n)||b(r.valueType,n);if(r.type==="pipe")return b(r.in,n)||b(r.out,n);if(r.type==="object"){for(const i in r.shape)if(b(r.shape[i],n))return!0;return!1}if(r.type==="union"){for(const i of r.options)if(b(i,n))return!0;return!1}if(r.type==="tuple"){for(const i of r.items)if(b(i,n))return!0;return!!(r.rest&&b(r.rest,n))}return!1}const Yi=(t,e={})=>n=>{const r=vt({...n,processors:e});return w(t,r),_t(r,t),kt(r,t)},ce=(t,e)=>n=>{const{libraryOptions:r,target:i}=n??{},s=vt({...r??{},target:i,io:e,processors:{}});return w(t,s),_t(s,t),kt(s,t)},qi={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Xi=(t,e,n,r)=>{const i=n;i.type="string";const{minimum:s,maximum:o,format:a,patterns:c,contentEncoding:h}=t._zod.bag;if(typeof s=="number"&&(i.minLength=s),typeof o=="number"&&(i.maxLength=o),a&&(i.format=qi[a]??a,i.format===""&&delete i.format),h&&(i.contentEncoding=h),c&&c.size>0){const p=[...c];p.length===1?i.pattern=p[0].source:p.length>1&&(i.allOf=[...p.map(d=>({...e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"?{type:"string"}:{},pattern:d.source}))])}},Qi=(t,e,n,r)=>{const i=n,{minimum:s,maximum:o,format:a,multipleOf:c,exclusiveMaximum:h,exclusiveMinimum:p}=t._zod.bag;typeof a=="string"&&a.includes("int")?i.type="integer":i.type="number",typeof p=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(i.minimum=p,i.exclusiveMinimum=!0):i.exclusiveMinimum=p),typeof s=="number"&&(i.minimum=s,typeof p=="number"&&e.target!=="draft-04"&&(p>=s?delete i.minimum:delete i.exclusiveMinimum)),typeof h=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(i.maximum=h,i.exclusiveMaximum=!0):i.exclusiveMaximum=h),typeof o=="number"&&(i.maximum=o,typeof h=="number"&&e.target!=="draft-04"&&(h<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c=="number"&&(i.multipleOf=c)},Hi=(t,e,n,r)=>{n.not={}},es=(t,e,n,r)=>{},ts=(t,e,n,r)=>{const i=t._zod.def,s=Re(i.entries);s.every(o=>typeof o=="number")&&(n.type="number"),s.every(o=>typeof o=="string")&&(n.type="string"),n.enum=s},ns=(t,e,n,r)=>{const i=t._zod.def,s=[];for(const o of i.values)if(o===void 0){if(e.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(e.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");s.push(Number(o))}else s.push(o);if(s.length!==0)if(s.length===1){const o=s[0];n.type=o===null?"null":typeof o,e.target==="draft-04"||e.target==="openapi-3.0"?n.enum=[o]:n.const=o}else s.every(o=>typeof o=="number")&&(n.type="number"),s.every(o=>typeof o=="string")&&(n.type="string"),s.every(o=>typeof o=="boolean")&&(n.type="boolean"),s.every(o=>o===null)&&(n.type="null"),n.enum=s},rs=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},is=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},ss=(t,e,n,r)=>{const i=n,s=t._zod.def,{minimum:o,maximum:a}=t._zod.bag;typeof o=="number"&&(i.minItems=o),typeof a=="number"&&(i.maxItems=a),i.type="array",i.items=w(s.element,e,{...r,path:[...r.path,"items"]})},os=(t,e,n,r)=>{const i=n,s=t._zod.def;i.type="object",i.properties={};const o=s.shape;for(const h in o)i.properties[h]=w(o[h],e,{...r,path:[...r.path,"properties",h]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(h=>{const p=s.shape[h]._zod;return e.io==="input"?p.optin===void 0:p.optout===void 0}));c.size>0&&(i.required=Array.from(c)),s.catchall?._zod.def.type==="never"?i.additionalProperties=!1:s.catchall?s.catchall&&(i.additionalProperties=w(s.catchall,e,{...r,path:[...r.path,"additionalProperties"]})):e.io==="output"&&(i.additionalProperties=!1)},as=(t,e,n,r)=>{const i=t._zod.def,s=i.inclusive===!1,o=i.options.map((a,c)=>w(a,e,{...r,path:[...r.path,s?"oneOf":"anyOf",c]}));s?n.oneOf=o:n.anyOf=o},cs=(t,e,n,r)=>{const i=t._zod.def,s=w(i.left,e,{...r,path:[...r.path,"allOf",0]}),o=w(i.right,e,{...r,path:[...r.path,"allOf",1]}),a=h=>"allOf"in h&&Object.keys(h).length===1,c=[...a(s)?s.allOf:[s],...a(o)?o.allOf:[o]];n.allOf=c},us=(t,e,n,r)=>{const i=t._zod.def,s=w(i.innerType,e,r),o=e.seen.get(t);e.target==="openapi-3.0"?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]},hs=(t,e,n,r)=>{const i=t._zod.def;w(i.innerType,e,r);const s=e.seen.get(t);s.ref=i.innerType},ps=(t,e,n,r)=>{const i=t._zod.def;w(i.innerType,e,r);const s=e.seen.get(t);s.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},ls=(t,e,n,r)=>{const i=t._zod.def;w(i.innerType,e,r);const s=e.seen.get(t);s.ref=i.innerType,e.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},ds=(t,e,n,r)=>{const i=t._zod.def;w(i.innerType,e,r);const s=e.seen.get(t);s.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},fs=(t,e,n,r)=>{const i=t._zod.def,s=e.io==="input"?i.in._zod.def.type==="transform"?i.out:i.in:i.out;w(s,e,r);const o=e.seen.get(t);o.ref=s},ms=(t,e,n,r)=>{const i=t._zod.def;w(i.innerType,e,r);const s=e.seen.get(t);s.ref=i.innerType,n.readOnly=!0},gs=(t,e,n,r)=>{const i=t._zod.def;w(i.innerType,e,r);const s=e.seen.get(t);s.ref=i.innerType},vs=u("ZodISODateTime",(t,e)=>{wr.init(t,e),v.init(t,e)});function _s(t){return zi(vs,t)}const ks=u("ZodISODate",(t,e)=>{br.init(t,e),v.init(t,e)});function ys(t){return $i(ks,t)}const Ts=u("ZodISOTime",(t,e)=>{Er.init(t,e),v.init(t,e)});function ws(t){return Oi(Ts,t)}const bs=u("ZodISODuration",(t,e)=>{Ir.init(t,e),v.init(t,e)});function Es(t){return Pi(bs,t)}const O=u("ZodError",(t,e)=>{Ue.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:n=>mn(t,n)},flatten:{value:n=>fn(t,n)},addIssue:{value:n=>{t.issues.push(n),t.message=JSON.stringify(t.issues,me,2)}},addIssues:{value:n=>{t.issues.push(...n),t.message=JSON.stringify(t.issues,me,2)}},isEmpty:{get(){return t.issues.length===0}}})},{Parent:Error}),Is=ke(O),zs=ye(O),$s=ne(O),Os=re(O),Ps=_n(O),Ss=kn(O),Ns=yn(O),As=Tn(O),Zs=wn(O),Cs=bn(O),Rs=En(O),Ls=In(O),y=u("ZodType",(t,e)=>(k.init(t,e),Object.assign(t["~standard"],{jsonSchema:{input:ce(t,"input"),output:ce(t,"output")}}),t.toJSONSchema=Yi(t,{}),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...n)=>t.clone(L(e,{checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]})),t.clone=(n,r)=>N(t,n,r),t.brand=()=>t,t.register=((n,r)=>(n.add(t,r),t)),t.parse=(n,r)=>Is(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>$s(t,n,r),t.parseAsync=async(n,r)=>zs(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>Os(t,n,r),t.spa=t.safeParseAsync,t.encode=(n,r)=>Ps(t,n,r),t.decode=(n,r)=>Ss(t,n,r),t.encodeAsync=async(n,r)=>Ns(t,n,r),t.decodeAsync=async(n,r)=>As(t,n,r),t.safeEncode=(n,r)=>Zs(t,n,r),t.safeDecode=(n,r)=>Cs(t,n,r),t.safeEncodeAsync=async(n,r)=>Rs(t,n,r),t.safeDecodeAsync=async(n,r)=>Ls(t,n,r),t.refine=(n,r)=>t.check(Oo(n,r)),t.superRefine=n=>t.check(Po(n)),t.overwrite=n=>t.check(V(n)),t.optional=()=>Ot(t),t.nullable=()=>Pt(t),t.nullish=()=>Ot(Pt(t)),t.nonoptional=n=>To(t,n),t.array=()=>x(t),t.or=n=>he([t,n]),t.and=n=>po(t,n),t.transform=n=>Nt(t,mo(n)),t.default=n=>_o(t,n),t.prefault=n=>yo(t,n),t.catch=n=>bo(t,n),t.pipe=n=>Nt(t,n),t.readonly=()=>zo(t),t.describe=n=>{const r=t.clone();return Y.add(r,{description:n}),r},Object.defineProperty(t,"description",{get(){return Y.get(t)?.description},configurable:!0}),t.meta=(...n)=>{if(n.length===0)return Y.get(t);const r=t.clone();return Y.add(r,n[0]),r},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t)),yt=u("_ZodString",(t,e)=>{Te.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,i,s)=>Xi(t,r,i);const n=t._zod.bag;t.format=n.format??null,t.minLength=n.minimum??null,t.maxLength=n.maximum??null,t.regex=(...r)=>t.check(Ci(...r)),t.includes=(...r)=>t.check(Di(...r)),t.startsWith=(...r)=>t.check(xi(...r)),t.endsWith=(...r)=>t.check(Fi(...r)),t.min=(...r)=>t.check(ae(...r)),t.max=(...r)=>t.check(mt(...r)),t.length=(...r)=>t.check(gt(...r)),t.nonempty=(...r)=>t.check(ae(1,...r)),t.lowercase=r=>t.check(Ri(r)),t.uppercase=r=>t.check(Li(r)),t.trim=()=>t.check(Mi()),t.normalize=(...r)=>t.check(ji(...r)),t.toLowerCase=()=>t.check(Ui()),t.toUpperCase=()=>t.check(Gi()),t.slugify=()=>t.check(Vi())}),Ds=u("ZodString",(t,e)=>{Te.init(t,e),yt.init(t,e),t.email=n=>t.check(si(xs,n)),t.url=n=>t.check(hi(Fs,n)),t.jwt=n=>t.check(Ii(eo,n)),t.emoji=n=>t.check(pi(js,n)),t.guid=n=>t.check(pt(Tt,n)),t.uuid=n=>t.check(oi(ue,n)),t.uuidv4=n=>t.check(ai(ue,n)),t.uuidv6=n=>t.check(ci(ue,n)),t.uuidv7=n=>t.check(ui(ue,n)),t.nanoid=n=>t.check(li(Ms,n)),t.guid=n=>t.check(pt(Tt,n)),t.cuid=n=>t.check(di(Us,n)),t.cuid2=n=>t.check(fi(Gs,n)),t.ulid=n=>t.check(mi(Vs,n)),t.base64=n=>t.check(wi(Xs,n)),t.base64url=n=>t.check(bi(Qs,n)),t.xid=n=>t.check(gi(Bs,n)),t.ksuid=n=>t.check(vi(Js,n)),t.ipv4=n=>t.check(_i(Ws,n)),t.ipv6=n=>t.check(ki(Ks,n)),t.cidrv4=n=>t.check(yi(Ys,n)),t.cidrv6=n=>t.check(Ti(qs,n)),t.e164=n=>t.check(Ei(Hs,n)),t.datetime=n=>t.check(_s(n)),t.date=n=>t.check(ys(n)),t.time=n=>t.check(ws(n)),t.duration=n=>t.check(Es(n))});function I(t){return ii(Ds,t)}const v=u("ZodStringFormat",(t,e)=>{g.init(t,e),yt.init(t,e)}),xs=u("ZodEmail",(t,e)=>{dr.init(t,e),v.init(t,e)}),Tt=u("ZodGUID",(t,e)=>{pr.init(t,e),v.init(t,e)}),ue=u("ZodUUID",(t,e)=>{lr.init(t,e),v.init(t,e)}),Fs=u("ZodURL",(t,e)=>{fr.init(t,e),v.init(t,e)}),js=u("ZodEmoji",(t,e)=>{mr.init(t,e),v.init(t,e)}),Ms=u("ZodNanoID",(t,e)=>{gr.init(t,e),v.init(t,e)}),Us=u("ZodCUID",(t,e)=>{vr.init(t,e),v.init(t,e)}),Gs=u("ZodCUID2",(t,e)=>{_r.init(t,e),v.init(t,e)}),Vs=u("ZodULID",(t,e)=>{kr.init(t,e),v.init(t,e)}),Bs=u("ZodXID",(t,e)=>{yr.init(t,e),v.init(t,e)}),Js=u("ZodKSUID",(t,e)=>{Tr.init(t,e),v.init(t,e)}),Ws=u("ZodIPv4",(t,e)=>{zr.init(t,e),v.init(t,e)}),Ks=u("ZodIPv6",(t,e)=>{$r.init(t,e),v.init(t,e)}),Ys=u("ZodCIDRv4",(t,e)=>{Or.init(t,e),v.init(t,e)}),qs=u("ZodCIDRv6",(t,e)=>{Pr.init(t,e),v.init(t,e)}),Xs=u("ZodBase64",(t,e)=>{Sr.init(t,e),v.init(t,e)}),Qs=u("ZodBase64URL",(t,e)=>{Ar.init(t,e),v.init(t,e)}),Hs=u("ZodE164",(t,e)=>{Zr.init(t,e),v.init(t,e)}),eo=u("ZodJWT",(t,e)=>{Rr.init(t,e),v.init(t,e)}),wt=u("ZodNumber",(t,e)=>{Qe.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,i,s)=>Qi(t,r,i),t.gt=(r,i)=>t.check(dt(r,i)),t.gte=(r,i)=>t.check(Ee(r,i)),t.min=(r,i)=>t.check(Ee(r,i)),t.lt=(r,i)=>t.check(lt(r,i)),t.lte=(r,i)=>t.check(be(r,i)),t.max=(r,i)=>t.check(be(r,i)),t.int=r=>t.check(bt(r)),t.safe=r=>t.check(bt(r)),t.positive=r=>t.check(dt(0,r)),t.nonnegative=r=>t.check(Ee(0,r)),t.negative=r=>t.check(lt(0,r)),t.nonpositive=r=>t.check(be(0,r)),t.multipleOf=(r,i)=>t.check(ft(r,i)),t.step=(r,i)=>t.check(ft(r,i)),t.finite=()=>t;const n=t._zod.bag;t.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),t.isFinite=!0,t.format=n.format??null});function to(t){return Si(wt,t)}const no=u("ZodNumberFormat",(t,e)=>{Lr.init(t,e),wt.init(t,e)});function bt(t){return Ni(no,t)}const ro=u("ZodUnknown",(t,e)=>{Dr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>es()});function Et(){return Ai(ro)}const io=u("ZodNever",(t,e)=>{xr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>Hi(t,n,r)});function so(t){return Zi(io,t)}const oo=u("ZodArray",(t,e)=>{Fr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>ss(t,n,r,i),t.element=e.element,t.min=(n,r)=>t.check(ae(n,r)),t.nonempty=n=>t.check(ae(1,n)),t.max=(n,r)=>t.check(mt(n,r)),t.length=(n,r)=>t.check(gt(n,r)),t.unwrap=()=>t.element});function x(t,e){return Bi(oo,t,e)}const ao=u("ZodObject",(t,e)=>{Mr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>os(t,n,r,i),m(t,"shape",()=>e.shape),t.keyof=()=>zt(Object.keys(t._zod.def.shape)),t.catchall=n=>t.clone({...t._zod.def,catchall:n}),t.passthrough=()=>t.clone({...t._zod.def,catchall:Et()}),t.loose=()=>t.clone({...t._zod.def,catchall:Et()}),t.strict=()=>t.clone({...t._zod.def,catchall:so()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=n=>un(t,n),t.safeExtend=n=>hn(t,n),t.merge=n=>pn(t,n),t.pick=n=>an(t,n),t.omit=n=>cn(t,n),t.partial=(...n)=>ln($t,t,n[0]),t.required=(...n)=>dn(St,t,n[0])});function z(t,e){const n={type:"object",shape:t??{},...l(e)};return new ao(n)}const It=u("ZodUnion",(t,e)=>{rt.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>as(t,n,r,i),t.options=e.options});function he(t,e){return new It({type:"union",options:t,...l(e)})}const co=u("ZodDiscriminatedUnion",(t,e)=>{It.init(t,e),Ur.init(t,e)});function uo(t,e,n){return new co({type:"union",options:e,discriminator:t,...l(n)})}const ho=u("ZodIntersection",(t,e)=>{Gr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>cs(t,n,r,i)});function po(t,e){return new ho({type:"intersection",left:t,right:e})}const Ie=u("ZodEnum",(t,e)=>{Vr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,i,s)=>ts(t,r,i),t.enum=e.entries,t.options=Object.values(e.entries);const n=new Set(Object.keys(e.entries));t.extract=(r,i)=>{const s={};for(const o of r)if(n.has(o))s[o]=e.entries[o];else throw new Error(`Key ${o} not found in enum`);return new Ie({...e,checks:[],...l(i),entries:s})},t.exclude=(r,i)=>{const s={...e.entries};for(const o of r)if(n.has(o))delete s[o];else throw new Error(`Key ${o} not found in enum`);return new Ie({...e,checks:[],...l(i),entries:s})}});function zt(t,e){const n=Array.isArray(t)?Object.fromEntries(t.map(r=>[r,r])):t;return new Ie({type:"enum",entries:n,...l(e)})}const lo=u("ZodLiteral",(t,e)=>{Br.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>ns(t,n,r),t.values=new Set(e.values),Object.defineProperty(t,"value",{get(){if(e.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return e.values[0]}})});function A(t,e){return new lo({type:"literal",values:Array.isArray(t)?t:[t],...l(e)})}const fo=u("ZodTransform",(t,e)=>{Jr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>is(t,n),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Ze(t.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(K(s,n.value,e));else{const o=s;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),n.issues.push(K(o))}};const i=e.transform(n.value,n);return i instanceof Promise?i.then(s=>(n.value=s,n)):(n.value=i,n)}});function mo(t){return new fo({type:"transform",transform:t})}const $t=u("ZodOptional",(t,e)=>{Wr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>gs(t,n,r,i),t.unwrap=()=>t._zod.def.innerType});function Ot(t){return new $t({type:"optional",innerType:t})}const go=u("ZodNullable",(t,e)=>{Kr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>us(t,n,r,i),t.unwrap=()=>t._zod.def.innerType});function Pt(t){return new go({type:"nullable",innerType:t})}const vo=u("ZodDefault",(t,e)=>{Yr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>ps(t,n,r,i),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function _o(t,e){return new vo({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():Fe(e)}})}const ko=u("ZodPrefault",(t,e)=>{qr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>ls(t,n,r,i),t.unwrap=()=>t._zod.def.innerType});function yo(t,e){return new ko({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():Fe(e)}})}const St=u("ZodNonOptional",(t,e)=>{Xr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>hs(t,n,r,i),t.unwrap=()=>t._zod.def.innerType});function To(t,e){return new St({type:"nonoptional",innerType:t,...l(e)})}const wo=u("ZodCatch",(t,e)=>{Qr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>ds(t,n,r,i),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function bo(t,e){return new wo({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const Eo=u("ZodPipe",(t,e)=>{Hr.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>fs(t,n,r,i),t.in=e.in,t.out=e.out});function Nt(t,e){return new Eo({type:"pipe",in:t,out:e})}const Io=u("ZodReadonly",(t,e)=>{ei.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>ms(t,n,r,i),t.unwrap=()=>t._zod.def.innerType});function zo(t){return new Io({type:"readonly",innerType:t})}const $o=u("ZodCustom",(t,e)=>{ti.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,r,i)=>rs(t,n)});function Oo(t,e={}){return Ji($o,t,e)}function Po(t){return Wi(t)}const Z=he([I(),z({pattern:I(),flags:I().optional()})]),So=z({kind:A("fragment"),condition:Z.optional(),operator:he([I(),x(I())]).optional()}),ze=z({kind:A("participant"),name:Z.optional(),id:Z.optional(),stereotype:Z.optional()}),No=z({kind:A("message"),text:Z.optional(),from:Z.optional(),to:Z.optional()}),Ao=z({kind:A("group"),name:Z.optional()}),Zo=z({action:A("resolve"),selector:So}),Co=z({action:A("focus"),selector:ze}),Ro=z({action:A("remove"),selector:he([ze,No,Ao])}),Lo=z({action:A("merge"),into:z({name:I().optional(),id:I().optional(),stereotype:I().optional()}).optional(),selector:ze}),Do=uo("action",[Zo,Co,Ro,Lo]),xo=z({name:I(),suffix:I().optional(),layers:x(Do)}),At=zt(["mermaid","plantuml"]),Fo=z({input:x(I()),outputDir:I(),ignore:x(I()).optional(),lenses:x(xo),format:At.optional(),outputFormat:At.optional()}),Zt=z({version:to(),targets:x(Fo)});function jo(t){const e=Zt.safeParse(t);if(!e.success){const n=e.error.issues.map(r=>`[${r.path.join(".")}]: ${r.message}`).join(`
33
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const s of t.seen.entries()){const o=s[1];if(e===s[0]){i(s);continue}if(t.external){const c=t.external.registry.get(s[0])?.id;if(e!==s[0]&&c){i(s);continue}}if(t.metadataRegistry.get(s[0])?.id){i(s);continue}if(o.cycle){i(s);continue}if(o.count>1&&t.reused==="ref"){i(s);continue}}}function kt(t,e){const r=t.seen.get(e);if(!r)throw new Error("Unprocessed schema. This is a bug in Zod.");const n=o=>{const a=t.seen.get(o),c=a.def??a.schema,p={...c};if(a.ref===null)return;const h=a.ref;if(a.ref=null,h){n(h);const d=t.seen.get(h).schema;d.$ref&&(t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0")?(c.allOf=c.allOf??[],c.allOf.push(d)):(Object.assign(c,d),Object.assign(c,p))}a.isParent||t.override({zodSchema:o,jsonSchema:c,path:a.path??[]})};for(const o of[...t.seen.entries()].reverse())n(o[0]);const i={};if(t.target==="draft-2020-12"?i.$schema="https://json-schema.org/draft/2020-12/schema":t.target==="draft-07"?i.$schema="http://json-schema.org/draft-07/schema#":t.target==="draft-04"?i.$schema="http://json-schema.org/draft-04/schema#":t.target,t.external?.uri){const o=t.external.registry.get(e)?.id;if(!o)throw new Error("Schema is missing an `id` property");i.$id=t.external.uri(o)}Object.assign(i,r.def??r.schema);const s=t.external?.defs??{};for(const o of t.seen.entries()){const a=o[1];a.def&&a.defId&&(s[a.defId]=a.def)}t.external||Object.keys(s).length>0&&(t.target==="draft-2020-12"?i.$defs=s:i.definitions=s);try{const o=JSON.parse(JSON.stringify(i));return Object.defineProperty(o,"~standard",{value:{...e["~standard"],jsonSchema:{input:ce(e,"input"),output:ce(e,"output")}},enumerable:!1,writable:!1}),o}catch{throw new Error("Error converting schema to JSON.")}}function w(t,e){const r=e??{seen:new Set};if(r.seen.has(t))return!1;r.seen.add(t);const n=t._zod.def;if(n.type==="transform")return!0;if(n.type==="array")return w(n.element,r);if(n.type==="set")return w(n.valueType,r);if(n.type==="lazy")return w(n.getter(),r);if(n.type==="promise"||n.type==="optional"||n.type==="nonoptional"||n.type==="nullable"||n.type==="readonly"||n.type==="default"||n.type==="prefault")return w(n.innerType,r);if(n.type==="intersection")return w(n.left,r)||w(n.right,r);if(n.type==="record"||n.type==="map")return w(n.keyType,r)||w(n.valueType,r);if(n.type==="pipe")return w(n.in,r)||w(n.out,r);if(n.type==="object"){for(const i in n.shape)if(w(n.shape[i],r))return!0;return!1}if(n.type==="union"){for(const i of n.options)if(w(i,r))return!0;return!1}if(n.type==="tuple"){for(const i of n.items)if(w(i,r))return!0;return!!(n.rest&&w(n.rest,r))}return!1}const Yi=(t,e={})=>r=>{const n=vt({...r,processors:e});return b(t,n),_t(n,t),kt(n,t)},ce=(t,e)=>r=>{const{libraryOptions:n,target:i}=r??{},s=vt({...n??{},target:i,io:e,processors:{}});return b(t,s),_t(s,t),kt(s,t)},qi={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Xi=(t,e,r,n)=>{const i=r;i.type="string";const{minimum:s,maximum:o,format:a,patterns:c,contentEncoding:p}=t._zod.bag;if(typeof s=="number"&&(i.minLength=s),typeof o=="number"&&(i.maxLength=o),a&&(i.format=qi[a]??a,i.format===""&&delete i.format),p&&(i.contentEncoding=p),c&&c.size>0){const h=[...c];h.length===1?i.pattern=h[0].source:h.length>1&&(i.allOf=[...h.map(d=>({...e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"?{type:"string"}:{},pattern:d.source}))])}},Qi=(t,e,r,n)=>{const i=r,{minimum:s,maximum:o,format:a,multipleOf:c,exclusiveMaximum:p,exclusiveMinimum:h}=t._zod.bag;typeof a=="string"&&a.includes("int")?i.type="integer":i.type="number",typeof h=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(i.minimum=h,i.exclusiveMinimum=!0):i.exclusiveMinimum=h),typeof s=="number"&&(i.minimum=s,typeof h=="number"&&e.target!=="draft-04"&&(h>=s?delete i.minimum:delete i.exclusiveMinimum)),typeof p=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(i.maximum=p,i.exclusiveMaximum=!0):i.exclusiveMaximum=p),typeof o=="number"&&(i.maximum=o,typeof p=="number"&&e.target!=="draft-04"&&(p<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c=="number"&&(i.multipleOf=c)},Hi=(t,e,r,n)=>{r.not={}},es=(t,e,r,n)=>{},ts=(t,e,r,n)=>{const i=t._zod.def,s=Re(i.entries);s.every(o=>typeof o=="number")&&(r.type="number"),s.every(o=>typeof o=="string")&&(r.type="string"),r.enum=s},rs=(t,e,r,n)=>{const i=t._zod.def,s=[];for(const o of i.values)if(o===void 0){if(e.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(e.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");s.push(Number(o))}else s.push(o);if(s.length!==0)if(s.length===1){const o=s[0];r.type=o===null?"null":typeof o,e.target==="draft-04"||e.target==="openapi-3.0"?r.enum=[o]:r.const=o}else s.every(o=>typeof o=="number")&&(r.type="number"),s.every(o=>typeof o=="string")&&(r.type="string"),s.every(o=>typeof o=="boolean")&&(r.type="boolean"),s.every(o=>o===null)&&(r.type="null"),r.enum=s},ns=(t,e,r,n)=>{if(e.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},is=(t,e,r,n)=>{if(e.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},ss=(t,e,r,n)=>{const i=r,s=t._zod.def,{minimum:o,maximum:a}=t._zod.bag;typeof o=="number"&&(i.minItems=o),typeof a=="number"&&(i.maxItems=a),i.type="array",i.items=b(s.element,e,{...n,path:[...n.path,"items"]})},os=(t,e,r,n)=>{const i=r,s=t._zod.def;i.type="object",i.properties={};const o=s.shape;for(const p in o)i.properties[p]=b(o[p],e,{...n,path:[...n.path,"properties",p]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(p=>{const h=s.shape[p]._zod;return e.io==="input"?h.optin===void 0:h.optout===void 0}));c.size>0&&(i.required=Array.from(c)),s.catchall?._zod.def.type==="never"?i.additionalProperties=!1:s.catchall?s.catchall&&(i.additionalProperties=b(s.catchall,e,{...n,path:[...n.path,"additionalProperties"]})):e.io==="output"&&(i.additionalProperties=!1)},as=(t,e,r,n)=>{const i=t._zod.def,s=i.inclusive===!1,o=i.options.map((a,c)=>b(a,e,{...n,path:[...n.path,s?"oneOf":"anyOf",c]}));s?r.oneOf=o:r.anyOf=o},cs=(t,e,r,n)=>{const i=t._zod.def,s=b(i.left,e,{...n,path:[...n.path,"allOf",0]}),o=b(i.right,e,{...n,path:[...n.path,"allOf",1]}),a=p=>"allOf"in p&&Object.keys(p).length===1,c=[...a(s)?s.allOf:[s],...a(o)?o.allOf:[o]];r.allOf=c},us=(t,e,r,n)=>{const i=t._zod.def,s=b(i.innerType,e,n),o=e.seen.get(t);e.target==="openapi-3.0"?(o.ref=i.innerType,r.nullable=!0):r.anyOf=[s,{type:"null"}]},ps=(t,e,r,n)=>{const i=t._zod.def;b(i.innerType,e,n);const s=e.seen.get(t);s.ref=i.innerType},hs=(t,e,r,n)=>{const i=t._zod.def;b(i.innerType,e,n);const s=e.seen.get(t);s.ref=i.innerType,r.default=JSON.parse(JSON.stringify(i.defaultValue))},ls=(t,e,r,n)=>{const i=t._zod.def;b(i.innerType,e,n);const s=e.seen.get(t);s.ref=i.innerType,e.io==="input"&&(r._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},ds=(t,e,r,n)=>{const i=t._zod.def;b(i.innerType,e,n);const s=e.seen.get(t);s.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}r.default=o},fs=(t,e,r,n)=>{const i=t._zod.def,s=e.io==="input"?i.in._zod.def.type==="transform"?i.out:i.in:i.out;b(s,e,n);const o=e.seen.get(t);o.ref=s},ms=(t,e,r,n)=>{const i=t._zod.def;b(i.innerType,e,n);const s=e.seen.get(t);s.ref=i.innerType,r.readOnly=!0},gs=(t,e,r,n)=>{const i=t._zod.def;b(i.innerType,e,n);const s=e.seen.get(t);s.ref=i.innerType},vs=u("ZodISODateTime",(t,e)=>{bn.init(t,e),_.init(t,e)});function _s(t){return zi(vs,t)}const ks=u("ZodISODate",(t,e)=>{wn.init(t,e),_.init(t,e)});function ys(t){return $i(ks,t)}const Ts=u("ZodISOTime",(t,e)=>{In.init(t,e),_.init(t,e)});function bs(t){return Oi(Ts,t)}const ws=u("ZodISODuration",(t,e)=>{En.init(t,e),_.init(t,e)});function Is(t){return Pi(ws,t)}const O=u("ZodError",(t,e)=>{Ue.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:r=>fr(t,r)},flatten:{value:r=>dr(t,r)},addIssue:{value:r=>{t.issues.push(r),t.message=JSON.stringify(t.issues,me,2)}},addIssues:{value:r=>{t.issues.push(...r),t.message=JSON.stringify(t.issues,me,2)}},isEmpty:{get(){return t.issues.length===0}}})},{Parent:Error}),Es=ke(O),zs=ye(O),$s=re(O),Os=ne(O),Ps=vr(O),Ss=_r(O),Ns=kr(O),As=yr(O),Zs=Tr(O),Cs=br(O),Rs=wr(O),xs=Ir(O),y=u("ZodType",(t,e)=>(k.init(t,e),Object.assign(t["~standard"],{jsonSchema:{input:ce(t,"input"),output:ce(t,"output")}}),t.toJSONSchema=Yi(t,{}),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...r)=>t.clone(x(e,{checks:[...e.checks??[],...r.map(n=>typeof n=="function"?{_zod:{check:n,def:{check:"custom"},onattach:[]}}:n)]})),t.clone=(r,n)=>N(t,r,n),t.brand=()=>t,t.register=((r,n)=>(r.add(t,n),t)),t.parse=(r,n)=>Es(t,r,n,{callee:t.parse}),t.safeParse=(r,n)=>$s(t,r,n),t.parseAsync=async(r,n)=>zs(t,r,n,{callee:t.parseAsync}),t.safeParseAsync=async(r,n)=>Os(t,r,n),t.spa=t.safeParseAsync,t.encode=(r,n)=>Ps(t,r,n),t.decode=(r,n)=>Ss(t,r,n),t.encodeAsync=async(r,n)=>Ns(t,r,n),t.decodeAsync=async(r,n)=>As(t,r,n),t.safeEncode=(r,n)=>Zs(t,r,n),t.safeDecode=(r,n)=>Cs(t,r,n),t.safeEncodeAsync=async(r,n)=>Rs(t,r,n),t.safeDecodeAsync=async(r,n)=>xs(t,r,n),t.refine=(r,n)=>t.check(Oo(r,n)),t.superRefine=r=>t.check(Po(r)),t.overwrite=r=>t.check(V(r)),t.optional=()=>Ot(t),t.nullable=()=>Pt(t),t.nullish=()=>Ot(Pt(t)),t.nonoptional=r=>To(t,r),t.array=()=>D(t),t.or=r=>pe([t,r]),t.and=r=>ho(t,r),t.transform=r=>Nt(t,mo(r)),t.default=r=>_o(t,r),t.prefault=r=>yo(t,r),t.catch=r=>wo(t,r),t.pipe=r=>Nt(t,r),t.readonly=()=>zo(t),t.describe=r=>{const n=t.clone();return Y.add(n,{description:r}),n},Object.defineProperty(t,"description",{get(){return Y.get(t)?.description},configurable:!0}),t.meta=(...r)=>{if(r.length===0)return Y.get(t);const n=t.clone();return Y.add(n,r[0]),n},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t)),yt=u("_ZodString",(t,e)=>{Te.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,i,s)=>Xi(t,n,i);const r=t._zod.bag;t.format=r.format??null,t.minLength=r.minimum??null,t.maxLength=r.maximum??null,t.regex=(...n)=>t.check(Ci(...n)),t.includes=(...n)=>t.check(Li(...n)),t.startsWith=(...n)=>t.check(Di(...n)),t.endsWith=(...n)=>t.check(Fi(...n)),t.min=(...n)=>t.check(ae(...n)),t.max=(...n)=>t.check(mt(...n)),t.length=(...n)=>t.check(gt(...n)),t.nonempty=(...n)=>t.check(ae(1,...n)),t.lowercase=n=>t.check(Ri(n)),t.uppercase=n=>t.check(xi(n)),t.trim=()=>t.check(ji()),t.normalize=(...n)=>t.check(Mi(...n)),t.toLowerCase=()=>t.check(Ui()),t.toUpperCase=()=>t.check(Gi()),t.slugify=()=>t.check(Vi())}),Ls=u("ZodString",(t,e)=>{Te.init(t,e),yt.init(t,e),t.email=r=>t.check(si(Ds,r)),t.url=r=>t.check(pi(Fs,r)),t.jwt=r=>t.check(Ei(eo,r)),t.emoji=r=>t.check(hi(Ms,r)),t.guid=r=>t.check(ht(Tt,r)),t.uuid=r=>t.check(oi(ue,r)),t.uuidv4=r=>t.check(ai(ue,r)),t.uuidv6=r=>t.check(ci(ue,r)),t.uuidv7=r=>t.check(ui(ue,r)),t.nanoid=r=>t.check(li(js,r)),t.guid=r=>t.check(ht(Tt,r)),t.cuid=r=>t.check(di(Us,r)),t.cuid2=r=>t.check(fi(Gs,r)),t.ulid=r=>t.check(mi(Vs,r)),t.base64=r=>t.check(bi(Xs,r)),t.base64url=r=>t.check(wi(Qs,r)),t.xid=r=>t.check(gi(Bs,r)),t.ksuid=r=>t.check(vi(Js,r)),t.ipv4=r=>t.check(_i(Ws,r)),t.ipv6=r=>t.check(ki(Ks,r)),t.cidrv4=r=>t.check(yi(Ys,r)),t.cidrv6=r=>t.check(Ti(qs,r)),t.e164=r=>t.check(Ii(Hs,r)),t.datetime=r=>t.check(_s(r)),t.date=r=>t.check(ys(r)),t.time=r=>t.check(bs(r)),t.duration=r=>t.check(Is(r))});function E(t){return ii(Ls,t)}const _=u("ZodStringFormat",(t,e)=>{v.init(t,e),yt.init(t,e)}),Ds=u("ZodEmail",(t,e)=>{dn.init(t,e),_.init(t,e)}),Tt=u("ZodGUID",(t,e)=>{hn.init(t,e),_.init(t,e)}),ue=u("ZodUUID",(t,e)=>{ln.init(t,e),_.init(t,e)}),Fs=u("ZodURL",(t,e)=>{fn.init(t,e),_.init(t,e)}),Ms=u("ZodEmoji",(t,e)=>{mn.init(t,e),_.init(t,e)}),js=u("ZodNanoID",(t,e)=>{gn.init(t,e),_.init(t,e)}),Us=u("ZodCUID",(t,e)=>{vn.init(t,e),_.init(t,e)}),Gs=u("ZodCUID2",(t,e)=>{_n.init(t,e),_.init(t,e)}),Vs=u("ZodULID",(t,e)=>{kn.init(t,e),_.init(t,e)}),Bs=u("ZodXID",(t,e)=>{yn.init(t,e),_.init(t,e)}),Js=u("ZodKSUID",(t,e)=>{Tn.init(t,e),_.init(t,e)}),Ws=u("ZodIPv4",(t,e)=>{zn.init(t,e),_.init(t,e)}),Ks=u("ZodIPv6",(t,e)=>{$n.init(t,e),_.init(t,e)}),Ys=u("ZodCIDRv4",(t,e)=>{On.init(t,e),_.init(t,e)}),qs=u("ZodCIDRv6",(t,e)=>{Pn.init(t,e),_.init(t,e)}),Xs=u("ZodBase64",(t,e)=>{Sn.init(t,e),_.init(t,e)}),Qs=u("ZodBase64URL",(t,e)=>{An.init(t,e),_.init(t,e)}),Hs=u("ZodE164",(t,e)=>{Zn.init(t,e),_.init(t,e)}),eo=u("ZodJWT",(t,e)=>{Rn.init(t,e),_.init(t,e)}),bt=u("ZodNumber",(t,e)=>{Qe.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,i,s)=>Qi(t,n,i),t.gt=(n,i)=>t.check(dt(n,i)),t.gte=(n,i)=>t.check(Ie(n,i)),t.min=(n,i)=>t.check(Ie(n,i)),t.lt=(n,i)=>t.check(lt(n,i)),t.lte=(n,i)=>t.check(we(n,i)),t.max=(n,i)=>t.check(we(n,i)),t.int=n=>t.check(wt(n)),t.safe=n=>t.check(wt(n)),t.positive=n=>t.check(dt(0,n)),t.nonnegative=n=>t.check(Ie(0,n)),t.negative=n=>t.check(lt(0,n)),t.nonpositive=n=>t.check(we(0,n)),t.multipleOf=(n,i)=>t.check(ft(n,i)),t.step=(n,i)=>t.check(ft(n,i)),t.finite=()=>t;const r=t._zod.bag;t.minValue=Math.max(r.minimum??Number.NEGATIVE_INFINITY,r.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(r.maximum??Number.POSITIVE_INFINITY,r.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(r.format??"").includes("int")||Number.isSafeInteger(r.multipleOf??.5),t.isFinite=!0,t.format=r.format??null});function to(t){return Si(bt,t)}const ro=u("ZodNumberFormat",(t,e)=>{xn.init(t,e),bt.init(t,e)});function wt(t){return Ni(ro,t)}const no=u("ZodUnknown",(t,e)=>{Ln.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>es()});function It(){return Ai(no)}const io=u("ZodNever",(t,e)=>{Dn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>Hi(t,r,n)});function so(t){return Zi(io,t)}const oo=u("ZodArray",(t,e)=>{Fn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>ss(t,r,n,i),t.element=e.element,t.min=(r,n)=>t.check(ae(r,n)),t.nonempty=r=>t.check(ae(1,r)),t.max=(r,n)=>t.check(mt(r,n)),t.length=(r,n)=>t.check(gt(r,n)),t.unwrap=()=>t.element});function D(t,e){return Bi(oo,t,e)}const ao=u("ZodObject",(t,e)=>{jn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>os(t,r,n,i),m(t,"shape",()=>e.shape),t.keyof=()=>zt(Object.keys(t._zod.def.shape)),t.catchall=r=>t.clone({...t._zod.def,catchall:r}),t.passthrough=()=>t.clone({...t._zod.def,catchall:It()}),t.loose=()=>t.clone({...t._zod.def,catchall:It()}),t.strict=()=>t.clone({...t._zod.def,catchall:so()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=r=>cr(t,r),t.safeExtend=r=>ur(t,r),t.merge=r=>pr(t,r),t.pick=r=>or(t,r),t.omit=r=>ar(t,r),t.partial=(...r)=>hr($t,t,r[0]),t.required=(...r)=>lr(St,t,r[0])});function z(t,e){const r={type:"object",shape:t??{},...l(e)};return new ao(r)}const Et=u("ZodUnion",(t,e)=>{nt.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>as(t,r,n,i),t.options=e.options});function pe(t,e){return new Et({type:"union",options:t,...l(e)})}const co=u("ZodDiscriminatedUnion",(t,e)=>{Et.init(t,e),Un.init(t,e)});function uo(t,e,r){return new co({type:"union",options:e,discriminator:t,...l(r)})}const po=u("ZodIntersection",(t,e)=>{Gn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>cs(t,r,n,i)});function ho(t,e){return new po({type:"intersection",left:t,right:e})}const Ee=u("ZodEnum",(t,e)=>{Vn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(n,i,s)=>ts(t,n,i),t.enum=e.entries,t.options=Object.values(e.entries);const r=new Set(Object.keys(e.entries));t.extract=(n,i)=>{const s={};for(const o of n)if(r.has(o))s[o]=e.entries[o];else throw new Error(`Key ${o} not found in enum`);return new Ee({...e,checks:[],...l(i),entries:s})},t.exclude=(n,i)=>{const s={...e.entries};for(const o of n)if(r.has(o))delete s[o];else throw new Error(`Key ${o} not found in enum`);return new Ee({...e,checks:[],...l(i),entries:s})}});function zt(t,e){const r=Array.isArray(t)?Object.fromEntries(t.map(n=>[n,n])):t;return new Ee({type:"enum",entries:r,...l(e)})}const lo=u("ZodLiteral",(t,e)=>{Bn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>rs(t,r,n),t.values=new Set(e.values),Object.defineProperty(t,"value",{get(){if(e.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return e.values[0]}})});function A(t,e){return new lo({type:"literal",values:Array.isArray(t)?t:[t],...l(e)})}const fo=u("ZodTransform",(t,e)=>{Jn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>is(t,r),t._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Ze(t.constructor.name);r.addIssue=s=>{if(typeof s=="string")r.issues.push(K(s,r.value,e));else{const o=s;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=r.value),o.inst??(o.inst=t),r.issues.push(K(o))}};const i=e.transform(r.value,r);return i instanceof Promise?i.then(s=>(r.value=s,r)):(r.value=i,r)}});function mo(t){return new fo({type:"transform",transform:t})}const $t=u("ZodOptional",(t,e)=>{Wn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>gs(t,r,n,i),t.unwrap=()=>t._zod.def.innerType});function Ot(t){return new $t({type:"optional",innerType:t})}const go=u("ZodNullable",(t,e)=>{Kn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>us(t,r,n,i),t.unwrap=()=>t._zod.def.innerType});function Pt(t){return new go({type:"nullable",innerType:t})}const vo=u("ZodDefault",(t,e)=>{Yn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>hs(t,r,n,i),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function _o(t,e){return new vo({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():Fe(e)}})}const ko=u("ZodPrefault",(t,e)=>{qn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>ls(t,r,n,i),t.unwrap=()=>t._zod.def.innerType});function yo(t,e){return new ko({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():Fe(e)}})}const St=u("ZodNonOptional",(t,e)=>{Xn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>ps(t,r,n,i),t.unwrap=()=>t._zod.def.innerType});function To(t,e){return new St({type:"nonoptional",innerType:t,...l(e)})}const bo=u("ZodCatch",(t,e)=>{Qn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>ds(t,r,n,i),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function wo(t,e){return new bo({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const Io=u("ZodPipe",(t,e)=>{Hn.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>fs(t,r,n,i),t.in=e.in,t.out=e.out});function Nt(t,e){return new Io({type:"pipe",in:t,out:e})}const Eo=u("ZodReadonly",(t,e)=>{ei.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>ms(t,r,n,i),t.unwrap=()=>t._zod.def.innerType});function zo(t){return new Eo({type:"readonly",innerType:t})}const $o=u("ZodCustom",(t,e)=>{ti.init(t,e),y.init(t,e),t._zod.processJSONSchema=(r,n,i)=>ns(t,r)});function Oo(t,e={}){return Ji($o,t,e)}function Po(t){return Wi(t)}const Z=pe([E(),z({pattern:E().describe(`Regex pattern to match.
34
+ @example ".*\\\\.ts$"`),flags:E().optional().describe(`Regex flags to modify matching behavior (e.g. "i" for case-insensitive, "m" for multiline).
35
+ @example "i"`)})]).describe("A string or a regex pattern to match text."),So=z({kind:A("fragment").describe(`The type of element to select.
36
+ @example "fragment"`),condition:Z.optional().describe(`Filter by branch condition text (e.g. "Success").
37
+ @example "Success"`),operator:pe([E(),D(E())]).optional().describe(`Filter by loop/alt type.
38
+ @example "loop"
39
+ @values "loop", "alt", "opt", "break", "par", "critical"`)}).describe("Selects fragment (alt/loop/opt) blocks."),ze=z({kind:A("participant").describe(`The type of element to select.
40
+ @example "participant"`),name:Z.optional().describe(`Filter by participant name (the text displayed).
41
+ @example "UserService"`),id:Z.optional().describe(`Filter by participant ID (alias).
42
+ @example "S1"`),stereotype:Z.optional().describe(`Filter by stereotype (e.g. <<Service>>).
43
+ @example "<<Service>>"`)}).describe("Selects participants in the diagram."),No=z({kind:A("message").describe(`The type of element to select.
44
+ @example "message"`),text:Z.optional().describe(`Filter by message content.
45
+ @example "Login Request"`),from:Z.optional().describe(`Filter by Sender participant ID.
46
+ @example "User"`),to:Z.optional().describe(`Filter by Receiver participant ID.
47
+ @example "Database"`)}).describe("Selects messages between participants."),Ao=z({kind:A("group").describe(`The type of element to select.
48
+ @example "group"`),name:Z.optional().describe(`Filter by group name.
49
+ @example "Services"`)}).describe("Selects groups (boxes/rectangles) of participants."),Zo=z({action:A("resolve").describe(`The operation to perform.
50
+ @example "resolve"`),selector:So.describe("Criteria for selecting fragments to resolve.")}).describe("Unwraps specific branches of fragments (alt, opt, loop), simplifying the diagram."),Co=z({action:A("focus").describe(`The operation to perform.
51
+ @example "focus"`),selector:ze.describe("Criteria for selecting participants to focus on.")}).describe("Keeps only interactions involving the selected participants, hiding everything else."),Ro=z({action:A("remove").describe(`The operation to perform.
52
+ @example "remove"`),selector:pe([ze,No,Ao]).describe("Criteria for selecting elements to remove.")}).describe("Removes the selected elements (participants, messages, or groups) from the diagram."),xo=z({action:A("merge").describe(`The operation to perform.
53
+ @example "merge"`),into:z({name:E().optional().describe(`The name of the new merged participant.
54
+ @example "User System"`),id:E().optional().describe(`The ID of the new merged participant.
55
+ @example "MergedUser"`),stereotype:E().optional().describe(`The stereotype of the new merged participant.
56
+ @example "<<System>>"`)}).optional().describe("Configuration for the target participant to merge into."),selector:ze.describe("Criteria for selecting participants to merge.")}).describe("Merges multiple participants into a single participant."),Lo=uo("action",[Zo,Co,Ro,xo]).describe("A transformation step to apply to the diagram."),Do=z({name:E().describe(`Unique name for the lens. Used to generate the output filename.
57
+ @example "web-view"`),suffix:E().optional().describe(`Custom file suffix. If omitted, defaults to ".<name>".
58
+ @example ".web.mmd"`),layers:D(Lo).describe("Ordered list of transformation layers. Applied sequentially.")}).describe("A specific view or transformation configuration for the diagram."),At=zt(["mermaid","plantuml"]).describe(`Supported diagram format for parsing/generation.
59
+ @example "mermaid"`),Fo=z({input:D(E()).describe(`Array of file paths or glob patterns to include.
60
+ @example ["src/**/*.mmd"]`),outputDir:E().describe(`Directory where generated files will be saved.
61
+ @example "generated"`),ignore:D(E()).optional().describe(`Array of glob patterns to exclude files from processing.
62
+ @example ["**/node_modules/**", "**/*.test.mmd"]`),lenses:D(Do).describe("List of lenses (transformations) to apply to the input diagrams."),format:At.optional().describe("Input format (auto-detected if omitted)."),outputFormat:At.optional().describe("Output format (same as input if omitted).")}).describe("Defines a conversion target: inputs, output location, and transformations."),Zt=z({version:to().describe(`The version of the configuration schema. Currently, only version 1 is supported.
63
+ @example 1`),targets:D(Fo).describe("A list of conversion targets.")}).describe("The root configuration object for Polagram.");function Mo(t){const e=Zt.safeParse(t);if(!e.success){const r=e.error.issues.map(n=>`[${n.path.join(".")}]: ${n.message}`).join(`
34
64
  `);throw new Error(`Invalid Polagram Configuration:
35
- ${n}`)}return e.data}T.FormatDetector=fe,T.GeneratorFactory=Ht,T.MermaidGeneratorVisitor=le,T.ParserFactory=Se,T.PlantUMLGeneratorVisitor=de,T.Polagram=Qt,T.PolagramBuilder=Ae,T.PolagramConfigSchema=Zt,T.TransformationEngine=H,T.Traverser=pe,T.transformerRegistry=Ne,T.validateConfig=jo,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));
65
+ ${r}`)}return e.data}T.FormatDetector=fe,T.GeneratorFactory=Ht,T.MermaidGeneratorVisitor=le,T.ParserFactory=Se,T.PlantUMLGeneratorVisitor=de,T.Polagram=Qt,T.PolagramBuilder=Ae,T.PolagramConfigSchema=Zt,T.TransformationEngine=H,T.Traverser=he,T.transformerRegistry=Ne,T.validateConfig=Mo,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));