sketchi 0.32.0 → 0.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/sketchi.js +3 -3
package/sketchi.js CHANGED
@@ -410,7 +410,7 @@ authority: ${e.diagram.authority}`,e=>({id:e.diagram.manifest.id,restoredFromRev
410
410
  `:`error: usage_error
411
411
  ${a}
412
412
  next: ${s}
413
- `)}},d=new Proxy(globalThis.console,{get(e,t,a){if("log"===t)return(...t)=>{(1!==t.length||""!==t[0])&&e.log(...t)};let l=Reflect.get(e,t,a);return"function"==typeof l?l.bind(e):l}}),gE(mh,{version:"0.32.0"})(e).pipe(F.sFT(e=>el.i5(e,n8)&&"ShowHelp"!==e._tag?n6(n.formatErrors([e])):F.rIH),F.PfK(pB,{builtIns:[pz,pC,pq]}),F.PfK(cd,n),F.PfK(n5,d))).pipe(F.khu({onFailure:e=>F.JkU(function*(){let t,a=eF.getOrUndefined($.L$(e));if(a instanceof fy)return a.exitCode;if(a instanceof iz)return 7;let l=function(e){if(el.i5(e,n8))return"ShowHelp"===e._tag?2*(e.errors.length>0):2}(a);if(void 0!==l)return l;let i=yield*fv;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"===c?iJ({ok:!1,command:"sketchi",error:t}):fb(t))).pipe(F.MfU(()=>F.rIH)),1}),onSuccess:()=>F.PyW(0)}))}),mu=D.Um(iM.Txp,(0,iM.rRT)({createId:e=>`${e}_offline_cli`,icons:rV})),mf=D.Gt(i0,mu),mm=D.Gt(sl,mu),mv=D.Um(i7,o1),my=D.Gt(rt,mv),mw=D.Gt(rC,D.Um(my,rb)),mx=D.Gt(fE,fH),mb=D.Um(i7,o1,mf,mm,my,mw,rb,mx,fF,so.pipe(D.Gt(i7)),fx,n3),mk=D.S5(mb,ik);Y(mg(process.argv.slice(2)).pipe(F.Mim(e=>F.OH5(()=>{process.exitCode=e})),F.Gte(mk)),{disableErrorReporting:!0})},1688(e,t,a){var l=a(2390);let i=l.xCb(["invalid_render_artifact","render_limit_exceeded","unsupported_render_glyph","rasterization_failed"]),s=l.xCb(["artifact","geometry","font","rasterization"]);class o extends l.rNF()("HeadlessPngRenderError",{cause:l.kld(),code:i,stage:s,message:l.QfV,details:l.O31(l.QfV)}){}a.d(t,{},{FG:o})},5030(e,t,a){function l(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i(e,t,a,l){return{code:e,message:t,...void 0===a?{}:{observed:a},...void 0===l?{}:{limit:l}}}function s(e,t=0){let a=1/0,o=1/0,r=-1/0,n=-1/0;for(let t of e){if(!(l(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),s=Math.abs(t.height);if(e>8192||s>8192)return i("element_dimension",`element dimension exceeds ${String(8192)}`,Math.max(e,s),8192);let d=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])],l=[e.y,e.y+e.height,...t.map(t=>e.y+t[1])];return{left:Math.min(...a),top:Math.min(...l),right:Math.max(...a),bottom:Math.max(...l)}}(t);if(d){a=Math.min(a,d.left),o=Math.min(o,d.top),r=Math.max(r,d.right),n=Math.max(n,d.bottom);continue}let c=Math.hypot(e,s)/2,p=t.x+t.width/2,h=t.y+t.height/2;a=Math.min(a,p-c),o=Math.min(o,h-c),r=Math.max(r,p+c),n=Math.max(n,h+c)}if(0===e.length)return;let d=r-a,c=n-o;if(d>8192||c>8192)return i("canvas_dimension",`canvas dimension exceeds ${String(8192)}`,Math.max(d,c),8192);let p=d*c;if(p>6291456)return i("canvas_area",`canvas area exceeds ${String(6291456)}`,p,6291456);let h=(d+40)*1*((c+40+t)*1);if(h>0x1800000)return i("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,h,0x1800000)}a.d(t,{},{Gd:function(e,t=0){return s(e,t)?.message},Ts:s,Yu:function(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)},Z4:6291456,ce:0x1800000,jA:function(e,t){let a=new Set(t.flatMap(e=>l(e)&&"image"===e.type&&!0!==e.isDeleted&&"string"==typeof e.fileId?[e.fileId]:[])),s=0;for(let t of a){let a=Object.hasOwn(e,t)?e[t]:void 0,i=l(a)?a.dataURL:void 0;"string"==typeof i&&(s+=i.length)}return s>8388608?i("file_bytes",`embedded image data exceeds ${String(8388608)} bytes`,s,8388608):void 0}})},6982(e){e.exports=t("crypto")},7598(e){e.exports=t("node:crypto")},76(e,t,a){let l=a(9095),i=process.env;function s(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:l.map(function(e){return e.constant})}),t.name=null,t.isPR=null,t.id=null,"false"!==i.CI&&l.forEach(function(e){let a=(Array.isArray(e.env)?e.env:[e.env]).every(function(e){return s(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 s(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},5185(e,t,a){a.d(t,{CN:()=>g,BC:()=>m,Ie:()=>_,pb:()=>B,i8:()=>M,g9:()=>k,Uk:()=>z,Ts:()=>u,Yz:()=>S,CZ:()=>v,iX:()=>w,ET:()=>y,HV:()=>x,T9:()=>V,Tj:()=>L,YW:()=>f,of:()=>q,jB:()=>A,TS:()=>P,di:()=>C});var l=a(1058),i=a(4876);let s=e=>e.length>0;var o=a(6813),r=a(9974),n=a(3565),d=a(2538),c=a(841),p=a(2881);let h=globalThis.Array,g=e=>new h(o.S(e)),u=e=>h.isArray(e)?e:h.from(e);c.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=s,y=s;function w(e){let t=Number(e);return String(t)===e&&Number.isInteger(t)&&t>=0&&t<0xffffffff}let x=e=>y(e)?n.some(b(e)):n.none(),b=e=>e[e.length-1],k=(0,i.XY)(2,(e,t)=>{let a=0;for(let l of e){if(t(l,a))return n.some(a);a++}return n.none()}),M=r.i8,z=(0,i.XY)(2,(e,t)=>{let a=u(e);for(let e=a.length-1;e>=0;e--){let l=a[e],i=t(l,e);if("boolean"==typeof i){if(i)return n.some(l)}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}),_=()=>[],q=e=>[e],L=(0,i.XY)(2,(e,t)=>e.map(t)),S=e=>{let t=[];for(let a of e)n.isSome(a)&&t.push(a.value);return t},B=(0,i.XY)(2,(e,t)=>{let a=u(e),l=[];for(let e=0;e<a.length;e++)t(a[e],e)&&l.push(a[e]);return l}),A=(0,i.XY)(2,(e,t)=>{let a=[],l=[],i=0;for(let s of e){let e=t(s,i++);p.oJ(e)?a.push(e.success):l.push(e.failure)}return[a,l]}),P=(0,i.XY)(3,(e,t,a)=>u(e).reduce((e,t,l)=>a(e,t,l),t));d.O3;let V=l.O3},8895(e,t,a){var l=a(6681),i=a(1058),s=a(4876),o=a(3565),r=a(2538),n=a(6307),d=a(5770);let c=globalThis.BigInt,p=c(0);n.sI;let h=(0,s.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=d.L((e,t)=>e+t,p),z=l.T9(g),C=l.jk(g);a.d(t,{},{K0:C,OW:y,Ro:e=>e>c(Number.MAX_SAFE_INTEGER)||e<c(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:z,yJ:v})},723(e,t,a){var l=a(8895),i=a(3565);let s=BigInt(0),o=BigInt(1),r=BigInt(1e3),n=BigInt(1024),d=[{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"]}],c=[d[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([...d,...c.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[2]);if(void 0===a)return h(`unsupported unit ${JSON.stringify(t[2])}`);let l=((e,t)=>{let a=/^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(e);if(null===a)return;let l=a[2]??"",i=BigInt(a[1]+l)*t,o=Number(a[3]??0)-l.length;if(o>=0)return i*BigInt(10)**BigInt(o);let r=BigInt(10)**BigInt(-o);return i%r===s?i/r:void 0})(t[1],a.factor);return void 0===l?h(`${JSON.stringify(e)} does not represent an integral number of bytes`):l},f=i.liftThrowable(u),m=e=>{switch(typeof e){case"bigint":if(e<s)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=l.Ro;l.pH,l.rs,l.Tq,l.jk,l.T9,l.qE,l.hl,l.bi,l.yJ,l.OW,l.cz,l.aD,l.sO,l.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>=s})},6313(e,t,a){var l=a(1863),i=a(7669);l.PX,l.B4;let s=l.Aj;l.Wg;let o=l.lC,r=l.Xb;l.ik;let n=l.b5;l.DH;let d=l.OE,c=l.Iu;i.nIy,i.ORc;let p=i.nn5,h=i.O$X;l.h2;let g=i.ReC;i.myX,i.QE5,i.khU;let u=i.L$u;i.gpn,i.k7S,i.BbX;let f=i.prj;i.tU5,i.h74,i.Bou,i.RJ6;let m=i.GyP;l.PW,l.qB,l.Xm;let v=l.$L;l.q_;let y=l.RS,w=l.Vw;i.DQo,i.c8t,i.MUS,i.t8c,i._y;let x=i.qwd;i.ASO,i.F7W,i.Aub,i.cOF,i.Rft,i.RD4,i.Kkt,i.PnV;let b=i.Bk6;l.Eh;let k=i.tQ6;i.On5,a.d(t,{},{$E:e=>new l.pg(e),$L:v,Aj:s,Bk:b,F_:c,Jh:e=>new l.dM(e),L$:u,RS:y,Tj:h,Vw:w,Xb:r,fJ:d,iw:g,j9:m,kO:n,lC:o,nn:p,pr:f,qw:x,tQ:k})},760(e,t,a){var l=a(7669);l.a1U,l.RKA;let i=l.Rud;l.s0X,l.T13,a.d(t,{},{Ru:i})},6681(e,t,a){function l(e){return{combine:e}}a.d(t,{},{L8:l,T9:function(e){return l((t,a)=>1===e(t,a)?t:a)},jk:function(e){return l((t,a)=>-1===e(t,a)?t:a)}})},369(e,t,a){var l=a(3825),i=a(6886),s=a(4876),o=a(4763),r=a(1863),n=a(3565),d=a(6307);let c="~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={[c]:c,...l.bp({label:"Service",evaluate(e){return(0,r.xt)(P(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(P(t.context,this)))},useSync(e){return(0,r.R6)(t=>(0,r.xt)(e(P(t.context,this))))}},g=new Set,u="~effect/Context/Reference",f="~effect/Context",m=(e,t,a,l,i)=>{let s=Object.create(k);return s.cacheRoot=e??s,s.base=t,s.overlay=a,s.depth=l,s._flat=void 0,s.baseHits=0,s.maxDepth=i,s},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,t)=>{let a=t?.maxDepth;return m(void 0,e,void 0,0,Number.isInteger(a)&&a>=0?a:8)},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,l]of t)if(!a.has(e)||!i.aI(l,a.get(e)))return!1;return!0},[o.HR](){return o.ai(this.mapUnsafe.size)}},M=e=>(0,d.i5)(e,f),z=e=>!!e[u],C=b(new Map),_=(e,t)=>b(new Map([[e.key,t]])),q=(0,s.XY)(3,(e,t,a)=>L(e,t.key,a)),L=(e,t,a)=>{let l=g.has(t)?void 0:e.cacheRoot;if(e.depth>=e.maxDepth){let i=new Map(e._flat??e.base);return e._flat||v(i,e.overlay),i.set(t,a),m(l,i,void 0,0,e.maxDepth)}return m(l,e.base,{key:t,value:a,parent:e.overlay},e.depth+1,e.maxDepth)},S=(0,s.XY)(2,(e,t)=>B(e,t.key)),B=(e,t)=>{let a=x(e,t);return a===w?void 0:a},A=(0,s.XY)(2,(e,t)=>{let a=x(e,t.key);if(a===w){if(z(t))return H(t);throw I(t)}return a}),P=A,V="~effect/Context/defaultValue",H=e=>V in e?e[V]:e[V]=e.defaultValue(),I=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},$=(0,s.XY)(2,(e,t)=>{let a=x(e,t.key);return a!==w?n.some(a):z(t)?n.some(H(t)):n.none()}),F=(0,s.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)),m(void 0,a,void 0,0,e.maxDepth))});a.d(t,{},{Ie:()=>C,Jt:P,L8:_,LZ:b,Or:p,Pf:(e,t)=>e.cacheRoot===t.cacheRoot,Ub:B,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:q,Y6:S,aE:M,fp:A,h1:F,kl:p,om:$})},2788(e,t,a){var l=a(1863),i=a(5005),s=a(244),o=a(6307);let r=class extends s.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 d=l.$D,c=l.rN;a.d(t,{},{$D:d,Ij:()=>new Proxy({},{get:(e,t,a)=>"$is"===t?o.$J:"$match"===t?n:e=>({...e,_tag:t})}),Xs:r,rN:c})},9303(e,t,a){var l=a(4876),i=a(1863),s=a(7669),o=a(244);let r={"~effect/Deferred":{_A:l.D_,_E:l.D_},pipe(){return(0,o.tT)(this,arguments)}},n=function(){this.resumes=void 0,this.effect=void 0};n.prototype=r;let d=(0,l.XY)(2,(e,t)=>s.OH5(()=>h(e,t))),c=(0,l.XY)(2,(e,t)=>d(e,i.Rk(t))),p=e=>void 0!==e.effect,h=(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};a.d(t,{},{$L:e=>s.OH5(()=>p(e)),$w:h,LZ:()=>new n,NJ:p,Tx:e=>s.E2r(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),s.OH5(()=>{let a=e.resumes;if(void 0===a)return;let l=a.indexOf(t);l>=0&&a.splice(l,1)}))),fJ:c})},328(e,t,a){var l=a(6886),i=a(4876),s=a(4763),o=a(8946),r=a(2538),n=a(244),d=a(6307);let c="~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=BigInt(1e9),x=BigInt(6e10),b=BigInt(36e11),k=BigInt(864e11),M=BigInt(6048e11),z=e=>BigInt(Math.sign(e)*Math.round(Math.abs(e))),C=e=>Number.isInteger(e)?BigInt(e)*y:z(1e6*e),_=e=>U(Number.isFinite(e)?z(e):e),q=(e,t)=>{let a=Number(e);if(Number.isFinite(a))return a/t;let l=BigInt(t);return Number(e/l)+Number(e%l)/t},L=(e,t)=>{let a=e.indexOf(".");if(-1===a)return BigInt(e)*t;let l="-"===e[0],i=e.slice(a+1),s=u**BigInt(i.length),o=(BigInt(e.slice(+!!l,a))*s+BigInt(i))*t;return S(l?-o:o,s)},S=(e,t)=>{let a=e<p?-e:e,l=a/t+(a%t*g>=t?h:p);return e<p?-l:l},B=(e,t)=>{let a=Number(e)*t;if(!Number.isFinite(a))return U(a);let l=L(e,BigInt(t)*y);return U(Number.isInteger(a)&&BigInt(a)*y===l?a:l)},A=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,P=e=>{switch(typeof e){case"number":return Z(e);case"bigint":return G(e);case"string":{if("Infinity"===e)return Y;if("-Infinity"===e)return D;let t=A.exec(e);if(!t)break;let[a,l,i]=t;if("nano"===i||"nanos"===i)return G(L(l,h));if("micro"===i||"micros"===i)return G(L(l,v));switch(i){case"milli":case"millis":return B(l,1);case"second":case"seconds":return B(l,1e3);case"minute":case"minutes":return B(l,6e4);case"hour":case"hours":return B(l,36e5);case"day":case"days":return B(l,864e5);case"week":case"weeks":return B(l,6048e5)}break}case"object":{if(null===e)break;if(c in e)return e;if(Array.isArray(e)){if(2!==e.length||!e.every(d.Et))return I(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return R;if(-1/0===e[0]||-1/0===e[1])return D;if(1/0===e[0]||1/0===e[1])return Y;let t=1e9*e[0]+e[1];return Number.isFinite(t)&&Number.isInteger(e[0])&&Number.isInteger(e[1])?U(BigInt(e[0])*w+BigInt(e[1])):_(t)}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){if(!Number.isFinite(t))return U(t);let a=H(e);return void 0===a||BigInt(t)*y===a?U(t):U(a)}let a=1e6*t+(e.microseconds??0)*1e3+(e.nanoseconds??0),l=Number.isFinite(a)?H(e):void 0;return void 0===l?_(a):U(l)}}return I(e)},V=e=>!e||Number.isInteger(e),H=e=>{if(!V(e.weeks)||!V(e.days)||!V(e.hours)||!V(e.minutes)||!V(e.seconds)||!V(e.milliseconds)||!V(e.microseconds)||!V(e.nanoseconds))return;let t=p;return e.weeks&&(t+=BigInt(e.weeks)*M),e.days&&(t+=BigInt(e.days)*k),e.hours&&(t+=BigInt(e.hours)*b),e.minutes&&(t+=BigInt(e.minutes)*x),e.seconds&&(t+=BigInt(e.seconds)*w),e.milliseconds&&(t+=BigInt(e.milliseconds)*y),e.microseconds&&(t+=BigInt(e.microseconds)*v),e.nanoseconds&&(t+=BigInt(e.nanoseconds)),t},I=e=>{throw Error(`Invalid Input: ${e}`)},$={_tag:"Millis",millis:0},F={_tag:"Infinity"},O={_tag:"NegativeInfinity"},E={[c]:c,[s.HR](){switch(this.value._tag){case"Millis":return s.tW(C(this.value.millis));case"Nanos":return s.tW(this.value.nanos);default:return s.QK(this.value)}},[l.HR](e){return X(e)&&Q(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)}},U=e=>{let t=Object.create(E);return"number"==typeof e?isNaN(e)||0===e||Object.is(e,-0)?t.value=$:Number.isFinite(e)?Number.isInteger(e)?t.value={_tag:"Millis",millis:e}:t.value={_tag:"Nanos",nanos:C(e)}:t.value=e>0?F:O:e===p?t.value=$:t.value={_tag:"Nanos",nanos:e},t},X=e=>(0,d.i5)(e,c),T=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}},R=U(0),Y=U(1/0),D=U(-1/0),G=e=>U(e),Z=e=>U(e),j=e=>{let t=P(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 C(t.value.millis)}},N=(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)()}}),W=(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(j(e),t.value.nanos):a.onNanos(e.value.nanos,j(t))),J=r.L8((e,t)=>W(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})),K=r.bi(J),Q=(0,i.XY)(2,(e,t)=>W(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag})),ee=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(T(e))return"-"+ee((e=>{switch(e.value._tag){case"Infinity":case"NegativeInfinity":return Y;case"Millis":return e.value.millis<0?U(-e.value.millis):e;case"Nanos":return e.value.nanos<p?U(-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=j(e),a=t<p,l=a?-t:t,i=l/y,s=i/v,o=s/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(s%m),millis:n*Number(i%v),nanos:n*Number(l%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:ee,MI:e=>"Infinity"!==e.value._tag&&"NegativeInfinity"!==e.value._tag,Tn:Y,YA:e=>U(1e3*e),bN:P,bi:K,cF:G,cI:T,fP:e=>N(P(e),{onMillis:e=>e/1e3,onNanos:e=>q(e,1e9),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),kE:e=>N(P(e),{onMillis:i.D_,onNanos:e=>q(e,1e6),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),n$:X,ne:Z,qv:D,v_:R})},639(e,t,a){a.d(t,{Q56:()=>eT,jGc:()=>eR,U9h:()=>eY,Q7R:()=>$,hgn:()=>el,swY:()=>tl,Muk:()=>e1,as:()=>ed,NLW:()=>ec,PO3:()=>eN,E2r:()=>D,MfU:()=>eh,Tyx:()=>em,UVN:()=>td,osR:()=>ey,XWm:()=>ev,AXC:()=>ef,KuX:()=>eg,loE:()=>eu,_OA:()=>eV,sxi:()=>eH,_32:()=>e0,F_Q:()=>K,_r7:()=>ti,yeE:()=>eD,NS5:()=>er,fJG:()=>j,ATB:()=>W,pVV:()=>J,gOk:()=>N,qIB:()=>ea,Ab9:()=>tn,fn:()=>te,D9k:()=>e9,vCS:()=>tc,jJl:()=>F,i4r:()=>eQ,zhn:()=>e3,ar0:()=>e5,x6Z:()=>e4,yUA:()=>et,JkU:()=>Z,XeO:()=>ez,GrF:()=>eC,GaK:()=>eW,yw5:()=>I,vVN:()=>ta,FFw:()=>tt,TjK:()=>en,q7Y:()=>tr,jkJ:()=>ts,xm_:()=>ew,Z9x:()=>to,YWq:()=>eB,khu:()=>eA,tvg:()=>eP,ZmZ:()=>G,S5A:()=>eG,cfM:()=>ej,r7h:()=>eZ,uKv:()=>eo,QgK:()=>ex,ivC:()=>E,Gte:()=>eI,PpN:()=>e$,PfK:()=>eO,KT6:()=>eS,Ket:()=>es,L5P:()=>eM,MY7:()=>e6,eJC:()=>e7,lKS:()=>e8,z8E:()=>eE,P1j:()=>eU,Pxi:()=>eX,Nav:()=>eF,yy4:()=>eL,PyW:()=>X,DYE:()=>T,OH5:()=>R,Mim:()=>ei,dGm:()=>ek,sFT:()=>eb,wRz:()=>e_,mgX:()=>eq,SvU:()=>Q,$mh:()=>U,rfi:()=>eJ,FcF:()=>eK,rIH:()=>Y,iMI:()=>O,R6R:()=>ee,fRP:()=>e2,OYO:()=>ep});var l=a(4876),i=a(1863),s=a(7669),o=(a(328),a(369));a(2881);var r=a(4577),n=a(6215);let d=(0,l.XY)(e=>(0,i.yw)(e[0]),(e,t,a)=>{let l;return o.aE(t)?s.PpN(e,t):(l=Array.isArray(t)?n.Um(...t):t,s.Pxi(t=>s.qIB(a?.local?n.H7(l,n.j6(),t):n.LT(l,t),t=>s.PpN(e,t))))});var c=a(3565),p=a(3271),h=a(471);(e,t,a)=>s.qIB(r.xn(t),t=>{let l=r.d3.defaultValue(),i=a=>p.tv(t(a),{onSuccess:t=>(l=t,s.qIB(s.PfK(e,r.d3,l),i)),onFailure:s.ATB,onDone:s.PyW});return s.rNk(s.qIB(s.PfK(e,r.d3,l),i),s.ovK,e=>a(e,0===l.attempt?c.none():c.some(l)))});let g=(0,l.XY)(3,(e,t,a)=>s.qIB(r.xn(t),t=>{let l,i=r.d3.defaultValue(),o=s.rNk(s.DYE(()=>s.PfK(e,r.d3,i)),s.ovK,e=>(l=e,s.qIB(t(e),e=>(i=e,o))));return p.m8(o,e=>(0,h.s)(()=>a(l,e)))})),u=(0,l.XY)(2,(e,t)=>g(e,"function"==typeof t?t(l.D_):r.GM(t)?t:m(t),s.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:s.PyW(a)})),e.until&&(t=r.E6(t,({input:t})=>{let a=e.until(t);return i.yw(a)?s.TjK(a,e=>!e):s.PyW(!a)})),void 0!==e.times&&(t=r.E6(t,({attempt:t})=>s.PyW(t<=e.times))),t},v=r.t5(1);var y=a(5005),w=a(6886),x=a(6896),b=a(4763),k=a(8946),M=a(244);let z="~effect/MutableHashMap",C={[z]:z,[Symbol.iterator](){return this.backing[Symbol.iterator]()},toString(){return`MutableHashMap(${(0,x.GP)(Array.from(this))})`},toJSON(){return{_id:"MutableHashMap",values:(0,k.aB)(Array.from(this))}},[k.FX](){return this.toJSON()},pipe(){return(0,M.tT)(this,arguments)}},_=(0,l.XY)(2,(e,t)=>{if(e.backing.has(t))return c.some(e.backing.get(t));if(q(t))return c.none();let a=b.tW(t),l=e.buckets.get(a);return void 0===l?c.none():L(e,l,t)}),q=e=>"object"!=typeof e&&"function"!=typeof e,L=(e,t,a)=>{for(let l=0,i=t.length;l<i;l++)if(w.aI(a,t[l])){let a=t[l];return c.some(e.backing.get(a))}return c.none()},S=(0,l.XY)(2,(e,t)=>c.isSome(_(e,t))),B=(0,l.XY)(3,(e,t,a)=>{if(e.backing.has(t)||q(t))return e.backing.set(t,a),e;let l=b.tW(t),i=e.buckets.get(l);if(void 0===i)return e.buckets.set(l,[t]),e.backing.set(t,a),e;let s=A(i,t);return void 0===s&&(i.push(t),s=t),e.backing.set(s,a),e}),A=(e,t)=>{for(let a=0,l=e.length;a<l;a++)if(w.aI(t,e[a]))return e[a]},P=(0,l.XY)(2,(e,t)=>{if(q(t))return e.backing.delete(t),e;let a=b.tW(t),l=e.buckets.get(a);if(void 0===l)return e;for(let a=0,i=l.length;a<i;a++){let i=l[a];if(i===t||w.aI(t,i)){e.backing.delete(i),l.splice(a,1);break}}return 0===l.length&&e.buckets.delete(a),e}),V=w.Xq({_E:e=>e,_A:e=>e,_R:e=>e});({...i.In,"~effect/Request":V});a(4171);var H=a(9214);i.$n;let I=i.yw,$=s.Q7R;s.jBG,s.TSs,s.tfT,s.i8i,s.kAe;let F=s.jJl;s.d5f;let O=s.iMI,E=s.ivC,U=s.$mh,X=s.PyW;s.lwU,s.nGE;let T=s.DYE,R=s.OH5,Y=s.rIH;s.Vxk;let D=s.E2r,G=s.ZmZ;s.Do,s.JrD,s.uVU,s.oIE;let Z=s.JkU,j=s.fJG,N=s.gOk,W=s.ATB,J=s.pVV,K=s.F_Q,Q=s.SvU;s.m9E,s.KN3;let ee=i.R6;i.Hq;let et=s.yUA;s.sVm,s.pkL,s.bJ;let ea=s.qIB;s.Bqz;let el=s.hgn,ei=s.Mim,es=s.Ket,eo=s.uKv,er=s.NS5,en=s.TjK,ed=s.as;s.Xx$;let ec=s.NLW;s.UUz,s.yU6;let ep=s.OYO,eh=s.h_t,eg=s.KuX,eu=s.loE,ef=s.AXC;s.zt4,s.scW;let em=s.Tyx;s.Fig;let ev=s.XWm,ey=s.osR;s.U9Y,s.sJf,s.rNk;let ew=s.xm_;s.UcN;let ex=s.QgK,eb=s.sFT;s.k$L;let ek=s.dGm;s.cA6,s.bKC,s.nAi,s.u4Y;let eM=u;s._Sg;let ez=s.XeO,eC=s.GrF;s.$$g,s.DM4,s.Dd;let e_=s.wRz;s.D52;let eq=s.mgX;s.cbG;let eL=s.yy4;s.ayu,s.Vdx,s.FfP,s.O4F;let eS=s.KT6;s.pbD,s.x1Q,s.E8K,s.Pm0,s.VtY,s.W$I,s.ahH,s.z7s;let eB=s.YWq;s.G$Q,s.D$$,s.NZb,s.wR5;let eA=s.khu,eP=s.tvg;s.N6O,s.oJd;let eV=s._OA,eH=s.sxi,eI=d,e$=s.PpN;s.oao,s.euC;let eF=s.Nav;s.r_d,s.bUZ,s.L_I;let eO=s.PfK;s.c7E;let eE=s.z8E,eU=s.P1j,eX=s.Pxi,eT=s.Q56;s.N24;let eR=s.jGc,eY=s.U9h,eD=s.yeE,eG=s.S5A;s.BeE,s.iKM;let eZ=s.r7h,ej=s.cfM;s.fGe,s.uRq;let eN=s.PO3;s.Rgn,s.CJw;let eW=s.GaK;s.Inz,s.nAr;let eJ=s.rfi,eK=s.FcF;s.eMl,s.dsN;let eQ=s.i4r;s.aAq,s.Xrv,s.kJM,s._o1,s.nDN,s.MaT;let e1=s.Muk;s.ww9;let e0=s._32;s.Wj8,s.Fu6,s.WbR,s.A_r,s.Z98,s.Rd$,s.gvr;let e2=s.fRP;s.zr8,s.hq;let e3=s.zhn,e5=s.ar0,e4=s.x6Z;s.yxg,s.PCg,s.pEE,s.ABT;let e6=s.MY7,e7=s.eJC;s.lSz,s.bPG,s.pR5,s.v2Q,s.NpQ,s.jqV,s.HZF,s.lE;let e8=s.lKS;s.rfH;let e9=s.D9k,te=s.fn;s.RKA,s.lIX;let tt=s.lIX("Warn"),ta=s.lIX("Error"),tl=(0,l.XY)(e=>I(e[0]),(e,...t)=>s.bUZ(e,H.iL,e=>{let a=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||y.x(a,t[0],t[1]),a}));s.gsV;let ti=(e,t,a)=>(...l)=>D(i=>{let s,o=!0;try{e(...l,(e,a)=>{let r=e?t?T(()=>j(t(e,l))):j(e):X(a);o?s??=r:i(r)})}catch(e){s=a?j(a(e,l)):K(e)}o=!1,s&&i(s)}),ts=s.jkJ,to=s.Z9x,tr=s.q7Y,tn=s.Ab9,td=s.UVN,tc=s.vCS},3825(e,t,a){var l=a(1863);a.d(t,{},{bp:e=>(0,l.yj)({op:e.label,[l._3]:e.evaluate})})},6886(e,t,a){var l=a(4763),i=a(4674),s=a(6307);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=c.length;for(let l=a;l-- >0;)if(c[l]===e&&p[l]===t)return!0;if(a)return d(e,t);let l=h.get(e);l||h.set(e,l=new WeakMap);let i=l.get(t);return void 0===i&&l.set(t,i=d(e,t)),i}(e,t))}function d(e,t){c.push(e),p.push(t);try{return function(e,t){if(l.tW(e)!==l.tW(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let a=e.getTime(),l=t.getTime();return a===l||Number.isNaN(a)&&Number.isNaN(l)}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((0,i.B1)(e)){if(!(0,i.B1)(t)||e instanceof ArrayBuffer!=t instanceof ArrayBuffer)return!1;let a=(0,i._P)(e),l=(0,i._P)(t);return void 0!==a&&void 0!==l&&g(a,l)}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))}else 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,l.tW,n);var s=e,r=t;let d=(0,i.Xp)(s),c=(0,i.Xp)(r);if(d.size!==c.size)return!1;for(let e of d)if(!c.has(e)||!n(s[e],r[e]))return!1;return!0}(e,t)}finally{c.pop(),p.pop()}}let c=[],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,l){let i=new Map,s=0;for(let e of t){let t=a(e),l=i.get(t);l?l.push(e):i.set(t,[e]),s++}e:for(let t of e){let e=i.get(a(t));if(e){for(let a=0;a<e.length;a++)if(l(t,e[a])){e[a]=e[e.length-1],e.pop(),s--;continue e}}return!1}return 0===s}let f=e=>l.tW(e[0]),m=(e,t)=>n(e[0],t[0])&&n(e[1],t[1]),v=e=>(0,s.i5)(e,o)&&"function"==typeof e[o];a.d(t,{},{HR:o,Xq:e=>(i.J3.add(e),e),aI:r,jI:()=>r})},1058(e,t,a){let l=e=>(t,a)=>t===a||e(t,a),i=(e,t)=>e===t,s=l((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t));a.d(t,{},{L8:l,O3:function(e){return l((t,a)=>{if(t.length!==a.length)return!1;for(let l=0;l<t.length;l++)if(!e(t[l],a[l]))return!1;return!0})},Qw:i,YZ:()=>i,_k:function(e){let t=Reflect.ownKeys(e);return l((a,l)=>{for(let i of t)if(!e[i](a[i],l[i]))return!1;return!0})},rd:function(e){return l((t,a)=>{if(t.length!==a.length)return!1;for(let l=0;l<t.length;l++)if(!e[l](t[l],a[l]))return!1;return!0})},wN:s})},5596(e,t,a){var l=a(1863),i=a(7669);l.IH,l.b9;let s=l.xt,o=l.cb,r=l.Rk;l.V2,i._sz;let n=i.x5l,d=i.CoE,c=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:c,Py:s,fJ:r,oJ:d,rI:n})},6896(e,t,a){var l=a(6307),i=a(5257);function s(e,t){let a=t?.space??0,s=new WeakSet,c=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(s.has(a))return o;if(s.add(a),i.uC in a)g=e((0,i.f6)(a),h);else if(Array.isArray(a)){let t,l;g=!c||a.length<=1?`[${a.map(t=>e(t,h)).join(",")}]`:`[
413
+ `)}},d=new Proxy(globalThis.console,{get(e,t,a){if("log"===t)return(...t)=>{(1!==t.length||""!==t[0])&&e.log(...t)};let l=Reflect.get(e,t,a);return"function"==typeof l?l.bind(e):l}}),gE(mh,{version:"0.32.1"})(e).pipe(F.sFT(e=>el.i5(e,n8)&&"ShowHelp"!==e._tag?n6(n.formatErrors([e])):F.rIH),F.PfK(pB,{builtIns:[pz,pC,pq]}),F.PfK(cd,n),F.PfK(n5,d))).pipe(F.khu({onFailure:e=>F.JkU(function*(){let t,a=eF.getOrUndefined($.L$(e));if(a instanceof fy)return a.exitCode;if(a instanceof iz)return 7;let l=function(e){if(el.i5(e,n8))return"ShowHelp"===e._tag?2*(e.errors.length>0):2}(a);if(void 0!==l)return l;let i=yield*fv;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"===c?iJ({ok:!1,command:"sketchi",error:t}):fb(t))).pipe(F.MfU(()=>F.rIH)),1}),onSuccess:()=>F.PyW(0)}))}),mu=D.Um(iM.Txp,(0,iM.rRT)({createId:e=>`${e}_offline_cli`,icons:rV})),mf=D.Gt(i0,mu),mm=D.Gt(sl,mu),mv=D.Um(i7,o1),my=D.Gt(rt,mv),mw=D.Gt(rC,D.Um(my,rb)),mx=D.Gt(fE,fH),mb=D.Um(i7,o1,mf,mm,my,mw,rb,mx,fF,so.pipe(D.Gt(i7)),fx,n3),mk=D.S5(mb,ik);Y(mg(process.argv.slice(2)).pipe(F.Mim(e=>F.OH5(()=>{process.exitCode=e})),F.Gte(mk)),{disableErrorReporting:!0})},1688(e,t,a){var l=a(2390);let i=l.xCb(["invalid_render_artifact","render_limit_exceeded","unsupported_render_glyph","rasterization_failed"]),s=l.xCb(["artifact","geometry","font","rasterization"]);class o extends l.rNF()("HeadlessPngRenderError",{cause:l.kld(),code:i,stage:s,message:l.QfV,details:l.O31(l.QfV)}){}a.d(t,{},{FG:o})},5030(e,t,a){function l(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i(e,t,a,l){return{code:e,message:t,...void 0===a?{}:{observed:a},...void 0===l?{}:{limit:l}}}function s(e,t=0){let a=1/0,o=1/0,r=-1/0,n=-1/0;for(let t of e){if(!(l(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),s=Math.abs(t.height);if(e>8192||s>8192)return i("element_dimension",`element dimension exceeds ${String(8192)}`,Math.max(e,s),8192);let d=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])],l=[e.y,e.y+e.height,...t.map(t=>e.y+t[1])];return{left:Math.min(...a),top:Math.min(...l),right:Math.max(...a),bottom:Math.max(...l)}}(t);if(d){a=Math.min(a,d.left),o=Math.min(o,d.top),r=Math.max(r,d.right),n=Math.max(n,d.bottom);continue}let c=Math.hypot(e,s)/2,p=t.x+t.width/2,h=t.y+t.height/2;a=Math.min(a,p-c),o=Math.min(o,h-c),r=Math.max(r,p+c),n=Math.max(n,h+c)}if(0===e.length)return;let d=r-a,c=n-o;if(d>8192||c>8192)return i("canvas_dimension",`canvas dimension exceeds ${String(8192)}`,Math.max(d,c),8192);let p=d*c;if(p>6291456)return i("canvas_area",`canvas area exceeds ${String(6291456)}`,p,6291456);let h=(d+40)*1*((c+40+t)*1);if(h>0x1800000)return i("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,h,0x1800000)}a.d(t,{},{Gd:function(e,t=0){return s(e,t)?.message},Ts:s,Yu:function(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)},Z4:6291456,ce:0x1800000,jA:function(e,t){let a=new Set(t.flatMap(e=>l(e)&&"image"===e.type&&!0!==e.isDeleted&&"string"==typeof e.fileId?[e.fileId]:[])),s=0;for(let t of a){let a=Object.hasOwn(e,t)?e[t]:void 0,i=l(a)?a.dataURL:void 0;"string"==typeof i&&(s+=i.length)}return s>8388608?i("file_bytes",`embedded image data exceeds ${String(8388608)} bytes`,s,8388608):void 0}})},6982(e){e.exports=t("crypto")},7598(e){e.exports=t("node:crypto")},76(e,t,a){let l=a(9095),i=process.env;function s(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:l.map(function(e){return e.constant})}),t.name=null,t.isPR=null,t.id=null,"false"!==i.CI&&l.forEach(function(e){let a=(Array.isArray(e.env)?e.env:[e.env]).every(function(e){return s(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 s(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},5185(e,t,a){a.d(t,{CN:()=>g,BC:()=>m,Ie:()=>_,pb:()=>B,i8:()=>M,g9:()=>k,Uk:()=>z,Ts:()=>u,Yz:()=>S,CZ:()=>v,iX:()=>w,ET:()=>y,HV:()=>x,T9:()=>V,Tj:()=>L,YW:()=>f,of:()=>q,jB:()=>A,TS:()=>P,di:()=>C});var l=a(1058),i=a(4876);let s=e=>e.length>0;var o=a(6813),r=a(9974),n=a(3565),d=a(2538),c=a(841),p=a(2881);let h=globalThis.Array,g=e=>new h(o.S(e)),u=e=>h.isArray(e)?e:h.from(e);c.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=s,y=s;function w(e){let t=Number(e);return String(t)===e&&Number.isInteger(t)&&t>=0&&t<0xffffffff}let x=e=>y(e)?n.some(b(e)):n.none(),b=e=>e[e.length-1],k=(0,i.XY)(2,(e,t)=>{let a=0;for(let l of e){if(t(l,a))return n.some(a);a++}return n.none()}),M=r.i8,z=(0,i.XY)(2,(e,t)=>{let a=u(e);for(let e=a.length-1;e>=0;e--){let l=a[e],i=t(l,e);if("boolean"==typeof i){if(i)return n.some(l)}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}),_=()=>[],q=e=>[e],L=(0,i.XY)(2,(e,t)=>e.map(t)),S=e=>{let t=[];for(let a of e)n.isSome(a)&&t.push(a.value);return t},B=(0,i.XY)(2,(e,t)=>{let a=u(e),l=[];for(let e=0;e<a.length;e++)t(a[e],e)&&l.push(a[e]);return l}),A=(0,i.XY)(2,(e,t)=>{let a=[],l=[],i=0;for(let s of e){let e=t(s,i++);p.oJ(e)?a.push(e.success):l.push(e.failure)}return[a,l]}),P=(0,i.XY)(3,(e,t,a)=>u(e).reduce((e,t,l)=>a(e,t,l),t));d.O3;let V=l.O3},8895(e,t,a){var l=a(6681),i=a(1058),s=a(4876),o=a(3565),r=a(2538),n=a(6307),d=a(5770);let c=globalThis.BigInt,p=c(0);n.sI;let h=(0,s.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=d.L((e,t)=>e+t,p),z=l.T9(g),C=l.jk(g);a.d(t,{},{K0:C,OW:y,Ro:e=>e>c(Number.MAX_SAFE_INTEGER)||e<c(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:z,yJ:v})},723(e,t,a){var l=a(8895),i=a(3565);let s=BigInt(0),o=BigInt(1),r=BigInt(1e3),n=BigInt(1024),d=[{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"]}],c=[d[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([...d,...c.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[2]);if(void 0===a)return h(`unsupported unit ${JSON.stringify(t[2])}`);let l=((e,t)=>{let a=/^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(e);if(null===a)return;let l=a[2]??"",i=BigInt(a[1]+l)*t,o=Number(a[3]??0)-l.length;if(o>=0)return i*BigInt(10)**BigInt(o);let r=BigInt(10)**BigInt(-o);return i%r===s?i/r:void 0})(t[1],a.factor);return void 0===l?h(`${JSON.stringify(e)} does not represent an integral number of bytes`):l},f=i.liftThrowable(u),m=e=>{switch(typeof e){case"bigint":if(e<s)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=l.Ro;l.pH,l.rs,l.Tq,l.jk,l.T9,l.qE,l.hl,l.bi,l.yJ,l.OW,l.cz,l.aD,l.sO,l.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>=s})},6313(e,t,a){var l=a(1863),i=a(7669);l.PX,l.B4;let s=l.Aj;l.Wg;let o=l.lC,r=l.Xb;l.ik;let n=l.b5;l.DH;let d=l.OE,c=l.Iu;i.nIy,i.ORc;let p=i.nn5,h=i.O$X;l.h2;let g=i.ReC;i.myX,i.QE5,i.khU;let u=i.L$u;i.gpn,i.k7S,i.BbX;let f=i.prj;i.tU5,i.h74,i.Bou,i.RJ6;let m=i.GyP;l.PW,l.qB,l.Xm;let v=l.$L;l.q_;let y=l.RS,w=l.Vw;i.DQo,i.c8t,i.MUS,i.t8c,i._y;let x=i.qwd;i.ASO,i.F7W,i.Aub,i.cOF,i.Rft,i.RD4,i.Kkt,i.PnV;let b=i.Bk6;l.Eh;let k=i.tQ6;i.On5,a.d(t,{},{$E:e=>new l.pg(e),$L:v,Aj:s,Bk:b,F_:c,Jh:e=>new l.dM(e),L$:u,RS:y,Tj:h,Vw:w,Xb:r,fJ:d,iw:g,j9:m,kO:n,lC:o,nn:p,pr:f,qw:x,tQ:k})},760(e,t,a){var l=a(7669);l.a1U,l.RKA;let i=l.Rud;l.s0X,l.T13,a.d(t,{},{Ru:i})},6681(e,t,a){function l(e){return{combine:e}}a.d(t,{},{L8:l,T9:function(e){return l((t,a)=>1===e(t,a)?t:a)},jk:function(e){return l((t,a)=>-1===e(t,a)?t:a)}})},369(e,t,a){var l=a(3825),i=a(6886),s=a(4876),o=a(4763),r=a(1863),n=a(3565),d=a(6307);let c="~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={[c]:c,...l.bp({label:"Service",evaluate(e){return(0,r.xt)(P(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(P(t.context,this)))},useSync(e){return(0,r.R6)(t=>(0,r.xt)(e(P(t.context,this))))}},g=new Set,u="~effect/Context/Reference",f="~effect/Context",m=(e,t,a,l,i)=>{let s=Object.create(k);return s.cacheRoot=e??s,s.base=t,s.overlay=a,s.depth=l,s._flat=void 0,s.baseHits=0,s.maxDepth=i,s},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,t)=>{let a=t?.maxDepth;return m(void 0,e,void 0,0,Number.isInteger(a)&&a>=0?a:8)},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,l]of t)if(!a.has(e)||!i.aI(l,a.get(e)))return!1;return!0},[o.HR](){return o.ai(this.mapUnsafe.size)}},M=e=>(0,d.i5)(e,f),z=e=>!!e[u],C=b(new Map),_=(e,t)=>b(new Map([[e.key,t]])),q=(0,s.XY)(3,(e,t,a)=>L(e,t.key,a)),L=(e,t,a)=>{let l=g.has(t)?void 0:e.cacheRoot;if(e.depth>=e.maxDepth){let i=new Map(e._flat??e.base);return e._flat||v(i,e.overlay),i.set(t,a),m(l,i,void 0,0,e.maxDepth)}return m(l,e.base,{key:t,value:a,parent:e.overlay},e.depth+1,e.maxDepth)},S=(0,s.XY)(2,(e,t)=>B(e,t.key)),B=(e,t)=>{let a=x(e,t);return a===w?void 0:a},A=(0,s.XY)(2,(e,t)=>{let a=x(e,t.key);if(a===w){if(z(t))return H(t);throw I(t)}return a}),P=A,V="~effect/Context/defaultValue",H=e=>V in e?e[V]:e[V]=e.defaultValue(),I=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},$=(0,s.XY)(2,(e,t)=>{let a=x(e,t.key);return a!==w?n.some(a):z(t)?n.some(H(t)):n.none()}),F=(0,s.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)),m(void 0,a,void 0,0,e.maxDepth))});a.d(t,{},{Ie:()=>C,Jt:P,L8:_,LZ:b,Or:p,Pf:(e,t)=>e.cacheRoot===t.cacheRoot,Ub:B,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:q,Y6:S,aE:M,fp:A,h1:F,kl:p,om:$})},2788(e,t,a){var l=a(1863),i=a(5005),s=a(244),o=a(6307);let r=class extends s.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 d=l.$D,c=l.rN;a.d(t,{},{$D:d,Ij:()=>new Proxy({},{get:(e,t,a)=>"$is"===t?o.$J:"$match"===t?n:e=>({...e,_tag:t})}),Xs:r,rN:c})},9303(e,t,a){var l=a(4876),i=a(1863),s=a(7669),o=a(244);let r={"~effect/Deferred":{_A:l.D_,_E:l.D_},pipe(){return(0,o.tT)(this,arguments)}},n=function(){this.resumes=void 0,this.effect=void 0};n.prototype=r;let d=(0,l.XY)(2,(e,t)=>s.OH5(()=>h(e,t))),c=(0,l.XY)(2,(e,t)=>d(e,i.Rk(t))),p=e=>void 0!==e.effect,h=(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};a.d(t,{},{$L:e=>s.OH5(()=>p(e)),$w:h,LZ:()=>new n,NJ:p,Tx:e=>s.E2r(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),s.OH5(()=>{let a=e.resumes;if(void 0===a)return;let l=a.indexOf(t);l>=0&&a.splice(l,1)}))),fJ:c})},328(e,t,a){var l=a(6886),i=a(4876),s=a(4763),o=a(8946),r=a(2538),n=a(244),d=a(6307);let c="~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=BigInt(1e9),x=BigInt(6e10),b=BigInt(36e11),k=BigInt(864e11),M=BigInt(6048e11),z=e=>BigInt(Math.sign(e)*Math.round(Math.abs(e))),C=e=>Number.isInteger(e)?BigInt(e)*y:z(1e6*e),_=e=>U(Number.isFinite(e)?z(e):e),q=(e,t)=>{let a=Number(e);if(Number.isFinite(a))return a/t;let l=BigInt(t);return Number(e/l)+Number(e%l)/t},L=(e,t)=>{let a=e.indexOf(".");if(-1===a)return BigInt(e)*t;let l="-"===e[0],i=e.slice(a+1),s=u**BigInt(i.length),o=(BigInt(e.slice(+!!l,a))*s+BigInt(i))*t;return S(l?-o:o,s)},S=(e,t)=>{let a=e<p?-e:e,l=a/t+(a%t*g>=t?h:p);return e<p?-l:l},B=(e,t)=>{let a=Number(e)*t;if(!Number.isFinite(a))return U(a);let l=L(e,BigInt(t)*y);return U(Number.isInteger(a)&&BigInt(a)*y===l?a:l)},A=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,P=e=>{switch(typeof e){case"number":return Z(e);case"bigint":return G(e);case"string":{if("Infinity"===e)return Y;if("-Infinity"===e)return D;let t=A.exec(e);if(!t)break;let[a,l,i]=t;if("nano"===i||"nanos"===i)return G(L(l,h));if("micro"===i||"micros"===i)return G(L(l,v));switch(i){case"milli":case"millis":return B(l,1);case"second":case"seconds":return B(l,1e3);case"minute":case"minutes":return B(l,6e4);case"hour":case"hours":return B(l,36e5);case"day":case"days":return B(l,864e5);case"week":case"weeks":return B(l,6048e5)}break}case"object":{if(null===e)break;if(c in e)return e;if(Array.isArray(e)){if(2!==e.length||!e.every(d.Et))return I(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return R;if(-1/0===e[0]||-1/0===e[1])return D;if(1/0===e[0]||1/0===e[1])return Y;let t=1e9*e[0]+e[1];return Number.isFinite(t)&&Number.isInteger(e[0])&&Number.isInteger(e[1])?U(BigInt(e[0])*w+BigInt(e[1])):_(t)}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){if(!Number.isFinite(t))return U(t);let a=H(e);return void 0===a||BigInt(t)*y===a?U(t):U(a)}let a=1e6*t+(e.microseconds??0)*1e3+(e.nanoseconds??0),l=Number.isFinite(a)?H(e):void 0;return void 0===l?_(a):U(l)}}return I(e)},V=e=>!e||Number.isInteger(e),H=e=>{if(!V(e.weeks)||!V(e.days)||!V(e.hours)||!V(e.minutes)||!V(e.seconds)||!V(e.milliseconds)||!V(e.microseconds)||!V(e.nanoseconds))return;let t=p;return e.weeks&&(t+=BigInt(e.weeks)*M),e.days&&(t+=BigInt(e.days)*k),e.hours&&(t+=BigInt(e.hours)*b),e.minutes&&(t+=BigInt(e.minutes)*x),e.seconds&&(t+=BigInt(e.seconds)*w),e.milliseconds&&(t+=BigInt(e.milliseconds)*y),e.microseconds&&(t+=BigInt(e.microseconds)*v),e.nanoseconds&&(t+=BigInt(e.nanoseconds)),t},I=e=>{throw Error(`Invalid Input: ${e}`)},$={_tag:"Millis",millis:0},F={_tag:"Infinity"},O={_tag:"NegativeInfinity"},E={[c]:c,[s.HR](){switch(this.value._tag){case"Millis":return s.tW(C(this.value.millis));case"Nanos":return s.tW(this.value.nanos);default:return s.QK(this.value)}},[l.HR](e){return X(e)&&Q(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)}},U=e=>{let t=Object.create(E);return"number"==typeof e?isNaN(e)||0===e||Object.is(e,-0)?t.value=$:Number.isFinite(e)?Number.isInteger(e)?t.value={_tag:"Millis",millis:e}:t.value={_tag:"Nanos",nanos:C(e)}:t.value=e>0?F:O:e===p?t.value=$:t.value={_tag:"Nanos",nanos:e},t},X=e=>(0,d.i5)(e,c),T=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}},R=U(0),Y=U(1/0),D=U(-1/0),G=e=>U(e),Z=e=>U(e),j=e=>{let t=P(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 C(t.value.millis)}},N=(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)()}}),W=(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(j(e),t.value.nanos):a.onNanos(e.value.nanos,j(t))),J=r.L8((e,t)=>W(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})),K=r.bi(J),Q=(0,i.XY)(2,(e,t)=>W(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag})),ee=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(T(e))return"-"+ee((e=>{switch(e.value._tag){case"Infinity":case"NegativeInfinity":return Y;case"Millis":return e.value.millis<0?U(-e.value.millis):e;case"Nanos":return e.value.nanos<p?U(-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=j(e),a=t<p,l=a?-t:t,i=l/y,s=i/v,o=s/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(s%m),millis:n*Number(i%v),nanos:n*Number(l%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:ee,MI:e=>"Infinity"!==e.value._tag&&"NegativeInfinity"!==e.value._tag,Tn:Y,YA:e=>U(1e3*e),bN:P,bi:K,cF:G,cI:T,fP:e=>N(P(e),{onMillis:e=>e/1e3,onNanos:e=>q(e,1e9),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),kE:e=>N(P(e),{onMillis:i.D_,onNanos:e=>q(e,1e6),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),n$:X,ne:Z,qv:D,v_:R})},639(e,t,a){a.d(t,{Q56:()=>eT,jGc:()=>eR,U9h:()=>eY,Q7R:()=>$,hgn:()=>el,swY:()=>tl,Muk:()=>e1,as:()=>ed,NLW:()=>ec,PO3:()=>eN,E2r:()=>D,MfU:()=>eh,Tyx:()=>em,UVN:()=>td,osR:()=>ey,XWm:()=>ev,AXC:()=>ef,KuX:()=>eg,loE:()=>eu,_OA:()=>eV,sxi:()=>eH,_32:()=>e0,F_Q:()=>K,_r7:()=>ti,yeE:()=>eD,NS5:()=>er,fJG:()=>j,ATB:()=>W,pVV:()=>J,gOk:()=>N,qIB:()=>ea,Ab9:()=>tn,fn:()=>te,D9k:()=>e9,vCS:()=>tc,jJl:()=>F,i4r:()=>eQ,zhn:()=>e3,ar0:()=>e5,x6Z:()=>e4,yUA:()=>et,JkU:()=>Z,XeO:()=>ez,GrF:()=>eC,GaK:()=>eW,yw5:()=>I,vVN:()=>ta,FFw:()=>tt,TjK:()=>en,q7Y:()=>tr,jkJ:()=>ts,xm_:()=>ew,Z9x:()=>to,YWq:()=>eB,khu:()=>eA,tvg:()=>eP,ZmZ:()=>G,S5A:()=>eG,cfM:()=>ej,r7h:()=>eZ,uKv:()=>eo,QgK:()=>ex,ivC:()=>E,Gte:()=>eI,PpN:()=>e$,PfK:()=>eO,KT6:()=>eS,Ket:()=>es,L5P:()=>eM,MY7:()=>e6,eJC:()=>e7,lKS:()=>e8,z8E:()=>eE,P1j:()=>eU,Pxi:()=>eX,Nav:()=>eF,yy4:()=>eL,PyW:()=>X,DYE:()=>T,OH5:()=>R,Mim:()=>ei,dGm:()=>ek,sFT:()=>eb,wRz:()=>e_,mgX:()=>eq,SvU:()=>Q,$mh:()=>U,rfi:()=>eJ,FcF:()=>eK,rIH:()=>Y,iMI:()=>O,R6R:()=>ee,fRP:()=>e2,OYO:()=>ep});var l=a(4876),i=a(1863),s=a(7669),o=(a(328),a(369));a(2881);var r=a(4577),n=a(6215);let d=(0,l.XY)(e=>(0,i.yw)(e[0]),(e,t,a)=>{let l;return o.aE(t)?s.PpN(e,t):(l=Array.isArray(t)?n.Um(...t):t,s.Pxi(t=>s.qIB(a?.local?n.H7(l,n.j6(),t):n.LT(l,t),t=>s.PpN(e,t))))});var c=a(3565),p=a(3271),h=a(471);(e,t,a)=>s.qIB(r.xn(t),t=>{let l=r.d3.defaultValue(),i=a=>p.tv(t(a),{onSuccess:t=>(l=t,s.qIB(s.PfK(e,r.d3,l),i)),onFailure:s.ATB,onDone:s.PyW});return s.rNk(s.qIB(s.PfK(e,r.d3,l),i),s.ovK,e=>a(e,0===l.attempt?c.none():c.some(l)))});let g=(0,l.XY)(3,(e,t,a)=>s.qIB(r.xn(t),t=>{let l,i=r.d3.defaultValue(),o=s.rNk(s.DYE(()=>s.PfK(e,r.d3,i)),s.ovK,e=>(l=e,s.qIB(t(e),e=>(i=e,o))));return p.m8(o,e=>(0,h.s)(()=>a(l,e)))})),u=(0,l.XY)(2,(e,t)=>g(e,"function"==typeof t?t(l.D_):r.GM(t)?t:m(t),s.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:s.PyW(a)})),e.until&&(t=r.E6(t,({input:t})=>{let a=e.until(t);return i.yw(a)?s.TjK(a,e=>!e):s.PyW(!a)})),void 0!==e.times&&(t=r.E6(t,({attempt:t})=>s.PyW(t<=e.times))),t},v=r.t5(1);var y=a(5005),w=a(6886),x=a(6896),b=a(4763),k=a(8946),M=a(244);let z="~effect/MutableHashMap",C={[z]:z,[Symbol.iterator](){return this.backing[Symbol.iterator]()},toString(){return`MutableHashMap(${(0,x.GP)(Array.from(this))})`},toJSON(){return{_id:"MutableHashMap",values:(0,k.aB)(Array.from(this))}},[k.FX](){return this.toJSON()},pipe(){return(0,M.tT)(this,arguments)}},_=(0,l.XY)(2,(e,t)=>{if(e.backing.has(t))return c.some(e.backing.get(t));if(q(t))return c.none();let a=b.tW(t),l=e.buckets.get(a);return void 0===l?c.none():L(e,l,t)}),q=e=>"object"!=typeof e&&"function"!=typeof e,L=(e,t,a)=>{for(let l=0,i=t.length;l<i;l++)if(w.aI(a,t[l])){let a=t[l];return c.some(e.backing.get(a))}return c.none()},S=(0,l.XY)(2,(e,t)=>c.isSome(_(e,t))),B=(0,l.XY)(3,(e,t,a)=>{if(e.backing.has(t)||q(t))return e.backing.set(t,a),e;let l=b.tW(t),i=e.buckets.get(l);if(void 0===i)return e.buckets.set(l,[t]),e.backing.set(t,a),e;let s=A(i,t);return void 0===s&&(i.push(t),s=t),e.backing.set(s,a),e}),A=(e,t)=>{for(let a=0,l=e.length;a<l;a++)if(w.aI(t,e[a]))return e[a]},P=(0,l.XY)(2,(e,t)=>{if(q(t))return e.backing.delete(t),e;let a=b.tW(t),l=e.buckets.get(a);if(void 0===l)return e;for(let a=0,i=l.length;a<i;a++){let i=l[a];if(i===t||w.aI(t,i)){e.backing.delete(i),l.splice(a,1);break}}return 0===l.length&&e.buckets.delete(a),e}),V=w.Xq({_E:e=>e,_A:e=>e,_R:e=>e});({...i.In,"~effect/Request":V});a(4171);var H=a(9214);i.$n;let I=i.yw,$=s.Q7R;s.jBG,s.TSs,s.tfT,s.i8i,s.kAe;let F=s.jJl;s.d5f;let O=s.iMI,E=s.ivC,U=s.$mh,X=s.PyW;s.lwU,s.nGE;let T=s.DYE,R=s.OH5,Y=s.rIH;s.Vxk;let D=s.E2r,G=s.ZmZ;s.Do,s.JrD,s.uVU,s.oIE;let Z=s.JkU,j=s.fJG,N=s.gOk,W=s.ATB,J=s.pVV,K=s.F_Q,Q=s.SvU;s.m9E,s.KN3;let ee=i.R6;i.Hq;let et=s.yUA;s.sVm,s.pkL,s.bJ;let ea=s.qIB;s.Bqz;let el=s.hgn,ei=s.Mim,es=s.Ket,eo=s.uKv,er=s.NS5,en=s.TjK,ed=s.as;s.Xx$;let ec=s.NLW;s.UUz,s.yU6;let ep=s.OYO,eh=s.h_t,eg=s.KuX,eu=s.loE,ef=s.AXC;s.zt4,s.scW;let em=s.Tyx;s.Fig;let ev=s.XWm,ey=s.osR;s.U9Y,s.sJf,s.rNk;let ew=s.xm_;s.UcN;let ex=s.QgK,eb=s.sFT;s.k$L;let ek=s.dGm;s.cA6,s.bKC,s.nAi,s.u4Y;let eM=u;s._Sg;let ez=s.XeO,eC=s.GrF;s.$$g,s.DM4,s.Dd;let e_=s.wRz;s.D52;let eq=s.mgX;s.cbG;let eL=s.yy4;s.ayu,s.Vdx,s.FfP,s.O4F;let eS=s.KT6;s.pbD,s.x1Q,s.E8K,s.Pm0,s.VtY,s.W$I,s.ahH,s.z7s;let eB=s.YWq;s.G$Q,s.D$$,s.NZb,s.wR5;let eA=s.khu,eP=s.tvg;s.N6O,s.oJd;let eV=s._OA,eH=s.sxi,eI=d,e$=s.PpN;s.oao,s.euC;let eF=s.Nav;s.r_d,s.bUZ,s.L_I;let eO=s.PfK;s.c7E;let eE=s.z8E,eU=s.P1j,eX=s.Pxi,eT=s.Q56;s.N24;let eR=s.jGc,eY=s.U9h,eD=s.yeE,eG=s.S5A;s.BeE,s.iKM;let eZ=s.r7h,ej=s.cfM;s.fGe,s.uRq;let eN=s.PO3;s.Rgn,s.CJw;let eW=s.GaK;s.Inz,s.nAr;let eJ=s.rfi,eK=s.FcF;s.eMl,s.dsN;let eQ=s.i4r;s.aAq,s.Xrv,s.kJM,s._o1,s.nDN,s.MaT;let e1=s.Muk;s.ww9;let e0=s._32;s.Wj8,s.Fu6,s.WbR,s.A_r,s.Z98,s.Rd$,s.gvr;let e2=s.fRP;s.zr8,s.hq;let e3=s.zhn,e5=s.ar0,e4=s.x6Z;s.yxg,s.PCg,s.pEE,s.ABT;let e6=s.MY7,e7=s.eJC;s.lSz,s.bPG,s.pR5,s.v2Q,s.NpQ,s.jqV,s.HZF,s.lE;let e8=s.lKS;s.rfH;let e9=s.D9k,te=s.fn;s.RKA,s.lIX;let tt=s.lIX("Warn"),ta=s.lIX("Error"),tl=(0,l.XY)(e=>I(e[0]),(e,...t)=>s.bUZ(e,H.iL,e=>{let a=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||y.x(a,t[0],t[1]),a}));s.gsV;let ti=(e,t,a)=>(...l)=>D(i=>{let s,o=!0;try{e(...l,(e,a)=>{let r=e?t?T(()=>j(t(e,l))):j(e):X(a);o?s??=r:i(r)})}catch(e){s=a?j(a(e,l)):K(e)}o=!1,s&&i(s)}),ts=s.jkJ,to=s.Z9x,tr=s.q7Y,tn=s.Ab9,td=s.UVN,tc=s.vCS},3825(e,t,a){var l=a(1863);a.d(t,{},{bp:e=>(0,l.yj)({op:e.label,[l._3]:e.evaluate})})},6886(e,t,a){var l=a(4763),i=a(4674),s=a(6307);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=c.length;for(let l=a;l-- >0;)if(c[l]===e&&p[l]===t)return!0;if(a)return d(e,t);let l=h.get(e);l||h.set(e,l=new WeakMap);let i=l.get(t);return void 0===i&&l.set(t,i=d(e,t)),i}(e,t))}function d(e,t){c.push(e),p.push(t);try{return function(e,t){if(l.tW(e)!==l.tW(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let a=e.getTime(),l=t.getTime();return a===l||Number.isNaN(a)&&Number.isNaN(l)}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((0,i.B1)(e)){if(!(0,i.B1)(t)||e instanceof ArrayBuffer!=t instanceof ArrayBuffer)return!1;let a=(0,i._P)(e),l=(0,i._P)(t);return void 0!==a&&void 0!==l&&g(a,l)}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))}else 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,l.tW,n);var s=e,r=t;let d=(0,i.Xp)(s),c=(0,i.Xp)(r);if(d.size!==c.size)return!1;for(let e of d)if(!c.has(e)||!n(s[e],r[e]))return!1;return!0}(e,t)}finally{c.pop(),p.pop()}}let c=[],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,l){let i=new Map,s=0;for(let e of t){let t=a(e),l=i.get(t);l?l.push(e):i.set(t,[e]),s++}e:for(let t of e){let e=i.get(a(t));if(e){for(let a=0;a<e.length;a++)if(l(t,e[a])){e[a]=e[e.length-1],e.pop(),s--;continue e}}return!1}return 0===s}let f=e=>l.tW(e[0]),m=(e,t)=>n(e[0],t[0])&&n(e[1],t[1]),v=e=>(0,s.i5)(e,o)&&"function"==typeof e[o];a.d(t,{},{HR:o,Xq:e=>(i.J3.add(e),e),aI:r,jI:()=>r})},1058(e,t,a){let l=e=>(t,a)=>t===a||e(t,a),i=(e,t)=>e===t,s=l((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t));a.d(t,{},{L8:l,O3:function(e){return l((t,a)=>{if(t.length!==a.length)return!1;for(let l=0;l<t.length;l++)if(!e(t[l],a[l]))return!1;return!0})},Qw:i,YZ:()=>i,_k:function(e){let t=Reflect.ownKeys(e);return l((a,l)=>{for(let i of t)if(!e[i](a[i],l[i]))return!1;return!0})},rd:function(e){return l((t,a)=>{if(t.length!==a.length)return!1;for(let l=0;l<t.length;l++)if(!e[l](t[l],a[l]))return!1;return!0})},wN:s})},5596(e,t,a){var l=a(1863),i=a(7669);l.IH,l.b9;let s=l.xt,o=l.cb,r=l.Rk;l.V2,i._sz;let n=i.x5l,d=i.CoE,c=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:c,Py:s,fJ:r,oJ:d,rI:n})},6896(e,t,a){var l=a(6307),i=a(5257);function s(e,t){let a=t?.space??0,s=new WeakSet,c=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(s.has(a))return o;if(s.add(a),i.uC in a)g=e((0,i.f6)(a),h);else if(Array.isArray(a)){let t,l;g=!c||a.length<=1?`[${a.map(t=>e(t,h)).join(",")}]`:`[
414
414
  ${t=h+1,c.repeat(t)}${a.map(t=>e(t,h+1)).join(",\n"+(l=h+1,c.repeat(l)))}
415
415
  ${c.repeat(h)}]`}else if(a instanceof Date)g=n(a);else if(!t?.ignoreToString&&l.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(!c||t.length<=1){let l=`{${t.map(t=>`${r(t)}:${e(d(a,t),h)}`).join(",")}}`;g=p(a,l)}else{let l=`{
416
416
  ${t.map(t=>{let l;return`${l=h+1,c.repeat(l)}${r(t)}: ${e(d(a,t),h+1)}`}).join(",\n")}
@@ -424,7 +424,7 @@ ${t}${a[e]}`;return e.cause&&(l+=` {
424
424
  ${ey(e.cause,`${t} `)}
425
425
  ${t}}`),l},ew="~effect/Fiber",ex={_A:m.D_,_E:m.D_},eb={id:0},ek=(()=>{try{return globalThis.process?.getBuiltinModule?.("node:async_hooks")?.AsyncResource}catch{return}})(),eM=()=>void 0===ek?void 0:new ek("effect/Fiber"),ez=()=>globalThis[q.fL];class eC{constructor(e,t=!0){this.setContext(e),this.id=++eb.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[ew](){return ex}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return g.Jt(this.context,e)}addObserver(e){return this._exit?(e(this._exit),m.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=T(e);this.cache.stackFrame&&(a=(0,A.Eh)(a,g.L8(A.z8,this.cache.stackFrame))),t&&(a=(0,A.Eh)(a,t)),this._interruptedCause=this._interruptedCause?(0,A.ND)(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;this._asyncContext=void 0;try{return t.runInAsyncScope(this.evaluate,this,e)}finally{t.emitDestroy()}}if(void 0!==this._yielded){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===A.GN){this._asyncContext=eM();return}let a=eS.interruptChildren&&eS.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=g.Ie();let l=this.cache;(void 0!==l.span||void 0!==l.stackFrame)&&(this.cache={...l,span:void 0,stackFrame:void 0})}runLoop(e){let t=globalThis[q.fL];globalThis[q.fL]=this;let a=this._running;this._running=!0;let l=!1,i=e;this.currentOpCount=0;try{for(;;)try{this._deferredInterrupt&&(this._deferredInterrupt=!1,i=eX(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!l&&!e.preventYield&&e.scheduler.shouldYield(this)){l=!0;let e=i;i=tV(eN,()=>e)}if((i=e.tracerContext?e.tracerContext(i,this):i[A._3](this))===A.GN){let e=this._yielded;if(A.IH in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return A.GN}}catch(e){if(!(0,y.i5)(i,A._3))return(0,A.V2)(`Fiber.runLoop: Not a valid effect: ${String(i)}`);i=(0,A.V2)(e)}}finally{this._running=a,globalThis[q.fL]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,eq;for(;;){let t=this._stack.pop();if(!t)return;let a=t[A.u4];if(void 0!==a){let l=a.call(t,this);if(l)return l[e]=l,l}if(t[e])return t}}succeedWith(e){if((++this.currentOpCount&eL-1)==0)return(0,A.xt)(e);let t=this.getCont(A.ee);return t?t[A.ee](e,this):this.yieldWith((0,A.xt)(e))}yieldWith(e){return this._yielded=e,A.GN}children(){return this._children??=new Set}pipe(){return(0,_.tT)(this,arguments)}setContext(e){let t=this.context;if(this.context=e,void 0!==t&&g.Pf(t,e))return;let a=e.cacheRoot,l=a._fiberCache??=e_(e);this.cache?.scheduler!==l.scheduler&&(this._dispatcher=void 0),this.cache=l}get currentSpanLocal(){let e=this.cache.span;return e?._tag==="Span"?e:void 0}}let e_=e=>{let t=g.Ub(e,S.RL);return{scheduler:g.Jt(e,L._F),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:g.Jt(e,I.rf),span:g.Ub(e,S.WG),logLevel:g.Jt(e,I.Gl),minimumLogLevel:g.Jt(e,I.zQ),stackFrame:g.Jt(e,I.vA),runtimeMetrics:g.Ub(e,V.F),maxOpsBeforeYield:g.Jt(e,L.Zm),preventYield:g.Jt(e,L.hf)}},eq={[A.ee]:(e,t)=>eX(t._interruptedCause),[A.Sc]:(e,t)=>eX(t._interruptedCause)},eL=32,eS={interruptChildren:void 0},eB=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(A.QJ.key,e.cache.stackFrame),g.LZ(t)},eA=e=>{if(void 0!==e._children&&0!==e._children.size)return eO(e._children)},eP=e=>e._exit?eU(e._exit):te(t=>e._exit?t(eU(e._exit)):eR(e.addObserver(e=>t(eU(e))))),eV=e=>te(t=>{let a,l=e[Symbol.iterator](),i=[];return!function e(){let s=l.next();for(;!s.done;){if(s.value._exit){i.push(s.value._exit),s=l.next();continue}a=s.value.addObserver(t=>{i.push(t),e()});return}t(eU(i))}(),eR(()=>a?.())}),eH=e=>e._exit?e._exit:te(t=>e._exit?t(e._exit):eR(e.addObserver(t))),eI=e=>te(t=>{let a=Array.from(e);if(0===a.length)return t(eU(h.Ie()));let l=Array(a.length),i=h.Ie(),s=()=>{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,s(),t(i);l[e]=i.value,o===a.length&&t(eU(l))};i.push(n),a[e].addObserver(n)}return eR(()=>{r=!0,s()})}),e$=e=>(0,A.R6)(t=>eF(e,t.id)),eF=(0,m.XY)(e=>(0,y.i5)(e[0],ew),(e,t,a)=>(0,A.R6)(l=>{let i=eB(l);return i=i&&a?g.h1(i,a):i??a,e.interruptUnsafe(t,i),tq(eP(e))})),eO=e=>(0,A.R6)(t=>{let a=eB(t),l=h.Ie();for(let i of e)i.interruptUnsafe(t.id,a),l.push(i);return tq(eV(l))}),eE=(0,m.XY)(2,(e,t)=>(0,A.R6)(a=>{let l=eB(a),i=h.Ie();for(let a of e)a.interruptUnsafe(t,l),i.push(a);return tq(eV(i))})),eU=A.xt,eX=A.cb,eT=A.Rk,eR=(0,A.Uf)({op:"Sync",[A._3](e){let t=(0,this[A.a2])(),a=e.getCont(A.ee);return a?a[A.ee](t,e):e.yieldWith((0,A.xt)(t))}}),eY=(0,A.Uf)({op:"Suspend",[A._3](e){return(0,this[A.a2])()}}),eD=(0,m.XY)(e=>e.length>=2||v.isOption(e[0]),(e,t)=>v.isNone(e)?t?e0(t):eT(new A.Xm("Effect.fromOption: Option.none")):eU(e.value)),eG=w.YW({onFailure:eT,onSuccess:eU}),eZ=e=>null==e?eT(new A.Xm):eU(e),ej=(0,A.Uf)({op:"Yield",[A._3](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{t||e.evaluate(t0)},this[A.a2]??0),e.yieldWith(()=>{t=!0})}}),eN=ej(0),eW=e=>eU(v.some(e)),eJ=eU(v.none()),eK=e=>v.isNone(e)?eJ:tO(e.value,v.some),eQ=e=>eY(()=>eX(e())),e1=e=>(0,A.V2)(e),e0=e=>eY(()=>eT(e())),e2=eU(void 0),e3=e=>{let t="function"==typeof e?e:e.try,a="function"==typeof e?e=>new sE(e,"An error occurred in Effect.try"):e.catch;return eY(()=>{try{return eU(t())}catch(e){return eT(a(e))}})},e5=e=>e8(function(t,a){e(a).then(e=>t(eU(e)),e=>t(e1(e)))},0!==e.length),e4=e=>{let t="function"==typeof e?e:e.try,a="function"==typeof e?e=>new sE(e,"An error occurred in Effect.tryPromise"):e.catch;return e8(function(e,l){let i=e=>eY(()=>{try{return eT((0,B.s)(()=>a(e)))}catch(e){return e1(e)}});try{t(l).then(t=>e(eU(t)),t=>e(i(t)))}catch(t){e(i(t))}},0!==t.length)},e6=(0,A.R6)(eU),e7=(0,A.R6)(e=>eU(e.id)),e8=(l=(0,A.yj)({op:"Async",[A._3](e){let t=!1,a=!1,l=this.withSignal?new AbortController:void 0,i=this.register.call(e.cache.scheduler,l=>{t||(t=!0,a?e.evaluate(l):a=l)},l?.signal);return!1!==a?a:(a=!0,e.yieldWith(()=>{t=!0}),void 0===l&&void 0===i||e._stack.push(e9(()=>(t=!0,l?.abort(),i??t0))),A.GN)}}),(i=function(e,t){this.register=e,this.withSignal=t}).prototype=l,function(e,t){return new i(e,t)}),e9=(0,A.Uf)({op:"AsyncFinalizer",[A.u4](e){e.interruptible&&(e.interruptible=!1,e._stack.push(l5))},[A.Sc](e,t){return K(e)?tV(ly((0,A.cb)(e),this[A.a2]()),()=>eX(e)):eX(e)}}),te=e=>e8(e,e.length>=2),tt=te(m.Yi),ta=(...e)=>{if(1===e.length){let t=e[0];return eY(()=>tp(t()))}let[t,a]=e;return eY(()=>tp(a.call(t.self)))},tl=(e,t)=>"function"==typeof e?e:t.shift().bind(e.self),ti=(e,...t)=>{let a=tl(e,t),l=0===t.length?function(){return eY(()=>tp(a.apply(this,arguments)))}:function(){let e=eY(()=>tp(a.apply(this,arguments)));for(let a=0;a<t.length;a++)e=t[a](e,...arguments);return e};return ts(a.length,l)},ts=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),to=O(2),tr=function(){let e,t="string"==typeof arguments[0],a=t?arguments[0]:"Effect.fn",l=t?arguments[1]:void 0,i=(0,$.jt)();return(0!==i&&((0,$.ft)(2),e=new globalThis.Error,(0,$.ft)(i)),t)?(i,...s)=>tn(a,i,e,s,t,l):tn(a,arguments[0],e,Array.prototype.slice.call(arguments,1),t,l)},tn=(e,t,a,l,i,s)=>{let o=tl(t,l),r=`${e} (definition)`,n=a?to(()=>a.stack):m.MN;return ts(o.length,function(...t){let a,d,c=eY(()=>{let e=o.apply(this,arguments);return(0,A.yw)(e)?e:tp(e)});for(let e=0;e<l.length;e++)c=l[e](c,...t);if(!(0,A.yw)(c))return c;let p=(0,$.jt)();return 0!==p&&((0,$.ft)(2),d=new globalThis.Error,(0,$.ft)(p)),ao(i?sr(e,s,e=>sn(c,e)):c,I.vA,(a=d,t=>({name:e,stack:a?to(()=>a.stack):m.MN,parent:{name:r,stack:n,parent:t}})))})},td=(e,...t)=>{let a=tl(e,t);return ts(a.length,0===t.length?function(){return tc(()=>a.apply(this,arguments))}:function(){let e=tc(()=>a.apply(this,arguments));for(let a of t)e=a(e,...arguments);return e})},tc=e=>{try{let t,a=e();for(;;){let l=a.next(t);if(l.done)return eU(l.value);let i=l.value;if(i&&"Success"===i._tag){t=i.value;continue}{if(i&&"Failure"===i._tag)return l.value;let t=!0;return eY(()=>t?(t=!1,tV(l.value,e=>tp(a,e))):eY(()=>tp(e())))}}}catch(e){return e1(e)}},tp=(s=(0,A.yj)({op:"Iterator",[A.ee](e,t){let a=this.iterator;for(;;){let l=a.next(e);if(l.done)return eU(l.value);if(!tI(l.value))return t._stack.push(this),l.value;if("Failure"===l.value._tag)return l.value;e=l.value.value}},[A._3](e){return this[A.ee](this.initial,e)}}),(o=function(e,t){this.iterator=e,this.initial=t}).prototype=s,function(e,t){return new o(e,t)}),th=(0,m.XY)(2,(e,t)=>new tf(e,tm,eU(t))),tg=function(e){return e._stack.push(this),this[A.a2]},tu=(0,A.yj)({op:"OnSuccess",[A._3]:tg}),tf=function(e,t,a){this[A.a2]=e,this[A.ee]=t,this.payload=a};tf.prototype=tu;let tm=function(){return this.payload},tv=function(e,t){return t.succeedWith(this.payload)},ty=(()=>{let e=(0,$.jt)();if(0===e)return!1;let t="~effect/Effect/stackProbe";(0,$.ft)(1);let a=({[t]:function(){return Error()}})[t]();return(0,$.ft)(e),a.stack?.includes("[as "+t+"]")===!0})(),tw=function(e,t){let a=this.payload;return t.succeedWith(ty?a(e):(0,B.s)(()=>a(e)))},tx=function(e){return(0,this.payload)(e)},tb=function(e){return new tf((0,this.payload)(e),tv,e)},tk=function(e){return new tf(this.payload,tv,e)},tM=e=>tO(e,v.some),tz=e=>a9(e,{onFailure:eU,onSuccess:eT}),tC=(0,m.XY)(2,(e,t)=>new tf(e,(0,A.yw)(t)?tm:tx,t)),t_=(0,m.XY)(2,(e,t)=>new tf(e,(0,A.yw)(t)?tk:tb,t)),tq=e=>new tf(e,tm,t0),tL=e=>aM(e,eT),tS=(e,t)=>(0,A.R6)(a=>{let l=new Set;return lE(a,()=>0===l.size?void 0:eO(l)),te(i=>{let s=h.Ts(e),o=s.length,r=0,n=!1,d=[],c=(e,l,s)=>{if(r++,"Failure"===e._tag){d.push(...e.cause.reasons),r>=o&&i(eX(j((0,A.b5)(d))));return}let c=!n;n=!0,i(e),c&&t?.onWinner&&t.onWinner({fiber:l,index:s,parentFiber:a})};for(let e=0;e<o;e++){let t=iP(a,s[e],!0,!0,!1);if(l.add(t),t.addObserver(a=>{l.delete(t),c(a,t,e)}),n)break}})}),tB=(e,t)=>(0,A.R6)(a=>{let l=new Set;return lE(a,()=>0===l.size?void 0:eO(l)),te(i=>{let s=!1,o=0;for(let r of e){if(s)break;let e=o++,n=iP(a,r,!0,!0,!1);l.add(n),n.addObserver(o=>{l.delete(n);let r=!s;s=!0,i(o),r&&t?.onWinner&&t.onWinner({fiber:n,index:e,parentFiber:a})})}})}),tA=(0,m.XY)(e=>(0,A.yw)(e[1]),(e,t,a)=>tS([e,t],a)),tP=(0,m.XY)(e=>(0,A.yw)(e[1]),(e,t,a)=>tB([e,t],a)),tV=(0,m.XY)(2,(e,t)=>new tf(e,tx,t)),tH=(0,m.XY)(2,(e,t)=>tI(e)?"Success"===e._tag?t.onSuccess(e.value):t.onFailure(e.cause):a0(e,t)),tI=e=>void 0!==e[A.IH],t$=(0,m.XY)(2,(e,t)=>tI(e)?"Success"===e._tag?t(e.value):e:tV(e,t)),tF=e=>tV(e,m.D_),tO=(0,m.XY)(2,(e,t)=>new tf(e,tw,t)),tE=(0,m.XY)(2,(e,t)=>tI(e)?t2(e,t):tO(e,t)),tU=(0,m.XY)(2,(e,t)=>tI(e)?t3(e,t):aY(e,t)),tX=(0,m.XY)(2,(e,t)=>tI(e)?t5(e,t):aD(e,t)),tT=(0,m.XY)(2,(e,t)=>{if(tI(e)){if("Success"===e._tag)return e;let a=N(e.cause);return w.N6(a)?(0,A.cb)(a.failure):t(a.success)}return aL(e,t)}),tR=e=>(0,A.cb)(T(e)),tY=e=>"Success"===e._tag,tD=e=>"Success"===e._tag?w.Py(e):w.fJ(e),tG=e=>"Success"===e._tag?w.Py(e.value):w.fJ(e),tZ=e=>"Failure"===e._tag,tj=e=>"Failure"===e._tag?w.Py(e):w.fJ(e),tN=e=>"Failure"===e._tag?w.Py(e.cause):w.fJ(e),tW=x(tN,D),tJ=x(tN,J),tK=e=>"Failure"===e._tag&&K(e.cause),tQ=e=>"Failure"===e._tag&&Z(e.cause),t1=e=>"Failure"===e._tag&&R(e.cause),t0=(0,A.xt)(void 0),t2=(0,m.XY)(2,(e,t)=>"Success"===e._tag?(0,A.xt)(t(e.value)):e),t3=(0,m.XY)(2,(e,t)=>"Success"===e._tag?e:(0,A.cb)(eo(e.cause,t))),t5=(0,m.XY)(2,(e,t)=>"Success"===e._tag?(0,A.xt)(t.onSuccess(e.value)):(0,A.cb)(eo(e.cause,t.onFailure))),t4=(0,m.XY)(2,(e,t)=>tY(e)?(0,A.xt)(t):e),t6=(0,m.XY)(2,(e,t)=>tY(e)?t:e),t7=(0,m.XY)(2,(e,t)=>tY(e)?t.onSuccess(e.value):t.onFailure(e.cause)),t8=t4(void 0),t9=e=>{let t=[];for(let a of e)"Failure"===a._tag&&t.push(...a.cause.reasons);return 0===t.length?t0:(0,A.cb)((0,A.b5)(t))},ae=e=>tY(e)?v.some(e.value):v.none(),at=e=>tZ(e)?v.some(e.cause):v.none(),aa=e=>{let t=tW(e);return w.N6(t)?v.none():v.some(t.success)},al=e=>e,ai=e=>(0,A.R6)(t=>eU(g.om(t.context,e))),as=(0,m.XY)(2,(e,t)=>(0,A.R6)(a=>{let l=a.context,i=t(l);return l===i||(a.setContext(i),lE(a,()=>{a.setContext(l)})),e})),ao=(0,m.XY)(3,(e,t,a)=>as(e,e=>{let l=g.fp(e,t),i=a(l);return l===i?e:g.WQ(e,t,i)})),ar=(e,t,a)=>l2((0,A.R6)(l=>{let i=g.fp(l.context,e),s=t(i);return l.setContext(g.WQ(l.context,e,s)),lk(g.fp(l.context,lu),t=>{let o,r=g.om(l.context,e);if(v.isNone(r))return e2;let n=r.value;if(a?.reset===void 0){if(n!==s)return e2;o=i}else o=a.reset(i,s,n);return l.setContext(g.WQ(l.context,e,o)),e2})})),an=()=>ad,ad=(0,A.R6)(e=>eU(e.context)),ac=e=>(0,A.R6)(t=>e(t.context)),ap=(0,m.XY)(2,(e,t)=>as(e,(0,m.dY)(t))),ah=(0,m.XY)(2,(e,t)=>tI(e)?e:as(e,g.h1(t))),ag=function(){return 1==arguments.length?(0,m.XY)(2,(e,t)=>au(e,arguments[0],t)):(0,m.XY)(3,(e,t,a)=>au(e,t,a)).apply(this,arguments)},au=(e,t,a)=>as(e,g.WQ(t,a)),af=(0,m.XY)(3,(e,t,a)=>tV(a,a=>ag(e,t,a))),am=(0,m.XY)(e=>(0,A.yw)(e[1]),(e,t,a)=>av(e,t,(e,t)=>[e,t],a)),av=(0,m.XY)(e=>(0,A.yw)(e[1]),(e,t,a,l)=>l?.concurrent?tO(ia([e,t],{concurrency:2}),([e,t])=>a(e,t)):tV(e,e=>tO(t,t=>a(e,t)))),ay=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a)=>ib(e,t,a?e=>eT(a(e)):()=>eT(new A.Xm))),aw=(0,m.XY)(2,(e,t)=>tV(t,t=>t?tM(e):eJ)),ax=(0,m.XY)(2,(e,t)=>Array.from({length:t},()=>e)),ab=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a)=>ia(ax(e,t),a)),ak=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t)=>ip({while:m.ue,body:(0,m.dY)(t?.disableYield?e:tV(e,e=>eN)),step:m.Yi})),aM=(0,m.XY)(2,(e,t)=>new aC(e,1!==t.length?e=>t(e):t)),az=(0,A.yj)({op:"OnFailure",[A._3]:tg}),aC=function(e,t){this[A.a2]=e,this[A.Sc]=t};aC.prototype=az;let a_=(0,m.XY)(3,(e,t,a)=>aM(e,e=>t(e)?a(e):eX(e))),aq=(0,m.XY)(3,(e,t,a)=>aM(e,e=>{let l=t(e);return w.N6(l)?eX(l.failure):a(l.success,e)})),aL=(0,m.XY)(2,(e,t)=>aq(e,N,e=>t(e))),aS=e=>a9(e,{onFailure:e=>(0,A.PW)(e)?eJ:eT(e),onSuccess:eW}),aB=(0,m.XY)(2,(e,t)=>aq(e,J,t)),aA=(0,m.XY)(2,(e,t)=>aM(e,e=>tC(t(e),eX(e)))),aP=(0,m.XY)(3,(e,t,a)=>a_(e,t,e=>tC(a(e),eX(e)))),aV=(0,m.XY)(3,(e,t,a)=>aM(e,e=>{let l=t(e);return w.N6(l)?eX(e):tC(a(l.success,e),eX(e))})),aH=(0,m.XY)(2,(e,t)=>aV(e,D,e=>t(e))),aI=(0,m.XY)(3,(e,t,a)=>{let l=Array.isArray(t)?e=>(0,y.i5)(e,"_tag")&&t.includes(e._tag):(0,y.$J)(t);return aH(e,e=>l(e)?a(e):e2)}),a$=(0,m.XY)(2,(e,t)=>aV(e,J,e=>t(e))),aF=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a,l)=>aM(e,e=>{let i=N(e);return w.N6(i)?eX(i.failure):t(i.success)?a(i.success):l?l(i.success):eX(e)})),aO=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a,l)=>aM(e,e=>{let i=N(e);if(w.N6(i))return eX(i.failure);let s=t(i.success);return w.N6(s)?l?l(s.failure):eX(e):a(s.success)})),aE=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a,l)=>aF(e,Array.isArray(t)?e=>(0,y.i5)(e,"_tag")&&t.includes(e._tag):(0,y.$J)(t),a,l)),aU=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a)=>{let l;return aO(e,e=>(l??=Object.keys(t),(0,y.i5)(e,"_tag")&&(0,y.Kg)(e._tag)&&l.includes(e._tag)?w.Py(e):w.fJ(e)),e=>t[e._tag](e),a)}),aX=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a,l,i)=>aF(e,e=>(0,y.$J)(e,t)&&(0,y.i5)(e,"reason")&&(void 0!==i||(0,y.$J)(e.reason,a)),e=>{let t=e.reason;return(0,y.$J)(t,a)?l(t,e):i?i(t,e):eT(e)})),aT=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a,l)=>{let i;return aF(e,e=>(0,y.$J)(e,t)&&(0,y.i5)(e,"reason")&&(0,y.i5)(e.reason,"_tag")&&(0,y.Kg)(e.reason._tag)&&(void 0!==l||(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):l?l(t,e):eT(e)})}),aR=(0,m.XY)(2,(e,t)=>aO(e,e=>(0,y.$J)(e,t)&&(0,y.i5)(e,"reason")?w.Py(e.reason):w.fJ(e),eT)),aY=(0,m.XY)(2,(e,t)=>aM(e,e=>eX(eo(e,t)))),aD=(0,m.XY)(2,(e,t)=>a0(e,{onFailure:e=>eX(eo(e,t.onFailure)),onSuccess:e=>eR(()=>t.onSuccess(e))})),aG=e=>aL(e,e1),aZ=(0,m.XY)(2,(e,t)=>aL(e,e=>eR(()=>t(e)))),aj=e=>eY(()=>{let t=e[Symbol.iterator](),a=t.next();return a.done?e1(Error("Received an empty collection of effects")):function e(a){let l=t.next();return l.done?a.value:aL(a.value,t=>e(l))}(a)}),aN=e=>aL(e,t=>tV(eN,()=>aN(e))),aW=e=>"Unhandled"===e?(...e)=>(0,A.R6)(t=>{let a=t.getRef(I.aG);return void 0===a?e2:sN(a)(...e)}):sN(!0===e?void 0:e),aJ=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t)=>{if(!t?.log)return a9(e,{onFailure:e=>e2,onSuccess:e=>e2});let a=aW(t.log);return a0(e,{onFailure(e){let l=N(e);return w.N6(l)?eX(l.failure):void 0===t.message?a(e):a(t.message,e)},onSuccess:e=>e2})}),aK=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t)=>{if(!t?.log)return a0(e,{onFailure:e=>e2,onSuccess:e=>e2});let a=aW(t.log);return a0(e,{onFailure:e=>void 0===t.message?a(e):a(t.message,e),onSuccess:e=>e2})}),aQ=e=>le(e,{onFailure:v.none,onSuccess:v.some}),a1=e=>lt(e,{onFailure:w.fJ,onSuccess:w.Py}),a0=(0,m.XY)(2,(e,t)=>new a3(e,1!==t.onSuccess.length?e=>t.onSuccess(e):t.onSuccess,1!==t.onFailure.length?e=>t.onFailure(e):t.onFailure)),a2=(0,A.yj)({op:"OnSuccessAndFailure",[A._3]:tg}),a3=function(e,t,a){this[A.a2]=e,this[A.ee]=t,this[A.Sc]=a};a3.prototype=a2;let a5=function(e,t){let a=this.payload;return t.succeedWith(ty?a.onSuccess(e):(0,B.s)(()=>a.onSuccess(e)))},a4=(e,t)=>{let a=(0,A.yj)({op:e,[A._3]:tg,[A.ee]:a5,[A.Sc]:t}),l=function(e,t){this[A.a2]=e,this.payload=t};return l.prototype=a,l},a6=a4("Match",function(e,t){let a=N(e);if(w.N6(a))return eX(a.failure);let l=this.payload;return t.succeedWith(ty?l.onFailure(a.success):(0,B.s)(()=>l.onFailure(a.success)))}),a7=a4("MatchCause",function(e,t){let a=this.payload;return t.succeedWith(ty?a.onFailure(e):(0,B.s)(()=>a.onFailure(e)))}),a8=(0,m.XY)(2,(e,t)=>new a7(e,t)),a9=(0,m.XY)(2,(e,t)=>a0(e,{onFailure:e=>{let a=N(e);return w.N6(a)?eX(a.failure):t.onFailure(a.success)},onSuccess:t.onSuccess})),le=(0,m.XY)(2,(e,t)=>new a6(e,t)),lt=(0,m.XY)(2,(e,t)=>{if(tI(e)){if("Success"===e._tag)return(0,A.xt)(t.onSuccess(e.value));let a=N(e.cause);return w.N6(a)?(0,A.cb)(a.failure):(0,A.xt)(t.onFailure(a.success))}return le(e,t)}),la=(0,m.XY)(2,(e,t)=>tI(e)?"Success"===e._tag?(0,A.xt)(t.onSuccess(e.value)):(0,A.xt)(t.onFailure(e.cause)):a8(e,t)),ll=e=>tI(e)?(0,A.xt)(e):li(e),li=(0,A.Uf)({op:"Exit",[A._3](e){return e._stack.push(this),this[A.a2]},[A.ee]:(e,t,a)=>t.succeedWith(a??(0,A.xt)(e)),[A.Sc]:(e,t,a)=>t.succeedWith(a??(0,A.cb)(e))}),ls=lt({onFailure:()=>!0,onSuccess:()=>!1}),lo=lt({onFailure:()=>!1,onSuccess:()=>!0}),lr=(0,m.XY)(2,(e,t)=>tC(sb(t),e)),ln=(0,m.XY)(2,(e,t)=>tV(lc(e,t.duration),e=>v.isNone(e)?t.orElse():eU(e.value))),ld=(0,m.XY)(2,(e,t)=>{let a=u.bN(t);return ln(e,{duration:a,orElse:()=>eT(new sq(`Operation timed out after '${u.GP(a)}'`))})}),lc=(0,m.XY)(2,(e,t)=>tP(tM(e),th(sb(t),v.none()))),lp=e=>sx(t=>{let a=t.monotonicTimeNanosUnsafe();return tO(e,e=>[u.cF(t.monotonicTimeNanosUnsafe()-a),e])}),lh="~effect/Scope",lg="~effect/Scope/Closeable",lu=g.kl("effect/Scope"),lf=(e,t)=>(0,A.R6)(a=>(l7(a),lm(e,t)??e2)),lm=(e,t)=>{let a=e.state;if("Closed"===a._tag||(e.state={_tag:"Closed",exit:t},void 0!==e.parent&&lC(e.parent,e),"Empty"===a._tag))return;if(void 0!==a.finalizer)return lv(a.finalizer,t);let l=a.finalizers;return 1===l.size?lv(l.values().next().value,t):lw(e,l,t)},lv=(e,t)=>{try{return e(t)}catch(e){return(0,A.V2)(e)}},ly=(e,t)=>tY(e)?t:aM(t,t=>eX(j((0,A.h2)(e.cause,t)))),lw=ti(function*(e,t,a){let l=[],i=[],s=Array.from(t),o=ez();for(let t=s.length-1;t>=0;t--){let[r,n]=s[t];"sequential"===e.strategy?l.push((yield*ll(lv(n,a)))):r!==o&&i.push(iP(o,lv(n,a),!0,!0,"inherit"))}return i.length>0&&(l=yield*eV(i)),yield*t9(l)}),lx=(e,t)=>eR(()=>lb(e,t)),lb=(e,t)=>{let a=lq(t,e);return"Closed"===e.state._tag?a.state=e.state:lz(e,a,e=>lf(a,e)),a},lk=(e,t)=>eY(()=>"Closed"===e.state._tag?t(e.state.exit):(lz(e,{},t),e2)),lM=(e,t)=>lk(e,(0,m.dY)(t)),lz=(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 l=e.state;void 0!==l.finalizer&&(l.finalizers=new Map([[l.finalizerKey,l.finalizer]]),l.finalizerKey=void 0,l.finalizer=void 0),l.finalizers.set(t,a)}},lC=(e,t)=>{if("Open"!==e.state._tag)return;let a=e.state;a.finalizerKey===t?e.state=lL:void 0!==a.finalizers&&(a.finalizers.delete(t),0===a.finalizers.size&&(e.state=lL))},l_=e=>lq(e,void 0),lq=(e="sequential",t)=>({[lg]:lg,[lh]:lh,strategy:e,parent:t,state:lL}),lL={_tag:"Empty"},lS=e=>eR(()=>l_(e)),lB=lu,lA=ag(lu),lP=e=>(0,A.R6)(t=>{let a=t.context,l=l_();return t.setContext(g.WQ(t.context,lu,l)),lE(t,e=>(t.setContext(a),lm(l,e))),e}),lV=(0,m.XY)(2,(e,t)=>lU(lA(e,t),e=>eY(()=>lm(t,e)??e2))),lH=e=>eY(()=>{let t=l_();return lU(e(t),e=>eY(()=>lm(t,e)??e2))}),lI=(e,t,a)=>ac(l=>l9(i=>tV(lB,s=>t_(a?.interruptible?i(e):e,e=>lk(s,a=>ah(t(e,a),l)))))),l$=e=>tV(lB,t=>ac(a=>lk(t,t=>ah(e(t),a)))),lF=(r=(0,A.yj)({op:"OnExit",[A._3](e){return e._stack.push(this),this.effect},[A.u4](e){e.interruptible&&!0!==this.interruptible&&(e._stack.push(l5),e.interruptible=!1)},[A.ee](e,t,a){let l;a??=(0,A.xt)(e);try{l=this.onExit(a)}catch(e){l=(0,A.V2)(e)}return l?tV(l,e=>a):a},[A.Sc](e,t,a){let l;a??=(0,A.cb)(e);try{l=this.onExit(a)}catch(e){l=(0,A.V2)(e)}return l?tV(ly(a,l),e=>a):a}}),(n=function(e,t,a){this.effect=e,this.onExit=t,this.interruptible=a}).prototype=r,n),lO=(e,t,a)=>new lF(e,t,a),lE=(e,t)=>{e._stack.push(new lF(void 0,t,void 0))},lU=(0,m.XY)(2,lO),lX=(0,m.XY)(2,(e,t)=>lU(e,e=>t)),lT=(0,m.XY)(3,(e,t,a)=>lU(e,e=>t(e)?a(e):e2)),lR=(0,m.XY)(3,(e,t,a)=>lU(e,e=>{let l=t(e);return w.N6(l)?e2:a(l.success,e)})),lY=(0,m.XY)(2,(e,t)=>lR(e,tN,t)),lD=(0,m.XY)(3,(e,t,a)=>lT(e,e=>"Failure"===e._tag&&t(e.cause),e=>a(e.cause))),lG=(0,m.XY)(3,(e,t,a)=>lU(e,e=>{if("Failure"!==e._tag)return e2;let l=t(e.cause);return w.N6(l)?e2:a(l.success,e.cause)})),lZ=(0,m.XY)(2,(e,t)=>lG(ee,t)(e)),lj=(e,t,a)=>l9(l=>tV(e,e=>lO(eY(()=>l(t(e))),t=>a(e,t),!0))),lN=e=>lI(e,e=>(0,y.i5)(e,Symbol.asyncDispose)?e5(()=>e[Symbol.asyncDispose]()):eR(()=>e[Symbol.dispose]())),lW=(0,m.XY)(2,(e,t)=>eR(()=>lK(e,"function"==typeof t?e=>u.kE(u.bN(t(e))):(0,m.dY)(u.kE(u.bN(t)))))),lJ=(0,m.dY)(1/0),lK=(e,t)=>{let a,l,i=0,s=(e,t)=>(t.awaiters++,lE(e,()=>{if(!(--t.awaiters>0)&&!t.done)return l===t&&(l=void 0),e$(t.fiber)}),eH(t.fiber));return[(0,A.R6)(o=>{if(void 0!==l)return o===l.fiber?eH(l.fiber):s(o,l);if(void 0!==a&&(1/0===i||o.getRef(sf).currentTimeMillisUnsafe()<i))return a;a=void 0;let r=o.getRef(sf),n={fiber:new eC(o.context),awaiters:0,done:!1};l=n;let d=s(o,n);return n.fiber.evaluate(lO(e,e=>{if(n.done=!0,l!==n||(l=void 0,tK(e)))return;let s=t(e);i=1/0===s?1/0:r.currentTimeMillisUnsafe()+s,a=e})),n.fiber._exit??d}),eR(()=>{l=void 0,a=void 0})]},lQ=(0,m.XY)(2,(e,t)=>tO(lW(e,t),e=>e[0])),l1=e=>eR(()=>lK(e,lJ)[0]),l0=(0,A.R6)(e=>eX(T(e.id))),l2=e=>(0,A.R6)(t=>(t.interruptible&&(t.interruptible=!1,t._stack.push(l5)),e)),l3=(0,A.Uf)({op:"SetInterruptible",[A.u4](e){if(e.interruptible=this[A.a2],e._interruptedCause&&e.interruptible)return()=>eX(e._interruptedCause)}}),l5=l3(!0),l4=l3(!1),l6=e=>{if(e.interruptible=!0,e._stack.push(l4),e._interruptedCause)return eX(e._interruptedCause)},l7=e=>{e.interruptible&&(e.interruptible=!1,e._stack.push(l5))},l8=e=>(0,A.R6)(t=>t.interruptible?e:l6(t)??e),l9=e=>(0,A.R6)(t=>t.interruptible?(t.interruptible=!1,t._stack.push(l5),e(l8)):e(m.D_)),ie=e=>(0,A.R6)(t=>{if(t.interruptible)return e(m.D_);let a=l6(t),l=e(l2);return a??l}),it=tO(lI(eR(()=>new AbortController),e=>eR(()=>e.abort())),e=>e.signal),ia=(e,t)=>(0,y.xZ)(e)?t?.mode==="result"?ih(e,a1,t):ih(e,m.D_,t):t?.discard?"result"===t.mode?ih(Object.values(e),a1,t):ih(Object.values(e),m.D_,t):eY(()=>tO(ih(Object.entries(e),([e,a])=>tO(t?.mode==="result"?a1(a):a,t=>[e,t]),{concurrency:t?.concurrency}),Object.fromEntries)),il=(0,m.XY)(e=>(0,y.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,a)=>tO(ih(e,(e,a)=>a1(t(e,a)),a),e=>h.jB(e,m.D_))),ii=(0,m.XY)(3,(e,t,a)=>{let l=h.Ts(e);return 0===l.length?eR(t):eY(()=>{let e=0,i=t();return tO(ip({while:()=>e<l.length,body:()=>a(i,l[e],e),step(t){i=t,e++}}),()=>i)})}),is=(0,m.XY)(e=>(0,y.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,a)=>tV(il(e,t,{concurrency:a?.concurrency}),([e,t])=>h.CZ(t)?eT(t):a?.discard?e2:eU(e))),io=(0,m.XY)(e=>(0,y.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eY(()=>{let a=e[Symbol.iterator](),l=a.next();return l.done?eU(v.none()):ir(a,0,t,l.value)})),ir=(e,t,a,l)=>tV(a(l,t),i=>{if(i)return eU(v.some(l));let s=e.next();return s.done?eU(v.none()):ir(e,t+1,a,s.value)}),id=(0,m.XY)(e=>(0,y.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eY(()=>{let a=e[Symbol.iterator](),l=a.next();return l.done?eU(v.none()):ic(a,0,t,l.value)})),ic=(e,t,a,l)=>tV(a(l,t),l=>{if(w.oJ(l))return eU(v.some(l.success));let i=e.next();return i.done?eU(v.none()):ic(e,t+1,a,i.value)}),ip=(0,A.Uf)({op:"While",[A.ee](e,t){return(this[A.a2].step(e),this[A.a2].while())?(t._stack.push(this),this[A.a2].body()):t0},[A._3](e){return this[A.a2].while()?(e._stack.push(this),this[A.a2].body()):t0}}),ih=(0,m.XY)(e=>"function"==typeof e[1],(e,t,a)=>eY(()=>{let l=im(a?.concurrency);if(1===l)return iu(e,t,a);let i=h.Ts(e),s=i.length;if(0===s)return a?.discard?e2:eU([]);let o=a?.discard?void 0:Array(s),r=ix({f:t,out:o},i,{concurrency:l});return r?th(r,o):eU(o)})),ig=e=>tV(e,e=>{let t=e[Symbol.iterator]().next();return t.done?eT(new A.Xm):eU(t.value)}),iu=(e,t,a)=>eY(()=>{let l=a?.discard?void 0:[],i=e[Symbol.iterator](),s=i.next(),o=0;return th(ip({while:()=>!s.done,body:()=>t(s.value,o++),step:e=>{l&&l.push(e),s=i.next()}}),l)}),im=e=>"unbounded"===e?1/0:Math.max(1,e??1),iv=()=>e=>{let t=e.onItem,a=e.step,l=(e,t,l,s,o)=>tV(ll(o),o=>a(e,t[l],o,l)??i(e,t,l+1,s)??e2),i=(e,i,s=0,o=i.length)=>{for(;s<o;s++){let r=i[s],n=t(e,r,s);if(!tI(n))return l(e,i,s,o,n);let d=a(e,r,n,s);if(d)return"Failure"===d._tag?d:void 0}};return i},iy=e=>{let t=e.onItem,a=e.step;return(e,l,i)=>{let s,o,r,n,d,c=0,p=i.end??l.length,h=i.concurrency,g=!1,u=e=>{let t=(0,A.V2)(e);return n=t,g=!0,o&&o.size>0?tV(l2(eO(Array.from(o))),()=>n??t):t},f=()=>{let i=!1;for(;!n&&c<p;c++){let p=l[c],m=d??t(e,p,c);if(tI(m)){if(n=a(e,p,m,c))break}else{if(!s)return te(e=>{let t;s=ez(),o=new Set,d=m,r=e;try{t=f()}catch(t){return e(u(t))}return t?e(t):eY(()=>(n??=t0,tV(o?eO(o):e2,()=>n?._tag==="Failure"?n:e2)))});d=void 0;let t=iP(s,m,!0,!0,"inherit");if(t._exit){if(n=a(e,p,t._exit,c))break;continue}o.add(t);let l=c;if(t.addObserver(s=>{o.delete(t);try{if(n){if("Failure"===s._tag){let e=s.cause.reasons.filter(e=>"Interrupt"!==e._tag);if(e.length>0){let t=(0,A.b5)(e);n=(0,A.cb)("Failure"===n._tag?j((0,A.h2)(n.cause,t)):t)}}}else{let t=a(e,p,s,l);t&&(n=t,f())}if(i){let e=f();e&&r(e)}else g&&0===o.size&&r(n??e2)}catch(e){r(u(e))}}),o.size<h)continue;i=!0,c++;return}}if(g=!0,n){if(o&&o.size>0){let e=eB(s);o.forEach(t=>t.interruptUnsafe(s.id,e));return}if(r||"Failure"===n._tag)return n}else if(r)if(!o)return t0;else 0===o.size&&r(e2)};return f()}},iw=()=>e=>iy(e),ix=iy({onItem:(e,t,a)=>e.f(t,a),step(e,t,a,l){if("Failure"===a._tag)return a;e.out&&(e.out[l]=a.value)}}),ib=(0,m.XY)(3,(e,t,a)=>tV(e,e=>t(e)?eU(e):a(e))),ik=(0,m.XY)(3,(e,t,a)=>tV(e,e=>{let l=t(e);return w.N6(l)?a(l.failure):eU(l.success)})),iM=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a)=>ik(e,t,a?e=>eT(a(e)):()=>eT(new A.Xm))),iz=(0,m.XY)(e=>(0,y.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,a)=>tO(ih(e,(e,a)=>{let l=t(e,a);return"boolean"==typeof l?eU(l?v.some(e):v.none()):tO(l,t=>t?v.some(e):v.none())},a),h.Yz)),iC=(0,m.XY)(e=>(0,y.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eY(()=>{let a=[];for(let l of e){let e=t(l);w.oJ(e)&&a.push(e.success)}return eU(a)})),i_=(0,m.XY)(e=>(0,y.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,a)=>eY(()=>{let l=[];return th(ih(e,e=>tO(t(e),e=>{w.oJ(e)&&l.push(e.success)}),{discard:!0,concurrency:a?.concurrency}),l)})),iq=eU({}),iL=P.Jr(tO),iS=P.oI(tO,tV),iB=P.zM(tO),iA=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t)=>(0,A.R6)(a=>(eS.interruptChildren??=eA,eU(iP(a,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),iP=(e,t,a=!1,l=!1,i=!1)=>{let s="inherit"===i?e.interruptible:!i,o=new eC(e.context,s);return l||(e.children().add(o),o._parent=e),a?o.evaluate(t):(o._asyncContext=eM(),e.currentDispatcher.scheduleTask(()=>o.evaluate(t),0)),o},iV=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t)=>(0,A.R6)(a=>eU(iP(a,e,t?.startImmediately,!0,t?.uninterruptible)))),iH=e=>(0,A.R6)(t=>{let a=t._children&&new Set(t._children),l=t.interruptible;return lO(e,e=>{let i=t._children;if(void 0===i||0===i.size)return e2;a&&(i=z.pb(i,e=>!a.has(e)));let s=tq(eV(i));return l?l8(s):s})}),iI=e=>()=>(0,A.R6)(t=>t===e?e2:e$(e)),i$=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a)=>(0,A.R6)(l=>{let i="Closed"===t.state._tag?new eC(l.context):iP(l,e,a?.startImmediately,!0,a?.uninterruptible);return i._exit||("Closed"!==t.state._tag?(lz(t,i,iI(i)),i.addObserver(()=>lC(t,i))):i.interruptUnsafe(l.id,eB(l))),eU(i)})),iF=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t)=>tV(lB,a=>i$(e,a,t))),iO=e=>(t,a)=>{let l=new eC(a?.scheduler?g.WQ(e,L._F,a.scheduler):e,a?.uninterruptible!==!0);if(l.evaluate(t),l._exit)return l;if(a?.signal)if(a.signal.aborted)l.interruptUnsafe();else{let e=()=>l.interruptUnsafe();a.signal.addEventListener("abort",e,{once:!0}),l.addObserver(()=>a.signal.removeEventListener("abort",e))}return a?.onFiberStart&&a.onFiberStart(l),l},iE=(0,m.XY)(2,(e,t)=>(e._exit||("Closed"===t.state._tag?e.interruptUnsafe(e.id):(lC(t,e),lz(t,e,iI(e)),e.addObserver(()=>lC(t,e)))),e)),iU=iO(g.Ie()),iX=e=>{let t=iO(e);return(e,a)=>{let l=t(e,a);return a?.onExit&&l.addObserver(a.onExit),e=>l.interruptUnsafe(e)}},iT=iX(g.Ie()),iR=e=>{let t=iO(e);return(e,a)=>{let l=t(e,a);return new Promise(e=>{l.addObserver(t=>e(t))})}},iY=iR(g.Ie()),iD=e=>{let t=iR(e);return(e,a)=>t(e,a).then(e=>{if("Failure"===e._tag)throw er(e.cause);return e.value})},iG=iD(g.Ie()),iZ=e=>{let t=iO(e);return e=>{if(tI(e))return e;let a=t(e,{scheduler:new L.FG("sync")});return a._dispatcher?.flush(),a._exit??(0,A.V2)(new s$(a))}},ij=iZ(g.Ie()),iN=e=>{let t=iZ(e);return e=>{let a=t(e);if("Failure"===a._tag)throw er(a.cause);return a.value}},iW=iN(g.Ie()),iJ=eU(!0),iK=eU(!1);class iQ{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](t0)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](t0)}open=(0,A.R6)(e=>this._isOpen?iK:(this._isOpen=!0,this.scheduleUnsafe(e)));release=(0,A.R6)(e=>this._isOpen?iK:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=te(e=>this._isOpen?e(e2):(this.waiters.push(e),eR(()=>{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=eR(()=>this.closeUnsafe());whenOpen=e=>tV(this.await,()=>e);isOpen(){return this._isOpen}}let i1=e=>new iQ(e??!1),i0=e=>eR(()=>i1(e)),i2=(0,A.R6)(e=>eU(e.getRef(S.sh))),i3=(0,m.XY)(2,(e,t)=>ag(e,S.sh,t)),i5=ag(I.rf),i4=ag(I.nU),i6=BigInt(0),i7={_tag:"Span",spanId:"noop",traceId:"noop",sampled:!1,status:{_tag:"Ended",startTime:i6,endTime:i6,exit:t0},attributes:new Map,links:[],kind:"internal",attribute(){},event(){},end(){},addLinks(){}},i8=e=>e?g.Jt(e.annotations,S.DW)?"Span"===e._tag?i8(v.getOrUndefined(e.parent)):v.none():v.some(e):v.none(),i9=(e,t,a)=>{let l,i=!e.cache.tracerEnabled||a?.annotations&&g.Jt(a.annotations,S.DW),s=a?.parent!==void 0?v.some(a.parent):a?.root?v.none():i8(e.cache.span);if(i){let e;e={name:t,parent:s,annotations:g.WQ(a?.annotations??g.Ie(),S.DW,!0)},l=Object.assign(Object.create(i7),e)}else{let i=e.cache.tracer??S.Vv,o=e.getRef(sf),r=e.getRef(I.nU),n=e.getRef(I.ce),d=e.getRef(I.ls),c=a?.level??e.getRef(S.pX),p=a?.links!==void 0?[...d,...a.links]:0===d.length?[]:d.slice();for(let d in l=i.span({name:t,parent:s,annotations:a?.annotations??g.Ie(),links:p,startTime:r?o.currentTimeNanosUnsafe():i6,kind:a?.kind??"internal",root:a?.root??!1,sampled:a?.sampled??((!v.isSome(s)||!1!==s.value.sampled)&&!sT(e.getRef(S.EW),c))}),n)l.attribute(d,n[d]);if(a?.attributes!==void 0)for(let e in a.attributes)l.attribute(e,a.attributes[e])}return l},se=(e,t)=>(0,A.R6)(a=>eU(i9(a,e,t))),st=(e,t)=>l2((0,A.R6)(a=>{let l=g.fp(a.context,lu),i=i9(a,e,t??{}),s=a.getRef(sf),o=a.getRef(I.nU);return th(lk(l,e=>so(i,e,s,o)),i)})),sa=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],a=F(e?arguments[2]:arguments[1]);if(e){let e=arguments[0];return tV(st(t,a),t=>sd(e,t,a))}return e=>tV(st(t,a),t=>sd(e,t,a))},sl=I.ce,si=I.ls,ss=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t,a={})=>{let l=(Array.isArray(t)?t:[t]).map(e=>({span:e,attributes:a}));return ao(e,I.ls,e=>[...e,...l])}),so=(e,t,a,l)=>eR(()=>{"Ended"!==e.status._tag&&e.end(l?a.currentTimeNanosUnsafe():i6,t)}),sr=(e,...t)=>{let a=1===t.length?void 0:t[0],l=t[t.length-1];return(0,A.R6)(t=>{let i=i9(t,e,a),s=t.getRef(sf),o=t.getRef(I.nU);return lE(t,e=>so(i,e,s,o)),l(i)})},sn=ag(S.Tv),sd=function(){let e=(0,A.yw)(arguments[0]),t=e?arguments[1]:arguments[0],a=e?arguments[2]:arguments[1],l=m.D_;if("Span"===t._tag){var i,s;a=F(a),i=t.name,s="function"==typeof(s=a?.captureStackTrace)?s:m.MN,l=ao(I.vA,e=>({name:i,stack:s,parent:e}))}return e?sn(l(arguments[0]),t):e=>sn(l(e),t)},sc=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],a=F(arguments[2]);if(e){let e=arguments[0];return sr(t,arguments[2],t=>sd(e,t,a))}let l="function"==typeof arguments[1]?arguments[1]:void 0,i=l?void 0:arguments[1];return(e,...s)=>sr(t,l?l(...s):i,t=>sd(e,t,a))},sp=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,...t)=>ao(e,I.ce,e=>{let a=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||H.x(a,t[0],t[1]),a})),sh=(...e)=>(0,A.R6)(t=>{let a=t.currentSpanLocal;if(a&&"Ended"!==a.status._tag)if(1===e.length)for(let[t,l]of Object.entries(e[0]))a.attribute(t,l);else a.attribute(e[0],e[1]);return e2}),sg=(0,A.R6)(e=>{let t=e.currentSpanLocal;return t?eU(t):eT(new A.Xm)}),su=(d=S.Tv,(0,A.R6)(e=>eD(g.om(e.context,d)))),sf=g.Or("effect/Clock",{defaultValue:()=>new sm});class sm{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=eR(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return sw()}currentTimeNanos=eR(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return sy()}monotonicTimeNanos=eR(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(u.kE(e))}sleepMillis(e){return e<=0?eN:Number.isFinite(e)?te(t=>{let a=e>0x7fffffff?this.sleepMillis(e-0x7fffffff):e2,l=setTimeout(()=>t(a),Math.min(e,0x7fffffff));return eR(()=>clearTimeout(l))}):tt}}let sv=BigInt(1e6),sy=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())*sv;return e>t&&(t=e),t}}(),sw=(p=BigInt(1e9),()=>{let e=sy(),t=BigInt(Date.now())*sv;if(void 0===c)c=t-e;else{let a=c+e;(t>a?t-a:a-t)>p&&(c=t-e)}return c+e}),sx=e=>(0,A.R6)(t=>e(t.getRef(sf))),sb=e=>sx(t=>t.sleep(u.bN(e))),sk=sx(e=>e.currentTimeMillis),sM=sx(e=>e.currentTimeNanos),sz=sx(e=>e.monotonicTimeNanos),sC="~effect/Cause/TimeoutError",s_=e=>(0,y.i5)(e,sC);class sq extends(0,A.rN)("TimeoutError"){[sC]=sC;constructor(e){super({message:e})}}let sL="~effect/Cause/IllegalArgumentError",sS=e=>(0,y.i5)(e,sL);class sB extends(0,A.rN)("IllegalArgumentError"){[sL]=sL;constructor(e){super({message:e})}}let sA="~effect/Cause/ExceededCapacityError",sP=e=>(0,y.i5)(e,sA);class sV extends(0,A.rN)("ExceededCapacityError"){[sA]=sA;constructor(e){super({message:e})}}let sH="~effect/Cause/AsyncFiberError",sI=e=>(0,y.i5)(e,sH);class s$ extends(0,A.rN)("AsyncFiberError"){[sH]=sH;constructor(e){super({message:"An asynchronous Effect was executed with Effect.runSync",fiber:e})}}let sF="~effect/Cause/UnknownError",sO=e=>(0,y.i5)(e,sF);class sE extends(0,A.rN)("UnknownError"){[sF]=sF;constructor(e,t){super({message:t,cause:e})}}let sU=g.Or("effect/Console",{defaultValue:()=>globalThis.console}),sX=C.zQ(C.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}}),sT=C.yJ(sX),sR=g.Or("effect/Logger/CurrentLoggers",{defaultValue:()=>new Set([sW,sJ])}),sY=g.Or("effect/Logger/LogToStderr",{defaultValue:m.f4}),sD=function(){let e="string"==typeof arguments[0]?[[arguments[0],arguments[1]]]:Object.entries(arguments[0]);return l2((0,A.R6)(t=>{let a=t.getRef(I.iL),l={...a};for(let t=0;t<e.length;t++){let[a,i]=e[t];H.x(l,a,i)}return t.setContext(g.WQ(t.context,I.iL,l)),lk(g.fp(t.context,lu),l=>{let i=t.getRef(I.iL),s={...i};for(let t=0;t<e.length;t++){let[l,o]=e[t];(i[l]===o||Object.is(i[l],o))&&(Object.hasOwn(a,l)?H.x(s,l,a[l]):delete s[l])}return t.setContext(g.WQ(t.context,I.iL,s)),e2})}))},sG={"~effect/Logger":{_Message:m.D_,_Output:m.D_},pipe(){return(0,_.tT)(this,arguments)}},sZ=e=>{let t=Object.create(sG);return t.log=e,t},sj=(e,t)=>{let a=e[0].replace(/[\s="]/g,"_");return`${a}=${t-e[1]}ms`},sN=e=>(...t)=>{let a;for(let e=0,l=t.length;e<l;e++){let l=t[e];(0,A.Aj)(l)&&(a?t.splice(e,1):t=t.slice(0,e).concat(t.slice(e+1)),a=a?(0,A.b5)(a.reasons.concat(l.reasons)):l,e--)}return void 0===a&&(a=A.DH),(0,A.R6)(l=>{let i=e??l.cache.logLevel;if(sT(l.cache.minimumLogLevel,i))return e2;let s=l.getRef(sf),o=l.getRef(sR);if(o.size>0){let e=new Date(s.currentTimeMillisUnsafe());for(let s of o)s.log({cause:a,fiber:l,date:e,logLevel:i,message:t})}return e2})},sW=sZ(({cause:e,date:t,fiber:a,logLevel:l,message:i})=>{let s=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&s.push(em(e));let o=t.getTime(),r=a.getRef(I.d8),n="";for(let e of r)n+=` ${sj(e,o)}`;let d=a.getRef(I.iL);Object.keys(d).length>0&&s.push(d);let c=a.getRef(sU);(a.getRef(sY)?c.error:c.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")}] ${l.toUpperCase()} (#${a.id})${n}:`,...s)}),sJ=sZ(({cause:e,fiber:t,logLevel:a,message:l})=>{let i=t.getRef(sf),s=t.getRef(I.iL),o=t.cache.span;if(void 0===o||"ExternalSpan"===o._tag||"Ended"===o.status._tag)return;let r={};for(let[e,t]of Object.entries(s))H.x(r,e,t);r["effect.fiberId"]=t.id,r["effect.logLevel"]=a.toUpperCase(),e.reasons.length>0&&(r["effect.cause"]=em(e)),o.event((0,M.ZK)(Array.isArray(l)&&1===l.length?l[0]:l),i.currentTimeNanosUnsafe(),r)}),sK=eU(void 0),sQ=(0,m.XY)(e=>(0,A.yw)(e[0]),(e,t)=>lY(e,e=>(0,A.R6)(a=>(s1(a,e,t?.defectsOnly),e2)))),s1=(e,t,a)=>{let l=e.getRef(I.oQ);if(0===l.size||a&&!Z(t))return;let i={cause:t,fiber:e,timestamp:e.getRef(sf).currentTimeNanosUnsafe()};l.forEach(e=>e.report(i))}},4674(e,t,a){let l=new WeakSet;a.d(t,{},{B1:e=>e instanceof ArrayBuffer||"u">typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer,J3:l,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),l=a;for(;null!==l&&l!==Object.prototype;){let e=Reflect.ownKeys(l);for(let a=0;a<e.length;a++)t.add(e[a]);l=Object.getPrototypeOf(l)}return t.has("constructor")&&"function"==typeof e.constructor&&a===e.constructor.prototype&&t.delete("constructor"),t},_P:e=>{try{return new Uint8Array(e)}catch{return}},j:e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength)})},9332(e,t,a){a.d(t,{},{F:"effect/Metric/FiberRuntimeMetrics"})},8137(e,t,a){var l=a(6886),i=a(6896),s=a(4763),o=a(8946),r=a(6307),n=a(471),d=a(1863);let c="~effect/Option",p={[c]:{_A:e=>e},...d.fU,[Symbol.iterator](){return new n.B(this)}},h=Object.defineProperty(Object.assign(Object.create(p),{_tag:"Some",_op:"Some",[l.HR](e){return f(e)&&v(e)&&l.aI(this.value,e.value)},[s.HR](){return s.kg(s.tW(this._tag))(s.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=s.tW("None"),u=Object.assign(Object.create(p),{_tag:"None",_op:"None",valueOrUndefined:void 0,[l.HR]:e=>f(e)&&m(e),[s.HR]:()=>g,toString:()=>"none()",toJSON(){return{_id:"Option",_tag:this._tag}}}),f=e=>(0,r.i5)(e,c),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)})},5005(e,t,a){function l(e,t,a){"__proto__"===t?Object.defineProperty(e,t,{value:a,writable:!0,enumerable:!0,configurable:!0}):e[t]=a}a.d(t,{},{x:l,z:function(e,t){if(!Object.hasOwn(t,"__proto__"))return void Object.assign(e,t);for(let a of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,a)&&l(e,a,t[a])}})},4730(e,t,a){var l=a(369),i=a(4876);let s=l.Or("effect/ErrorReporter/CurrentErrorReporters",{defaultValue:()=>new Set}),o=l.Or("effect/References/CurrentStackFrame",{fiberCached:!0,defaultValue:i.MN}),r=l.Or("effect/References/TracerEnabled",{fiberCached:!0,defaultValue:i.ue}),n=l.Or("effect/References/TracerTimingEnabled",{defaultValue:i.ue}),d=l.Or("effect/References/TracerSpanAnnotations",{defaultValue:()=>({})}),c=l.Or("effect/References/TracerSpanLinks",{defaultValue:()=>[]}),p=l.Or("effect/References/CurrentLogAnnotations",{defaultValue:()=>({})}),h=l.Or("effect/References/CurrentLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),g=l.Or("effect/References/MinimumLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),u=l.Or("effect/References/UnhandledLogLevel",{defaultValue:()=>"Error"}),f=l.Or("effect/References/CurrentLogSpans",{defaultValue:()=>[]});a.d(t,{},{Gl:h,aG:u,ce:d,d8:f,iL:p,ls:c,nU:n,oQ:s,rf:r,vA:o,zQ:g})},1645(e,t,a){var l=a(6886),i=a(6896),s=a(4876),o=a(4763),r=a(8946),n=a(6307),d=a(471),c=a(1863),p=a(8137);let h="~effect/Result",g={[h]:{_A:e=>e,_E:e=>e},...c.fU,[Symbol.iterator](){return new d.B(this)}},u=Object.assign(Object.create(g),{_tag:"Success",_op:"Success",[l.HR](e){return m(e)&&y(e)&&l.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",[l.HR](e){return m(e)&&v(e)&&l.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,s.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})},6046(e,t,a){var l=a(4876);function i(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function s(e){return t=>i(t)?.[e]}let o="~structural",r="~identifier",n="~sentinels",d=s("identifier"),c=s(r),p=s("title"),h=s("description"),g=(0,l.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,{},{C3:o,CD:c,DQ:p,I_:n,KE:d,L1:["title","description","default","examples","readOnly","writeOnly","format","contentEncoding","contentMediaType","contentSchema"],Pk:h,R4:r,UI:u,bo:g,hd:i,ip:s,py:"~constructor"})},2851(e,t,a){var l=a(6313),i=a(2056);function s(e){let t;for(let a of e.reasons){if(!l.lC(a)||!i.gh(a.error))return;t??=a.error}return t}a.d(t,{},{R:s,q:function(e,t){let a=s(e);if(void 0===a)throw Error(t,{cause:e});return a}})},3289(e,t,a){let l=Symbol.for("~effect/Schema/content");a.d(t,{},{I:function(e,t){return Object.defineProperty(e,l,{value:t}),e},_:function(e){return e[l]}})},929(e,t,a){var l=a(5596),i=a(3565);let s=Symbol(),o=l.Py,r=o(s),n=o(s);a.d(t,{},{LO:s,Py:o,Rr:n,e8:e=>"None"===e._tag?r:o(e.value),r2:r,zL:e=>e===s?i.none():i.some(e)})},5158(e,t,a){let l,i=void 0===(l=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"))?Object.isExtensible(Error):Object.hasOwn(l,"writable")?!0===l.writable:void 0!==l.set;a.d(t,{},{ft:e=>{i&&(Error.stackTraceLimit=e)},jt:()=>Error.stackTraceLimit})},5105(e,t,a){let l;a.d(t,{x3j:()=>dA,aoY:()=>Mq,$BZ:()=>M_,y15:()=>de,OvW:()=>cI,Txp:()=>cU,Q5o:()=>x5,Hdr:()=>oT,UA7:()=>bm,JHX:()=>cC,yEg:()=>dr,UhG:()=>dt,OFB:()=>MC,Yep:()=>MS,z4o:()=>os,Ahp:()=>ML,txp:()=>x6,rRT:()=>bv});var i=a(2390),s=a(369),o=a(639),r=a(760),n=a(6215),d=a(2499),c=a(2056),p=a(8510);let h=["flowchart","mindmap","sequence","timeline","chart","state-machine","gantt","er","class","org-chart","venn","journey","sankey","wireframe","quadrant"],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 z=["cloud","datacenter","region","zone","vpc","subnet","cluster","namespace"],C=i.xCb(z);class _ extends i.Xsx("DiagramGroup")({id:f,label:f,parent:i.lqM(f),kind:i.lqM(C),icon:i.lqM(M)}){}class q extends i.Xsx("DiagramLane")({id:f,label:f}){}let L=["database","queue","document","storage"],S=i.xCb(L);class B 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 A extends B.extend("GraphNode")({description:i.lqM(f)}){}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 I extends i.Xsx("DiagramLayout")({direction:w(b,"LR"),edgeRouting:w(k,"orthogonal")}){}class $ 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(q).pipe(i.fXn)),layout:w(I,{direction:"LR",edgeRouting:"orthogonal"}),style:w(H,y),metadata:w(m,{})}){}class F extends Error{constructor(e){super(e),this.name="DiagramValidationError"}}let O=e=>{let t=new Set;for(let a of e){if(t.has(a))return a;t.add(a)}};function E(e){let t=O(e.nodes.map(e=>e.id));if(t)throw new F(`Duplicate node id "${t}" is not allowed.`);let a=O(e.edges.map(e=>e.id));if(a)throw new F(`Duplicate edge id "${a}" is not allowed.`);let l=O((e.groups??[]).map(e=>e.id));if(l)throw new F(`Duplicate group id "${l}" is not allowed.`);let i=new Set((e.groups??[]).map(e=>e.id)),s=new Map((e.groups??[]).flatMap(e=>void 0===e.parent?[]:[[e.id,e.parent]]));for(let[e,t]of s){if(!i.has(t))throw new F(`Group "${e}" references missing parent group "${t}".`);let a=new Set([e]);for(let t=s.get(e);void 0!==t;){if(a.has(t))throw new F(`Group "${e}" is nested inside itself.`);a.add(t),t=s.get(t)}}for(let t of e.nodes)if(void 0!==t.group&&!i.has(t.group))throw new F(`Node "${t.id}" references missing group "${t.group}".`);let o=e.lanes??[],r=O(o.map(e=>e.id));if(r)throw new F(`Duplicate lane id "${r}" is not allowed.`);if(o.length>0&&(e.groups??[]).length>0)throw new F("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 F(`Node "${t.id}" references missing lane "${t.lane}".`);if(void 0===t.lane&&n.size>0)throw new F(`Node "${t.id}" has no lane.`)}let d=new Set(e.nodes.map(e=>e.id));for(let t of e.edges){if(!d.has(t.source))throw new F(`Edge "${t.id}" references missing source node "${t.source}".`);if(!d.has(t.target))throw new F(`Edge "${t.id}" references missing target node "${t.target}".`);if(t.source===t.target)throw new F(`Edge "${t.id}" cannot connect node "${t.source}" to itself.`)}return e}function U(e){return E(i.svK($,{errors:"all"})(e))}let X="chart",T=["bar","line","pie"],R=["vertical","horizontal"],Y=i.xCb(T),D=i.xCb(R);class G extends i.Xsx("ChartSeries")({name:i.Qrq(i.ukk),values:i.O31(i.wYs).pipe(i.fXn)}){}class Z extends i.Xsx("ChartDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(X),kind:Y,categories:i.O31(i.ukk).pipe(i.fXn,i.Sr8(i.tJb(1))),series:i.O31(G).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(D),style:H.pipe(i.tiU(o.PyW({...y})))}){}let j=e=>e.trim().toLowerCase();function N(e){let t=[],{categories:a,kind:l,series:i}=e,s="pie"===l,o=s?8:40;a.length>o&&t.push({code:"chart_too_large",path:"categories",message:`A ${l} chart supports at most ${o} ${s?"slices":"categories"}.`,hint:s?'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(j(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(j(e))}),s&&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,l)=>{let o=`series.[${l}]`;i.length>1&&void 0===e.name&&t.push({code:"invalid_chart_series",path:`${o}.name`,message:`Series ${l+1} needs a name for the legend.`,hint:"Name every series when a chart has more than one."}),void 0!==e.name&&(n.has(j(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(j(e.name))),e.values.length!==a.length&&t.push({code:"chart_series_mismatch",path:`${o}.values`,message:`Series ${e.name?`"${e.name}"`:l+1} has ${e.values.length} values for ${a.length} categories.`,hint:"Give every series exactly one value per category, in category order."}),s&&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."})}),s&&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 d=(e,a,l,i)=>{a||t.push({code:"invalid_chart_option",path:e,message:l,hint:i})};for(let t of(e.stacked&&d("stacked","bar"===l,"Only bar charts stack.",'Remove stacked, or use kind: "bar".'),e.donut&&d("donut",s,"Only pie charts draw as a donut.",'Remove donut, or use kind: "pie".'),void 0!==e.orientation&&d("orientation","bar"===l,"Only bar charts have an orientation.","Remove orientation for line and pie charts."),["categoryAxisTitle","valueAxisTitle"]))void 0!==e[t]&&d(t,!s,"A pie chart has no axes.",`Remove ${t} from the pie chart.`);return t.slice(0,20)}class W extends F{issues;constructor(e){super(e[0]?.message??"Chart failed validation."),this.issues=e,this.name="ChartValidationError"}}function J(e){let t=N(e);if(t.length)throw new W(t);return e}J(i.svK(Z,{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 K="timeline",Q=["event","milestone"],ee=i.xCb(Q);class et 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(ee),lane:i.Qrq(i.ukk),description:i.Qrq(i.ukk)}){}class ea extends i.Xsx("TimelineDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(K),events:i.O31(et).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 el=/^(\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2}))?)?)?$/u;function ei(e,t,a,l=0,i=0,s=0,o=0){let r=new Date(0);return r.setUTCFullYear(e,t-1,a),r.setUTCHours(l,i,s,o),r.getTime()}function es(e){let t=el.exec(e);if(!t)return;let[,a,l,i,s,o,r,n,d]=t,c=Number(a),p=void 0===l?1:Number(l),h=void 0===i?1:Number(i);if(p<1||p>12||h<1||h>new Date(ei(c,p+1,0)).getUTCDate())return;if(void 0===s){let e=void 0!==i?"day":void 0!==l?"month":"year",t=ei(c,p,h),a="day"===e?ei(c,p,h+1):"month"===e?ei(c,p+1,1):ei(c+1,1,1);return{granularity:e,start:t,end:a,fields:{year:c,month:p,day:h,hour:0,minute:0,second:0,millisecond:0}}}let g=Number(s),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===d)return;let v=0;if("Z"!==d){let e=Number(d.slice(1,3)),t=Number(d.slice(4,6));if(e>14||t>59)return;v=(d.startsWith("-")?-1:1)*(60*e+t)}let y=ei(c,p,h,g,u,f,m)-6e4*v;return{granularity:"instant",start:y,end:y,fields:{year:c,month:p,day:h,hour:g,minute:u,second:f,millisecond:m},offsetMinutes:v}}let eo="Use YYYY, YYYY-MM, YYYY-MM-DD, or YYYY-MM-DDTHH:mm[:ss] with Z or ±HH:MM, copied from the source.";function er(e){if(e.lanes)return[...e.lanes];let t=[];for(let a of eh(e))void 0===a.lane||t.includes(a.lane)||t.push(a.lane);return t}function en(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,l=e.events[0]?.date!==void 0,i=void 0!==e.lanes||e.events.some(e=>e.lane);return e.events.forEach((s,o)=>{let r=`events.[${o}]`;a.has(s.id)&&t.push({code:"duplicate_event_id",path:`${r}.id`,message:`Event id "${s.id}" is duplicated.`,hint:"Give each event a unique stable id."}),a.add(s.id);let n=void 0===s.date?void 0:es(s.date);if(void 0===s.date||n||t.push({code:"invalid_timeline_date",path:`${r}.date`,message:`Event "${s.id}" has invalid date "${s.date}".`,hint:eo}),(void 0!==s.date==(void 0!==s.order)||void 0!==s.date!==l)&&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!==s.end){let e=es(s.end);e?(void 0===s.date||"milestone"===s.kind||n&&e.end<=n.start)&&t.push({code:"invalid_timeline_span",path:`${r}.end`,message:`Span "${s.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 "${s.id}" has invalid end "${s.end}".`,hint:eo})}i&&(void 0===s.lane||e.lanes&&!e.lanes.includes(s.lane))&&t.push({code:"invalid_timeline_lane",path:`${r}.lane`,message:`Event "${s.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."}),er(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||l&&void 0!==es(e.today)||t.push({code:"invalid_timeline_date",path:"today",message:`Today "${e.today}" must be a valid date on a dated timeline.`,hint:`${eo} Omit today unless the source states it.`}),t.slice(0,20)}class ed extends F{issues;constructor(e){super(e[0]?.message??"Timeline failed validation."),this.issues=e,this.name="TimelineValidationError"}}function ec(e){let t=en(e);if(t.length)throw new ed(t);return e}function ep(e){return void 0!==e.date?es(e.date)?.start??0/0:e.order??0}function eh(e){return e.events.toSorted((e,t)=>ep(e)-ep(t)||0)}ec(i.svK(ea,{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 eg="flowchart",eu=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 ef 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:eu,ref:i.lqM(ef),message:i.ukk,hint:i.ukk});let em=i.xCb(["start","process","decision","end"]);class ev extends A.extend("FlowchartNode")({kind:em}){}class ey extends P.extend("FlowchartEdge")({label:i.lqM(i.ukk)}){}class ew extends $.extend("FlowchartDiagram")({type:i.uSQ(eg),nodes:i.O31(ev).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(ey).pipe(i.fXn).check(i.tJb(1))}){}function ex(e){let t=new Set,a=new Set;for(let l of e)t.has(l)?a.add(l):t.add(l);return[...a]}function eb(e,t,a){let l=new Set,i=[...e];for(let e=0;e<i.length;e+=1){let s=i[e];if(!(void 0===s||l.has(s)))for(let e of(l.add(s),t.get(s)??[]))i.push(a(e))}return l}function ek(e){let t=[],a=new Set(e.nodes.map(e=>e.id)),{incoming:l,outgoing:i}=function(e){let t=new Map,a=new Map;for(let l of e)t.set(l.target,[...t.get(l.target)??[],l]),a.set(l.source,[...a.get(l.source)??[],l]);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 s=e.groups??[];for(let a of(s.length>8&&t.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"groups"},message:`Flowchart has ${s.length} groups; the supported maximum is 8.`,hint:"Merge related groups or leave minor steps ungrouped."}),ex(s.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(s.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)),l=new Map(t.flatMap(e=>void 0!==e.parent&&a.has(e.parent)?[[e.id,e.parent]]:[])),i=[],s=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=l.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=l.get(a)}o||(s=Math.max(s,t.length))}return s>4&&i.push({code:"flowchart_too_large",ref:{kind:"diagram",id:e.id,path:"groups.parent"},message:`Groups nest ${s} 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),...s.map(e=>e.parent)]);for(let e of s.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 l 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."}),ex(t.map(e=>e.id))))a.push({code:"duplicate_lane_id",ref:{kind:"lane",id:l,path:"lanes"},message:`Lane id "${l}" is used more than once.`,hint:"Give every lane a stable unique id."});let l=new Set(t.map(e=>e.id)),i=[...l].map(e=>`"${e}"`).join(", ");for(let t of e.nodes)void 0!==t.lane&&l.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 s=new Set(e.nodes.map(e=>e.lane));for(let e of t.filter(e=>!s.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)),ex(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 ex(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 l of e.edges)a.has(l.source)||t.push({code:"missing_edge_source",ref:{kind:"edge",id:l.id,path:"edges.source"},message:`Edge "${l.id}" references missing source node "${l.source}".`,hint:"Set edge.source to one of the diagram node ids."}),a.has(l.target)||t.push({code:"missing_edge_target",ref:{kind:"edge",id:l.id,path:"edges.target"},message:`Edge "${l.id}" references missing target node "${l.target}".`,hint:"Set edge.target to one of the diagram node ids."}),l.source===l.target&&t.push({code:"self_loop",ref:{kind:"edge",id:l.id},message:`Edge "${l.id}" connects node "${l.source}" to itself.`,hint:"Connect the edge to a different target node."});let n=e.nodes.filter(e=>"start"===e.kind),d=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===d.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=l.get(a.id)??[],s=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&&s.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===s.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 l=t.map(e=>e.label?.trim()??"");for(let l of t.filter(e=>!e.label?.trim()))a.push({code:"unlabeled_decision_branch",ref:{kind:"edge",id:l.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 ex(l.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,s))}let c=1===n.length?n[0]:void 0;if(c){let a=eb([c.id],i,e=>e.target);for(let l of e.nodes)a.has(l.id)||t.push({code:"unreachable_node",ref:{kind:"node",id:l.id},message:`Node "${l.id}" is not reachable from the start node.`,hint:"Connect every node to the flow that begins at the single start node."});if(d.length>0){let s=eb(d.map(e=>e.id),l,e=>e.source);for(let l of e.nodes)a.has(l.id)&&!s.has(l.id)&&(i.get(l.id)?.length??0)>0&&t.push({code:"nonterminating_node",ref:{kind:"node",id:l.id},message:`Node "${l.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 eM extends F{issues;constructor(e){super(e[0]?.message??"Flowchart failed semantic validation."),this.issues=e,this.name="FlowchartValidationError"}}function ez(e){let t=ek(e);if(t.length>0)throw new eM(t);return e}function eC(e){return ez(i.svK(ew,{errors:"all"})(e))}eC({id:"onboarding-flow",title:"Sketchi onboarding decision flow",type:eg,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:eg,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:eg,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"}}),eC({id:"request-flow-group-logo",title:"Request flow",type:eg,groups:[{id:"vercel",label:"Vercel",icon:{slug:"vercel"}}],nodes:[{id:"page",label:"Next.js page receives the question",kind:"start",icon:{slug:"nextjs"},group:"vercel"},{id:"check",label:"Check Redis cache",kind:"process",icon:{slug:"redis"},group:"vercel"},{id:"hit",label:"Cache hit?",kind:"decision",group:"vercel"},{id:"call",label:"Call OpenAI model",kind:"process",icon:{slug:"openai"}},{id:"store",label:"Store answer in Redis",kind:"process",icon:{slug:"redis"}},{id:"log",label:"Log any errors to Sentry",kind:"process",icon:{slug:"sentry"}},{id:"ret",label:"Return the answer",kind:"end"},{id:"cached",label:"Return cached answer",kind:"end"}],edges:[{id:"page-check",source:"page",target:"check"},{id:"check-hit",source:"check",target:"hit"},{id:"hit-cached",source:"hit",target:"cached",label:"yes"},{id:"hit-call",source:"hit",target:"call",label:"no"},{id:"call-store",source:"call",target:"store"},{id:"store-log",source:"store",target:"log"},{id:"log-ret",source:"log",target:"ret"}],layout:{direction:"TB",edgeRouting:"orthogonal"}});let e_="mindmap";class eq extends i.Xsx("MindmapNodeMetadata")({depth:i.Aiz.check(i.OWK(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class eL extends B.extend("MindmapNode")({kind:i.xCb(["root","topic"]),metadata:eq}){}class eS extends i.Xsx("MindmapEdgeMetadata")({depth:i.Aiz.check(i.yJO(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class eB extends P.extend("MindmapEdge")({metadata:eS}){}class eA extends $.extend("MindmapDiagram")({type:i.uSQ(e_),nodes:i.O31(eL).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(eB).pipe(i.fXn).check(i.tJb(1))}){}function eP(e){E(e);let t=e.nodes.filter(e=>"root"===e.kind);if(1!==t.length)throw new F(`Mindmap must contain exactly one root topic; found ${t.length}.`);let a=t[0];if(!a||0!==a.metadata.depth)throw new F("Mindmap root topic must have depth 0.");let l=new Map,i=new Map(e.nodes.map(e=>[e.id,e])),s=new Map;for(let t of e.edges){l.set(t.target,(l.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 F(`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 F(`Mindmap edge "${t.id}" metadata must match its child topic.`);s.set(t.source,[...s.get(t.source)??[],a.metadata.siblingIndex])}for(let t of e.nodes){let e=l.get(t.id)??0;if(t.id===a.id?0!==e:1!==e)throw new F(`Mindmap topic "${t.id}" must have ${t.id===a.id?"no parent":"exactly one parent"}.`)}for(let[e,t]of s){let a=t.map((e,t)=>t);if([...t].sort((e,t)=>e-t).some((e,t)=>e!==a[t]))throw new F(`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:e_,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",eI=["message","return"],e$=["solid","dashed"],eF=":lifeline";function eO(e){return`${e}${eF}`}let eE=i.xCb(eI),eU=i.xCb(e$);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(eE),style:i.Qrq(eU)}){}class eR 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 eY=i.xCb(["sequence_too_large","duplicate_participant_id","lifeline_id_collision","duplicate_message_id","missing_message_source","missing_message_target"]);function eD(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 l of(e.participants.forEach((e,l)=>{a.has(e.id)?t.push({code:"duplicate_participant_id",path:`participants.[${l}].id`,message:`Participant id "${e.id}" is duplicated.`,hint:"Give every participant a unique stable id and update message references."}):a.set(e.id,l)}),e.participants)){let a=eO(l.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 "${l.id}".`,hint:`Rename the participant so its id does not start with another participant id followed by ${eF}.`})})}let l=new Set;return e.messages.forEach((e,i)=>{l.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."}),l.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:eY,path:i.ukk,message:i.ukk,hint:i.ukk});class eG extends F{issues;constructor(e){super(e[0]?.message??"Sequence diagram failed semantic validation."),this.issues=e,this.name="SequenceValidationError"}}function eZ(e){let t=eD(e);if(t.length>0)throw new eG(t);return e}function ej(e){return eZ(i.svK(eR,{errors:"all"})(e))}ej({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"}]}),ej({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"}]}),ej({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"}]}),ej({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 eN="state-machine",eW=["state","final","choice"],eJ=["TB","LR"],eK=i.xCb(eW);class eQ extends i.Xsx("StateMachineState")({id:i.ukk,label:i.Qrq(i.ukk),kind:i.Qrq(eK),parent:i.Qrq(i.ukk),initial:i.Qrq(i.ukk)}){}class e1 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 e0 extends i.Xsx("StateMachineLayout")({direction:i.xCb(eJ)}){}class e2 extends i.Xsx("StateMachineDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(eN),initial:i.ukk,states:i.O31(eQ).pipe(i.fXn,i.Sr8(i.tJb(1))),transitions:i.O31(e1).pipe(i.fXn,i.tiU(o.PyW([]))),layout:i.Qrq(e0),style:H.pipe(i.tiU(o.PyW({...y})))}){}let e3=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 e5(e){return e.kind??"state"}i.Xsx("StateMachineValidationIssue")({code:e3,path:i.ukk,message:i.ukk,hint:i.ukk});let e4=new Set(["end","ended","final","finish","finished","done","stop","stopped","exit","state","node"]);function e6(e){if(void 0!==e.label)return e.label;let t=e5(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=>e4.has(e.toLowerCase())))return}return e.id}}function e7(e,t){return e.initial??t.find(t=>t.parent===e.id&&"state"===e5(t))?.id}function e8(e){return{...e,states:e.states.map(t=>{let a=e7(t,e.states);return void 0===t.initial&&void 0!==a?{...t,initial:a}:t})}}function e9(e){return new Set(e.states.flatMap(e=>e.parent?[e.parent]:[]))}function te(e,t){return e.replace(t,"").trim()}function tt(e){e=e8(e);let t=[],a=e9(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 l=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."}),l.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."}),l.set(e.id,e);let i=e6(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,i)=>{if(void 0!==e.parent){let a=l.get(e.parent);a&&"state"===e5(a)?void 0!==a.parent&&t.push({code:"nested_composite",path:`states.[${i}].parent`,message:`State "${e.id}" sits in "${a.id}", which itself sits in "${a.parent}".`,hint:"Composite states hold states but not other composites; flatten one level."}):t.push({code:"unknown_parent_state",path:`states.[${i}].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(a.has(e.id)&&void 0===e.initial&&t.push({code:"missing_composite_initial",path:`states.[${i}].initial`,message:`Composite "${e.id}" has no regular substate to enter.`,hint:`Add a regular substate whose parent is "${e.id}", or set initial explicitly to an intended choice substate.`}),void 0!==e.initial){let a=l.get(e.initial);a&&a.parent===e.id&&"final"!==e5(a)||t.push({code:"unknown_initial_state",path:`states.[${i}].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=l.get(e.initial);i&&void 0===i.parent&&"final"!==e5(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 s=new Set,o=new Map;if(e.transitions.forEach((e,i)=>{s.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."}),s.add(e.id),o.set(e.source,(o.get(e.source)??0)+1);let r=l.get(e.source),n=l.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"===e5(r)&&t.push({code:"final_has_outgoing",path:`transitions.[${i}].source`,message:`Transition "${e.id}" leaves final state "${r.id}".`,hint:"A final state has no outgoing transitions. A state that both ends the machine and continues is a regular state with a transition to a new final state, plus its others."}),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."})}),e.states.forEach((a,l)=>{if("choice"===e5(a)&&(o.get(a.id)??0)<2&&t.push({code:"underbranched_choice",path:`states.[${l}]`,message:`Choice "${a.id}" has fewer than two outgoing transitions.`,hint:"Give a choice two or more outgoing transitions, each with a guard."}),"choice"!==e5(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.[${l}]`,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,l=new Set,i=[{id:e.initial,entry:!0}];for(;i.length>0;){let{id:s,entry:o}=i.pop(),r=t.get(s);if(!(!r||a.has(s)&&(!o||l.has(s)))){if(o&&(l.add(s),r.initial&&i.push({id:r.initial,entry:!0})),!a.has(s))for(let t of(a.add(s),r.parent&&i.push({id:r.parent,entry:!1}),e.transitions))t.source===s&&i.push({id:t.target,entry:!0})}}return a}(e);e.states.forEach((e,l)=>{a.has(e.id)||t.push({code:"unreachable_state",path:`states.[${l}]`,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)}i._kM({code:i.uSQ("composite_initial_defaulted"),severity:i.uSQ("warning"),path:i.ukk,message:i.ukk,hint:i.ukk});class ta extends F{issues;constructor(e){super(e[0]?.message??"State machine failed semantic validation."),this.issues=e,this.name="StateMachineValidationError"}}function tl(e){var t=i.svK(e2,{errors:"all"})(e);let a=tt(t);if(a.length>0)throw new ta(a);return e8(t)}tl({id:"order-lifecycle",title:"Order lifecycle",type:eN,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"}]}),tl({id:"media-player",title:"Media player",type:eN,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 ti="gantt";class ts 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 to extends i.Xsx("GanttDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(ti),tasks:i.O31(ts).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 tr(e){let t=es(e);return t?.granularity==="day"?Math.round(t.start/864e5):void 0}function tn(e){return new Date(864e5*e).toISOString().slice(0,10)}function td(e){return!0===e.milestone||0===e.duration}function tc(e){let t=tr(e.start);if(void 0!==t){if(td(e))return{start:t,end:t,milestone:!0};if(void 0!==e.end){let a=tr(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 tp(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 th(e){let t=tp(e);return 0===t.length?[{tasks:e.tasks}]:t.map(t=>({phase:t,tasks:e.tasks.filter(e=>e.phase===t)}))}let tg="Use YYYY-MM-DD, copied from the source.";function tu(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 l=new Set;for(let[e,i]of a.entries())l.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."}),l.add(i.id);let i=void 0!==e.phases||a.some(e=>void 0!==e.phase),s=0;a.forEach((a,o)=>{let r=`tasks.[${o}]`,n=tr(a.start);void 0===n&&t.push({code:"invalid_gantt_date",path:`${r}.start`,message:`Task "${a.id}" has invalid start "${a.start}".`,hint:tg});let d=void 0===a.end?void 0:tr(a.end);void 0!==a.end&&void 0===d&&t.push({code:"invalid_gantt_date",path:`${r}.end`,message:`Task "${a.id}" has invalid end "${a.end}".`,hint:`${tg} end is the last day, inclusive.`});let c=(e,a,l="")=>t.push({code:"invalid_gantt_span",path:`${r}${l}`,message:e,hint:a});td(a)?(!0===a.milestone&&void 0!==a.duration&&0!==a.duration&&c(`Milestone "${a.id}" cannot have a duration.`,"A milestone is one day: give it start only.",".duration"),void 0!==a.end&&void 0!==d&&void 0!==n&&d!==n&&c(`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)?c(`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)?c(`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!==d&&void 0!==n&&d<n?c(`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&&c(`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||td(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)=>{s+=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."}):l.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)})}),s>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,l=[],i=e=>{if("done"!==a.get(e)){if("open"===a.get(e))return[...l.slice(l.indexOf(e)),e];for(let s of(a.set(e,"open"),l.push(e),t.get(e)?.dependsOn??[])){if(s===e||!t.has(s))continue;let a=i(s);if(a)return a}l.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,l)=>{a.some(t=>t.phase===e)||t.push({code:"invalid_gantt_phase",path:`phases.[${l}]`,message:`Phase "${e}" has no tasks.`,hint:"List only phases that tasks name."})})),tp(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:tr(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:`${tg} Omit today unless the source states it.`});let n=[...a.flatMap(e=>{let t=tc(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 tf extends F{issues;constructor(e){super(e[0]?.message??"Gantt chart failed validation."),this.issues=e,this.name="GanttValidationError"}}function tm(e){let t=tu(e);if(t.length)throw new tf(t);return e}tm(i.svK(to,{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 tv="er",ty=["one","zero-or-one","many","one-or-many","zero-or-many"],tw=i.xCb(ty);class tx 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 tb extends i.Xsx("ErEntity")({id:i.ukk,name:i.Qrq(i.ukk),fields:i.O31(tx).pipe(i.fXn,i.tiU(o.PyW([])))}){}class tk extends i.Xsx("ErRelationship")({id:i.ukk,from:i.ukk,to:i.ukk,fromCardinality:tw,toCardinality:tw,label:i.Qrq(i.ukk)}){}class tM extends i.Xsx("ErDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(tv),entities:i.O31(tb).pipe(i.fXn,i.Sr8(i.tJb(1))),relationships:i.O31(tk).pipe(i.fXn,i.tiU(o.PyW([]))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let tz=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 tC(e){return e.name??e.id}function t_(e){let t=e.indexOf(".");return t<0?{entity:e.trim()}:{entity:e.slice(0,t).trim(),field:e.slice(t+1).trim()}}function tq(e){return e.trim().toLowerCase()}function tL(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 l=new Map,i=new Map;e.entities.forEach((e,a)=>{let s=`entities.[${a}]`;/[.:\s]/u.test(e.id)&&t.push({code:"invalid_entity_id",path:`${s}.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".'}),l.has(e.id)&&t.push({code:"duplicate_entity_id",path:`${s}.id`,message:`Entity id "${e.id}" is used more than once.`,hint:"Give every entity a unique id."}),l.set(e.id,e);let o=tC(e),r=i.get(tq(o));void 0!==r&&r!==e.id&&t.push({code:"duplicate_entity_name",path:void 0===e.name?`${s}.id`:`${s}.name`,message:`Entities "${r}" and "${e.id}" are both named "${o}".`,hint:"Give every entity a distinct name, or merge the two."}),i.set(tq(o),e.id),o.length>64&&t.push({code:"er_text_too_long",path:void 0===e.name?`${s}.id`:`${s}.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:`${s}.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,l)=>{let i=`${s}.fields.[${l}]`;for(let[l,s]of(n.has(tq(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(tq(a.name)),[["name",a.name],["type",a.type]]))void 0!==s&&(s.length>64||/\n/u.test(s))&&t.push({code:"er_text_too_long",path:`${i}.${l}`,message:`Field ${l} "${s}" of "${e.id}" is longer than 64 characters or spans lines.`,hint:`Write the field ${l} 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 s=new Set;return e.relationships.forEach((e,a)=>{let i=`relationships.[${a}]`;s.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."}),s.add(e.id);let[o,r]=["from","to"].map(a=>{let s=t_(e[a]),o=l.get(s.entity);return o?void 0===s.field||o.fields.some(e=>tq(e.name)===tq(s.field))?s:void t.push({code:"missing_relationship_field",path:`${i}.${a}`,message:`Relationship "${e.id}" names field "${s.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 "${s.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&&tq(o.field)===tq(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:tz,path:i.ukk,message:i.ukk,hint:i.ukk});class tS extends F{issues;constructor(e){super(e[0]?.message??"ER diagram failed semantic validation."),this.issues=e,this.name="ErValidationError"}}function tB(e){var t=i.svK(tM,{errors:"all"})(e);let a=tL(t);if(a.length>0)throw new tS(a);return t}tB({id:"shop-schema",title:"Shop schema",type:tv,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"}]}),tB({id:"org-schema",title:"Org schema",type:tv,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 tA={PK:"pk",FK:"fk",UK:"unique",UQ:"unique",UNIQUE:"unique",NULL:"nullable",NULLABLE:"nullable","?":"nullable"};function tP(e){let t=e.trim().split(/\s+/u).filter(Boolean),a={},l=e=>tA[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=l(e)??(e.length>1&&e.endsWith("?")?l(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[l(t.shift())]=!0;let i=t.shift()??e.trim(),s=t.join(" ");return s.endsWith("?")&&(s=s.slice(0,-1).trim(),a.nullable=!0),!s&&i.length>1&&i.endsWith("?")&&(i=i.slice(0,-1),a.nullable=!0),{name:i,...s?{type:s}:{},...a}}let tV={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 tH(e){if("string"!=typeof e)return e;let t=e.trim().toLowerCase().replace(/[\s_]+/gu,"-");return ty.includes(t)?t:tV[t]??e}let tI=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),t$="class",tF=["class","abstract","interface","enum"],tO=i.xCb(tF),tE=["public","private","protected","package"],tU=i.xCb(tE),tX={public:"+",private:"-",protected:"#",package:"~"},tT=["inheritance","realization","composition","aggregation","association","dependency"],tR=i.xCb(tT);function tY(e){return"inheritance"===e||"realization"===e}function tD(e){return"association"===e||"composition"===e||"aggregation"===e}class tG extends i.Xsx("ClassAttribute")({name:i.ukk,type:i.Qrq(i.ukk),visibility:i.Qrq(tU),static:i.Qrq(i.v8c)}){}class tZ extends i.Xsx("ClassParameter")({name:i.ukk,type:i.Qrq(i.ukk)}){}class tj extends i.Xsx("ClassMethod")({name:i.ukk,params:i.O31(tZ).pipe(i.fXn,i.tiU(o.PyW([]))),returns:i.Qrq(i.ukk),visibility:i.Qrq(tU),static:i.Qrq(i.v8c),abstract:i.Qrq(i.v8c)}){}class tN extends i.Xsx("ClassNode")({id:i.ukk,name:i.Qrq(i.ukk),kind:i.Qrq(tO),stereotype:i.Qrq(i.ukk),attributes:i.O31(tG).pipe(i.fXn,i.tiU(o.PyW([]))),methods:i.O31(tj).pipe(i.fXn,i.tiU(o.PyW([])))}){}class tW extends i.Xsx("ClassRelationship")({id:i.ukk,kind:tR,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(t$),classes:i.O31(tN).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 tK=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 tQ(e){return e.name??e.id}function t1(e){return e.kind??"class"}i.Xsx("ClassValidationIssue")({code:tK,path:i.ukk,message:i.ukk,hint:i.ukk});let t0={class:void 0,abstract:"abstract",interface:"interface",enum:"enumeration"};function t2(e){return e?`${tX[e]} `:""}function t3(e){return`${t2(e.visibility)}${e.name.trim()}${e.type?`: ${e.type.trim()}`:""}${e.static?" {static}":""}`}function t5(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`${t2(e.visibility)}${e.name.trim()}(${t})${e.returns?`: ${e.returns.trim()}`:""}${a.length>0?` ${a.join(" ")}`:""}`}function t4(e){return e.trim().toLowerCase()}let t6=/^(\d+|\*)(?:\.\.(\d+|\*))?$/u;function t7(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 l=new Map,i=new Map;e.classes.forEach((e,a)=>{let s=`classes.[${a}]`;/[:\s]/u.test(e.id)&&t.push({code:"invalid_class_id",path:`${s}.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."}),l.has(e.id)&&t.push({code:"duplicate_class_id",path:`${s}.id`,message:`Class id "${e.id}" is used more than once.`,hint:"Give every class a unique id."}),l.set(e.id,e);let o=tQ(e),r=void 0===e.name?`${s}.id`:`${s}.name`,n=i.get(t4(o));for(let[a,l,d]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(t4(o),e.id),[["name",o,64],["stereotype",e.stereotype,64]]))void 0!==l&&(!(l.length<=d)||/\n/u.test(l))&&t.push({code:"class_text_too_long",path:"name"===a?r:`${s}.stereotype`,message:`The ${a} of "${e.id}" is longer than ${d} characters or spans lines.`,hint:`Write the ${a} on one line of at most ${d} characters.`});let d=e.attributes.length+e.methods.length;d>30&&t.push({code:"class_too_large",path:s,message:`Class "${e.id}" has ${d} members; the supported maximum is 30.`,hint:"Keep the members the request names."});let c=new Set,p=(a,l,i,o)=>{let r=`${s}.${a}.[${l}]`;c.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."}),c.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,t3(e),`a:${t4(e.name)}`)),e.methods.forEach((e,t)=>p("methods",t,t5(e),`m:${t4(e.name)}(${e.params.map(e=>t4(e.type??e.name)).join(",")})`))});let s=new Set,o=new Map,r=new Set;e.relationships.forEach((e,a)=>{let i=`relationships.[${a}]`;s.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."}),s.add(e.id);let[n,d]=["from","to"].map(a=>{let s=l.get(e[a].trim());return s||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."}),s}),{kind:c}=e;if(n&&d&&tY(c)){let e=`${c}\0${n.id}\0${d.id}`,[a,l]=[t1(n),t1(d)];r.has(e)?t.push({code:"inheritance"===c?"invalid_inheritance":"invalid_realization",path:i,message:`"${n.id}" ${"inheritance"===c?"extends":"implements"} "${d.id}" more than once.`,hint:"Draw each generalization once."}):n.id===d.id?t.push({code:"inheritance_cycle",path:i,message:`"${n.id}" ${"inheritance"===c?"extends":"implements"} itself.`,hint:"A class extends or implements another class, never itself."}):"inheritance"===c&&"interface"===a!=("interface"===l)?t.push({code:"invalid_inheritance",path:i,message:"interface"===a?`Interface "${n.id}" extends "${d.id}", which is not an interface.`:`"${n.id}" extends interface "${d.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"===c&&("interface"===a||"interface"!==l)&&t.push({code:"invalid_realization",path:i,message:"interface"===a?`Interface "${n.id}" implements "${d.id}".`:`"${n.id}" implements "${d.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!==d.id&&o.set(n.id,[...o.get(n.id)??[],d.id])}let p=tD(c);for(let a of["from","to"])for(let l of[`${a}Multiplicity`,`${a}Role`]){let a=e[l];void 0!==a&&(p?a.length>64||/\n/u.test(a)?t.push({code:"class_text_too_long",path:`${i}.${l}`,message:`"${a}" at an end of "${e.id}" is longer than 64 characters or spans lines.`,hint:"Write it on one short line."}):l.endsWith("Multiplicity")&&!function(e){let t=t6.exec(e.trim());if(!t)return!1;let[,a,l]=t;return void 0===l||"*"!==a&&("*"===l||Number(a)<=Number(l))}(a)?t.push({code:"invalid_multiplicity",path:`${i}.${l}`,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"!==l||"composition"!==c||["1","0..1","1..1"].includes(a.trim())||t.push({code:"invalid_multiplicity",path:`${i}.${l}`,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}.${l}`,message:`${"dependency"===c?"A dependency":`An ${c}`} "${e.id}" has a ${l.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"===c?"A dependency":`An ${c}`} "${e.id}" is marked navigable.`,hint:"dependency"===c?"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,d=(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=d(a,[...t,a]);if(e)return e}}n.set(e,2)};for(let e of o.keys()){if(n.has(e))continue;let a=d(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 t8 extends F{issues;constructor(e){super(e[0]?.message??"Class diagram failed semantic validation."),this.issues=e,this.name="ClassValidationError"}}function t9(e){var t=i.svK(tJ,{errors:"all"})(e);let a=t7(t);if(a.length>0)throw new t8(a);return t}let ae={"+":"public","-":"private","#":"protected","~":"package",public:"public",private:"private",protected:"protected",package:"package",internal:"package"};function at(e){let t=e.trim(),a={};for(;;){let e=/^([+\-#~])\s*/u.exec(t);if(e&&!a.visibility){a.visibility=ae[e[1]],t=t.slice(e[0].length);continue}let l=/^(public|private|protected|package|internal|static|abstract)\s+/iu.exec(t);if(!l)break;let i=l[1].toLowerCase();"static"===i?a.static=!0:"abstract"===i?a.abstract=!0:a.visibility=ae[i],t=t.slice(l[0].length)}for(;;){let e=/\s*(?:\{(static|abstract)\}|([$*]))$/iu.exec(t);if(!e||0===e.index)break;let l=(e[1]??e[2]).toLowerCase();"static"===l||"$"===l?a.static=!0:a.abstract=!0,t=t.slice(0,e.index)}return{rest:t.trim(),modifiers:a}}function aa(e){let t=e.indexOf(":");if(t<0)return{name:e.trim()};let[a,l]=[e.slice(0,t).trim(),e.slice(t+1).trim()];return{name:a||e.trim(),...a&&l?{type:l}:{}}}function al(e){let t=[],a=0,l=0;for(let i=0;i<e.length;i+=1){let s=e[i];"<([{".includes(s)?a+=1:">)]}".includes(s)?a=Math.max(0,a-1):","===s&&0===a&&(t.push(e.slice(l,i)),l=i+1)}return t.push(e.slice(l)),t.map(e=>e.trim()).filter(Boolean)}function ai(e){let{rest:t,modifiers:a}=at(e),{visibility:l,static:i}=a;return{...aa(t),...l?{visibility:l}:{},...i?{static:!0}:{}}}function as(e){let{rest:t,modifiers:a}=at(e),l=t.indexOf("("),i=function(e,t){if(t<0)return -1;let a=0;for(let l=t;l<e.length;l+=1)if("("===e[l])a+=1;else if(")"===e[l]&&0==(a-=1))return l;return -1}(t,l),s={...a.visibility?{visibility:a.visibility}:{},...a.static?{static:!0}:{},...a.abstract?{abstract:!0}:{}};if(l<0||i<l){let{name:e,type:a}=aa(t);return{name:e,params:[],...a?{returns:a}:{},...s}}let o=t.slice(i+1).replace(/^\s*:\s*/u,"").trim();return{name:t.slice(0,l).trim()||t,params:al(t.slice(l+1,i)).map(aa),...o?{returns:o}:{},...s}}let ao={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"},ar={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..*"},an=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function ad(e){if(!an(e))return e;let t=(e,t)=>{let a;if("string"==typeof e)return t?as(e):ai(e);if(!an(e))return e;let l={...e};if(void 0!==l.visibility&&(l.visibility="string"==typeof(a=l.visibility)?ae[a.trim().toLowerCase()]??a:a),t){void 0===l.returns&&void 0!==l.returnType&&(l.returns=l.returnType,delete l.returnType);let e=l.params??l.parameters;delete l.parameters,"string"==typeof e?l.params=al(e).map(aa):Array.isArray(e)&&(l.params=e.map(e=>"string"==typeof e?aa(e):e))}return l},a=Array.isArray(e.classes)?e.classes.map(e=>{if(!an(e))return e;let{values:a,...l}=e,i=Array.isArray(l.attributes)?l.attributes:Array.isArray(a)?a:l.attributes;return{...l,...void 0===l.kind&&Array.isArray(a)?{kind:"enum"}:{},...Array.isArray(i)?{attributes:i.map(e=>t(e,!1))}:void 0===i?{}:{attributes:i},...Array.isArray(l.methods)?{methods:l.methods.map(e=>t(e,!0))}:{},..."string"==typeof l.kind?{kind:"enumeration"===l.kind.trim().toLowerCase()?"enum":l.kind.trim().toLowerCase()}:{}}}):e.classes,l=Array.isArray(e.relationships)?e.relationships.map(e=>{if(!an(e))return e;let{source:t,target:a,type:l,...i}=e,s={...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 tT.includes(t)?t:ao[t]??e}(i.kind??l)};for(let e of["fromMultiplicity","toMultiplicity"])void 0!==s[e]&&(s[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=ar[t.toLowerCase().replace(/[\s_]+/gu,"-")];return a||t.replace(/\s*\.\.\s*/gu,"..").replace(/(^|\.\.)[nm]$/iu,"$1*")}(s[e]));for(let e of["from","to","kind"])void 0===s[e]&&delete s[e];return s}):e.relationships;return{...e,...void 0===a?{}:{classes:a},...void 0===l?{}:{relationships:l}}}t9({id:"shapes",title:"Shapes",type:t$,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 ac="org-chart";class ap 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 ah extends i.Xsx("OrgDottedLine")({id:i.ukk,report:i.ukk,manager:i.ukk,label:i.Qrq(i.ukk)}){}class ag extends i.Xsx("OrgChartDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(ac),people:i.O31(ap).pipe(i.fXn,i.Sr8(i.tJb(1))),dottedLines:i.O31(ah).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 au=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 af(e){return e.people.filter(e=>void 0===e.manager)}function am(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 av(e){let t=e.trim().split(/\s+/u).filter(e=>/[\p{L}\p{N}]/u.test(e)),a=t.length>2&&/^(dr|mr|mrs|ms|mx|prof|sir|dame)\.?$/iu.test(t[0])?t.slice(1):t,l=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()??""};return 0===a.length?"?":1===a.length?l(a[0])||"?":`${l(a[0])}${l(a.at(-1))}`}function ay(e){let t=[],a=(e,a,l,i)=>t.push({code:e,path:a,message:l,hint:i}),{people:l,dottedLines:i}=e;l.length>100&&a("org_chart_too_large","people",`An org chart holds at most 100 people; this one has ${l.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 s=new Set;l.forEach((e,t)=>{let l=`people.[${t}]`;e.id.includes(":")&&a("invalid_person_id",`${l}.id`,`Person id "${e.id}" contains a colon.`,"Use a short id without colons, such as ada or vp-eng."),s.has(e.id)&&a("duplicate_person_id",`${l}.id`,`Person id "${e.id}" is used more than once.`,"Give each person a unique id; two people with one name need two ids."),s.add(e.id);let i=(t,i,s)=>{void 0!==i&&i.trim().length>s&&a("org_text_too_long",`${l}.${t}`,`The ${t} of "${e.id}" is longer than ${s} characters.`,`Shorten the ${t} to at most ${s} characters.`)};i("name",e.name,60),i("title",e.title,80),i("department",e.department,40)});let o=am(e);l.forEach((e,t)=>{let l=`people.[${t}]`;if(void 0===e.manager){e.assistant&&a("invalid_assistant",`${l}.assistant`,`Assistant "${e.id}" has no manager.`,"Set manager to the person they assist.");return}e.manager===e.id?a("self_manager",`${l}.manager`,`"${e.id}" is their own manager.`,"Set manager to the person they report to, or omit it for the top person."):s.has(e.manager)||a("unknown_manager",`${l}.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",`${l}.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 l of e){let e=[],i=new Set,s=l.id;for(;void 0!==s&&t.has(s)&&!a.has(s);){if(i.has(s))return[...e.slice(e.indexOf(s)),s];i.add(s),e.push(s),s=t.get(s)}for(let t of e)a.add(t)}}(l);r&&a("reporting_cycle",`people.[${l.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=af(e);n.length>1&&!0!==e.forest&&a("multiple_roots",`people.[${l.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 d=new Map(l.map(e=>[e.id,e]));if(!r&&n.length>0){let e=new Map,t=a=>{let l=e.get(a.id);if(void 0!==l)return l;let i=void 0===a.manager?void 0:d.get(a.manager),s=i&&i.id!==a.id?t(i)+1:1;return e.set(a.id,s),s},i=Math.max(...l.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 c=new Set,p=new Set;return i.forEach((e,t)=>{let l=`dottedLines.[${t}]`;for(let t of(c.has(e.id)&&a("duplicate_dotted_line_id",`${l}.id`,`Dotted line id "${e.id}" is used more than once.`,"Give each dotted line a unique id."),c.add(e.id),["report","manager"]))s.has(e[t])||a("invalid_dotted_line",`${l}.${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",l,`Dotted line "${e.id}" joins "${e.report}" to themselves.`,"A dotted line joins a person to a second manager."):d.get(e.report)?.manager===e.manager&&a("invalid_dotted_line",l,`"${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",l,`"${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",`${l}.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:au,path:i.ukk,message:i.ukk,hint:i.ukk});class aw extends F{issues;constructor(e){super(e[0]?.message??"Org chart failed semantic validation."),this.issues=e,this.name="OrgChartValidationError"}}function ax(e){let t=ay(e);if(t.length>0)throw new aw(t);return e}function ab(e){return ax(i.svK(ag,{errors:"all"})(e))}let ak=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function aM(e,t){let a;for(let l of t)void 0===a&&void 0!==e[l]&&(a=e[l]),delete e[l];return a}let az=["manager","reportsTo","managerId","manager_id","reports_to","parent","boss"],aC=["title","role","position","jobTitle","job_title"],a_=["department","team","dept","division","group"],aq=["dottedLines","dottedLine","dottedLineTo","dottedManager","dottedManagers"];function aL(e){if(!ak(e))return e;let{employees:t,members:a,reportingLines:l,reports:i,edges:s,...o}=e,r=o.people??t??a,n=[],d=new Map;if(Array.isArray(r)){for(let e of r)if(ak(e)){for(let t of["directReports","reports"])if(Array.isArray(e[t]))for(let a of e[t])"string"!=typeof a||d.has(a)||d.set(a,e.id)}}let c=Array.isArray(r)?r.map(e=>{if(!ak(e))return e;let t={...e};Array.isArray(t.directReports)&&delete t.directReports,Array.isArray(t.reports)&&delete t.reports;let a=aM(t,az)??d.get(t.id),l=aM(t,aC),i=aM(t,a_),s=aM(t,aq),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(s)?s:void 0===s?[]:[s]))n.push(ak(e)?{report:t.id,...e}:{report:t.id,manager:e});return{...t,...void 0===o?{}:{name:o},...null==a||""===a?{}:{manager:a},...void 0===l||""===l?{}:{title:l},...void 0===i||""===i?{}:{department:i}}}):r,p=[l,i,s].find(Array.isArray),h=Array.isArray(c)&&p?c.map(e=>{if(!ak(e)||void 0!==e.manager)return e;let t=p.find(t=>ak(t)&&(t.report??t.to??t.target)===e.id&&!0!==t.dotted),a=ak(t)?t.manager??t.from??t.source:void 0;return void 0===a?e:{...e,manager:a}}):c,g=(p??[]).filter(e=>ak(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=>ak(e)&&"string"==typeof e.id?[e.id]:[])),v=f.map(e=>{if(!ak(e))return e;let{from:t,to:a,source:l,target:i,person:s,employee:o,...r}=e,n={...r,report:r.report??t??l??s??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}}}ab({id:"startup-team",title:"Startup team",type:ac,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 aS="venn",aB=Object.freeze({blue:"#2a78d6",orange:"#eb6834",green:"#1baf7a",yellow:"#eda100",pink:"#e87ba4",violet:"#6250d6",red:"#e34948",gray:"#7a7468"}),aA=Object.keys(aB),aP=["blue","orange","green"],aV=/^#[0-9a-fA-F]{6}$/u;class aH extends i.Xsx("VennSet")({id:i.ukk,label:i.ukk,color:i.Qrq(i.ukk)}){}class aI extends i.Xsx("VennRegion")({sets:i.O31(i.ukk).pipe(i.fXn,i.Sr8(i.tJb(1))),label:i.Qrq(i.ukk),items:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),count:i.Qrq(i.Aiz.check(i.OWK(0)))}){}class a$ extends i.Xsx("VennDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(aS),sets:i.O31(aH).pipe(i.fXn,i.Sr8(i.tJb(1))),regions:i.O31(aI).pipe(i.fXn,i.tiU(o.PyW([]))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let aF=i.xCb(["venn_set_count","duplicate_venn_set","invalid_venn_color","unknown_venn_set","duplicate_venn_region","invalid_venn_region","venn_text_too_long","venn_too_large"]);class aO extends i.Xsx("VennValidationIssue")({code:aF,path:i.ukk,message:i.ukk,hint:i.ukk}){}let aE=e=>e.trim().toLowerCase();function aU(e,t){let a=new Map(e.sets.map((e,t)=>[e.id,t]));return[...new Set(t.sets.flatMap(e=>a.get(e)??[]))].sort((e,t)=>e-t)}function aX(e){let t=[],a=(e,a,l,i)=>t.push(new aO({code:e,path:a,message:l,hint:i})),{sets:l,regions:i}=e;(l.length<2||l.length>3)&&a("venn_set_count","sets",`A Venn diagram has 2 or 3 sets, not ${l.length}.`,l.length<2?"Add the set it overlaps with, or use a different diagram.":"Keep the three sets the request compares, or split them into several diagrams.");let s=new Set,o=new Set;l.forEach((e,t)=>{let l=`sets.[${t}]`;s.has(e.id)&&a("duplicate_venn_set",`${l}.id`,`Set id "${e.id}" is used more than once.`,"Give every set a distinct id."),s.add(e.id),o.has(aE(e.label))&&a("duplicate_venn_set",`${l}.label`,`Set label "${e.label}" is used more than once.`,"Give every set a distinct label."),o.add(aE(e.label)),e.label.trim().length>40&&a("venn_text_too_long",`${l}.label`,`The label of set "${e.id}" is longer than 40 characters.`,"Shorten the label to at most 40 characters.");let i=e.color?.trim();void 0===i||aV.test(i)||Object.hasOwn(aB,i.toLowerCase())||a("invalid_venn_color",`${l}.color`,`Set "${e.id}" has an unknown color "${e.color}".`,`Use one of ${aA.join(", ")} or a #rrggbb hex, or omit color.`)});let r=new Map,n=0;return i.forEach((t,i)=>{let o=`regions.[${i}]`,d=t.sets.filter(e=>!s.has(e));for(let e of d)a("unknown_venn_set",`${o}.sets`,`Region ${i+1} names set "${e}", which is not in sets.`,`Key each region by set ids: ${l.map(e=>e.id).join(", ")}.`);if(new Set(t.sets).size!==t.sets.length&&a("invalid_venn_region",`${o}.sets`,`Region ${i+1} lists a set more than once.`,"List each set of a region once."),0===d.length){let l=aU(e,t).join("+"),s=r.get(l);void 0!==s?a("duplicate_venn_region",`${o}.sets`,`Regions ${s+1} and ${i+1} are the same overlap (${t.sets.join(" & ")}).`,"Merge their items into one region."):r.set(l,i)}void 0!==t.items&&void 0!==t.count&&a("invalid_venn_region",o,`Region ${i+1} has both items and a count.`,"Give a region items or a count, not both.");let c=t.items??[];n+=c.length,c.length>12&&a("venn_too_large",`${o}.items`,`Region ${i+1} lists ${c.length} items; a region holds at most 12.`,"Keep the items the request names, group similar ones, or give a count instead."),c.forEach((e,t)=>{e.trim().length>60&&a("venn_text_too_long",`${o}.items.[${t}]`,`Item "${e.slice(0,24)}…" is longer than 60 characters.`,"Shorten each item to a phrase of at most 60 characters.")}),void 0!==t.label&&t.label.trim().length>40&&a("venn_text_too_long",`${o}.label`,`The label of region ${i+1} is longer than 40 characters.`,"Shorten the label to at most 40 characters.")}),n>40&&a("venn_too_large","regions",`The diagram lists ${n} items; a Venn diagram holds at most 40.`,"Keep the items the request names, or give regions counts instead."),t.slice(0,20)}class aT extends F{issues;constructor(e){super(e[0]?.message??"Venn diagram failed semantic validation."),this.issues=e,this.name="VennValidationError"}}function aR(e){let t=aX(e);if(t.length>0)throw new aT(t);return e}function aY(e){return aR(i.svK(a$,{errors:"all"})(e))}let aD=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);aY({id:"product-team-skills",title:"Product team skills",type:aS,sets:[{id:"design",label:"Design"},{id:"engineering",label:"Engineering"},{id:"product",label:"Product"}],regions:[{sets:["design"],items:["Visual design","Prototyping"]},{sets:["engineering"],items:["System design","Code review"]},{sets:["product"],items:["Roadmapping","Pricing"]},{sets:["design","engineering"],items:["Design systems"]},{sets:["design","product"],items:["User research"]},{sets:["engineering","product"],items:["Technical specs"]},{sets:["design","engineering","product"],label:"Shared",items:["Customer empathy"]}]});let aG="journey",aZ=["Very negative","Negative","Neutral","Positive","Very positive"];class aj extends i.Xsx("JourneyStep")({label:i.ukk,score:i.wYs,actor:i.Qrq(i.ukk),touchpoint:i.Qrq(i.ukk)}){}class aN extends i.Xsx("JourneyStage")({name:i.ukk,steps:i.O31(aj).pipe(i.fXn),painPoints:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),opportunities:i.Qrq(i.O31(i.ukk).pipe(i.fXn))}){}class aW extends i.Xsx("JourneyDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(aG),persona:i.Qrq(i.ukk),actors:i.Qrq(i.O31(i.ukk).pipe(i.fXn)),stages:i.O31(aN).pipe(i.fXn,i.Sr8(i.tJb(1))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let aJ=i.xCb(["journey_too_large","empty_journey_stage","duplicate_journey_stage","invalid_journey_score","unknown_journey_actor","duplicate_journey_actor","journey_text_too_long","unplaced_journey_entry"]);i.Xsx("JourneyValidationIssue")({code:aJ,path:i.ukk,message:i.ukk,hint:i.ukk});let aK=e=>e.trim().toLocaleLowerCase(),aQ="(no stage)";function a1(e){let t=[],a=(e,a,l,i)=>t.push({code:e,path:a,message:l,hint:i}),l=(e,t,l,i)=>{void 0!==l&&l.trim().length>i&&a("journey_text_too_long",e,`${t} is longer than ${i} characters.`,`Shorten it to at most ${i} characters; keep the words the source uses.`)},{stages:i}=e;i.length>10&&a("journey_too_large","stages",`A journey map holds at most 10 stages; this one has ${i.length}.`,"Merge neighboring stages, or split the journey into maps of their own.");let s=i.reduce((e,t)=>e+t.steps.length,0);s>40&&a("journey_too_large","stages",`A journey map holds at most 40 steps; this one has ${s}.`,"Keep the steps the source states, or split the journey into maps of their own."),l("persona","The persona",e.persona,80);let o=e.actors;if(void 0!==o){o.length>8&&a("journey_too_large","actors",`A journey map names at most 8 actors; this one has ${o.length}.`,"Keep the actors the source names.");let e=new Set;o.forEach((t,i)=>{e.has(aK(t))&&a("duplicate_journey_actor",`actors.[${i}]`,`Actor "${t.trim()}" is listed more than once.`,"List each actor once."),e.add(aK(t)),l(`actors.[${i}]`,`Actor "${t.trim()}"`,t,32)})}let r=new Set((o??[]).map(aK)),n=new Set;return i.forEach((e,t)=>{let s=`stages.[${t}]`,d=e.name.trim();n.has(aK(d))&&a("duplicate_journey_stage",`${s}.name`,`Stage "${d}" appears more than once.`,"Give each stage one entry and put all its steps there, in order."),n.add(aK(d)),l(`${s}.name`,`Stage "${d}"`,e.name,40);let c=(e.painPoints?.length??0)+(e.opportunities?.length??0),p=i.filter(e=>e.steps.length>0&&e.name!==aQ).map(e=>`"${e.name.trim()}"`).join(", ");for(let t of(d===aQ?a("unplaced_journey_entry",s,e.steps.length+c===1?"A step or note names no stage.":`${e.steps.length+c} steps or notes name no stage.`,p.length>0?`Give each its stage, one of ${p}, or list it under that stage.`:"Give each step its stage, or list the steps under stages: [{ name, steps }]."):0===e.steps.length&&a("empty_journey_stage",`${s}.steps`,c>0?`Stage "${d}" has pain points or opportunities but no steps.`:`Stage "${d}" has no steps.`,c>0&&p.length>0?`Put each note under the stage it belongs to: ${p}; or give "${d}" its steps.`:"Give every stage at least one step, or drop the stage."),e.steps.length>8&&a("journey_too_large",`${s}.steps`,`Stage "${d}" has ${e.steps.length} steps; a stage holds at most 8.`,"Split the stage in two, or keep the steps the source states."),e.steps.forEach((e,t)=>{let i=`${s}.steps.[${t}]`,n=e.label.trim();(!Number.isInteger(e.score)||e.score<1||e.score>5)&&a("invalid_journey_score",`${i}.score`,`Step "${n}" has score ${e.score}.`,"Use a whole number from 1 (very negative) to 5 (very positive); 3 is neutral."),l(`${i}.label`,`Step "${n.slice(0,24)}…"`,e.label,90);let d=void 0===e.actor?[]:function(e,t=[]){let a=e.split(","),l=[];for(let e=0;e<a.length;){let i=a.length;for(;i>e+1&&!t.some(t=>aK(t)===aK(a.slice(e,i).join(",")));)i-=1;let s=a.slice(e,i).join(",").trim();s.length>0&&l.push(s),e=i}return l}(e.actor,o??[]);for(let e of d)l(`${i}.actor`,`Actor "${e}" of "${n}"`,e,32);l(`${i}.touchpoint`,`The touchpoint of "${n}"`,e.touchpoint,32);let c=d.filter(e=>!r.has(aK(e)));void 0!==o&&c.length>0&&a("unknown_journey_actor",`${i}.actor`,`Actor "${c[0]}" of step "${n}" is not one of the journey's actors.`,`Use one of ${o.map(e=>`"${e.trim()}"`).join(", ")}, or add the actor to actors; a step several actors share names them all, "A, B".`)}),["painPoints","opportunities"])){let i=e[t]??[],o="painPoints"===t?"pain points":"opportunities";i.length>4&&a("journey_too_large",`${s}.${t}`,`Stage "${d}" has ${i.length} ${o}; a stage holds at most 4.`,`Keep the ${o} the source states, merging the closest ones.`),i.forEach((e,a)=>l(`${s}.${t}.[${a}]`,`A ${o.replace(/s$/u,"")} of "${d}"`,e,100))}}),t.slice(0,20)}class a0 extends F{issues;constructor(e){super(e[0]?.message??"Journey map failed semantic validation."),this.issues=e,this.name="JourneyValidationError"}}function a2(e){let t=a1(e);if(t.length>0)throw new a0(t);return e}function a3(e){return a2(i.svK(aW,{errors:"all"})(e))}let a5=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function a4(e,t){let a;for(let l of t)void 0===a&&void 0!==e[l]&&(a=e[l]),delete e[l];return a}let a6=["stages","sections","phases"],a7=["name","title","label","stage","section","phase"],a8=["steps","tasks","actions"],a9=["label","task","name","title","action","step"],le=["score","sentiment","emotion","rating","feeling","mood","satisfaction"],lt=["touchpoint","channel","touchPoint","via"],la=["painPoints","pain_points","painpoints","pains","pain"],ll=["opportunities","opportunity","ideas","improvements"],li=["text","label","name","title","description"];function ls(e){return a5(e)?e.name??e.label??e.title??e:e}function lo(e){let t="string"==typeof e?[e]:e;return Array.isArray(t)?t.map(e=>{if(!a5(e))return e;for(let t of li)if("string"==typeof e[t])return e[t];return e}):t}function lr(e){if("string"==typeof e){let t=/^(.+?):\s*(-?\d+(?:\.\d+)?)\s*(?::\s*(.+))?$/u.exec(e.trim());if(!t)return e;let a=t[3]?.split(",").map(e=>e.trim()).filter(Boolean)??[];return{label:t[1].trim(),score:Number(t[2]),...a.length>0?{actor:a.join(", ")}:{}}}if(!a5(e))return e;let t={...e};delete t.stage;let a=a4(t,a9),l=a4(t,le),i=a4(t,lt),s=t.actors;if(Array.isArray(s)){let e=s.map(ls);void 0===t.actor&&e.length>0&&(t.actor=e.every(e=>"string"==typeof e)?e.join(", "):e),delete t.actors}return a5(t.actor)&&(t.actor=ls(t.actor)),{...t,...void 0===a?{}:{label:a},...void 0===l?{}:{score:function(e){if("string"!=typeof e)return e;let t=Number(e.trim());return""!==e.trim()&&Number.isFinite(t)?t:e}(l)},...void 0===i||""===i?{}:{touchpoint:i}}}function ln(e){if(!a5(e))return e;let t={...e},a=a4(t,a7),l=a4(t,a8),i=a4(t,la),s=a4(t,ll);return{...t,...void 0===a?{}:{name:a},...void 0===l?{}:{steps:Array.isArray(l)?l.map(lr):l},...void 0===i?{}:{painPoints:lo(i)},...void 0===s?{}:{opportunities:lo(s)}}}a3({id:"online-purchase-journey",title:"Online purchase journey",type:aG,persona:"Maya, a first-time buyer",stages:[{name:"Discover",steps:[{label:"Sees an ad for running shoes",score:4,touchpoint:"Instagram"},{label:"Reads reviews",score:3,touchpoint:"Website"}],painPoints:["Reviews are hard to filter"],opportunities:["Highlight reviews by runners"]},{name:"Purchase",steps:[{label:"Adds shoes to cart",score:4,touchpoint:"Website"},{label:"Creates an account to pay",score:2,touchpoint:"Website"},{label:"Pays by card",score:3,touchpoint:"Website"}],painPoints:["Forced account creation","Shipping cost shown late"],opportunities:["Offer guest checkout"]},{name:"Delivery",steps:[{label:"Waits for the parcel",score:2,touchpoint:"Email"},{label:"Unboxes the shoes",score:5}],opportunities:["Send live tracking updates"]}]});let ld="sankey",lc=i.QfV.check(i.Pto(/^#[0-9a-fA-F]{6}$/u));class lp extends i.Xsx("SankeyNode")({id:i.ukk,label:i.ukk,color:i.Qrq(lc)}){}class lh extends i.Xsx("SankeyLink")({source:i.ukk,target:i.ukk,value:i.wYs,label:i.Qrq(i.ukk)}){}class lg extends i.Xsx("SankeyDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(ld),nodes:i.O31(lp).pipe(i.fXn,i.Sr8(i.tJb(2))),links:i.O31(lh).pipe(i.fXn,i.Sr8(i.tJb(1))),unit:i.Qrq(i.ukk),style:H.pipe(i.tiU(o.PyW({...y})))}){}let lu=i.xCb(["sankey_too_large","invalid_sankey_node_id","duplicate_sankey_node_id","sankey_text_too_long","unknown_sankey_node","sankey_self_link","duplicate_sankey_link","invalid_sankey_value","sankey_cycle","unlinked_sankey_node","blank_sankey_label"]);function lf(e){let t=new Map;for(let a of e.links)a.source!==a.target&&t.set(a.target,[...t.get(a.target)??[],a.source]);let a=new Map,l=new Set,i=e=>{let s=a.get(e);if(void 0!==s)return s;if(l.has(e))return 0;l.add(e);let o=Math.max(-1,...(t.get(e)??[]).map(i))+1;return l.delete(e),a.set(e,o),o};for(let t of e.nodes)i(t.id);let s=Math.max(0,...a.values()),o=new Set(e.links.map(e=>e.source));for(let l of e.nodes)!o.has(l.id)&&new Set(t.get(l.id)).size>1&&a.set(l.id,s);return a}function lm(e){let[t="",a="0"]=Math.abs(e).toString().split("e");return Math.max(0,(t.split(".")[1]?.length??0)-Number(a))}function lv(e){let t=Math.max(0,...e.map(lm)),a=e.reduce((e,t)=>e+t,0);return t<=100?Number(a.toFixed(t)):Number(a.toPrecision(15))}function ly(e){let t=[],a=(e,a,l,i)=>t.push({code:e,path:a,message:l,hint:i}),{nodes:l,links:i}=e;l.length>40&&a("sankey_too_large","nodes",`A Sankey diagram holds at most 40 nodes; this one has ${l.length}.`,'Fold the smallest nodes of a stage into one "Other" node, or split the flow into several diagrams.'),i.length>100&&a("sankey_too_large","links",`A Sankey diagram holds at most 100 links; this one has ${i.length}.`,'Fold the smallest flows into an "Other" node, or split the flow into several diagrams.');let s=new Set;l.forEach((e,t)=>{let l=`nodes.[${t}]`;e.id.includes(":")&&a("invalid_sankey_node_id",`${l}.id`,`Node id "${e.id}" contains a colon.`,"Use a short id without colons, such as compute or paid-search."),s.has(e.id)&&a("duplicate_sankey_node_id",`${l}.id`,`Node id "${e.id}" is used more than once.`,"Give each node a unique id; list a stage once and send every flow through it."),s.add(e.id),""===e.label.trim()&&a("blank_sankey_label",`${l}.label`,`Node "${e.id}" has a blank label.`,"Give the node the name the source states."),e.label.trim().length>48&&a("sankey_text_too_long",`${l}.label`,`The label of node "${e.id}" is longer than 48 characters.`,"Shorten the label to at most 48 characters.")});let o=new Set,r=new Map;i.forEach((e,t)=>{let l=`links.[${t}]`;for(let i of["source","target"])o.add(e[i]),s.has(e[i])||a("unknown_sankey_node",`${l}.${i}`,`Link ${t+1} names unknown ${i} "${e[i]}".`,"Use the id of a node in nodes, or add the node.");e.source===e.target&&a("sankey_self_link",l,`Link ${t+1} flows from "${e.source}" into itself.`,"A flow runs from one node to another; drop it, or send it to a node of the next stage."),e.value>0||a("invalid_sankey_value",`${l}.value`,`Link "${e.source}" → "${e.target}" has value ${e.value}; flows must be positive.`,e.value<0?"Swap source and target to reverse the flow, and give its size as a positive value.":"Drop a flow of zero, or give its stated value.");let i=`${e.source}\0${e.target}`,n=r.get(i);void 0!==n?a("duplicate_sankey_link",l,`Links ${n+1} and ${t+1} both flow from "${e.source}" to "${e.target}".`,"Merge them into one link whose value is their sum."):r.set(i,t),void 0!==e.label&&""===e.label.trim()&&a("blank_sankey_label",`${l}.label`,`Link ${t+1} has a blank label.`,"Give the label the source states, or omit label."),void 0!==e.label&&e.label.trim().length>40&&a("sankey_text_too_long",`${l}.label`,`The label of link ${t+1} is longer than 40 characters.`,"Shorten the label to at most 40 characters.")}),l.forEach((e,t)=>{o.has(e.id)||a("unlinked_sankey_node",`nodes.[${t}]`,`Node "${e.id}" has no flow in or out.`,"Link it to the stage it feeds or draws from, or remove it.")});let n=function(e){let t=new Map;for(let a of e)a.source!==a.target&&t.set(a.source,[...t.get(a.source)??[],a.target]);let a=new Map,l=[],i=e=>{for(let s of(a.set(e,"open"),l.push(e),t.get(e)??[])){if("open"===a.get(s))return[...l.slice(l.indexOf(s)),s];if(void 0===a.get(s)){let e=i(s);if(e)return e}}l.pop(),a.set(e,"done")};for(let t of e)if(void 0===a.get(t.source)){let e=i(t.source);if(e)return e}}(i);if(n){let e=i.findIndex(e=>e.source===n.at(-2)&&e.target===n.at(-1));a("sankey_cycle",`links.[${e}]`,`Flows run in a cycle: ${n.join(" → ")}.`,`A Sankey diagram flows one way. Drop the flow from "${n.at(-2)}" back to "${n.at(-1)}", or send it to a separate node such as "${n.at(-1)} (returning)".`)}else if(0===t.length){let t=Math.max(...lf(e).values())+1;t>8&&a("sankey_too_large","links",`The flow runs through ${t} stages; a Sankey diagram draws at most 8 columns.`,"Merge consecutive stages, or split the flow into several diagrams.")}return t.slice(0,20)}i.Xsx("SankeyValidationIssue")({code:lu,path:i.ukk,message:i.ukk,hint:i.ukk});class lw extends F{issues;constructor(e){super(e[0]?.message??"Sankey diagram failed semantic validation."),this.issues=e,this.name="SankeyValidationError"}}function lx(e){let t=ly(e);if(t.length>0)throw new lw(t);return e}function lb(e){return lx(i.svK(lg,{errors:"all"})(e))}let lk=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function lM(e,t){let a;for(let l of t)void 0===a&&void 0!==e[l]&&(a=e[l]),delete e[l];return a}let lz=["source","from","src"],lC=["target","to","dst","destination"],l_=["value","amount","weight","count","size","flow"],lq=["label","name","title"];lb({id:"cloud-budget",title:"Cloud budget",type:ld,unit:"$k",nodes:[{id:"engineering",label:"Engineering"},{id:"data",label:"Data"},{id:"marketing",label:"Marketing"},{id:"compute",label:"Compute"},{id:"storage",label:"Storage"},{id:"databases",label:"Databases"},{id:"networking",label:"Networking"}],links:[{source:"engineering",target:"compute",value:180},{source:"engineering",target:"databases",value:60},{source:"engineering",target:"storage",value:40},{source:"engineering",target:"networking",value:25},{source:"data",target:"storage",value:85},{source:"data",target:"compute",value:70},{source:"data",target:"databases",value:30},{source:"marketing",target:"compute",value:12},{source:"marketing",target:"storage",value:8}]});let lL="wireframe",lS=["desktop","tablet","mobile"],lB=["header","footer","sidebar","main","section","card","modal","row","column","grid"],lA=[...lB,"heading","text","link","badge","button","input","textarea","select","checkbox","radio","toggle","search","tabs","nav","breadcrumbs","avatar","icon","image","chart","table","list","divider"],lP=["start","center","end","between"],lV=["bar","line","pie"],lH=["wide","square","tall"],lI=i.DYE(()=>l$),l$=i._kM({type:i.xCb(lA),text:i.Qrq(i.ukk),label:i.Qrq(i.ukk),title:i.Qrq(i.ukk),placeholder:i.Qrq(i.ukk),value:i.Qrq(i.ukk),level:i.Qrq(i.Aiz),lines:i.Qrq(i.Aiz),variant:i.Qrq(i.xCb(["primary","secondary"])),checked:i.Qrq(i.v8c),disabled:i.Qrq(i.v8c),items:i.Qrq(i.O31(i.ukk)),active:i.Qrq(i.ukk),columns:i.Qrq(i.gPz([i.Aiz,i.O31(i.ukk)])),rows:i.Qrq(i.Aiz),kind:i.Qrq(i.xCb(lV)),aspect:i.Qrq(i.xCb(lH)),side:i.Qrq(i.xCb(["left","right"])),align:i.Qrq(i.xCb(lP)),target:i.Qrq(i.ukk),children:i.Qrq(i.O31(lI))});class lF extends i.Xsx("WireframeScreen")({id:i.ukk,name:i.ukk,device:i.xCb(lS).pipe(i.tiU(o.PyW("desktop"))),align:i.Qrq(i.xCb(lP)),children:i.O31(lI).pipe(i.fXn)}){}class lO extends i.Xsx("WireframeDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(lL),screens:i.O31(lF).pipe(i.fXn,i.Sr8(i.tJb(1))),style:H.pipe(i.tiU(o.PyW({...y})))}){}let lE=i.xCb(["wireframe_too_large","invalid_screen_id","duplicate_screen_id","empty_wireframe_screen","unknown_wireframe_target","empty_wireframe_container","missing_wireframe_text","wireframe_text_too_long","invalid_wireframe_option"]);i.Xsx("WireframeValidationIssue")({code:lE,path:i.ukk,message:i.ukk,hint:i.ukk});let lU=new Set(lB),lX=new Set(["heading","text","link","badge","button"]),lT=new Set(["input","textarea","select","checkbox","radio","toggle","avatar","icon","image","chart"]),lR=new Set(["tabs","nav","breadcrumbs","list"]),lY=new Set(["input","textarea","select","search"]),lD=new Set(["checkbox","radio","toggle"]),lG=new Set(["button","input","textarea","select","checkbox","radio","toggle","search","link"]),lZ={text:lX,label:lT,title:lU,placeholder:lY,value:lY,level:new Set(["heading"]),lines:new Set(["text"]),variant:new Set(["button"]),checked:lD,disabled:lG,items:lR,active:new Set(["tabs","nav"]),columns:new Set(["grid","table"]),rows:new Set(["table","textarea"]),kind:new Set(["chart"]),aspect:new Set(["image"]),side:new Set(["sidebar"]),align:lU,target:new Set(["button","link"]),children:lU},lj={text:"Put a form control's or placeholder's name in label, and a container's in title.",label:"Put a heading's, paragraph's, link's, badge's or button's words in text, and a container's name in title.",title:"Only containers take a title; put a widget's words in text or label.",children:"Only containers (header, footer, sidebar, main, section, card, modal, row, column, grid) hold children.",columns:"columns is a grid's column count or a table's column headers.",rows:"rows is a table's placeholder row count or a text area's line count.",items:"items lists tabs, nav items, breadcrumbs or list items; a select shows its value, and each radio has its own label.",value:"value is what an input, text area, select or search bar shows filled in.",target:"Only a button or link opens another screen; set target on the control that does."};function lN(e){let t=[],a=(e,a,l,i)=>t.push({code:e,path:a,message:l,hint:i}),{screens:l}=e;l.length>6&&a("wireframe_too_large","screens",`A wireframe holds at most 6 screens; this one has ${l.length}.`,"Draw each flow as its own wireframe, or keep the screens the request names.");let i=new Set;l.forEach((e,t)=>{let l=`screens.[${t}]`;e.id.includes(":")&&a("invalid_screen_id",`${l}.id`,`Screen id "${e.id}" contains a colon.`,"Use a short id without colons, such as login or checkout."),i.has(e.id)&&a("duplicate_screen_id",`${l}.id`,`Screen id "${e.id}" is used more than once.`,"Give each screen a unique id."),i.add(e.id),e.name.trim().length>60&&a("wireframe_text_too_long",`${l}.name`,`The name of screen "${e.id}" is longer than 60 characters.`,"Shorten the name to at most 60 characters."),0===e.children.length&&a("empty_wireframe_screen",`${l}.children`,`Screen "${e.id}" has no components.`,"Give each screen the components the request describes."),"between"===e.align&&a("invalid_wireframe_option",`${l}.align`,`Screen "${e.id}" sets align "between", which only spreads a row.`,'A screen\'s content stacks down; use align "start", "center" or "end".')});let s=0,o=l.length,r=0;for(let{component:t,path:n,depth:d,screen:c}of function*(e){function*t(e,a,l,i,s){for(let[o,r]of e.entries()){let e=`${a}.children.[${o}]`;yield{component:r,path:e,depth:l,screen:i,parent:s},r.children&&(yield*t(r.children,e,l+1,i,r))}}for(let[a,l]of e.screens.entries())yield*t(l.children,`screens.[${a}]`,1,a,void 0)}(e)){s+=1,o+=function(e){let t=e.items?.length??0;switch(e.type){case"table":{let t=Array.isArray(e.columns)?e.columns.length:1;return 2+t+(e.rows??4)*(2*t+1)}case"tabs":case"list":return 2*t+2;case"nav":return t+2;case"text":return e.text?1:e.lines??3;case"chart":return 12;case"image":return 6;case"modal":case"select":return 5;case"input":case"textarea":case"search":case"checkbox":case"radio":case"toggle":case"card":return 4;default:return 3}}(t)+2*(void 0!==t.target),r=Math.max(r,d),function(e,t,a){let{type:l}=e,i=`The ${l} at ${t}`;for(let[i,s]of Object.entries(lZ))void 0===e[i]||s.has(l)||a("invalid_wireframe_option",`${t}.${i}`,`A ${l} takes no ${i}.`,lj[i]??`Remove ${i}; it applies only to ${[...s].join(", ")}.`);let s=(l,s)=>{let o=e[l];void 0!==o&&o.trim().length>s&&a("wireframe_text_too_long",`${t}.${l}`,`${i} has a ${l} longer than ${s} characters.`,`Shorten the ${l} to at most ${s} characters.`)};s("text","text"===l?280:"heading"===l?80:60),s("label",60),s("title",60),s("placeholder",60),s("value",60);let o=(s,o)=>{void 0===e[s]&&a("missing_wireframe_text",`${t}.${s}`,`${i} has no ${s}.`,`Give the ${l} ${o} as ${s}.`)};("heading"===l||"link"===l||"badge"===l||"button"===l)&&o("text","the words it shows"),lD.has(l)&&o("label","the option it sets");let r=e.items;("tabs"===l||"nav"===l||"breadcrumbs"===l||"list"===l)&&(void 0===r||0===r.length)&&a("missing_wireframe_text",`${t}.items`,`${i} has no items.`,`List the ${"list"===l?"items":"breadcrumbs"===l?"pages of the trail":l} it shows as items.`),void 0!==r&&(r.length>12&&a("wireframe_too_large",`${t}.items`,`${i} lists ${r.length} items; at most 12 read at once.`,"Keep at most 12 items."),r.forEach((e,l)=>{e.trim().length>60&&a("wireframe_text_too_long",`${t}.items.[${l}]`,`Item ${l+1} of ${i.toLowerCase()} is longer than 60 characters.`,"Shorten each item to at most 60 characters.")})),void 0===e.active||void 0===r||r.includes(e.active)||a("invalid_wireframe_option",`${t}.active`,`${i} marks "${e.active}" active, which is not one of its items.`,"Set active to one of items, word for word."),void 0!==e.level&&(e.level<1||e.level>3)&&a("invalid_wireframe_option",`${t}.level`,`Heading level ${e.level} is out of range.`,"Use level 1 for the page title, 2 for a section and 3 below that.");let n=(l,s)=>{let o=e[l];void 0!==o&&(o<1||o>s)&&a(o>s?"wireframe_too_large":"invalid_wireframe_option",`${t}.${l}`,`${i} asks for ${o} ${l}.`,`Use 1 to ${s} ${l}.`)};n("lines",8),n("rows",8);let{columns:d}=e;"grid"===l&&("number"!=typeof d?a("invalid_wireframe_option",`${t}.columns`,`${i} has no column count.`,"Set columns to how many children sit side by side, 1 to 6."):(d<1||d>6)&&a("invalid_wireframe_option",`${t}.columns`,`${i} asks for ${d} columns.`,"Use 1 to 6 columns; more children wrap onto new rows.")),"table"===l&&(Array.isArray(d)&&0!==d.length?(d.length>8&&a("wireframe_too_large",`${t}.columns`,`${i} has ${d.length} columns.`,"Keep at most 8 columns."),d.forEach((e,l)=>{e.trim().length>60&&a("wireframe_text_too_long",`${t}.columns.[${l}]`,`Column ${l+1} of ${i.toLowerCase()} has a header longer than 60 characters.`,"Shorten each header to at most 60 characters.")})):a("missing_wireframe_text",`${t}.columns`,`${i} has no column headers.`,'List the table\'s column headers as columns: ["Order", "Customer", "Total"].')),("row"===l||"column"===l||"grid"===l)&&(e.children?.length??0)===0&&a("empty_wireframe_container",`${t}.children`,`${i} has no children.`,`A ${l} only arranges its children; give it some or remove it.`),"between"===e.align&&"row"!==l&&"header"!==l&&"footer"!==l&&a("invalid_wireframe_option",`${t}.align`,`${i} sets align "between", which only spreads a row, header or footer.`,'Use align "start", "center" or "end" in a column.')}(t,n,a);let{target:e}=t;void 0!==e&&("button"===t.type||"link"===t.type)&&(i.has(e)?e===l[c].id&&a("unknown_wireframe_target",`${n}.target`,`The ${t.type} at ${n} opens its own screen.`,"Set target to another screen, or omit it."):a("unknown_wireframe_target",`${n}.target`,`The ${t.type} at ${n} opens "${e}", which is not a screen.`,`Set target to the id of the screen it opens: ${[...i].slice(0,6).map(e=>`"${e}"`).join(", ")}.`))}return s>160?a("wireframe_too_large","screens",`A wireframe holds at most 160 components; this one has ${s}.`,"Keep the components the request names, or split the screens into separate wireframes."):o>560&&a("wireframe_too_large","screens","This wireframe draws more than one scene holds.","Use fewer table rows and columns, list items or screens."),r>8&&a("wireframe_too_large","screens",`Components nest ${r} levels deep; a wireframe draws at most 8.`,"Drop wrapper rows and columns that hold a single child."),t.slice(0,20)}class lW extends F{issues;constructor(e){super(e[0]?.message??"Wireframe failed semantic validation."),this.issues=e,this.name="WireframeValidationError"}}function lJ(e){let t=lN(e);if(t.length>0)throw new lW(t);return e}function lK(e){return lJ(i.svK(lO,{errors:"all"})(e))}let lQ=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);function l1(e,t,a=!1){let l;for(let i of t){let t=e[i];void 0===l&&void 0!==t&&""!==t&&(a||null!==t)&&(l=t),delete e[i]}return l}let l0=e=>"number"==typeof e&&Number.isFinite(e)?String(e):e,l2=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0,l3=e=>e.toLowerCase().replace(/[\s_-]+/gu,""),l5={h1:"heading",h2:"heading",h3:"heading",h4:"heading",title:"heading",headline:"heading",paragraph:"text",p:"text",body:"text",copy:"text",label:"text",caption:"text",description:"text",placeholdertext:"text",anchor:"link",hyperlink:"link",textlink:"link",tag:"badge",chip:"badge",pill:"badge",status:"badge",cta:"button",btn:"button",textinput:"input",textfield:"input",field:"input",inputfield:"input",formfield:"input",email:"input",password:"input",textbox:"input",multiline:"textarea",dropdown:"select",picker:"select",combobox:"select",check:"checkbox",radiobutton:"radio",switch:"toggle",searchbar:"search",searchbox:"search",searchinput:"search",searchfield:"search",tab:"tabs",tabbar:"tabs",segmented:"tabs",menu:"nav",navbar:"nav",navigation:"nav",navlinks:"nav",menubar:"nav",links:"nav",breadcrumb:"breadcrumbs",crumbs:"breadcrumbs",profile:"avatar",userpic:"avatar",img:"image",photo:"image",picture:"image",thumbnail:"image",media:"image",logo:"image",graph:"chart",barchart:"chart",linechart:"chart",piechart:"chart",sparkline:"chart",datatable:"table",datagrid:"table",ul:"list",ol:"list",bullets:"list",bulletlist:"list",hr:"divider",separator:"divider",rule:"divider",topbar:"header",appbar:"header",toolbar:"header",bottombar:"footer",actionbar:"footer",savebar:"footer",aside:"sidebar",sidenav:"sidebar",drawer:"sidebar",container:"main",content:"main",page:"main",dialog:"modal",popup:"modal",popover:"modal",panel:"card",tile:"card",box:"card",kpi:"card",stat:"card",metric:"card",stack:"column",vstack:"column",vertical:"column",col:"column",form:"column",fieldset:"column",group:"column",hstack:"row",horizontal:"row",buttongroup:"row",actions:"row"},l4=["text","label","title","value","content","name","caption"],l6=["label","text","title","name","alt","caption","initials"],l7=["title","label","text","heading","name"],l8=["children","components","elements","content","body","fields"],l9=["items","options","links","tabs","entries","crumbs","values"];function ie(e){return lQ(e)?l0(e.text??e.label??e.title??e.name??e.value??e):l0(e)}function it(e){if(!lQ(e))return e;let t={...e};delete t.id;let a=l1(t,["type","component","widget","element"]);if(void 0===a&&"string"==typeof t.kind){let e=l3(t.kind);lV.includes(e)||(a=t.kind,delete t.kind)}let l="string"==typeof a?l3(a):void 0,i=void 0===l?a:lA.includes(l)?l:l2(l5,l)??a,s={type:i};if("string"!=typeof i)return{...t,type:i};void 0!==l&&/^h[1-4]$/u.test(l)&&void 0===t.level&&(s.level=Math.min(3,Number(l.slice(1)))),("barchart"===l||"linechart"===l||"piechart"===l)&&(s.kind=l.slice(0,-5)),"cta"===l&&void 0===t.variant&&(s.variant="primary"),"password"===l&&void 0===t.label&&void 0===t.text&&(s.label="Password"),"email"===l&&void 0===t.label&&void 0===t.text&&(s.label="Email");let o=lU.has(i);if(o){let e=l1(t,l8,!0),a=l1(t,l7);void 0!==a&&(s.title=l0(a));let l=t.items,i=Array.isArray(l)&&l.some(lQ)?l:void 0;i&&delete t.items;let o=void 0!==e?e:i;Array.isArray(o)?s.children=o.map(it):void 0!==o&&(s.children=o)}else if(lX.has(i)){let e=l1(t,l4);void 0!==e&&(s.text=l0(e))}else if(lT.has(i)){let e=l1(t,l6);void 0!==e&&(s.label=l0(e))}if(lY.has(i)){let e=l1(t,"select"===i?["value","selected","active","current","defaultValue"]:["value","defaultValue"]);void 0!==e&&(s.value=l0(e)),"select"===i&&l1(t,["items","options","choices"]);let a=l1(t,"search"===i?["placeholder","hint","prompt","text","label"]:["placeholder","hint","prompt"]);void 0!==a&&(s.placeholder=l0(a))}if(lR.has(i)){let e=l1(t,l9,!0);if(Array.isArray(e)){s.items=e.map(ie);let a=e.find(e=>lQ(e)&&(!0===e.active||!0===e.selected||!0===e.current));void 0!==a&&void 0===t.active&&(s.active=ie(a))}else void 0!==e&&(s.items=e);let a=l1(t,["active","selected","current","value","activeTab"]),l="number"==typeof a&&Array.isArray(s.items)?s.items[a]:void 0;void 0!==l?s.active=l:void 0!==a&&(s.active=a)}if(lD.has(i)){let e=l1(t,["checked","selected","on","value","active","enabled"]);"boolean"==typeof e?s.checked=e:void 0!==e&&(s.checked=e)}if(!1===t.enabled&&void 0===t.disabled&&(t.disabled=!0),delete t.enabled,"button"===i||"link"===i){let e=l1(t,["target","navigatesTo","navigateTo","goTo","goesTo","opens","to","href","next","screen"]);void 0!==e&&(s.target=l0(e))}if("button"===i){let e=l1(t,["variant","style","appearance","kind","emphasis"]),a="boolean"==typeof t.primary?l1(t,["primary"]):void 0;if("string"==typeof e){let t=l3(e);s.variant=["primary","filled","solid","cta","main"].includes(t)?"primary":["secondary","outline","outlined","ghost","tertiary","default","text"].includes(t)?"secondary":e}else void 0!==e?s.variant=e:!0===a&&(s.variant="primary")}if("heading"===i&&"string"==typeof t.level){let e=Number(t.level.replace(/^h/iu,""));t.level=Number.isFinite(e)?e:t.level}if("table"===i){let e=l1(t,["columns","headers","fields","cols"],!0);Array.isArray(e)?s.columns=e.map(ie):void 0!==e&&(s.columns=e);let a=l1(t,["rows","data","rowCount"],!0);s.rows=Array.isArray(a)?Math.max(1,Math.min(8,a.length)):a,void 0===s.rows&&delete s.rows}if("grid"===i){let e=l1(t,["columns","cols","columnCount"],!0),a="string"==typeof e?Number(e):e;void 0!==e&&(s.columns=Number.isInteger(a)?a:e)}if("chart"===i){let e=l1(t,["kind","chartType","variant"]);if("string"==typeof e){let t=l3(e).replace(/chart$/u,"");s.kind="donut"===t?"pie":"area"===t?"line":t}else void 0!==e&&(s.kind=e)}if("sidebar"===i){let e=l1(t,["side","position","placement"]);void 0!==e&&(s.side=e)}if(o){let e=l1(t,["align","justify","alignment"]);if("string"==typeof e){let t=l3(e);s.align="left"===t||"top"===t||"flexstart"===t?"start":"right"===t||"bottom"===t||"flexend"===t?"end":"middle"===t||"centre"===t?"center":"spacebetween"===t||"spread"===t?"between":e}else void 0!==e&&(s.align=e)}return{...t,...s}}let ia={phone:"mobile",mobile:"mobile",iphone:"mobile",android:"mobile",ios:"mobile",smartphone:"mobile",tablet:"tablet",ipad:"tablet",desktop:"desktop",web:"desktop",browser:"desktop",laptop:"desktop",webapp:"desktop"};lK({id:"mobile-login",title:"Mobile login",type:lL,screens:[{id:"login",name:"Login",device:"mobile",children:[{type:"image",label:"Logo",aspect:"square"},{type:"heading",text:"Welcome back"},{type:"text",text:"Sign in to see your orders and saved items."},{type:"input",label:"Email",placeholder:"you@example.com"},{type:"input",label:"Password",placeholder:"••••••••"},{type:"checkbox",label:"Remember me",checked:!0},{type:"button",text:"Sign in",variant:"primary"},{type:"link",text:"Forgot password?"},{type:"divider"},{type:"row",align:"center",children:[{type:"text",text:"New here?"},{type:"link",text:"Create an account"}]}]}]});let il="quadrant",ii=["topLeft","topRight","bottomLeft","bottomRight"];class is extends i.Xsx("QuadrantAxis")({title:i.ukk,low:i.ukk,high:i.ukk}){}class io extends i.Xsx("QuadrantNames")({topLeft:i.ukk,topRight:i.ukk,bottomLeft:i.ukk,bottomRight:i.ukk}){}class ir extends i.Xsx("QuadrantPoint")({label:i.ukk,x:i.wYs,y:i.wYs,group:i.Qrq(i.ukk)}){}class id extends i.Xsx("QuadrantDiagram")({id:i.ukk,title:i.ukk,type:i.uSQ(il),xAxis:is,yAxis:is,quadrants:io,points:i.O31(ir).pipe(i.fXn),style:H.pipe(i.tiU(o.PyW({...y})))}){}let ic=e=>e.trim().replace(/\s+/gu," ").toLowerCase();function ip(e){let t=new Map;for(let a of e.points)void 0===a.group||t.has(ic(a.group))||t.set(ic(a.group),a.group);return[...t.values()]}function ih(e){let t=[],a=(e,a,l,i)=>{a.trim()?a.length>l&&t.push({code:"invalid_quadrant_text",path:e,message:`${i} "${a.slice(0,24)}…" is longer than ${l} characters.`,hint:`Shorten it to at most ${l} characters; the chart has no room for prose.`}):t.push({code:"invalid_quadrant_text",path:e,message:`${i} is blank.`,hint:"Give it the words the request uses, or drop the item it belongs to."})};for(let t of["xAxis","yAxis"])a(`${t}.title`,e[t].title,40,"Axis title"),a(`${t}.low`,e[t].low,30,"Axis end label"),a(`${t}.high`,e[t].high,30,"Axis end label");for(let t of ii)a(`quadrants.${t}`,e.quadrants[t],40,"Quadrant name");e.points.length>30&&t.push({code:"quadrant_too_large",path:"points",message:"A quadrant chart supports at most 30 points.",hint:"Keep the points the request names, or split them into several charts."});let l=ip(e);l.length>6&&t.push({code:"quadrant_too_large",path:"points",message:`A quadrant chart supports at most 6 groups; this one has ${l.length}.`,hint:"Merge groups, or leave group off points that need no color of their own."});let i=new Set;return e.points.forEach((e,l)=>{let s=`points.[${l}]`;for(let l of(a(`${s}.label`,e.label,40,"Point label"),void 0!==e.group&&a(`${s}.group`,e.group,30,"Group name"),["x","y"]))(e[l]<0||e[l]>1)&&t.push({code:"invalid_quadrant_point",path:`${s}.${l}`,message:`Point "${e.label}" has ${l} ${e[l]}, outside 0 to 1.`,hint:`Scale ${l} to 0..1 along its axis: 0 is the low end, 1 the high end, 0.5 the middle line. Divide a score out of 100 by 100, or out of 10 by 10.`});i.has(ic(e.label))&&t.push({code:"invalid_quadrant_point",path:`${s}.label`,message:`Point "${e.label}" is listed more than once.`,hint:"List each item once, or tell repeated items apart in their labels."}),i.add(ic(e.label))}),t.slice(0,20)}class ig extends F{issues;constructor(e){super(e[0]?.message??"Quadrant chart failed validation."),this.issues=e,this.name="QuadrantValidationError"}}function iu(e){let t=ih(e);if(t.length)throw new ig(t);return e}iu(i.svK(id,{errors:"all"})({id:"effort-impact-backlog",title:"Effort vs impact",type:il,xAxis:{title:"Effort",low:"Low effort",high:"High effort"},yAxis:{title:"Impact",low:"Low impact",high:"High impact"},quadrants:{topLeft:"Quick wins",topRight:"Major projects",bottomLeft:"Fill-ins",bottomRight:"Thankless tasks"},points:[{label:"Dark mode",x:.2,y:.7},{label:"SSO login",x:.75,y:.85},{label:"CSV export",x:.3,y:.35},{label:"Rewrite billing",x:.9,y:.3},{label:"Onboarding tour",x:.45,y:.6}]}));let im=[0,.25,.5,.75,1];function iv(e){return Math.round(100*e)/100}function iy(e){let[t,a,l,i]=e;return im.map(e=>{let s=1-e,[o,r,n,d]=[s*s*s,3*s*s*e,3*s*e*e,e*e*e];return{x:iv(o*t.x+r*a.x+n*l.x+d*i.x),y:iv(o*t.y+r*a.y+n*l.y+d*i.y)}})}let iw=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ix=/\p{Emoji_Presentation}|\uFE0F|\p{Regional_Indicator}|\u20E3/u,ib=/^[\uFE00-\uFE0F\u200B-\u200D\u2060]+$/u;function ik(e){return Array.from(iw.segment(e),e=>e.segment)}function iM(e){var t;return ib.test(e)?0:ix.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 iz(e){return ik(e).reduce((e,t)=>e+iM(t),0)}function iC(e,t){return Math.max(...e.split("\n").map(e=>(function(e,t){let a=0,l=0;for(let t of ik(e)){let e=iM(t);62===e?a+=1:l+=e}return a*t*.62+l*t/100})(e,t)))}function i_(e,t,a){let l=iC(e,t);return Math.max(1,Math.min(a,Math.ceil(l)),Math.ceil(l-t))}function iq(e,t,a){return Math.max(i_(e,t,a),Math.ceil(iC(e,t)))}function iL(e,t){return e.split("\n").flatMap(e=>(function(e,t){if(iz(e)<=t)return[e];let a=[],l="";for(let i of e.split(" ")){if(iz(i)>t){l&&(a.push(l),l=""),a.push(...function(e,t){let a=(function(e){let t=[],a="";for(let l of ik(e)){if(!(iM(l)>62)){a+=l;continue}a&&t.push(a),t.push(l),a=""}return a&&t.push(a),t})(e).flatMap(e=>iz(e)>t?function(e,t){let a=Math.max(t,1488);return iz(e)<=a?[e]:e.split(/(?<=[/\-_.])(?=.)|(?<=\p{Ll})(?=\p{Lu})/u).flatMap(e=>iz(e)<=a?[e]:function(e,t){let a=[],l="",i=0;for(let s of ik(e)){let e=iM(s);l&&i+e>t&&(a.push(l),l="",i=0),l+=s,i+=e}return l&&a.push(l),a}(e,t))}(e,t):[e]),l=[],i="";for(let e of a){if(iz(e)>t){i&&l.push(i),l.push(e),i="";continue}i&&iz(i+e)>t&&(l.push(i),i=""),i+=e}return i&&l.push(i),l}(i,t));continue}let e=l?`${l} ${i}`:i;if(iz(e)<=t){l=e;continue}a.push(l),l=i}return l&&a.push(l),a})(e,t)).join("\n")}function iS(e,t,a){return iL(e,Math.floor(100*t/a+1e-6))}let iB=Object.freeze({maxDimension:16384,maxElements:600,maxGroupsPerElement:16,maxLayouts:128,maxLayers:64,maxPointsPerElement:256,maxSerializedBytes:15e5,maxTextLength:4096,maxZOrderEntries:600}),iA=Object.freeze({boundTextPadding:5,gap:4,maxAssetBytes:65536,maxSize:64,maxTotalAssetBytes:786432,minSize:16}),iP=["cylinder","pipe","document","bucket"];function iV(e){return iP.includes(e)}let iH={cylinder:12,pipe:12,document:5,bucket:12};function iI(e){return Math.round(.08*e)}function i$(e,t,a,l,i,s,o=12){return Array.from({length:o+1},(r,n)=>{let d=i+(s-i)*n/o;return{x:Math.round((e+a*Math.cos(d))*100)/100,y:Math.round((t+l*Math.sin(d))*100)/100}})}function iF(e,t,a,l=12,i=0){let{x:s,y:o,width:r,height:n}=e,d=s+r/2,c=o+n/2;if(a){let e=o+t,a=o+n-t;return{back:i$(d,e,r/2,t,0,-Math.PI,l),front:i$(d,e,r/2,t,Math.PI,0,l),end:i$(d,a,r/2-i,t,Math.PI,0,l),sides:[[{x:s,y:e},{x:s+i,y:a}],[{x:s+r,y:e},{x:s+r-i,y:a}]]}}let p=s+r-t,h=s+t;return{back:i$(p,c,t,n/2,-Math.PI/2,Math.PI/2,l),front:i$(p,c,t,n/2,-Math.PI/2,-(3*Math.PI)/2,l),end:i$(h,c,t,n/2,Math.PI/2,3*Math.PI/2,l),sides:[[{x:h,y:o},{x:p,y:o}],[{x:h,y:o+n},{x:p,y:o+n}]]}}function iO(e,t){let{x:a,y:l,width:i,height:s}=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((l+s-t*(1-Math.cos(4*Math.PI*r)))*100)/100}})}function iE(e,t,a){let{x:l,y:i,width:s,height:o}=e,r=iH[e.shape],n=l+s/2,d=i+o/2,c=(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:l+r-c(a.y-d,o/2),y:a.y}:"right"===t?{x:l+s-r+c(a.y-d,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-l)/s));return{x:a.x,y:i+o-r*(1-Math.cos(4*Math.PI*e))}}let p="bucket"===e.shape?iI(s):0,[h,g]=[i+r,i+o-r];if("top"===t)return{x:a.x,y:h-c(a.x-n,s/2)};if("bottom"===t)return{x:a.x,y:g+c(a.x-n,s/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?l+u:l+s-u,y:a.y}}function iU(e,t,a=1){let l=iX(e);return l.slice(1).some((e,i)=>{let s=l[i],[o,r]=[e.x-s.x,e.y-s.y],n=Math.max(0,Math.min(1,((t.x-s.x)*o+(t.y-s.y)*r)/(o*o+r*r||1)));return Math.hypot(t.x-s.x-n*o,t.y-s.y-n*r)<=a})}function iX(e){let{x:t,y:a,width:l}=e,i=iH[e.shape];if("document"===e.shape)return[{x:t,y:a},{x:t+l,y:a},...iO(e,i),{x:t,y:a}];let{back:s,end:o}=iF(e,i,"pipe"!==e.shape,24,"bucket"===e.shape?iI(l):0);return[...s,...o,s[0]]}let iT=["zone","sequence-lifeline","sequence-activation","timeline-marker","chart-mark","state-marker","gantt-mark","er-table","er-optional","class-box","swimlane","swimlane-header","venn-set","journey-mark","sankey-mark","wireframe-widget","wireframe-region","quadrant-mark"],iR=["sequence-lifeline","sequence-activation","timeline-marker","chart-mark","er-optional","swimlane","zone"],iY=new Set(["chart-mark","sankey-mark","gantt-mark","er-table","class-box","swimlane","swimlane-header","zone","wireframe-region","quadrant-mark"]);function iD(e){return"rectangle"===e.shape&&(void 0===e.rendererRole||!iY.has(e.rendererRole))}function iG(e){return iD(e)?Math.min(Math.min(e.width,e.height)/4,"wireframe-widget"===e.rendererRole?8:32):0}let iZ={"chart-mark":"Chart mark","class-box":"Class box","er-optional":"Optional relationship end","er-table":"Entity table","gantt-mark":"Gantt mark","journey-mark":"Journey mark","quadrant-mark":"Quadrant mark","sequence-activation":"Sequence activation","sequence-lifeline":"Sequence lifeline","state-marker":"State marker",swimlane:"Swimlane","swimlane-header":"Swimlane header","timeline-marker":"Timeline marker","venn-set":"Venn set","sankey-mark":"Sankey mark","wireframe-region":"Wireframe region","wireframe-widget":"Wireframe widget",zone:"Zone"};function ij(e){let t=new Set;for(let a of e){if(t.has(a))return a;t.add(a)}}function iN(e){return"x"in e&&"y"in e}let iW=new TextEncoder;function iJ(e){return iW.encode(e).byteLength}function iK(e){let t=iA.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*iH.pipe,y:t}:"bucket"===e.shape?{x:t+iI(e.width),y:t+2*iH.bucket}:"cylinder"===e.shape||"document"===e.shape?{x:t,y:t+2*iH[e.shape]}:{x:t,y:t}}function iQ(e){let t=2*iA.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*iH.pipe,height:e.height-t}:"cylinder"===e.shape||"document"===e.shape?{width:e.width-t,height:e.height-t-4*iH[e.shape]}:"bucket"===e.shape?{width:e.width-t-2*iI(e.width),height:e.height-t-4*iH.bucket}:{width:e.width-t,height:e.height-t}}function i1(e){return e?e.size+2*iA.gap:0}function i0(e){let t=new Map(e.layers.map(e=>[e.id,e]));return e=>!e.layerId||t.get(e.layerId)?.visible!==!1}function i2(e,t){let a=new Map;for(let[l,i]of e.elements.entries())"text"===i.type&&i.containerId&&t(i)&&a.set(i.containerId,{element:i,index:l});return a}function i3(e,t,a){let l=t?.text??e.label,i=t?.fontSize??16,s=t?t.maxWidth??160:Math.max(1,e.width-24),o=l.split("\n"),r=iC(l,i),n=Math.max(1,Math.min(s,r)),d=Math.ceil(o.length*i*1.35);if(i_(l,i,s)-i+24>e.width)return!0;if(a||iV(e.shape)){let t=iQ(e);return r>t.width||d+i1(a)>t.height}return n+24>e.width||d+18>e.height}function i5(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>iB.maxElements&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${iB.maxElements} elements.`,path:"elements"}),e.layers.length>iB.maxLayers&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${iB.maxLayers} layers.`,path:"layers"}),e.layouts.length>iB.maxLayouts&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${iB.maxLayouts} layout primitives.`,path:"layouts"}),(e.width>iB.maxDimension||e.height>iB.maxDimension)&&t.push({code:"limit_exceeded",message:`Canvas dimensions may not exceed ${iB.maxDimension}.`,path:"width"});let a=ij(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 l=ij(e.layers.map(e=>e.id));l&&t.push({code:"duplicate_layer_id",message:`Duplicate layer id "${l}" is not allowed.`,path:"layers"});let i=ij(e.zOrder);i&&t.push({code:"duplicate_z_order_element",elementId:i,message:`zOrder contains duplicate element "${i}".`,path:"zOrder"}),e.zOrder.length>iB.maxZOrderEntries&&t.push({code:"limit_exceeded",message:`zOrder exceeds ${iB.maxZOrderEntries} entries.`,path:"zOrder"});let s=new Map(e.elements.map(e=>[e.id,e])),o=e.elements.filter(e=>"node"===e.type),r=si(e.elements),n=ij([...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 d=ij(e.elements.flatMap(e=>"arrow"===e.type?[e.edgeId]:[]));d&&t.push({code:"invalid_binding",message:`Duplicate edgeId "${d}" makes connector selection ambiguous.`,path:"elements"});let c=ij(e.elements.flatMap(e=>"text"===e.type&&e.containerId?[e.containerId]:[]));c&&t.push({code:"invalid_binding",elementId:c,message:`Container "${c}" has more than one bound text element.`,path:"elements"});let p=new Set(e.layers.map(e=>e.id)),h=i0(e),g=i2(e,h);t.push(...function(e){let t=[],a=0;for(let[l,i]of Object.entries(e.icons??{})){let e=iJ(i.svg);a+=e,e>iA.maxAssetBytes&&t.push({code:"limit_exceeded",message:`Icon asset "${l}" exceeds ${iA.maxAssetBytes} bytes.`,path:`icons.${l}`})}return a>iA.maxTotalAssetBytes&&t.push({code:"limit_exceeded",message:`Icon assets exceed ${iA.maxTotalAssetBytes} bytes per canvas.`,path:"icons"}),t}(e)),e.elements.forEach((a,l)=>{let i,o;if(t.push(...(i=[],o=`elements[${l}]`,"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>iB.maxPointsPerElement&&i.push({code:"limit_exceeded",elementId:a.id,message:`Element "${a.id}" exceeds ${iB.maxPointsPerElement} points.`,path:`${o}.points`}),"text"in a&&a.text.length>iB.maxTextLength&&i.push({code:"limit_exceeded",elementId:a.id,message:`Text element "${a.id}" exceeds ${iB.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>iB.maxGroupsPerElement&&i.push({code:"limit_exceeded",elementId:a.id,message:`Element "${a.id}" exceeds ${iB.maxGroupsPerElement} groups.`,path:`${o}.groupIds`}),i)),("node"===a.type||"frame"===a.type)&&t.push(...function(e,t,a){let l=t.icon;if(!l)return[];let i=`elements[${a}].icon`,s="frame"===t.type?"Frame":"Node",o=[];return"node"===t.type&&t.rendererRole&&"zone"!==t.rendererRole&&o.push({code:"invalid_icon",elementId:t.id,message:`${iZ[t.rendererRole]} "${t.id}" cannot carry an icon.`,path:i}),u(l.slug)?e.icons&&Object.hasOwn(e.icons,l.slug)||o.push({code:"invalid_icon",elementId:t.id,message:`${s} "${t.id}" references icon "${l.slug}" without an embedded asset.`,path:`${i}.slug`}):o.push({code:"invalid_icon",elementId:t.id,message:`${s} "${t.id}" has an invalid icon slug "${l.slug}".`,path:`${i}.slug`}),(!Number.isFinite(l.size)||l.size<iA.minSize||l.size>iA.maxSize)&&o.push({code:"invalid_icon",elementId:t.id,message:`${s} "${t.id}" icon size must be ${iA.minSize}-${iA.maxSize}.`,path:`${i}.size`}),o}(e,a,l)),"node"===a.type&&"polygon"!==a.shape&&h(a)){let e=g.get(a.id);(e||void 0===a.rendererRole)&&i3(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[${l}].label`})}if(a.frameId){let e=s.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[${l}].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[${l}].layerId`}),a.groupIds&&ij(a.groupIds)&&t.push({code:"invalid_composition",elementId:a.id,message:`Element "${a.id}" contains duplicate group ids.`,path:`elements[${l}].groupIds`}),"text"===a.type&&a.containerId){let e=s.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[${l}].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[${l}].sourceNodeId`}),r.has(a.targetNodeId)||t.push({code:"invalid_binding",elementId:a.id,message:`Connector "${a.id}" references missing target "${a.targetNodeId}".`,path:`elements[${l}].targetNodeId`})),"line"===a.type)for(let[e,i]of[["startBinding",a.startBinding],["endBinding",a.endBinding]]){let o=i?s.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[${l}].${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)s.has(a)||t.push({code:"unknown_z_order_element",elementId:a,message:`zOrder references missing element "${a}".`,path:"zOrder"});for(let[a,l]of e.layouts.entries())for(let e of l.ids){let l=s.get(e);l&&iN(l)||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]),l=a.frameId;for(;l;){if(e.has(l)){t.push({code:"invalid_composition",elementId:a.id,message:`Frame "${a.id}" participates in a frame nesting cycle.`,path:"elements"});break}e.add(l);let i=s.get(l);l=i?.type==="frame"?i.frameId:void 0}}return t}function i4(e){if("text"===e.type){let t=e.text.split("\n");return{x:e.x,y:e.y,width:e.maxWidth??iC(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 i6(e,t){let a=new Map(e.map(e=>[e.id,e]));return t.flatMap(e=>{let t=a.get(e);return t&&iN(t)?[t]:[]})}function i7(e,t){return e.map(e=>{var a,l;let i=t.get(e.id);return i?(a=i.x,l=i.y,iN(e)?{...e,x:a,y:l}:e):e})}function i8(e,t){return"x"===t?e.x:e.y}function i9(e,t){return"x"===t?e.width:e.height}function se(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function st(e,t){let a=se(e),l=t.x-a.x,i=t.y-a.y,[s,o]=Math.abs(l)>=Math.abs(i)?[l>=0?"right":"left",{x:l>=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&&iV(e.shape)?iE({...e,shape:e.shape},s,o):o}function sa(e,t){let a=t.width/2,l=t.height/2,i=(e.x-t.x-a)/a,s=(e.y-t.y-l)/l,o="node"===t.type?t.shape:"rectangle";if("node"===t.type&&iV(t.shape))return iU({...t,shape:t.shape},e,1);let r=.5/Math.min(a,l);if("ellipse"===o||"circle"===o)return Math.abs(Math.hypot(i,s)-1)<=r;if("diamond"===o)return Math.abs(Math.abs(i)+Math.abs(s)-1)<=r;let n=(e,t,a)=>e>=t-.5&&e<=a+.5,d=(e,t)=>.5>=Math.abs(e-t);return n(e.y,t.y,t.y+t.height)&&(d(e.x,t.x)||d(e.x,t.x+t.width))||n(e.x,t.x,t.x+t.width)&&(d(e.y,t.y)||d(e.y,t.y+t.height))}function sl(e,t){let a=st(e,se(t)),l=st(t,se(e)),i=se(e),s=se(t),o=Math.abs(s.x-i.x)>=Math.abs(s.y-i.y),r=o?"x":"y",n=(l[r]-a[r])/2,d=(e,t)=>o?{x:e.x+t,y:e.y}:{x:e.x,y:e.y+t};return iy([a,d(a,n),d(l,-n),l])}function si(e){return new Map(e.flatMap(e=>"node"===e.type||"frame"===e.type&&void 0!==e.nodeId?[[e.nodeId,e]]:[]))}function ss(e,t=.01){let a=[];for(let l=0;l<e.length-1;l+=1){let i=e[l],s=e[l+1];if(!i||!s)continue;let o=Math.abs(i.y-s.y)<=t,r=Math.abs(i.x-s.x)<=t;if(!o&&!r)continue;let n=Math.min(o?i.x:i.y,o?s.x:s.y),d=Math.max(o?i.x:i.y,o?s.x:s.y);d-n<=t||a.push({min:n,max:d,orientation:o?"horizontal":"vertical",staticCoordinate:o?i.y:i.x,segmentIndex:l,isFirstSegment:0===l,isLastSegment:l===e.length-2})}return a}function so(e,t){return Math.min(e.max,t.max)-Math.max(e.min,t.min)}function sr(e,t,a=.01){return e.orientation===t.orientation&&Math.abs(e.staticCoordinate-t.staticCoordinate)<=a&&so(e,t)>a}function sn(e,t,a=.01){let l="horizontal"===e.orientation,i=l?t.y:t.x,s=i+(l?t.height:t.width),o=l?t.x:t.y,r=o+(l?t.width:t.height);return e.staticCoordinate>i+a&&e.staticCoordinate<s-a&&Math.min(e.max,r)-Math.max(e.min,o)>a}function sd(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 sc(e,t,a,l=0){let i=-1/0;for(let s of t)for(let t of e)s.x0<t.x1+l&&t.x0<s.x1+l&&(i=Math.max(i,t.y1+a-s.y0));return i}function sp(e,t,a,l=0){let i=-1/0;for(let s of t)for(let t of e)s.y0<t.y1+l&&t.y0<s.y1+l&&(i=Math.max(i,t.x1+a-s.x0));return i}function sh(e,t,a="characters"){let l=0x811c9dc5;for(let t=0;t<e.length;t+=1)l^=e.charCodeAt(t),l=Math.imul(l,0x1000193),"characters"===a&&(e.codePointAt(t)??0)>65535&&(t+=1);return"seed"===t?Math.abs(l)||1:(l>>>0).toString(16).padStart(8,"0")}i.gPz([ew,eA,eR,ea,Z,e2,to,tM,tJ,ag,a$,aW,lg,lO,id]);let sg={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"}:{}}))]},su={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 sf(e){return eC({...e,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}})}function sm(e,t="TB"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}function sv(e){return eC({...e,type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}})}function sy(e){return tl({...e,type:eN})}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:"cache-lookup",title:"Answer a question from the cache or the model",nodes:[{id:"host",label:"App receives the question",kind:"start"},{id:"page",label:"Page sends the question to the API",kind:"process"},{id:"auth",label:"Authenticate the user",kind:"process"},{id:"limit",label:"Apply the rate limit",kind:"process"},{id:"cache",label:"Check the answer cache",kind:"process"},{id:"hit",label:"Cache hit?",kind:"decision"},{id:"cached",label:"Return the cached answer",kind:"end"},{id:"model",label:"Call the language model",kind:"process"},{id:"store",label:"Store the answer in the cache",kind:"process"},{id:"log",label:"Log any errors",kind:"process"},{id:"answer",label:"Return the answer",kind:"end"}],edges:[{id:"ask",source:"host",target:"page"},{id:"verify",source:"page",target:"auth"},{id:"throttle",source:"auth",target:"limit"},{id:"lookup",source:"limit",target:"cache"},{id:"check",source:"cache",target:"hit"},{id:"hit-yes",source:"hit",target:"cached",label:"Yes"},{id:"hit-no",source:"hit",target:"model",label:"No"},{id:"keep",source:"model",target:"store"},{id:"trace",source:"store",target:"log"},{id:"reply",source:"log",target:"answer"}],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({...su,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({...sg,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"}}),eC({id:"expense-reimbursement",title:"Expense reimbursement",nodes:[{id:"submitted",label:"Expense is submitted",kind:"start"},{id:"receipt",label:"Receipt attached?",kind:"decision"},{id:"request",label:"Request a receipt",kind:"process"},{id:"check",label:"Run a policy check",kind:"process"},{id:"policy",label:"Within policy?",kind:"decision"},{id:"manager",label:"Manager approval",kind:"process"},{id:"payment",label:"Payment",kind:"end"},{id:"finance",label:"Finance exception review",kind:"process"},{id:"exception",label:"Exception approved?",kind:"decision"},{id:"reject",label:"Reject the expense",kind:"end"}],edges:[{id:"edge-1",source:"submitted",target:"receipt"},{id:"edge-2",source:"receipt",target:"request",label:"Missing"},{id:"edge-3",source:"request",target:"receipt"},{id:"edge-4",source:"receipt",target:"check",label:"Attached"},{id:"edge-5",source:"check",target:"policy"},{id:"edge-6",source:"policy",target:"manager",label:"Within policy"},{id:"edge-7",source:"policy",target:"finance",label:"Out of policy"},{id:"edge-8",source:"finance",target:"exception"},{id:"edge-9",source:"exception",target:"manager",label:"Approved"},{id:"edge-10",source:"exception",target:"reject",label:"Rejected"},{id:"edge-11",source:"manager",target:"payment"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"incident-response-escalation-flow",title:"Incident response escalation flow",nodes:[{id:"alert",label:"Alert is received",kind:"start"},{id:"triage",label:"Triaged",kind:"process"},{id:"real",label:"Is it a real incident?",kind:"decision"},{id:"close",label:"False alarms close",kind:"end"},{id:"declare",label:"Real incidents are declared",kind:"process"},{id:"notify",label:"Stakeholders are notified",kind:"process"},{id:"evidence",label:"Collect logs and deploy evidence",kind:"process",description:"Collect fresh evidence on each escalation loop."},{id:"cause",label:"Root cause: deploy, code, or provider?",kind:"decision"},{id:"rollback",label:"Roll back",kind:"process"},{id:"hotfix",label:"Prepare a hotfix",kind:"process"},{id:"provider",label:"Escalate to the provider",kind:"end"},{id:"stable",label:"Is the service stable?",kind:"decision"},{id:"monitor",label:"Monitoring",kind:"process"},{id:"resolved",label:"Resolved",kind:"end"},{id:"escalate",label:"Escalate",kind:"process"}],edges:[{id:"edge-1",source:"alert",target:"triage"},{id:"edge-2",source:"triage",target:"real"},{id:"edge-3",source:"real",target:"close",label:"No — false alarm"},{id:"edge-4",source:"real",target:"declare",label:"Yes — real incident"},{id:"edge-5",source:"declare",target:"notify"},{id:"edge-6",source:"notify",target:"evidence"},{id:"edge-7",source:"evidence",target:"cause"},{id:"edge-8",source:"cause",target:"rollback",label:"Deploy"},{id:"edge-9",source:"cause",target:"hotfix",label:"Code"},{id:"edge-10",source:"cause",target:"provider",label:"Provider"},{id:"edge-11",source:"rollback",target:"stable"},{id:"edge-12",source:"hotfix",target:"stable"},{id:"edge-13",source:"stable",target:"monitor",label:"Yes — stable"},{id:"edge-14",source:"monitor",target:"resolved"},{id:"edge-15",source:"stable",target:"escalate",label:"No — unstable"},{id:"edge-16",source:"escalate",target:"evidence",label:"Collect fresh evidence"}],type:"flowchart",layout:{direction:"TB",edgeRouting:"orthogonal"}}),eC({id:"incident-escalation",title:"Incident Escalation",nodes:[{id:"mon",label:"Monitoring creates alert",kind:"start"},{id:"ack",label:"Responder acknowledges alert",kind:"process"},{id:"sev",label:"Severity?",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"mit",label:"Mitigate impact",kind:"process"},{id:"comm",label:"Send customer communications",kind:"process"},{id:"res",label:"Resolve incident",kind:"end"},{id:"tri",label:"Triage queue",kind:"process",shape:"queue"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"low",label:"Monitoring",kind:"process"}],edges:[{id:"edge-1",source:"mon",target:"ack"},{id:"edge-2",source:"ack",target:"sev"},{id:"edge-3",source:"sev",target:"bridge",label:"High"},{id:"edge-4",source:"sev",target:"tri",label:"Medium"},{id:"edge-5",source:"sev",target:"low",label:"Low"},{id:"edge-6",source:"bridge",target:"mit"},{id:"edge-7",source:"mit",target:"comm"},{id:"edge-8",source:"comm",target:"res"},{id:"edge-9",source:"tri",target:"fix"},{id:"edge-10",source:"fix",target:"res",label:"Yes"},{id:"edge-11",source:"fix",target:"bridge",label:"No, escalate"},{id:"edge-12",source:"low",target:"res"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"},type:"flowchart",layout:{direction:"LR",edgeRouting:"orthogonal"}}),sf({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"}}),sf({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"}}),sf({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"}}),sf({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"}}),sf({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"}}),sm({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"}]}),sm({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"),sm({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"}]}),sm({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"}]}),sm({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"}]}),sm({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:"expense-approval-process-by-team",title:"Expense Approval Process by Team",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 the report 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:"No — rejected"},{id:"edge-4",source:"revise",target:"resubmit"},{id:"edge-5",source:"resubmit",target:"review"},{id:"edge-6",source:"approved",target:"verify",label:"Yes — approved"},{id:"edge-7",source:"verify",target:"pay"}],groups:[{id:"employee",label:"Employee"},{id:"manager",label:"Manager"},{id:"finance",label:"Finance"}]},"LR"),sm({id:"expense-approval-process",title:"Expense Approval Process",nodes:[{id:"submit",label:"Employee submits expense report",kind:"start",group:"emp"},{id:"review",label:"Manager reviews the report",kind:"process",group:"mgr"},{id:"approved",label:"Is the report approved?",kind:"decision",group:"mgr"},{id:"revise",label:"Employee revises the report",kind:"process",group:"emp"},{id:"verify",label:"Finance verifies the receipts",kind:"process",group:"fin"},{id:"pay",label:"Finance pays the employee",kind:"end",group:"fin"}],edges:[{id:"edge-1",source:"submit",target:"review"},{id:"edge-2",source:"review",target:"approved"},{id:"edge-3",source:"approved",target:"verify",label:"yes"},{id:"edge-4",source:"approved",target:"revise",label:"no"},{id:"edge-5",source:"revise",target:"review",label:"resubmit"},{id:"edge-6",source:"verify",target:"pay"}],groups:[{id:"emp",label:"Employee"},{id:"mgr",label:"Manager"},{id:"fin",label:"Finance"}]},"LR"),sm({id:"mixed-membership-row",title:"Mixed-membership row of teams",nodes:[{id:"n0",label:"Review report",kind:"start",group:"g0"},{id:"n2",label:"Review report",kind:"decision"},{id:"n3",label:"Review report",kind:"process"},{id:"n4",label:"Review report",kind:"process",group:"g2"},{id:"n5",label:"Review report",kind:"process",group:"g3"},{id:"n6",label:"Review report",kind:"process",group:"g3"},{id:"n7",label:"Review report",kind:"process"},{id:"n8",label:"Review report",kind:"process",group:"g5"},{id:"n9",label:"Review report",kind:"end",group:"g5"}],edges:[{id:"e0",source:"n0",target:"n2"},{id:"e2",source:"n2",target:"n3",label:"Yes"},{id:"e3",source:"n3",target:"n4"},{id:"e4",source:"n4",target:"n5"},{id:"e5",source:"n5",target:"n6"},{id:"e6",source:"n6",target:"n7"},{id:"e7",source:"n7",target:"n8"},{id:"e8",source:"n8",target:"n9"},{id:"e9",source:"n2",target:"n4",label:"No"}],groups:[{id:"g0",label:"Team 0"},{id:"g2",label:"Team 2"},{id:"g3",label:"Team 3"},{id:"g5",label:"Team 5"}]},"LR"),sm({id:"five-team-row",title:"Five-team row",nodes:[{id:"n0",label:"Step",kind:"start",group:"g0"},{id:"n2",label:"Step",kind:"process",group:"g0"},{id:"n3",label:"Step",kind:"process",group:"g1"},{id:"n4",label:"Step",kind:"process",group:"g1"},{id:"n5",label:"Step",kind:"process",group:"g2"},{id:"n6",label:"Step",kind:"process",group:"g2"},{id:"n7",label:"Customer submits a request for approval",kind:"decision",group:"g3"},{id:"n8",label:"Step",kind:"process",group:"g3"},{id:"n9",label:"Step",kind:"process",group:"g3"},{id:"n10",label:"Step",kind:"process",group:"g4"},{id:"n11",label:"Step",kind:"process",group:"g4"},{id:"n12",label:"Step",kind:"process",group:"g4"},{id:"n13",label:"Step",kind:"process",group:"g4"},{id:"n14",label:"Step",kind:"process"},{id:"n15",label:"Customer submits a request for approval",kind:"end"}],edges:[{id:"e0",source:"n0",target:"n2"},{id:"e2",source:"n2",target:"n3"},{id:"e3",source:"n3",target:"n4",label:"Next step"},{id:"e4",source:"n4",target:"n5"},{id:"e5",source:"n5",target:"n6"},{id:"e6",source:"n6",target:"n7"},{id:"e7",source:"n7",target:"n8",label:"Yes"},{id:"e8",source:"n8",target:"n9"},{id:"e9",source:"n9",target:"n10"},{id:"e10",source:"n10",target:"n11"},{id:"e11",source:"n11",target:"n12"},{id:"e12",source:"n12",target:"n13",label:"Next step"},{id:"e13",source:"n13",target:"n14"},{id:"e14",source:"n14",target:"n15",label:"Next step"},{id:"e15",source:"n7",target:"n9",label:"No"}],groups:[{id:"g0",label:"Team"},{id:"g1",label:"Team"},{id:"g2",label:"Legal and compliance"},{id:"g3",label:"Team"},{id:"g4",label:"Team"}]},"LR"),sv({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"}}),sv({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"}}),sv({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"}}),sv({id:"incident-escalation-flowchart",title:"Incident Escalation Flowchart",nodes:[{id:"alert",label:"Monitoring creates an alert",kind:"start"},{id:"ack",label:"Responder acknowledges the alert",kind:"process"},{id:"sev",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:"mon",label:"Monitoring",kind:"process"},{id:"resolved",label:"Resolved",kind:"end"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"sev"},{id:"edge-3",source:"sev",target:"bridge",label:"high"},{id:"edge-4",source:"sev",target:"triage",label:"medium"},{id:"edge-5",source:"sev",target:"mon",label:"low"},{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:"mon",target:"resolved"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sv({id:"incident-escalation",title:"Incident Escalation",nodes:[{id:"mon",label:"Monitoring creates alert",kind:"start"},{id:"ack",label:"Responder acknowledges alert",kind:"process"},{id:"sev",label:"Severity?",kind:"decision"},{id:"bridge",label:"Incident bridge",kind:"process"},{id:"mit",label:"Mitigate impact",kind:"process"},{id:"comm",label:"Send customer communications",kind:"process"},{id:"triage",label:"Triage queue",kind:"process",shape:"queue"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"lowmon",label:"Monitoring",kind:"process"},{id:"res",label:"Resolve incident",kind:"end"}],edges:[{id:"edge-1",source:"mon",target:"ack"},{id:"edge-2",source:"ack",target:"sev"},{id:"edge-3",source:"sev",target:"bridge",label:"High"},{id:"edge-4",source:"sev",target:"triage",label:"Medium"},{id:"edge-5",source:"sev",target:"lowmon",label:"Low"},{id:"edge-6",source:"bridge",target:"mit"},{id:"edge-7",source:"mit",target:"comm"},{id:"edge-8",source:"comm",target:"res"},{id:"edge-9",source:"triage",target:"fix"},{id:"edge-10",source:"fix",target:"res",label:"Yes"},{id:"edge-11",source:"fix",target:"bridge",label:"No, escalate"},{id:"edge-12",source:"lowmon",target:"res"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sv({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"}}),sv({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"}}),sv({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"}}),sv({id:"patient-intake-scheduling",title:"Patient Intake Scheduling",nodes:[{id:"req",label:"Patient requests appointment",kind:"start"},{id:"intake",label:"Collect intake information",kind:"process"},{id:"urgent",label:"Urgent symptoms?",kind:"decision"},{id:"triage",label:"Nurse triage",kind:"process"},{id:"same",label:"Schedule same-day appointment",kind:"end"},{id:"ins",label:"Insurance valid?",kind:"decision"},{id:"routine",label:"Schedule routine appointment",kind:"end"},{id:"self",label:"Patient accepts self-pay?",kind:"decision"},{id:"bill",label:"Refer to billing",kind:"end"}],edges:[{id:"edge-1",source:"req",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"},{id:"edge-5",source:"urgent",target:"ins",label:"No"},{id:"edge-6",source:"ins",target:"routine",label:"Yes"},{id:"edge-7",source:"ins",target:"self",label:"No"},{id:"edge-8",source:"self",target:"routine",label:"Yes"},{id:"edge-9",source:"self",target:"bill",label:"No"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sv({id:"patient-intake-scheduling",title:"Patient Intake Scheduling",nodes:[{id:"request",label:"Patient requests an appointment",kind:"start"},{id:"intake",label:"Collect intake information",kind:"process"},{id:"urgent",label:"Urgent symptoms?",kind:"decision"},{id:"triage",label:"Nurse triage",kind:"process"},{id:"same",label:"Same-day appointment",kind:"end"},{id:"insurance",label:"Insurance valid?",kind:"decision"},{id:"routine",label:"Schedule routine appointment",kind:"end"},{id:"self",label:"Patient accepts 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"},{id:"edge-5",source:"urgent",target:"insurance",label:"No"},{id:"edge-6",source:"insurance",target:"routine",label:"Yes"},{id:"edge-7",source:"insurance",target:"self",label:"No"},{id:"edge-8",source:"self",target:"routine",label:"Yes"},{id:"edge-9",source:"self",target:"billing",label:"No"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sv({id:"patient-intake-scheduling",title:"Patient Intake Scheduling",nodes:[{id:"req",label:"Patient requests appointment",kind:"start"},{id:"intake",label:"Collect intake information",kind:"process"},{id:"urgent",label:"Are there urgent symptoms?",kind:"decision"},{id:"triage",label:"Nurse triage",kind:"process"},{id:"same",label:"Schedule same-day appointment",kind:"end"},{id:"ins",label:"Is insurance valid?",kind:"decision"},{id:"routine",label:"Schedule routine appointment",kind:"end"},{id:"self",label:"Does the patient accept self-pay?",kind:"decision"},{id:"bill",label:"Refer to billing",kind:"end"}],edges:[{id:"edge-1",source:"req",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"},{id:"edge-5",source:"urgent",target:"ins",label:"No"},{id:"edge-6",source:"ins",target:"routine",label:"Yes"},{id:"edge-7",source:"ins",target:"self",label:"No"},{id:"edge-8",source:"self",target:"routine",label:"Yes"},{id:"edge-9",source:"self",target:"bill",label:"No"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sv({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"}}),sv({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"}}),sv({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"}}),sv({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"}}),sv({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"}}),sv({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"}}),sv({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",shape:"queue"},{id:"monitor",label:"Monitoring",kind:"process"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"mitigate",label:"Mitigates impact",kind:"process"},{id:"comms",label:"Sends customer communications",kind:"process"},{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"},{id:"edge-4",source:"severity",target:"triage",label:"Medium"},{id:"edge-5",source:"severity",target:"monitor",label:"Low"},{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"}}),sv({id:"incident-escalation",title:"Incident Escalation",nodes:[{id:"alert",label:"Monitoring creates an alert",kind:"start"},{id:"ack",label:"Responder acknowledges the alert",kind:"process"},{id:"sev",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:"triage",label:"Triage queue",kind:"process",shape:"queue"},{id:"fix",label:"Is there a fix?",kind:"decision"},{id:"mon",label:"Monitoring",kind:"process"},{id:"resolved",label:"Resolve the incident",kind:"end"}],edges:[{id:"edge-1",source:"alert",target:"ack"},{id:"edge-2",source:"ack",target:"sev"},{id:"edge-3",source:"sev",target:"bridge",label:"high"},{id:"edge-4",source:"sev",target:"triage",label:"medium"},{id:"edge-5",source:"sev",target:"mon",label:"low"},{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:"mon",target:"resolved"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sv({id:"expense-reimbursement",title:"Expense reimbursement",nodes:[{id:"submit",label:"An expense is submitted",kind:"start"},{id:"receipt",label:"Receipt attached?",kind:"decision"},{id:"request",label:"Request a receipt",kind:"end"},{id:"policy",label:"Run a policy check",kind:"process"},{id:"within",label:"Within policy?",kind:"decision"},{id:"manager",label:"Manager approval",kind:"process"},{id:"payment",label:"Payment",kind:"end"},{id:"finance",label:"Finance exception review",kind:"process"},{id:"exception",label:"Exception approved?",kind:"decision"},{id:"reject",label:"Reject the expense",kind:"end"}],edges:[{id:"edge-1",source:"submit",target:"receipt"},{id:"edge-2",source:"receipt",target:"request",label:"Missing"},{id:"edge-3",source:"receipt",target:"policy",label:"Attached"},{id:"edge-4",source:"policy",target:"within"},{id:"edge-5",source:"within",target:"manager",label:"Within policy"},{id:"edge-6",source:"within",target:"finance",label:"Out of policy"},{id:"edge-7",source:"finance",target:"exception"},{id:"edge-8",source:"exception",target:"manager",label:"Approved"},{id:"edge-9",source:"exception",target:"reject",label:"Rejected"},{id:"edge-10",source:"manager",target:"payment"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sy({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"}]}),sy({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"}]}),sy({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"}]}),sy({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?",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-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-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"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sy({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"}]}),sy({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",kind:"final"},{id:"refunded",label:"Refunded",kind:"final"},{id:"end",label:"Lifecycle ended",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"}]}),sy({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 sw=20*Math.PI/180;function sx(e){return 2e3/(Math.max(e.width,e.height,1)+40)}function sb(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 l=t.at(-2);if(l&&e&&.01>=Math.abs((e.x-l.x)*(a.y-e.y)-(e.y-l.y)*(a.x-e.x))&&(e.x-l.x)*(a.x-e.x)+(e.y-l.y)*(a.y-e.y)>0){t[t.length-1]=a;continue}t.push(a)}return t}function sk(e){let t=[];for(let a=0;a<e.length-1;a+=1){let l=e[a],i=e[a+1],s=.01>=Math.abs(l.y-i.y);!s&&Math.abs(l.x-i.x)>.01||t.push({horizontal:s,at:s?l.y:l.x,min:Math.min(s?l.x:l.y,s?i.x:i.y),max:Math.max(s?l.x:l.y,s?i.x:i.y),first:0===a,last:a===e.length-2})}return t}function sM(e,t){let a=sb(e.points),l=a[0],i=a.at(-1);if(!l||!i)return[];let s=new Map;for(let e=1;e<a.length-2;e+=1){let[o,r,n,d]=[a[e-1],a[e],a[e+1],a[e+2]],c={x:r.x-o.x,y:r.y-o.y},p={x:n.x-r.x,y:n.y-r.y},h={x:d.x-n.x,y:d.y-n.y},g=[c,p,h].every(e=>.01>=Math.abs(e.x)||.01>=Math.abs(e.y)),u=.01>=Math.abs(c.x*h.y-c.y*h.x)&&c.x*h.x+c.y*h.y>0,f=.01>=Math.abs(c.x*p.x+c.y*p.y),m=Math.hypot(p.x,p.y);g&&u&&f&&!(m*t>=150)&&(!s.has("end")&&Math.hypot(i.x-n.x,i.y-n.y)*t<=90&&2*m<=Math.hypot(c.x,c.y)?s.set("end",m):!s.has("start")&&Math.hypot(r.x-l.x,r.y-l.y)*t<=90&&2*m<=Math.hypot(h.x,h.y)&&s.set("start",m))}return[...s].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 sz(e,t,a,l,i){return t.some(t=>l.some(l=>{if(t.horizontal!==l.horizontal||Math.abs(t.at-l.at)*i>=24)return!1;let s=Math.min(t.max,l.max)-Math.max(t.min,l.min);return!(s*i<30)&&!((t.first&&l.first&&e.sourceId&&e.sourceId===a.sourceId||t.last&&l.last&&e.targetId&&e.targetId===a.targetId)&&s*i<=90)}))}function sC(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),l=t.at(-2);if(!a||!l)return;let i=Math.hypot(a.x-l.x,a.y-l.y),s=Math.min(25,Math.max(i,e.headRun??0)/2),o=(a.x-l.x)/i,r=(a.y-l.y)/i,n=e=>({x:a.x-s*(o*Math.cos(e)-r*Math.sin(e)),y:a.y-s*(r*Math.cos(e)+o*Math.sin(e))});return[a,n(sw),n(-sw)]}function s_(e,t,a){let l=a.x-t.x,i=a.y-t.y,s=0===l&&0===i?0:Math.max(0,Math.min(1,((e.x-t.x)*l+(e.y-t.y)*i)/(l*l+i*i)));return Math.hypot(e.x-(t.x+s*l),e.y-(t.y+s*i))}function sq(e,t,a,l){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,l)<0&&i(a,l,e)*i(a,l,t)<0}function sL(e,t){let a=e.flatMap((a,l)=>e.slice(l+1).flatMap(e=>{let l,i;return[sz(a,sk(sb(a.points)),e,sk(sb(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,(l=sC(a),i=sC(e),l&&i&&(function(e,t){let a=e=>e.map((t,a)=>[t,e[(a+1)%e.length]]),l=1/0;for(let[i,s]of a(e))for(let[e,o]of a(t)){if(sq(i,s,e,o))return 0;l=Math.min(l,s_(i,e,o),s_(s,e,o),s_(e,i,s),s_(o,i,s))}return l}(l,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=>sM(e,t)),...a.filter(e=>"near-coincident-corridor"===e.kind),...a.filter(e=>"touching-arrowheads"===e.kind)]}function sS(e,t,a){let l=1/0;for(let[i,s]of a.entries()){let o=a[(i+1)%a.length];if(sq(e,t,s,o))return 0;l=Math.min(l,s_(e,s,o),s_(t,s,o),s_(s,e,t),s_(o,e,t))}return l}function sB(e,t){let a=24/t+2,l=e.map(e=>{let t=sC(e);return{arrow:e,bounds:sA([...e.points,...t??[]]),head:t,headBounds:t?sA(t):void 0,runs:sk(sb(e.points))}});return e=>{let i=sk(sb(e.points)),s=sA(e.points,a),o=e.points.slice(1).map((t,l)=>{let i=e.points[l];return{bounds:sA([i,t],a),from:i,to:t}}),r=l.filter(({arrow:t,bounds:a})=>t.id!==e.id&&sP(s,a)),n=new Set(r.filter(({arrow:a,runs:l})=>sz(e,i,a,l,t)).map(({arrow:e})=>e.id));return{arrowheadsCrossed:new Set(r.filter(({head:e,headBounds:a})=>e&&o.some(({bounds:l,from:i,to:s})=>sP(l,a)&&(sS(i,s,e)-2)*t<8)).map(({arrow:e})=>e.id)).size,corridors:n.size,jogs:sM(e,t).length}}}function sA(e,t=0){let a=e.map(e=>e.x),l=e.map(e=>e.y);return{maxX:Math.max(...a)+t,maxY:Math.max(...l)+t,minX:Math.min(...a)-t,minY:Math.min(...l)-t}}function sP(e,t){return e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY}let sV=Object.freeze({clearance:4,fontSize:14,height:21}),sH=Object.freeze({gap:6,inset:10,size:18}),sI=Object.freeze({height:36,labelInset:12});function s$(e){return e?e.size+sH.gap:0}function sF(e){let{icon:t}=e;if(t)return"frame"===e.type?{x:e.x+sH.inset,y:e.y+sH.inset,width:t.size,height:t.size}:{x:e.x+sI.labelInset,y:e.y+(sI.height-t.size)/2,width:t.size,height:t.size}}let sO=/[@%MW]/u,sE=/[A-Z0-9mw#$&_~]/u,sU=new Intl.Segmenter(void 0,{granularity:"grapheme"});function sX(e){let{fontSize:t}=sV,a=0;for(let{segment:l}of sU.segment(e))a+=sO.test(l)?1.02*t:sE.test(l)?.86*t:/^[\x20-\x7e]$/u.test(l)?iC(l,t):Math.max(.86*t,iC(l,t));return Math.ceil(a)}function sT(e){let{clearance:t,height:a}=sV,l=sX(e.name??"Frame");return{x:e.x-t,y:e.y-a-t,width:l+2*t,height:a+t-1}}function sR(e,t,a,l){return tB({id:e,title:t,type:"er",entities:a.map(([e,t])=>({id:e,fields:t.map(tP)})),relationships:l.map(([e,t,a,l,i],s)=>({id:`r${s+1}`,from:e,to:t,fromCardinality:a,toCardinality:l,...i?{label:i}:{}}))})}sR("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"]]),sR("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"]]),sR("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"]]),sR("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 sY=e=>t9(ad({type:"class",...e}));function sD(e,t="LR"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}sY({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}))}),sY({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"}]}),sY({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"}]}),sY({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"}]}),sY({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"}]}),sY({id:"weather-observer",title:"Weather station observer",classes:[{id:"Subject",kind:"interface",methods:["+ attach(o: Observer): void","+ detach(o: Observer): void","+ notifyObservers(): void"]},{id:"Observer",kind:"interface",methods:["+ update(subject: Subject): void"]},{id:"WeatherStation",attributes:["- temperature: double","- humidity: double","- observers: List<Observer>"],methods:["+ attach(o: Observer): void","+ detach(o: Observer): void","+ notifyObservers(): void","+ setMeasurements(t: double, h: double): void","+ getTemperature(): double"]},{id:"PhoneDisplay",attributes:["- lastReading: double"],methods:["+ update(subject: Subject): void"]},{id:"WindowDisplay",methods:["+ update(subject: Subject): void"]}],relationships:[{id:"station-subject",kind:"realization",from:"WeatherStation",to:"Subject"},{id:"phone-observer",kind:"realization",from:"PhoneDisplay",to:"Observer"},{id:"window-observer",kind:"realization",from:"WindowDisplay",to:"Observer"},{id:"observers",kind:"association",from:"WeatherStation",to:"Observer",toMultiplicity:"0..*",toRole:"observers",navigable:!0},{id:"attaches",kind:"dependency",from:"Subject",to:"Observer",label:"attach / detach"},{id:"updates",kind:"dependency",from:"Observer",to:"Subject",label:"update parameter"},{id:"reads",kind:"dependency",from:"PhoneDisplay",to:"WeatherStation",label:"casts to; getTemperature()"}]}),sY({id:"library-system",title:"Library system",classes:[{id:"Library",attributes:["- name: String","- branches: List<Branch>","- catalog: Catalog"],methods:["+ search(query: String): List<Item>"]},{id:"Branch",attributes:["- address: String"]},{id:"Catalog",attributes:["- items: List<Item>"],methods:["+ add(item: Item): void","+ find(isbn: String): Book"]},{id:"Item",kind:"abstract",attributes:["# id: UUID","# title: String"],methods:["+ loanPeriod(): int {abstract}"]},{id:"Book",attributes:["- isbn: String","- pages: int","- authors: List<Author>"],methods:["+ loanPeriod(): int"]},{id:"DVD",attributes:["- minutes: int"],methods:["+ loanPeriod(): int"]},{id:"Magazine",attributes:["- issue: int"],methods:["+ loanPeriod(): int"]},{id:"Author",attributes:["- name: String","- books: List<Book>"]},{id:"Member",attributes:["- memberId: String","- name: String","- loans: List<Loan>","- reservations: List<Reservation>"],methods:["+ borrow(item: Item): Loan","+ reserve(item: Item): Reservation"]},{id:"StudentMember",attributes:["- school: String"]},{id:"StaffMember",attributes:["- department: String"]},{id:"Loan",attributes:["- due: Date","- returned: Date","- item: Item","- fine: Fine"],methods:["+ isOverdue(): boolean"]},{id:"Reservation",attributes:["- placed: Date","- item: Item"]},{id:"Fine",attributes:["- amount: Money"],methods:["+ pay(): void"]},{id:"Librarian",attributes:["- staffId: String","- branch: Branch"],methods:["+ checkOut(loan: Loan): void"]}],relationships:[{id:"relationship-1",kind:"composition",from:"Library",to:"Branch",fromMultiplicity:"1",toMultiplicity:"1..*",toRole:"branches"},{id:"relationship-2",kind:"composition",from:"Library",to:"Catalog",fromMultiplicity:"1",toMultiplicity:"1",toRole:"catalog"},{id:"relationship-3",kind:"composition",from:"Loan",to:"Fine",fromMultiplicity:"1",toRole:"fine"},{id:"relationship-4",kind:"aggregation",from:"Catalog",to:"Item",toMultiplicity:"0..*",toRole:"items"},{id:"relationship-5",kind:"inheritance",from:"Book",to:"Item"},{id:"relationship-6",kind:"inheritance",from:"DVD",to:"Item"},{id:"relationship-7",kind:"inheritance",from:"Magazine",to:"Item"},{id:"relationship-8",kind:"association",from:"Book",to:"Author",fromMultiplicity:"0..*",toMultiplicity:"1..*",fromRole:"books",toRole:"authors"},{id:"relationship-9",kind:"inheritance",from:"StudentMember",to:"Member"},{id:"relationship-10",kind:"inheritance",from:"StaffMember",to:"Member"},{id:"relationship-11",kind:"association",from:"Member",to:"Loan",toMultiplicity:"0..*",toRole:"loans",navigable:!0},{id:"relationship-12",kind:"association",from:"Member",to:"Reservation",toMultiplicity:"0..*",toRole:"reservations",navigable:!0},{id:"relationship-13",kind:"association",from:"Loan",to:"Item",toRole:"item",navigable:!0},{id:"relationship-14",kind:"association",from:"Reservation",to:"Item",toRole:"item",navigable:!0},{id:"relationship-15",kind:"association",from:"Librarian",to:"Branch",toRole:"branch",navigable:!0},{id:"relationship-16",kind:"dependency",from:"Librarian",to:"Loan"},{id:"relationship-17",kind:"dependency",from:"Library",to:"Item"},{id:"relationship-18",kind:"dependency",from:"Catalog",to:"Book"},{id:"relationship-19",kind:"dependency",from:"Member",to:"Item"}]}),sD({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"}]}),sD({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"),sD({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"}]}),sD({id:"incident-response",title:"Incident Response",nodes:[{id:"alert",label:"Alert fires",kind:"start",lane:"oncall"},{id:"triage",label:"Triage alert",kind:"process",lane:"oncall"},{id:"page",label:"Page SRE",kind:"process",lane:"oncall"},{id:"inv",label:"Investigate incident",kind:"process",lane:"sre"},{id:"mit",label:"Apply mitigation",kind:"process",lane:"sre"},{id:"status",label:"Post status update",kind:"process",lane:"comms"},{id:"res",label:"Incident resolved?",kind:"decision",lane:"oncall"},{id:"pub",label:"Publish resolution",kind:"end",lane:"comms"}],edges:[{id:"edge-1",source:"alert",target:"triage"},{id:"edge-2",source:"triage",target:"page"},{id:"edge-3",source:"page",target:"inv"},{id:"edge-4",source:"inv",target:"mit"},{id:"edge-5",source:"mit",target:"status"},{id:"edge-6",source:"status",target:"res"},{id:"edge-7",source:"res",target:"inv",label:"No"},{id:"edge-8",source:"res",target:"pub",label:"Yes"}],lanes:[{id:"oncall",label:"On-call"},{id:"sre",label:"SRE"},{id:"comms",label:"Comms"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),sD({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"}]}),sD({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 sG=["Customer","Support","Billing","Engineering","QA","Release"],sZ=["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"],sj=Array.from({length:30}).reduce((e,t,a)=>{let l=e.at(-1)??0,i=[0,1,1,0,2,-1,1,0,-1,-2][a%10],s=l+i;return[...e,s<0||s>5?l-i:s]},[]);U({id:"six-lanes-thirty-steps",title:"Thirty steps across six lanes",type:"flowchart",lanes:sG.map((e,t)=>({id:`l${t}`,label:e})),nodes:Array.from({length:30},(e,t)=>({id:`s${t}`,label:`${sZ[t%sZ.length]} ${t}`,kind:0===t?"start":29===t?"end":t%7==3?"decision":"process",lane:`l${sj[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:sG.slice(0,4).map((e,t)=>({id:`l${t}`,label:e})),nodes:Array.from({length:14},(e,t)=>({id:`n${t}`,label:`${sZ[t%sZ.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 sN=["Ada","Grace","Alan","Barbara","Edsger","Frances","Donald","Hedy","John","Katherine","Leslie","Mary","Niklaus","Radia","Tim","Shafi","Vint","Lynn","Ken","Sophie"],sW=["Lovelace","Hopper","Turing","Liskov","Dijkstra","Allen","Knuth","Lamarr","Backus","Johnson","Lamport","Keller","Wirth","Perlman","Berners-Lee","Goldwasser","Cerf","Conway","Thompson","Wilson"],sJ=["Engineering","Product","Sales","Marketing","Operations","Finance"],sK=["Chief Executive Officer","Vice President","Director","Engineering Manager","Team Lead","Senior Engineer","Engineer"];function sQ(e){return`${sN[e%sN.length]} ${sW[(7*e+Math.floor(e/sN.length))%sW.length]}`}function s1(e,t,a,l={}){let i=[{id:"p0",name:sQ(0),title:sK[0],department:"Executive"}],s=[{id:"p0",department:"Executive"}];for(let[e,t]of a.entries()){let a=[];s.forEach((l,s)=>{let o=t[s%t.length];for(let t=0;t<o;t+=1){let s=i.length,o=0===e?sJ[t%sJ.length]:l.department,r={id:`p${s}`,department:o};i.push({id:r.id,name:sQ(s),title:sK[Math.min(e+1,sK.length-1)],department:o,manager:l.id}),a.push(r)}}),s=a}return ab(aL({id:e,title:t,type:ac,people:i,...l}))}function s0(e,t="LR"){return eC({...e,type:"flowchart",layout:{direction:t,edgeRouting:"orthogonal"}})}s1("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]]),s1("twenty-reports","Twenty reports",[[1],[20]]),s1("six-levels","Six levels deep",[[2],[2,1],[1,2],[2,1],[1,2]]),s1("department","Department of twenty-five",[[3],[8,6,7]]),s1("wide-top","Twelve vice presidents",[[12],[2,3,1]]),ab(aL({id:"three-boards",title:"Three boards",type:ac,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"}]})),s1("regions","Departments as regions",[[4],[3,2,1,4],[0,2,1]],{groupByDepartment:!0}),s0({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"}]}),s0({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"),s0({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"}]}),s0({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"),s0({id:"hybrid-cloud-labeled",title:"Hybrid setup: on-prem data center to AWS",groups:[{id:"dc",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",parent:"dc",kind:"zone"},{id:"aws",label:"AWS cloud",kind:"cloud"},{id:"reg",label:"eu-west-1",parent:"aws",kind:"region"},{id:"vpc",label:"Production VPC",parent:"reg",kind:"vpc"},{id:"priv",label:"Private subnet",parent:"vpc",kind:"subnet"}],nodes:[{id:"staff",label:"Office staff enter orders",kind:"start",group:"corp"},{id:"erp",label:"Legacy ERP",kind:"process",group:"corp"},{id:"ora",label:"Oracle database",kind:"end",group:"dc",shape:"database"},{id:"vpn",label:"Site-to-site VPN gateway",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"priv"},{id:"q",label:"Order queue",kind:"process",group:"reg",shape:"queue"},{id:"sync",label:"Sync function",kind:"process",group:"reg"},{id:"tbl",label:"Orders table",kind:"end",group:"reg",shape:"database"},{id:"arc",label:"Invoice archive (PDF)",kind:"end",group:"reg",shape:"document"}],edges:[{id:"edge-1",source:"staff",target:"erp"},{id:"edge-2",source:"erp",target:"ora",label:"stores records"},{id:"edge-3",source:"erp",target:"vpn",label:"sends orders"},{id:"edge-4",source:"vpn",target:"api"},{id:"edge-5",source:"api",target:"q"},{id:"edge-6",source:"q",target:"sync"},{id:"edge-7",source:"sync",target:"tbl",label:"writes orders"},{id:"edge-8",source:"sync",target:"arc",label:"saves invoice PDF"}]}),s0({id:"hybrid-cloud-described",title:"Hybrid order processing — on-premises to AWS",groups:[{id:"dc",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",parent:"dc"},{id:"aws",label:"AWS cloud",kind:"cloud"},{id:"region",label:"eu-west-1",parent:"aws",kind:"region"},{id:"vpc",label:"Production VPC",parent:"region",kind:"vpc"},{id:"private",label:"Private subnet",parent:"vpc",kind:"subnet"}],nodes:[{id:"staff",label:"Office staff",kind:"start",description:"Enter orders",group:"corp"},{id:"erp",label:"Legacy ERP",kind:"process",group:"corp"},{id:"oracle",label:"Oracle database",kind:"end",description:"Stores records",icon:{slug:"oracle"},group:"dc",shape:"database"},{id:"vpn",label:"Site-to-site VPN gateway",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"private"},{id:"queue",label:"Order queue",kind:"process",group:"region",shape:"queue"},{id:"sync",label:"Sync function",kind:"process",group:"region"},{id:"table",label:"Orders table",kind:"end",group:"region",shape:"database"},{id:"archive",label:"Invoice archive",kind:"end",description:"Each invoice saved as a PDF document",group:"region",shape:"storage"}],edges:[{id:"edge-1",source:"staff",target:"erp",label:"Enter orders"},{id:"edge-2",source:"erp",target:"oracle",label:"Stores records"},{id:"edge-3",source:"erp",target:"vpn",label:"Sends orders"},{id:"edge-4",source:"vpn",target:"api",label:"Passes orders"},{id:"edge-5",source:"api",target:"queue",label:"Puts each order"},{id:"edge-6",source:"queue",target:"sync",label:"Takes orders"},{id:"edge-7",source:"sync",target:"table",label:"Writes orders"},{id:"edge-8",source:"sync",target:"archive",label:"Saves invoice PDFs"}]}),s0({id:"hybrid-cloud-bypass",title:"Hybrid setup",groups:[{id:"dc",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",parent:"dc",kind:"zone"},{id:"aws",label:"AWS cloud",kind:"cloud"},{id:"region",label:"eu-west-1",parent:"aws",kind:"region"},{id:"vpc",label:"Production VPC",parent:"region",kind:"vpc"},{id:"private",label:"Private subnet",parent:"vpc",kind:"subnet"}],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",icon:{slug:"oracle"},group:"dc",shape:"database"},{id:"vpn",label:"Site-to-site VPN gateway",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"private"},{id:"queue",label:"Order queue",kind:"process",group:"region",shape:"queue"},{id:"sync",label:"Sync function",kind:"process",group:"region"},{id:"orders",label:"Orders table",kind:"end",group:"region",shape:"database"},{id:"archive",label:"Invoice archive",kind:"end",group:"region",shape:"document"}],edges:[{id:"edge-1",source:"staff",target:"erp",label:"enters orders"},{id:"edge-2",source:"erp",target:"oracle",label:"stores records"},{id:"edge-3",source:"erp",target:"vpn",label:"sends orders"},{id:"edge-4",source:"vpn",target:"api"},{id:"edge-5",source:"api",target:"queue",label:"puts orders"},{id:"edge-6",source:"queue",target:"sync"},{id:"edge-7",source:"sync",target:"orders",label:"writes orders"},{id:"edge-8",source:"sync",target:"archive",label:"saves invoice PDF"}]}),s0({id:"hybrid-cloud-bypass-archive",title:"Hybrid on-prem to AWS order flow",groups:[{id:"dc",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",parent:"dc",kind:"zone"},{id:"aws",label:"AWS cloud",kind:"cloud"},{id:"reg",label:"eu-west-1",parent:"aws",kind:"region"},{id:"vpc",label:"Production VPC",parent:"reg",kind:"vpc"},{id:"priv",label:"Private subnet",parent:"vpc",kind:"subnet"}],nodes:[{id:"staff",label:"Office staff enter orders",kind:"start",group:"corp"},{id:"erp",label:"Legacy ERP",kind:"process",group:"corp"},{id:"ora",label:"Oracle database",kind:"end",icon:{slug:"oracle"},group:"dc",shape:"database"},{id:"vpn",label:"Site-to-site VPN gateway",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"priv"},{id:"q",label:"Order queue",kind:"process",group:"reg",shape:"queue"},{id:"sync",label:"Sync function",kind:"process",group:"reg"},{id:"tbl",label:"Orders table",kind:"end",group:"reg",shape:"database"},{id:"arch",label:"Invoice archive",kind:"end",description:"Invoices saved as PDF",group:"reg",shape:"document"}],edges:[{id:"edge-1",source:"staff",target:"erp"},{id:"edge-2",source:"erp",target:"ora",label:"stores records"},{id:"edge-3",source:"erp",target:"vpn",label:"sends orders"},{id:"edge-4",source:"vpn",target:"api"},{id:"edge-5",source:"api",target:"q",label:"puts each order"},{id:"edge-6",source:"q",target:"sync"},{id:"edge-7",source:"sync",target:"tbl",label:"writes orders"},{id:"edge-8",source:"sync",target:"arch",label:"saves invoice PDF"}]}),s0({id:"aws-three-tier-described",title:"AWS three-tier app",groups:[{id:"region",label:"us-east-1",kind:"region"},{id:"vpc",label:"VPC",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",description:"Send requests"},{id:"alb",label:"Application Load Balancer",kind:"process",group:"public"},{id:"web",label:"Web service",kind:"process",description:"ECS Fargate",group:"private"},{id:"api",label:"API service",kind:"process",description:"ECS Fargate, two tasks behind the load balancer",group:"private"},{id:"rds",label:"RDS PostgreSQL",kind:"end",shape:"database",icon:{slug:"postgresql"},description:"Multi-AZ primary",group:"data"},{id:"s3",label:"S3 bucket",kind:"end",shape:"storage",group:"region"}],edges:[{id:"e1",source:"users",target:"alb",label:"requests"},{id:"e2",source:"alb",target:"web",label:"routes"},{id:"e3",source:"alb",target:"api",label:"routes"},{id:"e4",source:"web",target:"rds",label:"queries"},{id:"e5",source:"api",target:"rds",label:"queries"},{id:"e6",source:"api",target:"s3",label:"stores uploads"}]}),s0({id:"aws-architecture",title:"AWS Architecture",groups:[{id:"region",label:"us-east-1",kind:"region"},{id:"vpc",label:"VPC",parent:"region",kind:"vpc"},{id:"pub",label:"Public subnet",parent:"vpc",kind:"subnet"},{id:"priv",label:"Private subnet",parent:"vpc",kind:"subnet"},{id:"dbs",label:"Database subnet",parent:"vpc",kind:"subnet"}],nodes:[{id:"users",label:"Users",kind:"start"},{id:"alb",label:"Application Load Balancer",kind:"process",group:"pub"},{id:"web",label:"Web service",kind:"process",group:"priv"},{id:"api",label:"API service",kind:"process",group:"priv"},{id:"rds",label:"RDS PostgreSQL",kind:"end",icon:{slug:"postgresql"},group:"dbs",shape:"database"},{id:"s3",label:"S3 bucket",kind:"end",group:"region",shape:"storage"}],edges:[{id:"edge-1",source:"users",target:"alb",label:"requests"},{id:"edge-2",source:"alb",target:"web"},{id:"edge-3",source:"alb",target:"api"},{id:"edge-4",source:"web",target:"rds",label:"queries"},{id:"edge-5",source:"api",target:"rds",label:"queries"},{id:"edge-6",source:"api",target:"s3",label:"stores uploads"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),s0({id:"aws-architecture",title:"AWS Architecture",groups:[{id:"region",label:"us-east-1",kind:"region"},{id:"vpc",label:"VPC",parent:"region",kind:"vpc"},{id:"pub",label:"Public subnet",parent:"vpc",kind:"subnet"},{id:"priv",label:"Private subnet",parent:"vpc",kind:"subnet"},{id:"dbs",label:"Database subnet",parent:"vpc",kind:"subnet"}],nodes:[{id:"users",label:"Users",kind:"start"},{id:"alb",label:"Application Load Balancer",kind:"process",group:"pub"},{id:"web",label:"ECS web service",kind:"process",group:"priv"},{id:"api",label:"ECS API service",kind:"process",group:"priv"},{id:"rds",label:"RDS PostgreSQL",kind:"end",icon:{slug:"postgresql"},group:"dbs",shape:"database"},{id:"s3",label:"S3 bucket",kind:"end",group:"region",shape:"storage"}],edges:[{id:"edge-1",source:"users",target:"alb",label:"requests"},{id:"edge-2",source:"alb",target:"web"},{id:"edge-3",source:"alb",target:"api"},{id:"edge-4",source:"web",target:"rds",label:"queries"},{id:"edge-5",source:"api",target:"rds",label:"queries"},{id:"edge-6",source:"api",target:"s3",label:"stores uploads"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),s0({id:"hybrid-order-flow",title:"Hybrid Order Flow",groups:[{id:"dc",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",parent:"dc",kind:"zone"},{id:"aws",label:"AWS cloud",kind:"cloud"},{id:"reg",label:"eu-west-1",parent:"aws",kind:"region"},{id:"vpc",label:"Production VPC",parent:"reg",kind:"vpc"},{id:"priv",label:"Private subnet",parent:"vpc",kind:"subnet"}],nodes:[{id:"staff",label:"Office staff enter orders",kind:"start",group:"corp"},{id:"erp",label:"Legacy ERP",kind:"process",group:"corp"},{id:"ora",label:"Oracle database",kind:"end",icon:{slug:"oracle"},group:"dc",shape:"database"},{id:"vpn",label:"Site-to-site VPN gateway",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"priv"},{id:"q",label:"Order queue",kind:"process",group:"reg",shape:"queue"},{id:"sync",label:"Sync function",kind:"process",group:"reg"},{id:"tbl",label:"Orders table",kind:"end",group:"reg",shape:"database"},{id:"arch",label:"Invoice archive (PDF)",kind:"end",group:"reg",shape:"document"}],edges:[{id:"edge-1",source:"staff",target:"erp"},{id:"edge-2",source:"erp",target:"ora",label:"stores records"},{id:"edge-3",source:"erp",target:"vpn",label:"sends orders"},{id:"edge-4",source:"vpn",target:"api"},{id:"edge-5",source:"api",target:"q"},{id:"edge-6",source:"q",target:"sync"},{id:"edge-7",source:"sync",target:"tbl",label:"writes orders"},{id:"edge-8",source:"sync",target:"arch",label:"saves invoice"}],style:{accentColor:"#8f707f",backgroundColor:"#fffdf8"}}),s0({id:"hybrid-order-processing",title:"Hybrid order processing",nodes:[{id:"staff",label:"Office staff",kind:"start",description:"Enter orders",group:"corp"},{id:"erp",label:"Legacy ERP",kind:"process",group:"corp"},{id:"oracle",label:"Oracle database",kind:"end",icon:{slug:"oracle"},group:"dc",shape:"database"},{id:"vpn",label:"Site-to-site VPN gateway",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"private"},{id:"queue",label:"Order queue",kind:"process",group:"region",shape:"queue"},{id:"sync",label:"Sync function",kind:"process",group:"region"},{id:"table",label:"Orders table",kind:"end",group:"region",shape:"database"},{id:"pdf",label:"Invoice PDF document",kind:"process",group:"region",shape:"document"},{id:"archive",label:"Invoice archive",kind:"end",group:"region",shape:"storage"}],edges:[{id:"edge-1",source:"staff",target:"erp",label:"Enter orders"},{id:"edge-2",source:"erp",target:"oracle",label:"Store records"},{id:"edge-3",source:"erp",target:"vpn",label:"Send orders"},{id:"edge-4",source:"vpn",target:"api",label:"Pass orders"},{id:"edge-5",source:"api",target:"queue",label:"Put each order"},{id:"edge-6",source:"queue",target:"sync",label:"Take orders"},{id:"edge-7",source:"sync",target:"table",label:"Write orders"},{id:"edge-8",source:"sync",target:"pdf",label:"Save each invoice as PDF"},{id:"edge-9",source:"pdf",target:"archive",label:"Store"}],groups:[{id:"dc",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",parent:"dc"},{id:"aws",label:"AWS cloud",kind:"cloud"},{id:"region",label:"eu-west-1",parent:"aws",kind:"region"},{id:"vpc",label:"Production VPC",parent:"region",kind:"vpc"},{id:"private",label:"Private subnet",parent:"vpc",kind:"subnet"}]}),s0({id:"hybrid-order-processing-on-premises-and-aws",title:"Hybrid order processing — on-premises and AWS",nodes:[{id:"staff",label:"Office staff",kind:"start",description:"Enter orders",group:"corp"},{id:"erp",label:"Legacy ERP",kind:"process",group:"corp"},{id:"oracle",label:"Oracle database",kind:"end",icon:{slug:"oracle"},group:"dc",shape:"database"},{id:"vpn",label:"Site-to-site VPN gateway",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"private"},{id:"queue",label:"Order queue",kind:"process",group:"region",shape:"queue"},{id:"sync",label:"Sync function",kind:"process",group:"region"},{id:"table",label:"Orders table",kind:"end",group:"region",shape:"database"},{id:"archive",label:"Invoice archive",kind:"end",description:"Each invoice saved as a PDF document",group:"region",shape:"storage"}],edges:[{id:"edge-1",source:"staff",target:"erp",label:"Enter orders"},{id:"edge-2",source:"erp",target:"oracle",label:"Store records"},{id:"edge-3",source:"erp",target:"vpn",label:"Send orders"},{id:"edge-4",source:"vpn",target:"api",label:"Pass orders"},{id:"edge-5",source:"api",target:"queue",label:"Put each order"},{id:"edge-6",source:"queue",target:"sync",label:"Take orders"},{id:"edge-7",source:"sync",target:"table",label:"Write orders"},{id:"edge-8",source:"sync",target:"archive",label:"Save invoices as PDF documents"}],groups:[{id:"dc",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",parent:"dc",kind:"zone"},{id:"aws",label:"AWS cloud",kind:"cloud"},{id:"region",label:"eu-west-1",parent:"aws",kind:"region"},{id:"vpc",label:"Production VPC",parent:"region",kind:"vpc"},{id:"private",label:"Private subnet",parent:"vpc",kind:"subnet"}]}),s0({id:"hybrid-order-processing-aws-eu-west-1",title:"Hybrid order processing — AWS eu-west-1",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",icon:{slug:"oracle"},group:"dc",shape:"database"},{id:"vpn",label:"Site-to-site VPN gateway",kind:"process",group:"vpc"},{id:"api",label:"Order API",kind:"process",group:"private"},{id:"queue",label:"Order queue",kind:"process",group:"region",shape:"queue"},{id:"sync",label:"Sync function",kind:"process",group:"region"},{id:"table",label:"Orders table",kind:"end",group:"region",shape:"database"},{id:"archive",label:"Invoice archive",kind:"end",description:"Invoices saved as PDFs",group:"region",shape:"storage"}],edges:[{id:"edge-1",source:"staff",target:"erp",label:"Enter orders"},{id:"edge-2",source:"erp",target:"oracle",label:"Store records"},{id:"edge-3",source:"erp",target:"vpn"},{id:"edge-4",source:"vpn",target:"api"},{id:"edge-5",source:"api",target:"queue"},{id:"edge-6",source:"queue",target:"sync"},{id:"edge-7",source:"sync",target:"table"},{id:"edge-8",source:"sync",target:"archive",label:"Save each invoice as a PDF"}],groups:[{id:"dc",label:"On-prem data center",kind:"datacenter"},{id:"corp",label:"Corporate network",parent:"dc"},{id:"aws",label:"AWS cloud",kind:"cloud"},{id:"region",label:"eu-west-1",parent:"aws",kind:"region"},{id:"vpc",label:"Production VPC",parent:"region",kind:"vpc"},{id:"private",label:"Private subnet",parent:"vpc",kind:"subnet"}]}),s0({id:"web-request-across-three-network-zones",title:"Web request across three network zones",nodes:[{id:"browser",label:"Browser sends a request",kind:"start",group:"public"},{id:"cache",label:"CDN checks its cache",kind:"process",group:"dmz"},{id:"hit",label:"Cache hit?",kind:"decision",group:"dmz"},{id:"cached",label:"Return cached page",kind:"end",group:"dmz"},{id:"waf",label:"WAF",kind:"process",group:"dmz"},{id:"filter",label:"Filter the request",kind:"process",group:"dmz"},{id:"api",label:"API server handles the request",kind:"process",group:"private"},{id:"db",label:"Query the database",kind:"process",group:"private",shape:"database"},{id:"response",label:"Return response",kind:"end",group:"private"}],edges:[{id:"edge-1",source:"browser",target:"cache"},{id:"edge-2",source:"cache",target:"hit"},{id:"edge-3",source:"hit",target:"cached",label:"Hit"},{id:"edge-4",source:"hit",target:"waf",label:"Miss"},{id:"edge-5",source:"waf",target:"filter"},{id:"edge-6",source:"filter",target:"api"},{id:"edge-7",source:"api",target:"db"},{id:"edge-8",source:"db",target:"response"}],groups:[{id:"public",label:"Public internet"},{id:"dmz",label:"DMZ"},{id:"private",label:"Private subnet",kind:"subnet"}]}),s0({id:"web-request-across-network-zones",title:"Web request across network zones",nodes:[{id:"browser",label:"Browser",kind:"start",description:"Sends a request",group:"pub"},{id:"cache",label:"Cache hit?",kind:"decision",group:"dmz"},{id:"cached",label:"Return cached page",kind:"process",group:"dmz"},{id:"waf",label:"WAF filters request",kind:"process",group:"dmz"},{id:"api",label:"API server handles request",kind:"process",group:"priv"},{id:"db",label:"Query database",kind:"process",group:"priv",shape:"database"},{id:"resp",label:"Response returned",kind:"end"}],edges:[{id:"edge-1",source:"browser",target:"cache",label:"request"},{id:"edge-2",source:"cache",target:"cached",label:"yes"},{id:"edge-3",source:"cache",target:"waf",label:"no"},{id:"edge-4",source:"waf",target:"api"},{id:"edge-5",source:"api",target:"db"},{id:"edge-6",source:"db",target:"resp"},{id:"edge-7",source:"cached",target:"resp"}],groups:[{id:"pub",label:"Public internet",kind:"zone"},{id:"dmz",label:"DMZ",kind:"zone"},{id:"priv",label:"Private subnet",kind:"subnet"}]}),s0({id:"web-request-across-network-zones",title:"Web Request Across Network Zones",nodes:[{id:"browser",label:"Browser sends request",kind:"start",group:"pub"},{id:"cache",label:"CDN checks its cache",kind:"process",group:"dmz"},{id:"hit",label:"Cache hit?",kind:"decision",group:"dmz"},{id:"waf",label:"WAF filters request",kind:"process",group:"dmz"},{id:"api",label:"API server handles request",kind:"process",group:"priv"},{id:"db",label:"Query database",kind:"process",group:"priv",shape:"database"},{id:"resp",label:"Response returned",kind:"end"}],edges:[{id:"edge-1",source:"browser",target:"cache"},{id:"edge-2",source:"cache",target:"hit"},{id:"edge-3",source:"hit",target:"resp",label:"yes: cached page"},{id:"edge-4",source:"hit",target:"waf",label:"no"},{id:"edge-5",source:"waf",target:"api"},{id:"edge-6",source:"api",target:"db"},{id:"edge-7",source:"db",target:"resp"}],groups:[{id:"pub",label:"Public Internet",kind:"zone"},{id:"dmz",label:"DMZ",kind:"zone"},{id:"priv",label:"Private Subnet",kind:"subnet"}]}),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],l)=>({id:`s${l}`,label:e,kind:0===l?"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"}}),aY({id:"ios-android",title:"iOS vs Android",type:"venn",sets:[{id:"ios",label:"iOS"},{id:"android",label:"Android"}],regions:[{sets:["ios"],items:["iMessage","AirDrop","Face ID","Apple Pay"]},{sets:["android"],items:["Custom launchers","Sideloading apps","Expandable storage","Google Assistant"]},{sets:["ios","android"],label:"Both",items:["Push notifications","Biometric unlock","App stores","Dark mode","Widgets"]}]}),aY({id:"heavy-center",title:"Features in every plan",type:"venn",sets:[{id:"starter",label:"Starter"},{id:"team",label:"Team"},{id:"business",label:"Business"}],regions:[{sets:["starter","team","business"],label:"Every plan",items:["Single sign-on","Audit logs","Role-based access","API access","Webhooks","Custom domains","Usage analytics","Priority support","Data export","Two-factor auth","Team workspaces","Version history"]}]}),aY({id:"heavy-lens",title:"Python and JavaScript",type:"venn",sets:[{id:"python",label:"Python"},{id:"javascript",label:"JavaScript"}],regions:[{sets:["python"],items:["NumPy"]},{sets:["javascript"],items:["DOM"]},{sets:["python","javascript"],items:["Dynamic typing","First-class functions","Garbage collection","Package managers","REPL","Closures","Async/await","Generators","Decorator-like syntax","Huge ecosystems","Interpreted","Popular in teaching"]}]}),aY({id:"heavy-singles",title:"Plan tiers",type:"venn",sets:[{id:"basic",label:"Basic",color:"violet"},{id:"pro",label:"Pro",color:"pink"},{id:"enterprise",label:"Enterprise",color:"#222222"}],regions:[{sets:["basic"],items:["Community forum access for every member of the workspace","Basic templates","Email support within two business days","Five projects"]},{sets:["pro"],items:["Unlimited projects","Advanced analytics dashboards","Custom branding on shared pages","Priority email support"]},{sets:["enterprise"],items:["Dedicated success manager","SAML single sign-on","Custom contracts and invoicing","99.99% uptime SLA","Audit log export"]},{sets:["basic","pro","enterprise"],items:["Mobile apps"]}]}),aY({id:"counts",title:"On-call coverage",type:"venn",sets:[{id:"support",label:"Customer success and support operations"},{id:"platform",label:"Platform infrastructure engineering"}],regions:[{sets:["support"],count:1204},{sets:["platform"],count:87},{sets:["support","platform"],label:"Shared on-call rotation",count:12}]}),aY({id:"empty",title:"Pets",type:"venn",sets:[{id:"cats",label:"Cats"},{id:"dogs",label:"Dogs"},{id:"birds",label:"Birds"}]}),aY({id:"cjk",title:"East Asian scripts",type:"venn",sets:[{id:"ja",label:"日本語"},{id:"zh",label:"中文"},{id:"ko",label:"한국어"}],regions:[{sets:["ja"],items:["ひらがな","カタカナ"]},{sets:["zh"],items:["简体字"]},{sets:["ko"],items:["한글"]},{sets:["ja","zh"],items:["漢字"]},{sets:["ja","ko"],items:["敬語 honorifics"]},{sets:["zh","ko"],items:["声调"]},{sets:["ja","zh","ko"],items:["東アジア"]}]});let s2=["Compares","Searches","Opens","Reads","Asks about","Checks","Updates","Confirms","Shares","Returns"],s3=["the pricing page","delivery options","a confirmation email","the mobile app","account settings","the help center","a discount code","the order status"],s5=[3,4,2,5,1,3,4,2];function s4(e,t,a){return a3({id:e,title:`${t*a}-step journey`,type:aG,stages:Array.from({length:t},(e,t)=>({name:`Stage ${t+1}`,steps:Array.from({length:a},(e,a)=>({label:`${s2[(t+a)%s2.length]} ${s3[(3*t+a)%s3.length]}`,score:s5[(t+a)%s5.length]})),painPoints:t%2==0?[`Slow ${s3[t%s3.length]}`]:[],opportunities:t%3==0?[`Simplify ${s3[(t+2)%s3.length]}`]:[]}))})}s4("longest-journey",5,8),s4("widest-journey",10,4),s4("long-stage-journey",1,8),a3({id:"single-step-journey",title:"Sign in",type:aG,stages:[{name:"Sign in",steps:[{label:"Enters a password",score:3}]}]}),a3({id:"wordy-journey",title:"Enterprise procurement journey for a multi-region analytics platform",type:aG,persona:"Priya Raman, head of procurement at a regulated healthcare company",actors:["Procurement lead","Vendor account executive","Security reviewer"],stages:[{name:"Evaluate vendors and shortlist the best",steps:[{label:"Collects requirements from finance and compliance teams",score:3,actor:"Procurement lead",touchpoint:"Internal workshop"},{label:"Requests a tailored demo with production-scale sample data and a named solutions engineer",score:4,actor:"Vendor account executive",touchpoint:"Video call"}],painPoints:["Pricing pages hide the per-seat costs behind a sales conversation","Every vendor uses different names for the same capabilities","Security questionnaires arrive as unstructured spreadsheets","Reference customers in healthcare are hard to find"],opportunities:["Publish transparent pricing tiers with worked examples","Offer a standard security package with SOC 2 and HIPAA evidence"]},{name:"Negotiate",steps:[{label:"Waits three weeks for the security review",score:1,actor:"Security reviewer",touchpoint:"Email"}],painPoints:["No status updates while the review is pending"]}]}),a3({id:"cjk-journey",title:"オンライン購入",type:aG,stages:[{name:"発見",steps:[{label:"広告を見る",score:4,touchpoint:"インスタグラム"},{label:"レビューを読んで比較検討する",score:3}]},{name:"購入",steps:[{label:"カートに追加して支払う",score:2}],painPoints:["送料が最後に表示される"]}]});let s6=(e,t,a,l)=>({source:e,target:t,value:a,...void 0===l?{}:{label:l}}),s7=(...e)=>e.map(e=>({id:e.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,""),label:e}));lb({id:"cloud-budget-by-department",title:"Monthly cloud budget by department",type:"sankey",unit:"$k",nodes:s7("Engineering","Data Science","Marketing","Sales","Finance","Compute","Managed databases","Object storage","Observability and logging","GPU training clusters","Content delivery network","Customer relationship management hosting"),links:[s6("engineering","compute",310),s6("engineering","managed-databases",120),s6("engineering","object-storage",45),s6("engineering","observability-and-logging",38),s6("data-science","compute",140),s6("data-science","gpu-training-clusters",220),s6("data-science","object-storage",60),s6("marketing","content-delivery-network",25),s6("marketing","compute",4),s6("sales","customer-relationship-management-hosting",12),s6("sales","compute",2),s6("finance","managed-databases",3)]}),lb({id:"website-traffic",title:"Website visits last month",type:"sankey",unit:"visits",nodes:s7("Organic search","Paid ads","Social","Home","Pricing","Blog","Signed up","Requested demo","Bounced"),links:[s6("organic-search","home",4200),s6("organic-search","pricing",1800),s6("organic-search","blog",3e3),s6("paid-ads","pricing",2400),s6("paid-ads","home",600),s6("social","blog",1500),s6("social","home",500),s6("home","signed-up",700),s6("home","requested-demo",200),s6("home","bounced",4400),s6("pricing","signed-up",1200),s6("pricing","requested-demo",400),s6("pricing","bounced",2600),s6("blog","signed-up",300),s6("blog","bounced",4200)]}),lb({id:"hiring-funnel",title:"2026 engineering hiring funnel",type:"sankey",nodes:s7("Applicants","Phone screen","Onsite","Offer","Hired","Declined","Rejected","Withdrew"),links:[s6("applicants","phone-screen",300),s6("applicants","rejected",900),s6("phone-screen","onsite",120),s6("phone-screen","rejected",150),s6("phone-screen","withdrew",30),s6("onsite","offer",40),s6("onsite","rejected",70),s6("onsite","withdrew",10),s6("offer","hired",32),s6("offer","declined",8)]}),lb({id:"stage-drop-offs",title:"Hiring funnel with a drop-off per stage",type:"sankey",nodes:s7("Applied","Phone screen","Rejected at résumé","Onsite interview","Rejected after screen","Withdrew","Offer","Rejected after onsite","Hired","Declined offer"),links:[s6("applied","phone-screen",420),s6("applied","rejected-at-résumé",780),s6("phone-screen","onsite-interview",140),s6("phone-screen","rejected-after-screen",250),s6("phone-screen","withdrew",30),s6("onsite-interview","offer",32),s6("onsite-interview","rejected-after-onsite",108),s6("offer","hired",26),s6("offer","declined-offer",6)]}),lb({id:"energy-flow",title:"US energy flow, quads",type:"sankey",unit:"quads",nodes:s7("Solar","Wind","Nuclear","Coal","Natural gas","Petroleum","Electricity","Residential","Commercial","Industrial","Transportation","Energy services","Rejected energy"),links:[s6("solar","electricity",.9),s6("wind","electricity",1.4),s6("nuclear","electricity",8.1),s6("coal","electricity",8.2),s6("coal","industrial",.9),s6("natural-gas","electricity",11.8),s6("natural-gas","residential",5),s6("natural-gas","commercial",3.6),s6("natural-gas","industrial",10.1),s6("natural-gas","transportation",1),s6("petroleum","transportation",24),s6("petroleum","industrial",8.9),s6("petroleum","residential",.9),s6("petroleum","commercial",.8),s6("electricity","residential",5),s6("electricity","commercial",4.6),s6("electricity","industrial",3.4),s6("electricity","rejected-energy",17.4,"conversion losses"),s6("residential","energy-services",7),s6("residential","rejected-energy",3.9),s6("commercial","energy-services",5.3),s6("commercial","rejected-energy",3.7),s6("industrial","energy-services",18),s6("industrial","rejected-energy",5.3),s6("transportation","energy-services",5.2),s6("transportation","rejected-energy",19.8)]}),lb({id:"sliver-flows",title:"One dominant flow among slivers",type:"sankey",unit:"$",nodes:s7("Platform","Apps","Grants","Core team","Contractors","Tools","Travel","Swag"),links:[s6("platform","core-team",98e3),s6("platform","tools",1200),s6("apps","core-team",4500),s6("apps","contractors",900),s6("apps","travel",40),s6("grants","travel",12),s6("grants","swag",3),s6("grants","contractors",2)]}),lb({id:"long-labels",title:"Where the quarterly operating budget of the platform group goes",type:"sankey",unit:"$M",nodes:s7("Platform infrastructure and reliability","Developer experience","Cloud compute reservations","Observability, logging and incident tooling","Contractors"),links:[s6("platform-infrastructure-and-reliability","cloud-compute-reservations",4.2),s6("platform-infrastructure-and-reliability","observability-logging-and-incident-tooling",1.35),s6("developer-experience","observability-logging-and-incident-tooling",.4),s6("developer-experience","contractors",.75)]}),lb({id:"dense-budget",title:"Eight teams across eight services",type:"sankey",unit:"$k",nodes:[...Array.from({length:8},(e,t)=>({id:`team-${t}`,label:`Team ${t+1}`})),...Array.from({length:8},(e,t)=>({id:`service-${t}`,label:`Service ${String.fromCharCode(65+t)}`}))],links:Array.from({length:64},(e,t)=>{let a=Math.floor(t/8);return s6(`team-${a}`,`service-${(5*t+a)%8}`,5+37*t%90)}).filter((e,t,a)=>a.findIndex(t=>t.source===e.source&&t.target===e.target)===t)}),lb({id:"eight-stages",title:"Eight stages",type:"sankey",nodes:s7("Leads","Qualified","Contacted","Demo","Trial","Proposal","Negotiation","Won","Lost"),links:[s6("leads","qualified",800),s6("qualified","contacted",600),s6("contacted","demo",300),s6("demo","trial",180),s6("trial","proposal",90),s6("proposal","negotiation",60),s6("negotiation","won",35),s6("leads","lost",200,"never qualified"),s6("demo","lost",120),s6("negotiation","lost",25)]});let s8=(e,t,a)=>({type:"card",title:e,children:[{type:"heading",level:2,text:t},{type:"badge",text:a}]});lK({id:"saas-dashboard",title:"SaaS dashboard",type:"wireframe",screens:[{id:"dashboard",name:"Dashboard",device:"desktop",children:[{type:"header",children:[{type:"heading",level:3,text:"Acme Analytics"},{type:"search",placeholder:"Search orders"},{type:"icon",label:"Alerts"},{type:"avatar",label:"Dana Scully"}]},{type:"sidebar",children:[{type:"nav",items:["Overview","Orders","Customers","Products","Settings"],active:"Overview"}]},{type:"main",children:[{type:"row",children:[{type:"heading",level:1,text:"Overview"},{type:"button",text:"Export",variant:"secondary"},{type:"button",text:"New order",variant:"primary"}]},{type:"grid",columns:4,children:[s8("Revenue","$48,200","+12%"),s8("Orders","1,284","+4%"),s8("Customers","862","+9%"),s8("Refunds","14","-2%")]},{type:"card",title:"Revenue over time",children:[{type:"chart",kind:"line"}]},{type:"card",title:"Recent orders",children:[{type:"table",columns:["Order","Customer","Date","Total","Status"],rows:5}]}]}]}]}),lK({id:"settings-form",title:"Account settings",type:"wireframe",screens:[{id:"settings",name:"Settings",device:"desktop",children:[{type:"header",children:[{type:"heading",level:3,text:"Acme"},{type:"nav",items:["Home","Projects","Settings"],active:"Settings"},{type:"avatar",label:"Ada Lovelace"}]},{type:"main",children:[{type:"breadcrumbs",items:["Home","Settings","Account"]},{type:"heading",level:1,text:"Account settings"},{type:"tabs",items:["Profile","Notifications","Billing"],active:"Profile"},{type:"section",title:"Profile",children:[{type:"grid",columns:2,children:[{type:"input",label:"Full name",placeholder:"Ada Lovelace"},{type:"input",label:"Email",placeholder:"ada@example.com"}]},{type:"select",label:"Time zone",value:"Europe/London"},{type:"textarea",label:"Bio",placeholder:"Tell people about yourself",rows:3}]},{type:"divider"},{type:"section",title:"Notifications",children:[{type:"toggle",label:"Email me about new comments",checked:!0},{type:"toggle",label:"Weekly summary"},{type:"toggle",label:"Product announcements",disabled:!0},{type:"checkbox",label:"Also send to my phone"},{type:"radio",label:"Instantly",checked:!0},{type:"radio",label:"Daily digest"}]}]},{type:"footer",align:"end",children:[{type:"button",text:"Cancel",variant:"secondary"},{type:"button",text:"Save changes",variant:"primary"}]}]}]}),lK({id:"product-page",title:"Product page",type:"wireframe",screens:[{id:"product",name:"Product",device:"desktop",children:[{type:"header",children:[{type:"heading",level:3,text:"Trailhead"},{type:"nav",items:["Men","Women","Sale"]},{type:"search",placeholder:"Search"},{type:"icon",label:"Cart"}]},{type:"main",children:[{type:"breadcrumbs",items:["Home","Shoes","Trail runners"]},{type:"row",children:[{type:"column",children:[{type:"image",label:"Product photo",aspect:"square"},{type:"grid",columns:4,children:Array.from({length:4},()=>({type:"image",aspect:"square"}))}]},{type:"column",children:[{type:"badge",text:"New arrival"},{type:"heading",level:1,text:"Summit Trail Runner"},{type:"text",text:"Rated 4.6 from 128 reviews"},{type:"heading",level:2,text:"$129.00"},{type:"text",lines:3},{type:"select",label:"Size",placeholder:"Choose a size"},{type:"row",children:[{type:"button",text:"Add to cart",variant:"primary"},{type:"button",text:"Save",variant:"secondary"}]},{type:"list",items:["Free shipping over $50","30-day returns"]}]}]},{type:"tabs",items:["Description","Reviews","Shipping"],active:"Description"},{type:"text",lines:4}]},{type:"footer",children:[{type:"text",text:"© 2026 Trailhead"},{type:"nav",items:["Help","Returns","Contact"]}]}]}]}),lK({id:"signup-flow",title:"Signup flow",type:"wireframe",screens:[{id:"signup",name:"Sign up",device:"mobile",children:[{type:"heading",text:"Create your account"},{type:"input",label:"Email",placeholder:"you@example.com"},{type:"input",label:"Password",placeholder:"At least 8 characters"},{type:"checkbox",label:"I agree to the terms"},{type:"button",text:"Continue",variant:"primary",target:"verify"}]},{id:"verify",name:"Verify email",device:"mobile",align:"center",children:[{type:"icon",label:"Mail"},{type:"heading",text:"Check your inbox"},{type:"text",text:"We sent a six-digit code to you@example.com."},{type:"input",label:"Code",placeholder:"123456"},{type:"button",text:"Verify",variant:"primary",target:"welcome"},{type:"link",text:"Back to sign up",target:"signup"}]},{id:"welcome",name:"Welcome",device:"mobile",children:[{type:"image",label:"Celebration",aspect:"wide"},{type:"heading",text:"You're all set"},{type:"text",lines:2},{type:"button",text:"Go to dashboard",variant:"primary"}]}]}),lK({id:"delete-project",title:"Delete project",type:"wireframe",screens:[{id:"projects",name:"Projects",device:"tablet",children:[{type:"header",children:[{type:"heading",level:3,text:"Projects"},{type:"button",text:"New project",variant:"primary"}]},{type:"list",items:["Website redesign","Mobile app","Data warehouse","Brand refresh"]},{type:"modal",title:"Delete project?",children:[{type:"text",text:"This removes Mobile app and its 14 files for everyone."},{type:"input",label:"Type the project name",placeholder:"Mobile app"},{type:"row",align:"end",children:[{type:"button",text:"Cancel",variant:"secondary"},{type:"button",text:"Delete",variant:"primary"}]}]}]}]}),lK({id:"dense-mobile",title:"Dense mobile screen",type:"wireframe",screens:[{id:"feed",name:"Feed",device:"mobile",children:[{type:"header",children:[{type:"icon",label:"Menu"},{type:"heading",level:3,text:"Internationalization"},{type:"avatar"}]},{type:"search"},{type:"tabs",items:["For you","Following","Trending now","Local news","Saved"],active:"Following"},{type:"grid",columns:3,children:[s8("Unread notifications","12","new"),s8("Drafts","3","today"),s8("Scheduled","1","soon")]},{type:"card",title:"Top stories this week across every team",children:[{type:"table",columns:["Headline","Author","Reads","Published"],rows:3}]},{type:"chart",kind:"pie",label:"Readers by region"},{type:"row",children:[{type:"badge",text:"Design"},{type:"badge",text:"Engineering"},{type:"badge",text:"Operations"},{type:"badge",text:"Customer success"},{type:"badge",text:"Marketing"}]}]}]});let s9=/[,;]\s*(?:id|label|kind|group|source|target|title|direction|nodes|edges)\s*:?\s*$/i;function oe(e){let t=e.trim();for(;;){let e=t.replace(s9,"").trim();if(e===t)return t;t=e}}class ot extends i.Xsx("ContractSchemaIssue")({code:ox("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 oa extends i.rNF()("ContractSchemaError",{issues:i.O31(i.O3D(ot))}){}let ol=e=>{var t;if("InvalidType"!==e._tag)return c.vp(e);let a=c.bZ(e)?e.input:void 0;return`Invalid input: expected ${t=e.ast,d.Kg(t)?"string":d.Et(t)?"number":d.Lm(t)?"boolean":d.tF(t)?"array":d.RP(t)?"object":d.c$(t)?JSON.stringify(t.literal):"value"}, received ${null===a?"null":Array.isArray(a)?"array":typeof a}`},oi=c.ID({leafHook:ol});function os(e){let t,a;return new oa({issues:(t=[],((a=(e,l,i)=>{switch(e._tag){case"Pointer":return a(e.issue,[...l,...e.path],i);case"Encoding":return a(e.issue,l,i);case"Composite":for(let t of e.issues)a(t,l,e.ast);return;case"AnyOf":if(e.issues.length>0){for(let t of e.issues)a(t,l,e.ast);return}break;case"Filter":if(void 0===c.VY(e)&&"InvalidValue"!==e.issue._tag)return a(e.issue,l,i)}let s="ast"in e?e.ast:i,o="MissingKey"===e._tag&&e.annotations?.[oc]==="invalid_type"?"invalid_type":void 0,r=s&&d.mi(s)&&s.types.every(d.c$)?"LiteralUnion":s?._tag,n=s?.annotations?.[od],p="string"==typeof n?[...l,n]:l;for(let a of oi(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 oo=new Set(["x-sketchi-default","x-sketchi-one-of","const","exclusiveMaximum","exclusiveMinimum","maximum","maxLength","maxItems","minimum","minItems","minLength","pattern"]),or="x-sketchi-default",on="x-sketchi-one-of",od="codeModeDiscriminator",oc="codeModeMissingKeyCode";function op(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function oh(e){let t=i._oz(i.AxX(e),{includeAnnotationKey:e=>oo.has(e),onExcessProperty:"error"});return function e(t){if(Array.isArray(t))return t.map(e);if(!op(t))return t;let a=Object.fromEntries(Object.entries(t).map(([t,a])=>[t,e(a)])),l=!0===a[on];delete a[on],l&&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)op(t)&&Object.hasOwn(t,or)?a.default=t[or]: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 og(){return i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"}))}function ou(e){return i.O31(e).pipe(i.fXn).check(i.tJb(1,{message:"Too small: expected array to have >=1 items"}))}function of(e){return i.Qrq(e)}function om(e){return e.pipe(i.usV({[oc]:"invalid_type",messageMissingKey:"Invalid input: expected string, received undefined"}))}function ov(e){return e.pipe(i.usV({[oc]:"invalid_type",messageMissingKey:"Invalid input: expected object, received undefined"}))}function oy(e){return e.pipe(i.usV({[oc]:"invalid_type",messageMissingKey:"Invalid input: expected array, received undefined"}))}function ow(e){return i.xCb(e).annotate({message:`Invalid option: expected one of ${e.map(e=>JSON.stringify(e)).join("|")}`})}function ox(e){return oM(e,i.QfV)}function ob(e){return oM(e,i.wNn)}function ok(e){return oM(e,i.v8c)}function oM(e,t){let a=i.hzj()([],()=>(t,a,l)=>t===e?o.PyW(e):o.fJG(new c.eE(a,t,l)),{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 oz=og(),oC=om(oz),o_=i.wYs,oq=i.wNn.check(i.MIs(),i.yJO(0,{message:"Too small: expected number to be >0"})),oL=/^#[0-9a-fA-F]{6}$/u;function oS(e){return i.QfV.annotate(void 0===e?{}:{default:e}).check(i.Pto(oL,{message:`Invalid string: must match pattern /${oL.source}/`}))}let oB=oS(),oA=["excalidraw","scene","png"],oP=["excalidraw","scene"],oV=Object.assign(ow(oA),{options:oA}),oH=Object.assign(ow(oP),{options:oP});class oI extends i.Xsx("ArtifactProvenance")({sourceArtifactId:oC.pipe(i.Wa3)},{identifier:void 0}){}let o$=["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","composite_initial_defaulted","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","venn_too_large","invalid_venn_set","invalid_venn_region","journey_too_large","invalid_journey_stage","invalid_journey_step","sankey_too_large","invalid_sankey_node","invalid_sankey_flow","sankey_cycle","wireframe_too_large","invalid_screen","invalid_component","quadrant_too_large","invalid_quadrant_point","invalid_quadrant_text","request_too_large","generic_label","label_too_long","quality_below_threshold","render_failed","png_unavailable","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","icon_filled"],oF=Object.assign(ow(o$),{options:o$}),oO=ow(["request","diagram","node","edge","group","lane","element","layer","artifact"]),oE=ow(["input","canvas","flowchart","mindmap","quality","render","export","storage"]);class oU extends i.Xsx("CodeModeIssueRef")({kind:oO,id:of(oz),path:of(oz)},{identifier:void 0}){}class oX extends i.Xsx("CodeModeIssue")({code:oF,severity:ow(["error","warning","info"]),stage:oE,ref:of(oU),message:oC,hint:oC},{identifier:void 0}){}let oT=oX,oR=["start","process","decision","end"],oY=Object.assign(ow(oR),{options:oR}),oD=["setDefaultStyle","setStyle","setShape","translate","replaceText","rerouteEdges","insert","remove","replace","reorder","group","ungroup"];Object.assign(ow(oD),{options:oD});let oG=om(og().check(i.NYj(128,{message:"Too big: expected string to have <=128 characters"})));class oZ extends i.Xsx("NodeIconSpec")({slug:oG},{identifier:void 0}){}class oj extends i.Xsx("FlowchartSpecNode")({id:oC,label:oC,kind:oY,description:of(oz),icon:of(oZ),group:of(oz),lane:of(oz),shape:of(ow(L))},{identifier:void 0}){}class oN extends i.Xsx("FlowchartSpecLane")({id:oC,label:oC},{identifier:void 0}){}class oW extends i.Xsx("FlowchartSpecGroup")({id:oC,label:oC,parent:of(oz),kind:of(ow(z))},{identifier:void 0}){}class oJ extends i.Xsx("FlowchartSpecEdge")({id:of(oz),source:oC,target:oC,label:of(oz)},{identifier:void 0}){}let oK=ow(["TB","LR"]),oQ=oK.annotate({default:"TB"}).pipe(i.E$i(o.PyW("TB")));class o1 extends i.Xsx("FlowchartSpecLayout")({direction:oQ},{identifier:void 0}){}let o0=y.accentColor,o2=oS(o0).pipe(i.E$i(o.PyW(o0))),o3=y.backgroundColor,o5=oS(o3).pipe(i.E$i(o.PyW(o3)));class o4 extends i.Xsx("FlowchartSpecStyle")({accentColor:o2,backgroundColor:o5},{identifier:void 0}){}let o6=[],o7=i.O31(oJ).pipe(i.fXn).annotate({default:o6}).pipe(i.E$i(o.PyW(o6))),o8={direction:"TB"},o9=o1.annotate({default:o8}).pipe(i.E$i(o.PyW(o8)),i.usV({[or]:o8})),re={accentColor:y.accentColor,backgroundColor:y.backgroundColor},rt=o4.annotate({default:re}).pipe(i.E$i(o.PyW(re)),i.usV({[or]:re}));class ra extends i.Xsx("FlowchartSpec")({id:of(oz),title:oC,nodes:oy(ou(oj)),edges:o7,groups:of(i.O31(oW).pipe(i.fXn)),lanes:of(i.O31(oN).pipe(i.fXn)),layout:o9,style:rt},{identifier:void 0}){}class rl extends i.Xsx("SequenceParticipantSpec")({id:oC,label:oC,kind:of(oz),icon:of(oZ)},{identifier:void 0}){}class ri extends i.Xsx("SequenceMessageSpec")({id:of(oz),source:oC,target:oC,label:oC,type:of(ow(eI)),style:of(ow(e$))},{identifier:void 0}){}let rs=[],ro=i.O31(ri).pipe(i.fXn).annotate({default:rs}).pipe(i.E$i(o.PyW(rs)));class rr extends i.Xsx("SequenceDiagramSpec")({id:of(oz),title:oC,participants:oy(ou(rl)),messages:ro,style:rt},{identifier:void 0}){}class rn extends i.Xsx("TimelineEventSpec")({id:oC,label:oC,date:of(oz),end:of(oz),order:of(o_),kind:of(ow(Q)),lane:of(oz),description:of(oz)},{identifier:void 0}){}class rd extends i.Xsx("TimelineSpec")({id:of(oz),title:oC,events:oy(ou(rn)),lanes:of(i.O31(oz).pipe(i.fXn)),today:of(oz),style:rt},{identifier:void 0}){}class rc extends i.Xsx("ChartSeriesSpec")({name:of(oz),values:oy(i.O31(o_).pipe(i.fXn))},{identifier:void 0}){}class rp extends i.Xsx("ChartSpec")({id:of(oz),title:oC,kind:ow(T),categories:oy(ou(oz)),series:oy(ou(rc)),unit:of(oz),categoryAxisTitle:of(oz),valueAxisTitle:of(oz),stacked:of(i.v8c),donut:of(i.v8c),orientation:of(ow(R)),style:rt},{identifier:void 0}){}class rh extends i.Xsx("StateMachineStateSpec")({id:oC,label:of(oz),kind:of(ow(eW)),parent:of(oz),initial:of(oz)},{identifier:void 0}){}class rg extends i.Xsx("StateMachineTransitionSpec")({id:of(oz),source:oC,target:oC,event:of(oz),guard:of(oz),action:of(oz)},{identifier:void 0}){}class ru extends i.Xsx("StateMachineSpecLayout")({direction:ow(eJ)},{identifier:void 0}){}let rf=[],rm=i.O31(rg).pipe(i.fXn).annotate({default:rf}).pipe(i.E$i(o.PyW(rf)));class rv extends i.Xsx("StateMachineSpec")({id:of(oz),title:oC,initial:oC,states:oy(ou(rh)),transitions:rm,layout:of(ru),style:rt},{identifier:void 0}){}class ry extends i.Xsx("GanttTaskSpec")({id:oC,label:oC,start:oC,end:of(oz),duration:of(o_),milestone:of(i.v8c),phase:of(oz),dependsOn:of(i.O31(oz).pipe(i.fXn)),progress:of(o_)},{identifier:void 0}){}class rw extends i.Xsx("GanttSpec")({id:of(oz),title:oC,tasks:oy(ou(ry)),phases:of(i.O31(oz).pipe(i.fXn)),today:of(oz),style:rt},{identifier:void 0}){}class rx extends i.Xsx("ErFieldSpec")({name:oC,type:of(oz),pk:of(i.v8c),fk:of(i.v8c),unique:of(i.v8c),nullable:of(i.v8c)},{identifier:void 0}){}let rb=[];class rk extends i.Xsx("ErEntitySpec")({id:oC,name:of(oz),fields:i.O31(i.gPz([oz,rx])).pipe(i.fXn).annotate({default:rb}).pipe(i.E$i(o.PyW(rb)))},{identifier:void 0}){}class rM extends i.Xsx("ErRelationshipSpec")({id:of(oz),from:oC,to:oC,fromCardinality:ow(ty),toCardinality:ow(ty),label:of(oz)},{identifier:void 0}){}let rz=[],rC=i.O31(rM).pipe(i.fXn).annotate({default:rz}).pipe(i.E$i(o.PyW(rz)));class r_ extends i.Xsx("ErSpec")({id:of(oz),title:oC,entities:oy(ou(rk)),relationships:rC,style:rt},{identifier:void 0}){}class rq extends i.Xsx("ClassAttributeSpec")({name:oC,type:of(oz),visibility:of(ow(tE)),static:of(i.v8c)},{identifier:void 0}){}class rL extends i.Xsx("ClassParameterSpec")({name:oC,type:of(oz)},{identifier:void 0}){}let rS=[];class rB extends i.Xsx("ClassMethodSpec")({name:oC,params:i.O31(i.gPz([oz,rL])).pipe(i.fXn).annotate({default:rS}).pipe(i.E$i(o.PyW(rS))),returns:of(oz),visibility:of(ow(tE)),static:of(i.v8c),abstract:of(i.v8c)},{identifier:void 0}){}let rA=[],rP=[];class rV extends i.Xsx("ClassNodeSpec")({id:oC,name:of(oz),kind:of(ow(tF)),stereotype:of(oz),attributes:i.O31(i.gPz([oz,rq])).pipe(i.fXn).annotate({default:rA}).pipe(i.E$i(o.PyW(rA))),methods:i.O31(i.gPz([oz,rB])).pipe(i.fXn).annotate({default:rP}).pipe(i.E$i(o.PyW(rP)))},{identifier:void 0}){}class rH extends i.Xsx("ClassRelationshipSpec")({id:of(oz),kind:ow(tT),from:oC,to:oC,fromMultiplicity:of(oz),toMultiplicity:of(oz),fromRole:of(oz),toRole:of(oz),navigable:of(i.v8c),label:of(oz)},{identifier:void 0}){}let rI=[],r$=i.O31(rH).pipe(i.fXn).annotate({default:rI}).pipe(i.E$i(o.PyW(rI)));class rF extends i.Xsx("ClassSpec")({id:of(oz),title:oC,classes:oy(ou(rV)),relationships:r$,style:rt},{identifier:void 0}){}class rO extends i.Xsx("OrgPersonSpec")({id:oC,name:oC,title:of(oz),department:of(oz),manager:of(oz),assistant:of(i.v8c),avatar:of(i.v8c)},{identifier:void 0}){}class rE extends i.Xsx("OrgDottedLineSpec")({id:of(oz),report:oC,manager:oC,label:of(oz)},{identifier:void 0}){}let rU=[],rX=i.O31(rE).pipe(i.fXn).annotate({default:rU}).pipe(i.E$i(o.PyW(rU)));class rT extends i.Xsx("OrgChartSpec")({id:of(oz),title:oC,people:oy(ou(rO)),dottedLines:rX,groupByDepartment:of(i.v8c),forest:of(i.v8c),style:rt},{identifier:void 0}){}class rR extends i.Xsx("VennSetSpec")({id:oC,label:oC,color:of(oz)},{identifier:void 0}){}class rY extends i.Xsx("VennRegionSpec")({sets:oy(ou(oz)),label:of(oz),items:of(i.O31(oz).pipe(i.fXn)),count:of(i.Aiz.check(i.OWK(0,{message:"Too small: expected number to be >=0"})))},{identifier:void 0}){}let rD=[],rG=i.O31(rY).pipe(i.fXn).annotate({default:rD}).pipe(i.E$i(o.PyW(rD)));class rZ extends i.Xsx("VennSpec")({id:of(oz),title:oC,sets:oy(ou(rR)),regions:rG,style:rt},{identifier:void 0}){}class rj extends i.Xsx("JourneyStepSpec")({label:oC,score:o_,actor:of(oz),touchpoint:of(oz)},{identifier:void 0}){}class rN extends i.Xsx("JourneyStageSpec")({name:oC,steps:oy(i.O31(rj).pipe(i.fXn)),painPoints:of(i.O31(oz).pipe(i.fXn)),opportunities:of(i.O31(oz).pipe(i.fXn))},{identifier:void 0}){}class rW extends i.Xsx("JourneySpec")({id:of(oz),title:oC,persona:of(oz),actors:of(i.O31(oz).pipe(i.fXn)),stages:oy(ou(rN)),style:rt},{identifier:void 0}){}class rJ extends i.Xsx("SankeyNodeSpec")({id:oC,label:oC,color:of(oB)},{identifier:void 0}){}class rK extends i.Xsx("SankeyLinkSpec")({source:oC,target:oC,value:o_,label:of(oz)},{identifier:void 0}){}class rQ extends i.Xsx("SankeySpec")({id:of(oz),title:oC,nodes:oy(ou(rJ)),links:oy(ou(rK)),unit:of(oz),style:rt},{identifier:void 0}){}let r1=ov(i.DYE(()=>r0).annotate({identifier:"Component"})),r0=i._kM({type:ow(lA),text:of(oz),label:of(oz),title:of(oz),placeholder:of(oz),value:of(oz),level:of(i.Aiz),lines:of(i.Aiz),variant:of(ow(["primary","secondary"])),checked:of(i.v8c),disabled:of(i.v8c),items:of(i.O31(oz).pipe(i.fXn)),active:of(oz),columns:of(i.gPz([i.Aiz,i.O31(oz).pipe(i.fXn)])),rows:of(i.Aiz),kind:of(ow(lV)),aspect:of(ow(lH)),side:of(ow(["left","right"])),align:of(ow(lP)),target:of(oz),children:of(i.O31(r1).pipe(i.fXn))});class r2 extends i.Xsx("WireframeScreenSpec")({id:of(oz),name:oC,device:of(ow(lS)),align:of(ow(lP)),children:oy(ou(r1))},{identifier:void 0}){}class r3 extends i.Xsx("WireframeSpec")({id:of(oz),title:oC,screens:oy(ou(r2)),style:rt},{identifier:void 0}){}class r5 extends i.Xsx("QuadrantAxisSpec")({title:oC,low:oC,high:oC},{identifier:void 0}){}class r4 extends i.Xsx("QuadrantNamesSpec")({topLeft:oC,topRight:oC,bottomLeft:oC,bottomRight:oC},{identifier:void 0}){}class r6 extends i.Xsx("QuadrantPointSpec")({label:oC,x:o_,y:o_,group:of(oz)},{identifier:void 0}){}class r7 extends i.Xsx("QuadrantChartSpec")({id:of(oz),title:oC,xAxis:ov(r5),yAxis:ov(r5),quadrants:ov(r4),points:oy(i.O31(r6).pipe(i.fXn)),style:rt},{identifier:void 0}){}let r8=of(ou(oV)),r9=of(i.O31(oH).pipe(i.fXn)),ne=of(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 nt extends i.Xsx("BuildFlowchartOptions")({artifactFormats:r8,inlineArtifacts:r9,minQualityScore:ne},{identifier:void 0}){}of(nt);class na extends i.Xsx("BuildFlowchartRequest")({requestId:of(oz),spec:ov(ra),options:of(nt)},{identifier:void 0}){}let nl=ra.mapFields(({id:e,title:t,nodes:a,edges:l,groups:i,lanes:s,layout:o})=>({id:e,title:t,nodes:a,edges:l,groups:i,lanes:s,layout:o})),ni=i._kM({requestId:of(oz),spec:ov(nl)}),ns=i.rcy(ni,{leafHook:ol,parseOptions:{errors:"all"}}),no=Object.assign(ns,{"~standard":{...ns["~standard"],jsonSchema:{input:()=>oh(ni),output:()=>oh(ni)}}}),nr=Object.assign(na,{omit:e=>no});class nn extends i.Xsx("BuildSequenceDiagramRequest")({requestId:of(oz),spec:ov(rr),options:of(nt)},{identifier:void 0}){}i._kM({requestId:of(oz),spec:ov(rr.mapFields(({id:e,title:t,participants:a,messages:l})=>({id:e,title:t,participants:a,messages:l})))});class nd extends i.Xsx("BuildTimelineRequest")({requestId:of(oz),spec:ov(rd),options:of(nt)},{identifier:void 0}){}i._kM({requestId:of(oz),spec:ov(rd.mapFields(({id:e,title:t,events:a,lanes:l,today:i})=>({id:e,title:t,events:a,lanes:l,today:i})))});class nc extends i.Xsx("BuildChartRequest")({requestId:of(oz),spec:ov(rp),options:of(nt)},{identifier:void 0}){}let np=rp.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(np)});class nh extends i.Xsx("BuildStateMachineRequest")({requestId:of(oz),spec:ov(rv),options:of(nt)},{identifier:void 0}){}i._kM({requestId:of(oz),spec:ov(rv.mapFields(({id:e,title:t,initial:a,states:l,transitions:i,layout:s})=>({id:e,title:t,initial:a,states:l,transitions:i,layout:s})))});class ng extends i.Xsx("BuildGanttRequest")({requestId:of(oz),spec:ov(rw),options:of(nt)},{identifier:void 0}){}let nu=rw.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(nu)});class nf extends i.Xsx("BuildErDiagramRequest")({requestId:of(oz),spec:ov(r_),options:of(nt)},{identifier:void 0}){}let nm=r_.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(nm)});class nv extends i.Xsx("BuildClassDiagramRequest")({requestId:of(oz),spec:ov(rF),options:of(nt)},{identifier:void 0}){}let ny=rF.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(ny)});class nw extends i.Xsx("BuildOrgChartRequest")({requestId:of(oz),spec:ov(rT),options:of(nt)},{identifier:void 0}){}let nx=rT.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(nx)});class nb extends i.Xsx("BuildVennDiagramRequest")({requestId:of(oz),spec:ov(rZ),options:of(nt)},{identifier:void 0}){}let nk=rZ.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(nk)});class nM extends i.Xsx("BuildJourneyMapRequest")({requestId:of(oz),spec:ov(rW),options:of(nt)},{identifier:void 0}){}let nz=rW.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(nz)});class nC extends i.Xsx("BuildSankeyRequest")({requestId:of(oz),spec:ov(rQ),options:of(nt)},{identifier:void 0}){}let n_=rQ.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(n_)});class nq extends i.Xsx("BuildWireframeRequest")({requestId:of(oz),spec:ov(r3),options:of(nt)},{identifier:void 0}){}let nL=r3.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(nL)});class nS extends i.Xsx("BuildQuadrantChartRequest")({requestId:of(oz),spec:ov(r7),options:of(nt)},{identifier:void 0}){}let nB=r7.mapFields(({style:e,...t})=>t);i._kM({requestId:of(oz),spec:ov(nB)});let nA=i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"}),i.HNH(function(e){let t=oe(e);return t.length>0&&!/^(?:""|''|``)$/.test(t)},{message:"Must contain semantic text after normalization."})),nP=ov(i.DYE(()=>nV).annotate({identifier:"__schema0"})),nV=i._kM({label:om(nA),children:i.Qrq(i.O31(nP).pipe(i.fXn))});class nH extends i.Xsx("MindmapSpecLayout")({direction:ow(["LR","RL"]).annotate({default:"LR"}).pipe(i.E$i(o.PyW("LR")))},{identifier:void 0}){}let nI={direction:"LR"},n$=nH.annotate({default:nI}).pipe(i.E$i(o.PyW(nI)),i.usV({[or]:nI})),nF=i._kM({id:of(oz),title:om(nA),root:nP,layout:n$,style:rt});class nO extends i.Xsx("MindmapSpec")(nF,{identifier:void 0}){}let nE=i._kM({requestId:of(oz),spec:ov(nF),options:of(nt)});i.Xsx("BuildMindmapRequest")(nE,{identifier:void 0});class nU extends i.Xsx("ScenePoint")({x:o_.pipe(i.Wa3),y:o_.pipe(i.Wa3)},{identifier:void 0}){}let nX={frameId:of(oz).pipe(i.Wa3),groupIds:of(i.O31(oz).pipe(i.fXn).annotate({maxItems:iB.maxGroupsPerElement})).pipe(i.Wa3),layerId:of(oz).pipe(i.Wa3),locked:of(i.v8c).pipe(i.Wa3),opacity:of(i.wNn.check(i.MIs(),i.Bt9({minimum:0,maximum:100}))).pipe(i.Wa3),zIndex:of(i.Aiz).pipe(i.Wa3)},nT={fillColor:of(oB).pipe(i.Wa3),fillStyle:of(ow(["cross-hatch","hachure","solid"])).pipe(i.Wa3),roughness:of(ow([0,1,2])).pipe(i.Wa3),strokeColor:of(oB).pipe(i.Wa3),strokeStyle:of(ow(["dashed","dotted","solid"])).pipe(i.Wa3),strokeWidth:of(ow([1,2,4])).pipe(i.Wa3)},nR=i.T9y(ow(["arrow","bar","circle","diamond","triangle","crowfoot_one","crowfoot_many","crowfoot_one_or_many","triangle_outline","diamond_outline"])),nY=i.O31(nU).pipe(i.fXn).check(i.tJb(2,{message:"Too small: expected array to have >=2 items"}),i.NYj(iB.maxPointsPerElement,{message:`Too big: expected array to have <=${iB.maxPointsPerElement} items`}));class nD extends i.Xsx("CanvasNodeIcon")({slug:oG.pipe(i.Wa3),size:i.wNn.check(i.MIs(),i.Bt9({minimum:iA.minSize,maximum:iA.maxSize},{message:`Expected a number between ${iA.minSize} and ${iA.maxSize}`})).pipe(i.Wa3)},{identifier:void 0}){}class nG extends i.Xsx("CanvasIconAsset")({name:i.QfV,svg:i.QfV},{identifier:void 0}){}class nZ extends i.Xsx("NodeSceneElement")({...nX,...nT,type:ox("node"),id:oC,nodeId:oC,kind:of(oz),icon:of(nD).pipe(i.Wa3),rendererRole:of(ow(iT)),shape:ow(["rectangle","ellipse","diamond","circle","polygon",...iP]).pipe(i.Wa3),points:of(nY).pipe(i.Wa3),textColor:of(oB).pipe(i.Wa3),x:o_.pipe(i.Wa3),y:o_.pipe(i.Wa3),width:oq.pipe(i.Wa3),height:oq.pipe(i.Wa3),label:oC.pipe(i.Wa3)},{identifier:void 0}){}class nj extends i.Xsx("TextSceneElement")({...nX,type:ox("text"),id:oC,containerId:of(oz),textColor:of(oB).pipe(i.Wa3),x:o_.pipe(i.Wa3),y:o_.pipe(i.Wa3),text:oC.pipe(i.Wa3),fontSize:oq,fontFamily:of(ow(["hand","mono","sans"])),lineHeight:of(oq),maxWidth:of(oq),textAlign:of(ow(["center","left","right"])),verticalAlign:of(ow(["bottom","middle","top"]))},{identifier:void 0}){}class nN extends i.Xsx("ArrowSceneElement")({...nX,...nT,type:ox("arrow"),id:oC,edgeId:oC,sourceNodeId:oC,targetNodeId:oC.pipe(i.Wa3),startArrowhead:of(nR).pipe(i.Wa3),endArrowhead:of(nR).pipe(i.Wa3),textColor:of(oB).pipe(i.Wa3),points:oy(nY).pipe(i.Wa3),curved:of(i.v8c).pipe(i.Wa3),label:of(oz).pipe(i.Wa3)},{identifier:void 0}){}class nW extends i.Xsx("CanvasLineBinding")({elementId:oC,focus:of(o_),gap:of(o_)},{identifier:void 0}){}class nJ extends i.Xsx("LineSceneElement")({...nX,...nT,type:ox("line"),id:oC,points:oy(nY).pipe(i.Wa3),startBinding:of(nW).pipe(i.Wa3),endBinding:of(nW).pipe(i.Wa3),startArrowhead:of(nR).pipe(i.Wa3),endArrowhead:of(nR).pipe(i.Wa3),label:of(oz).pipe(i.Wa3),textColor:of(oB).pipe(i.Wa3)},{identifier:void 0}){}class nK extends i.Xsx("FrameSceneElement")({...nX,...nT,type:ox("frame"),id:oC,nodeId:of(oz),name:of(oz).pipe(i.Wa3),icon:of(nD).pipe(i.Wa3),x:o_.pipe(i.Wa3),y:o_.pipe(i.Wa3),width:oq.pipe(i.Wa3),height:oq.pipe(i.Wa3)},{identifier:void 0}){}class nQ extends i.Xsx("CanvasLayer")({id:oC,name:of(oz),locked:of(i.v8c),visible:of(i.v8c)},{identifier:void 0}){}let n1=oy(ou(oz));class n0 extends i.Xsx("CanvasFlowLayout")({type:ow(["row","column","stack"]),ids:n1,x:of(o_),y:of(o_),gap:of(o_)},{identifier:void 0}){}class n2 extends i.Xsx("CanvasGridLayout")({type:ox("grid"),ids:n1,columns:i.Aiz.check(i.OWK(1,{message:"Too small: expected number to be >=1"})),x:of(o_),y:of(o_),columnGap:of(o_),rowGap:of(o_)},{identifier:void 0}){}class n3 extends i.Xsx("CanvasAlignLayout")({type:ox("align"),ids:n1,axis:ow(["x","y"]),alignment:ow(["center","end","start"])},{identifier:void 0}){}class n5 extends i.Xsx("CanvasDistributeLayout")({type:ox("distribute"),ids:n1,axis:ow(["x","y"]),gap:of(o_)},{identifier:void 0}){}let n4=i.gPz([nZ,nj,nN,nJ,nK],{mode:"oneOf"}).annotate({[on]:!0}),n6=i.gPz([n0,n2,n3,n5],{mode:"oneOf"}),n7=i.O31(nQ).pipe(i.fXn).annotate({default:[],maxItems:iB.maxLayers}).pipe(i.E$i(o.PyW([]))),n8=i.O31(n6).pipe(i.fXn).annotate({default:[],maxItems:iB.maxLayouts}).pipe(i.E$i(o.PyW([]))),n9=i.O31(oz).pipe(i.fXn).annotate({default:[],maxItems:iB.maxZOrderEntries}).pipe(i.E$i(o.PyW([])));class de extends i.Xsx("CanvasSpec")({kind:ox("canvas"),version:ob(1),diagramId:oC,title:oC,width:oq.pipe(i.Wa3),height:oq.pipe(i.Wa3),accentColor:oB.pipe(i.Wa3),backgroundColor:oB.pipe(i.Wa3),elements:oy(i.O31(n4).pipe(i.fXn).annotate({maxItems:iB.maxElements})),icons:of(i.mSG(i.QfV,nG)).pipe(i.Wa3),layers:n7,layouts:n8,zOrder:n9},{identifier:void 0}){}let dt=de;class da extends i.Xsx("CreateCanvasRequest")({requestId:of(oz),spec:ov(de),options:of(nt)},{identifier:void 0}){}let dl=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 di extends i.Xsx("ExcalidrawScene")({appState:i.mSG(i.QfV,i.$r1),elements:i.O31(dl).pipe(i.fXn)},{identifier:void 0}){}class ds extends di.extend("ExcalidrawFile")({files:i.mSG(i.QfV,i.$r1),source:oC,type:ox("excalidraw"),version:ob(2)},{identifier:void 0}){}let dr=ds;class dn extends i.Xsx("GetArtifactRequest")({artifactId:oC,format:of(oV),inline:of(i.v8c)},{identifier:void 0}){}class dd extends i.Xsx("DiagramSelector")({ids:of(i.O31(oz).pipe(i.fXn)),nodeIds:of(i.O31(oz).pipe(i.fXn)),edgeIds:of(i.O31(oz).pipe(i.fXn)),kinds:of(i.O31(oY).pipe(i.fXn)),labels:of(i.O31(oz).pipe(i.fXn)),scope:of(ow(["all","nodes","edges"]))},{identifier:void 0}){}class dc extends i.Xsx("DiagramStylePatch")({strokeColor:of(oB),fillColor:of(oB),textColor:of(oB),backgroundColor:of(oB)},{identifier:void 0}){}let dp=["rectangle","diamond","ellipse","circle","polygon"],dh=Object.assign(ow(dp),{options:dp});class dg extends i.Xsx("SetDefaultStyleOperation")({op:ox("setDefaultStyle"),style:ov(dc)},{identifier:void 0}){}class du extends i.Xsx("SetStyleOperation")({op:ox("setStyle"),selector:ov(dd),style:ov(dc)},{identifier:void 0}){}class df extends i.Xsx("SetShapeOperation")({op:ox("setShape"),selector:ov(dd),shape:dh},{identifier:void 0}){}class dm extends i.Xsx("TranslateOperation")({op:ox("translate"),selector:ov(dd),dx:o_,dy:o_},{identifier:void 0}){}class dv extends i.Xsx("ReplaceTextOperation")({op:ox("replaceText"),selector:ov(dd),text:oC},{identifier:void 0}){}class dy extends i.Xsx("RerouteEdgesOperation")({op:ox("rerouteEdges"),selector:of(dd)},{identifier:void 0}){}let dw=oy(ou(oz));class dx extends i.Xsx("InsertElementsOperation")({op:ox("insert"),elements:oy(ou(n4)),beforeId:of(oz),afterId:of(oz)},{identifier:void 0}){}class db extends i.Xsx("RemoveElementsOperation")({op:ox("remove"),selector:ov(dd)},{identifier:void 0}){}class dk extends i.Xsx("ReplaceElementOperation")({op:ox("replace"),id:oC,element:ov(n4)},{identifier:void 0}){}class dM extends i.Xsx("ReorderElementsOperation")({op:ox("reorder"),ids:dw,beforeId:of(oz),afterId:of(oz)},{identifier:void 0}){}class dz extends i.Xsx("GroupElementsOperation")({op:ox("group"),ids:dw,groupId:oC},{identifier:void 0}){}class dC extends i.Xsx("UngroupElementsOperation")({op:ox("ungroup"),ids:dw,groupId:of(oz)},{identifier:void 0}){}let d_=i.gPz([dg,du,df,dm,dv,dy,dx,db,dk,dM,dz,dC],{mode:"oneOf"}).annotate({[on]:!0,[od]:"op",message:`Invalid discriminator value. Expected ${oD.map(e=>`'${e}'`).join(" | ")}`});class dq extends i.Xsx("ArtifactPatchSource")({artifactId:oC,format:of(ox("scene"))},{identifier:void 0}){}class dL extends i.Xsx("InlineScenePatchSource")({scene:ov(de)},{identifier:void 0}){}let dS=i.gPz([dq,dL]).annotate({message:"Invalid input"});class dB extends i.Xsx("ApplyDiagramPatchOptions")({artifactFormats:r8,inlineArtifacts:r9,preserveConnectivity:of(i.v8c)},{identifier:void 0}){}of(dB);class dA extends i.Xsx("ApplyDiagramPatchRequest")({requestId:of(oz),source:dS.annotateKey({messageMissingKey:"Invalid input"}),operations:oy(ou(d_)),options:of(dB),intent:of(oz)},{identifier:void 0}){}class dP extends i.Xsx("NormalizedMindmapTopic")({id:oz,label:oz,children:i.O31(i.DYE(()=>dP)).pipe(i.fXn)},{identifier:void 0}){}let dV=i._kM({id:oz,title:oz,nodes:i.O31(oj).pipe(i.fXn),edges:i.O31(oJ.mapFields(e=>({...e,id:oz}))).pipe(i.fXn),groups:i.Qrq(i.O31(oW).pipe(i.fXn)),lanes:i.Qrq(i.O31(oN).pipe(i.fXn)),layout:i._kM({direction:oK}),style:i._kM({accentColor:oB,backgroundColor:oB})}),dH=i._kM({id:oz,title:oz,root:dP,layout:i._kM({direction:ow(["LR","RL"])}),style:i._kM({accentColor:oB,backgroundColor:oB})}),dI=i._kM({id:oz,title:oz,participants:i.O31(rl).pipe(i.fXn),messages:i.O31(ri.mapFields(e=>({...e,id:oz}))).pipe(i.fXn),style:i._kM({accentColor:oB,backgroundColor:oB})}),d$=i._kM({id:oz,title:oz,events:i.O31(rn).pipe(i.fXn),lanes:of(i.O31(oz).pipe(i.fXn)),today:of(oz),style:i._kM({accentColor:oB,backgroundColor:oB})}),dF=i._kM({id:oz,title:oz,initial:oz,states:i.O31(rh).pipe(i.fXn),transitions:i.O31(rg.mapFields(e=>({...e,id:oz}))).pipe(i.fXn),layout:of(ru),style:i._kM({accentColor:oB,backgroundColor:oB})}),dO=rw.mapFields(e=>({...e,id:oz,title:oz,style:i._kM({accentColor:oB,backgroundColor:oB})})),dE=i._kM({id:oz,title:oz,entities:i.O31(i._kM({id:oz,name:of(oz),fields:i.O31(rx).pipe(i.fXn)})).pipe(i.fXn),relationships:i.O31(rM.mapFields(e=>({...e,id:oz}))).pipe(i.fXn),style:i._kM({accentColor:oB,backgroundColor:oB})}),dU=i._kM({id:oz,title:oz,classes:i.O31(i._kM({id:oz,name:of(oz),kind:of(ow(tF)),stereotype:of(oz),attributes:i.O31(rq).pipe(i.fXn),methods:i.O31(rB.mapFields(e=>({...e,params:i.O31(rL).pipe(i.fXn)}))).pipe(i.fXn)})).pipe(i.fXn),relationships:i.O31(rH.mapFields(e=>({...e,id:oz}))).pipe(i.fXn),style:i._kM({accentColor:oB,backgroundColor:oB})}),dX=i._kM({id:oz,title:oz,people:i.O31(rO).pipe(i.fXn),dottedLines:i.O31(rE.mapFields(e=>({...e,id:oz}))).pipe(i.fXn),groupByDepartment:of(i.v8c),forest:of(i.v8c),style:i._kM({accentColor:oB,backgroundColor:oB})}),dT=i._kM({id:oz,title:oz,sets:i.O31(rR).pipe(i.fXn),regions:i.O31(rY).pipe(i.fXn),style:i._kM({accentColor:oB,backgroundColor:oB})}),dR=i._kM({id:oz,title:oz,persona:of(oz),actors:of(i.O31(oz).pipe(i.fXn)),stages:i.O31(rN).pipe(i.fXn),style:i._kM({accentColor:oB,backgroundColor:oB})}),dY=i._kM({id:oz,title:oz,nodes:i.O31(rJ).pipe(i.fXn),links:i.O31(rK).pipe(i.fXn),unit:of(oz),style:i._kM({accentColor:oB,backgroundColor:oB})}),dD=i._kM({id:oz,title:oz,screens:i.O31(i._kM({id:oz,name:oz,device:ow(lS),align:of(ow(lP)),children:i.O31(r1).pipe(i.fXn)})).pipe(i.fXn),style:i._kM({accentColor:oB,backgroundColor:oB})}),dG=i._kM({id:oz,title:oz,xAxis:r5,yAxis:r5,quadrants:r4,points:i.O31(r6).pipe(i.fXn),style:i._kM({accentColor:oB,backgroundColor:oB})}),dZ=rp.mapFields(e=>({...e,id:oz,title:oz,style:i._kM({accentColor:oB,backgroundColor:oB})})),dj=i._kM({code:i.QfV,passed:i.v8c,severity:ow(["error","warning"]),message:i.QfV,refs:i.O31(oU).pipe(i.fXn)}),dN=i._kM({accepted:i.v8c,score:i.wNn,threshold:i.wNn,summary:i._kM({nodeCount:i.wNn,edgeCount:i.wNn}),checks:i.O31(dj).pipe(i.fXn)}),dW=i._kM({format:oV,mimeType:i.QfV,url:of(i.QfV),expiresAt:of(i.QfV),inline:of(i.$r1),sizeBytes:of(i.wNn)}),dJ=i._kM({artifactId:i.QfV,diagramId:i.QfV,formats:i.O31(dW).pipe(i.fXn),provenance:of(oI)}),dK=i._kM({artifactId:of(i.QfV),diagramId:of(i.QfV),formats:of(i.O31(dW).pipe(i.fXn))});class dQ extends i.Xsx("BuildFlowchartAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dV,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class d1 extends i.Xsx("BuildFlowchartRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_flowchart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dV),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([dQ,d1]);class d0 extends i.Xsx("BuildMindmapAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dH,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class d2 extends i.Xsx("BuildMindmapRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_mindmap","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dH),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([d0,d2]);class d3 extends i.Xsx("BuildSequenceDiagramAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dI,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class d5 extends i.Xsx("BuildSequenceDiagramRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_sequence","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dI),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([d3,d5]);class d4 extends i.Xsx("BuildTimelineAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:d$,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class d6 extends i.Xsx("BuildTimelineRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_timeline","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(d$),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([d4,d6]);class d7 extends i.Xsx("BuildChartAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dZ,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class d8 extends i.Xsx("BuildChartRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_chart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dZ),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([d7,d8]);class d9 extends i.Xsx("BuildStateMachineAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dF,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class ce extends i.Xsx("BuildStateMachineRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_state_machine","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dF),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([d9,ce]);class ct extends i.Xsx("BuildGanttAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dO,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class ca extends i.Xsx("BuildGanttRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_gantt","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dO),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([ct,ca]);class cl extends i.Xsx("BuildErDiagramAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dE,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class ci extends i.Xsx("BuildErDiagramRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_er_diagram","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dE),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cl,ci]);class cs extends i.Xsx("BuildClassDiagramAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dU,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class co extends i.Xsx("BuildClassDiagramRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_class_diagram","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dU),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cs,co]);class cr extends i.Xsx("BuildOrgChartAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dX,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class cn extends i.Xsx("BuildOrgChartRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_org_chart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dX),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cr,cn]);class cd extends i.Xsx("BuildVennDiagramAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dT,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class cc extends i.Xsx("BuildVennDiagramRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_venn_diagram","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dT),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cd,cc]);class cp extends i.Xsx("BuildJourneyMapAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dR,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class ch extends i.Xsx("BuildJourneyMapRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_journey","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dR),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cp,ch]);class cg extends i.Xsx("BuildSankeyAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dY,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class cu extends i.Xsx("BuildSankeyRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_sankey","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dY),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cg,cu]);class cf extends i.Xsx("BuildWireframeAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dD,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class cm extends i.Xsx("BuildWireframeRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_wireframe","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dD),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cf,cm]);class cv extends i.Xsx("BuildQuadrantChartAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:dG,quality:dN,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class cy extends i.Xsx("BuildQuadrantChartRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_quadrant_chart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(dG),quality:of(dN),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cv,cy]);class cw extends i.Xsx("GetArtifactAccepted")({ok:ok(!0),artifactId:i.QfV,diagramId:i.QfV,format:oV,mimeType:i.QfV,url:of(i.QfV),expiresAt:of(i.QfV),inline:of(i.$r1),sizeBytes:of(i.wNn),provenance:of(oI)},{identifier:void 0}){}class cx extends i.Xsx("GetArtifactRejected")({ok:ok(!1),status:ow(["invalid_input","not_found","format_unavailable","expired","storage_failed"]),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cw,cx]);class cb extends i.Xsx("ApplyDiagramPatchAccepted")({ok:ok(!0),status:ox("accepted"),patchId:i.QfV,requestId:of(i.QfV),sourceArtifactId:of(i.QfV),artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class ck extends i.Xsx("ApplyDiagramPatchRejected")({ok:ok(!1),status:ow(["invalid_input","source_unavailable","target_not_found","unsupported_operation","connectivity_changed","render_failed","export_failed","storage_failed"]),patchId:of(i.QfV),requestId:of(i.QfV),sourceArtifactId:of(i.QfV),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cb,ck]);class cM extends i.Xsx("CreateCanvasAccepted")({ok:ok(!0),status:ox("accepted"),buildId:i.QfV,requestId:of(i.QfV),normalizedSpec:de,artifact:dJ,issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class cz extends i.Xsx("CreateCanvasRejected")({ok:ok(!1),status:ow(["invalid_input","invalid_canvas","limit_exceeded","render_failed","export_failed","storage_failed"]),buildId:of(i.QfV),requestId:of(i.QfV),normalizedSpec:of(de),partial:of(dK),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}let cC=i.gPz([cM,cz]),c_=120,cq=1,cL=25;class cS extends i.Xsx("SearchIconsRequest")({q:om(og().check(i.NYj(c_,{message:`Too big: expected string to have <=${c_} characters`}))),limit:of(i.Aiz.check(i.Bt9({minimum:cq,maximum:cL},{message:`Expected an integer between ${cq} and ${cL}`})))},{identifier:void 0}){}class cB extends i.Xsx("SearchIconsMatch")({slug:i.QfV,name:i.QfV,collection:i.QfV,match:ow(["exact","vendor","weak"])},{identifier:void 0}){}class cA extends i.Xsx("SearchIconsAccepted")({ok:ok(!0),status:ox("accepted"),query:i.QfV,icons:i.O31(cB).pipe(i.fXn),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}class cP extends i.Xsx("SearchIconsRejected")({ok:ok(!1),status:ow(["invalid_input"]),issues:i.O31(oX).pipe(i.fXn)},{identifier:void 0}){}i.gPz([cA,cP]);let cV=i.xCb(["read","readManifest","write"]);class cH extends i.rNF()("CodeModeArtifactStorageError",{cause:i.kld(),message:i.QfV,operation:cV}){}class cI extends s.kl()("@sketchi/diagram-agent/CodeModeArtifactStorage"){}let c$={excalidraw:"application/vnd.excalidraw+json",png:"image/png",scene:"application/vnd.sketchi.scene+json"};function cF(e){return"excalidraw"===e||"scene"===e}function cO(e){return{format:e.format,mimeType:e.mimeType,sizeBytes:e.sizeBytes}}function cE(e){return new TextEncoder().encode(JSON.stringify(e)).length}let cU=n.QZ(cI)(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 l=t.get(`${e}:${a}`);return l?{...l,data:structuredClone(l.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 l;let i=yield*r.Ru;return yield*o.SvU({try:()=>{var l;let s=a.formats.map(cO),o=a.provenance?structuredClone(a.provenance):void 0,r={artifactId:a.artifactId,diagramId:a.diagramId,formats:s,...o?{provenance:o}:{},createdAt:new Date(i).toISOString()};for(let l of(e.set(a.artifactId,r),a.formats))t.set(`${a.artifactId}:${l.format}`,{...l,data:structuredClone(l.data)});let n=a.formats.map(e=>{var t;return t=a.inlineFormats,{format:e.format,mimeType:e.mimeType,...cF(e.format)&&t.includes(e.format)?{inline:e.data}:{},sizeBytes:e.sizeBytes}});return{artifactId:(l={artifactId:a.artifactId,diagramId:a.diagramId,formats:n,...a.provenance?{provenance:structuredClone(a.provenance)}:{}}).artifactId,diagramId:l.diagramId,formats:l.formats,...l.provenance?{provenance:l.provenance}:{}}},catch:(l="write",e=>{var t;return cH.make({cause:e,message:(t="Artifact storage failed.",e instanceof Error?e.message:t),operation:l})})})})}}}),e=>e.close).pipe(o.TjK(e=>e.storage))),cX=new TextEncoder;function cT(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."}}o.D9k(function*(e,t,a){let l=yield*r.Ru,i=yield*a,s=yield*r.Ru;return{body:i,bodyBytes:"string"==typeof i?cX.encode(i).byteLength:i.byteLength,bodyMs:s-l,contentType:t,format:e}});let cR="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",cY=cR.slice(10),cD=new Map;function cG(e){let t=cD.get(e);if(void 0===t){t=new Uint8Array(256);for(let a=0;a<e.length;a++)t[e.charCodeAt(a)]=a;cD.set(e,t)}return t}function cZ(e,t,a,l){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 s=0;for(;(e[s]||i)===t[s];)s++;if(s>0)return t.slice(0,s)+cZ(e.slice(s),t.slice(s),a,l)}let s=e?l[e.charCodeAt(0)]:0,o=null!=t?l[t.charCodeAt(0)]:a.length;return o-s>1?a[Math.round(.5*(s+o))]:t&&t.length>1?t.slice(0,1):a[s]+cZ(e.slice(1),null,a,l)}function cj(e,t,a){if(e.length!==cN(e[0],t,a))throw Error("invalid integer part of order key: "+e)}function cN(e,t,a){let l=a[e.charCodeAt(0)];if(t[l]===e){let e=t.length/2;return l<e?e-l+1:l-e+2}throw Error("invalid order key head: "+e)}function cW(e,t,a){let l=cN(e[0],t,a);if(l>e.length)throw Error("invalid order key: "+e);return e.slice(0,l)}function cJ(e,t,a,l){if(c1(e,t,a))throw Error("invalid order key: "+e);let i=cW(e,a,l);if(e.slice(i.length).slice(-1)===t[0])throw Error("invalid order key: "+e)}function cK(e,t,a,l,i){cj(e,l,i);let s=e[0],o=t[0],r="";for(let l=e.length-1;l>=1;l--){let i=a[e.charCodeAt(l)]+1;if(i!==t.length)return s+e.slice(1,l)+t[i]+r;r=o+r}let n=i[s.charCodeAt(0)];if(n===l.length-1)return null;let d=l[n+1],c=cN(d,l,i)-cN(s,l,i);return d+(c>0?r+o:c<0?r.slice(1):r)}let cQ=new Map;function c1(e,t,a){let l=cQ.get(a);void 0===l&&(l=new Map,cQ.set(a,l));let i=t.charCodeAt(0),s=l.get(i);return void 0===s&&(s=a[0]+t[0].repeat(a.length/2),l.set(i,s)),e===s}function c0(e){for(let t=1;t<e.length;t++)if(e.charCodeAt(t-1)>=e.charCodeAt(t))return!1;return!0}function c2(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}let c3=new Set,c5=new Set,c4=new Set(["rectangle","ellipse","diamond"]),c6=v.ink;function c7(e){return"number"==typeof e&&Number.isFinite(e)?e:null}function c8(e){if(!Array.isArray(e)||e.length<2)return null;let t=c7(e[0]),a=c7(e[1]);return null===t||null===a?null:[t,a]}function c9(e){let t=c7(e.x),a=c7(e.y),l=c7(e.width),i=c7(e.height);return null===t||null===a||null===l||null===i?null:{x:t,y:a,width:l,height:i}}function pe(e){return 1e-4>Math.abs(e-.5)?.5001:e}function pt(e,t){let a=c9(e);return a&&0!==a.width&&0!==a.height?[pe((t.x-a.x)/a.width),pe((t.y-a.y)/a.height)]:null}function pa(e,t){return{elementId:e?.id??"",focus:0,gap:0,fixedPoint:e?pt(e,t):null}}function pl(e,t){let a=sh(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 pi(e){var t;let a,l=e.wrap?iS(e.text,e.maxWidth,e.fontSize):e.text,i=e.wrap?iq(l,e.fontSize,e.maxWidth):i_(l,e.fontSize,e.maxWidth),s=e.element?.lineHeight??1.35,o=function(e,t,a=1.35){return Math.ceil(e.split("\n").length*t*a)}(l,e.fontSize,s),r=e.element?.verticalAlign;return{...pl(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+iK(t).y,"top"===r?a:a+iQ(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:s,originalText:e.text,roundness:null,strokeColor:e.textColor??c6,text:l,textAlign:e.element?.textAlign??"center",verticalAlign:e.element?.verticalAlign??"middle",autoResize:!(e.wrap&&!e.containerId)}}function ps(e,t){return`sketchi-icon-${e}-${sh(t,"hex","utf16")}`}function po(e,t){return{id:e,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)}(t)}`,created:1,lastRetrieved:1}}function pr(e){return iV(e.shape)?`${e.id}:shape`:`${e.id}:logo`}function pn(e){let{node:t}=e,a="frame"===t.type||"zone"===t.rendererRole,l=a?sF(t):function(e){if(!e.icon)return;let t=iK(e);return{x:e.x+(e.width-e.icon.size)/2,y:e.y+t.y+iA.gap,width:e.icon.size,height:e.icon.size}}(t);return l&&t.icon?{...pl(e.id,t),..."frame"===t.type?{frameId:t.id,groupIds:[]}:{groupIds:[pr(t),...t.groupIds??[]]},type:"image",x:l.x,y:l.y,width:l.width,height:l.height,backgroundColor:"transparent",boundElements:null,crop:null,customData:a?{sketchiGroupIcon:t.icon.slug}:{sketchiNodeIcon:t.icon.slug},fileId:e.fileId,roundness:null,scale:[1,1],status:"saved",strokeColor:"transparent"}:null}function pd(e){return e.points[e.points.length-1]??e.points[0]}function pc(e,t,a){if(!e)return null;let l=t.get(e.elementId);return l?{elementId:e.elementId,focus:e.focus??0,gap:e.gap??0,fixedPoint:pt(l,a)}:null}function pp(e){return"node"===e.type}function ph(e){return"text"===e.type}function pg(e){return"arrow"===e.type}function pu(e){return"line"===e.type}function pf(e){return"frame"===e.type}function pm(e,t){let a=`${e.id.replace(/[^\w-]/gu,"-")}-icon`,l=a,i=2;for(;t.has(l);)l=`${a}-${i}`,i+=1;return t.add(l),l}function pv(e,t){let a=e[t];if(!(a&&"object"==typeof a))return null;let l=a.elementId;return"string"==typeof l?l:null}function py(e){let t=c7(e.x)??0,a=c7(e.y)??0,l=pv(e,"startBinding"),i=pv(e,"endBinding"),s=Array.isArray(e.points)?e.points.map(c8).filter(e=>null!==e).map(([e,l])=>({x:t+e,y:a+l})):[];return ss(s).map(t=>({...t,arrowId:e.id,startBindingId:l,endBindingId:i,startCoordinate:"horizontal"===t.orientation?s[t.segmentIndex].x:s[t.segmentIndex].y,endCoordinate:"horizontal"===t.orientation?s[t.segmentIndex+1].x:s[t.segmentIndex+1].y,route:s}))}function pw(e){if(c4.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 px(e,t,a){let l=a.get(e.id);return!!l&&[t.startBindingId,t.endBindingId].some(t=>{let i=null===t?void 0:a.get(t);return null!=i&&t!==e.id&&i.x>=l.x&&i.y>=l.y&&i.x+i.width<=l.x+l.width&&i.y+i.height<=l.y+l.height})}function pb(e,t,a){return e>=t-.01&&e<=a+.01}function pk(e,t){return .01>=Math.abs(e-t)}let pM=[1,2,5];function pz(e){return Math.max(0,-Math.floor(Math.log10(e)+1e-9))}function pC(e,t){let a=Number(e.toFixed(t));return Object.is(a,-0)?0:a}function p_(e,t,a=5,l=8){let i,s=Math.min(e,t),o=Math.max(e,t);s===o&&(0===s?o=1:s>0?s=0:o=0);let r=Math.floor(Math.log10((o-s)/Math.max(1,a)));for(let e=r-1;e<=r+1;e+=1)for(let t of pM){let r=t*10**e,n=pz(r),d=pC(Math.floor(s/r+1e-9)*r,n),c=pC(Math.ceil(o/r-1e-9)*r,n),p=Math.round((c-d)/r);if(p<1||p>l)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:d,max:c,intervals:p})}if(!i)throw Error(`No tick step covers ${s}..${o}.`);let n=pz(i.step),d=Array.from({length:i.intervals+1},(e,t)=>pC(i.min+t*i.step,n));return{min:i.min,max:i.max,step:i.step,ticks:d,decimals:n}}function pq(e,t,a){let l=t?pC(e.min-e.step,e.decimals):e.min,i=a?pC(e.max+e.step,e.decimals):e.max,s=Math.round((i-l)/e.step);return{...e,min:l,max:i,ticks:Array.from({length:s+1},(t,a)=>pC(l+a*e.step,e.decimals))}}function pL(e,t){let a=Math.min(...e),l=Math.max(...e);if(t||a<=0!=l<=0)return{low:Math.min(0,a),high:Math.max(0,l)};let i=Math.max(Math.abs(a),Math.abs(l));return l-a>i/6?{low:Math.min(0,a),high:Math.max(0,l)}:{low:a,high:l}}let pS=/^[$€£¥₹₩₽₺₪₦฿]+/u,pB=/^(?:[%‰°]|(?:[kKMBT]|bn|MM|x)(?!\p{L}))/u;function pA(e){if(!e)return{prefix:"",suffix:""};let t=pS.exec(e)?.[0]??"",a=e.slice(t.length);return t?{prefix:t,suffix:a}:{prefix:"",suffix:pB.test(a)?a:` ${a}`}}function pP(e){let[t="",a="0"]=Math.abs(e).toString().split("e");return Math.max(0,(t.split(".")[1]?.length??0)-Number(a))}let pV=new Map;function pH(e,t){let a=pV.get(t);return a||(a=new Intl.NumberFormat("en-US",{minimumFractionDigits:t,maximumFractionDigits:t}),pV.set(t,a)),a.format(e)}let pI=[{size:1e12,letter:"T"},{size:1e9,letter:"B"},{size:1e6,letter:"M"},{size:1e3,letter:"k"}];function p$(e,t,a){return`${t?"-":""}${a.prefix}${e}${a.suffix}`}function pF(e){return!/^(?:[kKMBT]|bn|MM)/u.test(e.suffix)}function pO(e,t,a=pP(e)){let l=e<0,i=Math.abs(e);if(i>=1e6&&0===a&&pF(t)){let e=pI.find(e=>i>=e.size),a=Number((i/e.size).toPrecision(12));if(Number(a.toPrecision(3))===a)return p$(`${pH(a,pP(a))}${e.letter}`,l,t)}return i>0&&a>6?p$(i.toExponential(),l,t):p$(pH(i,a),l,t)}let pE=e=>Math.round(100*e)/100;function pU(e,t,a,l=2){let i=new Map;for(let s of e){if("line"!==s.type||!a(s.id)||2!==s.points.length)continue;let[e,o]=s.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,d=r?Math.min(e.x,o.x):Math.min(e.y,o.y),c=r?Math.max(e.x,o.x):Math.max(e.y,o.y),p=t.filter(e=>r?e.top-l<n&&n<e.bottom+l:e.left-l<n&&n<e.right+l).map(e=>r?[e.left-l,e.right+l]:[e.top-l,e.bottom+l]).filter(([e,t])=>t>d&&e<c).toSorted((e,t)=>e[0]-t[0]);if(!p.length)continue;let h=[],g=d;for(let[e,t]of p)e>g&&h.push([g,Math.min(e,c)]),g=Math.max(g,t);g<c&&h.push([g,c]),i.set(s.id,h.filter(([e,t])=>t-e>=1).map(([e,t],a)=>({...s,id:0===a?s.id:`${s.id}:${a}`,points:r?[{x:pE(e),y:n},{x:pE(t),y:n}]:[{x:n,y:pE(e)},{x:n,y:pE(t)}]})))}return i}let pX="chart-mark",pT=["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#6250d6","#e34948"],pR=v.ink,pY="#4c4639",pD="#e6dfd2",pG="#8c826f",pZ=3*Math.PI/180,pj=20*Math.PI/180;function pN(e,t){return{text:e,width:Math.ceil(iC(e,t)),height:Math.ceil(e.split("\n").length*t*1.35)}}function pW(e,t,a){return pN(iS(e,Math.max(1,t),a),a)}function pJ(e){return Math.round(100*e)/100}function pK(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 pQ(e,t,a,l){let i=e.map((e,t)=>t).toSorted((t,a)=>e[t].preferred-e[a].preferred),s=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);s[t]=i,o=i+a.size+l}let r=a;for(let t of i.toReversed()){let a=e[t],i=Math.min(s[t],r-a.size);s[t]=i,r=i-l}return s}function p1(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 p0(e,t){return(Math.max(e,t)+.05)/(Math.min(e,t)+.05)}function p2(e){let t=p1(e);return p0(t,p1(pR))>=p0(t,1)?pR:"#ffffff"}function p3(e,t){let a=[...pT.slice(0,e)];return t&&7===e&&(a[6]=pT[7]),a}class p5{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=pU(this.elements,this.textBoxes.map(e=>e.box),e,t);if(!a.size)return;let l=this.elements.flatMap(e=>a.get(e.id)??[e]);for(let e of(this.elements.splice(0,this.elements.length,...l),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,l,i,s,o="center",r={}){let n={left:a,top:l,right:a+t.width,bottom:l+t.height};return this.push({type:"text",id:e,x:pJ(a+t.width/2),y:pJ(l+t.height/2),text:t.text,fontSize:i,maxWidth:t.width,textAlign:o,textColor:s,...r},"front"),this.textBoxes.push({id:e,box:n}),n}line(e,t,a,l,i="back"){this.push({type:"line",id:e,points:[{x:pJ(t.x),y:pJ(t.y)},{x:pJ(a.x),y:pJ(a.y)}],roughness:0,strokeWidth:1,...l},i)}mark(e,t,a,l,i,s="middle"){this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:pX,shape:t,x:pJ(a.x),y:pJ(a.y),width:pJ(Math.max(a.width,.5)),height:pJ(Math.max(a.height,.5)),label:l,roughness:0,fillStyle:"solid",strokeWidth:1,...i},s)}polygon(e,t,a,l,i="middle"){let s=t.map(e=>e.x),o=t.map(e=>e.y),r=Math.min(...s),n=Math.min(...o),d=t.map(e=>({x:pJ(e.x-r),y:pJ(e.y-n)}));this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:pX,shape:"polygon",points:[d[0],d[1],d[2],...d.slice(3)],x:pJ(r),y:pJ(n),width:pJ(Math.max(Math.max(...s)-r,.5)),height:pJ(Math.max(Math.max(...o)-n,.5)),label:a,roughness:0,fillStyle:"solid",strokeWidth:1,...l},i)}bounds(){let e=1/0,t=1/0,a=-1/0,l=-1/0,i=(i,s,o,r)=>{e=Math.min(e,i),t=Math.min(t,s),a=Math.max(a,o),l=Math.max(l,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??iC(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:l}}}function p4(e,t,a){let l=e.bounds(),i=Math.max(l.right-l.left,320),s=l.top-16;if(a.legend&&t.series.length>1){let o=t.series.map((e,t)=>{let l=pW(e.name??`Series ${t+1}`,200,14),i="line"===a.legend?26:12;return{index:t,text:l,keyWidth:i,width:i+6+l.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 d=r.map(e=>Math.max(...e.map(e=>e.text.height))),c=s-d.reduce((e,t)=>e+t,0)-(r.length-1)*6;s=c-12,r.forEach((t,i)=>{let s=d[i],o=c+s/2,r=l.left;for(let l of t){let t=a.colors[l.index],i={groupIds:[`chart:legend:${l.index}`]};"line"===a.legend?(e.line(`chart:legend:${l.index}:line`,{x:r,y:o},{x:r+l.keyWidth,y:o},{strokeColor:t,strokeWidth:2,...i},"middle"),p6(e,`chart:key:${l.index}`,l.index,r+l.keyWidth/2,o,t,l.text.text,i)):e.mark(`chart:key:${l.index}`,"rectangle",{x:r,y:o-6,width:12,height:12},l.text.text,{fillColor:t,strokeColor:t,...i}),e.text(`chart:legend:${l.index}:label`,l.text,r+l.keyWidth+6,o-l.text.height/2,14,pR,"left",i),r+=l.width+18}c+=s+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=pW(o,Math.max(i,360),14);e.text("chart:subtitle",t,l.left,s-t.height,14,pY,"left"),s-=t.height+6}let n=pW(t.title,Math.max(i,360),20);e.text("chart:title",n,l.left,s-n.height,20,pR,"left")}function p6(e,t,a,l,i,s,o,r={}){let n={strokeColor:e.surface,strokeWidth:1,fillColor:s,...r},d=a%6;if(3===d||5===d)return e.polygon(t,3===d?[{x:l,y:i-6.5},{x:l+6.5,y:i+5.2},{x:l-6.5,y:i+5.2}]:[{x:l-6.5,y:i-5.2},{x:l+6.5,y:i-5.2},{x:l,y:i+6.5}],o,n,"front"),{left:l-6.5,top:i-6.5,right:l+6.5,bottom:i+6.5};let c=2===d?13:1===d?10:11,p={x:l-c/2,y:i-c/2,width:c,height:c};return e.mark(t,1===d?"rectangle":2===d?"diamond":"ellipse",p,o,4===d?{strokeColor:s,strokeWidth:2,fillColor:e.surface,...r}:n,"front"),{left:p.x,top:p.y,right:p.x+c,bottom:p.y+c}}function p7(e,t){return e.series[t]?.name??e.title}function p8(e,t){return{scale:e,labels:e.ticks.map(a=>pN(function(e,t,a){let l=Math.max(Math.abs(t.min),Math.abs(t.max)),i=e<0,s=Math.abs(e);if(0===s)return p$("0",!1,pF(a)?a:{...a,suffix:""});if(l>=1e4&&pF(a)){let e=pI.find(e=>l>=e.size),o=Math.max(0,pz(t.step/e.size));return p$(`${pH(s/e.size,o)}${e.letter}`,i,a)}return p$(pH(s,t.decimals),i,a)}(a,e,t),13))}}function p9(e){let t=!0===e.stacked&&e.series.length>1,a=pA(e.unit),l=Math.max(...e.series.flatMap(e=>e.values.map(pP))),i=e.categories.map((t,l)=>e.series.map(e=>{let t=e.values[l];return{value:t,text:pN(pO(t,a),12)}})),s=e.categories.map((t,i)=>{let s=e.series.map(e=>e.values[i]),o=s.filter(e=>e>0).reduce((e,t)=>e+t,0),r=s.filter(e=>e<0).reduce((e,t)=>e+t,0),n=e=>({value:e,text:pN(pO(Number(e.toFixed(l)),a,l),12)});return{...o>0||0===r?{up:n(o)}:{},...r<0?{down:n(r)}:{}}}),o=t?s.flatMap(e=>[e.up?.value??0,e.down?.value??0]):e.series.flatMap(e=>e.values);return{diagram:e,stacked:t,parts:a,colors:p3(e.series.length,!1),labels:i,totals:s,domain:pL(o,!0)}}function he(e,t,a,l){let i=t;for(let t of e){let e=Math.max(i,Math.max(...t.split(/\s+/u).map(e=>pN(e,14).width))+10);for(;e<l&&pW(t,e-10,14).text.split("\n").length>a;)e+=4;i=Math.max(i,e)}return i}function ht(e){let t=e.stacked?1:e.diagram.series.length,a=Math.min(96,720/e.diagram.categories.length),l=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)),s=e=>t*e+(t-1)*2;if(1===t)return{bars:t,thickness:l,band:Math.max(s(l)+20,a,i+8)};let o=Math.max(l,i+2);return{bars:t,thickness:o,band:Math.max(s(o)+16,a)}}function ha(e,t,a,l,i=5){let s=p_(e.low,e.high,i);for(let e=0;e<2;e+=1){let e=t/(s.max-s.min),i=a(s,e),o=l(s,e);if(!i&&!o)break;s=pq(s,o,i)}return s}function hl(e,t,a){let l=Math.max(1,Math.ceil(Math.abs(a-t)/pZ));return Array.from({length:l+1},(i,s)=>{let o=t+(a-t)*s/l;return{x:e*Math.cos(o),y:e*Math.sin(o)}})}function hi(e,t,a){let l=Math.cos(t),i=Math.sin(t),s=Math.max(0,Math.min(a,e.x*l+e.y*i));return Math.hypot(e.x-s*l,e.y-s*i)}let hs=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function ho(e){let t=new Date(864e5*e);return{year:t.getUTCFullYear(),month:t.getUTCMonth()+1,day:t.getUTCDate(),weekday:(t.getUTCDay()+6)%7}}function hr(e,t,a=1){let l=new Date(0);return l.setUTCFullYear(e,t-1,a),Math.round(l.getTime()/864e5)}let hn=[{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 hd(e,t,a,l,i,s=1/0){let o=[];for(let r=function(e,t,a){let l=ho(e);switch(t){case"day":return e;case"week":return e-l.weekday;case"month":return hr(l.year,l.month);case"quarter":return hr(l.year,l.month-(l.month-1)%3);case"year":return hr(l.year-(l.year%a+a)%a,1)}}(e,a,l);r<t;){if(o.length>=s)return;let e=function(e,t,a){let l=ho(e);switch(t){case"day":return e+1;case"week":return e+7;case"month":return hr(l.year,l.month+1);case"quarter":return hr(l.year,l.month+3);case"year":return hr(l.year+a,1)}}(r,a,l);o.push({start:r,end:e,label:i(r)}),r=e}return o}function hc(e){return e%2==0?16:12}let hp=[0,6,12,18,24,30],hh=[1,0,-1,0],hg=[0,1,0,-1];function hu(e,t,a){return{x:e.x+hh[t]*a,y:e.y+hg[t]*a}}function hf(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 hm{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 l=this.order++,i=this.length++;for(;i>0;){let t=i-1>>1;if(!hv(e,l,this.costs[t],this.orders[t]))break;this.move(t,i),i=t}this.place(i,e,t,l,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],l=this.orders[t],i=this.states[t],s=0;for(;;){let a=2*s+1;if(a>=t)break;let i=a+1,o=i<t&&hv(this.costs[i],this.orders[i],this.costs[a],this.orders[a])?i:a;if(!hv(this.costs[o],this.orders[o],e,l))break;this.move(o,s),s=o}this.place(s,e,a,l,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,l,i){this.costs[e]=t,this.reachedAt[e]=a,this.orders[e]=l,this.states[e]=i}grow(){let e=2*this.costs.length,t=(t,a)=>{let l=a(e);return l.set(t),l};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 hv(e,t,a,l){return e<a-1e-9||1e-9>=Math.abs(e-a)&&t<l}function hy(e,t,a,l){let{box:i}=e;if(e.parallel&&i.right-i.left>=i.bottom-i.top!==l)return!1;let s=Math.max(0,e.clearance-.01),o=Math.max(0,(e.sideClearance??e.clearance)-.01);return l?Math.min(a,i.right+o)-Math.max(t,i.left-o)>.01:Math.min(a,i.bottom+s)-Math.max(t,i.top-s)>.01}function hw(e,t,a){return e.filter(({box:e,clearance:l,sideClearance:i})=>{let s=Math.max(0,l-.01),o=Math.max(0,(i??l)-.01);return a?t>e.top-s&&t<e.bottom+s:t>e.left-o&&t<e.right+o})}function hx(e){return .01>Math.abs(e.from.y-e.to.y)}function hb(e,t,a,l=5){let i=.01>Math.abs(e.y-t.y);if(i!==hx(a)||(i?Math.abs(e.y-a.from.y):Math.abs(e.x-a.from.x))>=l)return!1;let[s,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(s,r)>-l}function hk(e,t,a){if(!a)return!1;let l=.01>Math.abs(e.y-t.y);return l===hx(a)&&(l?.01>Math.abs(e.y-a.from.y):.01>Math.abs(e.x-a.from.x))}let hM={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 hz(e){let t=function(e){let t;for(let a of e.sources)for(let l of e.targets){if(a.direction!==l.direction)continue;let i=a.direction%2==0?(l.x-a.x)*hh[a.direction]:(l.y-a.y)*hg[a.direction];if(!(a.direction%2==0?.01>Math.abs(a.y-l.y):.01>Math.abs(a.x-l.x))||i<(a.lead??8)+hc(l.direction))continue;let s=e.obstacles.some(e=>!e.own&&function(e,t,a){let l=.01>Math.abs(t.y-a.y);return 0!==hw([e],l?t.y:t.x,l).length&&hy(e,l?Math.min(t.x,a.x):Math.min(t.y,a.y),l?Math.max(t.x,a.x):Math.max(t.y,a.y),l)}(e,a,l))||e.routed.some(t=>!e.trunks?.has(t)&&!e.joins?.has(t)&&hb(a,l,t)),o=a.cost+l.cost+i;s||t&&!(o<t.cost)||(t={cost:o,points:[a,l]})}return t?.points}(e);if(t)return t;let a=[...e.sources,...e.targets],l=(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:s}=e,o=void 0===s?i:{...i,behind:s},r={...o,separation:2.5,lanes:e.denseLanes,splits:[.25,.5,.75],crossingCost:2},n=l(200,90),d=l(800,360),{reach:c}=e,p=c?{left:Math.min(d.left,c.left),right:Math.max(d.right,c.right),top:Math.min(d.top,e.top),bottom:Math.max(d.bottom,e.bottom)}:d,h=e.budget,g=e.kinkBudget,u=(t,a,l)=>{if(h&&h.remaining<=0)return;let i=function(e,t,a){var l;let{routed:i}=e,{separation:s}=a,o=e.pastTrunk??new Map,r=[...e.obstacles,...o.keys()],n=e.sources.map(e=>hu(e,e.direction,e.lead??8)),d=e.targets.map(e=>hu(e,(e.direction+2)%4,hc(e.direction))),c=[...e.sources,...e.targets,...n,...d],p=8+hp.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)]),...(e.besides??[]).filter(e=>e.bottom>=t.top&&e.top<=t.bottom).flatMap(e=>[e.left-15,e.right+15])].filter(e=>e>=t.left&&e<=t.right),u=c.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=hf([...u,...g,...hp.flatMap(e=>[f-e,m+e])]),y=hf([...v,...v.slice(1).flatMap((e,t)=>{let l=v[t];return e-l>4*s?a.splits.map(t=>l+(e-l)*t):[]})]),w=hf([...c.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=[],z=e=>M[e]??={x:y[e%y.length],y:w[Math.floor(e/y.length)]},C=p+12,_=i.filter(e=>Math.max(e.from.x,e.to.x)>=t.left-C&&Math.min(e.from.x,e.to.x)<=t.right+C&&Math.max(e.from.y,e.to.y)>=t.top-C&&Math.min(e.from.y,e.to.y)<=t.bottom+C),q=_.filter(hx),L=_.filter(e=>!hx(e)),S=(e.edges??[]).filter(e=>e.right>=t.left&&e.left<=t.right&&e.bottom>=t.top-7&&e.top<=t.bottom+7),B=(e.sides??[]).filter(e=>e.right>=t.left-15&&e.left<=t.right+15&&e.bottom>=t.top&&e.top<=t.bottom),A=new Map,P=new Map,V=(t,a)=>{let l=a?A:P,i=l.get(t);if(!i){let[o,r]=a?[q,L]:[L,q],n=e=>Math.abs(a?e.from.y-t:e.from.x-t);i={obstacles:hw(h,t,a),routed:[...o.filter(e=>n(e)<s),...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):B.filter(e=>t<=e.left&&e.left-t<14.99||t>=e.right&&t-e.right<14.99)},l.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)},I=(t,a,l=!1,i=!1,r=H(t,a))=>{let n=.01>Math.abs(t.y-a.y),d=n?Math.min(t.x,a.x):Math.min(t.y,a.y),c=n?Math.max(t.x,a.x):Math.max(t.y,a.y);return!r.obstacles.some(e=>!(l&&e.own)&&!(i&&hk(t,a,o.get(e)))&&hy(e,d,c,n))&&!r.routed.some(o=>!(i&&e.trunks?.has(o))&&!(l&&e.joins?.has(o))&&hb(t,a,o,s))},{behind:$}=a,F=e.targets.map(e=>e.cost+hc(e.direction)),O=Float64Array.from(d,e=>e.x),E=Float64Array.from(d,e=>e.y),U=(e,t,a)=>{let l=1/0;for(let i=0;i<O.length;i+=1){let s=O[i]-e,o=E[i]-t,r=s*hh[a]+o*hg[a],n=Math.abs(s*hg[a])+Math.abs(o*hh[a])<.01?r>-.01?0:2:r>-.01?1:2,d=Math.abs(s)+Math.abs(o)+24*n+F[i];d<l&&(l=d)}return l},{steps:X,stepStamp:T,estimates:R,estimateStamp:Y,gridEpoch:D}=(l=y.length*w.length*4,hM.stepStamp.length<l&&(hM.steps=new Float64Array(l),hM.stepStamp=new Int32Array(l),hM.estimates=new Float64Array(l),hM.estimateStamp=new Int32Array(l)),hM.gridEpoch>=0x40000000&&(hM.stepStamp.fill(0),hM.estimateStamp.fill(0),hM.gridEpoch=0),hM.gridEpoch+=1,hM),G=new Map,Z=new Map;e.targets.forEach((e,t)=>{let a=d[t],l=k(a);if(void 0===l||!I(a,e,!0))return;G.set(l,[...G.get(l)??[],e]);let i=4*l+e.direction;Z.set(i,Math.min(Z.get(i)??1/0,F[t]))});let j=(e,t,a,l)=>{let i=4*e+a;if(!l&&T[i]===D)return X[i];let s=N(z(e),z(t),a,l)??1/0;return l||(T[i]=D,X[i]=s),s},N=(t,l,i,s)=>{let o=V(i%2==0?t.y:t.x,i%2==0);if(!I(t,l,!1,s,o))return;let r=2===i?a.crossingCost*(e.backCrossingFactor??8):a.crossingCost;return Math.abs(l.x-t.x)+Math.abs(l.y-t.y)+(void 0===$?0:4*Math.max(0,Math.min($,Math.max(t.x,l.x))-Math.min(t.x,l.x)))+(i%2==0?2:1)*((e,t,a=H(e,t))=>{if(0===a.edges.length)return 0;let l=.01>Math.abs(e.y-t.y),i=l?Math.min(e.x,t.x):Math.min(e.y,t.y),s=l?Math.max(e.x,t.x):Math.max(e.y,t.y),o=0;for(let e of a.edges)o+=l?Math.max(0,Math.min(s,e.right)-Math.max(i,e.left)):Math.max(0,Math.min(s,e.bottom)-Math.max(i,e.top));return o})(t,l,o)+(r?((t,a,l=H(t,a))=>{let i=0;for(let s of l.routed)(function(e,t,a){let l=.01>Math.abs(e.y-t.y);if(l===hx(a))return!1;let[i,s,o,r]=l?[e,t,a.from,a.to]:[a.from,a.to,e,t],n=o.x,d=i.y;return n>Math.min(i.x,s.x)+.01&&n<Math.max(i.x,s.x)-.01&&d>Math.min(o.y,r.y)+.01&&d<Math.max(o.y,r.y)-.01})(t,a,s)&&(i+=e.lastRuns?.has(s)?4:1);return i})(t,l,o)*r:0)+2*((e,t,a=H(e,t))=>{if(0===a.beside.length)return 0;let l=.01>Math.abs(e.y-t.y),i=l?Math.min(e.x,t.x):Math.min(e.y,t.y),s=l?Math.max(e.x,t.x):Math.max(e.y,t.y),o=0;for(let e of a.beside){let[t,a]=l?[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(s,a)-Math.max(i,t))}return o})(t,l,o)},W=y.length,J=w.length;return(t,a,l)=>{var i;let s,{best:o,previous:r,stamp:d,epoch:c}=(i=y.length*w.length*12,hM.stamp.length<i&&(hM.best=new Float64Array(i),hM.previous=new Int32Array(i),hM.stamp=new Int32Array(i)),hM.epoch>=0x40000000&&(hM.stamp.fill(0),hM.epoch=0),hM.epoch+=1,hM),p=e=>d[e]===c?o[e]:1/0,h=(e,t)=>{let a=e%3;if(0===a)return!1;let l=e-a,i=2!==a||Z.has(l/3)?0:40;return p(l+0)<=t+i+1e-9||2===a&&p(l+1)<=t+i+1e-9},g=new hm,u=new Map;e.sources.forEach((e,t)=>{let a=n[t],l=k(a);if(void 0===l||!I(e,a,!0,!0))return;let i=(4*l+e.direction)*3+0,s=e.cost+(e.lead??8);s<p(i)&&(d[i]=c,o[i]=s,r[i]=-1,u.set(i,e),g.push(s+U(a.x,a.y,e.direction),s,i))});let f=a,m=(e,t,a,l,i)=>{let s;if(t>=p(e)-1e-9||h(e,t))return;let n=(Y[s=4*l+i]!==D&&(Y[s]=D,R[s]=U(y[l%y.length],w[Math.floor(l/y.length)],i)),R[s]);e%3==2&&(n=Math.min(40+n,Z.get(4*l+i)??1/0)),t+n>=f||(d[e]=c,o[e]=t,r[e]=a,u.delete(e),g.push(t+n,t,e))},v=0;for(;g.size>0&&v++<l;){let e=g.pop(),a=g.cost,l=g.reached;if(a>=f)break;let i=p(e);if(l>i+1e-6||h(e,i))continue;let o=e%3,r=Math.floor(e/12),n=Math.floor(e/3)%4,d=r%W,c=(r-d)/W,u=y[d],v=w[c],x=40*(2===o);for(let t of G.get(r)??[]){if((t.direction+2)%4===n)continue;let a=i+t.cost+hc(t.direction)+(t.direction===n?0:24+x);a<f&&(s={state:e,port:t},f=a)}let b=d+hh[n],k=c+hg[n];if(2!==o&&b>=0&&b<W&&k>=0&&k<J){let t=k*W+b,a=(4*t+n)*3+o;if(i+(Math.abs(y[b]-u)+Math.abs(w[k]-v))<p(a)-1e-9){let l=j(r,t,n,0===o);1/0!==l&&m(a,i+l,e,t,n)}}for(let a=1;a<=3;a+=2){let l=(n+a)%4,s=i+24+x,o=0,r=d,h=c;for(;;){let a=r+hh[l],i=h+hg[l];if(a<0||a>=W||i<0||i>=J)break;let n=Math.abs(y[a]-y[r])+Math.abs(w[i]-w[h]),d=i*W+a,c=(4*d+l)*3;if(Math.min(p(c),p(c+1))<=s+n+1e-9)break;let g=j(h*W+r,d,l,!1);if(1/0===g)break;s+=g,o+=n,r=a,h=i;let u=!t||o>=28;if(m(c+(u?1:2),s,e,d,l),u)break}}}if(!s)return{expansions:v};let x=f,b=[s.port],M=s.state;for(b.push(hu(s.port,(s.port.direction+2)%4,hc(s.port.direction)));M>=0;){b.push(z(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 l=t.at(-2);l&&e&&(.01>Math.abs(l.x-e.x)&&.01>Math.abs(e.x-a.x)||.01>Math.abs(l.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),s=i(!1,1/0,Math.min(12e3,e.limit??12e3));if(h&&(h.remaining-=s.expansions),!s.points)return;let o=hC(s.points);if(!l||!g||g.remaining<=0||0===o)return s.points;let r=i(!0,s.cost+o-1e-6,Math.min(12e3,2*s.expansions,g.remaining));return g.remaining-=r.expansions,r.points??s.points};return(e.wide?void 0:u(n,o,!0))??u(p,o,!0)??u(p,r,!1)}function hC(e){let t=h_(e),a=0;for(let{from:e,to:l}of t.slice(1,-1))Math.abs(l.x-e.x)+Math.abs(l.y-e.y)<28&&(a+=40);return a}function h_(e){return e.slice(1).map((t,a)=>({from:e[a],to:t}))}function hq(e,t,a){let l=e.at(-1),i=e.at(-2),s=Math.min(1,t/Math.max(Math.abs(l.x-i.x)+Math.abs(l.y-i.y),.01)),o={x:l.x+(i.x-l.x)*s,y:l.y+(i.y-l.y)*s};return{left:Math.min(o.x,l.x)-a,right:Math.max(o.x,l.x)+a,top:Math.min(o.y,l.y)-a,bottom:Math.max(o.y,l.y)+a}}let hL=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],hS=(e,t=2)=>String(e).padStart(t,"0");function hB(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:es(t);void 0!==t&&e&&a.set(t,e)}if(0===a.size)return{events:new Map};let l=new Set([...a.values()].flatMap(e=>void 0===e.offsetMinutes?[]:[e.offsetMinutes])),i=1===l.size?[...l][0]??0:0,s=l.size>0?function(e){if(0===e)return"UTC";let t=Math.abs(e);return`UTC${e<0?"-":"+"}${hS(Math.floor(t/60))}:${hS(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],d=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),c=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=>`${hS(e.hour)}:${hS(e.minute)}${p||h?`:${hS(e.second)}`:""}${h?`.${hS(e.millisecond,3)}`:""}`,u=e=>`${hL[e.month-1]} ${e.day}`,f=(e,t)=>{if(d)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`${hL[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(d)return`${f(e,!1)}–${f(t,!1)}`;if(e.year!==t.year)return`${f(e,!0)} – ${f(t,!0)}`;let l=a&&"year"!==t.granularity?`, ${t.year}`:"";return"day"===e.granularity&&"day"===t.granularity&&e.month===t.month?`${u(e)}–${t.day}${l}`:"month"===e.granularity&&"month"===t.granularity?`${hL[e.month-1]} – ${hL[t.month-1]}${a?` ${t.year}`:""}`:`${f(e,!1)} – ${f(t,!1)}${l}`},v=new Map;for(let a of eh(e)){let e=void 0===a.date?void 0:o.get(a.date);if(!e)continue;let l=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,l?m(e,l,i):f(e,i)),t=l??e}let y=d?`${u(n)}, ${n.year}${s?` \xb7 ${s}`:""}`:s?`Times in ${s}`: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,c)}`}:{}}}let hA={millisecond:1,second:1e3,minute:6e4,hour:36e5,day:864e5,month:2629746e3,year:31556952e3},hP=v.ink,hV="#4c4639",hH="#cbbfa9",hI="#c0392b",h$=[12,24];function hF(e,t){let a=[e.left-8,e.right+8];return t?[e.left-15,...a,e.right+15]:a}let hO=[0,-6,6],hE=[-3,3];function hU(e,t){return{text:e,width:Math.ceil(iC(e,t)),height:Math.ceil(e.split("\n").length*t*1.35)}}function hX(e,t,a){let l=hU(e,a);return l.width<=t?l:hU(iS(e,Math.max(1,t),a),a)}function hT(e){return Math.round(100*e)/100}class hR{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,l,i,s,o="left",r={}){let n={left:a,top:l,right:a+t.width,bottom:l+t.height};return this.push({type:"text",id:e,x:hT(a+t.width/2),y:hT(l+t.height/2),text:t.text,fontSize:i,maxWidth:t.width,textAlign:o,textColor:s,...r},"front"),this.textBoxes.push(n),n}line(e,t,a,l="back"){let[i,s,...o]=t.map(e=>({x:hT(e.x),y:hT(e.y)}));this.push({type:"line",id:e,points:[i,s,...o],roughness:0,strokeWidth:1,...a},l)}mark(e,t,a,l,i){this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:"gantt-mark",shape:t,x:hT(a.x),y:hT(a.y),width:hT(hT(a.x+a.width)-hT(a.x)),height:hT(hT(a.y+a.height)-hT(a.y)),label:l,roughness:0,fillStyle:"solid",strokeWidth:1,...i},"middle")}breakRulesUnderText(e,t=this.textBoxes){let a=pU(this.elements,t,e);if(!a.size)return;let l=this.elements.flatMap(e=>a.get(e.id)??[e]);for(let e of(this.elements.splice(0,this.elements.length,...l),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,l=-1/0,i=(i,s,o,r)=>{e=Math.min(e,i),t=Math.min(t,s),a=Math.max(a,o),l=Math.max(l,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??iC(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:l}}}let hY=[7,19,31],hD=[6,16,26];function hG(e,t,a,l,i=[]){let s=(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:s,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:s+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 l=2*a-Math.abs(e-t),i=(e<t?16:6)+3;return[{x:e,y:s+l,direction:1,cost:i+o(1)},{x:e,y:s-l,direction:3,cost:i+o(3)}]})]}let r=hD.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),d=r.length>=3?r.map(t=>e.right-t):n.length?n:[(e.left+e.right)/2],c=void 0!==l&&l>e.left+1&&l<e.right-1?[l]:[],p=i.filter(t=>t>=Math.max(e.left+2,e.right-32)&&t<=e.right-2&&d.every(e=>Math.abs(e-t)>=1));return[...c.flatMap(t=>[{x:t,y:e.bottom,direction:1,cost:o(1)},{x:t,y:e.top,direction:3,cost:o(3)}]),...d.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:s,direction:0,cost:2}]:[],...d.map((t,a)=>({x:t,y:e.top,direction:3,cost:o(3)+3*a}))]}function hZ(e,t=!1){let a=!t&&.01>Math.abs(e.at(-1).y-e.at(-2).y);return hq(e,a?40:12,4.5)}function hj(e){let t=new Set;for(let a of h_(e)){let e=hW(a);if(t.has((e+2)%4))return!0;t.add(e)}return!1}function hN(e,t,a,l=!1){let i=hZ(t,l),s=h_(e),o=h_(t),r=a.leaving&&hk(s[0].from,s[0].to,o[0])?hZ(t,!0):i,n=a.arriving&&function(e,t){let[a,l]=[e.at(-1),t.at(-1)];return .01>Math.hypot(a.x-l.x,a.y-l.y)}(e,t),d=0;return s.forEach((e,t)=>{let l=t===s.length-1;!(n&&l)&&hJ(e,0===t?r:i)&&(d+=1),o.forEach((l,i)=>{!(a.leaving&&0===t&&0===i||a.arriving&&t===s.length-1&&i===o.length-1)&&h0(e.from,e.to,l,2)&&function(e,t){let a=.01>Math.abs(e.from.y-e.to.y),l=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,s]=l(e),[o,r]=l(t);return Math.min(s,r)-Math.max(i,o)}(e,l)>1&&(d+=1)})}),d}function hW({from:e,to:t}){return .01>Math.abs(e.y-t.y)?t.x>e.x?0:2:t.y>e.y?1:3}function hJ(e,t){let{from:a,to:l}=e;return Math.max(a.x,l.x)>t.left&&Math.min(a.x,l.x)<t.right&&Math.max(a.y,l.y)>t.top&&Math.min(a.y,l.y)<t.bottom}function hK(e){return e.replaceAll("%","%25").replaceAll(":","%3A")}let hQ=[2.5,2,.3,.05,0];function h1(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 h0(e,t,a,l){let i=.01>Math.abs(e.y-t.y);if(i!==.01>Math.abs(a.from.y-a.to.y)||(i?Math.abs(e.y-a.from.y):Math.abs(e.x-a.from.x))>=l)return!1;let[s,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(s,r)>0}let h2={forward:!0,clear:!0},h3={forward:!1,clear:!1},h5={forward:!1,clear:!0};function h4(e,t,{forward:a,clear:l}){var i;let s,o,r,n,d,c,p,h,g,u=l?32:24,f=new Map(e.tasks.map(e=>[e.id,tc(e)])),m=th(e),v=void 0===e.today?void 0:tr(e.today),y=[...f.values()],w=Math.min(...y.map(e=>e.start),v??1/0),x=Math.max(...y.map(e=>e.milestone?e.start+1:e.end),void 0===v?-1/0:v+1),b=(s=new Map(e.tasks.map(e=>[e.id,tc(e)])),o=th(e).flatMap((e,t)=>{if(void 0===e.phase)return[];let a=e.tasks.map(e=>s.get(e.id));return[{index:t,name:e.phase,start:Math.min(...a.map(e=>e.start)),end:Math.max(...a.map(e=>Math.max(e.end,e.start+1)))}]}),r=e=>`\0phase:${e}`,n=(e,t,a,l)=>({id:e,label:t,date:tn(a),...l-a>1?{end:tn(l-1)}:{}}),c=hB(d={id:e.id,title:e.title,type:"timeline",events:[...o.map(e=>n(r(e.index),e.name,e.start,e.end)),...e.tasks.map(e=>{let t=s.get(e.id);return n(e.id,e.label,t.start,t.end)})],...e.today?{today:e.today}:{},style:e.style}),p=new Set(d.events.flatMap(e=>[e.date,e.end].flatMap(e=>void 0===e?[]:[e.slice(0,4)]))),h=e=>{if(p.size<2)return c.events.get(e)??"";let t=d.events.find(t=>t.id===e);return hB({...d,events:[t]}).events.get(e)??""},{tasks:new Map(e.tasks.map(e=>{let t=h(e.id);return[e.id,void 0===e.progress?t:`${t} \xb7 ${e.progress}%`]})),phases:new Map(o.map(e=>[e.name,h(r(e.index))])),...c.today?{today:c.today}:{}}),k=(e,a)=>{let l=hX(e.label,260,14);return{task:e,schedule:f.get(e.id),color:a,label:l,caption:hU(b.tasks.get(e.id),12),height:Math.max(t,l.height+16)}},M=[],z=0;m.forEach((e,t)=>{let a=pT[t%pT.length];if(void 0!==e.phase){let a=hX(e.phase,220,15),l=hU(b.phases.get(e.phase),12),i=Math.max(40,a.height+16);M.push({kind:"phase",top:z,height:i,phase:{index:t,name:a,caption:l}}),z+=i}for(let t of e.tasks){let e=k(t,a);M.push({kind:"task",top:z,height:e.height,task:e}),z+=e.height}});let C=z,_=M.filter(e=>"task"===e.kind).length,q=12*!!M.some(e=>"phase"===e.kind),L=Math.max(Math.max(...M.map(e=>e.task?q+e.task.label.width:0))+20+Math.max(...M.map(e=>(e.task?e.task.caption:e.phase.caption).width)),...M.map(e=>e.phase?e.phase.name.width+10+e.phase.caption.width:0)),S=-16-L,B=function(e,t,a=960){let l=Math.max(t,e+1);for(let{unit:t,step:i}of hn){let s="year"===t&&50===i,o=hd(e,l,t,i,e=>(function(e,t,a){let l=ho(e);switch(t){case"day":return String(l.day);case"week":return`${hs[l.month-1]} ${l.day}`;case"month":return hs[l.month-1];case"quarter":return`Q${Math.floor((l.month-1)/3)+1}`;case"year":return 1===a?String(l.year):`${l.year}–${String(l.year+a-1)}`}})(e,t,i),s?1/0:36);if(!o)continue;let r=o[0].start,n=o.at(-1).end,d=Math.min(56,a/(n-r));if(!o.every(e=>iC(e.label,12)+8<=(e.end-e.start)*d)&&!s)continue;let c=("year"===t?[]:"day"===t?hd(r,n,"month",1,e=>`${hs[ho(e).month-1]} ${ho(e).year}`):hd(r,n,"year",1,e=>String(ho(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)*d>=12?(hd(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:d,cells:o,minor:g,bands:c.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")}(w,x,Math.max(640,Math.min(960,2.2*(Math.ceil(27*!!e.title.length)+14+18*(void 0!==v)+44+C+44*(_>=16)+80)-80-L-16-u))),A=Math.max(0,...y.map(e=>e.milestone?15-(e.start+.5-B.start)*B.pxPerDay:0)),P=e=>u+A+(e-B.start)*B.pxPerDay,V=P(B.end),H=new hR,I=[{box:{left:S-32,right:-2,top:0,bottom:C},clearance:0}],$=new Map;for(let e of M){if("phase"!==e.kind)continue;let{index:t,name:a,caption:l}=e.phase,i=e.top+e.height/2,s={groupIds:[`gantt:phase:${t}`]};H.text(`gantt:phase:${t}`,a,S,i-a.height/2,15,hP,"left",s),H.text(`gantt:phase-caption:${t}`,l,-16-l.width,i-l.height/2,12,hV,"right",s)}for(let e of M){if("task"!==e.kind)continue;let{task:t,schedule:a,color:l,label:i,caption:s}=e.task,o=e.top+e.height/2,r=a.milestone?P(a.start+.5)-13:P(a.start),n=a.milestone?P(a.start+.5)+13:Math.max(P(a.end),P(a.start)+2),d=`gantt:task:${t.id}`,c={groupIds:[d]},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};$.set(t.id,h),H.mark(d,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:hP,strokeColor:hP,...c}:{fillColor:l,strokeColor:l,...c});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(hP.slice(t,t+2),16)-a)*.35).toString(16).padStart(2,"0")};return`#${t(1)}${t(3)}${t(5)}`}(l),f=h.left+(h.right-h.left)*g/100;!a.milestone&&f-h.left>=1&&H.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,...c}),H.text(`gantt:label:${t.id}`,i,S+q,o-i.height/2,14,hP,"left",p),H.text(`gantt:caption:${t.id}`,s,-16-s.width,o-s.height/2,12,hV,"right",p)}let F=[...$].filter(([e])=>!f.get(e).milestone),O=new Map(M.flatMap((e,t)=>e.task?[[e.task.task.id,t]]:[])),E=M.slice(1).map(e=>e.top),U=E.flatMap(e=>hO.map(t=>e+t)),X=M.slice(1).flatMap(e=>[...hO,...hE].map(t=>e.top+t)),T=e.tasks.flatMap((e,t)=>(e.dependsOn??[]).map((a,l)=>({from:a,to:e.id,taskIndex:t,order:l}))).toSorted((e,t)=>Math.abs(O.get(e.to)-O.get(e.from))-Math.abs(O.get(t.to)-O.get(t.from))||O.get(e.to)-O.get(t.to)||O.get(e.from)-O.get(t.from)||e.taskIndex-t.taskIndex||e.order-t.order),R=void 0===v?void 0:P(v+.5),Y=void 0===R?[]:[{from:{x:R,y:0},to:{x:R,y:C}}],D=T.map(()=>void 0),G=[...Y],Z=new Map,j=new Map,N=new Map,W=[],J=[],K=new Set,Q=new Set,ee=new Map,et=new Set,ea=Math.min(16e4,Math.max(12e3,6e3*T.length)),el={remaining:ea},ei=Math.min(48e3,1500*T.length),es={remaining:ei},eo=Math.min(24e3,1e3*T.length),er={remaining:eo},en=0,ed=0,ec=new WeakSet,ep=new Map;for(let{from:e,to:t}of T)ep.set(e,(ep.get(e)??new Set).add(O.get(t)>O.get(e)?1:3));let eh=(e,t)=>{let a=h_(t);G.push(...a),K.add(a.at(-1)),Q.add(a[0]),j.set(e.from,[...j.get(e.from)??[],...a]),N.set(e.to,[...N.get(e.to)??[],...a]);let l={box:hZ(t,!0),clearance:0};W.push({from:e.from,trunk:a[0],keepOut:{box:hZ(t),clearance:0},arrowhead:l}),J.push({from:e.from,trunk:a[0],keepOut:{box:hq(t,.01>Math.abs(t.at(-1).y-t.at(-2).y)?40:12,6),clearance:0},arrowhead:l}),ee.set(e.to,ee.get(e.to)-1),Z.set(e.to,[...Z.get(e.to)??[],t.at(-1)])},eg=()=>{for(let e of(G.splice(0,G.length,...Y),[Z,j,N,ee]))e.clear();for(let e of(W.length=0,J.length=0,K.clear(),Q.clear(),T))ee.set(e.to,(ee.get(e.to)??0)+1);T.forEach((e,t)=>{let a=D[t];a&&eh(e,a)})};eg();let eu=(e,t=el)=>{var i;let s,o,r,n;en+=1;let d=Math.min(12e3,t.remaining),c={remaining:d},p=$.get(e.from),h=$.get(e.to),g=f.get(e.from).milestone,u=f.get(e.to).milestone,m=O.get(e.to)>O.get(e.from),v=e=>(e.left+e.right)/2,y=t=>(O.get(t)-O.get(e.from))*(O.get(e.to)-O.get(t))>0,w=Z.get(e.to)??[],x=function(e,t,a,l=[],i=!1){let s=(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,n=l=>(e.bottom-e.top)/2*(1-Math.abs(l-t)/(2*a)),d=l.filter(e=>Math.abs(e-t)>=1&&Math.abs(e-t)<=2*a-4),c=e=>24+6*(Math.abs(e-t)>a);return[{x:e.left,y:s,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:s+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)},...d.flatMap(e=>[{x:e,y:s-n(e),direction:1,cost:c(e)+o(1)},{x:e,y:s+n(e),direction:3,cost:c(e)+o(3)}])]}let n=hY.filter(t=>e.left+t<=e.right-3),d=n.length?n.map(t=>e.left+t):[(e.left+e.right)/2],c=l.filter(t=>t>e.left+1&&t<e.right-1);return[{x:e.left,y:s,direction:0,cost:24*!!i},...[-1,1].map(t=>({x:e.left,y:s+7*t,direction:0,cost:i?r(t):24})),...c.flatMap(t=>[{x:t,y:e.top,direction:1,cost:o(1)},{x:t,y:e.bottom,direction:3,cost:o(3)}]),...d.map((t,a)=>({x:t,y:e.top,direction:1,cost:20+o(1)+3*a})),...d.map((t,a)=>({x:t,y:e.bottom,direction:3,cost:20+o(3)+3*a}))]}(h,u,m,u?[...g?[v(p)]:[],...[...$].flatMap(([e,t])=>a&&y(e)?hF(t,a):[])]:g?[v(p)]:p.right-p.left>=8&&p.right+8<=h.left+hY.at(-1)?[p.right+8]:[],(ee.get(e.to)>1||w.length>0)&&(!u||et.has(e.to))),b=e=>void 0===R||(e.direction%2==0?R<e.x-16-5||R>e.x+5:Math.abs(e.x-R)>=5),k=(e,t)=>w.every(a=>Math.hypot(a.x-e.x,a.y-e.y)>=t),z=e=>{let t=hc(e.direction),a=hq([{x:e.x-(0===e.direction?t:0),y:e.y-(1===e.direction?t:3===e.direction?-t:0)},e],t,6);return!G.some(e=>hJ(e,a))},_=[...ep.get(e.to)??[]].flatMap(e=>hG(h,u,1===e).find(t=>t.direction===e)??[]),q=e=>{if(e.direction%2==0){let t=hZ([{x:e.x-16,y:e.y},e]);return _.every(e=>!hJ({from:e,to:{x:e.x,y:e.y+(1===e.direction?1:-1)*8}},t))}return _.every(t=>t.direction!==(e.direction+2)%4||Math.abs(t.x-e.x)>=8)},L=function(e,t,a){let l=(e.top+e.bottom)/2,i=(e.left+e.right)/2,s=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,s)=>l+s*a*(1-Math.abs(e-i)/t);return[...o(e.top+3,e.bottom-3).map(e=>({x:i-t*(1-Math.abs(e-l)/a),y:e,direction:0,cost:30})),...o(e.left+3,i).flatMap(e=>[{x:e,y:r(e,-1),direction:1,cost:40+s(1)},{x:e,y:r(e,1),direction:3,cost:40+s(3)}])]}return[...o(e.top+3,e.bottom-3).map(t=>({x:e.left,y:t,direction:0,cost:30+Math.abs(t-l)})),...o(e.left+3,e.right-3).flatMap(t=>[{x:t,y:e.top,direction:1,cost:40+s(1)+(t-e.left)/4},{x:t,y:e.bottom,direction:3,cost:40+s(3)+(t-e.left)/4}])]}(h,u,m),S=[[x,e=>b(e)&&k(e,11)&&z(e)&&q(e)],[x,e=>b(e)&&k(e,6)&&z(e)&&q(e)],[L,e=>b(e)&&k(e,3)&&z(e)&&q(e)],[x,e=>b(e)&&k(e,1)&&z(e)],[x,e=>k(e,1)&&z(e)],[L,e=>k(e,1)&&z(e)]].map(([e,t])=>e.filter(t)).find(e=>e.length>0)??x,B=g?v(p)-(p.right-p.left)/4:Math.max(p.left+2,p.right-hD.at(-1)),A=(N.get(e.to)??[]).filter(e=>{let t=hW(e);return K.has(e)&&e.from.x>=B-.5&&(t%2==0||1===t===m)}),P=(j.get(e.from)??[]).filter(e=>Q.has(e)),V=new Map(P.map(e=>{let t=hW(e),a=t%2==1&&1===t!==m;return[`${e.from.x},${e.from.y},${t}`,{...e.from,direction:t,cost:40*!!a}]})),H=[...[...$].flatMap(([t,a])=>{let l,i,s,o,r,n;return t!==e.from&&t!==e.to?[{box:a,clearance:4,sideClearance:8}]:f.get(t).milestone?[{box:(l=(a.right-a.left)/4,i=(a.bottom-a.top)/4,{left:a.left+l,right:a.right-l,top:a.top+i,bottom:a.bottom-i}),clearance:3,own:!0},...(s=(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:s-n,bottom:s+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}]}),...I],T={sources:[...V.values(),...g||p.right-p.left<8?[]:(u?[v(h)]:hY.some(e=>h.left+e<=h.right-3)?hY.filter(e=>h.left+e<=h.right-3).map(e=>h.left+e):[v(h)]).filter(e=>e-p.right>=3&&e-p.right<8).map(e=>({x:p.right,y:(p.top+p.bottom)/2,direction:0,cost:2,lead:e-p.right})),...hG(p,g,m,u?v(h):void 0,[...u?[h.left-19,h.left+(h.right-h.left)/4-19]:[h.left-19,...hY.filter(e=>h.left+e<=h.right-3).map(e=>h.left+e)],...[...$].flatMap(([t,l])=>t===e.from||t===e.to?[]:hF(l,a))])],targets:S,obstacles:[...H,...J.map(t=>t.from===e.from?t.arrowhead:t.keepOut),...[...ee.keys()].flatMap(t=>t===e.to?[]:(e=>{let t=ee.get(e)??0;if(t<=0)return[];let a=$.get(e),l=(a.top+a.bottom)/2,i=(a.right-a.left)/4,s=f.get(e).milestone,o=s?[{x:a.left,y:l},{x:a.left+i,y:l-i},{x:a.left+i,y:l+i}]:[0,-7,7].map(e=>({x:a.left,y:l+e})),r=Z.get(e)??[],[n,...d]=o;return(t+r.length>1?[...d,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*!!s,top:e.y-6,bottom:e.y+6}))})(t).map(e=>({box:e,clearance:0})))],behind:Math.min(p.left,h.left-16-8-5)-16,lanes:U,denseLanes:X,routed:G,kin:new Set([...j.get(e.from)??[],...N.get(e.to)??[]]),lastRuns:K,trunks:new Set(P),pastTrunk:new Map(J.flatMap(t=>t.from===e.from?[[t.keepOut,t.trunk]]:[])),edges:F.flatMap(([t,a])=>t===e.from||t===e.to?[]:[a]),...a?{sides:F.flatMap(([t,a])=>t===e.from||t===e.to?[]:[a]),besides:F.flatMap(([e,t])=>y(e)?[t]:[])}:{},top:1,bottom:C-1,budget:c,kinkBudget:es},Y=t=>hz(t)??hz({...t,obstacles:[...H,...W.map(t=>t.from===e.from?t.arrowhead:t.keepOut)],pastTrunk:new Map(W.flatMap(t=>t.from===e.from?[[t.keepOut,t.trunk]]:[]))}),D=Y(T),ea=(t,a)=>[...$].every(([l,i])=>l===e.from||l===e.to||t<=i.left-8||t>=i.right+8||(m?i.top-4>=a||i.bottom<=p.bottom:i.bottom+4<=a||i.top>=p.top)),ei=[...hG(p,g,m).map(e=>e.x),p.right+8,...[...$].flatMap(([,e])=>hF(e,a))],eo=a&&D&&hj(D)?A.flatMap(e=>(function(e,t){let a=hW(e),l=t=>Math.abs(e.to.x-t.x)+Math.abs(e.to.y-t.y),i=[{...e.from,direction:a,cost:48+l(e.from)}];if(a%2==0)return i;for(let a of t){let t={x:e.from.x,y:a};if((a-e.from.y)*(e.to.y-a)<=0||5>Math.abs(a-e.from.y)||23>l(t))continue;let s=48+l(t);i.push({...t,direction:0,cost:s},{...t,direction:2,cost:s})}return i})(e,E).filter(t=>(({x:e,y:t,direction:a})=>a%2==1?e>=B-.5&&ea(e,t):ei.some(l=>l>=B-.5&&l<=p.right+8+.5&&(0===a?l<=e-16:l>=e+16)&&ea(l,t)))(t)&&!G.some(a=>a!==e&&!(K.has(a)&&.01>Math.hypot(a.to.x-e.to.x,a.to.y-e.to.y))&&h0(t,e.to,a,5)))):[];if(eo.length>0&&er.remaining>0){let e=Math.min(1e3,er.remaining),t={remaining:e};s=Y({...T,targets:[...S,...eo],joins:new Set(A),budget:t,limit:e,kinkBudget:{remaining:0}}),er.remaining-=e-t.remaining}let eh=s&&(o=(i=s).at(-1),r=(e,t,a)=>e>=Math.min(t,a)-.01&&e<=Math.max(t,a)+.01,(n=A.find(({from:e,to:t})=>Math.hypot(t.x-o.x,t.y-o.y)>1&&r(o.x,e.x,t.x)&&r(o.y,e.y,t.y)))?hk(i.at(-2),o,n)?[...i.slice(0,-1),n.to]:[...i,n.to]:i),eg=eh&&!hj(eh)?eh:D,eu=eg&&(a?(t=>{if(t.length<4||ee.get(e.to)>1||!hj(t))return t;let[a,l,i]=t.slice(-3);if(Math.abs(l.x-i.x)>=.01||Math.abs(a.y-l.y)>=.01||l.x>=a.x-.01)return t;let s=i.y>l.y?1:3;for(let e of S.filter(e=>e.direction===s&&.01>Math.abs(e.y-i.y)&&e.x<i.x-1).toSorted((e,t)=>e.x-t.x)){if(er.remaining<=0)break;let l=Math.min(1e3,er.remaining),i={remaining:l},s=hz({...T,sources:[{...a,direction:2,cost:0}],targets:[e],budget:i,limit:l,kinkBudget:{remaining:0}});if(er.remaining-=l-i.remaining,s?.length===3&&.01>Math.abs(s[1].y-a.y))return[...t.slice(0,-2),s[1],e]}return t})(eg):eg);if(t.remaining-=d-c.remaining,eu)return eu;ed+=1;let ef=function(e){let{source:t,target:a,routed:l}=e,i=e.heads.map(({box:e})=>e),s=l.filter(e=>.01>Math.abs(e.from.y-e.to.y)),o=l.filter(e=>Math.abs(e.from.y-e.to.y)>=.01),r=([t,a,l])=>{let r=.01>Math.abs(t.y-a.y),n=r?t.y:t.x,d=r?Math.min(t.x,a.x):Math.min(t.y,a.y),c=r?Math.max(t.x,a.x):Math.max(t.y,a.y),p=1/0;for(let t of r?s:o){if(l&&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(c,r?Math.max(t.from.x,t.to.x):Math.max(t.from.y,t.to.y))-Math.max(d,i)>0&&(p=a)}let h=hQ.findIndex(e=>p>=e);return i.some(e=>hJ({from:t,to:a},e))?Math.max(h,3):h},n=(e,t,a=()=>!0)=>{let l;for(let i of e){let e=t(i).map(e=>r(e)),s=100*Math.max(...e,+!a(i))+e.reduce((e,t)=>e+t,0);if((!l||s<l.score)&&(l={candidate:i,score:s}),0===s)break}return l.candidate},d=(t.left+t.right)/2,c=(t.right-t.left)/2,p=a=>e.sourceMilestone?h1(d,c-4,.5).map(e=>({x:e,y:(1===a?t.bottom:t.top)-a*Math.abs(e-d)})):h1(Math.max(d,t.right-6),Math.min(2*c,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=>[...h1(e,8),...h1(e,8,.5),...h1(e+.1,8,.1)],g=(t,a)=>e.marks.every(e=>e.right<=1.5||e.left>=a||t<=e.top-4||t>=e.bottom+4),u=h(e.sourceRow.top+e.sourceRow.height).filter(a=>a>=t.bottom+2&&a<=e.rowsBottom-1),f=h(e.sourceRow.top).filter(a=>a<=t.top-2&&a>=e.rowsTop+1),m=e=>[...p(1).map(t=>[t,u.filter(a=>!e||g(a,t.x))]),...p(-1).map(t=>[t,f.filter(a=>!e||g(a,t.x))])].filter(([,e])=>e.length>0),v=m(!0),[y,w]=n(v.length>0?v:m(!1),([e,t])=>[[e,{x:e.x,y:t[0]},!0],[{x:e.x,y:t[0]},{x:12,y:t[0]}]]),x=n(w,e=>[[y,{x:y.x,y:e},!0],[{x:y.x,y:e},{x:12,y:e}]]),b=(a.top+a.bottom)/2,k=(a.bottom-a.top)/2,M=(a.right-a.left)/(a.bottom-a.top),z=n(h1(b,k-(e.targetMilestone?4:3)).map(t=>({x:e.targetMilestone?a.left+Math.abs(t-b)*M:a.left,y:t})),e=>[[{x:12,y:e.y},e]],t=>{let a=hq([{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)&&!l.some(e=>hJ(e,a))}),C=10.5,_=n([...h1(12,10.5,.5),...h1(12.1,C-.1,.1)],e=>[[{x:y.x,y:x},{x:e,y:x}],[{x:e,y:x},{x:e,y:z.y}],[{x:e,y:z.y},z]]);return[y,{x:y.x,y:x},{x:_,y:x},{x:_,y:z.y},z]}({marks:l?[...$].flatMap(([t,a])=>t===e.from||t===e.to?[]:[a]):[],source:p,sourceMilestone:g,sourceRow:M[O.get(e.from)],target:h,targetMilestone:u,rowsTop:0,rowsBottom:C,routed:G,heads:W.map(e=>e.keepOut),taken:w,siblings:new Set(P)});return ec.add(ef),ef};T.forEach((e,t)=>{let a=eu(e);D[t]=a,eh(e,a)});let ef=(e,t)=>({leaving:T[e].from===T[t].from,arriving:T[e].to===T[t].to}),em=e=>{let t=D[e],a=0;return D.forEach((l,i)=>{if(i===e||!l)return;let s=ef(e,i);a+=hN(t,l,s)+hN(l,t,s)}),a},ev=new Map;T.forEach((e,t)=>ev.set(e.to,[...ev.get(e.to)??[],t]));let ey=e=>h_(e).reduce((e,{from:t,to:a})=>e+Math.abs(a.x-t.x)+Math.abs(a.y-t.y),0),ew=e=>{let t=h_(D[e]),a=0;return D.forEach((l,i)=>{if(i!==e&&l)for(let e of h_(l))for(let l 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[l,i]=a(e)?[e,t]:[t,e],s=i.from.x,o=l.from.y;return s>Math.min(l.from.x,l.to.x)+.01&&s<Math.max(l.from.x,l.to.x)-.01&&o>Math.min(i.from.y,i.to.y)+.01&&o<Math.max(i.from.y,i.to.y)-.01})(l,e)&&(a+=1)}),a},ex=e=>({conflicts:e.reduce((e,t)=>e+em(t),0),drawn:e.reduce((e,t)=>{let a=D[t];return e+ey(a)+24*(a.length-2)+hC(a)+60*ew(t)},0)}),eb=(e,t)=>e.conflicts<t.conflicts||e.conflicts===t.conflicts&&e.drawn<t.drawn-1e-6,ek=e=>e.some(e=>em(e)>0||ew(e)>0)||e.reduce((e,t)=>{let a=D[t],[l,i]=[a[0],a.at(-1)];return e+ey(a)-Math.abs(i.x-l.x)-Math.abs(i.y-l.y)},0)>60;for(let[e,t]of ev){if(t.length<2||!ek(t))continue;let a=[{order:t.toReversed(),split:!1},...f.get(e).milestone?[{order:t,split:!0}]:[]],l={routes:t.map(e=>D[e]),standing:ex(t),split:!1};for(let i of a){if(el.remaining<=0||i.split&&(t.forEach((e,t)=>D[e]=l.routes[t]),!t.some(e=>ew(e)>0||hC(D[e])>0)))break;for(let e of t)D[e]=void 0;for(let t of(eg(),i.split&&et.add(e),i.order)){let e=eu(T[t]);D[t]=e,eh(T[t],e)}et.delete(e);let a=ex(t);eb(a,l.standing)&&(l={routes:t.map(e=>D[e]),standing:a,split:i.split})}t.forEach((e,t)=>D[e]=l.routes[t]),l.split&&et.add(e),eg()}let eM={remaining:48e3},ez=0,eC=e=>{if(ez>=2*T.length)return;ez+=1;let t=D[e];D[e]=void 0,eg();let a=eu(T[e],eM);return D[e]=t,eg(),a},e_=(e,t)=>{let a,l=[e,t],i=ex(l);for(let e of l){let t=eC(e);if(!t)continue;let s=D[e];D[e]=t,eg();let o=ex(l);o.conflicts<i.conflicts&&eb(o,i)&&(i=o,a={index:e,points:t}),D[e]=s,eg()}return!!a&&(D[a.index]=a.points,eq[a.index]=eq[a.index]+1,eg(),!0)},eq=T.map(()=>0),eL=new Set;for(let e=0;e<2;e+=1){let e=!1;if(D.forEach((t,a)=>{D.forEach((t,l)=>{let i=D[a];if(l===a||!i||!t||0===hN(i,t,ef(a,l)))return;let s=`${a}.${eq[a]}:${l}.${eq[l]}`;!eL.has(s)&&(eL.add(s),e_(a,l)&&(e=!0))})}),!e)break}for(let e of T.map((e,t)=>({id:`gantt:dependency:${hK(e.from)}:${hK(e.to)}`,...e,points:D[t]})).map(e=>{let[t,...a]=(function(e){var t;let a,l,i=e.at(-1),s=e.at(-2),o=Math.abs(i.x-s.x)+Math.abs(i.y-s.y),r=(a=(t=e).at(-1),l=t.at(-2),.01>Math.abs(a.y-l.y)?16:12);if(o<=r+1)return[...e];let n=r/o;return[...e.slice(0,-1),{x:i.x+(s.x-i.x)*n,y:i.y+(s.y-i.y)*n},i]})(e.points).map(e=>({x:hT(e.x),y:hT(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"}}))H.push(e,"front");let eS=e=>{let t="top"===e?"":"-bottom",a="top"===e?-22:C,l="top"===e?a-22:a+22;B.cells.forEach((e,l)=>{let i=hU(e.label,12);H.text(`gantt:tick${t}:${l}`,i,(P(e.start)+P(e.end))/2-i.width/2,a+(22-i.height)/2,12,hV,"center")}),B.bands.forEach((e,a)=>{let i,s=P(e.end)-P(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=>hU(e,13)).find(e=>e.width<=s);o&&H.text(`gantt:band${t}:${a}`,o,(P(e.start)+P(e.end))/2-o.width/2,l+(22-o.height)/2,13,hP,"center"),a>0&&H.line(`gantt:band-edge${t}:${a}`,[{x:P(e.start),y:l+3},{x:P(e.start),y:l+22-3}],{strokeColor:hH})}),H.line(`gantt:axis${t}`,[{x:P(B.start),y:"top"===e?0:C},{x:V,y:"top"===e?0:C}],{strokeColor:"#8c826f"})},eB=(g=H.elements.length,eS("top"),H.elements.length-g),eA=-44;if(void 0!==R){let e=hU(b.today??"Today",12);eA-=18,H.text("gantt:today-label",e,Math.min(Math.max(R-e.width/2,P(B.start)),Math.max(P(B.start),V-e.width)),eA+(18-e.height)/2,12,hI,"center")}let eP=hX(e.title,Math.max(V-S,360),20);H.text("gantt:title",eP,S,eA-14-eP.height,20,hP,"left");let eV=new Set([B.start,B.end,...B.bands.map(e=>e.start)]),eH=[...B.cells.map(e=>e.start),B.end],eI=_>=16,e$=[!0,!1].flatMap(e=>[{grid:eH,minor:!0,bottom:eI},{grid:eH,minor:!1,bottom:eI},{grid:eH,minor:!1,bottom:!1},{grid:eH.filter(e=>eV.has(e)),minor:!1,bottom:eI},{grid:eH.filter(e=>eV.has(e)),minor:!1,bottom:!1},{grid:[B.start,B.end],minor:!1,bottom:!1}].map(t=>({...t,rowRules:e}))),eF=e=>{let t=e.bottom?C+22:C,a=(e,t,a,l,i)=>({type:"line",id:e,points:[{x:hT(t),y:hT(a)},{x:hT(t),y:hT(l)}],roughness:0,strokeWidth:1,...i});return[...e.rowRules?[...M.slice(1).map(e=>e.top),C].map((e,t)=>({type:"line",id:`gantt:row-rule:${t}`,points:[{x:hT(S),y:hT(e)},{x:hT(V),y:hT(e)}],roughness:0,strokeWidth:1,strokeColor:"#ebe4d8"})):[],...e.minor?B.minor.map(e=>a(`gantt:minor:${tn(e)}`,P(e),0,C,{strokeColor:"#f0ebe1"})):[],...e.grid.map(e=>a(`gantt:grid:${tn(e)}`,P(e),-22,t,{strokeColor:eV.has(e)?hH:"#e6dfd2"})),...void 0===R?[]:[a("gantt:today",R,eA+18,t,{strokeColor:hI,strokeStyle:"dashed"})]]},eO=[...$.values()].map(e=>({left:e.left-5,right:e.right+5,top:e.top-1,bottom:e.bottom+1})),eE=e=>e?[...H.textBoxes,...eO]:H.textBoxes,eU=e=>"gantt:today"===e,[eX,eT]=[!0,!1].flatMap(e=>e$.map(t=>[t,e])).find(([e,t])=>{let a=eF(e),l=new Map([...pU(a,H.textBoxes,e=>!eU(e)),...pU(a,eE(t),eU)]),i=a.reduce((e,t)=>e+(l.get(t.id)?.length??1),0);return H.elements.length+i+(e.bottom?eB:0)<=iB.maxElements})??[e$.at(-1),!1];for(let e of(eX.bottom&&eS("bottom"),eF(eX)))H.push(e,"gantt:today"===e.id?"middle":"back");H.breakRulesUnderText(e=>e.startsWith("gantt:grid:")||e.startsWith("gantt:minor:")||e.startsWith("gantt:row-rule:")||e.startsWith("gantt:axis")||e.startsWith("gantt:band-edge")),H.breakRulesUnderText(eU,eE(eT));let eR=H.bounds(),eY=40-eR.left,eD=40-eR.top,eG=e=>({x:hT(e.x+eY),y:hT(e.y+eD)}),eZ=H.elements.map(e=>{if("line"===e.type){let[t,a,...l]=e.points.map(eG);return{...e,points:[t,a,...l]}}if("arrow"===e.type){let[t,...a]=e.points.map(eG);return{...e,points:[t,...a]}}return{...e,x:hT(e.x+eY),y:hT(e.y+eD)}}),ej=D.reduce((e,t,a)=>e+D.reduce((e,l,i)=>i===a?e:e+hN(t,l,ef(a,i),!0),0),0);return{scene:{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:Math.ceil(eR.right-eR.left+80),height:Math.ceil(eR.bottom-eR.top+80),accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:eZ,layers:[],layouts:[],zOrder:H.zOrder()},crossings:D.reduce((e,t,a)=>e+ew(a),0)/2,findings:function(e,t,a,l){let[i,s,o,r,n]=[0,0,0,0,0];for(let{from:a,to:d,points:c}of e){l.has(c)&&(n+=1),hj(c)&&(i+=1);let e=h_(c),p=e.map(({from:e,to:t})=>Math.abs(t.x-e.x)+Math.abs(t.y-e.y)),h=p.reduce((e,t)=>e+t,0),g=p[0]??0;for(let t=1;t<e.length-1;t+=1){let e=p[t];(g<=46||h-g-e<=46)&&e<40?o+=1:e<28&&(s+=1),g+=e}for(let{from:l,to:i}of e)if(!(Math.abs(l.x-i.x)>=.01))for(let[e,s]of t)e!==a&&e!==d&&14.99>Math.min(Math.abs(l.x-s.left),Math.abs(l.x-s.right))&&Math.min(Math.max(l.y,i.y),s.bottom)-Math.max(Math.min(l.y,i.y),s.top)>1&&(r+=1)}return{conflicts:a,fallbacks:n,detours:i,kinks:s,jogs:o,traces:r}}(D.map((e,t)=>({...T[t],points:e})),F,ej,ec),clear:(i=D.map((e,t)=>({...T[t],points:e})),i.every(({from:e,to:t,points:a})=>h_(a).every(({from:a,to:l})=>{let i=.01>Math.abs(a.x-l.x);return[...$].every(([s,o])=>!!(s===e||s===t||(i?Math.min(Math.max(a.y,l.y),o.bottom)-Math.max(Math.min(a.y,l.y),o.top):Math.min(Math.max(a.x,l.x),o.right)-Math.max(Math.min(a.x,l.x),o.left))<=1)||(i?Math.max(o.left-a.x,a.x-o.right):Math.max(o.top-a.y,a.y-o.bottom))>=(i?8:4)-.02)}))),work:{layouts:1,placements:en,expansions:ea-el.remaining+48e3-eM.remaining+ei-es.remaining+eo-er.remaining,corridors:ed,conflicts:ej}}}let h6="timeline-marker",h7=22,h8=6,h9="#4c4639",ge="#c0392b",gt=[{stroke:"",ink:"#6a4e5c",wash:"#efe6ec"},{stroke:"#1f44c9",ink:"#1a39a8",wash:"#e6eafb"},{stroke:"#1c7a4d",ink:"#15613c",wash:"#def0e5"},{stroke:"#9a6a1f",ink:"#7a5216",wash:"#f6e8cf"}];function ga(e,t,a,l){let i=function(e,t){let a=e=>e.split("\n").length,l=iS(e,200,t);if(1===a(l))return l;let i=t,s=200;for(;s-i>1;){let o=Math.floor((i+s)/2);a(iS(e,o,t))<=a(l)?s=o:i=o}return iS(e,s,t)}(t,a);return{id:e,text:i,fontSize:a,color:l,width:Math.ceil(Math.max(iC(i,a),i_(i,a,200))),height:Math.ceil(i.split("\n").length*a*1.35)}}let gl=[{lookahead:!0,coverPenalty:0},{lookahead:!0,coverPenalty:80},{lookahead:!1,coverPenalty:0},{lookahead:!1,coverPenalty:240}];function gi(e){return e.span?6:("milestone"===e.event.kind?18:12)/2}let gs=[{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 go(e){return gs[Math.min(e,gs.length-1)]}function gr(e,t,a){return{x0:e.x0+t,x1:e.x1+t,y0:e.y0+a,y1:e.y1+a}}function gn(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 gd(e,t){return 1===e.places.size&&1===t.places.size?14:28}function gc(e,t=0){return e.reduce((a,l,i)=>a+(l.bottom-l.top)+(0===i?0:gd(e[i-1],l)+t),0)}function gp(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 gh(e){return Math.round(100*e)/100}function gg(e){let[t,,,a]=e;return .5>Math.abs(a.y-t.y)?[{x:gh(t.x),y:gh(t.y)},{x:gh(a.x),y:gh(a.y)}]:iy(e)}function gu(e,t){return{x:1===t?e.x:e.x+e.width,y:e.y+e.height/2}}let gf={circle:24,bucket:28,cylinder:28,diamond:20,document:28,ellipse:24,pipe:28,polygon:28,rectangle:28},gm={database:"cylinder",queue:"pipe",document:"document",storage:"bucket"},gv=20*Math.PI/180;function gy(e,t){let a=iL(e,t),l=a.split("\n"),i=iC(a,14),s=Math.ceil(14*l.length*1.35),o=Math.ceil(i+36),r=Math.ceil(s+28);return{text:a,textHeight:s,textWidth:i,width:o,height:r}}function gw(e,t,a){let l=2*iA.boundTextPadding,i="diamond"===e?2:"ellipse"===e||"circle"===e?Math.SQRT2:1,s=Math.ceil((t+l)*i),o=Math.ceil((a+l)*i);for(;iQ({height:o,shape:e,width:s}).width<t;)s+=1;for(;iQ({height:o,shape:e,width:s}).height<a;)o+=1;return{width:s,height:o}}let gx={bucket:220,circle:260,cylinder:264,diamond:240,document:264,ellipse:260,pipe:240,polygon:264,rectangle:264};function gb(e){return Math.floor(100*e/12)}function gk(e,t){let a=gb(("diamond"===t?744:1116)*14/100),l=gb(gx[t]),i=e=>e.split("\n").length,s=iL(e,a);for(let o=a;i(s)>("diamond"===t||"ellipse"===t||"circle"===t?1:2)&&o<l;)s=iL(e,o=Math.min(l,o+62));let o=i(s);return{text:s,lines:o,width:iC(s,12),height:Math.ceil(12*o*1.25)}}let gM={initial:20,final:28};function gz(e,t){let a=Math.max(e.width,e.height,t);return{...e,width:a,height:a}}function gC(e){return void 0===e.kind?void 0:gM[e.kind]}function g_(e){return"decision"===e||"choice"===e}function gq(e,t=184,a=1116){let l=function(e){if(void 0!==e.shape)return gm[e.shape];let t=e.kind?.toLowerCase();return"start"===t||"end"===t?"ellipse":"initial"===t||"final"===t?"circle":g_(t)?"diamond":"rectangle"}(e),i=gC(e);if(void 0!==i||"choice"===e.kind&&!e.label){let t=i??44;return{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},shape:l,x:0,y:0,width:t,height:t,label:""}}let s="diamond"===l?744:a,o=gy(e.label,s),r=e.icon?{slug:e.icon.slug,size:gf[l]}:void 0,n=iV(l)?iH[l]:0,d="diamond"===l?32:"ellipse"===l?20:"pipe"===l?4*n:0,c="diamond"===l?32:"cylinder"===l||"document"===l||"bucket"===l?3*n:0,[p,h]="state"===e.kind?[136,56]:[t,72];if(e.description){let t=gk(e.description,l),a=gy(e.label,Math.max(s,Math.floor(100*t.width/14))),i=Math.max(a.textWidth,t.width),o=gw(l,i,a.textHeight+2*Math.max(i1(r),2+t.height+4));return{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},...r?{icon:r}:{},shape:l,x:0,y:0,width:Math.max(p,Math.ceil(i+36)+d,o.width),height:Math.max(h,o.height),label:a.text}}let g=r||"diamond"===l||n>0?gw(l,o.textWidth,o.textHeight+i1(r)):{height:0,width:0};return{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},...r?{icon:r}:{},shape:l,x:0,y:0,width:Math.max(p,o.width+d,g.width),height:r?Math.max(h,g.height):Math.max(h,o.height+c,g.height),label:o.text}}function gL(e){let t=new Map,a=new Map;for(let l of e)t.set(l.target,[...t.get(l.target)??[],l]),a.set(l.source,[...a.get(l.source)??[],l]);return{incoming:t,outgoing:a}}function gS(e){return new Map(e.map((e,t)=>[e.id,t]))}function gB(e,t,a){let l=new Map,i=new Set;function s(e){for(let t of(l.set(e,"visiting"),a.get(e)??[])){let e=l.get(t.target);if("visiting"===e){i.add(t.id);continue}e||s(t.target)}l.set(e,"visited")}let o=e.nodes.find(e=>0===(t.get(e.id)??[]).length)??e.nodes[0];for(let t of(o&&s(o.id),e.nodes))l.has(t.id)||s(t.id);return i}let gA=new WeakMap;function gP(e){let t=gA.get(e);if(t||(gY(e),t=gA.get(e)))return t;let a=gL(e.edges);return t=gB(e,a.incoming,a.outgoing),gA.set(e,t),t}let gV=new WeakMap,gH="\0group:",gI=sI.height,g$=sI.labelInset,gF=sV.fontSize;function gO(e){return e.logoBox?[e.labelBox,e.logoBox]:[e.labelBox]}function gE(e){return e.icon?{slug:e.icon.slug,size:sH.size}:void 0}function gU(e,t){let a=[];for(let l=t;void 0!==l;l=e.parentOf.get(l))a.push(l);return a}function gX(e,t,a){let l=new Set(gU(e,e.groupOf.get(a)));return gU(e,e.groupOf.get(t)).find(e=>l.has(e))}let gT=new WeakMap;function gR(e){return`${gH}${e}`}function gY(e){let t=gT.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]])),l=new Set;for(let t of e.nodes)for(let e=t.group;void 0!==e&&!l.has(e);e=a.get(e))l.add(e);let i=(e.groups??[]).filter(e=>l.has(e.id));if(0===i.length)return void gT.set(e,null);let s=new Set(i.map(e=>e.id)),o=new Map([...a].filter(([e,t])=>s.has(e)&&s.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&&s.has(e.group)?[[e.id,e.group]]:[])),d=new Set(e.nodes.map(e=>e.id)),c=new Set(e.edges.flatMap(e=>[e.source,e.target].filter(e=>!d.has(e)&&s.has(e)))),p=e=>{let t=[];for(let a=c.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),l=void 0===e?a.length:a.indexOf(e);if(!(l<0||0===l&&c.has(t)))return 0===l?t:gR(a[l-1])},g=(e,t)=>({id:t,label:e.label,kind:"process",metadata:{}}),u=gL(e.edges),f=gB(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),l=e.edges.flatMap(e=>{let[a,l]=[h(t.id,e.source),h(t.id,e.target)];return void 0===a||void 0===l||a===l&&a!==e.source?[]:[a===e.source&&l===e.target?e:{...e,source:a,target:l}]}),s=[];for(let l of e.nodes){let e=h(t.id,l.id);if(void 0===e||s.some(t=>t.id===e))continue;let i=a.find(t=>gR(t.id)===e);s.push(i?g(i,e):l)}let n={...e,groups:[],nodes:s,edges:l},d={...n,layout:{...e.layout,direction:gK[e.layout.direction]}},c=new Set(l.flatMap(e=>f.has(e.id)?[e.id]:[]));if(a.length>0){let e={...n,edges:l.filter(e=>!c.has(e.id))},t=gL(e.edges);for(let a of gB(e,t.incoming,t.outgoing))c.add(a)}for(let e of(gA.set(n,c),gA.set(d,c),c))m.add(e);if(r){let a=function(e,t,a,l){let i=e=>void 0!==l(e),s=new Map;for(let t of e.edges)i(t.source)||i(t.target)||s.set(t.source,[...s.get(t.source)??[],t.target]);let o=e=>{let t=new Set([e]);for(let e of t)for(let a of s.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)},d=[];for(let t of e.edges){if(!i(t.source)||i(t.target))continue;let a=o(t.target);for(let s of e.edges){if(i(s.source)||!i(s.target)||!a.has(s.source))continue;let[e,o]=[l(t.source),l(s.target)];!(e===o||d.some(([t,a])=>t===e&&a===o))&&(n(o,e)||(d.push([e,o]),r.set(e,[...r.get(e)??[],o])))}}return d}(e,n,c,e=>h(t.id,e));a.length>0&&(gV.set(n,a),gV.set(d,a))}let p=new Set(e.edges.flatMap(e=>{let[a,l]=[h(t.id,e.source),h(t.id,e.target)];return void 0===a&&void 0!==l?[l]:void 0===l&&void 0!==a?[a]:[]}));return{across:d,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=gL(k.edges),z=gB(k,M.incoming,M.outgoing);for(let e of(gA.set(k,z),z))m.add(e);gA.set(e,m);let C={composites:c,crossEdges:b,groupOf:n,groups:v,parentOf:o,top:k,zoned:r};return gT.set(e,C),C}function gD(e,t,a){let l=gS(e.nodes),i=new Map(e.nodes.map(e=>[e.id,0])),s=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 d=s.get(n)??0;for(let r of t.outgoing.get(n)??[]){if(a.has(r.id))continue;s.set(r.target,Math.max(s.get(r.target)??0,d+1));let t=(i.get(r.target)??0)-1;i.set(r.target,t),0===t&&function(e,t,a,l){let i=a.get(t)??Number.MAX_SAFE_INTEGER,s=e.findIndex((e,t)=>t>l&&(a.get(e)??Number.MAX_SAFE_INTEGER)>i);-1===s?e.push(t):e.splice(s,0,t)}(o,r.target,l,e)}}for(let l of e.nodes)!function e(l){if(r.has(l))return s.get(l)??0;let i=0;for(let s of t.incoming.get(l)??[])a.has(s.id)||(i=Math.max(i,e(s.source)+1));return r.add(l),s.set(l,i),i}(l.id);return s}let gG=new WeakMap,gZ={TB:"bottom",BT:"top",LR:"right",RL:"left"};function gj(e,t,a,l,i=184,s=1116){return new Map(e.nodes.map(e=>{let o=gq(e,i,s),r=t.get(e.id),n={...o,width:Math.max(o.width,r?.width??0),height:Math.max(o.height,r?.height??0)},d=(a.outgoing.get(e.id)??[]).filter(t=>t.target!==e.id),c=(a.incoming.get(e.id)??[]).filter(t=>t.source!==e.id).length+d.length,p=!g_(e.kind)&&d.length>1&&d.some(e=>e.label)?Math.max(18,...d.map(e=>{let t=fn(e.label??"");return(l?t.width:t.height)+24})):18,h=d.filter(e=>e.label),g=void 0!==gC(e)?0:"state"===e.kind?32+h.reduce((e,t)=>{let a=fn(t.label);return e+(l?a.width:a.height)+24},0)+Math.max(0,c-h.length-1)*uL:32+Math.max(0,c-1)*p;return[e.id,"choice"!==e.kind||e.label?{...n,...l?{width:Math.max(n.width,g)}:{height:Math.max(n.height,g)}}:gz(n,g)]}))}function gN(e,t,a,l=!1){let i="TB"===e.layout.direction||"BT"===e.layout.direction,[s,o]=i?["left","right"]:["top","bottom"],r=(e,t)=>Math.max(112,(a.get(uk(e.nodeId,o))??0)+(a.get(uk(t.nodeId,s))??0)+18),n=gL(e.edges),d=gj(e,t,n,i),c=gP(e),p=function(e,t,a){let l=gV.get(e);if(!l)return t;for(let i=!0,s=0;i&&s<=e.nodes.length;s+=1){for(let[e,a]of(i=!1,l))t.get(a)<t.get(e)&&(t.set(a,t.get(e)),i=!0);for(let l of e.edges)!a.has(l.id)&&l.source!==l.target&&t.get(l.target)<t.get(l.source)+1&&(t.set(l.target,t.get(l.source)+1),i=!0)}return t}(e,gD(e,n,c),c),h=Array.from((function(e,t,a,l,i,s=!1){var o,r,n,d;let c,p,h=gS(e.nodes),g=new Map;for(let l of e.nodes){let e=a.get(l.id)??0,i=t.get(l.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 s=new Map;(g.get(e+1)??[]).forEach((e,t)=>{s.set(e.nodeId,t)});let o=e=>{let t=[...(l.incoming.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>a.get(e.source)).filter(e=>void 0!==e),...(l.outgoing.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>s.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 s?(o=g,r=e,n=a,d=i,(c=gG.get(r))||(c=function(e,t,a,l){let i=new Map,s=new Set,o=(e,t,a)=>i.set(a,[...i.get(a)??[],[e,t]]);for(let i of t.edges){let[t,r]=l.has(i.id)?[i.target,i.source]:[i.source,i.target],[n,d]=(a.get(t)??0)<=(a.get(r)??0)?[t,r]:[r,t],c=a.get(n)??0,p=a.get(d)??0;if(c===p)continue;let h=n;for(let t=c+1;t<p;t+=1){let a=`\0${i.id}\0${t}`;s.add(a);let l=e.get(t-1),r=e.get(t);r.splice(Math.round((l.indexOf(h)+.5)/l.length*r.length),0,a),o(h,a,t-1),h=a}o(h,d,p-1)}let r=new Map,n=t=>e.get(t)?.forEach((e,t)=>r.set(e,t)),d=[...e.keys()].sort((e,t)=>e-t);d.forEach(n);let c=e=>{let t=i.get(e)??[],a=0;for(let[e,[l,i]]of t.entries())for(let[s,o]of t.slice(e+1))(r.get(l)-r.get(s))*(r.get(i)-r.get(o))<0&&(a+=1);return a},p=()=>d.reduce((e,t)=>e+c(t),0),h=p(),g=()=>new Map([...e].map(([e,t])=>[e,t.filter(e=>!s.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 l=f.get(a)??{above:[],below:[]};l.above.push(t),f.set(a,l)}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?d.slice(1):d.slice(0,-1).reverse()){let l=e.get(t),i=new Map(l.map((e,t)=>{let l=(a?f.get(e)?.above:f.get(e)?.below)??[];return[e,l.length>0?l.reduce((e,t)=>e+r.get(t),0)/l.length:t]}));l.sort((e,t)=>i.get(e)-i.get(t)),n(t)}for(let t=!0;t;)for(let a of(t=!1,d)){let l=e.get(a);for(let e=0;e+1<l.length;e+=1){let i=c(a-1)+c(a);[l[e],l[e+1]]=[l[e+1],l[e]],n(a),c(a-1)+c(a)<i?t=!0:([l[e],l[e+1]]=[l[e+1],l[e]],n(a))}}let l=p();l<m.crossings&&(m={crossings:l,order:g()})}return m.order}(new Map([...o].map(([e,t])=>[e,t.map(e=>e.nodeId)])),r,n,d),gG.set(r,c)),p=new Map([...o.values()].flat().map(e=>[e.nodeId,e])),new Map([...o.keys()].map(e=>[e,(c.get(e)??[]).flatMap(e=>p.has(e)?[p.get(e)]:[])]))):g})(e,d,p,n,c,l).entries()).sort(([e],[t])=>e-t).map(([e,t])=>({breadth:t.reduce((e,a,l)=>e+(i?a.width:a.height)+(l>0?r(t[l-1],a):0),0),depth:Math.max(...t.map(e=>i?e.height:e.width)),rank:e,shapes:t})),g=gZ[e.layout.direction],u=(e,t)=>Math.max(0,...e.map(e=>a.get(uk(e.nodeId,t))??0));return{feedbackEdges:c,gapAfter:h.map((t,l)=>{let s=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=>fn(e.label,g_(d.get(e.source)?.kind)).width+16+72)),o=h[l+1];return Math.max(96,s,o&&a.size>0?u(t.shapes,g)+u(o.shapes,uS[g])+18:0)}),gapBetween:r,highSide:o,lowSide:s,rankByNodeId:p,rankMetrics:h,reachOf:u,vertical:i}}let gW={bandOf:new Map,continuations:new Set},gJ={crossingRepair:!1,reorder:!1,wrap:gW},gK={TB:"LR",BT:"LR",LR:"TB",RL:"TB"};function gQ(e,t){let[a,l]=e>t?[e,t]:[t,e];return(a+40)/(l+40)}function g1(e,t,a=0,l){let i;if("orthogonal"!==e.layout.edgeRouting||gY(e)||g6(e))return gW;let{feedbackEdges:s,gapAfter:o,rankByNodeId:r,rankMetrics:n}=gN(e,l?.sizes??new Map,new Map,t),d="TB"===e.layout.direction||"BT"===e.layout.direction,c=(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=gQ(c(0,h),p(0,h)),u=e=>Math.max(...n[e].shapes.map(e=>l?.weights.get(e.nodeId)??1)),f=(e,t)=>{let a=0;for(let l=e;l<=t;l+=1)a+=u(l);return a};if(5>f(0,h)||c(0,h)<=p(0,h))return gW;let m=new Map(e.nodes.map(e=>[e.id,e.kind])),v=e=>r.get(e)??0,y=new Map,w=new Set;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=e=>v(e.source)===a.rank&&v(e.target)===a.rank+1,r=i.find(o);(l?i.length>=1:1===i.length)&&r&&i.every(e=>!s.has(e.id)&&(l?.skips?v(e.source)<v(e.target):o(e))&&!g_(m.get(e.source)))&&(y.set(t,r.id),i.every(o)||w.add(t))}let x=(t,a)=>l?.skips===!0&&e.edges.some(e=>Math.min(v(e.source),v(e.target))<=n[t].rank&&Math.max(v(e.source),v(e.target))>n[a].rank),b=new Map(e.edges.map(e=>[e.id,e.label])),k=(e,t)=>{let a=b.get(y.get(t)??""),l=a?fn(a):void 0,i=t===h?0:Math.max(36,l?d?Math.max(40,l.height+24):l.width+16:0);return c(e,t)+36*(e>0)+i},M=[...y.keys(),h].sort((e,t)=>e-t),z=l?1:2,C=e=>{let t,l=(i,s)=>{if(i.length===e-1){if(f(s+1,h)<z)return;let e=[...i,h],l=e.map((t,a)=>k(0===a?0:e[a-1]+1,t)),o=Math.max(...l);if(Math.min(...l)<a*o)return;let r=l.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 M)e!==h&&e>s&&f(s+1,e)>=z&&(s<0||!x(s,e))&&l([...i,e],e)};return l([],-1),t},[_,q]=l?[l.bands,Math.min(l.bands,M.length)]:[2,Math.min(6,M.length)];for(let e=_;e<=q;e+=1){let t=new Map;for(let e of M)f(0,e)>=z&&e<h&&t.set(e,{ends:[e],longest:k(0,e),squares:k(0,e)**2});for(let a=2;a<=e;a+=1){let l=new Map;for(let i of M)if(a===e?i===h:i!==h)for(let[e,a]of[...t].reverse()){if(i<=e||f(e+1,i)<z||i!==h&&x(e,i))continue;let t=k(e+1,i),s={ends:[...a.ends,i],longest:Math.max(a.longest,t),squares:a.squares+t**2},o=l.get(i);(!o||s.longest<o.longest||s.longest===o.longest&&s.squares<o.squares)&&l.set(i,s)}t=l}let l=a>0?C(e):t.get(h);if(!l)continue;let s=[0,...l.ends.slice(0,-1).map(e=>e+1)].reduce((e,t,a)=>e+p(t,l.ends[a]),0)+(e-1)*144,o=gQ(l.longest,s);if((!i||o<i.aspect)&&(i={aspect:o,ends:l.ends}),o<=2)break}if(!i||i.aspect>=g)return gW;let L=new Map,S=0;for(let[e,t]of n.entries()){for(let e of t.shapes)L.set(e.nodeId,S);i.ends.includes(e)&&e!==h&&(S+=1)}return{bandOf:L,continuations:new Set(i.ends.filter(e=>e!==h).map(e=>y.get(e))),...l?{under:!0}:{},...i.ends.some(e=>w.has(e))?{skips:!0}:{}}}function g0(e,t=new Map,a=new Map,{compactGaps:l,reorder:i,widenGaps:s,wrap:o}=gJ,r=new Map){let{gapAfter:n,gapBetween:d,highSide:c,lowSide:p,rankMetrics:h,reachOf:g,vertical:u}=gN(e,t,a,i),f=[];for(let[e,t]of h.entries()){let a=o.bandOf.get(t.shapes[0].nodeId)??0;(f[a]??=[]).push({index:e,metric:t})}let m=[],v=o.under?function(e,t,a,l){let i=new Map,s=t.map(e=>{let t=0;for(let{index:l,metric:s}of e){for(let e of s.shapes)i.set(e.nodeId,t+s.depth);t+=s.depth+a[l]}return t-a[e.at(-1).index]}),o=Math.max(...s),r=[0];for(let a=1;a<t.length;a+=1){let t=e.edges.flatMap(e=>l.get(e.source)===a-1&&l.get(e.target)===a?[i.get(e.source)+r[a-1]-s[a]]:[]);r.push(Math.max(0,Math.min(Math.max(0,...t),o-s[a])))}return r}(e,f,n,o.bandOf):[],y=48;for(let[e,t]of f.entries()){let a=Math.max(...t.map(({metric:e})=>e.breadth)),i=48+(v[e]??0);for(let{index:e,metric:o}of t){let[t]=1===o.shapes.length?o.shapes:[],c=y+Math.max(0,a-o.breadth)/2-(t?r.get(t.nodeId)??0:0);for(let[e,t]of o.shapes.entries()){let a=o.shapes[e+1];u?(m.push({...t,x:c,y:i+Math.max(0,o.depth-t.height)/2}),c+=t.width):(m.push({...t,x:i+Math.max(0,o.depth-t.width)/2,y:c}),c+=t.height),a&&(c+=d(t,a))}i+=o.depth+Math.min(l?.get(e)??1/0,n[e])+(s?.get(e)??0)}let o=f[e+1];o&&(y+=a+Math.max(144,g(t.flatMap(({metric:e})=>e.shapes),c)+g(o.flatMap(({metric:e})=>e.shapes),p)+72))}if("BT"===e.layout.direction){let e=Math.max(...m.map(e=>e.y+e.height));return m.map(t=>({...t,y:48+e-t.y-t.height}))}if("RL"===e.layout.direction){let e=Math.max(...m.map(e=>e.x+e.width));return m.map(t=>({...t,x:48+e-t.x-t.width}))}return m}function g2(e,t=new Map,a=new Map,l=gJ,i=new Map){if(g6(e))return function(e,t,a,l=gJ){let{compactGaps:i,wrap:s}=l,o=e.lanes,{direction:r}=e.layout,{along:n,across:d,backSide:c,breadth:p,columnCount:h,columnOf:g,columns:u,content:f,depth:m,depthOf:v,forwardSide:y,gapAfter:w,headerSize:x,laneIndex:b,laneOf:k,offset:M,padding:z,poolBreadth:C,reach:_,shapes:q,vertical:L,wrapped:S}=g8(e,t,a,l.throughHandoffs,l.laneBreadth),B=g.map(e=>s.bandOf.get(e[0]?.nodeId??"")??0),A=Math.max(0,...B)+1,P=Array.from({length:A},(e,t)=>t),V=Math.max(48,...P.map(e=>_(g[B.indexOf(e)]??[],c)+g4)),H=Math.max(48,...P.map(e=>_(g[B.lastIndexOf(e)]??[],y)+g4)),I="RL"===r||"BT"===r,[$,F]=I?[H,V]:[V,H],O=48+x+$,E=[],U=O,X=0;for(let[e,t]of m.entries())e>0&&B[e]!==B[e-1]&&(U=O),E.push(U),U+=t,X=Math.max(X,U-O),e<h-1&&B[e+1]===B[e]&&(U+=Math.min(i?.get(e)??1/0,w[e]));let T=O+X,R=T+F,Y=P.map(t=>[...s.continuations].filter(a=>{let l=e.edges.find(e=>e.id===a);return void 0!==l&&s.bandOf.get(l.source)===t})),D=[];for(let e of(U=48,P))D.push(U),U+=C+g9(Y[e].length);let G=(e,t)=>D[e]+p.slice(0,t).reduce((e,t)=>e+t,0),Z=e.nodes.map(e=>{let t=q.get(e.id),a=b.get(e.lane),l=u.get(e.id),i=E[l]+(m[l]-t[v])/2,s=I?O+T-i-t[v]:i,o=G(B[l],a)+z[a].low+(p[a]-z[a].low-z[a].high-f[a])/2+M.get(e.id);return{...t,[n]:s,[d]:o}}),j=(e,t,a,l)=>L?{x:a,y:e,width:l,height:t}:{x:e,y:a,width:t,height:l},N=function(e,t,a){let l=new Map;for(let i of e){let e=`lane:${encodeURIComponent(i.id)}`,s=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;s(o);t+=1)o=`${e}@${t}`;l.set(i.id,o)}return l}(o,A,new Set(e.nodes.map(e=>e.id))),W=P.flatMap(e=>o.map((t,a)=>({box:j(48,R-48,G(e,a),p[a]),elementId:0===e?N.get(t.id):`${N.get(t.id)}:${e+1}`,header:j(48,x,G(e,a),p[a]),id:t.id,label:t.label,pool:e,text:S[a].text}))),J=P.map(e=>j(48,R-48,D[e],C));return{lanes:{continuations:s.continuations,frames:W,laneOf:k,pool:g3(J),pools:J,vertical:L},nodes:Z}}(e,t,a,l);let s=gY(e);return s?function(e,t,a,l,i,s){let o="TB"===e.layout.direction||"BT"===e.layout.direction,{zoned:r}=t,n=28*!r,d=new Map(a),c=new Map(l),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=g0(u.has(y.id)?e:v,d,c,{...gJ,reorder:i.reorder,wrap:i.zoneWraps?.get(y.id)??gW},g),x=g3(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=>(c.get(uk(t.nodeId,e))??0)-b(t,e)+18))+(s.get(y.id)??0),M=sX(y.label),z=r?g$+s$(gE(y))+M+sV.clearance:M+2*sV.clearance,C=w.filter(e=>m.has(e.nodeId)&&.01>=b(e,"top")).map(e=>e.x-x.x+e.width/2-36),_={top:k("top")+(r?gI:0),bottom:k("bottom"),right:k("right"),left:o&&C.length>0?Math.max(k("left"),z+18-Math.min(...C)):k("left")},q={content:x,group:y,height:x.height+_.top+_.bottom,nodes:w,padding:_,width:Math.max(x.width+_.left+_.right,r?z+g$:M+2*sV.clearance+16,(l.get(uk(y.id,"top"))??0)>0&&t.composites.has(y.id)?M+2*sV.clearance+36+16+t.crossEdges.filter(e=>e.source===y.id||e.target===y.id).length*uL:0)};h.set(y.id,q);let L=gR(y.id);d.set(L,{width:q.width,height:q.height+n}),r&&g.set(L,o?(q.padding.left-q.padding.right)/2:(q.padding.top-q.padding.bottom)/2);let S=(q.width-q.content.width-q.padding.left-q.padding.right)/2,B=(e,t)=>"top"===t?e.y-q.content.y+q.padding.top+n:"bottom"===t?q.content.y+q.content.height-e.y-e.height+q.padding.bottom:"left"===t?e.x-q.content.x+q.padding.left+S:q.content.x+q.content.width-e.x-e.width+q.padding.right+S;for(let e of["top","right","bottom","left"]){let a=Math.max(0,t.composites.has(y.id)?(l.get(uk(y.id,e))??0)-("top"===e?n:0):0,...w.map(t=>(c.get(uk(t.nodeId,e))??0)-B(t,e)));a>0&&c.set(uk(L,e),a)}};for(let e of t.groups)t.parentOf.has(e.group.id)||f(e);let m=i.zoneWraps?.get("")??gW,v=g0(t.top,d,c,{...i,wrap:m},g),y=new Map;for(let e of v)e.nodeId.startsWith(gH)||y.set(e.nodeId,{nodes:[e]});let w=new Map,x=(e,t,a)=>{let l=h.get(e),i={x:t.x,y:t.y+n,width:t.width,height:t.height-n};w.set(e,i);let s=i.x+l.padding.left+(i.width-l.content.width-l.padding.left-l.padding.right)/2-l.content.x,o=i.y+l.padding.top+(i.height-l.content.height-l.padding.top-l.padding.bottom)/2-l.content.y;for(let e of l.nodes){let t={...e,x:e.x+s,y:e.y+o};e.nodeId.startsWith(gH)?x(e.nodeId.slice(gH.length),t,a):a.push(t)}return i};for(let e of t.groups){if(t.parentOf.has(e.group.id))continue;let a=gR(e.group.id),l=v.find(e=>e.nodeId===a),i=[],s=x(e.group.id,l,i),o=t.groups.flatMap(({group:a})=>a.id!==e.group.id&&g5(t,a.id).at(-1)===e.group.id?[a.id]:[]);y.set(a,{frame:s,...o.length>0?{nested:new Map(o.map(e=>[e,w.get(e)]))}:{},nodes:i})}for(let[e,a]of(function(e,t,a,l=new Map,i=!1){let{crossEdges:s,top:o}=e,r=gP(o),n=gD(o,gL(o.edges),r),d=new Map;for(let e of o.nodes){let t=n.get(e.id)??0;d.set(t,[...d.get(t)??[],e.id])}let c=a?"x":"y",p=a?"width":"height",h=Math.max(0,...l.values())+1,g=e=>[...t].filter(([t])=>(l.get(t)??0)===e).map(([,e])=>e.frame??e.nodes[0]),u=e=>{let t=g(e);return{start:Math.min(...t.map(e=>e[c])),end:Math.max(...t.map(e=>e[c]+e[p]))}},f=e=>{let[t,l]=a?["y","height"]:["x","width"],i=g(e),[s,o]=[Math.min(...i.map(e=>e[t])),Math.max(...i.map(e=>e[t]+e[l]))],r=Array.from({length:e},(e,t)=>g(t)).flat().filter(e=>e[t]<o&&e[t]+e[l]>s);return r.length>0?Math.max(...r.map(e=>e[c]+e[p])):u(e-1).end},m=Array.from({length:h},(e,t)=>0===t?0:u(t).start-u(t-1).end),v=e=>(d.get(e)??[]).reduce((e,a)=>{let l=t.get(a);return e+(l.frame??l.nodes[0])[p]},0),y=[...d.keys()].sort((e,t)=>e-t),w=y.reduce((e,t)=>v(t)>v(e)?t:e),x=a=>{let l=e.composites.has(a)?t.get(gR(a)).frame:[...t.values()].flatMap(e=>e.nodes).find(e=>e.nodeId===a);return l[c]+l[p]/2},b=(e,a)=>{let l=t.get(e);for(let[e,t]of(l.nodes=l.nodes.map(e=>({...e,[c]:e[c]+a})),l.frame&&(l.frame={...l.frame,[c]:l.frame[c]+a}),l.nested??[]))l.nested.set(e,{...t,[c]:t[c]+a})},k=e=>l.get(d.get(e)?.[0]??"")??0,M=(e,t,a)=>{let[l]=d.get(e)??[];if(!l||1!==d.get(e).length||k(e)!==k(t))return;let i=o.edges.find(e=>!r.has(e.id)&&(a?e.target:e.source)===l&&n.get(a?e.source:e.target)===t);if(!i)return;let c=s[o.edges.indexOf(i)],[p,h]=a?[c.target,c.source]:[c.source,c.target];b(l,x(h)-x(p))},z=a=>{let l=d.get(a);if(!e.zoned||l.length<2)return;let i=e=>t.get(e).frame??t.get(e).nodes[0],n=new Map(l.map(e=>[e,o.edges.flatMap((t,a)=>{let i=s[a],[o,n]=t.source===e?[i.source,i.target]:[i.target,i.source];if(t.source!==e&&t.target!==e||l.includes(t.source===e?t.target:t.source))return[];let d=x(n);return r.has(t.id)&&t.source===e?[d,d]:[d]})])),h=[...l].sort((e,t)=>i(e)[c]-i(t)[c]),g=e=>e.reduce((e,t)=>e+t,0)/e.length,u=e=>n.get(e).length>0?g(n.get(e)):i(e)[c]+i(e)[p]/2,f=[...h].sort((e,t)=>u(e)-u(t)),m=h.slice(1).map((e,t)=>{let a=i(h[t]);return i(e)[c]-a[c]-a[p]}),v=l.flatMap(e=>n.get(e)),y=f.reduce((e,t)=>e+i(t)[p],0)+m.reduce((e,t)=>e+t,0),w=v.length>0?g(v)-y/2:i(h[0])[c];for(let[e,t]of f.entries())b(t,w-i(t)[c]),w+=i(t)[p]+(m[e]??0)};for(let e of y.filter(e=>e>w))M(e,e-1,!0),z(e);for(let e of y.filter(e=>e<w).reverse())M(e,e+1,!1),z(e);for(let e=1;e<h;e+=1){let a=(i?f(e):u(e-1).end)+m[e]-u(e).start;for(let[i]of t)(l.get(i)??0)===e&&b(i,a)}}(t,y,o,m.bandOf,m.rise),y))for(let[t,l]of(a.frame&&w.set(e.slice(gH.length),a.frame),a.nested??[]))w.set(t,l);let b=[...y.values()].flatMap(e=>e.nodes),k=gS(e.nodes);b.sort((e,t)=>k.get(e.nodeId)-k.get(t.nodeId));let M=(r?[...t.groups].sort((e,a)=>g5(t,e.group.id).length-g5(t,a.group.id).length):t.groups).map(({group:e})=>{let t=w.get(e.id),a=gE(e),l=!r&&a?sF({type:"frame",...t,icon:a}):void 0;return{box:t,elementId:`group:${e.id}`,...a?{icon:a}:{},id:e.id,...r&&void 0!==e.kind?{kind:e.kind}:{},label:e.label,labelBox:r?function(e,t,a){let{clearance:l,height:i}=sV;return{x:e.x+g$-l,y:e.y+(gI-i)/2-l,width:s$(a)+sX(t)+2*l,height:i+2*l}}(t,e.label,a):sT({...t,name:e.label}),...l?{logoBox:fg(l,sV.clearance)}:{}}});return{groups:{across:u,composites:t.composites,frames:M,groupOf:t.groupOf,parentOf:t.parentOf,zoned:r},nodes:b}}(e,s,t,a,l,i):{nodes:g0(e,t,a,l)}}function g3(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 g5(e,t){let a=[];for(let l=t;void 0!==l;l=e.parentOf.get(l))a.push(l);return a}let g4=36;function g6(e){return(e.lanes??[]).length>0}function g7(e,t=!1){let a=e.lanes??[],l=new Map(a.map((e,t)=>[e.id,t])),i=new Map(e.nodes.map(e=>[e.id,l.get(e.lane??"")??0])),s=gP(e),o=e.edges.filter(e=>!s.has(e.id)&&e.source!==e.target),r=new Set,n=new Set,d=new Set;for(let e of o){let[a,l]=[i.get(e.source),i.get(e.target)],s=`${e.source}\0${l}`,o=Math.abs(a-l)>1;a===l||o&&!t||d.has(s)||(d.add(s),(o?n:r).add(e.id))}let c=new Map(e.nodes.map(e=>[e.id,[]])),p=new Map(e.nodes.map(e=>[e.id,[]]));for(let e of o)c.get(e.target).push(e),p.get(e.source).push(e);let h=gS(e.nodes),g=t=>{let l=new Map(e.nodes.map(e=>[e.id,c.get(e.id).length])),s=e.nodes.filter(e=>0===l.get(e.id)).map(e=>e.id),o=new Map,r=new Map;for(;s.length>0;){s.sort((e,t)=>h.get(e)-h.get(t));let e=s.shift(),n=i.get(e),d=a.map((t,a)=>Math.max(-1,...c.get(e).map(e=>r.get(e.source)[a]))),g=d[n]+1;for(let a of c.get(e))g=Math.max(g,o.get(a.source)+ +!t.has(a.id));for(let t of(o.set(e,g),d[n]=g,r.set(e,d),p.get(e))){let e=l.get(t.target)-1;l.set(t.target,e),0===e&&s.push(t.target)}}return o},u=new Map(o.map(e=>[e.id,e]));for(;;){let t=g(new Set([...r,...n])),a=[...n].filter(a=>{let{source:l,target:s}=u.get(a),o=t.get(l);if(t.get(s)!==o)return!1;let[r,n]=[i.get(l),i.get(s)].sort((e,t)=>e-t);return e.nodes.some(e=>{let a=i.get(e.id);return a>r&&a<n&&t.get(e.id)===o})});if(0===a.length)return t;for(let e of a)n.delete(e)}}function g8(e,t,a,l=!1,i=0){let s=e.lanes,{direction:o}=e.layout,r="TB"===o||"BT"===o,[n,d]=r?["y","x"]:["x","y"],[c,p]=r?["height","width"]:["width","height"],[h,g]=r?["left","right"]:["top","bottom"],u=gZ[o],f=uS[u],m=(e,t)=>a.get(uk(e,t))??0,v=gL(e.edges),y=r?gj(e,t,v,r):gj(e,t,v,r,144,744),w=g7(e,l),x=new Map(s.map((e,t)=>[e.id,t])),b=new Map(e.nodes.map(e=>[e.id,e.lane])),k=Math.max(0,...w.values())+1,M=s.map(()=>Array.from({length:k},()=>[]));for(let t of e.nodes)M[x.get(t.lane)][w.get(t.id)].push(t.id);let z=gP(e),C=new Map(e.nodes.map(e=>[e.id,[]]));for(let t of e.edges)z.has(t.id)||t.source===t.target||(C.get(t.source).push(t.target),C.get(t.target).push(t.source));let _=gS(e.nodes),q=e=>{let t=M[x.get(b.get(e))][w.get(e)];return x.get(b.get(e))+(t.indexOf(e)+.5)/t.length};for(let e=0;e<4;e+=1)for(let e of M)for(let t of e){if(t.length<2)continue;let e=new Map(t.map(e=>{let t=C.get(e);return[e,t.length>0?t.reduce((e,t)=>e+q(t),0)/t.length:q(e)]}));t.sort((t,a)=>e.get(t)-e.get(a)||_.get(t)-_.get(a))}let L=Array.from({length:k},(t,a)=>e.nodes.filter(e=>w.get(e.id)===a).map(e=>y.get(e.id))),S=L.map(e=>Math.max(0,...e.map(e=>e[c]))),B=(e,t)=>Math.max(0,...e.map(e=>m(e.nodeId,t))),A=L.map((t,l)=>{let i=new Set(t.map(e=>e.nodeId)),s=r?0:Math.max(0,...e.edges.filter(e=>i.has(e.source)&&e.label&&(w.get(e.target)??0)>l).map(e=>fn(e.label,g_(y.get(e.source)?.kind)).width+16+72)),o=L[l+1];return Math.max(72,s,o&&a.size>0?B(t,u)+B(o,f)+18:0)}),P=(e,t)=>Math.max(112,m(e,g)+m(t,h)+18),V=e=>e.reduce((t,a,l)=>t+y.get(a)[p]+(l>0?P(e[l-1],a):0),0),H=M.map(e=>Math.max(0,...e.map(V))),I=new Map;for(let[e,t]of M.entries())for(let a of t){let t=(H[e]-V(a))/2;for(let[e,l]of a.entries())e>0&&(t+=P(a[e-1],l)),I.set(l,t),t+=y.get(l)[p]}let $=M.map((e,t)=>{let a=e.flat(),l=e=>Math.max(32,...a.map(a=>{let l=e===h?I.get(a):H[t]-I.get(a)-y.get(a)[p];return m(a,e)-l+g4}));return{low:l(h),high:l(g)}}),F=s.map(e=>ue(e.label)),O=r?0:Math.max(...F.map(e=>e.textWidth))+32,E=M.map((e,t)=>Math.max(i,$[t].low+H[t]+$[t].high,r?ue(s[t].label).longestWord+32:F[t].textHeight+32)),U=s.map((e,t)=>r?ue(e.label,E[t]-32):F[t]),X=r?Math.max(44,...U.map(e=>e.textHeight+32)):Math.ceil(O),T=E.reduce((e,t)=>e+t,0);return{along:n,across:d,backSide:f,breadth:E,columnCount:k,columnOf:L,columns:w,content:H,depth:S,depthOf:c,forwardSide:u,gapAfter:A,headerSize:X,laneIndex:x,laneOf:b,offset:I,padding:$,poolBreadth:T,reach:B,shapes:y,vertical:r,wrapped:U}}function g9(e){return Math.max(144,72+(e+1)*18)}function ue(e,t){let a=void 0===t?iL(e,868):iS(e,t,16),l=a.split("\n");return{longestWord:Math.max(...e.split(/\s+/u).map(e=>iC(e,16))),text:a,textHeight:Math.ceil(16*l.length*1.35),textWidth:Math.ceil(iC(a,16))}}function ut(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 ua(e){return(e?.frames??[]).flatMap(t=>e.composites.has(t.id)?[{...ut(t.elementId,t.box),kind:"composite",label:t.label,nodeId:t.id}]:[])}function ul(e){let t=28*!e?.zoned;return(e?.frames??[]).map(e=>ut(e.elementId,{...e.box,y:e.box.y-t,height:e.box.height+t}))}function ui(e,t){if(!e)return[];let a=new Set([...gU(e,e.groupOf.get(t.source.nodeId)),...gU(e,e.groupOf.get(t.target.nodeId))]),l=gX(e,t.source.nodeId,t.target.nodeId);return e.frames.flatMap(e=>{let t=ut(`group-label:${e.id}`,e.labelBox),i=e.logoBox?[ut(`group-logo:${e.id}`,e.logoBox)]:[];if(e.id===l){let{x:a,y:l,width:s,height:o}=e.box;return[t,...i,ut(`group-wall:${e.id}:top`,{x:a-4,y:l-4,width:s+8,height:4}),ut(`group-wall:${e.id}:bottom`,{x:a-4,y:l+o,width:s+8,height:4}),ut(`group-wall:${e.id}:left`,{x:a-4,y:l-4,width:4,height:o+8}),ut(`group-wall:${e.id}:right`,{x:a+s,y:l-4,width:4,height:o+8})]}return a.has(e.id)?[t,...i]:[t,ut(e.elementId,e.box)]})}let us="group-outline:",uo=`${us}lane:`;function ur(e){return ss([{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 un(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 ud(e){return e.elementId}function uc(e,t=!1){return e?[...e.frames.map(e=>ut(`lane-header:${ud(e)}`,e.header)),...(t?[]:e.pools).flatMap(({x:e,y:t,width:a,height:l},i)=>[ut(`lane-wall:${i}:top`,{x:e-4,y:t-4,width:a+8,height:4}),ut(`lane-wall:${i}:bottom`,{x:e-4,y:t+l,width:a+8,height:4}),ut(`lane-wall:${i}:left`,{x:e-4,y:t-4,width:4,height:l+8}),ut(`lane-wall:${i}:right`,{x:e+a,y:t-4,width:4,height:l+8})])]:[]}function up(e){return e.pools.flatMap((t,a)=>{var l,i,s;let o,r,n;return l=t,i=e.frames.filter(e=>e.pool===a),s=e.vertical,o=i[0].header,r=[...i.map(e=>s?e.box.x:e.box.y),s?l.x+l.width:l.y+l.height],n=s?[l.y,o.y+o.height,l.y+l.height]:[l.x,o.x+o.width,l.x+l.width],[...r.flatMap(e=>ss(s?[{x:e,y:l.y},{x:e,y:l.y+l.height}]:[{x:l.x,y:e},{x:l.x+l.width,y:e}])),...n.flatMap(e=>ss(s?[{x:l.x,y:e},{x:l.x+l.width,y:e}]:[{x:e,y:l.y},{x:e,y:l.y+l.height}]))]})}function uh(e){return e?[ut("lanes",e.pool)]:[]}function ug(e,t){let{source:a,target:l}=e,[i,s]=t.vertical?["y","height"]:["x","width"];return t.laneOf.get(a.nodeId)!==t.laneOf.get(l.nodeId)&&uP(e.sourceEdge)===i&&e.targetEdge===uS[e.sourceEdge]&&Math.min(a[i]+a[s],l[i]+l[s])-Math.max(a[i],l[i])>.01}function uu(e,t){let[a,l]=t.vertical?["y","height"]:["x","width"];for(let i of e){let{source:e,target:s}=i;if(uM(i)||t.continuations.has(i.edge.id)||t.laneOf.get(e.nodeId)===t.laneOf.get(s.nodeId)||Math.min(e[a]+e[l],s[a]+s[l])-Math.max(e[a],s[a])<=.01)continue;let o=t.vertical?um(s).x>um(e).x:um(s).y>um(e).y;i.sourceEdge=t.vertical?o?"right":"left":o?"bottom":"top",i.targetEdge=uS[i.sourceEdge]}}function uf(e,t=!1){return{type:"text",id:`label:${e.nodeId}`,containerId:e.id,...t&&e.groupIds?{groupIds:[...e.groupIds]}:{},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&&!t?{verticalAlign:"bottom"}:{}}}function um(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function uv(e,t,a){let l=um(e),i=um(t),s=i.x-l.x,o=i.y-l.y,r=e.kind?.toLowerCase();if("LR"===a||"RL"===a)return s>=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(s)>Math.abs(o)?{sourceEdge:s>0?"right":"left",targetEdge:"bottom"}:{sourceEdge:"top",targetEdge:"bottom"};let n=g_(r)&&o>e.height+96;return g_(r)&&o>0&&(0!==s||n)?{sourceEdge:s<0?"left":"right",targetEdge:"top"}:o>0?{sourceEdge:"bottom",targetEdge:"top"}:Math.abs(s)>Math.abs(o)?s>0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"}:{sourceEdge:"top",targetEdge:"bottom"}}function uy(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}}function uw(e,t,a){return Math.min(a,Math.max(t,e))}function ux(e,t,a=0){let l;if(iV(e.shape))return iE({...e,shape:e.shape},t,ux({...e,shape:"rectangle"},t,a));let i=(l="top"===t||"bottom"===t?e.width/2-16:e.height/2-16)>0?uw(a,-l,l):0,s=um(e),o=e.width/2,r=e.height/2;if("diamond"===e.shape&&o>0&&r>0){if("top"===t||"bottom"===t){let e=s.x+i,a=r*(1-Math.abs(i)/o);return{x:e,y:"top"===t?s.y-a:s.y+a}}let e=s.y+i,a=o*(1-Math.abs(i)/r);return{x:"left"===t?s.x-a:s.x+a,y:e}}if(("ellipse"===e.shape||"circle"===e.shape)&&o>0&&r>0){if("top"===t||"bottom"===t){let e=s.x+i,a=r*Math.sqrt(Math.max(0,1-(i/o)**2));return{x:e,y:"top"===t?s.y-a:s.y+a}}let e=s.y+i,a=o*Math.sqrt(Math.max(0,1-(i/r)**2));return{x:"left"===t?s.x-a:s.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 ub(e){return`${e.edgeId}:${e.endpoint}`}function uk(e,t){return`${e}:${t}`}function uM(e){return e.edge.source===e.edge.target}function uz(e,t){let[a,l]="source"===t?[e.sourceEdge,e.targetEdge]:[e.targetEdge,e.sourceEdge];return uB[l][uP(a)]}function uC(e,t){let a="source"===t?e.sourceEdge:e.targetEdge;return uM(e)?1e9*uz(e,t):um("source"===t?e.target:e.source)[uP(a)]}function u_(e,t){return e.find(e=>e.edge.id===t)?.pair??0}function uq(e,t=!1){let a=new Map;for(let t of e){let e=uk(t.source.nodeId,t.sourceEdge),l=uk(t.target.nodeId,t.targetEdge);a.set(e,[...a.get(e)??[],{edgeId:t.edge.id,endpoint:"source",coordinate:uC(t,"source")}]),a.set(l,[...a.get(l)??[],{edgeId:t.edge.id,endpoint:"target",coordinate:uC(t,"target")}])}let l=new Map;for(let i of a.values()){let a=i.filter(e=>"source"===e.endpoint),s=a.map(t=>e.find(e=>e.edge.id===t.edgeId)).filter(e=>e.edge.label),o=a.length>1&&s.length>0&&(!g_(s[0].source.kind)||t&&s.length>1)?Math.max(18,...s.map(e=>{let t=fn(e.edge.label);return("top"===e.sourceEdge||"bottom"===e.sourceEdge?t.width:t.height)+24})):18;i.sort((t,a)=>t.coordinate-a.coordinate||u_(e,t.edgeId)-u_(e,a.edgeId)).forEach((e,t)=>{l.set(ub(e),(t-(i.length-1)/2)*18*o/18)})}return l}let uL=36,uS={top:"bottom",right:"left",bottom:"top",left:"right"},uB={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function uA(e){return"source"===e.endpoint?e.route.sourceEdge:e.route.targetEdge}function uP(e){return"top"===e||"bottom"===e?"x":"y"}function uV(e,t){return("x"===uP(t)?e.width:e.height)/2-16}function uH(e,t){return"source"===e.endpoint?fi(e.route,t,36):fl(e.route,t,36)}let uI={desired:0,high:1/0,low:-1/0,priority:0};function u$(e){let t="left"===e.sourceEdge||"right"===e.sourceEdge;return e.labelSide??e.pair??(t?-1:1)}function uF(e,t){let{edge:a,source:l,sourceEdge:i,target:s,targetEdge:o}=e;return{start:ux(l,i,t.get(ub({edgeId:a.id,endpoint:"source"}))??0),end:ux(s,o,t.get(ub({edgeId:a.id,endpoint:"target"}))??0)}}function uO(e,t,a){let l=0,i=1;for(let[s,o]of[["x","width"],["y","height"]]){let r=a[s]+.01,n=a[s]+a[o]-.01,d=t[s]-e[s];if(.01>=Math.abs(d)){if(e[s]<=r||e[s]>=n)return!1}else{let t=(r-e[s])/d,a=(n-e[s])/d;l=Math.max(l,Math.min(t,a)),i=Math.min(i,Math.max(t,a))}}return l<i}function uE(e,t,a,l){let i=(a.x-um(e).x)/(e.width/2),s=(a.y-um(e).y)/(e.height/2),o="ellipse"===e.shape||"circle"===e.shape?{x:i/e.width,y:s/e.height}:"diamond"===e.shape?{x:Math.sign(i)/e.width,y:Math.sign(s)/e.height}:{x:"left"===t?-1:+("right"===t),y:"top"===t?-1:+("bottom"===t)};return(o.x*(l.x-a.x)+o.y*(l.y-a.y))/Math.hypot(o.x,o.y)>=-.01}function uU(e,t,a,l=!1){let i=new Map,s=gP(t),o="TB"===t.layout.direction||"BT"===t.layout.direction?["right","left","top","bottom"]:["bottom","top","left","right"],r=uq(e);for(let n of e.filter(e=>s.has(e.edge.id)||l&&(e=>{let{start:t,end:l}=uF(e,r);return!uE(e.source,e.sourceEdge,t,l)||!uE(e.target,e.targetEdge,l,t)||a.some(a=>a!==e.source&&a!==e.target&&uO(t,l,a))})(e))){let l,d={sourceEdge:n.sourceEdge,targetEdge:n.targetEdge},c=ub({edgeId:n.edge.id,endpoint:"source"}),p=ub({edgeId:n.edge.id,endpoint:"target"}),h=[d,...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),s=(e,a,l)=>{let s=("top"===a||"bottom"===a?e.width:e.height)/2-16;return t.spread?[i.get(l)??0,-s,s]:[i.get(l)??0]},o=s(n.source,n.sourceEdge,c),d=s(n.target,n.targetEdge,p);for(let s of o){for(let o of d){i.set(c,s),i.set(p,o);let{start:d,end:h}=uF(n,i);if(!uE(n.source,n.sourceEdge,d,h)||!uE(n.target,n.targetEdge,h,d)||a.some(e=>e!==n.source&&e!==n.target&&uO(d,h,e))||e.some(e=>{if(e===n)return!1;let{start:t,end:a}=uF(e,i);return[[n.source,d,e.source,t],[n.source,d,e.target,a],[n.target,h,e.source,t],[n.target,h,e.target,a]].some(([e,t,a,l])=>e===a&&.01>=Math.hypot(t.x-l.x,t.y-l.y))||function(e,t,a,l){let i=t.x-e.x,s=t.y-e.y,o=Math.hypot(i,s);if(o<=.01)return!1;let r=t=>Math.abs(i*(t.y-e.y)-s*(t.x-e.x))/o;if(r(a)>.01||r(l)>.01)return!1;let n=t=>((t.x-e.x)*i+(t.y-e.y)*s)/o,d=n(a),c=n(l);return Math.min(o,Math.max(d,c))-Math.max(0,Math.min(d,c))>.01}(d,h,t,a)}))continue;let g=fc(e,i),f=g.find(e=>e.nodeId===`branch-label:${n.edge.id}`);if(!(f&&uO(d,h,f))&&(l??={sides:t,sourceOffset:s,targetOffset:o},!g.some(e=>e.nodeId!==`branch-label:${n.edge.id}`&&uO(d,h,e)))){r.set(c,s),r.set(p,o),u=!0;break}}if(u)break}if(u)break}if(u||s.has(n.edge.id)){if(!u)if(Object.assign(n,l?.sides??d),l)r.set(c,l.sourceOffset),r.set(p,l.targetOffset);else{let e="TB"===t.layout.direction||"BT"===t.layout.direction,l=e?"x":"y",s=e?"width":"height",o=um(n.source)[l],r=Math.max(...a.flatMap(e=>[Math.abs(e[l]-o),Math.abs(e[l]+e[s]-o)]));i.set(n.source.nodeId,{width:n.source.width,height:n.source.height,[s]:2*(r+16+18)})}}else Object.assign(n,l?.sides??d),l&&(r.set(c,l.sourceOffset),r.set(p,l.targetOffset))}return{offsets:r,minimumSizes:i}}function uX(e,t,a=!1){let l=new Map;for(let i of e){let{start:e,end:s}=uF(i,t);for(let[t,a,o]of[[i.source,i.sourceEdge,fi(i,e,36)],[i.target,i.targetEdge,fl(i,s,36)]]){let r=u7(t===i.source?e:s,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,d=uk(t.nodeId,a);l.set(d,Math.max(l.get(d)??0,n))}if(i.edge.label&&(a||uM(i))){let t=i.source,a=fp(fd(i,e),fn(i.edge.label,g_(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=uk(t.nodeId,e);i>0&&l.set(a,Math.max(l.get(a)??0,i))}}}return l}let uT=new WeakSet;function uR(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 uY(e,t){return e.x>=t.x&&e.x<=t.x+t.width&&e.y>=t.y&&e.y<=t.y+t.height}function uD(e,t,a){let l,i="horizontal"===e.orientation,[s,o]=i?[t.width/2,t.height/2]:[t.height/2,t.width/2],r=i?t.x+s:t.y+s,n=Math.abs(e.staticCoordinate-(i?t.y+o:t.x+o));if("ellipse"===t.shape||"circle"===t.shape){let[e,t]=[s+a,o+a];if(n>=t)return!1;l=e*Math.sqrt(1-(n/t)**2)}else if("diamond"===t.shape){let e=1+a*Math.hypot(1/s,1/o);if(n>=o*e)return!1;l=s*(e-n/o)}else{if(n>=o+a)return!1;l=s+a}return e.min<r+l-.01&&e.max>r-l+.01}function uG(e,t){return e.id.startsWith("node:")&&!t.has(e.nodeId)}function uZ(e,t,a){return ss(e).filter(e=>t.some(t=>uG(t,a)&&uj(e,t))).length}function uj(e,t){let[a,l,i,s]="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-l))&&Math.min(e.max,i+s)-Math.max(e.min,i)>.01}function uN(e,t,a){let l=0;for(let[i,s]of ss(e).entries())for(let o of t)!(a.has(o.nodeId)&&(0===i&&uY(e[0],o)||i===e.length-2&&uY(e.at(-1),o)))&&sn(s,o)&&(l+=1);return l}function uW(e,t,a){let l=0;for(let i of ss(e))for(let e of t)uG(e,a)&&!sn(i,e)&&uD(i,e,12)&&(l+=1);return l}function uJ({edgeArrows:e,groups:t,nodeShapes:a}){if(!t?.zoned)return;let l=sx(fX([...a,...ul(t)],e));return{gap:24/l,run:30/l}}function uK(e,t,{gap:a,run:l}){let[i,s,o,r]="horizontal"===e.orientation?[t.y,t.height,t.x,t.width]:[t.x,t.width,t.y,t.height],n=e.staticCoordinate,d=n<i?i-n:n-i-s;return d>0&&d<a&&Math.min(e.max,o+r)-Math.max(e.min,o)>l}function uQ(e){let t=0;for(let a=0;a<e.length-1;a+=1){let l=e[a],i=e[a+1];l&&i&&(t+=Math.abs(i.x-l.x)+Math.abs(i.y-l.y))}return t}function u1(e){return ss(e.points).map(t=>{let[a,l]=[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?l.x:l.y}})}function u0(e){return e.flatMap(e=>u1({arrowId:e.id,points:e.points,sourceNodeId:e.sourceNodeId,targetNodeId:e.targetNodeId}))}function u2(e,t,a){let l=u1({arrowId:`edge:${a.edge.id}`,points:e,sourceNodeId:a.edge.source,targetNodeId:a.edge.target}),i=0;for(let e of l)for(let l of t)e.arrowId===l.arrowId||!sr(e,l)||void 0!==a.pinned&&function(e,t){let a=e.isFirstSegment&&t.isFirstSegment&&e.startBindingId===t.startBindingId;return sd(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,l)||(i+=1);return i}function u3(e,t){let a=u1({arrowId:`edge:${t.edge.id}`,points:e,sourceNodeId:t.edge.source,targetNodeId:t.edge.target}),l=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&&sr(t,e)&&(l+=1)}}return l}function u5(e){let t=e[0],a=e[e.length-1];if(!t||!a)return 0;let l=e.map(e=>e.x),i=e.map(e=>e.y),s=0;return a.x<t.x?s+=Math.max(0,Math.max(...l)-t.x):a.x>t.x&&(s+=Math.max(0,t.x-Math.min(...l))),a.y<t.y?s+=Math.max(0,Math.max(...i)-t.y):a.y>t.y&&(s+=Math.max(0,t.y-Math.min(...i))),s}function u4(e){let t=e[0],a=e[e.length-1];if(!t||!a)return 0;let l=e.map(e=>e.x),i=e.map(e=>e.y),s=0;return a.x<t.x?s+=Math.max(0,a.x-Math.min(...l)):a.x>t.x&&(s+=Math.max(0,Math.max(...l)-a.x)),a.y<t.y?s+=Math.max(0,a.y-Math.min(...i)):a.y>t.y&&(s+=Math.max(0,Math.max(...i)-a.y)),s}function u6(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 u7(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 u8(e,t){return 0===t.length?0:ss(e).filter(e=>t.some(t=>t.orientation===e.orientation&&Math.abs(t.staticCoordinate-e.staticCoordinate)<(t.arrowId.startsWith(uo)?24:8)&&so(t,e)>8)).length}function u9(e){return ss(e).filter((e,t,a)=>t>0&&e.orientation!==a[t-1].orientation).length}function fe(e,t,a,l,i,s=!1){let o=e[0];if(!o)return[{x:0,y:0}];let r=e=>{let o,r,n,d,c,p=i.quality?.({id:`edge:${l.edge.id}`,points:e,sourceId:l.edge.source,targetId:l.edge.target})??{arrowheadsCrossed:0,corridors:0,jogs:0};return[-(o=e[0],r=e[1],n=e[e.length-1],d=e[e.length-2],c=0,r&&u6(o,r,l.sourceEdge)&&(c+=1),d&&n&&u6(n,d,l.targetEdge)&&(c+=1),c),uN(e,t,a),...s?[uZ(e,t,a)]:[],u3(e,l),u2(e,i.segments,l),i.heads?p.arrowheadsCrossed:0,u8(e,i.outlines),p.corridors,i.heads?0:p.arrowheadsCrossed,i.crossings?.route(e,`edge:${l.edge.id}`)??0,u5(e),u4(e),p.jogs,uQ(e),i.quality?u9(e):0]},n=(e,t)=>{for(let a=0;a<e.length;a+=1){let l=(e[a]??0)-(t[a]??0);if(0!==l)return l<0}return!1},d=o,c=r(o);for(let t of e.slice(1)){let e=r(t);n(e,c)&&(d=t,c=e)}return d}function ft(e,t,a,l){switch(a){case"left":return l+t.x-e.x;case"right":return l+e.x+e.width-t.x;case"top":return l+t.y-e.y;case"bottom":return l+e.y+e.height-t.y}}function fa(e,t){return e.runs?.[t]??e.endRun??0}function fl(e,t,a){return ft(e.target,t,e.targetEdge,Math.max(a,fa(e,"target")))}function fi(e,t,a){let l=e.edge.label&&!uM(e)?"left"===e.sourceEdge||"right"===e.sourceEdge?fn(e.edge.label,g_(e.source.kind)).width+16:Math.max(40,fn(e.edge.label,g_(e.source.kind)).height+24):0;return ft(e.source,t,e.sourceEdge,Math.max(a,fa(e,"source")+Math.min(l,function(e,t){if("choice"!==e.source.kind||e.targetEdge!==uS[e.sourceEdge])return 1/0;let a=uB[e.sourceEdge],l=0===a.x?"y":"x",i=a[l],[s,o]="x"===l?["y","height"]:["x","width"];if(t[s]>=e.target[s]&&t[s]<=e.target[s]+e.target[o])return 1/0;let r=((i>0?e.target[l]:e.target[l]+e.target["x"===l?"width":"height"])-t[l])*i-36-18;return r>36?r:1/0}(e,t))))}function fs(e,t,a=!1){let l="TB"===t||"BT"===t;if(!l&&!a)return;let i=l?"x":"y",s=l?"y":"x",[o,r]=l?["left","right"]:["top","bottom"],n="TB"===t?"bottom":"BT"===t?"top":"LR"===t?"right":"left";for(let t of new Set(e.filter(e=>g_(e.source.kind)).map(e=>e.source))){let a=e.filter(e=>e.source===t).sort((e,t)=>um(e.target)[i]-um(t.target)[i]||um(e.target)[s]-um(t.target)[s]||e.index-t.index);a.length<2||a.forEach((e,l)=>{let d=a.filter(e=>1>Math.abs(um(e.target)[i]-um(t)[i])).sort((e,a)=>Math.abs(um(e.target)[s]-um(t)[s])-Math.abs(um(a.target)[s]-um(t)[s]))[0],c=2===a.length&&e===d,p=2===a.length&&void 0!==d&&!c;e.sourceEdge=c?n:p?um(e.target)[i]<um(t)[i]?o:r:0===l?o:l===a.length-1?r:n})}}let fo=new Map;function fr(e,t){let a=`${t}\0${e}`,l=fo.get(a);if(!l){let i=iS(e,t,13);l={width:iq(i,13,t),height:Math.ceil(13*i.split("\n").length*1.35)},fo.size>=4096&&fo.clear(),fo.set(a,l)}return l}function fn(e,t=!1){return fr(e,t?80:160)}function fd(e,t){let a=fn(e.edge.label??"",g_(e.source.kind)),l=u7(t,e.sourceEdge,fi(e,t,36)),i="left"===e.sourceEdge||"right"===e.sourceEdge;if(uM(e)){let t=u7(ux(e.target,e.targetEdge),e.targetEdge,36),s=uB[e.sourceEdge];return i?{x:l.x+s.x*(a.width/2+8),y:(l.y+t.y)/2}:{x:(l.x+t.x)/2,y:l.y+s.y*(a.height/2+5)}}let s=u$(e),o=u7(t,e.sourceEdge,fa(e,"source"));return{x:(o.x+l.x)/2+(i?0:s*(a.width/2+8)),y:(o.y+l.y)/2+(i?s*(a.height/2+5):0)}}function fc(e,t){return e.filter(e=>e.edge.label).map(e=>{let a=ux(e.source,e.sourceEdge,t.get(ub({edgeId:e.edge.id,endpoint:"source"}))??0),l=fd(e,a),i=fn(e.edge.label,g_(e.source.kind)),s=i.width+12;return{...e.source,id:`branch-label:${e.edge.id}`,nodeId:`branch-label:${e.edge.id}`,x:l.x-s/2,y:l.y-i.height/2-4,width:s,height:i.height+8,shape:"rectangle"}})}function fp(e,t){return{x:e.x-t.width/2,y:e.y-t.height/2,width:t.width,height:t.height}}function fh(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 fg(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function fu(e,t){let[a,l,i,s]="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-l,a-e.x-e.width),Math.max(0,e.y-s,i-e.y-e.height))}function ff(e,t){return Math.min(1/0,...t.map(t=>fu(e,t)))}function fm(e,t,a){return Math.max(0,ff(e,t)+8-ff(e,a))}function fv(e,t,a={start:0,end:0}){let l=[],i=uQ(e),s=0;for(let o of ss(e)){if(s>240)break;let r=e[o.segmentIndex],n=e[o.segmentIndex+1],d=o.max-o.min,c="horizontal"===o.orientation,p=c?t.width/2+4:t.height/2+4;for(let e=Math.min(p,d/2);e<=d-Math.min(p,d/2)&&!(s+e>240);e+=12){if(a.start>0&&s+e-p<a.start||a.end>0&&s+e+p>i-a.end)continue;let o=e/d,h={x:r.x+(n.x-r.x)*o,y:r.y+(n.y-r.y)*o};for(let e of[1,-1])l.push(c?{x:h.x,y:h.y-e*(t.height/2+5)}:{x:h.x+e*(t.width/2+8),y:h.y})}s+=d}return l}function fy(e){return e?{start:fa(e,"source"),end:fa(e,"target")}:{start:0,end:0}}function fw(e,t,a,l,i=!0,s){return fx(e,t,a,l,i,s).labels}function fx(e,t,a,l,i=!0,s){let o=[],r=0,n=e.map(e=>ss(e.points)),d=[...a,...(l?.frames??[]).flatMap(e=>[ut(`group-label:${e.id}`,e.labelBox),...e.logoBox?[ut(`group-logo:${e.id}`,e.logoBox)]:[]]),...(s?.frames??[]).map(e=>ut(`lane-header:${ud(e)}`,e.header))],c=[...(l?.frames??[]).flatMap(e=>ur(e.box)),...s?up(s):[]],p=g3([...a,...ul(l),...uh(s),...e.flatMap(e=>e.points.map(e=>({...e,width:0,height:0})))]),h=[],g=e.map((e,a)=>e.label?fn(e.label,g_(t[a]?.source.kind)):void 0),u=e.map((e,a)=>e.label?fd(t[a],e.points[0]):void 0);for(let[a,l]of e.entries()){let e=g[a],s=u[a];if(!e||!s)continue;let o=u.flatMap((e,t)=>e&&t!==a&&!h.some(e=>e.index===t)?[fp(e,g[t])]:[]),v=[...n.flatMap((e,t)=>t===a?[]:e),...c],y=function(e){if(null===e.endArrowhead)return;let[t,a]=[e.points.at(-2),e.points.at(-1)];if(!t||!a)return;let l=Math.hypot(a.x-t.x,a.y-t.y);if(l<=0)return;let i=Math.min(25,l/2),[s,o]=[i*Math.cos(gv),i*Math.sin(gv)+1],[r,n]=[(a.x-t.x)/l,(a.y-t.y)/l],d=[a.x,a.x-r*s-n*o,a.x-r*s+n*o],c=[a.y,a.y-n*s+r*o,a.y-n*s-r*o];return ut(`arrowhead:${e.id}`,{x:Math.min(...d)-1,y:Math.min(...c)-1,width:Math.max(...d)-Math.min(...d)+2,height:Math.max(...c)-Math.min(...c)+2})}(l),w=y?[...d,y]:d,x=(t,l=0)=>(function(e,t,a,l,i){let s=fg(e,3),o=fg(e,8);return t.filter(e=>sn(e,s)).length+a.filter(e=>sn(e,o)).length+l.filter(t=>(function(e,t){let[a,l]=[t.x+t.width/2,t.y+t.height/2],i=Math.max(e.x,Math.min(a,e.x+e.width))-a,s=Math.max(e.y,Math.min(l,e.y+e.height))-l,[o,r]=[Math.abs(i)/(t.width/2),Math.abs(s)/(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=>fh(s,e)).length})(fg(fp(t,e),l),n[a],v,w,[...o,...h.map(e=>e.box)]),b=s,k=x(s);if(k>0)for(let i of[...fv(l.points,e,fy(t[a])),...function(e,t,a){let[l,i]=t.points;if(!a||!i||2!==t.points.length)return[];let s=(.01>=Math.abs(l.x-i.x)?a.width:a.height)/2;return .01>=Math.abs(l.x-i.x)?[{x:e.x+Math.sign(e.x-l.x)*(s+3),y:e.y}]:[{x:e.x,y:e.y+Math.sign(e.y-l.y)*(s+3)}]}(s,l,y)]){let e=x(i);if(e<k&&([b,k]=[i,e]),0===k)break}else{var f,m;if(i&&(f=fp(s,e),fm(f,n[a],v)>0)){let i=t=>fm(fp(t,e),n[a],v),o=(m=fp(s,e),fm(m,n[a],n.flatMap((e,t)=>t===a?[]:e))>0),r=fv(l.points,e,fy(t[a])).filter(t=>{var a;return o||(a=fp(t,e),a.x>=p.x-.01&&a.y>=p.y-.01&&a.x+a.width<=p.x+p.width+.01&&a.y+a.height<=p.y+p.height+.01)});b=r.find(e=>0===x(e,6)&&0===i(e))??r.filter(e=>0===x(e)).reduce((e,t)=>i(t)<i(e)?t:e,s)}}r+=k,u[a]=b,h.push({box:fp(b,e),index:a})}let v=[];for(let[a,l]of e.entries()){let i=u[a];if(!l.label||!i)continue;let s=fp(i,g[a]),r=n[a],d=fm(s,r,[...n.flatMap((e,t)=>t===a?[]:e),...c]);d>0&&v.push({box:s,own:ff(s,r),index:a,shortfall:d});let p=[`branch:${l.edgeId}`],h=function(e,t){let[a]=t.toSorted((t,a)=>fu(e,t)-fu(e,a));if(a&&"vertical"===a.orientation&&!(a.max<=e.y)&&!(a.min>=e.y+e.height)){if(e.x>=a.staticCoordinate)return"left";if(e.x+e.width<=a.staticCoordinate)return"right"}}(s,r);o.push({type:"text",id:`${l.id}:label`,text:l.label,fontSize:13,x:i.x,y:i.y,maxWidth:g_(t[a]?.source.kind)?80:160,...h?{textAlign:h}:{},groupIds:p}),e[a]={...l,groupIds:p}}return{labels:o,touches:r,shortfalls:v}}function fb(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,l)=>{let i=a.get(e.orientation),s=Math.max(t,.02),o=0,r=i.length;for(;o<r;){let t=o+r>>1;i[t].staticCoordinate<e.staticCoordinate-s?o=t+1:r=t}let n=0,d=0;for(let a=o;a<i.length&&i[a].staticCoordinate<=e.staticCoordinate+s;a+=1){let s=i[a];s.arrowId!==l&&(sr(e,s)?n+=1:Math.abs(s.staticCoordinate-e.staticCoordinate)<t&&so(e,s)>.01&&(d+=1))}return{beside:d,overlaps:n}}}function fk(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 fM(e,t){if(t.length!==e.length||!fk(t))return!1;let a=(e,t,a)=>({dx:e[a].x-e[t].x,dy:e[a].y-e[t].y}),l=e.length-1;return[[0,1],[l,l-1]].every(([l,i])=>{let[s,o]=[a(e,l,i),a(t,l,i)],r=Math.abs(s.dx)+Math.abs(s.dy);return Math.sign(o.dx)===Math.sign(s.dx)&&Math.sign(o.dy)===Math.sign(s.dy)&&Math.abs(o.dx)+Math.abs(o.dy)>=Math.min(r,36)-.01})}function fz(e,t,a,l,i,s=e.map((e,t)=>t),o=new Map){var r,n;let d=[...fc(e,a),...e.filter(uM).map(e=>{let{start:t,end:l}=uF(e,a),i=g3([t,l,u7(t,e.sourceEdge,fi(e,t,36)),u7(l,e.targetEdge,fl(e,l,36))].map(e=>({...e,width:0,height:0})));return ut(`loop:${e.edge.id}`,fg(i,9))})],c="orthogonal"===t?e.flatMap(e=>{let{start:t,end:l}=uF(e,a),i={type:"arrow",id:`edge:${e.edge.id}`,edgeId:e.edge.id,sourceNodeId:e.edge.source,targetNodeId:e.edge.target},s={...i,points:[u7(l,e.targetEdge,fl(e,l,36)),l]};return uT.add(s),[{...i,endArrowhead:null,points:[t,u7(t,e.sourceEdge,fi(e,t,36))]},s]}):[],p=[...(r=i.groups,(r?.frames??[]).map(e=>{let{x:t,y:a,width:l,height:i}=e.box,s=`${us}${e.id}`;return{type:"arrow",id:s,edgeId:s,sourceNodeId:"",targetNodeId:"",endArrowhead:null,points:[{x:t,y:a},{x:t+l,y:a},{x:t+l,y:a+i},{x:t,y:a+i},{x:t,y:a}]}})),...(n=i.lanes)?up(n).map((e,t)=>{let a=`${uo}${t}`,[l,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:[l,i]}}):[]],h=uc(i.lanes),g=uc(i.lanes,!0),u=[];for(let r of s.map(t=>e[t])){let e=o.get(r.edge.id);if(e){u.push(e);continue}u.push(function(e,t,a,l,i,s){let{edge:o}=e,{start:r,end:n}=uF(e,a),d="orthogonal"===t?function(e,t,a,l,i,{avoidCrossings:s,clearHeads:o,readerScale:r,guided:n,bandOf:d,groups:c,lanes:p,midway:h}){let g=Math.abs(a.x-t.x)>=Math.abs(a.y-t.y),u=new Set([e.source.nodeId,e.target.nodeId]),f=d?.get(e.source.nodeId),m=void 0===f?l:l.filter(e=>d.get(e.nodeId)===f),v=Math.min(...m.map(e=>e.x)),y=Math.max(...m.map(e=>e.x+e.width)),w=Math.min(...m.map(e=>e.y)),x=Math.max(...m.map(e=>e.y+e.height)),b="left"===e.sourceEdge||"left"===e.targetEdge||um(e.target).x<um(e.source).x,k=um(e.target).y<um(e.source).y,M=18*e.index,z=v-56-M,C=y+56+M,_=w-48-M,q=x+48+M,L=e.index%4*18/2,S=Math.min(e.source.x,e.target.x)-56-L,B=Math.max(e.source.x+e.source.width,e.target.x+e.target.width)+56+L,A=Math.min(e.source.y,e.target.y)-48-L,P=Math.max(e.source.y+e.source.height,e.target.y+e.target.height)+48+L,V=36+e.index%4*18,H=void 0===r?[V]:[...new Set([V,36])],I=(l,i)=>{let s=i>0?u7(t,e.sourceEdge,fi(e,t,36)):t,o=i>0?u7(a,e.targetEdge,fl(e,a,i)):a;return uR([t,s,{x:l,y:s.y},{x:l,y:o.y},o,a])},$=(l,i)=>{let s=i>0?u7(t,e.sourceEdge,fi(e,t,36)):t,o=i>0?u7(a,e.targetEdge,fl(e,a,i)):a;return uR([t,s,{x:s.x,y:l},{x:o.x,y:l},o,a])},F=[[k?A:P,$],[k?P:A,$],[k?_:q,$],[k?q:_,$]],O=[[b?S:B,I],[b?B:S,I],[b?z:C,I],[b?C:z,I]],[E,U]=g?[F,O]:[O,F],X=[...E.slice(0,2),...U.slice(0,2),...E.slice(2),...U.slice(2)],T=u7(t,e.sourceEdge,fi(e,t,36)),R=u7(a,e.targetEdge,fl(e,a,36)),Y=e.lane,D=Y?H.map(e=>Y.vertical?I(Y.at,e):$(Y.at,e)):[],G=e.targetEdge===uS[e.sourceEdge]&&(void 0!==e.pinned||(void 0!==p?ug(e,p):!0===h)),Z="left"===e.sourceEdge||"right"===e.sourceEdge?[{x:(T.x+R.x)/2,y:T.y},{x:(T.x+R.x)/2,y:R.y}]:[{x:T.x,y:(T.y+R.y)/2},{x:R.x,y:(T.y+R.y)/2}],j=[...D,uR([t,a]),uR([t,T,{x:T.x,y:R.y},R,a]),uR([t,T,{x:R.x,y:T.y},R,a]),...G?[uR([t,T,...Z,R,a])]:[],...X.flatMap(([e,t])=>H.map(a=>t(e,a)))],N=function(e,t,a=!1,l=!1){let i,s,o=e.some(e=>e.id.startsWith(uo))?e.filter(e=>!e.id.startsWith(uo)):e,r=o.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId,endArrowhead:null!==e.endArrowhead,...l&&uT.has(e)?{headRun:50}:{}}));return{...void 0===t?{}:{...a?{crossings:function(e){let t={horizontal:[],vertical:[]};for(let a of e){if(a.id.startsWith(us))continue;let e=fT(a.points);for(let l=0;l+1<e.length;l+=1){let[i,s]=[e[l],e[l+1]],o=.01>=Math.abs(i.y-s.y);if(!o&&Math.abs(i.x-s.x)>.01)continue;let[r,n]=o?[i.x,s.x]:[i.y,s.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,l,i,s,o)=>{let r=t["horizontal"===e?"vertical":"horizontal"],n=0,d=r.length;for(;n<d;){let e=n+d>>1;r[e].at<=l+.01?n=e+1:d=e}let c=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!==s&&a>t.min+.01&&a<t.max-.01&&(c+=1)}return c};return{step:(e,t,l,i,s)=>a(e,t,Math.min(l,i),Math.max(l,i),s,!0),route:(e,t)=>{let l=fT(e),i=0;for(let e=0;e+1<l.length;e+=1){let[s,o]=[l[e],l[e+1]],r=.01>=Math.abs(s.y-o.y);if(!r&&Math.abs(s.x-o.x)>.01)continue;let[n,d]=r?[Math.min(s.x,o.x),Math.max(s.x,o.x)]:[Math.min(s.y,o.y),Math.max(s.y,o.y)];i+=a(r?"horizontal":"vertical",r?s.y:s.x,n,d,t,!1)}return i}}}(o)}:{},...l?{heads:(i=8/t+2,s=r.flatMap(e=>{let t=sC(e);return t?[{bounds:sA(t,i),head:t,id:e.id}]:[]}),(e,a,l)=>{let i=sA([e,a]),o=new Set;for(let r of s)r.id!==l&&!o.has(r.id)&&sP(i,r.bounds)&&(sS(e,a,r.head)-2)*t<8&&o.add(r.id);return o.size})}:{},quality:sB(r,t)},outlines:u0(e.filter(e=>e.id.startsWith(us))),segments:u0(o)}}(i,r,s,o),W=c?.zoned===!0,J=fe(j,l,u,e,N,W),K=void 0===r?0:24/r,Q=K?fe([J,...function(e,t,a,l){let i=`edge:${a.edge.id}`,s=[];for(let a of ss(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)>=l||.01>=so(a,o)))for(let t of[o.staticCoordinate-l-1,o.staticCoordinate+l+1]){let l=e.map((e,l)=>l===a.segmentIndex||l===a.segmentIndex+1?"horizontal"===a.orientation?{x:e.x,y:t}:{x:t,y:e.y}:e);s.push(uR(l))}}return s}(J,N.segments,e,K)],l,u,e,N,W):J,ee=t=>N.quality?.({id:`edge:${e.edge.id}`,points:t,sourceId:e.edge.source,targetId:e.edge.target})??{arrowheadsCrossed:0,corridors:0,jogs:0},et=W&&uZ(Q,l,u)>0,ea=uN(Q,l,u)||u3(Q,e)||u2(Q,N.segments,e)||void 0!==N.heads&&ee(Q).arrowheadsCrossed||u8(Q,N.outlines),el=void 0!==e.pinned&&u5(Q)+u4(Q)>0;if(ea||et||ee(Q).corridors||el){let s=function(e,t,a,l,i,s,o,r,n,d=0,c=1/0,p=!0,h,g=!1,u){let f,m,v,y,w=e=>[...new Set([18,Math.max(18,d+1)])].flatMap(t=>[e-t,e+t]),x=[...new Set([a.x,l.x,...i.flatMap(e=>[e.x-18,e.x+e.width+18]),...o.flatMap(e=>e.points.flatMap(e=>w(e.x)))])].sort((e,t)=>e-t),b=[...new Set([a.y,l.y,...i.flatMap(e=>[e.y-18,e.y+e.height+18]),...o.flatMap(e=>e.points.flatMap(e=>w(e.y)))])].sort((e,t)=>e-t),k=(e,t,a)=>(e*b.length+t)*2+a,M=`edge:${s.edge.id}`,z=fb(r,d),[C,_]=[!1,!0].map(e=>n.filter(t=>t.arrowId.startsWith(uo)===e)),q=C.length>0?fb(C,8):void 0,L=_.length>0?fb(_,24):void 0,S=[...ss([e,a]),...ss([l,t])],B=(e,t)=>p?Math.abs(x[e]-l.x)+Math.abs(b[t]-l.y):0,A=x.indexOf(a.x),P=b.indexOf(a.y),V={x:A,y:P,axis:+(e.x===a.x),cost:0,estimate:B(A,P)},H=(e,t)=>{let a="x"===t?"width":"height",l=[],s=g?-.01:.01;return o=>l[o]??=i.filter(l=>e[o]>l[t]+s&&e[o]<l[t]+l[a]-s)},[I,$]=[H(x,"x"),H(b,"y")],F=(f=[],m=0,v=(e,t)=>e.item.estimate<t.item.estimate||e.item.estimate===t.item.estimate&&e.order>t.order,y=(e,t)=>{[f[e],f[t]]=[f[t],f[e]]},{get size(){return f.length},push(e){f.push({item:e,order:m++});for(let e=f.length-1;e>0;){let t=e-1>>1;if(!v(f[e],f[t]))break;y(e,t),e=t}},pop(){let e=f[0],t=f.pop();if(f.length>0){f[0]=t;for(let e=0;;){let t=2*e+1,a=t+1,l=e;if(t<f.length&&v(f[t],f[l])&&(l=t),a<f.length&&v(f[a],f[l])&&(l=a),l===e)break;y(e,l),e=l}}return e.item}});F.push(V);let O=new Map([[k(V.x,V.y,V.axis),0]]),E=new Map;for(let a=0;F.size&&a<c;a+=1){let a=F.pop();if(a.cost!==O.get(k(a.x,a.y,a.axis)))continue;let i={x:x[a.x],y:b[a.y]};if(i.x===l.x&&i.y===l.y){let l=[];for(let e=a;e;e=e.previous)l.unshift({x:x[e.x],y:b[e.y]});return uR([e,...l.filter((e,t)=>0===t||t===l.length-1||(l[t-1].x!==e.x||e.x!==l[t+1].x)&&(l[t-1].y!==e.y||e.y!==l[t+1].y)),t])}for(let[e,t,l]of[[-1,0,0],[1,0,0],[0,-1,1],[0,1,1]]){let s=a.x+e,o=a.y+t;if(s<0||o<0||s>=x.length||o>=b.length)continue;let r={x:x[s],y:b[o]},n=(Math.min(s,a.x)*b.length+Math.min(o,a.y))*2+l;if(!E.has(n)){let e=ss([i,r],0)[0],t=ss([i,r])[0],{beside:s,overlaps:o}=t?z(t,M):{beside:0,overlaps:0},d=t&&q?q(t,M):void 0,c=t&&L?L(t,M):void 0;E.set(n,(0===l?$(a.y):I(a.x)).some(t=>sn(e,t)||g&&t.id.startsWith("node:")&&uj(e,t))||S.some(t=>sr(e,t))?void 0:Math.abs(r.x-i.x)+Math.abs(r.y-i.y)+1e4*o+1e3*s+(d?(d.beside+d.overlaps)*1e3:0)+(c?(c.beside+c.overlaps)*1e3:0)+(u?1e4*u(i,r,M):0)+(h&&t?320*h.step(t.orientation,t.staticCoordinate,t.min,t.max,M):0))}let d=E.get(n);if(void 0===d)continue;let c=a.cost+d+24*(l!==a.axis),p=k(s,o,l);c>=(O.get(p)??1/0)||(O.set(p,c),F.push({x:s,y:o,axis:l,cost:c,estimate:c+B(s,o),previous:a}))}}}(t,a,T,R,l,e,i,N.segments,N.outlines,ea?0:K,ea?1/0:5e3,n,N.crossings,W,N.heads);if(s)return fe([Q,s],l,u,e,N,W)}return Q}(e,r,n,l,i,s):uR([r,n]),c=e.pinned?uR(fT(d)):d;return{type:"arrow",id:`edge:${o.id}`,edgeId:o.id,sourceNodeId:o.source,targetNodeId:o.target,points:c,...o.label?{label:o.label}:{}}}(r,t,a,[...l,...d.filter(e=>e.nodeId!==`branch-label:${r.edge.id}`&&e.nodeId!==`loop:${r.edge.id}`),...ui(i.groups,r),...i.lanes?.continuations.has(r.edge.id)?g:h],[...p,...c,...u],i))}return e.map(e=>u.find(t=>t.edgeId===e.edge.id))}function fC(e){let t=new Map;for(let a of e)for(let e of[uk(a.source.nodeId,a.sourceEdge),uk(a.target.nodeId,a.targetEdge)])t.set(e,(t.get(e)??0)+1);return t}function f_(e,t,a){if((a.get(uk(e.target.nodeId,e.targetEdge))??0)<2)return!1;let l=fT(t.points);if(l.length<3)return!1;let[i,s,o]=l.slice(-3);if(Math.abs(o.x-s.x)+Math.abs(o.y-s.y)>=72)return!1;let{target:r}=e,[n,d,c]=.01>=Math.abs(i.y-s.y)?[i.x,r.x,r.width]:[i.y,r.y,r.height];return n<d-.01||n>d+c+.01}function fq(e,t,a,l,i){let s=gP(a),o=fC(e),r=new Set(o.keys()),n=[];for(let[a,d]of t.entries()){let c=e[a];if(s.has(c.edge.id)||c.pinned?.target!==void 0||!("hooked"===i?sL([{id:d.id,points:d.points}],l).some(e=>"endpoint-jog"===e.kind&&"end"===e.endpoint):"cornered"===i?f_(c,d,o):t.some(e=>e!==d&&fR(d.points,e.points,d.points.length-3,!1)>0)))continue;let p=ss(d.points),h=p.at(-1),g=p.findLast(e=>e.orientation!==h?.orientation);if(!h||!g)continue;let u=d.points[g.segmentIndex],f=d.points[g.segmentIndex+1],m="horizontal"===g.orientation?f.x>u.x?"left":"right":f.y>u.y?"top":"bottom";m===c.targetEdge||r.has(uk(c.target.nodeId,m))||(n.push({route:c,side:c.targetEdge}),r.add(uk(c.target.nodeId,m)),c.targetEdge=m)}return n}function fL(e,t,a,l){let i,s=e.flatMap(e=>ss(e.points).map(t=>{let a=e.points[t.segmentIndex],l=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?l.x:l.y}})),o=[];for(let[e,a]of s.entries()){for(let t of s.slice(e+1)){if(a.arrowId===t.arrowId||!sr(a,t))continue;let e=a.isFirstSegment&&t.isFirstSegment&&a.startBindingId===t.startBindingId;sd(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&&sn(a,e)&&o.push([a.arrowId])}let r=a?[...o,...function(e,t){let a=[],l=t.frames.map(e=>ur(e.box));for(let i of e){let e=ss(i.points),s=new Set([...gU(t,t.groupOf.get(i.sourceNodeId)),...gU(t,t.groupOf.get(i.targetNodeId))]),o=new Set(gU(t,gX(t,i.sourceNodeId,i.targetNodeId)));for(let[r,n]of t.frames.entries()){let t=s.has(n.id);(e.some(e=>gO(n).some(t=>sn(e,t))||!t&&sn(e,n.box)||l[r].some(t=>t.orientation===e.orientation&&8>Math.abs(t.staticCoordinate-e.staticCoordinate)&&so(t,e)>8))||o.has(n.id)&&i.points.some(e=>!un(e,n.box)))&&a.push([i.id])}}return a}(e,a)]:o;return l?[...r,...(i=up(l),e.flatMap(e=>ss(e.points).some(e=>l.frames.some(t=>sn(e,t.header))||i.some(t=>t.orientation===e.orientation&&8>Math.abs(t.staticCoordinate-e.staticCoordinate)&&so(t,e)>8))||e.points.some(e=>!un(e,l.pool))?[[e.id]]:[]))]:r}function fS(e,t){let a=new Map(t.map(e=>[e.nodeId,e])),l=0;for(let t of e)for(let[e,i,s]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||!s)continue;if(iV(t.shape)){let e=e=>Math.max(Math.abs(e.x-um(t).x)/(t.width/2),Math.abs(e.y-um(t).y)/(t.height/2));e({x:i.x+(s.x-i.x)*1e-4,y:i.y+(s.y-i.y)*1e-4})<e(i)-1e-9&&(l+=1);continue}let o=(i.x+(s.x-i.x)*1e-4-um(t).x)/(t.width/2),r=(i.y+(s.y-i.y)*1e-4-um(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&&(l+=1)}return l}function fB(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 fA(e,t,a){return{x:e.x+t,y:e.y+a}}let fP={ports:!1,reader:!1,sides:!1,repair:!1};function fV(e,t){let a=t?gY(e):void 0;if(!a||!t)return new Set;let l=new Map([["",a.top],...a.groups.map(e=>[e.group.id,e.diagram])]);return new Set([...t].flatMap(([e,{bandOf:t}])=>l.get(e).edges.filter(e=>(t.get(e.source)??0)!==(t.get(e.target)??0)).map(e=>e.id)))}function fH(e){let{edgeArrows:t,groups:a,nodeShapes:l,routedEdges:i}=e,s=new Set;if(!a)return s;let o=new Map(t.map(e=>[e.id,e]));for(let e of fL(t,l,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&&s.add(e)}}let r=fw([...t],i,l,a,!1),n=a.frames.flatMap(e=>ur(e.box));for(let e of r){let t=o.get(e.id.slice(0,-6)),l=t?a.groupOf.get(t.sourceNodeId):void 0,i=fp(e,fr(e.text,e.maxWidth??160));if(a.zoned)for(let e of a.frames)(ur(e.box).some(e=>sn(e,i))||gO(e).some(e=>fh(i,e)))&&s.add(e.id);void 0!==l&&(n.some(e=>sn(e,i))||a.frames.some(e=>gO(e).some(e=>fh(i,e))))&&s.add(l)}return s}function fI(e){let{edgeArrows:t,groups:a,nodeShapes:l}=e,i=new Set,s=uJ(e);if(!a||!s)return i;for(let e of t){let t=new Set([e.sourceNodeId,e.targetNodeId]);for(let o of ss(fT(e.points)))if(!o.isFirstSegment&&!o.isLastSegment)for(let e of l){if(!uG(e,t)||!uK(o,e,s))continue;let l=a.frames.find(t=>t.id===a.groupOf.get(e.nodeId));if(!l)continue;let[r,n,d,c]="horizontal"===o.orientation?[e.y,e.height,l.box.y+gI,l.box.y+l.box.height]:[e.x,e.width,l.box.x,l.box.x+l.box.width],p=o.staticCoordinate<r?r-s.gap-1:r+n+s.gap+1;o.staticCoordinate>d&&o.staticCoordinate<c&&(p<d+8||p>c-8)&&i.add(l.id)}}return i}function f$({edgeArrows:e,groups:t,nodeShapes:a}){let l=sx(fX([...a,...ul(t)],e)),[i,s]=[90/l,150/l];return e.reduce((e,t)=>e+(t.sourceNodeId===t.targetNodeId?0:f7(fT(t.points),i,s).length),0)}function fF(e,t,a,l){let i="TB"===l||"BT"===l,s=e=>i?{low:e.x,high:e.x+e.width}:{low:e.y,high:e.y+e.height},o=e=>i?{low:e.y,high:e.y+e.height}:{low:e.x,high:e.x+e.width},[r,n,d,c]=[s(e),s(t),o(t),o(e)];return a.some(a=>{if(a.nodeId===e.nodeId||a.nodeId===t.nodeId)return!1;let l=o(a),{low:i,high:p}=s(a);return l.low<d.high&&d.low<l.high&&l.low<c.high&&c.low<l.high&&i>Math.min(r.high,n.high)-.01&&p<Math.max(r.low,n.low)+.01})}function fO(e,t,a=gJ){let l=new Map(a.zoneSlack??[]),i=fU(e,t,a,l);if(!i.groups)return i;let s=e=>fL(e.edgeArrows,e.nodeShapes,e.groups).length+fH(e).size,o=s(i);for(let r=0;r<3&&o>0;r+=1){let r=fH(i);if(0===r.size)break;let n=fU(e,t,a,l=new Map([...l,...[...r].map(e=>[e,(l.get(e)??0)+36])])),d=s(n);d<o&&([i,o]=[n,d])}return i}function fE(e,t,a,l){var i=e,s=t.ports?function(e,t,a=!1,l=uL){let i=uq(e,t),s=new Map;for(let t of e)for(let e of["source","target"]){let a=uk(t[e].nodeId,"source"===e?t.sourceEdge:t.targetEdge);s.set(a,[...s.get(a)??[],{endpoint:e,key:ub({edgeId:t.edge.id,endpoint:e}),route:t}])}let o=[...s.values()].sort((e,t)=>t.length-e.length);for(let e=0;e<3;e+=1)for(let e of o){let o=uA(e[0]),r=e[0].route[e[0].endpoint],n=new Map(e.map(e=>[e,function(e,t,a){let l=function(e,t,a){let l={endpoint:"source"===e.endpoint?"target":"source",key:ub({edgeId:e.route.edge.id,endpoint:"source"===e.endpoint?"target":"source"}),route:e.route},i=e.route[e.endpoint],s=uA(e),o=uA(l),r=uP(s),n=uB[s];if(uM(e.route)){let t=uz(e.route,e.endpoint)*Math.max(0,uV(i,s));return{desired:t,high:t,low:t,priority:2}}let d=ux(i,s,t.get(e.key)??0),c=ux(e.route[l.endpoint],o,t.get(l.key)??0),p=(c.x-d.x)*n.x+(c.y-d.y)*n.y;if(uP(o)!==r&&p>=uH(e,d)){let e=u7(c,o,uH(l,c)),t=uB[o][r],a=e[r]-um(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)=>uy(e.route[e.endpoint],t)&&a.get(uk(e.route[e.endpoint].nodeId,t))?.length===1,g=o===uS[s]&&p>0;if(h(e,s)&&!(g&&"target"===e.endpoint&&h(l,o)))return{desired:0,high:0,low:0,priority:2};let u=c[r]-um(i)[r];return g&&Math.abs(u)<=uV(i,s)?{desired:u,high:u,low:u,priority:2}:uI}(e,t,a),i=e.route[e.endpoint];if("composite"!==i.kind||"top"!==uA(e))return l;let s=sT({...i,name:i.label}),o=s.x+s.width+18-um(i).x;return{...l,desired:Math.max(o,l.desired),low:Math.max(o,l.low),high:Math.max(o,l.high),priority:3}}(e,i,s)])),d=function(e,t,a,l){let i=e=>{let t="source"===e.endpoint?"target":"source";if(!l||uM(e.route))return uC(e.route,e.endpoint);let i=e.route[t],s="source"===t?e.route.sourceEdge:e.route.targetEdge,o=ub({edgeId:e.route.edge.id,endpoint:t});return u7(ux(i,s,a.get(o)??0),s,36)[uP(uA(e))]},s=[...e].sort((e,t)=>i(e)-i(t)||(e.route.pair??0)-(t.route.pair??0));for(let e of[1,-1]){let a=s.map((e,a)=>({index:a,lane:t.get(e).lane,slot:e})).filter(({lane:t})=>void 0!==t&&Math.sign(t)===e),l=[...a].sort((e,t)=>e.lane-t.lane);a.forEach(({index:e},t)=>{s[e]=l[t].slot})}return s}(e,n,i,a),c=d.filter(e=>"source"===e.endpoint),p=c.filter(e=>e.route.edge.label),h=c.length>1&&p.length>0&&(!g_(p[0].route.source.kind)||t&&p.length>1)?Math.max(...p.map(e=>{let t=fn(e.route.edge.label);return("x"===uP(o)?t.width:t.height)+24})):0;"state"===r.kind&&function(e){for(let[t,a]of e.entries()){let{route:l}=a;if("source"!==a.endpoint||void 0!==l.pair||uM(l))continue;let i=0===t?-1:t===e.length-1?1:void 0;e.length>1&&void 0!==i?l.labelSide=i:delete l.labelSide}}(d);let g=function(e,t,a){let l=e.map((e,a)=>t.slice(0,a).reduce((e,t)=>e+t,0)),i=l.at(-1)??0;if(i>2*a)return l.map(e=>e-i/2);let s=e.map(()=>-1/0),o=e.map(()=>1/0),r=()=>{let e=s.map((e,t)=>Math.max(e-l[t],-a)),t=o.map((e,t)=>Math.min(e-l[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)){s[t]=e[t].low,o[t]=e[t].high;let{highs:a,lows:l}=r();l.some((e,t)=>e>a[t]+.01)&&(s[t]=-1/0,o[t]=1/0)}let{highs:n,lows:d}=r();return(function(e,t,a){let l=[];for(let[i,s]of e.entries())for(l.push({count:1,high:a[i],low:t[i],sum:s,value:uw(s,t[i],Math.max(t[i],a[i]))});l.length>1&&l.at(-2).value>l.at(-1).value;){let e=l.pop(),t=l.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=uw(t.sum/t.count,t.low,Math.max(t.low,t.high))}return l.flatMap(e=>Array(e.count).fill(e.value))})(e.map((e,t)=>e.desired-l[t]),d,n).map((e,t)=>e+l[t])}(d.map(e=>n.get(e)),d.slice(1).map((e,t)=>Math.max("state"===r.kind?function(e,t,a){let l=(e,t)=>{let{route:l}=e,i="x"===uP(a);if("source"!==e.endpoint||!l.edge.label||uM(l)||u$(l)!==t)return 0;let s=fn(l.edge.label,g_(l.source.kind));return(i?s.width:s.height)+24};return Math.max(l(e,1),l(t,-1))}(d[t],e,o):h,"target"===e.endpoint||"target"===d[t].endpoint?l:18)),uV(r,o));d.forEach((e,t)=>i.set(e.key,g[t]))}return i}(e,t.repair,a,l?54:uL):uq(e,t.repair);for(let e of i)for(let t of["source","target"]){let a=e.pinned?.[t];void 0!==a&&s.set(ub({edgeId:e.edge.id,endpoint:t}),a)}return s}function fU(e,t,a,l){let i,s,o="orthogonal"===e.layout.edgeRouting,{anchors:r,endRun:n,placement:d}=md.get(e)??{},c=l=>fE(l,t,a.crossingRepair,g6(e)),{wrap:p}=a,h=fV(e,a.zoneWraps),{groups:g,lanes:u,nodes:f}=d?{nodes:e.nodes.map(e=>{let t=d.get(e.id);if(!t)throw Error(`Cannot render node "${e.id}" without a placement.`);return{...gq(e),x:t.x,y:t.y,width:t.width,height:t.height}})}:g2(e,new Map,new Map,a,l),{direction:m}=e.layout,v=e=>void 0!==e&&void 0!==g&&g.across.has(e),y=e=>v(g?.groupOf.get(e))?gK[m]:m,w=e=>g&&v(gX(g,e.source,e.target))?gK[m]:m,x=new Map([...f,...ua(g)].map(e=>[e.nodeId,e])),b=e.edges.map((e,t)=>(function(e,t,a,l,i=!1){let s=a.get(e.source),o=a.get(e.target);if(!s||!o)throw Error(`Cannot render edge "${e.id}" with unresolved nodes.`);let{sourceEdge:r,targetEdge:n}=i?{sourceEdge:gZ[l],targetEdge:uS[gZ[l]]}:uv(s,o,l);return{edge:e,index:t,source:s,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:l}=e,i={LR:l.x>=t.x+t.width,RL:l.x+l.width<=t.x,TB:l.y>=t.y+t.height,BT:l.y+l.height<=t.y}[m],s=gZ[gK[m]],o=!0===a.aroundRanks&&!i&&fF(t,l,f,m);e.sourceEdge=i||o?gZ[m]:s,e.targetEdge=o?gZ[m]:uS[s]}if(n)for(let e of b)e.endRun=n;u&&uu(b,u);let k=o&&t.ports;for(let e of new Set(b.map(e=>y(e.source.nodeId))))fs(b.filter(t=>y(t.source.nodeId)===e),e,k);if(u&&o?!function(e,t,a){let[l,i]=t.vertical?["x","y"]:["y","x"],s=gZ[a],o=uB[s][i],r=e=>t.vertical?e<0?"left":"right":e<0?"top":"bottom";for(let a of new Set(e.filter(e=>g_(e.source.kind)).map(e=>e.source))){let n=e.filter(e=>e.source===a&&!uM(e));if(n.length>3)continue;let d=e=>t.laneOf.get(e.target.nodeId)===t.laneOf.get(a.nodeId)?0:Math.sign(um(e.target)[l]-um(a)[l]),c=e=>(um(e.target)[i]-um(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=>d(t)===e).sort((e,t)=>Number(h(t))-Number(h(e))||c(e)-c(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===d(e))),u.sort((e,t)=>c(e)-c(t)))){let t=0>c(e)?[r(1),r(-1),s]:[s,r(-1),r(1)];e.sourceEdge=t.find(e=>!g.has(e))??s,g.add(e.sourceEdge)}}}(b,u,m):o&&!p.lineBreaks&&function(e,t,a,l){let i=gZ[gK[l]],s=uS[i],[o,r,n]="TB"===l||"BT"===l?["y","height","x"]:["x","width","y"],d=e=>a.bandOf.get(e.nodeId)??0,c=(e,a)=>t.some(t=>t.nodeId!==e.nodeId&&d(t)===d(e)&&Math.min(t[o]+t[r],e[o]+e[r])-Math.max(t[o],e[o])>.01&&a*(um(t)[n]-um(e)[n])>0);for(let t of e){if(!a.continuations.has(t.edge.id))continue;c(t.source,1)||a.leaveForward?.has(t.edge.id)||(t.sourceEdge=i);let{target:o}=t;if(c(o,-1))continue;let r=e.filter(e=>e.source.nodeId===o.nodeId);if(r.some(e=>e.sourceEdge===s)&&g_(o.kind)){let[e,t]=[...r].sort((e,t)=>um(e.target)[n]-um(t.target)[n]);if(2!==r.length||um(t.target)[n]-um(o)[n]<1)continue;e.sourceEdge=gZ[l],t.sourceEdge=i}r.every(e=>e.sourceEdge!==s)&&(t.targetEdge=s)}}(b,f,p,m),o){for(let t of(!function(e,t){let a=new Map;for(let l of e.filter(uM)){let i=t(l),s=uS[gZ[i]],o=t=>e.filter(e=>!uM(e)&&(e.source===l.source&&e.sourceEdge===t||e.target===l.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,s]),...r.map(e=>[e,gZ[i]])],d=a.get(l.source.nodeId)??new Set,[c,p]=n.find(([e,t])=>!d.has(`${e}:${t}`))??n[0];d.add(`${c}:${p}`),a.set(l.source.nodeId,d),l.sourceEdge=c,l.targetEdge=p}}(b,e=>w(e.edge)),!function(e,t,a=()=>t.layout.direction){let l=gP(t);for(let t of e.filter(e=>l.has(e.edge.id)&&!uM(e))){let l=a(t),i="LR"===l||"RL"===l,s=i?um(t.source).y<um(t.target).y:um(t.source).x<um(t.target).x,o=[...i?s?["top","bottom"]:["bottom","top"]:s?["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)),d=new Set(e.filter(e=>e!==t&&e.target===t.target).map(e=>e.targetEdge)),c=new Set(e.filter(e=>e!==t&&e.source===t.source).map(e=>e.sourceEdge)),p=g_(t.source.kind)?[t.sourceEdge,...o]:o;t.targetEdge=o.find(e=>!r.has(e)&&!d.has(e))??o.find(e=>!r.has(e))??t.targetEdge,t.sourceEdge=p.find(e=>!n.has(e)&&(!g_(t.source.kind)||!c.has(e))&&(t.source!==t.target||e!==t.targetEdge))??t.sourceEdge}}(b,e,e=>w(e.edge)),md.get(e)?.pairedReturns&&function(e,t,a,l,i){for(let s of e){if(!t.has(s.edge.id)||uM(s)||i?.has(s.edge.id))continue;let o=e.find(e=>void 0===e.pair&&!i?.has(e.edge.id)&&!t.has(e.edge.id)&&e.source===s.target&&e.target===s.source&&e.targetEdge===uS[e.sourceEdge]);if(!o)continue;let[r,n]=[um(s.source),um(s.target)],d=new Set([s.source.nodeId,s.target.nodeId]),c=new Set([...d].flatMap(e=>l?gU(l,l.groupOf.get(e)??e):[e]));[...a.filter(e=>!d.has(e.nodeId)),...(l?.frames??[]).filter(e=>!c.has(e.id)).map(e=>ut(e.elementId,e.box))].some(e=>uO(r,n,e))||(s.sourceEdge=o.targetEdge,s.targetEdge=o.sourceEdge,o.pair=-1,s.pair=1)}}(b,gP(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=gZ[t],l="TB"===t||"BT"===t?["left","right"]:["top","bottom"];for(let t of e){if(uM(t)||void 0!==t.pinned)continue;let i=t.source,s=t=>e.some(e=>e.target===i&&e.targetEdge===t),o=a=>e.some(e=>e!==t&&e.source===i&&e.sourceEdge===a);if(!s(t.sourceEdge))continue;let r=[a,...l].filter(e=>!s(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 l=t.get(ub({edgeId:a.edge.id,endpoint:e}));l&&("source"===e?a.sourceEdge=l.side:a.targetEdge=l.side,a.pinned={...a.pinned,[e]:l.offset},void 0!==l.run&&(a.runs={...a.runs,[e]:l.run}))}}(b,r),i=c(b),s=function(e,t){let a=new Map;for(let l of e)for(let e of["source","target"]){let i=l[e];if(void 0!==gC(i))continue;let s="source"===e?l.sourceEdge:l.targetEdge,o="top"===s||"bottom"===s?"width":"height",r=2*(16+Math.abs(t.get(ub({edgeId:l.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:gz(n,0))}return a}(b,i)}else{let a=uU(b,e,f,t.repair);i=a.offsets,s=a.minimumSizes}let M=o&&!d&&(t.repair||g||u)?u?uX(b.filter(e=>e.edge.label||!ug(e,u)),i,!0):uX(b,i):new Map;if(!d&&(s.size>0||M.size>0)){({groups:g,lanes:u,nodes:f}=g2(e,s,M,a,l));let r=new Map([...f,...ua(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,uv(t.source,t.target,e.layout.direction));o?i=c(b):(u&&uu(b,u),fs(b,e.layout.direction,k),i=uU(b,e,f,t.repair).offsets)}f=function(e,t,a,l){let i=new Map;for(let s of t){if(void 0===gC(s))continue;let o=e.filter(e=>e.source===s||e.target===s),r=o[0];if(1!==o.length||!r||uM(r))continue;let n=r.source===s?"target":"source",d=r[n],c="source"===n?r.sourceEdge:r.targetEdge;if(("source"===n?r.targetEdge:r.sourceEdge)!==uS[c])continue;let p=uP(c),h="x"===p?"width":"height",g=ux(d,c,l.get(ub({edgeId:r.edge.id,endpoint:n}))??0),u={...s,[p]:g[p]-s[h]/2},f=fg(u,18),m=a?.groupOf.get(s.nodeId),v=a?.frames.find(e=>e.id===m),y=new Set(a?gU(a,m):[]);t.every(e=>e===s||!fh(f,i.get(e.nodeId)??e))&&(a?.frames??[]).every(e=>y.has(e.id)||!fh(f,e.box)&&gO(e).every(e=>!fh(f,e)))&&(!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(s.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 l=t.vertical?"x":"y",i=t.vertical?"width":"height",s=e.filter(e=>a.continuations.has(e.edge.id));for(let e of s){let o=a.bandOf.get(e.source.nodeId)??0,[r,n]=[t.pools[o],t.pools[o+1]];if(!n)continue;let d=s.filter(e=>(a.bandOf.get(e.source.nodeId)??0)===o);e.lane={at:(r[l]+r[i]+n[l])/2+(d.indexOf(e)-(d.length-1)/2)*18,vertical:t.vertical}}}(b,u,p):function(e,t,a,l){let i="TB"===l||"BT"===l,[s,o]=i?["x","width"]:["y","height"];for(let l of e){if(!a.continuations.has(l.edge.id))continue;let e=a.bandOf.get(l.source.nodeId)??0,r=e=>t.filter(t=>(a.bandOf.get(t.nodeId)??0)===e);l.lane={at:(Math.max(...r(e).map(e=>e[s]+e[o]))+Math.min(...r(e+1).map(e=>e[s])))/2,vertical:i}}}(b,f,p,m);let z=g?.zoned===!1?a.zoneWraps?.get(""):void 0;o&&g&&z&&function(e,t,a,l,i){let s="TB"===i||"BT"===i,[o,r]=s?["x","width"]:["y","height"],[n,d]=s?["y","height"]:["x","width"],c=e=>{let t;return l.bandOf.get(void 0===(t=a.groupOf.get(e))?e:gR(t))??0},p=[...a.frames.map(e=>({band:l.bandOf.get(gR(e.id))??0,box:g3([e.box,e.labelBox])})),...t.flatMap(e=>a.groupOf.has(e.nodeId)?[]:[{band:c(e.nodeId),box:e}])],h=e.filter(e=>c(e.target.nodeId)===c(e.source.nodeId)+1);for(let e of h){let t=c(e.source.nodeId);if(h.some(a=>a!==e&&c(a.source.nodeId)===t))continue;let a=p.filter(({band:e})=>e===t+1),[i,g]=[Math.min(...a.map(({box:e})=>e[n])),Math.max(...a.map(({box:e})=>e[n]+e[d]))],u=l.rise?p.filter(({band:e,box:a})=>e<=t&&a[n]<g&&a[n]+a[d]>i):[];e.lane={at:(Math.max(...(u.length>0?u:p.filter(({band:e})=>e===t)).map(({box:e})=>e[o]+e[r]))+Math.min(...a.map(({box:e})=>e[o])))/2,vertical:s}}}(b,f,g,z,m);let C=[...f,...ul(g),...uh(u)],_=sx({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))}),q={guided:t.repair,...t.reader?{readerScale:_}:{},...p.continuations.size>0?{bandOf:p.bandOf}:{},...g?{groups:g}:{},...u?{lanes:u}:{},...a.avoidCrossings?{avoidCrossings:!0}:{},...a.clearHeads?{clearHeads:!0}:{}},L=fz(b,e.layout.edgeRouting,i,f,q);if(o&&t.sides){let t=fq(b,L,e,_,"hooked");if(t.length>0){let e=c(b),a=fz(b,"orthogonal",e,f,q),[l,s]=[L,a].map(e=>{var t,a,l;let i;return t=f,a=g,l=u,i=sL(e.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),_).length,{hard:fL(e,t,a,l).length,reader:i}});if(s.hard<=l.hard&&s.reader<l.reader)[L,i]=[a,e];else for(let{route:e,side:a}of t)e.targetEdge=a}let l=a.crossingRepair?fq(b,L,e,_,"crossed"):[];if(l.length>0){let e=c(b),t=fz(b,"orthogonal",e,f,q);if(fL(t,f,g,u).length<=fL(L,f,g,u).length&&fj({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 l)e.targetEdge=t}}return o&&t.repair&&(L=function(e,t,a,l,i){let s=fL(e,l,i.groups,i.lanes),o=t.map((e,t)=>t);for(let r=0;r<4&&s.length>0;r+=1){let r=e=>o.findIndex(a=>`edge:${t[a].edge.id}`===e),[n,d]=s[0],[c,p]=void 0===d?[0,r(n)]:[Math.min(r(n),r(d)),Math.max(r(n),r(d))];if(p<=c)break;let h=[...o];h.splice(c,0,...h.splice(p,1));let g=fz(t,"orthogonal",a,l,i,h),u=fL(g,l,i.groups,i.lanes);if(u.length>=s.length)break;[e,s,o]=[g,u,h]}return e}(L,b,i,f,q)),{byApproach:a.crossingRepair,edgeArrows:L,...g?{groups:g}:{},...u?{lanes:u}:{},nodeShapes:f,polish:t,portOffsets:i,routeOptions:q,routedEdges:b}}function fX(e,t,a=[]){let l=[...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}=fr(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(...l.map(e=>e.x))-Math.min(...l.map(e=>e.x)),height:Math.max(...l.map(e=>e.y))-Math.min(...l.map(e=>e.y))}}function fT(e){return e.filter((t,a)=>{let[l,i]=[e[a-1],e[a+1]];return!l||!i||!(.01>=Math.abs(l.x-t.x)&&.01>=Math.abs(t.x-i.x)||.01>=Math.abs(l.y-t.y)&&.01>=Math.abs(t.y-i.y))})}function fR(e,t,a=0,l=!0){let i=l?fT(e.slice(Math.max(0,a))):e.slice(Math.max(0,a)),s=l?fT(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,d=0;for(let e=0;e<i.length-1;e+=1)for(let t=0;t<s.length-1;t+=1){let[a,l,c,p]=[i[e],i[e+1],s[t],s[t+1]],[h,g]=r(a,l)&&n(c,p)?[[a,l],[c,p]]:n(a,l)&&r(c,p)?[[c,p],[a,l]]:[];h&&g&&o(g[0].x,h[0].x,h[1].x)&&o(h[0].y,g[0].y,g[1].y)&&(d+=1)}return d}function fY(e,t=!0){return e.reduce((a,l,i)=>a+e.slice(i+1).reduce((e,a)=>e+fR(l.points,a.points,0,t),0),0)}function fD(e,t,a=!0){let l=sx(fX(t,e)),i=e.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),s=sB(i,l);return sL(i,l).filter(e=>a||"endpoint-jog"!==e.kind).length+i.filter(e=>s(e).arrowheadsCrossed>0).length}function fG(e){return e.filter(e=>{let[t,a]=[e.points[0],e.points.at(-1)],l=Math.abs(a.x-t.x)+Math.abs(a.y-t.y);return uQ(e.points)>2*l+72+96}).length}function fZ(e){let t=[...e.nodeShapes,...ul(e.groups),...uh(e.lanes)],a=e.edgeArrows.map(e=>({id:e.id,edgeId:e.edgeId,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId,endArrowhead:null!==e.endArrowhead})),l=sB(a,sx(fX(t,e.edgeArrows)));return new Set(a.filter(e=>l(e).arrowheadsCrossed>0).map(e=>e.edgeId))}function fj(e,t,a=!1,l=!0,i=!1,s=!0){let[o,r]=[e,t].map(e=>fY(e.edgeArrows,l)),[n,d]=[e,t].map(e=>fX([...e.nodeShapes,...ul(e.groups),...uh(e.lanes)],e.edgeArrows)),[c,p]=[n,d].map(({width:e,height:t})=>gQ(e,t));return(a?o<r:o<=r)&&(c<2.45||c<=p+.01||i&&(({width:e,height:t})=>Math.max(e,t))(n)<=(({width:e,height:t})=>Math.max(e,t))(d)+.01)&&fD(e.edgeArrows,[...e.nodeShapes,...ul(e.groups),...uh(e.lanes)],s)<=fD(t.edgeArrows,[...t.nodeShapes,...ul(t.groups),...uh(t.lanes)],s)}function fN(e,t=!1){let a,{groups:l,lanes:i,nodeShapes:s,routedEdges:o}=e,r=e.edgeArrows,n=[...s,...ul(l),...uh(i)],d=a=>({crossings:fY(a),defects:fL(a,s,l,i).length,findings:fD(a,n),heads:t?fZ({...e,edgeArrows:[...a]}).size:0,inward:fS(a,s),labels:fx([...a],o,s,l,!0,i).touches}),c=[void 0,t?uJ(e):void 0];for(let[l,i]of e.edgeArrows.entries()){let e=new Set([i.sourceNodeId,i.targetNodeId]),o=t=>uW(t,s,e);for(let[i,n]of c.entries()){if(i>0&&!n)break;let c=t=>n?function(e,t,a,l){return ss(fT(e)).filter(e=>!e.isFirstSegment&&!e.isLastSegment&&t.some(t=>uG(t,a)&&uK(e,t,l))).length}(t,s,e,n):o(t),p=c(r[l].points);for(let i=0;p>0&&(t||0===i);i+=1){a??=d(r);let t=!1,i=o(r[l].points);for(let h of function(e,t,a,l){let i=fT(e),s=[];for(let e of ss(i))if(!e.isFirstSegment&&!e.isLastSegment)for(let o of t){if(!uG(o,a)||sn(e,o)||!(l?uK(e,o,l):uD(e,o,12)))continue;let t=l?l.gap:12,[r,n]="horizontal"===e.orientation?[o.y,o.height]:[o.x,o.width];for(let a of[r-t-1,r+n+t+1]){let t=i.map((t,l)=>l===e.segmentIndex||l===e.segmentIndex+1?"horizontal"===e.orientation?{x:t.x,y:a}:{x:a,y:t.y}:t);fM(i,t)&&s.push(uR(t))}}return s}(r[l].points,s,e,n)){let e=c(h);if(!fk(h)||e>=p||void 0!==n&&o(h)>i)continue;let s=r.map((e,t)=>t===l?{...e,points:h}:e),g=d(s);if(g.defects<=a.defects&&g.crossings<=a.crossings&&g.findings<=a.findings&&g.heads<=a.heads&&g.inward<=a.inward&&g.labels<=a.labels){[r,a,p,t]=[s,g,e,!0];break}}if(!t)break}}}return r===e.edgeArrows?e:{...e,edgeArrows:r}}function fW(e){let{groups:t,lanes:a,nodeShapes:l,routedEdges:i}=e,s=e.edgeArrows,o=e=>fx([...e],i,l,t,!0,a);if(0===o(s).shortfalls.length)return e;let r=[...l,...ul(t),...uh(a)],n=e=>{let i=o(e);return{labels:i,shortfall:i.shortfalls.reduce((e,t)=>e+t.shortfall,0),touches:i.touches,crossings:fY(e),defects:fL(e,l,t,a).length,findings:fD(e,r),nodeFindings:fD(e,l),inward:fS(e,l),near:e.reduce((e,t)=>e+uW(t.points,l,new Set([t.sourceNodeId,t.targetNodeId])),0)}},d=n(s);for(let e=0;e<3&&d.shortfall>0;e+=1){let e=!1;for(let t of d.labels.shortfalls){for(let[a,l]of s.entries())if(a!==t.index){for(let i of function(e,t){let{box:a,own:l}=t,i=fT(e),s=[];for(let e of[6,1].map(e=>l+8+e))for(let t of ss(i)){if(t.isFirstSegment||t.isLastSegment||fu(a,t)>=e)continue;let[l,o]="horizontal"===t.orientation?[a.y,a.height]:[a.x,a.width];for(let a of[l-e,l+o+e]){let e=i.map((e,l)=>l===t.segmentIndex||l===t.segmentIndex+1?"horizontal"===t.orientation?{x:e.x,y:a}:{x:a,y:e.y}:e);fM(i,e)&&s.push(uR(e))}}return s}(l.points,t)){if(!fk(i))continue;let t=s.map((e,t)=>t===a?{...e,points:i}:e),l=n(t);if(l.shortfall<d.shortfall&&l.defects<=d.defects&&l.crossings<=d.crossings&&l.findings<=d.findings&&l.nodeFindings<=d.nodeFindings&&l.inward<=d.inward&&l.near<=d.near&&l.touches<=d.touches){[s,d,e]=[t,l,!0];break}}if(e)break}if(e)break}if(!e)break}return s===e.edgeArrows?e:{...e,edgeArrows:s}}function fJ(e){return e.edgeArrows.filter((t,a)=>{let l=e.routedEdges[a],i=ss(fT(t.points)).slice(1,-1);return["source","target"].some(e=>{let t=l[e],a="source"===e?l.sourceEdge:l.targetEdge;return i.some(e=>{let[l,i,s,o]="horizontal"===e.orientation?[t.y,t.height,t.x,t.width]:[t.x,t.width,t.y,t.height],r=e.staticCoordinate<l?l-e.staticCoordinate:e.staticCoordinate-l-i;return("horizontal"===e.orientation?e.staticCoordinate<l?"top":"bottom":e.staticCoordinate<l?"left":"right")!==a&&r>0&&r<72&&e.min<s+o&&e.max>s})})}).length}function fK(e){let t=e.map(e=>fT(e.points)),a=[],l=(e,t,a)=>e>Math.min(t,a)+.01&&e<Math.max(t,a)-.01;for(let[e,i]of t.entries())for(let[s,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,d,c,p]=[i[t],i[t+1],o[r],o[r+1]],[h,g]=.01>=Math.abs(n.y-d.y)&&.01>=Math.abs(c.x-p.x)?[[n,d],[c,p]]:.01>=Math.abs(n.x-d.x)&&.01>=Math.abs(c.y-p.y)?[[c,p],[n,d]]:[];h&&g&&l(g[0].x,h[0].x,h[1].x)&&l(h[0].y,g[0].y,g[1].y)&&a.push({first:e,second:e+1+s,at:{x:g[0].x,y:h[0].y}})}return a}function fQ(e,t,a,l,i){let s=a,o=new Set,[r,n]=[6,24];for(let a=!0;a&&r>0;){a=!1;let d=fY(s.layout.edgeArrows),c=fK(s.layout.edgeArrows).flatMap(({first:t,second:a,at:l})=>(function(e,t,a,l,i,s,o){let r="TB"===l.layout.direction||"BT"===l.layout.direction,n=r?"y":"x",d=e=>uP(e)===n?uS[e]:e,c=gP(l),p=e=>!uM(e)&&void 0===e.pair&&void 0===e.pinned,h=e=>"source"===e?"sourceEdge":"targetEdge",g=(e,t,a)=>{if(uP(a)===n)return!0;let l=um(e[t])[n],i=um(e["source"===t?"target":"source"])[n];return uB[a][n]*(i-l)>.01},u=[],f=(e,t)=>m.get(e.edge.id)?.[h(t)]??e[h(t)],m=new Map,v=e=>{m=e,[...e].every(([e,t])=>{let a=s.find(t=>t.edge.id===e);return g(a,"source",t.sourceEdge??a.sourceEdge)&&g(a,"target",t.targetEdge??a.targetEdge)})&&!(g6(l)&&[...m.keys()].some(e=>{let t=s.find(t=>t.edge.id===e);return["source","target"].some(e=>{let a="source"===e?"target":"source",l=t[e],i=f(t,e);return s.some(e=>e!==t&&e[a]===l&&f(e,a)===i)})}))&&u.push(e)},y=r?["left","right"]:["top","bottom"];for(let a of[e,t].filter(p))if(c.has(a.edge.id))for(let e of[...y].sort((e,t)=>e===d(a.sourceEdge)?-1:+(t===d(a.sourceEdge))))(a.sourceEdge!==e||a.targetEdge!==e)&&v(new Map([[a.edge.id,{sourceEdge:e,targetEdge:e}]]));if(p(e)&&p(t))for(let a of["source","target"])for(let l of["source","target"]){let[i,s]=[e[h(a)],t[h(l)]];e[a].nodeId===t[l].nodeId&&i!==s&&v(new Map([[e.edge.id,{[h(a)]:s}],[t.edge.id,{[h(l)]:i}]]))}let w=a=>{for(let i of new Set([e,t].map(e=>e.source))){if(!g_(i.kind))continue;let e=s.filter(e=>e.source===i&&p(e)&&!c.has(e.edge.id));if(e.length<2||e.length>3)continue;let t=e.map(e=>e.sourceEdge),r=new Set(s.filter(t=>t.source===i&&!e.includes(t)&&!uM(t)).map(e=>e.sourceEdge));for(let s of f4(a?f2(f0(l,o,i.nodeId)).filter(e=>!r.has(e)):t,e.length)){if(a&&s.every(e=>t.includes(e)))continue;let l=new Map(e.flatMap((e,t)=>s[t]===e.sourceEdge?[]:[[e.edge.id,{sourceEdge:s[t]}]]));l.size>0&&v(l)}}};for(let{endpoint:l,route:s}of(w(!1),[e,t].filter(p).flatMap(e=>["source","target"].map(t=>{let{start:l,end:s}=uF(e,i),o="source"===t?l:s;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=s[h(l)],t=um(s[l]),a=um(s["source"===l?"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",d(e),"top","right","bottom","left"]))i!==e&&v(new Map([[s.edge.id,{[h(l)]:i}]]))}return g6(l)||w(!0),u})(s.layout.routedEdges[t],s.layout.routedEdges[a],l,e,s.layout.portOffsets??new Map,s.layout.routedEdges,s.layout.groups)),p=3;for(let h of c){if(0===r||0===p||0===n)break;let c=new Map(s.arrangement.sides);for(let[e,t]of h)c.set(e,{...c.get(e),...t});let g=JSON.stringify([...c].sort(([e],[t])=>e<t?-1:1));if(o.has(g)||(o.add(g),n-=1,function(e,t,a){let{layout:l}=e;if(!l.portOffsets||!l.routeOptions)return 0;let i=l.routedEdges.map(e=>({...e,...t.get(e.edge.id)})),s=fE(i,a,e.arrangement.crossingRepair,void 0!==l.lanes),o=new Set(i.flatMap(e=>t.has(e.edge.id)||["source","target"].some(t=>{let a=ub({edgeId:e.edge.id,endpoint:t});return s.get(a)!==l.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 fz(i,"orthogonal",s,l.nodeShapes,{...l.routeOptions,avoidCrossings:!0},o,a)},n=r(l.edgeArrows,o),d=new Set(fK(n).flatMap(({first:e,second:t})=>{let[a,l]=[i[e].edge.id,i[t].edge.id];return o.has(a)===o.has(l)?[]:[o.has(a)?l:a]}));return 0===d.size?fY(n):Math.min(fY(n),fY(r(n,d)))}(s,h,t)>=d))continue;[r,p]=[r-1,p-1];let u={...s.arrangement,sides:c,avoidCrossings:!0},f=fO(e,t,u),m=l(f);if(!i(s.defects,m)&&fj(f,s.layout,!0,!0,!0)&&fJ(f)<=fJ(s.layout)){s={arrangement:u,defects:m,layout:f},a=!0;break}}}return s}function f1(e,t){let a=e.findIndex((e,a)=>e!==t[a]);return a>=0&&e[a]<t[a]}function f0(e,t,a){let l=t?.groupOf.get(a);return void 0!==l&&t.across.has(l)?gK[e.layout.direction]:e.layout.direction}function f2(e){let[t,a]="TB"===e||"BT"===e?["left","right"]:["top","bottom"];return[t,gZ[e],a]}function f3(e,t){let a=uB[t],[l,i]=0===a.x?["y","height"]:["x","width"];return(um(e.target)[l]-um(e.source)[l])*a[l]<-e.source[i]/2}function f5(e){return new Set(e.flatMap(e=>{let t=fT(e.points);if(t.length<5)return[];let[a,l,i,s]=t.slice(-4),o={x:s.x-i.x,y:s.y-i.y},r={x:l.x-a.x,y:l.y-a.y};return o.x*r.x+o.y*r.y<0&&Math.abs(r.x)+Math.abs(r.y)<72?[e.edgeId]:[]}))}function f4(e,t){return 0===t?[[]]:e.flatMap((a,l)=>f4([...e.slice(0,l),...e.slice(l+1)],t-1).map(e=>[a,...e]))}let f6=[0,-1,1];function f7(e,t,a){let[l,i]=[e[0],e.at(-1)],s=[];for(let o=1;o<e.length-2;o+=1){let[r,n,d,c]=e.slice(o-1,o+3),p=.01>=Math.abs(r.y-n.y)?"x":"y",h=Math.sign(n[p]-r[p]);0!==h&&Math.sign(c[p]-d[p])===h&&Math.hypot(d.x-n.x,d.y-n.y)<a&&(Math.hypot(i.x-d.x,i.y-d.y)<=t&&s.push(o),Math.hypot(n.x-l.x,n.y-l.y)<=t&&s.push(o))}return s}function f8(e,t,a,l,i,s,o){let{edgeArrows:r}=e;for(let n of[...(function(e,t,a){let l=fT(e),i=f7(l,t,a),s=i[0];if(void 0===s)return[];let[o,r,n,d]=l.slice(s-1,s+3),[c,p]=.01>=Math.abs(o.y-r.y)?["x","y"]:["y","x"],h=Math.sign(r[c]-o[c]),[g,u]=[l[0],l.at(-1)],f=(e,a,l)=>{let i=t**2-(e[p]-a[p])**2;return Math.hypot(e.x-a.x,e.y-a.y)>t||i<0?[]:[e[c]+l*(Math.sqrt(i)+1)]},m=[...f(u,n,-h),...f(g,r,h)].sort((e,t)=>Math.abs(e-r[c])-Math.abs(t-r[c]));return[...new Set([(o[c]+d[c])/2,...m].map(Math.round))].flatMap(e=>{if(18>Math.abs(e-r[c])||Math.sign(e-o[c])!==h||Math.sign(d[c]-e)!==h)return[];let n=l.map((t,a)=>a===s||a===s+1?{...t,[c]:e}:t);return fM(l,n)&&f7(n,t,a).length<i.length?[uR(n)]:[]})})(r[t].points,90/l,150/l).map(e=>r.map((a,l)=>l===t?{...a,points:e}:a)),...o?[r]:[]]){if(fY(n)>fY(a.edgeArrows))continue;let t=o?o({...e,edgeArrows:n}):{...e,edgeArrows:n};if(mt(t,a,i,s)&&f9(t)<=f9(a))return t}}function f9({edgeArrows:e,nodeShapes:t}){return e.reduce((e,a)=>e+uW(a.points,t,new Set([a.sourceNodeId,a.targetNodeId])),0)}function me({edgeArrows:e,groups:t,lanes:a,nodeShapes:l}){let i=sx(fX([...l,...ul(t),...uh(a)],e));return function(e,t){let a=4/t,l=e.map(e=>({arrow:e,bounds:sA(e.points,a),runs:sk(sb(e.points))})),i=[];for(let[e,t]of l.entries())for(let s of l.slice(e+1)){let e;if(t.arrow.id!==s.arrow.id&&sP(t.bounds,s.bounds)){for(let l of t.runs)for(let i of s.runs){let o=Math.abs(l.at-i.at),r=Math.min(l.max,i.max)-Math.max(l.min,i.min);l.horizontal===i.horizontal&&o<a&&r>50&&(!e||r>e.length)&&(e={arrowIds:[t.arrow.id,s.arrow.id],gap:o,length:r})}e&&i.push(e)}}return i}(e.map(e=>({id:e.id,points:e.points})),i).length}function mt(e,t,a,l){let[i,s]=[e,t].map(ma);return!l(a(t),a(e))&&fj(e,t,!1,!0)&&fZ(e).size<=fZ(t).size&&fJ(e)<=fJ(t)&&fG(e.edgeArrows)<=fG(t.edgeArrows)&&f5(e.edgeArrows).size<=f5(t.edgeArrows).size&&i.every((e,t)=>e<=s[t])&&mi(e)<=mi(t)+.01&&me(e)<=me(t)}function ma({edgeArrows:e,groups:t,lanes:a,nodeShapes:l,routedEdges:i}){let{shortfalls:s,touches:o}=fx([...e],i,l,t,!0,a);return[o,s.reduce((e,t)=>e+t.shortfall,0)]}function ml(e){return fX([...e.nodeShapes,...ul(e.groups),...uh(e.lanes)],e.edgeArrows,fw([...e.edgeArrows],e.routedEdges,e.nodeShapes,e.groups,!0,e.lanes))}function mi(e){let{width:t,height:a}=ml(e);return Math.max(t,a)}let ms={initial:"circle",final:"circle","final-core":"circle",choice:"diamond"},mo={initial:"Initial state",final:"Final state","final-core":"Final state",choice:"Choice"},mr="#4c4639",mn={subnet:"#f6f1e7",namespace:"#efe6ec"},md=new WeakMap;function mc(e,t={}){var a,l,i;let s,o,r,n,d,c,p,h;md.set(e,t);let g=e=>[fL(e.edgeArrows,e.nodeShapes,e.groups,e.lanes).length,fS(e.edgeArrows,e.nodeShapes)],u=(e,t)=>e[0]<t[0]||e[0]===t[0]&&e[1]<t[1],f="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},fP]:[{...fP,repair:!0},fP],m=(t=>{let[a,...l]=f,i=fO(e,a,t),s=g(i);for(let a of l){if(0===s[0]&&0===s[1])break;let l=fO(e,a,t),o=g(l);u(o,s)&&([i,s]=[l,o])}return{arrangement:t,defects:s,layout:i}})(gJ),v=void 0===t.placement,y=(e,t)=>[fY(e.edgeArrows,t),fD(e.edgeArrows,[...e.nodeShapes,...ul(e.groups),...uh(e.lanes)])],w=(e,t,a)=>{let[l,i]=[e,t].map(e=>y(e,a));return fj(e,t,!1,a)&&l.some((e,t)=>e<i[t])},x=(t,a,l=!1)=>{let i=fO(e,f[0],t),s=g(i);return!u(m.defects,s)&&(l?w(i,m.layout,!1):fj(i,m.layout,a,!1))&&(m={arrangement:t,defects:s,layout:i}),i},b="orthogonal"===e.layout.edgeRouting,k=v&&b&&e.edges.length<=24;k&&fY(m.layout.edgeArrows,!1)>0&&x({...m.arrangement,crossingRepair:!0},!1),k&&fY(m.layout.edgeArrows,!1)>0&&function(e){if(g6(e))return!1;let t=gY(e);return(t?[t.top,...t.groups.map(e=>e.diagram)]:[e]).some(e=>{let[t,a]=[!1,!0].map(t=>gN(e,new Map,new Map,t).rankMetrics.map(e=>e.shapes.map(e=>e.nodeId).join("\n")).join("\n\n"));return t!==a})}(e)&&x({...m.arrangement,reorder:!0},!0);let M="TB"===e.layout.direction||"BT"===e.layout.direction,z=e=>{let t=fX([...e.nodeShapes,...ul(e.groups),...uh(e.lanes)],e.edgeArrows,[...fw([...e.edgeArrows],e.routedEdges,e.nodeShapes,e.groups,!1,e.lanes)]),[a,l]=M?[t.height,t.width]:[t.width,t.height],i=(a+40)/(l+40),s=28e3/(Math.max(a,l)+40);return{aspect:i,balance:M&&i<4&&s>=14?.6:0,size:t,tooLong:i>=4||i>=2.45&&(M||a>=1200)}},{aspect:C,balance:_,tooLong:q}=z(m.layout),L=v&&b&&q?g6(e)?C>=4?function(e){let t,{columnCount:a,columns:l,depth:i,gapAfter:s,headerSize:o,poolBreadth:r}=g8(e,new Map,new Map);if(a<4)return gW;let n=gP(e),d=Array.from({length:a-1},(t,a)=>{let i=e.edges.filter(e=>{let[t,i]=(e=>{let[t,a]=[l.get(e.source),l.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)}),c=(e,t)=>o+96+i.slice(e,t+1).reduce((e,t)=>e+t,0)+s.slice(e,t).reduce((e,t)=>e+t,0),p=a-1,h=gQ(c(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,l=new Map;for(let e=1;e<p;e+=1)void 0!==d[e]&&l.set(e,{cuts:[e],longest:c(0,e),carried:d[e].length,squares:c(0,e)**2});for(let t=2;t<e;t+=1){let e=new Map;for(let[t,a]of l)for(let l=t+2;l<p;l+=1){if(void 0===d[l])continue;let i=c(t+1,l),s={cuts:[...a.cuts,l],longest:Math.max(a.longest,i),carried:a.carried+d[l].length,squares:a.squares+i**2};g(s,e.get(l))&&e.set(l,s)}l=e}for(let[e,t]of l){if(p<e+2)continue;let l=c(e+1,p),i={...t,longest:Math.max(t.longest,l),squares:t.squares+l**2};g(i,a)&&(a=i)}if(!a)continue;let i=e*r+(e-1)*g9(2),s=gQ(a.longest,i);if((!t||s<t.aspect)&&(t={aspect:s,cuts:a.cuts}),s<=2)break}return!t||t.aspect>=h?gW:{bandOf:new Map(e.nodes.map(e=>{let a;return[e.id,(a=l.get(e.id),t.cuts.filter(e=>e<a).length)]})),continuations:new Set(t.cuts.flatMap(e=>d[e]))}}(e):gW:g1(e,m.arrangement.reorder,_):gW,S=(e,t=!1)=>{let a;for(let l of k&&!m.arrangement.crossingRepair?[!0,!1]:[m.arrangement.crossingRepair]){if(0===e.continuations.size||m.arrangement.wrap===e)break;a=x({...m.arrangement,crossingRepair:l,wrap:e},!1,t)}return a},B=S(L);if(B&&!g6(e)){let t=m.arrangement.wrap===L;if(!t||y(m.layout,!1).some(e=>e>0)){let a=function(e,t,a){let l=gZ[gK[a]],[i,s]="TB"===a||"BT"===a?["x","width"]:["y","height"],o=new Set;for(let a of e.routedEdges){if(!t.continuations.has(a.edge.id)||a.sourceEdge!==l)continue;let{source:r}=a,n=r[i]+r[s];e.edgeArrows.some(e=>e.targetNodeId===r.nodeId&&e.edgeId!==a.edge.id&&e.points.slice(-3).some(e=>e[i]>n+.01))&&o.add(a.edge.id)}return o}(B,L,e.layout.direction);a.size>0&&S({...L,leaveForward:a},t),(m.arrangement.wrap===L||0===m.arrangement.wrap.continuations.size)&&S({...L,lineBreaks:!0},t)}}let A=gY(e),P=v&&b&&q&&void 0!==A&&!A.zoned;for(let e of k&&!m.arrangement.crossingRepair?[!0,!1]:[m.arrangement.crossingRepair]){if(!P||m.arrangement.groupsAcross)break;x({...m.arrangement,crossingRepair:e,groupsAcross:!0},!1)}let V=e=>b?fW(fN(e)):e,H=t=>(function(e,t,a,l){let{groups:i,lanes:s,nodeShapes:o,polish:r,routedEdges:n}=t;if(!r?.sides||s||md.get(e)?.placement)return t;let d=sx(fX([...o,...ul(i)],t.edgeArrows)),c=t;for(let[e,t]of n.entries())uM(t)||(c=f8(c,e,c,d,a,l)??c);return c})(e,function(e,t,a,l,i){let{groups:s,lanes:o,nodeShapes:r,polish:n,routeOptions:d,routedEdges:c}=t;if(!n?.sides||!t.portOffsets||!d||o||md.get(e)?.placement)return t;let p=sx(fX([...r,...ul(s)],t.edgeArrows)),h=t;for(let[e,t]of c.entries()){let o=h.edgeArrows[e],{source:r,target:n,targetEdge:g}=t;if(uM(t)||t.pinned?.target!==void 0||0===u9(o.points)||uy(n,g)||c.some(e=>e!==t&&(e.target===n&&e.targetEdge===g||e.source===n&&e.sourceEdge===g)))continue;let[u,f]="x"===uP(g)?["x","y"]:["y","x"],m=um(n)[u],v=("x"===u?n.width:n.height)/2,y=o.points.at(-1),w=y[u]-m;if(Math.abs(w)<=.75*v)continue;let x=Math.min(v-Math.max(16,n.id.startsWith("node:")?iG(n):0),.75*v),b=fT(o.points).at(-2),[k,M]=[Math.min(b[f],y[f]),Math.max(b[f],y[f])],[z,C]="x"===u?["width","height"]:["height","width"],_=[...h.nodeShapes.filter(e=>e.nodeId!==n.nodeId&&e.nodeId!==r.nodeId),...ui(s,t),...fc(c,h.portOffsets).filter(e=>e.nodeId!==`branch-label:${t.edge.id}`)].filter(e=>e[f]<M&&e[f]+e[C]>k&&e[u]<m+v&&e[u]+e[z]>m-v),q=[...new Set([0,..._.flatMap(e=>[e[u]-18-m,e[u]+e[z]+18-m])])].filter(e=>Math.abs(e)<=x+.01&&Math.abs(e)<Math.abs(w)-.01&&!_.some(t=>t[u]<m+e&&t[u]+t[z]>m+e)).sort((e,t)=>Math.abs(e)-Math.abs(t)).slice(0,3),L=ub({edgeId:t.edge.id,endpoint:"target"}),S=new Map(h.edgeArrows.filter(e=>e!==o).map(e=>[e.edgeId,e])),B=c.map((e,t)=>t).sort((t,a)=>Number(t===e)-Number(a===e));for(let t of q){let s=new Map(h.portOffsets).set(L,t),r=fz(c,"orthogonal",s,h.nodeShapes,{...d,midway:!0},B,S),n=r[e].points;if(u9(n)>u9(o.points)||uQ(n)>uQ(o.points)+Math.abs(t-w)+.01)continue;let g=f8({...h,edgeArrows:r,portOffsets:s},e,h,p,l,i,a);if(g){h=g;break}}}return h}(e,function(e,t,a,l,i){let{lanes:s,routeOptions:o,routedEdges:r}=t;if(!t.portOffsets||!o||s||md.get(e)?.placement)return t;let n=t,d=(e,t,a)=>r.flatMap((l,i)=>["source","target"].flatMap(s=>{let o="source"===s?l.sourceEdge:l.targetEdge;if(l.edge.id===a||l[s].nodeId!==e.nodeId||o!==t)return[];let r=n.edgeArrows[i].points;return[("source"===s?r[0]:r.at(-1))[uP(t)]-um(e)[uP(t)]]}));for(let[e,t]of r.entries()){let s=n.edgeArrows[e],c=["source","target"].map(e=>{let a=t[e],l="source"===e?t.sourceEdge:t.targetEdge,i=uP(l),o="source"===e?s.points[0]:s.points.at(-1),r=a.id.startsWith("node:")?iG(a):0,n=("x"===i?a.width:a.height)/2;return{along:o[i]-um(a)[i],curved:r>16,key:ub({edgeId:t.edge.id,endpoint:e}),limit:Math.max(0,n-Math.max(16,r)),others:d(a,l,t.edge.id)}}),p=c.filter(e=>e.curved&&Math.abs(e.along)>e.limit+.01),h=(e,t)=>e.others.every(a=>Math.abs(t-a)>=Math.min(Math.abs(e.along-a),18)-.01);if(0===p.length||!p.every(e=>h(e,Math.sign(e.along)*e.limit)))continue;let g=new Map(n.portOffsets);for(let e of p)g.set(e.key,Math.sign(e.along)*e.limit);if(2===s.points.length&&1===p.length){let[e]=p,t=c.find(t=>t!==e),a=t.along+Math.sign(e.along)*e.limit-e.along;Math.abs(a)<=t.limit+.01&&h(t,a)&&g.set(t.key,a)}let u=r.map((e,t)=>t).sort((t,a)=>Number(t===e)-Number(a===e)),f=fz(r,"orthogonal",g,n.nodeShapes,{...o,midway:!0},u,new Map(n.edgeArrows.filter(e=>e!==s).map(e=>[e.edgeId,e])));if(fY(f)>fY(n.edgeArrows))continue;let m=a({...n,edgeArrows:f,portOffsets:g});mt(m,n,l,i)&&(n=m)}return n}(e,function(e,t,a,l){let{lanes:i,nodeShapes:s,polish:o,routeOptions:r,routedEdges:n}=e;if(!o?.sides||!e.portOffsets||!r?.readerScale||i)return e;let d=e;for(let[e,i]of n.entries()){let o=d.edgeArrows[e],{target:c,targetEdge:p}=i;if(p!==uS[i.sourceEdge]||i.pinned?.target!==void 0||2>=u9(o.points)||!function(e){let[t,a]=[e[0],e.at(-1)],l=Math.abs(a.x-t.x)+Math.abs(a.y-t.y);return uQ(e)>=l+72&&e.some(e=>e.x<Math.min(t.x,a.x)-.01||e.x>Math.max(t.x,a.x)+.01||e.y<Math.min(t.y,a.y)-.01||e.y>Math.max(t.y,a.y)+.01)}(o.points)||uy(c,p)||n.some(e=>e!==i&&(e.target===c&&e.targetEdge===p||e.source===c&&e.sourceEdge===p)))continue;let h=ub({edgeId:i.edge.id,endpoint:"target"}),g=uV(c,p),u=new Map(d.edgeArrows.filter(e=>e!==o).map(e=>[e.edgeId,e])),f=n.map((e,t)=>t).sort((t,a)=>Number(t===e)-Number(a===e)),m=f6.flatMap(t=>{let a=t*g;if(.01>=Math.abs(a-(d.portOffsets.get(h)??0)))return[];let l=new Map(d.portOffsets).set(h,a),i=fz(n,"orthogonal",l,s,{...r,midway:!0},f,u),c=i[e].points,[p,m]=[u9(c),uQ(c)];return p<u9(o.points)&&m<=uQ(o.points)+.01?[{arrows:i,bends:p,length:m,offsets:l}]:[]}).sort((e,t)=>e.bends-t.bends||e.length-t.length)[0];if(!m||fY(m.arrows)>fY(d.edgeArrows))continue;let v=t({...d,edgeArrows:m.arrows,portOffsets:m.offsets});mt(v,d,a,l)&&(d=v)}return d}(t,V,g,u),V,g,u),V,g,u),g,u),I=t=>{if(!b)return t;let a=function(e,t,a,l,i){let{edgeArrows:s,lanes:o,nodeShapes:r,polish:n,portOffsets:d,routeOptions:c}=t;if(!n?.sides||!d||!c?.readerScale||o)return t;let p=t.routedEdges.map(e=>({...e})),h=sx(fX([...r,...ul(t.groups)],s)),g=new Set(fq(p,s,e,h,"cornered").map(({route:e})=>e.edge.id)),u=gP(e),f=f5(s);for(let[e,t]of s.entries()){let a=p[e];if(!f.has(t.edgeId)||u.has(a.edge.id)||a.pinned?.target!==void 0)continue;let[l,i]=fT(t.points).slice(-5),s=.01>=Math.abs(l.y-i.y)?i.x>l.x?"left":"right":i.y>l.y?"top":"bottom",o=p.filter(e=>e!==a&&(e.source===a.target&&e.sourceEdge===s||e.target===a.target&&e.targetEdge===s));s===a.targetEdge||o.length>0&&(uy(a.target,s)||o.some(e=>e.source===a.target))||(a.targetEdge=s,g.add(a.edge.id))}let m=(e,t)=>{let a=uS[e.sourceEdge],{source:l,target:i}=e,o=uP(a),[n,d]="x"===o?[i.x,i.width]:[i.y,i.height],c=t.points[0][o],h=c>n+16&&c<n+d-16,g=h?c:uw(c,n+32,n+d-32),u=um(l)[o],f=p.flatMap((t,a)=>t!==e&&(t.source===l&&t.sourceEdge===e.sourceEdge||t.target===l&&t.targetEdge===e.sourceEdge)?[(t.source===l?s[a].points[0]:s[a].points.at(-1))[o]]:[]);if(!h&&(void 0!==e.pinned||d<64||Math.abs(g-u)>uV(l,e.sourceEdge)||f.some(e=>18>Math.abs(g-e)||Math.sign(g-e)!==Math.sign(c-e))))return;let m=h?t.points[0]:ux(l,e.sourceEdge,g-u),v=ux(i,a,g-n-d/2),y="x"===o?"y":"x";return uB[a][y]*(m[y]-v[y])<=0||r.some(e=>e.nodeId!==l.nodeId&&e.nodeId!==i.nodeId&&uO(m,v,e))?void 0:{inLine:h,source:g-u,target:g-n-d/2}},v=new Map,y=new Map,w=(e,t)=>{v.set(ub({edgeId:e.edge.id,endpoint:"source"}),t.source),v.set(ub({edgeId:e.edge.id,endpoint:"target"}),t.target)};for(let[e,t]of s.entries()){let a=p[e];if(!g.has(a.edge.id)||a.targetEdge!==uS[a.sourceEdge])continue;let l=m(a,t);l&&w(a,l)}for(let[e,t]of s.entries()){let a=p[e],l=uS[a.sourceEdge],{target:i}=a;if(a.targetEdge===l||g.has(a.edge.id)||u.has(a.edge.id)||a.pinned?.target!==void 0||uM(a)||p.some(e=>e.target===i&&e.targetEdge===l||e.source===i&&e.sourceEdge===l))continue;let s=m(a,t);s&&(s.inLine||(y.set(a.edge.id,a.targetEdge),w(a,s)),a.targetEdge=l,g.add(a.edge.id))}for(let e of sL(s.map(e=>({id:e.edgeId,points:e.points})),h))if("endpoint-jog"===e.kind){let t=p.find(t=>t.edge.id===e.arrowIds[0]);t.targetEdge===uS[t.sourceEdge]&&g.add(t.edge.id)}let x=(e,o,p)=>{if(0===o.size)return;let h=fE(e,n,t.byApproach??!1,!1);for(let[e,t]of p)h.set(e,t);let g=new Set(e.flatMap(e=>o.has(e.edge.id)||["source","target"].some(t=>{let a=ub({edgeId:e.edge.id,endpoint:t});return h.get(a)!==d.get(a)})?[e.edge.id]:[])),u=e.map((e,t)=>({again:g.has(e.edge.id),index:t})).sort((e,t)=>Number(e.again)-Number(t.again)).map(({index:e})=>e),f=a({...t,edgeArrows:fz(e,"orthogonal",h,r,{...c,midway:!0},u,new Map(s.filter(e=>!g.has(e.edgeId)).map(e=>[e.edgeId,e]))),portOffsets:h,routedEdges:e}),m=e=>e.filter(e=>o.has(e.edgeId)).reduce((e,t)=>({bends:e.bends+u9(t.points),length:e.length+uQ(t.points)}),{bends:0,length:0}),[v,y]=[m(s),m(f.edgeArrows)],[w,x]=[f,t].map(e=>fD(e.edgeArrows,[...e.nodeShapes,...ul(e.groups)])),[b,k]=[f,t].map(e=>f5(e.edgeArrows).size);return(w<x||b<k||y.bends<v.bends)&&y.length<=v.length+.01&&mt(f,t,l,i)?f:void 0};return(v.size>0?x(p,g,v):void 0)??x(p.map(e=>y.has(e.edge.id)?{...e,targetEdge:y.get(e.edge.id)}:e),new Set([...g].filter(e=>!y.has(e))),new Map)??t}(e,function(e,t,a,l,i){let{lanes:s,polish:o,routeOptions:r}=t;if(!o?.sides||!t.portOffsets||!r||s||md.get(e)?.placement)return t;let n=gP(e),d=["top","right","bottom","left"],c=t;for(let e of t.routedEdges.keys()){let t,s=c.routedEdges[e],{source:p,target:h}=s;if(!n.has(s.edge.id)||uM(s)||!g_(h.kind)||void 0!==s.pinned||void 0!==s.pair)continue;let g=c.edgeArrows[e],u=e=>Math.hypot(Math.max(p.x-e.x,0,e.x-p.x-p.width),Math.max(p.y-e.y,0,e.y-p.y-p.height)),[f]=d.filter(e=>!c.routedEdges.some(t=>t!==s&&(t.target===h&&t.targetEdge===e||t.source===h&&t.sourceEdge===e))).map(e=>({point:ux(h,e),side:e})).filter(({point:e})=>u(e)<u(g.points.at(-1))-18).sort((e,t)=>u(e.point)-u(t.point));if(!f)continue;let m=d.filter(e=>{let[t,a]=[ux(p,e),uB[e]];return(f.point.x-t.x)*a.x+(f.point.y-t.y)*a.y>0});for(let n of new Set([s.sourceEdge,...m])){let s=c.routedEdges.map((t,a)=>a===e?{...t,sourceEdge:n,targetEdge:f.side}:t),d=fE(s,o,c.byApproach??!1,!1),p=new Set(s.flatMap((t,a)=>a===e||["source","target"].some(e=>{let a=ub({edgeId:t.edge.id,endpoint:e});return d.get(a)!==c.portOffsets.get(a)})?[t.edge.id]:[])),h=s.map((e,t)=>({again:p.has(e.edge.id),at:t})).sort((e,t)=>Number(e.again)-Number(t.again)).map(({at:e})=>e),u=fz(s,"orthogonal",d,c.nodeShapes,{...r,midway:!0},h,new Map(c.edgeArrows.filter(e=>!p.has(e.edgeId)).map(e=>[e.edgeId,e])));if(fY(u)>fY(c.edgeArrows))continue;let m=a({...c,edgeArrows:u,portOffsets:d,routedEdges:s}),v=m.edgeArrows[e].points,y=uQ(v);y<uQ(g.points)-.01&&u9(v)<=u9(g.points)&&(!t||y<t.length-.01)&&mt(m,c,l,i)&&f9(m)<=f9(c)&&(t={layout:m,length:y})}t&&(c=t.layout)}return c}(e,t,V,g,u),V,g,u),l=H(a),i=function(e,t,a,l,i){let{lanes:s,polish:o,routeOptions:r}=t;if(!o?.sides||!t.portOffsets||!r||s||md.get(e)?.placement||e.edges.length>24)return t;let n=gP(e),d=["top","right","bottom","left"],c=e=>!n.has(e.edge.id)&&!uM(e)&&void 0===e.pinned&&void 0===e.pair,p=(e,t)=>{let[a,l,i]=[um(e.source),um(e.target),uB[t]],s=0!==i.x?e.target.width/2:e.target.height/2;return(a.x-l.x)*i.x+(a.y-l.y)*i.y-s},h=e=>p(e,uS[e.targetEdge])>0,g=({edgeArrows:e,routedEdges:t})=>{let a=fC(t);return e.filter((e,l)=>f_(t[l],e,a)).length},u=t;for(let e of new Set(t.routedEdges.filter(c).map(e=>e.target.nodeId))){let t,s=new Set(u.routedEdges.flatMap((t,a)=>t.target.nodeId===e&&c(t)?[a]:[]));if(s.size<2)continue;let n=new Set(fK(u.edgeArrows).flatMap(({first:e,second:t})=>s.has(e)&&s.has(t)?[e,t]:[])),f=[...s].filter(e=>n.has(e)||h(u.routedEdges[e]));if(0===f.length)continue;let m=u.routedEdges[f[0]].target,v=new Set(u.routedEdges.flatMap(e=>e.source===m?[e.sourceEdge]:[])),y=(e,t)=>!v.has(t)&&p(u.routedEdges[e],t)>0,w=e=>[fY(e.edgeArrows),[...s].filter(t=>h(e.routedEdges[t])).length,g(e),[...s].reduce((t,a)=>t+uQ(e.edgeArrows[a].points),0)],[x,b,k,M]=w(u),z=([e,t,,a])=>e<x||e===x&&t<b&&a<M-.01;for(let e of f.flatMap(e=>d.flatMap(t=>{if(!y(e,t))return[];let a=new Map([[e,t]]),l=u.routedEdges[e].targetEdge,i=[...s].filter(a=>a!==e&&u.routedEdges[a].targetEdge===t);return i.length>0&&i.every(e=>y(e,l))?[a,new Map([...a,...i.map(e=>[e,l])])]:[a]}))){let n=u.routedEdges.map((t,a)=>e.has(a)?{...t,targetEdge:e.get(a)}:t),d=fE(n,o,u.byApproach??!1,!1),[c]=e.keys(),p=e.get(c),h=[...s].filter(e=>n[e].targetEdge===p).map(e=>ub({edgeId:n[e].edge.id,endpoint:"target"})).sort((e,t)=>d.get(e)-d.get(t)),g=new Map(d);for(let[e,t]of h.entries())g.set(t,d.get(h[h.length-1-e]));let f=[...s].filter(e=>e!==c);for(let e of h.length>1?[d,g]:[d]){let o=new Set(n.flatMap((t,a)=>s.has(a)||["source","target"].some(a=>{let l=ub({edgeId:t.edge.id,endpoint:a});return e.get(l)!==u.portOffsets.get(l)})?[a]:[])),d=n.map((e,t)=>t);for(let p of[[c,...f],[...f,c]]){let c=[...d.filter(e=>!o.has(e)),...p,...d.filter(e=>o.has(e)&&!s.has(e))],h={...u,edgeArrows:fz(n,"orthogonal",e,u.nodeShapes,{...r,midway:!0},c,new Map(u.edgeArrows.filter((e,t)=>!o.has(t)).map(e=>[e.edgeId,e]))),portOffsets:e,routedEdges:n};if(!z(w(h)))continue;let g=a(h),f=w(g);z(f)&&(f[2]<=k||f[0]<x)&&(!t||f1(f,t.score))&&mt(g,u,l,i)&&f9(g)<=f9(u)&&f$(g)<=f$(u)&&(t={layout:g,score:f})}}}t&&(u=t.layout)}return u}(e,a,V,g,u);if(i===a)return l;let s=H(i);return mt(s,l,g,u)&&f9(s)<=f9(l)&&f$(s)<=f$(l)?s:l},$=e=>{if(!b)return e;let t=fN(e,!0);return t===e?e:fW(t)},F=e=>[fY(e.edgeArrows,!1),fD(e.edgeArrows,[...e.nodeShapes,...ul(e.groups)]),z(e).aspect],O=e=>fD(e.edgeArrows,[...e.nodeShapes,...ul(e.groups)]),E=(e,t,a=!1)=>{let[l,i]=[e,t].map(e=>$(V(e)));return[!1,!0].every(e=>fY(l.edgeArrows,e)<=fY(i.edgeArrows,e))&&fG(l.edgeArrows)<=fG(i.edgeArrows)&&fJ(l)<=fJ(i)&&fZ(l).size<=fZ(i).size&&f9(l)<=f9(i)&&l.edgeArrows.every(e=>{let[t,a]=[e.points[0],e.points.at(-1)];return e.sourceNodeId===e.targetNodeId||uQ(e.points)<=2*(Math.abs(a.x-t.x)+Math.abs(a.y-t.y))+72})&&(!a||O(l)<=O(i)||O($(I(V(e))))<=O($(I(V(t)))))};for(let t=0;t<2&&v&&b&&void 0!==A&&(A.zoned||0===A.composites.size);t+=1){let t,a,l=z(m.layout);if(!l.tooLong)break;let i=m,s=!1;for(let o of function(e,t,a,l,i){let s=new Map([["",t.top],...t.zoned?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,l=e=>{for(let a of e.children)l(t.get(a));let{rankMetrics:i}=gN(e.diagram,new Map,new Map),s=i.reduce((e,t)=>e+Math.max(...t.shapes.map(e=>a.get(e.nodeId)??1)),0);return a.set(gR(e.group.id),Math.max(2,s)),s};for(let t of e.groups)e.parentOf.has(t.group.id)||l(t);return a}(t),r=t=>{let l=g2(e,new Map,new Map,{...a,zoneWraps:t});return{bounds:g3([...l.nodes,...ul(l.groups)]),placed:l}},n=new Map(a.zoneWraps??[]),d=r(n),[c,p]=[i.width/d.bounds.width,i.height/d.bounds.height],h=e=>{let{bounds:t,placed:a}=r(e);return{aspect:gQ(t.width*c,t.height*p),placed:a}},g=(e,t)=>{let[a,l]=[e,t].map(e=>e.aspect<=2);return a!==l?a?-1:1:a&&e.bands-t.bands||e.aspect-t.aspect},u="LR"===e.layout.direction||"RL"===e.layout.direction,f=({next:e})=>{let a=e.get("");return t.zoned&&u&&a?new Set(t.groups.flatMap(({group:e})=>t.parentOf.has(e.id)?[]:[a.bandOf.get(gR(e.id))])).size-1:0},m=n.size,v=h(n),y=e=>[...e.values()].some(e=>e.skips),w=[];for(;v.aspect>2;){let e=new Map([...v.placed.nodes.map(e=>[e.nodeId,e]),...(v.placed.groups?.frames??[]).map(e=>[gR(e.id),e.box])]),t=[];for(let[i,r]of s){if(n.has(i))continue;let s=new Map;for(let d of[!0,!1])for(let c=2;c<=6;c+=1){let p=g1(r,a.reorder,l,{bands:c,sizes:e,weights:o,skips:d});if(0===p.bandOf.size)continue;let g=[...p.bandOf].join(" "),u=s.get(g);if(!u){let e=new Map([...n,[i,p]]);u={...h(e),bands:c,next:e},s.set(g,u),t.push(u)}if(u.aspect<=2)break}}let i=t.filter(e=>e.aspect<v.aspect).sort(g),r=i.reduce((e,t,a)=>t.aspect<2.45&&f(t)<f(i[e])?a:e,0);r>0&&i.unshift(...i.splice(r,1));let[d]=i;if(!d)break;if(n.size===m){let e=i.slice(1,3),t=y(d.next)&&e.every(e=>y(e.next))?i.find(e=>!y(e.next)):void 0;w.push(...[...e,...t?[t]:[]].map(e=>e.next))}n=d.next,v=d}return n.size>m?[n,...w]:[]}(e,A,i.arrangement,l.balance,l.size)){let l={...i.arrangement,crossingRepair:k||i.arrangement.crossingRepair,zoneWraps:o},r=fO(e,f[0],l),n=!l.avoidCrossings&&fY(r.edgeArrows,!1)>fY(i.layout.edgeArrows,!1),d=n?fO(e,f[0],{...l,avoidCrossings:!0}):r,c={arrangement:n?{...l,avoidCrossings:!0}:l,defects:g(d),layout:d},p=({defects:e,layout:t})=>!u(i.defects,e)&&fj(t,i.layout,!1,!1,!1,!1),h=p(c)||!k||!n||A.zoned&&o.has("")||fY(d.edgeArrows)!==fY(i.layout.edgeArrows)+1?void 0:fQ(e,f[0],c,g,u),m=void 0!==h&&p(h)&&E(h.layout,i.layout,!A.zoned),{arrangement:v,defects:y,layout:w}=m?h:c;if(!m&&!p(c)||!m&&!A.zoned&&!E(w,i.layout,!0))continue;let x=F(w),[b,M]=F(i.layout),z=x[0]<=b&&x[1]<=M;if(m){if((!a||f1(x,a.score))&&(a={arrangement:v,defects:y,layout:w,score:x}),!A.zoned&&z)break;continue}let C=[...o.values()].some(e=>e.skips);if((!t||f1(x,t.score)||s&&z&&(x[0]<t.score[0]||x[1]<t.score[1]))&&(t={arrangement:v,defects:y,layout:w,score:x},s=C),z&&!C)break}if(a&&(!t||(t.arrangement.zoneWraps?.has("")||z(t.layout).tooLong&&!z(a.layout).tooLong)&&a.score[0]<=t.score[0]&&a.score[1]<=t.score[1])&&(t=a),!t)break;let o=t.arrangement.zoneWraps?.get(""),r=o&&{...t.arrangement,zoneWraps:new Map([...t.arrangement.zoneWraps,["",{...o,rise:!0}]])},n=t=>g2(e,new Map,new Map,t).nodes.map(e=>`${e.x},${e.y}`).join(" ");if(!A.zoned&&o&&r&&!o.rise&&n(r)!==n(t.arrangement)){let a=fO(e,f[0],r),l=g(a);!u(t.defects,l)&&fj(a,t.layout,!1,!1,!1,!1)&&E(a,t.layout,!0)&&(t={arrangement:r,defects:l,layout:a,score:F(a)})}m=t}let U=fV(e,m.arrangement.zoneWraps);if(m.arrangement.zoneWraps&&!m.arrangement.aroundRanks&&m.layout.routedEdges.some(({edge:t,source:a,target:l})=>U.has(t.id)&&fF(a,l,m.layout.nodeShapes,e.layout.direction))){let t={...m.arrangement,aroundRanks:!0},a=fO(e,f[0],t),l=g(a),i=({edgeArrows:e})=>e.reduce((e,t)=>e+uQ(t.points),0);!u(m.defects,l)&&fj(a,m.layout,!1,!1)&&fJ(a)<=fJ(m.layout)&&fG(a.edgeArrows)<=fG(m.layout.edgeArrows)&&i(a)<i(m.layout)-.01&&(m={arrangement:t,defects:l,layout:a})}let X=b&&m.layout.groups?.zoned?fI($(V(m.layout))):new Set;if(X.size>0){let t=new Map(m.arrangement.zoneSlack??[]);for(let e of X)t.set(e,(t.get(e)??0)+36);let a={...m.arrangement,zoneSlack:t},l=fO(e,f[0],a),i=g(l);!u(m.defects,i)&&fj(l,m.layout,!1,!1)&&fI($(V(l))).size<X.size&&(m={arrangement:a,defects:i,layout:l})}v&&b&&g6(e)&&x({...m.arrangement,separateRoles:!0},!1);let T=t=>{let a=fY(t.layout.edgeArrows);return k&&a>0&&a<=6?fQ(e,f[0],t,g,u):t},R=(a,l)=>{m=T(m=a);let{wrap:i}=a.arrangement;if(k&&!g6(e)&&i.continuations.size>0&&!i.lineBreaks&&fY(m.layout.edgeArrows)>0){let t={...a.arrangement,wrap:{...i,lineBreaks:!0}},l=fO(e,f[0],t),s=T({arrangement:t,defects:g(l),layout:l});!u(m.defects,s.defects)&&w(s.layout,m.layout,!0)&&(m=s)}if(t.pairedReturns&&fY(m.layout.edgeArrows)>0){let t=m,a=new Map(m.layout.edgeArrows.map(e=>[e.edgeId,e])),l=new Set;for(let e of m.layout.routedEdges){let t=a.get(e.edge.id);if(void 0!==e.pair&&t&&m.layout.edgeArrows.some(e=>e!==t&&fY([t,e])>0))for(let t of m.layout.routedEdges)void 0!==t.pair&&(t.edge.id===e.edge.id||t.edge.source===e.edge.target&&t.edge.target===e.edge.source)&&l.add(t.edge.id)}if(l.size>0){x({...m.arrangement,unpairedReturns:l},!0);let a=fY(m.layout.edgeArrows);m!==t&&k&&a>0&&a<=6&&(m=fQ(e,f[0],m,g,u));let i=new Set(m.layout.routedEdges.filter(e=>void 0!==e.pair).map(e=>e.edge.id));t.layout.routedEdges.some(e=>void 0!==e.pair&&!l.has(e.edge.id)&&!i.has(e.edge.id))&&(m=t)}}if(s=V(m.layout),l?.(s))return{layout:s,settled:m};let o=()=>v&&b&&(g6(e)||M&&!A)&&0===m.arrangement.wrap.continuations.size&&z(s).aspect>=2.3&&(!g6(e)||0===fZ(s).size),r=t=>{let a=fO(e,f[0],t),l=T({arrangement:t,defects:g(a),layout:a}),i=V(l.layout),o=new Map(s.edgeArrows.map(e=>[e.id,uQ(e.points)]));return!!(!u(m.defects,l.defects)&&fj(i,s,!1,!0)&&i.edgeArrows.every(e=>uQ(e.points)<=o.get(e.id)+.01)&&(!g6(e)||0===fZ(i).size)&&fJ(i)<=fJ(s)&&fG(i.edgeArrows)<=fG(s.edgeArrows)&&ma(i).every((e,t)=>e<=ma(s)[t]))&&z(i).aspect<z(s).aspect&&(m=l,s=i,!0)};if(g6(e)&&o()){let t=g7(e,!0);[...g7(e)].some(([e,a])=>t.get(e)!==a)&&r({...m.arrangement,throughHandoffs:!0})}for(let t of o()?[!1,!0]:[]){let a=function(e,t,a,l=!1){let i=new Map(t.nodeShapes.map(e=>[e.nodeId,e])),s=g6(e)?[...g7(e,a.throughHandoffs)].reduce((e,[t,a])=>((e[a]??=[]).push(t),e),[]):gN(e,new Map,new Map,a.reorder).rankMetrics.map(({shapes:e})=>e.map(e=>e.nodeId)),o="TB"===e.layout.direction||"BT"===e.layout.direction,[r,n]=o?["y","height"]:["x","width"],d=s.map(e=>{let t=e.map(e=>i.get(e));return{top:Math.min(...t.map(e=>e[r])),bottom:Math.max(...t.map(e=>e[r]+e[n]))}}),c=o?"x":"y",p=t.edgeArrows.flatMap(e=>e.points.slice(1).flatMap((t,a)=>{let l=e.points[a];return .01>=Math.abs(t[r]-l[r])&&Math.abs(t[c]-l[c])>.01?[t[r]]:[]})),h=new Map;for(let e=0;e<d.length-1;e+=1){let[t,a]=[d[e],d[e+1]],[i,s]=t.bottom<=a.top?[t.bottom,a.top]:[a.bottom,t.top],o=new Set(p.filter(e=>e>i+.01&&e<s-.01)).size;0===o?h.set(e,56):l||h.set(e,72+(o-1)*18)}return h}(e,s,m.arrangement,t);if(a.size>0&&r({...m.arrangement,compactGaps:a}))break}let n=v&&b&&g6(e)&&0===m.arrangement.wrap.continuations.size&&0===fZ(s).size?function({lanes:e},t){if(!e)return;let[a,l]=e.vertical?[t.height,t.width]:[t.width,t.height],i=(a+40)/2.4-40-l;if(i<=.01)return;let s=e.frames.filter(e=>0===e.pool).map(t=>e.vertical?t.box.width:t.box.height).sort((e,t)=>e-t);for(let[e,t]of s.slice(0,-1).entries()){let a=(s[e+1]-t)*(e+1);if(a>=i)return Math.ceil(t+i/(e+1));i-=a}}(s,z(s).size):void 0;if(void 0!==n){let t={...m.arrangement,laneBreadth:n},a=fO(e,f[0],t),l=T({arrangement:t,defects:g(a),layout:a}),i=V(l.layout);!u(m.defects,l.defects)&&fj(i,s,!1,!0)&&0===fZ(i).size&&fJ(i)<=fJ(s)&&fG(i.edgeArrows)<=fG(s.edgeArrows)&&ma(i).every((e,t)=>e<=ma(s)[t])&&z(i).aspect<z(s).aspect&&(m=l,s=i)}let d=b?fZ(s):new Set,c=[];if(d.size>0&&s.portOffsets&&s.routeOptions){let{edgeArrows:e,nodeShapes:t,portOffsets:a,routeOptions:l,routedEdges:i}=s,o=i.map((e,t)=>t),r=e=>+!!d.has(i[e].edge.id);c.push(V({...s,edgeArrows:fz(i,"orthogonal",a,t,{...l,clearHeads:!0},o.sort((e,t)=>r(e)-r(t)),new Map(e.filter(e=>!d.has(e.edgeId)).map(e=>[e.edgeId,e])))}))}if(k&&d.size>0){let t={...m.arrangement,clearHeads:!0},a=fO(e,f[0],t);c.push(V(T({arrangement:t,defects:g(a),layout:a}).layout))}let p=e=>[fZ(e).size,...y(e,!0)],h=s;for(let e of c.filter(e=>{let[t,a]=[e,s].map(g),[l,i]=[e,s].map(ma);return!u(a,t)&&fZ(e).size<fZ(s).size&&fj(e,s,!1,!0,!0)&&mi(e)<=mi(s)+.01&&fG(e.edgeArrows)<=fG(s.edgeArrows)&&l.every((e,t)=>e<=i[t])}))(s===h||f1(p(e),p(s)))&&(s=e);return{layout:s,settled:m}},Y=m;({layout:s,settled:m}=R(Y)),k&&!g6(e)&&({layout:s,settled:m}=function(e,t,a,l,i,s,o){let r=gP(e),{continuations:n}=a.arrangement.wrap,d=e=>[fY(e.edgeArrows),fG(e.edgeArrows)+f5(e.edgeArrows).size,e.edgeArrows.reduce((e,t)=>e+uQ(t.points),0)],c=(e,t)=>{let[a,l]=[e,t].map(ma);return!o(s(t),s(e))&&fj(e,t,!1,!0)&&fZ(e).size<=fZ(t).size&&fJ(e)<=fJ(t)&&a.every((e,t)=>e<=l[t])&&p(e,t)},p=(e,t)=>{let[a,l]=[e,t].map(ml),[i,s]=[a,l].map(({width:e,height:t})=>Math.max(e,t));return i<=s+.01&&(i<s-.01||gQ(a.width,a.height)<=gQ(l.width,l.height)+.01)},[h,g]=[a,l],u=d(g.layout);for(let a of new Set(l.layout.routedEdges.filter(e=>g_(e.source.kind)).map(e=>e.source.nodeId))){let l,{groups:o,routedEdges:p}=g.layout,f=p.filter(e=>e.source.nodeId===a&&!uM(e)),m=f.filter(e=>!r.has(e.edge.id)&&void 0===e.pinned&&void 0===e.pair&&!n.has(e.edge.id));if(m.length<2||m.length>3)continue;let v=new Set(m.map(e=>e.edge.id)),y=d(h.layout),w=e=>m.filter((t,a)=>f3(t,e[a])).length,[x,b]=[g.layout,h.layout].map(e=>{let t=e.edgeArrows.filter(e=>v.has(e.edgeId)),a=e.routedEdges.filter(e=>v.has(e.edge.id)&&f3(e,e.sourceEdge)).length,l=a>0||fG(t)>0||f5(t).size>0||fY(t)>0;return[a,l]}).reduce(([e,t],[a,l])=>[Math.max(e,a),t||l]);if(!b)continue;let k=new Set(f.filter(e=>!v.has(e.edge.id)).map(e=>e.sourceEdge)),M=f2(f0(e,o,a)).filter(e=>!k.has(e)),z=e=>m.reduce((t,a,l)=>t+function(e,t){let a=u7(ux(e.source,t),t,36),l=um(e.target);return 36+Math.abs(l.x-a.x)+Math.abs(l.y-a.y)}(a,e[l]),0),C=m.map(e=>h.layout.routedEdges.find(t=>t.edge.id===e.edge.id)?.sourceEdge);for(let{score:a,...o}of f4(M,m.length).filter(e=>w(e)<=x&&e.some((e,t)=>e!==m[t].sourceEdge)).sort((e,t)=>z(e)-z(t)).slice(0,2).map(a=>{if(a.every((e,t)=>e===C[t]))return{...h,score:y};let l=new Map(h.arrangement.sides);m.forEach((e,t)=>l.set(e.edge.id,{...l.get(e.edge.id),sourceEdge:a[t]}));let i={...h.arrangement,sides:l},o=fO(e,t,i);return{arrangement:i,defects:s(o),layout:o,score:d(o)}}).filter(e=>!f1(y.slice(0,2),e.score.slice(0,2))).sort((e,t)=>f1(e.score,t.score)?-1:+!!f1(t.score,e.score)).slice(0,1)){if(o.layout===h.layout)continue;let e=i(o,e=>f1((l?.score??u).slice(0,2),d(e).slice(0,2))),t=d(e.layout);f1(t,l?.score??u)&&c(e.layout,g.layout)&&(l={base:o,drawn:e,score:t})}l&&([h,g,u]=[l.base,l.drawn,l.score])}return g}(e,f[0],Y,{layout:s,settled:m},R,g,u)),s=I(s);let D=!v||!b||A||g6(e)||0!==m.arrangement.wrap.continuations.size||m.arrangement.compactGaps?new Map:function(e,t){let{edgeArrows:a,groups:l,nodeShapes:i}=t,{direction:s}=e.layout,o="TB"===s||"BT"===s,r=o?"y":"x",n=i.map(e=>um(e)[r]),d=[...new Set(n.map(Math.round))].sort((e,t)=>"BT"===s||"RL"===s?t-e:e-t),c=new Map(i.map((e,t)=>[e.nodeId,d.findIndex(e=>1>=Math.abs(e-n[t]))])),p=fX([...i,...ul(l)],a),h=e=>sx(o?{...p,height:p.height+e}:{...p,width:p.width+e}),g=a.flatMap(e=>{let[t,a]=[c.get(e.sourceNodeId),c.get(e.targetNodeId)],l=fT(e.points);return void 0===t||void 0===a||t<0||a<0||1!==Math.abs(t-a)||4!==l.length?[]:[{corners:l,index:Math.min(t,a)}]}),u=new Map;for(let e=0;e<4;e+=1){let e=h([...u.values()].reduce((e,t)=>e+t,0)),[t,a]=[90/e,150/e],l=!1;for(let{corners:e,index:i}of g){let s=Math.abs(e[3][r]-e[0][r])+(u.get(i)??0);if(Math.hypot(e[2].x-e[1].x,e[2].y-e[1].y)>=a||!u.has(i)&&0===f7(e,t,a).length)continue;let o=Math.ceil(2*t+18-s);o>0&&(u.set(i,(u.get(i)??0)+o),l=!0)}if(!l)break}let f=[...u.values()].reduce((e,t)=>e+t,0),[m,v]=o?[p.height,p.width]:[p.width,p.height];return 2.3>gQ(m+f,v)?u:new Map}(e,s);if(D.size>0){let t=s,a=m,l={...m.arrangement,widenGaps:D},i=fO(e,f[0],l),o={arrangement:l,defects:g(i),layout:i},[r,n]=[I(V(i)),t].map($),[d,c]=[r,n].map(ma),p=!u(g(n),g(r))&&z(r).aspect<2.3&&f$(r)<f$(n)&&fj(r,n,!1,!0)&&fZ(r).size<=fZ(n).size&&fJ(r)<=fJ(n)&&fG(r.edgeArrows)<=fG(n.edgeArrows)&&f5(r.edgeArrows).size<=f5(n.edgeArrows).size&&d.every((e,t)=>e<=c[t])&&f9(r)<=f9(n);({layout:s,settled:m}=p?{layout:r,settled:o}:{layout:n,settled:a})}else s=$(s);let{groups:G,lanes:Z,routedEdges:j}=s,N=[...s.edgeArrows],W=new Map(e.nodes.flatMap(e=>e.description?[[e.id,e.description]]:[])),J=(a=s.nodeShapes,r=(o=a.map(e=>W.has(e.nodeId)?{...e,groupIds:[`${e.id}:described`,...e.groupIds??[]]}:e)).filter(e=>e.label).flatMap(e=>{let t,a,l=W.get(e.nodeId);return l?[uf(e,!0),(t=gk(l,e.shape),a=Math.ceil(14*e.label.split("\n").length*1.35),{type:"text",id:`description:${e.nodeId}`,...e.groupIds?{groupIds:[...e.groupIds]}:{},textColor:"#5f574c",x:e.x+e.width/2,y:e.y+e.height/2+a/2+2+t.height/2,text:t.text,fontSize:12,lineHeight:1.25,maxWidth:Math.ceil(t.width)})]:[uf(e)]}),{nodes:o,texts:r}),K={arrows:N,frames:[],labels:[...J.texts,...fw(N,j,s.nodeShapes,G,!0,Z)],nodes:J.nodes},Q=G&&!G.zoned?function(e,t){let a=new Map(e.frames.map(e=>[e.id,e])),l=t=>{let l=e.groupOf.get(t);return void 0===l?void 0:a.get(l)},i=new Map(t.labels.map(e=>[e.id,e])),s=new Map;for(let e of t.arrows){let t=l(e.sourceNodeId);if(!t||t!==l(e.targetNodeId))continue;let a=i.get(`${e.id}:label`),o=a?fr(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=>un(e,t.box)))&&e.points.every(e=>un(e,t.box))&&s.set(e.id,t.elementId)}let o=new Map(t.nodes.flatMap(e=>{let t=l(e.nodeId);return t?[[e.id,t.elementId]]:[]}));return{arrows:t.arrows.map(e=>{let t=s.get(e.id);return t?{...e,frameId:t}:e}),frames:e.frames.map(t=>({type:"frame",id:t.elementId,name:t.label,...t.icon?{icon:t.icon}:{},...e.composites.has(t.id)?{nodeId:t.id}:{},...t.box})),labels:t.labels.map(e=>{let t=e.containerId?o.get(e.containerId):e.id.startsWith("description:")?o.get(`node:${e.id.slice(12)}`):s.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})}}(G,K):K,{arrows:ee,frames:et,labels:ea}=Q,el=Q.nodes.flatMap(t=>(function(e,t){if(e.label)return[e];let a={...e,label:mo[e.kind??""]??"Marker",rendererRole:"state-marker"};if("initial"===e.kind)return[{...a,fillColor:t,fillStyle:"solid"}];if("final"!==e.kind)return[a];let l=[`marker:${e.nodeId}`,...e.groupIds??[]];return[{...a,groupIds:l},{...a,id:`${e.id}:core`,nodeId:`${e.nodeId}:core`,kind:"final-core",groupIds:l,x:e.x+6,y:e.y+6,width:e.width-12,height:e.height-12,fillColor:t,fillStyle:"solid"}]})(t,e.style.accentColor)),ei=Z?Z.frames.flatMap(e=>{let t=ud(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}]}):G?.zoned?(l=e.style.accentColor,G.frames.flatMap(e=>{var t;let a,i=s$(e.icon),s=Math.max(1,e.box.width-2*g$-i);return[{type:"node",id:e.elementId,nodeId:e.elementId,kind:e.kind??"zone",...e.icon?{icon:e.icon}:{},rendererRole:"zone",shape:"rectangle",...e.box,label:e.label,...(t=e.kind,a=void 0===t?void 0:mn[t],{strokeColor:"cloud"===t||"datacenter"===t?mr:l,strokeStyle:"cloud"===t||"region"===t||"namespace"===t?"dashed":"zone"===t?"dotted":"solid",strokeWidth:"cloud"===t||"datacenter"===t||"vpc"===t||"cluster"===t?2:1,...a?{fillColor:a,fillStyle:"solid"}:{}}),roughness:0,locked:!0},{type:"text",id:`zone-label:${e.id}`,x:e.box.x+g$+i+i_(e.label,gF,s)/2,y:e.box.y+gI/2,text:e.label,fontSize:gF,maxWidth:s,textAlign:"left",textColor:mr,locked:!0}]})):[],es=(p=Math.max(0,48-(c={x:Math.min(...(d=fB(i=[...ei,...et,...ee,...el,...ea])).map(e=>e.x)),y:Math.min(...d.map(e=>e.y))}).x),h=Math.max(0,48-c.y),0===p&&0===h?[...i]:i.map(e=>"arrow"===e.type?{...e,points:function(e,t,a){let[l,...i]=e;return[fA(l,t,a),...i.map(e=>fA(e,t,a))]}(e.points,p,h)}:"line"===e.type?{...e,points:function(e,t,a){let[l,i,...s]=e;return[fA(l,t,a),fA(i,t,a),...s.map(e=>fA(e,t,a))]}(e.points,p,h)}:{...e,x:e.x+p,y:e.y+h})),eo={width:Math.max(...(n=fB(es)).map(e=>e.x))+48,height:Math.max(...n.map(e=>e.y))+48},er=[...ei.map(e=>e.id),...et.map(e=>e.id),...el.map(e=>e.id),...ea.map(e=>e.id),...ee.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:eo.width,height:eo.height,accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:es,layers:[],layouts:[],zOrder:er}}function mp(e,t){if(!t.nodeId.endsWith(eF)||t.id!==`node:${t.nodeId}`||"rectangle"!==t.shape||2!==t.width||t.height<120)return!1;let a=t.nodeId.slice(0,-eF.length);if(0===a.length)return!1;let l=e.elements.find(e=>"node"===e.type&&e.id===`node:${a}`&&e.nodeId===a);return!!l&&.01>=Math.abs(t.x+t.width/2-(l.x+l.width/2))&&t.y>=l.y+l.height-.01}let mh=":initial";function mg(e,t,a,l){let i=0,s=new Map,o=new Map,r=(e,a,l)=>{let i=2*e+ +(a>=t[e]);s.set(i,(s.get(i)??0)+1);let r=1e6*i+Math.round(2*l);o.set(r,(o.get(r)??0)+1)};for(let{parent:a,child:s,link:o}of e.pairs)i+=function(e,t,a){let l=t-e;return 1===l?0:-1===l?.4:0===l?a:2.5*(Math.abs(l)-1)+.4*(l<0)}(t[a],t[s],l),r(a,t[s],o.parentY),r(s,t[a],o.childY);for(let e of s.values())i+=.4*e*(e-1)/2;for(let e of o.values())i+=+Math.max(0,e-2);let n=new Map,d=new Map;for(let[a,l]of e.tables.entries()){let e=t[a];n.set(e,(n.get(e)??-56)+l.height+56),d.set(e,Math.max(d.get(e)??0,l.width))}for(let e of n.values()){let t=Math.max(0,e-a.height)/a.unit;i+=1.5*t*t}let c=Math.max(0,[...d.values()].reduce((e,t)=>e+t,0)+150*Math.max(0,d.size-1)-a.width)/a.column;return i+1.5*c*c}function mu(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 mf(e){let t=e.tables.map(()=>new Set);for(let{parent:a,child:l}of e.pairs)t[a].add(l),t[l].add(a);return t}function mm(e,t,a,l){let i=mf(e),s=e.tables.map((e,t)=>t).sort((e,t)=>i[t].size-i[e].size||e-t),o=l(t);for(let e=0;e<a;e+=1){let e=!1;for(let a of s){let s=t[a],r=new Set([s-2,s-1,s+1,s+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(s);let n=s;for(let e of[...r].sort((e,t)=>e-t)){t[a]=e;let i=l(t);i<o-1e-9&&([n,o]=[e,i])}t[a]=n,n!==s&&(e=!0)}if(!e)break}}function mv(e,t){let a=[...t],l=e.tables.map(e=>e.height),i=e.tables.map(()=>void 0),s=[];for(let{parent:o,child:r,link:n}of e.pairs){let[e,d]=[t[o],t[r]],[c,p]=[n.parentPort??n.parentY,n.childPort??n.childY];if(1>=Math.abs(d-e)){s.push({a:o,b:r,aY:c,bY:p});continue}let h=Math.sign(d-e),g={item:o,y:c};for(let t=e+h;t!==d;t+=h){let e=a.length;a.push(t),l.push(4),i.push({parent:o,y:c}),s.push({a:g.item,b:e,aY:g.y,bY:2}),g={item:e,y:2}}s.push({a:g.item,b:r,aY:g.y,bY:p})}return{column:a,height:l,corridor:i,segments:s}}function my(e,t,a){let l=[t,a].filter(t=>void 0!==e.corridor[t]).length;return 2===l?20:1===l?26:56}function mw(e,t){let a=[],l=0;for(let[i,s]of t.entries())i>0&&(l+=my(e,t[i-1],s)),a.push(l),l+=e.height[s];return a}function mx(e,t){let a=e.column.map(()=>0);for(let l of t)mb(e,a,l);return a}function mb(e,t,a){let l=mw(e,a),i=a.length>0?l.at(-1)+e.height[a.at(-1)]:0;for(let[e,s]of a.entries())t[s]=l[e]-i/2}function mk(e,t){let a=new Map,l=new Map,i=[],s=(e,t,a)=>{let i=2*e+ +!!t,s=l.get(i);s?s.push(a):l.set(i,[a])};for(let{a:l,b:o,aY:r,bY:n}of e.segments){let[d,c]=[e.column[l],e.column[o]],[p,h]=[t[l]+r,t[o]+n];if(d===c){i.push(d,Math.min(p,h),Math.max(p,h));continue}s(d,c>d,p),s(c,d>c,h);let g=Math.min(d,c),u=a.get(g),f=d<c?[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,s]=[i[e],i[e+1],i[e+2]],r=e=>{let i=0;for(let o of l.get(2*t+e)??[])o>a&&o<s&&(i+=1);return i};o+=Math.min(r(0),r(1))}return o}function mM(e){let t=e.column.map(()=>[]);for(let{a,b:l,aY:i,bY:s}of e.segments)t[a].push({other:l,ownY:i,otherY:s}),t[l].push({other:a,ownY:s,otherY:i});return t}function mz(e,t=!0){let a=Array.from({length:Math.max(...e.column)+1},()=>[]);for(let[t,l]of e.column.entries())a[l].push(t);let l=mM(e),i=mx(e,a),s={columns:a.map(e=>[...e]),crossings:mk(e,i)};for(let t=0;t<8&&s.crossings>0;t+=1){let o=[...a.keys()];for(let s of(t%2==1&&o.reverse(),o)){let t=new Map;for(let o of a[s]){let a=0,r=0;for(let{other:t,ownY:n,otherY:d}of l[o]){let l=e.column[t]===s?.5:1;a+=l*(i[t]+d-n),r+=l}t.set(o,r>0?a/r:i[o])}a[s]=[...a[s]].sort((e,a)=>t.get(e)-t.get(a)||i[e]-i[a]),mb(e,i,a[s])}let r=mk(e,i);r<s.crossings&&(s={columns:a.map(e=>[...e]),crossings:r})}i=mx(e,a=s.columns);let o=mk(e,i);for(let l=t&&o>0;l;)for(let t of(l=!1,a))for(let i=0;i+1<t.length;i+=1){[t[i],t[i+1]]=[t[i+1],t[i]];let s=mk(e,mx(e,a));s<o?(o=s,l=!0):[t[i],t[i+1]]=[t[i+1],t[i]]}return{columns:a,top:mx(e,a),crossings:o}}let mC="#f3ebef",m_={one:"crowfoot_one","zero-or-one":"crowfoot_one",many:"crowfoot_many","one-or-many":"crowfoot_one_or_many","zero-or-many":"crowfoot_many"};function mq(e){return"one"===e||"zero-or-one"===e}let mL=e=>Math.ceil(Math.max(0,...e.map(e=>iC(e,14)))),mS={rows:[],foot:0};function mB(e,t=mS){let a=tC(e),l=e.fields.map(e=>[e.pk&&"PK",e.fk&&"FK",e.unique&&!e.pk&&"UK"].filter(e=>"string"==typeof e).join(" ")),i=e.fields.map(e=>`${e.name.trim()}${e.nullable&&!e.type?"?":""}`),s=e.fields.map(e=>e.type?`${e.type}${e.nullable?"?":""}`:""),[o,r,n]=[l,i,s].map(mL),d=14+o+8*(o>0)+r+(n>0?16+n:0)+14,c=Math.ceil(iC(a,16))+28,p=46,h=e.fields.map((e,a)=>{let l=28+(t.rows[a]??0);return p+=l,[tq(e.name),{index:a,top:p-l,height:l,middle:p-l/2}]});return{entity:e,name:a,width:Math.max(160,d,c),height:e.fields.length>0?p+6+t.foot:40,keys:l,names:i,types:s,keyWidth:o,nameWidth:r,typeWidth:n,rows:new Map(h),growth:t}}function mA(e,t){let[a,l]=[t_(e.from),t_(e.to)],i=(e,a,l)=>{let i=((e,a)=>{let l=t.get(e.entity);if(void 0!==e.field)return l.rows.get(tq(e.field));let i=l.entity.fields.filter(e=>e.pk);if(void 0!==a.field&&1===i.length)return l.rows.get(tq(i[0].name))})(e,a);return{entity:e.entity,row:i,y:i?.middle??20,top:i?.top??0,bottom:i?i.top+i.height:40,lines:i?i.height/28:1,cardinality:l}},s={from:i(a,l,e.fromCardinality),to:i(l,a,e.toCardinality)},o=e=>{let a=void 0===e.field?void 0:t.get(e.entity).entity.fields.find(t=>tq(t.name)===tq(e.field));return void 0!==a&&!0===a.pk&&!0!==a.fk};return(mq(e.fromCardinality)!==mq(e.toCardinality)?mq(e.fromCardinality):!(o(l)&&!o(a)))?{relationship:e,parent:s.from,child:s.to}:{relationship:e,parent:s.to,child:s.from}}function mP(e,t){return t.get(e.link[e.end].entity).y+e.row}function mV(e,t){return t.get(e.link[e.end].entity).y+e.y}function mH(e,t){return 1>Math.abs(e.x+e.width/2-(t.x+t.width/2))}function mI(e,t,a){return mH(e.get(t.link[t.end].entity),e.get(a.link[a.end].entity))}function m$(e,t){let a=t.get(e.link[e.end].entity),l=[...t.values()].filter(e=>mH(e,a));return"left"===e.side?a.x-Math.min(...l.map(e=>e.x)):Math.max(...l.map(e=>e.x+e.width))-(a.x+a.width)}function mF(e,t){return e.find(e=>e.link===t.link&&e!==t)}function mO(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 mE(e,t){let a=!1;for(let l of mO(e)){if(l.length<=2)continue;let[i,s]=[l[0].link[l[0].end].entity,l[0].side],o=t.get(i),r="left"===s?"right":"left",n=e.filter(e=>e.link[e.end].entity===i&&e.side===r&&e.row===l[0].row).length,d=a=>{let l=mP(mF(e,a),t);return Math.max(o.y-48-l,l-(o.y+o.height+48))},c=l.filter(t=>mF(e,t).side!==t.side&&d(t)>0).sort((e,t)=>d(t)-d(e)),p=l.length;for(let e of c){if(p-n<2)break;e.side=r,p-=1,n+=1,a=!0}}return a}function mU(e,t,a){let l=e=>mP(mF(t,e),a)-mP(e,a),i=e=>+!!mI(a,e,mF(t,e));return{ups:e.filter(e=>0>l(e)).sort((e,t)=>i(t)-i(e)||l(e)-l(t)),levels:e.filter(e=>0===l(e)),downs:e.filter(e=>l(e)>0).sort((e,t)=>i(e)-i(t)||l(e)-l(t))}}function mX(e,t){let{ups:a,levels:l,downs:i}=e;return new Map([...a.map((e,t)=>[e,t]),...l.map((e,t)=>[e,a.length+t]),...i.map((e,a)=>[e,t-i.length+a])])}function mT(e,t){let a=e.flatMap(e=>{let a=t.sides.get(e.relationship.id);return["parent","child"].map(t=>{let{y:l,top:i,bottom:s,lines:o}=e[t];return{link:e,end:t,side:a[t],row:l,top:i,bottom:s,lines:o,y:l}})});for(let t of e){if(t.parent.entity!==t.child.entity)continue;let[e,l]=a.filter(e=>e.link===t);e&&l&&e.row===l.row&&(l.side="top")}return a}let mR=[...["layered","hub"].flatMap(e=>[1.6,1.1,.7,.5].map(t=>({start:e,aspect:t,sameColumn:1}))),{aspect:.5,sameColumn:0}];function mY(e){let t=e.elements.filter(e=>"arrow"===e.type),a=Math.max(e.width/e.height,e.height/e.width);return fY(t)+sL(t.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),sx({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)],l=0;for(let[t,a]of e.points.slice(1).entries())l+=Math.abs(a.x-e.points[t].x)+Math.abs(a.y-e.points[t].y);return Math.max(0,l/(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,l]of[[a.sourceNodeId,a.points[0]],[a.targetNodeId,a.points.at(-1)]]){let a=`${e}\0${Math.round(l.x)}`;t.set(a,[...t.get(a)??[],l.y])}let a=0;for(let e of t.values()){e.sort((e,t)=>e-t);let t=!1;for(let[l,i]of e.slice(1).entries()){let s=i-e[l]<21.99;s&&(a+=t?.25:1),t=s}}return a}(t)+mZ(e,t)+mD*mG(e,t)}let mD=.25;function mG(e,t){let a=e.elements.flatMap(e=>"node"===e.type?[e]:[]),l=new Map(a.map(e=>[e.nodeId,e])),i=0;for(let e of t){let[t,s]=[l.get(e.sourceNodeId),l.get(e.targetNodeId)];if(!t||!s||t===s||!(t.x<s.x+s.width&&s.x<t.x+t.width))continue;let[o,r]=[Math.min(t.y+t.height,s.y+s.height),Math.max(t.y,s.y)];i+=a.filter(e=>e!==t&&e!==s&&e.y>=o&&e.y+e.height<=r&&e.x<Math.max(t.x+t.width,s.x+s.width)&&Math.min(t.x,s.x)<e.x+e.width).length}return i}function mZ(e,t){let a=new Map(e.elements.flatMap(e=>"node"===e.type?[[e.nodeId,e]]:[])),l=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&&(l+=1)}return l}function mj(e){let t=mT(e.links,e.placement);return e.spill&&mE(t,e.placement.boxes),t}function mN(e,t){return function(e,t,a,l,i,s=!1){let o=function(e,t,a=!1){let l=mO(e),[i,s]=[e=>e.top+3,e=>e.bottom-3],o=new Map;for(let r of l){if(r.length<2)continue;let l=mU(r,e,t),{ups:n,downs:d}=l,{lines:c}=r[0];if(c>1&&!a)for(let[e,t]of mX(l,c))e.y=e.row+(t-(c-1)/2)*28;else{let e=[...n,...l.levels,...d],t=Math.min(22,(s(r[0])-i(r[0]))/(e.length-1));e.forEach((a,l)=>{a.y=a.row+(l-(e.length-1)/2)*t})}let p=(e,a)=>o.set(e,m$(e,t)+48+32*a);n.forEach(p),d.toReversed().forEach(p)}for(let a of l){if(a.length>1)continue;let l=a[0],o=mF(e,l);if(o.side===l.side||"top"===o.side)continue;let r=mV(o,t)-(mP(l,t)-l.row);r>=i(l)&&r<=s(l)&&(l.y=r)}for(let a of e)"top"!==a.side&&!o.has(a)&&m$(a,t)>0&&o.set(a,m$(a,t)+48);let r=new Map;for(let t of e){if("top"===t.side)continue;let e=`${t.link[t.end].entity}\0${t.side}`;r.set(e,[...r.get(e)??[],t])}for(let e of r.values()){let{height:a}=t.get(e[0].link[e[0].end].entity);!function(e,t,a){if(e.length<2)return;let l=(t,a)=>e[a].row===e[a-1].row?t:Math.max(t,9),i=i=>{let s=-1/0;for(let[o,r]of e.entries())if((s=Math.max(t(r),o>0?s+l(i,o):s))>a(r)+1e-9)return!1;return!0},[s,o]=[0,22];if(i(o))s=o;else for(let e=0;e<24;e+=1){let e=(s+o)/2;i(e)?s=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]-l(s,t+1));let n=-1/0;for(let[a,i]of e.entries()){let e=a>0?n+l(s,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(i(e),16),e=>Math.min(s(e),a-16))}return o}(i,l.boxes,s);!function(e,t,a){let l=e.filter(e=>"parent"===e.end).flatMap(a=>{let l=mF(e,a);return a.side===l.side&&"top"!==a.side&&mI(t,a,l)?[{parent:a,child:l}]:[]}).sort((e,a)=>Math.abs(mV(e.parent,t)-mV(e.child,t))-Math.abs(mV(a.parent,t)-mV(a.child,t))),i=[];for(let{parent:e,child:s}of l){let[l,o]=[t.get(e.link.parent.entity),t.get(e.link.child.entity)],r=e=>(a.get(e)??m$(e,t)+48)-m$(e,t),n=Math.max(r(e),r(s)),[d,c]=[mV(e,t),mV(s,t)].sort((e,t)=>e-t),p=i.filter(a=>a.end.side===e.side&&mI(t,a.end,e)&&a.top<=c&&d<=a.bottom);if("left"===e.side){let r=Math.min(l.x-m$(e,t)-n,...p.map(e=>e.tip-32));a.set(e,l.x-r),a.set(s,o.x-r),i.push({end:e,top:d,bottom:c,tip:r})}else{let r=Math.max(l.x+l.width+m$(e,t)+n,...p.map(e=>e.tip+32));a.set(e,r-l.x-l.width),a.set(s,r-o.x-o.width),i.push({end:e,top:d,bottom:c,tip:r})}}}(i,l.boxes,o);let r=new Map(i.map(e=>{var a,l;let s=t.get(e.link[e.end].entity),r="top"===e.side?("left"===(a=i,l=e.link,a.find(e=>e.link===l&&"parent"===e.end)?.side??"right")?-1:1)*(s.width/2-28):e.y-s.height/2,n=o.get(e);return[`${e.link.relationship.id}:${"parent"===e.end?"source":"target"}`,{side:e.side,offset:r,...void 0===n?{}:{run:n}}]}));return mc({id:e.id,title:e.title,type:"flowchart",nodes:e.entities.map(e=>({id:e.id,label:tC(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:l.boxes,anchors:r,endRun:48})}(e,t.tables,t.links,t.placement,mj(t),t.packed)}function mW(e,t,a,l=new Map){return function(e,t,a={}){var l;let i,s,o,r,n,d,c=(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}])}),p=a.arrangement,h=p?[...p.column]:(o=function(e,t=1.6){let a=e.tables.reduce((e,t)=>e+(t.width+132)*(t.height+56),0),l=Math.max(...e.tables.map(e=>e.height)),i=e.tables.reduce((e,t)=>e+t.height+56,0)/e.tables.length,s=e.tables.reduce((e,t)=>e+t.width+150,0)/e.tables.length,o=Math.max(l,Math.sqrt(a/t));return{height:o,unit:i,width:1.25*t*o,column:s}}(c,a.aspect),r=a.sameColumn??2.5,n="hub"===a.start?function(e){let t=mf(e),a=e.tables.map(()=>void 0),l=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,l.set(i,0);let s={[-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=l.get(i);0===t&&(t=s[1]<=s[-1]?1:-1,s[t]=s[t]+e.tables[r].height),a[r]=a[i]+t,l.set(r,t),o.push(r)}}}return a.map(e=>e??0)}(c):function(e){let t=e.tables.length,a=Array.from({length:t},()=>[]);for(let{parent:t,child:l}of e.pairs)a[t].push(l);let l=Array.from({length:t}).fill(0),i=Array.from({length:t},()=>[]),s=e=>{for(let t of(l[e]=1,a[e]))1!==l[t]&&(i[e].push(t),0===l[t]&&s(t));l[e]=2};for(let e=0;e<t;e+=1)0===l[e]&&s(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=[],d=o.map(e=>e.length),c=d.flatMap((e,t)=>0===e?[t]:[]);for(;c.length>0;){let e=c.shift();for(let t of(n.push(e),i[e]))r[t]=Math.max(r[t],r[e]+1),d[t]-=1,0===d[t]&&c.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}(c),mm(c,n,40,e=>mg(c,e,o,r)),d=new Map,mm(c,n,8,e=>{let t=mu(e),a=t.join(","),l=d.get(a);return void 0===l&&(l=mz(mv(c,t),!1).crossings,d.set(a,l)),mg(c,e,o,r)+ +l}),mu(n)),g=Math.max(...h)+1,u=mv(c,h),f=p?(l=u,{columns:i=p.stacks.map(e=>[...e]),top:mx(l,i),crossings:mk(l,mx(l,i))}):mz(u),m=function(e,t){let a=[...t.top],l=mM(e);for(let i=0;i<12;i+=1){let s=[...t.columns.keys()];for(let o of(i%2==1&&s.reverse(),s)){let i=t.columns[o];if(0===i.length)continue;let s=[],r=[];for(let t of i){let i=e.corridor[t];if(i){s.push(a[i.parent]+i.y-2),r.push(4);continue}let n=0,d=0;for(let{other:i,ownY:s,otherY:r}of l[t])e.column[i]!==o&&(n+=a[i]+r-s,d+=1);s.push(d>0?n/d:a[t]),r.push(d>0?d:.05)}let n=mw(e,i),d=function(e,t){let a=[];for(let[l,i]of e.entries()){let e=t[l];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))}(s.map((e,t)=>e-n[t]),r);for(let[e,t]of i.entries())a[t]=d[e]+n[e]}}return function(e,t,a){let l=mM(e),i=t=>t.reduce((t,i)=>t+l[i].filter(({other:t,ownY:l,otherY:s})=>e.column[t]!==e.column[i]&&.5>Math.abs(a[t]+s-a[i]-l)).length,0),s=(t,l)=>a[l]-a[t]-e.height[t]-my(e,t,l)<.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 l[r].flatMap(({other:t,ownY:l,otherY:i})=>{let s=a[t]+i-a[r]-l;return e.column[t]!==e.column[r]&&Math.abs(s)>=.5&&40>=Math.abs(s)?[s]:[]})){let l=[r],d=n>0?1:-1;for(let i=t;;i+=d){let t=o[i+d];if(void 0===t)break;if(!(d>0?s(o[i],t):s(t,o[i]))){(d>0?a[t]-a[o[i]]-e.height[o[i]]-my(e,o[i],t):a[o[i]]-a[t]-e.height[t]-my(e,t,o[i]))<Math.abs(n)-.5&&(l.length=0);break}l.push(t)}if(0===l.length)continue;let c=i(l);for(let e of l)a[e]=a[e]+n;if(i(l)>c)break;for(let e of l)a[e]=a[e]-n}return a}(e,t,a.map(e=>Math.round(e)))}(u,f),v=function(e,t,a,l){let i=new Map,s=[],o=[];for(let a of e.links){let[r,n]=[e.index.get(a.parent),e.index.get(a.child)],[d,c]=[t[r],t[n]];if(d===c){o.push(a);continue}let[p,h]=d<c?["right","left"]:["left","right"];i.set(a.id,{parent:p,child:h}),s.push({column:d,side:p,y:l[r]+a.parentY}),s.push({column:c,side:h,y:l[n]+a.childY})}for(let r of o){let[o,n]=[e.index.get(r.parent),e.index.get(r.child)],d=t[o],[c,p]=[l[o]+r.parentY,l[n]+r.childY],[h,g]=[Math.min(c,p),Math.max(c,p)],u=e=>s.filter(t=>t.column===d&&t.side===e&&t.y>h&&t.y<g).length,f=0===d&&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}),s.push({column:d,side:y,y:c},{column:d,side:y,y:p})}return i}(c,h,g,m),y=function(e,t,a,l){let i=Array.from({length:Math.max(0,l-1)},()=>0),s=Array.from({length:Math.max(0,l-1)},()=>0),o=new Map,r=(e,a,l)=>{let i="right"===a?t[e]:t[e]-1,s=`${e}:${a}:${l}`,r=o.get(s)??{gap:i,low:"right"===a,count:0};r.count+=1,o.set(s,r)};for(let l of e.links){let[o,n]=[e.index.get(l.parent),e.index.get(l.child)],[d,c]=[t[o],t[n]],p=a.get(l.id);r(o,p.parent,l.parentY),r(n,p.child,l.childY);let h="right"===p.parent?d:d-1;if(l.labelWidth>0&&h>=0&&h<i.length&&(s[h]=Math.max(s[h],l.labelWidth+16)),d===c){h>=0&&h<i.length&&(i[h]+=1);continue}for(let e=Math.min(d,c);e<Math.max(d,c);e+=1)i[e]+=1}let n=i.map(()=>({low:0,high:0})),d=new Map;for(let[e,{gap:t,low:a,count:l}]of o){let i=(l-1)*32,s=e.split(":").slice(0,2).join(":");d.set(s,Math.max(d.get(s)??0,i));let o=n[t];o&&(a?o.low=Math.max(o.low,i):o.high=Math.max(o.high,i))}for(let l of e.links){let[i,s]=[e.index.get(l.parent),e.index.get(l.child)];if(t[i]!==t[s])continue;let o=a.get(l.id).parent,r=n["right"===o?t[i]:t[i]-1];if(!r)continue;let c=Math.max(d.get(`${i}:${o}`)??0,d.get(`${s}:${o}`)??0)+32+Math.abs(e.tables[i].width-e.tables[s].width)/2;"right"===o?r.low=Math.max(r.low,c):r.high=Math.max(r.high,c)}return i.map((e,t)=>Math.max(132,96+n[t].low+n[t].high+s[t]+20*(e+1)))}(c,h,v,g),w=Array.from({length:g},(t,a)=>Math.max(0,...f.columns[a].flatMap(t=>t<e.length?[e[t].width]:[]))),x=88*!!t.some(e=>{let t=h[c.index.get(e.parent)];return t===h[c.index.get(e.child)]&&(0===t||t===g-1)}),b=[],k=x;for(let[e,t]of w.entries())b.push(k),k+=t+(y[e]??0);let M=Math.min(...m.slice(0,e.length));return{boxes:new Map(e.map((e,t)=>{let a=h[t];return[e.id,{x:b[a]+Math.round((w[a]-e.width)/2),y:m[t]-M,width:e.width,height:e.height}]})),sides:v,arrangement:{column:h,stacks:f.columns}}}([...e.values()].map(e=>({id:e.entity.id,width:e.width,height:e.height})),t.map(e=>({id:e.relationship.id,parent:e.parent.entity,child:e.child.entity,parentY:e.parent.y,childY:e.child.y,...l.has(`${e.relationship.id}:parent`)?{parentPort:e.parent.y+l.get(`${e.relationship.id}:parent`)}:{},...l.has(`${e.relationship.id}:child`)?{childPort:e.child.y+l.get(`${e.relationship.id}:child`)}:{},labelWidth:e.relationship.label?Math.min(160,Math.ceil(iC(e.relationship.label,13))):0})),a)}function mJ(e){let t=e.elements.filter(e=>"arrow"===e.type);return{crossings:fY(t),findings:sL(t.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),sx({width:e.width,height:e.height})).length,detours:t.filter(e=>{let[t,a]=[e.points[0],e.points.at(-1)],l=0;for(let[t,a]of e.points.slice(1).entries())l+=Math.abs(a.x-e.points[t].x)+Math.abs(a.y-e.points[t].y);return l>2*(Math.abs(a.x-t.x)+Math.abs(a.y-t.y))+120}).length,wraps:mZ(e,t),passed:mG(e,t),marksOnLabels:function(e,t){let a=e.elements.flatMap(e=>"text"===e.type&&void 0===e.containerId?[{x:e.x,y:e.y,half:Math.min(e.maxWidth??1/0,iC(e.text,e.fontSize))/2,height:1.25*e.fontSize/2}]:[]),l=0;for(let e of t)for(let[t,i]of[[e.points[0],e.points[1]],[e.points.at(-1),e.points.at(-2)]]){let e=Math.hypot(i.x-t.x,i.y-t.y)||1,s=Math.min(20,e/2),[o,r]=[(i.x-t.x)/e,(i.y-t.y)/e],[n,d]=[Math.min(t.x,t.x+o*s),Math.max(t.x,t.x+o*s)],[c,p]=[Math.min(t.y,t.y+r*s),Math.max(t.y,t.y+r*s)];a.some(e=>n-9*Math.abs(r)<e.x+e.half&&e.x-e.half<d+9*Math.abs(r)&&c-9*Math.abs(o)<e.y+e.height&&e.y-e.height<p+9*Math.abs(o))&&(l+=1)}return l}(e,t),length:Math.max(e.width,e.height)}}function mK(e,t,a,l,i,s=32){let o=e.points,[r,n]="start"===t?[o[0],o[1]]:[o.at(-1),o.at(-2)],d=n?Math.hypot(n.x-r.x,n.y-r.y):1,[c,p]=n?[(n.x-r.x)/d,(n.y-r.y)/d]:[1,0],h={x:r.x+c*s,y:r.y+p*s};return{type:"node",id:`node:${a}:optional:${l}`,nodeId:`${a}:optional:${l}`,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 mQ(e,t,a,l,i){let s=0;for(let{parent:a,child:l}of e.generalizations){let e=t[l]-t[a];if(e<1)return 1/0;s+=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):s+=l+2.5*(e-1),n&&t[a]>t[r]&&(s+=i)}for(let e of o)s+=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:l}of e.others){if(t[a]!==t[l])continue;let[e,i]=[n(a),n(l)];e===i?s+=1.5:r[e]=i}let d=new Map,c=new Map;for(let[a,l]of e.boxes.entries()){let e=t[a];d.set(e,(d.get(e)??-64)+l.width+64),c.set(e,Math.max(c.get(e)??0,l.height))}for(let e of d.values()){let t=Math.max(0,e-a.width)/a.column;s+=1.5*t*t}let p=Math.max(0,[...c.values()].reduce((e,t)=>e+t,0)+130*Math.max(0,c.size-1)-1.2*a.height)/a.unit;return s+1.5*p*p}function m1(e,t,a,l){let i=[a,l].filter(t=>e.corridor[t]).length;return 2===i?28:1===i?Math.max(30,t.get(a<l?`${a}:${l}`:`${l}:${a}`)??0):Math.max(64,t.get(a<l?`${a}:${l}`:`${l}:${a}`)??0)}function m0(e,t,a){let l=[];for(let[i,s]of a.entries()){if(0===i){l.push(0);continue}let o=a[i-1],r=l[i-1]+e.width[o]+m1(e,t,o,s);for(let[o,n]of a.slice(0,i-1).entries()){let a=t.get(n<s?`${n}:${s}`:`${s}:${n}`);void 0!==a&&(r=Math.max(r,l[o]+e.width[n]+a))}l.push(r)}return l}function m2(e,t,a){let l=e.row.map(()=>0);for(let i of a){let a=m0(e,t,i),s=i.length>0?a.at(-1)+e.width[i.at(-1)]:0;for(let[t,o]of i.entries())l[o]=a[t]+e.width[o]/2-s/2}return l}function m3(e,t,a){let l=new Map;for(let{upper:t,lower:i}of e.segments){let s=l.get(e.row[t])??[];s.push({upper:a[t],lower:a[i]}),l.set(e.row[t],s)}let i=0;for(let e of l.values())for(let[t,a]of e.entries())for(let l of e.slice(t+1))(a.upper-l.upper)*(a.lower-l.lower)<0&&(i+=1);let s=new Map;for(let e of t)for(let[t,a]of e.entries())s.set(a,t);let o=e.flats.map(({a:t,b:a})=>{let[l,i]=[s.get(t),s.get(a)].sort((e,t)=>e-t);return{row:e.row[t],low:l,high:i}});for(let a of o){let l=t[a.row];for(let t=a.low+1;t<a.high;t+=1)e.corridor[l[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 m5(e,t){let a=[];for(let[l,i]of e.entries()){let e=t[l];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 m4(e,t){return e.find(e=>e.link===t.link&&e!==t)}let m6=e=>"top"===e||"bottom"===e;function m7(e,t){let a=(e,t)=>e>t.min+.5&&e<t.max-.5,l=(e,t)=>t.some(t=>.5>Math.abs(e-t)),i=0;for(let l of t.upper)a(l,e)&&(i+=1);for(let l of e.lower)a(l,t)&&(i+=1);for(let a of e.lower)l(a,t.upper)&&(i+=1e3);return i}function m8(e,t,a={},l=0){let i=function(e,t){let a=new Map(e.map((e,t)=>[e.id,t])),l=[],i=[];for(let e of t){let[t,s]=[a.get(e.from),a.get(e.to)];t!==s&&(e.generalization?l.push({parent:s,child:t}):i.push({a:t,b:s,whole:!0===e.whole}))}return{boxes:e,index:a,links:t,generalizations:l,others:i}}(e,t),s=function(e,t){let a,l=function(e,t=1.6){let a=e.boxes.reduce((e,t)=>e+(t.width+64)*(t.height+130),0),l=Math.max(...e.boxes.map(e=>e.width)),i=Math.sqrt(a/t),s=e.boxes.length;return{width:Math.max(l,1.2*t*i),height:i,column:e.boxes.reduce((e,t)=>e+t.width+64,0)/s,unit:e.boxes.reduce((e,t)=>e+t.height+130,0)/s}}(e,t.aspect),i=t.between??.3,s=t.wholeBelow??0,o=function(e){let t=e.boxes.length,a=Array.from({length:t},()=>[]),l=Array.from({length:t},()=>[]);for(let{parent:t,child:i}of e.generalizations)a[i].push(t),l[t].push(i);let i=Array.from({length:t},()=>0),s=a.map(e=>e.length),o=s.flatMap((e,t)=>0===e?[t]:[]),r=[];for(;o.length>0;){let e=o.shift();for(let t of(r.push(e),l[e]))i[t]=Math.max(i[t],i[e]+1),s[t]-=1,0===s[t]&&o.push(t)}for(let e of r.toReversed())l[e].length>0&&(i[e]=Math.min(...l[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,l]=n.has(t)?[t,a]:[a,t];i[l]=i[e],n.add(l)}let d=Math.min(...i);return i.map(e=>e-d)}(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),d=mQ(e,o,l,i,s),c=e.boxes.map(()=>[]);for(let{parent:t,child:a}of e.generalizations)c[t].push(a);let p=t.hierarchies?n.flatMap(e=>{if(0===c[e].length)return[];let t=new Set([e]);for(let e of t)for(let a of c[e])t.add(a);return[[...t]]}):[];for(let t=0;t<40;t+=1){let t=!1;for(let a of p)for(let r of[-1,1]){for(let e of a)o[e]+=r;let n=mQ(e,o,l,i,s);if(n<d-1e-9)d=n,t=!0;else for(let e of a)o[e]-=r}for(let a of n){let n=o[a],c=new Set([n-1,n+1,n+2]);for(let e of r[a])for(let t of[-1,0,1])c.add(o[e]+t);if(0===r[a].size)for(let e of o)c.add(e);c.delete(n);let p=n;for(let t of[...c].sort((e,t)=>e-t)){o[a]=t;let r=mQ(e,o,l,i,s);r<d-1e-9&&([p,d]=[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))}(i,a),o=function(e,t){let a=[...t],l=e.boxes.map(e=>e.width),i=e.boxes.map(()=>!1),s=[],o=[],r=[];for(let n of e.links){let[d,c]=[e.index.get(n.from),e.index.get(n.to)];if(d===c){r.push([d]);continue}let[p,h]=[t[d],t[c]];if(p===h){o.push({a:d,b:c}),r.push([d,c]);continue}let g=Math.sign(h-p),u=[d];for(let e=p+g;e!==h;e+=g){let t=a.length;a.push(e),l.push(4),i.push(!0),u.push(t)}u.push(c);let f=n.generalization?3:1;for(let[e,t]of u.slice(1).entries()){let l=u[e];s.push(a[l]<a[t]?{upper:l,lower:t,weight:f}:{upper:t,lower:l,weight:f})}r.push(u)}return{row:a,width:l,corridor:i,segments:s,flats:o,chains:r}}(i,s),r=new Map,n=(e,t,a)=>{let l=e<t?`${e}:${t}`:`${t}:${e}`;r.set(l,Math.max(r.get(l)??0,a))};for(let[e,a]of t.entries()){let t=o.chains[e],[l,i]=[t[0],t.at(-1)];l!==i&&o.row[l]===o.row[i]&&n(l,i,Math.max(50,a.fromLabel+16)+(a.label>0?a.label+16:0)+Math.max(50,a.toLabel+16))}let d=function(e,t){let a=Array.from({length:Math.max(...e.row)+1},()=>[]);for(let[t,l]of e.row.entries())a[l].push(t);let l=e.row.map(()=>[]);for(let{upper:t,lower:a}of e.segments)l[t].push({other:a,weight:1}),l[a].push({other:t,weight:1});for(let{a:t,b:a}of e.flats)l[t].push({other:a,weight:.5}),l[a].push({other:t,weight:.5});let i=m2(e,t,a),s={rows:a.map(e=>[...e]),crossings:m3(e,a,i)};for(let o=0;o<8&&s.crossings>0;o+=1){let r=[...a.keys()];for(let s of(o%2==1&&r.reverse(),r)){let o=new Map;for(let e of a[s]){let t=0,a=0;for(let{other:s,weight:o}of l[e])t+=o*i[s],a+=o;o.set(e,a>0?t/a:i[e])}a[s]=[...a[s]].sort((e,t)=>o.get(e)-o.get(t)||i[e]-i[t]),i=m2(e,t,a)}let n=m3(e,a,i);n<s.crossings&&(s={rows:a.map(e=>[...e]),crossings:n})}let o=a=(a=s.rows).map(t=>{let a=t=>e.segments.find(e=>e.lower===t)?.upper,l=new Map;for(let e of t){let t=a(e);void 0!==t&&l.set(t,[...l.get(t)??[],e])}let i=t;for(let t of l.values()){let a=t.filter(t=>e.corridor[t]),l=t.filter(t=>!e.corridor[t]);if(0===a.length||l.length<2)continue;let s=[];for(let[e,t]of l.entries()){s.push(t);let i=Math.round(e*a.length/(l.length-1)),o=Math.round((e+1)*a.length/(l.length-1));e<l.length-1&&s.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]=s[e];i=r}return i});a=s.rows,m3(e,o,m2(e,t,o))<=m3(e,a,m2(e,t,a))&&(a=o);let r=m3(e,a,m2(e,t,a));for(let l=r>0,i=0;l&&i<40;i+=1)for(let i of(l=!1,a))for(let s=0;s+1<i.length;s+=1){[i[s],i[s+1]]=[i[s+1],i[s]];let o=m3(e,a,m2(e,t,a));o<r?(r=o,l=!0):[i[s],i[s+1]]=[i[s+1],i[s]]}return a}(o,r);for(let[e,l]of t.entries()){let t=o.chains[e],[i,s]=[t[0],t.at(-1)];if(i===s||o.row[i]!==o.row[s])continue;let r=d[o.row[i]],[c,p]=[r.indexOf(i),r.indexOf(s)],h=r.slice(Math.min(c,p)+1,Math.max(c,p));if(0===h.length||h.some(e=>!o.corridor[e]))continue;let[g,u]=c<p?[i,s]:[s,i],[f,m]=c<p?[l.fromLabel,l.toLabel]:[l.toLabel,l.fromLabel],v=a.labelRoom?30:16;n(g,h[0],Math.max(50,f+v)),n(h.at(-1),u,Math.max(50,m+v))}let c=e=>Math.max(40,Math.max(e.fromLabel,e.toLabel)+24);for(let[e,a]of t.entries()){if(a.from!==a.to)continue;let t=o.chains[e][0],l=d[o.row[t]],i=l.filter(e=>!o.corridor[e]),s=i.indexOf(t),r=l.indexOf(t),p=c(a)+a.label+56+64;for(let e of[i[s-1],i[s+1],l[r-1],l[r+1]])void 0!==e&&n(t,e,p)}let p=function(e,t,a){let l=m2(e,t,a),i=e.row.map(()=>[]);for(let{upper:t,lower:a,weight:l}of e.segments)i[t].push({other:a,weight:l}),i[a].push({other:t,weight:l});for(let s=0;s<12;s+=1){let o=[...a.keys()];for(let r of(s%2==1&&o.reverse(),o)){let s=a[r];if(0===s.length)continue;let o=[],n=[];for(let t of s){let a=i[t];if(0===a.length){o.push(l[t]),n.push(.05);continue}let s=a.reduce((e,{weight:t})=>e+t,0);o.push(a.reduce((e,{other:t,weight:a})=>e+a*l[t],0)/s),n.push(e.corridor[t]?4:s)}let d=m0(e,t,s),c=m5(o.map((t,a)=>t-e.width[s[a]]/2-d[a]),n);for(let[t,a]of s.entries())l[a]=c[t]+d[t]+e.width[a]/2}}for(let s of a){let a=m0(e,t,s),o=t=>l[s[t]]-e.width[s[t]]/2-a[t],r=s.findIndex(e=>i[e].length>0),n=s.findLastIndex(e=>i[e].length>0);if(!(r<0))for(let[t,i]of s.entries())(t<r||t>n)&&(l[i]=o(t<r?r:n)+a[t]+e.width[i]/2)}return l.map((t,a)=>{let l=e.width[a]/2;return Math.round(t-l)+l})}(o,r,d),h=t=>t<e.length?e[t]:{id:"",width:4,height:0},g=Math.ceil(24/sx({width:Math.max(...e.map((e,t)=>p[t]+e.width/2))-Math.min(...e.map((e,t)=>p[t]-e.width/2)),height:d.reduce((t,a)=>t+Math.max(0,...a.filter(t=>t<e.length).map(t=>e[t].height))+100+28,0)}))+4,u={port:Math.max(32,g),track:Math.max(28,g),lane:Math.max(20,g),clearLabels:!0===a.labelRoom},f=function(e,t,a,l){let i=new Map;for(let e of a)for(let[t,a]of e.entries())i.set(a,t);let s=[],o=new Map,r=(e,t)=>o.set(`${e}:${t}`,(o.get(`${e}:${t}`)??0)+1),n=[],d=(e,t,a,l,i)=>({link:e,end:t,box:a,side:i,at:0,toward:l,loop:!1,slot:0}),c=(e,a,i,s)=>t.segments.filter(({upper:o,lower:r})=>{let n=s?r:o;return t.row[n]===e&&l[n]>a&&l[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([d(o,"source",p,p,"right"),d(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]=[l[p],l[h]].sort((e,t)=>e-t),[a,i]=[c(g,e,t,!0),c(g,e,t,!1)];f=a<i||a===i&&0===g?["top","top"]:["bottom","bottom"]}s.push(d(o,"source",p,h,f[0]),d(o,"target",h,p,f[1])),r(p,f[0]),r(h,f[1]);continue}let g=t.row[p]<t.row[h];s.push(d(o,"source",p,e[1],g?"bottom":"top"),d(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,l=e=>s.some(t=>t.box===a&&t.side===e),i=["right","left","top","bottom"].filter(e=>!l(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;s.push(...e)}return s}(i,o,d,p);if(l<2){let i=e.map((e,t)=>{let a=e=>36+Math.max(0,f.filter(a=>a.box===t&&a.side===e).length-1)*u.port,l=Math.ceil(Math.max(e.width,a("top"),a("bottom"))),i=Math.ceil(Math.max(e.height,a("left"),a("right")));return l===e.width&&i===e.height?e:{...e,width:l,height:i}});if(i.some((t,a)=>t!==e[a]))return m8(i,t,a,l+1)}let m=()=>(function(e,t,a,l,i,s){let{port:o,lane:r}=s,n=new Map;for(let t of e){let e=`${t.box}:${t.side}`;n.set(e,[...n.get(e)??[],t])}let d=e=>t[e]-a(e).width/2,c=e=>m6(e.side)?a(e.box).width:a(e.box).height,p=e=>{let{end:t,name:a}=l(e);if(!m6(e.side))return t>0?s.clearLabels?40:26:0;let i=Math.max(t,e.loop||0===a?0:Math.ceil(a/2)+14);return i>0?i+(s.clearLabels?30:14):0},h=(e,t)=>{let[a,l]=[p(e),p(t)];return Math.max(o,a>0&&l>0?a+l:Math.max(a,l))},g=e=>{let t=e.slice(1).map((t,a)=>h(e[a],t)),a=c(e[0])-36,l=t.length*o,i=t.reduce((e,t)=>e+t-o,0),s=l+i<=a?t:l<=a?t.map(e=>o+(e-o)*(a-l)/i):t.map(()=>a/t.length),r=[0];for(let e of s)r.push(r.at(-1)+e);return r},u=(t,l)=>{if(m6(t.side))return!1;let i=m4(e,t);return[...a(t.box).dividers??[],...i.loop?[]:a(i.box).dividers??[]].some(e=>8>Math.abs(e-l))},f=t=>{let l=m4(e,t),i=t.loop?a(t.box).height:Math.min(a(t.box).height,a(l.box).height),s=Math.round(i/2);for(let e=0;e<i/2-18;e+=2)for(let a of[s+e,s-e])if(!u(t,a))return a;return s},m=i=>{let s=m4(e,i);if(m6(i.side)&&i.loop){let e=Math.min(2*Math.max(l(i).end,l(s).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(m6(i.side))return(s.box!==i.toward||i.loop?t[i.toward]:d(s.box)+s.at)-d(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 s.at};for(let t of e)t.at=m6(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=c(t[0]),l=t.map(m),i=t.map((e,t)=>t).sort((e,a)=>l[e]-l[a]||t[e].link-t[a].link||("source"===t[e].end?-1:1)),s=g(i.map(e=>t[e])),o=m5(i.map((e,t)=>l[e]-s[t]),i.map(()=>1)),r=s.at(-1)??0;i.forEach((l,i)=>{let n=Math.round(Math.min(Math.max(o[i],18),a-18-r)+s[i]);n!==t[l].at&&(e=!0),t[l].at=n})}if(!e)break}let v=(e,t)=>{let a=n.get(`${e.box}:${e.side}`);return!(t<18||t>c(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||!m6(t.side))continue;let a=m4(e,t);if(a.box!==t.toward||!m6(a.side)||a.side===t.side)continue;let[l,i]=[d(t.box)+t.at,d(a.box)+a.at];!(.5>Math.abs(l-i)||Math.abs(l-i)>72)&&(v(a,Math.round(l-d(a.box)))?a.at=Math.round(l-d(a.box)):v(t,Math.round(i-d(t.box)))&&(t.at=Math.round(i-d(t.box))))}let y=e=>d(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)-(d(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=c(e);for(let l=4;l<=3*o;l+=4)for(let i of[l,-l])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(m6(t.side)||!u(t,t.at))continue;let a=m4(e,t),l=!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)&&(!l||v(a,e)));if(void 0!==i){t.at=i,l&&(a.at=i);break}}}let k=new Map;for(let e of n.values()){let t=e.toSorted((e,t)=>e.at-t.at),a=36+t.slice(1).reduce((e,a,l)=>e+h(t[l],a),0),{box:l,side:i}=t[0],s=k.get(l)??{width:0,height:0};k.set(l,m6(i)?{...s,width:Math.max(s.width,a)}:{...s,height:Math.max(s.height,a)})}return k})(f,p,h,e=>{let a=t[e.link];return{end:"source"===e.end?a.fromLabel:a.toLabel,name:a.label}},e=>o.row[e],u),v=m();if(a.labelRoom&&l<2){let i=e.map((e,t)=>{let a=v.get(t),[l,i]=[Math.ceil(Math.max(e.width,a?.width??0)),Math.ceil(Math.max(e.height,a?.height??0))];return l===e.width&&i===e.height?e:{...e,width:l,height:i}});if(i.some((t,a)=>t!==e[a]))return m8(i,t,a,l+1)}let y=e=>p[e]-h(e).width/2,w=e=>y(e.box)+e.at,x=t.map((e,t)=>["source","target"].map(e=>f.find(a=>a.link===t&&a.end===e)));!function(e,t,a,l,i,s,o){let r=new Map;for(let e of a)for(let[t,a]of e.entries())r.set(a,t);let n=(i,s)=>{let o=a[e.row[i]],n=r.get(i),[d,c]=[o[n-1],o[n+1]],p=e.width[i]/2;return(void 0===d||s-p>=l[d]+e.width[d]/2+m1(e,t,d,i))&&(void 0===c||s+p<=l[c]-e.width[c]/2-m1(e,t,i,c))};for(let[t,a]of e.chains.entries()){let e=a.slice(1,-1);if(0===e.length)continue;let s=i(t).find(t=>e.every(e=>n(e,t)));if(void 0!==s)for(let t of e)l[t]=s}for(let[t,a]of e.chains.entries())for(let i of a.slice(1,-1)){let a=e.row[i],r=e=>s.some(l=>l.link!==t&&(l.row===a-1||l.row===a+1)&&Math.abs(l.x-e)<o.lane);if(r(l[i]))for(let e=4;e<=3*o.port;e+=4){let t=[l[i]+e,l[i]-e].find(e=>n(i,e)&&!r(e));if(void 0!==t){l[i]=t;break}}}}(o,r,d,p,e=>{let[t,a]=x[e];return o.row[t.box]<o.row[a.box]?[w(t),w(a)]:[w(a),w(t)]},f.flatMap(e=>m6(e.side)&&!e.loop?[{link:e.link,row:o.row[e.box],x:w(e)}]:[]),u),o.corridor.some(Boolean)&&m();let b=d.length,k=d.map(t=>Math.max(0,...t.filter(t=>t<e.length).map(t=>e[t].height))),M=new Map,z=(e,t)=>M.set(e,[...M.get(e)??[],t]);for(let[e]of t.entries()){let[t,a]=x[e],l=o.chains[e];if(t.loop||"left"===t.side||"right"===t.side)continue;if(t.side===a.side){let[e,i]=[w(t),w(a)],s=o.row[l[0]],r="top"===t.side;z(r?s-1:s,{ends:[t,a],upper:r?[]:[e,i],lower:r?[e,i]:[],min:Math.min(e,i),max:Math.max(e,i),track:0});continue}let i=o.row[l[0]]<o.row[l.at(-1)]?l:l.toReversed(),[s,r]=i[0]===l[0]?[t,a]:[a,t];for(let[e,t]of i.slice(1).entries()){let a=i[e],l=a===i[0]?w(s):p[a],n=t===i.at(-1)?w(r):p[t];.5>Math.abs(l-n)||z(o.row[a],{ends:[...a===i[0]?[s]:[],...t===i.at(-1)?[r]:[]],upper:[l],lower:[n],min:Math.min(l,n),max:Math.max(l,n),track:0})}}let C=new Map([...M].map(([e,t])=>[e,function(e,t){let a=[...e],l=[];for(;a.length>0;){let e=0,t=1/0;for(let[l,i]of a.entries()){let s=a.reduce((e,t)=>t===i?e:e+m7(i,t),0);s<t&&([e,t]=[l,s])}l.push(a.splice(e,1)[0])}let i=(e,a)=>e.min<a.max+t&&a.min<e.max+t,s=0;for(let[e,t]of l.entries())t.track=Math.max(0,...l.slice(0,e).filter(e=>i(e,t)||m7(t,e)>=1e3).map(e=>e.track+1)),s=Math.max(s,t.track+1);return s}(t,u.track)])),_=new Set;for(let[e,a]of t.entries()){let[t,l]=x[e];if(0===a.label||t.loop||"left"===t.side||"right"===t.side)continue;let[i,s]=[o.row[t.box],o.row[l.box]];if(t.side===l.side)_.add("top"===t.side?i-1:i);else for(let e=Math.min(i,s);e<Math.max(i,s);e+=1)_.add(e)}let q=e=>54*!!_.has(e),L=e=>100+q(e)+Math.max(0,(C.get(e)??0)-1)*u.track,S=[],B=C.has(-1)?L(-1):0;for(let e=0;e<b;e+=1)S.push(B),B+=k[e]+L(e);let A=(e,t)=>(e<0?0:S[e]+k[e])+50+q(e)+t*u.track,P=Math.min(...e.map((e,t)=>y(t))),V=new Map(e.map((e,t)=>[e.id,{x:Math.round(y(t)-P),y:S[o.row[t]],width:e.width,height:e.height}])),H=new Map;for(let[t,a]of M)for(let l of a)for(let a of l.ends){let i=V.get(e[a.box].id),s="bottom"===a.side?i.y+i.height:i.y;H.set(a,Math.abs(A(t,l.track)-s))}for(let e of f){if(!e.loop)continue;let a=f.filter(t=>t.loop&&t.box===e.box&&t.side===e.side&&t.slot<e.slot).reduce((e,a)=>Math.max(e,c(t[a.link])),0);H.set(e,Math.max(c(t[e.link]),a+u.track))}return{boxes:V,anchors:new Map(f.map(a=>{let l=e[a.box],i=m6(a.side)?l.width:l.height,s=H.get(a);return[`${t[a.link].id}:${a.end}`,{side:a.side,offset:a.at-i/2,...void 0===s?{}:{run:s}}]})),rows:new Map(e.map((e,t)=>[e.id,o.row[t]]))}}let m9={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"}},ve=e=>e.length>0?12+22*e.length:14;function vt(e,t){return[e["from"===t?"fromMultiplicity":"toMultiplicity"],e["from"===t?"fromRole":"toRole"]].flatMap(e=>e?[e.trim()]:[])}let va=e=>Math.ceil(iC(e,13))+2,vl="label-room:";function vi(e,t,a){let l=function(e,t){let a=new Map;for(let l of e.relationships)for(let e of["from","to"]){let i=t.anchors.get(`${l.id}:${"from"===e?"source":"target"}`),s=t.boxes.get(l[e].trim()),o=vt(l,e);if(!i||!s||0===o.length||"left"!==i.side&&"right"!==i.side)continue;let r=Math.max(...o.map(va))+8,n=s.y+s.height/2+i.offset,d="right"===i.side?s.x+s.width+2:s.x-2-r;for(let[t,i]of[["above",n-10+4-18],["below",n+10-4]])a.set(`${vl}${l.id}:${e}:${t}`,{x:d,y:i,width:r,height:18})}return a}(e,a);return mc({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:{}})),...[...l.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,...l]),anchors:a.anchors,endRun:50})}let vs=[{wholeBelow:1.5},{},{aspect:1.1},{between:1}],vo={aspect:1.1,hierarchies:!0};function vr(e){let t=e.elements.filter(e=>"arrow"===e.type);return{crossings:fY(t),findings:sL(t.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),sx({width:e.width,height:e.height})).length,detours:t.reduce((e,t)=>e+function(e){let[t,a]=[e.points[0],e.points.at(-1)],l=0;for(let[t,a]of e.points.slice(1).entries())l+=Math.abs(a.x-e.points[t].x)+Math.abs(a.y-e.points[t].y);return Math.max(0,l/(Math.abs(a.x-t.x)+Math.abs(a.y-t.y)+100+200)-1)}(t),0),hugging:function(e){let t=e.flatMap(e=>ss(e.points).map(t=>({arrow:e.id,segment:t}))),a=0;for(let[e,l]of t.entries())for(let i of t.slice(e+1))i.arrow!==l.arrow&&i.segment.orientation===l.segment.orientation&&10>Math.abs(i.segment.staticCoordinate-l.segment.staticCoordinate)&&Math.min(i.segment.max,l.segment.max)>Math.max(i.segment.min,l.segment.min)&&(a+=1);return a}(t)}}function vn(e,t){let a=Math.max(e.width/e.height,e.height/e.width);return t.crossings+t.findings+(a>2.5?4*(a-2.5):0)+t.detours+vc*t.hugging}function vd(e){let[t,a]=[e.width,e.height].map(e=>e-96+40);return Math.max(t/a,a/t)}let vc=3;function vp(e){return e.elements.filter(e=>"node"===e.type&&!e.nodeId.startsWith(vl))}function vh(e,t,a){return e.left<t.right+a&&t.left<e.right+a&&e.top<t.bottom+a&&t.top<e.bottom+a}function vg(e,t){return Math.hypot(Math.max(0,e.left-t.x,t.x-e.right),Math.max(0,e.top-t.y,t.y-e.bottom))}let vu=(e,t,a)=>({x:e.x+t,y:e.y+a}),vf=(e,t,a)=>({...e,x:e.x+t,y:e.y+a}),vm=(e,t,a)=>({x0:e.x0+t,x1:e.x1+t,y0:e.y0+a,y1:e.y1+a}),vv=e=>({x0:e.x,x1:e.x+e.width,y0:e.y,y1:e.y+e.height});function vy(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 l=t[a-1],i=t[a+1],s=.01>Math.abs(l.x-e.x)&&.01>Math.abs(e.x-i.x),o=.01>Math.abs(l.y-e.y)&&.01>Math.abs(e.y-i.y);return!s&&!o})}function vw(e){return e.slice(1).map((t,a)=>{let l=e[a];return{x0:Math.min(l.x,t.x)-1,x1:Math.max(l.x,t.x)+1,y0:Math.min(l.y,t.y)-1,y1:Math.max(l.y,t.y)+1}})}function vx(){return{boxes:[],cards:new Map,links:[],regions:[],rows:new Map,attach:0,tails:[],top:0}}function vb(e,t,a){e.cards.set(t,a),e.boxes.push(vv(a))}function vk(e,t,a,l){let i=vy(l);e.links.push({manager:t,report:a,points:i}),e.boxes.push(...vw(i))}function vM(e,t,a,l){for(let[i,s]of t.cards)e.cards.set(i,vf(s,a,l));for(let[i,s]of(e.boxes.push(...t.boxes.map(e=>vm(e,a,l))),e.links.push(...t.links.map(e=>({...e,points:e.points.map(e=>vu(e,a,l))}))),e.regions.push(...t.regions.map(e=>({...e,frame:vf(e.frame,a,l)}))),t.rows))e.rows.set(i,s)}function vz(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 vC=e=>0===e.reports.length&&0===e.assistants.length,v_=e=>0===e.assistants.length&&e.reports.length>0&&e.reports.every(vC),vq=e=>e.reports.length>=2&&e.reports.some(v_)&&e.reports.every(e=>vC(e)||v_(e))&&e.reports.every(e=>void 0===e.region);function vL(e,t,a=5){let l=vx(),i=void 0===t&&e.length>=a,s=0;e.forEach((a,o)=>{let r=t??(i&&o%2==0?-1:1),n=1===r?18:-18-a.width;vb(l,a.id,{x:n,y:s,width:a.width,height:a.height});let d=s+a.height/2;l.tails.push({report:a.id,points:[{x:0,y:d},{x:1===r?n:n+a.width,y:d}]}),i&&1!==r&&o!==e.length-1||(s+=a.height+14)});let o=Math.max(...l.tails.map(e=>e.points[0].y));return l.boxes.push({x0:-1,x1:1,y0:-28,y1:o}),l}function vS(e,t,a,l,i,s,o){for(let r of i)vk(e,t,r.report,[a,...l,...r.points.map(e=>vu(e,s,o))])}function vB(e,t,a){let l=0;for(let i=t;i<a;i+=1)l+=e[i];return l+24*Math.max(0,a-t-1)}function vA(e,t,a){let l={split:t,half:vB(e,t,a),imbalance:vB(e,t,a)};for(let i=t+1;i<a;i+=1){let s=vB(e,t,i),o=vB(e,i,a),r=Math.max(s,o),n=Math.abs(s-o);(r<l.half-1e-9||r<l.half+1e-9&&n<l.imbalance-1e-9)&&(l={split:i,half:r,imbalance:n})}return l}function vP(e,t=[]){let a=[];for(let l of e){let e=sp(t,l.block.boxes,24,8),i=Number.isFinite(e)?e:0===a.length?0:-1/0,s=Number.isFinite(i)?i:Math.max(...t.map(e=>e.x1))+24-vz(l.block.boxes).x0;a.push(s),t.push(...l.block.boxes.map(e=>vm(e,s,0)))}return a}function vV(e){let t=vz(e.boxes);return t.x1-t.x0}function vH(e,t){let a=e.map(e=>(function e(t,a,l,i){let s=vx(),{width:o,height:r}=t;vb(s,t.id,{x:-o/2,y:0,width:o,height:r}),s.tails.push({report:t.id,points:[{x:0,y:0}]});let n={x:0,y:r},d=t.reports.length>0&&t.reports.every(vC)&&(void 0!==i||t.reports.length>=a.stackMin&&t.reports.length<=20),c=d&&(void 0!==i||t.reports.length<a.twoColumns),p=r,h=vq(t)?a.outline.get(t.id):void 0,g=c||1===h||2===h&&t.reports.length<3;if(t.assistants.forEach((e,a)=>{let l=g||a%2==0?1:-1,i=r+16+(g?a:Math.floor(a/2))*(e.height+14),o=1===l?22:-22-e.width;vb(s,e.id,{x:o,y:i,width:e.width,height:e.height});let d=i+e.height/2;vk(s,t.id,e.id,[n,{x:0,y:d},{x:1===l?o:o+e.width,y:d}]),p=Math.max(p,i+e.height)}),0===t.reports.length)return s;let u=l||void 0!==t.region;if(d){let e=i??1,l=vL(t.reports,c?e:void 0,a.twoColumns),n=c?e*(-o/2+20):0,d=p+18;return vM(s,{...l,links:[],regions:[],rows:new Map,tails:[]},n,d),vS(s,t.id,{x:n,y:r},[],l.tails,n,d),s}if(void 0!==h){let l=2===h&&t.reports.length>=3,i=l?0:-o/2+20,n=new Map([[1,p+18],[-1,p+18]]);return t.reports.forEach((o,d)=>{let c=l&&d%2==0?-1:1,p=n.get(c),h=e(o,a,u,c),g=i+c*(18+o.width/2);vM(s,h,g,p);let f=p+o.height/2;vk(s,t.id,o.id,[{x:i,y:r},{x:i,y:f},{x:g-c*o.width/2,y:f}]),n.set(c,p+vz(h.boxes).y1+14)}),s}let f=t.reports.filter(vC),m=f.length>=a.stackMin,v=Math.ceil(f.length/20),y=[];for(let l of t.reports){if(m&&vC(l)){if(l===f[0])for(let e=0;e<v;e+=1){let t=vL(f.slice(Math.round(e*f.length/v),Math.round((e+1)*f.length/v)),void 0,a.twoColumns);y.push({block:t,width:vV(t)})}continue}let t=e(l,a,u),i=u?t:function(e,t){if(!t.region)return e;let a=vz(e.boxes),l={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=l.y0-21-4;return{...e,boxes:[{...l,x0:l.x0-10,x1:l.x1+10,y0:i}],regions:[...e.regions,{root:t.id,label:t.region.label,frame:{x:l.x0,y:l.y0,width:l.x1-l.x0,height:l.y1-l.y0},members:[...e.cards.keys()]}],top:i}}(t,l);y.push({block:i,width:vV(i),root:l.id})}let w=Math.max(1,Math.min(a.rows.get(t.id)??1,y.length)),x=function(e,t,a){let l,i=e.length,s=(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 l=e;l<=i-(a-e);l+=1)for(let a=e-1;a<l;a+=1){let i=o[e-1][a];if(!i)continue;let r=vA(t,a,l),n={half:Math.max(i.half,r.half),imbalance:i.imbalance+r.imbalance,cut:a};s(n,o[e][l])&&(o[e][l]=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,vB(t,e,i)/2),imbalance:r.imbalance,cut:e};s(n,l)&&(l=n)}let r=[e.slice(l.cut)],n=l.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 l;if(a===x.length-1){l=vP(e);let t=e.map((e,t)=>l[t]+e.block.attach),a=(Math.min(...t)+Math.max(...t))/2;l=l.map(e=>e-a)}else{let{split:t}=vA(e.map(e=>e.width),0,e.length),a={x0:-1,x1:1,y0:-1e6,y1:1e6};l=[...function(e,t){let a=Array.from({length:e.length},()=>0);for(let l=e.length-1;l>=0;l-=1){let i=e[l],s=function(e,t,a=0){let l=1/0;for(let i of t)for(let t of e)i.y0<t.y1+a&&t.y0<i.y1+a&&(l=Math.min(l,t.x0-24-i.x1));return l}(t,i.block.boxes,8),o=Number.isFinite(s)?s:Math.min(...t.map(e=>e.x0))-24-vz(i.block.boxes).x1;a[l]=o,t.push(...i.block.boxes.map(e=>vm(e,o,0)))}return a}(e.slice(0,t),[a]),...vP(e.slice(t),[a])]}let i=Math.max(0,...e.map(e=>-e.block.top)),o=b+28,r=b+56+i,d=[];e.forEach((e,a)=>{let i=l[a];vM(s,e.block,i,r),vS(s,t.id,n,[{x:0,y:o},{x:i+e.block.attach,y:o}],e.block.tails,i,r),d.push(...e.block.boxes.map(e=>vm(e,i,r)))});let c=vz(d);k=Math.max(k,c.x1-c.x0),b=c.y1});let M=y.reduce((e,t)=>t.width>e.width?t:e);return s.rows.set(t.id,{width:k,widestItem:M.width,widest:M.root,items:y.length,rows:x.length}),s})(e,t,!1)),l=vx(),i=[];for(let e of a){let t=sp(i,e.boxes,64,8),a=Number.isFinite(t)?t:0;vM(l,e,a,0),i.push(...e.boxes.map(e=>vm(e,a,0)))}let s=vz(vI(l)),o=vx();return vM(o,l,-s.x0,-s.y0),o}function vI(e){return[...[...e.cards.values()].map(vv),...e.links.flatMap(e=>vw(e.points)),...e.regions.map(e=>({...vv(e.frame),y0:e.frame.y-21-4}))]}function v$(e){let t,a,l;return Math.max(1,Math.max((l=((a=vz(vI(e))).x1-a.x0+40)/(a.y1-a.y0+40))/2.4,.45/l))*Math.max(1,((t=vz(vI(e))).x1-t.x0+80)*(t.y1-t.y0+80+64)/56e5)}let vF="#6250d6",vO=[14,22,30],vE=[8,18,26,36];function vU(e,t,a){let l=(e,t)=>Number.parseInt(e.slice(t,t+2),16);return`#${[1,3,5].map(i=>Math.round(l(t,i)+(l(e,i)-l(t,i))*a).toString(16).padStart(2,"0")).join("")}`}function vX(e,t,a){let l=e=>e.split("\n").length,i=iS(e,t,a);if(1===l(i))return i;let s=a,o=t;for(;o-s>1;){let t=Math.floor((s+o)/2);l(iS(e,t,a))<=l(i)?o=t:s=t}return iS(e,o,a)}let vT=e=>void 0===e?0:e.split("\n").length,vR=(e,t)=>Math.ceil(vT(e)*t*1.25),vY=(e,t=0)=>({left:e.x-t,top:e.y-t,right:e.x+e.width+t,bottom:e.y+e.height+t});function vD(e,t,a){let{x:l,y:i,width:s,height:o}=e;return[{x:l+s,y:i+o/2,outward:0,cost:0},{x:l,y:i+o/2,outward:2,cost:0},{x:l+s,y:i+o/4,outward:0,cost:4},{x:l,y:i+o/4,outward:2,cost:4},{x:l+3*s/4,y:i+o,outward:1,cost:6},{x:l+s/4,y:i+o,outward:1,cost:6},{x:l+3*s/4,y:i,outward:3,cost:6},{x:l+s/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 vG(e,t){let a=0;for(let l of h_(e)){let e=.01>Math.abs(l.to.y-l.from.y);for(let i of t){if(e===.01>Math.abs(i.to.y-i.from.y))continue;let[t,s]=e?[l,i]:[i,l],o=s.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(s.from.y,s.to.y)+.5&&r<Math.max(s.from.y,s.to.y)-.5&&(a+=1)}}return a}function vZ(e,t){let a=h_(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*vG(e,t)}let vj=(e,t,a)=>e.left<t.right+a&&t.left<e.right+a&&e.top<t.bottom+a&&t.top<e.bottom+a;function vN(e,t,a,l){return vj({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,l)}function vW(e,t,a,l,i,s){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=>h_(e.points)),n=[...t.values()].flatMap(e=>[e.y,e.y+e.height]),d=e=>[...t.values()].flatMap(t=>e.flatMap(e=>[t.y-e,t.y+t.height+e])),c=[...t.values()],p=c.flatMap(e=>{let t=c.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=>sT(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=[...d(vO),...p,...f],v=[...d([...vO,...vE]),...p,...f],y=g-60-10*e.dottedLines.length,w=u+60,x={left:Math.min(...c.map(e=>e.x),...a.map(e=>e.x))-60,right:Math.max(...c.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=[],z=[],C=0,_=0,q=a.flatMap(e=>h_([{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}])),L=(e,t)=>{let a,l=h_(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,...h_(t)],s=iC(e,13),o=[1,2,3].map(t=>{let a=1===t?e:vX(e,Math.ceil(s/t)+13,13),l=iq(a,13,Math.ceil(iC(a,13)));return{text:a,width:l,height:Math.ceil(13*vT(a)*1.35)}}).flatMap(({text:e,width:t,height:a},s)=>l.flatMap(l=>{let o=.01>Math.abs(l.to.y-l.from.y);return[.5,.3,.7,.15,.85].flatMap(r=>{let n={x:l.from.x+(l.to.x-l.from.x)*r,y:l.from.y+(l.to.y-l.from.y)*r};return[6,14,30,50,80].flatMap(l=>(o?[-1,1].map(e=>({left:n.x-t/2,right:n.x+t/2,top:e<0?n.y-l-a:n.y+l,bottom:e<0?n.y-l:n.y+l+a})):[1,-1].map(e=>({left:e>0?n.x+l:n.x-l-t,right:e>0?n.x+l+t:n.x-l,top:n.y-a/2,bottom:n.y+a/2}))).map(a=>({text:e,width:t,rect:a,offset:l,form:s,score:100*c.filter(e=>vj(a,vY(e),4)).length+100*h.filter(e=>vj(a,vY(e),2)).length+10*q.filter(e=>vN(e.from,e.to,a,3)).length+10*z.filter(e=>vj(a,e,4)).length+i.filter(e=>vN(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,c.some(e=>vj(a,vY(e),0))||h.some(e=>vj(a,vY(e),0)))}},S=(e,t,a)=>{let l=Math.min(g,...z.map(e=>e.top),...[...r,...h_(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:l-i,bottom:l},covers:!1}};for(let[i,n]of e.dottedLines.entries()){let d=t.get(n.report),c=t.get(n.manager),u=new Set([l.get(n.report),l.get(n.manager)]),q=l.get(n.report)===l.get(n.manager)?l.get(n.report):void 0,B=(e,l)=>[...[...t].map(([t,a])=>({box:vY(a),clearance:e,...t===n.report||t===n.manager?{own:!0}:{}})),...h.map(e=>({box:vY(e),clearance:2})),...a.filter(e=>!u.has(e.id)).map(t=>({box:vY(t),clearance:Math.min(e,8)})),...a.filter(e=>l||q===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:vY(t),clearance:8,...q===e.id?{}:{parallel:!0}})))],A=vD(d,o.get(n.report)??[],!1),P=vD(c,o.get(n.manager)??[],!0),V=[d,c],H=[...f,...m.filter(e=>V.some(t=>e>t.y-120&&e<t.y+t.height+120))],I=(e,t,a={sources:A,targets:P},l=!1)=>t.flatMap(t=>{let i={remaining:Math.min(b.remaining,12e3)},s=hz({...a,obstacles:e,...t,routed:r,top:y,bottom:w,reach:x,...l?{wide:!0,crossingCost:500,backCrossingFactor:1}:{},budget:i});return b.remaining-=Math.min(b.remaining,12e3)-i.remaining,s?[vy(s)]:[]}).reduce((e,t)=>!e||vZ(t,r)<vZ(e,r)?t:e,void 0),$=I(B(6,!0),[{lanes:[...p,...f],denseLanes:m},{lanes:m,denseLanes:v}])??I(B(6,!0),[{lanes:H,denseLanes:H}])??I(B(3,!1),[{lanes:v,denseLanes:v}]),F=e.dottedLines.length-1-i,O=s&&$&&vG($,r)>0&&b.remaining>=12e3+48e3*F?I(B(6,!0),[{lanes:[...p,...f],denseLanes:m}],void 0,!0):void 0,E=O&&$&&vZ(O,r)<vZ($,r)?O:$,U=()=>{let e=Math.min(g-24-10*C,...r.flatMap(e=>[e.from.y-10,e.to.y-10])),t=(t,a)=>[0,-1,1,-2,2,-4,4].map(l=>({x:t.x+t.width/2+48*l,y:e,direction:a,cost:8*Math.abs(l)})),a=[{lanes:[...H,e],denseLanes:[...H,e]}],l=I(B(6,!0),a,{sources:A,targets:t(d,3)}),i=l&&I(B(6,!0),a,{sources:t(c,1),targets:P});return l&&i?vy([...l,...i]):void 0},X=E?void 0:U();X&&(C+=1),E||X||(_+=1);let T=vy(E??X??function(e,t){let a=e=>({x:e.x+e.width/2,y:e.y+e.height/2}),[l,i]=[a(e),a(t)],s=(e,t,a)=>{let l=t.x-a.x,i=t.y-a.y,s=Math.min(0===l?1/0:e.width/2/Math.abs(l),0===i?1/0:e.height/2/Math.abs(i));return{x:a.x+l*s,y:a.y+i*s}};return[s(e,i,l),s(t,l,i)]}(d,c)).map(({x:e,y:t})=>({x:e,y:t})),R=n.label?.trim(),Y=void 0===R?void 0:L(R,T);if(void 0!==R&&Y?.covers&&!X&&b.remaining>=12e3+48e3*F){let e=U(),t=e&&L(R,e);e&&t&&!t.covers&&(C+=1,T=e.map(({x:e,y:t})=>({x:e,y:t})),Y=t)}Y?.covers&&(Y=S(Y,T[0].x,T)),r.push(...h_(T)),o.set(n.report,[...o.get(n.report)??[],T[0]]),o.set(n.manager,[...o.get(n.manager)??[],T.at(-1)]),k.push({type:"arrow",id:`edge:dotted:${n.id}`,edgeId:`dotted:${n.id}`,sourceNodeId:n.report,targetNodeId:n.manager,points:T,startArrowhead:null,endArrowhead:"arrow",strokeColor:vF,strokeStyle:"dashed",strokeWidth:2,roughness:0}),void 0!==Y&&(z.push(Y.rect),M.push({type:"text",id:`text:dotted:${n.id}`,x:(Y.rect.left+Y.rect.right)/2,y:(Y.rect.top+Y.rect.bottom)/2,text:Y.text,fontSize:13,lineHeight:1.25,maxWidth:Y.width,textColor:vF}))}return{arrows:k,labels:M,straight:_}}let vJ={2:110,3:120},vK=[1,.9,1.1,.8,1.2,.7,1.3,.6,1.4],vQ=[1/0,220,170,130,100,75];function v1(e,t,a){let l=1.35*t;return e.split("\n").map((e,i)=>({text:e,fontSize:t,width:Math.ceil(iC(e,t)),height:l,top:a+i*l}))}function v0(e,t,a){let l=!0;return{text:e.trim().split(/\s*\n\s*/u).map(e=>{if(!Number.isFinite(t))return e;let i=iS(e,t,a);return!function(e,t){let a=e.trim(),l=t.split("\n"),i=0;for(let[e,t]of l.entries()){if(!a.startsWith(t,i))return!1;if(i+=t.length,e===l.length-1)break;if(" "===a[i]){for(;" "===a[i];)i+=1;continue}if(!v2.test(t.at(-1)??"")&&!v2.test(l[e+1]?.[0]??""))return!1}return i===a.length}(e,i)&&(l=!1),i}).join("\n"),whole:l}}let v2=/[\u1100-\u11ff\u2e80-\u9fff\uac00-\ud7af\uf900-\ufaff\uff00-\uffef]/u;function v3(e,t,a){return(function(e,t){if(2===e)return[{x:-t/2,y:0},{x:t/2,y:0}];let a=t*Math.sqrt(3)/2;return[{x:-t/2,y:-a/3},{x:t/2,y:-a/3},{x:0,y:2*a/3}]})(e,t).map(e=>({x:e.x*a,y:e.y*a,r:a}))}function v5(e,t,a){let l=1/0;return t.forEach((t,i)=>{let s,o,r=a.includes(i)?(s=Math.max(Math.abs(e.left-t.x),Math.abs(e.right-t.x)),o=Math.max(Math.abs(e.top-t.y),Math.abs(e.bottom-t.y)),t.r-Math.hypot(s,o)):Math.hypot(Math.max(e.left-t.x,0,t.x-e.right),Math.max(e.top-t.y,0,t.y-e.bottom))-t.r;r<l&&(l=r)}),l}let v4=[[1,0],[-1,0],[0,-1],[0,1],[Math.SQRT1_2,Math.SQRT1_2],[-Math.SQRT1_2,Math.SQRT1_2],[Math.SQRT1_2,-Math.SQRT1_2],[-Math.SQRT1_2,-Math.SQRT1_2]];function v6(e,t,a,l){let i=e,s=a(i),o=t;for(let e=0;o>=.5&&e<400;e+=1){let e;for(let[t,r]of v4){let n={x:i.x+t*o,y:i.y+r*o},d=a(n);l.work+=1,d>s+1e-9&&(s=d,e=n)}e?i=e:o/=2}return{point:i,clearance:s}}function v7(e,t,a){let l=t.map(t=>e[t]),i=e.filter((e,a)=>!t.includes(a)),s=e=>({x:e.reduce((e,t)=>e+t.x,0)/e.length,y:e.reduce((e,t)=>e+t.y,0)/e.length}),o=s(l),r=o;if(i.length){let e=s(i),t=o.x-e.x,a=o.y-e.y,n=Math.hypot(t,a)||1;r={x:o.x+t/n*l[0].r*.4,y:o.y+a/n*l[0].r*.4}}return v6(r,e[0].r/4,a=>v5({left:a.x,right:a.x,top:a.y,bottom:a.y},e,t),a).point}function v8(e,t,a,l,i,s=!1){let o=l=>{let i=1/0;for(let s of e.lines){let o=v5(function(e,t,a){let l=t.y-a/2+e.top;return{left:t.x-e.width/2,right:t.x+e.width/2,top:l,bottom:l+e.height}}(s,l,e.height),t,a);o<i&&(i=o)}return i},r=t[0].r,{point:n,clearance:d}=v6(l,r/4,o,i);if(!s||d<10)return{center:n,clearance:d};let c=function(e,t,a,l,i){let s=e,o=(e,o)=>{let r=0,n=a;for(let d=2;d<=a;d+=2){if(i.work+=1,l({x:s.x+e*d,y:s.y+o*d})<t){n=d;break}r=d}for(;n-r>.25;){let a=(r+n)/2;i.work+=1,l({x:s.x+e*a,y:s.y+o*a})>=t?r=a:n=a}return r};for(let e=0;e<3;e+=1){let e=(o(1,0)-o(-1,0))/2;s={x:s.x+e,y:s.y};let t=(o(0,1)-o(0,-1))/2;s={x:s.x,y:s.y+t}}return s}(n,Math.max(10,d-Math.max(2,(d-10)/6)),2*r,o,i);return{center:c,clearance:o(c)}}let v9=v.ink;function ye(e){let t=Number.parseInt(e.slice(1),16);return[t>>16&255,t>>8&255,255&t]}function yt(e){return`#${e.map(e=>Math.round(e).toString(16).padStart(2,"0")).join("")}`}function ya(e,t,a){return[e[0]+(t[0]-e[0])*a,e[1]+(t[1]-e[1])*a,e[2]+(t[2]-e[2])*a]}function yl(e){let[t,a,l]=e.map(e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4});return .2126*t+.7152*a+.0722*l}function yi(e,t){let a=yl(ye(e)),l=yl(ye(t));return(Math.max(a,l)+.05)/(Math.min(a,l)+.05)}function ys(e){return Math.round(100*e)/100}function yo(e,t,a,l,i,s,o){e.elements.push({type:"text",id:t,x:ys((i.left+i.right)/2),y:ys((i.top+i.bottom)/2),text:a,fontSize:l,maxWidth:Math.ceil(i.right-i.left),textAlign:"center",textColor:s,groupIds:o}),e.front.push(t)}function yr(e,t,a,l){return{type:"node",id:`node:${e}`,nodeId:e,rendererRole:"venn-set",shape:"ellipse",x:ys(t.x-t.r),y:ys(t.y-t.r),width:ys(2*t.r),height:ys(2*t.r),label:a,...l}}let yn="journey-mark",yd=v.ink,yc="#4c4639",yp="#5f574c",yh="#4c4639",yg=[pT["0"],pT["6"],pT["4"]],yu=["#e34948","#eb6834","#a39a8a","#1baf7a","#008300"],yf=[34,40,46],ym=35,yv=e=>ym+20+4*e,yy=e=>e.split("\n").length,yw=(e,t)=>Math.ceil(yy(e)*t*1.25),yx=(e,t)=>Math.ceil(yy(e)*t*1.35)+18,yb=new Map,yk=iz(" ");function yM(e){let t=yb.get(e);if(void 0!==t)return t;let a=iz(e);return yb.set(e,a),a}function yz(e,t,a){let l=Math.floor(100*t/a+1e-6),i=e.split(" "),s=i.map(yM);if(e.includes("\n")||/(^| )\p{M}/u.test(e)||i.some((e,t)=>s[t]>l&&(s[t]>1488||!/^[\u0021-\u007e\u00a1-\u024f]+$/u.test(e))))return iS(e,t,a);if(s.reduce((e,t)=>e+t,(i.length-1)*yk)<=l)return e;let o=[],r="",n=0;return i.forEach((e,t)=>{if(s[t]>l){r&&o.push(r),o.push(e),r="",n=0;return}let a=r?n+yk+s[t]:s[t];if(a<=l){r=r?`${r} ${e}`:e,n=a;return}o.push(r),r=e,n=s[t]}),r&&o.push(r),o.join("\n")}let yC=new Map;function y_(e,t,a){let l=`${a}|${t}|${e}`,i=yC.get(l);if(i)return i;let s=function(e,t,a){let l=yz(e,t,a);if(1===yy(l))return l;let i=Math.max(...e.split(" ").map(e=>yM(e)*a/100)),s=Math.max(a,Math.min(t,Math.floor(i))-1),o=t;for(;o-s>1;){let t=Math.floor((s+o)/2);yy(yz(e,t,a))<=yy(l)?o=t:s=t}return yz(e,o,a)}(e.trim(),t,a),o={text:s,width:Math.ceil(iC(s,a)),height:yw(s,a)};return yC.set(l,o),o}function yq(e,t,a){let l=(e,t)=>Number.parseInt(e.slice(t,t+2),16);return`#${[1,3,5].map(i=>Math.round(l(t,i)+(l(e,i)-l(t,i))*a).toString(16).padStart(2,"0")).join("")}`}let yL=e=>Math.round(100*e)/100;function yS(e,t){let a=t-24;return e.stages.map(e=>e.steps.map(e=>({label:y_(e.label,a,15),details:function(e,t){let a=[e.actor,e.touchpoint].map(e=>e?.trim()).filter(e=>void 0!==e&&e.length>0);if(0===a.length)return;let l=y_(a.join(" · "),t,13);if(1===a.length||1===yy(l.text))return l;let i=a.map(e=>y_(e,t,13).text).join("\n");return{text:i,width:Math.ceil(iC(i,13)),height:yw(i,13)}}(e,a)})))}let yB=(e,t)=>0===t.from?e.stages[t.stage].name.trim():`${e.stages[t.stage].name.trim()} (continued)`;function yA(e,t){return(e??[]).map(e=>{let a=y_(e,t-24,13);return{...a,height:yx(a.text,13)}})}let yP=e=>e.reduce((e,t)=>e+t.height,0)+8*Math.max(0,e.length-1),yV=e=>(e.width-80)/(e.height-80),yH=e=>e.elements<=iB.maxElements&&e.width*(e.height+64)<=6291456&&2.45>=yV(e),yI=e=>[Math.max(0,e.elements-iB.maxElements),Math.max(0,e.width*(e.height+64)-6291456)/6291456+Math.max(0,yV(e)-2.45)/2.45+Math.max(0,.8-yV(e))/.8];function y$(e,t,a,l,i,s,o={}){return{type:"text",id:e,x:yL(a),y:yL(l),text:t.text,fontSize:i,lineHeight:1.25,maxWidth:t.width,textColor:s,...o}}let yF=["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#6250d6","#e34948"],yO=[26,40,56,76,100,130,170,220,300];function yE(e,t,a){let l=iS(e,a,t),i=l.split("\n");return{text:l,width:Math.ceil(Math.max(...i.map(e=>iC(e,t)))),height:Math.ceil(i.length*t*1.35)}}function yU(e){return Math.round(100*e)/100}function yX(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 yT(e,t,a){let l=0,i=1,s=t.x-e.x,o=t.y-e.y;for(let[t,r]of[[-s,e.x-a.left],[s,a.right-e.x],[-o,e.y-a.top],[o,a.bottom-e.y]]){if(1e-9>Math.abs(t)){if(r<=0)return!1;continue}let e=r/t;if(t<0?l=Math.max(l,e):i=Math.min(i,e),l>=i)return!1}return i-l>1e-6}function yR(e,t,a,l){let i=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),s=i(a,l,e),o=i(a,l,t),r=i(e,t,a),n=i(e,t,l);return(s>0&&o<0||s<0&&o>0)&&(r>0&&n<0||r<0&&n>0)}function yY(e,t){let a=!1;for(let l=0,i=t.length-1;l<t.length;i=l,l+=1){let s=t[l],o=t[i];s.y>e.y!=o.y>e.y&&e.x<(o.x-s.x)*(e.y-s.y)/(o.y-s.y)+s.x&&(a=!a)}return a}function yD(e,t,a=yG(t)){if(!yX(e,a))return!1;let l={left:e.left+.01,top:e.top+.01,right:e.right-.01,bottom:e.bottom-.01};if(l.left>=l.right||l.top>=l.bottom)return!1;let i=[{x:l.left,y:l.top},{x:l.right,y:l.top},{x:l.right,y:l.bottom},{x:l.left,y:l.bottom}];if(i.some(e=>yY(e,t)))return!0;for(let e=0;e<t.length;e+=1){let a=t[e],s=t[(e+1)%t.length];if(a.x>l.left&&a.x<l.right&&a.y>l.top&&a.y<l.bottom)return!0;if(!(Math.max(a.x,s.x)<=l.left||Math.min(a.x,s.x)>=l.right)&&!(Math.max(a.y,s.y)<=l.top||Math.min(a.y,s.y)>=l.bottom)){for(let e=0;e<4;e+=1)if(yR(a,s,i[e],i[(e+1)%4]))return!0}}return!1}function yG(e){let t=1/0,a=1/0,l=-1/0,i=-1/0;for(let s of e)t=Math.min(t,s.x),l=Math.max(l,s.x),a=Math.min(a,s.y),i=Math.max(i,s.y);return{left:t,top:a,right:l,bottom:i}}function yZ(e,t,a,l,i){let s=(e+a)/2,o=1-i;return{x:o*o*o*e+3*o*o*i*s+3*o*i*i*s+i*i*i*a,y:t+(l-t)*(3*i*i-2*i*i*i)}}let yj="sankey-mark",yN=v.ink,yW=e=>`sankey:node:${e}`,yJ=(e,t)=>`sankey:link:${e}:${t}`;function yK(e){return Math.round(100*e)/100}function yQ(e,t,a){let{box:l}=t;return{type:"text",id:e,x:yK((l.left+l.right)/2),y:yK((l.top+l.bottom)/2),text:t.text,fontSize:t.fontSize,lineHeight:1.35,maxWidth:t.width,textAlign:t.align,textColor:yN,groupIds:a}}let y1=[{dx:1,dy:0},{dx:0,dy:1},{dx:-1,dy:0},{dx:0,dy:-1}];class y0{items=[];get size(){return this.items.length}push(e,t){let a=this.items;a.push({cost:e,state:t});let l=a.length-1;for(;l>0;){let e=l-1>>1;if(a[e].cost<=a[l].cost)break;[a[e],a[l]]=[a[l],a[e]],l=e}}pop(){let e=this.items,t=e[0],a=e.pop();if(e.length>0){e[0]=a;let t=0;for(;;){let a=2*t+1,l=a+1,i=t;if(a<e.length&&e[a].cost<e[i].cost&&(i=a),l<e.length&&e[l].cost<e[i].cost&&(i=l),i===t)break;[e[i],e[t]]=[e[t],e[i]],t=i}}return t}}let y2=(e,t)=>t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height,y3=e=>Math.round(100*e)/100;function y5(e,t,a){let l=[...new Set(e.map(y3))].filter(e=>e>=t&&e<=a).toSorted((e,t)=>e-t),i=[];for(let[e,t]of l.entries()){let a=l[e-1];if(void 0!==a){let e=t-a,l=Math.max(2,Math.ceil(e/96));for(let t=1;t<l;t+=1)i.push(y3(a+e*t/l))}i.push(t)}return i}let y4={desktop:{width:1280,minHeight:800,pad:32,gap:24,rowGap:16,gridGap:24,barGap:24,barHeight:64,control:40,touch:24,sidebar:240,modal:480,headings:[28,22,18]},tablet:{width:768,minHeight:1024,pad:24,gap:16,rowGap:12,gridGap:16,barGap:16,barHeight:56,control:40,touch:32,sidebar:200,modal:440,headings:[26,20,18]},mobile:{width:390,minHeight:844,pad:16,gap:16,rowGap:12,gridGap:12,barGap:12,barHeight:56,control:44,touch:44,sidebar:0,modal:358,headings:[24,20,17]}},y6=v.ink,y7="#495057",y8="#868e96",y9="#495057",we="#adb5bd",wt="#ced4da",wa="#f1f3f5",wl="#e9ecef",wi="#ffffff",ws="#1971c2",wo="#e7f5ff",wr="#343a40",wn="wireframe-widget",wd="wireframe-region";function wc(e,t,a){let l=("start"===a||"between"===a)&&e.grow;return Math.max(e.min,l?Math.min(t,e.max??t):Math.min(t,e.pref))}let wp=(e,t)=>Math.ceil(e*t*1.25);function wh(e,t,a){let l=iS(e,Math.max(1,Math.floor(t)),a),i=l.split("\n").length;return{text:l,width:Math.ceil(iC(l,a)),height:wp(i,a),lines:i}}function wg(e,t){return e?Math.ceil(Math.max(0,...e.split(/\s+/u).map(e=>iC(e,t)))):0}let wu=(e,t)=>e?Math.ceil(iC(e,t)):0;function wf(e,t,a,l,i,s,o){return{type:"text",id:e,x:"left"===i?l.x+t.width/2:l.x+l.width/2,y:l.y+t.height/2,text:t.text,fontSize:a,lineHeight:1.25,maxWidth:t.width,textAlign:i,textColor:s,...o}}function wm(e,t,a,l,i,s,o){return{type:"node",id:e,nodeId:e,kind:`wireframe:${t}`,shape:i.shape??"rectangle",rendererRole:l,x:a.x,y:a.y,width:a.width,height:a.height,label:s,fillColor:i.fill,fillStyle:"solid",strokeColor:i.stroke,strokeWidth:i.strokeWidth??1,...o}}function wv(e,t,a,l,i){return{type:"line",id:e,points:t.map(e=>({x:Math.round(100*e.x)/100,y:Math.round(100*e.y)/100})),strokeColor:a,strokeWidth:l,...i}}function wy(e,t,a,l,i,s,o){return{type:"text",id:e,containerId:t.id,x:t.x+t.width/2,y:t.y+t.height/2,text:a,fontSize:l,lineHeight:1.25,maxWidth:Math.max(1,Math.floor(i)),textColor:s,...o}}let ww=new Set(["header","footer","sidebar","section","card","modal"]);function wx(e,t){let a=e.level??t.headingLevel;return t.device.headings[a-1]}function wb(e,t,a,l){let i=t;for(;i>l&&wg(e,i)>a;)i-=1;return i}function wk(e,t){let a=e.type,l="header"===a||"footer"===a||"sidebar"===a?3:"card"===a||"modal"===a||"section"===a?2:t.headingLevel,i=e.align??("header"===a||"footer"===a?"between":"start");return{...t,inSidebar:t.inSidebar||"sidebar"===a,headingLevel:Math.max(t.headingLevel,l),textAlign:"row"===a||"header"===a||"footer"===a||"grid"===a?"left":"center"===i?"center":"left"}}let wM=new Set(["row","header","footer"]);function wz(e,t){return"main"===e?t.device.headings[0]:"section"===e||"modal"===e||"sidebar"===e||"header"===e?t.device.headings[2]:15}function wC(e,t){return"card"===e?{x:16,y:16}:"modal"===e?{x:24,y:24}:"sidebar"===e?{x:16,y:16}:"header"===e||"footer"===e?{x:t.device.pad,y:12}:{x:0,y:0}}function w_(e,t){return"header"===e||"footer"===e?t.device.barGap:"row"===e?t.device.rowGap:"grid"===e?t.device.gridGap:"main"===e?t.device.gap:12}function wq(e,t){let{device:a}=t,l=a.touch;switch(e.type){case"heading":{let a=wx(e,t);return{min:wg(e.text,Math.min(a,16)),pref:wu(e.text,a),grow:!0}}case"text":return e.text?{min:wg(e.text,14),pref:Math.min(640,wu(e.text,14)),grow:!0}:{min:80,pref:320,grow:!0};case"link":return{min:wg(e.text,14),pref:wu(e.text,14),grow:!1};case"badge":return{min:wg(e.text,12)+16,pref:wu(e.text,12)+16,grow:!1};case"button":return{min:Math.max(48,wg(e.text,14)+32),pref:Math.max(80,wu(e.text,14)+32),grow:!1};case"input":case"textarea":case"select":case"search":{let t=e.value??e.placeholder??("search"===e.type?"Search":""),a=36*("select"===e.type||"search"===e.type),l=Math.max("search"===e.type?140:120,wg(e.label,13),wg(t,14)+24+a),i=Math.max(l,"search"===e.type?280:320,Math.min(480,wu(t,14)+24+a));return{min:l,pref:i,grow:!0}}case"checkbox":case"radio":return{min:26+wg(e.label,14),pref:26+wu(e.label,14),grow:!1};case"toggle":return{min:wg(e.label,14)+16+36,pref:wu(e.label,14)+16+36,grow:!0,max:640};case"tabs":{let t=e.items??[],a=t.map(e=>wu(e,14)+24);return{min:Math.max(0,...t.map(e=>wg(e,14)+24)),pref:a.reduce((e,t)=>e+t,0)+4*Math.max(0,a.length-1),grow:!0}}case"nav":{let a=e.items??[],l=a.map(e=>wu(e,14)+24),i=Math.max(0,...a.map(e=>wg(e,14)+24));return t.inSidebar?{min:i,pref:Math.max(0,...l),grow:!0}:{min:i,pref:l.reduce((e,t)=>e+t,0)+4*Math.max(0,l.length-1),grow:!1}}case"breadcrumbs":{let t=wL(e);return{min:wg(t,13),pref:wu(t,13),grow:!1}}case"avatar":{let e=t.mobile?Math.max(40,l):40;return{min:e,pref:e,grow:!1}}case"icon":{let a=Math.max(22,t.mobile?l:22);return{min:a+(e.label?8+wg(e.label,14):0),pref:a+(e.label?8+wu(e.label,14):0),grow:!1}}case"image":return{min:Math.max(48,wg(e.label,13)+24),pref:320,grow:!0};case"chart":return{min:Math.max(160,wg(e.label,13)+24),pref:360,grow:!0};case"table":{let t=wS(e),a=Math.max(...t.map(e=>wg(e,13)))+36+48;return{min:a,pref:Math.max(a,t.reduce((e,t)=>e+wu(t,13)+24+32,0)),grow:!0}}case"list":{let t=e.items??[];return{min:18+Math.max(0,...t.map(e=>wg(e,14))),pref:18+Math.max(0,...t.map(e=>wu(e,14))),grow:!0}}case"divider":return{min:1,pref:1,grow:!0};default:return function(e,t){let a=e.type,l=wk(e,t),i=wC(a,t),s=w_(a,t),o=(e.children??[]).map(e=>wq(e,l)),r=wz(a,t),n=e.title,d=wg(n,Math.min(r,13))+32*("modal"===a),c=wu(n,r),p=Math.max(0,d,...o.map(e=>e.min));if("sidebar"===a&&!t.mobile){let e=Math.max(t.device.sidebar,p+2*i.x);return{min:e,pref:e,grow:!1}}if("modal"===a){let e=p+2*i.x;return{min:e,pref:Math.max(e,Math.min(t.device.modal,t.device.width-2*t.device.pad)),grow:!1}}if(wM.has(a)){let e=[...n?[wq({type:"heading",text:n},l)]:[],...o];return{min:Math.max(0,...e.map(e=>e.min))+2*i.x,pref:e.reduce((e,t)=>e+t.pref,0)+s*Math.max(0,e.length-1)+2*i.x,grow:!0}}if("grid"===a){let t=Math.max(1,Math.min("number"==typeof e.columns?e.columns:1,o.length||1));return{min:p,pref:Math.max(c,t*Math.max(0,...o.map(e=>e.pref))+s*(t-1)),grow:!0}}return{min:p+2*i.x,pref:Math.max(c,...o.map(e=>e.pref))+2*i.x,grow:!0}}(e,t)}}function wL(e){return(e.items??[]).join(" › ")}function wS(e){return Array.isArray(e.columns)?e.columns:[]}function wB(e,t,a,l,i){return{component:e,path:t,width:a,height:l,x:0,y:0,children:[],stretch:!1,paint:i}}function wA(e,t,a,l,i){var s,o,r,n,d,c,p;let{device:h}=t,g=h.touch,u=t.textAlign;switch(e.type){case"heading":{let i=wb(e.text,wx(e,t),a,16),s=wh(e.text??"",a,i);return wB(e,l,a,s.height,(e,t,a)=>[wf(`${a}:text`,s,i,e,u,y6,t)])}case"text":{if(e.text){let t=wh(e.text,Math.min(a,640),14);return wB(e,l,a,t.height,(e,a,l)=>[wf(`${l}:text`,t,14,e,u,y7,a)])}let t=e.lines??3;return wB(e,l,a,20*t,(e,a,l)=>{let i=Math.min(e.width,560),s="center"===u?e.x+(e.width-i)/2:e.x;return Array.from({length:t},(o,r)=>{let n=Math.max(8,Math.round(i*(r===t-1&&t>1?.6:[1,.94,.97,.9,.96,.92,.98][r%7]))),d="center"===u?s+(i-n)/2:s,c=e.y+20*r+10;return wv(`${l}:line-${r}`,[{x:d+2,y:c},{x:d+n-2,y:c}],wt,4,a)})})}case"link":{let i=wh(e.text??"",a,14),s=Math.max(i.height+3,t.mobile?g:0),o=e.disabled?y8:ws;return wB(e,l,Math.min(a,Math.max(i.width,t.mobile?g:0)),s,(e,t,a)=>{let l=e.y+Math.round((e.height-i.height-3)/2),s="center"===u?e.x+(e.width-i.width)/2:e.x,r=function(e){let t=0;for(let a of e)t+=/\p{Lu}/u.test(a)?.66:/[\p{Ll}\p{N}]/u.test(a)?.54:" "===a?.3:.42;return Math.min(Math.ceil(iC(e,14)),Math.ceil(14*t))}(i.text.split("\n").at(-1)??""),n="center"===u?e.x+(e.width-r)/2:s;return[wf(`${a}:text`,i,14,{x:e.x,y:l,width:e.width},u,o,t),wv(`${a}:underline`,[{x:n,y:l+i.height+2},{x:n+r,y:l+i.height+2}],o,1,t)]})}case"badge":{let t=wh(e.text??"",a-16,12),i=Math.max(22,t.height+8);return wB(e,l,Math.min(a,t.width+16),i,(a,l,i)=>[wm(`${i}:box`,"badge",a,wn,{fill:wa,stroke:we},e.text??"",l),wf(`${i}:text`,t,12,{x:a.x,y:a.y+Math.round((a.height-t.height)/2),width:a.width},"center",y7,l)])}case"button":{let t=Math.min(a,Math.max(80,wu(e.text,14)+32)),i=iS(e.text??"",t-32,14),s=i.split("\n").length,o=Math.max(h.control,Math.ceil(14*s*1.35)+18),r="primary"===e.variant,n=!0===e.disabled,d=n?wa:r?ws:wi,c=n?we:r?ws:y9,p=n?y8:r?wi:y6;return wB(e,l,t,o,(t,a,l)=>{let s=wm(`${l}:box`,"button",t,wn,{fill:d,stroke:c},e.text??"",a);return[s,wy(`${l}:label`,s,i,14,t.width-32,p,a)]})}case"input":case"textarea":case"select":case"search":return function(e,t,a,l){let{device:i}=t,s=e.type,o=e.label?wh(e.label,a,13):void 0,r=void 0!==e.value,n=e.value??e.placeholder??("search"===s?"Search":void 0),d=36*("select"===s||"search"===s),c=n?wh(n,a-24-d,14):void 0,p="textarea"===s?e.rows??3:1,h="textarea"===s?Math.max(i.control,20*p+16,(c?.height??0)+20):Math.max(i.control,(c?.height??0)+16),g=o?o.height+6:0,u=!0===e.disabled;return wB(e,l,a,g+h,(t,a,l)=>{let i={x:t.x,y:t.y+g,width:t.width,height:h},d=[];o&&d.push(wf(`${l}:label`,o,13,t,"left",y7,a)),d.push(wm(`${l}:box`,s,i,wn,{fill:u?wa:wi,stroke:u?we:y9},n??e.label??s,a)),c&&d.push(wf(`${l}:${r?"value":"placeholder"}`,c,14,{x:i.x+12,y:"textarea"===s?i.y+10:i.y+Math.round((h-c.height)/2),width:c.width},"left",r&&!u?y6:y8,a));let p=i.y+h/2,f=i.x+i.width;return"select"===s&&d.push(wv(`${l}:chevron-0`,[{x:f-24,y:p-3},{x:f-18,y:p+3}],y9,2,a),wv(`${l}:chevron-1`,[{x:f-18,y:p+3},{x:f-12,y:p-3}],y9,2,a)),"search"===s&&d.push(wm(`${l}:lens`,"search-lens",{x:f-28,y:p-7,width:11,height:11},wn,{fill:wi,stroke:y9,shape:"ellipse"},"Search",a),wv(`${l}:handle`,[{x:f-18.5,y:p+2.5},{x:f-14,y:p+7}],y9,2,a)),d})}(e,t,a,l);case"checkbox":case"radio":{let t=wh(e.label??"",a-18-8,14),i=Math.max(18,t.height,g);return wB(e,l,Math.min(a,26+t.width),i,(a,l,i)=>{let s=a.y+Math.round((a.height-Math.max(18,t.height))/2),o=s+(t.lines>1?0:Math.round((Math.max(18,t.height)-18)/2)),r={x:a.x,y:o,width:18,height:18},n=!0===e.checked,d=[];return"checkbox"===e.type?(d.push(wm(`${i}:box`,"checkbox",r,wn,n?{fill:ws,stroke:ws}:{fill:wi,stroke:y9},e.label??"",l)),n&&d.push(wv(`${i}:check-0`,[{x:r.x+4,y:r.y+9},{x:r.x+8,y:r.y+13}],wi,2,l),wv(`${i}:check-1`,[{x:r.x+8,y:r.y+13},{x:r.x+14,y:r.y+5}],wi,2,l))):(d.push(wm(`${i}:box`,"radio",r,wn,{fill:wi,stroke:n?ws:y9,shape:"ellipse"},e.label??"",l)),n&&d.push(wm(`${i}:dot`,"radio-dot",{x:r.x+5,y:r.y+5,width:8,height:8},wn,{fill:ws,stroke:ws,shape:"ellipse"},"selected",l))),d.push(wf(`${i}:text`,t,14,{x:a.x+18+8,y:s+Math.round((Math.max(18,t.height)-t.height)/2),width:t.width},"left",y6,l)),d})}case"toggle":{let t=wh(e.label??"",a-16-36,14);return wB(e,l,a,Math.max(20,t.height,g),(a,l,i)=>{let s,o,r,n=!0===e.checked,d={x:a.x+a.width-36,y:a.y+Math.round((a.height-20)/2),width:36,height:20},c=n?d.x+d.width-3-14:d.x+3;return[wf(`${i}:text`,t,14,{x:a.x,y:a.y+Math.round((a.height-t.height)/2),width:t.width},"left",y6,l),{...wm(`${i}:track`,"toggle",d,wn,n?{fill:ws,stroke:ws}:{fill:wl,stroke:we},`${e.label??"Toggle"}: ${n?"on":"off"}`,l),shape:"polygon",points:(s=10,o=[],(r=(e,t)=>{for(let a=0;a<=8;a+=1){let l=t+Math.PI*a/8;o.push({x:Math.round((e+s*Math.cos(l))*100)/100,y:Math.round((s+s*Math.sin(l))*100)/100})}})(36-s,-Math.PI/2),r(s,Math.PI/2),o)},wm(`${i}:knob`,"toggle-knob",{x:c,y:d.y+3,width:14,height:14},wn,{fill:wi,stroke:n?ws:y9,shape:"ellipse"},n?"on":"off",l)]})}case"tabs":return wP(e,t,a,l,"tabs");case"nav":return wP(e,t,a,l,"nav");case"breadcrumbs":{let t=wh(wL(e),a,13);return wB(e,l,Math.min(a,t.width),t.height,(e,a,l)=>[wf(`${l}:text`,t,13,e,"left",y8,a)])}case"avatar":{let a=t.mobile?Math.max(40,g):40;return wB(e,l,a,a,(t,l,i)=>{let s=wm(`${i}:box`,"avatar",t,wn,{fill:wl,stroke:y9,shape:"ellipse"},e.label??"Avatar",l);if(!e.label)return[s];let o=iQ(s).width,r=av(e.label);return iC(r,12)+24>a&&(r=[...r][0]??"?"),[s,wy(`${i}:label`,s,r,12,o,y6,l)]})}case"icon":{let i=t.mobile?g:22,s=e.label?wh(e.label,a-i-8,14):void 0,o=Math.max(i,s?.height??0);return wB(e,l,Math.min(a,i+(s?8+s.width:0)),o,(t,a,l)=>{let o=[wm(`${l}:box`,"icon",{x:t.x+(i-22)/2,y:t.y+Math.round((t.height-22)/2),width:22,height:22},wn,{fill:wl,stroke:y9,shape:"ellipse"},e.label??"Icon",a)];return s&&o.push(wf(`${l}:text`,s,14,{x:t.x+i+8,y:t.y+Math.round((t.height-s.height)/2),width:s.width},"left",y7,a)),o})}case"image":let f,m,v,y,w;return s=e,o=t,r=a,n=l,f="square"===s.aspect?1:"tall"===s.aspect?4/3:9/16,m=o.mobile?280:o.device===y4.tablet?360:480,v=Math.max(Math.min(r,wg(s.label,13)+24),Math.min(r,Math.round(m/f))),y=Math.max(48,Math.min(m,Math.round(v*f))),w=s.label?wh(s.label,v-24,13):void 0,wB(s,n,v,Math.max(y,(w?.height??0)+24),(e,t,a)=>{let l=[wm(`${a}:box`,"image",e,wd,{fill:wa,stroke:we},s.label??"Image",t)],i=[[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}],[{x:e.x+e.width,y:e.y},{x:e.x,y:e.y+e.height}]],o=w?{left:e.x+(e.width-w.width)/2-6,right:e.x+(e.width+w.width)/2+6,top:e.y+(e.height-w.height)/2-4,bottom:e.y+(e.height+w.height)/2+4}:void 0;return i.forEach(([e,i],s)=>{(o?function(e,t,a){let l=t.x-e.x,i=t.y-e.y,s=0,o=1;for(let[r,n]of[[-l,e.x-a.left],[l,a.right-e.x],[-i,e.y-a.top],[i,a.bottom-e.y]]){if(0===r){if(n<0)return[[e,t]];continue}let a=n/r;r<0?s=Math.max(s,a):o=Math.min(o,a)}if(s>=o)return[[e,t]];let r=t=>({x:e.x+l*t,y:e.y+i*t});return[...s>.02?[[e,r(s)]]:[],...o<.98?[[r(o),t]]:[]]}(e,i,o):[[e,i]]).forEach(([e,i],o)=>l.push(wv(`${a}:cross-${s}${o?`-${o}`:""}`,[e,i],we,1,t)))}),w&&l.push(wf(`${a}:text`,w,13,{x:e.x,y:e.y+(e.height-w.height)/2,width:e.width},"center",y8,t)),l});case"chart":let x,b,k;return d=e,c=a,p=l,x=d.label?wh(d.label,c-24,13):void 0,b=Math.max(120,Math.min(280,Math.round(.4*c))),wB(d,p,c,16+(k=x?x.height+12:0)+b+16,(e,t,a)=>{let l=[wm(`${a}:box`,"chart",e,wd,{fill:wi,stroke:we},d.label??"Chart",t)];x&&l.push(wf(`${a}:title`,x,13,{x:e.x+16,y:e.y+16,width:x.width},"left",y7,t));let i={x:e.x+24,y:e.y+16+k,width:e.width-48,height:b},s=d.kind??"bar";if("pie"===s){let e=Math.min(i.width,i.height),s={x:i.x+(i.width-e)/2,y:i.y,width:e,height:e},o=s.x+e/2,r=s.y+e/2;return l.push(wm(`${a}:pie`,"chart-pie",s,wn,{fill:wa,stroke:y9,shape:"ellipse"},"Pie",t)),[-90,40,150].forEach((i,s)=>{let n=i*Math.PI/180;l.push(wv(`${a}:slice-${s}`,[{x:o,y:r},{x:o+e/2*Math.cos(n),y:r+e/2*Math.sin(n)}],y9,1,t))}),l}let o=i.y+i.height;if(l.push(wv(`${a}:x-axis`,[{x:i.x,y:o},{x:i.x+i.width,y:o}],y9,1,t),wv(`${a}:y-axis`,[{x:i.x,y:i.y},{x:i.x,y:o}],y9,1,t)),"line"===s){let e=(i.width-16)/(wH.length-1);return l.push(wv(`${a}:series`,wH.map((t,a)=>({x:i.x+8+e*a,y:o-8-(i.height-16)*t})),ws,2,t)),l}let r=(i.width-16)/wV.length;return wV.forEach((e,s)=>{let n=Math.round((i.height-8)*e);l.push(wm(`${a}:bar-${s}`,"chart-bar",{x:Math.round(i.x+8+r*s+.2*r),y:o-n,width:Math.max(4,Math.round(.6*r)),height:n},wd,{fill:wt,stroke:wt},"Bar",t))}),l});case"table":return function(e,t,a,l){let i=wS(e),s=e.rows??4,o=function(e,t){let a=e.map(e=>wg(e,13)+24);if(!(a.reduce((e,t)=>e+t,0)>t))return wI(a,t)}(i,a),r=t.mobile?44:40;if(o){let t=i.map((e,t)=>wh(e,o[t]-24,13)),n=Math.max(r,Math.max(...t.map(e=>e.height))+16);return wB(e,l,a,n+s*r,(e,a,l)=>{let d=[wm(`${l}:box`,"table",e,wd,{fill:wi,stroke:we},i.join(" | "),a),wm(`${l}:head`,"table-head",{x:e.x,y:e.y,width:e.width,height:n},wd,{fill:wa,stroke:we},"Header",a)],c=e.x,p=o.map(e=>{let t=c;return c+=e,t});t.forEach((t,i)=>d.push(wf(`${l}:header-${i}`,t,13,{x:p[i]+12,y:e.y+Math.round((n-t.height)/2),width:t.width},"left",y6,a)));for(let t=0;t<s;t+=1){let i=e.y+n+t*r;t>0&&d.push(wv(`${l}:rule-${t}`,[{x:e.x,y:i},{x:e.x+e.width,y:i}],wt,1,a)),o.forEach((e,s)=>{let o=Math.max(12,Math.round((e-24)*[.7,.5,.62,.45,.66,.55][(t+2*s)%6])),n=p[s]+12;d.push(wv(`${l}:cell-${t}-${s}`,[{x:n+2,y:i+r/2},{x:n+o-2,y:i+r/2}],wt,4,a))})}return d})}let n=Math.min(Math.floor(a/2),Math.max(...i.map(e=>wu(e,13)))),d=i.map(e=>wh(e,Math.max(n,wg(e,13)),13)),c=d.map(e=>Math.max(24,e.height+6)),p=c.reduce((e,t)=>e+t,0)+16;return wB(e,l,a,s*p,(e,t,a)=>{let l=[wm(`${a}:box`,"table",e,wd,{fill:wi,stroke:we},i.join(" | "),t)];for(let i=0;i<s;i+=1){let s=e.y+i*p+8;i>0&&l.push(wv(`${a}:rule-${i}`,[{x:e.x,y:s-8},{x:e.x+e.width,y:s-8}],wt,1,t)),d.forEach((o,r)=>{let d=c[r];l.push(wf(`${a}:header-${i}-${r}`,o,13,{x:e.x+12,y:s+Math.round((d-o.height)/2),width:o.width},"left",y8,t));let p=e.x+12+Math.max(n,o.width)+12,h=e.x+e.width-12-p,g=[.8,.55,.7,.6][(i+r)%4];l.push(wv(`${a}:cell-${i}-${r}`,[{x:p+2,y:s+d/2},{x:p+Math.max(10,h*g)-2,y:s+d/2}],wt,4,t)),s+=d})}return l})}(e,t,a,l);case"list":{let t=(e.items??[]).map(e=>wh(e,a-6-12,14));return wB(e,l,a,t.reduce((e,t)=>e+t.height,0)+8*Math.max(0,t.length-1),(e,a,l)=>{let i=e.y;return t.flatMap((t,s)=>{let o=i;return i+=t.height+8,[wm(`${l}:bullet-${s}`,"bullet",{x:e.x+2,y:o+5.75,width:6,height:6},wn,{fill:y7,stroke:y7,shape:"ellipse"},"•",a),wf(`${l}:item-${s}`,t,14,{x:e.x+6+12,y:o,width:t.width},"left",y7,a)]})})}case"divider":return wB(e,l,a,1,(e,t,a)=>[wv(`${a}:line`,[{x:e.x,y:e.y+.5},{x:e.x+e.width,y:e.y+.5}],we,1,t)]);default:return function(e,t,a,l,i){let s,o,r,n=e.type,d=wk(e,t),c=wC(n,t),p=w_(n,t),h=e.align??("header"===n||"footer"===n?"between":"start"),g=a-2*c.x,u=e.children??[],f=function(e,t,a){if(!e.title||wM.has(e.type))return;let l="modal"===e.type?a-32:a,i=wb(e.title,wz(e.type,t),l,13);return{text:wh(e.title,l,i),size:i}}(e,t,g),m=f?.text,v=f?.size??wz(n,t),y="modal"===n?wh("×",24,20):void 0,w=Math.max(m?Math.max(m.height,i??0):0,y?.height??0),x=w&&u.length?"modal"===n?16:12:0,b=u.map((e,t)=>`${l}.${t}`);if(wM.has(n)){let t=function(e,t,a,l,i,s){let o=e.map(e=>wq(e,t)),r="center"===i||"end"===i,n=[],d=[],c=0;o.forEach((e,t)=>{let i=e.min;d.length>0&&c+l+i>a&&(n.push(d),d=[],c=0),c+=(d.length>0?l:0)+i,d.push(t)}),d.length&&n.push(d);let p=[],h=0,g=!1;for(let d of n){let n=a-l*(d.length-1),c=d.map(e=>o[e].min).reduce((e,t)=>e+t,0),u=d.filter(e=>!r&&o[e].grow),f=d.filter(e=>r||!o[e].grow),m=new Map(d.map(e=>[e,o[e].min])),v=n-c,y=f.reduce((e,t)=>e+Math.max(0,o[t].pref-o[t].min),0);for(let e of f){let t=Math.max(0,o[e].pref-o[e].min),a=y<=v?t:Math.floor(t*v/Math.max(1,y));m.set(e,o[e].min+a)}if(v=n-[...m.values()].reduce((e,t)=>e+t,0),u.length>0&&v>0){let e=wI(u.map(e=>m.get(e)),u.reduce((e,t)=>e+m.get(t),0)+v);u.forEach((t,a)=>m.set(t,e[a]))}let w=w$(a=>d.map(l=>wA(e[l],t,m.get(l),s[l],a))),x=Math.max(0,...w.map(e=>e.height)),b=Math.max(0,a-(w.reduce((e,t)=>e+t.width,0)+l*(w.length-1))),k="center"===i?Math.floor(b/2):"end"===i?b:0,M="between"===i&&w.length>1&&b>0;g||=M;let z=M?b/(w.length-1):0;w.forEach((e,t)=>{e.x=Math.round(k+(M?z*t:0)),e.stretch&&(e.height=x),e.y=h+Math.round((x-e.height)/2),k+=e.width+l,p.push(e)}),h+=x+l}return{laid:p,height:Math.max(0,h-l),spread:g}}(e.title?[{type:"heading",text:e.title},...u]:[...u],d,g,p,h,e.title?[`${l}.title`,...b]:b);s=t.laid,o=t.height,r={axis:"row",gap:p,spread:t.spread}}else if("grid"===n){let t=function(e,t,a,l,i,s){let o=t.map(e=>wq(e,a)),r=Math.max(0,...o.map(e=>e.min)),n=Math.max(1,Math.min("number"==typeof e.columns?e.columns:1,t.length)),d=e=>Math.floor((l-i*(e-1))/e);for(;n>1&&d(n)<r;)n-=1;let c=d(n),p=[],h=0;for(let e=0;e<t.length;e+=n){let l=w$(l=>t.slice(e,e+n).map((t,i)=>wA(t,a,Math.max(c,o[e+i].min),s[e+i],l))),r=Math.max(...l.map(e=>e.height));l.forEach((e,t)=>{e.x=t*(c+i),e.y=h,e.stretch&&(e.height=r),p.push(e)}),h+=r+i}return{laid:p,height:Math.max(0,h-i)}}(e,u,d,g,p,b);s=t.laid,o=t.height,r={axis:"grid",gap:p,spread:!1}}else{let e,t=(e=0,{laid:u.map((t,a)=>{let l=wc(wq(t,d),g,h),i=wA(t,d,l,b[a]);return i.x="center"===h?Math.floor((g-i.width)/2):"end"===h?g-i.width:0,i.y=e,e+=i.height+p,i}),height:Math.max(0,e-p)});s=t.laid,o=t.height,r={axis:"column",gap:p,spread:!1}}let k=c.y+(w?w+x:0);for(let e of s)e.x+=c.x,e.y+=k;let M="header"===n||"footer"===n,z=Math.max(k+o+c.y,M?t.device.barHeight:0,"card"===n||"modal"===n?2*c.y:0);if(M&&z>k+o+c.y){let e=Math.round((z-(k+o+c.y))/2);for(let t of s)t.y+=e}let C=(e,t,a)=>m?[wf(`${a}:title`,m,v,{x:e.x+c.x,y:e.y+c.y,width:y?g-32:g},d.textAlign,y6,t)]:[];return{component:e,path:l,width:a,height:z,x:0,y:0,children:s,flow:r,stretch:"card"===n||"section"===n||"column"===n||"modal"===n,...m?{titleHeight:m.height}:{},paint:(t,a,l)=>{switch(n){case"card":return[wm(`${l}:box`,"card",t,wn,{fill:wi,stroke:we},e.title??"Card",a),...C(t,a,l)];case"modal":return[wm(`${l}:box`,"modal",t,wn,{fill:wi,stroke:y9,strokeWidth:2},e.title??"Dialog",a),...C(t,a,l),wf(`${l}:close`,y,20,{x:t.x+t.width-c.x-y.width,y:t.y+c.y,width:y.width},"left",y8,a)];case"header":case"footer":case"sidebar":return[wm(`${l}:box`,n,t,wd,{fill:wa,stroke:we},e.title??n,a),...C(t,a,l)];default:return C(t,a,l)}}}}(e,t,a,l,i)}}function wP(e,t,a,l,i){let s=e.items??[],o="nav"===i&&t.inSidebar,r=Math.max("tabs"===i?38:36,t.device.touch),n=[],d=[];if(o)for(let e of s){let t=wh(e,a-24,14),l=n.length?n.at(-1).box.y+n.at(-1).box.height+4:0;n.push({item:e,text:t,box:{x:0,y:l,width:a,height:Math.max(r,t.height+16)}})}else{let e=0,t=0,l=[],i=()=>{let a=Math.max(r,...l.map(({text:e})=>e.height+16));for(let e of l)n.push({item:e.item,text:e.text,box:{x:e.x,y:t,width:e.width,height:a}});d.push(t+a),t+=a+4,l=[],e=0};for(let t of s){let s=wh(t,a-24,14),o=Math.min(a,s.width+24);e>0&&e+o>a&&i(),l.push({item:t,text:s,x:e,width:o}),e+=o+4}l.length&&i()}let c=Math.max(0,...n.map(({box:e})=>e.y+e.height)),p=o?a:Math.max(0,...n.map(({box:e})=>e.x+e.width)),h="tabs"===i||o?a:Math.min(a,p),g=!o&&"center"===t.textAlign;return wB(e,l,h,c+ +("tabs"===i),(t,a,l)=>{let o=[],r=g&&"tabs"===i?Math.round((t.width-p)/2):0;return"tabs"===i&&d.forEach((e,i)=>o.push(wv(`${l}:baseline${i?`-${i}`:""}`,[{x:t.x,y:t.y+e+.5},{x:t.x+t.width,y:t.y+e+.5}],we,1,a))),n.forEach(({item:n,text:d,box:c},p)=>{let h={x:t.x+r+c.x,y:t.y+c.y,width:c.width,height:c.height},g=e.active===n&&s.indexOf(n)===p;g&&"nav"===i&&o.push(wm(`${l}:active`,"nav-active",h,wn,{fill:wo,stroke:wo},`${n} (active)`,a)),o.push(wf(`${l}:item-${p}`,d,14,{x:h.x+12,y:h.y+Math.round((h.height-d.height)/2),width:h.width-24},"left",g?ws:y7,a)),g&&"tabs"===i&&o.push(wv(`${l}:active`,[{x:h.x+4,y:h.y+h.height-1},{x:h.x+h.width-4,y:h.y+h.height-1}],ws,2,a))}),o})}let wV=[.45,.7,.55,.85,.65,.95],wH=[.3,.55,.45,.7,.6,.85,.75];function wI(e,t){let a=Array.from({length:e.length},()=>0),l=e.map((e,t)=>({min:e,index:t})).toSorted((e,t)=>t.min-e.min),i=t,s=e.length,o=[];for(let{min:e,index:t}of l)0===o.length&&e>i/s?(a[t]=e,i-=e,s-=1):o.push(t);o.sort((e,t)=>e-t);let r=o.length?Math.floor(i/o.length):0,n=i-r*o.length;for(let e of o)a[e]=r+ +(n>0),n>0&&(n-=1);return a}function w$(e){let t=e(),a=t.flatMap(e=>void 0===e.titleHeight?[]:[e.titleHeight]);return a.length<2||Math.min(...a)===Math.max(...a)?t:e(Math.max(...a))}function wF(e){let t=y4[e.device],a="mobile"===e.device,l={device:t,mobile:a,inSidebar:!1,headingLevel:1,textAlign:"center"===e.align?"center":"left"},i=e.children.map((e,t)=>({component:e,index:t})),s=i.filter(({component:e})=>"header"===e.type),o=i.filter(({component:e})=>"footer"===e.type),r=a?[]:i.filter(({component:e})=>"sidebar"===e.type),n=i.filter(({component:e})=>"modal"===e.type),d=i.filter(({component:e})=>{let t;return"header"!==(t=e.type)&&"footer"!==t&&"modal"!==e.type&&(a||"sidebar"!==e.type)}),c=e=>r.filter(({component:t})=>(t.side??"left")===e).reduce((e,{component:t})=>e+wq(t,l).min,0),p=e.align??"start",h=Math.max(0,...d.map(({component:e})=>wq(e,l).min)),g=Math.max(0,...[...s,...o,...n].map(({component:e})=>wq(e,l).min)),u=Math.max(t.width,c("left")+c("right")+h+2*t.pad,g+(n.length?2*t.pad:0)),f=e=>String(e),m=[],v=0;for(let{component:e,index:t}of s){let a=wA(e,l,u,f(t));a.x=0,a.y=v,v+=a.height,m.push(a)}let y=c("left"),w=u-y-c("right")-2*t.pad,x=[],b=t.pad;d.forEach(({component:e,index:a})=>{let i=wc(wq(e,l),w,p),s=wA(e,l,i,f(a));s.x=y+t.pad+("center"===p?Math.floor((w-s.width)/2):"end"===p?w-s.width:0),s.y=v+b,b+=s.height+t.gap,x.push(s)});let k=d.length?b-t.gap+t.pad:0,M=r.map(({component:e,index:t})=>{let a=wq(e,l);return wA(e,l,a.min,f(t))}),z=o.map(({component:e,index:t})=>wA(e,l,u,f(t))),C=z.reduce((e,t)=>e+t.height,0),_=n.map(({component:e,index:a})=>{let i=wq(e,l);return wA(e,l,Math.max(i.min,Math.min(i.pref,u-2*t.pad)),f(a))}),q=_.reduce((e,t)=>e+t.height,0)+t.gap*Math.max(0,_.length-1),L=Math.max(k,...M.map(e=>e.height)),S=Math.max(t.minHeight,v+L+C,q+2*t.pad);L=S-v-C;let B={left:0,right:u};for(let e of M){let t=e.component.side??"left";e.x="left"===t?B.left:B.right-e.width,B="left"===t?{...B,left:B.left+e.width}:{...B,right:B.right-e.width},e.y=v,e.height=L}let A=S-C;for(let e of z)e.x=0,e.y=A,A+=e.height;let P=Math.max(t.pad,Math.round((S-q)/2));for(let e of _)e.x=Math.round((u-e.width)/2),e.y=P,P+=e.height+t.gap;S=Math.max(S,P-t.gap+t.pad),m.push(...x,...M,...z,..._);let V=s.length+o.length+d.length+r.length>0;return{screen:e,width:u,height:S,widened:u>t.width,laid:m,scrim:_.length>0&&V,modals:new Set(_.map(e=>e.path))}}let wO=(e,t,a)=>"line"===e.type||"arrow"===e.type?{...e,points:e.points.map(e=>({x:e.x+t,y:e.y+a}))}:{...e,x:e.x+t,y:e.y+a},wE=e=>`screen:${e}`,wU=(e,t)=>`nav:${e}:${t}`,wX=[560,640,720,800,880,960],wT=v.ink,wR="#4c4639",wY={topLeft:pT["0"],topRight:pT["2"],bottomLeft:pT["3"],bottomRight:pT["4"]};function wD(e,t,a){var l;let i=Math.max(...e.split(/\s+/u).map(e=>Math.ceil(iC(e,a))));return{text:l=iS(e,Math.max(t,i)+1,a),width:Math.ceil(iC(l,a)),height:Math.ceil(l.split("\n").length*a*1.35)}}function wG(e){return Math.round(100*e)/100}function wZ(e,t,a){return{left:e,top:t,right:e+a.width,bottom:t+a.height}}function wj(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 wN(e,t,a){if(Math.max(e.x,t.x)<a.left||Math.min(e.x,t.x)>a.right||Math.max(e.y,t.y)<a.top||Math.min(e.y,t.y)>a.bottom)return!1;let l=0,i=1,s=t.x-e.x,o=t.y-e.y;for(let[t,r]of[[-s,e.x-a.left],[s,a.right-e.x],[-o,e.y-a.top],[o,a.bottom-e.y]]){if(0===t){if(r<0)return!1;continue}let e=r/t;if(t<0?l=Math.max(l,e):i=Math.min(i,e),l>i)return!1}return i-l>1e-9}function wW(e,t,a,l){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,l)<0&&i(a,l,e)*i(a,l,t)<0}function wJ(e){let t=e/2;return{topLeft:{left:0,top:0,right:t,bottom:t},topRight:{left:t,top:0,right:e,bottom:t},bottomLeft:{left:0,top:t,right:t,bottom:e},bottomRight:{left:t,top:t,right:e,bottom:e}}}function wK(e,t){let a=t.right-t.left;return{x:t.left+e.x*a,y:t.top+(1-e.y)*a}}function wQ(e,t=6){let a=e.map((e,t)=>t),l=e=>{for(;a[e]!==e;)e=a[e]=a[a[e]];return e};for(let i=0;i<e.length;i+=1)for(let s=i+1;s<e.length;s+=1){let o=e[i],r=e[s];Math.hypot(o.x-r.x,o.y-r.y)<=12+t&&(a[l(s)]=l(i))}return e.map((e,t)=>l(t))}function w1(e){return{left:e.x-6,top:e.y-6,right:e.x+6,bottom:e.y+6}}function w0(e,t){let{x:a,y:l}=e,{width:i,height:s}=t;return[wZ(a+10,l-s/2,t),wZ(a-10-i,l-s/2,t),wZ(a-i/2,l-6-2-1-s,t),wZ(a-i/2,l+6+2+1,t),wZ(a+9,l-9-s,t),wZ(a-9-i,l-9-s,t),wZ(a+9,l+9,t),wZ(a-9-i,l+9,t)]}function w2(e,t){return Math.hypot(Math.max(e.left-t.x,0,t.x-e.right),Math.max(e.top-t.y,0,t.y-e.bottom))}function w3(e,t){return{x:Math.min(e.right,Math.max(e.left,t.x)),y:Math.min(e.bottom,Math.max(e.top,t.y))}}function w5(e,t,a,l=0){let i=[e.left,e.right,...a?[a[0].x,a[1].x]:[]],s=[e.top,e.bottom,...a?[a[0].y,a[1].y]:[]];return{box:e,cost:t,over:l,...a?{leader:a}:{},extent:{left:Math.min(...i),top:Math.min(...s),right:Math.max(...i),bottom:Math.max(...s)}}}function w4(e,t){var a,l,i,s;if(!wj(e.extent,t.extent,4))return!1;if(wj(e.box,t.box,3))return!0;let o=e=>({left:e.left-1,top:e.top-1,right:e.right+1,bottom:e.bottom+1});if(e.leader&&wN(e.leader[0],e.leader[1],o(t.box))||t.leader&&wN(t.leader[0],t.leader[1],o(e.box)))return!0;if(!e.leader||!t.leader)return!1;if(wW(e.leader[0],e.leader[1],t.leader[0],t.leader[1]))return!0;let r=e=>{let[t,a]=e;return[{x:(t.x+a.x)/2,y:(t.y+a.y)/2},a]},[n,d]=r(e.leader),[c,p]=r(t.leader);return!(Math.max(n.x,d.x)+5<Math.min(c.x,p.x)||Math.max(c.x,p.x)+5<Math.min(n.x,d.x)||Math.max(n.y,d.y)+5<Math.min(c.y,p.y)||Math.max(c.y,p.y)+5<Math.min(n.y,d.y))&&5>(wW(a=n,l=d,i=c,s=p)?0:Math.min(w6(a,i,s),w6(l,i,s),w6(i,a,l),w6(s,a,l)))}function w6(e,t,a){let l=a.x-t.x,i=a.y-t.y,s=Math.max(0,Math.min(1,((e.x-t.x)*l+(e.y-t.y)*i)/(l*l+i*i||1)));return Math.hypot(e.x-t.x-s*l,e.y-t.y-s*i)}function w7(e,t,{crowded:a=new Set,relaxed:l=!1,labelFont:i=14,thorough:s=!1,work:o={spent:0,limit:1/0}}={}){let r=()=>o.spent>o.limit,n={left:0,top:0,right:t,bottom:t},d={left:6,top:6,right:t-6,bottom:t-6},c=e.points.map(e=>wK(e,n)),p=c.map(w1),h=wQ(c),g=wJ(t),u=[],f=e.points.map(e=>wD(e.label,150*i/14,i)),m=t/2,v=e=>(o.spent+=1,e.left>=d.left&&e.top>=d.top&&e.right<=d.right&&e.bottom<=d.bottom&&!(e.left<m+3&&e.right>m-3||e.top<m+3&&e.bottom>m-3)&&!p.some(t=>wj(e,t,2))&&!u.some(t=>wj(e,t,3))),y=(e,t)=>{let a=c[e],i=Math.hypot(t.x-a.x,t.y-a.y);if(i<=11)return;let s={x:a.x+(t.x-a.x)*7/i,y:a.y+(t.y-a.y)*7/i};if(u.some(e=>wN(s,t,e)))return;let o=p.filter((a,l)=>h[l]!==h[e]&&wN(s,t,{left:a.left-1,top:a.top-1,right:a.right+1,bottom:a.bottom+1})).length;return o&&!l?void 0:{leader:[s,t],over:o}},w=new Map;h.forEach((e,t)=>w.set(e,[...w.get(e)??[],t]));let x=e.points.map(()=>void 0),b=new Map,k=new Map;for(let e of((s?wQ(c,40):h).forEach((e,t)=>k.set(e,[...k.get(e)??[],t])),k.values()))if(!(e.length<4))for(let[t,a]of function(e,t,a,l,i,s,o,r,n=!1){let d=e.toSorted((e,a)=>t[e].x-t[a].x||e-a),c=(i.top+i.bottom)/2,p=Math.min(...e.map(e=>a[e].left)),h=Math.max(...e.map(e=>a[e].right)),g=Math.ceil(d.length/2),u=[[d.slice(0,d.length-g),d.slice(d.length-g)],[[],d],[d,[]]];for(let e of[16,28,44,64,96,140,200])for(let[a,d]of u){let g=new Map,u=!0;for(let[f,m]of[[-1,a],[1,d]]){if(!m.length)continue;let a=m.toSorted((e,a)=>t[e].y-t[a].y||e-a),d=()=>(function(e,t,a,l){let i=(e,t)=>void 0!==l&&e<l.high&&e+t>l.low,s=[],o=t;for(let t of e){let e=Math.max(t.preferred-t.size/2,o);i(e,t.size)&&(e=l.high),s.push(e),o=e+t.size+4}let r=a;for(let t=e.length-1;t>=0;t-=1){let a=Math.min(s[t],r-e[t].size);i(a,e[t].size)&&(a=l.low-e[t].size),s[t]=a,r=a-4}return s})(a.map(e=>({preferred:t[e].y,size:l[e].height})),i.top,i.bottom,{low:c-3,high:c+3}).map((t,i)=>{let s=l[a[i]];return wZ(f>0?h+e:p-e-s.width,t,s)}),v=e=>({x:f>0?e.left:e.right,y:(e.top+e.bottom)/2});for(let e=0;e<4*a.length;e+=1){let e=d(),l=a.flatMap((l,i)=>a.slice(i+1).flatMap((a,s)=>wW(t[l],v(e[i]),t[a],v(e[i+1+s]))?[[i,i+1+s]]:[]))[0];if(!l)break;let[i,s]=l;[a[i],a[s]]=[a[s],a[i]]}let y=d();for(let[e,t]of a.entries()){let a=y[e],l=s(a)?o(t,v(a)):void 0,i=l&&(n||!l.over)?w5(a,20+120*l.over,l.leader,l.over):void 0;if(!i||[...g.values(),...r].some(e=>w4(i,e))){u=!1;break}g.set(t,i)}if(!u)break}if(u)return g}}(e,c,p,f,d,v,y,[...b.values()],l)??[])b.set(t,a),x[t]=a;let M=0,z=Object.fromEntries(Object.keys(g).map(t=>{let l=function(e,t,a,l,i,s){let o,r="topLeft"===t||"topRight"===t,n="topLeft"===t||"bottomLeft"===t,d={left:a.left+10,top:a.top+10,right:a.right-10,bottom:a.bottom-10},c=[];for(let[t,a]of[1,.5,1/3].map((e,t)=>[t,(d.right-d.left)*e])){let l=wD(e,a,16);if(l.width>d.right-d.left||l.height>d.bottom-d.top)continue;let i=d.right-d.left-l.width,s=d.bottom-d.top-l.height;for(let e=0;e<=s+1e-9;e+=Math.max(4,s/40)||1){for(let a=0;a<=i+1e-9;a+=Math.max(4,i/40)||1){let s=n?d.left+a:d.right-l.width-a,o=r?d.top+e:d.bottom-l.height-e;if(c.push({text:l,box:wZ(s,o,l),score:a+3*e+40*t}),0===i)break}if(0===s)break}}c.sort((e,t)=>e.score-t.score);let p=(e,t)=>!l.some((a,l)=>wj(e,a,t?i.has(l)?72:24:2))&&!s.some(t=>w4(t,w5(e,0)));if(!c.length){let t=wD(e,d.right-d.left,16);return{text:t,box:wZ(d.left,d.top,t),clear:!1}}let h=c.find(e=>p(e.box,!0))??c.find(e=>p(e.box,!1));if(h)return{text:h.text,box:h.box,clear:!0};for(let e of c){let t=l.filter(t=>wj(e.box,t,2)).length;(!o||t<o.hits)&&(o={...e,hits:t})}return{text:o.text,box:o.box,clear:0===o.hits}}(e.quadrants[t],t,g[t],p,a,[...b.values()]);return l.clear||(M+=1),[t,{text:l.text,box:l.box}]}));for(let[e,t]of(u=Object.values(z).map(e=>e.box),b))u.some(e=>w4(t,w5(e,0)))&&(b.delete(e),x[e]=void 0);let C=e.points.map((e,t)=>w0(c[t],f[t]).flatMap((e,a)=>{let l;return v(e)&&(l=w2(e,c[t]),c.every((a,i)=>i===t||1>Math.hypot(a.x-c[t].x,a.y-c[t].y)||w2(e,a)>l+2))?[w5(e,a+330*(void 0!==function(e,t,a,l=0){let i=a[t];if(!i||i.y+6>e.top-l&&i.y-6<e.bottom+l||i.x+6>e.left-l&&i.x-6<e.right+l)return;let s=48-l,o=a.findIndex((a,o)=>o!==t&&void 0!==a&&Math.hypot(a.x-i.x,a.y-i.y)>=1&&(a.y>e.top+l&&a.y<e.bottom-l&&Math.max(e.left-a.x,a.x-e.right)<=s||a.x>e.left+6+l&&a.x<e.right-6-l&&Math.max(e.top-a.y,a.y-e.bottom)<=s));return -1===o?void 0:o}(e,t,c)))]:[]})),_=C.map(e=>e.filter(e=>e.cost<330)),q=C.map(e=>e.filter(e=>e.cost>=330)),L=_.map(e=>[...e]);for(let[e,t]of b)L[e]=[t,...L[e]];let S=(e,t)=>(o.spent+=1,w4(e,t)),B=[],A=e=>B[e]??=[...L[e],...[...q[e],...(e=>{let a,i,s,o=c[e],n=f[e],d=(a=c[e],i=0,s=0,c.forEach((t,l)=>{let o=Math.hypot(a.x-t.x,a.y-t.y);l===e||o<1e-6||(i+=(a.x-t.x)/o/(o+1)**2,s+=(a.y-t.y)/o/(o+1)**2)}),0===i&&0===s?-Math.PI/2:Math.atan2(s,i)),p=[];for(let a=22;a<=(l?t:300)&&!r();a+=12)for(let t=0;t<24;t+=1){let l=Math.ceil(t/2)*(t%2?1:-1),i=d+2*l*Math.PI/24,s=Math.cos(i),r=Math.sin(i),c={x:o.x+a*s,y:o.y+a*r},h=s>.38?[c.x]:s<-.38?[c.x-n.width]:[c.x-n.width/2,c.x,c.x-n.width],g=r>.38?[c.y]:r<-.38?[c.y-n.height]:[c.y-n.height/2,c.y,c.y-n.height],u=30+a+9*Math.abs(l);for(let[t,a]of h.entries())for(let[l,i]of g.entries()){let s=wZ(a,i,n);if(!v(s))continue;let r=y(e,w3(s,o));r&&p.push(w5(s,u+(t||l?2:0)+120*r.over,r.leader,r.over))}}return p.sort((e,t)=>e.cost-t.cost)})(e)].sort((e,t)=>e.cost-t.cost)],P=(e,t)=>x.flatMap((a,l)=>l!==e&&a&&S(t,a)?[l]:[]),V=(e,t)=>x.every((a,l)=>l===e||!a||!S(t,a)),H=e=>L[e].find(t=>V(e,t))??A(e).find(t=>V(e,t)),I=new Set(e.points.flatMap((e,t)=>x[t]?[]:[t]));for(;I.size&&!r();){let e;for(let t of I){let a=_[t].filter(e=>V(t,e)).length;if((!e||a<e.count)&&(e={index:t,count:a}),0===a)break}I.delete(e.index),x[e.index]=H(e.index)}let $=e.points.map(()=>0),F=e.points.flatMap((e,t)=>x[t]?[]:[t]);for(let t=0;F.length&&!r()&&t<(s?4:1)*6*e.points.length;t+=1){let e,t,a=F.shift(),l=H(a);if(l){x[a]=l;continue}let i=s?960:240,o=A(a).slice(0,i).map(e=>({spot:e,displaced:P(a,e)}));for(let{spot:t,displaced:l}of o.slice(0,s?192:48)){if(r())break;if(1!==l.length)continue;let s=l[0],o=x[s];x[s]=void 0,x[a]=t;let n=A(s).slice(0,i).find(e=>V(s,e));if(x[a]=void 0,x[s]=o,n){e={spot:t,other:s,moved:n};break}}if(e){x[a]=e.spot,x[e.other]=e.moved;continue}for(let{spot:e,displaced:a}of o){let l=a.reduce((e,t)=>e+1e3*(1+$[t]),0)+e.cost;(!t||l<t.weight)&&(t={spot:e,displaced:a,weight:l})}if(t){for(let e of t.displaced)x[e]=void 0,$[e]=$[e]+1,F.push(e);x[a]=t.spot}}if(s)for(let t of e.points.keys()){let e;if(x[t])continue;let a=c[t],l=f[t];for(let i=d.top;i+l.height<=d.bottom&&!r();i+=8)for(let s=d.left;s+l.width<=d.right;s+=8){let o=wZ(s,i,l),r=w2(o,a);if(e&&r+30>=e.cost||!v(o))continue;let n=y(t,w3(o,a));if(!n)continue;let d=w5(o,30+r+120*n.over,n.leader,n.over);V(t,d)&&(!e||d.cost<e.cost)&&(e=d)}e&&(x[t]=e)}let O=x.flatMap((e,t)=>e?[]:[t]),E=x.map((e,t)=>{let a=f[t];return e?e.leader?{text:a,box:e.box,leader:e.leader}:{text:a,box:e.box}:{text:a,box:w0(c[t],a)[0]}});return{size:t,names:z,labels:E,labelFont:i,leaders:E.filter(e=>e.leader).length,blocked:O.length,blockedPoints:O,overDots:x.filter(e=>e&&e.over>0).length,clumped:[...w.values()].filter(e=>e.length>=4).reduce((e,t)=>e+t.length,0),covered:M}}class w8{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]}text(e,t,a,l,i,s,o){this.push({type:"text",id:e,x:wG((a.left+a.right)/2),y:wG((a.top+a.bottom)/2),text:t.text,fontSize:l,maxWidth:t.width,textAlign:s,textColor:i,...o?{groupIds:[o]}:{}},"front"),this.textBoxes.push(a)}line(e,t,a,l,i="middle"){this.push({type:"line",id:e,points:[{x:wG(t.x),y:wG(t.y)},{x:wG(a.x),y:wG(a.y)}],roughness:0,strokeWidth:1,...l},i)}mark(e,t,a,l,i,s){this.push({type:"node",id:`node:${e}`,nodeId:e,rendererRole:"quadrant-mark",shape:t,x:wG(a.left),y:wG(a.top),width:wG(a.right-a.left),height:wG(a.bottom-a.top),label:l,roughness:0,fillStyle:"solid",strokeWidth:1,...i},s)}bounds(){let e=1/0,t=1/0,a=-1/0,l=-1/0,i=i=>{e=Math.min(e,i.left),t=Math.min(t,i.top),a=Math.max(a,i.right),l=Math.max(l,i.bottom)};for(let e of this.elements)if("line"===e.type||"arrow"===e.type)for(let t of e.points)i({left:t.x,top:t.y,right:t.x,bottom:t.y});else"node"===e.type&&i({left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height});for(let e of this.textBoxes)i(e);return{left:e,top:t,right:a,bottom:l}}}function w9(e){let t=e.maxWidth??iC(e.text,e.fontSize),a=e.text.split("\n").length*e.fontSize*(e.lineHeight??1.35);return{left:e.x-t/2,top:e.y-a/2,right:e.x+t/2,bottom:e.y+a/2}}function xe(e,t){let a="left"===t?Math.min(...e.map(e=>e.x)):Math.max(...e.map(e=>e.x)),l=e.filter(e=>.01>Math.abs(e.x-a)).map(e=>e.y);return{x:a,top:Math.min(...l),bottom:Math.max(...l)}}var xt=a(5185);a(328);var xa=a(4876),xl=a(7669),xi=a(9332),xs=a(5005),xo=a(2538),xr=a(244),xn=a(6307);let xd=s.Or("effect/Metric/CurrentMetricAttributes",{defaultValue:()=>({})}),xc=s.Or("effect/Metric/MetricRegistry",{defaultValue:()=>new Map}),xp="~effect/Metric";class xh{[xp]=xp;#e;#t;#a="";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){let t=this.key(e),a=s.Jt(e,xc),l=a.get(t);return xn.b0(l)&&(l=this.metadata(this.createHooks()),a.set(t,l)),l.hooks}removeUnsafe(e){s.Jt(e,xc).delete(this.key(e))}registerUnsafe(e,t){let a=this.key(e),l=s.Jt(e,xc),i=this.metadata({get:t.get,update:xa.Yi,modify:xa.Yi});return l.set(a,i),{remove(){l.get(a)===i&&l.delete(a)}}}key(e){let t=s.Jt(e,xd);if(t!==this.#e){var a;let e;this.#e=t;let l=xk(this.attributes,t);this.#t=Object.keys(t).length>0?l:this.attributes,this.#a=(a=this,e=Object.entries(l).sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0])),JSON.stringify([a.type,a.id,a.description,e]))}return this.#a}metadata(e){return{id:this.id,type:this.type,description:this.description,attributes:this.#t,hooks:e}}pipe(){return(0,xr.tT)(this,arguments)}}let xg=BigInt(0);class xu extends xh{type="Counter";#l;#i;constructor(e,t){super(e,t?.description,xM(t?.attributes)),this.#l=t?.bigint??!1,this.#i=t?.incremental??!1}createHooks(){let e=this.#l?xg:0,t=this.#i?this.#l?e=>e>=xg:e=>e>=0:e=>!0;return xb(()=>({count:e,incremental:this.#i}),a=>{t(a)&&(e+=a)})}}class xf extends xh{type;metric;mapInput;mapContext;constructor(e,t,a){super(e.id,e.description,e.attributes),this.metric=e,this.mapInput=t,this.mapContext=a,this.type=e.type}createHooks(){return this.metric.createHooks()}valueUnsafe(e){return this.metric.valueUnsafe(this.mapContext(e))}updateUnsafe(e,t){let a=this.mapContext(t);this.metric.updateUnsafe(this.mapInput(e,a),a)}modifyUnsafe(e,t){let a=this.mapContext(t);this.metric.modifyUnsafe(this.mapInput(e,a),a)}removeUnsafe(e){xy(this.metric,this.mapContext(e))}registerUnsafe(e,t){return xw(this.metric,this.mapContext(e),{get:t.get,update:xa.Yi,modify:xa.Yi})}}let xm=(e,t)=>new xu(e,t),xv=(0,xa.XY)(2,(e,t)=>xl.sxi(a=>xl.OH5(()=>e.updateUnsafe(t,a)))),xy=(e,t)=>e.removeUnsafe(t),xw=(e,t,a)=>e.registerUnsafe(t,a),xx=(0,xa.XY)(2,(e,t)=>{var a;let l,i;return new xf(e,xa.D_,(a=t,i={},e=>{let t=s.Jt(e,xd);return t!==l&&(l=t,i=xk(t,a)),s.WQ(e,xd,i)}))});function xb(e,t,a){return{get:e,update:t,modify:a??t}}function xk(e,t){return{...xM(e),...xM(t)}}function xM(e){return xn.EA(e)&&Array.isArray(e)?e.reduce((e,[t,a])=>(xs.x(e,t,a),e),{}):e}xi.F,xi.F,xa.MN;var xz=a(3565),xC=(a(5596),a(6313),a(1677));let x_=[["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"]],xq=new Set(["artifact_count","artifact_format","artifact_kind","attempt","body_bytes","body_ms","cache_mode","duration_ms","error_category","error_tag","export_ms","failure_category","format_count","gateway_log_id","method","model","object_count","open_ms","operation","outcome","provider","queue_ms","request_kind","retry_kind","sink","status","status_code","surface","timeout_kind","timeout_ms"]),xL=([...x_.map(([,e])=>e),...xq],{metric:()=>void 0}),xS=s.Or("@sketchi/observability/TelemetryExporter",{defaultValue:()=>xL}),xB=s.Or("@sketchi/observability/TelemetryCorrelation",{defaultValue:()=>({})});function xA(e){let t=e?.trim();if(t&&!(t.length>128)&&/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(t))return t}function xP(e,t){return o.JkU(function*(){let a={...yield*xB,...function(e){let t={};for(let[a]of x_){let l=xA(e[a]);l&&(t[a]=l)}return t}(t)},l=function(e){let t={};for(let[a,l]of x_){let i=e[a];i&&(t[l]=i)}return t}(a);return yield*e.pipe(o.PfK(xB,a),o.Muk(l),o.swY(l))})}s.Or("@sketchi/observability/TelemetryResource",{defaultValue:()=>({serviceName:"sketchi"})});let xV=o.fn(function*(e,t,a={}){let l=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,l]of Object.entries(t)){let t=xA(l);t&&(a[e]=t)}return a}(a);yield*xv(xx(e,l),t);let i=yield*xS,s=xz.getOrUndefined((yield*o._32.pipe(o.uKv)));yield*o.OH5(()=>i.metric({attributes:l,metric:e.id,metricType:e.type,...s?{spanId:s.spanId,traceId:s.traceId}:{},value:t}))});xC.W1;var xH=a(2881),xI=a(8713),x$=a(4733);let xF=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"]),xO=/[A-Za-z0-9.+#]+/gu;function xE(e){return[...e.matchAll(xO)].map(([e])=>e.replace(/^\.+|\.+$/gu,"")).filter(Boolean)}function xU(e){return xE(e).map(e=>e.toLocaleLowerCase())}function xX(e){return/[0-9.+#]/u.test(e)||e.length>=3&&!xF.has(e)}function xT(e){return e.trim().toLocaleLowerCase().replace(/\s+/gu," ")}function xR(e,t){return e.some(e=>xT(e).includes(t))}function xY(e,t){let a=xT(e.slug),l=xT(e.name),i=xT(e.collection),s=xT((0,x$.y)(e.collection));return a===t?0:l.startsWith(t)?1:xR(e.aliases,t)?2:a.includes(t)||l.includes(t)||xR(e.keywords,t)?3:i.includes(t)||s.includes(t)?4:null}let xD=new Set(["cloud-platforms","cloud-vendors"]);function xG(e){return e.toLocaleLowerCase().replace(/[^a-z0-9+#]/gu,"")}let xZ=new WeakMap,xj=new Set(["app","cluster","database","db","icon","logo","server","service"]);function xN(e,t){let a=xU(t),l=[a,a.filter(e=>!xj.has(e))].map(e=>xG(e.join(""))),i=[e.slug,e.name,...e.aliases];if(i.some(e=>l.includes(xG(e))))return"exact";let s=new Set(a.flatMap((e,t)=>a.slice(t).map((e,l)=>xG(a.slice(t,t+l+1).join("")))));return i.some(e=>""!==xG(e)&&s.has(xG(e)))?"vendor":"weak"}let xW=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"]]]),xJ=new Set([...xW].flatMap(([e,t])=>[e,...t].map(xG)));function xK(e,t={}){let a=xT(t.query??""),l=t.collection?.trim(),i=Math.max(0,t.limit??1/0),s=e.flatMap(e=>{if(l&&e.collection!==l)return[];let t=function(e,t){if(0===t.length)return 5;let a=xY(e,t);if(null!==a)return a;let l=t.split(/\s+/u);if(1===l.length)return null;let i=0;for(let t of l){let a=xY(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(s.length>0?s:function(e,t,a){let l=xU(t),i=function(e){let t=xZ.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(xG))){if(!e)continue;let l=a.get(e)??[];l.push(t),a.set(e,l)}return xZ.set(e,a),a}(e),s=new Map;for(let e=Math.min(4,l.length);e>0;e-=1)for(let t=0;t+e<=l.length;t+=1){let o=l.slice(t,t+e),r=o.some(xX);for(let l of i.get(xG(o.join("")))??[]){let i=xD.has(l.collection);if(s.has(l.slug)||!r&&!i||a&&l.collection!==a)continue;let n=xY(l,o.join(" "))??6;s.set(l.slug,{icon:l,length:e,start:t,termRank:n,vendor:i})}}return[...s.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,l)).slice(0,i)}let xQ=/(?<=[.!?:])\s+|\n+/u;function x1(e){return/^[A-Z]/u.test(e)&&/[a-z]/u.test(e)}function x0(e){return/[a-z][A-Z]/u.test(e.raw)||xX(e.lower)}function x2(e){return!e.initial&&!e.titleCase&&x1(e.raw)}let x3=new WeakMap;class x5 extends i.rNF()("CodeModeIconLoadError",{cause:i.kld(),message:i.QfV,slug:i.QfV}){}function x4(e){return{collection:e.collection,name:e.name,slug:e.slug}}function x6(e){let t=e.icons.filter(xI.nC),a=new Map(t.map(e=>[e.slug,e])),l=new Map(t.map(e=>[e.slug,x4(e)]));return{get:e=>l.get(e),isStrayVendorLogo:(e,t)=>{let l,i=a.get(e);return void 0!==i&&(xD.has(i.collection)||[i.slug,i.name,...i.aliases].some(e=>xJ.has(xG(e))))&&(l=xU(t),[t,...l.flatMap((e,t)=>l.slice(t).flatMap((e,a)=>{let i=l.slice(t,t+a+1).join(" ");return xW.get(i)??[]}))]).every(e=>"weak"===xN(i,e))},logoNamedByLabel:e=>{let a=function(e,t){let[a,...l]=function(e,t,a=24){let l=function(e){let t=x3.get(e);if(t)return t;let a=new Map,l=(e,t)=>{let l=xU(e).join(" ");if(!l)return;let i=a.get(l)??[];i.includes(t)||i.push(t),a.set(l,i)};for(let t of e)for(let e of(l(t.slug.replaceAll("-"," "),t),l(t.name,t),t.aliases))l(e,t);return x3.set(e,a),a}(t),i=e.split(xQ).flatMap(e=>{let t=xE(e),a=t.filter(x1).length>=2&&t.every(e=>!/^[a-z]/u.test(e)||e.length<=3);return t.map((e,t)=>({lower:e.toLocaleLowerCase(),raw:e,initial:0===t,titleCase:a}))}),s=[],o=new Map;for(let e=0;e<i.length&&s.length<a;){let t=0;for(let a=Math.min(4,i.length-e);a>0;a-=1){let r=i.slice(e,e+a),n=l.get(r.map(e=>e.lower).join(" "));if(!n)continue;let d=r.some(x0);if(!d&&!r.some(x2))continue;let c=xK(n,{query:r.map(e=>e.lower).join(" ")})[0]?.icon,p=c?o.get(c.slug):void 0;c&&void 0===p?(o.set(c.slug,s.length),s.push({icon:c,distinctive:d})):c&&d&&void 0!==p&&(s[p]={icon:c,distinctive:d}),t=a;break}e+=Math.max(1,t)}return s}(e,t,2);return a?.distinctive&&0===l.length?a.icon:void 0}(e,t);return a?l.get(a.slug):void 0},search:(e,a)=>xK(t,{limit:a,query:e}).map(({icon:t})=>({...x4(t),match:xN(t,e)})),loadSvg:e.loadSvg,slugLookup:e.slugLookup}}function x7(e){return oe(e).toLowerCase()}function x8(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),l=new Set,i=[];for(let t of[a.join(" "),...a])if(t){for(let a of e.search(t,3))l.has(a.slug)||(l.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 x9(e,t,a={noun:"node",path:"nodes"},l={}){let i=[],s=e.map(e=>{if(!e.icon)return e;let l=x7(e.icon.slug),s={kind:"node",id:e.id,path:`${a.path}.icon.slug`},o=u(l)?t?.get(l):void 0;if(o&&!t?.isStrayVendorLogo(l,e.label))return{...e,icon:{slug:l}};i.push(o?{code:"icon_dropped",severity:"warning",stage:"input",ref:s,message:`Icon "${l}" 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.`}:x8({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:s,slug:l}));let{icon:r,...n}=e;return n});if(!l.fillNamedLogos||!t||!s.some(e=>e.icon))return{issues:i,nodes:s};let o=s.map((l,s)=>{if(e[s]?.icon)return l;let o=t.logoNamedByLabel(l.label);return o?(i.push({code:"icon_filled",severity:"info",stage:"input",ref:{kind:"node",id:l.id,path:`${a.path}.icon.slug`},message:`${a.noun[0]?.toUpperCase()}${a.noun.slice(1)} "${l.id}" draws the "${o.slug}" logo because its label "${l.label}" names ${o.name}.`,hint:"No action needed."}),{...l,icon:{slug:o.slug}}):l});return{issues:i,nodes:o}}let be=o.fn("codeMode.icons.embedScene")(function*(e,t){let a=e.elements.map(e=>("node"===e.type||"frame"===e.type)&&e.icon?{...e,icon:{...e.icon,slug:x7(e.icon.slug)}}:e),l=new Map([...new Set(a.flatMap(e=>("node"===e.type||"frame"===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([...l.values()],e=>t?t.loadSvg(e).pipe(o.qIB(t=>o.SvU({try:()=>(0,xI.Bn)(t),catch:t=>x5.make({cause:t,message:`Node logo ${e.slug} has unusable SVG.`,slug:e.slug})})),o.TjK(t=>[e.slug,{name:e.name,svg:t}]),o.KuX("CodeModeIconLoadError",e=>o.FFw("Code Mode icon asset unavailable",{error_tag:e._tag,slug:e.slug}).pipe(o.as(void 0)))):o.PyW(void 0),{concurrency:8})).flatMap(e=>e?[e]:[])),s=function(e,t){let a=new Map,l=[],i=i0(e),s=i2(e,i),o=0,r=e.elements.map((e,r)=>{if("node"!==e.type&&"frame"!==e.type||!e.icon)return e;let n=e.icon,d=t=>(l.push({elementId:e.id,index:r,reason:t,slug:n.slug}),function(e){let{icon:t,...a}=e;return a}(e)),c=a.get(n.slug),p=c??(u(n.slug)?t(n.slug):void 0);if("string"!=typeof p?.svg||iJ(p.svg)>iA.maxAssetBytes)return d("unavailable");if("node"===e.type&&e.rendererRole&&"zone"!==e.rendererRole)return d("lifeline");if("node"===e.type&&!e.rendererRole&&"polygon"!==e.shape&&i(e)){let t=s.get(e.id)?.element;if(i3(e,t,n)&&!i3(e,t,void 0))return d("no_room")}if(!c){let e=iJ(p.svg);if(o+e>iA.maxTotalAssetBytes)return d("budget");o+=e,a.set(n.slug,{name:p.name,svg:p.svg})}return e}),{icons:n,...d}=e;return{dropped:l,scene:a.size>0?{...d,elements:r,icons:Object.fromEntries(a)}:{...d,elements:r}}}({...e,elements:a},e=>i.get(e));return{issues:s.dropped.map(e=>(function(e){let{dropped:t}=e,a={kind:"element",id:t.elementId,path:`elements[${t.index}].icon${"unavailable"===t.reason?".slug":""}`},{element:l}=e,i=l?.type==="frame"||l?.type==="node"&&"zone"===l.rendererRole?"group":"node",s=`Icon "${t.slug}" on ${i} "${t.elementId}"`;if("unavailable"===t.reason&&!e.known)return x8({catalog:e.catalog,message:`${s} is not a Sketchi node logo; the ${i} renders without a logo.`,ref:a,slug:t.slug});let o=e.element?.type==="node"?i1(e.element.icon):0,r={budget:{message:`${s} exceeds the per-diagram logo budget; the ${i} 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 ${o}px taller or shorten its label to keep the logo.`},unavailable:{message:`${s} could not be loaded; the ${i} 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:r.message,hint:r.hint}})({catalog:t,dropped:e,element:a[e.index],known:l.has(e.slug)})),scene:s.scene}}),bt=/^(node|step|item|box|thing|process|task)\s*\d*$/i,ba=/^(diagram|untitled|flowchart|chart|sketch)$/i;function bl(e){return e.map(e=>({kind:"node",id:e.id}))}function bi(e){if(void 0===e)return;let t=oe(e);return t.length>0?t:void 0}let bs={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"},bo=new Set(["terminal","terminator","terminus"]),br=new Set(["database","document","queue","storage"]),bn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),bd=e=>e.trim().toLowerCase().replace(/[\s_-]+/g,""),bc=["excalidraw","scene"],bp=["scene"],bh=xm("sketchi_codemode_requests",{description:"Code Mode boundary requests by terminal outcome",incremental:!0}),bg=xm("sketchi_codemode_failures",{description:"Code Mode boundary failures by typed status",incremental:!0}),bu=xm("sketchi_codemode_artifacts",{description:"Code Mode artifacts accepted at workflow boundaries",incremental:!0}),bf=new class e extends xh{type="Histogram";#s;constructor(e,t){super(e,t?.description,xM(t?.attributes)),this.#s=t.boundaries}createHooks(){let e=this.#s,t=e.length,a=new Uint32Array(t+1),l=new Float64Array(t),i=0,s=0,o=Number.MAX_VALUE,r=-Number.MAX_VALUE;return xt.Tj(xt.di(e,xo.wN),(e,t)=>{l[t]=e}),xb(()=>({buckets:(()=>{let e=xt.CN(t),i=0;for(let s=0;s<t;s++){let t=l[s];i+=a[s],e[s]=[t,i]}return e})(),count:i,min:o,max:r,sum:s}),e=>{let n=0,d=t;for(;n!==d;){let t=Math.floor(n+(d-n)/2);e<=l[t]?d=t:n=t,d===n+1&&(e<=l[n]?d=n:n=d)}a[n]=a[n]+1,i+=1,s+=e,e<o&&(o=e),e>r&&(r=e)})}}("sketchi_codemode_duration_ms",{description:"Code Mode boundary duration in milliseconds",boundaries:(l=[1,5,10,25,50,100,250,500,1e3,2500,5e3,1e4],xt.BC(xt.pb(new Set(l),e=>e>0),1/0))});class bm extends s.kl()("@sketchi/diagram-agent/CodeModeRuntimeEnvironment"){}function bv(e={}){return n.Py(bm,{createId:e.createId??kr,...e.icons?{icons:e.icons}:{},...e.renderer?{renderer:e.renderer}:{},...e.defaultPng?{defaultPng:e.defaultPng}:{},...e.artifactUrl?{artifactUrl:e.artifactUrl}:{},...e.fillNamedLogos?{fillNamedLogos:!0}:{}})}function by(e){return null===e||"object"!=typeof e||Array.isArray(e)?void 0:Object.fromEntries(Object.entries(e))}function bw(e){return{...e,type:"timeline"}}function bx(e){return{...e,type:"chart"}}function bb(e){return{...e,type:"gantt"}}n.Py(bm,{createId:kr});let bk={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 bM(e){return{id:e.id,title:e.title,type:"sequence",participants:e.participants,messages:e.messages,style:e.style}}let bz={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"},bC={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 b_(e){return{...e,type:"state-machine"}}let bq={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 bL(e){return{...e,type:"er"}}let bS={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 bB(e){return{...e,type:"class"}}let bA={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 bP(e){return{...e,type:"org-chart"}}let bV={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"};function bH(e){return{...e,type:"sankey"}}let bI={sankey_too_large:"sankey_too_large",invalid_sankey_node_id:"invalid_sankey_node",duplicate_sankey_node_id:"duplicate_node_id",sankey_text_too_long:"label_too_long",unknown_sankey_node:"invalid_sankey_flow",sankey_self_link:"self_loop",duplicate_sankey_link:"invalid_sankey_flow",invalid_sankey_value:"invalid_sankey_flow",sankey_cycle:"sankey_cycle",unlinked_sankey_node:"invalid_sankey_node",blank_sankey_label:"missing_field"};function b$(e){return{...e,type:"venn"}}let bF={venn_set_count:"invalid_venn_set",duplicate_venn_set:"duplicate_node_id",invalid_venn_color:"invalid_venn_set",unknown_venn_set:"invalid_venn_region",duplicate_venn_region:"invalid_venn_region",invalid_venn_region:"invalid_venn_region",venn_text_too_long:"label_too_long",venn_too_large:"venn_too_large"};function bO(e){return{...e,type:"journey"}}let bE={journey_too_large:"journey_too_large",empty_journey_stage:"invalid_journey_stage",duplicate_journey_stage:"invalid_journey_stage",invalid_journey_score:"invalid_journey_step",unknown_journey_actor:"invalid_journey_step",duplicate_journey_actor:"invalid_journey_step",journey_text_too_long:"label_too_long",unplaced_journey_entry:"invalid_journey_stage"};function bU(e){let t={};for(let[a,l]of Object.entries(e))if(void 0!==l)if("children"===a&&Array.isArray(l))t[a]=l.map(bU);else if("string"==typeof l){let e=oe(l);e&&(t[a]=e)}else Array.isArray(l)?t[a]=l.map(e=>"string"==typeof e?oe(e):e):t[a]=l;return t}function bX(e){return{...e,screens:e.screens.map(e=>({...e,children:e.children})),type:"wireframe"}}let bT={wireframe_too_large:"wireframe_too_large",invalid_screen_id:"invalid_screen",duplicate_screen_id:"duplicate_node_id",empty_wireframe_screen:"invalid_screen",unknown_wireframe_target:"missing_edge_target",empty_wireframe_container:"invalid_component",missing_wireframe_text:"invalid_component",wireframe_text_too_long:"label_too_long",invalid_wireframe_option:"invalid_component"};function bR(e){return{...e,type:"quadrant"}}let bY={quadrant_too_large:"quadrant_too_large",invalid_quadrant_point:"invalid_quadrant_point",invalid_quadrant_text:"invalid_quadrant_text"};function bD(e){return e.map(e=>kn({code:bY[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}))}class bG extends i.rNF()("CodeModeArtifactRenderFailed",{cause:i.kld(),message:i.QfV}){}class bZ extends i.rNF()("CodeModeArtifactRendererNotConfigured",{message:i.QfV}){}let bj=i._kM({issues:i.O31(i.O3D(oT)).pipe(i.fXn)});class bN extends i.rNF()("ArtifactExportFailure",{status:i.uSQ("export_failed"),issues:bj.fields.issues}){}class bW extends i.rNF()("ArtifactStorageFailure",{status:i.uSQ("storage_failed"),cause:i.kld(),issues:bj.fields.issues}){}function bJ(e,t,a){class l 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 l}let bK=bJ("BuildFlowchartFailure",d1.fields.status,d1.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),bQ=bJ("BuildMindmapFailure",d2.fields.status,d2.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b1=bJ("BuildSequenceDiagramFailure",d5.fields.status,d5.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b0=bJ("BuildStateMachineFailure",ce.fields.status,ce.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b2=bJ("BuildErDiagramFailure",ci.fields.status,ci.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b3=bJ("BuildClassDiagramFailure",co.fields.status,co.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b5=bJ("BuildOrgChartFailure",cn.fields.status,cn.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b4=bJ("BuildVennDiagramFailure",cc.fields.status,cc.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b6=bJ("BuildJourneyMapFailure",ch.fields.status,ch.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b7=bJ("BuildSankeyFailure",cu.fields.status,cu.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b8=bJ("BuildWireframeFailure",cm.fields.status,cm.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),b9=bJ("BuildTimelineFailure",d6.fields.status,d6.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),ke=bJ("BuildQuadrantChartFailure",cy.fields.status,cy.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),kt=bJ("BuildChartFailure",d8.fields.status,d8.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),ka=bJ("BuildGanttFailure",ca.fields.status,ca.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),kl=bJ("CreateCanvasFailure",cz.fields.status,cz.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),ki=bJ("GetArtifactFailure",cx.fields.status,cx.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),ks=bJ("SearchIconsFailure",cP.fields.status,cP.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields}))),ko=bJ("ApplyDiagramPatchFailure",ck.fields.status,ck.mapFields(({ok:e,status:t,...a})=>({...a,...bj.fields})));function kr(e){return`${e}_${globalThis.crypto.randomUUID()}`}function kn(e){return{code:e.code,severity:e.severity??"error",stage:e.stage,...e.ref?{ref:e.ref}:{},message:e.message,hint:e.hint}}function kd(e){return 0===e.length?"input":e.map(e=>"number"==typeof e?`[${e}]`:String(e)).join(".")}function kc(e){let t=kd(e.path);return kp(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 kp(e){return/^operations\.\[\d+\]\.op$/.test(e)}function kh(e){return kp(e)?`Use one of: ${oD.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 kg=/^spec\.nodes\.\[\d+\]\.kind$/;function ku(e){return kg.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).':kh(e)}function kf(e,t=kh){let a=e.issues.slice(0,20).map(e=>{let a=kd(e.path);return kn({code:kc(e),stage:"input",ref:{kind:"request",path:a},message:e.message,hint:t(a)})});return e.issues.length>20&&a.push(kn({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 km(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)}function kv(e){if(void 0===e)return;let t=oe(e);return t.length>0?t:void 0}function ky(e){return e.checks.map(e=>{var t;return kn({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 kw(e){return e?.artifactFormats??bc}function kx(e){return e?.inlineArtifacts??bp}let kb=o.fn("codeMode.artifacts.exportFormats")(function*(e){let t=[];for(let l of e.formats){var a;let i;if("png"===l&&e.defaultPng){let t=e.defaultPng.deadlineMillis-(yield*r.Ru);if(t<=0){e.defaultPng.onUnavailable("Default PNG delivery budget exhausted.");continue}let a=yield*kk(e,l).pipe(o.wRz(t),o.Ket);if(xH.N6(a)){e.defaultPng.onUnavailable("TimeoutError"===a.failure._tag?"Default PNG rendering exceeded its delivery budget.":a.failure.message);continue}i=a.success}else i=yield*kk(e,l);t.push({format:l,mimeType:c$[l],data:i,sizeBytes:(a=i)instanceof ArrayBuffer||a instanceof Uint8Array?a.byteLength:cE(a)})}return t});function kk(e,t){return"scene"===t?o.PyW(e.scene):"excalidraw"===t?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??{}}}(e.excalidraw)):e.renderer?e.renderer.renderPng({scene:e.scene,excalidraw:e.excalidraw}).pipe(o.xm_(e=>bG.make({cause:e,message:e.message}))):o.fJG(bZ.make({message:"PNG artifact rendering is not configured for this runtime."}))}function kM(e){return e.map(e=>kn({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 kz(e){return e.slice(0,20).map(e=>kn({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 kC(e){return kM(e.filter(e=>"overlapping-arrow-segment"!==e.code&&"arrow-segment-through-node"!==e.code))}function k_(e){let t=[];for(let h of e.elements){if("arrow"===h.type){let e=h.points[0],a=h.points[1],l=h.points.slice(2);if(!e||!a)return null;let i=[e,a,...l];t.push({...h,type:"arrow",id:h.id,edgeId:h.edgeId,sourceNodeId:h.sourceNodeId,targetNodeId:h.targetNodeId,...h.strokeColor?{strokeColor:h.strokeColor}:{},...h.strokeStyle?{strokeStyle:h.strokeStyle}:{},...h.textColor?{textColor:h.textColor}:{},points:i,...h.label?{label:h.label}:{}});continue}if("node"===h.type){var a,l,i,s,o,r,n,d,c,p;let g=h.points;if("polygon"===h.shape&&(!g||!g[0]||!g[1]||!g[2]))return null;t.push({type:"node",id:h.id,nodeId:h.nodeId,...h.kind?{kind:h.kind}:{},...h.icon?{icon:{slug:h.icon.slug,size:h.icon.size}}:{},shape:h.shape,...h.fillColor?{fillColor:h.fillColor}:{},...h.strokeColor?{strokeColor:h.strokeColor}:{},x:h.x,y:h.y,width:h.width,height:h.height,label:h.label,...h.frameId?{frameId:h.frameId}:{},...h.groupIds?{groupIds:[...h.groupIds]}:{},...h.layerId?{layerId:h.layerId}:{},...void 0!==h.locked?{locked:h.locked}:{},...void 0!==h.opacity?{opacity:h.opacity}:{},...void 0!==h.zIndex?{zIndex:h.zIndex}:{},...h.fillStyle?{fillStyle:h.fillStyle}:{},...void 0!==h.roughness?{roughness:h.roughness}:{},...h.strokeStyle?{strokeStyle:h.strokeStyle}:{},...void 0!==h.strokeWidth?{strokeWidth:h.strokeWidth}:{},..."sequence-lifeline"===h.rendererRole&&mp(e,h)||"sequence-activation"===h.rendererRole&&function(e,t){let a=`${eF}:activation:`,l=t.nodeId.indexOf(a);if(l<=0||l+a.length===t.nodeId.length||t.id!==`node:${t.nodeId}`||"rectangle"!==t.shape||12!==t.width)return!1;let i=t.nodeId.slice(0,l+eF.length),s=e.elements.find(e=>"node"===e.type&&e.id===`node:${i}`&&e.nodeId===i);if(!s||!mp(e,s))return!1;let o=s.x+s.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>=s.y-.01&&t.y+t.height<=s.y+s.height+.01}(e,h)||"timeline-marker"===h.rendererRole&&(a=h).nodeId.startsWith("event:")&&a.id===`node:${a.nodeId}`&&a.height<=18&&void 0===a.icon||"chart-mark"===h.rendererRole&&(l=h).nodeId.startsWith("chart:")&&l.id===`node:${l.nodeId}`&&void 0===l.icon||"journey-mark"===h.rendererRole&&(i=h).nodeId.startsWith("journey:face:")&&i.id===`node:${i.nodeId}`&&void 0===i.icon||"quadrant-mark"===h.rendererRole&&(s=h).nodeId.startsWith("quadrant:")&&s.id===`node:${s.nodeId}`&&void 0===s.icon||"gantt-mark"===h.rendererRole&&((o=h).nodeId.startsWith("gantt:task:")||o.nodeId.startsWith("gantt:progress:"))&&o.id===`node:${o.nodeId}`&&void 0===o.icon||"state-marker"===h.rendererRole&&void 0!==(r=h).kind&&ms[r.kind]===r.shape&&void 0===r.icon||"er-table"===h.rendererRole&&"rectangle"===(n=h).shape&&void 0===n.icon&&n.id===`node:${n.nodeId}`||"er-optional"===h.rendererRole&&("circle"===(d=h).shape||"ellipse"===d.shape)&&void 0===d.icon&&d.nodeId.includes(":optional:")&&24>=Math.max(d.width,d.height)||"class-box"===h.rendererRole&&"rectangle"===(c=h).shape&&void 0===c.icon&&c.id===`node:${c.nodeId}`||"venn-set"===h.rendererRole&&/^venn:set:\d+(?::fill)?$/u.test(h.nodeId)&&h.id===`node:${h.nodeId}`&&"ellipse"===h.shape&&void 0===h.icon||"sankey-mark"===h.rendererRole&&(p=h).nodeId.startsWith("sankey:")&&p.id===`node:${p.nodeId}`&&void 0===p.icon||("swimlane"===h.rendererRole||"swimlane-header"===h.rendererRole)&&"rectangle"===h.shape&&!h.icon||"zone"===h.rendererRole&&"rectangle"===h.shape||("wireframe-widget"===h.rendererRole||"wireframe-region"===h.rendererRole)&&!h.icon?{rendererRole:h.rendererRole}:{},...h.textColor?{textColor:h.textColor}:{},..."polygon"===h.shape&&g?.[0]&&g[1]&&g[2]?{points:[g[0],g[1],g[2],...g.slice(3)]}:{}});continue}if("line"===h.type){let e=h.points[0],a=h.points[1];if(!e||!a)return null;t.push({...h,points:[e,a,...h.points.slice(2)]});continue}t.push(structuredClone(h))}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 kq(e){let{icons:t,...a}=e;return a}function kL(e){return structuredClone(e)}function kS(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 kB(e){return e.elements.filter(e=>"node"===e.type)}function kA(e){return e.elements.filter(e=>"text"===e.type)}function kP(e){return e.elements.filter(e=>"arrow"===e.type)}function kV(e,t){if(!e||0===e.length||!t)return!1;let a=t.trim().toLowerCase();return e.some(e=>e.trim().toLowerCase()===a)}function kH(e,t){let a=t?.scope??"all",l=!!(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??[]),s=new Set(t?.nodeIds??[]),o=new Set(t?.edgeIds??[]),r=new Set(t?.kinds??[]),n=kB(e).filter(e=>"edges"!==a&&(!t||!l||i.has(e.id)||s.has(e.nodeId)||!!e.kind&&[...r].some(t=>t===e.kind)||kV(t.labels,e.label))),d=kP(e).filter(e=>"nodes"!==a&&(!t||!l||i.has(e.id)||o.has(e.edgeId)||kV(t.labels,e.label))),c=new Set(n.map(e=>e.id)),p=new Set(d.map(e=>e.id));return{arrows:d,nodes:n,texts:kA(e).filter(e=>t&&l?i.has(e.id)||!!e.containerId&&c.has(e.containerId)||!!e.containerId&&p.has(e.containerId)||kV(t.labels,e.text):"nodes"===a?!!e.containerId&&c.has(e.containerId):"edges"!==a||!!e.containerId&&p.has(e.containerId))}}function kI(e){return kn({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 k$(e,t){return kA(e).find(e=>e.containerId===t||e.id===`${t}:label`)}function kF(e,t){let a=k$(e,t.id),l=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 l=t.points.find(t=>t.x!==e.x||t.y!==e.y);if(!l)return;let i=iS(a.text,a.maxWidth??160,a.fontSize),s=iq(i,a.fontSize,a.maxWidth??160),o=Math.ceil(i.split("\n").length*a.fontSize*1.35);a.x=(e.x+l.x)/2+(e.x===l.x?s/2+8:0),a.y=(e.y+l.y)/2-(e.y===l.y?o/2+5:0);return}a&&l&&(a.x=l.x,a.y=l.y)}function kO(e,t){let a=new Set(t);for(let t of kP(e))(a.has(t.sourceNodeId)||a.has(t.targetNodeId))&&kX(e,t)}function kE(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function kU(e,t,a){let l=kE(e),i=kE(t),s=i.x-l.x,o=i.y-l.y;return 0===s&&0===o?{x:l.x,y:"source"===a?e.y+e.height:e.y}:Math.abs(s)>Math.abs(o)?s>=0?{x:e.x+e.width,y:l.y}:{x:e.x,y:l.y}:o>=0?{x:l.x,y:e.y+e.height}:{x:l.x,y:e.y}}function kX(e,t){let a=new Map(kB(e).map(e=>[e.nodeId,e])),l=a.get(t.sourceNodeId),i=a.get(t.targetNodeId);if(!l||!i)return[kn({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=sl(l,i).map(e=>({...e})),kF(e,t),[];let s=kU(l,i,"source"),o=kU(i,l,"target");if(Math.abs(o.y-s.y)>=Math.abs(o.x-s.x)){let e=(s.y+o.y)/2;t.points=[s,{x:s.x,y:e},{x:o.x,y:e},o]}else{let e=(s.x+o.x)/2;t.points=[s,{x:e,y:s.y},{x:e,y:o.y},o]}return kF(e,t),[]}function kT(e){let t=e.width,a=e.height;for(let l of e.elements)if("arrow"===l.type||"line"===l.type)for(let e of l.points)t=Math.max(t,e.x),a=Math.max(a,e.y);else"text"===l.type?(t=Math.max(t,l.x+(l.maxWidth??0)),a=Math.max(a,l.y+l.fontSize)):(t=Math.max(t,l.x+l.width),a=Math.max(a,l.y+l.height));e.width=t+48,e.height=a+48}function kR(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 kY(e,t){return[kn({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 kD=o.fn("codeMode.patch.resolveSource")(function*(e){if("scene"in e.source)return{scene:kL(e.source.scene)};let t=yield*cI,a=yield*t.readManifest(e.source.artifactId).pipe(o.xm_(e=>new ko({status:"storage_failed",context:{issues:[cT(e.message,"storage_read_failed")]}})));if(!a||a.artifactId!==e.source.artifactId||!a.formats.some(e=>"scene"===e.format))return yield*new ko({status:"source_unavailable",context:{issues:[kn({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 l=yield*t.read(e.source.artifactId,"scene").pipe(o.xm_(e=>new ko({status:"storage_failed",context:{issues:[cT(e.message,"storage_read_failed")]}})));if(!l)return yield*new ko({status:"source_unavailable",context:{issues:[kn({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 s=i.q$Z(dt,{errors:"all",reportInput:!0})(l.data);return xH.oJ(s)?{scene:kL(s.success),sourceArtifactId:e.source.artifactId}:yield*new ko({status:"source_unavailable",context:{issues:[kn({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 kG(e){return e?{requestId:e}:{}}function kZ(e){let t=kq(e);return{diagramId:e.diagramId,formats:[{format:"scene",mimeType:c$.scene,inline:t,sizeBytes:cE(t)}]}}function kj(e){return{ok:!1,status:e.status,...e.context}}function kN(e,t){return cT(e.message,t)}let kW=o.fn("codeMode.artifacts.exportAndStore")(function*(e){let t=yield*bm,a=yield*cI,{excalidraw:l,validation:i}=yield*o.OH5(()=>{let t=function(e){let t,a,l,i,s,o,r,n=(t=new Map(e.layers.map(e=>[e.id,e])),l=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]:[])),s=new Set((i=a.filter(e=>"arrow"!==e.type||l.has(e.sourceNodeId)&&l.has(e.targetNodeId))).flatMap(e=>"text"===e.type?[]:[e.id])),r=new Set((o=i.filter(e=>"text"!==e.type||!e.containerId||s.has(e.containerId))).map(e=>e.id)),o.map(e=>{let a=e.layerId?t.get(e.layerId):void 0,{frameId:l,...i}=e;return{...e.frameId&&!r.has(e.frameId)?i:e,...a?.locked===!0?{locked:!0}:{}}})),{textElements:d,generatedLabelSourceIds:c}=function(e){let t=e.filter(pp),a=e.filter(ph),l=new Set(e.map(e=>e.id)),i=new Map,s=new Set(a.flatMap(e=>e.containerId?[e.containerId]:[]));for(let e of t){if(s.has(e.id)||e.rendererRole)continue;let t=`__sketchi_node_label__${e.id}`,o=t,r=2;for(;l.has(o);)o=`${t}:${r}`,r+=1;l.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(c),g=function(e,t,a,l,i){let s=t.filter(pp),o=new Set([...t.map(e=>e.id),...a.map(e=>e.id)]),r=new Map,n=new Map;for(let e of a)e.containerId&&n.set(e.containerId,e);let d=t.filter(pg),c=t.filter(pu),p=function(e,t,a,l){let i=new Map,s=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=s.get(t);a&&i.set(a,[...i.get(a)??[],e.id])}for(let e of l)for(let t of[e.startBinding,e.endBinding])t&&i.set(t.elementId,[...i.get(t.elementId)??[],e.id]);return i}(s,t.filter(pf),d,c),h=new Map,g=[];for(let t of s){let a=n.get(t.id),s=function(e){let t=e.shape.height,a="circle"===e.shape.shape?"ellipse":e.shape.shape,l=[...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{...pl(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 iV(e.shape.shape)?{...pl(e.shape.id,e.shape),groupIds:[pr(e.shape),...e.shape.groupIds??[]],type:"rectangle",x:e.shape.x,y:e.shape.y,width:e.shape.width,height:t,backgroundColor:"transparent",boundElements:l.length>0?l:null,customData:{sketchiShape:e.shape.shape},roundness:null,strokeColor:"transparent"}:{...pl(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:l.length>0?l:null,roundness:iD(e.shape)?"wireframe-widget"===e.shape.rendererRole?{type:3,value:8}:{type:3}:null,strokeColor:e.shape.strokeColor??e.scene.accentColor,...e.shape.rendererRole?{customData:{sketchiRendererRole:e.shape.rendererRole}}:{}}}({scene:e,shape:t,arrowIds:p.get(t.id)??[],...a?{text:a}:{}});if(h.set(t.nodeId,s),g.push(s),iV(t.shape)){let a=function(e){let{shape:t}=e;if(!iV(t.shape))return[];let a={...t,shape:t.shape};return[...t.fillColor?[{fill:t.fillColor,points:iX(a),smooth:!1}]:[],...(function(e){let{x:t,y:a,width:l,height:i}=e,s=iH[e.shape];if("document"===e.shape)return[{points:[{x:t,y:a+i},{x:t,y:a},{x:t+l,y:a},{x:t+l,y:a+i}],smooth:!1},{points:iO(e,s),smooth:!0}];let o=iF(e,s,"pipe"!==e.shape,12,"bucket"===e.shape?iI(l):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,l)=>{let[i]=a.points,s=a.points.map(e=>e.x),o=a.points.map(e=>e.y);return{...pl(e.id(l),t),groupIds:[pr(t),...t.groupIds??[]],type:"line",x:i.x,y:i.y,width:Math.max(...s)-Math.min(...s),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 l=`${e.id}:stroke-${t}`,i=l,s=2;for(;a.has(i);)i=`${l}-${s}`,s+=1;return a.add(i),i})(t,e,o),scene:e,shape:t});for(let e of a)i.set(e.id,t.id);g.push(...a),r.set(t.id,t)}let d=t.icon&&e.icons&&Object.hasOwn(e.icons,t.icon.slug)?e.icons[t.icon.slug]:void 0;if(!t.icon||"string"!=typeof d?.svg)continue;let c=ps(t.icon.slug,d.svg),u=pm(t,o),f=pn({fileId:c,id:u,node:t});f&&(l[c]??=po(c,d.svg),s.groupIds=[pr(t),...t.groupIds??[]],i.set(u,t.id),r.set(t.id,t),g.push(f))}for(let a of t.filter(pf)){var u;let t={...pl((u={element:a,scene:e}).element.id,u.element),type:"frame",x:u.element.x,y:u.element.y,width:u.element.width,height:u.element.height,backgroundColor:u.element.fillColor??"transparent",boundElements:null,name:u.element.name??null,roundness:null,strokeColor:u.element.strokeColor??u.scene.accentColor},s=p.get(a.id)??[];t.boundElements=s.length?s.map(e=>({id:e,type:"arrow"})):null,void 0!==a.nodeId&&h.set(a.nodeId,t),g.push(t);let r=a.icon&&e.icons&&Object.hasOwn(e.icons,a.icon.slug)?e.icons[a.icon.slug]:void 0;if(!a.icon||"string"!=typeof r?.svg)continue;let n=ps(a.icon.slug,r.svg),d=pm(a,o),c=pn({fileId:n,id:d,node:a});c&&(l[n]??=po(n,r.svg),i.set(d,a.id),g.push(c))}for(let e of a){let t=s.find(t=>t.id===e.containerId&&"polygon"!==t.shape),a=d.some(t=>t.id===e.containerId),l=d.find(t=>e.id===`${t.id}:label`),i=e.containerId&&(t||a),o=e.textColor??l?.textColor,n=pi({...t?{container:t}:{},element:e,id:e.id,...i?{containerId:e.containerId}:{},fontSize:e.fontSize,maxWidth:e.maxWidth??160,...o?{textColor:o}:{},text:e.text,wrap:a||!!l,x:e.x,y:e.y}),c=t?r.get(t.id):void 0;c&&(n.groupIds=[pr(c),...e.groupIds??[]]),g.push(n)}for(let t of d){let l=n.get(t.id)??a.find(e=>e.id===`${t.id}:label`);g.push(function(e){let t=e.arrow.points[0],a=pd(e.arrow),l=!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{...pl(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:l,endArrowhead:void 0===e.arrow.endArrowhead?"arrow":e.arrow.endArrowhead,endBinding:pa(e.targetShape,a),...l?{fixedSegments:[],startIsSpecial:null,endIsSpecial:null}:{},points:e.arrow.points.map(e=>[e.x-t.x,e.y-t.y]),roundness:l?null:{type:2},startArrowhead:e.arrow.startArrowhead??null,startBinding:pa(e.sourceShape,t),strokeColor:e.arrow.strokeColor??e.scene.accentColor,strokeStyle:e.arrow.strokeStyle??"solid"}}({arrow:t,scene:e,sourceShape:h.get(t.sourceNodeId),targetShape:h.get(t.targetNodeId),...l?{text:l}:{}}));let i=t.label&&!l?function(e){if(!e.arrow.label)return null;let t=e.arrow.points[0],a=pd(e.arrow);return pi({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&&g.push(i)}let f=new Map(g.map(e=>[e.id,e]));for(let t of c)if(g.push(function(e){let[t,...a]=e.element.points,l=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,s=i&&e.element.points.length>2;return{...pl(e.element.id,e.element),type:i?"arrow":"line",x:t.x,y:t.y,width:l.x-t.x,height:l.y-t.y,backgroundColor:e.element.fillColor??"transparent",boundElements:null,...i?{elbowed:s}:{},endArrowhead:e.element.endArrowhead??null,endBinding:pc(e.element.endBinding,e.elementsById,l),...s?{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&&!s?{type:2}:null,startArrowhead:e.element.startArrowhead??null,startBinding:pc(e.element.startBinding,e.elementsById,t),strokeColor:e.element.strokeColor??e.scene.accentColor}}({element:t,elementsById:f,scene:e})),t.label){let e=t.points[0],a=t.points[t.points.length-1]??e;g.push(pi({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 g}(e,n,d,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,l){if(void 0!==l){var i=l;if(!c5.has(i)){if(i.length<2||i.length%2!=0||!c0(i))throw Error("intDigits must be an even number of at least 2 characters in strictly ascending character code order: "+i);if(!c2(i))throw Error("intDigits must be single-byte (char code 0-255): "+i);c5.add(i)}}else l=a??cY;if(void 0!==a){var s=a;if(!c3.has(s)){if(s.length<2||!c0(s))throw Error("digits must be at least 2 characters in strictly ascending character code order: "+s);if(!c2(s))throw Error("digits must be single-byte (char code 0-255): "+s);c3.add(s)}}else a=cR;let o=cG(a),r=cG(l);if(null!=e&&cJ(e,a,l,r),null!=t&&cJ(t,a,l,r),null!=e&&null!=t&&e>t){let a=e;e=t,t=a}if(null==e){if(null==t)return l[l.length/2]+a[0];let e=cW(t,l,r),i=t.slice(e.length);if(c1(e,a,l))return e+cZ("",i,a,o);if(e<t)return e;let s=function(e,t,a,l,i){cj(e,l,i);let s=e[0],o=t[t.length-1],r="";for(let l=e.length-1;l>=1;l--){let i=a[e.charCodeAt(l)]-1;if(-1!==i)return s+e.slice(1,l)+t[i]+r;r=o+r}let n=i[s.charCodeAt(0)];if(0===n)return null;let d=l[n-1],c=cN(d,l,i)-cN(s,l,i);return d+(c>0?r+o:c<0?r.slice(1):r)}(e,a,o,l,r);if(null==s)throw Error("cannot decrement any more");return s}if(null==t){let t=cW(e,l,r),i=e.slice(t.length),s=cK(t,a,o,l,r);return null==s?t+cZ(i,null,a,o):s}let n=cW(e,l,r),d=e.slice(n.length),c=cW(t,l,r),p=t.slice(c.length);if(n===c)return n+cZ(d,p,a,o);let h=cK(n,a,o,l,r);if(null==h)throw Error("cannot increment any more");return h<t?h:n+cZ(d,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])),l=new Set(e.elements.filter(pw).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 s 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[s]||void 0===i[s])continue;let o=pv(i,s);if(!(o&&l.has(o))){t.push({code:"missing-arrow-binding",elementId:i.id,message:`Arrow "${i.id}" has invalid ${s}.`});continue}let r=a.get(o);r&&!function(e,t,a){let l=e.boundElements;return!!Array.isArray(l)&&l.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=c7(e.x)??0,l=c7(e.y)??0,i=Array.isArray(e.points)?e.points.map(c8).filter(e=>!!e):[],s="startBinding"===t?i[0]:i[i.length-1];return s?{x:a+s[0],y:l+s[1]}:null}(i,s);if(r&&n&&!function(e,t){let a=c9(t);if(!a)return!1;let l=t.customData&&"object"==typeof t.customData?t.customData.sketchiShape:void 0;if("string"==typeof l&&iV(l))return iU({...a,shape:l},e);if("diamond"===t.type){let t=a.width/2,l=a.height/2;if(0===t||0===l)return!1;let i=a.x+t,s=a.y+l;return pk(Math.abs(e.x-i)/t+Math.abs(e.y-s)/l,1)}if("ellipse"===t.type){let t=a.width/2,l=a.height/2;if(0===t||0===l)return!1;let i=a.x+t,s=a.y+l;return pk(((e.x-i)/t)**2+((e.y-s)/l)**2,1)}let i=(pk(e.x,a.x)||pk(e.x,a.x+a.width))&&pb(e.y,a.y,a.y+a.height),s=(pk(e.y,a.y)||pk(e.y,a.y+a.height))&&pb(e.x,a.x,a.x+a.width);return i||s}(n,r)&&t.push({code:"arrow-endpoint-off-shape",elementId:i.id,message:`Arrow "${i.id}" ${s} endpoint does not land on "${r.id}".`}),r&&n&&e){let e=function(e,t){let a=e[t];return a&&"object"==typeof a?c8(a.fixedPoint):null}(i,s);e&&function(e,t,a){let l=c9(a);if(!l)return!1;let i=1e-4>Math.abs(e[0]-.5001)?.5:e[0],s=1e-4>Math.abs(e[1]-.5001)?.5:e[1];return pk(l.x+i*l.width,t.x)&&pk(l.y+s*l.height,t.y)}(e,n,r)||t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Elbow arrow "${i.id}" has invalid ${s} fixedPoint metadata.`})}}}if("text"===i.type){let e=i.containerId;if("string"!=typeof e)continue;let l=a.get(e);if(!l){t.push({code:"missing-container",elementId:i.id,message:`Text "${i.id}" references missing container "${e}".`});continue}let s=("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 l.width?l.width:0,n="number"==typeof l.height?l.height:0;pw(l)&&(s+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(py),a=e.filter(pw),l=new Map(e.map(e=>[e.id,c9(e)])),i=new Map(e.map((e,t)=>[e.id,t])),s=new Map(e.flatMap(e=>"string"==typeof e.frameId?[[e.id,e.frameId]]:[])),o=[],r=new Set;for(let e of t){let t=a.filter(t=>px(t,e,l));for(let n of a){if(function(e){let t=e.customData;if(null===t||"object"!=typeof t)return!1;let a=t.sketchiRendererRole;return iR.some(e=>e===a)}(n)||function(e,t,a,l){let i=a.get(e.id);return!!i&&t.some(t=>{var s;let o=a.get(t.id);return t.id!==e.id&&"frame"!==(s=t).type&&"string"==typeof s.backgroundColor&&"transparent"!==s.backgroundColor&&("number"!=typeof s.opacity||s.opacity>0)&&null!=o&&(l.get(t.id)??0)>(l.get(e.id)??0)&&i.x>=o.x&&i.y>=o.y&&i.x+i.width<=o.x+o.width&&i.y+i.height<=o.y+o.height})}(n,t,l,i)||n.id===e.startBindingId||n.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)}(n,e,s)||px(n,e,l))continue;let a=c9(n);if(!a||!sn(e,a))continue;let d=`${e.arrowId}:${e.segmentIndex}:${n.id}`;r.has(d)||(r.add(d),o.push({code:"arrow-segment-through-node",elementId:e.arrowId,message:`Arrow "${e.arrowId}" passes through shape "${n.id}".`}))}}return o}(e.elements)),t.push(...function(e){let t=e.filter(e=>"arrow"===e.type).flatMap(py),a=[],l=new Set;for(let e=0;e<t.length;e+=1){let i=t[e];if(i)for(let s=e+1;s<t.length;s+=1){let e=t[s];if(!e||i.arrowId===e.arrowId||function(e,t){if(!sd(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 l=e.route[a],i=t.route[a];if(!l||!i||Math.abs(l.x-i.x)>.01||Math.abs(l.y-i.y)>.01)return!1}return Math.sign(e.endCoordinate-e.startCoordinate)===Math.sign(t.endCoordinate-t.startCoordinate)}(i,e)||function(e,t){let[a,l]=[e.route.at(-1),t.route.at(-1)];if(null===e.endBindingId||e.endBindingId!==t.endBindingId||!a||!l||Math.abs(a.x-l.x)>.01||Math.abs(a.y-l.y)>.01)return!1;let i=e=>e.route.slice(e.segmentIndex).every(t=>"horizontal"===e.orientation?.01>=Math.abs(t.y-e.route[e.segmentIndex].y):.01>=Math.abs(t.x-e.route[e.segmentIndex].x));return i(e)&&i(t)&&Math.sign(e.endCoordinate-e.startCoordinate)===Math.sign(t.endCoordinate-t.startCoordinate)}(i,e)||!sr(i,e))continue;let o=[i.arrowId,String(i.segmentIndex),e.arrowId,String(e.segmentIndex)].sort().join(":");l.has(o)||(l.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")),s=e.validationIssues(i.issues);if(s.length>0)return yield*new bN({status:"export_failed",issues:s});let r=yield*kb({formats:e.formats,scene:e.scene,excalidraw:l,renderer:t.renderer,defaultPng:t.defaultPng}).pipe(o.xm_(e=>new bN({status:"export_failed",issues:[kn({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 d=yield*xP(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 bW({status:"storage_failed",cause:e,issues:[kN(e,"storage_write_failed")]}))),c=t.artifactUrl;if(!c)return d;let p=d.formats.map(e=>({...e,url:c({artifactId:d.artifactId,format:e.format})}));return{...d,formats:p}}),kJ=o.fn("codeMode.buildMindmap.workflow")(function*(e){var t,a;let l,s,r,n,d,c,p,h,g,u=function(e){let t=by(by(by(e)?.spec)?.root);if(!t)return[];let a=[{depth:0,topic:t}],l=1;for(;a.length>0;){let e=a.pop();if(!e)continue;if(e.depth>8)return[kn({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((l+=t.length)>100)return[kn({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 l=t.length-1;l>=0;l-=1){let i=by(t[l]);i&&a.push({depth:e.depth+1,topic:i})}}}return[]}(e);if(u.length>0)return yield*new bQ({status:"invalid_mindmap",context:{issues:u}});let f=i.q$Z(nE,{errors:"all",reportInput:!0})(e);if(!xH.oJ(f))return yield*new bQ({status:"invalid_input",context:{issues:kf(os(f.failure))}});let m=yield*bm,v=f.success,w=yield*o.OH5(()=>m.createId("build")),x=(t=v.spec,l=(e,t)=>({id:`topic-${t.join("-")}`,label:oe(e.label),children:(e.children??[]).map((e,a)=>l(e,[...t,a]))}),s=oe(t.title),{id:kv(t.id)??(km(s)||"sketchi-mindmap"),title:s,root:l(t.root,[0]),layout:{direction:t.layout.direction},style:{...y}}),b={buildId:w,...kG(v.requestId),normalizedSpec:x},k=(r=0,n=0,(d=(e,t)=>{r+=1,n=Math.max(n,t),e.children.forEach(e=>d(e,t+1))})(x.root,0),p=[],(c={count:r,depth:n}).count<2&&p.push(kn({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."})),c.depth>8&&p.push(kn({code:"mindmap_too_deep",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:`Mindmap depth ${c.depth} exceeds the supported maximum of 8.`,hint:"Combine overly deep topics into a shallower hierarchy."})),c.count>100&&p.push(kn({code:"mindmap_too_large",stage:"mindmap",ref:{kind:"diagram",id:x.id},message:`Mindmap has ${c.count} topics; the supported maximum is 100.`,hint:"Split this hierarchy into smaller focused mindmaps."})),p);if(k.length>0)return yield*new bQ({status:"invalid_mindmap",context:{...b,issues:k}});let M=yield*o.SvU({try:()=>{var e;let t,a,l;return e={id:x.id,title:x.title,root:x.root,direction:x.layout.direction,style:y},t=[],a=[],(l=(e,i,s)=>{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}),s&&a.push({id:`branch-${o}`,source:s,target:`topic-${o}`,metadata:n}),e.children?.forEach((e,t)=>l(e,[...i,t],`topic-${o}`))})(e.root,[0]),eV({id:e.id,title:e.title,type:e_,nodes:t,edges:a,layout:{direction:e.direction??"LR",edgeRouting:"curved"},...e.style?{style:{...e.style}}:{}})},catch:e=>new bQ({status:"invalid_mindmap",context:{...b,issues:[kn({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."})]}})}),z=(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}]}))}),C={...b,quality:z};if(!z.accepted)return yield*new bQ({status:"quality_failed",context:{...C,issues:ky(z)}});let _=yield*o.SvU({try:()=>{let e,t,a,l,i,s,o,r,n,d,c,p,h,g,u,f,m;return l=Math.round(40-Math.min(...(a=function(e,t){let a=a=>{var l;let i,s,o,r,n,d,c,p,h,g,u,f,m,v,y,w,x,b,k,M,z,C,_,q;return s=function(e){let t=e.length,a=1/0,l=Math.ceil(e.length/2);for(let i=1;i<=e.length;i+=1){let s=Math.abs(gc(e.slice(0,i))-gc(e.slice(i)));(s<a-1e-6||1e-6>=Math.abs(s-a)&&Math.abs(i-l)<Math.abs(t-l))&&(t=i,a=s)}return t}(i=e.children.map(e=>(function e(t,a){let l={x0:0,x1:t.width,y0:-t.height/2,y1:t.height/2};if(0===t.children.length)return gn([l],new Map([[t.id,{x:0,y:0}]]),new Set);let i=t.depth>=a,s=t.depth<=1?14:8,o=t.children.map(t=>e(t,a)),r=48*!!i,n=i?[l]:[],d=[];for(let e of o){let t=e.boxes.map(e=>gr(e,r,0)),a=d.length>0?sc(n,t,s,8):i?Math.max(sc(n,t,12,8),l.y1+12-e.top):0;d.push(a),n.push(...t.map(e=>gr(e,0,a)))}let c=d[0],p=d.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-c)),u=i?0:(c+p)/2,f=new Map([[t.id,{x:0,y:0}]]);o.forEach((e,t)=>{for(let[a,l]of e.places)f.set(a,{x:l.x+r+g,y:l.y+d[t]-u})});let m=i?{x0:20,x1:r,y0:l.y1,y1:p}:{x0:t.width,x1:g,y0:c-u,y1:p-u};return gn([l,m,...(i?n.slice(1):n).map(e=>gr(e,g,-u))],f,h)})(e,a))),r=(o=i.map((e,t)=>t)).slice(0,s),n=o.slice(s).toReversed(),d=r.map(e=>i[e]),c=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)))(d)+u(c),m=Math.max(e.height,gc(d),gc(c)),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=d.length<=1&&c.length<=1?function(e,t,a,l){let i=a=>{let i=[[-l/2,l/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))},s=0,o=(Math.max(e??0,t??0)+l)/2+28;if(i(o)<=a)return o;if(i(s)>=a)return 0;for(let e=0;e<24;e+=1){let e=(s+o)/2;i(e)<a?s=e:o=e}return o}(x(d),x(c),w,e.height):0,M=[],(k=(e,a,l)=>{var i;let s,o,r=t=>Math.max(0,t-gc(e))/(e.length-1),n=e.length>1?Math.max(Math.min(120,r(v)),r(w)):0,d=(s=[],o=l-gc(e,i=y>0?n:0)/2,e.forEach((t,a)=>{a>0&&(o+=gd(e[a-1],t)+i),s.push(o-t.top),o+=t.bottom-t.top}),s);return e.map((e,l)=>({block:e,side:t?-a:a,y:d[l],inner:g}))})(d,1,-b).forEach((e,t)=>M[r[t]]=e),k(c,-1,b).forEach((e,t)=>M[n[t]]=e),z=Math.max(...M.map(e=>Math.abs(e.y))),l=M.map(e=>{if(0===z)return e;let t=.6*(e.y/z)**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)}}),_=[C={topic:e,parent:void 0,branch:-1,side:1,folded:!1,x:-e.width/2,y:-e.height/2}],q=(e,t,a,l)=>{let i=a.block.places.get(e.id),s=a.inner+i.x,o={topic:e,parent:t,branch:l,side:a.side,folded:-1!==t.branch&&a.block.folded.has(t.topic.id),x:1===a.side?s:-s-e.width,y:a.y+i.y-e.height/2};for(let t of(_.push(o),e.children))q(t,o,a,l)},e.children.forEach((e,t)=>q(e,C,l[t],t)),_},l=a(1/0);for(let t=function e(t){return Math.max(t.depth,...t.children.map(e))}(e)-1;t>=1&&!(gp(l)<=2.4+.01);t-=1){let e=a(t);gp(e)<gp(l)&&(l=e)}return l}(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])),l=(e,i)=>{let s=a.get(e),{fontSize:o,textWidth:r,padX:n,padY:d}=go(i),c=function(e,t,a){let l=e=>e.split("\n").length,i=iS(e,t,a);if(1===l(i))return i;let s=a,o=t;for(;o-s>1;){let t=Math.floor((s+o)/2);l(iS(e,t,a))<=l(i)?o=t:s=t}return iS(e,o,a)}(s.label,r,o),p=Math.ceil(Math.max(iC(c,o),i_(c,o,r))),h=Math.ceil(c.split("\n").length*o*1.35),g=0===i?function(e,t){let a=Math.ceil((e+36)*Math.SQRT2),l=Math.ceil((t+20)*Math.SQRT2);for(;iQ({shape:"ellipse",width:a,height:l}).width<e+18;)a+=1;for(;iQ({shape:"ellipse",width:a,height:l}).height<t+10;)l+=1;return{width:a,height:l}}(p,h):{width:p+2*n,height:h+2*d};return{id:e,depth:i,text:c,fontSize:o,...g,children:(t.get(e)??[]).toSorted((e,t)=>e.index-t.index).map(e=>l(e.id,i+1))}};return l(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))),s=e.style.accentColor,o=e.style.backgroundColor,r=e=>-1===e.branch?s:pT[e.branch%pT.length],n=e=>-1===e.branch?{}:{groupIds:[`branch:${t.children[e.branch].id}`]},d=a.map(e=>{var t;let a,{topic:s}=e,d=[.18,.16,.06][s.depth];return{type:"node",id:`node:${s.id}`,nodeId:s.id,kind:0===s.depth?"root":"topic",shape:0===s.depth?"ellipse":"rectangle",x:Math.round(e.x)+l,y:Math.round(e.y)+i,width:s.width,height:s.height,label:s.text,strokeColor:r(e),strokeWidth:go(s.depth).strokeWidth,...void 0===d?{}:{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))*d).toString(16).padStart(2,"0")).join("")}`),fillStyle:"solid"},...n(e)}}),c=a.map((e,t)=>({type:"text",id:`label:${e.topic.id}`,containerId:d[t].id,x:d[t].x+e.topic.width/2,y:d[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(d.map(e=>[e.nodeId,e])),h=function(e,t){let a=e.width/2,l=e.height/2,i=new Map;for(let s of[1,-1]){let o=t.filter(e=>e.side===s).map(t=>{let i=gu(t.shape,s),o=Math.atan2((i.y-e.y-l)/l,s*(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}(d[0],a.flatMap((e,t)=>1===e.topic.depth?[{shape:d[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,l=g.get(a.id),i=function(e,t,a,l){let i=a.side,s=gu(e,i);if(void 0!==l){let e=t.width/2,a=t.height/2,o={x:t.x+e+i*e*Math.cos(l),y:t.y+a+a*Math.sin(l)};return gg([o,{x:o.x+.4*(s.x-o.x),y:o.y+.4*(s.y-o.y)},{x:s.x-.5*i*Math.abs(s.x-o.x),y:s.y},s])}if(a.folded){let e={x:1===i?t.x+20:t.x+t.width-20,y:t.y+t.height};return gg([e,{x:e.x,y:e.y+.5*(s.y-e.y)},{x:s.x-.5*i*Math.abs(s.x-e.x),y:s.y},s])}let o={x:1===i?t.x+t.width:t.x,y:t.y+t.height/2},r=.5*Math.abs(s.x-o.x);return gg([o,{x:o.x+i*r,y:o.y},{x:s.x-i*r,y:s.y},s])}(d[t],p.get(e.parent.topic.id),e,h.get(a.id));return[{type:"arrow",id:`edge:${l}`,edgeId:l,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(...d.map(e=>e.x+e.width)),m=Math.max(...d.map(e=>e.y+e.height)),{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:f+40,height:m+40,accentColor:s,backgroundColor:o,elements:[...u,...d,...c],layers:[],layouts:[],zOrder:[...u,...d,...c].map(e=>e.id)}},catch:e=>new bQ({status:"render_failed",context:{...C,issues:[kn({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")),q={...C,partial:kZ(_)},L=yield*kW({scene:_,formats:kw(v.options),inlineFormats:kx(v.options),...v.requestId?{requestId:v.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new bQ({status:e.status,context:{..."export_failed"===e.status?q:{...C,partial:{diagramId:_.diagramId}},issues:e.issues}})));return{ok:!0,status:"accepted",buildId:w,...kG(v.requestId),normalizedSpec:x,quality:z,artifact:L,issues:[]}}),kK=o.fn("codeMode.buildSequenceDiagram.workflow")(function*(e){var t,a;let l,s=i.q$Z(nn,{errors:"all",reportInput:!0})(e);if(!xH.oJ(s))return yield*new b1({status:"invalid_input",context:{issues:kf(os(s.failure))}});let r=yield*bm,n=s.success,d=yield*o.OH5(()=>r.createId("build")),c=(l=oe((t=n.spec).title),{id:kv(t.id)??(km(l)||"sketchi-sequence"),title:l,participants:t.participants.map(e=>({id:oe(e.id),label:oe(e.label),...e.kind?{kind:oe(e.kind)}:{},...e.icon?{icon:{slug:e.icon.slug}}:{}})),messages:t.messages.map((e,t)=>({id:kv(e.id)??`message-${t+1}-${km(e.source)}-${km(e.target)}`,source:oe(e.source),target:oe(e.target),label:oe(e.label),...e.type?{type:e.type}:{},...e.style?{style:e.style}:{}})),style:{...y}}),p=x9(c.participants,r.icons,{noun:"participant",path:"participants"},{fillNamedLogos:!0===r.fillNamedLogos}),h={...c,participants:p.nodes},g={buildId:d,...kG(n.requestId),normalizedSpec:h},u=eD(bM(h)).map(e=>kn({code:bz[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:bC[e.code]??e.hint}));if(u.length>0)return yield*new b1({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 b1({status:"quality_failed",context:{...m,issues:ky(f)}});let v=yield*o.SvU({try:()=>(function(e){let t=eZ(e),a=new Map(t.participants.map(e=>[e.id,iS(e.label,156,14)])),l=Math.max(180,...[...a.values()].map(e=>Math.ceil(iC(e,14))+24)),i=l+140,s=t.participants.reduce((e,t)=>Math.max(e,Math.ceil(14*(a.get(t.id)??t.label).split("\n").length*1.35)+18+i1(t.icon?{slug:t.icon.slug,size:28}:void 0)),72),o=48+s,r=o+64,n=new Map(t.messages.flatMap(e=>{let t;return e.source===e.target?[[e.id,{width:iq(t=iS(e.label,160,13),13,160),height:Math.ceil(13*t.split("\n").length*1.35)}]]:[]})),d=e=>{let t=n.get(e);return t?Math.max(32,t.height):0},c=[],p=r;for(let e of t.messages)c.push(p),p+=88+d(e.id);let h=t.messages.at(-1),g=(h?(c.at(-1)??r)+d(h.id):r)-o+56,u=function(e){let t=new Map,a=[];e.messages.forEach((e,l)=>{if(e.source===e.target)return;if("return"!==e.type)return void t.set(e.target,[...t.get(e.target)??[],{caller:e.source,index:l,messageId:e.id}]);let i=t.get(e.source)??[],s=i.findLastIndex(t=>t.caller===e.target),o=i[s];o&&(t.set(e.source,i.filter((e,t)=>t!==s)),a.push({participantId:e.source,callMessageId:o.messageId,returnMessageId:e.id,startIndex:o.index,endIndex:l}))});let l=[];for(let e of a.toSorted((e,t)=>e.startIndex-t.startIndex)){let t=l.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;l.push({...e,depth:i})}return l}(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 l,i=n.get(t.id);if(!i||t.source!==e.id)return[];let s=f(e.id,a);return[((l="return"===t.type?s:s+1)<0?1:6*l+6)+32+10+i.width+6+24]}))),v=new Map,y=[],w=[],x=[],b=48+l/2;t.participants.forEach((e,r)=>{let n=b,d=n-l/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:d,y:48,width:l,height:s,label:a.get(e.id)??e.label}),w.push({type:"text",id:`label:${e.id}`,containerId:`node:${e.id}`,x:n,y:48+s/2,text:a.get(e.id)??e.label,fontSize:14,maxWidth:l-24,...e.icon?{verticalAlign:"bottom"}:{}}),x.push({type:"node",id:`node:${eO(e.id)}`,nodeId:eO(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=>c[e]??r,M=new Map(t.participants.map(e=>[e.id,e.label])),z=(e,a,l,i,s)=>{let o=`${eO(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*l,y:i,width:12,height:s-i,label:`${M.get(e)??e} active`}},C=u.map(e=>({activation:e,node:z(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,l=k(t)+d(e.id);return[[e.id,z(e.source,e.id,a,l-12,l+12)]]})),q=(e,t,a,l)=>{let i=v.get(e)??0,s=l>i,o=C.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:s?r.node.x+r.node.width:r.node.x}:{nodeId:eO(e),x:i+(s?1:-1)*2/2}},L=t.participants.map(e=>v.get(e.id)??0),S=[],B=t.messages.map((e,t)=>{let a,l,i,s,o;if(e.source===e.target){let a,l,i,s,o,r,c;return a=q(e.source,t,e.id,1/0),i=(l=_.get(e.id))?{nodeId:l.nodeId,x:l.x+l.width}:a,s=Math.max(a.x,i.x)+32,r=(o=k(t))+d(e.id),c=[`message:${e.id}`],S.push({type:"text",id:`arrow:${e.id}:label`,text:e.label,fontSize:13,x:s+10+(n.get(e.id)?.width??0)/2,y:(o+r)/2,maxWidth:160,groupIds:c}),{type:"arrow",id:`arrow:${e.id}`,edgeId:e.id,groupIds:c,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:s,y:o},{x:s,y:r},{x:i.x,y:r}],label:e.label}}let r=v.get(e.source)??0,c=v.get(e.target)??0,p=q(e.source,t,e.id,c),h=q(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+c)/2,l=Math.sign(c-r),i=L.findIndex(e=>100>Math.abs(e-a)&&Math.min(r,c)<e&&e<Math.max(r,c)),s=L[i],o=L[i-l],void 0===s||void 0===o?[]:[{x:(s+o)/2,y:g}]),{x:h.x,y:g}],label:e.label}}),A=Math.max(0,...B.flatMap(({edgeId:e,points:t})=>{let a=n.get(e);return a&&t[1]?[t[1].x+10+a.width]:[]})),P=[...C.map(({node:e})=>e),..._.values()],V=[...B,...S,...x,...P,...y,...w],H=[...x.map(e=>e.id),...P.map(e=>e.id),...y.map(e=>e.id),...w.map(e=>e.id),...B.map(e=>e.id),...S.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:t.id,title:t.title,width:Math.max((L.at(-1)??48)+l/2+48,Math.ceil(A)+48),height:o+g+48,accentColor:t.style.accentColor,backgroundColor:t.style.backgroundColor,elements:V,layers:[],layouts:[],zOrder:H}})(bM(h)),catch:e=>new b1({status:"render_failed",context:{...m,issues:[kn({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*be(v,r.icons),x=w.scene,b=i5(x);if(b.length>0)return yield*new b1({status:"render_failed",context:{...m,issues:kz(b).map(e=>({...e,hint:"Reduce participant label lines, participants, or messages and retry buildSequenceDiagram."}))}});let k={...m,partial:kZ(x)},M=yield*kW({scene:x,formats:kw(n.options),inlineFormats:kx(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b1({status:e.status,context:{..."export_failed"===e.status?k:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:d,...kG(n.requestId),normalizedSpec:h,quality:f,artifact:M,issues:[...p.issues,...w.issues]}}),kQ=o.fn("codeMode.buildStateMachine.workflow")(function*(e){var t,a;let l,s,r=i.q$Z(nh,{errors:"all",reportInput:!0})(e);if(!xH.oJ(r))return yield*new b0({status:"invalid_input",context:{issues:kf(os(r.failure))}});let n=yield*bm,d=r.success,c=yield*o.OH5(()=>n.createId("build")),p=(l=oe((t=d.spec).title),s=(e,t)=>t&&oe(t)?{[e]:oe(t)}:{},{id:kv(t.id)??(km(l)||"sketchi-state-machine"),title:l,initial:oe(t.initial),states:t.states.map(e=>{let t=oe(e.id),a=e6({...e,id:t});return{id:t,...void 0!==a?{label:a}:{},...e.kind?{kind:e.kind}:{},...s("parent",e.parent),...void 0!==e.initial?{initial:oe(e.initial)}:{}}}),transitions:t.transitions.map((e,t)=>({id:kv(e.id)??`transition-${t+1}-${km(e.source)}-${km(e.target)}`,source:oe(e.source),target:oe(e.target),...s("event",e.event),...s("guard",e.guard),...s("action",e.action)})),...t.layout?{layout:{direction:t.layout.direction}}:{},style:{...y}}),h=p.states.flatMap((e,t)=>{let a=e7(e,p.states);return void 0===e.initial&&void 0!==a?[{code:"composite_initial_defaulted",severity:"warning",path:`states.[${t}].initial`,message:`Composite "${e.id}" has no initial; defaulted to its first listed regular substate "${a}".`,hint:`Set initial on "${e.id}" explicitly if "${a}" is not the intended entry.`}]:[]}).map(e=>kn({...e,stage:"input",ref:{kind:"request",path:`spec.${e.path}`}})),g=e8(p),u={buildId:c,...kG(d.requestId),normalizedSpec:g},f=tt(b_(g)).map(e=>kn({code:bq[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new b0({status:"invalid_state_machine",context:{...u,issues:f}});let m={accepted:10>=(a=d.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:g.states.length,edgeCount:g.transitions.length},checks:[]},v={...u,quality:m};if(!m.accepted)return yield*new b0({status:"quality_failed",context:{...v,issues:ky(m)}});let w=yield*o.SvU({try:()=>(function(e){let t=t=>mc(function(e,t){let a=e9(e),l=(e,t,a,l)=>({id:e,label:t,kind:a,metadata:{},...l?{group:l}:{}}),i=(e,t,a,l)=>({id:e,source:t,target:a,metadata:{},...l?{label:l}:{}}),s=new Set(e.transitions.map(e=>e.id)),o=e=>{let t=e;for(let a=2;s.has(t);a+=1)t=`${e}~${a}`;return s.add(t),t},r=[l(mh,"","initial")],n=[i(o(mh),mh,e.initial)],d=new Map,c=new Map;for(let t of e.states){if("final"!==e5(t)||void 0!==e6(t))continue;let a=e.transitions.filter(e=>e.target===t.id),l=a.map((e,a)=>0===a?t.id:`${t.id}:${a+1}`);a.forEach((e,t)=>d.set(e.id,l[t])),c.set(t.id,l.length>0?l:[t.id])}for(let t of e.states){let s=t.parent;if(a.has(t.id)){let a=e7(t,e.states);void 0!==a&&(r.push(l(`${t.id}${mh}`,"","initial",t.id)),n.push(i(o(`${t.id}${mh}`),`${t.id}${mh}`,a)));continue}let d=e5(t),p=e6(t);if("final"===d&&void 0===p){for(let e of c.get(t.id))r.push(l(e,"","final",s));continue}if("final"===d){r.push(l(t.id,p,"state",s)),r.push(l(`${t.id}:end`,"","final",s)),n.push(i(o(`${t.id}:end`),t.id,`${t.id}:end`));continue}r.push(l(t.id,p??"",d,s))}for(let t of e.transitions){let e=function(e){let t=e.guard?te(e.guard,/^\s*\[|\]\s*$/gu):"",a=e.action?te(e.action,/^\s*\//u):"";return[e.event?.trim(),t&&`[${t}]`,a&&`/ ${a}`].filter(Boolean).join(" ")}(t);n.push(i(t.id,t.source,d.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:e6(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,l=t(e);return{aspect:Math.max(l.width/l.height,l.height/l.width),cost:fY(a=l.elements.filter(e=>"arrow"===e.type))+sL(a.map(e=>({id:e.id,points:e.points,sourceId:e.sourceNodeId,targetId:e.targetNodeId})),sx({width:l.width,height:l.height})).length,scene:l}}),l=a.filter(e=>e.aspect<=2.2),[i]=l.length>0?l.toSorted((e,t)=>e.cost-t.cost):a.toSorted((e,t)=>e.aspect-t.aspect);return i.scene})(b_(g)),catch:e=>new b0({status:"render_failed",context:{...v,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.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")),x=i5(w);if(x.length>0)return yield*new b0({status:"render_failed",context:{...v,issues:kz(x).map(e=>({...e,hint:"Shorten state labels or split the machine and retry buildStateMachine."}))}});let b={...v,partial:kZ(w)},k=yield*kW({scene:w,formats:kw(d.options),inlineFormats:kx(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b0({status:e.status,context:{..."export_failed"===e.status?b:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...kG(d.requestId),normalizedSpec:g,quality:m,artifact:k,issues:h}}),k1=o.fn("codeMode.buildErDiagram.workflow")(function*(e){var t,a;let l,s,r,n,d=i.q$Z(nf,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:function(e){if(!tI(e))return e;let t=Array.isArray(e.entities)?e.entities.map(e=>tI(e)&&Array.isArray(e.fields)?{...e,fields:e.fields.map(e=>"string"==typeof e?tP(e):e)}:e):e.entities,a=Array.isArray(e.relationships)?e.relationships.map(e=>{if(!tI(e))return e;let{source:t,target:a,cardinality:l,...i}=e,s=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=>tH(/^m$|^n$/u.test(e)?"many":e);return[a(t[0]),a(t[1])]}(l),o={...i,from:i.from??t,to:i.to??a,fromCardinality:tH(i.fromCardinality??s?.[0]),toCardinality:tH(i.toCardinality??s?.[1])};for(let e of["from","to","fromCardinality","toCardinality"])void 0===o[e]&&delete o[e];return void 0!==l&&void 0===s&&(o.cardinality=l),o}):e.relationships;return{...e,...void 0===t?{}:{entities:t},...void 0===a?{}:{relationships:a}}}(e.spec)}:e);if(!xH.oJ(d))return yield*new b2({status:"invalid_input",context:{issues:kf(os(d.failure))}});let c=yield*bm,p=d.success,h=yield*o.OH5(()=>c.createId("build")),g=(l=oe((t=p.spec).title),s=(e,t)=>t&&oe(t)?{[e]:oe(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.relationships.flatMap(e=>kv(e.id)??[])),{id:kv(t.id)??(km(l)||"sketchi-er-diagram"),title:l,entities:t.entities.map(e=>({id:oe(e.id),...s("name",e.name),fields:e.fields.map(e=>{let t="string"==typeof e?tP(oe(e)):e;return{name:oe(t.name),...s("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:kv(e.id)??(e=>{let t=e+1;for(;n.has(`relationship-${t}`);)t+=1;return n.add(`relationship-${t}`),`relationship-${t}`})(t),from:oe(e.from),to:oe(e.to),fromCardinality:e.fromCardinality,toCardinality:e.toCardinality,...s("label",e.label)})),style:{...y}}),u={buildId:h,...kG(p.requestId),normalizedSpec:g},f=tL(bL(g)).map(e=>kn({code:"missing_relationship_entity"===e.code&&e.path.endsWith(".from")?"missing_edge_source":bS[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new b2({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 b2({status:"quality_failed",context:{...v,issues:ky(m)}});let w=yield*o.SvU({try:()=>(function(e){let t=new Map(e.entities.map(e=>[e.id,mB(e)])),{scene:a,candidate:{tables:l,links:i}}=function(e,t,a){let l,i=e.entities.length>24?mR.slice(0,2):mR,s=new Set;for(let o of i){let i=mW(t,a,o),r=JSON.stringify([...i.boxes,...i.sides]);if(s.has(r))continue;s.add(r);let n={tables:t,links:a,placement:i,option:o,spill:!1,packed:!1},d=mN(e,n),c=mY(d),p=l?c:c-.75;if((!l||p<l.score)&&(l={cost:c,score:p,scene:d,candidate:n}),0===c)break}let o=l,r={...l.candidate,spill:!0};if(mE(mT(r.links,r.placement),r.placement.boxes)){let t=mN(e,r);mY(t)<l.cost&&(o={scene:t,candidate:r})}for(let t of[!1,!0]){let a=function(e,t){let a=t;for(let l=0;l<2;l+=1){let l=mj(a),i=function(e,t){let a,l=new Map;for(let e of t){let{entity:t,row:a}=e.link[e.end];if(void 0===a||"top"===e.side)continue;let i=`${t}\0${e.side}\0${a.index}`;l.set(i,(l.get(i)??0)+1)}for(let t of e.values()){let{entity:i,growth:s}=t,o=e=>Math.max(...["left","right"].map(t=>l.get(`${i.id}\0${t}\0${e}`)??0)),r=i.fields.map((e,t)=>Math.max(s.rows[t]??0,o(t)>2?(o(t)-1)*28:0)),n=i.fields.length-1,d=r[n]??0,c=d>0?d/2:(Math.max(1,o(n))-1)*22/2,p=(28+d)/2+6,h=Math.max(s.foot,n<0?0:2*Math.ceil(Math.max(0,c+16-p)/2));h===s.foot&&r.every((e,t)=>e===(s.rows[t]??0))||(a??=new Map(e)).set(i.id,mB(i,{rows:r,foot:h}))}return a}(a.tables,l);if(!i)break;let s=e.relationships.map(e=>mA(e,i)),o={...t.option,arrangement:t.placement.arrangement},r=function(e,t,a){let l=mO(e),i=e=>`${e.link[e.end].entity}\0${e.row}`,s=new Map;for(let e of l)s.set(i(e[0]),Math.max(s.get(i(e[0]))??0,e.length,e[0].lines));let o=new Map;for(let r of l){let l=s.get(i(r[0]));if(l<=2||r.length<2)continue;let n=mU(r,e,t),d=(e,t)=>o.set(`${e.link.relationship.id}:${e.end}`,t);if(a)r.length>2&&[...n.ups,...n.levels,...n.downs].forEach((e,t)=>d(e,(t-(r.length-1)/2)*22));else for(let[e,t]of mX(n,l))d(e,(t-(l-1)/2)*28)}return o}(l,a.placement.boxes,t.packed);a={...t,tables:i,links:s,placement:mW(i,s,o,r)}}return a}(e,{...o.candidate,packed:t});if(a.tables===o.candidate.tables)break;let l=mN(e,a);if(function(e,t){let[a,l]=[mJ(e),mJ(t)];return Object.keys(a).every(e=>a[e]<=l[e]+1e-9)}(l,o.scene))return{scene:l,candidate:a}}return o}(e,t,e.relationships.map(e=>mA(e,t))),s=new Map(a.elements.flatMap(e=>"node"===e.type?[[e.nodeId,e]]:[])),o=e.entities.map(t=>(function(e,t,a){let{id:l}=e.entity,i=[`table:${l}`],s={type:"node",id:`node:${l}`,nodeId:l,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:${l}:header`,nodeId:`${l}: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:${l}: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,s=28*e.entity.fields.length,o=[...e.rows.values()],n=(r,n,d,c,p)=>{let h=(e,t,a)=>({type:"text",id:e,x:d+c/2,y:a,text:t,fontSize:14,lineHeight:2,maxWidth:c,textAlign:"left",...p?{textColor:p}:{},groupIds:i});return e.growth.rows.some(e=>e>0)?o.flatMap(e=>n[e.index]?[h(`text:${l}:${r}:${e.index}`,n[e.index],t.y+e.middle)]:[]):[h(`text:${l}:${r}`,n.join("\n"),a+s/2)]},d=t.x+14;e.keyWidth>0&&(r.push(...n("keys",e.keys,d,e.keyWidth,"#6a4e5c")),d+=e.keyWidth+8),r.push(...n("fields",e.names,d,e.nameWidth)),e.typeWidth>0&&r.push(...n("types",e.types,d+e.nameWidth+16,e.typeWidth,"#6f6656"))}return{nodes:[s,o,...[...e.rows.values()].flatMap(a=>{if((e.growth.rows[a.index]??0)===0)return[];let s=0===a.index?42:a.top,o=a.index===e.entity.fields.length-1?e.height-2:a.top+a.height;return[{type:"node",id:`node:${l}:row:${a.index}`,nodeId:`${l}:row:${a.index}`,kind:"entity-key-row",rendererRole:"er-table",shape:"rectangle",x:t.x+2,y:t.y+s,width:e.width-4,height:o-s,label:e.names[a.index],fillColor:mC,fillStyle:"solid",strokeColor:mC,strokeWidth:1,roughness:0,groupIds:i}]})],texts:r}})(l.get(t.id),s.get(t.id),e)),r=new Map(i.map(e=>[e.relationship.id,e])),n=[],d=e=>n.some(t=>14>Math.hypot(t.x-e.x,t.y-e.y)),c=a.elements.flatMap(t=>{if("arrow"!==t.type)return[];let a=r.get(t.edgeId);for(let[i,s]of[["start",a.parent],["end",a.child]]){var l;if("zero-or-one"!==(l=s.cardinality)&&"zero-or-many"!==l)continue;let[a,o]="start"===i?[t.points[0],t.points[1]]:[t.points.at(-1),t.points.at(-2)],r=Math.hypot(o.x-a.x,o.y-a.y),c=mK(t,i,s.entity,n.length,e);for(let a=46;d(c)&&a+12<=r;a+=14)c=mK(t,i,s.entity,n.length,e,a);n.push(c)}return[{...t,startArrowhead:m_[a.parent.cardinality],endArrowhead:m_[a.child.cardinality]}]}),p=a.elements.filter(e=>"text"===e.type&&void 0===e.containerId),h=[...o.flatMap(e=>[...e.nodes,...e.texts]),...c,...n,...p];return{...a,elements:h,zOrder:h.map(e=>e.id)}})(bL(g)),catch:e=>new b2({status:"render_failed",context:{...v,issues:[kn({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=i5(w);if(x.length>0)return yield*new b2({status:"render_failed",context:{...v,issues:kz(x).map(e=>({...e,hint:"Shorten entity or field names, or split the schema, and retry buildErDiagram."}))}});let b={...v,partial:kZ(w)},k=yield*kW({scene:w,formats:kw(p.options),inlineFormats:kx(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b2({status:e.status,context:{..."export_failed"===e.status?b:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...kG(p.requestId),normalizedSpec:g,quality:m,artifact:k,issues:[]}}),k0=o.fn("codeMode.buildClassDiagram.workflow")(function*(e){var t,a;let l,s,r,n,d=i.q$Z(nv,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:ad(e.spec)}:e);if(!xH.oJ(d))return yield*new b3({status:"invalid_input",context:{issues:kf(os(d.failure))}});let c=yield*bm,p=d.success,h=yield*o.OH5(()=>c.createId("build")),g=(l=oe((t=p.spec).title),s=(e,t)=>t&&oe(t)?{[e]:oe(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.relationships.flatMap(e=>kv(e.id)??[])),{id:kv(t.id)??(km(l)||"sketchi-class-diagram"),title:l,classes:t.classes.map(e=>({id:oe(e.id),...s("name",e.name),...e.kind?{kind:e.kind}:{},...s("stereotype",e.stereotype),attributes:e.attributes.map(e=>{let t="string"==typeof e?ai(oe(e)):e;return{name:oe(t.name),...s("type",t.type),...t.visibility?{visibility:t.visibility}:{},...r("static",t.static)}}),methods:e.methods.map(e=>{let t="string"==typeof e?as(oe(e)):e;return{name:oe(t.name),params:t.params.map(e=>{let t="string"==typeof e?aa(oe(e)):e;return{name:oe(t.name),...s("type",t.type)}}),...s("returns",t.returns),...t.visibility?{visibility:t.visibility}:{},...r("static",t.static),...r("abstract",t.abstract)}})})),relationships:t.relationships.map((e,t)=>({id:kv(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:oe(e.from),to:oe(e.to),...s("fromMultiplicity",e.fromMultiplicity),...s("toMultiplicity",e.toMultiplicity),...s("fromRole",e.fromRole),...s("toRole",e.toRole),...void 0===e.navigable?{}:{navigable:e.navigable},...s("label",e.label)})),style:{...y}}),u={buildId:h,...kG(p.requestId),normalizedSpec:g},f=t7(bB(g)).map(e=>kn({code:"missing_relationship_class"===e.code&&e.path.endsWith(".from")?"missing_edge_source":bA[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new b3({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 b3({status:"quality_failed",context:{...v,issues:ky(m)}});let w=yield*o.SvU({try:()=>(function(e){let t=new Map(e.classes.map(e=>[e.id,function(e){let t,a=tQ(e).trim(),l=(t=[t0[t1(e)],e.stereotype?.trim()].filter(e=>"string"==typeof e&&e.length>0)).length>0?`\xab${t.join(", ")}\xbb`:void 0,i=e.attributes.map(t3),s=e.methods.map(t5),o=Math.max(iC(a,16),l?iC(l,16):0,...[...i,...s].map(e=>iC(e,14))),r=(l?2:1)*22+20,[n,d]=[ve(i),ve(s)];return{node:e,name:a,heading:l?`${l}
426
426
  ${a}`:a,width:Math.max(140,Math.ceil(o)+24),height:r+n+d,band:r,attributesHeight:n,methodsHeight:d,attributes:i,methods:s}}(e)])),{scene:a,labels:l}=function(e,t){let a,l=e.relationships.map(e=>({id:e.id,from:e.from.trim(),to:e.to.trim(),generalization:tY(e.kind),whole:"composition"===e.kind||"aggregation"===e.kind,fromLabel:Math.max(0,...vt(e,"from").map(va)),toLabel:Math.max(0,...vt(e,"to").map(va)),label:e.label?va(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]}}),s=e.classes.length>20?vs.slice(0,2):vs,o=new Set,r=({scene:e})=>vd(e)>2.4,n=({scene:e})=>Math.max(e.width,e.height),d=(e,t)=>r(t)&&!r(e)&&n(e)<=n(t)&&Object.keys(e.counts).every(a=>e.counts[a]<=t.counts[a]);for(let n of[...s,vo]){if(n===vo&&(s!==vs||!r(a)))break;let c=m8(i,l,n),p=JSON.stringify([...c.boxes,...c.anchors]);if(o.has(p))continue;o.add(p);let h=vi(e,t,c),g=vr(h),u={cost:vn(h,g),counts:g,scene:h};if((!a||n!==vo&&u.cost<a.cost-.75||d(u,a))&&(a=u),0===u.cost&&!r(a))break}let c=t=>({...t,labels:function(e,t,a){let l=a.map(e=>({left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})),i=t.flatMap(e=>ss(e.points).map(t=>({owner:e.edgeId,segment:t}))),s=i.map(e=>e.segment),o=[],r=e=>l.filter(t=>vh(e,t,3)).length+s.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+o.filter(t=>vh(e,t,3)).length,n=e=>0===r(e),d=()=>n,c=(e,t)=>{let a={x:(va(e)-iC(e,13))/2,y:e.split("\n").length*(18-17.55)/2};return{left:t.left+a.x,top:t.top+a.y,right:t.right-a.x,bottom:t.bottom-a.y}},p=(e,t)=>a=>{if(!n(a))return!1;let l=c(t,a),[s,o]=[1/0,1/0];for(let t of i){let a=function(e,t){let[a,l,i,s]="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.left-l,a-e.right),Math.max(0,e.top-s,i-e.bottom))}(l,t.segment);t.owner===e?s=Math.min(s,a):o=Math.min(o,a)}return o>=Math.max(1.5*s,s+8)},h=[],g=0,u=(e,t,a,l)=>{o.push(a),h.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,...l?{groupIds:[l]}:{}})},f=new Map(t.map(e=>[e.edgeId,e])),m=(e,t,a,l,i)=>e.slice(0,-1).flatMap((s,o)=>[...function*(e,t,a,l,i,s){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],d=Math.abs(r)>.5?a:l;for(let t=s;t+d<=Math.max(o,s+d);t+=6){for(let s of i)if(Math.abs(r)>.5){let i=r>0?e.x+t:e.x-t-a,o=s<0?e.y-10+4-l:e.y+10-4;yield{left:i,top:o,right:i+a,bottom:o+l}}else{let i=n>0?e.y+t:e.y-t-l,o=s>0?e.x+10:e.x-10-a;yield{left:o,top:i,right:o+a,bottom:i+l}}if(t+d>=o)break}}(s,e[o+1],t,a,l,0===o?i:6)]);for(let t of e.relationships){let e=f.get(t.id);if(e)for(let a of["from","to"]){let l=vt(t,a);if(0===l.length)continue;let i="from"===a?e.points:e.points.toReversed(),[s,r]=[i[0],i.at(-1)],h="from"===a?e.sourceNodeId:e.targetNodeId,f=[t["from"===a?"fromMultiplicity":"toMultiplicity"]&&"multiplicity",t["from"===a?"fromRole":"toRole"]&&"role"].filter(e=>"string"==typeof e),v=(e,t,a)=>{let i=[];for(let[s,r]of l.entries()){let l=m(e,va(r),18,t(s),4).find(a(r));if(!l)break;i.push(l),o.push(l)}return o.splice(o.length-i.length,i.length),i.length===l.length?i:void 0},y=e=>t=>{let a=c(e,t),[l,i]=[vg(a,s),vg(a,r)];return 110>=Math.hypot((a.left+a.right)/2-s.x,(a.top+a.bottom)/2-s.y)&&i>=Math.max(1.5*l,l+8)},w=e=>{let t=y(e);return e=>n(e)&&t(e)},x=e=>{let[a,l]=[p(t.id,e),y(e)];return e=>a(e)&&l(e)},b=2===l.length?[e=>[0===e?1:-1],e=>[0===e?-1:1],()=>[1],()=>[-1]]:[()=>[1,-1]],k=2===l.length?[[1,-1],[-1,1]]:[[1],[-1]],M=function(e){let t=e.slice(1).map((t,a)=>Math.hypot(t.x-e[a].x,t.y-e[a].y)),a=t.reduce((e,t)=>e+t,0)/2,l=[e[0]];for(let[i,s]of t.entries()){let[t,o]=[e[i],e[i+1]];if(s>=a){let e=s>0?a/s:0;l.push({x:t.x+(o.x-t.x)*e,y:t.y+(o.y-t.y)*e});break}l.push(o),a-=s}return l}(i),z=e=>b.map(t=>v(i.slice(0,2),t,e)).find(Boolean)??v(M,()=>[1,-1],e),C=z(x);for(let[e,s]of(C||(g+=l.length),(C??z(w)??k.map(e=>v(M,t=>[e[t]],d)).find(Boolean)??v(M,()=>[1,-1],d)??l.map(e=>m(i,va(e),18,[1,-1],4)[0])).entries()))u(`relationship:${t.id}:${a}:${f[e]}`,l[e],s,`class:${h}`)}}for(let t of e.relationships){let e=f.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),l={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 l=(e,t)=>iC(a.slice(e,t).join(" "),13),i=new Map,s=(e,t)=>{if(1===t)return{widest:l(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=s(i,t-1),o=Math.max(l(e,i),a.widest);o<n.widest&&(n={widest:o,breaks:[i,...a.breaks]})}return i.set(o,n),n},o=[0,...s(0,t).breaks,a.length];return o.slice(1).map((e,t)=>a.slice(o[t],e).join(" ")).join("\n")})(t.label.trim(),e)),s=t=>{let[i,s]=[va(t),18*t.split("\n").length];return[...m([l,a[1]],i,s,[-1,1],0),...m(e.points,i,s,[-1,1],50),...m(e.points,i,s,[-1,1],0)]},o=e=>i.map(t=>({text:t,rect:s(t).find(e(t))})).find(e=>void 0!==e.rect),n=o(e=>p(t.id,e));n||(g+=1);let c=n??o(d);if(c){u(`relationship:${t.id}:name`,c.text,c.rect);continue}let h=i.flatMap(e=>s(e).map(t=>({text:e,rect:t,hits:r(t)}))).reduce((e,t)=>t.hits<e.hits?t:e);u(`relationship:${t.id}:name`,h.text,h.rect)}return{texts:h,unclear:g}}(e,t.scene.elements.filter(e=>"arrow"===e.type),vp(t.scene))}),p=c(a);for(let a of s){if(0===p.labels.unclear)break;let s=m8(i,l,{...a,labelRoom:!0}),n=JSON.stringify([...s.boxes,...s.anchors]);if(o.has(n))continue;o.add(n);let d=vi(e,t,s),h=vr(d),g=c({cost:vn(d,h),counts:h,scene:d}),u=p.counts;g.labels.unclear<p.labels.unclear&&(!r(g)||vd(d)<=1.05*vd(p.scene))&&h.crossings<=u.crossings&&h.crossings+h.findings<=u.crossings+u.findings+p.labels.unclear-g.labels.unclear&&h.detours<=u.detours&&h.hugging<=u.hugging&&(p=g)}return{scene:p.scene,labels:p.labels.texts}}(e,t),i=new Map(vp(a).map(e=>[e.nodeId,e])),s=e.classes.map(a=>(function(e,t,a){let{id:l}=e.node,i=[`class:${l}`],[s,o]=[t.width,t.height],r=(a,o,r,n,d)=>({type:"node",id:`node:${l}${a}`,nodeId:`${l}${a}`,kind:o,rendererRole:"class-box",shape:"rectangle",x:t.x,y:r,width:s,height:n,label:e.name,...d?{fillColor:d,fillStyle:"solid"}:{},groupIds:i}),n=r("","class",t.y,o,a.style.backgroundColor),d=r(":name","class-name",t.y,e.band,"#efe6ec"),c=t.y+e.band+e.attributesHeight,p=r(":methods","class-methods",c,t.y+o-c),h=[{type:"text",id:`label:${l}:name`,containerId:d.id,x:t.x+s/2,y:t.y+e.band/2,text:e.heading,fontSize:16,lineHeight:1.375,maxWidth:s-24,...e.heading!==e.name?{textColor:"#6a4e5c"}:{},groupIds:i}],g=(e,a,s)=>{if(0===a.length)return;let o=22*a.length,r=Math.ceil(Math.max(...a.map(e=>iC(e,14))));h.push({type:"text",id:`text:${l}:${e}`,x:t.x+12+r/2,y:s+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,c),{nodes:[n,d,p],texts:h}})(t.get(a.id),i.get(a.id),e)),o=new Map(e.relationships.map(e=>[e.id,e])),r=a.elements.flatMap(e=>{var t;let a;if("arrow"!==e.type)return[];let l=(a=m9[(t=o.get(e.edgeId)).kind],t.navigable&&tD(t.kind)?{...a,to:"arrow"}:a);return[{...e,startArrowhead:l.from,endArrowhead:l.to,..."dashed"===l.stroke?{strokeStyle:"dashed"}:{}}]}),{elements:n,width:d,height:c}=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,l]=[Math.min(...t.map(e=>e.x)),Math.min(...t.map(e=>e.y))],[i,s]=[Math.max(0,48-a),Math.max(0,48-l)].map(Math.ceil);return{elements:e.map(e=>0===i&&0===s?e:"arrow"===e.type?{...e,points:e.points.map(e=>({x:e.x+i,y:e.y+s}))}:"line"===e.type?e:{...e,x:e.x+i,y:e.y+s}),width:Math.max(...t.map(e=>e.x))+i+48,height:Math.max(...t.map(e=>e.y))+s+48}}([...s.flatMap(e=>[...e.nodes,...e.texts]),...r,...l]);return{...a,width:d,height:c,elements:n,zOrder:n.map(e=>e.id)}})(bB(g)),catch:e=>new b3({status:"render_failed",context:{...v,issues:[kn({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=i5(w);if(x.length>0)return yield*new b3({status:"render_failed",context:{...v,issues:kz(x).map(e=>({...e,hint:"Shorten class or member names, or split the model, and retry buildClassDiagram."}))}});let b={...v,partial:kZ(w)},k=yield*kW({scene:w,formats:kw(p.options),inlineFormats:kx(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b3({status:e.status,context:{..."export_failed"===e.status?b:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...kG(p.requestId),normalizedSpec:g,quality:m,artifact:k,issues:[]}}),k2=o.fn("codeMode.buildOrgChart.workflow")(function*(e){var t,a;let l,s,r,n,d=i.q$Z(nw,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:aL(e.spec)}:e);if(!xH.oJ(d))return yield*new b5({status:"invalid_input",context:{issues:kf(os(d.failure))}});let c=yield*bm,p=d.success,h=yield*o.OH5(()=>c.createId("build")),g=(l=oe((t=p.spec).title),s=(e,t)=>t&&oe(t)?{[e]:oe(t)}:{},r=(e,t)=>t?{[e]:!0}:{},n=new Set(t.dottedLines.flatMap(e=>kv(e.id)??[])),{id:kv(t.id)??(km(l)||"sketchi-org-chart"),title:l,people:t.people.map(e=>({id:oe(e.id),name:oe(e.name),...s("title",e.title),...s("department",e.department),...s("manager",e.manager),...r("assistant",e.assistant),...r("avatar",e.avatar)})),dottedLines:t.dottedLines.map((e,t)=>({id:kv(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:oe(e.report),manager:oe(e.manager),...s("label",e.label)})),...r("groupByDepartment",t.groupByDepartment),...r("forest",t.forest),style:{...y}}),u={buildId:h,...kG(p.requestId),normalizedSpec:g},f=ay(bP(g)).map(e=>kn({code:bV[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new b5({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 b5({status:"quality_failed",context:{...w,issues:ky(m)}});let x=yield*o.SvU({try:()=>{let e,t,a,l,i,s,o,r,n,d,c,p,h,u,f,m,y,w,x,b,k,M,z;return t=function(e){let t=new Map;if(!0!==e.groupByDepartment)return t;let a=am(e),l=new Map(e.people.map(e=>[e.id,e])),i=(e,s)=>{let o=void 0===e.manager?void 0:l.get(e.manager),r=!s&&void 0!==o&&void 0!==e.department&&e.department!==o.department&&(a.get(e.id)?.length??0)>0;for(let l of(r&&t.set(e.id,e.department),a.get(e.id)??[]))i(l,s||r)};for(let t of af(e))i(t,!1);return t}(e=ax(bP(g))),a=function(e,t){let a=am(e),l=[...new Set(e.people.flatMap(e=>e.department??[]))],i=new Map(e.people.map(e=>[e.id,e])),s=af(e).flatMap(e=>(a.get(e.id)??[]).filter(e=>!0!==e.assistant)),o=e=>pT[e%pT.length],r=t=>{if(l.length>0)return void 0===t.department?e.style.accentColor:o(l.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:s.indexOf(a);return r<0?e.style.accentColor:o(r)},n=new Map,d=new Map,c=(e,l,i)=>{let s=t.get(e.id)??i;for(let t of(d.set(e.id,l),void 0!==s&&n.set(e.id,s),a.get(e.id)??[]))c(t,l+1,s)};for(let t of af(e))c(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,l=[t.title,a].filter(e=>void 0!==e).map(e=>vX(e.trim(),208,13));p.set(t.id,{person:t,depth:d.get(t.id)??0,name:vX(t.name.trim(),208,16),details:l.length>0?l.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(iC(e.name,16),e.details?iC(e.details,13):0,44*!!e.avatar)+24)))));for(let a of e)a.width=t}let g=e=>9+49*!!e.avatar+vR(e.name,16)+(e.details?3+vR(e.details,13):0)+5+4*!e.details,u=e=>e.details?Math.ceil(13*vT(e.details)*1.35)+18:Math.ceil(16*vT(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),s=function(e){let t={stackMin:5,twoColumns:5,outline:new Map,rows:new Map},a=vH(e,t),l=1;if(v$(a)>1){let i={...t,stackMin:2},s=vH(e,i);l+=1,v$(s)<v$(a)-1e-9&&([t,a]=[i,s])}let i=new Map,s=[],o=(e,t)=>{for(let a of(i.set(e.id,t),t>=1&&vq(e)&&s.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:s}of t){let t=vH(e,a);l+=1;let o={policy:a,block:t,excess:v$(t),preference:s};(!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<v$(a)-1e-6?i:void 0};for(let l=0;l<30&&v$(a)>1;l+=1){let l=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)=>(l.get(t)?.width??0)-(l.get(e)?.width??0)||e.localeCompare(t),d=r([...s.filter(e=>!t.outline.has(e)&&l.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(d){[t,a]=[d.policy,d.block];continue}let c=([,e])=>e.items>e.rows,p=[...l].filter(e=>c(e)&&e[1].widestItem<.6*e[1].width).toSorted(([e,t],[a,l])=>l.width-l.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&&l.has(e);)h.push([e,l.get(e)]),e=l.get(e).widest}let g=[...p,...h.filter(c).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 s=t.rows.get(i)-1;s>=1;s-=1){let o={...t,rows:new Map(t.rows).set(i,s)},r=vH(e,o);if(l+=1,v$(r)>Math.max(1,v$(a))+1e-9)break;t=o,a=r}let n=vz(vI(a));return{cards:a.cards,links:a.links,regions:a.regions,width:n.x1-n.x0,height:n.y1-n.y0,attempts:l,stackMin:t.stackMin,wraps:new Map([...t.rows].filter(([,e])=>e>1)),outlines:t.outline}}((l=am(e),i=e=>{let s=a.get(e.id),o=t.get(e.id),r=l.get(e.id)??[];return{id:e.id,width:s.width,height:s.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:sX(o)}}}},af(e).map(i))),o=e.style.backgroundColor,r=e=>({...e,x:e.x+40,y:e.y+40}),n=new Map([...s.cards].map(([e,t])=>[e,r(t)])),d=s.regions.map(e=>({type:"frame",id:`frame:${e.root}`,name:e.label,...r(e.frame)})),c=new Map(s.regions.flatMap(e=>e.members.map(t=>[t,`frame:${e.root}`]))),p=e.people.map(e=>(function(e,t,a,l){let{person:i}=e,s={groupIds:[`person:${i.id}`],...l?{frameId:l}:{}},o={type:"node",id:`node:${i.id}`,nodeId:i.id,kind:i.assistant?"assistant":"person",shape:"rectangle",...t,label:i.name,strokeColor:e.color,strokeWidth:2,fillColor:vU(e.color,a,.13),fillStyle:"solid",...s},r=[o],n=[],d=t.x+t.width/2,c=t.width-24;if(e.avatar&&r.push({type:"node",id:`node:${i.id}:avatar`,nodeId:`${i.id}:avatar`,kind:"avatar",shape:"ellipse",x:d-22,y:t.y+9,width:44,height:44,label:av(i.name),strokeColor:e.color,strokeWidth:1,fillColor:vU(e.color,a,.32),fillStyle:"solid",...s}),e.details){let a=vR(e.details,13),l=t.y+t.height-5-a;n.push({type:"text",id:`label:${i.id}`,containerId:o.id,x:d,y:l+a/2,text:e.details,fontSize:13,lineHeight:1.25,maxWidth:c,verticalAlign:"bottom",textColor:"#5f574c",...s});let r=vR(e.name,16);n.push({type:"text",id:`text:${i.id}:name`,x:d,y:l-3-r/2,text:e.name,fontSize:16,lineHeight:1.25,maxWidth:Math.ceil(iC(e.name,16)),textColor:v.ink,...s})}else{let a=vR(e.name,16),l=e.avatar;n.push({type:"text",id:`label:${i.id}`,containerId:o.id,x:d,y:l?t.y+t.height-5-a/2:t.y+t.height/2,text:e.name,fontSize:16,lineHeight:1.25,maxWidth:c,...l?{verticalAlign:"bottom"}:{},textColor:v.ink,...s})}return{nodes:r,texts:n}})(a.get(e.id),n.get(e.id),o,c.get(e.id))),h=s.links.map(e=>{let t=e.points.map(e=>({x:e.x+40,y:e.y+40})),a=void 0!==c.get(e.manager)&&c.get(e.manager)===c.get(e.report)?c.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=vW(e,n,d,c,h,!0)).straight?u:[vW(e,n,d,c,h,!1)].find(e=>e.straight<u.straight)??u,y=(m=[...d,...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=vT(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=d.map(e=>sT(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)),z=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:z,layers:[],layouts:[],zOrder:z.map(e=>e.id)}},catch:e=>new b5({status:"render_failed",context:{...w,issues:[kn({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=i5(x);if(b.length>0)return yield*new b5({status:"render_failed",context:{...w,issues:kz(b).map(e=>({...e,hint:"Shorten names or titles, or split the chart by division, and retry buildOrgChart."}))}});let k={...w,partial:kZ(x)},M=yield*kW({scene:x,formats:kw(p.options),inlineFormats:kx(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b5({status:e.status,context:{..."export_failed"===e.status?k:w,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...kG(p.requestId),normalizedSpec:g,quality:m,artifact:M,issues:[]}}),k3=o.fn("codeMode.buildVennDiagram.workflow")(function*(e){var t,a;let l,s,r=i.q$Z(nb,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:function(e){if(!aD(e)||!Array.isArray(e.sets))return e;let t=new Map,a=e.sets.map(e=>{if("string"==typeof e)return{id:e,label:e};if(!aD(e))return e;let{items:a,members:l,name:i,...s}=e,o=s.label??i,r=s.id??o,n=a??l;if(Array.isArray(n))for(let e of n){if("string"!=typeof e||""===e.trim())continue;let a=aE(e),l=t.get(a)??{text:e.trim(),sets:[]};l.sets.includes(r)||l.sets.push(r),t.set(a,l)}return{...s,...void 0===r?{}:{id:r},...void 0===o?{}:{label:o}}}),l=new Map(a.flatMap(e=>aD(e)&&"string"==typeof e.label?[[aE(e.label),e.id]]:[])),i=new Set(a.flatMap(e=>aD(e)?[e.id]:[])),s=e=>"string"!=typeof e||i.has(e)?e:l.get(aE(e))??e,o=e.regions;if(void 0!==o&&!Array.isArray(o)&&!aD(o))return{...e,sets:a};let r=(Array.isArray(o)?o:aD(o)?[o]:[]).map(e=>{if(!aD(e))return e;let{members:t,in:a,...l}=e,i=l.sets??a,o="string"==typeof i?[i]:i;return{...l,...void 0===o?{}:{sets:Array.isArray(o)?o.map(s):o},...void 0===l.items&&void 0!==t?{items:t}:{}}}),n=new Map;for(let{text:e,sets:a}of t.values()){let t=a.map(String).sort().join("\0"),l=n.get(t)??{sets:a,items:[]};l.items.push(e),n.set(t,l)}for(let{sets:e,items:t}of n.values()){let a=r.find(t=>aD(t)&&Array.isArray(t.sets)&&t.sets.length===e.length&&e.every(e=>t.sets.includes(e)));if(aD(a)&&void 0===a.count){let e=Array.isArray(a.items)?a.items:[],l=new Set(e.map(e=>"string"==typeof e?aE(e):e));a.items=[...e,...t.filter(e=>!l.has(aE(e)))]}else void 0===a&&r.push({sets:e,items:t})}return{...e,sets:a,...void 0===o&&0===r.length?{}:{regions:r}}}(e.spec)}:e);if(!xH.oJ(r))return yield*new b4({status:"invalid_input",context:{issues:kf(os(r.failure))}});let n=yield*bm,d=r.success,c=yield*o.OH5(()=>n.createId("build")),p=(l=oe((t=d.spec).title),s=(e,t)=>t&&oe(t)?{[e]:oe(t)}:{},{id:kv(t.id)??(km(l)||"sketchi-venn"),title:l,sets:t.sets.map(e=>({id:oe(e.id),label:oe(e.label),...s("color",e.color)})),regions:t.regions.map(e=>({sets:e.sets.map(oe),...s("label",e.label),...void 0===e.items?{}:{items:e.items.map(oe)},...void 0===e.count?{}:{count:e.count}})),style:{...y}}),h={buildId:c,...kG(d.requestId),normalizedSpec:p},g=aX(b$(p)).map(e=>kn({code:bF[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(g.length>0)return yield*new b4({status:"invalid_venn_diagram",context:{...h,issues:g}});let u={accepted:10>=(a=d.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:p.sets.length,edgeCount:0},checks:[]},f={...h,quality:u};if(!u.accepted)return yield*new b4({status:"quality_failed",context:{...f,issues:ky(u)}});let m=yield*o.SvU({try:()=>(function(e){var t;let a,l=aR(e),i=l.style.backgroundColor,s=function(e){let t=e.sets.length,a=2===t?vJ[2]:vJ[3],l=function(e){let t=[],a=e.regions.some(e=>(e.items?.length??0)>0),l=e.regions.some(e=>(e.count??0)>0);for(let i of e.regions){let s=i.items??[],o=0===i.count&&a&&!l?void 0:i.count;(void 0!==i.label||void 0!==o||0!==s.length)&&t.push({key:aU(e,i),options:function(e){let t=[],a=new Set;for(let l of vQ){let{whole:i,...s}=function(e,t){let a=[],l=0,i=!0,s=(e,t,a)=>{let l=v0(e,t,a);return i&&=l.whole,l.text},o=(e,t,i,s)=>{a.length&&(l+="item"===e&&a.at(-1)?.role==="item"?7:4);let o=v1(i,s,l),r=o.length*s*1.35;a.push({role:e,index:t,text:i,fontSize:s,width:Math.max(...o.map(e=>e.width)),height:r,top:l,lines:o}),l+=r};void 0!==e.label&&o("label",0,s(e.label,Math.max(t,120),17),17),void 0!==e.count&&o("count",0,e.count.toLocaleString("en-US"),26),e.items.forEach((e,a)=>o("item",a,s(e,t,15),15));let r=a.flatMap(e=>e.lines);return{pieces:a,lines:r,width:Math.max(0,...r.map(e=>e.width)),height:l,whole:i}}(e,l);if(!i)continue;let o=s.pieces.map(e=>e.text).join("\0");a.has(o)||(a.add(o),t.push(s))}return t}({...void 0===i.label?{}:{label:i.label},items:s,...void 0===o?{}:{count:o}})})}return t}(e),i={work:0},s={separation:1,radius:a,score:1/0};for(let e of vK){let o=a;for(let a of l)o=Math.max(o,function(e,t,a,l,i){let s=1/0,o=[];for(let r of e.options){let n=function(e,t,a,l,i,s,o){let r=i=>{let s=v3(a,l,i),r=v7(s,t,o);return v8(e,s,t,r,o).clearance>=10};if(r(i))return i;let n=i,d=Math.min(2*i,s);for(;!r(d);){if(d>=s)return 1/0;n=d,d=Math.min(2*d,s)}for(;d-n>1;){let e=Math.round((n+d)/2);r(e)?d=e:n=e}return d}(r,e.key,t,a,l,Math.min(s,2400),i);if(o.push(n),s=Math.min(s,n),n===l)break}return Number.isFinite(s)?o.find(e=>e<=1.2*s)??s:2400}(a,t,e,o,i));let r=o*(2===t?{width:2+e,height:2}:{width:2+e,height:2+e*Math.sqrt(3)/2}).width*(1+.4*Math.abs(e-1));r<s.score-1e-6&&(s={separation:e,radius:o,score:r})}let o=v3(t,s.separation,s.radius),r=l.map(e=>{let t=function(e,t,a,l,i,s=!1){for(let o of e){let e=v8(o,t,a,i,l,s);if(e.clearance>=10)return{block:o,...e}}}(e.options,o,e.key,i,v7(o,e.key,i),!0),a=t?.block??e.options[0];return{key:e.key,block:a,center:t?.center??v7(o,e.key,i),clearance:t?.clearance??-1/0}});return{radius:s.radius,separation:s.separation,circles:o,regions:r,labels:function(e,t,a,l){let i=Math.max(1.6*a,180),s=e.sets.map(e=>{let t=v0(e.label,i,20).text,a=v1(t,20,0);return{text:t,width:Math.max(...a.map(e=>e.width)),height:20*a.length*1.35}}),o=Math.min(...t.map(e=>e.y-e.r)),r=s.map((e,a)=>{let i=t[a],s=v7(t,[a],l);return 2===a?{x:s.x,top:i.y+i.r+10}:{x:s.x,top:o-10-e.height}}),[n,d]=s;if(n&&d){let e=r[0].x+n.width/2,t=r[1].x-d.width/2;e>-8&&(r[0]={...r[0],x:-8-n.width/2}),t<8&&(r[1]={...r[1],x:8+d.width/2})}return s.map((e,t)=>{let{x:a,top:l}=r[t];return{...e,box:{left:a-e.width/2,right:a+e.width/2,top:l,bottom:l+e.height}}})}(e,o,s.radius,i),work:i.work}}(l),o={left:Math.min(...(a=[...s.circles.map(e=>({left:e.x-e.r,right:e.x+e.r,top:e.y-e.r,bottom:e.y+e.r})),...s.labels.map(e=>e.box)]).map(e=>e.left)),top:Math.min(...a.map(e=>e.top)),right:Math.max(...a.map(e=>e.right)),bottom:Math.max(...a.map(e=>e.bottom))},r=40-o.left,n=40-o.top,d=e=>({...e,x:e.x+r,y:e.y+n}),c=l.sets.map((e,t)=>(function(e,t){let a=e.color?.trim();if(a&&aV.test(a))return a.toLowerCase();let l=a?.toLowerCase();return(l&&Object.hasOwn(aB,l)?aB[l]:void 0)??aB[aP[t]??"violet"]})(e,t)),p=function(e,t){let a=function(e){let t=[];for(let a=1;a<1<<e;a+=1)t.push(Array.from({length:e},(e,t)=>t).filter(e=>a&1<<e));return t}(t.length);for(let l=0;l<=10;l+=1){let i=t.map(e=>yt(ya(ye(e),[255,255,255],l/10)));if(a.every(t=>yi(v9,function(e,t,a,l=22){let i=ye(e);for(let e of a)i=ya(i,ye(t[e]),l/100);return yt(i)}(e,i,t))>=7))return i}return t.map(()=>"#ffffff")}(i,c),h={elements:[],back:[],middle:[],front:[]};for(let e of(l.sets.forEach((e,t)=>{let a,l=d(s.circles[t]),o=[`venn:set:${t}`],g=yr(`venn:set:${t}:fill`,l,e.label,{fillColor:p[t],fillStyle:"solid",strokeColor:p[t],strokeWidth:1,roughness:0,opacity:22,groupIds:o});h.elements.push(g),h.back.push(g.id);let u=yr(`venn:set:${t}`,l,e.label,{strokeColor:c[t],strokeWidth:2,roughness:0,groupIds:o});h.elements.push(u),h.middle.push(u.id);let f=s.labels[t];yo(h,`venn:set:${t}:label`,f.text,20,{left:(a=f.box).left+r,right:a.right+r,top:a.top+n,bottom:a.bottom+n},function(e,t){for(let a=0;a<=20;a+=1){let l=yt(ya(ye(t),[0,0,0],a/20));if(yi(l,e)>=4.5)return l}return v9}(i,c[t]),o)}),s.regions)){let a=(t=e.key,`venn:region:${t.join("+")}`),l=d(e.center),i=l.y-e.block.height/2;for(let t of e.block.pieces){let e=i+t.top;yo(h,"item"===t.role?`${a}:item:${t.index}`:`${a}:${t.role}`,t.text,t.fontSize,{left:l.x-t.width/2,right:l.x+t.width/2,top:e,bottom:e+t.height},v9,[a])}}return{kind:"canvas",version:1,diagramId:l.id,title:l.title,width:Math.ceil(o.right-o.left+80),height:Math.ceil(o.bottom-o.top+80),accentColor:l.style.accentColor,backgroundColor:i,elements:h.elements,layers:[],layouts:[],zOrder:[...h.back,...h.middle,...h.front]}})(b$(p)),catch:e=>new b4({status:"render_failed",context:{...f,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render Venn diagram scene.",hint:"Repair the sets and regions and retry."})]}})}).pipe(o.fRP("codeMode.buildVennDiagram.render")),v=i5(m);if(v.length>0)return yield*new b4({status:"render_failed",context:{...f,issues:kz(v).map(e=>({...e,hint:"Shorten names or titles, or split the chart by division, and retry buildVennDiagram."}))}});let w={...f,partial:kZ(m)},x=yield*kW({scene:m,formats:kw(d.options),inlineFormats:kx(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b4({status:e.status,context:{..."export_failed"===e.status?w:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...kG(d.requestId),normalizedSpec:p,quality:u,artifact:x,issues:[]}}),k5=o.fn("codeMode.buildJourneyMap.workflow")(function*(e){var t,a;let l,s,r,n,d=i.q$Z(nM,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:function(e){if(!a5(e))return e;let t={...e},a=a4(t,a6),l=a4(t,a8),i=a4(t,la),s=a4(t,ll),o=Array.isArray(a)?a.map(ln):a,r=null==l?void 0:Array.isArray(l)?l:[l];if(r&&(void 0===o||Array.isArray(o))){let e=o?.map(e=>({...e}))??[];for(let t of r){let a=a5(t)?ls(t.stage):void 0,l="string"==typeof a&&a.trim().length>0?a:aQ,i=e.find(e=>a5(e)&&e.name===l);i||(i={name:l,steps:[]},e.push(i)),i.steps=[...i.steps??[],lr(t)]}o=e}for(let[e,t]of[["painPoints",i],["opportunities",s]])if(null!=t&&Array.isArray(o))for(let a of Array.isArray(t)?t:[t]){let t=a5(a)?ls(a.stage):void 0,l="string"==typeof t&&t.trim().length>0?t:aQ,i=o.find(e=>a5(e)&&e.name===l);i||(i={name:l,steps:[]},o.push(i));let s=a5(a)?(({stage:e,...t})=>lo([t]))(a):[a];i[e]=[...i[e]??[],...s]}let n=t.persona;if(a5(n)){let e=n.name,a=n.description??n.role??n.summary;t.persona="string"==typeof e&&"string"==typeof a?`${e}, ${a}`:e??a}return Array.isArray(t.actors)&&(t.actors=t.actors.map(ls)),{...t,...void 0===o?{}:{stages:o}}}(e.spec)}:e);if(!xH.oJ(d))return yield*new b6({status:"invalid_input",context:{issues:kf(os(d.failure))}});let c=yield*bm,p=d.success,h=yield*o.OH5(()=>c.createId("build")),g=(l=oe((t=p.spec).title),s=(e,t)=>t&&oe(t)?{[e]:oe(t)}:{},r=(e,t)=>{let a=(t??[]).map(oe).filter(e=>e.length>0);return a.length>0?{[e]:a}:{}},n=(t.actors??[]).map(oe).filter(e=>e.length>0),{id:kv(t.id)??(km(l)||"sketchi-journey-map"),title:l,...s("persona",t.persona),...n.length>0?{actors:n}:{},stages:t.stages.map(e=>({name:oe(e.name),steps:e.steps.map(e=>({label:oe(e.label),score:e.score,...s("actor",e.actor),...s("touchpoint",e.touchpoint)})),...r("painPoints",e.painPoints),...r("opportunities",e.opportunities)})),style:{...y}}),u={buildId:h,...kG(p.requestId),normalizedSpec:g},f=a1(bO(g)).map(e=>kn({code:bE[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(f.length>0)return yield*new b6({status:"invalid_journey",context:{...u,issues:f}});let m={accepted:10>=(a=p.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:g.stages.reduce((e,t)=>e+t.steps.length,0),edgeCount:0},checks:[]},v={...u,quality:m};if(!m.accepted)return yield*new b6({status:"quality_failed",context:{...v,issues:ky(m)}});let w=yield*o.SvU({try:()=>{let e,t,a,l,i,s,o,r,n,d,c,p,h;return e=a2(bO(g)),yC.clear(),yb.clear(),t=function(e){let t,{narrowest:a,needed:l}=function(e){let t,a=e=>e.flat().map(({label:e,details:t})=>10*yy(e.text)+(t?yy(t.text):0)),l=a(yS(e,220));for(let i=128;i<220;i+=4){let s=yS(e,i);if(function(e,t){return e.flat().every(({label:e,details:a})=>e.width<=t-24&&(void 0===a||a.width<=t-24))}(s,i)&&(void 0===t&&s.flat().every(({label:e})=>4>=yy(e.text))&&(t=i),a(s).every((e,t)=>e<=l[t])))return{narrowest:t??i,needed:i}}return{narrowest:t??220,needed:220}}(e),i=e.stages.map(e=>e.steps.length),s=i.reduce((e,t)=>e+t,0),o=new Set,r=(i,s)=>{let r=JSON.stringify(i);if(!o.has(r))for(let n of(o.add(r),s))for(let s=l;s>=a;s-=4){let a=function(e,t,a,l){let i=yS(e,t),s={steps:y_("Steps",200,14),experience:y_("Experience",200,14),pains:y_("Pain points",200,14),opportunities:y_("Opportunities",200,14),continued:y_("continued",200,12)},o=Array.from({length:5},(e,t)=>{let a=1+t;return y_(3===a?`${a} \xb7 Neutral`:`${a}`,200,12)}),r=e.stages.some(e=>(e.painPoints?.length??0)>0),n=e.stages.some(e=>(e.opportunities?.length??0)>0),d=Math.max(s.steps.width,s.experience.width,...o.map(e=>e.width),r?s.pains.width:0,n?s.opportunities.width:0)+16,c=40+d,p=a.map(a=>{let s=c,o=a.map(({stage:a,from:l,to:i})=>{let o=i-l,r=o*t+(o-1)*12,n=0===l?[...e.stages[a].painPoints??[],...e.stages[a].opportunities??[]]:[],d=Math.max(r,y_(yB(e,{stage:a,from:l}),1,16).width+24,...n.map(e=>y_(e,1,13).width+24)),c=(d-r)/2,p={stage:a,from:l,to:i,x:s,width:d,steps:Array.from({length:o},(e,a)=>yL(s+c+a*(t+12)))};return s+=d+28,p}),r=o.map(t=>y_(yB(e,t),t.width-24,16)),n=Math.max(40,...r.map(e=>yx(e.text,16))),d=o.map(t=>0===t.from?yA(e.stages[t.stage].painPoints,t.width):[]),p=o.map(t=>0===t.from?yA(e.stages[t.stage].opportunities,t.width):[]),h=Math.max(48,...o.map(e=>i[e.stage].slice(e.from,e.to)).flat().map(({label:e,details:t})=>Math.max(yx(e.text,15),t?5+e.height+6+t.height+6:0))),g=Math.max(0,...d.map(yP)),u=Math.max(0,...p.map(yP));return{stages:o,right:s-28,cardHeight:h,headerHeight:n,header:r,pains:d,opportunities:p,painHeight:g,opportunityHeight:u,height:n+14+h+14+yv(l)+(g>0?14+g:0)+(u>0?14+u:0)}}),h=Math.max(...p.map(e=>e.right)),g=h-40,u=y_(e.title,Math.max(g,360),20),f=[void 0===e.persona?void 0:`Persona: ${e.persona.trim()}`,void 0===e.actors||0===e.actors.length?void 0:`Actors: ${e.actors.map(e=>e.trim()).join(", ")}`].filter(e=>void 0!==e).map(e=>y_(e,Math.max(g,360),14)),m=40+u.height+f.reduce((e,t)=>e+4+t.height,0)+18,v=p.reduce((e,t)=>e+t.height,0)+(p.length-1)*44,y=i.flat();return{cardWidth:t,pitch:l,elements:1+f.length+y.reduce((e,t)=>e+(t.details?8:7),0)+2*e.stages.reduce((e,t)=>e+(t.painPoints?.length??0)+(t.opportunities?.length??0),0)+p.reduce((e,t,a)=>e+4*t.stages.length+ +(t.painHeight>0)+ +(t.opportunityHeight>0)+(a>0?4:2)+ +(a<p.length-1)+14,0),detailed:i.flat().some(e=>void 0!==e.details),texts:i,bands:p,title:u,subtitles:f,headerColumn:d,rowLabels:s,levels:o,gridLeft:c,top:m,width:Math.ceil(Math.max(h,40+u.width,...f.map(e=>40+e.width))+40),height:Math.ceil(m+v+40)}}(e,s,i,n),l=yI(a);if(yH(a))return a;(!t||l[0]<t.excess[0]||l[0]===t.excess[0]&&l[1]<t.excess[1])&&(t={plan:a,excess:l})}};for(let t=1;t<=e.stages.length;t+=1){let e=r(function(e,t){let a,l=t=>t.reduce((t,a)=>t+e[a],0)+(t.length-1)*28/140,i=e.length,s=(e,t)=>0===t?[[]]:Array.from({length:i-t-e+1},(t,a)=>e+a).flatMap(e=>s(e+1,t-1).map(t=>[e,...t]));for(let e of s(1,t-1)){let t=[0,...e,i],s=t.slice(1).map((e,a)=>Array.from({length:e-t[a]},(e,l)=>t[a]+l)),o=s.map(l),r={runs:s,key:[Math.max(...o),o.reduce((e,t)=>e+t*t,0),...o.map(e=>-e)]},n=a?.key.findIndex((e,t)=>Math.abs(e-r.key[t])>1e-9);(!a||void 0!==n&&n>=0&&r.key[n]<a.key[n])&&(a=r)}return a.runs.map(t=>t.map(t=>({stage:t,from:0,to:e[t]})))}(i,t),1===t?yf:yf.slice(0,1));if(e)return e}for(let e=2;e<=s;e+=1){let t=r(function(e,t){let a=Math.max(1,Math.ceil(e.reduce((e,t)=>e+t,0)/t)),l=[[]],i=a;return e.forEach((e,t)=>{let s=0;for(;s<e;){let o=e-s,r=l.at(-1);o<=i?(r.push({stage:t,from:s,to:e}),i-=o,s=e):(r.length>0&&0===s&&o<=a||i>0&&(r.push({stage:t,from:s,to:s+i}),s+=i),l.push([]),i=a)}}),l.filter(e=>e.length>0)}(i,e),yf.slice(0,1));if(t)return t}return t.plan}(e),yC.clear(),yb.clear(),a=e.style.backgroundColor,l=[],i=[],s=[],r=40,(o=[]).push(y$("text:journey:title",t.title,40+t.title.width/2,r+t.title.height/2,20,yd,{textAlign:"left"})),r+=t.title.height,t.subtitles.forEach((e,t)=>{r+=4,o.push(y$(`text:journey:subtitle:${t}`,e,40+e.width/2,r+e.height/2,14,yc,{textAlign:"left"})),r+=e.height}),n=e.stages.flatMap(e=>e.steps.map(e=>e.score)),d=[],c=t.top,t.bands.forEach((r,p)=>{let h=(e,t,a,l)=>o.push(y$(`text:journey:row:${p}:${e}`,t,40+t.width/2,a+t.height/2,14,l,{textAlign:"left"})),g=c+r.headerHeight+14,u=g+r.cardHeight+14,f=u+yv(t.pitch)+14,m=f+(r.painHeight>0?r.painHeight+14:0),v=c+r.height;h("steps",t.rowLabels.steps,g+5,yc),h("experience",t.rowLabels.experience,u+2,yc),p>0&&o.push(y$(`text:journey:continued:${p}`,t.rowLabels.continued,40+t.rowLabels.continued.width/2,u+4+t.rowLabels.experience.height+t.rowLabels.continued.height/2,12,yp,{textAlign:"left"}));let y=u+ym+2*t.pitch;t.levels.forEach((e,a)=>{let i=1+a,s=yL(u+ym+(5-i)*t.pitch);o.push(y$(`text:journey:level:${p}:${i}`,e,t.gridLeft-16+4-e.width/2,s,12,yp,{textAlign:"right"})),3!==i&&l.push({type:"line",id:`line:journey:level:${p}:${i}`,points:[{x:t.gridLeft,y:s},{x:r.right,y:s}],strokeColor:"#e9e2d5",strokeWidth:1,roughness:0})}),r.painHeight>0&&h("pain-points",t.rowLabels.pains,f+9,"#b3261e"),r.opportunityHeight>0&&h("opportunities",t.rowLabels.opportunities,m+9,"#0b6e4b"),l.push({type:"line",id:`line:journey:baseline:${p}`,points:[{x:t.gridLeft,y:y},{x:r.right,y:y}],strokeColor:"#a89d89",strokeStyle:"dashed",strokeWidth:1,roughness:0}),r.stages.forEach((e,t)=>{if(0===t)return;let a=e.x-14;l.push({type:"line",id:`line:journey:divider:${e.stage}`,points:[{x:a,y:g},{x:a,y:v}],strokeColor:"#d6cdbd",strokeWidth:1,roughness:0})});let w=[];r.stages.forEach((l,n)=>{let p=e.stages[l.stage],h=yg[l.stage%yg.length],v=0===l.from?`journey:stage:${l.stage}`:`journey:stage-continued:${l.stage}-${l.from}`;i.push({type:"node",id:`node:${v}`,nodeId:v,kind:0===l.from?"journey-stage":"journey-stage-continued",shape:"rectangle",x:l.x,y:c,width:l.width,height:r.headerHeight,label:yB(e,l),strokeColor:h,strokeWidth:2,fillColor:yq(h,a,.22),fillStyle:"solid"}),o.push({type:"text",id:`label:${v}`,containerId:`node:${v}`,x:yL(l.x+l.width/2),y:yL(c+r.headerHeight/2),text:r.header[n].text,fontSize:16,lineHeight:1.25,maxWidth:l.width-24,textColor:yd}),p.steps.slice(l.from,l.to).forEach((e,n)=>{var c,p,f,m;let v,y,x,b,k,M,z,C,_=l.from+n,q=`${l.stage}-${_}`,L=`journey:step:${q}`,S=l.steps[n],B=S+t.cardWidth/2,{label:A,details:P}=t.texts[l.stage][_],V=[L];i.push({type:"node",id:`node:${L}`,nodeId:L,kind:"journey-step",shape:"rectangle",x:S,y:g,width:t.cardWidth,height:r.cardHeight,label:e.label.trim(),strokeColor:h,strokeWidth:1,fillColor:yq(h,a,.07),fillStyle:"solid",groupIds:V});let H=t.cardWidth-24;o.push({type:"text",id:`label:${L}`,containerId:`node:${L}`,x:yL(B),y:yL(t.detailed?g+5+A.height/2:g+r.cardHeight/2),text:A.text,fontSize:15,lineHeight:1.25,maxWidth:H,...t.detailed?{verticalAlign:"top"}:{},textColor:yd,groupIds:V}),P&&o.push(y$(`text:${L}:details`,P,B,g+r.cardHeight-6-P.height/2,13,yp,{groupIds:V}));let I={x:yL(B),y:yL(u+ym+(5-e.score)*t.pitch)};w.push(I);let $=(c=q,p=I,f=e.score,m=a,y=yu[f-1],x=[`journey:face:${c}`],b=(e,t)=>({type:"node",id:`node:journey:face:${c}:eye-${e}`,nodeId:`journey:face:${c}:eye-${e}`,kind:"journey-eye",rendererRole:yn,shape:"ellipse",x:yL(p.x+t-2),y:yL(p.y-6),width:4,height:4,label:`${e} eye`,strokeColor:yd,strokeWidth:1,fillColor:yd,fillStyle:"solid",roughness:0,groupIds:x}),k=(v=Math.round(f)-1,aZ[Math.min(aZ.length-1,Math.max(0,v))]),M=(f-3)*2.5,z=p.y+5-M/2,C={type:"line",id:`line:journey:face:${c}:mouth`,points:0===M?[{x:yL(p.x-5.5),y:yL(z)},{x:yL(p.x+5.5),y:yL(z)}]:[{x:yL(p.x-6),y:yL(z)},{x:yL(p.x),y:yL(z+M)},{x:yL(p.x+6),y:yL(z)}],strokeColor:yd,strokeWidth:2,roughness:0,groupIds:x},{nodes:[{type:"node",id:`node:journey:face:${c}`,nodeId:`journey:face:${c}`,kind:"journey-face",rendererRole:yn,shape:"ellipse",x:yL(p.x-14),y:yL(p.y-14),width:28,height:28,label:`${k} (${f})`,strokeColor:y,strokeWidth:2,fillColor:yq(y,m,.4),fillStyle:"solid",roughness:0,groupIds:x},b("left",-4.5),b("right",4.5)],mouth:C});s.push(...$.nodes,$.mouth);let F=y_(`${e.score}`,40,12),O=I.y-14-2-F.height/2;o.push(y$(`text:journey:score:${q}`,F,I.x,O,12,yd,{groupIds:[`journey:face:${q}`]})),d.push({left:I.x-F.width/2,top:O-F.height/2,right:I.x+F.width/2,bottom:O+F.height/2})});let y=(e,t,s,r)=>{let n=s;t.forEach((t,s)=>{let d=`journey:${e}:${l.stage}-${s}`;i.push({type:"node",id:`node:${d}`,nodeId:d,kind:"pain"===e?"journey-pain-point":"journey-opportunity",shape:"rectangle",x:l.x,y:n,width:l.width,height:t.height,label:("pain"===e?p.painPoints:p.opportunities)[s].trim(),strokeColor:r,strokeWidth:1,fillColor:yq(r,a,.1),fillStyle:"solid"}),o.push({type:"text",id:`label:${d}`,containerId:`node:${d}`,x:yL(l.x+l.width/2),y:yL(n+t.height/2),text:t.text,fontSize:13,lineHeight:1.25,maxWidth:l.width-24,textColor:yd}),n+=t.height+8})};y("pain",r.pains[n],f,"#e34948"),y("opportunity",r.opportunities[n],m,"#1baf7a")}),w.length>=2&&l.push({type:"line",id:`line:journey:curve:${p}`,points:[w[0],w[1],...w.slice(2)],strokeColor:yh,strokeWidth:2,roughness:0});let x=r.stages[0],b=e.stages.slice(0,x.stage).reduce((e,t)=>e+t.steps.length,0)+x.from,k=n[b-1],M=n[b+w.length],z=(e,t,a)=>l.push({type:"line",id:`line:journey:${e}:${p}`,points:[t,a],strokeColor:yh,strokeStyle:"dashed",strokeWidth:2,roughness:0});void 0!==k&&z("curve-in",{x:t.gridLeft,y:yL(u+ym+(5-k)*t.pitch)},w[0]),void 0!==M&&z("curve-out",w.at(-1),{x:r.right,y:yL(u+ym+(5-M)*t.pitch)}),c=v+44}),p=pU(l,d,e=>e.startsWith("line:journey:level:")||e.startsWith("line:journey:baseline:")),h=[...l.flatMap(e=>p.get(e.id)??[e]),...i,...s,...o],{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:t.width,height:t.height,accentColor:e.style.accentColor,backgroundColor:a,elements:h,layers:[],layouts:[],zOrder:h.map(e=>e.id)}},catch:e=>new b6({status:"render_failed",context:{...v,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.id},message:e instanceof Error?e.message:"Unable to render journey map scene.",hint:"Repair the stages and steps and retry."})]}})}).pipe(o.fRP("codeMode.buildJourneyMap.render")),x=i5(w);if(x.length>0)return yield*new b6({status:"render_failed",context:{...v,issues:kz(x).map(e=>({...e,hint:"Shorten step labels or notes, or split the journey, and retry buildJourneyMap."}))}});let b={...v,partial:kZ(w)},k=yield*kW({scene:w,formats:kw(p.options),inlineFormats:kx(p.options),...p.requestId?{requestId:p.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b6({status:e.status,context:{..."export_failed"===e.status?b:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:h,...kG(p.requestId),normalizedSpec:g,quality:m,artifact:k,issues:[]}}),k4=o.fn("codeMode.buildSankey.workflow")(function*(e){var t,a;let l,s,r=i.q$Z(nC,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:function(e){if(!lk(e))return e;let{flows:t,edges:a,connections:l,...i}=e,s=i.links??t??a??l,o=i.nodes,r=[],n=new Set,d=new Map,c=(e,t)=>{for(let a of(n.add(e),[t,e.toLowerCase(),t.toLowerCase()]))d.has(a)||d.set(a,e)},p=new Set,h=e=>{let t=e.trim().toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"node",a=t;for(let e=2;p.has(a);e+=1)a=`${t}-${e}`;return p.add(a),a},g=Array.isArray(o)?o.map(e=>{if("string"==typeof e){let t=h(e);return c(t,e),{id:t,label:e}}if(!lk(e))return e;let t={...e},a=lM(t,lq),l="string"==typeof t.id&&""!==t.id?t.id:void 0,i=a??l,s=l??("string"==typeof i?h(i):void 0);return"string"==typeof s&&(p.add(s),c(s,"string"==typeof i?i:s)),(null===t.color||""===t.color)&&delete t.color,{...t,...void 0===s?{}:{id:s},...void 0===i?{}:{label:i}}}):o;Array.isArray(g)&&r.push(...g);let u=e=>{if(lk(e)){let t=[e.id,e.label,e.name].find(e=>"string"==typeof e&&""!==e);if(void 0===t)return e;e=t}if("string"!=typeof e||""===e)return e;let t=n.has(e)?e:d.get(e)??d.get(e.toLowerCase());if(void 0!==t)return t;if(void 0!==o)return e;let a=h(e);return p.add(a),c(a,e),r.push({id:a,label:e}),a},f=Array.isArray(s)?s.map(e=>{if(!lk(e))return e;let t={...e},a=u(lM(t,lz)),l=u(lM(t,lC)),i=function(e){if("string"!=typeof e)return e;let t=Number(e.trim().replace(/,/gu,""));return""!==e.trim()&&Number.isFinite(t)?t:e}(lM(t,l_)),s=lM(t,lq);return{...t,...void 0===a?{}:{source:a},...void 0===l?{}:{target:l},...void 0===i?{}:{value:i},...void 0===s||""===s?{}:{label:s}}}):s;return{...i,...void 0===o?0===r.length?{}:{nodes:r}:{nodes:Array.isArray(o)?r:o},...void 0===s?{}:{links:f}}}(e.spec)}:e);if(!xH.oJ(r))return yield*new b7({status:"invalid_input",context:{issues:kf(os(r.failure))}});let n=yield*bm,d=r.success,c=yield*o.OH5(()=>n.createId("build")),p=(l=oe((t=d.spec).title),s=(e,t)=>t&&oe(t)?{[e]:oe(t)}:{},{id:kv(t.id)??(km(l)||"sketchi-sankey"),title:l,nodes:t.nodes.map(e=>({id:oe(e.id),label:oe(e.label),...e.color?{color:e.color}:{}})),links:t.links.map(e=>({source:oe(e.source),target:oe(e.target),value:e.value,...s("label",e.label)})),...s("unit",t.unit),style:{...y}}),h={buildId:c,...kG(d.requestId),normalizedSpec:p},g=ly(bH(p)).map(e=>kn({code:bI[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(g.length>0)return yield*new b7({status:"invalid_sankey",context:{...h,issues:g}});let u={accepted:10>=(a=d.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:p.nodes.length,edgeCount:p.links.length},checks:[]},f={...h,quality:u};if(!u.accepted)return yield*new b7({status:"quality_failed",context:{...f,issues:ky(u)}});let m=yield*o.SvU({try:()=>{let e;return function(e,t){let a=new Map(e.nodes.map(e=>[e.id,e.label])),l=pA(e.unit),i=[],s=[],o=[];for(let e of t.bands){let t=yJ(e.source,e.target),r=yG(e.points),n=e.points.map(e=>({x:yK(e.x-r.left),y:yK(e.y-r.top)}));i.push({type:"node",id:`node:${t}`,nodeId:t,rendererRole:yj,shape:"polygon",points:[n[0],n[1],n[2],...n.slice(3)],x:yK(r.left),y:yK(r.top),width:yK(Math.max(r.right-r.left,.5)),height:yK(Math.max(r.bottom-r.top,.5)),label:`${a.get(e.source)} → ${a.get(e.target)}: ${pO(e.value,l)}`,fillColor:e.color,fillStyle:"solid",strokeColor:e.color,strokeWidth:1,roughness:0,opacity:45,groupIds:[t]}),e.leader&&s.push({type:"line",id:`leader:${t}`,points:[{x:e.leader[0].x,y:e.leader[0].y},{x:e.leader[1].x,y:e.leader[1].y}],strokeColor:"#4c4639",strokeWidth:1,roughness:0,groupIds:[t]}),o.push(yQ(`text:${t}`,e.text,[t]))}for(let a of t.nodes){let t=yW(a.id);if(a.knockout){let l=`sankey:knockout:${a.id}`;s.push({type:"node",id:`node:${l}`,nodeId:l,rendererRole:yj,shape:"rectangle",x:yK(a.knockout.left),y:yK(a.knockout.top),width:yK(a.knockout.right-a.knockout.left),height:yK(a.knockout.bottom-a.knockout.top),label:`${a.label} label background`,fillColor:e.style.backgroundColor,fillStyle:"solid",strokeColor:e.style.backgroundColor,strokeWidth:1,roughness:0,opacity:75,groupIds:[t]})}s.push({type:"node",id:`node:${t}`,nodeId:t,rendererRole:yj,shape:"rectangle",x:a.x,y:a.y,width:a.width,height:a.height,label:a.label,fillColor:a.color,fillStyle:"solid",strokeColor:a.color,strokeWidth:1,roughness:0,groupIds:[t]}),o.push(yQ(`text:${t}`,a.text,[t]))}let r=[...t.nodes.flatMap(e=>[{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height},e.text.box,...e.knockout?[e.knockout]:[]]),...t.bands.flatMap(e=>[yG(e.points),e.text.box]),...t.bands.flatMap(e=>e.leader?[yG(e.leader)]:[])],n={left:Math.min(...r.map(e=>e.left)),top:Math.min(...r.map(e=>e.top)),right:Math.max(...r.map(e=>e.right)),bottom:Math.max(...r.map(e=>e.bottom))},d=iS(e.title,Math.max(n.right-n.left,360),20),c=d.split("\n"),p=Math.ceil(Math.max(...c.map(e=>iC(e,20)))),h=Math.ceil(20*c.length*1.35),g=n.top-20-h;o.push(yQ("sankey:title",{text:d,fontSize:20,width:p,height:h,align:"left",box:{left:n.left,top:g,right:n.left+p,bottom:n.top-20}},[]));let u=n.left,f=Math.max(n.right,n.left+p),m=40-u,v=40-g,y=[...i,...s,...o].map(e=>{if("node"===e.type||"text"===e.type)return{...e,x:yK(e.x+m),y:yK(e.y+v)};if("line"===e.type){let[t,a,...l]=e.points.map(e=>({x:yK(e.x+m),y:yK(e.y+v)}));return{...e,points:[t,a,...l]}}return e});return{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:Math.ceil(f-u+80),height:Math.ceil(n.bottom-g+80),accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:y,layers:[],layouts:[],zOrder:y.map(e=>e.id)}}(e=lx(bH(p)),function(e,t={}){let a=function(e){let t=new Map,a=new Map;for(let l of e.links)t.set(l.target,[...t.get(l.target)??[],l.value]),a.set(l.source,[...a.get(l.source)??[],l.value]);return new Map(e.nodes.map(e=>{let l=lv(t.get(e.id)??[]),i=lv(a.get(e.id)??[]);return[e.id,{inflow:l,outflow:i,total:Math.max(l,i)}]}))}(e),l=lf(e),i=Math.max(...l.values())+1,s=new Set(e.links.map(e=>e.source)),o=new Map(e.nodes.filter(e=>s.has(e.id)).map((e,t)=>({node:e,index:t})).toSorted((e,t)=>l.get(e.node.id)-l.get(t.node.id)||e.index-t.index).map(({node:e},t)=>[e.id,yF[t%yF.length]]));for(let t of e.nodes)o.set(t.id,t.color??o.get(t.id)??"#8c826f");let r=new Map(e.nodes.map(t=>{var l,i;return[t.id,yE((l=t.label,i=a.get(t.id).total,`${l}
427
- ${pO(i,pA(e.unit))}`),14,170)]})),n=e.links.map(t=>{let a,l;return yE((a=pA(e.unit),l=pO(t.value,a.suffix.startsWith(" ")?{...a,suffix:""}:a),void 0===t.label?l:`${t.label}
428
- ${l}`),12,140)}),d=Array.from({length:i},()=>[]),c=new Map;for(let t of e.nodes){let e={key:t.id,node:t.id,column:l.get(t.id),height:0,y:0,overhang:0};c.set(t.id,e),d[e.column].push(e)}let p=[],h=e.links.map((e,t)=>{let a=[],l=c.get(e.source),i=c.get(e.target);for(let s=l.column+1;s<i.column;s+=1){let i={key:`~${t}:${s}`,column:s,height:0,y:0,overhang:0};d[s].push(i),a.push({link:t,from:l,to:i,value:e.value,width:0}),l=i}return a.push({link:t,from:l,to:i,value:e.value,width:0}),p.push(...a),a}),g=new Map,u=new Map;for(let e of p)u.set(e.from,[...u.get(e.from)??[],e]),g.set(e.to,[...g.get(e.to)??[],e]);let f=Array.from({length:Math.max(0,i-1)},(e,t)=>p.filter(e=>e.from.column===t)),m=(e,t)=>Math.max(22,e.overhang+t.overhang+4),v=e=>e.reduce((t,a,l)=>t+a.height+(l>0?m(e[l-1],a):0),0),y=t=>{for(let a of p)a.width=Math.max(e.links[a.link].value*t,3);for(let e of d)for(let t of e){let e=e=>(e??[]).reduce((e,t)=>e+t.width,0);t.height=Math.max(e(g.get(t)),e(u.get(t)));let a=void 0===t.node?void 0:r.get(t.node);t.overhang=a?Math.max(0,(a.height-t.height)/2):0}},w=0,x=()=>{let e=new Map;for(let t of d)t.forEach((t,a)=>e.set(t,a));return e},b=e=>{let t=x(),a=0,l=0;for(let i of e){let e=function(e,t){let a=0,l=0;for(let i=0;i<e.length;i+=1){let s=e[i],o=t.get(s.from),r=t.get(s.to);for(let n=i+1;n<e.length;n+=1){let i=e[n];s.from!==i.from&&s.to!==i.to&&(o-t.get(i.from))*(r-t.get(i.to))<0&&(a+=1,l+=s.value*i.value)}}return{count:a,weighted:l,work:e.length*(e.length-1)/2}}(f[i],t);a+=e.count,l+=e.weighted,w+=e.work}return{count:a,weighted:l}},k=f.map((e,t)=>t),M=()=>b(k),z=(e,t)=>{let a=1e-9*Math.max(Math.abs(e.weighted),Math.abs(t.weighted));return e.weighted<t.weighted-a||Math.abs(e.weighted-t.weighted)<=a&&e.count<t.count};if(y(1),"authored"!==t.ordering){let e=d.map(e=>[...e]),t=M(),a=e=>{let t=new Map,a=0;for(let l of e)t.set(l,a+l.height/2),a+=l.height+22;return t},l=(e,t)=>{let l=a(d["in"===t?e-1:e+1]),i=a(d[e]),s=new Map(d[e].map(e=>{let a=("in"===t?g:u).get(e)??[],s=a.reduce((e,t)=>e+t.value,0);return 0===s?[e,i.get(e)]:[e,a.reduce((e,a)=>e+a.value*l.get("in"===t?a.from:a.to),0)/s]}));d[e].sort((e,t)=>s.get(e)-s.get(t))},s=()=>d.map(e=>[...e]),o=e=>d.splice(0,d.length,...e.map(e=>[...e])),r=()=>{let e=s(),t=M();for(let a=0;a<12&&w<4e6;a+=1){for(let e=1;e<i;e+=1)l(e,"in");for(let e=i-2;e>=0;e-=1)l(e,"out");let a=M();z(a,t)&&(t=a,e=s())}return e},n=()=>{for(let e=0,t=!0;t&&e<8;e+=1)for(let[e,a]of(t=!1,d.entries())){let l=[e-1,e].filter(e=>e>=0&&e<f.length);for(let e of[...a]){if(w>=4e6)break;let i=a.indexOf(e),s=i,o=b(l);a.splice(i,1);for(let t=0;t<=a.length;t+=1){if(t===i)continue;a.splice(t,0,e);let r=b(l);a.splice(t,1),z(r,o)&&(s=t,o=r)}a.splice(s,0,e),s!==i&&(t=!0)}}return M()},c=s(),p=[c,r()];for(let a of(o(c.map(e=>e.toReversed())),p.push(r()),p)){if(w>=4e6)break;o(a);let l=n();z(l,t)&&(t=l,e=s())}o(e)}let{count:C,weighted:_}=M(),q=e=>Math.max(0,...d[e].flatMap(e=>void 0===e.node?[]:[r.get(e.node).width])),L=Array.from({length:Math.max(0,i-1)},(e,t)=>t>0?q(t)+12:0),S=Array.from({length:Math.max(0,i-1)},(t,a)=>{let i=e.links.flatMap((e,t)=>l.get(e.target)===a+1?[n[t].width]:[]);return i.length>0?Math.max(...i)+12:0}),B=q(0)+12+q(i-1)+14*i+[...L,...S].reduce((e,t)=>e+t,0),A=x(),P=new Map,V=new Map,H=(e,t)=>e.toSorted((e,a)=>A.get(e[t])-A.get(a[t])||e.link-a.link);for(let e of d)for(let t of e)P.set(t,H(u.get(t)??[],"to")),V.set(t,H(g.get(t)??[],"from"));let I=(e,t)=>{let a=0;for(let l of e){if(l===t)break;a+=l.width}return a},$=e=>e.from.y+I(P.get(e.from),e),F=e=>e.to.y+I(V.get(e.to),e),O=(e,t)=>{let a=0;e.forEach((t,l)=>{l>0&&(a+=m(e[l-1],t)),t.y=Math.max(t.y,a),a=t.y+t.height});let l=t;for(let t=e.length-1;t>=0;t-=1){let a=e[t];a.y=Math.min(a.y,l-a.height),t>0&&(l=a.y-m(e[t-1],a))}},E=Math.max(...d.map(t=>t.reduce((t,a)=>{let l=t=>(t??[]).reduce((t,a)=>t+e.links[a.link].value,0);return t+Math.max(l(g.get(a)),l(u.get(a)))},0))),U=(e,t=1)=>{y(e);let a=Math.max(...d.map(v));return(e=>{for(let t of d){let a=(e-v(t))/2;t.forEach((e,l)=>{l>0&&(a+=m(t[l-1],e)),e.y=a,a+=e.height})}for(let t=0;t<24;t+=1){let a=.9**t*.8;for(let t=1;t<i;t+=1){for(let e of d[t]){let t=g.get(e)??[],l=t.reduce((e,t)=>e+t.width,0);if(0===l)continue;let i=t.reduce((t,a)=>t+a.width*($(a)-(F(a)-e.y)),0)/l;e.y+=(i-e.y)*a}O(d[t],e)}for(let t=i-2;t>=0;t-=1){for(let e of d[t]){let t=u.get(e)??[],l=t.reduce((e,t)=>e+t.width,0);if(0===l)continue;let i=t.reduce((t,a)=>t+a.width*(F(a)-($(a)-e.y)),0)/l;e.y+=(i-e.y)*a}O(d[t],e)}}for(let t of h){if(t.length<2)continue;let a=$(t[0]),l=F(t.at(-1)),i=t[0].from.column,s=t.at(-1).to.column-i;for(let o of t.slice(1)){let t=o.from,r=d[t.column],n=r.indexOf(t),c=r[n-1],p=r[n+1],h=c?c.y+c.height+m(c,t):0,g=p?p.y-m(t,p)-t.height:e-t.height,u=a+(l-a)*(t.column-i)/s;h<=g&&(t.y=Math.min(g,Math.max(h,u)))}}})(a),{height:a,runs:f.map(e=>t*Math.min(340,Math.max(120,.7*Math.max(0,...e.map(e=>Math.abs($(e)-F(e))))))),bars:Math.max(...d.map(e=>e.reduce((e,t)=>e+t.height,0)))}},X=360/E;for(let e=0;e<2;e+=1){let{height:e,runs:t,bars:a}=U(X),l=(B+t.reduce((e,t)=>e+t,0))/2.2-60;if(e>=l-1||a>=1400)break;X*=Math.min(1400,a+(l-e))/a}let T=(t,s=1)=>{let{runs:d,bars:p,height:g}=U(t,s),f=[],m=0;for(let e=0;e<i;e+=1)f.push(m),e<i-1&&(m+=14+L[e]+d[e]+S[e]);let v=e.nodes.map(e=>{let t=c.get(e.id),l=r.get(e.id),s=f[t.column],n=t.y+t.height/2-l.height/2,d=0===t.column&&i>1?"right":"left",p="right"===d?s-6-l.width:s+14+6,h=a.get(e.id),g={left:p,top:n,right:p+l.width,bottom:n+l.height};return{...t.column>0&&t.column<i-1&&(u.get(t)?.length??0)>0?{knockout:{left:g.left-3,top:g.top,right:g.right+3,bottom:g.bottom}}:{},id:e.id,label:e.label,color:o.get(e.id),column:t.column,x:yU(s),y:yU(t.y),width:14,height:yU(Math.max(t.height,.5)),inflow:h.inflow,outflow:h.outflow,total:h.total,text:{...l,fontSize:14,align:d,box:g}}}),y=(e,t,a,l)=>{let i,s=[],o=Math.max(6,Math.min(20,Math.floor((125-6*(i=e.length))/i)));for(let i of e){let e=i.from.column,r=f[e]+14,n=f[e+1],d=a(i)+t(i),c=l(i)+t(i),p=r+L[e],h=n-S[e];0===s.length&&s.push({x:r,y:d}),p>r&&s.push({x:p,y:d});for(let e=1;e<=o;e+=1)s.push(yZ(p,d,h,c,e/o));h<n&&s.push({x:n,y:c}),void 0===i.to.node&&s.push({x:n+14,y:c})}return s.map(e=>({x:yU(e.x),y:yU(e.y)}))},w=e.links.map((e,t)=>{let a=h[t],l=a[0].width,i=y(a,()=>0,$,F),s=y(a,()=>l,$,F);return{index:t,source:e.source,target:e.target,value:e.value,width:yU(l),color:o.get(e.source),sourceTop:yU($(a[0])),targetTop:yU(F(a.at(-1))),points:[...i,...s.toReversed()]}}),x=v.map(e=>e.knockout??e.text.box),b=v.map(e=>({left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})),k=w.map(e=>({band:e,bounds:yG(e.points)})),M=[],z=(e,t,a=0)=>{let l={left:e.left-a,top:e.top-a,right:e.right+a,bottom:e.bottom+a};return!x.some(t=>yX(e,t,2))&&!M.some(([t,a])=>yT(t,a,e))&&!b.some(t=>yX(e,t,2))&&!k.some(({band:e,bounds:a})=>e.index!==t&&yD(l,e.points,a))},C=0,_=0,q=(e,t,a)=>{let l=n[e];return{...l,fontSize:12,align:"center",box:{left:t,top:a,right:t+l.width,bottom:a+l.height}}},A=w.map(e=>{let t=n[e.index],a=f[l.get(e.target)]-6;return q(e.index,a-t.width,e.targetTop+(e.width-t.height)/2)}),P=e=>e.width>=n[e.index].height+2;for(let e of w)P(e)&&x.push(A[e.index].box);return{nodes:v,bands:w.map(e=>{let t,a=n[e.index],i=f[l.get(e.target)-1+1]-6,s=(t,a)=>q(e.index,t,a),o=A[e.index];if(P(e))return{...e,text:o};let r=h[e.index],d=f[r[0].from.column]+14+6,c=[s(i-a.width,e.targetTop-a.height-1),s(i-a.width,e.targetTop+e.width+1),s(d,e.sourceTop-a.height-1),s(d,e.sourceTop+e.width+1)],p=[];for(let t of[.5,.4,.6,.3,.7,.2,.8,.1,.9])for(let l of r){let i=l.from.column,o=f[i]+14+L[i],r=f[i+1]-S[i],n=$(l),d=F(l),c=yZ(o,n,r,d,t).x-a.width/2,h=[c,c+a.width].map(e=>(function(e,t,a,l,i){if(i<=e)return t;if(i>=a)return l;let s=0,o=1;for(let r=0;r<24;r+=1){let r=(s+o)/2;yZ(e,t,a,l,r).x<i?s=r:o=r}return yZ(e,t,a,l,(s+o)/2).y})(o,n,r,d,e));p.push(s(c,Math.min(...h)-a.height-2),s(c,Math.max(...h)+e.width+2))}let g=c.find(t=>z(t.box,e.index))??p.find(t=>z(t.box,e.index,5))??(z(o.box,e.index)?o:void 0);if(g)return x.push(g.box),{...e,text:g};C+=1;let u=[];for(let t of[.5,.3,.7])for(let a of r){let l=a.from.column,i=f[l]+14+L[l],s=f[l+1]-S[l],o=yZ(i,$(a),s,F(a),t);u.push({x:o.x,y:o.y+e.width/2})}let m=(e,t)=>![...x,...b].some(a=>yT(e,t,a));for(let l of yO){for(let i of u)for(let o=0;o<16;o+=1){let r=o*Math.PI/8,n={x:i.x+l*Math.cos(r)*1.6,y:i.y+l*Math.sin(r)},d=s(n.x-a.width/2,n.y-a.height/2);if(!z(d.box,e.index,5))continue;let c={x:Math.min(Math.max(i.x,d.box.left),d.box.right),y:Math.min(Math.max(i.y,d.box.top-1),d.box.bottom+1)};if(!m(i,c))continue;let p=k.filter(({band:t,bounds:a})=>t.index!==e.index&&function(e,t,a,l=yG(a)){if(!yT(e,t,{left:l.left-.01,top:l.top-.01,right:l.right+.01,bottom:l.bottom+.01}))return!1;if(yY(e,a)||yY(t,a))return!0;for(let l=0;l<a.length;l+=1)if(yR(e,t,a[l],a[(l+1)%a.length]))return!0;return!1}(i,c,t.points,a)).length;(!t||p<t.crossed)&&(t={text:d,leader:[i,c],crossed:p})}if(t)break}if(!t&&0===_){let l=[...b,...x,...k.map(e=>e.bounds)].reduce((e,t)=>({left:Math.min(e.left,t.left),top:Math.min(e.top,t.top),right:Math.max(e.right,t.right),bottom:Math.max(e.bottom,t.bottom)})),i=u[0],o=[],r=Math.max(8,Math.sqrt((l.right-l.left+a.width+16)*(l.bottom-l.top+a.height+16)/2500));for(let e=l.top-a.height-8;e<=l.bottom+8;e+=r)for(let t=l.left-a.width-8;t<=l.right+8;t+=r)o.push({x:t,y:e});for(let l of(o.sort((e,t)=>Math.hypot(e.x+a.width/2-i.x,e.y+a.height/2-i.y)-Math.hypot(t.x+a.width/2-i.x,t.y+a.height/2-i.y)),o)){let a=s(l.x,l.y);if(!z(a.box,e.index,5))continue;let o={x:Math.min(Math.max(i.x,a.box.left),a.box.right),y:Math.min(Math.max(i.y,a.box.top-1),a.box.bottom+1)};if(m(i,o)){t={text:a,leader:[i,o],crossed:0};break}}}t||(_+=1);let v=t??{text:o,leader:void 0};return x.push(v.text.box),v.leader&&M.push(v.leader),{...e,text:v.text,...v.leader?{leader:[{x:yU(v.leader[0].x),y:yU(v.leader[0].y)},{x:yU(v.leader[1].x),y:yU(v.leader[1].y)}]}:{}}}),crowdedValues:C,unplacedValues:_,bars:p,height:g,width:B+d.reduce((e,t)=>e+t,0)}},R=(e,t,a)=>{let l=X,i=T(l,e);for(let s=0;s<3&&i.crowdedValues>0;s+=1){let s=i.height+i.bars*(1.4-1);if(1.4*i.bars>a||s>i.width*t)break;let o=T(1.4*l,e);if(o.unplacedValues>i.unplacedValues||o.unplacedValues===i.unplacedValues&&o.crowdedValues>=i.crowdedValues)break;l*=1.4,i=o}return i},Y=R(1,1.25,1100);if(Y.unplacedValues>0){let e=R(1.8,3,2400);(e.unplacedValues<Y.unplacedValues||e.unplacedValues===Y.unplacedValues&&e.crowdedValues<Y.crowdedValues)&&(Y=e)}return{nodes:Y.nodes,bands:Y.bands,columns:i,crossings:C,weightedCrossings:_,work:w,crowdedValues:Y.crowdedValues,unplacedValues:Y.unplacedValues}}(e))},catch:e=>new b7({status:"render_failed",context:{...f,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render Sankey scene.",hint:"Repair the nodes and links and retry."})]}})}).pipe(o.fRP("codeMode.buildSankey.render")),v=i5(m);if(v.length>0)return yield*new b7({status:"render_failed",context:{...f,issues:kz(v).map(e=>({...e,hint:"Shorten labels, or split the flows into smaller diagrams, and retry buildSankey."}))}});let w=function(e){let t,a,l,i,s=[],{nodes:o,bands:r,texts:n}=(t=new Map(e.elements.flatMap(e=>"text"===e.type?[[e.id,e]]:[])),a=e.elements.filter(e=>"node"===e.type),l=new Map(e.elements.flatMap(e=>"line"===e.type?[[e.id,e]]:[])),i=new Map(a.flatMap(e=>{let t=/^sankey:knockout:([^:]+)$/u.exec(e.nodeId);return t?[[t[1],{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height}]]:[]})),{nodes:a.flatMap(e=>{let a=/^sankey:node:([^:]+)$/u.exec(e.nodeId);if(!a||"rectangle"!==e.shape)return[];let l=t.get(`text:${e.nodeId}`),s=i.get(a[1]);return[{...s?{knockout:s}:{},id:a[1],box:{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height},...l?{text:l.text,textBox:w9(l)}:{}}]}),bands:a.flatMap(e=>{let a=/^sankey:link:([^:]+):([^:]+)$/u.exec(e.nodeId);if(!a||"polygon"!==e.shape||!e.points)return[];let i=e.points.map(t=>({x:e.x+t.x,y:e.y+t.y})),s=xe(i,"left"),o=xe(i,"right"),r=t.get(`text:${e.nodeId}`),n=l.get(`leader:${e.nodeId}`);return[{...n?{leader:[n.points[0],n.points.at(-1)]}:{},source:a[1],target:a[2],points:i,bounds:yG(i),sourceEnd:s,targetEnd:o,width:Math.round((s.bottom-s.top)*100)/100,...r?{text:r.text,textBox:w9(r)}:{}}]}),texts:[...t.values()].map(e=>({id:e.id,text:e.text,box:w9(e),maxWidth:e.maxWidth??iC(e.text,e.fontSize),fontSize:e.fontSize}))}),d=new Map(o.map(e=>[e.id,e]));for(let e of o){let t={out:r.filter(t=>t.source===e.id).map(e=>e.sourceEnd),in:r.filter(t=>t.target===e.id).map(e=>e.targetEnd)},a={out:0,in:0};for(let l of["out","in"]){let i="out"===l?e.box.right:e.box.left,o=-1/0;for(let r of t[l].toSorted((e,t)=>e.top-t.top))(Math.abs(r.x-i)>.6||r.top<e.box.top-.6||r.bottom>e.box.bottom+.6||r.top<o-.6)&&s.push({code:"band-off-node",elementId:`node:sankey:node:${e.id}`,message:`A band at the ${"out"===l?"right":"left"} of "${e.id}" leaves its bar or overlaps another band.`}),o=r.bottom,a[l]+=r.bottom-r.top}let l=e.box.bottom-e.box.top;(Math.abs(Math.max(a.in,a.out)-l)>.6||Math.min(a.in,a.out)>l+.6)&&s.push({code:"side-unbalanced",elementId:`node:sankey:node:${e.id}`,message:`The bands at "${e.id}" sum to ${a.in.toFixed(2)} in and ${a.out.toFixed(2)} out on a bar ${l.toFixed(2)} tall.`})}for(let e of r){let t=`node:sankey:link:${e.source}:${e.target}`,a=d.get(e.source),l=d.get(e.target);if((!a||!l||e.bounds.left<a.box.right-.6||e.bounds.right>l.box.left+.6)&&s.push({code:"band-leaves-gap",elementId:t,message:`Band "${e.source}" → "${e.target}" runs outside the gap between its bars.`}),e.leader){let a=[...o.map(e=>({id:`node:sankey:node:${e.id}`,box:e.box})),...n.filter(t=>t.id!==`text:sankey:link:${e.source}:${e.target}`)].find(t=>yT(e.leader[0],e.leader[1],t.box));a&&s.push({code:"leader-over-label",elementId:t,message:`The leader of "${e.source}" → "${e.target}" crosses "${a.id}".`})}for(let a of o)a.id!==e.source&&a.id!==e.target&&yD(a.box,e.points,e.bounds)&&s.push({code:"band-over-node",elementId:t,message:`Band "${e.source}" → "${e.target}" runs over "${a.id}".`})}for(let[e,t]of n.entries()){for(let a of(t.text.split("\n").some(e=>iC(e,t.fontSize)>t.maxWidth+.5)&&s.push({code:"text-overflow",elementId:t.id,message:`Text "${t.id}" is wider than its box.`}),n.slice(e+1)))yX(t.box,a.box)&&s.push({code:"labels-overlap",elementId:t.id,message:`Labels "${t.id}" and "${a.id}" overlap.`});for(let e of o)yX(t.box,e.box)&&s.push({code:"label-over-node",elementId:t.id,message:`Label "${t.id}" covers bar "${e.id}".`});let a=/^text:sankey:(node|link):([^:]+)(?::([^:]+))?$/u.exec(t.id);for(let e of r)!(a?.[1]==="link"?a[2]===e.source&&a[3]===e.target:a?.[1]==="node"&&a[2]===e.source)&&yD(t.box,e.points,e.bounds)&&s.push({code:"label-over-band",elementId:t.id,message:`Label "${t.id}" covers band "${e.source}" → "${e.target}".`});if(a?.[1]==="node"){let e=d.get(a[2]),l=e?.knockout;if(!(void 0!==l&&l.left<=t.box.left+.5&&l.right>=t.box.right-.5&&l.top<=t.box.top+.5&&l.bottom>=t.box.bottom-.5)&&r.some(e=>e.source===a[2]&&yD(t.box,e.points,e.bounds))&&s.push({code:"label-on-band",elementId:t.id,message:`Label "${t.id}" sits on its own bands with no paper behind it.`}),l)for(let e of r)e.source!==a[2]&&yD(l,e.points,e.bounds)&&s.push({code:"label-on-band",elementId:t.id,message:`The paper behind "${t.id}" hides band "${e.source}" → "${e.target}".`})}if(a?.[1]==="link"){let e=r.find(e=>e.source===a[2]&&e.target===a[3]),l=e&&d.get(e.source),i=e&&d.get(e.target),o=[{x:t.box.left,y:t.box.top},{x:t.box.right,y:t.box.top},{x:t.box.right,y:t.box.bottom},{x:t.box.left,y:t.box.bottom}],n=void 0!==e&&o.every(t=>yY(t,e.points)),c=void 0!==i&&1>=Math.abs(t.box.right-(i.box.left-6))||void 0!==l&&1>=Math.abs(t.box.left-(l.box.right+6));if(e&&!n&&!c){let a={left:t.box.left-4,top:t.box.top-4,right:t.box.right+4,bottom:t.box.bottom+4};for(let l of r)l!==e&&yD(a,l.points,l.bounds)&&s.push({code:"label-on-band",elementId:t.id,message:`Value "${t.id}" sits within 4 px of band "${l.source}" → "${l.target}".`})}}}return s}(m);if(w.length>0){let e=`${w.length} labels, values or leaders would overlap another label or cover another flow, so the diagram would not read.`;return yield*new b7({status:"quality_failed",context:{...h,quality:{...u,accepted:!1,score:0,checks:[{code:"sankey_layout",passed:!1,severity:"error",message:e,refs:[]}]},issues:[kn({code:"quality_below_threshold",stage:"quality",ref:{kind:"diagram",id:p.id},message:e,hint:"Shorten node and link labels or leave link labels out, or split the flows into smaller diagrams, then call buildSankey again."})]}})}let x={...f,partial:kZ(m)},b=yield*kW({scene:m,formats:kw(d.options),inlineFormats:kx(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b7({status:e.status,context:{..."export_failed"===e.status?x:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...kG(d.requestId),normalizedSpec:p,quality:u,artifact:b,issues:[]}}),k6=o.fn("codeMode.buildWireframe.workflow")(function*(e){var t,a;let l,s,r,n=i.q$Z(nq,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:function(e){if(!lQ(e))return e;let t={...e},a=l1(t,["screens","pages","views","frames"],!0),l=["children","components","elements","layout","body"].find(e=>Array.isArray(t[e]));if(void 0===a&&void 0!==l){let e=l1(t,[l]);if(Array.isArray(e)){let l=l1(t,["device","platform","viewport"]);a=[{name:t.title??"Screen",...void 0===l?{}:{device:l},children:e}]}}if(!Array.isArray(a))return void 0===a?t:{...t,screens:a};let i=new Set(a.flatMap(e=>lQ(e)&&"string"==typeof e.id?[e.id]:[])),s=a.map((e,t)=>{if(!lQ(e))return e;let a={...e},l=l0(l1(a,["name","title","label"])),s=l1(a,l8,!0),o=l1(a,["device","platform","viewport","size","form"]),r=a.align,n="string"==typeof o?l2(ia,l3(o))??o:o,d=a.id;if("string"!=typeof d||0===d.length){let e=("string"==typeof l?l:"").toLowerCase().normalize("NFKD").replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||`screen-${t+1}`,a=e;for(let t=2;i.has(a);t+=1)a=`${e}-${t}`;i.add(a),d=a}let c="string"==typeof r?it({type:"column",align:r}):{};return{...a,id:d,...void 0===l?{}:{name:l},...void 0===n?{}:{device:n},...lQ(c)&&void 0!==c.align?{align:c.align}:{},...Array.isArray(s)?{children:s.map(it)}:void 0===s?{}:{children:s}}}),o=new Set,r=new Map,n=new Map,d=(e,t,a)=>e.set(t,e.has(t)&&e.get(t)!==a?void 0:a);for(let e of s)lQ(e)&&"string"==typeof e.id&&(o.add(e.id),d(r,l3(e.id),e.id),"string"==typeof e.name&&d(n,l3(e.name),e.id));let c=e=>{if(!lQ(e))return e;let t=e.target,a="string"==typeof t?(e=>{if(o.has(e))return e;let t=l3(e).replace(/^[#/]+/u,"");return r.has(t)?r.get(t):n.get(t)})(t):void 0,l=e.children;return{...e,...void 0===a||a===t?{}:{target:a},...Array.isArray(l)?{children:l.map(c)}:{}}};return{...t,screens:s.map(e=>lQ(e)&&Array.isArray(e.children)?{...e,children:e.children.map(c)}:e)}}(e.spec)}:e);if(!xH.oJ(n))return yield*new b8({status:"invalid_input",context:{issues:kf(os(n.failure))}});let d=yield*bm,c=n.success,p=yield*o.OH5(()=>d.createId("build")),h=(l=oe((t=c.spec).title),s=new Set(t.screens.flatMap(e=>kv(e.id)??[])),{id:kv(t.id)??(km(l)||"sketchi-wireframe"),title:l,screens:t.screens.map((e,t)=>{let a=oe(e.name);return{id:kv(e.id)??((e,t)=>{let a=km(e)||`screen-${t+1}`,l=a;for(let e=2;s.has(l);e+=1)l=`${a}-${e}`;return s.add(l),l})(a,t),name:a,device:e.device??"desktop",...e.align?{align:e.align}:{},children:e.children.map(bU)}}),style:{...y}}),g={buildId:p,...kG(c.requestId),normalizedSpec:h},u=lN(bX(h)).map(e=>kn({code:bT[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(u.length>0)return yield*new b8({status:"invalid_wireframe",context:{...g,issues:u}});let f=(a=c.options?.minQualityScore??8,r=e=>e.reduce((e,t)=>e+1+r(t.children??[]),0),{accepted:10>=a,score:10,threshold:a,summary:{nodeCount:h.screens.reduce((e,t)=>e+r(t.children),0),edgeCount:0},checks:[]}),m={...g,quality:f};if(!f.accepted)return yield*new b8({status:"quality_failed",context:{...m,issues:ky(f)}});let v=yield*o.SvU({try:()=>(function(e){let t,a,l,i=lJ(e),{placed:s,origins:o,frames:r}=(a=function(e){let t=t=>{let a=[],l=0,i=0;for(let s=0;s<e.length;s+=t){let o=e.slice(s,s+t),r=0;for(let e of o)a.push({x:r,y:l}),r+=e.width+80;i=Math.max(i,r-80),l+=Math.max(...o.map(e=>e.height))+96}return{origins:a,aspect:i/Math.max(1,l-96)}},a=e.length;for(;a>1&&t(a).aspect>2.45;)a-=1;let l=Math.ceil(e.length/a);return t(Math.ceil(e.length/l)).origins}(t=i.screens.map(wF)),l=t.map((e,t)=>({type:"frame",id:`frame:${e.screen.id}`,name:e.screen.name.replace(/\s*\n\s*/gu," "),x:a[t].x,y:a[t].y,width:e.width,height:e.height})),{placed:t,origins:a,frames:l}),n=s.map((e,t)=>(function(e,t){let{screen:a}=e,l=`frame:${a.id}`,i=[],s=[],o=[],r=(e,t,n,d,c,p,h,g=[])=>{var u;let f={x:t+e.x,y:n+e.y,width:e.width,height:e.height},m=`group:${a.id}:${e.path}`,v=(u=e.component,lU.has(u.type)),y=!v||ww.has(e.component.type)?[m,...d]:d,w=!0===e.component.disabled?50:h,x={groupIds:y,frameId:l,...void 0===w?{}:{opacity:w}},b=`wf:${a.id}:${e.path}`,{target:k}=e.component,M=void 0!==k&&("button"===e.component.type||"link"===e.component.type);for(let t of(M&&"link"===e.component.type&&i.push({...wm(`${b}:hit`,"link-target",f,wn,{fill:wi,stroke:wi},e.component.text??"Link",x),opacity:0}),i.push(...e.paint(f,x,b)),M&&o.push({screen:a.id,path:e.path,target:k,nodeId:"link"===e.component.type?`${b}:hit`:`${b}:box`,box:f,ancestors:new Set(g)}),s.push({path:e.path,type:e.component.type,box:f,parent:c,...e.flow?{flow:e.flow}:{},overlay:p,group:m}),e.children))r(t,f.x,f.y,v&&ww.has(e.component.type)?y:d,e.path,p,w,[...g,e.path])};for(let s of e.laid){let o=e.modals.has(s.path);o&&e.scrim&&!i.some(e=>e.id===`wf:${a.id}:scrim`)&&i.push({...wm(`wf:${a.id}:scrim`,"scrim",{x:t.x,y:t.y,width:e.width,height:e.height},wd,{fill:wr,stroke:wr},"Backdrop",{groupIds:[],frameId:l}),opacity:30}),r(s,t.x,t.y,[],void 0,o,void 0)}return{elements:i,components:s,navigations:o}})(e,o[t])),d=n.flatMap(e=>e.navigations),c=new Set(d.map(e=>e.target)),p=r.map((e,t)=>{let a=s[t].screen.id;return c.has(a)?{...e,nodeId:wE(a)}:e}),h=function(e,t,a){var l;let i;if(0===e.length)return[];let s=new Map(t.map(e=>[e.id,e])),o=t.map(e=>sT(e)),r=[...t,...o],n={x:Math.min(...r.map(e=>e.x))-64,y:Math.min(...r.map(e=>e.y))-64,width:Math.max(...r.map(e=>e.x+e.width))-Math.min(...r.map(e=>e.x))+128,height:Math.max(...r.map(e=>e.y+e.height))-Math.min(...r.map(e=>e.y))+128},d=new Map(a.map((e,a)=>[t[a].id,e])),c=(l=e.map(e=>{let a=s.get(`frame:${e.screen}`),l=s.get(`frame:${e.target}`),i=d.get(a.id),r=`wf:${e.screen}:${e.path}:`,n=i.components.find(t=>t.path===e.path)?.overlay===!0,c=i.elements.findIndex(e=>"node"===e.type&&"wireframe:scrim"===e.kind);return{source:e.box,target:l,obstacles:[...t.filter(e=>e!==a&&e!==l),...o,...i.components.filter(t=>t.path!==e.path&&!e.ancestors.has(t.path)&&!t.path.startsWith(`${e.path}.`)&&(!n||t.overlay)).map(e=>e.box),...i.elements.flatMap((e,t)=>{let a,l;return"text"!==e.type||e.id.startsWith(r)||e.containerId||n&&!(t>c)?[]:[(a=Math.max(1,Math.min(e.maxWidth??160,Math.ceil(iC(e.text,e.fontSize)))),l=wp(e.text.split("\n").length,e.fontSize),{x:e.x-a/2,y:e.y-l/2,width:a,height:l})]})]}}),i=[],l.map(e=>{let t=function(e,t,a){var l;let i,{source:s,target:o}=e,r=y3(s.y+s.height/2),n=(l=[...e.obstacles,s]).filter((e,t)=>!l.some((a,l)=>l!==t&&y2(a,e)&&(!y2(e,a)||l<t))).map(e=>({left:e.x-4,top:e.y-4,right:e.x+e.width+4,bottom:e.y+e.height+4})),d={left:y3(o.x),top:y3(o.y),right:y3(o.x+o.width),bottom:y3(o.y+o.height)},c=y3(s.x+s.width+4),p=y3(s.x-4),h=y5([t.x,t.x+t.width,p,c,d.left,d.right,d.left+24,d.right-24,d.left-28,d.right+28,...n.flatMap(e=>[e.left,e.right])],t.x,t.x+t.width),g=y5([t.y,t.y+t.height,r,d.top,d.bottom,d.top+24,d.bottom-24,d.top-28,d.bottom+28,...n.flatMap(e=>[e.top,e.bottom])],t.y,t.y+t.height),u=h.length,f=g.length,m=(e,t)=>t*u+e,v=(e,t,a)=>t>e.left&&t<e.right&&a>e.top&&a<e.bottom,y=(e,t)=>v(d,e,t)||n.some(a=>v(a,e,t)),w=(e,t)=>e>=d.left&&e<=d.right&&t>=d.top&&t<=d.bottom&&!v(d,e,t),x=new Uint8Array(u*f);for(let e=0;e<f;e+=1)for(let t=0;t<u;t+=1)x[m(t,e)]=+!y(h[t],g[e]);let b=(e,t,a,l)=>!y((e+a)/2,(t+l)/2),k=new Float64Array(u*f*4).fill(1/0),M=new Int32Array(u*f*4).fill(-1),z=new Float64Array(u*f*4),C=new y0,_=(e,t)=>Math.max(0,d.left-e,e-d.right)+Math.max(0,d.top-t,t-d.bottom),q=g.indexOf(r),L=(e,t)=>{let a=h.indexOf(e);if(a<0||q<0||!x[m(a,q)])return;let l=4*m(a,q)+t;k[l]=0,C.push(_(e,r),l)};L(c,0),L(p,2);let S=0,B=1/0;for(;C.size>0&&S<4e5;){let{cost:e,state:t}=C.pop();if(e>=B)break;let l=k[t],s=Math.floor(t/4),o=t%4,r=s%u,n=Math.floor(s/u),c=h[r],p=g[n];if(!(e-_(c,p)>l+1e-6))for(let[e,s]of(S+=1,y1.entries())){if((e+2)%4===o)continue;let v=r+s.dx,y=n+s.dy;if(v<0||y<0||v>=u||y>=f)continue;let q=h[v],L=g[y],S=Math.abs(q-c)+Math.abs(L-p),A=48*(e!==o),P=(e===o?z[t]:0)+S;if(w(q,L)){let e=0!==s.dx&&(q===d.left||q===d.right)||0!==s.dy&&(L===d.top||L===d.bottom),a=0!==s.dx?L>=d.top+24&&L<=d.bottom-24:q>=d.left+24&&q<=d.right-24,o=l+A+S;e&&a&&P>=28&&b(c,p,q,L)&&o<B&&(B=o,i={state:t,end:{x:q,y:L}});continue}let V=m(v,y);if(!x[V]||!b(c,p,q,L))continue;let H=4*V+e,I=l+S+A+function(e,t,a){let l=.01>Math.abs(e.y-t.y),i=l?Math.min(e.x,t.x):Math.min(e.y,t.y),s=l?Math.max(e.x,t.x):Math.max(e.y,t.y),o=l?e.y:e.x,r=0;for(let e of a)for(let t=1;t<e.length;t+=1){let a=e[t-1],n=e[t],d=.01>Math.abs(a.y-n.y),c=d?Math.min(a.x,n.x):Math.min(a.y,n.y),p=d?Math.max(a.x,n.x):Math.max(a.y,n.y),h=d?a.y:a.x;if(d===l){if(Math.abs(h-o)>=6)continue;let e=Math.min(s,p)-Math.max(i,c);e>0&&(r+=60*e)}else h>=i&&h<=s&&o>=c&&o<=p&&(r+=16)}return r}({x:c,y:p},{x:q,y:L},a);I<k[H]&&(k[H]=I,M[H]=t,z[H]=P,C.push(I+_(q,L),H))}}if(!i)return;let A=[];for(let e=i.state;e>=0;e=M[e]){let t=Math.floor(e/4);A.push({x:h[t%u],y:g[Math.floor(t/u)]})}return A.reverse(),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 l=t.at(-2);l&&e&&(.01>Math.abs(l.x-e.x)&&.01>Math.abs(e.x-a.x)||.01>Math.abs(l.y-e.y)&&.01>Math.abs(e.y-a.y))&&t.pop(),t.push(a)}return t}([{x:A[0].x>s.x?s.x+s.width:s.x,y:r},...A,i.end])}(e,n,i);return t&&i.push(t),t}));return e.flatMap((e,t)=>{let a=c[t];if(!a||a.length<2)return[];let l=wU(e.screen,e.path);return[{type:"arrow",id:l,edgeId:l,sourceNodeId:e.nodeId,targetNodeId:wE(e.target),points:a,startArrowhead:null,endArrowhead:"arrow",strokeColor:y9,strokeWidth:2}]})}(d,p,n),g=p.map(e=>sT(e)),u=h.flatMap(e=>e.points),f=Math.min(...p.map(e=>e.x),...u.map(e=>e.x)),m=Math.min(...g.map(e=>e.y),...u.map(e=>e.y)),v=40-f,y=40-m,w=[...p.map(e=>wO(e,v,y)),...n.flatMap(e=>e.elements.map(e=>wO(e,v,y))),...h.map(e=>wO(e,v,y))],x=Math.max(...p.map(e=>e.x+e.width),...u.map(e=>e.x)),b=Math.max(...p.map(e=>e.y+e.height),...u.map(e=>e.y)),k={kind:"canvas",version:1,diagramId:i.id,title:i.title,width:Math.ceil(x+v+40),height:Math.ceil(b+y+40),accentColor:i.style.accentColor,backgroundColor:i.style.backgroundColor,elements:w,layers:[],layouts:[],zOrder:w.map(e=>e.id)},M=e=>({...e,x:e.x+v,y:e.y+y}),z=new Set(h.map(e=>e.id));return{scene:k,layout:{screens:s.map((e,t)=>({id:e.screen.id,device:e.screen.device,frame:M(p[t]),widened:e.widened,components:n[t].components.map(e=>({...e,box:M(e.box)}))})),navigations:d.map(e=>({screen:e.screen,path:e.path,target:e.target,routed:z.has(wU(e.screen,e.path))}))}}})(bX(h)).scene,catch:e=>new b8({status:"render_failed",context:{...m,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:h.id},message:e instanceof Error?e.message:"Unable to render wireframe scene.",hint:"Repair the screens and components and retry."})]}})}).pipe(o.fRP("codeMode.buildWireframe.render")),w=i5(v);if(w.length>0)return yield*new b8({status:"render_failed",context:{...m,issues:kz(w).map(e=>({...e,hint:"Shorten long texts, or split the screens into separate wireframes, and retry buildWireframe."}))}});let x={...m,partial:kZ(v)},b=yield*kW({scene:v,formats:kw(c.options),inlineFormats:kx(c.options),...c.requestId?{requestId:c.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b8({status:e.status,context:{..."export_failed"===e.status?x:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:p,...kG(c.requestId),normalizedSpec:h,quality:f,artifact:b,issues:[]}}),k7=o.fn("codeMode.buildQuadrantChart.workflow")(function*(e){var t,a;let l,s,r=i.q$Z(nS,{errors:"all",reportInput:!0})(e);if(!xH.oJ(r))return yield*new ke({status:"invalid_input",context:{issues:kf(os(r.failure))}});let n=yield*bm,d=r.success,c=yield*o.OH5(()=>n.createId("build")),p=(l=oe((t=d.spec).title),s=e=>({title:oe(e.title),low:oe(e.low),high:oe(e.high)}),{id:kv(t.id)??(km(l)||"sketchi-quadrant-chart"),title:l,xAxis:s(t.xAxis),yAxis:s(t.yAxis),quadrants:{topLeft:oe(t.quadrants.topLeft),topRight:oe(t.quadrants.topRight),bottomLeft:oe(t.quadrants.bottomLeft),bottomRight:oe(t.quadrants.bottomRight)},points:t.points.map(e=>{let t=kv(e.group);return{label:oe(e.label),x:e.x,y:e.y,...t?{group:t}:{}}}),style:{...y}}),h={buildId:c,...kG(d.requestId),normalizedSpec:p},g=bD(ih(bR(p)));if(g.length>0)return yield*new ke({status:"invalid_quadrant_chart",context:{...h,issues:g}});let u={accepted:10>=(a=d.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:p.points.length,edgeCount:0},checks:[]},f={...h,quality:u};if(!u.accepted)return yield*new ke({status:"quality_failed",context:{...f,issues:ky(u)}});let m=yield*o.SvU({try:()=>(function(e){let t,a,l,i,s,o,r,n,d,c,p,h,g,u,f,m,v=iu(e),y=v.style.backgroundColor,w=new w8(y),x=function(e){let t,a,l,i,s,o=(i=Math.max(...ii.map(t=>Math.max(...e.quadrants[t].split(/\s+/u).map(e=>Math.ceil(iC(e,16)))))),s=wD(e.xAxis.low,170,13).width+wD(e.xAxis.high,170,13).width+16,wX.find(e=>i<=e/2-20&&s<=e));if(void 0===o)throw new ig([{code:"invalid_quadrant_text",path:"quadrants",message:"A quadrant name or the x axis's end labels hold a word too long for the largest plot.",hint:"Shorten the longest unbroken word in the quadrant names and the x axis's low and high labels, or break it with a space."}]);let r=Math.max(2,Math.ceil(.2*e.points.length)),n=e=>[e.blocked+e.covered,e.overDots,e.leaders],d=(e,t)=>{let[a,l]=[n(e),n(t)],i=a.findIndex((e,t)=>e!==l[t]);return -1!==i&&a[i]>l[i]},c=e=>e.blocked+e.covered+e.overDots===0,p=e=>c(e)&&e.leaders<=r+e.clumped,h={spent:0,limit:1/0},g=a=>{let l=w7(e,a,{work:h}),i=l.blocked>0&&l.blocked<=Math.max(3,e.points.length/4);if(i){let t=w7(e,a,{crowded:new Set(l.blockedPoints),work:h});d(t,l)||(l=t)}if(i&&l.blocked){let t=w7(e,a,{crowded:new Set(l.blockedPoints),relaxed:!0,work:h});d(t,l)||(l=t)}return(!t||d(t,l))&&(t=l),l},u=()=>{let l=new Set(t.blockedPoints);for(let a of[{labelFont:12},{labelFont:12,thorough:!0},{labelFont:12,relaxed:!0},{labelFont:12,relaxed:!0,thorough:!0}]){if(0===t.blocked&&a.relaxed||h.spent>h.limit)break;let i=w7(e,wX.at(-1),{crowded:l,work:h,...a});if(d(t,i)&&(t=i),c(t))break}a=t},f=wX.filter(e=>e>=o),m=0,v=0;for(;m<f.length&&!(t&&c(t)&&m-f.indexOf(t.size)>2);){let e=g(f[m]);if(m+=1,p(e))return e;if(v=e.blocked>3&&void 0!==l&&e.blocked>=l?v+1:0,l=e.blocked,v>=2)break}if(!c(t)&&t.blocked+t.covered<=3&&u(),t.blocked||t.covered){for(h.limit=h.spent+4e6;m<f.length&&h.spent<=h.limit;m+=1){let e=g(f[m]);if(p(e))return e}t!==a&&u()}if(t.blocked||t.covered)throw new ig([{code:"quadrant_too_large",path:t.blocked?`points.[${t.blockedPoints[0]}]`:"quadrants",message:t.blocked?`The labels of ${t.blocked} points cannot all sit clear of the other labels and dots.`:"A quadrant name cannot sit clear of every dot in its quadrant.",hint:"Spread the scores of points that nearly coincide, shorten their labels or the quadrant names, or split the chart."}]);return t}(v),{size:b}=x,k=wJ(b);for(let e of Object.keys(k)){let t=function(e,t){let a=(e,t)=>Number.parseInt(e.slice(t,t+2),16);return`#${[1,3,5].map(l=>Math.round(.89*a(t,l)+.11*a(e,l)).toString(16).padStart(2,"0")).join("")}`}(wY[e],y),a=`quadrant:region:${e}`;w.mark(a,"rectangle",k[e],v.quadrants[e],{fillColor:t,strokeColor:t,groupIds:[a]},"back");let l=x.names[e];w.text(`quadrant:name:${e}`,l.text,l.box,16,wR,"topRight"===e||"bottomRight"===e?"right":"left",a)}let M={strokeColor:"#a99f8c"};w.line("quadrant:midline:vertical",{x:b/2,y:0},{x:b/2,y:b},M),w.line("quadrant:midline:horizontal",{x:0,y:b/2},{x:b,y:b/2},M),t={strokeColor:wR,strokeWidth:2,endArrowhead:"arrow"},a="quadrant:axis:x",l="quadrant:axis:y",w.line(a,{x:0,y:b+14},{x:b,y:b+14},{...t,groupIds:[a]}),w.line(l,{x:-14,y:b},{x:-14,y:0},{...t,groupIds:[l]}),i=b+14+8,s=wD(v.xAxis.low,170,13),o=wD(v.xAxis.high,170,13),r=wD(v.xAxis.title,b,14),n=wZ(0,i,s),d=wZ(b-o.width,i,o),(wj(c=wZ(b/2-r.width/2,i,r),n,16)||wj(c,d,16))&&(c=wZ(b/2-r.width/2,Math.max(n.bottom,d.bottom)+4,r)),w.text(`${a}:low`,s,n,13,wR,"left",a),w.text(`${a}:high`,o,d,13,wR,"right",a),w.text(`${a}:title`,r,c,14,wT,"center",a),p=wD(v.yAxis.high,130,13),h=wD(v.yAxis.low,130,13),g=wD(v.yAxis.title,130,14),u=wZ(-22-p.width,0,p),f=wZ(-22-h.width,b-h.height,h),m=Math.min(Math.max(b/2-g.height/2,u.bottom+12),f.top-12-g.height),w.text(`${l}:high`,p,u,13,wR,"right",l),w.text(`${l}:low`,h,f,13,wR,"right",l),w.text(`${l}:title`,g,wZ(-22-g.width,m,g),14,wT,"right",l);let z=ip(v),C=new Map(z.map((e,t)=>[e,pT[t]])),_={left:0,top:0,right:b,bottom:b};v.points.forEach((e,t)=>{let a,l=`quadrant:point:${t}`,i=wK(e,_),s=void 0===(a=e.group)?void 0:z.find(e=>ic(e)===ic(a)),o=void 0!==s?C.get(s):z.length?"#8c826f":pT["0"];w.mark(l,"ellipse",w1(i),e.label,{fillColor:o,strokeColor:y,strokeWidth:2,groupIds:[l]},"front");let r=x.labels[t];r.leader&&w.line(`quadrant:leader:${t}`,r.leader[0],r.leader[1],{strokeColor:"#8c826f",groupIds:[l]}),w.text(`quadrant:label:${t}`,r.text,r.box,x.labelFont,wT,r.box.left>=i.x?"left":r.box.right<=i.x?"right":"center",l)}),function(e,t,a,l){let i=e.bounds(),s=Math.max(i.right-i.left,360),o=i.top-18;if(a.length){let t=a.map((e,t)=>{let a=wD(e,200,14);return{index:t,group:e,text:a,width:18+a.width}}),r=[[]],n=0;for(let e of t){let t=r.at(-1);t.length&&n+18+e.width>s?(r.push([e]),n=e.width):(n+=18*!!t.length+e.width,t.push(e))}let d=r.map(e=>Math.max(...e.map(e=>e.text.height))),c=o-d.reduce((e,t)=>e+t,0)-(r.length-1)*6;o=c-12,r.forEach((t,a)=>{let s=d[a],o=c+s/2,r=i.left;for(let a of t){let t=`quadrant:legend:${a.index}`,i=l.get(a.group);e.mark(`quadrant:key:${a.index}`,"ellipse",{left:r,top:o-6,right:r+12,bottom:o+6},a.group,{fillColor:i,strokeColor:e.surface,strokeWidth:2,groupIds:[t]},"front"),e.text(`${t}:label`,a.text,wZ(r+18,o-a.text.height/2,a.text),14,wT,"left",t),r+=a.width+18}c+=s+6})}let r=wD(t.title,s,20);e.text("quadrant:title",r,wZ(i.left,o-r.height,r),20,wT,"left")}(w,v,z,C);let q=w.bounds(),L=40-q.left,S=40-q.top,B=w.elements.map(e=>{if("line"===e.type){let[t,a,...l]=e.points.map(e=>({x:wG(e.x+L),y:wG(e.y+S)}));return{...e,points:[t,a,...l]}}return"arrow"===e.type?e:{...e,x:wG(e.x+L),y:wG(e.y+S)}});return{kind:"canvas",version:1,diagramId:v.id,title:v.title,width:Math.ceil(q.right-q.left+80),height:Math.ceil(q.bottom-q.top+80),accentColor:v.style.accentColor,backgroundColor:v.style.backgroundColor,elements:B,layers:[],layouts:[],zOrder:w.zOrder()}})(bR(p)),catch:e=>new ke(e instanceof ig?{status:"invalid_quadrant_chart",context:{...f,issues:bD(e.issues)}}:{status:"render_failed",context:{...f,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render quadrant chart scene.",hint:"Repair the axes, quadrant names and points and retry."})]}})}).pipe(o.fRP("codeMode.buildQuadrantChart.render")),v=i5(m);if(v.length>0)return yield*new ke({status:"render_failed",context:{...f,issues:kz(v).map(e=>({...e,hint:"Use fewer points or shorter labels and retry buildQuadrantChart."}))}});let w={...f,partial:kZ(m)},x=yield*kW({scene:m,formats:kw(d.options),inlineFormats:kx(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new ke({status:e.status,context:{..."export_failed"===e.status?w:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...kG(d.requestId),normalizedSpec:p,quality:u,artifact:x,issues:[]}}),k8=o.fn("codeMode.buildTimeline.workflow")(function*(e){var t,a;let l,s,r=i.q$Z(nd,{errors:"all",reportInput:!0})(e);if(!xH.oJ(r))return yield*new b9({status:"invalid_input",context:{issues:kf(os(r.failure))}});let n=yield*bm,d=r.success,c=yield*o.OH5(()=>n.createId("build")),p=(l=oe((t=d.spec).title),{id:(s={id:kv(t.id)??(km(l)||"sketchi-timeline"),title:l,type:"timeline",style:{...y},events:t.events.map(e=>({...e}))}).id,title:l,events:eh(s),...t.lanes?{lanes:[...t.lanes]}:{},...t.today?{today:t.today}:{},style:s.style}),h={buildId:c,...kG(d.requestId),normalizedSpec:p},g=en(bw(p)).map(e=>kn({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 b9({status:"invalid_timeline",context:{...h,issues:g}});let u={accepted:10>=(a=d.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 b9({status:"quality_failed",context:{...f,issues:ky(u)}});let m=yield*o.SvU({try:()=>(function(e){let t,a,l=ec(e),i=eh(l),s=hB(l),o=er(l),r=(o.length?o:[""]).map((e,t)=>{let a=gt[t%gt.length];return{...a,stroke:a.stroke||l.style.accentColor}}),n=i[0]?.date!==void 0,d=[],c=e=>{let t=d.findIndex(t=>t.time===e.time&&t.tie===e.tie);return t>=0?t:(d.push(e),d.length-1)},p=void 0===l.today?void 0:es(l.today),h=new Map,g=new Map,u=[!1,!0].flatMap(e=>i.flatMap((t,a)=>{let l,i,s=void 0!==t.end;if(s!==e)return[];let o=n?es(t.date):void 0,r=void 0===t.end?void 0:es(t.end),d=o?o.start:t.order??a,u=t.lane??"",f=r?(d+r.end)/2:d,m=p&&r&&p.start>d&&p.start<r.end,v=r&&(m||h.has(`${u}\0${f}`))?function(e,t,a){let l=[e,...a.filter(a=>a>e&&a<t),t].toSorted((e,t)=>e-t),i={from:e,to:e};for(let[e,t]of l.slice(1).entries())t-l[e]>i.to-i.from&&(i={from:l[e],to:t});return(i.from+i.to)/2}(d,r.end,[...g.get(u)??[],...m?[p.start]:[]]):f,y=c({time:v,tie:(l=`${u}\0${v}`,i=h.get(l)??0,h.set(l,i+1),g.set(u,[...g.get(u)??[],v]),i)});return[{event:t,index:a,span:s,start:s?c({time:d,tie:0}):y,end:r?c({time:r.end,tie:0}):void 0,stem:y}]})).toSorted((e,t)=>e.index-t.index),f=p?c({time:p.start,tie:0}):void 0,m=d.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}`,l=s.events.get(e.event.id),i=[...l?[ga(`date:${a}`,l,14,t.ink)]:[],ga(`label:${a}`,e.event.label,16,v.ink),...e.event.description?[ga(`description:${a}`,e.event.description,13,h9)]:[]];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,(l?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,z=e=>x.some(t=>t.span&&t.startKey<=e&&t.endKey>e),C=w.slice(1).map((e,t)=>e.time-w[t].time),_=new Map,q=e=>{let t=_.get(e);if(!t){var a;let l,i,s,o=(a=C[e],l=(e,t)=>`${e} ${t}${1===e?"":"s"}`,i=e=>l(Math.max(1,Math.round(a/hA[e])),e),s=e=>{let t=a/hA[e];return l(t<10?Math.round(10*t)/10:Math.round(t),e)},a<1e3?i("millisecond"):a<12e4?s("second"):a<72e5?i("minute"):a<1728e5?i("hour"):a<5184e6?i("day"):a<63113904e3?i("month"):s("year"));t={text:o,half:i_(o,13,200)/2+6},_.set(e,t)}return t},L=[...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=C.reduce((e,t)=>e+t,0),l=x.length*k,i=10*k,s=a>0?l/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 l=a[t-1];return l&&l.stemKey!==e.stemKey?[{from:l.stemKey,to:e.stemKey,min:Math.max(28,e.inset+h8+1)}]:[]})),...x.filter(e=>e.span).map(e=>({from:e.startKey,to:e.endKey,min:12}))].filter(e=>e.to>e.from),d=Math.max(28,...o.map(e=>e.min)),c=(e,a)=>{let l=[0],i=0,s=0;return C.forEach((o,r)=>{let n=w[r+1];n.tie>0?l.push(i+n.tie*d):(i=t.has(r)?a?Math.max(i+a.get(r),s+Math.max(M,2*(q(r).half+3+16))):s+M:i+o*e,l.push(i)),s=Math.max(s,l[r+1])}),l},p=()=>{let[e,t]=[c(0),c(1)];return o.map(({from:a,to:l,min:i})=>{let s=e[l]-e[a];return{from:a,to:l,min:i,fixed:s,perScale:t[l]-e[l]-(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(s,2*i/h):1/0,u=s;for(;;){let e=C.reduce((e,a,l)=>e+(t.has(l)?0:a),0),a=t.size&&e>0?Math.min(2*s,Math.max(s,(l-t.size*M)/e)):s,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=C.flatMap((e,a)=>t.has(a)||!(e*u>r)||z(a)?[]:[a]);for(let{from:e,to:a,min:l,fixed:i,perScale:s}of o)if(i+s*u<l-1e-6){let l=C.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];l&&n.push(l.key)}if(!n.length)break;for(let e of n)t.add(e)}if(!t.size)return{x:c(u),breaks:t};let f=Math.max(M,...C.map((e,a)=>t.has(a)||z(a)?0:e*u)),m=[...t].filter(e=>C[e]*u>=M),v=Math.min(...m.map(e=>C[e])),y=Math.log2(Math.max(...m.map(e=>C[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,C[e]/v)))])),S=c(u,_),B=new Set(m),A=L.slice(1).flatMap((e,a)=>{let l=L[a],i=C.slice(l,e).map((e,t)=>l+t),s=i.filter(e=>B.has(e)).at(-1);return void 0===s&&i.some(e=>t.has(e))?[]:[{from:l,to:e,elapsed:w[e].time-w[l].time,broken:s}]}),P=e=>S[e.to]-S[e.from];for(let e of A.toSorted((e,t)=>e.elapsed-t.elapsed)){if(void 0===e.broken)continue;let{elapsed:t}=e,a=Math.max(...A.map(e=>1.5*e.elapsed<=t?P(e)+12:e.elapsed<t?P(e):0)),l=Math.min(...A.map(e=>void 0!==e.broken?1/0:e.elapsed>=1.5*t?P(e)-12:e.elapsed>t?P(e):1/0)),i=Math.min(Math.max(P(e),a),l);if(1e-9>Math.abs(i-P(e)))continue;let s=e.broken,o=w.findIndex(e=>e.time===w[s].time);_.set(s,S[s+1]-S[o]+i-P(e)),S=c(u,_)}return{x:S,breaks:t}},B=({x:e,breaks:t})=>{let a=e.map((t,a)=>Math.max(...e.slice(0,a+1))),l=e.map((t,a)=>Math.min(...e.slice(a))),i=t=>(a[t]+e[t+1])/2,s=w.slice(0,-1).flatMap((e,s)=>{if(z(s))return[];let o=l[s+1]-14;if(t.has(s)){let e=i(s)+q(s).half+3+7;return[{key:s,low:e,high:Math.max(e,o),broken:!0}]}let r=a[s]+14;return r<=o?[{key:s,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(l=>!l.span&&l.lane===t.lane&&(l.startKey<t.startKey||l.startKey>=t.endKey)&&e[l.startKey]+gi(l)>e[t.startKey]&&e[l.startKey]-gi(l)<a)?[t.lane]:[]}));return{x:e,breaks:t,reachBefore:a,rowsFor:t=>{let a=e[e.length-1],l=[],i=0,o=-24;for(let e=1;e<t;e+=1){let r=a*e/t,n=s.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;l.push({first:i,last:n.cut.key,start:o,end:n.at}),i=n.cut.key+1,o=n.at}return l.push({first:i,last:w.length-1,start:o,end:Math.max(...e)+24}),l},layout:(t,a=h7)=>{let l=Math.max(1,o.length);return t.map((t,s)=>{let o=t.start-32*(s>0),n=t=>e[t]-o,d=void 0!==b&&b>=t.first&&b<=t.last?n(b):void 0,c=Array.from({length:l},(e,l)=>(function(e,t,a,l,i=h7){let s;for(let o of gl){let r=function(e,t,a,l,i,s=h7){let o=[],r=new Map;for(let t of e.filter(e=>e.span).toSorted((e,t)=>e.startKey-t.startKey)){let e=o.findIndex((e,a)=>a>=l&&e<=t.startKey);for(e<0&&(e=Math.max(l,o.length));o.length<e;)o.push(-1/0);o[e]=t.endKey,r.set(t,e)}let n=o.length,d=s+16*Math.max(0,n-1),c=e=>t(e.stemKey),p=e.toSorted((e,t)=>c(t)-c(e)||t.index-e.index),h={"-1":[],1:[]},g={"-1":[],1:[]},u=[],f=(e,t,a=h8)=>t>e.left-a&&t<e.right+a,m=-1;p.forEach((e,t)=>{let l=c(e),o=p.slice(t+1).map(c),n=i.lookahead?p[t+2]:void 0,v=(e,t,a)=>{if(!n||t>a)return 0;let l=c(n);return l+10+16>e?1e3:Math.max(0,l+n.width/2+16-e)/2},y=l-e.width+e.inset,w=l-e.inset,x=(r.get(e)??0)>0,b=x?1:m,k=e=>e.option.near-(e.side===b?x?120:1:0),M=t=>[b,-b].flatMap(r=>{let p=((t,r)=>{let p=t<0?s:d,u=h[t],m=h[-t],x=[...g[t],...r&&void 0!==a&&Math.abs(a-l)>=14?[{x:a,reach:1/0}]:[]],b=[p,...u.map(e=>e.far+10)].filter(e=>e>=p).toSorted((e,t)=>e-t),k=l-e.width/2,M=[k,y,w,...u.flatMap(t=>[t.right+16,t.left-16-e.width]),...[...x,...o.map(e=>({x:e,reach:0}))].flatMap(t=>{let a=1/0===t.reach?3*h8:h8;return[t.x+a,t.x-a-e.width]}),...n?[c(n)+10+16,c(n)+n.width/2+16]:[]].map(e=>Math.min(w,Math.max(y,e)));for(let t of b){let a=t+e.height,s=a=>Math.abs(a-k)+v(a,t,p)+i.coverPenalty*o.slice(1).filter(t=>f({left:a,right:a+e.width},t)).length;for(let i of M.toSorted((e,t)=>s(e)-s(t)||e-t)){let s=i+e.width,r={left:i,right:s};if(u.every(e=>i>=e.right+16||e.left>=s+16||t>=e.far+10||e.near>=a+10)&&u.every(e=>!f(e,l)||e.near>t)&&x.every(e=>!f(r,e.x,1/0===e.reach?3*h8:h8)||e.reach<=t)&&o.every(e=>!f(r,e)||m.every(t=>!f(t,e))))return{near:t,left:i}}}})(r,t);return p?[{side:r,option:p}]:[]}).toSorted((e,t)=>k(e)-k(t))[0],z=M(!0)??M(!1);if(!z)throw Error(`Timeline label for "${e.event.id}" has no clear placement.`);let{side:C,option:_}=z,{near:q,left:L}=_;h[C].push({left:L,right:L+e.width,near:q,far:q+e.height}),g[C].push({x:l,reach:q});let S=r.get(e)??0,B=16*S;u.push({item:e,stemX:l,side:C,near:q,left:L,stemStart:C>0?B+gi(e):gi(e)-B,track:S}),m=-C});let v=(e,t)=>Math.max(t,...h[e].map(e=>e.far));return{placements:u,above:v(-1,15),below:v(1,Math.max(9,d-s+6)+6),tracks:n}}(e,t,a,l,o,i);(!s||r.above+r.below<s.above+s.below)&&(s=r)}return s})(x.filter(e=>e.lane===l&&e.startKey>=t.first&&e.startKey<=t.last),n,d,+!!r.has(l),a));return{row:t,localX:n,breakX:e=>i(e)-o,todayX:d,lanes:c,axisStart:t.start-o,axisEnd:t.end-o}})}}},A=o.length?Math.max(...o.map(e=>i_(e,15,160)))+20:0,P=s.header,V=s.today,H=(e,t,a=h7)=>{var l;let i,s,n,d,c,p,h,g,u,f,m=e.rowsFor(t);if(m.length<t)return;let v=e.layout(m,a),y=(l=e.breaks,i=[],s=[],n=[],d=[],c=(e,t)=>{i.push(e),t.push(e.id)},p=(e,t,a={})=>({type:"line",id:e,points:t,...a}),h=(e,t,a,l,i,s,o={})=>({type:"text",id:e,x:a,y:l,text:t,fontSize:i,maxWidth:200,textColor:s,...o}),g=P?Math.ceil(14*1.35):0,u=18*!!V,f=P?g+18:0,v.forEach((e,t)=>{let a=f,i=void 0!==e.todayX;i&&(f+=u+6);let g=t<v.length-1,m=t>0;if(e.lanes.forEach((a,i)=>{let u=r[i],v=f+a.above,y=`${i}:${t}`,w={strokeColor:u.stroke,strokeWidth:2,roughness:0},x=[...l].toSorted((e,t)=>e-t).filter(t=>t>=e.row.first&&t<=e.row.last).map(t=>({x:A+e.breakX(t),...q(t)})),b=[A+e.axisStart,...x.flatMap(e=>[e.x-e.half,e.x+e.half]),A+e.axisEnd];for(let e=0;e<b.length;e+=2)b[e+1]>b[e]&&c(p(`axis:${y}${e?`:${e/2}`:""}`,[{x:b[e],y:v},{x:b[e+1],y:v}],w),s);for(let t of(x.forEach((e,t)=>{for(let a of[-1,1])c(p(`break:${y}:${t}:${a<0?"a":"b"}`,[{x:e.x+a*e.half-3,y:v+7},{x:e.x+a*e.half+3,y:v-7}],w),d);c(h(`break-label:${y}:${t}`,e.text,e.x,v,13,u.ink),d)}),m&&c(p(`continue-in:${y}`,[{x:A,y:v},{x:A+32,y:v}],{...w,strokeStyle:"dashed"}),s),g&&c(p(`continue-out:${y}`,[{x:A+e.axisEnd,y:v},{x:A+e.axisEnd+32,y:v}],{...w,strokeStyle:"dashed",endArrowhead:"arrow"}),s),o.length&&c(h(`lane:${y}`,o[i],A-16-i_(o[i],15,160)/2,v,15,u.ink,{maxWidth:160,textAlign:"right"}),d),a.placements)){let{item:a}=t,l=`event:${a.event.id}`,i={groupIds:[l]},o=v+16*t.track,r=A+t.stemX;if(a.span){let t=A+e.localX(a.startKey);c({type:"node",id:`node:${l}`,nodeId:l,rendererRole:h6,shape:"rectangle",x:t,y:o-6,width:Math.max(12,A+e.localX(a.endKey)-t),height:12,label:a.event.label,fillColor:u.wash,strokeColor:u.stroke,...i},n)}else{let e="milestone"===a.event.kind,t=e?18:12;c({type:"node",id:`node:${l}`,nodeId:l,rendererRole:h6,shape:e?"diamond":"ellipse",x:r-t/2,y:v-t/2,width:t,height:t,label:a.event.label,fillColor:u.stroke,strokeColor:u.stroke,...i},d)}let g=v+t.side*t.near;c(p(`stem:${l}`,[{x:r,y:v+t.side*t.stemStart},{x:r,y:g}],{strokeColor:"#b9ad95",strokeWidth:1,roughness:0,...i}),s);let f=A+t.left,m=t.side<0?g-a.height:g;for(let e of a.parts){let t=i_(e.text,e.fontSize,200),l=Math.min(Math.max(r,f+t/2),f+a.width-t/2),s=l===r?"center":l<r?"right":"left";c(h(e.id,e.text,l,m+e.height/2,e.fontSize,e.color,{textAlign:s,...i}),d),m+=e.height+2}}f=v+a.below+28*(i<e.lanes.length-1)}),i){let l=A+e.todayX;c(p(`today:${t}`,[{x:l,y:a+u+3},{x:l,y:f}],{strokeColor:ge,strokeWidth:1,strokeStyle:"dashed",roughness:0}),s),c(h(`today-label:${t}`,V,l,a+u/2,13,ge),d)}f+=48}),f-=48,P&&c(h("header",P,i_(P,14,400)/2,g/2,14,h9,{maxWidth:400,textAlign:"left"}),d),{elements:i,zOrder:[...s,...n,...d],height:f}),w=(e=>{let t=1/0,a=-1/0,l=1/0,i=-1/0,s=(e,s,o,r)=>{t=Math.min(t,e),a=Math.max(a,o),l=Math.min(l,s),i=Math.max(i,r)};for(let t of e)if("line"===t.type||"arrow"===t.type)for(let e of t.points)s(e.x,e.y,e.x,e.y);else if("text"===t.type){let e=i_(t.text,t.fontSize,t.maxWidth??200),a=t.text.split("\n").length*t.fontSize*1.35;s(t.x-e/2,t.y-a/2,t.x+e/2,t.y+a/2)}else("node"===t.type||"frame"===t.type)&&s(t.x,t.y,t.x+t.width,t.y+t.height);return{minX:t,maxX:a,minY:l,maxY:i}})(y.elements),x=Math.abs(Math.log((w.maxX-w.minX+80)/(w.maxY-w.minY+80)/2))+.3*(t-1);return{count:t,composed:y,box:w,score:x,labeled:v.flatMap(({lanes:e})=>e).reduce((e,{placements:t})=>e+ +!!t.some(({side:e})=>e<0)+ +!!t.some(({side:e})=>e>0),0)}},I=e=>e.reduce((e,t)=>!e||t.score<e.score-1e-9?t:e,void 0),$=({box:e})=>(e.maxX-e.minX+40)/(e.maxY-e.minY+40),F=({x:e,breaks:t,reachBefore:a})=>C.map((t,l)=>({gap:t,key:l,free:e[l+1]-a[l]})).filter(({gap:e,key:a,free:l})=>e>0&&!t.has(a)&&!z(a)&&l>=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))),E=B(S(new Set)),U=[];for(let e=1;e<=O;e+=1){let t=H(E,e);if(!t)break;U.push(t)}let X=I(U),T=E;if(n&&1===X.count&&$(X)>3.5){let e=new Set,t=X;for(let a=F(T);a&&$(t)>3.5;a=F(T))e.add(a.key),t=H(T=B(S(e)),1);(X=3.5>=$(t)?t:I(U.slice(1))??t)!==t&&(T=E)}if(1===X.count&&$(X)>2.3){let e=Math.floor((140-h7)/6),t=new Map([[0,X]]),a=e=>{let a=t.get(e);if(a)return a;let l=H(T,1,h7+6*e);return t.set(e,l),l},l=e=>2.3>=$(a(e)),i=X.box.maxX-X.box.minX,s=6*X.labeled,o=(i+40)/2.3-40-(({box:e})=>e.maxY-e.minY)(X),r=s>0?Math.min(e,Math.max(1,Math.ceil(o/s))):e;if(l(r))for(;r>1&&l(r-1);)r-=1;else for(;r<e&&!l(r);)r+=1;X=a(r)}let{composed:R,box:Y}=X,D=40-Y.minX,G=40-Y.minY,Z=R.elements.map(e=>{if("line"===e.type||"arrow"===e.type){let[t,...a]=e.points.map(e=>({x:e.x+D,y:e.y+G}));return"line"===e.type?{...e,points:[t,a[0],...a.slice(1)]}:{...e,points:[t,...a]}}return{...e,x:e.x+D,y:e.y+G}});return{kind:"canvas",version:1,diagramId:l.id,title:l.title,width:Math.ceil(Y.maxX-Y.minX+80),height:Math.ceil(Y.maxY-Y.minY+80),accentColor:l.style.accentColor,backgroundColor:l.style.backgroundColor,elements:Z,layers:[],layouts:[],zOrder:R.zOrder}})(bw(p)),catch:e=>new b9({status:"render_failed",context:{...f,issues:[kn({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=i5(m);if(w.length>0)return yield*new b9({status:"render_failed",context:{...f,issues:kz(w).map(e=>({...e,hint:"Split the chronology into smaller timelines and retry buildTimeline."}))}});let x={...f,partial:kZ(m)},b=yield*kW({scene:m,formats:kw(d.options),inlineFormats:kx(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b9({status:e.status,context:{..."export_failed"===e.status?x:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...kG(d.requestId),normalizedSpec:p,quality:u,artifact:b,issues:[]}}),k9=o.fn("codeMode.buildChart.workflow")(function*(e){var t,a;let l,s,r,n,d,c=i.q$Z(nc,{errors:"all",reportInput:!0})(e);if(!xH.oJ(c))return yield*new kt({status:"invalid_input",context:{issues:kf(os(c.failure))}});let p=yield*bm,h=c.success,g=yield*o.OH5(()=>p.createId("build")),u=(l=oe((t=h.spec).title),r=(s=e=>{let t=kv(e);return void 0===t?void 0:t})(t.unit),n=s(t.categoryAxisTitle),d=s(t.valueAxisTitle),{id:kv(t.id)??(km(l)||"sketchi-chart"),title:l,kind:t.kind,categories:t.categories.map(oe),series:t.series.map(e=>{let t=s(e.name);return{...t?{name:t}:{},values:[...e.values]}}),...r?{unit:r}:{},...n?{categoryAxisTitle:n}:{},...d?{valueAxisTitle:d}:{},...void 0!==t.stacked?{stacked:t.stacked}:{},...void 0!==t.donut?{donut:t.donut}:{},...t.orientation?{orientation:t.orientation}:{},style:{...y}}),f={buildId:g,...kG(h.requestId),normalizedSpec:u},m=N(bx(u)).map(e=>kn({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 kt({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 kt({status:"quality_failed",context:{...w,issues:ky(v)}});let x=yield*o.SvU({try:()=>(function(e){let t=J(e),a=new p5(t.style.backgroundColor);if("pie"===t.kind)!function(e,t){let a=t.series[0].values,l=pA(t.unit),i=p3(a.length,!0),{labels:s,shares:o}=function(e){let t=e.reduce((e,t)=>e+t,0),a=e.map(e=>t>0?e/t*100:0),l=e=>a.map(t=>Math.round(t*10**e)/10**e),i=t=>e.some((a,l)=>a>0&&0===t[l]||e.some((e,i)=>i>l&&e!==a&&t[i]===t[l])),s=+!!a.some(e=>e>0&&e<10);for(;s<2&&i(l(s));)s+=1;let o=l(s);return{shares:a,decimals:s,labels:o.map((t,a)=>0===t&&e[a]>0?`<${(10**-s).toFixed(s)}%`:`${Number(t.toFixed(s))}%`)}}(a),r=t.unit?.trim()==="%",n=87*!!t.donut,d=-Math.PI/2,c=a.map((e,t)=>{let a=o[t]/100*2*Math.PI,l={index:t,start:d,end:d+a,mid:d+a/2};return d+=a,l}),p=[];for(let o of c){let d=i[o.index],c=t.categories[o.index],h=pO(a[o.index],l),g=s[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=hl(150,o.start,t?o.end-1e-4:o.end),l=n>0?[...a,...hl(n,t?o.end-1e-4:o.end,o.start)]:t?a:[{x:0,y:0},...a];e.polygon(`chart:slice:${o.index}`,l,`${c}: ${g} (${h})`,{fillColor:d,strokeColor:e.surface,strokeWidth:2,...u})}let m=r&&g===h?g:`${g} \xb7 ${h}`,v=pN(`${iS(c,110,14)}
427
+ ${pO(i,pA(e.unit))}`),14,170)]})),n=e.links.map(t=>yE(function(e,t){let a=pA(e.unit),l=pO(t.value,a.suffix.startsWith(" ")?{...a,suffix:""}:a);if(void 0===t.label)return l;let i=e=>e.replace(/[\s,]+/gu,"").toLowerCase();return[l,pO(t.value,a),String(t.value)].map(i).includes(i(t.label))?l:`${t.label}
428
+ ${l}`}(e,t),12,140)),d=Array.from({length:i},()=>[]),c=new Map;for(let t of e.nodes){let e={key:t.id,node:t.id,column:l.get(t.id),height:0,y:0,overhang:0};c.set(t.id,e),d[e.column].push(e)}let p=[],h=e.links.map((e,t)=>{let a=[],l=c.get(e.source),i=c.get(e.target);for(let s=l.column+1;s<i.column;s+=1){let i={key:`~${t}:${s}`,column:s,height:0,y:0,overhang:0};d[s].push(i),a.push({link:t,from:l,to:i,value:e.value,width:0}),l=i}return a.push({link:t,from:l,to:i,value:e.value,width:0}),p.push(...a),a}),g=new Map,u=new Map;for(let e of p)u.set(e.from,[...u.get(e.from)??[],e]),g.set(e.to,[...g.get(e.to)??[],e]);let f=Array.from({length:Math.max(0,i-1)},(e,t)=>p.filter(e=>e.from.column===t)),m=(e,t)=>Math.max(22,e.overhang+t.overhang+4),v=e=>e.reduce((t,a,l)=>t+a.height+(l>0?m(e[l-1],a):0),0),y=t=>{for(let a of p)a.width=Math.max(e.links[a.link].value*t,3);for(let e of d)for(let t of e){let e=e=>(e??[]).reduce((e,t)=>e+t.width,0);t.height=Math.max(e(g.get(t)),e(u.get(t)));let a=void 0===t.node?void 0:r.get(t.node);t.overhang=a?Math.max(0,(a.height-t.height)/2):0}},w=0,x=()=>{let e=new Map;for(let t of d)t.forEach((t,a)=>e.set(t,a));return e},b=e=>{let t=x(),a=0,l=0;for(let i of e){let e=function(e,t){let a=0,l=0;for(let i=0;i<e.length;i+=1){let s=e[i],o=t.get(s.from),r=t.get(s.to);for(let n=i+1;n<e.length;n+=1){let i=e[n];s.from!==i.from&&s.to!==i.to&&(o-t.get(i.from))*(r-t.get(i.to))<0&&(a+=1,l+=s.value*i.value)}}return{count:a,weighted:l,work:e.length*(e.length-1)/2}}(f[i],t);a+=e.count,l+=e.weighted,w+=e.work}return{count:a,weighted:l}},k=f.map((e,t)=>t),M=()=>b(k),z=(e,t)=>{let a=1e-9*Math.max(Math.abs(e.weighted),Math.abs(t.weighted));return e.weighted<t.weighted-a||Math.abs(e.weighted-t.weighted)<=a&&e.count<t.count};if(y(1),"authored"!==t.ordering){let e=d.map(e=>[...e]),t=M(),a=e=>{let t=new Map,a=0;for(let l of e)t.set(l,a+l.height/2),a+=l.height+22;return t},l=(e,t)=>{let l=a(d["in"===t?e-1:e+1]),i=a(d[e]),s=new Map(d[e].map(e=>{let a=("in"===t?g:u).get(e)??[],s=a.reduce((e,t)=>e+t.value,0);return 0===s?[e,i.get(e)]:[e,a.reduce((e,a)=>e+a.value*l.get("in"===t?a.from:a.to),0)/s]}));d[e].sort((e,t)=>s.get(e)-s.get(t))},s=()=>d.map(e=>[...e]),o=e=>d.splice(0,d.length,...e.map(e=>[...e])),r=()=>{let e=s(),t=M();for(let a=0;a<12&&w<4e6;a+=1){for(let e=1;e<i;e+=1)l(e,"in");for(let e=i-2;e>=0;e-=1)l(e,"out");let a=M();z(a,t)&&(t=a,e=s())}return e},n=()=>{for(let e=0,t=!0;t&&e<8;e+=1)for(let[e,a]of(t=!1,d.entries())){let l=[e-1,e].filter(e=>e>=0&&e<f.length);for(let e of[...a]){if(w>=4e6)break;let i=a.indexOf(e),s=i,o=b(l);a.splice(i,1);for(let t=0;t<=a.length;t+=1){if(t===i)continue;a.splice(t,0,e);let r=b(l);a.splice(t,1),z(r,o)&&(s=t,o=r)}a.splice(s,0,e),s!==i&&(t=!0)}}return M()},c=s(),p=[c,r()];for(let a of(o(c.map(e=>e.toReversed())),p.push(r()),p)){if(w>=4e6)break;o(a);let l=n();z(l,t)&&(t=l,e=s())}o(e)}let{count:C,weighted:_}=M(),q=e=>Math.max(0,...d[e].flatMap(e=>void 0===e.node?[]:[r.get(e.node).width])),L=Array.from({length:Math.max(0,i-1)},(e,t)=>t>0?q(t)+12:0),S=Array.from({length:Math.max(0,i-1)},(t,a)=>{let i=e.links.flatMap((e,t)=>l.get(e.target)===a+1?[n[t].width]:[]);return i.length>0?Math.max(...i)+12:0}),B=q(0)+12+q(i-1)+14*i+[...L,...S].reduce((e,t)=>e+t,0),A=x(),P=new Map,V=new Map,H=(e,t)=>e.toSorted((e,a)=>A.get(e[t])-A.get(a[t])||e.link-a.link);for(let e of d)for(let t of e)P.set(t,H(u.get(t)??[],"to")),V.set(t,H(g.get(t)??[],"from"));let I=(e,t)=>{let a=0;for(let l of e){if(l===t)break;a+=l.width}return a},$=e=>e.from.y+I(P.get(e.from),e),F=e=>e.to.y+I(V.get(e.to),e),O=(e,t)=>{let a=0;e.forEach((t,l)=>{l>0&&(a+=m(e[l-1],t)),t.y=Math.max(t.y,a),a=t.y+t.height});let l=t;for(let t=e.length-1;t>=0;t-=1){let a=e[t];a.y=Math.min(a.y,l-a.height),t>0&&(l=a.y-m(e[t-1],a))}},E=Math.max(...d.map(t=>t.reduce((t,a)=>{let l=t=>(t??[]).reduce((t,a)=>t+e.links[a.link].value,0);return t+Math.max(l(g.get(a)),l(u.get(a)))},0))),U=(e,t=1)=>{y(e);let a=Math.max(...d.map(v));return(e=>{for(let t of d){let a=(e-v(t))/2;t.forEach((e,l)=>{l>0&&(a+=m(t[l-1],e)),e.y=a,a+=e.height})}for(let t=0;t<24;t+=1){let a=.9**t*.8;for(let t=1;t<i;t+=1){for(let e of d[t]){let t=g.get(e)??[],l=t.reduce((e,t)=>e+t.width,0);if(0===l)continue;let i=t.reduce((t,a)=>t+a.width*($(a)-(F(a)-e.y)),0)/l;e.y+=(i-e.y)*a}O(d[t],e)}for(let t=i-2;t>=0;t-=1){for(let e of d[t]){let t=u.get(e)??[],l=t.reduce((e,t)=>e+t.width,0);if(0===l)continue;let i=t.reduce((t,a)=>t+a.width*(F(a)-($(a)-e.y)),0)/l;e.y+=(i-e.y)*a}O(d[t],e)}}for(let t of h){if(t.length<2)continue;let a=$(t[0]),l=F(t.at(-1)),i=t[0].from.column,s=t.at(-1).to.column-i;for(let o of t.slice(1)){let t=o.from,r=d[t.column],n=r.indexOf(t),c=r[n-1],p=r[n+1],h=c?c.y+c.height+m(c,t):0,g=p?p.y-m(t,p)-t.height:e-t.height,u=a+(l-a)*(t.column-i)/s;h<=g&&(t.y=Math.min(g,Math.max(h,u)))}}})(a),{height:a,runs:f.map(e=>t*Math.min(340,Math.max(120,.7*Math.max(0,...e.map(e=>Math.abs($(e)-F(e))))))),bars:Math.max(...d.map(e=>e.reduce((e,t)=>e+t.height,0)))}},X=360/E;for(let e=0;e<2;e+=1){let{height:e,runs:t,bars:a}=U(X),l=(B+t.reduce((e,t)=>e+t,0))/2.2-60;if(e>=l-1||a>=1400)break;X*=Math.min(1400,a+(l-e))/a}let T=(t,s=1)=>{let{runs:d,bars:p,height:g}=U(t,s),f=[],m=0;for(let e=0;e<i;e+=1)f.push(m),e<i-1&&(m+=14+L[e]+d[e]+S[e]);let v=e.nodes.map(e=>{let t=c.get(e.id),l=r.get(e.id),s=f[t.column],n=t.y+t.height/2-l.height/2,d=0===t.column&&i>1?"right":"left",p="right"===d?s-6-l.width:s+14+6,h=a.get(e.id),g={left:p,top:n,right:p+l.width,bottom:n+l.height};return{...t.column>0&&t.column<i-1&&(u.get(t)?.length??0)>0?{knockout:{left:g.left-3,top:g.top,right:g.right+3,bottom:g.bottom}}:{},id:e.id,label:e.label,color:o.get(e.id),column:t.column,x:yU(s),y:yU(t.y),width:14,height:yU(Math.max(t.height,.5)),inflow:h.inflow,outflow:h.outflow,total:h.total,text:{...l,fontSize:14,align:d,box:g}}}),y=(e,t,a,l)=>{let i,s=[],o=Math.max(6,Math.min(20,Math.floor((125-6*(i=e.length))/i)));for(let i of e){let e=i.from.column,r=f[e]+14,n=f[e+1],d=a(i)+t(i),c=l(i)+t(i),p=r+L[e],h=n-S[e];0===s.length&&s.push({x:r,y:d}),p>r&&s.push({x:p,y:d});for(let e=1;e<=o;e+=1)s.push(yZ(p,d,h,c,e/o));h<n&&s.push({x:n,y:c}),void 0===i.to.node&&s.push({x:n+14,y:c})}return s.map(e=>({x:yU(e.x),y:yU(e.y)}))},w=e.links.map((e,t)=>{let a=h[t],l=a[0].width,i=y(a,()=>0,$,F),s=y(a,()=>l,$,F);return{index:t,source:e.source,target:e.target,value:e.value,width:yU(l),color:o.get(e.source),sourceTop:yU($(a[0])),targetTop:yU(F(a.at(-1))),points:[...i,...s.toReversed()]}}),x=v.map(e=>e.knockout??e.text.box),b=v.map(e=>({left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})),k=w.map(e=>({band:e,bounds:yG(e.points)})),M=[],z=(e,t,a=0)=>{let l={left:e.left-a,top:e.top-a,right:e.right+a,bottom:e.bottom+a};return!x.some(t=>yX(e,t,2))&&!M.some(([t,a])=>yT(t,a,e))&&!b.some(t=>yX(e,t,2))&&!k.some(({band:e,bounds:a})=>e.index!==t&&yD(l,e.points,a))},C=0,_=0,q=(e,t,a)=>{let l=n[e];return{...l,fontSize:12,align:"center",box:{left:t,top:a,right:t+l.width,bottom:a+l.height}}},A=w.map(e=>{let t=n[e.index],a=f[l.get(e.target)]-6;return q(e.index,a-t.width,e.targetTop+(e.width-t.height)/2)}),P=e=>e.width>=n[e.index].height+2;for(let e of w)P(e)&&x.push(A[e.index].box);return{nodes:v,bands:w.map(e=>{let t,a=n[e.index],i=f[l.get(e.target)-1+1]-6,s=(t,a)=>q(e.index,t,a),o=A[e.index];if(P(e))return{...e,text:o};let r=h[e.index],d=f[r[0].from.column]+14+6,c=[s(i-a.width,e.targetTop-a.height-1),s(i-a.width,e.targetTop+e.width+1),s(d,e.sourceTop-a.height-1),s(d,e.sourceTop+e.width+1)],p=[];for(let t of[.5,.4,.6,.3,.7,.2,.8,.1,.9])for(let l of r){let i=l.from.column,o=f[i]+14+L[i],r=f[i+1]-S[i],n=$(l),d=F(l),c=yZ(o,n,r,d,t).x-a.width/2,h=[c,c+a.width].map(e=>(function(e,t,a,l,i){if(i<=e)return t;if(i>=a)return l;let s=0,o=1;for(let r=0;r<24;r+=1){let r=(s+o)/2;yZ(e,t,a,l,r).x<i?s=r:o=r}return yZ(e,t,a,l,(s+o)/2).y})(o,n,r,d,e));p.push(s(c,Math.min(...h)-a.height-2),s(c,Math.max(...h)+e.width+2))}let g=c.find(t=>z(t.box,e.index))??p.find(t=>z(t.box,e.index,5))??(z(o.box,e.index)?o:void 0);if(g)return x.push(g.box),{...e,text:g};C+=1;let u=[];for(let t of[.5,.3,.7])for(let a of r){let l=a.from.column,i=f[l]+14+L[l],s=f[l+1]-S[l],o=yZ(i,$(a),s,F(a),t);u.push({x:o.x,y:o.y+e.width/2})}let m=(e,t)=>![...x,...b].some(a=>yT(e,t,a));for(let l of yO){for(let i of u)for(let o=0;o<16;o+=1){let r=o*Math.PI/8,n={x:i.x+l*Math.cos(r)*1.6,y:i.y+l*Math.sin(r)},d=s(n.x-a.width/2,n.y-a.height/2);if(!z(d.box,e.index,5))continue;let c={x:Math.min(Math.max(i.x,d.box.left),d.box.right),y:Math.min(Math.max(i.y,d.box.top-1),d.box.bottom+1)};if(!m(i,c))continue;let p=k.filter(({band:t,bounds:a})=>t.index!==e.index&&function(e,t,a,l=yG(a)){if(!yT(e,t,{left:l.left-.01,top:l.top-.01,right:l.right+.01,bottom:l.bottom+.01}))return!1;if(yY(e,a)||yY(t,a))return!0;for(let l=0;l<a.length;l+=1)if(yR(e,t,a[l],a[(l+1)%a.length]))return!0;return!1}(i,c,t.points,a)).length;(!t||p<t.crossed)&&(t={text:d,leader:[i,c],crossed:p})}if(t)break}if(!t&&0===_){let l=[...b,...x,...k.map(e=>e.bounds)].reduce((e,t)=>({left:Math.min(e.left,t.left),top:Math.min(e.top,t.top),right:Math.max(e.right,t.right),bottom:Math.max(e.bottom,t.bottom)})),i=u[0],o=[],r=Math.max(8,Math.sqrt((l.right-l.left+a.width+16)*(l.bottom-l.top+a.height+16)/2500));for(let e=l.top-a.height-8;e<=l.bottom+8;e+=r)for(let t=l.left-a.width-8;t<=l.right+8;t+=r)o.push({x:t,y:e});for(let l of(o.sort((e,t)=>Math.hypot(e.x+a.width/2-i.x,e.y+a.height/2-i.y)-Math.hypot(t.x+a.width/2-i.x,t.y+a.height/2-i.y)),o)){let a=s(l.x,l.y);if(!z(a.box,e.index,5))continue;let o={x:Math.min(Math.max(i.x,a.box.left),a.box.right),y:Math.min(Math.max(i.y,a.box.top-1),a.box.bottom+1)};if(m(i,o)){t={text:a,leader:[i,o],crossed:0};break}}}t||(_+=1);let v=t??{text:o,leader:void 0};return x.push(v.text.box),v.leader&&M.push(v.leader),{...e,text:v.text,...v.leader?{leader:[{x:yU(v.leader[0].x),y:yU(v.leader[0].y)},{x:yU(v.leader[1].x),y:yU(v.leader[1].y)}]}:{}}}),crowdedValues:C,unplacedValues:_,bars:p,height:g,width:B+d.reduce((e,t)=>e+t,0)}},R=(e,t,a)=>{let l=X,i=T(l,e);for(let s=0;s<3&&i.crowdedValues>0;s+=1){let s=i.height+i.bars*(1.4-1);if(1.4*i.bars>a||s>i.width*t)break;let o=T(1.4*l,e);if(o.unplacedValues>i.unplacedValues||o.unplacedValues===i.unplacedValues&&o.crowdedValues>=i.crowdedValues)break;l*=1.4,i=o}return i},Y=R(1,1.25,1100);if(Y.unplacedValues>0){let e=R(1.8,3,2400);(e.unplacedValues<Y.unplacedValues||e.unplacedValues===Y.unplacedValues&&e.crowdedValues<Y.crowdedValues)&&(Y=e)}return{nodes:Y.nodes,bands:Y.bands,columns:i,crossings:C,weightedCrossings:_,work:w,crowdedValues:Y.crowdedValues,unplacedValues:Y.unplacedValues}}(e))},catch:e=>new b7({status:"render_failed",context:{...f,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render Sankey scene.",hint:"Repair the nodes and links and retry."})]}})}).pipe(o.fRP("codeMode.buildSankey.render")),v=i5(m);if(v.length>0)return yield*new b7({status:"render_failed",context:{...f,issues:kz(v).map(e=>({...e,hint:"Shorten labels, or split the flows into smaller diagrams, and retry buildSankey."}))}});let w=function(e){let t,a,l,i,s=[],{nodes:o,bands:r,texts:n}=(t=new Map(e.elements.flatMap(e=>"text"===e.type?[[e.id,e]]:[])),a=e.elements.filter(e=>"node"===e.type),l=new Map(e.elements.flatMap(e=>"line"===e.type?[[e.id,e]]:[])),i=new Map(a.flatMap(e=>{let t=/^sankey:knockout:([^:]+)$/u.exec(e.nodeId);return t?[[t[1],{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height}]]:[]})),{nodes:a.flatMap(e=>{let a=/^sankey:node:([^:]+)$/u.exec(e.nodeId);if(!a||"rectangle"!==e.shape)return[];let l=t.get(`text:${e.nodeId}`),s=i.get(a[1]);return[{...s?{knockout:s}:{},id:a[1],box:{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height},...l?{text:l.text,textBox:w9(l)}:{}}]}),bands:a.flatMap(e=>{let a=/^sankey:link:([^:]+):([^:]+)$/u.exec(e.nodeId);if(!a||"polygon"!==e.shape||!e.points)return[];let i=e.points.map(t=>({x:e.x+t.x,y:e.y+t.y})),s=xe(i,"left"),o=xe(i,"right"),r=t.get(`text:${e.nodeId}`),n=l.get(`leader:${e.nodeId}`);return[{...n?{leader:[n.points[0],n.points.at(-1)]}:{},source:a[1],target:a[2],points:i,bounds:yG(i),sourceEnd:s,targetEnd:o,width:Math.round((s.bottom-s.top)*100)/100,...r?{text:r.text,textBox:w9(r)}:{}}]}),texts:[...t.values()].map(e=>({id:e.id,text:e.text,box:w9(e),maxWidth:e.maxWidth??iC(e.text,e.fontSize),fontSize:e.fontSize}))}),d=new Map(o.map(e=>[e.id,e]));for(let e of o){let t={out:r.filter(t=>t.source===e.id).map(e=>e.sourceEnd),in:r.filter(t=>t.target===e.id).map(e=>e.targetEnd)},a={out:0,in:0};for(let l of["out","in"]){let i="out"===l?e.box.right:e.box.left,o=-1/0;for(let r of t[l].toSorted((e,t)=>e.top-t.top))(Math.abs(r.x-i)>.6||r.top<e.box.top-.6||r.bottom>e.box.bottom+.6||r.top<o-.6)&&s.push({code:"band-off-node",elementId:`node:sankey:node:${e.id}`,message:`A band at the ${"out"===l?"right":"left"} of "${e.id}" leaves its bar or overlaps another band.`}),o=r.bottom,a[l]+=r.bottom-r.top}let l=e.box.bottom-e.box.top;(Math.abs(Math.max(a.in,a.out)-l)>.6||Math.min(a.in,a.out)>l+.6)&&s.push({code:"side-unbalanced",elementId:`node:sankey:node:${e.id}`,message:`The bands at "${e.id}" sum to ${a.in.toFixed(2)} in and ${a.out.toFixed(2)} out on a bar ${l.toFixed(2)} tall.`})}for(let e of r){let t=`node:sankey:link:${e.source}:${e.target}`,a=d.get(e.source),l=d.get(e.target);if((!a||!l||e.bounds.left<a.box.right-.6||e.bounds.right>l.box.left+.6)&&s.push({code:"band-leaves-gap",elementId:t,message:`Band "${e.source}" → "${e.target}" runs outside the gap between its bars.`}),e.leader){let a=[...o.map(e=>({id:`node:sankey:node:${e.id}`,box:e.box})),...n.filter(t=>t.id!==`text:sankey:link:${e.source}:${e.target}`)].find(t=>yT(e.leader[0],e.leader[1],t.box));a&&s.push({code:"leader-over-label",elementId:t,message:`The leader of "${e.source}" → "${e.target}" crosses "${a.id}".`})}for(let a of o)a.id!==e.source&&a.id!==e.target&&yD(a.box,e.points,e.bounds)&&s.push({code:"band-over-node",elementId:t,message:`Band "${e.source}" → "${e.target}" runs over "${a.id}".`})}for(let[e,t]of n.entries()){for(let a of(t.text.split("\n").some(e=>iC(e,t.fontSize)>t.maxWidth+.5)&&s.push({code:"text-overflow",elementId:t.id,message:`Text "${t.id}" is wider than its box.`}),n.slice(e+1)))yX(t.box,a.box)&&s.push({code:"labels-overlap",elementId:t.id,message:`Labels "${t.id}" and "${a.id}" overlap.`});for(let e of o)yX(t.box,e.box)&&s.push({code:"label-over-node",elementId:t.id,message:`Label "${t.id}" covers bar "${e.id}".`});let a=/^text:sankey:(node|link):([^:]+)(?::([^:]+))?$/u.exec(t.id);for(let e of r)!(a?.[1]==="link"?a[2]===e.source&&a[3]===e.target:a?.[1]==="node"&&a[2]===e.source)&&yD(t.box,e.points,e.bounds)&&s.push({code:"label-over-band",elementId:t.id,message:`Label "${t.id}" covers band "${e.source}" → "${e.target}".`});if(a?.[1]==="node"){let e=d.get(a[2]),l=e?.knockout;if(!(void 0!==l&&l.left<=t.box.left+.5&&l.right>=t.box.right-.5&&l.top<=t.box.top+.5&&l.bottom>=t.box.bottom-.5)&&r.some(e=>e.source===a[2]&&yD(t.box,e.points,e.bounds))&&s.push({code:"label-on-band",elementId:t.id,message:`Label "${t.id}" sits on its own bands with no paper behind it.`}),l)for(let e of r)e.source!==a[2]&&yD(l,e.points,e.bounds)&&s.push({code:"label-on-band",elementId:t.id,message:`The paper behind "${t.id}" hides band "${e.source}" → "${e.target}".`})}if(a?.[1]==="link"){let e=r.find(e=>e.source===a[2]&&e.target===a[3]),l=e&&d.get(e.source),i=e&&d.get(e.target),o=[{x:t.box.left,y:t.box.top},{x:t.box.right,y:t.box.top},{x:t.box.right,y:t.box.bottom},{x:t.box.left,y:t.box.bottom}],n=void 0!==e&&o.every(t=>yY(t,e.points)),c=void 0!==i&&1>=Math.abs(t.box.right-(i.box.left-6))||void 0!==l&&1>=Math.abs(t.box.left-(l.box.right+6));if(e&&!n&&!c){let a={left:t.box.left-4,top:t.box.top-4,right:t.box.right+4,bottom:t.box.bottom+4};for(let l of r)l!==e&&yD(a,l.points,l.bounds)&&s.push({code:"label-on-band",elementId:t.id,message:`Value "${t.id}" sits within 4 px of band "${l.source}" → "${l.target}".`})}}}return s}(m);if(w.length>0){let e=`${w.length} labels, values or leaders would overlap another label or cover another flow, so the diagram would not read.`;return yield*new b7({status:"quality_failed",context:{...h,quality:{...u,accepted:!1,score:0,checks:[{code:"sankey_layout",passed:!1,severity:"error",message:e,refs:[]}]},issues:[kn({code:"quality_below_threshold",stage:"quality",ref:{kind:"diagram",id:p.id},message:e,hint:"Shorten node and link labels or leave link labels out, or split the flows into smaller diagrams, then call buildSankey again."})]}})}let x={...f,partial:kZ(m)},b=yield*kW({scene:m,formats:kw(d.options),inlineFormats:kx(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b7({status:e.status,context:{..."export_failed"===e.status?x:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...kG(d.requestId),normalizedSpec:p,quality:u,artifact:b,issues:[]}}),k6=o.fn("codeMode.buildWireframe.workflow")(function*(e){var t,a;let l,s,r,n=i.q$Z(nq,{errors:"all",reportInput:!0})("object"==typeof e&&null!==e&&"spec"in e?{...e,spec:function(e){if(!lQ(e))return e;let t={...e},a=l1(t,["screens","pages","views","frames"],!0),l=["children","components","elements","layout","body"].find(e=>Array.isArray(t[e]));if(void 0===a&&void 0!==l){let e=l1(t,[l]);if(Array.isArray(e)){let l=l1(t,["device","platform","viewport"]);a=[{name:t.title??"Screen",...void 0===l?{}:{device:l},children:e}]}}if(!Array.isArray(a))return void 0===a?t:{...t,screens:a};let i=new Set(a.flatMap(e=>lQ(e)&&"string"==typeof e.id?[e.id]:[])),s=a.map((e,t)=>{if(!lQ(e))return e;let a={...e},l=l0(l1(a,["name","title","label"])),s=l1(a,l8,!0),o=l1(a,["device","platform","viewport","size","form"]),r=a.align,n="string"==typeof o?l2(ia,l3(o))??o:o,d=a.id;if("string"!=typeof d||0===d.length){let e=("string"==typeof l?l:"").toLowerCase().normalize("NFKD").replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||`screen-${t+1}`,a=e;for(let t=2;i.has(a);t+=1)a=`${e}-${t}`;i.add(a),d=a}let c="string"==typeof r?it({type:"column",align:r}):{};return{...a,id:d,...void 0===l?{}:{name:l},...void 0===n?{}:{device:n},...lQ(c)&&void 0!==c.align?{align:c.align}:{},...Array.isArray(s)?{children:s.map(it)}:void 0===s?{}:{children:s}}}),o=new Set,r=new Map,n=new Map,d=(e,t,a)=>e.set(t,e.has(t)&&e.get(t)!==a?void 0:a);for(let e of s)lQ(e)&&"string"==typeof e.id&&(o.add(e.id),d(r,l3(e.id),e.id),"string"==typeof e.name&&d(n,l3(e.name),e.id));let c=e=>{if(!lQ(e))return e;let t=e.target,a="string"==typeof t?(e=>{if(o.has(e))return e;let t=l3(e).replace(/^[#/]+/u,"");return r.has(t)?r.get(t):n.get(t)})(t):void 0,l=e.children;return{...e,...void 0===a||a===t?{}:{target:a},...Array.isArray(l)?{children:l.map(c)}:{}}};return{...t,screens:s.map(e=>lQ(e)&&Array.isArray(e.children)?{...e,children:e.children.map(c)}:e)}}(e.spec)}:e);if(!xH.oJ(n))return yield*new b8({status:"invalid_input",context:{issues:kf(os(n.failure))}});let d=yield*bm,c=n.success,p=yield*o.OH5(()=>d.createId("build")),h=(l=oe((t=c.spec).title),s=new Set(t.screens.flatMap(e=>kv(e.id)??[])),{id:kv(t.id)??(km(l)||"sketchi-wireframe"),title:l,screens:t.screens.map((e,t)=>{let a=oe(e.name);return{id:kv(e.id)??((e,t)=>{let a=km(e)||`screen-${t+1}`,l=a;for(let e=2;s.has(l);e+=1)l=`${a}-${e}`;return s.add(l),l})(a,t),name:a,device:e.device??"desktop",...e.align?{align:e.align}:{},children:e.children.map(bU)}}),style:{...y}}),g={buildId:p,...kG(c.requestId),normalizedSpec:h},u=lN(bX(h)).map(e=>kn({code:bT[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(u.length>0)return yield*new b8({status:"invalid_wireframe",context:{...g,issues:u}});let f=(a=c.options?.minQualityScore??8,r=e=>e.reduce((e,t)=>e+1+r(t.children??[]),0),{accepted:10>=a,score:10,threshold:a,summary:{nodeCount:h.screens.reduce((e,t)=>e+r(t.children),0),edgeCount:0},checks:[]}),m={...g,quality:f};if(!f.accepted)return yield*new b8({status:"quality_failed",context:{...m,issues:ky(f)}});let v=yield*o.SvU({try:()=>(function(e){let t,a,l,i=lJ(e),{placed:s,origins:o,frames:r}=(a=function(e){let t=t=>{let a=[],l=0,i=0;for(let s=0;s<e.length;s+=t){let o=e.slice(s,s+t),r=0;for(let e of o)a.push({x:r,y:l}),r+=e.width+80;i=Math.max(i,r-80),l+=Math.max(...o.map(e=>e.height))+96}return{origins:a,aspect:i/Math.max(1,l-96)}},a=e.length;for(;a>1&&t(a).aspect>2.45;)a-=1;let l=Math.ceil(e.length/a);return t(Math.ceil(e.length/l)).origins}(t=i.screens.map(wF)),l=t.map((e,t)=>({type:"frame",id:`frame:${e.screen.id}`,name:e.screen.name.replace(/\s*\n\s*/gu," "),x:a[t].x,y:a[t].y,width:e.width,height:e.height})),{placed:t,origins:a,frames:l}),n=s.map((e,t)=>(function(e,t){let{screen:a}=e,l=`frame:${a.id}`,i=[],s=[],o=[],r=(e,t,n,d,c,p,h,g=[])=>{var u;let f={x:t+e.x,y:n+e.y,width:e.width,height:e.height},m=`group:${a.id}:${e.path}`,v=(u=e.component,lU.has(u.type)),y=!v||ww.has(e.component.type)?[m,...d]:d,w=!0===e.component.disabled?50:h,x={groupIds:y,frameId:l,...void 0===w?{}:{opacity:w}},b=`wf:${a.id}:${e.path}`,{target:k}=e.component,M=void 0!==k&&("button"===e.component.type||"link"===e.component.type);for(let t of(M&&"link"===e.component.type&&i.push({...wm(`${b}:hit`,"link-target",f,wn,{fill:wi,stroke:wi},e.component.text??"Link",x),opacity:0}),i.push(...e.paint(f,x,b)),M&&o.push({screen:a.id,path:e.path,target:k,nodeId:"link"===e.component.type?`${b}:hit`:`${b}:box`,box:f,ancestors:new Set(g)}),s.push({path:e.path,type:e.component.type,box:f,parent:c,...e.flow?{flow:e.flow}:{},overlay:p,group:m}),e.children))r(t,f.x,f.y,v&&ww.has(e.component.type)?y:d,e.path,p,w,[...g,e.path])};for(let s of e.laid){let o=e.modals.has(s.path);o&&e.scrim&&!i.some(e=>e.id===`wf:${a.id}:scrim`)&&i.push({...wm(`wf:${a.id}:scrim`,"scrim",{x:t.x,y:t.y,width:e.width,height:e.height},wd,{fill:wr,stroke:wr},"Backdrop",{groupIds:[],frameId:l}),opacity:30}),r(s,t.x,t.y,[],void 0,o,void 0)}return{elements:i,components:s,navigations:o}})(e,o[t])),d=n.flatMap(e=>e.navigations),c=new Set(d.map(e=>e.target)),p=r.map((e,t)=>{let a=s[t].screen.id;return c.has(a)?{...e,nodeId:wE(a)}:e}),h=function(e,t,a){var l;let i;if(0===e.length)return[];let s=new Map(t.map(e=>[e.id,e])),o=t.map(e=>sT(e)),r=[...t,...o],n={x:Math.min(...r.map(e=>e.x))-64,y:Math.min(...r.map(e=>e.y))-64,width:Math.max(...r.map(e=>e.x+e.width))-Math.min(...r.map(e=>e.x))+128,height:Math.max(...r.map(e=>e.y+e.height))-Math.min(...r.map(e=>e.y))+128},d=new Map(a.map((e,a)=>[t[a].id,e])),c=(l=e.map(e=>{let a=s.get(`frame:${e.screen}`),l=s.get(`frame:${e.target}`),i=d.get(a.id),r=`wf:${e.screen}:${e.path}:`,n=i.components.find(t=>t.path===e.path)?.overlay===!0,c=i.elements.findIndex(e=>"node"===e.type&&"wireframe:scrim"===e.kind);return{source:e.box,target:l,obstacles:[...t.filter(e=>e!==a&&e!==l),...o,...i.components.filter(t=>t.path!==e.path&&!e.ancestors.has(t.path)&&!t.path.startsWith(`${e.path}.`)&&(!n||t.overlay)).map(e=>e.box),...i.elements.flatMap((e,t)=>{let a,l;return"text"!==e.type||e.id.startsWith(r)||e.containerId||n&&!(t>c)?[]:[(a=Math.max(1,Math.min(e.maxWidth??160,Math.ceil(iC(e.text,e.fontSize)))),l=wp(e.text.split("\n").length,e.fontSize),{x:e.x-a/2,y:e.y-l/2,width:a,height:l})]})]}}),i=[],l.map(e=>{let t=function(e,t,a){var l;let i,{source:s,target:o}=e,r=y3(s.y+s.height/2),n=(l=[...e.obstacles,s]).filter((e,t)=>!l.some((a,l)=>l!==t&&y2(a,e)&&(!y2(e,a)||l<t))).map(e=>({left:e.x-4,top:e.y-4,right:e.x+e.width+4,bottom:e.y+e.height+4})),d={left:y3(o.x),top:y3(o.y),right:y3(o.x+o.width),bottom:y3(o.y+o.height)},c=y3(s.x+s.width+4),p=y3(s.x-4),h=y5([t.x,t.x+t.width,p,c,d.left,d.right,d.left+24,d.right-24,d.left-28,d.right+28,...n.flatMap(e=>[e.left,e.right])],t.x,t.x+t.width),g=y5([t.y,t.y+t.height,r,d.top,d.bottom,d.top+24,d.bottom-24,d.top-28,d.bottom+28,...n.flatMap(e=>[e.top,e.bottom])],t.y,t.y+t.height),u=h.length,f=g.length,m=(e,t)=>t*u+e,v=(e,t,a)=>t>e.left&&t<e.right&&a>e.top&&a<e.bottom,y=(e,t)=>v(d,e,t)||n.some(a=>v(a,e,t)),w=(e,t)=>e>=d.left&&e<=d.right&&t>=d.top&&t<=d.bottom&&!v(d,e,t),x=new Uint8Array(u*f);for(let e=0;e<f;e+=1)for(let t=0;t<u;t+=1)x[m(t,e)]=+!y(h[t],g[e]);let b=(e,t,a,l)=>!y((e+a)/2,(t+l)/2),k=new Float64Array(u*f*4).fill(1/0),M=new Int32Array(u*f*4).fill(-1),z=new Float64Array(u*f*4),C=new y0,_=(e,t)=>Math.max(0,d.left-e,e-d.right)+Math.max(0,d.top-t,t-d.bottom),q=g.indexOf(r),L=(e,t)=>{let a=h.indexOf(e);if(a<0||q<0||!x[m(a,q)])return;let l=4*m(a,q)+t;k[l]=0,C.push(_(e,r),l)};L(c,0),L(p,2);let S=0,B=1/0;for(;C.size>0&&S<4e5;){let{cost:e,state:t}=C.pop();if(e>=B)break;let l=k[t],s=Math.floor(t/4),o=t%4,r=s%u,n=Math.floor(s/u),c=h[r],p=g[n];if(!(e-_(c,p)>l+1e-6))for(let[e,s]of(S+=1,y1.entries())){if((e+2)%4===o)continue;let v=r+s.dx,y=n+s.dy;if(v<0||y<0||v>=u||y>=f)continue;let q=h[v],L=g[y],S=Math.abs(q-c)+Math.abs(L-p),A=48*(e!==o),P=(e===o?z[t]:0)+S;if(w(q,L)){let e=0!==s.dx&&(q===d.left||q===d.right)||0!==s.dy&&(L===d.top||L===d.bottom),a=0!==s.dx?L>=d.top+24&&L<=d.bottom-24:q>=d.left+24&&q<=d.right-24,o=l+A+S;e&&a&&P>=28&&b(c,p,q,L)&&o<B&&(B=o,i={state:t,end:{x:q,y:L}});continue}let V=m(v,y);if(!x[V]||!b(c,p,q,L))continue;let H=4*V+e,I=l+S+A+function(e,t,a){let l=.01>Math.abs(e.y-t.y),i=l?Math.min(e.x,t.x):Math.min(e.y,t.y),s=l?Math.max(e.x,t.x):Math.max(e.y,t.y),o=l?e.y:e.x,r=0;for(let e of a)for(let t=1;t<e.length;t+=1){let a=e[t-1],n=e[t],d=.01>Math.abs(a.y-n.y),c=d?Math.min(a.x,n.x):Math.min(a.y,n.y),p=d?Math.max(a.x,n.x):Math.max(a.y,n.y),h=d?a.y:a.x;if(d===l){if(Math.abs(h-o)>=6)continue;let e=Math.min(s,p)-Math.max(i,c);e>0&&(r+=60*e)}else h>=i&&h<=s&&o>=c&&o<=p&&(r+=16)}return r}({x:c,y:p},{x:q,y:L},a);I<k[H]&&(k[H]=I,M[H]=t,z[H]=P,C.push(I+_(q,L),H))}}if(!i)return;let A=[];for(let e=i.state;e>=0;e=M[e]){let t=Math.floor(e/4);A.push({x:h[t%u],y:g[Math.floor(t/u)]})}return A.reverse(),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 l=t.at(-2);l&&e&&(.01>Math.abs(l.x-e.x)&&.01>Math.abs(e.x-a.x)||.01>Math.abs(l.y-e.y)&&.01>Math.abs(e.y-a.y))&&t.pop(),t.push(a)}return t}([{x:A[0].x>s.x?s.x+s.width:s.x,y:r},...A,i.end])}(e,n,i);return t&&i.push(t),t}));return e.flatMap((e,t)=>{let a=c[t];if(!a||a.length<2)return[];let l=wU(e.screen,e.path);return[{type:"arrow",id:l,edgeId:l,sourceNodeId:e.nodeId,targetNodeId:wE(e.target),points:a,startArrowhead:null,endArrowhead:"arrow",strokeColor:y9,strokeWidth:2}]})}(d,p,n),g=p.map(e=>sT(e)),u=h.flatMap(e=>e.points),f=Math.min(...p.map(e=>e.x),...u.map(e=>e.x)),m=Math.min(...g.map(e=>e.y),...u.map(e=>e.y)),v=40-f,y=40-m,w=[...p.map(e=>wO(e,v,y)),...n.flatMap(e=>e.elements.map(e=>wO(e,v,y))),...h.map(e=>wO(e,v,y))],x=Math.max(...p.map(e=>e.x+e.width),...u.map(e=>e.x)),b=Math.max(...p.map(e=>e.y+e.height),...u.map(e=>e.y)),k={kind:"canvas",version:1,diagramId:i.id,title:i.title,width:Math.ceil(x+v+40),height:Math.ceil(b+y+40),accentColor:i.style.accentColor,backgroundColor:i.style.backgroundColor,elements:w,layers:[],layouts:[],zOrder:w.map(e=>e.id)},M=e=>({...e,x:e.x+v,y:e.y+y}),z=new Set(h.map(e=>e.id));return{scene:k,layout:{screens:s.map((e,t)=>({id:e.screen.id,device:e.screen.device,frame:M(p[t]),widened:e.widened,components:n[t].components.map(e=>({...e,box:M(e.box)}))})),navigations:d.map(e=>({screen:e.screen,path:e.path,target:e.target,routed:z.has(wU(e.screen,e.path))}))}}})(bX(h)).scene,catch:e=>new b8({status:"render_failed",context:{...m,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:h.id},message:e instanceof Error?e.message:"Unable to render wireframe scene.",hint:"Repair the screens and components and retry."})]}})}).pipe(o.fRP("codeMode.buildWireframe.render")),w=i5(v);if(w.length>0)return yield*new b8({status:"render_failed",context:{...m,issues:kz(w).map(e=>({...e,hint:"Shorten long texts, or split the screens into separate wireframes, and retry buildWireframe."}))}});let x={...m,partial:kZ(v)},b=yield*kW({scene:v,formats:kw(c.options),inlineFormats:kx(c.options),...c.requestId?{requestId:c.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b8({status:e.status,context:{..."export_failed"===e.status?x:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:p,...kG(c.requestId),normalizedSpec:h,quality:f,artifact:b,issues:[]}}),k7=o.fn("codeMode.buildQuadrantChart.workflow")(function*(e){var t,a;let l,s,r=i.q$Z(nS,{errors:"all",reportInput:!0})(e);if(!xH.oJ(r))return yield*new ke({status:"invalid_input",context:{issues:kf(os(r.failure))}});let n=yield*bm,d=r.success,c=yield*o.OH5(()=>n.createId("build")),p=(l=oe((t=d.spec).title),s=e=>({title:oe(e.title),low:oe(e.low),high:oe(e.high)}),{id:kv(t.id)??(km(l)||"sketchi-quadrant-chart"),title:l,xAxis:s(t.xAxis),yAxis:s(t.yAxis),quadrants:{topLeft:oe(t.quadrants.topLeft),topRight:oe(t.quadrants.topRight),bottomLeft:oe(t.quadrants.bottomLeft),bottomRight:oe(t.quadrants.bottomRight)},points:t.points.map(e=>{let t=kv(e.group);return{label:oe(e.label),x:e.x,y:e.y,...t?{group:t}:{}}}),style:{...y}}),h={buildId:c,...kG(d.requestId),normalizedSpec:p},g=bD(ih(bR(p)));if(g.length>0)return yield*new ke({status:"invalid_quadrant_chart",context:{...h,issues:g}});let u={accepted:10>=(a=d.options?.minQualityScore??8),score:10,threshold:a,summary:{nodeCount:p.points.length,edgeCount:0},checks:[]},f={...h,quality:u};if(!u.accepted)return yield*new ke({status:"quality_failed",context:{...f,issues:ky(u)}});let m=yield*o.SvU({try:()=>(function(e){let t,a,l,i,s,o,r,n,d,c,p,h,g,u,f,m,v=iu(e),y=v.style.backgroundColor,w=new w8(y),x=function(e){let t,a,l,i,s,o=(i=Math.max(...ii.map(t=>Math.max(...e.quadrants[t].split(/\s+/u).map(e=>Math.ceil(iC(e,16)))))),s=wD(e.xAxis.low,170,13).width+wD(e.xAxis.high,170,13).width+16,wX.find(e=>i<=e/2-20&&s<=e));if(void 0===o)throw new ig([{code:"invalid_quadrant_text",path:"quadrants",message:"A quadrant name or the x axis's end labels hold a word too long for the largest plot.",hint:"Shorten the longest unbroken word in the quadrant names and the x axis's low and high labels, or break it with a space."}]);let r=Math.max(2,Math.ceil(.2*e.points.length)),n=e=>[e.blocked+e.covered,e.overDots,e.leaders],d=(e,t)=>{let[a,l]=[n(e),n(t)],i=a.findIndex((e,t)=>e!==l[t]);return -1!==i&&a[i]>l[i]},c=e=>e.blocked+e.covered+e.overDots===0,p=e=>c(e)&&e.leaders<=r+e.clumped,h={spent:0,limit:1/0},g=a=>{let l=w7(e,a,{work:h}),i=l.blocked>0&&l.blocked<=Math.max(3,e.points.length/4);if(i){let t=w7(e,a,{crowded:new Set(l.blockedPoints),work:h});d(t,l)||(l=t)}if(i&&l.blocked){let t=w7(e,a,{crowded:new Set(l.blockedPoints),relaxed:!0,work:h});d(t,l)||(l=t)}return(!t||d(t,l))&&(t=l),l},u=()=>{let l=new Set(t.blockedPoints);for(let a of[{labelFont:12},{labelFont:12,thorough:!0},{labelFont:12,relaxed:!0},{labelFont:12,relaxed:!0,thorough:!0}]){if(0===t.blocked&&a.relaxed||h.spent>h.limit)break;let i=w7(e,wX.at(-1),{crowded:l,work:h,...a});if(d(t,i)&&(t=i),c(t))break}a=t},f=wX.filter(e=>e>=o),m=0,v=0;for(;m<f.length&&!(t&&c(t)&&m-f.indexOf(t.size)>2);){let e=g(f[m]);if(m+=1,p(e))return e;if(v=e.blocked>3&&void 0!==l&&e.blocked>=l?v+1:0,l=e.blocked,v>=2)break}if(!c(t)&&t.blocked+t.covered<=3&&u(),t.blocked||t.covered){for(h.limit=h.spent+4e6;m<f.length&&h.spent<=h.limit;m+=1){let e=g(f[m]);if(p(e))return e}t!==a&&u()}if(t.blocked||t.covered)throw new ig([{code:"quadrant_too_large",path:t.blocked?`points.[${t.blockedPoints[0]}]`:"quadrants",message:t.blocked?`The labels of ${t.blocked} points cannot all sit clear of the other labels and dots.`:"A quadrant name cannot sit clear of every dot in its quadrant.",hint:"Spread the scores of points that nearly coincide, shorten their labels or the quadrant names, or split the chart."}]);return t}(v),{size:b}=x,k=wJ(b);for(let e of Object.keys(k)){let t=function(e,t){let a=(e,t)=>Number.parseInt(e.slice(t,t+2),16);return`#${[1,3,5].map(l=>Math.round(.89*a(t,l)+.11*a(e,l)).toString(16).padStart(2,"0")).join("")}`}(wY[e],y),a=`quadrant:region:${e}`;w.mark(a,"rectangle",k[e],v.quadrants[e],{fillColor:t,strokeColor:t,groupIds:[a]},"back");let l=x.names[e];w.text(`quadrant:name:${e}`,l.text,l.box,16,wR,"topRight"===e||"bottomRight"===e?"right":"left",a)}let M={strokeColor:"#a99f8c"};w.line("quadrant:midline:vertical",{x:b/2,y:0},{x:b/2,y:b},M),w.line("quadrant:midline:horizontal",{x:0,y:b/2},{x:b,y:b/2},M),t={strokeColor:wR,strokeWidth:2,endArrowhead:"arrow"},a="quadrant:axis:x",l="quadrant:axis:y",w.line(a,{x:0,y:b+14},{x:b,y:b+14},{...t,groupIds:[a]}),w.line(l,{x:-14,y:b},{x:-14,y:0},{...t,groupIds:[l]}),i=b+14+8,s=wD(v.xAxis.low,170,13),o=wD(v.xAxis.high,170,13),r=wD(v.xAxis.title,b,14),n=wZ(0,i,s),d=wZ(b-o.width,i,o),(wj(c=wZ(b/2-r.width/2,i,r),n,16)||wj(c,d,16))&&(c=wZ(b/2-r.width/2,Math.max(n.bottom,d.bottom)+4,r)),w.text(`${a}:low`,s,n,13,wR,"left",a),w.text(`${a}:high`,o,d,13,wR,"right",a),w.text(`${a}:title`,r,c,14,wT,"center",a),p=wD(v.yAxis.high,130,13),h=wD(v.yAxis.low,130,13),g=wD(v.yAxis.title,130,14),u=wZ(-22-p.width,0,p),f=wZ(-22-h.width,b-h.height,h),m=Math.min(Math.max(b/2-g.height/2,u.bottom+12),f.top-12-g.height),w.text(`${l}:high`,p,u,13,wR,"right",l),w.text(`${l}:low`,h,f,13,wR,"right",l),w.text(`${l}:title`,g,wZ(-22-g.width,m,g),14,wT,"right",l);let z=ip(v),C=new Map(z.map((e,t)=>[e,pT[t]])),_={left:0,top:0,right:b,bottom:b};v.points.forEach((e,t)=>{let a,l=`quadrant:point:${t}`,i=wK(e,_),s=void 0===(a=e.group)?void 0:z.find(e=>ic(e)===ic(a)),o=void 0!==s?C.get(s):z.length?"#8c826f":pT["0"];w.mark(l,"ellipse",w1(i),e.label,{fillColor:o,strokeColor:y,strokeWidth:2,groupIds:[l]},"front");let r=x.labels[t];r.leader&&w.line(`quadrant:leader:${t}`,r.leader[0],r.leader[1],{strokeColor:"#8c826f",groupIds:[l]}),w.text(`quadrant:label:${t}`,r.text,r.box,x.labelFont,wT,r.box.left>=i.x?"left":r.box.right<=i.x?"right":"center",l)}),function(e,t,a,l){let i=e.bounds(),s=Math.max(i.right-i.left,360),o=i.top-18;if(a.length){let t=a.map((e,t)=>{let a=wD(e,200,14);return{index:t,group:e,text:a,width:18+a.width}}),r=[[]],n=0;for(let e of t){let t=r.at(-1);t.length&&n+18+e.width>s?(r.push([e]),n=e.width):(n+=18*!!t.length+e.width,t.push(e))}let d=r.map(e=>Math.max(...e.map(e=>e.text.height))),c=o-d.reduce((e,t)=>e+t,0)-(r.length-1)*6;o=c-12,r.forEach((t,a)=>{let s=d[a],o=c+s/2,r=i.left;for(let a of t){let t=`quadrant:legend:${a.index}`,i=l.get(a.group);e.mark(`quadrant:key:${a.index}`,"ellipse",{left:r,top:o-6,right:r+12,bottom:o+6},a.group,{fillColor:i,strokeColor:e.surface,strokeWidth:2,groupIds:[t]},"front"),e.text(`${t}:label`,a.text,wZ(r+18,o-a.text.height/2,a.text),14,wT,"left",t),r+=a.width+18}c+=s+6})}let r=wD(t.title,s,20);e.text("quadrant:title",r,wZ(i.left,o-r.height,r),20,wT,"left")}(w,v,z,C);let q=w.bounds(),L=40-q.left,S=40-q.top,B=w.elements.map(e=>{if("line"===e.type){let[t,a,...l]=e.points.map(e=>({x:wG(e.x+L),y:wG(e.y+S)}));return{...e,points:[t,a,...l]}}return"arrow"===e.type?e:{...e,x:wG(e.x+L),y:wG(e.y+S)}});return{kind:"canvas",version:1,diagramId:v.id,title:v.title,width:Math.ceil(q.right-q.left+80),height:Math.ceil(q.bottom-q.top+80),accentColor:v.style.accentColor,backgroundColor:v.style.backgroundColor,elements:B,layers:[],layouts:[],zOrder:w.zOrder()}})(bR(p)),catch:e=>new ke(e instanceof ig?{status:"invalid_quadrant_chart",context:{...f,issues:bD(e.issues)}}:{status:"render_failed",context:{...f,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render quadrant chart scene.",hint:"Repair the axes, quadrant names and points and retry."})]}})}).pipe(o.fRP("codeMode.buildQuadrantChart.render")),v=i5(m);if(v.length>0)return yield*new ke({status:"render_failed",context:{...f,issues:kz(v).map(e=>({...e,hint:"Use fewer points or shorter labels and retry buildQuadrantChart."}))}});let w={...f,partial:kZ(m)},x=yield*kW({scene:m,formats:kw(d.options),inlineFormats:kx(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new ke({status:e.status,context:{..."export_failed"===e.status?w:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...kG(d.requestId),normalizedSpec:p,quality:u,artifact:x,issues:[]}}),k8=o.fn("codeMode.buildTimeline.workflow")(function*(e){var t,a;let l,s,r=i.q$Z(nd,{errors:"all",reportInput:!0})(e);if(!xH.oJ(r))return yield*new b9({status:"invalid_input",context:{issues:kf(os(r.failure))}});let n=yield*bm,d=r.success,c=yield*o.OH5(()=>n.createId("build")),p=(l=oe((t=d.spec).title),{id:(s={id:kv(t.id)??(km(l)||"sketchi-timeline"),title:l,type:"timeline",style:{...y},events:t.events.map(e=>({...e}))}).id,title:l,events:eh(s),...t.lanes?{lanes:[...t.lanes]}:{},...t.today?{today:t.today}:{},style:s.style}),h={buildId:c,...kG(d.requestId),normalizedSpec:p},g=en(bw(p)).map(e=>kn({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 b9({status:"invalid_timeline",context:{...h,issues:g}});let u={accepted:10>=(a=d.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 b9({status:"quality_failed",context:{...f,issues:ky(u)}});let m=yield*o.SvU({try:()=>(function(e){let t,a,l=ec(e),i=eh(l),s=hB(l),o=er(l),r=(o.length?o:[""]).map((e,t)=>{let a=gt[t%gt.length];return{...a,stroke:a.stroke||l.style.accentColor}}),n=i[0]?.date!==void 0,d=[],c=e=>{let t=d.findIndex(t=>t.time===e.time&&t.tie===e.tie);return t>=0?t:(d.push(e),d.length-1)},p=void 0===l.today?void 0:es(l.today),h=new Map,g=new Map,u=[!1,!0].flatMap(e=>i.flatMap((t,a)=>{let l,i,s=void 0!==t.end;if(s!==e)return[];let o=n?es(t.date):void 0,r=void 0===t.end?void 0:es(t.end),d=o?o.start:t.order??a,u=t.lane??"",f=r?(d+r.end)/2:d,m=p&&r&&p.start>d&&p.start<r.end,v=r&&(m||h.has(`${u}\0${f}`))?function(e,t,a){let l=[e,...a.filter(a=>a>e&&a<t),t].toSorted((e,t)=>e-t),i={from:e,to:e};for(let[e,t]of l.slice(1).entries())t-l[e]>i.to-i.from&&(i={from:l[e],to:t});return(i.from+i.to)/2}(d,r.end,[...g.get(u)??[],...m?[p.start]:[]]):f,y=c({time:v,tie:(l=`${u}\0${v}`,i=h.get(l)??0,h.set(l,i+1),g.set(u,[...g.get(u)??[],v]),i)});return[{event:t,index:a,span:s,start:s?c({time:d,tie:0}):y,end:r?c({time:r.end,tie:0}):void 0,stem:y}]})).toSorted((e,t)=>e.index-t.index),f=p?c({time:p.start,tie:0}):void 0,m=d.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}`,l=s.events.get(e.event.id),i=[...l?[ga(`date:${a}`,l,14,t.ink)]:[],ga(`label:${a}`,e.event.label,16,v.ink),...e.event.description?[ga(`description:${a}`,e.event.description,13,h9)]:[]];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,(l?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,z=e=>x.some(t=>t.span&&t.startKey<=e&&t.endKey>e),C=w.slice(1).map((e,t)=>e.time-w[t].time),_=new Map,q=e=>{let t=_.get(e);if(!t){var a;let l,i,s,o=(a=C[e],l=(e,t)=>`${e} ${t}${1===e?"":"s"}`,i=e=>l(Math.max(1,Math.round(a/hA[e])),e),s=e=>{let t=a/hA[e];return l(t<10?Math.round(10*t)/10:Math.round(t),e)},a<1e3?i("millisecond"):a<12e4?s("second"):a<72e5?i("minute"):a<1728e5?i("hour"):a<5184e6?i("day"):a<63113904e3?i("month"):s("year"));t={text:o,half:i_(o,13,200)/2+6},_.set(e,t)}return t},L=[...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=C.reduce((e,t)=>e+t,0),l=x.length*k,i=10*k,s=a>0?l/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 l=a[t-1];return l&&l.stemKey!==e.stemKey?[{from:l.stemKey,to:e.stemKey,min:Math.max(28,e.inset+h8+1)}]:[]})),...x.filter(e=>e.span).map(e=>({from:e.startKey,to:e.endKey,min:12}))].filter(e=>e.to>e.from),d=Math.max(28,...o.map(e=>e.min)),c=(e,a)=>{let l=[0],i=0,s=0;return C.forEach((o,r)=>{let n=w[r+1];n.tie>0?l.push(i+n.tie*d):(i=t.has(r)?a?Math.max(i+a.get(r),s+Math.max(M,2*(q(r).half+3+16))):s+M:i+o*e,l.push(i)),s=Math.max(s,l[r+1])}),l},p=()=>{let[e,t]=[c(0),c(1)];return o.map(({from:a,to:l,min:i})=>{let s=e[l]-e[a];return{from:a,to:l,min:i,fixed:s,perScale:t[l]-e[l]-(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(s,2*i/h):1/0,u=s;for(;;){let e=C.reduce((e,a,l)=>e+(t.has(l)?0:a),0),a=t.size&&e>0?Math.min(2*s,Math.max(s,(l-t.size*M)/e)):s,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=C.flatMap((e,a)=>t.has(a)||!(e*u>r)||z(a)?[]:[a]);for(let{from:e,to:a,min:l,fixed:i,perScale:s}of o)if(i+s*u<l-1e-6){let l=C.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];l&&n.push(l.key)}if(!n.length)break;for(let e of n)t.add(e)}if(!t.size)return{x:c(u),breaks:t};let f=Math.max(M,...C.map((e,a)=>t.has(a)||z(a)?0:e*u)),m=[...t].filter(e=>C[e]*u>=M),v=Math.min(...m.map(e=>C[e])),y=Math.log2(Math.max(...m.map(e=>C[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,C[e]/v)))])),S=c(u,_),B=new Set(m),A=L.slice(1).flatMap((e,a)=>{let l=L[a],i=C.slice(l,e).map((e,t)=>l+t),s=i.filter(e=>B.has(e)).at(-1);return void 0===s&&i.some(e=>t.has(e))?[]:[{from:l,to:e,elapsed:w[e].time-w[l].time,broken:s}]}),P=e=>S[e.to]-S[e.from];for(let e of A.toSorted((e,t)=>e.elapsed-t.elapsed)){if(void 0===e.broken)continue;let{elapsed:t}=e,a=Math.max(...A.map(e=>1.5*e.elapsed<=t?P(e)+12:e.elapsed<t?P(e):0)),l=Math.min(...A.map(e=>void 0!==e.broken?1/0:e.elapsed>=1.5*t?P(e)-12:e.elapsed>t?P(e):1/0)),i=Math.min(Math.max(P(e),a),l);if(1e-9>Math.abs(i-P(e)))continue;let s=e.broken,o=w.findIndex(e=>e.time===w[s].time);_.set(s,S[s+1]-S[o]+i-P(e)),S=c(u,_)}return{x:S,breaks:t}},B=({x:e,breaks:t})=>{let a=e.map((t,a)=>Math.max(...e.slice(0,a+1))),l=e.map((t,a)=>Math.min(...e.slice(a))),i=t=>(a[t]+e[t+1])/2,s=w.slice(0,-1).flatMap((e,s)=>{if(z(s))return[];let o=l[s+1]-14;if(t.has(s)){let e=i(s)+q(s).half+3+7;return[{key:s,low:e,high:Math.max(e,o),broken:!0}]}let r=a[s]+14;return r<=o?[{key:s,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(l=>!l.span&&l.lane===t.lane&&(l.startKey<t.startKey||l.startKey>=t.endKey)&&e[l.startKey]+gi(l)>e[t.startKey]&&e[l.startKey]-gi(l)<a)?[t.lane]:[]}));return{x:e,breaks:t,reachBefore:a,rowsFor:t=>{let a=e[e.length-1],l=[],i=0,o=-24;for(let e=1;e<t;e+=1){let r=a*e/t,n=s.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;l.push({first:i,last:n.cut.key,start:o,end:n.at}),i=n.cut.key+1,o=n.at}return l.push({first:i,last:w.length-1,start:o,end:Math.max(...e)+24}),l},layout:(t,a=h7)=>{let l=Math.max(1,o.length);return t.map((t,s)=>{let o=t.start-32*(s>0),n=t=>e[t]-o,d=void 0!==b&&b>=t.first&&b<=t.last?n(b):void 0,c=Array.from({length:l},(e,l)=>(function(e,t,a,l,i=h7){let s;for(let o of gl){let r=function(e,t,a,l,i,s=h7){let o=[],r=new Map;for(let t of e.filter(e=>e.span).toSorted((e,t)=>e.startKey-t.startKey)){let e=o.findIndex((e,a)=>a>=l&&e<=t.startKey);for(e<0&&(e=Math.max(l,o.length));o.length<e;)o.push(-1/0);o[e]=t.endKey,r.set(t,e)}let n=o.length,d=s+16*Math.max(0,n-1),c=e=>t(e.stemKey),p=e.toSorted((e,t)=>c(t)-c(e)||t.index-e.index),h={"-1":[],1:[]},g={"-1":[],1:[]},u=[],f=(e,t,a=h8)=>t>e.left-a&&t<e.right+a,m=-1;p.forEach((e,t)=>{let l=c(e),o=p.slice(t+1).map(c),n=i.lookahead?p[t+2]:void 0,v=(e,t,a)=>{if(!n||t>a)return 0;let l=c(n);return l+10+16>e?1e3:Math.max(0,l+n.width/2+16-e)/2},y=l-e.width+e.inset,w=l-e.inset,x=(r.get(e)??0)>0,b=x?1:m,k=e=>e.option.near-(e.side===b?x?120:1:0),M=t=>[b,-b].flatMap(r=>{let p=((t,r)=>{let p=t<0?s:d,u=h[t],m=h[-t],x=[...g[t],...r&&void 0!==a&&Math.abs(a-l)>=14?[{x:a,reach:1/0}]:[]],b=[p,...u.map(e=>e.far+10)].filter(e=>e>=p).toSorted((e,t)=>e-t),k=l-e.width/2,M=[k,y,w,...u.flatMap(t=>[t.right+16,t.left-16-e.width]),...[...x,...o.map(e=>({x:e,reach:0}))].flatMap(t=>{let a=1/0===t.reach?3*h8:h8;return[t.x+a,t.x-a-e.width]}),...n?[c(n)+10+16,c(n)+n.width/2+16]:[]].map(e=>Math.min(w,Math.max(y,e)));for(let t of b){let a=t+e.height,s=a=>Math.abs(a-k)+v(a,t,p)+i.coverPenalty*o.slice(1).filter(t=>f({left:a,right:a+e.width},t)).length;for(let i of M.toSorted((e,t)=>s(e)-s(t)||e-t)){let s=i+e.width,r={left:i,right:s};if(u.every(e=>i>=e.right+16||e.left>=s+16||t>=e.far+10||e.near>=a+10)&&u.every(e=>!f(e,l)||e.near>t)&&x.every(e=>!f(r,e.x,1/0===e.reach?3*h8:h8)||e.reach<=t)&&o.every(e=>!f(r,e)||m.every(t=>!f(t,e))))return{near:t,left:i}}}})(r,t);return p?[{side:r,option:p}]:[]}).toSorted((e,t)=>k(e)-k(t))[0],z=M(!0)??M(!1);if(!z)throw Error(`Timeline label for "${e.event.id}" has no clear placement.`);let{side:C,option:_}=z,{near:q,left:L}=_;h[C].push({left:L,right:L+e.width,near:q,far:q+e.height}),g[C].push({x:l,reach:q});let S=r.get(e)??0,B=16*S;u.push({item:e,stemX:l,side:C,near:q,left:L,stemStart:C>0?B+gi(e):gi(e)-B,track:S}),m=-C});let v=(e,t)=>Math.max(t,...h[e].map(e=>e.far));return{placements:u,above:v(-1,15),below:v(1,Math.max(9,d-s+6)+6),tracks:n}}(e,t,a,l,o,i);(!s||r.above+r.below<s.above+s.below)&&(s=r)}return s})(x.filter(e=>e.lane===l&&e.startKey>=t.first&&e.startKey<=t.last),n,d,+!!r.has(l),a));return{row:t,localX:n,breakX:e=>i(e)-o,todayX:d,lanes:c,axisStart:t.start-o,axisEnd:t.end-o}})}}},A=o.length?Math.max(...o.map(e=>i_(e,15,160)))+20:0,P=s.header,V=s.today,H=(e,t,a=h7)=>{var l;let i,s,n,d,c,p,h,g,u,f,m=e.rowsFor(t);if(m.length<t)return;let v=e.layout(m,a),y=(l=e.breaks,i=[],s=[],n=[],d=[],c=(e,t)=>{i.push(e),t.push(e.id)},p=(e,t,a={})=>({type:"line",id:e,points:t,...a}),h=(e,t,a,l,i,s,o={})=>({type:"text",id:e,x:a,y:l,text:t,fontSize:i,maxWidth:200,textColor:s,...o}),g=P?Math.ceil(14*1.35):0,u=18*!!V,f=P?g+18:0,v.forEach((e,t)=>{let a=f,i=void 0!==e.todayX;i&&(f+=u+6);let g=t<v.length-1,m=t>0;if(e.lanes.forEach((a,i)=>{let u=r[i],v=f+a.above,y=`${i}:${t}`,w={strokeColor:u.stroke,strokeWidth:2,roughness:0},x=[...l].toSorted((e,t)=>e-t).filter(t=>t>=e.row.first&&t<=e.row.last).map(t=>({x:A+e.breakX(t),...q(t)})),b=[A+e.axisStart,...x.flatMap(e=>[e.x-e.half,e.x+e.half]),A+e.axisEnd];for(let e=0;e<b.length;e+=2)b[e+1]>b[e]&&c(p(`axis:${y}${e?`:${e/2}`:""}`,[{x:b[e],y:v},{x:b[e+1],y:v}],w),s);for(let t of(x.forEach((e,t)=>{for(let a of[-1,1])c(p(`break:${y}:${t}:${a<0?"a":"b"}`,[{x:e.x+a*e.half-3,y:v+7},{x:e.x+a*e.half+3,y:v-7}],w),d);c(h(`break-label:${y}:${t}`,e.text,e.x,v,13,u.ink),d)}),m&&c(p(`continue-in:${y}`,[{x:A,y:v},{x:A+32,y:v}],{...w,strokeStyle:"dashed"}),s),g&&c(p(`continue-out:${y}`,[{x:A+e.axisEnd,y:v},{x:A+e.axisEnd+32,y:v}],{...w,strokeStyle:"dashed",endArrowhead:"arrow"}),s),o.length&&c(h(`lane:${y}`,o[i],A-16-i_(o[i],15,160)/2,v,15,u.ink,{maxWidth:160,textAlign:"right"}),d),a.placements)){let{item:a}=t,l=`event:${a.event.id}`,i={groupIds:[l]},o=v+16*t.track,r=A+t.stemX;if(a.span){let t=A+e.localX(a.startKey);c({type:"node",id:`node:${l}`,nodeId:l,rendererRole:h6,shape:"rectangle",x:t,y:o-6,width:Math.max(12,A+e.localX(a.endKey)-t),height:12,label:a.event.label,fillColor:u.wash,strokeColor:u.stroke,...i},n)}else{let e="milestone"===a.event.kind,t=e?18:12;c({type:"node",id:`node:${l}`,nodeId:l,rendererRole:h6,shape:e?"diamond":"ellipse",x:r-t/2,y:v-t/2,width:t,height:t,label:a.event.label,fillColor:u.stroke,strokeColor:u.stroke,...i},d)}let g=v+t.side*t.near;c(p(`stem:${l}`,[{x:r,y:v+t.side*t.stemStart},{x:r,y:g}],{strokeColor:"#b9ad95",strokeWidth:1,roughness:0,...i}),s);let f=A+t.left,m=t.side<0?g-a.height:g;for(let e of a.parts){let t=i_(e.text,e.fontSize,200),l=Math.min(Math.max(r,f+t/2),f+a.width-t/2),s=l===r?"center":l<r?"right":"left";c(h(e.id,e.text,l,m+e.height/2,e.fontSize,e.color,{textAlign:s,...i}),d),m+=e.height+2}}f=v+a.below+28*(i<e.lanes.length-1)}),i){let l=A+e.todayX;c(p(`today:${t}`,[{x:l,y:a+u+3},{x:l,y:f}],{strokeColor:ge,strokeWidth:1,strokeStyle:"dashed",roughness:0}),s),c(h(`today-label:${t}`,V,l,a+u/2,13,ge),d)}f+=48}),f-=48,P&&c(h("header",P,i_(P,14,400)/2,g/2,14,h9,{maxWidth:400,textAlign:"left"}),d),{elements:i,zOrder:[...s,...n,...d],height:f}),w=(e=>{let t=1/0,a=-1/0,l=1/0,i=-1/0,s=(e,s,o,r)=>{t=Math.min(t,e),a=Math.max(a,o),l=Math.min(l,s),i=Math.max(i,r)};for(let t of e)if("line"===t.type||"arrow"===t.type)for(let e of t.points)s(e.x,e.y,e.x,e.y);else if("text"===t.type){let e=i_(t.text,t.fontSize,t.maxWidth??200),a=t.text.split("\n").length*t.fontSize*1.35;s(t.x-e/2,t.y-a/2,t.x+e/2,t.y+a/2)}else("node"===t.type||"frame"===t.type)&&s(t.x,t.y,t.x+t.width,t.y+t.height);return{minX:t,maxX:a,minY:l,maxY:i}})(y.elements),x=Math.abs(Math.log((w.maxX-w.minX+80)/(w.maxY-w.minY+80)/2))+.3*(t-1);return{count:t,composed:y,box:w,score:x,labeled:v.flatMap(({lanes:e})=>e).reduce((e,{placements:t})=>e+ +!!t.some(({side:e})=>e<0)+ +!!t.some(({side:e})=>e>0),0)}},I=e=>e.reduce((e,t)=>!e||t.score<e.score-1e-9?t:e,void 0),$=({box:e})=>(e.maxX-e.minX+40)/(e.maxY-e.minY+40),F=({x:e,breaks:t,reachBefore:a})=>C.map((t,l)=>({gap:t,key:l,free:e[l+1]-a[l]})).filter(({gap:e,key:a,free:l})=>e>0&&!t.has(a)&&!z(a)&&l>=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))),E=B(S(new Set)),U=[];for(let e=1;e<=O;e+=1){let t=H(E,e);if(!t)break;U.push(t)}let X=I(U),T=E;if(n&&1===X.count&&$(X)>3.5){let e=new Set,t=X;for(let a=F(T);a&&$(t)>3.5;a=F(T))e.add(a.key),t=H(T=B(S(e)),1);(X=3.5>=$(t)?t:I(U.slice(1))??t)!==t&&(T=E)}if(1===X.count&&$(X)>2.3){let e=Math.floor((140-h7)/6),t=new Map([[0,X]]),a=e=>{let a=t.get(e);if(a)return a;let l=H(T,1,h7+6*e);return t.set(e,l),l},l=e=>2.3>=$(a(e)),i=X.box.maxX-X.box.minX,s=6*X.labeled,o=(i+40)/2.3-40-(({box:e})=>e.maxY-e.minY)(X),r=s>0?Math.min(e,Math.max(1,Math.ceil(o/s))):e;if(l(r))for(;r>1&&l(r-1);)r-=1;else for(;r<e&&!l(r);)r+=1;X=a(r)}let{composed:R,box:Y}=X,D=40-Y.minX,G=40-Y.minY,Z=R.elements.map(e=>{if("line"===e.type||"arrow"===e.type){let[t,...a]=e.points.map(e=>({x:e.x+D,y:e.y+G}));return"line"===e.type?{...e,points:[t,a[0],...a.slice(1)]}:{...e,points:[t,...a]}}return{...e,x:e.x+D,y:e.y+G}});return{kind:"canvas",version:1,diagramId:l.id,title:l.title,width:Math.ceil(Y.maxX-Y.minX+80),height:Math.ceil(Y.maxY-Y.minY+80),accentColor:l.style.accentColor,backgroundColor:l.style.backgroundColor,elements:Z,layers:[],layouts:[],zOrder:R.zOrder}})(bw(p)),catch:e=>new b9({status:"render_failed",context:{...f,issues:[kn({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=i5(m);if(w.length>0)return yield*new b9({status:"render_failed",context:{...f,issues:kz(w).map(e=>({...e,hint:"Split the chronology into smaller timelines and retry buildTimeline."}))}});let x={...f,partial:kZ(m)},b=yield*kW({scene:m,formats:kw(d.options),inlineFormats:kx(d.options),...d.requestId?{requestId:d.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new b9({status:e.status,context:{..."export_failed"===e.status?x:f,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:c,...kG(d.requestId),normalizedSpec:p,quality:u,artifact:b,issues:[]}}),k9=o.fn("codeMode.buildChart.workflow")(function*(e){var t,a;let l,s,r,n,d,c=i.q$Z(nc,{errors:"all",reportInput:!0})(e);if(!xH.oJ(c))return yield*new kt({status:"invalid_input",context:{issues:kf(os(c.failure))}});let p=yield*bm,h=c.success,g=yield*o.OH5(()=>p.createId("build")),u=(l=oe((t=h.spec).title),r=(s=e=>{let t=kv(e);return void 0===t?void 0:t})(t.unit),n=s(t.categoryAxisTitle),d=s(t.valueAxisTitle),{id:kv(t.id)??(km(l)||"sketchi-chart"),title:l,kind:t.kind,categories:t.categories.map(oe),series:t.series.map(e=>{let t=s(e.name);return{...t?{name:t}:{},values:[...e.values]}}),...r?{unit:r}:{},...n?{categoryAxisTitle:n}:{},...d?{valueAxisTitle:d}:{},...void 0!==t.stacked?{stacked:t.stacked}:{},...void 0!==t.donut?{donut:t.donut}:{},...t.orientation?{orientation:t.orientation}:{},style:{...y}}),f={buildId:g,...kG(h.requestId),normalizedSpec:u},m=N(bx(u)).map(e=>kn({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 kt({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 kt({status:"quality_failed",context:{...w,issues:ky(v)}});let x=yield*o.SvU({try:()=>(function(e){let t=J(e),a=new p5(t.style.backgroundColor);if("pie"===t.kind)!function(e,t){let a=t.series[0].values,l=pA(t.unit),i=p3(a.length,!0),{labels:s,shares:o}=function(e){let t=e.reduce((e,t)=>e+t,0),a=e.map(e=>t>0?e/t*100:0),l=e=>a.map(t=>Math.round(t*10**e)/10**e),i=t=>e.some((a,l)=>a>0&&0===t[l]||e.some((e,i)=>i>l&&e!==a&&t[i]===t[l])),s=+!!a.some(e=>e>0&&e<10);for(;s<2&&i(l(s));)s+=1;let o=l(s);return{shares:a,decimals:s,labels:o.map((t,a)=>0===t&&e[a]>0?`<${(10**-s).toFixed(s)}%`:`${Number(t.toFixed(s))}%`)}}(a),r=t.unit?.trim()==="%",n=87*!!t.donut,d=-Math.PI/2,c=a.map((e,t)=>{let a=o[t]/100*2*Math.PI,l={index:t,start:d,end:d+a,mid:d+a/2};return d+=a,l}),p=[];for(let o of c){let d=i[o.index],c=t.categories[o.index],h=pO(a[o.index],l),g=s[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=hl(150,o.start,t?o.end-1e-4:o.end),l=n>0?[...a,...hl(n,t?o.end-1e-4:o.end,o.start)]:t?a:[{x:0,y:0},...a];e.polygon(`chart:slice:${o.index}`,l,`${c}: ${g} (${h})`,{fillColor:d,strokeColor:e.surface,strokeWidth:2,...u})}let m=r&&g===h?g:`${g} \xb7 ${h}`,v=pN(`${iS(c,110,14)}
429
429
  ${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 l=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(l>=2*Math.PI-1e-9)return!0;let s=Math.atan2(e.y,e.x)-t.start;return(s=(s%(2*Math.PI)+2*Math.PI)%(2*Math.PI))<=l&&hi(e,t.start,150)>=6&&hi(e,t.end,150)>=6})}(b,o,n)){e.text(`chart:slice-label:${o.index}`,v,b.left,b.top,14,p2(d),"center",u);continue}let k=pN(`${iS(c,160,14)}
430
430
  ${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(pj)).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),l=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)),s=new Map,o=1/0;for(let e of l){let t=Math.min(e.preferred-e.text.height/2,o-6-e.text.height);s.set(e,t),o=t}let r=l.length?Math.max(...l.map(e=>s.get(e)+e.text.height))+6:-1/0;for(let e of i){let t=Math.max(e.preferred-e.text.height/2,r);s.set(e,t),r=t+e.text.height+6}[...l,...i].forEach(a=>{let l=s.get(a),i=l+a.text.height/2,o=180*t,r=t>0?o:o-a.text.width,n={groupIds:[`chart:slice:${a.slice.index}`]},d={x:152*Math.cos(a.slice.mid),y:152*Math.sin(a.slice.mid)},c={x:164*Math.cos(a.slice.mid),y:164*Math.sin(a.slice.mid)};e.line(`chart:leader:${a.slice.index}:a`,d,c,{strokeColor:pY,...n},"middle"),e.line(`chart:leader:${a.slice.index}:b`,c,{x:o-4*t,y:i},{strokeColor:pY,...n},"middle"),e.text(`chart:slice-label:${a.slice.index}`,a.text,r,l,14,pR,t>0?"left":"right",n)})}}(a,t),p4(a,t,{colors:[]});else if("line"===t.kind)!function(e,t){let a,l=t.categories.length,i=pA(t.unit),s=p3(t.series.length,!1),o=he(t.categories,Math.max(Math.min(720/l,120),36,320/l),2,400),r=t.series.flatMap(e=>e.values),n=1===t.series.length&&l<=16?t.series[0].values.map(e=>pN(pO(e,i),12)):void 0,d=(e,a,i)=>{if(!n)return;let s=t.series[0].values,r=s.map((t,a)=>({x:o*(a+.5),y:e(t)})),d=t.series.flatMap(t=>t.values.slice(1).map((a,l)=>({from:{x:o*(l+.5),y:e(t.values[l])},to:{x:o*(l+1+.5),y:e(a)}})));p.min<0&&p.max>0&&d.push({from:{x:0,y:e(0)},to:{x:o*l,y:e(0)}});let c=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=s[e-1],g=s[e+1],u=s[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)),z=x(0,22+w/2),C=x(-(y/2+10),-(4+w/2)),_=x(y/2+10,-(4+w/2)),q=x(-(y/2+10),4+w/2),L=x(y/2+10,4+w/2),S=(v?[b,C,_,M,k,z]:f&&!m?[C,L,b,k,M,z]:m&&!f?[_,q,b,k,M,z]:[k,q,L,z,b,M]).find(e=>e.top>=a&&e.bottom<=i&&e.left>=0&&e.right<=o*l&&!d.some(t=>(function(e,t){let{from:a,to:l}=e,i=e=>e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom;if(i(a)||i(l))return!0;let s=[{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 s.some((e,t)=>{var i;let o,r,n,d,c;return i=s[(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,l,e),n=o(a,l,i),d=o(e,i,a),c=o(e,i,l),r*n<0&&d*c<0})})(t,{left:e.left-2,top:e.top-2,right:e.right+2,bottom:e.bottom+2}))&&!c.some(t=>pK(t,e,2))&&!h.some(t=>pK(t,e,3)));if(!S)return;h.push(S)}return h},c=pL(r,!1),p=p_(c.low,c.high);for(let e=0;e<3&&n;e+=1){let t=280/(p.max-p.min),l=e=>(p.max-e)*t,i=d(l,-1/0,1/0);if(!i)break;let s=i.some(e=>e.top<0),o=i.some(e=>e.bottom>280);if(!s&&!o){a=i;break}2===e?a=d(l,0,280):p=pq(p,o,s)}let h=a?void 0:t.series.map(e=>e.values.map(e=>pN(pO(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=p8(p,i),m=Math.max(...f.labels.map(e=>e.width)),v=o*l;p.ticks.forEach((t,a)=>{let l=u(t),i=f.labels[a];e.line(`chart:grid:${a}`,{x:0,y:l},{x:v,y:l},{strokeColor:pD}),e.text(`chart:tick:${a}`,i,-8-i.width,l-i.height/2,13,pY,"right")}),p.min<0&&p.max>0&&e.line("chart:baseline",{x:0,y:u(0)},{x:v,y:u(0)},{strokeColor:pG,strokeWidth:2},"middle"),e.line("chart:axis",{x:0,y:280},{x:v,y:280},{strokeColor:pG},"middle");let y=280;if(t.categories.forEach((t,a)=>{let l=o*(a+.5);e.line(`chart:category-tick:${a}`,{x:l,y:280},{x:l,y:285},{strokeColor:pG},"middle");let i=pW(t,o-10,14),s=e.text(`chart:category:${a}`,i,l-i.width/2,289,14,pR);y=Math.max(y,s.bottom)}),t.series.forEach((a,l)=>{let r=s[l],n={groupIds:[`chart:series:${l}`]};a.values.slice(1).forEach((t,i)=>e.line(`chart:line:${l}:${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,s)=>{let d=pO(a,i);p6(e,`chart:point:${s}:${l}`,l,o*(s+.5),u(a),r,`${t.categories[s]} \xb7 ${p7(t,l)}: ${d}`,n)})}),h){let a=y+12,l=t.series.map(e=>e.name?pW(e.name,200,12):void 0),i=-10-Math.max(0,...l.map(e=>e?e.width+6:0));h.forEach((r,n)=>{let d=t.series[n],c=s[n],p={groupIds:[`chart:table:${n}`]},h=l[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:c,strokeWidth:2,...p},"middle"),p6(e,`chart:table-key:${n}`,n,i-11,u,c,d.name??t.title,p),h&&e.text(`chart:table-name:${n}`,h,i+6,a+(g-h.height)/2,12,pR,"left",p),r.forEach((t,l)=>e.text(`chart:table:${l}:${n}`,t,o*(l+.5)-t.width/2,a+(g-t.height)/2,12,pY,"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,pY,"center",{groupIds:["chart:series:0"]})),t.valueAxisTitle){let a=pW(t.valueAxisTitle,Math.max(v+m,200),14),l=f.labels[f.labels.length-1];e.text("chart:value-axis-title",a,-8-m,-l.height/2-8-a.height,14,pY,"left")}if(t.categoryAxisTitle){let a=pW(t.categoryAxisTitle,Math.max(v,200),14);e.text("chart:category-axis-title",a,(v-a.width)/2,y+12,14,pY)}}(a,t),p4(a,t,{legend:"line",colors:p3(t.series.length,!1)});else{let e=p9(t);"horizontal"===function(e){if(e.orientation)return e.orientation;let t=ht(p9(e)),a=he(e.categories,t.band,2,161);return a>160||a*e.categories.length>960?"horizontal":"vertical"}(t)?function(e,t){let{diagram:a,stacked:l,colors:i}=t,s=l?1:a.series.length,o=pN("0",12).height,r=1===s?24:Math.max(o-2,Math.round(44/s)),n=s*r+(s-1)*2,d=Math.min(220,Math.max(...a.categories.map(e=>pN(e,14).width))),c=a.categories.map(e=>pW(e,d,14)),p=l?t.totals.flatMap(e=>[e.up,e.down].filter(e=>void 0!==e)):t.labels.flat(),h=e=>(t,a)=>p.some(l=>"up"===e==l.value>=0&&("up"===e?(t.max-l.value)*a:(l.value-t.min)*a)<l.text.width+4+4),g=ha(t.domain,480,h("up"),h("down"));for(let e=4;e>=2;e-=1){let a=p8(g,t.parts);if(480/(g.max-g.min)*g.step>=Math.max(...a.labels.map(e=>e.width))+12)break;g=ha(t.domain,480,h("up"),h("down"),e)}let u=e=>{let l=480/(e.max-e.min),i=t=>(t-e.min)*l;return a.categories.map((e,l)=>{let s=0,o=0;return a.series.map((e,a)=>{let{value:n,text:d}=t.labels[l][a],c=n>=0?s:o,p=c+n;n>=0?s=p:o=p;let h=i(Math.min(c,p)),g=i(Math.max(c,p));g-h<.5&&(n>=0?g=h+.5:h=g-.5);let u=g-h>=d.width+6&&r>=d.height+1;return{s:a,value:n,text:d,left:h,right:g,inside:u}})})};for(let e=0;l&&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=pq(g,!0,!1)}let f=480/(g.max-g.min),m=e=>(e-g.min)*f,v=u(g),y=l&&v.flat().some(e=>!e.inside)?o+10:0,w=Math.max(n+14,...c.map(e=>e.height+8))+y,x=p8(g,t.parts),b=w*a.categories.length;g.ticks.forEach((t,a)=>{let l=m(t),i=x.labels[a];e.line(`chart:grid:${a}`,{x:l,y:0},{x:l,y:b},{strokeColor:pD}),e.text(`chart:tick:${a}`,i,l-i.width/2,b+6,13,pY)});let k=m(0);e.line("chart:baseline",{x:k,y:0},{x:k,y:b},{strokeColor:pG,strokeWidth:2},"middle"),a.categories.forEach((s,o)=>{let d=w*o+(w-y)/2,p=c[o];e.text(`chart:category:${o}`,p,-10-p.width,d-p.height/2,14,pR,"right");let h=d-n/2;if(a.series.forEach((n,d)=>{let c,p,{value:g,text:u}=t.labels[o][d],f=i[d],y=`chart:bar:${o}:${d}`,w={groupIds:[l?`chart:stack:${o}`:y]},x=l?h:h+d*(r+2);l?{left:c,right:p}=v[o][d]:(c=m(Math.min(0,g)),(p=m(Math.max(0,g)))-c<.5&&(g>=0?p=c+.5:c=p-.5));let b=`${s} \xb7 ${p7(a,d)}: ${u.text}`;if(0!==g&&e.mark(y,"rectangle",{x:c,y:x,width:p-c,height:r},b,l?{fillColor:f,strokeColor:e.surface,strokeWidth:2,...w}:{fillColor:f,strokeColor:f,...w}),l){v[o][d].inside&&e.text(`chart:value:${o}:${d}`,u,(c+p-u.width)/2,x+(r-u.height)/2,12,p2(f),"center",w);return}let k=g>=0?p+4:c-4-u.width;e.text(`chart:value:${o}:${d}`,u,k,x+(r-u.height)/2,12,pY,g>=0?"left":"right",w)}),l){let a=t.totals[o],l={groupIds:[`chart:stack:${o}`]};a.up&&e.text(`chart:total:${o}`,a.up.text,m(a.up.value)+4,d-a.up.text.height/2,12,pR,"left",l),a.down&&e.text(`chart:total-negative:${o}`,a.down.text,m(a.down.value)-4-a.down.text.width,d-a.down.text.height/2,12,pR,"right",l);let i=v[o].filter(e=>!e.inside),s=h+n,r=s+7,c=new Map;for(let e of[!0,!1]){let t=i.filter(t=>t.value>=0===e);pQ(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)=>c.set(t[a],e))}i.forEach(t=>{let a=c.get(t),i=(t.left+t.right)/2,n={strokeColor:pY,...l};e.line(`chart:leader:${o}:${t.s}:a`,{x:i,y:s+1},{x:i,y:s+3},n,"middle"),e.line(`chart:leader:${o}:${t.s}:b`,{x:i,y:s+3},{x:a+t.text.width/2,y:r-1},n,"middle"),e.text(`chart:value:${o}:${t.s}`,t.text,a,r,12,pY,"center",l)})}});let M=x.labels[0].height;if(a.valueAxisTitle){let t=pW(a.valueAxisTitle,480,14);e.text("chart:value-axis-title",t,(480-t.width)/2,b+6+M+10,14,pY)}if(a.categoryAxisTitle){let t=pW(a.categoryAxisTitle,Math.max(d,160),14);e.text("chart:category-axis-title",t,-10-t.width,-8-t.height,14,pY,"right")}}(a,e):function(e,t){let{diagram:a,stacked:l,colors:i}=t,s=a.categories.length,o=ht(t),r="vertical"===a.orientation,n=pN("0",12).height+4+2,d=a.categories.map((e,t)=>t),c=ha(t.domain,300,(e,a)=>d.some(i=>(l?void 0!==t.totals[i].up:t.labels[i].some(e=>e.value>=0))&&(e.max-(l?t.totals[i].up?.value??0:Math.max(0,...t.labels[i].map(e=>e.value))))*a<n),(e,a)=>d.some(i=>(l?void 0!==t.totals[i].down:t.labels[i].some(e=>e.value<0))&&((l?t.totals[i].down?.value??0:Math.min(0,...t.labels[i].map(e=>e.value)))-e.min)*a<n)),p=e=>{let l=300/(e.max-e.min),i=t=>(e.max-t)*l;return a.categories.map((e,l)=>{let s=0,r=0;return a.series.map((e,a)=>{let{value:n,text:d}=t.labels[l][a],c=n>=0?s:r,p=c+n;n>=0?s=p:r=p;let h=i(Math.max(c,p)),g=i(Math.min(c,p));g-h<.5&&(n>=0?h=g-.5:g=h+.5);let u=g-h>=d.height+1&&d.width+6<=o.thickness;return{s:a,value:n,text:d,top:h,bottom:g,inside:u}})})};for(let e=0;l&&e<6;e+=1){let e=p(c),t=c.max/(c.max-c.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))),l=a(!0)>0&&a(!0)>t-2,i=a(!1)>0&&a(!1)>300-t-2;if(!l&&!i)break;c=pq(c,i,l)}let h=300/(c.max-c.min),g=e=>(c.max-e)*h,u=p(c),f=e=>Math.max(o.thickness,t.totals[e].up?.text.width??0,t.totals[e].down?.text.width??0)/2,m=l?Math.max(0,...u.flat().flatMap(e=>e.inside?[]:[e.text.width])):0,v=Math.max(he(a.categories,o.band,r?3:2,r?200:161),320/s,m>0?2*Math.max(...d.map(f))+10+m+6:0),y=p8(c,t.parts),w=Math.max(...y.labels.map(e=>e.width)),x=v*s;c.ticks.forEach((t,a)=>{let l=g(t),i=y.labels[a];e.line(`chart:grid:${a}`,{x:0,y:l},{x:x,y:l},{strokeColor:pD}),e.text(`chart:tick:${a}`,i,-8-i.width,l-i.height/2,13,pY,"right")});let b=g(0);e.line("chart:baseline",{x:0,y:b},{x:x,y:b},{strokeColor:pG,strokeWidth:2},"middle");let k=o.bars*o.thickness+(o.bars-1)*2,M=300;if(a.categories.forEach((s,r)=>{let n=0+v*(r+.5),d=n-k/2,c=pW(s,v-10,14),p=e.text(`chart:category:${r}`,c,n-c.width/2,308,14,pR);if(M=Math.max(M,p.bottom),a.series.forEach((n,c)=>{let p,h,{value:f,text:m}=t.labels[r][c],v=i[c],y=`chart:bar:${r}:${c}`,w={groupIds:[l?`chart:stack:${r}`:y]},x=l?d:d+c*(o.thickness+2);l?{top:p,bottom:h}=u[r][c]:(p=g(Math.max(0,f)),(h=g(Math.min(0,f)))-p<.5&&(f>=0?p=h-.5:h=p+.5));let b=`${s} \xb7 ${p7(a,c)}: ${m.text}`;if(0!==f&&e.mark(y,"rectangle",{x:x,y:p,width:o.thickness,height:h-p},b,l?{fillColor:v,strokeColor:e.surface,strokeWidth:2,...w}:{fillColor:v,strokeColor:v,...w}),l){u[r][c].inside&&e.text(`chart:value:${r}:${c}`,m,x+(o.thickness-m.width)/2,(p+h-m.height)/2,12,p2(v),"center",w);return}let k=f>=0?p-4-m.height:h+4;e.text(`chart:value:${r}:${c}`,m,x+(o.thickness-m.width)/2,k,12,pY,"center",w)}),l){let t=u[r].filter(e=>!e.inside),a=n+f(r)+10,l=new Map;for(let e of[!0,!1]){let a=t.filter(t=>t.value>=0===e);pQ(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)=>l.set(a[t],e))}let i={groupIds:[`chart:stack:${r}`]};t.forEach(t=>{let s=l.get(t),n=(t.top+t.bottom)/2,c={strokeColor:pY,...i};e.line(`chart:leader:${r}:${t.s}:a`,{x:d+o.thickness+1,y:n},{x:a-4,y:n},c,"middle"),e.line(`chart:leader:${r}:${t.s}:b`,{x:a-4,y:n},{x:a-1,y:s+t.text.height/2},c,"middle"),e.text(`chart:value:${r}:${t.s}`,t.text,a,s,12,pY,"left",i)})}if(l){let a=t.totals[r],l={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,pR,"center",l),a.down&&e.text(`chart:total-negative:${r}`,a.down.text,n-a.down.text.width/2,g(a.down.value)+4,12,pR,"center",l)}}),a.valueAxisTitle){let t=pW(a.valueAxisTitle,Math.max(x+w,200),14),l=y.labels[y.labels.length-1];e.text("chart:value-axis-title",t,-8-w,-l.height/2-8-t.height,14,pY,"left")}if(a.categoryAxisTitle){let t=pW(a.categoryAxisTitle,Math.max(x,200),14);e.text("chart:category-axis-title",t,(0+x-t.width)/2,M+12,14,pY)}}(a,e),p4(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 l=a.bounds(),i=40-l.left,s=40-l.top,o=a.elements.map(e=>{if("line"===e.type){let[t,a,...l]=e.points.map(e=>({x:pJ(e.x+i),y:pJ(e.y+s)}));return{...e,points:[t,a,...l]}}return"arrow"===e.type?e:{...e,x:pJ(e.x+i),y:pJ(e.y+s)}});return{kind:"canvas",version:1,diagramId:t.id,title:t.title,width:Math.ceil(l.right-l.left+80),height:Math.ceil(l.bottom-l.top+80),accentColor:t.style.accentColor,backgroundColor:t.style.backgroundColor,elements:o,layers:[],layouts:[],zOrder:a.zOrder()}})(bx(u)),catch:e=>new kt({status:"render_failed",context:{...w,issues:[kn({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=i5(x);if(b.length>0)return yield*new kt({status:"render_failed",context:{...w,issues:kz(b).map(e=>({...e,hint:"Use fewer categories or series and retry buildChart."}))}});let k={...w,partial:kZ(x)},M=yield*kW({scene:x,formats:kw(h.options),inlineFormats:kx(h.options),...h.requestId?{requestId:h.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new kt({status:e.status,context:{..."export_failed"===e.status?k:w,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:g,...kG(h.requestId),normalizedSpec:u,quality:v,artifact:M,issues:[]}}),Me=o.fn("codeMode.buildGantt.workflow")(function*(e){var t,a,l;let s,r,n=i.q$Z(ng,{errors:"all",reportInput:!0})(e);if(!xH.oJ(n))return yield*new ka({status:"invalid_input",context:{issues:kf(os(n.failure))}});let d=yield*bm,c=n.success,p=yield*o.OH5(()=>d.createId("build")),h=(s=oe((t=c.spec).title),{id:kv(t.id)??(km(s)||"sketchi-gantt"),title:s,tasks:t.tasks.map(e=>{let t=kv(e.phase);return{...e,id:oe(e.id),label:oe(e.label),start:oe(e.start),...void 0!==e.end?{end:oe(e.end)}:{},...void 0!==t?{phase:t}:{},...e.dependsOn?{dependsOn:e.dependsOn.map(oe)}:{}}}),...t.phases?{phases:t.phases.map(oe)}:{},...t.today?{today:oe(t.today)}:{},style:{...y}}),g={buildId:p,...kG(c.requestId),normalizedSpec:h},u=tu(bb(h)).map(e=>kn({code:bk[e.code],stage:"input",ref:{kind:"request",path:`spec.${e.path}`},message:e.message,hint:e.hint}));if(u.length>0)return yield*new ka({status:"invalid_gantt",context:{...g,issues:u}});let f={accepted:10>=(a=c.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 ka({status:"quality_failed",context:{...m,issues:ky(f)}});let v=yield*o.SvU({try:()=>(function(e){var t,a,l;let i=tm(e),s=[h4(i,44,h2)],o=s[0],r=h2;if(!(0===(t=o).crossings&&Object.values(t.findings).every(e=>0===e))){let e,t,n=h4(i,44,h3),d=h3;s.push(n),n.clear||(n=h4(i,44,h5),d=h5,s.push(n)),n.clear&&(a=o,l=n,e=Object.keys(a.findings),t=t=>e.reduce((e,a)=>e+t[a],0),!(a.crossings<=l.crossings&&t(a.findings)<=t(l.findings)&&e.every(e=>a.findings[e]<=l.findings[e]+1)))&&(o=n,r=d)}for(let e of h$){if(0===o.work.conflicts||o.work.conflicts>4)break;let t=h4(i,44+e,r);s.push(t),t.work.conflicts<o.work.conflicts&&(o=t)}return{scene:o.scene,work:{layouts:s.length,placements:s.reduce((e,{work:t})=>e+t.placements,0),expansions:s.reduce((e,{work:t})=>e+t.expansions,0),corridors:o.work.corridors,conflicts:o.work.conflicts}}})(bb(h)).scene,catch:e=>new ka({status:"render_failed",context:{...m,issues:[kn({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=i5(v);if(w.length>0)return yield*new ka({status:"render_failed",context:{...m,issues:kz(w).map(e=>({...e,hint:"Use fewer tasks or dependencies and retry buildGantt."}))}});let x={...m,partial:kZ(v)},b=yield*kW({scene:v,formats:kw(c.options),inlineFormats:kx(c.options),...c.requestId?{requestId:c.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new ka({status:e.status,context:{..."export_failed"===e.status?x:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:p,...kG(c.requestId),normalizedSpec:h,quality:f,artifact:b,issues:(r=new Map((l=bb(h)).tasks.map(e=>[e.id,e])),l.tasks.flatMap((e,t)=>{let a=tc(e);return(e.dependsOn??[]).flatMap((l,i)=>{let s=r.get(l),o=s&&tc(s);if(!a||!o)return[];let n=o.milestone?o.start:o.end-!!a.milestone;return a.start>=n?[]:[{task:e.id,dependsOn:l,finishes:tn(o.milestone?o.start:o.end-1),path:`tasks.[${t}].dependsOn.[${i}]`}]})})).map(e=>kn({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}.`}))}}),Mt=i._kM({spec:i.$r1,requestId:i.Qrq(i.$r1)}),Ma=i._kM({source:i._kM({scene:i.$r1})}),Ml=o.fn("codeMode.canvas.serializedLimit")((e,t)=>o.SvU(()=>cE(e)).pipe(o.YWq({onFailure:()=>kn({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<=iB.maxSerializedBytes?void 0:kn({code:"canvas_limit_exceeded",stage:"canvas",ref:{kind:"request",path:t},message:`CanvasSpec exceeds ${iB.maxSerializedBytes} serialized bytes.`,hint:"Split the visualization into a smaller canvas or reduce repeated text and points."})}))),Mi=o.fn("codeMode.createCanvas.workflow")(function*(e){let t=yield*bm,a=yield*o.OH5(()=>t.createId("build")),l=i.q$Z(Mt)(e),s=xH.oJ(l)?{spec:l.success.spec,requestId:i.is(i.QfV)(l.success.requestId)?l.success.requestId:void 0}:void 0;if(s){let e=yield*Ml(s.spec,"spec");if(e)return yield*new kl({status:"canvas_limit_exceeded"===e.code?"limit_exceeded":"invalid_input",context:{buildId:a,...kG(s.requestId),issues:[e]}})}let r=i.q$Z(da,{errors:"all",reportInput:!0})(e);if(!xH.oJ(r))return yield*new kl({status:"invalid_input",context:{issues:kf(os(r.failure))}});let n=r.success,d={buildId:a,...kG(n.requestId)},c=k_(n.spec);if(!c)return yield*new kl({status:"invalid_canvas",context:{...d,issues:[kn({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=i5(c).filter(e=>"limit_exceeded"===e.code);if(p.length>0)return yield*new kl({status:"limit_exceeded",context:{...d,issues:kz(p)}});let h=yield*be(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=i6(e,t.ids),l=a[0];if(!l)return[...e];let i=i4(l),s=t.x??i.x,o=t.y??i.y,r="stack"===t.type?t.gap??0:t.gap??32,n=new Map,d="column"===t.type?o:s;for(let e of a){let a=i4(e);n.set(e.id,{x:"column"===t.type||"stack"===t.type?s:d,y:"column"===t.type?d:o}),"stack"!==t.type&&(d+=("column"===t.type?a.height:a.width)+r)}return i7(e,n)}(e,t);case"grid":return function(e,t){let a=i6(e,t.ids);if(0===a.length)return[...e];let l=Math.max(1,Math.floor(t.columns)),i=a.map(i4),s=Array.from({length:l},(e,t)=>Math.max(0,...i.filter((e,a)=>a%l===t).map(e=>e.width))),o=Array.from({length:Math.ceil(a.length/l)},(e,t)=>Math.max(0,...i.filter((e,a)=>Math.floor(a/l)===t).map(e=>e.height))),r=i[0];if(!r)return[...e];let n=t.x??r.x,d=t.y??r.y,c=t.columnGap??32,p=t.rowGap??32,h=new Map;return a.forEach((e,t)=>{let a=t%l,i=Math.floor(t/l);h.set(e.id,{x:n+s.slice(0,a).reduce((e,t)=>e+t,0)+c*a,y:d+o.slice(0,i).reduce((e,t)=>e+t,0)+p*i})}),i7(e,h)}(e,t);case"align":return function(e,t){let a=i6(e,t.ids);if(0===a.length)return[...e];let l=a.map(i4),i=l.map(e=>i8(e,t.axis)),s=l.map(e=>i8(e,t.axis)+i9(e,t.axis)),o=l.map(e=>i8(e,t.axis)+i9(e,t.axis)/2),r="start"===t.alignment?Math.min(...i):"end"===t.alignment?Math.max(...s):o.reduce((e,t)=>e+t,0)/o.length,n=new Map;return a.forEach((e,a)=>{let i=l[a];if(!i)return;let s="start"===t.alignment?r:"end"===t.alignment?r-i9(i,t.axis):r-i9(i,t.axis)/2;n.set(e.id,{x:"x"===t.axis?s:i.x,y:"y"===t.axis?s:i.y})}),i7(e,n)}(e,t);case"distribute":return function(e,t){let a=i6(e,t.ids).sort((e,a)=>i8(i4(e),t.axis)-i8(i4(a),t.axis));if(a.length<2)return[...e];let l=a.map(i4),i=l[0],s=l[l.length-1];if(!i||!s)return[...e];let o=i8(i,t.axis),r=i8(s,t.axis)+i9(s,t.axis),n=l.reduce((e,a)=>e+i9(a,t.axis),0),d=t.gap??Math.max(0,(r-o-n)/(a.length-1)),c=new Map,p=o;return a.forEach((e,a)=>{let i=l[a];i&&(c.set(e.id,{x:"x"===t.axis?p:i.x,y:"y"===t.axis?p:i.y}),p+=i9(i,t.axis)+d)}),i7(e,c)}(e,t)}}(t,a);let a=function(e){let t=1,a=1;for(let l of e)if(iN(l)){let e=i4(l);t=Math.max(t,e.x+e.width),a=Math.max(a,e.y+e.height)}else if("arrow"===l.type||"line"===l.type)for(let e of l.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=si(e),a=new Map;for(let t of e)("node"===t.type||"frame"===t.type)&&a.set(t.id,t);let l=e.map(e=>{if("arrow"===e.type){let a=t.get(e.sourceNodeId),l=t.get(e.targetNodeId);if(!a||!l)return e;if(e.curved){let t=e.points[0],i=e.points[e.points.length-1]??t;return sa(t,a)&&sa(i,l)?e:{...e,points:sl(a,l)}}return{...e,points:[st(a,se(l)),...e.points.slice(1,-1),st(l,se(a))]}}if("line"===e.type){let t=e.startBinding?a.get(e.startBinding.elementId):void 0,l=e.endBinding?a.get(e.endBinding.elementId):void 0;if(!t&&!l)return e;let i=[e.points[0],e.points[1],...e.points.slice(2)];return t&&(i[0]=st(t,l?se(l):i[i.length-1]??i[0])),l&&(i[i.length-1]=st(l,t?se(t):i[0])),{...e,points:i}}return e}),i=new Map(l.map(e=>[e.id,e]));return l.map(e=>{if("text"!==e.type||!e.containerId)return e;let t=i.get(e.containerId);if(t?.type==="node"){let a=se(t);return{...e,x:a.x,y:a.y}}if(t?.type==="arrow"){let a=t.points[0],l=t.points[t.points.length-1]??a;return{...e,x:(a.x+l.x)/2,y:(a.y+l.y)/2}}return e})}(t)),l=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:l}}(c),t.icons),g=h.scene,u=kq(g),f=i5(g);if(f.length>0){let e=kz(f);return yield*new kl({status:e.some(e=>"canvas_limit_exceeded"===e.code)?"limit_exceeded":"invalid_canvas",context:{...d,normalizedSpec:u,issues:[...h.issues,...e]}})}let m={...d,normalizedSpec:u,partial:kZ(g)},v=yield*kW({scene:g,formats:kw(n.options),inlineFormats:kx(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:kC}).pipe(o.xm_(e=>new kl({status:e.status,context:{...m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:a,...kG(n.requestId),normalizedSpec:u,artifact:v,issues:h.issues}}),Ms=o.fn("codeMode.buildFlowchart.workflow")(function*(e){var t,a;let l,s=i.q$Z(nr,{errors:"all",reportInput:!0})(function(e){if(!bn(e))return e;let{spec:t}=e;if(!bn(t)||!Array.isArray(t.nodes))return e;let a=t.nodes,l=!1,i=Array.isArray(t.edges)?t.edges:void 0,s=i?.map(e=>{if(!bn(e)||void 0!==e.source&&void 0!==e.target||void 0===e.from&&void 0===e.to)return e;l=!0;let{from:t,to:a,...i}=e;return{...i,source:e.source??t,target:e.target??a}}),o=(s??[]).filter(bn),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 d=a.filter(bn).filter(e=>0===n(e.id).incoming),c=a.map(e=>bn(e)?(e=>{let t=e.kind??e.type,{incoming:a,outgoing:l,labeledOutgoing:i}=n(e.id),s="string"==typeof e.label&&oe(e.label).endsWith("?");if("string"==typeof t){let i=bd(t),s=bs[i];if(s)return s;if(bo.has(i)){if(0===a&&l>0)return"start";if(0===l&&a>0)return"end"}return e.kind}return void 0!==t?e.kind:0===l&&a>0?"end":0===a&&1===d.length&&0===i?"start":a>0&&1===l&&0===i&&!s?"process":void 0})(e):void 0),p=a.some((e,t)=>bn(e)&&"end"===c[t]&&n(e.id).incoming>0&&0===n(e.id).outgoing),h=e=>"string"==typeof e.shape&&br.has(bd(e.shape)),g=(e,t)=>"process"===t&&h(e)&&n(e.id).incoming>0&&0===n(e.id).outgoing,u=p||a.some((e,t)=>bn(e)&&g(e,c[t])),f=new Set(a.flatMap((e,t)=>bn(e)&&"decision"===c[t]?[e.id]:[])),m=new Set(o.filter(e=>f.has(e.source)&&"string"==typeof e.label&&""!==e.label.trim()).map(e=>e.target)),v=a.map((e,t)=>{if(!bn(e))return e;let a=c[t],i="string"==typeof e.label&&oe(e.label).endsWith("?");"process"===a&&p&&m.has(e.id)&&0===n(e.id).outgoing&&!i&&(a="end");let{incoming:s,outgoing:o}=n(e.id);if(g(e,a)?a="end":"end"===a&&u&&h(e)&&s>0&&o>0&&(a="process"),a===e.kind)return e;l=!0;let{type:r,...d}=e;return{...d,kind:a}});return l?{...e,spec:{...t,nodes:v,...s?{edges:s}:{}}}:e}(e));if(!xH.oJ(s))return yield*new bK({status:"invalid_input",context:{issues:kf(os(s.failure),ku)}});let r=yield*bm,n=s.success,d=yield*o.OH5(()=>r.createId("build")),c=(l=oe((t=n.spec).title),{id:bi(t.id)??(l.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"sketchi-flowchart"),title:l,nodes:t.nodes.map(e=>({id:oe(e.id),label:oe(e.label),kind:e.kind,...e.description?{description:oe(e.description)}:{},...e.icon?{icon:{slug:oe(e.icon.slug)}}:{},...e.group?{group:oe(e.group)}:{},...e.lane?{lane:oe(e.lane)}:{},...e.shape?{shape:e.shape}:{}})),edges:t.edges.map((e,t)=>({id:bi(e.id)??`edge-${t+1}`,source:oe(e.source),target:oe(e.target),...e.label?{label:oe(e.label)}:{}})),...t.groups?{groups:t.groups.map(e=>({id:oe(e.id),label:oe(e.label),...e.parent?{parent:oe(e.parent)}:{},...e.kind?{kind:e.kind}:{}}))}:{},...t.lanes?{lanes:t.lanes.map(e=>({id:oe(e.id),label:oe(e.label)}))}:{},layout:{direction:t.layout.direction},style:{...y}}),p=x9(c.nodes,r.icons,void 0,{fillNamedLogos:!0===r.fillNamedLogos}),h=function(e,t,a,l={}){let i=new Map,s=[];if(!e?.length||!l.fillNamedLogos||!a||!t.some(e=>e.icon))return{issues:s,logos:i};let o=new Map(e.flatMap(e=>void 0===e.parent?[]:[[e.id,e.parent]])),r=e=>{let t=[];for(let a=e;void 0!==a&&!t.includes(a);a=o.get(a))t.push(a);return t},n=new Map;for(let e of t)for(let t of r(e.group)){let a=n.get(t)??new Set;e.icon&&a.add(e.icon.slug),n.set(t,a)}for(let t of[...e].sort((e,t)=>r(e.id).length-r(t.id).length)){let e=n.get(t.id);if(!e)continue;let l=a.logoNamedByLabel(t.label);!(!l||e.has(l.slug))&&(r(t.parent).some(e=>i.get(e)===l.slug)||(i.set(t.id,l.slug),s.push({code:"icon_filled",severity:"info",stage:"input",ref:{kind:"group",id:t.id},message:`Group "${t.id}" draws the "${l.slug}" logo because its label "${t.label}" names ${l.name}.`,hint:"No action needed."})))}return{issues:s,logos:i}}(c.groups,p.nodes,r.icons,{fillNamedLogos:!0===r.fillNamedLogos}),g={...c,nodes:p.nodes},u={buildId:d,...kG(n.requestId),normalizedSpec:g},f=i.q$Z(ew,{errors:"all",reportInput:!0})(function(e,t=new Map){return{id:e.id,title:e.title,type:"flowchart",nodes:e.nodes.map(e=>({...e,metadata:{}})),edges:e.edges.map(e=>({...e,metadata:{}})),...e.groups?{groups:e.groups.map(e=>{var a;let l;return{...e,...(a=e.id,(l=t.get(a))?{icon:{slug:l}}:{})}})}:{},...e.lanes?{lanes:e.lanes.map(e=>({...e}))}:{},layout:{direction:e.layout.direction,edgeRouting:"orthogonal"},style:e.style,metadata:{}}}(g,h.logos));if(!xH.oJ(f)){return yield*new bK({status:"invalid_flowchart",context:{...u,issues:(a=os(f.failure),a.issues.slice(0,20).map(e=>{let t=function(e,t){let a=kd(e.path),l="input"===a?"spec":`spec.${a}`,[i,s]=e.path;if("nodes"===i&&"number"==typeof s){let e=t.nodes[s]?.id;return{kind:"node",...e?{id:e}:{},path:l}}if("edges"===i&&"number"==typeof s){let e=t.edges[s]?.id;return{kind:"edge",...e?{id:e}:{},path:l}}if("groups"===i&&"number"==typeof s){let e=t.groups?.[s]?.id;return{kind:"group",...e?{id:e}:{},path:l}}if("lanes"===i&&"number"==typeof s){let e=t.lanes?.[s]?.id;return{kind:"lane",...e?{id:e}:{},path:l}}return{kind:"diagram",id:t.id,path:l}}(e,g);return kn({code:kc(e),stage:"flowchart",ref:t,message:e.message,hint:`Fix ${t.path??"spec"} so normalization produces a valid canonical flowchart value.`})}))}})}let m=f.success,v=ek(m).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 kn({code:e.code,stage:"flowchart",...t?{ref:t}:{},message:e.message,hint:e.hint})});if(v.length>0)return yield*new bK({status:"invalid_flowchart",context:{...u,issues:v}});ez(m);let w=function(e,t){let a=[],l=0,i=(e,t,i,s=!1)=>{l+=e,a.push({...i,passed:!1,severity:s?"error":"warning",message:t})},s=new Map,o=new Map;for(let t of e.edges)s.set(t.source,(s.get(t.source)??0)+1),s.set(t.target,(s.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:bl(e.nodes)},!0);else{let t=e.nodes.filter(e=>(s.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:bl(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,l=0;for(let i of e.nodes){if(a.has(i.id))continue;l+=1;let e=[i.id];for(a.add(i.id);e.length>0;){let l=e.pop();if(void 0===l)break;for(let i of t.get(l)??[])a.has(i)||(a.add(i),e.push(i))}}return l}(e);a>1&&0===t.length&&i(2,`diagram splits into ${a} disconnected islands`,{code:"disconnected_graph",refs:bl(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:bl(e.nodes.filter(e=>(r.get(e.label.trim().toLowerCase())??0)>1))});let d=0,c=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:bl([t])});continue}let e=o.get(t.id)??[];e.length<2?(d+=1,i(0,`decision "${t.id}" needs at least 2 outgoing branches`,{code:"underbranched_decision",refs:bl([t])},!0)):e.some(e=>!e.label)&&(c+=1,i(0,`label every branch out of decision "${t.id}" (yes/no, …)`,{code:"unlabeled_decision_branch",refs:bl([t])}))}l+=Math.min(1.5*d,4.5)+Math.min(c,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:bl(p)});let h=e.nodes.filter(e=>bt.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:bl(h)}),(e.title.trim().length<4||ba.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-l)*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}}(m,n.options?.minQualityScore??8),x={...u,quality:w};if(!w.accepted)return yield*new bK({status:"quality_failed",context:{...x,issues:ky(w)}});let b=yield*o.SvU({try:()=>mc(U(m)),catch:e=>new bK({status:"render_failed",context:{...x,issues:[kn({code:"render_failed",stage:"render",ref:{kind:"diagram",id:g.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")),k=yield*be(b,r.icons),M=k.scene,z={...x,partial:kZ(M)},C=yield*kW({scene:M,formats:kw(n.options),inlineFormats:kx(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:kM}).pipe(o.xm_(e=>new bK({status:e.status,context:{..."export_failed"===e.status?z:x,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:d,...kG(n.requestId),normalizedSpec:g,quality:w,artifact:C,issues:[...p.issues,...h.issues,...k.issues,...M.elements.flatMap(e=>"text"===e.type&&e.id.startsWith("description:")&&e.text.split("\n").length>3?[e.id.slice(12)]:[]).map(e=>kn({code:"label_too_long",severity:"warning",stage:"render",ref:{kind:"node",id:e,path:"spec.nodes.description"},message:`Node "${e}" has a description longer than 3 lines; it draws in full under the label.`,hint:"Keep a description to a short subtitle, and name technologies in the label."}))]}}),Mo=o.fn("codeMode.getArtifact.workflow")(function*(e){let t=i.q$Z(dn,{errors:"all",reportInput:!0})(e);if(!xH.oJ(t))return yield*new ki({status:"invalid_input",context:{issues:kf(os(t.failure))}});let a=yield*bm,l=yield*cI,s=t.success,r=yield*l.readManifest(s.artifactId).pipe(o.xm_(e=>new ki({status:"storage_failed",context:{issues:[kN(e,"storage_read_failed")]}})));if(!r)return yield*new ki({status:"not_found",context:{issues:[kn({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:s.artifactId},message:`Artifact "${s.artifactId}" was not found.`,hint:"Use the artifactId returned by buildFlowchart or applyDiagramPatch."})]}});let n=s.format??"scene";if(!r.formats.some(e=>e.format===n))return yield*new ki({status:"format_unavailable",context:{issues:[kn({code:"unsupported_artifact_format",stage:"storage",ref:{kind:"artifact",id:s.artifactId},message:`Artifact "${s.artifactId}" does not include format "${n}".`,hint:"Request a format listed in the artifact bundle."})]}});let d=yield*l.read(s.artifactId,n).pipe(o.xm_(e=>new ki({status:"storage_failed",context:{issues:[kN(e,"storage_read_failed")]}})));return d?{ok:!0,artifactId:s.artifactId,diagramId:r.diagramId,format:n,mimeType:d.mimeType,...a.artifactUrl?{url:a.artifactUrl({artifactId:s.artifactId,format:n})}:{},...!0!==s.inline||!cF(n)?{}:{inline:d.data},sizeBytes:d.sizeBytes,...r.provenance?{provenance:r.provenance}:{}}:yield*new ki({status:"format_unavailable",context:{issues:[kn({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:s.artifactId},message:`Artifact "${s.artifactId}" format "${n}" could not be read.`,hint:"Retry retrieval or rebuild the artifact."})]}})}),Mr=o.fn("codeMode.applyDiagramPatch.workflow")(function*(e){let t,a=i.q$Z(Ma)(e),l=xH.oJ(a)?yield*Ml(a.success.source.scene,"source.scene"):void 0;if(l)return yield*new ko({status:"invalid_input",context:{issues:[l]}});let s=i.q$Z(dA,{errors:"all",reportInput:!0})(e);if(!xH.oJ(s))return yield*new ko({status:"invalid_input",context:{issues:kf(os(s.failure))}});let r=yield*bm,n=s.success,d=yield*o.OH5(()=>r.createId("patch")),c={patchId:d,...kG(n.requestId)},p=yield*kD(n).pipe(o.xm_(e=>new ko({status:e.status,context:{...c,...e.context}}))),h={...c,...p.sourceArtifactId?{sourceArtifactId:p.sourceArtifactId}:{}},g=p.scene;if(g.elements.length>iB.maxElements)t=[{code:"limit_exceeded",message:`Canvas exceeds ${iB.maxElements} elements.`,path:"elements"}];else{let e=k_(g);t=e?i5(e).filter(e=>"limit_exceeded"===e.code):[]}if(t.length>0)return yield*new ko({status:"invalid_input",context:{...h,issues:kz(t)}});let u=kS(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),kB(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 kP(e))t.style.strokeColor&&(a.strokeColor=t.style.strokeColor),t.style.textColor&&(a.textColor=t.style.textColor);for(let a of kA(e))t.style.textColor&&(a.textColor=t.style.textColor);return[]}let a=kH(e,t.selector);if(0===a.nodes.length&&0===a.arrows.length&&0===a.texts.length)return[kI(t)];for(let l of a.nodes)if(t.style.fillColor&&(l.fillColor=t.style.fillColor),t.style.strokeColor&&(l.strokeColor=t.style.strokeColor),t.style.textColor){l.textColor=t.style.textColor;let a=k$(e,l.id);a&&(a.textColor=t.style.textColor)}for(let l of a.arrows)if(t.style.strokeColor&&(l.strokeColor=t.style.strokeColor),t.style.textColor){l.textColor=t.style.textColor;let a=k$(e,l.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 l=kH(e,t.selector);if(0===l.nodes.length)return[kI(t)];let i=[];for(let a of l.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=k$(e,t.id);a&&(a.x=t.x+t.width/2,a.y=t.y+t.height/2)}(e,a)}return kO(e,i),[];case"translate":return function(e,t){let a=kH(e,t.selector);if(0===a.nodes.length&&0===a.arrows.length&&0===a.texts.length)return[kI(t)];let l=new Set,i=new Set;for(let s of a.nodes){s.x+=t.dx,s.y+=t.dy,l.add(s.nodeId);let a=k$(e,s.id);a&&(a.x+=t.dx,a.y+=t.dy,i.add(a.id))}for(let l of a.arrows){l.points=l.points.map(e=>{var a,l;return a=t.dx,l=t.dy,{x:e.x+a,y:e.y+l}});let a=k$(e,l.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 kO(e,[...l]),kT(e),[]}(e,t);case"replaceText":let s=kH(e,t.selector);if(0===s.nodes.length&&0===s.arrows.length&&0===s.texts.length)return[kI(t)];for(let a of s.nodes){a.label=t.text;let l=k$(e,a.id);l&&(l.text=t.text)}for(let a of s.arrows){a.label=t.text;let l=k$(e,a.id);l&&(l.text=t.text)}for(let e of s.texts)e.text=t.text;return[];case"rerouteEdges":let o;return 0===(o=kH(e,t.selector)).arrows.length?[kI(t)]:o.arrows.flatMap(t=>kX(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 kY(t,"Inserted elements must use ids that are unique within the canvas.");let d=kR(e.zOrder,t.beforeId,t.afterId);return void 0===d?kY(t,"Insert specifies an unknown anchor or both beforeId and afterId."):(e.elements.push(...t.elements.map(e=>structuredClone(e))),e.zOrder.splice(d,0,...n),[]);case"remove":return function(e,t){let a,l=function(e,t){let a=kH(e,t),l=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)&&l.add(t.id);return l}(e,t.selector);if(0===l.size)return[kI(t)];let i=new Set(e.elements.flatMap(e=>"node"===e.type&&l.has(e.id)?[e.nodeId]:[]));do for(let t of(a=l.size,e.elements))("text"===t.type&&(t.containerId&&l.has(t.containerId)||kP(e).some(a=>l.has(a.id)&&k$(e,a.id)?.id===t.id))||"arrow"===t.type&&(i.has(t.sourceNodeId)||i.has(t.targetNodeId))||"line"===t.type&&(t.startBinding&&l.has(t.startBinding.elementId)||t.endBinding&&l.has(t.endBinding.elementId)))&&l.add(t.id);while(l.size!==a)let s=e.elements.filter(e=>!l.has(e.id)).map(e=>{if(e.frameId&&l.has(e.frameId)){let{frameId:t,...a}=e;return a}return e});e.elements.splice(0,e.elements.length,...s);let o=e.zOrder.filter(e=>!l.has(e));e.zOrder.splice(0,e.zOrder.length,...o);let r=e.layouts.map(e=>({...e,ids:e.ids.filter(e=>!l.has(e))})).filter(e=>e.ids.length>0);return e.layouts.splice(0,e.layouts.length,...r),kT(e),[]}(e,t);case"replace":let c;return(c=e.elements.findIndex(e=>e.id===t.id))<0?[kI(t)]:t.element.id!==t.id?kY(t,"Replacement element id must match the stable id being replaced."):(e.elements.splice(c,1,structuredClone(t.element)),kT(e),[]);case"reorder":let p=new Set(t.ids);if(p.size!==t.ids.length||t.ids.some(t=>!e.zOrder.includes(t)))return kY(t,"Reorder ids must be unique ids already present in zOrder.");let h=e.zOrder.filter(e=>!p.has(e)),g=kR(h,t.beforeId,t.afterId);return void 0===g?kY(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[kI(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 ko({status:f[0]?.code==="unknown_patch_target"?"target_not_found":"unsupported_operation",context:{...h,issues:f}});if(n.options?.preserveConnectivity!==!1){let e=kS(g);if(!(u.length===e.length&&u.every((t,a)=>t===e[a])))return yield*new ko({status:"connectivity_changed",context:{...h,issues:[kn({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=k_(g);if(!m)return yield*new ko({status:"render_failed",context:{...h,issues:[kn({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*be(m,r.icons),y=v.scene,w=i5(y);if(w.length>0)return yield*new ko({status:"render_failed",context:{...h,partial:kZ(y),issues:[...v.issues,...kz(w)]}});let x={...h,partial:kZ(y)},b=yield*kW({scene:y,formats:kw(n.options),inlineFormats:kx(n.options),...n.requestId?{requestId:n.requestId}:{},validationIssues:kC,...p.sourceArtifactId?{provenance:{sourceArtifactId:p.sourceArtifactId}}:{}}).pipe(o.xm_(e=>new ko({status:e.status,context:{..."export_failed"===e.status?x:h,issues:e.issues}})));return{ok:!0,status:"accepted",patchId:d,...kG(n.requestId),...p.sourceArtifactId?{sourceArtifactId:p.sourceArtifactId}:{},artifact:b,issues:v.issues}}),Mn=o.fn("codeMode.searchIcons.workflow")(function*(e){let t=i.q$Z(cS,{errors:"all",reportInput:!0})(e);if(!xH.oJ(t))return yield*new ks({status:"invalid_input",context:{issues:kf(os(t.failure))}});let a=yield*bm,l=oe(t.success.q),s=a.icons?.search(l,t.success.limit??10)??[];return{ok:!0,status:"accepted",query:l,icons:s.map(({collection:e,match:t,name:a,slug:l})=>({collection:e,name:a,slug:l,match:t})),issues:a.icons?[]:[kn({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 Md(e,t,a){return o.fn(`codeMode.${e}`)(l=>{var i,s,n;let d,c,p,h;return i=e,s=l,n=t(l).pipe(o.YWq({onFailure:a,onSuccess:e=>e})),xP(o.JkU(function*(){let e=yield*r.Ru,t=yield*n,a=yield*r.Ru,l=t.ok?"success":"failure",s=t.ok?void 0:t.status??"unknown_failure";yield*xV(bh,1,{...s?{failureCategory:s}:{},operation:i,outcome:l,surface:"code_mode"}),yield*xV(bf,a-e,{...s?{failureCategory:s}:{},operation:i,outcome:l,surface:"code_mode"}),s&&(yield*xV(bg,1,{failureCategory:s,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":"buildVennDiagram"===i?"venn":"buildJourneyMap"===i?"journey":"buildSankey"===i?"sankey":"buildWireframe"===i?"wireframe":"buildQuadrantChart"===i?"quadrant":"createCanvas"===i?"canvas":"applyDiagramPatch"===i?"patch":void 0;return t.ok&&o&&(yield*xV(bu,1,{artifactKind:o,operation:i,surface:"code_mode"})),t}),(d=by(s),c=by(d?.source),p="string"==typeof d?.artifactId?d.artifactId:"string"==typeof c?.artifactId?c.artifactId:void 0,h="string"==typeof d?.requestId?d.requestId:void 0,{...p?{artifactId:p}:{},...h?{requestId:h}:{}}))})}let Mc=Md("buildFlowchart",Ms,kj),Mp=Md("buildMindmap",kJ,kj),Mh=Md("buildSequenceDiagram",kK,kj),Mg=Md("buildStateMachine",kQ,kj),Mu=Md("buildErDiagram",k1,kj),Mf=Md("buildClassDiagram",k0,kj),Mm=Md("buildOrgChart",k2,kj),Mv=Md("buildVennDiagram",k3,kj),My=Md("buildJourneyMap",k5,kj),Mw=Md("buildSankey",k4,kj),Mx=Md("buildWireframe",k6,kj),Mb=Md("buildQuadrantChart",k7,kj),Mk=Md("buildTimeline",k8,kj),MM=Md("buildChart",k9,kj),Mz=Md("buildGantt",Me,kj);Md("createCanvas",Mi,kj),Md("getArtifact",Mo,kj),Md("searchIcons",Mn,kj);let MC=Md("applyDiagramPatch",Mr,kj),M_=h,Mq={flowchart:ra,mindmap:nO,sequence:rr,timeline:rd,chart:rp,"state-machine":rv,gantt:rw,er:r_,class:rF,"org-chart":rT,venn:rZ,journey:rW,sankey:rQ,wireframe:r3,quadrant:r7};function ML(e){return M_.some(t=>t===e)}function MS(e,t){let a={spec:e.spec,...t?{options:t}:{}};switch(e.type){case"flowchart":return Mc(a);case"mindmap":return Mp(a);case"sequence":return Mh(a);case"timeline":return Mk(a);case"chart":return MM(a);case"state-machine":return Mg(a);case"gantt":return Mz(a);case"er":return Mu(a);case"class":return Mf(a);case"org-chart":return Mm(a);case"venn":return Mv(a);case"journey":return My(a);case"sankey":return Mw(a);case"wireframe":return Mx(a);case"quadrant":return Mb(a)}}},4733(e,t,a){function l(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}function s(e){var t;return l(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)&&l(t=e.viewBox)&&"number"==typeof t.height&&"number"==typeof t.minX&&"number"==typeof t.minY&&"number"==typeof t.width}a.d(t,{},{L:function(e){if(!l(e)||1!==e.version||!Array.isArray(e.icons)||!e.icons.every(s)||!l(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(!l(e))throw Error("Icon manifest collection counts are invalid.");let t={};for(let[a,l]of Object.entries(e)){if("number"!=typeof l)throw Error(`Icon manifest count for ${a} is invalid.`);t[a]=l}return t}(e.summary.collectionCounts),totalIcons:e.summary.totalIcons},version:1}},y:function(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(" ")}})},8713(e,t,a){let l=/<svg\b[^>]*>/u,i=/\sviewBox\s*=\s*(["'])([^"']*)\1/u;a.d(t,{},{Bn:function(e){let t=l.exec(e);if(!t)throw Error("Node logo source has no <svg> root element.");let a=t[0],s=i.exec(a)?.[2]?.trim().split(/[\s,]+/u).map(Number);if(!s||4!==s.length||s.some(e=>!Number.isFinite(e))||!((s[2]??0)>0&&(s[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="${s[2]}"`,/\sheight\s*=/u.test(a)?"":` height="${s[3]}"`].join("");if(!o)return e;let r=t.index+4;return`${e.slice(0,r)}${o}${e.slice(r)}`},nC:function(e){return void 0===e.variant&&e.bytes<=65536}})},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},l=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 s={};a=a||[null,l({}),l([]),l(l)];for(var o=2&t&&e;("object"==typeof o||"function"==typeof o)&&!~a.indexOf(o);o=l(o))Object.getOwnPropertyNames(o).forEach(t=>{s[t]=()=>e[t]});return s.default=()=>e,n.d(i,s),i},n.d=(e,t,a)=>{var l=(t,a)=>{for(var l in t)n.o(t,l)&&!n.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,[a]:t[l]})};l(t,"get"),l(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+"."+({16:"c673929a15151f96",712:"7f18d21e43cc7311"})[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},s=e=>{var t,a,l=e.__rspack_esm_ids,s=e.__webpack_modules__,o=e.__rspack_esm_runtime,r=0;for(t in s)n.o(s,t)&&(n.m[t]=s[t]);for(o&&o(n);r<l.length;r++)a=l[r],n.o(i,a)&&i[a]&&i[a][0](),i[l[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 l=import("./"+n.u(e)).then(s,t=>{throw 0!==i[e]&&(i[e]=void 0),t}),l=Promise.race([l,new Promise(t=>{a=i[e]=[t]})]);t.push(a[1]=l)}},n(6420);