@polagram/core 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/polagram-core.js +4 -16
- package/dist/polagram-core.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/polagram-core.js
CHANGED
|
@@ -1316,15 +1316,9 @@ class Bt extends K {
|
|
|
1316
1316
|
return super.visitEvent(e);
|
|
1317
1317
|
}
|
|
1318
1318
|
filterMultiParticipantNode(e) {
|
|
1319
|
-
|
|
1319
|
+
return e.participantIds.filter(
|
|
1320
1320
|
(n) => this.targetParticipantIds.has(n)
|
|
1321
|
-
);
|
|
1322
|
-
return r.length === 0 ? [] : [
|
|
1323
|
-
{
|
|
1324
|
-
...e,
|
|
1325
|
-
participantIds: r
|
|
1326
|
-
}
|
|
1327
|
-
];
|
|
1321
|
+
).length !== e.participantIds.length ? [] : [e];
|
|
1328
1322
|
}
|
|
1329
1323
|
// Helper to check if message involves the participant from selector
|
|
1330
1324
|
isRelatedToParticipant(e) {
|
|
@@ -1456,15 +1450,9 @@ class Wt extends K {
|
|
|
1456
1450
|
return super.visitEvent(e);
|
|
1457
1451
|
}
|
|
1458
1452
|
filterMultiParticipantNode(e) {
|
|
1459
|
-
|
|
1453
|
+
return e.participantIds.filter(
|
|
1460
1454
|
(n) => !this.removedParticipantIds.has(n)
|
|
1461
|
-
);
|
|
1462
|
-
return r.length === 0 ? [] : [
|
|
1463
|
-
{
|
|
1464
|
-
...e,
|
|
1465
|
-
participantIds: r
|
|
1466
|
-
}
|
|
1467
|
-
];
|
|
1455
|
+
).length !== e.participantIds.length ? [] : [e];
|
|
1468
1456
|
}
|
|
1469
1457
|
isRelatedToRemovedParticipant(e) {
|
|
1470
1458
|
return !!(e.from && this.removedParticipantIds.has(e.from) || e.to && this.removedParticipantIds.has(e.to));
|
|
@@ -9,7 +9,7 @@
|
|
|
9
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
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
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(`
|
|
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){return e.participantIds.filter(n=>this.targetParticipantIds.has(n)).length!==e.participantIds.length?[]:[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 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){return e.participantIds.filter(n=>!this.removedParticipantIds.has(n)).length!==e.participantIds.length?[]:[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 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
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
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) {
|