sketchi 0.25.1 → 0.25.2
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/package.json +1 -1
- package/sketchi.js +4 -4
package/sketchi.js
CHANGED
|
@@ -233,7 +233,7 @@ authority: ${e.diagram.authority}`,e=>({id:e.diagram.manifest.id,restoredFromRev
|
|
|
233
233
|
`:`error: usage_error
|
|
234
234
|
${a}
|
|
235
235
|
next: ${l}
|
|
236
|
-
`)}},c=new Proxy(globalThis.console,{get(e,t,a){if("log"===t)return(...t)=>{(1!==t.length||""!==t[0])&&e.log(...t)};let s=Reflect.get(e,t,a);return"function"==typeof s?s.bind(e):s}}),pL(g9,{version:"0.25.1"})(e).pipe(X.sFT(e=>eu.i5(e,ru)&&"ShowHelp"!==e._tag?rh(n.formatErrors([e])):X.rIH),X.PfK(ch,{builtIns:[co,cr,cc]}),X.PfK(ni,n),X.PfK(rd,c))).pipe(X.khu({onFailure:e=>X.JkU(function*(){let t,a=ee.getOrUndefined(U.L$(e));if(a instanceof go)return a.exitCode;if(a instanceof sV)return 7;let s=function(e){if(eu.i5(e,ru))return"ShowHelp"===e._tag?2*(e.errors.length>0):2}(a);if(void 0!==s)return s;let i=yield*gl;return yield*i.stderr((t={code:"internal_error",message:"Sketchi could not complete the command.",hint:"Retry once; if it persists, report the command and inputs without secrets."},"json"===d?s4({ok:!1,command:"sketchi",error:t}):gc(t))).pipe(X.MfU(()=>X.rIH)),1}),onSuccess:()=>X.PyW(0)}))}),ut=j.Um(sP.Txp,(0,sP.rRT)({createId:e=>`${e}_offline_cli`,icons:lj})),ua=j.Gt(s9,ut),us=j.Gt(ih,ut),ui=j.Um(il,ll),ul=j.Gt(lm,ui),uo=j.Gt(lX,j.Um(ul,lI)),ur=j.Gt(gL,gk),un=j.Um(il,ll,ua,us,ul,uo,lI,ur,gz,im.pipe(j.Gt(il)),gn,rc),uc=j.S5(un,sA);Z(ue(process.argv.slice(2)).pipe(X.Mim(e=>X.OH5(()=>{process.exitCode=e})),X.Gte(uc)),{disableErrorReporting:!0})},1688(e,t,a){var s=a(2718);let i=s.xCb(["invalid_render_artifact","render_limit_exceeded","unsupported_render_glyph","rasterization_failed"]),l=s.xCb(["artifact","geometry","font","rasterization"]);class o extends s.rNF()("HeadlessPngRenderError",{cause:s.kld(),code:i,stage:l,message:s.QfV,details:s.O31(s.QfV)}){}a.d(t,{FG:()=>o})},5030(e,t,a){function s(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i(e,t,a,s){return{code:e,message:t,...void 0===a?{}:{observed:a},...void 0===s?{}:{limit:s}}}function l(e,t=0){let a=1/0,o=1/0,r=-1/0,n=-1/0;for(let t of e){if(!(s(t)&&"number"==typeof t.x&&Number.isFinite(t.x)&&"number"==typeof t.y&&Number.isFinite(t.y)&&"number"==typeof t.width&&Number.isFinite(t.width)&&"number"==typeof t.height&&Number.isFinite(t.height)))return i("invalid_geometry","element geometry is invalid");let e=Math.abs(t.width),l=Math.abs(t.height);if(e>8192||l>8192)return i("element_dimension",`element dimension exceeds ${String(8192)}`,Math.max(e,l),8192);let c=function(e){if(void 0!==e.angle&&0!==e.angle)return;let t=Array.isArray(e.points)?e.points.filter(e=>Array.isArray(e)&&"number"==typeof e[0]&&Number.isFinite(e[0])&&"number"==typeof e[1]&&Number.isFinite(e[1])):[],a=[e.x,e.x+e.width,...t.map(t=>e.x+t[0])],s=[e.y,e.y+e.height,...t.map(t=>e.y+t[1])];return{left:Math.min(...a),top:Math.min(...s),right:Math.max(...a),bottom:Math.max(...s)}}(t);if(c){a=Math.min(a,c.left),o=Math.min(o,c.top),r=Math.max(r,c.right),n=Math.max(n,c.bottom);continue}let d=Math.hypot(e,l)/2,p=t.x+t.width/2,h=t.y+t.height/2;a=Math.min(a,p-d),o=Math.min(o,h-d),r=Math.max(r,p+d),n=Math.max(n,h+d)}if(0===e.length)return;let c=r-a,d=n-o;if(c>8192||d>8192)return i("canvas_dimension",`canvas dimension exceeds ${String(8192)}`,Math.max(c,d),8192);let p=c*d;if(p>6291456)return i("canvas_area",`canvas area exceeds ${String(6291456)}`,p,6291456);let h=(c+40)*1*((d+40+t)*1);if(h>0x1800000)return i("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,h,0x1800000)}function o(e,t){let a=new Set(t.flatMap(e=>s(e)&&"image"===e.type&&!0!==e.isDeleted&&"string"==typeof e.fileId?[e.fileId]:[])),l=0;for(let t of a){let a=Object.hasOwn(e,t)?e[t]:void 0,i=s(a)?a.dataURL:void 0;"string"==typeof i&&(l+=i.length)}return l>8388608?i("file_bytes",`embedded image data exceeds ${String(8388608)} bytes`,l,8388608):void 0}function r(e,t=0){return l(e,t)?.message}function n(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return i("invalid_geometry","rendered SVG dimensions are invalid");let a=Math.min(2,16384/e,16384/t,Math.sqrt(0x1800000/(e*t)));if(a<1){let a=e*t;return a>0x1800000?i("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,a,0x1800000):i("output_dimension","rendered SVG dimension exceeds the PNG limit at minimum scale",Math.max(e,t),16384)}return Math.max(1,Math.floor(1e3*a)/1e3)}a.d(t,{Gd:()=>r,Ts:()=>l,Yu:()=>n,jA:()=>o},{Z4:6291456,ce:0x1800000})},6982(e){e.exports=t("crypto")},7598(e){e.exports=t("node:crypto")},76(e,t,a){let s=a(9095),i=process.env;function l(e){return"string"==typeof e?!!i[e]:"env"in e?i[e.env]&&i[e.env].includes(e.includes):"any"in e?e.any.some(function(e){return!!i[e]}):Object.keys(e).every(function(t){return i[t]===e[t]})}Object.defineProperty(t,"_vendors",{value:s.map(function(e){return e.constant})}),t.name=null,t.isPR=null,t.id=null,"false"!==i.CI&&s.forEach(function(e){let a=(Array.isArray(e.env)?e.env:[e.env]).every(function(e){return l(e)});t[e.constant]=a,a&&(t.name=e.name,t.isPR=function(e){switch(typeof e.pr){case"string":return!!i[e.pr];case"object":if("env"in e.pr)if("any"in e.pr)return e.pr.any.some(function(t){return i[e.pr.env]===t});else return e.pr.env in i&&i[e.pr.env]!==e.pr.ne;if("any"in e.pr)return e.pr.any.some(function(e){return!!i[e]});return l(e.pr);default:return null}}(e),t.id=e.constant)}),t.isCI=!!("false"!==i.CI&&(i.BUILD_ID||i.BUILD_NUMBER||i.CI||i.CI_APP_ID||i.CI_BUILD_ID||i.CI_BUILD_NUMBER||i.CI_NAME||i.CONTINUOUS_INTEGRATION||i.RUN_ID||t.name))},485(e,t,a){e.exports=a(76).isCI},664(e,t,a){a.d(t,{CN:()=>g,BC:()=>m,Ie:()=>z,pb:()=>B,i8:()=>k,g9:()=>b,Uk:()=>M,Ts:()=>u,CZ:()=>v,ET:()=>y,HV:()=>w,T9:()=>P,Tj:()=>L,YW:()=>f,of:()=>_,jB:()=>S,TS:()=>A,di:()=>C});var s=a(7876),i=a(1594);let l=e=>e.length>0;var o=a(9771),r=a(592),n=a(1587),c=a(2860),d=a(915),p=a(9315);let h=globalThis.Array,g=e=>new h(o.S(e)),u=e=>h.isArray(e)?e:h.from(e);d.Wo,n.toArray;let f=(0,i.XY)(2,(e,{onEmpty:t,onNonEmpty:a})=>y(e)?a(e):t()),m=(0,i.XY)(2,(e,t)=>[...e,t]);h.isArray;let v=l,y=l,w=e=>y(e)?n.some(x(e)):n.none(),x=e=>e[e.length-1],b=(0,i.XY)(2,(e,t)=>{let a=0;for(let s of e){if(t(s,a))return n.some(a);a++}return n.none()}),k=r.i8,M=(0,i.XY)(2,(e,t)=>{let a=u(e);for(let e=a.length-1;e>=0;e--){let s=a[e],i=t(s,e);if("boolean"==typeof i){if(i)return n.some(s)}else if(n.isSome(i))return i}return n.none()}),C=(0,i.XY)(2,(e,t)=>{let a=h.from(e);return a.sort(t),a}),z=()=>[],_=e=>[e],L=(0,i.XY)(2,(e,t)=>e.map(t)),B=(0,i.XY)(2,(e,t)=>{let a=u(e),s=[];for(let e=0;e<a.length;e++)t(a[e],e)&&s.push(a[e]);return s}),S=(0,i.XY)(2,(e,t)=>{let a=[],s=[],i=0;for(let l of e){let e=t(l,i++);p.oJ(e)?a.push(e.success):s.push(e.failure)}return[a,s]}),A=(0,i.XY)(3,(e,t,a)=>u(e).reduce((e,t,s)=>a(e,t,s),t));c.O3;let P=s.O3},5053(e,t,a){var s=a(9519),i=a(7876),l=a(1594),o=a(1587),r=a(2860),n=a(4233),c=a(636);let d=globalThis.BigInt,p=d(0);n.sI;let h=(0,l.XY)(2,(e,t)=>e+t),g=r.Qw,u=i.Qw,f=r.hl(g),m=r.bi(g),v=r.yJ(g),y=r.OW(g),w=r.Bt(g),x=r.qE(g),b=r.jk(g),k=r.T9(g),M=c.L((e,t)=>e+t,p),C=s.T9(g),z=s.jk(g);a.d(t,{},{K0:z,OW:y,Ro:e=>e>d(Number.MAX_SAFE_INTEGER)||e<d(Number.MIN_SAFE_INTEGER)?o.none():o.some(Number(e)),T9:k,Tq:w,aD:M,bi:m,cz:h,hl:f,jk:b,pH:g,qE:x,rs:u,sO:C,yJ:v})},3265(e,t,a){var s=a(5053),i=a(1587);let l=BigInt(0),o=BigInt(1),r=BigInt(1e3),n=BigInt(1024),c=[{symbol:"B",factor:o,names:["B","byte","bytes"]},{symbol:"kB",factor:r,names:["kB","kilobyte","kilobytes"]},{symbol:"MB",factor:r**BigInt(2),names:["MB","megabyte","megabytes"]},{symbol:"GB",factor:r**BigInt(3),names:["GB","gigabyte","gigabytes"]},{symbol:"TB",factor:r**BigInt(4),names:["TB","terabyte","terabytes"]},{symbol:"PB",factor:r**BigInt(5),names:["PB","petabyte","petabytes"]},{symbol:"EB",factor:r**BigInt(6),names:["EB","exabyte","exabytes"]},{symbol:"ZB",factor:r**BigInt(7),names:["ZB","zettabyte","zettabytes"]},{symbol:"YB",factor:r**BigInt(8),names:["YB","yottabyte","yottabytes"]},{symbol:"RB",factor:r**BigInt(9),names:["RB","ronnabyte","ronnabytes"]},{symbol:"QB",factor:r**BigInt(10),names:["QB","quettabyte","quettabytes"]}],d=[c[0],{symbol:"KiB",factor:n,names:["KiB","kibibyte","kibibytes"]},{symbol:"MiB",factor:n**BigInt(2),names:["MiB","mebibyte","mebibytes"]},{symbol:"GiB",factor:n**BigInt(3),names:["GiB","gibibyte","gibibytes"]},{symbol:"TiB",factor:n**BigInt(4),names:["TiB","tebibyte","tebibytes"]},{symbol:"PiB",factor:n**BigInt(5),names:["PiB","pebibyte","pebibytes"]},{symbol:"EiB",factor:n**BigInt(6),names:["EiB","exbibyte","exbibytes"]},{symbol:"ZiB",factor:n**BigInt(7),names:["ZiB","zebibyte","zebibytes"]},{symbol:"YiB",factor:n**BigInt(8),names:["YiB","yobibyte","yobibytes"]}],p=new Map([...c,...d.slice(1)].flatMap(e=>e.names.map(t=>[t,e]))),h=e=>{throw Error(`Invalid ByteSize: ${e}`)},g=e=>!Number.isSafeInteger(e)||e<0?h(`expected a non-negative safe integer, received ${e}`):BigInt(e),u=e=>{let t=/^\s*(\d+)(?:\.(\d+))?\s*([A-Za-z]+)\s*$/.exec(e);if(null===t)return h(`unsupported syntax ${JSON.stringify(e)}`);let a=p.get(t[3]);if(void 0===a)return h(`unsupported unit ${JSON.stringify(t[3])}`);let s=t[2]??"",i=BigInt(10)**BigInt(s.length),o=BigInt(t[1]+s)*a.factor;return o%i!==l?h(`${JSON.stringify(e)} does not represent an integral number of bytes`):o/i},f=i.liftThrowable(u),m=e=>{switch(typeof e){case"bigint":if(e<l)return h(`expected a non-negative bigint, received ${e}`);return e;case"number":return g(e);case"string":return u(e)}return h(`unsupported input ${e}`)},v=i.liftThrowable(m),y=s.Ro;s.pH,s.rs,s.Tq,s.jk,s.T9,s.qE,s.hl,s.bi,s.yJ,s.OW,s.cz,s.aD,s.sO,s.K0,a.d(t,{},{Dg:e=>e,Ro:y,bN:m,ee:e=>"bigint"==typeof e?m(e):g(e),lX:v,sH:f,yp:e=>"bigint"==typeof e&&e>=l})},719(e,t,a){var s=a(2449),i=a(6297);s.PX,s.B4,s.Aj,s.Wg;let l=s.lC;s.Xb,s.ik;let o=s.b5;s.DH;let r=s.OE,n=s.Iu;i.nIy,i.ORc;let c=i.nn5,d=i.O$X;s.h2;let p=i.ReC;i.myX,i.QE5,i.khU;let h=i.L$u;i.gpn,i.k7S,i.BbX;let g=i.prj;i.tU5,i.h74,i.Bou,i.RJ6;let u=i.GyP;s.PW,s.qB,s.Xm;let f=s.$L;s.q_;let m=s.RS,v=s.Vw;i.DQo,i.c8t,i.MUS,i.t8c,i._y;let y=i.qwd;i.ASO,i.F7W,i.Aub,i.cOF,i.Rft,i.RD4,i.Kkt,i.PnV;let w=i.Bk6;s.Eh,i.tQ6,i.On5,a.d(t,{},{$L:f,Bk:w,F_:n,L$:h,RS:m,Tj:d,Vw:v,fJ:r,iw:p,j9:u,kO:o,lC:l,nn:c,pr:g,qw:y})},4238(e,t,a){var s=a(6297);s.a1U,s.RKA;let i=s.Rud;s.s0X,s.T13,a.d(t,{},{Ru:i})},9519(e,t,a){function s(e){return{combine:e}}function i(e){return s((t,a)=>-1===e(t,a)?t:a)}function l(e){return s((t,a)=>1===e(t,a)?t:a)}a.d(t,{L8:()=>s,T9:()=>l,jk:()=>i})},1179(e,t,a){var s=a(3811),i=a(3332),l=a(1594),o=a(5033),r=a(2449),n=a(1587),c=a(4233);let d="~effect/Context/Service",p=function(){let e=function(){};Object.setPrototypeOf(e,h);let t=(t,a)=>(e.key=t,a?.defaultValue&&(e[u]=u,e.defaultValue=a.defaultValue),a?.make&&(e.make=a.make),a?.fiberCached&&g.add(t),e);return arguments.length>0?t(arguments[0],arguments[1]):t},h={[d]:d,...s.bp({label:"Service",evaluate(e){return(0,r.xt)(V(e.context,this))}}),toJSON(){return{_id:"Service",key:this.key}},of:e=>e,context(e){return _(this,e)},use(e){return(0,r.R6)(t=>e(V(t.context,this)))},useSync(e){return(0,r.R6)(t=>(0,r.xt)(e(V(t.context,this))))}},g=new Set,u="~effect/Context/Reference",f="~effect/Context",m=(e,t,a,s)=>{let i=Object.create(k);return i.cacheRoot=e??i,i.base=t,i.overlay=a,i.depth=s,i._flat=void 0,i.baseHits=0,i},v=(e,t)=>{t&&(v(e,t.parent),e.set(t.key,t.value))},y=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return v(t,e.overlay),e._flat=t},w=Symbol(),x=(e,t)=>{for(let a=e.overlay;a;a=a.parent)if(a.key===t)return a.value;let a=e.base.get(t);return void 0!==a||e.base.has(t)?(e.overlay&&++e.baseHits>=e.base.size&&e.baseHits>=8&&(e.base=y(e),e.overlay=void 0,e.depth=0),a):w},b=e=>m(void 0,e,void 0,0),k={get mapUnsafe(){return y(this)},...r.fU,[f]:{_Services:e=>e},toJSON(){return{_id:"Context",services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[i.HR](e){if(!M(e))return!1;let t=this.mapUnsafe,a=e.mapUnsafe;if(t.size!==a.size)return!1;for(let[e,s]of t)if(!a.has(e)||!i.aI(s,a.get(e)))return!1;return!0},[o.HR](){return o.ai(this.mapUnsafe.size)}},M=e=>(0,c.i5)(e,f),C=e=>!!e[u],z=b(new Map),_=(e,t)=>b(new Map([[e.key,t]])),L=(0,l.XY)(3,(e,t,a)=>B(e,t.key,a)),B=(e,t,a)=>{let s=g.has(t)?void 0:e.cacheRoot;if(e.depth>=8){let i=new Map(e.mapUnsafe);return i.set(t,a),m(s,i,void 0,0)}return m(s,e.base,{key:t,value:a,parent:e.overlay},e.depth+1)},S=(0,l.XY)(2,(e,t)=>A(e,t.key)),A=(e,t)=>{let a=x(e,t);return a===w?void 0:a},P=(0,l.XY)(2,(e,t)=>{let a=x(e,t.key);if(a===w){if(C(t))return q(t);throw F(t)}return a}),V=P,H="~effect/Context/defaultValue",q=e=>H in e?e[H]:e[H]=e.defaultValue(),F=e=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:""}`);if(t.stack){let e=t.stack.split("\n");e.splice(1,3),t.stack=e.join("\n")}return t},I=(0,l.XY)(2,(e,t)=>{let a=x(e,t.key);return a!==w?n.some(a):C(t)?n.some(q(t)):n.none()}),E=(0,l.XY)(2,(e,t)=>{let a;return 0===e.mapUnsafe.size?t:0===t.mapUnsafe.size?e:((e=>t.mapUnsafe.forEach((t,a)=>e.set(a,t)))(a=new Map(e.mapUnsafe)),b(a))});a.d(t,{},{Ie:()=>z,Jt:V,L8:_,LZ:b,Or:p,Pf:(e,t)=>e.cacheRoot===t.cacheRoot,Ub:A,Um:(...e)=>{let t=new Map;for(let a=0;a<e.length;a++)e[a].mapUnsafe.forEach((e,a)=>{t.set(a,e)});return b(t)},WQ:L,Y6:S,aE:M,fp:P,h1:E,kl:p,om:I})},4942(e,t,a){var s=a(2449),i=a(2275),l=a(1554),o=a(4233);let r=class extends l.Xs{constructor(e){super(),e&&i.z(this,e)}};function n(){if(1==arguments.length){let e=arguments[0];return function(t){return e[t._tag](t)}}let e=arguments[0],t=arguments[1];return t[e._tag](e)}let c=s.$D,d=s.rN;a.d(t,{},{$D:c,Ij:()=>new Proxy({},{get:(e,t,a)=>"$is"===t?o.$J:"$match"===t?n:e=>({...e,_tag:t})}),Xs:r,rN:d})},9237(e,t,a){var s=a(1594),i=a(6297),l=a(1554);let o={"~effect/Deferred":{_A:s.D_,_E:s.D_},pipe(){return(0,l.tT)(this,arguments)}},r=function(){this.resumes=void 0,this.effect=void 0};r.prototype=o;let n=e=>void 0!==e.effect;a.d(t,{},{$L:e=>i.OH5(()=>n(e)),$w:(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let a=e.resumes;e.resumes=void 0;for(let e=0;e<a.length;e++)a[e](t)}return!0},LZ:()=>new r,NJ:n,Tx:e=>i.E2r(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),i.OH5(()=>{let a=e.resumes;if(void 0===a)return;let s=a.indexOf(t);s>=0&&a.splice(s,1)})))})},3614(e,t,a){var s=a(3332),i=a(1594),l=a(5033),o=a(3952),r=a(2860),n=a(1554),c=a(4233);let d="~effect/Duration",p=BigInt(0),h=BigInt(1),g=BigInt(2),u=BigInt(10),f=BigInt(24),m=BigInt(60),v=BigInt(1e3),y=BigInt(1e6),w=e=>BigInt(e<0?Math.ceil(e-.5):Math.floor(e+.5)),x=(e,t)=>{let a=e.indexOf(".");if(-1===a)return BigInt(e)*t;let s="-"===e[0],i=e.slice(a+1),l=u**BigInt(i.length),o=(BigInt(e.slice(+!!s,a))*l+BigInt(i))*t,r=o/l+(o%l*g>=l?h:p);return s?-r:r},b=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,k=e=>{switch(typeof e){case"number":return q(e);case"bigint":return H(e);case"string":{if("Infinity"===e)return P;if("-Infinity"===e)return V;let t=b.exec(e);if(!t)break;let[a,s,i]=t;if("nano"===i||"nanos"===i)return H(x(s,h));if("micro"===i||"micros"===i)return H(x(s,v));let l=Number(s);switch(i){case"milli":case"millis":return q(l);case"second":case"seconds":return F(l);case"minute":case"minutes":return I(l);case"hour":case"hours":return E(l);case"day":case"days":return O(l);case"week":case"weeks":return U(l)}break}case"object":{if(null===e)break;if(d in e)return e;if(Array.isArray(e)){if(2!==e.length||!e.every(c.Et))return M(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return A;if(-1/0===e[0]||-1/0===e[1])return V;if(1/0===e[0]||1/0===e[1])return P;return B(w(1e9*e[0]+e[1]))}let t=0;if(e.weeks&&(t+=6048e5*e.weeks),e.days&&(t+=864e5*e.days),e.hours&&(t+=36e5*e.hours),e.minutes&&(t+=6e4*e.minutes),e.seconds&&(t+=1e3*e.seconds),e.milliseconds&&(t+=e.milliseconds),!e.microseconds&&!e.nanoseconds)return B(t);return B(w(1e6*t+(e.microseconds??0)*1e3+(e.nanoseconds??0)))}}return M(e)},M=e=>{throw Error(`Invalid Input: ${e}`)},C={_tag:"Millis",millis:0},z={_tag:"Infinity"},_={_tag:"NegativeInfinity"},L={[d]:d,[l.HR](){switch(this.value._tag){case"Millis":{let e=1e6*this.value.millis;return Number.isFinite(e)?l.tW(w(e)):l.ai(this.value.millis)}case"Nanos":return l.tW(this.value.nanos);default:return l.QK(this.value)}},[s.HR](e){return S(e)&&D(this,e)},toString(){switch(this.value._tag){case"Infinity":return"Infinity";case"NegativeInfinity":return"-Infinity";case"Nanos":return`${this.value.nanos} nanos`;case"Millis":return`${this.value.millis} millis`}},toJSON(){switch(this.value._tag){case"Millis":return{_id:"Duration",_tag:"Millis",millis:this.value.millis};case"Nanos":return{_id:"Duration",_tag:"Nanos",nanos:String(this.value.nanos)};case"Infinity":return{_id:"Duration",_tag:"Infinity"};case"NegativeInfinity":return{_id:"Duration",_tag:"NegativeInfinity"}}},[o.FX](){return this.toJSON()},pipe(){return(0,n.tT)(this,arguments)}},B=e=>{let t=Object.create(L);return"number"==typeof e?isNaN(e)||0===e||Object.is(e,-0)?t.value=C:Number.isFinite(e)?Number.isInteger(e)?t.value={_tag:"Millis",millis:e}:t.value={_tag:"Nanos",nanos:w(1e6*e)}:t.value=e>0?z:_:e===p?t.value=C:t.value={_tag:"Nanos",nanos:e},t},S=e=>(0,c.i5)(e,d),A=B(0),P=B(1/0),V=B(-1/0),H=e=>B(e),q=e=>B(e),F=e=>B(1e3*e),I=e=>B(6e4*e),E=e=>B(36e5*e),O=e=>B(864e5*e),U=e=>B(6048e5*e),X=e=>{let t=k(e);switch(t.value._tag){case"Infinity":case"NegativeInfinity":throw Error("Cannot convert infinite duration to nanos");case"Nanos":return t.value.nanos;case"Millis":return w(1e6*t.value.millis)}},T=(0,i.XY)(2,(e,t)=>{switch(e.value._tag){case"Millis":return t.onMillis(e.value.millis);case"Nanos":return t.onNanos(e.value.nanos);case"Infinity":return t.onInfinity();case"NegativeInfinity":return(t.onNegativeInfinity??t.onInfinity)()}}),Y=(0,i.XY)(3,(e,t,a)=>"Infinity"===e.value._tag||"NegativeInfinity"===e.value._tag||"Infinity"===t.value._tag||"NegativeInfinity"===t.value._tag?a.onInfinity(e,t):"Millis"===e.value._tag?"Millis"===t.value._tag?a.onMillis(e.value.millis,t.value.millis):a.onNanos(X(e),t.value.nanos):a.onNanos(e.value.nanos,X(t))),$=r.L8((e,t)=>Y(e,t,{onMillis:(e,t)=>e<t?-1:+(e>t),onNanos:(e,t)=>e<t?-1:+(e>t),onInfinity:(e,t)=>e.value._tag===t.value._tag?0:"Infinity"===e.value._tag?1:"NegativeInfinity"===e.value._tag||"Infinity"===t.value._tag?-1:1})),G=r.bi($),D=(0,i.XY)(2,(e,t)=>Y(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag})),R=e=>{if("Infinity"===e.value._tag)return"Infinity";if("NegativeInfinity"===e.value._tag)return"-Infinity";if((e=>{switch(e.value._tag){case"Millis":return 0===e.value.millis;case"Nanos":return e.value.nanos===p;case"Infinity":case"NegativeInfinity":return!1}})(e))return"0";if((e=>{switch(e.value._tag){case"Millis":return e.value.millis<0;case"Nanos":return e.value.nanos<p;case"NegativeInfinity":return!0;case"Infinity":return!1}})(e))return"-"+R((e=>{switch(e.value._tag){case"Infinity":case"NegativeInfinity":return P;case"Millis":return e.value.millis<0?B(-e.value.millis):e;case"Nanos":return e.value.nanos<p?B(-e.value.nanos):e}})(e));let t=(e=>{if("Infinity"===e.value._tag)return{days:1/0,hours:1/0,minutes:1/0,seconds:1/0,millis:1/0,nanos:1/0};if("NegativeInfinity"===e.value._tag)return{days:-1/0,hours:-1/0,minutes:-1/0,seconds:-1/0,millis:-1/0,nanos:-1/0};let t=X(e),a=t<p,s=a?-t:t,i=s/y,l=i/v,o=l/m,r=o/m,n=a?-1:1;return{days:n*Number(r/f),hours:n*Number(r%f),minutes:n*Number(o%m),seconds:n*Number(l%m),millis:n*Number(i%v),nanos:n*Number(s%y)}})(e),a=[];return 0!==t.days&&a.push(`${t.days}d`),0!==t.hours&&a.push(`${t.hours}h`),0!==t.minutes&&a.push(`${t.minutes}m`),0!==t.seconds&&a.push(`${t.seconds}s`),0!==t.millis&&a.push(`${t.millis}ms`),0!==t.nanos&&a.push(`${t.nanos}ns`),a.join(" ")};a.d(t,{},{GP:R,MI:e=>"Infinity"!==e.value._tag&&"NegativeInfinity"!==e.value._tag,Tn:P,YA:F,bN:k,bi:G,cF:H,fP:e=>T(k(e),{onMillis:e=>e/1e3,onNanos:e=>Number(e)/1e9,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),kE:e=>T(k(e),{onMillis:i.D_,onNanos:e=>Number(e)/1e6,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),n$:S,ne:q,qv:V,v_:A})},2842(e,t,a){a.d(t,{Q56:()=>ex,jGc:()=>eb,U9h:()=>ek,Q7R:()=>k,hgn:()=>Y,swY:()=>e$,Muk:()=>eA,as:()=>j,E2r:()=>P,MfU:()=>N,Tyx:()=>K,osR:()=>Q,KuX:()=>W,loE:()=>J,RKA:()=>eX,_32:()=>eP,F_Q:()=>E,_r7:()=>eG,yeE:()=>eM,NS5:()=>R,fJG:()=>q,ATB:()=>F,pVV:()=>I,qIB:()=>T,Ab9:()=>ej,fn:()=>eU,D9k:()=>eO,vCS:()=>eN,jJl:()=>M,i4r:()=>eS,ar0:()=>eH,x6Z:()=>eq,yUA:()=>X,JkU:()=>H,XeO:()=>el,GaK:()=>e_,yw5:()=>b,vVN:()=>eY,FFw:()=>eT,TjK:()=>Z,q7Y:()=>eZ,jkJ:()=>eD,xm_:()=>ee,Z9x:()=>eR,YWq:()=>ed,khu:()=>ep,tvg:()=>eh,ZmZ:()=>V,S5A:()=>eC,cfM:()=>ez,uKv:()=>D,QgK:()=>et,ivC:()=>z,Gte:()=>eg,PpN:()=>eu,PfK:()=>em,KT6:()=>ec,Ket:()=>G,L5P:()=>ei,MY7:()=>eF,eJC:()=>eI,lKS:()=>eE,z8E:()=>ev,P1j:()=>ey,Pxi:()=>ew,Nav:()=>ef,yy4:()=>en,PyW:()=>L,DYE:()=>B,OH5:()=>S,Mim:()=>$,dGm:()=>es,sFT:()=>ea,wRz:()=>eo,mgX:()=>er,SvU:()=>O,$mh:()=>_,rfi:()=>eL,FcF:()=>eB,rIH:()=>A,iMI:()=>C,R6R:()=>U,fRP:()=>eV});var s=a(1594),i=a(2449),l=a(6297),o=(a(3614),a(1179));a(9315);var r=a(6771),n=a(5633);let c=(0,s.XY)(e=>(0,i.yw)(e[0]),(e,t,a)=>{let s;return o.aE(t)?l.PpN(e,t):(s=Array.isArray(t)?n.Um(...t):t,l.Pxi(t=>l.qIB(a?.local?n.H7(s,n.j6(),t):n.LT(s,t),t=>l.PpN(e,t))))});var d=a(1587),p=a(3753),h=a(6481);(e,t,a)=>l.qIB(r.xn(t),t=>{let s=r.d3.defaultValue();return l.h_t(l.i4r(l.Mim(l.qIB(l.DYE(()=>l.PfK(e,r.d3,s)),t),e=>l.OH5(()=>{s=e})),{disableYield:!0}),e=>i.$L(e)?l.PyW(e.value):a(e,0===s.attempt?d.none():d.some(s)))});let g=(0,s.XY)(3,(e,t,a)=>l.qIB(r.xn(t),t=>{let s,i=r.d3.defaultValue(),o=l.h_t(l.DYE(()=>l.PfK(e,r.d3,i)),e=>(s=e,l.qIB(t(e),e=>(i=e,o))));return p.m8(o,e=>(0,h.s)(()=>a(s,e)))})),u=(0,s.XY)(2,(e,t)=>g(e,"function"==typeof t?t(s.D_):r.GM(t)?t:m(t),l.fJG)),f=r.le(r.i4),m=e=>{let t=e.schedule?r.le(e.schedule):f;return e.while&&(t=r.E6(t,({input:t})=>{let a=e.while(t);return i.yw(a)?a:l.PyW(a)})),e.until&&(t=r.E6(t,({input:t})=>{let a=e.until(t);return i.yw(a)?l.TjK(a,e=>!e):l.PyW(!a)})),void 0!==e.times&&(t=r.E6(t,({attempt:t})=>l.PyW(t<=e.times))),t},v=r.t5(1);var y=a(2275);let w=a(3332).Xq({_E:e=>e,_A:e=>e,_R:e=>e});({...i.In,"~effect/Request":w}),a(3909);var x=a(4600);i.$n;let b=i.yw,k=l.Q7R;l.jBG,l.TSs,l.tfT,l.i8i,l.kAe;let M=l.jJl;l.d5f;let C=l.iMI,z=l.ivC,_=l.$mh,L=l.PyW;l.lwU,l.nGE;let B=l.DYE,S=l.OH5,A=l.rIH;l.Vxk;let P=l.E2r,V=l.ZmZ;l.Do,l.JrD,l.uVU,l.oIE;let H=l.JkU,q=l.fJG;l.gOk;let F=l.ATB,I=l.pVV,E=l.F_Q,O=l.SvU;l.m9E,l.KN3;let U=i.R6;i.Hq;let X=l.yUA;l.sVm,l.pkL,l.bJ;let T=l.qIB;l.Bqz;let Y=l.hgn,$=l.Mim,G=l.Ket,D=l.uKv,R=l.NS5,Z=l.TjK,j=l.as;l.Xx$,l.NLW,l.UUz,l.yU6,l.OYO;let N=l.h_t,W=l.KuX,J=l.loE;l.AXC,l.zt4,l.scW;let K=l.Tyx;l.Fig,l.XWm;let Q=l.osR;l.U9Y,l.sJf,l.rNk;let ee=l.xm_;l.UcN;let et=l.QgK,ea=l.sFT;l.k$L;let es=l.dGm;l.cA6,l.bKC,l.nAi,l.u4Y;let ei=u;l._Sg;let el=l.XeO;l.GrF,l.$$g,l.DM4,l.Dd;let eo=l.wRz;l.D52;let er=l.mgX;l.cbG;let en=l.yy4;l.ayu,l.Vdx,l.FfP,l.O4F;let ec=l.KT6;l.pbD,l.x1Q,l.E8K,l.Pm0,l.VtY,l.W$I,l.ahH,l.z7s;let ed=l.YWq;l.G$Q,l.D$$,l.NZb,l.wR5;let ep=l.khu,eh=l.tvg;l.N6O,l.oJd,l._OA,l.sxi;let eg=c,eu=l.PpN;l.oao,l.euC;let ef=l.Nav;l.r_d,l.bUZ,l.L_I;let em=l.PfK;l.c7E;let ev=l.z8E,ey=l.P1j,ew=l.Pxi,ex=l.Q56;l.N24;let eb=l.jGc,ek=l.U9h,eM=l.yeE,eC=l.S5A;l.BeE,l.iKM,l.r7h;let ez=l.cfM;l.fGe,l.uRq,l.PO3,l.Rgn,l.CJw;let e_=l.GaK;l.Inz,l.nAr;let eL=l.rfi,eB=l.FcF;l.eMl,l.dsN;let eS=l.i4r;l.aAq,l.Xrv,l.kJM,l._o1,l.nDN,l.MaT;let eA=l.Muk;l.ww9;let eP=l._32;l.Wj8,l.Fu6,l.WbR,l.A_r,l.Z98,l.Rd$,l.gvr;let eV=l.fRP;l.zr8,l.hq,l.zhn;let eH=l.ar0,eq=l.x6Z;l.yxg,l.PCg,l.pEE,l.ABT;let eF=l.MY7,eI=l.eJC;l.lSz,l.bPG,l.pR5,l.v2Q,l.NpQ,l.jqV,l.HZF,l.lE;let eE=l.lKS;l.rfH;let eO=l.D9k,eU=l.fn,eX=l.RKA;l.lIX;let eT=l.lIX("Warn"),eY=l.lIX("Error"),e$=(0,s.XY)(e=>b(e[0]),(e,...t)=>l.bUZ(e,x.iL,e=>{let a=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||y.x(a,t[0],t[1]),a}));l.gsV;let eG=(e,t,a)=>(...s)=>P(i=>{try{e(...s,(e,a)=>{e?i(q(t?t(e,s):e)):i(L(a))})}catch(e){i(a?q(a(e,s)):E(e))}}),eD=l.jkJ,eR=l.Z9x,eZ=l.q7Y,ej=l.Ab9;l.UVN;let eN=l.vCS},3811(e,t,a){var s=a(2449);a.d(t,{},{bp:e=>(0,s.yj)({op:e.label,[s._3]:e.evaluate})})},3332(e,t,a){var s=a(5033),i=a(5844),l=a(4233);let o="~effect/Equal";function r(){return 1==arguments.length?e=>n(e,arguments[0]):n(arguments[0],arguments[1])}function n(e,t){if(e===t)return!0;if(null==e||null==t)return!1;let a=typeof e;return a===typeof t&&("number"===a&&e!=e&&t!=t||!("object"!==a&&"function"!==a||i.J3.has(e)||i.J3.has(t))&&function(e,t){let a=d.length;for(let s=a;s-- >0;)if(d[s]===e&&p[s]===t)return!0;if(a)return c(e,t);let s=h.get(e);s||h.set(e,s=new WeakMap);let i=s.get(t);return void 0===i&&s.set(t,i=c(e,t)),i}(e,t))}function c(e,t){d.push(e),p.push(t);try{return function(e,t){if(s.tW(e)!==s.tW(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let a=e.getTime(),s=t.getTime();return a===s||Number.isNaN(a)&&Number.isNaN(s)}if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let a=v(e);if(a!==v(t)||"function"==typeof e&&!a)return!1;if(a)return e[o](t);if(Array.isArray(e))return!!Array.isArray(t)&&e.length===t.length&&function(e,t){for(let a=0;a<e.length;a++)if(!n(e[a],t[a]))return!1;return!0}(e,t);if(ArrayBuffer.isView(e)){let a=e instanceof DataView;return!!ArrayBuffer.isView(t)&&e.byteLength===t.byteLength&&a===t instanceof DataView&&(a?g((0,i.j)(e),(0,i.j)(t)):g(e,t))}if(e instanceof Map)return t instanceof Map&&e.size===t.size&&u(e,t,f,m);else if(e instanceof Set)return t instanceof Set&&e.size===t.size&&u(e,t,s.tW,n);var l=e,r=t;let c=(0,i.Xp)(l),d=(0,i.Xp)(r);if(c.size!==d.size)return!1;for(let e of c)if(!d.has(e)||!n(l[e],r[e]))return!1;return!0}(e,t)}finally{d.pop(),p.pop()}}let d=[],p=[],h=new WeakMap;function g(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}function u(e,t,a,s){let i=new Map;for(let e of t){let t=a(e),s=i.get(t);s?s.push(e):i.set(t,[e])}e:for(let t of e){let e=i.get(a(t));if(e){for(let a=0;a<e.length;a++)if(s(t,e[a])){e[a]=e[e.length-1],e.pop();continue e}}return!1}return!0}let f=e=>s.tW(e[0]),m=(e,t)=>n(e[0],t[0])&&n(e[1],t[1]),v=e=>(0,l.i5)(e,o);a.d(t,{aI:()=>r},{HR:o,Xq:e=>(i.J3.add(e),e),jI:()=>r})},7876(e,t,a){let s=e=>(t,a)=>t===a||e(t,a),i=(e,t)=>e===t,l=s((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t));function o(e){return s((t,a)=>{if(t.length!==a.length)return!1;for(let s=0;s<t.length;s++)if(!e[s](t[s],a[s]))return!1;return!0})}function r(e){return s((t,a)=>{if(t.length!==a.length)return!1;for(let s=0;s<t.length;s++)if(!e(t[s],a[s]))return!1;return!0})}function n(e){let t=Reflect.ownKeys(e);return s((a,s)=>{for(let i of t)if(!e[i](a[i],s[i]))return!1;return!0})}a.d(t,{O3:()=>r,_k:()=>n,rd:()=>o},{L8:s,Qw:i,YZ:()=>i,wN:l})},6526(e,t,a){var s=a(2449),i=a(6297);s.IH,s.b9;let l=s.xt,o=s.cb,r=s.Rk;s.V2,i._sz;let n=i.x5l,c=i.CoE,d=i.VE1;i._mh,i.YDM,i.lNM,i.K$2,i.GUt,i.HIt,i.yJo,i._OD,i.jCT,i.Wtn,i.v9O,i.zPu,i.EkE,i.Hox,i.ely,i.kMI,i.Sv3,i.lgw,a.d(t,{},{AT:o,N6:d,Py:l,fJ:r,oJ:c,rI:n})},1958(e,t,a){var s=a(4233),i=a(1279);function l(e,t){let a=t?.space??0,l=new WeakSet,n=a?"number"==typeof a?" ".repeat(a):a:"",p=(e,t)=>{let a=e?.constructor;return a&&a!==Object.prototype.constructor&&a.name?`${a.name}(${t})`:t};return function e(a,h=0){try{return function(a,h=0){if("string"==typeof a)return JSON.stringify(a);if("number"==typeof a||null==a||"boolean"==typeof a||"symbol"==typeof a)return String(a);if("bigint"==typeof a)return String(a)+"n";if("object"==typeof a||"function"==typeof a){let g;if(l.has(a))return o;if(l.add(a),i.uC in a)g=e((0,i.f6)(a),h);else if(Array.isArray(a)){let t,s;g=!n||a.length<=1?`[${a.map(t=>e(t,h)).join(",")}]`:`[
|
|
236
|
+
`)}},c=new Proxy(globalThis.console,{get(e,t,a){if("log"===t)return(...t)=>{(1!==t.length||""!==t[0])&&e.log(...t)};let s=Reflect.get(e,t,a);return"function"==typeof s?s.bind(e):s}}),pL(g9,{version:"0.25.2"})(e).pipe(X.sFT(e=>eu.i5(e,ru)&&"ShowHelp"!==e._tag?rh(n.formatErrors([e])):X.rIH),X.PfK(ch,{builtIns:[co,cr,cc]}),X.PfK(ni,n),X.PfK(rd,c))).pipe(X.khu({onFailure:e=>X.JkU(function*(){let t,a=ee.getOrUndefined(U.L$(e));if(a instanceof go)return a.exitCode;if(a instanceof sV)return 7;let s=function(e){if(eu.i5(e,ru))return"ShowHelp"===e._tag?2*(e.errors.length>0):2}(a);if(void 0!==s)return s;let i=yield*gl;return yield*i.stderr((t={code:"internal_error",message:"Sketchi could not complete the command.",hint:"Retry once; if it persists, report the command and inputs without secrets."},"json"===d?s4({ok:!1,command:"sketchi",error:t}):gc(t))).pipe(X.MfU(()=>X.rIH)),1}),onSuccess:()=>X.PyW(0)}))}),ut=j.Um(sP.Txp,(0,sP.rRT)({createId:e=>`${e}_offline_cli`,icons:lj})),ua=j.Gt(s9,ut),us=j.Gt(ih,ut),ui=j.Um(il,ll),ul=j.Gt(lm,ui),uo=j.Gt(lX,j.Um(ul,lI)),ur=j.Gt(gL,gk),un=j.Um(il,ll,ua,us,ul,uo,lI,ur,gz,im.pipe(j.Gt(il)),gn,rc),uc=j.S5(un,sA);Z(ue(process.argv.slice(2)).pipe(X.Mim(e=>X.OH5(()=>{process.exitCode=e})),X.Gte(uc)),{disableErrorReporting:!0})},1688(e,t,a){var s=a(2718);let i=s.xCb(["invalid_render_artifact","render_limit_exceeded","unsupported_render_glyph","rasterization_failed"]),l=s.xCb(["artifact","geometry","font","rasterization"]);class o extends s.rNF()("HeadlessPngRenderError",{cause:s.kld(),code:i,stage:l,message:s.QfV,details:s.O31(s.QfV)}){}a.d(t,{FG:()=>o})},5030(e,t,a){function s(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i(e,t,a,s){return{code:e,message:t,...void 0===a?{}:{observed:a},...void 0===s?{}:{limit:s}}}function l(e,t=0){let a=1/0,o=1/0,r=-1/0,n=-1/0;for(let t of e){if(!(s(t)&&"number"==typeof t.x&&Number.isFinite(t.x)&&"number"==typeof t.y&&Number.isFinite(t.y)&&"number"==typeof t.width&&Number.isFinite(t.width)&&"number"==typeof t.height&&Number.isFinite(t.height)))return i("invalid_geometry","element geometry is invalid");let e=Math.abs(t.width),l=Math.abs(t.height);if(e>8192||l>8192)return i("element_dimension",`element dimension exceeds ${String(8192)}`,Math.max(e,l),8192);let c=function(e){if(void 0!==e.angle&&0!==e.angle)return;let t=Array.isArray(e.points)?e.points.filter(e=>Array.isArray(e)&&"number"==typeof e[0]&&Number.isFinite(e[0])&&"number"==typeof e[1]&&Number.isFinite(e[1])):[],a=[e.x,e.x+e.width,...t.map(t=>e.x+t[0])],s=[e.y,e.y+e.height,...t.map(t=>e.y+t[1])];return{left:Math.min(...a),top:Math.min(...s),right:Math.max(...a),bottom:Math.max(...s)}}(t);if(c){a=Math.min(a,c.left),o=Math.min(o,c.top),r=Math.max(r,c.right),n=Math.max(n,c.bottom);continue}let d=Math.hypot(e,l)/2,p=t.x+t.width/2,h=t.y+t.height/2;a=Math.min(a,p-d),o=Math.min(o,h-d),r=Math.max(r,p+d),n=Math.max(n,h+d)}if(0===e.length)return;let c=r-a,d=n-o;if(c>8192||d>8192)return i("canvas_dimension",`canvas dimension exceeds ${String(8192)}`,Math.max(c,d),8192);let p=c*d;if(p>6291456)return i("canvas_area",`canvas area exceeds ${String(6291456)}`,p,6291456);let h=(c+40)*1*((d+40+t)*1);if(h>0x1800000)return i("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,h,0x1800000)}function o(e,t){let a=new Set(t.flatMap(e=>s(e)&&"image"===e.type&&!0!==e.isDeleted&&"string"==typeof e.fileId?[e.fileId]:[])),l=0;for(let t of a){let a=Object.hasOwn(e,t)?e[t]:void 0,i=s(a)?a.dataURL:void 0;"string"==typeof i&&(l+=i.length)}return l>8388608?i("file_bytes",`embedded image data exceeds ${String(8388608)} bytes`,l,8388608):void 0}function r(e,t=0){return l(e,t)?.message}function n(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return i("invalid_geometry","rendered SVG dimensions are invalid");let a=Math.min(2,16384/e,16384/t,Math.sqrt(0x1800000/(e*t)));if(a<1){let a=e*t;return a>0x1800000?i("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,a,0x1800000):i("output_dimension","rendered SVG dimension exceeds the PNG limit at minimum scale",Math.max(e,t),16384)}return Math.max(1,Math.floor(1e3*a)/1e3)}a.d(t,{Gd:()=>r,Ts:()=>l,Yu:()=>n,jA:()=>o},{Z4:6291456,ce:0x1800000})},6982(e){e.exports=t("crypto")},7598(e){e.exports=t("node:crypto")},76(e,t,a){let s=a(9095),i=process.env;function l(e){return"string"==typeof e?!!i[e]:"env"in e?i[e.env]&&i[e.env].includes(e.includes):"any"in e?e.any.some(function(e){return!!i[e]}):Object.keys(e).every(function(t){return i[t]===e[t]})}Object.defineProperty(t,"_vendors",{value:s.map(function(e){return e.constant})}),t.name=null,t.isPR=null,t.id=null,"false"!==i.CI&&s.forEach(function(e){let a=(Array.isArray(e.env)?e.env:[e.env]).every(function(e){return l(e)});t[e.constant]=a,a&&(t.name=e.name,t.isPR=function(e){switch(typeof e.pr){case"string":return!!i[e.pr];case"object":if("env"in e.pr)if("any"in e.pr)return e.pr.any.some(function(t){return i[e.pr.env]===t});else return e.pr.env in i&&i[e.pr.env]!==e.pr.ne;if("any"in e.pr)return e.pr.any.some(function(e){return!!i[e]});return l(e.pr);default:return null}}(e),t.id=e.constant)}),t.isCI=!!("false"!==i.CI&&(i.BUILD_ID||i.BUILD_NUMBER||i.CI||i.CI_APP_ID||i.CI_BUILD_ID||i.CI_BUILD_NUMBER||i.CI_NAME||i.CONTINUOUS_INTEGRATION||i.RUN_ID||t.name))},485(e,t,a){e.exports=a(76).isCI},664(e,t,a){a.d(t,{CN:()=>g,BC:()=>m,Ie:()=>z,pb:()=>B,i8:()=>k,g9:()=>b,Uk:()=>M,Ts:()=>u,CZ:()=>v,ET:()=>y,HV:()=>w,T9:()=>P,Tj:()=>L,YW:()=>f,of:()=>_,jB:()=>S,TS:()=>A,di:()=>C});var s=a(7876),i=a(1594);let l=e=>e.length>0;var o=a(9771),r=a(592),n=a(1587),c=a(2860),d=a(915),p=a(9315);let h=globalThis.Array,g=e=>new h(o.S(e)),u=e=>h.isArray(e)?e:h.from(e);d.Wo,n.toArray;let f=(0,i.XY)(2,(e,{onEmpty:t,onNonEmpty:a})=>y(e)?a(e):t()),m=(0,i.XY)(2,(e,t)=>[...e,t]);h.isArray;let v=l,y=l,w=e=>y(e)?n.some(x(e)):n.none(),x=e=>e[e.length-1],b=(0,i.XY)(2,(e,t)=>{let a=0;for(let s of e){if(t(s,a))return n.some(a);a++}return n.none()}),k=r.i8,M=(0,i.XY)(2,(e,t)=>{let a=u(e);for(let e=a.length-1;e>=0;e--){let s=a[e],i=t(s,e);if("boolean"==typeof i){if(i)return n.some(s)}else if(n.isSome(i))return i}return n.none()}),C=(0,i.XY)(2,(e,t)=>{let a=h.from(e);return a.sort(t),a}),z=()=>[],_=e=>[e],L=(0,i.XY)(2,(e,t)=>e.map(t)),B=(0,i.XY)(2,(e,t)=>{let a=u(e),s=[];for(let e=0;e<a.length;e++)t(a[e],e)&&s.push(a[e]);return s}),S=(0,i.XY)(2,(e,t)=>{let a=[],s=[],i=0;for(let l of e){let e=t(l,i++);p.oJ(e)?a.push(e.success):s.push(e.failure)}return[a,s]}),A=(0,i.XY)(3,(e,t,a)=>u(e).reduce((e,t,s)=>a(e,t,s),t));c.O3;let P=s.O3},5053(e,t,a){var s=a(9519),i=a(7876),l=a(1594),o=a(1587),r=a(2860),n=a(4233),c=a(636);let d=globalThis.BigInt,p=d(0);n.sI;let h=(0,l.XY)(2,(e,t)=>e+t),g=r.Qw,u=i.Qw,f=r.hl(g),m=r.bi(g),v=r.yJ(g),y=r.OW(g),w=r.Bt(g),x=r.qE(g),b=r.jk(g),k=r.T9(g),M=c.L((e,t)=>e+t,p),C=s.T9(g),z=s.jk(g);a.d(t,{},{K0:z,OW:y,Ro:e=>e>d(Number.MAX_SAFE_INTEGER)||e<d(Number.MIN_SAFE_INTEGER)?o.none():o.some(Number(e)),T9:k,Tq:w,aD:M,bi:m,cz:h,hl:f,jk:b,pH:g,qE:x,rs:u,sO:C,yJ:v})},3265(e,t,a){var s=a(5053),i=a(1587);let l=BigInt(0),o=BigInt(1),r=BigInt(1e3),n=BigInt(1024),c=[{symbol:"B",factor:o,names:["B","byte","bytes"]},{symbol:"kB",factor:r,names:["kB","kilobyte","kilobytes"]},{symbol:"MB",factor:r**BigInt(2),names:["MB","megabyte","megabytes"]},{symbol:"GB",factor:r**BigInt(3),names:["GB","gigabyte","gigabytes"]},{symbol:"TB",factor:r**BigInt(4),names:["TB","terabyte","terabytes"]},{symbol:"PB",factor:r**BigInt(5),names:["PB","petabyte","petabytes"]},{symbol:"EB",factor:r**BigInt(6),names:["EB","exabyte","exabytes"]},{symbol:"ZB",factor:r**BigInt(7),names:["ZB","zettabyte","zettabytes"]},{symbol:"YB",factor:r**BigInt(8),names:["YB","yottabyte","yottabytes"]},{symbol:"RB",factor:r**BigInt(9),names:["RB","ronnabyte","ronnabytes"]},{symbol:"QB",factor:r**BigInt(10),names:["QB","quettabyte","quettabytes"]}],d=[c[0],{symbol:"KiB",factor:n,names:["KiB","kibibyte","kibibytes"]},{symbol:"MiB",factor:n**BigInt(2),names:["MiB","mebibyte","mebibytes"]},{symbol:"GiB",factor:n**BigInt(3),names:["GiB","gibibyte","gibibytes"]},{symbol:"TiB",factor:n**BigInt(4),names:["TiB","tebibyte","tebibytes"]},{symbol:"PiB",factor:n**BigInt(5),names:["PiB","pebibyte","pebibytes"]},{symbol:"EiB",factor:n**BigInt(6),names:["EiB","exbibyte","exbibytes"]},{symbol:"ZiB",factor:n**BigInt(7),names:["ZiB","zebibyte","zebibytes"]},{symbol:"YiB",factor:n**BigInt(8),names:["YiB","yobibyte","yobibytes"]}],p=new Map([...c,...d.slice(1)].flatMap(e=>e.names.map(t=>[t,e]))),h=e=>{throw Error(`Invalid ByteSize: ${e}`)},g=e=>!Number.isSafeInteger(e)||e<0?h(`expected a non-negative safe integer, received ${e}`):BigInt(e),u=e=>{let t=/^\s*(\d+)(?:\.(\d+))?\s*([A-Za-z]+)\s*$/.exec(e);if(null===t)return h(`unsupported syntax ${JSON.stringify(e)}`);let a=p.get(t[3]);if(void 0===a)return h(`unsupported unit ${JSON.stringify(t[3])}`);let s=t[2]??"",i=BigInt(10)**BigInt(s.length),o=BigInt(t[1]+s)*a.factor;return o%i!==l?h(`${JSON.stringify(e)} does not represent an integral number of bytes`):o/i},f=i.liftThrowable(u),m=e=>{switch(typeof e){case"bigint":if(e<l)return h(`expected a non-negative bigint, received ${e}`);return e;case"number":return g(e);case"string":return u(e)}return h(`unsupported input ${e}`)},v=i.liftThrowable(m),y=s.Ro;s.pH,s.rs,s.Tq,s.jk,s.T9,s.qE,s.hl,s.bi,s.yJ,s.OW,s.cz,s.aD,s.sO,s.K0,a.d(t,{},{Dg:e=>e,Ro:y,bN:m,ee:e=>"bigint"==typeof e?m(e):g(e),lX:v,sH:f,yp:e=>"bigint"==typeof e&&e>=l})},719(e,t,a){var s=a(2449),i=a(6297);s.PX,s.B4,s.Aj,s.Wg;let l=s.lC;s.Xb,s.ik;let o=s.b5;s.DH;let r=s.OE,n=s.Iu;i.nIy,i.ORc;let c=i.nn5,d=i.O$X;s.h2;let p=i.ReC;i.myX,i.QE5,i.khU;let h=i.L$u;i.gpn,i.k7S,i.BbX;let g=i.prj;i.tU5,i.h74,i.Bou,i.RJ6;let u=i.GyP;s.PW,s.qB,s.Xm;let f=s.$L;s.q_;let m=s.RS,v=s.Vw;i.DQo,i.c8t,i.MUS,i.t8c,i._y;let y=i.qwd;i.ASO,i.F7W,i.Aub,i.cOF,i.Rft,i.RD4,i.Kkt,i.PnV;let w=i.Bk6;s.Eh,i.tQ6,i.On5,a.d(t,{},{$L:f,Bk:w,F_:n,L$:h,RS:m,Tj:d,Vw:v,fJ:r,iw:p,j9:u,kO:o,lC:l,nn:c,pr:g,qw:y})},4238(e,t,a){var s=a(6297);s.a1U,s.RKA;let i=s.Rud;s.s0X,s.T13,a.d(t,{},{Ru:i})},9519(e,t,a){function s(e){return{combine:e}}function i(e){return s((t,a)=>-1===e(t,a)?t:a)}function l(e){return s((t,a)=>1===e(t,a)?t:a)}a.d(t,{L8:()=>s,T9:()=>l,jk:()=>i})},1179(e,t,a){var s=a(3811),i=a(3332),l=a(1594),o=a(5033),r=a(2449),n=a(1587),c=a(4233);let d="~effect/Context/Service",p=function(){let e=function(){};Object.setPrototypeOf(e,h);let t=(t,a)=>(e.key=t,a?.defaultValue&&(e[u]=u,e.defaultValue=a.defaultValue),a?.make&&(e.make=a.make),a?.fiberCached&&g.add(t),e);return arguments.length>0?t(arguments[0],arguments[1]):t},h={[d]:d,...s.bp({label:"Service",evaluate(e){return(0,r.xt)(V(e.context,this))}}),toJSON(){return{_id:"Service",key:this.key}},of:e=>e,context(e){return _(this,e)},use(e){return(0,r.R6)(t=>e(V(t.context,this)))},useSync(e){return(0,r.R6)(t=>(0,r.xt)(e(V(t.context,this))))}},g=new Set,u="~effect/Context/Reference",f="~effect/Context",m=(e,t,a,s)=>{let i=Object.create(k);return i.cacheRoot=e??i,i.base=t,i.overlay=a,i.depth=s,i._flat=void 0,i.baseHits=0,i},v=(e,t)=>{t&&(v(e,t.parent),e.set(t.key,t.value))},y=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return v(t,e.overlay),e._flat=t},w=Symbol(),x=(e,t)=>{for(let a=e.overlay;a;a=a.parent)if(a.key===t)return a.value;let a=e.base.get(t);return void 0!==a||e.base.has(t)?(e.overlay&&++e.baseHits>=e.base.size&&e.baseHits>=8&&(e.base=y(e),e.overlay=void 0,e.depth=0),a):w},b=e=>m(void 0,e,void 0,0),k={get mapUnsafe(){return y(this)},...r.fU,[f]:{_Services:e=>e},toJSON(){return{_id:"Context",services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[i.HR](e){if(!M(e))return!1;let t=this.mapUnsafe,a=e.mapUnsafe;if(t.size!==a.size)return!1;for(let[e,s]of t)if(!a.has(e)||!i.aI(s,a.get(e)))return!1;return!0},[o.HR](){return o.ai(this.mapUnsafe.size)}},M=e=>(0,c.i5)(e,f),C=e=>!!e[u],z=b(new Map),_=(e,t)=>b(new Map([[e.key,t]])),L=(0,l.XY)(3,(e,t,a)=>B(e,t.key,a)),B=(e,t,a)=>{let s=g.has(t)?void 0:e.cacheRoot;if(e.depth>=8){let i=new Map(e.mapUnsafe);return i.set(t,a),m(s,i,void 0,0)}return m(s,e.base,{key:t,value:a,parent:e.overlay},e.depth+1)},S=(0,l.XY)(2,(e,t)=>A(e,t.key)),A=(e,t)=>{let a=x(e,t);return a===w?void 0:a},P=(0,l.XY)(2,(e,t)=>{let a=x(e,t.key);if(a===w){if(C(t))return q(t);throw F(t)}return a}),V=P,H="~effect/Context/defaultValue",q=e=>H in e?e[H]:e[H]=e.defaultValue(),F=e=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:""}`);if(t.stack){let e=t.stack.split("\n");e.splice(1,3),t.stack=e.join("\n")}return t},I=(0,l.XY)(2,(e,t)=>{let a=x(e,t.key);return a!==w?n.some(a):C(t)?n.some(q(t)):n.none()}),E=(0,l.XY)(2,(e,t)=>{let a;return 0===e.mapUnsafe.size?t:0===t.mapUnsafe.size?e:((e=>t.mapUnsafe.forEach((t,a)=>e.set(a,t)))(a=new Map(e.mapUnsafe)),b(a))});a.d(t,{},{Ie:()=>z,Jt:V,L8:_,LZ:b,Or:p,Pf:(e,t)=>e.cacheRoot===t.cacheRoot,Ub:A,Um:(...e)=>{let t=new Map;for(let a=0;a<e.length;a++)e[a].mapUnsafe.forEach((e,a)=>{t.set(a,e)});return b(t)},WQ:L,Y6:S,aE:M,fp:P,h1:E,kl:p,om:I})},4942(e,t,a){var s=a(2449),i=a(2275),l=a(1554),o=a(4233);let r=class extends l.Xs{constructor(e){super(),e&&i.z(this,e)}};function n(){if(1==arguments.length){let e=arguments[0];return function(t){return e[t._tag](t)}}let e=arguments[0],t=arguments[1];return t[e._tag](e)}let c=s.$D,d=s.rN;a.d(t,{},{$D:c,Ij:()=>new Proxy({},{get:(e,t,a)=>"$is"===t?o.$J:"$match"===t?n:e=>({...e,_tag:t})}),Xs:r,rN:d})},9237(e,t,a){var s=a(1594),i=a(6297),l=a(1554);let o={"~effect/Deferred":{_A:s.D_,_E:s.D_},pipe(){return(0,l.tT)(this,arguments)}},r=function(){this.resumes=void 0,this.effect=void 0};r.prototype=o;let n=e=>void 0!==e.effect;a.d(t,{},{$L:e=>i.OH5(()=>n(e)),$w:(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let a=e.resumes;e.resumes=void 0;for(let e=0;e<a.length;e++)a[e](t)}return!0},LZ:()=>new r,NJ:n,Tx:e=>i.E2r(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),i.OH5(()=>{let a=e.resumes;if(void 0===a)return;let s=a.indexOf(t);s>=0&&a.splice(s,1)})))})},3614(e,t,a){var s=a(3332),i=a(1594),l=a(5033),o=a(3952),r=a(2860),n=a(1554),c=a(4233);let d="~effect/Duration",p=BigInt(0),h=BigInt(1),g=BigInt(2),u=BigInt(10),f=BigInt(24),m=BigInt(60),v=BigInt(1e3),y=BigInt(1e6),w=e=>BigInt(e<0?Math.ceil(e-.5):Math.floor(e+.5)),x=(e,t)=>{let a=e.indexOf(".");if(-1===a)return BigInt(e)*t;let s="-"===e[0],i=e.slice(a+1),l=u**BigInt(i.length),o=(BigInt(e.slice(+!!s,a))*l+BigInt(i))*t,r=o/l+(o%l*g>=l?h:p);return s?-r:r},b=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,k=e=>{switch(typeof e){case"number":return q(e);case"bigint":return H(e);case"string":{if("Infinity"===e)return P;if("-Infinity"===e)return V;let t=b.exec(e);if(!t)break;let[a,s,i]=t;if("nano"===i||"nanos"===i)return H(x(s,h));if("micro"===i||"micros"===i)return H(x(s,v));let l=Number(s);switch(i){case"milli":case"millis":return q(l);case"second":case"seconds":return F(l);case"minute":case"minutes":return I(l);case"hour":case"hours":return E(l);case"day":case"days":return O(l);case"week":case"weeks":return U(l)}break}case"object":{if(null===e)break;if(d in e)return e;if(Array.isArray(e)){if(2!==e.length||!e.every(c.Et))return M(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return A;if(-1/0===e[0]||-1/0===e[1])return V;if(1/0===e[0]||1/0===e[1])return P;return B(w(1e9*e[0]+e[1]))}let t=0;if(e.weeks&&(t+=6048e5*e.weeks),e.days&&(t+=864e5*e.days),e.hours&&(t+=36e5*e.hours),e.minutes&&(t+=6e4*e.minutes),e.seconds&&(t+=1e3*e.seconds),e.milliseconds&&(t+=e.milliseconds),!e.microseconds&&!e.nanoseconds)return B(t);return B(w(1e6*t+(e.microseconds??0)*1e3+(e.nanoseconds??0)))}}return M(e)},M=e=>{throw Error(`Invalid Input: ${e}`)},C={_tag:"Millis",millis:0},z={_tag:"Infinity"},_={_tag:"NegativeInfinity"},L={[d]:d,[l.HR](){switch(this.value._tag){case"Millis":{let e=1e6*this.value.millis;return Number.isFinite(e)?l.tW(w(e)):l.ai(this.value.millis)}case"Nanos":return l.tW(this.value.nanos);default:return l.QK(this.value)}},[s.HR](e){return S(e)&&D(this,e)},toString(){switch(this.value._tag){case"Infinity":return"Infinity";case"NegativeInfinity":return"-Infinity";case"Nanos":return`${this.value.nanos} nanos`;case"Millis":return`${this.value.millis} millis`}},toJSON(){switch(this.value._tag){case"Millis":return{_id:"Duration",_tag:"Millis",millis:this.value.millis};case"Nanos":return{_id:"Duration",_tag:"Nanos",nanos:String(this.value.nanos)};case"Infinity":return{_id:"Duration",_tag:"Infinity"};case"NegativeInfinity":return{_id:"Duration",_tag:"NegativeInfinity"}}},[o.FX](){return this.toJSON()},pipe(){return(0,n.tT)(this,arguments)}},B=e=>{let t=Object.create(L);return"number"==typeof e?isNaN(e)||0===e||Object.is(e,-0)?t.value=C:Number.isFinite(e)?Number.isInteger(e)?t.value={_tag:"Millis",millis:e}:t.value={_tag:"Nanos",nanos:w(1e6*e)}:t.value=e>0?z:_:e===p?t.value=C:t.value={_tag:"Nanos",nanos:e},t},S=e=>(0,c.i5)(e,d),A=B(0),P=B(1/0),V=B(-1/0),H=e=>B(e),q=e=>B(e),F=e=>B(1e3*e),I=e=>B(6e4*e),E=e=>B(36e5*e),O=e=>B(864e5*e),U=e=>B(6048e5*e),X=e=>{let t=k(e);switch(t.value._tag){case"Infinity":case"NegativeInfinity":throw Error("Cannot convert infinite duration to nanos");case"Nanos":return t.value.nanos;case"Millis":return w(1e6*t.value.millis)}},T=(0,i.XY)(2,(e,t)=>{switch(e.value._tag){case"Millis":return t.onMillis(e.value.millis);case"Nanos":return t.onNanos(e.value.nanos);case"Infinity":return t.onInfinity();case"NegativeInfinity":return(t.onNegativeInfinity??t.onInfinity)()}}),Y=(0,i.XY)(3,(e,t,a)=>"Infinity"===e.value._tag||"NegativeInfinity"===e.value._tag||"Infinity"===t.value._tag||"NegativeInfinity"===t.value._tag?a.onInfinity(e,t):"Millis"===e.value._tag?"Millis"===t.value._tag?a.onMillis(e.value.millis,t.value.millis):a.onNanos(X(e),t.value.nanos):a.onNanos(e.value.nanos,X(t))),$=r.L8((e,t)=>Y(e,t,{onMillis:(e,t)=>e<t?-1:+(e>t),onNanos:(e,t)=>e<t?-1:+(e>t),onInfinity:(e,t)=>e.value._tag===t.value._tag?0:"Infinity"===e.value._tag?1:"NegativeInfinity"===e.value._tag||"Infinity"===t.value._tag?-1:1})),G=r.bi($),D=(0,i.XY)(2,(e,t)=>Y(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag})),R=e=>{if("Infinity"===e.value._tag)return"Infinity";if("NegativeInfinity"===e.value._tag)return"-Infinity";if((e=>{switch(e.value._tag){case"Millis":return 0===e.value.millis;case"Nanos":return e.value.nanos===p;case"Infinity":case"NegativeInfinity":return!1}})(e))return"0";if((e=>{switch(e.value._tag){case"Millis":return e.value.millis<0;case"Nanos":return e.value.nanos<p;case"NegativeInfinity":return!0;case"Infinity":return!1}})(e))return"-"+R((e=>{switch(e.value._tag){case"Infinity":case"NegativeInfinity":return P;case"Millis":return e.value.millis<0?B(-e.value.millis):e;case"Nanos":return e.value.nanos<p?B(-e.value.nanos):e}})(e));let t=(e=>{if("Infinity"===e.value._tag)return{days:1/0,hours:1/0,minutes:1/0,seconds:1/0,millis:1/0,nanos:1/0};if("NegativeInfinity"===e.value._tag)return{days:-1/0,hours:-1/0,minutes:-1/0,seconds:-1/0,millis:-1/0,nanos:-1/0};let t=X(e),a=t<p,s=a?-t:t,i=s/y,l=i/v,o=l/m,r=o/m,n=a?-1:1;return{days:n*Number(r/f),hours:n*Number(r%f),minutes:n*Number(o%m),seconds:n*Number(l%m),millis:n*Number(i%v),nanos:n*Number(s%y)}})(e),a=[];return 0!==t.days&&a.push(`${t.days}d`),0!==t.hours&&a.push(`${t.hours}h`),0!==t.minutes&&a.push(`${t.minutes}m`),0!==t.seconds&&a.push(`${t.seconds}s`),0!==t.millis&&a.push(`${t.millis}ms`),0!==t.nanos&&a.push(`${t.nanos}ns`),a.join(" ")};a.d(t,{},{GP:R,MI:e=>"Infinity"!==e.value._tag&&"NegativeInfinity"!==e.value._tag,Tn:P,YA:F,bN:k,bi:G,cF:H,fP:e=>T(k(e),{onMillis:e=>e/1e3,onNanos:e=>Number(e)/1e9,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),kE:e=>T(k(e),{onMillis:i.D_,onNanos:e=>Number(e)/1e6,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),n$:S,ne:q,qv:V,v_:A})},2842(e,t,a){a.d(t,{Q56:()=>ex,jGc:()=>eb,U9h:()=>ek,Q7R:()=>k,hgn:()=>Y,swY:()=>e$,Muk:()=>eA,as:()=>j,E2r:()=>P,MfU:()=>N,Tyx:()=>K,osR:()=>Q,KuX:()=>W,loE:()=>J,RKA:()=>eX,_32:()=>eP,F_Q:()=>E,_r7:()=>eG,yeE:()=>eM,NS5:()=>R,fJG:()=>q,ATB:()=>F,pVV:()=>I,qIB:()=>T,Ab9:()=>ej,fn:()=>eU,D9k:()=>eO,vCS:()=>eN,jJl:()=>M,i4r:()=>eS,ar0:()=>eH,x6Z:()=>eq,yUA:()=>X,JkU:()=>H,XeO:()=>el,GaK:()=>e_,yw5:()=>b,vVN:()=>eY,FFw:()=>eT,TjK:()=>Z,q7Y:()=>eZ,jkJ:()=>eD,xm_:()=>ee,Z9x:()=>eR,YWq:()=>ed,khu:()=>ep,tvg:()=>eh,ZmZ:()=>V,S5A:()=>eC,cfM:()=>ez,uKv:()=>D,QgK:()=>et,ivC:()=>z,Gte:()=>eg,PpN:()=>eu,PfK:()=>em,KT6:()=>ec,Ket:()=>G,L5P:()=>ei,MY7:()=>eF,eJC:()=>eI,lKS:()=>eE,z8E:()=>ev,P1j:()=>ey,Pxi:()=>ew,Nav:()=>ef,yy4:()=>en,PyW:()=>L,DYE:()=>B,OH5:()=>S,Mim:()=>$,dGm:()=>es,sFT:()=>ea,wRz:()=>eo,mgX:()=>er,SvU:()=>O,$mh:()=>_,rfi:()=>eL,FcF:()=>eB,rIH:()=>A,iMI:()=>C,R6R:()=>U,fRP:()=>eV});var s=a(1594),i=a(2449),l=a(6297),o=(a(3614),a(1179));a(9315);var r=a(6771),n=a(5633);let c=(0,s.XY)(e=>(0,i.yw)(e[0]),(e,t,a)=>{let s;return o.aE(t)?l.PpN(e,t):(s=Array.isArray(t)?n.Um(...t):t,l.Pxi(t=>l.qIB(a?.local?n.H7(s,n.j6(),t):n.LT(s,t),t=>l.PpN(e,t))))});var d=a(1587),p=a(3753),h=a(6481);(e,t,a)=>l.qIB(r.xn(t),t=>{let s=r.d3.defaultValue();return l.h_t(l.i4r(l.Mim(l.qIB(l.DYE(()=>l.PfK(e,r.d3,s)),t),e=>l.OH5(()=>{s=e})),{disableYield:!0}),e=>i.$L(e)?l.PyW(e.value):a(e,0===s.attempt?d.none():d.some(s)))});let g=(0,s.XY)(3,(e,t,a)=>l.qIB(r.xn(t),t=>{let s,i=r.d3.defaultValue(),o=l.h_t(l.DYE(()=>l.PfK(e,r.d3,i)),e=>(s=e,l.qIB(t(e),e=>(i=e,o))));return p.m8(o,e=>(0,h.s)(()=>a(s,e)))})),u=(0,s.XY)(2,(e,t)=>g(e,"function"==typeof t?t(s.D_):r.GM(t)?t:m(t),l.fJG)),f=r.le(r.i4),m=e=>{let t=e.schedule?r.le(e.schedule):f;return e.while&&(t=r.E6(t,({input:t})=>{let a=e.while(t);return i.yw(a)?a:l.PyW(a)})),e.until&&(t=r.E6(t,({input:t})=>{let a=e.until(t);return i.yw(a)?l.TjK(a,e=>!e):l.PyW(!a)})),void 0!==e.times&&(t=r.E6(t,({attempt:t})=>l.PyW(t<=e.times))),t},v=r.t5(1);var y=a(2275);let w=a(3332).Xq({_E:e=>e,_A:e=>e,_R:e=>e});({...i.In,"~effect/Request":w}),a(3909);var x=a(4600);i.$n;let b=i.yw,k=l.Q7R;l.jBG,l.TSs,l.tfT,l.i8i,l.kAe;let M=l.jJl;l.d5f;let C=l.iMI,z=l.ivC,_=l.$mh,L=l.PyW;l.lwU,l.nGE;let B=l.DYE,S=l.OH5,A=l.rIH;l.Vxk;let P=l.E2r,V=l.ZmZ;l.Do,l.JrD,l.uVU,l.oIE;let H=l.JkU,q=l.fJG;l.gOk;let F=l.ATB,I=l.pVV,E=l.F_Q,O=l.SvU;l.m9E,l.KN3;let U=i.R6;i.Hq;let X=l.yUA;l.sVm,l.pkL,l.bJ;let T=l.qIB;l.Bqz;let Y=l.hgn,$=l.Mim,G=l.Ket,D=l.uKv,R=l.NS5,Z=l.TjK,j=l.as;l.Xx$,l.NLW,l.UUz,l.yU6,l.OYO;let N=l.h_t,W=l.KuX,J=l.loE;l.AXC,l.zt4,l.scW;let K=l.Tyx;l.Fig,l.XWm;let Q=l.osR;l.U9Y,l.sJf,l.rNk;let ee=l.xm_;l.UcN;let et=l.QgK,ea=l.sFT;l.k$L;let es=l.dGm;l.cA6,l.bKC,l.nAi,l.u4Y;let ei=u;l._Sg;let el=l.XeO;l.GrF,l.$$g,l.DM4,l.Dd;let eo=l.wRz;l.D52;let er=l.mgX;l.cbG;let en=l.yy4;l.ayu,l.Vdx,l.FfP,l.O4F;let ec=l.KT6;l.pbD,l.x1Q,l.E8K,l.Pm0,l.VtY,l.W$I,l.ahH,l.z7s;let ed=l.YWq;l.G$Q,l.D$$,l.NZb,l.wR5;let ep=l.khu,eh=l.tvg;l.N6O,l.oJd,l._OA,l.sxi;let eg=c,eu=l.PpN;l.oao,l.euC;let ef=l.Nav;l.r_d,l.bUZ,l.L_I;let em=l.PfK;l.c7E;let ev=l.z8E,ey=l.P1j,ew=l.Pxi,ex=l.Q56;l.N24;let eb=l.jGc,ek=l.U9h,eM=l.yeE,eC=l.S5A;l.BeE,l.iKM,l.r7h;let ez=l.cfM;l.fGe,l.uRq,l.PO3,l.Rgn,l.CJw;let e_=l.GaK;l.Inz,l.nAr;let eL=l.rfi,eB=l.FcF;l.eMl,l.dsN;let eS=l.i4r;l.aAq,l.Xrv,l.kJM,l._o1,l.nDN,l.MaT;let eA=l.Muk;l.ww9;let eP=l._32;l.Wj8,l.Fu6,l.WbR,l.A_r,l.Z98,l.Rd$,l.gvr;let eV=l.fRP;l.zr8,l.hq,l.zhn;let eH=l.ar0,eq=l.x6Z;l.yxg,l.PCg,l.pEE,l.ABT;let eF=l.MY7,eI=l.eJC;l.lSz,l.bPG,l.pR5,l.v2Q,l.NpQ,l.jqV,l.HZF,l.lE;let eE=l.lKS;l.rfH;let eO=l.D9k,eU=l.fn,eX=l.RKA;l.lIX;let eT=l.lIX("Warn"),eY=l.lIX("Error"),e$=(0,s.XY)(e=>b(e[0]),(e,...t)=>l.bUZ(e,x.iL,e=>{let a=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||y.x(a,t[0],t[1]),a}));l.gsV;let eG=(e,t,a)=>(...s)=>P(i=>{try{e(...s,(e,a)=>{e?i(q(t?t(e,s):e)):i(L(a))})}catch(e){i(a?q(a(e,s)):E(e))}}),eD=l.jkJ,eR=l.Z9x,eZ=l.q7Y,ej=l.Ab9;l.UVN;let eN=l.vCS},3811(e,t,a){var s=a(2449);a.d(t,{},{bp:e=>(0,s.yj)({op:e.label,[s._3]:e.evaluate})})},3332(e,t,a){var s=a(5033),i=a(5844),l=a(4233);let o="~effect/Equal";function r(){return 1==arguments.length?e=>n(e,arguments[0]):n(arguments[0],arguments[1])}function n(e,t){if(e===t)return!0;if(null==e||null==t)return!1;let a=typeof e;return a===typeof t&&("number"===a&&e!=e&&t!=t||!("object"!==a&&"function"!==a||i.J3.has(e)||i.J3.has(t))&&function(e,t){let a=d.length;for(let s=a;s-- >0;)if(d[s]===e&&p[s]===t)return!0;if(a)return c(e,t);let s=h.get(e);s||h.set(e,s=new WeakMap);let i=s.get(t);return void 0===i&&s.set(t,i=c(e,t)),i}(e,t))}function c(e,t){d.push(e),p.push(t);try{return function(e,t){if(s.tW(e)!==s.tW(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let a=e.getTime(),s=t.getTime();return a===s||Number.isNaN(a)&&Number.isNaN(s)}if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let a=v(e);if(a!==v(t)||"function"==typeof e&&!a)return!1;if(a)return e[o](t);if(Array.isArray(e))return!!Array.isArray(t)&&e.length===t.length&&function(e,t){for(let a=0;a<e.length;a++)if(!n(e[a],t[a]))return!1;return!0}(e,t);if(ArrayBuffer.isView(e)){let a=e instanceof DataView;return!!ArrayBuffer.isView(t)&&e.byteLength===t.byteLength&&a===t instanceof DataView&&(a?g((0,i.j)(e),(0,i.j)(t)):g(e,t))}if(e instanceof Map)return t instanceof Map&&e.size===t.size&&u(e,t,f,m);else if(e instanceof Set)return t instanceof Set&&e.size===t.size&&u(e,t,s.tW,n);var l=e,r=t;let c=(0,i.Xp)(l),d=(0,i.Xp)(r);if(c.size!==d.size)return!1;for(let e of c)if(!d.has(e)||!n(l[e],r[e]))return!1;return!0}(e,t)}finally{d.pop(),p.pop()}}let d=[],p=[],h=new WeakMap;function g(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}function u(e,t,a,s){let i=new Map;for(let e of t){let t=a(e),s=i.get(t);s?s.push(e):i.set(t,[e])}e:for(let t of e){let e=i.get(a(t));if(e){for(let a=0;a<e.length;a++)if(s(t,e[a])){e[a]=e[e.length-1],e.pop();continue e}}return!1}return!0}let f=e=>s.tW(e[0]),m=(e,t)=>n(e[0],t[0])&&n(e[1],t[1]),v=e=>(0,l.i5)(e,o);a.d(t,{aI:()=>r},{HR:o,Xq:e=>(i.J3.add(e),e),jI:()=>r})},7876(e,t,a){let s=e=>(t,a)=>t===a||e(t,a),i=(e,t)=>e===t,l=s((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t));function o(e){return s((t,a)=>{if(t.length!==a.length)return!1;for(let s=0;s<t.length;s++)if(!e[s](t[s],a[s]))return!1;return!0})}function r(e){return s((t,a)=>{if(t.length!==a.length)return!1;for(let s=0;s<t.length;s++)if(!e(t[s],a[s]))return!1;return!0})}function n(e){let t=Reflect.ownKeys(e);return s((a,s)=>{for(let i of t)if(!e[i](a[i],s[i]))return!1;return!0})}a.d(t,{O3:()=>r,_k:()=>n,rd:()=>o},{L8:s,Qw:i,YZ:()=>i,wN:l})},6526(e,t,a){var s=a(2449),i=a(6297);s.IH,s.b9;let l=s.xt,o=s.cb,r=s.Rk;s.V2,i._sz;let n=i.x5l,c=i.CoE,d=i.VE1;i._mh,i.YDM,i.lNM,i.K$2,i.GUt,i.HIt,i.yJo,i._OD,i.jCT,i.Wtn,i.v9O,i.zPu,i.EkE,i.Hox,i.ely,i.kMI,i.Sv3,i.lgw,a.d(t,{},{AT:o,N6:d,Py:l,fJ:r,oJ:c,rI:n})},1958(e,t,a){var s=a(4233),i=a(1279);function l(e,t){let a=t?.space??0,l=new WeakSet,n=a?"number"==typeof a?" ".repeat(a):a:"",p=(e,t)=>{let a=e?.constructor;return a&&a!==Object.prototype.constructor&&a.name?`${a.name}(${t})`:t};return function e(a,h=0){try{return function(a,h=0){if("string"==typeof a)return JSON.stringify(a);if("number"==typeof a||null==a||"boolean"==typeof a||"symbol"==typeof a)return String(a);if("bigint"==typeof a)return String(a)+"n";if("object"==typeof a||"function"==typeof a){let g;if(l.has(a))return o;if(l.add(a),i.uC in a)g=e((0,i.f6)(a),h);else if(Array.isArray(a)){let t,s;g=!n||a.length<=1?`[${a.map(t=>e(t,h)).join(",")}]`:`[
|
|
237
237
|
${t=h+1,n.repeat(t)}${a.map(t=>e(t,h+1)).join(",\n"+(s=h+1,n.repeat(s)))}
|
|
238
238
|
${n.repeat(h)}]`}else if(a instanceof Date)g=c(a);else if(!t?.ignoreToString&&s.i5(a,"toString")&&"function"==typeof a.toString&&a.toString!==Object.prototype.toString&&a.toString!==Array.prototype.toString){let t=function(e){try{let t=e.toString();return"string"==typeof t?t:String(t)}catch{return"[toString threw]"}}(a);g=a instanceof Error&&void 0!==a.cause?`${t} (cause: ${e(a.cause,h)})`:t}else if(Symbol.iterator in a)g=`${a.constructor.name}(${e(Array.from(a),h)})`;else{let t=(e=>{try{return Reflect.ownKeys(e)}catch{return["[ownKeys threw]"]}})(a);if(!n||t.length<=1){let s=`{${t.map(t=>`${r(t)}:${e(d(a,t),h)}`).join(",")}}`;g=p(a,s)}else{let s=`{
|
|
239
239
|
${t.map(t=>{let s;return`${s=h+1,n.repeat(s)}${r(t)}: ${e(d(a,t),h+1)}`}).join(",\n")}
|
|
@@ -245,7 +245,7 @@ ${ev(e.cause," ")}
|
|
|
245
245
|
}`:e.stack,ev=(e,t)=>{let a=e.stack.split("\n"),s=`${t}[cause]: ${a[0]}`;for(let e=1,i=a.length;e<i;e++)s+=`
|
|
246
246
|
${t}${a[e]}`;return e.cause&&(s+=` {
|
|
247
247
|
${ev(e.cause,`${t} `)}
|
|
248
|
-
${t}}`),s},ey="~effect/Fiber",ew={_A:v.D_,_E:v.D_},ex={id:0},eb=(()=>{try{return globalThis.process?.getBuiltinModule?.("node:async_hooks")?.AsyncResource}catch{return}})(),ek=()=>void 0===eb?void 0:new eb("effect/Fiber"),eM=()=>globalThis[B.fL];class eC{constructor(e,t=!0){this.setContext(e),this.id=++ex.id,this.currentOpCount=0,this.interruptible=t,this._stack=[],this._observers=void 0,this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0,this._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this._asyncContext=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}get[ey](){return ew}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return u.Jt(this.context,e)}addObserver(e){return this._exit?(e(this._exit),v.Yi):(void 0===this._observers?this._observers=[e]:this._observers.push(e),()=>this.removeObserver(e))}removeObserver(e){if(this._exit||void 0===this._observers)return;let t=this._observers.indexOf(e);t>=0&&this._observers.splice(t,1)}interruptUnsafe(e,t){if(this._exit)return;let a=$(e);this.cache.stackFrame&&(a=(0,V.Eh)(a,u.L8(V.z8,this.cache.stackFrame))),t&&(a=(0,V.Eh)(a,t)),this._interruptedCause=this._interruptedCause?(0,V.h2)(this._interruptedCause,a):a,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(eX(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(void 0!==this._asyncContext){let t=this._asyncContext;return this._asyncContext=void 0,t.runInAsyncScope(this.evaluate,this,e)}if(void 0!==this._yielded){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===V.GN){this._asyncContext=ek();return}let a=eB.interruptChildren&&eB.interruptChildren(this);if(void 0!==a)return this.evaluate(tV(a,()=>t));if(this._exit=t,this.cache.runtimeMetrics?.recordFiberEnd(this.context,this._exit),this._parent&&(this._parent._children?.delete(this),this._parent=void 0),void 0!==this._observers){let e=this._observers;this._observers=void 0;for(let a=0;a<e.length;a++)e[a](t)}this._stack.length=0,this._children=void 0,this.context=u.Ie()}runLoop(e){let t=globalThis[B.fL];globalThis[B.fL]=this;let a=this._running;this._running=!0;let s=!1,i=e;this.currentOpCount=0;try{for(;;){this._deferredInterrupt&&(this._deferredInterrupt=!1,i=eX(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!s&&!e.preventYield&&e.scheduler.shouldYield(this)){s=!0;let e=i;i=tV(ej,()=>e)}if((i=e.tracerContext?e.tracerContext(i,this):i[V._3](this))===V.GN){let e=this._yielded;if(V.IH in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return V.GN}}}catch(e){if(!(0,w.i5)(i,V._3))return(0,V.V2)(`Fiber.runLoop: Not a valid effect: ${String(i)}`);return this.runLoop((0,V.V2)(e))}finally{this._running=a,globalThis[B.fL]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,e_;for(;;){let t=this._stack.pop();if(!t)return;let a=t[V.u4];if(void 0!==a){let s=a.call(t,this);if(s)return s[e]=s,s}if(t[e])return t}}succeedWith(e){if((++this.currentOpCount&eL-1)==0)return(0,V.xt)(e);let t=this.getCont(V.ee);return t?t[V.ee](e,this):this.yieldWith((0,V.xt)(e))}yieldWith(e){return this._yielded=e,V.GN}children(){return this._children??=new Set}pipe(){return(0,L.tT)(this,arguments)}setContext(e){let t=this.context;if(this.context=e,void 0!==t&&u.Pf(t,e))return;let a=e.cacheRoot,s=a._fiberCache??=ez(e);this.cache?.scheduler!==s.scheduler&&(this._dispatcher=void 0),this.cache=s}get currentSpanLocal(){let e=this.cache.span;return e?._tag==="Span"?e:void 0}}let ez=e=>{let t=u.Ub(e,A.RL);return{scheduler:u.Jt(e,S._F),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:u.Jt(e,I.rf),span:u.Ub(e,A.WG),logLevel:u.Jt(e,I.Gl),minimumLogLevel:u.Jt(e,I.zQ),stackFrame:u.Jt(e,I.vA),runtimeMetrics:u.Ub(e,q.F),maxOpsBeforeYield:u.Jt(e,S.Zm),preventYield:u.Jt(e,S.hf)}},e_={[V.ee]:(e,t)=>eX(t._interruptedCause),[V.Sc]:(e,t)=>eX(t._interruptedCause)},eL=32,eB={interruptChildren:void 0},eS=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(V.QJ.key,e.cache.stackFrame),u.LZ(t)},eA=e=>{if(void 0!==e._children&&0!==e._children.size)return eE(e._children)},eP=e=>e._exit?eU(e._exit):te(t=>e._exit?t(eU(e._exit)):eY(e.addObserver(e=>t(eU(e))))),eV=e=>te(t=>{let a,s=e[Symbol.iterator](),i=[];return!function e(){let l=s.next();for(;!l.done;){if(l.value._exit){i.push(l.value._exit),l=s.next();continue}a=l.value.addObserver(t=>{i.push(t),e()});return}t(eU(i))}(),eY(()=>a?.())}),eH=e=>e._exit?e._exit:te(t=>e._exit?t(e._exit):eY(e.addObserver(t))),eq=e=>te(t=>{let a=Array.from(e);if(0===a.length)return t(eU(g.Ie()));let s=Array(a.length),i=g.Ie(),l=()=>{for(let e=0;e<i.length;e++)a[e].removeObserver(i[e])},o=0,r=!1;for(let e=0;e<a.length&&!r;e++){let n=i=>{if(o++,"Failure"===i._tag)return r=!0,l(),t(i);s[e]=i.value,o===a.length&&t(eU(s))};i.push(n),a[e].addObserver(n)}return eY(()=>{r=!0,l()})}),eF=e=>(0,V.R6)(t=>eI(e,t.id)),eI=(0,v.XY)(e=>(0,w.i5)(e[0],ey),(e,t,a)=>(0,V.R6)(s=>{let i=eS(s);return i=i&&a?u.h1(i,a):i??a,e.interruptUnsafe(t,i),t_(eP(e))})),eE=e=>(0,V.R6)(t=>{let a=eS(t),s=g.Ie();for(let i of e)i.interruptUnsafe(t.id,a),s.push(i);return t_(eV(s))}),eO=(0,v.XY)(2,(e,t)=>(0,V.R6)(a=>{let s=eS(a),i=g.Ie();for(let a of e)a.interruptUnsafe(t,s),i.push(a);return t_(eV(i))})),eU=V.xt,eX=V.cb,eT=V.Rk,eY=(0,V.Uf)({op:"Sync",[V._3](e){let t=this[V.a2](),a=e.getCont(V.ee);return a?a[V.ee](t,e):e.yieldWith((0,V.xt)(t))}}),e$=(0,V.Uf)({op:"Suspend",[V._3](e){return this[V.a2]()}}),eG=(0,v.XY)(e=>e.length>=2||y.isOption(e[0]),(e,t)=>y.isNone(e)?eT(t?t():new V.Xm("Effect.fromOption: Option.none")):eU(e.value)),eD=x.YW({onFailure:eT,onSuccess:eU}),eR=e=>null==e?eT(new V.Xm):eU(e),eZ=(0,V.Uf)({op:"Yield",[V._3](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{t||e.evaluate(t1)},this[V.a2]??0),e.yieldWith(()=>{t=!0})}}),ej=eZ(0),eN=e=>eU(y.some(e)),eW=eU(y.none()),eJ=e=>y.isNone(e)?eW:tE(e.value,y.some),eK=e=>e$(()=>eX(e())),eQ=e=>(0,V.V2)(e),e1=e=>e$(()=>eT(e())),e0=eU(void 0),e2=e=>{let t="function"==typeof e?e:e.try,a="function"==typeof e?e=>new lI(e,"An error occurred in Effect.try"):e.catch;return e$(()=>{try{return eU(t())}catch(e){return eT(a(e))}})},e3=e=>e8(function(t,a){e(a).then(e=>t(eU(e)),e=>t(eQ(e)))},0!==e.length),e5=e=>{let t="function"==typeof e?e:e.try,a="function"==typeof e?e=>new lI(e,"An error occurred in Effect.tryPromise"):e.catch;return e8(function(e,s){let i=e=>e$(()=>{try{return eT((0,P.s)(()=>a(e)))}catch(e){return eQ(e)}});try{t(s).then(t=>e(eU(t)),t=>e(i(t)))}catch(t){e(i(t))}},0!==t.length)},e4=e=>(0,V.R6)(t=>e(t.id)),e6=(0,V.R6)(eU),e7=e4(eU),e8=(s=(0,V.yj)({op:"Async",[V._3](e){let t=!1,a=!1,s=this.withSignal?new AbortController:void 0,i=this.register.call(e.cache.scheduler,s=>{t||(t=!0,a?e.evaluate(s):a=s)},s?.signal);return!1!==a?a:(a=!0,e._yielded=()=>{t=!0},void 0===s&&void 0===i||e._stack.push(e9(()=>(t=!0,s?.abort(),i??t1))),V.GN)}}),(i=function(e,t){this.register=e,this.withSignal=t}).prototype=s,function(e,t){return new i(e,t)}),e9=(0,V.Uf)({op:"AsyncFinalizer",[V.u4](e){e.interruptible&&(e.interruptible=!1,e._stack.push(s2))},[V.Sc](e,t){return J(e)?tV(sm((0,V.cb)(e),this[V.a2]()),()=>eX(e)):eX(e)}}),te=e=>e8(e,e.length>=2),tt=te(v.Yi),ta=(...e)=>{if(1===e.length){let t=e[0];return e$(()=>td(t()))}let[t,a]=e;return e$(()=>td(a.call(t.self)))},ts=(e,...t)=>{let a=0===t.length?function(){return e$(()=>td(e.apply(this,arguments)))}:function(){let a=e$(()=>td(e.apply(this,arguments)));for(let e=0;e<t.length;e++)a=t[e](a,...arguments);return a};return ti(e.length,a)},ti=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),tl=U(2),to=function(){let e,t="string"==typeof arguments[0],a=t?arguments[0]:"Effect.fn",s=t?arguments[1]:void 0,i=(0,E.jt)();return(0!==i&&((0,E.ft)(2),e=new globalThis.Error,(0,E.ft)(i)),t)?(i,...l)=>tr(a,i,e,l,t,s):tr(a,arguments[0],e,Array.prototype.slice.call(arguments,1),t,s)},tr=(e,t,a,s,i,l)=>{let o="function"==typeof t?t:s.shift().bind(t.self),r=`${e} (definition)`,n=a?tl(()=>a.stack):v.MN;return ti(o.length,function(...t){let a,c=e$(()=>{let e=o.apply(this,arguments);return(0,V.yw)(e)?e:td(e)});for(let e=0;e<s.length;e++)c=s[e](c,...t);if(!(0,V.yw)(c))return c;let d=(0,E.jt)();return 0!==d&&((0,E.ft)(2),a=new globalThis.Error,(0,E.ft)(d)),al(i?li(e,l,e=>ll(c,e)):c,I.vA,t=>({name:e,stack:a?tl(()=>a.stack):v.MN,parent:{name:r,stack:n,parent:t}}))})},tn=(e,...t)=>ti(e.length,0===t.length?function(){return tc(()=>e.apply(this,arguments))}:function(){let a=tc(()=>e.apply(this,arguments));for(let e of t)a=e(a,...arguments);return a}),tc=e=>{try{let t,a=e();for(;;){let s=a.next(t);if(s.done)return eU(s.value);let i=s.value;if(i&&"Success"===i._tag){t=i.value;continue}{if(i&&"Failure"===i._tag)return s.value;let t=!0;return e$(()=>t?(t=!1,tV(s.value,e=>td(a,e))):e$(()=>td(e())))}}}catch(e){return eQ(e)}},td=(l=(0,V.yj)({op:"Iterator",[V.ee](e,t){let a=this.iterator;for(;;){let s=a.next(e);if(s.done)return eU(s.value);if(!tq(s.value))return t._stack.push(this),s.value;if("Failure"===s.value._tag)return s.value;e=s.value.value}},[V._3](e){return this[V.ee](this.initial,e)}}),(o=function(e,t){this.iterator=e,this.initial=t}).prototype=l,function(e,t){return new o(e,t)}),tp=(0,v.XY)(2,(e,t)=>new tu(e,tf,eU(t))),th=function(e){return e._stack.push(this),this[V.a2]},tg=(0,V.yj)({op:"OnSuccess",[V._3]:th}),tu=function(e,t,a){this[V.a2]=e,this[V.ee]=t,this.payload=a};tu.prototype=tg;let tf=function(){return this.payload},tm=function(e,t){return t.succeedWith(this.payload)},tv=(r="~effect/Effect/stackProbe",({[r]:function(){return Error().stack}})[r]()?.includes("[as "+r+"]")===!0),ty=function(e,t){let a=this.payload;return t.succeedWith(tv?a(e):(0,P.s)(()=>a(e)))},tw=function(e){return(0,this.payload)(e)},tx=function(e){return new tu((0,this.payload)(e),tm,e)},tb=function(e){return new tu(this.payload,tm,e)},tk=e=>tE(e,y.some),tM=e=>a7(e,{onFailure:eU,onSuccess:eT}),tC=(0,v.XY)(2,(e,t)=>new tu(e,(0,V.yw)(t)?tf:tw,t)),tz=(0,v.XY)(2,(e,t)=>new tu(e,(0,V.yw)(t)?tb:tx,t)),t_=e=>new tu(e,tf,t1),tL=e=>ak(e,eT),tB=(e,t)=>(0,V.R6)(a=>{let s=new Set;return sE(a,()=>0===s.size?void 0:eE(s)),te(i=>{let l=g.Ts(e),o=l.length,r=0,n=!1,c=[],d=(e,s,l)=>{if(r++,"Failure"===e._tag){c.push(...e.cause.reasons),r>=o&&i(eX((0,V.b5)(c)));return}let d=!n;n=!0,i(e),d&&t?.onWinner&&t.onWinner({fiber:s,index:l,parentFiber:a})};for(let e=0;e<o;e++){let t=iA(a,l[e],!0,!0,!1);if(s.add(t),t.addObserver(a=>{s.delete(t),d(a,t,e)}),n)break}})}),tS=(e,t)=>(0,V.R6)(a=>{let s=new Set;return sE(a,()=>0===s.size?void 0:eE(s)),te(i=>{let l=!1,o=0;for(let r of e){if(l)break;let e=o++,n=iA(a,r,!0,!0,!1);s.add(n),n.addObserver(o=>{s.delete(n);let r=!l;l=!0,i(o),r&&t?.onWinner&&t.onWinner({fiber:n,index:e,parentFiber:a})})}})}),tA=(0,v.XY)(e=>(0,V.yw)(e[1]),(e,t,a)=>tB([e,t],a)),tP=(0,v.XY)(e=>(0,V.yw)(e[1]),(e,t,a)=>tS([e,t],a)),tV=(0,v.XY)(2,(e,t)=>new tu(e,tw,t)),tH=(0,v.XY)(2,(e,t)=>tq(e)?"Success"===e._tag?t.onSuccess(e.value):t.onFailure(e.cause):aQ(e,t)),tq=e=>void 0!==e[V.IH],tF=(0,v.XY)(2,(e,t)=>tq(e)?"Success"===e._tag?t(e.value):e:tV(e,t)),tI=e=>tV(e,v.D_),tE=(0,v.XY)(2,(e,t)=>new tu(e,ty,t)),tO=(0,v.XY)(2,(e,t)=>tq(e)?t0(e,t):tE(e,t)),tU=(0,v.XY)(2,(e,t)=>tq(e)?t2(e,t):a$(e,t)),tX=(0,v.XY)(2,(e,t)=>tq(e)?t3(e,t):aG(e,t)),tT=(0,v.XY)(2,(e,t)=>{if(tq(e)){if("Success"===e._tag)return e;let a=R(e.cause);return x.N6(a)?e:t(a.success)}return aL(e,t)}),tY=e=>(0,V.cb)($(e)),t$=e=>"Success"===e._tag,tG=e=>"Success"===e._tag?x.Py(e):x.fJ(e),tD=e=>"Success"===e._tag?x.Py(e.value):x.fJ(e),tR=e=>"Failure"===e._tag,tZ=e=>"Failure"===e._tag?x.Py(e):x.fJ(e),tj=e=>"Failure"===e._tag?x.Py(e.cause):x.fJ(e),tN=b(tj,R),tW=b(tj,W),tJ=e=>"Failure"===e._tag&&J(e.cause),tK=e=>"Failure"===e._tag&&j(e.cause),tQ=e=>"Failure"===e._tag&&G(e.cause),t1=(0,V.xt)(void 0),t0=(0,v.XY)(2,(e,t)=>"Success"===e._tag?(0,V.xt)(t(e.value)):e),t2=(0,v.XY)(2,(e,t)=>{if("Success"===e._tag)return e;let a=R(e.cause);return x.N6(a)?e:(0,V.Rk)(t(a.success))}),t3=(0,v.XY)(2,(e,t)=>{if("Success"===e._tag)return(0,V.xt)(t.onSuccess(e.value));let a=R(e.cause);return x.N6(a)?e:(0,V.Rk)(t.onFailure(a.success))}),t5=(0,v.XY)(2,(e,t)=>t$(e)?(0,V.xt)(t):e),t4=(0,v.XY)(2,(e,t)=>t$(e)?t:e),t6=(0,v.XY)(2,(e,t)=>t$(e)?t.onSuccess(e.value):t.onFailure(e.cause)),t7=t5(void 0),t8=e=>{let t=[];for(let a of e)"Failure"===a._tag&&t.push(...a.cause.reasons);return 0===t.length?t1:(0,V.cb)((0,V.b5)(t))},t9=e=>t$(e)?y.some(e.value):y.none(),ae=e=>tR(e)?y.some(e.cause):y.none(),at=e=>{let t=tN(e);return x.N6(t)?y.none():y.some(t.success)},aa=e=>e,as=e=>(0,V.R6)(t=>eU(u.om(t.context,e))),ai=(0,v.XY)(2,(e,t)=>(0,V.R6)(a=>{let s=a.context,i=t(s);return s===i||(a.setContext(i),sE(a,()=>{a.setContext(s)})),e})),al=(0,v.XY)(3,(e,t,a)=>ai(e,e=>{let s=u.fp(e,t),i=a(s);return s===i?e:u.WQ(e,t,i)})),ao=(e,t,a)=>s1((0,V.R6)(s=>{let i=u.fp(s.context,e),l=t(i);return s.setContext(u.WQ(s.context,e,l)),sx(u.fp(s.context,sh),t=>{let o,r=u.om(s.context,e);if(y.isNone(r))return e0;let n=r.value;if(a?.reset===void 0){if(n!==l)return e0;o=i}else o=a.reset(i,l,n);return s.setContext(u.WQ(s.context,e,o)),e0})})),ar=()=>an,an=(0,V.R6)(e=>eU(e.context)),ac=e=>(0,V.R6)(t=>e(t.context)),ad=(0,v.XY)(2,(e,t)=>ai(e,(0,v.dY)(t))),ap=(0,v.XY)(2,(e,t)=>tq(e)?e:ai(e,u.h1(t))),ah=function(){return 1==arguments.length?(0,v.XY)(2,(e,t)=>ag(e,arguments[0],t)):(0,v.XY)(3,(e,t,a)=>ag(e,t,a)).apply(this,arguments)},ag=(e,t,a)=>ai(e,u.WQ(t,a)),au=(0,v.XY)(3,(e,t,a)=>tV(a,a=>ah(e,t,a))),af=(0,v.XY)(e=>(0,V.yw)(e[1]),(e,t,a)=>am(e,t,(e,t)=>[e,t],a)),am=(0,v.XY)(e=>(0,V.yw)(e[1]),(e,t,a,s)=>s?.concurrent?tE(ie([e,t],{concurrency:2}),([e,t])=>a(e,t)):tV(e,e=>tE(t,t=>a(e,t)))),av=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>iw(e,t,a?e=>eT(a(e)):()=>eT(new V.Xm))),ay=(0,v.XY)(2,(e,t)=>tV(t,t=>t?tk(e):eW)),aw=(0,v.XY)(2,(e,t)=>Array.from({length:t},()=>e)),ax=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>ie(aw(e,t),a)),ab=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>ic({while:v.ue,body:(0,v.dY)(t?.disableYield?e:tV(e,e=>ej)),step:v.Yi})),ak=(0,v.XY)(2,(e,t)=>new aC(e,1!==t.length?e=>t(e):t)),aM=(0,V.yj)({op:"OnFailure",[V._3]:th}),aC=function(e,t){this[V.a2]=e,this[V.Sc]=t};aC.prototype=aM;let az=(0,v.XY)(3,(e,t,a)=>ak(e,e=>t(e)?a(e):eX(e))),a_=(0,v.XY)(3,(e,t,a)=>ak(e,e=>{let s=t(e);return x.N6(s)?eX(s.failure):a(s.success,e)})),aL=(0,v.XY)(2,(e,t)=>a_(e,R,e=>t(e))),aB=e=>a7(e,{onFailure:e=>(0,V.PW)(e)?eW:eT(e),onSuccess:eN}),aS=(0,v.XY)(2,(e,t)=>a_(e,W,t)),aA=(0,v.XY)(2,(e,t)=>ak(e,e=>tC(t(e),eX(e)))),aP=(0,v.XY)(3,(e,t,a)=>az(e,t,e=>tC(a(e),eX(e)))),aV=(0,v.XY)(3,(e,t,a)=>ak(e,e=>{let s=t(e);return x.N6(s)?eX(e):tC(a(s.success,e),eX(e))})),aH=(0,v.XY)(2,(e,t)=>aV(e,R,e=>t(e))),aq=(0,v.XY)(3,(e,t,a)=>{let s=Array.isArray(t)?e=>(0,w.i5)(e,"_tag")&&t.includes(e._tag):(0,w.$J)(t);return aH(e,e=>s(e)?a(e):e0)}),aF=(0,v.XY)(2,(e,t)=>aV(e,W,e=>t(e))),aI=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s)=>ak(e,e=>{let i=R(e);return x.N6(i)?eX(i.failure):t(i.success)?a(i.success):s?s(i.success):eX(e)})),aE=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s)=>ak(e,e=>{let i=R(e);if(x.N6(i))return eX(i.failure);let l=t(i.success);return x.N6(l)?s?s(l.failure):eX(e):a(l.success)})),aO=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s)=>aI(e,Array.isArray(t)?e=>(0,w.i5)(e,"_tag")&&t.includes(e._tag):(0,w.$J)(t),a,s)),aU=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>{let s;return aE(e,e=>(s??=Object.keys(t),(0,w.i5)(e,"_tag")&&(0,w.Kg)(e._tag)&&s.includes(e._tag)?x.Py(e):x.fJ(e)),e=>t[e._tag](e),a)}),aX=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s,i)=>aI(e,e=>(0,w.$J)(e,t)&&(0,w.i5)(e,"reason")&&(void 0!==i||(0,w.$J)(e.reason,a)),e=>{let t=e.reason;return(0,w.$J)(t,a)?s(t,e):i?i(t,e):eT(e)})),aT=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s)=>{let i;return aI(e,e=>(0,w.$J)(e,t)&&(0,w.i5)(e,"reason")&&(0,w.i5)(e.reason,"_tag")&&(0,w.Kg)(e.reason._tag)&&(void 0!==s||(i??=Object.keys(a)).includes(e.reason._tag)),e=>{let t=e.reason;return(i??=Object.keys(a)).includes(t._tag)?a[t._tag](t,e):s?s(t,e):eT(e)})}),aY=(0,v.XY)(2,(e,t)=>aE(e,e=>(0,w.$J)(e,t)&&(0,w.i5)(e,"reason")?x.Py(e.reason):x.fJ(e),eT)),a$=(0,v.XY)(2,(e,t)=>aL(e,e=>e1(()=>t(e)))),aG=(0,v.XY)(2,(e,t)=>a7(e,{onFailure:e=>e1(()=>t.onFailure(e)),onSuccess:e=>eY(()=>t.onSuccess(e))})),aD=e=>aL(e,eQ),aR=(0,v.XY)(2,(e,t)=>aL(e,e=>eY(()=>t(e)))),aZ=e=>e$(()=>{let t=e[Symbol.iterator](),a=t.next();return a.done?eQ(Error("Received an empty collection of effects")):function e(a){let s=t.next();return s.done?a.value:aL(a.value,t=>e(s))}(a)}),aj=e=>aL(e,t=>tV(ej,()=>aj(e))),aN=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>{if(!t?.log)return a7(e,{onFailure:e=>e0,onSuccess:e=>e0});let a=lR(!0===t.log?void 0:t.log);return aQ(e,{onFailure(e){let s=D(e);return x.N6(s)?eX(s.failure):void 0===t.message?a(e):a(t.message,e)},onSuccess:e=>e0})}),aW=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>{if(!t?.log)return aQ(e,{onFailure:e=>e0,onSuccess:e=>e0});let a=lR(!0===t.log?void 0:t.log);return aQ(e,{onFailure:e=>void 0===t.message?a(e):a(t.message,e),onSuccess:e=>e0})}),aJ=e=>a8(e,{onFailure:y.none,onSuccess:y.some}),aK=e=>a9(e,{onFailure:x.fJ,onSuccess:x.Py}),aQ=(0,v.XY)(2,(e,t)=>new a0(e,1!==t.onSuccess.length?e=>t.onSuccess(e):t.onSuccess,1!==t.onFailure.length?e=>t.onFailure(e):t.onFailure)),a1=(0,V.yj)({op:"OnSuccessAndFailure",[V._3]:th}),a0=function(e,t,a){this[V.a2]=e,this[V.ee]=t,this[V.Sc]=a};a0.prototype=a1;let a2=function(e,t){let a=this.payload;return t.succeedWith(tv?a.onSuccess(e):(0,P.s)(()=>a.onSuccess(e)))},a3=(e,t)=>{let a=(0,V.yj)({op:e,[V._3]:th,[V.ee]:a2,[V.Sc]:t}),s=function(e,t){this[V.a2]=e,this.payload=t};return s.prototype=a,s},a5=a3("Match",function(e,t){let a=e.reasons.find(V.lC);if(void 0===a)return eX(e);let s=this.payload;return t.succeedWith(tv?s.onFailure(a.error):(0,P.s)(()=>s.onFailure(a.error)))}),a4=a3("MatchCause",function(e,t){let a=this.payload;return t.succeedWith(tv?a.onFailure(e):(0,P.s)(()=>a.onFailure(e)))}),a6=(0,v.XY)(2,(e,t)=>new a4(e,t)),a7=(0,v.XY)(2,(e,t)=>aQ(e,{onFailure:e=>{let a=e.reasons.find(V.lC);return a?t.onFailure(a.error):eX(e)},onSuccess:t.onSuccess})),a8=(0,v.XY)(2,(e,t)=>new a5(e,t)),a9=(0,v.XY)(2,(e,t)=>{if(tq(e)){if("Success"===e._tag)return(0,V.xt)(t.onSuccess(e.value));let a=R(e.cause);return x.N6(a)?e:(0,V.xt)(t.onFailure(a.success))}return a8(e,t)}),se=(0,v.XY)(2,(e,t)=>tq(e)?"Success"===e._tag?(0,V.xt)(t.onSuccess(e.value)):(0,V.xt)(t.onFailure(e.cause)):a6(e,t)),st=e=>tq(e)?(0,V.xt)(e):sa(e),sa=(0,V.Uf)({op:"Exit",[V._3](e){return e._stack.push(this),this[V.a2]},[V.ee]:(e,t,a)=>t.succeedWith(a??(0,V.xt)(e)),[V.Sc]:(e,t,a)=>t.succeedWith(a??(0,V.cb)(e))}),ss=a9({onFailure:()=>!0,onSuccess:()=>!1}),si=a9({onFailure:()=>!1,onSuccess:()=>!0}),sl=(0,v.XY)(2,(e,t)=>tC(ly(t),e)),so=(0,v.XY)(2,(e,t)=>tV(sn(e,t.duration),e=>y.isNone(e)?t.orElse():eU(e.value))),sr=(0,v.XY)(2,(e,t)=>{let a=f.bN(t);return so(e,{duration:a,orElse:()=>eT(new lC(`Operation timed out after '${f.GP(a)}'`))})}),sn=(0,v.XY)(2,(e,t)=>tP(tk(e),tp(ly(t),y.none()))),sc=e=>lv(t=>{let a=t.monotonicTimeNanosUnsafe();return tE(e,e=>[f.cF(t.monotonicTimeNanosUnsafe()-a),e])}),sd="~effect/Scope",sp="~effect/Scope/Closeable",sh=u.kl("effect/Scope"),sg=(e,t)=>(0,V.R6)(a=>{let s=su(e,t);return void 0===s?e0:(s4(a),s)}),su=(e,t)=>{let a=e.state;if("Closed"===a._tag||(e.state={_tag:"Closed",exit:t},void 0!==e.parent&&sM(e.parent,e),"Empty"===a._tag))return;if(void 0!==a.finalizer)return sf(a.finalizer,t);let s=a.finalizers;return 1===s.size?sf(s.values().next().value,t):sv(e,s,t)},sf=(e,t)=>{try{return e(t)}catch(e){return(0,V.V2)(e)}},sm=(e,t)=>t$(e)?t:ak(t,t=>eX((0,V.h2)(e.cause,t))),sv=ts(function*(e,t,a){let s=[],i=[],l=Array.from(t.values()),o=eM();for(let t=l.length-1;t>=0;t--){let r=l[t];"sequential"===e.strategy?s.push((yield*st(sf(r,a)))):i.push(iA(o,sf(r,a),!0,!0,"inherit"))}return i.length>0&&(s=yield*eV(i)),yield*t8(s)}),sy=(e,t)=>eY(()=>sw(e,t)),sw=(e,t)=>{let a=sz(t,e);return"Closed"===e.state._tag?a.state=e.state:sk(e,a,e=>sg(a,e)),a},sx=(e,t)=>e$(()=>"Closed"===e.state._tag?t(e.state.exit):(sk(e,{},t),e0)),sb=(e,t)=>sx(e,(0,v.dY)(t)),sk=(e,t,a)=>{if("Empty"===e.state._tag)e.state={_tag:"Open",finalizerKey:t,finalizer:a,finalizers:void 0};else if("Open"===e.state._tag){let s=e.state;void 0!==s.finalizer&&(s.finalizers=new Map([[s.finalizerKey,s.finalizer]]),s.finalizerKey=void 0,s.finalizer=void 0),s.finalizers.set(t,a)}},sM=(e,t)=>{if("Open"!==e.state._tag)return;let a=e.state;a.finalizerKey===t?e.state=s_:void 0!==a.finalizers&&(a.finalizers.delete(t),0===a.finalizers.size&&(e.state=s_))},sC=e=>sz(e,void 0),sz=(e="sequential",t)=>({[sp]:sp,[sd]:sd,strategy:e,parent:t,state:s_}),s_={_tag:"Empty"},sL=e=>eY(()=>sC(e)),sB=sh,sS=ah(sh),sA=e=>(0,V.R6)(t=>{let a=t.context,s=sC();return t.setContext(u.WQ(t.context,sh,s)),sE(t,e=>(t.setContext(a),su(s,e))),e}),sP=(0,v.XY)(2,(e,t)=>sO(sS(e,t),e=>e$(()=>su(t,e)??e0))),sV=e=>e$(()=>{let t=sC();return sO(e(t),e=>e$(()=>su(t,e)??e0))}),sH=(e,t,a)=>ac(s=>s7(i=>tV(sB,l=>tz(a?.interruptible?i(e):e,e=>sx(l,a=>ap(t(e,a),s)))))),sq=e=>tV(sB,t=>ac(a=>sx(t,t=>ap(e(t),a)))),sF=(n=(0,V.yj)({op:"OnExit",[V._3](e){return e._stack.push(this),this.effect},[V.u4](e){e.interruptible&&!0!==this.interruptible&&(e._stack.push(s2),e.interruptible=!1)},[V.ee](e,t,a){let s;a??=(0,V.xt)(e);try{s=this.onExit(a)}catch(e){s=(0,V.V2)(e)}return s?tV(s,e=>a):a},[V.Sc](e,t,a){let s;a??=(0,V.cb)(e);try{s=this.onExit(a)}catch(e){s=(0,V.V2)(e)}return s?tV(sm(a,s),e=>a):a}}),(c=function(e,t,a){this.effect=e,this.onExit=t,this.interruptible=a}).prototype=n,c),sI=(e,t,a)=>new sF(e,t,a),sE=(e,t)=>{e._stack.push(new sF(void 0,t,void 0))},sO=(0,v.XY)(2,sI),sU=(0,v.XY)(2,(e,t)=>sO(e,e=>t)),sX=(0,v.XY)(3,(e,t,a)=>sO(e,e=>t(e)?a(e):e0)),sT=(0,v.XY)(3,(e,t,a)=>sO(e,e=>{let s=t(e);return x.N6(s)?e0:a(s.success,e)})),sY=(0,v.XY)(2,(e,t)=>sT(e,tj,t)),s$=(0,v.XY)(3,(e,t,a)=>sX(e,e=>"Failure"===e._tag&&t(e.cause),e=>a(e.cause))),sG=(0,v.XY)(3,(e,t,a)=>sO(e,e=>{if("Failure"!==e._tag)return e0;let s=t(e.cause);return x.N6(s)?e0:a(s.success,e.cause)})),sD=(0,v.XY)(2,(e,t)=>sG(Q,t)(e)),sR=(e,t,a)=>s7(s=>tV(e,e=>sI(e$(()=>s(t(e))),t=>a(e,t),!0))),sZ=e=>sH(e,e=>(0,w.i5)(e,Symbol.asyncDispose)?e3(()=>e[Symbol.asyncDispose]()):eY(()=>e[Symbol.dispose]())),sj=(0,v.XY)(2,(e,t)=>eY(()=>sW(e,"function"==typeof t?e=>f.kE(f.bN(t(e))):(0,v.dY)(f.kE(f.bN(t)))))),sN=(0,v.dY)(1/0),sW=(e,t)=>{let a,s,i=0,l=(e,t)=>(t.awaiters++,sE(e,()=>{if(!(--t.awaiters>0)&&s===t)return s=void 0,eF(t.fiber)}),eH(t.fiber));return[(0,V.R6)(o=>{if(void 0!==s)return l(o,s);if(void 0!==a&&(1/0===i||o.getRef(lh).currentTimeMillisUnsafe()<i))return a;a=void 0;let r=o.getRef(lh),n={fiber:void 0,awaiters:0};return s=n,n.fiber=iA(o,sI(e,e=>{if(s!==n||(s=void 0,tJ(e)))return;let l=t(e);i=1/0===l?1/0:r.currentTimeMillisUnsafe()+l,a=e}),!0,!0),n.fiber._exit??l(o,n)}),eY(()=>{a=void 0})]},sJ=(0,v.XY)(2,(e,t)=>tE(sj(e,t),e=>e[0])),sK=e=>eY(()=>sW(e,sN)[0]),sQ=(0,V.R6)(e=>eX($(e.id))),s1=e=>(0,V.R6)(t=>(t.interruptible&&(t.interruptible=!1,t._stack.push(s2)),e)),s0=(0,V.Uf)({op:"SetInterruptible",[V.u4](e){if(e.interruptible=this[V.a2],e._interruptedCause&&e.interruptible)return()=>eX(e._interruptedCause)}}),s2=s0(!0),s3=s0(!1),s5=e=>{if(e.interruptible=!0,e._stack.push(s3),e._interruptedCause)return eX(e._interruptedCause)},s4=e=>{e.interruptible&&(e.interruptible=!1,e._stack.push(s2))},s6=e=>(0,V.R6)(t=>t.interruptible?e:s5(t)??e),s7=e=>(0,V.R6)(t=>t.interruptible?(t.interruptible=!1,t._stack.push(s2),e(s6)):e(v.D_)),s8=e=>(0,V.R6)(t=>{if(t.interruptible)return e(v.D_);let a=s5(t),s=e(s1);return a??s}),s9=tE(sH(eY(()=>new AbortController),e=>eY(()=>e.abort())),e=>e.signal),ie=(e,t)=>(0,w.xZ)(e)?t?.mode==="result"?id(e,aK,t):id(e,v.D_,t):t?.discard?"result"===t.mode?id(Object.values(e),aK,t):id(Object.values(e),v.D_,t):e$(()=>{let a={};return tp(id(Object.entries(e),([e,s])=>tE(t?.mode==="result"?aK(s):s,t=>{F.x(a,e,t)}),{discard:!0,concurrency:t?.concurrency}),a)}),it=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t,a)=>tE(id(e,(e,a)=>aK(t(e,a)),a),e=>g.jB(e,v.D_))),ia=(0,v.XY)(3,(e,t,a)=>{let s=g.Ts(e);return 0===s.length?eY(t):e$(()=>{let e=0,i=t();return tE(ic({while:()=>e<s.length,body:()=>a(i,s[e],e),step(t){i=t,e++}}),()=>i)})}),is=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t,a)=>tV(it(e,t,{concurrency:a?.concurrency}),([e,t])=>g.CZ(t)?eT(t):a?.discard?e0:eU(e))),ii=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t)=>e$(()=>{let a=e[Symbol.iterator](),s=a.next();return s.done?eU(y.none()):il(a,0,t,s.value)})),il=(e,t,a,s)=>tV(a(s,t),i=>{if(i)return eU(y.some(s));let l=e.next();return l.done?eU(y.none()):il(e,t+1,a,l.value)}),io=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t)=>e$(()=>{let a=e[Symbol.iterator](),s=a.next();return s.done?eU(y.none()):ir(a,0,t,s.value)})),ir=(e,t,a,s)=>tV(a(s,t),s=>{if(x.oJ(s))return eU(y.some(s.success));let i=e.next();return i.done?eU(y.none()):ir(e,t+1,a,i.value)}),ic=(0,V.Uf)({op:"While",[V.ee](e,t){return(this[V.a2].step(e),this[V.a2].while())?(t._stack.push(this),this[V.a2].body()):t1},[V._3](e){return this[V.a2].while()?(e._stack.push(this),this[V.a2].body()):t1}}),id=(0,v.XY)(e=>"function"==typeof e[1],(e,t,a)=>e$(()=>{let s=ig(a?.concurrency);if(1===s)return ih(e,t,a);let i=g.Ts(e),l=i.length;if(0===l)return a?.discard?e0:eU([]);let o=a?.discard?void 0:Array(l),r=iy({f:t,out:o},i,{concurrency:s});return r?tp(r,o):eU(o)})),ip=e=>tV(e,e=>{let t=e[Symbol.iterator]().next();return t.done?eT(new V.Xm):eU(t.value)}),ih=(e,t,a)=>e$(()=>{let s=a?.discard?void 0:[],i=e[Symbol.iterator](),l=i.next(),o=0;return tp(ic({while:()=>!l.done,body:()=>t(l.value,o++),step:e=>{s&&s.push(e),l=i.next()}}),s)}),ig=e=>"unbounded"===e?1/0:Math.max(1,e??1),iu=()=>e=>{let t=e.onItem,a=e.step,s=(e,t,s,l,o)=>tV(st(o),o=>a(e,t[s],o,s)??i(e,t,s+1,l)??e0),i=(e,i,l=0,o=i.length)=>{for(;l<o;l++){let r=i[l],n=t(e,r,l);if(!tq(n))return s(e,i,l,o,n);let c=a(e,r,n,l);if(c)return"Failure"===c._tag?c:void 0}};return i},im=e=>{let t=e.onItem,a=e.step;return(e,s,i)=>{let l,o,r,n,c,d=0,p=i.end??s.length,h=i.concurrency,g=!1,u=e=>{let t=(0,V.V2)(e);return n=t,g=!0,o&&o.size>0?tV(s1(eE(Array.from(o))),()=>n??t):t},f=()=>{let i=!1;for(;!n&&d<p;d++){let p=s[d],m=c??t(e,p,d);if(tq(m)){if(n=a(e,p,m,d))break}else{if(!l)return te(e=>{let t;l=eM(),o=new Set,c=m,r=e;try{t=f()}catch(t){return e(u(t))}return t?e(t):e$(()=>(n??=t1,tV(o?eE(o):e0,()=>n?._tag==="Failure"?n:e0)))});c=void 0;let t=iA(l,m,!0,!0,"inherit");if(t._exit){if(n=a(e,p,t._exit,d))break;continue}o.add(t);let s=d;if(t.addObserver(l=>{o.delete(t);try{if(n){if("Failure"===l._tag){let e=l.cause.reasons.filter(e=>"Interrupt"!==e._tag);if(e.length>0){let t=(0,V.b5)(e);n=(0,V.cb)("Failure"===n._tag?(0,V.h2)(n.cause,t):t)}}}else{let t=a(e,p,l,s);t&&(n=t,f())}if(i){let e=f();e&&r(e)}else g&&0===o.size&&r(n??e0)}catch(e){r(u(e))}}),o.size<h)continue;i=!0,d++;return}}if(g=!0,n){if(o&&o.size>0){let e=eS(l);o.forEach(t=>t.interruptUnsafe(l.id,e));return}if(r||"Failure"===n._tag)return n}else if(r)if(!o)return t1;else 0===o.size&&r(e0)};return f()}},iv=()=>e=>im(e),iy=im({onItem:(e,t,a)=>e.f(t,a),step(e,t,a,s){if("Failure"===a._tag)return a;e.out&&(e.out[s]=a.value)}}),iw=(0,v.XY)(3,(e,t,a)=>tV(e,e=>t(e)?eU(e):a(e))),ix=(0,v.XY)(3,(e,t,a)=>tV(e,e=>{let s=t(e);return x.N6(s)?a(s.failure):eU(s.success)})),ib=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>ix(e,t,a?e=>eT(a(e)):()=>eT(new V.Xm))),ik=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t,a)=>e$(()=>{let s=[];return tp(id(e,(e,a)=>{let i=t(e,a);return"boolean"==typeof i?(i&&s.push(e),e0):tE(i,t=>{t&&s.push(e)})},{discard:!0,concurrency:a?.concurrency}),s)})),iM=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t)=>e$(()=>{let a=[];for(let s of e){let e=t(s);x.oJ(e)&&a.push(e.success)}return eU(a)})),iC=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t,a)=>e$(()=>{let s=[];return tp(id(e,e=>tE(t(e),e=>{x.oJ(e)&&s.push(e.success)}),{discard:!0,concurrency:a?.concurrency}),s)})),iz=eU({}),i_=H.Jr(tE),iL=H.oI(tE,tV),iB=H.zM(tE),iS=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>(0,V.R6)(a=>(eB.interruptChildren??=eA,eU(iA(a,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),iA=(e,t,a=!1,s=!1,i=!1)=>{let l="inherit"===i?e.interruptible:!i,o=new eC(e.context,l);return a?o.evaluate(t):(o._asyncContext=ek(),e.currentDispatcher.scheduleTask(()=>o.evaluate(t),0)),s||o._exit||(e.children().add(o),o._parent=e),o},iP=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>(0,V.R6)(a=>eU(iA(a,e,t?.startImmediately,!0,t?.uninterruptible)))),iV=e=>(0,V.R6)(t=>{let a=t._children&&new Set(t._children),s=t.interruptible;return sI(e,e=>{let i=t._children;if(void 0===i||0===i.size)return e0;a&&(i=z.pb(i,e=>!a.has(e)));let l=t_(eV(i));return s?s6(l):l})}),iH=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>(0,V.R6)(s=>{let i=iA(s,e,a?.startImmediately,!0,a?.uninterruptible);if(!i._exit)if("Closed"!==t.state._tag){let e={};sk(t,e,()=>e4(e=>e===i.id?e0:eF(i))),i.addObserver(()=>sM(t,e))}else i.interruptUnsafe(s.id,eS(s));return eU(i)})),iq=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>tV(sB,a=>iH(e,a,t))),iF=e=>(t,a)=>{let s=new eC(a?.scheduler?u.WQ(e,S._F,a.scheduler):e,a?.uninterruptible!==!0);if(s.evaluate(t),s._exit)return s;if(a?.signal)if(a.signal.aborted)s.interruptUnsafe();else{let e=()=>s.interruptUnsafe();a.signal.addEventListener("abort",e,{once:!0}),s.addObserver(()=>a.signal.removeEventListener("abort",e))}return a?.onFiberStart&&a.onFiberStart(s),s},iI=(0,v.XY)(2,(e,t)=>{if(e._exit)return e;if("Closed"===t.state._tag)return e.interruptUnsafe(e.id),e;let a={};return sk(t,a,()=>eF(e)),e.addObserver(()=>sM(t,a)),e}),iE=iF(u.Ie()),iO=e=>{let t=iF(e);return(e,a)=>{let s=t(e,a);return a?.onExit&&s.addObserver(a.onExit),e=>s.interruptUnsafe(e)}},iU=iO(u.Ie()),iX=e=>{let t=iF(e);return(e,a)=>{let s=t(e,a);return new Promise(e=>{s.addObserver(t=>e(t))})}},iT=iX(u.Ie()),iY=e=>{let t=iX(e);return(e,a)=>t(e,a).then(e=>{if("Failure"===e._tag)throw eo(e.cause);return e.value})},i$=iY(u.Ie()),iG=e=>{let t=iF(e);return e=>{if(tq(e))return e;let a=t(e,{scheduler:new S.FG("sync")});return a._dispatcher?.flush(),a._exit??(0,V.V2)(new lH(a))}},iD=iG(u.Ie()),iR=e=>{let t=iG(e);return e=>{let a=t(e);if("Failure"===a._tag)throw eo(a.cause);return a.value}},iZ=iR(u.Ie()),ij=eU(!0),iN=eU(!1);class iW{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(0===this.waiters.length)return ij;if(void 0===this.scheduled)this.scheduled=this.waiters,e.currentDispatcher.scheduleTask(this.flushScheduled,0);else for(let e=0;e<this.waiters.length;e++)this.scheduled.push(this.waiters[e]);return this.waiters=[],ij}flushScheduled=()=>{if(void 0===this.scheduled)return;let e=this.scheduled;this.scheduled=void 0;for(let t=0;t<e.length;t++)e[t](t1)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](t1)}open=(0,V.R6)(e=>this._isOpen?iN:(this._isOpen=!0,this.scheduleUnsafe(e)));release=(0,V.R6)(e=>this._isOpen?iN:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=te(e=>this._isOpen?e(e0):(this.waiters.push(e),eY(()=>{let t=this.waiters.indexOf(e);-1!==t?this.waiters.splice(t,1):void 0!==this.scheduled&&-1!==(t=this.scheduled.indexOf(e))&&this.scheduled.splice(t,1)})));closeUnsafe(){return!!this._isOpen&&(this._isOpen=!1,!0)}close=eY(()=>this.closeUnsafe());whenOpen=e=>tV(this.await,()=>e);isOpen(){return this._isOpen}}let iJ=e=>new iW(e??!1),iK=e=>eY(()=>iJ(e)),iQ=(0,V.R6)(e=>eU(e.getRef(A.sh))),i1=(0,v.XY)(2,(e,t)=>ah(e,A.sh,t)),i0=ah(I.rf),i2=ah(I.nU),i3=BigInt(0),i5={_tag:"Span",spanId:"noop",traceId:"noop",sampled:!1,status:{_tag:"Ended",startTime:i3,endTime:i3,exit:t1},attributes:new Map,links:[],kind:"internal",attribute(){},event(){},end(){},addLinks(){}},i4=e=>e?u.Jt(e.annotations,A.DW)?"Span"===e._tag?i4(y.getOrUndefined(e.parent)):y.none():y.some(e):y.none(),i6=(e,t,a)=>{let s,i=!e.cache.tracerEnabled||a?.annotations&&u.Jt(a.annotations,A.DW),l=a?.parent!==void 0?y.some(a.parent):a?.root?y.none():i4(e.cache.span);if(i){let e;e={name:t,parent:l,annotations:u.WQ(a?.annotations??u.Ie(),A.DW,!0)},s=Object.assign(Object.create(i5),e)}else{let i=e.cache.tracer??A.Vv,o=e.getRef(lh),r=e.getRef(I.nU),n=e.getRef(I.ce),c=e.getRef(I.ls),d=a?.level??e.getRef(A.pX),p=a?.links!==void 0?[...c,...a.links]:0===c.length?[]:c.slice();for(let c in s=i.span({name:t,parent:l,annotations:a?.annotations??u.Ie(),links:p,startTime:r?o.currentTimeNanosUnsafe():i3,kind:a?.kind??"internal",root:a?.root??y.isNone(l),sampled:a?.sampled??((!y.isSome(l)||!1!==l.value.sampled)&&!lU(e.getRef(A.EW),d))}),n)s.attribute(c,n[c]);if(a?.attributes!==void 0)for(let e in a.attributes)s.attribute(e,a.attributes[e])}return s},i7=(e,t)=>(0,V.R6)(a=>eU(i6(a,e,t))),i8=(e,t)=>s1((0,V.R6)(a=>{let s=u.fp(a.context,sh),i=i6(a,e,t??{}),l=a.getRef(lh),o=a.getRef(I.nU);return tp(sx(s,e=>ls(i,e,l,o)),i)})),i9=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],a=O(e?arguments[2]:arguments[1]);if(e){let e=arguments[0];return tV(i8(t,a),t=>lo(e,t,a))}return e=>tV(i8(t,a),t=>lo(e,t,a))},le=I.ce,lt=I.ls,la=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a={})=>{let s=(Array.isArray(t)?t:[t]).map(e=>({span:e,attributes:a}));return al(e,I.ls,e=>[...e,...s])}),ls=(e,t,a,s)=>eY(()=>{"Ended"!==e.status._tag&&e.end(s?a.currentTimeNanosUnsafe():i3,t)}),li=(e,...t)=>{let a=1===t.length?void 0:t[0],s=t[t.length-1];return(0,V.R6)(t=>{let i=i6(t,e,a),l=t.getRef(lh),o=t.getRef(I.nU);return sE(t,e=>ls(i,e,l,o)),s(i)})},ll=ah(A.Tv),lo=function(){let e=(0,V.yw)(arguments[0]),t=e?arguments[1]:arguments[0],a=e?arguments[2]:arguments[1],s=v.D_;if("Span"===t._tag){var i,l;a=O(a),i=t.name,l="function"==typeof(l=a?.captureStackTrace)?l:v.MN,s=al(I.vA,e=>({name:i,stack:l,parent:e}))}return e?ll(s(arguments[0]),t):e=>ll(s(e),t)},lr=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],a=O(arguments[2]);if(e){let e=arguments[0];return li(t,arguments[2],t=>lo(e,t,a))}let s="function"==typeof arguments[1]?arguments[1]:void 0,i=s?void 0:arguments[1];return(e,...l)=>li(t,s?s(...l):i,t=>lo(e,t,a))},ln=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,...t)=>al(e,I.ce,e=>{let a=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||F.x(a,t[0],t[1]),a})),lc=(...e)=>(0,V.R6)(t=>{let a=t.currentSpanLocal;if(a)if(1===e.length)for(let[t,s]of Object.entries(e[0]))a.attribute(t,s);else a.attribute(e[0],e[1]);return e0}),ld=(0,V.R6)(e=>{let t=e.currentSpanLocal;return t?eU(t):eT(new V.Xm)}),lp=(d=A.Tv,(0,V.R6)(e=>eG(u.om(e.context,d)))),lh=u.Or("effect/Clock",{defaultValue:()=>new lg});class lg{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=eY(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return lm()}currentTimeNanos=eY(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return lf()}monotonicTimeNanos=eY(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(f.kE(e))}sleepMillis(e){return e<=0?ej:Number.isFinite(e)?te(t=>{let a=e>0x7fffffff?this.sleepMillis(e-0x7fffffff):e0,s=setTimeout(()=>t(a),Math.min(e,0x7fffffff));return eY(()=>clearTimeout(s))}):tt}}let lu=BigInt(1e6),lf=function(){let e=globalThis.process?.hrtime;if("function"==typeof e?.bigint)return()=>e.bigint();if("u">typeof performance&&"function"==typeof performance.now)return()=>BigInt(Math.round(1e6*performance.now()));let t=BigInt(0);return()=>{let e=BigInt(Date.now())*lu;return e>t&&(t=e),t}}(),lm=(h=BigInt(1e9),()=>{let e=lf(),t=BigInt(Date.now())*lu;if(void 0===p)p=t-e;else{let a=p+e;(t>a?t-a:a-t)>h&&(p=t-e)}return p+e}),lv=e=>(0,V.R6)(t=>e(t.getRef(lh))),ly=e=>lv(t=>t.sleep(f.bN(e))),lw=lv(e=>e.currentTimeMillis),lx=lv(e=>e.currentTimeNanos),lb=lv(e=>e.monotonicTimeNanos),lk="~effect/Cause/TimeoutError",lM=e=>(0,w.i5)(e,lk);class lC extends(0,V.rN)("TimeoutError"){[lk]=lk;constructor(e){super({message:e})}}let lz="~effect/Cause/IllegalArgumentError",l_=e=>(0,w.i5)(e,lz);class lL extends(0,V.rN)("IllegalArgumentError"){[lz]=lz;constructor(e){super({message:e})}}let lB="~effect/Cause/ExceededCapacityError",lS=e=>(0,w.i5)(e,lB);class lA extends(0,V.rN)("ExceededCapacityError"){[lB]=lB;constructor(e){super({message:e})}}let lP="~effect/Cause/AsyncFiberError",lV=e=>(0,w.i5)(e,lP);class lH extends(0,V.rN)("AsyncFiberError"){[lP]=lP;constructor(e){super({message:"An asynchronous Effect was executed with Effect.runSync",fiber:e})}}let lq="~effect/Cause/UnknownError",lF=e=>(0,w.i5)(e,lq);class lI extends(0,V.rN)("UnknownError"){[lq]=lq;constructor(e,t){super({message:t,cause:e})}}let lE=u.Or("effect/Console",{defaultValue:()=>globalThis.console}),lO=_.zQ(_.wN,e=>{switch(e){case"All":return Number.MIN_SAFE_INTEGER;case"Fatal":return 5e4;case"Error":return 4e4;case"Warn":return 3e4;case"Info":return 2e4;case"Debug":return 1e4;case"Trace":return 0;case"None":return Number.MAX_SAFE_INTEGER}}),lU=_.yJ(lO),lX=u.Or("effect/Logger/CurrentLoggers",{defaultValue:()=>new Set([lZ,lj])}),lT=u.Or("effect/Logger/LogToStderr",{defaultValue:v.f4}),lY=function(){let e="string"==typeof arguments[0]?[[arguments[0],arguments[1]]]:Object.entries(arguments[0]);return s1((0,V.R6)(t=>{let a=t.getRef(I.iL),s={...a};for(let t=0;t<e.length;t++){let[a,i]=e[t];F.x(s,a,i)}return t.setContext(u.WQ(t.context,I.iL,s)),sx(u.fp(t.context,sh),s=>{let i=t.getRef(I.iL),l={...i};for(let t=0;t<e.length;t++){let[s,o]=e[t];(i[s]===o||Object.is(i[s],o))&&(Object.hasOwn(a,s)?F.x(l,s,a[s]):delete l[s])}return t.setContext(u.WQ(t.context,I.iL,l)),e0})}))},l$={"~effect/Logger":{_Message:v.D_,_Output:v.D_},pipe(){return(0,L.tT)(this,arguments)}},lG=e=>{let t=Object.create(l$);return t.log=e,t},lD=(e,t)=>{let a=e[0].replace(/[\s="]/g,"_");return`${a}=${t-e[1]}ms`},lR=e=>(...t)=>{let a;for(let e=0,s=t.length;e<s;e++){let s=t[e];(0,V.Aj)(s)&&(a?t.splice(e,1):t=t.slice(0,e).concat(t.slice(e+1)),a=a?(0,V.b5)(a.reasons.concat(s.reasons)):s,e--)}return void 0===a&&(a=V.DH),(0,V.R6)(s=>{let i=e??s.cache.logLevel;if(lU(s.cache.minimumLogLevel,i))return e0;let l=s.getRef(lh),o=s.getRef(lX);if(o.size>0){let e=new Date(l.currentTimeMillisUnsafe());for(let l of o)l.log({cause:a,fiber:s,date:e,logLevel:i,message:t})}return e0})},lZ=lG(({cause:e,date:t,fiber:a,logLevel:s,message:i})=>{let l=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&l.push(ef(e));let o=t.getTime(),r=a.getRef(I.d8),n="";for(let e of r)n+=` ${lD(e,o)}`;let c=a.getRef(I.iL);Object.keys(c).length>0&&l.push(c);let d=a.getRef(lE);(a.getRef(lT)?d.error:d.log)(`[${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}] ${s.toUpperCase()} (#${a.id})${n}:`,...l)}),lj=lG(({cause:e,fiber:t,logLevel:a,message:s})=>{let i=t.getRef(lh),l=t.getRef(I.iL),o=t.cache.span;if(void 0===o||"ExternalSpan"===o._tag)return;let r={};for(let[e,t]of Object.entries(l))F.x(r,e,t);r["effect.fiberId"]=t.id,r["effect.logLevel"]=a.toUpperCase(),e.reasons.length>0&&(r["effect.cause"]=ef(e)),o.event((0,C.ZK)(Array.isArray(s)&&1===s.length?s[0]:s),i.currentTimeNanosUnsafe(),r)}),lN=eU(void 0),lW=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>sY(e,e=>(0,V.R6)(a=>(lJ(a,e,t?.defectsOnly),e0)))),lJ=(e,t,a)=>{let s=e.getRef(I.oQ);if(0===s.size||a&&!j(t))return;let i={cause:t,fiber:e,timestamp:e.getRef(lh).currentTimeNanosUnsafe()};s.forEach(e=>e.report(i))}},5844(e,t,a){let s=new WeakSet;a.d(t,{},{J3:s,Xp:e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;e instanceof Error&&t.delete("stack");let a=Object.getPrototypeOf(e),s=a;for(;null!==s&&s!==Object.prototype;){let e=Reflect.ownKeys(s);for(let a=0;a<e.length;a++)t.add(e[a]);s=Object.getPrototypeOf(s)}return t.has("constructor")&&"function"==typeof e.constructor&&a===e.constructor.prototype&&t.delete("constructor"),t},j:e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength)})},7258(e,t,a){a.d(t,{},{F:"effect/Metric/FiberRuntimeMetrics"})},7731(e,t,a){var s=a(3332),i=a(1958),l=a(5033),o=a(3952),r=a(4233),n=a(6481),c=a(2449);let d="~effect/Option",p={[d]:{_A:e=>e},...c.fU,[Symbol.iterator](){return new n.B(this)}},h=Object.defineProperty(Object.assign(Object.create(p),{_tag:"Some",_op:"Some",[s.HR](e){return f(e)&&v(e)&&s.aI(this.value,e.value)},[l.HR](){return l.kg(l.tW(this._tag))(l.tW(this.value))},toString(){return`some(${(0,i.GP)(this.value)})`},toJSON(){return{_id:"Option",_tag:this._tag,value:(0,o.aB)(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),g=l.tW("None"),u=Object.assign(Object.create(p),{_tag:"None",_op:"None",valueOrUndefined:void 0,[s.HR]:e=>f(e)&&m(e),[l.HR]:()=>g,toString:()=>"none()",toJSON(){return{_id:"Option",_tag:this._tag}}}),f=e=>(0,r.i5)(e,d),m=e=>"None"===e._tag,v=e=>"Some"===e._tag,y=Object.create(u),w=function(e){this.value=e};w.prototype=h,a.d(t,{},{$I:m,Ru:v,dv:y,oL:f,zN:e=>new w(e)})},2275(e,t,a){function s(e,t,a){"__proto__"===t?Object.defineProperty(e,t,{value:a,writable:!0,enumerable:!0,configurable:!0}):e[t]=a}function i(e,t){for(let a of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,a)&&s(e,a,t[a])}a.d(t,{x:()=>s,z:()=>i})},6712(e,t,a){var s=a(1179),i=a(1594);let l=s.Or("effect/ErrorReporter/CurrentErrorReporters",{defaultValue:()=>new Set}),o=s.Or("effect/References/CurrentStackFrame",{fiberCached:!0,defaultValue:i.MN}),r=s.Or("effect/References/TracerEnabled",{fiberCached:!0,defaultValue:i.ue}),n=s.Or("effect/References/TracerTimingEnabled",{defaultValue:i.ue}),c=s.Or("effect/References/TracerSpanAnnotations",{defaultValue:()=>({})}),d=s.Or("effect/References/TracerSpanLinks",{defaultValue:()=>[]}),p=s.Or("effect/References/CurrentLogAnnotations",{defaultValue:()=>({})}),h=s.Or("effect/References/CurrentLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),g=s.Or("effect/References/MinimumLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),u=s.Or("effect/References/UnhandledLogLevel",{defaultValue:()=>"Error"}),f=s.Or("effect/References/CurrentLogSpans",{defaultValue:()=>[]});a.d(t,{},{Gl:h,aG:u,ce:c,d8:f,iL:p,ls:d,nU:n,oQ:l,rf:r,vA:o,zQ:g})},2563(e,t,a){var s=a(3332),i=a(1958),l=a(1594),o=a(5033),r=a(3952),n=a(4233),c=a(6481),d=a(2449),p=a(7731);let h="~effect/Result",g={[h]:{_A:e=>e,_E:e=>e},...d.fU,[Symbol.iterator](){return new c.B(this)}},u=Object.assign(Object.create(g),{_tag:"Success",_op:"Success",[s.HR](e){return m(e)&&y(e)&&s.aI(this.success,e.success)},[o.HR](){return o.kg(o.tW(this._tag))(o.tW(this.success))},toString(){return`success(${(0,i.GP)(this.success)})`},toJSON(){return{_id:"Result",_tag:this._tag,value:(0,r.aB)(this.success)}}}),f=Object.assign(Object.create(g),{_tag:"Failure",_op:"Failure",[s.HR](e){return m(e)&&v(e)&&s.aI(this.failure,e.failure)},[o.HR](){return o.kg(o.tW(this._tag))(o.tW(this.failure))},toString(){return`failure(${(0,i.GP)(this.failure)})`},toJSON(){return{_id:"Result",_tag:this._tag,failure:(0,r.aB)(this.failure)}}}),m=e=>(0,n.i5)(e,h),v=e=>"Failure"===e._tag,y=e=>"Success"===e._tag,w=function(e){this.failure=e};w.prototype=f;let x=e=>new w(e),b=function(e){this.success=e};b.prototype=u;let k=e=>new b(e),M=(0,l.XY)(2,(e,t)=>p.$I(e)?x(t()):k(e.value));a.d(t,{},{L8:e=>y(e)?p.dv:p.zN(e.failure),N6:v,Oz:e=>v(e)?p.dv:p.zN(e.success),Py:k,aI:m,fJ:x,oJ:y,sV:M})},2840(e,t,a){var s=a(1594);function i(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function l(e){return t=>i(t)?.[e]}let o="~structural",r="~identifier",n="~sentinels",c=l("identifier"),d=l(r),p=l("title"),h=l("description"),g=(0,s.Bj)(e=>{let t=i(e)?.identifier;return"string"==typeof t?t:e.getExpected(g)}),u=new Set([n,o,"representation","arbitraryConstraint","toJsonSchema","toCode","toEquivalence","toFormatter","toCodec","toCodecJson","toCodecStringTree","toCodecIso","toCodecArbitrary"]);a.d(t,{hd:()=>i,ip:()=>l},{C3:o,CD:d,DQ:p,I_:n,KE:c,L1:["title","description","default","examples","readOnly","writeOnly","format","contentEncoding","contentMediaType","contentSchema"],Pk:h,R4:r,UI:u,bo:g,py:"~constructor"})},8253(e,t,a){var s=a(719),i=a(7086);function l(e){let t;for(let a of e.reasons){if(!s.lC(a)||!i.gh(a.error))return;t??=a.error}return t}function o(e,t){let a=l(e);if(void 0===a)throw Error(t,{cause:e});return a}a.d(t,{R:()=>l,q:()=>o})},587(e,t,a){var s=a(6526),i=a(1587);let l=Symbol(),o=s.Py,r=o(l),n=o(l);a.d(t,{},{LO:l,Py:o,Rr:n,e8:e=>"None"===e._tag?r:o(e.value),r2:r,zL:e=>e===l?i.none():i.some(e)})},5340(e,t,a){let s,i=void 0===(s=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"))?Object.isExtensible(Error):Object.hasOwn(s,"writable")?!0===s.writable:void 0!==s.set;a.d(t,{},{ft:e=>{i&&(Error.stackTraceLimit=e)},jt:()=>Error.stackTraceLimit})},8689(e,t,a){let s,i,l,o,r;function n(e){let t=e.length;for(;--t>=0;)e[t]=0}let c=573,d=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),p=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),h=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),g=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=Array(576);n(u);let f=Array(60);n(f);let m=Array(512);n(m);let v=Array(256);n(v);let y=Array(29);n(y);let w=Array(30);function x(e,t,a,s,i){this.static_tree=e,this.extra_bits=t,this.extra_base=a,this.elems=s,this.max_length=i,this.has_stree=e&&e.length}function b(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}n(w);let k=e=>e<256?m[e]:m[256+(e>>>7)],M=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},C=(e,t,a)=>{e.bi_valid>16-a?(e.bi_buf|=t<<e.bi_valid&65535,M(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=a-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=a)},z=(e,t,a)=>{C(e,a[2*t],a[2*t+1])},_=(e,t)=>{let a=0;do a|=1&e,e>>>=1,a<<=1;while(--t>0)return a>>>1},L=(e,t,a)=>{let s,i,l=Array(16),o=0;for(s=1;s<=15;s++)l[s]=o=o+a[s-1]<<1;for(i=0;i<=t;i++){let t=e[2*i+1];0!==t&&(e[2*i]=_(l[t]++,t))}},B=e=>{let t;for(t=0;t<286;t++)e.dyn_ltree[2*t]=0;for(t=0;t<30;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0},S=e=>{e.bi_valid>8?M(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},A=(e,t,a,s)=>{let i=2*t,l=2*a;return e[i]<e[l]||e[i]===e[l]&&s[t]<=s[a]},P=(e,t,a)=>{let s=e.heap[a],i=a<<1;for(;i<=e.heap_len&&(i<e.heap_len&&A(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!A(t,s,e.heap[i],e.depth));)e.heap[a]=e.heap[i],a=i,i<<=1;e.heap[a]=s},V=(e,t,a)=>{let s,i,l,o,r=0;if(0!==e.last_lit)do s=e.pending_buf[e.d_buf+2*r]<<8|e.pending_buf[e.d_buf+2*r+1],i=e.pending_buf[e.l_buf+r],r++,0===s?z(e,i,t):(z(e,(l=v[i])+256+1,t),0!==(o=d[l])&&C(e,i-=y[l],o),z(e,l=k(--s),a),0!==(o=p[l])&&C(e,s-=w[l],o));while(r<e.last_lit)z(e,256,t)},H=(e,t)=>{let a,s,i,l=t.dyn_tree,o=t.stat_desc.static_tree,r=t.stat_desc.has_stree,n=t.stat_desc.elems,d=-1;for(e.heap_len=0,e.heap_max=c,a=0;a<n;a++)0!==l[2*a]?(e.heap[++e.heap_len]=d=a,e.depth[a]=0):l[2*a+1]=0;for(;e.heap_len<2;)l[2*(i=e.heap[++e.heap_len]=d<2?++d:0)]=1,e.depth[i]=0,e.opt_len--,r&&(e.static_len-=o[2*i+1]);for(t.max_code=d,a=e.heap_len>>1;a>=1;a--)P(e,l,a);i=n;do a=e.heap[1],e.heap[1]=e.heap[e.heap_len--],P(e,l,1),s=e.heap[1],e.heap[--e.heap_max]=a,e.heap[--e.heap_max]=s,l[2*i]=l[2*a]+l[2*s],e.depth[i]=(e.depth[a]>=e.depth[s]?e.depth[a]:e.depth[s])+1,l[2*a+1]=l[2*s+1]=i,e.heap[1]=i++,P(e,l,1);while(e.heap_len>=2)e.heap[--e.heap_max]=e.heap[1],((e,t)=>{let a,s,i,l,o,r,n=t.dyn_tree,d=t.max_code,p=t.stat_desc.static_tree,h=t.stat_desc.has_stree,g=t.stat_desc.extra_bits,u=t.stat_desc.extra_base,f=t.stat_desc.max_length,m=0;for(l=0;l<=15;l++)e.bl_count[l]=0;for(n[2*e.heap[e.heap_max]+1]=0,a=e.heap_max+1;a<c;a++)(l=n[2*n[2*(s=e.heap[a])+1]+1]+1)>f&&(l=f,m++),n[2*s+1]=l,!(s>d)&&(e.bl_count[l]++,o=0,s>=u&&(o=g[s-u]),r=n[2*s],e.opt_len+=r*(l+o),h&&(e.static_len+=r*(p[2*s+1]+o)));if(0!==m){do{for(l=f-1;0===e.bl_count[l];)l--;e.bl_count[l]--,e.bl_count[l+1]+=2,e.bl_count[f]--,m-=2}while(m>0)for(l=f;0!==l;l--)for(s=e.bl_count[l];0!==s;)!((i=e.heap[--a])>d)&&(n[2*i+1]!==l&&(e.opt_len+=(l-n[2*i+1])*n[2*i],n[2*i+1]=l),s--)}})(e,t),L(l,d,e.bl_count)},q=(e,t,a)=>{let s,i,l=-1,o=t[1],r=0,n=7,c=4;for(0===o&&(n=138,c=3),t[(a+1)*2+1]=65535,s=0;s<=a;s++)i=o,o=t[(s+1)*2+1],++r<n&&i===o||(r<c?e.bl_tree[2*i]+=r:0!==i?(i!==l&&e.bl_tree[2*i]++,e.bl_tree[32]++):r<=10?e.bl_tree[34]++:e.bl_tree[36]++,r=0,l=i,0===o?(n=138,c=3):i===o?(n=6,c=3):(n=7,c=4))},F=(e,t,a)=>{let s,i,l=-1,o=t[1],r=0,n=7,c=4;for(0===o&&(n=138,c=3),s=0;s<=a;s++)if(i=o,o=t[(s+1)*2+1],!(++r<n)||i!==o){if(r<c)do z(e,i,e.bl_tree);while(0!=--r)else 0!==i?(i!==l&&(z(e,i,e.bl_tree),r--),z(e,16,e.bl_tree),C(e,r-3,2)):r<=10?(z(e,17,e.bl_tree),C(e,r-3,3)):(z(e,18,e.bl_tree),C(e,r-11,7));r=0,l=i,0===o?(n=138,c=3):i===o?(n=6,c=3):(n=7,c=4)}},I=!1,E=(e,t,a,s)=>{C(e,0+ +!!s,3),S(e),M(e,a),M(e,~a),e.pending_buf.set(e.window.subarray(t,t+a),e.pending),e.pending+=a};var O={_tr_init:e=>{I||((()=>{let e,t,a,o,r,n=Array(16);for(o=0,a=0;o<28;o++)for(y[o]=a,e=0;e<1<<d[o];e++)v[a++]=o;for(v[a-1]=o,r=0,o=0;o<16;o++)for(w[o]=r,e=0;e<1<<p[o];e++)m[r++]=o;for(r>>=7;o<30;o++)for(w[o]=r<<7,e=0;e<1<<p[o]-7;e++)m[256+r++]=o;for(t=0;t<=15;t++)n[t]=0;for(e=0;e<=143;)u[2*e+1]=8,e++,n[8]++;for(;e<=255;)u[2*e+1]=9,e++,n[9]++;for(;e<=279;)u[2*e+1]=7,e++,n[7]++;for(;e<=287;)u[2*e+1]=8,e++,n[8]++;for(L(u,287,n),e=0;e<30;e++)f[2*e+1]=5,f[2*e]=_(e,5);s=new x(u,d,257,286,15),i=new x(f,p,0,30,15),l=new x([],h,0,19,7)})(),I=!0),e.l_desc=new b(e.dyn_ltree,s),e.d_desc=new b(e.dyn_dtree,i),e.bl_desc=new b(e.bl_tree,l),e.bi_buf=0,e.bi_valid=0,B(e)},_tr_stored_block:E,_tr_flush_block:(e,t,a,s)=>{let i,l,o=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,a=0xf3ffc07f;for(t=0;t<=31;t++,a>>>=1)if(1&a&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<256;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),H(e,e.l_desc),H(e,e.d_desc),o=(e=>{let t;for(q(e,e.dyn_ltree,e.l_desc.max_code),q(e,e.dyn_dtree,e.d_desc.max_code),H(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*g[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),i=e.opt_len+3+7>>>3,(l=e.static_len+3+7>>>3)<=i&&(i=l)):i=l=a+5,a+4<=i&&-1!==t?E(e,t,a,s):4===e.strategy||l===i?(C(e,2+ +!!s,3),V(e,u,f)):(C(e,4+ +!!s,3),((e,t,a,s)=>{let i;for(C(e,t-257,5),C(e,a-1,5),C(e,s-4,4),i=0;i<s;i++)C(e,e.bl_tree[2*g[i]+1],3);F(e,e.dyn_ltree,t-1),F(e,e.dyn_dtree,a-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),V(e,e.dyn_ltree,e.dyn_dtree)),B(e),s&&S(e)},_tr_tally:(e,t,a)=>(e.pending_buf[e.d_buf+2*e.last_lit]=t>>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&a,e.last_lit++,0===t?e.dyn_ltree[2*a]++:(e.matches++,t--,e.dyn_ltree[(v[a]+256+1)*2]++,e.dyn_dtree[2*k(t)]++),e.last_lit===e.lit_bufsize-1),_tr_align:e=>{C(e,2,3),z(e,256,u),16===e.bi_valid?(M(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}},U=(e,t,a,s)=>{let i=65535&e,l=e>>>16&65535,o=0;for(;0!==a;){o=a>2e3?2e3:a,a-=o;do l=l+(i=i+t[s++]|0)|0;while(--o)i%=65521,l%=65521}return i|l<<16};let X=new Uint32Array((()=>{let e,t=[];for(var a=0;a<256;a++){e=a;for(var s=0;s<8;s++)e=1&e?0xedb88320^e>>>1:e>>>1;t[a]=e}return t})());var T=(e,t,a,s)=>{let i=s+a;e^=-1;for(let a=s;a<i;a++)e=e>>>8^X[(e^t[a])&255];return -1^e},Y={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},$={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};let{_tr_init:G,_tr_stored_block:D,_tr_flush_block:R,_tr_tally:Z,_tr_align:j}=O,{Z_NO_FLUSH:N,Z_PARTIAL_FLUSH:W,Z_FULL_FLUSH:J,Z_FINISH:K,Z_BLOCK:Q,Z_OK:ee,Z_STREAM_END:et,Z_STREAM_ERROR:ea,Z_DATA_ERROR:es,Z_BUF_ERROR:ei,Z_DEFAULT_COMPRESSION:el,Z_FILTERED:eo,Z_HUFFMAN_ONLY:er,Z_RLE:en,Z_FIXED:ec,Z_DEFAULT_STRATEGY:ed,Z_UNKNOWN:ep,Z_DEFLATED:eh}=$,eg=573,eu=(e,t)=>(e.msg=Y[t],t),ef=e=>(e<<1)-9*(e>4),em=e=>{let t=e.length;for(;--t>=0;)e[t]=0},ev=(e,t,a)=>(t<<e.hash_shift^a)&e.hash_mask,ey=e=>{let t=e.state,a=t.pending;a>e.avail_out&&(a=e.avail_out),0!==a&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+a),e.next_out),e.next_out+=a,t.pending_out+=a,e.total_out+=a,e.avail_out-=a,t.pending-=a,0===t.pending&&(t.pending_out=0))},ew=(e,t)=>{R(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ey(e.strm)},ex=(e,t)=>{e.pending_buf[e.pending++]=t},eb=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},ek=(e,t,a,s)=>{let i=e.avail_in;return(i>s&&(i=s),0===i)?0:(e.avail_in-=i,t.set(e.input.subarray(e.next_in,e.next_in+i),a),1===e.state.wrap?e.adler=U(e.adler,t,i,a):2===e.state.wrap&&(e.adler=T(e.adler,t,i,a)),e.next_in+=i,e.total_in+=i,i)},eM=(e,t)=>{let a,s,i=e.max_chain_length,l=e.strstart,o=e.prev_length,r=e.nice_match,n=e.strstart>e.w_size-262?e.strstart-(e.w_size-262):0,c=e.window,d=e.w_mask,p=e.prev,h=e.strstart+258,g=c[l+o-1],u=c[l+o];e.prev_length>=e.good_match&&(i>>=2),r>e.lookahead&&(r=e.lookahead);do{if(c[(a=t)+o]!==u||c[a+o-1]!==g||c[a]!==c[l]||c[++a]!==c[l+1])continue;l+=2,a++;do;while(c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&l<h)if(s=258-(h-l),l=h-258,s>o){if(e.match_start=t,o=s,s>=r)break;g=c[l+o-1],u=c[l+o]}}while((t=p[t&d])>n&&0!=--i)return o<=e.lookahead?o:e.lookahead},eC=e=>{let t,a,s,i,l,o=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=o+(o-262)){e.window.set(e.window.subarray(o,o+o),0),e.match_start-=o,e.strstart-=o,e.block_start-=o,t=a=e.hash_size;do s=e.head[--t],e.head[t]=s>=o?s-o:0;while(--a)t=a=o;do s=e.prev[--t],e.prev[t]=s>=o?s-o:0;while(--a)i+=o}if(0===e.strm.avail_in)break;if(a=ek(e.strm,e.window,e.strstart+e.lookahead,i),e.lookahead+=a,e.lookahead+e.insert>=3)for(l=e.strstart-e.insert,e.ins_h=e.window[l],e.ins_h=ev(e,e.ins_h,e.window[l+1]);e.insert&&(e.ins_h=ev(e,e.ins_h,e.window[l+3-1]),e.prev[l&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=l,l++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<262&&0!==e.strm.avail_in)},ez=(e,t)=>{let a,s;for(;;){if(e.lookahead<262){if(eC(e),e.lookahead<262&&t===N)return 1;if(0===e.lookahead)break}if(a=0,e.lookahead>=3&&(e.ins_h=ev(e,e.ins_h,e.window[e.strstart+3-1]),a=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==a&&e.strstart-a<=e.w_size-262&&(e.match_length=eM(e,a)),e.match_length>=3)if(s=Z(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do e.strstart++,e.ins_h=ev(e,e.ins_h,e.window[e.strstart+3-1]),a=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(0!=--e.match_length)e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=ev(e,e.ins_h,e.window[e.strstart+1]);else s=Z(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(s&&(ew(e,!1),0===e.strm.avail_out))return 1}return(e.insert=e.strstart<2?e.strstart:2,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(ew(e,!1),0===e.strm.avail_out)?1:2},e_=(e,t)=>{let a,s,i;for(;;){if(e.lookahead<262){if(eC(e),e.lookahead<262&&t===N)return 1;if(0===e.lookahead)break}if(a=0,e.lookahead>=3&&(e.ins_h=ev(e,e.ins_h,e.window[e.strstart+3-1]),a=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==a&&e.prev_length<e.max_lazy_match&&e.strstart-a<=e.w_size-262&&(e.match_length=eM(e,a),e.match_length<=5&&(e.strategy===eo||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-3,s=Z(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=ev(e,e.ins_h,e.window[e.strstart+3-1]),a=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(0!=--e.prev_length)if(e.match_available=0,e.match_length=2,e.strstart++,s&&(ew(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if((s=Z(e,0,e.window[e.strstart-1]))&&ew(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return(e.match_available&&(s=Z(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(ew(e,!1),0===e.strm.avail_out)?1:2};function eL(e,t,a,s,i){this.good_length=e,this.max_lazy=t,this.nice_length=a,this.max_chain=s,this.func=i}let eB=[new eL(0,0,0,0,(e,t)=>{let a=65535;for(65535>e.pending_buf_size-5&&(a=e.pending_buf_size-5);;){if(e.lookahead<=1){if(eC(e),0===e.lookahead&&t===N)return 1;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;let s=e.block_start+a;if((0===e.strstart||e.strstart>=s)&&(e.lookahead=e.strstart-s,e.strstart=s,ew(e,!1),0===e.strm.avail_out)||e.strstart-e.block_start>=e.w_size-262&&(ew(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:(e.strstart>e.block_start&&(ew(e,!1),e.strm.avail_out),1)}),new eL(4,4,8,4,ez),new eL(4,5,16,8,ez),new eL(4,6,32,32,ez),new eL(4,4,16,16,e_),new eL(8,16,32,32,e_),new eL(8,16,128,128,e_),new eL(8,32,128,256,e_),new eL(32,128,258,1024,e_),new eL(32,258,258,4096,e_)];function eS(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=eh,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(2*eg),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),em(this.dyn_ltree),em(this.dyn_dtree),em(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),em(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),em(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var eA=(e,t)=>{let a,s;if(!e||!e.state||t>Q||t<0)return e?eu(e,ea):ea;let i=e.state;if(!e.output||!e.input&&0!==e.avail_in||666===i.status&&t!==K)return eu(e,0===e.avail_out?ei:ea);i.strm=e;let l=i.last_flush;if(i.last_flush=t,42===i.status)if(2===i.wrap)e.adler=0,ex(i,31),ex(i,139),ex(i,8),i.gzhead?(ex(i,+!!i.gzhead.text+2*!!i.gzhead.hcrc+4*!!i.gzhead.extra+8*!!i.gzhead.name+16*!!i.gzhead.comment),ex(i,255&i.gzhead.time),ex(i,i.gzhead.time>>8&255),ex(i,i.gzhead.time>>16&255),ex(i,i.gzhead.time>>24&255),ex(i,9===i.level?2:4*(i.strategy>=er||i.level<2)),ex(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(ex(i,255&i.gzhead.extra.length),ex(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=T(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(ex(i,0),ex(i,0),ex(i,0),ex(i,0),ex(i,0),ex(i,9===i.level?2:4*(i.strategy>=er||i.level<2)),ex(i,3),i.status=113);else{let t=eh+(i.w_bits-8<<4)<<8;t|=(i.strategy>=er||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(t|=32),t+=31-t%31,i.status=113,eb(i,t),0!==i.strstart&&(eb(i,e.adler>>>16),eb(i,65535&e.adler)),e.adler=1}if(69===i.status)if(i.gzhead.extra){for(a=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),ey(e),a=i.pending,i.pending!==i.pending_buf_size));)ex(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){a=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),ey(e),a=i.pending,i.pending===i.pending_buf_size)){s=1;break}s=i.gzindex<i.gzhead.name.length?255&i.gzhead.name.charCodeAt(i.gzindex++):0,ex(i,s)}while(0!==s)i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),0===s&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){a=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),ey(e),a=i.pending,i.pending===i.pending_buf_size)){s=1;break}s=i.gzindex<i.gzhead.comment.length?255&i.gzhead.comment.charCodeAt(i.gzindex++):0,ex(i,s)}while(0!==s)i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),0===s&&(i.status=103)}else i.status=103;if(103===i.status&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&ey(e),i.pending+2<=i.pending_buf_size&&(ex(i,255&e.adler),ex(i,e.adler>>8&255),e.adler=0,i.status=113)):i.status=113),0!==i.pending){if(ey(e),0===e.avail_out)return i.last_flush=-1,ee}else if(0===e.avail_in&&ef(t)<=ef(l)&&t!==K)return eu(e,ei);if(666===i.status&&0!==e.avail_in)return eu(e,ei);if(0!==e.avail_in||0!==i.lookahead||t!==N&&666!==i.status){let a=i.strategy===er?((e,t)=>{let a;for(;;){if(0===e.lookahead&&(eC(e),0===e.lookahead)){if(t===N)return 1;break}if(e.match_length=0,a=Z(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,a&&(ew(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(ew(e,!1),0===e.strm.avail_out)?1:2})(i,t):i.strategy===en?((e,t)=>{let a,s,i,l,o=e.window;for(;;){if(e.lookahead<=258){if(eC(e),e.lookahead<=258&&t===N)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(s=o[i=e.strstart-1])===o[++i]&&s===o[++i]&&s===o[++i]){l=e.strstart+258;do;while(s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&i<l)e.match_length=258-(l-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(a=Z(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(a=Z(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),a&&(ew(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(ew(e,!1),0===e.strm.avail_out)?1:2})(i,t):eB[i.level].func(i,t);if((3===a||4===a)&&(i.status=666),1===a||3===a)return 0===e.avail_out&&(i.last_flush=-1),ee;if(2===a&&(t===W?j(i):t!==Q&&(D(i,0,0,!1),t===J&&(em(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),ey(e),0===e.avail_out))return i.last_flush=-1,ee}return t!==K?ee:i.wrap<=0?et:(2===i.wrap?(ex(i,255&e.adler),ex(i,e.adler>>8&255),ex(i,e.adler>>16&255),ex(i,e.adler>>24&255),ex(i,255&e.total_in),ex(i,e.total_in>>8&255),ex(i,e.total_in>>16&255),ex(i,e.total_in>>24&255)):(eb(i,e.adler>>>16),eb(i,65535&e.adler)),ey(e),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?ee:et)},eP=e=>{if(!e||!e.state)return ea;let t=e.state.status;return 42!==t&&69!==t&&73!==t&&91!==t&&103!==t&&113!==t&&666!==t?eu(e,ea):(e.state=null,113===t?eu(e,es):ee)};let eV=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var eH=function(e){let t=Array.prototype.slice.call(arguments,1);for(;t.length;){let a=t.shift();if(a){if("object"!=typeof a)throw TypeError(a+"must be non-object");for(let t in a)eV(a,t)&&(e[t]=a[t])}}return e},eq=e=>{let t=0;for(let a=0,s=e.length;a<s;a++)t+=e[a].length;let a=new Uint8Array(t);for(let t=0,s=0,i=e.length;t<i;t++){let i=e[t];a.set(i,s),s+=i.length}return a};let eF=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){eF=!1}let eI=new Uint8Array(256);for(let e=0;e<256;e++)eI[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;eI[254]=eI[254]=1;var eE=e=>{let t,a,s,i,l,o=e.length,r=0;for(i=0;i<o;i++)(64512&(a=e.charCodeAt(i)))==55296&&i+1<o&&(64512&(s=e.charCodeAt(i+1)))==56320&&(a=65536+(a-55296<<10)+(s-56320),i++),r+=a<128?1:a<2048?2:a<65536?3:4;for(t=new Uint8Array(r),l=0,i=0;l<r;i++)(64512&(a=e.charCodeAt(i)))==55296&&i+1<o&&(64512&(s=e.charCodeAt(i+1)))==56320&&(a=65536+(a-55296<<10)+(s-56320),i++),a<128?t[l++]=a:(a<2048?t[l++]=192|a>>>6:(a<65536?t[l++]=224|a>>>12:(t[l++]=240|a>>>18,t[l++]=128|a>>>12&63),t[l++]=128|a>>>6&63),t[l++]=128|63&a);return t},eO=(e,t)=>{let a,s,i=t||e.length,l=Array(2*i);for(s=0,a=0;a<i;){let t=e[a++];if(t<128){l[s++]=t;continue}let o=eI[t];if(o>4){l[s++]=65533,a+=o-1;continue}for(t&=2===o?31:3===o?15:7;o>1&&a<i;)t=t<<6|63&e[a++],o--;if(o>1){l[s++]=65533;continue}t<65536?l[s++]=t:(t-=65536,l[s++]=55296|t>>10&1023,l[s++]=56320|1023&t)}var o=s;if(o<65534&&l.subarray&&eF)return String.fromCharCode.apply(null,l.length===o?l:l.subarray(0,o));let r="";for(let e=0;e<o;e++)r+=String.fromCharCode(l[e]);return r},eU=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let a=t-1;for(;a>=0&&(192&e[a])==128;)a--;return a<0||0===a?t:a+eI[e[a]]>t?a:t},eX=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};let eT=Object.prototype.toString,{Z_NO_FLUSH:eY,Z_SYNC_FLUSH:e$,Z_FULL_FLUSH:eG,Z_FINISH:eD,Z_OK:eR,Z_STREAM_END:eZ,Z_DEFAULT_COMPRESSION:ej,Z_DEFAULT_STRATEGY:eN,Z_DEFLATED:eW}=$;function eJ(e){let t,a;this.options=eH({level:ej,method:eW,chunkSize:16384,windowBits:15,memLevel:8,strategy:eN},e||{});let s=this.options;s.raw&&s.windowBits>0?s.windowBits=-s.windowBits:s.gzip&&s.windowBits>0&&s.windowBits<16&&(s.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new eX,this.strm.avail_out=0;let i=((e,t,a,s,i,l)=>{var o,r;let n;if(!e)return ea;let c=1;if(t===el&&(t=6),s<0?(c=0,s=-s):s>15&&(c=2,s-=16),i<1||i>9||a!==eh||s<8||s>15||t<0||t>9||l<0||l>ec)return eu(e,ea);8===s&&(s=9);let d=new eS;return e.state=d,d.strm=e,d.wrap=c,d.gzhead=null,d.w_bits=s,d.w_size=1<<d.w_bits,d.w_mask=d.w_size-1,d.hash_bits=i+7,d.hash_size=1<<d.hash_bits,d.hash_mask=d.hash_size-1,d.hash_shift=~~((d.hash_bits+3-1)/3),d.window=new Uint8Array(2*d.w_size),d.head=new Uint16Array(d.hash_size),d.prev=new Uint16Array(d.w_size),d.lit_bufsize=1<<i+6,d.pending_buf_size=4*d.lit_bufsize,d.pending_buf=new Uint8Array(d.pending_buf_size),d.d_buf=+d.lit_bufsize,d.l_buf=3*d.lit_bufsize,d.level=t,d.strategy=l,d.method=a,(n=(e=>{if(!e||!e.state)return eu(e,ea);e.total_in=e.total_out=0,e.data_type=ep;let t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?42:113,e.adler=+(2!==t.wrap),t.last_flush=N,G(t),ee})(o=e))===ee&&((r=o.state).window_size=2*r.w_size,em(r.head),r.max_lazy_match=eB[r.level].max_lazy,r.good_match=eB[r.level].good_length,r.nice_match=eB[r.level].nice_length,r.max_chain_length=eB[r.level].max_chain,r.strstart=0,r.block_start=0,r.lookahead=0,r.insert=0,r.match_length=r.prev_length=2,r.match_available=0,r.ins_h=0),n})(this.strm,s.level,s.method,s.windowBits,s.memLevel,s.strategy);if(i!==eR)throw Error(Y[i]);if(s.header&&(t=this.strm,a=s.header,t&&t.state&&2===t.state.wrap&&(t.state.gzhead=a)),s.dictionary){let e;if(e="string"==typeof s.dictionary?eE(s.dictionary):"[object ArrayBuffer]"===eT.call(s.dictionary)?new Uint8Array(s.dictionary):s.dictionary,(i=((e,t)=>{let a=t.length;if(!e||!e.state)return ea;let s=e.state,i=s.wrap;if(2===i||1===i&&42!==s.status||s.lookahead)return ea;if(1===i&&(e.adler=U(e.adler,t,a,0)),s.wrap=0,a>=s.w_size){0===i&&(em(s.head),s.strstart=0,s.block_start=0,s.insert=0);let e=new Uint8Array(s.w_size);e.set(t.subarray(a-s.w_size,a),0),t=e,a=s.w_size}let l=e.avail_in,o=e.next_in,r=e.input;for(e.avail_in=a,e.next_in=0,e.input=t,eC(s);s.lookahead>=3;){let e=s.strstart,t=s.lookahead-2;do s.ins_h=ev(s,s.ins_h,s.window[e+3-1]),s.prev[e&s.w_mask]=s.head[s.ins_h],s.head[s.ins_h]=e,e++;while(--t)s.strstart=e,s.lookahead=2,eC(s)}return s.strstart+=s.lookahead,s.block_start=s.strstart,s.insert=s.lookahead,s.lookahead=0,s.match_length=s.prev_length=2,s.match_available=0,e.next_in=o,e.input=r,e.avail_in=l,s.wrap=i,ee})(this.strm,e))!==eR)throw Error(Y[i]);this._dict_set=!0}}function eK(e,t){let a=new eJ(t);if(a.push(e,!0),a.err)throw a.msg||Y[a.err];return a.result}eJ.prototype.push=function(e,t){let a,s,i=this.strm,l=this.options.chunkSize;if(this.ended)return!1;for(s=t===~~t?t:!0===t?eD:eY,"string"==typeof e?i.input=eE(e):"[object ArrayBuffer]"===eT.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){if(0===i.avail_out&&(i.output=new Uint8Array(l),i.next_out=0,i.avail_out=l),(s===e$||s===eG)&&i.avail_out<=6){this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;continue}if((a=eA(i,s))===eZ)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),a=eP(this.strm),this.onEnd(a),this.ended=!0,a===eR;if(0===i.avail_out){this.onData(i.output);continue}if(s>0&&i.next_out>0){this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;continue}if(0===i.avail_in)break}return!0},eJ.prototype.onData=function(e){this.chunks.push(e)},eJ.prototype.onEnd=function(e){e===eR&&(this.result=eq(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var eQ=function(e,t){let a,s,i,l,o,r,n,c,d,p,h,g,u,f,m,v,y,w,x,b,k,M,C,z,_=e.state;a=e.next_in,C=e.input,s=a+(e.avail_in-5),i=e.next_out,z=e.output,l=i-(t-e.avail_out),o=i+(e.avail_out-257),r=_.dmax,n=_.wsize,c=_.whave,d=_.wnext,p=_.window,h=_.hold,g=_.bits,u=_.lencode,f=_.distcode,m=(1<<_.lenbits)-1,v=(1<<_.distbits)-1;t:do for(g<15&&(h+=C[a++]<<g,g+=8,h+=C[a++]<<g,g+=8),y=u[h&m];;){if(h>>>=w=y>>>24,g-=w,0==(w=y>>>16&255))z[i++]=65535&y;else if(16&w)for(x=65535&y,(w&=15)&&(g<w&&(h+=C[a++]<<g,g+=8),x+=h&(1<<w)-1,h>>>=w,g-=w),g<15&&(h+=C[a++]<<g,g+=8,h+=C[a++]<<g,g+=8),y=f[h&v];;){if(h>>>=w=y>>>24,g-=w,16&(w=y>>>16&255)){if(b=65535&y,g<(w&=15)&&(h+=C[a++]<<g,(g+=8)<w&&(h+=C[a++]<<g,g+=8)),(b+=h&(1<<w)-1)>r){e.msg="invalid distance too far back",_.mode=30;break t}if(h>>>=w,g-=w,b>(w=i-l)){if((w=b-w)>c&&_.sane){e.msg="invalid distance too far back",_.mode=30;break t}if(k=0,M=p,0===d){if(k+=n-w,w<x){x-=w;do z[i++]=p[k++];while(--w)k=i-b,M=z}}else if(d<w){if(k+=n+d-w,(w-=d)<x){x-=w;do z[i++]=p[k++];while(--w)if(k=0,d<x){x-=w=d;do z[i++]=p[k++];while(--w)k=i-b,M=z}}}else if(k+=d-w,w<x){x-=w;do z[i++]=p[k++];while(--w)k=i-b,M=z}for(;x>2;)z[i++]=M[k++],z[i++]=M[k++],z[i++]=M[k++],x-=3;x&&(z[i++]=M[k++],x>1&&(z[i++]=M[k++]))}else{k=i-b;do z[i++]=z[k++],z[i++]=z[k++],z[i++]=z[k++],x-=3;while(x>2)x&&(z[i++]=z[k++],x>1&&(z[i++]=z[k++]))}}else if((64&w)==0){y=f[(65535&y)+(h&(1<<w)-1)];continue}else{e.msg="invalid distance code",_.mode=30;break t}break}else if((64&w)==0){y=u[(65535&y)+(h&(1<<w)-1)];continue}else if(32&w){_.mode=12;break t}else{e.msg="invalid literal/length code",_.mode=30;break t}break}while(a<s&&i<o)a-=x=g>>3,g-=x<<3,h&=(1<<g)-1,e.next_in=a,e.next_out=i,e.avail_in=a<s?5+(s-a):5-(a-s),e.avail_out=i<o?257+(o-i):257-(i-o),_.hold=h,_.bits=g};let e1=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),e0=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),e2=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),e3=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var e5=(e,t,a,s,i,l,o,r)=>{let n,c,d,p,h,g,u,f,m,v=r.bits,y=0,w=0,x=0,b=0,k=0,M=0,C=0,z=0,_=0,L=0,B=null,S=0,A=new Uint16Array(16),P=new Uint16Array(16),V=null,H=0;for(y=0;y<=15;y++)A[y]=0;for(w=0;w<s;w++)A[t[a+w]]++;for(k=v,b=15;b>=1&&0===A[b];b--);if(k>b&&(k=b),0===b)return i[l++]=0x1400000,i[l++]=0x1400000,r.bits=1,0;for(x=1;x<b&&0===A[x];x++);for(k<x&&(k=x),z=1,y=1;y<=15;y++)if(z<<=1,(z-=A[y])<0)return -1;if(z>0&&(0===e||1!==b))return -1;for(P[1]=0,y=1;y<15;y++)P[y+1]=P[y]+A[y];for(w=0;w<s;w++)0!==t[a+w]&&(o[P[t[a+w]]++]=w);if(0===e?(B=V=o,g=19):1===e?(B=e1,S-=257,V=e0,H-=257,g=256):(B=e2,V=e3,g=-1),L=0,w=0,y=x,h=l,M=k,C=0,d=-1,p=(_=1<<k)-1,1===e&&_>852||2===e&&_>592)return 1;for(;;){u=y-C,o[w]<g?(f=0,m=o[w]):o[w]>g?(f=V[H+o[w]],m=B[S+o[w]]):(f=96,m=0),n=1<<y-C,x=c=1<<M;do i[h+(L>>C)+(c-=n)]=u<<24|f<<16|m;while(0!==c)for(n=1<<y-1;L&n;)n>>=1;if(0!==n?(L&=n-1,L+=n):L=0,w++,0==--A[y]){if(y===b)break;y=t[a+o[w]]}if(y>k&&(L&p)!==d){for(0===C&&(C=k),h+=x,z=1<<(M=y-C);M+C<b&&!((z-=A[M+C])<=0);)M++,z<<=1;if(_+=1<<M,1===e&&_>852||2===e&&_>592)return 1;i[d=L&p]=k<<24|M<<16|h-l}}return 0!==L&&(i[h+L]=y-C<<24|4194304),r.bits=k,0};let{Z_FINISH:e4,Z_BLOCK:e6,Z_TREES:e7,Z_OK:e8,Z_STREAM_END:e9,Z_NEED_DICT:te,Z_STREAM_ERROR:tt,Z_DATA_ERROR:ta,Z_MEM_ERROR:ts,Z_BUF_ERROR:ti,Z_DEFLATED:tl}=$,to=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function tr(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}let tn=e=>{if(!e||!e.state)return tt;let t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,(e=>{if(!e||!e.state)return tt;let t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,e8})(e)},tc=!0,td=e=>{if(tc){o=new Int32Array(512),r=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(e5(1,e.lens,0,288,o,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;e5(2,e.lens,0,32,r,0,e.work,{bits:5}),tc=!1}e.lencode=o,e.lenbits=9,e.distcode=r,e.distbits=5},tp=(e,t,a,s)=>{let i,l=e.state;return null===l.window&&(l.wsize=1<<l.wbits,l.wnext=0,l.whave=0,l.window=new Uint8Array(l.wsize)),s>=l.wsize?(l.window.set(t.subarray(a-l.wsize,a),0),l.wnext=0,l.whave=l.wsize):((i=l.wsize-l.wnext)>s&&(i=s),l.window.set(t.subarray(a-s,a-s+i),l.wnext),(s-=i)?(l.window.set(t.subarray(a-s,a),0),l.wnext=s,l.whave=l.wsize):(l.wnext+=i,l.wnext===l.wsize&&(l.wnext=0),l.whave<l.wsize&&(l.whave+=i))),0};var th=(e,t)=>{let a,s,i,l,o,r,n,c,d,p,h,g,u,f,m,v,y,w,x,b,k,M,C,z,_=0,L=new Uint8Array(4),B=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return tt;12===(a=e.state).mode&&(a.mode=13),o=e.next_out,i=e.output,n=e.avail_out,l=e.next_in,s=e.input,r=e.avail_in,c=a.hold,d=a.bits,p=r,h=n,M=e8;a:for(;;)switch(a.mode){case 1:if(0===a.wrap){a.mode=13;break}for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(2&a.wrap&&35615===c){a.check=0,L[0]=255&c,L[1]=c>>>8&255,a.check=T(a.check,L,2,0),c=0,d=0,a.mode=2;break}if(a.flags=0,a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",a.mode=30;break}if((15&c)!==tl){e.msg="unknown compression method",a.mode=30;break}if(c>>>=4,d-=4,k=(15&c)+8,0===a.wbits)a.wbits=k;else if(k>a.wbits){e.msg="invalid window size",a.mode=30;break}a.dmax=1<<a.wbits,e.adler=a.check=1,a.mode=512&c?10:12,c=0,d=0;break;case 2:for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(a.flags=c,(255&a.flags)!==tl){e.msg="unknown compression method",a.mode=30;break}if(57344&a.flags){e.msg="unknown header flags set",a.mode=30;break}a.head&&(a.head.text=c>>8&1),512&a.flags&&(L[0]=255&c,L[1]=c>>>8&255,a.check=T(a.check,L,2,0)),c=0,d=0,a.mode=3;case 3:for(;d<32;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.head&&(a.head.time=c),512&a.flags&&(L[0]=255&c,L[1]=c>>>8&255,L[2]=c>>>16&255,L[3]=c>>>24&255,a.check=T(a.check,L,4,0)),c=0,d=0,a.mode=4;case 4:for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.head&&(a.head.xflags=255&c,a.head.os=c>>8),512&a.flags&&(L[0]=255&c,L[1]=c>>>8&255,a.check=T(a.check,L,2,0)),c=0,d=0,a.mode=5;case 5:if(1024&a.flags){for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.length=c,a.head&&(a.head.extra_len=c),512&a.flags&&(L[0]=255&c,L[1]=c>>>8&255,a.check=T(a.check,L,2,0)),c=0,d=0}else a.head&&(a.head.extra=null);a.mode=6;case 6:if(1024&a.flags&&((g=a.length)>r&&(g=r),g&&(a.head&&(k=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(s.subarray(l,l+g),k)),512&a.flags&&(a.check=T(a.check,s,g,l)),r-=g,l+=g,a.length-=g),a.length))break a;a.length=0,a.mode=7;case 7:if(2048&a.flags){if(0===r)break a;g=0;do k=s[l+g++],a.head&&k&&a.length<65536&&(a.head.name+=String.fromCharCode(k));while(k&&g<r)if(512&a.flags&&(a.check=T(a.check,s,g,l)),r-=g,l+=g,k)break a}else a.head&&(a.head.name=null);a.length=0,a.mode=8;case 8:if(4096&a.flags){if(0===r)break a;g=0;do k=s[l+g++],a.head&&k&&a.length<65536&&(a.head.comment+=String.fromCharCode(k));while(k&&g<r)if(512&a.flags&&(a.check=T(a.check,s,g,l)),r-=g,l+=g,k)break a}else a.head&&(a.head.comment=null);a.mode=9;case 9:if(512&a.flags){for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(c!==(65535&a.check)){e.msg="header crc mismatch",a.mode=30;break}c=0,d=0}a.head&&(a.head.hcrc=a.flags>>9&1,a.head.done=!0),e.adler=a.check=0,a.mode=12;break;case 10:for(;d<32;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}e.adler=a.check=to(c),c=0,d=0,a.mode=11;case 11:if(0===a.havedict)return e.next_out=o,e.avail_out=n,e.next_in=l,e.avail_in=r,a.hold=c,a.bits=d,te;e.adler=a.check=1,a.mode=12;case 12:if(t===e6||t===e7)break a;case 13:if(a.last){c>>>=7&d,d-=7&d,a.mode=27;break}for(;d<3;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}switch(a.last=1&c,d-=1,3&(c>>>=1)){case 0:a.mode=14;break;case 1:if(td(a),a.mode=20,t===e7){c>>>=2,d-=2;break a}break;case 2:a.mode=17;break;case 3:e.msg="invalid block type",a.mode=30}c>>>=2,d-=2;break;case 14:for(c>>>=7&d,d-=7&d;d<32;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if((65535&c)!=(c>>>16^65535)){e.msg="invalid stored block lengths",a.mode=30;break}if(a.length=65535&c,c=0,d=0,a.mode=15,t===e7)break a;case 15:a.mode=16;case 16:if(g=a.length){if(g>r&&(g=r),g>n&&(g=n),0===g)break a;i.set(s.subarray(l,l+g),o),r-=g,l+=g,n-=g,o+=g,a.length-=g;break}a.mode=12;break;case 17:for(;d<14;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(a.nlen=(31&c)+257,d-=5,a.ndist=(31&(c>>>=5))+1,d-=5,a.ncode=(15&(c>>>=5))+4,c>>>=4,d-=4,a.nlen>286||a.ndist>30){e.msg="too many length or distance symbols",a.mode=30;break}a.have=0,a.mode=18;case 18:for(;a.have<a.ncode;){for(;d<3;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.lens[B[a.have++]]=7&c,c>>>=3,d-=3}for(;a.have<19;)a.lens[B[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,C={bits:a.lenbits},M=e5(0,a.lens,0,19,a.lencode,0,a.work,C),a.lenbits=C.bits,M){e.msg="invalid code lengths set",a.mode=30;break}a.have=0,a.mode=19;case 19:for(;a.have<a.nlen+a.ndist;){for(;m=(_=a.lencode[c&(1<<a.lenbits)-1])>>>24,v=_>>>16&255,y=65535&_,!(m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(y<16)c>>>=m,d-=m,a.lens[a.have++]=y;else{if(16===y){for(z=m+2;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(c>>>=m,d-=m,0===a.have){e.msg="invalid bit length repeat",a.mode=30;break}k=a.lens[a.have-1],g=3+(3&c),c>>>=2,d-=2}else if(17===y){for(z=m+3;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}c>>>=m,d-=m,k=0,g=3+(7&c),c>>>=3,d-=3}else{for(z=m+7;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}c>>>=m,d-=m,k=0,g=11+(127&c),c>>>=7,d-=7}if(a.have+g>a.nlen+a.ndist){e.msg="invalid bit length repeat",a.mode=30;break}for(;g--;)a.lens[a.have++]=k}}if(30===a.mode)break;if(0===a.lens[256]){e.msg="invalid code -- missing end-of-block",a.mode=30;break}if(a.lenbits=9,C={bits:a.lenbits},M=e5(1,a.lens,0,a.nlen,a.lencode,0,a.work,C),a.lenbits=C.bits,M){e.msg="invalid literal/lengths set",a.mode=30;break}if(a.distbits=6,a.distcode=a.distdyn,C={bits:a.distbits},M=e5(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,C),a.distbits=C.bits,M){e.msg="invalid distances set",a.mode=30;break}if(a.mode=20,t===e7)break a;case 20:a.mode=21;case 21:if(r>=6&&n>=258){e.next_out=o,e.avail_out=n,e.next_in=l,e.avail_in=r,a.hold=c,a.bits=d,eQ(e,h),o=e.next_out,i=e.output,n=e.avail_out,l=e.next_in,s=e.input,r=e.avail_in,c=a.hold,d=a.bits,12===a.mode&&(a.back=-1);break}for(a.back=0;m=(_=a.lencode[c&(1<<a.lenbits)-1])>>>24,v=_>>>16&255,y=65535&_,!(m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(v&&(240&v)==0){for(w=m,x=v,b=y;m=(_=a.lencode[b+((c&(1<<w+x)-1)>>w)])>>>24,v=_>>>16&255,y=65535&_,!(w+m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}c>>>=w,d-=w,a.back+=w}if(c>>>=m,d-=m,a.back+=m,a.length=y,0===v){a.mode=26;break}if(32&v){a.back=-1,a.mode=12;break}if(64&v){e.msg="invalid literal/length code",a.mode=30;break}a.extra=15&v,a.mode=22;case 22:if(a.extra){for(z=a.extra;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.length+=c&(1<<a.extra)-1,c>>>=a.extra,d-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=23;case 23:for(;m=(_=a.distcode[c&(1<<a.distbits)-1])>>>24,v=_>>>16&255,y=65535&_,!(m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if((240&v)==0){for(w=m,x=v,b=y;m=(_=a.distcode[b+((c&(1<<w+x)-1)>>w)])>>>24,v=_>>>16&255,y=65535&_,!(w+m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}c>>>=w,d-=w,a.back+=w}if(c>>>=m,d-=m,a.back+=m,64&v){e.msg="invalid distance code",a.mode=30;break}a.offset=y,a.extra=15&v,a.mode=24;case 24:if(a.extra){for(z=a.extra;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.offset+=c&(1<<a.extra)-1,c>>>=a.extra,d-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){e.msg="invalid distance too far back",a.mode=30;break}a.mode=25;case 25:if(0===n)break a;if(g=h-n,a.offset>g){if((g=a.offset-g)>a.whave&&a.sane){e.msg="invalid distance too far back",a.mode=30;break}g>a.wnext?(g-=a.wnext,u=a.wsize-g):u=a.wnext-g,g>a.length&&(g=a.length),f=a.window}else f=i,u=o-a.offset,g=a.length;g>n&&(g=n),n-=g,a.length-=g;do i[o++]=f[u++];while(--g)0===a.length&&(a.mode=21);break;case 26:if(0===n)break a;i[o++]=a.length,n--,a.mode=21;break;case 27:if(a.wrap){for(;d<32;){if(0===r)break a;r--,c|=s[l++]<<d,d+=8}if(h-=n,e.total_out+=h,a.total+=h,h&&(e.adler=a.check=a.flags?T(a.check,i,h,o-h):U(a.check,i,h,o-h)),h=n,(a.flags?c:to(c))!==a.check){e.msg="incorrect data check",a.mode=30;break}c=0,d=0}a.mode=28;case 28:if(a.wrap&&a.flags){for(;d<32;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(c!==(0|a.total)){e.msg="incorrect length check",a.mode=30;break}c=0,d=0}a.mode=29;case 29:M=e9;break a;case 30:M=ta;break a;case 31:return ts;default:return tt}return e.next_out=o,e.avail_out=n,e.next_in=l,e.avail_in=r,a.hold=c,a.bits=d,(a.wsize||h!==e.avail_out&&a.mode<30&&(a.mode<27||t!==e4))&&tp(e,e.output,e.next_out,h-e.avail_out),p-=e.avail_in,h-=e.avail_out,e.total_in+=p,e.total_out+=h,a.total+=h,a.wrap&&h&&(e.adler=a.check=a.flags?T(a.check,i,h,e.next_out-h):U(a.check,i,h,e.next_out-h)),e.data_type=a.bits+64*!!a.last+128*(12===a.mode)+256*(20===a.mode||15===a.mode),(0===p&&0===h||t===e4)&&M===e8&&(M=ti),M},tg=e=>{if(!e||!e.state)return tt;let t=e.state;return t.window&&(t.window=null),e.state=null,e8},tu=(e,t)=>{let a,s=t.length;return e&&e.state&&(0===(a=e.state).wrap||11===a.mode)?11===a.mode&&U(1,t,s,0)!==a.check?ta:tp(e,t,s,s)?(a.mode=31,ts):(a.havedict=1,e8):tt},tf=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};let tm=Object.prototype.toString,{Z_NO_FLUSH:tv,Z_FINISH:ty,Z_OK:tw,Z_STREAM_END:tx,Z_NEED_DICT:tb,Z_STREAM_ERROR:tk,Z_DATA_ERROR:tM,Z_MEM_ERROR:tC}=$;function tz(e){this.options=eH({chunkSize:65536,windowBits:15,to:""},e||{});let t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(e&&e.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(15&t.windowBits)==0&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new eX,this.strm.avail_out=0;let a=((e,t)=>{if(!e)return tt;let a=new tr;e.state=a,a.window=null;let s=((e,t)=>{let a;if(!e||!e.state)return tt;let s=e.state;return(t<0?(a=0,t=-t):(a=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?tt:(null!==s.window&&s.wbits!==t&&(s.window=null),s.wrap=a,s.wbits=t,tn(e))})(e,t);return s!==e8&&(e.state=null),s})(this.strm,t.windowBits);if(a!==tw||(this.header=new tf,((e,t)=>{if(!e||!e.state)return;let a=e.state;return(2&a.wrap)==0||(a.head=t,t.done=!1)})(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=eE(t.dictionary):"[object ArrayBuffer]"===tm.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw)&&(a=tu(this.strm,t.dictionary))!==tw))throw Error(Y[a])}function t_(e,t){let a=new tz(t);if(a.push(e),a.err)throw a.msg||Y[a.err];return a.result}tz.prototype.push=function(e,t){let a,s,i,l=this.strm,o=this.options.chunkSize,r=this.options.dictionary;if(this.ended)return!1;for(s=t===~~t?t:!0===t?ty:tv,"[object ArrayBuffer]"===tm.call(e)?l.input=new Uint8Array(e):l.input=e,l.next_in=0,l.avail_in=l.input.length;;){for(0===l.avail_out&&(l.output=new Uint8Array(o),l.next_out=0,l.avail_out=o),(a=th(l,s))===tb&&r&&((a=tu(l,r))===tw?a=th(l,s):a===tM&&(a=tb));l.avail_in>0&&a===tx&&l.state.wrap>0&&0!==e[l.next_in];)tn(l),a=th(l,s);switch(a){case tk:case tM:case tb:case tC:return this.onEnd(a),this.ended=!0,!1}if(i=l.avail_out,l.next_out&&(0===l.avail_out||a===tx))if("string"===this.options.to){let e=eU(l.output,l.next_out),t=l.next_out-e,a=eO(l.output,e);l.next_out=t,l.avail_out=o-t,t&&l.output.set(l.output.subarray(e,e+t),0),this.onData(a)}else this.onData(l.output.length===l.next_out?l.output:l.output.subarray(0,l.next_out));if(a!==tw||0!==i){if(a===tx)return a=tg(this.strm),this.onEnd(a),this.ended=!0,!0;if(0===l.avail_in)break}}return!0},tz.prototype.onData=function(e){this.chunks.push(e)},tz.prototype.onEnd=function(e){e===tw&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=eq(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};let{Deflate:tL,deflate:tB,deflateRaw:tS,gzip:tA}={Deflate:eJ,deflate:eK,deflateRaw:function(e,t){return(t=t||{}).raw=!0,eK(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,eK(e,t)},constants:$},{Inflate:tP,inflate:tV,inflateRaw:tH,ungzip:tq}={Inflate:tz,inflate:t_,inflateRaw:function(e,t){return(t=t||{}).raw=!0,t_(e,t)},ungzip:t_,constants:$};a.d(t,{Gy:()=>tL,Kc:()=>tB,UD:()=>tV})},2338(e,t,a){let s;a.d(t,{x3j:()=>o6,aoY:()=>mF,$BZ:()=>mq,y15:()=>oA,OvW:()=>rN,Txp:()=>r1,Q5o:()=>uH,UA7:()=>uQ,JHX:()=>rU,yEg:()=>oI,UhG:()=>oP,OFB:()=>mH,Yep:()=>mE,z4o:()=>s9,Ahp:()=>mI,txp:()=>uF,rRT:()=>u1});var i=a(2718),l=a(1179),o=a(2842),r=a(4238),n=a(5633),c=a(2109),d=a(7086),p=a(2981);let h=["flowchart","mindmap","sequence","timeline","chart","state-machine","gantt","er","class","org-chart"],g=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u;function u(e){return e.length<=64&&g.test(e)}let f=i.ukk,m=i.mSG(i.QfV,i.$r1),v=Object.freeze({paper:"#f6f1e7",card:"#fffdf8",ink:"#1a1712",accent:"#8f707f"}),y=Object.freeze({accentColor:v.accent,backgroundColor:v.card});function w(e,t){return e.pipe(i.tiU(o.PyW(t)))}i.xCb(h);let x=i.xCb(["flowchart","mindmap"]),b=i.xCb(["TB","BT","LR","RL"]),k=i.xCb(["straight","orthogonal","curved"]);class M extends i.Xsx("DiagramIconRef")({slug:f.check(i.Pto(g),i.NYj(64))}){}let C=["cloud","datacenter","region","zone","vpc","subnet","cluster","namespace"],z=i.xCb(C);class _ extends i.Xsx("DiagramGroup")({id:f,label:f,parent:i.lqM(f),kind:i.lqM(z)}){}class L extends i.Xsx("DiagramLane")({id:f,label:f}){}let B=["database","queue","document","storage"],S=i.xCb(B);class A extends i.Xsx("DiagramNode")({id:f,label:f,group:i.lqM(f),lane:i.lqM(f),kind:i.lqM(f),shape:i.lqM(S),icon:i.lqM(M),metadata:w(m,{})}){}class P extends i.Xsx("DiagramEdge")({id:f,source:f,target:f,label:i.lqM(f),metadata:w(m,{})}){}let V=i.QfV.check(i.Pto(/^#[0-9a-fA-F]{6}$/));class H extends i.Xsx("DiagramStyle")({accentColor:w(V,y.accentColor),backgroundColor:w(V,y.backgroundColor)}){}class q extends i.Xsx("DiagramLayout")({direction:w(b,"LR"),edgeRouting:w(k,"orthogonal")}){}class F extends i.Xsx("IntermediateDiagram")({id:f,title:f,type:w(x,"flowchart"),nodes:i.O31(A).pipe(i.fXn).check(i.tJb(1)),edges:w(i.O31(P).pipe(i.fXn),[]),groups:i.lqM(i.O31(_).pipe(i.fXn)),lanes:i.lqM(i.O31(L).pipe(i.fXn)),layout:w(q,{direction:"LR",edgeRouting:"orthogonal"}),style:w(H,y),metadata:w(m,{})}){}class I extends Error{constructor(e){super(e),this.name="DiagramValidationError"}}let E=e=>{let t=new Set;for(let a of e){if(t.has(a))return a;t.add(a)}};function O(e){let t=E(e.nodes.map(e=>e.id));if(t)throw new I(`Duplicate node id "${t}" is not allowed.`);let a=E(e.edges.map(e=>e.id));if(a)throw new I(`Duplicate edge id "${a}" is not allowed.`);let s=E((e.groups??[]).map(e=>e.id));if(s)throw new I(`Duplicate group id "${s}" is not allowed.`);let i=new Set((e.groups??[]).map(e=>e.id)),l=new Map((e.groups??[]).flatMap(e=>void 0===e.parent?[]:[[e.id,e.parent]]));for(let[e,t]of l){if(!i.has(t))throw new I(`Group "${e}" references missing parent group "${t}".`);let a=new Set([e]);for(let t=l.get(e);void 0!==t;){if(a.has(t))throw new I(`Group "${e}" is nested inside itself.`);a.add(t),t=l.get(t)}}for(let t of e.nodes)if(void 0!==t.group&&!i.has(t.group))throw new I(`Node "${t.id}" references missing group "${t.group}".`);let o=e.lanes??[],r=E(o.map(e=>e.id));if(r)throw new I(`Duplicate lane id "${r}" is not allowed.`);if(o.length>0&&(e.groups??[]).length>0)throw new I("A diagram with lanes cannot also declare groups.");let n=new Set(o.map(e=>e.id));for(let t of e.nodes){if(void 0!==t.lane&&!n.has(t.lane))throw new I(`Node "${t.id}" references missing lane "${t.lane}".`);if(void 0===t.lane&&n.size>0)throw new I(`Node "${t.id}" has no lane.`)}let c=new Set(e.nodes.map(e=>e.id));for(let t of e.edges){if(!c.has(t.source))throw new I(`Edge "${t.id}" references missing source node "${t.source}".`);if(!c.has(t.target))throw new I(`Edge "${t.id}" references missing target node "${t.target}".`);if(t.source===t.target)throw new I(`Edge "${t.id}" cannot connect node "${t.source}" to itself.`)}return e}function U(e){return O(i.svK(F,{errors:"all"})(e))}let X="chart",T=["bar","line","pie"],Y=["vertical","horizontal"],$=i.xCb(T),G=i.xCb(Y);class D extends i.Xsx("ChartSeries")({name:i.Qrq(i.ukk),values:i.O31(i.wYs).pipe(i.fXn)}){}class R extends i.Xsx("ChartDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(X),kind:$,categories:i.O31(i.ukk).pipe(i.fXn,i.Sr8(i.tJb(1))),series:i.O31(D).pipe(i.fXn,i.Sr8(i.tJb(1))),unit:i.Qrq(i.ukk),categoryAxisTitle:i.Qrq(i.ukk),valueAxisTitle:i.Qrq(i.ukk),stacked:i.Qrq(i.v8c),donut:i.Qrq(i.v8c),orientation:i.Qrq(G),style:H.pipe(i.tiU(o.PyW({...y})))}){}let Z=e=>e.trim().toLowerCase();function j(e){let t=[],{categories:a,kind:s,series:i}=e,l="pie"===s,o=l?8:40;a.length>o&&t.push({code:"chart_too_large",path:"categories",message:`A ${s} chart supports at most ${o} ${l?"slices":"categories"}.`,hint:l?'Fold the smallest slices into one "Other" slice, or use a bar chart.':"Group categories, or split the data into several charts."}),i.length>6&&t.push({code:"chart_too_large",path:"series",message:"A chart supports at most 6 series.",hint:"Keep the series the request compares, or split them into several charts."}),a.length*i.length>120&&t.push({code:"chart_too_large",path:"series",message:"A chart supports at most 120 values (categories × series).",hint:"Split the data into several charts."});let r=new Set;a.forEach((e,a)=>{r.has(Z(e))&&t.push({code:"duplicate_chart_category",path:`categories.[${a}]`,message:`Category "${e}" is listed more than once.`,hint:"List each category once; put its values for every series at the same position."}),r.add(Z(e))}),l&&1!==i.length&&t.push({code:"invalid_chart_series",path:"series",message:"A pie chart has exactly one series.",hint:"Use one series of slice values, or a grouped bar chart to compare several series."});let n=new Set;i.forEach((e,s)=>{let o=`series.[${s}]`;i.length>1&&void 0===e.name&&t.push({code:"invalid_chart_series",path:`${o}.name`,message:`Series ${s+1} needs a name for the legend.`,hint:"Name every series when a chart has more than one."}),void 0!==e.name&&(n.has(Z(e.name))&&t.push({code:"invalid_chart_series",path:`${o}.name`,message:`Series name "${e.name}" is used more than once.`,hint:"Give each series a distinct name."}),n.add(Z(e.name))),e.values.length!==a.length&&t.push({code:"chart_series_mismatch",path:`${o}.values`,message:`Series ${e.name?`"${e.name}"`:s+1} has ${e.values.length} values for ${a.length} categories.`,hint:"Give every series exactly one value per category, in category order."}),l&&e.values.some(e=>e<0)&&t.push({code:"invalid_chart_value",path:`${o}.values`,message:"Pie slice values cannot be negative.",hint:"Use a bar chart for data with negative values."})}),l&&i[0]&&!i[0].values.some(e=>e>0)&&t.push({code:"invalid_chart_value",path:"series.[0].values",message:"A pie chart needs at least one positive slice value.",hint:"Supply the slice values from the request."});let c=(e,a,s,i)=>{a||t.push({code:"invalid_chart_option",path:e,message:s,hint:i})};for(let t of(e.stacked&&c("stacked","bar"===s,"Only bar charts stack.",'Remove stacked, or use kind: "bar".'),e.donut&&c("donut",l,"Only pie charts draw as a donut.",'Remove donut, or use kind: "pie".'),void 0!==e.orientation&&c("orientation","bar"===s,"Only bar charts have an orientation.","Remove orientation for line and pie charts."),["categoryAxisTitle","valueAxisTitle"]))void 0!==e[t]&&c(t,!l,"A pie chart has no axes.",`Remove ${t} from the pie chart.`);return t.slice(0,20)}class N extends I{issues;constructor(e){super(e[0]?.message??"Chart failed validation."),this.issues=e,this.name="ChartValidationError"}}function W(e){let t=j(e);if(t.length)throw new N(t);return e}W(i.svK(R,{errors:"all"})({id:"quarterly-revenue-chart",title:"Quarterly revenue",type:"chart",kind:"bar",categories:["Q1","Q2","Q3","Q4"],series:[{name:"2025",values:[42,51,47,63]},{name:"2026",values:[48,57,61,72]}],unit:"$M",categoryAxisTitle:"Quarter",valueAxisTitle:"Revenue"}));let J="timeline",K=["event","milestone"],Q=i.xCb(K);class ee extends i.Xsx("TimelineEvent")({id:i.ukk,label:i.ukk,date:i.Qrq(i.ukk),end:i.Qrq(i.ukk),order:i.Qrq(i.wYs),kind:i.Qrq(Q),lane:i.Qrq(i.ukk),description:i.Qrq(i.ukk)}){}class et extends i.Xsx("TimelineDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(J),events:i.O31(ee).pipe(i.fXn,i.Sr8(i.tJb(1))),lanes:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),today:i.Qrq(i.ukk),style:H.pipe(i.tiU(o.PyW({...y})))}){}let ea=/^(\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2}))?)?)?$/u;function es(e,t,a,s=0,i=0,l=0,o=0){let r=new Date(0);return r.setUTCFullYear(e,t-1,a),r.setUTCHours(s,i,l,o),r.getTime()}function ei(e){let t=ea.exec(e);if(!t)return;let[,a,s,i,l,o,r,n,c]=t,d=Number(a),p=void 0===s?1:Number(s),h=void 0===i?1:Number(i);if(p<1||p>12||h<1||h>new Date(es(d,p+1,0)).getUTCDate())return;if(void 0===l){let e=void 0!==i?"day":void 0!==s?"month":"year",t=es(d,p,h),a="day"===e?es(d,p,h+1):"month"===e?es(d,p+1,1):es(d+1,1,1);return{granularity:e,start:t,end:a,fields:{year:d,month:p,day:h,hour:0,minute:0,second:0,millisecond:0}}}let g=Number(l),u=Number(o),f=void 0===r?0:Number(r),m=void 0===n?0:Number(n.padEnd(3,"0"));if(g>23||u>59||f>59||void 0===c)return;let v=0;if("Z"!==c){let e=Number(c.slice(1,3)),t=Number(c.slice(4,6));if(e>14||t>59)return;v=(c.startsWith("-")?-1:1)*(60*e+t)}let y=es(d,p,h,g,u,f,m)-6e4*v;return{granularity:"instant",start:y,end:y,fields:{year:d,month:p,day:h,hour:g,minute:u,second:f,millisecond:m},offsetMinutes:v}}let el="Use YYYY, YYYY-MM, YYYY-MM-DD, or YYYY-MM-DDTHH:mm[:ss] with Z or ±HH:MM, copied from the source.";function eo(e){if(e.lanes)return[...e.lanes];let t=[];for(let a of ep(e))void 0===a.lane||t.includes(a.lane)||t.push(a.lane);return t}function er(e){let t=[];(0===e.events.length||e.events.length>60)&&t.push({code:"timeline_too_large",path:"events",message:"Timeline needs 1–60 events.",hint:"Provide at least one event, or split a longer chronology into timelines."});let a=new Set,s=e.events[0]?.date!==void 0,i=void 0!==e.lanes||e.events.some(e=>e.lane);return e.events.forEach((l,o)=>{let r=`events.[${o}]`;a.has(l.id)&&t.push({code:"duplicate_event_id",path:`${r}.id`,message:`Event id "${l.id}" is duplicated.`,hint:"Give each event a unique stable id."}),a.add(l.id);let n=void 0===l.date?void 0:ei(l.date);if(void 0===l.date||n||t.push({code:"invalid_timeline_date",path:`${r}.date`,message:`Event "${l.id}" has invalid date "${l.date}".`,hint:el}),(void 0!==l.date==(void 0!==l.order)||void 0!==l.date!==s)&&t.push({code:"invalid_timeline_order",path:r,message:"Every event must use exactly one chronology field, with the same date or order mode throughout.",hint:"Supply dates for all events, or numeric order for all events; never invent a missing date."}),void 0!==l.end){let e=ei(l.end);e?(void 0===l.date||"milestone"===l.kind||n&&e.end<=n.start)&&t.push({code:"invalid_timeline_span",path:`${r}.end`,message:`Span "${l.id}" needs a date, an end on or after it, and no milestone kind.`,hint:"Use end only for dated phases; a milestone is a single point."}):t.push({code:"invalid_timeline_date",path:`${r}.end`,message:`Event "${l.id}" has invalid end "${l.end}".`,hint:el})}i&&(void 0===l.lane||e.lanes&&!e.lanes.includes(l.lane))&&t.push({code:"invalid_timeline_lane",path:`${r}.lane`,message:`Event "${l.id}" needs one of the timeline's lanes.`,hint:"Give every event a lane listed in lanes, or omit lanes everywhere."})}),e.lanes&&new Set(e.lanes).size!==e.lanes.length&&t.push({code:"invalid_timeline_lane",path:"lanes",message:"Lane names must be unique.",hint:"List each lane once, in top-to-bottom order."}),eo(e).length>6&&t.push({code:"timeline_too_large",path:"lanes",message:"Timeline supports at most 6 lanes.",hint:"Merge related tracks or split the chronology into timelines."}),void 0===e.today||s&&void 0!==ei(e.today)||t.push({code:"invalid_timeline_date",path:"today",message:`Today "${e.today}" must be a valid date on a dated timeline.`,hint:`${el} Omit today unless the source states it.`}),t.slice(0,20)}class en extends I{issues;constructor(e){super(e[0]?.message??"Timeline failed validation."),this.issues=e,this.name="TimelineValidationError"}}function ec(e){let t=er(e);if(t.length)throw new en(t);return e}function ed(e){return void 0!==e.date?ei(e.date)?.start??0/0:e.order??0}function ep(e){return e.events.toSorted((e,t)=>ed(e)-ed(t)||0)}ec(i.svK(et,{errors:"all"})({id:"release-timeline",title:"Release milestones",type:"timeline",events:[{id:"plan",label:"Scope agreed",date:"2026-09-01"},{id:"beta",label:"Public beta",date:"2026-09-15",description:"Collect feedback from early users."},{id:"release",label:"General availability",date:"2026-10-01",kind:"milestone"}]}));let eh="flowchart",eg=i.xCb(["duplicate_node_id","duplicate_edge_id","missing_edge_source","missing_edge_target","self_loop","missing_start","multiple_starts","missing_end","start_has_incoming","end_has_outgoing","unreachable_node","missing_outgoing_edge","underbranched_decision","unlabeled_decision_branch","duplicate_decision_branch_label","nonterminating_node","flowchart_too_large","duplicate_group_id","unknown_node_group","empty_group","unknown_group_parent","group_cycle","shaped_decision","duplicate_lane_id","unknown_node_lane","empty_lane","lanes_with_groups"]);class eu extends i.Xsx("FlowchartValidationIssueRef")({kind:i.xCb(["diagram","node","edge","group","lane"]),id:i.lqM(i.ukk),path:i.lqM(i.ukk)}){}i.Xsx("FlowchartValidationIssue")({code:eg,ref:i.lqM(eu),message:i.ukk,hint:i.ukk});let ef=i.xCb(["start","process","decision","end"]);class em extends A.extend("FlowchartNode")({kind:ef,description:i.lqM(i.ukk)}){}class ev extends P.extend("FlowchartEdge")({label:i.lqM(i.ukk)}){}class ey extends F.extend("FlowchartDiagram")({type:i.uSQ(eh),nodes:i.O31(em).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(ev).pipe(i.fXn).check(i.tJb(1))}){}function ew(e){let t=new Set,a=new Set;for(let s of e)t.has(s)?a.add(s):t.add(s);return[...a]}function ex(e,t,a){let s=new Set,i=[...e];for(let e=0;e<i.length;e+=1){let l=i[e];if(!(void 0===l||s.has(l)))for(let e of(s.add(l),t.get(l)??[]))i.push(a(e))}return s}function eb(e){let t=[],a=new Set(e.nodes.map(e=>e.id)),{incoming:s,outgoing:i}=function(e){let t=new Map,a=new Map;for(let s of e)t.set(s.target,[...t.get(s.target)??[],s]),a.set(s.source,[...a.get(s.source)??[],s]);return{incoming:t,outgoing:a}}(e.edges);e.nodes.length>24&&t.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"nodes"},message:`Flowchart has ${e.nodes.length} nodes; the supported maximum is 24.`,hint:"Split the workflow or combine lower-signal steps."}),e.edges.length>64&&t.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"edges"},message:`Flowchart has ${e.edges.length} edges; the supported maximum is 64.`,hint:"Split the workflow or remove lower-signal connections."});let l=e.groups??[];for(let a of(l.length>8&&t.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"groups"},message:`Flowchart has ${l.length} groups; the supported maximum is 8.`,hint:"Merge related groups or leave minor steps ungrouped."}),ew(l.map(e=>e.id))))t.push({code:"duplicate_group_id",ref:{kind:"group",id:a,path:"groups"},message:`Group id "${a}" is used more than once.`,hint:"Give every group a stable unique id."});let o=new Set(l.map(e=>e.id));for(let a of e.nodes)void 0===a.group||o.has(a.group)||t.push({code:"unknown_node_group",ref:{kind:"node",id:a.id,path:"nodes.group"},message:`Node "${a.id}" references undeclared group "${a.group}".`,hint:o.size>0?`Set group to a declared group id (${[...o].map(e=>`"${e}"`).join(", ")}) or declare "${a.group}" in groups.`:`Declare "${a.group}" in groups as { id, label }, or remove the node's group.`});t.push(...function(e){let t=e.groups??[],a=new Set(t.map(e=>e.id)),s=new Map(t.flatMap(e=>void 0!==e.parent&&a.has(e.parent)?[[e.id,e.parent]]:[])),i=[],l=0;for(let e of t){if(void 0!==e.parent&&!a.has(e.parent)){i.push({code:"unknown_group_parent",ref:{kind:"group",id:e.id,path:"groups.parent"},message:`Group "${e.id}" references undeclared parent group "${e.parent}".`,hint:`Set parent to the id of the declared group that encloses it (${[...a].map(e=>`"${e}"`).join(", ")}), or remove parent.`});continue}let t=[e.id],o=!1;for(let a=s.get(e.id);void 0!==a;){if(t.includes(a)){o=!0,a===e.id&&i.push({code:"group_cycle",ref:{kind:"group",id:e.id,path:"groups.parent"},message:`Group "${e.id}" is nested inside itself through ${[...t,a].map(e=>`"${e}"`).join(" in ")}.`,hint:"Set each group's parent to the group that encloses it; the outermost group has no parent."});break}t.push(a),a=s.get(a)}o||(l=Math.max(l,t.length))}return l>4&&i.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"groups.parent"},message:`Groups nest ${l} deep; the supported maximum is 4.`,hint:"Drop an intermediate zone, or merge a zone into its parent."}),i}(e));let r=new Set([...e.nodes.map(e=>e.group),...l.map(e=>e.parent)]);for(let e of l.filter(e=>!r.has(e.id)))t.push({code:"empty_group",ref:{kind:"group",id:e.id,path:"groups"},message:`Group "${e.id}" has no nodes.`,hint:"Set group on the nodes it holds, or remove the group."});for(let a of e.nodes)"decision"===a.kind&&void 0!==a.shape&&t.push({code:"shaped_decision",ref:{kind:"node",id:a.id,path:"nodes.shape"},message:`Decision node "${a.id}" cannot draw as a ${a.shape}.`,hint:"Remove shape from the decision; a decision always draws as a diamond."});for(let a of(t.push(...function(e){let t=e.lanes??[];if(0===t.length)return e.nodes.flatMap(e=>void 0===e.lane?[]:[{code:"unknown_node_lane",ref:{kind:"node",id:e.id,path:"nodes.lane"},message:`Node "${e.id}" references undeclared lane "${e.lane}".`,hint:`Declare "${e.lane}" in lanes as { id, label }, or remove the node's lane.`}]);let a=[];for(let s of(t.length>8&&a.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"lanes"},message:`Flowchart has ${t.length} lanes; the supported maximum is 8.`,hint:"Merge related actors into one lane."}),(e.groups??[]).length>0&&a.push({code:"lanes_with_groups",ref:{kind:"diagram",id:e.id,path:"groups"},message:"A flowchart with lanes cannot also declare groups.",hint:"Keep lanes for the actors and remove groups and every node's group."}),ew(t.map(e=>e.id))))a.push({code:"duplicate_lane_id",ref:{kind:"lane",id:s,path:"lanes"},message:`Lane id "${s}" is used more than once.`,hint:"Give every lane a stable unique id."});let s=new Set(t.map(e=>e.id)),i=[...s].map(e=>`"${e}"`).join(", ");for(let t of e.nodes)void 0!==t.lane&&s.has(t.lane)||a.push({code:"unknown_node_lane",ref:{kind:"node",id:t.id,path:"nodes.lane"},message:void 0===t.lane?`Node "${t.id}" has no lane.`:`Node "${t.id}" references undeclared lane "${t.lane}".`,hint:void 0===t.lane?`Set lane to the declared lane id (${i}) of the actor that does this step.`:`Set lane to a declared lane id (${i}) or declare "${t.lane}" in lanes.`});let l=new Set(e.nodes.map(e=>e.lane));for(let e of t.filter(e=>!l.has(e.id)))a.push({code:"empty_lane",ref:{kind:"lane",id:e.id,path:"lanes"},message:`Lane "${e.id}" has no nodes.`,hint:"Set lane on the steps this actor does, or remove the lane."});return a}(e)),ew(e.nodes.map(e=>e.id))))t.push({code:"duplicate_node_id",ref:{kind:"node",id:a,path:"nodes"},message:`Node id "${a}" is used more than once.`,hint:"Give every node a stable unique id."});for(let a of ew(e.edges.map(e=>e.id)))t.push({code:"duplicate_edge_id",ref:{kind:"edge",id:a,path:"edges"},message:`Edge id "${a}" is used more than once.`,hint:"Give every edge a stable unique id."});for(let s of e.edges)a.has(s.source)||t.push({code:"missing_edge_source",ref:{kind:"edge",id:s.id,path:"edges.source"},message:`Edge "${s.id}" references missing source node "${s.source}".`,hint:"Set edge.source to one of the diagram node ids."}),a.has(s.target)||t.push({code:"missing_edge_target",ref:{kind:"edge",id:s.id,path:"edges.target"},message:`Edge "${s.id}" references missing target node "${s.target}".`,hint:"Set edge.target to one of the diagram node ids."}),s.source===s.target&&t.push({code:"self_loop",ref:{kind:"edge",id:s.id},message:`Edge "${s.id}" connects node "${s.source}" to itself.`,hint:"Connect the edge to a different target node."});let n=e.nodes.filter(e=>"start"===e.kind),c=e.nodes.filter(e=>"end"===e.kind);for(let a of(0===n.length?t.push({code:"missing_start",ref:{kind:"diagram",id:e.id,path:"nodes"},message:"Flowchart must contain exactly one start node.",hint:'Mark the first node in the flow with kind: "start".'}):n.length>1&&t.push({code:"multiple_starts",ref:{kind:"diagram",id:e.id,path:"nodes"},message:`Flowchart has ${n.length} start nodes.`,hint:"Keep one start node and change the others to process, decision, or end."}),0===c.length&&t.push({code:"missing_end",ref:{kind:"diagram",id:e.id,path:"nodes"},message:"Flowchart must contain at least one end node.",hint:'Add an end node or mark terminal outcomes with kind: "end".'}),e.nodes)){let e=s.get(a.id)??[],l=i.get(a.id)??[];"start"===a.kind&&e.length>0&&t.push({code:"start_has_incoming",ref:{kind:"node",id:a.id},message:`Start node "${a.id}" cannot have incoming edges.`,hint:"Route the start node only to later nodes."}),"end"===a.kind&&l.length>0&&t.push({code:"end_has_outgoing",ref:{kind:"node",id:a.id},message:`End node "${a.id}" cannot have outgoing edges.`,hint:"End nodes must be terminal outcomes."}),"end"!==a.kind&&0===l.length&&t.push({code:"missing_outgoing_edge",ref:{kind:"node",id:a.id},message:`Node "${a.id}" must have at least one outgoing edge.`,hint:'Connect it to the next step, or mark it as kind: "end".'}),"decision"===a.kind&&t.push(...function(e,t){let a=[];t.length<2&&a.push({code:"underbranched_decision",ref:{kind:"node",id:e.id},message:`Decision node "${e.id}" must have at least two outgoing branches.`,hint:"Add at least two outgoing edges for the decision outcomes."});let s=t.map(e=>e.label?.trim()??"");for(let s of t.filter(e=>!e.label?.trim()))a.push({code:"unlabeled_decision_branch",ref:{kind:"edge",id:s.id,path:"edges.label"},message:`Decision node "${e.id}" has an outgoing branch without a label.`,hint:'Add a short branch label such as "yes", "no", "approved", or "rejected".'});for(let t of ew(s.filter(e=>e.length>0).map(e=>e.toLowerCase())))a.push({code:"duplicate_decision_branch_label",ref:{kind:"node",id:e.id},message:`Decision node "${e.id}" repeats branch label "${t}".`,hint:"Make every outgoing branch label from the same decision unique."});return a}(a,l))}let d=1===n.length?n[0]:void 0;if(d){let a=ex([d.id],i,e=>e.target);for(let s of e.nodes)a.has(s.id)||t.push({code:"unreachable_node",ref:{kind:"node",id:s.id},message:`Node "${s.id}" is not reachable from the start node.`,hint:"Connect every node to the flow that begins at the single start node."});if(c.length>0){let l=ex(c.map(e=>e.id),s,e=>e.source);for(let s of e.nodes)a.has(s.id)&&!l.has(s.id)&&(i.get(s.id)?.length??0)>0&&t.push({code:"nonterminating_node",ref:{kind:"node",id:s.id},message:`Node "${s.id}" cannot reach an end node.`,hint:"Add an eventual exit from this path to an end node; retry loops are valid when they retain an exit."})}}return t.slice(0,20)}class ek extends I{issues;constructor(e){super(e[0]?.message??"Flowchart failed semantic validation."),this.issues=e,this.name="FlowchartValidationError"}}function eM(e){let t=eb(e);if(t.length>0)throw new ek(t);return e}function eC(e){return eM(i.svK(ey,{errors:"all"})(e))}eC({id:"onboarding-flow",title:"Sketchi onboarding decision flow",type:eh,nodes:[{id:"prompt",label:"Prompt received",kind:"start"},{id:"requirements",label:"Extract requirements",kind:"process"},{id:"clear",label:"Scope clear?",kind:"decision"},{id:"draft",label:"Draft typed IR",kind:"process"},{id:"review",label:"Review diagram",kind:"end"}],edges:[{id:"prompt-requirements",source:"prompt",target:"requirements"},{id:"requirements-clear",source:"requirements",target:"clear"},{id:"clear-draft",source:"clear",target:"draft",label:"yes"},{id:"clear-review",source:"clear",target:"review",label:"no"},{id:"draft-review",source:"draft",target:"review"}],layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"pharma-batch-disposition",title:"Pharma batch disposition flow",type:eh,nodes:[{id:"batch-received",label:"Batch received",kind:"start"},{id:"qa-review",label:"QA reviews Certificate of Analysis",kind:"process"},{id:"passes-specs",label:"Passes specs?",kind:"decision"},{id:"final-review",label:"QA Manager final review",kind:"process"},{id:"packaging",label:"Send to packaging",kind:"end"},{id:"investigate",label:"Investigate retesting",kind:"process"},{id:"reject",label:"Reject batch",kind:"end"}],edges:[{id:"batch-qa",source:"batch-received",target:"qa-review"},{id:"qa-specs",source:"qa-review",target:"passes-specs"},{id:"specs-pass",source:"passes-specs",target:"final-review",label:"yes"},{id:"specs-investigate",source:"passes-specs",target:"investigate",label:"retest"},{id:"specs-reject",source:"passes-specs",target:"reject",label:"reject"},{id:"review-packaging",source:"final-review",target:"packaging"},{id:"investigate-review",source:"investigate",target:"final-review"}],layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"deploy-pipeline-logos",title:"Deploy pipeline",type:eh,nodes:[{id:"push",label:"Push to GitHub",kind:"start",icon:{slug:"github"}},{id:"build",label:"Build the Docker image",kind:"process",icon:{slug:"docker"}},{id:"tests",label:"Tests pass?",kind:"decision",icon:{slug:"vitest"}},{id:"fix",label:"Fix the failing tests",kind:"process"},{id:"ship",label:"Ship to Cloudflare Workers",kind:"end",icon:{slug:"cloudflare"}}],edges:[{id:"push-build",source:"push",target:"build"},{id:"build-tests",source:"build",target:"tests"},{id:"tests-ship",source:"tests",target:"ship",label:"yes"},{id:"tests-fix",source:"tests",target:"fix",label:"no"},{id:"fix-build",source:"fix",target:"build"}],layout:{direction:"TB",edgeRouting:"orthogonal"}});let ez="mindmap";class e_ extends i.Xsx("MindmapNodeMetadata")({depth:i.Aiz.check(i.OWK(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class eL extends A.extend("MindmapNode")({kind:i.xCb(["root","topic"]),metadata:e_}){}class eB extends i.Xsx("MindmapEdgeMetadata")({depth:i.Aiz.check(i.yJO(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class eS extends P.extend("MindmapEdge")({metadata:eB}){}class eA extends F.extend("MindmapDiagram")({type:i.uSQ(ez),nodes:i.O31(eL).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(eS).pipe(i.fXn).check(i.tJb(1))}){}function eP(e){O(e);let t=e.nodes.filter(e=>"root"===e.kind);if(1!==t.length)throw new I(`Mindmap must contain exactly one root topic; found ${t.length}.`);let a=t[0];if(!a||0!==a.metadata.depth)throw new I("Mindmap root topic must have depth 0.");let s=new Map,i=new Map(e.nodes.map(e=>[e.id,e])),l=new Map;for(let t of e.edges){s.set(t.target,(s.get(t.target)??0)+1);let e=i.get(t.source)?.metadata.depth,a=i.get(t.target),o=a?.metadata.depth;if(void 0===e||o!==e+1)throw new I(`Mindmap edge "${t.id}" must connect a topic to its immediate child.`);if(!a||t.metadata.depth!==a.metadata.depth||t.metadata.siblingIndex!==a.metadata.siblingIndex)throw new I(`Mindmap edge "${t.id}" metadata must match its child topic.`);l.set(t.source,[...l.get(t.source)??[],a.metadata.siblingIndex])}for(let t of e.nodes){let e=s.get(t.id)??0;if(t.id===a.id?0!==e:1!==e)throw new I(`Mindmap topic "${t.id}" must have ${t.id===a.id?"no parent":"exactly one parent"}.`)}for(let[e,t]of l){let a=t.map((e,t)=>t);if([...t].sort((e,t)=>e-t).some((e,t)=>e!==a[t]))throw new I(`Mindmap children of "${e}" must use contiguous sibling ordering from 0.`)}return e}function eV(e){return eP(i.svK(eA,{errors:"all"})(e))}eV({id:"public-mindmap-capability",title:"Public mindmap generation",type:ez,nodes:[{id:"topic-0",label:"Public mindmaps",kind:"root",metadata:{depth:0,siblingIndex:0}},{id:"topic-0-0",label:"Semantic input",kind:"topic",metadata:{depth:1,siblingIndex:0}},{id:"topic-0-0-0",label:"Nested topics",kind:"topic",metadata:{depth:2,siblingIndex:0}},{id:"topic-0-0-1",label:"Stable ordering",kind:"topic",metadata:{depth:2,siblingIndex:1}},{id:"topic-0-1",label:"Artifact output",kind:"topic",metadata:{depth:1,siblingIndex:1}},{id:"topic-0-1-0",label:"Scene",kind:"topic",metadata:{depth:2,siblingIndex:0}},{id:"topic-0-1-1",label:"Excalidraw",kind:"topic",metadata:{depth:2,siblingIndex:1}}],edges:[{id:"branch-0-0",source:"topic-0",target:"topic-0-0",metadata:{depth:1,siblingIndex:0}},{id:"branch-0-0-0",source:"topic-0-0",target:"topic-0-0-0",metadata:{depth:2,siblingIndex:0}},{id:"branch-0-0-1",source:"topic-0-0",target:"topic-0-0-1",metadata:{depth:2,siblingIndex:1}},{id:"branch-0-1",source:"topic-0",target:"topic-0-1",metadata:{depth:1,siblingIndex:1}},{id:"branch-0-1-0",source:"topic-0-1",target:"topic-0-1-0",metadata:{depth:2,siblingIndex:0}},{id:"branch-0-1-1",source:"topic-0-1",target:"topic-0-1-1",metadata:{depth:2,siblingIndex:1}}],layout:{direction:"LR",edgeRouting:"curved"}});let eH="sequence",eq=["message","return"],eF=["solid","dashed"],eI=":lifeline";function eE(e){return`${e}${eI}`}let eO=i.xCb(eq),eU=i.xCb(eF);class eX extends i.Xsx("SequenceParticipant")({id:i.ukk,label:i.ukk,kind:i.Qrq(i.ukk),icon:i.Qrq(M)}){}class eT extends i.Xsx("SequenceMessage")({id:i.ukk,source:i.ukk,target:i.ukk,label:i.ukk,type:i.Qrq(eO),style:i.Qrq(eU)}){}class eY extends i.Xsx("SequenceDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(eH),participants:i.O31(eX).pipe(i.fXn,i.Sr8(i.tJb(1))),messages:i.O31(eT).pipe(i.fXn,i.tiU(o.PyW([]))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let e$=i.xCb(["sequence_too_large","duplicate_participant_id","lifeline_id_collision","duplicate_message_id","missing_message_source","missing_message_target","self_message"]);function eG(e){let t=[];e.participants.length>12&&t.push({code:"sequence_too_large",path:"participants",message:`Sequence diagram has ${e.participants.length} participants; the supported maximum is 12.`,hint:"Combine minor actors or split the interaction into several diagrams."}),e.messages.length>40&&t.push({code:"sequence_too_large",path:"messages",message:`Sequence diagram has ${e.messages.length} messages; the supported maximum is 40.`,hint:"Split the interaction into phases or drop lower-signal messages."});let a=new Map;for(let s of(e.participants.forEach((e,s)=>{a.has(e.id)?t.push({code:"duplicate_participant_id",path:`participants.[${s}].id`,message:`Participant id "${e.id}" is duplicated.`,hint:"Give every participant a unique stable id and update message references."}):a.set(e.id,s)}),e.participants)){let a=eE(s.id);e.participants.forEach((e,i)=>{(e.id===a||e.id.startsWith(`${a}:`))&&t.push({code:"lifeline_id_collision",path:`participants.[${i}].id`,message:`Participant id "${e.id}" collides with the generated lifeline for "${s.id}".`,hint:`Rename the participant so its id does not start with another participant id followed by ${eI}.`})})}let s=new Set;return e.messages.forEach((e,i)=>{s.has(e.id)&&t.push({code:"duplicate_message_id",path:`messages.[${i}].id`,message:`Message id "${e.id}" is duplicated.`,hint:"Give every message a unique id or omit message ids to generate them deterministically."}),s.add(e.id),a.has(e.source)||t.push({code:"missing_message_source",path:`messages.[${i}].source`,message:`Message source "${e.source}" is not a participant.`,hint:"Use the id of a participant declared in participants."}),a.has(e.target)||t.push({code:"missing_message_target",path:`messages.[${i}].target`,message:`Message target "${e.target}" is not a participant.`,hint:"Use the id of a participant declared in participants."}),e.source===e.target&&t.push({code:"self_message",path:`messages.[${i}]`,message:`Message "${e.id}" is self-referential.`,hint:"Choose a different target participant; self messages are not supported."})}),t.slice(0,20)}i.Xsx("SequenceValidationIssue")({code:e$,path:i.ukk,message:i.ukk,hint:i.ukk});class eD extends I{issues;constructor(e){super(e[0]?.message??"Sequence diagram failed semantic validation."),this.issues=e,this.name="SequenceValidationError"}}function eR(e){let t=eG(e);if(t.length>0)throw new eD(t);return e}function eZ(e){return eR(i.svK(eY,{errors:"all"})(e))}eZ({id:"checkout-sequence",title:"Checkout sequence",type:eH,participants:[{id:"customer",label:"Customer"},{id:"store",label:"Store"},{id:"payments",label:"Payments"}],messages:[{id:"checkout",source:"customer",target:"store",label:"Submit checkout"},{id:"charge",source:"store",target:"payments",label:"Charge card"},{id:"charged",source:"payments",target:"store",label:"Payment approved",type:"return"},{id:"receipt",source:"store",target:"customer",label:"Order receipt",type:"return"}]}),eZ({id:"api-request-sequence",title:"API request with cache miss",type:eH,participants:[{id:"browser",label:"Browser"},{id:"api",label:"API Worker"},{id:"cache",label:"Cache"},{id:"database",label:"Database"},{id:"analytics",label:"Analytics"}],messages:[{id:"request",source:"browser",target:"api",label:"GET /orders"},{id:"lookup",source:"api",target:"cache",label:"Look up orders"},{id:"miss",source:"cache",target:"api",label:"Cache miss",type:"return"},{id:"query",source:"api",target:"database",label:"Query orders"},{id:"rows",source:"database",target:"api",label:"Order rows",type:"return"},{id:"track",source:"api",target:"analytics",label:"Track request"},{id:"response",source:"api",target:"browser",label:"200 OK",type:"return"}]}),eZ({id:"deploy-webhook-logos",title:"Deploy webhook",type:eH,participants:[{id:"developer",label:"Developer"},{id:"github",label:"GitHub",icon:{slug:"github"}},{id:"worker",label:"Cloudflare Worker",icon:{slug:"cloudflare"}},{id:"docker",label:"Docker build",icon:{slug:"docker"}}],messages:[{id:"push",source:"developer",target:"github",label:"git push"},{id:"webhook",source:"github",target:"worker",label:"Push webhook"},{id:"build",source:"worker",target:"docker",label:"Build image"},{id:"digest",source:"docker",target:"worker",label:"Image digest",type:"return"},{id:"accepted",source:"worker",target:"github",label:"202 Accepted",type:"return"}]});let ej="state-machine",eN=["state","final","choice"],eW=["TB","LR"],eJ=i.xCb(eN);class eK extends i.Xsx("StateMachineState")({id:i.ukk,label:i.Qrq(i.ukk),kind:i.Qrq(eJ),parent:i.Qrq(i.ukk),initial:i.Qrq(i.ukk)}){}class eQ extends i.Xsx("StateMachineTransition")({id:i.ukk,source:i.ukk,target:i.ukk,event:i.Qrq(i.ukk),guard:i.Qrq(i.ukk),action:i.Qrq(i.ukk)}){}class e1 extends i.Xsx("StateMachineLayout")({direction:i.xCb(eW)}){}class e0 extends i.Xsx("StateMachineDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(ej),initial:i.ukk,states:i.O31(eK).pipe(i.fXn,i.Sr8(i.tJb(1))),transitions:i.O31(eQ).pipe(i.fXn,i.tiU(o.PyW([]))),layout:i.Qrq(e1),style:H.pipe(i.tiU(o.PyW({...y})))}){}let e2=i.xCb(["state_machine_too_large","invalid_state_id","duplicate_state_id","duplicate_transition_id","missing_state_label","unknown_initial_state","unknown_parent_state","nested_composite","missing_transition_source","missing_transition_target","final_has_outgoing","composite_member_transition","missing_composite_initial","underbranched_choice","unguarded_choice_branch","unreachable_state"]);function e3(e){return e.kind??"state"}i.Xsx("StateMachineValidationIssue")({code:e2,path:i.ukk,message:i.ukk,hint:i.ukk});let e5=new Set(["end","ended","final","finish","finished","done","stop","stopped","exit","state","node"]);function e4(e){if(void 0!==e.label)return e.label;let t=e3(e);if("choice"!==t){if("final"===t){let t=e.id.replace(/(\p{Ll})(\p{Lu})/gu,"$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu,"$1 $2").split(/[_\s\-\p{N}]+/u).filter(Boolean);if(t.length>0&&t.every(e=>e5.has(e.toLowerCase())))return}return e.id}}function e6(e){return new Set(e.states.flatMap(e=>e.parent?[e.parent]:[]))}function e7(e,t){return e.replace(t,"").trim()}function e8(e){let t=[],a=e6(e);e.states.length>30&&t.push({code:"state_machine_too_large",path:"states",message:`State machine has ${e.states.length} states; the supported maximum is 30.`,hint:"Split the machine into smaller machines or merge minor states."}),e.transitions.length>60&&t.push({code:"state_machine_too_large",path:"transitions",message:`State machine has ${e.transitions.length} transitions; the supported maximum is 60.`,hint:"Move transitions every substate shares onto their composite state."}),a.size>6&&t.push({code:"state_machine_too_large",path:"states",message:`State machine has ${a.size} composite states; the supported maximum is 6.`,hint:"Flatten minor composite states into their parents."});let s=new Map;e.states.forEach((e,a)=>{e.id.includes(":")&&t.push({code:"invalid_state_id",path:`states.[${a}].id`,message:`State id "${e.id}" contains ":".`,hint:"Use letters, digits, hyphens or underscores in state ids."}),s.has(e.id)&&t.push({code:"duplicate_state_id",path:`states.[${a}].id`,message:`State id "${e.id}" is used more than once.`,hint:"Give every state a unique id."}),s.set(e.id,e);let i=e4(e);void 0===i||i.trim()||t.push({code:"missing_state_label",path:`states.[${a}].label`,message:`State "${e.id}" has no label.`,hint:"Omit the label to use the default, or provide a non-blank label."})}),e.states.forEach((e,a)=>{if(void 0!==e.parent){let i=s.get(e.parent);i&&"state"===e3(i)?void 0!==i.parent&&t.push({code:"nested_composite",path:`states.[${a}].parent`,message:`State "${e.id}" sits in "${i.id}", which itself sits in "${i.parent}".`,hint:"Composite states hold states but not other composites; flatten one level."}):t.push({code:"unknown_parent_state",path:`states.[${a}].parent`,message:`State "${e.id}" names "${e.parent}" as its parent, which is not a state.`,hint:"Set parent to the id of a state (not a final state or choice), or remove it."})}if(void 0!==e.initial){let i=s.get(e.initial);i&&i.parent===e.id&&"final"!==e3(i)||t.push({code:"unknown_initial_state",path:`states.[${a}].initial`,message:`Composite "${e.id}" starts in "${e.initial}", which is not one of its substates.`,hint:`Set initial to a substate whose parent is "${e.id}", or remove it.`})}});let i=s.get(e.initial);i&&a.has(i.id)&&void 0===i.initial&&t.push({code:"missing_composite_initial",path:"initial",message:`The machine starts in composite "${i.id}", which has no initial substate.`,hint:`Set initial on "${i.id}" to the substate it starts in.`}),i&&void 0===i.parent&&"final"!==e3(i)||t.push({code:"unknown_initial_state",path:"initial",message:`The machine starts in "${e.initial}", which is not a top-level state.`,hint:"Set initial to the id of the top-level state the machine starts in."});let l=new Set,o=new Map;if(e.transitions.forEach((e,i)=>{l.has(e.id)&&t.push({code:"duplicate_transition_id",path:`transitions.[${i}].id`,message:`Transition id "${e.id}" is used more than once.`,hint:"Give every transition a unique id, or omit ids to generate them."}),l.add(e.id),o.set(e.source,(o.get(e.source)??0)+1);let r=s.get(e.source),n=s.get(e.target);r||t.push({code:"missing_transition_source",path:`transitions.[${i}].source`,message:`Transition "${e.id}" leaves "${e.source}", which is not a state.`,hint:"Set source to the id of a declared state."}),n||t.push({code:"missing_transition_target",path:`transitions.[${i}].target`,message:`Transition "${e.id}" enters "${e.target}", which is not a state.`,hint:"Set target to the id of a declared state."}),r&&"final"===e3(r)&&t.push({code:"final_has_outgoing",path:`transitions.[${i}].source`,message:`Transition "${e.id}" leaves final state "${r.id}".`,hint:"A final state ends the machine; leave from the state before it instead."}),r&&n&&(a.has(r.id)&&(n.id===r.id||n.parent===r.id)||a.has(n.id)&&r.parent===n.id)&&t.push({code:"composite_member_transition",path:`transitions.[${i}]`,message:`Transition "${e.id}" joins composite "${a.has(r.id)?r.id:n.id}" to itself or its own substate.`,hint:"Connect substates to each other, or the composite to a state outside it."}),n&&a.has(n.id)&&void 0===n.initial&&t.push({code:"missing_composite_initial",path:`transitions.[${i}].target`,message:`Transition "${e.id}" enters composite "${n.id}", which has no initial substate.`,hint:`Set initial on "${n.id}" to the substate it enters first, or target that substate.`})}),e.states.forEach((a,s)=>{if("choice"===e3(a)&&(o.get(a.id)??0)<2&&t.push({code:"underbranched_choice",path:`states.[${s}]`,message:`Choice "${a.id}" has fewer than two outgoing transitions.`,hint:"Give a choice two or more outgoing transitions, each with a guard."}),"choice"!==e3(a))return;let i=e.transitions.filter(e=>e.source===a.id).map(e=>e.guard?.replace(/^\s*\[|\]\s*$/gu,"").trim()??"");(i.some(e=>""===e)||i.filter(e=>"else"===e.toLowerCase()).length>1)&&t.push({code:"unguarded_choice_branch",path:`states.[${s}]`,message:`Choice "${a.id}" has a branch without its own guard.`,hint:'Give every branch of a choice a guard; one may be "else".'})}),i){let a=function(e){let t=new Map(e.states.map(e=>[e.id,e])),a=new Set,s=new Set,i=[{id:e.initial,entry:!0}];for(;i.length>0;){let{id:l,entry:o}=i.pop(),r=t.get(l);if(!(!r||a.has(l)&&(!o||s.has(l)))){if(o&&(s.add(l),r.initial&&i.push({id:r.initial,entry:!0})),!a.has(l))for(let t of(a.add(l),r.parent&&i.push({id:r.parent,entry:!1}),e.transitions))t.source===l&&i.push({id:t.target,entry:!0})}}return a}(e);e.states.forEach((e,s)=>{a.has(e.id)||t.push({code:"unreachable_state",path:`states.[${s}]`,message:`State "${e.id}" cannot be reached from the initial state.`,hint:"Add a transition into it, or make it its composite's initial substate."})})}return t.slice(0,20)}class e9 extends I{issues;constructor(e){super(e[0]?.message??"State machine failed semantic validation."),this.issues=e,this.name="StateMachineValidationError"}}function te(e){var t=i.svK(e0,{errors:"all"})(e);let a=e8(t);if(a.length>0)throw new e9(a);return t}te({id:"order-lifecycle",title:"Order lifecycle",type:ej,initial:"pending",states:[{id:"pending",label:"Pending payment"},{id:"paid",label:"Paid"},{id:"shipped",label:"Shipped"},{id:"cancelled",label:"Cancelled"},{id:"done",kind:"final"}],transitions:[{id:"pay",source:"pending",target:"paid",event:"pay",guard:"card valid",action:"charge"},{id:"remind",source:"pending",target:"pending",event:"after 24h",action:"email"},{id:"cancel",source:"pending",target:"cancelled",event:"cancel"},{id:"ship",source:"paid",target:"shipped",event:"ship"},{id:"reject",source:"shipped",target:"paid",event:"reject shipment"},{id:"deliver",source:"shipped",target:"done",event:"deliver"},{id:"close",source:"cancelled",target:"done"}]}),te({id:"media-player",title:"Media player",type:ej,initial:"stopped",states:[{id:"stopped",label:"Stopped"},{id:"active",label:"Active",initial:"playing"},{id:"playing",label:"Playing",parent:"active"},{id:"paused",label:"Paused",parent:"active"}],transitions:[{id:"play",source:"stopped",target:"active",event:"play"},{id:"pause",source:"playing",target:"paused",event:"pause"},{id:"resume",source:"paused",target:"playing",event:"resume"},{id:"seek",source:"playing",target:"playing",event:"seek",action:"jump"},{id:"stop",source:"active",target:"stopped",event:"stop"}]});let tt="gantt";class ta extends i.Xsx("GanttTask")({id:i.ukk,label:i.ukk,start:i.ukk,end:i.Qrq(i.ukk),duration:i.Qrq(i.wYs),milestone:i.Qrq(i.v8c),phase:i.Qrq(i.ukk),dependsOn:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),progress:i.Qrq(i.wYs)}){}class ts extends i.Xsx("GanttDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(tt),tasks:i.O31(ta).pipe(i.fXn,i.Sr8(i.tJb(1))),phases:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),today:i.Qrq(i.ukk),style:H.pipe(i.tiU(o.PyW({...y})))}){}function ti(e){let t=ei(e);return t?.granularity==="day"?Math.round(t.start/864e5):void 0}function tl(e){return new Date(864e5*e).toISOString().slice(0,10)}function to(e){return!0===e.milestone||0===e.duration}function tr(e){let t=ti(e.start);if(void 0!==t){if(to(e))return{start:t,end:t,milestone:!0};if(void 0!==e.end){let a=ti(e.end);return void 0===a?void 0:{start:t,end:a+1,milestone:!1}}return void 0===e.duration?void 0:{start:t,end:t+e.duration,milestone:!1}}}function tn(e){if(e.phases)return[...e.phases];let t=[];for(let a of e.tasks)void 0===a.phase||t.includes(a.phase)||t.push(a.phase);return t}function tc(e){let t=tn(e);return 0===t.length?[{tasks:e.tasks}]:t.map(t=>({phase:t,tasks:e.tasks.filter(e=>e.phase===t)}))}let td="Use YYYY-MM-DD, copied from the source.";function tp(e){let t=[],{tasks:a}=e;(0===a.length||a.length>60)&&t.push({code:"gantt_too_large",path:"tasks",message:"A Gantt chart needs 1–60 tasks.",hint:"Provide at least one task, or split a longer plan into several charts."});let s=new Set;for(let[e,i]of a.entries())s.has(i.id)&&t.push({code:"duplicate_task_id",path:`tasks.[${e}].id`,message:`Task id "${i.id}" is duplicated.`,hint:"Give each task a unique stable id."}),s.add(i.id);let i=void 0!==e.phases||a.some(e=>void 0!==e.phase),l=0;a.forEach((a,o)=>{let r=`tasks.[${o}]`,n=ti(a.start);void 0===n&&t.push({code:"invalid_gantt_date",path:`${r}.start`,message:`Task "${a.id}" has invalid start "${a.start}".`,hint:td});let c=void 0===a.end?void 0:ti(a.end);void 0!==a.end&&void 0===c&&t.push({code:"invalid_gantt_date",path:`${r}.end`,message:`Task "${a.id}" has invalid end "${a.end}".`,hint:`${td} end is the last day, inclusive.`});let d=(e,a,s="")=>t.push({code:"invalid_gantt_span",path:`${r}${s}`,message:e,hint:a});to(a)?(!0===a.milestone&&void 0!==a.duration&&0!==a.duration&&d(`Milestone "${a.id}" cannot have a duration.`,"A milestone is one day: give it start only.",".duration"),void 0!==a.end&&void 0!==c&&void 0!==n&&c!==n&&d(`Milestone "${a.id}" cannot end on another day.`,"A milestone is one day: give it start only, or drop milestone to draw a bar.",".end")):void 0===a.end==(void 0===a.duration)?d(`Task "${a.id}" needs exactly one of end or duration.`,"Give end (last day, inclusive) or duration (calendar days), or set milestone: true."):void 0!==a.duration&&(!Number.isInteger(a.duration)||a.duration<0)?d(`Task "${a.id}" has duration ${a.duration}; durations are whole calendar days.`,"Use a whole number of days counting start, such as 5 for start through start + 4.",".duration"):void 0!==c&&void 0!==n&&c<n?d(`Task "${a.id}" ends before it starts.`,"end is the last day, inclusive, on or after start.",".end"):void 0!==a.duration&&a.duration>36525&&d(`Task "${a.id}" has duration ${a.duration}; a chart spans at most 36525 days.`,"Give the task's real length in calendar days, or split a longer plan into several charts.",".duration"),void 0!==a.progress&&(a.progress<0||a.progress>100||to(a))&&t.push({code:"invalid_gantt_progress",path:`${r}.progress`,message:`Task "${a.id}" has progress ${a.progress}.`,hint:"progress is a percent from 0 to 100, on tasks only, never milestones."}),i&&(void 0===a.phase||e.phases&&!e.phases.includes(a.phase))&&t.push({code:"invalid_gantt_phase",path:`${r}.phase`,message:`Task "${a.id}" needs one of the chart's phases.`,hint:"Give every task a phase listed in phases, or omit phases everywhere."});let p=new Set;(a.dependsOn??[]).forEach((e,i)=>{l+=1;let o=`${r}.dependsOn.[${i}]`;e===a.id?t.push({code:"self_dependency",path:o,message:`Task "${a.id}" depends on itself.`,hint:"List only the tasks that must finish before this one starts."}):s.has(e)?p.has(e)&&t.push({code:"missing_dependency",path:o,message:`Task "${a.id}" lists "${e}" more than once.`,hint:"List each predecessor once."}):t.push({code:"missing_dependency",path:o,message:`Task "${a.id}" depends on unknown task "${e}".`,hint:"Use the id of a task declared in tasks."}),p.add(e)})}),l>120&&t.push({code:"gantt_too_large",path:"tasks",message:"A Gantt chart supports at most 120 dependencies.",hint:"Keep the dependencies the plan states, or split it into several charts."});let o=function(e){let t=new Map(e.map(e=>[e.id,e])),a=new Map,s=[],i=e=>{if("done"!==a.get(e)){if("open"===a.get(e))return[...s.slice(s.indexOf(e)),e];for(let l of(a.set(e,"open"),s.push(e),t.get(e)?.dependsOn??[])){if(l===e||!t.has(l))continue;let a=i(l);if(a)return a}s.pop(),a.set(e,"done")}};for(let t of e){let e=i(t.id);if(e)return e.toReversed()}}(a);o&&t.push({code:"gantt_dependency_cycle",path:`tasks.[${a.findIndex(e=>e.id===o[0])}].dependsOn`,message:`Dependencies form a cycle: ${o.join(" → ")}.`,hint:"A task cannot wait, directly or indirectly, for itself. Remove one dependency on the cycle."}),e.phases&&(new Set(e.phases).size!==e.phases.length&&t.push({code:"invalid_gantt_phase",path:"phases",message:"Phase names must be unique.",hint:"List each phase once, in top-to-bottom order."}),e.phases.forEach((e,s)=>{a.some(t=>t.phase===e)||t.push({code:"invalid_gantt_phase",path:`phases.[${s}]`,message:`Phase "${e}" has no tasks.`,hint:"List only phases that tasks name."})})),tn(e).length>12&&t.push({code:"gantt_too_large",path:"phases",message:"A Gantt chart supports at most 12 phases.",hint:"Merge related phases or split the plan into several charts."});let r=void 0===e.today?void 0:ti(e.today);void 0!==e.today&&void 0===r&&t.push({code:"invalid_gantt_date",path:"today",message:`Today "${e.today}" must be a YYYY-MM-DD date.`,hint:`${td} Omit today unless the source states it.`});let n=[...a.flatMap(e=>{let t=tr(e);return t&&Number.isFinite(t.end)?[t.start,t.end]:[]}),...void 0===r?[]:[r,r+1]];return n.length&&Math.max(...n)-Math.min(...n)>36525&&t.push({code:"gantt_too_large",path:"tasks",message:"A Gantt chart spans at most 36525 days, first task through last and Today.",hint:"Check the dates for a typo, or split a longer plan into several charts."}),t.slice(0,20)}class th extends I{issues;constructor(e){super(e[0]?.message??"Gantt chart failed validation."),this.issues=e,this.name="GanttValidationError"}}function tg(e){let t=tp(e);if(t.length)throw new th(t);return e}tg(i.svK(ts,{errors:"all"})({id:"release-plan",title:"Release plan",type:"gantt",tasks:[{id:"design",label:"Design",start:"2026-03-02",end:"2026-03-06",phase:"Build"},{id:"api",label:"API",start:"2026-03-09",duration:10,phase:"Build",dependsOn:["design"],progress:40},{id:"web",label:"Web app",start:"2026-03-09",end:"2026-03-20",phase:"Build",dependsOn:["design"]},{id:"qa",label:"QA",start:"2026-03-23",duration:5,phase:"Launch",dependsOn:["api","web"]},{id:"release",label:"Release",start:"2026-03-30",milestone:!0,phase:"Launch",dependsOn:["qa"]}]}));let tu="er",tf=["one","zero-or-one","many","one-or-many","zero-or-many"],tm=i.xCb(tf);class tv extends i.Xsx("ErField")({name:i.ukk,type:i.Qrq(i.ukk),pk:i.Qrq(i.v8c),fk:i.Qrq(i.v8c),unique:i.Qrq(i.v8c),nullable:i.Qrq(i.v8c)}){}class ty extends i.Xsx("ErEntity")({id:i.ukk,name:i.Qrq(i.ukk),fields:i.O31(tv).pipe(i.fXn,i.tiU(o.PyW([])))}){}class tw extends i.Xsx("ErRelationship")({id:i.ukk,from:i.ukk,to:i.ukk,fromCardinality:tm,toCardinality:tm,label:i.Qrq(i.ukk)}){}class tx extends i.Xsx("ErDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(tu),entities:i.O31(ty).pipe(i.fXn,i.Sr8(i.tJb(1))),relationships:i.O31(tw).pipe(i.fXn,i.tiU(o.PyW([]))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let tb=i.xCb(["er_too_large","invalid_entity_id","duplicate_entity_id","duplicate_entity_name","duplicate_field_name","er_text_too_long","nullable_primary_key","duplicate_relationship_id","missing_relationship_entity","missing_relationship_field","self_referencing_field"]);function tk(e){return e.name??e.id}function tM(e){let t=e.indexOf(".");return t<0?{entity:e.trim()}:{entity:e.slice(0,t).trim(),field:e.slice(t+1).trim()}}function tC(e){return e.trim().toLowerCase()}function tz(e){let t=[],a=e.entities.reduce((e,t)=>e+t.fields.length,0);e.entities.length>30&&t.push({code:"er_too_large",path:"entities",message:`The diagram has ${e.entities.length} entities; the supported maximum is 30.`,hint:"Split the schema into diagrams by area, or leave out minor lookup tables."}),a>240&&t.push({code:"er_too_large",path:"entities",message:`The diagram has ${a} fields; the supported maximum is 240.`,hint:"Keep the keys and the fields the request names, or split the schema by area."}),e.relationships.length>60&&t.push({code:"er_too_large",path:"relationships",message:`The diagram has ${e.relationships.length} relationships; the supported maximum is 60.`,hint:"Split the schema into diagrams by area."});let s=new Map,i=new Map;e.entities.forEach((e,a)=>{let l=`entities.[${a}]`;/[.:\s]/u.test(e.id)&&t.push({code:"invalid_entity_id",path:`${l}.id`,message:`Entity id "${e.id}" contains a dot, a colon or a space.`,hint:'Use letters, digits, hyphens or underscores in entity ids; relationships write "entity.field".'}),s.has(e.id)&&t.push({code:"duplicate_entity_id",path:`${l}.id`,message:`Entity id "${e.id}" is used more than once.`,hint:"Give every entity a unique id."}),s.set(e.id,e);let o=tk(e),r=i.get(tC(o));void 0!==r&&r!==e.id&&t.push({code:"duplicate_entity_name",path:void 0===e.name?`${l}.id`:`${l}.name`,message:`Entities "${r}" and "${e.id}" are both named "${o}".`,hint:"Give every entity a distinct name, or merge the two."}),i.set(tC(o),e.id),o.length>64&&t.push({code:"er_text_too_long",path:void 0===e.name?`${l}.id`:`${l}.name`,message:`Entity name "${o}" is longer than 64 characters.`,hint:"Shorten the entity name."}),e.fields.length>40&&t.push({code:"er_too_large",path:`${l}.fields`,message:`Entity "${e.id}" has ${e.fields.length} fields; the supported maximum is 40.`,hint:"Keep the keys and the fields the request names."});let n=new Set;e.fields.forEach((a,s)=>{let i=`${l}.fields.[${s}]`;for(let[s,l]of(n.has(tC(a.name))&&t.push({code:"duplicate_field_name",path:`${i}.name`,message:`Entity "${e.id}" has more than one field named "${a.name}".`,hint:"List each field once."}),n.add(tC(a.name)),[["name",a.name],["type",a.type]]))void 0!==l&&(l.length>64||/\n/u.test(l))&&t.push({code:"er_text_too_long",path:`${i}.${s}`,message:`Field ${s} "${l}" of "${e.id}" is longer than 64 characters or spans lines.`,hint:`Write the field ${s} on one line of at most 64 characters.`});a.pk&&a.nullable&&t.push({code:"nullable_primary_key",path:`${i}.nullable`,message:`Primary key "${e.id}.${a.name}" is marked nullable.`,hint:"A primary key is never empty; drop nullable from it."})})});let l=new Set;return e.relationships.forEach((e,a)=>{let i=`relationships.[${a}]`;l.has(e.id)&&t.push({code:"duplicate_relationship_id",path:`${i}.id`,message:`Relationship id "${e.id}" is used more than once.`,hint:"Give every relationship a unique id, or omit ids to generate them."}),l.add(e.id);let[o,r]=["from","to"].map(a=>{let l=tM(e[a]),o=s.get(l.entity);return o?void 0===l.field||o.fields.some(e=>tC(e.name)===tC(l.field))?l:void t.push({code:"missing_relationship_field",path:`${i}.${a}`,message:`Relationship "${e.id}" names field "${l.field}", which "${o.id}" does not have.`,hint:`Name one of the fields of "${o.id}", add the field, or name the entity alone.`}):void t.push({code:"missing_relationship_entity",path:`${i}.${a}`,message:`Relationship "${e.id}" ${"from"===a?"starts":"ends"} at "${l.entity}", which is not an entity.`,hint:'Set it to an entity id, or "entity.field" for the column the relationship runs through.'})});o?.field!==void 0&&r?.field!==void 0&&o.entity===r.entity&&tC(o.field)===tC(r.field)&&t.push({code:"self_referencing_field",path:i,message:`Relationship "${e.id}" joins "${o.entity}.${o.field}" to itself.`,hint:"A self-reference runs from the foreign key to the key it references, such as employees.manager_id to employees.id."})}),t.slice(0,20)}i.Xsx("ErValidationIssue")({code:tb,path:i.ukk,message:i.ukk,hint:i.ukk});class t_ extends I{issues;constructor(e){super(e[0]?.message??"ER diagram failed semantic validation."),this.issues=e,this.name="ErValidationError"}}function tL(e){var t=i.svK(tx,{errors:"all"})(e);let a=tz(t);if(a.length>0)throw new t_(a);return t}tL({id:"shop-schema",title:"Shop schema",type:tu,entities:[{id:"customers",fields:[{name:"id",type:"uuid",pk:!0},{name:"email",type:"text",unique:!0},{name:"name",type:"text"}]},{id:"orders",fields:[{name:"id",type:"uuid",pk:!0},{name:"customer_id",type:"uuid",fk:!0},{name:"placed_at",type:"timestamptz"},{name:"shipped_at",type:"timestamptz",nullable:!0}]},{id:"order_items",fields:[{name:"order_id",type:"uuid",pk:!0,fk:!0},{name:"product_id",type:"uuid",pk:!0,fk:!0},{name:"quantity",type:"int"}]},{id:"products",fields:[{name:"id",type:"uuid",pk:!0},{name:"sku",type:"text",unique:!0},{name:"price",type:"numeric(10,2)"}]}],relationships:[{id:"places",from:"customers.id",to:"orders.customer_id",fromCardinality:"one",toCardinality:"zero-or-many",label:"places"},{id:"contains",from:"orders.id",to:"order_items.order_id",fromCardinality:"one",toCardinality:"one-or-many"},{id:"ordered-as",from:"products.id",to:"order_items.product_id",fromCardinality:"one",toCardinality:"zero-or-many"}]}),tL({id:"org-schema",title:"Org schema",type:tu,entities:[{id:"employees",fields:[{name:"id",type:"int",pk:!0},{name:"manager_id",type:"int",fk:!0,nullable:!0},{name:"department_id",type:"int",fk:!0},{name:"name",type:"text"}]},{id:"departments",fields:[{name:"id",type:"int",pk:!0},{name:"head_id",type:"int",fk:!0,unique:!0,nullable:!0},{name:"name",type:"text",unique:!0}]}],relationships:[{id:"reports-to",from:"employees.id",to:"employees.manager_id",fromCardinality:"zero-or-one",toCardinality:"zero-or-many",label:"manages"},{id:"works-in",from:"departments.id",to:"employees.department_id",fromCardinality:"one",toCardinality:"one-or-many"},{id:"heads",from:"employees.id",to:"departments.head_id",fromCardinality:"zero-or-one",toCardinality:"zero-or-one",label:"heads"}]});let tB={PK:"pk",FK:"fk",UK:"unique",UQ:"unique",UNIQUE:"unique",NULL:"nullable",NULLABLE:"nullable","?":"nullable"};function tS(e){let t=e.trim().split(/\s+/u).filter(Boolean),a={},s=e=>tB[e.toUpperCase()];for(;t.length>1;){let e=t.at(-1);if("NULL"===e.toUpperCase()&&t.at(-2)?.toUpperCase()==="NOT"){t.splice(-2,2);continue}let i=s(e)??(e.length>1&&e.endsWith("?")?s(e.slice(0,-1)):void 0);if(!i)break;a[i]=!0,e.length>1&&e.endsWith("?")&&(a.nullable=!0),t.pop()}for(;t.length>1&&/^(?:PK|FK|UK)$/u.test(t[0]);)a[s(t.shift())]=!0;let i=t.shift()??e.trim(),l=t.join(" ");return l.endsWith("?")&&(l=l.slice(0,-1).trim(),a.nullable=!0),!l&&i.length>1&&i.endsWith("?")&&(i=i.slice(0,-1),a.nullable=!0),{name:i,...l?{type:l}:{},...a}}let tA={1:"one","1..1":"one","exactly-one":"one","one-and-only-one":"one","only-one":"one","mandatory-one":"one","0..1":"zero-or-one","0-1":"zero-or-one","0-or-1":"zero-or-one",optional:"zero-or-one","optional-one":"zero-or-one","one-or-zero":"zero-or-one","at-most-one":"zero-or-one","*":"many",n:"many",m:"many",multiple:"many","1..*":"one-or-many","1..n":"one-or-many","1-n":"one-or-many","1+":"one-or-many","at-least-one":"one-or-many","one-or-more":"one-or-many","many-mandatory":"one-or-many","0..*":"zero-or-many","0..n":"zero-or-many","0-n":"zero-or-many","0+":"zero-or-many","zero-or-more":"zero-or-many","optional-many":"zero-or-many","many-optional":"zero-or-many"};function tP(e){if("string"!=typeof e)return e;let t=e.trim().toLowerCase().replace(/[\s_]+/gu,"-");return tf.includes(t)?t:tA[t]??e}let tV=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),tH="class",tq=["class","abstract","interface","enum"],tF=i.xCb(tq),tI=["public","private","protected","package"],tE=i.xCb(tI),tO={public:"+",private:"-",protected:"#",package:"~"},tU=["inheritance","realization","composition","aggregation","association","dependency"],tX=i.xCb(tU);function tT(e){return"inheritance"===e||"realization"===e}function tY(e){return"association"===e||"composition"===e||"aggregation"===e}class t$ extends i.Xsx("ClassAttribute")({name:i.ukk,type:i.Qrq(i.ukk),visibility:i.Qrq(tE),static:i.Qrq(i.v8c)}){}class tG extends i.Xsx("ClassParameter")({name:i.ukk,type:i.Qrq(i.ukk)}){}class tD extends i.Xsx("ClassMethod")({name:i.ukk,params:i.O31(tG).pipe(i.fXn,i.tiU(o.PyW([]))),returns:i.Qrq(i.ukk),visibility:i.Qrq(tE),static:i.Qrq(i.v8c),abstract:i.Qrq(i.v8c)}){}class tR extends i.Xsx("ClassNode")({id:i.ukk,name:i.Qrq(i.ukk),kind:i.Qrq(tF),stereotype:i.Qrq(i.ukk),attributes:i.O31(t$).pipe(i.fXn,i.tiU(o.PyW([]))),methods:i.O31(tD).pipe(i.fXn,i.tiU(o.PyW([])))}){}class tZ extends i.Xsx("ClassRelationship")({id:i.ukk,kind:tX,from:i.ukk,to:i.ukk,fromMultiplicity:i.Qrq(i.ukk),toMultiplicity:i.Qrq(i.ukk),fromRole:i.Qrq(i.ukk),toRole:i.Qrq(i.ukk),navigable:i.Qrq(i.v8c),label:i.Qrq(i.ukk)}){}class tj extends i.Xsx("ClassDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(tH),classes:i.O31(tR).pipe(i.fXn,i.Sr8(i.tJb(1))),relationships:i.O31(tZ).pipe(i.fXn,i.tiU(o.PyW([]))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let tN=i.xCb(["class_too_large","invalid_class_id","duplicate_class_id","duplicate_class_name","duplicate_member","class_text_too_long","duplicate_relationship_id","missing_relationship_class","inheritance_cycle","invalid_inheritance","invalid_realization","invalid_multiplicity","misplaced_end_label"]);function tW(e){return e.name??e.id}function tJ(e){return e.kind??"class"}i.Xsx("ClassValidationIssue")({code:tN,path:i.ukk,message:i.ukk,hint:i.ukk});let tK={class:void 0,abstract:"abstract",interface:"interface",enum:"enumeration"};function tQ(e){return e?`${tO[e]} `:""}function t1(e){return`${tQ(e.visibility)}${e.name.trim()}${e.type?`: ${e.type.trim()}`:""}${e.static?" {static}":""}`}function t0(e){let t=e.params.map(e=>`${e.name.trim()}${e.type?`: ${e.type.trim()}`:""}`).join(", "),a=[e.abstract&&"{abstract}",e.static&&"{static}"].filter(Boolean);return`${tQ(e.visibility)}${e.name.trim()}(${t})${e.returns?`: ${e.returns.trim()}`:""}${a.length>0?` ${a.join(" ")}`:""}`}function t2(e){return e.trim().toLowerCase()}let t3=/^(\d+|\*)(?:\.\.(\d+|\*))?$/u;function t5(e){let t=[],a=e.classes.reduce((e,t)=>e+t.attributes.length+t.methods.length,0);e.classes.length>30&&t.push({code:"class_too_large",path:"classes",message:`The diagram has ${e.classes.length} classes; the supported maximum is 30.`,hint:"Split the model into diagrams by package, or leave out minor classes."}),a>300&&t.push({code:"class_too_large",path:"classes",message:`The diagram has ${a} members; the supported maximum is 300.`,hint:"Keep the members the request names, or split the model by package."}),e.relationships.length>60&&t.push({code:"class_too_large",path:"relationships",message:`The diagram has ${e.relationships.length} relationships; the supported maximum is 60.`,hint:"Split the model into diagrams by package."});let s=new Map,i=new Map;e.classes.forEach((e,a)=>{let l=`classes.[${a}]`;/[:\s]/u.test(e.id)&&t.push({code:"invalid_class_id",path:`${l}.id`,message:`Class id "${e.id}" contains a colon or a space.`,hint:"Use letters, digits, dots, hyphens or underscores in class ids, and put the shown name in name."}),s.has(e.id)&&t.push({code:"duplicate_class_id",path:`${l}.id`,message:`Class id "${e.id}" is used more than once.`,hint:"Give every class a unique id."}),s.set(e.id,e);let o=tW(e),r=void 0===e.name?`${l}.id`:`${l}.name`,n=i.get(t2(o));for(let[a,s,c]of(void 0!==n&&n!==e.id&&t.push({code:"duplicate_class_name",path:r,message:`Classes "${n}" and "${e.id}" are both named "${o}".`,hint:"Give every class a distinct name, or merge the two."}),i.set(t2(o),e.id),[["name",o,64],["stereotype",e.stereotype,64]]))void 0!==s&&(!(s.length<=c)||/\n/u.test(s))&&t.push({code:"class_text_too_long",path:"name"===a?r:`${l}.stereotype`,message:`The ${a} of "${e.id}" is longer than ${c} characters or spans lines.`,hint:`Write the ${a} on one line of at most ${c} characters.`});let c=e.attributes.length+e.methods.length;c>30&&t.push({code:"class_too_large",path:l,message:`Class "${e.id}" has ${c} members; the supported maximum is 30.`,hint:"Keep the members the request names."});let d=new Set,p=(a,s,i,o)=>{let r=`${l}.${a}.[${s}]`;d.has(o)&&t.push({code:"duplicate_member",path:r,message:`Class "${e.id}" lists ${"attributes"===a?"attribute":"method"} "${i}" more than once.`,hint:"List each member once; overloads differ in their parameters."}),d.add(o),(i.length>96||/\n/u.test(i))&&t.push({code:"class_text_too_long",path:r,message:`Member "${i}" of "${e.id}" is longer than 96 characters or spans lines.`,hint:"Write each member on one line of at most 96 characters."})};e.attributes.forEach((e,t)=>p("attributes",t,t1(e),`a:${t2(e.name)}`)),e.methods.forEach((e,t)=>p("methods",t,t0(e),`m:${t2(e.name)}(${e.params.map(e=>t2(e.type??e.name)).join(",")})`))});let l=new Set,o=new Map,r=new Set;e.relationships.forEach((e,a)=>{let i=`relationships.[${a}]`;l.has(e.id)&&t.push({code:"duplicate_relationship_id",path:`${i}.id`,message:`Relationship id "${e.id}" is used more than once.`,hint:"Give every relationship a unique id, or omit ids to generate them."}),l.add(e.id);let[n,c]=["from","to"].map(a=>{let l=s.get(e[a].trim());return l||t.push({code:"missing_relationship_class",path:`${i}.${a}`,message:`Relationship "${e.id}" ${"from"===a?"starts":"ends"} at "${e[a]}", which is not a class.`,hint:"Set it to the id of one of the classes."}),l}),{kind:d}=e;if(n&&c&&tT(d)){let e=`${d}\0${n.id}\0${c.id}`,[a,s]=[tJ(n),tJ(c)];r.has(e)?t.push({code:"inheritance"===d?"invalid_inheritance":"invalid_realization",path:i,message:`"${n.id}" ${"inheritance"===d?"extends":"implements"} "${c.id}" more than once.`,hint:"Draw each generalization once."}):n.id===c.id?t.push({code:"inheritance_cycle",path:i,message:`"${n.id}" ${"inheritance"===d?"extends":"implements"} itself.`,hint:"A class extends or implements another class, never itself."}):"inheritance"===d&&"interface"===a!=("interface"===s)?t.push({code:"invalid_inheritance",path:i,message:"interface"===a?`Interface "${n.id}" extends "${c.id}", which is not an interface.`:`"${n.id}" extends interface "${c.id}".`,hint:"interface"===a?"An interface extends only interfaces; make the class implement the interface instead (a realization from the class to the interface).":'A class implements an interface: use kind "realization" from the class to the interface.'}):"realization"===d&&("interface"===a||"interface"!==s)&&t.push({code:"invalid_realization",path:i,message:"interface"===a?`Interface "${n.id}" implements "${c.id}".`:`"${n.id}" implements "${c.id}", which is not an interface.`,hint:"interface"===a?'An interface extends another interface: use kind "inheritance".':'Mark "to" as kind "interface", or use kind "inheritance" to extend a class.'}),r.add(e),n.id!==c.id&&o.set(n.id,[...o.get(n.id)??[],c.id])}let p=tY(d);for(let a of["from","to"])for(let s of[`${a}Multiplicity`,`${a}Role`]){let a=e[s];void 0!==a&&(p?a.length>64||/\n/u.test(a)?t.push({code:"class_text_too_long",path:`${i}.${s}`,message:`"${a}" at an end of "${e.id}" is longer than 64 characters or spans lines.`,hint:"Write it on one short line."}):s.endsWith("Multiplicity")&&!function(e){let t=t3.exec(e.trim());if(!t)return!1;let[,a,s]=t;return void 0===s||"*"!==a&&("*"===s||Number(a)<=Number(s))}(a)?t.push({code:"invalid_multiplicity",path:`${i}.${s}`,message:`Multiplicity "${a}" of "${e.id}" is not a UML multiplicity.`,hint:'Write a bound or a range: "1", "0..1", "*", "1..*", "0..*" or "2..4".'}):"fromMultiplicity"!==s||"composition"!==d||["1","0..1","1..1"].includes(a.trim())||t.push({code:"invalid_multiplicity",path:`${i}.${s}`,message:`Composition "${e.id}" gives its whole "${e.from}" multiplicity "${a}".`,hint:'A part belongs to one whole at a time: write "1" or "0..1", or use an aggregation for a shared part.'}):t.push({code:"misplaced_end_label",path:`${i}.${s}`,message:`${"dependency"===d?"A dependency":`An ${d}`} "${e.id}" has a ${s.endsWith("Role")?"role":"multiplicity"}.`,hint:"Only associations, compositions and aggregations carry multiplicities and roles; drop it."}))}void 0===e.navigable||p||t.push({code:"misplaced_end_label",path:`${i}.navigable`,message:`${"dependency"===d?"A dependency":`An ${d}`} "${e.id}" is marked navigable.`,hint:"dependency"===d?"A dependency always draws its arrow; drop navigable.":"Only associations, compositions and aggregations take navigable; drop it."}),void 0!==e.label&&e.label.length>64&&t.push({code:"class_text_too_long",path:`${i}.label`,message:`The label of "${e.id}" is longer than 64 characters.`,hint:"Shorten the label."})});let n=new Map,c=(e,t)=>{for(let a of(n.set(e,1),o.get(e)??[])){if(1===n.get(a))return[...t.slice(t.indexOf(a)),a];if(void 0===n.get(a)){let e=c(a,[...t,a]);if(e)return e}}n.set(e,2)};for(let e of o.keys()){if(n.has(e))continue;let a=c(e,[e]);if(a){t.push({code:"inheritance_cycle",path:"relationships",message:`Inheritance runs in a cycle: ${a.join(" → ")}.`,hint:"A class never extends one of its own subclasses; drop or reverse one generalization."});break}}return t.slice(0,20)}class t4 extends I{issues;constructor(e){super(e[0]?.message??"Class diagram failed semantic validation."),this.issues=e,this.name="ClassValidationError"}}function t6(e){var t=i.svK(tj,{errors:"all"})(e);let a=t5(t);if(a.length>0)throw new t4(a);return t}let t7={"+":"public","-":"private","#":"protected","~":"package",public:"public",private:"private",protected:"protected",package:"package",internal:"package"};function t8(e){let t=e.trim(),a={};for(;;){let e=/^([+\-#~])\s*/u.exec(t);if(e&&!a.visibility){a.visibility=t7[e[1]],t=t.slice(e[0].length);continue}let s=/^(public|private|protected|package|internal|static|abstract)\s+/iu.exec(t);if(!s)break;let i=s[1].toLowerCase();"static"===i?a.static=!0:"abstract"===i?a.abstract=!0:a.visibility=t7[i],t=t.slice(s[0].length)}for(;;){let e=/\s*(?:\{(static|abstract)\}|([$*]))$/iu.exec(t);if(!e||0===e.index)break;let s=(e[1]??e[2]).toLowerCase();"static"===s||"$"===s?a.static=!0:a.abstract=!0,t=t.slice(0,e.index)}return{rest:t.trim(),modifiers:a}}function t9(e){let t=e.indexOf(":");if(t<0)return{name:e.trim()};let[a,s]=[e.slice(0,t).trim(),e.slice(t+1).trim()];return{name:a||e.trim(),...a&&s?{type:s}:{}}}function ae(e){let t=[],a=0,s=0;for(let i=0;i<e.length;i+=1){let l=e[i];"<([{".includes(l)?a+=1:">)]}".includes(l)?a=Math.max(0,a-1):","===l&&0===a&&(t.push(e.slice(s,i)),s=i+1)}return t.push(e.slice(s)),t.map(e=>e.trim()).filter(Boolean)}function at(e){let{rest:t,modifiers:a}=t8(e),{visibility:s,static:i}=a;return{...t9(t),...s?{visibility:s}:{},...i?{static:!0}:{}}}function aa(e){let{rest:t,modifiers:a}=t8(e),s=t.indexOf("("),i=function(e,t){if(t<0)return -1;let a=0;for(let s=t;s<e.length;s+=1)if("("===e[s])a+=1;else if(")"===e[s]&&0==(a-=1))return s;return -1}(t,s),l={...a.visibility?{visibility:a.visibility}:{},...a.static?{static:!0}:{},...a.abstract?{abstract:!0}:{}};if(s<0||i<s){let{name:e,type:a}=t9(t);return{name:e,params:[],...a?{returns:a}:{},...l}}let o=t.slice(i+1).replace(/^\s*:\s*/u,"").trim();return{name:t.slice(0,s).trim()||t,params:ae(t.slice(s+1,i)).map(t9),...o?{returns:o}:{},...l}}let as={extends:"inheritance",inherits:"inheritance",generalization:"inheritance","is-a":"inheritance",implements:"realization",realizes:"realization","interface-realization":"realization",composes:"composition","composed-of":"composition",aggregates:"aggregation","uses-a":"dependency",uses:"dependency",depends:"dependency","depends-on":"dependency",associates:"association"},ai={one:"1","exactly-one":"1","zero-or-one":"0..1",optional:"0..1",many:"*",n:"*",m:"*","zero-or-many":"0..*","zero-or-more":"0..*","one-or-many":"1..*","one-or-more":"1..*"},al=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function ao(e){if(!al(e))return e;let t=(e,t)=>{let a;if("string"==typeof e)return t?aa(e):at(e);if(!al(e))return e;let s={...e};if(void 0!==s.visibility&&(s.visibility="string"==typeof(a=s.visibility)?t7[a.trim().toLowerCase()]??a:a),t){void 0===s.returns&&void 0!==s.returnType&&(s.returns=s.returnType,delete s.returnType);let e=s.params??s.parameters;delete s.parameters,"string"==typeof e?s.params=ae(e).map(t9):Array.isArray(e)&&(s.params=e.map(e=>"string"==typeof e?t9(e):e))}return s},a=Array.isArray(e.classes)?e.classes.map(e=>{if(!al(e))return e;let{values:a,...s}=e,i=Array.isArray(s.attributes)?s.attributes:Array.isArray(a)?a:s.attributes;return{...s,...void 0===s.kind&&Array.isArray(a)?{kind:"enum"}:{},...Array.isArray(i)?{attributes:i.map(e=>t(e,!1))}:void 0===i?{}:{attributes:i},...Array.isArray(s.methods)?{methods:s.methods.map(e=>t(e,!0))}:{},..."string"==typeof s.kind?{kind:"enumeration"===s.kind.trim().toLowerCase()?"enum":s.kind.trim().toLowerCase()}:{}}}):e.classes,s=Array.isArray(e.relationships)?e.relationships.map(e=>{if(!al(e))return e;let{source:t,target:a,type:s,...i}=e,l={...i,from:i.from??t,to:i.to??a,kind:function(e){if("string"!=typeof e)return e;let t=e.trim().toLowerCase().replace(/[\s_]+/gu,"-");return tU.includes(t)?t:as[t]??e}(i.kind??s)};for(let e of["fromMultiplicity","toMultiplicity"])void 0!==l[e]&&(l[e]=function(e){if("number"==typeof e&&Number.isInteger(e)&&e>=0)return String(e);if("string"!=typeof e)return e;let t=e.trim(),a=ai[t.toLowerCase().replace(/[\s_]+/gu,"-")];return a||t.replace(/\s*\.\.\s*/gu,"..").replace(/(^|\.\.)[nm]$/iu,"$1*")}(l[e]));for(let e of["from","to","kind"])void 0===l[e]&&delete l[e];return l}):e.relationships;return{...e,...void 0===a?{}:{classes:a},...void 0===s?{}:{relationships:s}}}t6({id:"shapes",title:"Shapes",type:tH,classes:[{id:"Drawable",kind:"interface",methods:[{name:"draw",params:[{name:"ctx",type:"Canvas"}],returns:"void"}]},{id:"Shape",kind:"abstract",attributes:[{name:"x",type:"double",visibility:"protected"},{name:"y",type:"double",visibility:"protected"}],methods:[{name:"area",returns:"double",visibility:"public",abstract:!0},{name:"moveTo",params:[{name:"x",type:"double"},{name:"y",type:"double"}],returns:"void",visibility:"public"}]},{id:"Circle",attributes:[{name:"radius",type:"double",visibility:"private"}],methods:[{name:"area",returns:"double",visibility:"public"}]},{id:"Rectangle",attributes:[{name:"width",type:"double",visibility:"private"},{name:"height",type:"double",visibility:"private"}],methods:[{name:"area",returns:"double",visibility:"public"}]},{id:"Square",methods:[{name:"of",params:[{name:"side",type:"double"}],returns:"Square",visibility:"public",static:!0}]},{id:"Canvas",attributes:[{name:"MAX_SHAPES",type:"int",visibility:"public",static:!0}],methods:[{name:"add",params:[{name:"shape",type:"Shape"}],returns:"void",visibility:"public"}]}],relationships:[{id:"shape-draws",kind:"realization",from:"Shape",to:"Drawable"},{id:"circle-is-shape",kind:"inheritance",from:"Circle",to:"Shape"},{id:"rectangle-is-shape",kind:"inheritance",from:"Rectangle",to:"Shape"},{id:"square-is-rectangle",kind:"inheritance",from:"Square",to:"Rectangle"},{id:"canvas-holds",kind:"aggregation",from:"Canvas",to:"Shape",fromMultiplicity:"1",toMultiplicity:"0..*",toRole:"shapes"}]});let ar="org-chart";class an extends i.Xsx("OrgPerson")({id:i.ukk,name:i.ukk,title:i.Qrq(i.ukk),department:i.Qrq(i.ukk),manager:i.Qrq(i.ukk),assistant:i.Qrq(i.v8c),avatar:i.Qrq(i.v8c)}){}class ac extends i.Xsx("OrgDottedLine")({id:i.ukk,report:i.ukk,manager:i.ukk,label:i.Qrq(i.ukk)}){}class ad extends i.Xsx("OrgChartDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(ar),people:i.O31(an).pipe(i.fXn,i.Sr8(i.tJb(1))),dottedLines:i.O31(ac).pipe(i.fXn,i.tiU(o.PyW([]))),groupByDepartment:i.Qrq(i.v8c),forest:i.Qrq(i.v8c),style:H.pipe(i.tiU(o.PyW({...y})))}){}let ap=i.xCb(["org_chart_too_large","invalid_person_id","duplicate_person_id","org_text_too_long","unknown_manager","self_manager","reporting_cycle","multiple_roots","invalid_assistant","duplicate_dotted_line_id","invalid_dotted_line"]);function ah(e){return e.people.filter(e=>void 0===e.manager)}function ag(e){let t=new Map;for(let a of e.people){if(void 0===a.manager)continue;let e=t.get(a.manager)??[];e.push(a),t.set(a.manager,e)}return t}function au(e){let t=[],a=(e,a,s,i)=>t.push({code:e,path:a,message:s,hint:i}),{people:s,dottedLines:i}=e;s.length>100&&a("org_chart_too_large","people",`An org chart holds at most 100 people; this one has ${s.length}.`,"Draw each division as its own chart, or keep the levels the request asks for."),i.length>24&&a("org_chart_too_large","dottedLines",`An org chart holds at most 24 dotted lines; this one has ${i.length}.`,"Keep the dotted-line reports the request states.");let l=new Set;s.forEach((e,t)=>{let s=`people.[${t}]`;e.id.includes(":")&&a("invalid_person_id",`${s}.id`,`Person id "${e.id}" contains a colon.`,"Use a short id without colons, such as ada or vp-eng."),l.has(e.id)&&a("duplicate_person_id",`${s}.id`,`Person id "${e.id}" is used more than once.`,"Give each person a unique id; two people with one name need two ids."),l.add(e.id);let i=(t,i,l)=>{void 0!==i&&i.trim().length>l&&a("org_text_too_long",`${s}.${t}`,`The ${t} of "${e.id}" is longer than ${l} characters.`,`Shorten the ${t} to at most ${l} characters.`)};i("name",e.name,60),i("title",e.title,80),i("department",e.department,40)});let o=ag(e);s.forEach((e,t)=>{let s=`people.[${t}]`;if(void 0===e.manager){e.assistant&&a("invalid_assistant",`${s}.assistant`,`Assistant "${e.id}" has no manager.`,"Set manager to the person they assist.");return}e.manager===e.id?a("self_manager",`${s}.manager`,`"${e.id}" is their own manager.`,"Set manager to the person they report to, or omit it for the top person."):l.has(e.manager)||a("unknown_manager",`${s}.manager`,`Manager "${e.manager}" of "${e.id}" is not a person in the chart.`,"Use the id of a person in people, or add the manager as a person."),e.assistant&&(o.get(e.id)?.length??0)>0&&a("invalid_assistant",`${s}.assistant`,`Assistant "${e.id}" has reports of their own.`,"An assistant sits beside their manager with no reports; drop assistant: true to draw them as a manager.")});let r=function(e){let t=new Map(e.map(e=>[e.id,e.manager])),a=new Set;for(let s of e){let e=[],i=new Set,l=s.id;for(;void 0!==l&&t.has(l)&&!a.has(l);){if(i.has(l))return[...e.slice(e.indexOf(l)),l];i.add(l),e.push(l),l=t.get(l)}for(let t of e)a.add(t)}}(s);r&&a("reporting_cycle",`people.[${s.findIndex(e=>e.id===r[0])}].manager`,`Reporting lines run in a cycle: ${r.join(" → ")}.`,"Every chain of managers ends at a top person with no manager; remove one manager on the cycle.");let n=ah(e);n.length>1&&!0!==e.forest&&a("multiple_roots",`people.[${s.indexOf(n[1])}].manager`,`${n.length} people have no manager: ${n.slice(0,4).map(e=>`"${e.id}"`).join(", ")}${n.length>4?", …":""}.`,"Give everyone but the top person a manager, or set forest: true to draw separate trees.");let c=new Map(s.map(e=>[e.id,e]));if(!r&&n.length>0){let e=new Map,t=a=>{let s=e.get(a.id);if(void 0!==s)return s;let i=void 0===a.manager?void 0:c.get(a.manager),l=i&&i.id!==a.id?t(i)+1:1;return e.set(a.id,l),l},i=Math.max(...s.map(t));i>12&&a("org_chart_too_large","people",`Reporting chains run ${i} levels deep; an org chart draws at most 12.`,"Draw the deepest teams as charts of their own.")}let d=new Set,p=new Set;return i.forEach((e,t)=>{let s=`dottedLines.[${t}]`;for(let t of(d.has(e.id)&&a("duplicate_dotted_line_id",`${s}.id`,`Dotted line id "${e.id}" is used more than once.`,"Give each dotted line a unique id."),d.add(e.id),["report","manager"]))l.has(e[t])||a("invalid_dotted_line",`${s}.${t}`,`Dotted line "${e.id}" names unknown ${t} "${e[t]}".`,"Use the ids of two people in the chart.");e.report===e.manager?a("invalid_dotted_line",s,`Dotted line "${e.id}" joins "${e.report}" to themselves.`,"A dotted line joins a person to a second manager."):c.get(e.report)?.manager===e.manager&&a("invalid_dotted_line",s,`"${e.report}" already reports to "${e.manager}" on a solid line.`,"Draw a dotted line only to a second manager, outside the solid reporting line.");let i=`${e.report}\0${e.manager}`;p.has(i)&&a("invalid_dotted_line",s,`"${e.report}" has two dotted lines to "${e.manager}".`,"Draw each dotted-line report once."),p.add(i),void 0!==e.label&&e.label.trim().length>40&&a("org_text_too_long",`${s}.label`,`The label of dotted line "${e.id}" is longer than 40 characters.`,"Shorten the label to at most 40 characters.")}),t.slice(0,20)}i.Xsx("OrgChartValidationIssue")({code:ap,path:i.ukk,message:i.ukk,hint:i.ukk});class af extends I{issues;constructor(e){super(e[0]?.message??"Org chart failed semantic validation."),this.issues=e,this.name="OrgChartValidationError"}}function am(e){let t=au(e);if(t.length>0)throw new af(t);return e}function av(e){return am(i.svK(ad,{errors:"all"})(e))}let ay=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function aw(e,t){let a;for(let s of t)void 0===a&&void 0!==e[s]&&(a=e[s]),delete e[s];return a}let ax=["manager","reportsTo","managerId","manager_id","reports_to","parent","boss"],ab=["title","role","position","jobTitle","job_title"],ak=["department","team","dept","division","group"],aM=["dottedLines","dottedLine","dottedLineTo","dottedManager","dottedManagers"];function aC(e){if(!ay(e))return e;let{employees:t,members:a,reportingLines:s,reports:i,edges:l,...o}=e,r=o.people??t??a,n=[],c=new Map;if(Array.isArray(r)){for(let e of r)if(ay(e)){for(let t of["directReports","reports"])if(Array.isArray(e[t]))for(let a of e[t])"string"!=typeof a||c.has(a)||c.set(a,e.id)}}let d=Array.isArray(r)?r.map(e=>{if(!ay(e))return e;let t={...e};Array.isArray(t.directReports)&&delete t.directReports,Array.isArray(t.reports)&&delete t.reports;let a=aw(t,ax)??c.get(t.id),s=aw(t,ab),i=aw(t,ak),l=aw(t,aM),o=t.name??t.label;for(let e of(delete t.label,("assistant"===t.kind||"assistant"===t.type)&&(t.assistant=!0,delete t.kind,delete t.type),Array.isArray(l)?l:void 0===l?[]:[l]))n.push(ay(e)?{report:t.id,...e}:{report:t.id,manager:e});return{...t,...void 0===o?{}:{name:o},...null==a||""===a?{}:{manager:a},...void 0===s||""===s?{}:{title:s},...void 0===i||""===i?{}:{department:i}}}):r,p=[s,i,l].find(Array.isArray),h=Array.isArray(d)&&p?d.map(e=>{if(!ay(e)||void 0!==e.manager)return e;let t=p.find(t=>ay(t)&&(t.report??t.to??t.target)===e.id&&!0!==t.dotted),a=ay(t)?t.manager??t.from??t.source:void 0;return void 0===a?e:{...e,manager:a}}):d,g=(p??[]).filter(e=>ay(e)&&!0===e.dotted),u=o.dottedLines,f=[...Array.isArray(u)?u:null==u?[]:[u],...n,...g.map(({dotted:e,...t})=>({report:t.report??t.to??t.target,manager:t.manager??t.from??t.source,...void 0===t.label?{}:{label:t.label}}))],m=new Set(f.flatMap(e=>ay(e)&&"string"==typeof e.id?[e.id]:[])),v=f.map(e=>{if(!ay(e))return e;let{from:t,to:a,source:s,target:i,person:l,employee:o,...r}=e,n={...r,report:r.report??t??s??l??o,manager:r.manager??a??i};for(let e of["report","manager"])void 0===n[e]&&delete n[e];if("string"!=typeof n.id||0===n.id.length){let e=`${String(n.report)}-dotted-${String(n.manager)}`.replace(/[^\w-]+/gu,"-"),t=e;for(let a=2;m.has(t);a+=1)t=`${e}-${a}`;m.add(t),n.id=t}return n});return{...o,...void 0===h?{}:{people:h},...void 0===u&&0===v.length?{}:{dottedLines:v}}}av({id:"startup-team",title:"Startup team",type:ar,people:[{id:"ada",name:"Ada Lovelace",title:"Chief Executive Officer",department:"Executive"},{id:"grace",name:"Grace Hopper",title:"Executive Assistant",department:"Executive",manager:"ada",assistant:!0},{id:"linus",name:"Linus Torvalds",title:"Chief Technology Officer",department:"Engineering",manager:"ada"},{id:"margaret",name:"Margaret Hamilton",title:"Engineering Manager",department:"Engineering",manager:"linus"},{id:"ken",name:"Ken Thompson",title:"Platform Engineer",department:"Engineering",manager:"linus"},{id:"radia",name:"Radia Perlman",title:"Head of Product",department:"Product",manager:"ada"},{id:"don",name:"Don Norman",title:"Product Designer",department:"Product",manager:"radia"}],dottedLines:[{id:"ken-to-radia",report:"ken",manager:"radia"}]});let az=[0,.25,.5,.75,1];function a_(e){return Math.round(100*e)/100}function aL(e){let[t,a,s,i]=e;return az.map(e=>{let l=1-e,[o,r,n,c]=[l*l*l,3*l*l*e,3*l*e*e,e*e*e];return{x:a_(o*t.x+r*a.x+n*s.x+c*i.x),y:a_(o*t.y+r*a.y+n*s.y+c*i.y)}})}let aB=new Intl.Segmenter(void 0,{granularity:"grapheme"}),aS=/\p{Emoji_Presentation}|\uFE0F|\p{Regional_Indicator}|\u20E3/u,aA=/^[\uFE00-\uFE0F\u200B-\u200D\u2060]+$/u;function aP(e){return Array.from(aB.segment(e),e=>e.segment)}function aV(e){var t;return aA.test(e)?0:aS.test(e)?130:(t=e.codePointAt(0)??0)>=4352&&t<=4447||t>=11904&&t<=12350||t>=12353&&t<=13311||t>=13312&&t<=19903||t>=19968&&t<=40959||t>=40960&&t<=42191||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65072&&t<=65103||t>=65280&&t<=65376||t>=65504&&t<=65510||t>=131072&&t<=262141?100:62}function aH(e){return aP(e).reduce((e,t)=>e+aV(t),0)}function aq(e,t){return Math.max(...e.split("\n").map(e=>(function(e,t){let a=0,s=0;for(let t of aP(e)){let e=aV(t);62===e?a+=1:s+=e}return a*t*.62+s*t/100})(e,t)))}function aF(e,t,a){let s=aq(e,t);return Math.max(1,Math.min(a,Math.ceil(s)),Math.ceil(s-t))}function aI(e,t,a){return Math.max(aF(e,t,a),Math.ceil(aq(e,t)))}function aE(e,t){return e.split("\n").flatMap(e=>(function(e,t){if(aH(e)<=t)return[e];let a=[],s="";for(let i of e.split(" ")){if(aH(i)>t){s&&(a.push(s),s=""),a.push(...function(e,t){let a=(function(e){let t=[],a="";for(let s of aP(e)){if(!(aV(s)>62)){a+=s;continue}a&&t.push(a),t.push(s),a=""}return a&&t.push(a),t})(e).flatMap(e=>aH(e)>t?function(e,t){let a=Math.max(t,1488);return aH(e)<=a?[e]:e.split(/(?<=[/\-_.])(?=.)|(?<=\p{Ll})(?=\p{Lu})/u).flatMap(e=>aH(e)<=a?[e]:function(e,t){let a=[],s="",i=0;for(let l of aP(e)){let e=aV(l);s&&i+e>t&&(a.push(s),s="",i=0),s+=l,i+=e}return s&&a.push(s),a}(e,t))}(e,t):[e]),s=[],i="";for(let e of a){if(aH(e)>t){i&&s.push(i),s.push(e),i="";continue}i&&aH(i+e)>t&&(s.push(i),i=""),i+=e}return i&&s.push(i),s}(i,t));continue}let e=s?`${s} ${i}`:i;if(aH(e)<=t){s=e;continue}a.push(s),s=i}return s&&a.push(s),a})(e,t)).join("\n")}function aO(e,t,a){return aE(e,Math.floor(100*t/a+1e-6))}let aU=Object.freeze({maxDimension:16384,maxElements:600,maxGroupsPerElement:16,maxLayouts:128,maxLayers:64,maxPointsPerElement:256,maxSerializedBytes:15e5,maxTextLength:4096,maxZOrderEntries:600}),aX=Object.freeze({boundTextPadding:5,gap:4,maxAssetBytes:65536,maxSize:64,maxTotalAssetBytes:786432,minSize:16}),aT=["cylinder","pipe","document","bucket"];function aY(e){return aT.includes(e)}let a$={cylinder:12,pipe:12,document:5,bucket:12};function aG(e){return Math.round(.08*e)}function aD(e,t,a,s,i,l,o=12){return Array.from({length:o+1},(r,n)=>{let c=i+(l-i)*n/o;return{x:Math.round((e+a*Math.cos(c))*100)/100,y:Math.round((t+s*Math.sin(c))*100)/100}})}function aR(e,t,a,s=12,i=0){let{x:l,y:o,width:r,height:n}=e,c=l+r/2,d=o+n/2;if(a){let e=o+t,a=o+n-t;return{back:aD(c,e,r/2,t,0,-Math.PI,s),front:aD(c,e,r/2,t,Math.PI,0,s),end:aD(c,a,r/2-i,t,Math.PI,0,s),sides:[[{x:l,y:e},{x:l+i,y:a}],[{x:l+r,y:e},{x:l+r-i,y:a}]]}}let p=l+r-t,h=l+t;return{back:aD(p,d,t,n/2,-Math.PI/2,Math.PI/2,s),front:aD(p,d,t,n/2,-Math.PI/2,-(3*Math.PI)/2,s),end:aD(h,d,t,n/2,Math.PI/2,3*Math.PI/2,s),sides:[[{x:h,y:o},{x:p,y:o}],[{x:h,y:o+n},{x:p,y:o+n}]]}}function aZ(e,t){let{x:a,y:s,width:i,height:l}=e;return Array.from({length:17},(e,o)=>{let r=1-o/16;return{x:Math.round((a+i*r)*100)/100,y:Math.round((s+l-t*(1-Math.cos(4*Math.PI*r)))*100)/100}})}function aj(e,t,a){let{x:s,y:i,width:l,height:o}=e,r=a$[e.shape],n=s+l/2,c=i+o/2,d=(e,t)=>r*Math.sqrt(Math.max(0,1-(Math.min(Math.abs(e),t)/t)**2));if("pipe"===e.shape)return"left"===t?{x:s+r-d(a.y-c,o/2),y:a.y}:"right"===t?{x:s+l-r+d(a.y-c,o/2),y:a.y}:a;if("document"===e.shape){if("bottom"!==t)return a;let e=Math.min(1,Math.max(0,(a.x-s)/l));return{x:a.x,y:i+o-r*(1-Math.cos(4*Math.PI*e))}}let p="bucket"===e.shape?aG(l):0,[h,g]=[i+r,i+o-r];if("top"===t)return{x:a.x,y:h-d(a.x-n,l/2)};if("bottom"===t)return{x:a.x,y:g+d(a.x-n,l/2-p)};if(0===p)return a;let u=p*(Math.min(g,Math.max(h,a.y))-h)/(g-h);return{x:"left"===t?s+u:s+l-u,y:a.y}}function aN(e,t,a=1){let s=aW(e);return s.slice(1).some((e,i)=>{let l=s[i],[o,r]=[e.x-l.x,e.y-l.y],n=Math.max(0,Math.min(1,((t.x-l.x)*o+(t.y-l.y)*r)/(o*o+r*r||1)));return Math.hypot(t.x-l.x-n*o,t.y-l.y-n*r)<=a})}function aW(e){let{x:t,y:a,width:s}=e,i=a$[e.shape];if("document"===e.shape)return[{x:t,y:a},{x:t+s,y:a},...aZ(e,i),{x:t,y:a}];let{back:l,end:o}=aR(e,i,"pipe"!==e.shape,24,"bucket"===e.shape?aG(s):0);return[...l,...o,l[0]]}let aJ=["zone","sequence-lifeline","sequence-activation","timeline-marker","chart-mark","state-marker","gantt-mark","er-table","er-optional","class-box","swimlane","swimlane-header"],aK=["sequence-lifeline","sequence-activation","timeline-marker","chart-mark","er-optional","swimlane","zone"],aQ={"chart-mark":"Chart mark","class-box":"Class box","er-optional":"Optional relationship end","er-table":"Entity table","gantt-mark":"Gantt mark","sequence-activation":"Sequence activation","sequence-lifeline":"Sequence lifeline","state-marker":"State marker",swimlane:"Swimlane","swimlane-header":"Swimlane header","timeline-marker":"Timeline marker",zone:"Zone"};function a1(e){let t=new Set;for(let a of e){if(t.has(a))return a;t.add(a)}}function a0(e){return"x"in e&&"y"in e}let a2=new TextEncoder;function a3(e){return a2.encode(e).byteLength}function a5(e){let t=aX.boundTextPadding;if("ellipse"===e.shape||"circle"===e.shape){let a=1-Math.SQRT1_2;return{x:t+e.width/2*a,y:t+e.height/2*a}}return"diamond"===e.shape?{x:t+e.width/4,y:t+e.height/4}:"pipe"===e.shape?{x:t+2*a$.pipe,y:t}:"bucket"===e.shape?{x:t+aG(e.width),y:t+2*a$.bucket}:"cylinder"===e.shape||"document"===e.shape?{x:t,y:t+2*a$[e.shape]}:{x:t,y:t}}function a4(e){let t=2*aX.boundTextPadding;return"ellipse"===e.shape||"circle"===e.shape?{width:Math.round(e.width/2*Math.SQRT2)-t,height:Math.round(e.height/2*Math.SQRT2)-t}:"diamond"===e.shape?{width:Math.round(e.width/2)-t,height:Math.round(e.height/2)-t}:"pipe"===e.shape?{width:e.width-t-4*a$.pipe,height:e.height-t}:"cylinder"===e.shape||"document"===e.shape?{width:e.width-t,height:e.height-t-4*a$[e.shape]}:"bucket"===e.shape?{width:e.width-t-2*aG(e.width),height:e.height-t-4*a$.bucket}:{width:e.width-t,height:e.height-t}}function a6(e){return e?e.size+2*aX.gap:0}function a7(e){let t=new Map(e.layers.map(e=>[e.id,e]));return e=>!e.layerId||t.get(e.layerId)?.visible!==!1}function a8(e,t){let a=new Map;for(let[s,i]of e.elements.entries())"text"===i.type&&i.containerId&&t(i)&&a.set(i.containerId,{element:i,index:s});return a}function a9(e,t,a){let s=t?.text??e.label,i=t?.fontSize??16,l=t?t.maxWidth??160:Math.max(1,e.width-24),o=s.split("\n"),r=aq(s,i),n=Math.max(1,Math.min(l,r)),c=Math.ceil(o.length*i*1.35);if(aF(s,i,l)-i+24>e.width)return!0;if(a||aY(e.shape)){let t=a4(e);return r>t.width||c+a6(a)>t.height}return n+24>e.width||c+18>e.height}function se(e){let t=[];0===e.elements.length&&t.push({code:"empty_canvas",message:"CanvasSpec must contain at least one element.",path:"elements"}),e.elements.length>aU.maxElements&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${aU.maxElements} elements.`,path:"elements"}),e.layers.length>aU.maxLayers&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${aU.maxLayers} layers.`,path:"layers"}),e.layouts.length>aU.maxLayouts&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${aU.maxLayouts} layout primitives.`,path:"layouts"}),(e.width>aU.maxDimension||e.height>aU.maxDimension)&&t.push({code:"limit_exceeded",message:`Canvas dimensions may not exceed ${aU.maxDimension}.`,path:"width"});let a=a1(e.elements.map(e=>e.id));a&&t.push({code:"duplicate_element_id",elementId:a,message:`Duplicate element id "${a}" is not allowed.`,path:"elements"});let s=a1(e.layers.map(e=>e.id));s&&t.push({code:"duplicate_layer_id",message:`Duplicate layer id "${s}" is not allowed.`,path:"layers"});let i=a1(e.zOrder);i&&t.push({code:"duplicate_z_order_element",elementId:i,message:`zOrder contains duplicate element "${i}".`,path:"zOrder"}),e.zOrder.length>aU.maxZOrderEntries&&t.push({code:"limit_exceeded",message:`zOrder exceeds ${aU.maxZOrderEntries} entries.`,path:"zOrder"});let l=new Map(e.elements.map(e=>[e.id,e])),o=e.elements.filter(e=>"node"===e.type),r=sd(e.elements),n=a1([...o.map(e=>e.nodeId),...e.elements.flatMap(e=>"frame"===e.type&&void 0!==e.nodeId?[e.nodeId]:[])]);n&&t.push({code:"invalid_binding",message:`Duplicate nodeId "${n}" makes connector bindings ambiguous.`,path:"elements"});let c=a1(e.elements.flatMap(e=>"arrow"===e.type?[e.edgeId]:[]));c&&t.push({code:"invalid_binding",message:`Duplicate edgeId "${c}" makes connector selection ambiguous.`,path:"elements"});let d=a1(e.elements.flatMap(e=>"text"===e.type&&e.containerId?[e.containerId]:[]));d&&t.push({code:"invalid_binding",elementId:d,message:`Container "${d}" has more than one bound text element.`,path:"elements"});let p=new Set(e.layers.map(e=>e.id)),h=a7(e),g=a8(e,h);t.push(...function(e){let t=[],a=0;for(let[s,i]of Object.entries(e.icons??{})){let e=a3(i.svg);a+=e,e>aX.maxAssetBytes&&t.push({code:"limit_exceeded",message:`Icon asset "${s}" exceeds ${aX.maxAssetBytes} bytes.`,path:`icons.${s}`})}return a>aX.maxTotalAssetBytes&&t.push({code:"limit_exceeded",message:`Icon assets exceed ${aX.maxTotalAssetBytes} bytes per canvas.`,path:"icons"}),t}(e)),e.elements.forEach((a,s)=>{let i,o;if(t.push(...(i=[],o=`elements[${s}]`,"width"in a&&"height"in a&&(!(a.width>0)||!(a.height>0))&&i.push({code:"invalid_geometry",elementId:a.id,message:`Element "${a.id}" must have positive width and height.`,path:o}),"points"in a&&void 0!==a.points&&a.points.length>aU.maxPointsPerElement&&i.push({code:"limit_exceeded",elementId:a.id,message:`Element "${a.id}" exceeds ${aU.maxPointsPerElement} points.`,path:`${o}.points`}),"text"in a&&a.text.length>aU.maxTextLength&&i.push({code:"limit_exceeded",elementId:a.id,message:`Text element "${a.id}" exceeds ${aU.maxTextLength} characters.`,path:`${o}.text`}),"node"===a.type&&"polygon"===a.shape&&(!a.points||a.points.length<3)&&i.push({code:"invalid_polygon",elementId:a.id,message:`Polygon "${a.id}" requires at least three points.`,path:`${o}.points`}),a.groupIds&&a.groupIds.length>aU.maxGroupsPerElement&&i.push({code:"limit_exceeded",elementId:a.id,message:`Element "${a.id}" exceeds ${aU.maxGroupsPerElement} groups.`,path:`${o}.groupIds`}),i)),"node"===a.type&&t.push(...function(e,t,a){let s=t.icon;if(!s)return[];let i=`elements[${a}].icon`,l=[];return t.rendererRole&&l.push({code:"invalid_icon",elementId:t.id,message:`${aQ[t.rendererRole]} "${t.id}" cannot carry an icon.`,path:i}),u(s.slug)?e.icons&&Object.hasOwn(e.icons,s.slug)||l.push({code:"invalid_icon",elementId:t.id,message:`Node "${t.id}" references icon "${s.slug}" without an embedded asset.`,path:`${i}.slug`}):l.push({code:"invalid_icon",elementId:t.id,message:`Node "${t.id}" has an invalid icon slug "${s.slug}".`,path:`${i}.slug`}),(!Number.isFinite(s.size)||s.size<aX.minSize||s.size>aX.maxSize)&&l.push({code:"invalid_icon",elementId:t.id,message:`Node "${t.id}" icon size must be ${aX.minSize}-${aX.maxSize}.`,path:`${i}.size`}),l}(e,a,s)),"node"===a.type&&"polygon"!==a.shape&&h(a)){let e=g.get(a.id);(e||void 0===a.rendererRole)&&a9(a,e?.element,a.icon)&&t.push({code:"label_overflow",elementId:e?.element.id??a.id,message:`Label does not fit inside node "${a.id}" without changing its geometry.`,path:e?`elements[${e.index}].text`:`elements[${s}].label`})}if(a.frameId){let e=l.get(a.frameId);e&&"frame"===e.type||t.push({code:"invalid_composition",elementId:a.id,message:`Element "${a.id}" references missing frame "${a.frameId}".`,path:`elements[${s}].frameId`})}if(a.layerId&&!p.has(a.layerId)&&t.push({code:"invalid_composition",elementId:a.id,message:`Element "${a.id}" references missing layer "${a.layerId}".`,path:`elements[${s}].layerId`}),a.groupIds&&a1(a.groupIds)&&t.push({code:"invalid_composition",elementId:a.id,message:`Element "${a.id}" contains duplicate group ids.`,path:`elements[${s}].groupIds`}),"text"===a.type&&a.containerId){let e=l.get(a.containerId);e&&("node"===e.type||"arrow"===e.type)||t.push({code:"invalid_binding",elementId:a.id,message:`Text "${a.id}" references unsupported container "${a.containerId}".`,path:`elements[${s}].containerId`})}if("arrow"===a.type&&(r.has(a.sourceNodeId)||t.push({code:"invalid_binding",elementId:a.id,message:`Connector "${a.id}" references missing source "${a.sourceNodeId}".`,path:`elements[${s}].sourceNodeId`}),r.has(a.targetNodeId)||t.push({code:"invalid_binding",elementId:a.id,message:`Connector "${a.id}" references missing target "${a.targetNodeId}".`,path:`elements[${s}].targetNodeId`})),"line"===a.type)for(let[e,i]of[["startBinding",a.startBinding],["endBinding",a.endBinding]]){let o=i?l.get(i.elementId):void 0;i&&(!o||"node"!==o.type&&"frame"!==o.type)&&t.push({code:"invalid_binding",elementId:a.id,message:`Line "${a.id}" references missing binding "${i.elementId}".`,path:`elements[${s}].${e}`})}});let f=new Set(e.zOrder);for(let a of e.elements)f.has(a.id)||t.push({code:"missing_z_order_element",elementId:a.id,message:`Element "${a.id}" is missing from zOrder.`,path:"zOrder"});for(let a of e.zOrder)l.has(a)||t.push({code:"unknown_z_order_element",elementId:a,message:`zOrder references missing element "${a}".`,path:"zOrder"});for(let[a,s]of e.layouts.entries())for(let e of s.ids){let s=l.get(e);s&&a0(s)||t.push({code:"unknown_layout_target",elementId:e,message:`Layout references missing or non-positioned element "${e}".`,path:`layouts[${a}].ids`})}for(let a of e.elements.filter(e=>"frame"===e.type)){let e=new Set([a.id]),s=a.frameId;for(;s;){if(e.has(s)){t.push({code:"invalid_composition",elementId:a.id,message:`Frame "${a.id}" participates in a frame nesting cycle.`,path:"elements"});break}e.add(s);let i=l.get(s);s=i?.type==="frame"?i.frameId:void 0}}return t}function st(e){if("text"===e.type){let t=e.text.split("\n");return{x:e.x,y:e.y,width:e.maxWidth??aq(e.text,e.fontSize),height:t.length*e.fontSize*(e.lineHeight??1.35)}}return{x:e.x,y:e.y,width:e.width,height:e.height}}function sa(e,t){let a=new Map(e.map(e=>[e.id,e]));return t.flatMap(e=>{let t=a.get(e);return t&&a0(t)?[t]:[]})}function ss(e,t){return e.map(e=>{var a,s;let i=t.get(e.id);return i?(a=i.x,s=i.y,a0(e)?{...e,x:a,y:s}:e):e})}function si(e,t){return"x"===t?e.x:e.y}function sl(e,t){return"x"===t?e.width:e.height}function so(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function sr(e,t){let a=so(e),s=t.x-a.x,i=t.y-a.y,[l,o]=Math.abs(s)>=Math.abs(i)?[s>=0?"right":"left",{x:s>=0?e.x+e.width:e.x,y:a.y}]:[i>=0?"bottom":"top",{x:a.x,y:i>=0?e.y+e.height:e.y}];return"type"in e&&"node"===e.type&&aY(e.shape)?aj({...e,shape:e.shape},l,o):o}function sn(e,t){let a=t.width/2,s=t.height/2,i=(e.x-t.x-a)/a,l=(e.y-t.y-s)/s,o="node"===t.type?t.shape:"rectangle";if("node"===t.type&&aY(t.shape))return aN({...t,shape:t.shape},e,1);let r=.5/Math.min(a,s);if("ellipse"===o||"circle"===o)return Math.abs(Math.hypot(i,l)-1)<=r;if("diamond"===o)return Math.abs(Math.abs(i)+Math.abs(l)-1)<=r;let n=(e,t,a)=>e>=t-.5&&e<=a+.5,c=(e,t)=>.5>=Math.abs(e-t);return n(e.y,t.y,t.y+t.height)&&(c(e.x,t.x)||c(e.x,t.x+t.width))||n(e.x,t.x,t.x+t.width)&&(c(e.y,t.y)||c(e.y,t.y+t.height))}function sc(e,t){let a=sr(e,so(t)),s=sr(t,so(e)),i=so(e),l=so(t),o=Math.abs(l.x-i.x)>=Math.abs(l.y-i.y),r=o?"x":"y",n=(s[r]-a[r])/2,c=(e,t)=>o?{x:e.x+t,y:e.y}:{x:e.x,y:e.y+t};return aL([a,c(a,n),c(s,-n),s])}function sd(e){return new Map(e.flatMap(e=>"node"===e.type||"frame"===e.type&&void 0!==e.nodeId?[[e.nodeId,e]]:[]))}function sp(e,t=.01){let a=[];for(let s=0;s<e.length-1;s+=1){let i=e[s],l=e[s+1];if(!i||!l)continue;let o=Math.abs(i.y-l.y)<=t,r=Math.abs(i.x-l.x)<=t;if(!o&&!r)continue;let n=Math.min(o?i.x:i.y,o?l.x:l.y),c=Math.max(o?i.x:i.y,o?l.x:l.y);c-n<=t||a.push({min:n,max:c,orientation:o?"horizontal":"vertical",staticCoordinate:o?i.y:i.x,segmentIndex:s,isFirstSegment:0===s,isLastSegment:s===e.length-2})}return a}function sh(e,t){return Math.min(e.max,t.max)-Math.max(e.min,t.min)}function sg(e,t,a=.01){return e.orientation===t.orientation&&Math.abs(e.staticCoordinate-t.staticCoordinate)<=a&&sh(e,t)>a}function su(e,t,a=.01){let s="horizontal"===e.orientation,i=s?t.y:t.x,l=i+(s?t.height:t.width),o=s?t.x:t.y,r=o+(s?t.width:t.height);return e.staticCoordinate>i+a&&e.staticCoordinate<l-a&&Math.min(e.max,r)-Math.max(e.min,o)>a}function sf(e,t){return e.isFirstSegment&&t.isFirstSegment&&null!==e.startBindingId&&e.startBindingId===t.startBindingId||e.isLastSegment&&t.isLastSegment&&null!==e.endBindingId&&e.endBindingId===t.endBindingId}function sm(e,t,a,s=0){let i=-1/0;for(let l of t)for(let t of e)l.x0<t.x1+s&&t.x0<l.x1+s&&(i=Math.max(i,t.y1+a-l.y0));return i}function sv(e,t,a,s=0){let i=-1/0;for(let l of t)for(let t of e)l.y0<t.y1+s&&t.y0<l.y1+s&&(i=Math.max(i,t.x1+a-l.x0));return i}function sy(e,t,a="characters"){let s=0x811c9dc5;for(let t=0;t<e.length;t+=1)s^=e.charCodeAt(t),s=Math.imul(s,0x1000193),"characters"===a&&(e.codePointAt(t)??0)>65535&&(t+=1);return"seed"===t?Math.abs(s)||1:(s>>>0).toString(16).padStart(8,"0")}i.gPz([ey,eA,eY,et,R,e0,ts,tx,tj,ad]);let sw={id:"multi-stage-rework",title:"Rework earlier stages",nodes:[{id:"start",label:"Received",kind:"start"},...["Intake","Validate","Assemble","Review","Rework","Release"].map((e,t)=>({id:String(t),label:e,kind:5===t?"end":"process"}))],edges:[{id:"start",source:"start",target:"0"},...Array.from({length:5},(e,t)=>({id:`e${t}`,source:String(t),target:String(t+1)})),...Array.from({length:4},(e,t)=>({id:`back${t}`,source:"4",target:String(t),...0===t?{label:"Retry"}:{}}))]},sx={id:"two-stage-retry",title:"Revisit earlier checks",nodes:[{id:"s",label:"Received",kind:"start"},...["Prepare","Inspect","Review","Rework"].map((e,t)=>({id:["a","b","c","d"][t],label:e,kind:"process"})),{id:"end",label:"Released",kind:"end"}],edges:[["s","a"],["a","b"],["b","c"],["c","d"],["d","end"],["d","a"],["d","b"]].map(([e,t],a)=>({id:`e${a}`,source:e,target:t}))};function sb(e){return eC({...e,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}})}function sk(e,t="TB"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}function sM(e){return eC({...e,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}})}function sC(e){return te({...e,type:ej})}eC({id:"package-chain",title:"Request to hosted artifact",nodes:[{id:"app",label:"App request",kind:"start"},{id:"agent",label:"Agent / orchestration",kind:"process"},{id:"core",label:"Core diagram model",kind:"process"},{id:"renderer",label:"Renderer",kind:"process"},{id:"export",label:"Excalidraw export",kind:"process"},{id:"host",label:"Artifact hosting / storage",kind:"process"},{id:"response",label:"Hosted artifact response",kind:"end"}],edges:[{id:"request",source:"app",target:"agent",label:"Request contract"},{id:"build",source:"agent",target:"core",label:"Semantic builder input"},{id:"validate",source:"core",target:"renderer",label:"Validated diagram spec"},{id:"render",source:"renderer",target:"export",label:"CanvasSpec scene"},{id:"store",source:"export",target:"host",label:"Exported artifact bundle"},{id:"respond",source:"host",target:"response",label:"Artifact ID + hosted URLs"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"scope-bypass",title:"Diagram request",nodes:[{id:"received",label:"Prompt received",kind:"start"},{id:"requirements",label:"Extract requirements",kind:"process"},{id:"scope",label:"Is the scope clear?",kind:"decision"},{id:"draft",label:"Draft typed IR",kind:"process"},{id:"review",label:"Review",kind:"end"}],edges:[{id:"extract",source:"received",target:"requirements"},{id:"assess",source:"requirements",target:"scope"},{id:"clear",source:"scope",target:"draft",label:"Yes"},{id:"unclear",source:"scope",target:"review",label:"No"},{id:"submit",source:"draft",target:"review"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"rollout-failures",title:"Feature flag rollout",nodes:[{id:"ready",label:"Flag is ready",kind:"start"},{id:"internal",label:"Enable internally",kind:"process"},{id:"internal-health",label:"Internal checks healthy?",kind:"decision"},{id:"beta",label:"Enable beta cohort",kind:"process"},{id:"beta-health",label:"Beta checks healthy?",kind:"decision"},{id:"ramp",label:"Ramp to all users",kind:"process"},{id:"complete",label:"Rollout complete",kind:"end"},{id:"rollback",label:"Roll back the feature",kind:"end"}],edges:[{id:"enable",source:"ready",target:"internal"},{id:"check-internal",source:"internal",target:"internal-health"},{id:"internal-healthy",source:"internal-health",target:"beta",label:"Healthy"},{id:"internal-fail",source:"internal-health",target:"rollback",label:"Fail"},{id:"check-beta",source:"beta",target:"beta-health"},{id:"beta-healthy",source:"beta-health",target:"ramp",label:"Healthy"},{id:"beta-unhealthy",source:"beta-health",target:"rollback",label:"Unhealthy"},{id:"finish",source:"ramp",target:"complete"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"release-fan-in",title:"Fix release",nodes:[{id:"confirmed",label:"Bug confirmed",kind:"start"},{id:"security",label:"Security impact?",kind:"decision"},{id:"triage",label:"Security triage",kind:"process"},{id:"hotfix",label:"Hotfix branch",kind:"process"},{id:"priority",label:"High priority?",kind:"decision"},{id:"sprint",label:"Sprint backlog",kind:"process"},{id:"release",label:"Release fix",kind:"end"},{id:"backlog",label:"Regular backlog",kind:"end"}],edges:[{id:"assess",source:"confirmed",target:"security"},{id:"secure",source:"security",target:"triage",label:"Yes"},{id:"branch",source:"triage",target:"hotfix"},{id:"ship-hotfix",source:"hotfix",target:"release"},{id:"prioritize",source:"security",target:"priority",label:"No"},{id:"plan",source:"priority",target:"sprint",label:"Yes"},{id:"ship-sprint",source:"sprint",target:"release"},{id:"defer",source:"priority",target:"backlog",label:"No"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"stability-fan-in",title:"Incident remediation",nodes:[{id:"evidence",label:"Collect evidence",kind:"start"},{id:"cause",label:"Classify root cause",kind:"decision"},{id:"rollback",label:"Roll back deploy",kind:"process"},{id:"hotfix",label:"Prepare hotfix",kind:"process"},{id:"provider",label:"Escalate to provider",kind:"process"},{id:"stable",label:"Service stable?",kind:"decision"},{id:"monitor",label:"Monitor service",kind:"end"},{id:"escalate",label:"Escalate unstable service",kind:"process"},{id:"fresh",label:"Collect fresh evidence",kind:"process"}],edges:[{id:"classify",source:"evidence",target:"cause"},{id:"deploy",source:"cause",target:"rollback",label:"Deploy"},{id:"code",source:"cause",target:"hotfix",label:"Code"},{id:"vendor",source:"cause",target:"provider",label:"Provider"},{id:"check-rollback",source:"rollback",target:"stable"},{id:"check-hotfix",source:"hotfix",target:"stable"},{id:"check-provider",source:"provider",target:"stable"},{id:"healthy",source:"stable",target:"monitor",label:"Yes"},{id:"unhealthy",source:"stable",target:"escalate",label:"No"},{id:"gather",source:"escalate",target:"fresh"},{id:"retry",source:"fresh",target:"cause"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"renewal-retry",title:"Subscription renewal",nodes:[{id:"due",label:"Renewal due",kind:"start"},{id:"charge",label:"Charge payment",kind:"process"},{id:"paid",label:"Payment succeeded?",kind:"decision"},{id:"renew",label:"Renew subscription",kind:"end"},{id:"remind",label:"Send reminder",kind:"process"},{id:"updated",label:"Payment updated?",kind:"decision"},{id:"pause",label:"Pause subscription",kind:"end"}],edges:[{id:"bill",source:"due",target:"charge"},{id:"confirm",source:"charge",target:"paid"},{id:"renewed",source:"paid",target:"renew",label:"Yes"},{id:"declined",source:"paid",target:"remind",label:"No"},{id:"wait",source:"remind",target:"updated"},{id:"retry",source:"updated",target:"charge",label:"Yes"},{id:"expired",source:"updated",target:"pause",label:"No"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"cancellation-convergence",title:"Subscription cancellation",nodes:[{id:"requested",label:"Member requests cancellation",kind:"start"},{id:"reason",label:"Collect the cancellation reason",kind:"process"},{id:"eligible",label:"Eligible for a retention offer?",kind:"decision"},{id:"offer",label:"Present retention offer",kind:"process"},{id:"accepted",label:"Offer accepted?",kind:"decision"},{id:"keep",label:"Retain member",kind:"end"},{id:"confirm",label:"Confirm cancellation",kind:"process"},{id:"close",label:"Close account",kind:"end"}],edges:[{id:"record",source:"requested",target:"reason"},{id:"check",source:"reason",target:"eligible"},{id:"offer-save",source:"eligible",target:"offer",label:"Yes"},{id:"not-eligible",source:"eligible",target:"confirm",label:"No"},{id:"decide",source:"offer",target:"accepted"},{id:"kept",source:"accepted",target:"keep",label:"Yes"},{id:"declined",source:"accepted",target:"confirm",label:"No"},{id:"close-account",source:"confirm",target:"close"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"shared-feedback-returns",title:"Revisit earlier checks",nodes:[{id:"start",label:"Received",kind:"start"},{id:"a",label:"Intake",kind:"process"},{id:"b",label:"Inspect",kind:"process"},{id:"c",label:"Review",kind:"process"},{id:"d",label:"Approve",kind:"process"},{id:"end",label:"Released",kind:"end"}],edges:[{id:"entry",source:"start",target:"a"},{id:"ab",source:"a",target:"b"},{id:"bc",source:"b",target:"c"},{id:"cd",source:"c",target:"d"},{id:"release",source:"d",target:"end"},{id:"ba",source:"b",target:"a"},{id:"ca",source:"c",target:"a",label:"Retry"},{id:"da",source:"d",target:"a"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({...sx,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"feedback-chain",title:"Repeat inspection",nodes:[{id:"start",label:"Received",kind:"start"},{id:"a",label:"Prepare",kind:"process"},{id:"b",label:"Inspect",kind:"process"},{id:"c",label:"Approve",kind:"process"},{id:"end",label:"Released",kind:"end"}],edges:[{id:"start",source:"start",target:"a"},{id:"ab",source:"a",target:"b"},{id:"bc",source:"b",target:"c"},{id:"ca",source:"c",target:"a",label:"Retry"},{id:"end",source:"c",target:"end"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({...sw,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"feedback-skip-stubs",title:"Retry with skipped stages",nodes:[{id:"0",label:"Step 0",kind:"start"},{id:"1",label:"Step 1",kind:"process"},{id:"2",label:"Step 2",kind:"process"},{id:"3",label:"Step 3",kind:"process"},{id:"4",label:"Step 4",kind:"process"},{id:"5",label:"Step 5",kind:"end"}],edges:[{id:"e0",source:"0",target:"1"},{id:"e1",source:"1",target:"2"},{id:"e2",source:"2",target:"3"},{id:"e3",source:"3",target:"4",label:"Path 3"},{id:"e4",source:"4",target:"5"},{id:"e5",source:"3",target:"5"},{id:"feedback",source:"4",target:"1"},{id:"e7",source:"2",target:"4"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"decision-feedback",title:"Retry a failed attempt",nodes:[{id:"start",label:"Start",kind:"start"},{id:"attempt",label:"Attempt",kind:"process"},{id:"check",label:"Success?",kind:"decision"},{id:"done",label:"Done",kind:"end"}],edges:[{id:"start",source:"start",target:"attempt"},{id:"check",source:"attempt",target:"check"},{id:"yes",source:"check",target:"done",label:"Yes"},{id:"feedback",source:"check",target:"attempt",label:"Retry"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"review-feedback",title:"Review feedback",nodes:[{id:"start",label:"Received",kind:"start"},{id:"prepare",label:"Prepare submission",kind:"process"},{id:"review",label:"Ready?",kind:"decision"},{id:"revise",label:"Request changes",kind:"process"},{id:"done",label:"Accepted",kind:"end"}],edges:[{id:"start",source:"start",target:"prepare"},{id:"review",source:"prepare",target:"review"},{id:"no",source:"review",target:"revise",label:"No"},{id:"feedback",source:"revise",target:"prepare",label:"Changes ready"},{id:"yes",source:"review",target:"done",label:"Yes"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"wait-retry",title:"Wait and retry",nodes:[{id:"start",label:"Join queue",kind:"start"},{id:"responds",label:"Responds?",kind:"decision"},{id:"leave",label:"Leave queue",kind:"end"},{id:"ready",label:"Ready?",kind:"decision"},{id:"done",label:"Continue",kind:"end"},{id:"wait",label:"Keep waiting",kind:"process"}],edges:[{id:"start",source:"start",target:"responds"},{id:"leave",source:"responds",target:"leave",label:"No"},{id:"ready",source:"responds",target:"ready",label:"Yes"},{id:"done",source:"ready",target:"done",label:"Yes"},{id:"wait",source:"ready",target:"wait",label:"No"},{id:"feedback",source:"wait",target:"responds"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"content-moderation-flow",title:"Content moderation flow",nodes:[{id:"report",label:"Report received",kind:"start"},{id:"scan",label:"Automated scan runs",kind:"process"},{id:"severe",label:"Severe harm detected?",kind:"decision"},{id:"remove",label:"Remove content",kind:"process"},{id:"escalate",label:"Escalate to safety",kind:"process"},{id:"violation",label:"Policy violation?",kind:"decision"},{id:"restore_none",label:"Restore content",kind:"end"},{id:"review",label:"Human review",kind:"process"},{id:"action",label:"Action needed?",kind:"decision"},{id:"limit",label:"Limit content",kind:"end"},{id:"restore_review",label:"Restore content",kind:"end"},{id:"closed_severe",label:"Severe case closed",kind:"end"}],edges:[{id:"edge-1",source:"report",target:"scan"},{id:"edge-2",source:"scan",target:"severe"},{id:"edge-3",source:"severe",target:"remove",label:"Yes"},{id:"edge-4",source:"severe",target:"violation",label:"No"},{id:"edge-5",source:"remove",target:"escalate"},{id:"edge-6",source:"escalate",target:"closed_severe"},{id:"edge-7",source:"violation",target:"restore_none",label:"No"},{id:"edge-8",source:"violation",target:"review",label:"Yes"},{id:"edge-9",source:"review",target:"action"},{id:"edge-10",source:"action",target:"limit",label:"Yes"},{id:"edge-11",source:"action",target:"restore_review",label:"No"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"data-import-validation",title:"Data import validation",nodes:[{id:"upload",label:"File uploaded",kind:"start"},{id:"parse",label:"Parse file",kind:"process"},{id:"parse_ok",label:"Parsing succeeded?",kind:"decision"},{id:"reject",label:"Reject file",kind:"process"},{id:"rejected_end",label:"File rejected",kind:"end"},{id:"validate",label:"Validate schema",kind:"process"},{id:"schema_ok",label:"Schema valid?",kind:"decision"},{id:"mapping_errors",label:"Return mapping errors",kind:"process"},{id:"mapping_end",label:"Mapping errors returned",kind:"end"},{id:"dedupe",label:"Deduplicate records",kind:"process"},{id:"dup_found",label:"Duplicates found?",kind:"decision"},{id:"merge",label:"Merge duplicates",kind:"process"},{id:"import",label:"Import records",kind:"process"},{id:"done",label:"Import complete",kind:"end"}],edges:[{id:"edge-1",source:"upload",target:"parse"},{id:"edge-2",source:"parse",target:"parse_ok"},{id:"edge-3",source:"parse_ok",target:"reject",label:"No"},{id:"edge-4",source:"reject",target:"rejected_end"},{id:"edge-5",source:"parse_ok",target:"validate",label:"Yes"},{id:"edge-6",source:"validate",target:"schema_ok"},{id:"edge-7",source:"schema_ok",target:"mapping_errors",label:"No"},{id:"edge-8",source:"mapping_errors",target:"mapping_end"},{id:"edge-9",source:"schema_ok",target:"dedupe",label:"Yes"},{id:"edge-10",source:"dedupe",target:"dup_found"},{id:"edge-11",source:"dup_found",target:"merge",label:"Yes"},{id:"edge-12",source:"merge",target:"import"},{id:"edge-13",source:"dup_found",target:"import",label:"No"},{id:"edge-14",source:"import",target:"done"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"incident-escalation-flowchart",title:"Incident Escalation Flowchart",nodes:[{id:"alert",label:"Monitoring creates alert",kind:"start"},{id:"ack",label:"Responder acknowledges alert",kind:"process"},{id:"severity",label:"Severity?",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"triage",label:"Triage queue",kind:"process"},{id:"monitor_low",label:"Monitoring: low-severity incident",kind:"process"},{id:"mitigate",label:"Mitigate impact",kind:"process"},{id:"comms",label:"Send customer communications",kind:"process"},{id:"resolve_bridge",label:"Resolve incident",kind:"end"},{id:"fix",label:"Fix available?",kind:"decision"},{id:"resolve_fix",label:"Resolve incident (fix found)",kind:"end"},{id:"escalate",label:"Escalate to incident bridge",kind:"process"},{id:"resolved_low",label:"Resolved",kind:"end"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"severity"},{id:"edge-3",source:"severity",target:"bridge",label:"High"},{id:"edge-4",source:"severity",target:"triage",label:"Medium"},{id:"edge-5",source:"severity",target:"monitor_low",label:"Low"},{id:"edge-6",source:"bridge",target:"mitigate"},{id:"edge-7",source:"mitigate",target:"comms"},{id:"edge-8",source:"comms",target:"resolve_bridge"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"resolve_fix",label:"Yes"},{id:"edge-11",source:"fix",target:"escalate",label:"No"},{id:"edge-12",source:"escalate",target:"bridge"},{id:"edge-13",source:"monitor_low",target:"resolved_low"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"invoice-approval",title:"Invoice approval",nodes:[{id:"received",label:"Invoice received",kind:"start"},{id:"match_po",label:"Match invoice to purchase order",kind:"process"},{id:"po_matched",label:"Invoice matches PO?",kind:"decision"},{id:"exception_review",label:"Route to exception review",kind:"process"},{id:"exception_resolved",label:"Exception resolved?",kind:"decision"},{id:"reject",label:"Reject invoice",kind:"end"},{id:"over_threshold",label:"Amount over approval threshold?",kind:"decision"},{id:"director_approval",label:"Director approval before payment",kind:"process"},{id:"schedule_payment",label:"Schedule payment",kind:"process"},{id:"paid",label:"Payment scheduled",kind:"end"}],edges:[{id:"e1",source:"received",target:"match_po"},{id:"e2",source:"match_po",target:"po_matched"},{id:"e3",source:"po_matched",target:"over_threshold",label:"Yes"},{id:"e4",source:"po_matched",target:"exception_review",label:"No"},{id:"e5",source:"exception_review",target:"exception_resolved"},{id:"e6",source:"exception_resolved",target:"over_threshold",label:"Yes"},{id:"e7",source:"exception_resolved",target:"reject",label:"No"},{id:"e8",source:"over_threshold",target:"director_approval",label:"Yes"},{id:"e9",source:"over_threshold",target:"schedule_payment",label:"No"},{id:"e10",source:"director_approval",target:"schedule_payment"},{id:"e11",source:"schedule_payment",target:"paid"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"loan-underwriting",title:"Loan Application Underwriting",nodes:[{id:"submit",label:"Application submitted",kind:"start"},{id:"verify_id",label:"Verify identity",kind:"process"},{id:"id_ok",label:"Identity verified?",kind:"decision"},{id:"credit_review",label:"Credit review",kind:"process"},{id:"credit_ok",label:"Credit acceptable?",kind:"decision"},{id:"manual_uw",label:"Manual underwriting",kind:"process"},{id:"exception",label:"Exception approved?",kind:"decision"},{id:"income",label:"Income verification",kind:"process"},{id:"approve",label:"Loan approved",kind:"end"},{id:"decline",label:"Decline application",kind:"end"}],edges:[{id:"e1",source:"submit",target:"verify_id"},{id:"e2",source:"verify_id",target:"id_ok"},{id:"e3",source:"id_ok",target:"credit_review",label:"Yes"},{id:"e4",source:"id_ok",target:"decline",label:"No"},{id:"e5",source:"credit_review",target:"credit_ok"},{id:"e6",source:"credit_ok",target:"income",label:"Yes"},{id:"e7",source:"credit_ok",target:"manual_uw",label:"No"},{id:"e8",source:"manual_uw",target:"exception"},{id:"e9",source:"exception",target:"income",label:"Yes"},{id:"e10",source:"exception",target:"decline",label:"No"},{id:"e11",source:"income",target:"approve"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"patient-intake-scheduling",title:"Patient Intake Scheduling",nodes:[{id:"request",label:"Patient requests appointment",kind:"start"},{id:"collect",label:"Clinic collects intake information",kind:"process"},{id:"urgent",label:"Urgent symptoms?",kind:"decision"},{id:"triage",label:"Nurse triage",kind:"process"},{id:"same_day",label:"Schedule same-day appointment",kind:"process"},{id:"insurance",label:"Is insurance valid?",kind:"decision"},{id:"routine",label:"Schedule routine appointment",kind:"process"},{id:"self_pay_q",label:"Patient accepts self-pay?",kind:"decision"},{id:"self_pay",label:"Schedule routine care (self-pay)",kind:"process"},{id:"billing",label:"Refer to billing",kind:"process"},{id:"end_same_day",label:"Same-day visit booked",kind:"end"},{id:"end_routine",label:"Routine visit booked",kind:"end"},{id:"end_self_pay",label:"Self-pay visit booked",kind:"end"},{id:"end_billing",label:"Billing referral made",kind:"end"}],edges:[{id:"e1",source:"request",target:"collect"},{id:"e2",source:"collect",target:"urgent"},{id:"e3",source:"urgent",target:"triage",label:"Yes"},{id:"e4",source:"triage",target:"same_day"},{id:"e5",source:"same_day",target:"end_same_day"},{id:"e6",source:"urgent",target:"insurance",label:"No"},{id:"e7",source:"insurance",target:"routine",label:"Valid"},{id:"e8",source:"routine",target:"end_routine"},{id:"e9",source:"insurance",target:"self_pay_q",label:"Invalid"},{id:"e10",source:"self_pay_q",target:"self_pay",label:"Yes"},{id:"e11",source:"self_pay",target:"end_self_pay"},{id:"e12",source:"self_pay_q",target:"billing",label:"No"},{id:"e13",source:"billing",target:"end_billing"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"pharma-batch-disposition",title:"Pharma Batch Disposition",nodes:[{id:"received",label:"Batch received",kind:"start"},{id:"coa_review",label:"QA reviews Certificate of Analysis (CoA)",kind:"process"},{id:"spec_check",label:"Batch passes specs?",kind:"decision"},{id:"final_review",label:"QA Manager final review",kind:"process"},{id:"packaging",label:"Packaging",kind:"process"},{id:"released",label:"Packaged batch released",kind:"end"},{id:"investigation",label:"Investigation",kind:"process"},{id:"rejected",label:"Reject batch",kind:"end"}],edges:[{id:"e1",source:"received",target:"coa_review"},{id:"e2",source:"coa_review",target:"spec_check"},{id:"e3",source:"spec_check",target:"final_review",label:"Pass"},{id:"e4",source:"spec_check",target:"investigation",label:"Retest"},{id:"e5",source:"spec_check",target:"rejected",label:"Reject"},{id:"e6",source:"final_review",target:"packaging"},{id:"e7",source:"packaging",target:"released"},{id:"e8",source:"investigation",target:"final_review",label:"Returns to final review"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"warehouse-reorder-flow",title:"Warehouse reorder flow",nodes:[{id:"count",label:"Stock count updated",kind:"start"},{id:"reorder_check",label:"Inventory below reorder point?",kind:"decision"},{id:"monitor",label:"Monitor stock",kind:"process"},{id:"monitor_end",label:"Stock monitoring continues",kind:"end"},{id:"check_supplier",label:"Check supplier availability",kind:"process"},{id:"supplier_check",label:"Supplier available?",kind:"decision"},{id:"substitute",label:"Use substitute supplier",kind:"process"},{id:"create_po",label:"Create purchase order",kind:"process"},{id:"await_delivery",label:"Await delivery",kind:"process"},{id:"reorder_end",label:"Reorder cycle complete",kind:"end"}],edges:[{id:"e1",source:"count",target:"reorder_check"},{id:"e2",source:"reorder_check",target:"monitor",label:"No"},{id:"e3",source:"monitor",target:"monitor_end"},{id:"e4",source:"reorder_check",target:"check_supplier",label:"Yes"},{id:"e5",source:"check_supplier",target:"supplier_check"},{id:"e6",source:"supplier_check",target:"create_po",label:"Yes"},{id:"e7",source:"supplier_check",target:"substitute",label:"No"},{id:"e8",source:"substitute",target:"create_po"},{id:"e9",source:"create_po",target:"await_delivery"},{id:"e10",source:"await_delivery",target:"reorder_end"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),sb({id:"loan-application-underwriting",title:"Loan Application Underwriting",nodes:[{id:"submitted",label:"Application submitted",kind:"start"},{id:"identity",label:"Verify identity",kind:"process"},{id:"identity_decision",label:"Identity verified?",kind:"decision"},{id:"identity_decline",label:"Decline application",kind:"end"},{id:"credit",label:"Credit review",kind:"process"},{id:"credit_decision",label:"Acceptable credit?",kind:"decision"},{id:"manual",label:"Manual underwriting",kind:"process"},{id:"exception",label:"Exception approved?",kind:"decision"},{id:"exception_decline",label:"Decline application",kind:"end"},{id:"income",label:"Income verification",kind:"process"},{id:"approved",label:"Approve loan",kind:"end"}],edges:[{id:"edge-1",source:"submitted",target:"identity"},{id:"edge-2",source:"identity",target:"identity_decision"},{id:"edge-3",source:"identity_decision",target:"identity_decline",label:"Failed"},{id:"edge-4",source:"identity_decision",target:"credit",label:"Verified"},{id:"edge-5",source:"credit",target:"credit_decision"},{id:"edge-6",source:"credit_decision",target:"income",label:"Acceptable"},{id:"edge-7",source:"credit_decision",target:"manual",label:"Unacceptable"},{id:"edge-8",source:"manual",target:"exception"},{id:"edge-9",source:"exception",target:"income",label:"Yes"},{id:"edge-10",source:"exception",target:"exception_decline",label:"No"},{id:"edge-11",source:"income",target:"approved"}],layout:{direction:"TB"}}),sb({id:"invoice-approval-flowchart",title:"Invoice approval flowchart",nodes:[{id:"received",label:"Invoice received",kind:"start"},{id:"match",label:"Match to purchase order",kind:"process"},{id:"matches",label:"Matches purchase order?",kind:"decision"},{id:"review",label:"Exception review",kind:"process"},{id:"resolved",label:"Exception resolved?",kind:"decision"},{id:"reject",label:"Reject invoice",kind:"end"},{id:"threshold",label:"Amount over approval threshold?",kind:"decision"},{id:"director",label:"Director approval",kind:"process"},{id:"schedule",label:"Schedule payment",kind:"process"},{id:"payment",label:"Payment",kind:"end"}],edges:[{id:"edge-1",source:"received",target:"match"},{id:"edge-2",source:"match",target:"matches"},{id:"edge-3",source:"matches",target:"review",label:"No"},{id:"edge-4",source:"review",target:"resolved"},{id:"edge-5",source:"resolved",target:"reject",label:"No — unresolved"},{id:"edge-6",source:"resolved",target:"threshold",label:"Yes — resolved"},{id:"edge-7",source:"matches",target:"threshold",label:"Yes — matched"},{id:"edge-8",source:"threshold",target:"director",label:"Yes — over threshold"},{id:"edge-9",source:"threshold",target:"schedule",label:"No — at or below threshold"},{id:"edge-10",source:"director",target:"schedule"},{id:"edge-11",source:"schedule",target:"payment"}],layout:{direction:"TB"}}),sb({id:"identifier-labels",title:"Identifier labels",nodes:[{id:"call",label:"buildSequenceDiagram",kind:"start"},{id:"check",label:"Layout renderer-independent?",kind:"decision"},{id:"export",label:"exportToExcalidrawScene(spec)",kind:"process"},{id:"fetch",label:"Fetch https://playground.sketchi.app/api/v1/artifacts/download",kind:"process"},{id:"cjk",label:"品質保証レビュー承認待ち",kind:"process"},{id:"done",label:"Ship 🚀 release",kind:"end"}],edges:[{id:"e1",source:"call",target:"check"},{id:"e2",source:"check",target:"export",label:"renderer-independent"},{id:"e3",source:"check",target:"fetch",label:"buildSequenceDiagram"},{id:"e4",source:"export",target:"cjk",label:"品質保証レビュー承認待ち"},{id:"e5",source:"fetch",target:"done",label:"https://example.com/api/v1/artifacts/download"},{id:"e6",source:"cjk",target:"done",label:"🚀🚀 shipped"}],layout:{direction:"TB"}}),sb({id:"multiline-labels",title:"Multi-line labels",nodes:[{id:"request",label:"Refund requested",kind:"start"},{id:"eligible",label:"Refund within the policy window?",kind:"decision"},{id:"provider",label:"Ask the payment provider",kind:"process"},{id:"confirmed",label:"Provider confirmed?",kind:"decision"},{id:"refund",label:"Issue the refund",kind:"process"},{id:"deny",label:"Explain the decision to the customer",kind:"end"},{id:"closed",label:"Refund closed",kind:"end"}],edges:[{id:"e1",source:"request",target:"eligible"},{id:"e2",source:"eligible",target:"provider",label:"Yes, within the window and eligible for a full refund"},{id:"e3",source:"eligible",target:"deny",label:"No — outside\nthe policy window"},{id:"e4",source:"provider",target:"confirmed",label:"Request sent to the provider"},{id:"e5",source:"confirmed",target:"refund",label:"Confirmed by the provider"},{id:"e6",source:"confirmed",target:"provider",label:"Retry after the provider\nconfirms the hold"},{id:"e7",source:"refund",target:"closed"}],layout:{direction:"TB"}}),sb({id:"competing-branch-labels",title:"Competing branch labels",nodes:[{id:"triage",label:"Triage the report",kind:"start"},{id:"kind",label:"Which kind of report?",kind:"decision"},{id:"bug",label:"Reproduce the bug",kind:"process"},{id:"feature",label:"Log the feature",kind:"process"},{id:"question",label:"Answer the question",kind:"process"},{id:"duplicate",label:"Link the duplicate",kind:"process"},{id:"reproduced",label:"Reproduced?",kind:"decision"},{id:"fix",label:"Fix and verify",kind:"process"},{id:"closed",label:"Close the report",kind:"end"}],edges:[{id:"e1",source:"triage",target:"kind"},{id:"e2",source:"kind",target:"bug",label:"Unexpected behavior"},{id:"e3",source:"kind",target:"feature",label:"Enhancement"},{id:"e4",source:"kind",target:"question",label:"Unanswered question"},{id:"e5",source:"kind",target:"duplicate",label:"Duplicate"},{id:"e6",source:"bug",target:"reproduced"},{id:"e7",source:"reproduced",target:"fix",label:"Reproduced"},{id:"e8",source:"reproduced",target:"bug",label:"Unreproducible"},{id:"e9",source:"fix",target:"closed"},{id:"e10",source:"feature",target:"closed"},{id:"e11",source:"question",target:"closed"},{id:"e12",source:"duplicate",target:"closed"}],layout:{direction:"TB"}}),sk({id:"grouped-approval",title:"Expense approval by team",groups:[{id:"employee",label:"Employee"},{id:"manager",label:"Manager"},{id:"finance",label:"Finance"}],nodes:[{id:"incurred",label:"Expense incurred",kind:"start"},{id:"submit",label:"Submit expense report",kind:"process",group:"employee"},{id:"review",label:"Review the report",kind:"process",group:"manager"},{id:"approved",label:"Approved?",kind:"decision",group:"manager"},{id:"revise",label:"Revise the report",kind:"process",group:"employee"},{id:"verify",label:"Verify receipts",kind:"process",group:"finance"},{id:"pay",label:"Pay the employee",kind:"process",group:"finance"},{id:"paid",label:"Expense paid",kind:"end"}],edges:[{id:"e1",source:"incurred",target:"submit"},{id:"e2",source:"submit",target:"review"},{id:"e3",source:"review",target:"approved"},{id:"e4",source:"approved",target:"verify",label:"yes"},{id:"e5",source:"approved",target:"revise",label:"no"},{id:"e6",source:"revise",target:"submit"},{id:"e7",source:"verify",target:"pay"},{id:"e8",source:"pay",target:"paid"}]}),sk({id:"three-zone-service",title:"Request path across network zones",groups:[{id:"internet",label:"Public internet"},{id:"edge",label:"Edge network"},{id:"private",label:"Private subnet"}],nodes:[{id:"browser",label:"Browser sends request",kind:"start",group:"internet"},{id:"cdn",label:"CDN serves cache",kind:"process",group:"edge"},{id:"cached",label:"Cache hit?",kind:"decision",group:"edge"},{id:"waf",label:"WAF filters traffic",kind:"process",group:"edge"},{id:"api",label:"API handles request",kind:"process",group:"private"},{id:"db",label:"Query the database",kind:"process",group:"private"},{id:"response",label:"Response returned",kind:"end"}],edges:[{id:"e1",source:"browser",target:"cdn"},{id:"e2",source:"cdn",target:"cached"},{id:"e3",source:"cached",target:"response",label:"hit"},{id:"e4",source:"cached",target:"waf",label:"miss"},{id:"e5",source:"waf",target:"api"},{id:"e6",source:"api",target:"db"},{id:"e7",source:"db",target:"response"}]},"LR"),sk({id:"mixed-membership",title:"Order fulfilment with partial grouping",groups:[{id:"warehouse",label:"Warehouse"},{id:"shipping",label:"Shipping partner"}],nodes:[{id:"order",label:"Order placed",kind:"start"},{id:"fraud",label:"Fraud check passed?",kind:"decision"},{id:"pick",label:"Pick items",kind:"process",group:"warehouse"},{id:"pack",label:"Pack the order",kind:"process",group:"warehouse"},{id:"label",label:"Print shipping label",kind:"process",group:"warehouse"},{id:"collect",label:"Collect parcel",kind:"process",group:"shipping"},{id:"deliver",label:"Deliver to customer",kind:"end",group:"shipping"},{id:"cancel",label:"Cancel the order",kind:"end"}],edges:[{id:"e1",source:"order",target:"fraud"},{id:"e2",source:"fraud",target:"pick",label:"yes"},{id:"e3",source:"fraud",target:"cancel",label:"no"},{id:"e4",source:"pick",target:"pack"},{id:"e5",source:"pack",target:"label"},{id:"e6",source:"label",target:"collect"},{id:"e7",source:"collect",target:"deliver"}]}),sk({id:"scattered-members",title:"Incident handling across on-call and support",groups:[{id:"support",label:"Customer support desk and escalation team"},{id:"oncall",label:"On-call"},{id:"comms",label:"Comms"}],nodes:[{id:"report",label:"Customer reports issue",kind:"start",group:"support"},{id:"triage",label:"Triage the report",kind:"process",group:"support"},{id:"outage",label:"Outage?",kind:"decision"},{id:"page",label:"Page on-call",kind:"process",group:"oncall"},{id:"mitigate",label:"Mitigate impact",kind:"process",group:"oncall"},{id:"fixed",label:"Fixed?",kind:"decision",group:"oncall"},{id:"status",label:"Post status update",kind:"process",group:"comms"},{id:"reply",label:"Reply to customer",kind:"process",group:"support"},{id:"closed",label:"Ticket closed",kind:"end",group:"support"}],edges:[{id:"e1",source:"report",target:"triage"},{id:"e2",source:"triage",target:"outage"},{id:"e3",source:"outage",target:"page",label:"yes"},{id:"e4",source:"outage",target:"reply",label:"no"},{id:"e5",source:"page",target:"mitigate"},{id:"e6",source:"mitigate",target:"fixed"},{id:"e7",source:"fixed",target:"status",label:"yes"},{id:"e8",source:"fixed",target:"mitigate",label:"not yet"},{id:"e9",source:"status",target:"reply"},{id:"e10",source:"reply",target:"closed"}]}),sk({id:"many-groups",title:"Release train across teams",groups:[{id:"product",label:"Product"},{id:"web",label:"Web team"},{id:"mobile",label:"Mobile team"},{id:"qa",label:"QA"},{id:"ops",label:"Ops"},{id:"marketing",label:"Marketing"}],nodes:[{id:"plan",label:"Plan the release",kind:"start",group:"product"},{id:"web-build",label:"Build web app",kind:"process",group:"web"},{id:"mobile-build",label:"Build mobile app",kind:"process",group:"mobile"},{id:"store",label:"Submit to app stores",kind:"process",group:"mobile"},{id:"test",label:"Regression tests",kind:"process",group:"qa"},{id:"pass",label:"Tests pass?",kind:"decision",group:"qa"},{id:"deploy",label:"Deploy to production",kind:"process",group:"ops"},{id:"announce",label:"Announce the release",kind:"end",group:"marketing"}],edges:[{id:"e1",source:"plan",target:"web-build"},{id:"e2",source:"plan",target:"mobile-build"},{id:"e3",source:"mobile-build",target:"store"},{id:"e4",source:"web-build",target:"test"},{id:"e5",source:"store",target:"test"},{id:"e6",source:"test",target:"pass"},{id:"e7",source:"pass",target:"deploy",label:"yes"},{id:"e8",source:"pass",target:"web-build",label:"no"},{id:"e9",source:"deploy",target:"announce"}]}),sk({id:"single-group",title:"Payment retries inside the billing service",groups:[{id:"billing",label:"Billing service"}],nodes:[{id:"charge",label:"Charge the card",kind:"start",group:"billing"},{id:"ok",label:"Charge succeeded?",kind:"decision",group:"billing"},{id:"wait",label:"Wait and retry",kind:"process",group:"billing"},{id:"receipt",label:"Send receipt",kind:"end",group:"billing"}],edges:[{id:"e1",source:"charge",target:"ok"},{id:"e2",source:"ok",target:"receipt",label:"yes"},{id:"e3",source:"ok",target:"wait",label:"no"},{id:"e4",source:"wait",target:"ok"}]}),sM({id:"incident-escalation",title:"Incident escalation",nodes:[{id:"alert",label:"Monitoring creates an alert",kind:"start"},{id:"ack",label:"Responder acknowledges it",kind:"process"},{id:"severity",label:"Severity",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"triage",label:"Triage queue",kind:"process"},{id:"monitor",label:"Monitoring",kind:"process"},{id:"mitigate",label:"Mitigates impact",kind:"process"},{id:"comms",label:"Sends customer communications",kind:"process"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"resolved",label:"Resolved",kind:"end"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"severity"},{id:"edge-3",source:"severity",target:"bridge",label:"High severity"},{id:"edge-4",source:"severity",target:"triage",label:"Medium severity"},{id:"edge-5",source:"severity",target:"monitor",label:"Low severity"},{id:"edge-6",source:"bridge",target:"mitigate"},{id:"edge-7",source:"mitigate",target:"comms"},{id:"edge-8",source:"comms",target:"resolved"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"resolved",label:"Yes"},{id:"edge-11",source:"fix",target:"bridge",label:"No — escalate"},{id:"edge-12",source:"monitor",target:"resolved"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"incident-escalation-flowchart",title:"Incident escalation flowchart",nodes:[{id:"alert",label:"Monitoring creates an alert",kind:"start"},{id:"ack",label:"Responder acknowledges it",kind:"process"},{id:"severity",label:"Severity",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"triage",label:"Triage queue",kind:"process"},{id:"monitor",label:"Monitoring low severity incidents",kind:"process"},{id:"mitigate",label:"Mitigates impact",kind:"process"},{id:"comms",label:"Sends customer communications",kind:"process"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"escalate",label:"Escalate to the incident bridge",kind:"process"},{id:"resolve",label:"Resolve the incident",kind:"end"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"severity"},{id:"edge-3",source:"severity",target:"bridge",label:"High severity"},{id:"edge-4",source:"severity",target:"triage",label:"Medium severity"},{id:"edge-5",source:"severity",target:"monitor",label:"Low severity"},{id:"edge-6",source:"bridge",target:"mitigate"},{id:"edge-7",source:"mitigate",target:"comms"},{id:"edge-8",source:"comms",target:"resolve"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"resolve",label:"Yes"},{id:"edge-11",source:"fix",target:"escalate",label:"No"},{id:"edge-12",source:"escalate",target:"bridge"},{id:"edge-13",source:"monitor",target:"resolve"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"incident-escalation-flowchart",title:"Incident escalation flowchart",nodes:[{id:"alert",label:"Monitoring creates an alert",kind:"start"},{id:"ack",label:"Responder acknowledges it",kind:"process"},{id:"severity",label:"Severity",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"mitigate",label:"Mitigate impact",kind:"process"},{id:"comms",label:"Send customer communications",kind:"process"},{id:"resolve",label:"Resolve the incident",kind:"end"},{id:"triage",label:"Triage queue",kind:"process"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"monitor",label:"Monitoring low severity incidents",kind:"process"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"severity"},{id:"edge-3",source:"severity",target:"bridge",label:"High severity"},{id:"edge-4",source:"severity",target:"triage",label:"Medium severity"},{id:"edge-5",source:"severity",target:"monitor",label:"Low severity"},{id:"edge-6",source:"bridge",target:"mitigate"},{id:"edge-7",source:"mitigate",target:"comms"},{id:"edge-8",source:"comms",target:"resolve"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"resolve",label:"Yes"},{id:"edge-11",source:"fix",target:"bridge",label:"No — escalate"},{id:"edge-12",source:"monitor",target:"resolve"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"subscription-renewal-dunning",title:"Subscription renewal dunning",nodes:[{id:"due",label:"A renewal is due",kind:"start"},{id:"charge",label:"Charges payment",kind:"process"},{id:"success",label:"Payment succeeds?",kind:"decision"},{id:"renew",label:"Renew the subscription",kind:"end"},{id:"reminder",label:"Send a reminder",kind:"process"},{id:"updated",label:"Payment was updated?",kind:"decision"},{id:"expired",label:"Grace period has expired?",kind:"decision"},{id:"pause",label:"Pause the subscription",kind:"end"},{id:"another",label:"Send another reminder",kind:"process"}],edges:[{id:"edge-1",source:"due",target:"charge"},{id:"edge-2",source:"charge",target:"success"},{id:"edge-3",source:"success",target:"renew",label:"Yes"},{id:"edge-4",source:"success",target:"reminder",label:"No"},{id:"edge-5",source:"reminder",target:"updated"},{id:"edge-6",source:"updated",target:"charge",label:"Yes — retry charge"},{id:"edge-7",source:"updated",target:"expired",label:"No"},{id:"edge-8",source:"expired",target:"pause",label:"Yes"},{id:"edge-9",source:"expired",target:"another",label:"No"},{id:"edge-10",source:"another",target:"updated"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"subscription-renewal-dunning",title:"Subscription renewal dunning",nodes:[{id:"due",label:"A renewal is due",kind:"start"},{id:"charge",label:"Charges payment",kind:"process"},{id:"success",label:"Payment succeeds?",kind:"decision"},{id:"renew",label:"Renew the subscription",kind:"end"},{id:"reminder",label:"Send a reminder",kind:"process"},{id:"updated",label:"Payment was updated?",kind:"decision"},{id:"expired",label:"Grace period has expired?",kind:"decision"},{id:"pause",label:"Pause the subscription",kind:"end"}],edges:[{id:"edge-1",source:"due",target:"charge"},{id:"edge-2",source:"charge",target:"success"},{id:"edge-3",source:"success",target:"renew",label:"Yes"},{id:"edge-4",source:"success",target:"reminder",label:"No"},{id:"edge-5",source:"reminder",target:"updated"},{id:"edge-6",source:"updated",target:"charge",label:"Yes — retry the charge"},{id:"edge-7",source:"updated",target:"expired",label:"No"},{id:"edge-8",source:"expired",target:"pause",label:"Yes"},{id:"edge-9",source:"expired",target:"reminder",label:"No — send another reminder"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"patient-intake-scheduling",title:"Patient Intake Scheduling",nodes:[{id:"request",label:"Patient requests an appointment",kind:"start"},{id:"intake",label:"Clinic collects intake information",kind:"process"},{id:"urgent",label:"Are there urgent symptoms?",kind:"decision"},{id:"triage",label:"Nurse triage",kind:"process"},{id:"same-day",label:"Same-day appointment",kind:"end"},{id:"insurance",label:"Is insurance valid?",kind:"decision"},{id:"routine",label:"Schedule a routine appointment",kind:"end"},{id:"self-pay",label:"Does the patient accept self-pay?",kind:"decision"},{id:"billing",label:"Refer to billing",kind:"end"}],edges:[{id:"edge-1",source:"request",target:"intake"},{id:"edge-2",source:"intake",target:"urgent"},{id:"edge-3",source:"urgent",target:"triage",label:"Yes"},{id:"edge-4",source:"triage",target:"same-day"},{id:"edge-5",source:"urgent",target:"insurance",label:"No"},{id:"edge-6",source:"insurance",target:"routine",label:"Valid"},{id:"edge-7",source:"insurance",target:"self-pay",label:"Invalid"},{id:"edge-8",source:"self-pay",target:"routine",label:"Yes"},{id:"edge-9",source:"self-pay",target:"billing",label:"No"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"procurement-vendor-approval",title:"Procurement vendor approval",nodes:[{id:"need",label:"Business need is identified",kind:"start"},{id:"quotes",label:"Quotes are collected",kind:"process"},{id:"preferred",label:"Is there a preferred vendor?",kind:"decision"},{id:"bid",label:"Run a competitive bid",kind:"process"},{id:"risk",label:"Risk assessment",kind:"process"},{id:"acceptable",label:"Is risk acceptable?",kind:"decision"},{id:"reject",label:"Reject the vendor",kind:"end"},{id:"legal",label:"Legal review",kind:"process"},{id:"approved",label:"Does legal approve?",kind:"decision"},{id:"renegotiate",label:"Renegotiate terms",kind:"process"},{id:"contract",label:"Create the contract",kind:"end"}],edges:[{id:"edge-1",source:"need",target:"quotes"},{id:"edge-2",source:"quotes",target:"preferred"},{id:"edge-3",source:"preferred",target:"risk",label:"Yes"},{id:"edge-4",source:"preferred",target:"bid",label:"No"},{id:"edge-5",source:"bid",target:"risk"},{id:"edge-6",source:"risk",target:"acceptable"},{id:"edge-7",source:"acceptable",target:"reject",label:"No"},{id:"edge-8",source:"acceptable",target:"legal",label:"Yes"},{id:"edge-9",source:"legal",target:"approved"},{id:"edge-10",source:"approved",target:"contract",label:"Yes"},{id:"edge-11",source:"approved",target:"renegotiate",label:"No"},{id:"edge-12",source:"renegotiate",target:"legal"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"procurement-vendor-approval",title:"Procurement Vendor Approval",nodes:[{id:"need",label:"A business need is identified",kind:"start"},{id:"quotes",label:"Quotes are collected",kind:"process"},{id:"preferred",label:"Is there a preferred vendor?",kind:"decision"},{id:"bid",label:"Run a competitive bid",kind:"process"},{id:"risk",label:"Risk assessment",kind:"process"},{id:"acceptable",label:"Is risk acceptable?",kind:"decision"},{id:"reject",label:"Reject the vendor",kind:"end"},{id:"legal",label:"Legal review",kind:"process"},{id:"approve",label:"Does legal approve?",kind:"decision"},{id:"contract",label:"Create the contract",kind:"end"},{id:"renegotiate",label:"Renegotiate terms",kind:"process"}],edges:[{id:"edge-1",source:"need",target:"quotes"},{id:"edge-2",source:"quotes",target:"preferred"},{id:"edge-3",source:"preferred",target:"risk",label:"Yes"},{id:"edge-4",source:"preferred",target:"bid",label:"No"},{id:"edge-5",source:"bid",target:"risk"},{id:"edge-6",source:"risk",target:"acceptable"},{id:"edge-7",source:"acceptable",target:"reject",label:"No"},{id:"edge-8",source:"acceptable",target:"legal",label:"Yes"},{id:"edge-9",source:"legal",target:"approve"},{id:"edge-10",source:"approve",target:"contract",label:"Yes"},{id:"edge-11",source:"approve",target:"renegotiate",label:"No"},{id:"edge-12",source:"renegotiate",target:"legal"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"restaurant-waitlist",title:"Restaurant waitlist",nodes:[{id:"arrives",label:"Party arrives",kind:"start"},{id:"quote",label:"Host quotes a wait time",kind:"process"},{id:"available",label:"Table available?",kind:"decision"},{id:"seat",label:"Seat the party",kind:"end"},{id:"add",label:"Add the party to the waitlist",kind:"process"},{id:"notified",label:"Party notified",kind:"process"},{id:"responds",label:"Party responds?",kind:"decision"},{id:"remove",label:"Remove the party from the list",kind:"end"},{id:"ready",label:"Table ready?",kind:"decision"},{id:"waiting",label:"Keeps waiting",kind:"process"}],edges:[{id:"edge-1",source:"arrives",target:"quote"},{id:"edge-2",source:"quote",target:"available"},{id:"edge-3",source:"available",target:"seat",label:"Available"},{id:"edge-4",source:"available",target:"add",label:"Not available"},{id:"edge-5",source:"add",target:"notified"},{id:"edge-6",source:"notified",target:"responds"},{id:"edge-7",source:"responds",target:"remove",label:"No response"},{id:"edge-8",source:"responds",target:"ready",label:"Responds"},{id:"edge-9",source:"ready",target:"seat",label:"Ready"},{id:"edge-10",source:"ready",target:"waiting",label:"Not ready"},{id:"edge-11",source:"waiting",target:"responds"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"restaurant-waitlist",title:"Restaurant waitlist",nodes:[{id:"arrives",label:"A party arrives",kind:"start"},{id:"quote",label:"Host quotes a wait time",kind:"process"},{id:"available",label:"Is a table available?",kind:"decision"},{id:"seat",label:"Seat the party",kind:"end"},{id:"add",label:"Add the party to the waitlist",kind:"process"},{id:"notify",label:"Notify the party",kind:"process"},{id:"responds",label:"Does the party respond?",kind:"decision"},{id:"remove",label:"Remove the party from the list",kind:"end"},{id:"ready",label:"Is the table ready?",kind:"decision"},{id:"wait",label:"Keep waiting",kind:"process"}],edges:[{id:"edge-1",source:"arrives",target:"quote"},{id:"edge-2",source:"quote",target:"available"},{id:"edge-3",source:"available",target:"seat",label:"Yes"},{id:"edge-4",source:"available",target:"add",label:"No"},{id:"edge-5",source:"add",target:"notify"},{id:"edge-6",source:"notify",target:"responds"},{id:"edge-7",source:"responds",target:"remove",label:"No response"},{id:"edge-8",source:"responds",target:"ready",label:"Responds"},{id:"edge-9",source:"ready",target:"seat",label:"Ready"},{id:"edge-10",source:"ready",target:"wait",label:"Not ready"},{id:"edge-11",source:"wait",target:"responds",label:"Check response again"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"expense-approval-process",title:"Expense Approval Process",nodes:[{id:"submit",label:"Employee submits an expense report",kind:"start",group:"employee"},{id:"review",label:"Manager reviews the report",kind:"process",group:"manager"},{id:"approved",label:"Is it approved?",kind:"decision",group:"manager"},{id:"revise",label:"Employee revises the report",kind:"process",group:"employee"},{id:"resubmit",label:"Employee resubmits it for review",kind:"process",group:"employee"},{id:"verify",label:"Finance verifies the receipts",kind:"process",group:"finance"},{id:"pay",label:"Finance pays the employee",kind:"end",group:"finance"}],edges:[{id:"edge-1",source:"submit",target:"review"},{id:"edge-2",source:"review",target:"approved"},{id:"edge-3",source:"approved",target:"revise",label:"Rejected"},{id:"edge-4",source:"revise",target:"resubmit"},{id:"edge-5",source:"resubmit",target:"review"},{id:"edge-6",source:"approved",target:"verify",label:"Approved"},{id:"edge-7",source:"verify",target:"pay"}],groups:[{id:"employee",label:"Employee"},{id:"manager",label:"Manager"},{id:"finance",label:"Finance"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"content-moderation",title:"Content moderation",nodes:[{id:"report",label:"Report is received",kind:"start"},{id:"scan",label:"Automated scan runs",kind:"process"},{id:"severe",label:"Severe harm detected?",kind:"decision"},{id:"remove",label:"Remove the content",kind:"process"},{id:"escalate",label:"Escalate to safety",kind:"end"},{id:"violation",label:"Policy violation?",kind:"decision"},{id:"restore",label:"Restore content",kind:"end"},{id:"review",label:"Human review",kind:"process"},{id:"action",label:"Action needed?",kind:"decision"},{id:"limit",label:"Limits content",kind:"end"}],edges:[{id:"edge-1",source:"report",target:"scan"},{id:"edge-2",source:"scan",target:"severe"},{id:"edge-3",source:"severe",target:"remove",label:"Yes"},{id:"edge-4",source:"remove",target:"escalate"},{id:"edge-5",source:"severe",target:"violation",label:"No"},{id:"edge-6",source:"violation",target:"restore",label:"No"},{id:"edge-7",source:"violation",target:"review",label:"Yes"},{id:"edge-8",source:"review",target:"action"},{id:"edge-9",source:"action",target:"limit",label:"Yes"},{id:"edge-10",source:"action",target:"restore",label:"No"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sC({id:"media-player",title:"Media player",initial:"stopped",states:[{id:"stopped",label:"Stopped"},{id:"active",label:"Active",initial:"playing"},{id:"playing",label:"Playing",parent:"active"},{id:"paused",label:"Paused",parent:"active"},{id:"ended",kind:"final"}],transitions:[{id:"transition-1-stopped-active",source:"stopped",target:"active",event:"play"},{id:"transition-2-playing-paused",source:"playing",target:"paused",event:"pause"},{id:"transition-3-paused-playing",source:"paused",target:"playing",event:"resume"},{id:"transition-4-playing-playing",source:"playing",target:"playing",event:"seek",action:"jump to position"},{id:"transition-5-active-stopped",source:"active",target:"stopped",event:"stop"},{id:"transition-6-stopped-ended",source:"stopped",target:"ended",event:"eject"}]}),sC({id:"media-player",title:"Media player",initial:"stopped",states:[{id:"stopped",label:"Stopped"},{id:"active",label:"Active",initial:"playing"},{id:"playing",label:"Playing",parent:"active"},{id:"paused",label:"Paused",parent:"active"},{id:"final",kind:"final"}],transitions:[{id:"transition-1-stopped-active",source:"stopped",target:"active",event:"play"},{id:"transition-2-playing-paused",source:"playing",target:"paused",event:"pause"},{id:"transition-3-paused-playing",source:"paused",target:"playing",event:"resume"},{id:"transition-4-playing-playing",source:"playing",target:"playing",event:"seek",action:"jump to position"},{id:"transition-5-active-stopped",source:"active",target:"stopped",event:"stop"},{id:"transition-6-stopped-final",source:"stopped",target:"final",event:"eject"}]}),sC({id:"network-connection",title:"Network connection",initial:"disconnected",states:[{id:"disconnected",label:"Disconnected"},{id:"connecting",label:"Connecting"},{id:"connected",label:"Connected",initial:"idle"},{id:"idle",label:"Idle",parent:"connected"},{id:"streaming",label:"Streaming",parent:"connected"},{id:"retry_choice",kind:"choice"},{id:"failed",label:"Failed"},{id:"end",kind:"final"}],transitions:[{id:"transition-1-disconnected-connecting",source:"disconnected",target:"connecting",event:"Connect"},{id:"transition-2-connecting-connected",source:"connecting",target:"connected",event:"handshake ok"},{id:"transition-3-connecting-retry-choice",source:"connecting",target:"retry_choice",event:"timeout"},{id:"transition-4-retry-choice-connecting",source:"retry_choice",target:"connecting",guard:"retries < 3",action:"increment retries"},{id:"transition-5-retry-choice-failed",source:"retry_choice",target:"failed",guard:"no retries left"},{id:"transition-6-failed-end",source:"failed",target:"end"},{id:"transition-7-idle-streaming",source:"idle",target:"streaming",event:"start stream"},{id:"transition-8-streaming-idle",source:"streaming",target:"idle",event:"stop stream"},{id:"transition-9-connected-disconnected",source:"connected",target:"disconnected",event:"Disconnect"}]}),sC({id:"order-lifecycle",title:"Order lifecycle",initial:"pending",states:[{id:"pending",label:"Pending payment"},{id:"paid",label:"Paid"},{id:"shipped",label:"Shipped"},{id:"delivered",label:"Delivered"},{id:"cancelled",label:"Cancelled"},{id:"refunded",label:"Refunded"},{id:"end",kind:"final"}],transitions:[{id:"transition-1-pending-paid",source:"pending",target:"paid",event:"pay",guard:"card valid",action:"charge card"},{id:"transition-2-pending-cancelled",source:"pending",target:"cancelled",event:"cancel"},{id:"transition-3-paid-shipped",source:"paid",target:"shipped",event:"ship"},{id:"transition-4-paid-cancelled",source:"paid",target:"cancelled",event:"cancel",action:"refund payment"},{id:"transition-5-shipped-delivered",source:"shipped",target:"delivered",event:"deliver"},{id:"transition-6-shipped-paid",source:"shipped",target:"paid",event:"return to sender"},{id:"transition-7-delivered-refunded",source:"delivered",target:"refunded",event:"request return",guard:"within 30 days",action:"issue refund"},{id:"transition-8-delivered-end",source:"delivered",target:"end"},{id:"transition-9-cancelled-end",source:"cancelled",target:"end"},{id:"transition-10-refunded-end",source:"refunded",target:"end"}]}),sC({id:"network-connection",title:"Network Connection",initial:"Disconnected",states:[{id:"Disconnected",label:"Disconnected"},{id:"Connecting",label:"Connecting"},{id:"Connected",label:"Connected",initial:"Idle"},{id:"Idle",label:"Idle",parent:"Connected"},{id:"Streaming",label:"Streaming",parent:"Connected"},{id:"RetryCheck",label:"Retry check",kind:"choice"},{id:"Failed",label:"Failed",kind:"final"}],transitions:[{id:"transition-1-disconnected-connecting",source:"Disconnected",target:"Connecting",event:"Connect"},{id:"transition-2-connecting-connected",source:"Connecting",target:"Connected",event:"handshake ok"},{id:"transition-3-connecting-retrycheck",source:"Connecting",target:"RetryCheck",event:"timeout"},{id:"transition-4-retrycheck-connecting",source:"RetryCheck",target:"Connecting",guard:"retries < 3",action:"increment retries"},{id:"transition-5-retrycheck-failed",source:"RetryCheck",target:"Failed",guard:"no retries left"},{id:"transition-6-idle-streaming",source:"Idle",target:"Streaming",event:"start stream"},{id:"transition-7-streaming-idle",source:"Streaming",target:"Idle",event:"stop stream"},{id:"transition-8-connected-disconnected",source:"Connected",target:"Disconnected",event:"Disconnect"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"state-machine"});let sz=20*Math.PI/180;function s_(e){return 2e3/(Math.max(e.width,e.height,1)+40)}function sL(e){let t=[];for(let a of e){let e=t.at(-1);if(e&&.01>=Math.hypot(a.x-e.x,a.y-e.y))continue;let s=t.at(-2);if(s&&e&&.01>=Math.abs((e.x-s.x)*(a.y-e.y)-(e.y-s.y)*(a.x-e.x))&&(e.x-s.x)*(a.x-e.x)+(e.y-s.y)*(a.y-e.y)>0){t[t.length-1]=a;continue}t.push(a)}return t}function sB(e){let t=[];for(let a=0;a<e.length-1;a+=1){let s=e[a],i=e[a+1],l=.01>=Math.abs(s.y-i.y);!l&&Math.abs(s.x-i.x)>.01||t.push({horizontal:l,at:l?s.y:s.x,min:Math.min(l?s.x:s.y,l?i.x:i.y),max:Math.max(l?s.x:s.y,l?i.x:i.y),first:0===a,last:a===e.length-2})}return t}function sS(e,t){let a=sL(e.points),s=a[0],i=a.at(-1);if(!s||!i)return[];let l=new Map;for(let e=1;e<a.length-2;e+=1){let[o,r,n,c]=[a[e-1],a[e],a[e+1],a[e+2]],d={x:r.x-o.x,y:r.y-o.y},p={x:n.x-r.x,y:n.y-r.y},h={x:c.x-n.x,y:c.y-n.y},g=[d,p,h].every(e=>.01>=Math.abs(e.x)||.01>=Math.abs(e.y)),u=.01>=Math.abs(d.x*h.y-d.y*h.x)&&d.x*h.x+d.y*h.y>0,f=.01>=Math.abs(d.x*p.x+d.y*p.y),m=Math.hypot(p.x,p.y);g&&u&&f&&!(m*t>=150)&&(!l.has("end")&&Math.hypot(i.x-n.x,i.y-n.y)*t<=90&&2*m<=Math.hypot(d.x,d.y)?l.set("end",m):!l.has("start")&&Math.hypot(r.x-s.x,r.y-s.y)*t<=90&&2*m<=Math.hypot(h.x,h.y)&&l.set("start",m))}return[...l].map(([t,a])=>({kind:"endpoint-jog",arrowIds:[e.id],endpoint:t,message:`Arrow "${e.id}" steps ${a.toFixed(1)} units sideways near its ${"end"===t?"arrowhead":"start"}.`}))}function sA(e,t,a,s,i){return t.some(t=>s.some(s=>{if(t.horizontal!==s.horizontal||Math.abs(t.at-s.at)*i>=24)return!1;let l=Math.min(t.max,s.max)-Math.max(t.min,s.min);return!(l*i<30)&&!((t.first&&s.first&&e.sourceId&&e.sourceId===a.sourceId||t.last&&s.last&&e.targetId&&e.targetId===a.targetId)&&l*i<=90)}))}function sP(e){if(!1===e.endArrowhead)return;let t=e.points.filter((e,t,a)=>0===t||Math.hypot(e.x-a[t-1].x,e.y-a[t-1].y)>.01),a=t.at(-1),s=t.at(-2);if(!a||!s)return;let i=Math.hypot(a.x-s.x,a.y-s.y),l=Math.min(25,i/2),o=(a.x-s.x)/i,r=(a.y-s.y)/i,n=e=>({x:a.x-l*(o*Math.cos(e)-r*Math.sin(e)),y:a.y-l*(r*Math.cos(e)+o*Math.sin(e))});return[a,n(sz),n(-sz)]}function sV(e,t,a){let s=a.x-t.x,i=a.y-t.y,l=0===s&&0===i?0:Math.max(0,Math.min(1,((e.x-t.x)*s+(e.y-t.y)*i)/(s*s+i*i)));return Math.hypot(e.x-(t.x+l*s),e.y-(t.y+l*i))}function sH(e,t,a,s){let i=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x);return i(e,t,a)*i(e,t,s)<0&&i(a,s,e)*i(a,s,t)<0}function sq(e,t){let a=e.flatMap((a,s)=>e.slice(s+1).flatMap(e=>{let s,i;return[sA(a,sB(sL(a.points)),e,sB(sL(e.points)),t)?{kind:"near-coincident-corridor",arrowIds:[a.id,e.id],message:`Arrows "${a.id}" and "${e.id}" run side by side closer than 24 px.`}:void 0,(s=sP(a),i=sP(e),s&&i&&(function(e,t){let a=e=>e.map((t,a)=>[t,e[(a+1)%e.length]]),s=1/0;for(let[i,l]of a(e))for(let[e,o]of a(t)){if(sH(i,l,e,o))return 0;s=Math.min(s,sV(i,e,o),sV(l,e,o),sV(e,i,l),sV(o,i,l))}return s}(s,i)-2)*t<8?{kind:"touching-arrowheads",arrowIds:[a.id,e.id],message:`Arrowheads of "${a.id}" and "${e.id}" touch.`}:void 0)].filter(e=>void 0!==e)}));return[...e.flatMap(e=>sS(e,t)),...a.filter(e=>"near-coincident-corridor"===e.kind),...a.filter(e=>"touching-arrowheads"===e.kind)]}function sF(e,t){let a=24/t+2,s=e.map(e=>{let t=sP(e);return{arrow:e,bounds:sI([...e.points,...t??[]]),head:t,headBounds:t?sI(t):void 0,runs:sB(sL(e.points))}});return e=>{let i=sB(sL(e.points)),l=sI(e.points,a),o=e.points.slice(1).map((t,s)=>{let i=e.points[s];return{bounds:sI([i,t],a),from:i,to:t}}),r=s.filter(({arrow:t,bounds:a})=>t.id!==e.id&&sE(l,a)),n=new Set(r.filter(({arrow:a,runs:s})=>sA(e,i,a,s,t)).map(({arrow:e})=>e.id));return{arrowheadsCrossed:new Set(r.filter(({head:e,headBounds:a})=>e&&o.some(({bounds:s,from:i,to:l})=>sE(s,a)&&(function(e,t,a){let s=1/0;for(let[i,l]of a.entries()){let o=a[(i+1)%a.length];if(sH(e,t,l,o))return 0;s=Math.min(s,sV(e,l,o),sV(t,l,o),sV(l,e,t),sV(o,e,t))}return s}(i,l,e)-2)*t<8)).map(({arrow:e})=>e.id)).size,corridors:n.size,jogs:sS(e,t).length}}}function sI(e,t=0){let a=e.map(e=>e.x),s=e.map(e=>e.y);return{maxX:Math.max(...a)+t,maxY:Math.max(...s)+t,minX:Math.min(...a)-t,minY:Math.min(...s)-t}}function sE(e,t){return e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY}let sO=Object.freeze({clearance:4,fontSize:14,height:21}),sU=/[@%MW]/u,sX=/[A-Z0-9mw#$&_~]/u,sT=new Intl.Segmenter(void 0,{granularity:"grapheme"});function sY(e){let{fontSize:t}=sO,a=0;for(let{segment:s}of sT.segment(e))a+=sU.test(s)?1.02*t:sX.test(s)?.86*t:/^[\x20-\x7e]$/u.test(s)?aq(s,t):Math.max(.86*t,aq(s,t));return Math.ceil(a)}function s$(e){let{clearance:t,height:a}=sO,s=sY(e.name??"Frame");return{x:e.x-t,y:e.y-a-t,width:s+2*t,height:a+t-1}}function sG(e,t,a,s){return tL({id:e,title:t,type:"er",entities:a.map(([e,t])=>({id:e,fields:t.map(tS)})),relationships:s.map(([e,t,a,s,i],l)=>({id:`r${l+1}`,from:e,to:t,fromCardinality:a,toCardinality:s,...i?{label:i}:{}}))})}sG("marketplace-schema","Marketplace schema",[["users",["id uuid PK","email text UK","name text","created_at timestamptz"]],["profiles",["user_id uuid PK FK","bio text?","avatar_url text?"]],["addresses",["id uuid PK","user_id uuid FK","line1 text","city text","country char(2)"]],["sellers",["id uuid PK","user_id uuid FK UK","payout_account text","verified_at timestamptz?"]],["stores",["id uuid PK","seller_id uuid FK","name text","slug text UK"]],["categories",["id uuid PK","parent_id uuid FK?","name text","slug text UK"]],["products",["id uuid PK","store_id uuid FK","title text","price numeric(10,2)","status text"]],["product_categories",["product_id uuid PK FK","category_id uuid PK FK"]],["product_images",["id uuid PK","product_id uuid FK","url text","position int"]],["inventory",["product_id uuid PK FK","on_hand int","reserved int","updated_at timestamptz"]],["orders",["id uuid PK","user_id uuid FK","address_id uuid FK","status text","placed_at timestamptz"]],["order_items",["order_id uuid PK FK","product_id uuid PK FK","quantity int","unit_price numeric(10,2)"]],["payments",["id uuid PK","order_id uuid FK","amount numeric(10,2)","provider text","paid_at timestamptz?"]],["refunds",["id uuid PK","payment_id uuid FK","amount numeric(10,2)","reason text?"]],["carriers",["id uuid PK","name text UK","tracking_url text"]],["shipments",["id uuid PK","order_id uuid FK","carrier_id uuid FK","tracking_code text?","shipped_at timestamptz?"]],["reviews",["id uuid PK","product_id uuid FK","user_id uuid FK","rating int","body text?"]],["coupons",["id uuid PK","code text UK","percent_off int","expires_at timestamptz?"]],["order_coupons",["order_id uuid PK FK","coupon_id uuid PK FK"]],["wishlist_items",["user_id uuid PK FK","product_id uuid PK FK","added_at timestamptz"]]],[["users.id","profiles.user_id","one","zero-or-one"],["users.id","addresses.user_id","one","zero-or-many"],["users.id","sellers.user_id","one","zero-or-one"],["sellers.id","stores.seller_id","one","one-or-many","runs"],["categories.id","categories.parent_id","zero-or-one","zero-or-many","contains"],["stores.id","products.store_id","one","zero-or-many","lists"],["products.id","product_categories.product_id","one","one-or-many"],["categories.id","product_categories.category_id","one","zero-or-many"],["products.id","product_images.product_id","one","zero-or-many"],["products.id","inventory.product_id","one","zero-or-one"],["users.id","orders.user_id","one","zero-or-many","places"],["addresses.id","orders.address_id","one","zero-or-many"],["orders.id","order_items.order_id","one","one-or-many"],["products.id","order_items.product_id","one","zero-or-many"],["orders.id","payments.order_id","one","zero-or-many"],["payments.id","refunds.payment_id","one","zero-or-many"],["orders.id","shipments.order_id","one","zero-or-many"],["carriers.id","shipments.carrier_id","one","zero-or-many"],["products.id","reviews.product_id","one","zero-or-many"],["users.id","reviews.user_id","one","zero-or-many","writes"],["orders.id","order_coupons.order_id","one","zero-or-many"],["coupons.id","order_coupons.coupon_id","one","zero-or-many"],["users.id","wishlist_items.user_id","one","zero-or-many"],["products.id","wishlist_items.product_id","one","zero-or-many"]]),sG("threaded-comments","Threaded comments",[["comments",["id int PK","parent_id int FK?","quoted_id int FK?","author_id int FK","body text"]],["authors",["id int PK","mentor_id int FK?","handle text UK"]]],[["comments.id","comments.parent_id","zero-or-one","zero-or-many","replies"],["comments.id","comments.quoted_id","zero-or-one","zero-or-many","quotes"],["authors.id","comments.author_id","one","zero-or-many"],["authors.id","authors.mentor_id","zero-or-one","zero-or-many","mentors"]]),sG("tag-fans","Tags everywhere",[["tags",["id int PK","name text UK"]],["posts",["id int PK","title text"]],["products",["id int PK","sku text UK"]],["users",["id int PK","email text UK"]],["events",["id int PK","starts_at timestamptz"]],["post_tags",["post_id int PK FK","tag_id int PK FK"]],["product_tags",["product_id int PK FK","tag_id int PK FK"]],["user_tags",["user_id int PK FK","tag_id int PK FK"]],["event_tags",["event_id int PK FK","tag_id int PK FK"]]],[["posts.id","post_tags.post_id","one","zero-or-many"],["tags.id","post_tags.tag_id","one","zero-or-many"],["products.id","product_tags.product_id","one","zero-or-many"],["tags.id","product_tags.tag_id","one","zero-or-many"],["users.id","user_tags.user_id","one","zero-or-many"],["tags.id","user_tags.tag_id","one","zero-or-many"],["events.id","event_tags.event_id","one","zero-or-many"],["tags.id","event_tags.tag_id","one","zero-or-many"]]),sG("saas-workspace","SaaS workspace",[["organizations",["id uuid PK","name text"]],["users",["id uuid PK","email text UK","name text"]],["memberships",["organization_id uuid PK FK","user_id uuid PK FK","role text"]],["projects",["id uuid PK","organization_id uuid FK","name text"]],["tasks",["id uuid PK","project_id uuid FK","assignee_id uuid? FK","title text","due_on date?"]],["comments",["id uuid PK","task_id uuid FK","author_id uuid FK","body text"]],["labels",["id uuid PK","organization_id uuid FK","name text"]],["task_labels",["task_id uuid PK FK","label_id uuid PK FK"]],["plans",["id uuid PK","name text UK","monthly_price numeric"]],["subscriptions",["id uuid PK","organization_id uuid FK UK","plan_id uuid FK","renews_on date"]],["invoices",["id uuid PK","subscription_id uuid FK","amount numeric","paid_at timestamptz?"]],["api_keys",["id uuid PK","organization_id uuid FK","created_by uuid FK","token_hash text UK"]]],[["organizations.id","memberships.organization_id","one","one-or-many"],["users.id","memberships.user_id","one","zero-or-many"],["organizations.id","projects.organization_id","one","zero-or-many"],["projects.id","tasks.project_id","one","zero-or-many"],["users.id","tasks.assignee_id","zero-or-one","zero-or-many"],["tasks.id","comments.task_id","one","zero-or-many"],["users.id","comments.author_id","one","zero-or-many"],["organizations.id","labels.organization_id","one","zero-or-many"],["tasks.id","task_labels.task_id","one","zero-or-many"],["labels.id","task_labels.label_id","one","zero-or-many"],["organizations.id","subscriptions.organization_id","one","zero-or-one"],["plans.id","subscriptions.plan_id","one","zero-or-many"],["subscriptions.id","invoices.subscription_id","one","zero-or-many"],["organizations.id","api_keys.organization_id","one","zero-or-many"],["users.id","api_keys.created_by","one","zero-or-many"]]);let sD=e=>t6(ao({type:"class",...e}));function sR(e,t="LR"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}sD({id:"library-model",title:"Library model",classes:[{id:"Library",attributes:["- name: String"],methods:["+ search(q: String): List<Item>"]},{id:"Branch",attributes:["- address: String"]},{id:"Item",kind:"abstract",attributes:["# id: UUID","# title: String"],methods:["+ loanPeriod(): int {abstract}"]},{id:"Book",attributes:["- isbn: String","- pages: int"],methods:["+ loanPeriod(): int"]},{id:"DVD",attributes:["- minutes: int"],methods:["+ loanPeriod(): int"]},{id:"Magazine",attributes:["- issue: int"],methods:["+ loanPeriod(): int"]},{id:"EBook",attributes:["- fileSize: long"]},{id:"Author",attributes:["- name: String"]},{id:"Publisher",attributes:["- name: String"]},{id:"Member",attributes:["- memberId: String","- name: String"],methods:["+ borrow(i: Item): Loan","+ reserve(i: Item): Reservation"]},{id:"StudentMember",attributes:["- school: String"]},{id:"StaffMember",attributes:["- department: String"]},{id:"Loan",attributes:["- due: Date","- returned: Date"],methods:["+ isOverdue(): bool"]},{id:"Reservation",attributes:["- placed: Date"]},{id:"Fine",attributes:["- amount: Money"],methods:["+ pay(): void"]},{id:"Librarian",attributes:["- staffId: String"],methods:["+ checkOut(l: Loan): void"]},{id:"Notifier",kind:"interface",methods:["+ send(m: Member, text: String): void"]},{id:"EmailNotifier",methods:["+ send(m: Member, text: String): void"]},{id:"SmsNotifier",methods:["+ send(m: Member, text: String): void"]},{id:"Catalog",methods:["+ add(i: Item): void","+ find(isbn: String): Book"]}],relationships:[{kind:"composition",from:"Library",to:"Branch",fromMultiplicity:"1",toMultiplicity:"1..*"},{kind:"composition",from:"Library",to:"Catalog",fromMultiplicity:"1",toMultiplicity:"1"},{kind:"aggregation",from:"Catalog",to:"Item",fromMultiplicity:"1",toMultiplicity:"0..*",toRole:"items"},{kind:"inheritance",from:"Book",to:"Item"},{kind:"inheritance",from:"DVD",to:"Item"},{kind:"inheritance",from:"Magazine",to:"Item"},{kind:"inheritance",from:"EBook",to:"Book"},{kind:"association",from:"Book",to:"Author",fromMultiplicity:"*",toMultiplicity:"1..*",toRole:"authors"},{kind:"association",from:"Book",to:"Publisher",fromMultiplicity:"*",toMultiplicity:"1"},{kind:"inheritance",from:"StudentMember",to:"Member"},{kind:"inheritance",from:"StaffMember",to:"Member"},{kind:"association",from:"Member",to:"Loan",fromMultiplicity:"1",toMultiplicity:"0..*",navigable:!0},{kind:"association",from:"Loan",to:"Item",fromMultiplicity:"*",toMultiplicity:"1",navigable:!0},{kind:"association",from:"Member",to:"Reservation",fromMultiplicity:"1",toMultiplicity:"0..*"},{kind:"association",from:"Reservation",to:"Item",fromMultiplicity:"*",toMultiplicity:"1"},{kind:"composition",from:"Loan",to:"Fine",fromMultiplicity:"1",toMultiplicity:"0..1"},{kind:"dependency",from:"Librarian",to:"Loan",label:"checks out"},{kind:"realization",from:"EmailNotifier",to:"Notifier"},{kind:"realization",from:"SmsNotifier",to:"Notifier"},{kind:"dependency",from:"Loan",to:"Notifier"},{kind:"association",from:"Librarian",to:"Branch",fromMultiplicity:"*",toMultiplicity:"1"}].map((e,t)=>({id:`r${t+1}`,...e}))}),sD({id:"vehicles",title:"Vehicles",classes:[{id:"Vehicle",kind:"abstract",attributes:["# wheels: int","# maxSpeed: double"],methods:["+ move(): void {abstract}"]},...["Car","Truck","Bicycle","Motorcycle","Bus","Tram","Scooter","Van"].map(e=>({id:e,methods:["+ move(): void"]})),{id:"Engine",attributes:["- power: int"]},{id:"Electric",kind:"interface",methods:["+ charge(): void"]}],relationships:[...["Car","Truck","Bicycle","Motorcycle","Bus","Tram","Scooter","Van"].map(e=>({id:`${e}-is-vehicle`,kind:"inheritance",from:e,to:"Vehicle"})),{id:"car-engine",kind:"composition",from:"Car",to:"Engine",fromMultiplicity:"1",toMultiplicity:"1"},{id:"tram-electric",kind:"realization",from:"Tram",to:"Electric"},{id:"scooter-electric",kind:"realization",from:"Scooter",to:"Electric"}]}),sD({id:"widgets",title:"Widgets",classes:[{id:"Component",kind:"interface",methods:["+ render(): Node"]},{id:"Widget",kind:"abstract",attributes:["# id: String"]},{id:"Control",kind:"abstract",attributes:["# enabled: bool"]},{id:"ButtonBase",kind:"abstract",methods:["+ click(): void {abstract}"]},{id:"IconButton",attributes:["- icon: Icon"],methods:["+ click(): void"]},{id:"Clickable",kind:"interface",methods:["+ click(): void"]},{id:"Theme",attributes:["- palette: Map<String, Color>"]}],relationships:[{id:"widget-component",kind:"realization",from:"Widget",to:"Component"},{id:"control-widget",kind:"inheritance",from:"Control",to:"Widget"},{id:"button-control",kind:"inheritance",from:"ButtonBase",to:"Control"},{id:"icon-button",kind:"inheritance",from:"IconButton",to:"ButtonBase"},{id:"icon-clickable",kind:"realization",from:"IconButton",to:"Clickable"},{id:"widget-theme",kind:"dependency",from:"Widget",to:"Theme"},{id:"icon-theme",kind:"association",from:"IconButton",to:"Theme",toMultiplicity:"0..1",toRole:"override"}]}),sD({id:"org",title:"Organization",classes:[{id:"Employee",attributes:["- name: String","- title: String"],methods:["+ reports(): List<Employee>"]},{id:"Department",attributes:["- name: String"]}],relationships:[{id:"manages",kind:"association",from:"Employee",to:"Employee",fromMultiplicity:"0..1",toMultiplicity:"0..*",fromRole:"manager",toRole:"reports"},{id:"mentors",kind:"association",from:"Employee",to:"Employee",fromMultiplicity:"0..1",toMultiplicity:"0..*",fromRole:"mentor",toRole:"mentees"},{id:"works-in",kind:"association",from:"Employee",to:"Department",fromMultiplicity:"*",toMultiplicity:"1",label:"works in"}]}),sD({id:"strategy",title:"Strategy",classes:[{id:"Checkout",methods:["+ total(cart: Cart): Money"]},{id:"PricingStrategy",kind:"interface",methods:["+ price(cart: Cart): Money"]},{id:"Cart",attributes:["- items: List<Item>"]},{id:"Regular",methods:["+ price(cart: Cart): Money"]},{id:"Sale",methods:["+ price(cart: Cart): Money"]}],relationships:[{id:"uses",kind:"aggregation",from:"Checkout",to:"PricingStrategy",fromMultiplicity:"1",toMultiplicity:"1",toRole:"strategy"},{id:"prices",kind:"dependency",from:"PricingStrategy",to:"Cart"},{id:"totals",kind:"dependency",from:"Checkout",to:"Cart"},{id:"regular",kind:"realization",from:"Regular",to:"PricingStrategy"},{id:"sale",kind:"realization",from:"Sale",to:"PricingStrategy"}]}),sR({id:"order-fulfilment-lanes",title:"Order fulfilment",lanes:[{id:"customer",label:"Customer"},{id:"sales",label:"Sales"},{id:"warehouse",label:"Warehouse"},{id:"billing",label:"Billing"}],nodes:[{id:"place",label:"Place order",kind:"start",lane:"customer"},{id:"review",label:"Review order",kind:"process",lane:"sales"},{id:"stock",label:"Items in stock?",kind:"decision",lane:"sales"},{id:"backorder",label:"Notify backorder",kind:"end",lane:"sales"},{id:"pick",label:"Pick items",kind:"process",lane:"warehouse"},{id:"pack",label:"Pack the order",kind:"process",lane:"warehouse"},{id:"ship",label:"Ship the order",kind:"process",lane:"warehouse"},{id:"invoice",label:"Send invoice",kind:"process",lane:"billing"},{id:"pay",label:"Pay the invoice",kind:"process",lane:"customer"},{id:"record",label:"Record payment",kind:"end",lane:"billing"}],edges:[{id:"e1",source:"place",target:"review"},{id:"e2",source:"review",target:"stock"},{id:"e3",source:"stock",target:"backorder",label:"no"},{id:"e4",source:"stock",target:"pick",label:"yes"},{id:"e5",source:"pick",target:"pack"},{id:"e6",source:"pack",target:"ship"},{id:"e7",source:"ship",target:"invoice"},{id:"e8",source:"invoice",target:"pay"},{id:"e9",source:"pay",target:"record"}]}),sR({id:"hiring-lanes",title:"Hiring process",lanes:[{id:"candidate",label:"Candidate"},{id:"recruiter",label:"Recruiter"},{id:"manager",label:"Hiring manager"}],nodes:[{id:"apply",label:"Submit application",kind:"start",lane:"candidate"},{id:"screen",label:"Screen the résumé",kind:"process",lane:"recruiter"},{id:"qualified",label:"Qualified?",kind:"decision",lane:"recruiter"},{id:"decline",label:"Receive rejection",kind:"end",lane:"candidate"},{id:"schedule",label:"Schedule interview",kind:"process",lane:"recruiter"},{id:"interview",label:"Attend interview",kind:"process",lane:"candidate"},{id:"assess",label:"Assess the candidate",kind:"process",lane:"manager"},{id:"hire",label:"Hire?",kind:"decision",lane:"manager"},{id:"offer",label:"Send offer",kind:"process",lane:"recruiter"},{id:"accept",label:"Accept offer",kind:"end",lane:"candidate"}],edges:[{id:"e1",source:"apply",target:"screen"},{id:"e2",source:"screen",target:"qualified"},{id:"e3",source:"qualified",target:"decline",label:"no"},{id:"e4",source:"qualified",target:"schedule",label:"yes"},{id:"e5",source:"schedule",target:"interview"},{id:"e6",source:"interview",target:"assess"},{id:"e7",source:"assess",target:"hire"},{id:"e8",source:"hire",target:"offer",label:"yes"},{id:"e9",source:"hire",target:"schedule",label:"another round"},{id:"e10",source:"offer",target:"accept"}]},"TB"),sR({id:"incident-response-lanes",title:"Incident response",lanes:[{id:"oncall",label:"On-call"},{id:"sre",label:"SRE"},{id:"comms",label:"Comms"}],nodes:[{id:"alert",label:"Alert fires",kind:"start",lane:"oncall"},{id:"triage",label:"Triage the alert",kind:"process",lane:"oncall"},{id:"page",label:"Page the SRE",kind:"process",lane:"oncall"},{id:"status",label:"Post status update",kind:"process",lane:"comms"},{id:"investigate",label:"Investigate",kind:"process",lane:"sre"},{id:"mitigate",label:"Apply mitigation",kind:"process",lane:"sre"},{id:"resolved",label:"Resolved?",kind:"decision",lane:"oncall"},{id:"close",label:"Publish resolution",kind:"end",lane:"comms"}],edges:[{id:"e1",source:"alert",target:"triage"},{id:"e2",source:"triage",target:"page"},{id:"e3",source:"page",target:"investigate"},{id:"e4",source:"investigate",target:"mitigate"},{id:"e5",source:"mitigate",target:"status"},{id:"e6",source:"status",target:"resolved"},{id:"e7",source:"resolved",target:"investigate",label:"no"},{id:"e8",source:"resolved",target:"close",label:"yes"}]}),sR({id:"skip-lanes",title:"Purchase request",lanes:[{id:"requester",label:"Requester"},{id:"procurement",label:"Procurement"},{id:"finance",label:"Finance"},{id:"vendor",label:"Vendor"}],nodes:[{id:"request",label:"Raise purchase request",kind:"start",lane:"requester"},{id:"budget",label:"Within budget?",kind:"decision",lane:"finance"},{id:"quotes",label:"Collect quotes",kind:"process",lane:"procurement"},{id:"compare",label:"Compare vendors",kind:"process",lane:"procurement"},{id:"terms",label:"Check payment terms",kind:"process",lane:"finance"},{id:"order",label:"Place purchase order",kind:"process",lane:"procurement"},{id:"deliver",label:"Deliver goods",kind:"process",lane:"vendor"},{id:"receive",label:"Receive goods",kind:"end",lane:"requester"},{id:"denied",label:"Request denied",kind:"end",lane:"requester"}],edges:[{id:"e1",source:"request",target:"budget"},{id:"e2",source:"budget",target:"quotes",label:"yes"},{id:"e3",source:"budget",target:"denied",label:"no"},{id:"e4",source:"quotes",target:"compare"},{id:"e5",source:"quotes",target:"terms"},{id:"e6",source:"compare",target:"order"},{id:"e7",source:"terms",target:"order"},{id:"e8",source:"order",target:"deliver"},{id:"e9",source:"deliver",target:"receive"}]}),sR({id:"single-lane",title:"Ticket handling",lanes:[{id:"support",label:"Support desk"}],nodes:[{id:"open",label:"Ticket opened",kind:"start",lane:"support"},{id:"answer",label:"Answer the customer",kind:"process",lane:"support"},{id:"solved",label:"Solved?",kind:"decision",lane:"support"},{id:"escalate",label:"Escalate",kind:"process",lane:"support"},{id:"close",label:"Close the ticket",kind:"end",lane:"support"}],edges:[{id:"e1",source:"open",target:"answer"},{id:"e2",source:"answer",target:"solved"},{id:"e3",source:"solved",target:"close",label:"yes"},{id:"e4",source:"solved",target:"escalate",label:"no"},{id:"e5",source:"escalate",target:"answer"}]},"TB");let sZ=["Customer","Support","Billing","Engineering","QA","Release"],sj=["Report the problem","Triage the ticket","Check the account","Reproduce the bug","Write a fix","Review the change","Run regression tests","Approve the release","Ship the fix","Confirm with customer"],sN=Array.from({length:30}).reduce((e,t,a)=>{let s=e.at(-1)??0,i=[0,1,1,0,2,-1,1,0,-1,-2][a%10],l=s+i;return[...e,l<0||l>5?s-i:l]},[]);U({id:"six-lanes-thirty-steps",title:"Thirty steps across six lanes",type:"flowchart",lanes:sZ.map((e,t)=>({id:`l${t}`,label:e})),nodes:Array.from({length:30},(e,t)=>({id:`s${t}`,label:`${sj[t%sj.length]} ${t}`,kind:0===t?"start":29===t?"end":t%7==3?"decision":"process",lane:`l${sN[t]}`})),edges:[...Array.from({length:29},(e,t)=>({id:`e${t}`,source:`s${t}`,target:`s${t+1}`,...t%7==3?{label:"yes"}:{}})),...Array.from({length:30},(e,t)=>t).filter(e=>e%7==3&&e<28).map(e=>({id:`b${e}`,source:`s${e}`,target:`s${e%2==0?e+2:e-2}`,label:"no"}))],layout:{direction:"LR",edgeRouting:"orthogonal"}}),U({id:"cross-lane-loops",title:"Loops across lanes",type:"flowchart",lanes:sZ.slice(0,4).map((e,t)=>({id:`l${t}`,label:e})),nodes:Array.from({length:14},(e,t)=>({id:`n${t}`,label:`${sj[t%sj.length]} ${t}`,kind:0===t?"start":13===t?"end":t%3==2?"decision":"process",lane:`l${3*t%4}`})),edges:[...Array.from({length:13},(e,t)=>({id:`e${t}`,source:`n${t}`,target:`n${t+1}`,...t%3==2?{label:"yes"}:{}})),...[2,5,8,11].map(e=>({id:`loop${e}`,source:`n${e}`,target:`n${Math.max(1,e-2-e%2)}`,label:"retry"}))],layout:{direction:"LR",edgeRouting:"orthogonal"}});let sW=["Ada","Grace","Alan","Barbara","Edsger","Frances","Donald","Hedy","John","Katherine","Leslie","Mary","Niklaus","Radia","Tim","Shafi","Vint","Lynn","Ken","Sophie"],sJ=["Lovelace","Hopper","Turing","Liskov","Dijkstra","Allen","Knuth","Lamarr","Backus","Johnson","Lamport","Keller","Wirth","Perlman","Berners-Lee","Goldwasser","Cerf","Conway","Thompson","Wilson"],sK=["Engineering","Product","Sales","Marketing","Operations","Finance"],sQ=["Chief Executive Officer","Vice President","Director","Engineering Manager","Team Lead","Senior Engineer","Engineer"];function s1(e){return`${sW[e%sW.length]} ${sJ[(7*e+Math.floor(e/sW.length))%sJ.length]}`}function s0(e,t,a,s={}){let i=[{id:"p0",name:s1(0),title:sQ[0],department:"Executive"}],l=[{id:"p0",department:"Executive"}];for(let[e,t]of a.entries()){let a=[];l.forEach((s,l)=>{let o=t[l%t.length];for(let t=0;t<o;t+=1){let l=i.length,o=0===e?sK[t%sK.length]:s.department,r={id:`p${l}`,department:o};i.push({id:r.id,name:s1(l),title:sQ[Math.min(e+1,sQ.length-1)],department:o,manager:s.id}),a.push(r)}}),l=a}return av(aC({id:e,title:t,type:ar,people:i,...s}))}function s2(e,t="LR"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}s0("eighty-people","Eighty people",[[6],[3,2,4],[3,4,2,3,3,3,4,3,2,3,4,3,2,3,3,3,4,3]]),s0("twenty-reports","Twenty reports",[[1],[20]]),s0("six-levels","Six levels deep",[[2],[2,1],[1,2],[2,1],[1,2]]),s0("department","Department of twenty-five",[[3],[8,6,7]]),s0("wide-top","Twelve vice presidents",[[12],[2,3,1]]),av(aC({id:"three-boards",title:"Three boards",type:ar,forest:!0,people:[{id:"a",name:"North Board",title:"Chair"},{id:"a1",name:"Ada Lovelace",title:"Member",manager:"a"},{id:"a2",name:"Alan Turing",title:"Member",manager:"a"},{id:"b",name:"South Board",title:"Chair"},{id:"b1",name:"Grace Hopper",title:"Member",manager:"b"},{id:"c",name:"West Board",title:"Chair"}]})),s0("regions","Departments as regions",[[4],[3,2,1,4],[0,2,1]],{groupByDepartment:!0}),s2({id:"aws-three-tier",title:"AWS three-tier app",groups:[{id:"region",label:"us-east-1",kind:"region"},{id:"vpc",label:"VPC 10.0.0.0/16",kind:"vpc",parent:"region"},{id:"public",label:"Public subnet",kind:"subnet",parent:"vpc"},{id:"private",label:"Private subnet",kind:"subnet",parent:"vpc"},{id:"data",label:"Database subnet",kind:"subnet",parent:"vpc"}],nodes:[{id:"users",label:"Users",kind:"start"},{id:"alb",label:"Application Load Balancer",kind:"process",group:"public"},{id:"web",label:"ECS web service",kind:"process",group:"private"},{id:"api",label:"ECS API service",kind:"process",group:"private"},{id:"rds",label:"RDS PostgreSQL",kind:"end",shape:"database",group:"data"},{id:"s3",label:"S3 assets bucket",kind:"end",shape:"storage",group:"region"}],edges:[{id:"e1",source:"users",target:"alb"},{id:"e2",source:"alb",target:"web"},{id:"e3",source:"alb",target:"api"},{id:"e4",source:"web",target:"rds"},{id:"e5",source:"api",target:"rds"},{id:"e6",source:"api",target:"s3"}]}),s2({id:"kubernetes-cluster",title:"Kubernetes cluster",groups:[{id:"cluster",label:"GKE cluster",kind:"cluster"},{id:"edge",label:"ingress-nginx",kind:"namespace",parent:"cluster"},{id:"frontend",label:"frontend",kind:"namespace",parent:"cluster"},{id:"backend",label:"backend",kind:"namespace",parent:"cluster"}],nodes:[{id:"client",label:"Browser",kind:"start"},{id:"ingress",label:"Ingress controller",kind:"process",group:"edge"},{id:"web-svc",label:"web Service",kind:"process",group:"frontend"},{id:"web-pods",label:"web Pods",kind:"process",group:"frontend"},{id:"api-svc",label:"api Service",kind:"process",group:"backend"},{id:"api-pods",label:"api Pods",kind:"process",group:"backend"},{id:"worker",label:"worker Pods",kind:"process",group:"backend"},{id:"queue",label:"RabbitMQ jobs queue",kind:"process",shape:"queue"},{id:"db",label:"Cloud SQL Postgres",kind:"end",shape:"database"}],edges:[{id:"e1",source:"client",target:"ingress"},{id:"e2",source:"ingress",target:"web-svc"},{id:"e3",source:"web-svc",target:"web-pods"},{id:"e4",source:"web-pods",target:"api-svc"},{id:"e5",source:"api-svc",target:"api-pods"},{id:"e6",source:"api-pods",target:"db"},{id:"e7",source:"api-pods",target:"queue"},{id:"e8",source:"queue",target:"worker"},{id:"e9",source:"worker",target:"db"}]},"TB"),s2({id:"hybrid-cloud",title:"Hybrid on-prem and cloud",groups:[{id:"onprem",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",kind:"zone",parent:"onprem"},{id:"aws",label:"AWS",kind:"cloud"},{id:"region",label:"eu-west-1",kind:"region",parent:"aws"},{id:"vpc",label:"Production VPC",kind:"vpc",parent:"region"},{id:"private",label:"Private subnet",kind:"subnet",parent:"vpc"}],nodes:[{id:"staff",label:"Office staff",kind:"start",group:"corp"},{id:"erp",label:"Legacy ERP",kind:"process",group:"corp"},{id:"oracle",label:"Oracle database",kind:"end",shape:"database",group:"onprem"},{id:"vpn",label:"Site-to-site VPN",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"private"},{id:"orders",label:"Order queue",kind:"process",shape:"queue",group:"region"},{id:"sync",label:"Sync function",kind:"process",group:"region"},{id:"dynamo",label:"Orders table",kind:"end",shape:"database",group:"region"},{id:"invoice",label:"Invoice archive",kind:"end",shape:"document",group:"region"}],edges:[{id:"e1",source:"staff",target:"erp"},{id:"e2",source:"erp",target:"oracle"},{id:"e3",source:"erp",target:"vpn"},{id:"e4",source:"vpn",target:"api"},{id:"e5",source:"api",target:"orders"},{id:"e6",source:"orders",target:"sync"},{id:"e7",source:"sync",target:"dynamo"},{id:"e8",source:"sync",target:"invoice"}]}),s2({id:"kinded-flat",title:"Two availability zones",groups:[{id:"az-a",label:"us-east-1a",kind:"zone"},{id:"az-b",label:"us-east-1b",kind:"zone"}],nodes:[{id:"lb",label:"Network Load Balancer",kind:"start"},{id:"app-a",label:"App server A",kind:"process",group:"az-a"},{id:"db-a",label:"Primary database",kind:"end",shape:"database",group:"az-a"},{id:"app-b",label:"App server B",kind:"process",group:"az-b"},{id:"db-b",label:"Standby replica",kind:"end",shape:"database",group:"az-b"}],edges:[{id:"e1",source:"lb",target:"app-a"},{id:"e2",source:"lb",target:"app-b"},{id:"e3",source:"app-a",target:"db-a"},{id:"e4",source:"app-b",target:"db-b"}]},"TB"),U({id:"depth-four",title:"Two availability zones, four zones deep",type:"flowchart",groups:[{id:"region",label:"us-west-2",kind:"region"},{id:"vpc",label:"VPC",kind:"vpc",parent:"region"},{id:"az-a",label:"us-west-2a",kind:"zone",parent:"vpc"},{id:"az-b",label:"us-west-2b",kind:"zone",parent:"vpc"},{id:"public-a",label:"Public subnet A",kind:"subnet",parent:"az-a"},{id:"private-a",label:"Private subnet A",kind:"subnet",parent:"az-a"},{id:"public-b",label:"Public subnet B",kind:"subnet",parent:"az-b"},{id:"private-b",label:"Private subnet B",kind:"subnet",parent:"az-b"}],nodes:[{id:"users",label:"Users",kind:"start"},{id:"alb",label:"Load balancer",kind:"process",group:"vpc"},{id:"web-a",label:"Web server A",kind:"process",group:"public-a"},{id:"web-b",label:"Web server B",kind:"process",group:"public-b"},{id:"app-a",label:"App server A",kind:"process",group:"private-a"},{id:"app-b",label:"App server B",kind:"process",group:"private-b"},{id:"db-a",label:"Primary database",kind:"end",shape:"database",group:"private-a"},{id:"db-b",label:"Standby database",kind:"end",shape:"database",group:"private-b"},{id:"s3",label:"Backups bucket",kind:"end",shape:"storage",group:"region"}],edges:[{id:"e1",source:"users",target:"alb"},{id:"e2",source:"alb",target:"web-a"},{id:"e3",source:"alb",target:"web-b"},{id:"e4",source:"web-a",target:"app-a"},{id:"e5",source:"web-b",target:"app-b"},{id:"e6",source:"app-a",target:"db-a"},{id:"e7",source:"app-b",target:"db-b"},{id:"e8",source:"db-a",target:"db-b",label:"replicates"},{id:"e9",source:"db-a",target:"s3",label:"backs up"}],layout:{direction:"LR",edgeRouting:"orthogonal"}}),U({id:"thirty-services",title:"Thirty services in eight zones",type:"flowchart",groups:[{id:"aws",label:"AWS",kind:"cloud"},{id:"region",label:"us-east-1",kind:"region",parent:"aws"},{id:"vpc",label:"Production VPC",kind:"vpc",parent:"region"},{id:"public",label:"Public subnet",kind:"subnet",parent:"vpc"},{id:"app",label:"App subnet",kind:"subnet",parent:"vpc"},{id:"data",label:"Data subnet",kind:"subnet",parent:"vpc"},{id:"onprem",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",kind:"zone",parent:"onprem"}],nodes:[["Customers"],["CloudFront CDN","aws"],["WAF rules","region"],["Route 53 DNS","region"],["Load balancer","public"],["NAT gateway","public"],["Bastion host","public"],["Web frontend","app"],["Auth service","app"],["Catalog service","app"],["Cart service","app"],["Checkout service","app"],["Payments service","app"],["Session cache","data","database"],["Catalog database","data","database"],["Orders database","data","database"],["Order events","region","queue"],["Email worker","vpc"],["Invoice renderer","vpc"],["Invoice PDFs","region","document"],["Analytics stream","region","queue"],["Data warehouse","aws","database"],["VPN gateway","vpc"],["Corporate VPN","corp"],["ERP sync","corp"],["ERP system","corp"],["Finance team","corp"],["Mainframe ledger","onprem","database"],["Audit log","onprem","document"],["Partners"]].map(([e,t,a],s)=>({id:`s${s}`,label:e,kind:0===s?"start":"process",...t?{group:t}:{},...a?{shape:a}:{}})),edges:[[0,1],[1,2],[2,4],[3,4],[0,3],[4,7],[5,7],[6,8],[7,8],[7,9],[7,10],[10,11],[11,12],[8,13],[9,14],[11,15],[12,15],[11,16],[16,17],[16,18],[18,19],[16,20],[20,21],[12,22],[22,23],[23,24],[24,25],[25,26],[25,27],[24,28],[29,22]].map(([e,t],a)=>({id:`e${a}`,source:`s${e}`,target:`s${t}`})),layout:{direction:"LR",edgeRouting:"orthogonal"}});let s3=/[,;]\s*(?:id|label|kind|group|source|target|title|direction|nodes|edges)\s*:?\s*$/i;function s5(e){let t=e.trim();for(;;){let e=t.replace(s3,"").trim();if(e===t)return t;t=e}}class s4 extends i.Xsx("ContractSchemaIssue")({code:im("custom"),issueTag:i.xCb(["Filter","InvalidType","InvalidValue","MissingKey","UnexpectedKey","Forbidden","OneOf","AnyOf"]),astKind:i.Qrq(i.QfV),missingKeyCode:i.Qrq(i.uSQ("invalid_type")),message:i.QfV,path:i.O31(i.pHd)},{identifier:void 0}){}class s6 extends i.rNF()("ContractSchemaError",{issues:i.O31(i.O3D(s4))}){}let s7=e=>{var t;if("InvalidType"!==e._tag)return d.vp(e);let a=d.bZ(e)?e.input:void 0;return`Invalid input: expected ${t=e.ast,c.Kg(t)?"string":c.Et(t)?"number":c.Lm(t)?"boolean":c.tF(t)?"array":c.RP(t)?"object":c.c$(t)?JSON.stringify(t.literal):"value"}, received ${null===a?"null":Array.isArray(a)?"array":typeof a}`},s8=d.ID({leafHook:s7});function s9(e){let t,a;return new s6({issues:(t=[],((a=(e,s,i)=>{switch(e._tag){case"Pointer":return a(e.issue,[...s,...e.path],i);case"Encoding":return a(e.issue,s,i);case"Composite":for(let t of e.issues)a(t,s,e.ast);return;case"AnyOf":if(e.issues.length>0){for(let t of e.issues)a(t,s,e.ast);return}break;case"Filter":if(void 0===d.VY(e)&&"InvalidValue"!==e.issue._tag)return a(e.issue,s,i)}let l="ast"in e?e.ast:i,o="MissingKey"===e._tag&&e.annotations?.[ii]==="invalid_type"?"invalid_type":void 0,r=l&&c.mi(l)&&l.types.every(c.c$)?"LiteralUnion":l?._tag,n=l?.annotations?.[is],p="string"==typeof n?[...s,n]:s;for(let a of s8(e).issues)t.push({code:"custom",issueTag:e._tag,...o?{missingKeyCode:o}:{},...r?{astKind:r}:{},message:a.message,path:p})})(e.issue,[]),t.length>1&&t.every(e=>"source"===e.path[0]))?[{code:"custom",issueTag:"AnyOf",astKind:"Union",message:"Invalid input",path:["source"]}]:t)})}let ie=new Set(["x-sketchi-default","x-sketchi-one-of","const","exclusiveMaximum","exclusiveMinimum","maximum","maxLength","maxItems","minimum","minItems","minLength","pattern"]),it="x-sketchi-default",ia="x-sketchi-one-of",is="codeModeDiscriminator",ii="codeModeMissingKeyCode";function il(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function io(e){let t=i._oz(i.AxX(e),{includeAnnotationKey:e=>ie.has(e),onExcessProperty:"error"});return function e(t){if(Array.isArray(t))return t.map(e);if(!il(t))return t;let a=Object.fromEntries(Object.entries(t).map(([t,a])=>[t,e(a)])),s=!0===a[ia];delete a[ia],s&&Array.isArray(a.anyOf)&&(a.oneOf=a.anyOf,delete a.anyOf);let i=a.allOf;if(Array.isArray(i)){let e=[];for(let t of i)il(t)&&Object.hasOwn(t,it)?a.default=t[it]:e.push(t);0===e.length?delete a.allOf:a.allOf=e}return a}({$schema:"https://json-schema.org/draft/2020-12/schema",...t.schema,...0===Object.keys(t.definitions).length?{}:{$defs:t.definitions}})}function ir(){return i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"}))}function ic(e){return i.O31(e).pipe(i.fXn).check(i.tJb(1,{message:"Too small: expected array to have >=1 items"}))}function id(e){return i.Qrq(e)}function ip(e){return e.pipe(i.usV({[ii]:"invalid_type",messageMissingKey:"Invalid input: expected string, received undefined"}))}function ih(e){return e.pipe(i.usV({[ii]:"invalid_type",messageMissingKey:"Invalid input: expected object, received undefined"}))}function ig(e){return e.pipe(i.usV({[ii]:"invalid_type",messageMissingKey:"Invalid input: expected array, received undefined"}))}function iu(e){return i.xCb(e).annotate({message:`Invalid option: expected one of ${e.map(e=>JSON.stringify(e)).join("|")}`})}function im(e){return iw(e,i.QfV)}function iv(e){return iw(e,i.wNn)}function iy(e){return iw(e,i.v8c)}function iw(e,t){let a=i.hzj()([],()=>(t,a,s)=>t===e?o.PyW(e):o.fJG(new d.eE(a,t,s)),{message:`Invalid literal value, expected ${JSON.stringify(e)}`,toCodecJson:()=>i.nfo()(t.annotate({const:e}),{decode:p.pd(()=>e),encode:p.pd(e=>e)})});return i.uSQ(e).pipe(i.GLL(a))}let ix=ir(),ib=ip(ix),ik=i.wYs,iM=i.wNn.check(i.MIs(),i.yJO(0,{message:"Too small: expected number to be >0"})),iC=/^#[0-9a-fA-F]{6}$/u;function iz(e){return i.QfV.annotate(void 0===e?{}:{default:e}).check(i.Pto(iC,{message:`Invalid string: must match pattern /${iC.source}/`}))}let i_=iz(),iL=["excalidraw","scene","png"],iB=["excalidraw","scene"],iS=Object.assign(iu(iL),{options:iL}),iA=Object.assign(iu(iB),{options:iB});class iP extends i.Xsx("ArtifactProvenance")({sourceArtifactId:ib.pipe(i.Wa3)},{identifier:void 0}){}let iV=["missing_field","invalid_type","invalid_enum","invalid_color","duplicate_node_id","duplicate_edge_id","missing_edge_source","missing_edge_target","self_loop","missing_start","multiple_starts","missing_end","start_has_incoming","end_has_outgoing","unreachable_node","nonterminating_node","missing_outgoing_edge","underbranched_decision","unlabeled_decision_branch","duplicate_decision_branch_label","disconnected_graph","flowchart_too_large","duplicate_group_id","unknown_node_group","empty_group","unknown_group_parent","group_cycle","shaped_decision","duplicate_lane_id","unknown_node_lane","empty_lane","lanes_with_groups","mindmap_too_deep","mindmap_too_large","sequence_too_large","invalid_timeline_date","duplicate_event_id","invalid_timeline_order","timeline_too_large","invalid_timeline_span","invalid_timeline_lane","chart_too_large","chart_series_mismatch","duplicate_chart_category","invalid_chart_series","invalid_chart_value","invalid_chart_option","state_machine_too_large","invalid_state","unknown_initial_state","invalid_composite","final_has_outgoing","underbranched_choice","gantt_too_large","invalid_gantt_date","invalid_gantt_span","invalid_gantt_phase","invalid_gantt_progress","gantt_dependency_cycle","gantt_schedule_conflict","er_too_large","invalid_entity","invalid_field","unknown_relationship_field","invalid_relationship","class_too_large","invalid_class","invalid_member","invalid_generalization","org_chart_too_large","invalid_person","invalid_reporting_line","request_too_large","generic_label","label_too_long","quality_below_threshold","render_failed","text_overflow","arrow_binding_invalid","arrow_overlap","export_invalid_scene","storage_read_failed","storage_write_failed","unsupported_artifact_format","patch_source_unavailable","unknown_patch_target","unsupported_patch_operation","patch_preserve_connectivity_failed","patch_output_invalid","duplicate_element_id","duplicate_layer_id","invalid_canvas_binding","invalid_canvas_composition","invalid_canvas_geometry","invalid_polygon","canvas_limit_exceeded","invalid_z_order","unknown_layout_target","unknown_icon","invalid_canvas_icon","icon_dropped"],iH=Object.assign(iu(iV),{options:iV}),iq=iu(["request","diagram","node","edge","group","lane","element","layer","artifact"]),iF=iu(["input","canvas","flowchart","mindmap","quality","render","export","storage"]);class iI extends i.Xsx("CodeModeIssueRef")({kind:iq,id:id(ix),path:id(ix)},{identifier:void 0}){}class iE extends i.Xsx("CodeModeIssue")({code:iH,severity:iu(["error","warning"]),stage:iF,ref:id(iI),message:ib,hint:ib},{identifier:void 0}){}let iO=["start","process","decision","end"],iU=Object.assign(iu(iO),{options:iO}),iX=["setDefaultStyle","setStyle","setShape","translate","replaceText","rerouteEdges","insert","remove","replace","reorder","group","ungroup"];Object.assign(iu(iX),{options:iX});let iT=ip(ir().check(i.NYj(128,{message:"Too big: expected string to have <=128 characters"})));class iY extends i.Xsx("NodeIconSpec")({slug:iT},{identifier:void 0}){}class i$ extends i.Xsx("FlowchartSpecNode")({id:ib,label:ib,kind:iU,description:id(ix),icon:id(iY),group:id(ix),lane:id(ix),shape:id(iu(B))},{identifier:void 0}){}class iG extends i.Xsx("FlowchartSpecLane")({id:ib,label:ib},{identifier:void 0}){}class iD extends i.Xsx("FlowchartSpecGroup")({id:ib,label:ib,parent:id(ix),kind:id(iu(C))},{identifier:void 0}){}class iR extends i.Xsx("FlowchartSpecEdge")({id:id(ix),source:ib,target:ib,label:id(ix)},{identifier:void 0}){}let iZ=iu(["TB","LR"]),ij=iZ.annotate({default:"TB"}).pipe(i.E$i(o.PyW("TB")));class iN extends i.Xsx("FlowchartSpecLayout")({direction:ij},{identifier:void 0}){}let iW=y.accentColor,iJ=iz(iW).pipe(i.E$i(o.PyW(iW))),iK=y.backgroundColor,iQ=iz(iK).pipe(i.E$i(o.PyW(iK)));class i1 extends i.Xsx("FlowchartSpecStyle")({accentColor:iJ,backgroundColor:iQ},{identifier:void 0}){}let i0=[],i2=i.O31(iR).pipe(i.fXn).annotate({default:i0}).pipe(i.E$i(o.PyW(i0))),i3={direction:"TB"},i5=iN.annotate({default:i3}).pipe(i.E$i(o.PyW(i3)),i.usV({[it]:i3})),i4={accentColor:y.accentColor,backgroundColor:y.backgroundColor},i6=i1.annotate({default:i4}).pipe(i.E$i(o.PyW(i4)),i.usV({[it]:i4}));class i7 extends i.Xsx("FlowchartSpec")({id:id(ix),title:ib,nodes:ig(ic(i$)),edges:i2,groups:id(i.O31(iD).pipe(i.fXn)),lanes:id(i.O31(iG).pipe(i.fXn)),layout:i5,style:i6},{identifier:void 0}){}class i8 extends i.Xsx("SequenceParticipantSpec")({id:ib,label:ib,kind:id(ix),icon:id(iY)},{identifier:void 0}){}class i9 extends i.Xsx("SequenceMessageSpec")({id:id(ix),source:ib,target:ib,label:ib,type:id(iu(eq)),style:id(iu(eF))},{identifier:void 0}){}let le=[],lt=i.O31(i9).pipe(i.fXn).annotate({default:le}).pipe(i.E$i(o.PyW(le)));class la extends i.Xsx("SequenceDiagramSpec")({id:id(ix),title:ib,participants:ig(ic(i8)),messages:lt,style:i6},{identifier:void 0}){}class ls extends i.Xsx("TimelineEventSpec")({id:ib,label:ib,date:id(ix),end:id(ix),order:id(ik),kind:id(iu(K)),lane:id(ix),description:id(ix)},{identifier:void 0}){}class li extends i.Xsx("TimelineSpec")({id:id(ix),title:ib,events:ig(ic(ls)),lanes:id(i.O31(ix).pipe(i.fXn)),today:id(ix),style:i6},{identifier:void 0}){}class ll extends i.Xsx("ChartSeriesSpec")({name:id(ix),values:ig(i.O31(ik).pipe(i.fXn))},{identifier:void 0}){}class lo extends i.Xsx("ChartSpec")({id:id(ix),title:ib,kind:iu(T),categories:ig(ic(ix)),series:ig(ic(ll)),unit:id(ix),categoryAxisTitle:id(ix),valueAxisTitle:id(ix),stacked:id(i.v8c),donut:id(i.v8c),orientation:id(iu(Y)),style:i6},{identifier:void 0}){}class lr extends i.Xsx("StateMachineStateSpec")({id:ib,label:id(ix),kind:id(iu(eN)),parent:id(ix),initial:id(ix)},{identifier:void 0}){}class ln extends i.Xsx("StateMachineTransitionSpec")({id:id(ix),source:ib,target:ib,event:id(ix),guard:id(ix),action:id(ix)},{identifier:void 0}){}class lc extends i.Xsx("StateMachineSpecLayout")({direction:iu(eW)},{identifier:void 0}){}let ld=[],lp=i.O31(ln).pipe(i.fXn).annotate({default:ld}).pipe(i.E$i(o.PyW(ld)));class lh extends i.Xsx("StateMachineSpec")({id:id(ix),title:ib,initial:ib,states:ig(ic(lr)),transitions:lp,layout:id(lc),style:i6},{identifier:void 0}){}class lg extends i.Xsx("GanttTaskSpec")({id:ib,label:ib,start:ib,end:id(ix),duration:id(ik),milestone:id(i.v8c),phase:id(ix),dependsOn:id(i.O31(ix).pipe(i.fXn)),progress:id(ik)},{identifier:void 0}){}class lu extends i.Xsx("GanttSpec")({id:id(ix),title:ib,tasks:ig(ic(lg)),phases:id(i.O31(ix).pipe(i.fXn)),today:id(ix),style:i6},{identifier:void 0}){}class lf extends i.Xsx("ErFieldSpec")({name:ib,type:id(ix),pk:id(i.v8c),fk:id(i.v8c),unique:id(i.v8c),nullable:id(i.v8c)},{identifier:void 0}){}let lm=[];class lv extends i.Xsx("ErEntitySpec")({id:ib,name:id(ix),fields:i.O31(i.gPz([ix,lf])).pipe(i.fXn).annotate({default:lm}).pipe(i.E$i(o.PyW(lm)))},{identifier:void 0}){}class ly extends i.Xsx("ErRelationshipSpec")({id:id(ix),from:ib,to:ib,fromCardinality:iu(tf),toCardinality:iu(tf),label:id(ix)},{identifier:void 0}){}let lw=[],lx=i.O31(ly).pipe(i.fXn).annotate({default:lw}).pipe(i.E$i(o.PyW(lw)));class lb extends i.Xsx("ErSpec")({id:id(ix),title:ib,entities:ig(ic(lv)),relationships:lx,style:i6},{identifier:void 0}){}class lk extends i.Xsx("ClassAttributeSpec")({name:ib,type:id(ix),visibility:id(iu(tI)),static:id(i.v8c)},{identifier:void 0}){}class lM extends i.Xsx("ClassParameterSpec")({name:ib,type:id(ix)},{identifier:void 0}){}let lC=[];class lz extends i.Xsx("ClassMethodSpec")({name:ib,params:i.O31(i.gPz([ix,lM])).pipe(i.fXn).annotate({default:lC}).pipe(i.E$i(o.PyW(lC))),returns:id(ix),visibility:id(iu(tI)),static:id(i.v8c),abstract:id(i.v8c)},{identifier:void 0}){}let l_=[],lL=[];class lB extends i.Xsx("ClassNodeSpec")({id:ib,name:id(ix),kind:id(iu(tq)),stereotype:id(ix),attributes:i.O31(i.gPz([ix,lk])).pipe(i.fXn).annotate({default:l_}).pipe(i.E$i(o.PyW(l_))),methods:i.O31(i.gPz([ix,lz])).pipe(i.fXn).annotate({default:lL}).pipe(i.E$i(o.PyW(lL)))},{identifier:void 0}){}class lS extends i.Xsx("ClassRelationshipSpec")({id:id(ix),kind:iu(tU),from:ib,to:ib,fromMultiplicity:id(ix),toMultiplicity:id(ix),fromRole:id(ix),toRole:id(ix),navigable:id(i.v8c),label:id(ix)},{identifier:void 0}){}let lA=[],lP=i.O31(lS).pipe(i.fXn).annotate({default:lA}).pipe(i.E$i(o.PyW(lA)));class lV extends i.Xsx("ClassSpec")({id:id(ix),title:ib,classes:ig(ic(lB)),relationships:lP,style:i6},{identifier:void 0}){}class lH extends i.Xsx("OrgPersonSpec")({id:ib,name:ib,title:id(ix),department:id(ix),manager:id(ix),assistant:id(i.v8c),avatar:id(i.v8c)},{identifier:void 0}){}class lq extends i.Xsx("OrgDottedLineSpec")({id:id(ix),report:ib,manager:ib,label:id(ix)},{identifier:void 0}){}let lF=[],lI=i.O31(lq).pipe(i.fXn).annotate({default:lF}).pipe(i.E$i(o.PyW(lF)));class lE extends i.Xsx("OrgChartSpec")({id:id(ix),title:ib,people:ig(ic(lH)),dottedLines:lI,groupByDepartment:id(i.v8c),forest:id(i.v8c),style:i6},{identifier:void 0}){}let lO=id(ic(iS)),lU=id(i.O31(iA).pipe(i.fXn)),lX=id(i.wNn.check(i.MIs(),i.OWK(0,{message:"Too small: expected number to be >=0"}),i.biW(10,{message:"Too big: expected number to be <=10"})));class lT extends i.Xsx("BuildFlowchartOptions")({artifactFormats:lO,inlineArtifacts:lU,minQualityScore:lX},{identifier:void 0}){}id(lT);class lY extends i.Xsx("BuildFlowchartRequest")({requestId:id(ix),spec:ih(i7),options:id(lT)},{identifier:void 0}){}let l$=i7.mapFields(({id:e,title:t,nodes:a,edges:s,groups:i,lanes:l,layout:o})=>({id:e,title:t,nodes:a,edges:s,groups:i,lanes:l,layout:o})),lG=i._kM({requestId:id(ix),spec:ih(l$)}),lD=i.rcy(lG,{leafHook:s7,parseOptions:{errors:"all"}}),lR=Object.assign(lD,{"~standard":{...lD["~standard"],jsonSchema:{input:()=>io(lG),output:()=>io(lG)}}}),lZ=Object.assign(lY,{omit:e=>lR});class lj extends i.Xsx("BuildSequenceDiagramRequest")({requestId:id(ix),spec:ih(la),options:id(lT)},{identifier:void 0}){}i._kM({requestId:id(ix),spec:ih(la.mapFields(({id:e,title:t,participants:a,messages:s})=>({id:e,title:t,participants:a,messages:s})))});class lN extends i.Xsx("BuildTimelineRequest")({requestId:id(ix),spec:ih(li),options:id(lT)},{identifier:void 0}){}i._kM({requestId:id(ix),spec:ih(li.mapFields(({id:e,title:t,events:a,lanes:s,today:i})=>({id:e,title:t,events:a,lanes:s,today:i})))});class lW extends i.Xsx("BuildChartRequest")({requestId:id(ix),spec:ih(lo),options:id(lT)},{identifier:void 0}){}let lJ=lo.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(lJ)});class lK extends i.Xsx("BuildStateMachineRequest")({requestId:id(ix),spec:ih(lh),options:id(lT)},{identifier:void 0}){}i._kM({requestId:id(ix),spec:ih(lh.mapFields(({id:e,title:t,initial:a,states:s,transitions:i,layout:l})=>({id:e,title:t,initial:a,states:s,transitions:i,layout:l})))});class lQ extends i.Xsx("BuildGanttRequest")({requestId:id(ix),spec:ih(lu),options:id(lT)},{identifier:void 0}){}let l1=lu.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(l1)});class l0 extends i.Xsx("BuildErDiagramRequest")({requestId:id(ix),spec:ih(lb),options:id(lT)},{identifier:void 0}){}let l2=lb.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(l2)});class l3 extends i.Xsx("BuildClassDiagramRequest")({requestId:id(ix),spec:ih(lV),options:id(lT)},{identifier:void 0}){}let l5=lV.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(l5)});class l4 extends i.Xsx("BuildOrgChartRequest")({requestId:id(ix),spec:ih(lE),options:id(lT)},{identifier:void 0}){}let l6=lE.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(l6)});let l7=i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"}),i.HNH(function(e){let t=s5(e);return t.length>0&&!/^(?:""|''|``)$/.test(t)},{message:"Must contain semantic text after normalization."})),l8=ih(i.DYE(()=>l9).annotate({identifier:"__schema0"})),l9=i._kM({label:ip(l7),children:i.Qrq(i.O31(l8).pipe(i.fXn))});class oe extends i.Xsx("MindmapSpecLayout")({direction:iu(["LR","RL"]).annotate({default:"LR"}).pipe(i.E$i(o.PyW("LR")))},{identifier:void 0}){}let ot={direction:"LR"},oa=oe.annotate({default:ot}).pipe(i.E$i(o.PyW(ot)),i.usV({[it]:ot})),os=i._kM({id:id(ix),title:ip(l7),root:l8,layout:oa,style:i6});class oi extends i.Xsx("MindmapSpec")(os,{identifier:void 0}){}let ol=i._kM({requestId:id(ix),spec:ih(os),options:id(lT)});i.Xsx("BuildMindmapRequest")(ol,{identifier:void 0});class oo extends i.Xsx("ScenePoint")({x:ik.pipe(i.Wa3),y:ik.pipe(i.Wa3)},{identifier:void 0}){}let or={frameId:id(ix).pipe(i.Wa3),groupIds:id(i.O31(ix).pipe(i.fXn).annotate({maxItems:aU.maxGroupsPerElement})).pipe(i.Wa3),layerId:id(ix).pipe(i.Wa3),locked:id(i.v8c).pipe(i.Wa3),opacity:id(i.wNn.check(i.MIs(),i.Bt9({minimum:0,maximum:100}))).pipe(i.Wa3),zIndex:id(i.Aiz).pipe(i.Wa3)},on={fillColor:id(i_).pipe(i.Wa3),fillStyle:id(iu(["cross-hatch","hachure","solid"])).pipe(i.Wa3),roughness:id(iu([0,1,2])).pipe(i.Wa3),strokeColor:id(i_).pipe(i.Wa3),strokeStyle:id(iu(["dashed","dotted","solid"])).pipe(i.Wa3),strokeWidth:id(iu([1,2,4])).pipe(i.Wa3)},oc=i.T9y(iu(["arrow","bar","circle","diamond","triangle","crowfoot_one","crowfoot_many","crowfoot_one_or_many","triangle_outline","diamond_outline"])),od=i.O31(oo).pipe(i.fXn).check(i.tJb(2,{message:"Too small: expected array to have >=2 items"}),i.NYj(aU.maxPointsPerElement,{message:`Too big: expected array to have <=${aU.maxPointsPerElement} items`}));class op extends i.Xsx("CanvasNodeIcon")({slug:iT.pipe(i.Wa3),size:i.wNn.check(i.MIs(),i.Bt9({minimum:aX.minSize,maximum:aX.maxSize},{message:`Expected a number between ${aX.minSize} and ${aX.maxSize}`})).pipe(i.Wa3)},{identifier:void 0}){}class oh extends i.Xsx("CanvasIconAsset")({name:i.QfV,svg:i.QfV},{identifier:void 0}){}class og extends i.Xsx("NodeSceneElement")({...or,...on,type:im("node"),id:ib,nodeId:ib,kind:id(ix),icon:id(op).pipe(i.Wa3),rendererRole:id(iu(aJ)),shape:iu(["rectangle","ellipse","diamond","circle","polygon",...aT]).pipe(i.Wa3),points:id(od).pipe(i.Wa3),textColor:id(i_).pipe(i.Wa3),x:ik.pipe(i.Wa3),y:ik.pipe(i.Wa3),width:iM.pipe(i.Wa3),height:iM.pipe(i.Wa3),label:ib.pipe(i.Wa3)},{identifier:void 0}){}class ou extends i.Xsx("TextSceneElement")({...or,type:im("text"),id:ib,containerId:id(ix),textColor:id(i_).pipe(i.Wa3),x:ik.pipe(i.Wa3),y:ik.pipe(i.Wa3),text:ib.pipe(i.Wa3),fontSize:iM,fontFamily:id(iu(["hand","mono","sans"])),lineHeight:id(iM),maxWidth:id(iM),textAlign:id(iu(["center","left","right"])),verticalAlign:id(iu(["bottom","middle","top"]))},{identifier:void 0}){}class of extends i.Xsx("ArrowSceneElement")({...or,...on,type:im("arrow"),id:ib,edgeId:ib,sourceNodeId:ib,targetNodeId:ib.pipe(i.Wa3),startArrowhead:id(oc).pipe(i.Wa3),endArrowhead:id(oc).pipe(i.Wa3),textColor:id(i_).pipe(i.Wa3),points:ig(od).pipe(i.Wa3),curved:id(i.v8c).pipe(i.Wa3),label:id(ix).pipe(i.Wa3)},{identifier:void 0}){}class om extends i.Xsx("CanvasLineBinding")({elementId:ib,focus:id(ik),gap:id(ik)},{identifier:void 0}){}class ov extends i.Xsx("LineSceneElement")({...or,...on,type:im("line"),id:ib,points:ig(od).pipe(i.Wa3),startBinding:id(om).pipe(i.Wa3),endBinding:id(om).pipe(i.Wa3),startArrowhead:id(oc).pipe(i.Wa3),endArrowhead:id(oc).pipe(i.Wa3),label:id(ix).pipe(i.Wa3),textColor:id(i_).pipe(i.Wa3)},{identifier:void 0}){}class oy extends i.Xsx("FrameSceneElement")({...or,...on,type:im("frame"),id:ib,nodeId:id(ix),name:id(ix).pipe(i.Wa3),x:ik.pipe(i.Wa3),y:ik.pipe(i.Wa3),width:iM.pipe(i.Wa3),height:iM.pipe(i.Wa3)},{identifier:void 0}){}class ow extends i.Xsx("CanvasLayer")({id:ib,name:id(ix),locked:id(i.v8c),visible:id(i.v8c)},{identifier:void 0}){}let ox=ig(ic(ix));class ob extends i.Xsx("CanvasFlowLayout")({type:iu(["row","column","stack"]),ids:ox,x:id(ik),y:id(ik),gap:id(ik)},{identifier:void 0}){}class ok extends i.Xsx("CanvasGridLayout")({type:im("grid"),ids:ox,columns:i.Aiz.check(i.OWK(1,{message:"Too small: expected number to be >=1"})),x:id(ik),y:id(ik),columnGap:id(ik),rowGap:id(ik)},{identifier:void 0}){}class oM extends i.Xsx("CanvasAlignLayout")({type:im("align"),ids:ox,axis:iu(["x","y"]),alignment:iu(["center","end","start"])},{identifier:void 0}){}class oC extends i.Xsx("CanvasDistributeLayout")({type:im("distribute"),ids:ox,axis:iu(["x","y"]),gap:id(ik)},{identifier:void 0}){}let oz=i.gPz([og,ou,of,ov,oy],{mode:"oneOf"}).annotate({[ia]:!0}),o_=i.gPz([ob,ok,oM,oC],{mode:"oneOf"}),oL=i.O31(ow).pipe(i.fXn).annotate({default:[],maxItems:aU.maxLayers}).pipe(i.E$i(o.PyW([]))),oB=i.O31(o_).pipe(i.fXn).annotate({default:[],maxItems:aU.maxLayouts}).pipe(i.E$i(o.PyW([]))),oS=i.O31(ix).pipe(i.fXn).annotate({default:[],maxItems:aU.maxZOrderEntries}).pipe(i.E$i(o.PyW([])));class oA extends i.Xsx("CanvasSpec")({kind:im("canvas"),version:iv(1),diagramId:ib,title:ib,width:iM.pipe(i.Wa3),height:iM.pipe(i.Wa3),accentColor:i_.pipe(i.Wa3),backgroundColor:i_.pipe(i.Wa3),elements:ig(i.O31(oz).pipe(i.fXn).annotate({maxItems:aU.maxElements})),icons:id(i.mSG(i.QfV,oh)).pipe(i.Wa3),layers:oL,layouts:oB,zOrder:oS},{identifier:void 0}){}let oP=oA;class oV extends i.Xsx("CreateCanvasRequest")({requestId:id(ix),spec:ih(oA),options:id(lT)},{identifier:void 0}){}let oH=i.mSG(i.QfV,i.$r1).check(i.HNH(e=>"string"==typeof e.id&&e.id.length>0&&"string"==typeof e.type&&e.type.length>0,{message:"Invalid input"}));class oq extends i.Xsx("ExcalidrawScene")({appState:i.mSG(i.QfV,i.$r1),elements:i.O31(oH).pipe(i.fXn)},{identifier:void 0}){}class oF extends oq.extend("ExcalidrawFile")({files:i.mSG(i.QfV,i.$r1),source:ib,type:im("excalidraw"),version:iv(2)},{identifier:void 0}){}let oI=oF;class oE extends i.Xsx("GetArtifactRequest")({artifactId:ib,format:id(iS),inline:id(i.v8c)},{identifier:void 0}){}class oO extends i.Xsx("DiagramSelector")({ids:id(i.O31(ix).pipe(i.fXn)),nodeIds:id(i.O31(ix).pipe(i.fXn)),edgeIds:id(i.O31(ix).pipe(i.fXn)),kinds:id(i.O31(iU).pipe(i.fXn)),labels:id(i.O31(ix).pipe(i.fXn)),scope:id(iu(["all","nodes","edges"]))},{identifier:void 0}){}class oU extends i.Xsx("DiagramStylePatch")({strokeColor:id(i_),fillColor:id(i_),textColor:id(i_),backgroundColor:id(i_)},{identifier:void 0}){}let oX=["rectangle","diamond","ellipse","circle","polygon"],oT=Object.assign(iu(oX),{options:oX});class oY extends i.Xsx("SetDefaultStyleOperation")({op:im("setDefaultStyle"),style:ih(oU)},{identifier:void 0}){}class o$ extends i.Xsx("SetStyleOperation")({op:im("setStyle"),selector:ih(oO),style:ih(oU)},{identifier:void 0}){}class oG extends i.Xsx("SetShapeOperation")({op:im("setShape"),selector:ih(oO),shape:oT},{identifier:void 0}){}class oD extends i.Xsx("TranslateOperation")({op:im("translate"),selector:ih(oO),dx:ik,dy:ik},{identifier:void 0}){}class oR extends i.Xsx("ReplaceTextOperation")({op:im("replaceText"),selector:ih(oO),text:ib},{identifier:void 0}){}class oZ extends i.Xsx("RerouteEdgesOperation")({op:im("rerouteEdges"),selector:id(oO)},{identifier:void 0}){}let oj=ig(ic(ix));class oN extends i.Xsx("InsertElementsOperation")({op:im("insert"),elements:ig(ic(oz)),beforeId:id(ix),afterId:id(ix)},{identifier:void 0}){}class oW extends i.Xsx("RemoveElementsOperation")({op:im("remove"),selector:ih(oO)},{identifier:void 0}){}class oJ extends i.Xsx("ReplaceElementOperation")({op:im("replace"),id:ib,element:ih(oz)},{identifier:void 0}){}class oK extends i.Xsx("ReorderElementsOperation")({op:im("reorder"),ids:oj,beforeId:id(ix),afterId:id(ix)},{identifier:void 0}){}class oQ extends i.Xsx("GroupElementsOperation")({op:im("group"),ids:oj,groupId:ib},{identifier:void 0}){}class o1 extends i.Xsx("UngroupElementsOperation")({op:im("ungroup"),ids:oj,groupId:id(ix)},{identifier:void 0}){}let o0=i.gPz([oY,o$,oG,oD,oR,oZ,oN,oW,oJ,oK,oQ,o1],{mode:"oneOf"}).annotate({[ia]:!0,[is]:"op",message:`Invalid discriminator value. Expected ${iX.map(e=>`'${e}'`).join(" | ")}`});class o2 extends i.Xsx("ArtifactPatchSource")({artifactId:ib,format:id(im("scene"))},{identifier:void 0}){}class o3 extends i.Xsx("InlineScenePatchSource")({scene:ih(oA)},{identifier:void 0}){}let o5=i.gPz([o2,o3]).annotate({message:"Invalid input"});class o4 extends i.Xsx("ApplyDiagramPatchOptions")({artifactFormats:lO,inlineArtifacts:lU,preserveConnectivity:id(i.v8c)},{identifier:void 0}){}id(o4);class o6 extends i.Xsx("ApplyDiagramPatchRequest")({requestId:id(ix),source:o5.annotateKey({messageMissingKey:"Invalid input"}),operations:ig(ic(o0)),options:id(o4),intent:id(ix)},{identifier:void 0}){}class o7 extends i.Xsx("NormalizedMindmapTopic")({id:ix,label:ix,children:i.O31(i.DYE(()=>o7)).pipe(i.fXn)},{identifier:void 0}){}let o8=i._kM({id:ix,title:ix,nodes:i.O31(i$).pipe(i.fXn),edges:i.O31(iR.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),groups:i.Qrq(i.O31(iD).pipe(i.fXn)),lanes:i.Qrq(i.O31(iG).pipe(i.fXn)),layout:i._kM({direction:iZ}),style:i._kM({accentColor:i_,backgroundColor:i_})}),o9=i._kM({id:ix,title:ix,root:o7,layout:i._kM({direction:iu(["LR","RL"])}),style:i._kM({accentColor:i_,backgroundColor:i_})}),re=i._kM({id:ix,title:ix,participants:i.O31(i8).pipe(i.fXn),messages:i.O31(i9.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),style:i._kM({accentColor:i_,backgroundColor:i_})}),rt=i._kM({id:ix,title:ix,events:i.O31(ls).pipe(i.fXn),lanes:id(i.O31(ix).pipe(i.fXn)),today:id(ix),style:i._kM({accentColor:i_,backgroundColor:i_})}),ra=i._kM({id:ix,title:ix,initial:ix,states:i.O31(lr).pipe(i.fXn),transitions:i.O31(ln.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),layout:id(lc),style:i._kM({accentColor:i_,backgroundColor:i_})}),rs=lu.mapFields(e=>({...e,id:ix,title:ix,style:i._kM({accentColor:i_,backgroundColor:i_})})),ri=i._kM({id:ix,title:ix,entities:i.O31(i._kM({id:ix,name:id(ix),fields:i.O31(lf).pipe(i.fXn)})).pipe(i.fXn),relationships:i.O31(ly.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),style:i._kM({accentColor:i_,backgroundColor:i_})}),rl=i._kM({id:ix,title:ix,classes:i.O31(i._kM({id:ix,name:id(ix),kind:id(iu(tq)),stereotype:id(ix),attributes:i.O31(lk).pipe(i.fXn),methods:i.O31(lz.mapFields(e=>({...e,params:i.O31(lM).pipe(i.fXn)}))).pipe(i.fXn)})).pipe(i.fXn),relationships:i.O31(lS.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),style:i._kM({accentColor:i_,backgroundColor:i_})}),ro=i._kM({id:ix,title:ix,people:i.O31(lH).pipe(i.fXn),dottedLines:i.O31(lq.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),groupByDepartment:id(i.v8c),forest:id(i.v8c),style:i._kM({accentColor:i_,backgroundColor:i_})}),rr=lo.mapFields(e=>({...e,id:ix,title:ix,style:i._kM({accentColor:i_,backgroundColor:i_})})),rn=i._kM({code:i.QfV,passed:i.v8c,severity:iu(["error","warning"]),message:i.QfV,refs:i.O31(iI).pipe(i.fXn)}),rc=i._kM({accepted:i.v8c,score:i.wNn,threshold:i.wNn,summary:i._kM({nodeCount:i.wNn,edgeCount:i.wNn}),checks:i.O31(rn).pipe(i.fXn)}),rd=i._kM({format:iS,mimeType:i.QfV,url:id(i.QfV),expiresAt:id(i.QfV),inline:id(i.$r1),sizeBytes:id(i.wNn)}),rp=i._kM({artifactId:i.QfV,diagramId:i.QfV,formats:i.O31(rd).pipe(i.fXn),provenance:id(iP),preview:id(rd)}),rh=i._kM({artifactId:id(i.QfV),diagramId:id(i.QfV),formats:id(i.O31(rd).pipe(i.fXn))});class rg extends i.Xsx("BuildFlowchartAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:o8,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class ru extends i.Xsx("BuildFlowchartRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_flowchart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(o8),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rg,ru]);class rf extends i.Xsx("BuildMindmapAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:o9,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rm extends i.Xsx("BuildMindmapRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_mindmap","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(o9),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rf,rm]);class rv extends i.Xsx("BuildSequenceDiagramAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:re,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class ry extends i.Xsx("BuildSequenceDiagramRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_sequence","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(re),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rv,ry]);class rw extends i.Xsx("BuildTimelineAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:rt,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rx extends i.Xsx("BuildTimelineRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_timeline","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(rt),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rw,rx]);class rb extends i.Xsx("BuildChartAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:rr,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rk extends i.Xsx("BuildChartRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_chart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(rr),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rb,rk]);class rM extends i.Xsx("BuildStateMachineAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:ra,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rC extends i.Xsx("BuildStateMachineRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_state_machine","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(ra),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rM,rC]);class rz extends i.Xsx("BuildGanttAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:rs,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class r_ extends i.Xsx("BuildGanttRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_gantt","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(rs),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rz,r_]);class rL extends i.Xsx("BuildErDiagramAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:ri,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rB extends i.Xsx("BuildErDiagramRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_er_diagram","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(ri),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rL,rB]);class rS extends i.Xsx("BuildClassDiagramAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:rl,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rA extends i.Xsx("BuildClassDiagramRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_class_diagram","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(rl),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rS,rA]);class rP extends i.Xsx("BuildOrgChartAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:ro,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rV extends i.Xsx("BuildOrgChartRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_org_chart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(ro),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rP,rV]);class rH extends i.Xsx("GetArtifactAccepted")({ok:iy(!0),artifactId:i.QfV,diagramId:i.QfV,format:iS,mimeType:i.QfV,url:id(i.QfV),expiresAt:id(i.QfV),inline:id(i.$r1),sizeBytes:id(i.wNn),provenance:id(iP)},{identifier:void 0}){}class rq extends i.Xsx("GetArtifactRejected")({ok:iy(!1),status:iu(["invalid_input","not_found","format_unavailable","expired","storage_failed"]),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rH,rq]);class rF extends i.Xsx("ApplyDiagramPatchAccepted")({ok:iy(!0),status:im("accepted"),patchId:i.QfV,requestId:id(i.QfV),sourceArtifactId:id(i.QfV),artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rI extends i.Xsx("ApplyDiagramPatchRejected")({ok:iy(!1),status:iu(["invalid_input","source_unavailable","target_not_found","unsupported_operation","connectivity_changed","render_failed","export_failed","storage_failed"]),patchId:id(i.QfV),requestId:id(i.QfV),sourceArtifactId:id(i.QfV),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rF,rI]);class rE extends i.Xsx("CreateCanvasAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:oA,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rO extends i.Xsx("CreateCanvasRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_canvas","limit_exceeded","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(oA),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}let rU=i.gPz([rE,rO]),rX=120,rT=1,rY=25;class r$ extends i.Xsx("SearchIconsRequest")({q:ip(ir().check(i.NYj(rX,{message:`Too big: expected string to have <=${rX} characters`}))),limit:id(i.Aiz.check(i.Bt9({minimum:rT,maximum:rY},{message:`Expected an integer between ${rT} and ${rY}`})))},{identifier:void 0}){}class rG extends i.Xsx("SearchIconsMatch")({slug:i.QfV,name:i.QfV,collection:i.QfV,match:iu(["exact","vendor","weak"])},{identifier:void 0}){}class rD extends i.Xsx("SearchIconsAccepted")({ok:iy(!0),status:im("accepted"),query:i.QfV,icons:i.O31(rG).pipe(i.fXn),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rR extends i.Xsx("SearchIconsRejected")({ok:iy(!1),status:iu(["invalid_input"]),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rD,rR]);let rZ=i.xCb(["read","readManifest","write"]);class rj extends i.rNF()("CodeModeArtifactStorageError",{cause:i.kld(),message:i.QfV,operation:rZ}){}class rN extends l.kl()("@sketchi/diagram-agent/CodeModeArtifactStorage"){}let rW={excalidraw:"application/vnd.excalidraw+json",png:"image/png",scene:"application/vnd.sketchi.scene+json"};function rJ(e){return"excalidraw"===e||"scene"===e}function rK(e){return{format:e.format,mimeType:e.mimeType,sizeBytes:e.sizeBytes}}function rQ(e){return new TextEncoder().encode(JSON.stringify(e)).length}let r1=n.QZ(rN)(o.Q56(o.OH5(function(){let e=new Map,t=new Map;return{close:o.OH5(()=>{t.clear(),e.clear()}),storage:{read:o.fn("codeMode.artifacts.memory.read")(function*(e,a){return yield*o.OH5(()=>{let s=t.get(`${e}:${a}`);return s?{...s,data:structuredClone(s.data)}:null})}),readManifest:o.fn("codeMode.artifacts.memory.readManifest")(function*(t){return yield*o.OH5(()=>{let a=e.get(t);return a?structuredClone(a):null})}),write:o.fn("codeMode.artifacts.memory.write")(function*(a){var s;let i=yield*r.Ru;return yield*o.SvU({try:()=>{var s;let l,o=a.formats.map(rK),r=a.provenance?structuredClone(a.provenance):void 0,n={artifactId:a.artifactId,diagramId:a.diagramId,formats:o,...r?{provenance:r}:{},createdAt:new Date(i).toISOString()};for(let s of(e.set(a.artifactId,n),a.formats))t.set(`${a.artifactId}:${s.format}`,{...s,data:structuredClone(s.data)});let c=a.formats.map(e=>{var t;return t=a.inlineFormats,{format:e.format,mimeType:e.mimeType,...rJ(e.format)&&t.includes(e.format)?{inline:e.data}:{},sizeBytes:e.sizeBytes}});return l=(s={artifactId:a.artifactId,diagramId:a.diagramId,formats:c,...a.provenance?{provenance:structuredClone(a.provenance)}:{}}).formats.find(e=>"scene"===e.format),{artifactId:s.artifactId,diagramId:s.diagramId,formats:s.formats,...s.provenance?{provenance:s.provenance}:{},...l?{preview:l}:{}}},catch:(s="write",e=>{var t;return rj.make({cause:e,message:(t="Artifact storage failed.",e instanceof Error?e.message:t),operation:s})})})})}}}),e=>e.close).pipe(o.TjK(e=>e.storage)));function r0(e,t="storage_write_failed"){return{code:t,severity:"error",stage:"storage",message:e,hint:"Retry the request; if it keeps failing, inspect the artifact store binding."}}let r2="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",r3=r2.slice(10),r5=new Map;function r4(e){let t=r5.get(e);if(void 0===t){t=new Uint8Array(256);for(let a=0;a<e.length;a++)t[e.charCodeAt(a)]=a;r5.set(e,t)}return t}function r6(e,t,a,s){let i=a[0];if(null!=t&&e>=t)throw Error(e+" >= "+t);if(e.slice(-1)===i||t&&t.slice(-1)===i)throw Error("trailing zero");if(t){let l=0;for(;(e[l]||i)===t[l];)l++;if(l>0)return t.slice(0,l)+r6(e.slice(l),t.slice(l),a,s)}let l=e?s[e.charCodeAt(0)]:0,o=null!=t?s[t.charCodeAt(0)]:a.length;return o-l>1?a[Math.round(.5*(l+o))]:t&&t.length>1?t.slice(0,1):a[l]+r6(e.slice(1),null,a,s)}function r7(e,t,a){if(e.length!==r8(e[0],t,a))throw Error("invalid integer part of order key: "+e)}function r8(e,t,a){let s=a[e.charCodeAt(0)];if(t[s]===e){let e=t.length/2;return s<e?e-s+1:s-e+2}throw Error("invalid order key head: "+e)}function r9(e,t,a){let s=r8(e[0],t,a);if(s>e.length)throw Error("invalid order key: "+e);return e.slice(0,s)}function ne(e,t,a,s){if(ns(e,t,a))throw Error("invalid order key: "+e);let i=r9(e,a,s);if(e.slice(i.length).slice(-1)===t[0])throw Error("invalid order key: "+e)}function nt(e,t,a,s,i){r7(e,s,i);let l=e[0],o=t[0],r="";for(let s=e.length-1;s>=1;s--){let i=a[e.charCodeAt(s)]+1;if(i!==t.length)return l+e.slice(1,s)+t[i]+r;r=o+r}let n=i[l.charCodeAt(0)];if(n===s.length-1)return null;let c=s[n+1],d=r8(c,s,i)-r8(l,s,i);return c+(d>0?r+o:d<0?r.slice(1):r)}let na=new Map;function ns(e,t,a){let s=na.get(a);void 0===s&&(s=new Map,na.set(a,s));let i=t.charCodeAt(0),l=s.get(i);return void 0===l&&(l=a[0]+t[0].repeat(a.length/2),s.set(i,l)),e===l}function ni(e){for(let t=1;t<e.length;t++)if(e.charCodeAt(t-1)>=e.charCodeAt(t))return!1;return!0}function nl(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}let no=new Set,nr=new Set,nn=new Set(["rectangle","ellipse","diamond"]),nc=v.ink;function nd(e){return"number"==typeof e&&Number.isFinite(e)?e:null}function np(e){if(!Array.isArray(e)||e.length<2)return null;let t=nd(e[0]),a=nd(e[1]);return null===t||null===a?null:[t,a]}function nh(e){let t=nd(e.x),a=nd(e.y),s=nd(e.width),i=nd(e.height);return null===t||null===a||null===s||null===i?null:{x:t,y:a,width:s,height:i}}function ng(e){return 1e-4>Math.abs(e-.5)?.5001:e}function nu(e,t){let a=nh(e);return a&&0!==a.width&&0!==a.height?[ng((t.x-a.x)/a.width),ng((t.y-a.y)/a.height)]:null}function nf(e,t){return{elementId:e?.id??"",focus:0,gap:0,fixedPoint:e?nu(e,t):null}}function nm(e,t){let a=sy(e,"seed");return{id:e,angle:0,fillStyle:t&&"fillStyle"in t?t.fillStyle??"solid":"solid",frameId:t?.frameId??null,groupIds:[...t?.groupIds??[]],index:null,isDeleted:!1,link:null,locked:t?.locked??!1,opacity:t?.opacity??100,roughness:t&&"roughness"in t?t.roughness??1:1,seed:a,strokeStyle:t&&"strokeStyle"in t?t.strokeStyle??"solid":"solid",strokeWidth:t&&"strokeWidth"in t?t.strokeWidth??2:2,updated:1,version:1,versionNonce:a+1}}function nv(e){var t;let a,s=e.wrap?aO(e.text,e.maxWidth,e.fontSize):e.text,i=e.wrap?aI(s,e.fontSize,e.maxWidth):aF(s,e.fontSize,e.maxWidth),l=e.element?.lineHeight??1.35,o=function(e,t,a=1.35){return Math.ceil(e.split("\n").length*t*a)}(s,e.fontSize,l),r=e.element?.verticalAlign;return{...nm(e.id,e.element),...void 0===e.locked?{}:{locked:e.locked},type:"text",x:e.x-i/2,y:e.container&&("bottom"===r||"top"===r)?(t=e.container,a=t.y+a5(t).y,"top"===r?a:a+a4(t).height-o):e.y-o/2,width:i,height:o,backgroundColor:"transparent",boundElements:null,containerId:e.containerId??null,fontFamily:e.element?.fontFamily==="mono"?3:e.element?.fontFamily==="sans"?2:5,fontSize:e.fontSize,lineHeight:l,originalText:e.text,roundness:null,strokeColor:e.textColor??nc,text:s,textAlign:e.element?.textAlign??"center",verticalAlign:e.element?.verticalAlign??"middle",autoResize:!(e.wrap&&!e.containerId)}}function ny(e){return aY(e.shape)?`${e.id}:shape`:`${e.id}:logo`}function nw(e){return e.points[e.points.length-1]??e.points[0]}function nx(e,t,a){if(!e)return null;let s=t.get(e.elementId);return s?{elementId:e.elementId,focus:e.focus??0,gap:e.gap??0,fixedPoint:nu(s,a)}:null}function nb(e){return"node"===e.type}function nk(e){return"text"===e.type}function nM(e){return"arrow"===e.type}function nC(e){return"line"===e.type}function nz(e){return"frame"===e.type}function n_(e,t){let a=e[t];if(!(a&&"object"==typeof a))return null;let s=a.elementId;return"string"==typeof s?s:null}function nL(e){let t=nd(e.x)??0,a=nd(e.y)??0,s=n_(e,"startBinding"),i=n_(e,"endBinding"),l=Array.isArray(e.points)?e.points.map(np).filter(e=>null!==e).map(([e,s])=>({x:t+e,y:a+s})):[];return sp(l).map(t=>({...t,arrowId:e.id,startBindingId:s,endBindingId:i,startCoordinate:"horizontal"===t.orientation?l[t.segmentIndex].x:l[t.segmentIndex].y,endCoordinate:"horizontal"===t.orientation?l[t.segmentIndex+1].x:l[t.segmentIndex+1].y,route:l}))}function nB(e){if(nn.has(e.type)||"frame"===e.type)return!0;let t=e.customData;return"line"===e.type&&null!==t&&"object"==typeof t&&"polygon"===t.sketchiShape}function nS(e,t,a){return e>=t-.01&&e<=a+.01}function nA(e,t){return .01>=Math.abs(e-t)}let nP=[1,2,5];function nV(e){return Math.max(0,-Math.floor(Math.log10(e)+1e-9))}function nH(e,t){let a=Number(e.toFixed(t));return Object.is(a,-0)?0:a}function nq(e,t,a=5,s=8){let i,l=Math.min(e,t),o=Math.max(e,t);l===o&&(0===l?o=1:l>0?l=0:o=0);let r=Math.floor(Math.log10((o-l)/Math.max(1,a)));for(let e=r-1;e<=r+1;e+=1)for(let t of nP){let r=t*10**e,n=nV(r),c=nH(Math.floor(l/r+1e-9)*r,n),d=nH(Math.ceil(o/r-1e-9)*r,n),p=Math.round((d-c)/r);if(p<1||p>s)continue;let h=Math.abs(p-a),g=i?Math.abs(i.intervals-a):1/0;(h<g||h===g&&i&&r>i.step)&&(i={step:r,min:c,max:d,intervals:p})}if(!i)throw Error(`No tick step covers ${l}..${o}.`);let n=nV(i.step),c=Array.from({length:i.intervals+1},(e,t)=>nH(i.min+t*i.step,n));return{min:i.min,max:i.max,step:i.step,ticks:c,decimals:n}}function nF(e,t,a){let s=t?nH(e.min-e.step,e.decimals):e.min,i=a?nH(e.max+e.step,e.decimals):e.max,l=Math.round((i-s)/e.step);return{...e,min:s,max:i,ticks:Array.from({length:l+1},(t,a)=>nH(s+a*e.step,e.decimals))}}function nI(e,t){let a=Math.min(...e),s=Math.max(...e);if(t||a<=0!=s<=0)return{low:Math.min(0,a),high:Math.max(0,s)};let i=Math.max(Math.abs(a),Math.abs(s));return s-a>i/6?{low:Math.min(0,a),high:Math.max(0,s)}:{low:a,high:s}}let nE=/^[$€£¥₹₩₽₺₪₦฿]+/u,nO=/^(?:[%‰°]|(?:[kKMBT]|bn|MM|x)(?!\p{L}))/u;function nU(e){if(!e)return{prefix:"",suffix:""};let t=nE.exec(e)?.[0]??"",a=e.slice(t.length);return t?{prefix:t,suffix:a}:{prefix:"",suffix:nO.test(a)?a:` ${a}`}}function nX(e){let[t="",a="0"]=Math.abs(e).toString().split("e");return Math.max(0,(t.split(".")[1]?.length??0)-Number(a))}let nT=new Map;function nY(e,t){let a=nT.get(t);return a||(a=new Intl.NumberFormat("en-US",{minimumFractionDigits:t,maximumFractionDigits:t}),nT.set(t,a)),a.format(e)}let n$=[{size:1e12,letter:"T"},{size:1e9,letter:"B"},{size:1e6,letter:"M"},{size:1e3,letter:"k"}];function nG(e,t,a){return`${t?"-":""}${a.prefix}${e}${a.suffix}`}function nD(e){return!/^(?:[kKMBT]|bn|MM)/u.test(e.suffix)}function nR(e,t,a=nX(e)){let s=e<0,i=Math.abs(e);if(i>=1e6&&0===a&&nD(t)){let e=n$.find(e=>i>=e.size),a=Number((i/e.size).toPrecision(12));if(Number(a.toPrecision(3))===a)return nG(`${nY(a,nX(a))}${e.letter}`,s,t)}return i>0&&a>6?nG(i.toExponential(),s,t):nG(nY(i,a),s,t)}let nZ=e=>Math.round(100*e)/100;function nj(e,t,a,s=2){let i=new Map;for(let l of e){if("line"!==l.type||!a(l.id)||2!==l.points.length)continue;let[e,o]=l.points,r=.01>Math.abs(e.y-o.y);if(!r&&Math.abs(e.x-o.x)>=.01)continue;let n=r?e.y:e.x,c=r?Math.min(e.x,o.x):Math.min(e.y,o.y),d=r?Math.max(e.x,o.x):Math.max(e.y,o.y),p=t.filter(e=>r?e.top-s<n&&n<e.bottom+s:e.left-s<n&&n<e.right+s).map(e=>r?[e.left-s,e.right+s]:[e.top-s,e.bottom+s]).filter(([e,t])=>t>c&&e<d).toSorted((e,t)=>e[0]-t[0]);if(!p.length)continue;let h=[],g=c;for(let[e,t]of p)e>g&&h.push([g,Math.min(e,d)]),g=Math.max(g,t);g<d&&h.push([g,d]),i.set(l.id,h.filter(([e,t])=>t-e>=1).map(([e,t],a)=>({...l,id:0===a?l.id:`${l.id}:${a}`,points:r?[{x:nZ(e),y:n},{x:nZ(t),y:n}]:[{x:n,y:nZ(e)},{x:n,y:nZ(t)}]})))}return i}let nN="chart-mark",nW=["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#6250d6","#e34948"],nJ=v.ink,nK="#4c4639",nQ="#e6dfd2",n1="#8c826f",n0=3*Math.PI/180,n2=20*Math.PI/180;function n3(e,t){return{text:e,width:Math.ceil(aq(e,t)),height:Math.ceil(e.split("\n").length*t*1.35)}}function n5(e,t,a){return n3(aO(e,Math.max(1,t),a),a)}function n4(e){return Math.round(100*e)/100}function n6(e,t,a=0){return e.left<t.right+a&&t.left<e.right+a&&e.top<t.bottom+a&&t.top<e.bottom+a}function n7(e,t,a,s){let i=e.map((e,t)=>t).toSorted((t,a)=>e[t].preferred-e[a].preferred),l=Array.from({length:e.length},()=>0),o=t;for(let t of i){let a=e[t],i=Math.max(a.preferred-a.size/2,o);l[t]=i,o=i+a.size+s}let r=a;for(let t of i.toReversed()){let a=e[t],i=Math.min(l[t],r-a.size);l[t]=i,r=i-s}return l}function n8(e){let t=t=>{let a=Number.parseInt(e.slice(t,t+2),16)/255;return a<=.03928?a/12.92:((a+.055)/1.055)**2.4};return .2126*t(1)+.7152*t(3)+.0722*t(5)}function n9(e,t){return(Math.max(e,t)+.05)/(Math.min(e,t)+.05)}function ce(e){let t=n8(e);return n9(t,n8(nJ))>=n9(t,1)?nJ:"#ffffff"}function ct(e,t){let a=[...nW.slice(0,e)];return t&&7===e&&(a[6]=nW[7]),a}class ca{surface;elements=[];layers={back:[],middle:[],front:[]};textBoxes=[];constructor(e){this.surface=e}push(e,t){this.elements.push(e),this.layers[t].push(e.id)}zOrder(){return[...this.layers.back,...this.layers.middle,...this.layers.front]}breakRulesUnderText(e,t=2){let a=nj(this.elements,this.textBoxes.map(e=>e.box),e,t);if(!a.size)return;let s=this.elements.flatMap(e=>a.get(e.id)??[e]);for(let e of(this.elements.splice(0,this.elements.length,...s),Object.values(this.layers))){let t=e.flatMap(e=>a.get(e)?.map(e=>e.id)??[e]);e.splice(0,e.length,...t)}}text(e,t,a,s,i,l,o="center",r={}){let n={left:a,top:s,right:a+t.width,bottom:s+t.height};return this.push({type:"text",id:e,x:n4(a+t.width/2),y:n4(s+t.height/2),text:t.text,fontSize:i,maxWidth:t.width,textAlign:o,textColor:l,...r},"front"),this.textBoxes.push({id:e,box:n}),n}line(e,t,a,s,i="back"){this.push({type:"line",id:e,points:[{x:n4(t.x),y:n4(t.y)},{x:n4(a.x),y:n4(a.y)}],roughness:0,strokeWidth:1,...s},i)}mark(e,t,a,s,i,l="middle"){this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:nN,shape:t,x:n4(a.x),y:n4(a.y),width:n4(Math.max(a.width,.5)),height:n4(Math.max(a.height,.5)),label:s,roughness:0,fillStyle:"solid",strokeWidth:1,...i},l)}polygon(e,t,a,s,i="middle"){let l=t.map(e=>e.x),o=t.map(e=>e.y),r=Math.min(...l),n=Math.min(...o),c=t.map(e=>({x:n4(e.x-r),y:n4(e.y-n)}));this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:nN,shape:"polygon",points:[c[0],c[1],c[2],...c.slice(3)],x:n4(r),y:n4(n),width:n4(Math.max(Math.max(...l)-r,.5)),height:n4(Math.max(Math.max(...o)-n,.5)),label:a,roughness:0,fillStyle:"solid",strokeWidth:1,...s},i)}bounds(){let e=1/0,t=1/0,a=-1/0,s=-1/0,i=(i,l,o,r)=>{e=Math.min(e,i),t=Math.min(t,l),a=Math.max(a,o),s=Math.max(s,r)};for(let e of this.elements)if("line"===e.type||"arrow"===e.type)for(let t of e.points)i(t.x,t.y,t.x,t.y);else if("text"===e.type){let t=e.maxWidth??aq(e.text,e.fontSize),a=e.text.split("\n").length*e.fontSize*1.35;i(e.x-t/2,e.y-a/2,e.x+t/2,e.y+a/2)}else i(e.x,e.y,e.x+e.width,e.y+e.height);return{left:e,top:t,right:a,bottom:s}}}function cs(e,t,a){let s=e.bounds(),i=Math.max(s.right-s.left,320),l=s.top-16;if(a.legend&&t.series.length>1){let o=t.series.map((e,t)=>{let s=n5(e.name??`Series ${t+1}`,200,14),i="line"===a.legend?26:12;return{index:t,text:s,keyWidth:i,width:i+6+s.width}}),r=[[]],n=0;for(let e of o){let t=r.at(-1);t.length&&n+18+e.width>i?(r.push([e]),n=e.width):(n+=18*!!t.length+e.width,t.push(e))}let c=r.map(e=>Math.max(...e.map(e=>e.text.height))),d=l-c.reduce((e,t)=>e+t,0)-(r.length-1)*6;l=d-12,r.forEach((t,i)=>{let l=c[i],o=d+l/2,r=s.left;for(let s of t){let t=a.colors[s.index],i={groupIds:[`chart:legend:${s.index}`]};"line"===a.legend?(e.line(`chart:legend:${s.index}:line`,{x:r,y:o},{x:r+s.keyWidth,y:o},{strokeColor:t,strokeWidth:2,...i},"middle"),ci(e,`chart:key:${s.index}`,s.index,r+s.keyWidth/2,o,t,s.text.text,i)):e.mark(`chart:key:${s.index}`,"rectangle",{x:r,y:o-6,width:12,height:12},s.text.text,{fillColor:t,strokeColor:t,...i}),e.text(`chart:legend:${s.index}:label`,s.text,r+s.keyWidth+6,o-s.text.height/2,14,nJ,"left",i),r+=s.width+18}d+=l+6})}let o=1===t.series.length?t.series[0]?.name:void 0,r=e=>e?.toLowerCase().includes(o.toLowerCase())===!0;if(o&&!r(t.title)&&!r(t.valueAxisTitle)){let t=n5(o,Math.max(i,360),14);e.text("chart:subtitle",t,s.left,l-t.height,14,nK,"left"),l-=t.height+6}let n=n5(t.title,Math.max(i,360),20);e.text("chart:title",n,s.left,l-n.height,20,nJ,"left")}function ci(e,t,a,s,i,l,o,r={}){let n={strokeColor:e.surface,strokeWidth:1,fillColor:l,...r},c=a%6;if(3===c||5===c)return e.polygon(t,3===c?[{x:s,y:i-6.5},{x:s+6.5,y:i+5.2},{x:s-6.5,y:i+5.2}]:[{x:s-6.5,y:i-5.2},{x:s+6.5,y:i-5.2},{x:s,y:i+6.5}],o,n,"front"),{left:s-6.5,top:i-6.5,right:s+6.5,bottom:i+6.5};let d=2===c?13:1===c?10:11,p={x:s-d/2,y:i-d/2,width:d,height:d};return e.mark(t,1===c?"rectangle":2===c?"diamond":"ellipse",p,o,4===c?{strokeColor:l,strokeWidth:2,fillColor:e.surface,...r}:n,"front"),{left:p.x,top:p.y,right:p.x+d,bottom:p.y+d}}function cl(e,t){return e.series[t]?.name??e.title}function co(e,t){return{scale:e,labels:e.ticks.map(a=>n3(function(e,t,a){let s=Math.max(Math.abs(t.min),Math.abs(t.max)),i=e<0,l=Math.abs(e);if(0===l)return nG("0",!1,nD(a)?a:{...a,suffix:""});if(s>=1e4&&nD(a)){let e=n$.find(e=>s>=e.size),o=Math.max(0,nV(t.step/e.size));return nG(`${nY(l/e.size,o)}${e.letter}`,i,a)}return nG(nY(l,t.decimals),i,a)}(a,e,t),13))}}function cr(e){let t=!0===e.stacked&&e.series.length>1,a=nU(e.unit),s=Math.max(...e.series.flatMap(e=>e.values.map(nX))),i=e.categories.map((t,s)=>e.series.map(e=>{let t=e.values[s];return{value:t,text:n3(nR(t,a),12)}})),l=e.categories.map((t,i)=>{let l=e.series.map(e=>e.values[i]),o=l.filter(e=>e>0).reduce((e,t)=>e+t,0),r=l.filter(e=>e<0).reduce((e,t)=>e+t,0),n=e=>({value:e,text:n3(nR(Number(e.toFixed(s)),a,s),12)});return{...o>0||0===r?{up:n(o)}:{},...r<0?{down:n(r)}:{}}}),o=t?l.flatMap(e=>[e.up?.value??0,e.down?.value??0]):e.series.flatMap(e=>e.values);return{diagram:e,stacked:t,parts:a,colors:ct(e.series.length,!1),labels:i,totals:l,domain:nI(o,!0)}}function cn(e,t,a,s){let i=t;for(let t of e){let e=Math.max(i,Math.max(...t.split(/\s+/u).map(e=>n3(e,14).width))+10);for(;e<s&&n5(t,e-10,14).text.split("\n").length>a;)e+=4;i=Math.max(i,e)}return i}function cc(e){let t=e.stacked?1:e.diagram.series.length,a=Math.min(96,720/e.diagram.categories.length),s=1===t?Math.max(16,Math.min(44,Math.round(.6*a))):Math.max(10,Math.round(Math.min(64,.75*a)/t)),i=Math.max(...e.stacked?e.totals.flatMap(e=>[e.up?.text.width??0,e.down?.text.width??0]):e.labels.flat().map(e=>e.text.width)),l=e=>t*e+(t-1)*2;if(1===t)return{bars:t,thickness:s,band:Math.max(l(s)+20,a,i+8)};let o=Math.max(s,i+2);return{bars:t,thickness:o,band:Math.max(l(o)+16,a)}}function cd(e,t,a,s,i=5){let l=nq(e.low,e.high,i);for(let e=0;e<2;e+=1){let e=t/(l.max-l.min),i=a(l,e),o=s(l,e);if(!i&&!o)break;l=nF(l,o,i)}return l}function cp(e,t,a){let s=Math.max(1,Math.ceil(Math.abs(a-t)/n0));return Array.from({length:s+1},(i,l)=>{let o=t+(a-t)*l/s;return{x:e*Math.cos(o),y:e*Math.sin(o)}})}function ch(e,t,a){let s=Math.cos(t),i=Math.sin(t),l=Math.max(0,Math.min(a,e.x*s+e.y*i));return Math.hypot(e.x-l*s,e.y-l*i)}let cg=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function cu(e){let t=new Date(864e5*e);return{year:t.getUTCFullYear(),month:t.getUTCMonth()+1,day:t.getUTCDate(),weekday:(t.getUTCDay()+6)%7}}function cf(e,t,a=1){let s=new Date(0);return s.setUTCFullYear(e,t-1,a),Math.round(s.getTime()/864e5)}let cm=[{unit:"day",step:1},{unit:"week",step:1},{unit:"month",step:1},{unit:"quarter",step:1},{unit:"year",step:1},{unit:"year",step:2},{unit:"year",step:5},{unit:"year",step:10},{unit:"year",step:20},{unit:"year",step:25},{unit:"year",step:50}];function cv(e,t,a,s,i,l=1/0){let o=[];for(let r=function(e,t,a){let s=cu(e);switch(t){case"day":return e;case"week":return e-s.weekday;case"month":return cf(s.year,s.month);case"quarter":return cf(s.year,s.month-(s.month-1)%3);case"year":return cf(s.year-(s.year%a+a)%a,1)}}(e,a,s);r<t;){if(o.length>=l)return;let e=function(e,t,a){let s=cu(e);switch(t){case"day":return e+1;case"week":return e+7;case"month":return cf(s.year,s.month+1);case"quarter":return cf(s.year,s.month+3);case"year":return cf(s.year+a,1)}}(r,a,s);o.push({start:r,end:e,label:i(r)}),r=e}return o}function cy(e){return e%2==0?16:12}let cw=[0,6,12,18,24,30],cx=[1,0,-1,0],cb=[0,1,0,-1];function ck(e,t,a){return{x:e.x+cx[t]*a,y:e.y+cb[t]*a}}function cM(e){let t=e.map(e=>Math.round(100*e)/100).toSorted((e,t)=>e-t);return t.filter((e,a)=>0===a||e-t[a-1]>.01)}class cC{costs=new Float64Array(1024);reachedAt=new Float64Array(1024);orders=new Float64Array(1024);states=new Int32Array(1024);length=0;order=0;cost=0;reached=0;get size(){return this.length}push(e,t,a){this.length===this.costs.length&&this.grow();let s=this.order++,i=this.length++;for(;i>0;){let t=i-1>>1;if(!cz(e,s,this.costs[t],this.orders[t]))break;this.move(t,i),i=t}this.place(i,e,t,s,a)}pop(){let e=this.states[0];this.cost=this.costs[0],this.reached=this.reachedAt[0];let t=--this.length;if(t>0){let e=this.costs[t],a=this.reachedAt[t],s=this.orders[t],i=this.states[t],l=0;for(;;){let a=2*l+1;if(a>=t)break;let i=a+1,o=i<t&&cz(this.costs[i],this.orders[i],this.costs[a],this.orders[a])?i:a;if(!cz(this.costs[o],this.orders[o],e,s))break;this.move(o,l),l=o}this.place(l,e,a,s,i)}return e}move(e,t){this.costs[t]=this.costs[e],this.reachedAt[t]=this.reachedAt[e],this.orders[t]=this.orders[e],this.states[t]=this.states[e]}place(e,t,a,s,i){this.costs[e]=t,this.reachedAt[e]=a,this.orders[e]=s,this.states[e]=i}grow(){let e=2*this.costs.length,t=(t,a)=>{let s=a(e);return s.set(t),s};this.costs=t(this.costs,e=>new Float64Array(e)),this.reachedAt=t(this.reachedAt,e=>new Float64Array(e)),this.orders=t(this.orders,e=>new Float64Array(e)),this.states=t(this.states,e=>new Int32Array(e))}}function cz(e,t,a,s){return e<a-1e-9||1e-9>=Math.abs(e-a)&&t<s}function c_(e,t,a,s){let{box:i}=e;if(e.parallel&&i.right-i.left>=i.bottom-i.top!==s)return!1;let l=Math.max(0,e.clearance-.01),o=Math.max(0,(e.sideClearance??e.clearance)-.01);return s?Math.min(a,i.right+o)-Math.max(t,i.left-o)>.01:Math.min(a,i.bottom+l)-Math.max(t,i.top-l)>.01}function cL(e,t,a){return e.filter(({box:e,clearance:s,sideClearance:i})=>{let l=Math.max(0,s-.01),o=Math.max(0,(i??s)-.01);return a?t>e.top-l&&t<e.bottom+l:t>e.left-o&&t<e.right+o})}function cB(e){return .01>Math.abs(e.from.y-e.to.y)}function cS(e,t,a,s=5){let i=.01>Math.abs(e.y-t.y);if(i!==cB(a)||(i?Math.abs(e.y-a.from.y):Math.abs(e.x-a.from.x))>=s)return!1;let[l,o]=i?[Math.min(e.x,t.x),Math.max(e.x,t.x)]:[Math.min(e.y,t.y),Math.max(e.y,t.y)],[r,n]=i?[Math.min(a.from.x,a.to.x),Math.max(a.from.x,a.to.x)]:[Math.min(a.from.y,a.to.y),Math.max(a.from.y,a.to.y)];return Math.min(o,n)-Math.max(l,r)>-s}function cA(e,t,a){if(!a)return!1;let s=.01>Math.abs(e.y-t.y);return s===cB(a)&&(s?.01>Math.abs(e.y-a.from.y):.01>Math.abs(e.x-a.from.x))}let cP={best:new Float64Array(0),previous:new Int32Array(0),stamp:new Int32Array(0),epoch:0,steps:new Float64Array(0),stepStamp:new Int32Array(0),estimates:new Float64Array(0),estimateStamp:new Int32Array(0),gridEpoch:0};function cV(e){let t=function(e){let t;for(let a of e.sources)for(let s of e.targets){if(a.direction!==s.direction)continue;let i=a.direction%2==0?(s.x-a.x)*cx[a.direction]:(s.y-a.y)*cb[a.direction];if(!(a.direction%2==0?.01>Math.abs(a.y-s.y):.01>Math.abs(a.x-s.x))||i<(a.lead??8)+cy(s.direction))continue;let l=e.obstacles.some(e=>!e.own&&function(e,t,a){let s=.01>Math.abs(t.y-a.y);return 0!==cL([e],s?t.y:t.x,s).length&&c_(e,s?Math.min(t.x,a.x):Math.min(t.y,a.y),s?Math.max(t.x,a.x):Math.max(t.y,a.y),s)}(e,a,s))||e.routed.some(t=>!e.trunks?.has(t)&&cS(a,s,t)),o=a.cost+s.cost+i;l||t&&!(o<t.cost)||(t={cost:o,points:[a,s]})}return t?.points}(e);if(t)return t;let a=[...e.sources,...e.targets],s=(e,t)=>({left:Math.min(...a.map(e=>e.x))-e,right:Math.max(...a.map(e=>e.x))+e,top:Math.min(...a.map(e=>e.y))-t,bottom:Math.max(...a.map(e=>e.y))+t}),i={separation:5,lanes:e.lanes,splits:[.5],crossingCost:e.crossingCost??30},{behind:l}=e,o=void 0===l?i:{...i,behind:l},r={...o,separation:2.5,lanes:e.denseLanes,splits:[.25,.5,.75],crossingCost:2},n=s(200,90),c=s(800,360),{reach:d}=e,p=d?{left:Math.min(c.left,d.left),right:Math.max(c.right,d.right),top:Math.min(c.top,e.top),bottom:Math.max(c.bottom,e.bottom)}:c,h=e.budget,g=e.kinkBudget,u=(t,a,s)=>{if(h&&h.remaining<=0)return;let i=function(e,t,a){var s;let{routed:i}=e,{separation:l}=a,o=e.pastTrunk??new Map,r=[...e.obstacles,...o.keys()],n=e.sources.map(e=>ck(e,e.direction,e.lead??8)),c=e.targets.map(e=>ck(e,(e.direction+2)%4,cy(e.direction))),d=[...e.sources,...e.targets,...n,...c],p=8+cw.at(-1)+10,h=r.filter(({box:e})=>e.right>=t.left-p&&e.left<=t.right+p&&e.bottom>=t.top-p&&e.top<=t.bottom+p),g=h.filter(({box:e})=>e.bottom>=t.top&&e.top<=t.bottom).flatMap(({box:e,clearance:t,sideClearance:a})=>[e.left-Math.max(a??t,5),e.right+Math.max(a??t,5)]).filter(e=>e>=t.left&&e<=t.right),u=d.map(e=>e.x),f=Math.max(t.left,Math.min(...u,...g))-8,m=Math.min(t.right,Math.max(...u,...g))+8,v=cM([...u,...g,...cw.flatMap(e=>[f-e,m+e])]),y=cM([...v,...v.slice(1).flatMap((e,t)=>{let s=v[t];return e-s>4*l?a.splits.map(t=>s+(e-s)*t):[]})]),w=cM([...d.map(e=>e.y),...a.lanes.filter(e=>e>=t.top&&e<=t.bottom)]).filter(t=>t>=e.top&&t<=e.bottom),x=new Map(y.map((e,t)=>[e,t])),b=new Map(w.map((e,t)=>[e,t])),k=e=>{let t=x.get(Math.round(100*e.x)/100),a=b.get(Math.round(100*e.y)/100);return void 0===t||void 0===a?void 0:a*y.length+t},M=[],C=e=>M[e]??={x:y[e%y.length],y:w[Math.floor(e/y.length)]},z=p+12,_=i.filter(e=>Math.max(e.from.x,e.to.x)>=t.left-z&&Math.min(e.from.x,e.to.x)<=t.right+z&&Math.max(e.from.y,e.to.y)>=t.top-z&&Math.min(e.from.y,e.to.y)<=t.bottom+z),L=_.filter(cB),B=_.filter(e=>!cB(e)),S=(e.edges??[]).filter(e=>e.right>=t.left&&e.left<=t.right&&e.bottom>=t.top-7&&e.top<=t.bottom+7),A=new Map,P=new Map,V=(t,a)=>{let s=a?A:P,i=s.get(t);if(!i){let[o,r]=a?[L,B]:[B,L],n=e=>Math.abs(a?e.from.y-t:e.from.x-t);i={obstacles:cL(h,t,a),routed:[...o.filter(e=>n(e)<l),...r.filter(e=>a?t>Math.min(e.from.y,e.to.y)&&t<Math.max(e.from.y,e.to.y):t>Math.min(e.from.x,e.to.x)&&t<Math.max(e.from.x,e.to.x))],beside:o.filter(t=>12>n(t)&&!e.kin?.has(t)),edges:a?S.filter(e=>t<=e.top&&e.top-t<7||t>=e.bottom&&t-e.bottom<7):[]},s.set(t,i)}return i},H=(e,t)=>{let a=.01>Math.abs(e.y-t.y);return V(a?e.y:e.x,a)},q=(t,a,s=!1,i=!1,r=H(t,a))=>{let n=.01>Math.abs(t.y-a.y),c=n?Math.min(t.x,a.x):Math.min(t.y,a.y),d=n?Math.max(t.x,a.x):Math.max(t.y,a.y);return!r.obstacles.some(e=>!(s&&e.own)&&!(i&&cA(t,a,o.get(e)))&&c_(e,c,d,n))&&!r.routed.some(s=>!(i&&e.trunks?.has(s))&&cS(t,a,s,l))},{behind:F}=a,I=e.targets.map(e=>e.cost+cy(e.direction)),E=Float64Array.from(c,e=>e.x),O=Float64Array.from(c,e=>e.y),U=(e,t,a)=>{let s=1/0;for(let i=0;i<E.length;i+=1){let l=E[i]-e,o=O[i]-t,r=l*cx[a]+o*cb[a],n=Math.abs(l*cb[a])+Math.abs(o*cx[a])<.01?r>-.01?0:2:r>-.01?1:2,c=Math.abs(l)+Math.abs(o)+24*n+I[i];c<s&&(s=c)}return s},{steps:X,stepStamp:T,estimates:Y,estimateStamp:$,gridEpoch:G}=(s=y.length*w.length*4,cP.stepStamp.length<s&&(cP.steps=new Float64Array(s),cP.stepStamp=new Int32Array(s),cP.estimates=new Float64Array(s),cP.estimateStamp=new Int32Array(s)),cP.gridEpoch>=0x40000000&&(cP.stepStamp.fill(0),cP.estimateStamp.fill(0),cP.gridEpoch=0),cP.gridEpoch+=1,cP),D=new Map,R=new Map;e.targets.forEach((e,t)=>{let a=c[t],s=k(a);if(void 0===s||!q(a,e,!0))return;D.set(s,[...D.get(s)??[],e]);let i=4*s+e.direction;R.set(i,Math.min(R.get(i)??1/0,I[t]))});let Z=(e,t,a,s)=>{let i=4*e+a;if(!s&&T[i]===G)return X[i];let l=j(C(e),C(t),a,s)??1/0;return s||(T[i]=G,X[i]=l),l},j=(t,s,i,l)=>{let o=V(i%2==0?t.y:t.x,i%2==0);if(!q(t,s,!1,l,o))return;let r=2===i?a.crossingCost*(e.backCrossingFactor??8):a.crossingCost;return Math.abs(s.x-t.x)+Math.abs(s.y-t.y)+(void 0===F?0:4*Math.max(0,Math.min(F,Math.max(t.x,s.x))-Math.min(t.x,s.x)))+2*((e,t,a=H(e,t))=>{if(0===a.edges.length)return 0;let s=Math.min(e.x,t.x),i=Math.max(e.x,t.x),l=0;for(let e of a.edges)l+=Math.max(0,Math.min(i,e.right)-Math.max(s,e.left));return l})(t,s,o)+(r?((t,a,s=H(t,a))=>{let i=0;for(let l of s.routed)(function(e,t,a){let s=.01>Math.abs(e.y-t.y);if(s===cB(a))return!1;let[i,l,o,r]=s?[e,t,a.from,a.to]:[a.from,a.to,e,t],n=o.x,c=i.y;return n>Math.min(i.x,l.x)+.01&&n<Math.max(i.x,l.x)-.01&&c>Math.min(o.y,r.y)+.01&&c<Math.max(o.y,r.y)-.01})(t,a,l)&&(i+=e.lastRuns?.has(l)?4:1);return i})(t,s,o)*r:0)+2*((e,t,a=H(e,t))=>{if(0===a.beside.length)return 0;let s=.01>Math.abs(e.y-t.y),i=s?Math.min(e.x,t.x):Math.min(e.y,t.y),l=s?Math.max(e.x,t.x):Math.max(e.y,t.y),o=0;for(let e of a.beside){let[t,a]=s?[Math.min(e.from.x,e.to.x),Math.max(e.from.x,e.to.x)]:[Math.min(e.from.y,e.to.y),Math.max(e.from.y,e.to.y)];o+=Math.max(0,Math.min(l,a)-Math.max(i,t))}return o})(t,s,o)},N=y.length,W=w.length;return(t,a,s)=>{var i;let l,{best:o,previous:r,stamp:c,epoch:d}=(i=y.length*w.length*12,cP.stamp.length<i&&(cP.best=new Float64Array(i),cP.previous=new Int32Array(i),cP.stamp=new Int32Array(i)),cP.epoch>=0x40000000&&(cP.stamp.fill(0),cP.epoch=0),cP.epoch+=1,cP),p=e=>c[e]===d?o[e]:1/0,h=(e,t)=>{let a=e%3;if(0===a)return!1;let s=e-a,i=2!==a||R.has(s/3)?0:40;return p(s+0)<=t+i+1e-9||2===a&&p(s+1)<=t+i+1e-9},g=new cC,u=new Map;e.sources.forEach((e,t)=>{let a=n[t],s=k(a);if(void 0===s||!q(e,a,!0,!0))return;let i=(4*s+e.direction)*3+0,l=e.cost+(e.lead??8);l<p(i)&&(c[i]=d,o[i]=l,r[i]=-1,u.set(i,e),g.push(l+U(a.x,a.y,e.direction),l,i))});let f=a,m=(e,t,a,s,i)=>{let l;if(t>=p(e)-1e-9||h(e,t))return;let n=($[l=4*s+i]!==G&&($[l]=G,Y[l]=U(y[s%y.length],w[Math.floor(s/y.length)],i)),Y[l]);e%3==2&&(n=Math.min(40+n,R.get(4*s+i)??1/0)),t+n>=f||(c[e]=d,o[e]=t,r[e]=a,u.delete(e),g.push(t+n,t,e))},v=0;for(;g.size>0&&v++<s;){let e=g.pop(),a=g.cost,s=g.reached;if(a>=f)break;let i=p(e);if(s>i+1e-6||h(e,i))continue;let o=e%3,r=Math.floor(e/12),n=Math.floor(e/3)%4,c=r%N,d=(r-c)/N,u=y[c],v=w[d],x=40*(2===o);for(let t of D.get(r)??[]){if((t.direction+2)%4===n)continue;let a=i+t.cost+cy(t.direction)+(t.direction===n?0:24+x);a<f&&(l={state:e,port:t},f=a)}let b=c+cx[n],k=d+cb[n];if(2!==o&&b>=0&&b<N&&k>=0&&k<W){let t=k*N+b,a=(4*t+n)*3+o;if(i+(Math.abs(y[b]-u)+Math.abs(w[k]-v))<p(a)-1e-9){let s=Z(r,t,n,0===o);1/0!==s&&m(a,i+s,e,t,n)}}for(let a=1;a<=3;a+=2){let s=(n+a)%4,l=i+24+x,o=0,r=c,h=d;for(;;){let a=r+cx[s],i=h+cb[s];if(a<0||a>=N||i<0||i>=W)break;let n=Math.abs(y[a]-y[r])+Math.abs(w[i]-w[h]),c=i*N+a,d=(4*c+s)*3;if(Math.min(p(d),p(d+1))<=l+n+1e-9)break;let g=Z(h*N+r,c,s,!1);if(1/0===g)break;l+=g,o+=n,r=a,h=i;let u=!t||o>=28;if(m(d+(u?1:2),l,e,c,s),u)break}}}if(!l)return{expansions:v};let x=f,b=[l.port],M=l.state;for(b.push(ck(l.port,(l.port.direction+2)%4,cy(l.port.direction)));M>=0;){b.push(C(Math.floor(M/12)));let e=u.get(M);if(e){b.push(e);break}M=r[M]}return{points:function(e){let t=[];for(let a of e){let e=t.at(-1);if(e&&.01>Math.abs(e.x-a.x)&&.01>Math.abs(e.y-a.y))continue;let s=t.at(-2);s&&e&&(.01>Math.abs(s.x-e.x)&&.01>Math.abs(e.x-a.x)||.01>Math.abs(s.y-e.y)&&.01>Math.abs(e.y-a.y))?t[t.length-1]=a:t.push(a)}return t}(b.toReversed()),cost:x,expansions:v}}}(e,t,a),l=i(!1,1/0,12e3);if(h&&(h.remaining-=l.expansions),!l.points)return;let o=cH(l.points);if(!s||!g||g.remaining<=0||0===o)return l.points;let r=i(!0,l.cost+o-1e-6,Math.min(12e3,2*l.expansions,g.remaining));return g.remaining-=r.expansions,r.points??l.points};return(e.wide?void 0:u(n,o,!0))??u(p,o,!0)??u(p,r,!1)}function cH(e){let t=cq(e),a=0;for(let{from:e,to:s}of t.slice(1,-1))Math.abs(s.x-e.x)+Math.abs(s.y-e.y)<28&&(a+=40);return a}function cq(e){return e.slice(1).map((t,a)=>({from:e[a],to:t}))}function cF(e,t,a){let s=e.at(-1),i=e.at(-2),l=Math.min(1,t/Math.max(Math.abs(s.x-i.x)+Math.abs(s.y-i.y),.01)),o={x:s.x+(i.x-s.x)*l,y:s.y+(i.y-s.y)*l};return{left:Math.min(o.x,s.x)-a,right:Math.max(o.x,s.x)+a,top:Math.min(o.y,s.y)-a,bottom:Math.max(o.y,s.y)+a}}let cI=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],cE=(e,t=2)=>String(e).padStart(t,"0");function cO(e){let t,a=new Map;for(let t of[...e.events.flatMap(e=>[e.date,e.end]),e.today]){let e=void 0===t?void 0:ei(t);void 0!==t&&e&&a.set(t,e)}if(0===a.size)return{events:new Map};let s=new Set([...a.values()].flatMap(e=>void 0===e.offsetMinutes?[]:[e.offsetMinutes])),i=1===s.size?[...s][0]??0:0,l=s.size>0?function(e){if(0===e)return"UTC";let t=Math.abs(e);return`UTC${e<0?"-":"+"}${cE(Math.floor(t/60))}:${cE(t%60)}`}(i):void 0,o=new Map([...a].map(([e,t])=>[e,function(e,t){if("instant"!==e.granularity)return{granularity:e.granularity,...e.fields};let a=new Date(e.start+6e4*t);return{granularity:"instant",year:a.getUTCFullYear(),month:a.getUTCMonth()+1,day:a.getUTCDate(),hour:a.getUTCHours(),minute:a.getUTCMinutes(),second:a.getUTCSeconds(),millisecond:a.getUTCMilliseconds()}}(t,i)])),r=[...o.values()],n=r[0],c=r.some(e=>"instant"===e.granularity)&&r.every(e=>("day"===e.granularity||"instant"===e.granularity)&&e.year===n.year&&e.month===n.month&&e.day===n.day),d=r.some(e=>e.year!==n.year),p=r.some(e=>"instant"===e.granularity&&e.second>0),h=r.some(e=>"instant"===e.granularity&&e.millisecond>0),g=e=>`${cE(e.hour)}:${cE(e.minute)}${p||h?`:${cE(e.second)}`:""}${h?`.${cE(e.millisecond,3)}`:""}`,u=e=>`${cI[e.month-1]} ${e.day}`,f=(e,t)=>{if(c)return"instant"===e.granularity?g(e):u(e);let a=t?` ${e.year}`:"";switch(e.granularity){case"year":return String(e.year);case"month":return`${cI[e.month-1]}${a}`;case"day":return`${u(e)}${t?`, ${e.year}`:""}`;case"instant":return`${u(e)}${t?`, ${e.year}`:""}, ${g(e)}`}},m=(e,t,a)=>{if(c)return`${f(e,!1)}–${f(t,!1)}`;if(e.year!==t.year)return`${f(e,!0)} – ${f(t,!0)}`;let s=a&&"year"!==t.granularity?`, ${t.year}`:"";return"day"===e.granularity&&"day"===t.granularity&&e.month===t.month?`${u(e)}–${t.day}${s}`:"month"===e.granularity&&"month"===t.granularity?`${cI[e.month-1]} – ${cI[t.month-1]}${a?` ${t.year}`:""}`:`${f(e,!1)} – ${f(t,!1)}${s}`},v=new Map;for(let a of ep(e)){let e=void 0===a.date?void 0:o.get(a.date);if(!e)continue;let s=void 0===a.end?void 0:o.get(a.end),i=e.year!==t?.year||"month"===e.granularity&&"month"!==t.granularity;v.set(a.id,s?m(e,s,i):f(e,i)),t=s??e}let y=c?`${u(n)}, ${n.year}${l?` \xb7 ${l}`:""}`:l?`Times in ${l}`:void 0,w=void 0===e.today?void 0:o.get(e.today);return{...y?{header:y}:{},events:v,...w?{today:`Today \xb7 ${f(w,d)}`}:{}}}let cU={millisecond:1,second:1e3,minute:6e4,hour:36e5,day:864e5,month:2629746e3,year:31556952e3},cX=v.ink,cT="#4c4639",cY="#cbbfa9",c$="#c0392b",cG=[12,24],cD=[0,-6,6],cR=[-3,3];function cZ(e,t){return{text:e,width:Math.ceil(aq(e,t)),height:Math.ceil(e.split("\n").length*t*1.35)}}function cj(e,t,a){let s=cZ(e,a);return s.width<=t?s:cZ(aO(e,Math.max(1,t),a),a)}function cN(e){return Math.round(100*e)/100}class cW{elements=[];layers={back:[],middle:[],front:[]};textBoxes=[];push(e,t){this.elements.push(e),this.layers[t].push(e.id)}zOrder(){return[...this.layers.back,...this.layers.middle,...this.layers.front]}text(e,t,a,s,i,l,o="left",r={}){let n={left:a,top:s,right:a+t.width,bottom:s+t.height};return this.push({type:"text",id:e,x:cN(a+t.width/2),y:cN(s+t.height/2),text:t.text,fontSize:i,maxWidth:t.width,textAlign:o,textColor:l,...r},"front"),this.textBoxes.push(n),n}line(e,t,a,s="back"){let[i,l,...o]=t.map(e=>({x:cN(e.x),y:cN(e.y)}));this.push({type:"line",id:e,points:[i,l,...o],roughness:0,strokeWidth:1,...a},s)}mark(e,t,a,s,i){this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:"gantt-mark",shape:t,x:cN(a.x),y:cN(a.y),width:cN(cN(a.x+a.width)-cN(a.x)),height:cN(cN(a.y+a.height)-cN(a.y)),label:s,roughness:0,fillStyle:"solid",strokeWidth:1,...i},"middle")}breakRulesUnderText(e,t=this.textBoxes){let a=nj(this.elements,t,e);if(!a.size)return;let s=this.elements.flatMap(e=>a.get(e.id)??[e]);for(let e of(this.elements.splice(0,this.elements.length,...s),Object.values(this.layers))){let t=e.flatMap(e=>a.get(e)?.map(e=>e.id)??[e]);e.splice(0,e.length,...t)}}bounds(){let e=1/0,t=1/0,a=-1/0,s=-1/0,i=(i,l,o,r)=>{e=Math.min(e,i),t=Math.min(t,l),a=Math.max(a,o),s=Math.max(s,r)};for(let e of this.elements)if("line"===e.type||"arrow"===e.type)for(let t of e.points)i(t.x,t.y,t.x,t.y);else if("text"===e.type){let t=e.maxWidth??aq(e.text,e.fontSize),a=e.text.split("\n").length*e.fontSize*1.35;i(e.x-t/2,e.y-a/2,e.x+t/2,e.y+a/2)}else i(e.x,e.y,e.x+e.width,e.y+e.height);return{left:e,top:t,right:a,bottom:s}}}let cJ=[7,19,31];function cK(e,t,a,s,i=[]){let l=(e.top+e.bottom)/2,o=e=>40*(1===e!==a);if(t){let t=(e.left+e.right)/2,a=(e.right-e.left)/4;return[{x:e.right,y:l,direction:0,cost:2},{x:t,y:e.bottom,direction:1,cost:o(1)},{x:t,y:e.top,direction:3,cost:o(3)},...[-1,1].map(t=>({x:e.right-a,y:l+t*a,direction:0,cost:8})),{x:t+a,y:e.bottom-a,direction:1,cost:6+o(1)},{x:t+a,y:e.top+a,direction:3,cost:6+o(3)},{x:t-a,y:e.bottom-a,direction:1,cost:16+o(1)},{x:t-a,y:e.top+a,direction:3,cost:16+o(3)},...i.filter(t=>t>e.left+2&&t<e.right-2).flatMap(e=>{let s=2*a-Math.abs(e-t),i=(e<t?16:6)+3;return[{x:e,y:l+s,direction:1,cost:i+o(1)},{x:e,y:l-s,direction:3,cost:i+o(3)}]})]}let r=[6,16,26].filter(t=>e.right-t>=e.left+3),n=Array.from({length:6},(t,a)=>e.right-6-2.5*a).filter(t=>t>=e.left+2),c=r.length>=3?r.map(t=>e.right-t):n.length?n:[(e.left+e.right)/2],d=void 0!==s&&s>e.left+1&&s<e.right-1?[s]:[],p=i.filter(t=>t>=Math.max(e.left+2,e.right-32)&&t<=e.right-2&&c.every(e=>Math.abs(e-t)>=1));return[...d.flatMap(t=>[{x:t,y:e.bottom,direction:1,cost:o(1)},{x:t,y:e.top,direction:3,cost:o(3)}]),...c.map((t,a)=>({x:t,y:e.bottom,direction:1,cost:o(1)+3*a})),...p.flatMap(t=>[{x:t,y:e.bottom,direction:1,cost:o(1)+3},{x:t,y:e.top,direction:3,cost:o(3)+3}]),...e.right-e.left>=8?[{x:e.right,y:l,direction:0,cost:2}]:[],...c.map((t,a)=>({x:t,y:e.top,direction:3,cost:o(3)+3*a}))]}function cQ(e,t=!1){let a=!t&&.01>Math.abs(e.at(-1).y-e.at(-2).y);return cF(e,a?40:12,4.5)}function c1(e,t,a,s=!1){let i=cQ(t,s),l=cq(e),o=cq(t),r=a.leaving&&cA(l[0].from,l[0].to,o[0])?cQ(t,!0):i,n=0;return l.forEach((e,t)=>{c0(e,0===t?r:i)&&(n+=1),o.forEach((s,i)=>{!(a.leaving&&0===t&&0===i||a.arriving&&t===l.length-1&&i===o.length-1)&&function(e,t,a){let s=.01>Math.abs(e.y-t.y);if(s!==.01>Math.abs(a.from.y-a.to.y)||(s?Math.abs(e.y-a.from.y):Math.abs(e.x-a.from.x))>=2)return!1;let[i,l]=s?[Math.min(e.x,t.x),Math.max(e.x,t.x)]:[Math.min(e.y,t.y),Math.max(e.y,t.y)],[o,r]=s?[Math.min(a.from.x,a.to.x),Math.max(a.from.x,a.to.x)]:[Math.min(a.from.y,a.to.y),Math.max(a.from.y,a.to.y)];return Math.min(l,r)-Math.max(i,o)>0}(e.from,e.to,s)&&function(e,t){let a=.01>Math.abs(e.from.y-e.to.y),s=e=>a?[Math.min(e.from.x,e.to.x),Math.max(e.from.x,e.to.x)]:[Math.min(e.from.y,e.to.y),Math.max(e.from.y,e.to.y)],[i,l]=s(e),[o,r]=s(t);return Math.min(l,r)-Math.max(i,o)}(e,s)>1&&(n+=1)})}),n}function c0(e,t){let{from:a,to:s}=e;return Math.max(a.x,s.x)>t.left&&Math.min(a.x,s.x)<t.right&&Math.max(a.y,s.y)>t.top&&Math.min(a.y,s.y)<t.bottom}function c2(e){return e.replaceAll("%","%25").replaceAll(":","%3A")}let c3=[2.5,2,.3,.05,0];function c5(e,t,a=1){return[e,...Array.from({length:Math.max(0,Math.floor(t/a))},(e,t)=>(t+1)*a).flatMap(t=>[e+t,e-t])]}function c4(e,t){let a,s,i,l,o,r,n,c,d,p=new Map(e.tasks.map(e=>[e.id,tr(e)])),h=tc(e),g=void 0===e.today?void 0:ti(e.today),u=[...p.values()],f=Math.min(...u.map(e=>e.start),g??1/0),m=Math.max(...u.map(e=>e.milestone?e.start+1:e.end),void 0===g?-1/0:g+1),v=(a=new Map(e.tasks.map(e=>[e.id,tr(e)])),s=tc(e).flatMap((e,t)=>{if(void 0===e.phase)return[];let s=e.tasks.map(e=>a.get(e.id));return[{index:t,name:e.phase,start:Math.min(...s.map(e=>e.start)),end:Math.max(...s.map(e=>Math.max(e.end,e.start+1)))}]}),i=e=>`\0phase:${e}`,l=(e,t,a,s)=>({id:e,label:t,date:tl(a),...s-a>1?{end:tl(s-1)}:{}}),r=cO(o={id:e.id,title:e.title,type:"timeline",events:[...s.map(e=>l(i(e.index),e.name,e.start,e.end)),...e.tasks.map(e=>{let t=a.get(e.id);return l(e.id,e.label,t.start,t.end)})],...e.today?{today:e.today}:{},style:e.style}),n=new Set(o.events.flatMap(e=>[e.date,e.end].flatMap(e=>void 0===e?[]:[e.slice(0,4)]))),c=e=>{if(n.size<2)return r.events.get(e)??"";let t=o.events.find(t=>t.id===e);return cO({...o,events:[t]}).events.get(e)??""},{tasks:new Map(e.tasks.map(e=>{let t=c(e.id);return[e.id,void 0===e.progress?t:`${t} \xb7 ${e.progress}%`]})),phases:new Map(s.map(e=>[e.name,c(i(e.index))])),...r.today?{today:r.today}:{}}),y=(e,a)=>{let s=cj(e.label,260,14);return{task:e,schedule:p.get(e.id),color:a,label:s,caption:cZ(v.tasks.get(e.id),12),height:Math.max(t,s.height+16)}},w=[],x=0;h.forEach((e,t)=>{let a=nW[t%nW.length];if(void 0!==e.phase){let a=cj(e.phase,220,15),s=cZ(v.phases.get(e.phase),12),i=Math.max(40,a.height+16);w.push({kind:"phase",top:x,height:i,phase:{index:t,name:a,caption:s}}),x+=i}for(let t of e.tasks){let e=y(t,a);w.push({kind:"task",top:x,height:e.height,task:e}),x+=e.height}});let b=x,k=w.filter(e=>"task"===e.kind).length,M=12*!!w.some(e=>"phase"===e.kind),C=Math.max(Math.max(...w.map(e=>e.task?M+e.task.label.width:0))+20+Math.max(...w.map(e=>(e.task?e.task.caption:e.phase.caption).width)),...w.map(e=>e.phase?e.phase.name.width+10+e.phase.caption.width:0)),z=-16-C,_=function(e,t,a=960){let s=Math.max(t,e+1);for(let{unit:t,step:i}of cm){let l="year"===t&&50===i,o=cv(e,s,t,i,e=>(function(e,t,a){let s=cu(e);switch(t){case"day":return String(s.day);case"week":return`${cg[s.month-1]} ${s.day}`;case"month":return cg[s.month-1];case"quarter":return`Q${Math.floor((s.month-1)/3)+1}`;case"year":return 1===a?String(s.year):`${s.year}–${String(s.year+a-1)}`}})(e,t,i),l?1/0:36);if(!o)continue;let r=o[0].start,n=o.at(-1).end,c=Math.min(56,a/(n-r));if(!o.every(e=>aq(e.label,12)+8<=(e.end-e.start)*c)&&!l)continue;let d=("year"===t?[]:"day"===t?cv(r,n,"month",1,e=>`${cg[cu(e).month-1]} ${cu(e).year}`):cv(r,n,"year",1,e=>String(cu(e).year)))??[],p=new Set(o.map(e=>e.start)),h="month"===t?"week":"quarter"===t?"month":void 0,g=h&&("week"===h?7:28)*c>=12?(cv(r,n,h,1,()=>"")??[]).map(e=>e.start).filter(e=>e>r&&!p.has(e)):[];return{unit:t,step:i,start:r,end:n,pxPerDay:c,cells:o,minor:g,bands:d.map(e=>({start:Math.max(e.start,r),end:Math.min(e.end,n),label:e.label}))}}throw Error("unreachable: half-century ticks always fit")}(f,m,Math.max(640,Math.min(960,2.2*(Math.ceil(27*!!e.title.length)+14+18*(void 0!==g)+44+b+44*(k>=16)+80)-80-C-16-24))),L=Math.max(0,...u.map(e=>e.milestone?15-(e.start+.5-_.start)*_.pxPerDay:0)),B=e=>24+L+(e-_.start)*_.pxPerDay,S=B(_.end),A=new cW,P=[{box:{left:z-32,right:-2,top:0,bottom:b},clearance:0}],V=new Map;for(let e of w){if("phase"!==e.kind)continue;let{index:t,name:a,caption:s}=e.phase,i=e.top+e.height/2,l={groupIds:[`gantt:phase:${t}`]};A.text(`gantt:phase:${t}`,a,z,i-a.height/2,15,cX,"left",l),A.text(`gantt:phase-caption:${t}`,s,-16-s.width,i-s.height/2,12,cT,"right",l)}for(let e of w){if("task"!==e.kind)continue;let{task:t,schedule:a,color:s,label:i,caption:l}=e.task,o=e.top+e.height/2,r=a.milestone?B(a.start+.5)-13:B(a.start),n=a.milestone?B(a.start+.5)+13:Math.max(B(a.end),B(a.start)+2),c=`gantt:task:${t.id}`,d={groupIds:[c]},p={groupIds:[`gantt:row:${t.id}`]},h=a.milestone?{left:r,right:n,top:o-13,bottom:o+13}:{left:r,right:n,top:o-11,bottom:o+11};V.set(t.id,h),A.mark(c,a.milestone?"diamond":"rectangle",{x:h.left,y:h.top,width:h.right-h.left,height:h.bottom-h.top},t.label,a.milestone?{fillColor:cX,strokeColor:cX,...d}:{fillColor:s,strokeColor:s,...d});let g=t.progress??0,u=function(e){let t=t=>{let a=Number.parseInt(e.slice(t,t+2),16);return Math.round(a+(Number.parseInt(cX.slice(t,t+2),16)-a)*.35).toString(16).padStart(2,"0")};return`#${t(1)}${t(3)}${t(5)}`}(s),f=h.left+(h.right-h.left)*g/100;!a.milestone&&f-h.left>=1&&A.mark(`gantt:progress:${t.id}`,"rectangle",{x:h.left,y:h.top,width:f-h.left,height:h.bottom-h.top},`${t.label} \xb7 ${g}%`,{fillColor:u,strokeColor:u,...d}),A.text(`gantt:label:${t.id}`,i,z+M,o-i.height/2,14,cX,"left",p),A.text(`gantt:caption:${t.id}`,l,-16-l.width,o-l.height/2,12,cT,"right",p)}let H=[...V].filter(([e])=>!p.get(e).milestone),q=new Map(w.flatMap((e,t)=>e.task?[[e.task.task.id,t]]:[])),F=w.slice(1).flatMap(e=>cD.map(t=>e.top+t)),I=w.slice(1).flatMap(e=>[...cD,...cR].map(t=>e.top+t)),E=e.tasks.flatMap((e,t)=>(e.dependsOn??[]).map((a,s)=>({from:a,to:e.id,taskIndex:t,order:s}))).toSorted((e,t)=>Math.abs(q.get(e.to)-q.get(e.from))-Math.abs(q.get(t.to)-q.get(t.from))||q.get(e.to)-q.get(t.to)||q.get(e.from)-q.get(t.from)||e.taskIndex-t.taskIndex||e.order-t.order),O=void 0===g?void 0:B(g+.5),U=void 0===O?[]:[{from:{x:O,y:0},to:{x:O,y:b}}],X=E.map(()=>void 0),T=[...U],Y=new Map,$=new Map,G=new Map,D=[],R=[],Z=new Set,j=new Set,N=new Map,W=new Set,J=Math.min(16e4,Math.max(12e3,6e3*E.length)),K={remaining:J},Q=Math.min(48e3,1500*E.length),ee={remaining:Q},et=0,ea=0,es=new Map;for(let{from:e,to:t}of E)es.set(e,(es.get(e)??new Set).add(q.get(t)>q.get(e)?1:3));let ei=(e,t)=>{let a=cq(t);T.push(...a),Z.add(a.at(-1)),j.add(a[0]),$.set(e.from,[...$.get(e.from)??[],...a]),G.set(e.to,[...G.get(e.to)??[],...a]);let s={box:cQ(t,!0),clearance:0};D.push({from:e.from,trunk:a[0],keepOut:{box:cQ(t),clearance:0},arrowhead:s}),R.push({from:e.from,trunk:a[0],keepOut:{box:cF(t,.01>Math.abs(t.at(-1).y-t.at(-2).y)?40:12,6),clearance:0},arrowhead:s}),N.set(e.to,N.get(e.to)-1),Y.set(e.to,[...Y.get(e.to)??[],t.at(-1)])},el=()=>{for(let e of(T.splice(0,T.length,...U),[Y,$,G,N]))e.clear();for(let e of(D.length=0,R.length=0,Z.clear(),j.clear(),E))N.set(e.to,(N.get(e.to)??0)+1);E.forEach((e,t)=>{let a=X[t];a&&ei(e,a)})};el();let eo=(e,t=K)=>{et+=1;let a=Math.min(12e3,t.remaining),s={remaining:a},i=V.get(e.from),l=V.get(e.to),o=p.get(e.from).milestone,r=p.get(e.to).milestone,n=q.get(e.to)>q.get(e.from),c=e=>(e.left+e.right)/2,d=Y.get(e.to)??[],h=function(e,t,a,s=[],i=!1){let l=(e.top+e.bottom)/2,o=e=>40*(1===e!==a),r=e=>4*(-1===e!==a);if(t){let t=(e.left+e.right)/2,a=(e.right-e.left)/4;return[{x:e.left,y:l,direction:0,cost:16*!!i},{x:t,y:e.top,direction:1,cost:2+o(1)},{x:t,y:e.bottom,direction:3,cost:2+o(3)},...[-1,1].map(t=>({x:e.left+a,y:l+t*a,direction:0,cost:i?r(t):16})),{x:t-a,y:e.top+a,direction:1,cost:16+o(1)},{x:t-a,y:e.bottom-a,direction:3,cost:16+o(3)}]}let n=cJ.filter(t=>e.left+t<=e.right-3),c=n.length?n.map(t=>e.left+t):[(e.left+e.right)/2],d=s.filter(t=>t>e.left+1&&t<e.right-1);return[{x:e.left,y:l,direction:0,cost:24*!!i},...[-1,1].map(t=>({x:e.left,y:l+7*t,direction:0,cost:i?r(t):24})),...d.flatMap(t=>[{x:t,y:e.top,direction:1,cost:o(1)},{x:t,y:e.bottom,direction:3,cost:o(3)}]),...c.map((t,a)=>({x:t,y:e.top,direction:1,cost:20+o(1)+3*a})),...c.map((t,a)=>({x:t,y:e.bottom,direction:3,cost:20+o(3)+3*a}))]}(l,r,n,o?[c(i)]:i.right-i.left>=8&&i.right+8<=l.left+cJ.at(-1)?[i.right+8]:[],(N.get(e.to)>1||d.length>0)&&(!r||W.has(e.to))),g=e=>void 0===O||(e.direction%2==0?O<e.x-16-5||O>e.x+5:Math.abs(e.x-O)>=5),u=(e,t)=>d.every(a=>Math.hypot(a.x-e.x,a.y-e.y)>=t),f=e=>{let t=cy(e.direction),a=cF([{x:e.x-(0===e.direction?t:0),y:e.y-(1===e.direction?t:3===e.direction?-t:0)},e],t,6);return!T.some(e=>c0(e,a))},m=[...es.get(e.to)??[]].flatMap(e=>cK(l,r,1===e).find(t=>t.direction===e)??[]),v=e=>{if(e.direction%2==0){let t=cQ([{x:e.x-16,y:e.y},e]);return m.every(e=>!c0({from:e,to:{x:e.x,y:e.y+(1===e.direction?1:-1)*8}},t))}return m.every(t=>t.direction!==(e.direction+2)%4||Math.abs(t.x-e.x)>=8)},y=function(e,t,a){let s=(e.top+e.bottom)/2,i=(e.left+e.right)/2,l=e=>40*(1===e!==a),o=(e,t)=>Array.from({length:Math.max(0,Math.floor((t-e)/3))+1},(t,a)=>e+3*a);if(t){let t=(e.right-e.left)/2,a=(e.bottom-e.top)/2,r=(e,l)=>s+l*a*(1-Math.abs(e-i)/t);return[...o(e.top+3,e.bottom-3).map(e=>({x:i-t*(1-Math.abs(e-s)/a),y:e,direction:0,cost:30})),...o(e.left+3,i).flatMap(e=>[{x:e,y:r(e,-1),direction:1,cost:40+l(1)},{x:e,y:r(e,1),direction:3,cost:40+l(3)}])]}return[...o(e.top+3,e.bottom-3).map(t=>({x:e.left,y:t,direction:0,cost:30+Math.abs(t-s)})),...o(e.left+3,e.right-3).flatMap(t=>[{x:t,y:e.top,direction:1,cost:40+l(1)+(t-e.left)/4},{x:t,y:e.bottom,direction:3,cost:40+l(3)+(t-e.left)/4}])]}(l,r,n),x=[[h,e=>g(e)&&u(e,11)&&f(e)&&v(e)],[h,e=>g(e)&&u(e,6)&&f(e)&&v(e)],[y,e=>g(e)&&u(e,3)&&f(e)&&v(e)],[h,e=>g(e)&&u(e,1)&&f(e)],[h,e=>u(e,1)&&f(e)],[y,e=>u(e,1)&&f(e)]].map(([e,t])=>e.filter(t)).find(e=>e.length>0)??h,k=($.get(e.from)??[]).filter(e=>j.has(e)),M=new Map(k.map(e=>{let t=function({from:e,to:t}){return .01>Math.abs(e.y-t.y)?t.x>e.x?0:2:t.y>e.y?1:3}(e),a=t%2==1&&1===t!==n;return[`${e.from.x},${e.from.y},${t}`,{...e.from,direction:t,cost:40*!!a}]})),C=[...[...V].flatMap(([t,a])=>{let s,i,l,o,r,n;return t!==e.from&&t!==e.to?[{box:a,clearance:4,sideClearance:8}]:p.get(t).milestone?[{box:(s=(a.right-a.left)/4,i=(a.bottom-a.top)/4,{left:a.left+s,right:a.right-s,top:a.top+i,bottom:a.bottom-i}),clearance:3,own:!0},...(l=(a.top+a.bottom)/2,o=(a.left+a.right)/2,r=(a.right-a.left)/8,n=(a.bottom-a.top)/8,[{left:a.left,right:a.right,top:l-n,bottom:l+n},{left:o-r,right:o+r,top:a.top,bottom:a.bottom}]).map(e=>({box:e,clearance:.5,own:!0})),...[{...a,bottom:a.top},{...a,top:a.bottom},{...a,right:a.left},{...a,left:a.right}].map(e=>({box:e,clearance:3,own:!0,parallel:!0}))]:[{box:a,clearance:3,own:!0}]}),...P],z={sources:[...M.values(),...o||i.right-i.left<8?[]:(r?[c(l)]:cJ.some(e=>l.left+e<=l.right-3)?cJ.filter(e=>l.left+e<=l.right-3).map(e=>l.left+e):[c(l)]).filter(e=>e-i.right>=3&&e-i.right<8).map(e=>({x:i.right,y:(i.top+i.bottom)/2,direction:0,cost:2,lead:e-i.right})),...cK(i,o,n,r?c(l):void 0,[...r?[l.left-19,l.left+(l.right-l.left)/4-19]:[l.left-19,...cJ.filter(e=>l.left+e<=l.right-3).map(e=>l.left+e)],...[...V].flatMap(([t,a])=>t===e.from||t===e.to?[]:[a.left-8,a.right+8])])],targets:x,obstacles:[...C,...R.map(t=>t.from===e.from?t.arrowhead:t.keepOut),...[...N.keys()].flatMap(t=>t===e.to?[]:(e=>{let t=N.get(e)??0;if(t<=0)return[];let a=V.get(e),s=(a.top+a.bottom)/2,i=(a.right-a.left)/4,l=p.get(e).milestone,o=l?[{x:a.left,y:s},{x:a.left+i,y:s-i},{x:a.left+i,y:s+i}]:[0,-7,7].map(e=>({x:a.left,y:s+e})),r=Y.get(e)??[],[n,...c]=o;return(t+r.length>1?[...c,n]:o).filter(e=>r.every(t=>Math.hypot(t.x-e.x,t.y-e.y)>=3)).slice(0,t).map(e=>({left:e.x-16-6,right:e.x+6*!!l,top:e.y-6,bottom:e.y+6}))})(t).map(e=>({box:e,clearance:0})))],behind:Math.min(i.left,l.left-16-8-5)-16,lanes:F,denseLanes:I,routed:T,kin:new Set([...$.get(e.from)??[],...G.get(e.to)??[]]),lastRuns:Z,trunks:new Set(k),pastTrunk:new Map(R.flatMap(t=>t.from===e.from?[[t.keepOut,t.trunk]]:[])),edges:H.flatMap(([t,a])=>t===e.from||t===e.to?[]:[a]),top:1,bottom:b-1,budget:s,kinkBudget:ee},_=cV(z)??cV({...z,obstacles:[...C,...D.map(t=>t.from===e.from?t.arrowhead:t.keepOut)],pastTrunk:new Map(D.flatMap(t=>t.from===e.from?[[t.keepOut,t.trunk]]:[]))});return t.remaining-=a-s.remaining,_||(ea+=1),_??function(e){let{source:t,target:a,routed:s}=e,i=e.heads.map(({box:e})=>e),l=s.filter(e=>.01>Math.abs(e.from.y-e.to.y)),o=s.filter(e=>Math.abs(e.from.y-e.to.y)>=.01),r=([t,a,s])=>{let r=.01>Math.abs(t.y-a.y),n=r?t.y:t.x,c=r?Math.min(t.x,a.x):Math.min(t.y,a.y),d=r?Math.max(t.x,a.x):Math.max(t.y,a.y),p=1/0;for(let t of r?l:o){if(s&&e.siblings.has(t))continue;let a=Math.abs((r?t.from.y:t.from.x)-n);if(a>=p)continue;let i=r?Math.min(t.from.x,t.to.x):Math.min(t.from.y,t.to.y);Math.min(d,r?Math.max(t.from.x,t.to.x):Math.max(t.from.y,t.to.y))-Math.max(c,i)>0&&(p=a)}let h=c3.findIndex(e=>p>=e);return i.some(e=>c0({from:t,to:a},e))?Math.max(h,3):h},n=(e,t,a=()=>!0)=>{let s;for(let i of e){let e=t(i).map(e=>r(e)),l=100*Math.max(...e,+!a(i))+e.reduce((e,t)=>e+t,0);if((!s||l<s.score)&&(s={candidate:i,score:l}),0===l)break}return s.candidate},c=(t.left+t.right)/2,d=(t.right-t.left)/2,p=a=>e.sourceMilestone?c5(c,d-4,.5).map(e=>({x:e,y:(1===a?t.bottom:t.top)-a*Math.abs(e-c)})):c5(Math.max(c,t.right-6),Math.min(2*d,12),.5).filter(e=>e>=t.left+.5&&e<=t.right-.5).map(e=>({x:e,y:1===a?t.bottom:t.top})),h=e=>[...c5(e,8),...c5(e,8,.5),...c5(e+.1,8,.1)],g=h(e.sourceRow.top+e.sourceRow.height).filter(a=>a>=t.bottom+2&&a<=e.rowsBottom-1),u=h(e.sourceRow.top).filter(a=>a<=t.top-2&&a>=e.rowsTop+1),[f,m]=n([...p(1).map(e=>[e,g]),...p(-1).map(e=>[e,u])].filter(([,e])=>e.length>0),([e,t])=>[[e,{x:e.x,y:t[0]},!0],[{x:e.x,y:t[0]},{x:12,y:t[0]}]]),v=n(m,e=>[[f,{x:f.x,y:e},!0],[{x:f.x,y:e},{x:12,y:e}]]),y=(a.top+a.bottom)/2,w=(a.bottom-a.top)/2,x=(a.right-a.left)/(a.bottom-a.top),b=n(c5(y,w-(e.targetMilestone?4:3)).map(t=>({x:e.targetMilestone?a.left+Math.abs(t-y)*x:a.left,y:t})),e=>[[{x:12,y:e.y},e]],t=>{let a=cF([{x:t.x-16,y:t.y},t],16,4.5);return e.taken.every(e=>Math.hypot(e.x-t.x,e.y-t.y)>=3)&&!s.some(e=>c0(e,a))}),k=n([...c5(12,10.5,.5),...c5(12.1,10.5,.1)],e=>[[{x:f.x,y:v},{x:e,y:v}],[{x:e,y:v},{x:e,y:b.y}],[{x:e,y:b.y},b]]);return[f,{x:f.x,y:v},{x:k,y:v},{x:k,y:b.y},b]}({source:i,sourceMilestone:o,sourceRow:w[q.get(e.from)],target:l,targetMilestone:r,rowsTop:0,rowsBottom:b,routed:T,heads:D.map(e=>e.keepOut),taken:d,siblings:new Set(k)})};E.forEach((e,t)=>{let a=eo(e);X[t]=a,ei(e,a)});let er=(e,t)=>({leaving:E[e].from===E[t].from,arriving:E[e].to===E[t].to}),en=e=>{let t=X[e],a=0;return X.forEach((s,i)=>{if(i===e||!s)return;let l=er(e,i);a+=c1(t,s,l)+c1(s,t,l)}),a},ec=new Map;E.forEach((e,t)=>ec.set(e.to,[...ec.get(e.to)??[],t]));let ed=e=>cq(e).reduce((e,{from:t,to:a})=>e+Math.abs(a.x-t.x)+Math.abs(a.y-t.y),0),ep=e=>{let t=cq(X[e]),a=0;return X.forEach((s,i)=>{if(i!==e&&s)for(let e of cq(s))for(let s of t)(function(e,t){let a=e=>.01>Math.abs(e.from.y-e.to.y);if(a(e)===a(t))return!1;let[s,i]=a(e)?[e,t]:[t,e],l=i.from.x,o=s.from.y;return l>Math.min(s.from.x,s.to.x)+.01&&l<Math.max(s.from.x,s.to.x)-.01&&o>Math.min(i.from.y,i.to.y)+.01&&o<Math.max(i.from.y,i.to.y)-.01})(s,e)&&(a+=1)}),a},eh=e=>({conflicts:e.reduce((e,t)=>e+en(t),0),drawn:e.reduce((e,t)=>{let a=X[t];return e+ed(a)+24*(a.length-2)+cH(a)+60*ep(t)},0)}),eg=(e,t)=>e.conflicts<t.conflicts||e.conflicts===t.conflicts&&e.drawn<t.drawn-1e-6,eu=e=>e.some(e=>en(e)>0||ep(e)>0)||e.reduce((e,t)=>{let a=X[t],[s,i]=[a[0],a.at(-1)];return e+ed(a)-Math.abs(i.x-s.x)-Math.abs(i.y-s.y)},0)>60;for(let[e,t]of ec){if(t.length<2||!eu(t))continue;let a=[{order:t.toReversed(),split:!1},...p.get(e).milestone?[{order:t,split:!0}]:[]],s={routes:t.map(e=>X[e]),standing:eh(t),split:!1};for(let i of a){if(K.remaining<=0||i.split&&(t.forEach((e,t)=>X[e]=s.routes[t]),!t.some(e=>ep(e)>0||cH(X[e])>0)))break;for(let e of t)X[e]=void 0;for(let t of(el(),i.split&&W.add(e),i.order)){let e=eo(E[t]);X[t]=e,ei(E[t],e)}W.delete(e);let a=eh(t);eg(a,s.standing)&&(s={routes:t.map(e=>X[e]),standing:a,split:i.split})}t.forEach((e,t)=>X[e]=s.routes[t]),s.split&&W.add(e),el()}let ef={remaining:48e3},em=0,ev=e=>{if(em>=2*E.length)return;em+=1;let t=X[e];X[e]=void 0,el();let a=eo(E[e],ef);return X[e]=t,el(),a},ey=(e,t)=>{let a,s=[e,t],i=eh(s);for(let e of s){let t=ev(e);if(!t)continue;let l=X[e];X[e]=t,el();let o=eh(s);o.conflicts<i.conflicts&&eg(o,i)&&(i=o,a={index:e,points:t}),X[e]=l,el()}return!!a&&(X[a.index]=a.points,ew[a.index]=ew[a.index]+1,el(),!0)},ew=E.map(()=>0),ex=new Set;for(let e=0;e<2;e+=1){let e=!1;if(X.forEach((t,a)=>{X.forEach((t,s)=>{let i=X[a];if(s===a||!i||!t||0===c1(i,t,er(a,s)))return;let l=`${a}.${ew[a]}:${s}.${ew[s]}`;!ex.has(l)&&(ex.add(l),ey(a,s)&&(e=!0))})}),!e)break}for(let e of E.map((e,t)=>({id:`gantt:dependency:${c2(e.from)}:${c2(e.to)}`,...e,points:X[t]})).map(e=>{let[t,...a]=(function(e){var t;let a,s,i=e.at(-1),l=e.at(-2),o=Math.abs(i.x-l.x)+Math.abs(i.y-l.y),r=(a=(t=e).at(-1),s=t.at(-2),.01>Math.abs(a.y-s.y)?16:12);if(o<=r+1)return[...e];let n=r/o;return[...e.slice(0,-1),{x:i.x+(l.x-i.x)*n,y:i.y+(l.y-i.y)*n},i]})(e.points).map(e=>({x:cN(e.x),y:cN(e.y)}));return{type:"arrow",id:e.id,edgeId:e.id,sourceNodeId:`gantt:task:${e.from}`,targetNodeId:`gantt:task:${e.to}`,points:[t,...a],strokeColor:"#5c5345",strokeWidth:1,roughness:0,endArrowhead:"triangle"}}))A.push(e,"front");let eb=e=>{let t="top"===e?"":"-bottom",a="top"===e?-22:b,s="top"===e?a-22:a+22;_.cells.forEach((e,s)=>{let i=cZ(e.label,12);A.text(`gantt:tick${t}:${s}`,i,(B(e.start)+B(e.end))/2-i.width/2,a+(22-i.height)/2,12,cT,"center")}),_.bands.forEach((e,a)=>{let i,l=B(e.end)-B(e.start)-8,o=((i=/^([A-Z][a-z]{2}) \d{4}$/u.exec(e.label))?[e.label,i[1]]:/^\d{4}$/u.test(e.label)?[e.label,`’${e.label.slice(2)}`]:[e.label]).map(e=>cZ(e,13)).find(e=>e.width<=l);o&&A.text(`gantt:band${t}:${a}`,o,(B(e.start)+B(e.end))/2-o.width/2,s+(22-o.height)/2,13,cX,"center"),a>0&&A.line(`gantt:band-edge${t}:${a}`,[{x:B(e.start),y:s+3},{x:B(e.start),y:s+22-3}],{strokeColor:cY})}),A.line(`gantt:axis${t}`,[{x:B(_.start),y:"top"===e?0:b},{x:S,y:"top"===e?0:b}],{strokeColor:"#8c826f"})},ek=(d=A.elements.length,eb("top"),A.elements.length-d),eM=-44;if(void 0!==O){let e=cZ(v.today??"Today",12);eM-=18,A.text("gantt:today-label",e,Math.min(Math.max(O-e.width/2,B(_.start)),Math.max(B(_.start),S-e.width)),eM+(18-e.height)/2,12,c$,"center")}let eC=cj(e.title,Math.max(S-z,360),20);A.text("gantt:title",eC,z,eM-14-eC.height,20,cX,"left");let ez=new Set([_.start,_.end,..._.bands.map(e=>e.start)]),e_=[..._.cells.map(e=>e.start),_.end],eL=k>=16,eB=[!0,!1].flatMap(e=>[{grid:e_,minor:!0,bottom:eL},{grid:e_,minor:!1,bottom:eL},{grid:e_,minor:!1,bottom:!1},{grid:e_.filter(e=>ez.has(e)),minor:!1,bottom:eL},{grid:e_.filter(e=>ez.has(e)),minor:!1,bottom:!1},{grid:[_.start,_.end],minor:!1,bottom:!1}].map(t=>({...t,rowRules:e}))),eS=e=>{let t=e.bottom?b+22:b,a=(e,t,a,s,i)=>({type:"line",id:e,points:[{x:cN(t),y:cN(a)},{x:cN(t),y:cN(s)}],roughness:0,strokeWidth:1,...i});return[...e.rowRules?[...w.slice(1).map(e=>e.top),b].map((e,t)=>({type:"line",id:`gantt:row-rule:${t}`,points:[{x:cN(z),y:cN(e)},{x:cN(S),y:cN(e)}],roughness:0,strokeWidth:1,strokeColor:"#ebe4d8"})):[],...e.minor?_.minor.map(e=>a(`gantt:minor:${tl(e)}`,B(e),0,b,{strokeColor:"#f0ebe1"})):[],...e.grid.map(e=>a(`gantt:grid:${tl(e)}`,B(e),-22,t,{strokeColor:ez.has(e)?cY:"#e6dfd2"})),...void 0===O?[]:[a("gantt:today",O,eM+18,t,{strokeColor:c$,strokeStyle:"dashed"})]]},eA=[...V.values()].map(e=>({left:e.left-5,right:e.right+5,top:e.top-1,bottom:e.bottom+1})),eP=e=>e?[...A.textBoxes,...eA]:A.textBoxes,eV=e=>"gantt:today"===e,[eH,eq]=[!0,!1].flatMap(e=>eB.map(t=>[t,e])).find(([e,t])=>{let a=eS(e),s=new Map([...nj(a,A.textBoxes,e=>!eV(e)),...nj(a,eP(t),eV)]),i=a.reduce((e,t)=>e+(s.get(t.id)?.length??1),0);return A.elements.length+i+(e.bottom?ek:0)<=aU.maxElements})??[eB.at(-1),!1];for(let e of(eH.bottom&&eb("bottom"),eS(eH)))A.push(e,"gantt:today"===e.id?"middle":"back");A.breakRulesUnderText(e=>e.startsWith("gantt:grid:")||e.startsWith("gantt:minor:")||e.startsWith("gantt:row-rule:")||e.startsWith("gantt:axis")||e.startsWith("gantt:band-edge")),A.breakRulesUnderText(eV,eP(eq));let eF=A.bounds(),eI=40-eF.left,eE=40-eF.top,eO=e=>({x:cN(e.x+eI),y:cN(e.y+eE)}),eU=A.elements.map(e=>{if("line"===e.type){let[t,a,...s]=e.points.map(eO);return{...e,points:[t,a,...s]}}if("arrow"===e.type){let[t,...a]=e.points.map(eO);return{...e,points:[t,...a]}}return{...e,x:cN(e.x+eI),y:cN(e.y+eE)}});return{scene:{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:Math.ceil(eF.right-eF.left+80),height:Math.ceil(eF.bottom-eF.top+80),accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:eU,layers:[],layouts:[],zOrder:A.zOrder()},work:{layouts:1,placements:et,expansions:J-K.remaining+48e3-ef.remaining+Q-ee.remaining,corridors:ea,conflicts:X.reduce((e,t,a)=>e+X.reduce((e,s,i)=>i===a?e:e+c1(t,s,er(a,i),!0),0),0)}}}let c6="timeline-marker",c7=6,c8="#4c4639",c9="#c0392b",de=[{stroke:"",ink:"#6a4e5c",wash:"#efe6ec"},{stroke:"#1f44c9",ink:"#1a39a8",wash:"#e6eafb"},{stroke:"#1c7a4d",ink:"#15613c",wash:"#def0e5"},{stroke:"#9a6a1f",ink:"#7a5216",wash:"#f6e8cf"}];function dt(e,t,a,s){let i=function(e,t){let a=e=>e.split("\n").length,s=aO(e,200,t);if(1===a(s))return s;let i=t,l=200;for(;l-i>1;){let o=Math.floor((i+l)/2);a(aO(e,o,t))<=a(s)?l=o:i=o}return aO(e,l,t)}(t,a);return{id:e,text:i,fontSize:a,color:s,width:Math.ceil(Math.max(aq(i,a),aF(i,a,200))),height:Math.ceil(i.split("\n").length*a*1.35)}}let da=[{lookahead:!0,coverPenalty:0},{lookahead:!0,coverPenalty:80},{lookahead:!1,coverPenalty:0},{lookahead:!1,coverPenalty:240}];function ds(e){return e.span?6:("milestone"===e.event.kind?18:12)/2}let di=[{fontSize:20,textWidth:160,padX:0,padY:0,strokeWidth:2},{fontSize:16,textWidth:180,padX:16,padY:11,strokeWidth:2},{fontSize:14,textWidth:150,padX:12,padY:9,strokeWidth:1}];function dl(e){return di[Math.min(e,di.length-1)]}function dr(e,t,a){return{x0:e.x0+t,x1:e.x1+t,y0:e.y0+a,y1:e.y1+a}}function dn(e,t,a){return{boxes:e,places:t,folded:a,top:Math.min(...e.map(e=>e.y0)),bottom:Math.max(...e.map(e=>e.y1)),outer:Math.max(...e.map(e=>e.x1))}}function dc(e,t){return 1===e.places.size&&1===t.places.size?14:28}function dd(e,t=0){return e.reduce((a,s,i)=>a+(s.bottom-s.top)+(0===i?0:dc(e[i-1],s)+t),0)}function dp(e){let t=e.flatMap(e=>[e.x,e.x+e.topic.width]),a=e.flatMap(e=>[e.y,e.y+e.topic.height]);return(Math.max(...t)-Math.min(...t)+40)/(Math.max(...a)-Math.min(...a)+40)}function dh(e){return Math.round(100*e)/100}function dg(e){let[t,,,a]=e;return .5>Math.abs(a.y-t.y)?[{x:dh(t.x),y:dh(t.y)},{x:dh(a.x),y:dh(a.y)}]:aL(e)}function du(e,t){return{x:1===t?e.x:e.x+e.width,y:e.y+e.height/2}}let df={circle:24,bucket:28,cylinder:28,diamond:20,document:28,ellipse:24,pipe:28,polygon:28,rectangle:28},dm={database:"cylinder",queue:"pipe",document:"document",storage:"bucket"},dv={initial:20,final:28};function dy(e,t){let a=Math.max(e.width,e.height,t);return{...e,width:a,height:a}}function dw(e){return void 0===e.kind?void 0:dv[e.kind]}function dx(e){return"decision"===e||"choice"===e}function db(e,t=184,a=1116){let s,i,l,o,r,n,c=function(e){if(void 0!==e.shape)return dm[e.shape];let t=e.kind?.toLowerCase();return"start"===t||"end"===t?"ellipse":"initial"===t||"final"===t?"circle":dx(t)?"diamond":"rectangle"}(e),d=dw(e);if(void 0!==d||"choice"===e.kind&&!e.label){let t=d??44;return{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},shape:c,x:0,y:0,width:t,height:t,label:""}}let p=(i=(s=aE(e.label,"diamond"===c?744:a)).split("\n"),l=aq(s,14),o=Math.ceil(14*i.length*1.35),r=Math.ceil(l+36),n=Math.ceil(o+28),{text:s,textHeight:o,textWidth:l,width:r,height:n}),h=e.icon?{slug:e.icon.slug,size:df[c]}:void 0,g=aY(c)?a$[c]:0,u="diamond"===c?32:"ellipse"===c?20:"pipe"===c?4*g:0,f="diamond"===c?32:"cylinder"===c||"document"===c||"bucket"===c?3*g:0,m=h||"diamond"===c||g>0?function(e,t,a){let s=2*aX.boundTextPadding,i=t.textHeight+a6(a),l="diamond"===e?2:"ellipse"===e||"circle"===e?Math.SQRT2:1,o=Math.ceil((t.textWidth+s)*l),r=Math.ceil((i+s)*l);for(;a4({height:r,shape:e,width:o}).width<t.textWidth;)o+=1;for(;a4({height:r,shape:e,width:o}).height<i;)r+=1;return{width:o,height:r}}(c,p,h):{height:0,width:0},[v,y]="state"===e.kind?[136,56]:[t,72];return{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},...h?{icon:h}:{},shape:c,x:0,y:0,width:Math.max(v,p.width+u,m.width),height:h?Math.max(y,m.height):Math.max(y,p.height+f,m.height),label:p.text}}function dk(e){let t=new Map,a=new Map;for(let s of e)t.set(s.target,[...t.get(s.target)??[],s]),a.set(s.source,[...a.get(s.source)??[],s]);return{incoming:t,outgoing:a}}function dM(e){return new Map(e.map((e,t)=>[e.id,t]))}function dC(e,t,a){let s=new Map,i=new Set;function l(e){for(let t of(s.set(e,"visiting"),a.get(e)??[])){let e=s.get(t.target);if("visiting"===e){i.add(t.id);continue}e||l(t.target)}s.set(e,"visited")}let o=e.nodes.find(e=>0===(t.get(e.id)??[]).length)??e.nodes[0];for(let t of(o&&l(o.id),e.nodes))s.has(t.id)||l(t.id);return i}let dz=new WeakMap;function d_(e){let t=dz.get(e);if(t||(dq(e),t=dz.get(e)))return t;let a=dk(e.edges);return t=dC(e,a.incoming,a.outgoing),dz.set(e,t),t}let dL=new WeakMap,dB="\0group:",dS=sO.fontSize;function dA(e,t){let a=[];for(let s=t;void 0!==s;s=e.parentOf.get(s))a.push(s);return a}function dP(e,t,a){let s=new Set(dA(e,e.groupOf.get(a)));return dA(e,e.groupOf.get(t)).find(e=>s.has(e))}let dV=new WeakMap;function dH(e){return`${dB}${e}`}function dq(e){let t=dV.get(e);if(void 0!==t)return t??void 0;let a=new Map((e.groups??[]).flatMap(e=>void 0===e.parent?[]:[[e.id,e.parent]])),s=new Set;for(let t of e.nodes)for(let e=t.group;void 0!==e&&!s.has(e);e=a.get(e))s.add(e);let i=(e.groups??[]).filter(e=>s.has(e.id));if(0===i.length)return void dV.set(e,null);let l=new Set(i.map(e=>e.id)),o=new Map([...a].filter(([e,t])=>l.has(e)&&l.has(t))),r=i.some(e=>void 0!==e.parent||void 0!==e.kind),n=new Map(e.nodes.flatMap(e=>void 0!==e.group&&l.has(e.group)?[[e.id,e.group]]:[])),c=new Set(e.nodes.map(e=>e.id)),d=new Set(e.edges.flatMap(e=>[e.source,e.target].filter(e=>!c.has(e)&&l.has(e)))),p=e=>{let t=[];for(let a=d.has(e)?e:n.get(e);void 0!==a;a=o.get(a))t.push(a);return t},h=(e,t)=>{let a=p(t),s=void 0===e?a.length:a.indexOf(e);if(!(s<0||0===s&&d.has(t)))return 0===s?t:dH(a[s-1])},g=(e,t)=>({id:t,label:e.label,kind:"process",metadata:{}}),u=dk(e.edges),f=dC(e,u.incoming,u.outgoing),m=new Set(e.edges.flatMap(e=>e.source===e.target?[e.id]:[])),v=i.map(t=>{let a=i.filter(e=>o.get(e.id)===t.id),s=e.edges.flatMap(e=>{let[a,s]=[h(t.id,e.source),h(t.id,e.target)];return void 0===a||void 0===s||a===s&&a!==e.source?[]:[a===e.source&&s===e.target?e:{...e,source:a,target:s}]}),l=[];for(let s of e.nodes){let e=h(t.id,s.id);if(void 0===e||l.some(t=>t.id===e))continue;let i=a.find(t=>dH(t.id)===e);l.push(i?g(i,e):s)}let n={...e,groups:[],nodes:l,edges:s},c={...n,layout:{...e.layout,direction:dY[e.layout.direction]}},d=new Set(s.flatMap(e=>f.has(e.id)?[e.id]:[]));if(a.length>0){let e={...n,edges:s.filter(e=>!d.has(e.id))},t=dk(e.edges);for(let a of dC(e,t.incoming,t.outgoing))d.add(a)}for(let e of(dz.set(n,d),dz.set(c,d),d))m.add(e);if(r){let a=function(e,t,a,s){let i=e=>void 0!==s(e),l=new Map;for(let t of e.edges)i(t.source)||i(t.target)||l.set(t.source,[...l.get(t.source)??[],t.target]);let o=e=>{let t=new Set([e]);for(let e of t)for(let a of l.get(e)??[])t.add(a);return t},r=new Map;for(let e of t.edges)a.has(e.id)||r.set(e.source,[...r.get(e.source)??[],e.target]);let n=(e,t)=>{let a=new Set([e]);for(let e of a)for(let t of r.get(e)??[])a.add(t);return a.has(t)},c=[];for(let t of e.edges){if(!i(t.source)||i(t.target))continue;let a=o(t.target);for(let l of e.edges){if(i(l.source)||!i(l.target)||!a.has(l.source))continue;let[e,o]=[s(t.source),s(l.target)];!(e===o||c.some(([t,a])=>t===e&&a===o))&&(n(o,e)||(c.push([e,o]),r.set(e,[...r.get(e)??[],o])))}}return c}(e,n,d,e=>h(t.id,e));a.length>0&&(dL.set(n,a),dL.set(c,a))}let p=new Set(e.edges.flatMap(e=>{let[a,s]=[h(t.id,e.source),h(t.id,e.target)];return void 0===a&&void 0!==s?[s]:void 0===s&&void 0!==a?[a]:[]}));return{across:c,children:a.map(e=>e.id),crossing:p,diagram:n,group:t}}),y=[],w=new Set;for(let t of e.nodes){let e=h(void 0,t.id);if(w.has(e))continue;w.add(e);let a=p(t.id).at(-1);y.push(void 0===a?t:g(i.find(e=>e.id===a),e))}let x=e=>h(void 0,e)??e,b=e.edges.filter(e=>x(e.source)!==x(e.target)),k={...e,groups:[],nodes:y,edges:b.map(e=>({...e,source:x(e.source),target:x(e.target)}))},M=dk(k.edges),C=dC(k,M.incoming,M.outgoing);for(let e of(dz.set(k,C),C))m.add(e);dz.set(e,m);let z={composites:d,crossEdges:b,groupOf:n,groups:v,parentOf:o,top:k,zoned:r};return dV.set(e,z),z}function dF(e,t,a){let s=dM(e.nodes),i=new Map(e.nodes.map(e=>[e.id,0])),l=new Map(e.nodes.map(e=>[e.id,0]));for(let t of e.edges)a.has(t.id)||i.set(t.target,(i.get(t.target)??0)+1);let o=[];for(let t of e.nodes)(i.get(t.id)??0)===0&&o.push(t.id);let r=new Set;for(let e=0;e<o.length;e+=1){let n=o[e];if(!n||r.has(n))continue;r.add(n);let c=l.get(n)??0;for(let r of t.outgoing.get(n)??[]){if(a.has(r.id))continue;l.set(r.target,Math.max(l.get(r.target)??0,c+1));let t=(i.get(r.target)??0)-1;i.set(r.target,t),0===t&&function(e,t,a,s){let i=a.get(t)??Number.MAX_SAFE_INTEGER,l=e.findIndex((e,t)=>t>s&&(a.get(e)??Number.MAX_SAFE_INTEGER)>i);-1===l?e.push(t):e.splice(l,0,t)}(o,r.target,s,e)}}for(let s of e.nodes)!function e(s){if(r.has(s))return l.get(s)??0;let i=0;for(let l of t.incoming.get(s)??[])a.has(l.id)||(i=Math.max(i,e(l.source)+1));return r.add(s),l.set(s,i),i}(s.id);return l}let dI=new WeakMap,dE={TB:"bottom",BT:"top",LR:"right",RL:"left"};function dO(e,t,a,s,i=184,l=1116){return new Map(e.nodes.map(e=>{let o=db(e,i,l),r=t.get(e.id),n={...o,width:Math.max(o.width,r?.width??0),height:Math.max(o.height,r?.height??0)},c=(a.outgoing.get(e.id)??[]).filter(t=>t.target!==e.id),d=(a.incoming.get(e.id)??[]).filter(t=>t.source!==e.id).length+c.length,p=!dx(e.kind)&&c.length>1&&c.some(e=>e.label)?Math.max(18,...c.map(e=>{let t=p0(e.label??"");return(s?t.width:t.height)+24})):18,h=c.filter(e=>e.label),g=void 0!==dw(e)?0:"state"===e.kind?32+h.reduce((e,t)=>{let a=p0(t.label);return e+(s?a.width:a.height)+24},0)+Math.max(0,d-h.length-1)*pf:32+Math.max(0,d-1)*p;return[e.id,"choice"!==e.kind||e.label?{...n,...s?{width:Math.max(n.width,g)}:{height:Math.max(n.height,g)}}:dy(n,g)]}))}function dU(e,t,a,s=!1){let i="TB"===e.layout.direction||"BT"===e.layout.direction,[l,o]=i?["left","right"]:["top","bottom"],r=(e,t)=>Math.max(112,(a.get(pc(e.nodeId,o))??0)+(a.get(pc(t.nodeId,l))??0)+18),n=dk(e.edges),c=dO(e,t,n,i),d=d_(e),p=function(e,t,a){let s=dL.get(e);if(!s)return t;for(let i=!0,l=0;i&&l<=e.nodes.length;l+=1){for(let[e,a]of(i=!1,s))t.get(a)<t.get(e)&&(t.set(a,t.get(e)),i=!0);for(let s of e.edges)!a.has(s.id)&&s.source!==s.target&&t.get(s.target)<t.get(s.source)+1&&(t.set(s.target,t.get(s.source)+1),i=!0)}return t}(e,dF(e,n,d),d),h=Array.from((function(e,t,a,s,i,l=!1){var o,r,n,c;let d,p,h=dM(e.nodes),g=new Map;for(let s of e.nodes){let e=a.get(s.id)??0,i=t.get(s.id);i&&g.set(e,[...g.get(e)??[],i])}for(let e=0;e<4;e+=1)for(let e of Array.from(g.keys()).sort((e,t)=>e-t)){let t=g.get(e);if(!t||t.length<2)continue;let a=new Map;(g.get(e-1)??[]).forEach((e,t)=>{a.set(e.nodeId,t)});let l=new Map;(g.get(e+1)??[]).forEach((e,t)=>{l.set(e.nodeId,t)});let o=e=>{let t=[...(s.incoming.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>a.get(e.source)).filter(e=>void 0!==e),...(s.outgoing.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>l.get(e.target)).filter(e=>void 0!==e)];return 0===t.length?h.get(e.nodeId)??Number.MAX_SAFE_INTEGER:t.reduce((e,t)=>e+t,0)/t.length};g.set(e,[...t].sort((e,t)=>{let a=o(e)-o(t);return Math.abs(a)>.001?a:(h.get(e.nodeId)??Number.MAX_SAFE_INTEGER)-(h.get(t.nodeId)??Number.MAX_SAFE_INTEGER)}))}return l?(o=g,r=e,n=a,c=i,(d=dI.get(r))||(d=function(e,t,a,s){let i=new Map,l=new Set,o=(e,t,a)=>i.set(a,[...i.get(a)??[],[e,t]]);for(let i of t.edges){let[t,r]=s.has(i.id)?[i.target,i.source]:[i.source,i.target],[n,c]=(a.get(t)??0)<=(a.get(r)??0)?[t,r]:[r,t],d=a.get(n)??0,p=a.get(c)??0;if(d===p)continue;let h=n;for(let t=d+1;t<p;t+=1){let a=`\0${i.id}\0${t}`;l.add(a);let s=e.get(t-1),r=e.get(t);r.splice(Math.round((s.indexOf(h)+.5)/s.length*r.length),0,a),o(h,a,t-1),h=a}o(h,c,p-1)}let r=new Map,n=t=>e.get(t)?.forEach((e,t)=>r.set(e,t)),c=[...e.keys()].sort((e,t)=>e-t);c.forEach(n);let d=e=>{let t=i.get(e)??[],a=0;for(let[e,[s,i]]of t.entries())for(let[l,o]of t.slice(e+1))(r.get(s)-r.get(l))*(r.get(i)-r.get(o))<0&&(a+=1);return a},p=()=>c.reduce((e,t)=>e+d(t),0),h=p(),g=()=>new Map([...e].map(([e,t])=>[e,t.filter(e=>!l.has(e))])),u=g();if(0===h)return u;let f=new Map;for(let e of i.values())for(let[t,a]of e){let e=f.get(t)??{above:[],below:[]};e.below.push(a),f.set(t,e);let s=f.get(a)??{above:[],below:[]};s.above.push(t),f.set(a,s)}let m={crossings:h,order:u};for(let t=0;t<8&&m.crossings>0;t+=1){let a=t%2==0;for(let t of a?c.slice(1):c.slice(0,-1).reverse()){let s=e.get(t),i=new Map(s.map((e,t)=>{let s=(a?f.get(e)?.above:f.get(e)?.below)??[];return[e,s.length>0?s.reduce((e,t)=>e+r.get(t),0)/s.length:t]}));s.sort((e,t)=>i.get(e)-i.get(t)),n(t)}for(let t=!0;t;)for(let a of(t=!1,c)){let s=e.get(a);for(let e=0;e+1<s.length;e+=1){let i=d(a-1)+d(a);[s[e],s[e+1]]=[s[e+1],s[e]],n(a),d(a-1)+d(a)<i?t=!0:([s[e],s[e+1]]=[s[e+1],s[e]],n(a))}}let s=p();s<m.crossings&&(m={crossings:s,order:g()})}return m.order}(new Map([...o].map(([e,t])=>[e,t.map(e=>e.nodeId)])),r,n,c),dI.set(r,d)),p=new Map([...o.values()].flat().map(e=>[e.nodeId,e])),new Map([...o.keys()].map(e=>[e,(d.get(e)??[]).flatMap(e=>p.has(e)?[p.get(e)]:[])]))):g})(e,c,p,n,d,s).entries()).sort(([e],[t])=>e-t).map(([e,t])=>({breadth:t.reduce((e,a,s)=>e+(i?a.width:a.height)+(s>0?r(t[s-1],a):0),0),depth:Math.max(...t.map(e=>i?e.height:e.width)),rank:e,shapes:t})),g=dE[e.layout.direction],u=(e,t)=>Math.max(0,...e.map(e=>a.get(pc(e.nodeId,t))??0));return{feedbackEdges:d,gapAfter:h.map((t,s)=>{let l=i?0:Math.max(0,...e.edges.filter(e=>t.shapes.some(t=>t.nodeId===e.source)&&e.label&&e.source!==e.target).map(e=>p0(e.label,dx(c.get(e.source)?.kind)).width+16+72)),o=h[s+1];return Math.max(96,l,o&&a.size>0?u(t.shapes,g)+u(o.shapes,pm[g])+18:0)}),gapBetween:r,highSide:o,lowSide:l,rankByNodeId:p,rankMetrics:h,reachOf:u,vertical:i}}let dX={bandOf:new Map,continuations:new Set},dT={crossingRepair:!1,reorder:!1,wrap:dX},dY={TB:"LR",BT:"LR",LR:"TB",RL:"TB"};function d$(e,t){let[a,s]=e>t?[e,t]:[t,e];return(a+40)/(s+40)}function dG(e,t,a=0,s){let i;if("orthogonal"!==e.layout.edgeRouting||dq(e)||dW(e))return dX;let{feedbackEdges:l,gapAfter:o,rankByNodeId:r,rankMetrics:n}=dU(e,s?.sizes??new Map,new Map,t),c="TB"===e.layout.direction||"BT"===e.layout.direction,d=(e,t)=>n.slice(e,t+1).reduce((e,t)=>e+t.depth,0)+o.slice(e,t).reduce((e,t)=>e+t,0),p=(e,t)=>Math.max(...n.slice(e,t+1).map(e=>e.breadth)),h=n.length-1,g=d$(d(0,h),p(0,h)),u=e=>Math.max(...n[e].shapes.map(e=>s?.weights.get(e.nodeId)??1)),f=(e,t)=>{let a=0;for(let s=e;s<=t;s+=1)a+=u(s);return a};if(5>f(0,h)||d(0,h)<=p(0,h))return dX;let m=new Map(e.nodes.map(e=>[e.id,e.kind])),v=e=>r.get(e)??0,y=new Map;for(let[t,a]of n.entries()){let i=e.edges.filter(e=>Math.min(v(e.source),v(e.target))<=a.rank&&Math.max(v(e.source),v(e.target))>a.rank),[o]=i;(s?i.length>=1:1===i.length)&&o&&i.every(e=>!l.has(e.id)&&v(e.source)===a.rank&&v(e.target)===a.rank+1&&!dx(m.get(e.source)))&&y.set(t,o.id)}let w=new Map(e.edges.map(e=>[e.id,e.label])),x=(e,t)=>{let a=w.get(y.get(t)??""),s=a?p0(a):void 0,i=t===h?0:Math.max(36,s?c?Math.max(40,s.height+24):s.width+16:0);return d(e,t)+36*(e>0)+i},b=[...y.keys(),h].sort((e,t)=>e-t),k=s?1:2,M=e=>{let t,s=(i,l)=>{if(i.length===e-1){if(f(l+1,h)<k)return;let e=[...i,h],s=e.map((t,a)=>x(0===a?0:e[a-1]+1,t)),o=Math.max(...s);if(Math.min(...s)<a*o)return;let r=s.reduce((e,t)=>e+t**2,0);(!t||o<t.longest||o===t.longest&&r<t.squares)&&(t={ends:e,longest:o,squares:r});return}for(let e of b)e!==h&&e>l&&f(l+1,e)>=k&&s([...i,e],e)};return s([],-1),t},[C,z]=s?[s.bands,Math.min(s.bands,b.length)]:[2,Math.min(6,b.length)];for(let e=C;e<=z;e+=1){let t=new Map;for(let e of b)f(0,e)>=k&&e<h&&t.set(e,{ends:[e],longest:x(0,e),squares:x(0,e)**2});for(let a=2;a<=e;a+=1){let s=new Map;for(let i of b)if(a===e?i===h:i!==h)for(let[e,a]of[...t].reverse()){if(i<=e||f(e+1,i)<k)continue;let t=x(e+1,i),l={ends:[...a.ends,i],longest:Math.max(a.longest,t),squares:a.squares+t**2},o=s.get(i);(!o||l.longest<o.longest||l.longest===o.longest&&l.squares<o.squares)&&s.set(i,l)}t=s}let s=a>0?M(e):t.get(h);if(!s)continue;let l=[0,...s.ends.slice(0,-1).map(e=>e+1)].reduce((e,t,a)=>e+p(t,s.ends[a]),0)+(e-1)*144,o=d$(s.longest,l);if((!i||o<i.aspect)&&(i={aspect:o,ends:s.ends}),o<=2)break}if(!i||i.aspect>=g)return dX;let _=new Map,L=0;for(let[e,t]of n.entries()){for(let e of t.shapes)_.set(e.nodeId,L);i.ends.includes(e)&&e!==h&&(L+=1)}return{bandOf:_,continuations:new Set(i.ends.filter(e=>e!==h).map(e=>y.get(e))),...s?{under:!0}:{}}}function dD(e,t=new Map,a=new Map,{reorder:s,wrap:i}=dT,l=new Map){let{gapAfter:o,gapBetween:r,highSide:n,lowSide:c,rankMetrics:d,reachOf:p,vertical:h}=dU(e,t,a,s),g=[];for(let[e,t]of d.entries()){let a=i.bandOf.get(t.shapes[0].nodeId)??0;(g[a]??=[]).push({index:e,metric:t})}let u=[],f=i.under?function(e,t,a,s){let i=new Map,l=t.map(e=>{let t=0;for(let{index:s,metric:l}of e){for(let e of l.shapes)i.set(e.nodeId,t+l.depth);t+=l.depth+a[s]}return t-a[e.at(-1).index]}),o=Math.max(...l),r=[0];for(let a=1;a<t.length;a+=1){let t=e.edges.flatMap(e=>s.get(e.source)===a-1&&s.get(e.target)===a?[i.get(e.source)+r[a-1]-l[a]]:[]);r.push(Math.max(0,Math.min(Math.max(0,...t),o-l[a])))}return r}(e,g,o,i.bandOf):[],m=48;for(let[e,t]of g.entries()){let a=Math.max(...t.map(({metric:e})=>e.breadth)),s=48+(f[e]??0);for(let{index:e,metric:i}of t){let[t]=1===i.shapes.length?i.shapes:[],n=m+Math.max(0,a-i.breadth)/2-(t?l.get(t.nodeId)??0:0);for(let[e,t]of i.shapes.entries()){let a=i.shapes[e+1];h?(u.push({...t,x:n,y:s+Math.max(0,i.depth-t.height)/2}),n+=t.width):(u.push({...t,x:s+Math.max(0,i.depth-t.width)/2,y:n}),n+=t.height),a&&(n+=r(t,a))}s+=i.depth+o[e]}let i=g[e+1];i&&(m+=a+Math.max(144,p(t.flatMap(({metric:e})=>e.shapes),n)+p(i.flatMap(({metric:e})=>e.shapes),c)+72))}if("BT"===e.layout.direction){let e=Math.max(...u.map(e=>e.y+e.height));return u.map(t=>({...t,y:48+e-t.y-t.height}))}if("RL"===e.layout.direction){let e=Math.max(...u.map(e=>e.x+e.width));return u.map(t=>({...t,x:48+e-t.x-t.width}))}return u}function dR(e,t=new Map,a=new Map,s=dT,i=new Map){if(dW(e))return function(e,t,a,s=dX){let i=e.lanes,{direction:l}=e.layout,{along:o,across:r,backSide:n,breadth:c,columnCount:d,columnOf:p,columns:h,content:g,depth:u,depthOf:f,forwardSide:m,gapAfter:v,headerSize:y,laneIndex:w,laneOf:x,offset:b,padding:k,poolBreadth:M,reach:C,shapes:z,vertical:_,wrapped:L}=dJ(e,t,a),B=p.map(e=>s.bandOf.get(e[0]?.nodeId??"")??0),S=Math.max(0,...B)+1,A=Array.from({length:S},(e,t)=>t),P=Math.max(48,...A.map(e=>C(p[B.indexOf(e)]??[],n)+dN)),V=Math.max(48,...A.map(e=>C(p[B.lastIndexOf(e)]??[],m)+dN)),H="RL"===l||"BT"===l,[q,F]=H?[V,P]:[P,V],I=48+y+q,E=[],O=I,U=0;for(let[e,t]of u.entries())e>0&&B[e]!==B[e-1]&&(O=I),E.push(O),O+=t,U=Math.max(U,O-I),e<d-1&&B[e+1]===B[e]&&(O+=v[e]);let X=I+U,T=X+F,Y=A.map(t=>[...s.continuations].filter(a=>{let i=e.edges.find(e=>e.id===a);return void 0!==i&&s.bandOf.get(i.source)===t})),$=[];for(let e of(O=48,A))$.push(O),O+=M+dK(Y[e].length);let G=(e,t)=>$[e]+c.slice(0,t).reduce((e,t)=>e+t,0),D=e.nodes.map(e=>{let t=z.get(e.id),a=w.get(e.lane),s=h.get(e.id),i=E[s]+(u[s]-t[f])/2,l=H?I+X-i-t[f]:i,n=G(B[s],a)+k[a].low+(c[a]-k[a].low-k[a].high-g[a])/2+b.get(e.id);return{...t,[o]:l,[r]:n}}),R=(e,t,a,s)=>_?{x:a,y:e,width:s,height:t}:{x:e,y:a,width:t,height:s},Z=function(e,t,a){let s=new Map;for(let i of e){let e=`lane:${encodeURIComponent(i.id)}`,l=e=>Array.from({length:t},(t,a)=>0===a?e:`${e}:${a+1}`).some(e=>a.has(e)||a.has(`${e}:header`)),o=e;for(let t=1;l(o);t+=1)o=`${e}@${t}`;s.set(i.id,o)}return s}(i,S,new Set(e.nodes.map(e=>e.id))),j=A.flatMap(e=>i.map((t,a)=>({box:R(48,T-48,G(e,a),c[a]),elementId:0===e?Z.get(t.id):`${Z.get(t.id)}:${e+1}`,header:R(48,y,G(e,a),c[a]),id:t.id,label:t.label,pool:e,text:L[a].text}))),N=A.map(e=>R(48,T-48,$[e],M));return{lanes:{continuations:s.continuations,frames:j,laneOf:x,pool:dZ(N),pools:N,vertical:_},nodes:D}}(e,t,a,s.wrap);let l=dq(e);return l?function(e,t,a,s,i,l){let o="TB"===e.layout.direction||"BT"===e.layout.direction,{zoned:r}=t,n=28*!r,c=new Map(a),d=new Map(s),p=new Map(t.groups.map(e=>[e.group.id,e])),h=new Map,g=new Map,u=i.groupsAcross&&!r?new Set(t.groups.map(e=>e.group.id)):new Set,f=({across:e,children:a,crossing:m,diagram:v,group:y})=>{for(let e of a)f(p.get(e));let w=dD(u.has(y.id)?e:v,c,d,{...dT,reorder:i.reorder,wrap:i.zoneWraps?.get(y.id)??dX},g),x=dZ(w),b=(e,t)=>"top"===t?e.y-x.y:"bottom"===t?x.y+x.height-e.y-e.height:"left"===t?e.x-x.x:x.x+x.width-e.x-e.width,k=e=>Math.max(r?24:40,...w.map(t=>(d.get(pc(t.nodeId,e))??0)-b(t,e)+18))+(l.get(y.id)??0),M=sY(y.label),C=r?12+M+sO.clearance:M+2*sO.clearance,z=w.filter(e=>m.has(e.nodeId)&&.01>=b(e,"top")).map(e=>e.x-x.x+e.width/2-36),_={top:k("top")+36*!!r,bottom:k("bottom"),right:k("right"),left:o&&z.length>0?Math.max(k("left"),C+18-Math.min(...z)):k("left")},L={content:x,group:y,height:x.height+_.top+_.bottom,nodes:w,padding:_,width:Math.max(x.width+_.left+_.right,r?C+12:M+2*sO.clearance+16,(s.get(pc(y.id,"top"))??0)>0&&t.composites.has(y.id)?M+2*sO.clearance+36+16+t.crossEdges.filter(e=>e.source===y.id||e.target===y.id).length*pf:0)};h.set(y.id,L);let B=dH(y.id);c.set(B,{width:L.width,height:L.height+n}),r&&g.set(B,o?(L.padding.left-L.padding.right)/2:(L.padding.top-L.padding.bottom)/2);let S=(L.width-L.content.width-L.padding.left-L.padding.right)/2,A=(e,t)=>"top"===t?e.y-L.content.y+L.padding.top+n:"bottom"===t?L.content.y+L.content.height-e.y-e.height+L.padding.bottom:"left"===t?e.x-L.content.x+L.padding.left+S:L.content.x+L.content.width-e.x-e.width+L.padding.right+S;for(let e of["top","right","bottom","left"]){let a=Math.max(0,t.composites.has(y.id)?(s.get(pc(y.id,e))??0)-("top"===e?n:0):0,...w.map(t=>(d.get(pc(t.nodeId,e))??0)-A(t,e)));a>0&&d.set(pc(B,e),a)}};for(let e of t.groups)t.parentOf.has(e.group.id)||f(e);let m=i.zoneWraps?.get("")??dX,v=dD(t.top,c,d,{...i,wrap:m},g),y=new Map;for(let e of v)e.nodeId.startsWith(dB)||y.set(e.nodeId,{nodes:[e]});let w=new Map,x=(e,t,a)=>{let s=h.get(e),i={x:t.x,y:t.y+n,width:t.width,height:t.height-n};w.set(e,i);let l=i.x+s.padding.left+(i.width-s.content.width-s.padding.left-s.padding.right)/2-s.content.x,o=i.y+s.padding.top+(i.height-s.content.height-s.padding.top-s.padding.bottom)/2-s.content.y;for(let e of s.nodes){let t={...e,x:e.x+l,y:e.y+o};e.nodeId.startsWith(dB)?x(e.nodeId.slice(dB.length),t,a):a.push(t)}return i};for(let e of t.groups){if(t.parentOf.has(e.group.id))continue;let a=dH(e.group.id),s=v.find(e=>e.nodeId===a),i=[],l=x(e.group.id,s,i),o=t.groups.flatMap(({group:a})=>a.id!==e.group.id&&dj(t,a.id).at(-1)===e.group.id?[a.id]:[]);y.set(a,{frame:l,...o.length>0?{nested:new Map(o.map(e=>[e,w.get(e)]))}:{},nodes:i})}for(let[e,a]of(function(e,t,a,s=new Map){let{crossEdges:i,top:l}=e,o=d_(l),r=dF(l,dk(l.edges),o),n=new Map;for(let e of l.nodes){let t=r.get(e.id)??0;n.set(t,[...n.get(t)??[],e.id])}let c=a?"x":"y",d=a?"width":"height",p=Math.max(0,...s.values())+1,h=e=>{let a=[...t].filter(([t])=>(s.get(t)??0)===e).map(([,e])=>e.frame??e.nodes[0]);return{start:Math.min(...a.map(e=>e[c])),end:Math.max(...a.map(e=>e[c]+e[d]))}},g=Array.from({length:p},(e,t)=>0===t?0:h(t).start-h(t-1).end),u=e=>(n.get(e)??[]).reduce((e,a)=>{let s=t.get(a);return e+(s.frame??s.nodes[0])[d]},0),f=[...n.keys()].sort((e,t)=>e-t),m=f.reduce((e,t)=>u(t)>u(e)?t:e),v=a=>{let s=e.composites.has(a)?t.get(dH(a)).frame:[...t.values()].flatMap(e=>e.nodes).find(e=>e.nodeId===a);return s[c]+s[d]/2},y=(e,a)=>{let s=t.get(e);for(let[e,t]of(s.nodes=s.nodes.map(e=>({...e,[c]:e[c]+a})),s.frame&&(s.frame={...s.frame,[c]:s.frame[c]+a}),s.nested??[]))s.nested.set(e,{...t,[c]:t[c]+a})},w=e=>s.get(n.get(e)?.[0]??"")??0,x=(e,t,a)=>{let[s]=n.get(e)??[];if(!s||1!==n.get(e).length||w(e)!==w(t))return;let c=l.edges.find(e=>!o.has(e.id)&&(a?e.target:e.source)===s&&r.get(a?e.source:e.target)===t);if(!c)return;let d=i[l.edges.indexOf(c)],[p,h]=a?[d.target,d.source]:[d.source,d.target];y(s,v(h)-v(p))},b=a=>{let s=n.get(a);if(!e.zoned||s.length<2)return;let r=e=>t.get(e).frame??t.get(e).nodes[0],p=new Map(s.map(e=>[e,l.edges.flatMap((t,a)=>{let l=i[a],[r,n]=t.source===e?[l.source,l.target]:[l.target,l.source];if(t.source!==e&&t.target!==e||s.includes(t.source===e?t.target:t.source))return[];let c=v(n);return o.has(t.id)&&t.source===e?[c,c]:[c]})])),h=[...s].sort((e,t)=>r(e)[c]-r(t)[c]),g=e=>e.reduce((e,t)=>e+t,0)/e.length,u=e=>p.get(e).length>0?g(p.get(e)):r(e)[c]+r(e)[d]/2,f=[...h].sort((e,t)=>u(e)-u(t)),m=h.slice(1).map((e,t)=>{let a=r(h[t]);return r(e)[c]-a[c]-a[d]}),w=s.flatMap(e=>p.get(e)),x=f.reduce((e,t)=>e+r(t)[d],0)+m.reduce((e,t)=>e+t,0),b=w.length>0?g(w)-x/2:r(h[0])[c];for(let[e,t]of f.entries())y(t,b-r(t)[c]),b+=r(t)[d]+(m[e]??0)};for(let e of f.filter(e=>e>m))x(e,e-1,!0),b(e);for(let e of f.filter(e=>e<m).reverse())x(e,e+1,!1),b(e);for(let e=1;e<p;e+=1){let a=h(e-1).end+g[e]-h(e).start;for(let[i]of t)(s.get(i)??0)===e&&y(i,a)}}(t,y,o,m.bandOf),y))for(let[t,s]of(a.frame&&w.set(e.slice(dB.length),a.frame),a.nested??[]))w.set(t,s);let b=[...y.values()].flatMap(e=>e.nodes),k=dM(e.nodes);b.sort((e,t)=>k.get(e.nodeId)-k.get(t.nodeId));let M=(r?[...t.groups].sort((e,a)=>dj(t,e.group.id).length-dj(t,a.group.id).length):t.groups).map(({group:e})=>{let t=w.get(e.id);return{box:t,elementId:`group:${e.id}`,id:e.id,...r&&void 0!==e.kind?{kind:e.kind}:{},label:e.label,labelBox:r?function(e,t){let{clearance:a,height:s}=sO;return{x:e.x+12-a,y:e.y+(36-s)/2-a,width:sY(t)+2*a,height:s+2*a}}(t,e.label):s$({...t,name:e.label})}});return{groups:{across:u,composites:t.composites,frames:M,groupOf:t.groupOf,parentOf:t.parentOf,zoned:r},nodes:b}}(e,l,t,a,s,i):{nodes:dD(e,t,a,s)}}function dZ(e){let t=Math.min(...e.map(e=>e.x)),a=Math.min(...e.map(e=>e.y));return{x:t,y:a,width:Math.max(...e.map(e=>e.x+e.width))-t,height:Math.max(...e.map(e=>e.y+e.height))-a}}function dj(e,t){let a=[];for(let s=t;void 0!==s;s=e.parentOf.get(s))a.push(s);return a}let dN=36;function dW(e){return(e.lanes??[]).length>0}function dJ(e,t,a){let s=e.lanes,{direction:i}=e.layout,l="TB"===i||"BT"===i,[o,r]=l?["y","x"]:["x","y"],[n,c]=l?["height","width"]:["width","height"],[d,p]=l?["left","right"]:["top","bottom"],h=dE[i],g=pm[h],u=(e,t)=>a.get(pc(e,t))??0,f=dk(e.edges),m=l?dO(e,t,f,l):dO(e,t,f,l,144,744),v=function(e){let t=e.lanes??[],a=new Map(t.map((e,t)=>[e.id,t])),s=new Map(e.nodes.map(e=>[e.id,a.get(e.lane??"")??0])),i=d_(e),l=e.edges.filter(e=>!i.has(e.id)&&e.source!==e.target),o=new Set,r=new Set;for(let e of l){let[t,a]=[s.get(e.source),s.get(e.target)],i=`${e.source}\0${a}`;1!==Math.abs(t-a)||r.has(i)||(r.add(i),o.add(e.id))}let n=new Map(e.nodes.map(e=>[e.id,[]])),c=new Map(e.nodes.map(e=>[e.id,[]]));for(let e of l)n.get(e.target).push(e),c.get(e.source).push(e);let d=dM(e.nodes),p=new Map(e.nodes.map(e=>[e.id,n.get(e.id).length])),h=e.nodes.filter(e=>0===p.get(e.id)).map(e=>e.id),g=new Map,u=new Map;for(;h.length>0;){h.sort((e,t)=>d.get(e)-d.get(t));let e=h.shift(),a=s.get(e),i=t.map((t,a)=>Math.max(-1,...n.get(e).map(e=>u.get(e.source)[a]))),l=i[a]+1;for(let t of n.get(e))l=Math.max(l,g.get(t.source)+ +!o.has(t.id));for(let t of(g.set(e,l),i[a]=l,u.set(e,i),c.get(e))){let e=p.get(t.target)-1;p.set(t.target,e),0===e&&h.push(t.target)}}return g}(e),y=new Map(s.map((e,t)=>[e.id,t])),w=new Map(e.nodes.map(e=>[e.id,e.lane])),x=Math.max(0,...v.values())+1,b=s.map(()=>Array.from({length:x},()=>[]));for(let t of e.nodes)b[y.get(t.lane)][v.get(t.id)].push(t.id);let k=d_(e),M=new Map(e.nodes.map(e=>[e.id,[]]));for(let t of e.edges)k.has(t.id)||t.source===t.target||(M.get(t.source).push(t.target),M.get(t.target).push(t.source));let C=dM(e.nodes),z=e=>{let t=b[y.get(w.get(e))][v.get(e)];return y.get(w.get(e))+(t.indexOf(e)+.5)/t.length};for(let e=0;e<4;e+=1)for(let e of b)for(let t of e){if(t.length<2)continue;let e=new Map(t.map(e=>{let t=M.get(e);return[e,t.length>0?t.reduce((e,t)=>e+z(t),0)/t.length:z(e)]}));t.sort((t,a)=>e.get(t)-e.get(a)||C.get(t)-C.get(a))}let _=Array.from({length:x},(t,a)=>e.nodes.filter(e=>v.get(e.id)===a).map(e=>m.get(e.id))),L=_.map(e=>Math.max(0,...e.map(e=>e[n]))),B=(e,t)=>Math.max(0,...e.map(e=>u(e.nodeId,t))),S=_.map((t,s)=>{let i=new Set(t.map(e=>e.nodeId)),o=l?0:Math.max(0,...e.edges.filter(e=>i.has(e.source)&&e.label&&(v.get(e.target)??0)>s).map(e=>p0(e.label,dx(m.get(e.source)?.kind)).width+16+72)),r=_[s+1];return Math.max(72,o,r&&a.size>0?B(t,h)+B(r,g)+18:0)}),A=(e,t)=>Math.max(112,u(e,p)+u(t,d)+18),P=e=>e.reduce((t,a,s)=>t+m.get(a)[c]+(s>0?A(e[s-1],a):0),0),V=b.map(e=>Math.max(0,...e.map(P))),H=new Map;for(let[e,t]of b.entries())for(let a of t){let t=(V[e]-P(a))/2;for(let[e,s]of a.entries())e>0&&(t+=A(a[e-1],s)),H.set(s,t),t+=m.get(s)[c]}let q=b.map((e,t)=>{let a=e.flat(),s=e=>Math.max(32,...a.map(a=>{let s=e===d?H.get(a):V[t]-H.get(a)-m.get(a)[c];return u(a,e)-s+dN}));return{low:s(d),high:s(p)}}),F=s.map(e=>dQ(e.label)),I=l?0:Math.max(...F.map(e=>e.textWidth))+32,E=b.map((e,t)=>Math.max(q[t].low+V[t]+q[t].high,l?dQ(s[t].label).longestWord+32:F[t].textHeight+32)),O=s.map((e,t)=>l?dQ(e.label,E[t]-32):F[t]),U=l?Math.max(44,...O.map(e=>e.textHeight+32)):Math.ceil(I),X=E.reduce((e,t)=>e+t,0);return{along:o,across:r,backSide:g,breadth:E,columnCount:x,columnOf:_,columns:v,content:V,depth:L,depthOf:n,forwardSide:h,gapAfter:S,headerSize:U,laneIndex:y,laneOf:w,offset:H,padding:q,poolBreadth:X,reach:B,shapes:m,vertical:l,wrapped:O}}function dK(e){return Math.max(144,72+(e+1)*18)}function dQ(e,t){let a=void 0===t?aE(e,868):aO(e,t,16),s=a.split("\n");return{longestWord:Math.max(...e.split(/\s+/u).map(e=>aq(e,16))),text:a,textHeight:Math.ceil(16*s.length*1.35),textWidth:Math.ceil(aq(a,16))}}function d1(e,t){return{type:"node",id:e,nodeId:e,shape:"rectangle",label:"",x:t.x,y:t.y,width:t.width,height:t.height}}function d0(e){return(e?.frames??[]).flatMap(t=>e.composites.has(t.id)?[{...d1(t.elementId,t.box),kind:"composite",label:t.label,nodeId:t.id}]:[])}function d2(e){let t=28*!e?.zoned;return(e?.frames??[]).map(e=>d1(e.elementId,{...e.box,y:e.box.y-t,height:e.box.height+t}))}let d3="group-outline:",d5=`${d3}lane:`;function d4(e){return sp([{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x+e.width,y:e.y+e.height},{x:e.x,y:e.y+e.height},{x:e.x,y:e.y}])}function d6(e,t){return e.x>=t.x-.01&&e.x<=t.x+t.width+.01&&e.y>=t.y-.01&&e.y<=t.y+t.height+.01}function d7(e){return e.elementId}function d8(e,t=!1){return e?[...e.frames.map(e=>d1(`lane-header:${d7(e)}`,e.header)),...(t?[]:e.pools).flatMap(({x:e,y:t,width:a,height:s},i)=>[d1(`lane-wall:${i}:top`,{x:e-4,y:t-4,width:a+8,height:4}),d1(`lane-wall:${i}:bottom`,{x:e-4,y:t+s,width:a+8,height:4}),d1(`lane-wall:${i}:left`,{x:e-4,y:t-4,width:4,height:s+8}),d1(`lane-wall:${i}:right`,{x:e+a,y:t-4,width:4,height:s+8})])]:[]}function d9(e){return e.pools.flatMap((t,a)=>{var s,i,l;let o,r,n;return s=t,i=e.frames.filter(e=>e.pool===a),l=e.vertical,o=i[0].header,r=[...i.map(e=>l?e.box.x:e.box.y),l?s.x+s.width:s.y+s.height],n=l?[s.y,o.y+o.height,s.y+s.height]:[s.x,o.x+o.width,s.x+s.width],[...r.flatMap(e=>sp(l?[{x:e,y:s.y},{x:e,y:s.y+s.height}]:[{x:s.x,y:e},{x:s.x+s.width,y:e}])),...n.flatMap(e=>sp(l?[{x:s.x,y:e},{x:s.x+s.width,y:e}]:[{x:e,y:s.y},{x:e,y:s.y+s.height}]))]})}function pe(e){return e?[d1("lanes",e.pool)]:[]}function pt(e,t){let{source:a,target:s}=e,[i,l]=t.vertical?["y","height"]:["x","width"];return t.laneOf.get(a.nodeId)!==t.laneOf.get(s.nodeId)&&pw(e.sourceEdge)===i&&e.targetEdge===pm[e.sourceEdge]&&Math.min(a[i]+a[l],s[i]+s[l])-Math.max(a[i],s[i])>.01}function pa(e,t){let[a,s]=t.vertical?["y","height"]:["x","width"];for(let i of e){let{source:e,target:l}=i;if(pd(i)||t.continuations.has(i.edge.id)||t.laneOf.get(e.nodeId)===t.laneOf.get(l.nodeId)||Math.min(e[a]+e[s],l[a]+l[s])-Math.max(e[a],l[a])<=.01)continue;let o=t.vertical?pi(l).x>pi(e).x:pi(l).y>pi(e).y;i.sourceEdge=t.vertical?o?"right":"left":o?"bottom":"top",i.targetEdge=pm[i.sourceEdge]}}function ps(e){return{type:"text",id:`label:${e.nodeId}`,containerId:e.id,x:e.x+e.width/2,y:e.y+e.height/2,text:e.label,fontSize:14,maxWidth:Math.max(1,e.width-36),...e.icon?{verticalAlign:"bottom"}:{}}}function pi(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function pl(e,t,a){let s=pi(e),i=pi(t),l=i.x-s.x,o=i.y-s.y,r=e.kind?.toLowerCase();if("LR"===a||"RL"===a)return l>=0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"};if(o<0)return!(Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)>.01)&&Math.abs(l)>Math.abs(o)?{sourceEdge:l>0?"right":"left",targetEdge:"bottom"}:{sourceEdge:"top",targetEdge:"bottom"};let n=dx(r)&&o>e.height+96;return dx(r)&&o>0&&(0!==l||n)?{sourceEdge:l<0?"left":"right",targetEdge:"top"}:o>0?{sourceEdge:"bottom",targetEdge:"top"}:Math.abs(l)>Math.abs(o)?l>0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"}:{sourceEdge:"top",targetEdge:"bottom"}}function po(e,t,a){return Math.min(a,Math.max(t,e))}function pr(e,t,a=0){let s;if(aY(e.shape))return aj({...e,shape:e.shape},t,pr({...e,shape:"rectangle"},t,a));let i=(s="top"===t||"bottom"===t?e.width/2-16:e.height/2-16)>0?po(a,-s,s):0,l=pi(e),o=e.width/2,r=e.height/2;if("diamond"===e.shape&&o>0&&r>0){if("top"===t||"bottom"===t){let e=l.x+i,a=r*(1-Math.abs(i)/o);return{x:e,y:"top"===t?l.y-a:l.y+a}}let e=l.y+i,a=o*(1-Math.abs(i)/r);return{x:"left"===t?l.x-a:l.x+a,y:e}}if(("ellipse"===e.shape||"circle"===e.shape)&&o>0&&r>0){if("top"===t||"bottom"===t){let e=l.x+i,a=r*Math.sqrt(Math.max(0,1-(i/o)**2));return{x:e,y:"top"===t?l.y-a:l.y+a}}let e=l.y+i,a=o*Math.sqrt(Math.max(0,1-(i/r)**2));return{x:"left"===t?l.x-a:l.x+a,y:e}}switch(t){case"top":return{x:e.x+e.width/2+i,y:e.y};case"right":return{x:e.x+e.width,y:e.y+e.height/2+i};case"bottom":return{x:e.x+e.width/2+i,y:e.y+e.height};case"left":return{x:e.x,y:e.y+e.height/2+i}}}function pn(e){return`${e.edgeId}:${e.endpoint}`}function pc(e,t){return`${e}:${t}`}function pd(e){return e.edge.source===e.edge.target}function pp(e,t){let[a,s]="source"===t?[e.sourceEdge,e.targetEdge]:[e.targetEdge,e.sourceEdge];return pv[s][pw(a)]}function ph(e,t){let a="source"===t?e.sourceEdge:e.targetEdge;return pd(e)?1e9*pp(e,t):pi("source"===t?e.target:e.source)[pw(a)]}function pg(e,t){return e.find(e=>e.edge.id===t)?.pair??0}function pu(e,t=!1){let a=new Map;for(let t of e){let e=pc(t.source.nodeId,t.sourceEdge),s=pc(t.target.nodeId,t.targetEdge);a.set(e,[...a.get(e)??[],{edgeId:t.edge.id,endpoint:"source",coordinate:ph(t,"source")}]),a.set(s,[...a.get(s)??[],{edgeId:t.edge.id,endpoint:"target",coordinate:ph(t,"target")}])}let s=new Map;for(let i of a.values()){let a=i.filter(e=>"source"===e.endpoint),l=a.map(t=>e.find(e=>e.edge.id===t.edgeId)).filter(e=>e.edge.label),o=a.length>1&&l.length>0&&(!dx(l[0].source.kind)||t&&l.length>1)?Math.max(18,...l.map(e=>{let t=p0(e.edge.label);return("top"===e.sourceEdge||"bottom"===e.sourceEdge?t.width:t.height)+24})):18;i.sort((t,a)=>t.coordinate-a.coordinate||pg(e,t.edgeId)-pg(e,a.edgeId)).forEach((e,t)=>{s.set(pn(e),(t-(i.length-1)/2)*18*o/18)})}return s}let pf=36,pm={top:"bottom",right:"left",bottom:"top",left:"right"},pv={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function py(e){return"source"===e.endpoint?e.route.sourceEdge:e.route.targetEdge}function pw(e){return"top"===e||"bottom"===e?"x":"y"}function px(e,t){return("x"===pw(t)?e.width:e.height)/2-16}function pb(e,t){return"source"===e.endpoint?pK(e.route,t,36):pJ(e.route,t,36)}let pk={desired:0,high:1/0,low:-1/0,priority:0};function pM(e,t,a=!1,s=pf){let i=pu(e,t),l=new Map;for(let t of e)for(let e of["source","target"]){let a=pc(t[e].nodeId,"source"===e?t.sourceEdge:t.targetEdge);l.set(a,[...l.get(a)??[],{endpoint:e,key:pn({edgeId:t.edge.id,endpoint:e}),route:t}])}let o=[...l.values()].sort((e,t)=>t.length-e.length);for(let e=0;e<3;e+=1)for(let e of o){let o=py(e[0]),r=e[0].route[e[0].endpoint],n=new Map(e.map(e=>[e,function(e,t,a){let s=function(e,t,a){let s={endpoint:"source"===e.endpoint?"target":"source",key:pn({edgeId:e.route.edge.id,endpoint:"source"===e.endpoint?"target":"source"}),route:e.route},i=e.route[e.endpoint],l=py(e),o=py(s),r=pw(l),n=pv[l];if(pd(e.route)){let t=pp(e.route,e.endpoint)*Math.max(0,px(i,l));return{desired:t,high:t,low:t,priority:2}}let c=pr(i,l,t.get(e.key)??0),d=pr(e.route[s.endpoint],o,t.get(s.key)??0),p=(d.x-c.x)*n.x+(d.y-c.y)*n.y;if(pw(o)!==r&&p>=pb(e,c)){let e=pR(d,o,pb(s,d)),t=pv[o][r],a=e[r]-pi(i)[r];return{desired:0,high:t<0?a:1/0,lane:t*p,low:t>0?a:-1/0,priority:1}}let h=(e,t)=>(function(e,t){switch(e.shape){case"rectangle":return!1;case"cylinder":return"top"===t||"bottom"===t;case"pipe":return"left"===t||"right"===t;case"document":return"bottom"===t;default:return!0}})(e.route[e.endpoint],t)&&a.get(pc(e.route[e.endpoint].nodeId,t))?.length===1,g=o===pm[l]&&p>0;if(h(e,l)&&!(g&&"target"===e.endpoint&&h(s,o)))return{desired:0,high:0,low:0,priority:2};let u=d[r]-pi(i)[r];return g&&Math.abs(u)<=px(i,l)?{desired:u,high:u,low:u,priority:2}:pk}(e,t,a),i=e.route[e.endpoint];if("composite"!==i.kind||"top"!==py(e))return s;let l=s$({...i,name:i.label}),o=l.x+l.width+18-pi(i).x;return{...s,desired:Math.max(o,s.desired),low:Math.max(o,s.low),high:Math.max(o,s.high),priority:3}}(e,i,l)])),c=function(e,t,a,s){let i=e=>{let t="source"===e.endpoint?"target":"source";if(!s||pd(e.route))return ph(e.route,e.endpoint);let i=e.route[t],l="source"===t?e.route.sourceEdge:e.route.targetEdge,o=pn({edgeId:e.route.edge.id,endpoint:t});return pR(pr(i,l,a.get(o)??0),l,36)[pw(py(e))]},l=[...e].sort((e,t)=>i(e)-i(t)||(e.route.pair??0)-(t.route.pair??0));for(let e of[1,-1]){let a=l.map((e,a)=>({index:a,lane:t.get(e).lane,slot:e})).filter(({lane:t})=>void 0!==t&&Math.sign(t)===e),s=[...a].sort((e,t)=>e.lane-t.lane);a.forEach(({index:e},t)=>{l[e]=s[t].slot})}return l}(e,n,i,a),d=c.filter(e=>"source"===e.endpoint),p=d.filter(e=>e.route.edge.label),h=d.length>1&&p.length>0&&(!dx(p[0].route.source.kind)||t&&p.length>1)?Math.max(...p.map(e=>{let t=p0(e.route.edge.label);return("x"===pw(o)?t.width:t.height)+24})):0;"state"===r.kind&&function(e){for(let[t,a]of e.entries()){let{route:s}=a;if("source"!==a.endpoint||void 0!==s.pair||pd(s))continue;let i=0===t?-1:t===e.length-1?1:void 0;e.length>1&&void 0!==i?s.labelSide=i:delete s.labelSide}}(c);let g=function(e,t,a){let s=e.map((e,a)=>t.slice(0,a).reduce((e,t)=>e+t,0)),i=s.at(-1)??0;if(i>2*a)return s.map(e=>e-i/2);let l=e.map(()=>-1/0),o=e.map(()=>1/0),r=()=>{let e=l.map((e,t)=>Math.max(e-s[t],-a)),t=o.map((e,t)=>Math.min(e-s[t],a-i));for(let t=1;t<e.length;t+=1)e[t]=Math.max(e[t],e[t-1]);for(let e=t.length-2;e>=0;e-=1)t[e]=Math.min(t[e],t[e+1]);return{highs:t,lows:e}};for(let{index:t}of e.map((e,t)=>({index:t,priority:e.priority})).filter(({priority:e})=>e>0).sort((e,t)=>t.priority-e.priority||e.index-t.index)){l[t]=e[t].low,o[t]=e[t].high;let{highs:a,lows:s}=r();s.some((e,t)=>e>a[t]+.01)&&(l[t]=-1/0,o[t]=1/0)}let{highs:n,lows:c}=r();return(function(e,t,a){let s=[];for(let[i,l]of e.entries())for(s.push({count:1,high:a[i],low:t[i],sum:l,value:po(l,t[i],Math.max(t[i],a[i]))});s.length>1&&s.at(-2).value>s.at(-1).value;){let e=s.pop(),t=s.at(-1);t.count+=e.count,t.sum+=e.sum,t.low=Math.max(t.low,e.low),t.high=Math.min(t.high,e.high),t.value=po(t.sum/t.count,t.low,Math.max(t.low,t.high))}return s.flatMap(e=>Array(e.count).fill(e.value))})(e.map((e,t)=>e.desired-s[t]),c,n).map((e,t)=>e+s[t])}(c.map(e=>n.get(e)),c.slice(1).map((e,t)=>Math.max("state"===r.kind?function(e,t,a){let s=(e,t)=>{let{route:s}=e,i="x"===pw(a);if("source"!==e.endpoint||!s.edge.label||pd(s)||pC(s)!==t)return 0;let l=p0(s.edge.label,dx(s.source.kind));return(i?l.width:l.height)+24};return Math.max(s(e,1),s(t,-1))}(c[t],e,o):h,"target"===e.endpoint||"target"===c[t].endpoint?s:18)),px(r,o));c.forEach((e,t)=>i.set(e.key,g[t]))}return i}function pC(e){let t="left"===e.sourceEdge||"right"===e.sourceEdge;return e.labelSide??e.pair??(t?-1:1)}function pz(e,t){let{edge:a,source:s,sourceEdge:i,target:l,targetEdge:o}=e;return{start:pr(s,i,t.get(pn({edgeId:a.id,endpoint:"source"}))??0),end:pr(l,o,t.get(pn({edgeId:a.id,endpoint:"target"}))??0)}}function p_(e,t,a){let s=0,i=1;for(let[l,o]of[["x","width"],["y","height"]]){let r=a[l]+.01,n=a[l]+a[o]-.01,c=t[l]-e[l];if(.01>=Math.abs(c)){if(e[l]<=r||e[l]>=n)return!1}else{let t=(r-e[l])/c,a=(n-e[l])/c;s=Math.max(s,Math.min(t,a)),i=Math.min(i,Math.max(t,a))}}return s<i}function pL(e,t,a,s){let i=(a.x-pi(e).x)/(e.width/2),l=(a.y-pi(e).y)/(e.height/2),o="ellipse"===e.shape||"circle"===e.shape?{x:i/e.width,y:l/e.height}:"diamond"===e.shape?{x:Math.sign(i)/e.width,y:Math.sign(l)/e.height}:{x:"left"===t?-1:+("right"===t),y:"top"===t?-1:+("bottom"===t)};return(o.x*(s.x-a.x)+o.y*(s.y-a.y))/Math.hypot(o.x,o.y)>=-.01}function pB(e,t,a,s=!1){let i=new Map,l=d_(t),o="TB"===t.layout.direction||"BT"===t.layout.direction?["right","left","top","bottom"]:["bottom","top","left","right"],r=pu(e);for(let n of e.filter(e=>l.has(e.edge.id)||s&&(e=>{let{start:t,end:s}=pz(e,r);return!pL(e.source,e.sourceEdge,t,s)||!pL(e.target,e.targetEdge,s,t)||a.some(a=>a!==e.source&&a!==e.target&&p_(t,s,a))})(e))){let s,c={sourceEdge:n.sourceEdge,targetEdge:n.targetEdge},d=pn({edgeId:n.edge.id,endpoint:"source"}),p=pn({edgeId:n.edge.id,endpoint:"target"}),h=[c,...o.map(e=>({sourceEdge:e,targetEdge:e})),...o.flatMap(e=>o.map(t=>({sourceEdge:e,targetEdge:t})))],g=[!1,!0].flatMap(e=>h.map(t=>({...t,spread:e}))),u=!1;for(let t of g){Object.assign(n,{sourceEdge:t.sourceEdge,targetEdge:t.targetEdge});let i=new Map(r),l=(e,a,s)=>{let l=("top"===a||"bottom"===a?e.width:e.height)/2-16;return t.spread?[i.get(s)??0,-l,l]:[i.get(s)??0]},o=l(n.source,n.sourceEdge,d),c=l(n.target,n.targetEdge,p);for(let l of o){for(let o of c){i.set(d,l),i.set(p,o);let{start:c,end:h}=pz(n,i);if(!pL(n.source,n.sourceEdge,c,h)||!pL(n.target,n.targetEdge,h,c)||a.some(e=>e!==n.source&&e!==n.target&&p_(c,h,e))||e.some(e=>{if(e===n)return!1;let{start:t,end:a}=pz(e,i);return[[n.source,c,e.source,t],[n.source,c,e.target,a],[n.target,h,e.source,t],[n.target,h,e.target,a]].some(([e,t,a,s])=>e===a&&.01>=Math.hypot(t.x-s.x,t.y-s.y))||function(e,t,a,s){let i=t.x-e.x,l=t.y-e.y,o=Math.hypot(i,l);if(o<=.01)return!1;let r=t=>Math.abs(i*(t.y-e.y)-l*(t.x-e.x))/o;if(r(a)>.01||r(s)>.01)return!1;let n=t=>((t.x-e.x)*i+(t.y-e.y)*l)/o,c=n(a),d=n(s);return Math.min(o,Math.max(c,d))-Math.max(0,Math.min(c,d))>.01}(c,h,t,a)}))continue;let g=p3(e,i),f=g.find(e=>e.nodeId===`branch-label:${n.edge.id}`);if(!(f&&p_(c,h,f))&&(s??={sides:t,sourceOffset:l,targetOffset:o},!g.some(e=>e.nodeId!==`branch-label:${n.edge.id}`&&p_(c,h,e)))){r.set(d,l),r.set(p,o),u=!0;break}}if(u)break}if(u)break}if(u||l.has(n.edge.id)){if(!u)if(Object.assign(n,s?.sides??c),s)r.set(d,s.sourceOffset),r.set(p,s.targetOffset);else{let e="TB"===t.layout.direction||"BT"===t.layout.direction,s=e?"x":"y",l=e?"width":"height",o=pi(n.source)[s],r=Math.max(...a.flatMap(e=>[Math.abs(e[s]-o),Math.abs(e[s]+e[l]-o)]));i.set(n.source.nodeId,{width:n.source.width,height:n.source.height,[l]:2*(r+16+18)})}}else Object.assign(n,s?.sides??c),s&&(r.set(d,s.sourceOffset),r.set(p,s.targetOffset))}return{offsets:r,minimumSizes:i}}function pS(e,t,a=!1){let s=new Map;for(let i of e){let{start:e,end:l}=pz(i,t);for(let[t,a,o]of[[i.source,i.sourceEdge,pK(i,e,36)],[i.target,i.targetEdge,pJ(i,l,36)]]){let r=pR(t===i.source?e:l,a,o),n="left"===a?t.x-r.x:"right"===a?r.x-t.x-t.width:"top"===a?t.y-r.y:r.y-t.y-t.height,c=pc(t.nodeId,a);s.set(c,Math.max(s.get(c)??0,n))}if(i.edge.label&&(a||pd(i))){let t=i.source,a=p5(p2(i,e),p0(i.edge.label,dx(t.kind)));for(let[e,i]of[["left",t.x-a.x],["right",a.x+a.width-t.x-t.width],["top",t.y-a.y],["bottom",a.y+a.height-t.y-t.height]]){let a=pc(t.nodeId,e);i>0&&s.set(a,Math.max(s.get(a)??0,i))}}}return s}function pA(e){let t=[];for(let a of e){let e=t[t.length-1];e&&e.x===a.x&&e.y===a.y||t.push(a)}let a=t[0];return a?[a,...t.slice(1)]:[{x:0,y:0}]}function pP(e,t){return e.x>=t.x&&e.x<=t.x+t.width&&e.y>=t.y&&e.y<=t.y+t.height}function pV(e,t,a){let s,i="horizontal"===e.orientation,[l,o]=i?[t.width/2,t.height/2]:[t.height/2,t.width/2],r=i?t.x+l:t.y+l,n=Math.abs(e.staticCoordinate-(i?t.y+o:t.x+o));if("ellipse"===t.shape||"circle"===t.shape){let[e,t]=[l+a,o+a];if(n>=t)return!1;s=e*Math.sqrt(1-(n/t)**2)}else if("diamond"===t.shape){let e=1+a*Math.hypot(1/l,1/o);if(n>=o*e)return!1;s=l*(e-n/o)}else{if(n>=o+a)return!1;s=l+a}return e.min<r+s-.01&&e.max>r-s+.01}function pH(e,t){return e.id.startsWith("node:")&&!t.has(e.nodeId)}function pq(e,t,a){return sp(e).filter(e=>t.some(t=>pH(t,a)&&pF(e,t))).length}function pF(e,t){let[a,s,i,l]="horizontal"===e.orientation?[t.y,t.height,t.x,t.width]:[t.x,t.width,t.y,t.height];return(.01>=Math.abs(e.staticCoordinate-a)||.01>=Math.abs(e.staticCoordinate-a-s))&&Math.min(e.max,i+l)-Math.max(e.min,i)>.01}function pI(e,t,a){let s=0;for(let[i,l]of sp(e).entries())for(let o of t)!(a.has(o.nodeId)&&(0===i&&pP(e[0],o)||i===e.length-2&&pP(e.at(-1),o)))&&su(l,o)&&(s+=1);return s}function pE(e,t,a){let s=0;for(let i of sp(e))for(let e of t)pH(e,a)&&!su(i,e)&&pV(i,e,12)&&(s+=1);return s}function pO(e){let t=0;for(let a=0;a<e.length-1;a+=1){let s=e[a],i=e[a+1];s&&i&&(t+=Math.abs(i.x-s.x)+Math.abs(i.y-s.y))}return t}function pU(e){return sp(e.points).map(t=>{let[a,s]=[e.points[t.segmentIndex],e.points[t.segmentIndex+1]];return{...t,arrowId:e.arrowId,startBindingId:e.sourceNodeId,endBindingId:e.targetNodeId,from:"horizontal"===t.orientation?a.x:a.y,to:"horizontal"===t.orientation?s.x:s.y}})}function pX(e){return e.flatMap(e=>pU({arrowId:e.id,points:e.points,sourceNodeId:e.sourceNodeId,targetNodeId:e.targetNodeId}))}function pT(e,t,a){let s=pU({arrowId:`edge:${a.edge.id}`,points:e,sourceNodeId:a.edge.source,targetNodeId:a.edge.target}),i=0;for(let e of s)for(let s of t)e.arrowId===s.arrowId||!sg(e,s)||void 0!==a.pinned&&function(e,t){let a=e.isFirstSegment&&t.isFirstSegment&&e.startBindingId===t.startBindingId;return sf(e,t)&&.01>=Math.abs((a?e.from:e.to)-(a?t.from:t.to))&&Math.sign(e.to-e.from)===Math.sign(t.to-t.from)}(e,s)||(i+=1);return i}function pY(e,t){let a=pU({arrowId:`edge:${t.edge.id}`,points:e,sourceNodeId:t.edge.source,targetNodeId:t.edge.target}),s=0;for(let e=0;e<a.length;e+=1){let t=a[e];if(t)for(let i=e+1;i<a.length;i+=1){let e=a[i];e&&sg(t,e)&&(s+=1)}}return s}function p$(e){let t=e[0],a=e[e.length-1];if(!t||!a)return 0;let s=e.map(e=>e.x),i=e.map(e=>e.y),l=0;return a.x<t.x?l+=Math.max(0,Math.max(...s)-t.x):a.x>t.x&&(l+=Math.max(0,t.x-Math.min(...s))),a.y<t.y?l+=Math.max(0,Math.max(...i)-t.y):a.y>t.y&&(l+=Math.max(0,t.y-Math.min(...i))),l}function pG(e){let t=e[0],a=e[e.length-1];if(!t||!a)return 0;let s=e.map(e=>e.x),i=e.map(e=>e.y),l=0;return a.x<t.x?l+=Math.max(0,a.x-Math.min(...s)):a.x>t.x&&(l+=Math.max(0,Math.max(...s)-a.x)),a.y<t.y?l+=Math.max(0,a.y-Math.min(...i)):a.y>t.y&&(l+=Math.max(0,Math.max(...i)-a.y)),l}function pD(e,t,a){switch(a){case"top":return t.x===e.x&&e.y-t.y>=36;case"right":return t.y===e.y&&t.x-e.x>=36;case"bottom":return t.x===e.x&&t.y-e.y>=36;case"left":return t.y===e.y&&e.x-t.x>=36}}function pR(e,t,a){switch(t){case"top":return{x:e.x,y:e.y-a};case"right":return{x:e.x+a,y:e.y};case"bottom":return{x:e.x,y:e.y+a};case"left":return{x:e.x-a,y:e.y}}}function pZ(e,t){return 0===t.length?0:sp(e).filter(e=>t.some(t=>t.orientation===e.orientation&&Math.abs(t.staticCoordinate-e.staticCoordinate)<(t.arrowId.startsWith(d5)?24:8)&&sh(t,e)>8)).length}function pj(e,t,a,s,i,l=!1){let o=e[0];if(!o)return[{x:0,y:0}];let r=e=>{let o,r,n,c,d,p=i.quality?.({id:`edge:${s.edge.id}`,points:e,sourceId:s.edge.source,targetId:s.edge.target})??{arrowheadsCrossed:0,corridors:0,jogs:0};return[-(o=e[0],r=e[1],n=e[e.length-1],c=e[e.length-2],d=0,r&&pD(o,r,s.sourceEdge)&&(d+=1),c&&n&&pD(n,c,s.targetEdge)&&(d+=1),d),pI(e,t,a),...l?[pq(e,t,a)]:[],pY(e,s),pT(e,i.segments,s),pZ(e,i.outlines),p.corridors,p.arrowheadsCrossed,i.crossings?.route(e,`edge:${s.edge.id}`)??0,p$(e),pG(e),p.jogs,pO(e),i.quality?sp(e).filter((e,t,a)=>t>0&&e.orientation!==a[t-1].orientation).length:0]},n=(e,t)=>{for(let a=0;a<e.length;a+=1){let s=(e[a]??0)-(t[a]??0);if(0!==s)return s<0}return!1},c=o,d=r(o);for(let t of e.slice(1)){let e=r(t);n(e,d)&&(c=t,d=e)}return c}function pN(e,t,a,s){switch(a){case"left":return s+t.x-e.x;case"right":return s+e.x+e.width-t.x;case"top":return s+t.y-e.y;case"bottom":return s+e.y+e.height-t.y}}function pW(e,t){return e.runs?.[t]??e.endRun??0}function pJ(e,t,a){return pN(e.target,t,e.targetEdge,Math.max(a,pW(e,"target")))}function pK(e,t,a){let s=e.edge.label&&!pd(e)?"left"===e.sourceEdge||"right"===e.sourceEdge?p0(e.edge.label,dx(e.source.kind)).width+16:Math.max(40,p0(e.edge.label,dx(e.source.kind)).height+24):0;return pN(e.source,t,e.sourceEdge,Math.max(a,pW(e,"source")+Math.min(s,function(e,t){if("choice"!==e.source.kind||e.targetEdge!==pm[e.sourceEdge])return 1/0;let a=pv[e.sourceEdge],s=0===a.x?"y":"x",i=a[s],[l,o]="x"===s?["y","height"]:["x","width"];if(t[l]>=e.target[l]&&t[l]<=e.target[l]+e.target[o])return 1/0;let r=((i>0?e.target[s]:e.target[s]+e.target["x"===s?"width":"height"])-t[s])*i-36-18;return r>36?r:1/0}(e,t))))}function pQ(e,t,a=!1){let s="TB"===t||"BT"===t;if(!s&&!a)return;let i=s?"x":"y",l=s?"y":"x",[o,r]=s?["left","right"]:["top","bottom"],n="TB"===t?"bottom":"BT"===t?"top":"LR"===t?"right":"left";for(let t of new Set(e.filter(e=>dx(e.source.kind)).map(e=>e.source))){let a=e.filter(e=>e.source===t).sort((e,t)=>pi(e.target)[i]-pi(t.target)[i]||pi(e.target)[l]-pi(t.target)[l]||e.index-t.index);a.length<2||a.forEach((e,s)=>{let c=a.filter(e=>1>Math.abs(pi(e.target)[i]-pi(t)[i])).sort((e,a)=>Math.abs(pi(e.target)[l]-pi(t)[l])-Math.abs(pi(a.target)[l]-pi(t)[l]))[0],d=2===a.length&&e===c,p=2===a.length&&void 0!==c&&!d;e.sourceEdge=d?n:p?pi(e.target)[i]<pi(t)[i]?o:r:0===s?o:s===a.length-1?r:n})}}function p1(e,t){let a=aO(e,t,13);return{width:aI(a,13,t),height:Math.ceil(13*a.split("\n").length*1.35)}}function p0(e,t=!1){return p1(e,t?80:160)}function p2(e,t){let a=p0(e.edge.label??"",dx(e.source.kind)),s=pR(t,e.sourceEdge,pK(e,t,36)),i="left"===e.sourceEdge||"right"===e.sourceEdge;if(pd(e)){let t=pR(pr(e.target,e.targetEdge),e.targetEdge,36),l=pv[e.sourceEdge];return i?{x:s.x+l.x*(a.width/2+8),y:(s.y+t.y)/2}:{x:(s.x+t.x)/2,y:s.y+l.y*(a.height/2+5)}}let l=pC(e),o=pR(t,e.sourceEdge,pW(e,"source"));return{x:(o.x+s.x)/2+(i?0:l*(a.width/2+8)),y:(o.y+s.y)/2+(i?l*(a.height/2+5):0)}}function p3(e,t){return e.filter(e=>e.edge.label).map(e=>{let a=pr(e.source,e.sourceEdge,t.get(pn({edgeId:e.edge.id,endpoint:"source"}))??0),s=p2(e,a),i=p0(e.edge.label,dx(e.source.kind)),l=i.width+12;return{...e.source,id:`branch-label:${e.edge.id}`,nodeId:`branch-label:${e.edge.id}`,x:s.x-l/2,y:s.y-i.height/2-4,width:l,height:i.height+8,shape:"rectangle"}})}function p5(e,t){return{x:e.x-t.width/2,y:e.y-t.height/2,width:t.width,height:t.height}}function p4(e,t){return e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height}function p6(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function p7(e,t,a){let s=t=>Math.min(1/0,...t.map(t=>(function(e,t){let[a,s,i,l]="horizontal"===t.orientation?[t.min,t.max,t.staticCoordinate,t.staticCoordinate]:[t.staticCoordinate,t.staticCoordinate,t.min,t.max];return Math.hypot(Math.max(0,e.x-s,a-e.x-e.width),Math.max(0,e.y-l,i-e.y-e.height))})(e,t)));return s(a)<s(t)+8}function p8(e,t,a={start:0,end:0}){let s=[],i=pO(e),l=0;for(let o of sp(e)){if(l>240)break;let r=e[o.segmentIndex],n=e[o.segmentIndex+1],c=o.max-o.min,d="horizontal"===o.orientation,p=d?t.width/2+4:t.height/2+4;for(let e=Math.min(p,c/2);e<=c-Math.min(p,c/2)&&!(l+e>240);e+=12){if(a.start>0&&l+e-p<a.start||a.end>0&&l+e+p>i-a.end)continue;let o=e/c,h={x:r.x+(n.x-r.x)*o,y:r.y+(n.y-r.y)*o};for(let e of[1,-1])s.push(d?{x:h.x,y:h.y-e*(t.height/2+5)}:{x:h.x+e*(t.width/2+8),y:h.y})}l+=c}return s}function p9(e){return e?{start:pW(e,"source"),end:pW(e,"target")}:{start:0,end:0}}function he(e,t,a,s,i=!0,l){return ht(e,t,a,s,i,l).labels}function ht(e,t,a,s,i=!0,l){let o=[],r=0,n=e.map(e=>sp(e.points)),c=[...a,...(s?.frames??[]).map(e=>d1(`group-label:${e.id}`,e.labelBox)),...(l?.frames??[]).map(e=>d1(`lane-header:${d7(e)}`,e.header))],d=[...(s?.frames??[]).flatMap(e=>d4(e.box)),...l?d9(l):[]],p=[],h=e.map((e,a)=>e.label?p0(e.label,dx(t[a]?.source.kind)):void 0),g=e.map((e,a)=>e.label?p2(t[a],e.points[0]):void 0);for(let[a,s]of e.entries()){let e=h[a],l=g[a];if(!e||!l)continue;let o=g.flatMap((e,t)=>e&&t!==a&&!p.some(e=>e.index===t)?[p5(e,h[t])]:[]),u=[...n.flatMap((e,t)=>t===a?[]:e),...d],f=(t,s=0)=>(function(e,t,a,s,i){let l=p6(e,3),o=p6(e,8);return t.filter(e=>su(e,l)).length+a.filter(e=>su(e,o)).length+s.filter(t=>(function(e,t){let[a,s]=[t.x+t.width/2,t.y+t.height/2],i=Math.max(e.x,Math.min(a,e.x+e.width))-a,l=Math.max(e.y,Math.min(s,e.y+e.height))-s,[o,r]=[Math.abs(i)/(t.width/2),Math.abs(l)/(t.height/2)];return"diamond"===t.shape?o+r<1:"ellipse"===t.shape||"circle"===t.shape?o*o+r*r<1:o<1&&r<1})(e,t)).length+i.filter(e=>p4(l,e)).length})(p6(p5(t,e),s),n[a],u,c,[...o,...p.map(e=>e.box)]),m=l,v=f(l);if(v>0)for(let i of p8(s.points,e,p9(t[a]))){let e=f(i);if(e<v&&([m,v]=[i,e]),0===v)break}else i&&p7(p5(l,e),n[a],u)&&(m=p8(s.points,e,p9(t[a])).find(t=>0===f(t,6)&&!p7(p5(t,e),n[a],u))??l);r+=v,g[a]=m,p.push({box:p5(m,e),index:a})}for(let[a,s]of e.entries()){let i=g[a];if(!s.label||!i)continue;let l=[`branch:${s.edgeId}`];o.push({type:"text",id:`${s.id}:label`,text:s.label,fontSize:13,x:i.x,y:i.y,maxWidth:dx(t[a]?.source.kind)?80:160,groupIds:l}),e[a]={...s,groupIds:l}}return{labels:o,touches:r}}function ha(e,t){let a=new Map([["horizontal",[]],["vertical",[]]]);for(let t of e)a.get(t.orientation).push(t);for(let e of a.values())e.sort((e,t)=>e.staticCoordinate-t.staticCoordinate);return(e,s)=>{let i=a.get(e.orientation),l=Math.max(t,.02),o=0,r=i.length;for(;o<r;){let t=o+r>>1;i[t].staticCoordinate<e.staticCoordinate-l?o=t+1:r=t}let n=0,c=0;for(let a=o;a<i.length&&i[a].staticCoordinate<=e.staticCoordinate+l;a+=1){let l=i[a];l.arrowId!==s&&(sg(e,l)?n+=1:Math.abs(l.staticCoordinate-e.staticCoordinate)<t&&sh(e,l)>.01&&(c+=1))}return{beside:c,overlaps:n}}}function hs(e){return e.every((t,a)=>0===a||.01>=Math.abs(t.x-e[a-1].x)||.01>=Math.abs(t.y-e[a-1].y))}function hi(e,t,a,s,i,l=e.map((e,t)=>t),o=new Map){var r,n;let c=[...p3(e,a),...e.filter(pd).map(e=>{let{start:t,end:s}=pz(e,a),i=dZ([t,s,pR(t,e.sourceEdge,pK(e,t,36)),pR(s,e.targetEdge,pJ(e,s,36))].map(e=>({...e,width:0,height:0})));return d1(`loop:${e.edge.id}`,p6(i,9))})],d="orthogonal"===t?e.flatMap(e=>{let{start:t,end:s}=pz(e,a),i={type:"arrow",id:`edge:${e.edge.id}`,edgeId:e.edge.id,sourceNodeId:e.edge.source,targetNodeId:e.edge.target};return[{...i,endArrowhead:null,points:[t,pR(t,e.sourceEdge,pK(e,t,36))]},{...i,points:[pR(s,e.targetEdge,pJ(e,s,36)),s]}]}):[],p=[...(r=i.groups,(r?.frames??[]).map(e=>{let{x:t,y:a,width:s,height:i}=e.box,l=`${d3}${e.id}`;return{type:"arrow",id:l,edgeId:l,sourceNodeId:"",targetNodeId:"",endArrowhead:null,points:[{x:t,y:a},{x:t+s,y:a},{x:t+s,y:a+i},{x:t,y:a+i},{x:t,y:a}]}})),...(n=i.lanes)?d9(n).map((e,t)=>{let a=`${d5}${t}`,[s,i]="horizontal"===e.orientation?[{x:e.min,y:e.staticCoordinate},{x:e.max,y:e.staticCoordinate}]:[{x:e.staticCoordinate,y:e.min},{x:e.staticCoordinate,y:e.max}];return{type:"arrow",id:a,edgeId:a,sourceNodeId:"",targetNodeId:"",endArrowhead:null,points:[s,i]}}):[]],h=d8(i.lanes),g=d8(i.lanes,!0),u=[];for(let r of l.map(t=>e[t])){let e=o.get(r.edge.id);if(e){u.push(e);continue}u.push(function(e,t,a,s,i,l){let{edge:o}=e,{start:r,end:n}=pz(e,a),c="orthogonal"===t?function(e,t,a,s,i,{avoidCrossings:l,readerScale:o,guided:r,bandOf:n,groups:c,lanes:d}){let p=Math.abs(a.x-t.x)>=Math.abs(a.y-t.y),h=new Set([e.source.nodeId,e.target.nodeId]),g=n?.get(e.source.nodeId),u=void 0===g?s:s.filter(e=>n.get(e.nodeId)===g),f=Math.min(...u.map(e=>e.x)),m=Math.max(...u.map(e=>e.x+e.width)),v=Math.min(...u.map(e=>e.y)),y=Math.max(...u.map(e=>e.y+e.height)),w="left"===e.sourceEdge||"left"===e.targetEdge||pi(e.target).x<pi(e.source).x,x=pi(e.target).y<pi(e.source).y,b=18*e.index,k=f-56-b,M=m+56+b,C=v-48-b,z=y+48+b,_=e.index%4*18/2,L=Math.min(e.source.x,e.target.x)-56-_,B=Math.max(e.source.x+e.source.width,e.target.x+e.target.width)+56+_,S=Math.min(e.source.y,e.target.y)-48-_,A=Math.max(e.source.y+e.source.height,e.target.y+e.target.height)+48+_,P=36+e.index%4*18,V=void 0===o?[P]:[...new Set([P,36])],H=(s,i)=>{let l=i>0?pR(t,e.sourceEdge,pK(e,t,36)):t,o=i>0?pR(a,e.targetEdge,pJ(e,a,i)):a;return pA([t,l,{x:s,y:l.y},{x:s,y:o.y},o,a])},q=(s,i)=>{let l=i>0?pR(t,e.sourceEdge,pK(e,t,36)):t,o=i>0?pR(a,e.targetEdge,pJ(e,a,i)):a;return pA([t,l,{x:l.x,y:s},{x:o.x,y:s},o,a])},F=[[x?S:A,q],[x?A:S,q],[x?C:z,q],[x?z:C,q]],I=[[w?L:B,H],[w?B:L,H],[w?k:M,H],[w?M:k,H]],[E,O]=p?[F,I]:[I,F],U=[...E.slice(0,2),...O.slice(0,2),...E.slice(2),...O.slice(2)],X=pR(t,e.sourceEdge,pK(e,t,36)),T=pR(a,e.targetEdge,pJ(e,a,36)),Y=void 0===e.lane?[]:V.map(t=>"top"===e.sourceEdge||"bottom"===e.sourceEdge?H(e.lane,t):q(e.lane,t)),$=(void 0!==e.pinned||void 0!==d&&pt(e,d))&&e.targetEdge===pm[e.sourceEdge],G="left"===e.sourceEdge||"right"===e.sourceEdge?[{x:(X.x+T.x)/2,y:X.y},{x:(X.x+T.x)/2,y:T.y}]:[{x:X.x,y:(X.y+T.y)/2},{x:T.x,y:(X.y+T.y)/2}],D=[...Y,pA([t,a]),pA([t,X,{x:X.x,y:T.y},T,a]),pA([t,X,{x:T.x,y:X.y},T,a]),...$?[pA([t,X,...G,T,a])]:[],...U.flatMap(([e,t])=>V.map(a=>t(e,a)))],R=function(e,t,a=!1){let s=e.some(e=>e.id.startsWith(d5))?e.filter(e=>!e.id.startsWith(d5)):e;return{...void 0===t?{}:{...a?{crossings:function(e){let t={horizontal:[],vertical:[]};for(let a of e){if(a.id.startsWith(d3))continue;let e=hm(a.points);for(let s=0;s+1<e.length;s+=1){let[i,l]=[e[s],e[s+1]],o=.01>=Math.abs(i.y-l.y);if(!o&&Math.abs(i.x-l.x)>.01)continue;let[r,n]=o?[i.x,l.x]:[i.y,l.y];.01>=Math.abs(n-r)||t[o?"horizontal":"vertical"].push({arrowId:a.id,at:o?i.y:i.x,min:Math.min(r,n),max:Math.max(r,n)})}}for(let e of Object.values(t))e.sort((e,t)=>e.at-t.at);let a=(e,a,s,i,l,o)=>{let r=t["horizontal"===e?"vertical":"horizontal"],n=0,c=r.length;for(;n<c;){let e=n+c>>1;r[e].at<=s+.01?n=e+1:c=e}let d=0;for(let e=n;e<r.length;e+=1){let t=r[e];if(o?t.at>i+.01:t.at>=i-.01)break;t.arrowId!==l&&a>t.min+.01&&a<t.max-.01&&(d+=1)}return d};return{step:(e,t,s,i,l)=>a(e,t,Math.min(s,i),Math.max(s,i),l,!0),route:(e,t)=>{let s=hm(e),i=0;for(let e=0;e+1<s.length;e+=1){let[l,o]=[s[e],s[e+1]],r=.01>=Math.abs(l.y-o.y);if(!r&&Math.abs(l.x-o.x)>.01)continue;let[n,c]=r?[Math.min(l.x,o.x),Math.max(l.x,o.x)]:[Math.min(l.y,o.y),Math.max(l.y,o.y)];i+=a(r?"horizontal":"vertical",r?l.y:l.x,n,c,t,!1)}return i}}}(s)}:{},quality:sF(s.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId,endArrowhead:null!==e.endArrowhead})),t)},outlines:pX(e.filter(e=>e.id.startsWith(d3))),segments:pX(s)}}(i,o,l),Z=c?.zoned===!0,j=pj(D,s,h,e,R,Z),N=void 0===o?0:24/o,W=N?pj([j,...function(e,t,a,s){let i=`edge:${a.edge.id}`,l=[];for(let a of sp(e))if(!a.isFirstSegment&&!a.isLastSegment){for(let o of t)if(!(o.arrowId===i||o.orientation!==a.orientation||Math.abs(o.staticCoordinate-a.staticCoordinate)>=s||.01>=sh(a,o)))for(let t of[o.staticCoordinate-s-1,o.staticCoordinate+s+1]){let s=e.map((e,s)=>s===a.segmentIndex||s===a.segmentIndex+1?"horizontal"===a.orientation?{x:e.x,y:t}:{x:t,y:e.y}:e);l.push(pA(s))}}return l}(j,R.segments,e,N)],s,h,e,R,Z):j,J=Z&&pq(W,s,h)>0,K=pI(W,s,h)||pY(W,e)||pT(W,R.segments,e)||pZ(W,R.outlines),Q=void 0!==e.pinned&&p$(W)+pG(W)>0;if(K||J||R.quality?.({id:`edge:${e.edge.id}`,points:W,sourceId:e.edge.source,targetId:e.edge.target}).corridors||Q){let l=function(e,t,a,s,i,l,o,r,n,c=0,d=1/0,p=!0,h,g=!1){let u,f,m,v,y=e=>[...new Set([18,Math.max(18,c+1)])].flatMap(t=>[e-t,e+t]),w=[...new Set([a.x,s.x,...i.flatMap(e=>[e.x-18,e.x+e.width+18]),...o.flatMap(e=>e.points.flatMap(e=>y(e.x)))])].sort((e,t)=>e-t),x=[...new Set([a.y,s.y,...i.flatMap(e=>[e.y-18,e.y+e.height+18]),...o.flatMap(e=>e.points.flatMap(e=>y(e.y)))])].sort((e,t)=>e-t),b=(e,t,a)=>(e*x.length+t)*2+a,k=`edge:${l.edge.id}`,M=ha(r,c),[C,z]=[!1,!0].map(e=>n.filter(t=>t.arrowId.startsWith(d5)===e)),_=C.length>0?ha(C,8):void 0,L=z.length>0?ha(z,24):void 0,B=[...sp([e,a]),...sp([s,t])],S=(e,t)=>p?Math.abs(w[e]-s.x)+Math.abs(x[t]-s.y):0,A=w.indexOf(a.x),P=x.indexOf(a.y),V={x:A,y:P,axis:+(e.x===a.x),cost:0,estimate:S(A,P)},H=(e,t)=>{let a="x"===t?"width":"height",s=[],l=g?-.01:.01;return o=>s[o]??=i.filter(s=>e[o]>s[t]+l&&e[o]<s[t]+s[a]-l)},[q,F]=[H(w,"x"),H(x,"y")],I=(u=[],f=0,m=(e,t)=>e.item.estimate<t.item.estimate||e.item.estimate===t.item.estimate&&e.order>t.order,v=(e,t)=>{[u[e],u[t]]=[u[t],u[e]]},{get size(){return u.length},push(e){u.push({item:e,order:f++});for(let e=u.length-1;e>0;){let t=e-1>>1;if(!m(u[e],u[t]))break;v(e,t),e=t}},pop(){let e=u[0],t=u.pop();if(u.length>0){u[0]=t;for(let e=0;;){let t=2*e+1,a=t+1,s=e;if(t<u.length&&m(u[t],u[s])&&(s=t),a<u.length&&m(u[a],u[s])&&(s=a),s===e)break;v(e,s),e=s}}return e.item}});I.push(V);let E=new Map([[b(V.x,V.y,V.axis),0]]),O=new Map;for(let a=0;I.size&&a<d;a+=1){let a=I.pop();if(a.cost!==E.get(b(a.x,a.y,a.axis)))continue;let i={x:w[a.x],y:x[a.y]};if(i.x===s.x&&i.y===s.y){let s=[];for(let e=a;e;e=e.previous)s.unshift({x:w[e.x],y:x[e.y]});return pA([e,...s.filter((e,t)=>0===t||t===s.length-1||(s[t-1].x!==e.x||e.x!==s[t+1].x)&&(s[t-1].y!==e.y||e.y!==s[t+1].y)),t])}for(let[e,t,s]of[[-1,0,0],[1,0,0],[0,-1,1],[0,1,1]]){let l=a.x+e,o=a.y+t;if(l<0||o<0||l>=w.length||o>=x.length)continue;let r={x:w[l],y:x[o]},n=(Math.min(l,a.x)*x.length+Math.min(o,a.y))*2+s;if(!O.has(n)){let e=sp([i,r],0)[0],t=sp([i,r])[0],{beside:l,overlaps:o}=t?M(t,k):{beside:0,overlaps:0},c=t&&_?_(t,k):void 0,d=t&&L?L(t,k):void 0;O.set(n,(0===s?F(a.y):q(a.x)).some(t=>su(e,t)||g&&t.id.startsWith("node:")&&pF(e,t))||B.some(t=>sg(e,t))?void 0:Math.abs(r.x-i.x)+Math.abs(r.y-i.y)+1e4*o+1e3*l+(c?(c.beside+c.overlaps)*1e3:0)+(d?(d.beside+d.overlaps)*1e3:0)+(h&&t?320*h.step(t.orientation,t.staticCoordinate,t.min,t.max,k):0))}let c=O.get(n);if(void 0===c)continue;let d=a.cost+c+24*(s!==a.axis),p=b(l,o,s);d>=(E.get(p)??1/0)||(E.set(p,d),I.push({x:l,y:o,axis:s,cost:d,estimate:d+S(l,o),previous:a}))}}}(t,a,X,T,s,e,i,R.segments,R.outlines,K?0:N,K?1/0:5e3,r,R.crossings,Z);if(l)return pj([W,l],s,h,e,R,Z)}return W}(e,r,n,s,i,l):pA([r,n]),d=e.pinned?pA(hm(c)):c;return{type:"arrow",id:`edge:${o.id}`,edgeId:o.id,sourceNodeId:o.source,targetNodeId:o.target,points:d,...o.label?{label:o.label}:{}}}(r,t,a,[...s,...c.filter(e=>e.nodeId!==`branch-label:${r.edge.id}`&&e.nodeId!==`loop:${r.edge.id}`),...function(e,t){if(!e)return[];let a=new Set([...dA(e,e.groupOf.get(t.source.nodeId)),...dA(e,e.groupOf.get(t.target.nodeId))]),s=dP(e,t.source.nodeId,t.target.nodeId);return e.frames.flatMap(e=>{let t=d1(`group-label:${e.id}`,e.labelBox);if(e.id===s){let{x:a,y:s,width:i,height:l}=e.box;return[t,d1(`group-wall:${e.id}:top`,{x:a-4,y:s-4,width:i+8,height:4}),d1(`group-wall:${e.id}:bottom`,{x:a-4,y:s+l,width:i+8,height:4}),d1(`group-wall:${e.id}:left`,{x:a-4,y:s-4,width:4,height:l+8}),d1(`group-wall:${e.id}:right`,{x:a+i,y:s-4,width:4,height:l+8})]}return a.has(e.id)?[t]:[t,d1(e.elementId,e.box)]})}(i.groups,r),...i.lanes?.continuations.has(r.edge.id)?g:h],[...p,...d,...u],i))}return e.map(e=>u.find(t=>t.edgeId===e.edge.id))}function hl(e,t,a,s,i){let l=d_(a),o=new Set(e.flatMap(e=>[pc(e.source.nodeId,e.sourceEdge),pc(e.target.nodeId,e.targetEdge)])),r=[];for(let[a,n]of t.entries()){let c=e[a];if(l.has(c.edge.id)||c.pinned?.target!==void 0||!("hooked"===i?sq([{id:n.id,points:n.points}],s).some(e=>"endpoint-jog"===e.kind&&"end"===e.endpoint):t.some(e=>e!==n&&hv(n.points,e.points,n.points.length-3,!1)>0)))continue;let d=sp(n.points),p=d.at(-1),h=d.findLast(e=>e.orientation!==p?.orientation);if(!p||!h)continue;let g=n.points[h.segmentIndex],u=n.points[h.segmentIndex+1],f="horizontal"===h.orientation?u.x>g.x?"left":"right":u.y>g.y?"top":"bottom";f===c.targetEdge||o.has(pc(c.target.nodeId,f))||(r.push({route:c,side:c.targetEdge}),o.add(pc(c.target.nodeId,f)),c.targetEdge=f)}return r}function ho(e,t,a,s){let i,l=e.flatMap(e=>sp(e.points).map(t=>{let a=e.points[t.segmentIndex],s=e.points[t.segmentIndex+1];return{...t,arrowId:e.id,startBindingId:e.sourceNodeId,endBindingId:e.targetNodeId,from:"horizontal"===t.orientation?a.x:a.y,to:"horizontal"===t.orientation?s.x:s.y}})),o=[];for(let[e,a]of l.entries()){for(let t of l.slice(e+1)){if(a.arrowId===t.arrowId||!sg(a,t))continue;let e=a.isFirstSegment&&t.isFirstSegment&&a.startBindingId===t.startBindingId;sf(a,t)&&.01>=Math.abs((e?a.from:a.to)-(e?t.from:t.to))&&Math.sign(a.to-a.from)===Math.sign(t.to-t.from)||o.push([a.arrowId,t.arrowId])}for(let e of t)e.nodeId!==a.startBindingId&&e.nodeId!==a.endBindingId&&su(a,e)&&o.push([a.arrowId])}let r=a?[...o,...function(e,t){let a=[],s=t.frames.map(e=>d4(e.box));for(let i of e){let e=sp(i.points),l=new Set([...dA(t,t.groupOf.get(i.sourceNodeId)),...dA(t,t.groupOf.get(i.targetNodeId))]),o=new Set(dA(t,dP(t,i.sourceNodeId,i.targetNodeId)));for(let[r,n]of t.frames.entries()){let t=l.has(n.id);(e.some(e=>su(e,n.labelBox)||!t&&su(e,n.box)||s[r].some(t=>t.orientation===e.orientation&&8>Math.abs(t.staticCoordinate-e.staticCoordinate)&&sh(t,e)>8))||o.has(n.id)&&i.points.some(e=>!d6(e,n.box)))&&a.push([i.id])}}return a}(e,a)]:o;return s?[...r,...(i=d9(s),e.flatMap(e=>sp(e.points).some(e=>s.frames.some(t=>su(e,t.header))||i.some(t=>t.orientation===e.orientation&&8>Math.abs(t.staticCoordinate-e.staticCoordinate)&&sh(t,e)>8))||e.points.some(e=>!d6(e,s.pool))?[[e.id]]:[]))]:r}function hr(e,t){let a=new Map(t.map(e=>[e.nodeId,e])),s=0;for(let t of e)for(let[e,i,l]of[[t.sourceNodeId,t.points[0],t.points[1]],[t.targetNodeId,t.points.at(-1),t.points.at(-2)]]){let t=a.get(e);if(!t||!i||!l)continue;if(aY(t.shape)){let e=e=>Math.max(Math.abs(e.x-pi(t).x)/(t.width/2),Math.abs(e.y-pi(t).y)/(t.height/2));e({x:i.x+(l.x-i.x)*1e-4,y:i.y+(l.y-i.y)*1e-4})<e(i)-1e-9&&(s+=1);continue}let o=(i.x+(l.x-i.x)*1e-4-pi(t).x)/(t.width/2),r=(i.y+(l.y-i.y)*1e-4-pi(t).y)/(t.height/2);("diamond"===t.shape?Math.abs(o)+Math.abs(r):"ellipse"===t.shape||"circle"===t.shape?Math.hypot(o,r):Math.max(Math.abs(o),Math.abs(r)))<1-1e-6&&(s+=1)}return s}function hn(e){return e.flatMap(e=>{if("arrow"===e.type||"line"===e.type)return[...e.points];if("text"===e.type){if(e.containerId)return[];let t=(e.maxWidth??e.text.length)/2,a=e.text.split("\n").length*e.fontSize*1.35/2;return[{x:e.x-t,y:e.y-a},{x:e.x+t,y:e.y+a}]}return[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]})}function hc(e,t,a){return{x:e.x+t,y:e.y+a}}let hd={ports:!1,reader:!1,sides:!1,repair:!1};function hp(e){let{edgeArrows:t,groups:a,nodeShapes:s,routedEdges:i}=e,l=new Set;if(!a)return l;let o=new Map(t.map(e=>[e.id,e]));for(let e of ho(t,s,a))for(let t of e){let e=o.get(t);for(let t of e?[e.sourceNodeId,e.targetNodeId]:[]){let e=a.groupOf.get(t);void 0!==e&&l.add(e)}}let r=he([...t],i,s,a,!1),n=a.frames.flatMap(e=>d4(e.box));for(let e of r){let t=o.get(e.id.slice(0,-6)),s=t?a.groupOf.get(t.sourceNodeId):void 0,i=p5(e,p1(e.text,e.maxWidth??160));if(a.zoned)for(let e of a.frames)(d4(e.box).some(e=>su(e,i))||p4(i,e.labelBox))&&l.add(e.id);void 0!==s&&(n.some(e=>su(e,i))||a.frames.some(e=>p4(i,e.labelBox)))&&l.add(s)}return l}function hh(e,t,a=dT){let s=hu(e,t,a,new Map);if(!s.groups)return s;let i=e=>ho(e.edgeArrows,e.nodeShapes,e.groups).length+hp(e).size,l=new Map,o=i(s);for(let r=0;r<3&&o>0;r+=1){let r=hp(s);if(0===r.size)break;let n=hu(e,t,a,l=new Map([...l,...[...r].map(e=>[e,(l.get(e)??0)+36])])),c=i(n);c<o&&([s,o]=[n,c])}return s}function hg(e,t){for(let a of e)for(let e of["source","target"]){let s=a.pinned?.[e];void 0!==s&&t.set(pn({edgeId:a.edge.id,endpoint:e}),s)}return t}function hu(e,t,a,s){let i,l,o="orthogonal"===e.layout.edgeRouting,{anchors:r,endRun:n,placement:c}=hB.get(e)??{},d=s=>hg(s,t.ports?pM(s,t.repair,a.crossingRepair,dW(e)?54:pf):pu(s,t.repair)),{wrap:p}=a,h=function(e,t){let a=t?dq(e):void 0;if(!a||!t)return new Set;let s=new Map([["",a.top],...a.groups.map(e=>[e.group.id,e.diagram])]);return new Set([...t].flatMap(([e,{bandOf:t}])=>s.get(e).edges.filter(e=>(t.get(e.source)??0)!==(t.get(e.target)??0)).map(e=>e.id)))}(e,a.zoneWraps),{groups:g,lanes:u,nodes:f}=c?{nodes:e.nodes.map(e=>{let t=c.get(e.id);if(!t)throw Error(`Cannot render node "${e.id}" without a placement.`);return{...db(e),x:t.x,y:t.y,width:t.width,height:t.height}})}:dR(e,new Map,new Map,a,s),{direction:m}=e.layout,v=e=>void 0!==e&&void 0!==g&&g.across.has(e),y=e=>v(g?.groupOf.get(e))?dY[m]:m,w=e=>g&&v(dP(g,e.source,e.target))?dY[m]:m,x=new Map([...f,...d0(g)].map(e=>[e.nodeId,e])),b=e.edges.map((e,t)=>(function(e,t,a,s,i=!1){let l=a.get(e.source),o=a.get(e.target);if(!l||!o)throw Error(`Cannot render edge "${e.id}" with unresolved nodes.`);let{sourceEdge:r,targetEdge:n}=i?{sourceEdge:dE[s],targetEdge:pm[dE[s]]}:pl(l,o,s);return{edge:e,index:t,source:l,sourceEdge:r,target:o,targetEdge:n}})(e,t,x,w(e),p.continuations.has(e.id)));for(let e of b)if(h.has(e.edge.id)){let{source:t,target:a}=e,s={LR:a.x>=t.x+t.width,RL:a.x+a.width<=t.x,TB:a.y>=t.y+t.height,BT:a.y+a.height<=t.y}[m],i=dE[dY[m]];e.sourceEdge=s?dE[m]:i,e.targetEdge=pm[i]}if(n)for(let e of b)e.endRun=n;u&&pa(b,u);let k=o&&t.ports;for(let e of new Set(b.map(e=>y(e.source.nodeId))))pQ(b.filter(t=>y(t.source.nodeId)===e),e,k);if(u&&o&&function(e,t,a){let[s,i]=t.vertical?["x","y"]:["y","x"],l=dE[a],o=pv[l][i],r=e=>t.vertical?e<0?"left":"right":e<0?"top":"bottom";for(let a of new Set(e.filter(e=>dx(e.source.kind)).map(e=>e.source))){let n=e.filter(e=>e.source===a&&!pd(e));if(n.length>3)continue;let c=e=>t.laneOf.get(e.target.nodeId)===t.laneOf.get(a.nodeId)?0:Math.sign(pi(e.target)[s]-pi(a)[s]),d=e=>(pi(e.target)[i]-pi(a)[i])*o,p=t.vertical?"height":"width",h=e=>Math.min(a[i]+a[p],e.target[i]+e.target[p])-Math.max(a[i],e.target[i])>.01,g=new Set,u=[];for(let e of[-1,1]){let t=n.filter(t=>c(t)===e).sort((e,t)=>Number(h(t))-Number(h(e))||d(e)-d(t));t[0]&&(t[0].sourceEdge=r(e),g.add(r(e))),u.push(...t.slice(1))}for(let e of(u.push(...n.filter(e=>0===c(e))),u.sort((e,t)=>d(e)-d(t)))){let t=0>d(e)?[r(1),r(-1),l]:[l,r(-1),r(1)];e.sourceEdge=t.find(e=>!g.has(e))??l,g.add(e.sourceEdge)}}}(b,u,m),o){for(let t of(!function(e,t){let a=new Map;for(let s of e.filter(pd)){let i=t(s),l=pm[dE[i]],o=t=>e.filter(e=>!pd(e)&&(e.source===s.source&&e.sourceEdge===t||e.target===s.source&&e.targetEdge===t)).length,r=[..."TB"===i||"BT"===i?["right","left"]:["bottom","top"]].sort((e,t)=>o(e)-o(t)),n=[...r.map(e=>[e,l]),...r.map(e=>[e,dE[i]])],c=a.get(s.source.nodeId)??new Set,[d,p]=n.find(([e,t])=>!c.has(`${e}:${t}`))??n[0];c.add(`${d}:${p}`),a.set(s.source.nodeId,c),s.sourceEdge=d,s.targetEdge=p}}(b,e=>w(e.edge)),!function(e,t,a=()=>t.layout.direction){let s=d_(t);for(let t of e.filter(e=>s.has(e.edge.id)&&!pd(e))){let s=a(t),i="LR"===s||"RL"===s,l=i?pi(t.source).y<pi(t.target).y:pi(t.source).x<pi(t.target).x,o=[...i?l?["top","bottom"]:["bottom","top"]:l?["left","right"]:["right","left"],...i?["left","right"]:["top","bottom"]],r=new Set(e.filter(e=>e!==t&&e.source===t.target).map(e=>e.sourceEdge)),n=new Set(e.filter(e=>e!==t&&e.target===t.source).map(e=>e.targetEdge)),c=new Set(e.filter(e=>e!==t&&e.target===t.target).map(e=>e.targetEdge)),d=new Set(e.filter(e=>e!==t&&e.source===t.source).map(e=>e.sourceEdge)),p=dx(t.source.kind)?[t.sourceEdge,...o]:o;t.targetEdge=o.find(e=>!r.has(e)&&!c.has(e))??o.find(e=>!r.has(e))??t.targetEdge,t.sourceEdge=p.find(e=>!n.has(e)&&(!dx(t.source.kind)||!d.has(e))&&(t.source!==t.target||e!==t.targetEdge))??t.sourceEdge}}(b,e,e=>w(e.edge)),hB.get(e)?.pairedReturns&&function(e,t,a,s,i){for(let l of e){if(!t.has(l.edge.id)||pd(l)||i?.has(l.edge.id))continue;let o=e.find(e=>void 0===e.pair&&!i?.has(e.edge.id)&&!t.has(e.edge.id)&&e.source===l.target&&e.target===l.source&&e.targetEdge===pm[e.sourceEdge]);if(!o)continue;let[r,n]=[pi(l.source),pi(l.target)],c=new Set([l.source.nodeId,l.target.nodeId]),d=new Set([...c].flatMap(e=>s?dA(s,s.groupOf.get(e)??e):[e]));[...a.filter(e=>!c.has(e.nodeId)),...(s?.frames??[]).filter(e=>!d.has(e.id)).map(e=>d1(e.elementId,e.box))].some(e=>p_(r,n,e))||(l.sourceEdge=o.targetEdge,l.targetEdge=o.sourceEdge,o.pair=-1,l.pair=1)}}(b,d_(e),f,g,a.unpairedReturns),b)){let e=a.sides?.get(t.edge.id);e?.sourceEdge&&(t.sourceEdge=e.sourceEdge),e?.targetEdge&&(t.targetEdge=e.targetEdge)}u&&a.separateRoles&&function(e,t){let a=dE[t],s="TB"===t||"BT"===t?["left","right"]:["top","bottom"];for(let t of e){if(pd(t)||void 0!==t.pinned)continue;let i=t.source,l=t=>e.some(e=>e.target===i&&e.targetEdge===t),o=a=>e.some(e=>e!==t&&e.source===i&&e.sourceEdge===a);if(!l(t.sourceEdge))continue;let r=[a,...s].filter(e=>!l(e));t.sourceEdge=r.find(e=>!o(e))??r[0]??t.sourceEdge}}(b,m),r&&function(e,t){for(let a of e)for(let e of["source","target"]){let s=t.get(pn({edgeId:a.edge.id,endpoint:e}));s&&("source"===e?a.sourceEdge=s.side:a.targetEdge=s.side,a.pinned={...a.pinned,[e]:s.offset},void 0!==s.run&&(a.runs={...a.runs,[e]:s.run}))}}(b,r),i=d(b),l=function(e,t){let a=new Map;for(let s of e)for(let e of["source","target"]){let i=s[e];if(void 0!==dw(i))continue;let l="source"===e?s.sourceEdge:s.targetEdge,o="top"===l||"bottom"===l?"width":"height",r=2*(16+Math.abs(t.get(pn({edgeId:s.edge.id,endpoint:e}))??0));if(r<=(a.get(i.nodeId)?.[o]??i[o]))continue;let n=a.get(i.nodeId)??{width:i.width,height:i.height};n[o]=r,a.set(i.nodeId,"choice"!==i.kind||i.label?n:dy(n,0))}return a}(b,i)}else{let a=pB(b,e,f,t.repair);i=a.offsets,l=a.minimumSizes}let M=o&&!c&&(t.repair||g||u)?u?pS(b.filter(e=>e.edge.label||!pt(e,u)),i,!0):pS(b,i):new Map;if(!c&&(l.size>0||M.size>0)){({groups:g,lanes:u,nodes:f}=dR(e,l,M,a,s));let r=new Map([...f,...d0(g)].map(e=>[e.nodeId,e]));for(let t of b)t.source=r.get(t.source.nodeId),t.target=r.get(t.target.nodeId),o||Object.assign(t,pl(t.source,t.target,e.layout.direction));o?i=d(b):(u&&pa(b,u),pQ(b,e.layout.direction,k),i=pB(b,e,f,t.repair).offsets)}f=function(e,t,a,s){let i=new Map;for(let l of t){if(void 0===dw(l))continue;let o=e.filter(e=>e.source===l||e.target===l),r=o[0];if(1!==o.length||!r||pd(r))continue;let n=r.source===l?"target":"source",c=r[n],d="source"===n?r.sourceEdge:r.targetEdge;if(("source"===n?r.targetEdge:r.sourceEdge)!==pm[d])continue;let p=pw(d),h="x"===p?"width":"height",g=pr(c,d,s.get(pn({edgeId:r.edge.id,endpoint:n}))??0),u={...l,[p]:g[p]-l[h]/2},f=p6(u,18),m=a?.groupOf.get(l.nodeId),v=a?.frames.find(e=>e.id===m),y=new Set(a?dA(a,m):[]);t.every(e=>e===l||!p4(f,i.get(e.nodeId)??e))&&(a?.frames??[]).every(e=>y.has(e.id)||!p4(f,e.box)&&!p4(f,e.labelBox))&&(!v||f.x>=v.box.x&&f.y>=v.box.y&&f.x+f.width<=v.box.x+v.box.width&&f.y+f.height<=v.box.y+v.box.height)&&i.set(l.nodeId,u)}if(0===i.size)return t;for(let t of e)t.source=i.get(t.source.nodeId)??t.source,t.target=i.get(t.target.nodeId)??t.target;return t.map(e=>i.get(e.nodeId)??e)}(b,f,g,i),u?function(e,t,a){let s=t.vertical?"x":"y",i=t.vertical?"width":"height",l=e.filter(e=>a.continuations.has(e.edge.id));for(let e of l){let o=a.bandOf.get(e.source.nodeId)??0,[r,n]=[t.pools[o],t.pools[o+1]];if(!n)continue;let c=l.filter(e=>(a.bandOf.get(e.source.nodeId)??0)===o);e.lane=(r[s]+r[i]+n[s])/2+(c.indexOf(e)-(c.length-1)/2)*18}}(b,u,p):function(e,t,a){for(let s of e){if(!a.continuations.has(s.edge.id))continue;let e=a.bandOf.get(s.source.nodeId)??0,i="top"===s.sourceEdge||"bottom"===s.sourceEdge?"x":"y",l="x"===i?"width":"height",o=e=>t.filter(t=>(a.bandOf.get(t.nodeId)??0)===e);s.lane=(Math.max(...o(e).map(e=>e[i]+e[l]))+Math.min(...o(e+1).map(e=>e[i])))/2}}(b,f,p);let C=[...f,...d2(g),...pe(u)],z=s_({width:Math.max(...C.map(e=>e.x+e.width))-Math.min(...C.map(e=>e.x)),height:Math.max(...C.map(e=>e.y+e.height))-Math.min(...C.map(e=>e.y))}),_={guided:t.repair,...t.reader?{readerScale:z}:{},...p.continuations.size>0?{bandOf:p.bandOf}:{},...g?{groups:g}:{},...u?{lanes:u}:{},...a.avoidCrossings?{avoidCrossings:!0}:{}},L=hi(b,e.layout.edgeRouting,i,f,_);if(o&&t.sides){let t=hl(b,L,e,z,"hooked");if(t.length>0){let e=d(b),a=hi(b,"orthogonal",e,f,_),[s,l]=[L,a].map(e=>{var t,a,s;let i;return t=f,a=g,s=u,i=sq(e.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),z).length,{hard:ho(e,t,a,s).length,reader:i}});if(l.hard<=s.hard&&l.reader<s.reader)[L,i]=[a,e];else for(let{route:e,side:a}of t)e.targetEdge=a}let s=a.crossingRepair?hl(b,L,e,z,"crossed"):[];if(s.length>0){let e=d(b),t=hi(b,"orthogonal",e,f,_);if(ho(t,f,g,u).length<=ho(L,f,g,u).length&&hx({edgeArrows:t,...g?{groups:g}:{},...u?{lanes:u}:{},nodeShapes:f},{edgeArrows:L,...g?{groups:g}:{},...u?{lanes:u}:{},nodeShapes:f},!0,!1))[L,i]=[t,e];else for(let{route:e,side:t}of s)e.targetEdge=t}}return o&&t.repair&&(L=function(e,t,a,s,i){let l=ho(e,s,i.groups,i.lanes),o=t.map((e,t)=>t);for(let r=0;r<4&&l.length>0;r+=1){let r=e=>o.findIndex(a=>`edge:${t[a].edge.id}`===e),[n,c]=l[0],[d,p]=void 0===c?[0,r(n)]:[Math.min(r(n),r(c)),Math.max(r(n),r(c))];if(p<=d)break;let h=[...o];h.splice(d,0,...h.splice(p,1));let g=hi(t,"orthogonal",a,s,i,h),u=ho(g,s,i.groups,i.lanes);if(u.length>=l.length)break;[e,l,o]=[g,u,h]}return e}(L,b,i,f,_)),{edgeArrows:L,...g?{groups:g}:{},...u?{lanes:u}:{},nodeShapes:f,portOffsets:i,routeOptions:_,routedEdges:b}}function hf(e,t,a=[]){let s=[...e.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]),...t.flatMap(e=>e.points),...a.flatMap(e=>{let{width:t,height:a}=p1(e.text,e.maxWidth??160);return[{x:e.x-t/2,y:e.y-a/2},{x:e.x+t/2,y:e.y+a/2}]})];return{width:Math.max(...s.map(e=>e.x))-Math.min(...s.map(e=>e.x)),height:Math.max(...s.map(e=>e.y))-Math.min(...s.map(e=>e.y))}}function hm(e){return e.filter((t,a)=>{let[s,i]=[e[a-1],e[a+1]];return!s||!i||!(.01>=Math.abs(s.x-t.x)&&.01>=Math.abs(t.x-i.x)||.01>=Math.abs(s.y-t.y)&&.01>=Math.abs(t.y-i.y))})}function hv(e,t,a=0,s=!0){let i=s?hm(e.slice(Math.max(0,a))):e.slice(Math.max(0,a)),l=s?hm(t):t,o=(e,t,a)=>e>Math.min(t,a)+.01&&e<Math.max(t,a)-.01,r=(e,t)=>.01>=Math.abs(e.y-t.y)&&Math.abs(e.x-t.x)>.01,n=(e,t)=>.01>=Math.abs(e.x-t.x)&&Math.abs(e.y-t.y)>.01,c=0;for(let e=0;e<i.length-1;e+=1)for(let t=0;t<l.length-1;t+=1){let[a,s,d,p]=[i[e],i[e+1],l[t],l[t+1]],[h,g]=r(a,s)&&n(d,p)?[[a,s],[d,p]]:n(a,s)&&r(d,p)?[[d,p],[a,s]]:[];h&&g&&o(g[0].x,h[0].x,h[1].x)&&o(h[0].y,g[0].y,g[1].y)&&(c+=1)}return c}function hy(e,t=!0){return e.reduce((a,s,i)=>a+e.slice(i+1).reduce((e,a)=>e+hv(s.points,a.points,0,t),0),0)}function hw(e,t,a=!0){let s=s_(hf(t,e)),i=e.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),l=sF(i,s);return sq(i,s).filter(e=>a||"endpoint-jog"!==e.kind).length+i.filter(e=>l(e).arrowheadsCrossed>0).length}function hx(e,t,a=!1,s=!0,i=!1,l=!0){let[o,r]=[e,t].map(e=>hy(e.edgeArrows,s)),[n,c]=[e,t].map(e=>hf([...e.nodeShapes,...d2(e.groups),...pe(e.lanes)],e.edgeArrows)),[d,p]=[n,c].map(({width:e,height:t})=>d$(e,t));return(a?o<r:o<=r)&&(d<2.45||d<=p+.01||i&&(({width:e,height:t})=>Math.max(e,t))(n)<=(({width:e,height:t})=>Math.max(e,t))(c)+.01)&&hw(e.edgeArrows,[...e.nodeShapes,...d2(e.groups),...pe(e.lanes)],l)<=hw(t.edgeArrows,[...t.nodeShapes,...d2(t.groups),...pe(t.lanes)],l)}function hb(e){return e.edgeArrows.filter((t,a)=>{let s=e.routedEdges[a],i=sp(hm(t.points)).slice(1,-1);return["source","target"].some(e=>{let t=s[e],a="source"===e?s.sourceEdge:s.targetEdge;return i.some(e=>{let[s,i,l,o]="horizontal"===e.orientation?[t.y,t.height,t.x,t.width]:[t.x,t.width,t.y,t.height],r=e.staticCoordinate<s?s-e.staticCoordinate:e.staticCoordinate-s-i;return("horizontal"===e.orientation?e.staticCoordinate<s?"top":"bottom":e.staticCoordinate<s?"left":"right")!==a&&r>0&&r<72&&e.min<l+o&&e.max>l})})}).length}function hk(e){let t=e.map(e=>hm(e.points)),a=[],s=(e,t,a)=>e>Math.min(t,a)+.01&&e<Math.max(t,a)-.01;for(let[e,i]of t.entries())for(let[l,o]of t.slice(e+1).entries())for(let t=0;t+1<i.length;t+=1)for(let r=0;r+1<o.length;r+=1){let[n,c,d,p]=[i[t],i[t+1],o[r],o[r+1]],[h,g]=.01>=Math.abs(n.y-c.y)&&.01>=Math.abs(d.x-p.x)?[[n,c],[d,p]]:.01>=Math.abs(n.x-c.x)&&.01>=Math.abs(d.y-p.y)?[[d,p],[n,c]]:[];h&&g&&s(g[0].x,h[0].x,h[1].x)&&s(h[0].y,g[0].y,g[1].y)&&a.push({first:e,second:e+1+l,at:{x:g[0].x,y:h[0].y}})}return a}function hM(e,t,a,s,i){let l=a,o=new Set,[r,n]=[6,24];for(let a=!0;a&&r>0;){a=!1;let c=hy(l.layout.edgeArrows),d=hk(l.layout.edgeArrows).flatMap(({first:t,second:a,at:s})=>(function(e,t,a,s,i,l){let o="TB"===s.layout.direction||"BT"===s.layout.direction,r=o?"y":"x",n=e=>pw(e)===r?pm[e]:e,c=d_(s),d=e=>!pd(e)&&void 0===e.pair&&void 0===e.pinned,p=e=>"source"===e?"sourceEdge":"targetEdge",h=(e,t,a)=>{if(pw(a)===r)return!0;let s=pi(e[t])[r],i=pi(e["source"===t?"target":"source"])[r];return pv[a][r]*(i-s)>.01},g=[],u=(e,t)=>f.get(e.edge.id)?.[p(t)]??e[p(t)],f=new Map,m=e=>{f=e,[...e].every(([e,t])=>{let a=l.find(t=>t.edge.id===e);return h(a,"source",t.sourceEdge??a.sourceEdge)&&h(a,"target",t.targetEdge??a.targetEdge)})&&!(dW(s)&&[...f.keys()].some(e=>{let t=l.find(t=>t.edge.id===e);return["source","target"].some(e=>{let a="source"===e?"target":"source",s=t[e],i=u(t,e);return l.some(e=>e!==t&&e[a]===s&&u(e,a)===i)})}))&&g.push(e)},v=o?["left","right"]:["top","bottom"];for(let a of[e,t].filter(d))if(c.has(a.edge.id))for(let e of[...v].sort((e,t)=>e===n(a.sourceEdge)?-1:+(t===n(a.sourceEdge))))(a.sourceEdge!==e||a.targetEdge!==e)&&m(new Map([[a.edge.id,{sourceEdge:e,targetEdge:e}]]));if(d(e)&&d(t))for(let a of["source","target"])for(let s of["source","target"]){let[i,l]=[e[p(a)],t[p(s)]];e[a].nodeId===t[s].nodeId&&i!==l&&m(new Map([[e.edge.id,{[p(a)]:l}],[t.edge.id,{[p(s)]:i}]]))}for(let a of new Set([e,t].map(e=>e.source))){if(!dx(a.kind))continue;let e=l.filter(e=>e.source===a&&d(e)&&!c.has(e.edge.id));if(e.length<2||e.length>3)continue;let t=e=>e.length<=1?[[...e]]:e.flatMap((a,s)=>t([...e.slice(0,s),...e.slice(s+1)]).map(e=>[a,...e]));for(let a of t(e.map(e=>e.sourceEdge))){let t=new Map(e.flatMap((e,t)=>a[t]===e.sourceEdge?[]:[[e.edge.id,{sourceEdge:a[t]}]]));t.size>0&&m(t)}}for(let{endpoint:s,route:l}of[e,t].filter(d).flatMap(e=>["source","target"].map(t=>{let{start:s,end:l}=pz(e,i),o="source"===t?s:l;return{endpoint:t,route:e,distance:Math.abs(o.x-a.x)+Math.abs(o.y-a.y)}})).sort((e,t)=>e.distance-t.distance)){let e=l[p(s)],t=pi(l[s]),a=pi(l["source"===s?"target":"source"]);for(let i of new Set([Math.abs(a.x-t.x)>Math.abs(a.y-t.y)?a.x>t.x?"right":"left":a.y>t.y?"bottom":"top",n(e),"top","right","bottom","left"]))i!==e&&m(new Map([[l.edge.id,{[p(s)]:i}]]))}return g})(l.layout.routedEdges[t],l.layout.routedEdges[a],s,e,l.layout.portOffsets??new Map,l.layout.routedEdges)),p=3;for(let h of d){if(0===r||0===p||0===n)break;let d=new Map(l.arrangement.sides);for(let[e,t]of h)d.set(e,{...d.get(e),...t});let g=JSON.stringify([...d].sort(([e],[t])=>e<t?-1:1));if(o.has(g)||(o.add(g),n-=1,function(e,t,a){let{layout:s}=e;if(!s.portOffsets||!s.routeOptions)return 0;let i=s.routedEdges.map(e=>({...e,...t.get(e.edge.id)})),l=hg(i,a.ports?pM(i,a.repair,e.arrangement.crossingRepair,s.lanes?54:pf):pu(i,a.repair)),o=new Set(i.flatMap(e=>t.has(e.edge.id)||["source","target"].some(t=>{let a=pn({edgeId:e.edge.id,endpoint:t});return l.get(a)!==s.portOffsets.get(a)})?[e.edge.id]:[])),r=(e,t)=>{let a=new Map(e.flatMap(e=>t.has(e.edgeId)?[]:[[e.edgeId,e]])),o=i.map((e,a)=>({index:a,again:t.has(e.edge.id)})).sort((e,t)=>Number(e.again)-Number(t.again)).map(({index:e})=>e);return hi(i,"orthogonal",l,s.nodeShapes,{...s.routeOptions,avoidCrossings:!0},o,a)},n=r(s.edgeArrows,o),c=new Set(hk(n).flatMap(({first:e,second:t})=>{let[a,s]=[i[e].edge.id,i[t].edge.id];return o.has(a)===o.has(s)?[]:[o.has(a)?s:a]}));return 0===c.size?hy(n):Math.min(hy(n),hy(r(n,c)))}(l,h,t)>=c))continue;[r,p]=[r-1,p-1];let u={...l.arrangement,sides:d,avoidCrossings:!0},f=hh(e,t,u),m=s(f);if(!i(l.defects,m)&&hx(f,l.layout,!0,!0,!0)&&hb(f)<=hb(l.layout)){l={arrangement:u,defects:m,layout:f},a=!0;break}}}return l}let hC={initial:"circle",final:"circle","final-core":"circle",choice:"diamond"},hz={initial:"Initial state",final:"Final state","final-core":"Final state",choice:"Choice"},h_="#4c4639",hL={subnet:"#f6f1e7",namespace:"#efe6ec"},hB=new WeakMap;function hS(e,t={}){var a,s;let i,l,o,r,n;hB.set(e,t);let c=e=>[ho(e.edgeArrows,e.nodeShapes,e.groups,e.lanes).length,hr(e.edgeArrows,e.nodeShapes)],d=(e,t)=>e[0]<t[0]||e[0]===t[0]&&e[1]<t[1],p="orthogonal"===e.layout.edgeRouting?[{ports:!0,reader:!0,sides:!0,repair:!0},{ports:!0,reader:!0,sides:!1,repair:!0},{ports:!0,reader:!1,sides:!1,repair:!0},{ports:!1,reader:!1,sides:!1,repair:!0},hd]:[{...hd,repair:!0},hd],h=(t=>{let[a,...s]=p,i=hh(e,a,t),l=c(i);for(let a of s){if(0===l[0]&&0===l[1])break;let s=hh(e,a,t),o=c(s);d(o,l)&&([i,l]=[s,o])}return{arrangement:t,defects:l,layout:i}})(dT),g=void 0===t.placement,u=(t,a)=>{let s=hh(e,p[0],t),i=c(s);!d(h.defects,i)&&hx(s,h.layout,a,!1)&&(h={arrangement:t,defects:i,layout:s})},f="orthogonal"===e.layout.edgeRouting,m=g&&f&&e.edges.length<=24;m&&hy(h.layout.edgeArrows,!1)>0&&u({...h.arrangement,crossingRepair:!0},!1),m&&hy(h.layout.edgeArrows,!1)>0&&function(e){if(dW(e))return!1;let t=dq(e);return(t?[t.top,...t.groups.map(e=>e.diagram)]:[e]).some(e=>{let[t,a]=[!1,!0].map(t=>dU(e,new Map,new Map,t).rankMetrics.map(e=>e.shapes.map(e=>e.nodeId).join("\n")).join("\n\n"));return t!==a})}(e)&&u({...h.arrangement,reorder:!0},!0);let v="TB"===e.layout.direction||"BT"===e.layout.direction,y=e=>{let t=hf([...e.nodeShapes,...d2(e.groups),...pe(e.lanes)],e.edgeArrows,[...he([...e.edgeArrows],e.routedEdges,e.nodeShapes,e.groups,!1,e.lanes)]),[a,s]=v?[t.height,t.width]:[t.width,t.height],i=(a+40)/(s+40),l=28e3/(Math.max(a,s)+40);return{aspect:i,balance:v&&i<4&&l>=14?.6:0,size:t,tooLong:i>=4||i>=2.45&&(v||a>=1200)}},{aspect:w,balance:x,tooLong:b}=y(h.layout),k=g&&f&&b?dW(e)?w>=4?function(e){let t,{columnCount:a,columns:s,depth:i,gapAfter:l,headerSize:o,poolBreadth:r}=dJ(e,new Map,new Map);if(a<4)return dX;let n=d_(e),c=Array.from({length:a-1},(t,a)=>{let i=e.edges.filter(e=>{let[t,i]=(e=>{let[t,a]=[s.get(e.source),s.get(e.target)];return[Math.min(t,a),Math.max(t,a)]})(e);return t<=a&&i>a});return i.some(e=>n.has(e.id))||i.length>2?void 0:i.map(e=>e.id)}),d=(e,t)=>o+96+i.slice(e,t+1).reduce((e,t)=>e+t,0)+l.slice(e,t).reduce((e,t)=>e+t,0),p=a-1,h=d$(d(0,p),r),g=(e,t)=>!t||e.longest<t.longest-.01||.01>=Math.abs(e.longest-t.longest)&&(e.carried<t.carried||e.carried===t.carried&&e.squares<t.squares);for(let e=2;e<=6;e+=1){let a,s=new Map;for(let e=1;e<p;e+=1)void 0!==c[e]&&s.set(e,{cuts:[e],longest:d(0,e),carried:c[e].length,squares:d(0,e)**2});for(let t=2;t<e;t+=1){let e=new Map;for(let[t,a]of s)for(let s=t+2;s<p;s+=1){if(void 0===c[s])continue;let i=d(t+1,s),l={cuts:[...a.cuts,s],longest:Math.max(a.longest,i),carried:a.carried+c[s].length,squares:a.squares+i**2};g(l,e.get(s))&&e.set(s,l)}s=e}for(let[e,t]of s){if(p<e+2)continue;let s=d(e+1,p),i={...t,longest:Math.max(t.longest,s),squares:t.squares+s**2};g(i,a)&&(a=i)}if(!a)continue;let i=e*r+(e-1)*dK(2),l=d$(a.longest,i);if((!t||l<t.aspect)&&(t={aspect:l,cuts:a.cuts}),l<=2)break}return!t||t.aspect>=h?dX:{bandOf:new Map(e.nodes.map(e=>{let a;return[e.id,(a=s.get(e.id),t.cuts.filter(e=>e<a).length)]})),continuations:new Set(t.cuts.flatMap(e=>c[e]))}}(e):dX:dG(e,h.arrangement.reorder,x):dX;for(let e of m&&!h.arrangement.crossingRepair?[!0,!1]:[h.arrangement.crossingRepair]){if(0===k.continuations.size||h.arrangement.wrap===k)break;u({...h.arrangement,crossingRepair:e,wrap:k},!1)}let M=dq(e),C=g&&f&&b&&void 0!==M&&!M.zoned;for(let e of m&&!h.arrangement.crossingRepair?[!0,!1]:[h.arrangement.crossingRepair]){if(!C||h.arrangement.groupsAcross)break;u({...h.arrangement,crossingRepair:e,groupsAcross:!0},!1)}let z=e=>[hy(e.edgeArrows,!1),hw(e.edgeArrows,[...e.nodeShapes,...d2(e.groups)]),y(e).aspect],_=(e,t)=>{let a=e.findIndex((e,a)=>e!==t[a]);return a>=0&&e[a]<t[a]};for(let t=0;t<2&&g&&f&&M?.zoned;t+=1){let t,a=y(h.layout);if(!a.tooLong)break;let s=h;for(let i of function(e,t,a,s,i){let l=new Map([["",t.top],...t.groups.map(e=>[e.group.id,e.diagram])]),o=function(e){let t=new Map(e.groups.map(e=>[e.group.id,e])),a=new Map,s=e=>{for(let a of e.children)s(t.get(a));let{rankMetrics:i}=dU(e.diagram,new Map,new Map),l=i.reduce((e,t)=>e+Math.max(...t.shapes.map(e=>a.get(e.nodeId)??1)),0);return a.set(dH(e.group.id),Math.max(2,l)),l};for(let t of e.groups)e.parentOf.has(t.group.id)||s(t);return a}(t),r=t=>{let s=dR(e,new Map,new Map,{...a,zoneWraps:t});return{bounds:dZ([...s.nodes,...d2(s.groups)]),placed:s}},n=new Map(a.zoneWraps??[]),c=r(n),[d,p]=[i.width/c.bounds.width,i.height/c.bounds.height],h=e=>{let{bounds:t,placed:a}=r(e);return{aspect:d$(t.width*d,t.height*p),placed:a}},g=(e,t)=>{let[a,s]=[e,t].map(e=>e.aspect<=2);return a!==s?a?-1:1:a&&e.bands-t.bands||e.aspect-t.aspect},u=n.size,f=h(n),m=[];for(;f.aspect>2;){let e=new Map([...f.placed.nodes.map(e=>[e.nodeId,e]),...(f.placed.groups?.frames??[]).map(e=>[dH(e.id),e.box])]),t=[];for(let[i,r]of l)if(!n.has(i))for(let l=2;l<=6;l+=1){let c=dG(r,a.reorder,s,{bands:l,sizes:e,weights:o});if(0===c.bandOf.size)continue;let d=new Map([...n,[i,c]]);if(t.push({...h(d),bands:l,next:d}),t.at(-1).aspect<=2)break}let i=t.filter(e=>e.aspect<f.aspect).sort(g),[r]=i;if(!r)break;n.size===u&&m.push(...i.slice(1,3).map(e=>e.next)),n=r.next,f=r}return n.size>u?[n,...m]:[]}(e,M,s.arrangement,a.balance,a.size)){let a={...s.arrangement,crossingRepair:m||s.arrangement.crossingRepair,zoneWraps:i},l=hh(e,p[0],a),o=c(l);if(d(s.defects,o)||!hx(l,s.layout,!1,!1,!1,!1))continue;let r=z(l);(!t||_(r,t.score))&&(t={arrangement:a,defects:o,layout:l,score:r});let[n,h]=z(s.layout);if(r[0]<=n&&r[1]<=h)break}if(!t)break;h=t}g&&f&&dW(e)&&u({...h.arrangement,separateRoles:!0},!1);let L=hy(h.layout.edgeArrows);if(m&&L>0&&L<=6&&(h=hM(e,p[0],h,c,d)),t.pairedReturns&&hy(h.layout.edgeArrows)>0){let t=h,a=new Map(h.layout.edgeArrows.map(e=>[e.edgeId,e])),s=new Set;for(let e of h.layout.routedEdges){let t=a.get(e.edge.id);if(void 0!==e.pair&&t&&h.layout.edgeArrows.some(e=>e!==t&&hy([t,e])>0))for(let t of h.layout.routedEdges)void 0!==t.pair&&(t.edge.id===e.edge.id||t.edge.source===e.edge.target&&t.edge.target===e.edge.source)&&s.add(t.edge.id)}if(s.size>0){u({...h.arrangement,unpairedReturns:s},!0);let a=hy(h.layout.edgeArrows);h!==t&&m&&a>0&&a<=6&&(h=hM(e,p[0],h,c,d));let i=new Set(h.layout.routedEdges.filter(e=>void 0!==e.pair).map(e=>e.edge.id));t.layout.routedEdges.some(e=>void 0!==e.pair&&!s.has(e.edge.id)&&!i.has(e.edge.id))&&(h=t)}}let B=f?function(e){let t,{groups:a,lanes:s,nodeShapes:i,routedEdges:l}=e,o=e.edgeArrows,r=[...i,...d2(a),...pe(s)],n=e=>({crossings:hy(e),defects:ho(e,i,a,s).length,findings:hw(e,r),inward:hr(e,i),labels:ht([...e],l,i,a,!0,s).touches});for(let[a,s]of e.edgeArrows.entries()){let e=new Set([s.sourceNodeId,s.targetNodeId]),l=pE(s.points,i,e);if(0!==l)for(let r of(t??=n(o),function(e,t,a){let s=hm(e),i=[];for(let e of sp(s))if(!e.isFirstSegment&&!e.isLastSegment)for(let l of t){if(!pH(l,a)||su(e,l)||!pV(e,l,12))continue;let[t,o]="horizontal"===e.orientation?[l.y,l.height]:[l.x,l.width];for(let a of[t-12-1,t+o+12+1]){let t=s.map((t,s)=>s===e.segmentIndex||s===e.segmentIndex+1?"horizontal"===e.orientation?{x:t.x,y:a}:{x:a,y:t.y}:t);(function(e,t){if(t.length!==e.length||!hs(t))return!1;let a=(e,t,a)=>({dx:e[a].x-e[t].x,dy:e[a].y-e[t].y}),s=e.length-1;return[[0,1],[s,s-1]].every(([s,i])=>{let[l,o]=[a(e,s,i),a(t,s,i)],r=Math.abs(l.dx)+Math.abs(l.dy);return Math.sign(o.dx)===Math.sign(l.dx)&&Math.sign(o.dy)===Math.sign(l.dy)&&Math.abs(o.dx)+Math.abs(o.dy)>=Math.min(r,36)-.01})})(s,t)&&i.push(pA(t))}}return i}(s.points,i,e))){if(!hs(r)||pE(r,i,e)>=l)continue;let s=o.map((e,t)=>t===a?{...e,points:r}:e),c=n(s);if(c.defects<=t.defects&&c.crossings<=t.crossings&&c.findings<=t.findings&&c.inward<=t.inward&&c.labels<=t.labels){[o,t]=[s,c];break}}}return o===e.edgeArrows?e:{...e,edgeArrows:o}}(h.layout):h.layout,{groups:S,lanes:A,routedEdges:P}=B,V=[...B.edgeArrows],H={arrows:V,frames:[],labels:[...B.nodeShapes.filter(e=>e.label).map(ps),...he(V,P,B.nodeShapes,S,!0,A)],nodes:B.nodeShapes},q=S&&!S.zoned?function(e,t){let a=new Map(e.frames.map(e=>[e.id,e])),s=t=>{let s=e.groupOf.get(t);return void 0===s?void 0:a.get(s)},i=new Map(t.labels.map(e=>[e.id,e])),l=new Map;for(let e of t.arrows){let t=s(e.sourceNodeId);if(!t||t!==s(e.targetNodeId))continue;let a=i.get(`${e.id}:label`),o=a?p1(a.text,a.maxWidth??160):void 0;(!a||!o||[{x:a.x-o.width/2,y:a.y-o.height/2},{x:a.x+o.width/2,y:a.y+o.height/2}].every(e=>d6(e,t.box)))&&e.points.every(e=>d6(e,t.box))&&l.set(e.id,t.elementId)}let o=new Map(t.nodes.flatMap(e=>{let t=s(e.nodeId);return t?[[e.id,t.elementId]]:[]}));return{arrows:t.arrows.map(e=>{let t=l.get(e.id);return t?{...e,frameId:t}:e}),frames:e.frames.map(t=>({type:"frame",id:t.elementId,name:t.label,...e.composites.has(t.id)?{nodeId:t.id}:{},...t.box})),labels:t.labels.map(e=>{let t=e.containerId?o.get(e.containerId):l.get(e.id.slice(0,-6));return t?{...e,frameId:t}:e}),nodes:t.nodes.map(e=>{let t=o.get(e.id);return t?{...e,frameId:t}:e})}}(S,H):H,{arrows:F,frames:I,labels:E}=q,O=q.nodes.flatMap(t=>(function(e,t){if(e.label)return[e];let a={...e,label:hz[e.kind??""]??"Marker",rendererRole:"state-marker"};if("initial"===e.kind)return[{...a,fillColor:t,fillStyle:"solid"}];if("final"!==e.kind)return[a];let s=[`marker:${e.nodeId}`,...e.groupIds??[]];return[{...a,groupIds:s},{...a,id:`${e.id}:core`,nodeId:`${e.nodeId}:core`,kind:"final-core",groupIds:s,x:e.x+6,y:e.y+6,width:e.width-12,height:e.height-12,fillColor:t,fillStyle:"solid"}]})(t,e.style.accentColor)),U=A?A.frames.flatMap(e=>{let t=d7(e),a={type:"node",id:`${t}:header`,nodeId:`${t}:header`,kind:"lane-header",rendererRole:"swimlane-header",shape:"rectangle",...e.header,label:e.text,fillColor:"#f6f1e7",fillStyle:"solid",roughness:0,strokeWidth:1,locked:!0};return[{type:"node",id:t,nodeId:t,kind:"lane",rendererRole:"swimlane",shape:"rectangle",...e.box,label:e.label,roughness:0,strokeWidth:1,locked:!0},a,{type:"text",id:`${t}:label`,containerId:a.id,x:a.x+a.width/2,y:a.y+a.height/2,text:e.text,fontSize:16,maxWidth:Math.max(1,a.width-32),locked:!0}]}):S?.zoned?(a=e.style.accentColor,S.frames.flatMap(e=>{var t;let s,i=Math.max(1,e.box.width-24);return[{type:"node",id:e.elementId,nodeId:e.elementId,kind:e.kind??"zone",rendererRole:"zone",shape:"rectangle",...e.box,label:e.label,...(t=e.kind,s=void 0===t?void 0:hL[t],{strokeColor:"cloud"===t||"datacenter"===t?h_:a,strokeStyle:"cloud"===t||"region"===t||"namespace"===t?"dashed":"zone"===t?"dotted":"solid",strokeWidth:"cloud"===t||"datacenter"===t||"vpc"===t||"cluster"===t?2:1,...s?{fillColor:s,fillStyle:"solid"}:{}}),roughness:0,locked:!0},{type:"text",id:`zone-label:${e.id}`,x:e.box.x+12+aF(e.label,dS,i)/2,y:e.box.y+18,text:e.label,fontSize:dS,maxWidth:i,textAlign:"left",textColor:h_,locked:!0}]})):[],X=(r=Math.max(0,48-(o={x:Math.min(...(l=hn(s=[...U,...I,...F,...O,...E])).map(e=>e.x)),y:Math.min(...l.map(e=>e.y))}).x),n=Math.max(0,48-o.y),0===r&&0===n?[...s]:s.map(e=>"arrow"===e.type?{...e,points:function(e,t,a){let[s,...i]=e;return[hc(s,t,a),...i.map(e=>hc(e,t,a))]}(e.points,r,n)}:"line"===e.type?{...e,points:function(e,t,a){let[s,i,...l]=e;return[hc(s,t,a),hc(i,t,a),...l.map(e=>hc(e,t,a))]}(e.points,r,n)}:{...e,x:e.x+r,y:e.y+n})),T={width:Math.max(...(i=hn(X)).map(e=>e.x))+48,height:Math.max(...i.map(e=>e.y))+48},Y=[...U.map(e=>e.id),...I.map(e=>e.id),...O.map(e=>e.id),...E.map(e=>e.id),...F.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:T.width,height:T.height,accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:X,layers:[],layouts:[],zOrder:Y}}function hA(e,t){if(!t.nodeId.endsWith(eI)||t.id!==`node:${t.nodeId}`||"rectangle"!==t.shape||2!==t.width||t.height<120)return!1;let a=t.nodeId.slice(0,-eI.length);if(0===a.length)return!1;let s=e.elements.find(e=>"node"===e.type&&e.id===`node:${a}`&&e.nodeId===a);return!!s&&.01>=Math.abs(t.x+t.width/2-(s.x+s.width/2))&&t.y>=s.y+s.height-.01}let hP=":initial";function hV(e,t,a,s){let i=0,l=new Map,o=new Map,r=(e,a,s)=>{let i=2*e+ +(a>=t[e]);l.set(i,(l.get(i)??0)+1);let r=1e6*i+Math.round(2*s);o.set(r,(o.get(r)??0)+1)};for(let{parent:a,child:l,link:o}of e.pairs)i+=function(e,t,a){let s=t-e;return 1===s?0:-1===s?.4:0===s?a:2.5*(Math.abs(s)-1)+.4*(s<0)}(t[a],t[l],s),r(a,t[l],o.parentY),r(l,t[a],o.childY);for(let e of l.values())i+=.4*e*(e-1)/2;for(let e of o.values())i+=+Math.max(0,e-2);let n=new Map,c=new Map;for(let[a,s]of e.tables.entries()){let e=t[a];n.set(e,(n.get(e)??-56)+s.height+56),c.set(e,Math.max(c.get(e)??0,s.width))}for(let e of n.values()){let t=Math.max(0,e-a.height)/a.unit;i+=1.5*t*t}let d=Math.max(0,[...c.values()].reduce((e,t)=>e+t,0)+150*Math.max(0,c.size-1)-a.width)/a.column;return i+1.5*d*d}function hH(e){let t=new Map([...new Set(e)].sort((e,t)=>e-t).map((e,t)=>[e,t]));return e.map(e=>t.get(e))}function hq(e){let t=e.tables.map(()=>new Set);for(let{parent:a,child:s}of e.pairs)t[a].add(s),t[s].add(a);return t}function hF(e,t,a,s){let i=hq(e),l=e.tables.map((e,t)=>t).sort((e,t)=>i[t].size-i[e].size||e-t),o=s(t);for(let e=0;e<a;e+=1){let e=!1;for(let a of l){let l=t[a],r=new Set([l-2,l-1,l+1,l+2]);for(let e of i[a])for(let a of[-1,0,1])r.add(t[e]+a);if(0===i[a].size)for(let e of t)r.add(e);r.delete(l);let n=l;for(let e of[...r].sort((e,t)=>e-t)){t[a]=e;let i=s(t);i<o-1e-9&&([n,o]=[e,i])}t[a]=n,n!==l&&(e=!0)}if(!e)break}}function hI(e,t){let a=[...t],s=e.tables.map(e=>e.height),i=e.tables.map(()=>void 0),l=[];for(let{parent:o,child:r,link:n}of e.pairs){let[e,c]=[t[o],t[r]];if(1>=Math.abs(c-e)){l.push({a:o,b:r,aY:n.parentY,bY:n.childY});continue}let d=Math.sign(c-e),p={item:o,y:n.parentY};for(let t=e+d;t!==c;t+=d){let e=a.length;a.push(t),s.push(4),i.push({parent:o,y:n.parentY}),l.push({a:p.item,b:e,aY:p.y,bY:2}),p={item:e,y:2}}l.push({a:p.item,b:r,aY:p.y,bY:n.childY})}return{column:a,height:s,corridor:i,segments:l}}function hE(e,t,a){let s=[t,a].filter(t=>void 0!==e.corridor[t]).length;return 2===s?20:1===s?26:56}function hO(e,t){let a=[],s=0;for(let[i,l]of t.entries())i>0&&(s+=hE(e,t[i-1],l)),a.push(s),s+=e.height[l];return a}function hU(e,t){let a=e.column.map(()=>0);for(let s of t)hX(e,a,s);return a}function hX(e,t,a){let s=hO(e,a),i=a.length>0?s.at(-1)+e.height[a.at(-1)]:0;for(let[e,l]of a.entries())t[l]=s[e]-i/2}function hT(e,t){let a=new Map,s=new Map,i=[],l=(e,t,a)=>{let i=2*e+ +!!t,l=s.get(i);l?l.push(a):s.set(i,[a])};for(let{a:s,b:o,aY:r,bY:n}of e.segments){let[c,d]=[e.column[s],e.column[o]],[p,h]=[t[s]+r,t[o]+n];if(c===d){i.push(c,Math.min(p,h),Math.max(p,h));continue}l(c,d>c,p),l(d,c>d,h);let g=Math.min(c,d),u=a.get(g),f=c<d?[p,h]:[h,p];u?u.push(...f):a.set(g,f)}let o=0;for(let e of a.values())for(let t=0;t<e.length;t+=2)for(let a=t+2;a<e.length;a+=2)(e[t]-e[a])*(e[t+1]-e[a+1])<0&&(o+=1);for(let e=0;e<i.length;e+=3){let[t,a,l]=[i[e],i[e+1],i[e+2]],r=e=>{let i=0;for(let o of s.get(2*t+e)??[])o>a&&o<l&&(i+=1);return i};o+=Math.min(r(0),r(1))}return o}function hY(e){let t=e.column.map(()=>[]);for(let{a,b:s,aY:i,bY:l}of e.segments)t[a].push({other:s,ownY:i,otherY:l}),t[s].push({other:a,ownY:l,otherY:i});return t}function h$(e,t=!0){let a=Array.from({length:Math.max(...e.column)+1},()=>[]);for(let[t,s]of e.column.entries())a[s].push(t);let s=hY(e),i=hU(e,a),l={columns:a.map(e=>[...e]),crossings:hT(e,i)};for(let t=0;t<8&&l.crossings>0;t+=1){let o=[...a.keys()];for(let l of(t%2==1&&o.reverse(),o)){let t=new Map;for(let o of a[l]){let a=0,r=0;for(let{other:t,ownY:n,otherY:c}of s[o]){let s=e.column[t]===l?.5:1;a+=s*(i[t]+c-n),r+=s}t.set(o,r>0?a/r:i[o])}a[l]=[...a[l]].sort((e,a)=>t.get(e)-t.get(a)||i[e]-i[a]),hX(e,i,a[l])}let r=hT(e,i);r<l.crossings&&(l={columns:a.map(e=>[...e]),crossings:r})}i=hU(e,a=l.columns);let o=hT(e,i);for(let s=t&&o>0;s;)for(let t of(s=!1,a))for(let i=0;i+1<t.length;i+=1){[t[i],t[i+1]]=[t[i+1],t[i]];let l=hT(e,hU(e,a));l<o?(o=l,s=!0):[t[i],t[i+1]]=[t[i+1],t[i]]}return{columns:a,top:hU(e,a),crossings:o}}let hG={one:"crowfoot_one","zero-or-one":"crowfoot_one",many:"crowfoot_many","one-or-many":"crowfoot_one_or_many","zero-or-many":"crowfoot_many"};function hD(e){return"one"===e||"zero-or-one"===e}let hR=e=>Math.ceil(Math.max(0,...e.map(e=>aq(e,14))));function hZ(e,t){return t.get(e.link[e.end].entity).y+e.row}function hj(e,t){return t.get(e.link[e.end].entity).y+e.y}function hN(e,t){return 1>Math.abs(e.x+e.width/2-(t.x+t.width/2))}function hW(e,t,a){return hN(e.get(t.link[t.end].entity),e.get(a.link[a.end].entity))}function hJ(e,t){let a=t.get(e.link[e.end].entity),s=[...t.values()].filter(e=>hN(e,a));return"left"===e.side?a.x-Math.min(...s.map(e=>e.x)):Math.max(...s.map(e=>e.x+e.width))-(a.x+a.width)}function hK(e,t){return e.find(e=>e.link===t.link&&e!==t)}function hQ(e){let t=new Map;for(let a of e){if("top"===a.side)continue;let e=`${a.link[a.end].entity}\0${a.side}\0${a.row}`;t.set(e,[...t.get(e)??[],a])}return[...t.values()]}function h1(e,t){let a=e.flatMap(e=>{let a=t.sides.get(e.relationship.id);return["parent","child"].map(t=>({link:e,end:t,side:a[t],row:e[t].y,y:e[t].y}))});for(let t of e){if(t.parent.entity!==t.child.entity)continue;let[e,s]=a.filter(e=>e.link===t);e&&s&&e.row===s.row&&(s.side="top")}return a}function h0(e,t,a,s,i){let l=function(e,t){let a=hQ(e),s=e=>(20===e.row?40:28)/2-3,i=new Map;for(let l of a){if(l.length<2)continue;let a=a=>hZ(hK(e,a),t)-hZ(a,t),o=l.filter(e=>0>a(e)).sort((e,t)=>a(e)-a(t)),r=l.filter(e=>a(e)>0).sort((e,t)=>a(e)-a(t)),n=[...o,...l.filter(e=>0===a(e)),...r],c=Math.min(22,2*s(l[0])/(n.length-1));n.forEach((e,t)=>{e.y=e.row+(t-(n.length-1)/2)*c});let d=(e,a)=>i.set(e,hJ(e,t)+48+32*a);o.forEach(d),r.toReversed().forEach(d)}for(let i of a){if(i.length>1)continue;let a=i[0],l=hK(e,a);if(l.side===a.side||"top"===l.side)continue;let o=hj(l,t)-(hZ(a,t)-a.row);Math.abs(o-a.row)<=s(a)&&(a.y=o)}for(let a of e)"top"!==a.side&&!i.has(a)&&hJ(a,t)>0&&i.set(a,hJ(a,t)+48);let l=new Map;for(let t of e){if("top"===t.side)continue;let e=`${t.link[t.end].entity}\0${t.side}`;l.set(e,[...l.get(e)??[],t])}for(let e of l.values()){let{height:a}=t.get(e[0].link[e[0].end].entity);!function(e,t,a){if(e.length<2)return;let s=(t,a)=>e[a].row===e[a-1].row?t:Math.max(t,9),i=i=>{let l=-1/0;for(let[o,r]of e.entries())if((l=Math.max(t(r),o>0?l+s(i,o):l))>a(r)+1e-9)return!1;return!0},[l,o]=[0,22];if(i(o))l=o;else for(let e=0;e<24;e+=1){let e=(l+o)/2;i(e)?l=e:o=e}let r=e.map(a);for(let t=e.length-2;t>=0;t-=1)r[t]=Math.min(r[t],r[t+1]-s(l,t+1));let n=-1/0;for(let[a,i]of e.entries()){let e=a>0?n+s(l,a):-1/0;i.y=Math.min(Math.max(i.y,t(i),e),r[a]),n=i.y}}(e.sort((e,t)=>e.row-t.row||e.y-t.y),e=>Math.max(e.row-s(e),16),e=>Math.min(e.row+s(e),a-16))}return i}(i,s.boxes);!function(e,t,a){let s=e.filter(e=>"parent"===e.end).flatMap(a=>{let s=hK(e,a);return a.side===s.side&&"top"!==a.side&&hW(t,a,s)?[{parent:a,child:s}]:[]}).sort((e,a)=>Math.abs(hj(e.parent,t)-hj(e.child,t))-Math.abs(hj(a.parent,t)-hj(a.child,t))),i=[];for(let{parent:e,child:l}of s){let[s,o]=[t.get(e.link.parent.entity),t.get(e.link.child.entity)],r=e=>(a.get(e)??hJ(e,t)+48)-hJ(e,t),n=Math.max(r(e),r(l)),[c,d]=[hj(e,t),hj(l,t)].sort((e,t)=>e-t),p=i.filter(a=>a.end.side===e.side&&hW(t,a.end,e)&&a.top<=d&&c<=a.bottom);if("left"===e.side){let r=Math.min(s.x-hJ(e,t)-n,...p.map(e=>e.tip-32));a.set(e,s.x-r),a.set(l,o.x-r),i.push({end:e,top:c,bottom:d,tip:r})}else{let r=Math.max(s.x+s.width+hJ(e,t)+n,...p.map(e=>e.tip+32));a.set(e,r-s.x-s.width),a.set(l,r-o.x-o.width),i.push({end:e,top:c,bottom:d,tip:r})}}}(i,s.boxes,l);let o=new Map(i.map(e=>{var a,s;let o=t.get(e.link[e.end].entity),r="top"===e.side?("left"===(a=i,s=e.link,a.find(e=>e.link===s&&"parent"===e.end)?.side??"right")?-1:1)*(o.width/2-28):e.y-o.height/2,n=l.get(e);return[`${e.link.relationship.id}:${"parent"===e.end?"source":"target"}`,{side:e.side,offset:r,...void 0===n?{}:{run:n}}]}));return hS({id:e.id,title:e.title,type:"flowchart",nodes:e.entities.map(e=>({id:e.id,label:tk(e),kind:"entity",metadata:{}})),edges:a.map(e=>({id:e.relationship.id,source:e.parent.entity,target:e.child.entity,metadata:{},...e.relationship.label?{label:e.relationship.label}:{}})),layout:{direction:"LR",edgeRouting:"orthogonal"},style:e.style,metadata:{}},{placement:s.boxes,anchors:o,endRun:48})}let h2=[...["layered","hub"].flatMap(e=>[1.6,1.1,.7,.5].map(t=>({start:e,aspect:t,sameColumn:1}))),{aspect:.5,sameColumn:0}];function h3(e){let t=e.elements.filter(e=>"arrow"===e.type),a=Math.max(e.width/e.height,e.height/e.width);return hy(t)+sq(t.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),s_({width:e.width,height:e.height})).length+(a>2?4*(a-2):0)+t.reduce((e,t)=>e+function(e){let[t,a]=[e.points[0],e.points.at(-1)],s=0;for(let[t,a]of e.points.slice(1).entries())s+=Math.abs(a.x-e.points[t].x)+Math.abs(a.y-e.points[t].y);return Math.max(0,s/(Math.abs(a.x-t.x)+Math.abs(a.y-t.y)+96+200)-1)}(t),0)+function(e){let t=new Map;for(let a of e)for(let[e,s]of[[a.sourceNodeId,a.points[0]],[a.targetNodeId,a.points.at(-1)]]){let a=`${e}\0${Math.round(s.x)}`;t.set(a,[...t.get(a)??[],s.y])}let a=0;for(let e of t.values()){e.sort((e,t)=>e-t);let t=!1;for(let[s,i]of e.slice(1).entries()){let l=i-e[s]<21.99;l&&(a+=t?.25:1),t=l}}return a}(t)+function(e,t){let a=new Map(e.elements.flatMap(e=>"node"===e.type?[[e.nodeId,e]]:[])),s=0;for(let e of t){let[t,i]=[a.get(e.sourceNodeId),a.get(e.targetNodeId)];if(t&&i&&(!(t.x<i.x+i.width)||!(i.x<t.x+t.width)))for(let[t,a,i]of[[e.points[0],e.points[1],e.points.at(-1)],[e.points.at(-1),e.points.at(-2),e.points[0]]])(a.x-t.x)*(i.x-t.x)<0&&(s+=1)}return s}(e,t)+h5*function(e,t){let a=e.elements.flatMap(e=>"node"===e.type?[e]:[]),s=new Map(a.map(e=>[e.nodeId,e])),i=0;for(let e of t){let[t,l]=[s.get(e.sourceNodeId),s.get(e.targetNodeId)];if(!t||!l||t===l||!(t.x<l.x+l.width&&l.x<t.x+t.width))continue;let[o,r]=[Math.min(t.y+t.height,l.y+l.height),Math.max(t.y,l.y)];i+=a.filter(e=>e!==t&&e!==l&&e.y>=o&&e.y+e.height<=r&&e.x<Math.max(t.x+t.width,l.x+l.width)&&Math.min(t.x,l.x)<e.x+e.width).length}return i}(e,t)}let h5=.25;function h4(e,t,a,s,i,l=32){let o=e.points,[r,n]="start"===t?[o[0],o[1]]:[o.at(-1),o.at(-2)],c=n?Math.hypot(n.x-r.x,n.y-r.y):1,[d,p]=n?[(n.x-r.x)/c,(n.y-r.y)/c]:[1,0],h={x:r.x+d*l,y:r.y+p*l};return{type:"node",id:`node:${a}:optional:${s}`,nodeId:`${a}:optional:${s}`,kind:"optional",rendererRole:"er-optional",shape:"circle",x:h.x-6,y:h.y-6,width:12,height:12,label:"Optional end",fillColor:i.style.backgroundColor,fillStyle:"solid",strokeColor:i.style.accentColor,groupIds:[`table:${a}`]}}function h6(e,t,a,s,i){let l=0;for(let{parent:a,child:s}of e.generalizations){let e=t[s]-t[a];if(e<1)return 1/0;l+=2.5*(e-1)}let o=e.boxes.map(()=>0);for(let{a,b:r,whole:n}of e.others){let e=Math.abs(t[a]-t[r]);0===e?(o[a]+=1,o[r]+=1):l+=s+2.5*(e-1),n&&t[a]>t[r]&&(l+=i)}for(let e of o)l+=1.5*Math.max(0,e-2);let r=e.boxes.map((e,t)=>t),n=e=>r[e]===e?e:r[e]=n(r[e]);for(let{a,b:s}of e.others){if(t[a]!==t[s])continue;let[e,i]=[n(a),n(s)];e===i?l+=1.5:r[e]=i}let c=new Map,d=new Map;for(let[a,s]of e.boxes.entries()){let e=t[a];c.set(e,(c.get(e)??-64)+s.width+64),d.set(e,Math.max(d.get(e)??0,s.height))}for(let e of c.values()){let t=Math.max(0,e-a.width)/a.column;l+=1.5*t*t}let p=Math.max(0,[...d.values()].reduce((e,t)=>e+t,0)+130*Math.max(0,d.size-1)-1.2*a.height)/a.unit;return l+1.5*p*p}function h7(e,t,a,s){let i=[a,s].filter(t=>e.corridor[t]).length;return 2===i?28:1===i?Math.max(30,t.get(a<s?`${a}:${s}`:`${s}:${a}`)??0):Math.max(64,t.get(a<s?`${a}:${s}`:`${s}:${a}`)??0)}function h8(e,t,a){let s=[];for(let[i,l]of a.entries()){if(0===i){s.push(0);continue}let o=a[i-1],r=s[i-1]+e.width[o]+h7(e,t,o,l);for(let[o,n]of a.slice(0,i-1).entries()){let a=t.get(n<l?`${n}:${l}`:`${l}:${n}`);void 0!==a&&(r=Math.max(r,s[o]+e.width[n]+a))}s.push(r)}return s}function h9(e,t,a){let s=e.row.map(()=>0);for(let i of a){let a=h8(e,t,i),l=i.length>0?a.at(-1)+e.width[i.at(-1)]:0;for(let[t,o]of i.entries())s[o]=a[t]+e.width[o]/2-l/2}return s}function ge(e,t,a){let s=new Map;for(let{upper:t,lower:i}of e.segments){let l=s.get(e.row[t])??[];l.push({upper:a[t],lower:a[i]}),s.set(e.row[t],l)}let i=0;for(let e of s.values())for(let[t,a]of e.entries())for(let s of e.slice(t+1))(a.upper-s.upper)*(a.lower-s.lower)<0&&(i+=1);let l=new Map;for(let e of t)for(let[t,a]of e.entries())l.set(a,t);let o=e.flats.map(({a:t,b:a})=>{let[s,i]=[l.get(t),l.get(a)].sort((e,t)=>e-t);return{row:e.row[t],low:s,high:i}});for(let a of o){let s=t[a.row];for(let t=a.low+1;t<a.high;t+=1)e.corridor[s[t]]||(i+=1)}for(let[e,t]of o.entries())for(let a of o.slice(e+1))t.row===a.row&&(t.low<a.low&&a.low<t.high&&t.high<a.high||a.low<t.low&&t.low<a.high&&a.high<t.high)&&(i+=1);return i}function gt(e,t){let a=[];for(let[s,i]of e.entries()){let e=t[s];for(a.push({count:1,weight:e,sum:i*e});a.length>1;){let e=a.at(-1),t=a.at(-2);if(t.sum/t.weight<=e.sum/e.weight)break;a.pop(),t.count+=e.count,t.weight+=e.weight,t.sum+=e.sum}}return a.flatMap(e=>Array(e.count).fill(e.sum/e.weight))}function ga(e,t){return e.find(e=>e.link===t.link&&e!==t)}let gs=e=>"top"===e||"bottom"===e;function gi(e,t){let a=(e,t)=>e>t.min+.5&&e<t.max-.5,s=(e,t)=>t.some(t=>.5>Math.abs(e-t)),i=0;for(let s of t.upper)a(s,e)&&(i+=1);for(let s of e.lower)a(s,t)&&(i+=1);for(let a of e.lower)s(a,t.upper)&&(i+=1e3);return i}let gl={inheritance:{stroke:"solid",from:null,to:"triangle_outline"},realization:{stroke:"dashed",from:null,to:"triangle_outline"},composition:{stroke:"solid",from:"diamond",to:null},aggregation:{stroke:"solid",from:"diamond_outline",to:null},association:{stroke:"solid",from:null,to:null},dependency:{stroke:"dashed",from:null,to:"arrow"}},go=e=>e.length>0?12+22*e.length:14;function gr(e,t){return[e["from"===t?"fromMultiplicity":"toMultiplicity"],e["from"===t?"fromRole":"toRole"]].flatMap(e=>e?[e.trim()]:[])}let gn=e=>Math.ceil(aq(e,13))+2,gc="label-room:",gd=[{wholeBelow:1.5},{},{aspect:1.1},{between:1}];function gp(e,t,a){return e.left<t.right+a&&t.left<e.right+a&&e.top<t.bottom+a&&t.top<e.bottom+a}let gh=(e,t,a)=>({x:e.x+t,y:e.y+a}),gg=(e,t,a)=>({...e,x:e.x+t,y:e.y+a}),gu=(e,t,a)=>({x0:e.x0+t,x1:e.x1+t,y0:e.y0+a,y1:e.y1+a}),gf=e=>({x0:e.x,x1:e.x+e.width,y0:e.y,y1:e.y+e.height});function gm(e){let t=e.filter((t,a)=>0===a||Math.abs(t.x-e[a-1].x)>.01||Math.abs(t.y-e[a-1].y)>.01);return t.filter((e,a)=>{if(0===a||a===t.length-1)return!0;let s=t[a-1],i=t[a+1],l=.01>Math.abs(s.x-e.x)&&.01>Math.abs(e.x-i.x),o=.01>Math.abs(s.y-e.y)&&.01>Math.abs(e.y-i.y);return!l&&!o})}function gv(e){return e.slice(1).map((t,a)=>{let s=e[a];return{x0:Math.min(s.x,t.x)-1,x1:Math.max(s.x,t.x)+1,y0:Math.min(s.y,t.y)-1,y1:Math.max(s.y,t.y)+1}})}function gy(){return{boxes:[],cards:new Map,links:[],regions:[],rows:new Map,attach:0,tails:[],top:0}}function gw(e,t,a){e.cards.set(t,a),e.boxes.push(gf(a))}function gx(e,t,a,s){let i=gm(s);e.links.push({manager:t,report:a,points:i}),e.boxes.push(...gv(i))}function gb(e,t,a,s){for(let[i,l]of t.cards)e.cards.set(i,gg(l,a,s));for(let[i,l]of(e.boxes.push(...t.boxes.map(e=>gu(e,a,s))),e.links.push(...t.links.map(e=>({...e,points:e.points.map(e=>gh(e,a,s))}))),e.regions.push(...t.regions.map(e=>({...e,frame:gg(e.frame,a,s)}))),t.rows))e.rows.set(i,l)}function gk(e){return{x0:Math.min(...e.map(e=>e.x0)),x1:Math.max(...e.map(e=>e.x1)),y0:Math.min(...e.map(e=>e.y0)),y1:Math.max(...e.map(e=>e.y1))}}let gM=e=>0===e.reports.length&&0===e.assistants.length,gC=e=>0===e.assistants.length&&e.reports.length>0&&e.reports.every(gM),gz=e=>e.reports.length>=2&&e.reports.some(gC)&&e.reports.every(e=>gM(e)||gC(e))&&e.reports.every(e=>void 0===e.region);function g_(e,t,a=5){let s=gy(),i=void 0===t&&e.length>=a,l=0;e.forEach((a,o)=>{let r=t??(i&&o%2==0?-1:1),n=1===r?18:-18-a.width;gw(s,a.id,{x:n,y:l,width:a.width,height:a.height});let c=l+a.height/2;s.tails.push({report:a.id,points:[{x:0,y:c},{x:1===r?n:n+a.width,y:c}]}),i&&1!==r&&o!==e.length-1||(l+=a.height+14)});let o=Math.max(...s.tails.map(e=>e.points[0].y));return s.boxes.push({x0:-1,x1:1,y0:-28,y1:o}),s}function gL(e,t,a,s,i,l,o){for(let r of i)gx(e,t,r.report,[a,...s,...r.points.map(e=>gh(e,l,o))])}function gB(e,t,a){let s=0;for(let i=t;i<a;i+=1)s+=e[i];return s+24*Math.max(0,a-t-1)}function gS(e,t,a){let s={split:t,half:gB(e,t,a),imbalance:gB(e,t,a)};for(let i=t+1;i<a;i+=1){let l=gB(e,t,i),o=gB(e,i,a),r=Math.max(l,o),n=Math.abs(l-o);(r<s.half-1e-9||r<s.half+1e-9&&n<s.imbalance-1e-9)&&(s={split:i,half:r,imbalance:n})}return s}function gA(e,t=[]){let a=[];for(let s of e){let e=sv(t,s.block.boxes,24,8),i=Number.isFinite(e)?e:0===a.length?0:-1/0,l=Number.isFinite(i)?i:Math.max(...t.map(e=>e.x1))+24-gk(s.block.boxes).x0;a.push(l),t.push(...s.block.boxes.map(e=>gu(e,l,0)))}return a}function gP(e){let t=gk(e.boxes);return t.x1-t.x0}function gV(e,t){let a=e.map(e=>(function e(t,a,s,i){let l=gy(),{width:o,height:r}=t;gw(l,t.id,{x:-o/2,y:0,width:o,height:r}),l.tails.push({report:t.id,points:[{x:0,y:0}]});let n={x:0,y:r},c=t.reports.length>0&&t.reports.every(gM)&&(void 0!==i||t.reports.length>=a.stackMin&&t.reports.length<=20),d=c&&(void 0!==i||t.reports.length<a.twoColumns),p=r,h=gz(t)?a.outline.get(t.id):void 0,g=d||1===h||2===h&&t.reports.length<3;if(t.assistants.forEach((e,a)=>{let s=g||a%2==0?1:-1,i=r+16+(g?a:Math.floor(a/2))*(e.height+14),o=1===s?22:-22-e.width;gw(l,e.id,{x:o,y:i,width:e.width,height:e.height});let c=i+e.height/2;gx(l,t.id,e.id,[n,{x:0,y:c},{x:1===s?o:o+e.width,y:c}]),p=Math.max(p,i+e.height)}),0===t.reports.length)return l;let u=s||void 0!==t.region;if(c){let e=i??1,s=g_(t.reports,d?e:void 0,a.twoColumns),n=d?e*(-o/2+20):0,c=p+18;return gb(l,{...s,links:[],regions:[],rows:new Map,tails:[]},n,c),gL(l,t.id,{x:n,y:r},[],s.tails,n,c),l}if(void 0!==h){let s=2===h&&t.reports.length>=3,i=s?0:-o/2+20,n=new Map([[1,p+18],[-1,p+18]]);return t.reports.forEach((o,c)=>{let d=s&&c%2==0?-1:1,p=n.get(d),h=e(o,a,u,d),g=i+d*(18+o.width/2);gb(l,h,g,p);let f=p+o.height/2;gx(l,t.id,o.id,[{x:i,y:r},{x:i,y:f},{x:g-d*o.width/2,y:f}]),n.set(d,p+gk(h.boxes).y1+14)}),l}let f=t.reports.filter(gM),m=f.length>=a.stackMin,v=Math.ceil(f.length/20),y=[];for(let s of t.reports){if(m&&gM(s)){if(s===f[0])for(let e=0;e<v;e+=1){let t=g_(f.slice(Math.round(e*f.length/v),Math.round((e+1)*f.length/v)),void 0,a.twoColumns);y.push({block:t,width:gP(t)})}continue}let t=e(s,a,u),i=u?t:function(e,t){if(!t.region)return e;let a=gk(e.boxes),s={x0:Math.min(a.x0-20,e.attach-10-t.region.nameWidth-8),x1:a.x1+20,y0:a.y0-20,y1:a.y1+20},i=s.y0-21-4;return{...e,boxes:[{...s,x0:s.x0-10,x1:s.x1+10,y0:i}],regions:[...e.regions,{root:t.id,label:t.region.label,frame:{x:s.x0,y:s.y0,width:s.x1-s.x0,height:s.y1-s.y0},members:[...e.cards.keys()]}],top:i}}(t,s);y.push({block:i,width:gP(i),root:s.id})}let w=Math.max(1,Math.min(a.rows.get(t.id)??1,y.length)),x=function(e,t,a){let s,i=e.length,l=(e,t)=>!t||e.half<t.half-1e-9||e.half<t.half+1e-9&&e.imbalance<t.imbalance-1e-9,o=Array.from({length:a+1},()=>Array.from({length:i+1},()=>void 0));o[0][0]={half:0,imbalance:0,cut:0};for(let e=1;e<a;e+=1)for(let s=e;s<=i-(a-e);s+=1)for(let a=e-1;a<s;a+=1){let i=o[e-1][a];if(!i)continue;let r=gS(t,a,s),n={half:Math.max(i.half,r.half),imbalance:i.imbalance+r.imbalance,cut:a};l(n,o[e][s])&&(o[e][s]=n)}for(let e=a-1;e<i;e+=1){let r=o[a-1][e];if(!r)continue;let n={half:Math.max(r.half,gB(t,e,i)/2),imbalance:r.imbalance,cut:e};l(n,s)&&(s=n)}let r=[e.slice(s.cut)],n=s.cut;for(let t=a-1;t>=1;t-=1){let a=o[t][n].cut;r.unshift(e.slice(a,n)),n=a}return r}(y,y.map(e=>e.width),w),b=p,k=0;x.forEach((e,a)=>{let s;if(a===x.length-1){s=gA(e);let t=e.map((e,t)=>s[t]+e.block.attach),a=(Math.min(...t)+Math.max(...t))/2;s=s.map(e=>e-a)}else{let{split:t}=gS(e.map(e=>e.width),0,e.length),a={x0:-1,x1:1,y0:-1e6,y1:1e6};s=[...function(e,t){let a=Array.from({length:e.length},()=>0);for(let s=e.length-1;s>=0;s-=1){let i=e[s],l=function(e,t,a=0){let s=1/0;for(let i of t)for(let t of e)i.y0<t.y1+a&&t.y0<i.y1+a&&(s=Math.min(s,t.x0-24-i.x1));return s}(t,i.block.boxes,8),o=Number.isFinite(l)?l:Math.min(...t.map(e=>e.x0))-24-gk(i.block.boxes).x1;a[s]=o,t.push(...i.block.boxes.map(e=>gu(e,o,0)))}return a}(e.slice(0,t),[a]),...gA(e.slice(t),[a])]}let i=Math.max(0,...e.map(e=>-e.block.top)),o=b+28,r=b+56+i,c=[];e.forEach((e,a)=>{let i=s[a];gb(l,e.block,i,r),gL(l,t.id,n,[{x:0,y:o},{x:i+e.block.attach,y:o}],e.block.tails,i,r),c.push(...e.block.boxes.map(e=>gu(e,i,r)))});let d=gk(c);k=Math.max(k,d.x1-d.x0),b=d.y1});let M=y.reduce((e,t)=>t.width>e.width?t:e);return l.rows.set(t.id,{width:k,widestItem:M.width,widest:M.root,items:y.length,rows:x.length}),l})(e,t,!1)),s=gy(),i=[];for(let e of a){let t=sv(i,e.boxes,64,8),a=Number.isFinite(t)?t:0;gb(s,e,a,0),i.push(...e.boxes.map(e=>gu(e,a,0)))}let l=gk(gH(s)),o=gy();return gb(o,s,-l.x0,-l.y0),o}function gH(e){return[...[...e.cards.values()].map(gf),...e.links.flatMap(e=>gv(e.points)),...e.regions.map(e=>({...gf(e.frame),y0:e.frame.y-21-4}))]}function gq(e){let t,a,s;return Math.max(1,Math.max((s=((a=gk(gH(e))).x1-a.x0+40)/(a.y1-a.y0+40))/2.4,.45/s))*Math.max(1,((t=gk(gH(e))).x1-t.x0+80)*(t.y1-t.y0+80+64)/56e5)}let gF="#6250d6",gI=[14,22,30],gE=[8,18,26,36];function gO(e,t,a){let s=(e,t)=>Number.parseInt(e.slice(t,t+2),16);return`#${[1,3,5].map(i=>Math.round(s(t,i)+(s(e,i)-s(t,i))*a).toString(16).padStart(2,"0")).join("")}`}function gU(e,t,a){let s=e=>e.split("\n").length,i=aO(e,t,a);if(1===s(i))return i;let l=a,o=t;for(;o-l>1;){let t=Math.floor((l+o)/2);s(aO(e,t,a))<=s(i)?o=t:l=t}return aO(e,o,a)}let gX=e=>void 0===e?0:e.split("\n").length,gT=(e,t)=>Math.ceil(gX(e)*t*1.25),gY=(e,t=0)=>({left:e.x-t,top:e.y-t,right:e.x+e.width+t,bottom:e.y+e.height+t});function g$(e,t,a){let{x:s,y:i,width:l,height:o}=e;return[{x:s+l,y:i+o/2,outward:0,cost:0},{x:s,y:i+o/2,outward:2,cost:0},{x:s+l,y:i+o/4,outward:0,cost:4},{x:s,y:i+o/4,outward:2,cost:4},{x:s+3*l/4,y:i+o,outward:1,cost:6},{x:s+l/4,y:i+o,outward:1,cost:6},{x:s+3*l/4,y:i,outward:3,cost:6},{x:s+l/4,y:i,outward:3,cost:6}].filter(e=>!t.some(t=>Math.abs(t.x-e.x)+Math.abs(t.y-e.y)<14)).map(e=>({x:e.x,y:e.y,direction:a?(e.outward+2)%4:e.outward,cost:e.cost}))}function gG(e,t){let a=0;for(let s of cq(e)){let e=.01>Math.abs(s.to.y-s.from.y);for(let i of t){if(e===.01>Math.abs(i.to.y-i.from.y))continue;let[t,l]=e?[s,i]:[i,s],o=l.from.x,r=t.from.y;o>Math.min(t.from.x,t.to.x)+.5&&o<Math.max(t.from.x,t.to.x)-.5&&r>Math.min(l.from.y,l.to.y)+.5&&r<Math.max(l.from.y,l.to.y)-.5&&(a+=1)}}return a}function gD(e,t){let a=cq(e);return 24*Math.max(0,a.length-1)+a.reduce((e,t)=>e+Math.abs(t.to.x-t.from.x)+Math.abs(t.to.y-t.from.y),0)+500*gG(e,t)}let gR=(e,t,a)=>e.left<t.right+a&&t.left<e.right+a&&e.top<t.bottom+a&&t.top<e.bottom+a;function gZ(e,t,a,s){return gR({left:Math.min(e.x,t.x),right:Math.max(e.x,t.x),top:Math.min(e.y,t.y),bottom:Math.max(e.y,t.y)},a,s)}function gj(e,t,a,s,i,l){if(0===e.dottedLines.length)return{arrows:[],labels:[],straight:0};let o=new Map;for(let e of i){let t=e.points[0],a=e.points.at(-1);o.set(e.sourceNodeId,[...o.get(e.sourceNodeId)??[],t]),o.set(e.targetNodeId,[...o.get(e.targetNodeId)??[],a])}let r=i.flatMap(e=>cq(e.points)),n=[...t.values()].flatMap(e=>[e.y,e.y+e.height]),c=e=>[...t.values()].flatMap(t=>e.flatMap(e=>[t.y-e,t.y+t.height+e])),d=[...t.values()],p=d.flatMap(e=>{let t=d.filter(t=>t.y>=e.y+e.height&&t.x<e.x+e.width&&e.x<t.x+t.width).map(e=>e.y);return 0===t.length?[]:[(e.y+e.height+Math.min(...t))/2]}),h=a.map(e=>s$(e)),g=Math.min(...n,...h.map(e=>e.y)),u=Math.max(...n,...a.map(e=>e.y+e.height)),f=[...h.map(e=>e.y-10),...a.flatMap(e=>[e.y+e.height+14,e.y+e.height+24]),g-24,u+24],m=[...c(gI),...p,...f],v=[...c([...gI,...gE]),...p,...f],y=g-60-10*e.dottedLines.length,w=u+60,x={left:Math.min(...d.map(e=>e.x),...a.map(e=>e.x))-60,right:Math.max(...d.map(e=>e.x+e.width),...a.map(e=>e.x+e.width))+60},b={remaining:Math.min(4e5,48e3*e.dottedLines.length)},k=[],M=[],C=[],z=0,_=0,L=a.flatMap(e=>cq([{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x+e.width,y:e.y+e.height},{x:e.x,y:e.y+e.height},{x:e.x,y:e.y}])),B=(e,t)=>{let a,s=cq(t).toSorted((e,t)=>Math.abs(t.to.x-t.from.x)+Math.abs(t.to.y-t.from.y)-(Math.abs(e.to.x-e.from.x)+Math.abs(e.to.y-e.from.y))),i=[...r,...cq(t)],l=aq(e,13),o=[1,2,3].map(t=>{let a=1===t?e:gU(e,Math.ceil(l/t)+13,13),s=aI(a,13,Math.ceil(aq(a,13)));return{text:a,width:s,height:Math.ceil(13*gX(a)*1.35)}}).flatMap(({text:e,width:t,height:a},l)=>s.flatMap(s=>{let o=.01>Math.abs(s.to.y-s.from.y);return[.5,.3,.7,.15,.85].flatMap(r=>{let n={x:s.from.x+(s.to.x-s.from.x)*r,y:s.from.y+(s.to.y-s.from.y)*r};return[6,14,30,50,80].flatMap(s=>(o?[-1,1].map(e=>({left:n.x-t/2,right:n.x+t/2,top:e<0?n.y-s-a:n.y+s,bottom:e<0?n.y-s:n.y+s+a})):[1,-1].map(e=>({left:e>0?n.x+s:n.x-s-t,right:e>0?n.x+s+t:n.x-s,top:n.y-a/2,bottom:n.y+a/2}))).map(a=>({text:e,width:t,rect:a,offset:s,form:l,score:100*d.filter(e=>gR(a,gY(e),4)).length+100*h.filter(e=>gR(a,gY(e),2)).length+10*L.filter(e=>gZ(e.from,e.to,a,3)).length+10*C.filter(e=>gR(a,e,4)).length+i.filter(e=>gZ(e.from,e.to,a,3)).length})))})})).reduce((e,t)=>t.score<e.score||t.score===e.score&&(t.offset<e.offset||t.offset===e.offset&&t.form<e.form)?t:e);return{text:o.text,width:o.width,rect:o.rect,covers:(a=o.rect,d.some(e=>gR(a,gY(e),0))||h.some(e=>gR(a,gY(e),0)))}},S=(e,t,a)=>{let s=Math.min(g,...C.map(e=>e.top),...[...r,...cq(a)].flatMap(e=>[e.from.y,e.to.y]))-8,i=e.rect.bottom-e.rect.top;return{...e,rect:{left:t-e.width/2,right:t+e.width/2,top:s-i,bottom:s},covers:!1}};for(let[i,n]of e.dottedLines.entries()){let c=t.get(n.report),d=t.get(n.manager),u=new Set([s.get(n.report),s.get(n.manager)]),L=s.get(n.report)===s.get(n.manager)?s.get(n.report):void 0,A=(e,s)=>[...[...t].map(([t,a])=>({box:gY(a),clearance:e,...t===n.report||t===n.manager?{own:!0}:{}})),...h.map(e=>({box:gY(e),clearance:2})),...a.filter(e=>!u.has(e.id)).map(t=>({box:gY(t),clearance:Math.min(e,8)})),...a.filter(e=>s||L===e.id).flatMap(e=>[{...e,height:0},{...e,y:e.y+e.height,height:0},{...e,width:0},{...e,x:e.x+e.width,width:0}].map(t=>({box:gY(t),clearance:8,...L===e.id?{}:{parallel:!0}})))],P=g$(c,o.get(n.report)??[],!1),V=g$(d,o.get(n.manager)??[],!0),H=[c,d],q=[...f,...m.filter(e=>H.some(t=>e>t.y-120&&e<t.y+t.height+120))],F=(e,t,a={sources:P,targets:V},s=!1)=>t.flatMap(t=>{let i={remaining:Math.min(b.remaining,12e3)},l=cV({...a,obstacles:e,...t,routed:r,top:y,bottom:w,reach:x,...s?{wide:!0,crossingCost:500,backCrossingFactor:1}:{},budget:i});return b.remaining-=Math.min(b.remaining,12e3)-i.remaining,l?[gm(l)]:[]}).reduce((e,t)=>!e||gD(t,r)<gD(e,r)?t:e,void 0),I=F(A(6,!0),[{lanes:[...p,...f],denseLanes:m},{lanes:m,denseLanes:v}])??F(A(6,!0),[{lanes:q,denseLanes:q}])??F(A(3,!1),[{lanes:v,denseLanes:v}]),E=e.dottedLines.length-1-i,O=l&&I&&gG(I,r)>0&&b.remaining>=12e3+48e3*E?F(A(6,!0),[{lanes:[...p,...f],denseLanes:m}],void 0,!0):void 0,U=O&&I&&gD(O,r)<gD(I,r)?O:I,X=()=>{let e=Math.min(g-24-10*z,...r.flatMap(e=>[e.from.y-10,e.to.y-10])),t=(t,a)=>[0,-1,1,-2,2,-4,4].map(s=>({x:t.x+t.width/2+48*s,y:e,direction:a,cost:8*Math.abs(s)})),a=[{lanes:[...q,e],denseLanes:[...q,e]}],s=F(A(6,!0),a,{sources:P,targets:t(c,3)}),i=s&&F(A(6,!0),a,{sources:t(d,1),targets:V});return s&&i?gm([...s,...i]):void 0},T=U?void 0:X();T&&(z+=1),U||T||(_+=1);let Y=gm(U??T??function(e,t){let a=e=>({x:e.x+e.width/2,y:e.y+e.height/2}),[s,i]=[a(e),a(t)],l=(e,t,a)=>{let s=t.x-a.x,i=t.y-a.y,l=Math.min(0===s?1/0:e.width/2/Math.abs(s),0===i?1/0:e.height/2/Math.abs(i));return{x:a.x+s*l,y:a.y+i*l}};return[l(e,i,s),l(t,s,i)]}(c,d)).map(({x:e,y:t})=>({x:e,y:t})),$=n.label?.trim(),G=void 0===$?void 0:B($,Y);if(void 0!==$&&G?.covers&&!T&&b.remaining>=12e3+48e3*E){let e=X(),t=e&&B($,e);e&&t&&!t.covers&&(z+=1,Y=e.map(({x:e,y:t})=>({x:e,y:t})),G=t)}G?.covers&&(G=S(G,Y[0].x,Y)),r.push(...cq(Y)),o.set(n.report,[...o.get(n.report)??[],Y[0]]),o.set(n.manager,[...o.get(n.manager)??[],Y.at(-1)]),k.push({type:"arrow",id:`edge:dotted:${n.id}`,edgeId:`dotted:${n.id}`,sourceNodeId:n.report,targetNodeId:n.manager,points:Y,startArrowhead:null,endArrowhead:"arrow",strokeColor:gF,strokeStyle:"dashed",strokeWidth:2,roughness:0}),void 0!==G&&(C.push(G.rect),M.push({type:"text",id:`text:dotted:${n.id}`,x:(G.rect.left+G.rect.right)/2,y:(G.rect.top+G.rect.bottom)/2,text:G.text,fontSize:13,lineHeight:1.25,maxWidth:G.width,textColor:gF}))}return{arrows:k,labels:M,straight:_}}var gN=a(664);a(3614);var gW=a(1594),gJ=a(6297),gK=a(7258),gQ=a(2275),g1=a(2860),g0=a(1554),g2=a(4233);let g3=l.Or("effect/Metric/CurrentMetricAttributes",{defaultValue:()=>({})}),g5=l.Or("effect/Metric/MetricRegistry",{defaultValue:()=>new Map}),g4="~effect/Metric";class g6{[g4]=g4;#e;#t="";id;description;attributes;constructor(e,t,a){this.id=e,this.description=t,this.attributes=a}valueUnsafe(e){return this.hook(e).get(e)}modifyUnsafe(e,t){return this.hook(t).modify(e,t)}updateUnsafe(e,t){return this.hook(t).update(e,t)}hook(e){var t;let a,s=l.Jt(e,g3);s!==this.#e&&(this.#e=s,this.#t=(t=this,a=Object.entries(ui(this.attributes,s)).sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0])),JSON.stringify([t.type,t.id,t.description,a])));let i=l.Jt(e,g5),o=i.get(this.#t);return g2.b0(o)&&(o={id:this.id,type:this.type,description:this.description,attributes:Object.keys(s).length>0?ui(this.attributes,s):this.attributes,hooks:this.createHooks()},i.set(this.#t,o)),o.hooks}pipe(){return(0,g0.tT)(this,arguments)}}let g7=BigInt(0);class g8 extends g6{type="Counter";#a;#s;constructor(e,t){super(e,t?.description,ul(t?.attributes)),this.#a=t?.bigint??!1,this.#s=t?.incremental??!1}createHooks(){let e=this.#a?g7:0,t=this.#s?this.#a?e=>e>=g7:e=>e>=0:e=>!0;return us(()=>({count:e,incremental:this.#s}),a=>{t(a)&&(e+=a)})}}class g9 extends g6{type;metric;valueUnsafe;updateUnsafe;modifyUnsafe;constructor(e,t,a,s){super(e.id,e.description,e.attributes),this.metric=e,this.valueUnsafe=t,this.updateUnsafe=a,this.modifyUnsafe=s,this.type=e.type}createHooks(){return this.metric.createHooks()}}let ue=(e,t)=>new g8(e,t),ut=(0,gW.XY)(2,(e,t)=>gJ.sxi(a=>gJ.OH5(()=>e.updateUnsafe(t,a)))),ua=(0,gW.XY)(2,(e,t)=>{var a;let s,i,o=(a=t,i={},e=>{let t=l.Jt(e,g3);return t!==s&&(s=t,i=ui(t,a)),l.WQ(e,g3,i)});return new g9(e,t=>e.valueUnsafe(o(t)),(t,a)=>e.updateUnsafe(t,o(a)),(t,a)=>e.modifyUnsafe(t,o(a)))});function us(e,t,a){return{get:e,update:t,modify:a??t}}function ui(e,t){return{...ul(e),...ul(t)}}function ul(e){return g2.EA(e)&&Array.isArray(e)?e.reduce((e,[t,a])=>(gQ.x(e,t,a),e),{}):e}gK.F,gK.F,gW.MN;var uo=a(1587),ur=(a(6526),a(719),a(2707));let un=[["artifactId","sketchi.artifact_id"],["attemptId","sketchi.attempt_id"],["projectId","sketchi.project_id"],["requestId","sketchi.request_id"],["runId","sketchi.run_id"],["scenarioId","sketchi.scenario_id"],["traceId","sketchi.trace_id"]],uc=new Set(["artifact_count","artifact_format","artifact_kind","attempt","cache_mode","duration_ms","error_category","error_tag","failure_category","format_count","method","model","operation","outcome","provider","request_kind","retry_kind","sink","status","status_code","surface","timeout_kind","timeout_ms"]),ud=([...un.map(([,e])=>e),...uc],{metric:()=>void 0}),up=l.Or("@sketchi/observability/TelemetryExporter",{defaultValue:()=>ud}),uh=l.Or("@sketchi/observability/TelemetryCorrelation",{defaultValue:()=>({})});function ug(e){let t=e?.trim();if(t&&!(t.length>128)&&/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(t))return t}function uu(e,t){return o.JkU(function*(){let a={...yield*uh,...function(e){let t={};for(let[a]of un){let s=ug(e[a]);s&&(t[a]=s)}return t}(t)},s=function(e){let t={};for(let[a,s]of un){let i=e[a];i&&(t[s]=i)}return t}(a);return yield*e.pipe(o.PfK(uh,a),o.Muk(s),o.swY(s))})}l.Or("@sketchi/observability/TelemetryResource",{defaultValue:()=>({serviceName:"sketchi"})});let uf=o.fn(function*(e,t,a={}){let s=function(e){let t={artifact_kind:e.artifactKind,failure_category:e.failureCategory,operation:e.operation,outcome:e.outcome,provider:e.provider,retry_kind:e.retryKind,sink:e.sink,surface:e.surface,timeout_kind:e.timeoutKind},a={};for(let[e,s]of Object.entries(t)){let t=ug(s);t&&(a[e]=t)}return a}(a);yield*ut(ua(e,s),t);let i=yield*up,l=uo.getOrUndefined((yield*o._32.pipe(o.uKv)));yield*o.OH5(()=>i.metric({attributes:s,metric:e.id,metricType:e.type,...l?{spanId:l.spanId,traceId:l.traceId}:{},value:t}))});ur.W1;var um=a(9315),uv=a(8713),uy=a(4733);let uw=new Set([...JSON.parse('["access","ace","active","addresses","administration","adobe","advanced","affinity","agent","agents","alloy","amazon","amp","analysis","analyzer","and","android","angular","apple","appliance","application","approvals","arc","armor","arrow","artifact","artifacts","asset","assist","assistant","assured","atom","audit","augment","authority","authorization","automatic","automation","autopilot","aware","axiom","azure","babel","balancing","bare","bash","basic","batch","bedrock","big","billing","binary","blitz","bolt","branching","brave","brunch","build","builder","business","c","capture","carbon","catalog","center","certificate","channel","checkpoints","chrome","chromium","cipher","clerk","cloud","code","codex","cohere","collaboration","command","composer","compute","computing","configuration","connect","connection","connectivity","connectors","console","contact","container","containers","context","contour","control","convex","copilot","core","crystal","cursor","custom","cypress","dart","dashboard","data","database","databases","db","debugger","default","deploy","deployed","deployment","design","designer","developer","director","directory","discovery","disk","distributed","document","dolphin","domains","dovetail","drizzle","early","edge","elastic","electron","elixir","ember","enforcement","engine","enterprise","error","expo","external","financial","firefly","firewall","fireworks","flask","fleet","flora","flow","flutter","flux","for","form","foundry","framer","frameworks","free","functions","fusion","game","gateway","generic","go","google","goose","graph","graphite","gulp","health","healthcare","home","hub","hybrid","hyper","hyperbolic","id","identity","ideogram","ids","illustrator","inception","inference","inflection","insights","insomnia","inspection","integration","intelligence","interconnect","inventory","jest","job","jobs","justifications","key","lab","labeling","lambda","language","launcher","layers","learning","legacy","less","linear","liquid","lit","load","local","lockup","logging","logic","logs","loss","lovable","lunacy","machine","machinery","magic","make","managed","management","manager","map","maps","marionette","markdown","marketing","marketplace","media","mesh","metal","migrate","migration","mixed","mobile","model","modeling","module","mongoose","monitoring","monocle","moonshot","motion","my","native","natural","neon","net","network","networking","next","nomad","notepad","notes","notion","nova","object","objective","obsidian","on","opera","operations","optimization","optimized","oracle","packaging","packer","palm","pandas","panel","partner","passport","patch","payload","performance","permissions","perplexity","persistent","phishing","phoenix","pipeline","platform","playwright","plus","poetry","policy","pool","portal","positron","postman","preferences","premium","preparation","presto","prettier","prevention","private","processing","producer","project","protection","protractor","providers","proxy","pulsar","puppeteer","putty","python","quantum","quasar","query","quiver","quotas","r","racket","rails","railway","rancher","react","real","reality","realm","recommendations","reflex","registry","release","render","replicate","reporting","resend","resource","restricted","retail","retention","rider","risk","router","routes","routing","ruby","rules","run","runway","rust","safari","sanity","sass","scanner","scheduler","search","secret","security","segment","selenium","sense","sentry","series","servers","service","services","sharp","shell","showcase","sketch","slack","slate","snowflake","solidity","solution","solutions","spanner","spark","speech","spring","stability","standard","stimulus","storage","storybook","stream","structured","studio","stylus","sublime","subversion","suite","support","swagger","swift","sync","systems","tables","tailwind","tasks","templates","test","text","threads","threat","tier","tiers","time","to","together","tomcat","tools","topology","trace","tracker","traffic","training","transfer","translation","trial","tutorials","twitter","type","types","typescript","unified","unity","unstructured","upgrade","upstage","user","vagrant","value","vapor","vault","vertex","video","view","vim","virtual","vision","visual","vortex","voyage","web","windsurf","wolfram","workbook","workflow","workflows","workload","workloads","workshop","world","yarn","yoga","zed"]'),"antigravity","api","dataflow","datastore","datastream","filestore","genomics","json","memorystore","meta","nitro","observability","onboarding","ontology","profiler","pubsub","pwa","remix","serverless","submodel","turbo"]),ux=/[A-Za-z0-9.+#]+/gu;function ub(e){return[...e.matchAll(ux)].map(([e])=>e.replace(/^\.+|\.+$/gu,"")).filter(Boolean).map(e=>e.toLocaleLowerCase())}function uk(e){return/[0-9.+#]/u.test(e)||e.length>=3&&!uw.has(e)}function uM(e){return e.trim().toLocaleLowerCase().replace(/\s+/gu," ")}function uC(e,t){return e.some(e=>uM(e).includes(t))}function uz(e,t){let a=uM(e.slug),s=uM(e.name),i=uM(e.collection),l=uM((0,uy.y)(e.collection));return a===t?0:s.startsWith(t)?1:uC(e.aliases,t)?2:a.includes(t)||s.includes(t)||uC(e.keywords,t)?3:i.includes(t)||l.includes(t)?4:null}let u_=new Set(["cloud-platforms","cloud-vendors"]);function uL(e){return e.toLocaleLowerCase().replace(/[^a-z0-9+#]/gu,"")}let uB=new WeakMap,uS=new Set(["app","cluster","database","db","icon","logo","server","service"]);function uA(e,t){let a=ub(t),s=[a,a.filter(e=>!uS.has(e))].map(e=>uL(e.join(""))),i=[e.slug,e.name,...e.aliases];if(i.some(e=>s.includes(uL(e))))return"exact";let l=new Set(a.flatMap((e,t)=>a.slice(t).map((e,s)=>uL(a.slice(t,t+s+1).join("")))));return i.some(e=>""!==uL(e)&&l.has(uL(e)))?"vendor":"weak"}let uP=new Map([["aks",["azure","kubernetes"]],["amazon",["aws"]],["aws",["amazon","amazon web services"]],["eks",["aws","kubernetes"]],["gcp",["google cloud"]],["gke",["google kubernetes engine","google cloud","kubernetes"]],["google cloud",["gcp"]],["google kubernetes engine",["gke","google cloud","kubernetes"]],["k8s",["kubernetes"]]]),uV=new Set([...uP].flatMap(([e,t])=>[e,...t].map(uL)));class uH extends i.rNF()("CodeModeIconLoadError",{cause:i.kld(),message:i.QfV,slug:i.QfV}){}function uq(e){return{collection:e.collection,name:e.name,slug:e.slug}}function uF(e){let t=e.icons.filter(uv.nC),a=new Map(t.map(e=>[e.slug,e])),s=new Map(t.map(e=>[e.slug,uq(e)]));return{get:e=>s.get(e),isStrayVendorLogo:(e,t)=>{let s,i=a.get(e);return void 0!==i&&(u_.has(i.collection)||[i.slug,i.name,...i.aliases].some(e=>uV.has(uL(e))))&&(s=ub(t),[t,...s.flatMap((e,t)=>s.slice(t).flatMap((e,a)=>{let i=s.slice(t,t+a+1).join(" ");return uP.get(i)??[]}))]).every(e=>"weak"===uA(i,e))},search:(e,a)=>(function(e,t={}){let a=uM(t.query??""),s=t.collection?.trim(),i=Math.max(0,t.limit??1/0),l=e.flatMap(e=>{if(s&&e.collection!==s)return[];let t=function(e,t){if(0===t.length)return 5;let a=uz(e,t);if(null!==a)return a;let s=t.split(/\s+/u);if(1===s.length)return null;let i=0;for(let t of s){let a=uz(e,t);if(null===a)return null;i=Math.max(i,a)}return i}(e,a);return null===t?[]:[{icon:e,rank:t}]}).sort((e,t)=>e.rank-t.rank||e.icon.name.localeCompare(t.icon.name)||e.icon.slug.localeCompare(t.icon.slug));return(l.length>0?l:function(e,t,a){let s=ub(t),i=function(e){let t=uB.get(e);if(t)return t;let a=new Map;for(let t of e)for(let e of new Set([t.slug,t.name,...t.aliases].map(uL))){if(!e)continue;let s=a.get(e)??[];s.push(t),a.set(e,s)}return uB.set(e,a),a}(e),l=new Map;for(let e=Math.min(4,s.length);e>0;e-=1)for(let t=0;t+e<=s.length;t+=1){let o=s.slice(t,t+e),r=o.some(uk);for(let s of i.get(uL(o.join("")))??[]){let i=u_.has(s.collection);if(l.has(s.slug)||!r&&!i||a&&s.collection!==a)continue;let n=uz(s,o.join(" "))??6;l.set(s.slug,{icon:s,length:e,start:t,termRank:n,vendor:i})}}return[...l.values()].sort((e,t)=>t.length-e.length||Number(e.vendor)-Number(t.vendor)||e.start-t.start||e.termRank-t.termRank||e.icon.name.localeCompare(t.icon.name)||e.icon.slug.localeCompare(t.icon.slug)).map(({icon:e})=>({icon:e,rank:6}))}(e,a,s)).slice(0,i)})(t,{limit:a,query:e}).map(({icon:t})=>({...uq(t),match:uA(t,e)})),loadSvg:e.loadSvg,slugLookup:e.slugLookup}}function uI(e){return s5(e).toLowerCase()}function uE(e){var t;let a;return{code:"unknown_icon",severity:"warning",stage:"input",...e.ref?{ref:e.ref}:{},message:e.message,hint:e.catalog?(a=function(e,t){let a=t.split(/[-_\s]+/u).filter(Boolean),s=new Set,i=[];for(let t of[a.join(" "),...a])if(t){for(let a of e.search(t,3))s.has(a.slug)||(s.add(a.slug),i.push(a));if(i.length>=3)break}return i.slice(0,3)}(t=e.catalog,e.slug)).length>0?`Use an exact slug, for example ${a.map(e=>`"${e.slug}" (${e.name})`).join(", ")}, or look one up with ${t.slugLookup}.`:`Look up an exact slug with ${t.slugLookup}, or omit icon.`:"This Sketchi runtime has no icon catalog; omit icon or retry on a host with logos."}}function uO(e,t,a={noun:"node",path:"nodes"}){let s=[],i=e.map(e=>{if(!e.icon)return e;let i=uI(e.icon.slug),l={kind:"node",id:e.id,path:`${a.path}.icon.slug`},o=u(i)?t?.get(i):void 0;if(o&&!t?.isStrayVendorLogo(i,e.label))return{...e,icon:{slug:i}};s.push(o?{code:"icon_dropped",severity:"warning",stage:"input",ref:l,message:`Icon "${i}" on ${a.noun} "${e.id}" is a vendor logo, but the label "${e.label}" does not name ${o.name}; the ${a.noun} renders without a logo.`,hint:`Put a vendor's logo only on a ${a.noun} whose label names that vendor ("Cloudflare Workers" takes cloudflare); other ${a.noun}s take their product's own logo or none.`}:uE({catalog:t,message:`Icon "${e.icon.slug}" on ${a.noun} "${e.id}" is not a Sketchi node logo; the ${a.noun} renders without a logo.`,ref:l,slug:i}));let{icon:r,...n}=e;return n});return{issues:s,nodes:i}}let uU=o.fn("codeMode.icons.embedScene")(function*(e,t){let a=e.elements.map(e=>"node"===e.type&&e.icon?{...e,icon:{...e.icon,slug:uI(e.icon.slug)}}:e),s=new Map([...new Set(a.flatMap(e=>"node"===e.type&&e.icon?[e.icon.slug]:[]))].flatMap(e=>{let a=u(e)?t?.get(e):void 0;return a?[[e,a]]:[]})),i=new Map((yield*o.jJl([...s.values()],e=>t?t.loadSvg(e).pipe(o.TjK(e=>(0,uv.Bn)(e)),o.TjK(t=>[e.slug,{name:e.name,svg:t}]),o.Tyx(t=>o.FFw("Code Mode icon asset unavailable",{slug:e.slug,cause:t}).pipe(o.as(void 0)))):o.PyW(void 0),{concurrency:8})).flatMap(e=>e?[e]:[])),l=function(e,t){let a=new Map,s=[],i=a7(e),l=a8(e,i),o=0,r=e.elements.map((e,r)=>{if("node"!==e.type||!e.icon)return e;let n=e.icon,c=t=>(s.push({elementId:e.id,index:r,reason:t,slug:n.slug}),function(e){let{icon:t,...a}=e;return a}(e)),d=a.get(n.slug),p=d??(u(n.slug)?t(n.slug):void 0);if("string"!=typeof p?.svg||a3(p.svg)>aX.maxAssetBytes)return c("unavailable");if(e.rendererRole)return c("lifeline");if("polygon"!==e.shape&&i(e)){let t=l.get(e.id)?.element;if(a9(e,t,n)&&!a9(e,t,void 0))return c("no_room")}if(!d){let e=a3(p.svg);if(o+e>aX.maxTotalAssetBytes)return c("budget");o+=e,a.set(n.slug,{name:p.name,svg:p.svg})}return e}),{icons:n,...c}=e;return{dropped:s,scene:a.size>0?{...c,elements:r,icons:Object.fromEntries(a)}:{...c,elements:r}}}({...e,elements:a},e=>i.get(e));return{issues:l.dropped.map(e=>(function(e){let{dropped:t}=e,a={kind:"element",id:t.elementId,path:`elements[${t.index}].icon${"unavailable"===t.reason?".slug":""}`},s=`Icon "${t.slug}" on node "${t.elementId}"`;if("unavailable"===t.reason&&!e.known)return uE({catalog:e.catalog,message:`${s} is not a Sketchi node logo; the node renders without a logo.`,ref:a,slug:t.slug});let i=e.element?.type==="node"?a6(e.element.icon):0,l={budget:{message:`${s} exceeds the per-diagram logo budget; the node renders without a logo.`,hint:"Use fewer distinct logos in one diagram."},lifeline:{message:`Sequence lifeline or activation "${t.elementId}" cannot carry a logo; the logo was dropped.`,hint:"Put logos on nodes or sequence participants, not on lifelines."},no_room:{message:`${s} does not fit above its label; the node renders without a logo.`,hint:`Make node "${t.elementId}" about ${i}px taller or shorten its label to keep the logo.`},unavailable:{message:`${s} could not be loaded; the node renders without a logo.`,hint:"Retry the request; if the logo stays unavailable, omit icon."}}[t.reason];return{code:"icon_dropped",severity:"warning",stage:"input",ref:a,message:l.message,hint:l.hint}})({catalog:t,dropped:e,element:a[e.index],known:s.has(e.slug)})),scene:l.scene}}),uX=/^(node|step|item|box|thing|process|task)\s*\d*$/i,uT=/^(diagram|untitled|flowchart|chart|sketch)$/i;function uY(e){return e.map(e=>({kind:"node",id:e.id}))}function u$(e){if(void 0===e)return;let t=s5(e);return t.length>0?t:void 0}let uG={start:"start",begin:"start",entry:"start",process:"process",task:"process",action:"process",step:"process",activity:"process",operation:"process",decision:"decision",condition:"decision",question:"decision",choice:"decision",gateway:"decision",end:"end",stop:"end",finish:"end",exit:"end",final:"end"},uD=new Set(["terminal","terminator","terminus"]),uR=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),uZ=["excalidraw","scene"],uj=["scene"],uN=ue("sketchi_codemode_requests",{description:"Code Mode boundary requests by terminal outcome",incremental:!0}),uW=ue("sketchi_codemode_failures",{description:"Code Mode boundary failures by typed status",incremental:!0}),uJ=ue("sketchi_codemode_artifacts",{description:"Code Mode artifacts accepted at workflow boundaries",incremental:!0}),uK=new class e extends g6{type="Histogram";#i;constructor(e,t){super(e,t?.description,ul(t?.attributes)),this.#i=t.boundaries}createHooks(){let e=this.#i,t=e.length,a=new Uint32Array(t+1),s=new Float64Array(t),i=0,l=0,o=Number.MAX_VALUE,r=-Number.MAX_VALUE;return gN.Tj(gN.di(e,g1.wN),(e,t)=>{s[t]=e}),us(()=>({buckets:(()=>{let e=gN.CN(t),i=0;for(let l=0;l<t;l++){let t=s[l];i+=a[l],e[l]=[t,i]}return e})(),count:i,min:o,max:r,sum:l}),e=>{let n=0,c=t;for(;n!==c;){let t=Math.floor(n+(c-n)/2);e<=s[t]?c=t:n=t,c===n+1&&(e<=s[n]?c=n:n=c)}a[n]=a[n]+1,i+=1,l+=e,e<o&&(o=e),e>r&&(r=e)})}}("sketchi_codemode_duration_ms",{description:"Code Mode boundary duration in milliseconds",boundaries:(s=[1,5,10,25,50,100,250,500,1e3,2500,5e3,1e4],gN.BC(gN.pb(new Set(s),e=>e>0),1/0))});class uQ extends l.kl()("@sketchi/diagram-agent/CodeModeRuntimeEnvironment"){}function u1(e={}){return n.Py(uQ,{createId:e.createId??fL,...e.icons?{icons:e.icons}:{},...e.renderer?{renderer:e.renderer}:{},...e.artifactUrl?{artifactUrl:e.artifactUrl}:{}})}function u0(e){return null===e||"object"!=typeof e||Array.isArray(e)?void 0:Object.fromEntries(Object.entries(e))}function u2(e){return{...e,type:"timeline"}}function u3(e){return{...e,type:"chart"}}function u5(e){return{...e,type:"gantt"}}n.Py(uQ,{createId:fL});let u4={gantt_too_large:"gantt_too_large",duplicate_task_id:"duplicate_node_id",invalid_gantt_date:"invalid_gantt_date",invalid_gantt_span:"invalid_gantt_span",invalid_gantt_phase:"invalid_gantt_phase",invalid_gantt_progress:"invalid_gantt_progress",missing_dependency:"missing_edge_source",self_dependency:"self_loop",gantt_dependency_cycle:"gantt_dependency_cycle"};function u6(e){return{id:e.id,title:e.title,type:"sequence",participants:e.participants,messages:e.messages,style:e.style}}let u7={sequence_too_large:"sequence_too_large",duplicate_participant_id:"duplicate_node_id",lifeline_id_collision:"duplicate_node_id",duplicate_message_id:"duplicate_edge_id",missing_message_source:"missing_edge_source",missing_message_target:"missing_edge_target",self_message:"self_loop"},u8={missing_message_source:"Use the id of a participant declared in spec.participants.",missing_message_target:"Use the id of a participant declared in spec.participants."};function u9(e){return{...e,type:"state-machine"}}let fe={state_machine_too_large:"state_machine_too_large",invalid_state_id:"invalid_state",duplicate_state_id:"duplicate_node_id",duplicate_transition_id:"duplicate_edge_id",missing_state_label:"invalid_state",unknown_initial_state:"unknown_initial_state",unknown_parent_state:"invalid_composite",nested_composite:"invalid_composite",missing_transition_source:"missing_edge_source",missing_transition_target:"missing_edge_target",final_has_outgoing:"final_has_outgoing",composite_member_transition:"invalid_composite",missing_composite_initial:"invalid_composite",underbranched_choice:"underbranched_choice",unguarded_choice_branch:"unlabeled_decision_branch",unreachable_state:"unreachable_node"};function ft(e){return{...e,type:"er"}}let fa={er_too_large:"er_too_large",invalid_entity_id:"invalid_entity",duplicate_entity_id:"duplicate_node_id",duplicate_entity_name:"invalid_entity",duplicate_field_name:"invalid_field",er_text_too_long:"label_too_long",nullable_primary_key:"invalid_field",duplicate_relationship_id:"duplicate_edge_id",missing_relationship_entity:"missing_edge_target",missing_relationship_field:"unknown_relationship_field",self_referencing_field:"invalid_relationship"};function fs(e){return{...e,type:"class"}}let fi={class_too_large:"class_too_large",invalid_class_id:"invalid_class",duplicate_class_id:"duplicate_node_id",duplicate_class_name:"invalid_class",duplicate_member:"invalid_member",class_text_too_long:"label_too_long",duplicate_relationship_id:"duplicate_edge_id",missing_relationship_class:"missing_edge_target",inheritance_cycle:"invalid_generalization",invalid_inheritance:"invalid_generalization",invalid_realization:"invalid_generalization",invalid_multiplicity:"invalid_relationship",misplaced_end_label:"invalid_relationship"};function fl(e){return{...e,type:"org-chart"}}let fo={org_chart_too_large:"org_chart_too_large",invalid_person_id:"invalid_person",duplicate_person_id:"duplicate_node_id",org_text_too_long:"label_too_long",unknown_manager:"missing_edge_source",self_manager:"invalid_reporting_line",reporting_cycle:"invalid_reporting_line",multiple_roots:"invalid_reporting_line",invalid_assistant:"invalid_person",duplicate_dotted_line_id:"duplicate_edge_id",invalid_dotted_line:"invalid_reporting_line"};class fr extends i.rNF()("CodeModeArtifactRenderFailed",{cause:i.kld(),message:i.QfV}){}class fn extends i.rNF()("CodeModeArtifactRendererNotConfigured",{message:i.QfV}){}let fc=i._kM({issues:i.O31(i.O3D(iE)).pipe(i.fXn)});class fd extends i.rNF()("ArtifactExportFailure",{status:i.uSQ("export_failed"),issues:fc.fields.issues}){}class fp extends i.rNF()("ArtifactStorageFailure",{status:i.uSQ("storage_failed"),cause:i.kld(),issues:fc.fields.issues}){}function fh(e,t,a){class s extends i.rNF()(e,{message:i.QfV,status:t,context:a}){constructor(e){super({...e,message:e.context.issues[0]?.message??e.status},{disableChecks:!0})}}return s}let fg=fh("BuildFlowchartFailure",ru.fields.status,ru.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fu=fh("BuildMindmapFailure",rm.fields.status,rm.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),ff=fh("BuildSequenceDiagramFailure",ry.fields.status,ry.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fm=fh("BuildStateMachineFailure",rC.fields.status,rC.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fv=fh("BuildErDiagramFailure",rB.fields.status,rB.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fy=fh("BuildClassDiagramFailure",rA.fields.status,rA.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fw=fh("BuildOrgChartFailure",rV.fields.status,rV.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fx=fh("BuildTimelineFailure",rx.fields.status,rx.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fb=fh("BuildChartFailure",rk.fields.status,rk.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fk=fh("BuildGanttFailure",r_.fields.status,r_.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fM=fh("CreateCanvasFailure",rO.fields.status,rO.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fC=fh("GetArtifactFailure",rq.fields.status,rq.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fz=fh("SearchIconsFailure",rR.fields.status,rR.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),f_=fh("ApplyDiagramPatchFailure",rI.fields.status,rI.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields})));function fL(e){return`${e}_${globalThis.crypto.randomUUID()}`}function fB(e){return{code:e.code,severity:e.severity??"error",stage:e.stage,...e.ref?{ref:e.ref}:{},message:e.message,hint:e.hint}}function fS(e){return 0===e.length?"input":e.map(e=>"number"==typeof e?`[${e}]`:String(e)).join(".")}function fA(e){let t=fS(e.path);return fP(t)?"unsupported_patch_operation":"InvalidType"===e.issueTag||"MissingKey"===e.issueTag&&"invalid_type"===e.missingKeyCode?"invalid_type":"LiteralUnion"===e.astKind&&"AnyOf"===e.issueTag?"invalid_enum":t.toLowerCase().includes("color")?"invalid_color":"input"===t?"invalid_type":"missing_field"}function fP(e){return/^operations\.\[\d+\]\.op$/.test(e)}function fV(e){return fP(e)?`Use one of: ${iX.join(", ")}. For label edits, use replaceText with selector plus text.`:"source"===e?"Pass source: { artifactId } from an accepted build or patch, or source: { scene } for inline Sketchi scene patching.":`Fix ${e} so it matches the Code Mode API contract.`}let fH=/^spec\.nodes\.\[\d+\]\.kind$/;function fq(e){return fH.test(e)?'Set kind to "start" (the single entry), "process" (a step), "decision" (a node whose outgoing edges carry branch labels) or "end" (an outcome).':fV(e)}function fF(e,t=fV){let a=e.issues.slice(0,20).map(e=>{let a=fS(e.path);return fB({code:fA(e),stage:"input",ref:{kind:"request",path:a},message:e.message,hint:t(a)})});return e.issues.length>20&&a.push(fB({code:"invalid_type",stage:"input",ref:{kind:"request",path:"input"},message:`${e.issues.length-20} additional input issues were omitted.`,hint:"Fix the summarized request shape before retrying."})),a}function fI(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)}function fE(e){if(void 0===e)return;let t=s5(e);return t.length>0?t:void 0}function fO(e){return e.checks.map(e=>{var t;return fB({code:"generic_label"===(t=e.code)||"label_too_long"===t||"disconnected_graph"===t?t:"quality_below_threshold",severity:e.severity,stage:"quality",message:e.message,hint:"error"===e.severity?"Repair the structural issue and call buildFlowchart again.":"Improve the labels or scope before styling the artifact."})})}function fU(e){return e?.artifactFormats??uZ}function fX(e){return e?.inlineArtifacts??uj}let fT=o.fn("codeMode.artifacts.exportFormats")(function*(e){let t=[];for(let l of e.formats){var a,s,i;let r=yield*(a=e,"scene"===(s=l)?o.PyW(a.scene):"excalidraw"===s?o.PyW(function(e,t={}){return{type:"excalidraw",version:2,source:t.source??"https://sketchi.app",elements:e.elements,appState:e.appState,files:e.files??{}}}(a.excalidraw)):a.renderer?a.renderer.renderPng({scene:a.scene,excalidraw:a.excalidraw}).pipe(o.xm_(e=>fr.make({cause:e,message:e.message}))):o.fJG(fn.make({message:"PNG artifact rendering is not configured for this runtime."})));t.push({format:l,mimeType:rW[l],data:r,sizeBytes:(i=r)instanceof ArrayBuffer||i instanceof Uint8Array?i.byteLength:rQ(i)})}return t});function fY(e){return e.map(e=>fB({code:"overlapping-arrow-segment"===e.code?"arrow_overlap":"text-overflow"===e.code?"text_overflow":e.code.includes("binding")||e.code.includes("bound")||e.code.includes("endpoint")?"arrow_binding_invalid":"export_invalid_scene",stage:"export",ref:e.elementId?{kind:"artifact",id:e.elementId}:{kind:"artifact"},message:e.message,hint:"Inspect the rendered scene and retry with a simpler layout or patch."}))}function f$(e){return e.slice(0,20).map(e=>fB({code:function(e){switch(e.code){case"duplicate_element_id":return"duplicate_element_id";case"duplicate_layer_id":return"duplicate_layer_id";case"empty_canvas":case"invalid_geometry":case"label_overflow":return"invalid_canvas_geometry";case"invalid_binding":return"invalid_canvas_binding";case"invalid_composition":return"invalid_canvas_composition";case"invalid_icon":return"invalid_canvas_icon";case"invalid_polygon":return"invalid_polygon";case"limit_exceeded":return"canvas_limit_exceeded";case"missing_z_order_element":case"duplicate_z_order_element":case"unknown_z_order_element":return"invalid_z_order";case"unknown_layout_target":return"unknown_layout_target"}}(e),stage:"canvas",ref:e.elementId?{kind:"element",id:e.elementId,path:e.path}:{kind:"diagram",path:e.path},message:e.message,hint:"Repair the referenced CanvasSpec field and call createCanvas again."}))}function fG(e){return fY(e.filter(e=>"overlapping-arrow-segment"!==e.code&&"arrow-segment-through-node"!==e.code))}function fD(e){let t=[];for(let c of e.elements){if("arrow"===c.type){let e=c.points[0],a=c.points[1],s=c.points.slice(2);if(!e||!a)return null;let i=[e,a,...s];t.push({...c,type:"arrow",id:c.id,edgeId:c.edgeId,sourceNodeId:c.sourceNodeId,targetNodeId:c.targetNodeId,...c.strokeColor?{strokeColor:c.strokeColor}:{},...c.strokeStyle?{strokeStyle:c.strokeStyle}:{},...c.textColor?{textColor:c.textColor}:{},points:i,...c.label?{label:c.label}:{}});continue}if("node"===c.type){var a,s,i,l,o,r,n;let d=c.points;if("polygon"===c.shape&&(!d||!d[0]||!d[1]||!d[2]))return null;t.push({type:"node",id:c.id,nodeId:c.nodeId,...c.kind?{kind:c.kind}:{},...c.icon?{icon:{slug:c.icon.slug,size:c.icon.size}}:{},shape:c.shape,...c.fillColor?{fillColor:c.fillColor}:{},...c.strokeColor?{strokeColor:c.strokeColor}:{},x:c.x,y:c.y,width:c.width,height:c.height,label:c.label,...c.frameId?{frameId:c.frameId}:{},...c.groupIds?{groupIds:[...c.groupIds]}:{},...c.layerId?{layerId:c.layerId}:{},...void 0!==c.locked?{locked:c.locked}:{},...void 0!==c.opacity?{opacity:c.opacity}:{},...void 0!==c.zIndex?{zIndex:c.zIndex}:{},...c.fillStyle?{fillStyle:c.fillStyle}:{},...void 0!==c.roughness?{roughness:c.roughness}:{},...c.strokeStyle?{strokeStyle:c.strokeStyle}:{},...void 0!==c.strokeWidth?{strokeWidth:c.strokeWidth}:{},..."sequence-lifeline"===c.rendererRole&&hA(e,c)||"sequence-activation"===c.rendererRole&&function(e,t){let a=`${eI}:activation:`,s=t.nodeId.indexOf(a);if(s<=0||s+a.length===t.nodeId.length||t.id!==`node:${t.nodeId}`||"rectangle"!==t.shape||12!==t.width)return!1;let i=t.nodeId.slice(0,s+eI.length),l=e.elements.find(e=>"node"===e.type&&e.id===`node:${i}`&&e.nodeId===i);if(!l||!hA(e,l))return!1;let o=l.x+l.width/2,r=(t.x-(o-6))/6,n=e.elements.filter(e=>"node"===e.type&&e.nodeId.startsWith(`${i}:activation:`)).length;return r>=-.01&&.01>=Math.abs(r-Math.round(r))&&Math.round(r)<n&&t.y>=l.y-.01&&t.y+t.height<=l.y+l.height+.01}(e,c)||"timeline-marker"===c.rendererRole&&(a=c).nodeId.startsWith("event:")&&a.id===`node:${a.nodeId}`&&a.height<=18&&void 0===a.icon||"chart-mark"===c.rendererRole&&(s=c).nodeId.startsWith("chart:")&&s.id===`node:${s.nodeId}`&&void 0===s.icon||"gantt-mark"===c.rendererRole&&((i=c).nodeId.startsWith("gantt:task:")||i.nodeId.startsWith("gantt:progress:"))&&i.id===`node:${i.nodeId}`&&void 0===i.icon||"state-marker"===c.rendererRole&&void 0!==(l=c).kind&&hC[l.kind]===l.shape&&void 0===l.icon||"er-table"===c.rendererRole&&"rectangle"===(o=c).shape&&void 0===o.icon&&o.id===`node:${o.nodeId}`||"er-optional"===c.rendererRole&&("circle"===(r=c).shape||"ellipse"===r.shape)&&void 0===r.icon&&r.nodeId.includes(":optional:")&&24>=Math.max(r.width,r.height)||"class-box"===c.rendererRole&&"rectangle"===(n=c).shape&&void 0===n.icon&&n.id===`node:${n.nodeId}`||("swimlane"===c.rendererRole||"swimlane-header"===c.rendererRole||"zone"===c.rendererRole)&&"rectangle"===c.shape&&!c.icon?{rendererRole:c.rendererRole}:{},...c.textColor?{textColor:c.textColor}:{},..."polygon"===c.shape&&d?.[0]&&d[1]&&d[2]?{points:[d[0],d[1],d[2],...d.slice(3)]}:{}});continue}if("line"===c.type){let e=c.points[0],a=c.points[1];if(!e||!a)return null;t.push({...c,points:[e,a,...c.points.slice(2)]});continue}t.push(structuredClone(c))}return{kind:e.kind,version:e.version,diagramId:e.diagramId,title:e.title,width:e.width,height:e.height,accentColor:e.accentColor,backgroundColor:e.backgroundColor,elements:t,layers:structuredClone(e.layers),layouts:structuredClone(e.layouts),zOrder:[...e.zOrder]}}function fR(e){return structuredClone(e)}function fZ(e){return e.elements.flatMap(e=>"arrow"===e.type?[`arrow:${e.id}:${e.sourceNodeId}->${e.targetNodeId}`]:"line"===e.type?[`line:${e.id}:${e.startBinding?.elementId??""}->${e.endBinding?.elementId??""}`]:[]).sort()}function fj(e){return e.elements.filter(e=>"node"===e.type)}function fN(e){return e.elements.filter(e=>"text"===e.type)}function fW(e){return e.elements.filter(e=>"arrow"===e.type)}function fJ(e,t){if(!e||0===e.length||!t)return!1;let a=t.trim().toLowerCase();return e.some(e=>e.trim().toLowerCase()===a)}function fK(e,t){let a=t?.scope??"all",s=!!(t&&((t.ids?.length??0)>0||(t.nodeIds?.length??0)>0||(t.edgeIds?.length??0)>0||(t.kinds?.length??0)>0||(t.labels?.length??0)>0)),i=new Set(t?.ids??[]),l=new Set(t?.nodeIds??[]),o=new Set(t?.edgeIds??[]),r=new Set(t?.kinds??[]),n=fj(e).filter(e=>"edges"!==a&&(!t||!s||i.has(e.id)||l.has(e.nodeId)||!!e.kind&&[...r].some(t=>t===e.kind)||fJ(t.labels,e.label))),c=fW(e).filter(e=>"nodes"!==a&&(!t||!s||i.has(e.id)||o.has(e.edgeId)||fJ(t.labels,e.label))),d=new Set(n.map(e=>e.id)),p=new Set(c.map(e=>e.id));return{arrows:c,nodes:n,texts:fN(e).filter(e=>t&&s?i.has(e.id)||!!e.containerId&&d.has(e.containerId)||!!e.containerId&&p.has(e.containerId)||fJ(t.labels,e.text):"nodes"===a?!!e.containerId&&d.has(e.containerId):"edges"!==a||!!e.containerId&&p.has(e.containerId))}}function fQ(e){return fB({code:"unknown_patch_target",stage:"flowchart",ref:{kind:"request",path:"operations.selector"},message:`Patch operation "${e.op}" did not match any scene element.`,hint:"Use nodeIds, edgeIds, ids, kinds, labels, or scope values that exist in the accepted artifact."})}function f1(e,t){return fN(e).find(e=>e.containerId===t||e.id===`${t}:label`)}function f0(e,t){let a=f1(e,t.id),s=function(e){let t=e[0],a=e[e.length-1];if(t&&a)return{x:(t.x+a.x)/2,y:(t.y+a.y)/2-10}}(t.points);if(a&&!a.containerId){let e=t.points[0];if(!e)return;let s=t.points.find(t=>t.x!==e.x||t.y!==e.y);if(!s)return;let i=aO(a.text,a.maxWidth??160,a.fontSize),l=aI(i,a.fontSize,a.maxWidth??160),o=Math.ceil(i.split("\n").length*a.fontSize*1.35);a.x=(e.x+s.x)/2+(e.x===s.x?l/2+8:0),a.y=(e.y+s.y)/2-(e.y===s.y?o/2+5:0);return}a&&s&&(a.x=s.x,a.y=s.y)}function f2(e,t){let a=new Set(t);for(let t of fW(e))(a.has(t.sourceNodeId)||a.has(t.targetNodeId))&&f4(e,t)}function f3(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function f5(e,t,a){let s=f3(e),i=f3(t),l=i.x-s.x,o=i.y-s.y;return 0===l&&0===o?{x:s.x,y:"source"===a?e.y+e.height:e.y}:Math.abs(l)>Math.abs(o)?l>=0?{x:e.x+e.width,y:s.y}:{x:e.x,y:s.y}:o>=0?{x:s.x,y:e.y+e.height}:{x:s.x,y:e.y}}function f4(e,t){let a=new Map(fj(e).map(e=>[e.nodeId,e])),s=a.get(t.sourceNodeId),i=a.get(t.targetNodeId);if(!s||!i)return[fB({code:"patch_output_invalid",stage:"render",ref:{kind:"edge",id:t.edgeId},message:`Arrow "${t.id}" references a node that is not in the scene.`,hint:"Rebuild the diagram with buildFlowchart or buildMindmap before applying visual patches."})];if(t.curved)return t.points=sc(s,i).map(e=>({...e})),f0(e,t),[];let l=f5(s,i,"source"),o=f5(i,s,"target");if(Math.abs(o.y-l.y)>=Math.abs(o.x-l.x)){let e=(l.y+o.y)/2;t.points=[l,{x:l.x,y:e},{x:o.x,y:e},o]}else{let e=(l.x+o.x)/2;t.points=[l,{x:e,y:l.y},{x:e,y:o.y},o]}return f0(e,t),[]}function f6(e){let t=e.width,a=e.height;for(let s of e.elements)if("arrow"===s.type||"line"===s.type)for(let e of s.points)t=Math.max(t,e.x),a=Math.max(a,e.y);else"text"===s.type?(t=Math.max(t,s.x+(s.maxWidth??0)),a=Math.max(a,s.y+s.fontSize)):(t=Math.max(t,s.x+s.width),a=Math.max(a,s.y+s.height));e.width=t+48,e.height=a+48}function f7(e,t,a){if(!t||!a){if(t){let a=e.indexOf(t);return a>=0?a:void 0}if(a){let t=e.indexOf(a);return t>=0?t+1:void 0}return e.length}}function f8(e,t){return[fB({code:"patch_output_invalid",stage:"canvas",ref:{kind:"request",path:"operations"},message:t,hint:`Repair the ${e.op} operation and preserve unique, stable element ids.`})]}let f9=o.fn("codeMode.patch.resolveSource")(function*(e){if("scene"in e.source)return{scene:fR(e.source.scene)};let t=yield*rN,a=yield*t.readManifest(e.source.artifactId).pipe(o.xm_(e=>new f_({status:"storage_failed",context:{issues:[r0(e.message,"storage_read_failed")]}})));if(!a||a.artifactId!==e.source.artifactId||!a.formats.some(e=>"scene"===e.format))return yield*new f_({status:"source_unavailable",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:e.source.artifactId},message:`Artifact "${e.source.artifactId}" does not have a valid source manifest.`,hint:"Rebuild with the appropriate build operation and patch the accepted artifact id."})]}});let s=yield*t.read(e.source.artifactId,"scene").pipe(o.xm_(e=>new f_({status:"storage_failed",context:{issues:[r0(e.message,"storage_read_failed")]}})));if(!s)return yield*new f_({status:"source_unavailable",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:e.source.artifactId},message:`Scene artifact "${e.source.artifactId}" is not available.`,hint:"Call buildFlowchart or buildMindmap first, then patch the accepted artifact id."})]}});let l=i.q$Z(oP,{errors:"all",reportInput:!0})(s.data);return um.oJ(l)?{scene:fR(l.success),sourceArtifactId:e.source.artifactId}:yield*new f_({status:"source_unavailable",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:e.source.artifactId},message:`Scene artifact "${e.source.artifactId}" could not be decoded.`,hint:"Rebuild with the appropriate build operation and patch the new artifact."})]}})});function me(e){return e?{requestId:e}:{}}function mt(e){return{diagramId:e.diagramId,formats:[{format:"scene",mimeType:rW.scene,inline:e,sizeBytes:rQ(e)}]}}function ma(e){return{ok:!1,status:e.status,...e.context}}function ms(e,t){return r0(e.message,t)}let mi=o.fn("codeMode.artifacts.exportAndStore")(function*(e){let t=yield*uQ,a=yield*rN,{excalidraw:s,validation:i}=yield*o.OH5(()=>{let t=function(e){let t,a,s,i,l,o,r,n=(t=new Map(e.layers.map(e=>[e.id,e])),s=new Set((a=e.elements.filter(e=>{let a=e.layerId?t.get(e.layerId):void 0;return a?.visible!==!1})).flatMap(e=>"node"===e.type||"frame"===e.type&&void 0!==e.nodeId?[e.nodeId]:[])),l=new Set((i=a.filter(e=>"arrow"!==e.type||s.has(e.sourceNodeId)&&s.has(e.targetNodeId))).flatMap(e=>"text"===e.type?[]:[e.id])),r=new Set((o=i.filter(e=>"text"!==e.type||!e.containerId||l.has(e.containerId))).map(e=>e.id)),o.map(e=>{let a=e.layerId?t.get(e.layerId):void 0,{frameId:s,...i}=e;return{...e.frameId&&!r.has(e.frameId)?i:e,...a?.locked===!0?{locked:!0}:{}}})),{textElements:c,generatedLabelSourceIds:d}=function(e){let t=e.filter(nb),a=e.filter(nk),s=new Set(e.map(e=>e.id)),i=new Map,l=new Set(a.flatMap(e=>e.containerId?[e.containerId]:[]));for(let e of t){if(l.has(e.id)||e.rendererRole)continue;let t=`__sketchi_node_label__${e.id}`,o=t,r=2;for(;s.has(o);)o=`${t}:${r}`,r+=1;s.add(o),i.set(o,e.id),a.push({type:"text",id:o,containerId:e.id,...e.frameId?{frameId:e.frameId}:{},...e.groupIds?{groupIds:[...e.groupIds]}:{},...e.layerId?{layerId:e.layerId}:{},...void 0!==e.locked?{locked:e.locked}:{},...void 0!==e.opacity?{opacity:e.opacity}:{},...e.textColor?{textColor:e.textColor}:{},x:e.x+e.width/2,y:e.y+e.height/2,text:e.label,fontSize:16,maxWidth:Math.max(1,e.width-24)})}return{textElements:a,generatedLabelSourceIds:i}}(n),p={},h=new Map(d),g=function(e,t,a,s,i){var l,o,r,n;let c=t.filter(nb),d=new Set([...t.map(e=>e.id),...a.map(e=>e.id)]),p=new Map,h=new Map;for(let e of a)e.containerId&&h.set(e.containerId,e);let g=t.filter(nM),u=t.filter(nC),f=function(e,t,a,s){let i=new Map,l=new Map([...e.map(e=>[e.nodeId,e.id]),...t.flatMap(e=>void 0===e.nodeId?[]:[[e.nodeId,e.id]])]);for(let e of a)for(let t of[e.sourceNodeId,e.targetNodeId]){let a=l.get(t);a&&i.set(a,[...i.get(a)??[],e.id])}for(let e of s)for(let t of[e.startBinding,e.endBinding])t&&i.set(t.elementId,[...i.get(t.elementId)??[],e.id]);return i}(c,t.filter(nz),g,u),m=new Map,v=[];for(let t of c){let a=h.get(t.id),n=function(e){let t=e.shape.height,a="circle"===e.shape.shape?"ellipse":e.shape.shape,s=[...e.text&&"polygon"!==e.shape.shape?[{id:e.text.id,type:"text"}]:[],...e.arrowIds.map(e=>({id:e,type:"arrow"}))];if("polygon"===e.shape.shape){let t=e.shape.points??[{x:e.shape.width/2,y:0},{x:e.shape.width,y:e.shape.height},{x:0,y:e.shape.height}],[a]=t;return{...nm(e.shape.id,e.shape),type:"line",x:e.shape.x,y:e.shape.y,width:e.shape.width,height:e.shape.height,backgroundColor:e.shape.fillColor??"transparent",boundElements:e.arrowIds.map(e=>({id:e,type:"arrow"})),customData:{sketchiShape:"polygon",...e.shape.rendererRole?{sketchiRendererRole:e.shape.rendererRole}:{}},endArrowhead:null,endBinding:null,lastCommittedPoint:null,points:[...t,a].map(e=>[e.x,e.y]),roundness:null,startArrowhead:null,startBinding:null,strokeColor:e.shape.strokeColor??e.scene.accentColor}}return aY(e.shape.shape)?{...nm(e.shape.id,e.shape),groupIds:[ny(e.shape),...e.shape.groupIds??[]],type:"rectangle",x:e.shape.x,y:e.shape.y,width:e.shape.width,height:t,backgroundColor:"transparent",boundElements:s.length>0?s:null,customData:{sketchiShape:e.shape.shape},roundness:null,strokeColor:"transparent"}:{...nm(e.shape.id,e.shape),type:a,x:e.shape.x,y:e.shape.y,width:e.shape.width,height:t,backgroundColor:e.shape.fillColor??"transparent",boundElements:s.length>0?s:null,roundness:"rectangle"===a&&"chart-mark"!==e.shape.rendererRole&&"gantt-mark"!==e.shape.rendererRole&&"er-table"!==e.shape.rendererRole&&"class-box"!==e.shape.rendererRole&&"swimlane"!==e.shape.rendererRole&&"swimlane-header"!==e.shape.rendererRole&&"zone"!==e.shape.rendererRole?{type:3}:null,strokeColor:e.shape.strokeColor??e.scene.accentColor,...e.shape.rendererRole?{customData:{sketchiRendererRole:e.shape.rendererRole}}:{}}}({scene:e,shape:t,arrowIds:f.get(t.id)??[],...a?{text:a}:{}});if(m.set(t.nodeId,n),v.push(n),aY(t.shape)){let a=function(e){let{shape:t}=e;if(!aY(t.shape))return[];let a={...t,shape:t.shape};return[...t.fillColor?[{fill:t.fillColor,points:aW(a),smooth:!1}]:[],...(function(e){let{x:t,y:a,width:s,height:i}=e,l=a$[e.shape];if("document"===e.shape)return[{points:[{x:t,y:a+i},{x:t,y:a},{x:t+s,y:a},{x:t+s,y:a+i}],smooth:!1},{points:aZ(e,l),smooth:!0}];let o=aR(e,l,"pipe"!==e.shape,12,"bucket"===e.shape?aG(s):0);return[{points:o.back,smooth:!0},{points:o.front,smooth:!0},...o.sides.map(e=>({points:e,smooth:!1})),{points:o.end,smooth:!0}]})(a).map(e=>({...e,fill:void 0}))].map((a,s)=>{let[i]=a.points,l=a.points.map(e=>e.x),o=a.points.map(e=>e.y);return{...nm(e.id(s),t),groupIds:[ny(t),...t.groupIds??[]],type:"line",x:i.x,y:i.y,width:Math.max(...l)-Math.min(...l),height:Math.max(...o)-Math.min(...o),backgroundColor:a.fill??"transparent",boundElements:null,customData:{sketchiShapeStroke:t.shape},endArrowhead:null,endBinding:null,lastCommittedPoint:null,points:a.points.map(e=>[e.x-i.x,e.y-i.y]),roughness:t.roughness??0,roundness:a.smooth?{type:2}:null,startArrowhead:null,startBinding:null,strokeColor:a.fill?"transparent":t.strokeColor??e.scene.accentColor}})}({id:e=>(function(e,t,a){let s=`${e.id}:stroke-${t}`,i=s,l=2;for(;a.has(i);)i=`${s}-${l}`,l+=1;return a.add(i),i})(t,e,d),scene:e,shape:t});for(let e of a)i.set(e.id,t.id);v.push(...a),p.set(t.id,t)}let c=t.icon&&e.icons&&Object.hasOwn(e.icons,t.icon.slug)?e.icons[t.icon.slug]:void 0;if(!t.icon||"string"!=typeof c?.svg)continue;let g=(l=t.icon.slug,o=c.svg,`sketchi-icon-${l}-${sy(o,"hex","utf16")}`),u=function(e,t){let a=`${e.id.replace(/[^\w-]/gu,"-")}-icon`,s=a,i=2;for(;t.has(s);)s=`${a}-${i}`,i+=1;return t.add(s),s}(t,d),y=function(e){let t=function(e){if(!e.icon)return;let t=a5(e);return{x:e.x+(e.width-e.icon.size)/2,y:e.y+t.y+aX.gap,width:e.icon.size,height:e.icon.size}}(e.node);return t&&e.node.icon?{...nm(e.id,e.node),groupIds:[ny(e.node),...e.node.groupIds??[]],type:"image",x:t.x,y:t.y,width:t.width,height:t.height,backgroundColor:"transparent",boundElements:null,crop:null,customData:{sketchiNodeIcon:e.node.icon.slug},fileId:e.fileId,roundness:null,scale:[1,1],status:"saved",strokeColor:"transparent"}:null}({fileId:g,id:u,node:t});y&&(s[g]??=(r=c.svg,{id:g,mimeType:"image/svg+xml",dataURL:`data:image/svg+xml;base64,${function(e){let t=new TextEncoder().encode(e),a="";for(let e=0;e<t.length;e+=32768)a+=String.fromCharCode(...t.subarray(e,e+32768));return btoa(a)}(r)}`,created:1,lastRetrieved:1}),n.groupIds=[ny(t),...t.groupIds??[]],i.set(u,t.id),p.set(t.id,t),v.push(y))}for(let a of t.filter(nz)){let t={...nm((n={element:a,scene:e}).element.id,n.element),type:"frame",x:n.element.x,y:n.element.y,width:n.element.width,height:n.element.height,backgroundColor:n.element.fillColor??"transparent",boundElements:null,name:n.element.name??null,roundness:null,strokeColor:n.element.strokeColor??n.scene.accentColor},s=f.get(a.id)??[];t.boundElements=s.length?s.map(e=>({id:e,type:"arrow"})):null,void 0!==a.nodeId&&m.set(a.nodeId,t),v.push(t)}for(let e of a){let t=c.find(t=>t.id===e.containerId&&"polygon"!==t.shape),a=g.some(t=>t.id===e.containerId),s=g.find(t=>e.id===`${t.id}:label`),i=e.containerId&&(t||a),l=e.textColor??s?.textColor,o=nv({...t?{container:t}:{},element:e,id:e.id,...i?{containerId:e.containerId}:{},fontSize:e.fontSize,maxWidth:e.maxWidth??160,...l?{textColor:l}:{},text:e.text,wrap:a||!!s,x:e.x,y:e.y}),r=t?p.get(t.id):void 0;r&&(o.groupIds=[ny(r),...e.groupIds??[]]),v.push(o)}for(let t of g){let s=h.get(t.id)??a.find(e=>e.id===`${t.id}:label`);v.push(function(e){let t=e.arrow.points[0],a=nw(e.arrow),s=!0!==e.arrow.curved&&(e.arrow.points.length>2||[e.sourceShape,e.targetShape].some(e=>e?.type==="frame"||function(e){let t=e?.customData;if(null===t||"object"!=typeof t)return!1;let a=t.sketchiRendererRole;return"er-table"===a||"class-box"===a}(e)));return{...nm(e.arrow.id,e.arrow),type:"arrow",x:t.x,y:t.y,width:a.x-t.x,height:a.y-t.y,backgroundColor:"transparent",boundElements:e.text?e.text.containerId===e.arrow.id?[{id:e.text.id,type:"text"}]:null:e.arrow.label?[{id:`${e.arrow.id}:label`,type:"text"}]:null,elbowed:s,endArrowhead:void 0===e.arrow.endArrowhead?"arrow":e.arrow.endArrowhead,endBinding:nf(e.targetShape,a),...s?{fixedSegments:[],startIsSpecial:null,endIsSpecial:null}:{},points:e.arrow.points.map(e=>[e.x-t.x,e.y-t.y]),roundness:s?null:{type:2},startArrowhead:e.arrow.startArrowhead??null,startBinding:nf(e.sourceShape,t),strokeColor:e.arrow.strokeColor??e.scene.accentColor,strokeStyle:e.arrow.strokeStyle??"solid"}}({arrow:t,scene:e,sourceShape:m.get(t.sourceNodeId),targetShape:m.get(t.targetNodeId),...s?{text:s}:{}}));let i=t.label&&!s?function(e){if(!e.arrow.label)return null;let t=e.arrow.points[0],a=nw(e.arrow);return nv({id:`${e.arrow.id}:label`,containerId:e.arrow.id,fontSize:13,...void 0===e.arrow.locked?{}:{locked:e.arrow.locked},maxWidth:160,...e.arrow.textColor?{textColor:e.arrow.textColor}:{},text:e.arrow.label,wrap:!0,x:(t.x+a.x)/2,y:(t.y+a.y)/2-10})}({arrow:t}):null;i&&v.push(i)}let y=new Map(v.map(e=>[e.id,e]));for(let t of u)if(v.push(function(e){let[t,...a]=e.element.points,s=a[a.length-1]??t,i=void 0!==e.element.startArrowhead||void 0!==e.element.endArrowhead||void 0!==e.element.startBinding||void 0!==e.element.endBinding,l=i&&e.element.points.length>2;return{...nm(e.element.id,e.element),type:i?"arrow":"line",x:t.x,y:t.y,width:s.x-t.x,height:s.y-t.y,backgroundColor:e.element.fillColor??"transparent",boundElements:null,...i?{elbowed:l}:{},endArrowhead:e.element.endArrowhead??null,endBinding:nx(e.element.endBinding,e.elementsById,s),...l?{fixedSegments:[],startIsSpecial:null,endIsSpecial:null}:{},points:e.element.points.map(e=>[e.x-t.x,e.y-t.y]),roundness:e.element.points.length>2&&!l?{type:2}:null,startArrowhead:e.element.startArrowhead??null,startBinding:nx(e.element.startBinding,e.elementsById,t),strokeColor:e.element.strokeColor??e.scene.accentColor}}({element:t,elementsById:y,scene:e})),t.label){let e=t.points[0],a=t.points[t.points.length-1]??e;v.push(nv({id:`${t.id}:label`,fontSize:13,...void 0===t.locked?{}:{locked:t.locked},maxWidth:160,...t.textColor?{textColor:t.textColor}:{},text:t.label,wrap:!0,x:(e.x+a.x)/2,y:(e.y+a.y)/2-10}))}return v}(e,n,c,p,h),u=new Map(e.zOrder.map((e,t)=>[e,t])),f=e=>{if(u.has(e.id))return e.id;let t=h.get(e.id);return t||(e.id.endsWith(":label")?e.id.slice(0,-6):e.id)};g.sort((e,t)=>(u.get(f(e))??Number.MAX_SAFE_INTEGER)-(u.get(f(t))??Number.MAX_SAFE_INTEGER));let m=null;for(let e of g){let t=function(e,t,a,s){if(void 0!==s){var i=s;if(!nr.has(i)){if(i.length<2||i.length%2!=0||!ni(i))throw Error("intDigits must be an even number of at least 2 characters in strictly ascending character code order: "+i);if(!nl(i))throw Error("intDigits must be single-byte (char code 0-255): "+i);nr.add(i)}}else s=a??r3;if(void 0!==a){var l=a;if(!no.has(l)){if(l.length<2||!ni(l))throw Error("digits must be at least 2 characters in strictly ascending character code order: "+l);if(!nl(l))throw Error("digits must be single-byte (char code 0-255): "+l);no.add(l)}}else a=r2;let o=r4(a),r=r4(s);if(null!=e&&ne(e,a,s,r),null!=t&&ne(t,a,s,r),null!=e&&null!=t&&e>t){let a=e;e=t,t=a}if(null==e){if(null==t)return s[s.length/2]+a[0];let e=r9(t,s,r),i=t.slice(e.length);if(ns(e,a,s))return e+r6("",i,a,o);if(e<t)return e;let l=function(e,t,a,s,i){r7(e,s,i);let l=e[0],o=t[t.length-1],r="";for(let s=e.length-1;s>=1;s--){let i=a[e.charCodeAt(s)]-1;if(-1!==i)return l+e.slice(1,s)+t[i]+r;r=o+r}let n=i[l.charCodeAt(0)];if(0===n)return null;let c=s[n-1],d=r8(c,s,i)-r8(l,s,i);return c+(d>0?r+o:d<0?r.slice(1):r)}(e,a,o,s,r);if(null==l)throw Error("cannot decrement any more");return l}if(null==t){let t=r9(e,s,r),i=e.slice(t.length),l=nt(t,a,o,s,r);return null==l?t+r6(i,null,a,o):l}let n=r9(e,s,r),c=e.slice(n.length),d=r9(t,s,r),p=t.slice(d.length);if(n===d)return n+r6(c,p,a,o);let h=nt(n,a,o,s,r);if(null==h)throw Error("cannot increment any more");return h<t?h:n+r6(c,null,a,o)}(m,null);e.index=t,m=t}return{appState:{viewBackgroundColor:e.backgroundColor,zoom:{value:Math.max(.42,Math.round(100*Math.min(1,860/Math.max(e.width,1),340/Math.max(e.height,1)))/100)}},elements:g,files:p}}(e.scene);return{excalidraw:t,validation:function(e){let t=[],a=new Map(e.elements.map(e=>[e.id,e])),s=new Set(e.elements.filter(nB).map(e=>e.id));for(let i of(0===e.elements.length&&t.push({code:"empty-scene",message:"Excalidraw scene must contain at least one shape."}),e.elements)){if("image"!==i.type||"string"==typeof i.fileId&&e.files&&Object.hasOwn(e.files,i.fileId)||t.push({code:"missing-image-file",elementId:i.id,message:`Image "${i.id}" references a file missing from the scene.`}),"arrow"===i.type){let e=!0===i.elbowed;for(let l of((Array.isArray(i.points)?i.points:[]).length>2&&!e&&!function(e){let t=e.roundness;return!0!==e.elbowed&&null!==t&&"object"==typeof t&&2===t.type}(i)&&t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Arrow "${i.id}" has an orthogonal route but is not marked elbowed.`}),e&&null!==i.fixedSegments&&!Array.isArray(i.fixedSegments)&&t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Elbow arrow "${i.id}" is missing fixedSegments metadata.`}),["startBinding","endBinding"])){if(null===i[l]||void 0===i[l])continue;let o=n_(i,l);if(!(o&&s.has(o))){t.push({code:"missing-arrow-binding",elementId:i.id,message:`Arrow "${i.id}" has invalid ${l}.`});continue}let r=a.get(o);r&&!function(e,t,a){let s=e.boundElements;return!!Array.isArray(s)&&s.some(e=>!!(e&&"object"==typeof e)&&e.id===t&&e.type===a)}(r,i.id,"arrow")&&t.push({code:"missing-bound-arrow",elementId:r.id,message:`Shape "${r.id}" does not include bound arrow "${i.id}".`});let n=function(e,t){let a=nd(e.x)??0,s=nd(e.y)??0,i=Array.isArray(e.points)?e.points.map(np).filter(e=>!!e):[],l="startBinding"===t?i[0]:i[i.length-1];return l?{x:a+l[0],y:s+l[1]}:null}(i,l);if(r&&n&&!function(e,t){let a=nh(t);if(!a)return!1;let s=t.customData&&"object"==typeof t.customData?t.customData.sketchiShape:void 0;if("string"==typeof s&&aY(s))return aN({...a,shape:s},e);if("diamond"===t.type){let t=a.width/2,s=a.height/2;if(0===t||0===s)return!1;let i=a.x+t,l=a.y+s;return nA(Math.abs(e.x-i)/t+Math.abs(e.y-l)/s,1)}if("ellipse"===t.type){let t=a.width/2,s=a.height/2;if(0===t||0===s)return!1;let i=a.x+t,l=a.y+s;return nA(((e.x-i)/t)**2+((e.y-l)/s)**2,1)}let i=(nA(e.x,a.x)||nA(e.x,a.x+a.width))&&nS(e.y,a.y,a.y+a.height),l=(nA(e.y,a.y)||nA(e.y,a.y+a.height))&&nS(e.x,a.x,a.x+a.width);return i||l}(n,r)&&t.push({code:"arrow-endpoint-off-shape",elementId:i.id,message:`Arrow "${i.id}" ${l} endpoint does not land on "${r.id}".`}),r&&n&&e){let e=function(e,t){let a=e[t];return a&&"object"==typeof a?np(a.fixedPoint):null}(i,l);e&&function(e,t,a){let s=nh(a);if(!s)return!1;let i=1e-4>Math.abs(e[0]-.5001)?.5:e[0],l=1e-4>Math.abs(e[1]-.5001)?.5:e[1];return nA(s.x+i*s.width,t.x)&&nA(s.y+l*s.height,t.y)}(e,n,r)||t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Elbow arrow "${i.id}" has invalid ${l} fixedPoint metadata.`})}}}if("text"===i.type){let e=i.containerId;if("string"!=typeof e)continue;let s=a.get(e);if(!s){t.push({code:"missing-container",elementId:i.id,message:`Text "${i.id}" references missing container "${e}".`});continue}let l=("number"==typeof i.width?i.width:0)-("number"==typeof i.fontSize?i.fontSize:0),o="number"==typeof i.height?i.height:0,r="number"==typeof s.width?s.width:0,n="number"==typeof s.height?s.height:0;nB(s)&&(l+24>r||o+18>n)&&t.push({code:"text-overflow",elementId:i.id,message:`Text "${i.id}" does not fit inside "${e}".`})}}return t.push(...function(e){let t=e.filter(e=>"arrow"===e.type).flatMap(nL),a=e.filter(nB),s=new Map(e.flatMap(e=>"string"==typeof e.frameId?[[e.id,e.frameId]]:[])),i=[],l=new Set;for(let e of t)for(let t of a){if(function(e){let t=e.customData;if(null===t||"object"!=typeof t)return!1;let a=t.sketchiRendererRole;return aK.some(e=>e===a)}(t)||t.id===e.startBindingId||t.id===e.endBindingId||function(e,t,a){return"frame"===e.type&&[t.arrowId,t.startBindingId,t.endBindingId].some(t=>null!==t&&a.get(t)===e.id)}(t,e,s))continue;let a=nh(t);if(!a||!su(e,a))continue;let o=`${e.arrowId}:${e.segmentIndex}:${t.id}`;l.has(o)||(l.add(o),i.push({code:"arrow-segment-through-node",elementId:e.arrowId,message:`Arrow "${e.arrowId}" passes through shape "${t.id}".`}))}return i}(e.elements)),t.push(...function(e){let t=e.filter(e=>"arrow"===e.type).flatMap(nL),a=[],s=new Set;for(let e=0;e<t.length;e+=1){let i=t[e];if(i)for(let l=e+1;l<t.length;l+=1){let e=t[l];if(!e||i.arrowId===e.arrowId||function(e,t){if(!sf(e,t))return!1;let a=e.isFirstSegment&&t.isFirstSegment&&null!==e.startBindingId&&e.startBindingId===t.startBindingId;return .01>=Math.abs((a?e.startCoordinate:e.endCoordinate)-(a?t.startCoordinate:t.endCoordinate))&&Math.sign(e.endCoordinate-e.startCoordinate)===Math.sign(t.endCoordinate-t.startCoordinate)}(i,e)||function(e,t){if(null===e.startBindingId||e.startBindingId!==t.startBindingId||e.segmentIndex!==t.segmentIndex)return!1;for(let a=0;a<=e.segmentIndex;a+=1){let s=e.route[a],i=t.route[a];if(!s||!i||Math.abs(s.x-i.x)>.01||Math.abs(s.y-i.y)>.01)return!1}return Math.sign(e.endCoordinate-e.startCoordinate)===Math.sign(t.endCoordinate-t.startCoordinate)}(i,e)||!sg(i,e))continue;let o=[i.arrowId,String(i.segmentIndex),e.arrowId,String(e.segmentIndex)].sort().join(":");s.has(o)||(s.add(o),a.push({code:"overlapping-arrow-segment",elementId:i.arrowId,message:`Arrow "${i.arrowId}" overlaps arrow "${e.arrowId}".`}))}}return a}(e.elements)),{ok:0===t.length,issues:t}}(t)}}).pipe(o.fRP("codeMode.artifacts.exportValidate")),l=e.validationIssues(i.issues);if(l.length>0)return yield*new fd({status:"export_failed",issues:l});let r=yield*fT({formats:e.formats,scene:e.scene,excalidraw:s,renderer:t.renderer}).pipe(o.xm_(e=>new fd({status:"export_failed",issues:[fB({code:"render_failed",stage:"export",..."CodeModeArtifactRendererNotConfigured"===e._tag?{ref:{kind:"artifact",path:"options.artifactFormats"}}:{},message:e.message,hint:"CodeModeArtifactRendererNotConfigured"===e._tag?"Use the hosted Studio Code Mode runtime with its Cloudflare Browser Run binding, or omit png from artifactFormats.":"Retry the request; if it keeps failing, inspect the configured renderer."})]}))),n=yield*o.OH5(()=>t.createId("artifact"));var c=yield*uu(a.write({artifactId:n,diagramId:e.scene.diagramId,formats:r,inlineFormats:e.inlineFormats,...e.provenance?{provenance:e.provenance}:{}}).pipe(o.fRP("codeMode.artifacts.store")),{artifactId:n,...e.requestId?{requestId:e.requestId}:{}}).pipe(o.xm_(e=>new fp({status:"storage_failed",cause:e,issues:[ms(e,"storage_write_failed")]}))),d=t.artifactUrl;if(!d)return c;let p=c.formats.map(e=>({...e,url:d({artifactId:c.artifactId,format:e.format})})),h=c.preview?p.find(e=>e.format===c.preview?.format):void 0;return{...c,formats:p,...h?{preview:h}:{}}}),ml=o.fn("codeMode.buildMindmap.workflow")(function*(e){var t,a;let s,l,r,n,c,d,p,h,g,u=function(e){let t=u0(u0(u0(e)?.spec)?.root);if(!t)return[];let a=[{depth:0,topic:t}],s=1;for(;a.length>0;){let e=a.pop();if(!e)continue;if(e.depth>8)return[fB({code:"mindmap_too_deep",stage:"mindmap",ref:{kind:"request",path:"spec.root.children"},message:"Mindmap depth exceeds the supported maximum of 8.",hint:"Combine overly deep topics into a shallower hierarchy."})];let t=e.topic.children;if(Array.isArray(t)){if((s+=t.length)>100)return[fB({code:"mindmap_too_large",stage:"mindmap",ref:{kind:"request",path:"spec.root"},message:"Mindmap exceeds the supported maximum of 100 topic slots.",hint:"Split this hierarchy into smaller focused mindmaps."})];for(let s=t.length-1;s>=0;s-=1){let i=u0(t[s]);i&&a.push({depth:e.depth+1,topic:i})}}}return[]}(e);if(u.length>0)return yield*new fu({status:"invalid_mindmap",context:{issues:u}});let f=i.q$Z(ol,{errors:"all",reportInput:!0})(e);if(!um.oJ(f))return yield*new fu({status:"invalid_input",context:{issues:fF(s9(f.failure))}});let m=yield*uQ,v=f.success,w=yield*o.OH5(()=>m.createId("build")),x=(t=v.spec,s=(e,t)=>({id:`topic-${t.join("-")}`,label:s5(e.label),children:(e.children??[]).map((e,a)=>s(e,[...t,a]))}),l=s5(t.title),{id:fE(t.id)??(fI(l)||"sketchi-mindmap"),title:l,root:s(t.root,[0]),layout:{direction:t.layout.direction},style:{...y}}),b={buildId:w,...me(v.requestId),normalizedSpec:x},k=(r=0,n=0,(c=(e,t)=>{r+=1,n=Math.max(n,t),e.children.forEach(e=>c(e,t+1))})(x.root,0),p=[],(d={count:r,depth:n}).count<2&&p.push(fB({code:"disconnected_graph",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:"Mindmap root must contain at least one child topic.",hint:"Add one or more nested topics under spec.root.children."})),d.depth>8&&p.push(fB({code:"mindmap_too_deep",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:`Mindmap depth ${d.depth} exceeds the supported maximum of 8.`,hint:"Combine overly deep topics into a shallower hierarchy."})),d.count>100&&p.push(fB({code:"mindmap_too_large",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:`Mindmap has ${d.count} topics; the supported maximum is 100.`,hint:"Split this hierarchy into smaller focused mindmaps."})),p);if(k.length>0)return yield*new fu({status:"invalid_mindmap",context:{...b,issues:k}});let M=yield*o.SvU({try:()=>{var e;let t,a,s;return e={id:x.id,title:x.title,root:x.root,direction:x.layout.direction,style:y},t=[],a=[],(s=(e,i,l)=>{let o=i.join("-"),r=i.length-1,n={depth:r,siblingIndex:i.at(-1)};t.push({id:`topic-${o}`,label:e.label,kind:0===r?"root":"topic",metadata:n}),l&&a.push({id:`branch-${o}`,source:l,target:`topic-${o}`,metadata:n}),e.children?.forEach((e,t)=>s(e,[...i,t],`topic-${o}`))})(e.root,[0]),eV({id:e.id,title:e.title,type:ez,nodes:t,edges:a,layout:{direction:e.direction??"LR",edgeRouting:"curved"},...e.style?{style:{...e.style}}:{}})},catch:e=>new fu({status:"invalid_mindmap",context:{...b,issues:[fB({code:"disconnected_graph",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:e instanceof Error?e.message:"Mindmap failed core validation.",hint:"Repair the nested topic hierarchy and call buildMindmap again."})]}})}),C=(a=v.options?.minQualityScore??8,{accepted:(g=Math.max(0,10-2*(h=M.nodes.filter(e=>/^(topic|branch|item|mindmap)$/i.test(e.label.trim()))).length))>=a,score:g,threshold:a,summary:{nodeCount:M.nodes.length,edgeCount:M.edges.length},checks:h.map(e=>({code:"generic_label",passed:!1,severity:"warning",message:`Topic "${e.label}" is too generic.`,refs:[{kind:"node",id:e.id}]}))}),z={...b,quality:C};if(!C.accepted)return yield*new fu({status:"quality_failed",context:{...z,issues:fO(C)}});let _=yield*o.SvU({try:()=>{let e,t,a,s,i,l,o,r,n,c,d,p,h,g,u,f,m;return s=Math.round(40-Math.min(...(a=function(e,t){let a=a=>{var s;let i,l,o,r,n,c,d,p,h,g,u,f,m,v,y,w,x,b,k,M,C,z,_,L;return l=function(e){let t=e.length,a=1/0,s=Math.ceil(e.length/2);for(let i=1;i<=e.length;i+=1){let l=Math.abs(dd(e.slice(0,i))-dd(e.slice(i)));(l<a-1e-6||1e-6>=Math.abs(l-a)&&Math.abs(i-s)<Math.abs(t-s))&&(t=i,a=l)}return t}(i=e.children.map(e=>(function e(t,a){let s={x0:0,x1:t.width,y0:-t.height/2,y1:t.height/2};if(0===t.children.length)return dn([s],new Map([[t.id,{x:0,y:0}]]),new Set);let i=t.depth>=a,l=t.depth<=1?14:8,o=t.children.map(t=>e(t,a)),r=48*!!i,n=i?[s]:[],c=[];for(let e of o){let t=e.boxes.map(e=>dr(e,r,0)),a=c.length>0?sm(n,t,l,8):i?Math.max(sm(n,t,12,8),s.y1+12-e.top):0;c.push(a),n.push(...t.map(e=>dr(e,0,a)))}let d=c[0],p=c.at(-1),h=new Set(o.flatMap(e=>[...e.folded]));i&&h.add(t.id);let g=i?0:t.width+44+Math.min(40,.08*(p-d)),u=i?0:(d+p)/2,f=new Map([[t.id,{x:0,y:0}]]);o.forEach((e,t)=>{for(let[a,s]of e.places)f.set(a,{x:s.x+r+g,y:s.y+c[t]-u})});let m=i?{x0:20,x1:r,y0:s.y1,y1:p}:{x0:t.width,x1:g,y0:d-u,y1:p-u};return dn([s,m,...(i?n.slice(1):n).map(e=>dr(e,g,-u))],f,h)})(e,a))),r=(o=i.map((e,t)=>t)).slice(0,l),n=o.slice(l).toReversed(),c=r.map(e=>i[e]),d=n.map(e=>i[e]),p=e.width/2,h=e.height/2,g=p+72,f=(u=e=>Math.max(p,...e.map(e=>g+e.outer)))(c)+u(d),m=Math.max(e.height,dd(c),dd(d)),y=Math.max(0,(v=(f+40)/1.8-40)-m),w=(f+40)/2.4-40,x=e=>e[0]?e[0].bottom-e[0].top:void 0,b=c.length<=1&&d.length<=1?function(e,t,a,s){let i=a=>{let i=[[-s/2,s/2],...void 0===e?[]:[[-a-e/2,-a+e/2]],...void 0===t?[]:[[a-t/2,a+t/2]]];return Math.max(...i.map(([,e])=>e))-Math.min(...i.map(([e])=>e))},l=0,o=(Math.max(e??0,t??0)+s)/2+28;if(i(o)<=a)return o;if(i(l)>=a)return 0;for(let e=0;e<24;e+=1){let e=(l+o)/2;i(e)<a?l=e:o=e}return o}(x(c),x(d),w,e.height):0,M=[],(k=(e,a,s)=>{var i;let l,o,r=t=>Math.max(0,t-dd(e))/(e.length-1),n=e.length>1?Math.max(Math.min(120,r(v)),r(w)):0,c=(l=[],o=s-dd(e,i=y>0?n:0)/2,e.forEach((t,a)=>{a>0&&(o+=dc(e[a-1],t)+i),l.push(o-t.top),o+=t.bottom-t.top}),l);return e.map((e,s)=>({block:e,side:t?-a:a,y:c[s],inner:g}))})(c,1,-b).forEach((e,t)=>M[r[t]]=e),k(d,-1,b).forEach((e,t)=>M[n[t]]=e),C=Math.max(...M.map(e=>Math.abs(e.y))),s=M.map(e=>{if(0===C)return e;let t=.6*(e.y/C)**2,a=e.y+e.block.bottom>-h-28&&e.y+e.block.top<h+28;return{...e,inner:a?Math.max(g-72*t,p+44):Math.max(g-t*g,44)}}),_=[z={topic:e,parent:void 0,branch:-1,side:1,folded:!1,x:-e.width/2,y:-e.height/2}],L=(e,t,a,s)=>{let i=a.block.places.get(e.id),l=a.inner+i.x,o={topic:e,parent:t,branch:s,side:a.side,folded:-1!==t.branch&&a.block.folded.has(t.topic.id),x:1===a.side?l:-l-e.width,y:a.y+i.y-e.height/2};for(let t of(_.push(o),e.children))L(t,o,a,s)},e.children.forEach((e,t)=>L(e,z,s[t],t)),_},s=a(1/0);for(let t=function e(t){return Math.max(t.depth,...t.children.map(e))}(e)-1;t>=1&&!(dp(s)<=2.4+.01);t-=1){let e=a(t);dp(e)<dp(s)&&(s=e)}return s}(t=function(e){let t=new Map;for(let a of e.edges){let e=t.get(a.source)??[];e.push({id:a.target,index:a.metadata.siblingIndex}),t.set(a.source,e)}let a=new Map(e.nodes.map(e=>[e.id,e])),s=(e,i)=>{let l=a.get(e),{fontSize:o,textWidth:r,padX:n,padY:c}=dl(i),d=function(e,t,a){let s=e=>e.split("\n").length,i=aO(e,t,a);if(1===s(i))return i;let l=a,o=t;for(;o-l>1;){let t=Math.floor((l+o)/2);s(aO(e,t,a))<=s(i)?o=t:l=t}return aO(e,o,a)}(l.label,r,o),p=Math.ceil(Math.max(aq(d,o),aF(d,o,r))),h=Math.ceil(d.split("\n").length*o*1.35),g=0===i?function(e,t){let a=Math.ceil((e+36)*Math.SQRT2),s=Math.ceil((t+20)*Math.SQRT2);for(;a4({shape:"ellipse",width:a,height:s}).width<e+18;)a+=1;for(;a4({shape:"ellipse",width:a,height:s}).height<t+10;)s+=1;return{width:a,height:s}}(p,h):{width:p+2*n,height:h+2*c};return{id:e,depth:i,text:d,fontSize:o,...g,children:(t.get(e)??[]).toSorted((e,t)=>e.index-t.index).map(e=>s(e.id,i+1))}};return s(e.nodes.find(e=>"root"===e.kind).id,0)}(e=eP(M)),"RL"===e.layout.direction)).map(e=>e.x))),i=Math.round(40-Math.min(...a.map(e=>e.y))),l=e.style.accentColor,o=e.style.backgroundColor,r=e=>-1===e.branch?l:nW[e.branch%nW.length],n=e=>-1===e.branch?{}:{groupIds:[`branch:${t.children[e.branch].id}`]},c=a.map(e=>{var t;let a,{topic:l}=e,c=[.18,.16,.06][l.depth];return{type:"node",id:`node:${l.id}`,nodeId:l.id,kind:0===l.depth?"root":"topic",shape:0===l.depth?"ellipse":"rectangle",x:Math.round(e.x)+s,y:Math.round(e.y)+i,width:l.width,height:l.height,label:l.text,strokeColor:r(e),strokeWidth:dl(l.depth).strokeWidth,...void 0===c?{}:{fillColor:(t=r(e),a=(e,t)=>Number.parseInt(e.slice(t,t+2),16),`#${[1,3,5].map(e=>Math.round(a(o,e)+(a(t,e)-a(o,e))*c).toString(16).padStart(2,"0")).join("")}`),fillStyle:"solid"},...n(e)}}),d=a.map((e,t)=>({type:"text",id:`label:${e.topic.id}`,containerId:c[t].id,x:c[t].x+e.topic.width/2,y:c[t].y+e.topic.height/2,text:e.topic.text,fontSize:e.topic.fontSize,maxWidth:Math.max(1,e.topic.width-24),...n(e)})),p=new Map(c.map(e=>[e.nodeId,e])),h=function(e,t){let a=e.width/2,s=e.height/2,i=new Map;for(let l of[1,-1]){let o=t.filter(e=>e.side===l).map(t=>{let i=du(t.shape,l),o=Math.atan2((i.y-e.y-s)/s,l*(i.x-e.x-a)/a);return{id:t.shape.nodeId,angle:o}}).toSorted((e,t)=>e.angle-t.angle),r=o[0]?.angle??0,n=o.at(-1)?.angle??0;o.forEach((e,t)=>{let a=1===o.length?e.angle:r+(n-r)*t/(o.length-1);i.set(e.id,(e.angle+a)/2)})}return i}(c[0],a.flatMap((e,t)=>1===e.topic.depth?[{shape:c[t],side:e.side}]:[])),g=new Map(e.edges.map(e=>[e.target,e.id])),u=a.flatMap((e,t)=>{if(!e.parent)return[];let{topic:a}=e,s=g.get(a.id),i=function(e,t,a,s){let i=a.side,l=du(e,i);if(void 0!==s){let e=t.width/2,a=t.height/2,o={x:t.x+e+i*e*Math.cos(s),y:t.y+a+a*Math.sin(s)};return dg([o,{x:o.x+.4*(l.x-o.x),y:o.y+.4*(l.y-o.y)},{x:l.x-.5*i*Math.abs(l.x-o.x),y:l.y},l])}if(a.folded){let e={x:1===i?t.x+20:t.x+t.width-20,y:t.y+t.height};return dg([e,{x:e.x,y:e.y+.5*(l.y-e.y)},{x:l.x-.5*i*Math.abs(l.x-e.x),y:l.y},l])}let o={x:1===i?t.x+t.width:t.x,y:t.y+t.height/2},r=.5*Math.abs(l.x-o.x);return dg([o,{x:o.x+i*r,y:o.y},{x:l.x-i*r,y:l.y},l])}(c[t],p.get(e.parent.topic.id),e,h.get(a.id));return[{type:"arrow",id:`edge:${s}`,edgeId:s,sourceNodeId:e.parent.topic.id,targetNodeId:a.id,points:i,...i.length>2?{curved:!0}:{},endArrowhead:null,strokeColor:r(e),strokeWidth:1===a.depth?4:2,...-1===e.parent.branch?{}:n(e)}]}),f=Math.max(...c.map(e=>e.x+e.width)),m=Math.max(...c.map(e=>e.y+e.height)),{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:f+40,height:m+40,accentColor:l,backgroundColor:o,elements:[...u,...c,...d],layers:[],layouts:[],zOrder:[...u,...c,...d].map(e=>e.id)}},catch:e=>new fu({status:"render_failed",context:{...z,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:x.id},message:e instanceof Error?e.message:"Unable to render mindmap scene.",hint:"Simplify the hierarchy or retry with a smaller mindmap."})]}})}).pipe(o.fRP("codeMode.buildMindmap.render")),L={...z,partial:mt(_)},B=yield*mi({scene:_,formats:fU(v.options),inlineFormats:fX(v.options),...v.requestId?{requestId:v.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fu({status:e.status,context:{..."export_failed"===e.status?L:{...z,partial:{diagramId:_.diagramId}},issues:e.issues}})));return{ok:!0,status:"accepted",buildId:w,...me(v.requestId),normalizedSpec:x,quality:C,artifact:B,issues:[]}}),mo=o.fn("codeMode.buildSequenceDiagram.workflow")(function*(e){var t,a;let s,l=i.q$Z(lj,{errors:"all",reportInput:!0})(e);if(!um.oJ(l))return yield*new ff({status:"invalid_input",context:{issues:fF(s9(l.failure))}});let r=yield*uQ,n=l.success,c=yield*o.OH5(()=>r.createId("build")),d=(s=s5((t=n.spec).title),{id:fE(t.id)??(fI(s)||"sketchi-sequence"),title:s,participants:t.participants.map(e=>({id:s5(e.id),label:s5(e.label),...e.kind?{kind:s5(e.kind)}:{},...e.icon?{icon:{slug:e.icon.slug}}:{}})),messages:t.messages.map((e,t)=>({id:fE(e.id)??`message-${t+1}-${fI(e.source)}-${fI(e.target)}`,source:s5(e.source),target:s5(e.target),label:s5(e.label),...e.type?{type:e.type}:{},...e.style?{style:e.style}:{}})),style:{...y}}),p=uO(d.participants,r.icons,{noun:"participant",path:"participants"}),h={...d,participants:p.nodes},g={buildId:c,...me(n.requestId),normalizedSpec:h},u=eG(u6(h)).map(e=>fB({code:u7[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:u8[e.code]??e.hint}));if(u.length>0)return yield*new ff({status:"invalid_sequence",context:{...g,issues:u}});let f={accepted:10>=(a=n.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:h.participants.length,edgeCount:h.messages.length},checks:[]},m={...g,quality:f};if(!f.accepted)return yield*new ff({status:"quality_failed",context:{...m,issues:fO(f)}});let v=yield*o.SvU({try:()=>{let e,t,a,s,i,l,o,r,n,c,d,p,g,u,f,m,v,y,w,x;return s=(a=Math.max(180,...[...(t=new Map((e=eR(u6(h))).participants.map(e=>[e.id,aO(e.label,156,14)]))).values()].map(e=>Math.ceil(aq(e,14))+24)))+140,r=(o=(l=48+(i=e.participants.reduce((e,a)=>Math.max(e,Math.ceil(14*(t.get(a.id)??a.label).split("\n").length*1.35)+18+a6(a.icon?{slug:a.icon.slug,size:28}:void 0)),72)))+64)+88*Math.max(0,e.messages.length-1),n=Math.max(o,r)-l+56,c=new Map,d=[],p=[],g=[],e.participants.forEach((o,r)=>{let h=48+r*s,u=h+a/2;c.set(o.id,u),d.push({type:"node",id:`node:${o.id}`,nodeId:o.id,...o.kind?{kind:o.kind}:{},...o.icon?{icon:{slug:o.icon.slug,size:28}}:{},shape:"rectangle",x:h,y:48,width:a,height:i,label:t.get(o.id)??o.label}),p.push({type:"text",id:`label:${o.id}`,containerId:`node:${o.id}`,x:u,y:48+i/2,text:t.get(o.id)??o.label,fontSize:14,maxWidth:a-24,...o.icon?{verticalAlign:"bottom"}:{}}),g.push({type:"node",id:`node:${eE(o.id)}`,nodeId:eE(o.id),rendererRole:"sequence-lifeline",shape:"rectangle",fillColor:e.style.backgroundColor,strokeColor:e.style.accentColor,x:u-1,y:l,width:2,height:n,label:`${o.label} lifeline`})}),u=new Map(e.participants.map(e=>[e.id,e.label])),f=(function(e){let t=new Map,a=[];e.messages.forEach((e,s)=>{if("return"!==e.type)return void t.set(e.target,[...t.get(e.target)??[],{caller:e.source,index:s,messageId:e.id}]);let i=t.get(e.source)??[],l=i.findLastIndex(t=>t.caller===e.target),o=i[l];o&&(t.set(e.source,i.filter((e,t)=>t!==l)),a.push({participantId:e.source,callMessageId:o.messageId,returnMessageId:e.id,startIndex:o.index,endIndex:s}))});let s=[];for(let e of a.toSorted((e,t)=>e.startIndex-t.startIndex)){let t=s.filter(t=>t.participantId===e.participantId&&t.endIndex>e.startIndex),a=new Set(t.map(e=>e.depth)),i=Math.max(0,...t.filter(t=>t.endIndex>e.endIndex).map(e=>e.depth+1));for(;a.has(i);)i+=1;s.push({...e,depth:i})}return s})(e).map(t=>{var a,s;let i=(a=t.participantId,s=t.callMessageId,`${eE(a)}:activation:${s}`),l=c.get(t.participantId)??0,r=o+88*t.startIndex-12;return{activation:t,node:{type:"node",id:`node:${i}`,nodeId:i,rendererRole:"sequence-activation",shape:"rectangle",fillColor:e.style.backgroundColor,strokeColor:e.style.accentColor,x:l-6+6*t.depth,y:r,width:12,height:o+88*t.endIndex+12-r,label:`${u.get(t.participantId)??t.participantId} active`}}}),m=(e,t,a,s)=>{let i=c.get(e)??0,l=s>i,o=f.filter(({activation:a})=>a.participantId===e&&a.startIndex<=t&&t<=a.endIndex),r=o.find(({activation:e})=>e.callMessageId===a||e.returnMessageId===a)??o.reduce((e,t)=>!e||t.activation.depth>e.activation.depth?t:e,void 0);return r?{nodeId:r.node.nodeId,x:l?r.node.x+r.node.width:r.node.x}:{nodeId:eE(e),x:i+(l?1:-1)*2/2}},v=e.messages.map((e,t)=>{let a,i=c.get(e.source)??0,l=c.get(e.target)??0,r=m(e.source,t,e.id,l),n=m(e.target,t,e.id,i),d=o+88*t;return{type:"arrow",id:`arrow:${e.id}`,edgeId:e.id,sourceNodeId:r.nodeId,targetNodeId:n.nodeId,..."return"===e.type?{strokeColor:"#6b7280"}:{},..."dashed"===e.style||"return"===e.type?{strokeStyle:"dashed"}:{},points:[{x:r.x,y:d},...(a=Math.round(Math.abs(l-i)/s))<2||a%2==1?[]:[{x:(i+l)/2-Math.sign(l-i)*s/2,y:d}],{x:n.x,y:d}],label:e.label}}),y=f.map(({node:e})=>e),w=[...v,...g,...y,...d,...p],x=[...g.map(e=>e.id),...y.map(e=>e.id),...d.map(e=>e.id),...p.map(e=>e.id),...v.map(e=>e.id)],{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:96+a+Math.max(0,e.participants.length-1)*s,height:l+n+48,accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:w,layers:[],layouts:[],zOrder:x}},catch:e=>new ff({status:"render_failed",context:{...m,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:h.id},message:e instanceof Error?e.message:"Unable to render sequence diagram scene.",hint:"Repair the participant/message structure and retry."})]}})}).pipe(o.fRP("codeMode.buildSequenceDiagram.render")),w=yield*uU(v,r.icons),x=w.scene,b=se(x);if(b.length>0)return yield*new ff({status:"render_failed",context:{...m,issues:f$(b).map(e=>({...e,hint:"Reduce participant label lines, participants, or messages and retry buildSequenceDiagram."}))}});let k={...m,partial:mt(x)},M=yield*mi({scene:x,formats:fU(n.options),inlineFormats:fX(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new ff({status:e.status,context:{..."export_failed"===e.status?k:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...me(n.requestId),normalizedSpec:h,quality:f,artifact:M,issues:[...p.issues,...w.issues]}}),mr=o.fn("codeMode.buildStateMachine.workflow")(function*(e){var t,a;let s,l,r=i.q$Z(lK,{errors:"all",reportInput:!0})(e);if(!um.oJ(r))return yield*new fm({status:"invalid_input",context:{issues:fF(s9(r.failure))}});let n=yield*uQ,c=r.success,d=yield*o.OH5(()=>n.createId("build")),p=(s=s5((t=c.spec).title),l=(e,t)=>t&&s5(t)?{[e]:s5(t)}:{},{id:fE(t.id)??(fI(s)||"sketchi-state-machine"),title:s,initial:s5(t.initial),states:t.states.map(e=>{let t=s5(e.id),a=e4({...e,id:t});return{id:t,...void 0!==a?{label:a}:{},...e.kind?{kind:e.kind}:{},...l("parent",e.parent),...l("initial",e.initial)}}),transitions:t.transitions.map((e,t)=>({id:fE(e.id)??`transition-${t+1}-${fI(e.source)}-${fI(e.target)}`,source:s5(e.source),target:s5(e.target),...l("event",e.event),...l("guard",e.guard),...l("action",e.action)})),...t.layout?{layout:{direction:t.layout.direction}}:{},style:{...y}}),h={buildId:d,...me(c.requestId),normalizedSpec:p},g=e8(u9(p)).map(e=>fB({code:fe[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(g.length>0)return yield*new fm({status:"invalid_state_machine",context:{...h,issues:g}});let u={accepted:10>=(a=c.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:p.states.length,edgeCount:p.transitions.length},checks:[]},f={...h,quality:u};if(!u.accepted)return yield*new fm({status:"quality_failed",context:{...f,issues:fO(u)}});let m=yield*o.SvU({try:()=>(function(e){let t=t=>hS(function(e,t){let a=e6(e),s=(e,t,a,s)=>({id:e,label:t,kind:a,metadata:{},...s?{group:s}:{}}),i=(e,t,a,s)=>({id:e,source:t,target:a,metadata:{},...s?{label:s}:{}}),l=new Set(e.transitions.map(e=>e.id)),o=e=>{let t=e;for(let a=2;l.has(t);a+=1)t=`${e}~${a}`;return l.add(t),t},r=[s(hP,"","initial")],n=[i(o(hP),hP,e.initial)],c=new Map,d=new Map;for(let t of e.states){if("final"!==e3(t)||void 0!==e4(t))continue;let a=e.transitions.filter(e=>e.target===t.id),s=a.map((e,a)=>0===a?t.id:`${t.id}:${a+1}`);a.forEach((e,t)=>c.set(e.id,s[t])),d.set(t.id,s.length>0?s:[t.id])}for(let t of e.states){let e=t.parent;if(a.has(t.id)){t.initial&&(r.push(s(`${t.id}${hP}`,"","initial",t.id)),n.push(i(o(`${t.id}${hP}`),`${t.id}${hP}`,t.initial)));continue}let l=e3(t),c=e4(t);if("final"===l&&void 0===c){for(let a of d.get(t.id))r.push(s(a,"","final",e));continue}if("final"===l){r.push(s(t.id,c,"state",e)),r.push(s(`${t.id}:end`,"","final",e)),n.push(i(o(`${t.id}:end`),t.id,`${t.id}:end`));continue}r.push(s(t.id,c??"",l,e))}for(let t of e.transitions){let e=function(e){let t=e.guard?e7(e.guard,/^\s*\[|\]\s*$/gu):"",a=e.action?e7(e.action,/^\s*\//u):"";return[e.event?.trim(),t&&`[${t}]`,a&&`/ ${a}`].filter(Boolean).join(" ")}(t);n.push(i(t.id,t.source,c.get(t.id)??t.target,e||void 0))}return{id:e.id,title:e.title,type:"flowchart",nodes:r,edges:n,groups:e.states.filter(e=>a.has(e.id)).map(e=>({id:e.id,label:e4(e)??""})),layout:{direction:t,edgeRouting:"orthogonal"},style:e.style,metadata:{}}}(e,t),{pairedReturns:!0});if(e.layout)return t(e.layout.direction);let a=["LR","TB"].map(e=>{let a,s=t(e);return{aspect:Math.max(s.width/s.height,s.height/s.width),cost:hy(a=s.elements.filter(e=>"arrow"===e.type))+sq(a.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),s_({width:s.width,height:s.height})).length,scene:s}}),s=a.filter(e=>e.aspect<=2.2),[i]=s.length>0?s.toSorted((e,t)=>e.cost-t.cost):a.toSorted((e,t)=>e.aspect-t.aspect);return i.scene})(u9(p)),catch:e=>new fm({status:"render_failed",context:{...f,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render state machine scene.",hint:"Repair the state and transition structure and retry."})]}})}).pipe(o.fRP("codeMode.buildStateMachine.render")),v=se(m);if(v.length>0)return yield*new fm({status:"render_failed",context:{...f,issues:f$(v).map(e=>({...e,hint:"Shorten state labels or split the machine and retry buildStateMachine."}))}});let w={...f,partial:mt(m)},x=yield*mi({scene:m,formats:fU(c.options),inlineFormats:fX(c.options),...c.requestId?{requestId:c.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fm({status:e.status,context:{..."export_failed"===e.status?w:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:d,...me(c.requestId),normalizedSpec:p,quality:u,artifact:x,issues:[]}}),mn=o.fn("codeMode.buildErDiagram.workflow")(function*(e){var t,a;let s,l,r,n,c=i.q$Z(l0,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:function(e){if(!tV(e))return e;let t=Array.isArray(e.entities)?e.entities.map(e=>tV(e)&&Array.isArray(e.fields)?{...e,fields:e.fields.map(e=>"string"==typeof e?tS(e):e)}:e):e.entities,a=Array.isArray(e.relationships)?e.relationships.map(e=>{if(!tV(e))return e;let{source:t,target:a,cardinality:s,...i}=e,l=function(e){if("string"!=typeof e)return;let t=e.trim().toLowerCase().split(/\s*(?:-to-|\sto\s|:)\s*/u);if(2!==t.length)return;let a=e=>tP(/^m$|^n$/u.test(e)?"many":e);return[a(t[0]),a(t[1])]}(s),o={...i,from:i.from??t,to:i.to??a,fromCardinality:tP(i.fromCardinality??l?.[0]),toCardinality:tP(i.toCardinality??l?.[1])};for(let e of["from","to","fromCardinality","toCardinality"])void 0===o[e]&&delete o[e];return void 0!==s&&void 0===l&&(o.cardinality=s),o}):e.relationships;return{...e,...void 0===t?{}:{entities:t},...void 0===a?{}:{relationships:a}}}(e.spec)}:e);if(!um.oJ(c))return yield*new fv({status:"invalid_input",context:{issues:fF(s9(c.failure))}});let d=yield*uQ,p=c.success,h=yield*o.OH5(()=>d.createId("build")),g=(s=s5((t=p.spec).title),l=(e,t)=>t&&s5(t)?{[e]:s5(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.relationships.flatMap(e=>fE(e.id)??[])),{id:fE(t.id)??(fI(s)||"sketchi-er-diagram"),title:s,entities:t.entities.map(e=>({id:s5(e.id),...l("name",e.name),fields:e.fields.map(e=>{let t="string"==typeof e?tS(s5(e)):e;return{name:s5(t.name),...l("type",t.type),...r("pk",t.pk),...r("fk",t.fk),...r("unique",t.unique),...r("nullable",t.nullable)}})})),relationships:t.relationships.map((e,t)=>({id:fE(e.id)??(e=>{let t=e+1;for(;n.has(`relationship-${t}`);)t+=1;return n.add(`relationship-${t}`),`relationship-${t}`})(t),from:s5(e.from),to:s5(e.to),fromCardinality:e.fromCardinality,toCardinality:e.toCardinality,...l("label",e.label)})),style:{...y}}),u={buildId:h,...me(p.requestId),normalizedSpec:g},f=tz(ft(g)).map(e=>fB({code:"missing_relationship_entity"===e.code&&e.path.endsWith(".from")?"missing_edge_source":fa[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new fv({status:"invalid_er_diagram",context:{...u,issues:f}});let m={accepted:10>=(a=p.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:g.entities.length,edgeCount:g.relationships.length},checks:[]},v={...u,quality:m};if(!m.accepted)return yield*new fv({status:"quality_failed",context:{...v,issues:fO(m)}});let w=yield*o.SvU({try:()=>{var e;let t,a,s,i,l,o,r,n,c,d,p;return t=new Map((e=ft(g)).entities.map(e=>[e.id,function(e){let t=tk(e),a=e.fields.map(e=>[e.pk&&"PK",e.fk&&"FK",e.unique&&!e.pk&&"UK"].filter(e=>"string"==typeof e).join(" ")),s=e.fields.map(e=>`${e.name.trim()}${e.nullable&&!e.type?"?":""}`),i=e.fields.map(e=>e.type?`${e.type}${e.nullable?"?":""}`:""),[l,o,r]=[a,s,i].map(hR),n=14+l+8*(l>0)+o+(r>0?16+r:0)+14,c=Math.ceil(aq(t,16))+28;return{entity:e,name:t,width:Math.max(160,n,c),height:e.fields.length>0?52+28*e.fields.length:40,keys:a,names:s,types:i,keyWidth:l,nameWidth:o,typeWidth:r,rows:new Map(e.fields.map((e,t)=>[tC(e.name),46+(t+.5)*28]))}}(e)])),a=e.relationships.map(e=>(function(e,t){let[a,s]=[tM(e.from),tM(e.to)],i=(e,a)=>{let s=t.get(e.entity);if(void 0!==e.field)return s.rows.get(tC(e.field));let i=s.entity.fields.filter(e=>e.pk);return void 0!==a.field&&1===i.length?s.rows.get(tC(i[0].name)):20},l={from:{entity:a.entity,y:i(a,s),cardinality:e.fromCardinality},to:{entity:s.entity,y:i(s,a),cardinality:e.toCardinality}},o=e=>{let a=void 0===e.field?void 0:t.get(e.entity).entity.fields.find(t=>tC(t.name)===tC(e.field));return void 0!==a&&!0===a.pk&&!0!==a.fk};return(hD(e.fromCardinality)!==hD(e.toCardinality)?hD(e.fromCardinality):!(o(s)&&!o(a)))?{relationship:e,parent:l.from,child:l.to}:{relationship:e,parent:l.to,child:l.from}})(e,t)),i=new Map((s=function(e,t,a){let s,i=a.map(e=>{let t;return{id:e.relationship.id,parent:e.parent.entity,child:e.child.entity,parentY:e.parent.y,childY:e.child.y,labelWidth:(t=e.relationship.label)?Math.min(160,Math.ceil(aq(t,13))):0}}),l=[...t.values()].map(e=>({id:e.entity.id,width:e.width,height:e.height})),o=e.entities.length>24?h2.slice(0,2):h2,r=new Set;for(let n of o){let o=function(e,t,a={}){let s,i,l,o,r,n=(s=new Map(e.map((e,t)=>[e.id,t])),{tables:e,index:s,links:t,pairs:t.flatMap(e=>e.parent===e.child?[]:[{parent:s.get(e.parent),child:s.get(e.child),link:e}])}),c=(i=function(e,t=1.6){let a=e.tables.reduce((e,t)=>e+(t.width+132)*(t.height+56),0),s=Math.max(...e.tables.map(e=>e.height)),i=e.tables.reduce((e,t)=>e+t.height+56,0)/e.tables.length,l=e.tables.reduce((e,t)=>e+t.width+150,0)/e.tables.length,o=Math.max(s,Math.sqrt(a/t));return{height:o,unit:i,width:1.25*t*o,column:l}}(n,a.aspect),l=a.sameColumn??2.5,o="hub"===a.start?function(e){let t=hq(e),a=e.tables.map(()=>void 0),s=new Map;for(let i of e.tables.map((e,t)=>t).sort((e,a)=>t[a].size-t[e].size||e-a)){if(void 0!==a[i])continue;a[i]=0,s.set(i,0);let l={[-1]:0,1:0},o=[i];for(;o.length>0;){let i=o.shift();for(let r of[...t[i]].filter(e=>void 0===a[e]).sort((e,a)=>t[a].size-t[e].size||e-a)){let t=s.get(i);0===t&&(t=l[1]<=l[-1]?1:-1,l[t]=l[t]+e.tables[r].height),a[r]=a[i]+t,s.set(r,t),o.push(r)}}}return a.map(e=>e??0)}(n):function(e){let t=e.tables.length,a=Array.from({length:t},()=>[]);for(let{parent:t,child:s}of e.pairs)a[t].push(s);let s=Array.from({length:t}).fill(0),i=Array.from({length:t},()=>[]),l=e=>{for(let t of(s[e]=1,a[e]))1!==s[t]&&(i[e].push(t),0===s[t]&&l(t));s[e]=2};for(let e=0;e<t;e+=1)0===s[e]&&l(e);let o=Array.from({length:t},()=>[]);for(let[e,t]of i.entries())for(let a of t)o[a].push(e);let r=Array.from({length:t},()=>0),n=[],c=o.map(e=>e.length),d=c.flatMap((e,t)=>0===e?[t]:[]);for(;d.length>0;){let e=d.shift();for(let t of(n.push(e),i[e]))r[t]=Math.max(r[t],r[e]+1),c[t]-=1,0===c[t]&&d.push(t)}for(let e of[...n].reverse())0===o[e].length&&i[e].length>0&&(r[e]=Math.min(...i[e].map(e=>r[e]))-1);return r}(n),hF(n,o,40,e=>hV(n,e,i,l)),r=new Map,hF(n,o,8,e=>{let t=hH(e),a=t.join(","),s=r.get(a);return void 0===s&&(s=h$(hI(n,t),!1).crossings,r.set(a,s)),hV(n,e,i,l)+ +s}),hH(o)),d=Math.max(...c)+1,p=hI(n,c),h=h$(p),g=function(e,t){let a=[...t.top],s=hY(e);for(let i=0;i<12;i+=1){let l=[...t.columns.keys()];for(let o of(i%2==1&&l.reverse(),l)){let i=t.columns[o];if(0===i.length)continue;let l=[],r=[];for(let t of i){let i=e.corridor[t];if(i){l.push(a[i.parent]+i.y-2),r.push(4);continue}let n=0,c=0;for(let{other:i,ownY:l,otherY:r}of s[t])e.column[i]!==o&&(n+=a[i]+r-l,c+=1);l.push(c>0?n/c:a[t]),r.push(c>0?c:.05)}let n=hO(e,i),c=function(e,t){let a=[];for(let[s,i]of e.entries()){let e=t[s];for(a.push({count:1,weight:e,sum:i*e});a.length>1;){let e=a.at(-1),t=a.at(-2);if(t.sum/t.weight<=e.sum/e.weight)break;a.pop(),t.count+=e.count,t.weight+=e.weight,t.sum+=e.sum}}return a.flatMap(e=>Array(e.count).fill(e.sum/e.weight))}(l.map((e,t)=>e-n[t]),r);for(let[e,t]of i.entries())a[t]=c[e]+n[e]}}return function(e,t,a){let s=hY(e),i=t=>t.reduce((t,i)=>t+s[i].filter(({other:t,ownY:s,otherY:l})=>e.column[t]!==e.column[i]&&.5>Math.abs(a[t]+l-a[i]-s)).length,0),l=(t,s)=>a[s]-a[t]-e.height[t]-hE(e,t,s)<.5;for(let o=0;o<2;o+=1)for(let o of t.columns)for(let[t,r]of o.entries())if(!e.corridor[r])for(let n of s[r].flatMap(({other:t,ownY:s,otherY:i})=>{let l=a[t]+i-a[r]-s;return e.column[t]!==e.column[r]&&Math.abs(l)>=.5&&40>=Math.abs(l)?[l]:[]})){let s=[r],c=n>0?1:-1;for(let i=t;;i+=c){let t=o[i+c];if(void 0===t)break;if(!(c>0?l(o[i],t):l(t,o[i]))){(c>0?a[t]-a[o[i]]-e.height[o[i]]-hE(e,o[i],t):a[o[i]]-a[t]-e.height[t]-hE(e,t,o[i]))<Math.abs(n)-.5&&(s.length=0);break}s.push(t)}if(0===s.length)continue;let d=i(s);for(let e of s)a[e]=a[e]+n;if(i(s)>d)break;for(let e of s)a[e]=a[e]-n}return a}(e,t,a.map(e=>Math.round(e)))}(p,h),u=function(e,t,a,s){let i=new Map,l=[],o=[];for(let a of e.links){let[r,n]=[e.index.get(a.parent),e.index.get(a.child)],[c,d]=[t[r],t[n]];if(c===d){o.push(a);continue}let[p,h]=c<d?["right","left"]:["left","right"];i.set(a.id,{parent:p,child:h}),l.push({column:c,side:p,y:s[r]+a.parentY}),l.push({column:d,side:h,y:s[n]+a.childY})}for(let r of o){let[o,n]=[e.index.get(r.parent),e.index.get(r.child)],c=t[o],[d,p]=[s[o]+r.parentY,s[n]+r.childY],[h,g]=[Math.min(d,p),Math.max(d,p)],u=e=>l.filter(t=>t.column===c&&t.side===e&&t.y>h&&t.y<g).length,f=0===c&&a>1?"left":"right",[m,v]=[u("left"),u("right")],y=m===v?f:m<v?"left":"right";i.set(r.id,{parent:y,child:y}),l.push({column:c,side:y,y:d},{column:c,side:y,y:p})}return i}(n,c,d,g),f=function(e,t,a,s){let i=Array.from({length:Math.max(0,s-1)},()=>0),l=Array.from({length:Math.max(0,s-1)},()=>0),o=new Map,r=(e,a,s)=>{let i="right"===a?t[e]:t[e]-1,l=`${e}:${a}:${s}`,r=o.get(l)??{gap:i,low:"right"===a,count:0};r.count+=1,o.set(l,r)};for(let s of e.links){let[o,n]=[e.index.get(s.parent),e.index.get(s.child)],[c,d]=[t[o],t[n]],p=a.get(s.id);r(o,p.parent,s.parentY),r(n,p.child,s.childY);let h="right"===p.parent?c:c-1;if(s.labelWidth>0&&h>=0&&h<i.length&&(l[h]=Math.max(l[h],s.labelWidth+16)),c===d){h>=0&&h<i.length&&(i[h]+=1);continue}for(let e=Math.min(c,d);e<Math.max(c,d);e+=1)i[e]+=1}let n=i.map(()=>({low:0,high:0})),c=new Map;for(let[e,{gap:t,low:a,count:s}]of o){let i=(s-1)*32,l=e.split(":").slice(0,2).join(":");c.set(l,Math.max(c.get(l)??0,i));let o=n[t];o&&(a?o.low=Math.max(o.low,i):o.high=Math.max(o.high,i))}for(let s of e.links){let[i,l]=[e.index.get(s.parent),e.index.get(s.child)];if(t[i]!==t[l])continue;let o=a.get(s.id).parent,r=n["right"===o?t[i]:t[i]-1];if(!r)continue;let d=Math.max(c.get(`${i}:${o}`)??0,c.get(`${l}:${o}`)??0)+32+Math.abs(e.tables[i].width-e.tables[l].width)/2;"right"===o?r.low=Math.max(r.low,d):r.high=Math.max(r.high,d)}return i.map((e,t)=>Math.max(132,96+n[t].low+n[t].high+l[t]+20*(e+1)))}(n,c,u,d),m=Array.from({length:d},(t,a)=>Math.max(0,...h.columns[a].flatMap(t=>t<e.length?[e[t].width]:[]))),v=88*!!t.some(e=>{let t=c[n.index.get(e.parent)];return t===c[n.index.get(e.child)]&&(0===t||t===d-1)}),y=[],w=v;for(let[e,t]of m.entries())y.push(w),w+=t+(f[e]??0);let x=Math.min(...g.slice(0,e.length));return{boxes:new Map(e.map((e,t)=>{let a=c[t];return[e.id,{x:y[a]+Math.round((m[a]-e.width)/2),y:g[t]-x,width:e.width,height:e.height}]})),sides:u}}(l,i,n),c=JSON.stringify([...o.boxes,...o.sides]);if(r.has(c))continue;r.add(c);let d=h0(e,t,a,o,h1(a,o)),p=h3(d),h=s?p:p-.75;if((!s||h<s.score)&&(s={cost:p,score:h,scene:d,placement:o}),0===p)break}let{placement:n}=s,c=h1(a,n);if(function(e,t){let a=!1;for(let s of hQ(e)){if(s.length<=2)continue;let[i,l]=[s[0].link[s[0].end].entity,s[0].side],o=t.get(i),r="left"===l?"right":"left",n=e.filter(e=>e.link[e.end].entity===i&&e.side===r&&e.row===s[0].row).length,c=a=>{let s=hZ(hK(e,a),t);return Math.max(o.y-48-s,s-(o.y+o.height+48))},d=s.filter(t=>hK(e,t).side!==t.side&&c(t)>0).sort((e,t)=>c(t)-c(e)),p=s.length;for(let e of d){if(p-n<2)break;e.side=r,p-=1,n+=1,a=!0}}return a}(c,n.boxes)){let i=h0(e,t,a,n,c);if(h3(i)<s.cost)return i}return s.scene}(e,t,a)).elements.flatMap(e=>"node"===e.type?[[e.nodeId,e]]:[])),l=e.entities.map(a=>(function(e,t,a){let{id:s}=e.entity,i=[`table:${s}`],l={type:"node",id:`node:${s}`,nodeId:s,kind:"entity",rendererRole:"er-table",shape:"rectangle",x:t.x,y:t.y,width:e.width,height:e.height,label:e.name,fillColor:a.style.backgroundColor,fillStyle:"solid",groupIds:i},o={type:"node",id:`node:${s}:header`,nodeId:`${s}:header`,kind:"entity-name",rendererRole:"er-table",shape:"rectangle",x:t.x,y:t.y,width:e.width,height:40,label:e.name,fillColor:"#efe6ec",fillStyle:"solid",groupIds:i},r=[{type:"text",id:`label:${s}:header`,containerId:o.id,x:t.x+e.width/2,y:t.y+20,text:e.name,fontSize:16,maxWidth:e.width-28,groupIds:i}];if(e.entity.fields.length>0){let a=t.y+40+6,l=28*e.entity.fields.length,o=(e,t,o,r,n)=>({type:"text",id:`text:${s}:${e}`,x:o+r/2,y:a+l/2,text:t.join("\n"),fontSize:14,lineHeight:2,maxWidth:r,textAlign:"left",...n?{textColor:n}:{},groupIds:i}),n=t.x+14;e.keyWidth>0&&(r.push(o("keys",e.keys,n,e.keyWidth,"#6a4e5c")),n+=e.keyWidth+8),r.push(o("fields",e.names,n,e.nameWidth)),e.typeWidth>0&&r.push(o("types",e.types,n+e.nameWidth+16,e.typeWidth,"#6f6656"))}return{nodes:[l,o],texts:r}})(t.get(a.id),i.get(a.id),e)),o=new Map(a.map(e=>[e.relationship.id,e])),r=[],n=e=>r.some(t=>14>Math.hypot(t.x-e.x,t.y-e.y)),c=s.elements.flatMap(t=>{if("arrow"!==t.type)return[];let a=o.get(t.edgeId);for(let[i,l]of[["start",a.parent],["end",a.child]]){var s;if("zero-or-one"!==(s=l.cardinality)&&"zero-or-many"!==s)continue;let[a,o]="start"===i?[t.points[0],t.points[1]]:[t.points.at(-1),t.points.at(-2)],c=Math.hypot(o.x-a.x,o.y-a.y),d=h4(t,i,l.entity,r.length,e);for(let a=46;n(d)&&a+12<=c;a+=14)d=h4(t,i,l.entity,r.length,e,a);r.push(d)}return[{...t,startArrowhead:hG[a.parent.cardinality],endArrowhead:hG[a.child.cardinality]}]}),d=s.elements.filter(e=>"text"===e.type&&void 0===e.containerId),p=[...l.flatMap(e=>[...e.nodes,...e.texts]),...c,...r,...d],{...s,elements:p,zOrder:p.map(e=>e.id)}},catch:e=>new fv({status:"render_failed",context:{...v,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.id},message:e instanceof Error?e.message:"Unable to render ER scene.",hint:"Repair the entities and relationships and retry."})]}})}).pipe(o.fRP("codeMode.buildErDiagram.render")),x=se(w);if(x.length>0)return yield*new fv({status:"render_failed",context:{...v,issues:f$(x).map(e=>({...e,hint:"Shorten entity or field names, or split the schema, and retry buildErDiagram."}))}});let b={...v,partial:mt(w)},k=yield*mi({scene:w,formats:fU(p.options),inlineFormats:fX(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fv({status:e.status,context:{..."export_failed"===e.status?b:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...me(p.requestId),normalizedSpec:g,quality:m,artifact:k,issues:[]}}),mc=o.fn("codeMode.buildClassDiagram.workflow")(function*(e){var t,a;let s,l,r,n,c=i.q$Z(l3,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:ao(e.spec)}:e);if(!um.oJ(c))return yield*new fy({status:"invalid_input",context:{issues:fF(s9(c.failure))}});let d=yield*uQ,p=c.success,h=yield*o.OH5(()=>d.createId("build")),g=(s=s5((t=p.spec).title),l=(e,t)=>t&&s5(t)?{[e]:s5(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.relationships.flatMap(e=>fE(e.id)??[])),{id:fE(t.id)??(fI(s)||"sketchi-class-diagram"),title:s,classes:t.classes.map(e=>({id:s5(e.id),...l("name",e.name),...e.kind?{kind:e.kind}:{},...l("stereotype",e.stereotype),attributes:e.attributes.map(e=>{let t="string"==typeof e?at(s5(e)):e;return{name:s5(t.name),...l("type",t.type),...t.visibility?{visibility:t.visibility}:{},...r("static",t.static)}}),methods:e.methods.map(e=>{let t="string"==typeof e?aa(s5(e)):e;return{name:s5(t.name),params:t.params.map(e=>{let t="string"==typeof e?t9(s5(e)):e;return{name:s5(t.name),...l("type",t.type)}}),...l("returns",t.returns),...t.visibility?{visibility:t.visibility}:{},...r("static",t.static),...r("abstract",t.abstract)}})})),relationships:t.relationships.map((e,t)=>({id:fE(e.id)??(e=>{let t=e+1;for(;n.has(`relationship-${t}`);)t+=1;return n.add(`relationship-${t}`),`relationship-${t}`})(t),kind:e.kind,from:s5(e.from),to:s5(e.to),...l("fromMultiplicity",e.fromMultiplicity),...l("toMultiplicity",e.toMultiplicity),...l("fromRole",e.fromRole),...l("toRole",e.toRole),...void 0===e.navigable?{}:{navigable:e.navigable},...l("label",e.label)})),style:{...y}}),u={buildId:h,...me(p.requestId),normalizedSpec:g},f=t5(fs(g)).map(e=>fB({code:"missing_relationship_class"===e.code&&e.path.endsWith(".from")?"missing_edge_source":fi[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new fy({status:"invalid_class_diagram",context:{...u,issues:f}});let m={accepted:10>=(a=p.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:g.classes.length,edgeCount:g.relationships.length},checks:[]},v={...u,quality:m};if(!m.accepted)return yield*new fy({status:"quality_failed",context:{...v,issues:fO(m)}});let w=yield*o.SvU({try:()=>(function(e){let t=new Map(e.classes.map(e=>[e.id,function(e){let t,a=tW(e).trim(),s=(t=[tK[tJ(e)],e.stereotype?.trim()].filter(e=>"string"==typeof e&&e.length>0)).length>0?`\xab${t.join(", ")}\xbb`:void 0,i=e.attributes.map(t1),l=e.methods.map(t0),o=Math.max(aq(a,16),s?aq(s,16):0,...[...i,...l].map(e=>aq(e,14))),r=(s?2:1)*22+20,[n,c]=[go(i),go(l)];return{node:e,name:a,heading:s?`${s}
|
|
249
|
-
${a}`:a,width:Math.max(140,Math.ceil(o)+24),height:r+n+c,band:r,attributesHeight:n,methodsHeight:c,attributes:i,methods:l}}(e)])),a=function(e,t){let a,s=e.relationships.map(e=>({id:e.id,from:e.from.trim(),to:e.to.trim(),generalization:tT(e.kind),whole:"composition"===e.kind||"aggregation"===e.kind,fromLabel:Math.max(0,...gr(e,"from").map(gn)),toLabel:Math.max(0,...gr(e,"to").map(gn)),label:e.label?gn(e.label.trim()):0})),i=e.classes.map(e=>{let a=t.get(e.id);return{id:e.id,width:a.width,height:a.height,dividers:[a.band,a.band+a.attributesHeight]}}),l=e.classes.length>20?gd.slice(0,2):gd,o=new Set;for(let r of l){let l=function e(t,a,s={},i=0){let l=function(e,t){let a=new Map(e.map((e,t)=>[e.id,t])),s=[],i=[];for(let e of t){let[t,l]=[a.get(e.from),a.get(e.to)];t!==l&&(e.generalization?s.push({parent:l,child:t}):i.push({a:t,b:l,whole:!0===e.whole}))}return{boxes:e,index:a,links:t,generalizations:s,others:i}}(t,a),o=function(e,t){let a,s=function(e,t=1.6){let a=e.boxes.reduce((e,t)=>e+(t.width+64)*(t.height+130),0),s=Math.max(...e.boxes.map(e=>e.width)),i=Math.sqrt(a/t),l=e.boxes.length;return{width:Math.max(s,1.2*t*i),height:i,column:e.boxes.reduce((e,t)=>e+t.width+64,0)/l,unit:e.boxes.reduce((e,t)=>e+t.height+130,0)/l}}(e,t.aspect),i=t.between??.3,l=t.wholeBelow??0,o=function(e){let t=e.boxes.length,a=Array.from({length:t},()=>[]),s=Array.from({length:t},()=>[]);for(let{parent:t,child:i}of e.generalizations)a[i].push(t),s[t].push(i);let i=Array.from({length:t},()=>0),l=a.map(e=>e.length),o=l.flatMap((e,t)=>0===e?[t]:[]),r=[];for(;o.length>0;){let e=o.shift();for(let t of(r.push(e),s[e]))i[t]=Math.max(i[t],i[e]+1),l[t]-=1,0===l[t]&&o.push(t)}for(let e of r.toReversed())s[e].length>0&&(i[e]=Math.min(...s[e].map(e=>i[e]))-1);let n=new Set(e.generalizations.flatMap(({parent:e,child:t})=>[e,t]));0===n.size&&e.others.length>0&&n.add(e.others[0].a);for(let a=0;a<t&&n.size<t;a+=1)for(let{a:t,b:a}of e.others){if(n.has(t)===n.has(a))continue;let[e,s]=n.has(t)?[t,a]:[a,t];i[s]=i[e],n.add(s)}let c=Math.min(...i);return i.map(e=>e-c)}(e),r=e.boxes.map(()=>new Set);for(let{parent:t,child:a}of e.generalizations)r[t].add(a),r[a].add(t);for(let{a:t,b:a}of e.others)r[t].add(a),r[a].add(t);let n=e.boxes.map((e,t)=>t).sort((e,t)=>r[t].size-r[e].size||e-t),c=h6(e,o,s,i,l);for(let t=0;t<40;t+=1){let t=!1;for(let a of n){let n=o[a],d=new Set([n-1,n+1,n+2]);for(let e of r[a])for(let t of[-1,0,1])d.add(o[e]+t);if(0===r[a].size)for(let e of o)d.add(e);d.delete(n);let p=n;for(let t of[...d].sort((e,t)=>e-t)){o[a]=t;let r=h6(e,o,s,i,l);r<c-1e-9&&([p,c]=[t,r])}o[a]=p,p!==n&&(t=!0)}if(!t)break}return a=new Map([...new Set(o)].sort((e,t)=>e-t).map((e,t)=>[e,t])),o.map(e=>a.get(e))}(l,s),r=function(e,t){let a=[...t],s=e.boxes.map(e=>e.width),i=e.boxes.map(()=>!1),l=[],o=[],r=[];for(let n of e.links){let[c,d]=[e.index.get(n.from),e.index.get(n.to)];if(c===d){r.push([c]);continue}let[p,h]=[t[c],t[d]];if(p===h){o.push({a:c,b:d}),r.push([c,d]);continue}let g=Math.sign(h-p),u=[c];for(let e=p+g;e!==h;e+=g){let t=a.length;a.push(e),s.push(4),i.push(!0),u.push(t)}u.push(d);let f=n.generalization?3:1;for(let[e,t]of u.slice(1).entries()){let s=u[e];l.push(a[s]<a[t]?{upper:s,lower:t,weight:f}:{upper:t,lower:s,weight:f})}r.push(u)}return{row:a,width:s,corridor:i,segments:l,flats:o,chains:r}}(l,o),n=new Map,c=(e,t,a)=>{let s=e<t?`${e}:${t}`:`${t}:${e}`;n.set(s,Math.max(n.get(s)??0,a))};for(let[e,t]of a.entries()){let a=r.chains[e],[s,i]=[a[0],a.at(-1)];s!==i&&r.row[s]===r.row[i]&&c(s,i,Math.max(50,t.fromLabel+16)+(t.label>0?t.label+16:0)+Math.max(50,t.toLabel+16))}let d=function(e,t){let a=Array.from({length:Math.max(...e.row)+1},()=>[]);for(let[t,s]of e.row.entries())a[s].push(t);let s=e.row.map(()=>[]);for(let{upper:t,lower:a}of e.segments)s[t].push({other:a,weight:1}),s[a].push({other:t,weight:1});for(let{a:t,b:a}of e.flats)s[t].push({other:a,weight:.5}),s[a].push({other:t,weight:.5});let i=h9(e,t,a),l={rows:a.map(e=>[...e]),crossings:ge(e,a,i)};for(let o=0;o<8&&l.crossings>0;o+=1){let r=[...a.keys()];for(let l of(o%2==1&&r.reverse(),r)){let o=new Map;for(let e of a[l]){let t=0,a=0;for(let{other:l,weight:o}of s[e])t+=o*i[l],a+=o;o.set(e,a>0?t/a:i[e])}a[l]=[...a[l]].sort((e,t)=>o.get(e)-o.get(t)||i[e]-i[t]),i=h9(e,t,a)}let n=ge(e,a,i);n<l.crossings&&(l={rows:a.map(e=>[...e]),crossings:n})}let o=a=(a=l.rows).map(t=>{let a=t=>e.segments.find(e=>e.lower===t)?.upper,s=new Map;for(let e of t){let t=a(e);void 0!==t&&s.set(t,[...s.get(t)??[],e])}let i=t;for(let t of s.values()){let a=t.filter(t=>e.corridor[t]),s=t.filter(t=>!e.corridor[t]);if(0===a.length||s.length<2)continue;let l=[];for(let[e,t]of s.entries()){l.push(t);let i=Math.round(e*a.length/(s.length-1)),o=Math.round((e+1)*a.length/(s.length-1));e<s.length-1&&l.push(...a.slice(i,o))}let o=i.flatMap((e,a)=>t.includes(e)?[a]:[]),r=[...i];for(let[e,t]of o.entries())r[t]=l[e];i=r}return i});a=l.rows,ge(e,o,h9(e,t,o))<=ge(e,a,h9(e,t,a))&&(a=o);let r=ge(e,a,h9(e,t,a));for(let s=r>0,i=0;s&&i<40;i+=1)for(let i of(s=!1,a))for(let l=0;l+1<i.length;l+=1){[i[l],i[l+1]]=[i[l+1],i[l]];let o=ge(e,a,h9(e,t,a));o<r?(r=o,s=!0):[i[l],i[l+1]]=[i[l+1],i[l]]}return a}(r,n);for(let[e,t]of a.entries()){let a=r.chains[e],[s,i]=[a[0],a.at(-1)];if(s===i||r.row[s]!==r.row[i])continue;let l=d[r.row[s]],[o,n]=[l.indexOf(s),l.indexOf(i)],p=l.slice(Math.min(o,n)+1,Math.max(o,n));if(0===p.length||p.some(e=>!r.corridor[e]))continue;let[h,g]=o<n?[s,i]:[i,s],[u,f]=o<n?[t.fromLabel,t.toLabel]:[t.toLabel,t.fromLabel];c(h,p[0],Math.max(50,u+16)),c(p.at(-1),g,Math.max(50,f+16))}let p=e=>Math.max(40,Math.max(e.fromLabel,e.toLabel)+24);for(let[e,t]of a.entries()){if(t.from!==t.to)continue;let a=r.chains[e][0],s=d[r.row[a]],i=s.filter(e=>!r.corridor[e]),l=i.indexOf(a),o=s.indexOf(a),n=p(t)+t.label+56+64;for(let e of[i[l-1],i[l+1],s[o-1],s[o+1]])void 0!==e&&c(a,e,n)}let h=function(e,t,a){let s=h9(e,t,a),i=e.row.map(()=>[]);for(let{upper:t,lower:a,weight:s}of e.segments)i[t].push({other:a,weight:s}),i[a].push({other:t,weight:s});for(let l=0;l<12;l+=1){let o=[...a.keys()];for(let r of(l%2==1&&o.reverse(),o)){let l=a[r];if(0===l.length)continue;let o=[],n=[];for(let t of l){let a=i[t];if(0===a.length){o.push(s[t]),n.push(.05);continue}let l=a.reduce((e,{weight:t})=>e+t,0);o.push(a.reduce((e,{other:t,weight:a})=>e+a*s[t],0)/l),n.push(e.corridor[t]?4:l)}let c=h8(e,t,l),d=gt(o.map((t,a)=>t-e.width[l[a]]/2-c[a]),n);for(let[t,a]of l.entries())s[a]=d[t]+c[t]+e.width[a]/2}}return s.map((t,a)=>{let s=e.width[a]/2;return Math.round(t-s)+s})}(r,n,d),g=e=>e<t.length?t[e]:{id:"",width:4,height:0},u=Math.ceil(24/s_({width:Math.max(...t.map((e,t)=>h[t]+e.width/2))-Math.min(...t.map((e,t)=>h[t]-e.width/2)),height:d.reduce((e,a)=>e+Math.max(0,...a.filter(e=>e<t.length).map(e=>t[e].height))+100+28,0)}))+4,f={port:Math.max(32,u),track:Math.max(28,u),lane:Math.max(20,u)},m=function(e,t,a,s){let i=new Map;for(let e of a)for(let[t,a]of e.entries())i.set(a,t);let l=[],o=new Map,r=(e,t)=>o.set(`${e}:${t}`,(o.get(`${e}:${t}`)??0)+1),n=[],c=(e,t,a,s,i)=>({link:e,end:t,box:a,side:i,at:0,toward:s,loop:!1,slot:0}),d=(e,a,i,l)=>t.segments.filter(({upper:o,lower:r})=>{let n=l?r:o;return t.row[n]===e&&s[n]>a&&s[n]<i}).length;for(let[o]of e.links.entries()){let e=t.chains[o],[p,h]=[e[0],e.at(-1)];if(p===h){n.push([c(o,"source",p,p,"right"),c(o,"target",h,h,"right")]);continue}if(t.row[p]===t.row[h]){let[e,n]=[i.get(p),i.get(h)],g=t.row[p],u=a[g].slice(Math.min(e,n)+1,Math.max(e,n)).some(e=>!t.corridor[e]),f=e<n?["right","left"]:["left","right"];if(u){let[e,t]=[s[p],s[h]].sort((e,t)=>e-t),[a,i]=[d(g,e,t,!0),d(g,e,t,!1)];f=a<i||a===i&&0===g?["top","top"]:["bottom","bottom"]}l.push(c(o,"source",p,h,f[0]),c(o,"target",h,p,f[1])),r(p,f[0]),r(h,f[1]);continue}let g=t.row[p]<t.row[h];l.push(c(o,"source",p,e[1],g?"bottom":"top"),c(o,"target",h,e.at(-2),g?"top":"bottom"))}let p=new Map,h=a.length-1;for(let e of n){let a=e[0].box,s=e=>l.some(t=>t.box===a&&t.side===e),i=["right","left","top","bottom"].filter(e=>!s(e)&&("right"===e||"left"===e||("top"===e?0===t.row[a]:t.row[a]===h)))[0]??((o.get(`${a}:right`)??0)<=(o.get(`${a}:left`)??0)?"right":"left"),r=p.get(`${a}:${i}`)??0;for(let t of(p.set(`${a}:${i}`,r+1),e))t.side=i,t.loop=!0,t.slot=r;l.push(...e)}return l}(l,r,d,h);if(i<2){let l=t.map((e,t)=>{let a=e=>36+Math.max(0,m.filter(a=>a.box===t&&a.side===e).length-1)*f.port,s=Math.ceil(Math.max(e.width,a("top"),a("bottom"))),i=Math.ceil(Math.max(e.height,a("left"),a("right")));return s===e.width&&i===e.height?e:{...e,width:s,height:i}});if(l.some((e,a)=>e!==t[a]))return e(l,a,s,i+1)}let v=()=>(function(e,t,a,s,i,l){let{port:o,lane:r}=l,n=new Map;for(let t of e){let e=`${t.box}:${t.side}`;n.set(e,[...n.get(e)??[],t])}let c=e=>t[e]-a(e).width/2,d=e=>gs(e.side)?a(e.box).width:a(e.box).height,p=e=>{let{end:t,name:a}=s(e);if(!gs(e.side))return 26*(t>0);let i=Math.max(t,e.loop||0===a?0:Math.ceil(a/2)+14);return i>0?i+14:0},h=(e,t)=>{let[a,s]=[p(e),p(t)];return Math.max(o,a>0&&s>0?a+s:Math.max(a,s))},g=e=>{let t=e.slice(1).map((t,a)=>h(e[a],t)),a=d(e[0])-36,s=t.length*o,i=t.reduce((e,t)=>e+t-o,0),l=s+i<=a?t:s<=a?t.map(e=>o+(e-o)*(a-s)/i):t.map(()=>a/t.length),r=[0];for(let e of l)r.push(r.at(-1)+e);return r},u=(t,s)=>{if(gs(t.side))return!1;let i=ga(e,t);return[...a(t.box).dividers??[],...i.loop?[]:a(i.box).dividers??[]].some(e=>8>Math.abs(e-s))},f=t=>{let s=ga(e,t),i=t.loop?a(t.box).height:Math.min(a(t.box).height,a(s.box).height),l=Math.round(i/2);for(let e=0;e<i/2-18;e+=2)for(let a of[l+e,l-e])if(!u(t,a))return a;return l},m=i=>{let l=ga(e,i);if(gs(i.side)&&i.loop){let e=Math.min(2*Math.max(s(i).end,s(l).end)+72+2*i.slot*o,a(i.box).width-36);return a(i.box).width/2+("source"===i.end?-1:1)*e/2}if(gs(i.side))return(l.box!==i.toward||i.loop?t[i.toward]:c(l.box)+l.at)-c(i.box);if(i.loop){let e=Math.min(64+2*i.slot*o,a(i.box).height-36);return f(i)+("source"===i.end?-1:1)*e/2}return l.at};for(let t of e)t.at=gs(t.side)?a(t.box).width/2:f(t);for(let e=0;e<8;e+=1){let e=!1;for(let t of n.values()){let a=d(t[0]),s=t.map(m),i=t.map((e,t)=>t).sort((e,a)=>s[e]-s[a]||t[e].link-t[a].link||("source"===t[e].end?-1:1)),l=g(i.map(e=>t[e])),o=gt(i.map((e,t)=>s[e]-l[t]),i.map(()=>1)),r=l.at(-1)??0;i.forEach((s,i)=>{let n=Math.round(Math.min(Math.max(o[i],18),a-18-r)+l[i]);n!==t[s].at&&(e=!0),t[s].at=n})}if(!e)break}let v=(e,t)=>{let a=n.get(`${e.box}:${e.side}`);return!(t<18||t>d(e)-18||u(e,t))&&a.every(a=>a===e||Math.sign(a.at-e.at)===Math.sign(a.at-t)&&Math.abs(a.at-t)>=Math.min(h(a,e),Math.abs(a.at-e.at))-.5)};for(let t of e){if("source"!==t.end||t.loop||!gs(t.side))continue;let a=ga(e,t);if(a.box!==t.toward||!gs(a.side)||a.side===t.side)continue;let[s,i]=[c(t.box)+t.at,c(a.box)+a.at];!(.5>Math.abs(s-i)||Math.abs(s-i)>72)&&(v(a,Math.round(s-c(a.box)))?a.at=Math.round(s-c(a.box)):v(t,Math.round(i-c(t.box)))&&(t.at=Math.round(i-c(t.box))))}let y=e=>c(e.box)+e.at,w=t=>e.filter(e=>e.link!==t.link&&!e.loop&&e.side===("top"===t.side?"bottom":"top")&&i(e.box)===i(t.box)+("top"===t.side?-1:1)),x=(e,t)=>w(e).every(a=>Math.abs(y(a)-(c(e.box)+t))>=r),b=e=>{for(let t=4;t<=3*o;t+=4){let a=[e.at+t,e.at-t].find(t=>v(e,t)&&x(e,t));if(void 0!==a)return e.at=a,!0}let t=n.get(`${e.box}:${e.side}`),a=d(e);for(let s=4;s<=3*o;s+=4)for(let i of[s,-s])if(t.every(e=>e.at+i>=18&&e.at+i<=a-18&&(x(e,e.at+i)||!x(e,e.at)))&&x(e,e.at+i)){for(let e of t)e.at+=i;return!0}return!1};for(let t of e){if(t.loop||"top"!==t.side)continue;let e=w(t).filter(e=>Math.abs(y(e)-y(t))<r);if(e.length>0&&!b(t))for(let t of e)b(t)}for(let t of e){if(gs(t.side)||!u(t,t.at))continue;let a=ga(e,t),s=!t.loop&&a.at===t.at;for(let e=2;e<=16;e+=2){let i=[t.at+e,t.at-e].find(e=>v(t,e)&&(!s||v(a,e)));if(void 0!==i){t.at=i,s&&(a.at=i);break}}}})(m,h,g,e=>{let t=a[e.link];return{end:"source"===e.end?t.fromLabel:t.toLabel,name:t.label}},e=>r.row[e],f);v();let y=e=>h[e]-g(e).width/2,w=e=>y(e.box)+e.at,x=a.map((e,t)=>["source","target"].map(e=>m.find(a=>a.link===t&&a.end===e)));!function(e,t,a,s,i,l,o){let r=new Map;for(let e of a)for(let[t,a]of e.entries())r.set(a,t);let n=(i,l)=>{let o=a[e.row[i]],n=r.get(i),[c,d]=[o[n-1],o[n+1]],p=e.width[i]/2;return(void 0===c||l-p>=s[c]+e.width[c]/2+h7(e,t,c,i))&&(void 0===d||l+p<=s[d]-e.width[d]/2-h7(e,t,i,d))};for(let[t,a]of e.chains.entries()){let e=a.slice(1,-1);if(0===e.length)continue;let l=i(t).find(t=>e.every(e=>n(e,t)));if(void 0!==l)for(let t of e)s[t]=l}for(let[t,a]of e.chains.entries())for(let i of a.slice(1,-1)){let a=e.row[i],r=e=>l.some(s=>s.link!==t&&(s.row===a-1||s.row===a+1)&&Math.abs(s.x-e)<o.lane);if(r(s[i]))for(let e=4;e<=3*o.port;e+=4){let t=[s[i]+e,s[i]-e].find(e=>n(i,e)&&!r(e));if(void 0!==t){s[i]=t;break}}}}(r,n,d,h,e=>{let[t,a]=x[e];return r.row[t.box]<r.row[a.box]?[w(t),w(a)]:[w(a),w(t)]},m.flatMap(e=>gs(e.side)&&!e.loop?[{link:e.link,row:r.row[e.box],x:w(e)}]:[]),f),r.corridor.some(Boolean)&&v();let b=d.length,k=d.map(e=>Math.max(0,...e.filter(e=>e<t.length).map(e=>t[e].height))),M=new Map,C=(e,t)=>M.set(e,[...M.get(e)??[],t]);for(let[e]of a.entries()){let[t,a]=x[e],s=r.chains[e];if(t.loop||"left"===t.side||"right"===t.side)continue;if(t.side===a.side){let[e,i]=[w(t),w(a)],l=r.row[s[0]],o="top"===t.side;C(o?l-1:l,{ends:[t,a],upper:o?[]:[e,i],lower:o?[e,i]:[],min:Math.min(e,i),max:Math.max(e,i),track:0});continue}let i=r.row[s[0]]<r.row[s.at(-1)]?s:s.toReversed(),[l,o]=i[0]===s[0]?[t,a]:[a,t];for(let[e,t]of i.slice(1).entries()){let a=i[e],s=a===i[0]?w(l):h[a],n=t===i.at(-1)?w(o):h[t];.5>Math.abs(s-n)||C(r.row[a],{ends:[...a===i[0]?[l]:[],...t===i.at(-1)?[o]:[]],upper:[s],lower:[n],min:Math.min(s,n),max:Math.max(s,n),track:0})}}let z=new Map([...M].map(([e,t])=>[e,function(e,t){let a=[...e],s=[];for(;a.length>0;){let e=0,t=1/0;for(let[s,i]of a.entries()){let l=a.reduce((e,t)=>t===i?e:e+gi(i,t),0);l<t&&([e,t]=[s,l])}s.push(a.splice(e,1)[0])}let i=(e,a)=>e.min<a.max+t&&a.min<e.max+t,l=0;for(let[e,t]of s.entries())t.track=Math.max(0,...s.slice(0,e).filter(e=>i(e,t)||gi(t,e)>=1e3).map(e=>e.track+1)),l=Math.max(l,t.track+1);return l}(t,f.track)])),_=new Set;for(let[e,t]of a.entries()){let[a,s]=x[e];if(0===t.label||a.loop||"left"===a.side||"right"===a.side)continue;let[i,l]=[r.row[a.box],r.row[s.box]];if(a.side===s.side)_.add("top"===a.side?i-1:i);else for(let e=Math.min(i,l);e<Math.max(i,l);e+=1)_.add(e)}let L=e=>54*!!_.has(e),B=e=>100+L(e)+Math.max(0,(z.get(e)??0)-1)*f.track,S=[],A=z.has(-1)?B(-1):0;for(let e=0;e<b;e+=1)S.push(A),A+=k[e]+B(e);let P=(e,t)=>(e<0?0:S[e]+k[e])+50+L(e)+t*f.track,V=Math.min(...t.map((e,t)=>y(t))),H=new Map(t.map((e,t)=>[e.id,{x:Math.round(y(t)-V),y:S[r.row[t]],width:e.width,height:e.height}])),q=new Map;for(let[e,a]of M)for(let s of a)for(let a of s.ends){let i=H.get(t[a.box].id),l="bottom"===a.side?i.y+i.height:i.y;q.set(a,Math.abs(P(e,s.track)-l))}for(let e of m){if(!e.loop)continue;let t=m.filter(t=>t.loop&&t.box===e.box&&t.side===e.side&&t.slot<e.slot).reduce((e,t)=>Math.max(e,p(a[t.link])),0);q.set(e,Math.max(p(a[e.link]),t+f.track))}return{boxes:H,anchors:new Map(m.map(e=>{let s=t[e.box],i=gs(e.side)?s.width:s.height,l=q.get(e);return[`${a[e.link].id}:${e.end}`,{side:e.side,offset:e.at-i/2,...void 0===l?{}:{run:l}}]})),rows:new Map(t.map((e,t)=>[e.id,r.row[t]]))}}(i,s,r),n=JSON.stringify([...l.boxes,...l.anchors]);if(o.has(n))continue;o.add(n);let c=function(e,t,a){let s=function(e,t){let a=new Map;for(let s of e.relationships)for(let e of["from","to"]){let i=t.anchors.get(`${s.id}:${"from"===e?"source":"target"}`),l=t.boxes.get(s[e].trim()),o=gr(s,e);if(!i||!l||0===o.length||"left"!==i.side&&"right"!==i.side)continue;let r=Math.max(...o.map(gn))+8,n=l.y+l.height/2+i.offset,c="right"===i.side?l.x+l.width+2:l.x-2-r;for(let[t,i]of[["above",n-10+4-18],["below",n+10-4]])a.set(`${gc}${s.id}:${e}:${t}`,{x:c,y:i,width:r,height:18})}return a}(e,a);return hS({id:e.id,title:e.title,type:"flowchart",nodes:[...e.classes.map(e=>({id:e.id,label:t.get(e.id).name,kind:"class",metadata:{}})),...[...s.keys()].map(e=>({id:e,label:"·",kind:"class",metadata:{}}))],edges:e.relationships.map(e=>({id:e.id,source:e.from.trim(),target:e.to.trim(),metadata:{}})).map((e,t)=>({edge:e,index:t,span:Math.abs((a.rows.get(e.source)??0)-(a.rows.get(e.target)??0))})).sort((e,t)=>Math.min(e.span,2)-Math.min(t.span,2)||e.index-t.index).map(({edge:e})=>e),layout:{direction:"TB",edgeRouting:"orthogonal"},style:e.style,metadata:{}},{placement:new Map([...a.boxes,...s]),anchors:a.anchors,endRun:50})}(e,t,l),d=function(e){let t=e.elements.filter(e=>"arrow"===e.type),a=Math.max(e.width/e.height,e.height/e.width);return hy(t)+sq(t.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),s_({width:e.width,height:e.height})).length+(a>2.5?4*(a-2.5):0)+t.reduce((e,t)=>e+function(e){let[t,a]=[e.points[0],e.points.at(-1)],s=0;for(let[t,a]of e.points.slice(1).entries())s+=Math.abs(a.x-e.points[t].x)+Math.abs(a.y-e.points[t].y);return Math.max(0,s/(Math.abs(a.x-t.x)+Math.abs(a.y-t.y)+100+200)-1)}(t),0)+3*function(e){let t=e.flatMap(e=>sp(e.points).map(t=>({arrow:e.id,segment:t}))),a=0;for(let[e,s]of t.entries())for(let i of t.slice(e+1))i.arrow!==s.arrow&&i.segment.orientation===s.segment.orientation&&10>Math.abs(i.segment.staticCoordinate-s.segment.staticCoordinate)&&Math.min(i.segment.max,s.segment.max)>Math.max(i.segment.min,s.segment.min)&&(a+=1);return a}(t)}(c);if((!a||d<a.cost-.75)&&(a={cost:d,scene:c}),0===d)break}return a.scene}(e,t),s=new Map(a.elements.flatMap(e=>"node"!==e.type||e.nodeId.startsWith(gc)?[]:[[e.nodeId,e]])),i=e.classes.map(a=>(function(e,t,a){let{id:s}=e.node,i=[`class:${s}`],[l,o]=[t.width,t.height],r=(a,o,r,n,c)=>({type:"node",id:`node:${s}${a}`,nodeId:`${s}${a}`,kind:o,rendererRole:"class-box",shape:"rectangle",x:t.x,y:r,width:l,height:n,label:e.name,...c?{fillColor:c,fillStyle:"solid"}:{},groupIds:i}),n=r("","class",t.y,o,a.style.backgroundColor),c=r(":name","class-name",t.y,e.band,"#efe6ec"),d=t.y+e.band+e.attributesHeight,p=r(":methods","class-methods",d,t.y+o-d),h=[{type:"text",id:`label:${s}:name`,containerId:c.id,x:t.x+l/2,y:t.y+e.band/2,text:e.heading,fontSize:16,lineHeight:1.375,maxWidth:l-24,...e.heading!==e.name?{textColor:"#6a4e5c"}:{},groupIds:i}],g=(e,a,l)=>{if(0===a.length)return;let o=22*a.length,r=Math.ceil(Math.max(...a.map(e=>aq(e,14))));h.push({type:"text",id:`text:${s}:${e}`,x:t.x+12+r/2,y:l+6+o/2,text:a.join("\n"),fontSize:14,lineHeight:22/14,maxWidth:r,textAlign:"left",groupIds:i})};return g("attributes",e.attributes,t.y+e.band),g("methods",e.methods,d),{nodes:[n,c,p],texts:h}})(t.get(a.id),s.get(a.id),e)),l=new Map(e.relationships.map(e=>[e.id,e])),o=a.elements.flatMap(e=>{var t;let a;if("arrow"!==e.type)return[];let s=(a=gl[(t=l.get(e.edgeId)).kind],t.navigable&&tY(t.kind)?{...a,to:"arrow"}:a);return[{...e,startArrowhead:s.from,endArrowhead:s.to,..."dashed"===s.stroke?{strokeStyle:"dashed"}:{}}]}),r=function(e,t,a){let s=a.map(e=>({left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})),i=t.flatMap(e=>sp(e.points)),l=[],o=e=>s.filter(t=>gp(e,t,3)).length+i.filter(t=>"horizontal"===t.orientation?t.staticCoordinate>e.top-3&&t.staticCoordinate<e.bottom+3&&t.max>e.left-3&&t.min<e.right+3:t.staticCoordinate>e.left-3&&t.staticCoordinate<e.right+3&&t.max>e.top-3&&t.min<e.bottom+3).length+l.filter(t=>gp(e,t,3)).length,r=e=>0===o(e),n=[],c=(e,t,a,s)=>{l.push(a),n.push({type:"text",id:e,x:(a.left+a.right)/2,y:(a.top+a.bottom)/2,text:t,fontSize:13,maxWidth:a.right-a.left,...s?{groupIds:[s]}:{}})},d=new Map(t.map(e=>[e.edgeId,e])),p=(e,t,a,s,i)=>e.slice(0,-1).flatMap((l,o)=>[...function*(e,t,a,s,i,l){let o=Math.hypot(t.x-e.x,t.y-e.y);if(o<1)return;let[r,n]=[(t.x-e.x)/o,(t.y-e.y)/o],c=Math.abs(r)>.5?a:s;for(let t=l;t+c<=Math.max(o,l+c);t+=6){for(let l of i)if(Math.abs(r)>.5){let i=r>0?e.x+t:e.x-t-a,o=l<0?e.y-10+4-s:e.y+10-4;yield{left:i,top:o,right:i+a,bottom:o+s}}else{let i=n>0?e.y+t:e.y-t-s,o=l>0?e.x+10:e.x-10-a;yield{left:o,top:i,right:o+a,bottom:i+s}}if(t+c>=o)break}}(l,e[o+1],t,a,s,0===o?i:6)]),h=(...e)=>p(...e).find(r);for(let t of e.relationships){let e=d.get(t.id);if(e)for(let a of["from","to"]){let s=gr(t,a);if(0===s.length)continue;let i="from"===a?e.points:e.points.toReversed(),o="from"===a?e.sourceNodeId:e.targetNodeId,r=[t["from"===a?"fromMultiplicity":"toMultiplicity"]&&"multiplicity",t["from"===a?"fromRole":"toRole"]&&"role"].filter(e=>"string"==typeof e),n=2===s.length?[[1,-1],[-1,1]]:[[1],[-1]],d=e=>{let t=[];for(let[a,o]of s.entries()){let s=h(i,gn(o),18,e(a),4);if(!s)break;t.push(s),l.push(s)}return l.splice(l.length-t.length,t.length),t.length===s.length?t:void 0};for(let[e,l]of(n.map(e=>d(t=>[e[t]])).find(Boolean)??d(()=>[1,-1])??s.map(e=>p(i,gn(e),18,[1,-1],4)[0])).entries())c(`relationship:${t.id}:${a}:${r[e]}`,s[e],l,`class:${o}`)}}for(let t of e.relationships){let e=d.get(t.id);if(!e||!t.label)continue;let a=e.points.slice(0,-1).map((t,a)=>[t,e.points[a+1]]).reduce((e,t)=>Math.hypot(t[1].x-t[0].x,t[1].y-t[0].y)>Math.hypot(e[1].x-e[0].x,e[1].y-e[0].y)?t:e),s={x:(a[0].x+a[1].x)/2,y:(a[0].y+a[1].y)/2},i=[1,2,3,4,5].map(e=>(function(e,t){let a=e.split(/\s+/u);if(t<=1||a.length<t)return e;let s=(e,t)=>aq(a.slice(e,t).join(" "),13),i=new Map,l=(e,t)=>{if(1===t)return{widest:s(e,a.length),breaks:[]};let o=`${e}:${t}`,r=i.get(o);if(r)return r;let n={widest:1/0,breaks:[]};for(let i=e+1;i<=a.length-t+1;i+=1){let a=l(i,t-1),o=Math.max(s(e,i),a.widest);o<n.widest&&(n={widest:o,breaks:[i,...a.breaks]})}return i.set(o,n),n},o=[0,...l(0,t).breaks,a.length];return o.slice(1).map((e,t)=>a.slice(o[t],e).join(" ")).join("\n")})(t.label.trim(),e)),l=t=>{let[i,l]=[gn(t),18*t.split("\n").length];return[...p([s,a[1]],i,l,[-1,1],0),...p(e.points,i,l,[-1,1],50),...p(e.points,i,l,[-1,1],0)]},n=i.map(e=>({text:e,rect:l(e).find(r)})).find(e=>void 0!==e.rect);if(n){c(`relationship:${t.id}:name`,n.text,n.rect);continue}let h=i.flatMap(e=>l(e).map(t=>({text:e,rect:t,hits:o(t)}))).reduce((e,t)=>t.hits<e.hits?t:e);c(`relationship:${t.id}:name`,h.text,h.rect)}return n}(e,o,[...s.values()]),{elements:n,width:c,height:d}=function(e){let t=e.flatMap(e=>{if("arrow"===e.type||"line"===e.type)return[...e.points];if("text"===e.type){if(e.containerId)return[];let t=(e.maxWidth??0)/2,a=e.text.split("\n").length*e.fontSize*(e.lineHeight??1.35)/2;return[{x:e.x-t,y:e.y-a},{x:e.x+t,y:e.y+a}]}return"frame"===e.type||"node"===e.type?[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]:[]}),[a,s]=[Math.min(...t.map(e=>e.x)),Math.min(...t.map(e=>e.y))],[i,l]=[Math.max(0,48-a),Math.max(0,48-s)].map(Math.ceil);return{elements:e.map(e=>0===i&&0===l?e:"arrow"===e.type?{...e,points:e.points.map(e=>({x:e.x+i,y:e.y+l}))}:"line"===e.type?e:{...e,x:e.x+i,y:e.y+l}),width:Math.max(...t.map(e=>e.x))+i+48,height:Math.max(...t.map(e=>e.y))+l+48}}([...i.flatMap(e=>[...e.nodes,...e.texts]),...o,...r]);return{...a,width:c,height:d,elements:n,zOrder:n.map(e=>e.id)}})(fs(g)),catch:e=>new fy({status:"render_failed",context:{...v,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.id},message:e instanceof Error?e.message:"Unable to render class diagram scene.",hint:"Repair the classes and relationships and retry."})]}})}).pipe(o.fRP("codeMode.buildClassDiagram.render")),x=se(w);if(x.length>0)return yield*new fy({status:"render_failed",context:{...v,issues:f$(x).map(e=>({...e,hint:"Shorten class or member names, or split the model, and retry buildClassDiagram."}))}});let b={...v,partial:mt(w)},k=yield*mi({scene:w,formats:fU(p.options),inlineFormats:fX(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fy({status:e.status,context:{..."export_failed"===e.status?b:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...me(p.requestId),normalizedSpec:g,quality:m,artifact:k,issues:[]}}),md=o.fn("codeMode.buildOrgChart.workflow")(function*(e){var t,a;let s,l,r,n,c=i.q$Z(l4,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:aC(e.spec)}:e);if(!um.oJ(c))return yield*new fw({status:"invalid_input",context:{issues:fF(s9(c.failure))}});let d=yield*uQ,p=c.success,h=yield*o.OH5(()=>d.createId("build")),g=(s=s5((t=p.spec).title),l=(e,t)=>t&&s5(t)?{[e]:s5(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.dottedLines.flatMap(e=>fE(e.id)??[])),{id:fE(t.id)??(fI(s)||"sketchi-org-chart"),title:s,people:t.people.map(e=>({id:s5(e.id),name:s5(e.name),...l("title",e.title),...l("department",e.department),...l("manager",e.manager),...r("assistant",e.assistant),...r("avatar",e.avatar)})),dottedLines:t.dottedLines.map((e,t)=>({id:fE(e.id)??(e=>{let t=e+1;for(;n.has(`dotted-line-${t}`);)t+=1;return n.add(`dotted-line-${t}`),`dotted-line-${t}`})(t),report:s5(e.report),manager:s5(e.manager),...l("label",e.label)})),...r("groupByDepartment",t.groupByDepartment),...r("forest",t.forest),style:{...y}}),u={buildId:h,...me(p.requestId),normalizedSpec:g},f=au(fl(g)).map(e=>fB({code:fo[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new fw({status:"invalid_org_chart",context:{...u,issues:f}});let m={accepted:10>=(a=p.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:g.people.length,edgeCount:g.people.filter(e=>void 0!==e.manager).length+g.dottedLines.length},checks:[]},w={...u,quality:m};if(!m.accepted)return yield*new fw({status:"quality_failed",context:{...w,issues:fO(m)}});let x=yield*o.SvU({try:()=>{let e,t,a,s,i,l,o,r,n,c,d,p,h,u,f,m,y,w,x,b,k,M,C;return t=function(e){let t=new Map;if(!0!==e.groupByDepartment)return t;let a=ag(e),s=new Map(e.people.map(e=>[e.id,e])),i=(e,l)=>{let o=void 0===e.manager?void 0:s.get(e.manager),r=!l&&void 0!==o&&void 0!==e.department&&e.department!==o.department&&(a.get(e.id)?.length??0)>0;for(let s of(r&&t.set(e.id,e.department),a.get(e.id)??[]))i(s,l||r)};for(let t of ah(e))i(t,!1);return t}(e=am(fl(g))),a=function(e,t){let a=ag(e),s=[...new Set(e.people.flatMap(e=>e.department??[]))],i=new Map(e.people.map(e=>[e.id,e])),l=ah(e).flatMap(e=>(a.get(e.id)??[]).filter(e=>!0!==e.assistant)),o=e=>nW[e%nW.length],r=t=>{if(s.length>0)return void 0===t.department?e.style.accentColor:o(s.indexOf(t.department));let a=(t=>{let a=t;for(let t=0;t<=e.people.length;t+=1){let e=void 0===a.manager?void 0:i.get(a.manager);if(!e)break;if(void 0===e.manager)return a;a=e}})(t),r=void 0===a?-1:l.indexOf(a);return r<0?e.style.accentColor:o(r)},n=new Map,c=new Map,d=(e,s,i)=>{let l=t.get(e.id)??i;for(let t of(c.set(e.id,s),void 0!==l&&n.set(e.id,l),a.get(e.id)??[]))d(t,s+1,l)};for(let t of ah(e))d(t,0,void 0);let p=new Map;for(let t of e.people){let e=void 0===t.manager?void 0:i.get(t.manager),a=void 0!==t.department&&e?.department!==t.department&&n.get(t.id)!==t.department?t.department:void 0,s=[t.title,a].filter(e=>void 0!==e).map(e=>gU(e.trim(),208,13));p.set(t.id,{person:t,depth:c.get(t.id)??0,name:gU(t.name.trim(),208,16),details:s.length>0?s.join("\n"):void 0,color:r(t),avatar:!0===t.avatar,width:0,height:0})}let h=new Map;for(let e of p.values()){let t=h.get(e.depth)??[];t.push(e),h.set(e.depth,t)}for(let e of h.values()){let t=Math.ceil(Math.min(232,Math.max(148,Math.max(...e.map(e=>Math.max(aq(e.name,16),e.details?aq(e.details,13):0,44*!!e.avatar)+24)))));for(let a of e)a.width=t}let g=e=>9+49*!!e.avatar+gT(e.name,16)+(e.details?3+gT(e.details,13):0)+5+4*!e.details,u=e=>e.details?Math.ceil(13*gX(e.details)*1.35)+18:Math.ceil(16*gX(e.name)*1.35)+18+49*!!e.avatar,f=new Map;for(let e of p.values()){let t=`${e.person.manager??`top:${e.person.id}`}:${!0===e.person.assistant}`;f.set(t,[...f.get(t)??[],e])}for(let e of f.values()){let t=Math.ceil(Math.max(40,...e.map(e=>Math.max(g(e),u(e)))));for(let a of e)a.height=t}return p}(e,t),l=function(e){let t={stackMin:5,twoColumns:5,outline:new Map,rows:new Map},a=gV(e,t),s=1;if(gq(a)>1){let i={...t,stackMin:2},l=gV(e,i);s+=1,gq(l)<gq(a)-1e-9&&([t,a]=[i,l])}let i=new Map,l=[],o=(e,t)=>{for(let a of(i.set(e.id,t),t>=1&&gz(e)&&l.push(e.id),e.reports))o(a,t+1)};for(let t of e)o(t,0);let r=t=>{let i;for(let{policy:a,preference:l}of t){let t=gV(e,a);s+=1;let o={policy:a,block:t,excess:gq(t),preference:l};(!i||(o.excess<=1&&i.excess<=1?o.preference<i.preference-1e-9:o.excess<i.excess-1e-9))&&(i=o)}return i&&i.excess<gq(a)-1e-6?i:void 0};for(let s=0;s<30&&gq(a)>1;s+=1){let s=a.rows,o=t.twoColumns<=8?r([{policy:{...t,twoColumns:9},preference:0}]):void 0;if(o){[t,a]=[o.policy,o.block];continue}let n=(e,t)=>(s.get(t)?.width??0)-(s.get(e)?.width??0)||e.localeCompare(t),c=r([...l.filter(e=>!t.outline.has(e)&&s.has(e)).toSorted(n).slice(0,3).map(e=>({policy:{...t,outline:new Map(t.outline).set(e,2)},preference:-i.get(e)})),...[...t.outline].filter(([,e])=>2===e).map(([e])=>e).slice(0,3).map(e=>({policy:{...t,outline:new Map(t.outline).set(e,1)},preference:1-i.get(e)}))]);if(c){[t,a]=[c.policy,c.block];continue}let d=([,e])=>e.items>e.rows,p=[...s].filter(e=>d(e)&&e[1].widestItem<.6*e[1].width).toSorted(([e,t],[a,s])=>s.width-s.widestItem-(t.width-t.widestItem)||e.localeCompare(a)).slice(0,3),h=[];for(let t of e){let e=t.id;for(;void 0!==e&&s.has(e);)h.push([e,s.get(e)]),e=s.get(e).widest}let g=[...p,...h.filter(d).filter(([e])=>!p.some(([t])=>t===e)).slice(0,3)],u=e=>r(e.map(([e,a])=>({policy:{...t,rows:new Map(t.rows).set(e,a.rows+1)},preference:a.widestItem}))),f=u(g.filter(([e])=>i.get(e)>=1))??u(g.filter(([e])=>0===i.get(e)));if(!f)break;[t,a]=[f.policy,f.block]}for(let i of[...t.rows.keys()].toReversed())for(let l=t.rows.get(i)-1;l>=1;l-=1){let o={...t,rows:new Map(t.rows).set(i,l)},r=gV(e,o);if(s+=1,gq(r)>Math.max(1,gq(a))+1e-9)break;t=o,a=r}let n=gk(gH(a));return{cards:a.cards,links:a.links,regions:a.regions,width:n.x1-n.x0,height:n.y1-n.y0,attempts:s,stackMin:t.stackMin,wraps:new Map([...t.rows].filter(([,e])=>e>1)),outlines:t.outline}}((s=ag(e),i=e=>{let l=a.get(e.id),o=t.get(e.id),r=s.get(e.id)??[];return{id:e.id,width:l.width,height:l.height,reports:r.filter(e=>!0!==e.assistant).map(i),assistants:r.filter(e=>!0===e.assistant).map(i),...void 0===o?{}:{region:{label:o,nameWidth:sY(o)}}}},ah(e).map(i))),o=e.style.backgroundColor,r=e=>({...e,x:e.x+40,y:e.y+40}),n=new Map([...l.cards].map(([e,t])=>[e,r(t)])),c=l.regions.map(e=>({type:"frame",id:`frame:${e.root}`,name:e.label,...r(e.frame)})),d=new Map(l.regions.flatMap(e=>e.members.map(t=>[t,`frame:${e.root}`]))),p=e.people.map(e=>(function(e,t,a,s){let i,l,o,{person:r}=e,n={groupIds:[`person:${r.id}`],...s?{frameId:s}:{}},c={type:"node",id:`node:${r.id}`,nodeId:r.id,kind:r.assistant?"assistant":"person",shape:"rectangle",...t,label:r.name,strokeColor:e.color,strokeWidth:2,fillColor:gO(e.color,a,.13),fillStyle:"solid",...n},d=[c],p=[],h=t.x+t.width/2,g=t.width-24;if(e.avatar&&d.push({type:"node",id:`node:${r.id}:avatar`,nodeId:`${r.id}:avatar`,kind:"avatar",shape:"ellipse",x:h-22,y:t.y+9,width:44,height:44,label:(l=(i=r.name.trim().split(/\s+/u).filter(e=>/[\p{L}\p{N}]/u.test(e))).length>2&&/^(dr|mr|mrs|ms|mx|prof|sir|dame)\.?$/iu.test(i[0])?i.slice(1):i,o=e=>{let t=[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(e??"")].map(e=>e.segment).find(e=>/[\p{L}\p{N}]/u.test(e));return t?.toLocaleUpperCase()??""},0===l.length?"?":1===l.length?o(l[0])||"?":`${o(l[0])}${o(l.at(-1))}`),strokeColor:e.color,strokeWidth:1,fillColor:gO(e.color,a,.32),fillStyle:"solid",...n}),e.details){let a=gT(e.details,13),s=t.y+t.height-5-a;p.push({type:"text",id:`label:${r.id}`,containerId:c.id,x:h,y:s+a/2,text:e.details,fontSize:13,lineHeight:1.25,maxWidth:g,verticalAlign:"bottom",textColor:"#5f574c",...n});let i=gT(e.name,16);p.push({type:"text",id:`text:${r.id}:name`,x:h,y:s-3-i/2,text:e.name,fontSize:16,lineHeight:1.25,maxWidth:Math.ceil(aq(e.name,16)),textColor:v.ink,...n})}else{let a=gT(e.name,16),s=e.avatar;p.push({type:"text",id:`label:${r.id}`,containerId:c.id,x:h,y:s?t.y+t.height-5-a/2:t.y+t.height/2,text:e.name,fontSize:16,lineHeight:1.25,maxWidth:g,...s?{verticalAlign:"bottom"}:{},textColor:v.ink,...n})}return{nodes:d,texts:p}})(a.get(e.id),n.get(e.id),o,d.get(e.id))),h=l.links.map(e=>{let t=e.points.map(e=>({x:e.x+40,y:e.y+40})),a=void 0!==d.get(e.manager)&&d.get(e.manager)===d.get(e.report)?d.get(e.report):void 0;return{type:"arrow",id:`edge:${e.report}`,edgeId:e.report,sourceNodeId:e.manager,targetNodeId:e.report,points:t,startArrowhead:null,endArrowhead:null,strokeColor:"#857b6f",strokeWidth:2,roughness:0,...a?{frameId:a}:{}}}),f=0===(u=gj(e,n,c,d,h,!0)).straight?u:[gj(e,n,c,d,h,!1)].find(e=>e.straight<u.straight)??u,y=(m=[...c,...h,...f.arrows,...p.flatMap(e=>e.nodes),...p.flatMap(e=>e.texts),...f.labels]).flatMap(e=>{if("arrow"===e.type)return[...e.points];if("text"===e.type){if(e.containerId)return[];let t=(e.maxWidth??0)/2,a=gX(e.text)*e.fontSize*1.25/2;return[{x:e.x-t,y:e.y-a},{x:e.x+t,y:e.y+a}]}return"node"===e.type||"frame"===e.type?[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]:[]}),w=c.map(e=>s$(e).y),x=Math.min(...y.map(e=>e.x)),b=Math.min(...y.map(e=>e.y),...w),k=Math.max(0,Math.ceil(40-x)),M=Math.max(0,Math.ceil(40-b)),C=0===k&&0===M?m:m.map(e=>"arrow"===e.type?{...e,points:e.points.map(e=>({x:e.x+k,y:e.y+M}))}:"line"===e.type?e:{...e,x:e.x+k,y:e.y+M}),{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:Math.ceil(Math.max(...y.map(e=>e.x))+k+40),height:Math.ceil(Math.max(...y.map(e=>e.y))+M+40),accentColor:e.style.accentColor,backgroundColor:o,elements:C,layers:[],layouts:[],zOrder:C.map(e=>e.id)}},catch:e=>new fw({status:"render_failed",context:{...w,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.id},message:e instanceof Error?e.message:"Unable to render org chart scene.",hint:"Repair the people and reporting lines and retry."})]}})}).pipe(o.fRP("codeMode.buildOrgChart.render")),b=se(x);if(b.length>0)return yield*new fw({status:"render_failed",context:{...w,issues:f$(b).map(e=>({...e,hint:"Shorten names or titles, or split the chart by division, and retry buildOrgChart."}))}});let k={...w,partial:mt(x)},M=yield*mi({scene:x,formats:fU(p.options),inlineFormats:fX(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fw({status:e.status,context:{..."export_failed"===e.status?k:w,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...me(p.requestId),normalizedSpec:g,quality:m,artifact:M,issues:[]}}),mp=o.fn("codeMode.buildTimeline.workflow")(function*(e){var t,a;let s,l,r=i.q$Z(lN,{errors:"all",reportInput:!0})(e);if(!um.oJ(r))return yield*new fx({status:"invalid_input",context:{issues:fF(s9(r.failure))}});let n=yield*uQ,c=r.success,d=yield*o.OH5(()=>n.createId("build")),p=(s=s5((t=c.spec).title),{id:(l={id:fE(t.id)??(fI(s)||"sketchi-timeline"),title:s,type:"timeline",style:{...y},events:t.events.map(e=>({...e}))}).id,title:s,events:ep(l),...t.lanes?{lanes:[...t.lanes]}:{},...t.today?{today:t.today}:{},style:l.style}),h={buildId:d,...me(c.requestId),normalizedSpec:p},g=er(u2(p)).map(e=>fB({code:e.code,stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(g.length>0)return yield*new fx({status:"invalid_timeline",context:{...h,issues:g}});let u={accepted:10>=(a=c.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:p.events.length,edgeCount:0},checks:[]},f={...h,quality:u};if(!u.accepted)return yield*new fx({status:"quality_failed",context:{...f,issues:fO(u)}});let m=yield*o.SvU({try:()=>(function(e){let t,a,s=ec(e),i=ep(s),l=cO(s),o=eo(s),r=(o.length?o:[""]).map((e,t)=>{let a=de[t%de.length];return{...a,stroke:a.stroke||s.style.accentColor}}),n=i[0]?.date!==void 0,c=[],d=e=>{let t=c.findIndex(t=>t.time===e.time&&t.tie===e.tie);return t>=0?t:(c.push(e),c.length-1)},p=void 0===s.today?void 0:ei(s.today),h=new Map,g=new Map,u=[!1,!0].flatMap(e=>i.flatMap((t,a)=>{let s,i,l=void 0!==t.end;if(l!==e)return[];let o=n?ei(t.date):void 0,r=void 0===t.end?void 0:ei(t.end),c=o?o.start:t.order??a,u=t.lane??"",f=r?(c+r.end)/2:c,m=p&&r&&p.start>c&&p.start<r.end,v=r&&(m||h.has(`${u}\0${f}`))?function(e,t,a){let s=[e,...a.filter(a=>a>e&&a<t),t].toSorted((e,t)=>e-t),i={from:e,to:e};for(let[e,t]of s.slice(1).entries())t-s[e]>i.to-i.from&&(i={from:s[e],to:t});return(i.from+i.to)/2}(c,r.end,[...g.get(u)??[],...m?[p.start]:[]]):f,y=d({time:v,tie:(s=`${u}\0${v}`,i=h.get(s)??0,h.set(s,i+1),g.set(u,[...g.get(u)??[],v]),i)});return[{event:t,index:a,span:l,start:l?d({time:c,tie:0}):y,end:r?d({time:r.end,tie:0}):void 0,stem:y}]})).toSorted((e,t)=>e.index-t.index),f=p?d({time:p.start,tie:0}):void 0,m=c.map((e,t)=>({anchor:e,key:t})).toSorted((e,t)=>e.anchor.time-t.anchor.time||e.anchor.tie-t.anchor.tie),y=new Map(m.map((e,t)=>[e.key,t])),w=m.map(e=>e.anchor),x=u.map(e=>{let t=r[e.event.lane?o.indexOf(e.event.lane):0],a=`event:${e.event.id}`,s=l.events.get(e.event.id),i=[...s?[dt(`date:${a}`,s,14,t.ink)]:[],dt(`label:${a}`,e.event.label,16,v.ink),...e.event.description?[dt(`description:${a}`,e.event.description,13,c8)]:[]];return{event:e.event,index:e.index,lane:e.event.lane?o.indexOf(e.event.lane):0,span:e.span,startKey:y.get(e.start),endKey:y.get(e.end??e.start),stemKey:y.get(e.stem),inset:Math.max(10,(s?i[0].width:0)/2-12),parts:i,width:Math.max(...i.map(e=>e.width)),height:i.reduce((e,t)=>e+t.height,0)+2*(i.length-1)}}),b=void 0===f?void 0:y.get(f),k=Math.min(128,Math.max(72,Math.round((a=Math.floor((t=x.map(e=>e.width).toSorted((e,t)=>e-t)).length/2),((t.length%2?t[a]:(t[a-1]+t[a])/2)+16)/2+8)))),M=1.5*k,C=e=>x.some(t=>t.span&&t.startKey<=e&&t.endKey>e),z=w.slice(1).map((e,t)=>e.time-w[t].time),_=new Map,L=e=>{let t=_.get(e);if(!t){var a;let s,i,l,o=(a=z[e],s=(e,t)=>`${e} ${t}${1===e?"":"s"}`,i=e=>s(Math.max(1,Math.round(a/cU[e])),e),l=e=>{let t=a/cU[e];return s(t<10?Math.round(10*t)/10:Math.round(t),e)},a<1e3?i("millisecond"):a<12e4?l("second"):a<72e5?i("minute"):a<1728e5?i("hour"):a<5184e6?i("day"):a<63113904e3?i("month"):l("year"));t={text:o,half:aF(o,13,200)/2+6},_.set(e,t)}return t},B=[...new Set(x.flatMap(e=>[e.startKey,e.endKey]).map(e=>w.findIndex(t=>t.time===w[e].time)))].toSorted((e,t)=>e-t),S=e=>{let t=new Set(e);if(!n)return{x:w.map((e,t)=>t*k),breaks:t};if(w.length<2)return{x:w.map(()=>0),breaks:t};let a=z.reduce((e,t)=>e+t,0),s=x.length*k,i=10*k,l=a>0?s/a:0,o=[...r.flatMap((e,t)=>x.filter(e=>e.lane===t).toSorted((e,t)=>e.stemKey-t.stemKey).flatMap((e,t,a)=>{let s=a[t-1];return s&&s.stemKey!==e.stemKey?[{from:s.stemKey,to:e.stemKey,min:Math.max(28,e.inset+c7+1)}]:[]})),...x.filter(e=>e.span).map(e=>({from:e.startKey,to:e.endKey,min:12}))].filter(e=>e.to>e.from),c=Math.max(28,...o.map(e=>e.min)),d=(e,a)=>{let s=[0],i=0,l=0;return z.forEach((o,r)=>{let n=w[r+1];n.tie>0?s.push(i+n.tie*c):(i=t.has(r)?a?Math.max(i+a.get(r),l+Math.max(M,2*(L(r).half+3+16))):l+M:i+o*e,s.push(i)),l=Math.max(l,s[r+1])}),s},p=()=>{let[e,t]=[d(0),d(1)];return o.map(({from:a,to:s,min:i})=>{let l=e[s]-e[a];return{from:a,to:s,min:i,fixed:l,perScale:t[s]-e[s]-(t[a]-e[a])}})},h=Math.max(0,...x.filter(e=>e.span).map(e=>w[e.endKey].time-w[e.startKey].time)),g=h>0?Math.max(l,2*i/h):1/0,u=l;for(;;){let e=z.reduce((e,a,s)=>e+(t.has(s)?0:a),0),a=t.size&&e>0?Math.min(2*l,Math.max(l,(s-t.size*M)/e)):l,o=p();u=Math.min(Math.max(a,...o.map(({min:e,fixed:t,perScale:a})=>a>0&&t<e?(e-t)/a:0)),g);let r=t.size?2*M:i,n=z.flatMap((e,a)=>t.has(a)||!(e*u>r)||C(a)?[]:[a]);for(let{from:e,to:a,min:s,fixed:i,perScale:l}of o)if(i+l*u<s-1e-6){let s=z.map((e,t)=>({gap:e,key:t})).slice(e,a).filter(({gap:e,key:a})=>e>0&&!t.has(a)).toSorted((e,t)=>t.gap-e.gap||e.key-t.key)[0];s&&n.push(s.key)}if(!n.length)break;for(let e of n)t.add(e)}if(!t.size)return{x:d(u),breaks:t};let f=Math.max(M,...z.map((e,a)=>t.has(a)||C(a)?0:e*u)),m=[...t].filter(e=>z[e]*u>=M),v=Math.min(...m.map(e=>z[e])),y=Math.log2(Math.max(...m.map(e=>z[e]))/v),b=Math.min(.5,y>0?1/y:1/0),_=new Map([...t].map(e=>[e,f*(1+b*Math.log2(Math.max(1,z[e]/v)))])),S=d(u,_),A=new Set(m),P=B.slice(1).flatMap((e,a)=>{let s=B[a],i=z.slice(s,e).map((e,t)=>s+t),l=i.filter(e=>A.has(e)).at(-1);return void 0===l&&i.some(e=>t.has(e))?[]:[{from:s,to:e,elapsed:w[e].time-w[s].time,broken:l}]}),V=e=>S[e.to]-S[e.from];for(let e of P.toSorted((e,t)=>e.elapsed-t.elapsed)){if(void 0===e.broken)continue;let{elapsed:t}=e,a=Math.max(...P.map(e=>1.5*e.elapsed<=t?V(e)+12:e.elapsed<t?V(e):0)),s=Math.min(...P.map(e=>void 0!==e.broken?1/0:e.elapsed>=1.5*t?V(e)-12:e.elapsed>t?V(e):1/0)),i=Math.min(Math.max(V(e),a),s);if(1e-9>Math.abs(i-V(e)))continue;let l=e.broken,o=w.findIndex(e=>e.time===w[l].time);_.set(l,S[l+1]-S[o]+i-V(e)),S=d(u,_)}return{x:S,breaks:t}},A=({x:e,breaks:t})=>{let a=e.map((t,a)=>Math.max(...e.slice(0,a+1))),s=e.map((t,a)=>Math.min(...e.slice(a))),i=t=>(a[t]+e[t+1])/2,l=w.slice(0,-1).flatMap((e,l)=>{if(C(l))return[];let o=s[l+1]-14;if(t.has(l)){let e=i(l)+L(l).half+3+7;return[{key:l,low:e,high:Math.max(e,o),broken:!0}]}let r=a[l]+14;return r<=o?[{key:l,low:r,high:o,broken:!1}]:[]}),r=new Set(x.flatMap(t=>{if(!t.span)return[];let a=e[t.startKey]+Math.max(12,e[t.endKey]-e[t.startKey]);return x.some(s=>!s.span&&s.lane===t.lane&&(s.startKey<t.startKey||s.startKey>=t.endKey)&&e[s.startKey]+ds(s)>e[t.startKey]&&e[s.startKey]-ds(s)<a)?[t.lane]:[]}));return{x:e,breaks:t,reachBefore:a,rowsFor:t=>{let a=e[e.length-1],s=[],i=0,o=-24;for(let e=1;e<t;e+=1){let r=a*e/t,n=l.filter(e=>e.key>=i).map(e=>{let t=Math.min(e.high,Math.max(e.low,r));return{cut:e,at:t,cost:Math.abs(t-r)-(e.broken?k:0)-Math.min(e.high-e.low,2*k)/4}}).toSorted((e,t)=>e.cost-t.cost||e.cut.key-t.cut.key)[0];if(!n)break;s.push({first:i,last:n.cut.key,start:o,end:n.at}),i=n.cut.key+1,o=n.at}return s.push({first:i,last:w.length-1,start:o,end:Math.max(...e)+24}),s},layout:t=>{let a=Math.max(1,o.length);return t.map((t,s)=>{let l=t.start-32*(s>0),o=t=>e[t]-l,n=void 0!==b&&b>=t.first&&b<=t.last?o(b):void 0,c=Array.from({length:a},(e,a)=>(function(e,t,a,s){let i;for(let l of da){let o=function(e,t,a,s,i){let l=[],o=new Map;for(let t of e.filter(e=>e.span).toSorted((e,t)=>e.startKey-t.startKey)){let e=l.findIndex((e,a)=>a>=s&&e<=t.startKey);for(e<0&&(e=Math.max(s,l.length));l.length<e;)l.push(-1/0);l[e]=t.endKey,o.set(t,e)}let r=l.length,n=22+16*Math.max(0,r-1),c=e=>t(e.stemKey),d=e.toSorted((e,t)=>c(t)-c(e)||t.index-e.index),p={"-1":[],1:[]},h={"-1":[],1:[]},g=[],u=(e,t,a=c7)=>t>e.left-a&&t<e.right+a,f=-1;d.forEach((e,t)=>{let s=c(e),l=d.slice(t+1).map(c),r=i.lookahead?d[t+2]:void 0,m=(e,t,a)=>{if(!r||t>a)return 0;let s=c(r);return s+10+16>e?1e3:Math.max(0,s+r.width/2+16-e)/2},v=s-e.width+e.inset,y=s-e.inset,w=(o.get(e)??0)>0,x=w?1:f,b=e=>e.option.near-(e.side===x?w?120:1:0),k=t=>[x,-x].flatMap(o=>{let d=((t,o)=>{let d=t<0?22:n,g=p[t],f=p[-t],w=[...h[t],...o&&void 0!==a&&Math.abs(a-s)>=14?[{x:a,reach:1/0}]:[]],x=[d,...g.map(e=>e.far+10)].filter(e=>e>=d).toSorted((e,t)=>e-t),b=s-e.width/2,k=[b,v,y,...g.flatMap(t=>[t.right+16,t.left-16-e.width]),...[...w,...l.map(e=>({x:e,reach:0}))].flatMap(t=>{let a=1/0===t.reach?3*c7:c7;return[t.x+a,t.x-a-e.width]}),...r?[c(r)+10+16,c(r)+r.width/2+16]:[]].map(e=>Math.min(y,Math.max(v,e)));for(let t of x){let a=t+e.height,o=a=>Math.abs(a-b)+m(a,t,d)+i.coverPenalty*l.slice(1).filter(t=>u({left:a,right:a+e.width},t)).length;for(let i of k.toSorted((e,t)=>o(e)-o(t)||e-t)){let o=i+e.width,r={left:i,right:o};if(g.every(e=>i>=e.right+16||e.left>=o+16||t>=e.far+10||e.near>=a+10)&&g.every(e=>!u(e,s)||e.near>t)&&w.every(e=>!u(r,e.x,1/0===e.reach?3*c7:c7)||e.reach<=t)&&l.every(e=>!u(r,e)||f.every(t=>!u(t,e))))return{near:t,left:i}}}})(o,t);return d?[{side:o,option:d}]:[]}).toSorted((e,t)=>b(e)-b(t))[0],M=k(!0)??k(!1);if(!M)throw Error(`Timeline label for "${e.event.id}" has no clear placement.`);let{side:C,option:z}=M,{near:_,left:L}=z;p[C].push({left:L,right:L+e.width,near:_,far:_+e.height}),h[C].push({x:s,reach:_});let B=o.get(e)??0,S=16*B;g.push({item:e,stemX:s,side:C,near:_,left:L,stemStart:C>0?S+ds(e):ds(e)-S,track:B}),f=-C});let m=(e,t)=>Math.max(t,...p[e].map(e=>e.far));return{placements:g,above:m(-1,15),below:m(1,Math.max(9,n-22+6)+6),tracks:r}}(e,t,a,s,l);(!i||o.above+o.below<i.above+i.below)&&(i=o)}return i})(x.filter(e=>e.lane===a&&e.startKey>=t.first&&e.startKey<=t.last),o,n,+!!r.has(a)));return{row:t,localX:o,breakX:e=>i(e)-l,todayX:n,lanes:c,axisStart:t.start-l,axisEnd:t.end-l}})}}},P=o.length?Math.max(...o.map(e=>aF(e,15,160)))+20:0,V=l.header,H=l.today,q=(e,t)=>{var a,s;let i,l,n,c,d,p,h,g,u,f,m=e.rowsFor(t);if(m.length<t)return;let v=(a=e.breaks,s=e.layout(m),i=[],l=[],n=[],c=[],d=(e,t)=>{i.push(e),t.push(e.id)},p=(e,t,a={})=>({type:"line",id:e,points:t,...a}),h=(e,t,a,s,i,l,o={})=>({type:"text",id:e,x:a,y:s,text:t,fontSize:i,maxWidth:200,textColor:l,...o}),g=V?Math.ceil(14*1.35):0,u=18*!!H,f=V?g+18:0,s.forEach((e,t)=>{let i=f,g=void 0!==e.todayX;g&&(f+=u+6);let m=t<s.length-1,v=t>0;if(e.lanes.forEach((s,i)=>{let g=r[i],u=f+s.above,y=`${i}:${t}`,w={strokeColor:g.stroke,strokeWidth:2,roughness:0},x=[...a].toSorted((e,t)=>e-t).filter(t=>t>=e.row.first&&t<=e.row.last).map(t=>({x:P+e.breakX(t),...L(t)})),b=[P+e.axisStart,...x.flatMap(e=>[e.x-e.half,e.x+e.half]),P+e.axisEnd];for(let e=0;e<b.length;e+=2)b[e+1]>b[e]&&d(p(`axis:${y}${e?`:${e/2}`:""}`,[{x:b[e],y:u},{x:b[e+1],y:u}],w),l);for(let t of(x.forEach((e,t)=>{for(let a of[-1,1])d(p(`break:${y}:${t}:${a<0?"a":"b"}`,[{x:e.x+a*e.half-3,y:u+7},{x:e.x+a*e.half+3,y:u-7}],w),c);d(h(`break-label:${y}:${t}`,e.text,e.x,u,13,g.ink),c)}),v&&d(p(`continue-in:${y}`,[{x:P,y:u},{x:P+32,y:u}],{...w,strokeStyle:"dashed"}),l),m&&d(p(`continue-out:${y}`,[{x:P+e.axisEnd,y:u},{x:P+e.axisEnd+32,y:u}],{...w,strokeStyle:"dashed",endArrowhead:"arrow"}),l),o.length&&d(h(`lane:${y}`,o[i],P-16-aF(o[i],15,160)/2,u,15,g.ink,{maxWidth:160,textAlign:"right"}),c),s.placements)){let{item:a}=t,s=`event:${a.event.id}`,i={groupIds:[s]},o=u+16*t.track,r=P+t.stemX;if(a.span){let t=P+e.localX(a.startKey);d({type:"node",id:`node:${s}`,nodeId:s,rendererRole:c6,shape:"rectangle",x:t,y:o-6,width:Math.max(12,P+e.localX(a.endKey)-t),height:12,label:a.event.label,fillColor:g.wash,strokeColor:g.stroke,...i},n)}else{let e="milestone"===a.event.kind,t=e?18:12;d({type:"node",id:`node:${s}`,nodeId:s,rendererRole:c6,shape:e?"diamond":"ellipse",x:r-t/2,y:u-t/2,width:t,height:t,label:a.event.label,fillColor:g.stroke,strokeColor:g.stroke,...i},c)}let f=u+t.side*t.near;d(p(`stem:${s}`,[{x:r,y:u+t.side*t.stemStart},{x:r,y:f}],{strokeColor:"#b9ad95",strokeWidth:1,roughness:0,...i}),l);let m=P+t.left,v=t.side<0?f-a.height:f;for(let e of a.parts){let t=aF(e.text,e.fontSize,200),s=Math.min(Math.max(r,m+t/2),m+a.width-t/2),l=s===r?"center":s<r?"right":"left";d(h(e.id,e.text,s,v+e.height/2,e.fontSize,e.color,{textAlign:l,...i}),c),v+=e.height+2}}f=u+s.below+28*(i<e.lanes.length-1)}),g){let a=P+e.todayX;d(p(`today:${t}`,[{x:a,y:i+u+3},{x:a,y:f}],{strokeColor:c9,strokeWidth:1,strokeStyle:"dashed",roughness:0}),l),d(h(`today-label:${t}`,H,a,i+u/2,13,c9),c)}f+=48}),f-=48,V&&d(h("header",V,aF(V,14,400)/2,g/2,14,c8,{maxWidth:400,textAlign:"left"}),c),{elements:i,zOrder:[...l,...n,...c],height:f}),y=(e=>{let t=1/0,a=-1/0,s=1/0,i=-1/0,l=(e,l,o,r)=>{t=Math.min(t,e),a=Math.max(a,o),s=Math.min(s,l),i=Math.max(i,r)};for(let t of e)if("line"===t.type||"arrow"===t.type)for(let e of t.points)l(e.x,e.y,e.x,e.y);else if("text"===t.type){let e=aF(t.text,t.fontSize,t.maxWidth??200),a=t.text.split("\n").length*t.fontSize*1.35;l(t.x-e/2,t.y-a/2,t.x+e/2,t.y+a/2)}else("node"===t.type||"frame"===t.type)&&l(t.x,t.y,t.x+t.width,t.y+t.height);return{minX:t,maxX:a,minY:s,maxY:i}})(v.elements),w=Math.abs(Math.log((y.maxX-y.minX+80)/(y.maxY-y.minY+80)/2))+.3*(t-1);return{count:t,composed:v,box:y,score:w}},F=e=>e.reduce((e,t)=>!e||t.score<e.score-1e-9?t:e,void 0),I=({box:e})=>(e.maxX-e.minX+40)/(e.maxY-e.minY+40),E=({x:e,breaks:t,reachBefore:a})=>z.map((t,s)=>({gap:t,key:s,free:e[s+1]-a[s]})).filter(({gap:e,key:a,free:s})=>e>0&&!t.has(a)&&!C(a)&&s>=2*M).toSorted((e,t)=>t.free-e.free||e.key-t.key)[0],O=Math.max(1,Math.min(12,Math.ceil(x.length/2))),U=A(S(new Set)),X=[];for(let e=1;e<=O;e+=1){let t=q(U,e);if(!t)break;X.push(t)}let T=F(X);if(n&&1===T.count&&I(T)>3.5){let e=new Set,t=U,a=T;for(let s=E(t);s&&I(a)>3.5;s=E(t))e.add(s.key),a=q(t=A(S(e)),1);T=3.5>=I(a)?a:F(X.slice(1))??a}let{composed:Y,box:$}=T,G=40-$.minX,D=40-$.minY,R=Y.elements.map(e=>{if("line"===e.type||"arrow"===e.type){let[t,...a]=e.points.map(e=>({x:e.x+G,y:e.y+D}));return"line"===e.type?{...e,points:[t,a[0],...a.slice(1)]}:{...e,points:[t,...a]}}return{...e,x:e.x+G,y:e.y+D}});return{kind:"canvas",version:1,diagramId:s.id,title:s.title,width:Math.ceil($.maxX-$.minX+80),height:Math.ceil($.maxY-$.minY+80),accentColor:s.style.accentColor,backgroundColor:s.style.backgroundColor,elements:R,layers:[],layouts:[],zOrder:Y.zOrder}})(u2(p)),catch:e=>new fx({status:"render_failed",context:{...f,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render timeline scene.",hint:"Repair the event dates and ordering and retry."})]}})}).pipe(o.fRP("codeMode.buildTimeline.render")),w=se(m);if(w.length>0)return yield*new fx({status:"render_failed",context:{...f,issues:f$(w).map(e=>({...e,hint:"Split the chronology into smaller timelines and retry buildTimeline."}))}});let x={...f,partial:mt(m)},b=yield*mi({scene:m,formats:fU(c.options),inlineFormats:fX(c.options),...c.requestId?{requestId:c.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fx({status:e.status,context:{..."export_failed"===e.status?x:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:d,...me(c.requestId),normalizedSpec:p,quality:u,artifact:b,issues:[]}}),mh=o.fn("codeMode.buildChart.workflow")(function*(e){var t,a;let s,l,r,n,c,d=i.q$Z(lW,{errors:"all",reportInput:!0})(e);if(!um.oJ(d))return yield*new fb({status:"invalid_input",context:{issues:fF(s9(d.failure))}});let p=yield*uQ,h=d.success,g=yield*o.OH5(()=>p.createId("build")),u=(s=s5((t=h.spec).title),r=(l=e=>{let t=fE(e);return void 0===t?void 0:t})(t.unit),n=l(t.categoryAxisTitle),c=l(t.valueAxisTitle),{id:fE(t.id)??(fI(s)||"sketchi-chart"),title:s,kind:t.kind,categories:t.categories.map(s5),series:t.series.map(e=>{let t=l(e.name);return{...t?{name:t}:{},values:[...e.values]}}),...r?{unit:r}:{},...n?{categoryAxisTitle:n}:{},...c?{valueAxisTitle:c}:{},...void 0!==t.stacked?{stacked:t.stacked}:{},...void 0!==t.donut?{donut:t.donut}:{},...t.orientation?{orientation:t.orientation}:{},style:{...y}}),f={buildId:g,...me(h.requestId),normalizedSpec:u},m=j(u3(u)).map(e=>fB({code:e.code,stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(m.length>0)return yield*new fb({status:"invalid_chart",context:{...f,issues:m}});let v={accepted:10>=(a=h.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:u.categories.length*u.series.length,edgeCount:0},checks:[]},w={...f,quality:v};if(!v.accepted)return yield*new fb({status:"quality_failed",context:{...w,issues:fO(v)}});let x=yield*o.SvU({try:()=>(function(e){let t=W(e),a=new ca(t.style.backgroundColor);if("pie"===t.kind)!function(e,t){let a=t.series[0].values,s=nU(t.unit),i=ct(a.length,!0),{labels:l,shares:o}=function(e){let t=e.reduce((e,t)=>e+t,0),a=e.map(e=>t>0?e/t*100:0),s=e=>a.map(t=>Math.round(t*10**e)/10**e),i=t=>e.some((a,s)=>a>0&&0===t[s]||e.some((e,i)=>i>s&&e!==a&&t[i]===t[s])),l=+!!a.some(e=>e>0&&e<10);for(;l<2&&i(s(l));)l+=1;let o=s(l);return{shares:a,decimals:l,labels:o.map((t,a)=>0===t&&e[a]>0?`<${(10**-l).toFixed(l)}%`:`${Number(t.toFixed(l))}%`)}}(a),r=t.unit?.trim()==="%",n=87*!!t.donut,c=-Math.PI/2,d=a.map((e,t)=>{let a=o[t]/100*2*Math.PI,s={index:t,start:c,end:c+a,mid:c+a/2};return c+=a,s}),p=[];for(let o of d){let c=i[o.index],d=t.categories[o.index],h=nR(a[o.index],s),g=l[o.index],u={groupIds:[`chart:slice:${o.index}`]},f=o.end-o.start;if(f>.0035){let t=f>=2*Math.PI-1e-9,a=cp(150,o.start,t?o.end-1e-4:o.end),s=n>0?[...a,...cp(n,t?o.end-1e-4:o.end,o.start)]:t?a:[{x:0,y:0},...a];e.polygon(`chart:slice:${o.index}`,s,`${d}: ${g} (${h})`,{fillColor:c,strokeColor:e.surface,strokeWidth:2,...u})}let m=r&&g===h?g:`${g} \xb7 ${h}`,v=n3(`${aO(d,110,14)}
|
|
248
|
+
${t}}`),s},ey="~effect/Fiber",ew={_A:v.D_,_E:v.D_},ex={id:0},eb=(()=>{try{return globalThis.process?.getBuiltinModule?.("node:async_hooks")?.AsyncResource}catch{return}})(),ek=()=>void 0===eb?void 0:new eb("effect/Fiber"),eM=()=>globalThis[B.fL];class eC{constructor(e,t=!0){this.setContext(e),this.id=++ex.id,this.currentOpCount=0,this.interruptible=t,this._stack=[],this._observers=void 0,this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0,this._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this._asyncContext=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}get[ey](){return ew}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return u.Jt(this.context,e)}addObserver(e){return this._exit?(e(this._exit),v.Yi):(void 0===this._observers?this._observers=[e]:this._observers.push(e),()=>this.removeObserver(e))}removeObserver(e){if(this._exit||void 0===this._observers)return;let t=this._observers.indexOf(e);t>=0&&this._observers.splice(t,1)}interruptUnsafe(e,t){if(this._exit)return;let a=$(e);this.cache.stackFrame&&(a=(0,V.Eh)(a,u.L8(V.z8,this.cache.stackFrame))),t&&(a=(0,V.Eh)(a,t)),this._interruptedCause=this._interruptedCause?(0,V.h2)(this._interruptedCause,a):a,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(eX(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(void 0!==this._asyncContext){let t=this._asyncContext;return this._asyncContext=void 0,t.runInAsyncScope(this.evaluate,this,e)}if(void 0!==this._yielded){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===V.GN){this._asyncContext=ek();return}let a=eB.interruptChildren&&eB.interruptChildren(this);if(void 0!==a)return this.evaluate(tV(a,()=>t));if(this._exit=t,this.cache.runtimeMetrics?.recordFiberEnd(this.context,this._exit),this._parent&&(this._parent._children?.delete(this),this._parent=void 0),void 0!==this._observers){let e=this._observers;this._observers=void 0;for(let a=0;a<e.length;a++)e[a](t)}this._stack.length=0,this._children=void 0,this.context=u.Ie()}runLoop(e){let t=globalThis[B.fL];globalThis[B.fL]=this;let a=this._running;this._running=!0;let s=!1,i=e;this.currentOpCount=0;try{for(;;){this._deferredInterrupt&&(this._deferredInterrupt=!1,i=eX(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!s&&!e.preventYield&&e.scheduler.shouldYield(this)){s=!0;let e=i;i=tV(ej,()=>e)}if((i=e.tracerContext?e.tracerContext(i,this):i[V._3](this))===V.GN){let e=this._yielded;if(V.IH in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return V.GN}}}catch(e){if(!(0,w.i5)(i,V._3))return(0,V.V2)(`Fiber.runLoop: Not a valid effect: ${String(i)}`);return this.runLoop((0,V.V2)(e))}finally{this._running=a,globalThis[B.fL]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,e_;for(;;){let t=this._stack.pop();if(!t)return;let a=t[V.u4];if(void 0!==a){let s=a.call(t,this);if(s)return s[e]=s,s}if(t[e])return t}}succeedWith(e){if((++this.currentOpCount&eL-1)==0)return(0,V.xt)(e);let t=this.getCont(V.ee);return t?t[V.ee](e,this):this.yieldWith((0,V.xt)(e))}yieldWith(e){return this._yielded=e,V.GN}children(){return this._children??=new Set}pipe(){return(0,L.tT)(this,arguments)}setContext(e){let t=this.context;if(this.context=e,void 0!==t&&u.Pf(t,e))return;let a=e.cacheRoot,s=a._fiberCache??=ez(e);this.cache?.scheduler!==s.scheduler&&(this._dispatcher=void 0),this.cache=s}get currentSpanLocal(){let e=this.cache.span;return e?._tag==="Span"?e:void 0}}let ez=e=>{let t=u.Ub(e,A.RL);return{scheduler:u.Jt(e,S._F),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:u.Jt(e,I.rf),span:u.Ub(e,A.WG),logLevel:u.Jt(e,I.Gl),minimumLogLevel:u.Jt(e,I.zQ),stackFrame:u.Jt(e,I.vA),runtimeMetrics:u.Ub(e,q.F),maxOpsBeforeYield:u.Jt(e,S.Zm),preventYield:u.Jt(e,S.hf)}},e_={[V.ee]:(e,t)=>eX(t._interruptedCause),[V.Sc]:(e,t)=>eX(t._interruptedCause)},eL=32,eB={interruptChildren:void 0},eS=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(V.QJ.key,e.cache.stackFrame),u.LZ(t)},eA=e=>{if(void 0!==e._children&&0!==e._children.size)return eE(e._children)},eP=e=>e._exit?eU(e._exit):te(t=>e._exit?t(eU(e._exit)):eY(e.addObserver(e=>t(eU(e))))),eV=e=>te(t=>{let a,s=e[Symbol.iterator](),i=[];return!function e(){let l=s.next();for(;!l.done;){if(l.value._exit){i.push(l.value._exit),l=s.next();continue}a=l.value.addObserver(t=>{i.push(t),e()});return}t(eU(i))}(),eY(()=>a?.())}),eH=e=>e._exit?e._exit:te(t=>e._exit?t(e._exit):eY(e.addObserver(t))),eq=e=>te(t=>{let a=Array.from(e);if(0===a.length)return t(eU(g.Ie()));let s=Array(a.length),i=g.Ie(),l=()=>{for(let e=0;e<i.length;e++)a[e].removeObserver(i[e])},o=0,r=!1;for(let e=0;e<a.length&&!r;e++){let n=i=>{if(o++,"Failure"===i._tag)return r=!0,l(),t(i);s[e]=i.value,o===a.length&&t(eU(s))};i.push(n),a[e].addObserver(n)}return eY(()=>{r=!0,l()})}),eF=e=>(0,V.R6)(t=>eI(e,t.id)),eI=(0,v.XY)(e=>(0,w.i5)(e[0],ey),(e,t,a)=>(0,V.R6)(s=>{let i=eS(s);return i=i&&a?u.h1(i,a):i??a,e.interruptUnsafe(t,i),t_(eP(e))})),eE=e=>(0,V.R6)(t=>{let a=eS(t),s=g.Ie();for(let i of e)i.interruptUnsafe(t.id,a),s.push(i);return t_(eV(s))}),eO=(0,v.XY)(2,(e,t)=>(0,V.R6)(a=>{let s=eS(a),i=g.Ie();for(let a of e)a.interruptUnsafe(t,s),i.push(a);return t_(eV(i))})),eU=V.xt,eX=V.cb,eT=V.Rk,eY=(0,V.Uf)({op:"Sync",[V._3](e){let t=this[V.a2](),a=e.getCont(V.ee);return a?a[V.ee](t,e):e.yieldWith((0,V.xt)(t))}}),e$=(0,V.Uf)({op:"Suspend",[V._3](e){return this[V.a2]()}}),eG=(0,v.XY)(e=>e.length>=2||y.isOption(e[0]),(e,t)=>y.isNone(e)?eT(t?t():new V.Xm("Effect.fromOption: Option.none")):eU(e.value)),eD=x.YW({onFailure:eT,onSuccess:eU}),eR=e=>null==e?eT(new V.Xm):eU(e),eZ=(0,V.Uf)({op:"Yield",[V._3](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{t||e.evaluate(t1)},this[V.a2]??0),e.yieldWith(()=>{t=!0})}}),ej=eZ(0),eN=e=>eU(y.some(e)),eW=eU(y.none()),eJ=e=>y.isNone(e)?eW:tE(e.value,y.some),eK=e=>e$(()=>eX(e())),eQ=e=>(0,V.V2)(e),e1=e=>e$(()=>eT(e())),e0=eU(void 0),e2=e=>{let t="function"==typeof e?e:e.try,a="function"==typeof e?e=>new lI(e,"An error occurred in Effect.try"):e.catch;return e$(()=>{try{return eU(t())}catch(e){return eT(a(e))}})},e3=e=>e8(function(t,a){e(a).then(e=>t(eU(e)),e=>t(eQ(e)))},0!==e.length),e5=e=>{let t="function"==typeof e?e:e.try,a="function"==typeof e?e=>new lI(e,"An error occurred in Effect.tryPromise"):e.catch;return e8(function(e,s){let i=e=>e$(()=>{try{return eT((0,P.s)(()=>a(e)))}catch(e){return eQ(e)}});try{t(s).then(t=>e(eU(t)),t=>e(i(t)))}catch(t){e(i(t))}},0!==t.length)},e4=e=>(0,V.R6)(t=>e(t.id)),e6=(0,V.R6)(eU),e7=e4(eU),e8=(s=(0,V.yj)({op:"Async",[V._3](e){let t=!1,a=!1,s=this.withSignal?new AbortController:void 0,i=this.register.call(e.cache.scheduler,s=>{t||(t=!0,a?e.evaluate(s):a=s)},s?.signal);return!1!==a?a:(a=!0,e._yielded=()=>{t=!0},void 0===s&&void 0===i||e._stack.push(e9(()=>(t=!0,s?.abort(),i??t1))),V.GN)}}),(i=function(e,t){this.register=e,this.withSignal=t}).prototype=s,function(e,t){return new i(e,t)}),e9=(0,V.Uf)({op:"AsyncFinalizer",[V.u4](e){e.interruptible&&(e.interruptible=!1,e._stack.push(s2))},[V.Sc](e,t){return J(e)?tV(sm((0,V.cb)(e),this[V.a2]()),()=>eX(e)):eX(e)}}),te=e=>e8(e,e.length>=2),tt=te(v.Yi),ta=(...e)=>{if(1===e.length){let t=e[0];return e$(()=>td(t()))}let[t,a]=e;return e$(()=>td(a.call(t.self)))},ts=(e,...t)=>{let a=0===t.length?function(){return e$(()=>td(e.apply(this,arguments)))}:function(){let a=e$(()=>td(e.apply(this,arguments)));for(let e=0;e<t.length;e++)a=t[e](a,...arguments);return a};return ti(e.length,a)},ti=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),tl=U(2),to=function(){let e,t="string"==typeof arguments[0],a=t?arguments[0]:"Effect.fn",s=t?arguments[1]:void 0,i=(0,E.jt)();return(0!==i&&((0,E.ft)(2),e=new globalThis.Error,(0,E.ft)(i)),t)?(i,...l)=>tr(a,i,e,l,t,s):tr(a,arguments[0],e,Array.prototype.slice.call(arguments,1),t,s)},tr=(e,t,a,s,i,l)=>{let o="function"==typeof t?t:s.shift().bind(t.self),r=`${e} (definition)`,n=a?tl(()=>a.stack):v.MN;return ti(o.length,function(...t){let a,c=e$(()=>{let e=o.apply(this,arguments);return(0,V.yw)(e)?e:td(e)});for(let e=0;e<s.length;e++)c=s[e](c,...t);if(!(0,V.yw)(c))return c;let d=(0,E.jt)();return 0!==d&&((0,E.ft)(2),a=new globalThis.Error,(0,E.ft)(d)),al(i?li(e,l,e=>ll(c,e)):c,I.vA,t=>({name:e,stack:a?tl(()=>a.stack):v.MN,parent:{name:r,stack:n,parent:t}}))})},tn=(e,...t)=>ti(e.length,0===t.length?function(){return tc(()=>e.apply(this,arguments))}:function(){let a=tc(()=>e.apply(this,arguments));for(let e of t)a=e(a,...arguments);return a}),tc=e=>{try{let t,a=e();for(;;){let s=a.next(t);if(s.done)return eU(s.value);let i=s.value;if(i&&"Success"===i._tag){t=i.value;continue}{if(i&&"Failure"===i._tag)return s.value;let t=!0;return e$(()=>t?(t=!1,tV(s.value,e=>td(a,e))):e$(()=>td(e())))}}}catch(e){return eQ(e)}},td=(l=(0,V.yj)({op:"Iterator",[V.ee](e,t){let a=this.iterator;for(;;){let s=a.next(e);if(s.done)return eU(s.value);if(!tq(s.value))return t._stack.push(this),s.value;if("Failure"===s.value._tag)return s.value;e=s.value.value}},[V._3](e){return this[V.ee](this.initial,e)}}),(o=function(e,t){this.iterator=e,this.initial=t}).prototype=l,function(e,t){return new o(e,t)}),tp=(0,v.XY)(2,(e,t)=>new tu(e,tf,eU(t))),th=function(e){return e._stack.push(this),this[V.a2]},tg=(0,V.yj)({op:"OnSuccess",[V._3]:th}),tu=function(e,t,a){this[V.a2]=e,this[V.ee]=t,this.payload=a};tu.prototype=tg;let tf=function(){return this.payload},tm=function(e,t){return t.succeedWith(this.payload)},tv=(r="~effect/Effect/stackProbe",({[r]:function(){return Error().stack}})[r]()?.includes("[as "+r+"]")===!0),ty=function(e,t){let a=this.payload;return t.succeedWith(tv?a(e):(0,P.s)(()=>a(e)))},tw=function(e){return(0,this.payload)(e)},tx=function(e){return new tu((0,this.payload)(e),tm,e)},tb=function(e){return new tu(this.payload,tm,e)},tk=e=>tE(e,y.some),tM=e=>a7(e,{onFailure:eU,onSuccess:eT}),tC=(0,v.XY)(2,(e,t)=>new tu(e,(0,V.yw)(t)?tf:tw,t)),tz=(0,v.XY)(2,(e,t)=>new tu(e,(0,V.yw)(t)?tb:tx,t)),t_=e=>new tu(e,tf,t1),tL=e=>ak(e,eT),tB=(e,t)=>(0,V.R6)(a=>{let s=new Set;return sE(a,()=>0===s.size?void 0:eE(s)),te(i=>{let l=g.Ts(e),o=l.length,r=0,n=!1,c=[],d=(e,s,l)=>{if(r++,"Failure"===e._tag){c.push(...e.cause.reasons),r>=o&&i(eX((0,V.b5)(c)));return}let d=!n;n=!0,i(e),d&&t?.onWinner&&t.onWinner({fiber:s,index:l,parentFiber:a})};for(let e=0;e<o;e++){let t=iA(a,l[e],!0,!0,!1);if(s.add(t),t.addObserver(a=>{s.delete(t),d(a,t,e)}),n)break}})}),tS=(e,t)=>(0,V.R6)(a=>{let s=new Set;return sE(a,()=>0===s.size?void 0:eE(s)),te(i=>{let l=!1,o=0;for(let r of e){if(l)break;let e=o++,n=iA(a,r,!0,!0,!1);s.add(n),n.addObserver(o=>{s.delete(n);let r=!l;l=!0,i(o),r&&t?.onWinner&&t.onWinner({fiber:n,index:e,parentFiber:a})})}})}),tA=(0,v.XY)(e=>(0,V.yw)(e[1]),(e,t,a)=>tB([e,t],a)),tP=(0,v.XY)(e=>(0,V.yw)(e[1]),(e,t,a)=>tS([e,t],a)),tV=(0,v.XY)(2,(e,t)=>new tu(e,tw,t)),tH=(0,v.XY)(2,(e,t)=>tq(e)?"Success"===e._tag?t.onSuccess(e.value):t.onFailure(e.cause):aQ(e,t)),tq=e=>void 0!==e[V.IH],tF=(0,v.XY)(2,(e,t)=>tq(e)?"Success"===e._tag?t(e.value):e:tV(e,t)),tI=e=>tV(e,v.D_),tE=(0,v.XY)(2,(e,t)=>new tu(e,ty,t)),tO=(0,v.XY)(2,(e,t)=>tq(e)?t0(e,t):tE(e,t)),tU=(0,v.XY)(2,(e,t)=>tq(e)?t2(e,t):a$(e,t)),tX=(0,v.XY)(2,(e,t)=>tq(e)?t3(e,t):aG(e,t)),tT=(0,v.XY)(2,(e,t)=>{if(tq(e)){if("Success"===e._tag)return e;let a=R(e.cause);return x.N6(a)?e:t(a.success)}return aL(e,t)}),tY=e=>(0,V.cb)($(e)),t$=e=>"Success"===e._tag,tG=e=>"Success"===e._tag?x.Py(e):x.fJ(e),tD=e=>"Success"===e._tag?x.Py(e.value):x.fJ(e),tR=e=>"Failure"===e._tag,tZ=e=>"Failure"===e._tag?x.Py(e):x.fJ(e),tj=e=>"Failure"===e._tag?x.Py(e.cause):x.fJ(e),tN=b(tj,R),tW=b(tj,W),tJ=e=>"Failure"===e._tag&&J(e.cause),tK=e=>"Failure"===e._tag&&j(e.cause),tQ=e=>"Failure"===e._tag&&G(e.cause),t1=(0,V.xt)(void 0),t0=(0,v.XY)(2,(e,t)=>"Success"===e._tag?(0,V.xt)(t(e.value)):e),t2=(0,v.XY)(2,(e,t)=>{if("Success"===e._tag)return e;let a=R(e.cause);return x.N6(a)?e:(0,V.Rk)(t(a.success))}),t3=(0,v.XY)(2,(e,t)=>{if("Success"===e._tag)return(0,V.xt)(t.onSuccess(e.value));let a=R(e.cause);return x.N6(a)?e:(0,V.Rk)(t.onFailure(a.success))}),t5=(0,v.XY)(2,(e,t)=>t$(e)?(0,V.xt)(t):e),t4=(0,v.XY)(2,(e,t)=>t$(e)?t:e),t6=(0,v.XY)(2,(e,t)=>t$(e)?t.onSuccess(e.value):t.onFailure(e.cause)),t7=t5(void 0),t8=e=>{let t=[];for(let a of e)"Failure"===a._tag&&t.push(...a.cause.reasons);return 0===t.length?t1:(0,V.cb)((0,V.b5)(t))},t9=e=>t$(e)?y.some(e.value):y.none(),ae=e=>tR(e)?y.some(e.cause):y.none(),at=e=>{let t=tN(e);return x.N6(t)?y.none():y.some(t.success)},aa=e=>e,as=e=>(0,V.R6)(t=>eU(u.om(t.context,e))),ai=(0,v.XY)(2,(e,t)=>(0,V.R6)(a=>{let s=a.context,i=t(s);return s===i||(a.setContext(i),sE(a,()=>{a.setContext(s)})),e})),al=(0,v.XY)(3,(e,t,a)=>ai(e,e=>{let s=u.fp(e,t),i=a(s);return s===i?e:u.WQ(e,t,i)})),ao=(e,t,a)=>s1((0,V.R6)(s=>{let i=u.fp(s.context,e),l=t(i);return s.setContext(u.WQ(s.context,e,l)),sx(u.fp(s.context,sh),t=>{let o,r=u.om(s.context,e);if(y.isNone(r))return e0;let n=r.value;if(a?.reset===void 0){if(n!==l)return e0;o=i}else o=a.reset(i,l,n);return s.setContext(u.WQ(s.context,e,o)),e0})})),ar=()=>an,an=(0,V.R6)(e=>eU(e.context)),ac=e=>(0,V.R6)(t=>e(t.context)),ad=(0,v.XY)(2,(e,t)=>ai(e,(0,v.dY)(t))),ap=(0,v.XY)(2,(e,t)=>tq(e)?e:ai(e,u.h1(t))),ah=function(){return 1==arguments.length?(0,v.XY)(2,(e,t)=>ag(e,arguments[0],t)):(0,v.XY)(3,(e,t,a)=>ag(e,t,a)).apply(this,arguments)},ag=(e,t,a)=>ai(e,u.WQ(t,a)),au=(0,v.XY)(3,(e,t,a)=>tV(a,a=>ah(e,t,a))),af=(0,v.XY)(e=>(0,V.yw)(e[1]),(e,t,a)=>am(e,t,(e,t)=>[e,t],a)),am=(0,v.XY)(e=>(0,V.yw)(e[1]),(e,t,a,s)=>s?.concurrent?tE(ie([e,t],{concurrency:2}),([e,t])=>a(e,t)):tV(e,e=>tE(t,t=>a(e,t)))),av=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>iw(e,t,a?e=>eT(a(e)):()=>eT(new V.Xm))),ay=(0,v.XY)(2,(e,t)=>tV(t,t=>t?tk(e):eW)),aw=(0,v.XY)(2,(e,t)=>Array.from({length:t},()=>e)),ax=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>ie(aw(e,t),a)),ab=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>ic({while:v.ue,body:(0,v.dY)(t?.disableYield?e:tV(e,e=>ej)),step:v.Yi})),ak=(0,v.XY)(2,(e,t)=>new aC(e,1!==t.length?e=>t(e):t)),aM=(0,V.yj)({op:"OnFailure",[V._3]:th}),aC=function(e,t){this[V.a2]=e,this[V.Sc]=t};aC.prototype=aM;let az=(0,v.XY)(3,(e,t,a)=>ak(e,e=>t(e)?a(e):eX(e))),a_=(0,v.XY)(3,(e,t,a)=>ak(e,e=>{let s=t(e);return x.N6(s)?eX(s.failure):a(s.success,e)})),aL=(0,v.XY)(2,(e,t)=>a_(e,R,e=>t(e))),aB=e=>a7(e,{onFailure:e=>(0,V.PW)(e)?eW:eT(e),onSuccess:eN}),aS=(0,v.XY)(2,(e,t)=>a_(e,W,t)),aA=(0,v.XY)(2,(e,t)=>ak(e,e=>tC(t(e),eX(e)))),aP=(0,v.XY)(3,(e,t,a)=>az(e,t,e=>tC(a(e),eX(e)))),aV=(0,v.XY)(3,(e,t,a)=>ak(e,e=>{let s=t(e);return x.N6(s)?eX(e):tC(a(s.success,e),eX(e))})),aH=(0,v.XY)(2,(e,t)=>aV(e,R,e=>t(e))),aq=(0,v.XY)(3,(e,t,a)=>{let s=Array.isArray(t)?e=>(0,w.i5)(e,"_tag")&&t.includes(e._tag):(0,w.$J)(t);return aH(e,e=>s(e)?a(e):e0)}),aF=(0,v.XY)(2,(e,t)=>aV(e,W,e=>t(e))),aI=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s)=>ak(e,e=>{let i=R(e);return x.N6(i)?eX(i.failure):t(i.success)?a(i.success):s?s(i.success):eX(e)})),aE=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s)=>ak(e,e=>{let i=R(e);if(x.N6(i))return eX(i.failure);let l=t(i.success);return x.N6(l)?s?s(l.failure):eX(e):a(l.success)})),aO=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s)=>aI(e,Array.isArray(t)?e=>(0,w.i5)(e,"_tag")&&t.includes(e._tag):(0,w.$J)(t),a,s)),aU=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>{let s;return aE(e,e=>(s??=Object.keys(t),(0,w.i5)(e,"_tag")&&(0,w.Kg)(e._tag)&&s.includes(e._tag)?x.Py(e):x.fJ(e)),e=>t[e._tag](e),a)}),aX=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s,i)=>aI(e,e=>(0,w.$J)(e,t)&&(0,w.i5)(e,"reason")&&(void 0!==i||(0,w.$J)(e.reason,a)),e=>{let t=e.reason;return(0,w.$J)(t,a)?s(t,e):i?i(t,e):eT(e)})),aT=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a,s)=>{let i;return aI(e,e=>(0,w.$J)(e,t)&&(0,w.i5)(e,"reason")&&(0,w.i5)(e.reason,"_tag")&&(0,w.Kg)(e.reason._tag)&&(void 0!==s||(i??=Object.keys(a)).includes(e.reason._tag)),e=>{let t=e.reason;return(i??=Object.keys(a)).includes(t._tag)?a[t._tag](t,e):s?s(t,e):eT(e)})}),aY=(0,v.XY)(2,(e,t)=>aE(e,e=>(0,w.$J)(e,t)&&(0,w.i5)(e,"reason")?x.Py(e.reason):x.fJ(e),eT)),a$=(0,v.XY)(2,(e,t)=>aL(e,e=>e1(()=>t(e)))),aG=(0,v.XY)(2,(e,t)=>a7(e,{onFailure:e=>e1(()=>t.onFailure(e)),onSuccess:e=>eY(()=>t.onSuccess(e))})),aD=e=>aL(e,eQ),aR=(0,v.XY)(2,(e,t)=>aL(e,e=>eY(()=>t(e)))),aZ=e=>e$(()=>{let t=e[Symbol.iterator](),a=t.next();return a.done?eQ(Error("Received an empty collection of effects")):function e(a){let s=t.next();return s.done?a.value:aL(a.value,t=>e(s))}(a)}),aj=e=>aL(e,t=>tV(ej,()=>aj(e))),aN=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>{if(!t?.log)return a7(e,{onFailure:e=>e0,onSuccess:e=>e0});let a=lR(!0===t.log?void 0:t.log);return aQ(e,{onFailure(e){let s=D(e);return x.N6(s)?eX(s.failure):void 0===t.message?a(e):a(t.message,e)},onSuccess:e=>e0})}),aW=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>{if(!t?.log)return aQ(e,{onFailure:e=>e0,onSuccess:e=>e0});let a=lR(!0===t.log?void 0:t.log);return aQ(e,{onFailure:e=>void 0===t.message?a(e):a(t.message,e),onSuccess:e=>e0})}),aJ=e=>a8(e,{onFailure:y.none,onSuccess:y.some}),aK=e=>a9(e,{onFailure:x.fJ,onSuccess:x.Py}),aQ=(0,v.XY)(2,(e,t)=>new a0(e,1!==t.onSuccess.length?e=>t.onSuccess(e):t.onSuccess,1!==t.onFailure.length?e=>t.onFailure(e):t.onFailure)),a1=(0,V.yj)({op:"OnSuccessAndFailure",[V._3]:th}),a0=function(e,t,a){this[V.a2]=e,this[V.ee]=t,this[V.Sc]=a};a0.prototype=a1;let a2=function(e,t){let a=this.payload;return t.succeedWith(tv?a.onSuccess(e):(0,P.s)(()=>a.onSuccess(e)))},a3=(e,t)=>{let a=(0,V.yj)({op:e,[V._3]:th,[V.ee]:a2,[V.Sc]:t}),s=function(e,t){this[V.a2]=e,this.payload=t};return s.prototype=a,s},a5=a3("Match",function(e,t){let a=e.reasons.find(V.lC);if(void 0===a)return eX(e);let s=this.payload;return t.succeedWith(tv?s.onFailure(a.error):(0,P.s)(()=>s.onFailure(a.error)))}),a4=a3("MatchCause",function(e,t){let a=this.payload;return t.succeedWith(tv?a.onFailure(e):(0,P.s)(()=>a.onFailure(e)))}),a6=(0,v.XY)(2,(e,t)=>new a4(e,t)),a7=(0,v.XY)(2,(e,t)=>aQ(e,{onFailure:e=>{let a=e.reasons.find(V.lC);return a?t.onFailure(a.error):eX(e)},onSuccess:t.onSuccess})),a8=(0,v.XY)(2,(e,t)=>new a5(e,t)),a9=(0,v.XY)(2,(e,t)=>{if(tq(e)){if("Success"===e._tag)return(0,V.xt)(t.onSuccess(e.value));let a=R(e.cause);return x.N6(a)?e:(0,V.xt)(t.onFailure(a.success))}return a8(e,t)}),se=(0,v.XY)(2,(e,t)=>tq(e)?"Success"===e._tag?(0,V.xt)(t.onSuccess(e.value)):(0,V.xt)(t.onFailure(e.cause)):a6(e,t)),st=e=>tq(e)?(0,V.xt)(e):sa(e),sa=(0,V.Uf)({op:"Exit",[V._3](e){return e._stack.push(this),this[V.a2]},[V.ee]:(e,t,a)=>t.succeedWith(a??(0,V.xt)(e)),[V.Sc]:(e,t,a)=>t.succeedWith(a??(0,V.cb)(e))}),ss=a9({onFailure:()=>!0,onSuccess:()=>!1}),si=a9({onFailure:()=>!1,onSuccess:()=>!0}),sl=(0,v.XY)(2,(e,t)=>tC(ly(t),e)),so=(0,v.XY)(2,(e,t)=>tV(sn(e,t.duration),e=>y.isNone(e)?t.orElse():eU(e.value))),sr=(0,v.XY)(2,(e,t)=>{let a=f.bN(t);return so(e,{duration:a,orElse:()=>eT(new lC(`Operation timed out after '${f.GP(a)}'`))})}),sn=(0,v.XY)(2,(e,t)=>tP(tk(e),tp(ly(t),y.none()))),sc=e=>lv(t=>{let a=t.monotonicTimeNanosUnsafe();return tE(e,e=>[f.cF(t.monotonicTimeNanosUnsafe()-a),e])}),sd="~effect/Scope",sp="~effect/Scope/Closeable",sh=u.kl("effect/Scope"),sg=(e,t)=>(0,V.R6)(a=>{let s=su(e,t);return void 0===s?e0:(s4(a),s)}),su=(e,t)=>{let a=e.state;if("Closed"===a._tag||(e.state={_tag:"Closed",exit:t},void 0!==e.parent&&sM(e.parent,e),"Empty"===a._tag))return;if(void 0!==a.finalizer)return sf(a.finalizer,t);let s=a.finalizers;return 1===s.size?sf(s.values().next().value,t):sv(e,s,t)},sf=(e,t)=>{try{return e(t)}catch(e){return(0,V.V2)(e)}},sm=(e,t)=>t$(e)?t:ak(t,t=>eX((0,V.h2)(e.cause,t))),sv=ts(function*(e,t,a){let s=[],i=[],l=Array.from(t.values()),o=eM();for(let t=l.length-1;t>=0;t--){let r=l[t];"sequential"===e.strategy?s.push((yield*st(sf(r,a)))):i.push(iA(o,sf(r,a),!0,!0,"inherit"))}return i.length>0&&(s=yield*eV(i)),yield*t8(s)}),sy=(e,t)=>eY(()=>sw(e,t)),sw=(e,t)=>{let a=sz(t,e);return"Closed"===e.state._tag?a.state=e.state:sk(e,a,e=>sg(a,e)),a},sx=(e,t)=>e$(()=>"Closed"===e.state._tag?t(e.state.exit):(sk(e,{},t),e0)),sb=(e,t)=>sx(e,(0,v.dY)(t)),sk=(e,t,a)=>{if("Empty"===e.state._tag)e.state={_tag:"Open",finalizerKey:t,finalizer:a,finalizers:void 0};else if("Open"===e.state._tag){let s=e.state;void 0!==s.finalizer&&(s.finalizers=new Map([[s.finalizerKey,s.finalizer]]),s.finalizerKey=void 0,s.finalizer=void 0),s.finalizers.set(t,a)}},sM=(e,t)=>{if("Open"!==e.state._tag)return;let a=e.state;a.finalizerKey===t?e.state=s_:void 0!==a.finalizers&&(a.finalizers.delete(t),0===a.finalizers.size&&(e.state=s_))},sC=e=>sz(e,void 0),sz=(e="sequential",t)=>({[sp]:sp,[sd]:sd,strategy:e,parent:t,state:s_}),s_={_tag:"Empty"},sL=e=>eY(()=>sC(e)),sB=sh,sS=ah(sh),sA=e=>(0,V.R6)(t=>{let a=t.context,s=sC();return t.setContext(u.WQ(t.context,sh,s)),sE(t,e=>(t.setContext(a),su(s,e))),e}),sP=(0,v.XY)(2,(e,t)=>sO(sS(e,t),e=>e$(()=>su(t,e)??e0))),sV=e=>e$(()=>{let t=sC();return sO(e(t),e=>e$(()=>su(t,e)??e0))}),sH=(e,t,a)=>ac(s=>s7(i=>tV(sB,l=>tz(a?.interruptible?i(e):e,e=>sx(l,a=>ap(t(e,a),s)))))),sq=e=>tV(sB,t=>ac(a=>sx(t,t=>ap(e(t),a)))),sF=(n=(0,V.yj)({op:"OnExit",[V._3](e){return e._stack.push(this),this.effect},[V.u4](e){e.interruptible&&!0!==this.interruptible&&(e._stack.push(s2),e.interruptible=!1)},[V.ee](e,t,a){let s;a??=(0,V.xt)(e);try{s=this.onExit(a)}catch(e){s=(0,V.V2)(e)}return s?tV(s,e=>a):a},[V.Sc](e,t,a){let s;a??=(0,V.cb)(e);try{s=this.onExit(a)}catch(e){s=(0,V.V2)(e)}return s?tV(sm(a,s),e=>a):a}}),(c=function(e,t,a){this.effect=e,this.onExit=t,this.interruptible=a}).prototype=n,c),sI=(e,t,a)=>new sF(e,t,a),sE=(e,t)=>{e._stack.push(new sF(void 0,t,void 0))},sO=(0,v.XY)(2,sI),sU=(0,v.XY)(2,(e,t)=>sO(e,e=>t)),sX=(0,v.XY)(3,(e,t,a)=>sO(e,e=>t(e)?a(e):e0)),sT=(0,v.XY)(3,(e,t,a)=>sO(e,e=>{let s=t(e);return x.N6(s)?e0:a(s.success,e)})),sY=(0,v.XY)(2,(e,t)=>sT(e,tj,t)),s$=(0,v.XY)(3,(e,t,a)=>sX(e,e=>"Failure"===e._tag&&t(e.cause),e=>a(e.cause))),sG=(0,v.XY)(3,(e,t,a)=>sO(e,e=>{if("Failure"!==e._tag)return e0;let s=t(e.cause);return x.N6(s)?e0:a(s.success,e.cause)})),sD=(0,v.XY)(2,(e,t)=>sG(Q,t)(e)),sR=(e,t,a)=>s7(s=>tV(e,e=>sI(e$(()=>s(t(e))),t=>a(e,t),!0))),sZ=e=>sH(e,e=>(0,w.i5)(e,Symbol.asyncDispose)?e3(()=>e[Symbol.asyncDispose]()):eY(()=>e[Symbol.dispose]())),sj=(0,v.XY)(2,(e,t)=>eY(()=>sW(e,"function"==typeof t?e=>f.kE(f.bN(t(e))):(0,v.dY)(f.kE(f.bN(t)))))),sN=(0,v.dY)(1/0),sW=(e,t)=>{let a,s,i=0,l=(e,t)=>(t.awaiters++,sE(e,()=>{if(!(--t.awaiters>0)&&s===t)return s=void 0,eF(t.fiber)}),eH(t.fiber));return[(0,V.R6)(o=>{if(void 0!==s)return l(o,s);if(void 0!==a&&(1/0===i||o.getRef(lh).currentTimeMillisUnsafe()<i))return a;a=void 0;let r=o.getRef(lh),n={fiber:void 0,awaiters:0};return s=n,n.fiber=iA(o,sI(e,e=>{if(s!==n||(s=void 0,tJ(e)))return;let l=t(e);i=1/0===l?1/0:r.currentTimeMillisUnsafe()+l,a=e}),!0,!0),n.fiber._exit??l(o,n)}),eY(()=>{a=void 0})]},sJ=(0,v.XY)(2,(e,t)=>tE(sj(e,t),e=>e[0])),sK=e=>eY(()=>sW(e,sN)[0]),sQ=(0,V.R6)(e=>eX($(e.id))),s1=e=>(0,V.R6)(t=>(t.interruptible&&(t.interruptible=!1,t._stack.push(s2)),e)),s0=(0,V.Uf)({op:"SetInterruptible",[V.u4](e){if(e.interruptible=this[V.a2],e._interruptedCause&&e.interruptible)return()=>eX(e._interruptedCause)}}),s2=s0(!0),s3=s0(!1),s5=e=>{if(e.interruptible=!0,e._stack.push(s3),e._interruptedCause)return eX(e._interruptedCause)},s4=e=>{e.interruptible&&(e.interruptible=!1,e._stack.push(s2))},s6=e=>(0,V.R6)(t=>t.interruptible?e:s5(t)??e),s7=e=>(0,V.R6)(t=>t.interruptible?(t.interruptible=!1,t._stack.push(s2),e(s6)):e(v.D_)),s8=e=>(0,V.R6)(t=>{if(t.interruptible)return e(v.D_);let a=s5(t),s=e(s1);return a??s}),s9=tE(sH(eY(()=>new AbortController),e=>eY(()=>e.abort())),e=>e.signal),ie=(e,t)=>(0,w.xZ)(e)?t?.mode==="result"?id(e,aK,t):id(e,v.D_,t):t?.discard?"result"===t.mode?id(Object.values(e),aK,t):id(Object.values(e),v.D_,t):e$(()=>{let a={};return tp(id(Object.entries(e),([e,s])=>tE(t?.mode==="result"?aK(s):s,t=>{F.x(a,e,t)}),{discard:!0,concurrency:t?.concurrency}),a)}),it=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t,a)=>tE(id(e,(e,a)=>aK(t(e,a)),a),e=>g.jB(e,v.D_))),ia=(0,v.XY)(3,(e,t,a)=>{let s=g.Ts(e);return 0===s.length?eY(t):e$(()=>{let e=0,i=t();return tE(ic({while:()=>e<s.length,body:()=>a(i,s[e],e),step(t){i=t,e++}}),()=>i)})}),is=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t,a)=>tV(it(e,t,{concurrency:a?.concurrency}),([e,t])=>g.CZ(t)?eT(t):a?.discard?e0:eU(e))),ii=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t)=>e$(()=>{let a=e[Symbol.iterator](),s=a.next();return s.done?eU(y.none()):il(a,0,t,s.value)})),il=(e,t,a,s)=>tV(a(s,t),i=>{if(i)return eU(y.some(s));let l=e.next();return l.done?eU(y.none()):il(e,t+1,a,l.value)}),io=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t)=>e$(()=>{let a=e[Symbol.iterator](),s=a.next();return s.done?eU(y.none()):ir(a,0,t,s.value)})),ir=(e,t,a,s)=>tV(a(s,t),s=>{if(x.oJ(s))return eU(y.some(s.success));let i=e.next();return i.done?eU(y.none()):ir(e,t+1,a,i.value)}),ic=(0,V.Uf)({op:"While",[V.ee](e,t){return(this[V.a2].step(e),this[V.a2].while())?(t._stack.push(this),this[V.a2].body()):t1},[V._3](e){return this[V.a2].while()?(e._stack.push(this),this[V.a2].body()):t1}}),id=(0,v.XY)(e=>"function"==typeof e[1],(e,t,a)=>e$(()=>{let s=ig(a?.concurrency);if(1===s)return ih(e,t,a);let i=g.Ts(e),l=i.length;if(0===l)return a?.discard?e0:eU([]);let o=a?.discard?void 0:Array(l),r=iy({f:t,out:o},i,{concurrency:s});return r?tp(r,o):eU(o)})),ip=e=>tV(e,e=>{let t=e[Symbol.iterator]().next();return t.done?eT(new V.Xm):eU(t.value)}),ih=(e,t,a)=>e$(()=>{let s=a?.discard?void 0:[],i=e[Symbol.iterator](),l=i.next(),o=0;return tp(ic({while:()=>!l.done,body:()=>t(l.value,o++),step:e=>{s&&s.push(e),l=i.next()}}),s)}),ig=e=>"unbounded"===e?1/0:Math.max(1,e??1),iu=()=>e=>{let t=e.onItem,a=e.step,s=(e,t,s,l,o)=>tV(st(o),o=>a(e,t[s],o,s)??i(e,t,s+1,l)??e0),i=(e,i,l=0,o=i.length)=>{for(;l<o;l++){let r=i[l],n=t(e,r,l);if(!tq(n))return s(e,i,l,o,n);let c=a(e,r,n,l);if(c)return"Failure"===c._tag?c:void 0}};return i},im=e=>{let t=e.onItem,a=e.step;return(e,s,i)=>{let l,o,r,n,c,d=0,p=i.end??s.length,h=i.concurrency,g=!1,u=e=>{let t=(0,V.V2)(e);return n=t,g=!0,o&&o.size>0?tV(s1(eE(Array.from(o))),()=>n??t):t},f=()=>{let i=!1;for(;!n&&d<p;d++){let p=s[d],m=c??t(e,p,d);if(tq(m)){if(n=a(e,p,m,d))break}else{if(!l)return te(e=>{let t;l=eM(),o=new Set,c=m,r=e;try{t=f()}catch(t){return e(u(t))}return t?e(t):e$(()=>(n??=t1,tV(o?eE(o):e0,()=>n?._tag==="Failure"?n:e0)))});c=void 0;let t=iA(l,m,!0,!0,"inherit");if(t._exit){if(n=a(e,p,t._exit,d))break;continue}o.add(t);let s=d;if(t.addObserver(l=>{o.delete(t);try{if(n){if("Failure"===l._tag){let e=l.cause.reasons.filter(e=>"Interrupt"!==e._tag);if(e.length>0){let t=(0,V.b5)(e);n=(0,V.cb)("Failure"===n._tag?(0,V.h2)(n.cause,t):t)}}}else{let t=a(e,p,l,s);t&&(n=t,f())}if(i){let e=f();e&&r(e)}else g&&0===o.size&&r(n??e0)}catch(e){r(u(e))}}),o.size<h)continue;i=!0,d++;return}}if(g=!0,n){if(o&&o.size>0){let e=eS(l);o.forEach(t=>t.interruptUnsafe(l.id,e));return}if(r||"Failure"===n._tag)return n}else if(r)if(!o)return t1;else 0===o.size&&r(e0)};return f()}},iv=()=>e=>im(e),iy=im({onItem:(e,t,a)=>e.f(t,a),step(e,t,a,s){if("Failure"===a._tag)return a;e.out&&(e.out[s]=a.value)}}),iw=(0,v.XY)(3,(e,t,a)=>tV(e,e=>t(e)?eU(e):a(e))),ix=(0,v.XY)(3,(e,t,a)=>tV(e,e=>{let s=t(e);return x.N6(s)?a(s.failure):eU(s.success)})),ib=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>ix(e,t,a?e=>eT(a(e)):()=>eT(new V.Xm))),ik=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t,a)=>e$(()=>{let s=[];return tp(id(e,(e,a)=>{let i=t(e,a);return"boolean"==typeof i?(i&&s.push(e),e0):tE(i,t=>{t&&s.push(e)})},{discard:!0,concurrency:a?.concurrency}),s)})),iM=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t)=>e$(()=>{let a=[];for(let s of e){let e=t(s);x.oJ(e)&&a.push(e.success)}return eU(a)})),iC=(0,v.XY)(e=>(0,w.xZ)(e[0])&&!(0,V.yw)(e[0]),(e,t,a)=>e$(()=>{let s=[];return tp(id(e,e=>tE(t(e),e=>{x.oJ(e)&&s.push(e.success)}),{discard:!0,concurrency:a?.concurrency}),s)})),iz=eU({}),i_=H.Jr(tE),iL=H.oI(tE,tV),iB=H.zM(tE),iS=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>(0,V.R6)(a=>(eB.interruptChildren??=eA,eU(iA(a,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),iA=(e,t,a=!1,s=!1,i=!1)=>{let l="inherit"===i?e.interruptible:!i,o=new eC(e.context,l);return a?o.evaluate(t):(o._asyncContext=ek(),e.currentDispatcher.scheduleTask(()=>o.evaluate(t),0)),s||o._exit||(e.children().add(o),o._parent=e),o},iP=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>(0,V.R6)(a=>eU(iA(a,e,t?.startImmediately,!0,t?.uninterruptible)))),iV=e=>(0,V.R6)(t=>{let a=t._children&&new Set(t._children),s=t.interruptible;return sI(e,e=>{let i=t._children;if(void 0===i||0===i.size)return e0;a&&(i=z.pb(i,e=>!a.has(e)));let l=t_(eV(i));return s?s6(l):l})}),iH=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a)=>(0,V.R6)(s=>{let i=iA(s,e,a?.startImmediately,!0,a?.uninterruptible);if(!i._exit)if("Closed"!==t.state._tag){let e={};sk(t,e,()=>e4(e=>e===i.id?e0:eF(i))),i.addObserver(()=>sM(t,e))}else i.interruptUnsafe(s.id,eS(s));return eU(i)})),iq=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>tV(sB,a=>iH(e,a,t))),iF=e=>(t,a)=>{let s=new eC(a?.scheduler?u.WQ(e,S._F,a.scheduler):e,a?.uninterruptible!==!0);if(s.evaluate(t),s._exit)return s;if(a?.signal)if(a.signal.aborted)s.interruptUnsafe();else{let e=()=>s.interruptUnsafe();a.signal.addEventListener("abort",e,{once:!0}),s.addObserver(()=>a.signal.removeEventListener("abort",e))}return a?.onFiberStart&&a.onFiberStart(s),s},iI=(0,v.XY)(2,(e,t)=>{if(e._exit)return e;if("Closed"===t.state._tag)return e.interruptUnsafe(e.id),e;let a={};return sk(t,a,()=>eF(e)),e.addObserver(()=>sM(t,a)),e}),iE=iF(u.Ie()),iO=e=>{let t=iF(e);return(e,a)=>{let s=t(e,a);return a?.onExit&&s.addObserver(a.onExit),e=>s.interruptUnsafe(e)}},iU=iO(u.Ie()),iX=e=>{let t=iF(e);return(e,a)=>{let s=t(e,a);return new Promise(e=>{s.addObserver(t=>e(t))})}},iT=iX(u.Ie()),iY=e=>{let t=iX(e);return(e,a)=>t(e,a).then(e=>{if("Failure"===e._tag)throw eo(e.cause);return e.value})},i$=iY(u.Ie()),iG=e=>{let t=iF(e);return e=>{if(tq(e))return e;let a=t(e,{scheduler:new S.FG("sync")});return a._dispatcher?.flush(),a._exit??(0,V.V2)(new lH(a))}},iD=iG(u.Ie()),iR=e=>{let t=iG(e);return e=>{let a=t(e);if("Failure"===a._tag)throw eo(a.cause);return a.value}},iZ=iR(u.Ie()),ij=eU(!0),iN=eU(!1);class iW{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(0===this.waiters.length)return ij;if(void 0===this.scheduled)this.scheduled=this.waiters,e.currentDispatcher.scheduleTask(this.flushScheduled,0);else for(let e=0;e<this.waiters.length;e++)this.scheduled.push(this.waiters[e]);return this.waiters=[],ij}flushScheduled=()=>{if(void 0===this.scheduled)return;let e=this.scheduled;this.scheduled=void 0;for(let t=0;t<e.length;t++)e[t](t1)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](t1)}open=(0,V.R6)(e=>this._isOpen?iN:(this._isOpen=!0,this.scheduleUnsafe(e)));release=(0,V.R6)(e=>this._isOpen?iN:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=te(e=>this._isOpen?e(e0):(this.waiters.push(e),eY(()=>{let t=this.waiters.indexOf(e);-1!==t?this.waiters.splice(t,1):void 0!==this.scheduled&&-1!==(t=this.scheduled.indexOf(e))&&this.scheduled.splice(t,1)})));closeUnsafe(){return!!this._isOpen&&(this._isOpen=!1,!0)}close=eY(()=>this.closeUnsafe());whenOpen=e=>tV(this.await,()=>e);isOpen(){return this._isOpen}}let iJ=e=>new iW(e??!1),iK=e=>eY(()=>iJ(e)),iQ=(0,V.R6)(e=>eU(e.getRef(A.sh))),i1=(0,v.XY)(2,(e,t)=>ah(e,A.sh,t)),i0=ah(I.rf),i2=ah(I.nU),i3=BigInt(0),i5={_tag:"Span",spanId:"noop",traceId:"noop",sampled:!1,status:{_tag:"Ended",startTime:i3,endTime:i3,exit:t1},attributes:new Map,links:[],kind:"internal",attribute(){},event(){},end(){},addLinks(){}},i4=e=>e?u.Jt(e.annotations,A.DW)?"Span"===e._tag?i4(y.getOrUndefined(e.parent)):y.none():y.some(e):y.none(),i6=(e,t,a)=>{let s,i=!e.cache.tracerEnabled||a?.annotations&&u.Jt(a.annotations,A.DW),l=a?.parent!==void 0?y.some(a.parent):a?.root?y.none():i4(e.cache.span);if(i){let e;e={name:t,parent:l,annotations:u.WQ(a?.annotations??u.Ie(),A.DW,!0)},s=Object.assign(Object.create(i5),e)}else{let i=e.cache.tracer??A.Vv,o=e.getRef(lh),r=e.getRef(I.nU),n=e.getRef(I.ce),c=e.getRef(I.ls),d=a?.level??e.getRef(A.pX),p=a?.links!==void 0?[...c,...a.links]:0===c.length?[]:c.slice();for(let c in s=i.span({name:t,parent:l,annotations:a?.annotations??u.Ie(),links:p,startTime:r?o.currentTimeNanosUnsafe():i3,kind:a?.kind??"internal",root:a?.root??y.isNone(l),sampled:a?.sampled??((!y.isSome(l)||!1!==l.value.sampled)&&!lU(e.getRef(A.EW),d))}),n)s.attribute(c,n[c]);if(a?.attributes!==void 0)for(let e in a.attributes)s.attribute(e,a.attributes[e])}return s},i7=(e,t)=>(0,V.R6)(a=>eU(i6(a,e,t))),i8=(e,t)=>s1((0,V.R6)(a=>{let s=u.fp(a.context,sh),i=i6(a,e,t??{}),l=a.getRef(lh),o=a.getRef(I.nU);return tp(sx(s,e=>ls(i,e,l,o)),i)})),i9=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],a=O(e?arguments[2]:arguments[1]);if(e){let e=arguments[0];return tV(i8(t,a),t=>lo(e,t,a))}return e=>tV(i8(t,a),t=>lo(e,t,a))},le=I.ce,lt=I.ls,la=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t,a={})=>{let s=(Array.isArray(t)?t:[t]).map(e=>({span:e,attributes:a}));return al(e,I.ls,e=>[...e,...s])}),ls=(e,t,a,s)=>eY(()=>{"Ended"!==e.status._tag&&e.end(s?a.currentTimeNanosUnsafe():i3,t)}),li=(e,...t)=>{let a=1===t.length?void 0:t[0],s=t[t.length-1];return(0,V.R6)(t=>{let i=i6(t,e,a),l=t.getRef(lh),o=t.getRef(I.nU);return sE(t,e=>ls(i,e,l,o)),s(i)})},ll=ah(A.Tv),lo=function(){let e=(0,V.yw)(arguments[0]),t=e?arguments[1]:arguments[0],a=e?arguments[2]:arguments[1],s=v.D_;if("Span"===t._tag){var i,l;a=O(a),i=t.name,l="function"==typeof(l=a?.captureStackTrace)?l:v.MN,s=al(I.vA,e=>({name:i,stack:l,parent:e}))}return e?ll(s(arguments[0]),t):e=>ll(s(e),t)},lr=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],a=O(arguments[2]);if(e){let e=arguments[0];return li(t,arguments[2],t=>lo(e,t,a))}let s="function"==typeof arguments[1]?arguments[1]:void 0,i=s?void 0:arguments[1];return(e,...l)=>li(t,s?s(...l):i,t=>lo(e,t,a))},ln=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,...t)=>al(e,I.ce,e=>{let a=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||F.x(a,t[0],t[1]),a})),lc=(...e)=>(0,V.R6)(t=>{let a=t.currentSpanLocal;if(a)if(1===e.length)for(let[t,s]of Object.entries(e[0]))a.attribute(t,s);else a.attribute(e[0],e[1]);return e0}),ld=(0,V.R6)(e=>{let t=e.currentSpanLocal;return t?eU(t):eT(new V.Xm)}),lp=(d=A.Tv,(0,V.R6)(e=>eG(u.om(e.context,d)))),lh=u.Or("effect/Clock",{defaultValue:()=>new lg});class lg{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=eY(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return lm()}currentTimeNanos=eY(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return lf()}monotonicTimeNanos=eY(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(f.kE(e))}sleepMillis(e){return e<=0?ej:Number.isFinite(e)?te(t=>{let a=e>0x7fffffff?this.sleepMillis(e-0x7fffffff):e0,s=setTimeout(()=>t(a),Math.min(e,0x7fffffff));return eY(()=>clearTimeout(s))}):tt}}let lu=BigInt(1e6),lf=function(){let e=globalThis.process?.hrtime;if("function"==typeof e?.bigint)return()=>e.bigint();if("u">typeof performance&&"function"==typeof performance.now)return()=>BigInt(Math.round(1e6*performance.now()));let t=BigInt(0);return()=>{let e=BigInt(Date.now())*lu;return e>t&&(t=e),t}}(),lm=(h=BigInt(1e9),()=>{let e=lf(),t=BigInt(Date.now())*lu;if(void 0===p)p=t-e;else{let a=p+e;(t>a?t-a:a-t)>h&&(p=t-e)}return p+e}),lv=e=>(0,V.R6)(t=>e(t.getRef(lh))),ly=e=>lv(t=>t.sleep(f.bN(e))),lw=lv(e=>e.currentTimeMillis),lx=lv(e=>e.currentTimeNanos),lb=lv(e=>e.monotonicTimeNanos),lk="~effect/Cause/TimeoutError",lM=e=>(0,w.i5)(e,lk);class lC extends(0,V.rN)("TimeoutError"){[lk]=lk;constructor(e){super({message:e})}}let lz="~effect/Cause/IllegalArgumentError",l_=e=>(0,w.i5)(e,lz);class lL extends(0,V.rN)("IllegalArgumentError"){[lz]=lz;constructor(e){super({message:e})}}let lB="~effect/Cause/ExceededCapacityError",lS=e=>(0,w.i5)(e,lB);class lA extends(0,V.rN)("ExceededCapacityError"){[lB]=lB;constructor(e){super({message:e})}}let lP="~effect/Cause/AsyncFiberError",lV=e=>(0,w.i5)(e,lP);class lH extends(0,V.rN)("AsyncFiberError"){[lP]=lP;constructor(e){super({message:"An asynchronous Effect was executed with Effect.runSync",fiber:e})}}let lq="~effect/Cause/UnknownError",lF=e=>(0,w.i5)(e,lq);class lI extends(0,V.rN)("UnknownError"){[lq]=lq;constructor(e,t){super({message:t,cause:e})}}let lE=u.Or("effect/Console",{defaultValue:()=>globalThis.console}),lO=_.zQ(_.wN,e=>{switch(e){case"All":return Number.MIN_SAFE_INTEGER;case"Fatal":return 5e4;case"Error":return 4e4;case"Warn":return 3e4;case"Info":return 2e4;case"Debug":return 1e4;case"Trace":return 0;case"None":return Number.MAX_SAFE_INTEGER}}),lU=_.yJ(lO),lX=u.Or("effect/Logger/CurrentLoggers",{defaultValue:()=>new Set([lZ,lj])}),lT=u.Or("effect/Logger/LogToStderr",{defaultValue:v.f4}),lY=function(){let e="string"==typeof arguments[0]?[[arguments[0],arguments[1]]]:Object.entries(arguments[0]);return s1((0,V.R6)(t=>{let a=t.getRef(I.iL),s={...a};for(let t=0;t<e.length;t++){let[a,i]=e[t];F.x(s,a,i)}return t.setContext(u.WQ(t.context,I.iL,s)),sx(u.fp(t.context,sh),s=>{let i=t.getRef(I.iL),l={...i};for(let t=0;t<e.length;t++){let[s,o]=e[t];(i[s]===o||Object.is(i[s],o))&&(Object.hasOwn(a,s)?F.x(l,s,a[s]):delete l[s])}return t.setContext(u.WQ(t.context,I.iL,l)),e0})}))},l$={"~effect/Logger":{_Message:v.D_,_Output:v.D_},pipe(){return(0,L.tT)(this,arguments)}},lG=e=>{let t=Object.create(l$);return t.log=e,t},lD=(e,t)=>{let a=e[0].replace(/[\s="]/g,"_");return`${a}=${t-e[1]}ms`},lR=e=>(...t)=>{let a;for(let e=0,s=t.length;e<s;e++){let s=t[e];(0,V.Aj)(s)&&(a?t.splice(e,1):t=t.slice(0,e).concat(t.slice(e+1)),a=a?(0,V.b5)(a.reasons.concat(s.reasons)):s,e--)}return void 0===a&&(a=V.DH),(0,V.R6)(s=>{let i=e??s.cache.logLevel;if(lU(s.cache.minimumLogLevel,i))return e0;let l=s.getRef(lh),o=s.getRef(lX);if(o.size>0){let e=new Date(l.currentTimeMillisUnsafe());for(let l of o)l.log({cause:a,fiber:s,date:e,logLevel:i,message:t})}return e0})},lZ=lG(({cause:e,date:t,fiber:a,logLevel:s,message:i})=>{let l=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&l.push(ef(e));let o=t.getTime(),r=a.getRef(I.d8),n="";for(let e of r)n+=` ${lD(e,o)}`;let c=a.getRef(I.iL);Object.keys(c).length>0&&l.push(c);let d=a.getRef(lE);(a.getRef(lT)?d.error:d.log)(`[${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}] ${s.toUpperCase()} (#${a.id})${n}:`,...l)}),lj=lG(({cause:e,fiber:t,logLevel:a,message:s})=>{let i=t.getRef(lh),l=t.getRef(I.iL),o=t.cache.span;if(void 0===o||"ExternalSpan"===o._tag)return;let r={};for(let[e,t]of Object.entries(l))F.x(r,e,t);r["effect.fiberId"]=t.id,r["effect.logLevel"]=a.toUpperCase(),e.reasons.length>0&&(r["effect.cause"]=ef(e)),o.event((0,C.ZK)(Array.isArray(s)&&1===s.length?s[0]:s),i.currentTimeNanosUnsafe(),r)}),lN=eU(void 0),lW=(0,v.XY)(e=>(0,V.yw)(e[0]),(e,t)=>sY(e,e=>(0,V.R6)(a=>(lJ(a,e,t?.defectsOnly),e0)))),lJ=(e,t,a)=>{let s=e.getRef(I.oQ);if(0===s.size||a&&!j(t))return;let i={cause:t,fiber:e,timestamp:e.getRef(lh).currentTimeNanosUnsafe()};s.forEach(e=>e.report(i))}},5844(e,t,a){let s=new WeakSet;a.d(t,{},{J3:s,Xp:e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;e instanceof Error&&t.delete("stack");let a=Object.getPrototypeOf(e),s=a;for(;null!==s&&s!==Object.prototype;){let e=Reflect.ownKeys(s);for(let a=0;a<e.length;a++)t.add(e[a]);s=Object.getPrototypeOf(s)}return t.has("constructor")&&"function"==typeof e.constructor&&a===e.constructor.prototype&&t.delete("constructor"),t},j:e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength)})},7258(e,t,a){a.d(t,{},{F:"effect/Metric/FiberRuntimeMetrics"})},7731(e,t,a){var s=a(3332),i=a(1958),l=a(5033),o=a(3952),r=a(4233),n=a(6481),c=a(2449);let d="~effect/Option",p={[d]:{_A:e=>e},...c.fU,[Symbol.iterator](){return new n.B(this)}},h=Object.defineProperty(Object.assign(Object.create(p),{_tag:"Some",_op:"Some",[s.HR](e){return f(e)&&v(e)&&s.aI(this.value,e.value)},[l.HR](){return l.kg(l.tW(this._tag))(l.tW(this.value))},toString(){return`some(${(0,i.GP)(this.value)})`},toJSON(){return{_id:"Option",_tag:this._tag,value:(0,o.aB)(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),g=l.tW("None"),u=Object.assign(Object.create(p),{_tag:"None",_op:"None",valueOrUndefined:void 0,[s.HR]:e=>f(e)&&m(e),[l.HR]:()=>g,toString:()=>"none()",toJSON(){return{_id:"Option",_tag:this._tag}}}),f=e=>(0,r.i5)(e,d),m=e=>"None"===e._tag,v=e=>"Some"===e._tag,y=Object.create(u),w=function(e){this.value=e};w.prototype=h,a.d(t,{},{$I:m,Ru:v,dv:y,oL:f,zN:e=>new w(e)})},2275(e,t,a){function s(e,t,a){"__proto__"===t?Object.defineProperty(e,t,{value:a,writable:!0,enumerable:!0,configurable:!0}):e[t]=a}function i(e,t){for(let a of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,a)&&s(e,a,t[a])}a.d(t,{x:()=>s,z:()=>i})},6712(e,t,a){var s=a(1179),i=a(1594);let l=s.Or("effect/ErrorReporter/CurrentErrorReporters",{defaultValue:()=>new Set}),o=s.Or("effect/References/CurrentStackFrame",{fiberCached:!0,defaultValue:i.MN}),r=s.Or("effect/References/TracerEnabled",{fiberCached:!0,defaultValue:i.ue}),n=s.Or("effect/References/TracerTimingEnabled",{defaultValue:i.ue}),c=s.Or("effect/References/TracerSpanAnnotations",{defaultValue:()=>({})}),d=s.Or("effect/References/TracerSpanLinks",{defaultValue:()=>[]}),p=s.Or("effect/References/CurrentLogAnnotations",{defaultValue:()=>({})}),h=s.Or("effect/References/CurrentLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),g=s.Or("effect/References/MinimumLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),u=s.Or("effect/References/UnhandledLogLevel",{defaultValue:()=>"Error"}),f=s.Or("effect/References/CurrentLogSpans",{defaultValue:()=>[]});a.d(t,{},{Gl:h,aG:u,ce:c,d8:f,iL:p,ls:d,nU:n,oQ:l,rf:r,vA:o,zQ:g})},2563(e,t,a){var s=a(3332),i=a(1958),l=a(1594),o=a(5033),r=a(3952),n=a(4233),c=a(6481),d=a(2449),p=a(7731);let h="~effect/Result",g={[h]:{_A:e=>e,_E:e=>e},...d.fU,[Symbol.iterator](){return new c.B(this)}},u=Object.assign(Object.create(g),{_tag:"Success",_op:"Success",[s.HR](e){return m(e)&&y(e)&&s.aI(this.success,e.success)},[o.HR](){return o.kg(o.tW(this._tag))(o.tW(this.success))},toString(){return`success(${(0,i.GP)(this.success)})`},toJSON(){return{_id:"Result",_tag:this._tag,value:(0,r.aB)(this.success)}}}),f=Object.assign(Object.create(g),{_tag:"Failure",_op:"Failure",[s.HR](e){return m(e)&&v(e)&&s.aI(this.failure,e.failure)},[o.HR](){return o.kg(o.tW(this._tag))(o.tW(this.failure))},toString(){return`failure(${(0,i.GP)(this.failure)})`},toJSON(){return{_id:"Result",_tag:this._tag,failure:(0,r.aB)(this.failure)}}}),m=e=>(0,n.i5)(e,h),v=e=>"Failure"===e._tag,y=e=>"Success"===e._tag,w=function(e){this.failure=e};w.prototype=f;let x=e=>new w(e),b=function(e){this.success=e};b.prototype=u;let k=e=>new b(e),M=(0,l.XY)(2,(e,t)=>p.$I(e)?x(t()):k(e.value));a.d(t,{},{L8:e=>y(e)?p.dv:p.zN(e.failure),N6:v,Oz:e=>v(e)?p.dv:p.zN(e.success),Py:k,aI:m,fJ:x,oJ:y,sV:M})},2840(e,t,a){var s=a(1594);function i(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function l(e){return t=>i(t)?.[e]}let o="~structural",r="~identifier",n="~sentinels",c=l("identifier"),d=l(r),p=l("title"),h=l("description"),g=(0,s.Bj)(e=>{let t=i(e)?.identifier;return"string"==typeof t?t:e.getExpected(g)}),u=new Set([n,o,"representation","arbitraryConstraint","toJsonSchema","toCode","toEquivalence","toFormatter","toCodec","toCodecJson","toCodecStringTree","toCodecIso","toCodecArbitrary"]);a.d(t,{hd:()=>i,ip:()=>l},{C3:o,CD:d,DQ:p,I_:n,KE:c,L1:["title","description","default","examples","readOnly","writeOnly","format","contentEncoding","contentMediaType","contentSchema"],Pk:h,R4:r,UI:u,bo:g,py:"~constructor"})},8253(e,t,a){var s=a(719),i=a(7086);function l(e){let t;for(let a of e.reasons){if(!s.lC(a)||!i.gh(a.error))return;t??=a.error}return t}function o(e,t){let a=l(e);if(void 0===a)throw Error(t,{cause:e});return a}a.d(t,{R:()=>l,q:()=>o})},587(e,t,a){var s=a(6526),i=a(1587);let l=Symbol(),o=s.Py,r=o(l),n=o(l);a.d(t,{},{LO:l,Py:o,Rr:n,e8:e=>"None"===e._tag?r:o(e.value),r2:r,zL:e=>e===l?i.none():i.some(e)})},5340(e,t,a){let s,i=void 0===(s=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"))?Object.isExtensible(Error):Object.hasOwn(s,"writable")?!0===s.writable:void 0!==s.set;a.d(t,{},{ft:e=>{i&&(Error.stackTraceLimit=e)},jt:()=>Error.stackTraceLimit})},8689(e,t,a){let s,i,l,o,r;function n(e){let t=e.length;for(;--t>=0;)e[t]=0}let c=573,d=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),p=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),h=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),g=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=Array(576);n(u);let f=Array(60);n(f);let m=Array(512);n(m);let v=Array(256);n(v);let y=Array(29);n(y);let w=Array(30);function x(e,t,a,s,i){this.static_tree=e,this.extra_bits=t,this.extra_base=a,this.elems=s,this.max_length=i,this.has_stree=e&&e.length}function b(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}n(w);let k=e=>e<256?m[e]:m[256+(e>>>7)],M=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},C=(e,t,a)=>{e.bi_valid>16-a?(e.bi_buf|=t<<e.bi_valid&65535,M(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=a-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=a)},z=(e,t,a)=>{C(e,a[2*t],a[2*t+1])},_=(e,t)=>{let a=0;do a|=1&e,e>>>=1,a<<=1;while(--t>0)return a>>>1},L=(e,t,a)=>{let s,i,l=Array(16),o=0;for(s=1;s<=15;s++)l[s]=o=o+a[s-1]<<1;for(i=0;i<=t;i++){let t=e[2*i+1];0!==t&&(e[2*i]=_(l[t]++,t))}},B=e=>{let t;for(t=0;t<286;t++)e.dyn_ltree[2*t]=0;for(t=0;t<30;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0},S=e=>{e.bi_valid>8?M(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},A=(e,t,a,s)=>{let i=2*t,l=2*a;return e[i]<e[l]||e[i]===e[l]&&s[t]<=s[a]},P=(e,t,a)=>{let s=e.heap[a],i=a<<1;for(;i<=e.heap_len&&(i<e.heap_len&&A(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!A(t,s,e.heap[i],e.depth));)e.heap[a]=e.heap[i],a=i,i<<=1;e.heap[a]=s},V=(e,t,a)=>{let s,i,l,o,r=0;if(0!==e.last_lit)do s=e.pending_buf[e.d_buf+2*r]<<8|e.pending_buf[e.d_buf+2*r+1],i=e.pending_buf[e.l_buf+r],r++,0===s?z(e,i,t):(z(e,(l=v[i])+256+1,t),0!==(o=d[l])&&C(e,i-=y[l],o),z(e,l=k(--s),a),0!==(o=p[l])&&C(e,s-=w[l],o));while(r<e.last_lit)z(e,256,t)},H=(e,t)=>{let a,s,i,l=t.dyn_tree,o=t.stat_desc.static_tree,r=t.stat_desc.has_stree,n=t.stat_desc.elems,d=-1;for(e.heap_len=0,e.heap_max=c,a=0;a<n;a++)0!==l[2*a]?(e.heap[++e.heap_len]=d=a,e.depth[a]=0):l[2*a+1]=0;for(;e.heap_len<2;)l[2*(i=e.heap[++e.heap_len]=d<2?++d:0)]=1,e.depth[i]=0,e.opt_len--,r&&(e.static_len-=o[2*i+1]);for(t.max_code=d,a=e.heap_len>>1;a>=1;a--)P(e,l,a);i=n;do a=e.heap[1],e.heap[1]=e.heap[e.heap_len--],P(e,l,1),s=e.heap[1],e.heap[--e.heap_max]=a,e.heap[--e.heap_max]=s,l[2*i]=l[2*a]+l[2*s],e.depth[i]=(e.depth[a]>=e.depth[s]?e.depth[a]:e.depth[s])+1,l[2*a+1]=l[2*s+1]=i,e.heap[1]=i++,P(e,l,1);while(e.heap_len>=2)e.heap[--e.heap_max]=e.heap[1],((e,t)=>{let a,s,i,l,o,r,n=t.dyn_tree,d=t.max_code,p=t.stat_desc.static_tree,h=t.stat_desc.has_stree,g=t.stat_desc.extra_bits,u=t.stat_desc.extra_base,f=t.stat_desc.max_length,m=0;for(l=0;l<=15;l++)e.bl_count[l]=0;for(n[2*e.heap[e.heap_max]+1]=0,a=e.heap_max+1;a<c;a++)(l=n[2*n[2*(s=e.heap[a])+1]+1]+1)>f&&(l=f,m++),n[2*s+1]=l,!(s>d)&&(e.bl_count[l]++,o=0,s>=u&&(o=g[s-u]),r=n[2*s],e.opt_len+=r*(l+o),h&&(e.static_len+=r*(p[2*s+1]+o)));if(0!==m){do{for(l=f-1;0===e.bl_count[l];)l--;e.bl_count[l]--,e.bl_count[l+1]+=2,e.bl_count[f]--,m-=2}while(m>0)for(l=f;0!==l;l--)for(s=e.bl_count[l];0!==s;)!((i=e.heap[--a])>d)&&(n[2*i+1]!==l&&(e.opt_len+=(l-n[2*i+1])*n[2*i],n[2*i+1]=l),s--)}})(e,t),L(l,d,e.bl_count)},q=(e,t,a)=>{let s,i,l=-1,o=t[1],r=0,n=7,c=4;for(0===o&&(n=138,c=3),t[(a+1)*2+1]=65535,s=0;s<=a;s++)i=o,o=t[(s+1)*2+1],++r<n&&i===o||(r<c?e.bl_tree[2*i]+=r:0!==i?(i!==l&&e.bl_tree[2*i]++,e.bl_tree[32]++):r<=10?e.bl_tree[34]++:e.bl_tree[36]++,r=0,l=i,0===o?(n=138,c=3):i===o?(n=6,c=3):(n=7,c=4))},F=(e,t,a)=>{let s,i,l=-1,o=t[1],r=0,n=7,c=4;for(0===o&&(n=138,c=3),s=0;s<=a;s++)if(i=o,o=t[(s+1)*2+1],!(++r<n)||i!==o){if(r<c)do z(e,i,e.bl_tree);while(0!=--r)else 0!==i?(i!==l&&(z(e,i,e.bl_tree),r--),z(e,16,e.bl_tree),C(e,r-3,2)):r<=10?(z(e,17,e.bl_tree),C(e,r-3,3)):(z(e,18,e.bl_tree),C(e,r-11,7));r=0,l=i,0===o?(n=138,c=3):i===o?(n=6,c=3):(n=7,c=4)}},I=!1,E=(e,t,a,s)=>{C(e,0+ +!!s,3),S(e),M(e,a),M(e,~a),e.pending_buf.set(e.window.subarray(t,t+a),e.pending),e.pending+=a};var O={_tr_init:e=>{I||((()=>{let e,t,a,o,r,n=Array(16);for(o=0,a=0;o<28;o++)for(y[o]=a,e=0;e<1<<d[o];e++)v[a++]=o;for(v[a-1]=o,r=0,o=0;o<16;o++)for(w[o]=r,e=0;e<1<<p[o];e++)m[r++]=o;for(r>>=7;o<30;o++)for(w[o]=r<<7,e=0;e<1<<p[o]-7;e++)m[256+r++]=o;for(t=0;t<=15;t++)n[t]=0;for(e=0;e<=143;)u[2*e+1]=8,e++,n[8]++;for(;e<=255;)u[2*e+1]=9,e++,n[9]++;for(;e<=279;)u[2*e+1]=7,e++,n[7]++;for(;e<=287;)u[2*e+1]=8,e++,n[8]++;for(L(u,287,n),e=0;e<30;e++)f[2*e+1]=5,f[2*e]=_(e,5);s=new x(u,d,257,286,15),i=new x(f,p,0,30,15),l=new x([],h,0,19,7)})(),I=!0),e.l_desc=new b(e.dyn_ltree,s),e.d_desc=new b(e.dyn_dtree,i),e.bl_desc=new b(e.bl_tree,l),e.bi_buf=0,e.bi_valid=0,B(e)},_tr_stored_block:E,_tr_flush_block:(e,t,a,s)=>{let i,l,o=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,a=0xf3ffc07f;for(t=0;t<=31;t++,a>>>=1)if(1&a&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<256;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),H(e,e.l_desc),H(e,e.d_desc),o=(e=>{let t;for(q(e,e.dyn_ltree,e.l_desc.max_code),q(e,e.dyn_dtree,e.d_desc.max_code),H(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*g[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),i=e.opt_len+3+7>>>3,(l=e.static_len+3+7>>>3)<=i&&(i=l)):i=l=a+5,a+4<=i&&-1!==t?E(e,t,a,s):4===e.strategy||l===i?(C(e,2+ +!!s,3),V(e,u,f)):(C(e,4+ +!!s,3),((e,t,a,s)=>{let i;for(C(e,t-257,5),C(e,a-1,5),C(e,s-4,4),i=0;i<s;i++)C(e,e.bl_tree[2*g[i]+1],3);F(e,e.dyn_ltree,t-1),F(e,e.dyn_dtree,a-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),V(e,e.dyn_ltree,e.dyn_dtree)),B(e),s&&S(e)},_tr_tally:(e,t,a)=>(e.pending_buf[e.d_buf+2*e.last_lit]=t>>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&a,e.last_lit++,0===t?e.dyn_ltree[2*a]++:(e.matches++,t--,e.dyn_ltree[(v[a]+256+1)*2]++,e.dyn_dtree[2*k(t)]++),e.last_lit===e.lit_bufsize-1),_tr_align:e=>{C(e,2,3),z(e,256,u),16===e.bi_valid?(M(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}},U=(e,t,a,s)=>{let i=65535&e,l=e>>>16&65535,o=0;for(;0!==a;){o=a>2e3?2e3:a,a-=o;do l=l+(i=i+t[s++]|0)|0;while(--o)i%=65521,l%=65521}return i|l<<16};let X=new Uint32Array((()=>{let e,t=[];for(var a=0;a<256;a++){e=a;for(var s=0;s<8;s++)e=1&e?0xedb88320^e>>>1:e>>>1;t[a]=e}return t})());var T=(e,t,a,s)=>{let i=s+a;e^=-1;for(let a=s;a<i;a++)e=e>>>8^X[(e^t[a])&255];return -1^e},Y={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},$={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};let{_tr_init:G,_tr_stored_block:D,_tr_flush_block:R,_tr_tally:Z,_tr_align:j}=O,{Z_NO_FLUSH:N,Z_PARTIAL_FLUSH:W,Z_FULL_FLUSH:J,Z_FINISH:K,Z_BLOCK:Q,Z_OK:ee,Z_STREAM_END:et,Z_STREAM_ERROR:ea,Z_DATA_ERROR:es,Z_BUF_ERROR:ei,Z_DEFAULT_COMPRESSION:el,Z_FILTERED:eo,Z_HUFFMAN_ONLY:er,Z_RLE:en,Z_FIXED:ec,Z_DEFAULT_STRATEGY:ed,Z_UNKNOWN:ep,Z_DEFLATED:eh}=$,eg=573,eu=(e,t)=>(e.msg=Y[t],t),ef=e=>(e<<1)-9*(e>4),em=e=>{let t=e.length;for(;--t>=0;)e[t]=0},ev=(e,t,a)=>(t<<e.hash_shift^a)&e.hash_mask,ey=e=>{let t=e.state,a=t.pending;a>e.avail_out&&(a=e.avail_out),0!==a&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+a),e.next_out),e.next_out+=a,t.pending_out+=a,e.total_out+=a,e.avail_out-=a,t.pending-=a,0===t.pending&&(t.pending_out=0))},ew=(e,t)=>{R(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ey(e.strm)},ex=(e,t)=>{e.pending_buf[e.pending++]=t},eb=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},ek=(e,t,a,s)=>{let i=e.avail_in;return(i>s&&(i=s),0===i)?0:(e.avail_in-=i,t.set(e.input.subarray(e.next_in,e.next_in+i),a),1===e.state.wrap?e.adler=U(e.adler,t,i,a):2===e.state.wrap&&(e.adler=T(e.adler,t,i,a)),e.next_in+=i,e.total_in+=i,i)},eM=(e,t)=>{let a,s,i=e.max_chain_length,l=e.strstart,o=e.prev_length,r=e.nice_match,n=e.strstart>e.w_size-262?e.strstart-(e.w_size-262):0,c=e.window,d=e.w_mask,p=e.prev,h=e.strstart+258,g=c[l+o-1],u=c[l+o];e.prev_length>=e.good_match&&(i>>=2),r>e.lookahead&&(r=e.lookahead);do{if(c[(a=t)+o]!==u||c[a+o-1]!==g||c[a]!==c[l]||c[++a]!==c[l+1])continue;l+=2,a++;do;while(c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&c[++l]===c[++a]&&l<h)if(s=258-(h-l),l=h-258,s>o){if(e.match_start=t,o=s,s>=r)break;g=c[l+o-1],u=c[l+o]}}while((t=p[t&d])>n&&0!=--i)return o<=e.lookahead?o:e.lookahead},eC=e=>{let t,a,s,i,l,o=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=o+(o-262)){e.window.set(e.window.subarray(o,o+o),0),e.match_start-=o,e.strstart-=o,e.block_start-=o,t=a=e.hash_size;do s=e.head[--t],e.head[t]=s>=o?s-o:0;while(--a)t=a=o;do s=e.prev[--t],e.prev[t]=s>=o?s-o:0;while(--a)i+=o}if(0===e.strm.avail_in)break;if(a=ek(e.strm,e.window,e.strstart+e.lookahead,i),e.lookahead+=a,e.lookahead+e.insert>=3)for(l=e.strstart-e.insert,e.ins_h=e.window[l],e.ins_h=ev(e,e.ins_h,e.window[l+1]);e.insert&&(e.ins_h=ev(e,e.ins_h,e.window[l+3-1]),e.prev[l&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=l,l++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<262&&0!==e.strm.avail_in)},ez=(e,t)=>{let a,s;for(;;){if(e.lookahead<262){if(eC(e),e.lookahead<262&&t===N)return 1;if(0===e.lookahead)break}if(a=0,e.lookahead>=3&&(e.ins_h=ev(e,e.ins_h,e.window[e.strstart+3-1]),a=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==a&&e.strstart-a<=e.w_size-262&&(e.match_length=eM(e,a)),e.match_length>=3)if(s=Z(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do e.strstart++,e.ins_h=ev(e,e.ins_h,e.window[e.strstart+3-1]),a=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(0!=--e.match_length)e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=ev(e,e.ins_h,e.window[e.strstart+1]);else s=Z(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(s&&(ew(e,!1),0===e.strm.avail_out))return 1}return(e.insert=e.strstart<2?e.strstart:2,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(ew(e,!1),0===e.strm.avail_out)?1:2},e_=(e,t)=>{let a,s,i;for(;;){if(e.lookahead<262){if(eC(e),e.lookahead<262&&t===N)return 1;if(0===e.lookahead)break}if(a=0,e.lookahead>=3&&(e.ins_h=ev(e,e.ins_h,e.window[e.strstart+3-1]),a=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==a&&e.prev_length<e.max_lazy_match&&e.strstart-a<=e.w_size-262&&(e.match_length=eM(e,a),e.match_length<=5&&(e.strategy===eo||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-3,s=Z(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=ev(e,e.ins_h,e.window[e.strstart+3-1]),a=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(0!=--e.prev_length)if(e.match_available=0,e.match_length=2,e.strstart++,s&&(ew(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if((s=Z(e,0,e.window[e.strstart-1]))&&ew(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return(e.match_available&&(s=Z(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(ew(e,!1),0===e.strm.avail_out)?1:2};function eL(e,t,a,s,i){this.good_length=e,this.max_lazy=t,this.nice_length=a,this.max_chain=s,this.func=i}let eB=[new eL(0,0,0,0,(e,t)=>{let a=65535;for(65535>e.pending_buf_size-5&&(a=e.pending_buf_size-5);;){if(e.lookahead<=1){if(eC(e),0===e.lookahead&&t===N)return 1;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;let s=e.block_start+a;if((0===e.strstart||e.strstart>=s)&&(e.lookahead=e.strstart-s,e.strstart=s,ew(e,!1),0===e.strm.avail_out)||e.strstart-e.block_start>=e.w_size-262&&(ew(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:(e.strstart>e.block_start&&(ew(e,!1),e.strm.avail_out),1)}),new eL(4,4,8,4,ez),new eL(4,5,16,8,ez),new eL(4,6,32,32,ez),new eL(4,4,16,16,e_),new eL(8,16,32,32,e_),new eL(8,16,128,128,e_),new eL(8,32,128,256,e_),new eL(32,128,258,1024,e_),new eL(32,258,258,4096,e_)];function eS(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=eh,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(2*eg),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),em(this.dyn_ltree),em(this.dyn_dtree),em(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),em(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),em(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var eA=(e,t)=>{let a,s;if(!e||!e.state||t>Q||t<0)return e?eu(e,ea):ea;let i=e.state;if(!e.output||!e.input&&0!==e.avail_in||666===i.status&&t!==K)return eu(e,0===e.avail_out?ei:ea);i.strm=e;let l=i.last_flush;if(i.last_flush=t,42===i.status)if(2===i.wrap)e.adler=0,ex(i,31),ex(i,139),ex(i,8),i.gzhead?(ex(i,+!!i.gzhead.text+2*!!i.gzhead.hcrc+4*!!i.gzhead.extra+8*!!i.gzhead.name+16*!!i.gzhead.comment),ex(i,255&i.gzhead.time),ex(i,i.gzhead.time>>8&255),ex(i,i.gzhead.time>>16&255),ex(i,i.gzhead.time>>24&255),ex(i,9===i.level?2:4*(i.strategy>=er||i.level<2)),ex(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(ex(i,255&i.gzhead.extra.length),ex(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=T(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(ex(i,0),ex(i,0),ex(i,0),ex(i,0),ex(i,0),ex(i,9===i.level?2:4*(i.strategy>=er||i.level<2)),ex(i,3),i.status=113);else{let t=eh+(i.w_bits-8<<4)<<8;t|=(i.strategy>=er||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(t|=32),t+=31-t%31,i.status=113,eb(i,t),0!==i.strstart&&(eb(i,e.adler>>>16),eb(i,65535&e.adler)),e.adler=1}if(69===i.status)if(i.gzhead.extra){for(a=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),ey(e),a=i.pending,i.pending!==i.pending_buf_size));)ex(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){a=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),ey(e),a=i.pending,i.pending===i.pending_buf_size)){s=1;break}s=i.gzindex<i.gzhead.name.length?255&i.gzhead.name.charCodeAt(i.gzindex++):0,ex(i,s)}while(0!==s)i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),0===s&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){a=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),ey(e),a=i.pending,i.pending===i.pending_buf_size)){s=1;break}s=i.gzindex<i.gzhead.comment.length?255&i.gzhead.comment.charCodeAt(i.gzindex++):0,ex(i,s)}while(0!==s)i.gzhead.hcrc&&i.pending>a&&(e.adler=T(e.adler,i.pending_buf,i.pending-a,a)),0===s&&(i.status=103)}else i.status=103;if(103===i.status&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&ey(e),i.pending+2<=i.pending_buf_size&&(ex(i,255&e.adler),ex(i,e.adler>>8&255),e.adler=0,i.status=113)):i.status=113),0!==i.pending){if(ey(e),0===e.avail_out)return i.last_flush=-1,ee}else if(0===e.avail_in&&ef(t)<=ef(l)&&t!==K)return eu(e,ei);if(666===i.status&&0!==e.avail_in)return eu(e,ei);if(0!==e.avail_in||0!==i.lookahead||t!==N&&666!==i.status){let a=i.strategy===er?((e,t)=>{let a;for(;;){if(0===e.lookahead&&(eC(e),0===e.lookahead)){if(t===N)return 1;break}if(e.match_length=0,a=Z(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,a&&(ew(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(ew(e,!1),0===e.strm.avail_out)?1:2})(i,t):i.strategy===en?((e,t)=>{let a,s,i,l,o=e.window;for(;;){if(e.lookahead<=258){if(eC(e),e.lookahead<=258&&t===N)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(s=o[i=e.strstart-1])===o[++i]&&s===o[++i]&&s===o[++i]){l=e.strstart+258;do;while(s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&s===o[++i]&&i<l)e.match_length=258-(l-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(a=Z(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(a=Z(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),a&&(ew(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===K)?(ew(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(ew(e,!1),0===e.strm.avail_out)?1:2})(i,t):eB[i.level].func(i,t);if((3===a||4===a)&&(i.status=666),1===a||3===a)return 0===e.avail_out&&(i.last_flush=-1),ee;if(2===a&&(t===W?j(i):t!==Q&&(D(i,0,0,!1),t===J&&(em(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),ey(e),0===e.avail_out))return i.last_flush=-1,ee}return t!==K?ee:i.wrap<=0?et:(2===i.wrap?(ex(i,255&e.adler),ex(i,e.adler>>8&255),ex(i,e.adler>>16&255),ex(i,e.adler>>24&255),ex(i,255&e.total_in),ex(i,e.total_in>>8&255),ex(i,e.total_in>>16&255),ex(i,e.total_in>>24&255)):(eb(i,e.adler>>>16),eb(i,65535&e.adler)),ey(e),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?ee:et)},eP=e=>{if(!e||!e.state)return ea;let t=e.state.status;return 42!==t&&69!==t&&73!==t&&91!==t&&103!==t&&113!==t&&666!==t?eu(e,ea):(e.state=null,113===t?eu(e,es):ee)};let eV=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var eH=function(e){let t=Array.prototype.slice.call(arguments,1);for(;t.length;){let a=t.shift();if(a){if("object"!=typeof a)throw TypeError(a+"must be non-object");for(let t in a)eV(a,t)&&(e[t]=a[t])}}return e},eq=e=>{let t=0;for(let a=0,s=e.length;a<s;a++)t+=e[a].length;let a=new Uint8Array(t);for(let t=0,s=0,i=e.length;t<i;t++){let i=e[t];a.set(i,s),s+=i.length}return a};let eF=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){eF=!1}let eI=new Uint8Array(256);for(let e=0;e<256;e++)eI[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;eI[254]=eI[254]=1;var eE=e=>{let t,a,s,i,l,o=e.length,r=0;for(i=0;i<o;i++)(64512&(a=e.charCodeAt(i)))==55296&&i+1<o&&(64512&(s=e.charCodeAt(i+1)))==56320&&(a=65536+(a-55296<<10)+(s-56320),i++),r+=a<128?1:a<2048?2:a<65536?3:4;for(t=new Uint8Array(r),l=0,i=0;l<r;i++)(64512&(a=e.charCodeAt(i)))==55296&&i+1<o&&(64512&(s=e.charCodeAt(i+1)))==56320&&(a=65536+(a-55296<<10)+(s-56320),i++),a<128?t[l++]=a:(a<2048?t[l++]=192|a>>>6:(a<65536?t[l++]=224|a>>>12:(t[l++]=240|a>>>18,t[l++]=128|a>>>12&63),t[l++]=128|a>>>6&63),t[l++]=128|63&a);return t},eO=(e,t)=>{let a,s,i=t||e.length,l=Array(2*i);for(s=0,a=0;a<i;){let t=e[a++];if(t<128){l[s++]=t;continue}let o=eI[t];if(o>4){l[s++]=65533,a+=o-1;continue}for(t&=2===o?31:3===o?15:7;o>1&&a<i;)t=t<<6|63&e[a++],o--;if(o>1){l[s++]=65533;continue}t<65536?l[s++]=t:(t-=65536,l[s++]=55296|t>>10&1023,l[s++]=56320|1023&t)}var o=s;if(o<65534&&l.subarray&&eF)return String.fromCharCode.apply(null,l.length===o?l:l.subarray(0,o));let r="";for(let e=0;e<o;e++)r+=String.fromCharCode(l[e]);return r},eU=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let a=t-1;for(;a>=0&&(192&e[a])==128;)a--;return a<0||0===a?t:a+eI[e[a]]>t?a:t},eX=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};let eT=Object.prototype.toString,{Z_NO_FLUSH:eY,Z_SYNC_FLUSH:e$,Z_FULL_FLUSH:eG,Z_FINISH:eD,Z_OK:eR,Z_STREAM_END:eZ,Z_DEFAULT_COMPRESSION:ej,Z_DEFAULT_STRATEGY:eN,Z_DEFLATED:eW}=$;function eJ(e){let t,a;this.options=eH({level:ej,method:eW,chunkSize:16384,windowBits:15,memLevel:8,strategy:eN},e||{});let s=this.options;s.raw&&s.windowBits>0?s.windowBits=-s.windowBits:s.gzip&&s.windowBits>0&&s.windowBits<16&&(s.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new eX,this.strm.avail_out=0;let i=((e,t,a,s,i,l)=>{var o,r;let n;if(!e)return ea;let c=1;if(t===el&&(t=6),s<0?(c=0,s=-s):s>15&&(c=2,s-=16),i<1||i>9||a!==eh||s<8||s>15||t<0||t>9||l<0||l>ec)return eu(e,ea);8===s&&(s=9);let d=new eS;return e.state=d,d.strm=e,d.wrap=c,d.gzhead=null,d.w_bits=s,d.w_size=1<<d.w_bits,d.w_mask=d.w_size-1,d.hash_bits=i+7,d.hash_size=1<<d.hash_bits,d.hash_mask=d.hash_size-1,d.hash_shift=~~((d.hash_bits+3-1)/3),d.window=new Uint8Array(2*d.w_size),d.head=new Uint16Array(d.hash_size),d.prev=new Uint16Array(d.w_size),d.lit_bufsize=1<<i+6,d.pending_buf_size=4*d.lit_bufsize,d.pending_buf=new Uint8Array(d.pending_buf_size),d.d_buf=+d.lit_bufsize,d.l_buf=3*d.lit_bufsize,d.level=t,d.strategy=l,d.method=a,(n=(e=>{if(!e||!e.state)return eu(e,ea);e.total_in=e.total_out=0,e.data_type=ep;let t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?42:113,e.adler=+(2!==t.wrap),t.last_flush=N,G(t),ee})(o=e))===ee&&((r=o.state).window_size=2*r.w_size,em(r.head),r.max_lazy_match=eB[r.level].max_lazy,r.good_match=eB[r.level].good_length,r.nice_match=eB[r.level].nice_length,r.max_chain_length=eB[r.level].max_chain,r.strstart=0,r.block_start=0,r.lookahead=0,r.insert=0,r.match_length=r.prev_length=2,r.match_available=0,r.ins_h=0),n})(this.strm,s.level,s.method,s.windowBits,s.memLevel,s.strategy);if(i!==eR)throw Error(Y[i]);if(s.header&&(t=this.strm,a=s.header,t&&t.state&&2===t.state.wrap&&(t.state.gzhead=a)),s.dictionary){let e;if(e="string"==typeof s.dictionary?eE(s.dictionary):"[object ArrayBuffer]"===eT.call(s.dictionary)?new Uint8Array(s.dictionary):s.dictionary,(i=((e,t)=>{let a=t.length;if(!e||!e.state)return ea;let s=e.state,i=s.wrap;if(2===i||1===i&&42!==s.status||s.lookahead)return ea;if(1===i&&(e.adler=U(e.adler,t,a,0)),s.wrap=0,a>=s.w_size){0===i&&(em(s.head),s.strstart=0,s.block_start=0,s.insert=0);let e=new Uint8Array(s.w_size);e.set(t.subarray(a-s.w_size,a),0),t=e,a=s.w_size}let l=e.avail_in,o=e.next_in,r=e.input;for(e.avail_in=a,e.next_in=0,e.input=t,eC(s);s.lookahead>=3;){let e=s.strstart,t=s.lookahead-2;do s.ins_h=ev(s,s.ins_h,s.window[e+3-1]),s.prev[e&s.w_mask]=s.head[s.ins_h],s.head[s.ins_h]=e,e++;while(--t)s.strstart=e,s.lookahead=2,eC(s)}return s.strstart+=s.lookahead,s.block_start=s.strstart,s.insert=s.lookahead,s.lookahead=0,s.match_length=s.prev_length=2,s.match_available=0,e.next_in=o,e.input=r,e.avail_in=l,s.wrap=i,ee})(this.strm,e))!==eR)throw Error(Y[i]);this._dict_set=!0}}function eK(e,t){let a=new eJ(t);if(a.push(e,!0),a.err)throw a.msg||Y[a.err];return a.result}eJ.prototype.push=function(e,t){let a,s,i=this.strm,l=this.options.chunkSize;if(this.ended)return!1;for(s=t===~~t?t:!0===t?eD:eY,"string"==typeof e?i.input=eE(e):"[object ArrayBuffer]"===eT.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){if(0===i.avail_out&&(i.output=new Uint8Array(l),i.next_out=0,i.avail_out=l),(s===e$||s===eG)&&i.avail_out<=6){this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;continue}if((a=eA(i,s))===eZ)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),a=eP(this.strm),this.onEnd(a),this.ended=!0,a===eR;if(0===i.avail_out){this.onData(i.output);continue}if(s>0&&i.next_out>0){this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;continue}if(0===i.avail_in)break}return!0},eJ.prototype.onData=function(e){this.chunks.push(e)},eJ.prototype.onEnd=function(e){e===eR&&(this.result=eq(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var eQ=function(e,t){let a,s,i,l,o,r,n,c,d,p,h,g,u,f,m,v,y,w,x,b,k,M,C,z,_=e.state;a=e.next_in,C=e.input,s=a+(e.avail_in-5),i=e.next_out,z=e.output,l=i-(t-e.avail_out),o=i+(e.avail_out-257),r=_.dmax,n=_.wsize,c=_.whave,d=_.wnext,p=_.window,h=_.hold,g=_.bits,u=_.lencode,f=_.distcode,m=(1<<_.lenbits)-1,v=(1<<_.distbits)-1;t:do for(g<15&&(h+=C[a++]<<g,g+=8,h+=C[a++]<<g,g+=8),y=u[h&m];;){if(h>>>=w=y>>>24,g-=w,0==(w=y>>>16&255))z[i++]=65535&y;else if(16&w)for(x=65535&y,(w&=15)&&(g<w&&(h+=C[a++]<<g,g+=8),x+=h&(1<<w)-1,h>>>=w,g-=w),g<15&&(h+=C[a++]<<g,g+=8,h+=C[a++]<<g,g+=8),y=f[h&v];;){if(h>>>=w=y>>>24,g-=w,16&(w=y>>>16&255)){if(b=65535&y,g<(w&=15)&&(h+=C[a++]<<g,(g+=8)<w&&(h+=C[a++]<<g,g+=8)),(b+=h&(1<<w)-1)>r){e.msg="invalid distance too far back",_.mode=30;break t}if(h>>>=w,g-=w,b>(w=i-l)){if((w=b-w)>c&&_.sane){e.msg="invalid distance too far back",_.mode=30;break t}if(k=0,M=p,0===d){if(k+=n-w,w<x){x-=w;do z[i++]=p[k++];while(--w)k=i-b,M=z}}else if(d<w){if(k+=n+d-w,(w-=d)<x){x-=w;do z[i++]=p[k++];while(--w)if(k=0,d<x){x-=w=d;do z[i++]=p[k++];while(--w)k=i-b,M=z}}}else if(k+=d-w,w<x){x-=w;do z[i++]=p[k++];while(--w)k=i-b,M=z}for(;x>2;)z[i++]=M[k++],z[i++]=M[k++],z[i++]=M[k++],x-=3;x&&(z[i++]=M[k++],x>1&&(z[i++]=M[k++]))}else{k=i-b;do z[i++]=z[k++],z[i++]=z[k++],z[i++]=z[k++],x-=3;while(x>2)x&&(z[i++]=z[k++],x>1&&(z[i++]=z[k++]))}}else if((64&w)==0){y=f[(65535&y)+(h&(1<<w)-1)];continue}else{e.msg="invalid distance code",_.mode=30;break t}break}else if((64&w)==0){y=u[(65535&y)+(h&(1<<w)-1)];continue}else if(32&w){_.mode=12;break t}else{e.msg="invalid literal/length code",_.mode=30;break t}break}while(a<s&&i<o)a-=x=g>>3,g-=x<<3,h&=(1<<g)-1,e.next_in=a,e.next_out=i,e.avail_in=a<s?5+(s-a):5-(a-s),e.avail_out=i<o?257+(o-i):257-(i-o),_.hold=h,_.bits=g};let e1=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),e0=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),e2=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),e3=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var e5=(e,t,a,s,i,l,o,r)=>{let n,c,d,p,h,g,u,f,m,v=r.bits,y=0,w=0,x=0,b=0,k=0,M=0,C=0,z=0,_=0,L=0,B=null,S=0,A=new Uint16Array(16),P=new Uint16Array(16),V=null,H=0;for(y=0;y<=15;y++)A[y]=0;for(w=0;w<s;w++)A[t[a+w]]++;for(k=v,b=15;b>=1&&0===A[b];b--);if(k>b&&(k=b),0===b)return i[l++]=0x1400000,i[l++]=0x1400000,r.bits=1,0;for(x=1;x<b&&0===A[x];x++);for(k<x&&(k=x),z=1,y=1;y<=15;y++)if(z<<=1,(z-=A[y])<0)return -1;if(z>0&&(0===e||1!==b))return -1;for(P[1]=0,y=1;y<15;y++)P[y+1]=P[y]+A[y];for(w=0;w<s;w++)0!==t[a+w]&&(o[P[t[a+w]]++]=w);if(0===e?(B=V=o,g=19):1===e?(B=e1,S-=257,V=e0,H-=257,g=256):(B=e2,V=e3,g=-1),L=0,w=0,y=x,h=l,M=k,C=0,d=-1,p=(_=1<<k)-1,1===e&&_>852||2===e&&_>592)return 1;for(;;){u=y-C,o[w]<g?(f=0,m=o[w]):o[w]>g?(f=V[H+o[w]],m=B[S+o[w]]):(f=96,m=0),n=1<<y-C,x=c=1<<M;do i[h+(L>>C)+(c-=n)]=u<<24|f<<16|m;while(0!==c)for(n=1<<y-1;L&n;)n>>=1;if(0!==n?(L&=n-1,L+=n):L=0,w++,0==--A[y]){if(y===b)break;y=t[a+o[w]]}if(y>k&&(L&p)!==d){for(0===C&&(C=k),h+=x,z=1<<(M=y-C);M+C<b&&!((z-=A[M+C])<=0);)M++,z<<=1;if(_+=1<<M,1===e&&_>852||2===e&&_>592)return 1;i[d=L&p]=k<<24|M<<16|h-l}}return 0!==L&&(i[h+L]=y-C<<24|4194304),r.bits=k,0};let{Z_FINISH:e4,Z_BLOCK:e6,Z_TREES:e7,Z_OK:e8,Z_STREAM_END:e9,Z_NEED_DICT:te,Z_STREAM_ERROR:tt,Z_DATA_ERROR:ta,Z_MEM_ERROR:ts,Z_BUF_ERROR:ti,Z_DEFLATED:tl}=$,to=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function tr(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}let tn=e=>{if(!e||!e.state)return tt;let t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,(e=>{if(!e||!e.state)return tt;let t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,e8})(e)},tc=!0,td=e=>{if(tc){o=new Int32Array(512),r=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(e5(1,e.lens,0,288,o,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;e5(2,e.lens,0,32,r,0,e.work,{bits:5}),tc=!1}e.lencode=o,e.lenbits=9,e.distcode=r,e.distbits=5},tp=(e,t,a,s)=>{let i,l=e.state;return null===l.window&&(l.wsize=1<<l.wbits,l.wnext=0,l.whave=0,l.window=new Uint8Array(l.wsize)),s>=l.wsize?(l.window.set(t.subarray(a-l.wsize,a),0),l.wnext=0,l.whave=l.wsize):((i=l.wsize-l.wnext)>s&&(i=s),l.window.set(t.subarray(a-s,a-s+i),l.wnext),(s-=i)?(l.window.set(t.subarray(a-s,a),0),l.wnext=s,l.whave=l.wsize):(l.wnext+=i,l.wnext===l.wsize&&(l.wnext=0),l.whave<l.wsize&&(l.whave+=i))),0};var th=(e,t)=>{let a,s,i,l,o,r,n,c,d,p,h,g,u,f,m,v,y,w,x,b,k,M,C,z,_=0,L=new Uint8Array(4),B=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return tt;12===(a=e.state).mode&&(a.mode=13),o=e.next_out,i=e.output,n=e.avail_out,l=e.next_in,s=e.input,r=e.avail_in,c=a.hold,d=a.bits,p=r,h=n,M=e8;a:for(;;)switch(a.mode){case 1:if(0===a.wrap){a.mode=13;break}for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(2&a.wrap&&35615===c){a.check=0,L[0]=255&c,L[1]=c>>>8&255,a.check=T(a.check,L,2,0),c=0,d=0,a.mode=2;break}if(a.flags=0,a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",a.mode=30;break}if((15&c)!==tl){e.msg="unknown compression method",a.mode=30;break}if(c>>>=4,d-=4,k=(15&c)+8,0===a.wbits)a.wbits=k;else if(k>a.wbits){e.msg="invalid window size",a.mode=30;break}a.dmax=1<<a.wbits,e.adler=a.check=1,a.mode=512&c?10:12,c=0,d=0;break;case 2:for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(a.flags=c,(255&a.flags)!==tl){e.msg="unknown compression method",a.mode=30;break}if(57344&a.flags){e.msg="unknown header flags set",a.mode=30;break}a.head&&(a.head.text=c>>8&1),512&a.flags&&(L[0]=255&c,L[1]=c>>>8&255,a.check=T(a.check,L,2,0)),c=0,d=0,a.mode=3;case 3:for(;d<32;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.head&&(a.head.time=c),512&a.flags&&(L[0]=255&c,L[1]=c>>>8&255,L[2]=c>>>16&255,L[3]=c>>>24&255,a.check=T(a.check,L,4,0)),c=0,d=0,a.mode=4;case 4:for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.head&&(a.head.xflags=255&c,a.head.os=c>>8),512&a.flags&&(L[0]=255&c,L[1]=c>>>8&255,a.check=T(a.check,L,2,0)),c=0,d=0,a.mode=5;case 5:if(1024&a.flags){for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.length=c,a.head&&(a.head.extra_len=c),512&a.flags&&(L[0]=255&c,L[1]=c>>>8&255,a.check=T(a.check,L,2,0)),c=0,d=0}else a.head&&(a.head.extra=null);a.mode=6;case 6:if(1024&a.flags&&((g=a.length)>r&&(g=r),g&&(a.head&&(k=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(s.subarray(l,l+g),k)),512&a.flags&&(a.check=T(a.check,s,g,l)),r-=g,l+=g,a.length-=g),a.length))break a;a.length=0,a.mode=7;case 7:if(2048&a.flags){if(0===r)break a;g=0;do k=s[l+g++],a.head&&k&&a.length<65536&&(a.head.name+=String.fromCharCode(k));while(k&&g<r)if(512&a.flags&&(a.check=T(a.check,s,g,l)),r-=g,l+=g,k)break a}else a.head&&(a.head.name=null);a.length=0,a.mode=8;case 8:if(4096&a.flags){if(0===r)break a;g=0;do k=s[l+g++],a.head&&k&&a.length<65536&&(a.head.comment+=String.fromCharCode(k));while(k&&g<r)if(512&a.flags&&(a.check=T(a.check,s,g,l)),r-=g,l+=g,k)break a}else a.head&&(a.head.comment=null);a.mode=9;case 9:if(512&a.flags){for(;d<16;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(c!==(65535&a.check)){e.msg="header crc mismatch",a.mode=30;break}c=0,d=0}a.head&&(a.head.hcrc=a.flags>>9&1,a.head.done=!0),e.adler=a.check=0,a.mode=12;break;case 10:for(;d<32;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}e.adler=a.check=to(c),c=0,d=0,a.mode=11;case 11:if(0===a.havedict)return e.next_out=o,e.avail_out=n,e.next_in=l,e.avail_in=r,a.hold=c,a.bits=d,te;e.adler=a.check=1,a.mode=12;case 12:if(t===e6||t===e7)break a;case 13:if(a.last){c>>>=7&d,d-=7&d,a.mode=27;break}for(;d<3;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}switch(a.last=1&c,d-=1,3&(c>>>=1)){case 0:a.mode=14;break;case 1:if(td(a),a.mode=20,t===e7){c>>>=2,d-=2;break a}break;case 2:a.mode=17;break;case 3:e.msg="invalid block type",a.mode=30}c>>>=2,d-=2;break;case 14:for(c>>>=7&d,d-=7&d;d<32;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if((65535&c)!=(c>>>16^65535)){e.msg="invalid stored block lengths",a.mode=30;break}if(a.length=65535&c,c=0,d=0,a.mode=15,t===e7)break a;case 15:a.mode=16;case 16:if(g=a.length){if(g>r&&(g=r),g>n&&(g=n),0===g)break a;i.set(s.subarray(l,l+g),o),r-=g,l+=g,n-=g,o+=g,a.length-=g;break}a.mode=12;break;case 17:for(;d<14;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(a.nlen=(31&c)+257,d-=5,a.ndist=(31&(c>>>=5))+1,d-=5,a.ncode=(15&(c>>>=5))+4,c>>>=4,d-=4,a.nlen>286||a.ndist>30){e.msg="too many length or distance symbols",a.mode=30;break}a.have=0,a.mode=18;case 18:for(;a.have<a.ncode;){for(;d<3;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.lens[B[a.have++]]=7&c,c>>>=3,d-=3}for(;a.have<19;)a.lens[B[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,C={bits:a.lenbits},M=e5(0,a.lens,0,19,a.lencode,0,a.work,C),a.lenbits=C.bits,M){e.msg="invalid code lengths set",a.mode=30;break}a.have=0,a.mode=19;case 19:for(;a.have<a.nlen+a.ndist;){for(;m=(_=a.lencode[c&(1<<a.lenbits)-1])>>>24,v=_>>>16&255,y=65535&_,!(m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(y<16)c>>>=m,d-=m,a.lens[a.have++]=y;else{if(16===y){for(z=m+2;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(c>>>=m,d-=m,0===a.have){e.msg="invalid bit length repeat",a.mode=30;break}k=a.lens[a.have-1],g=3+(3&c),c>>>=2,d-=2}else if(17===y){for(z=m+3;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}c>>>=m,d-=m,k=0,g=3+(7&c),c>>>=3,d-=3}else{for(z=m+7;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}c>>>=m,d-=m,k=0,g=11+(127&c),c>>>=7,d-=7}if(a.have+g>a.nlen+a.ndist){e.msg="invalid bit length repeat",a.mode=30;break}for(;g--;)a.lens[a.have++]=k}}if(30===a.mode)break;if(0===a.lens[256]){e.msg="invalid code -- missing end-of-block",a.mode=30;break}if(a.lenbits=9,C={bits:a.lenbits},M=e5(1,a.lens,0,a.nlen,a.lencode,0,a.work,C),a.lenbits=C.bits,M){e.msg="invalid literal/lengths set",a.mode=30;break}if(a.distbits=6,a.distcode=a.distdyn,C={bits:a.distbits},M=e5(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,C),a.distbits=C.bits,M){e.msg="invalid distances set",a.mode=30;break}if(a.mode=20,t===e7)break a;case 20:a.mode=21;case 21:if(r>=6&&n>=258){e.next_out=o,e.avail_out=n,e.next_in=l,e.avail_in=r,a.hold=c,a.bits=d,eQ(e,h),o=e.next_out,i=e.output,n=e.avail_out,l=e.next_in,s=e.input,r=e.avail_in,c=a.hold,d=a.bits,12===a.mode&&(a.back=-1);break}for(a.back=0;m=(_=a.lencode[c&(1<<a.lenbits)-1])>>>24,v=_>>>16&255,y=65535&_,!(m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(v&&(240&v)==0){for(w=m,x=v,b=y;m=(_=a.lencode[b+((c&(1<<w+x)-1)>>w)])>>>24,v=_>>>16&255,y=65535&_,!(w+m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}c>>>=w,d-=w,a.back+=w}if(c>>>=m,d-=m,a.back+=m,a.length=y,0===v){a.mode=26;break}if(32&v){a.back=-1,a.mode=12;break}if(64&v){e.msg="invalid literal/length code",a.mode=30;break}a.extra=15&v,a.mode=22;case 22:if(a.extra){for(z=a.extra;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.length+=c&(1<<a.extra)-1,c>>>=a.extra,d-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=23;case 23:for(;m=(_=a.distcode[c&(1<<a.distbits)-1])>>>24,v=_>>>16&255,y=65535&_,!(m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if((240&v)==0){for(w=m,x=v,b=y;m=(_=a.distcode[b+((c&(1<<w+x)-1)>>w)])>>>24,v=_>>>16&255,y=65535&_,!(w+m<=d);){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}c>>>=w,d-=w,a.back+=w}if(c>>>=m,d-=m,a.back+=m,64&v){e.msg="invalid distance code",a.mode=30;break}a.offset=y,a.extra=15&v,a.mode=24;case 24:if(a.extra){for(z=a.extra;d<z;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}a.offset+=c&(1<<a.extra)-1,c>>>=a.extra,d-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){e.msg="invalid distance too far back",a.mode=30;break}a.mode=25;case 25:if(0===n)break a;if(g=h-n,a.offset>g){if((g=a.offset-g)>a.whave&&a.sane){e.msg="invalid distance too far back",a.mode=30;break}g>a.wnext?(g-=a.wnext,u=a.wsize-g):u=a.wnext-g,g>a.length&&(g=a.length),f=a.window}else f=i,u=o-a.offset,g=a.length;g>n&&(g=n),n-=g,a.length-=g;do i[o++]=f[u++];while(--g)0===a.length&&(a.mode=21);break;case 26:if(0===n)break a;i[o++]=a.length,n--,a.mode=21;break;case 27:if(a.wrap){for(;d<32;){if(0===r)break a;r--,c|=s[l++]<<d,d+=8}if(h-=n,e.total_out+=h,a.total+=h,h&&(e.adler=a.check=a.flags?T(a.check,i,h,o-h):U(a.check,i,h,o-h)),h=n,(a.flags?c:to(c))!==a.check){e.msg="incorrect data check",a.mode=30;break}c=0,d=0}a.mode=28;case 28:if(a.wrap&&a.flags){for(;d<32;){if(0===r)break a;r--,c+=s[l++]<<d,d+=8}if(c!==(0|a.total)){e.msg="incorrect length check",a.mode=30;break}c=0,d=0}a.mode=29;case 29:M=e9;break a;case 30:M=ta;break a;case 31:return ts;default:return tt}return e.next_out=o,e.avail_out=n,e.next_in=l,e.avail_in=r,a.hold=c,a.bits=d,(a.wsize||h!==e.avail_out&&a.mode<30&&(a.mode<27||t!==e4))&&tp(e,e.output,e.next_out,h-e.avail_out),p-=e.avail_in,h-=e.avail_out,e.total_in+=p,e.total_out+=h,a.total+=h,a.wrap&&h&&(e.adler=a.check=a.flags?T(a.check,i,h,e.next_out-h):U(a.check,i,h,e.next_out-h)),e.data_type=a.bits+64*!!a.last+128*(12===a.mode)+256*(20===a.mode||15===a.mode),(0===p&&0===h||t===e4)&&M===e8&&(M=ti),M},tg=e=>{if(!e||!e.state)return tt;let t=e.state;return t.window&&(t.window=null),e.state=null,e8},tu=(e,t)=>{let a,s=t.length;return e&&e.state&&(0===(a=e.state).wrap||11===a.mode)?11===a.mode&&U(1,t,s,0)!==a.check?ta:tp(e,t,s,s)?(a.mode=31,ts):(a.havedict=1,e8):tt},tf=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};let tm=Object.prototype.toString,{Z_NO_FLUSH:tv,Z_FINISH:ty,Z_OK:tw,Z_STREAM_END:tx,Z_NEED_DICT:tb,Z_STREAM_ERROR:tk,Z_DATA_ERROR:tM,Z_MEM_ERROR:tC}=$;function tz(e){this.options=eH({chunkSize:65536,windowBits:15,to:""},e||{});let t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(e&&e.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(15&t.windowBits)==0&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new eX,this.strm.avail_out=0;let a=((e,t)=>{if(!e)return tt;let a=new tr;e.state=a,a.window=null;let s=((e,t)=>{let a;if(!e||!e.state)return tt;let s=e.state;return(t<0?(a=0,t=-t):(a=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?tt:(null!==s.window&&s.wbits!==t&&(s.window=null),s.wrap=a,s.wbits=t,tn(e))})(e,t);return s!==e8&&(e.state=null),s})(this.strm,t.windowBits);if(a!==tw||(this.header=new tf,((e,t)=>{if(!e||!e.state)return;let a=e.state;return(2&a.wrap)==0||(a.head=t,t.done=!1)})(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=eE(t.dictionary):"[object ArrayBuffer]"===tm.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw)&&(a=tu(this.strm,t.dictionary))!==tw))throw Error(Y[a])}function t_(e,t){let a=new tz(t);if(a.push(e),a.err)throw a.msg||Y[a.err];return a.result}tz.prototype.push=function(e,t){let a,s,i,l=this.strm,o=this.options.chunkSize,r=this.options.dictionary;if(this.ended)return!1;for(s=t===~~t?t:!0===t?ty:tv,"[object ArrayBuffer]"===tm.call(e)?l.input=new Uint8Array(e):l.input=e,l.next_in=0,l.avail_in=l.input.length;;){for(0===l.avail_out&&(l.output=new Uint8Array(o),l.next_out=0,l.avail_out=o),(a=th(l,s))===tb&&r&&((a=tu(l,r))===tw?a=th(l,s):a===tM&&(a=tb));l.avail_in>0&&a===tx&&l.state.wrap>0&&0!==e[l.next_in];)tn(l),a=th(l,s);switch(a){case tk:case tM:case tb:case tC:return this.onEnd(a),this.ended=!0,!1}if(i=l.avail_out,l.next_out&&(0===l.avail_out||a===tx))if("string"===this.options.to){let e=eU(l.output,l.next_out),t=l.next_out-e,a=eO(l.output,e);l.next_out=t,l.avail_out=o-t,t&&l.output.set(l.output.subarray(e,e+t),0),this.onData(a)}else this.onData(l.output.length===l.next_out?l.output:l.output.subarray(0,l.next_out));if(a!==tw||0!==i){if(a===tx)return a=tg(this.strm),this.onEnd(a),this.ended=!0,!0;if(0===l.avail_in)break}}return!0},tz.prototype.onData=function(e){this.chunks.push(e)},tz.prototype.onEnd=function(e){e===tw&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=eq(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};let{Deflate:tL,deflate:tB,deflateRaw:tS,gzip:tA}={Deflate:eJ,deflate:eK,deflateRaw:function(e,t){return(t=t||{}).raw=!0,eK(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,eK(e,t)},constants:$},{Inflate:tP,inflate:tV,inflateRaw:tH,ungzip:tq}={Inflate:tz,inflate:t_,inflateRaw:function(e,t){return(t=t||{}).raw=!0,t_(e,t)},ungzip:t_,constants:$};a.d(t,{Gy:()=>tL,Kc:()=>tB,UD:()=>tV})},2338(e,t,a){let s;a.d(t,{x3j:()=>o6,aoY:()=>mI,$BZ:()=>mF,y15:()=>oA,OvW:()=>rN,Txp:()=>r1,Q5o:()=>uH,UA7:()=>uQ,JHX:()=>rU,yEg:()=>oI,UhG:()=>oP,OFB:()=>mq,Yep:()=>mO,z4o:()=>s9,Ahp:()=>mE,txp:()=>uF,rRT:()=>u1});var i=a(2718),l=a(1179),o=a(2842),r=a(4238),n=a(5633),c=a(2109),d=a(7086),p=a(2981);let h=["flowchart","mindmap","sequence","timeline","chart","state-machine","gantt","er","class","org-chart"],g=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u;function u(e){return e.length<=64&&g.test(e)}let f=i.ukk,m=i.mSG(i.QfV,i.$r1),v=Object.freeze({paper:"#f6f1e7",card:"#fffdf8",ink:"#1a1712",accent:"#8f707f"}),y=Object.freeze({accentColor:v.accent,backgroundColor:v.card});function w(e,t){return e.pipe(i.tiU(o.PyW(t)))}i.xCb(h);let x=i.xCb(["flowchart","mindmap"]),b=i.xCb(["TB","BT","LR","RL"]),k=i.xCb(["straight","orthogonal","curved"]);class M extends i.Xsx("DiagramIconRef")({slug:f.check(i.Pto(g),i.NYj(64))}){}let C=["cloud","datacenter","region","zone","vpc","subnet","cluster","namespace"],z=i.xCb(C);class _ extends i.Xsx("DiagramGroup")({id:f,label:f,parent:i.lqM(f),kind:i.lqM(z)}){}class L extends i.Xsx("DiagramLane")({id:f,label:f}){}let B=["database","queue","document","storage"],S=i.xCb(B);class A extends i.Xsx("DiagramNode")({id:f,label:f,group:i.lqM(f),lane:i.lqM(f),kind:i.lqM(f),shape:i.lqM(S),icon:i.lqM(M),metadata:w(m,{})}){}class P extends i.Xsx("DiagramEdge")({id:f,source:f,target:f,label:i.lqM(f),metadata:w(m,{})}){}let V=i.QfV.check(i.Pto(/^#[0-9a-fA-F]{6}$/));class H extends i.Xsx("DiagramStyle")({accentColor:w(V,y.accentColor),backgroundColor:w(V,y.backgroundColor)}){}class q extends i.Xsx("DiagramLayout")({direction:w(b,"LR"),edgeRouting:w(k,"orthogonal")}){}class F extends i.Xsx("IntermediateDiagram")({id:f,title:f,type:w(x,"flowchart"),nodes:i.O31(A).pipe(i.fXn).check(i.tJb(1)),edges:w(i.O31(P).pipe(i.fXn),[]),groups:i.lqM(i.O31(_).pipe(i.fXn)),lanes:i.lqM(i.O31(L).pipe(i.fXn)),layout:w(q,{direction:"LR",edgeRouting:"orthogonal"}),style:w(H,y),metadata:w(m,{})}){}class I extends Error{constructor(e){super(e),this.name="DiagramValidationError"}}let E=e=>{let t=new Set;for(let a of e){if(t.has(a))return a;t.add(a)}};function O(e){let t=E(e.nodes.map(e=>e.id));if(t)throw new I(`Duplicate node id "${t}" is not allowed.`);let a=E(e.edges.map(e=>e.id));if(a)throw new I(`Duplicate edge id "${a}" is not allowed.`);let s=E((e.groups??[]).map(e=>e.id));if(s)throw new I(`Duplicate group id "${s}" is not allowed.`);let i=new Set((e.groups??[]).map(e=>e.id)),l=new Map((e.groups??[]).flatMap(e=>void 0===e.parent?[]:[[e.id,e.parent]]));for(let[e,t]of l){if(!i.has(t))throw new I(`Group "${e}" references missing parent group "${t}".`);let a=new Set([e]);for(let t=l.get(e);void 0!==t;){if(a.has(t))throw new I(`Group "${e}" is nested inside itself.`);a.add(t),t=l.get(t)}}for(let t of e.nodes)if(void 0!==t.group&&!i.has(t.group))throw new I(`Node "${t.id}" references missing group "${t.group}".`);let o=e.lanes??[],r=E(o.map(e=>e.id));if(r)throw new I(`Duplicate lane id "${r}" is not allowed.`);if(o.length>0&&(e.groups??[]).length>0)throw new I("A diagram with lanes cannot also declare groups.");let n=new Set(o.map(e=>e.id));for(let t of e.nodes){if(void 0!==t.lane&&!n.has(t.lane))throw new I(`Node "${t.id}" references missing lane "${t.lane}".`);if(void 0===t.lane&&n.size>0)throw new I(`Node "${t.id}" has no lane.`)}let c=new Set(e.nodes.map(e=>e.id));for(let t of e.edges){if(!c.has(t.source))throw new I(`Edge "${t.id}" references missing source node "${t.source}".`);if(!c.has(t.target))throw new I(`Edge "${t.id}" references missing target node "${t.target}".`);if(t.source===t.target)throw new I(`Edge "${t.id}" cannot connect node "${t.source}" to itself.`)}return e}function U(e){return O(i.svK(F,{errors:"all"})(e))}let X="chart",T=["bar","line","pie"],Y=["vertical","horizontal"],$=i.xCb(T),G=i.xCb(Y);class D extends i.Xsx("ChartSeries")({name:i.Qrq(i.ukk),values:i.O31(i.wYs).pipe(i.fXn)}){}class R extends i.Xsx("ChartDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(X),kind:$,categories:i.O31(i.ukk).pipe(i.fXn,i.Sr8(i.tJb(1))),series:i.O31(D).pipe(i.fXn,i.Sr8(i.tJb(1))),unit:i.Qrq(i.ukk),categoryAxisTitle:i.Qrq(i.ukk),valueAxisTitle:i.Qrq(i.ukk),stacked:i.Qrq(i.v8c),donut:i.Qrq(i.v8c),orientation:i.Qrq(G),style:H.pipe(i.tiU(o.PyW({...y})))}){}let Z=e=>e.trim().toLowerCase();function j(e){let t=[],{categories:a,kind:s,series:i}=e,l="pie"===s,o=l?8:40;a.length>o&&t.push({code:"chart_too_large",path:"categories",message:`A ${s} chart supports at most ${o} ${l?"slices":"categories"}.`,hint:l?'Fold the smallest slices into one "Other" slice, or use a bar chart.':"Group categories, or split the data into several charts."}),i.length>6&&t.push({code:"chart_too_large",path:"series",message:"A chart supports at most 6 series.",hint:"Keep the series the request compares, or split them into several charts."}),a.length*i.length>120&&t.push({code:"chart_too_large",path:"series",message:"A chart supports at most 120 values (categories × series).",hint:"Split the data into several charts."});let r=new Set;a.forEach((e,a)=>{r.has(Z(e))&&t.push({code:"duplicate_chart_category",path:`categories.[${a}]`,message:`Category "${e}" is listed more than once.`,hint:"List each category once; put its values for every series at the same position."}),r.add(Z(e))}),l&&1!==i.length&&t.push({code:"invalid_chart_series",path:"series",message:"A pie chart has exactly one series.",hint:"Use one series of slice values, or a grouped bar chart to compare several series."});let n=new Set;i.forEach((e,s)=>{let o=`series.[${s}]`;i.length>1&&void 0===e.name&&t.push({code:"invalid_chart_series",path:`${o}.name`,message:`Series ${s+1} needs a name for the legend.`,hint:"Name every series when a chart has more than one."}),void 0!==e.name&&(n.has(Z(e.name))&&t.push({code:"invalid_chart_series",path:`${o}.name`,message:`Series name "${e.name}" is used more than once.`,hint:"Give each series a distinct name."}),n.add(Z(e.name))),e.values.length!==a.length&&t.push({code:"chart_series_mismatch",path:`${o}.values`,message:`Series ${e.name?`"${e.name}"`:s+1} has ${e.values.length} values for ${a.length} categories.`,hint:"Give every series exactly one value per category, in category order."}),l&&e.values.some(e=>e<0)&&t.push({code:"invalid_chart_value",path:`${o}.values`,message:"Pie slice values cannot be negative.",hint:"Use a bar chart for data with negative values."})}),l&&i[0]&&!i[0].values.some(e=>e>0)&&t.push({code:"invalid_chart_value",path:"series.[0].values",message:"A pie chart needs at least one positive slice value.",hint:"Supply the slice values from the request."});let c=(e,a,s,i)=>{a||t.push({code:"invalid_chart_option",path:e,message:s,hint:i})};for(let t of(e.stacked&&c("stacked","bar"===s,"Only bar charts stack.",'Remove stacked, or use kind: "bar".'),e.donut&&c("donut",l,"Only pie charts draw as a donut.",'Remove donut, or use kind: "pie".'),void 0!==e.orientation&&c("orientation","bar"===s,"Only bar charts have an orientation.","Remove orientation for line and pie charts."),["categoryAxisTitle","valueAxisTitle"]))void 0!==e[t]&&c(t,!l,"A pie chart has no axes.",`Remove ${t} from the pie chart.`);return t.slice(0,20)}class N extends I{issues;constructor(e){super(e[0]?.message??"Chart failed validation."),this.issues=e,this.name="ChartValidationError"}}function W(e){let t=j(e);if(t.length)throw new N(t);return e}W(i.svK(R,{errors:"all"})({id:"quarterly-revenue-chart",title:"Quarterly revenue",type:"chart",kind:"bar",categories:["Q1","Q2","Q3","Q4"],series:[{name:"2025",values:[42,51,47,63]},{name:"2026",values:[48,57,61,72]}],unit:"$M",categoryAxisTitle:"Quarter",valueAxisTitle:"Revenue"}));let J="timeline",K=["event","milestone"],Q=i.xCb(K);class ee extends i.Xsx("TimelineEvent")({id:i.ukk,label:i.ukk,date:i.Qrq(i.ukk),end:i.Qrq(i.ukk),order:i.Qrq(i.wYs),kind:i.Qrq(Q),lane:i.Qrq(i.ukk),description:i.Qrq(i.ukk)}){}class et extends i.Xsx("TimelineDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(J),events:i.O31(ee).pipe(i.fXn,i.Sr8(i.tJb(1))),lanes:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),today:i.Qrq(i.ukk),style:H.pipe(i.tiU(o.PyW({...y})))}){}let ea=/^(\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2}))?)?)?$/u;function es(e,t,a,s=0,i=0,l=0,o=0){let r=new Date(0);return r.setUTCFullYear(e,t-1,a),r.setUTCHours(s,i,l,o),r.getTime()}function ei(e){let t=ea.exec(e);if(!t)return;let[,a,s,i,l,o,r,n,c]=t,d=Number(a),p=void 0===s?1:Number(s),h=void 0===i?1:Number(i);if(p<1||p>12||h<1||h>new Date(es(d,p+1,0)).getUTCDate())return;if(void 0===l){let e=void 0!==i?"day":void 0!==s?"month":"year",t=es(d,p,h),a="day"===e?es(d,p,h+1):"month"===e?es(d,p+1,1):es(d+1,1,1);return{granularity:e,start:t,end:a,fields:{year:d,month:p,day:h,hour:0,minute:0,second:0,millisecond:0}}}let g=Number(l),u=Number(o),f=void 0===r?0:Number(r),m=void 0===n?0:Number(n.padEnd(3,"0"));if(g>23||u>59||f>59||void 0===c)return;let v=0;if("Z"!==c){let e=Number(c.slice(1,3)),t=Number(c.slice(4,6));if(e>14||t>59)return;v=(c.startsWith("-")?-1:1)*(60*e+t)}let y=es(d,p,h,g,u,f,m)-6e4*v;return{granularity:"instant",start:y,end:y,fields:{year:d,month:p,day:h,hour:g,minute:u,second:f,millisecond:m},offsetMinutes:v}}let el="Use YYYY, YYYY-MM, YYYY-MM-DD, or YYYY-MM-DDTHH:mm[:ss] with Z or ±HH:MM, copied from the source.";function eo(e){if(e.lanes)return[...e.lanes];let t=[];for(let a of ep(e))void 0===a.lane||t.includes(a.lane)||t.push(a.lane);return t}function er(e){let t=[];(0===e.events.length||e.events.length>60)&&t.push({code:"timeline_too_large",path:"events",message:"Timeline needs 1–60 events.",hint:"Provide at least one event, or split a longer chronology into timelines."});let a=new Set,s=e.events[0]?.date!==void 0,i=void 0!==e.lanes||e.events.some(e=>e.lane);return e.events.forEach((l,o)=>{let r=`events.[${o}]`;a.has(l.id)&&t.push({code:"duplicate_event_id",path:`${r}.id`,message:`Event id "${l.id}" is duplicated.`,hint:"Give each event a unique stable id."}),a.add(l.id);let n=void 0===l.date?void 0:ei(l.date);if(void 0===l.date||n||t.push({code:"invalid_timeline_date",path:`${r}.date`,message:`Event "${l.id}" has invalid date "${l.date}".`,hint:el}),(void 0!==l.date==(void 0!==l.order)||void 0!==l.date!==s)&&t.push({code:"invalid_timeline_order",path:r,message:"Every event must use exactly one chronology field, with the same date or order mode throughout.",hint:"Supply dates for all events, or numeric order for all events; never invent a missing date."}),void 0!==l.end){let e=ei(l.end);e?(void 0===l.date||"milestone"===l.kind||n&&e.end<=n.start)&&t.push({code:"invalid_timeline_span",path:`${r}.end`,message:`Span "${l.id}" needs a date, an end on or after it, and no milestone kind.`,hint:"Use end only for dated phases; a milestone is a single point."}):t.push({code:"invalid_timeline_date",path:`${r}.end`,message:`Event "${l.id}" has invalid end "${l.end}".`,hint:el})}i&&(void 0===l.lane||e.lanes&&!e.lanes.includes(l.lane))&&t.push({code:"invalid_timeline_lane",path:`${r}.lane`,message:`Event "${l.id}" needs one of the timeline's lanes.`,hint:"Give every event a lane listed in lanes, or omit lanes everywhere."})}),e.lanes&&new Set(e.lanes).size!==e.lanes.length&&t.push({code:"invalid_timeline_lane",path:"lanes",message:"Lane names must be unique.",hint:"List each lane once, in top-to-bottom order."}),eo(e).length>6&&t.push({code:"timeline_too_large",path:"lanes",message:"Timeline supports at most 6 lanes.",hint:"Merge related tracks or split the chronology into timelines."}),void 0===e.today||s&&void 0!==ei(e.today)||t.push({code:"invalid_timeline_date",path:"today",message:`Today "${e.today}" must be a valid date on a dated timeline.`,hint:`${el} Omit today unless the source states it.`}),t.slice(0,20)}class en extends I{issues;constructor(e){super(e[0]?.message??"Timeline failed validation."),this.issues=e,this.name="TimelineValidationError"}}function ec(e){let t=er(e);if(t.length)throw new en(t);return e}function ed(e){return void 0!==e.date?ei(e.date)?.start??0/0:e.order??0}function ep(e){return e.events.toSorted((e,t)=>ed(e)-ed(t)||0)}ec(i.svK(et,{errors:"all"})({id:"release-timeline",title:"Release milestones",type:"timeline",events:[{id:"plan",label:"Scope agreed",date:"2026-09-01"},{id:"beta",label:"Public beta",date:"2026-09-15",description:"Collect feedback from early users."},{id:"release",label:"General availability",date:"2026-10-01",kind:"milestone"}]}));let eh="flowchart",eg=i.xCb(["duplicate_node_id","duplicate_edge_id","missing_edge_source","missing_edge_target","self_loop","missing_start","multiple_starts","missing_end","start_has_incoming","end_has_outgoing","unreachable_node","missing_outgoing_edge","underbranched_decision","unlabeled_decision_branch","duplicate_decision_branch_label","nonterminating_node","flowchart_too_large","duplicate_group_id","unknown_node_group","empty_group","unknown_group_parent","group_cycle","shaped_decision","duplicate_lane_id","unknown_node_lane","empty_lane","lanes_with_groups"]);class eu extends i.Xsx("FlowchartValidationIssueRef")({kind:i.xCb(["diagram","node","edge","group","lane"]),id:i.lqM(i.ukk),path:i.lqM(i.ukk)}){}i.Xsx("FlowchartValidationIssue")({code:eg,ref:i.lqM(eu),message:i.ukk,hint:i.ukk});let ef=i.xCb(["start","process","decision","end"]);class em extends A.extend("FlowchartNode")({kind:ef,description:i.lqM(i.ukk)}){}class ev extends P.extend("FlowchartEdge")({label:i.lqM(i.ukk)}){}class ey extends F.extend("FlowchartDiagram")({type:i.uSQ(eh),nodes:i.O31(em).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(ev).pipe(i.fXn).check(i.tJb(1))}){}function ew(e){let t=new Set,a=new Set;for(let s of e)t.has(s)?a.add(s):t.add(s);return[...a]}function ex(e,t,a){let s=new Set,i=[...e];for(let e=0;e<i.length;e+=1){let l=i[e];if(!(void 0===l||s.has(l)))for(let e of(s.add(l),t.get(l)??[]))i.push(a(e))}return s}function eb(e){let t=[],a=new Set(e.nodes.map(e=>e.id)),{incoming:s,outgoing:i}=function(e){let t=new Map,a=new Map;for(let s of e)t.set(s.target,[...t.get(s.target)??[],s]),a.set(s.source,[...a.get(s.source)??[],s]);return{incoming:t,outgoing:a}}(e.edges);e.nodes.length>24&&t.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"nodes"},message:`Flowchart has ${e.nodes.length} nodes; the supported maximum is 24.`,hint:"Split the workflow or combine lower-signal steps."}),e.edges.length>64&&t.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"edges"},message:`Flowchart has ${e.edges.length} edges; the supported maximum is 64.`,hint:"Split the workflow or remove lower-signal connections."});let l=e.groups??[];for(let a of(l.length>8&&t.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"groups"},message:`Flowchart has ${l.length} groups; the supported maximum is 8.`,hint:"Merge related groups or leave minor steps ungrouped."}),ew(l.map(e=>e.id))))t.push({code:"duplicate_group_id",ref:{kind:"group",id:a,path:"groups"},message:`Group id "${a}" is used more than once.`,hint:"Give every group a stable unique id."});let o=new Set(l.map(e=>e.id));for(let a of e.nodes)void 0===a.group||o.has(a.group)||t.push({code:"unknown_node_group",ref:{kind:"node",id:a.id,path:"nodes.group"},message:`Node "${a.id}" references undeclared group "${a.group}".`,hint:o.size>0?`Set group to a declared group id (${[...o].map(e=>`"${e}"`).join(", ")}) or declare "${a.group}" in groups.`:`Declare "${a.group}" in groups as { id, label }, or remove the node's group.`});t.push(...function(e){let t=e.groups??[],a=new Set(t.map(e=>e.id)),s=new Map(t.flatMap(e=>void 0!==e.parent&&a.has(e.parent)?[[e.id,e.parent]]:[])),i=[],l=0;for(let e of t){if(void 0!==e.parent&&!a.has(e.parent)){i.push({code:"unknown_group_parent",ref:{kind:"group",id:e.id,path:"groups.parent"},message:`Group "${e.id}" references undeclared parent group "${e.parent}".`,hint:`Set parent to the id of the declared group that encloses it (${[...a].map(e=>`"${e}"`).join(", ")}), or remove parent.`});continue}let t=[e.id],o=!1;for(let a=s.get(e.id);void 0!==a;){if(t.includes(a)){o=!0,a===e.id&&i.push({code:"group_cycle",ref:{kind:"group",id:e.id,path:"groups.parent"},message:`Group "${e.id}" is nested inside itself through ${[...t,a].map(e=>`"${e}"`).join(" in ")}.`,hint:"Set each group's parent to the group that encloses it; the outermost group has no parent."});break}t.push(a),a=s.get(a)}o||(l=Math.max(l,t.length))}return l>4&&i.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"groups.parent"},message:`Groups nest ${l} deep; the supported maximum is 4.`,hint:"Drop an intermediate zone, or merge a zone into its parent."}),i}(e));let r=new Set([...e.nodes.map(e=>e.group),...l.map(e=>e.parent)]);for(let e of l.filter(e=>!r.has(e.id)))t.push({code:"empty_group",ref:{kind:"group",id:e.id,path:"groups"},message:`Group "${e.id}" has no nodes.`,hint:"Set group on the nodes it holds, or remove the group."});for(let a of e.nodes)"decision"===a.kind&&void 0!==a.shape&&t.push({code:"shaped_decision",ref:{kind:"node",id:a.id,path:"nodes.shape"},message:`Decision node "${a.id}" cannot draw as a ${a.shape}.`,hint:"Remove shape from the decision; a decision always draws as a diamond."});for(let a of(t.push(...function(e){let t=e.lanes??[];if(0===t.length)return e.nodes.flatMap(e=>void 0===e.lane?[]:[{code:"unknown_node_lane",ref:{kind:"node",id:e.id,path:"nodes.lane"},message:`Node "${e.id}" references undeclared lane "${e.lane}".`,hint:`Declare "${e.lane}" in lanes as { id, label }, or remove the node's lane.`}]);let a=[];for(let s of(t.length>8&&a.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"lanes"},message:`Flowchart has ${t.length} lanes; the supported maximum is 8.`,hint:"Merge related actors into one lane."}),(e.groups??[]).length>0&&a.push({code:"lanes_with_groups",ref:{kind:"diagram",id:e.id,path:"groups"},message:"A flowchart with lanes cannot also declare groups.",hint:"Keep lanes for the actors and remove groups and every node's group."}),ew(t.map(e=>e.id))))a.push({code:"duplicate_lane_id",ref:{kind:"lane",id:s,path:"lanes"},message:`Lane id "${s}" is used more than once.`,hint:"Give every lane a stable unique id."});let s=new Set(t.map(e=>e.id)),i=[...s].map(e=>`"${e}"`).join(", ");for(let t of e.nodes)void 0!==t.lane&&s.has(t.lane)||a.push({code:"unknown_node_lane",ref:{kind:"node",id:t.id,path:"nodes.lane"},message:void 0===t.lane?`Node "${t.id}" has no lane.`:`Node "${t.id}" references undeclared lane "${t.lane}".`,hint:void 0===t.lane?`Set lane to the declared lane id (${i}) of the actor that does this step.`:`Set lane to a declared lane id (${i}) or declare "${t.lane}" in lanes.`});let l=new Set(e.nodes.map(e=>e.lane));for(let e of t.filter(e=>!l.has(e.id)))a.push({code:"empty_lane",ref:{kind:"lane",id:e.id,path:"lanes"},message:`Lane "${e.id}" has no nodes.`,hint:"Set lane on the steps this actor does, or remove the lane."});return a}(e)),ew(e.nodes.map(e=>e.id))))t.push({code:"duplicate_node_id",ref:{kind:"node",id:a,path:"nodes"},message:`Node id "${a}" is used more than once.`,hint:"Give every node a stable unique id."});for(let a of ew(e.edges.map(e=>e.id)))t.push({code:"duplicate_edge_id",ref:{kind:"edge",id:a,path:"edges"},message:`Edge id "${a}" is used more than once.`,hint:"Give every edge a stable unique id."});for(let s of e.edges)a.has(s.source)||t.push({code:"missing_edge_source",ref:{kind:"edge",id:s.id,path:"edges.source"},message:`Edge "${s.id}" references missing source node "${s.source}".`,hint:"Set edge.source to one of the diagram node ids."}),a.has(s.target)||t.push({code:"missing_edge_target",ref:{kind:"edge",id:s.id,path:"edges.target"},message:`Edge "${s.id}" references missing target node "${s.target}".`,hint:"Set edge.target to one of the diagram node ids."}),s.source===s.target&&t.push({code:"self_loop",ref:{kind:"edge",id:s.id},message:`Edge "${s.id}" connects node "${s.source}" to itself.`,hint:"Connect the edge to a different target node."});let n=e.nodes.filter(e=>"start"===e.kind),c=e.nodes.filter(e=>"end"===e.kind);for(let a of(0===n.length?t.push({code:"missing_start",ref:{kind:"diagram",id:e.id,path:"nodes"},message:"Flowchart must contain exactly one start node.",hint:'Mark the first node in the flow with kind: "start".'}):n.length>1&&t.push({code:"multiple_starts",ref:{kind:"diagram",id:e.id,path:"nodes"},message:`Flowchart has ${n.length} start nodes.`,hint:"Keep one start node and change the others to process, decision, or end."}),0===c.length&&t.push({code:"missing_end",ref:{kind:"diagram",id:e.id,path:"nodes"},message:"Flowchart must contain at least one end node.",hint:'Add an end node or mark terminal outcomes with kind: "end".'}),e.nodes)){let e=s.get(a.id)??[],l=i.get(a.id)??[];"start"===a.kind&&e.length>0&&t.push({code:"start_has_incoming",ref:{kind:"node",id:a.id},message:`Start node "${a.id}" cannot have incoming edges.`,hint:"Route the start node only to later nodes."}),"end"===a.kind&&l.length>0&&t.push({code:"end_has_outgoing",ref:{kind:"node",id:a.id},message:`End node "${a.id}" cannot have outgoing edges.`,hint:"End nodes must be terminal outcomes."}),"end"!==a.kind&&0===l.length&&t.push({code:"missing_outgoing_edge",ref:{kind:"node",id:a.id},message:`Node "${a.id}" must have at least one outgoing edge.`,hint:'Connect it to the next step, or mark it as kind: "end".'}),"decision"===a.kind&&t.push(...function(e,t){let a=[];t.length<2&&a.push({code:"underbranched_decision",ref:{kind:"node",id:e.id},message:`Decision node "${e.id}" must have at least two outgoing branches.`,hint:"Add at least two outgoing edges for the decision outcomes."});let s=t.map(e=>e.label?.trim()??"");for(let s of t.filter(e=>!e.label?.trim()))a.push({code:"unlabeled_decision_branch",ref:{kind:"edge",id:s.id,path:"edges.label"},message:`Decision node "${e.id}" has an outgoing branch without a label.`,hint:'Add a short branch label such as "yes", "no", "approved", or "rejected".'});for(let t of ew(s.filter(e=>e.length>0).map(e=>e.toLowerCase())))a.push({code:"duplicate_decision_branch_label",ref:{kind:"node",id:e.id},message:`Decision node "${e.id}" repeats branch label "${t}".`,hint:"Make every outgoing branch label from the same decision unique."});return a}(a,l))}let d=1===n.length?n[0]:void 0;if(d){let a=ex([d.id],i,e=>e.target);for(let s of e.nodes)a.has(s.id)||t.push({code:"unreachable_node",ref:{kind:"node",id:s.id},message:`Node "${s.id}" is not reachable from the start node.`,hint:"Connect every node to the flow that begins at the single start node."});if(c.length>0){let l=ex(c.map(e=>e.id),s,e=>e.source);for(let s of e.nodes)a.has(s.id)&&!l.has(s.id)&&(i.get(s.id)?.length??0)>0&&t.push({code:"nonterminating_node",ref:{kind:"node",id:s.id},message:`Node "${s.id}" cannot reach an end node.`,hint:"Add an eventual exit from this path to an end node; retry loops are valid when they retain an exit."})}}return t.slice(0,20)}class ek extends I{issues;constructor(e){super(e[0]?.message??"Flowchart failed semantic validation."),this.issues=e,this.name="FlowchartValidationError"}}function eM(e){let t=eb(e);if(t.length>0)throw new ek(t);return e}function eC(e){return eM(i.svK(ey,{errors:"all"})(e))}eC({id:"onboarding-flow",title:"Sketchi onboarding decision flow",type:eh,nodes:[{id:"prompt",label:"Prompt received",kind:"start"},{id:"requirements",label:"Extract requirements",kind:"process"},{id:"clear",label:"Scope clear?",kind:"decision"},{id:"draft",label:"Draft typed IR",kind:"process"},{id:"review",label:"Review diagram",kind:"end"}],edges:[{id:"prompt-requirements",source:"prompt",target:"requirements"},{id:"requirements-clear",source:"requirements",target:"clear"},{id:"clear-draft",source:"clear",target:"draft",label:"yes"},{id:"clear-review",source:"clear",target:"review",label:"no"},{id:"draft-review",source:"draft",target:"review"}],layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"pharma-batch-disposition",title:"Pharma batch disposition flow",type:eh,nodes:[{id:"batch-received",label:"Batch received",kind:"start"},{id:"qa-review",label:"QA reviews Certificate of Analysis",kind:"process"},{id:"passes-specs",label:"Passes specs?",kind:"decision"},{id:"final-review",label:"QA Manager final review",kind:"process"},{id:"packaging",label:"Send to packaging",kind:"end"},{id:"investigate",label:"Investigate retesting",kind:"process"},{id:"reject",label:"Reject batch",kind:"end"}],edges:[{id:"batch-qa",source:"batch-received",target:"qa-review"},{id:"qa-specs",source:"qa-review",target:"passes-specs"},{id:"specs-pass",source:"passes-specs",target:"final-review",label:"yes"},{id:"specs-investigate",source:"passes-specs",target:"investigate",label:"retest"},{id:"specs-reject",source:"passes-specs",target:"reject",label:"reject"},{id:"review-packaging",source:"final-review",target:"packaging"},{id:"investigate-review",source:"investigate",target:"final-review"}],layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"deploy-pipeline-logos",title:"Deploy pipeline",type:eh,nodes:[{id:"push",label:"Push to GitHub",kind:"start",icon:{slug:"github"}},{id:"build",label:"Build the Docker image",kind:"process",icon:{slug:"docker"}},{id:"tests",label:"Tests pass?",kind:"decision",icon:{slug:"vitest"}},{id:"fix",label:"Fix the failing tests",kind:"process"},{id:"ship",label:"Ship to Cloudflare Workers",kind:"end",icon:{slug:"cloudflare"}}],edges:[{id:"push-build",source:"push",target:"build"},{id:"build-tests",source:"build",target:"tests"},{id:"tests-ship",source:"tests",target:"ship",label:"yes"},{id:"tests-fix",source:"tests",target:"fix",label:"no"},{id:"fix-build",source:"fix",target:"build"}],layout:{direction:"TB",edgeRouting:"orthogonal"}});let ez="mindmap";class e_ extends i.Xsx("MindmapNodeMetadata")({depth:i.Aiz.check(i.OWK(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class eL extends A.extend("MindmapNode")({kind:i.xCb(["root","topic"]),metadata:e_}){}class eB extends i.Xsx("MindmapEdgeMetadata")({depth:i.Aiz.check(i.yJO(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class eS extends P.extend("MindmapEdge")({metadata:eB}){}class eA extends F.extend("MindmapDiagram")({type:i.uSQ(ez),nodes:i.O31(eL).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(eS).pipe(i.fXn).check(i.tJb(1))}){}function eP(e){O(e);let t=e.nodes.filter(e=>"root"===e.kind);if(1!==t.length)throw new I(`Mindmap must contain exactly one root topic; found ${t.length}.`);let a=t[0];if(!a||0!==a.metadata.depth)throw new I("Mindmap root topic must have depth 0.");let s=new Map,i=new Map(e.nodes.map(e=>[e.id,e])),l=new Map;for(let t of e.edges){s.set(t.target,(s.get(t.target)??0)+1);let e=i.get(t.source)?.metadata.depth,a=i.get(t.target),o=a?.metadata.depth;if(void 0===e||o!==e+1)throw new I(`Mindmap edge "${t.id}" must connect a topic to its immediate child.`);if(!a||t.metadata.depth!==a.metadata.depth||t.metadata.siblingIndex!==a.metadata.siblingIndex)throw new I(`Mindmap edge "${t.id}" metadata must match its child topic.`);l.set(t.source,[...l.get(t.source)??[],a.metadata.siblingIndex])}for(let t of e.nodes){let e=s.get(t.id)??0;if(t.id===a.id?0!==e:1!==e)throw new I(`Mindmap topic "${t.id}" must have ${t.id===a.id?"no parent":"exactly one parent"}.`)}for(let[e,t]of l){let a=t.map((e,t)=>t);if([...t].sort((e,t)=>e-t).some((e,t)=>e!==a[t]))throw new I(`Mindmap children of "${e}" must use contiguous sibling ordering from 0.`)}return e}function eV(e){return eP(i.svK(eA,{errors:"all"})(e))}eV({id:"public-mindmap-capability",title:"Public mindmap generation",type:ez,nodes:[{id:"topic-0",label:"Public mindmaps",kind:"root",metadata:{depth:0,siblingIndex:0}},{id:"topic-0-0",label:"Semantic input",kind:"topic",metadata:{depth:1,siblingIndex:0}},{id:"topic-0-0-0",label:"Nested topics",kind:"topic",metadata:{depth:2,siblingIndex:0}},{id:"topic-0-0-1",label:"Stable ordering",kind:"topic",metadata:{depth:2,siblingIndex:1}},{id:"topic-0-1",label:"Artifact output",kind:"topic",metadata:{depth:1,siblingIndex:1}},{id:"topic-0-1-0",label:"Scene",kind:"topic",metadata:{depth:2,siblingIndex:0}},{id:"topic-0-1-1",label:"Excalidraw",kind:"topic",metadata:{depth:2,siblingIndex:1}}],edges:[{id:"branch-0-0",source:"topic-0",target:"topic-0-0",metadata:{depth:1,siblingIndex:0}},{id:"branch-0-0-0",source:"topic-0-0",target:"topic-0-0-0",metadata:{depth:2,siblingIndex:0}},{id:"branch-0-0-1",source:"topic-0-0",target:"topic-0-0-1",metadata:{depth:2,siblingIndex:1}},{id:"branch-0-1",source:"topic-0",target:"topic-0-1",metadata:{depth:1,siblingIndex:1}},{id:"branch-0-1-0",source:"topic-0-1",target:"topic-0-1-0",metadata:{depth:2,siblingIndex:0}},{id:"branch-0-1-1",source:"topic-0-1",target:"topic-0-1-1",metadata:{depth:2,siblingIndex:1}}],layout:{direction:"LR",edgeRouting:"curved"}});let eH="sequence",eq=["message","return"],eF=["solid","dashed"],eI=":lifeline";function eE(e){return`${e}${eI}`}let eO=i.xCb(eq),eU=i.xCb(eF);class eX extends i.Xsx("SequenceParticipant")({id:i.ukk,label:i.ukk,kind:i.Qrq(i.ukk),icon:i.Qrq(M)}){}class eT extends i.Xsx("SequenceMessage")({id:i.ukk,source:i.ukk,target:i.ukk,label:i.ukk,type:i.Qrq(eO),style:i.Qrq(eU)}){}class eY extends i.Xsx("SequenceDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(eH),participants:i.O31(eX).pipe(i.fXn,i.Sr8(i.tJb(1))),messages:i.O31(eT).pipe(i.fXn,i.tiU(o.PyW([]))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let e$=i.xCb(["sequence_too_large","duplicate_participant_id","lifeline_id_collision","duplicate_message_id","missing_message_source","missing_message_target"]);function eG(e){let t=[];e.participants.length>12&&t.push({code:"sequence_too_large",path:"participants",message:`Sequence diagram has ${e.participants.length} participants; the supported maximum is 12.`,hint:"Combine minor actors or split the interaction into several diagrams."}),e.messages.length>40&&t.push({code:"sequence_too_large",path:"messages",message:`Sequence diagram has ${e.messages.length} messages; the supported maximum is 40.`,hint:"Split the interaction into phases or drop lower-signal messages."});let a=new Map;for(let s of(e.participants.forEach((e,s)=>{a.has(e.id)?t.push({code:"duplicate_participant_id",path:`participants.[${s}].id`,message:`Participant id "${e.id}" is duplicated.`,hint:"Give every participant a unique stable id and update message references."}):a.set(e.id,s)}),e.participants)){let a=eE(s.id);e.participants.forEach((e,i)=>{(e.id===a||e.id.startsWith(`${a}:`))&&t.push({code:"lifeline_id_collision",path:`participants.[${i}].id`,message:`Participant id "${e.id}" collides with the generated lifeline for "${s.id}".`,hint:`Rename the participant so its id does not start with another participant id followed by ${eI}.`})})}let s=new Set;return e.messages.forEach((e,i)=>{s.has(e.id)&&t.push({code:"duplicate_message_id",path:`messages.[${i}].id`,message:`Message id "${e.id}" is duplicated.`,hint:"Give every message a unique id or omit message ids to generate them deterministically."}),s.add(e.id),a.has(e.source)||t.push({code:"missing_message_source",path:`messages.[${i}].source`,message:`Message source "${e.source}" is not a participant.`,hint:"Use the id of a participant declared in participants."}),a.has(e.target)||t.push({code:"missing_message_target",path:`messages.[${i}].target`,message:`Message target "${e.target}" is not a participant.`,hint:"Use the id of a participant declared in participants."})}),t.slice(0,20)}i.Xsx("SequenceValidationIssue")({code:e$,path:i.ukk,message:i.ukk,hint:i.ukk});class eD extends I{issues;constructor(e){super(e[0]?.message??"Sequence diagram failed semantic validation."),this.issues=e,this.name="SequenceValidationError"}}function eR(e){let t=eG(e);if(t.length>0)throw new eD(t);return e}function eZ(e){return eR(i.svK(eY,{errors:"all"})(e))}eZ({id:"checkout-sequence",title:"Checkout sequence",type:eH,participants:[{id:"customer",label:"Customer"},{id:"store",label:"Store"},{id:"payments",label:"Payments"}],messages:[{id:"checkout",source:"customer",target:"store",label:"Submit checkout"},{id:"charge",source:"store",target:"payments",label:"Charge card"},{id:"charged",source:"payments",target:"store",label:"Payment approved",type:"return"},{id:"receipt",source:"store",target:"customer",label:"Order receipt",type:"return"}]}),eZ({id:"api-request-sequence",title:"API request with cache miss",type:eH,participants:[{id:"browser",label:"Browser"},{id:"api",label:"API Worker"},{id:"cache",label:"Cache"},{id:"database",label:"Database"},{id:"analytics",label:"Analytics"}],messages:[{id:"request",source:"browser",target:"api",label:"GET /orders"},{id:"lookup",source:"api",target:"cache",label:"Look up orders"},{id:"miss",source:"cache",target:"api",label:"Cache miss",type:"return"},{id:"query",source:"api",target:"database",label:"Query orders"},{id:"rows",source:"database",target:"api",label:"Order rows",type:"return"},{id:"track",source:"api",target:"analytics",label:"Track request"},{id:"response",source:"api",target:"browser",label:"200 OK",type:"return"}]}),eZ({id:"deploy-webhook-logos",title:"Deploy webhook",type:eH,participants:[{id:"developer",label:"Developer"},{id:"github",label:"GitHub",icon:{slug:"github"}},{id:"worker",label:"Cloudflare Worker",icon:{slug:"cloudflare"}},{id:"docker",label:"Docker build",icon:{slug:"docker"}}],messages:[{id:"push",source:"developer",target:"github",label:"git push"},{id:"webhook",source:"github",target:"worker",label:"Push webhook"},{id:"build",source:"worker",target:"docker",label:"Build image"},{id:"digest",source:"docker",target:"worker",label:"Image digest",type:"return"},{id:"accepted",source:"worker",target:"github",label:"202 Accepted",type:"return"}]}),eZ({id:"self-message-sequence",title:"Login with credential checks",type:eH,participants:[{id:"browser",label:"Browser"},{id:"idp",label:"Identity Provider"},{id:"users",label:"User Directory"}],messages:[{id:"sign-in",source:"browser",target:"idp",label:"Sign in"},{id:"validate",source:"idp",target:"idp",label:"Validate credentials"},{id:"mfa",source:"idp",target:"idp",label:"Check the one-time code against the enrolled authenticator"},{id:"lookup",source:"idp",target:"users",label:"Look up user"},{id:"profile",source:"users",target:"idp",label:"Profile",type:"return"},{id:"session",source:"idp",target:"browser",label:"Session",type:"return"},{id:"refresh",source:"browser",target:"browser",label:"Refresh the page"}]});let ej="state-machine",eN=["state","final","choice"],eW=["TB","LR"],eJ=i.xCb(eN);class eK extends i.Xsx("StateMachineState")({id:i.ukk,label:i.Qrq(i.ukk),kind:i.Qrq(eJ),parent:i.Qrq(i.ukk),initial:i.Qrq(i.ukk)}){}class eQ extends i.Xsx("StateMachineTransition")({id:i.ukk,source:i.ukk,target:i.ukk,event:i.Qrq(i.ukk),guard:i.Qrq(i.ukk),action:i.Qrq(i.ukk)}){}class e1 extends i.Xsx("StateMachineLayout")({direction:i.xCb(eW)}){}class e0 extends i.Xsx("StateMachineDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(ej),initial:i.ukk,states:i.O31(eK).pipe(i.fXn,i.Sr8(i.tJb(1))),transitions:i.O31(eQ).pipe(i.fXn,i.tiU(o.PyW([]))),layout:i.Qrq(e1),style:H.pipe(i.tiU(o.PyW({...y})))}){}let e2=i.xCb(["state_machine_too_large","invalid_state_id","duplicate_state_id","duplicate_transition_id","missing_state_label","unknown_initial_state","unknown_parent_state","nested_composite","missing_transition_source","missing_transition_target","final_has_outgoing","composite_member_transition","missing_composite_initial","underbranched_choice","unguarded_choice_branch","unreachable_state"]);function e3(e){return e.kind??"state"}i.Xsx("StateMachineValidationIssue")({code:e2,path:i.ukk,message:i.ukk,hint:i.ukk});let e5=new Set(["end","ended","final","finish","finished","done","stop","stopped","exit","state","node"]);function e4(e){if(void 0!==e.label)return e.label;let t=e3(e);if("choice"!==t){if("final"===t){let t=e.id.replace(/(\p{Ll})(\p{Lu})/gu,"$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu,"$1 $2").split(/[_\s\-\p{N}]+/u).filter(Boolean);if(t.length>0&&t.every(e=>e5.has(e.toLowerCase())))return}return e.id}}function e6(e){return new Set(e.states.flatMap(e=>e.parent?[e.parent]:[]))}function e7(e,t){return e.replace(t,"").trim()}function e8(e){let t=[],a=e6(e);e.states.length>30&&t.push({code:"state_machine_too_large",path:"states",message:`State machine has ${e.states.length} states; the supported maximum is 30.`,hint:"Split the machine into smaller machines or merge minor states."}),e.transitions.length>60&&t.push({code:"state_machine_too_large",path:"transitions",message:`State machine has ${e.transitions.length} transitions; the supported maximum is 60.`,hint:"Move transitions every substate shares onto their composite state."}),a.size>6&&t.push({code:"state_machine_too_large",path:"states",message:`State machine has ${a.size} composite states; the supported maximum is 6.`,hint:"Flatten minor composite states into their parents."});let s=new Map;e.states.forEach((e,a)=>{e.id.includes(":")&&t.push({code:"invalid_state_id",path:`states.[${a}].id`,message:`State id "${e.id}" contains ":".`,hint:"Use letters, digits, hyphens or underscores in state ids."}),s.has(e.id)&&t.push({code:"duplicate_state_id",path:`states.[${a}].id`,message:`State id "${e.id}" is used more than once.`,hint:"Give every state a unique id."}),s.set(e.id,e);let i=e4(e);void 0===i||i.trim()||t.push({code:"missing_state_label",path:`states.[${a}].label`,message:`State "${e.id}" has no label.`,hint:"Omit the label to use the default, or provide a non-blank label."})}),e.states.forEach((e,a)=>{if(void 0!==e.parent){let i=s.get(e.parent);i&&"state"===e3(i)?void 0!==i.parent&&t.push({code:"nested_composite",path:`states.[${a}].parent`,message:`State "${e.id}" sits in "${i.id}", which itself sits in "${i.parent}".`,hint:"Composite states hold states but not other composites; flatten one level."}):t.push({code:"unknown_parent_state",path:`states.[${a}].parent`,message:`State "${e.id}" names "${e.parent}" as its parent, which is not a state.`,hint:"Set parent to the id of a state (not a final state or choice), or remove it."})}if(void 0!==e.initial){let i=s.get(e.initial);i&&i.parent===e.id&&"final"!==e3(i)||t.push({code:"unknown_initial_state",path:`states.[${a}].initial`,message:`Composite "${e.id}" starts in "${e.initial}", which is not one of its substates.`,hint:`Set initial to a substate whose parent is "${e.id}", or remove it.`})}});let i=s.get(e.initial);i&&a.has(i.id)&&void 0===i.initial&&t.push({code:"missing_composite_initial",path:"initial",message:`The machine starts in composite "${i.id}", which has no initial substate.`,hint:`Set initial on "${i.id}" to the substate it starts in.`}),i&&void 0===i.parent&&"final"!==e3(i)||t.push({code:"unknown_initial_state",path:"initial",message:`The machine starts in "${e.initial}", which is not a top-level state.`,hint:"Set initial to the id of the top-level state the machine starts in."});let l=new Set,o=new Map;if(e.transitions.forEach((e,i)=>{l.has(e.id)&&t.push({code:"duplicate_transition_id",path:`transitions.[${i}].id`,message:`Transition id "${e.id}" is used more than once.`,hint:"Give every transition a unique id, or omit ids to generate them."}),l.add(e.id),o.set(e.source,(o.get(e.source)??0)+1);let r=s.get(e.source),n=s.get(e.target);r||t.push({code:"missing_transition_source",path:`transitions.[${i}].source`,message:`Transition "${e.id}" leaves "${e.source}", which is not a state.`,hint:"Set source to the id of a declared state."}),n||t.push({code:"missing_transition_target",path:`transitions.[${i}].target`,message:`Transition "${e.id}" enters "${e.target}", which is not a state.`,hint:"Set target to the id of a declared state."}),r&&"final"===e3(r)&&t.push({code:"final_has_outgoing",path:`transitions.[${i}].source`,message:`Transition "${e.id}" leaves final state "${r.id}".`,hint:"A final state ends the machine; leave from the state before it instead."}),r&&n&&(a.has(r.id)&&(n.id===r.id||n.parent===r.id)||a.has(n.id)&&r.parent===n.id)&&t.push({code:"composite_member_transition",path:`transitions.[${i}]`,message:`Transition "${e.id}" joins composite "${a.has(r.id)?r.id:n.id}" to itself or its own substate.`,hint:"Connect substates to each other, or the composite to a state outside it."}),n&&a.has(n.id)&&void 0===n.initial&&t.push({code:"missing_composite_initial",path:`transitions.[${i}].target`,message:`Transition "${e.id}" enters composite "${n.id}", which has no initial substate.`,hint:`Set initial on "${n.id}" to the substate it enters first, or target that substate.`})}),e.states.forEach((a,s)=>{if("choice"===e3(a)&&(o.get(a.id)??0)<2&&t.push({code:"underbranched_choice",path:`states.[${s}]`,message:`Choice "${a.id}" has fewer than two outgoing transitions.`,hint:"Give a choice two or more outgoing transitions, each with a guard."}),"choice"!==e3(a))return;let i=e.transitions.filter(e=>e.source===a.id).map(e=>e.guard?.replace(/^\s*\[|\]\s*$/gu,"").trim()??"");(i.some(e=>""===e)||i.filter(e=>"else"===e.toLowerCase()).length>1)&&t.push({code:"unguarded_choice_branch",path:`states.[${s}]`,message:`Choice "${a.id}" has a branch without its own guard.`,hint:'Give every branch of a choice a guard; one may be "else".'})}),i){let a=function(e){let t=new Map(e.states.map(e=>[e.id,e])),a=new Set,s=new Set,i=[{id:e.initial,entry:!0}];for(;i.length>0;){let{id:l,entry:o}=i.pop(),r=t.get(l);if(!(!r||a.has(l)&&(!o||s.has(l)))){if(o&&(s.add(l),r.initial&&i.push({id:r.initial,entry:!0})),!a.has(l))for(let t of(a.add(l),r.parent&&i.push({id:r.parent,entry:!1}),e.transitions))t.source===l&&i.push({id:t.target,entry:!0})}}return a}(e);e.states.forEach((e,s)=>{a.has(e.id)||t.push({code:"unreachable_state",path:`states.[${s}]`,message:`State "${e.id}" cannot be reached from the initial state.`,hint:"Add a transition into it, or make it its composite's initial substate."})})}return t.slice(0,20)}class e9 extends I{issues;constructor(e){super(e[0]?.message??"State machine failed semantic validation."),this.issues=e,this.name="StateMachineValidationError"}}function te(e){var t=i.svK(e0,{errors:"all"})(e);let a=e8(t);if(a.length>0)throw new e9(a);return t}te({id:"order-lifecycle",title:"Order lifecycle",type:ej,initial:"pending",states:[{id:"pending",label:"Pending payment"},{id:"paid",label:"Paid"},{id:"shipped",label:"Shipped"},{id:"cancelled",label:"Cancelled"},{id:"done",kind:"final"}],transitions:[{id:"pay",source:"pending",target:"paid",event:"pay",guard:"card valid",action:"charge"},{id:"remind",source:"pending",target:"pending",event:"after 24h",action:"email"},{id:"cancel",source:"pending",target:"cancelled",event:"cancel"},{id:"ship",source:"paid",target:"shipped",event:"ship"},{id:"reject",source:"shipped",target:"paid",event:"reject shipment"},{id:"deliver",source:"shipped",target:"done",event:"deliver"},{id:"close",source:"cancelled",target:"done"}]}),te({id:"media-player",title:"Media player",type:ej,initial:"stopped",states:[{id:"stopped",label:"Stopped"},{id:"active",label:"Active",initial:"playing"},{id:"playing",label:"Playing",parent:"active"},{id:"paused",label:"Paused",parent:"active"}],transitions:[{id:"play",source:"stopped",target:"active",event:"play"},{id:"pause",source:"playing",target:"paused",event:"pause"},{id:"resume",source:"paused",target:"playing",event:"resume"},{id:"seek",source:"playing",target:"playing",event:"seek",action:"jump"},{id:"stop",source:"active",target:"stopped",event:"stop"}]});let tt="gantt";class ta extends i.Xsx("GanttTask")({id:i.ukk,label:i.ukk,start:i.ukk,end:i.Qrq(i.ukk),duration:i.Qrq(i.wYs),milestone:i.Qrq(i.v8c),phase:i.Qrq(i.ukk),dependsOn:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),progress:i.Qrq(i.wYs)}){}class ts extends i.Xsx("GanttDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(tt),tasks:i.O31(ta).pipe(i.fXn,i.Sr8(i.tJb(1))),phases:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),today:i.Qrq(i.ukk),style:H.pipe(i.tiU(o.PyW({...y})))}){}function ti(e){let t=ei(e);return t?.granularity==="day"?Math.round(t.start/864e5):void 0}function tl(e){return new Date(864e5*e).toISOString().slice(0,10)}function to(e){return!0===e.milestone||0===e.duration}function tr(e){let t=ti(e.start);if(void 0!==t){if(to(e))return{start:t,end:t,milestone:!0};if(void 0!==e.end){let a=ti(e.end);return void 0===a?void 0:{start:t,end:a+1,milestone:!1}}return void 0===e.duration?void 0:{start:t,end:t+e.duration,milestone:!1}}}function tn(e){if(e.phases)return[...e.phases];let t=[];for(let a of e.tasks)void 0===a.phase||t.includes(a.phase)||t.push(a.phase);return t}function tc(e){let t=tn(e);return 0===t.length?[{tasks:e.tasks}]:t.map(t=>({phase:t,tasks:e.tasks.filter(e=>e.phase===t)}))}let td="Use YYYY-MM-DD, copied from the source.";function tp(e){let t=[],{tasks:a}=e;(0===a.length||a.length>60)&&t.push({code:"gantt_too_large",path:"tasks",message:"A Gantt chart needs 1–60 tasks.",hint:"Provide at least one task, or split a longer plan into several charts."});let s=new Set;for(let[e,i]of a.entries())s.has(i.id)&&t.push({code:"duplicate_task_id",path:`tasks.[${e}].id`,message:`Task id "${i.id}" is duplicated.`,hint:"Give each task a unique stable id."}),s.add(i.id);let i=void 0!==e.phases||a.some(e=>void 0!==e.phase),l=0;a.forEach((a,o)=>{let r=`tasks.[${o}]`,n=ti(a.start);void 0===n&&t.push({code:"invalid_gantt_date",path:`${r}.start`,message:`Task "${a.id}" has invalid start "${a.start}".`,hint:td});let c=void 0===a.end?void 0:ti(a.end);void 0!==a.end&&void 0===c&&t.push({code:"invalid_gantt_date",path:`${r}.end`,message:`Task "${a.id}" has invalid end "${a.end}".`,hint:`${td} end is the last day, inclusive.`});let d=(e,a,s="")=>t.push({code:"invalid_gantt_span",path:`${r}${s}`,message:e,hint:a});to(a)?(!0===a.milestone&&void 0!==a.duration&&0!==a.duration&&d(`Milestone "${a.id}" cannot have a duration.`,"A milestone is one day: give it start only.",".duration"),void 0!==a.end&&void 0!==c&&void 0!==n&&c!==n&&d(`Milestone "${a.id}" cannot end on another day.`,"A milestone is one day: give it start only, or drop milestone to draw a bar.",".end")):void 0===a.end==(void 0===a.duration)?d(`Task "${a.id}" needs exactly one of end or duration.`,"Give end (last day, inclusive) or duration (calendar days), or set milestone: true."):void 0!==a.duration&&(!Number.isInteger(a.duration)||a.duration<0)?d(`Task "${a.id}" has duration ${a.duration}; durations are whole calendar days.`,"Use a whole number of days counting start, such as 5 for start through start + 4.",".duration"):void 0!==c&&void 0!==n&&c<n?d(`Task "${a.id}" ends before it starts.`,"end is the last day, inclusive, on or after start.",".end"):void 0!==a.duration&&a.duration>36525&&d(`Task "${a.id}" has duration ${a.duration}; a chart spans at most 36525 days.`,"Give the task's real length in calendar days, or split a longer plan into several charts.",".duration"),void 0!==a.progress&&(a.progress<0||a.progress>100||to(a))&&t.push({code:"invalid_gantt_progress",path:`${r}.progress`,message:`Task "${a.id}" has progress ${a.progress}.`,hint:"progress is a percent from 0 to 100, on tasks only, never milestones."}),i&&(void 0===a.phase||e.phases&&!e.phases.includes(a.phase))&&t.push({code:"invalid_gantt_phase",path:`${r}.phase`,message:`Task "${a.id}" needs one of the chart's phases.`,hint:"Give every task a phase listed in phases, or omit phases everywhere."});let p=new Set;(a.dependsOn??[]).forEach((e,i)=>{l+=1;let o=`${r}.dependsOn.[${i}]`;e===a.id?t.push({code:"self_dependency",path:o,message:`Task "${a.id}" depends on itself.`,hint:"List only the tasks that must finish before this one starts."}):s.has(e)?p.has(e)&&t.push({code:"missing_dependency",path:o,message:`Task "${a.id}" lists "${e}" more than once.`,hint:"List each predecessor once."}):t.push({code:"missing_dependency",path:o,message:`Task "${a.id}" depends on unknown task "${e}".`,hint:"Use the id of a task declared in tasks."}),p.add(e)})}),l>120&&t.push({code:"gantt_too_large",path:"tasks",message:"A Gantt chart supports at most 120 dependencies.",hint:"Keep the dependencies the plan states, or split it into several charts."});let o=function(e){let t=new Map(e.map(e=>[e.id,e])),a=new Map,s=[],i=e=>{if("done"!==a.get(e)){if("open"===a.get(e))return[...s.slice(s.indexOf(e)),e];for(let l of(a.set(e,"open"),s.push(e),t.get(e)?.dependsOn??[])){if(l===e||!t.has(l))continue;let a=i(l);if(a)return a}s.pop(),a.set(e,"done")}};for(let t of e){let e=i(t.id);if(e)return e.toReversed()}}(a);o&&t.push({code:"gantt_dependency_cycle",path:`tasks.[${a.findIndex(e=>e.id===o[0])}].dependsOn`,message:`Dependencies form a cycle: ${o.join(" → ")}.`,hint:"A task cannot wait, directly or indirectly, for itself. Remove one dependency on the cycle."}),e.phases&&(new Set(e.phases).size!==e.phases.length&&t.push({code:"invalid_gantt_phase",path:"phases",message:"Phase names must be unique.",hint:"List each phase once, in top-to-bottom order."}),e.phases.forEach((e,s)=>{a.some(t=>t.phase===e)||t.push({code:"invalid_gantt_phase",path:`phases.[${s}]`,message:`Phase "${e}" has no tasks.`,hint:"List only phases that tasks name."})})),tn(e).length>12&&t.push({code:"gantt_too_large",path:"phases",message:"A Gantt chart supports at most 12 phases.",hint:"Merge related phases or split the plan into several charts."});let r=void 0===e.today?void 0:ti(e.today);void 0!==e.today&&void 0===r&&t.push({code:"invalid_gantt_date",path:"today",message:`Today "${e.today}" must be a YYYY-MM-DD date.`,hint:`${td} Omit today unless the source states it.`});let n=[...a.flatMap(e=>{let t=tr(e);return t&&Number.isFinite(t.end)?[t.start,t.end]:[]}),...void 0===r?[]:[r,r+1]];return n.length&&Math.max(...n)-Math.min(...n)>36525&&t.push({code:"gantt_too_large",path:"tasks",message:"A Gantt chart spans at most 36525 days, first task through last and Today.",hint:"Check the dates for a typo, or split a longer plan into several charts."}),t.slice(0,20)}class th extends I{issues;constructor(e){super(e[0]?.message??"Gantt chart failed validation."),this.issues=e,this.name="GanttValidationError"}}function tg(e){let t=tp(e);if(t.length)throw new th(t);return e}tg(i.svK(ts,{errors:"all"})({id:"release-plan",title:"Release plan",type:"gantt",tasks:[{id:"design",label:"Design",start:"2026-03-02",end:"2026-03-06",phase:"Build"},{id:"api",label:"API",start:"2026-03-09",duration:10,phase:"Build",dependsOn:["design"],progress:40},{id:"web",label:"Web app",start:"2026-03-09",end:"2026-03-20",phase:"Build",dependsOn:["design"]},{id:"qa",label:"QA",start:"2026-03-23",duration:5,phase:"Launch",dependsOn:["api","web"]},{id:"release",label:"Release",start:"2026-03-30",milestone:!0,phase:"Launch",dependsOn:["qa"]}]}));let tu="er",tf=["one","zero-or-one","many","one-or-many","zero-or-many"],tm=i.xCb(tf);class tv extends i.Xsx("ErField")({name:i.ukk,type:i.Qrq(i.ukk),pk:i.Qrq(i.v8c),fk:i.Qrq(i.v8c),unique:i.Qrq(i.v8c),nullable:i.Qrq(i.v8c)}){}class ty extends i.Xsx("ErEntity")({id:i.ukk,name:i.Qrq(i.ukk),fields:i.O31(tv).pipe(i.fXn,i.tiU(o.PyW([])))}){}class tw extends i.Xsx("ErRelationship")({id:i.ukk,from:i.ukk,to:i.ukk,fromCardinality:tm,toCardinality:tm,label:i.Qrq(i.ukk)}){}class tx extends i.Xsx("ErDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(tu),entities:i.O31(ty).pipe(i.fXn,i.Sr8(i.tJb(1))),relationships:i.O31(tw).pipe(i.fXn,i.tiU(o.PyW([]))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let tb=i.xCb(["er_too_large","invalid_entity_id","duplicate_entity_id","duplicate_entity_name","duplicate_field_name","er_text_too_long","nullable_primary_key","duplicate_relationship_id","missing_relationship_entity","missing_relationship_field","self_referencing_field"]);function tk(e){return e.name??e.id}function tM(e){let t=e.indexOf(".");return t<0?{entity:e.trim()}:{entity:e.slice(0,t).trim(),field:e.slice(t+1).trim()}}function tC(e){return e.trim().toLowerCase()}function tz(e){let t=[],a=e.entities.reduce((e,t)=>e+t.fields.length,0);e.entities.length>30&&t.push({code:"er_too_large",path:"entities",message:`The diagram has ${e.entities.length} entities; the supported maximum is 30.`,hint:"Split the schema into diagrams by area, or leave out minor lookup tables."}),a>240&&t.push({code:"er_too_large",path:"entities",message:`The diagram has ${a} fields; the supported maximum is 240.`,hint:"Keep the keys and the fields the request names, or split the schema by area."}),e.relationships.length>60&&t.push({code:"er_too_large",path:"relationships",message:`The diagram has ${e.relationships.length} relationships; the supported maximum is 60.`,hint:"Split the schema into diagrams by area."});let s=new Map,i=new Map;e.entities.forEach((e,a)=>{let l=`entities.[${a}]`;/[.:\s]/u.test(e.id)&&t.push({code:"invalid_entity_id",path:`${l}.id`,message:`Entity id "${e.id}" contains a dot, a colon or a space.`,hint:'Use letters, digits, hyphens or underscores in entity ids; relationships write "entity.field".'}),s.has(e.id)&&t.push({code:"duplicate_entity_id",path:`${l}.id`,message:`Entity id "${e.id}" is used more than once.`,hint:"Give every entity a unique id."}),s.set(e.id,e);let o=tk(e),r=i.get(tC(o));void 0!==r&&r!==e.id&&t.push({code:"duplicate_entity_name",path:void 0===e.name?`${l}.id`:`${l}.name`,message:`Entities "${r}" and "${e.id}" are both named "${o}".`,hint:"Give every entity a distinct name, or merge the two."}),i.set(tC(o),e.id),o.length>64&&t.push({code:"er_text_too_long",path:void 0===e.name?`${l}.id`:`${l}.name`,message:`Entity name "${o}" is longer than 64 characters.`,hint:"Shorten the entity name."}),e.fields.length>40&&t.push({code:"er_too_large",path:`${l}.fields`,message:`Entity "${e.id}" has ${e.fields.length} fields; the supported maximum is 40.`,hint:"Keep the keys and the fields the request names."});let n=new Set;e.fields.forEach((a,s)=>{let i=`${l}.fields.[${s}]`;for(let[s,l]of(n.has(tC(a.name))&&t.push({code:"duplicate_field_name",path:`${i}.name`,message:`Entity "${e.id}" has more than one field named "${a.name}".`,hint:"List each field once."}),n.add(tC(a.name)),[["name",a.name],["type",a.type]]))void 0!==l&&(l.length>64||/\n/u.test(l))&&t.push({code:"er_text_too_long",path:`${i}.${s}`,message:`Field ${s} "${l}" of "${e.id}" is longer than 64 characters or spans lines.`,hint:`Write the field ${s} on one line of at most 64 characters.`});a.pk&&a.nullable&&t.push({code:"nullable_primary_key",path:`${i}.nullable`,message:`Primary key "${e.id}.${a.name}" is marked nullable.`,hint:"A primary key is never empty; drop nullable from it."})})});let l=new Set;return e.relationships.forEach((e,a)=>{let i=`relationships.[${a}]`;l.has(e.id)&&t.push({code:"duplicate_relationship_id",path:`${i}.id`,message:`Relationship id "${e.id}" is used more than once.`,hint:"Give every relationship a unique id, or omit ids to generate them."}),l.add(e.id);let[o,r]=["from","to"].map(a=>{let l=tM(e[a]),o=s.get(l.entity);return o?void 0===l.field||o.fields.some(e=>tC(e.name)===tC(l.field))?l:void t.push({code:"missing_relationship_field",path:`${i}.${a}`,message:`Relationship "${e.id}" names field "${l.field}", which "${o.id}" does not have.`,hint:`Name one of the fields of "${o.id}", add the field, or name the entity alone.`}):void t.push({code:"missing_relationship_entity",path:`${i}.${a}`,message:`Relationship "${e.id}" ${"from"===a?"starts":"ends"} at "${l.entity}", which is not an entity.`,hint:'Set it to an entity id, or "entity.field" for the column the relationship runs through.'})});o?.field!==void 0&&r?.field!==void 0&&o.entity===r.entity&&tC(o.field)===tC(r.field)&&t.push({code:"self_referencing_field",path:i,message:`Relationship "${e.id}" joins "${o.entity}.${o.field}" to itself.`,hint:"A self-reference runs from the foreign key to the key it references, such as employees.manager_id to employees.id."})}),t.slice(0,20)}i.Xsx("ErValidationIssue")({code:tb,path:i.ukk,message:i.ukk,hint:i.ukk});class t_ extends I{issues;constructor(e){super(e[0]?.message??"ER diagram failed semantic validation."),this.issues=e,this.name="ErValidationError"}}function tL(e){var t=i.svK(tx,{errors:"all"})(e);let a=tz(t);if(a.length>0)throw new t_(a);return t}tL({id:"shop-schema",title:"Shop schema",type:tu,entities:[{id:"customers",fields:[{name:"id",type:"uuid",pk:!0},{name:"email",type:"text",unique:!0},{name:"name",type:"text"}]},{id:"orders",fields:[{name:"id",type:"uuid",pk:!0},{name:"customer_id",type:"uuid",fk:!0},{name:"placed_at",type:"timestamptz"},{name:"shipped_at",type:"timestamptz",nullable:!0}]},{id:"order_items",fields:[{name:"order_id",type:"uuid",pk:!0,fk:!0},{name:"product_id",type:"uuid",pk:!0,fk:!0},{name:"quantity",type:"int"}]},{id:"products",fields:[{name:"id",type:"uuid",pk:!0},{name:"sku",type:"text",unique:!0},{name:"price",type:"numeric(10,2)"}]}],relationships:[{id:"places",from:"customers.id",to:"orders.customer_id",fromCardinality:"one",toCardinality:"zero-or-many",label:"places"},{id:"contains",from:"orders.id",to:"order_items.order_id",fromCardinality:"one",toCardinality:"one-or-many"},{id:"ordered-as",from:"products.id",to:"order_items.product_id",fromCardinality:"one",toCardinality:"zero-or-many"}]}),tL({id:"org-schema",title:"Org schema",type:tu,entities:[{id:"employees",fields:[{name:"id",type:"int",pk:!0},{name:"manager_id",type:"int",fk:!0,nullable:!0},{name:"department_id",type:"int",fk:!0},{name:"name",type:"text"}]},{id:"departments",fields:[{name:"id",type:"int",pk:!0},{name:"head_id",type:"int",fk:!0,unique:!0,nullable:!0},{name:"name",type:"text",unique:!0}]}],relationships:[{id:"reports-to",from:"employees.id",to:"employees.manager_id",fromCardinality:"zero-or-one",toCardinality:"zero-or-many",label:"manages"},{id:"works-in",from:"departments.id",to:"employees.department_id",fromCardinality:"one",toCardinality:"one-or-many"},{id:"heads",from:"employees.id",to:"departments.head_id",fromCardinality:"zero-or-one",toCardinality:"zero-or-one",label:"heads"}]});let tB={PK:"pk",FK:"fk",UK:"unique",UQ:"unique",UNIQUE:"unique",NULL:"nullable",NULLABLE:"nullable","?":"nullable"};function tS(e){let t=e.trim().split(/\s+/u).filter(Boolean),a={},s=e=>tB[e.toUpperCase()];for(;t.length>1;){let e=t.at(-1);if("NULL"===e.toUpperCase()&&t.at(-2)?.toUpperCase()==="NOT"){t.splice(-2,2);continue}let i=s(e)??(e.length>1&&e.endsWith("?")?s(e.slice(0,-1)):void 0);if(!i)break;a[i]=!0,e.length>1&&e.endsWith("?")&&(a.nullable=!0),t.pop()}for(;t.length>1&&/^(?:PK|FK|UK)$/u.test(t[0]);)a[s(t.shift())]=!0;let i=t.shift()??e.trim(),l=t.join(" ");return l.endsWith("?")&&(l=l.slice(0,-1).trim(),a.nullable=!0),!l&&i.length>1&&i.endsWith("?")&&(i=i.slice(0,-1),a.nullable=!0),{name:i,...l?{type:l}:{},...a}}let tA={1:"one","1..1":"one","exactly-one":"one","one-and-only-one":"one","only-one":"one","mandatory-one":"one","0..1":"zero-or-one","0-1":"zero-or-one","0-or-1":"zero-or-one",optional:"zero-or-one","optional-one":"zero-or-one","one-or-zero":"zero-or-one","at-most-one":"zero-or-one","*":"many",n:"many",m:"many",multiple:"many","1..*":"one-or-many","1..n":"one-or-many","1-n":"one-or-many","1+":"one-or-many","at-least-one":"one-or-many","one-or-more":"one-or-many","many-mandatory":"one-or-many","0..*":"zero-or-many","0..n":"zero-or-many","0-n":"zero-or-many","0+":"zero-or-many","zero-or-more":"zero-or-many","optional-many":"zero-or-many","many-optional":"zero-or-many"};function tP(e){if("string"!=typeof e)return e;let t=e.trim().toLowerCase().replace(/[\s_]+/gu,"-");return tf.includes(t)?t:tA[t]??e}let tV=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),tH="class",tq=["class","abstract","interface","enum"],tF=i.xCb(tq),tI=["public","private","protected","package"],tE=i.xCb(tI),tO={public:"+",private:"-",protected:"#",package:"~"},tU=["inheritance","realization","composition","aggregation","association","dependency"],tX=i.xCb(tU);function tT(e){return"inheritance"===e||"realization"===e}function tY(e){return"association"===e||"composition"===e||"aggregation"===e}class t$ extends i.Xsx("ClassAttribute")({name:i.ukk,type:i.Qrq(i.ukk),visibility:i.Qrq(tE),static:i.Qrq(i.v8c)}){}class tG extends i.Xsx("ClassParameter")({name:i.ukk,type:i.Qrq(i.ukk)}){}class tD extends i.Xsx("ClassMethod")({name:i.ukk,params:i.O31(tG).pipe(i.fXn,i.tiU(o.PyW([]))),returns:i.Qrq(i.ukk),visibility:i.Qrq(tE),static:i.Qrq(i.v8c),abstract:i.Qrq(i.v8c)}){}class tR extends i.Xsx("ClassNode")({id:i.ukk,name:i.Qrq(i.ukk),kind:i.Qrq(tF),stereotype:i.Qrq(i.ukk),attributes:i.O31(t$).pipe(i.fXn,i.tiU(o.PyW([]))),methods:i.O31(tD).pipe(i.fXn,i.tiU(o.PyW([])))}){}class tZ extends i.Xsx("ClassRelationship")({id:i.ukk,kind:tX,from:i.ukk,to:i.ukk,fromMultiplicity:i.Qrq(i.ukk),toMultiplicity:i.Qrq(i.ukk),fromRole:i.Qrq(i.ukk),toRole:i.Qrq(i.ukk),navigable:i.Qrq(i.v8c),label:i.Qrq(i.ukk)}){}class tj extends i.Xsx("ClassDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(tH),classes:i.O31(tR).pipe(i.fXn,i.Sr8(i.tJb(1))),relationships:i.O31(tZ).pipe(i.fXn,i.tiU(o.PyW([]))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let tN=i.xCb(["class_too_large","invalid_class_id","duplicate_class_id","duplicate_class_name","duplicate_member","class_text_too_long","duplicate_relationship_id","missing_relationship_class","inheritance_cycle","invalid_inheritance","invalid_realization","invalid_multiplicity","misplaced_end_label"]);function tW(e){return e.name??e.id}function tJ(e){return e.kind??"class"}i.Xsx("ClassValidationIssue")({code:tN,path:i.ukk,message:i.ukk,hint:i.ukk});let tK={class:void 0,abstract:"abstract",interface:"interface",enum:"enumeration"};function tQ(e){return e?`${tO[e]} `:""}function t1(e){return`${tQ(e.visibility)}${e.name.trim()}${e.type?`: ${e.type.trim()}`:""}${e.static?" {static}":""}`}function t0(e){let t=e.params.map(e=>`${e.name.trim()}${e.type?`: ${e.type.trim()}`:""}`).join(", "),a=[e.abstract&&"{abstract}",e.static&&"{static}"].filter(Boolean);return`${tQ(e.visibility)}${e.name.trim()}(${t})${e.returns?`: ${e.returns.trim()}`:""}${a.length>0?` ${a.join(" ")}`:""}`}function t2(e){return e.trim().toLowerCase()}let t3=/^(\d+|\*)(?:\.\.(\d+|\*))?$/u;function t5(e){let t=[],a=e.classes.reduce((e,t)=>e+t.attributes.length+t.methods.length,0);e.classes.length>30&&t.push({code:"class_too_large",path:"classes",message:`The diagram has ${e.classes.length} classes; the supported maximum is 30.`,hint:"Split the model into diagrams by package, or leave out minor classes."}),a>300&&t.push({code:"class_too_large",path:"classes",message:`The diagram has ${a} members; the supported maximum is 300.`,hint:"Keep the members the request names, or split the model by package."}),e.relationships.length>60&&t.push({code:"class_too_large",path:"relationships",message:`The diagram has ${e.relationships.length} relationships; the supported maximum is 60.`,hint:"Split the model into diagrams by package."});let s=new Map,i=new Map;e.classes.forEach((e,a)=>{let l=`classes.[${a}]`;/[:\s]/u.test(e.id)&&t.push({code:"invalid_class_id",path:`${l}.id`,message:`Class id "${e.id}" contains a colon or a space.`,hint:"Use letters, digits, dots, hyphens or underscores in class ids, and put the shown name in name."}),s.has(e.id)&&t.push({code:"duplicate_class_id",path:`${l}.id`,message:`Class id "${e.id}" is used more than once.`,hint:"Give every class a unique id."}),s.set(e.id,e);let o=tW(e),r=void 0===e.name?`${l}.id`:`${l}.name`,n=i.get(t2(o));for(let[a,s,c]of(void 0!==n&&n!==e.id&&t.push({code:"duplicate_class_name",path:r,message:`Classes "${n}" and "${e.id}" are both named "${o}".`,hint:"Give every class a distinct name, or merge the two."}),i.set(t2(o),e.id),[["name",o,64],["stereotype",e.stereotype,64]]))void 0!==s&&(!(s.length<=c)||/\n/u.test(s))&&t.push({code:"class_text_too_long",path:"name"===a?r:`${l}.stereotype`,message:`The ${a} of "${e.id}" is longer than ${c} characters or spans lines.`,hint:`Write the ${a} on one line of at most ${c} characters.`});let c=e.attributes.length+e.methods.length;c>30&&t.push({code:"class_too_large",path:l,message:`Class "${e.id}" has ${c} members; the supported maximum is 30.`,hint:"Keep the members the request names."});let d=new Set,p=(a,s,i,o)=>{let r=`${l}.${a}.[${s}]`;d.has(o)&&t.push({code:"duplicate_member",path:r,message:`Class "${e.id}" lists ${"attributes"===a?"attribute":"method"} "${i}" more than once.`,hint:"List each member once; overloads differ in their parameters."}),d.add(o),(i.length>96||/\n/u.test(i))&&t.push({code:"class_text_too_long",path:r,message:`Member "${i}" of "${e.id}" is longer than 96 characters or spans lines.`,hint:"Write each member on one line of at most 96 characters."})};e.attributes.forEach((e,t)=>p("attributes",t,t1(e),`a:${t2(e.name)}`)),e.methods.forEach((e,t)=>p("methods",t,t0(e),`m:${t2(e.name)}(${e.params.map(e=>t2(e.type??e.name)).join(",")})`))});let l=new Set,o=new Map,r=new Set;e.relationships.forEach((e,a)=>{let i=`relationships.[${a}]`;l.has(e.id)&&t.push({code:"duplicate_relationship_id",path:`${i}.id`,message:`Relationship id "${e.id}" is used more than once.`,hint:"Give every relationship a unique id, or omit ids to generate them."}),l.add(e.id);let[n,c]=["from","to"].map(a=>{let l=s.get(e[a].trim());return l||t.push({code:"missing_relationship_class",path:`${i}.${a}`,message:`Relationship "${e.id}" ${"from"===a?"starts":"ends"} at "${e[a]}", which is not a class.`,hint:"Set it to the id of one of the classes."}),l}),{kind:d}=e;if(n&&c&&tT(d)){let e=`${d}\0${n.id}\0${c.id}`,[a,s]=[tJ(n),tJ(c)];r.has(e)?t.push({code:"inheritance"===d?"invalid_inheritance":"invalid_realization",path:i,message:`"${n.id}" ${"inheritance"===d?"extends":"implements"} "${c.id}" more than once.`,hint:"Draw each generalization once."}):n.id===c.id?t.push({code:"inheritance_cycle",path:i,message:`"${n.id}" ${"inheritance"===d?"extends":"implements"} itself.`,hint:"A class extends or implements another class, never itself."}):"inheritance"===d&&"interface"===a!=("interface"===s)?t.push({code:"invalid_inheritance",path:i,message:"interface"===a?`Interface "${n.id}" extends "${c.id}", which is not an interface.`:`"${n.id}" extends interface "${c.id}".`,hint:"interface"===a?"An interface extends only interfaces; make the class implement the interface instead (a realization from the class to the interface).":'A class implements an interface: use kind "realization" from the class to the interface.'}):"realization"===d&&("interface"===a||"interface"!==s)&&t.push({code:"invalid_realization",path:i,message:"interface"===a?`Interface "${n.id}" implements "${c.id}".`:`"${n.id}" implements "${c.id}", which is not an interface.`,hint:"interface"===a?'An interface extends another interface: use kind "inheritance".':'Mark "to" as kind "interface", or use kind "inheritance" to extend a class.'}),r.add(e),n.id!==c.id&&o.set(n.id,[...o.get(n.id)??[],c.id])}let p=tY(d);for(let a of["from","to"])for(let s of[`${a}Multiplicity`,`${a}Role`]){let a=e[s];void 0!==a&&(p?a.length>64||/\n/u.test(a)?t.push({code:"class_text_too_long",path:`${i}.${s}`,message:`"${a}" at an end of "${e.id}" is longer than 64 characters or spans lines.`,hint:"Write it on one short line."}):s.endsWith("Multiplicity")&&!function(e){let t=t3.exec(e.trim());if(!t)return!1;let[,a,s]=t;return void 0===s||"*"!==a&&("*"===s||Number(a)<=Number(s))}(a)?t.push({code:"invalid_multiplicity",path:`${i}.${s}`,message:`Multiplicity "${a}" of "${e.id}" is not a UML multiplicity.`,hint:'Write a bound or a range: "1", "0..1", "*", "1..*", "0..*" or "2..4".'}):"fromMultiplicity"!==s||"composition"!==d||["1","0..1","1..1"].includes(a.trim())||t.push({code:"invalid_multiplicity",path:`${i}.${s}`,message:`Composition "${e.id}" gives its whole "${e.from}" multiplicity "${a}".`,hint:'A part belongs to one whole at a time: write "1" or "0..1", or use an aggregation for a shared part.'}):t.push({code:"misplaced_end_label",path:`${i}.${s}`,message:`${"dependency"===d?"A dependency":`An ${d}`} "${e.id}" has a ${s.endsWith("Role")?"role":"multiplicity"}.`,hint:"Only associations, compositions and aggregations carry multiplicities and roles; drop it."}))}void 0===e.navigable||p||t.push({code:"misplaced_end_label",path:`${i}.navigable`,message:`${"dependency"===d?"A dependency":`An ${d}`} "${e.id}" is marked navigable.`,hint:"dependency"===d?"A dependency always draws its arrow; drop navigable.":"Only associations, compositions and aggregations take navigable; drop it."}),void 0!==e.label&&e.label.length>64&&t.push({code:"class_text_too_long",path:`${i}.label`,message:`The label of "${e.id}" is longer than 64 characters.`,hint:"Shorten the label."})});let n=new Map,c=(e,t)=>{for(let a of(n.set(e,1),o.get(e)??[])){if(1===n.get(a))return[...t.slice(t.indexOf(a)),a];if(void 0===n.get(a)){let e=c(a,[...t,a]);if(e)return e}}n.set(e,2)};for(let e of o.keys()){if(n.has(e))continue;let a=c(e,[e]);if(a){t.push({code:"inheritance_cycle",path:"relationships",message:`Inheritance runs in a cycle: ${a.join(" → ")}.`,hint:"A class never extends one of its own subclasses; drop or reverse one generalization."});break}}return t.slice(0,20)}class t4 extends I{issues;constructor(e){super(e[0]?.message??"Class diagram failed semantic validation."),this.issues=e,this.name="ClassValidationError"}}function t6(e){var t=i.svK(tj,{errors:"all"})(e);let a=t5(t);if(a.length>0)throw new t4(a);return t}let t7={"+":"public","-":"private","#":"protected","~":"package",public:"public",private:"private",protected:"protected",package:"package",internal:"package"};function t8(e){let t=e.trim(),a={};for(;;){let e=/^([+\-#~])\s*/u.exec(t);if(e&&!a.visibility){a.visibility=t7[e[1]],t=t.slice(e[0].length);continue}let s=/^(public|private|protected|package|internal|static|abstract)\s+/iu.exec(t);if(!s)break;let i=s[1].toLowerCase();"static"===i?a.static=!0:"abstract"===i?a.abstract=!0:a.visibility=t7[i],t=t.slice(s[0].length)}for(;;){let e=/\s*(?:\{(static|abstract)\}|([$*]))$/iu.exec(t);if(!e||0===e.index)break;let s=(e[1]??e[2]).toLowerCase();"static"===s||"$"===s?a.static=!0:a.abstract=!0,t=t.slice(0,e.index)}return{rest:t.trim(),modifiers:a}}function t9(e){let t=e.indexOf(":");if(t<0)return{name:e.trim()};let[a,s]=[e.slice(0,t).trim(),e.slice(t+1).trim()];return{name:a||e.trim(),...a&&s?{type:s}:{}}}function ae(e){let t=[],a=0,s=0;for(let i=0;i<e.length;i+=1){let l=e[i];"<([{".includes(l)?a+=1:">)]}".includes(l)?a=Math.max(0,a-1):","===l&&0===a&&(t.push(e.slice(s,i)),s=i+1)}return t.push(e.slice(s)),t.map(e=>e.trim()).filter(Boolean)}function at(e){let{rest:t,modifiers:a}=t8(e),{visibility:s,static:i}=a;return{...t9(t),...s?{visibility:s}:{},...i?{static:!0}:{}}}function aa(e){let{rest:t,modifiers:a}=t8(e),s=t.indexOf("("),i=function(e,t){if(t<0)return -1;let a=0;for(let s=t;s<e.length;s+=1)if("("===e[s])a+=1;else if(")"===e[s]&&0==(a-=1))return s;return -1}(t,s),l={...a.visibility?{visibility:a.visibility}:{},...a.static?{static:!0}:{},...a.abstract?{abstract:!0}:{}};if(s<0||i<s){let{name:e,type:a}=t9(t);return{name:e,params:[],...a?{returns:a}:{},...l}}let o=t.slice(i+1).replace(/^\s*:\s*/u,"").trim();return{name:t.slice(0,s).trim()||t,params:ae(t.slice(s+1,i)).map(t9),...o?{returns:o}:{},...l}}let as={extends:"inheritance",inherits:"inheritance",generalization:"inheritance","is-a":"inheritance",implements:"realization",realizes:"realization","interface-realization":"realization",composes:"composition","composed-of":"composition",aggregates:"aggregation","uses-a":"dependency",uses:"dependency",depends:"dependency","depends-on":"dependency",associates:"association"},ai={one:"1","exactly-one":"1","zero-or-one":"0..1",optional:"0..1",many:"*",n:"*",m:"*","zero-or-many":"0..*","zero-or-more":"0..*","one-or-many":"1..*","one-or-more":"1..*"},al=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function ao(e){if(!al(e))return e;let t=(e,t)=>{let a;if("string"==typeof e)return t?aa(e):at(e);if(!al(e))return e;let s={...e};if(void 0!==s.visibility&&(s.visibility="string"==typeof(a=s.visibility)?t7[a.trim().toLowerCase()]??a:a),t){void 0===s.returns&&void 0!==s.returnType&&(s.returns=s.returnType,delete s.returnType);let e=s.params??s.parameters;delete s.parameters,"string"==typeof e?s.params=ae(e).map(t9):Array.isArray(e)&&(s.params=e.map(e=>"string"==typeof e?t9(e):e))}return s},a=Array.isArray(e.classes)?e.classes.map(e=>{if(!al(e))return e;let{values:a,...s}=e,i=Array.isArray(s.attributes)?s.attributes:Array.isArray(a)?a:s.attributes;return{...s,...void 0===s.kind&&Array.isArray(a)?{kind:"enum"}:{},...Array.isArray(i)?{attributes:i.map(e=>t(e,!1))}:void 0===i?{}:{attributes:i},...Array.isArray(s.methods)?{methods:s.methods.map(e=>t(e,!0))}:{},..."string"==typeof s.kind?{kind:"enumeration"===s.kind.trim().toLowerCase()?"enum":s.kind.trim().toLowerCase()}:{}}}):e.classes,s=Array.isArray(e.relationships)?e.relationships.map(e=>{if(!al(e))return e;let{source:t,target:a,type:s,...i}=e,l={...i,from:i.from??t,to:i.to??a,kind:function(e){if("string"!=typeof e)return e;let t=e.trim().toLowerCase().replace(/[\s_]+/gu,"-");return tU.includes(t)?t:as[t]??e}(i.kind??s)};for(let e of["fromMultiplicity","toMultiplicity"])void 0!==l[e]&&(l[e]=function(e){if("number"==typeof e&&Number.isInteger(e)&&e>=0)return String(e);if("string"!=typeof e)return e;let t=e.trim(),a=ai[t.toLowerCase().replace(/[\s_]+/gu,"-")];return a||t.replace(/\s*\.\.\s*/gu,"..").replace(/(^|\.\.)[nm]$/iu,"$1*")}(l[e]));for(let e of["from","to","kind"])void 0===l[e]&&delete l[e];return l}):e.relationships;return{...e,...void 0===a?{}:{classes:a},...void 0===s?{}:{relationships:s}}}t6({id:"shapes",title:"Shapes",type:tH,classes:[{id:"Drawable",kind:"interface",methods:[{name:"draw",params:[{name:"ctx",type:"Canvas"}],returns:"void"}]},{id:"Shape",kind:"abstract",attributes:[{name:"x",type:"double",visibility:"protected"},{name:"y",type:"double",visibility:"protected"}],methods:[{name:"area",returns:"double",visibility:"public",abstract:!0},{name:"moveTo",params:[{name:"x",type:"double"},{name:"y",type:"double"}],returns:"void",visibility:"public"}]},{id:"Circle",attributes:[{name:"radius",type:"double",visibility:"private"}],methods:[{name:"area",returns:"double",visibility:"public"}]},{id:"Rectangle",attributes:[{name:"width",type:"double",visibility:"private"},{name:"height",type:"double",visibility:"private"}],methods:[{name:"area",returns:"double",visibility:"public"}]},{id:"Square",methods:[{name:"of",params:[{name:"side",type:"double"}],returns:"Square",visibility:"public",static:!0}]},{id:"Canvas",attributes:[{name:"MAX_SHAPES",type:"int",visibility:"public",static:!0}],methods:[{name:"add",params:[{name:"shape",type:"Shape"}],returns:"void",visibility:"public"}]}],relationships:[{id:"shape-draws",kind:"realization",from:"Shape",to:"Drawable"},{id:"circle-is-shape",kind:"inheritance",from:"Circle",to:"Shape"},{id:"rectangle-is-shape",kind:"inheritance",from:"Rectangle",to:"Shape"},{id:"square-is-rectangle",kind:"inheritance",from:"Square",to:"Rectangle"},{id:"canvas-holds",kind:"aggregation",from:"Canvas",to:"Shape",fromMultiplicity:"1",toMultiplicity:"0..*",toRole:"shapes"}]});let ar="org-chart";class an extends i.Xsx("OrgPerson")({id:i.ukk,name:i.ukk,title:i.Qrq(i.ukk),department:i.Qrq(i.ukk),manager:i.Qrq(i.ukk),assistant:i.Qrq(i.v8c),avatar:i.Qrq(i.v8c)}){}class ac extends i.Xsx("OrgDottedLine")({id:i.ukk,report:i.ukk,manager:i.ukk,label:i.Qrq(i.ukk)}){}class ad extends i.Xsx("OrgChartDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(ar),people:i.O31(an).pipe(i.fXn,i.Sr8(i.tJb(1))),dottedLines:i.O31(ac).pipe(i.fXn,i.tiU(o.PyW([]))),groupByDepartment:i.Qrq(i.v8c),forest:i.Qrq(i.v8c),style:H.pipe(i.tiU(o.PyW({...y})))}){}let ap=i.xCb(["org_chart_too_large","invalid_person_id","duplicate_person_id","org_text_too_long","unknown_manager","self_manager","reporting_cycle","multiple_roots","invalid_assistant","duplicate_dotted_line_id","invalid_dotted_line"]);function ah(e){return e.people.filter(e=>void 0===e.manager)}function ag(e){let t=new Map;for(let a of e.people){if(void 0===a.manager)continue;let e=t.get(a.manager)??[];e.push(a),t.set(a.manager,e)}return t}function au(e){let t=[],a=(e,a,s,i)=>t.push({code:e,path:a,message:s,hint:i}),{people:s,dottedLines:i}=e;s.length>100&&a("org_chart_too_large","people",`An org chart holds at most 100 people; this one has ${s.length}.`,"Draw each division as its own chart, or keep the levels the request asks for."),i.length>24&&a("org_chart_too_large","dottedLines",`An org chart holds at most 24 dotted lines; this one has ${i.length}.`,"Keep the dotted-line reports the request states.");let l=new Set;s.forEach((e,t)=>{let s=`people.[${t}]`;e.id.includes(":")&&a("invalid_person_id",`${s}.id`,`Person id "${e.id}" contains a colon.`,"Use a short id without colons, such as ada or vp-eng."),l.has(e.id)&&a("duplicate_person_id",`${s}.id`,`Person id "${e.id}" is used more than once.`,"Give each person a unique id; two people with one name need two ids."),l.add(e.id);let i=(t,i,l)=>{void 0!==i&&i.trim().length>l&&a("org_text_too_long",`${s}.${t}`,`The ${t} of "${e.id}" is longer than ${l} characters.`,`Shorten the ${t} to at most ${l} characters.`)};i("name",e.name,60),i("title",e.title,80),i("department",e.department,40)});let o=ag(e);s.forEach((e,t)=>{let s=`people.[${t}]`;if(void 0===e.manager){e.assistant&&a("invalid_assistant",`${s}.assistant`,`Assistant "${e.id}" has no manager.`,"Set manager to the person they assist.");return}e.manager===e.id?a("self_manager",`${s}.manager`,`"${e.id}" is their own manager.`,"Set manager to the person they report to, or omit it for the top person."):l.has(e.manager)||a("unknown_manager",`${s}.manager`,`Manager "${e.manager}" of "${e.id}" is not a person in the chart.`,"Use the id of a person in people, or add the manager as a person."),e.assistant&&(o.get(e.id)?.length??0)>0&&a("invalid_assistant",`${s}.assistant`,`Assistant "${e.id}" has reports of their own.`,"An assistant sits beside their manager with no reports; drop assistant: true to draw them as a manager.")});let r=function(e){let t=new Map(e.map(e=>[e.id,e.manager])),a=new Set;for(let s of e){let e=[],i=new Set,l=s.id;for(;void 0!==l&&t.has(l)&&!a.has(l);){if(i.has(l))return[...e.slice(e.indexOf(l)),l];i.add(l),e.push(l),l=t.get(l)}for(let t of e)a.add(t)}}(s);r&&a("reporting_cycle",`people.[${s.findIndex(e=>e.id===r[0])}].manager`,`Reporting lines run in a cycle: ${r.join(" → ")}.`,"Every chain of managers ends at a top person with no manager; remove one manager on the cycle.");let n=ah(e);n.length>1&&!0!==e.forest&&a("multiple_roots",`people.[${s.indexOf(n[1])}].manager`,`${n.length} people have no manager: ${n.slice(0,4).map(e=>`"${e.id}"`).join(", ")}${n.length>4?", …":""}.`,"Give everyone but the top person a manager, or set forest: true to draw separate trees.");let c=new Map(s.map(e=>[e.id,e]));if(!r&&n.length>0){let e=new Map,t=a=>{let s=e.get(a.id);if(void 0!==s)return s;let i=void 0===a.manager?void 0:c.get(a.manager),l=i&&i.id!==a.id?t(i)+1:1;return e.set(a.id,l),l},i=Math.max(...s.map(t));i>12&&a("org_chart_too_large","people",`Reporting chains run ${i} levels deep; an org chart draws at most 12.`,"Draw the deepest teams as charts of their own.")}let d=new Set,p=new Set;return i.forEach((e,t)=>{let s=`dottedLines.[${t}]`;for(let t of(d.has(e.id)&&a("duplicate_dotted_line_id",`${s}.id`,`Dotted line id "${e.id}" is used more than once.`,"Give each dotted line a unique id."),d.add(e.id),["report","manager"]))l.has(e[t])||a("invalid_dotted_line",`${s}.${t}`,`Dotted line "${e.id}" names unknown ${t} "${e[t]}".`,"Use the ids of two people in the chart.");e.report===e.manager?a("invalid_dotted_line",s,`Dotted line "${e.id}" joins "${e.report}" to themselves.`,"A dotted line joins a person to a second manager."):c.get(e.report)?.manager===e.manager&&a("invalid_dotted_line",s,`"${e.report}" already reports to "${e.manager}" on a solid line.`,"Draw a dotted line only to a second manager, outside the solid reporting line.");let i=`${e.report}\0${e.manager}`;p.has(i)&&a("invalid_dotted_line",s,`"${e.report}" has two dotted lines to "${e.manager}".`,"Draw each dotted-line report once."),p.add(i),void 0!==e.label&&e.label.trim().length>40&&a("org_text_too_long",`${s}.label`,`The label of dotted line "${e.id}" is longer than 40 characters.`,"Shorten the label to at most 40 characters.")}),t.slice(0,20)}i.Xsx("OrgChartValidationIssue")({code:ap,path:i.ukk,message:i.ukk,hint:i.ukk});class af extends I{issues;constructor(e){super(e[0]?.message??"Org chart failed semantic validation."),this.issues=e,this.name="OrgChartValidationError"}}function am(e){let t=au(e);if(t.length>0)throw new af(t);return e}function av(e){return am(i.svK(ad,{errors:"all"})(e))}let ay=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function aw(e,t){let a;for(let s of t)void 0===a&&void 0!==e[s]&&(a=e[s]),delete e[s];return a}let ax=["manager","reportsTo","managerId","manager_id","reports_to","parent","boss"],ab=["title","role","position","jobTitle","job_title"],ak=["department","team","dept","division","group"],aM=["dottedLines","dottedLine","dottedLineTo","dottedManager","dottedManagers"];function aC(e){if(!ay(e))return e;let{employees:t,members:a,reportingLines:s,reports:i,edges:l,...o}=e,r=o.people??t??a,n=[],c=new Map;if(Array.isArray(r)){for(let e of r)if(ay(e)){for(let t of["directReports","reports"])if(Array.isArray(e[t]))for(let a of e[t])"string"!=typeof a||c.has(a)||c.set(a,e.id)}}let d=Array.isArray(r)?r.map(e=>{if(!ay(e))return e;let t={...e};Array.isArray(t.directReports)&&delete t.directReports,Array.isArray(t.reports)&&delete t.reports;let a=aw(t,ax)??c.get(t.id),s=aw(t,ab),i=aw(t,ak),l=aw(t,aM),o=t.name??t.label;for(let e of(delete t.label,("assistant"===t.kind||"assistant"===t.type)&&(t.assistant=!0,delete t.kind,delete t.type),Array.isArray(l)?l:void 0===l?[]:[l]))n.push(ay(e)?{report:t.id,...e}:{report:t.id,manager:e});return{...t,...void 0===o?{}:{name:o},...null==a||""===a?{}:{manager:a},...void 0===s||""===s?{}:{title:s},...void 0===i||""===i?{}:{department:i}}}):r,p=[s,i,l].find(Array.isArray),h=Array.isArray(d)&&p?d.map(e=>{if(!ay(e)||void 0!==e.manager)return e;let t=p.find(t=>ay(t)&&(t.report??t.to??t.target)===e.id&&!0!==t.dotted),a=ay(t)?t.manager??t.from??t.source:void 0;return void 0===a?e:{...e,manager:a}}):d,g=(p??[]).filter(e=>ay(e)&&!0===e.dotted),u=o.dottedLines,f=[...Array.isArray(u)?u:null==u?[]:[u],...n,...g.map(({dotted:e,...t})=>({report:t.report??t.to??t.target,manager:t.manager??t.from??t.source,...void 0===t.label?{}:{label:t.label}}))],m=new Set(f.flatMap(e=>ay(e)&&"string"==typeof e.id?[e.id]:[])),v=f.map(e=>{if(!ay(e))return e;let{from:t,to:a,source:s,target:i,person:l,employee:o,...r}=e,n={...r,report:r.report??t??s??l??o,manager:r.manager??a??i};for(let e of["report","manager"])void 0===n[e]&&delete n[e];if("string"!=typeof n.id||0===n.id.length){let e=`${String(n.report)}-dotted-${String(n.manager)}`.replace(/[^\w-]+/gu,"-"),t=e;for(let a=2;m.has(t);a+=1)t=`${e}-${a}`;m.add(t),n.id=t}return n});return{...o,...void 0===h?{}:{people:h},...void 0===u&&0===v.length?{}:{dottedLines:v}}}av({id:"startup-team",title:"Startup team",type:ar,people:[{id:"ada",name:"Ada Lovelace",title:"Chief Executive Officer",department:"Executive"},{id:"grace",name:"Grace Hopper",title:"Executive Assistant",department:"Executive",manager:"ada",assistant:!0},{id:"linus",name:"Linus Torvalds",title:"Chief Technology Officer",department:"Engineering",manager:"ada"},{id:"margaret",name:"Margaret Hamilton",title:"Engineering Manager",department:"Engineering",manager:"linus"},{id:"ken",name:"Ken Thompson",title:"Platform Engineer",department:"Engineering",manager:"linus"},{id:"radia",name:"Radia Perlman",title:"Head of Product",department:"Product",manager:"ada"},{id:"don",name:"Don Norman",title:"Product Designer",department:"Product",manager:"radia"}],dottedLines:[{id:"ken-to-radia",report:"ken",manager:"radia"}]});let az=[0,.25,.5,.75,1];function a_(e){return Math.round(100*e)/100}function aL(e){let[t,a,s,i]=e;return az.map(e=>{let l=1-e,[o,r,n,c]=[l*l*l,3*l*l*e,3*l*e*e,e*e*e];return{x:a_(o*t.x+r*a.x+n*s.x+c*i.x),y:a_(o*t.y+r*a.y+n*s.y+c*i.y)}})}let aB=new Intl.Segmenter(void 0,{granularity:"grapheme"}),aS=/\p{Emoji_Presentation}|\uFE0F|\p{Regional_Indicator}|\u20E3/u,aA=/^[\uFE00-\uFE0F\u200B-\u200D\u2060]+$/u;function aP(e){return Array.from(aB.segment(e),e=>e.segment)}function aV(e){var t;return aA.test(e)?0:aS.test(e)?130:(t=e.codePointAt(0)??0)>=4352&&t<=4447||t>=11904&&t<=12350||t>=12353&&t<=13311||t>=13312&&t<=19903||t>=19968&&t<=40959||t>=40960&&t<=42191||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65072&&t<=65103||t>=65280&&t<=65376||t>=65504&&t<=65510||t>=131072&&t<=262141?100:62}function aH(e){return aP(e).reduce((e,t)=>e+aV(t),0)}function aq(e,t){return Math.max(...e.split("\n").map(e=>(function(e,t){let a=0,s=0;for(let t of aP(e)){let e=aV(t);62===e?a+=1:s+=e}return a*t*.62+s*t/100})(e,t)))}function aF(e,t,a){let s=aq(e,t);return Math.max(1,Math.min(a,Math.ceil(s)),Math.ceil(s-t))}function aI(e,t,a){return Math.max(aF(e,t,a),Math.ceil(aq(e,t)))}function aE(e,t){return e.split("\n").flatMap(e=>(function(e,t){if(aH(e)<=t)return[e];let a=[],s="";for(let i of e.split(" ")){if(aH(i)>t){s&&(a.push(s),s=""),a.push(...function(e,t){let a=(function(e){let t=[],a="";for(let s of aP(e)){if(!(aV(s)>62)){a+=s;continue}a&&t.push(a),t.push(s),a=""}return a&&t.push(a),t})(e).flatMap(e=>aH(e)>t?function(e,t){let a=Math.max(t,1488);return aH(e)<=a?[e]:e.split(/(?<=[/\-_.])(?=.)|(?<=\p{Ll})(?=\p{Lu})/u).flatMap(e=>aH(e)<=a?[e]:function(e,t){let a=[],s="",i=0;for(let l of aP(e)){let e=aV(l);s&&i+e>t&&(a.push(s),s="",i=0),s+=l,i+=e}return s&&a.push(s),a}(e,t))}(e,t):[e]),s=[],i="";for(let e of a){if(aH(e)>t){i&&s.push(i),s.push(e),i="";continue}i&&aH(i+e)>t&&(s.push(i),i=""),i+=e}return i&&s.push(i),s}(i,t));continue}let e=s?`${s} ${i}`:i;if(aH(e)<=t){s=e;continue}a.push(s),s=i}return s&&a.push(s),a})(e,t)).join("\n")}function aO(e,t,a){return aE(e,Math.floor(100*t/a+1e-6))}let aU=Object.freeze({maxDimension:16384,maxElements:600,maxGroupsPerElement:16,maxLayouts:128,maxLayers:64,maxPointsPerElement:256,maxSerializedBytes:15e5,maxTextLength:4096,maxZOrderEntries:600}),aX=Object.freeze({boundTextPadding:5,gap:4,maxAssetBytes:65536,maxSize:64,maxTotalAssetBytes:786432,minSize:16}),aT=["cylinder","pipe","document","bucket"];function aY(e){return aT.includes(e)}let a$={cylinder:12,pipe:12,document:5,bucket:12};function aG(e){return Math.round(.08*e)}function aD(e,t,a,s,i,l,o=12){return Array.from({length:o+1},(r,n)=>{let c=i+(l-i)*n/o;return{x:Math.round((e+a*Math.cos(c))*100)/100,y:Math.round((t+s*Math.sin(c))*100)/100}})}function aR(e,t,a,s=12,i=0){let{x:l,y:o,width:r,height:n}=e,c=l+r/2,d=o+n/2;if(a){let e=o+t,a=o+n-t;return{back:aD(c,e,r/2,t,0,-Math.PI,s),front:aD(c,e,r/2,t,Math.PI,0,s),end:aD(c,a,r/2-i,t,Math.PI,0,s),sides:[[{x:l,y:e},{x:l+i,y:a}],[{x:l+r,y:e},{x:l+r-i,y:a}]]}}let p=l+r-t,h=l+t;return{back:aD(p,d,t,n/2,-Math.PI/2,Math.PI/2,s),front:aD(p,d,t,n/2,-Math.PI/2,-(3*Math.PI)/2,s),end:aD(h,d,t,n/2,Math.PI/2,3*Math.PI/2,s),sides:[[{x:h,y:o},{x:p,y:o}],[{x:h,y:o+n},{x:p,y:o+n}]]}}function aZ(e,t){let{x:a,y:s,width:i,height:l}=e;return Array.from({length:17},(e,o)=>{let r=1-o/16;return{x:Math.round((a+i*r)*100)/100,y:Math.round((s+l-t*(1-Math.cos(4*Math.PI*r)))*100)/100}})}function aj(e,t,a){let{x:s,y:i,width:l,height:o}=e,r=a$[e.shape],n=s+l/2,c=i+o/2,d=(e,t)=>r*Math.sqrt(Math.max(0,1-(Math.min(Math.abs(e),t)/t)**2));if("pipe"===e.shape)return"left"===t?{x:s+r-d(a.y-c,o/2),y:a.y}:"right"===t?{x:s+l-r+d(a.y-c,o/2),y:a.y}:a;if("document"===e.shape){if("bottom"!==t)return a;let e=Math.min(1,Math.max(0,(a.x-s)/l));return{x:a.x,y:i+o-r*(1-Math.cos(4*Math.PI*e))}}let p="bucket"===e.shape?aG(l):0,[h,g]=[i+r,i+o-r];if("top"===t)return{x:a.x,y:h-d(a.x-n,l/2)};if("bottom"===t)return{x:a.x,y:g+d(a.x-n,l/2-p)};if(0===p)return a;let u=p*(Math.min(g,Math.max(h,a.y))-h)/(g-h);return{x:"left"===t?s+u:s+l-u,y:a.y}}function aN(e,t,a=1){let s=aW(e);return s.slice(1).some((e,i)=>{let l=s[i],[o,r]=[e.x-l.x,e.y-l.y],n=Math.max(0,Math.min(1,((t.x-l.x)*o+(t.y-l.y)*r)/(o*o+r*r||1)));return Math.hypot(t.x-l.x-n*o,t.y-l.y-n*r)<=a})}function aW(e){let{x:t,y:a,width:s}=e,i=a$[e.shape];if("document"===e.shape)return[{x:t,y:a},{x:t+s,y:a},...aZ(e,i),{x:t,y:a}];let{back:l,end:o}=aR(e,i,"pipe"!==e.shape,24,"bucket"===e.shape?aG(s):0);return[...l,...o,l[0]]}let aJ=["zone","sequence-lifeline","sequence-activation","timeline-marker","chart-mark","state-marker","gantt-mark","er-table","er-optional","class-box","swimlane","swimlane-header"],aK=["sequence-lifeline","sequence-activation","timeline-marker","chart-mark","er-optional","swimlane","zone"],aQ={"chart-mark":"Chart mark","class-box":"Class box","er-optional":"Optional relationship end","er-table":"Entity table","gantt-mark":"Gantt mark","sequence-activation":"Sequence activation","sequence-lifeline":"Sequence lifeline","state-marker":"State marker",swimlane:"Swimlane","swimlane-header":"Swimlane header","timeline-marker":"Timeline marker",zone:"Zone"};function a1(e){let t=new Set;for(let a of e){if(t.has(a))return a;t.add(a)}}function a0(e){return"x"in e&&"y"in e}let a2=new TextEncoder;function a3(e){return a2.encode(e).byteLength}function a5(e){let t=aX.boundTextPadding;if("ellipse"===e.shape||"circle"===e.shape){let a=1-Math.SQRT1_2;return{x:t+e.width/2*a,y:t+e.height/2*a}}return"diamond"===e.shape?{x:t+e.width/4,y:t+e.height/4}:"pipe"===e.shape?{x:t+2*a$.pipe,y:t}:"bucket"===e.shape?{x:t+aG(e.width),y:t+2*a$.bucket}:"cylinder"===e.shape||"document"===e.shape?{x:t,y:t+2*a$[e.shape]}:{x:t,y:t}}function a4(e){let t=2*aX.boundTextPadding;return"ellipse"===e.shape||"circle"===e.shape?{width:Math.round(e.width/2*Math.SQRT2)-t,height:Math.round(e.height/2*Math.SQRT2)-t}:"diamond"===e.shape?{width:Math.round(e.width/2)-t,height:Math.round(e.height/2)-t}:"pipe"===e.shape?{width:e.width-t-4*a$.pipe,height:e.height-t}:"cylinder"===e.shape||"document"===e.shape?{width:e.width-t,height:e.height-t-4*a$[e.shape]}:"bucket"===e.shape?{width:e.width-t-2*aG(e.width),height:e.height-t-4*a$.bucket}:{width:e.width-t,height:e.height-t}}function a6(e){return e?e.size+2*aX.gap:0}function a7(e){let t=new Map(e.layers.map(e=>[e.id,e]));return e=>!e.layerId||t.get(e.layerId)?.visible!==!1}function a8(e,t){let a=new Map;for(let[s,i]of e.elements.entries())"text"===i.type&&i.containerId&&t(i)&&a.set(i.containerId,{element:i,index:s});return a}function a9(e,t,a){let s=t?.text??e.label,i=t?.fontSize??16,l=t?t.maxWidth??160:Math.max(1,e.width-24),o=s.split("\n"),r=aq(s,i),n=Math.max(1,Math.min(l,r)),c=Math.ceil(o.length*i*1.35);if(aF(s,i,l)-i+24>e.width)return!0;if(a||aY(e.shape)){let t=a4(e);return r>t.width||c+a6(a)>t.height}return n+24>e.width||c+18>e.height}function se(e){let t=[];0===e.elements.length&&t.push({code:"empty_canvas",message:"CanvasSpec must contain at least one element.",path:"elements"}),e.elements.length>aU.maxElements&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${aU.maxElements} elements.`,path:"elements"}),e.layers.length>aU.maxLayers&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${aU.maxLayers} layers.`,path:"layers"}),e.layouts.length>aU.maxLayouts&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${aU.maxLayouts} layout primitives.`,path:"layouts"}),(e.width>aU.maxDimension||e.height>aU.maxDimension)&&t.push({code:"limit_exceeded",message:`Canvas dimensions may not exceed ${aU.maxDimension}.`,path:"width"});let a=a1(e.elements.map(e=>e.id));a&&t.push({code:"duplicate_element_id",elementId:a,message:`Duplicate element id "${a}" is not allowed.`,path:"elements"});let s=a1(e.layers.map(e=>e.id));s&&t.push({code:"duplicate_layer_id",message:`Duplicate layer id "${s}" is not allowed.`,path:"layers"});let i=a1(e.zOrder);i&&t.push({code:"duplicate_z_order_element",elementId:i,message:`zOrder contains duplicate element "${i}".`,path:"zOrder"}),e.zOrder.length>aU.maxZOrderEntries&&t.push({code:"limit_exceeded",message:`zOrder exceeds ${aU.maxZOrderEntries} entries.`,path:"zOrder"});let l=new Map(e.elements.map(e=>[e.id,e])),o=e.elements.filter(e=>"node"===e.type),r=sd(e.elements),n=a1([...o.map(e=>e.nodeId),...e.elements.flatMap(e=>"frame"===e.type&&void 0!==e.nodeId?[e.nodeId]:[])]);n&&t.push({code:"invalid_binding",message:`Duplicate nodeId "${n}" makes connector bindings ambiguous.`,path:"elements"});let c=a1(e.elements.flatMap(e=>"arrow"===e.type?[e.edgeId]:[]));c&&t.push({code:"invalid_binding",message:`Duplicate edgeId "${c}" makes connector selection ambiguous.`,path:"elements"});let d=a1(e.elements.flatMap(e=>"text"===e.type&&e.containerId?[e.containerId]:[]));d&&t.push({code:"invalid_binding",elementId:d,message:`Container "${d}" has more than one bound text element.`,path:"elements"});let p=new Set(e.layers.map(e=>e.id)),h=a7(e),g=a8(e,h);t.push(...function(e){let t=[],a=0;for(let[s,i]of Object.entries(e.icons??{})){let e=a3(i.svg);a+=e,e>aX.maxAssetBytes&&t.push({code:"limit_exceeded",message:`Icon asset "${s}" exceeds ${aX.maxAssetBytes} bytes.`,path:`icons.${s}`})}return a>aX.maxTotalAssetBytes&&t.push({code:"limit_exceeded",message:`Icon assets exceed ${aX.maxTotalAssetBytes} bytes per canvas.`,path:"icons"}),t}(e)),e.elements.forEach((a,s)=>{let i,o;if(t.push(...(i=[],o=`elements[${s}]`,"width"in a&&"height"in a&&(!(a.width>0)||!(a.height>0))&&i.push({code:"invalid_geometry",elementId:a.id,message:`Element "${a.id}" must have positive width and height.`,path:o}),"points"in a&&void 0!==a.points&&a.points.length>aU.maxPointsPerElement&&i.push({code:"limit_exceeded",elementId:a.id,message:`Element "${a.id}" exceeds ${aU.maxPointsPerElement} points.`,path:`${o}.points`}),"text"in a&&a.text.length>aU.maxTextLength&&i.push({code:"limit_exceeded",elementId:a.id,message:`Text element "${a.id}" exceeds ${aU.maxTextLength} characters.`,path:`${o}.text`}),"node"===a.type&&"polygon"===a.shape&&(!a.points||a.points.length<3)&&i.push({code:"invalid_polygon",elementId:a.id,message:`Polygon "${a.id}" requires at least three points.`,path:`${o}.points`}),a.groupIds&&a.groupIds.length>aU.maxGroupsPerElement&&i.push({code:"limit_exceeded",elementId:a.id,message:`Element "${a.id}" exceeds ${aU.maxGroupsPerElement} groups.`,path:`${o}.groupIds`}),i)),"node"===a.type&&t.push(...function(e,t,a){let s=t.icon;if(!s)return[];let i=`elements[${a}].icon`,l=[];return t.rendererRole&&l.push({code:"invalid_icon",elementId:t.id,message:`${aQ[t.rendererRole]} "${t.id}" cannot carry an icon.`,path:i}),u(s.slug)?e.icons&&Object.hasOwn(e.icons,s.slug)||l.push({code:"invalid_icon",elementId:t.id,message:`Node "${t.id}" references icon "${s.slug}" without an embedded asset.`,path:`${i}.slug`}):l.push({code:"invalid_icon",elementId:t.id,message:`Node "${t.id}" has an invalid icon slug "${s.slug}".`,path:`${i}.slug`}),(!Number.isFinite(s.size)||s.size<aX.minSize||s.size>aX.maxSize)&&l.push({code:"invalid_icon",elementId:t.id,message:`Node "${t.id}" icon size must be ${aX.minSize}-${aX.maxSize}.`,path:`${i}.size`}),l}(e,a,s)),"node"===a.type&&"polygon"!==a.shape&&h(a)){let e=g.get(a.id);(e||void 0===a.rendererRole)&&a9(a,e?.element,a.icon)&&t.push({code:"label_overflow",elementId:e?.element.id??a.id,message:`Label does not fit inside node "${a.id}" without changing its geometry.`,path:e?`elements[${e.index}].text`:`elements[${s}].label`})}if(a.frameId){let e=l.get(a.frameId);e&&"frame"===e.type||t.push({code:"invalid_composition",elementId:a.id,message:`Element "${a.id}" references missing frame "${a.frameId}".`,path:`elements[${s}].frameId`})}if(a.layerId&&!p.has(a.layerId)&&t.push({code:"invalid_composition",elementId:a.id,message:`Element "${a.id}" references missing layer "${a.layerId}".`,path:`elements[${s}].layerId`}),a.groupIds&&a1(a.groupIds)&&t.push({code:"invalid_composition",elementId:a.id,message:`Element "${a.id}" contains duplicate group ids.`,path:`elements[${s}].groupIds`}),"text"===a.type&&a.containerId){let e=l.get(a.containerId);e&&("node"===e.type||"arrow"===e.type)||t.push({code:"invalid_binding",elementId:a.id,message:`Text "${a.id}" references unsupported container "${a.containerId}".`,path:`elements[${s}].containerId`})}if("arrow"===a.type&&(r.has(a.sourceNodeId)||t.push({code:"invalid_binding",elementId:a.id,message:`Connector "${a.id}" references missing source "${a.sourceNodeId}".`,path:`elements[${s}].sourceNodeId`}),r.has(a.targetNodeId)||t.push({code:"invalid_binding",elementId:a.id,message:`Connector "${a.id}" references missing target "${a.targetNodeId}".`,path:`elements[${s}].targetNodeId`})),"line"===a.type)for(let[e,i]of[["startBinding",a.startBinding],["endBinding",a.endBinding]]){let o=i?l.get(i.elementId):void 0;i&&(!o||"node"!==o.type&&"frame"!==o.type)&&t.push({code:"invalid_binding",elementId:a.id,message:`Line "${a.id}" references missing binding "${i.elementId}".`,path:`elements[${s}].${e}`})}});let f=new Set(e.zOrder);for(let a of e.elements)f.has(a.id)||t.push({code:"missing_z_order_element",elementId:a.id,message:`Element "${a.id}" is missing from zOrder.`,path:"zOrder"});for(let a of e.zOrder)l.has(a)||t.push({code:"unknown_z_order_element",elementId:a,message:`zOrder references missing element "${a}".`,path:"zOrder"});for(let[a,s]of e.layouts.entries())for(let e of s.ids){let s=l.get(e);s&&a0(s)||t.push({code:"unknown_layout_target",elementId:e,message:`Layout references missing or non-positioned element "${e}".`,path:`layouts[${a}].ids`})}for(let a of e.elements.filter(e=>"frame"===e.type)){let e=new Set([a.id]),s=a.frameId;for(;s;){if(e.has(s)){t.push({code:"invalid_composition",elementId:a.id,message:`Frame "${a.id}" participates in a frame nesting cycle.`,path:"elements"});break}e.add(s);let i=l.get(s);s=i?.type==="frame"?i.frameId:void 0}}return t}function st(e){if("text"===e.type){let t=e.text.split("\n");return{x:e.x,y:e.y,width:e.maxWidth??aq(e.text,e.fontSize),height:t.length*e.fontSize*(e.lineHeight??1.35)}}return{x:e.x,y:e.y,width:e.width,height:e.height}}function sa(e,t){let a=new Map(e.map(e=>[e.id,e]));return t.flatMap(e=>{let t=a.get(e);return t&&a0(t)?[t]:[]})}function ss(e,t){return e.map(e=>{var a,s;let i=t.get(e.id);return i?(a=i.x,s=i.y,a0(e)?{...e,x:a,y:s}:e):e})}function si(e,t){return"x"===t?e.x:e.y}function sl(e,t){return"x"===t?e.width:e.height}function so(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function sr(e,t){let a=so(e),s=t.x-a.x,i=t.y-a.y,[l,o]=Math.abs(s)>=Math.abs(i)?[s>=0?"right":"left",{x:s>=0?e.x+e.width:e.x,y:a.y}]:[i>=0?"bottom":"top",{x:a.x,y:i>=0?e.y+e.height:e.y}];return"type"in e&&"node"===e.type&&aY(e.shape)?aj({...e,shape:e.shape},l,o):o}function sn(e,t){let a=t.width/2,s=t.height/2,i=(e.x-t.x-a)/a,l=(e.y-t.y-s)/s,o="node"===t.type?t.shape:"rectangle";if("node"===t.type&&aY(t.shape))return aN({...t,shape:t.shape},e,1);let r=.5/Math.min(a,s);if("ellipse"===o||"circle"===o)return Math.abs(Math.hypot(i,l)-1)<=r;if("diamond"===o)return Math.abs(Math.abs(i)+Math.abs(l)-1)<=r;let n=(e,t,a)=>e>=t-.5&&e<=a+.5,c=(e,t)=>.5>=Math.abs(e-t);return n(e.y,t.y,t.y+t.height)&&(c(e.x,t.x)||c(e.x,t.x+t.width))||n(e.x,t.x,t.x+t.width)&&(c(e.y,t.y)||c(e.y,t.y+t.height))}function sc(e,t){let a=sr(e,so(t)),s=sr(t,so(e)),i=so(e),l=so(t),o=Math.abs(l.x-i.x)>=Math.abs(l.y-i.y),r=o?"x":"y",n=(s[r]-a[r])/2,c=(e,t)=>o?{x:e.x+t,y:e.y}:{x:e.x,y:e.y+t};return aL([a,c(a,n),c(s,-n),s])}function sd(e){return new Map(e.flatMap(e=>"node"===e.type||"frame"===e.type&&void 0!==e.nodeId?[[e.nodeId,e]]:[]))}function sp(e,t=.01){let a=[];for(let s=0;s<e.length-1;s+=1){let i=e[s],l=e[s+1];if(!i||!l)continue;let o=Math.abs(i.y-l.y)<=t,r=Math.abs(i.x-l.x)<=t;if(!o&&!r)continue;let n=Math.min(o?i.x:i.y,o?l.x:l.y),c=Math.max(o?i.x:i.y,o?l.x:l.y);c-n<=t||a.push({min:n,max:c,orientation:o?"horizontal":"vertical",staticCoordinate:o?i.y:i.x,segmentIndex:s,isFirstSegment:0===s,isLastSegment:s===e.length-2})}return a}function sh(e,t){return Math.min(e.max,t.max)-Math.max(e.min,t.min)}function sg(e,t,a=.01){return e.orientation===t.orientation&&Math.abs(e.staticCoordinate-t.staticCoordinate)<=a&&sh(e,t)>a}function su(e,t,a=.01){let s="horizontal"===e.orientation,i=s?t.y:t.x,l=i+(s?t.height:t.width),o=s?t.x:t.y,r=o+(s?t.width:t.height);return e.staticCoordinate>i+a&&e.staticCoordinate<l-a&&Math.min(e.max,r)-Math.max(e.min,o)>a}function sf(e,t){return e.isFirstSegment&&t.isFirstSegment&&null!==e.startBindingId&&e.startBindingId===t.startBindingId||e.isLastSegment&&t.isLastSegment&&null!==e.endBindingId&&e.endBindingId===t.endBindingId}function sm(e,t,a,s=0){let i=-1/0;for(let l of t)for(let t of e)l.x0<t.x1+s&&t.x0<l.x1+s&&(i=Math.max(i,t.y1+a-l.y0));return i}function sv(e,t,a,s=0){let i=-1/0;for(let l of t)for(let t of e)l.y0<t.y1+s&&t.y0<l.y1+s&&(i=Math.max(i,t.x1+a-l.x0));return i}function sy(e,t,a="characters"){let s=0x811c9dc5;for(let t=0;t<e.length;t+=1)s^=e.charCodeAt(t),s=Math.imul(s,0x1000193),"characters"===a&&(e.codePointAt(t)??0)>65535&&(t+=1);return"seed"===t?Math.abs(s)||1:(s>>>0).toString(16).padStart(8,"0")}i.gPz([ey,eA,eY,et,R,e0,ts,tx,tj,ad]);let sw={id:"multi-stage-rework",title:"Rework earlier stages",nodes:[{id:"start",label:"Received",kind:"start"},...["Intake","Validate","Assemble","Review","Rework","Release"].map((e,t)=>({id:String(t),label:e,kind:5===t?"end":"process"}))],edges:[{id:"start",source:"start",target:"0"},...Array.from({length:5},(e,t)=>({id:`e${t}`,source:String(t),target:String(t+1)})),...Array.from({length:4},(e,t)=>({id:`back${t}`,source:"4",target:String(t),...0===t?{label:"Retry"}:{}}))]},sx={id:"two-stage-retry",title:"Revisit earlier checks",nodes:[{id:"s",label:"Received",kind:"start"},...["Prepare","Inspect","Review","Rework"].map((e,t)=>({id:["a","b","c","d"][t],label:e,kind:"process"})),{id:"end",label:"Released",kind:"end"}],edges:[["s","a"],["a","b"],["b","c"],["c","d"],["d","end"],["d","a"],["d","b"]].map(([e,t],a)=>({id:`e${a}`,source:e,target:t}))};function sb(e){return eC({...e,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}})}function sk(e,t="TB"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}function sM(e){return eC({...e,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}})}function sC(e){return te({...e,type:ej})}eC({id:"package-chain",title:"Request to hosted artifact",nodes:[{id:"app",label:"App request",kind:"start"},{id:"agent",label:"Agent / orchestration",kind:"process"},{id:"core",label:"Core diagram model",kind:"process"},{id:"renderer",label:"Renderer",kind:"process"},{id:"export",label:"Excalidraw export",kind:"process"},{id:"host",label:"Artifact hosting / storage",kind:"process"},{id:"response",label:"Hosted artifact response",kind:"end"}],edges:[{id:"request",source:"app",target:"agent",label:"Request contract"},{id:"build",source:"agent",target:"core",label:"Semantic builder input"},{id:"validate",source:"core",target:"renderer",label:"Validated diagram spec"},{id:"render",source:"renderer",target:"export",label:"CanvasSpec scene"},{id:"store",source:"export",target:"host",label:"Exported artifact bundle"},{id:"respond",source:"host",target:"response",label:"Artifact ID + hosted URLs"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"scope-bypass",title:"Diagram request",nodes:[{id:"received",label:"Prompt received",kind:"start"},{id:"requirements",label:"Extract requirements",kind:"process"},{id:"scope",label:"Is the scope clear?",kind:"decision"},{id:"draft",label:"Draft typed IR",kind:"process"},{id:"review",label:"Review",kind:"end"}],edges:[{id:"extract",source:"received",target:"requirements"},{id:"assess",source:"requirements",target:"scope"},{id:"clear",source:"scope",target:"draft",label:"Yes"},{id:"unclear",source:"scope",target:"review",label:"No"},{id:"submit",source:"draft",target:"review"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"rollout-failures",title:"Feature flag rollout",nodes:[{id:"ready",label:"Flag is ready",kind:"start"},{id:"internal",label:"Enable internally",kind:"process"},{id:"internal-health",label:"Internal checks healthy?",kind:"decision"},{id:"beta",label:"Enable beta cohort",kind:"process"},{id:"beta-health",label:"Beta checks healthy?",kind:"decision"},{id:"ramp",label:"Ramp to all users",kind:"process"},{id:"complete",label:"Rollout complete",kind:"end"},{id:"rollback",label:"Roll back the feature",kind:"end"}],edges:[{id:"enable",source:"ready",target:"internal"},{id:"check-internal",source:"internal",target:"internal-health"},{id:"internal-healthy",source:"internal-health",target:"beta",label:"Healthy"},{id:"internal-fail",source:"internal-health",target:"rollback",label:"Fail"},{id:"check-beta",source:"beta",target:"beta-health"},{id:"beta-healthy",source:"beta-health",target:"ramp",label:"Healthy"},{id:"beta-unhealthy",source:"beta-health",target:"rollback",label:"Unhealthy"},{id:"finish",source:"ramp",target:"complete"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"release-fan-in",title:"Fix release",nodes:[{id:"confirmed",label:"Bug confirmed",kind:"start"},{id:"security",label:"Security impact?",kind:"decision"},{id:"triage",label:"Security triage",kind:"process"},{id:"hotfix",label:"Hotfix branch",kind:"process"},{id:"priority",label:"High priority?",kind:"decision"},{id:"sprint",label:"Sprint backlog",kind:"process"},{id:"release",label:"Release fix",kind:"end"},{id:"backlog",label:"Regular backlog",kind:"end"}],edges:[{id:"assess",source:"confirmed",target:"security"},{id:"secure",source:"security",target:"triage",label:"Yes"},{id:"branch",source:"triage",target:"hotfix"},{id:"ship-hotfix",source:"hotfix",target:"release"},{id:"prioritize",source:"security",target:"priority",label:"No"},{id:"plan",source:"priority",target:"sprint",label:"Yes"},{id:"ship-sprint",source:"sprint",target:"release"},{id:"defer",source:"priority",target:"backlog",label:"No"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"stability-fan-in",title:"Incident remediation",nodes:[{id:"evidence",label:"Collect evidence",kind:"start"},{id:"cause",label:"Classify root cause",kind:"decision"},{id:"rollback",label:"Roll back deploy",kind:"process"},{id:"hotfix",label:"Prepare hotfix",kind:"process"},{id:"provider",label:"Escalate to provider",kind:"process"},{id:"stable",label:"Service stable?",kind:"decision"},{id:"monitor",label:"Monitor service",kind:"end"},{id:"escalate",label:"Escalate unstable service",kind:"process"},{id:"fresh",label:"Collect fresh evidence",kind:"process"}],edges:[{id:"classify",source:"evidence",target:"cause"},{id:"deploy",source:"cause",target:"rollback",label:"Deploy"},{id:"code",source:"cause",target:"hotfix",label:"Code"},{id:"vendor",source:"cause",target:"provider",label:"Provider"},{id:"check-rollback",source:"rollback",target:"stable"},{id:"check-hotfix",source:"hotfix",target:"stable"},{id:"check-provider",source:"provider",target:"stable"},{id:"healthy",source:"stable",target:"monitor",label:"Yes"},{id:"unhealthy",source:"stable",target:"escalate",label:"No"},{id:"gather",source:"escalate",target:"fresh"},{id:"retry",source:"fresh",target:"cause"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"renewal-retry",title:"Subscription renewal",nodes:[{id:"due",label:"Renewal due",kind:"start"},{id:"charge",label:"Charge payment",kind:"process"},{id:"paid",label:"Payment succeeded?",kind:"decision"},{id:"renew",label:"Renew subscription",kind:"end"},{id:"remind",label:"Send reminder",kind:"process"},{id:"updated",label:"Payment updated?",kind:"decision"},{id:"pause",label:"Pause subscription",kind:"end"}],edges:[{id:"bill",source:"due",target:"charge"},{id:"confirm",source:"charge",target:"paid"},{id:"renewed",source:"paid",target:"renew",label:"Yes"},{id:"declined",source:"paid",target:"remind",label:"No"},{id:"wait",source:"remind",target:"updated"},{id:"retry",source:"updated",target:"charge",label:"Yes"},{id:"expired",source:"updated",target:"pause",label:"No"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"cancellation-convergence",title:"Subscription cancellation",nodes:[{id:"requested",label:"Member requests cancellation",kind:"start"},{id:"reason",label:"Collect the cancellation reason",kind:"process"},{id:"eligible",label:"Eligible for a retention offer?",kind:"decision"},{id:"offer",label:"Present retention offer",kind:"process"},{id:"accepted",label:"Offer accepted?",kind:"decision"},{id:"keep",label:"Retain member",kind:"end"},{id:"confirm",label:"Confirm cancellation",kind:"process"},{id:"close",label:"Close account",kind:"end"}],edges:[{id:"record",source:"requested",target:"reason"},{id:"check",source:"reason",target:"eligible"},{id:"offer-save",source:"eligible",target:"offer",label:"Yes"},{id:"not-eligible",source:"eligible",target:"confirm",label:"No"},{id:"decide",source:"offer",target:"accepted"},{id:"kept",source:"accepted",target:"keep",label:"Yes"},{id:"declined",source:"accepted",target:"confirm",label:"No"},{id:"close-account",source:"confirm",target:"close"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"shared-feedback-returns",title:"Revisit earlier checks",nodes:[{id:"start",label:"Received",kind:"start"},{id:"a",label:"Intake",kind:"process"},{id:"b",label:"Inspect",kind:"process"},{id:"c",label:"Review",kind:"process"},{id:"d",label:"Approve",kind:"process"},{id:"end",label:"Released",kind:"end"}],edges:[{id:"entry",source:"start",target:"a"},{id:"ab",source:"a",target:"b"},{id:"bc",source:"b",target:"c"},{id:"cd",source:"c",target:"d"},{id:"release",source:"d",target:"end"},{id:"ba",source:"b",target:"a"},{id:"ca",source:"c",target:"a",label:"Retry"},{id:"da",source:"d",target:"a"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({...sx,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"feedback-chain",title:"Repeat inspection",nodes:[{id:"start",label:"Received",kind:"start"},{id:"a",label:"Prepare",kind:"process"},{id:"b",label:"Inspect",kind:"process"},{id:"c",label:"Approve",kind:"process"},{id:"end",label:"Released",kind:"end"}],edges:[{id:"start",source:"start",target:"a"},{id:"ab",source:"a",target:"b"},{id:"bc",source:"b",target:"c"},{id:"ca",source:"c",target:"a",label:"Retry"},{id:"end",source:"c",target:"end"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({...sw,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"feedback-skip-stubs",title:"Retry with skipped stages",nodes:[{id:"0",label:"Step 0",kind:"start"},{id:"1",label:"Step 1",kind:"process"},{id:"2",label:"Step 2",kind:"process"},{id:"3",label:"Step 3",kind:"process"},{id:"4",label:"Step 4",kind:"process"},{id:"5",label:"Step 5",kind:"end"}],edges:[{id:"e0",source:"0",target:"1"},{id:"e1",source:"1",target:"2"},{id:"e2",source:"2",target:"3"},{id:"e3",source:"3",target:"4",label:"Path 3"},{id:"e4",source:"4",target:"5"},{id:"e5",source:"3",target:"5"},{id:"feedback",source:"4",target:"1"},{id:"e7",source:"2",target:"4"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"decision-feedback",title:"Retry a failed attempt",nodes:[{id:"start",label:"Start",kind:"start"},{id:"attempt",label:"Attempt",kind:"process"},{id:"check",label:"Success?",kind:"decision"},{id:"done",label:"Done",kind:"end"}],edges:[{id:"start",source:"start",target:"attempt"},{id:"check",source:"attempt",target:"check"},{id:"yes",source:"check",target:"done",label:"Yes"},{id:"feedback",source:"check",target:"attempt",label:"Retry"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"review-feedback",title:"Review feedback",nodes:[{id:"start",label:"Received",kind:"start"},{id:"prepare",label:"Prepare submission",kind:"process"},{id:"review",label:"Ready?",kind:"decision"},{id:"revise",label:"Request changes",kind:"process"},{id:"done",label:"Accepted",kind:"end"}],edges:[{id:"start",source:"start",target:"prepare"},{id:"review",source:"prepare",target:"review"},{id:"no",source:"review",target:"revise",label:"No"},{id:"feedback",source:"revise",target:"prepare",label:"Changes ready"},{id:"yes",source:"review",target:"done",label:"Yes"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"wait-retry",title:"Wait and retry",nodes:[{id:"start",label:"Join queue",kind:"start"},{id:"responds",label:"Responds?",kind:"decision"},{id:"leave",label:"Leave queue",kind:"end"},{id:"ready",label:"Ready?",kind:"decision"},{id:"done",label:"Continue",kind:"end"},{id:"wait",label:"Keep waiting",kind:"process"}],edges:[{id:"start",source:"start",target:"responds"},{id:"leave",source:"responds",target:"leave",label:"No"},{id:"ready",source:"responds",target:"ready",label:"Yes"},{id:"done",source:"ready",target:"done",label:"Yes"},{id:"wait",source:"ready",target:"wait",label:"No"},{id:"feedback",source:"wait",target:"responds"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"content-moderation-flow",title:"Content moderation flow",nodes:[{id:"report",label:"Report received",kind:"start"},{id:"scan",label:"Automated scan runs",kind:"process"},{id:"severe",label:"Severe harm detected?",kind:"decision"},{id:"remove",label:"Remove content",kind:"process"},{id:"escalate",label:"Escalate to safety",kind:"process"},{id:"violation",label:"Policy violation?",kind:"decision"},{id:"restore_none",label:"Restore content",kind:"end"},{id:"review",label:"Human review",kind:"process"},{id:"action",label:"Action needed?",kind:"decision"},{id:"limit",label:"Limit content",kind:"end"},{id:"restore_review",label:"Restore content",kind:"end"},{id:"closed_severe",label:"Severe case closed",kind:"end"}],edges:[{id:"edge-1",source:"report",target:"scan"},{id:"edge-2",source:"scan",target:"severe"},{id:"edge-3",source:"severe",target:"remove",label:"Yes"},{id:"edge-4",source:"severe",target:"violation",label:"No"},{id:"edge-5",source:"remove",target:"escalate"},{id:"edge-6",source:"escalate",target:"closed_severe"},{id:"edge-7",source:"violation",target:"restore_none",label:"No"},{id:"edge-8",source:"violation",target:"review",label:"Yes"},{id:"edge-9",source:"review",target:"action"},{id:"edge-10",source:"action",target:"limit",label:"Yes"},{id:"edge-11",source:"action",target:"restore_review",label:"No"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"data-import-validation",title:"Data import validation",nodes:[{id:"upload",label:"File uploaded",kind:"start"},{id:"parse",label:"Parse file",kind:"process"},{id:"parse_ok",label:"Parsing succeeded?",kind:"decision"},{id:"reject",label:"Reject file",kind:"process"},{id:"rejected_end",label:"File rejected",kind:"end"},{id:"validate",label:"Validate schema",kind:"process"},{id:"schema_ok",label:"Schema valid?",kind:"decision"},{id:"mapping_errors",label:"Return mapping errors",kind:"process"},{id:"mapping_end",label:"Mapping errors returned",kind:"end"},{id:"dedupe",label:"Deduplicate records",kind:"process"},{id:"dup_found",label:"Duplicates found?",kind:"decision"},{id:"merge",label:"Merge duplicates",kind:"process"},{id:"import",label:"Import records",kind:"process"},{id:"done",label:"Import complete",kind:"end"}],edges:[{id:"edge-1",source:"upload",target:"parse"},{id:"edge-2",source:"parse",target:"parse_ok"},{id:"edge-3",source:"parse_ok",target:"reject",label:"No"},{id:"edge-4",source:"reject",target:"rejected_end"},{id:"edge-5",source:"parse_ok",target:"validate",label:"Yes"},{id:"edge-6",source:"validate",target:"schema_ok"},{id:"edge-7",source:"schema_ok",target:"mapping_errors",label:"No"},{id:"edge-8",source:"mapping_errors",target:"mapping_end"},{id:"edge-9",source:"schema_ok",target:"dedupe",label:"Yes"},{id:"edge-10",source:"dedupe",target:"dup_found"},{id:"edge-11",source:"dup_found",target:"merge",label:"Yes"},{id:"edge-12",source:"merge",target:"import"},{id:"edge-13",source:"dup_found",target:"import",label:"No"},{id:"edge-14",source:"import",target:"done"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"incident-escalation-flowchart",title:"Incident Escalation Flowchart",nodes:[{id:"alert",label:"Monitoring creates alert",kind:"start"},{id:"ack",label:"Responder acknowledges alert",kind:"process"},{id:"severity",label:"Severity?",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"triage",label:"Triage queue",kind:"process"},{id:"monitor_low",label:"Monitoring: low-severity incident",kind:"process"},{id:"mitigate",label:"Mitigate impact",kind:"process"},{id:"comms",label:"Send customer communications",kind:"process"},{id:"resolve_bridge",label:"Resolve incident",kind:"end"},{id:"fix",label:"Fix available?",kind:"decision"},{id:"resolve_fix",label:"Resolve incident (fix found)",kind:"end"},{id:"escalate",label:"Escalate to incident bridge",kind:"process"},{id:"resolved_low",label:"Resolved",kind:"end"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"severity"},{id:"edge-3",source:"severity",target:"bridge",label:"High"},{id:"edge-4",source:"severity",target:"triage",label:"Medium"},{id:"edge-5",source:"severity",target:"monitor_low",label:"Low"},{id:"edge-6",source:"bridge",target:"mitigate"},{id:"edge-7",source:"mitigate",target:"comms"},{id:"edge-8",source:"comms",target:"resolve_bridge"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"resolve_fix",label:"Yes"},{id:"edge-11",source:"fix",target:"escalate",label:"No"},{id:"edge-12",source:"escalate",target:"bridge"},{id:"edge-13",source:"monitor_low",target:"resolved_low"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"invoice-approval",title:"Invoice approval",nodes:[{id:"received",label:"Invoice received",kind:"start"},{id:"match_po",label:"Match invoice to purchase order",kind:"process"},{id:"po_matched",label:"Invoice matches PO?",kind:"decision"},{id:"exception_review",label:"Route to exception review",kind:"process"},{id:"exception_resolved",label:"Exception resolved?",kind:"decision"},{id:"reject",label:"Reject invoice",kind:"end"},{id:"over_threshold",label:"Amount over approval threshold?",kind:"decision"},{id:"director_approval",label:"Director approval before payment",kind:"process"},{id:"schedule_payment",label:"Schedule payment",kind:"process"},{id:"paid",label:"Payment scheduled",kind:"end"}],edges:[{id:"e1",source:"received",target:"match_po"},{id:"e2",source:"match_po",target:"po_matched"},{id:"e3",source:"po_matched",target:"over_threshold",label:"Yes"},{id:"e4",source:"po_matched",target:"exception_review",label:"No"},{id:"e5",source:"exception_review",target:"exception_resolved"},{id:"e6",source:"exception_resolved",target:"over_threshold",label:"Yes"},{id:"e7",source:"exception_resolved",target:"reject",label:"No"},{id:"e8",source:"over_threshold",target:"director_approval",label:"Yes"},{id:"e9",source:"over_threshold",target:"schedule_payment",label:"No"},{id:"e10",source:"director_approval",target:"schedule_payment"},{id:"e11",source:"schedule_payment",target:"paid"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"loan-underwriting",title:"Loan Application Underwriting",nodes:[{id:"submit",label:"Application submitted",kind:"start"},{id:"verify_id",label:"Verify identity",kind:"process"},{id:"id_ok",label:"Identity verified?",kind:"decision"},{id:"credit_review",label:"Credit review",kind:"process"},{id:"credit_ok",label:"Credit acceptable?",kind:"decision"},{id:"manual_uw",label:"Manual underwriting",kind:"process"},{id:"exception",label:"Exception approved?",kind:"decision"},{id:"income",label:"Income verification",kind:"process"},{id:"approve",label:"Loan approved",kind:"end"},{id:"decline",label:"Decline application",kind:"end"}],edges:[{id:"e1",source:"submit",target:"verify_id"},{id:"e2",source:"verify_id",target:"id_ok"},{id:"e3",source:"id_ok",target:"credit_review",label:"Yes"},{id:"e4",source:"id_ok",target:"decline",label:"No"},{id:"e5",source:"credit_review",target:"credit_ok"},{id:"e6",source:"credit_ok",target:"income",label:"Yes"},{id:"e7",source:"credit_ok",target:"manual_uw",label:"No"},{id:"e8",source:"manual_uw",target:"exception"},{id:"e9",source:"exception",target:"income",label:"Yes"},{id:"e10",source:"exception",target:"decline",label:"No"},{id:"e11",source:"income",target:"approve"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"patient-intake-scheduling",title:"Patient Intake Scheduling",nodes:[{id:"request",label:"Patient requests appointment",kind:"start"},{id:"collect",label:"Clinic collects intake information",kind:"process"},{id:"urgent",label:"Urgent symptoms?",kind:"decision"},{id:"triage",label:"Nurse triage",kind:"process"},{id:"same_day",label:"Schedule same-day appointment",kind:"process"},{id:"insurance",label:"Is insurance valid?",kind:"decision"},{id:"routine",label:"Schedule routine appointment",kind:"process"},{id:"self_pay_q",label:"Patient accepts self-pay?",kind:"decision"},{id:"self_pay",label:"Schedule routine care (self-pay)",kind:"process"},{id:"billing",label:"Refer to billing",kind:"process"},{id:"end_same_day",label:"Same-day visit booked",kind:"end"},{id:"end_routine",label:"Routine visit booked",kind:"end"},{id:"end_self_pay",label:"Self-pay visit booked",kind:"end"},{id:"end_billing",label:"Billing referral made",kind:"end"}],edges:[{id:"e1",source:"request",target:"collect"},{id:"e2",source:"collect",target:"urgent"},{id:"e3",source:"urgent",target:"triage",label:"Yes"},{id:"e4",source:"triage",target:"same_day"},{id:"e5",source:"same_day",target:"end_same_day"},{id:"e6",source:"urgent",target:"insurance",label:"No"},{id:"e7",source:"insurance",target:"routine",label:"Valid"},{id:"e8",source:"routine",target:"end_routine"},{id:"e9",source:"insurance",target:"self_pay_q",label:"Invalid"},{id:"e10",source:"self_pay_q",target:"self_pay",label:"Yes"},{id:"e11",source:"self_pay",target:"end_self_pay"},{id:"e12",source:"self_pay_q",target:"billing",label:"No"},{id:"e13",source:"billing",target:"end_billing"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"pharma-batch-disposition",title:"Pharma Batch Disposition",nodes:[{id:"received",label:"Batch received",kind:"start"},{id:"coa_review",label:"QA reviews Certificate of Analysis (CoA)",kind:"process"},{id:"spec_check",label:"Batch passes specs?",kind:"decision"},{id:"final_review",label:"QA Manager final review",kind:"process"},{id:"packaging",label:"Packaging",kind:"process"},{id:"released",label:"Packaged batch released",kind:"end"},{id:"investigation",label:"Investigation",kind:"process"},{id:"rejected",label:"Reject batch",kind:"end"}],edges:[{id:"e1",source:"received",target:"coa_review"},{id:"e2",source:"coa_review",target:"spec_check"},{id:"e3",source:"spec_check",target:"final_review",label:"Pass"},{id:"e4",source:"spec_check",target:"investigation",label:"Retest"},{id:"e5",source:"spec_check",target:"rejected",label:"Reject"},{id:"e6",source:"final_review",target:"packaging"},{id:"e7",source:"packaging",target:"released"},{id:"e8",source:"investigation",target:"final_review",label:"Returns to final review"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"warehouse-reorder-flow",title:"Warehouse reorder flow",nodes:[{id:"count",label:"Stock count updated",kind:"start"},{id:"reorder_check",label:"Inventory below reorder point?",kind:"decision"},{id:"monitor",label:"Monitor stock",kind:"process"},{id:"monitor_end",label:"Stock monitoring continues",kind:"end"},{id:"check_supplier",label:"Check supplier availability",kind:"process"},{id:"supplier_check",label:"Supplier available?",kind:"decision"},{id:"substitute",label:"Use substitute supplier",kind:"process"},{id:"create_po",label:"Create purchase order",kind:"process"},{id:"await_delivery",label:"Await delivery",kind:"process"},{id:"reorder_end",label:"Reorder cycle complete",kind:"end"}],edges:[{id:"e1",source:"count",target:"reorder_check"},{id:"e2",source:"reorder_check",target:"monitor",label:"No"},{id:"e3",source:"monitor",target:"monitor_end"},{id:"e4",source:"reorder_check",target:"check_supplier",label:"Yes"},{id:"e5",source:"check_supplier",target:"supplier_check"},{id:"e6",source:"supplier_check",target:"create_po",label:"Yes"},{id:"e7",source:"supplier_check",target:"substitute",label:"No"},{id:"e8",source:"substitute",target:"create_po"},{id:"e9",source:"create_po",target:"await_delivery"},{id:"e10",source:"await_delivery",target:"reorder_end"}],layout:{direction:"TB"},style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),sb({id:"loan-application-underwriting",title:"Loan Application Underwriting",nodes:[{id:"submitted",label:"Application submitted",kind:"start"},{id:"identity",label:"Verify identity",kind:"process"},{id:"identity_decision",label:"Identity verified?",kind:"decision"},{id:"identity_decline",label:"Decline application",kind:"end"},{id:"credit",label:"Credit review",kind:"process"},{id:"credit_decision",label:"Acceptable credit?",kind:"decision"},{id:"manual",label:"Manual underwriting",kind:"process"},{id:"exception",label:"Exception approved?",kind:"decision"},{id:"exception_decline",label:"Decline application",kind:"end"},{id:"income",label:"Income verification",kind:"process"},{id:"approved",label:"Approve loan",kind:"end"}],edges:[{id:"edge-1",source:"submitted",target:"identity"},{id:"edge-2",source:"identity",target:"identity_decision"},{id:"edge-3",source:"identity_decision",target:"identity_decline",label:"Failed"},{id:"edge-4",source:"identity_decision",target:"credit",label:"Verified"},{id:"edge-5",source:"credit",target:"credit_decision"},{id:"edge-6",source:"credit_decision",target:"income",label:"Acceptable"},{id:"edge-7",source:"credit_decision",target:"manual",label:"Unacceptable"},{id:"edge-8",source:"manual",target:"exception"},{id:"edge-9",source:"exception",target:"income",label:"Yes"},{id:"edge-10",source:"exception",target:"exception_decline",label:"No"},{id:"edge-11",source:"income",target:"approved"}],layout:{direction:"TB"}}),sb({id:"invoice-approval-flowchart",title:"Invoice approval flowchart",nodes:[{id:"received",label:"Invoice received",kind:"start"},{id:"match",label:"Match to purchase order",kind:"process"},{id:"matches",label:"Matches purchase order?",kind:"decision"},{id:"review",label:"Exception review",kind:"process"},{id:"resolved",label:"Exception resolved?",kind:"decision"},{id:"reject",label:"Reject invoice",kind:"end"},{id:"threshold",label:"Amount over approval threshold?",kind:"decision"},{id:"director",label:"Director approval",kind:"process"},{id:"schedule",label:"Schedule payment",kind:"process"},{id:"payment",label:"Payment",kind:"end"}],edges:[{id:"edge-1",source:"received",target:"match"},{id:"edge-2",source:"match",target:"matches"},{id:"edge-3",source:"matches",target:"review",label:"No"},{id:"edge-4",source:"review",target:"resolved"},{id:"edge-5",source:"resolved",target:"reject",label:"No — unresolved"},{id:"edge-6",source:"resolved",target:"threshold",label:"Yes — resolved"},{id:"edge-7",source:"matches",target:"threshold",label:"Yes — matched"},{id:"edge-8",source:"threshold",target:"director",label:"Yes — over threshold"},{id:"edge-9",source:"threshold",target:"schedule",label:"No — at or below threshold"},{id:"edge-10",source:"director",target:"schedule"},{id:"edge-11",source:"schedule",target:"payment"}],layout:{direction:"TB"}}),sb({id:"identifier-labels",title:"Identifier labels",nodes:[{id:"call",label:"buildSequenceDiagram",kind:"start"},{id:"check",label:"Layout renderer-independent?",kind:"decision"},{id:"export",label:"exportToExcalidrawScene(spec)",kind:"process"},{id:"fetch",label:"Fetch https://playground.sketchi.app/api/v1/artifacts/download",kind:"process"},{id:"cjk",label:"品質保証レビュー承認待ち",kind:"process"},{id:"done",label:"Ship 🚀 release",kind:"end"}],edges:[{id:"e1",source:"call",target:"check"},{id:"e2",source:"check",target:"export",label:"renderer-independent"},{id:"e3",source:"check",target:"fetch",label:"buildSequenceDiagram"},{id:"e4",source:"export",target:"cjk",label:"品質保証レビュー承認待ち"},{id:"e5",source:"fetch",target:"done",label:"https://example.com/api/v1/artifacts/download"},{id:"e6",source:"cjk",target:"done",label:"🚀🚀 shipped"}],layout:{direction:"TB"}}),sb({id:"multiline-labels",title:"Multi-line labels",nodes:[{id:"request",label:"Refund requested",kind:"start"},{id:"eligible",label:"Refund within the policy window?",kind:"decision"},{id:"provider",label:"Ask the payment provider",kind:"process"},{id:"confirmed",label:"Provider confirmed?",kind:"decision"},{id:"refund",label:"Issue the refund",kind:"process"},{id:"deny",label:"Explain the decision to the customer",kind:"end"},{id:"closed",label:"Refund closed",kind:"end"}],edges:[{id:"e1",source:"request",target:"eligible"},{id:"e2",source:"eligible",target:"provider",label:"Yes, within the window and eligible for a full refund"},{id:"e3",source:"eligible",target:"deny",label:"No — outside\nthe policy window"},{id:"e4",source:"provider",target:"confirmed",label:"Request sent to the provider"},{id:"e5",source:"confirmed",target:"refund",label:"Confirmed by the provider"},{id:"e6",source:"confirmed",target:"provider",label:"Retry after the provider\nconfirms the hold"},{id:"e7",source:"refund",target:"closed"}],layout:{direction:"TB"}}),sb({id:"competing-branch-labels",title:"Competing branch labels",nodes:[{id:"triage",label:"Triage the report",kind:"start"},{id:"kind",label:"Which kind of report?",kind:"decision"},{id:"bug",label:"Reproduce the bug",kind:"process"},{id:"feature",label:"Log the feature",kind:"process"},{id:"question",label:"Answer the question",kind:"process"},{id:"duplicate",label:"Link the duplicate",kind:"process"},{id:"reproduced",label:"Reproduced?",kind:"decision"},{id:"fix",label:"Fix and verify",kind:"process"},{id:"closed",label:"Close the report",kind:"end"}],edges:[{id:"e1",source:"triage",target:"kind"},{id:"e2",source:"kind",target:"bug",label:"Unexpected behavior"},{id:"e3",source:"kind",target:"feature",label:"Enhancement"},{id:"e4",source:"kind",target:"question",label:"Unanswered question"},{id:"e5",source:"kind",target:"duplicate",label:"Duplicate"},{id:"e6",source:"bug",target:"reproduced"},{id:"e7",source:"reproduced",target:"fix",label:"Reproduced"},{id:"e8",source:"reproduced",target:"bug",label:"Unreproducible"},{id:"e9",source:"fix",target:"closed"},{id:"e10",source:"feature",target:"closed"},{id:"e11",source:"question",target:"closed"},{id:"e12",source:"duplicate",target:"closed"}],layout:{direction:"TB"}}),sk({id:"grouped-approval",title:"Expense approval by team",groups:[{id:"employee",label:"Employee"},{id:"manager",label:"Manager"},{id:"finance",label:"Finance"}],nodes:[{id:"incurred",label:"Expense incurred",kind:"start"},{id:"submit",label:"Submit expense report",kind:"process",group:"employee"},{id:"review",label:"Review the report",kind:"process",group:"manager"},{id:"approved",label:"Approved?",kind:"decision",group:"manager"},{id:"revise",label:"Revise the report",kind:"process",group:"employee"},{id:"verify",label:"Verify receipts",kind:"process",group:"finance"},{id:"pay",label:"Pay the employee",kind:"process",group:"finance"},{id:"paid",label:"Expense paid",kind:"end"}],edges:[{id:"e1",source:"incurred",target:"submit"},{id:"e2",source:"submit",target:"review"},{id:"e3",source:"review",target:"approved"},{id:"e4",source:"approved",target:"verify",label:"yes"},{id:"e5",source:"approved",target:"revise",label:"no"},{id:"e6",source:"revise",target:"submit"},{id:"e7",source:"verify",target:"pay"},{id:"e8",source:"pay",target:"paid"}]}),sk({id:"three-zone-service",title:"Request path across network zones",groups:[{id:"internet",label:"Public internet"},{id:"edge",label:"Edge network"},{id:"private",label:"Private subnet"}],nodes:[{id:"browser",label:"Browser sends request",kind:"start",group:"internet"},{id:"cdn",label:"CDN serves cache",kind:"process",group:"edge"},{id:"cached",label:"Cache hit?",kind:"decision",group:"edge"},{id:"waf",label:"WAF filters traffic",kind:"process",group:"edge"},{id:"api",label:"API handles request",kind:"process",group:"private"},{id:"db",label:"Query the database",kind:"process",group:"private"},{id:"response",label:"Response returned",kind:"end"}],edges:[{id:"e1",source:"browser",target:"cdn"},{id:"e2",source:"cdn",target:"cached"},{id:"e3",source:"cached",target:"response",label:"hit"},{id:"e4",source:"cached",target:"waf",label:"miss"},{id:"e5",source:"waf",target:"api"},{id:"e6",source:"api",target:"db"},{id:"e7",source:"db",target:"response"}]},"LR"),sk({id:"mixed-membership",title:"Order fulfilment with partial grouping",groups:[{id:"warehouse",label:"Warehouse"},{id:"shipping",label:"Shipping partner"}],nodes:[{id:"order",label:"Order placed",kind:"start"},{id:"fraud",label:"Fraud check passed?",kind:"decision"},{id:"pick",label:"Pick items",kind:"process",group:"warehouse"},{id:"pack",label:"Pack the order",kind:"process",group:"warehouse"},{id:"label",label:"Print shipping label",kind:"process",group:"warehouse"},{id:"collect",label:"Collect parcel",kind:"process",group:"shipping"},{id:"deliver",label:"Deliver to customer",kind:"end",group:"shipping"},{id:"cancel",label:"Cancel the order",kind:"end"}],edges:[{id:"e1",source:"order",target:"fraud"},{id:"e2",source:"fraud",target:"pick",label:"yes"},{id:"e3",source:"fraud",target:"cancel",label:"no"},{id:"e4",source:"pick",target:"pack"},{id:"e5",source:"pack",target:"label"},{id:"e6",source:"label",target:"collect"},{id:"e7",source:"collect",target:"deliver"}]}),sk({id:"scattered-members",title:"Incident handling across on-call and support",groups:[{id:"support",label:"Customer support desk and escalation team"},{id:"oncall",label:"On-call"},{id:"comms",label:"Comms"}],nodes:[{id:"report",label:"Customer reports issue",kind:"start",group:"support"},{id:"triage",label:"Triage the report",kind:"process",group:"support"},{id:"outage",label:"Outage?",kind:"decision"},{id:"page",label:"Page on-call",kind:"process",group:"oncall"},{id:"mitigate",label:"Mitigate impact",kind:"process",group:"oncall"},{id:"fixed",label:"Fixed?",kind:"decision",group:"oncall"},{id:"status",label:"Post status update",kind:"process",group:"comms"},{id:"reply",label:"Reply to customer",kind:"process",group:"support"},{id:"closed",label:"Ticket closed",kind:"end",group:"support"}],edges:[{id:"e1",source:"report",target:"triage"},{id:"e2",source:"triage",target:"outage"},{id:"e3",source:"outage",target:"page",label:"yes"},{id:"e4",source:"outage",target:"reply",label:"no"},{id:"e5",source:"page",target:"mitigate"},{id:"e6",source:"mitigate",target:"fixed"},{id:"e7",source:"fixed",target:"status",label:"yes"},{id:"e8",source:"fixed",target:"mitigate",label:"not yet"},{id:"e9",source:"status",target:"reply"},{id:"e10",source:"reply",target:"closed"}]}),sk({id:"many-groups",title:"Release train across teams",groups:[{id:"product",label:"Product"},{id:"web",label:"Web team"},{id:"mobile",label:"Mobile team"},{id:"qa",label:"QA"},{id:"ops",label:"Ops"},{id:"marketing",label:"Marketing"}],nodes:[{id:"plan",label:"Plan the release",kind:"start",group:"product"},{id:"web-build",label:"Build web app",kind:"process",group:"web"},{id:"mobile-build",label:"Build mobile app",kind:"process",group:"mobile"},{id:"store",label:"Submit to app stores",kind:"process",group:"mobile"},{id:"test",label:"Regression tests",kind:"process",group:"qa"},{id:"pass",label:"Tests pass?",kind:"decision",group:"qa"},{id:"deploy",label:"Deploy to production",kind:"process",group:"ops"},{id:"announce",label:"Announce the release",kind:"end",group:"marketing"}],edges:[{id:"e1",source:"plan",target:"web-build"},{id:"e2",source:"plan",target:"mobile-build"},{id:"e3",source:"mobile-build",target:"store"},{id:"e4",source:"web-build",target:"test"},{id:"e5",source:"store",target:"test"},{id:"e6",source:"test",target:"pass"},{id:"e7",source:"pass",target:"deploy",label:"yes"},{id:"e8",source:"pass",target:"web-build",label:"no"},{id:"e9",source:"deploy",target:"announce"}]}),sk({id:"single-group",title:"Payment retries inside the billing service",groups:[{id:"billing",label:"Billing service"}],nodes:[{id:"charge",label:"Charge the card",kind:"start",group:"billing"},{id:"ok",label:"Charge succeeded?",kind:"decision",group:"billing"},{id:"wait",label:"Wait and retry",kind:"process",group:"billing"},{id:"receipt",label:"Send receipt",kind:"end",group:"billing"}],edges:[{id:"e1",source:"charge",target:"ok"},{id:"e2",source:"ok",target:"receipt",label:"yes"},{id:"e3",source:"ok",target:"wait",label:"no"},{id:"e4",source:"wait",target:"ok"}]}),sM({id:"incident-escalation",title:"Incident escalation",nodes:[{id:"alert",label:"Monitoring creates an alert",kind:"start"},{id:"ack",label:"Responder acknowledges it",kind:"process"},{id:"severity",label:"Severity",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"triage",label:"Triage queue",kind:"process"},{id:"monitor",label:"Monitoring",kind:"process"},{id:"mitigate",label:"Mitigates impact",kind:"process"},{id:"comms",label:"Sends customer communications",kind:"process"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"resolved",label:"Resolved",kind:"end"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"severity"},{id:"edge-3",source:"severity",target:"bridge",label:"High severity"},{id:"edge-4",source:"severity",target:"triage",label:"Medium severity"},{id:"edge-5",source:"severity",target:"monitor",label:"Low severity"},{id:"edge-6",source:"bridge",target:"mitigate"},{id:"edge-7",source:"mitigate",target:"comms"},{id:"edge-8",source:"comms",target:"resolved"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"resolved",label:"Yes"},{id:"edge-11",source:"fix",target:"bridge",label:"No — escalate"},{id:"edge-12",source:"monitor",target:"resolved"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"incident-escalation-flowchart",title:"Incident escalation flowchart",nodes:[{id:"alert",label:"Monitoring creates an alert",kind:"start"},{id:"ack",label:"Responder acknowledges it",kind:"process"},{id:"severity",label:"Severity",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"triage",label:"Triage queue",kind:"process"},{id:"monitor",label:"Monitoring low severity incidents",kind:"process"},{id:"mitigate",label:"Mitigates impact",kind:"process"},{id:"comms",label:"Sends customer communications",kind:"process"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"escalate",label:"Escalate to the incident bridge",kind:"process"},{id:"resolve",label:"Resolve the incident",kind:"end"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"severity"},{id:"edge-3",source:"severity",target:"bridge",label:"High severity"},{id:"edge-4",source:"severity",target:"triage",label:"Medium severity"},{id:"edge-5",source:"severity",target:"monitor",label:"Low severity"},{id:"edge-6",source:"bridge",target:"mitigate"},{id:"edge-7",source:"mitigate",target:"comms"},{id:"edge-8",source:"comms",target:"resolve"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"resolve",label:"Yes"},{id:"edge-11",source:"fix",target:"escalate",label:"No"},{id:"edge-12",source:"escalate",target:"bridge"},{id:"edge-13",source:"monitor",target:"resolve"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"incident-escalation-flowchart",title:"Incident escalation flowchart",nodes:[{id:"alert",label:"Monitoring creates an alert",kind:"start"},{id:"ack",label:"Responder acknowledges it",kind:"process"},{id:"severity",label:"Severity",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"mitigate",label:"Mitigate impact",kind:"process"},{id:"comms",label:"Send customer communications",kind:"process"},{id:"resolve",label:"Resolve the incident",kind:"end"},{id:"triage",label:"Triage queue",kind:"process"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"monitor",label:"Monitoring low severity incidents",kind:"process"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"severity"},{id:"edge-3",source:"severity",target:"bridge",label:"High severity"},{id:"edge-4",source:"severity",target:"triage",label:"Medium severity"},{id:"edge-5",source:"severity",target:"monitor",label:"Low severity"},{id:"edge-6",source:"bridge",target:"mitigate"},{id:"edge-7",source:"mitigate",target:"comms"},{id:"edge-8",source:"comms",target:"resolve"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"resolve",label:"Yes"},{id:"edge-11",source:"fix",target:"bridge",label:"No — escalate"},{id:"edge-12",source:"monitor",target:"resolve"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"subscription-renewal-dunning",title:"Subscription renewal dunning",nodes:[{id:"due",label:"A renewal is due",kind:"start"},{id:"charge",label:"Charges payment",kind:"process"},{id:"success",label:"Payment succeeds?",kind:"decision"},{id:"renew",label:"Renew the subscription",kind:"end"},{id:"reminder",label:"Send a reminder",kind:"process"},{id:"updated",label:"Payment was updated?",kind:"decision"},{id:"expired",label:"Grace period has expired?",kind:"decision"},{id:"pause",label:"Pause the subscription",kind:"end"},{id:"another",label:"Send another reminder",kind:"process"}],edges:[{id:"edge-1",source:"due",target:"charge"},{id:"edge-2",source:"charge",target:"success"},{id:"edge-3",source:"success",target:"renew",label:"Yes"},{id:"edge-4",source:"success",target:"reminder",label:"No"},{id:"edge-5",source:"reminder",target:"updated"},{id:"edge-6",source:"updated",target:"charge",label:"Yes — retry charge"},{id:"edge-7",source:"updated",target:"expired",label:"No"},{id:"edge-8",source:"expired",target:"pause",label:"Yes"},{id:"edge-9",source:"expired",target:"another",label:"No"},{id:"edge-10",source:"another",target:"updated"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"subscription-renewal-dunning",title:"Subscription renewal dunning",nodes:[{id:"due",label:"A renewal is due",kind:"start"},{id:"charge",label:"Charges payment",kind:"process"},{id:"success",label:"Payment succeeds?",kind:"decision"},{id:"renew",label:"Renew the subscription",kind:"end"},{id:"reminder",label:"Send a reminder",kind:"process"},{id:"updated",label:"Payment was updated?",kind:"decision"},{id:"expired",label:"Grace period has expired?",kind:"decision"},{id:"pause",label:"Pause the subscription",kind:"end"}],edges:[{id:"edge-1",source:"due",target:"charge"},{id:"edge-2",source:"charge",target:"success"},{id:"edge-3",source:"success",target:"renew",label:"Yes"},{id:"edge-4",source:"success",target:"reminder",label:"No"},{id:"edge-5",source:"reminder",target:"updated"},{id:"edge-6",source:"updated",target:"charge",label:"Yes — retry the charge"},{id:"edge-7",source:"updated",target:"expired",label:"No"},{id:"edge-8",source:"expired",target:"pause",label:"Yes"},{id:"edge-9",source:"expired",target:"reminder",label:"No — send another reminder"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"patient-intake-scheduling",title:"Patient Intake Scheduling",nodes:[{id:"request",label:"Patient requests an appointment",kind:"start"},{id:"intake",label:"Clinic collects intake information",kind:"process"},{id:"urgent",label:"Are there urgent symptoms?",kind:"decision"},{id:"triage",label:"Nurse triage",kind:"process"},{id:"same-day",label:"Same-day appointment",kind:"end"},{id:"insurance",label:"Is insurance valid?",kind:"decision"},{id:"routine",label:"Schedule a routine appointment",kind:"end"},{id:"self-pay",label:"Does the patient accept self-pay?",kind:"decision"},{id:"billing",label:"Refer to billing",kind:"end"}],edges:[{id:"edge-1",source:"request",target:"intake"},{id:"edge-2",source:"intake",target:"urgent"},{id:"edge-3",source:"urgent",target:"triage",label:"Yes"},{id:"edge-4",source:"triage",target:"same-day"},{id:"edge-5",source:"urgent",target:"insurance",label:"No"},{id:"edge-6",source:"insurance",target:"routine",label:"Valid"},{id:"edge-7",source:"insurance",target:"self-pay",label:"Invalid"},{id:"edge-8",source:"self-pay",target:"routine",label:"Yes"},{id:"edge-9",source:"self-pay",target:"billing",label:"No"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"procurement-vendor-approval",title:"Procurement vendor approval",nodes:[{id:"need",label:"Business need is identified",kind:"start"},{id:"quotes",label:"Quotes are collected",kind:"process"},{id:"preferred",label:"Is there a preferred vendor?",kind:"decision"},{id:"bid",label:"Run a competitive bid",kind:"process"},{id:"risk",label:"Risk assessment",kind:"process"},{id:"acceptable",label:"Is risk acceptable?",kind:"decision"},{id:"reject",label:"Reject the vendor",kind:"end"},{id:"legal",label:"Legal review",kind:"process"},{id:"approved",label:"Does legal approve?",kind:"decision"},{id:"renegotiate",label:"Renegotiate terms",kind:"process"},{id:"contract",label:"Create the contract",kind:"end"}],edges:[{id:"edge-1",source:"need",target:"quotes"},{id:"edge-2",source:"quotes",target:"preferred"},{id:"edge-3",source:"preferred",target:"risk",label:"Yes"},{id:"edge-4",source:"preferred",target:"bid",label:"No"},{id:"edge-5",source:"bid",target:"risk"},{id:"edge-6",source:"risk",target:"acceptable"},{id:"edge-7",source:"acceptable",target:"reject",label:"No"},{id:"edge-8",source:"acceptable",target:"legal",label:"Yes"},{id:"edge-9",source:"legal",target:"approved"},{id:"edge-10",source:"approved",target:"contract",label:"Yes"},{id:"edge-11",source:"approved",target:"renegotiate",label:"No"},{id:"edge-12",source:"renegotiate",target:"legal"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"procurement-vendor-approval",title:"Procurement Vendor Approval",nodes:[{id:"need",label:"A business need is identified",kind:"start"},{id:"quotes",label:"Quotes are collected",kind:"process"},{id:"preferred",label:"Is there a preferred vendor?",kind:"decision"},{id:"bid",label:"Run a competitive bid",kind:"process"},{id:"risk",label:"Risk assessment",kind:"process"},{id:"acceptable",label:"Is risk acceptable?",kind:"decision"},{id:"reject",label:"Reject the vendor",kind:"end"},{id:"legal",label:"Legal review",kind:"process"},{id:"approve",label:"Does legal approve?",kind:"decision"},{id:"contract",label:"Create the contract",kind:"end"},{id:"renegotiate",label:"Renegotiate terms",kind:"process"}],edges:[{id:"edge-1",source:"need",target:"quotes"},{id:"edge-2",source:"quotes",target:"preferred"},{id:"edge-3",source:"preferred",target:"risk",label:"Yes"},{id:"edge-4",source:"preferred",target:"bid",label:"No"},{id:"edge-5",source:"bid",target:"risk"},{id:"edge-6",source:"risk",target:"acceptable"},{id:"edge-7",source:"acceptable",target:"reject",label:"No"},{id:"edge-8",source:"acceptable",target:"legal",label:"Yes"},{id:"edge-9",source:"legal",target:"approve"},{id:"edge-10",source:"approve",target:"contract",label:"Yes"},{id:"edge-11",source:"approve",target:"renegotiate",label:"No"},{id:"edge-12",source:"renegotiate",target:"legal"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"restaurant-waitlist",title:"Restaurant waitlist",nodes:[{id:"arrives",label:"Party arrives",kind:"start"},{id:"quote",label:"Host quotes a wait time",kind:"process"},{id:"available",label:"Table available?",kind:"decision"},{id:"seat",label:"Seat the party",kind:"end"},{id:"add",label:"Add the party to the waitlist",kind:"process"},{id:"notified",label:"Party notified",kind:"process"},{id:"responds",label:"Party responds?",kind:"decision"},{id:"remove",label:"Remove the party from the list",kind:"end"},{id:"ready",label:"Table ready?",kind:"decision"},{id:"waiting",label:"Keeps waiting",kind:"process"}],edges:[{id:"edge-1",source:"arrives",target:"quote"},{id:"edge-2",source:"quote",target:"available"},{id:"edge-3",source:"available",target:"seat",label:"Available"},{id:"edge-4",source:"available",target:"add",label:"Not available"},{id:"edge-5",source:"add",target:"notified"},{id:"edge-6",source:"notified",target:"responds"},{id:"edge-7",source:"responds",target:"remove",label:"No response"},{id:"edge-8",source:"responds",target:"ready",label:"Responds"},{id:"edge-9",source:"ready",target:"seat",label:"Ready"},{id:"edge-10",source:"ready",target:"waiting",label:"Not ready"},{id:"edge-11",source:"waiting",target:"responds"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"restaurant-waitlist",title:"Restaurant waitlist",nodes:[{id:"arrives",label:"A party arrives",kind:"start"},{id:"quote",label:"Host quotes a wait time",kind:"process"},{id:"available",label:"Is a table available?",kind:"decision"},{id:"seat",label:"Seat the party",kind:"end"},{id:"add",label:"Add the party to the waitlist",kind:"process"},{id:"notify",label:"Notify the party",kind:"process"},{id:"responds",label:"Does the party respond?",kind:"decision"},{id:"remove",label:"Remove the party from the list",kind:"end"},{id:"ready",label:"Is the table ready?",kind:"decision"},{id:"wait",label:"Keep waiting",kind:"process"}],edges:[{id:"edge-1",source:"arrives",target:"quote"},{id:"edge-2",source:"quote",target:"available"},{id:"edge-3",source:"available",target:"seat",label:"Yes"},{id:"edge-4",source:"available",target:"add",label:"No"},{id:"edge-5",source:"add",target:"notify"},{id:"edge-6",source:"notify",target:"responds"},{id:"edge-7",source:"responds",target:"remove",label:"No response"},{id:"edge-8",source:"responds",target:"ready",label:"Responds"},{id:"edge-9",source:"ready",target:"seat",label:"Ready"},{id:"edge-10",source:"ready",target:"wait",label:"Not ready"},{id:"edge-11",source:"wait",target:"responds",label:"Check response again"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"expense-approval-process",title:"Expense Approval Process",nodes:[{id:"submit",label:"Employee submits an expense report",kind:"start",group:"employee"},{id:"review",label:"Manager reviews the report",kind:"process",group:"manager"},{id:"approved",label:"Is it approved?",kind:"decision",group:"manager"},{id:"revise",label:"Employee revises the report",kind:"process",group:"employee"},{id:"resubmit",label:"Employee resubmits it for review",kind:"process",group:"employee"},{id:"verify",label:"Finance verifies the receipts",kind:"process",group:"finance"},{id:"pay",label:"Finance pays the employee",kind:"end",group:"finance"}],edges:[{id:"edge-1",source:"submit",target:"review"},{id:"edge-2",source:"review",target:"approved"},{id:"edge-3",source:"approved",target:"revise",label:"Rejected"},{id:"edge-4",source:"revise",target:"resubmit"},{id:"edge-5",source:"resubmit",target:"review"},{id:"edge-6",source:"approved",target:"verify",label:"Approved"},{id:"edge-7",source:"verify",target:"pay"}],groups:[{id:"employee",label:"Employee"},{id:"manager",label:"Manager"},{id:"finance",label:"Finance"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sM({id:"content-moderation",title:"Content moderation",nodes:[{id:"report",label:"Report is received",kind:"start"},{id:"scan",label:"Automated scan runs",kind:"process"},{id:"severe",label:"Severe harm detected?",kind:"decision"},{id:"remove",label:"Remove the content",kind:"process"},{id:"escalate",label:"Escalate to safety",kind:"end"},{id:"violation",label:"Policy violation?",kind:"decision"},{id:"restore",label:"Restore content",kind:"end"},{id:"review",label:"Human review",kind:"process"},{id:"action",label:"Action needed?",kind:"decision"},{id:"limit",label:"Limits content",kind:"end"}],edges:[{id:"edge-1",source:"report",target:"scan"},{id:"edge-2",source:"scan",target:"severe"},{id:"edge-3",source:"severe",target:"remove",label:"Yes"},{id:"edge-4",source:"remove",target:"escalate"},{id:"edge-5",source:"severe",target:"violation",label:"No"},{id:"edge-6",source:"violation",target:"restore",label:"No"},{id:"edge-7",source:"violation",target:"review",label:"Yes"},{id:"edge-8",source:"review",target:"action"},{id:"edge-9",source:"action",target:"limit",label:"Yes"},{id:"edge-10",source:"action",target:"restore",label:"No"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sC({id:"media-player",title:"Media player",initial:"stopped",states:[{id:"stopped",label:"Stopped"},{id:"active",label:"Active",initial:"playing"},{id:"playing",label:"Playing",parent:"active"},{id:"paused",label:"Paused",parent:"active"},{id:"ended",kind:"final"}],transitions:[{id:"transition-1-stopped-active",source:"stopped",target:"active",event:"play"},{id:"transition-2-playing-paused",source:"playing",target:"paused",event:"pause"},{id:"transition-3-paused-playing",source:"paused",target:"playing",event:"resume"},{id:"transition-4-playing-playing",source:"playing",target:"playing",event:"seek",action:"jump to position"},{id:"transition-5-active-stopped",source:"active",target:"stopped",event:"stop"},{id:"transition-6-stopped-ended",source:"stopped",target:"ended",event:"eject"}]}),sC({id:"media-player",title:"Media player",initial:"stopped",states:[{id:"stopped",label:"Stopped"},{id:"active",label:"Active",initial:"playing"},{id:"playing",label:"Playing",parent:"active"},{id:"paused",label:"Paused",parent:"active"},{id:"final",kind:"final"}],transitions:[{id:"transition-1-stopped-active",source:"stopped",target:"active",event:"play"},{id:"transition-2-playing-paused",source:"playing",target:"paused",event:"pause"},{id:"transition-3-paused-playing",source:"paused",target:"playing",event:"resume"},{id:"transition-4-playing-playing",source:"playing",target:"playing",event:"seek",action:"jump to position"},{id:"transition-5-active-stopped",source:"active",target:"stopped",event:"stop"},{id:"transition-6-stopped-final",source:"stopped",target:"final",event:"eject"}]}),sC({id:"network-connection",title:"Network connection",initial:"disconnected",states:[{id:"disconnected",label:"Disconnected"},{id:"connecting",label:"Connecting"},{id:"connected",label:"Connected",initial:"idle"},{id:"idle",label:"Idle",parent:"connected"},{id:"streaming",label:"Streaming",parent:"connected"},{id:"retry_choice",kind:"choice"},{id:"failed",label:"Failed"},{id:"end",kind:"final"}],transitions:[{id:"transition-1-disconnected-connecting",source:"disconnected",target:"connecting",event:"Connect"},{id:"transition-2-connecting-connected",source:"connecting",target:"connected",event:"handshake ok"},{id:"transition-3-connecting-retry-choice",source:"connecting",target:"retry_choice",event:"timeout"},{id:"transition-4-retry-choice-connecting",source:"retry_choice",target:"connecting",guard:"retries < 3",action:"increment retries"},{id:"transition-5-retry-choice-failed",source:"retry_choice",target:"failed",guard:"no retries left"},{id:"transition-6-failed-end",source:"failed",target:"end"},{id:"transition-7-idle-streaming",source:"idle",target:"streaming",event:"start stream"},{id:"transition-8-streaming-idle",source:"streaming",target:"idle",event:"stop stream"},{id:"transition-9-connected-disconnected",source:"connected",target:"disconnected",event:"Disconnect"}]}),sC({id:"order-lifecycle",title:"Order lifecycle",initial:"pending",states:[{id:"pending",label:"Pending payment"},{id:"paid",label:"Paid"},{id:"shipped",label:"Shipped"},{id:"delivered",label:"Delivered"},{id:"cancelled",label:"Cancelled"},{id:"refunded",label:"Refunded"},{id:"end",kind:"final"}],transitions:[{id:"transition-1-pending-paid",source:"pending",target:"paid",event:"pay",guard:"card valid",action:"charge card"},{id:"transition-2-pending-cancelled",source:"pending",target:"cancelled",event:"cancel"},{id:"transition-3-paid-shipped",source:"paid",target:"shipped",event:"ship"},{id:"transition-4-paid-cancelled",source:"paid",target:"cancelled",event:"cancel",action:"refund payment"},{id:"transition-5-shipped-delivered",source:"shipped",target:"delivered",event:"deliver"},{id:"transition-6-shipped-paid",source:"shipped",target:"paid",event:"return to sender"},{id:"transition-7-delivered-refunded",source:"delivered",target:"refunded",event:"request return",guard:"within 30 days",action:"issue refund"},{id:"transition-8-delivered-end",source:"delivered",target:"end"},{id:"transition-9-cancelled-end",source:"cancelled",target:"end"},{id:"transition-10-refunded-end",source:"refunded",target:"end"}]}),sC({id:"network-connection",title:"Network Connection",initial:"Disconnected",states:[{id:"Disconnected",label:"Disconnected"},{id:"Connecting",label:"Connecting"},{id:"Connected",label:"Connected",initial:"Idle"},{id:"Idle",label:"Idle",parent:"Connected"},{id:"Streaming",label:"Streaming",parent:"Connected"},{id:"RetryCheck",label:"Retry check",kind:"choice"},{id:"Failed",label:"Failed",kind:"final"}],transitions:[{id:"transition-1-disconnected-connecting",source:"Disconnected",target:"Connecting",event:"Connect"},{id:"transition-2-connecting-connected",source:"Connecting",target:"Connected",event:"handshake ok"},{id:"transition-3-connecting-retrycheck",source:"Connecting",target:"RetryCheck",event:"timeout"},{id:"transition-4-retrycheck-connecting",source:"RetryCheck",target:"Connecting",guard:"retries < 3",action:"increment retries"},{id:"transition-5-retrycheck-failed",source:"RetryCheck",target:"Failed",guard:"no retries left"},{id:"transition-6-idle-streaming",source:"Idle",target:"Streaming",event:"start stream"},{id:"transition-7-streaming-idle",source:"Streaming",target:"Idle",event:"stop stream"},{id:"transition-8-connected-disconnected",source:"Connected",target:"Disconnected",event:"Disconnect"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"state-machine"});let sz=20*Math.PI/180;function s_(e){return 2e3/(Math.max(e.width,e.height,1)+40)}function sL(e){let t=[];for(let a of e){let e=t.at(-1);if(e&&.01>=Math.hypot(a.x-e.x,a.y-e.y))continue;let s=t.at(-2);if(s&&e&&.01>=Math.abs((e.x-s.x)*(a.y-e.y)-(e.y-s.y)*(a.x-e.x))&&(e.x-s.x)*(a.x-e.x)+(e.y-s.y)*(a.y-e.y)>0){t[t.length-1]=a;continue}t.push(a)}return t}function sB(e){let t=[];for(let a=0;a<e.length-1;a+=1){let s=e[a],i=e[a+1],l=.01>=Math.abs(s.y-i.y);!l&&Math.abs(s.x-i.x)>.01||t.push({horizontal:l,at:l?s.y:s.x,min:Math.min(l?s.x:s.y,l?i.x:i.y),max:Math.max(l?s.x:s.y,l?i.x:i.y),first:0===a,last:a===e.length-2})}return t}function sS(e,t){let a=sL(e.points),s=a[0],i=a.at(-1);if(!s||!i)return[];let l=new Map;for(let e=1;e<a.length-2;e+=1){let[o,r,n,c]=[a[e-1],a[e],a[e+1],a[e+2]],d={x:r.x-o.x,y:r.y-o.y},p={x:n.x-r.x,y:n.y-r.y},h={x:c.x-n.x,y:c.y-n.y},g=[d,p,h].every(e=>.01>=Math.abs(e.x)||.01>=Math.abs(e.y)),u=.01>=Math.abs(d.x*h.y-d.y*h.x)&&d.x*h.x+d.y*h.y>0,f=.01>=Math.abs(d.x*p.x+d.y*p.y),m=Math.hypot(p.x,p.y);g&&u&&f&&!(m*t>=150)&&(!l.has("end")&&Math.hypot(i.x-n.x,i.y-n.y)*t<=90&&2*m<=Math.hypot(d.x,d.y)?l.set("end",m):!l.has("start")&&Math.hypot(r.x-s.x,r.y-s.y)*t<=90&&2*m<=Math.hypot(h.x,h.y)&&l.set("start",m))}return[...l].map(([t,a])=>({kind:"endpoint-jog",arrowIds:[e.id],endpoint:t,message:`Arrow "${e.id}" steps ${a.toFixed(1)} units sideways near its ${"end"===t?"arrowhead":"start"}.`}))}function sA(e,t,a,s,i){return t.some(t=>s.some(s=>{if(t.horizontal!==s.horizontal||Math.abs(t.at-s.at)*i>=24)return!1;let l=Math.min(t.max,s.max)-Math.max(t.min,s.min);return!(l*i<30)&&!((t.first&&s.first&&e.sourceId&&e.sourceId===a.sourceId||t.last&&s.last&&e.targetId&&e.targetId===a.targetId)&&l*i<=90)}))}function sP(e){if(!1===e.endArrowhead)return;let t=e.points.filter((e,t,a)=>0===t||Math.hypot(e.x-a[t-1].x,e.y-a[t-1].y)>.01),a=t.at(-1),s=t.at(-2);if(!a||!s)return;let i=Math.hypot(a.x-s.x,a.y-s.y),l=Math.min(25,i/2),o=(a.x-s.x)/i,r=(a.y-s.y)/i,n=e=>({x:a.x-l*(o*Math.cos(e)-r*Math.sin(e)),y:a.y-l*(r*Math.cos(e)+o*Math.sin(e))});return[a,n(sz),n(-sz)]}function sV(e,t,a){let s=a.x-t.x,i=a.y-t.y,l=0===s&&0===i?0:Math.max(0,Math.min(1,((e.x-t.x)*s+(e.y-t.y)*i)/(s*s+i*i)));return Math.hypot(e.x-(t.x+l*s),e.y-(t.y+l*i))}function sH(e,t,a,s){let i=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x);return i(e,t,a)*i(e,t,s)<0&&i(a,s,e)*i(a,s,t)<0}function sq(e,t){let a=e.flatMap((a,s)=>e.slice(s+1).flatMap(e=>{let s,i;return[sA(a,sB(sL(a.points)),e,sB(sL(e.points)),t)?{kind:"near-coincident-corridor",arrowIds:[a.id,e.id],message:`Arrows "${a.id}" and "${e.id}" run side by side closer than 24 px.`}:void 0,(s=sP(a),i=sP(e),s&&i&&(function(e,t){let a=e=>e.map((t,a)=>[t,e[(a+1)%e.length]]),s=1/0;for(let[i,l]of a(e))for(let[e,o]of a(t)){if(sH(i,l,e,o))return 0;s=Math.min(s,sV(i,e,o),sV(l,e,o),sV(e,i,l),sV(o,i,l))}return s}(s,i)-2)*t<8?{kind:"touching-arrowheads",arrowIds:[a.id,e.id],message:`Arrowheads of "${a.id}" and "${e.id}" touch.`}:void 0)].filter(e=>void 0!==e)}));return[...e.flatMap(e=>sS(e,t)),...a.filter(e=>"near-coincident-corridor"===e.kind),...a.filter(e=>"touching-arrowheads"===e.kind)]}function sF(e,t){let a=24/t+2,s=e.map(e=>{let t=sP(e);return{arrow:e,bounds:sI([...e.points,...t??[]]),head:t,headBounds:t?sI(t):void 0,runs:sB(sL(e.points))}});return e=>{let i=sB(sL(e.points)),l=sI(e.points,a),o=e.points.slice(1).map((t,s)=>{let i=e.points[s];return{bounds:sI([i,t],a),from:i,to:t}}),r=s.filter(({arrow:t,bounds:a})=>t.id!==e.id&&sE(l,a)),n=new Set(r.filter(({arrow:a,runs:s})=>sA(e,i,a,s,t)).map(({arrow:e})=>e.id));return{arrowheadsCrossed:new Set(r.filter(({head:e,headBounds:a})=>e&&o.some(({bounds:s,from:i,to:l})=>sE(s,a)&&(function(e,t,a){let s=1/0;for(let[i,l]of a.entries()){let o=a[(i+1)%a.length];if(sH(e,t,l,o))return 0;s=Math.min(s,sV(e,l,o),sV(t,l,o),sV(l,e,t),sV(o,e,t))}return s}(i,l,e)-2)*t<8)).map(({arrow:e})=>e.id)).size,corridors:n.size,jogs:sS(e,t).length}}}function sI(e,t=0){let a=e.map(e=>e.x),s=e.map(e=>e.y);return{maxX:Math.max(...a)+t,maxY:Math.max(...s)+t,minX:Math.min(...a)-t,minY:Math.min(...s)-t}}function sE(e,t){return e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY}let sO=Object.freeze({clearance:4,fontSize:14,height:21}),sU=/[@%MW]/u,sX=/[A-Z0-9mw#$&_~]/u,sT=new Intl.Segmenter(void 0,{granularity:"grapheme"});function sY(e){let{fontSize:t}=sO,a=0;for(let{segment:s}of sT.segment(e))a+=sU.test(s)?1.02*t:sX.test(s)?.86*t:/^[\x20-\x7e]$/u.test(s)?aq(s,t):Math.max(.86*t,aq(s,t));return Math.ceil(a)}function s$(e){let{clearance:t,height:a}=sO,s=sY(e.name??"Frame");return{x:e.x-t,y:e.y-a-t,width:s+2*t,height:a+t-1}}function sG(e,t,a,s){return tL({id:e,title:t,type:"er",entities:a.map(([e,t])=>({id:e,fields:t.map(tS)})),relationships:s.map(([e,t,a,s,i],l)=>({id:`r${l+1}`,from:e,to:t,fromCardinality:a,toCardinality:s,...i?{label:i}:{}}))})}sG("marketplace-schema","Marketplace schema",[["users",["id uuid PK","email text UK","name text","created_at timestamptz"]],["profiles",["user_id uuid PK FK","bio text?","avatar_url text?"]],["addresses",["id uuid PK","user_id uuid FK","line1 text","city text","country char(2)"]],["sellers",["id uuid PK","user_id uuid FK UK","payout_account text","verified_at timestamptz?"]],["stores",["id uuid PK","seller_id uuid FK","name text","slug text UK"]],["categories",["id uuid PK","parent_id uuid FK?","name text","slug text UK"]],["products",["id uuid PK","store_id uuid FK","title text","price numeric(10,2)","status text"]],["product_categories",["product_id uuid PK FK","category_id uuid PK FK"]],["product_images",["id uuid PK","product_id uuid FK","url text","position int"]],["inventory",["product_id uuid PK FK","on_hand int","reserved int","updated_at timestamptz"]],["orders",["id uuid PK","user_id uuid FK","address_id uuid FK","status text","placed_at timestamptz"]],["order_items",["order_id uuid PK FK","product_id uuid PK FK","quantity int","unit_price numeric(10,2)"]],["payments",["id uuid PK","order_id uuid FK","amount numeric(10,2)","provider text","paid_at timestamptz?"]],["refunds",["id uuid PK","payment_id uuid FK","amount numeric(10,2)","reason text?"]],["carriers",["id uuid PK","name text UK","tracking_url text"]],["shipments",["id uuid PK","order_id uuid FK","carrier_id uuid FK","tracking_code text?","shipped_at timestamptz?"]],["reviews",["id uuid PK","product_id uuid FK","user_id uuid FK","rating int","body text?"]],["coupons",["id uuid PK","code text UK","percent_off int","expires_at timestamptz?"]],["order_coupons",["order_id uuid PK FK","coupon_id uuid PK FK"]],["wishlist_items",["user_id uuid PK FK","product_id uuid PK FK","added_at timestamptz"]]],[["users.id","profiles.user_id","one","zero-or-one"],["users.id","addresses.user_id","one","zero-or-many"],["users.id","sellers.user_id","one","zero-or-one"],["sellers.id","stores.seller_id","one","one-or-many","runs"],["categories.id","categories.parent_id","zero-or-one","zero-or-many","contains"],["stores.id","products.store_id","one","zero-or-many","lists"],["products.id","product_categories.product_id","one","one-or-many"],["categories.id","product_categories.category_id","one","zero-or-many"],["products.id","product_images.product_id","one","zero-or-many"],["products.id","inventory.product_id","one","zero-or-one"],["users.id","orders.user_id","one","zero-or-many","places"],["addresses.id","orders.address_id","one","zero-or-many"],["orders.id","order_items.order_id","one","one-or-many"],["products.id","order_items.product_id","one","zero-or-many"],["orders.id","payments.order_id","one","zero-or-many"],["payments.id","refunds.payment_id","one","zero-or-many"],["orders.id","shipments.order_id","one","zero-or-many"],["carriers.id","shipments.carrier_id","one","zero-or-many"],["products.id","reviews.product_id","one","zero-or-many"],["users.id","reviews.user_id","one","zero-or-many","writes"],["orders.id","order_coupons.order_id","one","zero-or-many"],["coupons.id","order_coupons.coupon_id","one","zero-or-many"],["users.id","wishlist_items.user_id","one","zero-or-many"],["products.id","wishlist_items.product_id","one","zero-or-many"]]),sG("threaded-comments","Threaded comments",[["comments",["id int PK","parent_id int FK?","quoted_id int FK?","author_id int FK","body text"]],["authors",["id int PK","mentor_id int FK?","handle text UK"]]],[["comments.id","comments.parent_id","zero-or-one","zero-or-many","replies"],["comments.id","comments.quoted_id","zero-or-one","zero-or-many","quotes"],["authors.id","comments.author_id","one","zero-or-many"],["authors.id","authors.mentor_id","zero-or-one","zero-or-many","mentors"]]),sG("tag-fans","Tags everywhere",[["tags",["id int PK","name text UK"]],["posts",["id int PK","title text"]],["products",["id int PK","sku text UK"]],["users",["id int PK","email text UK"]],["events",["id int PK","starts_at timestamptz"]],["post_tags",["post_id int PK FK","tag_id int PK FK"]],["product_tags",["product_id int PK FK","tag_id int PK FK"]],["user_tags",["user_id int PK FK","tag_id int PK FK"]],["event_tags",["event_id int PK FK","tag_id int PK FK"]]],[["posts.id","post_tags.post_id","one","zero-or-many"],["tags.id","post_tags.tag_id","one","zero-or-many"],["products.id","product_tags.product_id","one","zero-or-many"],["tags.id","product_tags.tag_id","one","zero-or-many"],["users.id","user_tags.user_id","one","zero-or-many"],["tags.id","user_tags.tag_id","one","zero-or-many"],["events.id","event_tags.event_id","one","zero-or-many"],["tags.id","event_tags.tag_id","one","zero-or-many"]]),sG("saas-workspace","SaaS workspace",[["organizations",["id uuid PK","name text"]],["users",["id uuid PK","email text UK","name text"]],["memberships",["organization_id uuid PK FK","user_id uuid PK FK","role text"]],["projects",["id uuid PK","organization_id uuid FK","name text"]],["tasks",["id uuid PK","project_id uuid FK","assignee_id uuid? FK","title text","due_on date?"]],["comments",["id uuid PK","task_id uuid FK","author_id uuid FK","body text"]],["labels",["id uuid PK","organization_id uuid FK","name text"]],["task_labels",["task_id uuid PK FK","label_id uuid PK FK"]],["plans",["id uuid PK","name text UK","monthly_price numeric"]],["subscriptions",["id uuid PK","organization_id uuid FK UK","plan_id uuid FK","renews_on date"]],["invoices",["id uuid PK","subscription_id uuid FK","amount numeric","paid_at timestamptz?"]],["api_keys",["id uuid PK","organization_id uuid FK","created_by uuid FK","token_hash text UK"]]],[["organizations.id","memberships.organization_id","one","one-or-many"],["users.id","memberships.user_id","one","zero-or-many"],["organizations.id","projects.organization_id","one","zero-or-many"],["projects.id","tasks.project_id","one","zero-or-many"],["users.id","tasks.assignee_id","zero-or-one","zero-or-many"],["tasks.id","comments.task_id","one","zero-or-many"],["users.id","comments.author_id","one","zero-or-many"],["organizations.id","labels.organization_id","one","zero-or-many"],["tasks.id","task_labels.task_id","one","zero-or-many"],["labels.id","task_labels.label_id","one","zero-or-many"],["organizations.id","subscriptions.organization_id","one","zero-or-one"],["plans.id","subscriptions.plan_id","one","zero-or-many"],["subscriptions.id","invoices.subscription_id","one","zero-or-many"],["organizations.id","api_keys.organization_id","one","zero-or-many"],["users.id","api_keys.created_by","one","zero-or-many"]]);let sD=e=>t6(ao({type:"class",...e}));function sR(e,t="LR"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}sD({id:"library-model",title:"Library model",classes:[{id:"Library",attributes:["- name: String"],methods:["+ search(q: String): List<Item>"]},{id:"Branch",attributes:["- address: String"]},{id:"Item",kind:"abstract",attributes:["# id: UUID","# title: String"],methods:["+ loanPeriod(): int {abstract}"]},{id:"Book",attributes:["- isbn: String","- pages: int"],methods:["+ loanPeriod(): int"]},{id:"DVD",attributes:["- minutes: int"],methods:["+ loanPeriod(): int"]},{id:"Magazine",attributes:["- issue: int"],methods:["+ loanPeriod(): int"]},{id:"EBook",attributes:["- fileSize: long"]},{id:"Author",attributes:["- name: String"]},{id:"Publisher",attributes:["- name: String"]},{id:"Member",attributes:["- memberId: String","- name: String"],methods:["+ borrow(i: Item): Loan","+ reserve(i: Item): Reservation"]},{id:"StudentMember",attributes:["- school: String"]},{id:"StaffMember",attributes:["- department: String"]},{id:"Loan",attributes:["- due: Date","- returned: Date"],methods:["+ isOverdue(): bool"]},{id:"Reservation",attributes:["- placed: Date"]},{id:"Fine",attributes:["- amount: Money"],methods:["+ pay(): void"]},{id:"Librarian",attributes:["- staffId: String"],methods:["+ checkOut(l: Loan): void"]},{id:"Notifier",kind:"interface",methods:["+ send(m: Member, text: String): void"]},{id:"EmailNotifier",methods:["+ send(m: Member, text: String): void"]},{id:"SmsNotifier",methods:["+ send(m: Member, text: String): void"]},{id:"Catalog",methods:["+ add(i: Item): void","+ find(isbn: String): Book"]}],relationships:[{kind:"composition",from:"Library",to:"Branch",fromMultiplicity:"1",toMultiplicity:"1..*"},{kind:"composition",from:"Library",to:"Catalog",fromMultiplicity:"1",toMultiplicity:"1"},{kind:"aggregation",from:"Catalog",to:"Item",fromMultiplicity:"1",toMultiplicity:"0..*",toRole:"items"},{kind:"inheritance",from:"Book",to:"Item"},{kind:"inheritance",from:"DVD",to:"Item"},{kind:"inheritance",from:"Magazine",to:"Item"},{kind:"inheritance",from:"EBook",to:"Book"},{kind:"association",from:"Book",to:"Author",fromMultiplicity:"*",toMultiplicity:"1..*",toRole:"authors"},{kind:"association",from:"Book",to:"Publisher",fromMultiplicity:"*",toMultiplicity:"1"},{kind:"inheritance",from:"StudentMember",to:"Member"},{kind:"inheritance",from:"StaffMember",to:"Member"},{kind:"association",from:"Member",to:"Loan",fromMultiplicity:"1",toMultiplicity:"0..*",navigable:!0},{kind:"association",from:"Loan",to:"Item",fromMultiplicity:"*",toMultiplicity:"1",navigable:!0},{kind:"association",from:"Member",to:"Reservation",fromMultiplicity:"1",toMultiplicity:"0..*"},{kind:"association",from:"Reservation",to:"Item",fromMultiplicity:"*",toMultiplicity:"1"},{kind:"composition",from:"Loan",to:"Fine",fromMultiplicity:"1",toMultiplicity:"0..1"},{kind:"dependency",from:"Librarian",to:"Loan",label:"checks out"},{kind:"realization",from:"EmailNotifier",to:"Notifier"},{kind:"realization",from:"SmsNotifier",to:"Notifier"},{kind:"dependency",from:"Loan",to:"Notifier"},{kind:"association",from:"Librarian",to:"Branch",fromMultiplicity:"*",toMultiplicity:"1"}].map((e,t)=>({id:`r${t+1}`,...e}))}),sD({id:"vehicles",title:"Vehicles",classes:[{id:"Vehicle",kind:"abstract",attributes:["# wheels: int","# maxSpeed: double"],methods:["+ move(): void {abstract}"]},...["Car","Truck","Bicycle","Motorcycle","Bus","Tram","Scooter","Van"].map(e=>({id:e,methods:["+ move(): void"]})),{id:"Engine",attributes:["- power: int"]},{id:"Electric",kind:"interface",methods:["+ charge(): void"]}],relationships:[...["Car","Truck","Bicycle","Motorcycle","Bus","Tram","Scooter","Van"].map(e=>({id:`${e}-is-vehicle`,kind:"inheritance",from:e,to:"Vehicle"})),{id:"car-engine",kind:"composition",from:"Car",to:"Engine",fromMultiplicity:"1",toMultiplicity:"1"},{id:"tram-electric",kind:"realization",from:"Tram",to:"Electric"},{id:"scooter-electric",kind:"realization",from:"Scooter",to:"Electric"}]}),sD({id:"widgets",title:"Widgets",classes:[{id:"Component",kind:"interface",methods:["+ render(): Node"]},{id:"Widget",kind:"abstract",attributes:["# id: String"]},{id:"Control",kind:"abstract",attributes:["# enabled: bool"]},{id:"ButtonBase",kind:"abstract",methods:["+ click(): void {abstract}"]},{id:"IconButton",attributes:["- icon: Icon"],methods:["+ click(): void"]},{id:"Clickable",kind:"interface",methods:["+ click(): void"]},{id:"Theme",attributes:["- palette: Map<String, Color>"]}],relationships:[{id:"widget-component",kind:"realization",from:"Widget",to:"Component"},{id:"control-widget",kind:"inheritance",from:"Control",to:"Widget"},{id:"button-control",kind:"inheritance",from:"ButtonBase",to:"Control"},{id:"icon-button",kind:"inheritance",from:"IconButton",to:"ButtonBase"},{id:"icon-clickable",kind:"realization",from:"IconButton",to:"Clickable"},{id:"widget-theme",kind:"dependency",from:"Widget",to:"Theme"},{id:"icon-theme",kind:"association",from:"IconButton",to:"Theme",toMultiplicity:"0..1",toRole:"override"}]}),sD({id:"org",title:"Organization",classes:[{id:"Employee",attributes:["- name: String","- title: String"],methods:["+ reports(): List<Employee>"]},{id:"Department",attributes:["- name: String"]}],relationships:[{id:"manages",kind:"association",from:"Employee",to:"Employee",fromMultiplicity:"0..1",toMultiplicity:"0..*",fromRole:"manager",toRole:"reports"},{id:"mentors",kind:"association",from:"Employee",to:"Employee",fromMultiplicity:"0..1",toMultiplicity:"0..*",fromRole:"mentor",toRole:"mentees"},{id:"works-in",kind:"association",from:"Employee",to:"Department",fromMultiplicity:"*",toMultiplicity:"1",label:"works in"}]}),sD({id:"strategy",title:"Strategy",classes:[{id:"Checkout",methods:["+ total(cart: Cart): Money"]},{id:"PricingStrategy",kind:"interface",methods:["+ price(cart: Cart): Money"]},{id:"Cart",attributes:["- items: List<Item>"]},{id:"Regular",methods:["+ price(cart: Cart): Money"]},{id:"Sale",methods:["+ price(cart: Cart): Money"]}],relationships:[{id:"uses",kind:"aggregation",from:"Checkout",to:"PricingStrategy",fromMultiplicity:"1",toMultiplicity:"1",toRole:"strategy"},{id:"prices",kind:"dependency",from:"PricingStrategy",to:"Cart"},{id:"totals",kind:"dependency",from:"Checkout",to:"Cart"},{id:"regular",kind:"realization",from:"Regular",to:"PricingStrategy"},{id:"sale",kind:"realization",from:"Sale",to:"PricingStrategy"}]}),sR({id:"order-fulfilment-lanes",title:"Order fulfilment",lanes:[{id:"customer",label:"Customer"},{id:"sales",label:"Sales"},{id:"warehouse",label:"Warehouse"},{id:"billing",label:"Billing"}],nodes:[{id:"place",label:"Place order",kind:"start",lane:"customer"},{id:"review",label:"Review order",kind:"process",lane:"sales"},{id:"stock",label:"Items in stock?",kind:"decision",lane:"sales"},{id:"backorder",label:"Notify backorder",kind:"end",lane:"sales"},{id:"pick",label:"Pick items",kind:"process",lane:"warehouse"},{id:"pack",label:"Pack the order",kind:"process",lane:"warehouse"},{id:"ship",label:"Ship the order",kind:"process",lane:"warehouse"},{id:"invoice",label:"Send invoice",kind:"process",lane:"billing"},{id:"pay",label:"Pay the invoice",kind:"process",lane:"customer"},{id:"record",label:"Record payment",kind:"end",lane:"billing"}],edges:[{id:"e1",source:"place",target:"review"},{id:"e2",source:"review",target:"stock"},{id:"e3",source:"stock",target:"backorder",label:"no"},{id:"e4",source:"stock",target:"pick",label:"yes"},{id:"e5",source:"pick",target:"pack"},{id:"e6",source:"pack",target:"ship"},{id:"e7",source:"ship",target:"invoice"},{id:"e8",source:"invoice",target:"pay"},{id:"e9",source:"pay",target:"record"}]}),sR({id:"hiring-lanes",title:"Hiring process",lanes:[{id:"candidate",label:"Candidate"},{id:"recruiter",label:"Recruiter"},{id:"manager",label:"Hiring manager"}],nodes:[{id:"apply",label:"Submit application",kind:"start",lane:"candidate"},{id:"screen",label:"Screen the résumé",kind:"process",lane:"recruiter"},{id:"qualified",label:"Qualified?",kind:"decision",lane:"recruiter"},{id:"decline",label:"Receive rejection",kind:"end",lane:"candidate"},{id:"schedule",label:"Schedule interview",kind:"process",lane:"recruiter"},{id:"interview",label:"Attend interview",kind:"process",lane:"candidate"},{id:"assess",label:"Assess the candidate",kind:"process",lane:"manager"},{id:"hire",label:"Hire?",kind:"decision",lane:"manager"},{id:"offer",label:"Send offer",kind:"process",lane:"recruiter"},{id:"accept",label:"Accept offer",kind:"end",lane:"candidate"}],edges:[{id:"e1",source:"apply",target:"screen"},{id:"e2",source:"screen",target:"qualified"},{id:"e3",source:"qualified",target:"decline",label:"no"},{id:"e4",source:"qualified",target:"schedule",label:"yes"},{id:"e5",source:"schedule",target:"interview"},{id:"e6",source:"interview",target:"assess"},{id:"e7",source:"assess",target:"hire"},{id:"e8",source:"hire",target:"offer",label:"yes"},{id:"e9",source:"hire",target:"schedule",label:"another round"},{id:"e10",source:"offer",target:"accept"}]},"TB"),sR({id:"incident-response-lanes",title:"Incident response",lanes:[{id:"oncall",label:"On-call"},{id:"sre",label:"SRE"},{id:"comms",label:"Comms"}],nodes:[{id:"alert",label:"Alert fires",kind:"start",lane:"oncall"},{id:"triage",label:"Triage the alert",kind:"process",lane:"oncall"},{id:"page",label:"Page the SRE",kind:"process",lane:"oncall"},{id:"status",label:"Post status update",kind:"process",lane:"comms"},{id:"investigate",label:"Investigate",kind:"process",lane:"sre"},{id:"mitigate",label:"Apply mitigation",kind:"process",lane:"sre"},{id:"resolved",label:"Resolved?",kind:"decision",lane:"oncall"},{id:"close",label:"Publish resolution",kind:"end",lane:"comms"}],edges:[{id:"e1",source:"alert",target:"triage"},{id:"e2",source:"triage",target:"page"},{id:"e3",source:"page",target:"investigate"},{id:"e4",source:"investigate",target:"mitigate"},{id:"e5",source:"mitigate",target:"status"},{id:"e6",source:"status",target:"resolved"},{id:"e7",source:"resolved",target:"investigate",label:"no"},{id:"e8",source:"resolved",target:"close",label:"yes"}]}),sR({id:"skip-lanes",title:"Purchase request",lanes:[{id:"requester",label:"Requester"},{id:"procurement",label:"Procurement"},{id:"finance",label:"Finance"},{id:"vendor",label:"Vendor"}],nodes:[{id:"request",label:"Raise purchase request",kind:"start",lane:"requester"},{id:"budget",label:"Within budget?",kind:"decision",lane:"finance"},{id:"quotes",label:"Collect quotes",kind:"process",lane:"procurement"},{id:"compare",label:"Compare vendors",kind:"process",lane:"procurement"},{id:"terms",label:"Check payment terms",kind:"process",lane:"finance"},{id:"order",label:"Place purchase order",kind:"process",lane:"procurement"},{id:"deliver",label:"Deliver goods",kind:"process",lane:"vendor"},{id:"receive",label:"Receive goods",kind:"end",lane:"requester"},{id:"denied",label:"Request denied",kind:"end",lane:"requester"}],edges:[{id:"e1",source:"request",target:"budget"},{id:"e2",source:"budget",target:"quotes",label:"yes"},{id:"e3",source:"budget",target:"denied",label:"no"},{id:"e4",source:"quotes",target:"compare"},{id:"e5",source:"quotes",target:"terms"},{id:"e6",source:"compare",target:"order"},{id:"e7",source:"terms",target:"order"},{id:"e8",source:"order",target:"deliver"},{id:"e9",source:"deliver",target:"receive"}]}),sR({id:"single-lane",title:"Ticket handling",lanes:[{id:"support",label:"Support desk"}],nodes:[{id:"open",label:"Ticket opened",kind:"start",lane:"support"},{id:"answer",label:"Answer the customer",kind:"process",lane:"support"},{id:"solved",label:"Solved?",kind:"decision",lane:"support"},{id:"escalate",label:"Escalate",kind:"process",lane:"support"},{id:"close",label:"Close the ticket",kind:"end",lane:"support"}],edges:[{id:"e1",source:"open",target:"answer"},{id:"e2",source:"answer",target:"solved"},{id:"e3",source:"solved",target:"close",label:"yes"},{id:"e4",source:"solved",target:"escalate",label:"no"},{id:"e5",source:"escalate",target:"answer"}]},"TB");let sZ=["Customer","Support","Billing","Engineering","QA","Release"],sj=["Report the problem","Triage the ticket","Check the account","Reproduce the bug","Write a fix","Review the change","Run regression tests","Approve the release","Ship the fix","Confirm with customer"],sN=Array.from({length:30}).reduce((e,t,a)=>{let s=e.at(-1)??0,i=[0,1,1,0,2,-1,1,0,-1,-2][a%10],l=s+i;return[...e,l<0||l>5?s-i:l]},[]);U({id:"six-lanes-thirty-steps",title:"Thirty steps across six lanes",type:"flowchart",lanes:sZ.map((e,t)=>({id:`l${t}`,label:e})),nodes:Array.from({length:30},(e,t)=>({id:`s${t}`,label:`${sj[t%sj.length]} ${t}`,kind:0===t?"start":29===t?"end":t%7==3?"decision":"process",lane:`l${sN[t]}`})),edges:[...Array.from({length:29},(e,t)=>({id:`e${t}`,source:`s${t}`,target:`s${t+1}`,...t%7==3?{label:"yes"}:{}})),...Array.from({length:30},(e,t)=>t).filter(e=>e%7==3&&e<28).map(e=>({id:`b${e}`,source:`s${e}`,target:`s${e%2==0?e+2:e-2}`,label:"no"}))],layout:{direction:"LR",edgeRouting:"orthogonal"}}),U({id:"cross-lane-loops",title:"Loops across lanes",type:"flowchart",lanes:sZ.slice(0,4).map((e,t)=>({id:`l${t}`,label:e})),nodes:Array.from({length:14},(e,t)=>({id:`n${t}`,label:`${sj[t%sj.length]} ${t}`,kind:0===t?"start":13===t?"end":t%3==2?"decision":"process",lane:`l${3*t%4}`})),edges:[...Array.from({length:13},(e,t)=>({id:`e${t}`,source:`n${t}`,target:`n${t+1}`,...t%3==2?{label:"yes"}:{}})),...[2,5,8,11].map(e=>({id:`loop${e}`,source:`n${e}`,target:`n${Math.max(1,e-2-e%2)}`,label:"retry"}))],layout:{direction:"LR",edgeRouting:"orthogonal"}});let sW=["Ada","Grace","Alan","Barbara","Edsger","Frances","Donald","Hedy","John","Katherine","Leslie","Mary","Niklaus","Radia","Tim","Shafi","Vint","Lynn","Ken","Sophie"],sJ=["Lovelace","Hopper","Turing","Liskov","Dijkstra","Allen","Knuth","Lamarr","Backus","Johnson","Lamport","Keller","Wirth","Perlman","Berners-Lee","Goldwasser","Cerf","Conway","Thompson","Wilson"],sK=["Engineering","Product","Sales","Marketing","Operations","Finance"],sQ=["Chief Executive Officer","Vice President","Director","Engineering Manager","Team Lead","Senior Engineer","Engineer"];function s1(e){return`${sW[e%sW.length]} ${sJ[(7*e+Math.floor(e/sW.length))%sJ.length]}`}function s0(e,t,a,s={}){let i=[{id:"p0",name:s1(0),title:sQ[0],department:"Executive"}],l=[{id:"p0",department:"Executive"}];for(let[e,t]of a.entries()){let a=[];l.forEach((s,l)=>{let o=t[l%t.length];for(let t=0;t<o;t+=1){let l=i.length,o=0===e?sK[t%sK.length]:s.department,r={id:`p${l}`,department:o};i.push({id:r.id,name:s1(l),title:sQ[Math.min(e+1,sQ.length-1)],department:o,manager:s.id}),a.push(r)}}),l=a}return av(aC({id:e,title:t,type:ar,people:i,...s}))}function s2(e,t="LR"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}s0("eighty-people","Eighty people",[[6],[3,2,4],[3,4,2,3,3,3,4,3,2,3,4,3,2,3,3,3,4,3]]),s0("twenty-reports","Twenty reports",[[1],[20]]),s0("six-levels","Six levels deep",[[2],[2,1],[1,2],[2,1],[1,2]]),s0("department","Department of twenty-five",[[3],[8,6,7]]),s0("wide-top","Twelve vice presidents",[[12],[2,3,1]]),av(aC({id:"three-boards",title:"Three boards",type:ar,forest:!0,people:[{id:"a",name:"North Board",title:"Chair"},{id:"a1",name:"Ada Lovelace",title:"Member",manager:"a"},{id:"a2",name:"Alan Turing",title:"Member",manager:"a"},{id:"b",name:"South Board",title:"Chair"},{id:"b1",name:"Grace Hopper",title:"Member",manager:"b"},{id:"c",name:"West Board",title:"Chair"}]})),s0("regions","Departments as regions",[[4],[3,2,1,4],[0,2,1]],{groupByDepartment:!0}),s2({id:"aws-three-tier",title:"AWS three-tier app",groups:[{id:"region",label:"us-east-1",kind:"region"},{id:"vpc",label:"VPC 10.0.0.0/16",kind:"vpc",parent:"region"},{id:"public",label:"Public subnet",kind:"subnet",parent:"vpc"},{id:"private",label:"Private subnet",kind:"subnet",parent:"vpc"},{id:"data",label:"Database subnet",kind:"subnet",parent:"vpc"}],nodes:[{id:"users",label:"Users",kind:"start"},{id:"alb",label:"Application Load Balancer",kind:"process",group:"public"},{id:"web",label:"ECS web service",kind:"process",group:"private"},{id:"api",label:"ECS API service",kind:"process",group:"private"},{id:"rds",label:"RDS PostgreSQL",kind:"end",shape:"database",group:"data"},{id:"s3",label:"S3 assets bucket",kind:"end",shape:"storage",group:"region"}],edges:[{id:"e1",source:"users",target:"alb"},{id:"e2",source:"alb",target:"web"},{id:"e3",source:"alb",target:"api"},{id:"e4",source:"web",target:"rds"},{id:"e5",source:"api",target:"rds"},{id:"e6",source:"api",target:"s3"}]}),s2({id:"kubernetes-cluster",title:"Kubernetes cluster",groups:[{id:"cluster",label:"GKE cluster",kind:"cluster"},{id:"edge",label:"ingress-nginx",kind:"namespace",parent:"cluster"},{id:"frontend",label:"frontend",kind:"namespace",parent:"cluster"},{id:"backend",label:"backend",kind:"namespace",parent:"cluster"}],nodes:[{id:"client",label:"Browser",kind:"start"},{id:"ingress",label:"Ingress controller",kind:"process",group:"edge"},{id:"web-svc",label:"web Service",kind:"process",group:"frontend"},{id:"web-pods",label:"web Pods",kind:"process",group:"frontend"},{id:"api-svc",label:"api Service",kind:"process",group:"backend"},{id:"api-pods",label:"api Pods",kind:"process",group:"backend"},{id:"worker",label:"worker Pods",kind:"process",group:"backend"},{id:"queue",label:"RabbitMQ jobs queue",kind:"process",shape:"queue"},{id:"db",label:"Cloud SQL Postgres",kind:"end",shape:"database"}],edges:[{id:"e1",source:"client",target:"ingress"},{id:"e2",source:"ingress",target:"web-svc"},{id:"e3",source:"web-svc",target:"web-pods"},{id:"e4",source:"web-pods",target:"api-svc"},{id:"e5",source:"api-svc",target:"api-pods"},{id:"e6",source:"api-pods",target:"db"},{id:"e7",source:"api-pods",target:"queue"},{id:"e8",source:"queue",target:"worker"},{id:"e9",source:"worker",target:"db"}]},"TB"),s2({id:"hybrid-cloud",title:"Hybrid on-prem and cloud",groups:[{id:"onprem",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",kind:"zone",parent:"onprem"},{id:"aws",label:"AWS",kind:"cloud"},{id:"region",label:"eu-west-1",kind:"region",parent:"aws"},{id:"vpc",label:"Production VPC",kind:"vpc",parent:"region"},{id:"private",label:"Private subnet",kind:"subnet",parent:"vpc"}],nodes:[{id:"staff",label:"Office staff",kind:"start",group:"corp"},{id:"erp",label:"Legacy ERP",kind:"process",group:"corp"},{id:"oracle",label:"Oracle database",kind:"end",shape:"database",group:"onprem"},{id:"vpn",label:"Site-to-site VPN",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"private"},{id:"orders",label:"Order queue",kind:"process",shape:"queue",group:"region"},{id:"sync",label:"Sync function",kind:"process",group:"region"},{id:"dynamo",label:"Orders table",kind:"end",shape:"database",group:"region"},{id:"invoice",label:"Invoice archive",kind:"end",shape:"document",group:"region"}],edges:[{id:"e1",source:"staff",target:"erp"},{id:"e2",source:"erp",target:"oracle"},{id:"e3",source:"erp",target:"vpn"},{id:"e4",source:"vpn",target:"api"},{id:"e5",source:"api",target:"orders"},{id:"e6",source:"orders",target:"sync"},{id:"e7",source:"sync",target:"dynamo"},{id:"e8",source:"sync",target:"invoice"}]}),s2({id:"kinded-flat",title:"Two availability zones",groups:[{id:"az-a",label:"us-east-1a",kind:"zone"},{id:"az-b",label:"us-east-1b",kind:"zone"}],nodes:[{id:"lb",label:"Network Load Balancer",kind:"start"},{id:"app-a",label:"App server A",kind:"process",group:"az-a"},{id:"db-a",label:"Primary database",kind:"end",shape:"database",group:"az-a"},{id:"app-b",label:"App server B",kind:"process",group:"az-b"},{id:"db-b",label:"Standby replica",kind:"end",shape:"database",group:"az-b"}],edges:[{id:"e1",source:"lb",target:"app-a"},{id:"e2",source:"lb",target:"app-b"},{id:"e3",source:"app-a",target:"db-a"},{id:"e4",source:"app-b",target:"db-b"}]},"TB"),U({id:"depth-four",title:"Two availability zones, four zones deep",type:"flowchart",groups:[{id:"region",label:"us-west-2",kind:"region"},{id:"vpc",label:"VPC",kind:"vpc",parent:"region"},{id:"az-a",label:"us-west-2a",kind:"zone",parent:"vpc"},{id:"az-b",label:"us-west-2b",kind:"zone",parent:"vpc"},{id:"public-a",label:"Public subnet A",kind:"subnet",parent:"az-a"},{id:"private-a",label:"Private subnet A",kind:"subnet",parent:"az-a"},{id:"public-b",label:"Public subnet B",kind:"subnet",parent:"az-b"},{id:"private-b",label:"Private subnet B",kind:"subnet",parent:"az-b"}],nodes:[{id:"users",label:"Users",kind:"start"},{id:"alb",label:"Load balancer",kind:"process",group:"vpc"},{id:"web-a",label:"Web server A",kind:"process",group:"public-a"},{id:"web-b",label:"Web server B",kind:"process",group:"public-b"},{id:"app-a",label:"App server A",kind:"process",group:"private-a"},{id:"app-b",label:"App server B",kind:"process",group:"private-b"},{id:"db-a",label:"Primary database",kind:"end",shape:"database",group:"private-a"},{id:"db-b",label:"Standby database",kind:"end",shape:"database",group:"private-b"},{id:"s3",label:"Backups bucket",kind:"end",shape:"storage",group:"region"}],edges:[{id:"e1",source:"users",target:"alb"},{id:"e2",source:"alb",target:"web-a"},{id:"e3",source:"alb",target:"web-b"},{id:"e4",source:"web-a",target:"app-a"},{id:"e5",source:"web-b",target:"app-b"},{id:"e6",source:"app-a",target:"db-a"},{id:"e7",source:"app-b",target:"db-b"},{id:"e8",source:"db-a",target:"db-b",label:"replicates"},{id:"e9",source:"db-a",target:"s3",label:"backs up"}],layout:{direction:"LR",edgeRouting:"orthogonal"}}),U({id:"thirty-services",title:"Thirty services in eight zones",type:"flowchart",groups:[{id:"aws",label:"AWS",kind:"cloud"},{id:"region",label:"us-east-1",kind:"region",parent:"aws"},{id:"vpc",label:"Production VPC",kind:"vpc",parent:"region"},{id:"public",label:"Public subnet",kind:"subnet",parent:"vpc"},{id:"app",label:"App subnet",kind:"subnet",parent:"vpc"},{id:"data",label:"Data subnet",kind:"subnet",parent:"vpc"},{id:"onprem",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",kind:"zone",parent:"onprem"}],nodes:[["Customers"],["CloudFront CDN","aws"],["WAF rules","region"],["Route 53 DNS","region"],["Load balancer","public"],["NAT gateway","public"],["Bastion host","public"],["Web frontend","app"],["Auth service","app"],["Catalog service","app"],["Cart service","app"],["Checkout service","app"],["Payments service","app"],["Session cache","data","database"],["Catalog database","data","database"],["Orders database","data","database"],["Order events","region","queue"],["Email worker","vpc"],["Invoice renderer","vpc"],["Invoice PDFs","region","document"],["Analytics stream","region","queue"],["Data warehouse","aws","database"],["VPN gateway","vpc"],["Corporate VPN","corp"],["ERP sync","corp"],["ERP system","corp"],["Finance team","corp"],["Mainframe ledger","onprem","database"],["Audit log","onprem","document"],["Partners"]].map(([e,t,a],s)=>({id:`s${s}`,label:e,kind:0===s?"start":"process",...t?{group:t}:{},...a?{shape:a}:{}})),edges:[[0,1],[1,2],[2,4],[3,4],[0,3],[4,7],[5,7],[6,8],[7,8],[7,9],[7,10],[10,11],[11,12],[8,13],[9,14],[11,15],[12,15],[11,16],[16,17],[16,18],[18,19],[16,20],[20,21],[12,22],[22,23],[23,24],[24,25],[25,26],[25,27],[24,28],[29,22]].map(([e,t],a)=>({id:`e${a}`,source:`s${e}`,target:`s${t}`})),layout:{direction:"LR",edgeRouting:"orthogonal"}});let s3=/[,;]\s*(?:id|label|kind|group|source|target|title|direction|nodes|edges)\s*:?\s*$/i;function s5(e){let t=e.trim();for(;;){let e=t.replace(s3,"").trim();if(e===t)return t;t=e}}class s4 extends i.Xsx("ContractSchemaIssue")({code:im("custom"),issueTag:i.xCb(["Filter","InvalidType","InvalidValue","MissingKey","UnexpectedKey","Forbidden","OneOf","AnyOf"]),astKind:i.Qrq(i.QfV),missingKeyCode:i.Qrq(i.uSQ("invalid_type")),message:i.QfV,path:i.O31(i.pHd)},{identifier:void 0}){}class s6 extends i.rNF()("ContractSchemaError",{issues:i.O31(i.O3D(s4))}){}let s7=e=>{var t;if("InvalidType"!==e._tag)return d.vp(e);let a=d.bZ(e)?e.input:void 0;return`Invalid input: expected ${t=e.ast,c.Kg(t)?"string":c.Et(t)?"number":c.Lm(t)?"boolean":c.tF(t)?"array":c.RP(t)?"object":c.c$(t)?JSON.stringify(t.literal):"value"}, received ${null===a?"null":Array.isArray(a)?"array":typeof a}`},s8=d.ID({leafHook:s7});function s9(e){let t,a;return new s6({issues:(t=[],((a=(e,s,i)=>{switch(e._tag){case"Pointer":return a(e.issue,[...s,...e.path],i);case"Encoding":return a(e.issue,s,i);case"Composite":for(let t of e.issues)a(t,s,e.ast);return;case"AnyOf":if(e.issues.length>0){for(let t of e.issues)a(t,s,e.ast);return}break;case"Filter":if(void 0===d.VY(e)&&"InvalidValue"!==e.issue._tag)return a(e.issue,s,i)}let l="ast"in e?e.ast:i,o="MissingKey"===e._tag&&e.annotations?.[ii]==="invalid_type"?"invalid_type":void 0,r=l&&c.mi(l)&&l.types.every(c.c$)?"LiteralUnion":l?._tag,n=l?.annotations?.[is],p="string"==typeof n?[...s,n]:s;for(let a of s8(e).issues)t.push({code:"custom",issueTag:e._tag,...o?{missingKeyCode:o}:{},...r?{astKind:r}:{},message:a.message,path:p})})(e.issue,[]),t.length>1&&t.every(e=>"source"===e.path[0]))?[{code:"custom",issueTag:"AnyOf",astKind:"Union",message:"Invalid input",path:["source"]}]:t)})}let ie=new Set(["x-sketchi-default","x-sketchi-one-of","const","exclusiveMaximum","exclusiveMinimum","maximum","maxLength","maxItems","minimum","minItems","minLength","pattern"]),it="x-sketchi-default",ia="x-sketchi-one-of",is="codeModeDiscriminator",ii="codeModeMissingKeyCode";function il(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function io(e){let t=i._oz(i.AxX(e),{includeAnnotationKey:e=>ie.has(e),onExcessProperty:"error"});return function e(t){if(Array.isArray(t))return t.map(e);if(!il(t))return t;let a=Object.fromEntries(Object.entries(t).map(([t,a])=>[t,e(a)])),s=!0===a[ia];delete a[ia],s&&Array.isArray(a.anyOf)&&(a.oneOf=a.anyOf,delete a.anyOf);let i=a.allOf;if(Array.isArray(i)){let e=[];for(let t of i)il(t)&&Object.hasOwn(t,it)?a.default=t[it]:e.push(t);0===e.length?delete a.allOf:a.allOf=e}return a}({$schema:"https://json-schema.org/draft/2020-12/schema",...t.schema,...0===Object.keys(t.definitions).length?{}:{$defs:t.definitions}})}function ir(){return i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"}))}function ic(e){return i.O31(e).pipe(i.fXn).check(i.tJb(1,{message:"Too small: expected array to have >=1 items"}))}function id(e){return i.Qrq(e)}function ip(e){return e.pipe(i.usV({[ii]:"invalid_type",messageMissingKey:"Invalid input: expected string, received undefined"}))}function ih(e){return e.pipe(i.usV({[ii]:"invalid_type",messageMissingKey:"Invalid input: expected object, received undefined"}))}function ig(e){return e.pipe(i.usV({[ii]:"invalid_type",messageMissingKey:"Invalid input: expected array, received undefined"}))}function iu(e){return i.xCb(e).annotate({message:`Invalid option: expected one of ${e.map(e=>JSON.stringify(e)).join("|")}`})}function im(e){return iw(e,i.QfV)}function iv(e){return iw(e,i.wNn)}function iy(e){return iw(e,i.v8c)}function iw(e,t){let a=i.hzj()([],()=>(t,a,s)=>t===e?o.PyW(e):o.fJG(new d.eE(a,t,s)),{message:`Invalid literal value, expected ${JSON.stringify(e)}`,toCodecJson:()=>i.nfo()(t.annotate({const:e}),{decode:p.pd(()=>e),encode:p.pd(e=>e)})});return i.uSQ(e).pipe(i.GLL(a))}let ix=ir(),ib=ip(ix),ik=i.wYs,iM=i.wNn.check(i.MIs(),i.yJO(0,{message:"Too small: expected number to be >0"})),iC=/^#[0-9a-fA-F]{6}$/u;function iz(e){return i.QfV.annotate(void 0===e?{}:{default:e}).check(i.Pto(iC,{message:`Invalid string: must match pattern /${iC.source}/`}))}let i_=iz(),iL=["excalidraw","scene","png"],iB=["excalidraw","scene"],iS=Object.assign(iu(iL),{options:iL}),iA=Object.assign(iu(iB),{options:iB});class iP extends i.Xsx("ArtifactProvenance")({sourceArtifactId:ib.pipe(i.Wa3)},{identifier:void 0}){}let iV=["missing_field","invalid_type","invalid_enum","invalid_color","duplicate_node_id","duplicate_edge_id","missing_edge_source","missing_edge_target","self_loop","missing_start","multiple_starts","missing_end","start_has_incoming","end_has_outgoing","unreachable_node","nonterminating_node","missing_outgoing_edge","underbranched_decision","unlabeled_decision_branch","duplicate_decision_branch_label","disconnected_graph","flowchart_too_large","duplicate_group_id","unknown_node_group","empty_group","unknown_group_parent","group_cycle","shaped_decision","duplicate_lane_id","unknown_node_lane","empty_lane","lanes_with_groups","mindmap_too_deep","mindmap_too_large","sequence_too_large","invalid_timeline_date","duplicate_event_id","invalid_timeline_order","timeline_too_large","invalid_timeline_span","invalid_timeline_lane","chart_too_large","chart_series_mismatch","duplicate_chart_category","invalid_chart_series","invalid_chart_value","invalid_chart_option","state_machine_too_large","invalid_state","unknown_initial_state","invalid_composite","final_has_outgoing","underbranched_choice","gantt_too_large","invalid_gantt_date","invalid_gantt_span","invalid_gantt_phase","invalid_gantt_progress","gantt_dependency_cycle","gantt_schedule_conflict","er_too_large","invalid_entity","invalid_field","unknown_relationship_field","invalid_relationship","class_too_large","invalid_class","invalid_member","invalid_generalization","org_chart_too_large","invalid_person","invalid_reporting_line","request_too_large","generic_label","label_too_long","quality_below_threshold","render_failed","text_overflow","arrow_binding_invalid","arrow_overlap","export_invalid_scene","storage_read_failed","storage_write_failed","unsupported_artifact_format","patch_source_unavailable","unknown_patch_target","unsupported_patch_operation","patch_preserve_connectivity_failed","patch_output_invalid","duplicate_element_id","duplicate_layer_id","invalid_canvas_binding","invalid_canvas_composition","invalid_canvas_geometry","invalid_polygon","canvas_limit_exceeded","invalid_z_order","unknown_layout_target","unknown_icon","invalid_canvas_icon","icon_dropped"],iH=Object.assign(iu(iV),{options:iV}),iq=iu(["request","diagram","node","edge","group","lane","element","layer","artifact"]),iF=iu(["input","canvas","flowchart","mindmap","quality","render","export","storage"]);class iI extends i.Xsx("CodeModeIssueRef")({kind:iq,id:id(ix),path:id(ix)},{identifier:void 0}){}class iE extends i.Xsx("CodeModeIssue")({code:iH,severity:iu(["error","warning"]),stage:iF,ref:id(iI),message:ib,hint:ib},{identifier:void 0}){}let iO=["start","process","decision","end"],iU=Object.assign(iu(iO),{options:iO}),iX=["setDefaultStyle","setStyle","setShape","translate","replaceText","rerouteEdges","insert","remove","replace","reorder","group","ungroup"];Object.assign(iu(iX),{options:iX});let iT=ip(ir().check(i.NYj(128,{message:"Too big: expected string to have <=128 characters"})));class iY extends i.Xsx("NodeIconSpec")({slug:iT},{identifier:void 0}){}class i$ extends i.Xsx("FlowchartSpecNode")({id:ib,label:ib,kind:iU,description:id(ix),icon:id(iY),group:id(ix),lane:id(ix),shape:id(iu(B))},{identifier:void 0}){}class iG extends i.Xsx("FlowchartSpecLane")({id:ib,label:ib},{identifier:void 0}){}class iD extends i.Xsx("FlowchartSpecGroup")({id:ib,label:ib,parent:id(ix),kind:id(iu(C))},{identifier:void 0}){}class iR extends i.Xsx("FlowchartSpecEdge")({id:id(ix),source:ib,target:ib,label:id(ix)},{identifier:void 0}){}let iZ=iu(["TB","LR"]),ij=iZ.annotate({default:"TB"}).pipe(i.E$i(o.PyW("TB")));class iN extends i.Xsx("FlowchartSpecLayout")({direction:ij},{identifier:void 0}){}let iW=y.accentColor,iJ=iz(iW).pipe(i.E$i(o.PyW(iW))),iK=y.backgroundColor,iQ=iz(iK).pipe(i.E$i(o.PyW(iK)));class i1 extends i.Xsx("FlowchartSpecStyle")({accentColor:iJ,backgroundColor:iQ},{identifier:void 0}){}let i0=[],i2=i.O31(iR).pipe(i.fXn).annotate({default:i0}).pipe(i.E$i(o.PyW(i0))),i3={direction:"TB"},i5=iN.annotate({default:i3}).pipe(i.E$i(o.PyW(i3)),i.usV({[it]:i3})),i4={accentColor:y.accentColor,backgroundColor:y.backgroundColor},i6=i1.annotate({default:i4}).pipe(i.E$i(o.PyW(i4)),i.usV({[it]:i4}));class i7 extends i.Xsx("FlowchartSpec")({id:id(ix),title:ib,nodes:ig(ic(i$)),edges:i2,groups:id(i.O31(iD).pipe(i.fXn)),lanes:id(i.O31(iG).pipe(i.fXn)),layout:i5,style:i6},{identifier:void 0}){}class i8 extends i.Xsx("SequenceParticipantSpec")({id:ib,label:ib,kind:id(ix),icon:id(iY)},{identifier:void 0}){}class i9 extends i.Xsx("SequenceMessageSpec")({id:id(ix),source:ib,target:ib,label:ib,type:id(iu(eq)),style:id(iu(eF))},{identifier:void 0}){}let le=[],lt=i.O31(i9).pipe(i.fXn).annotate({default:le}).pipe(i.E$i(o.PyW(le)));class la extends i.Xsx("SequenceDiagramSpec")({id:id(ix),title:ib,participants:ig(ic(i8)),messages:lt,style:i6},{identifier:void 0}){}class ls extends i.Xsx("TimelineEventSpec")({id:ib,label:ib,date:id(ix),end:id(ix),order:id(ik),kind:id(iu(K)),lane:id(ix),description:id(ix)},{identifier:void 0}){}class li extends i.Xsx("TimelineSpec")({id:id(ix),title:ib,events:ig(ic(ls)),lanes:id(i.O31(ix).pipe(i.fXn)),today:id(ix),style:i6},{identifier:void 0}){}class ll extends i.Xsx("ChartSeriesSpec")({name:id(ix),values:ig(i.O31(ik).pipe(i.fXn))},{identifier:void 0}){}class lo extends i.Xsx("ChartSpec")({id:id(ix),title:ib,kind:iu(T),categories:ig(ic(ix)),series:ig(ic(ll)),unit:id(ix),categoryAxisTitle:id(ix),valueAxisTitle:id(ix),stacked:id(i.v8c),donut:id(i.v8c),orientation:id(iu(Y)),style:i6},{identifier:void 0}){}class lr extends i.Xsx("StateMachineStateSpec")({id:ib,label:id(ix),kind:id(iu(eN)),parent:id(ix),initial:id(ix)},{identifier:void 0}){}class ln extends i.Xsx("StateMachineTransitionSpec")({id:id(ix),source:ib,target:ib,event:id(ix),guard:id(ix),action:id(ix)},{identifier:void 0}){}class lc extends i.Xsx("StateMachineSpecLayout")({direction:iu(eW)},{identifier:void 0}){}let ld=[],lp=i.O31(ln).pipe(i.fXn).annotate({default:ld}).pipe(i.E$i(o.PyW(ld)));class lh extends i.Xsx("StateMachineSpec")({id:id(ix),title:ib,initial:ib,states:ig(ic(lr)),transitions:lp,layout:id(lc),style:i6},{identifier:void 0}){}class lg extends i.Xsx("GanttTaskSpec")({id:ib,label:ib,start:ib,end:id(ix),duration:id(ik),milestone:id(i.v8c),phase:id(ix),dependsOn:id(i.O31(ix).pipe(i.fXn)),progress:id(ik)},{identifier:void 0}){}class lu extends i.Xsx("GanttSpec")({id:id(ix),title:ib,tasks:ig(ic(lg)),phases:id(i.O31(ix).pipe(i.fXn)),today:id(ix),style:i6},{identifier:void 0}){}class lf extends i.Xsx("ErFieldSpec")({name:ib,type:id(ix),pk:id(i.v8c),fk:id(i.v8c),unique:id(i.v8c),nullable:id(i.v8c)},{identifier:void 0}){}let lm=[];class lv extends i.Xsx("ErEntitySpec")({id:ib,name:id(ix),fields:i.O31(i.gPz([ix,lf])).pipe(i.fXn).annotate({default:lm}).pipe(i.E$i(o.PyW(lm)))},{identifier:void 0}){}class ly extends i.Xsx("ErRelationshipSpec")({id:id(ix),from:ib,to:ib,fromCardinality:iu(tf),toCardinality:iu(tf),label:id(ix)},{identifier:void 0}){}let lw=[],lx=i.O31(ly).pipe(i.fXn).annotate({default:lw}).pipe(i.E$i(o.PyW(lw)));class lb extends i.Xsx("ErSpec")({id:id(ix),title:ib,entities:ig(ic(lv)),relationships:lx,style:i6},{identifier:void 0}){}class lk extends i.Xsx("ClassAttributeSpec")({name:ib,type:id(ix),visibility:id(iu(tI)),static:id(i.v8c)},{identifier:void 0}){}class lM extends i.Xsx("ClassParameterSpec")({name:ib,type:id(ix)},{identifier:void 0}){}let lC=[];class lz extends i.Xsx("ClassMethodSpec")({name:ib,params:i.O31(i.gPz([ix,lM])).pipe(i.fXn).annotate({default:lC}).pipe(i.E$i(o.PyW(lC))),returns:id(ix),visibility:id(iu(tI)),static:id(i.v8c),abstract:id(i.v8c)},{identifier:void 0}){}let l_=[],lL=[];class lB extends i.Xsx("ClassNodeSpec")({id:ib,name:id(ix),kind:id(iu(tq)),stereotype:id(ix),attributes:i.O31(i.gPz([ix,lk])).pipe(i.fXn).annotate({default:l_}).pipe(i.E$i(o.PyW(l_))),methods:i.O31(i.gPz([ix,lz])).pipe(i.fXn).annotate({default:lL}).pipe(i.E$i(o.PyW(lL)))},{identifier:void 0}){}class lS extends i.Xsx("ClassRelationshipSpec")({id:id(ix),kind:iu(tU),from:ib,to:ib,fromMultiplicity:id(ix),toMultiplicity:id(ix),fromRole:id(ix),toRole:id(ix),navigable:id(i.v8c),label:id(ix)},{identifier:void 0}){}let lA=[],lP=i.O31(lS).pipe(i.fXn).annotate({default:lA}).pipe(i.E$i(o.PyW(lA)));class lV extends i.Xsx("ClassSpec")({id:id(ix),title:ib,classes:ig(ic(lB)),relationships:lP,style:i6},{identifier:void 0}){}class lH extends i.Xsx("OrgPersonSpec")({id:ib,name:ib,title:id(ix),department:id(ix),manager:id(ix),assistant:id(i.v8c),avatar:id(i.v8c)},{identifier:void 0}){}class lq extends i.Xsx("OrgDottedLineSpec")({id:id(ix),report:ib,manager:ib,label:id(ix)},{identifier:void 0}){}let lF=[],lI=i.O31(lq).pipe(i.fXn).annotate({default:lF}).pipe(i.E$i(o.PyW(lF)));class lE extends i.Xsx("OrgChartSpec")({id:id(ix),title:ib,people:ig(ic(lH)),dottedLines:lI,groupByDepartment:id(i.v8c),forest:id(i.v8c),style:i6},{identifier:void 0}){}let lO=id(ic(iS)),lU=id(i.O31(iA).pipe(i.fXn)),lX=id(i.wNn.check(i.MIs(),i.OWK(0,{message:"Too small: expected number to be >=0"}),i.biW(10,{message:"Too big: expected number to be <=10"})));class lT extends i.Xsx("BuildFlowchartOptions")({artifactFormats:lO,inlineArtifacts:lU,minQualityScore:lX},{identifier:void 0}){}id(lT);class lY extends i.Xsx("BuildFlowchartRequest")({requestId:id(ix),spec:ih(i7),options:id(lT)},{identifier:void 0}){}let l$=i7.mapFields(({id:e,title:t,nodes:a,edges:s,groups:i,lanes:l,layout:o})=>({id:e,title:t,nodes:a,edges:s,groups:i,lanes:l,layout:o})),lG=i._kM({requestId:id(ix),spec:ih(l$)}),lD=i.rcy(lG,{leafHook:s7,parseOptions:{errors:"all"}}),lR=Object.assign(lD,{"~standard":{...lD["~standard"],jsonSchema:{input:()=>io(lG),output:()=>io(lG)}}}),lZ=Object.assign(lY,{omit:e=>lR});class lj extends i.Xsx("BuildSequenceDiagramRequest")({requestId:id(ix),spec:ih(la),options:id(lT)},{identifier:void 0}){}i._kM({requestId:id(ix),spec:ih(la.mapFields(({id:e,title:t,participants:a,messages:s})=>({id:e,title:t,participants:a,messages:s})))});class lN extends i.Xsx("BuildTimelineRequest")({requestId:id(ix),spec:ih(li),options:id(lT)},{identifier:void 0}){}i._kM({requestId:id(ix),spec:ih(li.mapFields(({id:e,title:t,events:a,lanes:s,today:i})=>({id:e,title:t,events:a,lanes:s,today:i})))});class lW extends i.Xsx("BuildChartRequest")({requestId:id(ix),spec:ih(lo),options:id(lT)},{identifier:void 0}){}let lJ=lo.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(lJ)});class lK extends i.Xsx("BuildStateMachineRequest")({requestId:id(ix),spec:ih(lh),options:id(lT)},{identifier:void 0}){}i._kM({requestId:id(ix),spec:ih(lh.mapFields(({id:e,title:t,initial:a,states:s,transitions:i,layout:l})=>({id:e,title:t,initial:a,states:s,transitions:i,layout:l})))});class lQ extends i.Xsx("BuildGanttRequest")({requestId:id(ix),spec:ih(lu),options:id(lT)},{identifier:void 0}){}let l1=lu.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(l1)});class l0 extends i.Xsx("BuildErDiagramRequest")({requestId:id(ix),spec:ih(lb),options:id(lT)},{identifier:void 0}){}let l2=lb.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(l2)});class l3 extends i.Xsx("BuildClassDiagramRequest")({requestId:id(ix),spec:ih(lV),options:id(lT)},{identifier:void 0}){}let l5=lV.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(l5)});class l4 extends i.Xsx("BuildOrgChartRequest")({requestId:id(ix),spec:ih(lE),options:id(lT)},{identifier:void 0}){}let l6=lE.mapFields(({style:e,...t})=>t);i._kM({requestId:id(ix),spec:ih(l6)});let l7=i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"}),i.HNH(function(e){let t=s5(e);return t.length>0&&!/^(?:""|''|``)$/.test(t)},{message:"Must contain semantic text after normalization."})),l8=ih(i.DYE(()=>l9).annotate({identifier:"__schema0"})),l9=i._kM({label:ip(l7),children:i.Qrq(i.O31(l8).pipe(i.fXn))});class oe extends i.Xsx("MindmapSpecLayout")({direction:iu(["LR","RL"]).annotate({default:"LR"}).pipe(i.E$i(o.PyW("LR")))},{identifier:void 0}){}let ot={direction:"LR"},oa=oe.annotate({default:ot}).pipe(i.E$i(o.PyW(ot)),i.usV({[it]:ot})),os=i._kM({id:id(ix),title:ip(l7),root:l8,layout:oa,style:i6});class oi extends i.Xsx("MindmapSpec")(os,{identifier:void 0}){}let ol=i._kM({requestId:id(ix),spec:ih(os),options:id(lT)});i.Xsx("BuildMindmapRequest")(ol,{identifier:void 0});class oo extends i.Xsx("ScenePoint")({x:ik.pipe(i.Wa3),y:ik.pipe(i.Wa3)},{identifier:void 0}){}let or={frameId:id(ix).pipe(i.Wa3),groupIds:id(i.O31(ix).pipe(i.fXn).annotate({maxItems:aU.maxGroupsPerElement})).pipe(i.Wa3),layerId:id(ix).pipe(i.Wa3),locked:id(i.v8c).pipe(i.Wa3),opacity:id(i.wNn.check(i.MIs(),i.Bt9({minimum:0,maximum:100}))).pipe(i.Wa3),zIndex:id(i.Aiz).pipe(i.Wa3)},on={fillColor:id(i_).pipe(i.Wa3),fillStyle:id(iu(["cross-hatch","hachure","solid"])).pipe(i.Wa3),roughness:id(iu([0,1,2])).pipe(i.Wa3),strokeColor:id(i_).pipe(i.Wa3),strokeStyle:id(iu(["dashed","dotted","solid"])).pipe(i.Wa3),strokeWidth:id(iu([1,2,4])).pipe(i.Wa3)},oc=i.T9y(iu(["arrow","bar","circle","diamond","triangle","crowfoot_one","crowfoot_many","crowfoot_one_or_many","triangle_outline","diamond_outline"])),od=i.O31(oo).pipe(i.fXn).check(i.tJb(2,{message:"Too small: expected array to have >=2 items"}),i.NYj(aU.maxPointsPerElement,{message:`Too big: expected array to have <=${aU.maxPointsPerElement} items`}));class op extends i.Xsx("CanvasNodeIcon")({slug:iT.pipe(i.Wa3),size:i.wNn.check(i.MIs(),i.Bt9({minimum:aX.minSize,maximum:aX.maxSize},{message:`Expected a number between ${aX.minSize} and ${aX.maxSize}`})).pipe(i.Wa3)},{identifier:void 0}){}class oh extends i.Xsx("CanvasIconAsset")({name:i.QfV,svg:i.QfV},{identifier:void 0}){}class og extends i.Xsx("NodeSceneElement")({...or,...on,type:im("node"),id:ib,nodeId:ib,kind:id(ix),icon:id(op).pipe(i.Wa3),rendererRole:id(iu(aJ)),shape:iu(["rectangle","ellipse","diamond","circle","polygon",...aT]).pipe(i.Wa3),points:id(od).pipe(i.Wa3),textColor:id(i_).pipe(i.Wa3),x:ik.pipe(i.Wa3),y:ik.pipe(i.Wa3),width:iM.pipe(i.Wa3),height:iM.pipe(i.Wa3),label:ib.pipe(i.Wa3)},{identifier:void 0}){}class ou extends i.Xsx("TextSceneElement")({...or,type:im("text"),id:ib,containerId:id(ix),textColor:id(i_).pipe(i.Wa3),x:ik.pipe(i.Wa3),y:ik.pipe(i.Wa3),text:ib.pipe(i.Wa3),fontSize:iM,fontFamily:id(iu(["hand","mono","sans"])),lineHeight:id(iM),maxWidth:id(iM),textAlign:id(iu(["center","left","right"])),verticalAlign:id(iu(["bottom","middle","top"]))},{identifier:void 0}){}class of extends i.Xsx("ArrowSceneElement")({...or,...on,type:im("arrow"),id:ib,edgeId:ib,sourceNodeId:ib,targetNodeId:ib.pipe(i.Wa3),startArrowhead:id(oc).pipe(i.Wa3),endArrowhead:id(oc).pipe(i.Wa3),textColor:id(i_).pipe(i.Wa3),points:ig(od).pipe(i.Wa3),curved:id(i.v8c).pipe(i.Wa3),label:id(ix).pipe(i.Wa3)},{identifier:void 0}){}class om extends i.Xsx("CanvasLineBinding")({elementId:ib,focus:id(ik),gap:id(ik)},{identifier:void 0}){}class ov extends i.Xsx("LineSceneElement")({...or,...on,type:im("line"),id:ib,points:ig(od).pipe(i.Wa3),startBinding:id(om).pipe(i.Wa3),endBinding:id(om).pipe(i.Wa3),startArrowhead:id(oc).pipe(i.Wa3),endArrowhead:id(oc).pipe(i.Wa3),label:id(ix).pipe(i.Wa3),textColor:id(i_).pipe(i.Wa3)},{identifier:void 0}){}class oy extends i.Xsx("FrameSceneElement")({...or,...on,type:im("frame"),id:ib,nodeId:id(ix),name:id(ix).pipe(i.Wa3),x:ik.pipe(i.Wa3),y:ik.pipe(i.Wa3),width:iM.pipe(i.Wa3),height:iM.pipe(i.Wa3)},{identifier:void 0}){}class ow extends i.Xsx("CanvasLayer")({id:ib,name:id(ix),locked:id(i.v8c),visible:id(i.v8c)},{identifier:void 0}){}let ox=ig(ic(ix));class ob extends i.Xsx("CanvasFlowLayout")({type:iu(["row","column","stack"]),ids:ox,x:id(ik),y:id(ik),gap:id(ik)},{identifier:void 0}){}class ok extends i.Xsx("CanvasGridLayout")({type:im("grid"),ids:ox,columns:i.Aiz.check(i.OWK(1,{message:"Too small: expected number to be >=1"})),x:id(ik),y:id(ik),columnGap:id(ik),rowGap:id(ik)},{identifier:void 0}){}class oM extends i.Xsx("CanvasAlignLayout")({type:im("align"),ids:ox,axis:iu(["x","y"]),alignment:iu(["center","end","start"])},{identifier:void 0}){}class oC extends i.Xsx("CanvasDistributeLayout")({type:im("distribute"),ids:ox,axis:iu(["x","y"]),gap:id(ik)},{identifier:void 0}){}let oz=i.gPz([og,ou,of,ov,oy],{mode:"oneOf"}).annotate({[ia]:!0}),o_=i.gPz([ob,ok,oM,oC],{mode:"oneOf"}),oL=i.O31(ow).pipe(i.fXn).annotate({default:[],maxItems:aU.maxLayers}).pipe(i.E$i(o.PyW([]))),oB=i.O31(o_).pipe(i.fXn).annotate({default:[],maxItems:aU.maxLayouts}).pipe(i.E$i(o.PyW([]))),oS=i.O31(ix).pipe(i.fXn).annotate({default:[],maxItems:aU.maxZOrderEntries}).pipe(i.E$i(o.PyW([])));class oA extends i.Xsx("CanvasSpec")({kind:im("canvas"),version:iv(1),diagramId:ib,title:ib,width:iM.pipe(i.Wa3),height:iM.pipe(i.Wa3),accentColor:i_.pipe(i.Wa3),backgroundColor:i_.pipe(i.Wa3),elements:ig(i.O31(oz).pipe(i.fXn).annotate({maxItems:aU.maxElements})),icons:id(i.mSG(i.QfV,oh)).pipe(i.Wa3),layers:oL,layouts:oB,zOrder:oS},{identifier:void 0}){}let oP=oA;class oV extends i.Xsx("CreateCanvasRequest")({requestId:id(ix),spec:ih(oA),options:id(lT)},{identifier:void 0}){}let oH=i.mSG(i.QfV,i.$r1).check(i.HNH(e=>"string"==typeof e.id&&e.id.length>0&&"string"==typeof e.type&&e.type.length>0,{message:"Invalid input"}));class oq extends i.Xsx("ExcalidrawScene")({appState:i.mSG(i.QfV,i.$r1),elements:i.O31(oH).pipe(i.fXn)},{identifier:void 0}){}class oF extends oq.extend("ExcalidrawFile")({files:i.mSG(i.QfV,i.$r1),source:ib,type:im("excalidraw"),version:iv(2)},{identifier:void 0}){}let oI=oF;class oE extends i.Xsx("GetArtifactRequest")({artifactId:ib,format:id(iS),inline:id(i.v8c)},{identifier:void 0}){}class oO extends i.Xsx("DiagramSelector")({ids:id(i.O31(ix).pipe(i.fXn)),nodeIds:id(i.O31(ix).pipe(i.fXn)),edgeIds:id(i.O31(ix).pipe(i.fXn)),kinds:id(i.O31(iU).pipe(i.fXn)),labels:id(i.O31(ix).pipe(i.fXn)),scope:id(iu(["all","nodes","edges"]))},{identifier:void 0}){}class oU extends i.Xsx("DiagramStylePatch")({strokeColor:id(i_),fillColor:id(i_),textColor:id(i_),backgroundColor:id(i_)},{identifier:void 0}){}let oX=["rectangle","diamond","ellipse","circle","polygon"],oT=Object.assign(iu(oX),{options:oX});class oY extends i.Xsx("SetDefaultStyleOperation")({op:im("setDefaultStyle"),style:ih(oU)},{identifier:void 0}){}class o$ extends i.Xsx("SetStyleOperation")({op:im("setStyle"),selector:ih(oO),style:ih(oU)},{identifier:void 0}){}class oG extends i.Xsx("SetShapeOperation")({op:im("setShape"),selector:ih(oO),shape:oT},{identifier:void 0}){}class oD extends i.Xsx("TranslateOperation")({op:im("translate"),selector:ih(oO),dx:ik,dy:ik},{identifier:void 0}){}class oR extends i.Xsx("ReplaceTextOperation")({op:im("replaceText"),selector:ih(oO),text:ib},{identifier:void 0}){}class oZ extends i.Xsx("RerouteEdgesOperation")({op:im("rerouteEdges"),selector:id(oO)},{identifier:void 0}){}let oj=ig(ic(ix));class oN extends i.Xsx("InsertElementsOperation")({op:im("insert"),elements:ig(ic(oz)),beforeId:id(ix),afterId:id(ix)},{identifier:void 0}){}class oW extends i.Xsx("RemoveElementsOperation")({op:im("remove"),selector:ih(oO)},{identifier:void 0}){}class oJ extends i.Xsx("ReplaceElementOperation")({op:im("replace"),id:ib,element:ih(oz)},{identifier:void 0}){}class oK extends i.Xsx("ReorderElementsOperation")({op:im("reorder"),ids:oj,beforeId:id(ix),afterId:id(ix)},{identifier:void 0}){}class oQ extends i.Xsx("GroupElementsOperation")({op:im("group"),ids:oj,groupId:ib},{identifier:void 0}){}class o1 extends i.Xsx("UngroupElementsOperation")({op:im("ungroup"),ids:oj,groupId:id(ix)},{identifier:void 0}){}let o0=i.gPz([oY,o$,oG,oD,oR,oZ,oN,oW,oJ,oK,oQ,o1],{mode:"oneOf"}).annotate({[ia]:!0,[is]:"op",message:`Invalid discriminator value. Expected ${iX.map(e=>`'${e}'`).join(" | ")}`});class o2 extends i.Xsx("ArtifactPatchSource")({artifactId:ib,format:id(im("scene"))},{identifier:void 0}){}class o3 extends i.Xsx("InlineScenePatchSource")({scene:ih(oA)},{identifier:void 0}){}let o5=i.gPz([o2,o3]).annotate({message:"Invalid input"});class o4 extends i.Xsx("ApplyDiagramPatchOptions")({artifactFormats:lO,inlineArtifacts:lU,preserveConnectivity:id(i.v8c)},{identifier:void 0}){}id(o4);class o6 extends i.Xsx("ApplyDiagramPatchRequest")({requestId:id(ix),source:o5.annotateKey({messageMissingKey:"Invalid input"}),operations:ig(ic(o0)),options:id(o4),intent:id(ix)},{identifier:void 0}){}class o7 extends i.Xsx("NormalizedMindmapTopic")({id:ix,label:ix,children:i.O31(i.DYE(()=>o7)).pipe(i.fXn)},{identifier:void 0}){}let o8=i._kM({id:ix,title:ix,nodes:i.O31(i$).pipe(i.fXn),edges:i.O31(iR.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),groups:i.Qrq(i.O31(iD).pipe(i.fXn)),lanes:i.Qrq(i.O31(iG).pipe(i.fXn)),layout:i._kM({direction:iZ}),style:i._kM({accentColor:i_,backgroundColor:i_})}),o9=i._kM({id:ix,title:ix,root:o7,layout:i._kM({direction:iu(["LR","RL"])}),style:i._kM({accentColor:i_,backgroundColor:i_})}),re=i._kM({id:ix,title:ix,participants:i.O31(i8).pipe(i.fXn),messages:i.O31(i9.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),style:i._kM({accentColor:i_,backgroundColor:i_})}),rt=i._kM({id:ix,title:ix,events:i.O31(ls).pipe(i.fXn),lanes:id(i.O31(ix).pipe(i.fXn)),today:id(ix),style:i._kM({accentColor:i_,backgroundColor:i_})}),ra=i._kM({id:ix,title:ix,initial:ix,states:i.O31(lr).pipe(i.fXn),transitions:i.O31(ln.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),layout:id(lc),style:i._kM({accentColor:i_,backgroundColor:i_})}),rs=lu.mapFields(e=>({...e,id:ix,title:ix,style:i._kM({accentColor:i_,backgroundColor:i_})})),ri=i._kM({id:ix,title:ix,entities:i.O31(i._kM({id:ix,name:id(ix),fields:i.O31(lf).pipe(i.fXn)})).pipe(i.fXn),relationships:i.O31(ly.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),style:i._kM({accentColor:i_,backgroundColor:i_})}),rl=i._kM({id:ix,title:ix,classes:i.O31(i._kM({id:ix,name:id(ix),kind:id(iu(tq)),stereotype:id(ix),attributes:i.O31(lk).pipe(i.fXn),methods:i.O31(lz.mapFields(e=>({...e,params:i.O31(lM).pipe(i.fXn)}))).pipe(i.fXn)})).pipe(i.fXn),relationships:i.O31(lS.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),style:i._kM({accentColor:i_,backgroundColor:i_})}),ro=i._kM({id:ix,title:ix,people:i.O31(lH).pipe(i.fXn),dottedLines:i.O31(lq.mapFields(e=>({...e,id:ix}))).pipe(i.fXn),groupByDepartment:id(i.v8c),forest:id(i.v8c),style:i._kM({accentColor:i_,backgroundColor:i_})}),rr=lo.mapFields(e=>({...e,id:ix,title:ix,style:i._kM({accentColor:i_,backgroundColor:i_})})),rn=i._kM({code:i.QfV,passed:i.v8c,severity:iu(["error","warning"]),message:i.QfV,refs:i.O31(iI).pipe(i.fXn)}),rc=i._kM({accepted:i.v8c,score:i.wNn,threshold:i.wNn,summary:i._kM({nodeCount:i.wNn,edgeCount:i.wNn}),checks:i.O31(rn).pipe(i.fXn)}),rd=i._kM({format:iS,mimeType:i.QfV,url:id(i.QfV),expiresAt:id(i.QfV),inline:id(i.$r1),sizeBytes:id(i.wNn)}),rp=i._kM({artifactId:i.QfV,diagramId:i.QfV,formats:i.O31(rd).pipe(i.fXn),provenance:id(iP)}),rh=i._kM({artifactId:id(i.QfV),diagramId:id(i.QfV),formats:id(i.O31(rd).pipe(i.fXn))});class rg extends i.Xsx("BuildFlowchartAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:o8,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class ru extends i.Xsx("BuildFlowchartRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_flowchart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(o8),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rg,ru]);class rf extends i.Xsx("BuildMindmapAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:o9,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rm extends i.Xsx("BuildMindmapRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_mindmap","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(o9),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rf,rm]);class rv extends i.Xsx("BuildSequenceDiagramAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:re,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class ry extends i.Xsx("BuildSequenceDiagramRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_sequence","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(re),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rv,ry]);class rw extends i.Xsx("BuildTimelineAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:rt,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rx extends i.Xsx("BuildTimelineRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_timeline","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(rt),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rw,rx]);class rb extends i.Xsx("BuildChartAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:rr,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rk extends i.Xsx("BuildChartRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_chart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(rr),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rb,rk]);class rM extends i.Xsx("BuildStateMachineAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:ra,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rC extends i.Xsx("BuildStateMachineRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_state_machine","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(ra),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rM,rC]);class rz extends i.Xsx("BuildGanttAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:rs,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class r_ extends i.Xsx("BuildGanttRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_gantt","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(rs),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rz,r_]);class rL extends i.Xsx("BuildErDiagramAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:ri,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rB extends i.Xsx("BuildErDiagramRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_er_diagram","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(ri),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rL,rB]);class rS extends i.Xsx("BuildClassDiagramAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:rl,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rA extends i.Xsx("BuildClassDiagramRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_class_diagram","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(rl),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rS,rA]);class rP extends i.Xsx("BuildOrgChartAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:ro,quality:rc,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rV extends i.Xsx("BuildOrgChartRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_org_chart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(ro),quality:id(rc),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rP,rV]);class rH extends i.Xsx("GetArtifactAccepted")({ok:iy(!0),artifactId:i.QfV,diagramId:i.QfV,format:iS,mimeType:i.QfV,url:id(i.QfV),expiresAt:id(i.QfV),inline:id(i.$r1),sizeBytes:id(i.wNn),provenance:id(iP)},{identifier:void 0}){}class rq extends i.Xsx("GetArtifactRejected")({ok:iy(!1),status:iu(["invalid_input","not_found","format_unavailable","expired","storage_failed"]),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rH,rq]);class rF extends i.Xsx("ApplyDiagramPatchAccepted")({ok:iy(!0),status:im("accepted"),patchId:i.QfV,requestId:id(i.QfV),sourceArtifactId:id(i.QfV),artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rI extends i.Xsx("ApplyDiagramPatchRejected")({ok:iy(!1),status:iu(["invalid_input","source_unavailable","target_not_found","unsupported_operation","connectivity_changed","render_failed","export_failed","storage_failed"]),patchId:id(i.QfV),requestId:id(i.QfV),sourceArtifactId:id(i.QfV),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rF,rI]);class rE extends i.Xsx("CreateCanvasAccepted")({ok:iy(!0),status:im("accepted"),buildId:i.QfV,requestId:id(i.QfV),normalizedSpec:oA,artifact:rp,issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rO extends i.Xsx("CreateCanvasRejected")({ok:iy(!1),status:iu(["invalid_input","invalid_canvas","limit_exceeded","render_failed","export_failed","storage_failed"]),buildId:id(i.QfV),requestId:id(i.QfV),normalizedSpec:id(oA),partial:id(rh),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}let rU=i.gPz([rE,rO]),rX=120,rT=1,rY=25;class r$ extends i.Xsx("SearchIconsRequest")({q:ip(ir().check(i.NYj(rX,{message:`Too big: expected string to have <=${rX} characters`}))),limit:id(i.Aiz.check(i.Bt9({minimum:rT,maximum:rY},{message:`Expected an integer between ${rT} and ${rY}`})))},{identifier:void 0}){}class rG extends i.Xsx("SearchIconsMatch")({slug:i.QfV,name:i.QfV,collection:i.QfV,match:iu(["exact","vendor","weak"])},{identifier:void 0}){}class rD extends i.Xsx("SearchIconsAccepted")({ok:iy(!0),status:im("accepted"),query:i.QfV,icons:i.O31(rG).pipe(i.fXn),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}class rR extends i.Xsx("SearchIconsRejected")({ok:iy(!1),status:iu(["invalid_input"]),issues:i.O31(iE).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rD,rR]);let rZ=i.xCb(["read","readManifest","write"]);class rj extends i.rNF()("CodeModeArtifactStorageError",{cause:i.kld(),message:i.QfV,operation:rZ}){}class rN extends l.kl()("@sketchi/diagram-agent/CodeModeArtifactStorage"){}let rW={excalidraw:"application/vnd.excalidraw+json",png:"image/png",scene:"application/vnd.sketchi.scene+json"};function rJ(e){return"excalidraw"===e||"scene"===e}function rK(e){return{format:e.format,mimeType:e.mimeType,sizeBytes:e.sizeBytes}}function rQ(e){return new TextEncoder().encode(JSON.stringify(e)).length}let r1=n.QZ(rN)(o.Q56(o.OH5(function(){let e=new Map,t=new Map;return{close:o.OH5(()=>{t.clear(),e.clear()}),storage:{read:o.fn("codeMode.artifacts.memory.read")(function*(e,a){return yield*o.OH5(()=>{let s=t.get(`${e}:${a}`);return s?{...s,data:structuredClone(s.data)}:null})}),readManifest:o.fn("codeMode.artifacts.memory.readManifest")(function*(t){return yield*o.OH5(()=>{let a=e.get(t);return a?structuredClone(a):null})}),write:o.fn("codeMode.artifacts.memory.write")(function*(a){var s;let i=yield*r.Ru;return yield*o.SvU({try:()=>{var s;let l=a.formats.map(rK),o=a.provenance?structuredClone(a.provenance):void 0,r={artifactId:a.artifactId,diagramId:a.diagramId,formats:l,...o?{provenance:o}:{},createdAt:new Date(i).toISOString()};for(let s of(e.set(a.artifactId,r),a.formats))t.set(`${a.artifactId}:${s.format}`,{...s,data:structuredClone(s.data)});let n=a.formats.map(e=>{var t;return t=a.inlineFormats,{format:e.format,mimeType:e.mimeType,...rJ(e.format)&&t.includes(e.format)?{inline:e.data}:{},sizeBytes:e.sizeBytes}});return{artifactId:(s={artifactId:a.artifactId,diagramId:a.diagramId,formats:n,...a.provenance?{provenance:structuredClone(a.provenance)}:{}}).artifactId,diagramId:s.diagramId,formats:s.formats,...s.provenance?{provenance:s.provenance}:{}}},catch:(s="write",e=>{var t;return rj.make({cause:e,message:(t="Artifact storage failed.",e instanceof Error?e.message:t),operation:s})})})})}}}),e=>e.close).pipe(o.TjK(e=>e.storage)));function r0(e,t="storage_write_failed"){return{code:t,severity:"error",stage:"storage",message:e,hint:"Retry the request; if it keeps failing, inspect the artifact store binding."}}let r2="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",r3=r2.slice(10),r5=new Map;function r4(e){let t=r5.get(e);if(void 0===t){t=new Uint8Array(256);for(let a=0;a<e.length;a++)t[e.charCodeAt(a)]=a;r5.set(e,t)}return t}function r6(e,t,a,s){let i=a[0];if(null!=t&&e>=t)throw Error(e+" >= "+t);if(e.slice(-1)===i||t&&t.slice(-1)===i)throw Error("trailing zero");if(t){let l=0;for(;(e[l]||i)===t[l];)l++;if(l>0)return t.slice(0,l)+r6(e.slice(l),t.slice(l),a,s)}let l=e?s[e.charCodeAt(0)]:0,o=null!=t?s[t.charCodeAt(0)]:a.length;return o-l>1?a[Math.round(.5*(l+o))]:t&&t.length>1?t.slice(0,1):a[l]+r6(e.slice(1),null,a,s)}function r7(e,t,a){if(e.length!==r8(e[0],t,a))throw Error("invalid integer part of order key: "+e)}function r8(e,t,a){let s=a[e.charCodeAt(0)];if(t[s]===e){let e=t.length/2;return s<e?e-s+1:s-e+2}throw Error("invalid order key head: "+e)}function r9(e,t,a){let s=r8(e[0],t,a);if(s>e.length)throw Error("invalid order key: "+e);return e.slice(0,s)}function ne(e,t,a,s){if(ns(e,t,a))throw Error("invalid order key: "+e);let i=r9(e,a,s);if(e.slice(i.length).slice(-1)===t[0])throw Error("invalid order key: "+e)}function nt(e,t,a,s,i){r7(e,s,i);let l=e[0],o=t[0],r="";for(let s=e.length-1;s>=1;s--){let i=a[e.charCodeAt(s)]+1;if(i!==t.length)return l+e.slice(1,s)+t[i]+r;r=o+r}let n=i[l.charCodeAt(0)];if(n===s.length-1)return null;let c=s[n+1],d=r8(c,s,i)-r8(l,s,i);return c+(d>0?r+o:d<0?r.slice(1):r)}let na=new Map;function ns(e,t,a){let s=na.get(a);void 0===s&&(s=new Map,na.set(a,s));let i=t.charCodeAt(0),l=s.get(i);return void 0===l&&(l=a[0]+t[0].repeat(a.length/2),s.set(i,l)),e===l}function ni(e){for(let t=1;t<e.length;t++)if(e.charCodeAt(t-1)>=e.charCodeAt(t))return!1;return!0}function nl(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}let no=new Set,nr=new Set,nn=new Set(["rectangle","ellipse","diamond"]),nc=v.ink;function nd(e){return"number"==typeof e&&Number.isFinite(e)?e:null}function np(e){if(!Array.isArray(e)||e.length<2)return null;let t=nd(e[0]),a=nd(e[1]);return null===t||null===a?null:[t,a]}function nh(e){let t=nd(e.x),a=nd(e.y),s=nd(e.width),i=nd(e.height);return null===t||null===a||null===s||null===i?null:{x:t,y:a,width:s,height:i}}function ng(e){return 1e-4>Math.abs(e-.5)?.5001:e}function nu(e,t){let a=nh(e);return a&&0!==a.width&&0!==a.height?[ng((t.x-a.x)/a.width),ng((t.y-a.y)/a.height)]:null}function nf(e,t){return{elementId:e?.id??"",focus:0,gap:0,fixedPoint:e?nu(e,t):null}}function nm(e,t){let a=sy(e,"seed");return{id:e,angle:0,fillStyle:t&&"fillStyle"in t?t.fillStyle??"solid":"solid",frameId:t?.frameId??null,groupIds:[...t?.groupIds??[]],index:null,isDeleted:!1,link:null,locked:t?.locked??!1,opacity:t?.opacity??100,roughness:t&&"roughness"in t?t.roughness??1:1,seed:a,strokeStyle:t&&"strokeStyle"in t?t.strokeStyle??"solid":"solid",strokeWidth:t&&"strokeWidth"in t?t.strokeWidth??2:2,updated:1,version:1,versionNonce:a+1}}function nv(e){var t;let a,s=e.wrap?aO(e.text,e.maxWidth,e.fontSize):e.text,i=e.wrap?aI(s,e.fontSize,e.maxWidth):aF(s,e.fontSize,e.maxWidth),l=e.element?.lineHeight??1.35,o=function(e,t,a=1.35){return Math.ceil(e.split("\n").length*t*a)}(s,e.fontSize,l),r=e.element?.verticalAlign;return{...nm(e.id,e.element),...void 0===e.locked?{}:{locked:e.locked},type:"text",x:e.x-i/2,y:e.container&&("bottom"===r||"top"===r)?(t=e.container,a=t.y+a5(t).y,"top"===r?a:a+a4(t).height-o):e.y-o/2,width:i,height:o,backgroundColor:"transparent",boundElements:null,containerId:e.containerId??null,fontFamily:e.element?.fontFamily==="mono"?3:e.element?.fontFamily==="sans"?2:5,fontSize:e.fontSize,lineHeight:l,originalText:e.text,roundness:null,strokeColor:e.textColor??nc,text:s,textAlign:e.element?.textAlign??"center",verticalAlign:e.element?.verticalAlign??"middle",autoResize:!(e.wrap&&!e.containerId)}}function ny(e){return aY(e.shape)?`${e.id}:shape`:`${e.id}:logo`}function nw(e){return e.points[e.points.length-1]??e.points[0]}function nx(e,t,a){if(!e)return null;let s=t.get(e.elementId);return s?{elementId:e.elementId,focus:e.focus??0,gap:e.gap??0,fixedPoint:nu(s,a)}:null}function nb(e){return"node"===e.type}function nk(e){return"text"===e.type}function nM(e){return"arrow"===e.type}function nC(e){return"line"===e.type}function nz(e){return"frame"===e.type}function n_(e,t){let a=e[t];if(!(a&&"object"==typeof a))return null;let s=a.elementId;return"string"==typeof s?s:null}function nL(e){let t=nd(e.x)??0,a=nd(e.y)??0,s=n_(e,"startBinding"),i=n_(e,"endBinding"),l=Array.isArray(e.points)?e.points.map(np).filter(e=>null!==e).map(([e,s])=>({x:t+e,y:a+s})):[];return sp(l).map(t=>({...t,arrowId:e.id,startBindingId:s,endBindingId:i,startCoordinate:"horizontal"===t.orientation?l[t.segmentIndex].x:l[t.segmentIndex].y,endCoordinate:"horizontal"===t.orientation?l[t.segmentIndex+1].x:l[t.segmentIndex+1].y,route:l}))}function nB(e){if(nn.has(e.type)||"frame"===e.type)return!0;let t=e.customData;return"line"===e.type&&null!==t&&"object"==typeof t&&"polygon"===t.sketchiShape}function nS(e,t,a){return e>=t-.01&&e<=a+.01}function nA(e,t){return .01>=Math.abs(e-t)}let nP=[1,2,5];function nV(e){return Math.max(0,-Math.floor(Math.log10(e)+1e-9))}function nH(e,t){let a=Number(e.toFixed(t));return Object.is(a,-0)?0:a}function nq(e,t,a=5,s=8){let i,l=Math.min(e,t),o=Math.max(e,t);l===o&&(0===l?o=1:l>0?l=0:o=0);let r=Math.floor(Math.log10((o-l)/Math.max(1,a)));for(let e=r-1;e<=r+1;e+=1)for(let t of nP){let r=t*10**e,n=nV(r),c=nH(Math.floor(l/r+1e-9)*r,n),d=nH(Math.ceil(o/r-1e-9)*r,n),p=Math.round((d-c)/r);if(p<1||p>s)continue;let h=Math.abs(p-a),g=i?Math.abs(i.intervals-a):1/0;(h<g||h===g&&i&&r>i.step)&&(i={step:r,min:c,max:d,intervals:p})}if(!i)throw Error(`No tick step covers ${l}..${o}.`);let n=nV(i.step),c=Array.from({length:i.intervals+1},(e,t)=>nH(i.min+t*i.step,n));return{min:i.min,max:i.max,step:i.step,ticks:c,decimals:n}}function nF(e,t,a){let s=t?nH(e.min-e.step,e.decimals):e.min,i=a?nH(e.max+e.step,e.decimals):e.max,l=Math.round((i-s)/e.step);return{...e,min:s,max:i,ticks:Array.from({length:l+1},(t,a)=>nH(s+a*e.step,e.decimals))}}function nI(e,t){let a=Math.min(...e),s=Math.max(...e);if(t||a<=0!=s<=0)return{low:Math.min(0,a),high:Math.max(0,s)};let i=Math.max(Math.abs(a),Math.abs(s));return s-a>i/6?{low:Math.min(0,a),high:Math.max(0,s)}:{low:a,high:s}}let nE=/^[$€£¥₹₩₽₺₪₦฿]+/u,nO=/^(?:[%‰°]|(?:[kKMBT]|bn|MM|x)(?!\p{L}))/u;function nU(e){if(!e)return{prefix:"",suffix:""};let t=nE.exec(e)?.[0]??"",a=e.slice(t.length);return t?{prefix:t,suffix:a}:{prefix:"",suffix:nO.test(a)?a:` ${a}`}}function nX(e){let[t="",a="0"]=Math.abs(e).toString().split("e");return Math.max(0,(t.split(".")[1]?.length??0)-Number(a))}let nT=new Map;function nY(e,t){let a=nT.get(t);return a||(a=new Intl.NumberFormat("en-US",{minimumFractionDigits:t,maximumFractionDigits:t}),nT.set(t,a)),a.format(e)}let n$=[{size:1e12,letter:"T"},{size:1e9,letter:"B"},{size:1e6,letter:"M"},{size:1e3,letter:"k"}];function nG(e,t,a){return`${t?"-":""}${a.prefix}${e}${a.suffix}`}function nD(e){return!/^(?:[kKMBT]|bn|MM)/u.test(e.suffix)}function nR(e,t,a=nX(e)){let s=e<0,i=Math.abs(e);if(i>=1e6&&0===a&&nD(t)){let e=n$.find(e=>i>=e.size),a=Number((i/e.size).toPrecision(12));if(Number(a.toPrecision(3))===a)return nG(`${nY(a,nX(a))}${e.letter}`,s,t)}return i>0&&a>6?nG(i.toExponential(),s,t):nG(nY(i,a),s,t)}let nZ=e=>Math.round(100*e)/100;function nj(e,t,a,s=2){let i=new Map;for(let l of e){if("line"!==l.type||!a(l.id)||2!==l.points.length)continue;let[e,o]=l.points,r=.01>Math.abs(e.y-o.y);if(!r&&Math.abs(e.x-o.x)>=.01)continue;let n=r?e.y:e.x,c=r?Math.min(e.x,o.x):Math.min(e.y,o.y),d=r?Math.max(e.x,o.x):Math.max(e.y,o.y),p=t.filter(e=>r?e.top-s<n&&n<e.bottom+s:e.left-s<n&&n<e.right+s).map(e=>r?[e.left-s,e.right+s]:[e.top-s,e.bottom+s]).filter(([e,t])=>t>c&&e<d).toSorted((e,t)=>e[0]-t[0]);if(!p.length)continue;let h=[],g=c;for(let[e,t]of p)e>g&&h.push([g,Math.min(e,d)]),g=Math.max(g,t);g<d&&h.push([g,d]),i.set(l.id,h.filter(([e,t])=>t-e>=1).map(([e,t],a)=>({...l,id:0===a?l.id:`${l.id}:${a}`,points:r?[{x:nZ(e),y:n},{x:nZ(t),y:n}]:[{x:n,y:nZ(e)},{x:n,y:nZ(t)}]})))}return i}let nN="chart-mark",nW=["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#6250d6","#e34948"],nJ=v.ink,nK="#4c4639",nQ="#e6dfd2",n1="#8c826f",n0=3*Math.PI/180,n2=20*Math.PI/180;function n3(e,t){return{text:e,width:Math.ceil(aq(e,t)),height:Math.ceil(e.split("\n").length*t*1.35)}}function n5(e,t,a){return n3(aO(e,Math.max(1,t),a),a)}function n4(e){return Math.round(100*e)/100}function n6(e,t,a=0){return e.left<t.right+a&&t.left<e.right+a&&e.top<t.bottom+a&&t.top<e.bottom+a}function n7(e,t,a,s){let i=e.map((e,t)=>t).toSorted((t,a)=>e[t].preferred-e[a].preferred),l=Array.from({length:e.length},()=>0),o=t;for(let t of i){let a=e[t],i=Math.max(a.preferred-a.size/2,o);l[t]=i,o=i+a.size+s}let r=a;for(let t of i.toReversed()){let a=e[t],i=Math.min(l[t],r-a.size);l[t]=i,r=i-s}return l}function n8(e){let t=t=>{let a=Number.parseInt(e.slice(t,t+2),16)/255;return a<=.03928?a/12.92:((a+.055)/1.055)**2.4};return .2126*t(1)+.7152*t(3)+.0722*t(5)}function n9(e,t){return(Math.max(e,t)+.05)/(Math.min(e,t)+.05)}function ce(e){let t=n8(e);return n9(t,n8(nJ))>=n9(t,1)?nJ:"#ffffff"}function ct(e,t){let a=[...nW.slice(0,e)];return t&&7===e&&(a[6]=nW[7]),a}class ca{surface;elements=[];layers={back:[],middle:[],front:[]};textBoxes=[];constructor(e){this.surface=e}push(e,t){this.elements.push(e),this.layers[t].push(e.id)}zOrder(){return[...this.layers.back,...this.layers.middle,...this.layers.front]}breakRulesUnderText(e,t=2){let a=nj(this.elements,this.textBoxes.map(e=>e.box),e,t);if(!a.size)return;let s=this.elements.flatMap(e=>a.get(e.id)??[e]);for(let e of(this.elements.splice(0,this.elements.length,...s),Object.values(this.layers))){let t=e.flatMap(e=>a.get(e)?.map(e=>e.id)??[e]);e.splice(0,e.length,...t)}}text(e,t,a,s,i,l,o="center",r={}){let n={left:a,top:s,right:a+t.width,bottom:s+t.height};return this.push({type:"text",id:e,x:n4(a+t.width/2),y:n4(s+t.height/2),text:t.text,fontSize:i,maxWidth:t.width,textAlign:o,textColor:l,...r},"front"),this.textBoxes.push({id:e,box:n}),n}line(e,t,a,s,i="back"){this.push({type:"line",id:e,points:[{x:n4(t.x),y:n4(t.y)},{x:n4(a.x),y:n4(a.y)}],roughness:0,strokeWidth:1,...s},i)}mark(e,t,a,s,i,l="middle"){this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:nN,shape:t,x:n4(a.x),y:n4(a.y),width:n4(Math.max(a.width,.5)),height:n4(Math.max(a.height,.5)),label:s,roughness:0,fillStyle:"solid",strokeWidth:1,...i},l)}polygon(e,t,a,s,i="middle"){let l=t.map(e=>e.x),o=t.map(e=>e.y),r=Math.min(...l),n=Math.min(...o),c=t.map(e=>({x:n4(e.x-r),y:n4(e.y-n)}));this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:nN,shape:"polygon",points:[c[0],c[1],c[2],...c.slice(3)],x:n4(r),y:n4(n),width:n4(Math.max(Math.max(...l)-r,.5)),height:n4(Math.max(Math.max(...o)-n,.5)),label:a,roughness:0,fillStyle:"solid",strokeWidth:1,...s},i)}bounds(){let e=1/0,t=1/0,a=-1/0,s=-1/0,i=(i,l,o,r)=>{e=Math.min(e,i),t=Math.min(t,l),a=Math.max(a,o),s=Math.max(s,r)};for(let e of this.elements)if("line"===e.type||"arrow"===e.type)for(let t of e.points)i(t.x,t.y,t.x,t.y);else if("text"===e.type){let t=e.maxWidth??aq(e.text,e.fontSize),a=e.text.split("\n").length*e.fontSize*1.35;i(e.x-t/2,e.y-a/2,e.x+t/2,e.y+a/2)}else i(e.x,e.y,e.x+e.width,e.y+e.height);return{left:e,top:t,right:a,bottom:s}}}function cs(e,t,a){let s=e.bounds(),i=Math.max(s.right-s.left,320),l=s.top-16;if(a.legend&&t.series.length>1){let o=t.series.map((e,t)=>{let s=n5(e.name??`Series ${t+1}`,200,14),i="line"===a.legend?26:12;return{index:t,text:s,keyWidth:i,width:i+6+s.width}}),r=[[]],n=0;for(let e of o){let t=r.at(-1);t.length&&n+18+e.width>i?(r.push([e]),n=e.width):(n+=18*!!t.length+e.width,t.push(e))}let c=r.map(e=>Math.max(...e.map(e=>e.text.height))),d=l-c.reduce((e,t)=>e+t,0)-(r.length-1)*6;l=d-12,r.forEach((t,i)=>{let l=c[i],o=d+l/2,r=s.left;for(let s of t){let t=a.colors[s.index],i={groupIds:[`chart:legend:${s.index}`]};"line"===a.legend?(e.line(`chart:legend:${s.index}:line`,{x:r,y:o},{x:r+s.keyWidth,y:o},{strokeColor:t,strokeWidth:2,...i},"middle"),ci(e,`chart:key:${s.index}`,s.index,r+s.keyWidth/2,o,t,s.text.text,i)):e.mark(`chart:key:${s.index}`,"rectangle",{x:r,y:o-6,width:12,height:12},s.text.text,{fillColor:t,strokeColor:t,...i}),e.text(`chart:legend:${s.index}:label`,s.text,r+s.keyWidth+6,o-s.text.height/2,14,nJ,"left",i),r+=s.width+18}d+=l+6})}let o=1===t.series.length?t.series[0]?.name:void 0,r=e=>e?.toLowerCase().includes(o.toLowerCase())===!0;if(o&&!r(t.title)&&!r(t.valueAxisTitle)){let t=n5(o,Math.max(i,360),14);e.text("chart:subtitle",t,s.left,l-t.height,14,nK,"left"),l-=t.height+6}let n=n5(t.title,Math.max(i,360),20);e.text("chart:title",n,s.left,l-n.height,20,nJ,"left")}function ci(e,t,a,s,i,l,o,r={}){let n={strokeColor:e.surface,strokeWidth:1,fillColor:l,...r},c=a%6;if(3===c||5===c)return e.polygon(t,3===c?[{x:s,y:i-6.5},{x:s+6.5,y:i+5.2},{x:s-6.5,y:i+5.2}]:[{x:s-6.5,y:i-5.2},{x:s+6.5,y:i-5.2},{x:s,y:i+6.5}],o,n,"front"),{left:s-6.5,top:i-6.5,right:s+6.5,bottom:i+6.5};let d=2===c?13:1===c?10:11,p={x:s-d/2,y:i-d/2,width:d,height:d};return e.mark(t,1===c?"rectangle":2===c?"diamond":"ellipse",p,o,4===c?{strokeColor:l,strokeWidth:2,fillColor:e.surface,...r}:n,"front"),{left:p.x,top:p.y,right:p.x+d,bottom:p.y+d}}function cl(e,t){return e.series[t]?.name??e.title}function co(e,t){return{scale:e,labels:e.ticks.map(a=>n3(function(e,t,a){let s=Math.max(Math.abs(t.min),Math.abs(t.max)),i=e<0,l=Math.abs(e);if(0===l)return nG("0",!1,nD(a)?a:{...a,suffix:""});if(s>=1e4&&nD(a)){let e=n$.find(e=>s>=e.size),o=Math.max(0,nV(t.step/e.size));return nG(`${nY(l/e.size,o)}${e.letter}`,i,a)}return nG(nY(l,t.decimals),i,a)}(a,e,t),13))}}function cr(e){let t=!0===e.stacked&&e.series.length>1,a=nU(e.unit),s=Math.max(...e.series.flatMap(e=>e.values.map(nX))),i=e.categories.map((t,s)=>e.series.map(e=>{let t=e.values[s];return{value:t,text:n3(nR(t,a),12)}})),l=e.categories.map((t,i)=>{let l=e.series.map(e=>e.values[i]),o=l.filter(e=>e>0).reduce((e,t)=>e+t,0),r=l.filter(e=>e<0).reduce((e,t)=>e+t,0),n=e=>({value:e,text:n3(nR(Number(e.toFixed(s)),a,s),12)});return{...o>0||0===r?{up:n(o)}:{},...r<0?{down:n(r)}:{}}}),o=t?l.flatMap(e=>[e.up?.value??0,e.down?.value??0]):e.series.flatMap(e=>e.values);return{diagram:e,stacked:t,parts:a,colors:ct(e.series.length,!1),labels:i,totals:l,domain:nI(o,!0)}}function cn(e,t,a,s){let i=t;for(let t of e){let e=Math.max(i,Math.max(...t.split(/\s+/u).map(e=>n3(e,14).width))+10);for(;e<s&&n5(t,e-10,14).text.split("\n").length>a;)e+=4;i=Math.max(i,e)}return i}function cc(e){let t=e.stacked?1:e.diagram.series.length,a=Math.min(96,720/e.diagram.categories.length),s=1===t?Math.max(16,Math.min(44,Math.round(.6*a))):Math.max(10,Math.round(Math.min(64,.75*a)/t)),i=Math.max(...e.stacked?e.totals.flatMap(e=>[e.up?.text.width??0,e.down?.text.width??0]):e.labels.flat().map(e=>e.text.width)),l=e=>t*e+(t-1)*2;if(1===t)return{bars:t,thickness:s,band:Math.max(l(s)+20,a,i+8)};let o=Math.max(s,i+2);return{bars:t,thickness:o,band:Math.max(l(o)+16,a)}}function cd(e,t,a,s,i=5){let l=nq(e.low,e.high,i);for(let e=0;e<2;e+=1){let e=t/(l.max-l.min),i=a(l,e),o=s(l,e);if(!i&&!o)break;l=nF(l,o,i)}return l}function cp(e,t,a){let s=Math.max(1,Math.ceil(Math.abs(a-t)/n0));return Array.from({length:s+1},(i,l)=>{let o=t+(a-t)*l/s;return{x:e*Math.cos(o),y:e*Math.sin(o)}})}function ch(e,t,a){let s=Math.cos(t),i=Math.sin(t),l=Math.max(0,Math.min(a,e.x*s+e.y*i));return Math.hypot(e.x-l*s,e.y-l*i)}let cg=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function cu(e){let t=new Date(864e5*e);return{year:t.getUTCFullYear(),month:t.getUTCMonth()+1,day:t.getUTCDate(),weekday:(t.getUTCDay()+6)%7}}function cf(e,t,a=1){let s=new Date(0);return s.setUTCFullYear(e,t-1,a),Math.round(s.getTime()/864e5)}let cm=[{unit:"day",step:1},{unit:"week",step:1},{unit:"month",step:1},{unit:"quarter",step:1},{unit:"year",step:1},{unit:"year",step:2},{unit:"year",step:5},{unit:"year",step:10},{unit:"year",step:20},{unit:"year",step:25},{unit:"year",step:50}];function cv(e,t,a,s,i,l=1/0){let o=[];for(let r=function(e,t,a){let s=cu(e);switch(t){case"day":return e;case"week":return e-s.weekday;case"month":return cf(s.year,s.month);case"quarter":return cf(s.year,s.month-(s.month-1)%3);case"year":return cf(s.year-(s.year%a+a)%a,1)}}(e,a,s);r<t;){if(o.length>=l)return;let e=function(e,t,a){let s=cu(e);switch(t){case"day":return e+1;case"week":return e+7;case"month":return cf(s.year,s.month+1);case"quarter":return cf(s.year,s.month+3);case"year":return cf(s.year+a,1)}}(r,a,s);o.push({start:r,end:e,label:i(r)}),r=e}return o}function cy(e){return e%2==0?16:12}let cw=[0,6,12,18,24,30],cx=[1,0,-1,0],cb=[0,1,0,-1];function ck(e,t,a){return{x:e.x+cx[t]*a,y:e.y+cb[t]*a}}function cM(e){let t=e.map(e=>Math.round(100*e)/100).toSorted((e,t)=>e-t);return t.filter((e,a)=>0===a||e-t[a-1]>.01)}class cC{costs=new Float64Array(1024);reachedAt=new Float64Array(1024);orders=new Float64Array(1024);states=new Int32Array(1024);length=0;order=0;cost=0;reached=0;get size(){return this.length}push(e,t,a){this.length===this.costs.length&&this.grow();let s=this.order++,i=this.length++;for(;i>0;){let t=i-1>>1;if(!cz(e,s,this.costs[t],this.orders[t]))break;this.move(t,i),i=t}this.place(i,e,t,s,a)}pop(){let e=this.states[0];this.cost=this.costs[0],this.reached=this.reachedAt[0];let t=--this.length;if(t>0){let e=this.costs[t],a=this.reachedAt[t],s=this.orders[t],i=this.states[t],l=0;for(;;){let a=2*l+1;if(a>=t)break;let i=a+1,o=i<t&&cz(this.costs[i],this.orders[i],this.costs[a],this.orders[a])?i:a;if(!cz(this.costs[o],this.orders[o],e,s))break;this.move(o,l),l=o}this.place(l,e,a,s,i)}return e}move(e,t){this.costs[t]=this.costs[e],this.reachedAt[t]=this.reachedAt[e],this.orders[t]=this.orders[e],this.states[t]=this.states[e]}place(e,t,a,s,i){this.costs[e]=t,this.reachedAt[e]=a,this.orders[e]=s,this.states[e]=i}grow(){let e=2*this.costs.length,t=(t,a)=>{let s=a(e);return s.set(t),s};this.costs=t(this.costs,e=>new Float64Array(e)),this.reachedAt=t(this.reachedAt,e=>new Float64Array(e)),this.orders=t(this.orders,e=>new Float64Array(e)),this.states=t(this.states,e=>new Int32Array(e))}}function cz(e,t,a,s){return e<a-1e-9||1e-9>=Math.abs(e-a)&&t<s}function c_(e,t,a,s){let{box:i}=e;if(e.parallel&&i.right-i.left>=i.bottom-i.top!==s)return!1;let l=Math.max(0,e.clearance-.01),o=Math.max(0,(e.sideClearance??e.clearance)-.01);return s?Math.min(a,i.right+o)-Math.max(t,i.left-o)>.01:Math.min(a,i.bottom+l)-Math.max(t,i.top-l)>.01}function cL(e,t,a){return e.filter(({box:e,clearance:s,sideClearance:i})=>{let l=Math.max(0,s-.01),o=Math.max(0,(i??s)-.01);return a?t>e.top-l&&t<e.bottom+l:t>e.left-o&&t<e.right+o})}function cB(e){return .01>Math.abs(e.from.y-e.to.y)}function cS(e,t,a,s=5){let i=.01>Math.abs(e.y-t.y);if(i!==cB(a)||(i?Math.abs(e.y-a.from.y):Math.abs(e.x-a.from.x))>=s)return!1;let[l,o]=i?[Math.min(e.x,t.x),Math.max(e.x,t.x)]:[Math.min(e.y,t.y),Math.max(e.y,t.y)],[r,n]=i?[Math.min(a.from.x,a.to.x),Math.max(a.from.x,a.to.x)]:[Math.min(a.from.y,a.to.y),Math.max(a.from.y,a.to.y)];return Math.min(o,n)-Math.max(l,r)>-s}function cA(e,t,a){if(!a)return!1;let s=.01>Math.abs(e.y-t.y);return s===cB(a)&&(s?.01>Math.abs(e.y-a.from.y):.01>Math.abs(e.x-a.from.x))}let cP={best:new Float64Array(0),previous:new Int32Array(0),stamp:new Int32Array(0),epoch:0,steps:new Float64Array(0),stepStamp:new Int32Array(0),estimates:new Float64Array(0),estimateStamp:new Int32Array(0),gridEpoch:0};function cV(e){let t=function(e){let t;for(let a of e.sources)for(let s of e.targets){if(a.direction!==s.direction)continue;let i=a.direction%2==0?(s.x-a.x)*cx[a.direction]:(s.y-a.y)*cb[a.direction];if(!(a.direction%2==0?.01>Math.abs(a.y-s.y):.01>Math.abs(a.x-s.x))||i<(a.lead??8)+cy(s.direction))continue;let l=e.obstacles.some(e=>!e.own&&function(e,t,a){let s=.01>Math.abs(t.y-a.y);return 0!==cL([e],s?t.y:t.x,s).length&&c_(e,s?Math.min(t.x,a.x):Math.min(t.y,a.y),s?Math.max(t.x,a.x):Math.max(t.y,a.y),s)}(e,a,s))||e.routed.some(t=>!e.trunks?.has(t)&&cS(a,s,t)),o=a.cost+s.cost+i;l||t&&!(o<t.cost)||(t={cost:o,points:[a,s]})}return t?.points}(e);if(t)return t;let a=[...e.sources,...e.targets],s=(e,t)=>({left:Math.min(...a.map(e=>e.x))-e,right:Math.max(...a.map(e=>e.x))+e,top:Math.min(...a.map(e=>e.y))-t,bottom:Math.max(...a.map(e=>e.y))+t}),i={separation:5,lanes:e.lanes,splits:[.5],crossingCost:e.crossingCost??30},{behind:l}=e,o=void 0===l?i:{...i,behind:l},r={...o,separation:2.5,lanes:e.denseLanes,splits:[.25,.5,.75],crossingCost:2},n=s(200,90),c=s(800,360),{reach:d}=e,p=d?{left:Math.min(c.left,d.left),right:Math.max(c.right,d.right),top:Math.min(c.top,e.top),bottom:Math.max(c.bottom,e.bottom)}:c,h=e.budget,g=e.kinkBudget,u=(t,a,s)=>{if(h&&h.remaining<=0)return;let i=function(e,t,a){var s;let{routed:i}=e,{separation:l}=a,o=e.pastTrunk??new Map,r=[...e.obstacles,...o.keys()],n=e.sources.map(e=>ck(e,e.direction,e.lead??8)),c=e.targets.map(e=>ck(e,(e.direction+2)%4,cy(e.direction))),d=[...e.sources,...e.targets,...n,...c],p=8+cw.at(-1)+10,h=r.filter(({box:e})=>e.right>=t.left-p&&e.left<=t.right+p&&e.bottom>=t.top-p&&e.top<=t.bottom+p),g=h.filter(({box:e})=>e.bottom>=t.top&&e.top<=t.bottom).flatMap(({box:e,clearance:t,sideClearance:a})=>[e.left-Math.max(a??t,5),e.right+Math.max(a??t,5)]).filter(e=>e>=t.left&&e<=t.right),u=d.map(e=>e.x),f=Math.max(t.left,Math.min(...u,...g))-8,m=Math.min(t.right,Math.max(...u,...g))+8,v=cM([...u,...g,...cw.flatMap(e=>[f-e,m+e])]),y=cM([...v,...v.slice(1).flatMap((e,t)=>{let s=v[t];return e-s>4*l?a.splits.map(t=>s+(e-s)*t):[]})]),w=cM([...d.map(e=>e.y),...a.lanes.filter(e=>e>=t.top&&e<=t.bottom)]).filter(t=>t>=e.top&&t<=e.bottom),x=new Map(y.map((e,t)=>[e,t])),b=new Map(w.map((e,t)=>[e,t])),k=e=>{let t=x.get(Math.round(100*e.x)/100),a=b.get(Math.round(100*e.y)/100);return void 0===t||void 0===a?void 0:a*y.length+t},M=[],C=e=>M[e]??={x:y[e%y.length],y:w[Math.floor(e/y.length)]},z=p+12,_=i.filter(e=>Math.max(e.from.x,e.to.x)>=t.left-z&&Math.min(e.from.x,e.to.x)<=t.right+z&&Math.max(e.from.y,e.to.y)>=t.top-z&&Math.min(e.from.y,e.to.y)<=t.bottom+z),L=_.filter(cB),B=_.filter(e=>!cB(e)),S=(e.edges??[]).filter(e=>e.right>=t.left&&e.left<=t.right&&e.bottom>=t.top-7&&e.top<=t.bottom+7),A=new Map,P=new Map,V=(t,a)=>{let s=a?A:P,i=s.get(t);if(!i){let[o,r]=a?[L,B]:[B,L],n=e=>Math.abs(a?e.from.y-t:e.from.x-t);i={obstacles:cL(h,t,a),routed:[...o.filter(e=>n(e)<l),...r.filter(e=>a?t>Math.min(e.from.y,e.to.y)&&t<Math.max(e.from.y,e.to.y):t>Math.min(e.from.x,e.to.x)&&t<Math.max(e.from.x,e.to.x))],beside:o.filter(t=>12>n(t)&&!e.kin?.has(t)),edges:a?S.filter(e=>t<=e.top&&e.top-t<7||t>=e.bottom&&t-e.bottom<7):[]},s.set(t,i)}return i},H=(e,t)=>{let a=.01>Math.abs(e.y-t.y);return V(a?e.y:e.x,a)},q=(t,a,s=!1,i=!1,r=H(t,a))=>{let n=.01>Math.abs(t.y-a.y),c=n?Math.min(t.x,a.x):Math.min(t.y,a.y),d=n?Math.max(t.x,a.x):Math.max(t.y,a.y);return!r.obstacles.some(e=>!(s&&e.own)&&!(i&&cA(t,a,o.get(e)))&&c_(e,c,d,n))&&!r.routed.some(s=>!(i&&e.trunks?.has(s))&&cS(t,a,s,l))},{behind:F}=a,I=e.targets.map(e=>e.cost+cy(e.direction)),E=Float64Array.from(c,e=>e.x),O=Float64Array.from(c,e=>e.y),U=(e,t,a)=>{let s=1/0;for(let i=0;i<E.length;i+=1){let l=E[i]-e,o=O[i]-t,r=l*cx[a]+o*cb[a],n=Math.abs(l*cb[a])+Math.abs(o*cx[a])<.01?r>-.01?0:2:r>-.01?1:2,c=Math.abs(l)+Math.abs(o)+24*n+I[i];c<s&&(s=c)}return s},{steps:X,stepStamp:T,estimates:Y,estimateStamp:$,gridEpoch:G}=(s=y.length*w.length*4,cP.stepStamp.length<s&&(cP.steps=new Float64Array(s),cP.stepStamp=new Int32Array(s),cP.estimates=new Float64Array(s),cP.estimateStamp=new Int32Array(s)),cP.gridEpoch>=0x40000000&&(cP.stepStamp.fill(0),cP.estimateStamp.fill(0),cP.gridEpoch=0),cP.gridEpoch+=1,cP),D=new Map,R=new Map;e.targets.forEach((e,t)=>{let a=c[t],s=k(a);if(void 0===s||!q(a,e,!0))return;D.set(s,[...D.get(s)??[],e]);let i=4*s+e.direction;R.set(i,Math.min(R.get(i)??1/0,I[t]))});let Z=(e,t,a,s)=>{let i=4*e+a;if(!s&&T[i]===G)return X[i];let l=j(C(e),C(t),a,s)??1/0;return s||(T[i]=G,X[i]=l),l},j=(t,s,i,l)=>{let o=V(i%2==0?t.y:t.x,i%2==0);if(!q(t,s,!1,l,o))return;let r=2===i?a.crossingCost*(e.backCrossingFactor??8):a.crossingCost;return Math.abs(s.x-t.x)+Math.abs(s.y-t.y)+(void 0===F?0:4*Math.max(0,Math.min(F,Math.max(t.x,s.x))-Math.min(t.x,s.x)))+2*((e,t,a=H(e,t))=>{if(0===a.edges.length)return 0;let s=Math.min(e.x,t.x),i=Math.max(e.x,t.x),l=0;for(let e of a.edges)l+=Math.max(0,Math.min(i,e.right)-Math.max(s,e.left));return l})(t,s,o)+(r?((t,a,s=H(t,a))=>{let i=0;for(let l of s.routed)(function(e,t,a){let s=.01>Math.abs(e.y-t.y);if(s===cB(a))return!1;let[i,l,o,r]=s?[e,t,a.from,a.to]:[a.from,a.to,e,t],n=o.x,c=i.y;return n>Math.min(i.x,l.x)+.01&&n<Math.max(i.x,l.x)-.01&&c>Math.min(o.y,r.y)+.01&&c<Math.max(o.y,r.y)-.01})(t,a,l)&&(i+=e.lastRuns?.has(l)?4:1);return i})(t,s,o)*r:0)+2*((e,t,a=H(e,t))=>{if(0===a.beside.length)return 0;let s=.01>Math.abs(e.y-t.y),i=s?Math.min(e.x,t.x):Math.min(e.y,t.y),l=s?Math.max(e.x,t.x):Math.max(e.y,t.y),o=0;for(let e of a.beside){let[t,a]=s?[Math.min(e.from.x,e.to.x),Math.max(e.from.x,e.to.x)]:[Math.min(e.from.y,e.to.y),Math.max(e.from.y,e.to.y)];o+=Math.max(0,Math.min(l,a)-Math.max(i,t))}return o})(t,s,o)},N=y.length,W=w.length;return(t,a,s)=>{var i;let l,{best:o,previous:r,stamp:c,epoch:d}=(i=y.length*w.length*12,cP.stamp.length<i&&(cP.best=new Float64Array(i),cP.previous=new Int32Array(i),cP.stamp=new Int32Array(i)),cP.epoch>=0x40000000&&(cP.stamp.fill(0),cP.epoch=0),cP.epoch+=1,cP),p=e=>c[e]===d?o[e]:1/0,h=(e,t)=>{let a=e%3;if(0===a)return!1;let s=e-a,i=2!==a||R.has(s/3)?0:40;return p(s+0)<=t+i+1e-9||2===a&&p(s+1)<=t+i+1e-9},g=new cC,u=new Map;e.sources.forEach((e,t)=>{let a=n[t],s=k(a);if(void 0===s||!q(e,a,!0,!0))return;let i=(4*s+e.direction)*3+0,l=e.cost+(e.lead??8);l<p(i)&&(c[i]=d,o[i]=l,r[i]=-1,u.set(i,e),g.push(l+U(a.x,a.y,e.direction),l,i))});let f=a,m=(e,t,a,s,i)=>{let l;if(t>=p(e)-1e-9||h(e,t))return;let n=($[l=4*s+i]!==G&&($[l]=G,Y[l]=U(y[s%y.length],w[Math.floor(s/y.length)],i)),Y[l]);e%3==2&&(n=Math.min(40+n,R.get(4*s+i)??1/0)),t+n>=f||(c[e]=d,o[e]=t,r[e]=a,u.delete(e),g.push(t+n,t,e))},v=0;for(;g.size>0&&v++<s;){let e=g.pop(),a=g.cost,s=g.reached;if(a>=f)break;let i=p(e);if(s>i+1e-6||h(e,i))continue;let o=e%3,r=Math.floor(e/12),n=Math.floor(e/3)%4,c=r%N,d=(r-c)/N,u=y[c],v=w[d],x=40*(2===o);for(let t of D.get(r)??[]){if((t.direction+2)%4===n)continue;let a=i+t.cost+cy(t.direction)+(t.direction===n?0:24+x);a<f&&(l={state:e,port:t},f=a)}let b=c+cx[n],k=d+cb[n];if(2!==o&&b>=0&&b<N&&k>=0&&k<W){let t=k*N+b,a=(4*t+n)*3+o;if(i+(Math.abs(y[b]-u)+Math.abs(w[k]-v))<p(a)-1e-9){let s=Z(r,t,n,0===o);1/0!==s&&m(a,i+s,e,t,n)}}for(let a=1;a<=3;a+=2){let s=(n+a)%4,l=i+24+x,o=0,r=c,h=d;for(;;){let a=r+cx[s],i=h+cb[s];if(a<0||a>=N||i<0||i>=W)break;let n=Math.abs(y[a]-y[r])+Math.abs(w[i]-w[h]),c=i*N+a,d=(4*c+s)*3;if(Math.min(p(d),p(d+1))<=l+n+1e-9)break;let g=Z(h*N+r,c,s,!1);if(1/0===g)break;l+=g,o+=n,r=a,h=i;let u=!t||o>=28;if(m(d+(u?1:2),l,e,c,s),u)break}}}if(!l)return{expansions:v};let x=f,b=[l.port],M=l.state;for(b.push(ck(l.port,(l.port.direction+2)%4,cy(l.port.direction)));M>=0;){b.push(C(Math.floor(M/12)));let e=u.get(M);if(e){b.push(e);break}M=r[M]}return{points:function(e){let t=[];for(let a of e){let e=t.at(-1);if(e&&.01>Math.abs(e.x-a.x)&&.01>Math.abs(e.y-a.y))continue;let s=t.at(-2);s&&e&&(.01>Math.abs(s.x-e.x)&&.01>Math.abs(e.x-a.x)||.01>Math.abs(s.y-e.y)&&.01>Math.abs(e.y-a.y))?t[t.length-1]=a:t.push(a)}return t}(b.toReversed()),cost:x,expansions:v}}}(e,t,a),l=i(!1,1/0,12e3);if(h&&(h.remaining-=l.expansions),!l.points)return;let o=cH(l.points);if(!s||!g||g.remaining<=0||0===o)return l.points;let r=i(!0,l.cost+o-1e-6,Math.min(12e3,2*l.expansions,g.remaining));return g.remaining-=r.expansions,r.points??l.points};return(e.wide?void 0:u(n,o,!0))??u(p,o,!0)??u(p,r,!1)}function cH(e){let t=cq(e),a=0;for(let{from:e,to:s}of t.slice(1,-1))Math.abs(s.x-e.x)+Math.abs(s.y-e.y)<28&&(a+=40);return a}function cq(e){return e.slice(1).map((t,a)=>({from:e[a],to:t}))}function cF(e,t,a){let s=e.at(-1),i=e.at(-2),l=Math.min(1,t/Math.max(Math.abs(s.x-i.x)+Math.abs(s.y-i.y),.01)),o={x:s.x+(i.x-s.x)*l,y:s.y+(i.y-s.y)*l};return{left:Math.min(o.x,s.x)-a,right:Math.max(o.x,s.x)+a,top:Math.min(o.y,s.y)-a,bottom:Math.max(o.y,s.y)+a}}let cI=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],cE=(e,t=2)=>String(e).padStart(t,"0");function cO(e){let t,a=new Map;for(let t of[...e.events.flatMap(e=>[e.date,e.end]),e.today]){let e=void 0===t?void 0:ei(t);void 0!==t&&e&&a.set(t,e)}if(0===a.size)return{events:new Map};let s=new Set([...a.values()].flatMap(e=>void 0===e.offsetMinutes?[]:[e.offsetMinutes])),i=1===s.size?[...s][0]??0:0,l=s.size>0?function(e){if(0===e)return"UTC";let t=Math.abs(e);return`UTC${e<0?"-":"+"}${cE(Math.floor(t/60))}:${cE(t%60)}`}(i):void 0,o=new Map([...a].map(([e,t])=>[e,function(e,t){if("instant"!==e.granularity)return{granularity:e.granularity,...e.fields};let a=new Date(e.start+6e4*t);return{granularity:"instant",year:a.getUTCFullYear(),month:a.getUTCMonth()+1,day:a.getUTCDate(),hour:a.getUTCHours(),minute:a.getUTCMinutes(),second:a.getUTCSeconds(),millisecond:a.getUTCMilliseconds()}}(t,i)])),r=[...o.values()],n=r[0],c=r.some(e=>"instant"===e.granularity)&&r.every(e=>("day"===e.granularity||"instant"===e.granularity)&&e.year===n.year&&e.month===n.month&&e.day===n.day),d=r.some(e=>e.year!==n.year),p=r.some(e=>"instant"===e.granularity&&e.second>0),h=r.some(e=>"instant"===e.granularity&&e.millisecond>0),g=e=>`${cE(e.hour)}:${cE(e.minute)}${p||h?`:${cE(e.second)}`:""}${h?`.${cE(e.millisecond,3)}`:""}`,u=e=>`${cI[e.month-1]} ${e.day}`,f=(e,t)=>{if(c)return"instant"===e.granularity?g(e):u(e);let a=t?` ${e.year}`:"";switch(e.granularity){case"year":return String(e.year);case"month":return`${cI[e.month-1]}${a}`;case"day":return`${u(e)}${t?`, ${e.year}`:""}`;case"instant":return`${u(e)}${t?`, ${e.year}`:""}, ${g(e)}`}},m=(e,t,a)=>{if(c)return`${f(e,!1)}–${f(t,!1)}`;if(e.year!==t.year)return`${f(e,!0)} – ${f(t,!0)}`;let s=a&&"year"!==t.granularity?`, ${t.year}`:"";return"day"===e.granularity&&"day"===t.granularity&&e.month===t.month?`${u(e)}–${t.day}${s}`:"month"===e.granularity&&"month"===t.granularity?`${cI[e.month-1]} – ${cI[t.month-1]}${a?` ${t.year}`:""}`:`${f(e,!1)} – ${f(t,!1)}${s}`},v=new Map;for(let a of ep(e)){let e=void 0===a.date?void 0:o.get(a.date);if(!e)continue;let s=void 0===a.end?void 0:o.get(a.end),i=e.year!==t?.year||"month"===e.granularity&&"month"!==t.granularity;v.set(a.id,s?m(e,s,i):f(e,i)),t=s??e}let y=c?`${u(n)}, ${n.year}${l?` \xb7 ${l}`:""}`:l?`Times in ${l}`:void 0,w=void 0===e.today?void 0:o.get(e.today);return{...y?{header:y}:{},events:v,...w?{today:`Today \xb7 ${f(w,d)}`}:{}}}let cU={millisecond:1,second:1e3,minute:6e4,hour:36e5,day:864e5,month:2629746e3,year:31556952e3},cX=v.ink,cT="#4c4639",cY="#cbbfa9",c$="#c0392b",cG=[12,24],cD=[0,-6,6],cR=[-3,3];function cZ(e,t){return{text:e,width:Math.ceil(aq(e,t)),height:Math.ceil(e.split("\n").length*t*1.35)}}function cj(e,t,a){let s=cZ(e,a);return s.width<=t?s:cZ(aO(e,Math.max(1,t),a),a)}function cN(e){return Math.round(100*e)/100}class cW{elements=[];layers={back:[],middle:[],front:[]};textBoxes=[];push(e,t){this.elements.push(e),this.layers[t].push(e.id)}zOrder(){return[...this.layers.back,...this.layers.middle,...this.layers.front]}text(e,t,a,s,i,l,o="left",r={}){let n={left:a,top:s,right:a+t.width,bottom:s+t.height};return this.push({type:"text",id:e,x:cN(a+t.width/2),y:cN(s+t.height/2),text:t.text,fontSize:i,maxWidth:t.width,textAlign:o,textColor:l,...r},"front"),this.textBoxes.push(n),n}line(e,t,a,s="back"){let[i,l,...o]=t.map(e=>({x:cN(e.x),y:cN(e.y)}));this.push({type:"line",id:e,points:[i,l,...o],roughness:0,strokeWidth:1,...a},s)}mark(e,t,a,s,i){this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:"gantt-mark",shape:t,x:cN(a.x),y:cN(a.y),width:cN(cN(a.x+a.width)-cN(a.x)),height:cN(cN(a.y+a.height)-cN(a.y)),label:s,roughness:0,fillStyle:"solid",strokeWidth:1,...i},"middle")}breakRulesUnderText(e,t=this.textBoxes){let a=nj(this.elements,t,e);if(!a.size)return;let s=this.elements.flatMap(e=>a.get(e.id)??[e]);for(let e of(this.elements.splice(0,this.elements.length,...s),Object.values(this.layers))){let t=e.flatMap(e=>a.get(e)?.map(e=>e.id)??[e]);e.splice(0,e.length,...t)}}bounds(){let e=1/0,t=1/0,a=-1/0,s=-1/0,i=(i,l,o,r)=>{e=Math.min(e,i),t=Math.min(t,l),a=Math.max(a,o),s=Math.max(s,r)};for(let e of this.elements)if("line"===e.type||"arrow"===e.type)for(let t of e.points)i(t.x,t.y,t.x,t.y);else if("text"===e.type){let t=e.maxWidth??aq(e.text,e.fontSize),a=e.text.split("\n").length*e.fontSize*1.35;i(e.x-t/2,e.y-a/2,e.x+t/2,e.y+a/2)}else i(e.x,e.y,e.x+e.width,e.y+e.height);return{left:e,top:t,right:a,bottom:s}}}let cJ=[7,19,31];function cK(e,t,a,s,i=[]){let l=(e.top+e.bottom)/2,o=e=>40*(1===e!==a);if(t){let t=(e.left+e.right)/2,a=(e.right-e.left)/4;return[{x:e.right,y:l,direction:0,cost:2},{x:t,y:e.bottom,direction:1,cost:o(1)},{x:t,y:e.top,direction:3,cost:o(3)},...[-1,1].map(t=>({x:e.right-a,y:l+t*a,direction:0,cost:8})),{x:t+a,y:e.bottom-a,direction:1,cost:6+o(1)},{x:t+a,y:e.top+a,direction:3,cost:6+o(3)},{x:t-a,y:e.bottom-a,direction:1,cost:16+o(1)},{x:t-a,y:e.top+a,direction:3,cost:16+o(3)},...i.filter(t=>t>e.left+2&&t<e.right-2).flatMap(e=>{let s=2*a-Math.abs(e-t),i=(e<t?16:6)+3;return[{x:e,y:l+s,direction:1,cost:i+o(1)},{x:e,y:l-s,direction:3,cost:i+o(3)}]})]}let r=[6,16,26].filter(t=>e.right-t>=e.left+3),n=Array.from({length:6},(t,a)=>e.right-6-2.5*a).filter(t=>t>=e.left+2),c=r.length>=3?r.map(t=>e.right-t):n.length?n:[(e.left+e.right)/2],d=void 0!==s&&s>e.left+1&&s<e.right-1?[s]:[],p=i.filter(t=>t>=Math.max(e.left+2,e.right-32)&&t<=e.right-2&&c.every(e=>Math.abs(e-t)>=1));return[...d.flatMap(t=>[{x:t,y:e.bottom,direction:1,cost:o(1)},{x:t,y:e.top,direction:3,cost:o(3)}]),...c.map((t,a)=>({x:t,y:e.bottom,direction:1,cost:o(1)+3*a})),...p.flatMap(t=>[{x:t,y:e.bottom,direction:1,cost:o(1)+3},{x:t,y:e.top,direction:3,cost:o(3)+3}]),...e.right-e.left>=8?[{x:e.right,y:l,direction:0,cost:2}]:[],...c.map((t,a)=>({x:t,y:e.top,direction:3,cost:o(3)+3*a}))]}function cQ(e,t=!1){let a=!t&&.01>Math.abs(e.at(-1).y-e.at(-2).y);return cF(e,a?40:12,4.5)}function c1(e,t,a,s=!1){let i=cQ(t,s),l=cq(e),o=cq(t),r=a.leaving&&cA(l[0].from,l[0].to,o[0])?cQ(t,!0):i,n=0;return l.forEach((e,t)=>{c0(e,0===t?r:i)&&(n+=1),o.forEach((s,i)=>{!(a.leaving&&0===t&&0===i||a.arriving&&t===l.length-1&&i===o.length-1)&&function(e,t,a){let s=.01>Math.abs(e.y-t.y);if(s!==.01>Math.abs(a.from.y-a.to.y)||(s?Math.abs(e.y-a.from.y):Math.abs(e.x-a.from.x))>=2)return!1;let[i,l]=s?[Math.min(e.x,t.x),Math.max(e.x,t.x)]:[Math.min(e.y,t.y),Math.max(e.y,t.y)],[o,r]=s?[Math.min(a.from.x,a.to.x),Math.max(a.from.x,a.to.x)]:[Math.min(a.from.y,a.to.y),Math.max(a.from.y,a.to.y)];return Math.min(l,r)-Math.max(i,o)>0}(e.from,e.to,s)&&function(e,t){let a=.01>Math.abs(e.from.y-e.to.y),s=e=>a?[Math.min(e.from.x,e.to.x),Math.max(e.from.x,e.to.x)]:[Math.min(e.from.y,e.to.y),Math.max(e.from.y,e.to.y)],[i,l]=s(e),[o,r]=s(t);return Math.min(l,r)-Math.max(i,o)}(e,s)>1&&(n+=1)})}),n}function c0(e,t){let{from:a,to:s}=e;return Math.max(a.x,s.x)>t.left&&Math.min(a.x,s.x)<t.right&&Math.max(a.y,s.y)>t.top&&Math.min(a.y,s.y)<t.bottom}function c2(e){return e.replaceAll("%","%25").replaceAll(":","%3A")}let c3=[2.5,2,.3,.05,0];function c5(e,t,a=1){return[e,...Array.from({length:Math.max(0,Math.floor(t/a))},(e,t)=>(t+1)*a).flatMap(t=>[e+t,e-t])]}function c4(e,t){let a,s,i,l,o,r,n,c,d,p=new Map(e.tasks.map(e=>[e.id,tr(e)])),h=tc(e),g=void 0===e.today?void 0:ti(e.today),u=[...p.values()],f=Math.min(...u.map(e=>e.start),g??1/0),m=Math.max(...u.map(e=>e.milestone?e.start+1:e.end),void 0===g?-1/0:g+1),v=(a=new Map(e.tasks.map(e=>[e.id,tr(e)])),s=tc(e).flatMap((e,t)=>{if(void 0===e.phase)return[];let s=e.tasks.map(e=>a.get(e.id));return[{index:t,name:e.phase,start:Math.min(...s.map(e=>e.start)),end:Math.max(...s.map(e=>Math.max(e.end,e.start+1)))}]}),i=e=>`\0phase:${e}`,l=(e,t,a,s)=>({id:e,label:t,date:tl(a),...s-a>1?{end:tl(s-1)}:{}}),r=cO(o={id:e.id,title:e.title,type:"timeline",events:[...s.map(e=>l(i(e.index),e.name,e.start,e.end)),...e.tasks.map(e=>{let t=a.get(e.id);return l(e.id,e.label,t.start,t.end)})],...e.today?{today:e.today}:{},style:e.style}),n=new Set(o.events.flatMap(e=>[e.date,e.end].flatMap(e=>void 0===e?[]:[e.slice(0,4)]))),c=e=>{if(n.size<2)return r.events.get(e)??"";let t=o.events.find(t=>t.id===e);return cO({...o,events:[t]}).events.get(e)??""},{tasks:new Map(e.tasks.map(e=>{let t=c(e.id);return[e.id,void 0===e.progress?t:`${t} \xb7 ${e.progress}%`]})),phases:new Map(s.map(e=>[e.name,c(i(e.index))])),...r.today?{today:r.today}:{}}),y=(e,a)=>{let s=cj(e.label,260,14);return{task:e,schedule:p.get(e.id),color:a,label:s,caption:cZ(v.tasks.get(e.id),12),height:Math.max(t,s.height+16)}},w=[],x=0;h.forEach((e,t)=>{let a=nW[t%nW.length];if(void 0!==e.phase){let a=cj(e.phase,220,15),s=cZ(v.phases.get(e.phase),12),i=Math.max(40,a.height+16);w.push({kind:"phase",top:x,height:i,phase:{index:t,name:a,caption:s}}),x+=i}for(let t of e.tasks){let e=y(t,a);w.push({kind:"task",top:x,height:e.height,task:e}),x+=e.height}});let b=x,k=w.filter(e=>"task"===e.kind).length,M=12*!!w.some(e=>"phase"===e.kind),C=Math.max(Math.max(...w.map(e=>e.task?M+e.task.label.width:0))+20+Math.max(...w.map(e=>(e.task?e.task.caption:e.phase.caption).width)),...w.map(e=>e.phase?e.phase.name.width+10+e.phase.caption.width:0)),z=-16-C,_=function(e,t,a=960){let s=Math.max(t,e+1);for(let{unit:t,step:i}of cm){let l="year"===t&&50===i,o=cv(e,s,t,i,e=>(function(e,t,a){let s=cu(e);switch(t){case"day":return String(s.day);case"week":return`${cg[s.month-1]} ${s.day}`;case"month":return cg[s.month-1];case"quarter":return`Q${Math.floor((s.month-1)/3)+1}`;case"year":return 1===a?String(s.year):`${s.year}–${String(s.year+a-1)}`}})(e,t,i),l?1/0:36);if(!o)continue;let r=o[0].start,n=o.at(-1).end,c=Math.min(56,a/(n-r));if(!o.every(e=>aq(e.label,12)+8<=(e.end-e.start)*c)&&!l)continue;let d=("year"===t?[]:"day"===t?cv(r,n,"month",1,e=>`${cg[cu(e).month-1]} ${cu(e).year}`):cv(r,n,"year",1,e=>String(cu(e).year)))??[],p=new Set(o.map(e=>e.start)),h="month"===t?"week":"quarter"===t?"month":void 0,g=h&&("week"===h?7:28)*c>=12?(cv(r,n,h,1,()=>"")??[]).map(e=>e.start).filter(e=>e>r&&!p.has(e)):[];return{unit:t,step:i,start:r,end:n,pxPerDay:c,cells:o,minor:g,bands:d.map(e=>({start:Math.max(e.start,r),end:Math.min(e.end,n),label:e.label}))}}throw Error("unreachable: half-century ticks always fit")}(f,m,Math.max(640,Math.min(960,2.2*(Math.ceil(27*!!e.title.length)+14+18*(void 0!==g)+44+b+44*(k>=16)+80)-80-C-16-24))),L=Math.max(0,...u.map(e=>e.milestone?15-(e.start+.5-_.start)*_.pxPerDay:0)),B=e=>24+L+(e-_.start)*_.pxPerDay,S=B(_.end),A=new cW,P=[{box:{left:z-32,right:-2,top:0,bottom:b},clearance:0}],V=new Map;for(let e of w){if("phase"!==e.kind)continue;let{index:t,name:a,caption:s}=e.phase,i=e.top+e.height/2,l={groupIds:[`gantt:phase:${t}`]};A.text(`gantt:phase:${t}`,a,z,i-a.height/2,15,cX,"left",l),A.text(`gantt:phase-caption:${t}`,s,-16-s.width,i-s.height/2,12,cT,"right",l)}for(let e of w){if("task"!==e.kind)continue;let{task:t,schedule:a,color:s,label:i,caption:l}=e.task,o=e.top+e.height/2,r=a.milestone?B(a.start+.5)-13:B(a.start),n=a.milestone?B(a.start+.5)+13:Math.max(B(a.end),B(a.start)+2),c=`gantt:task:${t.id}`,d={groupIds:[c]},p={groupIds:[`gantt:row:${t.id}`]},h=a.milestone?{left:r,right:n,top:o-13,bottom:o+13}:{left:r,right:n,top:o-11,bottom:o+11};V.set(t.id,h),A.mark(c,a.milestone?"diamond":"rectangle",{x:h.left,y:h.top,width:h.right-h.left,height:h.bottom-h.top},t.label,a.milestone?{fillColor:cX,strokeColor:cX,...d}:{fillColor:s,strokeColor:s,...d});let g=t.progress??0,u=function(e){let t=t=>{let a=Number.parseInt(e.slice(t,t+2),16);return Math.round(a+(Number.parseInt(cX.slice(t,t+2),16)-a)*.35).toString(16).padStart(2,"0")};return`#${t(1)}${t(3)}${t(5)}`}(s),f=h.left+(h.right-h.left)*g/100;!a.milestone&&f-h.left>=1&&A.mark(`gantt:progress:${t.id}`,"rectangle",{x:h.left,y:h.top,width:f-h.left,height:h.bottom-h.top},`${t.label} \xb7 ${g}%`,{fillColor:u,strokeColor:u,...d}),A.text(`gantt:label:${t.id}`,i,z+M,o-i.height/2,14,cX,"left",p),A.text(`gantt:caption:${t.id}`,l,-16-l.width,o-l.height/2,12,cT,"right",p)}let H=[...V].filter(([e])=>!p.get(e).milestone),q=new Map(w.flatMap((e,t)=>e.task?[[e.task.task.id,t]]:[])),F=w.slice(1).flatMap(e=>cD.map(t=>e.top+t)),I=w.slice(1).flatMap(e=>[...cD,...cR].map(t=>e.top+t)),E=e.tasks.flatMap((e,t)=>(e.dependsOn??[]).map((a,s)=>({from:a,to:e.id,taskIndex:t,order:s}))).toSorted((e,t)=>Math.abs(q.get(e.to)-q.get(e.from))-Math.abs(q.get(t.to)-q.get(t.from))||q.get(e.to)-q.get(t.to)||q.get(e.from)-q.get(t.from)||e.taskIndex-t.taskIndex||e.order-t.order),O=void 0===g?void 0:B(g+.5),U=void 0===O?[]:[{from:{x:O,y:0},to:{x:O,y:b}}],X=E.map(()=>void 0),T=[...U],Y=new Map,$=new Map,G=new Map,D=[],R=[],Z=new Set,j=new Set,N=new Map,W=new Set,J=Math.min(16e4,Math.max(12e3,6e3*E.length)),K={remaining:J},Q=Math.min(48e3,1500*E.length),ee={remaining:Q},et=0,ea=0,es=new Map;for(let{from:e,to:t}of E)es.set(e,(es.get(e)??new Set).add(q.get(t)>q.get(e)?1:3));let ei=(e,t)=>{let a=cq(t);T.push(...a),Z.add(a.at(-1)),j.add(a[0]),$.set(e.from,[...$.get(e.from)??[],...a]),G.set(e.to,[...G.get(e.to)??[],...a]);let s={box:cQ(t,!0),clearance:0};D.push({from:e.from,trunk:a[0],keepOut:{box:cQ(t),clearance:0},arrowhead:s}),R.push({from:e.from,trunk:a[0],keepOut:{box:cF(t,.01>Math.abs(t.at(-1).y-t.at(-2).y)?40:12,6),clearance:0},arrowhead:s}),N.set(e.to,N.get(e.to)-1),Y.set(e.to,[...Y.get(e.to)??[],t.at(-1)])},el=()=>{for(let e of(T.splice(0,T.length,...U),[Y,$,G,N]))e.clear();for(let e of(D.length=0,R.length=0,Z.clear(),j.clear(),E))N.set(e.to,(N.get(e.to)??0)+1);E.forEach((e,t)=>{let a=X[t];a&&ei(e,a)})};el();let eo=(e,t=K)=>{et+=1;let a=Math.min(12e3,t.remaining),s={remaining:a},i=V.get(e.from),l=V.get(e.to),o=p.get(e.from).milestone,r=p.get(e.to).milestone,n=q.get(e.to)>q.get(e.from),c=e=>(e.left+e.right)/2,d=Y.get(e.to)??[],h=function(e,t,a,s=[],i=!1){let l=(e.top+e.bottom)/2,o=e=>40*(1===e!==a),r=e=>4*(-1===e!==a);if(t){let t=(e.left+e.right)/2,a=(e.right-e.left)/4;return[{x:e.left,y:l,direction:0,cost:16*!!i},{x:t,y:e.top,direction:1,cost:2+o(1)},{x:t,y:e.bottom,direction:3,cost:2+o(3)},...[-1,1].map(t=>({x:e.left+a,y:l+t*a,direction:0,cost:i?r(t):16})),{x:t-a,y:e.top+a,direction:1,cost:16+o(1)},{x:t-a,y:e.bottom-a,direction:3,cost:16+o(3)}]}let n=cJ.filter(t=>e.left+t<=e.right-3),c=n.length?n.map(t=>e.left+t):[(e.left+e.right)/2],d=s.filter(t=>t>e.left+1&&t<e.right-1);return[{x:e.left,y:l,direction:0,cost:24*!!i},...[-1,1].map(t=>({x:e.left,y:l+7*t,direction:0,cost:i?r(t):24})),...d.flatMap(t=>[{x:t,y:e.top,direction:1,cost:o(1)},{x:t,y:e.bottom,direction:3,cost:o(3)}]),...c.map((t,a)=>({x:t,y:e.top,direction:1,cost:20+o(1)+3*a})),...c.map((t,a)=>({x:t,y:e.bottom,direction:3,cost:20+o(3)+3*a}))]}(l,r,n,o?[c(i)]:i.right-i.left>=8&&i.right+8<=l.left+cJ.at(-1)?[i.right+8]:[],(N.get(e.to)>1||d.length>0)&&(!r||W.has(e.to))),g=e=>void 0===O||(e.direction%2==0?O<e.x-16-5||O>e.x+5:Math.abs(e.x-O)>=5),u=(e,t)=>d.every(a=>Math.hypot(a.x-e.x,a.y-e.y)>=t),f=e=>{let t=cy(e.direction),a=cF([{x:e.x-(0===e.direction?t:0),y:e.y-(1===e.direction?t:3===e.direction?-t:0)},e],t,6);return!T.some(e=>c0(e,a))},m=[...es.get(e.to)??[]].flatMap(e=>cK(l,r,1===e).find(t=>t.direction===e)??[]),v=e=>{if(e.direction%2==0){let t=cQ([{x:e.x-16,y:e.y},e]);return m.every(e=>!c0({from:e,to:{x:e.x,y:e.y+(1===e.direction?1:-1)*8}},t))}return m.every(t=>t.direction!==(e.direction+2)%4||Math.abs(t.x-e.x)>=8)},y=function(e,t,a){let s=(e.top+e.bottom)/2,i=(e.left+e.right)/2,l=e=>40*(1===e!==a),o=(e,t)=>Array.from({length:Math.max(0,Math.floor((t-e)/3))+1},(t,a)=>e+3*a);if(t){let t=(e.right-e.left)/2,a=(e.bottom-e.top)/2,r=(e,l)=>s+l*a*(1-Math.abs(e-i)/t);return[...o(e.top+3,e.bottom-3).map(e=>({x:i-t*(1-Math.abs(e-s)/a),y:e,direction:0,cost:30})),...o(e.left+3,i).flatMap(e=>[{x:e,y:r(e,-1),direction:1,cost:40+l(1)},{x:e,y:r(e,1),direction:3,cost:40+l(3)}])]}return[...o(e.top+3,e.bottom-3).map(t=>({x:e.left,y:t,direction:0,cost:30+Math.abs(t-s)})),...o(e.left+3,e.right-3).flatMap(t=>[{x:t,y:e.top,direction:1,cost:40+l(1)+(t-e.left)/4},{x:t,y:e.bottom,direction:3,cost:40+l(3)+(t-e.left)/4}])]}(l,r,n),x=[[h,e=>g(e)&&u(e,11)&&f(e)&&v(e)],[h,e=>g(e)&&u(e,6)&&f(e)&&v(e)],[y,e=>g(e)&&u(e,3)&&f(e)&&v(e)],[h,e=>g(e)&&u(e,1)&&f(e)],[h,e=>u(e,1)&&f(e)],[y,e=>u(e,1)&&f(e)]].map(([e,t])=>e.filter(t)).find(e=>e.length>0)??h,k=($.get(e.from)??[]).filter(e=>j.has(e)),M=new Map(k.map(e=>{let t=function({from:e,to:t}){return .01>Math.abs(e.y-t.y)?t.x>e.x?0:2:t.y>e.y?1:3}(e),a=t%2==1&&1===t!==n;return[`${e.from.x},${e.from.y},${t}`,{...e.from,direction:t,cost:40*!!a}]})),C=[...[...V].flatMap(([t,a])=>{let s,i,l,o,r,n;return t!==e.from&&t!==e.to?[{box:a,clearance:4,sideClearance:8}]:p.get(t).milestone?[{box:(s=(a.right-a.left)/4,i=(a.bottom-a.top)/4,{left:a.left+s,right:a.right-s,top:a.top+i,bottom:a.bottom-i}),clearance:3,own:!0},...(l=(a.top+a.bottom)/2,o=(a.left+a.right)/2,r=(a.right-a.left)/8,n=(a.bottom-a.top)/8,[{left:a.left,right:a.right,top:l-n,bottom:l+n},{left:o-r,right:o+r,top:a.top,bottom:a.bottom}]).map(e=>({box:e,clearance:.5,own:!0})),...[{...a,bottom:a.top},{...a,top:a.bottom},{...a,right:a.left},{...a,left:a.right}].map(e=>({box:e,clearance:3,own:!0,parallel:!0}))]:[{box:a,clearance:3,own:!0}]}),...P],z={sources:[...M.values(),...o||i.right-i.left<8?[]:(r?[c(l)]:cJ.some(e=>l.left+e<=l.right-3)?cJ.filter(e=>l.left+e<=l.right-3).map(e=>l.left+e):[c(l)]).filter(e=>e-i.right>=3&&e-i.right<8).map(e=>({x:i.right,y:(i.top+i.bottom)/2,direction:0,cost:2,lead:e-i.right})),...cK(i,o,n,r?c(l):void 0,[...r?[l.left-19,l.left+(l.right-l.left)/4-19]:[l.left-19,...cJ.filter(e=>l.left+e<=l.right-3).map(e=>l.left+e)],...[...V].flatMap(([t,a])=>t===e.from||t===e.to?[]:[a.left-8,a.right+8])])],targets:x,obstacles:[...C,...R.map(t=>t.from===e.from?t.arrowhead:t.keepOut),...[...N.keys()].flatMap(t=>t===e.to?[]:(e=>{let t=N.get(e)??0;if(t<=0)return[];let a=V.get(e),s=(a.top+a.bottom)/2,i=(a.right-a.left)/4,l=p.get(e).milestone,o=l?[{x:a.left,y:s},{x:a.left+i,y:s-i},{x:a.left+i,y:s+i}]:[0,-7,7].map(e=>({x:a.left,y:s+e})),r=Y.get(e)??[],[n,...c]=o;return(t+r.length>1?[...c,n]:o).filter(e=>r.every(t=>Math.hypot(t.x-e.x,t.y-e.y)>=3)).slice(0,t).map(e=>({left:e.x-16-6,right:e.x+6*!!l,top:e.y-6,bottom:e.y+6}))})(t).map(e=>({box:e,clearance:0})))],behind:Math.min(i.left,l.left-16-8-5)-16,lanes:F,denseLanes:I,routed:T,kin:new Set([...$.get(e.from)??[],...G.get(e.to)??[]]),lastRuns:Z,trunks:new Set(k),pastTrunk:new Map(R.flatMap(t=>t.from===e.from?[[t.keepOut,t.trunk]]:[])),edges:H.flatMap(([t,a])=>t===e.from||t===e.to?[]:[a]),top:1,bottom:b-1,budget:s,kinkBudget:ee},_=cV(z)??cV({...z,obstacles:[...C,...D.map(t=>t.from===e.from?t.arrowhead:t.keepOut)],pastTrunk:new Map(D.flatMap(t=>t.from===e.from?[[t.keepOut,t.trunk]]:[]))});return t.remaining-=a-s.remaining,_||(ea+=1),_??function(e){let{source:t,target:a,routed:s}=e,i=e.heads.map(({box:e})=>e),l=s.filter(e=>.01>Math.abs(e.from.y-e.to.y)),o=s.filter(e=>Math.abs(e.from.y-e.to.y)>=.01),r=([t,a,s])=>{let r=.01>Math.abs(t.y-a.y),n=r?t.y:t.x,c=r?Math.min(t.x,a.x):Math.min(t.y,a.y),d=r?Math.max(t.x,a.x):Math.max(t.y,a.y),p=1/0;for(let t of r?l:o){if(s&&e.siblings.has(t))continue;let a=Math.abs((r?t.from.y:t.from.x)-n);if(a>=p)continue;let i=r?Math.min(t.from.x,t.to.x):Math.min(t.from.y,t.to.y);Math.min(d,r?Math.max(t.from.x,t.to.x):Math.max(t.from.y,t.to.y))-Math.max(c,i)>0&&(p=a)}let h=c3.findIndex(e=>p>=e);return i.some(e=>c0({from:t,to:a},e))?Math.max(h,3):h},n=(e,t,a=()=>!0)=>{let s;for(let i of e){let e=t(i).map(e=>r(e)),l=100*Math.max(...e,+!a(i))+e.reduce((e,t)=>e+t,0);if((!s||l<s.score)&&(s={candidate:i,score:l}),0===l)break}return s.candidate},c=(t.left+t.right)/2,d=(t.right-t.left)/2,p=a=>e.sourceMilestone?c5(c,d-4,.5).map(e=>({x:e,y:(1===a?t.bottom:t.top)-a*Math.abs(e-c)})):c5(Math.max(c,t.right-6),Math.min(2*d,12),.5).filter(e=>e>=t.left+.5&&e<=t.right-.5).map(e=>({x:e,y:1===a?t.bottom:t.top})),h=e=>[...c5(e,8),...c5(e,8,.5),...c5(e+.1,8,.1)],g=h(e.sourceRow.top+e.sourceRow.height).filter(a=>a>=t.bottom+2&&a<=e.rowsBottom-1),u=h(e.sourceRow.top).filter(a=>a<=t.top-2&&a>=e.rowsTop+1),[f,m]=n([...p(1).map(e=>[e,g]),...p(-1).map(e=>[e,u])].filter(([,e])=>e.length>0),([e,t])=>[[e,{x:e.x,y:t[0]},!0],[{x:e.x,y:t[0]},{x:12,y:t[0]}]]),v=n(m,e=>[[f,{x:f.x,y:e},!0],[{x:f.x,y:e},{x:12,y:e}]]),y=(a.top+a.bottom)/2,w=(a.bottom-a.top)/2,x=(a.right-a.left)/(a.bottom-a.top),b=n(c5(y,w-(e.targetMilestone?4:3)).map(t=>({x:e.targetMilestone?a.left+Math.abs(t-y)*x:a.left,y:t})),e=>[[{x:12,y:e.y},e]],t=>{let a=cF([{x:t.x-16,y:t.y},t],16,4.5);return e.taken.every(e=>Math.hypot(e.x-t.x,e.y-t.y)>=3)&&!s.some(e=>c0(e,a))}),k=n([...c5(12,10.5,.5),...c5(12.1,10.5,.1)],e=>[[{x:f.x,y:v},{x:e,y:v}],[{x:e,y:v},{x:e,y:b.y}],[{x:e,y:b.y},b]]);return[f,{x:f.x,y:v},{x:k,y:v},{x:k,y:b.y},b]}({source:i,sourceMilestone:o,sourceRow:w[q.get(e.from)],target:l,targetMilestone:r,rowsTop:0,rowsBottom:b,routed:T,heads:D.map(e=>e.keepOut),taken:d,siblings:new Set(k)})};E.forEach((e,t)=>{let a=eo(e);X[t]=a,ei(e,a)});let er=(e,t)=>({leaving:E[e].from===E[t].from,arriving:E[e].to===E[t].to}),en=e=>{let t=X[e],a=0;return X.forEach((s,i)=>{if(i===e||!s)return;let l=er(e,i);a+=c1(t,s,l)+c1(s,t,l)}),a},ec=new Map;E.forEach((e,t)=>ec.set(e.to,[...ec.get(e.to)??[],t]));let ed=e=>cq(e).reduce((e,{from:t,to:a})=>e+Math.abs(a.x-t.x)+Math.abs(a.y-t.y),0),ep=e=>{let t=cq(X[e]),a=0;return X.forEach((s,i)=>{if(i!==e&&s)for(let e of cq(s))for(let s of t)(function(e,t){let a=e=>.01>Math.abs(e.from.y-e.to.y);if(a(e)===a(t))return!1;let[s,i]=a(e)?[e,t]:[t,e],l=i.from.x,o=s.from.y;return l>Math.min(s.from.x,s.to.x)+.01&&l<Math.max(s.from.x,s.to.x)-.01&&o>Math.min(i.from.y,i.to.y)+.01&&o<Math.max(i.from.y,i.to.y)-.01})(s,e)&&(a+=1)}),a},eh=e=>({conflicts:e.reduce((e,t)=>e+en(t),0),drawn:e.reduce((e,t)=>{let a=X[t];return e+ed(a)+24*(a.length-2)+cH(a)+60*ep(t)},0)}),eg=(e,t)=>e.conflicts<t.conflicts||e.conflicts===t.conflicts&&e.drawn<t.drawn-1e-6,eu=e=>e.some(e=>en(e)>0||ep(e)>0)||e.reduce((e,t)=>{let a=X[t],[s,i]=[a[0],a.at(-1)];return e+ed(a)-Math.abs(i.x-s.x)-Math.abs(i.y-s.y)},0)>60;for(let[e,t]of ec){if(t.length<2||!eu(t))continue;let a=[{order:t.toReversed(),split:!1},...p.get(e).milestone?[{order:t,split:!0}]:[]],s={routes:t.map(e=>X[e]),standing:eh(t),split:!1};for(let i of a){if(K.remaining<=0||i.split&&(t.forEach((e,t)=>X[e]=s.routes[t]),!t.some(e=>ep(e)>0||cH(X[e])>0)))break;for(let e of t)X[e]=void 0;for(let t of(el(),i.split&&W.add(e),i.order)){let e=eo(E[t]);X[t]=e,ei(E[t],e)}W.delete(e);let a=eh(t);eg(a,s.standing)&&(s={routes:t.map(e=>X[e]),standing:a,split:i.split})}t.forEach((e,t)=>X[e]=s.routes[t]),s.split&&W.add(e),el()}let ef={remaining:48e3},em=0,ev=e=>{if(em>=2*E.length)return;em+=1;let t=X[e];X[e]=void 0,el();let a=eo(E[e],ef);return X[e]=t,el(),a},ey=(e,t)=>{let a,s=[e,t],i=eh(s);for(let e of s){let t=ev(e);if(!t)continue;let l=X[e];X[e]=t,el();let o=eh(s);o.conflicts<i.conflicts&&eg(o,i)&&(i=o,a={index:e,points:t}),X[e]=l,el()}return!!a&&(X[a.index]=a.points,ew[a.index]=ew[a.index]+1,el(),!0)},ew=E.map(()=>0),ex=new Set;for(let e=0;e<2;e+=1){let e=!1;if(X.forEach((t,a)=>{X.forEach((t,s)=>{let i=X[a];if(s===a||!i||!t||0===c1(i,t,er(a,s)))return;let l=`${a}.${ew[a]}:${s}.${ew[s]}`;!ex.has(l)&&(ex.add(l),ey(a,s)&&(e=!0))})}),!e)break}for(let e of E.map((e,t)=>({id:`gantt:dependency:${c2(e.from)}:${c2(e.to)}`,...e,points:X[t]})).map(e=>{let[t,...a]=(function(e){var t;let a,s,i=e.at(-1),l=e.at(-2),o=Math.abs(i.x-l.x)+Math.abs(i.y-l.y),r=(a=(t=e).at(-1),s=t.at(-2),.01>Math.abs(a.y-s.y)?16:12);if(o<=r+1)return[...e];let n=r/o;return[...e.slice(0,-1),{x:i.x+(l.x-i.x)*n,y:i.y+(l.y-i.y)*n},i]})(e.points).map(e=>({x:cN(e.x),y:cN(e.y)}));return{type:"arrow",id:e.id,edgeId:e.id,sourceNodeId:`gantt:task:${e.from}`,targetNodeId:`gantt:task:${e.to}`,points:[t,...a],strokeColor:"#5c5345",strokeWidth:1,roughness:0,endArrowhead:"triangle"}}))A.push(e,"front");let eb=e=>{let t="top"===e?"":"-bottom",a="top"===e?-22:b,s="top"===e?a-22:a+22;_.cells.forEach((e,s)=>{let i=cZ(e.label,12);A.text(`gantt:tick${t}:${s}`,i,(B(e.start)+B(e.end))/2-i.width/2,a+(22-i.height)/2,12,cT,"center")}),_.bands.forEach((e,a)=>{let i,l=B(e.end)-B(e.start)-8,o=((i=/^([A-Z][a-z]{2}) \d{4}$/u.exec(e.label))?[e.label,i[1]]:/^\d{4}$/u.test(e.label)?[e.label,`’${e.label.slice(2)}`]:[e.label]).map(e=>cZ(e,13)).find(e=>e.width<=l);o&&A.text(`gantt:band${t}:${a}`,o,(B(e.start)+B(e.end))/2-o.width/2,s+(22-o.height)/2,13,cX,"center"),a>0&&A.line(`gantt:band-edge${t}:${a}`,[{x:B(e.start),y:s+3},{x:B(e.start),y:s+22-3}],{strokeColor:cY})}),A.line(`gantt:axis${t}`,[{x:B(_.start),y:"top"===e?0:b},{x:S,y:"top"===e?0:b}],{strokeColor:"#8c826f"})},ek=(d=A.elements.length,eb("top"),A.elements.length-d),eM=-44;if(void 0!==O){let e=cZ(v.today??"Today",12);eM-=18,A.text("gantt:today-label",e,Math.min(Math.max(O-e.width/2,B(_.start)),Math.max(B(_.start),S-e.width)),eM+(18-e.height)/2,12,c$,"center")}let eC=cj(e.title,Math.max(S-z,360),20);A.text("gantt:title",eC,z,eM-14-eC.height,20,cX,"left");let ez=new Set([_.start,_.end,..._.bands.map(e=>e.start)]),e_=[..._.cells.map(e=>e.start),_.end],eL=k>=16,eB=[!0,!1].flatMap(e=>[{grid:e_,minor:!0,bottom:eL},{grid:e_,minor:!1,bottom:eL},{grid:e_,minor:!1,bottom:!1},{grid:e_.filter(e=>ez.has(e)),minor:!1,bottom:eL},{grid:e_.filter(e=>ez.has(e)),minor:!1,bottom:!1},{grid:[_.start,_.end],minor:!1,bottom:!1}].map(t=>({...t,rowRules:e}))),eS=e=>{let t=e.bottom?b+22:b,a=(e,t,a,s,i)=>({type:"line",id:e,points:[{x:cN(t),y:cN(a)},{x:cN(t),y:cN(s)}],roughness:0,strokeWidth:1,...i});return[...e.rowRules?[...w.slice(1).map(e=>e.top),b].map((e,t)=>({type:"line",id:`gantt:row-rule:${t}`,points:[{x:cN(z),y:cN(e)},{x:cN(S),y:cN(e)}],roughness:0,strokeWidth:1,strokeColor:"#ebe4d8"})):[],...e.minor?_.minor.map(e=>a(`gantt:minor:${tl(e)}`,B(e),0,b,{strokeColor:"#f0ebe1"})):[],...e.grid.map(e=>a(`gantt:grid:${tl(e)}`,B(e),-22,t,{strokeColor:ez.has(e)?cY:"#e6dfd2"})),...void 0===O?[]:[a("gantt:today",O,eM+18,t,{strokeColor:c$,strokeStyle:"dashed"})]]},eA=[...V.values()].map(e=>({left:e.left-5,right:e.right+5,top:e.top-1,bottom:e.bottom+1})),eP=e=>e?[...A.textBoxes,...eA]:A.textBoxes,eV=e=>"gantt:today"===e,[eH,eq]=[!0,!1].flatMap(e=>eB.map(t=>[t,e])).find(([e,t])=>{let a=eS(e),s=new Map([...nj(a,A.textBoxes,e=>!eV(e)),...nj(a,eP(t),eV)]),i=a.reduce((e,t)=>e+(s.get(t.id)?.length??1),0);return A.elements.length+i+(e.bottom?ek:0)<=aU.maxElements})??[eB.at(-1),!1];for(let e of(eH.bottom&&eb("bottom"),eS(eH)))A.push(e,"gantt:today"===e.id?"middle":"back");A.breakRulesUnderText(e=>e.startsWith("gantt:grid:")||e.startsWith("gantt:minor:")||e.startsWith("gantt:row-rule:")||e.startsWith("gantt:axis")||e.startsWith("gantt:band-edge")),A.breakRulesUnderText(eV,eP(eq));let eF=A.bounds(),eI=40-eF.left,eE=40-eF.top,eO=e=>({x:cN(e.x+eI),y:cN(e.y+eE)}),eU=A.elements.map(e=>{if("line"===e.type){let[t,a,...s]=e.points.map(eO);return{...e,points:[t,a,...s]}}if("arrow"===e.type){let[t,...a]=e.points.map(eO);return{...e,points:[t,...a]}}return{...e,x:cN(e.x+eI),y:cN(e.y+eE)}});return{scene:{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:Math.ceil(eF.right-eF.left+80),height:Math.ceil(eF.bottom-eF.top+80),accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:eU,layers:[],layouts:[],zOrder:A.zOrder()},work:{layouts:1,placements:et,expansions:J-K.remaining+48e3-ef.remaining+Q-ee.remaining,corridors:ea,conflicts:X.reduce((e,t,a)=>e+X.reduce((e,s,i)=>i===a?e:e+c1(t,s,er(a,i),!0),0),0)}}}let c6="timeline-marker",c7=6,c8="#4c4639",c9="#c0392b",de=[{stroke:"",ink:"#6a4e5c",wash:"#efe6ec"},{stroke:"#1f44c9",ink:"#1a39a8",wash:"#e6eafb"},{stroke:"#1c7a4d",ink:"#15613c",wash:"#def0e5"},{stroke:"#9a6a1f",ink:"#7a5216",wash:"#f6e8cf"}];function dt(e,t,a,s){let i=function(e,t){let a=e=>e.split("\n").length,s=aO(e,200,t);if(1===a(s))return s;let i=t,l=200;for(;l-i>1;){let o=Math.floor((i+l)/2);a(aO(e,o,t))<=a(s)?l=o:i=o}return aO(e,l,t)}(t,a);return{id:e,text:i,fontSize:a,color:s,width:Math.ceil(Math.max(aq(i,a),aF(i,a,200))),height:Math.ceil(i.split("\n").length*a*1.35)}}let da=[{lookahead:!0,coverPenalty:0},{lookahead:!0,coverPenalty:80},{lookahead:!1,coverPenalty:0},{lookahead:!1,coverPenalty:240}];function ds(e){return e.span?6:("milestone"===e.event.kind?18:12)/2}let di=[{fontSize:20,textWidth:160,padX:0,padY:0,strokeWidth:2},{fontSize:16,textWidth:180,padX:16,padY:11,strokeWidth:2},{fontSize:14,textWidth:150,padX:12,padY:9,strokeWidth:1}];function dl(e){return di[Math.min(e,di.length-1)]}function dr(e,t,a){return{x0:e.x0+t,x1:e.x1+t,y0:e.y0+a,y1:e.y1+a}}function dn(e,t,a){return{boxes:e,places:t,folded:a,top:Math.min(...e.map(e=>e.y0)),bottom:Math.max(...e.map(e=>e.y1)),outer:Math.max(...e.map(e=>e.x1))}}function dc(e,t){return 1===e.places.size&&1===t.places.size?14:28}function dd(e,t=0){return e.reduce((a,s,i)=>a+(s.bottom-s.top)+(0===i?0:dc(e[i-1],s)+t),0)}function dp(e){let t=e.flatMap(e=>[e.x,e.x+e.topic.width]),a=e.flatMap(e=>[e.y,e.y+e.topic.height]);return(Math.max(...t)-Math.min(...t)+40)/(Math.max(...a)-Math.min(...a)+40)}function dh(e){return Math.round(100*e)/100}function dg(e){let[t,,,a]=e;return .5>Math.abs(a.y-t.y)?[{x:dh(t.x),y:dh(t.y)},{x:dh(a.x),y:dh(a.y)}]:aL(e)}function du(e,t){return{x:1===t?e.x:e.x+e.width,y:e.y+e.height/2}}let df={circle:24,bucket:28,cylinder:28,diamond:20,document:28,ellipse:24,pipe:28,polygon:28,rectangle:28},dm={database:"cylinder",queue:"pipe",document:"document",storage:"bucket"},dv={initial:20,final:28};function dy(e,t){let a=Math.max(e.width,e.height,t);return{...e,width:a,height:a}}function dw(e){return void 0===e.kind?void 0:dv[e.kind]}function dx(e){return"decision"===e||"choice"===e}function db(e,t=184,a=1116){let s,i,l,o,r,n,c=function(e){if(void 0!==e.shape)return dm[e.shape];let t=e.kind?.toLowerCase();return"start"===t||"end"===t?"ellipse":"initial"===t||"final"===t?"circle":dx(t)?"diamond":"rectangle"}(e),d=dw(e);if(void 0!==d||"choice"===e.kind&&!e.label){let t=d??44;return{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},shape:c,x:0,y:0,width:t,height:t,label:""}}let p=(i=(s=aE(e.label,"diamond"===c?744:a)).split("\n"),l=aq(s,14),o=Math.ceil(14*i.length*1.35),r=Math.ceil(l+36),n=Math.ceil(o+28),{text:s,textHeight:o,textWidth:l,width:r,height:n}),h=e.icon?{slug:e.icon.slug,size:df[c]}:void 0,g=aY(c)?a$[c]:0,u="diamond"===c?32:"ellipse"===c?20:"pipe"===c?4*g:0,f="diamond"===c?32:"cylinder"===c||"document"===c||"bucket"===c?3*g:0,m=h||"diamond"===c||g>0?function(e,t,a){let s=2*aX.boundTextPadding,i=t.textHeight+a6(a),l="diamond"===e?2:"ellipse"===e||"circle"===e?Math.SQRT2:1,o=Math.ceil((t.textWidth+s)*l),r=Math.ceil((i+s)*l);for(;a4({height:r,shape:e,width:o}).width<t.textWidth;)o+=1;for(;a4({height:r,shape:e,width:o}).height<i;)r+=1;return{width:o,height:r}}(c,p,h):{height:0,width:0},[v,y]="state"===e.kind?[136,56]:[t,72];return{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},...h?{icon:h}:{},shape:c,x:0,y:0,width:Math.max(v,p.width+u,m.width),height:h?Math.max(y,m.height):Math.max(y,p.height+f,m.height),label:p.text}}function dk(e){let t=new Map,a=new Map;for(let s of e)t.set(s.target,[...t.get(s.target)??[],s]),a.set(s.source,[...a.get(s.source)??[],s]);return{incoming:t,outgoing:a}}function dM(e){return new Map(e.map((e,t)=>[e.id,t]))}function dC(e,t,a){let s=new Map,i=new Set;function l(e){for(let t of(s.set(e,"visiting"),a.get(e)??[])){let e=s.get(t.target);if("visiting"===e){i.add(t.id);continue}e||l(t.target)}s.set(e,"visited")}let o=e.nodes.find(e=>0===(t.get(e.id)??[]).length)??e.nodes[0];for(let t of(o&&l(o.id),e.nodes))s.has(t.id)||l(t.id);return i}let dz=new WeakMap;function d_(e){let t=dz.get(e);if(t||(dq(e),t=dz.get(e)))return t;let a=dk(e.edges);return t=dC(e,a.incoming,a.outgoing),dz.set(e,t),t}let dL=new WeakMap,dB="\0group:",dS=sO.fontSize;function dA(e,t){let a=[];for(let s=t;void 0!==s;s=e.parentOf.get(s))a.push(s);return a}function dP(e,t,a){let s=new Set(dA(e,e.groupOf.get(a)));return dA(e,e.groupOf.get(t)).find(e=>s.has(e))}let dV=new WeakMap;function dH(e){return`${dB}${e}`}function dq(e){let t=dV.get(e);if(void 0!==t)return t??void 0;let a=new Map((e.groups??[]).flatMap(e=>void 0===e.parent?[]:[[e.id,e.parent]])),s=new Set;for(let t of e.nodes)for(let e=t.group;void 0!==e&&!s.has(e);e=a.get(e))s.add(e);let i=(e.groups??[]).filter(e=>s.has(e.id));if(0===i.length)return void dV.set(e,null);let l=new Set(i.map(e=>e.id)),o=new Map([...a].filter(([e,t])=>l.has(e)&&l.has(t))),r=i.some(e=>void 0!==e.parent||void 0!==e.kind),n=new Map(e.nodes.flatMap(e=>void 0!==e.group&&l.has(e.group)?[[e.id,e.group]]:[])),c=new Set(e.nodes.map(e=>e.id)),d=new Set(e.edges.flatMap(e=>[e.source,e.target].filter(e=>!c.has(e)&&l.has(e)))),p=e=>{let t=[];for(let a=d.has(e)?e:n.get(e);void 0!==a;a=o.get(a))t.push(a);return t},h=(e,t)=>{let a=p(t),s=void 0===e?a.length:a.indexOf(e);if(!(s<0||0===s&&d.has(t)))return 0===s?t:dH(a[s-1])},g=(e,t)=>({id:t,label:e.label,kind:"process",metadata:{}}),u=dk(e.edges),f=dC(e,u.incoming,u.outgoing),m=new Set(e.edges.flatMap(e=>e.source===e.target?[e.id]:[])),v=i.map(t=>{let a=i.filter(e=>o.get(e.id)===t.id),s=e.edges.flatMap(e=>{let[a,s]=[h(t.id,e.source),h(t.id,e.target)];return void 0===a||void 0===s||a===s&&a!==e.source?[]:[a===e.source&&s===e.target?e:{...e,source:a,target:s}]}),l=[];for(let s of e.nodes){let e=h(t.id,s.id);if(void 0===e||l.some(t=>t.id===e))continue;let i=a.find(t=>dH(t.id)===e);l.push(i?g(i,e):s)}let n={...e,groups:[],nodes:l,edges:s},c={...n,layout:{...e.layout,direction:dY[e.layout.direction]}},d=new Set(s.flatMap(e=>f.has(e.id)?[e.id]:[]));if(a.length>0){let e={...n,edges:s.filter(e=>!d.has(e.id))},t=dk(e.edges);for(let a of dC(e,t.incoming,t.outgoing))d.add(a)}for(let e of(dz.set(n,d),dz.set(c,d),d))m.add(e);if(r){let a=function(e,t,a,s){let i=e=>void 0!==s(e),l=new Map;for(let t of e.edges)i(t.source)||i(t.target)||l.set(t.source,[...l.get(t.source)??[],t.target]);let o=e=>{let t=new Set([e]);for(let e of t)for(let a of l.get(e)??[])t.add(a);return t},r=new Map;for(let e of t.edges)a.has(e.id)||r.set(e.source,[...r.get(e.source)??[],e.target]);let n=(e,t)=>{let a=new Set([e]);for(let e of a)for(let t of r.get(e)??[])a.add(t);return a.has(t)},c=[];for(let t of e.edges){if(!i(t.source)||i(t.target))continue;let a=o(t.target);for(let l of e.edges){if(i(l.source)||!i(l.target)||!a.has(l.source))continue;let[e,o]=[s(t.source),s(l.target)];!(e===o||c.some(([t,a])=>t===e&&a===o))&&(n(o,e)||(c.push([e,o]),r.set(e,[...r.get(e)??[],o])))}}return c}(e,n,d,e=>h(t.id,e));a.length>0&&(dL.set(n,a),dL.set(c,a))}let p=new Set(e.edges.flatMap(e=>{let[a,s]=[h(t.id,e.source),h(t.id,e.target)];return void 0===a&&void 0!==s?[s]:void 0===s&&void 0!==a?[a]:[]}));return{across:c,children:a.map(e=>e.id),crossing:p,diagram:n,group:t}}),y=[],w=new Set;for(let t of e.nodes){let e=h(void 0,t.id);if(w.has(e))continue;w.add(e);let a=p(t.id).at(-1);y.push(void 0===a?t:g(i.find(e=>e.id===a),e))}let x=e=>h(void 0,e)??e,b=e.edges.filter(e=>x(e.source)!==x(e.target)),k={...e,groups:[],nodes:y,edges:b.map(e=>({...e,source:x(e.source),target:x(e.target)}))},M=dk(k.edges),C=dC(k,M.incoming,M.outgoing);for(let e of(dz.set(k,C),C))m.add(e);dz.set(e,m);let z={composites:d,crossEdges:b,groupOf:n,groups:v,parentOf:o,top:k,zoned:r};return dV.set(e,z),z}function dF(e,t,a){let s=dM(e.nodes),i=new Map(e.nodes.map(e=>[e.id,0])),l=new Map(e.nodes.map(e=>[e.id,0]));for(let t of e.edges)a.has(t.id)||i.set(t.target,(i.get(t.target)??0)+1);let o=[];for(let t of e.nodes)(i.get(t.id)??0)===0&&o.push(t.id);let r=new Set;for(let e=0;e<o.length;e+=1){let n=o[e];if(!n||r.has(n))continue;r.add(n);let c=l.get(n)??0;for(let r of t.outgoing.get(n)??[]){if(a.has(r.id))continue;l.set(r.target,Math.max(l.get(r.target)??0,c+1));let t=(i.get(r.target)??0)-1;i.set(r.target,t),0===t&&function(e,t,a,s){let i=a.get(t)??Number.MAX_SAFE_INTEGER,l=e.findIndex((e,t)=>t>s&&(a.get(e)??Number.MAX_SAFE_INTEGER)>i);-1===l?e.push(t):e.splice(l,0,t)}(o,r.target,s,e)}}for(let s of e.nodes)!function e(s){if(r.has(s))return l.get(s)??0;let i=0;for(let l of t.incoming.get(s)??[])a.has(l.id)||(i=Math.max(i,e(l.source)+1));return r.add(s),l.set(s,i),i}(s.id);return l}let dI=new WeakMap,dE={TB:"bottom",BT:"top",LR:"right",RL:"left"};function dO(e,t,a,s,i=184,l=1116){return new Map(e.nodes.map(e=>{let o=db(e,i,l),r=t.get(e.id),n={...o,width:Math.max(o.width,r?.width??0),height:Math.max(o.height,r?.height??0)},c=(a.outgoing.get(e.id)??[]).filter(t=>t.target!==e.id),d=(a.incoming.get(e.id)??[]).filter(t=>t.source!==e.id).length+c.length,p=!dx(e.kind)&&c.length>1&&c.some(e=>e.label)?Math.max(18,...c.map(e=>{let t=p0(e.label??"");return(s?t.width:t.height)+24})):18,h=c.filter(e=>e.label),g=void 0!==dw(e)?0:"state"===e.kind?32+h.reduce((e,t)=>{let a=p0(t.label);return e+(s?a.width:a.height)+24},0)+Math.max(0,d-h.length-1)*pf:32+Math.max(0,d-1)*p;return[e.id,"choice"!==e.kind||e.label?{...n,...s?{width:Math.max(n.width,g)}:{height:Math.max(n.height,g)}}:dy(n,g)]}))}function dU(e,t,a,s=!1){let i="TB"===e.layout.direction||"BT"===e.layout.direction,[l,o]=i?["left","right"]:["top","bottom"],r=(e,t)=>Math.max(112,(a.get(pc(e.nodeId,o))??0)+(a.get(pc(t.nodeId,l))??0)+18),n=dk(e.edges),c=dO(e,t,n,i),d=d_(e),p=function(e,t,a){let s=dL.get(e);if(!s)return t;for(let i=!0,l=0;i&&l<=e.nodes.length;l+=1){for(let[e,a]of(i=!1,s))t.get(a)<t.get(e)&&(t.set(a,t.get(e)),i=!0);for(let s of e.edges)!a.has(s.id)&&s.source!==s.target&&t.get(s.target)<t.get(s.source)+1&&(t.set(s.target,t.get(s.source)+1),i=!0)}return t}(e,dF(e,n,d),d),h=Array.from((function(e,t,a,s,i,l=!1){var o,r,n,c;let d,p,h=dM(e.nodes),g=new Map;for(let s of e.nodes){let e=a.get(s.id)??0,i=t.get(s.id);i&&g.set(e,[...g.get(e)??[],i])}for(let e=0;e<4;e+=1)for(let e of Array.from(g.keys()).sort((e,t)=>e-t)){let t=g.get(e);if(!t||t.length<2)continue;let a=new Map;(g.get(e-1)??[]).forEach((e,t)=>{a.set(e.nodeId,t)});let l=new Map;(g.get(e+1)??[]).forEach((e,t)=>{l.set(e.nodeId,t)});let o=e=>{let t=[...(s.incoming.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>a.get(e.source)).filter(e=>void 0!==e),...(s.outgoing.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>l.get(e.target)).filter(e=>void 0!==e)];return 0===t.length?h.get(e.nodeId)??Number.MAX_SAFE_INTEGER:t.reduce((e,t)=>e+t,0)/t.length};g.set(e,[...t].sort((e,t)=>{let a=o(e)-o(t);return Math.abs(a)>.001?a:(h.get(e.nodeId)??Number.MAX_SAFE_INTEGER)-(h.get(t.nodeId)??Number.MAX_SAFE_INTEGER)}))}return l?(o=g,r=e,n=a,c=i,(d=dI.get(r))||(d=function(e,t,a,s){let i=new Map,l=new Set,o=(e,t,a)=>i.set(a,[...i.get(a)??[],[e,t]]);for(let i of t.edges){let[t,r]=s.has(i.id)?[i.target,i.source]:[i.source,i.target],[n,c]=(a.get(t)??0)<=(a.get(r)??0)?[t,r]:[r,t],d=a.get(n)??0,p=a.get(c)??0;if(d===p)continue;let h=n;for(let t=d+1;t<p;t+=1){let a=`\0${i.id}\0${t}`;l.add(a);let s=e.get(t-1),r=e.get(t);r.splice(Math.round((s.indexOf(h)+.5)/s.length*r.length),0,a),o(h,a,t-1),h=a}o(h,c,p-1)}let r=new Map,n=t=>e.get(t)?.forEach((e,t)=>r.set(e,t)),c=[...e.keys()].sort((e,t)=>e-t);c.forEach(n);let d=e=>{let t=i.get(e)??[],a=0;for(let[e,[s,i]]of t.entries())for(let[l,o]of t.slice(e+1))(r.get(s)-r.get(l))*(r.get(i)-r.get(o))<0&&(a+=1);return a},p=()=>c.reduce((e,t)=>e+d(t),0),h=p(),g=()=>new Map([...e].map(([e,t])=>[e,t.filter(e=>!l.has(e))])),u=g();if(0===h)return u;let f=new Map;for(let e of i.values())for(let[t,a]of e){let e=f.get(t)??{above:[],below:[]};e.below.push(a),f.set(t,e);let s=f.get(a)??{above:[],below:[]};s.above.push(t),f.set(a,s)}let m={crossings:h,order:u};for(let t=0;t<8&&m.crossings>0;t+=1){let a=t%2==0;for(let t of a?c.slice(1):c.slice(0,-1).reverse()){let s=e.get(t),i=new Map(s.map((e,t)=>{let s=(a?f.get(e)?.above:f.get(e)?.below)??[];return[e,s.length>0?s.reduce((e,t)=>e+r.get(t),0)/s.length:t]}));s.sort((e,t)=>i.get(e)-i.get(t)),n(t)}for(let t=!0;t;)for(let a of(t=!1,c)){let s=e.get(a);for(let e=0;e+1<s.length;e+=1){let i=d(a-1)+d(a);[s[e],s[e+1]]=[s[e+1],s[e]],n(a),d(a-1)+d(a)<i?t=!0:([s[e],s[e+1]]=[s[e+1],s[e]],n(a))}}let s=p();s<m.crossings&&(m={crossings:s,order:g()})}return m.order}(new Map([...o].map(([e,t])=>[e,t.map(e=>e.nodeId)])),r,n,c),dI.set(r,d)),p=new Map([...o.values()].flat().map(e=>[e.nodeId,e])),new Map([...o.keys()].map(e=>[e,(d.get(e)??[]).flatMap(e=>p.has(e)?[p.get(e)]:[])]))):g})(e,c,p,n,d,s).entries()).sort(([e],[t])=>e-t).map(([e,t])=>({breadth:t.reduce((e,a,s)=>e+(i?a.width:a.height)+(s>0?r(t[s-1],a):0),0),depth:Math.max(...t.map(e=>i?e.height:e.width)),rank:e,shapes:t})),g=dE[e.layout.direction],u=(e,t)=>Math.max(0,...e.map(e=>a.get(pc(e.nodeId,t))??0));return{feedbackEdges:d,gapAfter:h.map((t,s)=>{let l=i?0:Math.max(0,...e.edges.filter(e=>t.shapes.some(t=>t.nodeId===e.source)&&e.label&&e.source!==e.target).map(e=>p0(e.label,dx(c.get(e.source)?.kind)).width+16+72)),o=h[s+1];return Math.max(96,l,o&&a.size>0?u(t.shapes,g)+u(o.shapes,pm[g])+18:0)}),gapBetween:r,highSide:o,lowSide:l,rankByNodeId:p,rankMetrics:h,reachOf:u,vertical:i}}let dX={bandOf:new Map,continuations:new Set},dT={crossingRepair:!1,reorder:!1,wrap:dX},dY={TB:"LR",BT:"LR",LR:"TB",RL:"TB"};function d$(e,t){let[a,s]=e>t?[e,t]:[t,e];return(a+40)/(s+40)}function dG(e,t,a=0,s){let i;if("orthogonal"!==e.layout.edgeRouting||dq(e)||dW(e))return dX;let{feedbackEdges:l,gapAfter:o,rankByNodeId:r,rankMetrics:n}=dU(e,s?.sizes??new Map,new Map,t),c="TB"===e.layout.direction||"BT"===e.layout.direction,d=(e,t)=>n.slice(e,t+1).reduce((e,t)=>e+t.depth,0)+o.slice(e,t).reduce((e,t)=>e+t,0),p=(e,t)=>Math.max(...n.slice(e,t+1).map(e=>e.breadth)),h=n.length-1,g=d$(d(0,h),p(0,h)),u=e=>Math.max(...n[e].shapes.map(e=>s?.weights.get(e.nodeId)??1)),f=(e,t)=>{let a=0;for(let s=e;s<=t;s+=1)a+=u(s);return a};if(5>f(0,h)||d(0,h)<=p(0,h))return dX;let m=new Map(e.nodes.map(e=>[e.id,e.kind])),v=e=>r.get(e)??0,y=new Map;for(let[t,a]of n.entries()){let i=e.edges.filter(e=>Math.min(v(e.source),v(e.target))<=a.rank&&Math.max(v(e.source),v(e.target))>a.rank),[o]=i;(s?i.length>=1:1===i.length)&&o&&i.every(e=>!l.has(e.id)&&v(e.source)===a.rank&&v(e.target)===a.rank+1&&!dx(m.get(e.source)))&&y.set(t,o.id)}let w=new Map(e.edges.map(e=>[e.id,e.label])),x=(e,t)=>{let a=w.get(y.get(t)??""),s=a?p0(a):void 0,i=t===h?0:Math.max(36,s?c?Math.max(40,s.height+24):s.width+16:0);return d(e,t)+36*(e>0)+i},b=[...y.keys(),h].sort((e,t)=>e-t),k=s?1:2,M=e=>{let t,s=(i,l)=>{if(i.length===e-1){if(f(l+1,h)<k)return;let e=[...i,h],s=e.map((t,a)=>x(0===a?0:e[a-1]+1,t)),o=Math.max(...s);if(Math.min(...s)<a*o)return;let r=s.reduce((e,t)=>e+t**2,0);(!t||o<t.longest||o===t.longest&&r<t.squares)&&(t={ends:e,longest:o,squares:r});return}for(let e of b)e!==h&&e>l&&f(l+1,e)>=k&&s([...i,e],e)};return s([],-1),t},[C,z]=s?[s.bands,Math.min(s.bands,b.length)]:[2,Math.min(6,b.length)];for(let e=C;e<=z;e+=1){let t=new Map;for(let e of b)f(0,e)>=k&&e<h&&t.set(e,{ends:[e],longest:x(0,e),squares:x(0,e)**2});for(let a=2;a<=e;a+=1){let s=new Map;for(let i of b)if(a===e?i===h:i!==h)for(let[e,a]of[...t].reverse()){if(i<=e||f(e+1,i)<k)continue;let t=x(e+1,i),l={ends:[...a.ends,i],longest:Math.max(a.longest,t),squares:a.squares+t**2},o=s.get(i);(!o||l.longest<o.longest||l.longest===o.longest&&l.squares<o.squares)&&s.set(i,l)}t=s}let s=a>0?M(e):t.get(h);if(!s)continue;let l=[0,...s.ends.slice(0,-1).map(e=>e+1)].reduce((e,t,a)=>e+p(t,s.ends[a]),0)+(e-1)*144,o=d$(s.longest,l);if((!i||o<i.aspect)&&(i={aspect:o,ends:s.ends}),o<=2)break}if(!i||i.aspect>=g)return dX;let _=new Map,L=0;for(let[e,t]of n.entries()){for(let e of t.shapes)_.set(e.nodeId,L);i.ends.includes(e)&&e!==h&&(L+=1)}return{bandOf:_,continuations:new Set(i.ends.filter(e=>e!==h).map(e=>y.get(e))),...s?{under:!0}:{}}}function dD(e,t=new Map,a=new Map,{reorder:s,wrap:i}=dT,l=new Map){let{gapAfter:o,gapBetween:r,highSide:n,lowSide:c,rankMetrics:d,reachOf:p,vertical:h}=dU(e,t,a,s),g=[];for(let[e,t]of d.entries()){let a=i.bandOf.get(t.shapes[0].nodeId)??0;(g[a]??=[]).push({index:e,metric:t})}let u=[],f=i.under?function(e,t,a,s){let i=new Map,l=t.map(e=>{let t=0;for(let{index:s,metric:l}of e){for(let e of l.shapes)i.set(e.nodeId,t+l.depth);t+=l.depth+a[s]}return t-a[e.at(-1).index]}),o=Math.max(...l),r=[0];for(let a=1;a<t.length;a+=1){let t=e.edges.flatMap(e=>s.get(e.source)===a-1&&s.get(e.target)===a?[i.get(e.source)+r[a-1]-l[a]]:[]);r.push(Math.max(0,Math.min(Math.max(0,...t),o-l[a])))}return r}(e,g,o,i.bandOf):[],m=48;for(let[e,t]of g.entries()){let a=Math.max(...t.map(({metric:e})=>e.breadth)),s=48+(f[e]??0);for(let{index:e,metric:i}of t){let[t]=1===i.shapes.length?i.shapes:[],n=m+Math.max(0,a-i.breadth)/2-(t?l.get(t.nodeId)??0:0);for(let[e,t]of i.shapes.entries()){let a=i.shapes[e+1];h?(u.push({...t,x:n,y:s+Math.max(0,i.depth-t.height)/2}),n+=t.width):(u.push({...t,x:s+Math.max(0,i.depth-t.width)/2,y:n}),n+=t.height),a&&(n+=r(t,a))}s+=i.depth+o[e]}let i=g[e+1];i&&(m+=a+Math.max(144,p(t.flatMap(({metric:e})=>e.shapes),n)+p(i.flatMap(({metric:e})=>e.shapes),c)+72))}if("BT"===e.layout.direction){let e=Math.max(...u.map(e=>e.y+e.height));return u.map(t=>({...t,y:48+e-t.y-t.height}))}if("RL"===e.layout.direction){let e=Math.max(...u.map(e=>e.x+e.width));return u.map(t=>({...t,x:48+e-t.x-t.width}))}return u}function dR(e,t=new Map,a=new Map,s=dT,i=new Map){if(dW(e))return function(e,t,a,s=dX){let i=e.lanes,{direction:l}=e.layout,{along:o,across:r,backSide:n,breadth:c,columnCount:d,columnOf:p,columns:h,content:g,depth:u,depthOf:f,forwardSide:m,gapAfter:v,headerSize:y,laneIndex:w,laneOf:x,offset:b,padding:k,poolBreadth:M,reach:C,shapes:z,vertical:_,wrapped:L}=dJ(e,t,a),B=p.map(e=>s.bandOf.get(e[0]?.nodeId??"")??0),S=Math.max(0,...B)+1,A=Array.from({length:S},(e,t)=>t),P=Math.max(48,...A.map(e=>C(p[B.indexOf(e)]??[],n)+dN)),V=Math.max(48,...A.map(e=>C(p[B.lastIndexOf(e)]??[],m)+dN)),H="RL"===l||"BT"===l,[q,F]=H?[V,P]:[P,V],I=48+y+q,E=[],O=I,U=0;for(let[e,t]of u.entries())e>0&&B[e]!==B[e-1]&&(O=I),E.push(O),O+=t,U=Math.max(U,O-I),e<d-1&&B[e+1]===B[e]&&(O+=v[e]);let X=I+U,T=X+F,Y=A.map(t=>[...s.continuations].filter(a=>{let i=e.edges.find(e=>e.id===a);return void 0!==i&&s.bandOf.get(i.source)===t})),$=[];for(let e of(O=48,A))$.push(O),O+=M+dK(Y[e].length);let G=(e,t)=>$[e]+c.slice(0,t).reduce((e,t)=>e+t,0),D=e.nodes.map(e=>{let t=z.get(e.id),a=w.get(e.lane),s=h.get(e.id),i=E[s]+(u[s]-t[f])/2,l=H?I+X-i-t[f]:i,n=G(B[s],a)+k[a].low+(c[a]-k[a].low-k[a].high-g[a])/2+b.get(e.id);return{...t,[o]:l,[r]:n}}),R=(e,t,a,s)=>_?{x:a,y:e,width:s,height:t}:{x:e,y:a,width:t,height:s},Z=function(e,t,a){let s=new Map;for(let i of e){let e=`lane:${encodeURIComponent(i.id)}`,l=e=>Array.from({length:t},(t,a)=>0===a?e:`${e}:${a+1}`).some(e=>a.has(e)||a.has(`${e}:header`)),o=e;for(let t=1;l(o);t+=1)o=`${e}@${t}`;s.set(i.id,o)}return s}(i,S,new Set(e.nodes.map(e=>e.id))),j=A.flatMap(e=>i.map((t,a)=>({box:R(48,T-48,G(e,a),c[a]),elementId:0===e?Z.get(t.id):`${Z.get(t.id)}:${e+1}`,header:R(48,y,G(e,a),c[a]),id:t.id,label:t.label,pool:e,text:L[a].text}))),N=A.map(e=>R(48,T-48,$[e],M));return{lanes:{continuations:s.continuations,frames:j,laneOf:x,pool:dZ(N),pools:N,vertical:_},nodes:D}}(e,t,a,s.wrap);let l=dq(e);return l?function(e,t,a,s,i,l){let o="TB"===e.layout.direction||"BT"===e.layout.direction,{zoned:r}=t,n=28*!r,c=new Map(a),d=new Map(s),p=new Map(t.groups.map(e=>[e.group.id,e])),h=new Map,g=new Map,u=i.groupsAcross&&!r?new Set(t.groups.map(e=>e.group.id)):new Set,f=({across:e,children:a,crossing:m,diagram:v,group:y})=>{for(let e of a)f(p.get(e));let w=dD(u.has(y.id)?e:v,c,d,{...dT,reorder:i.reorder,wrap:i.zoneWraps?.get(y.id)??dX},g),x=dZ(w),b=(e,t)=>"top"===t?e.y-x.y:"bottom"===t?x.y+x.height-e.y-e.height:"left"===t?e.x-x.x:x.x+x.width-e.x-e.width,k=e=>Math.max(r?24:40,...w.map(t=>(d.get(pc(t.nodeId,e))??0)-b(t,e)+18))+(l.get(y.id)??0),M=sY(y.label),C=r?12+M+sO.clearance:M+2*sO.clearance,z=w.filter(e=>m.has(e.nodeId)&&.01>=b(e,"top")).map(e=>e.x-x.x+e.width/2-36),_={top:k("top")+36*!!r,bottom:k("bottom"),right:k("right"),left:o&&z.length>0?Math.max(k("left"),C+18-Math.min(...z)):k("left")},L={content:x,group:y,height:x.height+_.top+_.bottom,nodes:w,padding:_,width:Math.max(x.width+_.left+_.right,r?C+12:M+2*sO.clearance+16,(s.get(pc(y.id,"top"))??0)>0&&t.composites.has(y.id)?M+2*sO.clearance+36+16+t.crossEdges.filter(e=>e.source===y.id||e.target===y.id).length*pf:0)};h.set(y.id,L);let B=dH(y.id);c.set(B,{width:L.width,height:L.height+n}),r&&g.set(B,o?(L.padding.left-L.padding.right)/2:(L.padding.top-L.padding.bottom)/2);let S=(L.width-L.content.width-L.padding.left-L.padding.right)/2,A=(e,t)=>"top"===t?e.y-L.content.y+L.padding.top+n:"bottom"===t?L.content.y+L.content.height-e.y-e.height+L.padding.bottom:"left"===t?e.x-L.content.x+L.padding.left+S:L.content.x+L.content.width-e.x-e.width+L.padding.right+S;for(let e of["top","right","bottom","left"]){let a=Math.max(0,t.composites.has(y.id)?(s.get(pc(y.id,e))??0)-("top"===e?n:0):0,...w.map(t=>(d.get(pc(t.nodeId,e))??0)-A(t,e)));a>0&&d.set(pc(B,e),a)}};for(let e of t.groups)t.parentOf.has(e.group.id)||f(e);let m=i.zoneWraps?.get("")??dX,v=dD(t.top,c,d,{...i,wrap:m},g),y=new Map;for(let e of v)e.nodeId.startsWith(dB)||y.set(e.nodeId,{nodes:[e]});let w=new Map,x=(e,t,a)=>{let s=h.get(e),i={x:t.x,y:t.y+n,width:t.width,height:t.height-n};w.set(e,i);let l=i.x+s.padding.left+(i.width-s.content.width-s.padding.left-s.padding.right)/2-s.content.x,o=i.y+s.padding.top+(i.height-s.content.height-s.padding.top-s.padding.bottom)/2-s.content.y;for(let e of s.nodes){let t={...e,x:e.x+l,y:e.y+o};e.nodeId.startsWith(dB)?x(e.nodeId.slice(dB.length),t,a):a.push(t)}return i};for(let e of t.groups){if(t.parentOf.has(e.group.id))continue;let a=dH(e.group.id),s=v.find(e=>e.nodeId===a),i=[],l=x(e.group.id,s,i),o=t.groups.flatMap(({group:a})=>a.id!==e.group.id&&dj(t,a.id).at(-1)===e.group.id?[a.id]:[]);y.set(a,{frame:l,...o.length>0?{nested:new Map(o.map(e=>[e,w.get(e)]))}:{},nodes:i})}for(let[e,a]of(function(e,t,a,s=new Map){let{crossEdges:i,top:l}=e,o=d_(l),r=dF(l,dk(l.edges),o),n=new Map;for(let e of l.nodes){let t=r.get(e.id)??0;n.set(t,[...n.get(t)??[],e.id])}let c=a?"x":"y",d=a?"width":"height",p=Math.max(0,...s.values())+1,h=e=>{let a=[...t].filter(([t])=>(s.get(t)??0)===e).map(([,e])=>e.frame??e.nodes[0]);return{start:Math.min(...a.map(e=>e[c])),end:Math.max(...a.map(e=>e[c]+e[d]))}},g=Array.from({length:p},(e,t)=>0===t?0:h(t).start-h(t-1).end),u=e=>(n.get(e)??[]).reduce((e,a)=>{let s=t.get(a);return e+(s.frame??s.nodes[0])[d]},0),f=[...n.keys()].sort((e,t)=>e-t),m=f.reduce((e,t)=>u(t)>u(e)?t:e),v=a=>{let s=e.composites.has(a)?t.get(dH(a)).frame:[...t.values()].flatMap(e=>e.nodes).find(e=>e.nodeId===a);return s[c]+s[d]/2},y=(e,a)=>{let s=t.get(e);for(let[e,t]of(s.nodes=s.nodes.map(e=>({...e,[c]:e[c]+a})),s.frame&&(s.frame={...s.frame,[c]:s.frame[c]+a}),s.nested??[]))s.nested.set(e,{...t,[c]:t[c]+a})},w=e=>s.get(n.get(e)?.[0]??"")??0,x=(e,t,a)=>{let[s]=n.get(e)??[];if(!s||1!==n.get(e).length||w(e)!==w(t))return;let c=l.edges.find(e=>!o.has(e.id)&&(a?e.target:e.source)===s&&r.get(a?e.source:e.target)===t);if(!c)return;let d=i[l.edges.indexOf(c)],[p,h]=a?[d.target,d.source]:[d.source,d.target];y(s,v(h)-v(p))},b=a=>{let s=n.get(a);if(!e.zoned||s.length<2)return;let r=e=>t.get(e).frame??t.get(e).nodes[0],p=new Map(s.map(e=>[e,l.edges.flatMap((t,a)=>{let l=i[a],[r,n]=t.source===e?[l.source,l.target]:[l.target,l.source];if(t.source!==e&&t.target!==e||s.includes(t.source===e?t.target:t.source))return[];let c=v(n);return o.has(t.id)&&t.source===e?[c,c]:[c]})])),h=[...s].sort((e,t)=>r(e)[c]-r(t)[c]),g=e=>e.reduce((e,t)=>e+t,0)/e.length,u=e=>p.get(e).length>0?g(p.get(e)):r(e)[c]+r(e)[d]/2,f=[...h].sort((e,t)=>u(e)-u(t)),m=h.slice(1).map((e,t)=>{let a=r(h[t]);return r(e)[c]-a[c]-a[d]}),w=s.flatMap(e=>p.get(e)),x=f.reduce((e,t)=>e+r(t)[d],0)+m.reduce((e,t)=>e+t,0),b=w.length>0?g(w)-x/2:r(h[0])[c];for(let[e,t]of f.entries())y(t,b-r(t)[c]),b+=r(t)[d]+(m[e]??0)};for(let e of f.filter(e=>e>m))x(e,e-1,!0),b(e);for(let e of f.filter(e=>e<m).reverse())x(e,e+1,!1),b(e);for(let e=1;e<p;e+=1){let a=h(e-1).end+g[e]-h(e).start;for(let[i]of t)(s.get(i)??0)===e&&y(i,a)}}(t,y,o,m.bandOf),y))for(let[t,s]of(a.frame&&w.set(e.slice(dB.length),a.frame),a.nested??[]))w.set(t,s);let b=[...y.values()].flatMap(e=>e.nodes),k=dM(e.nodes);b.sort((e,t)=>k.get(e.nodeId)-k.get(t.nodeId));let M=(r?[...t.groups].sort((e,a)=>dj(t,e.group.id).length-dj(t,a.group.id).length):t.groups).map(({group:e})=>{let t=w.get(e.id);return{box:t,elementId:`group:${e.id}`,id:e.id,...r&&void 0!==e.kind?{kind:e.kind}:{},label:e.label,labelBox:r?function(e,t){let{clearance:a,height:s}=sO;return{x:e.x+12-a,y:e.y+(36-s)/2-a,width:sY(t)+2*a,height:s+2*a}}(t,e.label):s$({...t,name:e.label})}});return{groups:{across:u,composites:t.composites,frames:M,groupOf:t.groupOf,parentOf:t.parentOf,zoned:r},nodes:b}}(e,l,t,a,s,i):{nodes:dD(e,t,a,s)}}function dZ(e){let t=Math.min(...e.map(e=>e.x)),a=Math.min(...e.map(e=>e.y));return{x:t,y:a,width:Math.max(...e.map(e=>e.x+e.width))-t,height:Math.max(...e.map(e=>e.y+e.height))-a}}function dj(e,t){let a=[];for(let s=t;void 0!==s;s=e.parentOf.get(s))a.push(s);return a}let dN=36;function dW(e){return(e.lanes??[]).length>0}function dJ(e,t,a){let s=e.lanes,{direction:i}=e.layout,l="TB"===i||"BT"===i,[o,r]=l?["y","x"]:["x","y"],[n,c]=l?["height","width"]:["width","height"],[d,p]=l?["left","right"]:["top","bottom"],h=dE[i],g=pm[h],u=(e,t)=>a.get(pc(e,t))??0,f=dk(e.edges),m=l?dO(e,t,f,l):dO(e,t,f,l,144,744),v=function(e){let t=e.lanes??[],a=new Map(t.map((e,t)=>[e.id,t])),s=new Map(e.nodes.map(e=>[e.id,a.get(e.lane??"")??0])),i=d_(e),l=e.edges.filter(e=>!i.has(e.id)&&e.source!==e.target),o=new Set,r=new Set;for(let e of l){let[t,a]=[s.get(e.source),s.get(e.target)],i=`${e.source}\0${a}`;1!==Math.abs(t-a)||r.has(i)||(r.add(i),o.add(e.id))}let n=new Map(e.nodes.map(e=>[e.id,[]])),c=new Map(e.nodes.map(e=>[e.id,[]]));for(let e of l)n.get(e.target).push(e),c.get(e.source).push(e);let d=dM(e.nodes),p=new Map(e.nodes.map(e=>[e.id,n.get(e.id).length])),h=e.nodes.filter(e=>0===p.get(e.id)).map(e=>e.id),g=new Map,u=new Map;for(;h.length>0;){h.sort((e,t)=>d.get(e)-d.get(t));let e=h.shift(),a=s.get(e),i=t.map((t,a)=>Math.max(-1,...n.get(e).map(e=>u.get(e.source)[a]))),l=i[a]+1;for(let t of n.get(e))l=Math.max(l,g.get(t.source)+ +!o.has(t.id));for(let t of(g.set(e,l),i[a]=l,u.set(e,i),c.get(e))){let e=p.get(t.target)-1;p.set(t.target,e),0===e&&h.push(t.target)}}return g}(e),y=new Map(s.map((e,t)=>[e.id,t])),w=new Map(e.nodes.map(e=>[e.id,e.lane])),x=Math.max(0,...v.values())+1,b=s.map(()=>Array.from({length:x},()=>[]));for(let t of e.nodes)b[y.get(t.lane)][v.get(t.id)].push(t.id);let k=d_(e),M=new Map(e.nodes.map(e=>[e.id,[]]));for(let t of e.edges)k.has(t.id)||t.source===t.target||(M.get(t.source).push(t.target),M.get(t.target).push(t.source));let C=dM(e.nodes),z=e=>{let t=b[y.get(w.get(e))][v.get(e)];return y.get(w.get(e))+(t.indexOf(e)+.5)/t.length};for(let e=0;e<4;e+=1)for(let e of b)for(let t of e){if(t.length<2)continue;let e=new Map(t.map(e=>{let t=M.get(e);return[e,t.length>0?t.reduce((e,t)=>e+z(t),0)/t.length:z(e)]}));t.sort((t,a)=>e.get(t)-e.get(a)||C.get(t)-C.get(a))}let _=Array.from({length:x},(t,a)=>e.nodes.filter(e=>v.get(e.id)===a).map(e=>m.get(e.id))),L=_.map(e=>Math.max(0,...e.map(e=>e[n]))),B=(e,t)=>Math.max(0,...e.map(e=>u(e.nodeId,t))),S=_.map((t,s)=>{let i=new Set(t.map(e=>e.nodeId)),o=l?0:Math.max(0,...e.edges.filter(e=>i.has(e.source)&&e.label&&(v.get(e.target)??0)>s).map(e=>p0(e.label,dx(m.get(e.source)?.kind)).width+16+72)),r=_[s+1];return Math.max(72,o,r&&a.size>0?B(t,h)+B(r,g)+18:0)}),A=(e,t)=>Math.max(112,u(e,p)+u(t,d)+18),P=e=>e.reduce((t,a,s)=>t+m.get(a)[c]+(s>0?A(e[s-1],a):0),0),V=b.map(e=>Math.max(0,...e.map(P))),H=new Map;for(let[e,t]of b.entries())for(let a of t){let t=(V[e]-P(a))/2;for(let[e,s]of a.entries())e>0&&(t+=A(a[e-1],s)),H.set(s,t),t+=m.get(s)[c]}let q=b.map((e,t)=>{let a=e.flat(),s=e=>Math.max(32,...a.map(a=>{let s=e===d?H.get(a):V[t]-H.get(a)-m.get(a)[c];return u(a,e)-s+dN}));return{low:s(d),high:s(p)}}),F=s.map(e=>dQ(e.label)),I=l?0:Math.max(...F.map(e=>e.textWidth))+32,E=b.map((e,t)=>Math.max(q[t].low+V[t]+q[t].high,l?dQ(s[t].label).longestWord+32:F[t].textHeight+32)),O=s.map((e,t)=>l?dQ(e.label,E[t]-32):F[t]),U=l?Math.max(44,...O.map(e=>e.textHeight+32)):Math.ceil(I),X=E.reduce((e,t)=>e+t,0);return{along:o,across:r,backSide:g,breadth:E,columnCount:x,columnOf:_,columns:v,content:V,depth:L,depthOf:n,forwardSide:h,gapAfter:S,headerSize:U,laneIndex:y,laneOf:w,offset:H,padding:q,poolBreadth:X,reach:B,shapes:m,vertical:l,wrapped:O}}function dK(e){return Math.max(144,72+(e+1)*18)}function dQ(e,t){let a=void 0===t?aE(e,868):aO(e,t,16),s=a.split("\n");return{longestWord:Math.max(...e.split(/\s+/u).map(e=>aq(e,16))),text:a,textHeight:Math.ceil(16*s.length*1.35),textWidth:Math.ceil(aq(a,16))}}function d1(e,t){return{type:"node",id:e,nodeId:e,shape:"rectangle",label:"",x:t.x,y:t.y,width:t.width,height:t.height}}function d0(e){return(e?.frames??[]).flatMap(t=>e.composites.has(t.id)?[{...d1(t.elementId,t.box),kind:"composite",label:t.label,nodeId:t.id}]:[])}function d2(e){let t=28*!e?.zoned;return(e?.frames??[]).map(e=>d1(e.elementId,{...e.box,y:e.box.y-t,height:e.box.height+t}))}let d3="group-outline:",d5=`${d3}lane:`;function d4(e){return sp([{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x+e.width,y:e.y+e.height},{x:e.x,y:e.y+e.height},{x:e.x,y:e.y}])}function d6(e,t){return e.x>=t.x-.01&&e.x<=t.x+t.width+.01&&e.y>=t.y-.01&&e.y<=t.y+t.height+.01}function d7(e){return e.elementId}function d8(e,t=!1){return e?[...e.frames.map(e=>d1(`lane-header:${d7(e)}`,e.header)),...(t?[]:e.pools).flatMap(({x:e,y:t,width:a,height:s},i)=>[d1(`lane-wall:${i}:top`,{x:e-4,y:t-4,width:a+8,height:4}),d1(`lane-wall:${i}:bottom`,{x:e-4,y:t+s,width:a+8,height:4}),d1(`lane-wall:${i}:left`,{x:e-4,y:t-4,width:4,height:s+8}),d1(`lane-wall:${i}:right`,{x:e+a,y:t-4,width:4,height:s+8})])]:[]}function d9(e){return e.pools.flatMap((t,a)=>{var s,i,l;let o,r,n;return s=t,i=e.frames.filter(e=>e.pool===a),l=e.vertical,o=i[0].header,r=[...i.map(e=>l?e.box.x:e.box.y),l?s.x+s.width:s.y+s.height],n=l?[s.y,o.y+o.height,s.y+s.height]:[s.x,o.x+o.width,s.x+s.width],[...r.flatMap(e=>sp(l?[{x:e,y:s.y},{x:e,y:s.y+s.height}]:[{x:s.x,y:e},{x:s.x+s.width,y:e}])),...n.flatMap(e=>sp(l?[{x:s.x,y:e},{x:s.x+s.width,y:e}]:[{x:e,y:s.y},{x:e,y:s.y+s.height}]))]})}function pe(e){return e?[d1("lanes",e.pool)]:[]}function pt(e,t){let{source:a,target:s}=e,[i,l]=t.vertical?["y","height"]:["x","width"];return t.laneOf.get(a.nodeId)!==t.laneOf.get(s.nodeId)&&pw(e.sourceEdge)===i&&e.targetEdge===pm[e.sourceEdge]&&Math.min(a[i]+a[l],s[i]+s[l])-Math.max(a[i],s[i])>.01}function pa(e,t){let[a,s]=t.vertical?["y","height"]:["x","width"];for(let i of e){let{source:e,target:l}=i;if(pd(i)||t.continuations.has(i.edge.id)||t.laneOf.get(e.nodeId)===t.laneOf.get(l.nodeId)||Math.min(e[a]+e[s],l[a]+l[s])-Math.max(e[a],l[a])<=.01)continue;let o=t.vertical?pi(l).x>pi(e).x:pi(l).y>pi(e).y;i.sourceEdge=t.vertical?o?"right":"left":o?"bottom":"top",i.targetEdge=pm[i.sourceEdge]}}function ps(e){return{type:"text",id:`label:${e.nodeId}`,containerId:e.id,x:e.x+e.width/2,y:e.y+e.height/2,text:e.label,fontSize:14,maxWidth:Math.max(1,e.width-36),...e.icon?{verticalAlign:"bottom"}:{}}}function pi(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function pl(e,t,a){let s=pi(e),i=pi(t),l=i.x-s.x,o=i.y-s.y,r=e.kind?.toLowerCase();if("LR"===a||"RL"===a)return l>=0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"};if(o<0)return!(Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)>.01)&&Math.abs(l)>Math.abs(o)?{sourceEdge:l>0?"right":"left",targetEdge:"bottom"}:{sourceEdge:"top",targetEdge:"bottom"};let n=dx(r)&&o>e.height+96;return dx(r)&&o>0&&(0!==l||n)?{sourceEdge:l<0?"left":"right",targetEdge:"top"}:o>0?{sourceEdge:"bottom",targetEdge:"top"}:Math.abs(l)>Math.abs(o)?l>0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"}:{sourceEdge:"top",targetEdge:"bottom"}}function po(e,t,a){return Math.min(a,Math.max(t,e))}function pr(e,t,a=0){let s;if(aY(e.shape))return aj({...e,shape:e.shape},t,pr({...e,shape:"rectangle"},t,a));let i=(s="top"===t||"bottom"===t?e.width/2-16:e.height/2-16)>0?po(a,-s,s):0,l=pi(e),o=e.width/2,r=e.height/2;if("diamond"===e.shape&&o>0&&r>0){if("top"===t||"bottom"===t){let e=l.x+i,a=r*(1-Math.abs(i)/o);return{x:e,y:"top"===t?l.y-a:l.y+a}}let e=l.y+i,a=o*(1-Math.abs(i)/r);return{x:"left"===t?l.x-a:l.x+a,y:e}}if(("ellipse"===e.shape||"circle"===e.shape)&&o>0&&r>0){if("top"===t||"bottom"===t){let e=l.x+i,a=r*Math.sqrt(Math.max(0,1-(i/o)**2));return{x:e,y:"top"===t?l.y-a:l.y+a}}let e=l.y+i,a=o*Math.sqrt(Math.max(0,1-(i/r)**2));return{x:"left"===t?l.x-a:l.x+a,y:e}}switch(t){case"top":return{x:e.x+e.width/2+i,y:e.y};case"right":return{x:e.x+e.width,y:e.y+e.height/2+i};case"bottom":return{x:e.x+e.width/2+i,y:e.y+e.height};case"left":return{x:e.x,y:e.y+e.height/2+i}}}function pn(e){return`${e.edgeId}:${e.endpoint}`}function pc(e,t){return`${e}:${t}`}function pd(e){return e.edge.source===e.edge.target}function pp(e,t){let[a,s]="source"===t?[e.sourceEdge,e.targetEdge]:[e.targetEdge,e.sourceEdge];return pv[s][pw(a)]}function ph(e,t){let a="source"===t?e.sourceEdge:e.targetEdge;return pd(e)?1e9*pp(e,t):pi("source"===t?e.target:e.source)[pw(a)]}function pg(e,t){return e.find(e=>e.edge.id===t)?.pair??0}function pu(e,t=!1){let a=new Map;for(let t of e){let e=pc(t.source.nodeId,t.sourceEdge),s=pc(t.target.nodeId,t.targetEdge);a.set(e,[...a.get(e)??[],{edgeId:t.edge.id,endpoint:"source",coordinate:ph(t,"source")}]),a.set(s,[...a.get(s)??[],{edgeId:t.edge.id,endpoint:"target",coordinate:ph(t,"target")}])}let s=new Map;for(let i of a.values()){let a=i.filter(e=>"source"===e.endpoint),l=a.map(t=>e.find(e=>e.edge.id===t.edgeId)).filter(e=>e.edge.label),o=a.length>1&&l.length>0&&(!dx(l[0].source.kind)||t&&l.length>1)?Math.max(18,...l.map(e=>{let t=p0(e.edge.label);return("top"===e.sourceEdge||"bottom"===e.sourceEdge?t.width:t.height)+24})):18;i.sort((t,a)=>t.coordinate-a.coordinate||pg(e,t.edgeId)-pg(e,a.edgeId)).forEach((e,t)=>{s.set(pn(e),(t-(i.length-1)/2)*18*o/18)})}return s}let pf=36,pm={top:"bottom",right:"left",bottom:"top",left:"right"},pv={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function py(e){return"source"===e.endpoint?e.route.sourceEdge:e.route.targetEdge}function pw(e){return"top"===e||"bottom"===e?"x":"y"}function px(e,t){return("x"===pw(t)?e.width:e.height)/2-16}function pb(e,t){return"source"===e.endpoint?pK(e.route,t,36):pJ(e.route,t,36)}let pk={desired:0,high:1/0,low:-1/0,priority:0};function pM(e,t,a=!1,s=pf){let i=pu(e,t),l=new Map;for(let t of e)for(let e of["source","target"]){let a=pc(t[e].nodeId,"source"===e?t.sourceEdge:t.targetEdge);l.set(a,[...l.get(a)??[],{endpoint:e,key:pn({edgeId:t.edge.id,endpoint:e}),route:t}])}let o=[...l.values()].sort((e,t)=>t.length-e.length);for(let e=0;e<3;e+=1)for(let e of o){let o=py(e[0]),r=e[0].route[e[0].endpoint],n=new Map(e.map(e=>[e,function(e,t,a){let s=function(e,t,a){let s={endpoint:"source"===e.endpoint?"target":"source",key:pn({edgeId:e.route.edge.id,endpoint:"source"===e.endpoint?"target":"source"}),route:e.route},i=e.route[e.endpoint],l=py(e),o=py(s),r=pw(l),n=pv[l];if(pd(e.route)){let t=pp(e.route,e.endpoint)*Math.max(0,px(i,l));return{desired:t,high:t,low:t,priority:2}}let c=pr(i,l,t.get(e.key)??0),d=pr(e.route[s.endpoint],o,t.get(s.key)??0),p=(d.x-c.x)*n.x+(d.y-c.y)*n.y;if(pw(o)!==r&&p>=pb(e,c)){let e=pR(d,o,pb(s,d)),t=pv[o][r],a=e[r]-pi(i)[r];return{desired:0,high:t<0?a:1/0,lane:t*p,low:t>0?a:-1/0,priority:1}}let h=(e,t)=>(function(e,t){switch(e.shape){case"rectangle":return!1;case"cylinder":return"top"===t||"bottom"===t;case"pipe":return"left"===t||"right"===t;case"document":return"bottom"===t;default:return!0}})(e.route[e.endpoint],t)&&a.get(pc(e.route[e.endpoint].nodeId,t))?.length===1,g=o===pm[l]&&p>0;if(h(e,l)&&!(g&&"target"===e.endpoint&&h(s,o)))return{desired:0,high:0,low:0,priority:2};let u=d[r]-pi(i)[r];return g&&Math.abs(u)<=px(i,l)?{desired:u,high:u,low:u,priority:2}:pk}(e,t,a),i=e.route[e.endpoint];if("composite"!==i.kind||"top"!==py(e))return s;let l=s$({...i,name:i.label}),o=l.x+l.width+18-pi(i).x;return{...s,desired:Math.max(o,s.desired),low:Math.max(o,s.low),high:Math.max(o,s.high),priority:3}}(e,i,l)])),c=function(e,t,a,s){let i=e=>{let t="source"===e.endpoint?"target":"source";if(!s||pd(e.route))return ph(e.route,e.endpoint);let i=e.route[t],l="source"===t?e.route.sourceEdge:e.route.targetEdge,o=pn({edgeId:e.route.edge.id,endpoint:t});return pR(pr(i,l,a.get(o)??0),l,36)[pw(py(e))]},l=[...e].sort((e,t)=>i(e)-i(t)||(e.route.pair??0)-(t.route.pair??0));for(let e of[1,-1]){let a=l.map((e,a)=>({index:a,lane:t.get(e).lane,slot:e})).filter(({lane:t})=>void 0!==t&&Math.sign(t)===e),s=[...a].sort((e,t)=>e.lane-t.lane);a.forEach(({index:e},t)=>{l[e]=s[t].slot})}return l}(e,n,i,a),d=c.filter(e=>"source"===e.endpoint),p=d.filter(e=>e.route.edge.label),h=d.length>1&&p.length>0&&(!dx(p[0].route.source.kind)||t&&p.length>1)?Math.max(...p.map(e=>{let t=p0(e.route.edge.label);return("x"===pw(o)?t.width:t.height)+24})):0;"state"===r.kind&&function(e){for(let[t,a]of e.entries()){let{route:s}=a;if("source"!==a.endpoint||void 0!==s.pair||pd(s))continue;let i=0===t?-1:t===e.length-1?1:void 0;e.length>1&&void 0!==i?s.labelSide=i:delete s.labelSide}}(c);let g=function(e,t,a){let s=e.map((e,a)=>t.slice(0,a).reduce((e,t)=>e+t,0)),i=s.at(-1)??0;if(i>2*a)return s.map(e=>e-i/2);let l=e.map(()=>-1/0),o=e.map(()=>1/0),r=()=>{let e=l.map((e,t)=>Math.max(e-s[t],-a)),t=o.map((e,t)=>Math.min(e-s[t],a-i));for(let t=1;t<e.length;t+=1)e[t]=Math.max(e[t],e[t-1]);for(let e=t.length-2;e>=0;e-=1)t[e]=Math.min(t[e],t[e+1]);return{highs:t,lows:e}};for(let{index:t}of e.map((e,t)=>({index:t,priority:e.priority})).filter(({priority:e})=>e>0).sort((e,t)=>t.priority-e.priority||e.index-t.index)){l[t]=e[t].low,o[t]=e[t].high;let{highs:a,lows:s}=r();s.some((e,t)=>e>a[t]+.01)&&(l[t]=-1/0,o[t]=1/0)}let{highs:n,lows:c}=r();return(function(e,t,a){let s=[];for(let[i,l]of e.entries())for(s.push({count:1,high:a[i],low:t[i],sum:l,value:po(l,t[i],Math.max(t[i],a[i]))});s.length>1&&s.at(-2).value>s.at(-1).value;){let e=s.pop(),t=s.at(-1);t.count+=e.count,t.sum+=e.sum,t.low=Math.max(t.low,e.low),t.high=Math.min(t.high,e.high),t.value=po(t.sum/t.count,t.low,Math.max(t.low,t.high))}return s.flatMap(e=>Array(e.count).fill(e.value))})(e.map((e,t)=>e.desired-s[t]),c,n).map((e,t)=>e+s[t])}(c.map(e=>n.get(e)),c.slice(1).map((e,t)=>Math.max("state"===r.kind?function(e,t,a){let s=(e,t)=>{let{route:s}=e,i="x"===pw(a);if("source"!==e.endpoint||!s.edge.label||pd(s)||pC(s)!==t)return 0;let l=p0(s.edge.label,dx(s.source.kind));return(i?l.width:l.height)+24};return Math.max(s(e,1),s(t,-1))}(c[t],e,o):h,"target"===e.endpoint||"target"===c[t].endpoint?s:18)),px(r,o));c.forEach((e,t)=>i.set(e.key,g[t]))}return i}function pC(e){let t="left"===e.sourceEdge||"right"===e.sourceEdge;return e.labelSide??e.pair??(t?-1:1)}function pz(e,t){let{edge:a,source:s,sourceEdge:i,target:l,targetEdge:o}=e;return{start:pr(s,i,t.get(pn({edgeId:a.id,endpoint:"source"}))??0),end:pr(l,o,t.get(pn({edgeId:a.id,endpoint:"target"}))??0)}}function p_(e,t,a){let s=0,i=1;for(let[l,o]of[["x","width"],["y","height"]]){let r=a[l]+.01,n=a[l]+a[o]-.01,c=t[l]-e[l];if(.01>=Math.abs(c)){if(e[l]<=r||e[l]>=n)return!1}else{let t=(r-e[l])/c,a=(n-e[l])/c;s=Math.max(s,Math.min(t,a)),i=Math.min(i,Math.max(t,a))}}return s<i}function pL(e,t,a,s){let i=(a.x-pi(e).x)/(e.width/2),l=(a.y-pi(e).y)/(e.height/2),o="ellipse"===e.shape||"circle"===e.shape?{x:i/e.width,y:l/e.height}:"diamond"===e.shape?{x:Math.sign(i)/e.width,y:Math.sign(l)/e.height}:{x:"left"===t?-1:+("right"===t),y:"top"===t?-1:+("bottom"===t)};return(o.x*(s.x-a.x)+o.y*(s.y-a.y))/Math.hypot(o.x,o.y)>=-.01}function pB(e,t,a,s=!1){let i=new Map,l=d_(t),o="TB"===t.layout.direction||"BT"===t.layout.direction?["right","left","top","bottom"]:["bottom","top","left","right"],r=pu(e);for(let n of e.filter(e=>l.has(e.edge.id)||s&&(e=>{let{start:t,end:s}=pz(e,r);return!pL(e.source,e.sourceEdge,t,s)||!pL(e.target,e.targetEdge,s,t)||a.some(a=>a!==e.source&&a!==e.target&&p_(t,s,a))})(e))){let s,c={sourceEdge:n.sourceEdge,targetEdge:n.targetEdge},d=pn({edgeId:n.edge.id,endpoint:"source"}),p=pn({edgeId:n.edge.id,endpoint:"target"}),h=[c,...o.map(e=>({sourceEdge:e,targetEdge:e})),...o.flatMap(e=>o.map(t=>({sourceEdge:e,targetEdge:t})))],g=[!1,!0].flatMap(e=>h.map(t=>({...t,spread:e}))),u=!1;for(let t of g){Object.assign(n,{sourceEdge:t.sourceEdge,targetEdge:t.targetEdge});let i=new Map(r),l=(e,a,s)=>{let l=("top"===a||"bottom"===a?e.width:e.height)/2-16;return t.spread?[i.get(s)??0,-l,l]:[i.get(s)??0]},o=l(n.source,n.sourceEdge,d),c=l(n.target,n.targetEdge,p);for(let l of o){for(let o of c){i.set(d,l),i.set(p,o);let{start:c,end:h}=pz(n,i);if(!pL(n.source,n.sourceEdge,c,h)||!pL(n.target,n.targetEdge,h,c)||a.some(e=>e!==n.source&&e!==n.target&&p_(c,h,e))||e.some(e=>{if(e===n)return!1;let{start:t,end:a}=pz(e,i);return[[n.source,c,e.source,t],[n.source,c,e.target,a],[n.target,h,e.source,t],[n.target,h,e.target,a]].some(([e,t,a,s])=>e===a&&.01>=Math.hypot(t.x-s.x,t.y-s.y))||function(e,t,a,s){let i=t.x-e.x,l=t.y-e.y,o=Math.hypot(i,l);if(o<=.01)return!1;let r=t=>Math.abs(i*(t.y-e.y)-l*(t.x-e.x))/o;if(r(a)>.01||r(s)>.01)return!1;let n=t=>((t.x-e.x)*i+(t.y-e.y)*l)/o,c=n(a),d=n(s);return Math.min(o,Math.max(c,d))-Math.max(0,Math.min(c,d))>.01}(c,h,t,a)}))continue;let g=p3(e,i),f=g.find(e=>e.nodeId===`branch-label:${n.edge.id}`);if(!(f&&p_(c,h,f))&&(s??={sides:t,sourceOffset:l,targetOffset:o},!g.some(e=>e.nodeId!==`branch-label:${n.edge.id}`&&p_(c,h,e)))){r.set(d,l),r.set(p,o),u=!0;break}}if(u)break}if(u)break}if(u||l.has(n.edge.id)){if(!u)if(Object.assign(n,s?.sides??c),s)r.set(d,s.sourceOffset),r.set(p,s.targetOffset);else{let e="TB"===t.layout.direction||"BT"===t.layout.direction,s=e?"x":"y",l=e?"width":"height",o=pi(n.source)[s],r=Math.max(...a.flatMap(e=>[Math.abs(e[s]-o),Math.abs(e[s]+e[l]-o)]));i.set(n.source.nodeId,{width:n.source.width,height:n.source.height,[l]:2*(r+16+18)})}}else Object.assign(n,s?.sides??c),s&&(r.set(d,s.sourceOffset),r.set(p,s.targetOffset))}return{offsets:r,minimumSizes:i}}function pS(e,t,a=!1){let s=new Map;for(let i of e){let{start:e,end:l}=pz(i,t);for(let[t,a,o]of[[i.source,i.sourceEdge,pK(i,e,36)],[i.target,i.targetEdge,pJ(i,l,36)]]){let r=pR(t===i.source?e:l,a,o),n="left"===a?t.x-r.x:"right"===a?r.x-t.x-t.width:"top"===a?t.y-r.y:r.y-t.y-t.height,c=pc(t.nodeId,a);s.set(c,Math.max(s.get(c)??0,n))}if(i.edge.label&&(a||pd(i))){let t=i.source,a=p5(p2(i,e),p0(i.edge.label,dx(t.kind)));for(let[e,i]of[["left",t.x-a.x],["right",a.x+a.width-t.x-t.width],["top",t.y-a.y],["bottom",a.y+a.height-t.y-t.height]]){let a=pc(t.nodeId,e);i>0&&s.set(a,Math.max(s.get(a)??0,i))}}}return s}function pA(e){let t=[];for(let a of e){let e=t[t.length-1];e&&e.x===a.x&&e.y===a.y||t.push(a)}let a=t[0];return a?[a,...t.slice(1)]:[{x:0,y:0}]}function pP(e,t){return e.x>=t.x&&e.x<=t.x+t.width&&e.y>=t.y&&e.y<=t.y+t.height}function pV(e,t,a){let s,i="horizontal"===e.orientation,[l,o]=i?[t.width/2,t.height/2]:[t.height/2,t.width/2],r=i?t.x+l:t.y+l,n=Math.abs(e.staticCoordinate-(i?t.y+o:t.x+o));if("ellipse"===t.shape||"circle"===t.shape){let[e,t]=[l+a,o+a];if(n>=t)return!1;s=e*Math.sqrt(1-(n/t)**2)}else if("diamond"===t.shape){let e=1+a*Math.hypot(1/l,1/o);if(n>=o*e)return!1;s=l*(e-n/o)}else{if(n>=o+a)return!1;s=l+a}return e.min<r+s-.01&&e.max>r-s+.01}function pH(e,t){return e.id.startsWith("node:")&&!t.has(e.nodeId)}function pq(e,t,a){return sp(e).filter(e=>t.some(t=>pH(t,a)&&pF(e,t))).length}function pF(e,t){let[a,s,i,l]="horizontal"===e.orientation?[t.y,t.height,t.x,t.width]:[t.x,t.width,t.y,t.height];return(.01>=Math.abs(e.staticCoordinate-a)||.01>=Math.abs(e.staticCoordinate-a-s))&&Math.min(e.max,i+l)-Math.max(e.min,i)>.01}function pI(e,t,a){let s=0;for(let[i,l]of sp(e).entries())for(let o of t)!(a.has(o.nodeId)&&(0===i&&pP(e[0],o)||i===e.length-2&&pP(e.at(-1),o)))&&su(l,o)&&(s+=1);return s}function pE(e,t,a){let s=0;for(let i of sp(e))for(let e of t)pH(e,a)&&!su(i,e)&&pV(i,e,12)&&(s+=1);return s}function pO(e){let t=0;for(let a=0;a<e.length-1;a+=1){let s=e[a],i=e[a+1];s&&i&&(t+=Math.abs(i.x-s.x)+Math.abs(i.y-s.y))}return t}function pU(e){return sp(e.points).map(t=>{let[a,s]=[e.points[t.segmentIndex],e.points[t.segmentIndex+1]];return{...t,arrowId:e.arrowId,startBindingId:e.sourceNodeId,endBindingId:e.targetNodeId,from:"horizontal"===t.orientation?a.x:a.y,to:"horizontal"===t.orientation?s.x:s.y}})}function pX(e){return e.flatMap(e=>pU({arrowId:e.id,points:e.points,sourceNodeId:e.sourceNodeId,targetNodeId:e.targetNodeId}))}function pT(e,t,a){let s=pU({arrowId:`edge:${a.edge.id}`,points:e,sourceNodeId:a.edge.source,targetNodeId:a.edge.target}),i=0;for(let e of s)for(let s of t)e.arrowId===s.arrowId||!sg(e,s)||void 0!==a.pinned&&function(e,t){let a=e.isFirstSegment&&t.isFirstSegment&&e.startBindingId===t.startBindingId;return sf(e,t)&&.01>=Math.abs((a?e.from:e.to)-(a?t.from:t.to))&&Math.sign(e.to-e.from)===Math.sign(t.to-t.from)}(e,s)||(i+=1);return i}function pY(e,t){let a=pU({arrowId:`edge:${t.edge.id}`,points:e,sourceNodeId:t.edge.source,targetNodeId:t.edge.target}),s=0;for(let e=0;e<a.length;e+=1){let t=a[e];if(t)for(let i=e+1;i<a.length;i+=1){let e=a[i];e&&sg(t,e)&&(s+=1)}}return s}function p$(e){let t=e[0],a=e[e.length-1];if(!t||!a)return 0;let s=e.map(e=>e.x),i=e.map(e=>e.y),l=0;return a.x<t.x?l+=Math.max(0,Math.max(...s)-t.x):a.x>t.x&&(l+=Math.max(0,t.x-Math.min(...s))),a.y<t.y?l+=Math.max(0,Math.max(...i)-t.y):a.y>t.y&&(l+=Math.max(0,t.y-Math.min(...i))),l}function pG(e){let t=e[0],a=e[e.length-1];if(!t||!a)return 0;let s=e.map(e=>e.x),i=e.map(e=>e.y),l=0;return a.x<t.x?l+=Math.max(0,a.x-Math.min(...s)):a.x>t.x&&(l+=Math.max(0,Math.max(...s)-a.x)),a.y<t.y?l+=Math.max(0,a.y-Math.min(...i)):a.y>t.y&&(l+=Math.max(0,Math.max(...i)-a.y)),l}function pD(e,t,a){switch(a){case"top":return t.x===e.x&&e.y-t.y>=36;case"right":return t.y===e.y&&t.x-e.x>=36;case"bottom":return t.x===e.x&&t.y-e.y>=36;case"left":return t.y===e.y&&e.x-t.x>=36}}function pR(e,t,a){switch(t){case"top":return{x:e.x,y:e.y-a};case"right":return{x:e.x+a,y:e.y};case"bottom":return{x:e.x,y:e.y+a};case"left":return{x:e.x-a,y:e.y}}}function pZ(e,t){return 0===t.length?0:sp(e).filter(e=>t.some(t=>t.orientation===e.orientation&&Math.abs(t.staticCoordinate-e.staticCoordinate)<(t.arrowId.startsWith(d5)?24:8)&&sh(t,e)>8)).length}function pj(e,t,a,s,i,l=!1){let o=e[0];if(!o)return[{x:0,y:0}];let r=e=>{let o,r,n,c,d,p=i.quality?.({id:`edge:${s.edge.id}`,points:e,sourceId:s.edge.source,targetId:s.edge.target})??{arrowheadsCrossed:0,corridors:0,jogs:0};return[-(o=e[0],r=e[1],n=e[e.length-1],c=e[e.length-2],d=0,r&&pD(o,r,s.sourceEdge)&&(d+=1),c&&n&&pD(n,c,s.targetEdge)&&(d+=1),d),pI(e,t,a),...l?[pq(e,t,a)]:[],pY(e,s),pT(e,i.segments,s),pZ(e,i.outlines),p.corridors,p.arrowheadsCrossed,i.crossings?.route(e,`edge:${s.edge.id}`)??0,p$(e),pG(e),p.jogs,pO(e),i.quality?sp(e).filter((e,t,a)=>t>0&&e.orientation!==a[t-1].orientation).length:0]},n=(e,t)=>{for(let a=0;a<e.length;a+=1){let s=(e[a]??0)-(t[a]??0);if(0!==s)return s<0}return!1},c=o,d=r(o);for(let t of e.slice(1)){let e=r(t);n(e,d)&&(c=t,d=e)}return c}function pN(e,t,a,s){switch(a){case"left":return s+t.x-e.x;case"right":return s+e.x+e.width-t.x;case"top":return s+t.y-e.y;case"bottom":return s+e.y+e.height-t.y}}function pW(e,t){return e.runs?.[t]??e.endRun??0}function pJ(e,t,a){return pN(e.target,t,e.targetEdge,Math.max(a,pW(e,"target")))}function pK(e,t,a){let s=e.edge.label&&!pd(e)?"left"===e.sourceEdge||"right"===e.sourceEdge?p0(e.edge.label,dx(e.source.kind)).width+16:Math.max(40,p0(e.edge.label,dx(e.source.kind)).height+24):0;return pN(e.source,t,e.sourceEdge,Math.max(a,pW(e,"source")+Math.min(s,function(e,t){if("choice"!==e.source.kind||e.targetEdge!==pm[e.sourceEdge])return 1/0;let a=pv[e.sourceEdge],s=0===a.x?"y":"x",i=a[s],[l,o]="x"===s?["y","height"]:["x","width"];if(t[l]>=e.target[l]&&t[l]<=e.target[l]+e.target[o])return 1/0;let r=((i>0?e.target[s]:e.target[s]+e.target["x"===s?"width":"height"])-t[s])*i-36-18;return r>36?r:1/0}(e,t))))}function pQ(e,t,a=!1){let s="TB"===t||"BT"===t;if(!s&&!a)return;let i=s?"x":"y",l=s?"y":"x",[o,r]=s?["left","right"]:["top","bottom"],n="TB"===t?"bottom":"BT"===t?"top":"LR"===t?"right":"left";for(let t of new Set(e.filter(e=>dx(e.source.kind)).map(e=>e.source))){let a=e.filter(e=>e.source===t).sort((e,t)=>pi(e.target)[i]-pi(t.target)[i]||pi(e.target)[l]-pi(t.target)[l]||e.index-t.index);a.length<2||a.forEach((e,s)=>{let c=a.filter(e=>1>Math.abs(pi(e.target)[i]-pi(t)[i])).sort((e,a)=>Math.abs(pi(e.target)[l]-pi(t)[l])-Math.abs(pi(a.target)[l]-pi(t)[l]))[0],d=2===a.length&&e===c,p=2===a.length&&void 0!==c&&!d;e.sourceEdge=d?n:p?pi(e.target)[i]<pi(t)[i]?o:r:0===s?o:s===a.length-1?r:n})}}function p1(e,t){let a=aO(e,t,13);return{width:aI(a,13,t),height:Math.ceil(13*a.split("\n").length*1.35)}}function p0(e,t=!1){return p1(e,t?80:160)}function p2(e,t){let a=p0(e.edge.label??"",dx(e.source.kind)),s=pR(t,e.sourceEdge,pK(e,t,36)),i="left"===e.sourceEdge||"right"===e.sourceEdge;if(pd(e)){let t=pR(pr(e.target,e.targetEdge),e.targetEdge,36),l=pv[e.sourceEdge];return i?{x:s.x+l.x*(a.width/2+8),y:(s.y+t.y)/2}:{x:(s.x+t.x)/2,y:s.y+l.y*(a.height/2+5)}}let l=pC(e),o=pR(t,e.sourceEdge,pW(e,"source"));return{x:(o.x+s.x)/2+(i?0:l*(a.width/2+8)),y:(o.y+s.y)/2+(i?l*(a.height/2+5):0)}}function p3(e,t){return e.filter(e=>e.edge.label).map(e=>{let a=pr(e.source,e.sourceEdge,t.get(pn({edgeId:e.edge.id,endpoint:"source"}))??0),s=p2(e,a),i=p0(e.edge.label,dx(e.source.kind)),l=i.width+12;return{...e.source,id:`branch-label:${e.edge.id}`,nodeId:`branch-label:${e.edge.id}`,x:s.x-l/2,y:s.y-i.height/2-4,width:l,height:i.height+8,shape:"rectangle"}})}function p5(e,t){return{x:e.x-t.width/2,y:e.y-t.height/2,width:t.width,height:t.height}}function p4(e,t){return e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height}function p6(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function p7(e,t,a){let s=t=>Math.min(1/0,...t.map(t=>(function(e,t){let[a,s,i,l]="horizontal"===t.orientation?[t.min,t.max,t.staticCoordinate,t.staticCoordinate]:[t.staticCoordinate,t.staticCoordinate,t.min,t.max];return Math.hypot(Math.max(0,e.x-s,a-e.x-e.width),Math.max(0,e.y-l,i-e.y-e.height))})(e,t)));return s(a)<s(t)+8}function p8(e,t,a={start:0,end:0}){let s=[],i=pO(e),l=0;for(let o of sp(e)){if(l>240)break;let r=e[o.segmentIndex],n=e[o.segmentIndex+1],c=o.max-o.min,d="horizontal"===o.orientation,p=d?t.width/2+4:t.height/2+4;for(let e=Math.min(p,c/2);e<=c-Math.min(p,c/2)&&!(l+e>240);e+=12){if(a.start>0&&l+e-p<a.start||a.end>0&&l+e+p>i-a.end)continue;let o=e/c,h={x:r.x+(n.x-r.x)*o,y:r.y+(n.y-r.y)*o};for(let e of[1,-1])s.push(d?{x:h.x,y:h.y-e*(t.height/2+5)}:{x:h.x+e*(t.width/2+8),y:h.y})}l+=c}return s}function p9(e){return e?{start:pW(e,"source"),end:pW(e,"target")}:{start:0,end:0}}function he(e,t,a,s,i=!0,l){return ht(e,t,a,s,i,l).labels}function ht(e,t,a,s,i=!0,l){let o=[],r=0,n=e.map(e=>sp(e.points)),c=[...a,...(s?.frames??[]).map(e=>d1(`group-label:${e.id}`,e.labelBox)),...(l?.frames??[]).map(e=>d1(`lane-header:${d7(e)}`,e.header))],d=[...(s?.frames??[]).flatMap(e=>d4(e.box)),...l?d9(l):[]],p=[],h=e.map((e,a)=>e.label?p0(e.label,dx(t[a]?.source.kind)):void 0),g=e.map((e,a)=>e.label?p2(t[a],e.points[0]):void 0);for(let[a,s]of e.entries()){let e=h[a],l=g[a];if(!e||!l)continue;let o=g.flatMap((e,t)=>e&&t!==a&&!p.some(e=>e.index===t)?[p5(e,h[t])]:[]),u=[...n.flatMap((e,t)=>t===a?[]:e),...d],f=(t,s=0)=>(function(e,t,a,s,i){let l=p6(e,3),o=p6(e,8);return t.filter(e=>su(e,l)).length+a.filter(e=>su(e,o)).length+s.filter(t=>(function(e,t){let[a,s]=[t.x+t.width/2,t.y+t.height/2],i=Math.max(e.x,Math.min(a,e.x+e.width))-a,l=Math.max(e.y,Math.min(s,e.y+e.height))-s,[o,r]=[Math.abs(i)/(t.width/2),Math.abs(l)/(t.height/2)];return"diamond"===t.shape?o+r<1:"ellipse"===t.shape||"circle"===t.shape?o*o+r*r<1:o<1&&r<1})(e,t)).length+i.filter(e=>p4(l,e)).length})(p6(p5(t,e),s),n[a],u,c,[...o,...p.map(e=>e.box)]),m=l,v=f(l);if(v>0)for(let i of p8(s.points,e,p9(t[a]))){let e=f(i);if(e<v&&([m,v]=[i,e]),0===v)break}else i&&p7(p5(l,e),n[a],u)&&(m=p8(s.points,e,p9(t[a])).find(t=>0===f(t,6)&&!p7(p5(t,e),n[a],u))??l);r+=v,g[a]=m,p.push({box:p5(m,e),index:a})}for(let[a,s]of e.entries()){let i=g[a];if(!s.label||!i)continue;let l=[`branch:${s.edgeId}`];o.push({type:"text",id:`${s.id}:label`,text:s.label,fontSize:13,x:i.x,y:i.y,maxWidth:dx(t[a]?.source.kind)?80:160,groupIds:l}),e[a]={...s,groupIds:l}}return{labels:o,touches:r}}function ha(e,t){let a=new Map([["horizontal",[]],["vertical",[]]]);for(let t of e)a.get(t.orientation).push(t);for(let e of a.values())e.sort((e,t)=>e.staticCoordinate-t.staticCoordinate);return(e,s)=>{let i=a.get(e.orientation),l=Math.max(t,.02),o=0,r=i.length;for(;o<r;){let t=o+r>>1;i[t].staticCoordinate<e.staticCoordinate-l?o=t+1:r=t}let n=0,c=0;for(let a=o;a<i.length&&i[a].staticCoordinate<=e.staticCoordinate+l;a+=1){let l=i[a];l.arrowId!==s&&(sg(e,l)?n+=1:Math.abs(l.staticCoordinate-e.staticCoordinate)<t&&sh(e,l)>.01&&(c+=1))}return{beside:c,overlaps:n}}}function hs(e){return e.every((t,a)=>0===a||.01>=Math.abs(t.x-e[a-1].x)||.01>=Math.abs(t.y-e[a-1].y))}function hi(e,t,a,s,i,l=e.map((e,t)=>t),o=new Map){var r,n;let c=[...p3(e,a),...e.filter(pd).map(e=>{let{start:t,end:s}=pz(e,a),i=dZ([t,s,pR(t,e.sourceEdge,pK(e,t,36)),pR(s,e.targetEdge,pJ(e,s,36))].map(e=>({...e,width:0,height:0})));return d1(`loop:${e.edge.id}`,p6(i,9))})],d="orthogonal"===t?e.flatMap(e=>{let{start:t,end:s}=pz(e,a),i={type:"arrow",id:`edge:${e.edge.id}`,edgeId:e.edge.id,sourceNodeId:e.edge.source,targetNodeId:e.edge.target};return[{...i,endArrowhead:null,points:[t,pR(t,e.sourceEdge,pK(e,t,36))]},{...i,points:[pR(s,e.targetEdge,pJ(e,s,36)),s]}]}):[],p=[...(r=i.groups,(r?.frames??[]).map(e=>{let{x:t,y:a,width:s,height:i}=e.box,l=`${d3}${e.id}`;return{type:"arrow",id:l,edgeId:l,sourceNodeId:"",targetNodeId:"",endArrowhead:null,points:[{x:t,y:a},{x:t+s,y:a},{x:t+s,y:a+i},{x:t,y:a+i},{x:t,y:a}]}})),...(n=i.lanes)?d9(n).map((e,t)=>{let a=`${d5}${t}`,[s,i]="horizontal"===e.orientation?[{x:e.min,y:e.staticCoordinate},{x:e.max,y:e.staticCoordinate}]:[{x:e.staticCoordinate,y:e.min},{x:e.staticCoordinate,y:e.max}];return{type:"arrow",id:a,edgeId:a,sourceNodeId:"",targetNodeId:"",endArrowhead:null,points:[s,i]}}):[]],h=d8(i.lanes),g=d8(i.lanes,!0),u=[];for(let r of l.map(t=>e[t])){let e=o.get(r.edge.id);if(e){u.push(e);continue}u.push(function(e,t,a,s,i,l){let{edge:o}=e,{start:r,end:n}=pz(e,a),c="orthogonal"===t?function(e,t,a,s,i,{avoidCrossings:l,readerScale:o,guided:r,bandOf:n,groups:c,lanes:d}){let p=Math.abs(a.x-t.x)>=Math.abs(a.y-t.y),h=new Set([e.source.nodeId,e.target.nodeId]),g=n?.get(e.source.nodeId),u=void 0===g?s:s.filter(e=>n.get(e.nodeId)===g),f=Math.min(...u.map(e=>e.x)),m=Math.max(...u.map(e=>e.x+e.width)),v=Math.min(...u.map(e=>e.y)),y=Math.max(...u.map(e=>e.y+e.height)),w="left"===e.sourceEdge||"left"===e.targetEdge||pi(e.target).x<pi(e.source).x,x=pi(e.target).y<pi(e.source).y,b=18*e.index,k=f-56-b,M=m+56+b,C=v-48-b,z=y+48+b,_=e.index%4*18/2,L=Math.min(e.source.x,e.target.x)-56-_,B=Math.max(e.source.x+e.source.width,e.target.x+e.target.width)+56+_,S=Math.min(e.source.y,e.target.y)-48-_,A=Math.max(e.source.y+e.source.height,e.target.y+e.target.height)+48+_,P=36+e.index%4*18,V=void 0===o?[P]:[...new Set([P,36])],H=(s,i)=>{let l=i>0?pR(t,e.sourceEdge,pK(e,t,36)):t,o=i>0?pR(a,e.targetEdge,pJ(e,a,i)):a;return pA([t,l,{x:s,y:l.y},{x:s,y:o.y},o,a])},q=(s,i)=>{let l=i>0?pR(t,e.sourceEdge,pK(e,t,36)):t,o=i>0?pR(a,e.targetEdge,pJ(e,a,i)):a;return pA([t,l,{x:l.x,y:s},{x:o.x,y:s},o,a])},F=[[x?S:A,q],[x?A:S,q],[x?C:z,q],[x?z:C,q]],I=[[w?L:B,H],[w?B:L,H],[w?k:M,H],[w?M:k,H]],[E,O]=p?[F,I]:[I,F],U=[...E.slice(0,2),...O.slice(0,2),...E.slice(2),...O.slice(2)],X=pR(t,e.sourceEdge,pK(e,t,36)),T=pR(a,e.targetEdge,pJ(e,a,36)),Y=void 0===e.lane?[]:V.map(t=>"top"===e.sourceEdge||"bottom"===e.sourceEdge?H(e.lane,t):q(e.lane,t)),$=(void 0!==e.pinned||void 0!==d&&pt(e,d))&&e.targetEdge===pm[e.sourceEdge],G="left"===e.sourceEdge||"right"===e.sourceEdge?[{x:(X.x+T.x)/2,y:X.y},{x:(X.x+T.x)/2,y:T.y}]:[{x:X.x,y:(X.y+T.y)/2},{x:T.x,y:(X.y+T.y)/2}],D=[...Y,pA([t,a]),pA([t,X,{x:X.x,y:T.y},T,a]),pA([t,X,{x:T.x,y:X.y},T,a]),...$?[pA([t,X,...G,T,a])]:[],...U.flatMap(([e,t])=>V.map(a=>t(e,a)))],R=function(e,t,a=!1){let s=e.some(e=>e.id.startsWith(d5))?e.filter(e=>!e.id.startsWith(d5)):e;return{...void 0===t?{}:{...a?{crossings:function(e){let t={horizontal:[],vertical:[]};for(let a of e){if(a.id.startsWith(d3))continue;let e=hm(a.points);for(let s=0;s+1<e.length;s+=1){let[i,l]=[e[s],e[s+1]],o=.01>=Math.abs(i.y-l.y);if(!o&&Math.abs(i.x-l.x)>.01)continue;let[r,n]=o?[i.x,l.x]:[i.y,l.y];.01>=Math.abs(n-r)||t[o?"horizontal":"vertical"].push({arrowId:a.id,at:o?i.y:i.x,min:Math.min(r,n),max:Math.max(r,n)})}}for(let e of Object.values(t))e.sort((e,t)=>e.at-t.at);let a=(e,a,s,i,l,o)=>{let r=t["horizontal"===e?"vertical":"horizontal"],n=0,c=r.length;for(;n<c;){let e=n+c>>1;r[e].at<=s+.01?n=e+1:c=e}let d=0;for(let e=n;e<r.length;e+=1){let t=r[e];if(o?t.at>i+.01:t.at>=i-.01)break;t.arrowId!==l&&a>t.min+.01&&a<t.max-.01&&(d+=1)}return d};return{step:(e,t,s,i,l)=>a(e,t,Math.min(s,i),Math.max(s,i),l,!0),route:(e,t)=>{let s=hm(e),i=0;for(let e=0;e+1<s.length;e+=1){let[l,o]=[s[e],s[e+1]],r=.01>=Math.abs(l.y-o.y);if(!r&&Math.abs(l.x-o.x)>.01)continue;let[n,c]=r?[Math.min(l.x,o.x),Math.max(l.x,o.x)]:[Math.min(l.y,o.y),Math.max(l.y,o.y)];i+=a(r?"horizontal":"vertical",r?l.y:l.x,n,c,t,!1)}return i}}}(s)}:{},quality:sF(s.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId,endArrowhead:null!==e.endArrowhead})),t)},outlines:pX(e.filter(e=>e.id.startsWith(d3))),segments:pX(s)}}(i,o,l),Z=c?.zoned===!0,j=pj(D,s,h,e,R,Z),N=void 0===o?0:24/o,W=N?pj([j,...function(e,t,a,s){let i=`edge:${a.edge.id}`,l=[];for(let a of sp(e))if(!a.isFirstSegment&&!a.isLastSegment){for(let o of t)if(!(o.arrowId===i||o.orientation!==a.orientation||Math.abs(o.staticCoordinate-a.staticCoordinate)>=s||.01>=sh(a,o)))for(let t of[o.staticCoordinate-s-1,o.staticCoordinate+s+1]){let s=e.map((e,s)=>s===a.segmentIndex||s===a.segmentIndex+1?"horizontal"===a.orientation?{x:e.x,y:t}:{x:t,y:e.y}:e);l.push(pA(s))}}return l}(j,R.segments,e,N)],s,h,e,R,Z):j,J=Z&&pq(W,s,h)>0,K=pI(W,s,h)||pY(W,e)||pT(W,R.segments,e)||pZ(W,R.outlines),Q=void 0!==e.pinned&&p$(W)+pG(W)>0;if(K||J||R.quality?.({id:`edge:${e.edge.id}`,points:W,sourceId:e.edge.source,targetId:e.edge.target}).corridors||Q){let l=function(e,t,a,s,i,l,o,r,n,c=0,d=1/0,p=!0,h,g=!1){let u,f,m,v,y=e=>[...new Set([18,Math.max(18,c+1)])].flatMap(t=>[e-t,e+t]),w=[...new Set([a.x,s.x,...i.flatMap(e=>[e.x-18,e.x+e.width+18]),...o.flatMap(e=>e.points.flatMap(e=>y(e.x)))])].sort((e,t)=>e-t),x=[...new Set([a.y,s.y,...i.flatMap(e=>[e.y-18,e.y+e.height+18]),...o.flatMap(e=>e.points.flatMap(e=>y(e.y)))])].sort((e,t)=>e-t),b=(e,t,a)=>(e*x.length+t)*2+a,k=`edge:${l.edge.id}`,M=ha(r,c),[C,z]=[!1,!0].map(e=>n.filter(t=>t.arrowId.startsWith(d5)===e)),_=C.length>0?ha(C,8):void 0,L=z.length>0?ha(z,24):void 0,B=[...sp([e,a]),...sp([s,t])],S=(e,t)=>p?Math.abs(w[e]-s.x)+Math.abs(x[t]-s.y):0,A=w.indexOf(a.x),P=x.indexOf(a.y),V={x:A,y:P,axis:+(e.x===a.x),cost:0,estimate:S(A,P)},H=(e,t)=>{let a="x"===t?"width":"height",s=[],l=g?-.01:.01;return o=>s[o]??=i.filter(s=>e[o]>s[t]+l&&e[o]<s[t]+s[a]-l)},[q,F]=[H(w,"x"),H(x,"y")],I=(u=[],f=0,m=(e,t)=>e.item.estimate<t.item.estimate||e.item.estimate===t.item.estimate&&e.order>t.order,v=(e,t)=>{[u[e],u[t]]=[u[t],u[e]]},{get size(){return u.length},push(e){u.push({item:e,order:f++});for(let e=u.length-1;e>0;){let t=e-1>>1;if(!m(u[e],u[t]))break;v(e,t),e=t}},pop(){let e=u[0],t=u.pop();if(u.length>0){u[0]=t;for(let e=0;;){let t=2*e+1,a=t+1,s=e;if(t<u.length&&m(u[t],u[s])&&(s=t),a<u.length&&m(u[a],u[s])&&(s=a),s===e)break;v(e,s),e=s}}return e.item}});I.push(V);let E=new Map([[b(V.x,V.y,V.axis),0]]),O=new Map;for(let a=0;I.size&&a<d;a+=1){let a=I.pop();if(a.cost!==E.get(b(a.x,a.y,a.axis)))continue;let i={x:w[a.x],y:x[a.y]};if(i.x===s.x&&i.y===s.y){let s=[];for(let e=a;e;e=e.previous)s.unshift({x:w[e.x],y:x[e.y]});return pA([e,...s.filter((e,t)=>0===t||t===s.length-1||(s[t-1].x!==e.x||e.x!==s[t+1].x)&&(s[t-1].y!==e.y||e.y!==s[t+1].y)),t])}for(let[e,t,s]of[[-1,0,0],[1,0,0],[0,-1,1],[0,1,1]]){let l=a.x+e,o=a.y+t;if(l<0||o<0||l>=w.length||o>=x.length)continue;let r={x:w[l],y:x[o]},n=(Math.min(l,a.x)*x.length+Math.min(o,a.y))*2+s;if(!O.has(n)){let e=sp([i,r],0)[0],t=sp([i,r])[0],{beside:l,overlaps:o}=t?M(t,k):{beside:0,overlaps:0},c=t&&_?_(t,k):void 0,d=t&&L?L(t,k):void 0;O.set(n,(0===s?F(a.y):q(a.x)).some(t=>su(e,t)||g&&t.id.startsWith("node:")&&pF(e,t))||B.some(t=>sg(e,t))?void 0:Math.abs(r.x-i.x)+Math.abs(r.y-i.y)+1e4*o+1e3*l+(c?(c.beside+c.overlaps)*1e3:0)+(d?(d.beside+d.overlaps)*1e3:0)+(h&&t?320*h.step(t.orientation,t.staticCoordinate,t.min,t.max,k):0))}let c=O.get(n);if(void 0===c)continue;let d=a.cost+c+24*(s!==a.axis),p=b(l,o,s);d>=(E.get(p)??1/0)||(E.set(p,d),I.push({x:l,y:o,axis:s,cost:d,estimate:d+S(l,o),previous:a}))}}}(t,a,X,T,s,e,i,R.segments,R.outlines,K?0:N,K?1/0:5e3,r,R.crossings,Z);if(l)return pj([W,l],s,h,e,R,Z)}return W}(e,r,n,s,i,l):pA([r,n]),d=e.pinned?pA(hm(c)):c;return{type:"arrow",id:`edge:${o.id}`,edgeId:o.id,sourceNodeId:o.source,targetNodeId:o.target,points:d,...o.label?{label:o.label}:{}}}(r,t,a,[...s,...c.filter(e=>e.nodeId!==`branch-label:${r.edge.id}`&&e.nodeId!==`loop:${r.edge.id}`),...function(e,t){if(!e)return[];let a=new Set([...dA(e,e.groupOf.get(t.source.nodeId)),...dA(e,e.groupOf.get(t.target.nodeId))]),s=dP(e,t.source.nodeId,t.target.nodeId);return e.frames.flatMap(e=>{let t=d1(`group-label:${e.id}`,e.labelBox);if(e.id===s){let{x:a,y:s,width:i,height:l}=e.box;return[t,d1(`group-wall:${e.id}:top`,{x:a-4,y:s-4,width:i+8,height:4}),d1(`group-wall:${e.id}:bottom`,{x:a-4,y:s+l,width:i+8,height:4}),d1(`group-wall:${e.id}:left`,{x:a-4,y:s-4,width:4,height:l+8}),d1(`group-wall:${e.id}:right`,{x:a+i,y:s-4,width:4,height:l+8})]}return a.has(e.id)?[t]:[t,d1(e.elementId,e.box)]})}(i.groups,r),...i.lanes?.continuations.has(r.edge.id)?g:h],[...p,...d,...u],i))}return e.map(e=>u.find(t=>t.edgeId===e.edge.id))}function hl(e,t,a,s,i){let l=d_(a),o=new Set(e.flatMap(e=>[pc(e.source.nodeId,e.sourceEdge),pc(e.target.nodeId,e.targetEdge)])),r=[];for(let[a,n]of t.entries()){let c=e[a];if(l.has(c.edge.id)||c.pinned?.target!==void 0||!("hooked"===i?sq([{id:n.id,points:n.points}],s).some(e=>"endpoint-jog"===e.kind&&"end"===e.endpoint):t.some(e=>e!==n&&hv(n.points,e.points,n.points.length-3,!1)>0)))continue;let d=sp(n.points),p=d.at(-1),h=d.findLast(e=>e.orientation!==p?.orientation);if(!p||!h)continue;let g=n.points[h.segmentIndex],u=n.points[h.segmentIndex+1],f="horizontal"===h.orientation?u.x>g.x?"left":"right":u.y>g.y?"top":"bottom";f===c.targetEdge||o.has(pc(c.target.nodeId,f))||(r.push({route:c,side:c.targetEdge}),o.add(pc(c.target.nodeId,f)),c.targetEdge=f)}return r}function ho(e,t,a,s){let i,l=e.flatMap(e=>sp(e.points).map(t=>{let a=e.points[t.segmentIndex],s=e.points[t.segmentIndex+1];return{...t,arrowId:e.id,startBindingId:e.sourceNodeId,endBindingId:e.targetNodeId,from:"horizontal"===t.orientation?a.x:a.y,to:"horizontal"===t.orientation?s.x:s.y}})),o=[];for(let[e,a]of l.entries()){for(let t of l.slice(e+1)){if(a.arrowId===t.arrowId||!sg(a,t))continue;let e=a.isFirstSegment&&t.isFirstSegment&&a.startBindingId===t.startBindingId;sf(a,t)&&.01>=Math.abs((e?a.from:a.to)-(e?t.from:t.to))&&Math.sign(a.to-a.from)===Math.sign(t.to-t.from)||o.push([a.arrowId,t.arrowId])}for(let e of t)e.nodeId!==a.startBindingId&&e.nodeId!==a.endBindingId&&su(a,e)&&o.push([a.arrowId])}let r=a?[...o,...function(e,t){let a=[],s=t.frames.map(e=>d4(e.box));for(let i of e){let e=sp(i.points),l=new Set([...dA(t,t.groupOf.get(i.sourceNodeId)),...dA(t,t.groupOf.get(i.targetNodeId))]),o=new Set(dA(t,dP(t,i.sourceNodeId,i.targetNodeId)));for(let[r,n]of t.frames.entries()){let t=l.has(n.id);(e.some(e=>su(e,n.labelBox)||!t&&su(e,n.box)||s[r].some(t=>t.orientation===e.orientation&&8>Math.abs(t.staticCoordinate-e.staticCoordinate)&&sh(t,e)>8))||o.has(n.id)&&i.points.some(e=>!d6(e,n.box)))&&a.push([i.id])}}return a}(e,a)]:o;return s?[...r,...(i=d9(s),e.flatMap(e=>sp(e.points).some(e=>s.frames.some(t=>su(e,t.header))||i.some(t=>t.orientation===e.orientation&&8>Math.abs(t.staticCoordinate-e.staticCoordinate)&&sh(t,e)>8))||e.points.some(e=>!d6(e,s.pool))?[[e.id]]:[]))]:r}function hr(e,t){let a=new Map(t.map(e=>[e.nodeId,e])),s=0;for(let t of e)for(let[e,i,l]of[[t.sourceNodeId,t.points[0],t.points[1]],[t.targetNodeId,t.points.at(-1),t.points.at(-2)]]){let t=a.get(e);if(!t||!i||!l)continue;if(aY(t.shape)){let e=e=>Math.max(Math.abs(e.x-pi(t).x)/(t.width/2),Math.abs(e.y-pi(t).y)/(t.height/2));e({x:i.x+(l.x-i.x)*1e-4,y:i.y+(l.y-i.y)*1e-4})<e(i)-1e-9&&(s+=1);continue}let o=(i.x+(l.x-i.x)*1e-4-pi(t).x)/(t.width/2),r=(i.y+(l.y-i.y)*1e-4-pi(t).y)/(t.height/2);("diamond"===t.shape?Math.abs(o)+Math.abs(r):"ellipse"===t.shape||"circle"===t.shape?Math.hypot(o,r):Math.max(Math.abs(o),Math.abs(r)))<1-1e-6&&(s+=1)}return s}function hn(e){return e.flatMap(e=>{if("arrow"===e.type||"line"===e.type)return[...e.points];if("text"===e.type){if(e.containerId)return[];let t=(e.maxWidth??e.text.length)/2,a=e.text.split("\n").length*e.fontSize*1.35/2;return[{x:e.x-t,y:e.y-a},{x:e.x+t,y:e.y+a}]}return[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]})}function hc(e,t,a){return{x:e.x+t,y:e.y+a}}let hd={ports:!1,reader:!1,sides:!1,repair:!1};function hp(e){let{edgeArrows:t,groups:a,nodeShapes:s,routedEdges:i}=e,l=new Set;if(!a)return l;let o=new Map(t.map(e=>[e.id,e]));for(let e of ho(t,s,a))for(let t of e){let e=o.get(t);for(let t of e?[e.sourceNodeId,e.targetNodeId]:[]){let e=a.groupOf.get(t);void 0!==e&&l.add(e)}}let r=he([...t],i,s,a,!1),n=a.frames.flatMap(e=>d4(e.box));for(let e of r){let t=o.get(e.id.slice(0,-6)),s=t?a.groupOf.get(t.sourceNodeId):void 0,i=p5(e,p1(e.text,e.maxWidth??160));if(a.zoned)for(let e of a.frames)(d4(e.box).some(e=>su(e,i))||p4(i,e.labelBox))&&l.add(e.id);void 0!==s&&(n.some(e=>su(e,i))||a.frames.some(e=>p4(i,e.labelBox)))&&l.add(s)}return l}function hh(e,t,a=dT){let s=hu(e,t,a,new Map);if(!s.groups)return s;let i=e=>ho(e.edgeArrows,e.nodeShapes,e.groups).length+hp(e).size,l=new Map,o=i(s);for(let r=0;r<3&&o>0;r+=1){let r=hp(s);if(0===r.size)break;let n=hu(e,t,a,l=new Map([...l,...[...r].map(e=>[e,(l.get(e)??0)+36])])),c=i(n);c<o&&([s,o]=[n,c])}return s}function hg(e,t){for(let a of e)for(let e of["source","target"]){let s=a.pinned?.[e];void 0!==s&&t.set(pn({edgeId:a.edge.id,endpoint:e}),s)}return t}function hu(e,t,a,s){let i,l,o="orthogonal"===e.layout.edgeRouting,{anchors:r,endRun:n,placement:c}=hB.get(e)??{},d=s=>hg(s,t.ports?pM(s,t.repair,a.crossingRepair,dW(e)?54:pf):pu(s,t.repair)),{wrap:p}=a,h=function(e,t){let a=t?dq(e):void 0;if(!a||!t)return new Set;let s=new Map([["",a.top],...a.groups.map(e=>[e.group.id,e.diagram])]);return new Set([...t].flatMap(([e,{bandOf:t}])=>s.get(e).edges.filter(e=>(t.get(e.source)??0)!==(t.get(e.target)??0)).map(e=>e.id)))}(e,a.zoneWraps),{groups:g,lanes:u,nodes:f}=c?{nodes:e.nodes.map(e=>{let t=c.get(e.id);if(!t)throw Error(`Cannot render node "${e.id}" without a placement.`);return{...db(e),x:t.x,y:t.y,width:t.width,height:t.height}})}:dR(e,new Map,new Map,a,s),{direction:m}=e.layout,v=e=>void 0!==e&&void 0!==g&&g.across.has(e),y=e=>v(g?.groupOf.get(e))?dY[m]:m,w=e=>g&&v(dP(g,e.source,e.target))?dY[m]:m,x=new Map([...f,...d0(g)].map(e=>[e.nodeId,e])),b=e.edges.map((e,t)=>(function(e,t,a,s,i=!1){let l=a.get(e.source),o=a.get(e.target);if(!l||!o)throw Error(`Cannot render edge "${e.id}" with unresolved nodes.`);let{sourceEdge:r,targetEdge:n}=i?{sourceEdge:dE[s],targetEdge:pm[dE[s]]}:pl(l,o,s);return{edge:e,index:t,source:l,sourceEdge:r,target:o,targetEdge:n}})(e,t,x,w(e),p.continuations.has(e.id)));for(let e of b)if(h.has(e.edge.id)){let{source:t,target:a}=e,s={LR:a.x>=t.x+t.width,RL:a.x+a.width<=t.x,TB:a.y>=t.y+t.height,BT:a.y+a.height<=t.y}[m],i=dE[dY[m]];e.sourceEdge=s?dE[m]:i,e.targetEdge=pm[i]}if(n)for(let e of b)e.endRun=n;u&&pa(b,u);let k=o&&t.ports;for(let e of new Set(b.map(e=>y(e.source.nodeId))))pQ(b.filter(t=>y(t.source.nodeId)===e),e,k);if(u&&o&&function(e,t,a){let[s,i]=t.vertical?["x","y"]:["y","x"],l=dE[a],o=pv[l][i],r=e=>t.vertical?e<0?"left":"right":e<0?"top":"bottom";for(let a of new Set(e.filter(e=>dx(e.source.kind)).map(e=>e.source))){let n=e.filter(e=>e.source===a&&!pd(e));if(n.length>3)continue;let c=e=>t.laneOf.get(e.target.nodeId)===t.laneOf.get(a.nodeId)?0:Math.sign(pi(e.target)[s]-pi(a)[s]),d=e=>(pi(e.target)[i]-pi(a)[i])*o,p=t.vertical?"height":"width",h=e=>Math.min(a[i]+a[p],e.target[i]+e.target[p])-Math.max(a[i],e.target[i])>.01,g=new Set,u=[];for(let e of[-1,1]){let t=n.filter(t=>c(t)===e).sort((e,t)=>Number(h(t))-Number(h(e))||d(e)-d(t));t[0]&&(t[0].sourceEdge=r(e),g.add(r(e))),u.push(...t.slice(1))}for(let e of(u.push(...n.filter(e=>0===c(e))),u.sort((e,t)=>d(e)-d(t)))){let t=0>d(e)?[r(1),r(-1),l]:[l,r(-1),r(1)];e.sourceEdge=t.find(e=>!g.has(e))??l,g.add(e.sourceEdge)}}}(b,u,m),o){for(let t of(!function(e,t){let a=new Map;for(let s of e.filter(pd)){let i=t(s),l=pm[dE[i]],o=t=>e.filter(e=>!pd(e)&&(e.source===s.source&&e.sourceEdge===t||e.target===s.source&&e.targetEdge===t)).length,r=[..."TB"===i||"BT"===i?["right","left"]:["bottom","top"]].sort((e,t)=>o(e)-o(t)),n=[...r.map(e=>[e,l]),...r.map(e=>[e,dE[i]])],c=a.get(s.source.nodeId)??new Set,[d,p]=n.find(([e,t])=>!c.has(`${e}:${t}`))??n[0];c.add(`${d}:${p}`),a.set(s.source.nodeId,c),s.sourceEdge=d,s.targetEdge=p}}(b,e=>w(e.edge)),!function(e,t,a=()=>t.layout.direction){let s=d_(t);for(let t of e.filter(e=>s.has(e.edge.id)&&!pd(e))){let s=a(t),i="LR"===s||"RL"===s,l=i?pi(t.source).y<pi(t.target).y:pi(t.source).x<pi(t.target).x,o=[...i?l?["top","bottom"]:["bottom","top"]:l?["left","right"]:["right","left"],...i?["left","right"]:["top","bottom"]],r=new Set(e.filter(e=>e!==t&&e.source===t.target).map(e=>e.sourceEdge)),n=new Set(e.filter(e=>e!==t&&e.target===t.source).map(e=>e.targetEdge)),c=new Set(e.filter(e=>e!==t&&e.target===t.target).map(e=>e.targetEdge)),d=new Set(e.filter(e=>e!==t&&e.source===t.source).map(e=>e.sourceEdge)),p=dx(t.source.kind)?[t.sourceEdge,...o]:o;t.targetEdge=o.find(e=>!r.has(e)&&!c.has(e))??o.find(e=>!r.has(e))??t.targetEdge,t.sourceEdge=p.find(e=>!n.has(e)&&(!dx(t.source.kind)||!d.has(e))&&(t.source!==t.target||e!==t.targetEdge))??t.sourceEdge}}(b,e,e=>w(e.edge)),hB.get(e)?.pairedReturns&&function(e,t,a,s,i){for(let l of e){if(!t.has(l.edge.id)||pd(l)||i?.has(l.edge.id))continue;let o=e.find(e=>void 0===e.pair&&!i?.has(e.edge.id)&&!t.has(e.edge.id)&&e.source===l.target&&e.target===l.source&&e.targetEdge===pm[e.sourceEdge]);if(!o)continue;let[r,n]=[pi(l.source),pi(l.target)],c=new Set([l.source.nodeId,l.target.nodeId]),d=new Set([...c].flatMap(e=>s?dA(s,s.groupOf.get(e)??e):[e]));[...a.filter(e=>!c.has(e.nodeId)),...(s?.frames??[]).filter(e=>!d.has(e.id)).map(e=>d1(e.elementId,e.box))].some(e=>p_(r,n,e))||(l.sourceEdge=o.targetEdge,l.targetEdge=o.sourceEdge,o.pair=-1,l.pair=1)}}(b,d_(e),f,g,a.unpairedReturns),b)){let e=a.sides?.get(t.edge.id);e?.sourceEdge&&(t.sourceEdge=e.sourceEdge),e?.targetEdge&&(t.targetEdge=e.targetEdge)}u&&a.separateRoles&&function(e,t){let a=dE[t],s="TB"===t||"BT"===t?["left","right"]:["top","bottom"];for(let t of e){if(pd(t)||void 0!==t.pinned)continue;let i=t.source,l=t=>e.some(e=>e.target===i&&e.targetEdge===t),o=a=>e.some(e=>e!==t&&e.source===i&&e.sourceEdge===a);if(!l(t.sourceEdge))continue;let r=[a,...s].filter(e=>!l(e));t.sourceEdge=r.find(e=>!o(e))??r[0]??t.sourceEdge}}(b,m),r&&function(e,t){for(let a of e)for(let e of["source","target"]){let s=t.get(pn({edgeId:a.edge.id,endpoint:e}));s&&("source"===e?a.sourceEdge=s.side:a.targetEdge=s.side,a.pinned={...a.pinned,[e]:s.offset},void 0!==s.run&&(a.runs={...a.runs,[e]:s.run}))}}(b,r),i=d(b),l=function(e,t){let a=new Map;for(let s of e)for(let e of["source","target"]){let i=s[e];if(void 0!==dw(i))continue;let l="source"===e?s.sourceEdge:s.targetEdge,o="top"===l||"bottom"===l?"width":"height",r=2*(16+Math.abs(t.get(pn({edgeId:s.edge.id,endpoint:e}))??0));if(r<=(a.get(i.nodeId)?.[o]??i[o]))continue;let n=a.get(i.nodeId)??{width:i.width,height:i.height};n[o]=r,a.set(i.nodeId,"choice"!==i.kind||i.label?n:dy(n,0))}return a}(b,i)}else{let a=pB(b,e,f,t.repair);i=a.offsets,l=a.minimumSizes}let M=o&&!c&&(t.repair||g||u)?u?pS(b.filter(e=>e.edge.label||!pt(e,u)),i,!0):pS(b,i):new Map;if(!c&&(l.size>0||M.size>0)){({groups:g,lanes:u,nodes:f}=dR(e,l,M,a,s));let r=new Map([...f,...d0(g)].map(e=>[e.nodeId,e]));for(let t of b)t.source=r.get(t.source.nodeId),t.target=r.get(t.target.nodeId),o||Object.assign(t,pl(t.source,t.target,e.layout.direction));o?i=d(b):(u&&pa(b,u),pQ(b,e.layout.direction,k),i=pB(b,e,f,t.repair).offsets)}f=function(e,t,a,s){let i=new Map;for(let l of t){if(void 0===dw(l))continue;let o=e.filter(e=>e.source===l||e.target===l),r=o[0];if(1!==o.length||!r||pd(r))continue;let n=r.source===l?"target":"source",c=r[n],d="source"===n?r.sourceEdge:r.targetEdge;if(("source"===n?r.targetEdge:r.sourceEdge)!==pm[d])continue;let p=pw(d),h="x"===p?"width":"height",g=pr(c,d,s.get(pn({edgeId:r.edge.id,endpoint:n}))??0),u={...l,[p]:g[p]-l[h]/2},f=p6(u,18),m=a?.groupOf.get(l.nodeId),v=a?.frames.find(e=>e.id===m),y=new Set(a?dA(a,m):[]);t.every(e=>e===l||!p4(f,i.get(e.nodeId)??e))&&(a?.frames??[]).every(e=>y.has(e.id)||!p4(f,e.box)&&!p4(f,e.labelBox))&&(!v||f.x>=v.box.x&&f.y>=v.box.y&&f.x+f.width<=v.box.x+v.box.width&&f.y+f.height<=v.box.y+v.box.height)&&i.set(l.nodeId,u)}if(0===i.size)return t;for(let t of e)t.source=i.get(t.source.nodeId)??t.source,t.target=i.get(t.target.nodeId)??t.target;return t.map(e=>i.get(e.nodeId)??e)}(b,f,g,i),u?function(e,t,a){let s=t.vertical?"x":"y",i=t.vertical?"width":"height",l=e.filter(e=>a.continuations.has(e.edge.id));for(let e of l){let o=a.bandOf.get(e.source.nodeId)??0,[r,n]=[t.pools[o],t.pools[o+1]];if(!n)continue;let c=l.filter(e=>(a.bandOf.get(e.source.nodeId)??0)===o);e.lane=(r[s]+r[i]+n[s])/2+(c.indexOf(e)-(c.length-1)/2)*18}}(b,u,p):function(e,t,a){for(let s of e){if(!a.continuations.has(s.edge.id))continue;let e=a.bandOf.get(s.source.nodeId)??0,i="top"===s.sourceEdge||"bottom"===s.sourceEdge?"x":"y",l="x"===i?"width":"height",o=e=>t.filter(t=>(a.bandOf.get(t.nodeId)??0)===e);s.lane=(Math.max(...o(e).map(e=>e[i]+e[l]))+Math.min(...o(e+1).map(e=>e[i])))/2}}(b,f,p);let C=[...f,...d2(g),...pe(u)],z=s_({width:Math.max(...C.map(e=>e.x+e.width))-Math.min(...C.map(e=>e.x)),height:Math.max(...C.map(e=>e.y+e.height))-Math.min(...C.map(e=>e.y))}),_={guided:t.repair,...t.reader?{readerScale:z}:{},...p.continuations.size>0?{bandOf:p.bandOf}:{},...g?{groups:g}:{},...u?{lanes:u}:{},...a.avoidCrossings?{avoidCrossings:!0}:{}},L=hi(b,e.layout.edgeRouting,i,f,_);if(o&&t.sides){let t=hl(b,L,e,z,"hooked");if(t.length>0){let e=d(b),a=hi(b,"orthogonal",e,f,_),[s,l]=[L,a].map(e=>{var t,a,s;let i;return t=f,a=g,s=u,i=sq(e.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),z).length,{hard:ho(e,t,a,s).length,reader:i}});if(l.hard<=s.hard&&l.reader<s.reader)[L,i]=[a,e];else for(let{route:e,side:a}of t)e.targetEdge=a}let s=a.crossingRepair?hl(b,L,e,z,"crossed"):[];if(s.length>0){let e=d(b),t=hi(b,"orthogonal",e,f,_);if(ho(t,f,g,u).length<=ho(L,f,g,u).length&&hx({edgeArrows:t,...g?{groups:g}:{},...u?{lanes:u}:{},nodeShapes:f},{edgeArrows:L,...g?{groups:g}:{},...u?{lanes:u}:{},nodeShapes:f},!0,!1))[L,i]=[t,e];else for(let{route:e,side:t}of s)e.targetEdge=t}}return o&&t.repair&&(L=function(e,t,a,s,i){let l=ho(e,s,i.groups,i.lanes),o=t.map((e,t)=>t);for(let r=0;r<4&&l.length>0;r+=1){let r=e=>o.findIndex(a=>`edge:${t[a].edge.id}`===e),[n,c]=l[0],[d,p]=void 0===c?[0,r(n)]:[Math.min(r(n),r(c)),Math.max(r(n),r(c))];if(p<=d)break;let h=[...o];h.splice(d,0,...h.splice(p,1));let g=hi(t,"orthogonal",a,s,i,h),u=ho(g,s,i.groups,i.lanes);if(u.length>=l.length)break;[e,l,o]=[g,u,h]}return e}(L,b,i,f,_)),{edgeArrows:L,...g?{groups:g}:{},...u?{lanes:u}:{},nodeShapes:f,portOffsets:i,routeOptions:_,routedEdges:b}}function hf(e,t,a=[]){let s=[...e.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]),...t.flatMap(e=>e.points),...a.flatMap(e=>{let{width:t,height:a}=p1(e.text,e.maxWidth??160);return[{x:e.x-t/2,y:e.y-a/2},{x:e.x+t/2,y:e.y+a/2}]})];return{width:Math.max(...s.map(e=>e.x))-Math.min(...s.map(e=>e.x)),height:Math.max(...s.map(e=>e.y))-Math.min(...s.map(e=>e.y))}}function hm(e){return e.filter((t,a)=>{let[s,i]=[e[a-1],e[a+1]];return!s||!i||!(.01>=Math.abs(s.x-t.x)&&.01>=Math.abs(t.x-i.x)||.01>=Math.abs(s.y-t.y)&&.01>=Math.abs(t.y-i.y))})}function hv(e,t,a=0,s=!0){let i=s?hm(e.slice(Math.max(0,a))):e.slice(Math.max(0,a)),l=s?hm(t):t,o=(e,t,a)=>e>Math.min(t,a)+.01&&e<Math.max(t,a)-.01,r=(e,t)=>.01>=Math.abs(e.y-t.y)&&Math.abs(e.x-t.x)>.01,n=(e,t)=>.01>=Math.abs(e.x-t.x)&&Math.abs(e.y-t.y)>.01,c=0;for(let e=0;e<i.length-1;e+=1)for(let t=0;t<l.length-1;t+=1){let[a,s,d,p]=[i[e],i[e+1],l[t],l[t+1]],[h,g]=r(a,s)&&n(d,p)?[[a,s],[d,p]]:n(a,s)&&r(d,p)?[[d,p],[a,s]]:[];h&&g&&o(g[0].x,h[0].x,h[1].x)&&o(h[0].y,g[0].y,g[1].y)&&(c+=1)}return c}function hy(e,t=!0){return e.reduce((a,s,i)=>a+e.slice(i+1).reduce((e,a)=>e+hv(s.points,a.points,0,t),0),0)}function hw(e,t,a=!0){let s=s_(hf(t,e)),i=e.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),l=sF(i,s);return sq(i,s).filter(e=>a||"endpoint-jog"!==e.kind).length+i.filter(e=>l(e).arrowheadsCrossed>0).length}function hx(e,t,a=!1,s=!0,i=!1,l=!0){let[o,r]=[e,t].map(e=>hy(e.edgeArrows,s)),[n,c]=[e,t].map(e=>hf([...e.nodeShapes,...d2(e.groups),...pe(e.lanes)],e.edgeArrows)),[d,p]=[n,c].map(({width:e,height:t})=>d$(e,t));return(a?o<r:o<=r)&&(d<2.45||d<=p+.01||i&&(({width:e,height:t})=>Math.max(e,t))(n)<=(({width:e,height:t})=>Math.max(e,t))(c)+.01)&&hw(e.edgeArrows,[...e.nodeShapes,...d2(e.groups),...pe(e.lanes)],l)<=hw(t.edgeArrows,[...t.nodeShapes,...d2(t.groups),...pe(t.lanes)],l)}function hb(e){return e.edgeArrows.filter((t,a)=>{let s=e.routedEdges[a],i=sp(hm(t.points)).slice(1,-1);return["source","target"].some(e=>{let t=s[e],a="source"===e?s.sourceEdge:s.targetEdge;return i.some(e=>{let[s,i,l,o]="horizontal"===e.orientation?[t.y,t.height,t.x,t.width]:[t.x,t.width,t.y,t.height],r=e.staticCoordinate<s?s-e.staticCoordinate:e.staticCoordinate-s-i;return("horizontal"===e.orientation?e.staticCoordinate<s?"top":"bottom":e.staticCoordinate<s?"left":"right")!==a&&r>0&&r<72&&e.min<l+o&&e.max>l})})}).length}function hk(e){let t=e.map(e=>hm(e.points)),a=[],s=(e,t,a)=>e>Math.min(t,a)+.01&&e<Math.max(t,a)-.01;for(let[e,i]of t.entries())for(let[l,o]of t.slice(e+1).entries())for(let t=0;t+1<i.length;t+=1)for(let r=0;r+1<o.length;r+=1){let[n,c,d,p]=[i[t],i[t+1],o[r],o[r+1]],[h,g]=.01>=Math.abs(n.y-c.y)&&.01>=Math.abs(d.x-p.x)?[[n,c],[d,p]]:.01>=Math.abs(n.x-c.x)&&.01>=Math.abs(d.y-p.y)?[[d,p],[n,c]]:[];h&&g&&s(g[0].x,h[0].x,h[1].x)&&s(h[0].y,g[0].y,g[1].y)&&a.push({first:e,second:e+1+l,at:{x:g[0].x,y:h[0].y}})}return a}function hM(e,t,a,s,i){let l=a,o=new Set,[r,n]=[6,24];for(let a=!0;a&&r>0;){a=!1;let c=hy(l.layout.edgeArrows),d=hk(l.layout.edgeArrows).flatMap(({first:t,second:a,at:s})=>(function(e,t,a,s,i,l){let o="TB"===s.layout.direction||"BT"===s.layout.direction,r=o?"y":"x",n=e=>pw(e)===r?pm[e]:e,c=d_(s),d=e=>!pd(e)&&void 0===e.pair&&void 0===e.pinned,p=e=>"source"===e?"sourceEdge":"targetEdge",h=(e,t,a)=>{if(pw(a)===r)return!0;let s=pi(e[t])[r],i=pi(e["source"===t?"target":"source"])[r];return pv[a][r]*(i-s)>.01},g=[],u=(e,t)=>f.get(e.edge.id)?.[p(t)]??e[p(t)],f=new Map,m=e=>{f=e,[...e].every(([e,t])=>{let a=l.find(t=>t.edge.id===e);return h(a,"source",t.sourceEdge??a.sourceEdge)&&h(a,"target",t.targetEdge??a.targetEdge)})&&!(dW(s)&&[...f.keys()].some(e=>{let t=l.find(t=>t.edge.id===e);return["source","target"].some(e=>{let a="source"===e?"target":"source",s=t[e],i=u(t,e);return l.some(e=>e!==t&&e[a]===s&&u(e,a)===i)})}))&&g.push(e)},v=o?["left","right"]:["top","bottom"];for(let a of[e,t].filter(d))if(c.has(a.edge.id))for(let e of[...v].sort((e,t)=>e===n(a.sourceEdge)?-1:+(t===n(a.sourceEdge))))(a.sourceEdge!==e||a.targetEdge!==e)&&m(new Map([[a.edge.id,{sourceEdge:e,targetEdge:e}]]));if(d(e)&&d(t))for(let a of["source","target"])for(let s of["source","target"]){let[i,l]=[e[p(a)],t[p(s)]];e[a].nodeId===t[s].nodeId&&i!==l&&m(new Map([[e.edge.id,{[p(a)]:l}],[t.edge.id,{[p(s)]:i}]]))}for(let a of new Set([e,t].map(e=>e.source))){if(!dx(a.kind))continue;let e=l.filter(e=>e.source===a&&d(e)&&!c.has(e.edge.id));if(e.length<2||e.length>3)continue;let t=e=>e.length<=1?[[...e]]:e.flatMap((a,s)=>t([...e.slice(0,s),...e.slice(s+1)]).map(e=>[a,...e]));for(let a of t(e.map(e=>e.sourceEdge))){let t=new Map(e.flatMap((e,t)=>a[t]===e.sourceEdge?[]:[[e.edge.id,{sourceEdge:a[t]}]]));t.size>0&&m(t)}}for(let{endpoint:s,route:l}of[e,t].filter(d).flatMap(e=>["source","target"].map(t=>{let{start:s,end:l}=pz(e,i),o="source"===t?s:l;return{endpoint:t,route:e,distance:Math.abs(o.x-a.x)+Math.abs(o.y-a.y)}})).sort((e,t)=>e.distance-t.distance)){let e=l[p(s)],t=pi(l[s]),a=pi(l["source"===s?"target":"source"]);for(let i of new Set([Math.abs(a.x-t.x)>Math.abs(a.y-t.y)?a.x>t.x?"right":"left":a.y>t.y?"bottom":"top",n(e),"top","right","bottom","left"]))i!==e&&m(new Map([[l.edge.id,{[p(s)]:i}]]))}return g})(l.layout.routedEdges[t],l.layout.routedEdges[a],s,e,l.layout.portOffsets??new Map,l.layout.routedEdges)),p=3;for(let h of d){if(0===r||0===p||0===n)break;let d=new Map(l.arrangement.sides);for(let[e,t]of h)d.set(e,{...d.get(e),...t});let g=JSON.stringify([...d].sort(([e],[t])=>e<t?-1:1));if(o.has(g)||(o.add(g),n-=1,function(e,t,a){let{layout:s}=e;if(!s.portOffsets||!s.routeOptions)return 0;let i=s.routedEdges.map(e=>({...e,...t.get(e.edge.id)})),l=hg(i,a.ports?pM(i,a.repair,e.arrangement.crossingRepair,s.lanes?54:pf):pu(i,a.repair)),o=new Set(i.flatMap(e=>t.has(e.edge.id)||["source","target"].some(t=>{let a=pn({edgeId:e.edge.id,endpoint:t});return l.get(a)!==s.portOffsets.get(a)})?[e.edge.id]:[])),r=(e,t)=>{let a=new Map(e.flatMap(e=>t.has(e.edgeId)?[]:[[e.edgeId,e]])),o=i.map((e,a)=>({index:a,again:t.has(e.edge.id)})).sort((e,t)=>Number(e.again)-Number(t.again)).map(({index:e})=>e);return hi(i,"orthogonal",l,s.nodeShapes,{...s.routeOptions,avoidCrossings:!0},o,a)},n=r(s.edgeArrows,o),c=new Set(hk(n).flatMap(({first:e,second:t})=>{let[a,s]=[i[e].edge.id,i[t].edge.id];return o.has(a)===o.has(s)?[]:[o.has(a)?s:a]}));return 0===c.size?hy(n):Math.min(hy(n),hy(r(n,c)))}(l,h,t)>=c))continue;[r,p]=[r-1,p-1];let u={...l.arrangement,sides:d,avoidCrossings:!0},f=hh(e,t,u),m=s(f);if(!i(l.defects,m)&&hx(f,l.layout,!0,!0,!0)&&hb(f)<=hb(l.layout)){l={arrangement:u,defects:m,layout:f},a=!0;break}}}return l}let hC={initial:"circle",final:"circle","final-core":"circle",choice:"diamond"},hz={initial:"Initial state",final:"Final state","final-core":"Final state",choice:"Choice"},h_="#4c4639",hL={subnet:"#f6f1e7",namespace:"#efe6ec"},hB=new WeakMap;function hS(e,t={}){var a,s;let i,l,o,r,n;hB.set(e,t);let c=e=>[ho(e.edgeArrows,e.nodeShapes,e.groups,e.lanes).length,hr(e.edgeArrows,e.nodeShapes)],d=(e,t)=>e[0]<t[0]||e[0]===t[0]&&e[1]<t[1],p="orthogonal"===e.layout.edgeRouting?[{ports:!0,reader:!0,sides:!0,repair:!0},{ports:!0,reader:!0,sides:!1,repair:!0},{ports:!0,reader:!1,sides:!1,repair:!0},{ports:!1,reader:!1,sides:!1,repair:!0},hd]:[{...hd,repair:!0},hd],h=(t=>{let[a,...s]=p,i=hh(e,a,t),l=c(i);for(let a of s){if(0===l[0]&&0===l[1])break;let s=hh(e,a,t),o=c(s);d(o,l)&&([i,l]=[s,o])}return{arrangement:t,defects:l,layout:i}})(dT),g=void 0===t.placement,u=(t,a)=>{let s=hh(e,p[0],t),i=c(s);!d(h.defects,i)&&hx(s,h.layout,a,!1)&&(h={arrangement:t,defects:i,layout:s})},f="orthogonal"===e.layout.edgeRouting,m=g&&f&&e.edges.length<=24;m&&hy(h.layout.edgeArrows,!1)>0&&u({...h.arrangement,crossingRepair:!0},!1),m&&hy(h.layout.edgeArrows,!1)>0&&function(e){if(dW(e))return!1;let t=dq(e);return(t?[t.top,...t.groups.map(e=>e.diagram)]:[e]).some(e=>{let[t,a]=[!1,!0].map(t=>dU(e,new Map,new Map,t).rankMetrics.map(e=>e.shapes.map(e=>e.nodeId).join("\n")).join("\n\n"));return t!==a})}(e)&&u({...h.arrangement,reorder:!0},!0);let v="TB"===e.layout.direction||"BT"===e.layout.direction,y=e=>{let t=hf([...e.nodeShapes,...d2(e.groups),...pe(e.lanes)],e.edgeArrows,[...he([...e.edgeArrows],e.routedEdges,e.nodeShapes,e.groups,!1,e.lanes)]),[a,s]=v?[t.height,t.width]:[t.width,t.height],i=(a+40)/(s+40),l=28e3/(Math.max(a,s)+40);return{aspect:i,balance:v&&i<4&&l>=14?.6:0,size:t,tooLong:i>=4||i>=2.45&&(v||a>=1200)}},{aspect:w,balance:x,tooLong:b}=y(h.layout),k=g&&f&&b?dW(e)?w>=4?function(e){let t,{columnCount:a,columns:s,depth:i,gapAfter:l,headerSize:o,poolBreadth:r}=dJ(e,new Map,new Map);if(a<4)return dX;let n=d_(e),c=Array.from({length:a-1},(t,a)=>{let i=e.edges.filter(e=>{let[t,i]=(e=>{let[t,a]=[s.get(e.source),s.get(e.target)];return[Math.min(t,a),Math.max(t,a)]})(e);return t<=a&&i>a});return i.some(e=>n.has(e.id))||i.length>2?void 0:i.map(e=>e.id)}),d=(e,t)=>o+96+i.slice(e,t+1).reduce((e,t)=>e+t,0)+l.slice(e,t).reduce((e,t)=>e+t,0),p=a-1,h=d$(d(0,p),r),g=(e,t)=>!t||e.longest<t.longest-.01||.01>=Math.abs(e.longest-t.longest)&&(e.carried<t.carried||e.carried===t.carried&&e.squares<t.squares);for(let e=2;e<=6;e+=1){let a,s=new Map;for(let e=1;e<p;e+=1)void 0!==c[e]&&s.set(e,{cuts:[e],longest:d(0,e),carried:c[e].length,squares:d(0,e)**2});for(let t=2;t<e;t+=1){let e=new Map;for(let[t,a]of s)for(let s=t+2;s<p;s+=1){if(void 0===c[s])continue;let i=d(t+1,s),l={cuts:[...a.cuts,s],longest:Math.max(a.longest,i),carried:a.carried+c[s].length,squares:a.squares+i**2};g(l,e.get(s))&&e.set(s,l)}s=e}for(let[e,t]of s){if(p<e+2)continue;let s=d(e+1,p),i={...t,longest:Math.max(t.longest,s),squares:t.squares+s**2};g(i,a)&&(a=i)}if(!a)continue;let i=e*r+(e-1)*dK(2),l=d$(a.longest,i);if((!t||l<t.aspect)&&(t={aspect:l,cuts:a.cuts}),l<=2)break}return!t||t.aspect>=h?dX:{bandOf:new Map(e.nodes.map(e=>{let a;return[e.id,(a=s.get(e.id),t.cuts.filter(e=>e<a).length)]})),continuations:new Set(t.cuts.flatMap(e=>c[e]))}}(e):dX:dG(e,h.arrangement.reorder,x):dX;for(let e of m&&!h.arrangement.crossingRepair?[!0,!1]:[h.arrangement.crossingRepair]){if(0===k.continuations.size||h.arrangement.wrap===k)break;u({...h.arrangement,crossingRepair:e,wrap:k},!1)}let M=dq(e),C=g&&f&&b&&void 0!==M&&!M.zoned;for(let e of m&&!h.arrangement.crossingRepair?[!0,!1]:[h.arrangement.crossingRepair]){if(!C||h.arrangement.groupsAcross)break;u({...h.arrangement,crossingRepair:e,groupsAcross:!0},!1)}let z=e=>[hy(e.edgeArrows,!1),hw(e.edgeArrows,[...e.nodeShapes,...d2(e.groups)]),y(e).aspect],_=(e,t)=>{let a=e.findIndex((e,a)=>e!==t[a]);return a>=0&&e[a]<t[a]};for(let t=0;t<2&&g&&f&&M?.zoned;t+=1){let t,a=y(h.layout);if(!a.tooLong)break;let s=h;for(let i of function(e,t,a,s,i){let l=new Map([["",t.top],...t.groups.map(e=>[e.group.id,e.diagram])]),o=function(e){let t=new Map(e.groups.map(e=>[e.group.id,e])),a=new Map,s=e=>{for(let a of e.children)s(t.get(a));let{rankMetrics:i}=dU(e.diagram,new Map,new Map),l=i.reduce((e,t)=>e+Math.max(...t.shapes.map(e=>a.get(e.nodeId)??1)),0);return a.set(dH(e.group.id),Math.max(2,l)),l};for(let t of e.groups)e.parentOf.has(t.group.id)||s(t);return a}(t),r=t=>{let s=dR(e,new Map,new Map,{...a,zoneWraps:t});return{bounds:dZ([...s.nodes,...d2(s.groups)]),placed:s}},n=new Map(a.zoneWraps??[]),c=r(n),[d,p]=[i.width/c.bounds.width,i.height/c.bounds.height],h=e=>{let{bounds:t,placed:a}=r(e);return{aspect:d$(t.width*d,t.height*p),placed:a}},g=(e,t)=>{let[a,s]=[e,t].map(e=>e.aspect<=2);return a!==s?a?-1:1:a&&e.bands-t.bands||e.aspect-t.aspect},u=n.size,f=h(n),m=[];for(;f.aspect>2;){let e=new Map([...f.placed.nodes.map(e=>[e.nodeId,e]),...(f.placed.groups?.frames??[]).map(e=>[dH(e.id),e.box])]),t=[];for(let[i,r]of l)if(!n.has(i))for(let l=2;l<=6;l+=1){let c=dG(r,a.reorder,s,{bands:l,sizes:e,weights:o});if(0===c.bandOf.size)continue;let d=new Map([...n,[i,c]]);if(t.push({...h(d),bands:l,next:d}),t.at(-1).aspect<=2)break}let i=t.filter(e=>e.aspect<f.aspect).sort(g),[r]=i;if(!r)break;n.size===u&&m.push(...i.slice(1,3).map(e=>e.next)),n=r.next,f=r}return n.size>u?[n,...m]:[]}(e,M,s.arrangement,a.balance,a.size)){let a={...s.arrangement,crossingRepair:m||s.arrangement.crossingRepair,zoneWraps:i},l=hh(e,p[0],a),o=c(l);if(d(s.defects,o)||!hx(l,s.layout,!1,!1,!1,!1))continue;let r=z(l);(!t||_(r,t.score))&&(t={arrangement:a,defects:o,layout:l,score:r});let[n,h]=z(s.layout);if(r[0]<=n&&r[1]<=h)break}if(!t)break;h=t}g&&f&&dW(e)&&u({...h.arrangement,separateRoles:!0},!1);let L=hy(h.layout.edgeArrows);if(m&&L>0&&L<=6&&(h=hM(e,p[0],h,c,d)),t.pairedReturns&&hy(h.layout.edgeArrows)>0){let t=h,a=new Map(h.layout.edgeArrows.map(e=>[e.edgeId,e])),s=new Set;for(let e of h.layout.routedEdges){let t=a.get(e.edge.id);if(void 0!==e.pair&&t&&h.layout.edgeArrows.some(e=>e!==t&&hy([t,e])>0))for(let t of h.layout.routedEdges)void 0!==t.pair&&(t.edge.id===e.edge.id||t.edge.source===e.edge.target&&t.edge.target===e.edge.source)&&s.add(t.edge.id)}if(s.size>0){u({...h.arrangement,unpairedReturns:s},!0);let a=hy(h.layout.edgeArrows);h!==t&&m&&a>0&&a<=6&&(h=hM(e,p[0],h,c,d));let i=new Set(h.layout.routedEdges.filter(e=>void 0!==e.pair).map(e=>e.edge.id));t.layout.routedEdges.some(e=>void 0!==e.pair&&!s.has(e.edge.id)&&!i.has(e.edge.id))&&(h=t)}}let B=f?function(e){let t,{groups:a,lanes:s,nodeShapes:i,routedEdges:l}=e,o=e.edgeArrows,r=[...i,...d2(a),...pe(s)],n=e=>({crossings:hy(e),defects:ho(e,i,a,s).length,findings:hw(e,r),inward:hr(e,i),labels:ht([...e],l,i,a,!0,s).touches});for(let[a,s]of e.edgeArrows.entries()){let e=new Set([s.sourceNodeId,s.targetNodeId]),l=pE(s.points,i,e);if(0!==l)for(let r of(t??=n(o),function(e,t,a){let s=hm(e),i=[];for(let e of sp(s))if(!e.isFirstSegment&&!e.isLastSegment)for(let l of t){if(!pH(l,a)||su(e,l)||!pV(e,l,12))continue;let[t,o]="horizontal"===e.orientation?[l.y,l.height]:[l.x,l.width];for(let a of[t-12-1,t+o+12+1]){let t=s.map((t,s)=>s===e.segmentIndex||s===e.segmentIndex+1?"horizontal"===e.orientation?{x:t.x,y:a}:{x:a,y:t.y}:t);(function(e,t){if(t.length!==e.length||!hs(t))return!1;let a=(e,t,a)=>({dx:e[a].x-e[t].x,dy:e[a].y-e[t].y}),s=e.length-1;return[[0,1],[s,s-1]].every(([s,i])=>{let[l,o]=[a(e,s,i),a(t,s,i)],r=Math.abs(l.dx)+Math.abs(l.dy);return Math.sign(o.dx)===Math.sign(l.dx)&&Math.sign(o.dy)===Math.sign(l.dy)&&Math.abs(o.dx)+Math.abs(o.dy)>=Math.min(r,36)-.01})})(s,t)&&i.push(pA(t))}}return i}(s.points,i,e))){if(!hs(r)||pE(r,i,e)>=l)continue;let s=o.map((e,t)=>t===a?{...e,points:r}:e),c=n(s);if(c.defects<=t.defects&&c.crossings<=t.crossings&&c.findings<=t.findings&&c.inward<=t.inward&&c.labels<=t.labels){[o,t]=[s,c];break}}}return o===e.edgeArrows?e:{...e,edgeArrows:o}}(h.layout):h.layout,{groups:S,lanes:A,routedEdges:P}=B,V=[...B.edgeArrows],H={arrows:V,frames:[],labels:[...B.nodeShapes.filter(e=>e.label).map(ps),...he(V,P,B.nodeShapes,S,!0,A)],nodes:B.nodeShapes},q=S&&!S.zoned?function(e,t){let a=new Map(e.frames.map(e=>[e.id,e])),s=t=>{let s=e.groupOf.get(t);return void 0===s?void 0:a.get(s)},i=new Map(t.labels.map(e=>[e.id,e])),l=new Map;for(let e of t.arrows){let t=s(e.sourceNodeId);if(!t||t!==s(e.targetNodeId))continue;let a=i.get(`${e.id}:label`),o=a?p1(a.text,a.maxWidth??160):void 0;(!a||!o||[{x:a.x-o.width/2,y:a.y-o.height/2},{x:a.x+o.width/2,y:a.y+o.height/2}].every(e=>d6(e,t.box)))&&e.points.every(e=>d6(e,t.box))&&l.set(e.id,t.elementId)}let o=new Map(t.nodes.flatMap(e=>{let t=s(e.nodeId);return t?[[e.id,t.elementId]]:[]}));return{arrows:t.arrows.map(e=>{let t=l.get(e.id);return t?{...e,frameId:t}:e}),frames:e.frames.map(t=>({type:"frame",id:t.elementId,name:t.label,...e.composites.has(t.id)?{nodeId:t.id}:{},...t.box})),labels:t.labels.map(e=>{let t=e.containerId?o.get(e.containerId):l.get(e.id.slice(0,-6));return t?{...e,frameId:t}:e}),nodes:t.nodes.map(e=>{let t=o.get(e.id);return t?{...e,frameId:t}:e})}}(S,H):H,{arrows:F,frames:I,labels:E}=q,O=q.nodes.flatMap(t=>(function(e,t){if(e.label)return[e];let a={...e,label:hz[e.kind??""]??"Marker",rendererRole:"state-marker"};if("initial"===e.kind)return[{...a,fillColor:t,fillStyle:"solid"}];if("final"!==e.kind)return[a];let s=[`marker:${e.nodeId}`,...e.groupIds??[]];return[{...a,groupIds:s},{...a,id:`${e.id}:core`,nodeId:`${e.nodeId}:core`,kind:"final-core",groupIds:s,x:e.x+6,y:e.y+6,width:e.width-12,height:e.height-12,fillColor:t,fillStyle:"solid"}]})(t,e.style.accentColor)),U=A?A.frames.flatMap(e=>{let t=d7(e),a={type:"node",id:`${t}:header`,nodeId:`${t}:header`,kind:"lane-header",rendererRole:"swimlane-header",shape:"rectangle",...e.header,label:e.text,fillColor:"#f6f1e7",fillStyle:"solid",roughness:0,strokeWidth:1,locked:!0};return[{type:"node",id:t,nodeId:t,kind:"lane",rendererRole:"swimlane",shape:"rectangle",...e.box,label:e.label,roughness:0,strokeWidth:1,locked:!0},a,{type:"text",id:`${t}:label`,containerId:a.id,x:a.x+a.width/2,y:a.y+a.height/2,text:e.text,fontSize:16,maxWidth:Math.max(1,a.width-32),locked:!0}]}):S?.zoned?(a=e.style.accentColor,S.frames.flatMap(e=>{var t;let s,i=Math.max(1,e.box.width-24);return[{type:"node",id:e.elementId,nodeId:e.elementId,kind:e.kind??"zone",rendererRole:"zone",shape:"rectangle",...e.box,label:e.label,...(t=e.kind,s=void 0===t?void 0:hL[t],{strokeColor:"cloud"===t||"datacenter"===t?h_:a,strokeStyle:"cloud"===t||"region"===t||"namespace"===t?"dashed":"zone"===t?"dotted":"solid",strokeWidth:"cloud"===t||"datacenter"===t||"vpc"===t||"cluster"===t?2:1,...s?{fillColor:s,fillStyle:"solid"}:{}}),roughness:0,locked:!0},{type:"text",id:`zone-label:${e.id}`,x:e.box.x+12+aF(e.label,dS,i)/2,y:e.box.y+18,text:e.label,fontSize:dS,maxWidth:i,textAlign:"left",textColor:h_,locked:!0}]})):[],X=(r=Math.max(0,48-(o={x:Math.min(...(l=hn(s=[...U,...I,...F,...O,...E])).map(e=>e.x)),y:Math.min(...l.map(e=>e.y))}).x),n=Math.max(0,48-o.y),0===r&&0===n?[...s]:s.map(e=>"arrow"===e.type?{...e,points:function(e,t,a){let[s,...i]=e;return[hc(s,t,a),...i.map(e=>hc(e,t,a))]}(e.points,r,n)}:"line"===e.type?{...e,points:function(e,t,a){let[s,i,...l]=e;return[hc(s,t,a),hc(i,t,a),...l.map(e=>hc(e,t,a))]}(e.points,r,n)}:{...e,x:e.x+r,y:e.y+n})),T={width:Math.max(...(i=hn(X)).map(e=>e.x))+48,height:Math.max(...i.map(e=>e.y))+48},Y=[...U.map(e=>e.id),...I.map(e=>e.id),...O.map(e=>e.id),...E.map(e=>e.id),...F.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:T.width,height:T.height,accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:X,layers:[],layouts:[],zOrder:Y}}function hA(e,t){if(!t.nodeId.endsWith(eI)||t.id!==`node:${t.nodeId}`||"rectangle"!==t.shape||2!==t.width||t.height<120)return!1;let a=t.nodeId.slice(0,-eI.length);if(0===a.length)return!1;let s=e.elements.find(e=>"node"===e.type&&e.id===`node:${a}`&&e.nodeId===a);return!!s&&.01>=Math.abs(t.x+t.width/2-(s.x+s.width/2))&&t.y>=s.y+s.height-.01}let hP=":initial";function hV(e,t,a,s){let i=0,l=new Map,o=new Map,r=(e,a,s)=>{let i=2*e+ +(a>=t[e]);l.set(i,(l.get(i)??0)+1);let r=1e6*i+Math.round(2*s);o.set(r,(o.get(r)??0)+1)};for(let{parent:a,child:l,link:o}of e.pairs)i+=function(e,t,a){let s=t-e;return 1===s?0:-1===s?.4:0===s?a:2.5*(Math.abs(s)-1)+.4*(s<0)}(t[a],t[l],s),r(a,t[l],o.parentY),r(l,t[a],o.childY);for(let e of l.values())i+=.4*e*(e-1)/2;for(let e of o.values())i+=+Math.max(0,e-2);let n=new Map,c=new Map;for(let[a,s]of e.tables.entries()){let e=t[a];n.set(e,(n.get(e)??-56)+s.height+56),c.set(e,Math.max(c.get(e)??0,s.width))}for(let e of n.values()){let t=Math.max(0,e-a.height)/a.unit;i+=1.5*t*t}let d=Math.max(0,[...c.values()].reduce((e,t)=>e+t,0)+150*Math.max(0,c.size-1)-a.width)/a.column;return i+1.5*d*d}function hH(e){let t=new Map([...new Set(e)].sort((e,t)=>e-t).map((e,t)=>[e,t]));return e.map(e=>t.get(e))}function hq(e){let t=e.tables.map(()=>new Set);for(let{parent:a,child:s}of e.pairs)t[a].add(s),t[s].add(a);return t}function hF(e,t,a,s){let i=hq(e),l=e.tables.map((e,t)=>t).sort((e,t)=>i[t].size-i[e].size||e-t),o=s(t);for(let e=0;e<a;e+=1){let e=!1;for(let a of l){let l=t[a],r=new Set([l-2,l-1,l+1,l+2]);for(let e of i[a])for(let a of[-1,0,1])r.add(t[e]+a);if(0===i[a].size)for(let e of t)r.add(e);r.delete(l);let n=l;for(let e of[...r].sort((e,t)=>e-t)){t[a]=e;let i=s(t);i<o-1e-9&&([n,o]=[e,i])}t[a]=n,n!==l&&(e=!0)}if(!e)break}}function hI(e,t){let a=[...t],s=e.tables.map(e=>e.height),i=e.tables.map(()=>void 0),l=[];for(let{parent:o,child:r,link:n}of e.pairs){let[e,c]=[t[o],t[r]];if(1>=Math.abs(c-e)){l.push({a:o,b:r,aY:n.parentY,bY:n.childY});continue}let d=Math.sign(c-e),p={item:o,y:n.parentY};for(let t=e+d;t!==c;t+=d){let e=a.length;a.push(t),s.push(4),i.push({parent:o,y:n.parentY}),l.push({a:p.item,b:e,aY:p.y,bY:2}),p={item:e,y:2}}l.push({a:p.item,b:r,aY:p.y,bY:n.childY})}return{column:a,height:s,corridor:i,segments:l}}function hE(e,t,a){let s=[t,a].filter(t=>void 0!==e.corridor[t]).length;return 2===s?20:1===s?26:56}function hO(e,t){let a=[],s=0;for(let[i,l]of t.entries())i>0&&(s+=hE(e,t[i-1],l)),a.push(s),s+=e.height[l];return a}function hU(e,t){let a=e.column.map(()=>0);for(let s of t)hX(e,a,s);return a}function hX(e,t,a){let s=hO(e,a),i=a.length>0?s.at(-1)+e.height[a.at(-1)]:0;for(let[e,l]of a.entries())t[l]=s[e]-i/2}function hT(e,t){let a=new Map,s=new Map,i=[],l=(e,t,a)=>{let i=2*e+ +!!t,l=s.get(i);l?l.push(a):s.set(i,[a])};for(let{a:s,b:o,aY:r,bY:n}of e.segments){let[c,d]=[e.column[s],e.column[o]],[p,h]=[t[s]+r,t[o]+n];if(c===d){i.push(c,Math.min(p,h),Math.max(p,h));continue}l(c,d>c,p),l(d,c>d,h);let g=Math.min(c,d),u=a.get(g),f=c<d?[p,h]:[h,p];u?u.push(...f):a.set(g,f)}let o=0;for(let e of a.values())for(let t=0;t<e.length;t+=2)for(let a=t+2;a<e.length;a+=2)(e[t]-e[a])*(e[t+1]-e[a+1])<0&&(o+=1);for(let e=0;e<i.length;e+=3){let[t,a,l]=[i[e],i[e+1],i[e+2]],r=e=>{let i=0;for(let o of s.get(2*t+e)??[])o>a&&o<l&&(i+=1);return i};o+=Math.min(r(0),r(1))}return o}function hY(e){let t=e.column.map(()=>[]);for(let{a,b:s,aY:i,bY:l}of e.segments)t[a].push({other:s,ownY:i,otherY:l}),t[s].push({other:a,ownY:l,otherY:i});return t}function h$(e,t=!0){let a=Array.from({length:Math.max(...e.column)+1},()=>[]);for(let[t,s]of e.column.entries())a[s].push(t);let s=hY(e),i=hU(e,a),l={columns:a.map(e=>[...e]),crossings:hT(e,i)};for(let t=0;t<8&&l.crossings>0;t+=1){let o=[...a.keys()];for(let l of(t%2==1&&o.reverse(),o)){let t=new Map;for(let o of a[l]){let a=0,r=0;for(let{other:t,ownY:n,otherY:c}of s[o]){let s=e.column[t]===l?.5:1;a+=s*(i[t]+c-n),r+=s}t.set(o,r>0?a/r:i[o])}a[l]=[...a[l]].sort((e,a)=>t.get(e)-t.get(a)||i[e]-i[a]),hX(e,i,a[l])}let r=hT(e,i);r<l.crossings&&(l={columns:a.map(e=>[...e]),crossings:r})}i=hU(e,a=l.columns);let o=hT(e,i);for(let s=t&&o>0;s;)for(let t of(s=!1,a))for(let i=0;i+1<t.length;i+=1){[t[i],t[i+1]]=[t[i+1],t[i]];let l=hT(e,hU(e,a));l<o?(o=l,s=!0):[t[i],t[i+1]]=[t[i+1],t[i]]}return{columns:a,top:hU(e,a),crossings:o}}let hG={one:"crowfoot_one","zero-or-one":"crowfoot_one",many:"crowfoot_many","one-or-many":"crowfoot_one_or_many","zero-or-many":"crowfoot_many"};function hD(e){return"one"===e||"zero-or-one"===e}let hR=e=>Math.ceil(Math.max(0,...e.map(e=>aq(e,14))));function hZ(e,t){return t.get(e.link[e.end].entity).y+e.row}function hj(e,t){return t.get(e.link[e.end].entity).y+e.y}function hN(e,t){return 1>Math.abs(e.x+e.width/2-(t.x+t.width/2))}function hW(e,t,a){return hN(e.get(t.link[t.end].entity),e.get(a.link[a.end].entity))}function hJ(e,t){let a=t.get(e.link[e.end].entity),s=[...t.values()].filter(e=>hN(e,a));return"left"===e.side?a.x-Math.min(...s.map(e=>e.x)):Math.max(...s.map(e=>e.x+e.width))-(a.x+a.width)}function hK(e,t){return e.find(e=>e.link===t.link&&e!==t)}function hQ(e){let t=new Map;for(let a of e){if("top"===a.side)continue;let e=`${a.link[a.end].entity}\0${a.side}\0${a.row}`;t.set(e,[...t.get(e)??[],a])}return[...t.values()]}function h1(e,t){let a=e.flatMap(e=>{let a=t.sides.get(e.relationship.id);return["parent","child"].map(t=>({link:e,end:t,side:a[t],row:e[t].y,y:e[t].y}))});for(let t of e){if(t.parent.entity!==t.child.entity)continue;let[e,s]=a.filter(e=>e.link===t);e&&s&&e.row===s.row&&(s.side="top")}return a}function h0(e,t,a,s,i){let l=function(e,t){let a=hQ(e),s=e=>(20===e.row?40:28)/2-3,i=new Map;for(let l of a){if(l.length<2)continue;let a=a=>hZ(hK(e,a),t)-hZ(a,t),o=l.filter(e=>0>a(e)).sort((e,t)=>a(e)-a(t)),r=l.filter(e=>a(e)>0).sort((e,t)=>a(e)-a(t)),n=[...o,...l.filter(e=>0===a(e)),...r],c=Math.min(22,2*s(l[0])/(n.length-1));n.forEach((e,t)=>{e.y=e.row+(t-(n.length-1)/2)*c});let d=(e,a)=>i.set(e,hJ(e,t)+48+32*a);o.forEach(d),r.toReversed().forEach(d)}for(let i of a){if(i.length>1)continue;let a=i[0],l=hK(e,a);if(l.side===a.side||"top"===l.side)continue;let o=hj(l,t)-(hZ(a,t)-a.row);Math.abs(o-a.row)<=s(a)&&(a.y=o)}for(let a of e)"top"!==a.side&&!i.has(a)&&hJ(a,t)>0&&i.set(a,hJ(a,t)+48);let l=new Map;for(let t of e){if("top"===t.side)continue;let e=`${t.link[t.end].entity}\0${t.side}`;l.set(e,[...l.get(e)??[],t])}for(let e of l.values()){let{height:a}=t.get(e[0].link[e[0].end].entity);!function(e,t,a){if(e.length<2)return;let s=(t,a)=>e[a].row===e[a-1].row?t:Math.max(t,9),i=i=>{let l=-1/0;for(let[o,r]of e.entries())if((l=Math.max(t(r),o>0?l+s(i,o):l))>a(r)+1e-9)return!1;return!0},[l,o]=[0,22];if(i(o))l=o;else for(let e=0;e<24;e+=1){let e=(l+o)/2;i(e)?l=e:o=e}let r=e.map(a);for(let t=e.length-2;t>=0;t-=1)r[t]=Math.min(r[t],r[t+1]-s(l,t+1));let n=-1/0;for(let[a,i]of e.entries()){let e=a>0?n+s(l,a):-1/0;i.y=Math.min(Math.max(i.y,t(i),e),r[a]),n=i.y}}(e.sort((e,t)=>e.row-t.row||e.y-t.y),e=>Math.max(e.row-s(e),16),e=>Math.min(e.row+s(e),a-16))}return i}(i,s.boxes);!function(e,t,a){let s=e.filter(e=>"parent"===e.end).flatMap(a=>{let s=hK(e,a);return a.side===s.side&&"top"!==a.side&&hW(t,a,s)?[{parent:a,child:s}]:[]}).sort((e,a)=>Math.abs(hj(e.parent,t)-hj(e.child,t))-Math.abs(hj(a.parent,t)-hj(a.child,t))),i=[];for(let{parent:e,child:l}of s){let[s,o]=[t.get(e.link.parent.entity),t.get(e.link.child.entity)],r=e=>(a.get(e)??hJ(e,t)+48)-hJ(e,t),n=Math.max(r(e),r(l)),[c,d]=[hj(e,t),hj(l,t)].sort((e,t)=>e-t),p=i.filter(a=>a.end.side===e.side&&hW(t,a.end,e)&&a.top<=d&&c<=a.bottom);if("left"===e.side){let r=Math.min(s.x-hJ(e,t)-n,...p.map(e=>e.tip-32));a.set(e,s.x-r),a.set(l,o.x-r),i.push({end:e,top:c,bottom:d,tip:r})}else{let r=Math.max(s.x+s.width+hJ(e,t)+n,...p.map(e=>e.tip+32));a.set(e,r-s.x-s.width),a.set(l,r-o.x-o.width),i.push({end:e,top:c,bottom:d,tip:r})}}}(i,s.boxes,l);let o=new Map(i.map(e=>{var a,s;let o=t.get(e.link[e.end].entity),r="top"===e.side?("left"===(a=i,s=e.link,a.find(e=>e.link===s&&"parent"===e.end)?.side??"right")?-1:1)*(o.width/2-28):e.y-o.height/2,n=l.get(e);return[`${e.link.relationship.id}:${"parent"===e.end?"source":"target"}`,{side:e.side,offset:r,...void 0===n?{}:{run:n}}]}));return hS({id:e.id,title:e.title,type:"flowchart",nodes:e.entities.map(e=>({id:e.id,label:tk(e),kind:"entity",metadata:{}})),edges:a.map(e=>({id:e.relationship.id,source:e.parent.entity,target:e.child.entity,metadata:{},...e.relationship.label?{label:e.relationship.label}:{}})),layout:{direction:"LR",edgeRouting:"orthogonal"},style:e.style,metadata:{}},{placement:s.boxes,anchors:o,endRun:48})}let h2=[...["layered","hub"].flatMap(e=>[1.6,1.1,.7,.5].map(t=>({start:e,aspect:t,sameColumn:1}))),{aspect:.5,sameColumn:0}];function h3(e){let t=e.elements.filter(e=>"arrow"===e.type),a=Math.max(e.width/e.height,e.height/e.width);return hy(t)+sq(t.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),s_({width:e.width,height:e.height})).length+(a>2?4*(a-2):0)+t.reduce((e,t)=>e+function(e){let[t,a]=[e.points[0],e.points.at(-1)],s=0;for(let[t,a]of e.points.slice(1).entries())s+=Math.abs(a.x-e.points[t].x)+Math.abs(a.y-e.points[t].y);return Math.max(0,s/(Math.abs(a.x-t.x)+Math.abs(a.y-t.y)+96+200)-1)}(t),0)+function(e){let t=new Map;for(let a of e)for(let[e,s]of[[a.sourceNodeId,a.points[0]],[a.targetNodeId,a.points.at(-1)]]){let a=`${e}\0${Math.round(s.x)}`;t.set(a,[...t.get(a)??[],s.y])}let a=0;for(let e of t.values()){e.sort((e,t)=>e-t);let t=!1;for(let[s,i]of e.slice(1).entries()){let l=i-e[s]<21.99;l&&(a+=t?.25:1),t=l}}return a}(t)+function(e,t){let a=new Map(e.elements.flatMap(e=>"node"===e.type?[[e.nodeId,e]]:[])),s=0;for(let e of t){let[t,i]=[a.get(e.sourceNodeId),a.get(e.targetNodeId)];if(t&&i&&(!(t.x<i.x+i.width)||!(i.x<t.x+t.width)))for(let[t,a,i]of[[e.points[0],e.points[1],e.points.at(-1)],[e.points.at(-1),e.points.at(-2),e.points[0]]])(a.x-t.x)*(i.x-t.x)<0&&(s+=1)}return s}(e,t)+h5*function(e,t){let a=e.elements.flatMap(e=>"node"===e.type?[e]:[]),s=new Map(a.map(e=>[e.nodeId,e])),i=0;for(let e of t){let[t,l]=[s.get(e.sourceNodeId),s.get(e.targetNodeId)];if(!t||!l||t===l||!(t.x<l.x+l.width&&l.x<t.x+t.width))continue;let[o,r]=[Math.min(t.y+t.height,l.y+l.height),Math.max(t.y,l.y)];i+=a.filter(e=>e!==t&&e!==l&&e.y>=o&&e.y+e.height<=r&&e.x<Math.max(t.x+t.width,l.x+l.width)&&Math.min(t.x,l.x)<e.x+e.width).length}return i}(e,t)}let h5=.25;function h4(e,t,a,s,i,l=32){let o=e.points,[r,n]="start"===t?[o[0],o[1]]:[o.at(-1),o.at(-2)],c=n?Math.hypot(n.x-r.x,n.y-r.y):1,[d,p]=n?[(n.x-r.x)/c,(n.y-r.y)/c]:[1,0],h={x:r.x+d*l,y:r.y+p*l};return{type:"node",id:`node:${a}:optional:${s}`,nodeId:`${a}:optional:${s}`,kind:"optional",rendererRole:"er-optional",shape:"circle",x:h.x-6,y:h.y-6,width:12,height:12,label:"Optional end",fillColor:i.style.backgroundColor,fillStyle:"solid",strokeColor:i.style.accentColor,groupIds:[`table:${a}`]}}function h6(e,t,a,s,i){let l=0;for(let{parent:a,child:s}of e.generalizations){let e=t[s]-t[a];if(e<1)return 1/0;l+=2.5*(e-1)}let o=e.boxes.map(()=>0);for(let{a,b:r,whole:n}of e.others){let e=Math.abs(t[a]-t[r]);0===e?(o[a]+=1,o[r]+=1):l+=s+2.5*(e-1),n&&t[a]>t[r]&&(l+=i)}for(let e of o)l+=1.5*Math.max(0,e-2);let r=e.boxes.map((e,t)=>t),n=e=>r[e]===e?e:r[e]=n(r[e]);for(let{a,b:s}of e.others){if(t[a]!==t[s])continue;let[e,i]=[n(a),n(s)];e===i?l+=1.5:r[e]=i}let c=new Map,d=new Map;for(let[a,s]of e.boxes.entries()){let e=t[a];c.set(e,(c.get(e)??-64)+s.width+64),d.set(e,Math.max(d.get(e)??0,s.height))}for(let e of c.values()){let t=Math.max(0,e-a.width)/a.column;l+=1.5*t*t}let p=Math.max(0,[...d.values()].reduce((e,t)=>e+t,0)+130*Math.max(0,d.size-1)-1.2*a.height)/a.unit;return l+1.5*p*p}function h7(e,t,a,s){let i=[a,s].filter(t=>e.corridor[t]).length;return 2===i?28:1===i?Math.max(30,t.get(a<s?`${a}:${s}`:`${s}:${a}`)??0):Math.max(64,t.get(a<s?`${a}:${s}`:`${s}:${a}`)??0)}function h8(e,t,a){let s=[];for(let[i,l]of a.entries()){if(0===i){s.push(0);continue}let o=a[i-1],r=s[i-1]+e.width[o]+h7(e,t,o,l);for(let[o,n]of a.slice(0,i-1).entries()){let a=t.get(n<l?`${n}:${l}`:`${l}:${n}`);void 0!==a&&(r=Math.max(r,s[o]+e.width[n]+a))}s.push(r)}return s}function h9(e,t,a){let s=e.row.map(()=>0);for(let i of a){let a=h8(e,t,i),l=i.length>0?a.at(-1)+e.width[i.at(-1)]:0;for(let[t,o]of i.entries())s[o]=a[t]+e.width[o]/2-l/2}return s}function ge(e,t,a){let s=new Map;for(let{upper:t,lower:i}of e.segments){let l=s.get(e.row[t])??[];l.push({upper:a[t],lower:a[i]}),s.set(e.row[t],l)}let i=0;for(let e of s.values())for(let[t,a]of e.entries())for(let s of e.slice(t+1))(a.upper-s.upper)*(a.lower-s.lower)<0&&(i+=1);let l=new Map;for(let e of t)for(let[t,a]of e.entries())l.set(a,t);let o=e.flats.map(({a:t,b:a})=>{let[s,i]=[l.get(t),l.get(a)].sort((e,t)=>e-t);return{row:e.row[t],low:s,high:i}});for(let a of o){let s=t[a.row];for(let t=a.low+1;t<a.high;t+=1)e.corridor[s[t]]||(i+=1)}for(let[e,t]of o.entries())for(let a of o.slice(e+1))t.row===a.row&&(t.low<a.low&&a.low<t.high&&t.high<a.high||a.low<t.low&&t.low<a.high&&a.high<t.high)&&(i+=1);return i}function gt(e,t){let a=[];for(let[s,i]of e.entries()){let e=t[s];for(a.push({count:1,weight:e,sum:i*e});a.length>1;){let e=a.at(-1),t=a.at(-2);if(t.sum/t.weight<=e.sum/e.weight)break;a.pop(),t.count+=e.count,t.weight+=e.weight,t.sum+=e.sum}}return a.flatMap(e=>Array(e.count).fill(e.sum/e.weight))}function ga(e,t){return e.find(e=>e.link===t.link&&e!==t)}let gs=e=>"top"===e||"bottom"===e;function gi(e,t){let a=(e,t)=>e>t.min+.5&&e<t.max-.5,s=(e,t)=>t.some(t=>.5>Math.abs(e-t)),i=0;for(let s of t.upper)a(s,e)&&(i+=1);for(let s of e.lower)a(s,t)&&(i+=1);for(let a of e.lower)s(a,t.upper)&&(i+=1e3);return i}let gl={inheritance:{stroke:"solid",from:null,to:"triangle_outline"},realization:{stroke:"dashed",from:null,to:"triangle_outline"},composition:{stroke:"solid",from:"diamond",to:null},aggregation:{stroke:"solid",from:"diamond_outline",to:null},association:{stroke:"solid",from:null,to:null},dependency:{stroke:"dashed",from:null,to:"arrow"}},go=e=>e.length>0?12+22*e.length:14;function gr(e,t){return[e["from"===t?"fromMultiplicity":"toMultiplicity"],e["from"===t?"fromRole":"toRole"]].flatMap(e=>e?[e.trim()]:[])}let gn=e=>Math.ceil(aq(e,13))+2,gc="label-room:",gd=[{wholeBelow:1.5},{},{aspect:1.1},{between:1}];function gp(e,t,a){return e.left<t.right+a&&t.left<e.right+a&&e.top<t.bottom+a&&t.top<e.bottom+a}let gh=(e,t,a)=>({x:e.x+t,y:e.y+a}),gg=(e,t,a)=>({...e,x:e.x+t,y:e.y+a}),gu=(e,t,a)=>({x0:e.x0+t,x1:e.x1+t,y0:e.y0+a,y1:e.y1+a}),gf=e=>({x0:e.x,x1:e.x+e.width,y0:e.y,y1:e.y+e.height});function gm(e){let t=e.filter((t,a)=>0===a||Math.abs(t.x-e[a-1].x)>.01||Math.abs(t.y-e[a-1].y)>.01);return t.filter((e,a)=>{if(0===a||a===t.length-1)return!0;let s=t[a-1],i=t[a+1],l=.01>Math.abs(s.x-e.x)&&.01>Math.abs(e.x-i.x),o=.01>Math.abs(s.y-e.y)&&.01>Math.abs(e.y-i.y);return!l&&!o})}function gv(e){return e.slice(1).map((t,a)=>{let s=e[a];return{x0:Math.min(s.x,t.x)-1,x1:Math.max(s.x,t.x)+1,y0:Math.min(s.y,t.y)-1,y1:Math.max(s.y,t.y)+1}})}function gy(){return{boxes:[],cards:new Map,links:[],regions:[],rows:new Map,attach:0,tails:[],top:0}}function gw(e,t,a){e.cards.set(t,a),e.boxes.push(gf(a))}function gx(e,t,a,s){let i=gm(s);e.links.push({manager:t,report:a,points:i}),e.boxes.push(...gv(i))}function gb(e,t,a,s){for(let[i,l]of t.cards)e.cards.set(i,gg(l,a,s));for(let[i,l]of(e.boxes.push(...t.boxes.map(e=>gu(e,a,s))),e.links.push(...t.links.map(e=>({...e,points:e.points.map(e=>gh(e,a,s))}))),e.regions.push(...t.regions.map(e=>({...e,frame:gg(e.frame,a,s)}))),t.rows))e.rows.set(i,l)}function gk(e){return{x0:Math.min(...e.map(e=>e.x0)),x1:Math.max(...e.map(e=>e.x1)),y0:Math.min(...e.map(e=>e.y0)),y1:Math.max(...e.map(e=>e.y1))}}let gM=e=>0===e.reports.length&&0===e.assistants.length,gC=e=>0===e.assistants.length&&e.reports.length>0&&e.reports.every(gM),gz=e=>e.reports.length>=2&&e.reports.some(gC)&&e.reports.every(e=>gM(e)||gC(e))&&e.reports.every(e=>void 0===e.region);function g_(e,t,a=5){let s=gy(),i=void 0===t&&e.length>=a,l=0;e.forEach((a,o)=>{let r=t??(i&&o%2==0?-1:1),n=1===r?18:-18-a.width;gw(s,a.id,{x:n,y:l,width:a.width,height:a.height});let c=l+a.height/2;s.tails.push({report:a.id,points:[{x:0,y:c},{x:1===r?n:n+a.width,y:c}]}),i&&1!==r&&o!==e.length-1||(l+=a.height+14)});let o=Math.max(...s.tails.map(e=>e.points[0].y));return s.boxes.push({x0:-1,x1:1,y0:-28,y1:o}),s}function gL(e,t,a,s,i,l,o){for(let r of i)gx(e,t,r.report,[a,...s,...r.points.map(e=>gh(e,l,o))])}function gB(e,t,a){let s=0;for(let i=t;i<a;i+=1)s+=e[i];return s+24*Math.max(0,a-t-1)}function gS(e,t,a){let s={split:t,half:gB(e,t,a),imbalance:gB(e,t,a)};for(let i=t+1;i<a;i+=1){let l=gB(e,t,i),o=gB(e,i,a),r=Math.max(l,o),n=Math.abs(l-o);(r<s.half-1e-9||r<s.half+1e-9&&n<s.imbalance-1e-9)&&(s={split:i,half:r,imbalance:n})}return s}function gA(e,t=[]){let a=[];for(let s of e){let e=sv(t,s.block.boxes,24,8),i=Number.isFinite(e)?e:0===a.length?0:-1/0,l=Number.isFinite(i)?i:Math.max(...t.map(e=>e.x1))+24-gk(s.block.boxes).x0;a.push(l),t.push(...s.block.boxes.map(e=>gu(e,l,0)))}return a}function gP(e){let t=gk(e.boxes);return t.x1-t.x0}function gV(e,t){let a=e.map(e=>(function e(t,a,s,i){let l=gy(),{width:o,height:r}=t;gw(l,t.id,{x:-o/2,y:0,width:o,height:r}),l.tails.push({report:t.id,points:[{x:0,y:0}]});let n={x:0,y:r},c=t.reports.length>0&&t.reports.every(gM)&&(void 0!==i||t.reports.length>=a.stackMin&&t.reports.length<=20),d=c&&(void 0!==i||t.reports.length<a.twoColumns),p=r,h=gz(t)?a.outline.get(t.id):void 0,g=d||1===h||2===h&&t.reports.length<3;if(t.assistants.forEach((e,a)=>{let s=g||a%2==0?1:-1,i=r+16+(g?a:Math.floor(a/2))*(e.height+14),o=1===s?22:-22-e.width;gw(l,e.id,{x:o,y:i,width:e.width,height:e.height});let c=i+e.height/2;gx(l,t.id,e.id,[n,{x:0,y:c},{x:1===s?o:o+e.width,y:c}]),p=Math.max(p,i+e.height)}),0===t.reports.length)return l;let u=s||void 0!==t.region;if(c){let e=i??1,s=g_(t.reports,d?e:void 0,a.twoColumns),n=d?e*(-o/2+20):0,c=p+18;return gb(l,{...s,links:[],regions:[],rows:new Map,tails:[]},n,c),gL(l,t.id,{x:n,y:r},[],s.tails,n,c),l}if(void 0!==h){let s=2===h&&t.reports.length>=3,i=s?0:-o/2+20,n=new Map([[1,p+18],[-1,p+18]]);return t.reports.forEach((o,c)=>{let d=s&&c%2==0?-1:1,p=n.get(d),h=e(o,a,u,d),g=i+d*(18+o.width/2);gb(l,h,g,p);let f=p+o.height/2;gx(l,t.id,o.id,[{x:i,y:r},{x:i,y:f},{x:g-d*o.width/2,y:f}]),n.set(d,p+gk(h.boxes).y1+14)}),l}let f=t.reports.filter(gM),m=f.length>=a.stackMin,v=Math.ceil(f.length/20),y=[];for(let s of t.reports){if(m&&gM(s)){if(s===f[0])for(let e=0;e<v;e+=1){let t=g_(f.slice(Math.round(e*f.length/v),Math.round((e+1)*f.length/v)),void 0,a.twoColumns);y.push({block:t,width:gP(t)})}continue}let t=e(s,a,u),i=u?t:function(e,t){if(!t.region)return e;let a=gk(e.boxes),s={x0:Math.min(a.x0-20,e.attach-10-t.region.nameWidth-8),x1:a.x1+20,y0:a.y0-20,y1:a.y1+20},i=s.y0-21-4;return{...e,boxes:[{...s,x0:s.x0-10,x1:s.x1+10,y0:i}],regions:[...e.regions,{root:t.id,label:t.region.label,frame:{x:s.x0,y:s.y0,width:s.x1-s.x0,height:s.y1-s.y0},members:[...e.cards.keys()]}],top:i}}(t,s);y.push({block:i,width:gP(i),root:s.id})}let w=Math.max(1,Math.min(a.rows.get(t.id)??1,y.length)),x=function(e,t,a){let s,i=e.length,l=(e,t)=>!t||e.half<t.half-1e-9||e.half<t.half+1e-9&&e.imbalance<t.imbalance-1e-9,o=Array.from({length:a+1},()=>Array.from({length:i+1},()=>void 0));o[0][0]={half:0,imbalance:0,cut:0};for(let e=1;e<a;e+=1)for(let s=e;s<=i-(a-e);s+=1)for(let a=e-1;a<s;a+=1){let i=o[e-1][a];if(!i)continue;let r=gS(t,a,s),n={half:Math.max(i.half,r.half),imbalance:i.imbalance+r.imbalance,cut:a};l(n,o[e][s])&&(o[e][s]=n)}for(let e=a-1;e<i;e+=1){let r=o[a-1][e];if(!r)continue;let n={half:Math.max(r.half,gB(t,e,i)/2),imbalance:r.imbalance,cut:e};l(n,s)&&(s=n)}let r=[e.slice(s.cut)],n=s.cut;for(let t=a-1;t>=1;t-=1){let a=o[t][n].cut;r.unshift(e.slice(a,n)),n=a}return r}(y,y.map(e=>e.width),w),b=p,k=0;x.forEach((e,a)=>{let s;if(a===x.length-1){s=gA(e);let t=e.map((e,t)=>s[t]+e.block.attach),a=(Math.min(...t)+Math.max(...t))/2;s=s.map(e=>e-a)}else{let{split:t}=gS(e.map(e=>e.width),0,e.length),a={x0:-1,x1:1,y0:-1e6,y1:1e6};s=[...function(e,t){let a=Array.from({length:e.length},()=>0);for(let s=e.length-1;s>=0;s-=1){let i=e[s],l=function(e,t,a=0){let s=1/0;for(let i of t)for(let t of e)i.y0<t.y1+a&&t.y0<i.y1+a&&(s=Math.min(s,t.x0-24-i.x1));return s}(t,i.block.boxes,8),o=Number.isFinite(l)?l:Math.min(...t.map(e=>e.x0))-24-gk(i.block.boxes).x1;a[s]=o,t.push(...i.block.boxes.map(e=>gu(e,o,0)))}return a}(e.slice(0,t),[a]),...gA(e.slice(t),[a])]}let i=Math.max(0,...e.map(e=>-e.block.top)),o=b+28,r=b+56+i,c=[];e.forEach((e,a)=>{let i=s[a];gb(l,e.block,i,r),gL(l,t.id,n,[{x:0,y:o},{x:i+e.block.attach,y:o}],e.block.tails,i,r),c.push(...e.block.boxes.map(e=>gu(e,i,r)))});let d=gk(c);k=Math.max(k,d.x1-d.x0),b=d.y1});let M=y.reduce((e,t)=>t.width>e.width?t:e);return l.rows.set(t.id,{width:k,widestItem:M.width,widest:M.root,items:y.length,rows:x.length}),l})(e,t,!1)),s=gy(),i=[];for(let e of a){let t=sv(i,e.boxes,64,8),a=Number.isFinite(t)?t:0;gb(s,e,a,0),i.push(...e.boxes.map(e=>gu(e,a,0)))}let l=gk(gH(s)),o=gy();return gb(o,s,-l.x0,-l.y0),o}function gH(e){return[...[...e.cards.values()].map(gf),...e.links.flatMap(e=>gv(e.points)),...e.regions.map(e=>({...gf(e.frame),y0:e.frame.y-21-4}))]}function gq(e){let t,a,s;return Math.max(1,Math.max((s=((a=gk(gH(e))).x1-a.x0+40)/(a.y1-a.y0+40))/2.4,.45/s))*Math.max(1,((t=gk(gH(e))).x1-t.x0+80)*(t.y1-t.y0+80+64)/56e5)}let gF="#6250d6",gI=[14,22,30],gE=[8,18,26,36];function gO(e,t,a){let s=(e,t)=>Number.parseInt(e.slice(t,t+2),16);return`#${[1,3,5].map(i=>Math.round(s(t,i)+(s(e,i)-s(t,i))*a).toString(16).padStart(2,"0")).join("")}`}function gU(e,t,a){let s=e=>e.split("\n").length,i=aO(e,t,a);if(1===s(i))return i;let l=a,o=t;for(;o-l>1;){let t=Math.floor((l+o)/2);s(aO(e,t,a))<=s(i)?o=t:l=t}return aO(e,o,a)}let gX=e=>void 0===e?0:e.split("\n").length,gT=(e,t)=>Math.ceil(gX(e)*t*1.25),gY=(e,t=0)=>({left:e.x-t,top:e.y-t,right:e.x+e.width+t,bottom:e.y+e.height+t});function g$(e,t,a){let{x:s,y:i,width:l,height:o}=e;return[{x:s+l,y:i+o/2,outward:0,cost:0},{x:s,y:i+o/2,outward:2,cost:0},{x:s+l,y:i+o/4,outward:0,cost:4},{x:s,y:i+o/4,outward:2,cost:4},{x:s+3*l/4,y:i+o,outward:1,cost:6},{x:s+l/4,y:i+o,outward:1,cost:6},{x:s+3*l/4,y:i,outward:3,cost:6},{x:s+l/4,y:i,outward:3,cost:6}].filter(e=>!t.some(t=>Math.abs(t.x-e.x)+Math.abs(t.y-e.y)<14)).map(e=>({x:e.x,y:e.y,direction:a?(e.outward+2)%4:e.outward,cost:e.cost}))}function gG(e,t){let a=0;for(let s of cq(e)){let e=.01>Math.abs(s.to.y-s.from.y);for(let i of t){if(e===.01>Math.abs(i.to.y-i.from.y))continue;let[t,l]=e?[s,i]:[i,s],o=l.from.x,r=t.from.y;o>Math.min(t.from.x,t.to.x)+.5&&o<Math.max(t.from.x,t.to.x)-.5&&r>Math.min(l.from.y,l.to.y)+.5&&r<Math.max(l.from.y,l.to.y)-.5&&(a+=1)}}return a}function gD(e,t){let a=cq(e);return 24*Math.max(0,a.length-1)+a.reduce((e,t)=>e+Math.abs(t.to.x-t.from.x)+Math.abs(t.to.y-t.from.y),0)+500*gG(e,t)}let gR=(e,t,a)=>e.left<t.right+a&&t.left<e.right+a&&e.top<t.bottom+a&&t.top<e.bottom+a;function gZ(e,t,a,s){return gR({left:Math.min(e.x,t.x),right:Math.max(e.x,t.x),top:Math.min(e.y,t.y),bottom:Math.max(e.y,t.y)},a,s)}function gj(e,t,a,s,i,l){if(0===e.dottedLines.length)return{arrows:[],labels:[],straight:0};let o=new Map;for(let e of i){let t=e.points[0],a=e.points.at(-1);o.set(e.sourceNodeId,[...o.get(e.sourceNodeId)??[],t]),o.set(e.targetNodeId,[...o.get(e.targetNodeId)??[],a])}let r=i.flatMap(e=>cq(e.points)),n=[...t.values()].flatMap(e=>[e.y,e.y+e.height]),c=e=>[...t.values()].flatMap(t=>e.flatMap(e=>[t.y-e,t.y+t.height+e])),d=[...t.values()],p=d.flatMap(e=>{let t=d.filter(t=>t.y>=e.y+e.height&&t.x<e.x+e.width&&e.x<t.x+t.width).map(e=>e.y);return 0===t.length?[]:[(e.y+e.height+Math.min(...t))/2]}),h=a.map(e=>s$(e)),g=Math.min(...n,...h.map(e=>e.y)),u=Math.max(...n,...a.map(e=>e.y+e.height)),f=[...h.map(e=>e.y-10),...a.flatMap(e=>[e.y+e.height+14,e.y+e.height+24]),g-24,u+24],m=[...c(gI),...p,...f],v=[...c([...gI,...gE]),...p,...f],y=g-60-10*e.dottedLines.length,w=u+60,x={left:Math.min(...d.map(e=>e.x),...a.map(e=>e.x))-60,right:Math.max(...d.map(e=>e.x+e.width),...a.map(e=>e.x+e.width))+60},b={remaining:Math.min(4e5,48e3*e.dottedLines.length)},k=[],M=[],C=[],z=0,_=0,L=a.flatMap(e=>cq([{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x+e.width,y:e.y+e.height},{x:e.x,y:e.y+e.height},{x:e.x,y:e.y}])),B=(e,t)=>{let a,s=cq(t).toSorted((e,t)=>Math.abs(t.to.x-t.from.x)+Math.abs(t.to.y-t.from.y)-(Math.abs(e.to.x-e.from.x)+Math.abs(e.to.y-e.from.y))),i=[...r,...cq(t)],l=aq(e,13),o=[1,2,3].map(t=>{let a=1===t?e:gU(e,Math.ceil(l/t)+13,13),s=aI(a,13,Math.ceil(aq(a,13)));return{text:a,width:s,height:Math.ceil(13*gX(a)*1.35)}}).flatMap(({text:e,width:t,height:a},l)=>s.flatMap(s=>{let o=.01>Math.abs(s.to.y-s.from.y);return[.5,.3,.7,.15,.85].flatMap(r=>{let n={x:s.from.x+(s.to.x-s.from.x)*r,y:s.from.y+(s.to.y-s.from.y)*r};return[6,14,30,50,80].flatMap(s=>(o?[-1,1].map(e=>({left:n.x-t/2,right:n.x+t/2,top:e<0?n.y-s-a:n.y+s,bottom:e<0?n.y-s:n.y+s+a})):[1,-1].map(e=>({left:e>0?n.x+s:n.x-s-t,right:e>0?n.x+s+t:n.x-s,top:n.y-a/2,bottom:n.y+a/2}))).map(a=>({text:e,width:t,rect:a,offset:s,form:l,score:100*d.filter(e=>gR(a,gY(e),4)).length+100*h.filter(e=>gR(a,gY(e),2)).length+10*L.filter(e=>gZ(e.from,e.to,a,3)).length+10*C.filter(e=>gR(a,e,4)).length+i.filter(e=>gZ(e.from,e.to,a,3)).length})))})})).reduce((e,t)=>t.score<e.score||t.score===e.score&&(t.offset<e.offset||t.offset===e.offset&&t.form<e.form)?t:e);return{text:o.text,width:o.width,rect:o.rect,covers:(a=o.rect,d.some(e=>gR(a,gY(e),0))||h.some(e=>gR(a,gY(e),0)))}},S=(e,t,a)=>{let s=Math.min(g,...C.map(e=>e.top),...[...r,...cq(a)].flatMap(e=>[e.from.y,e.to.y]))-8,i=e.rect.bottom-e.rect.top;return{...e,rect:{left:t-e.width/2,right:t+e.width/2,top:s-i,bottom:s},covers:!1}};for(let[i,n]of e.dottedLines.entries()){let c=t.get(n.report),d=t.get(n.manager),u=new Set([s.get(n.report),s.get(n.manager)]),L=s.get(n.report)===s.get(n.manager)?s.get(n.report):void 0,A=(e,s)=>[...[...t].map(([t,a])=>({box:gY(a),clearance:e,...t===n.report||t===n.manager?{own:!0}:{}})),...h.map(e=>({box:gY(e),clearance:2})),...a.filter(e=>!u.has(e.id)).map(t=>({box:gY(t),clearance:Math.min(e,8)})),...a.filter(e=>s||L===e.id).flatMap(e=>[{...e,height:0},{...e,y:e.y+e.height,height:0},{...e,width:0},{...e,x:e.x+e.width,width:0}].map(t=>({box:gY(t),clearance:8,...L===e.id?{}:{parallel:!0}})))],P=g$(c,o.get(n.report)??[],!1),V=g$(d,o.get(n.manager)??[],!0),H=[c,d],q=[...f,...m.filter(e=>H.some(t=>e>t.y-120&&e<t.y+t.height+120))],F=(e,t,a={sources:P,targets:V},s=!1)=>t.flatMap(t=>{let i={remaining:Math.min(b.remaining,12e3)},l=cV({...a,obstacles:e,...t,routed:r,top:y,bottom:w,reach:x,...s?{wide:!0,crossingCost:500,backCrossingFactor:1}:{},budget:i});return b.remaining-=Math.min(b.remaining,12e3)-i.remaining,l?[gm(l)]:[]}).reduce((e,t)=>!e||gD(t,r)<gD(e,r)?t:e,void 0),I=F(A(6,!0),[{lanes:[...p,...f],denseLanes:m},{lanes:m,denseLanes:v}])??F(A(6,!0),[{lanes:q,denseLanes:q}])??F(A(3,!1),[{lanes:v,denseLanes:v}]),E=e.dottedLines.length-1-i,O=l&&I&&gG(I,r)>0&&b.remaining>=12e3+48e3*E?F(A(6,!0),[{lanes:[...p,...f],denseLanes:m}],void 0,!0):void 0,U=O&&I&&gD(O,r)<gD(I,r)?O:I,X=()=>{let e=Math.min(g-24-10*z,...r.flatMap(e=>[e.from.y-10,e.to.y-10])),t=(t,a)=>[0,-1,1,-2,2,-4,4].map(s=>({x:t.x+t.width/2+48*s,y:e,direction:a,cost:8*Math.abs(s)})),a=[{lanes:[...q,e],denseLanes:[...q,e]}],s=F(A(6,!0),a,{sources:P,targets:t(c,3)}),i=s&&F(A(6,!0),a,{sources:t(d,1),targets:V});return s&&i?gm([...s,...i]):void 0},T=U?void 0:X();T&&(z+=1),U||T||(_+=1);let Y=gm(U??T??function(e,t){let a=e=>({x:e.x+e.width/2,y:e.y+e.height/2}),[s,i]=[a(e),a(t)],l=(e,t,a)=>{let s=t.x-a.x,i=t.y-a.y,l=Math.min(0===s?1/0:e.width/2/Math.abs(s),0===i?1/0:e.height/2/Math.abs(i));return{x:a.x+s*l,y:a.y+i*l}};return[l(e,i,s),l(t,s,i)]}(c,d)).map(({x:e,y:t})=>({x:e,y:t})),$=n.label?.trim(),G=void 0===$?void 0:B($,Y);if(void 0!==$&&G?.covers&&!T&&b.remaining>=12e3+48e3*E){let e=X(),t=e&&B($,e);e&&t&&!t.covers&&(z+=1,Y=e.map(({x:e,y:t})=>({x:e,y:t})),G=t)}G?.covers&&(G=S(G,Y[0].x,Y)),r.push(...cq(Y)),o.set(n.report,[...o.get(n.report)??[],Y[0]]),o.set(n.manager,[...o.get(n.manager)??[],Y.at(-1)]),k.push({type:"arrow",id:`edge:dotted:${n.id}`,edgeId:`dotted:${n.id}`,sourceNodeId:n.report,targetNodeId:n.manager,points:Y,startArrowhead:null,endArrowhead:"arrow",strokeColor:gF,strokeStyle:"dashed",strokeWidth:2,roughness:0}),void 0!==G&&(C.push(G.rect),M.push({type:"text",id:`text:dotted:${n.id}`,x:(G.rect.left+G.rect.right)/2,y:(G.rect.top+G.rect.bottom)/2,text:G.text,fontSize:13,lineHeight:1.25,maxWidth:G.width,textColor:gF}))}return{arrows:k,labels:M,straight:_}}var gN=a(664);a(3614);var gW=a(1594),gJ=a(6297),gK=a(7258),gQ=a(2275),g1=a(2860),g0=a(1554),g2=a(4233);let g3=l.Or("effect/Metric/CurrentMetricAttributes",{defaultValue:()=>({})}),g5=l.Or("effect/Metric/MetricRegistry",{defaultValue:()=>new Map}),g4="~effect/Metric";class g6{[g4]=g4;#e;#t="";id;description;attributes;constructor(e,t,a){this.id=e,this.description=t,this.attributes=a}valueUnsafe(e){return this.hook(e).get(e)}modifyUnsafe(e,t){return this.hook(t).modify(e,t)}updateUnsafe(e,t){return this.hook(t).update(e,t)}hook(e){var t;let a,s=l.Jt(e,g3);s!==this.#e&&(this.#e=s,this.#t=(t=this,a=Object.entries(ui(this.attributes,s)).sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0])),JSON.stringify([t.type,t.id,t.description,a])));let i=l.Jt(e,g5),o=i.get(this.#t);return g2.b0(o)&&(o={id:this.id,type:this.type,description:this.description,attributes:Object.keys(s).length>0?ui(this.attributes,s):this.attributes,hooks:this.createHooks()},i.set(this.#t,o)),o.hooks}pipe(){return(0,g0.tT)(this,arguments)}}let g7=BigInt(0);class g8 extends g6{type="Counter";#a;#s;constructor(e,t){super(e,t?.description,ul(t?.attributes)),this.#a=t?.bigint??!1,this.#s=t?.incremental??!1}createHooks(){let e=this.#a?g7:0,t=this.#s?this.#a?e=>e>=g7:e=>e>=0:e=>!0;return us(()=>({count:e,incremental:this.#s}),a=>{t(a)&&(e+=a)})}}class g9 extends g6{type;metric;valueUnsafe;updateUnsafe;modifyUnsafe;constructor(e,t,a,s){super(e.id,e.description,e.attributes),this.metric=e,this.valueUnsafe=t,this.updateUnsafe=a,this.modifyUnsafe=s,this.type=e.type}createHooks(){return this.metric.createHooks()}}let ue=(e,t)=>new g8(e,t),ut=(0,gW.XY)(2,(e,t)=>gJ.sxi(a=>gJ.OH5(()=>e.updateUnsafe(t,a)))),ua=(0,gW.XY)(2,(e,t)=>{var a;let s,i,o=(a=t,i={},e=>{let t=l.Jt(e,g3);return t!==s&&(s=t,i=ui(t,a)),l.WQ(e,g3,i)});return new g9(e,t=>e.valueUnsafe(o(t)),(t,a)=>e.updateUnsafe(t,o(a)),(t,a)=>e.modifyUnsafe(t,o(a)))});function us(e,t,a){return{get:e,update:t,modify:a??t}}function ui(e,t){return{...ul(e),...ul(t)}}function ul(e){return g2.EA(e)&&Array.isArray(e)?e.reduce((e,[t,a])=>(gQ.x(e,t,a),e),{}):e}gK.F,gK.F,gW.MN;var uo=a(1587),ur=(a(6526),a(719),a(2707));let un=[["artifactId","sketchi.artifact_id"],["attemptId","sketchi.attempt_id"],["projectId","sketchi.project_id"],["requestId","sketchi.request_id"],["runId","sketchi.run_id"],["scenarioId","sketchi.scenario_id"],["traceId","sketchi.trace_id"]],uc=new Set(["artifact_count","artifact_format","artifact_kind","attempt","cache_mode","duration_ms","error_category","error_tag","failure_category","format_count","method","model","operation","outcome","provider","request_kind","retry_kind","sink","status","status_code","surface","timeout_kind","timeout_ms"]),ud=([...un.map(([,e])=>e),...uc],{metric:()=>void 0}),up=l.Or("@sketchi/observability/TelemetryExporter",{defaultValue:()=>ud}),uh=l.Or("@sketchi/observability/TelemetryCorrelation",{defaultValue:()=>({})});function ug(e){let t=e?.trim();if(t&&!(t.length>128)&&/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(t))return t}function uu(e,t){return o.JkU(function*(){let a={...yield*uh,...function(e){let t={};for(let[a]of un){let s=ug(e[a]);s&&(t[a]=s)}return t}(t)},s=function(e){let t={};for(let[a,s]of un){let i=e[a];i&&(t[s]=i)}return t}(a);return yield*e.pipe(o.PfK(uh,a),o.Muk(s),o.swY(s))})}l.Or("@sketchi/observability/TelemetryResource",{defaultValue:()=>({serviceName:"sketchi"})});let uf=o.fn(function*(e,t,a={}){let s=function(e){let t={artifact_kind:e.artifactKind,failure_category:e.failureCategory,operation:e.operation,outcome:e.outcome,provider:e.provider,retry_kind:e.retryKind,sink:e.sink,surface:e.surface,timeout_kind:e.timeoutKind},a={};for(let[e,s]of Object.entries(t)){let t=ug(s);t&&(a[e]=t)}return a}(a);yield*ut(ua(e,s),t);let i=yield*up,l=uo.getOrUndefined((yield*o._32.pipe(o.uKv)));yield*o.OH5(()=>i.metric({attributes:s,metric:e.id,metricType:e.type,...l?{spanId:l.spanId,traceId:l.traceId}:{},value:t}))});ur.W1;var um=a(9315),uv=a(8713),uy=a(4733);let uw=new Set([...JSON.parse('["access","ace","active","addresses","administration","adobe","advanced","affinity","agent","agents","alloy","amazon","amp","analysis","analyzer","and","android","angular","apple","appliance","application","approvals","arc","armor","arrow","artifact","artifacts","asset","assist","assistant","assured","atom","audit","augment","authority","authorization","automatic","automation","autopilot","aware","axiom","azure","babel","balancing","bare","bash","basic","batch","bedrock","big","billing","binary","blitz","bolt","branching","brave","brunch","build","builder","business","c","capture","carbon","catalog","center","certificate","channel","checkpoints","chrome","chromium","cipher","clerk","cloud","code","codex","cohere","collaboration","command","composer","compute","computing","configuration","connect","connection","connectivity","connectors","console","contact","container","containers","context","contour","control","convex","copilot","core","crystal","cursor","custom","cypress","dart","dashboard","data","database","databases","db","debugger","default","deploy","deployed","deployment","design","designer","developer","director","directory","discovery","disk","distributed","document","dolphin","domains","dovetail","drizzle","early","edge","elastic","electron","elixir","ember","enforcement","engine","enterprise","error","expo","external","financial","firefly","firewall","fireworks","flask","fleet","flora","flow","flutter","flux","for","form","foundry","framer","frameworks","free","functions","fusion","game","gateway","generic","go","google","goose","graph","graphite","gulp","health","healthcare","home","hub","hybrid","hyper","hyperbolic","id","identity","ideogram","ids","illustrator","inception","inference","inflection","insights","insomnia","inspection","integration","intelligence","interconnect","inventory","jest","job","jobs","justifications","key","lab","labeling","lambda","language","launcher","layers","learning","legacy","less","linear","liquid","lit","load","local","lockup","logging","logic","logs","loss","lovable","lunacy","machine","machinery","magic","make","managed","management","manager","map","maps","marionette","markdown","marketing","marketplace","media","mesh","metal","migrate","migration","mixed","mobile","model","modeling","module","mongoose","monitoring","monocle","moonshot","motion","my","native","natural","neon","net","network","networking","next","nomad","notepad","notes","notion","nova","object","objective","obsidian","on","opera","operations","optimization","optimized","oracle","packaging","packer","palm","pandas","panel","partner","passport","patch","payload","performance","permissions","perplexity","persistent","phishing","phoenix","pipeline","platform","playwright","plus","poetry","policy","pool","portal","positron","postman","preferences","premium","preparation","presto","prettier","prevention","private","processing","producer","project","protection","protractor","providers","proxy","pulsar","puppeteer","putty","python","quantum","quasar","query","quiver","quotas","r","racket","rails","railway","rancher","react","real","reality","realm","recommendations","reflex","registry","release","render","replicate","reporting","resend","resource","restricted","retail","retention","rider","risk","router","routes","routing","ruby","rules","run","runway","rust","safari","sanity","sass","scanner","scheduler","search","secret","security","segment","selenium","sense","sentry","series","servers","service","services","sharp","shell","showcase","sketch","slack","slate","snowflake","solidity","solution","solutions","spanner","spark","speech","spring","stability","standard","stimulus","storage","storybook","stream","structured","studio","stylus","sublime","subversion","suite","support","swagger","swift","sync","systems","tables","tailwind","tasks","templates","test","text","threads","threat","tier","tiers","time","to","together","tomcat","tools","topology","trace","tracker","traffic","training","transfer","translation","trial","tutorials","twitter","type","types","typescript","unified","unity","unstructured","upgrade","upstage","user","vagrant","value","vapor","vault","vertex","video","view","vim","virtual","vision","visual","vortex","voyage","web","windsurf","wolfram","workbook","workflow","workflows","workload","workloads","workshop","world","yarn","yoga","zed"]'),"antigravity","api","dataflow","datastore","datastream","filestore","genomics","json","memorystore","meta","nitro","observability","onboarding","ontology","profiler","pubsub","pwa","remix","serverless","submodel","turbo"]),ux=/[A-Za-z0-9.+#]+/gu;function ub(e){return[...e.matchAll(ux)].map(([e])=>e.replace(/^\.+|\.+$/gu,"")).filter(Boolean).map(e=>e.toLocaleLowerCase())}function uk(e){return/[0-9.+#]/u.test(e)||e.length>=3&&!uw.has(e)}function uM(e){return e.trim().toLocaleLowerCase().replace(/\s+/gu," ")}function uC(e,t){return e.some(e=>uM(e).includes(t))}function uz(e,t){let a=uM(e.slug),s=uM(e.name),i=uM(e.collection),l=uM((0,uy.y)(e.collection));return a===t?0:s.startsWith(t)?1:uC(e.aliases,t)?2:a.includes(t)||s.includes(t)||uC(e.keywords,t)?3:i.includes(t)||l.includes(t)?4:null}let u_=new Set(["cloud-platforms","cloud-vendors"]);function uL(e){return e.toLocaleLowerCase().replace(/[^a-z0-9+#]/gu,"")}let uB=new WeakMap,uS=new Set(["app","cluster","database","db","icon","logo","server","service"]);function uA(e,t){let a=ub(t),s=[a,a.filter(e=>!uS.has(e))].map(e=>uL(e.join(""))),i=[e.slug,e.name,...e.aliases];if(i.some(e=>s.includes(uL(e))))return"exact";let l=new Set(a.flatMap((e,t)=>a.slice(t).map((e,s)=>uL(a.slice(t,t+s+1).join("")))));return i.some(e=>""!==uL(e)&&l.has(uL(e)))?"vendor":"weak"}let uP=new Map([["aks",["azure","kubernetes"]],["amazon",["aws"]],["aws",["amazon","amazon web services"]],["eks",["aws","kubernetes"]],["gcp",["google cloud"]],["gke",["google kubernetes engine","google cloud","kubernetes"]],["google cloud",["gcp"]],["google kubernetes engine",["gke","google cloud","kubernetes"]],["k8s",["kubernetes"]]]),uV=new Set([...uP].flatMap(([e,t])=>[e,...t].map(uL)));class uH extends i.rNF()("CodeModeIconLoadError",{cause:i.kld(),message:i.QfV,slug:i.QfV}){}function uq(e){return{collection:e.collection,name:e.name,slug:e.slug}}function uF(e){let t=e.icons.filter(uv.nC),a=new Map(t.map(e=>[e.slug,e])),s=new Map(t.map(e=>[e.slug,uq(e)]));return{get:e=>s.get(e),isStrayVendorLogo:(e,t)=>{let s,i=a.get(e);return void 0!==i&&(u_.has(i.collection)||[i.slug,i.name,...i.aliases].some(e=>uV.has(uL(e))))&&(s=ub(t),[t,...s.flatMap((e,t)=>s.slice(t).flatMap((e,a)=>{let i=s.slice(t,t+a+1).join(" ");return uP.get(i)??[]}))]).every(e=>"weak"===uA(i,e))},search:(e,a)=>(function(e,t={}){let a=uM(t.query??""),s=t.collection?.trim(),i=Math.max(0,t.limit??1/0),l=e.flatMap(e=>{if(s&&e.collection!==s)return[];let t=function(e,t){if(0===t.length)return 5;let a=uz(e,t);if(null!==a)return a;let s=t.split(/\s+/u);if(1===s.length)return null;let i=0;for(let t of s){let a=uz(e,t);if(null===a)return null;i=Math.max(i,a)}return i}(e,a);return null===t?[]:[{icon:e,rank:t}]}).sort((e,t)=>e.rank-t.rank||e.icon.name.localeCompare(t.icon.name)||e.icon.slug.localeCompare(t.icon.slug));return(l.length>0?l:function(e,t,a){let s=ub(t),i=function(e){let t=uB.get(e);if(t)return t;let a=new Map;for(let t of e)for(let e of new Set([t.slug,t.name,...t.aliases].map(uL))){if(!e)continue;let s=a.get(e)??[];s.push(t),a.set(e,s)}return uB.set(e,a),a}(e),l=new Map;for(let e=Math.min(4,s.length);e>0;e-=1)for(let t=0;t+e<=s.length;t+=1){let o=s.slice(t,t+e),r=o.some(uk);for(let s of i.get(uL(o.join("")))??[]){let i=u_.has(s.collection);if(l.has(s.slug)||!r&&!i||a&&s.collection!==a)continue;let n=uz(s,o.join(" "))??6;l.set(s.slug,{icon:s,length:e,start:t,termRank:n,vendor:i})}}return[...l.values()].sort((e,t)=>t.length-e.length||Number(e.vendor)-Number(t.vendor)||e.start-t.start||e.termRank-t.termRank||e.icon.name.localeCompare(t.icon.name)||e.icon.slug.localeCompare(t.icon.slug)).map(({icon:e})=>({icon:e,rank:6}))}(e,a,s)).slice(0,i)})(t,{limit:a,query:e}).map(({icon:t})=>({...uq(t),match:uA(t,e)})),loadSvg:e.loadSvg,slugLookup:e.slugLookup}}function uI(e){return s5(e).toLowerCase()}function uE(e){var t;let a;return{code:"unknown_icon",severity:"warning",stage:"input",...e.ref?{ref:e.ref}:{},message:e.message,hint:e.catalog?(a=function(e,t){let a=t.split(/[-_\s]+/u).filter(Boolean),s=new Set,i=[];for(let t of[a.join(" "),...a])if(t){for(let a of e.search(t,3))s.has(a.slug)||(s.add(a.slug),i.push(a));if(i.length>=3)break}return i.slice(0,3)}(t=e.catalog,e.slug)).length>0?`Use an exact slug, for example ${a.map(e=>`"${e.slug}" (${e.name})`).join(", ")}, or look one up with ${t.slugLookup}.`:`Look up an exact slug with ${t.slugLookup}, or omit icon.`:"This Sketchi runtime has no icon catalog; omit icon or retry on a host with logos."}}function uO(e,t,a={noun:"node",path:"nodes"}){let s=[],i=e.map(e=>{if(!e.icon)return e;let i=uI(e.icon.slug),l={kind:"node",id:e.id,path:`${a.path}.icon.slug`},o=u(i)?t?.get(i):void 0;if(o&&!t?.isStrayVendorLogo(i,e.label))return{...e,icon:{slug:i}};s.push(o?{code:"icon_dropped",severity:"warning",stage:"input",ref:l,message:`Icon "${i}" on ${a.noun} "${e.id}" is a vendor logo, but the label "${e.label}" does not name ${o.name}; the ${a.noun} renders without a logo.`,hint:`Put a vendor's logo only on a ${a.noun} whose label names that vendor ("Cloudflare Workers" takes cloudflare); other ${a.noun}s take their product's own logo or none.`}:uE({catalog:t,message:`Icon "${e.icon.slug}" on ${a.noun} "${e.id}" is not a Sketchi node logo; the ${a.noun} renders without a logo.`,ref:l,slug:i}));let{icon:r,...n}=e;return n});return{issues:s,nodes:i}}let uU=o.fn("codeMode.icons.embedScene")(function*(e,t){let a=e.elements.map(e=>"node"===e.type&&e.icon?{...e,icon:{...e.icon,slug:uI(e.icon.slug)}}:e),s=new Map([...new Set(a.flatMap(e=>"node"===e.type&&e.icon?[e.icon.slug]:[]))].flatMap(e=>{let a=u(e)?t?.get(e):void 0;return a?[[e,a]]:[]})),i=new Map((yield*o.jJl([...s.values()],e=>t?t.loadSvg(e).pipe(o.TjK(e=>(0,uv.Bn)(e)),o.TjK(t=>[e.slug,{name:e.name,svg:t}]),o.Tyx(t=>o.FFw("Code Mode icon asset unavailable",{slug:e.slug,cause:t}).pipe(o.as(void 0)))):o.PyW(void 0),{concurrency:8})).flatMap(e=>e?[e]:[])),l=function(e,t){let a=new Map,s=[],i=a7(e),l=a8(e,i),o=0,r=e.elements.map((e,r)=>{if("node"!==e.type||!e.icon)return e;let n=e.icon,c=t=>(s.push({elementId:e.id,index:r,reason:t,slug:n.slug}),function(e){let{icon:t,...a}=e;return a}(e)),d=a.get(n.slug),p=d??(u(n.slug)?t(n.slug):void 0);if("string"!=typeof p?.svg||a3(p.svg)>aX.maxAssetBytes)return c("unavailable");if(e.rendererRole)return c("lifeline");if("polygon"!==e.shape&&i(e)){let t=l.get(e.id)?.element;if(a9(e,t,n)&&!a9(e,t,void 0))return c("no_room")}if(!d){let e=a3(p.svg);if(o+e>aX.maxTotalAssetBytes)return c("budget");o+=e,a.set(n.slug,{name:p.name,svg:p.svg})}return e}),{icons:n,...c}=e;return{dropped:s,scene:a.size>0?{...c,elements:r,icons:Object.fromEntries(a)}:{...c,elements:r}}}({...e,elements:a},e=>i.get(e));return{issues:l.dropped.map(e=>(function(e){let{dropped:t}=e,a={kind:"element",id:t.elementId,path:`elements[${t.index}].icon${"unavailable"===t.reason?".slug":""}`},s=`Icon "${t.slug}" on node "${t.elementId}"`;if("unavailable"===t.reason&&!e.known)return uE({catalog:e.catalog,message:`${s} is not a Sketchi node logo; the node renders without a logo.`,ref:a,slug:t.slug});let i=e.element?.type==="node"?a6(e.element.icon):0,l={budget:{message:`${s} exceeds the per-diagram logo budget; the node renders without a logo.`,hint:"Use fewer distinct logos in one diagram."},lifeline:{message:`Sequence lifeline or activation "${t.elementId}" cannot carry a logo; the logo was dropped.`,hint:"Put logos on nodes or sequence participants, not on lifelines."},no_room:{message:`${s} does not fit above its label; the node renders without a logo.`,hint:`Make node "${t.elementId}" about ${i}px taller or shorten its label to keep the logo.`},unavailable:{message:`${s} could not be loaded; the node renders without a logo.`,hint:"Retry the request; if the logo stays unavailable, omit icon."}}[t.reason];return{code:"icon_dropped",severity:"warning",stage:"input",ref:a,message:l.message,hint:l.hint}})({catalog:t,dropped:e,element:a[e.index],known:s.has(e.slug)})),scene:l.scene}}),uX=/^(node|step|item|box|thing|process|task)\s*\d*$/i,uT=/^(diagram|untitled|flowchart|chart|sketch)$/i;function uY(e){return e.map(e=>({kind:"node",id:e.id}))}function u$(e){if(void 0===e)return;let t=s5(e);return t.length>0?t:void 0}let uG={start:"start",begin:"start",entry:"start",process:"process",task:"process",action:"process",step:"process",activity:"process",operation:"process",decision:"decision",condition:"decision",question:"decision",choice:"decision",gateway:"decision",end:"end",stop:"end",finish:"end",exit:"end",final:"end"},uD=new Set(["terminal","terminator","terminus"]),uR=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),uZ=["excalidraw","scene"],uj=["scene"],uN=ue("sketchi_codemode_requests",{description:"Code Mode boundary requests by terminal outcome",incremental:!0}),uW=ue("sketchi_codemode_failures",{description:"Code Mode boundary failures by typed status",incremental:!0}),uJ=ue("sketchi_codemode_artifacts",{description:"Code Mode artifacts accepted at workflow boundaries",incremental:!0}),uK=new class e extends g6{type="Histogram";#i;constructor(e,t){super(e,t?.description,ul(t?.attributes)),this.#i=t.boundaries}createHooks(){let e=this.#i,t=e.length,a=new Uint32Array(t+1),s=new Float64Array(t),i=0,l=0,o=Number.MAX_VALUE,r=-Number.MAX_VALUE;return gN.Tj(gN.di(e,g1.wN),(e,t)=>{s[t]=e}),us(()=>({buckets:(()=>{let e=gN.CN(t),i=0;for(let l=0;l<t;l++){let t=s[l];i+=a[l],e[l]=[t,i]}return e})(),count:i,min:o,max:r,sum:l}),e=>{let n=0,c=t;for(;n!==c;){let t=Math.floor(n+(c-n)/2);e<=s[t]?c=t:n=t,c===n+1&&(e<=s[n]?c=n:n=c)}a[n]=a[n]+1,i+=1,l+=e,e<o&&(o=e),e>r&&(r=e)})}}("sketchi_codemode_duration_ms",{description:"Code Mode boundary duration in milliseconds",boundaries:(s=[1,5,10,25,50,100,250,500,1e3,2500,5e3,1e4],gN.BC(gN.pb(new Set(s),e=>e>0),1/0))});class uQ extends l.kl()("@sketchi/diagram-agent/CodeModeRuntimeEnvironment"){}function u1(e={}){return n.Py(uQ,{createId:e.createId??fL,...e.icons?{icons:e.icons}:{},...e.renderer?{renderer:e.renderer}:{},...e.artifactUrl?{artifactUrl:e.artifactUrl}:{}})}function u0(e){return null===e||"object"!=typeof e||Array.isArray(e)?void 0:Object.fromEntries(Object.entries(e))}function u2(e){return{...e,type:"timeline"}}function u3(e){return{...e,type:"chart"}}function u5(e){return{...e,type:"gantt"}}n.Py(uQ,{createId:fL});let u4={gantt_too_large:"gantt_too_large",duplicate_task_id:"duplicate_node_id",invalid_gantt_date:"invalid_gantt_date",invalid_gantt_span:"invalid_gantt_span",invalid_gantt_phase:"invalid_gantt_phase",invalid_gantt_progress:"invalid_gantt_progress",missing_dependency:"missing_edge_source",self_dependency:"self_loop",gantt_dependency_cycle:"gantt_dependency_cycle"};function u6(e){return{id:e.id,title:e.title,type:"sequence",participants:e.participants,messages:e.messages,style:e.style}}let u7={sequence_too_large:"sequence_too_large",duplicate_participant_id:"duplicate_node_id",lifeline_id_collision:"duplicate_node_id",duplicate_message_id:"duplicate_edge_id",missing_message_source:"missing_edge_source",missing_message_target:"missing_edge_target"},u8={missing_message_source:"Use the id of a participant declared in spec.participants.",missing_message_target:"Use the id of a participant declared in spec.participants."};function u9(e){return{...e,type:"state-machine"}}let fe={state_machine_too_large:"state_machine_too_large",invalid_state_id:"invalid_state",duplicate_state_id:"duplicate_node_id",duplicate_transition_id:"duplicate_edge_id",missing_state_label:"invalid_state",unknown_initial_state:"unknown_initial_state",unknown_parent_state:"invalid_composite",nested_composite:"invalid_composite",missing_transition_source:"missing_edge_source",missing_transition_target:"missing_edge_target",final_has_outgoing:"final_has_outgoing",composite_member_transition:"invalid_composite",missing_composite_initial:"invalid_composite",underbranched_choice:"underbranched_choice",unguarded_choice_branch:"unlabeled_decision_branch",unreachable_state:"unreachable_node"};function ft(e){return{...e,type:"er"}}let fa={er_too_large:"er_too_large",invalid_entity_id:"invalid_entity",duplicate_entity_id:"duplicate_node_id",duplicate_entity_name:"invalid_entity",duplicate_field_name:"invalid_field",er_text_too_long:"label_too_long",nullable_primary_key:"invalid_field",duplicate_relationship_id:"duplicate_edge_id",missing_relationship_entity:"missing_edge_target",missing_relationship_field:"unknown_relationship_field",self_referencing_field:"invalid_relationship"};function fs(e){return{...e,type:"class"}}let fi={class_too_large:"class_too_large",invalid_class_id:"invalid_class",duplicate_class_id:"duplicate_node_id",duplicate_class_name:"invalid_class",duplicate_member:"invalid_member",class_text_too_long:"label_too_long",duplicate_relationship_id:"duplicate_edge_id",missing_relationship_class:"missing_edge_target",inheritance_cycle:"invalid_generalization",invalid_inheritance:"invalid_generalization",invalid_realization:"invalid_generalization",invalid_multiplicity:"invalid_relationship",misplaced_end_label:"invalid_relationship"};function fl(e){return{...e,type:"org-chart"}}let fo={org_chart_too_large:"org_chart_too_large",invalid_person_id:"invalid_person",duplicate_person_id:"duplicate_node_id",org_text_too_long:"label_too_long",unknown_manager:"missing_edge_source",self_manager:"invalid_reporting_line",reporting_cycle:"invalid_reporting_line",multiple_roots:"invalid_reporting_line",invalid_assistant:"invalid_person",duplicate_dotted_line_id:"duplicate_edge_id",invalid_dotted_line:"invalid_reporting_line"};class fr extends i.rNF()("CodeModeArtifactRenderFailed",{cause:i.kld(),message:i.QfV}){}class fn extends i.rNF()("CodeModeArtifactRendererNotConfigured",{message:i.QfV}){}let fc=i._kM({issues:i.O31(i.O3D(iE)).pipe(i.fXn)});class fd extends i.rNF()("ArtifactExportFailure",{status:i.uSQ("export_failed"),issues:fc.fields.issues}){}class fp extends i.rNF()("ArtifactStorageFailure",{status:i.uSQ("storage_failed"),cause:i.kld(),issues:fc.fields.issues}){}function fh(e,t,a){class s extends i.rNF()(e,{message:i.QfV,status:t,context:a}){constructor(e){super({...e,message:e.context.issues[0]?.message??e.status},{disableChecks:!0})}}return s}let fg=fh("BuildFlowchartFailure",ru.fields.status,ru.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fu=fh("BuildMindmapFailure",rm.fields.status,rm.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),ff=fh("BuildSequenceDiagramFailure",ry.fields.status,ry.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fm=fh("BuildStateMachineFailure",rC.fields.status,rC.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fv=fh("BuildErDiagramFailure",rB.fields.status,rB.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fy=fh("BuildClassDiagramFailure",rA.fields.status,rA.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fw=fh("BuildOrgChartFailure",rV.fields.status,rV.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fx=fh("BuildTimelineFailure",rx.fields.status,rx.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fb=fh("BuildChartFailure",rk.fields.status,rk.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fk=fh("BuildGanttFailure",r_.fields.status,r_.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fM=fh("CreateCanvasFailure",rO.fields.status,rO.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fC=fh("GetArtifactFailure",rq.fields.status,rq.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),fz=fh("SearchIconsFailure",rR.fields.status,rR.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields}))),f_=fh("ApplyDiagramPatchFailure",rI.fields.status,rI.mapFields(({ok:e,status:t,...a})=>({...a,...fc.fields})));function fL(e){return`${e}_${globalThis.crypto.randomUUID()}`}function fB(e){return{code:e.code,severity:e.severity??"error",stage:e.stage,...e.ref?{ref:e.ref}:{},message:e.message,hint:e.hint}}function fS(e){return 0===e.length?"input":e.map(e=>"number"==typeof e?`[${e}]`:String(e)).join(".")}function fA(e){let t=fS(e.path);return fP(t)?"unsupported_patch_operation":"InvalidType"===e.issueTag||"MissingKey"===e.issueTag&&"invalid_type"===e.missingKeyCode?"invalid_type":"LiteralUnion"===e.astKind&&"AnyOf"===e.issueTag?"invalid_enum":t.toLowerCase().includes("color")?"invalid_color":"input"===t?"invalid_type":"missing_field"}function fP(e){return/^operations\.\[\d+\]\.op$/.test(e)}function fV(e){return fP(e)?`Use one of: ${iX.join(", ")}. For label edits, use replaceText with selector plus text.`:"source"===e?"Pass source: { artifactId } from an accepted build or patch, or source: { scene } for inline Sketchi scene patching.":`Fix ${e} so it matches the Code Mode API contract.`}let fH=/^spec\.nodes\.\[\d+\]\.kind$/;function fq(e){return fH.test(e)?'Set kind to "start" (the single entry), "process" (a step), "decision" (a node whose outgoing edges carry branch labels) or "end" (an outcome).':fV(e)}function fF(e,t=fV){let a=e.issues.slice(0,20).map(e=>{let a=fS(e.path);return fB({code:fA(e),stage:"input",ref:{kind:"request",path:a},message:e.message,hint:t(a)})});return e.issues.length>20&&a.push(fB({code:"invalid_type",stage:"input",ref:{kind:"request",path:"input"},message:`${e.issues.length-20} additional input issues were omitted.`,hint:"Fix the summarized request shape before retrying."})),a}function fI(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)}function fE(e){if(void 0===e)return;let t=s5(e);return t.length>0?t:void 0}function fO(e){return e.checks.map(e=>{var t;return fB({code:"generic_label"===(t=e.code)||"label_too_long"===t||"disconnected_graph"===t?t:"quality_below_threshold",severity:e.severity,stage:"quality",message:e.message,hint:"error"===e.severity?"Repair the structural issue and call buildFlowchart again.":"Improve the labels or scope before styling the artifact."})})}function fU(e){return e?.artifactFormats??uZ}function fX(e){return e?.inlineArtifacts??uj}let fT=o.fn("codeMode.artifacts.exportFormats")(function*(e){let t=[];for(let l of e.formats){var a,s,i;let r=yield*(a=e,"scene"===(s=l)?o.PyW(a.scene):"excalidraw"===s?o.PyW(function(e,t={}){return{type:"excalidraw",version:2,source:t.source??"https://sketchi.app",elements:e.elements,appState:e.appState,files:e.files??{}}}(a.excalidraw)):a.renderer?a.renderer.renderPng({scene:a.scene,excalidraw:a.excalidraw}).pipe(o.xm_(e=>fr.make({cause:e,message:e.message}))):o.fJG(fn.make({message:"PNG artifact rendering is not configured for this runtime."})));t.push({format:l,mimeType:rW[l],data:r,sizeBytes:(i=r)instanceof ArrayBuffer||i instanceof Uint8Array?i.byteLength:rQ(i)})}return t});function fY(e){return e.map(e=>fB({code:"overlapping-arrow-segment"===e.code?"arrow_overlap":"text-overflow"===e.code?"text_overflow":e.code.includes("binding")||e.code.includes("bound")||e.code.includes("endpoint")?"arrow_binding_invalid":"export_invalid_scene",stage:"export",ref:e.elementId?{kind:"artifact",id:e.elementId}:{kind:"artifact"},message:e.message,hint:"Inspect the rendered scene and retry with a simpler layout or patch."}))}function f$(e){return e.slice(0,20).map(e=>fB({code:function(e){switch(e.code){case"duplicate_element_id":return"duplicate_element_id";case"duplicate_layer_id":return"duplicate_layer_id";case"empty_canvas":case"invalid_geometry":case"label_overflow":return"invalid_canvas_geometry";case"invalid_binding":return"invalid_canvas_binding";case"invalid_composition":return"invalid_canvas_composition";case"invalid_icon":return"invalid_canvas_icon";case"invalid_polygon":return"invalid_polygon";case"limit_exceeded":return"canvas_limit_exceeded";case"missing_z_order_element":case"duplicate_z_order_element":case"unknown_z_order_element":return"invalid_z_order";case"unknown_layout_target":return"unknown_layout_target"}}(e),stage:"canvas",ref:e.elementId?{kind:"element",id:e.elementId,path:e.path}:{kind:"diagram",path:e.path},message:e.message,hint:"Repair the referenced CanvasSpec field and call createCanvas again."}))}function fG(e){return fY(e.filter(e=>"overlapping-arrow-segment"!==e.code&&"arrow-segment-through-node"!==e.code))}function fD(e){let t=[];for(let c of e.elements){if("arrow"===c.type){let e=c.points[0],a=c.points[1],s=c.points.slice(2);if(!e||!a)return null;let i=[e,a,...s];t.push({...c,type:"arrow",id:c.id,edgeId:c.edgeId,sourceNodeId:c.sourceNodeId,targetNodeId:c.targetNodeId,...c.strokeColor?{strokeColor:c.strokeColor}:{},...c.strokeStyle?{strokeStyle:c.strokeStyle}:{},...c.textColor?{textColor:c.textColor}:{},points:i,...c.label?{label:c.label}:{}});continue}if("node"===c.type){var a,s,i,l,o,r,n;let d=c.points;if("polygon"===c.shape&&(!d||!d[0]||!d[1]||!d[2]))return null;t.push({type:"node",id:c.id,nodeId:c.nodeId,...c.kind?{kind:c.kind}:{},...c.icon?{icon:{slug:c.icon.slug,size:c.icon.size}}:{},shape:c.shape,...c.fillColor?{fillColor:c.fillColor}:{},...c.strokeColor?{strokeColor:c.strokeColor}:{},x:c.x,y:c.y,width:c.width,height:c.height,label:c.label,...c.frameId?{frameId:c.frameId}:{},...c.groupIds?{groupIds:[...c.groupIds]}:{},...c.layerId?{layerId:c.layerId}:{},...void 0!==c.locked?{locked:c.locked}:{},...void 0!==c.opacity?{opacity:c.opacity}:{},...void 0!==c.zIndex?{zIndex:c.zIndex}:{},...c.fillStyle?{fillStyle:c.fillStyle}:{},...void 0!==c.roughness?{roughness:c.roughness}:{},...c.strokeStyle?{strokeStyle:c.strokeStyle}:{},...void 0!==c.strokeWidth?{strokeWidth:c.strokeWidth}:{},..."sequence-lifeline"===c.rendererRole&&hA(e,c)||"sequence-activation"===c.rendererRole&&function(e,t){let a=`${eI}:activation:`,s=t.nodeId.indexOf(a);if(s<=0||s+a.length===t.nodeId.length||t.id!==`node:${t.nodeId}`||"rectangle"!==t.shape||12!==t.width)return!1;let i=t.nodeId.slice(0,s+eI.length),l=e.elements.find(e=>"node"===e.type&&e.id===`node:${i}`&&e.nodeId===i);if(!l||!hA(e,l))return!1;let o=l.x+l.width/2,r=(t.x-(o-6))/6,n=e.elements.filter(e=>"node"===e.type&&e.nodeId.startsWith(`${i}:activation:`)).length;return r>=-.01&&.01>=Math.abs(r-Math.round(r))&&Math.round(r)<n&&t.y>=l.y-.01&&t.y+t.height<=l.y+l.height+.01}(e,c)||"timeline-marker"===c.rendererRole&&(a=c).nodeId.startsWith("event:")&&a.id===`node:${a.nodeId}`&&a.height<=18&&void 0===a.icon||"chart-mark"===c.rendererRole&&(s=c).nodeId.startsWith("chart:")&&s.id===`node:${s.nodeId}`&&void 0===s.icon||"gantt-mark"===c.rendererRole&&((i=c).nodeId.startsWith("gantt:task:")||i.nodeId.startsWith("gantt:progress:"))&&i.id===`node:${i.nodeId}`&&void 0===i.icon||"state-marker"===c.rendererRole&&void 0!==(l=c).kind&&hC[l.kind]===l.shape&&void 0===l.icon||"er-table"===c.rendererRole&&"rectangle"===(o=c).shape&&void 0===o.icon&&o.id===`node:${o.nodeId}`||"er-optional"===c.rendererRole&&("circle"===(r=c).shape||"ellipse"===r.shape)&&void 0===r.icon&&r.nodeId.includes(":optional:")&&24>=Math.max(r.width,r.height)||"class-box"===c.rendererRole&&"rectangle"===(n=c).shape&&void 0===n.icon&&n.id===`node:${n.nodeId}`||("swimlane"===c.rendererRole||"swimlane-header"===c.rendererRole||"zone"===c.rendererRole)&&"rectangle"===c.shape&&!c.icon?{rendererRole:c.rendererRole}:{},...c.textColor?{textColor:c.textColor}:{},..."polygon"===c.shape&&d?.[0]&&d[1]&&d[2]?{points:[d[0],d[1],d[2],...d.slice(3)]}:{}});continue}if("line"===c.type){let e=c.points[0],a=c.points[1];if(!e||!a)return null;t.push({...c,points:[e,a,...c.points.slice(2)]});continue}t.push(structuredClone(c))}return{kind:e.kind,version:e.version,diagramId:e.diagramId,title:e.title,width:e.width,height:e.height,accentColor:e.accentColor,backgroundColor:e.backgroundColor,elements:t,layers:structuredClone(e.layers),layouts:structuredClone(e.layouts),zOrder:[...e.zOrder]}}function fR(e){let{icons:t,...a}=e;return a}function fZ(e){return structuredClone(e)}function fj(e){return e.elements.flatMap(e=>"arrow"===e.type?[`arrow:${e.id}:${e.sourceNodeId}->${e.targetNodeId}`]:"line"===e.type?[`line:${e.id}:${e.startBinding?.elementId??""}->${e.endBinding?.elementId??""}`]:[]).sort()}function fN(e){return e.elements.filter(e=>"node"===e.type)}function fW(e){return e.elements.filter(e=>"text"===e.type)}function fJ(e){return e.elements.filter(e=>"arrow"===e.type)}function fK(e,t){if(!e||0===e.length||!t)return!1;let a=t.trim().toLowerCase();return e.some(e=>e.trim().toLowerCase()===a)}function fQ(e,t){let a=t?.scope??"all",s=!!(t&&((t.ids?.length??0)>0||(t.nodeIds?.length??0)>0||(t.edgeIds?.length??0)>0||(t.kinds?.length??0)>0||(t.labels?.length??0)>0)),i=new Set(t?.ids??[]),l=new Set(t?.nodeIds??[]),o=new Set(t?.edgeIds??[]),r=new Set(t?.kinds??[]),n=fN(e).filter(e=>"edges"!==a&&(!t||!s||i.has(e.id)||l.has(e.nodeId)||!!e.kind&&[...r].some(t=>t===e.kind)||fK(t.labels,e.label))),c=fJ(e).filter(e=>"nodes"!==a&&(!t||!s||i.has(e.id)||o.has(e.edgeId)||fK(t.labels,e.label))),d=new Set(n.map(e=>e.id)),p=new Set(c.map(e=>e.id));return{arrows:c,nodes:n,texts:fW(e).filter(e=>t&&s?i.has(e.id)||!!e.containerId&&d.has(e.containerId)||!!e.containerId&&p.has(e.containerId)||fK(t.labels,e.text):"nodes"===a?!!e.containerId&&d.has(e.containerId):"edges"!==a||!!e.containerId&&p.has(e.containerId))}}function f1(e){return fB({code:"unknown_patch_target",stage:"flowchart",ref:{kind:"request",path:"operations.selector"},message:`Patch operation "${e.op}" did not match any scene element.`,hint:"Use nodeIds, edgeIds, ids, kinds, labels, or scope values that exist in the accepted artifact."})}function f0(e,t){return fW(e).find(e=>e.containerId===t||e.id===`${t}:label`)}function f2(e,t){let a=f0(e,t.id),s=function(e){let t=e[0],a=e[e.length-1];if(t&&a)return{x:(t.x+a.x)/2,y:(t.y+a.y)/2-10}}(t.points);if(a&&!a.containerId){let e=t.points[0];if(!e)return;let s=t.points.find(t=>t.x!==e.x||t.y!==e.y);if(!s)return;let i=aO(a.text,a.maxWidth??160,a.fontSize),l=aI(i,a.fontSize,a.maxWidth??160),o=Math.ceil(i.split("\n").length*a.fontSize*1.35);a.x=(e.x+s.x)/2+(e.x===s.x?l/2+8:0),a.y=(e.y+s.y)/2-(e.y===s.y?o/2+5:0);return}a&&s&&(a.x=s.x,a.y=s.y)}function f3(e,t){let a=new Set(t);for(let t of fJ(e))(a.has(t.sourceNodeId)||a.has(t.targetNodeId))&&f6(e,t)}function f5(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function f4(e,t,a){let s=f5(e),i=f5(t),l=i.x-s.x,o=i.y-s.y;return 0===l&&0===o?{x:s.x,y:"source"===a?e.y+e.height:e.y}:Math.abs(l)>Math.abs(o)?l>=0?{x:e.x+e.width,y:s.y}:{x:e.x,y:s.y}:o>=0?{x:s.x,y:e.y+e.height}:{x:s.x,y:e.y}}function f6(e,t){let a=new Map(fN(e).map(e=>[e.nodeId,e])),s=a.get(t.sourceNodeId),i=a.get(t.targetNodeId);if(!s||!i)return[fB({code:"patch_output_invalid",stage:"render",ref:{kind:"edge",id:t.edgeId},message:`Arrow "${t.id}" references a node that is not in the scene.`,hint:"Rebuild the diagram with buildFlowchart or buildMindmap before applying visual patches."})];if(t.curved)return t.points=sc(s,i).map(e=>({...e})),f2(e,t),[];let l=f4(s,i,"source"),o=f4(i,s,"target");if(Math.abs(o.y-l.y)>=Math.abs(o.x-l.x)){let e=(l.y+o.y)/2;t.points=[l,{x:l.x,y:e},{x:o.x,y:e},o]}else{let e=(l.x+o.x)/2;t.points=[l,{x:e,y:l.y},{x:e,y:o.y},o]}return f2(e,t),[]}function f7(e){let t=e.width,a=e.height;for(let s of e.elements)if("arrow"===s.type||"line"===s.type)for(let e of s.points)t=Math.max(t,e.x),a=Math.max(a,e.y);else"text"===s.type?(t=Math.max(t,s.x+(s.maxWidth??0)),a=Math.max(a,s.y+s.fontSize)):(t=Math.max(t,s.x+s.width),a=Math.max(a,s.y+s.height));e.width=t+48,e.height=a+48}function f8(e,t,a){if(!t||!a){if(t){let a=e.indexOf(t);return a>=0?a:void 0}if(a){let t=e.indexOf(a);return t>=0?t+1:void 0}return e.length}}function f9(e,t){return[fB({code:"patch_output_invalid",stage:"canvas",ref:{kind:"request",path:"operations"},message:t,hint:`Repair the ${e.op} operation and preserve unique, stable element ids.`})]}let me=o.fn("codeMode.patch.resolveSource")(function*(e){if("scene"in e.source)return{scene:fZ(e.source.scene)};let t=yield*rN,a=yield*t.readManifest(e.source.artifactId).pipe(o.xm_(e=>new f_({status:"storage_failed",context:{issues:[r0(e.message,"storage_read_failed")]}})));if(!a||a.artifactId!==e.source.artifactId||!a.formats.some(e=>"scene"===e.format))return yield*new f_({status:"source_unavailable",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:e.source.artifactId},message:`Artifact "${e.source.artifactId}" does not have a valid source manifest.`,hint:"Rebuild with the appropriate build operation and patch the accepted artifact id."})]}});let s=yield*t.read(e.source.artifactId,"scene").pipe(o.xm_(e=>new f_({status:"storage_failed",context:{issues:[r0(e.message,"storage_read_failed")]}})));if(!s)return yield*new f_({status:"source_unavailable",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:e.source.artifactId},message:`Scene artifact "${e.source.artifactId}" is not available.`,hint:"Call buildFlowchart or buildMindmap first, then patch the accepted artifact id."})]}});let l=i.q$Z(oP,{errors:"all",reportInput:!0})(s.data);return um.oJ(l)?{scene:fZ(l.success),sourceArtifactId:e.source.artifactId}:yield*new f_({status:"source_unavailable",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:e.source.artifactId},message:`Scene artifact "${e.source.artifactId}" could not be decoded.`,hint:"Rebuild with the appropriate build operation and patch the new artifact."})]}})});function mt(e){return e?{requestId:e}:{}}function ma(e){let t=fR(e);return{diagramId:e.diagramId,formats:[{format:"scene",mimeType:rW.scene,inline:t,sizeBytes:rQ(t)}]}}function ms(e){return{ok:!1,status:e.status,...e.context}}function mi(e,t){return r0(e.message,t)}let ml=o.fn("codeMode.artifacts.exportAndStore")(function*(e){let t=yield*uQ,a=yield*rN,{excalidraw:s,validation:i}=yield*o.OH5(()=>{let t=function(e){let t,a,s,i,l,o,r,n=(t=new Map(e.layers.map(e=>[e.id,e])),s=new Set((a=e.elements.filter(e=>{let a=e.layerId?t.get(e.layerId):void 0;return a?.visible!==!1})).flatMap(e=>"node"===e.type||"frame"===e.type&&void 0!==e.nodeId?[e.nodeId]:[])),l=new Set((i=a.filter(e=>"arrow"!==e.type||s.has(e.sourceNodeId)&&s.has(e.targetNodeId))).flatMap(e=>"text"===e.type?[]:[e.id])),r=new Set((o=i.filter(e=>"text"!==e.type||!e.containerId||l.has(e.containerId))).map(e=>e.id)),o.map(e=>{let a=e.layerId?t.get(e.layerId):void 0,{frameId:s,...i}=e;return{...e.frameId&&!r.has(e.frameId)?i:e,...a?.locked===!0?{locked:!0}:{}}})),{textElements:c,generatedLabelSourceIds:d}=function(e){let t=e.filter(nb),a=e.filter(nk),s=new Set(e.map(e=>e.id)),i=new Map,l=new Set(a.flatMap(e=>e.containerId?[e.containerId]:[]));for(let e of t){if(l.has(e.id)||e.rendererRole)continue;let t=`__sketchi_node_label__${e.id}`,o=t,r=2;for(;s.has(o);)o=`${t}:${r}`,r+=1;s.add(o),i.set(o,e.id),a.push({type:"text",id:o,containerId:e.id,...e.frameId?{frameId:e.frameId}:{},...e.groupIds?{groupIds:[...e.groupIds]}:{},...e.layerId?{layerId:e.layerId}:{},...void 0!==e.locked?{locked:e.locked}:{},...void 0!==e.opacity?{opacity:e.opacity}:{},...e.textColor?{textColor:e.textColor}:{},x:e.x+e.width/2,y:e.y+e.height/2,text:e.label,fontSize:16,maxWidth:Math.max(1,e.width-24)})}return{textElements:a,generatedLabelSourceIds:i}}(n),p={},h=new Map(d),g=function(e,t,a,s,i){var l,o,r,n;let c=t.filter(nb),d=new Set([...t.map(e=>e.id),...a.map(e=>e.id)]),p=new Map,h=new Map;for(let e of a)e.containerId&&h.set(e.containerId,e);let g=t.filter(nM),u=t.filter(nC),f=function(e,t,a,s){let i=new Map,l=new Map([...e.map(e=>[e.nodeId,e.id]),...t.flatMap(e=>void 0===e.nodeId?[]:[[e.nodeId,e.id]])]);for(let e of a)for(let t of[e.sourceNodeId,e.targetNodeId]){let a=l.get(t);a&&i.set(a,[...i.get(a)??[],e.id])}for(let e of s)for(let t of[e.startBinding,e.endBinding])t&&i.set(t.elementId,[...i.get(t.elementId)??[],e.id]);return i}(c,t.filter(nz),g,u),m=new Map,v=[];for(let t of c){let a=h.get(t.id),n=function(e){let t=e.shape.height,a="circle"===e.shape.shape?"ellipse":e.shape.shape,s=[...e.text&&"polygon"!==e.shape.shape?[{id:e.text.id,type:"text"}]:[],...e.arrowIds.map(e=>({id:e,type:"arrow"}))];if("polygon"===e.shape.shape){let t=e.shape.points??[{x:e.shape.width/2,y:0},{x:e.shape.width,y:e.shape.height},{x:0,y:e.shape.height}],[a]=t;return{...nm(e.shape.id,e.shape),type:"line",x:e.shape.x,y:e.shape.y,width:e.shape.width,height:e.shape.height,backgroundColor:e.shape.fillColor??"transparent",boundElements:e.arrowIds.map(e=>({id:e,type:"arrow"})),customData:{sketchiShape:"polygon",...e.shape.rendererRole?{sketchiRendererRole:e.shape.rendererRole}:{}},endArrowhead:null,endBinding:null,lastCommittedPoint:null,points:[...t,a].map(e=>[e.x,e.y]),roundness:null,startArrowhead:null,startBinding:null,strokeColor:e.shape.strokeColor??e.scene.accentColor}}return aY(e.shape.shape)?{...nm(e.shape.id,e.shape),groupIds:[ny(e.shape),...e.shape.groupIds??[]],type:"rectangle",x:e.shape.x,y:e.shape.y,width:e.shape.width,height:t,backgroundColor:"transparent",boundElements:s.length>0?s:null,customData:{sketchiShape:e.shape.shape},roundness:null,strokeColor:"transparent"}:{...nm(e.shape.id,e.shape),type:a,x:e.shape.x,y:e.shape.y,width:e.shape.width,height:t,backgroundColor:e.shape.fillColor??"transparent",boundElements:s.length>0?s:null,roundness:"rectangle"===a&&"chart-mark"!==e.shape.rendererRole&&"gantt-mark"!==e.shape.rendererRole&&"er-table"!==e.shape.rendererRole&&"class-box"!==e.shape.rendererRole&&"swimlane"!==e.shape.rendererRole&&"swimlane-header"!==e.shape.rendererRole&&"zone"!==e.shape.rendererRole?{type:3}:null,strokeColor:e.shape.strokeColor??e.scene.accentColor,...e.shape.rendererRole?{customData:{sketchiRendererRole:e.shape.rendererRole}}:{}}}({scene:e,shape:t,arrowIds:f.get(t.id)??[],...a?{text:a}:{}});if(m.set(t.nodeId,n),v.push(n),aY(t.shape)){let a=function(e){let{shape:t}=e;if(!aY(t.shape))return[];let a={...t,shape:t.shape};return[...t.fillColor?[{fill:t.fillColor,points:aW(a),smooth:!1}]:[],...(function(e){let{x:t,y:a,width:s,height:i}=e,l=a$[e.shape];if("document"===e.shape)return[{points:[{x:t,y:a+i},{x:t,y:a},{x:t+s,y:a},{x:t+s,y:a+i}],smooth:!1},{points:aZ(e,l),smooth:!0}];let o=aR(e,l,"pipe"!==e.shape,12,"bucket"===e.shape?aG(s):0);return[{points:o.back,smooth:!0},{points:o.front,smooth:!0},...o.sides.map(e=>({points:e,smooth:!1})),{points:o.end,smooth:!0}]})(a).map(e=>({...e,fill:void 0}))].map((a,s)=>{let[i]=a.points,l=a.points.map(e=>e.x),o=a.points.map(e=>e.y);return{...nm(e.id(s),t),groupIds:[ny(t),...t.groupIds??[]],type:"line",x:i.x,y:i.y,width:Math.max(...l)-Math.min(...l),height:Math.max(...o)-Math.min(...o),backgroundColor:a.fill??"transparent",boundElements:null,customData:{sketchiShapeStroke:t.shape},endArrowhead:null,endBinding:null,lastCommittedPoint:null,points:a.points.map(e=>[e.x-i.x,e.y-i.y]),roughness:t.roughness??0,roundness:a.smooth?{type:2}:null,startArrowhead:null,startBinding:null,strokeColor:a.fill?"transparent":t.strokeColor??e.scene.accentColor}})}({id:e=>(function(e,t,a){let s=`${e.id}:stroke-${t}`,i=s,l=2;for(;a.has(i);)i=`${s}-${l}`,l+=1;return a.add(i),i})(t,e,d),scene:e,shape:t});for(let e of a)i.set(e.id,t.id);v.push(...a),p.set(t.id,t)}let c=t.icon&&e.icons&&Object.hasOwn(e.icons,t.icon.slug)?e.icons[t.icon.slug]:void 0;if(!t.icon||"string"!=typeof c?.svg)continue;let g=(l=t.icon.slug,o=c.svg,`sketchi-icon-${l}-${sy(o,"hex","utf16")}`),u=function(e,t){let a=`${e.id.replace(/[^\w-]/gu,"-")}-icon`,s=a,i=2;for(;t.has(s);)s=`${a}-${i}`,i+=1;return t.add(s),s}(t,d),y=function(e){let t=function(e){if(!e.icon)return;let t=a5(e);return{x:e.x+(e.width-e.icon.size)/2,y:e.y+t.y+aX.gap,width:e.icon.size,height:e.icon.size}}(e.node);return t&&e.node.icon?{...nm(e.id,e.node),groupIds:[ny(e.node),...e.node.groupIds??[]],type:"image",x:t.x,y:t.y,width:t.width,height:t.height,backgroundColor:"transparent",boundElements:null,crop:null,customData:{sketchiNodeIcon:e.node.icon.slug},fileId:e.fileId,roundness:null,scale:[1,1],status:"saved",strokeColor:"transparent"}:null}({fileId:g,id:u,node:t});y&&(s[g]??=(r=c.svg,{id:g,mimeType:"image/svg+xml",dataURL:`data:image/svg+xml;base64,${function(e){let t=new TextEncoder().encode(e),a="";for(let e=0;e<t.length;e+=32768)a+=String.fromCharCode(...t.subarray(e,e+32768));return btoa(a)}(r)}`,created:1,lastRetrieved:1}),n.groupIds=[ny(t),...t.groupIds??[]],i.set(u,t.id),p.set(t.id,t),v.push(y))}for(let a of t.filter(nz)){let t={...nm((n={element:a,scene:e}).element.id,n.element),type:"frame",x:n.element.x,y:n.element.y,width:n.element.width,height:n.element.height,backgroundColor:n.element.fillColor??"transparent",boundElements:null,name:n.element.name??null,roundness:null,strokeColor:n.element.strokeColor??n.scene.accentColor},s=f.get(a.id)??[];t.boundElements=s.length?s.map(e=>({id:e,type:"arrow"})):null,void 0!==a.nodeId&&m.set(a.nodeId,t),v.push(t)}for(let e of a){let t=c.find(t=>t.id===e.containerId&&"polygon"!==t.shape),a=g.some(t=>t.id===e.containerId),s=g.find(t=>e.id===`${t.id}:label`),i=e.containerId&&(t||a),l=e.textColor??s?.textColor,o=nv({...t?{container:t}:{},element:e,id:e.id,...i?{containerId:e.containerId}:{},fontSize:e.fontSize,maxWidth:e.maxWidth??160,...l?{textColor:l}:{},text:e.text,wrap:a||!!s,x:e.x,y:e.y}),r=t?p.get(t.id):void 0;r&&(o.groupIds=[ny(r),...e.groupIds??[]]),v.push(o)}for(let t of g){let s=h.get(t.id)??a.find(e=>e.id===`${t.id}:label`);v.push(function(e){let t=e.arrow.points[0],a=nw(e.arrow),s=!0!==e.arrow.curved&&(e.arrow.points.length>2||[e.sourceShape,e.targetShape].some(e=>e?.type==="frame"||function(e){let t=e?.customData;if(null===t||"object"!=typeof t)return!1;let a=t.sketchiRendererRole;return"er-table"===a||"class-box"===a}(e)));return{...nm(e.arrow.id,e.arrow),type:"arrow",x:t.x,y:t.y,width:a.x-t.x,height:a.y-t.y,backgroundColor:"transparent",boundElements:e.text?e.text.containerId===e.arrow.id?[{id:e.text.id,type:"text"}]:null:e.arrow.label?[{id:`${e.arrow.id}:label`,type:"text"}]:null,elbowed:s,endArrowhead:void 0===e.arrow.endArrowhead?"arrow":e.arrow.endArrowhead,endBinding:nf(e.targetShape,a),...s?{fixedSegments:[],startIsSpecial:null,endIsSpecial:null}:{},points:e.arrow.points.map(e=>[e.x-t.x,e.y-t.y]),roundness:s?null:{type:2},startArrowhead:e.arrow.startArrowhead??null,startBinding:nf(e.sourceShape,t),strokeColor:e.arrow.strokeColor??e.scene.accentColor,strokeStyle:e.arrow.strokeStyle??"solid"}}({arrow:t,scene:e,sourceShape:m.get(t.sourceNodeId),targetShape:m.get(t.targetNodeId),...s?{text:s}:{}}));let i=t.label&&!s?function(e){if(!e.arrow.label)return null;let t=e.arrow.points[0],a=nw(e.arrow);return nv({id:`${e.arrow.id}:label`,containerId:e.arrow.id,fontSize:13,...void 0===e.arrow.locked?{}:{locked:e.arrow.locked},maxWidth:160,...e.arrow.textColor?{textColor:e.arrow.textColor}:{},text:e.arrow.label,wrap:!0,x:(t.x+a.x)/2,y:(t.y+a.y)/2-10})}({arrow:t}):null;i&&v.push(i)}let y=new Map(v.map(e=>[e.id,e]));for(let t of u)if(v.push(function(e){let[t,...a]=e.element.points,s=a[a.length-1]??t,i=void 0!==e.element.startArrowhead||void 0!==e.element.endArrowhead||void 0!==e.element.startBinding||void 0!==e.element.endBinding,l=i&&e.element.points.length>2;return{...nm(e.element.id,e.element),type:i?"arrow":"line",x:t.x,y:t.y,width:s.x-t.x,height:s.y-t.y,backgroundColor:e.element.fillColor??"transparent",boundElements:null,...i?{elbowed:l}:{},endArrowhead:e.element.endArrowhead??null,endBinding:nx(e.element.endBinding,e.elementsById,s),...l?{fixedSegments:[],startIsSpecial:null,endIsSpecial:null}:{},points:e.element.points.map(e=>[e.x-t.x,e.y-t.y]),roundness:e.element.points.length>2&&!l?{type:2}:null,startArrowhead:e.element.startArrowhead??null,startBinding:nx(e.element.startBinding,e.elementsById,t),strokeColor:e.element.strokeColor??e.scene.accentColor}}({element:t,elementsById:y,scene:e})),t.label){let e=t.points[0],a=t.points[t.points.length-1]??e;v.push(nv({id:`${t.id}:label`,fontSize:13,...void 0===t.locked?{}:{locked:t.locked},maxWidth:160,...t.textColor?{textColor:t.textColor}:{},text:t.label,wrap:!0,x:(e.x+a.x)/2,y:(e.y+a.y)/2-10}))}return v}(e,n,c,p,h),u=new Map(e.zOrder.map((e,t)=>[e,t])),f=e=>{if(u.has(e.id))return e.id;let t=h.get(e.id);return t||(e.id.endsWith(":label")?e.id.slice(0,-6):e.id)};g.sort((e,t)=>(u.get(f(e))??Number.MAX_SAFE_INTEGER)-(u.get(f(t))??Number.MAX_SAFE_INTEGER));let m=null;for(let e of g){let t=function(e,t,a,s){if(void 0!==s){var i=s;if(!nr.has(i)){if(i.length<2||i.length%2!=0||!ni(i))throw Error("intDigits must be an even number of at least 2 characters in strictly ascending character code order: "+i);if(!nl(i))throw Error("intDigits must be single-byte (char code 0-255): "+i);nr.add(i)}}else s=a??r3;if(void 0!==a){var l=a;if(!no.has(l)){if(l.length<2||!ni(l))throw Error("digits must be at least 2 characters in strictly ascending character code order: "+l);if(!nl(l))throw Error("digits must be single-byte (char code 0-255): "+l);no.add(l)}}else a=r2;let o=r4(a),r=r4(s);if(null!=e&&ne(e,a,s,r),null!=t&&ne(t,a,s,r),null!=e&&null!=t&&e>t){let a=e;e=t,t=a}if(null==e){if(null==t)return s[s.length/2]+a[0];let e=r9(t,s,r),i=t.slice(e.length);if(ns(e,a,s))return e+r6("",i,a,o);if(e<t)return e;let l=function(e,t,a,s,i){r7(e,s,i);let l=e[0],o=t[t.length-1],r="";for(let s=e.length-1;s>=1;s--){let i=a[e.charCodeAt(s)]-1;if(-1!==i)return l+e.slice(1,s)+t[i]+r;r=o+r}let n=i[l.charCodeAt(0)];if(0===n)return null;let c=s[n-1],d=r8(c,s,i)-r8(l,s,i);return c+(d>0?r+o:d<0?r.slice(1):r)}(e,a,o,s,r);if(null==l)throw Error("cannot decrement any more");return l}if(null==t){let t=r9(e,s,r),i=e.slice(t.length),l=nt(t,a,o,s,r);return null==l?t+r6(i,null,a,o):l}let n=r9(e,s,r),c=e.slice(n.length),d=r9(t,s,r),p=t.slice(d.length);if(n===d)return n+r6(c,p,a,o);let h=nt(n,a,o,s,r);if(null==h)throw Error("cannot increment any more");return h<t?h:n+r6(c,null,a,o)}(m,null);e.index=t,m=t}return{appState:{viewBackgroundColor:e.backgroundColor,zoom:{value:Math.max(.42,Math.round(100*Math.min(1,860/Math.max(e.width,1),340/Math.max(e.height,1)))/100)}},elements:g,files:p}}(e.scene);return{excalidraw:t,validation:function(e){let t=[],a=new Map(e.elements.map(e=>[e.id,e])),s=new Set(e.elements.filter(nB).map(e=>e.id));for(let i of(0===e.elements.length&&t.push({code:"empty-scene",message:"Excalidraw scene must contain at least one shape."}),e.elements)){if("image"!==i.type||"string"==typeof i.fileId&&e.files&&Object.hasOwn(e.files,i.fileId)||t.push({code:"missing-image-file",elementId:i.id,message:`Image "${i.id}" references a file missing from the scene.`}),"arrow"===i.type){let e=!0===i.elbowed;for(let l of((Array.isArray(i.points)?i.points:[]).length>2&&!e&&!function(e){let t=e.roundness;return!0!==e.elbowed&&null!==t&&"object"==typeof t&&2===t.type}(i)&&t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Arrow "${i.id}" has an orthogonal route but is not marked elbowed.`}),e&&null!==i.fixedSegments&&!Array.isArray(i.fixedSegments)&&t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Elbow arrow "${i.id}" is missing fixedSegments metadata.`}),["startBinding","endBinding"])){if(null===i[l]||void 0===i[l])continue;let o=n_(i,l);if(!(o&&s.has(o))){t.push({code:"missing-arrow-binding",elementId:i.id,message:`Arrow "${i.id}" has invalid ${l}.`});continue}let r=a.get(o);r&&!function(e,t,a){let s=e.boundElements;return!!Array.isArray(s)&&s.some(e=>!!(e&&"object"==typeof e)&&e.id===t&&e.type===a)}(r,i.id,"arrow")&&t.push({code:"missing-bound-arrow",elementId:r.id,message:`Shape "${r.id}" does not include bound arrow "${i.id}".`});let n=function(e,t){let a=nd(e.x)??0,s=nd(e.y)??0,i=Array.isArray(e.points)?e.points.map(np).filter(e=>!!e):[],l="startBinding"===t?i[0]:i[i.length-1];return l?{x:a+l[0],y:s+l[1]}:null}(i,l);if(r&&n&&!function(e,t){let a=nh(t);if(!a)return!1;let s=t.customData&&"object"==typeof t.customData?t.customData.sketchiShape:void 0;if("string"==typeof s&&aY(s))return aN({...a,shape:s},e);if("diamond"===t.type){let t=a.width/2,s=a.height/2;if(0===t||0===s)return!1;let i=a.x+t,l=a.y+s;return nA(Math.abs(e.x-i)/t+Math.abs(e.y-l)/s,1)}if("ellipse"===t.type){let t=a.width/2,s=a.height/2;if(0===t||0===s)return!1;let i=a.x+t,l=a.y+s;return nA(((e.x-i)/t)**2+((e.y-l)/s)**2,1)}let i=(nA(e.x,a.x)||nA(e.x,a.x+a.width))&&nS(e.y,a.y,a.y+a.height),l=(nA(e.y,a.y)||nA(e.y,a.y+a.height))&&nS(e.x,a.x,a.x+a.width);return i||l}(n,r)&&t.push({code:"arrow-endpoint-off-shape",elementId:i.id,message:`Arrow "${i.id}" ${l} endpoint does not land on "${r.id}".`}),r&&n&&e){let e=function(e,t){let a=e[t];return a&&"object"==typeof a?np(a.fixedPoint):null}(i,l);e&&function(e,t,a){let s=nh(a);if(!s)return!1;let i=1e-4>Math.abs(e[0]-.5001)?.5:e[0],l=1e-4>Math.abs(e[1]-.5001)?.5:e[1];return nA(s.x+i*s.width,t.x)&&nA(s.y+l*s.height,t.y)}(e,n,r)||t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Elbow arrow "${i.id}" has invalid ${l} fixedPoint metadata.`})}}}if("text"===i.type){let e=i.containerId;if("string"!=typeof e)continue;let s=a.get(e);if(!s){t.push({code:"missing-container",elementId:i.id,message:`Text "${i.id}" references missing container "${e}".`});continue}let l=("number"==typeof i.width?i.width:0)-("number"==typeof i.fontSize?i.fontSize:0),o="number"==typeof i.height?i.height:0,r="number"==typeof s.width?s.width:0,n="number"==typeof s.height?s.height:0;nB(s)&&(l+24>r||o+18>n)&&t.push({code:"text-overflow",elementId:i.id,message:`Text "${i.id}" does not fit inside "${e}".`})}}return t.push(...function(e){let t=e.filter(e=>"arrow"===e.type).flatMap(nL),a=e.filter(nB),s=new Map(e.flatMap(e=>"string"==typeof e.frameId?[[e.id,e.frameId]]:[])),i=[],l=new Set;for(let e of t)for(let t of a){if(function(e){let t=e.customData;if(null===t||"object"!=typeof t)return!1;let a=t.sketchiRendererRole;return aK.some(e=>e===a)}(t)||t.id===e.startBindingId||t.id===e.endBindingId||function(e,t,a){return"frame"===e.type&&[t.arrowId,t.startBindingId,t.endBindingId].some(t=>null!==t&&a.get(t)===e.id)}(t,e,s))continue;let a=nh(t);if(!a||!su(e,a))continue;let o=`${e.arrowId}:${e.segmentIndex}:${t.id}`;l.has(o)||(l.add(o),i.push({code:"arrow-segment-through-node",elementId:e.arrowId,message:`Arrow "${e.arrowId}" passes through shape "${t.id}".`}))}return i}(e.elements)),t.push(...function(e){let t=e.filter(e=>"arrow"===e.type).flatMap(nL),a=[],s=new Set;for(let e=0;e<t.length;e+=1){let i=t[e];if(i)for(let l=e+1;l<t.length;l+=1){let e=t[l];if(!e||i.arrowId===e.arrowId||function(e,t){if(!sf(e,t))return!1;let a=e.isFirstSegment&&t.isFirstSegment&&null!==e.startBindingId&&e.startBindingId===t.startBindingId;return .01>=Math.abs((a?e.startCoordinate:e.endCoordinate)-(a?t.startCoordinate:t.endCoordinate))&&Math.sign(e.endCoordinate-e.startCoordinate)===Math.sign(t.endCoordinate-t.startCoordinate)}(i,e)||function(e,t){if(null===e.startBindingId||e.startBindingId!==t.startBindingId||e.segmentIndex!==t.segmentIndex)return!1;for(let a=0;a<=e.segmentIndex;a+=1){let s=e.route[a],i=t.route[a];if(!s||!i||Math.abs(s.x-i.x)>.01||Math.abs(s.y-i.y)>.01)return!1}return Math.sign(e.endCoordinate-e.startCoordinate)===Math.sign(t.endCoordinate-t.startCoordinate)}(i,e)||!sg(i,e))continue;let o=[i.arrowId,String(i.segmentIndex),e.arrowId,String(e.segmentIndex)].sort().join(":");s.has(o)||(s.add(o),a.push({code:"overlapping-arrow-segment",elementId:i.arrowId,message:`Arrow "${i.arrowId}" overlaps arrow "${e.arrowId}".`}))}}return a}(e.elements)),{ok:0===t.length,issues:t}}(t)}}).pipe(o.fRP("codeMode.artifacts.exportValidate")),l=e.validationIssues(i.issues);if(l.length>0)return yield*new fd({status:"export_failed",issues:l});let r=yield*fT({formats:e.formats,scene:e.scene,excalidraw:s,renderer:t.renderer}).pipe(o.xm_(e=>new fd({status:"export_failed",issues:[fB({code:"render_failed",stage:"export",..."CodeModeArtifactRendererNotConfigured"===e._tag?{ref:{kind:"artifact",path:"options.artifactFormats"}}:{},message:e.message,hint:"CodeModeArtifactRendererNotConfigured"===e._tag?"Use the hosted Studio Code Mode runtime with its Cloudflare Browser Run binding, or omit png from artifactFormats.":"Retry the request; if it keeps failing, inspect the configured renderer."})]}))),n=yield*o.OH5(()=>t.createId("artifact"));var c=yield*uu(a.write({artifactId:n,diagramId:e.scene.diagramId,formats:r,inlineFormats:e.inlineFormats,...e.provenance?{provenance:e.provenance}:{}}).pipe(o.fRP("codeMode.artifacts.store")),{artifactId:n,...e.requestId?{requestId:e.requestId}:{}}).pipe(o.xm_(e=>new fp({status:"storage_failed",cause:e,issues:[mi(e,"storage_write_failed")]}))),d=t.artifactUrl;if(!d)return c;let p=c.formats.map(e=>({...e,url:d({artifactId:c.artifactId,format:e.format})}));return{...c,formats:p}}),mo=o.fn("codeMode.buildMindmap.workflow")(function*(e){var t,a;let s,l,r,n,c,d,p,h,g,u=function(e){let t=u0(u0(u0(e)?.spec)?.root);if(!t)return[];let a=[{depth:0,topic:t}],s=1;for(;a.length>0;){let e=a.pop();if(!e)continue;if(e.depth>8)return[fB({code:"mindmap_too_deep",stage:"mindmap",ref:{kind:"request",path:"spec.root.children"},message:"Mindmap depth exceeds the supported maximum of 8.",hint:"Combine overly deep topics into a shallower hierarchy."})];let t=e.topic.children;if(Array.isArray(t)){if((s+=t.length)>100)return[fB({code:"mindmap_too_large",stage:"mindmap",ref:{kind:"request",path:"spec.root"},message:"Mindmap exceeds the supported maximum of 100 topic slots.",hint:"Split this hierarchy into smaller focused mindmaps."})];for(let s=t.length-1;s>=0;s-=1){let i=u0(t[s]);i&&a.push({depth:e.depth+1,topic:i})}}}return[]}(e);if(u.length>0)return yield*new fu({status:"invalid_mindmap",context:{issues:u}});let f=i.q$Z(ol,{errors:"all",reportInput:!0})(e);if(!um.oJ(f))return yield*new fu({status:"invalid_input",context:{issues:fF(s9(f.failure))}});let m=yield*uQ,v=f.success,w=yield*o.OH5(()=>m.createId("build")),x=(t=v.spec,s=(e,t)=>({id:`topic-${t.join("-")}`,label:s5(e.label),children:(e.children??[]).map((e,a)=>s(e,[...t,a]))}),l=s5(t.title),{id:fE(t.id)??(fI(l)||"sketchi-mindmap"),title:l,root:s(t.root,[0]),layout:{direction:t.layout.direction},style:{...y}}),b={buildId:w,...mt(v.requestId),normalizedSpec:x},k=(r=0,n=0,(c=(e,t)=>{r+=1,n=Math.max(n,t),e.children.forEach(e=>c(e,t+1))})(x.root,0),p=[],(d={count:r,depth:n}).count<2&&p.push(fB({code:"disconnected_graph",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:"Mindmap root must contain at least one child topic.",hint:"Add one or more nested topics under spec.root.children."})),d.depth>8&&p.push(fB({code:"mindmap_too_deep",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:`Mindmap depth ${d.depth} exceeds the supported maximum of 8.`,hint:"Combine overly deep topics into a shallower hierarchy."})),d.count>100&&p.push(fB({code:"mindmap_too_large",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:`Mindmap has ${d.count} topics; the supported maximum is 100.`,hint:"Split this hierarchy into smaller focused mindmaps."})),p);if(k.length>0)return yield*new fu({status:"invalid_mindmap",context:{...b,issues:k}});let M=yield*o.SvU({try:()=>{var e;let t,a,s;return e={id:x.id,title:x.title,root:x.root,direction:x.layout.direction,style:y},t=[],a=[],(s=(e,i,l)=>{let o=i.join("-"),r=i.length-1,n={depth:r,siblingIndex:i.at(-1)};t.push({id:`topic-${o}`,label:e.label,kind:0===r?"root":"topic",metadata:n}),l&&a.push({id:`branch-${o}`,source:l,target:`topic-${o}`,metadata:n}),e.children?.forEach((e,t)=>s(e,[...i,t],`topic-${o}`))})(e.root,[0]),eV({id:e.id,title:e.title,type:ez,nodes:t,edges:a,layout:{direction:e.direction??"LR",edgeRouting:"curved"},...e.style?{style:{...e.style}}:{}})},catch:e=>new fu({status:"invalid_mindmap",context:{...b,issues:[fB({code:"disconnected_graph",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:e instanceof Error?e.message:"Mindmap failed core validation.",hint:"Repair the nested topic hierarchy and call buildMindmap again."})]}})}),C=(a=v.options?.minQualityScore??8,{accepted:(g=Math.max(0,10-2*(h=M.nodes.filter(e=>/^(topic|branch|item|mindmap)$/i.test(e.label.trim()))).length))>=a,score:g,threshold:a,summary:{nodeCount:M.nodes.length,edgeCount:M.edges.length},checks:h.map(e=>({code:"generic_label",passed:!1,severity:"warning",message:`Topic "${e.label}" is too generic.`,refs:[{kind:"node",id:e.id}]}))}),z={...b,quality:C};if(!C.accepted)return yield*new fu({status:"quality_failed",context:{...z,issues:fO(C)}});let _=yield*o.SvU({try:()=>{let e,t,a,s,i,l,o,r,n,c,d,p,h,g,u,f,m;return s=Math.round(40-Math.min(...(a=function(e,t){let a=a=>{var s;let i,l,o,r,n,c,d,p,h,g,u,f,m,v,y,w,x,b,k,M,C,z,_,L;return l=function(e){let t=e.length,a=1/0,s=Math.ceil(e.length/2);for(let i=1;i<=e.length;i+=1){let l=Math.abs(dd(e.slice(0,i))-dd(e.slice(i)));(l<a-1e-6||1e-6>=Math.abs(l-a)&&Math.abs(i-s)<Math.abs(t-s))&&(t=i,a=l)}return t}(i=e.children.map(e=>(function e(t,a){let s={x0:0,x1:t.width,y0:-t.height/2,y1:t.height/2};if(0===t.children.length)return dn([s],new Map([[t.id,{x:0,y:0}]]),new Set);let i=t.depth>=a,l=t.depth<=1?14:8,o=t.children.map(t=>e(t,a)),r=48*!!i,n=i?[s]:[],c=[];for(let e of o){let t=e.boxes.map(e=>dr(e,r,0)),a=c.length>0?sm(n,t,l,8):i?Math.max(sm(n,t,12,8),s.y1+12-e.top):0;c.push(a),n.push(...t.map(e=>dr(e,0,a)))}let d=c[0],p=c.at(-1),h=new Set(o.flatMap(e=>[...e.folded]));i&&h.add(t.id);let g=i?0:t.width+44+Math.min(40,.08*(p-d)),u=i?0:(d+p)/2,f=new Map([[t.id,{x:0,y:0}]]);o.forEach((e,t)=>{for(let[a,s]of e.places)f.set(a,{x:s.x+r+g,y:s.y+c[t]-u})});let m=i?{x0:20,x1:r,y0:s.y1,y1:p}:{x0:t.width,x1:g,y0:d-u,y1:p-u};return dn([s,m,...(i?n.slice(1):n).map(e=>dr(e,g,-u))],f,h)})(e,a))),r=(o=i.map((e,t)=>t)).slice(0,l),n=o.slice(l).toReversed(),c=r.map(e=>i[e]),d=n.map(e=>i[e]),p=e.width/2,h=e.height/2,g=p+72,f=(u=e=>Math.max(p,...e.map(e=>g+e.outer)))(c)+u(d),m=Math.max(e.height,dd(c),dd(d)),y=Math.max(0,(v=(f+40)/1.8-40)-m),w=(f+40)/2.4-40,x=e=>e[0]?e[0].bottom-e[0].top:void 0,b=c.length<=1&&d.length<=1?function(e,t,a,s){let i=a=>{let i=[[-s/2,s/2],...void 0===e?[]:[[-a-e/2,-a+e/2]],...void 0===t?[]:[[a-t/2,a+t/2]]];return Math.max(...i.map(([,e])=>e))-Math.min(...i.map(([e])=>e))},l=0,o=(Math.max(e??0,t??0)+s)/2+28;if(i(o)<=a)return o;if(i(l)>=a)return 0;for(let e=0;e<24;e+=1){let e=(l+o)/2;i(e)<a?l=e:o=e}return o}(x(c),x(d),w,e.height):0,M=[],(k=(e,a,s)=>{var i;let l,o,r=t=>Math.max(0,t-dd(e))/(e.length-1),n=e.length>1?Math.max(Math.min(120,r(v)),r(w)):0,c=(l=[],o=s-dd(e,i=y>0?n:0)/2,e.forEach((t,a)=>{a>0&&(o+=dc(e[a-1],t)+i),l.push(o-t.top),o+=t.bottom-t.top}),l);return e.map((e,s)=>({block:e,side:t?-a:a,y:c[s],inner:g}))})(c,1,-b).forEach((e,t)=>M[r[t]]=e),k(d,-1,b).forEach((e,t)=>M[n[t]]=e),C=Math.max(...M.map(e=>Math.abs(e.y))),s=M.map(e=>{if(0===C)return e;let t=.6*(e.y/C)**2,a=e.y+e.block.bottom>-h-28&&e.y+e.block.top<h+28;return{...e,inner:a?Math.max(g-72*t,p+44):Math.max(g-t*g,44)}}),_=[z={topic:e,parent:void 0,branch:-1,side:1,folded:!1,x:-e.width/2,y:-e.height/2}],L=(e,t,a,s)=>{let i=a.block.places.get(e.id),l=a.inner+i.x,o={topic:e,parent:t,branch:s,side:a.side,folded:-1!==t.branch&&a.block.folded.has(t.topic.id),x:1===a.side?l:-l-e.width,y:a.y+i.y-e.height/2};for(let t of(_.push(o),e.children))L(t,o,a,s)},e.children.forEach((e,t)=>L(e,z,s[t],t)),_},s=a(1/0);for(let t=function e(t){return Math.max(t.depth,...t.children.map(e))}(e)-1;t>=1&&!(dp(s)<=2.4+.01);t-=1){let e=a(t);dp(e)<dp(s)&&(s=e)}return s}(t=function(e){let t=new Map;for(let a of e.edges){let e=t.get(a.source)??[];e.push({id:a.target,index:a.metadata.siblingIndex}),t.set(a.source,e)}let a=new Map(e.nodes.map(e=>[e.id,e])),s=(e,i)=>{let l=a.get(e),{fontSize:o,textWidth:r,padX:n,padY:c}=dl(i),d=function(e,t,a){let s=e=>e.split("\n").length,i=aO(e,t,a);if(1===s(i))return i;let l=a,o=t;for(;o-l>1;){let t=Math.floor((l+o)/2);s(aO(e,t,a))<=s(i)?o=t:l=t}return aO(e,o,a)}(l.label,r,o),p=Math.ceil(Math.max(aq(d,o),aF(d,o,r))),h=Math.ceil(d.split("\n").length*o*1.35),g=0===i?function(e,t){let a=Math.ceil((e+36)*Math.SQRT2),s=Math.ceil((t+20)*Math.SQRT2);for(;a4({shape:"ellipse",width:a,height:s}).width<e+18;)a+=1;for(;a4({shape:"ellipse",width:a,height:s}).height<t+10;)s+=1;return{width:a,height:s}}(p,h):{width:p+2*n,height:h+2*c};return{id:e,depth:i,text:d,fontSize:o,...g,children:(t.get(e)??[]).toSorted((e,t)=>e.index-t.index).map(e=>s(e.id,i+1))}};return s(e.nodes.find(e=>"root"===e.kind).id,0)}(e=eP(M)),"RL"===e.layout.direction)).map(e=>e.x))),i=Math.round(40-Math.min(...a.map(e=>e.y))),l=e.style.accentColor,o=e.style.backgroundColor,r=e=>-1===e.branch?l:nW[e.branch%nW.length],n=e=>-1===e.branch?{}:{groupIds:[`branch:${t.children[e.branch].id}`]},c=a.map(e=>{var t;let a,{topic:l}=e,c=[.18,.16,.06][l.depth];return{type:"node",id:`node:${l.id}`,nodeId:l.id,kind:0===l.depth?"root":"topic",shape:0===l.depth?"ellipse":"rectangle",x:Math.round(e.x)+s,y:Math.round(e.y)+i,width:l.width,height:l.height,label:l.text,strokeColor:r(e),strokeWidth:dl(l.depth).strokeWidth,...void 0===c?{}:{fillColor:(t=r(e),a=(e,t)=>Number.parseInt(e.slice(t,t+2),16),`#${[1,3,5].map(e=>Math.round(a(o,e)+(a(t,e)-a(o,e))*c).toString(16).padStart(2,"0")).join("")}`),fillStyle:"solid"},...n(e)}}),d=a.map((e,t)=>({type:"text",id:`label:${e.topic.id}`,containerId:c[t].id,x:c[t].x+e.topic.width/2,y:c[t].y+e.topic.height/2,text:e.topic.text,fontSize:e.topic.fontSize,maxWidth:Math.max(1,e.topic.width-24),...n(e)})),p=new Map(c.map(e=>[e.nodeId,e])),h=function(e,t){let a=e.width/2,s=e.height/2,i=new Map;for(let l of[1,-1]){let o=t.filter(e=>e.side===l).map(t=>{let i=du(t.shape,l),o=Math.atan2((i.y-e.y-s)/s,l*(i.x-e.x-a)/a);return{id:t.shape.nodeId,angle:o}}).toSorted((e,t)=>e.angle-t.angle),r=o[0]?.angle??0,n=o.at(-1)?.angle??0;o.forEach((e,t)=>{let a=1===o.length?e.angle:r+(n-r)*t/(o.length-1);i.set(e.id,(e.angle+a)/2)})}return i}(c[0],a.flatMap((e,t)=>1===e.topic.depth?[{shape:c[t],side:e.side}]:[])),g=new Map(e.edges.map(e=>[e.target,e.id])),u=a.flatMap((e,t)=>{if(!e.parent)return[];let{topic:a}=e,s=g.get(a.id),i=function(e,t,a,s){let i=a.side,l=du(e,i);if(void 0!==s){let e=t.width/2,a=t.height/2,o={x:t.x+e+i*e*Math.cos(s),y:t.y+a+a*Math.sin(s)};return dg([o,{x:o.x+.4*(l.x-o.x),y:o.y+.4*(l.y-o.y)},{x:l.x-.5*i*Math.abs(l.x-o.x),y:l.y},l])}if(a.folded){let e={x:1===i?t.x+20:t.x+t.width-20,y:t.y+t.height};return dg([e,{x:e.x,y:e.y+.5*(l.y-e.y)},{x:l.x-.5*i*Math.abs(l.x-e.x),y:l.y},l])}let o={x:1===i?t.x+t.width:t.x,y:t.y+t.height/2},r=.5*Math.abs(l.x-o.x);return dg([o,{x:o.x+i*r,y:o.y},{x:l.x-i*r,y:l.y},l])}(c[t],p.get(e.parent.topic.id),e,h.get(a.id));return[{type:"arrow",id:`edge:${s}`,edgeId:s,sourceNodeId:e.parent.topic.id,targetNodeId:a.id,points:i,...i.length>2?{curved:!0}:{},endArrowhead:null,strokeColor:r(e),strokeWidth:1===a.depth?4:2,...-1===e.parent.branch?{}:n(e)}]}),f=Math.max(...c.map(e=>e.x+e.width)),m=Math.max(...c.map(e=>e.y+e.height)),{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:f+40,height:m+40,accentColor:l,backgroundColor:o,elements:[...u,...c,...d],layers:[],layouts:[],zOrder:[...u,...c,...d].map(e=>e.id)}},catch:e=>new fu({status:"render_failed",context:{...z,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:x.id},message:e instanceof Error?e.message:"Unable to render mindmap scene.",hint:"Simplify the hierarchy or retry with a smaller mindmap."})]}})}).pipe(o.fRP("codeMode.buildMindmap.render")),L={...z,partial:ma(_)},B=yield*ml({scene:_,formats:fU(v.options),inlineFormats:fX(v.options),...v.requestId?{requestId:v.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fu({status:e.status,context:{..."export_failed"===e.status?L:{...z,partial:{diagramId:_.diagramId}},issues:e.issues}})));return{ok:!0,status:"accepted",buildId:w,...mt(v.requestId),normalizedSpec:x,quality:C,artifact:B,issues:[]}}),mr=o.fn("codeMode.buildSequenceDiagram.workflow")(function*(e){var t,a;let s,l=i.q$Z(lj,{errors:"all",reportInput:!0})(e);if(!um.oJ(l))return yield*new ff({status:"invalid_input",context:{issues:fF(s9(l.failure))}});let r=yield*uQ,n=l.success,c=yield*o.OH5(()=>r.createId("build")),d=(s=s5((t=n.spec).title),{id:fE(t.id)??(fI(s)||"sketchi-sequence"),title:s,participants:t.participants.map(e=>({id:s5(e.id),label:s5(e.label),...e.kind?{kind:s5(e.kind)}:{},...e.icon?{icon:{slug:e.icon.slug}}:{}})),messages:t.messages.map((e,t)=>({id:fE(e.id)??`message-${t+1}-${fI(e.source)}-${fI(e.target)}`,source:s5(e.source),target:s5(e.target),label:s5(e.label),...e.type?{type:e.type}:{},...e.style?{style:e.style}:{}})),style:{...y}}),p=uO(d.participants,r.icons,{noun:"participant",path:"participants"}),h={...d,participants:p.nodes},g={buildId:c,...mt(n.requestId),normalizedSpec:h},u=eG(u6(h)).map(e=>fB({code:u7[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:u8[e.code]??e.hint}));if(u.length>0)return yield*new ff({status:"invalid_sequence",context:{...g,issues:u}});let f={accepted:10>=(a=n.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:h.participants.length,edgeCount:h.messages.length},checks:[]},m={...g,quality:f};if(!f.accepted)return yield*new ff({status:"quality_failed",context:{...m,issues:fO(f)}});let v=yield*o.SvU({try:()=>(function(e){let t=eR(e),a=new Map(t.participants.map(e=>[e.id,aO(e.label,156,14)])),s=Math.max(180,...[...a.values()].map(e=>Math.ceil(aq(e,14))+24)),i=s+140,l=t.participants.reduce((e,t)=>Math.max(e,Math.ceil(14*(a.get(t.id)??t.label).split("\n").length*1.35)+18+a6(t.icon?{slug:t.icon.slug,size:28}:void 0)),72),o=48+l,r=o+64,n=new Map(t.messages.flatMap(e=>{let t;return e.source===e.target?[[e.id,{width:aI(t=aO(e.label,160,13),13,160),height:Math.ceil(13*t.split("\n").length*1.35)}]]:[]})),c=e=>{let t=n.get(e);return t?Math.max(32,t.height):0},d=[],p=r;for(let e of t.messages)d.push(p),p+=88+c(e.id);let h=t.messages.at(-1),g=(h?(d.at(-1)??r)+c(h.id):r)-o+56,u=function(e){let t=new Map,a=[];e.messages.forEach((e,s)=>{if(e.source===e.target)return;if("return"!==e.type)return void t.set(e.target,[...t.get(e.target)??[],{caller:e.source,index:s,messageId:e.id}]);let i=t.get(e.source)??[],l=i.findLastIndex(t=>t.caller===e.target),o=i[l];o&&(t.set(e.source,i.filter((e,t)=>t!==l)),a.push({participantId:e.source,callMessageId:o.messageId,returnMessageId:e.id,startIndex:o.index,endIndex:s}))});let s=[];for(let e of a.toSorted((e,t)=>e.startIndex-t.startIndex)){let t=s.filter(t=>t.participantId===e.participantId&&t.endIndex>e.startIndex),a=new Set(t.map(e=>e.depth)),i=Math.max(0,...t.filter(t=>t.endIndex>e.endIndex).map(e=>e.depth+1));for(;a.has(i);)i+=1;s.push({...e,depth:i})}return s}(t),f=(e,t)=>Math.max(-1,...u.filter(a=>a.participantId===e&&a.startIndex<=t&&t<=a.endIndex).map(e=>e.depth)),m=t.participants.map(e=>Math.max(i,...t.messages.flatMap((t,a)=>{let s,i=n.get(t.id);if(!i||t.source!==e.id)return[];let l=f(e.id,a);return[((s="return"===t.type?l:l+1)<0?1:6*s+6)+32+10+i.width+6+24]}))),v=new Map,y=[],w=[],x=[],b=48+s/2;t.participants.forEach((e,r)=>{let n=b,c=n-s/2;b+=m[r]??i,v.set(e.id,n),y.push({type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},...e.icon?{icon:{slug:e.icon.slug,size:28}}:{},shape:"rectangle",x:c,y:48,width:s,height:l,label:a.get(e.id)??e.label}),w.push({type:"text",id:`label:${e.id}`,containerId:`node:${e.id}`,x:n,y:48+l/2,text:a.get(e.id)??e.label,fontSize:14,maxWidth:s-24,...e.icon?{verticalAlign:"bottom"}:{}}),x.push({type:"node",id:`node:${eE(e.id)}`,nodeId:eE(e.id),rendererRole:"sequence-lifeline",shape:"rectangle",fillColor:t.style.backgroundColor,strokeColor:t.style.accentColor,x:n-1,y:o,width:2,height:g,label:`${e.label} lifeline`})});let k=e=>d[e]??r,M=new Map(t.participants.map(e=>[e.id,e.label])),C=(e,a,s,i,l)=>{let o=`${eE(e)}:activation:${a}`,r=v.get(e)??0;return{type:"node",id:`node:${o}`,nodeId:o,rendererRole:"sequence-activation",shape:"rectangle",fillColor:t.style.backgroundColor,strokeColor:t.style.accentColor,x:r-6+6*s,y:i,width:12,height:l-i,label:`${M.get(e)??e} active`}},z=u.map(e=>({activation:e,node:C(e.participantId,e.callMessageId,e.depth,k(e.startIndex)-12,k(e.endIndex)+12)})),_=new Map(t.messages.flatMap((e,t)=>{if(e.source!==e.target||"return"===e.type)return[];let a=f(e.source,t)+1,s=k(t)+c(e.id);return[[e.id,C(e.source,e.id,a,s-12,s+12)]]})),L=(e,t,a,s)=>{let i=v.get(e)??0,l=s>i,o=z.filter(({activation:a})=>a.participantId===e&&a.startIndex<=t&&t<=a.endIndex),r=o.find(({activation:e})=>e.callMessageId===a||e.returnMessageId===a)??o.reduce((e,t)=>!e||t.activation.depth>e.activation.depth?t:e,void 0);return r?{nodeId:r.node.nodeId,x:l?r.node.x+r.node.width:r.node.x}:{nodeId:eE(e),x:i+(l?1:-1)*2/2}},B=t.participants.map(e=>v.get(e.id)??0),S=[],A=t.messages.map((e,t)=>{let a,s,i,l,o;if(e.source===e.target){let a,s,i,l,o,r,d;return a=L(e.source,t,e.id,1/0),i=(s=_.get(e.id))?{nodeId:s.nodeId,x:s.x+s.width}:a,l=Math.max(a.x,i.x)+32,r=(o=k(t))+c(e.id),d=[`message:${e.id}`],S.push({type:"text",id:`arrow:${e.id}:label`,text:e.label,fontSize:13,x:l+10+(n.get(e.id)?.width??0)/2,y:(o+r)/2,maxWidth:160,groupIds:d}),{type:"arrow",id:`arrow:${e.id}`,edgeId:e.id,groupIds:d,sourceNodeId:a.nodeId,targetNodeId:i.nodeId,..."return"===e.type?{strokeColor:"#6b7280"}:{},..."dashed"===e.style||"return"===e.type?{strokeStyle:"dashed"}:{},points:[{x:a.x,y:o},{x:l,y:o},{x:l,y:r},{x:i.x,y:r}],label:e.label}}let r=v.get(e.source)??0,d=v.get(e.target)??0,p=L(e.source,t,e.id,d),h=L(e.target,t,e.id,r),g=k(t);return{type:"arrow",id:`arrow:${e.id}`,edgeId:e.id,sourceNodeId:p.nodeId,targetNodeId:h.nodeId,..."return"===e.type?{strokeColor:"#6b7280"}:{},..."dashed"===e.style||"return"===e.type?{strokeStyle:"dashed"}:{},points:[{x:p.x,y:g},...(a=(r+d)/2,s=Math.sign(d-r),i=B.findIndex(e=>100>Math.abs(e-a)&&Math.min(r,d)<e&&e<Math.max(r,d)),l=B[i],o=B[i-s],void 0===l||void 0===o?[]:[{x:(l+o)/2,y:g}]),{x:h.x,y:g}],label:e.label}}),P=Math.max(0,...A.flatMap(({edgeId:e,points:t})=>{let a=n.get(e);return a&&t[1]?[t[1].x+10+a.width]:[]})),V=[...z.map(({node:e})=>e),..._.values()],H=[...A,...S,...x,...V,...y,...w],q=[...x.map(e=>e.id),...V.map(e=>e.id),...y.map(e=>e.id),...w.map(e=>e.id),...A.map(e=>e.id),...S.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:t.id,title:t.title,width:Math.max((B.at(-1)??48)+s/2+48,Math.ceil(P)+48),height:o+g+48,accentColor:t.style.accentColor,backgroundColor:t.style.backgroundColor,elements:H,layers:[],layouts:[],zOrder:q}})(u6(h)),catch:e=>new ff({status:"render_failed",context:{...m,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:h.id},message:e instanceof Error?e.message:"Unable to render sequence diagram scene.",hint:"Repair the participant/message structure and retry."})]}})}).pipe(o.fRP("codeMode.buildSequenceDiagram.render")),w=yield*uU(v,r.icons),x=w.scene,b=se(x);if(b.length>0)return yield*new ff({status:"render_failed",context:{...m,issues:f$(b).map(e=>({...e,hint:"Reduce participant label lines, participants, or messages and retry buildSequenceDiagram."}))}});let k={...m,partial:ma(x)},M=yield*ml({scene:x,formats:fU(n.options),inlineFormats:fX(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new ff({status:e.status,context:{..."export_failed"===e.status?k:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...mt(n.requestId),normalizedSpec:h,quality:f,artifact:M,issues:[...p.issues,...w.issues]}}),mn=o.fn("codeMode.buildStateMachine.workflow")(function*(e){var t,a;let s,l,r=i.q$Z(lK,{errors:"all",reportInput:!0})(e);if(!um.oJ(r))return yield*new fm({status:"invalid_input",context:{issues:fF(s9(r.failure))}});let n=yield*uQ,c=r.success,d=yield*o.OH5(()=>n.createId("build")),p=(s=s5((t=c.spec).title),l=(e,t)=>t&&s5(t)?{[e]:s5(t)}:{},{id:fE(t.id)??(fI(s)||"sketchi-state-machine"),title:s,initial:s5(t.initial),states:t.states.map(e=>{let t=s5(e.id),a=e4({...e,id:t});return{id:t,...void 0!==a?{label:a}:{},...e.kind?{kind:e.kind}:{},...l("parent",e.parent),...l("initial",e.initial)}}),transitions:t.transitions.map((e,t)=>({id:fE(e.id)??`transition-${t+1}-${fI(e.source)}-${fI(e.target)}`,source:s5(e.source),target:s5(e.target),...l("event",e.event),...l("guard",e.guard),...l("action",e.action)})),...t.layout?{layout:{direction:t.layout.direction}}:{},style:{...y}}),h={buildId:d,...mt(c.requestId),normalizedSpec:p},g=e8(u9(p)).map(e=>fB({code:fe[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(g.length>0)return yield*new fm({status:"invalid_state_machine",context:{...h,issues:g}});let u={accepted:10>=(a=c.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:p.states.length,edgeCount:p.transitions.length},checks:[]},f={...h,quality:u};if(!u.accepted)return yield*new fm({status:"quality_failed",context:{...f,issues:fO(u)}});let m=yield*o.SvU({try:()=>(function(e){let t=t=>hS(function(e,t){let a=e6(e),s=(e,t,a,s)=>({id:e,label:t,kind:a,metadata:{},...s?{group:s}:{}}),i=(e,t,a,s)=>({id:e,source:t,target:a,metadata:{},...s?{label:s}:{}}),l=new Set(e.transitions.map(e=>e.id)),o=e=>{let t=e;for(let a=2;l.has(t);a+=1)t=`${e}~${a}`;return l.add(t),t},r=[s(hP,"","initial")],n=[i(o(hP),hP,e.initial)],c=new Map,d=new Map;for(let t of e.states){if("final"!==e3(t)||void 0!==e4(t))continue;let a=e.transitions.filter(e=>e.target===t.id),s=a.map((e,a)=>0===a?t.id:`${t.id}:${a+1}`);a.forEach((e,t)=>c.set(e.id,s[t])),d.set(t.id,s.length>0?s:[t.id])}for(let t of e.states){let e=t.parent;if(a.has(t.id)){t.initial&&(r.push(s(`${t.id}${hP}`,"","initial",t.id)),n.push(i(o(`${t.id}${hP}`),`${t.id}${hP}`,t.initial)));continue}let l=e3(t),c=e4(t);if("final"===l&&void 0===c){for(let a of d.get(t.id))r.push(s(a,"","final",e));continue}if("final"===l){r.push(s(t.id,c,"state",e)),r.push(s(`${t.id}:end`,"","final",e)),n.push(i(o(`${t.id}:end`),t.id,`${t.id}:end`));continue}r.push(s(t.id,c??"",l,e))}for(let t of e.transitions){let e=function(e){let t=e.guard?e7(e.guard,/^\s*\[|\]\s*$/gu):"",a=e.action?e7(e.action,/^\s*\//u):"";return[e.event?.trim(),t&&`[${t}]`,a&&`/ ${a}`].filter(Boolean).join(" ")}(t);n.push(i(t.id,t.source,c.get(t.id)??t.target,e||void 0))}return{id:e.id,title:e.title,type:"flowchart",nodes:r,edges:n,groups:e.states.filter(e=>a.has(e.id)).map(e=>({id:e.id,label:e4(e)??""})),layout:{direction:t,edgeRouting:"orthogonal"},style:e.style,metadata:{}}}(e,t),{pairedReturns:!0});if(e.layout)return t(e.layout.direction);let a=["LR","TB"].map(e=>{let a,s=t(e);return{aspect:Math.max(s.width/s.height,s.height/s.width),cost:hy(a=s.elements.filter(e=>"arrow"===e.type))+sq(a.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),s_({width:s.width,height:s.height})).length,scene:s}}),s=a.filter(e=>e.aspect<=2.2),[i]=s.length>0?s.toSorted((e,t)=>e.cost-t.cost):a.toSorted((e,t)=>e.aspect-t.aspect);return i.scene})(u9(p)),catch:e=>new fm({status:"render_failed",context:{...f,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render state machine scene.",hint:"Repair the state and transition structure and retry."})]}})}).pipe(o.fRP("codeMode.buildStateMachine.render")),v=se(m);if(v.length>0)return yield*new fm({status:"render_failed",context:{...f,issues:f$(v).map(e=>({...e,hint:"Shorten state labels or split the machine and retry buildStateMachine."}))}});let w={...f,partial:ma(m)},x=yield*ml({scene:m,formats:fU(c.options),inlineFormats:fX(c.options),...c.requestId?{requestId:c.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fm({status:e.status,context:{..."export_failed"===e.status?w:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:d,...mt(c.requestId),normalizedSpec:p,quality:u,artifact:x,issues:[]}}),mc=o.fn("codeMode.buildErDiagram.workflow")(function*(e){var t,a;let s,l,r,n,c=i.q$Z(l0,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:function(e){if(!tV(e))return e;let t=Array.isArray(e.entities)?e.entities.map(e=>tV(e)&&Array.isArray(e.fields)?{...e,fields:e.fields.map(e=>"string"==typeof e?tS(e):e)}:e):e.entities,a=Array.isArray(e.relationships)?e.relationships.map(e=>{if(!tV(e))return e;let{source:t,target:a,cardinality:s,...i}=e,l=function(e){if("string"!=typeof e)return;let t=e.trim().toLowerCase().split(/\s*(?:-to-|\sto\s|:)\s*/u);if(2!==t.length)return;let a=e=>tP(/^m$|^n$/u.test(e)?"many":e);return[a(t[0]),a(t[1])]}(s),o={...i,from:i.from??t,to:i.to??a,fromCardinality:tP(i.fromCardinality??l?.[0]),toCardinality:tP(i.toCardinality??l?.[1])};for(let e of["from","to","fromCardinality","toCardinality"])void 0===o[e]&&delete o[e];return void 0!==s&&void 0===l&&(o.cardinality=s),o}):e.relationships;return{...e,...void 0===t?{}:{entities:t},...void 0===a?{}:{relationships:a}}}(e.spec)}:e);if(!um.oJ(c))return yield*new fv({status:"invalid_input",context:{issues:fF(s9(c.failure))}});let d=yield*uQ,p=c.success,h=yield*o.OH5(()=>d.createId("build")),g=(s=s5((t=p.spec).title),l=(e,t)=>t&&s5(t)?{[e]:s5(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.relationships.flatMap(e=>fE(e.id)??[])),{id:fE(t.id)??(fI(s)||"sketchi-er-diagram"),title:s,entities:t.entities.map(e=>({id:s5(e.id),...l("name",e.name),fields:e.fields.map(e=>{let t="string"==typeof e?tS(s5(e)):e;return{name:s5(t.name),...l("type",t.type),...r("pk",t.pk),...r("fk",t.fk),...r("unique",t.unique),...r("nullable",t.nullable)}})})),relationships:t.relationships.map((e,t)=>({id:fE(e.id)??(e=>{let t=e+1;for(;n.has(`relationship-${t}`);)t+=1;return n.add(`relationship-${t}`),`relationship-${t}`})(t),from:s5(e.from),to:s5(e.to),fromCardinality:e.fromCardinality,toCardinality:e.toCardinality,...l("label",e.label)})),style:{...y}}),u={buildId:h,...mt(p.requestId),normalizedSpec:g},f=tz(ft(g)).map(e=>fB({code:"missing_relationship_entity"===e.code&&e.path.endsWith(".from")?"missing_edge_source":fa[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new fv({status:"invalid_er_diagram",context:{...u,issues:f}});let m={accepted:10>=(a=p.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:g.entities.length,edgeCount:g.relationships.length},checks:[]},v={...u,quality:m};if(!m.accepted)return yield*new fv({status:"quality_failed",context:{...v,issues:fO(m)}});let w=yield*o.SvU({try:()=>{var e;let t,a,s,i,l,o,r,n,c,d,p;return t=new Map((e=ft(g)).entities.map(e=>[e.id,function(e){let t=tk(e),a=e.fields.map(e=>[e.pk&&"PK",e.fk&&"FK",e.unique&&!e.pk&&"UK"].filter(e=>"string"==typeof e).join(" ")),s=e.fields.map(e=>`${e.name.trim()}${e.nullable&&!e.type?"?":""}`),i=e.fields.map(e=>e.type?`${e.type}${e.nullable?"?":""}`:""),[l,o,r]=[a,s,i].map(hR),n=14+l+8*(l>0)+o+(r>0?16+r:0)+14,c=Math.ceil(aq(t,16))+28;return{entity:e,name:t,width:Math.max(160,n,c),height:e.fields.length>0?52+28*e.fields.length:40,keys:a,names:s,types:i,keyWidth:l,nameWidth:o,typeWidth:r,rows:new Map(e.fields.map((e,t)=>[tC(e.name),46+(t+.5)*28]))}}(e)])),a=e.relationships.map(e=>(function(e,t){let[a,s]=[tM(e.from),tM(e.to)],i=(e,a)=>{let s=t.get(e.entity);if(void 0!==e.field)return s.rows.get(tC(e.field));let i=s.entity.fields.filter(e=>e.pk);return void 0!==a.field&&1===i.length?s.rows.get(tC(i[0].name)):20},l={from:{entity:a.entity,y:i(a,s),cardinality:e.fromCardinality},to:{entity:s.entity,y:i(s,a),cardinality:e.toCardinality}},o=e=>{let a=void 0===e.field?void 0:t.get(e.entity).entity.fields.find(t=>tC(t.name)===tC(e.field));return void 0!==a&&!0===a.pk&&!0!==a.fk};return(hD(e.fromCardinality)!==hD(e.toCardinality)?hD(e.fromCardinality):!(o(s)&&!o(a)))?{relationship:e,parent:l.from,child:l.to}:{relationship:e,parent:l.to,child:l.from}})(e,t)),i=new Map((s=function(e,t,a){let s,i=a.map(e=>{let t;return{id:e.relationship.id,parent:e.parent.entity,child:e.child.entity,parentY:e.parent.y,childY:e.child.y,labelWidth:(t=e.relationship.label)?Math.min(160,Math.ceil(aq(t,13))):0}}),l=[...t.values()].map(e=>({id:e.entity.id,width:e.width,height:e.height})),o=e.entities.length>24?h2.slice(0,2):h2,r=new Set;for(let n of o){let o=function(e,t,a={}){let s,i,l,o,r,n=(s=new Map(e.map((e,t)=>[e.id,t])),{tables:e,index:s,links:t,pairs:t.flatMap(e=>e.parent===e.child?[]:[{parent:s.get(e.parent),child:s.get(e.child),link:e}])}),c=(i=function(e,t=1.6){let a=e.tables.reduce((e,t)=>e+(t.width+132)*(t.height+56),0),s=Math.max(...e.tables.map(e=>e.height)),i=e.tables.reduce((e,t)=>e+t.height+56,0)/e.tables.length,l=e.tables.reduce((e,t)=>e+t.width+150,0)/e.tables.length,o=Math.max(s,Math.sqrt(a/t));return{height:o,unit:i,width:1.25*t*o,column:l}}(n,a.aspect),l=a.sameColumn??2.5,o="hub"===a.start?function(e){let t=hq(e),a=e.tables.map(()=>void 0),s=new Map;for(let i of e.tables.map((e,t)=>t).sort((e,a)=>t[a].size-t[e].size||e-a)){if(void 0!==a[i])continue;a[i]=0,s.set(i,0);let l={[-1]:0,1:0},o=[i];for(;o.length>0;){let i=o.shift();for(let r of[...t[i]].filter(e=>void 0===a[e]).sort((e,a)=>t[a].size-t[e].size||e-a)){let t=s.get(i);0===t&&(t=l[1]<=l[-1]?1:-1,l[t]=l[t]+e.tables[r].height),a[r]=a[i]+t,s.set(r,t),o.push(r)}}}return a.map(e=>e??0)}(n):function(e){let t=e.tables.length,a=Array.from({length:t},()=>[]);for(let{parent:t,child:s}of e.pairs)a[t].push(s);let s=Array.from({length:t}).fill(0),i=Array.from({length:t},()=>[]),l=e=>{for(let t of(s[e]=1,a[e]))1!==s[t]&&(i[e].push(t),0===s[t]&&l(t));s[e]=2};for(let e=0;e<t;e+=1)0===s[e]&&l(e);let o=Array.from({length:t},()=>[]);for(let[e,t]of i.entries())for(let a of t)o[a].push(e);let r=Array.from({length:t},()=>0),n=[],c=o.map(e=>e.length),d=c.flatMap((e,t)=>0===e?[t]:[]);for(;d.length>0;){let e=d.shift();for(let t of(n.push(e),i[e]))r[t]=Math.max(r[t],r[e]+1),c[t]-=1,0===c[t]&&d.push(t)}for(let e of[...n].reverse())0===o[e].length&&i[e].length>0&&(r[e]=Math.min(...i[e].map(e=>r[e]))-1);return r}(n),hF(n,o,40,e=>hV(n,e,i,l)),r=new Map,hF(n,o,8,e=>{let t=hH(e),a=t.join(","),s=r.get(a);return void 0===s&&(s=h$(hI(n,t),!1).crossings,r.set(a,s)),hV(n,e,i,l)+ +s}),hH(o)),d=Math.max(...c)+1,p=hI(n,c),h=h$(p),g=function(e,t){let a=[...t.top],s=hY(e);for(let i=0;i<12;i+=1){let l=[...t.columns.keys()];for(let o of(i%2==1&&l.reverse(),l)){let i=t.columns[o];if(0===i.length)continue;let l=[],r=[];for(let t of i){let i=e.corridor[t];if(i){l.push(a[i.parent]+i.y-2),r.push(4);continue}let n=0,c=0;for(let{other:i,ownY:l,otherY:r}of s[t])e.column[i]!==o&&(n+=a[i]+r-l,c+=1);l.push(c>0?n/c:a[t]),r.push(c>0?c:.05)}let n=hO(e,i),c=function(e,t){let a=[];for(let[s,i]of e.entries()){let e=t[s];for(a.push({count:1,weight:e,sum:i*e});a.length>1;){let e=a.at(-1),t=a.at(-2);if(t.sum/t.weight<=e.sum/e.weight)break;a.pop(),t.count+=e.count,t.weight+=e.weight,t.sum+=e.sum}}return a.flatMap(e=>Array(e.count).fill(e.sum/e.weight))}(l.map((e,t)=>e-n[t]),r);for(let[e,t]of i.entries())a[t]=c[e]+n[e]}}return function(e,t,a){let s=hY(e),i=t=>t.reduce((t,i)=>t+s[i].filter(({other:t,ownY:s,otherY:l})=>e.column[t]!==e.column[i]&&.5>Math.abs(a[t]+l-a[i]-s)).length,0),l=(t,s)=>a[s]-a[t]-e.height[t]-hE(e,t,s)<.5;for(let o=0;o<2;o+=1)for(let o of t.columns)for(let[t,r]of o.entries())if(!e.corridor[r])for(let n of s[r].flatMap(({other:t,ownY:s,otherY:i})=>{let l=a[t]+i-a[r]-s;return e.column[t]!==e.column[r]&&Math.abs(l)>=.5&&40>=Math.abs(l)?[l]:[]})){let s=[r],c=n>0?1:-1;for(let i=t;;i+=c){let t=o[i+c];if(void 0===t)break;if(!(c>0?l(o[i],t):l(t,o[i]))){(c>0?a[t]-a[o[i]]-e.height[o[i]]-hE(e,o[i],t):a[o[i]]-a[t]-e.height[t]-hE(e,t,o[i]))<Math.abs(n)-.5&&(s.length=0);break}s.push(t)}if(0===s.length)continue;let d=i(s);for(let e of s)a[e]=a[e]+n;if(i(s)>d)break;for(let e of s)a[e]=a[e]-n}return a}(e,t,a.map(e=>Math.round(e)))}(p,h),u=function(e,t,a,s){let i=new Map,l=[],o=[];for(let a of e.links){let[r,n]=[e.index.get(a.parent),e.index.get(a.child)],[c,d]=[t[r],t[n]];if(c===d){o.push(a);continue}let[p,h]=c<d?["right","left"]:["left","right"];i.set(a.id,{parent:p,child:h}),l.push({column:c,side:p,y:s[r]+a.parentY}),l.push({column:d,side:h,y:s[n]+a.childY})}for(let r of o){let[o,n]=[e.index.get(r.parent),e.index.get(r.child)],c=t[o],[d,p]=[s[o]+r.parentY,s[n]+r.childY],[h,g]=[Math.min(d,p),Math.max(d,p)],u=e=>l.filter(t=>t.column===c&&t.side===e&&t.y>h&&t.y<g).length,f=0===c&&a>1?"left":"right",[m,v]=[u("left"),u("right")],y=m===v?f:m<v?"left":"right";i.set(r.id,{parent:y,child:y}),l.push({column:c,side:y,y:d},{column:c,side:y,y:p})}return i}(n,c,d,g),f=function(e,t,a,s){let i=Array.from({length:Math.max(0,s-1)},()=>0),l=Array.from({length:Math.max(0,s-1)},()=>0),o=new Map,r=(e,a,s)=>{let i="right"===a?t[e]:t[e]-1,l=`${e}:${a}:${s}`,r=o.get(l)??{gap:i,low:"right"===a,count:0};r.count+=1,o.set(l,r)};for(let s of e.links){let[o,n]=[e.index.get(s.parent),e.index.get(s.child)],[c,d]=[t[o],t[n]],p=a.get(s.id);r(o,p.parent,s.parentY),r(n,p.child,s.childY);let h="right"===p.parent?c:c-1;if(s.labelWidth>0&&h>=0&&h<i.length&&(l[h]=Math.max(l[h],s.labelWidth+16)),c===d){h>=0&&h<i.length&&(i[h]+=1);continue}for(let e=Math.min(c,d);e<Math.max(c,d);e+=1)i[e]+=1}let n=i.map(()=>({low:0,high:0})),c=new Map;for(let[e,{gap:t,low:a,count:s}]of o){let i=(s-1)*32,l=e.split(":").slice(0,2).join(":");c.set(l,Math.max(c.get(l)??0,i));let o=n[t];o&&(a?o.low=Math.max(o.low,i):o.high=Math.max(o.high,i))}for(let s of e.links){let[i,l]=[e.index.get(s.parent),e.index.get(s.child)];if(t[i]!==t[l])continue;let o=a.get(s.id).parent,r=n["right"===o?t[i]:t[i]-1];if(!r)continue;let d=Math.max(c.get(`${i}:${o}`)??0,c.get(`${l}:${o}`)??0)+32+Math.abs(e.tables[i].width-e.tables[l].width)/2;"right"===o?r.low=Math.max(r.low,d):r.high=Math.max(r.high,d)}return i.map((e,t)=>Math.max(132,96+n[t].low+n[t].high+l[t]+20*(e+1)))}(n,c,u,d),m=Array.from({length:d},(t,a)=>Math.max(0,...h.columns[a].flatMap(t=>t<e.length?[e[t].width]:[]))),v=88*!!t.some(e=>{let t=c[n.index.get(e.parent)];return t===c[n.index.get(e.child)]&&(0===t||t===d-1)}),y=[],w=v;for(let[e,t]of m.entries())y.push(w),w+=t+(f[e]??0);let x=Math.min(...g.slice(0,e.length));return{boxes:new Map(e.map((e,t)=>{let a=c[t];return[e.id,{x:y[a]+Math.round((m[a]-e.width)/2),y:g[t]-x,width:e.width,height:e.height}]})),sides:u}}(l,i,n),c=JSON.stringify([...o.boxes,...o.sides]);if(r.has(c))continue;r.add(c);let d=h0(e,t,a,o,h1(a,o)),p=h3(d),h=s?p:p-.75;if((!s||h<s.score)&&(s={cost:p,score:h,scene:d,placement:o}),0===p)break}let{placement:n}=s,c=h1(a,n);if(function(e,t){let a=!1;for(let s of hQ(e)){if(s.length<=2)continue;let[i,l]=[s[0].link[s[0].end].entity,s[0].side],o=t.get(i),r="left"===l?"right":"left",n=e.filter(e=>e.link[e.end].entity===i&&e.side===r&&e.row===s[0].row).length,c=a=>{let s=hZ(hK(e,a),t);return Math.max(o.y-48-s,s-(o.y+o.height+48))},d=s.filter(t=>hK(e,t).side!==t.side&&c(t)>0).sort((e,t)=>c(t)-c(e)),p=s.length;for(let e of d){if(p-n<2)break;e.side=r,p-=1,n+=1,a=!0}}return a}(c,n.boxes)){let i=h0(e,t,a,n,c);if(h3(i)<s.cost)return i}return s.scene}(e,t,a)).elements.flatMap(e=>"node"===e.type?[[e.nodeId,e]]:[])),l=e.entities.map(a=>(function(e,t,a){let{id:s}=e.entity,i=[`table:${s}`],l={type:"node",id:`node:${s}`,nodeId:s,kind:"entity",rendererRole:"er-table",shape:"rectangle",x:t.x,y:t.y,width:e.width,height:e.height,label:e.name,fillColor:a.style.backgroundColor,fillStyle:"solid",groupIds:i},o={type:"node",id:`node:${s}:header`,nodeId:`${s}:header`,kind:"entity-name",rendererRole:"er-table",shape:"rectangle",x:t.x,y:t.y,width:e.width,height:40,label:e.name,fillColor:"#efe6ec",fillStyle:"solid",groupIds:i},r=[{type:"text",id:`label:${s}:header`,containerId:o.id,x:t.x+e.width/2,y:t.y+20,text:e.name,fontSize:16,maxWidth:e.width-28,groupIds:i}];if(e.entity.fields.length>0){let a=t.y+40+6,l=28*e.entity.fields.length,o=(e,t,o,r,n)=>({type:"text",id:`text:${s}:${e}`,x:o+r/2,y:a+l/2,text:t.join("\n"),fontSize:14,lineHeight:2,maxWidth:r,textAlign:"left",...n?{textColor:n}:{},groupIds:i}),n=t.x+14;e.keyWidth>0&&(r.push(o("keys",e.keys,n,e.keyWidth,"#6a4e5c")),n+=e.keyWidth+8),r.push(o("fields",e.names,n,e.nameWidth)),e.typeWidth>0&&r.push(o("types",e.types,n+e.nameWidth+16,e.typeWidth,"#6f6656"))}return{nodes:[l,o],texts:r}})(t.get(a.id),i.get(a.id),e)),o=new Map(a.map(e=>[e.relationship.id,e])),r=[],n=e=>r.some(t=>14>Math.hypot(t.x-e.x,t.y-e.y)),c=s.elements.flatMap(t=>{if("arrow"!==t.type)return[];let a=o.get(t.edgeId);for(let[i,l]of[["start",a.parent],["end",a.child]]){var s;if("zero-or-one"!==(s=l.cardinality)&&"zero-or-many"!==s)continue;let[a,o]="start"===i?[t.points[0],t.points[1]]:[t.points.at(-1),t.points.at(-2)],c=Math.hypot(o.x-a.x,o.y-a.y),d=h4(t,i,l.entity,r.length,e);for(let a=46;n(d)&&a+12<=c;a+=14)d=h4(t,i,l.entity,r.length,e,a);r.push(d)}return[{...t,startArrowhead:hG[a.parent.cardinality],endArrowhead:hG[a.child.cardinality]}]}),d=s.elements.filter(e=>"text"===e.type&&void 0===e.containerId),p=[...l.flatMap(e=>[...e.nodes,...e.texts]),...c,...r,...d],{...s,elements:p,zOrder:p.map(e=>e.id)}},catch:e=>new fv({status:"render_failed",context:{...v,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.id},message:e instanceof Error?e.message:"Unable to render ER scene.",hint:"Repair the entities and relationships and retry."})]}})}).pipe(o.fRP("codeMode.buildErDiagram.render")),x=se(w);if(x.length>0)return yield*new fv({status:"render_failed",context:{...v,issues:f$(x).map(e=>({...e,hint:"Shorten entity or field names, or split the schema, and retry buildErDiagram."}))}});let b={...v,partial:ma(w)},k=yield*ml({scene:w,formats:fU(p.options),inlineFormats:fX(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fv({status:e.status,context:{..."export_failed"===e.status?b:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...mt(p.requestId),normalizedSpec:g,quality:m,artifact:k,issues:[]}}),md=o.fn("codeMode.buildClassDiagram.workflow")(function*(e){var t,a;let s,l,r,n,c=i.q$Z(l3,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:ao(e.spec)}:e);if(!um.oJ(c))return yield*new fy({status:"invalid_input",context:{issues:fF(s9(c.failure))}});let d=yield*uQ,p=c.success,h=yield*o.OH5(()=>d.createId("build")),g=(s=s5((t=p.spec).title),l=(e,t)=>t&&s5(t)?{[e]:s5(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.relationships.flatMap(e=>fE(e.id)??[])),{id:fE(t.id)??(fI(s)||"sketchi-class-diagram"),title:s,classes:t.classes.map(e=>({id:s5(e.id),...l("name",e.name),...e.kind?{kind:e.kind}:{},...l("stereotype",e.stereotype),attributes:e.attributes.map(e=>{let t="string"==typeof e?at(s5(e)):e;return{name:s5(t.name),...l("type",t.type),...t.visibility?{visibility:t.visibility}:{},...r("static",t.static)}}),methods:e.methods.map(e=>{let t="string"==typeof e?aa(s5(e)):e;return{name:s5(t.name),params:t.params.map(e=>{let t="string"==typeof e?t9(s5(e)):e;return{name:s5(t.name),...l("type",t.type)}}),...l("returns",t.returns),...t.visibility?{visibility:t.visibility}:{},...r("static",t.static),...r("abstract",t.abstract)}})})),relationships:t.relationships.map((e,t)=>({id:fE(e.id)??(e=>{let t=e+1;for(;n.has(`relationship-${t}`);)t+=1;return n.add(`relationship-${t}`),`relationship-${t}`})(t),kind:e.kind,from:s5(e.from),to:s5(e.to),...l("fromMultiplicity",e.fromMultiplicity),...l("toMultiplicity",e.toMultiplicity),...l("fromRole",e.fromRole),...l("toRole",e.toRole),...void 0===e.navigable?{}:{navigable:e.navigable},...l("label",e.label)})),style:{...y}}),u={buildId:h,...mt(p.requestId),normalizedSpec:g},f=t5(fs(g)).map(e=>fB({code:"missing_relationship_class"===e.code&&e.path.endsWith(".from")?"missing_edge_source":fi[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new fy({status:"invalid_class_diagram",context:{...u,issues:f}});let m={accepted:10>=(a=p.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:g.classes.length,edgeCount:g.relationships.length},checks:[]},v={...u,quality:m};if(!m.accepted)return yield*new fy({status:"quality_failed",context:{...v,issues:fO(m)}});let w=yield*o.SvU({try:()=>(function(e){let t=new Map(e.classes.map(e=>[e.id,function(e){let t,a=tW(e).trim(),s=(t=[tK[tJ(e)],e.stereotype?.trim()].filter(e=>"string"==typeof e&&e.length>0)).length>0?`\xab${t.join(", ")}\xbb`:void 0,i=e.attributes.map(t1),l=e.methods.map(t0),o=Math.max(aq(a,16),s?aq(s,16):0,...[...i,...l].map(e=>aq(e,14))),r=(s?2:1)*22+20,[n,c]=[go(i),go(l)];return{node:e,name:a,heading:s?`${s}
|
|
249
|
+
${a}`:a,width:Math.max(140,Math.ceil(o)+24),height:r+n+c,band:r,attributesHeight:n,methodsHeight:c,attributes:i,methods:l}}(e)])),a=function(e,t){let a,s=e.relationships.map(e=>({id:e.id,from:e.from.trim(),to:e.to.trim(),generalization:tT(e.kind),whole:"composition"===e.kind||"aggregation"===e.kind,fromLabel:Math.max(0,...gr(e,"from").map(gn)),toLabel:Math.max(0,...gr(e,"to").map(gn)),label:e.label?gn(e.label.trim()):0})),i=e.classes.map(e=>{let a=t.get(e.id);return{id:e.id,width:a.width,height:a.height,dividers:[a.band,a.band+a.attributesHeight]}}),l=e.classes.length>20?gd.slice(0,2):gd,o=new Set;for(let r of l){let l=function e(t,a,s={},i=0){let l=function(e,t){let a=new Map(e.map((e,t)=>[e.id,t])),s=[],i=[];for(let e of t){let[t,l]=[a.get(e.from),a.get(e.to)];t!==l&&(e.generalization?s.push({parent:l,child:t}):i.push({a:t,b:l,whole:!0===e.whole}))}return{boxes:e,index:a,links:t,generalizations:s,others:i}}(t,a),o=function(e,t){let a,s=function(e,t=1.6){let a=e.boxes.reduce((e,t)=>e+(t.width+64)*(t.height+130),0),s=Math.max(...e.boxes.map(e=>e.width)),i=Math.sqrt(a/t),l=e.boxes.length;return{width:Math.max(s,1.2*t*i),height:i,column:e.boxes.reduce((e,t)=>e+t.width+64,0)/l,unit:e.boxes.reduce((e,t)=>e+t.height+130,0)/l}}(e,t.aspect),i=t.between??.3,l=t.wholeBelow??0,o=function(e){let t=e.boxes.length,a=Array.from({length:t},()=>[]),s=Array.from({length:t},()=>[]);for(let{parent:t,child:i}of e.generalizations)a[i].push(t),s[t].push(i);let i=Array.from({length:t},()=>0),l=a.map(e=>e.length),o=l.flatMap((e,t)=>0===e?[t]:[]),r=[];for(;o.length>0;){let e=o.shift();for(let t of(r.push(e),s[e]))i[t]=Math.max(i[t],i[e]+1),l[t]-=1,0===l[t]&&o.push(t)}for(let e of r.toReversed())s[e].length>0&&(i[e]=Math.min(...s[e].map(e=>i[e]))-1);let n=new Set(e.generalizations.flatMap(({parent:e,child:t})=>[e,t]));0===n.size&&e.others.length>0&&n.add(e.others[0].a);for(let a=0;a<t&&n.size<t;a+=1)for(let{a:t,b:a}of e.others){if(n.has(t)===n.has(a))continue;let[e,s]=n.has(t)?[t,a]:[a,t];i[s]=i[e],n.add(s)}let c=Math.min(...i);return i.map(e=>e-c)}(e),r=e.boxes.map(()=>new Set);for(let{parent:t,child:a}of e.generalizations)r[t].add(a),r[a].add(t);for(let{a:t,b:a}of e.others)r[t].add(a),r[a].add(t);let n=e.boxes.map((e,t)=>t).sort((e,t)=>r[t].size-r[e].size||e-t),c=h6(e,o,s,i,l);for(let t=0;t<40;t+=1){let t=!1;for(let a of n){let n=o[a],d=new Set([n-1,n+1,n+2]);for(let e of r[a])for(let t of[-1,0,1])d.add(o[e]+t);if(0===r[a].size)for(let e of o)d.add(e);d.delete(n);let p=n;for(let t of[...d].sort((e,t)=>e-t)){o[a]=t;let r=h6(e,o,s,i,l);r<c-1e-9&&([p,c]=[t,r])}o[a]=p,p!==n&&(t=!0)}if(!t)break}return a=new Map([...new Set(o)].sort((e,t)=>e-t).map((e,t)=>[e,t])),o.map(e=>a.get(e))}(l,s),r=function(e,t){let a=[...t],s=e.boxes.map(e=>e.width),i=e.boxes.map(()=>!1),l=[],o=[],r=[];for(let n of e.links){let[c,d]=[e.index.get(n.from),e.index.get(n.to)];if(c===d){r.push([c]);continue}let[p,h]=[t[c],t[d]];if(p===h){o.push({a:c,b:d}),r.push([c,d]);continue}let g=Math.sign(h-p),u=[c];for(let e=p+g;e!==h;e+=g){let t=a.length;a.push(e),s.push(4),i.push(!0),u.push(t)}u.push(d);let f=n.generalization?3:1;for(let[e,t]of u.slice(1).entries()){let s=u[e];l.push(a[s]<a[t]?{upper:s,lower:t,weight:f}:{upper:t,lower:s,weight:f})}r.push(u)}return{row:a,width:s,corridor:i,segments:l,flats:o,chains:r}}(l,o),n=new Map,c=(e,t,a)=>{let s=e<t?`${e}:${t}`:`${t}:${e}`;n.set(s,Math.max(n.get(s)??0,a))};for(let[e,t]of a.entries()){let a=r.chains[e],[s,i]=[a[0],a.at(-1)];s!==i&&r.row[s]===r.row[i]&&c(s,i,Math.max(50,t.fromLabel+16)+(t.label>0?t.label+16:0)+Math.max(50,t.toLabel+16))}let d=function(e,t){let a=Array.from({length:Math.max(...e.row)+1},()=>[]);for(let[t,s]of e.row.entries())a[s].push(t);let s=e.row.map(()=>[]);for(let{upper:t,lower:a}of e.segments)s[t].push({other:a,weight:1}),s[a].push({other:t,weight:1});for(let{a:t,b:a}of e.flats)s[t].push({other:a,weight:.5}),s[a].push({other:t,weight:.5});let i=h9(e,t,a),l={rows:a.map(e=>[...e]),crossings:ge(e,a,i)};for(let o=0;o<8&&l.crossings>0;o+=1){let r=[...a.keys()];for(let l of(o%2==1&&r.reverse(),r)){let o=new Map;for(let e of a[l]){let t=0,a=0;for(let{other:l,weight:o}of s[e])t+=o*i[l],a+=o;o.set(e,a>0?t/a:i[e])}a[l]=[...a[l]].sort((e,t)=>o.get(e)-o.get(t)||i[e]-i[t]),i=h9(e,t,a)}let n=ge(e,a,i);n<l.crossings&&(l={rows:a.map(e=>[...e]),crossings:n})}let o=a=(a=l.rows).map(t=>{let a=t=>e.segments.find(e=>e.lower===t)?.upper,s=new Map;for(let e of t){let t=a(e);void 0!==t&&s.set(t,[...s.get(t)??[],e])}let i=t;for(let t of s.values()){let a=t.filter(t=>e.corridor[t]),s=t.filter(t=>!e.corridor[t]);if(0===a.length||s.length<2)continue;let l=[];for(let[e,t]of s.entries()){l.push(t);let i=Math.round(e*a.length/(s.length-1)),o=Math.round((e+1)*a.length/(s.length-1));e<s.length-1&&l.push(...a.slice(i,o))}let o=i.flatMap((e,a)=>t.includes(e)?[a]:[]),r=[...i];for(let[e,t]of o.entries())r[t]=l[e];i=r}return i});a=l.rows,ge(e,o,h9(e,t,o))<=ge(e,a,h9(e,t,a))&&(a=o);let r=ge(e,a,h9(e,t,a));for(let s=r>0,i=0;s&&i<40;i+=1)for(let i of(s=!1,a))for(let l=0;l+1<i.length;l+=1){[i[l],i[l+1]]=[i[l+1],i[l]];let o=ge(e,a,h9(e,t,a));o<r?(r=o,s=!0):[i[l],i[l+1]]=[i[l+1],i[l]]}return a}(r,n);for(let[e,t]of a.entries()){let a=r.chains[e],[s,i]=[a[0],a.at(-1)];if(s===i||r.row[s]!==r.row[i])continue;let l=d[r.row[s]],[o,n]=[l.indexOf(s),l.indexOf(i)],p=l.slice(Math.min(o,n)+1,Math.max(o,n));if(0===p.length||p.some(e=>!r.corridor[e]))continue;let[h,g]=o<n?[s,i]:[i,s],[u,f]=o<n?[t.fromLabel,t.toLabel]:[t.toLabel,t.fromLabel];c(h,p[0],Math.max(50,u+16)),c(p.at(-1),g,Math.max(50,f+16))}let p=e=>Math.max(40,Math.max(e.fromLabel,e.toLabel)+24);for(let[e,t]of a.entries()){if(t.from!==t.to)continue;let a=r.chains[e][0],s=d[r.row[a]],i=s.filter(e=>!r.corridor[e]),l=i.indexOf(a),o=s.indexOf(a),n=p(t)+t.label+56+64;for(let e of[i[l-1],i[l+1],s[o-1],s[o+1]])void 0!==e&&c(a,e,n)}let h=function(e,t,a){let s=h9(e,t,a),i=e.row.map(()=>[]);for(let{upper:t,lower:a,weight:s}of e.segments)i[t].push({other:a,weight:s}),i[a].push({other:t,weight:s});for(let l=0;l<12;l+=1){let o=[...a.keys()];for(let r of(l%2==1&&o.reverse(),o)){let l=a[r];if(0===l.length)continue;let o=[],n=[];for(let t of l){let a=i[t];if(0===a.length){o.push(s[t]),n.push(.05);continue}let l=a.reduce((e,{weight:t})=>e+t,0);o.push(a.reduce((e,{other:t,weight:a})=>e+a*s[t],0)/l),n.push(e.corridor[t]?4:l)}let c=h8(e,t,l),d=gt(o.map((t,a)=>t-e.width[l[a]]/2-c[a]),n);for(let[t,a]of l.entries())s[a]=d[t]+c[t]+e.width[a]/2}}return s.map((t,a)=>{let s=e.width[a]/2;return Math.round(t-s)+s})}(r,n,d),g=e=>e<t.length?t[e]:{id:"",width:4,height:0},u=Math.ceil(24/s_({width:Math.max(...t.map((e,t)=>h[t]+e.width/2))-Math.min(...t.map((e,t)=>h[t]-e.width/2)),height:d.reduce((e,a)=>e+Math.max(0,...a.filter(e=>e<t.length).map(e=>t[e].height))+100+28,0)}))+4,f={port:Math.max(32,u),track:Math.max(28,u),lane:Math.max(20,u)},m=function(e,t,a,s){let i=new Map;for(let e of a)for(let[t,a]of e.entries())i.set(a,t);let l=[],o=new Map,r=(e,t)=>o.set(`${e}:${t}`,(o.get(`${e}:${t}`)??0)+1),n=[],c=(e,t,a,s,i)=>({link:e,end:t,box:a,side:i,at:0,toward:s,loop:!1,slot:0}),d=(e,a,i,l)=>t.segments.filter(({upper:o,lower:r})=>{let n=l?r:o;return t.row[n]===e&&s[n]>a&&s[n]<i}).length;for(let[o]of e.links.entries()){let e=t.chains[o],[p,h]=[e[0],e.at(-1)];if(p===h){n.push([c(o,"source",p,p,"right"),c(o,"target",h,h,"right")]);continue}if(t.row[p]===t.row[h]){let[e,n]=[i.get(p),i.get(h)],g=t.row[p],u=a[g].slice(Math.min(e,n)+1,Math.max(e,n)).some(e=>!t.corridor[e]),f=e<n?["right","left"]:["left","right"];if(u){let[e,t]=[s[p],s[h]].sort((e,t)=>e-t),[a,i]=[d(g,e,t,!0),d(g,e,t,!1)];f=a<i||a===i&&0===g?["top","top"]:["bottom","bottom"]}l.push(c(o,"source",p,h,f[0]),c(o,"target",h,p,f[1])),r(p,f[0]),r(h,f[1]);continue}let g=t.row[p]<t.row[h];l.push(c(o,"source",p,e[1],g?"bottom":"top"),c(o,"target",h,e.at(-2),g?"top":"bottom"))}let p=new Map,h=a.length-1;for(let e of n){let a=e[0].box,s=e=>l.some(t=>t.box===a&&t.side===e),i=["right","left","top","bottom"].filter(e=>!s(e)&&("right"===e||"left"===e||("top"===e?0===t.row[a]:t.row[a]===h)))[0]??((o.get(`${a}:right`)??0)<=(o.get(`${a}:left`)??0)?"right":"left"),r=p.get(`${a}:${i}`)??0;for(let t of(p.set(`${a}:${i}`,r+1),e))t.side=i,t.loop=!0,t.slot=r;l.push(...e)}return l}(l,r,d,h);if(i<2){let l=t.map((e,t)=>{let a=e=>36+Math.max(0,m.filter(a=>a.box===t&&a.side===e).length-1)*f.port,s=Math.ceil(Math.max(e.width,a("top"),a("bottom"))),i=Math.ceil(Math.max(e.height,a("left"),a("right")));return s===e.width&&i===e.height?e:{...e,width:s,height:i}});if(l.some((e,a)=>e!==t[a]))return e(l,a,s,i+1)}let v=()=>(function(e,t,a,s,i,l){let{port:o,lane:r}=l,n=new Map;for(let t of e){let e=`${t.box}:${t.side}`;n.set(e,[...n.get(e)??[],t])}let c=e=>t[e]-a(e).width/2,d=e=>gs(e.side)?a(e.box).width:a(e.box).height,p=e=>{let{end:t,name:a}=s(e);if(!gs(e.side))return 26*(t>0);let i=Math.max(t,e.loop||0===a?0:Math.ceil(a/2)+14);return i>0?i+14:0},h=(e,t)=>{let[a,s]=[p(e),p(t)];return Math.max(o,a>0&&s>0?a+s:Math.max(a,s))},g=e=>{let t=e.slice(1).map((t,a)=>h(e[a],t)),a=d(e[0])-36,s=t.length*o,i=t.reduce((e,t)=>e+t-o,0),l=s+i<=a?t:s<=a?t.map(e=>o+(e-o)*(a-s)/i):t.map(()=>a/t.length),r=[0];for(let e of l)r.push(r.at(-1)+e);return r},u=(t,s)=>{if(gs(t.side))return!1;let i=ga(e,t);return[...a(t.box).dividers??[],...i.loop?[]:a(i.box).dividers??[]].some(e=>8>Math.abs(e-s))},f=t=>{let s=ga(e,t),i=t.loop?a(t.box).height:Math.min(a(t.box).height,a(s.box).height),l=Math.round(i/2);for(let e=0;e<i/2-18;e+=2)for(let a of[l+e,l-e])if(!u(t,a))return a;return l},m=i=>{let l=ga(e,i);if(gs(i.side)&&i.loop){let e=Math.min(2*Math.max(s(i).end,s(l).end)+72+2*i.slot*o,a(i.box).width-36);return a(i.box).width/2+("source"===i.end?-1:1)*e/2}if(gs(i.side))return(l.box!==i.toward||i.loop?t[i.toward]:c(l.box)+l.at)-c(i.box);if(i.loop){let e=Math.min(64+2*i.slot*o,a(i.box).height-36);return f(i)+("source"===i.end?-1:1)*e/2}return l.at};for(let t of e)t.at=gs(t.side)?a(t.box).width/2:f(t);for(let e=0;e<8;e+=1){let e=!1;for(let t of n.values()){let a=d(t[0]),s=t.map(m),i=t.map((e,t)=>t).sort((e,a)=>s[e]-s[a]||t[e].link-t[a].link||("source"===t[e].end?-1:1)),l=g(i.map(e=>t[e])),o=gt(i.map((e,t)=>s[e]-l[t]),i.map(()=>1)),r=l.at(-1)??0;i.forEach((s,i)=>{let n=Math.round(Math.min(Math.max(o[i],18),a-18-r)+l[i]);n!==t[s].at&&(e=!0),t[s].at=n})}if(!e)break}let v=(e,t)=>{let a=n.get(`${e.box}:${e.side}`);return!(t<18||t>d(e)-18||u(e,t))&&a.every(a=>a===e||Math.sign(a.at-e.at)===Math.sign(a.at-t)&&Math.abs(a.at-t)>=Math.min(h(a,e),Math.abs(a.at-e.at))-.5)};for(let t of e){if("source"!==t.end||t.loop||!gs(t.side))continue;let a=ga(e,t);if(a.box!==t.toward||!gs(a.side)||a.side===t.side)continue;let[s,i]=[c(t.box)+t.at,c(a.box)+a.at];!(.5>Math.abs(s-i)||Math.abs(s-i)>72)&&(v(a,Math.round(s-c(a.box)))?a.at=Math.round(s-c(a.box)):v(t,Math.round(i-c(t.box)))&&(t.at=Math.round(i-c(t.box))))}let y=e=>c(e.box)+e.at,w=t=>e.filter(e=>e.link!==t.link&&!e.loop&&e.side===("top"===t.side?"bottom":"top")&&i(e.box)===i(t.box)+("top"===t.side?-1:1)),x=(e,t)=>w(e).every(a=>Math.abs(y(a)-(c(e.box)+t))>=r),b=e=>{for(let t=4;t<=3*o;t+=4){let a=[e.at+t,e.at-t].find(t=>v(e,t)&&x(e,t));if(void 0!==a)return e.at=a,!0}let t=n.get(`${e.box}:${e.side}`),a=d(e);for(let s=4;s<=3*o;s+=4)for(let i of[s,-s])if(t.every(e=>e.at+i>=18&&e.at+i<=a-18&&(x(e,e.at+i)||!x(e,e.at)))&&x(e,e.at+i)){for(let e of t)e.at+=i;return!0}return!1};for(let t of e){if(t.loop||"top"!==t.side)continue;let e=w(t).filter(e=>Math.abs(y(e)-y(t))<r);if(e.length>0&&!b(t))for(let t of e)b(t)}for(let t of e){if(gs(t.side)||!u(t,t.at))continue;let a=ga(e,t),s=!t.loop&&a.at===t.at;for(let e=2;e<=16;e+=2){let i=[t.at+e,t.at-e].find(e=>v(t,e)&&(!s||v(a,e)));if(void 0!==i){t.at=i,s&&(a.at=i);break}}}})(m,h,g,e=>{let t=a[e.link];return{end:"source"===e.end?t.fromLabel:t.toLabel,name:t.label}},e=>r.row[e],f);v();let y=e=>h[e]-g(e).width/2,w=e=>y(e.box)+e.at,x=a.map((e,t)=>["source","target"].map(e=>m.find(a=>a.link===t&&a.end===e)));!function(e,t,a,s,i,l,o){let r=new Map;for(let e of a)for(let[t,a]of e.entries())r.set(a,t);let n=(i,l)=>{let o=a[e.row[i]],n=r.get(i),[c,d]=[o[n-1],o[n+1]],p=e.width[i]/2;return(void 0===c||l-p>=s[c]+e.width[c]/2+h7(e,t,c,i))&&(void 0===d||l+p<=s[d]-e.width[d]/2-h7(e,t,i,d))};for(let[t,a]of e.chains.entries()){let e=a.slice(1,-1);if(0===e.length)continue;let l=i(t).find(t=>e.every(e=>n(e,t)));if(void 0!==l)for(let t of e)s[t]=l}for(let[t,a]of e.chains.entries())for(let i of a.slice(1,-1)){let a=e.row[i],r=e=>l.some(s=>s.link!==t&&(s.row===a-1||s.row===a+1)&&Math.abs(s.x-e)<o.lane);if(r(s[i]))for(let e=4;e<=3*o.port;e+=4){let t=[s[i]+e,s[i]-e].find(e=>n(i,e)&&!r(e));if(void 0!==t){s[i]=t;break}}}}(r,n,d,h,e=>{let[t,a]=x[e];return r.row[t.box]<r.row[a.box]?[w(t),w(a)]:[w(a),w(t)]},m.flatMap(e=>gs(e.side)&&!e.loop?[{link:e.link,row:r.row[e.box],x:w(e)}]:[]),f),r.corridor.some(Boolean)&&v();let b=d.length,k=d.map(e=>Math.max(0,...e.filter(e=>e<t.length).map(e=>t[e].height))),M=new Map,C=(e,t)=>M.set(e,[...M.get(e)??[],t]);for(let[e]of a.entries()){let[t,a]=x[e],s=r.chains[e];if(t.loop||"left"===t.side||"right"===t.side)continue;if(t.side===a.side){let[e,i]=[w(t),w(a)],l=r.row[s[0]],o="top"===t.side;C(o?l-1:l,{ends:[t,a],upper:o?[]:[e,i],lower:o?[e,i]:[],min:Math.min(e,i),max:Math.max(e,i),track:0});continue}let i=r.row[s[0]]<r.row[s.at(-1)]?s:s.toReversed(),[l,o]=i[0]===s[0]?[t,a]:[a,t];for(let[e,t]of i.slice(1).entries()){let a=i[e],s=a===i[0]?w(l):h[a],n=t===i.at(-1)?w(o):h[t];.5>Math.abs(s-n)||C(r.row[a],{ends:[...a===i[0]?[l]:[],...t===i.at(-1)?[o]:[]],upper:[s],lower:[n],min:Math.min(s,n),max:Math.max(s,n),track:0})}}let z=new Map([...M].map(([e,t])=>[e,function(e,t){let a=[...e],s=[];for(;a.length>0;){let e=0,t=1/0;for(let[s,i]of a.entries()){let l=a.reduce((e,t)=>t===i?e:e+gi(i,t),0);l<t&&([e,t]=[s,l])}s.push(a.splice(e,1)[0])}let i=(e,a)=>e.min<a.max+t&&a.min<e.max+t,l=0;for(let[e,t]of s.entries())t.track=Math.max(0,...s.slice(0,e).filter(e=>i(e,t)||gi(t,e)>=1e3).map(e=>e.track+1)),l=Math.max(l,t.track+1);return l}(t,f.track)])),_=new Set;for(let[e,t]of a.entries()){let[a,s]=x[e];if(0===t.label||a.loop||"left"===a.side||"right"===a.side)continue;let[i,l]=[r.row[a.box],r.row[s.box]];if(a.side===s.side)_.add("top"===a.side?i-1:i);else for(let e=Math.min(i,l);e<Math.max(i,l);e+=1)_.add(e)}let L=e=>54*!!_.has(e),B=e=>100+L(e)+Math.max(0,(z.get(e)??0)-1)*f.track,S=[],A=z.has(-1)?B(-1):0;for(let e=0;e<b;e+=1)S.push(A),A+=k[e]+B(e);let P=(e,t)=>(e<0?0:S[e]+k[e])+50+L(e)+t*f.track,V=Math.min(...t.map((e,t)=>y(t))),H=new Map(t.map((e,t)=>[e.id,{x:Math.round(y(t)-V),y:S[r.row[t]],width:e.width,height:e.height}])),q=new Map;for(let[e,a]of M)for(let s of a)for(let a of s.ends){let i=H.get(t[a.box].id),l="bottom"===a.side?i.y+i.height:i.y;q.set(a,Math.abs(P(e,s.track)-l))}for(let e of m){if(!e.loop)continue;let t=m.filter(t=>t.loop&&t.box===e.box&&t.side===e.side&&t.slot<e.slot).reduce((e,t)=>Math.max(e,p(a[t.link])),0);q.set(e,Math.max(p(a[e.link]),t+f.track))}return{boxes:H,anchors:new Map(m.map(e=>{let s=t[e.box],i=gs(e.side)?s.width:s.height,l=q.get(e);return[`${a[e.link].id}:${e.end}`,{side:e.side,offset:e.at-i/2,...void 0===l?{}:{run:l}}]})),rows:new Map(t.map((e,t)=>[e.id,r.row[t]]))}}(i,s,r),n=JSON.stringify([...l.boxes,...l.anchors]);if(o.has(n))continue;o.add(n);let c=function(e,t,a){let s=function(e,t){let a=new Map;for(let s of e.relationships)for(let e of["from","to"]){let i=t.anchors.get(`${s.id}:${"from"===e?"source":"target"}`),l=t.boxes.get(s[e].trim()),o=gr(s,e);if(!i||!l||0===o.length||"left"!==i.side&&"right"!==i.side)continue;let r=Math.max(...o.map(gn))+8,n=l.y+l.height/2+i.offset,c="right"===i.side?l.x+l.width+2:l.x-2-r;for(let[t,i]of[["above",n-10+4-18],["below",n+10-4]])a.set(`${gc}${s.id}:${e}:${t}`,{x:c,y:i,width:r,height:18})}return a}(e,a);return hS({id:e.id,title:e.title,type:"flowchart",nodes:[...e.classes.map(e=>({id:e.id,label:t.get(e.id).name,kind:"class",metadata:{}})),...[...s.keys()].map(e=>({id:e,label:"·",kind:"class",metadata:{}}))],edges:e.relationships.map(e=>({id:e.id,source:e.from.trim(),target:e.to.trim(),metadata:{}})).map((e,t)=>({edge:e,index:t,span:Math.abs((a.rows.get(e.source)??0)-(a.rows.get(e.target)??0))})).sort((e,t)=>Math.min(e.span,2)-Math.min(t.span,2)||e.index-t.index).map(({edge:e})=>e),layout:{direction:"TB",edgeRouting:"orthogonal"},style:e.style,metadata:{}},{placement:new Map([...a.boxes,...s]),anchors:a.anchors,endRun:50})}(e,t,l),d=function(e){let t=e.elements.filter(e=>"arrow"===e.type),a=Math.max(e.width/e.height,e.height/e.width);return hy(t)+sq(t.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),s_({width:e.width,height:e.height})).length+(a>2.5?4*(a-2.5):0)+t.reduce((e,t)=>e+function(e){let[t,a]=[e.points[0],e.points.at(-1)],s=0;for(let[t,a]of e.points.slice(1).entries())s+=Math.abs(a.x-e.points[t].x)+Math.abs(a.y-e.points[t].y);return Math.max(0,s/(Math.abs(a.x-t.x)+Math.abs(a.y-t.y)+100+200)-1)}(t),0)+3*function(e){let t=e.flatMap(e=>sp(e.points).map(t=>({arrow:e.id,segment:t}))),a=0;for(let[e,s]of t.entries())for(let i of t.slice(e+1))i.arrow!==s.arrow&&i.segment.orientation===s.segment.orientation&&10>Math.abs(i.segment.staticCoordinate-s.segment.staticCoordinate)&&Math.min(i.segment.max,s.segment.max)>Math.max(i.segment.min,s.segment.min)&&(a+=1);return a}(t)}(c);if((!a||d<a.cost-.75)&&(a={cost:d,scene:c}),0===d)break}return a.scene}(e,t),s=new Map(a.elements.flatMap(e=>"node"!==e.type||e.nodeId.startsWith(gc)?[]:[[e.nodeId,e]])),i=e.classes.map(a=>(function(e,t,a){let{id:s}=e.node,i=[`class:${s}`],[l,o]=[t.width,t.height],r=(a,o,r,n,c)=>({type:"node",id:`node:${s}${a}`,nodeId:`${s}${a}`,kind:o,rendererRole:"class-box",shape:"rectangle",x:t.x,y:r,width:l,height:n,label:e.name,...c?{fillColor:c,fillStyle:"solid"}:{},groupIds:i}),n=r("","class",t.y,o,a.style.backgroundColor),c=r(":name","class-name",t.y,e.band,"#efe6ec"),d=t.y+e.band+e.attributesHeight,p=r(":methods","class-methods",d,t.y+o-d),h=[{type:"text",id:`label:${s}:name`,containerId:c.id,x:t.x+l/2,y:t.y+e.band/2,text:e.heading,fontSize:16,lineHeight:1.375,maxWidth:l-24,...e.heading!==e.name?{textColor:"#6a4e5c"}:{},groupIds:i}],g=(e,a,l)=>{if(0===a.length)return;let o=22*a.length,r=Math.ceil(Math.max(...a.map(e=>aq(e,14))));h.push({type:"text",id:`text:${s}:${e}`,x:t.x+12+r/2,y:l+6+o/2,text:a.join("\n"),fontSize:14,lineHeight:22/14,maxWidth:r,textAlign:"left",groupIds:i})};return g("attributes",e.attributes,t.y+e.band),g("methods",e.methods,d),{nodes:[n,c,p],texts:h}})(t.get(a.id),s.get(a.id),e)),l=new Map(e.relationships.map(e=>[e.id,e])),o=a.elements.flatMap(e=>{var t;let a;if("arrow"!==e.type)return[];let s=(a=gl[(t=l.get(e.edgeId)).kind],t.navigable&&tY(t.kind)?{...a,to:"arrow"}:a);return[{...e,startArrowhead:s.from,endArrowhead:s.to,..."dashed"===s.stroke?{strokeStyle:"dashed"}:{}}]}),r=function(e,t,a){let s=a.map(e=>({left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})),i=t.flatMap(e=>sp(e.points)),l=[],o=e=>s.filter(t=>gp(e,t,3)).length+i.filter(t=>"horizontal"===t.orientation?t.staticCoordinate>e.top-3&&t.staticCoordinate<e.bottom+3&&t.max>e.left-3&&t.min<e.right+3:t.staticCoordinate>e.left-3&&t.staticCoordinate<e.right+3&&t.max>e.top-3&&t.min<e.bottom+3).length+l.filter(t=>gp(e,t,3)).length,r=e=>0===o(e),n=[],c=(e,t,a,s)=>{l.push(a),n.push({type:"text",id:e,x:(a.left+a.right)/2,y:(a.top+a.bottom)/2,text:t,fontSize:13,maxWidth:a.right-a.left,...s?{groupIds:[s]}:{}})},d=new Map(t.map(e=>[e.edgeId,e])),p=(e,t,a,s,i)=>e.slice(0,-1).flatMap((l,o)=>[...function*(e,t,a,s,i,l){let o=Math.hypot(t.x-e.x,t.y-e.y);if(o<1)return;let[r,n]=[(t.x-e.x)/o,(t.y-e.y)/o],c=Math.abs(r)>.5?a:s;for(let t=l;t+c<=Math.max(o,l+c);t+=6){for(let l of i)if(Math.abs(r)>.5){let i=r>0?e.x+t:e.x-t-a,o=l<0?e.y-10+4-s:e.y+10-4;yield{left:i,top:o,right:i+a,bottom:o+s}}else{let i=n>0?e.y+t:e.y-t-s,o=l>0?e.x+10:e.x-10-a;yield{left:o,top:i,right:o+a,bottom:i+s}}if(t+c>=o)break}}(l,e[o+1],t,a,s,0===o?i:6)]),h=(...e)=>p(...e).find(r);for(let t of e.relationships){let e=d.get(t.id);if(e)for(let a of["from","to"]){let s=gr(t,a);if(0===s.length)continue;let i="from"===a?e.points:e.points.toReversed(),o="from"===a?e.sourceNodeId:e.targetNodeId,r=[t["from"===a?"fromMultiplicity":"toMultiplicity"]&&"multiplicity",t["from"===a?"fromRole":"toRole"]&&"role"].filter(e=>"string"==typeof e),n=2===s.length?[[1,-1],[-1,1]]:[[1],[-1]],d=e=>{let t=[];for(let[a,o]of s.entries()){let s=h(i,gn(o),18,e(a),4);if(!s)break;t.push(s),l.push(s)}return l.splice(l.length-t.length,t.length),t.length===s.length?t:void 0};for(let[e,l]of(n.map(e=>d(t=>[e[t]])).find(Boolean)??d(()=>[1,-1])??s.map(e=>p(i,gn(e),18,[1,-1],4)[0])).entries())c(`relationship:${t.id}:${a}:${r[e]}`,s[e],l,`class:${o}`)}}for(let t of e.relationships){let e=d.get(t.id);if(!e||!t.label)continue;let a=e.points.slice(0,-1).map((t,a)=>[t,e.points[a+1]]).reduce((e,t)=>Math.hypot(t[1].x-t[0].x,t[1].y-t[0].y)>Math.hypot(e[1].x-e[0].x,e[1].y-e[0].y)?t:e),s={x:(a[0].x+a[1].x)/2,y:(a[0].y+a[1].y)/2},i=[1,2,3,4,5].map(e=>(function(e,t){let a=e.split(/\s+/u);if(t<=1||a.length<t)return e;let s=(e,t)=>aq(a.slice(e,t).join(" "),13),i=new Map,l=(e,t)=>{if(1===t)return{widest:s(e,a.length),breaks:[]};let o=`${e}:${t}`,r=i.get(o);if(r)return r;let n={widest:1/0,breaks:[]};for(let i=e+1;i<=a.length-t+1;i+=1){let a=l(i,t-1),o=Math.max(s(e,i),a.widest);o<n.widest&&(n={widest:o,breaks:[i,...a.breaks]})}return i.set(o,n),n},o=[0,...l(0,t).breaks,a.length];return o.slice(1).map((e,t)=>a.slice(o[t],e).join(" ")).join("\n")})(t.label.trim(),e)),l=t=>{let[i,l]=[gn(t),18*t.split("\n").length];return[...p([s,a[1]],i,l,[-1,1],0),...p(e.points,i,l,[-1,1],50),...p(e.points,i,l,[-1,1],0)]},n=i.map(e=>({text:e,rect:l(e).find(r)})).find(e=>void 0!==e.rect);if(n){c(`relationship:${t.id}:name`,n.text,n.rect);continue}let h=i.flatMap(e=>l(e).map(t=>({text:e,rect:t,hits:o(t)}))).reduce((e,t)=>t.hits<e.hits?t:e);c(`relationship:${t.id}:name`,h.text,h.rect)}return n}(e,o,[...s.values()]),{elements:n,width:c,height:d}=function(e){let t=e.flatMap(e=>{if("arrow"===e.type||"line"===e.type)return[...e.points];if("text"===e.type){if(e.containerId)return[];let t=(e.maxWidth??0)/2,a=e.text.split("\n").length*e.fontSize*(e.lineHeight??1.35)/2;return[{x:e.x-t,y:e.y-a},{x:e.x+t,y:e.y+a}]}return"frame"===e.type||"node"===e.type?[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]:[]}),[a,s]=[Math.min(...t.map(e=>e.x)),Math.min(...t.map(e=>e.y))],[i,l]=[Math.max(0,48-a),Math.max(0,48-s)].map(Math.ceil);return{elements:e.map(e=>0===i&&0===l?e:"arrow"===e.type?{...e,points:e.points.map(e=>({x:e.x+i,y:e.y+l}))}:"line"===e.type?e:{...e,x:e.x+i,y:e.y+l}),width:Math.max(...t.map(e=>e.x))+i+48,height:Math.max(...t.map(e=>e.y))+l+48}}([...i.flatMap(e=>[...e.nodes,...e.texts]),...o,...r]);return{...a,width:c,height:d,elements:n,zOrder:n.map(e=>e.id)}})(fs(g)),catch:e=>new fy({status:"render_failed",context:{...v,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.id},message:e instanceof Error?e.message:"Unable to render class diagram scene.",hint:"Repair the classes and relationships and retry."})]}})}).pipe(o.fRP("codeMode.buildClassDiagram.render")),x=se(w);if(x.length>0)return yield*new fy({status:"render_failed",context:{...v,issues:f$(x).map(e=>({...e,hint:"Shorten class or member names, or split the model, and retry buildClassDiagram."}))}});let b={...v,partial:ma(w)},k=yield*ml({scene:w,formats:fU(p.options),inlineFormats:fX(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fy({status:e.status,context:{..."export_failed"===e.status?b:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...mt(p.requestId),normalizedSpec:g,quality:m,artifact:k,issues:[]}}),mp=o.fn("codeMode.buildOrgChart.workflow")(function*(e){var t,a;let s,l,r,n,c=i.q$Z(l4,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:aC(e.spec)}:e);if(!um.oJ(c))return yield*new fw({status:"invalid_input",context:{issues:fF(s9(c.failure))}});let d=yield*uQ,p=c.success,h=yield*o.OH5(()=>d.createId("build")),g=(s=s5((t=p.spec).title),l=(e,t)=>t&&s5(t)?{[e]:s5(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.dottedLines.flatMap(e=>fE(e.id)??[])),{id:fE(t.id)??(fI(s)||"sketchi-org-chart"),title:s,people:t.people.map(e=>({id:s5(e.id),name:s5(e.name),...l("title",e.title),...l("department",e.department),...l("manager",e.manager),...r("assistant",e.assistant),...r("avatar",e.avatar)})),dottedLines:t.dottedLines.map((e,t)=>({id:fE(e.id)??(e=>{let t=e+1;for(;n.has(`dotted-line-${t}`);)t+=1;return n.add(`dotted-line-${t}`),`dotted-line-${t}`})(t),report:s5(e.report),manager:s5(e.manager),...l("label",e.label)})),...r("groupByDepartment",t.groupByDepartment),...r("forest",t.forest),style:{...y}}),u={buildId:h,...mt(p.requestId),normalizedSpec:g},f=au(fl(g)).map(e=>fB({code:fo[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new fw({status:"invalid_org_chart",context:{...u,issues:f}});let m={accepted:10>=(a=p.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:g.people.length,edgeCount:g.people.filter(e=>void 0!==e.manager).length+g.dottedLines.length},checks:[]},w={...u,quality:m};if(!m.accepted)return yield*new fw({status:"quality_failed",context:{...w,issues:fO(m)}});let x=yield*o.SvU({try:()=>{let e,t,a,s,i,l,o,r,n,c,d,p,h,u,f,m,y,w,x,b,k,M,C;return t=function(e){let t=new Map;if(!0!==e.groupByDepartment)return t;let a=ag(e),s=new Map(e.people.map(e=>[e.id,e])),i=(e,l)=>{let o=void 0===e.manager?void 0:s.get(e.manager),r=!l&&void 0!==o&&void 0!==e.department&&e.department!==o.department&&(a.get(e.id)?.length??0)>0;for(let s of(r&&t.set(e.id,e.department),a.get(e.id)??[]))i(s,l||r)};for(let t of ah(e))i(t,!1);return t}(e=am(fl(g))),a=function(e,t){let a=ag(e),s=[...new Set(e.people.flatMap(e=>e.department??[]))],i=new Map(e.people.map(e=>[e.id,e])),l=ah(e).flatMap(e=>(a.get(e.id)??[]).filter(e=>!0!==e.assistant)),o=e=>nW[e%nW.length],r=t=>{if(s.length>0)return void 0===t.department?e.style.accentColor:o(s.indexOf(t.department));let a=(t=>{let a=t;for(let t=0;t<=e.people.length;t+=1){let e=void 0===a.manager?void 0:i.get(a.manager);if(!e)break;if(void 0===e.manager)return a;a=e}})(t),r=void 0===a?-1:l.indexOf(a);return r<0?e.style.accentColor:o(r)},n=new Map,c=new Map,d=(e,s,i)=>{let l=t.get(e.id)??i;for(let t of(c.set(e.id,s),void 0!==l&&n.set(e.id,l),a.get(e.id)??[]))d(t,s+1,l)};for(let t of ah(e))d(t,0,void 0);let p=new Map;for(let t of e.people){let e=void 0===t.manager?void 0:i.get(t.manager),a=void 0!==t.department&&e?.department!==t.department&&n.get(t.id)!==t.department?t.department:void 0,s=[t.title,a].filter(e=>void 0!==e).map(e=>gU(e.trim(),208,13));p.set(t.id,{person:t,depth:c.get(t.id)??0,name:gU(t.name.trim(),208,16),details:s.length>0?s.join("\n"):void 0,color:r(t),avatar:!0===t.avatar,width:0,height:0})}let h=new Map;for(let e of p.values()){let t=h.get(e.depth)??[];t.push(e),h.set(e.depth,t)}for(let e of h.values()){let t=Math.ceil(Math.min(232,Math.max(148,Math.max(...e.map(e=>Math.max(aq(e.name,16),e.details?aq(e.details,13):0,44*!!e.avatar)+24)))));for(let a of e)a.width=t}let g=e=>9+49*!!e.avatar+gT(e.name,16)+(e.details?3+gT(e.details,13):0)+5+4*!e.details,u=e=>e.details?Math.ceil(13*gX(e.details)*1.35)+18:Math.ceil(16*gX(e.name)*1.35)+18+49*!!e.avatar,f=new Map;for(let e of p.values()){let t=`${e.person.manager??`top:${e.person.id}`}:${!0===e.person.assistant}`;f.set(t,[...f.get(t)??[],e])}for(let e of f.values()){let t=Math.ceil(Math.max(40,...e.map(e=>Math.max(g(e),u(e)))));for(let a of e)a.height=t}return p}(e,t),l=function(e){let t={stackMin:5,twoColumns:5,outline:new Map,rows:new Map},a=gV(e,t),s=1;if(gq(a)>1){let i={...t,stackMin:2},l=gV(e,i);s+=1,gq(l)<gq(a)-1e-9&&([t,a]=[i,l])}let i=new Map,l=[],o=(e,t)=>{for(let a of(i.set(e.id,t),t>=1&&gz(e)&&l.push(e.id),e.reports))o(a,t+1)};for(let t of e)o(t,0);let r=t=>{let i;for(let{policy:a,preference:l}of t){let t=gV(e,a);s+=1;let o={policy:a,block:t,excess:gq(t),preference:l};(!i||(o.excess<=1&&i.excess<=1?o.preference<i.preference-1e-9:o.excess<i.excess-1e-9))&&(i=o)}return i&&i.excess<gq(a)-1e-6?i:void 0};for(let s=0;s<30&&gq(a)>1;s+=1){let s=a.rows,o=t.twoColumns<=8?r([{policy:{...t,twoColumns:9},preference:0}]):void 0;if(o){[t,a]=[o.policy,o.block];continue}let n=(e,t)=>(s.get(t)?.width??0)-(s.get(e)?.width??0)||e.localeCompare(t),c=r([...l.filter(e=>!t.outline.has(e)&&s.has(e)).toSorted(n).slice(0,3).map(e=>({policy:{...t,outline:new Map(t.outline).set(e,2)},preference:-i.get(e)})),...[...t.outline].filter(([,e])=>2===e).map(([e])=>e).slice(0,3).map(e=>({policy:{...t,outline:new Map(t.outline).set(e,1)},preference:1-i.get(e)}))]);if(c){[t,a]=[c.policy,c.block];continue}let d=([,e])=>e.items>e.rows,p=[...s].filter(e=>d(e)&&e[1].widestItem<.6*e[1].width).toSorted(([e,t],[a,s])=>s.width-s.widestItem-(t.width-t.widestItem)||e.localeCompare(a)).slice(0,3),h=[];for(let t of e){let e=t.id;for(;void 0!==e&&s.has(e);)h.push([e,s.get(e)]),e=s.get(e).widest}let g=[...p,...h.filter(d).filter(([e])=>!p.some(([t])=>t===e)).slice(0,3)],u=e=>r(e.map(([e,a])=>({policy:{...t,rows:new Map(t.rows).set(e,a.rows+1)},preference:a.widestItem}))),f=u(g.filter(([e])=>i.get(e)>=1))??u(g.filter(([e])=>0===i.get(e)));if(!f)break;[t,a]=[f.policy,f.block]}for(let i of[...t.rows.keys()].toReversed())for(let l=t.rows.get(i)-1;l>=1;l-=1){let o={...t,rows:new Map(t.rows).set(i,l)},r=gV(e,o);if(s+=1,gq(r)>Math.max(1,gq(a))+1e-9)break;t=o,a=r}let n=gk(gH(a));return{cards:a.cards,links:a.links,regions:a.regions,width:n.x1-n.x0,height:n.y1-n.y0,attempts:s,stackMin:t.stackMin,wraps:new Map([...t.rows].filter(([,e])=>e>1)),outlines:t.outline}}((s=ag(e),i=e=>{let l=a.get(e.id),o=t.get(e.id),r=s.get(e.id)??[];return{id:e.id,width:l.width,height:l.height,reports:r.filter(e=>!0!==e.assistant).map(i),assistants:r.filter(e=>!0===e.assistant).map(i),...void 0===o?{}:{region:{label:o,nameWidth:sY(o)}}}},ah(e).map(i))),o=e.style.backgroundColor,r=e=>({...e,x:e.x+40,y:e.y+40}),n=new Map([...l.cards].map(([e,t])=>[e,r(t)])),c=l.regions.map(e=>({type:"frame",id:`frame:${e.root}`,name:e.label,...r(e.frame)})),d=new Map(l.regions.flatMap(e=>e.members.map(t=>[t,`frame:${e.root}`]))),p=e.people.map(e=>(function(e,t,a,s){let i,l,o,{person:r}=e,n={groupIds:[`person:${r.id}`],...s?{frameId:s}:{}},c={type:"node",id:`node:${r.id}`,nodeId:r.id,kind:r.assistant?"assistant":"person",shape:"rectangle",...t,label:r.name,strokeColor:e.color,strokeWidth:2,fillColor:gO(e.color,a,.13),fillStyle:"solid",...n},d=[c],p=[],h=t.x+t.width/2,g=t.width-24;if(e.avatar&&d.push({type:"node",id:`node:${r.id}:avatar`,nodeId:`${r.id}:avatar`,kind:"avatar",shape:"ellipse",x:h-22,y:t.y+9,width:44,height:44,label:(l=(i=r.name.trim().split(/\s+/u).filter(e=>/[\p{L}\p{N}]/u.test(e))).length>2&&/^(dr|mr|mrs|ms|mx|prof|sir|dame)\.?$/iu.test(i[0])?i.slice(1):i,o=e=>{let t=[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(e??"")].map(e=>e.segment).find(e=>/[\p{L}\p{N}]/u.test(e));return t?.toLocaleUpperCase()??""},0===l.length?"?":1===l.length?o(l[0])||"?":`${o(l[0])}${o(l.at(-1))}`),strokeColor:e.color,strokeWidth:1,fillColor:gO(e.color,a,.32),fillStyle:"solid",...n}),e.details){let a=gT(e.details,13),s=t.y+t.height-5-a;p.push({type:"text",id:`label:${r.id}`,containerId:c.id,x:h,y:s+a/2,text:e.details,fontSize:13,lineHeight:1.25,maxWidth:g,verticalAlign:"bottom",textColor:"#5f574c",...n});let i=gT(e.name,16);p.push({type:"text",id:`text:${r.id}:name`,x:h,y:s-3-i/2,text:e.name,fontSize:16,lineHeight:1.25,maxWidth:Math.ceil(aq(e.name,16)),textColor:v.ink,...n})}else{let a=gT(e.name,16),s=e.avatar;p.push({type:"text",id:`label:${r.id}`,containerId:c.id,x:h,y:s?t.y+t.height-5-a/2:t.y+t.height/2,text:e.name,fontSize:16,lineHeight:1.25,maxWidth:g,...s?{verticalAlign:"bottom"}:{},textColor:v.ink,...n})}return{nodes:d,texts:p}})(a.get(e.id),n.get(e.id),o,d.get(e.id))),h=l.links.map(e=>{let t=e.points.map(e=>({x:e.x+40,y:e.y+40})),a=void 0!==d.get(e.manager)&&d.get(e.manager)===d.get(e.report)?d.get(e.report):void 0;return{type:"arrow",id:`edge:${e.report}`,edgeId:e.report,sourceNodeId:e.manager,targetNodeId:e.report,points:t,startArrowhead:null,endArrowhead:null,strokeColor:"#857b6f",strokeWidth:2,roughness:0,...a?{frameId:a}:{}}}),f=0===(u=gj(e,n,c,d,h,!0)).straight?u:[gj(e,n,c,d,h,!1)].find(e=>e.straight<u.straight)??u,y=(m=[...c,...h,...f.arrows,...p.flatMap(e=>e.nodes),...p.flatMap(e=>e.texts),...f.labels]).flatMap(e=>{if("arrow"===e.type)return[...e.points];if("text"===e.type){if(e.containerId)return[];let t=(e.maxWidth??0)/2,a=gX(e.text)*e.fontSize*1.25/2;return[{x:e.x-t,y:e.y-a},{x:e.x+t,y:e.y+a}]}return"node"===e.type||"frame"===e.type?[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]:[]}),w=c.map(e=>s$(e).y),x=Math.min(...y.map(e=>e.x)),b=Math.min(...y.map(e=>e.y),...w),k=Math.max(0,Math.ceil(40-x)),M=Math.max(0,Math.ceil(40-b)),C=0===k&&0===M?m:m.map(e=>"arrow"===e.type?{...e,points:e.points.map(e=>({x:e.x+k,y:e.y+M}))}:"line"===e.type?e:{...e,x:e.x+k,y:e.y+M}),{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:Math.ceil(Math.max(...y.map(e=>e.x))+k+40),height:Math.ceil(Math.max(...y.map(e=>e.y))+M+40),accentColor:e.style.accentColor,backgroundColor:o,elements:C,layers:[],layouts:[],zOrder:C.map(e=>e.id)}},catch:e=>new fw({status:"render_failed",context:{...w,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.id},message:e instanceof Error?e.message:"Unable to render org chart scene.",hint:"Repair the people and reporting lines and retry."})]}})}).pipe(o.fRP("codeMode.buildOrgChart.render")),b=se(x);if(b.length>0)return yield*new fw({status:"render_failed",context:{...w,issues:f$(b).map(e=>({...e,hint:"Shorten names or titles, or split the chart by division, and retry buildOrgChart."}))}});let k={...w,partial:ma(x)},M=yield*ml({scene:x,formats:fU(p.options),inlineFormats:fX(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fw({status:e.status,context:{..."export_failed"===e.status?k:w,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...mt(p.requestId),normalizedSpec:g,quality:m,artifact:M,issues:[]}}),mh=o.fn("codeMode.buildTimeline.workflow")(function*(e){var t,a;let s,l,r=i.q$Z(lN,{errors:"all",reportInput:!0})(e);if(!um.oJ(r))return yield*new fx({status:"invalid_input",context:{issues:fF(s9(r.failure))}});let n=yield*uQ,c=r.success,d=yield*o.OH5(()=>n.createId("build")),p=(s=s5((t=c.spec).title),{id:(l={id:fE(t.id)??(fI(s)||"sketchi-timeline"),title:s,type:"timeline",style:{...y},events:t.events.map(e=>({...e}))}).id,title:s,events:ep(l),...t.lanes?{lanes:[...t.lanes]}:{},...t.today?{today:t.today}:{},style:l.style}),h={buildId:d,...mt(c.requestId),normalizedSpec:p},g=er(u2(p)).map(e=>fB({code:e.code,stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(g.length>0)return yield*new fx({status:"invalid_timeline",context:{...h,issues:g}});let u={accepted:10>=(a=c.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:p.events.length,edgeCount:0},checks:[]},f={...h,quality:u};if(!u.accepted)return yield*new fx({status:"quality_failed",context:{...f,issues:fO(u)}});let m=yield*o.SvU({try:()=>(function(e){let t,a,s=ec(e),i=ep(s),l=cO(s),o=eo(s),r=(o.length?o:[""]).map((e,t)=>{let a=de[t%de.length];return{...a,stroke:a.stroke||s.style.accentColor}}),n=i[0]?.date!==void 0,c=[],d=e=>{let t=c.findIndex(t=>t.time===e.time&&t.tie===e.tie);return t>=0?t:(c.push(e),c.length-1)},p=void 0===s.today?void 0:ei(s.today),h=new Map,g=new Map,u=[!1,!0].flatMap(e=>i.flatMap((t,a)=>{let s,i,l=void 0!==t.end;if(l!==e)return[];let o=n?ei(t.date):void 0,r=void 0===t.end?void 0:ei(t.end),c=o?o.start:t.order??a,u=t.lane??"",f=r?(c+r.end)/2:c,m=p&&r&&p.start>c&&p.start<r.end,v=r&&(m||h.has(`${u}\0${f}`))?function(e,t,a){let s=[e,...a.filter(a=>a>e&&a<t),t].toSorted((e,t)=>e-t),i={from:e,to:e};for(let[e,t]of s.slice(1).entries())t-s[e]>i.to-i.from&&(i={from:s[e],to:t});return(i.from+i.to)/2}(c,r.end,[...g.get(u)??[],...m?[p.start]:[]]):f,y=d({time:v,tie:(s=`${u}\0${v}`,i=h.get(s)??0,h.set(s,i+1),g.set(u,[...g.get(u)??[],v]),i)});return[{event:t,index:a,span:l,start:l?d({time:c,tie:0}):y,end:r?d({time:r.end,tie:0}):void 0,stem:y}]})).toSorted((e,t)=>e.index-t.index),f=p?d({time:p.start,tie:0}):void 0,m=c.map((e,t)=>({anchor:e,key:t})).toSorted((e,t)=>e.anchor.time-t.anchor.time||e.anchor.tie-t.anchor.tie),y=new Map(m.map((e,t)=>[e.key,t])),w=m.map(e=>e.anchor),x=u.map(e=>{let t=r[e.event.lane?o.indexOf(e.event.lane):0],a=`event:${e.event.id}`,s=l.events.get(e.event.id),i=[...s?[dt(`date:${a}`,s,14,t.ink)]:[],dt(`label:${a}`,e.event.label,16,v.ink),...e.event.description?[dt(`description:${a}`,e.event.description,13,c8)]:[]];return{event:e.event,index:e.index,lane:e.event.lane?o.indexOf(e.event.lane):0,span:e.span,startKey:y.get(e.start),endKey:y.get(e.end??e.start),stemKey:y.get(e.stem),inset:Math.max(10,(s?i[0].width:0)/2-12),parts:i,width:Math.max(...i.map(e=>e.width)),height:i.reduce((e,t)=>e+t.height,0)+2*(i.length-1)}}),b=void 0===f?void 0:y.get(f),k=Math.min(128,Math.max(72,Math.round((a=Math.floor((t=x.map(e=>e.width).toSorted((e,t)=>e-t)).length/2),((t.length%2?t[a]:(t[a-1]+t[a])/2)+16)/2+8)))),M=1.5*k,C=e=>x.some(t=>t.span&&t.startKey<=e&&t.endKey>e),z=w.slice(1).map((e,t)=>e.time-w[t].time),_=new Map,L=e=>{let t=_.get(e);if(!t){var a;let s,i,l,o=(a=z[e],s=(e,t)=>`${e} ${t}${1===e?"":"s"}`,i=e=>s(Math.max(1,Math.round(a/cU[e])),e),l=e=>{let t=a/cU[e];return s(t<10?Math.round(10*t)/10:Math.round(t),e)},a<1e3?i("millisecond"):a<12e4?l("second"):a<72e5?i("minute"):a<1728e5?i("hour"):a<5184e6?i("day"):a<63113904e3?i("month"):l("year"));t={text:o,half:aF(o,13,200)/2+6},_.set(e,t)}return t},B=[...new Set(x.flatMap(e=>[e.startKey,e.endKey]).map(e=>w.findIndex(t=>t.time===w[e].time)))].toSorted((e,t)=>e-t),S=e=>{let t=new Set(e);if(!n)return{x:w.map((e,t)=>t*k),breaks:t};if(w.length<2)return{x:w.map(()=>0),breaks:t};let a=z.reduce((e,t)=>e+t,0),s=x.length*k,i=10*k,l=a>0?s/a:0,o=[...r.flatMap((e,t)=>x.filter(e=>e.lane===t).toSorted((e,t)=>e.stemKey-t.stemKey).flatMap((e,t,a)=>{let s=a[t-1];return s&&s.stemKey!==e.stemKey?[{from:s.stemKey,to:e.stemKey,min:Math.max(28,e.inset+c7+1)}]:[]})),...x.filter(e=>e.span).map(e=>({from:e.startKey,to:e.endKey,min:12}))].filter(e=>e.to>e.from),c=Math.max(28,...o.map(e=>e.min)),d=(e,a)=>{let s=[0],i=0,l=0;return z.forEach((o,r)=>{let n=w[r+1];n.tie>0?s.push(i+n.tie*c):(i=t.has(r)?a?Math.max(i+a.get(r),l+Math.max(M,2*(L(r).half+3+16))):l+M:i+o*e,s.push(i)),l=Math.max(l,s[r+1])}),s},p=()=>{let[e,t]=[d(0),d(1)];return o.map(({from:a,to:s,min:i})=>{let l=e[s]-e[a];return{from:a,to:s,min:i,fixed:l,perScale:t[s]-e[s]-(t[a]-e[a])}})},h=Math.max(0,...x.filter(e=>e.span).map(e=>w[e.endKey].time-w[e.startKey].time)),g=h>0?Math.max(l,2*i/h):1/0,u=l;for(;;){let e=z.reduce((e,a,s)=>e+(t.has(s)?0:a),0),a=t.size&&e>0?Math.min(2*l,Math.max(l,(s-t.size*M)/e)):l,o=p();u=Math.min(Math.max(a,...o.map(({min:e,fixed:t,perScale:a})=>a>0&&t<e?(e-t)/a:0)),g);let r=t.size?2*M:i,n=z.flatMap((e,a)=>t.has(a)||!(e*u>r)||C(a)?[]:[a]);for(let{from:e,to:a,min:s,fixed:i,perScale:l}of o)if(i+l*u<s-1e-6){let s=z.map((e,t)=>({gap:e,key:t})).slice(e,a).filter(({gap:e,key:a})=>e>0&&!t.has(a)).toSorted((e,t)=>t.gap-e.gap||e.key-t.key)[0];s&&n.push(s.key)}if(!n.length)break;for(let e of n)t.add(e)}if(!t.size)return{x:d(u),breaks:t};let f=Math.max(M,...z.map((e,a)=>t.has(a)||C(a)?0:e*u)),m=[...t].filter(e=>z[e]*u>=M),v=Math.min(...m.map(e=>z[e])),y=Math.log2(Math.max(...m.map(e=>z[e]))/v),b=Math.min(.5,y>0?1/y:1/0),_=new Map([...t].map(e=>[e,f*(1+b*Math.log2(Math.max(1,z[e]/v)))])),S=d(u,_),A=new Set(m),P=B.slice(1).flatMap((e,a)=>{let s=B[a],i=z.slice(s,e).map((e,t)=>s+t),l=i.filter(e=>A.has(e)).at(-1);return void 0===l&&i.some(e=>t.has(e))?[]:[{from:s,to:e,elapsed:w[e].time-w[s].time,broken:l}]}),V=e=>S[e.to]-S[e.from];for(let e of P.toSorted((e,t)=>e.elapsed-t.elapsed)){if(void 0===e.broken)continue;let{elapsed:t}=e,a=Math.max(...P.map(e=>1.5*e.elapsed<=t?V(e)+12:e.elapsed<t?V(e):0)),s=Math.min(...P.map(e=>void 0!==e.broken?1/0:e.elapsed>=1.5*t?V(e)-12:e.elapsed>t?V(e):1/0)),i=Math.min(Math.max(V(e),a),s);if(1e-9>Math.abs(i-V(e)))continue;let l=e.broken,o=w.findIndex(e=>e.time===w[l].time);_.set(l,S[l+1]-S[o]+i-V(e)),S=d(u,_)}return{x:S,breaks:t}},A=({x:e,breaks:t})=>{let a=e.map((t,a)=>Math.max(...e.slice(0,a+1))),s=e.map((t,a)=>Math.min(...e.slice(a))),i=t=>(a[t]+e[t+1])/2,l=w.slice(0,-1).flatMap((e,l)=>{if(C(l))return[];let o=s[l+1]-14;if(t.has(l)){let e=i(l)+L(l).half+3+7;return[{key:l,low:e,high:Math.max(e,o),broken:!0}]}let r=a[l]+14;return r<=o?[{key:l,low:r,high:o,broken:!1}]:[]}),r=new Set(x.flatMap(t=>{if(!t.span)return[];let a=e[t.startKey]+Math.max(12,e[t.endKey]-e[t.startKey]);return x.some(s=>!s.span&&s.lane===t.lane&&(s.startKey<t.startKey||s.startKey>=t.endKey)&&e[s.startKey]+ds(s)>e[t.startKey]&&e[s.startKey]-ds(s)<a)?[t.lane]:[]}));return{x:e,breaks:t,reachBefore:a,rowsFor:t=>{let a=e[e.length-1],s=[],i=0,o=-24;for(let e=1;e<t;e+=1){let r=a*e/t,n=l.filter(e=>e.key>=i).map(e=>{let t=Math.min(e.high,Math.max(e.low,r));return{cut:e,at:t,cost:Math.abs(t-r)-(e.broken?k:0)-Math.min(e.high-e.low,2*k)/4}}).toSorted((e,t)=>e.cost-t.cost||e.cut.key-t.cut.key)[0];if(!n)break;s.push({first:i,last:n.cut.key,start:o,end:n.at}),i=n.cut.key+1,o=n.at}return s.push({first:i,last:w.length-1,start:o,end:Math.max(...e)+24}),s},layout:t=>{let a=Math.max(1,o.length);return t.map((t,s)=>{let l=t.start-32*(s>0),o=t=>e[t]-l,n=void 0!==b&&b>=t.first&&b<=t.last?o(b):void 0,c=Array.from({length:a},(e,a)=>(function(e,t,a,s){let i;for(let l of da){let o=function(e,t,a,s,i){let l=[],o=new Map;for(let t of e.filter(e=>e.span).toSorted((e,t)=>e.startKey-t.startKey)){let e=l.findIndex((e,a)=>a>=s&&e<=t.startKey);for(e<0&&(e=Math.max(s,l.length));l.length<e;)l.push(-1/0);l[e]=t.endKey,o.set(t,e)}let r=l.length,n=22+16*Math.max(0,r-1),c=e=>t(e.stemKey),d=e.toSorted((e,t)=>c(t)-c(e)||t.index-e.index),p={"-1":[],1:[]},h={"-1":[],1:[]},g=[],u=(e,t,a=c7)=>t>e.left-a&&t<e.right+a,f=-1;d.forEach((e,t)=>{let s=c(e),l=d.slice(t+1).map(c),r=i.lookahead?d[t+2]:void 0,m=(e,t,a)=>{if(!r||t>a)return 0;let s=c(r);return s+10+16>e?1e3:Math.max(0,s+r.width/2+16-e)/2},v=s-e.width+e.inset,y=s-e.inset,w=(o.get(e)??0)>0,x=w?1:f,b=e=>e.option.near-(e.side===x?w?120:1:0),k=t=>[x,-x].flatMap(o=>{let d=((t,o)=>{let d=t<0?22:n,g=p[t],f=p[-t],w=[...h[t],...o&&void 0!==a&&Math.abs(a-s)>=14?[{x:a,reach:1/0}]:[]],x=[d,...g.map(e=>e.far+10)].filter(e=>e>=d).toSorted((e,t)=>e-t),b=s-e.width/2,k=[b,v,y,...g.flatMap(t=>[t.right+16,t.left-16-e.width]),...[...w,...l.map(e=>({x:e,reach:0}))].flatMap(t=>{let a=1/0===t.reach?3*c7:c7;return[t.x+a,t.x-a-e.width]}),...r?[c(r)+10+16,c(r)+r.width/2+16]:[]].map(e=>Math.min(y,Math.max(v,e)));for(let t of x){let a=t+e.height,o=a=>Math.abs(a-b)+m(a,t,d)+i.coverPenalty*l.slice(1).filter(t=>u({left:a,right:a+e.width},t)).length;for(let i of k.toSorted((e,t)=>o(e)-o(t)||e-t)){let o=i+e.width,r={left:i,right:o};if(g.every(e=>i>=e.right+16||e.left>=o+16||t>=e.far+10||e.near>=a+10)&&g.every(e=>!u(e,s)||e.near>t)&&w.every(e=>!u(r,e.x,1/0===e.reach?3*c7:c7)||e.reach<=t)&&l.every(e=>!u(r,e)||f.every(t=>!u(t,e))))return{near:t,left:i}}}})(o,t);return d?[{side:o,option:d}]:[]}).toSorted((e,t)=>b(e)-b(t))[0],M=k(!0)??k(!1);if(!M)throw Error(`Timeline label for "${e.event.id}" has no clear placement.`);let{side:C,option:z}=M,{near:_,left:L}=z;p[C].push({left:L,right:L+e.width,near:_,far:_+e.height}),h[C].push({x:s,reach:_});let B=o.get(e)??0,S=16*B;g.push({item:e,stemX:s,side:C,near:_,left:L,stemStart:C>0?S+ds(e):ds(e)-S,track:B}),f=-C});let m=(e,t)=>Math.max(t,...p[e].map(e=>e.far));return{placements:g,above:m(-1,15),below:m(1,Math.max(9,n-22+6)+6),tracks:r}}(e,t,a,s,l);(!i||o.above+o.below<i.above+i.below)&&(i=o)}return i})(x.filter(e=>e.lane===a&&e.startKey>=t.first&&e.startKey<=t.last),o,n,+!!r.has(a)));return{row:t,localX:o,breakX:e=>i(e)-l,todayX:n,lanes:c,axisStart:t.start-l,axisEnd:t.end-l}})}}},P=o.length?Math.max(...o.map(e=>aF(e,15,160)))+20:0,V=l.header,H=l.today,q=(e,t)=>{var a,s;let i,l,n,c,d,p,h,g,u,f,m=e.rowsFor(t);if(m.length<t)return;let v=(a=e.breaks,s=e.layout(m),i=[],l=[],n=[],c=[],d=(e,t)=>{i.push(e),t.push(e.id)},p=(e,t,a={})=>({type:"line",id:e,points:t,...a}),h=(e,t,a,s,i,l,o={})=>({type:"text",id:e,x:a,y:s,text:t,fontSize:i,maxWidth:200,textColor:l,...o}),g=V?Math.ceil(14*1.35):0,u=18*!!H,f=V?g+18:0,s.forEach((e,t)=>{let i=f,g=void 0!==e.todayX;g&&(f+=u+6);let m=t<s.length-1,v=t>0;if(e.lanes.forEach((s,i)=>{let g=r[i],u=f+s.above,y=`${i}:${t}`,w={strokeColor:g.stroke,strokeWidth:2,roughness:0},x=[...a].toSorted((e,t)=>e-t).filter(t=>t>=e.row.first&&t<=e.row.last).map(t=>({x:P+e.breakX(t),...L(t)})),b=[P+e.axisStart,...x.flatMap(e=>[e.x-e.half,e.x+e.half]),P+e.axisEnd];for(let e=0;e<b.length;e+=2)b[e+1]>b[e]&&d(p(`axis:${y}${e?`:${e/2}`:""}`,[{x:b[e],y:u},{x:b[e+1],y:u}],w),l);for(let t of(x.forEach((e,t)=>{for(let a of[-1,1])d(p(`break:${y}:${t}:${a<0?"a":"b"}`,[{x:e.x+a*e.half-3,y:u+7},{x:e.x+a*e.half+3,y:u-7}],w),c);d(h(`break-label:${y}:${t}`,e.text,e.x,u,13,g.ink),c)}),v&&d(p(`continue-in:${y}`,[{x:P,y:u},{x:P+32,y:u}],{...w,strokeStyle:"dashed"}),l),m&&d(p(`continue-out:${y}`,[{x:P+e.axisEnd,y:u},{x:P+e.axisEnd+32,y:u}],{...w,strokeStyle:"dashed",endArrowhead:"arrow"}),l),o.length&&d(h(`lane:${y}`,o[i],P-16-aF(o[i],15,160)/2,u,15,g.ink,{maxWidth:160,textAlign:"right"}),c),s.placements)){let{item:a}=t,s=`event:${a.event.id}`,i={groupIds:[s]},o=u+16*t.track,r=P+t.stemX;if(a.span){let t=P+e.localX(a.startKey);d({type:"node",id:`node:${s}`,nodeId:s,rendererRole:c6,shape:"rectangle",x:t,y:o-6,width:Math.max(12,P+e.localX(a.endKey)-t),height:12,label:a.event.label,fillColor:g.wash,strokeColor:g.stroke,...i},n)}else{let e="milestone"===a.event.kind,t=e?18:12;d({type:"node",id:`node:${s}`,nodeId:s,rendererRole:c6,shape:e?"diamond":"ellipse",x:r-t/2,y:u-t/2,width:t,height:t,label:a.event.label,fillColor:g.stroke,strokeColor:g.stroke,...i},c)}let f=u+t.side*t.near;d(p(`stem:${s}`,[{x:r,y:u+t.side*t.stemStart},{x:r,y:f}],{strokeColor:"#b9ad95",strokeWidth:1,roughness:0,...i}),l);let m=P+t.left,v=t.side<0?f-a.height:f;for(let e of a.parts){let t=aF(e.text,e.fontSize,200),s=Math.min(Math.max(r,m+t/2),m+a.width-t/2),l=s===r?"center":s<r?"right":"left";d(h(e.id,e.text,s,v+e.height/2,e.fontSize,e.color,{textAlign:l,...i}),c),v+=e.height+2}}f=u+s.below+28*(i<e.lanes.length-1)}),g){let a=P+e.todayX;d(p(`today:${t}`,[{x:a,y:i+u+3},{x:a,y:f}],{strokeColor:c9,strokeWidth:1,strokeStyle:"dashed",roughness:0}),l),d(h(`today-label:${t}`,H,a,i+u/2,13,c9),c)}f+=48}),f-=48,V&&d(h("header",V,aF(V,14,400)/2,g/2,14,c8,{maxWidth:400,textAlign:"left"}),c),{elements:i,zOrder:[...l,...n,...c],height:f}),y=(e=>{let t=1/0,a=-1/0,s=1/0,i=-1/0,l=(e,l,o,r)=>{t=Math.min(t,e),a=Math.max(a,o),s=Math.min(s,l),i=Math.max(i,r)};for(let t of e)if("line"===t.type||"arrow"===t.type)for(let e of t.points)l(e.x,e.y,e.x,e.y);else if("text"===t.type){let e=aF(t.text,t.fontSize,t.maxWidth??200),a=t.text.split("\n").length*t.fontSize*1.35;l(t.x-e/2,t.y-a/2,t.x+e/2,t.y+a/2)}else("node"===t.type||"frame"===t.type)&&l(t.x,t.y,t.x+t.width,t.y+t.height);return{minX:t,maxX:a,minY:s,maxY:i}})(v.elements),w=Math.abs(Math.log((y.maxX-y.minX+80)/(y.maxY-y.minY+80)/2))+.3*(t-1);return{count:t,composed:v,box:y,score:w}},F=e=>e.reduce((e,t)=>!e||t.score<e.score-1e-9?t:e,void 0),I=({box:e})=>(e.maxX-e.minX+40)/(e.maxY-e.minY+40),E=({x:e,breaks:t,reachBefore:a})=>z.map((t,s)=>({gap:t,key:s,free:e[s+1]-a[s]})).filter(({gap:e,key:a,free:s})=>e>0&&!t.has(a)&&!C(a)&&s>=2*M).toSorted((e,t)=>t.free-e.free||e.key-t.key)[0],O=Math.max(1,Math.min(12,Math.ceil(x.length/2))),U=A(S(new Set)),X=[];for(let e=1;e<=O;e+=1){let t=q(U,e);if(!t)break;X.push(t)}let T=F(X);if(n&&1===T.count&&I(T)>3.5){let e=new Set,t=U,a=T;for(let s=E(t);s&&I(a)>3.5;s=E(t))e.add(s.key),a=q(t=A(S(e)),1);T=3.5>=I(a)?a:F(X.slice(1))??a}let{composed:Y,box:$}=T,G=40-$.minX,D=40-$.minY,R=Y.elements.map(e=>{if("line"===e.type||"arrow"===e.type){let[t,...a]=e.points.map(e=>({x:e.x+G,y:e.y+D}));return"line"===e.type?{...e,points:[t,a[0],...a.slice(1)]}:{...e,points:[t,...a]}}return{...e,x:e.x+G,y:e.y+D}});return{kind:"canvas",version:1,diagramId:s.id,title:s.title,width:Math.ceil($.maxX-$.minX+80),height:Math.ceil($.maxY-$.minY+80),accentColor:s.style.accentColor,backgroundColor:s.style.backgroundColor,elements:R,layers:[],layouts:[],zOrder:Y.zOrder}})(u2(p)),catch:e=>new fx({status:"render_failed",context:{...f,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render timeline scene.",hint:"Repair the event dates and ordering and retry."})]}})}).pipe(o.fRP("codeMode.buildTimeline.render")),w=se(m);if(w.length>0)return yield*new fx({status:"render_failed",context:{...f,issues:f$(w).map(e=>({...e,hint:"Split the chronology into smaller timelines and retry buildTimeline."}))}});let x={...f,partial:ma(m)},b=yield*ml({scene:m,formats:fU(c.options),inlineFormats:fX(c.options),...c.requestId?{requestId:c.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fx({status:e.status,context:{..."export_failed"===e.status?x:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:d,...mt(c.requestId),normalizedSpec:p,quality:u,artifact:b,issues:[]}}),mg=o.fn("codeMode.buildChart.workflow")(function*(e){var t,a;let s,l,r,n,c,d=i.q$Z(lW,{errors:"all",reportInput:!0})(e);if(!um.oJ(d))return yield*new fb({status:"invalid_input",context:{issues:fF(s9(d.failure))}});let p=yield*uQ,h=d.success,g=yield*o.OH5(()=>p.createId("build")),u=(s=s5((t=h.spec).title),r=(l=e=>{let t=fE(e);return void 0===t?void 0:t})(t.unit),n=l(t.categoryAxisTitle),c=l(t.valueAxisTitle),{id:fE(t.id)??(fI(s)||"sketchi-chart"),title:s,kind:t.kind,categories:t.categories.map(s5),series:t.series.map(e=>{let t=l(e.name);return{...t?{name:t}:{},values:[...e.values]}}),...r?{unit:r}:{},...n?{categoryAxisTitle:n}:{},...c?{valueAxisTitle:c}:{},...void 0!==t.stacked?{stacked:t.stacked}:{},...void 0!==t.donut?{donut:t.donut}:{},...t.orientation?{orientation:t.orientation}:{},style:{...y}}),f={buildId:g,...mt(h.requestId),normalizedSpec:u},m=j(u3(u)).map(e=>fB({code:e.code,stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(m.length>0)return yield*new fb({status:"invalid_chart",context:{...f,issues:m}});let v={accepted:10>=(a=h.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:u.categories.length*u.series.length,edgeCount:0},checks:[]},w={...f,quality:v};if(!v.accepted)return yield*new fb({status:"quality_failed",context:{...w,issues:fO(v)}});let x=yield*o.SvU({try:()=>(function(e){let t=W(e),a=new ca(t.style.backgroundColor);if("pie"===t.kind)!function(e,t){let a=t.series[0].values,s=nU(t.unit),i=ct(a.length,!0),{labels:l,shares:o}=function(e){let t=e.reduce((e,t)=>e+t,0),a=e.map(e=>t>0?e/t*100:0),s=e=>a.map(t=>Math.round(t*10**e)/10**e),i=t=>e.some((a,s)=>a>0&&0===t[s]||e.some((e,i)=>i>s&&e!==a&&t[i]===t[s])),l=+!!a.some(e=>e>0&&e<10);for(;l<2&&i(s(l));)l+=1;let o=s(l);return{shares:a,decimals:l,labels:o.map((t,a)=>0===t&&e[a]>0?`<${(10**-l).toFixed(l)}%`:`${Number(t.toFixed(l))}%`)}}(a),r=t.unit?.trim()==="%",n=87*!!t.donut,c=-Math.PI/2,d=a.map((e,t)=>{let a=o[t]/100*2*Math.PI,s={index:t,start:c,end:c+a,mid:c+a/2};return c+=a,s}),p=[];for(let o of d){let c=i[o.index],d=t.categories[o.index],h=nR(a[o.index],s),g=l[o.index],u={groupIds:[`chart:slice:${o.index}`]},f=o.end-o.start;if(f>.0035){let t=f>=2*Math.PI-1e-9,a=cp(150,o.start,t?o.end-1e-4:o.end),s=n>0?[...a,...cp(n,t?o.end-1e-4:o.end,o.start)]:t?a:[{x:0,y:0},...a];e.polygon(`chart:slice:${o.index}`,s,`${d}: ${g} (${h})`,{fillColor:c,strokeColor:e.surface,strokeWidth:2,...u})}let m=r&&g===h?g:`${g} \xb7 ${h}`,v=n3(`${aO(d,110,14)}
|
|
250
250
|
${m}`,14),y=n>0?(n+150)/2:90,w=y*Math.cos(o.mid),x=y*Math.sin(o.mid),b={left:w-v.width/2,top:x-v.height/2,right:w+v.width/2,bottom:x+v.height/2};if(f>.0035&&function(e,t,a){let s=t.end-t.start;return[{x:e.left,y:e.top},{x:e.right,y:e.top},{x:e.right,y:e.bottom},{x:e.left,y:e.bottom}].every(e=>{let i=Math.hypot(e.x,e.y);if(i>144||i<a+6)return!1;if(s>=2*Math.PI-1e-9)return!0;let l=Math.atan2(e.y,e.x)-t.start;return(l=(l%(2*Math.PI)+2*Math.PI)%(2*Math.PI))<=s&&ch(e,t.start,150)>=6&&ch(e,t.end,150)>=6})}(b,o,n)){e.text(`chart:slice-label:${o.index}`,v,b.left,b.top,14,ce(c),"center",u);continue}let k=n3(`${aO(d,160,14)}
|
|
251
|
-
${m}`,14),M=Math.cos(o.mid)>=-1e-9?1:-1;p.push({slice:o,text:k,side:M,preferred:166*Math.sin(o.mid)})}let h=e=>p.filter(t=>t.side===e).length,g=e=>Math.abs(Math.cos(e.slice.mid));for(let e of p.filter(e=>g(e)<Math.sin(n2)).toSorted((e,t)=>g(e)-g(t)))h(e.side)-1>h(1===e.side?-1:1)&&(e.side=1===e.side?-1:1);let u=e=>Math.atan2(Math.abs(Math.sin(e.slice.mid)),e.side*Math.cos(e.slice.mid));for(let t of[1,-1]){let a=p.filter(e=>e.side===t),s=a.filter(e=>e.preferred<0).toSorted((e,t)=>u(e)-u(t)),i=a.filter(e=>e.preferred>=0).toSorted((e,t)=>u(e)-u(t)),l=new Map,o=1/0;for(let e of s){let t=Math.min(e.preferred-e.text.height/2,o-6-e.text.height);l.set(e,t),o=t}let r=s.length?Math.max(...s.map(e=>l.get(e)+e.text.height))+6:-1/0;for(let e of i){let t=Math.max(e.preferred-e.text.height/2,r);l.set(e,t),r=t+e.text.height+6}[...s,...i].forEach(a=>{let s=l.get(a),i=s+a.text.height/2,o=180*t,r=t>0?o:o-a.text.width,n={groupIds:[`chart:slice:${a.slice.index}`]},c={x:152*Math.cos(a.slice.mid),y:152*Math.sin(a.slice.mid)},d={x:164*Math.cos(a.slice.mid),y:164*Math.sin(a.slice.mid)};e.line(`chart:leader:${a.slice.index}:a`,c,d,{strokeColor:nK,...n},"middle"),e.line(`chart:leader:${a.slice.index}:b`,d,{x:o-4*t,y:i},{strokeColor:nK,...n},"middle"),e.text(`chart:slice-label:${a.slice.index}`,a.text,r,s,14,nJ,t>0?"left":"right",n)})}}(a,t),cs(a,t,{colors:[]});else if("line"===t.kind)!function(e,t){let a,s=t.categories.length,i=nU(t.unit),l=ct(t.series.length,!1),o=cn(t.categories,Math.max(Math.min(720/s,120),36,320/s),2,400),r=t.series.flatMap(e=>e.values),n=1===t.series.length&&s<=16?t.series[0].values.map(e=>n3(nR(e,i),12)):void 0,c=(e,a,i)=>{if(!n)return;let l=t.series[0].values,r=l.map((t,a)=>({x:o*(a+.5),y:e(t)})),c=t.series.flatMap(t=>t.values.slice(1).map((a,s)=>({from:{x:o*(s+.5),y:e(t.values[s])},to:{x:o*(s+1+.5),y:e(a)}})));p.min<0&&p.max>0&&c.push({from:{x:0,y:e(0)},to:{x:o*s,y:e(0)}});let d=r.map(e=>({left:e.x-7,top:e.y-7,right:e.x+7,bottom:e.y+7})),h=[];for(let[e,t]of r.entries()){let r=n[e],p=l[e-1],g=l[e+1],u=l[e],f=(void 0===p||p<=u)&&(void 0===g||g>=u),m=(void 0===p||p>=u)&&(void 0===g||g<=u),v=(void 0===p||p<=u)&&(void 0===g||g<=u),y=r.width,w=r.height,x=(e,a)=>({left:t.x+e-y/2,top:t.y+a-w/2,right:t.x+e+y/2,bottom:t.y+a+w/2}),b=x(0,-(10+w/2)),k=x(0,10+w/2),M=x(0,-(22+w/2)),C=x(0,22+w/2),z=x(-(y/2+10),-(4+w/2)),_=x(y/2+10,-(4+w/2)),L=x(-(y/2+10),4+w/2),B=x(y/2+10,4+w/2),S=(v?[b,z,_,M,k,C]:f&&!m?[z,B,b,k,M,C]:m&&!f?[_,L,b,k,M,C]:[k,L,B,C,b,M]).find(e=>e.top>=a&&e.bottom<=i&&e.left>=0&&e.right<=o*s&&!c.some(t=>(function(e,t){let{from:a,to:s}=e,i=e=>e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom;if(i(a)||i(s))return!0;let l=[{x:t.left,y:t.top},{x:t.right,y:t.top},{x:t.right,y:t.bottom},{x:t.left,y:t.bottom}];return l.some((e,t)=>{var i;let o,r,n,c,d;return i=l[(t+1)%4],r=(o=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x))(a,s,e),n=o(a,s,i),c=o(e,i,a),d=o(e,i,s),r*n<0&&c*d<0})})(t,{left:e.left-2,top:e.top-2,right:e.right+2,bottom:e.bottom+2}))&&!d.some(t=>n6(t,e,2))&&!h.some(t=>n6(t,e,3)));if(!S)return;h.push(S)}return h},d=nI(r,!1),p=nq(d.low,d.high);for(let e=0;e<3&&n;e+=1){let t=280/(p.max-p.min),s=e=>(p.max-e)*t,i=c(s,-1/0,1/0);if(!i)break;let l=i.some(e=>e.top<0),o=i.some(e=>e.bottom>280);if(!l&&!o){a=i;break}2===e?a=c(s,0,280):p=nF(p,o,l)}let h=a?void 0:t.series.map(e=>e.values.map(e=>n3(nR(e,i),12)));h&&(o=Math.max(o,...h.flat().map(e=>e.width+8)));let g=280/(p.max-p.min),u=e=>(p.max-e)*g,f=co(p,i),m=Math.max(...f.labels.map(e=>e.width)),v=o*s;p.ticks.forEach((t,a)=>{let s=u(t),i=f.labels[a];e.line(`chart:grid:${a}`,{x:0,y:s},{x:v,y:s},{strokeColor:nQ}),e.text(`chart:tick:${a}`,i,-8-i.width,s-i.height/2,13,nK,"right")}),p.min<0&&p.max>0&&e.line("chart:baseline",{x:0,y:u(0)},{x:v,y:u(0)},{strokeColor:n1,strokeWidth:2},"middle"),e.line("chart:axis",{x:0,y:280},{x:v,y:280},{strokeColor:n1},"middle");let y=280;if(t.categories.forEach((t,a)=>{let s=o*(a+.5);e.line(`chart:category-tick:${a}`,{x:s,y:280},{x:s,y:285},{strokeColor:n1},"middle");let i=n5(t,o-10,14),l=e.text(`chart:category:${a}`,i,s-i.width/2,289,14,nJ);y=Math.max(y,l.bottom)}),t.series.forEach((a,s)=>{let r=l[s],n={groupIds:[`chart:series:${s}`]};a.values.slice(1).forEach((t,i)=>e.line(`chart:line:${s}:${i+1}`,{x:o*(i+.5),y:u(a.values[i])},{x:o*(i+1+.5),y:u(t)},{strokeColor:r,strokeWidth:2,...n},"middle")),a.values.forEach((a,l)=>{let c=nR(a,i);ci(e,`chart:point:${l}:${s}`,s,o*(l+.5),u(a),r,`${t.categories[l]} \xb7 ${cl(t,s)}: ${c}`,n)})}),h){let a=y+12,s=t.series.map(e=>e.name?n5(e.name,200,12):void 0),i=-10-Math.max(0,...s.map(e=>e?e.width+6:0));h.forEach((r,n)=>{let c=t.series[n],d=l[n],p={groupIds:[`chart:table:${n}`]},h=s[n],g=Math.max(r[0].height,h?.height??0),u=a+g/2;e.line(`chart:table-key:${n}:line`,{x:i-22,y:u},{x:i,y:u},{strokeColor:d,strokeWidth:2,...p},"middle"),ci(e,`chart:table-key:${n}`,n,i-11,u,d,c.name??t.title,p),h&&e.text(`chart:table-name:${n}`,h,i+6,a+(g-h.height)/2,12,nJ,"left",p),r.forEach((t,s)=>e.text(`chart:table:${s}:${n}`,t,o*(s+.5)-t.width/2,a+(g-t.height)/2,12,nK,"center",p)),a+=g+4}),y=a-4}if(a?.forEach((t,a)=>e.text(`chart:value:${a}:0`,n[a],t.left,t.top,12,nK,"center",{groupIds:["chart:series:0"]})),t.valueAxisTitle){let a=n5(t.valueAxisTitle,Math.max(v+m,200),14),s=f.labels[f.labels.length-1];e.text("chart:value-axis-title",a,-8-m,-s.height/2-8-a.height,14,nK,"left")}if(t.categoryAxisTitle){let a=n5(t.categoryAxisTitle,Math.max(v,200),14);e.text("chart:category-axis-title",a,(v-a.width)/2,y+12,14,nK)}}(a,t),cs(a,t,{legend:"line",colors:ct(t.series.length,!1)});else{let e=cr(t);"horizontal"===function(e){if(e.orientation)return e.orientation;let t=cc(cr(e)),a=cn(e.categories,t.band,2,161);return a>160||a*e.categories.length>960?"horizontal":"vertical"}(t)?function(e,t){let{diagram:a,stacked:s,colors:i}=t,l=s?1:a.series.length,o=n3("0",12).height,r=1===l?24:Math.max(o-2,Math.round(44/l)),n=l*r+(l-1)*2,c=Math.min(220,Math.max(...a.categories.map(e=>n3(e,14).width))),d=a.categories.map(e=>n5(e,c,14)),p=s?t.totals.flatMap(e=>[e.up,e.down].filter(e=>void 0!==e)):t.labels.flat(),h=e=>(t,a)=>p.some(s=>"up"===e==s.value>=0&&("up"===e?(t.max-s.value)*a:(s.value-t.min)*a)<s.text.width+4+4),g=cd(t.domain,480,h("up"),h("down"));for(let e=4;e>=2;e-=1){let a=co(g,t.parts);if(480/(g.max-g.min)*g.step>=Math.max(...a.labels.map(e=>e.width))+12)break;g=cd(t.domain,480,h("up"),h("down"),e)}let u=e=>{let s=480/(e.max-e.min),i=t=>(t-e.min)*s;return a.categories.map((e,s)=>{let l=0,o=0;return a.series.map((e,a)=>{let{value:n,text:c}=t.labels[s][a],d=n>=0?l:o,p=d+n;n>=0?l=p:o=p;let h=i(Math.min(d,p)),g=i(Math.max(d,p));g-h<.5&&(n>=0?g=h+.5:h=g-.5);let u=g-h>=c.width+6&&r>=c.height+1;return{s:a,value:n,text:c,left:h,right:g,inside:u}})})};for(let e=0;s&&e<6;e+=1){let e=-g.min/(g.max-g.min)*480,t=Math.max(0,...u(g).map(e=>e.filter(e=>!e.inside&&e.value<0).reduce((e,t)=>e+t.text.width+6,0)));if(0===t||t<=e-2)break;g=nF(g,!0,!1)}let f=480/(g.max-g.min),m=e=>(e-g.min)*f,v=u(g),y=s&&v.flat().some(e=>!e.inside)?o+10:0,w=Math.max(n+14,...d.map(e=>e.height+8))+y,x=co(g,t.parts),b=w*a.categories.length;g.ticks.forEach((t,a)=>{let s=m(t),i=x.labels[a];e.line(`chart:grid:${a}`,{x:s,y:0},{x:s,y:b},{strokeColor:nQ}),e.text(`chart:tick:${a}`,i,s-i.width/2,b+6,13,nK)});let k=m(0);e.line("chart:baseline",{x:k,y:0},{x:k,y:b},{strokeColor:n1,strokeWidth:2},"middle"),a.categories.forEach((l,o)=>{let c=w*o+(w-y)/2,p=d[o];e.text(`chart:category:${o}`,p,-10-p.width,c-p.height/2,14,nJ,"right");let h=c-n/2;if(a.series.forEach((n,c)=>{let d,p,{value:g,text:u}=t.labels[o][c],f=i[c],y=`chart:bar:${o}:${c}`,w={groupIds:[s?`chart:stack:${o}`:y]},x=s?h:h+c*(r+2);s?{left:d,right:p}=v[o][c]:(d=m(Math.min(0,g)),(p=m(Math.max(0,g)))-d<.5&&(g>=0?p=d+.5:d=p-.5));let b=`${l} \xb7 ${cl(a,c)}: ${u.text}`;if(0!==g&&e.mark(y,"rectangle",{x:d,y:x,width:p-d,height:r},b,s?{fillColor:f,strokeColor:e.surface,strokeWidth:2,...w}:{fillColor:f,strokeColor:f,...w}),s){v[o][c].inside&&e.text(`chart:value:${o}:${c}`,u,(d+p-u.width)/2,x+(r-u.height)/2,12,ce(f),"center",w);return}let k=g>=0?p+4:d-4-u.width;e.text(`chart:value:${o}:${c}`,u,k,x+(r-u.height)/2,12,nK,g>=0?"left":"right",w)}),s){let a=t.totals[o],s={groupIds:[`chart:stack:${o}`]};a.up&&e.text(`chart:total:${o}`,a.up.text,m(a.up.value)+4,c-a.up.text.height/2,12,nJ,"left",s),a.down&&e.text(`chart:total-negative:${o}`,a.down.text,m(a.down.value)-4-a.down.text.width,c-a.down.text.height/2,12,nJ,"right",s);let i=v[o].filter(e=>!e.inside),l=h+n,r=l+7,d=new Map;for(let e of[!0,!1]){let t=i.filter(t=>t.value>=0===e);n7(t.map(e=>({preferred:(e.left+e.right)/2,size:e.text.width})),e?k+2:0,e?1/0:k-2,6).forEach((e,a)=>d.set(t[a],e))}i.forEach(t=>{let a=d.get(t),i=(t.left+t.right)/2,n={strokeColor:nK,...s};e.line(`chart:leader:${o}:${t.s}:a`,{x:i,y:l+1},{x:i,y:l+3},n,"middle"),e.line(`chart:leader:${o}:${t.s}:b`,{x:i,y:l+3},{x:a+t.text.width/2,y:r-1},n,"middle"),e.text(`chart:value:${o}:${t.s}`,t.text,a,r,12,nK,"center",s)})}});let M=x.labels[0].height;if(a.valueAxisTitle){let t=n5(a.valueAxisTitle,480,14);e.text("chart:value-axis-title",t,(480-t.width)/2,b+6+M+10,14,nK)}if(a.categoryAxisTitle){let t=n5(a.categoryAxisTitle,Math.max(c,160),14);e.text("chart:category-axis-title",t,-10-t.width,-8-t.height,14,nK,"right")}}(a,e):function(e,t){let{diagram:a,stacked:s,colors:i}=t,l=a.categories.length,o=cc(t),r="vertical"===a.orientation,n=n3("0",12).height+4+2,c=a.categories.map((e,t)=>t),d=cd(t.domain,300,(e,a)=>c.some(i=>(s?void 0!==t.totals[i].up:t.labels[i].some(e=>e.value>=0))&&(e.max-(s?t.totals[i].up?.value??0:Math.max(0,...t.labels[i].map(e=>e.value))))*a<n),(e,a)=>c.some(i=>(s?void 0!==t.totals[i].down:t.labels[i].some(e=>e.value<0))&&((s?t.totals[i].down?.value??0:Math.min(0,...t.labels[i].map(e=>e.value)))-e.min)*a<n)),p=e=>{let s=300/(e.max-e.min),i=t=>(e.max-t)*s;return a.categories.map((e,s)=>{let l=0,r=0;return a.series.map((e,a)=>{let{value:n,text:c}=t.labels[s][a],d=n>=0?l:r,p=d+n;n>=0?l=p:r=p;let h=i(Math.max(d,p)),g=i(Math.min(d,p));g-h<.5&&(n>=0?h=g-.5:g=h+.5);let u=g-h>=c.height+1&&c.width+6<=o.thickness;return{s:a,value:n,text:c,top:h,bottom:g,inside:u}})})};for(let e=0;s&&e<6;e+=1){let e=p(d),t=d.max/(d.max-d.min)*300,a=t=>Math.max(0,...e.map(e=>e.filter(e=>!e.inside&&e.value>=0===t).reduce((e,t)=>e+t.text.height+2,0))),s=a(!0)>0&&a(!0)>t-2,i=a(!1)>0&&a(!1)>300-t-2;if(!s&&!i)break;d=nF(d,i,s)}let h=300/(d.max-d.min),g=e=>(d.max-e)*h,u=p(d),f=e=>Math.max(o.thickness,t.totals[e].up?.text.width??0,t.totals[e].down?.text.width??0)/2,m=s?Math.max(0,...u.flat().flatMap(e=>e.inside?[]:[e.text.width])):0,v=Math.max(cn(a.categories,o.band,r?3:2,r?200:161),320/l,m>0?2*Math.max(...c.map(f))+10+m+6:0),y=co(d,t.parts),w=Math.max(...y.labels.map(e=>e.width)),x=v*l;d.ticks.forEach((t,a)=>{let s=g(t),i=y.labels[a];e.line(`chart:grid:${a}`,{x:0,y:s},{x:x,y:s},{strokeColor:nQ}),e.text(`chart:tick:${a}`,i,-8-i.width,s-i.height/2,13,nK,"right")});let b=g(0);e.line("chart:baseline",{x:0,y:b},{x:x,y:b},{strokeColor:n1,strokeWidth:2},"middle");let k=o.bars*o.thickness+(o.bars-1)*2,M=300;if(a.categories.forEach((l,r)=>{let n=0+v*(r+.5),c=n-k/2,d=n5(l,v-10,14),p=e.text(`chart:category:${r}`,d,n-d.width/2,308,14,nJ);if(M=Math.max(M,p.bottom),a.series.forEach((n,d)=>{let p,h,{value:f,text:m}=t.labels[r][d],v=i[d],y=`chart:bar:${r}:${d}`,w={groupIds:[s?`chart:stack:${r}`:y]},x=s?c:c+d*(o.thickness+2);s?{top:p,bottom:h}=u[r][d]:(p=g(Math.max(0,f)),(h=g(Math.min(0,f)))-p<.5&&(f>=0?p=h-.5:h=p+.5));let b=`${l} \xb7 ${cl(a,d)}: ${m.text}`;if(0!==f&&e.mark(y,"rectangle",{x:x,y:p,width:o.thickness,height:h-p},b,s?{fillColor:v,strokeColor:e.surface,strokeWidth:2,...w}:{fillColor:v,strokeColor:v,...w}),s){u[r][d].inside&&e.text(`chart:value:${r}:${d}`,m,x+(o.thickness-m.width)/2,(p+h-m.height)/2,12,ce(v),"center",w);return}let k=f>=0?p-4-m.height:h+4;e.text(`chart:value:${r}:${d}`,m,x+(o.thickness-m.width)/2,k,12,nK,"center",w)}),s){let t=u[r].filter(e=>!e.inside),a=n+f(r)+10,s=new Map;for(let e of[!0,!1]){let a=t.filter(t=>t.value>=0===e);n7(a.map(e=>({preferred:(e.top+e.bottom)/2,size:e.text.height})),e?0:b+2,e?b-2:300,2).forEach((e,t)=>s.set(a[t],e))}let i={groupIds:[`chart:stack:${r}`]};t.forEach(t=>{let l=s.get(t),n=(t.top+t.bottom)/2,d={strokeColor:nK,...i};e.line(`chart:leader:${r}:${t.s}:a`,{x:c+o.thickness+1,y:n},{x:a-4,y:n},d,"middle"),e.line(`chart:leader:${r}:${t.s}:b`,{x:a-4,y:n},{x:a-1,y:l+t.text.height/2},d,"middle"),e.text(`chart:value:${r}:${t.s}`,t.text,a,l,12,nK,"left",i)})}if(s){let a=t.totals[r],s={groupIds:[`chart:stack:${r}`]};a.up&&e.text(`chart:total:${r}`,a.up.text,n-a.up.text.width/2,g(a.up.value)-4-a.up.text.height,12,nJ,"center",s),a.down&&e.text(`chart:total-negative:${r}`,a.down.text,n-a.down.text.width/2,g(a.down.value)+4,12,nJ,"center",s)}}),a.valueAxisTitle){let t=n5(a.valueAxisTitle,Math.max(x+w,200),14),s=y.labels[y.labels.length-1];e.text("chart:value-axis-title",t,-8-w,-s.height/2-8-t.height,14,nK,"left")}if(a.categoryAxisTitle){let t=n5(a.categoryAxisTitle,Math.max(x,200),14);e.text("chart:category-axis-title",t,(0+x-t.width)/2,M+12,14,nK)}}(a,e),cs(a,t,{legend:"bar",colors:e.colors})}a.breakRulesUnderText(e=>e.startsWith("chart:grid:")||e.startsWith("chart:category-tick:")||"chart:baseline"===e||"chart:axis"===e);let s=a.bounds(),i=40-s.left,l=40-s.top,o=a.elements.map(e=>{if("line"===e.type){let[t,a,...s]=e.points.map(e=>({x:n4(e.x+i),y:n4(e.y+l)}));return{...e,points:[t,a,...s]}}return"arrow"===e.type?e:{...e,x:n4(e.x+i),y:n4(e.y+l)}});return{kind:"canvas",version:1,diagramId:t.id,title:t.title,width:Math.ceil(s.right-s.left+80),height:Math.ceil(s.bottom-s.top+80),accentColor:t.style.accentColor,backgroundColor:t.style.backgroundColor,elements:o,layers:[],layouts:[],zOrder:a.zOrder()}})(u3(u)),catch:e=>new fb({status:"render_failed",context:{...w,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:u.id},message:e instanceof Error?e.message:"Unable to render chart scene.",hint:"Repair the categories and series values and retry."})]}})}).pipe(o.fRP("codeMode.buildChart.render")),b=se(x);if(b.length>0)return yield*new fb({status:"render_failed",context:{...w,issues:f$(b).map(e=>({...e,hint:"Use fewer categories or series and retry buildChart."}))}});let k={...w,partial:mt(x)},M=yield*mi({scene:x,formats:fU(h.options),inlineFormats:fX(h.options),...h.requestId?{requestId:h.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fb({status:e.status,context:{..."export_failed"===e.status?k:w,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:g,...me(h.requestId),normalizedSpec:u,quality:v,artifact:M,issues:[]}}),mg=o.fn("codeMode.buildGantt.workflow")(function*(e){var t,a,s;let l,r,n=i.q$Z(lQ,{errors:"all",reportInput:!0})(e);if(!um.oJ(n))return yield*new fk({status:"invalid_input",context:{issues:fF(s9(n.failure))}});let c=yield*uQ,d=n.success,p=yield*o.OH5(()=>c.createId("build")),h=(l=s5((t=d.spec).title),{id:fE(t.id)??(fI(l)||"sketchi-gantt"),title:l,tasks:t.tasks.map(e=>{let t=fE(e.phase);return{...e,id:s5(e.id),label:s5(e.label),start:s5(e.start),...void 0!==e.end?{end:s5(e.end)}:{},...void 0!==t?{phase:t}:{},...e.dependsOn?{dependsOn:e.dependsOn.map(s5)}:{}}}),...t.phases?{phases:t.phases.map(s5)}:{},...t.today?{today:s5(t.today)}:{},style:{...y}}),g={buildId:p,...me(d.requestId),normalizedSpec:h},u=tp(u5(h)).map(e=>fB({code:u4[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(u.length>0)return yield*new fk({status:"invalid_gantt",context:{...g,issues:u}});let f={accepted:10>=(a=d.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:h.tasks.length,edgeCount:h.tasks.reduce((e,t)=>e+(t.dependsOn?.length??0),0)},checks:[]},m={...g,quality:f};if(!f.accepted)return yield*new fk({status:"quality_failed",context:{...m,issues:fO(f)}});let v=yield*o.SvU({try:()=>(function(e){let t=tg(e),a=c4(t,44),s=a.work;for(let e of cG){if(0===a.work.conflicts||a.work.conflicts>4)break;let i=c4(t,44+e);s={layouts:s.layouts+1,placements:s.placements+i.work.placements,expansions:s.expansions+i.work.expansions,corridors:i.work.corridors,conflicts:i.work.conflicts},i.work.conflicts<a.work.conflicts&&(a=i)}return{scene:a.scene,work:{...s,corridors:a.work.corridors,conflicts:a.work.conflicts}}})(u5(h)).scene,catch:e=>new fk({status:"render_failed",context:{...m,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:h.id},message:e instanceof Error?e.message:"Unable to render Gantt scene.",hint:"Repair the tasks' dates and dependencies and retry."})]}})}).pipe(o.fRP("codeMode.buildGantt.render")),w=se(v);if(w.length>0)return yield*new fk({status:"render_failed",context:{...m,issues:f$(w).map(e=>({...e,hint:"Use fewer tasks or dependencies and retry buildGantt."}))}});let x={...m,partial:mt(v)},b=yield*mi({scene:v,formats:fU(d.options),inlineFormats:fX(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fk({status:e.status,context:{..."export_failed"===e.status?x:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:p,...me(d.requestId),normalizedSpec:h,quality:f,artifact:b,issues:(r=new Map((s=u5(h)).tasks.map(e=>[e.id,e])),s.tasks.flatMap((e,t)=>{let a=tr(e);return(e.dependsOn??[]).flatMap((s,i)=>{let l=r.get(s),o=l&&tr(l);if(!a||!o)return[];let n=o.milestone?o.start:o.end-!!a.milestone;return a.start>=n?[]:[{task:e.id,dependsOn:s,finishes:tl(o.milestone?o.start:o.end-1),path:`tasks.[${t}].dependsOn.[${i}]`}]})})).map(e=>fB({code:"gantt_schedule_conflict",severity:"warning",stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:`Task "${e.task}" starts before "${e.dependsOn}" finishes on ${e.finishes}.`,hint:`Keep dates the prompt states; otherwise start "${e.task}" after ${e.finishes}.`}))}}),mu=i._kM({spec:i.$r1,requestId:i.Qrq(i.$r1)}),mf=i._kM({source:i._kM({scene:i.$r1})}),mm=o.fn("codeMode.canvas.serializedLimit")((e,t)=>o.SvU(()=>rQ(e)).pipe(o.YWq({onFailure:()=>fB({code:"invalid_type",stage:"input",ref:{kind:"request",path:t},message:"CanvasSpec could not be serialized as JSON.",hint:"Remove non-JSON values or reduce deeply nested fields and retry."}),onSuccess:e=>e<=aU.maxSerializedBytes?void 0:fB({code:"canvas_limit_exceeded",stage:"canvas",ref:{kind:"request",path:t},message:`CanvasSpec exceeds ${aU.maxSerializedBytes} serialized bytes.`,hint:"Split the visualization into a smaller canvas or reduce repeated text and points."})}))),mv=o.fn("codeMode.createCanvas.workflow")(function*(e){let t=yield*uQ,a=yield*o.OH5(()=>t.createId("build")),s=i.q$Z(mu)(e),l=um.oJ(s)?{spec:s.success.spec,requestId:i.is(i.QfV)(s.success.requestId)?s.success.requestId:void 0}:void 0;if(l){let e=yield*mm(l.spec,"spec");if(e)return yield*new fM({status:"canvas_limit_exceeded"===e.code?"limit_exceeded":"invalid_input",context:{buildId:a,...me(l.requestId),issues:[e]}})}let r=i.q$Z(oV,{errors:"all",reportInput:!0})(e);if(!um.oJ(r))return yield*new fM({status:"invalid_input",context:{issues:fF(s9(r.failure))}});let n=r.success,c={buildId:a,...me(n.requestId)},d=fD(n.spec);if(!d)return yield*new fM({status:"invalid_canvas",context:{...c,issues:[fB({code:"invalid_canvas_geometry",stage:"canvas",ref:{kind:"request",path:"spec.elements"},message:"CanvasSpec contains an invalid point list.",hint:"Provide at least two points for lines/connectors and three points for polygons."})]}});let p=se(d).filter(e=>"limit_exceeded"===e.code);if(p.length>0)return yield*new fM({status:"limit_exceeded",context:{...c,issues:f$(p)}});let h=yield*uU(function(e){let t=[...e.elements];for(let a of e.layouts)t=function(e,t){switch(t.type){case"row":case"column":case"stack":return function(e,t){let a=sa(e,t.ids),s=a[0];if(!s)return[...e];let i=st(s),l=t.x??i.x,o=t.y??i.y,r="stack"===t.type?t.gap??0:t.gap??32,n=new Map,c="column"===t.type?o:l;for(let e of a){let a=st(e);n.set(e.id,{x:"column"===t.type||"stack"===t.type?l:c,y:"column"===t.type?c:o}),"stack"!==t.type&&(c+=("column"===t.type?a.height:a.width)+r)}return ss(e,n)}(e,t);case"grid":return function(e,t){let a=sa(e,t.ids);if(0===a.length)return[...e];let s=Math.max(1,Math.floor(t.columns)),i=a.map(st),l=Array.from({length:s},(e,t)=>Math.max(0,...i.filter((e,a)=>a%s===t).map(e=>e.width))),o=Array.from({length:Math.ceil(a.length/s)},(e,t)=>Math.max(0,...i.filter((e,a)=>Math.floor(a/s)===t).map(e=>e.height))),r=i[0];if(!r)return[...e];let n=t.x??r.x,c=t.y??r.y,d=t.columnGap??32,p=t.rowGap??32,h=new Map;return a.forEach((e,t)=>{let a=t%s,i=Math.floor(t/s);h.set(e.id,{x:n+l.slice(0,a).reduce((e,t)=>e+t,0)+d*a,y:c+o.slice(0,i).reduce((e,t)=>e+t,0)+p*i})}),ss(e,h)}(e,t);case"align":return function(e,t){let a=sa(e,t.ids);if(0===a.length)return[...e];let s=a.map(st),i=s.map(e=>si(e,t.axis)),l=s.map(e=>si(e,t.axis)+sl(e,t.axis)),o=s.map(e=>si(e,t.axis)+sl(e,t.axis)/2),r="start"===t.alignment?Math.min(...i):"end"===t.alignment?Math.max(...l):o.reduce((e,t)=>e+t,0)/o.length,n=new Map;return a.forEach((e,a)=>{let i=s[a];if(!i)return;let l="start"===t.alignment?r:"end"===t.alignment?r-sl(i,t.axis):r-sl(i,t.axis)/2;n.set(e.id,{x:"x"===t.axis?l:i.x,y:"y"===t.axis?l:i.y})}),ss(e,n)}(e,t);case"distribute":return function(e,t){let a=sa(e,t.ids).sort((e,a)=>si(st(e),t.axis)-si(st(a),t.axis));if(a.length<2)return[...e];let s=a.map(st),i=s[0],l=s[s.length-1];if(!i||!l)return[...e];let o=si(i,t.axis),r=si(l,t.axis)+sl(l,t.axis),n=s.reduce((e,a)=>e+sl(a,t.axis),0),c=t.gap??Math.max(0,(r-o-n)/(a.length-1)),d=new Map,p=o;return a.forEach((e,a)=>{let i=s[a];i&&(d.set(e.id,{x:"x"===t.axis?p:i.x,y:"y"===t.axis?p:i.y}),p+=sl(i,t.axis)+c)}),ss(e,d)}(e,t)}}(t,a);let a=function(e){let t=1,a=1;for(let s of e)if(a0(s)){let e=st(s);t=Math.max(t,e.x+e.width),a=Math.max(a,e.y+e.height)}else if("arrow"===s.type||"line"===s.type)for(let e of s.points)t=Math.max(t,e.x),a=Math.max(a,e.y);return{width:t+48,height:a+48}}(t=function(e){let t=sd(e),a=new Map;for(let t of e)("node"===t.type||"frame"===t.type)&&a.set(t.id,t);let s=e.map(e=>{if("arrow"===e.type){let a=t.get(e.sourceNodeId),s=t.get(e.targetNodeId);if(!a||!s)return e;if(e.curved){let t=e.points[0],i=e.points[e.points.length-1]??t;return sn(t,a)&&sn(i,s)?e:{...e,points:sc(a,s)}}return{...e,points:[sr(a,so(s)),...e.points.slice(1,-1),sr(s,so(a))]}}if("line"===e.type){let t=e.startBinding?a.get(e.startBinding.elementId):void 0,s=e.endBinding?a.get(e.endBinding.elementId):void 0;if(!t&&!s)return e;let i=[e.points[0],e.points[1],...e.points.slice(2)];return t&&(i[0]=sr(t,s?so(s):i[i.length-1]??i[0])),s&&(i[i.length-1]=sr(s,t?so(t):i[0])),{...e,points:i}}return e}),i=new Map(s.map(e=>[e.id,e]));return s.map(e=>{if("text"!==e.type||!e.containerId)return e;let t=i.get(e.containerId);if(t?.type==="node"){let a=so(t);return{...e,x:a.x,y:a.y}}if(t?.type==="arrow"){let a=t.points[0],s=t.points[t.points.length-1]??a;return{...e,x:(a.x+s.x)/2,y:(a.y+s.y)/2}}return e})}(t)),s=e.zOrder.length?[...e.zOrder]:t.map((e,t)=>({element:e,index:t})).sort((e,t)=>(e.element.zIndex??e.index)-(t.element.zIndex??t.index)).map(({element:e})=>e.id);return{...e,width:Math.max(e.width,a.width),height:Math.max(e.height,a.height),elements:t,zOrder:s}}(d),t.icons),g=h.scene,u=function(e){let{icons:t,...a}=e;return a}(g),f=se(g);if(f.length>0){let e=f$(f);return yield*new fM({status:e.some(e=>"canvas_limit_exceeded"===e.code)?"limit_exceeded":"invalid_canvas",context:{...c,normalizedSpec:u,issues:[...h.issues,...e]}})}let m={...c,normalizedSpec:u,partial:mt(g)},v=yield*mi({scene:g,formats:fU(n.options),inlineFormats:fX(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:fG}).pipe(o.xm_(e=>new fM({status:e.status,context:{...m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:a,...me(n.requestId),normalizedSpec:u,artifact:v,issues:h.issues}}),my=o.fn("codeMode.buildFlowchart.workflow")(function*(e){var t,a;let s,l=i.q$Z(lZ,{errors:"all",reportInput:!0})(function(e){if(!uR(e))return e;let{spec:t}=e;if(!uR(t)||!Array.isArray(t.nodes))return e;let a=t.nodes,s=!1,i=Array.isArray(t.edges)?t.edges:void 0,l=i?.map(e=>{if(!uR(e)||void 0!==e.source&&void 0!==e.target||void 0===e.from&&void 0===e.to)return e;s=!0;let{from:t,to:a,...i}=e;return{...i,source:e.source??t,target:e.target??a}}),o=(l??[]).filter(uR),r=new Map,n=e=>{let t=r.get(e);return t||r.set(e,t={incoming:0,outgoing:0,labeledOutgoing:0}),t};for(let e of o){let t=n(e.source);t.outgoing+=1,"string"==typeof e.label&&""!==e.label.trim()&&(t.labeledOutgoing+=1),n(e.target).incoming+=1}let c=a.filter(uR).filter(e=>0===n(e.id).incoming),d=a.map(e=>uR(e)?(e=>{let t=e.kind??e.type,{incoming:a,outgoing:s,labeledOutgoing:i}=n(e.id),l="string"==typeof e.label&&s5(e.label).endsWith("?");if("string"==typeof t){let i=t.trim().toLowerCase().replace(/[\s_-]+/g,""),l=uG[i];if(l)return l;if(uD.has(i)){if(0===a&&s>0)return"start";if(0===s&&a>0)return"end"}return e.kind}return void 0!==t?e.kind:0===s&&a>0?"end":0===a&&1===c.length&&0===i?"start":a>0&&1===s&&0===i&&!l?"process":void 0})(e):void 0),p=a.some((e,t)=>uR(e)&&"end"===d[t]&&n(e.id).incoming>0&&0===n(e.id).outgoing),h=new Set(a.flatMap((e,t)=>uR(e)&&"decision"===d[t]?[e.id]:[])),g=new Set(o.filter(e=>h.has(e.source)&&"string"==typeof e.label&&""!==e.label.trim()).map(e=>e.target)),u=a.map((e,t)=>{if(!uR(e))return e;let a=d[t],i="string"==typeof e.label&&s5(e.label).endsWith("?");if("process"===a&&p&&g.has(e.id)&&0===n(e.id).outgoing&&!i&&(a="end"),a===e.kind)return e;s=!0;let{type:l,...o}=e;return{...o,kind:a}});return s?{...e,spec:{...t,nodes:u,...l?{edges:l}:{}}}:e}(e));if(!um.oJ(l))return yield*new fg({status:"invalid_input",context:{issues:fF(s9(l.failure),fq)}});let r=yield*uQ,n=l.success,c=yield*o.OH5(()=>r.createId("build")),d=(s=s5((a=n.spec).title),{id:u$(a.id)??(s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"sketchi-flowchart"),title:s,nodes:a.nodes.map(e=>({id:s5(e.id),label:s5(e.label),kind:e.kind,...e.description?{description:s5(e.description)}:{},...e.icon?{icon:{slug:s5(e.icon.slug)}}:{},...e.group?{group:s5(e.group)}:{},...e.lane?{lane:s5(e.lane)}:{},...e.shape?{shape:e.shape}:{}})),edges:a.edges.map((e,t)=>({id:u$(e.id)??`edge-${t+1}`,source:s5(e.source),target:s5(e.target),...e.label?{label:s5(e.label)}:{}})),...a.groups?{groups:a.groups.map(e=>({id:s5(e.id),label:s5(e.label),...e.parent?{parent:s5(e.parent)}:{},...e.kind?{kind:e.kind}:{}}))}:{},...a.lanes?{lanes:a.lanes.map(e=>({id:s5(e.id),label:s5(e.label)}))}:{},layout:{direction:a.layout.direction},style:{...y}}),p=uO(d.nodes,r.icons),h={...d,nodes:p.nodes},g={buildId:c,...me(n.requestId),normalizedSpec:h},u=i.q$Z(ey,{errors:"all",reportInput:!0})({id:h.id,title:h.title,type:"flowchart",nodes:h.nodes.map(e=>({...e,metadata:{}})),edges:h.edges.map(e=>({...e,metadata:{}})),...h.groups?{groups:h.groups.map(e=>({...e}))}:{},...h.lanes?{lanes:h.lanes.map(e=>({...e}))}:{},layout:{direction:h.layout.direction,edgeRouting:"orthogonal"},style:h.style,metadata:{}});if(!um.oJ(u))return yield*new fg({status:"invalid_flowchart",context:{...g,issues:(t=s9(u.failure),t.issues.slice(0,20).map(e=>{let t=function(e,t){let a=fS(e.path),s="input"===a?"spec":`spec.${a}`,[i,l]=e.path;if("nodes"===i&&"number"==typeof l){let e=t.nodes[l]?.id;return{kind:"node",...e?{id:e}:{},path:s}}if("edges"===i&&"number"==typeof l){let e=t.edges[l]?.id;return{kind:"edge",...e?{id:e}:{},path:s}}if("groups"===i&&"number"==typeof l){let e=t.groups?.[l]?.id;return{kind:"group",...e?{id:e}:{},path:s}}if("lanes"===i&&"number"==typeof l){let e=t.lanes?.[l]?.id;return{kind:"lane",...e?{id:e}:{},path:s}}return{kind:"diagram",id:t.id,path:s}}(e,h);return fB({code:fA(e),stage:"flowchart",ref:t,message:e.message,hint:`Fix ${t.path??"spec"} so normalization produces a valid canonical flowchart value.`})}))}});let f=u.success,m=eb(f).map(e=>{let t=function(e){if(e)return{kind:e.kind,...e.id?{id:e.id}:{},...e.path?{path:`spec.${e.path}`}:{}}}(e.ref);return fB({code:e.code,stage:"flowchart",...t?{ref:t}:{},message:e.message,hint:e.hint})});if(m.length>0)return yield*new fg({status:"invalid_flowchart",context:{...g,issues:m}});eM(f);let v=function(e,t){let a=[],s=0,i=(e,t,i,l=!1)=>{s+=e,a.push({...i,passed:!1,severity:l?"error":"warning",message:t})},l=new Map,o=new Map;for(let t of e.edges)l.set(t.source,(l.get(t.source)??0)+1),l.set(t.target,(l.get(t.target)??0)+1),o.set(t.source,[...o.get(t.source)??[],t]);if(e.nodes.length>1&&0===e.edges.length)i(5,"no edges at all — every node floats unconnected",{code:"disconnected_graph",refs:uY(e.nodes)},!0);else{let t=e.nodes.filter(e=>(l.get(e.id)??0)===0);t.length>0&&e.nodes.length>1&&i(Math.min(1.5*t.length,4.5),`unconnected node(s): ${t.map(e=>e.id).join(", ")}`,{code:"disconnected_graph",refs:uY(t)},!0);let a=function(e){let t=new Map;for(let a of e.nodes)t.set(a.id,[]);for(let a of e.edges)t.get(a.source)?.push(a.target),t.get(a.target)?.push(a.source);let a=new Set,s=0;for(let i of e.nodes){if(a.has(i.id))continue;s+=1;let e=[i.id];for(a.add(i.id);e.length>0;){let s=e.pop();if(void 0===s)break;for(let i of t.get(s)??[])a.has(i)||(a.add(i),e.push(i))}}return s}(e);a>1&&0===t.length&&i(2,`diagram splits into ${a} disconnected islands`,{code:"disconnected_graph",refs:uY(e.nodes)},!0)}e.nodes.length<3?i(2,"too sparse — a useful flow needs at least 3 nodes",{code:"graph_too_sparse",refs:[{kind:"diagram",id:e.id,path:"spec.nodes"}]}):e.nodes.length>24&&i(2,"too dense — trim or merge nodes (24 max)",{code:"graph_too_dense",refs:[{kind:"diagram",id:e.id,path:"spec.nodes"}]});let r=new Map;for(let t of e.nodes){let e=t.label.trim().toLowerCase();r.set(e,(r.get(e)??0)+1)}let n=[...r.entries()].filter(([,e])=>e>1);n.length>0&&i(Math.min(n.length,3),`duplicate label(s): ${n.map(([e])=>`"${e}"`).join(", ")}`,{code:"duplicate_label",refs:uY(e.nodes.filter(e=>(r.get(e.label.trim().toLowerCase())??0)>1))});let c=0,d=0;for(let t of e.nodes){if("decision"!==t.kind){t.label.endsWith("?")&&i(0,`question label on non-decision node "${t.id}"; use kind "decision" only for branch points`,{code:"question_label_not_decision",refs:uY([t])});continue}let e=o.get(t.id)??[];e.length<2?(c+=1,i(0,`decision "${t.id}" needs at least 2 outgoing branches`,{code:"underbranched_decision",refs:uY([t])},!0)):e.some(e=>!e.label)&&(d+=1,i(0,`label every branch out of decision "${t.id}" (yes/no, …)`,{code:"unlabeled_decision_branch",refs:uY([t])}))}s+=Math.min(1.5*c,4.5)+Math.min(d,3);let p=e.nodes.filter(e=>e.label.length>42);p.length>0&&i(Math.min(.5*p.length,2),`shorten label(s): ${p.map(e=>e.id).join(", ")}`,{code:"label_too_long",refs:uY(p)});let h=e.nodes.filter(e=>uX.test(e.label.trim()));h.length>0&&i(Math.min(h.length,3),`generic label(s) say nothing: ${h.map(e=>`"${e.label}"`).join(", ")}`,{code:"generic_label",refs:uY(h)}),(e.title.trim().length<4||uT.test(e.title.trim()))&&i(.5,"give the diagram a specific title",{code:"weak_title",refs:[{kind:"diagram",id:e.id,path:"spec.title"}]});let g=Math.max(0,Math.round((10-s)*10)/10);return{accepted:g>=t&&!a.some(e=>"error"===e.severity),score:g,threshold:t,summary:{nodeCount:e.nodes.length,edgeCount:e.edges.length},checks:a}}(f,n.options?.minQualityScore??8),w={...g,quality:v};if(!v.accepted)return yield*new fg({status:"quality_failed",context:{...w,issues:fO(v)}});let x=yield*o.SvU({try:()=>hS(U(f)),catch:e=>new fg({status:"render_failed",context:{...w,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:h.id},message:e instanceof Error?e.message:"Unable to render flowchart scene.",hint:"Simplify the graph or retry with a smaller flowchart."})]}})}).pipe(o.fRP("codeMode.buildFlowchart.render")),b=yield*uU(x,r.icons),k=b.scene,M={...w,partial:mt(k)},C=yield*mi({scene:k,formats:fU(n.options),inlineFormats:fX(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fg({status:e.status,context:{..."export_failed"===e.status?M:w,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...me(n.requestId),normalizedSpec:h,quality:v,artifact:C,issues:[...p.issues,...b.issues]}}),mw=o.fn("codeMode.getArtifact.workflow")(function*(e){let t=i.q$Z(oE,{errors:"all",reportInput:!0})(e);if(!um.oJ(t))return yield*new fC({status:"invalid_input",context:{issues:fF(s9(t.failure))}});let a=yield*uQ,s=yield*rN,l=t.success,r=yield*s.readManifest(l.artifactId).pipe(o.xm_(e=>new fC({status:"storage_failed",context:{issues:[ms(e,"storage_read_failed")]}})));if(!r)return yield*new fC({status:"not_found",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:l.artifactId},message:`Artifact "${l.artifactId}" was not found.`,hint:"Use the artifactId returned by buildFlowchart or applyDiagramPatch."})]}});let n=l.format??"scene";if(!r.formats.some(e=>e.format===n))return yield*new fC({status:"format_unavailable",context:{issues:[fB({code:"unsupported_artifact_format",stage:"storage",ref:{kind:"artifact",id:l.artifactId},message:`Artifact "${l.artifactId}" does not include format "${n}".`,hint:"Request a format listed in the artifact bundle."})]}});let c=yield*s.read(l.artifactId,n).pipe(o.xm_(e=>new fC({status:"storage_failed",context:{issues:[ms(e,"storage_read_failed")]}})));return c?{ok:!0,artifactId:l.artifactId,diagramId:r.diagramId,format:n,mimeType:c.mimeType,...a.artifactUrl?{url:a.artifactUrl({artifactId:l.artifactId,format:n})}:{},...!0!==l.inline||!rJ(n)?{}:{inline:c.data},sizeBytes:c.sizeBytes,...r.provenance?{provenance:r.provenance}:{}}:yield*new fC({status:"format_unavailable",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:l.artifactId},message:`Artifact "${l.artifactId}" format "${n}" could not be read.`,hint:"Retry retrieval or rebuild the artifact."})]}})}),mx=o.fn("codeMode.applyDiagramPatch.workflow")(function*(e){let t,a=i.q$Z(mf)(e),s=um.oJ(a)?yield*mm(a.success.source.scene,"source.scene"):void 0;if(s)return yield*new f_({status:"invalid_input",context:{issues:[s]}});let l=i.q$Z(o6,{errors:"all",reportInput:!0})(e);if(!um.oJ(l))return yield*new f_({status:"invalid_input",context:{issues:fF(s9(l.failure))}});let r=yield*uQ,n=l.success,c=yield*o.OH5(()=>r.createId("patch")),d={patchId:c,...me(n.requestId)},p=yield*f9(n).pipe(o.xm_(e=>new f_({status:e.status,context:{...d,...e.context}}))),h={...d,...p.sourceArtifactId?{sourceArtifactId:p.sourceArtifactId}:{}},g=p.scene;if(g.elements.length>aU.maxElements)t=[{code:"limit_exceeded",message:`Canvas exceeds ${aU.maxElements} elements.`,path:"elements"}];else{let e=fD(g);t=e?se(e).filter(e=>"limit_exceeded"===e.code):[]}if(t.length>0)return yield*new f_({status:"invalid_input",context:{...h,issues:f$(t)}});let u=fZ(g),f=[];for(let e of n.operations)if((f=function(e,t){switch(t.op){case"setDefaultStyle":case"setStyle":if(t.style.backgroundColor&&(e.backgroundColor=t.style.backgroundColor),"setDefaultStyle"===t.op){for(let a of(t.style.strokeColor&&(e.accentColor=t.style.strokeColor),fj(e)))t.style.fillColor&&(a.fillColor=t.style.fillColor),t.style.strokeColor&&(a.strokeColor=t.style.strokeColor),t.style.textColor&&(a.textColor=t.style.textColor);for(let a of fW(e))t.style.strokeColor&&(a.strokeColor=t.style.strokeColor),t.style.textColor&&(a.textColor=t.style.textColor);for(let a of fN(e))t.style.textColor&&(a.textColor=t.style.textColor);return[]}let a=fK(e,t.selector);if(0===a.nodes.length&&0===a.arrows.length&&0===a.texts.length)return[fQ(t)];for(let s of a.nodes)if(t.style.fillColor&&(s.fillColor=t.style.fillColor),t.style.strokeColor&&(s.strokeColor=t.style.strokeColor),t.style.textColor){s.textColor=t.style.textColor;let a=f1(e,s.id);a&&(a.textColor=t.style.textColor)}for(let s of a.arrows)if(t.style.strokeColor&&(s.strokeColor=t.style.strokeColor),t.style.textColor){s.textColor=t.style.textColor;let a=f1(e,s.id);a&&(a.textColor=t.style.textColor)}for(let e of a.texts)t.style.textColor&&(e.textColor=t.style.textColor);return[];case"setShape":let s=fK(e,t.selector);if(0===s.nodes.length)return[fQ(t)];let i=[];for(let a of s.nodes){if(a.shape=t.shape,"polygon"===t.shape?a.points=[{x:a.width/2,y:0},{x:a.width,y:a.height/2},{x:a.width/2,y:a.height},{x:0,y:a.height/2}]:delete a.points,"circle"===t.shape){let e=Math.max(a.width,a.height);a.x-=(e-a.width)/2,a.y-=(e-a.height)/2,a.width=e,a.height=e,i.push(a.nodeId)}!function(e,t){let a=f1(e,t.id);a&&(a.x=t.x+t.width/2,a.y=t.y+t.height/2)}(e,a)}return f2(e,i),[];case"translate":return function(e,t){let a=fK(e,t.selector);if(0===a.nodes.length&&0===a.arrows.length&&0===a.texts.length)return[fQ(t)];let s=new Set,i=new Set;for(let l of a.nodes){l.x+=t.dx,l.y+=t.dy,s.add(l.nodeId);let a=f1(e,l.id);a&&(a.x+=t.dx,a.y+=t.dy,i.add(a.id))}for(let s of a.arrows){s.points=s.points.map(e=>{var a,s;return a=t.dx,s=t.dy,{x:e.x+a,y:e.y+s}});let a=f1(e,s.id);a&&(a.x+=t.dx,a.y+=t.dy,i.add(a.id))}for(let e of a.texts)i.has(e.id)||(e.x+=t.dx,e.y+=t.dy);return f2(e,[...s]),f6(e),[]}(e,t);case"replaceText":let l=fK(e,t.selector);if(0===l.nodes.length&&0===l.arrows.length&&0===l.texts.length)return[fQ(t)];for(let a of l.nodes){a.label=t.text;let s=f1(e,a.id);s&&(s.text=t.text)}for(let a of l.arrows){a.label=t.text;let s=f1(e,a.id);s&&(s.text=t.text)}for(let e of l.texts)e.text=t.text;return[];case"rerouteEdges":let o;return 0===(o=fK(e,t.selector)).arrows.length?[fQ(t)]:o.arrows.flatMap(t=>f4(e,t));case"insert":let r=new Set(e.elements.map(e=>e.id)),n=t.elements.map(e=>e.id);if(new Set(n).size!==n.length||n.some(e=>r.has(e)))return f8(t,"Inserted elements must use ids that are unique within the canvas.");let c=f7(e.zOrder,t.beforeId,t.afterId);return void 0===c?f8(t,"Insert specifies an unknown anchor or both beforeId and afterId."):(e.elements.push(...t.elements.map(e=>structuredClone(e))),e.zOrder.splice(c,0,...n),[]);case"remove":return function(e,t){let a,s=function(e,t){let a=fK(e,t),s=new Set([...a.nodes.map(e=>e.id),...a.arrows.map(e=>e.id),...a.texts.map(e=>e.id)]),i=new Set(t.ids??[]);for(let t of e.elements)i.has(t.id)&&s.add(t.id);return s}(e,t.selector);if(0===s.size)return[fQ(t)];let i=new Set(e.elements.flatMap(e=>"node"===e.type&&s.has(e.id)?[e.nodeId]:[]));do for(let t of(a=s.size,e.elements))("text"===t.type&&(t.containerId&&s.has(t.containerId)||fW(e).some(a=>s.has(a.id)&&f1(e,a.id)?.id===t.id))||"arrow"===t.type&&(i.has(t.sourceNodeId)||i.has(t.targetNodeId))||"line"===t.type&&(t.startBinding&&s.has(t.startBinding.elementId)||t.endBinding&&s.has(t.endBinding.elementId)))&&s.add(t.id);while(s.size!==a)let l=e.elements.filter(e=>!s.has(e.id)).map(e=>{if(e.frameId&&s.has(e.frameId)){let{frameId:t,...a}=e;return a}return e});e.elements.splice(0,e.elements.length,...l);let o=e.zOrder.filter(e=>!s.has(e));e.zOrder.splice(0,e.zOrder.length,...o);let r=e.layouts.map(e=>({...e,ids:e.ids.filter(e=>!s.has(e))})).filter(e=>e.ids.length>0);return e.layouts.splice(0,e.layouts.length,...r),f6(e),[]}(e,t);case"replace":let d;return(d=e.elements.findIndex(e=>e.id===t.id))<0?[fQ(t)]:t.element.id!==t.id?f8(t,"Replacement element id must match the stable id being replaced."):(e.elements.splice(d,1,structuredClone(t.element)),f6(e),[]);case"reorder":let p=new Set(t.ids);if(p.size!==t.ids.length||t.ids.some(t=>!e.zOrder.includes(t)))return f8(t,"Reorder ids must be unique ids already present in zOrder.");let h=e.zOrder.filter(e=>!p.has(e)),g=f7(h,t.beforeId,t.afterId);return void 0===g?f8(t,"Reorder specifies an unknown anchor or both beforeId and afterId."):(h.splice(g,0,...t.ids),e.zOrder.splice(0,e.zOrder.length,...h),[]);case"group":case"ungroup":let u=new Set(t.ids);if(t.ids.some(t=>!e.elements.some(e=>e.id===t)))return[fQ(t)];let f=e.elements.map(e=>u.has(e.id)?"group"===t.op?{...e,groupIds:[...new Set([...e.groupIds??[],t.groupId])]}:{...e,groupIds:t.groupId?(e.groupIds??[]).filter(e=>e!==t.groupId):[]}:e);return e.elements.splice(0,e.elements.length,...f),[]}}(g,e)).length>0)break;if(f.length>0)return yield*new f_({status:f[0]?.code==="unknown_patch_target"?"target_not_found":"unsupported_operation",context:{...h,issues:f}});if(n.options?.preserveConnectivity!==!1){let e=fZ(g);if(!(u.length===e.length&&u.every((t,a)=>t===e[a])))return yield*new f_({status:"connectivity_changed",context:{...h,issues:[fB({code:"patch_preserve_connectivity_failed",stage:"flowchart",ref:{kind:"diagram",id:g.diagramId},message:"Patch changed the diagram edge connectivity.",hint:"Use buildFlowchart for process-graph structure or buildMindmap for hierarchy structure."})]}})}let m=fD(g);if(!m)return yield*new f_({status:"render_failed",context:{...h,issues:[fB({code:"patch_output_invalid",stage:"render",ref:{kind:"diagram",id:g.diagramId},message:"Patched scene has an invalid arrow point list.",hint:"Reroute edges or rebuild the flowchart artifact."})]}});let v=yield*uU(m,r.icons),y=v.scene,w=se(y);if(w.length>0)return yield*new f_({status:"render_failed",context:{...h,partial:mt(y),issues:[...v.issues,...f$(w)]}});let x={...h,partial:mt(y)},b=yield*mi({scene:y,formats:fU(n.options),inlineFormats:fX(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:fG,...p.sourceArtifactId?{provenance:{sourceArtifactId:p.sourceArtifactId}}:{}}).pipe(o.xm_(e=>new f_({status:e.status,context:{..."export_failed"===e.status?x:h,issues:e.issues}})));return{ok:!0,status:"accepted",patchId:c,...me(n.requestId),...p.sourceArtifactId?{sourceArtifactId:p.sourceArtifactId}:{},artifact:b,issues:v.issues}}),mb=o.fn("codeMode.searchIcons.workflow")(function*(e){let t=i.q$Z(r$,{errors:"all",reportInput:!0})(e);if(!um.oJ(t))return yield*new fz({status:"invalid_input",context:{issues:fF(s9(t.failure))}});let a=yield*uQ,s=s5(t.success.q),l=a.icons?.search(s,t.success.limit??10)??[];return{ok:!0,status:"accepted",query:s,icons:l.map(({collection:e,match:t,name:a,slug:s})=>({collection:e,name:a,slug:s,match:t})),issues:a.icons?[]:[fB({code:"unknown_icon",severity:"warning",stage:"input",ref:{kind:"request",path:"q"},message:"This Sketchi runtime has no icon catalog.",hint:"Omit node icons on this host."})]}});function mk(e,t,a){return o.fn(`codeMode.${e}`)(s=>{var i,l,n;let c,d,p,h;return i=e,l=s,n=t(s).pipe(o.YWq({onFailure:a,onSuccess:e=>e})),uu(o.JkU(function*(){let e=yield*r.Ru,t=yield*n,a=yield*r.Ru,s=t.ok?"success":"failure",l=t.ok?void 0:t.status??"unknown_failure";yield*uf(uN,1,{...l?{failureCategory:l}:{},operation:i,outcome:s,surface:"code_mode"}),yield*uf(uK,a-e,{...l?{failureCategory:l}:{},operation:i,outcome:s,surface:"code_mode"}),l&&(yield*uf(uW,1,{failureCategory:l,operation:i,surface:"code_mode"}));let o="buildFlowchart"===i?"flowchart":"buildMindmap"===i?"mindmap":"buildSequenceDiagram"===i?"sequence":"buildTimeline"===i?"timeline":"buildChart"===i?"chart":"buildGantt"===i?"gantt":"buildStateMachine"===i?"state-machine":"buildErDiagram"===i?"er":"buildClassDiagram"===i?"class":"buildOrgChart"===i?"org-chart":"createCanvas"===i?"canvas":"applyDiagramPatch"===i?"patch":void 0;return t.ok&&o&&(yield*uf(uJ,1,{artifactKind:o,operation:i,surface:"code_mode"})),t}),(c=u0(l),d=u0(c?.source),p="string"==typeof c?.artifactId?c.artifactId:"string"==typeof d?.artifactId?d.artifactId:void 0,h="string"==typeof c?.requestId?c.requestId:void 0,{...p?{artifactId:p}:{},...h?{requestId:h}:{}}))})}let mM=mk("buildFlowchart",my,ma),mC=mk("buildMindmap",ml,ma),mz=mk("buildSequenceDiagram",mo,ma),m_=mk("buildStateMachine",mr,ma),mL=mk("buildErDiagram",mn,ma),mB=mk("buildClassDiagram",mc,ma),mS=mk("buildOrgChart",md,ma),mA=mk("buildTimeline",mp,ma),mP=mk("buildChart",mh,ma),mV=mk("buildGantt",mg,ma);mk("createCanvas",mv,ma),mk("getArtifact",mw,ma),mk("searchIcons",mb,ma);let mH=mk("applyDiagramPatch",mx,ma),mq=h,mF={flowchart:i7,mindmap:oi,sequence:la,timeline:li,chart:lo,"state-machine":lh,gantt:lu,er:lb,class:lV,"org-chart":lE};function mI(e){return mq.some(t=>t===e)}function mE(e,t){let a={spec:e.spec,...t?{options:t}:{}};switch(e.type){case"flowchart":return mM(a);case"mindmap":return mC(a);case"sequence":return mz(a);case"timeline":return mA(a);case"chart":return mP(a);case"state-machine":return m_(a);case"gantt":return mV(a);case"er":return mL(a);case"class":return mB(a);case"org-chart":return mS(a)}}},4733(e,t,a){function s(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}function l(e){var t;return s(e)&&i(e.aliases)&&"number"==typeof e.bytes&&"string"==typeof e.collection&&i(e.keywords)&&"string"==typeof e.name&&"string"==typeof e.slug&&"string"==typeof e.svgPath&&(void 0===e.variant||"string"==typeof e.variant)&&s(t=e.viewBox)&&"number"==typeof t.height&&"number"==typeof t.minX&&"number"==typeof t.minY&&"number"==typeof t.width}function o(e){if(!s(e)||1!==e.version||!Array.isArray(e.icons)||!e.icons.every(l)||!s(e.summary)||"number"!=typeof e.summary.totalIcons||void 0!==e.generatedAt&&"string"!=typeof e.generatedAt)throw Error("Icon manifest does not match the public contract.");return{..."string"==typeof e.generatedAt?{generatedAt:e.generatedAt}:{},icons:e.icons,summary:{collectionCounts:function(e){if(!s(e))throw Error("Icon manifest collection counts are invalid.");let t={};for(let[a,s]of Object.entries(e)){if("number"!=typeof s)throw Error(`Icon manifest count for ${a} is invalid.`);t[a]=s}return t}(e.summary.collectionCounts),totalIcons:e.summary.totalIcons},version:1}}function r(e){return"gcp"===e?"Google Cloud":"gcp-legacy"===e?"Google Cloud Classic":e.split("-").map(e=>["ai","ci","iot","paas"].includes(e)?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}a.d(t,{L:()=>o,y:()=>r})},8713(e,t,a){let s=/<svg\b[^>]*>/u,i=/\sviewBox\s*=\s*(["'])([^"']*)\1/u;function l(e){return void 0===e.variant&&e.bytes<=65536}function o(e){let t=s.exec(e);if(!t)throw Error("Node logo source has no <svg> root element.");let a=t[0],l=i.exec(a)?.[2]?.trim().split(/[\s,]+/u).map(Number);if(!l||4!==l.length||l.some(e=>!Number.isFinite(e))||!((l[2]??0)>0&&(l[3]??0)>0))throw Error("Node logo source has no valid viewBox.");let o=[/\sxmlns\s*=/u.test(a)?"":' xmlns="http://www.w3.org/2000/svg"',/\swidth\s*=/u.test(a)?"":` width="${l[2]}"`,/\sheight\s*=/u.test(a)?"":` height="${l[3]}"`].join("");if(!o)return e;let r=t.index+4;return`${e.slice(0,r)}${o}${e.slice(r)}`}a.d(t,{Bn:()=>o,nC:()=>l})},9095(e){e.exports=JSON.parse('[{"name":"Agola CI","constant":"AGOLA","env":"AGOLA_GIT_REF","pr":"AGOLA_PULL_REQUEST_ID"},{"name":"Alpic","constant":"ALPIC","env":"ALPIC_HOST"},{"name":"Appcircle","constant":"APPCIRCLE","env":"AC_APPCIRCLE","pr":{"env":"AC_GIT_PR","ne":"false"}},{"name":"AppVeyor","constant":"APPVEYOR","env":"APPVEYOR","pr":"APPVEYOR_PULL_REQUEST_NUMBER"},{"name":"AWS CodeBuild","constant":"CODEBUILD","env":"CODEBUILD_BUILD_ARN","pr":{"env":"CODEBUILD_WEBHOOK_EVENT","any":["PULL_REQUEST_CREATED","PULL_REQUEST_UPDATED","PULL_REQUEST_REOPENED"]}},{"name":"Azure Pipelines","constant":"AZURE_PIPELINES","env":"TF_BUILD","pr":{"BUILD_REASON":"PullRequest"}},{"name":"Bamboo","constant":"BAMBOO","env":"bamboo_planKey"},{"name":"Bitbucket Pipelines","constant":"BITBUCKET","env":"BITBUCKET_COMMIT","pr":"BITBUCKET_PR_ID"},{"name":"Bitrise","constant":"BITRISE","env":"BITRISE_IO","pr":"BITRISE_PULL_REQUEST"},{"name":"Buddy","constant":"BUDDY","env":"BUDDY_WORKSPACE_ID","pr":"BUDDY_EXECUTION_PULL_REQUEST_ID"},{"name":"Buildkite","constant":"BUILDKITE","env":"BUILDKITE","pr":{"env":"BUILDKITE_PULL_REQUEST","ne":"false"}},{"name":"CircleCI","constant":"CIRCLE","env":"CIRCLECI","pr":"CIRCLE_PULL_REQUEST"},{"name":"Cirrus CI","constant":"CIRRUS","env":"CIRRUS_CI","pr":"CIRRUS_PR"},{"name":"Cloudflare Pages","constant":"CLOUDFLARE_PAGES","env":"CF_PAGES"},{"name":"Cloudflare Workers","constant":"CLOUDFLARE_WORKERS","env":"WORKERS_CI"},{"name":"Codefresh","constant":"CODEFRESH","env":"CF_BUILD_ID","pr":{"any":["CF_PULL_REQUEST_NUMBER","CF_PULL_REQUEST_ID"]}},{"name":"Codemagic","constant":"CODEMAGIC","env":"CM_BUILD_ID","pr":"CM_PULL_REQUEST"},{"name":"Codeship","constant":"CODESHIP","env":{"CI_NAME":"codeship"}},{"name":"Drone","constant":"DRONE","env":"DRONE","pr":{"DRONE_BUILD_EVENT":"pull_request"}},{"name":"dsari","constant":"DSARI","env":"DSARI"},{"name":"Earthly","constant":"EARTHLY","env":"EARTHLY_CI"},{"name":"Expo Application Services","constant":"EAS","env":"EAS_BUILD"},{"name":"Gerrit","constant":"GERRIT","env":"GERRIT_PROJECT"},{"name":"Gitea Actions","constant":"GITEA_ACTIONS","env":"GITEA_ACTIONS"},{"name":"GitHub Actions","constant":"GITHUB_ACTIONS","env":"GITHUB_ACTIONS","pr":{"GITHUB_EVENT_NAME":"pull_request"}},{"name":"GitLab CI","constant":"GITLAB","env":"GITLAB_CI","pr":"CI_MERGE_REQUEST_ID"},{"name":"GoCD","constant":"GOCD","env":"GO_PIPELINE_LABEL"},{"name":"Google Cloud Build","constant":"GOOGLE_CLOUD_BUILD","env":"BUILDER_OUTPUT"},{"name":"Harness CI","constant":"HARNESS","env":"HARNESS_BUILD_ID"},{"name":"Heroku","constant":"HEROKU","env":{"env":"NODE","includes":"/app/.heroku/node/bin/node"}},{"name":"Hudson","constant":"HUDSON","env":"HUDSON_URL"},{"name":"Jenkins","constant":"JENKINS","env":["JENKINS_URL","BUILD_ID"],"pr":{"any":["ghprbPullId","CHANGE_ID"]}},{"name":"LayerCI","constant":"LAYERCI","env":"LAYERCI","pr":"LAYERCI_PULL_REQUEST"},{"name":"Magnum CI","constant":"MAGNUM","env":"MAGNUM"},{"name":"Netlify CI","constant":"NETLIFY","env":"NETLIFY","pr":{"env":"PULL_REQUEST","ne":"false"}},{"name":"Nevercode","constant":"NEVERCODE","env":"NEVERCODE","pr":{"env":"NEVERCODE_PULL_REQUEST","ne":"false"}},{"name":"Prow","constant":"PROW","env":"PROW_JOB_ID"},{"name":"ReleaseHub","constant":"RELEASEHUB","env":"RELEASE_BUILD_ID"},{"name":"Render","constant":"RENDER","env":"RENDER","pr":{"IS_PULL_REQUEST":"true"}},{"name":"Sail CI","constant":"SAIL","env":"SAILCI","pr":"SAIL_PULL_REQUEST_NUMBER"},{"name":"Screwdriver","constant":"SCREWDRIVER","env":"SCREWDRIVER","pr":{"env":"SD_PULL_REQUEST","ne":"false"}},{"name":"Semaphore","constant":"SEMAPHORE","env":"SEMAPHORE","pr":"PULL_REQUEST_NUMBER"},{"name":"Sourcehut","constant":"SOURCEHUT","env":{"CI_NAME":"sourcehut"}},{"name":"Strider CD","constant":"STRIDER","env":"STRIDER"},{"name":"TaskCluster","constant":"TASKCLUSTER","env":["TASK_ID","RUN_ID"]},{"name":"TeamCity","constant":"TEAMCITY","env":"TEAMCITY_VERSION"},{"name":"Travis CI","constant":"TRAVIS","env":"TRAVIS","pr":{"env":"TRAVIS_PULL_REQUEST","ne":"false"}},{"name":"Vela","constant":"VELA","env":"VELA","pr":{"VELA_PULL_REQUEST":"1"}},{"name":"Vercel","constant":"VERCEL","env":{"any":["NOW_BUILDER","VERCEL"]},"pr":"VERCEL_GIT_PULL_REQUEST_ID"},{"name":"Visual Studio App Center","constant":"APPCENTER","env":"APPCENTER_BUILD_ID"},{"name":"Woodpecker","constant":"WOODPECKER","env":{"CI":"woodpecker"},"pr":{"CI_BUILD_EVENT":"pull_request"}},{"name":"Xcode Cloud","constant":"XCODE_CLOUD","env":"CI_XCODE_PROJECT","pr":"CI_PULL_REQUEST_NUMBER"},{"name":"Xcode Server","constant":"XCODE_SERVER","env":"XCS"}]')}},r={};function n(e){var t=r[e];if(void 0!==t)return t.exports;var a=r[e]={exports:{}};return o[e].call(a.exports,a,a.exports,n),a.exports}n.m=o,n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},s=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,n.t=function(e,t){if(1&t&&(e=this(e)),8&t||"object"==typeof e&&e&&(4&t&&e.__esModule||16&t&&"function"==typeof e.then))return e;var i=Object.create(null);n.r(i);var l={};a=a||[null,s({}),s([]),s(s)];for(var o=2&t&&e;("object"==typeof o||"function"==typeof o)&&!~a.indexOf(o);o=s(o))Object.getOwnPropertyNames(o).forEach(t=>{l[t]=()=>e[t]});return l.default=()=>e,n.d(i,l),i},n.d=(e,t,a)=>{var s=(t,a)=>{for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,[a]:t[s]})};s(t,"get"),s(a,"value")},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce((t,a)=>(n.f[a](e,t),t),[])),n.u=e=>"chunks/"+e+"."+({548:"7c734cd41f2be66d",712:"a869102f22286cfc"})[e]+".js",n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.nc=void 0,i={889:0},l=e=>{var t,a,s=e.__rspack_esm_ids,l=e.__webpack_modules__,o=e.__rspack_esm_runtime,r=0;for(t in l)n.o(l,t)&&(n.m[t]=l[t]);for(o&&o(n);r<s.length;r++)a=s[r],n.o(i,a)&&i[a]&&i[a][0](),i[s[r]]=0},n.f.j=function(e,t){var a=n.o(i,e)?i[e]:void 0;if(0!==a)if(a)t.push(a[1]);else{var s=import("./"+n.u(e)).then(l,t=>{throw 0!==i[e]&&(i[e]=void 0),t}),s=Promise.race([s,new Promise(t=>{a=i[e]=[t]})]);t.push(a[1]=s)}},n(2141);
|
|
251
|
+
${m}`,14),M=Math.cos(o.mid)>=-1e-9?1:-1;p.push({slice:o,text:k,side:M,preferred:166*Math.sin(o.mid)})}let h=e=>p.filter(t=>t.side===e).length,g=e=>Math.abs(Math.cos(e.slice.mid));for(let e of p.filter(e=>g(e)<Math.sin(n2)).toSorted((e,t)=>g(e)-g(t)))h(e.side)-1>h(1===e.side?-1:1)&&(e.side=1===e.side?-1:1);let u=e=>Math.atan2(Math.abs(Math.sin(e.slice.mid)),e.side*Math.cos(e.slice.mid));for(let t of[1,-1]){let a=p.filter(e=>e.side===t),s=a.filter(e=>e.preferred<0).toSorted((e,t)=>u(e)-u(t)),i=a.filter(e=>e.preferred>=0).toSorted((e,t)=>u(e)-u(t)),l=new Map,o=1/0;for(let e of s){let t=Math.min(e.preferred-e.text.height/2,o-6-e.text.height);l.set(e,t),o=t}let r=s.length?Math.max(...s.map(e=>l.get(e)+e.text.height))+6:-1/0;for(let e of i){let t=Math.max(e.preferred-e.text.height/2,r);l.set(e,t),r=t+e.text.height+6}[...s,...i].forEach(a=>{let s=l.get(a),i=s+a.text.height/2,o=180*t,r=t>0?o:o-a.text.width,n={groupIds:[`chart:slice:${a.slice.index}`]},c={x:152*Math.cos(a.slice.mid),y:152*Math.sin(a.slice.mid)},d={x:164*Math.cos(a.slice.mid),y:164*Math.sin(a.slice.mid)};e.line(`chart:leader:${a.slice.index}:a`,c,d,{strokeColor:nK,...n},"middle"),e.line(`chart:leader:${a.slice.index}:b`,d,{x:o-4*t,y:i},{strokeColor:nK,...n},"middle"),e.text(`chart:slice-label:${a.slice.index}`,a.text,r,s,14,nJ,t>0?"left":"right",n)})}}(a,t),cs(a,t,{colors:[]});else if("line"===t.kind)!function(e,t){let a,s=t.categories.length,i=nU(t.unit),l=ct(t.series.length,!1),o=cn(t.categories,Math.max(Math.min(720/s,120),36,320/s),2,400),r=t.series.flatMap(e=>e.values),n=1===t.series.length&&s<=16?t.series[0].values.map(e=>n3(nR(e,i),12)):void 0,c=(e,a,i)=>{if(!n)return;let l=t.series[0].values,r=l.map((t,a)=>({x:o*(a+.5),y:e(t)})),c=t.series.flatMap(t=>t.values.slice(1).map((a,s)=>({from:{x:o*(s+.5),y:e(t.values[s])},to:{x:o*(s+1+.5),y:e(a)}})));p.min<0&&p.max>0&&c.push({from:{x:0,y:e(0)},to:{x:o*s,y:e(0)}});let d=r.map(e=>({left:e.x-7,top:e.y-7,right:e.x+7,bottom:e.y+7})),h=[];for(let[e,t]of r.entries()){let r=n[e],p=l[e-1],g=l[e+1],u=l[e],f=(void 0===p||p<=u)&&(void 0===g||g>=u),m=(void 0===p||p>=u)&&(void 0===g||g<=u),v=(void 0===p||p<=u)&&(void 0===g||g<=u),y=r.width,w=r.height,x=(e,a)=>({left:t.x+e-y/2,top:t.y+a-w/2,right:t.x+e+y/2,bottom:t.y+a+w/2}),b=x(0,-(10+w/2)),k=x(0,10+w/2),M=x(0,-(22+w/2)),C=x(0,22+w/2),z=x(-(y/2+10),-(4+w/2)),_=x(y/2+10,-(4+w/2)),L=x(-(y/2+10),4+w/2),B=x(y/2+10,4+w/2),S=(v?[b,z,_,M,k,C]:f&&!m?[z,B,b,k,M,C]:m&&!f?[_,L,b,k,M,C]:[k,L,B,C,b,M]).find(e=>e.top>=a&&e.bottom<=i&&e.left>=0&&e.right<=o*s&&!c.some(t=>(function(e,t){let{from:a,to:s}=e,i=e=>e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom;if(i(a)||i(s))return!0;let l=[{x:t.left,y:t.top},{x:t.right,y:t.top},{x:t.right,y:t.bottom},{x:t.left,y:t.bottom}];return l.some((e,t)=>{var i;let o,r,n,c,d;return i=l[(t+1)%4],r=(o=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x))(a,s,e),n=o(a,s,i),c=o(e,i,a),d=o(e,i,s),r*n<0&&c*d<0})})(t,{left:e.left-2,top:e.top-2,right:e.right+2,bottom:e.bottom+2}))&&!d.some(t=>n6(t,e,2))&&!h.some(t=>n6(t,e,3)));if(!S)return;h.push(S)}return h},d=nI(r,!1),p=nq(d.low,d.high);for(let e=0;e<3&&n;e+=1){let t=280/(p.max-p.min),s=e=>(p.max-e)*t,i=c(s,-1/0,1/0);if(!i)break;let l=i.some(e=>e.top<0),o=i.some(e=>e.bottom>280);if(!l&&!o){a=i;break}2===e?a=c(s,0,280):p=nF(p,o,l)}let h=a?void 0:t.series.map(e=>e.values.map(e=>n3(nR(e,i),12)));h&&(o=Math.max(o,...h.flat().map(e=>e.width+8)));let g=280/(p.max-p.min),u=e=>(p.max-e)*g,f=co(p,i),m=Math.max(...f.labels.map(e=>e.width)),v=o*s;p.ticks.forEach((t,a)=>{let s=u(t),i=f.labels[a];e.line(`chart:grid:${a}`,{x:0,y:s},{x:v,y:s},{strokeColor:nQ}),e.text(`chart:tick:${a}`,i,-8-i.width,s-i.height/2,13,nK,"right")}),p.min<0&&p.max>0&&e.line("chart:baseline",{x:0,y:u(0)},{x:v,y:u(0)},{strokeColor:n1,strokeWidth:2},"middle"),e.line("chart:axis",{x:0,y:280},{x:v,y:280},{strokeColor:n1},"middle");let y=280;if(t.categories.forEach((t,a)=>{let s=o*(a+.5);e.line(`chart:category-tick:${a}`,{x:s,y:280},{x:s,y:285},{strokeColor:n1},"middle");let i=n5(t,o-10,14),l=e.text(`chart:category:${a}`,i,s-i.width/2,289,14,nJ);y=Math.max(y,l.bottom)}),t.series.forEach((a,s)=>{let r=l[s],n={groupIds:[`chart:series:${s}`]};a.values.slice(1).forEach((t,i)=>e.line(`chart:line:${s}:${i+1}`,{x:o*(i+.5),y:u(a.values[i])},{x:o*(i+1+.5),y:u(t)},{strokeColor:r,strokeWidth:2,...n},"middle")),a.values.forEach((a,l)=>{let c=nR(a,i);ci(e,`chart:point:${l}:${s}`,s,o*(l+.5),u(a),r,`${t.categories[l]} \xb7 ${cl(t,s)}: ${c}`,n)})}),h){let a=y+12,s=t.series.map(e=>e.name?n5(e.name,200,12):void 0),i=-10-Math.max(0,...s.map(e=>e?e.width+6:0));h.forEach((r,n)=>{let c=t.series[n],d=l[n],p={groupIds:[`chart:table:${n}`]},h=s[n],g=Math.max(r[0].height,h?.height??0),u=a+g/2;e.line(`chart:table-key:${n}:line`,{x:i-22,y:u},{x:i,y:u},{strokeColor:d,strokeWidth:2,...p},"middle"),ci(e,`chart:table-key:${n}`,n,i-11,u,d,c.name??t.title,p),h&&e.text(`chart:table-name:${n}`,h,i+6,a+(g-h.height)/2,12,nJ,"left",p),r.forEach((t,s)=>e.text(`chart:table:${s}:${n}`,t,o*(s+.5)-t.width/2,a+(g-t.height)/2,12,nK,"center",p)),a+=g+4}),y=a-4}if(a?.forEach((t,a)=>e.text(`chart:value:${a}:0`,n[a],t.left,t.top,12,nK,"center",{groupIds:["chart:series:0"]})),t.valueAxisTitle){let a=n5(t.valueAxisTitle,Math.max(v+m,200),14),s=f.labels[f.labels.length-1];e.text("chart:value-axis-title",a,-8-m,-s.height/2-8-a.height,14,nK,"left")}if(t.categoryAxisTitle){let a=n5(t.categoryAxisTitle,Math.max(v,200),14);e.text("chart:category-axis-title",a,(v-a.width)/2,y+12,14,nK)}}(a,t),cs(a,t,{legend:"line",colors:ct(t.series.length,!1)});else{let e=cr(t);"horizontal"===function(e){if(e.orientation)return e.orientation;let t=cc(cr(e)),a=cn(e.categories,t.band,2,161);return a>160||a*e.categories.length>960?"horizontal":"vertical"}(t)?function(e,t){let{diagram:a,stacked:s,colors:i}=t,l=s?1:a.series.length,o=n3("0",12).height,r=1===l?24:Math.max(o-2,Math.round(44/l)),n=l*r+(l-1)*2,c=Math.min(220,Math.max(...a.categories.map(e=>n3(e,14).width))),d=a.categories.map(e=>n5(e,c,14)),p=s?t.totals.flatMap(e=>[e.up,e.down].filter(e=>void 0!==e)):t.labels.flat(),h=e=>(t,a)=>p.some(s=>"up"===e==s.value>=0&&("up"===e?(t.max-s.value)*a:(s.value-t.min)*a)<s.text.width+4+4),g=cd(t.domain,480,h("up"),h("down"));for(let e=4;e>=2;e-=1){let a=co(g,t.parts);if(480/(g.max-g.min)*g.step>=Math.max(...a.labels.map(e=>e.width))+12)break;g=cd(t.domain,480,h("up"),h("down"),e)}let u=e=>{let s=480/(e.max-e.min),i=t=>(t-e.min)*s;return a.categories.map((e,s)=>{let l=0,o=0;return a.series.map((e,a)=>{let{value:n,text:c}=t.labels[s][a],d=n>=0?l:o,p=d+n;n>=0?l=p:o=p;let h=i(Math.min(d,p)),g=i(Math.max(d,p));g-h<.5&&(n>=0?g=h+.5:h=g-.5);let u=g-h>=c.width+6&&r>=c.height+1;return{s:a,value:n,text:c,left:h,right:g,inside:u}})})};for(let e=0;s&&e<6;e+=1){let e=-g.min/(g.max-g.min)*480,t=Math.max(0,...u(g).map(e=>e.filter(e=>!e.inside&&e.value<0).reduce((e,t)=>e+t.text.width+6,0)));if(0===t||t<=e-2)break;g=nF(g,!0,!1)}let f=480/(g.max-g.min),m=e=>(e-g.min)*f,v=u(g),y=s&&v.flat().some(e=>!e.inside)?o+10:0,w=Math.max(n+14,...d.map(e=>e.height+8))+y,x=co(g,t.parts),b=w*a.categories.length;g.ticks.forEach((t,a)=>{let s=m(t),i=x.labels[a];e.line(`chart:grid:${a}`,{x:s,y:0},{x:s,y:b},{strokeColor:nQ}),e.text(`chart:tick:${a}`,i,s-i.width/2,b+6,13,nK)});let k=m(0);e.line("chart:baseline",{x:k,y:0},{x:k,y:b},{strokeColor:n1,strokeWidth:2},"middle"),a.categories.forEach((l,o)=>{let c=w*o+(w-y)/2,p=d[o];e.text(`chart:category:${o}`,p,-10-p.width,c-p.height/2,14,nJ,"right");let h=c-n/2;if(a.series.forEach((n,c)=>{let d,p,{value:g,text:u}=t.labels[o][c],f=i[c],y=`chart:bar:${o}:${c}`,w={groupIds:[s?`chart:stack:${o}`:y]},x=s?h:h+c*(r+2);s?{left:d,right:p}=v[o][c]:(d=m(Math.min(0,g)),(p=m(Math.max(0,g)))-d<.5&&(g>=0?p=d+.5:d=p-.5));let b=`${l} \xb7 ${cl(a,c)}: ${u.text}`;if(0!==g&&e.mark(y,"rectangle",{x:d,y:x,width:p-d,height:r},b,s?{fillColor:f,strokeColor:e.surface,strokeWidth:2,...w}:{fillColor:f,strokeColor:f,...w}),s){v[o][c].inside&&e.text(`chart:value:${o}:${c}`,u,(d+p-u.width)/2,x+(r-u.height)/2,12,ce(f),"center",w);return}let k=g>=0?p+4:d-4-u.width;e.text(`chart:value:${o}:${c}`,u,k,x+(r-u.height)/2,12,nK,g>=0?"left":"right",w)}),s){let a=t.totals[o],s={groupIds:[`chart:stack:${o}`]};a.up&&e.text(`chart:total:${o}`,a.up.text,m(a.up.value)+4,c-a.up.text.height/2,12,nJ,"left",s),a.down&&e.text(`chart:total-negative:${o}`,a.down.text,m(a.down.value)-4-a.down.text.width,c-a.down.text.height/2,12,nJ,"right",s);let i=v[o].filter(e=>!e.inside),l=h+n,r=l+7,d=new Map;for(let e of[!0,!1]){let t=i.filter(t=>t.value>=0===e);n7(t.map(e=>({preferred:(e.left+e.right)/2,size:e.text.width})),e?k+2:0,e?1/0:k-2,6).forEach((e,a)=>d.set(t[a],e))}i.forEach(t=>{let a=d.get(t),i=(t.left+t.right)/2,n={strokeColor:nK,...s};e.line(`chart:leader:${o}:${t.s}:a`,{x:i,y:l+1},{x:i,y:l+3},n,"middle"),e.line(`chart:leader:${o}:${t.s}:b`,{x:i,y:l+3},{x:a+t.text.width/2,y:r-1},n,"middle"),e.text(`chart:value:${o}:${t.s}`,t.text,a,r,12,nK,"center",s)})}});let M=x.labels[0].height;if(a.valueAxisTitle){let t=n5(a.valueAxisTitle,480,14);e.text("chart:value-axis-title",t,(480-t.width)/2,b+6+M+10,14,nK)}if(a.categoryAxisTitle){let t=n5(a.categoryAxisTitle,Math.max(c,160),14);e.text("chart:category-axis-title",t,-10-t.width,-8-t.height,14,nK,"right")}}(a,e):function(e,t){let{diagram:a,stacked:s,colors:i}=t,l=a.categories.length,o=cc(t),r="vertical"===a.orientation,n=n3("0",12).height+4+2,c=a.categories.map((e,t)=>t),d=cd(t.domain,300,(e,a)=>c.some(i=>(s?void 0!==t.totals[i].up:t.labels[i].some(e=>e.value>=0))&&(e.max-(s?t.totals[i].up?.value??0:Math.max(0,...t.labels[i].map(e=>e.value))))*a<n),(e,a)=>c.some(i=>(s?void 0!==t.totals[i].down:t.labels[i].some(e=>e.value<0))&&((s?t.totals[i].down?.value??0:Math.min(0,...t.labels[i].map(e=>e.value)))-e.min)*a<n)),p=e=>{let s=300/(e.max-e.min),i=t=>(e.max-t)*s;return a.categories.map((e,s)=>{let l=0,r=0;return a.series.map((e,a)=>{let{value:n,text:c}=t.labels[s][a],d=n>=0?l:r,p=d+n;n>=0?l=p:r=p;let h=i(Math.max(d,p)),g=i(Math.min(d,p));g-h<.5&&(n>=0?h=g-.5:g=h+.5);let u=g-h>=c.height+1&&c.width+6<=o.thickness;return{s:a,value:n,text:c,top:h,bottom:g,inside:u}})})};for(let e=0;s&&e<6;e+=1){let e=p(d),t=d.max/(d.max-d.min)*300,a=t=>Math.max(0,...e.map(e=>e.filter(e=>!e.inside&&e.value>=0===t).reduce((e,t)=>e+t.text.height+2,0))),s=a(!0)>0&&a(!0)>t-2,i=a(!1)>0&&a(!1)>300-t-2;if(!s&&!i)break;d=nF(d,i,s)}let h=300/(d.max-d.min),g=e=>(d.max-e)*h,u=p(d),f=e=>Math.max(o.thickness,t.totals[e].up?.text.width??0,t.totals[e].down?.text.width??0)/2,m=s?Math.max(0,...u.flat().flatMap(e=>e.inside?[]:[e.text.width])):0,v=Math.max(cn(a.categories,o.band,r?3:2,r?200:161),320/l,m>0?2*Math.max(...c.map(f))+10+m+6:0),y=co(d,t.parts),w=Math.max(...y.labels.map(e=>e.width)),x=v*l;d.ticks.forEach((t,a)=>{let s=g(t),i=y.labels[a];e.line(`chart:grid:${a}`,{x:0,y:s},{x:x,y:s},{strokeColor:nQ}),e.text(`chart:tick:${a}`,i,-8-i.width,s-i.height/2,13,nK,"right")});let b=g(0);e.line("chart:baseline",{x:0,y:b},{x:x,y:b},{strokeColor:n1,strokeWidth:2},"middle");let k=o.bars*o.thickness+(o.bars-1)*2,M=300;if(a.categories.forEach((l,r)=>{let n=0+v*(r+.5),c=n-k/2,d=n5(l,v-10,14),p=e.text(`chart:category:${r}`,d,n-d.width/2,308,14,nJ);if(M=Math.max(M,p.bottom),a.series.forEach((n,d)=>{let p,h,{value:f,text:m}=t.labels[r][d],v=i[d],y=`chart:bar:${r}:${d}`,w={groupIds:[s?`chart:stack:${r}`:y]},x=s?c:c+d*(o.thickness+2);s?{top:p,bottom:h}=u[r][d]:(p=g(Math.max(0,f)),(h=g(Math.min(0,f)))-p<.5&&(f>=0?p=h-.5:h=p+.5));let b=`${l} \xb7 ${cl(a,d)}: ${m.text}`;if(0!==f&&e.mark(y,"rectangle",{x:x,y:p,width:o.thickness,height:h-p},b,s?{fillColor:v,strokeColor:e.surface,strokeWidth:2,...w}:{fillColor:v,strokeColor:v,...w}),s){u[r][d].inside&&e.text(`chart:value:${r}:${d}`,m,x+(o.thickness-m.width)/2,(p+h-m.height)/2,12,ce(v),"center",w);return}let k=f>=0?p-4-m.height:h+4;e.text(`chart:value:${r}:${d}`,m,x+(o.thickness-m.width)/2,k,12,nK,"center",w)}),s){let t=u[r].filter(e=>!e.inside),a=n+f(r)+10,s=new Map;for(let e of[!0,!1]){let a=t.filter(t=>t.value>=0===e);n7(a.map(e=>({preferred:(e.top+e.bottom)/2,size:e.text.height})),e?0:b+2,e?b-2:300,2).forEach((e,t)=>s.set(a[t],e))}let i={groupIds:[`chart:stack:${r}`]};t.forEach(t=>{let l=s.get(t),n=(t.top+t.bottom)/2,d={strokeColor:nK,...i};e.line(`chart:leader:${r}:${t.s}:a`,{x:c+o.thickness+1,y:n},{x:a-4,y:n},d,"middle"),e.line(`chart:leader:${r}:${t.s}:b`,{x:a-4,y:n},{x:a-1,y:l+t.text.height/2},d,"middle"),e.text(`chart:value:${r}:${t.s}`,t.text,a,l,12,nK,"left",i)})}if(s){let a=t.totals[r],s={groupIds:[`chart:stack:${r}`]};a.up&&e.text(`chart:total:${r}`,a.up.text,n-a.up.text.width/2,g(a.up.value)-4-a.up.text.height,12,nJ,"center",s),a.down&&e.text(`chart:total-negative:${r}`,a.down.text,n-a.down.text.width/2,g(a.down.value)+4,12,nJ,"center",s)}}),a.valueAxisTitle){let t=n5(a.valueAxisTitle,Math.max(x+w,200),14),s=y.labels[y.labels.length-1];e.text("chart:value-axis-title",t,-8-w,-s.height/2-8-t.height,14,nK,"left")}if(a.categoryAxisTitle){let t=n5(a.categoryAxisTitle,Math.max(x,200),14);e.text("chart:category-axis-title",t,(0+x-t.width)/2,M+12,14,nK)}}(a,e),cs(a,t,{legend:"bar",colors:e.colors})}a.breakRulesUnderText(e=>e.startsWith("chart:grid:")||e.startsWith("chart:category-tick:")||"chart:baseline"===e||"chart:axis"===e);let s=a.bounds(),i=40-s.left,l=40-s.top,o=a.elements.map(e=>{if("line"===e.type){let[t,a,...s]=e.points.map(e=>({x:n4(e.x+i),y:n4(e.y+l)}));return{...e,points:[t,a,...s]}}return"arrow"===e.type?e:{...e,x:n4(e.x+i),y:n4(e.y+l)}});return{kind:"canvas",version:1,diagramId:t.id,title:t.title,width:Math.ceil(s.right-s.left+80),height:Math.ceil(s.bottom-s.top+80),accentColor:t.style.accentColor,backgroundColor:t.style.backgroundColor,elements:o,layers:[],layouts:[],zOrder:a.zOrder()}})(u3(u)),catch:e=>new fb({status:"render_failed",context:{...w,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:u.id},message:e instanceof Error?e.message:"Unable to render chart scene.",hint:"Repair the categories and series values and retry."})]}})}).pipe(o.fRP("codeMode.buildChart.render")),b=se(x);if(b.length>0)return yield*new fb({status:"render_failed",context:{...w,issues:f$(b).map(e=>({...e,hint:"Use fewer categories or series and retry buildChart."}))}});let k={...w,partial:ma(x)},M=yield*ml({scene:x,formats:fU(h.options),inlineFormats:fX(h.options),...h.requestId?{requestId:h.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fb({status:e.status,context:{..."export_failed"===e.status?k:w,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:g,...mt(h.requestId),normalizedSpec:u,quality:v,artifact:M,issues:[]}}),mu=o.fn("codeMode.buildGantt.workflow")(function*(e){var t,a,s;let l,r,n=i.q$Z(lQ,{errors:"all",reportInput:!0})(e);if(!um.oJ(n))return yield*new fk({status:"invalid_input",context:{issues:fF(s9(n.failure))}});let c=yield*uQ,d=n.success,p=yield*o.OH5(()=>c.createId("build")),h=(l=s5((t=d.spec).title),{id:fE(t.id)??(fI(l)||"sketchi-gantt"),title:l,tasks:t.tasks.map(e=>{let t=fE(e.phase);return{...e,id:s5(e.id),label:s5(e.label),start:s5(e.start),...void 0!==e.end?{end:s5(e.end)}:{},...void 0!==t?{phase:t}:{},...e.dependsOn?{dependsOn:e.dependsOn.map(s5)}:{}}}),...t.phases?{phases:t.phases.map(s5)}:{},...t.today?{today:s5(t.today)}:{},style:{...y}}),g={buildId:p,...mt(d.requestId),normalizedSpec:h},u=tp(u5(h)).map(e=>fB({code:u4[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(u.length>0)return yield*new fk({status:"invalid_gantt",context:{...g,issues:u}});let f={accepted:10>=(a=d.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:h.tasks.length,edgeCount:h.tasks.reduce((e,t)=>e+(t.dependsOn?.length??0),0)},checks:[]},m={...g,quality:f};if(!f.accepted)return yield*new fk({status:"quality_failed",context:{...m,issues:fO(f)}});let v=yield*o.SvU({try:()=>(function(e){let t=tg(e),a=c4(t,44),s=a.work;for(let e of cG){if(0===a.work.conflicts||a.work.conflicts>4)break;let i=c4(t,44+e);s={layouts:s.layouts+1,placements:s.placements+i.work.placements,expansions:s.expansions+i.work.expansions,corridors:i.work.corridors,conflicts:i.work.conflicts},i.work.conflicts<a.work.conflicts&&(a=i)}return{scene:a.scene,work:{...s,corridors:a.work.corridors,conflicts:a.work.conflicts}}})(u5(h)).scene,catch:e=>new fk({status:"render_failed",context:{...m,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:h.id},message:e instanceof Error?e.message:"Unable to render Gantt scene.",hint:"Repair the tasks' dates and dependencies and retry."})]}})}).pipe(o.fRP("codeMode.buildGantt.render")),w=se(v);if(w.length>0)return yield*new fk({status:"render_failed",context:{...m,issues:f$(w).map(e=>({...e,hint:"Use fewer tasks or dependencies and retry buildGantt."}))}});let x={...m,partial:ma(v)},b=yield*ml({scene:v,formats:fU(d.options),inlineFormats:fX(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fk({status:e.status,context:{..."export_failed"===e.status?x:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:p,...mt(d.requestId),normalizedSpec:h,quality:f,artifact:b,issues:(r=new Map((s=u5(h)).tasks.map(e=>[e.id,e])),s.tasks.flatMap((e,t)=>{let a=tr(e);return(e.dependsOn??[]).flatMap((s,i)=>{let l=r.get(s),o=l&&tr(l);if(!a||!o)return[];let n=o.milestone?o.start:o.end-!!a.milestone;return a.start>=n?[]:[{task:e.id,dependsOn:s,finishes:tl(o.milestone?o.start:o.end-1),path:`tasks.[${t}].dependsOn.[${i}]`}]})})).map(e=>fB({code:"gantt_schedule_conflict",severity:"warning",stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:`Task "${e.task}" starts before "${e.dependsOn}" finishes on ${e.finishes}.`,hint:`Keep dates the prompt states; otherwise start "${e.task}" after ${e.finishes}.`}))}}),mf=i._kM({spec:i.$r1,requestId:i.Qrq(i.$r1)}),mm=i._kM({source:i._kM({scene:i.$r1})}),mv=o.fn("codeMode.canvas.serializedLimit")((e,t)=>o.SvU(()=>rQ(e)).pipe(o.YWq({onFailure:()=>fB({code:"invalid_type",stage:"input",ref:{kind:"request",path:t},message:"CanvasSpec could not be serialized as JSON.",hint:"Remove non-JSON values or reduce deeply nested fields and retry."}),onSuccess:e=>e<=aU.maxSerializedBytes?void 0:fB({code:"canvas_limit_exceeded",stage:"canvas",ref:{kind:"request",path:t},message:`CanvasSpec exceeds ${aU.maxSerializedBytes} serialized bytes.`,hint:"Split the visualization into a smaller canvas or reduce repeated text and points."})}))),my=o.fn("codeMode.createCanvas.workflow")(function*(e){let t=yield*uQ,a=yield*o.OH5(()=>t.createId("build")),s=i.q$Z(mf)(e),l=um.oJ(s)?{spec:s.success.spec,requestId:i.is(i.QfV)(s.success.requestId)?s.success.requestId:void 0}:void 0;if(l){let e=yield*mv(l.spec,"spec");if(e)return yield*new fM({status:"canvas_limit_exceeded"===e.code?"limit_exceeded":"invalid_input",context:{buildId:a,...mt(l.requestId),issues:[e]}})}let r=i.q$Z(oV,{errors:"all",reportInput:!0})(e);if(!um.oJ(r))return yield*new fM({status:"invalid_input",context:{issues:fF(s9(r.failure))}});let n=r.success,c={buildId:a,...mt(n.requestId)},d=fD(n.spec);if(!d)return yield*new fM({status:"invalid_canvas",context:{...c,issues:[fB({code:"invalid_canvas_geometry",stage:"canvas",ref:{kind:"request",path:"spec.elements"},message:"CanvasSpec contains an invalid point list.",hint:"Provide at least two points for lines/connectors and three points for polygons."})]}});let p=se(d).filter(e=>"limit_exceeded"===e.code);if(p.length>0)return yield*new fM({status:"limit_exceeded",context:{...c,issues:f$(p)}});let h=yield*uU(function(e){let t=[...e.elements];for(let a of e.layouts)t=function(e,t){switch(t.type){case"row":case"column":case"stack":return function(e,t){let a=sa(e,t.ids),s=a[0];if(!s)return[...e];let i=st(s),l=t.x??i.x,o=t.y??i.y,r="stack"===t.type?t.gap??0:t.gap??32,n=new Map,c="column"===t.type?o:l;for(let e of a){let a=st(e);n.set(e.id,{x:"column"===t.type||"stack"===t.type?l:c,y:"column"===t.type?c:o}),"stack"!==t.type&&(c+=("column"===t.type?a.height:a.width)+r)}return ss(e,n)}(e,t);case"grid":return function(e,t){let a=sa(e,t.ids);if(0===a.length)return[...e];let s=Math.max(1,Math.floor(t.columns)),i=a.map(st),l=Array.from({length:s},(e,t)=>Math.max(0,...i.filter((e,a)=>a%s===t).map(e=>e.width))),o=Array.from({length:Math.ceil(a.length/s)},(e,t)=>Math.max(0,...i.filter((e,a)=>Math.floor(a/s)===t).map(e=>e.height))),r=i[0];if(!r)return[...e];let n=t.x??r.x,c=t.y??r.y,d=t.columnGap??32,p=t.rowGap??32,h=new Map;return a.forEach((e,t)=>{let a=t%s,i=Math.floor(t/s);h.set(e.id,{x:n+l.slice(0,a).reduce((e,t)=>e+t,0)+d*a,y:c+o.slice(0,i).reduce((e,t)=>e+t,0)+p*i})}),ss(e,h)}(e,t);case"align":return function(e,t){let a=sa(e,t.ids);if(0===a.length)return[...e];let s=a.map(st),i=s.map(e=>si(e,t.axis)),l=s.map(e=>si(e,t.axis)+sl(e,t.axis)),o=s.map(e=>si(e,t.axis)+sl(e,t.axis)/2),r="start"===t.alignment?Math.min(...i):"end"===t.alignment?Math.max(...l):o.reduce((e,t)=>e+t,0)/o.length,n=new Map;return a.forEach((e,a)=>{let i=s[a];if(!i)return;let l="start"===t.alignment?r:"end"===t.alignment?r-sl(i,t.axis):r-sl(i,t.axis)/2;n.set(e.id,{x:"x"===t.axis?l:i.x,y:"y"===t.axis?l:i.y})}),ss(e,n)}(e,t);case"distribute":return function(e,t){let a=sa(e,t.ids).sort((e,a)=>si(st(e),t.axis)-si(st(a),t.axis));if(a.length<2)return[...e];let s=a.map(st),i=s[0],l=s[s.length-1];if(!i||!l)return[...e];let o=si(i,t.axis),r=si(l,t.axis)+sl(l,t.axis),n=s.reduce((e,a)=>e+sl(a,t.axis),0),c=t.gap??Math.max(0,(r-o-n)/(a.length-1)),d=new Map,p=o;return a.forEach((e,a)=>{let i=s[a];i&&(d.set(e.id,{x:"x"===t.axis?p:i.x,y:"y"===t.axis?p:i.y}),p+=sl(i,t.axis)+c)}),ss(e,d)}(e,t)}}(t,a);let a=function(e){let t=1,a=1;for(let s of e)if(a0(s)){let e=st(s);t=Math.max(t,e.x+e.width),a=Math.max(a,e.y+e.height)}else if("arrow"===s.type||"line"===s.type)for(let e of s.points)t=Math.max(t,e.x),a=Math.max(a,e.y);return{width:t+48,height:a+48}}(t=function(e){let t=sd(e),a=new Map;for(let t of e)("node"===t.type||"frame"===t.type)&&a.set(t.id,t);let s=e.map(e=>{if("arrow"===e.type){let a=t.get(e.sourceNodeId),s=t.get(e.targetNodeId);if(!a||!s)return e;if(e.curved){let t=e.points[0],i=e.points[e.points.length-1]??t;return sn(t,a)&&sn(i,s)?e:{...e,points:sc(a,s)}}return{...e,points:[sr(a,so(s)),...e.points.slice(1,-1),sr(s,so(a))]}}if("line"===e.type){let t=e.startBinding?a.get(e.startBinding.elementId):void 0,s=e.endBinding?a.get(e.endBinding.elementId):void 0;if(!t&&!s)return e;let i=[e.points[0],e.points[1],...e.points.slice(2)];return t&&(i[0]=sr(t,s?so(s):i[i.length-1]??i[0])),s&&(i[i.length-1]=sr(s,t?so(t):i[0])),{...e,points:i}}return e}),i=new Map(s.map(e=>[e.id,e]));return s.map(e=>{if("text"!==e.type||!e.containerId)return e;let t=i.get(e.containerId);if(t?.type==="node"){let a=so(t);return{...e,x:a.x,y:a.y}}if(t?.type==="arrow"){let a=t.points[0],s=t.points[t.points.length-1]??a;return{...e,x:(a.x+s.x)/2,y:(a.y+s.y)/2}}return e})}(t)),s=e.zOrder.length?[...e.zOrder]:t.map((e,t)=>({element:e,index:t})).sort((e,t)=>(e.element.zIndex??e.index)-(t.element.zIndex??t.index)).map(({element:e})=>e.id);return{...e,width:Math.max(e.width,a.width),height:Math.max(e.height,a.height),elements:t,zOrder:s}}(d),t.icons),g=h.scene,u=fR(g),f=se(g);if(f.length>0){let e=f$(f);return yield*new fM({status:e.some(e=>"canvas_limit_exceeded"===e.code)?"limit_exceeded":"invalid_canvas",context:{...c,normalizedSpec:u,issues:[...h.issues,...e]}})}let m={...c,normalizedSpec:u,partial:ma(g)},v=yield*ml({scene:g,formats:fU(n.options),inlineFormats:fX(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:fG}).pipe(o.xm_(e=>new fM({status:e.status,context:{...m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:a,...mt(n.requestId),normalizedSpec:u,artifact:v,issues:h.issues}}),mw=o.fn("codeMode.buildFlowchart.workflow")(function*(e){var t,a;let s,l=i.q$Z(lZ,{errors:"all",reportInput:!0})(function(e){if(!uR(e))return e;let{spec:t}=e;if(!uR(t)||!Array.isArray(t.nodes))return e;let a=t.nodes,s=!1,i=Array.isArray(t.edges)?t.edges:void 0,l=i?.map(e=>{if(!uR(e)||void 0!==e.source&&void 0!==e.target||void 0===e.from&&void 0===e.to)return e;s=!0;let{from:t,to:a,...i}=e;return{...i,source:e.source??t,target:e.target??a}}),o=(l??[]).filter(uR),r=new Map,n=e=>{let t=r.get(e);return t||r.set(e,t={incoming:0,outgoing:0,labeledOutgoing:0}),t};for(let e of o){let t=n(e.source);t.outgoing+=1,"string"==typeof e.label&&""!==e.label.trim()&&(t.labeledOutgoing+=1),n(e.target).incoming+=1}let c=a.filter(uR).filter(e=>0===n(e.id).incoming),d=a.map(e=>uR(e)?(e=>{let t=e.kind??e.type,{incoming:a,outgoing:s,labeledOutgoing:i}=n(e.id),l="string"==typeof e.label&&s5(e.label).endsWith("?");if("string"==typeof t){let i=t.trim().toLowerCase().replace(/[\s_-]+/g,""),l=uG[i];if(l)return l;if(uD.has(i)){if(0===a&&s>0)return"start";if(0===s&&a>0)return"end"}return e.kind}return void 0!==t?e.kind:0===s&&a>0?"end":0===a&&1===c.length&&0===i?"start":a>0&&1===s&&0===i&&!l?"process":void 0})(e):void 0),p=a.some((e,t)=>uR(e)&&"end"===d[t]&&n(e.id).incoming>0&&0===n(e.id).outgoing),h=new Set(a.flatMap((e,t)=>uR(e)&&"decision"===d[t]?[e.id]:[])),g=new Set(o.filter(e=>h.has(e.source)&&"string"==typeof e.label&&""!==e.label.trim()).map(e=>e.target)),u=a.map((e,t)=>{if(!uR(e))return e;let a=d[t],i="string"==typeof e.label&&s5(e.label).endsWith("?");if("process"===a&&p&&g.has(e.id)&&0===n(e.id).outgoing&&!i&&(a="end"),a===e.kind)return e;s=!0;let{type:l,...o}=e;return{...o,kind:a}});return s?{...e,spec:{...t,nodes:u,...l?{edges:l}:{}}}:e}(e));if(!um.oJ(l))return yield*new fg({status:"invalid_input",context:{issues:fF(s9(l.failure),fq)}});let r=yield*uQ,n=l.success,c=yield*o.OH5(()=>r.createId("build")),d=(s=s5((a=n.spec).title),{id:u$(a.id)??(s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"sketchi-flowchart"),title:s,nodes:a.nodes.map(e=>({id:s5(e.id),label:s5(e.label),kind:e.kind,...e.description?{description:s5(e.description)}:{},...e.icon?{icon:{slug:s5(e.icon.slug)}}:{},...e.group?{group:s5(e.group)}:{},...e.lane?{lane:s5(e.lane)}:{},...e.shape?{shape:e.shape}:{}})),edges:a.edges.map((e,t)=>({id:u$(e.id)??`edge-${t+1}`,source:s5(e.source),target:s5(e.target),...e.label?{label:s5(e.label)}:{}})),...a.groups?{groups:a.groups.map(e=>({id:s5(e.id),label:s5(e.label),...e.parent?{parent:s5(e.parent)}:{},...e.kind?{kind:e.kind}:{}}))}:{},...a.lanes?{lanes:a.lanes.map(e=>({id:s5(e.id),label:s5(e.label)}))}:{},layout:{direction:a.layout.direction},style:{...y}}),p=uO(d.nodes,r.icons),h={...d,nodes:p.nodes},g={buildId:c,...mt(n.requestId),normalizedSpec:h},u=i.q$Z(ey,{errors:"all",reportInput:!0})({id:h.id,title:h.title,type:"flowchart",nodes:h.nodes.map(e=>({...e,metadata:{}})),edges:h.edges.map(e=>({...e,metadata:{}})),...h.groups?{groups:h.groups.map(e=>({...e}))}:{},...h.lanes?{lanes:h.lanes.map(e=>({...e}))}:{},layout:{direction:h.layout.direction,edgeRouting:"orthogonal"},style:h.style,metadata:{}});if(!um.oJ(u))return yield*new fg({status:"invalid_flowchart",context:{...g,issues:(t=s9(u.failure),t.issues.slice(0,20).map(e=>{let t=function(e,t){let a=fS(e.path),s="input"===a?"spec":`spec.${a}`,[i,l]=e.path;if("nodes"===i&&"number"==typeof l){let e=t.nodes[l]?.id;return{kind:"node",...e?{id:e}:{},path:s}}if("edges"===i&&"number"==typeof l){let e=t.edges[l]?.id;return{kind:"edge",...e?{id:e}:{},path:s}}if("groups"===i&&"number"==typeof l){let e=t.groups?.[l]?.id;return{kind:"group",...e?{id:e}:{},path:s}}if("lanes"===i&&"number"==typeof l){let e=t.lanes?.[l]?.id;return{kind:"lane",...e?{id:e}:{},path:s}}return{kind:"diagram",id:t.id,path:s}}(e,h);return fB({code:fA(e),stage:"flowchart",ref:t,message:e.message,hint:`Fix ${t.path??"spec"} so normalization produces a valid canonical flowchart value.`})}))}});let f=u.success,m=eb(f).map(e=>{let t=function(e){if(e)return{kind:e.kind,...e.id?{id:e.id}:{},...e.path?{path:`spec.${e.path}`}:{}}}(e.ref);return fB({code:e.code,stage:"flowchart",...t?{ref:t}:{},message:e.message,hint:e.hint})});if(m.length>0)return yield*new fg({status:"invalid_flowchart",context:{...g,issues:m}});eM(f);let v=function(e,t){let a=[],s=0,i=(e,t,i,l=!1)=>{s+=e,a.push({...i,passed:!1,severity:l?"error":"warning",message:t})},l=new Map,o=new Map;for(let t of e.edges)l.set(t.source,(l.get(t.source)??0)+1),l.set(t.target,(l.get(t.target)??0)+1),o.set(t.source,[...o.get(t.source)??[],t]);if(e.nodes.length>1&&0===e.edges.length)i(5,"no edges at all — every node floats unconnected",{code:"disconnected_graph",refs:uY(e.nodes)},!0);else{let t=e.nodes.filter(e=>(l.get(e.id)??0)===0);t.length>0&&e.nodes.length>1&&i(Math.min(1.5*t.length,4.5),`unconnected node(s): ${t.map(e=>e.id).join(", ")}`,{code:"disconnected_graph",refs:uY(t)},!0);let a=function(e){let t=new Map;for(let a of e.nodes)t.set(a.id,[]);for(let a of e.edges)t.get(a.source)?.push(a.target),t.get(a.target)?.push(a.source);let a=new Set,s=0;for(let i of e.nodes){if(a.has(i.id))continue;s+=1;let e=[i.id];for(a.add(i.id);e.length>0;){let s=e.pop();if(void 0===s)break;for(let i of t.get(s)??[])a.has(i)||(a.add(i),e.push(i))}}return s}(e);a>1&&0===t.length&&i(2,`diagram splits into ${a} disconnected islands`,{code:"disconnected_graph",refs:uY(e.nodes)},!0)}e.nodes.length<3?i(2,"too sparse — a useful flow needs at least 3 nodes",{code:"graph_too_sparse",refs:[{kind:"diagram",id:e.id,path:"spec.nodes"}]}):e.nodes.length>24&&i(2,"too dense — trim or merge nodes (24 max)",{code:"graph_too_dense",refs:[{kind:"diagram",id:e.id,path:"spec.nodes"}]});let r=new Map;for(let t of e.nodes){let e=t.label.trim().toLowerCase();r.set(e,(r.get(e)??0)+1)}let n=[...r.entries()].filter(([,e])=>e>1);n.length>0&&i(Math.min(n.length,3),`duplicate label(s): ${n.map(([e])=>`"${e}"`).join(", ")}`,{code:"duplicate_label",refs:uY(e.nodes.filter(e=>(r.get(e.label.trim().toLowerCase())??0)>1))});let c=0,d=0;for(let t of e.nodes){if("decision"!==t.kind){t.label.endsWith("?")&&i(0,`question label on non-decision node "${t.id}"; use kind "decision" only for branch points`,{code:"question_label_not_decision",refs:uY([t])});continue}let e=o.get(t.id)??[];e.length<2?(c+=1,i(0,`decision "${t.id}" needs at least 2 outgoing branches`,{code:"underbranched_decision",refs:uY([t])},!0)):e.some(e=>!e.label)&&(d+=1,i(0,`label every branch out of decision "${t.id}" (yes/no, …)`,{code:"unlabeled_decision_branch",refs:uY([t])}))}s+=Math.min(1.5*c,4.5)+Math.min(d,3);let p=e.nodes.filter(e=>e.label.length>42);p.length>0&&i(Math.min(.5*p.length,2),`shorten label(s): ${p.map(e=>e.id).join(", ")}`,{code:"label_too_long",refs:uY(p)});let h=e.nodes.filter(e=>uX.test(e.label.trim()));h.length>0&&i(Math.min(h.length,3),`generic label(s) say nothing: ${h.map(e=>`"${e.label}"`).join(", ")}`,{code:"generic_label",refs:uY(h)}),(e.title.trim().length<4||uT.test(e.title.trim()))&&i(.5,"give the diagram a specific title",{code:"weak_title",refs:[{kind:"diagram",id:e.id,path:"spec.title"}]});let g=Math.max(0,Math.round((10-s)*10)/10);return{accepted:g>=t&&!a.some(e=>"error"===e.severity),score:g,threshold:t,summary:{nodeCount:e.nodes.length,edgeCount:e.edges.length},checks:a}}(f,n.options?.minQualityScore??8),w={...g,quality:v};if(!v.accepted)return yield*new fg({status:"quality_failed",context:{...w,issues:fO(v)}});let x=yield*o.SvU({try:()=>hS(U(f)),catch:e=>new fg({status:"render_failed",context:{...w,issues:[fB({code:"render_failed",stage:"render",ref:{kind:"diagram",id:h.id},message:e instanceof Error?e.message:"Unable to render flowchart scene.",hint:"Simplify the graph or retry with a smaller flowchart."})]}})}).pipe(o.fRP("codeMode.buildFlowchart.render")),b=yield*uU(x,r.icons),k=b.scene,M={...w,partial:ma(k)},C=yield*ml({scene:k,formats:fU(n.options),inlineFormats:fX(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:fY}).pipe(o.xm_(e=>new fg({status:e.status,context:{..."export_failed"===e.status?M:w,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...mt(n.requestId),normalizedSpec:h,quality:v,artifact:C,issues:[...p.issues,...b.issues]}}),mx=o.fn("codeMode.getArtifact.workflow")(function*(e){let t=i.q$Z(oE,{errors:"all",reportInput:!0})(e);if(!um.oJ(t))return yield*new fC({status:"invalid_input",context:{issues:fF(s9(t.failure))}});let a=yield*uQ,s=yield*rN,l=t.success,r=yield*s.readManifest(l.artifactId).pipe(o.xm_(e=>new fC({status:"storage_failed",context:{issues:[mi(e,"storage_read_failed")]}})));if(!r)return yield*new fC({status:"not_found",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:l.artifactId},message:`Artifact "${l.artifactId}" was not found.`,hint:"Use the artifactId returned by buildFlowchart or applyDiagramPatch."})]}});let n=l.format??"scene";if(!r.formats.some(e=>e.format===n))return yield*new fC({status:"format_unavailable",context:{issues:[fB({code:"unsupported_artifact_format",stage:"storage",ref:{kind:"artifact",id:l.artifactId},message:`Artifact "${l.artifactId}" does not include format "${n}".`,hint:"Request a format listed in the artifact bundle."})]}});let c=yield*s.read(l.artifactId,n).pipe(o.xm_(e=>new fC({status:"storage_failed",context:{issues:[mi(e,"storage_read_failed")]}})));return c?{ok:!0,artifactId:l.artifactId,diagramId:r.diagramId,format:n,mimeType:c.mimeType,...a.artifactUrl?{url:a.artifactUrl({artifactId:l.artifactId,format:n})}:{},...!0!==l.inline||!rJ(n)?{}:{inline:c.data},sizeBytes:c.sizeBytes,...r.provenance?{provenance:r.provenance}:{}}:yield*new fC({status:"format_unavailable",context:{issues:[fB({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:l.artifactId},message:`Artifact "${l.artifactId}" format "${n}" could not be read.`,hint:"Retry retrieval or rebuild the artifact."})]}})}),mb=o.fn("codeMode.applyDiagramPatch.workflow")(function*(e){let t,a=i.q$Z(mm)(e),s=um.oJ(a)?yield*mv(a.success.source.scene,"source.scene"):void 0;if(s)return yield*new f_({status:"invalid_input",context:{issues:[s]}});let l=i.q$Z(o6,{errors:"all",reportInput:!0})(e);if(!um.oJ(l))return yield*new f_({status:"invalid_input",context:{issues:fF(s9(l.failure))}});let r=yield*uQ,n=l.success,c=yield*o.OH5(()=>r.createId("patch")),d={patchId:c,...mt(n.requestId)},p=yield*me(n).pipe(o.xm_(e=>new f_({status:e.status,context:{...d,...e.context}}))),h={...d,...p.sourceArtifactId?{sourceArtifactId:p.sourceArtifactId}:{}},g=p.scene;if(g.elements.length>aU.maxElements)t=[{code:"limit_exceeded",message:`Canvas exceeds ${aU.maxElements} elements.`,path:"elements"}];else{let e=fD(g);t=e?se(e).filter(e=>"limit_exceeded"===e.code):[]}if(t.length>0)return yield*new f_({status:"invalid_input",context:{...h,issues:f$(t)}});let u=fj(g),f=[];for(let e of n.operations)if((f=function(e,t){switch(t.op){case"setDefaultStyle":case"setStyle":if(t.style.backgroundColor&&(e.backgroundColor=t.style.backgroundColor),"setDefaultStyle"===t.op){for(let a of(t.style.strokeColor&&(e.accentColor=t.style.strokeColor),fN(e)))t.style.fillColor&&(a.fillColor=t.style.fillColor),t.style.strokeColor&&(a.strokeColor=t.style.strokeColor),t.style.textColor&&(a.textColor=t.style.textColor);for(let a of fJ(e))t.style.strokeColor&&(a.strokeColor=t.style.strokeColor),t.style.textColor&&(a.textColor=t.style.textColor);for(let a of fW(e))t.style.textColor&&(a.textColor=t.style.textColor);return[]}let a=fQ(e,t.selector);if(0===a.nodes.length&&0===a.arrows.length&&0===a.texts.length)return[f1(t)];for(let s of a.nodes)if(t.style.fillColor&&(s.fillColor=t.style.fillColor),t.style.strokeColor&&(s.strokeColor=t.style.strokeColor),t.style.textColor){s.textColor=t.style.textColor;let a=f0(e,s.id);a&&(a.textColor=t.style.textColor)}for(let s of a.arrows)if(t.style.strokeColor&&(s.strokeColor=t.style.strokeColor),t.style.textColor){s.textColor=t.style.textColor;let a=f0(e,s.id);a&&(a.textColor=t.style.textColor)}for(let e of a.texts)t.style.textColor&&(e.textColor=t.style.textColor);return[];case"setShape":let s=fQ(e,t.selector);if(0===s.nodes.length)return[f1(t)];let i=[];for(let a of s.nodes){if(a.shape=t.shape,"polygon"===t.shape?a.points=[{x:a.width/2,y:0},{x:a.width,y:a.height/2},{x:a.width/2,y:a.height},{x:0,y:a.height/2}]:delete a.points,"circle"===t.shape){let e=Math.max(a.width,a.height);a.x-=(e-a.width)/2,a.y-=(e-a.height)/2,a.width=e,a.height=e,i.push(a.nodeId)}!function(e,t){let a=f0(e,t.id);a&&(a.x=t.x+t.width/2,a.y=t.y+t.height/2)}(e,a)}return f3(e,i),[];case"translate":return function(e,t){let a=fQ(e,t.selector);if(0===a.nodes.length&&0===a.arrows.length&&0===a.texts.length)return[f1(t)];let s=new Set,i=new Set;for(let l of a.nodes){l.x+=t.dx,l.y+=t.dy,s.add(l.nodeId);let a=f0(e,l.id);a&&(a.x+=t.dx,a.y+=t.dy,i.add(a.id))}for(let s of a.arrows){s.points=s.points.map(e=>{var a,s;return a=t.dx,s=t.dy,{x:e.x+a,y:e.y+s}});let a=f0(e,s.id);a&&(a.x+=t.dx,a.y+=t.dy,i.add(a.id))}for(let e of a.texts)i.has(e.id)||(e.x+=t.dx,e.y+=t.dy);return f3(e,[...s]),f7(e),[]}(e,t);case"replaceText":let l=fQ(e,t.selector);if(0===l.nodes.length&&0===l.arrows.length&&0===l.texts.length)return[f1(t)];for(let a of l.nodes){a.label=t.text;let s=f0(e,a.id);s&&(s.text=t.text)}for(let a of l.arrows){a.label=t.text;let s=f0(e,a.id);s&&(s.text=t.text)}for(let e of l.texts)e.text=t.text;return[];case"rerouteEdges":let o;return 0===(o=fQ(e,t.selector)).arrows.length?[f1(t)]:o.arrows.flatMap(t=>f6(e,t));case"insert":let r=new Set(e.elements.map(e=>e.id)),n=t.elements.map(e=>e.id);if(new Set(n).size!==n.length||n.some(e=>r.has(e)))return f9(t,"Inserted elements must use ids that are unique within the canvas.");let c=f8(e.zOrder,t.beforeId,t.afterId);return void 0===c?f9(t,"Insert specifies an unknown anchor or both beforeId and afterId."):(e.elements.push(...t.elements.map(e=>structuredClone(e))),e.zOrder.splice(c,0,...n),[]);case"remove":return function(e,t){let a,s=function(e,t){let a=fQ(e,t),s=new Set([...a.nodes.map(e=>e.id),...a.arrows.map(e=>e.id),...a.texts.map(e=>e.id)]),i=new Set(t.ids??[]);for(let t of e.elements)i.has(t.id)&&s.add(t.id);return s}(e,t.selector);if(0===s.size)return[f1(t)];let i=new Set(e.elements.flatMap(e=>"node"===e.type&&s.has(e.id)?[e.nodeId]:[]));do for(let t of(a=s.size,e.elements))("text"===t.type&&(t.containerId&&s.has(t.containerId)||fJ(e).some(a=>s.has(a.id)&&f0(e,a.id)?.id===t.id))||"arrow"===t.type&&(i.has(t.sourceNodeId)||i.has(t.targetNodeId))||"line"===t.type&&(t.startBinding&&s.has(t.startBinding.elementId)||t.endBinding&&s.has(t.endBinding.elementId)))&&s.add(t.id);while(s.size!==a)let l=e.elements.filter(e=>!s.has(e.id)).map(e=>{if(e.frameId&&s.has(e.frameId)){let{frameId:t,...a}=e;return a}return e});e.elements.splice(0,e.elements.length,...l);let o=e.zOrder.filter(e=>!s.has(e));e.zOrder.splice(0,e.zOrder.length,...o);let r=e.layouts.map(e=>({...e,ids:e.ids.filter(e=>!s.has(e))})).filter(e=>e.ids.length>0);return e.layouts.splice(0,e.layouts.length,...r),f7(e),[]}(e,t);case"replace":let d;return(d=e.elements.findIndex(e=>e.id===t.id))<0?[f1(t)]:t.element.id!==t.id?f9(t,"Replacement element id must match the stable id being replaced."):(e.elements.splice(d,1,structuredClone(t.element)),f7(e),[]);case"reorder":let p=new Set(t.ids);if(p.size!==t.ids.length||t.ids.some(t=>!e.zOrder.includes(t)))return f9(t,"Reorder ids must be unique ids already present in zOrder.");let h=e.zOrder.filter(e=>!p.has(e)),g=f8(h,t.beforeId,t.afterId);return void 0===g?f9(t,"Reorder specifies an unknown anchor or both beforeId and afterId."):(h.splice(g,0,...t.ids),e.zOrder.splice(0,e.zOrder.length,...h),[]);case"group":case"ungroup":let u=new Set(t.ids);if(t.ids.some(t=>!e.elements.some(e=>e.id===t)))return[f1(t)];let f=e.elements.map(e=>u.has(e.id)?"group"===t.op?{...e,groupIds:[...new Set([...e.groupIds??[],t.groupId])]}:{...e,groupIds:t.groupId?(e.groupIds??[]).filter(e=>e!==t.groupId):[]}:e);return e.elements.splice(0,e.elements.length,...f),[]}}(g,e)).length>0)break;if(f.length>0)return yield*new f_({status:f[0]?.code==="unknown_patch_target"?"target_not_found":"unsupported_operation",context:{...h,issues:f}});if(n.options?.preserveConnectivity!==!1){let e=fj(g);if(!(u.length===e.length&&u.every((t,a)=>t===e[a])))return yield*new f_({status:"connectivity_changed",context:{...h,issues:[fB({code:"patch_preserve_connectivity_failed",stage:"flowchart",ref:{kind:"diagram",id:g.diagramId},message:"Patch changed the diagram edge connectivity.",hint:"Use buildFlowchart for process-graph structure or buildMindmap for hierarchy structure."})]}})}let m=fD(g);if(!m)return yield*new f_({status:"render_failed",context:{...h,issues:[fB({code:"patch_output_invalid",stage:"render",ref:{kind:"diagram",id:g.diagramId},message:"Patched scene has an invalid arrow point list.",hint:"Reroute edges or rebuild the flowchart artifact."})]}});let v=yield*uU(m,r.icons),y=v.scene,w=se(y);if(w.length>0)return yield*new f_({status:"render_failed",context:{...h,partial:ma(y),issues:[...v.issues,...f$(w)]}});let x={...h,partial:ma(y)},b=yield*ml({scene:y,formats:fU(n.options),inlineFormats:fX(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:fG,...p.sourceArtifactId?{provenance:{sourceArtifactId:p.sourceArtifactId}}:{}}).pipe(o.xm_(e=>new f_({status:e.status,context:{..."export_failed"===e.status?x:h,issues:e.issues}})));return{ok:!0,status:"accepted",patchId:c,...mt(n.requestId),...p.sourceArtifactId?{sourceArtifactId:p.sourceArtifactId}:{},artifact:b,issues:v.issues}}),mk=o.fn("codeMode.searchIcons.workflow")(function*(e){let t=i.q$Z(r$,{errors:"all",reportInput:!0})(e);if(!um.oJ(t))return yield*new fz({status:"invalid_input",context:{issues:fF(s9(t.failure))}});let a=yield*uQ,s=s5(t.success.q),l=a.icons?.search(s,t.success.limit??10)??[];return{ok:!0,status:"accepted",query:s,icons:l.map(({collection:e,match:t,name:a,slug:s})=>({collection:e,name:a,slug:s,match:t})),issues:a.icons?[]:[fB({code:"unknown_icon",severity:"warning",stage:"input",ref:{kind:"request",path:"q"},message:"This Sketchi runtime has no icon catalog.",hint:"Omit node icons on this host."})]}});function mM(e,t,a){return o.fn(`codeMode.${e}`)(s=>{var i,l,n;let c,d,p,h;return i=e,l=s,n=t(s).pipe(o.YWq({onFailure:a,onSuccess:e=>e})),uu(o.JkU(function*(){let e=yield*r.Ru,t=yield*n,a=yield*r.Ru,s=t.ok?"success":"failure",l=t.ok?void 0:t.status??"unknown_failure";yield*uf(uN,1,{...l?{failureCategory:l}:{},operation:i,outcome:s,surface:"code_mode"}),yield*uf(uK,a-e,{...l?{failureCategory:l}:{},operation:i,outcome:s,surface:"code_mode"}),l&&(yield*uf(uW,1,{failureCategory:l,operation:i,surface:"code_mode"}));let o="buildFlowchart"===i?"flowchart":"buildMindmap"===i?"mindmap":"buildSequenceDiagram"===i?"sequence":"buildTimeline"===i?"timeline":"buildChart"===i?"chart":"buildGantt"===i?"gantt":"buildStateMachine"===i?"state-machine":"buildErDiagram"===i?"er":"buildClassDiagram"===i?"class":"buildOrgChart"===i?"org-chart":"createCanvas"===i?"canvas":"applyDiagramPatch"===i?"patch":void 0;return t.ok&&o&&(yield*uf(uJ,1,{artifactKind:o,operation:i,surface:"code_mode"})),t}),(c=u0(l),d=u0(c?.source),p="string"==typeof c?.artifactId?c.artifactId:"string"==typeof d?.artifactId?d.artifactId:void 0,h="string"==typeof c?.requestId?c.requestId:void 0,{...p?{artifactId:p}:{},...h?{requestId:h}:{}}))})}let mC=mM("buildFlowchart",mw,ms),mz=mM("buildMindmap",mo,ms),m_=mM("buildSequenceDiagram",mr,ms),mL=mM("buildStateMachine",mn,ms),mB=mM("buildErDiagram",mc,ms),mS=mM("buildClassDiagram",md,ms),mA=mM("buildOrgChart",mp,ms),mP=mM("buildTimeline",mh,ms),mV=mM("buildChart",mg,ms),mH=mM("buildGantt",mu,ms);mM("createCanvas",my,ms),mM("getArtifact",mx,ms),mM("searchIcons",mk,ms);let mq=mM("applyDiagramPatch",mb,ms),mF=h,mI={flowchart:i7,mindmap:oi,sequence:la,timeline:li,chart:lo,"state-machine":lh,gantt:lu,er:lb,class:lV,"org-chart":lE};function mE(e){return mF.some(t=>t===e)}function mO(e,t){let a={spec:e.spec,...t?{options:t}:{}};switch(e.type){case"flowchart":return mC(a);case"mindmap":return mz(a);case"sequence":return m_(a);case"timeline":return mP(a);case"chart":return mV(a);case"state-machine":return mL(a);case"gantt":return mH(a);case"er":return mB(a);case"class":return mS(a);case"org-chart":return mA(a)}}},4733(e,t,a){function s(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}function l(e){var t;return s(e)&&i(e.aliases)&&"number"==typeof e.bytes&&"string"==typeof e.collection&&i(e.keywords)&&"string"==typeof e.name&&"string"==typeof e.slug&&"string"==typeof e.svgPath&&(void 0===e.variant||"string"==typeof e.variant)&&s(t=e.viewBox)&&"number"==typeof t.height&&"number"==typeof t.minX&&"number"==typeof t.minY&&"number"==typeof t.width}function o(e){if(!s(e)||1!==e.version||!Array.isArray(e.icons)||!e.icons.every(l)||!s(e.summary)||"number"!=typeof e.summary.totalIcons||void 0!==e.generatedAt&&"string"!=typeof e.generatedAt)throw Error("Icon manifest does not match the public contract.");return{..."string"==typeof e.generatedAt?{generatedAt:e.generatedAt}:{},icons:e.icons,summary:{collectionCounts:function(e){if(!s(e))throw Error("Icon manifest collection counts are invalid.");let t={};for(let[a,s]of Object.entries(e)){if("number"!=typeof s)throw Error(`Icon manifest count for ${a} is invalid.`);t[a]=s}return t}(e.summary.collectionCounts),totalIcons:e.summary.totalIcons},version:1}}function r(e){return"gcp"===e?"Google Cloud":"gcp-legacy"===e?"Google Cloud Classic":e.split("-").map(e=>["ai","ci","iot","paas"].includes(e)?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}a.d(t,{L:()=>o,y:()=>r})},8713(e,t,a){let s=/<svg\b[^>]*>/u,i=/\sviewBox\s*=\s*(["'])([^"']*)\1/u;function l(e){return void 0===e.variant&&e.bytes<=65536}function o(e){let t=s.exec(e);if(!t)throw Error("Node logo source has no <svg> root element.");let a=t[0],l=i.exec(a)?.[2]?.trim().split(/[\s,]+/u).map(Number);if(!l||4!==l.length||l.some(e=>!Number.isFinite(e))||!((l[2]??0)>0&&(l[3]??0)>0))throw Error("Node logo source has no valid viewBox.");let o=[/\sxmlns\s*=/u.test(a)?"":' xmlns="http://www.w3.org/2000/svg"',/\swidth\s*=/u.test(a)?"":` width="${l[2]}"`,/\sheight\s*=/u.test(a)?"":` height="${l[3]}"`].join("");if(!o)return e;let r=t.index+4;return`${e.slice(0,r)}${o}${e.slice(r)}`}a.d(t,{Bn:()=>o,nC:()=>l})},9095(e){e.exports=JSON.parse('[{"name":"Agola CI","constant":"AGOLA","env":"AGOLA_GIT_REF","pr":"AGOLA_PULL_REQUEST_ID"},{"name":"Alpic","constant":"ALPIC","env":"ALPIC_HOST"},{"name":"Appcircle","constant":"APPCIRCLE","env":"AC_APPCIRCLE","pr":{"env":"AC_GIT_PR","ne":"false"}},{"name":"AppVeyor","constant":"APPVEYOR","env":"APPVEYOR","pr":"APPVEYOR_PULL_REQUEST_NUMBER"},{"name":"AWS CodeBuild","constant":"CODEBUILD","env":"CODEBUILD_BUILD_ARN","pr":{"env":"CODEBUILD_WEBHOOK_EVENT","any":["PULL_REQUEST_CREATED","PULL_REQUEST_UPDATED","PULL_REQUEST_REOPENED"]}},{"name":"Azure Pipelines","constant":"AZURE_PIPELINES","env":"TF_BUILD","pr":{"BUILD_REASON":"PullRequest"}},{"name":"Bamboo","constant":"BAMBOO","env":"bamboo_planKey"},{"name":"Bitbucket Pipelines","constant":"BITBUCKET","env":"BITBUCKET_COMMIT","pr":"BITBUCKET_PR_ID"},{"name":"Bitrise","constant":"BITRISE","env":"BITRISE_IO","pr":"BITRISE_PULL_REQUEST"},{"name":"Buddy","constant":"BUDDY","env":"BUDDY_WORKSPACE_ID","pr":"BUDDY_EXECUTION_PULL_REQUEST_ID"},{"name":"Buildkite","constant":"BUILDKITE","env":"BUILDKITE","pr":{"env":"BUILDKITE_PULL_REQUEST","ne":"false"}},{"name":"CircleCI","constant":"CIRCLE","env":"CIRCLECI","pr":"CIRCLE_PULL_REQUEST"},{"name":"Cirrus CI","constant":"CIRRUS","env":"CIRRUS_CI","pr":"CIRRUS_PR"},{"name":"Cloudflare Pages","constant":"CLOUDFLARE_PAGES","env":"CF_PAGES"},{"name":"Cloudflare Workers","constant":"CLOUDFLARE_WORKERS","env":"WORKERS_CI"},{"name":"Codefresh","constant":"CODEFRESH","env":"CF_BUILD_ID","pr":{"any":["CF_PULL_REQUEST_NUMBER","CF_PULL_REQUEST_ID"]}},{"name":"Codemagic","constant":"CODEMAGIC","env":"CM_BUILD_ID","pr":"CM_PULL_REQUEST"},{"name":"Codeship","constant":"CODESHIP","env":{"CI_NAME":"codeship"}},{"name":"Drone","constant":"DRONE","env":"DRONE","pr":{"DRONE_BUILD_EVENT":"pull_request"}},{"name":"dsari","constant":"DSARI","env":"DSARI"},{"name":"Earthly","constant":"EARTHLY","env":"EARTHLY_CI"},{"name":"Expo Application Services","constant":"EAS","env":"EAS_BUILD"},{"name":"Gerrit","constant":"GERRIT","env":"GERRIT_PROJECT"},{"name":"Gitea Actions","constant":"GITEA_ACTIONS","env":"GITEA_ACTIONS"},{"name":"GitHub Actions","constant":"GITHUB_ACTIONS","env":"GITHUB_ACTIONS","pr":{"GITHUB_EVENT_NAME":"pull_request"}},{"name":"GitLab CI","constant":"GITLAB","env":"GITLAB_CI","pr":"CI_MERGE_REQUEST_ID"},{"name":"GoCD","constant":"GOCD","env":"GO_PIPELINE_LABEL"},{"name":"Google Cloud Build","constant":"GOOGLE_CLOUD_BUILD","env":"BUILDER_OUTPUT"},{"name":"Harness CI","constant":"HARNESS","env":"HARNESS_BUILD_ID"},{"name":"Heroku","constant":"HEROKU","env":{"env":"NODE","includes":"/app/.heroku/node/bin/node"}},{"name":"Hudson","constant":"HUDSON","env":"HUDSON_URL"},{"name":"Jenkins","constant":"JENKINS","env":["JENKINS_URL","BUILD_ID"],"pr":{"any":["ghprbPullId","CHANGE_ID"]}},{"name":"LayerCI","constant":"LAYERCI","env":"LAYERCI","pr":"LAYERCI_PULL_REQUEST"},{"name":"Magnum CI","constant":"MAGNUM","env":"MAGNUM"},{"name":"Netlify CI","constant":"NETLIFY","env":"NETLIFY","pr":{"env":"PULL_REQUEST","ne":"false"}},{"name":"Nevercode","constant":"NEVERCODE","env":"NEVERCODE","pr":{"env":"NEVERCODE_PULL_REQUEST","ne":"false"}},{"name":"Prow","constant":"PROW","env":"PROW_JOB_ID"},{"name":"ReleaseHub","constant":"RELEASEHUB","env":"RELEASE_BUILD_ID"},{"name":"Render","constant":"RENDER","env":"RENDER","pr":{"IS_PULL_REQUEST":"true"}},{"name":"Sail CI","constant":"SAIL","env":"SAILCI","pr":"SAIL_PULL_REQUEST_NUMBER"},{"name":"Screwdriver","constant":"SCREWDRIVER","env":"SCREWDRIVER","pr":{"env":"SD_PULL_REQUEST","ne":"false"}},{"name":"Semaphore","constant":"SEMAPHORE","env":"SEMAPHORE","pr":"PULL_REQUEST_NUMBER"},{"name":"Sourcehut","constant":"SOURCEHUT","env":{"CI_NAME":"sourcehut"}},{"name":"Strider CD","constant":"STRIDER","env":"STRIDER"},{"name":"TaskCluster","constant":"TASKCLUSTER","env":["TASK_ID","RUN_ID"]},{"name":"TeamCity","constant":"TEAMCITY","env":"TEAMCITY_VERSION"},{"name":"Travis CI","constant":"TRAVIS","env":"TRAVIS","pr":{"env":"TRAVIS_PULL_REQUEST","ne":"false"}},{"name":"Vela","constant":"VELA","env":"VELA","pr":{"VELA_PULL_REQUEST":"1"}},{"name":"Vercel","constant":"VERCEL","env":{"any":["NOW_BUILDER","VERCEL"]},"pr":"VERCEL_GIT_PULL_REQUEST_ID"},{"name":"Visual Studio App Center","constant":"APPCENTER","env":"APPCENTER_BUILD_ID"},{"name":"Woodpecker","constant":"WOODPECKER","env":{"CI":"woodpecker"},"pr":{"CI_BUILD_EVENT":"pull_request"}},{"name":"Xcode Cloud","constant":"XCODE_CLOUD","env":"CI_XCODE_PROJECT","pr":"CI_PULL_REQUEST_NUMBER"},{"name":"Xcode Server","constant":"XCODE_SERVER","env":"XCS"}]')}},r={};function n(e){var t=r[e];if(void 0!==t)return t.exports;var a=r[e]={exports:{}};return o[e].call(a.exports,a,a.exports,n),a.exports}n.m=o,n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},s=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,n.t=function(e,t){if(1&t&&(e=this(e)),8&t||"object"==typeof e&&e&&(4&t&&e.__esModule||16&t&&"function"==typeof e.then))return e;var i=Object.create(null);n.r(i);var l={};a=a||[null,s({}),s([]),s(s)];for(var o=2&t&&e;("object"==typeof o||"function"==typeof o)&&!~a.indexOf(o);o=s(o))Object.getOwnPropertyNames(o).forEach(t=>{l[t]=()=>e[t]});return l.default=()=>e,n.d(i,l),i},n.d=(e,t,a)=>{var s=(t,a)=>{for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,[a]:t[s]})};s(t,"get"),s(a,"value")},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce((t,a)=>(n.f[a](e,t),t),[])),n.u=e=>"chunks/"+e+"."+({548:"7c734cd41f2be66d",712:"a869102f22286cfc"})[e]+".js",n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.nc=void 0,i={889:0},l=e=>{var t,a,s=e.__rspack_esm_ids,l=e.__webpack_modules__,o=e.__rspack_esm_runtime,r=0;for(t in l)n.o(l,t)&&(n.m[t]=l[t]);for(o&&o(n);r<s.length;r++)a=s[r],n.o(i,a)&&i[a]&&i[a][0](),i[s[r]]=0},n.f.j=function(e,t){var a=n.o(i,e)?i[e]:void 0;if(0!==a)if(a)t.push(a[1]);else{var s=import("./"+n.u(e)).then(l,t=>{throw 0!==i[e]&&(i[e]=void 0),t}),s=Promise.race([s,new Promise(t=>{a=i[e]=[t]})]);t.push(a[1]=s)}},n(2141);
|