sketchi 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/sketchi.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as e}from"node:module";let t=e(import.meta.url);var r,n,i,a,s={5776(e){let t={to:(e,t)=>t?`\x1b[${t+1};${e+1}H`:`\x1b[${e+1}G`,move(e,t){let r="";return e<0?r+=`\x1b[${-e}D`:e>0&&(r+=`\x1b[${e}C`),t<0?r+=`\x1b[${-t}A`:t>0&&(r+=`\x1b[${t}B`),r},up:(e=1)=>`\x1b[${e}A`,down:(e=1)=>`\x1b[${e}B`,forward:(e=1)=>`\x1b[${e}C`,backward:(e=1)=>`\x1b[${e}D`,nextLine:(e=1)=>"\x1b[E".repeat(e),prevLine:(e=1)=>"\x1b[F".repeat(e),left:"\x1b[G",hide:"\x1b[?25l",show:"\x1b[?25h",save:"\x1b7",restore:"\x1b8"},r={screen:"\x1b[2J",up:(e=1)=>"\x1b[1J".repeat(e),down:(e=1)=>"\x1b[J".repeat(e),line:"\x1b[2K",lineEnd:"\x1b[K",lineStart:"\x1b[1K",lines(e){let r="";for(let n=0;n<e;n++)r+=this.line+(n<e-1?t.up():"");return e&&(r+=t.left),r}};e.exports={cursor:t,scroll:{up:(e=1)=>"\x1b[S".repeat(e),down:(e=1)=>"\x1b[T".repeat(e)},erase:r,beep:"\x07"}},1833(e,r,n){let i,a,s,o,l,d,c,u,f,p,h,m,g,y,v,b,_,x,w,k,S,I,$,E,O,C,T,M,A,N;var P,R,j,D,U,F=n(719),B=n(2842),L=n(6526),z=n(1594);let W=(e,t)=>t(L.oJ(e)?0:F.nn(e.cause)?130:Y(F.iw(e.cause))),J="~effect/Runtime/errorExitCode",Y=e=>{if("object"==typeof e&&null!==e&&J in e){let t=e[J];if("number"==typeof t)return t}return 1},X="~effect/Runtime/errorReported",q=(a=({fiber:e,teardown:t})=>{let r=!1;function n(){r=!0,e.interruptUnsafe(e.id)}e.addObserver(e=>{process.removeListener("SIGINT",n),process.removeListener("SIGTERM",n),t(e,e=>{(r||0!==e)&&process.exit(e)})}),process.on("SIGINT",n),process.on("SIGTERM",n)},(0,z.XY)(e=>B.yw5(e[0]),(e,t)=>{let r=t?.disableErrorReporting===!0?B.MY7(e):B.MY7(B.dGm(e,e=>F.nn(e)?B.rIH:(e=>{if("object"==typeof e&&null!==e&&X in e){let t=e[X];if("boolean"==typeof t)return t}return!0})(F.iw(e))?B.vVN(e):B.rIH));try{let e=globalThis.setInterval(z.Yi,0x7fffffff);r.addObserver(()=>{clearInterval(e)})}catch{}return a({fiber:r,teardown:t?.teardown??W})}));var G=n(5633),V=n(9237),H=n(3614),K=n(664),Q=n(3265),Z=n(1179),ee=n(1587),et=n(4942);let er="~effect/PlatformError";class en extends et.rN("BadArgument"){get message(){return`${this.module}.${this.method}${this.description?`: ${this.description}`:""}`}}class ei extends et.$D{get message(){return`${this._tag}: ${this.module}.${this.method}${void 0!==this.pathOrDescriptor?` (${this.pathOrDescriptor})`:""}${this.description?`: ${this.description}`:""}`}}class ea extends et.rN("PlatformError"){constructor(e){"cause"in e?super({reason:e,cause:e.cause}):super({reason:e})}[er]=er;get message(){return this.reason.message}}let es=e=>new ea(new ei(e)),eo=e=>new ea(new en(e));var el=n(3952),ed=n(2449);let ec="~effect/MutableRef",eu={[ec]:ec,...ed.fU,toJSON(){return{_id:"MutableRef",current:(0,el.aB)(this.current)}}},ef=e=>{let t=Object.create(eu);return t.current=e,t};var ep=n(1554),eh=n(4233),em=n(3753),eg=n(9771),ey=n(6297);let ev=Symbol.for("effect/MutableList/Empty"),eb=e=>{let t=e.head;t.offset>=1024&&t===e.tail&&t.mutable&&(t.array.length-t.offset)*8<=t.offset&&(e.head=e.tail={array:t.array.slice(t.offset),mutable:!0,offset:0,next:void 0})},e_=()=>({array:[],mutable:!0,offset:0,next:void 0}),ex=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=e_(),e.tail=e.tail.next):e.head=e.tail=e_(),e.tail.array.push(t),e.length++},ew=e=>{e.head=e.tail=void 0,e.length=0},ek=e=>{if(!e.head)return ev;let t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length?e.head.next?e.head=e.head.next:ew(e):eb(e),t},eS={_A:z.D_,_E:z.D_},eI={"~effect/Queue":eS,"~effect/Queue/Enqueue":eS,"~effect/Queue/Dequeue":eS,...ed.fU,toJSON(){return{_id:"effect/Queue",state:this.state._tag,size:eU(this)}}},e$=e=>ed.R6(t=>{let r=Object.create(eI);return r.dispatcher=t.currentDispatcher,r.capacity=e?.capacity??1/0,r.strategy=e?.strategy??"suspend",r.messages={head:void 0,tail:void 0,length:0},r.scheduleRunning=!1,r.state={_tag:"Open",takers:new Set,offers:new Set,awaiters:new Set},ey.PyW(r)}),eE=(0,z.XY)(2,(e,t)=>ey.DYE(()=>eO(e,t)?eB:"Open"===e.state._tag&&"suspend"===e.strategy?eG(e,t):eF)),eO=(e,t)=>"Open"===e.state._tag&&(e.messages.length>=e.capacity?"sliding"===e.strategy?(ek(e.messages),ex(e.messages,t),!0):e.capacity<=0&&e.state.takers.size>0&&(ex(e.messages,t),eW(e),!0):(ex(e.messages,t),eJ(e),!0)),eC=(0,z.XY)(2,(e,t)=>ey.OH5(()=>eT(e,t))),eT=(e,t)=>{if("Open"!==e.state._tag)return!1;let r=ed.cb(t),n=ey.il9(r,eL);return 0===e.state.offers.size&&0===e.messages.length?eZ(e,n):(e.state={...e.state,_tag:"Closing",exit:n},eJ(e)),!0},eM=e=>eT(e,ed.OE(ed.RS())),eA=e=>ey.OH5(()=>eN(e)),eN=e=>{if("Done"===e.state._tag)return!1;ew(e.messages);let t=e.state.offers;for(let r of(eZ(e,"Open"===e.state._tag?ez:e.state.exit),t))eH(r);return!0},eP=e=>eR(e,1,1/0),eR=(0,z.XY)(3,(e,t,r)=>(t=eg.S(t),r=eg.S(r),ey.DYE(()=>eY(e,t,r)??ey.hgn(eq(e,()=>eX(e,t)),eR(e,t,r))))),ej=e=>ey.DYE(()=>eD(e)??ey.hgn(eq(e,()=>eX(e,1)),ej(e))),eD=e=>{if("Done"===e.state._tag)return e.state.exit;if(e.messages.length>0){let t=ek(e.messages);return eQ(e),ed.xt(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=eK(e.state.offers);return eQ(e),ed.xt(t)}},eU=e=>"Done"===e.state._tag?0:e.messages.length,eF=ed.xt(!1),eB=ed.xt(!0),eL=ed.Rk(ed.RS()),ez=ey._sz(),eW=e=>{if("Done"!==e.state._tag&&0!==e.state.takers.size){for(let t of e.state.takers)if(t.ready()&&(e.state.takers.delete(t),t.resume(ey.x5l),0===e.messages.length))break}},eJ=e=>{e.scheduleRunning||"Done"===e.state._tag||0===e.state.takers.size||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,eW(e)},0))},eY=(e,t,r)=>{if("Done"===e.state._tag)return e.state.exit;if(r<=0||t<=0)return ed.xt([]);if(!eX(e,t))return;let n=e.messages.length>0?((e,t)=>{if((t=eg.S(t))<=0||!e.head)return[];if((t=Math.min(t,e.length))===e.length&&e.head?.offset===0&&!e.head.next){let t=e.head.array;return ew(e),t}let r=Array(t),n=0,i=e.head;for(;i;){for(;i.offset<i.array.length;)if(r[n++]=i.array[i.offset],i.mutable&&(i.array[i.offset]=void 0),i.offset++,n===t)return e.head=i.offset===i.array.length&&i.next?i.next:i,e.length-=t,0===e.length?ew(e):eb(e),r;i=i.next}return ew(e),r})(e.messages,r):[eK(e.state.offers)];return eQ(e),ed.xt(n)},eX=(e,t)=>e.messages.length>=("Closing"===e.state._tag?1:Math.min(t,e.capacity||1))||e.capacity<=0&&"Done"!==e.state._tag&&e.state.offers.size>0,eq=(e,t)=>ey.E2r(r=>{if("Done"===e.state._tag)return r(e.state.exit);if(t())return r(ey.x5l);let n={ready:t,resume:r};return e.state.takers.add(n),ey.OH5(()=>{"Done"!==e.state._tag&&e.state.takers.delete(n)})}),eG=(e,t)=>ey.E2r(r=>eO(e,t)?r(eB):eV(e,{_tag:"Single",message:t,resume:r})),eV=(e,t)=>{if("Open"!==e.state._tag)return eH(t);let r=e.state.offers;return r.add(t),ey.OH5(()=>{"Done"!==e.state._tag&&(r.delete(t),"Closing"===e.state._tag&&0===r.size&&0===e.messages.length&&eZ(e,e.state.exit))})},eH=e=>"Single"===e._tag?e.resume(eF):e.resume(ed.xt(e.remaining.slice(e.offset))),eK=e=>{let t=e.values().next().value;if("Single"===t._tag)return e.delete(t),t.resume(eB),t.message;let r=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(ed.xt([]))),r},eQ=e=>{if("Done"===e.state._tag)return em.Og(e.state.exit.cause);if(0===e.state.offers.size)return"Closing"===e.state._tag&&0===e.messages.length&&(eZ(e,e.state.exit),em.Og(e.state.exit.cause));for(let t of e.state.offers){let r=e.capacity-e.messages.length;if(r<=0)break;if("Single"===t._tag)ex(e.messages,t.message),e.state.offers.delete(t),t.resume(eB);else{for(;t.offset<t.remaining.length;t.offset++){if(0===r)return!1;ex(e.messages,t.remaining[t.offset]),r--}e.state.offers.delete(t),t.resume(ed.xt([]))}}return!1},eZ=(e,t)=>{if("Done"===e.state._tag)return;let r=e.state;for(let n of(e.state={_tag:"Done",exit:t},r.takers))n.resume(t);for(let e of(r.takers.clear(),r.awaiters))e(t);r.awaiters.clear()};var e0=n(5744);let e1="~effect/Channel",e2=e=>(0,eh.i5)(e,e1),e5={[e1]:{_Env:z.D_,_InErr:z.D_,_InElem:z.D_,_OutErr:z.D_,_OutElem:z.D_},pipe(){return(0,ep.tT)(this,arguments)}},e3=e=>{let t=Object.create(e5);return t.transform=(t,r)=>B.Tyx(e(t,r),e=>B.PyW(B.ATB(e))),t},e6=(e,t)=>e3((r,n)=>B.qIB(e9(e)(r,n),e=>t(e,n))),e8=e=>e3((t,r)=>e),e9=e=>e.transform,e4=e8(B.PyW(F.Vw()));B.ZmZ;let e7=(0,z.XY)(2,(e,t)=>e6(e,e=>B.OH5(()=>{let r=0;return B.TjK(e,e=>t(e,r++))}))),te=(0,z.XY)(2,(e,t)=>tt(e,e=>B.PyW(t(e)))),tt=(0,z.XY)(2,(e,t)=>e6(e,e=>B.PyW(em.m8(e,e=>B.qIB(t(e),F.Vw))))),tr=(0,z.XY)(e=>e2(e[0])&&e2(e[1]),(e,t,r)=>{let n;return n=B.D9k(function*(n,i,a){let s=r?.haltStrategy??"both",o=yield*e$({capacity:0});yield*e0.U9(a,eA(o));let l=0,d=(e,t,r)=>e9(t)(n,r).pipe(B.qIB(e=>e.pipe(B.qIB(e=>eE(o,e)),B.i4r)),B.S5A(t=>B.hgn(e0.VN(r,em.aU(t)),function(e,t){if(l++,!em.Og(t))return eC(o,t);switch(s){case"both":return 2===l?eC(o,t):B.rIH;case"left":case"right":return e===s?eC(o,t):B.rIH;case"either":return eC(o,t)}}(e,t))),B.ar0(a));return yield*d("left",e,e0.Fp(a)),yield*d("right",t,e0.Fp(a)),ej(o)}),e3(B.D9k(function*(e,t){let r=e0.Fp(t),i=e=>e0.VN(r,em.aU(e)),a=yield*B.S5A(n(e,t,r),i);return B.S5A(a,i)}))}),tn=(0,z.XY)(2,(e,t)=>e3((r,n)=>B.qIB(e9(e)(r,n),e=>e9(t)(e,n)))),ti=e=>e3((t,r)=>{let n;return B.PyW(B.DYE(()=>n||e.pipe(e0.Gt(r),B.qIB(e=>e9(e)(t,r)),B.qIB(e=>n=e))))}),ta=(e,t,r)=>B.DYE(()=>{let n=e0.LZ(),i=e9(e)(F.Vw(),n);return em.m8(B.qIB(i,t),r||B.PyW).pipe(B.cfM(e=>e0.VN(n,e)))}),ts=(0,z.XY)(2,(e,t)=>ta(e,e=>B.i4r(B.qIB(e,t),{disableYield:!0}))),to=(0,z.XY)(3,(e,t,r)=>B.DYE(()=>{let n=t();return ta(e,e=>B.iMI({while:z.ue,body:()=>e,step:e=>{n=r(n,e)}}),()=>B.PyW(n))})),tl=(0,z.XY)(3,(e,t,r)=>B.DYE(()=>{let n=t();return ta(e,e=>B.iMI({while:z.ue,body:(0,z.dY)(e.pipe(B.qIB(e=>r(n,e)),B.TjK(e=>{n=e}))),step:z.Yi}),()=>B.PyW(n))})),td=(e,t)=>e9(e)(F.Vw(),t),tc="~effect/Sink",tu=B.PyW([void 0]),tf={[tc]:{_A:z.D_,_In:z.D_,_L:z.D_,_E:z.D_,_R:z.D_},pipe(){return(0,ep.tT)(this,arguments)}},tp=e=>(0,eh.i5)(e,tc),th=e=>tm((t,r)=>e9(e)(t,r).pipe(B.qIB(B.i4r({disableYield:!0})),em.m8(B.PyW))),tm=e=>{let t=Object.create(tf);return t.transform=e,t},tg=e=>e3((t,r)=>B.PyW(B.qIB(e.transform(t,r),F.Vw)));B.ZmZ;let ty=tm(e=>em.m8(B.i4r(e,{disableYield:!0}),()=>tu));ee.none,ee.isNone,ee.none;let tv=e=>th(ti(B.TjK(e,tg))),tb={_R:z.D_,_E:z.D_,_A:z.D_},t_=function(e){this.channel=e};t_.prototype={"~effect/Stream":tb,pipe(){return(0,ep.tT)(this,arguments)}};let tx=e=>(0,eh.i5)(e,"~effect/Stream"),tw=e=>new t_(e),tk=e=>e.channel,tS=tw(e4),tI=e=>{let t;return tw((t=()=>e().channel,e3((e,r)=>B.DYE(()=>e9(t())(e,r)))))},t$=e=>{let t;return K.ET(e)?tw((t=B.PyW(e),e8(B.OH5(()=>{let e=!1;return B.DYE(()=>e?F.Vw():(e=!0,t))})))):tS},tE=e=>tw(ti(B.TjK(e,tk))),tO=(0,z.XY)(2,(e,t)=>tI(()=>{let r=0;return tw(e7(e.channel,K.Tj(e=>t(e,r++))))})),tC=(0,z.XY)(e=>tx(e[0])&&tx(e[1]),(e,t,r)=>tw(tr(tk(e),tk(t),r))),tT=(0,z.XY)(2,(e,t)=>{let r;return r=(e,r)=>B.OH5(()=>{let n,i,a=B.DYE(()=>{if(void 0!==i){let e=i;return i=void 0,B.PyW(e)}return e}).pipe(B.MfU(e=>(n=L.fJ(e),F.Vw()))),s=B.TjK(B.DYE(()=>t.transform(a,r)),([e,t])=>(i=t,K.of(e)));return B.DYE(()=>n||s)}),tw(e3((t,n)=>B.qIB(td(e.channel,n),e=>r(e,n))))}),tM=(0,z.XY)(e=>tx(e[0]),(e,t)=>tI(()=>{let r=new TextDecoder(t?.encoding);return tO(e,e=>r.decode(e,{stream:!0}))})),tA=(0,z.XY)(2,(e,t)=>B.Pxi(r=>td(e.channel,r).pipe(B.qIB(e=>t.transform(e,r)),B.TjK(([e])=>e)))),tN=(0,z.XY)(3,(e,t,r)=>tl(e.channel,t,(e,t)=>{let n=0,i=e;return B.TjK(B.iMI({while:()=>n<t.length,body:()=>r(i,t[n]),step(e){i=e,n++}}),()=>i)})),tP=((e,t)=>ts(e.channel,t),"~effect/FileSystem"),tR=Z.kl("effect/FileSystem"),tj="~effect/FileSystem/File";class tD extends(Z.kl())("effect/FileSystem/WatchBackend"){}let tU="~effect/Path",tF=Z.kl("effect/Path");var tB=n(3811),tL=n(9315);function tz(){return Object.assign(e=>e,{option:e=>ee.some(e),result:e=>tL.Py(e),is:e=>!0})}let tW=tz(),tJ=tz(),tY="~effect/process/ChildProcessSpawner/ChildProcessHandle",tX={[tY]:tY,...el.os,toJSON(){return{_id:"ChildProcessHandle",pid:this.pid}}},tq=e=>Object.setPrototypeOf({...e},tX);class tG extends(Z.kl())("effect/process/ChildProcessSpawner"){}let tV="~effect/process/ChildProcess",tH={...tB.bp({label:"Command",evaluate(e){return Z.fp(e.context,tG).spawn(this)}}),[tV]:tV},tK=(e,t,r)=>Object.assign(Object.create(tH),{_tag:"StandardCommand",command:e,args:t,options:r}),tQ=function(...e){if(tZ(e[0])){let[t,...r]=e,n=t2(t,r);return tK(n[0]??"",n.slice(1),{})}if("object"==typeof e[0]&&!Array.isArray(e[0])&&!tZ(e[0])){let t=e[0];return function(e,...r){let n=t2(e,r);return tK(n[0]??"",n.slice(1),t)}}if("string"==typeof e[0]&&!Array.isArray(e[1])){let[t,r={}]=e;return tK(t,[],r)}let[t,r=[],n={}]=e;return tK(t,r,n)},tZ=e=>Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw),t0=e=>{let t=/^fd(\d+)$/.exec(e);if(null===t)return;let r=parseInt(t[1],10);return r>=3?r:void 0},t1=e=>`fd${e}`,t2=(e,t)=>{let r=[];for(let[n,i]of e.entries())r=t5(e,t,r,i,n);return r},t5=(e,t,r,n,i)=>{let a=e.raw[i];if(void 0===a)throw Error(`Invalid backslash sequence: ${e.raw[i]}`);let{hasLeadingWhitespace:s,hasTrailingWhitespace:o,tokens:l}=t9(n,a),d=t4(r,l,s);if(i===t.length)return d;let c=t[i];return t4(d,Array.isArray(c)?c.map(e=>t3(e)):[t3(c)],o)},t3=e=>"string"==typeof e?e:String(e),t6=new Set([" "," ","\r","\n"]),t8={x:3,u:5},t9=(e,t)=>{if(0===t.length)return{tokens:[],hasLeadingWhitespace:!1,hasTrailingWhitespace:!1};let r=t6.has(t[0]),n=[],i=0;for(let r=0,a=0;r<e.length;r+=1,a+=1){let s=t[a];if(t6.has(s))i!==r&&n.push(e.slice(i,r)),i=r+1;else if("\\"===s){let e=t[a+1];if("\n"===e)r-=1,a+=1;else if("u"===e&&"{"===t[a+2]){let e=t.indexOf("}",a+3);parseInt(t.slice(a+3,e),16)>65535&&(r+=1),a=e}else a+=t8[e]??1}}let a=i===e.length;return a||n.push(e.slice(i)),{tokens:n,hasLeadingWhitespace:r,hasTrailingWhitespace:a}},t4=(e,t,r)=>r||0===e.length||0===t.length?[...e,...t]:[...e.slice(0,-1),`${e.at(-1)}${t.at(0)}`,...t.slice(1)],t7=t("node:child_process"),re=t("node:stream"),rt=(e,t)=>(r,[n])=>{let i="Unknown";switch(r.code){case"ENOENT":i="NotFound";break;case"EACCES":i="PermissionDenied";break;case"EEXIST":i="AlreadyExists";break;case"EISDIR":case"ENOTDIR":case"ELOOP":i="BadResource";break;case"EBUSY":i="Busy"}return es({_tag:i,module:e,method:t,pathOrDescriptor:n,syscall:r.syscall,cause:r})},rr=e=>th(te(rn(e),e=>[e])),rn=e=>e3(t=>{let r=e.evaluate();return B.PyW(ri({...e,writable:r,pull:t}))}),ri=e=>e.pull.pipe(B.qIB(t=>{let r=0;return B.E2r(n=>{let i=!1,a=()=>{for(;r<t.length;){if(i)return;if(!e.writable.write(t[r++],e.encoding)){i||e.writable.once("drain",a);return}}i||n(B.rIH)};return a(),B.OH5(()=>{i=!0,e.writable.off("drain",a)})})}),B.i4r({disableYield:!0}),!1!==e.endOnDone?em.m8(t=>"closed"in e.writable&&e.writable.closed?F.Vw(t):B.E2r(r=>{let n=()=>r(F.Vw(t));return e.writable.once("finish",n),e.writable.end(),B.OH5(()=>{e.writable.off("finish",n)})})):z.D_,B.KT6(B.E2r(t=>{let r=r=>t(B.fJG(e.onError(r)));return e.writable.once("error",r),B.OH5(()=>{e.writable.off("error",r)})})));ey.zFM,ey.C6p;let ra=ey.D7p;ey.INJ;let rs=ey.mKq;ey.eGS,ey.DKo,ey.$MQ;let ro=ey.Iku,rl=ey.vTQ,rd=ey.zzk;ey.Fbb;let rc=e=>tw(ru(e)),ru=e=>e3((t,r)=>rf({scope:r,readable:e.evaluate(),onError:e.onError??rp,chunkSize:e.chunkSize,closeOnDone:e.closeOnDone})),rf=e=>{let t=e.readable,r=e.closeOnDone??!0,n=e.exit??ef(void 0),i=e.latch??rd(!1);function a(){i.openUnsafe()}function s(t){n.current=L.fJ(e.onError(t)),i.openUnsafe()}function o(){n.current=L.fJ(F.RS()),i.openUnsafe()}t.on("readable",a),t.once("error",s),t.once("end",o);let l=B.DYE(function r(){let a=e.readable.read(e.chunkSize);if(null===a)return n.current?n.current:t.readableEnded?B.fJG(F.RS()):(i.closeUnsafe(),B.qIB(i.await,r));let s=K.of(a);for(;null!==(a=e.readable.read(e.chunkSize));)s.push(a);return B.PyW(s)});return B.as(e0.U9(e.scope,B.OH5(()=>{t.off("readable",a),t.off("error",s),t.off("end",o),r&&"closed"in e.readable&&!e.readable.closed&&e.readable.destroy()})),l)};re.Readable;let rp=e=>new F.Bk(e),rh=e=>e instanceof globalThis.Error?e:new globalThis.Error(String(e)),rm=(e,t,r)=>{let{commands:n}=r_(r),i=n.reduce((e,t)=>{let r=`${t.command} ${t.args.join(" ")}`;return 0===e.length?r:`${e} | ${r}`},"");return rt("ChildProcess",e)(t,[i])},rg=(e,t)=>{if(!V.NJ(t))return!0;if("win32"===globalThis.process.platform)return!1;try{return globalThis.process.kill(-e.pid,0),!0}catch{return!1}},ry=(e,t=()=>{})=>t7.execFile("taskkill",["/pid",String(e.pid),"/T","/F"],{windowsHide:!0},t),rv=B.JkU(function*(){let e,t,r=yield*tR,n=yield*tF,i=B.D9k(function*(e){if(!eh.b0(e.cwd))return yield*r.access(e.cwd),n.resolve(e.cwd)}),a=e=>tp(e)?"pipe":e,s=e=>{let t={stream:"pipe",encoding:"utf-8",endOnDone:!0};return eh.b0(e.stdin)?t:"string"==typeof e.stdin||tx(e.stdin)?{...t,stream:e.stdin}:{stream:e.stdin.stream,encoding:e.stdin.encoding??t.encoding,endOnDone:e.stdin.endOnDone??t.endOnDone}},o=(e,t)=>{let r=e[t];return eh.b0(r)?{stream:"pipe"}:"string"==typeof r||tp(r)?{stream:r}:{stream:r.stream}},l=B.D9k(function*(e,t,r){if(0===r.length)return{getInputFd:()=>ty,getOutputFd:()=>tS};let n=new Map,i=new Map;for(let{config:a,fd:s}of r){let r=t.stdio[s];switch(a.type){case"input":{let t=ty;r&&"write"in r&&(t=rr({evaluate:()=>r,onError:t=>rm(`fromWritable(fd${s})`,rh(t),e)})),a.stream&&(yield*B.x6Z(tA(a.stream,t))),n.set(s,t);break}case"output":{let t=tS;if(r&&"read"in r){let n=new re.PassThrough;r.on("error",e=>n.destroy(e)),r.pipe(n),t=rc({evaluate:()=>n,onError:t=>rm(`fromReadable(fd${s})`,rh(t),e)})}a.sink&&(t=tT(t,a.sink)),i.set(s,t)}}}return{getInputFd:e=>n.get(e)??ty,getOutputFd:e=>i.get(e)??tS}}),d=(e,t,r)=>B.E2r(n=>{let i,a=Date.now()+r,s=()=>{clearTimeout(i),e.removeListener("exit",o)},o=()=>{if(clearTimeout(i),Date.now()>=a||!rg(e,t)){s(),n(B.rIH);return}i=setTimeout(o,10)};return e.on("exit",o),o(),B.OH5(s)}),c=B.D9k(function*(e,t,r,n){let i=r=>("win32"===globalThis.process.platform?B.E2r(r=>{ry(t,t=>{t?r(B.fJG(rm("kill",rh(t),e))):r(B.rIH)})}):B.SvU({try:()=>{globalThis.process.kill(-t.pid,r)},catch:t=>rm("kill",rh(t),e)})).pipe(B.MfU(()=>B.DYE(()=>{if(!t.kill(r)){let t=new globalThis.Error("Failed to kill child process");return B.fJG(rm("kill",t,e))}return B.rIH})));yield*i(n?.killSignal??"SIGTERM"),eh.b0(n?.forceKillAfter)?yield*d(t,r,1e3):(yield*d(t,r,H.kE(n.forceKillAfter)),rg(t,r)&&(yield*i("SIGKILL"),yield*d(t,r,1e3))),yield*V.Tx(r)}),u=(e,t)=>{let r=t??"stdout";switch(r){case"stdout":return e.stdout;case"stderr":return e.stderr;case"all":return e.all;default:{let t=t0(r);if(eh.EA(t))return e.getOutputFd(t);return e.stdout}}},f=B.D9k(function*(e){switch(e._tag){case"StandardCommand":{var t,r,n;let d,u,f,p,h,m,g,y,v=s(e.options),b=o(e.options,"stdout"),_=o(e.options,"stderr"),x=(e=>{if(eh.b0(e.additionalFds))return[];let t=[];for(let[r,n]of Object.entries(e.additionalFds)){let e=t0(r);eh.EA(e)&&t.push({fd:e,config:n})}return t.sort((e,t)=>e.fd-t.fd)})(e.options),w=!0,k=yield*i(e.options),S=(d=e.options).extendEnv?{...globalThis.process.env,...d.env}:d.env,I=((e,t,r,n)=>{let i,s=[tx(i=e.stream)?"pipe":i,a(t.stream),a(r.stream)];if(0===n.length)return s;let o=n.reduce((e,{fd:t})=>Math.max(e,t),2);for(let e=3;e<=o;e++)s[e]="ignore";for(let{fd:e}of n)s[e]="pipe";return s})(v,b,_,x),[$,E]=yield*B.Q56((t=e.options,r={cwd:k,env:S,stdio:I},n=process.platform,u=t.detached??"win32"!==n,f={...r,detached:u,shell:t.shell,windowsHide:t.windowsHide??!u},B.E2r(t=>{let r=V.LZ(),n=t7.spawn(e.command,e.args,f);return n.on("error",r=>{t(B.fJG(rm("spawn",r,e)))}),n.on("exit",(...e)=>{V.$w(r,L.Py(e))}),n.on("spawn",()=>{t(B.PyW([n,r]))}),B.OH5(()=>{n.kill("SIGTERM")})})),B.D9k(function*([t,r]){if(yield*V.$L(r)){let[n]=yield*V.Tx(r);0!==n&&eh.Pe(n)?yield*B.XeO(c(e,t,r,e.options)):w&&"win32"!==process.platform&&!1!==e.options.detached&&(yield*B.XeO(c(e,t,r,e.options)));return}w&&(yield*B.XeO(c(e,t,r,e.options)))})),O=tJ($.pid);$.on("exit",t=>{0!==t&&eh.Pe(t)&&((e,t)=>{if("win32"===globalThis.process.platform)return ry(e);try{globalThis.process.kill(-e.pid,t)}catch{}})($,e.options.killSignal??"SIGTERM")});let C=B.OH5(()=>{w||($.ref(),w=!0)}),T=B.OH5(()=>(w&&($.unref(),w=!1),C)),M=yield*B.DYE(()=>{let t=ty;return(eh.Pe($.stdin)&&(t=rr({evaluate:()=>$.stdin,onError:t=>rm("fromWritable(stdin)",rh(t),e),endOnDone:v.endOnDone,encoding:v.encoding})),tx(v.stream))?B.as(B.x6Z(tA(v.stream,t)),t):B.PyW(t)}),{all:A,stderr:N,stdout:P}=(h=$.stdout?(p=new re.PassThrough,$.stdout.on("error",e=>p.destroy(e)),$.stdout.pipe(p),rc({evaluate:()=>p,onError:t=>rm("fromReadable(stdout)",rh(t),e)})):tS,g=$.stderr?(m=new re.PassThrough,$.stderr.on("error",e=>m.destroy(e)),$.stderr.pipe(m),rc({evaluate:()=>m,onError:t=>rm("fromReadable(stderr)",rh(t),e)})):tS,tp(b.stream)&&(h=tT(h,b.stream)),tp(_.stream)&&(g=tT(g,_.stream)),y=tC(h,g),{stdout:h,stderr:g,all:y}),{getInputFd:R,getOutputFd:j}=yield*l(e,$,x),D=B.TjK(V.$L(E),e=>!e);return tq({pid:O,exitCode:B.qIB(V.Tx(E),([t,r])=>{if(eh.Pe(t))return B.PyW(tW(t));let n=new globalThis.Error(`Process interrupted due to receipt of signal: '${r}'`);return B.fJG(rm("exitCode",n,e))}),isRunning:D,kill:t=>c(e,$,E,t),stdin:M,stdout:P,stderr:N,all:A,getInputFd:R,getOutputFd:j,unref:T})}case"PipedCommand":{let{commands:t,pipeOptions:r}=r_(e),[n,...i]=t,a=[(yield*f(n))];for(let e=0;e<i.length;e++){let t=i[e],n=r[e]??{},o=s(t.options),l=tE(B.PyW(u(a[a.length-1],n.from))),d=n.to??"stdin";if("stdin"===d)a.push((yield*f(tQ(t.command,t.args,{...t.options,stdin:{...o,stream:l}}))));else{let e=t0(d);if(eh.EA(e)){let r=t1(e),n=t.options.additionalFds??{};a.push((yield*f(tQ(t.command,t.args,{...t.options,additionalFds:{...n,[r]:{type:"input",stream:l}}}))))}else a.push((yield*f(tQ(t.command,t.args,{...t.options,stdin:{...o,stream:l}}))))}}let o=a[a.length-1],l=B.JkU(function*(){let e=[];for(let t of a)e.push((yield*t.unref));return B.jJl([...e].reverse(),e=>e,{discard:!0})});return tq({pid:o.pid,exitCode:o.exitCode,isRunning:o.isRunning,kill:e=>B.jJl([...a].reverse(),t=>B.XeO(t.kill(e)),{discard:!0}),stdin:a[0].stdin,stdout:o.stdout,stderr:o.stderr,all:o.all,getInputFd:o.getInputFd,getOutputFd:o.getOutputFd,unref:l})}}});return e=(e,t)=>f(e).pipe(B.TjK(e=>tM(t?.includeStderr===!0?e.all:e.stdout)),tE),t=(t,r)=>e(t,r).channel.pipe(tn(e3((e,t)=>B.OH5(()=>{let t="",r=!1,n=ee.none(),i=B.DYE(()=>"Some"===n._tag?F.Vw(n.value):em.tv(e,{onSuccess:a,onFailure:B.ATB,onDone:e=>{if(n=ee.some(e),t.length>0){let e=t;return t="",r=!1,B.PyW([e])}return F.Vw(e)}}));function a(e){let n=function(e){let n=[];function i(e){0===t.length?n.push(e):(n.push(t+e),t="")}for(let n=0;n<e.length;n++){let a=e[n];if(0!==a.length){let e=0,n=a.indexOf("\r"),s=a.indexOf("\n");for(r&&(0===s&&(e=1,s=a.indexOf("\n",e)),r=!1);-1!==n||-1!==s;)-1===n||-1!==s&&s<n?(i(a.substring(e,s)),e=s+1,s=a.indexOf("\n",e)):(i(a.substring(e,n)),a.length===n+1?(r=!0,e=a.length,n=-1):(e=n+(s===n+1?2:1),n=a.indexOf("\r",e),s=a.indexOf("\n",e)));t+=a.substring(e)}}return K.ET(n)?n:null}(e);return null!==n?B.PyW(n):i}return i}))),tw),tG.of({spawn:f,exitCode:e=>B.P1j(B.qIB(f(e),e=>e.exitCode)),streamString:e,streamLines:t,lines:(e,r)=>to(t(e,r).channel,()=>[],(e,t)=>{for(let r=0;r<t.length;r++)e.push(t[r]);return e}),string:(t,r)=>to(e(t,r).channel,()=>"",(e,t)=>e+t.join(""))})}),rb=G.QZ(tG,rv),r_=e=>{let t=[],r=[],n=e=>{switch(e._tag){case"StandardCommand":t.push(e);break;case"PipedCommand":n(e.left),r.push(e.options),n(e.right)}};if(n(e),0===t.length)throw Error("flattenCommand produced empty commands array");let[i,...a]=t;return{commands:[i,...a],pipeOptions:r}},rx="0123456789ABCDEFGHJKMNPQRSTVWXYZ",rw=e=>e.toString(16).padStart(2,"0"),rk=e=>[e.subarray(0,4),e.subarray(4,6),e.subarray(6,8),e.subarray(8,10),e.subarray(10,16)].map(e=>Array.from(e,rw).join("")).join("-"),rS=()=>globalThis.crypto.getRandomValues(new Uint8Array(16));function rI(e=rS()){return e[6]=15&e[6]|64,e[8]=63&e[8]|128,e}function r$(e,t=rS()){let r=Math.min(Math.max(0,Math.trunc(e)),0xffffffffffff);return t[0]=Math.floor(r/0x10000000000),t[1]=255&Math.floor(r/0x100000000),t[2]=255&Math.floor(r/0x1000000),t[3]=255&Math.floor(r/65536),t[4]=255&Math.floor(r/256),t[5]=255&r,t[6]=15&t[6]|112,t[8]=63&t[8]|128,t}let rE="~effect/Crypto",rO=Z.kl("effect/Crypto");var rC=n(7598);let rT=(s=(D={randomBytes:rC.randomBytes,digest:(e,t)=>B.SvU({try:()=>Uint8Array.from(rC.createHash((e=>{switch(e){case"SHA-1":return"sha1";case"SHA-256":return"sha256";case"SHA-384":return"sha384";case"SHA-512":return"sha512"}})(e)).update(t).digest()),catch:e=>es({module:"Crypto",method:"digest",_tag:"Unknown",description:"Could not compute digest",cause:e})})}).randomBytes,o=e=>(31&e[0])*0x1000000000000+0x10000000000*e[1]+0x100000000*e[2]+0x1000000*e[3]+65536*e[4]+256*e[5]+e[6],l=()=>o(s(7))/0x20000000000000,d=()=>{for(;;){let e=s(7),t=o(e);if((32&e[0])==0)return t+Number.MIN_SAFE_INTEGER;if(t<Number.MAX_SAFE_INTEGER)return t+1}},rO.of({[rE]:rE,randomBytes:e=>{let t,r;return B.TjK((t="randomBytes",Number.isSafeInteger(r=e)&&r>=0?B.PyW(r):B.fJG(eo({module:"Crypto",method:t,description:"size must be a non-negative safe integer"}))),s)},nextDoubleUnsafe:l,nextIntUnsafe:d,digest:D.digest,random:B.OH5(()=>l()),randomBoolean:B.OH5(()=>l()>.5),randomInt:B.OH5(()=>d()),randomBetween:(e,t)=>B.OH5(()=>((e,t,r)=>{let n=r*(t-e)+e;if(n!==t||e>=t||!Number.isFinite(t))return n;if(0===t)return -5e-324;let i=new DataView(new ArrayBuffer(8));i.setFloat64(0,t);let a=i.getBigUint64(0);return i.setBigUint64(0,t>0?a-BigInt(1):a+BigInt(1)),i.getFloat64(0)})(e,t,l())),randomIntBetween(e,t,r){let n=+(r?.halfOpen!==!0);return B.OH5(()=>{let r=Math.ceil(e),i=Math.floor(t);return Math.floor(l()*(i-r+n))+r})},randomShuffle:e=>B.OH5(()=>{let t=Array.from(e);for(let e=t.length-1;e>=1;e-=1){let r=Math.min(e,Math.floor(l()*(e+1))),n=t[e];t[e]=t[r],t[r]=n}return t}),randomUUIDv4:B.OH5(()=>{let e;return rk(void 0===(e=s(16))?rI():rI(e))}),randomUUIDv7:B.RKA(e=>{let t,r;return B.PyW((t=e.currentTimeMillisUnsafe(),rk(void 0===(r=s(16))?r$(t):r$(t,r))))}),randomULID:B.RKA(e=>B.PyW(((e,t)=>{if(10!==t.length)throw Error(`ULID randomness must be exactly 10 bytes, received ${t.length}`);let r=Math.min(Math.max(0,Math.trunc(e)),0xffffffffffff),n="";for(let e=45;e>=0;e-=5)n+=rx[31&Math.floor(r/2**e)];let i=0,a=0;for(let e of t){for(i=i<<8|e,a+=8;a>=5;)a-=5,n+=rx[i>>>a&31];i&=(1<<a)-1}return n})(e.currentTimeMillisUnsafe(),s(10))))})),rM=G.Py(rO,rT);var rA=n(5053);let rN=t("node:fs"),rP=t("node:os"),rR=t("node:path");var rj=n.t(rR,2);let rD=e=>t=>eo({module:"FileSystem",method:e,description:t.message??String(t)}),rU=(e,t)=>{let r=Number(e);if(!Number.isSafeInteger(r))throw RangeError(`${t} exceeds the safe integer range: ${e}`);return r},rF=e=>ee.flatMap(ee.fromNullishOr(e),rA.Ro),rB=(e,t)=>B.SvU({try:()=>rU(e,"position"),catch:rD(t)}),rL=(c=(0,B._r7)(rN.access,rt("FileSystem","access"),rD("access")),(e,t)=>{let r=rN.constants.F_OK;return t?.readable&&(r|=rN.constants.R_OK),t?.writable&&(r|=rN.constants.W_OK),c(e,r)}),rz=(u=(0,B._r7)(rN.cp,rt("FileSystem","copy"),rD("copy")),(e,t,r)=>u(e,t,{force:r?.overwrite??!1,preserveTimestamps:r?.preserveTimestamps??!1,recursive:!0})),rW=(f=(0,B._r7)(rN.copyFile,rt("FileSystem","copyFile"),rD("copyFile")),(e,t)=>f(e,t)),rJ=(p=(0,B._r7)(rN.chmod,rt("FileSystem","chmod"),rD("chmod")),(e,t)=>p(e,t)),rY=(h=(0,B._r7)(rN.chown,rt("FileSystem","chown"),rD("chown")),(e,t,r)=>h(e,t,r)),rX=(m=(0,B._r7)(rN.glob,rt("FileSystem","glob"),rD("glob")),(e,t)=>m(e,{cwd:t?.root,exclude:t?.exclude})),rq=(g=(0,B._r7)(rN.link,rt("FileSystem","link"),rD("link")),(e,t)=>g(e,t)),rG=(y=(0,B._r7)(rN.mkdir,rt("FileSystem","makeDirectory"),rD("makeDirectory")),(e,t)=>y(e,{recursive:t?.recursive??!1,mode:t?.mode})),rV=e=>{let t=(0,B._r7)(rN.mkdtemp,rt("FileSystem",e),rD(e));return e=>B.DYE(()=>{let r=e?.prefix??"",n="string"==typeof e?.directory?rR.join(e.directory,"."):rP.tmpdir();return t(r?rR.join(n,r):n+"/")})},rH=rV("makeTempDirectory"),rK=e=>{let t=(0,B._r7)(rN.rm,rt("FileSystem",e),rD(e));return(e,r)=>t(e,{recursive:r?.recursive??!1,force:r?.force??!1})},rQ=rK("remove"),rZ=(v=rV("makeTempDirectoryScoped"),b=rK("makeTempDirectoryScoped"),e=>B.Q56(v(e),e=>B.QgK(b(e,{recursive:!0})))),r0=(U="open",_=(0,B._r7)(rN.open,rt("FileSystem",U),rD(U)),x=(0,B._r7)(rN.close,rt("FileSystem",U),rD(U)),(e,t)=>(0,z.Fs)(B.Q56(_(e,t?.flag??"r",t?.mode),e=>B.QgK(x(e))),B.TjK(e=>r1(e,t?.flag?.startsWith("a")??!1)))),r1=(()=>{let e=e=>(0,B._r7)(rN.read,rt("FileSystem",e),rD(e)),t=e("read"),r=e("readAlloc"),n=(0,B._r7)(rN.fstat,rt("FileSystem","stat"),rD("stat")),i=(0,B._r7)(rN.ftruncate,rt("FileSystem","truncate"),rD("truncate")),a=(0,B._r7)(rN.fsync,rt("FileSystem","sync"),rD("sync")),s=e=>(0,B._r7)(rN.write,rt("FileSystem",e),rD(e)),o=s("write"),l=s("writeAll");class d{[tj];fd;append;position=BigInt(0);constructor(e,t){this[tj]=tj,this.fd=e,this.append=t}get stat(){return B.qIB(n(this.fd,{bigint:!0}),ne)}get sync(){return a(this.fd)}seek(e,t){return B.DYE(()=>{let r="start"===t?e:this.position+e;return r<BigInt(0)?B.fJG(eo({module:"FileSystem",method:"seek",description:"Cannot seek before the start of the file"})):(this.position=r,B.PyW(r))})}read(e){return B.DYE(()=>{let r=this.position;return B.TjK(t(this.fd,{buffer:e,position:r}),e=>(this.position=r+BigInt(e),e))})}readAlloc(e){return B.DYE(()=>{try{if(!Number.isInteger(e)||e<0)throw RangeError("size must be a non-negative integer");let t=Buffer.allocUnsafeSlow(e),n=this.position;return B.TjK(r(this.fd,{buffer:t,position:n}),r=>{if(0===r)return ee.none();if(this.position=n+BigInt(r),r===e)return ee.some(t);let i=Buffer.allocUnsafeSlow(r);return t.copy(i,0,0,r),ee.some(i)})}catch(e){return B.fJG(rD("readAlloc")(e))}})}truncate(e){return B.TjK(i(this.fd,e||void 0),()=>{if(!this.append){let t=BigInt(e??0);this.position>t&&(this.position=t)}})}write(e){return B.DYE(()=>{let t=this.position;return B.qIB(this.append?B.PyW(void 0):rB(t,"write"),r=>B.TjK(o(this.fd,e,void 0,void 0,r),e=>(this.append||(this.position=t+BigInt(e)),e)))})}writeAllChunk(e){return B.DYE(()=>{let t=this.position;return B.qIB(this.append?B.PyW(void 0):rB(t,"writeAll"),r=>B.qIB(l(this.fd,e,void 0,void 0,r),r=>0===r?B.fJG(es({module:"FileSystem",method:"writeAll",_tag:"WriteZero",pathOrDescriptor:this.fd,description:"write returned 0 bytes written"})):(this.append||(this.position=t+BigInt(r)),r<e.length?this.writeAllChunk(e.subarray(r)):B.rIH)))})}writeAll(e){return 0===e.length?B.rIH:this.writeAllChunk(e)}}return(e,t)=>new d(e,t)})(),r2=e=>{let t=rV(e);return B.D9k(function*(e){let r=yield*t(e),n=rC.randomBytes(6).toString("hex"),i=rR.join(r,e?.suffix?`${n}${e.suffix}`:n);return yield*na(i,new Uint8Array(0)),i})},r5=r2("makeTempFile"),r3=(w=r2("makeTempFileScoped"),k=rK("makeTempFileScoped"),e=>B.Q56(w(e),e=>B.QgK(k(rR.dirname(e),{recursive:!0})))),r6=(e,t)=>B.$mh({try:()=>rN.promises.readdir(e,t),catch:t=>rt("FileSystem","readDirectory")(t,[e])}),r8=e=>B.E2r((t,r)=>{try{rN.readFile(e,{signal:r},(r,n)=>{r?t(B.fJG(rt("FileSystem","readFile")(r,[e]))):t(B.PyW(n))})}catch(e){t(B.fJG(rD("readFile")(e)))}}),r9=(S=(0,B._r7)(rN.readlink,rt("FileSystem","readLink"),rD("readLink")),e=>S(e)),r4=(I=(0,B._r7)(rN.realpath,rt("FileSystem","realPath"),rD("realPath")),e=>I(e)),r7=($=(0,B._r7)(rN.rename,rt("FileSystem","rename"),rD("rename")),(e,t)=>$(e,t)),ne=e=>B.SvU({try:()=>({type:e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":e.isBlockDevice()?"BlockDevice":e.isCharacterDevice()?"CharacterDevice":e.isFIFO()?"FIFO":e.isSocket()?"Socket":"Unknown",mtime:ee.fromNullishOr(e.mtime),atime:ee.fromNullishOr(e.atime),birthtime:ee.fromNullishOr(e.birthtime),dev:rU(e.dev,"dev"),rdev:rF(e.rdev),ino:rF(e.ino),mode:rU(e.mode,"mode"),nlink:rF(e.nlink),uid:rF(e.uid),gid:rF(e.gid),size:Q.ee(e.size),blksize:void 0!==e.blksize?ee.some(Q.ee(e.blksize)):ee.none(),blocks:rF(e.blocks)}),catch:rD("stat")}),nt=(E=(0,B._r7)(rN.stat,rt("FileSystem","stat"),rD("stat")),e=>B.qIB(E(e,{bigint:!0}),ne)),nr=(O=(0,B._r7)(rN.symlink,rt("FileSystem","symlink"),rD("symlink")),(e,t)=>O(e,t)),nn=(C=(0,B._r7)(rN.truncate,rt("FileSystem","truncate"),rD("truncate")),(e,t)=>C(e,t)),ni=(T=(0,B._r7)(rN.utimes,rt("FileSystem","utime"),rD("utime")),(e,t,r)=>T(e,t,r)),na=(e,t,r)=>B.E2r((n,i)=>{try{rN.writeFile(e,t,{signal:i,flag:r?.flag,mode:r?.mode},t=>{t?n(B.fJG(rt("FileSystem","writeFile")(t,[e]))):n(B.rIH)})}catch(e){n(B.fJG(rD("writeFile")(e)))}}),ns=B.TjK(B.Nav(tD),e=>{let t;return t={access:rL,chmod:rJ,chown:rY,copy:rz,copyFile:rW,glob:rX,link:rq,makeDirectory:rG,makeTempDirectory:rH,makeTempDirectoryScoped:rZ,makeTempFile:r5,makeTempFileScoped:r3,open:r0,readDirectory:r6,readFile:r8,readLink:r9,realPath:r4,remove:rQ,rename:r7,stat:nt,symlink:nr,truncate:nn,utimes:ni,watch:(t,r)=>nt(t).pipe(B.TjK(n=>e.pipe(ee.flatMap(e=>e.register(t,n,r)),ee.getOrElse(()=>{let e,i;return tw((e=e=>B.Q56(B.OH5(()=>{let i="Directory"===n.type?t:rR.dirname(t),a=rN.watch(t,{recursive:r?.recursive??!1},(t,r)=>{if(r)switch(t){case"rename":return void B.MY7(B.tvg(nt(rR.resolve(i,r)),{onSuccess:t=>eE(e,{_tag:"Create",path:r}),onFailure:t=>eE(e,{_tag:"Remove",path:r})}));case"change":return void eO(e,{_tag:"Update",path:r})}});return a.on("error",r=>{eT(e,F.fJ(es({module:"FileSystem",_tag:"Unknown",method:"watch",pathOrDescriptor:t,cause:r})))}),a.on("close",()=>{eM(e)}),a}),e=>B.OH5(()=>e.close())),i=void 0,e3((t,r)=>B.TjK(e$({capacity:i?.bufferSize,strategy:i?.strategy}).pipe(B.Mim(e=>e0.U9(r,eA(e))),B.Mim(t=>B.ar0(e0.Gt(e(t),r),r))),eP))))}))),tE),writeFile:na},tR.of({...t,[tP]:tP,exists:e=>(0,z.Fs)(t.access(e),B.as(!0),B.KuX("PlatformError",e=>"NotFound"===e.reason._tag?B.PyW(!1):B.fJG(e))),readFileString:(e,r)=>B.qIB(t.readFile(e),e=>B.SvU({try:()=>new TextDecoder(r).decode(e),catch:e=>eo({module:"FileSystem",method:"readFileString",description:"invalid encoding",cause:e})})),stream:B.D9k(function*(e,r){let n=yield*t.open(e,{flag:"r"}),i=r?.offset===void 0?void 0:Q.bN(r.offset);i&&(yield*n.seek(i,"start"));let a=r?.bytesToRead===void 0?void 0:Q.bN(r.bytesToRead),s=BigInt(0),o=Number(BigInt(r?.chunkSize??65536)),l=n.readAlloc(o);return tw(e8(B.PyW(B.qIB(B.DYE(()=>void 0!==a&&a<=s?F.Vw():void 0!==a&&a-s<o?n.readAlloc(Number(a-s)):l),ee.match({onNone:()=>F.Vw(),onSome:e=>(s+=BigInt(e.length),B.PyW(K.of(e)))})))))},tE),sink:(e,r)=>(0,z.Fs)(t.open(e,{...r,flag:r?.flag??"w"}),B.TjK(e=>{let t,r;return t=t=>e.writeAll(t),r=B.jJl(e=>t(e),{discard:!0}),tm(e=>e.pipe(B.qIB(r),B.i4r({disableYield:!0}),em.m8(()=>tu)))}),tv),writeFileString:(e,r,n)=>B.qIB(B.SvU({try:()=>new TextEncoder().encode(r),catch:e=>eo({module:"FileSystem",method:"writeFileString",description:"could not encode string",cause:e})}),r=>t.writeFile(e,r,n))})}),no=(G.QZ(tR))(ns),nl=t("node:url"),nd=e=>({fromFileUrl:t=>B.SvU({try:()=>nl.fileURLToPath(t,{windows:e}),catch:e=>new en({module:"Path",method:"fromFileUrl",cause:e})}),toFileUrl:t=>B.SvU({try:()=>nl.pathToFileURL(t,{windows:e}),catch:e=>new en({module:"Path",method:"toFileUrl",cause:e})})});rR.posix,rR.win32;let nc=(G.Py(tF))({[tU]:tU,...rj,...nd(void 0)}),nu="~effect/Stdio",nf=Z.kl(nu),np=G.Py(nf,(M={args:B.OH5(()=>process.argv.slice(2)),stdinIsTerminal:B.OH5(()=>!0===process.stdin.isTTY),stdoutIsTerminal:B.OH5(()=>!0===process.stdout.isTTY),stdout:e=>rr({evaluate:()=>process.stdout,onError:e=>es({module:"Stdio",method:"stdout",_tag:"Unknown",cause:e}),endOnDone:e?.endOnDone??!1}),stderr:e=>rr({evaluate:()=>process.stderr,onError:e=>es({module:"Stdio",method:"stderr",_tag:"Unknown",cause:e}),endOnDone:e?.endOnDone??!1}),stdin:rc({evaluate:()=>process.stdin,onError:e=>es({module:"Stdio",method:"stdin",_tag:"Unknown",cause:e}),closeOnDone:!1})},{[nu]:nu,stdinIsTerminal:B.PyW(!1),stdoutIsTerminal:B.PyW(!1),...M})),nh={_tag:"Empty"},nm={_tag:"Closed"},ng={_A:z.D_,_E:z.D_};class ny{"~effect/RcRef"=ng;pipe(){return(0,ep.tT)(this,arguments)}state=nh;acquire;context;scope;idleTimeToLive;constructor(e,t,r,n){this.acquire=e,this.context=t,this.scope=r,this.idleTimeToLive=n}}let nv=(e,t,r)=>B.cfM(r(ra(t.fiber)),r=>{let n=t.acquired;return void 0!==n?L.N6(r)?nb(e,n):B.rIH:--t.awaiters>0||e.state!==t?B.rIH:(e.state=nh,rs(t.fiber))}),nb=(e,t)=>{if(t.refCount--,t.refCount>0)return B.rIH;let r=e.idleTimeToLive;return void 0===r||t.invalidated?(e.state===t&&(e.state=nh),e0.VN(t.scope,L.rI)):(H.MI(r)&&(t.fiber=B.FcF(n=>B.qIB(n(B.yy4(r)),()=>e.state===t&&0===t.refCount?(e.state=nh,e0.VN(t.scope,L.rI)):B.rIH)).pipe(B.yeE(B.OH5(()=>{t.fiber=void 0})),B.eJC(e.context),rl(e.scope))),B.rIH)},n_=e=>B.FcF(t=>B.qIB(B.z8E,r=>B.qIB(((e,t)=>{switch(e.state._tag){case"Closed":return B.GaK;case"Acquired":{let t=e.state;return t.refCount++,t.fiber?B.as(rs(t.fiber),t):B.PyW(t)}case"Acquiring":{let r=e.state;return r.awaiters++,nv(e,r,t)}case"Empty":{let r={_tag:"Acquiring",fiber:void 0,awaiters:1,acquired:void 0};e.state=r;let n=e0.LZ(),i=B.PpN(e.acquire,Z.WQ(e.context,e0.HG,n)).pipe(B.qIB(t=>{if(e.state!==r)return B.GaK;let i={_tag:"Acquired",value:t,scope:n,fiber:void 0,refCount:r.awaiters,invalidated:!1};return e.state=i,r.acquired=i,B.PyW(i)}),B.cfM(t=>L.oJ(t)?B.rIH:(e.state===r&&(e.state=nh),e0.VN(n,t))));return r.fiber=B.eJC(ro().context)(i),nv(e,r,t)}}})(e,t),t=>B.as(e0.a6(r,()=>nb(e,t)),t.value))));var nx=n(2718);let nw="~effect/Terminal",nk="~effect/Terminal/QuitError";class nS extends(nx.$DH("QuitError"))({_tag:nx.TcI("QuitError")}){[nk]=nk}let nI=Z.kl("effect/Terminal"),n$=t("node:readline"),nE=B.D9k(function*(e=nC){let t,r,n=process.stdin,i=process.stdout,a=yield*e$(),s=n.readableEnded,o=!1,l=()=>{s=!0,o||eM(a)};n.once("end",l),yield*B.U9h(()=>B.OH5(()=>n.off("end",l)));let d=yield*(t={acquire:B.Q56(B.OH5(()=>{let e=n$.createInterface({input:n,escapeCodeTimeout:50}),t=e=>eO(a,e),r=()=>{o=!1,eM(a)};return o=!0,n$.emitKeypressEvents(n,e),e.on("line",t),e.once("close",r),n.isTTY&&n.setRawMode(!0),{rl:e,onClose:r,onLine:t}}),({rl:e,onClose:t,onLine:r})=>B.OH5(()=>{o=!1,e.off("line",r),e.off("close",t),n.isTTY&&n.setRawMode(!1),e.close(),s&&eM(a)})),idleTimeToLive:"10 millis"},B.R6R(e=>{let r=e.context,n=Z.Jt(r,e0.HG),i=new ny(t.acquire,r,n,void 0!==t.idleTimeToLive?H.bN(t.idleTimeToLive):void 0);return B.as(e0.a6(n,()=>{let e=i.state;return(i.state=nm,"Acquired"===e._tag)?e0.VN(e.scope,L.rI):"Acquiring"===e._tag?rs(e.fiber):B.rIH}),i)})),c=B.OH5(()=>i.columns??0),u=B.OH5(()=>i.rows??0),f=B.JkU(function*(){let t=yield*e$(),r=(r,n)=>{let i={input:ee.fromUndefinedOr(r),key:{name:n.name??"",ctrl:!!n.ctrl,meta:!!n.meta,shift:!!n.shift}};eO(t,i),e(i)&&eM(t)},i=setInterval(()=>{},0x7fffffff),a=()=>{clearInterval(i),eM(t)};return yield*B.U9h(()=>B.OH5(()=>{clearInterval(i),n.off("keypress",r),n.off("end",a)})),n.on("keypress",r),s?a():(yield*n_(d),n.once("end",a)),t});return r={columns:c,rows:u,readInput:f,readLine:B.DYE(()=>ey.DYE(()=>{let e=eD(a);return void 0===e?ey.PyW(ee.none()):"Success"===e._tag?ey.PyW(ee.some(e.value)):ey.PyW(ee.none())}).pipe(B.qIB(ee.match({onNone:()=>B.P1j(B.hgn(n_(d),ej(a))),onSome:B.PyW})),B.xm_(()=>new nS({})))),display:e=>B.rfi(B.E2r(t=>{i.write(e,e=>eh.uy(e)?t(B.rIH):t(B.fJG(eo({module:"Terminal",method:"display",description:"Failed to write prompt to stdout",cause:e}))))}))},nI.of({...r,[nw]:nw})}),nO=G.QZ(nI,nE(nC));function nC(e){return e.key.ctrl&&("c"===e.key.name||"d"===e.key.name)}let nT=G.S5(rb,G.Um(no,rM,nc,np,nO));var nM=n(3178);class nA extends nx.rNF()("CliFilesystemError",{cause:nx.kld(),operation:nx.QfV,path:nx.QfV,message:nx.QfV}){}class nN extends nx.rNF()("CliInputError",{code:nx.xCb(["input_read_failed","invalid_json","interactive_stdin"]),message:nx.QfV,hint:nx.QfV}){}class nP extends nx.rNF()("CliValidationError",{message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nR extends nx.rNF()("CliBuildError",{status:nx.QfV,message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nj extends nx.rNF()("CliGenerationError",{code:nx.xCb(["provider_failure","generation_timeout","malformed_output","invalid_generated_document","unsupported_diagram_type"]),message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nD extends nx.rNF()("CliCanvasError",{code:nx.xCb(["canvas_rejected","canvas_timeout","endpoint_failure","malformed_response","network_failure"]),message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nU extends nx.rNF()("CliInteractiveError",{code:nx.xCb(["cancelled","prompt_failed"]),message:nx.QfV,hint:nx.QfV}){}class nF extends nx.rNF()("CliStorageError",{code:nx.xCb(["diagram_not_found","diagram_already_exists","diagram_busy","detached_edit","patch_source_unavailable","patch_conflict","replacement_conflict","restore_conflict","revision_not_found","corrupt_revision","corrupt_record","unsafe_storage_entry","storage_commit_failed"]),diagramId:nx.Qrq(nx.QfV),message:nx.QfV,hint:nx.QfV}){}class nB extends nx.rNF()("CliShareError",{code:nx.xCb(["invalid_share_link","unsupported_scene","share_payload_too_large","share_crypto_failed","share_transport_failed","share_timeout","share_api_changed","share_link_unavailable"]),message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nL extends nx.rNF()("CliExportError",{code:nx.xCb(["format_unavailable","invalid_destination","render_failed","invalid_render_artifact","render_limit_exceeded","unsupported_render_glyph","rasterization_failed","export_write_failed"]),diagramId:nx.Qrq(nx.QfV),storagePath:nx.Qrq(nx.QfV),recoveryCommand:nx.Qrq(nx.QfV),details:nx.Qrq(nx.O31(nx.QfV)),format:nx.QfV,message:nx.QfV,hint:nx.QfV}){}let nz=["scene","excalidraw"],nW=B.fn("sketchi.cli.codeMode.with")(function*(e,t,r){return yield*r({artifactFormats:[...nz],inlineArtifacts:[...nz]}).pipe(B.PfK(nM.Ov,e),B.PfK(nM.UA,t))});function nJ(e,t){let r=e.issues[0],n=r?.message??`Code Mode${"patch"===t?" patch":""} failed with ${e.status}.`,i=r?.hint??("patch"===t?"Repair the patch request and retry.":"Repair the document and retry."),a=e.issues.map(e=>`${e.code}${e.ref?.path?` (${e.ref.path})`:""}: ${e.message}`);return("patch"===t?["invalid_input","target_not_found","unsupported_operation","connectivity_changed"]:["invalid_input","invalid_flowchart","invalid_mindmap","invalid_sequence","quality_failed"]).includes(e.status)?nP.make({message:n,hint:i,details:a}):"storage_failed"===e.status?nF.make({code:"storage_commit_failed",message:n,hint:i}):nR.make({status:e.status,message:n,hint:i,details:a})}let nY=B.fn("sketchi.cli.codeMode.decodeArtifacts")(function*(e,t){let r="patch"===t?"patched ":"",n="patch"===t?"Inspect the Code Mode patch/export boundary.":"Inspect the Code Mode build/export boundary.",i=n=>{let i=e.formats.find(e=>e.format===n);return i?.inline!==void 0?B.PyW(i.inline):B.fJG(nR.make({status:"missing_inline_artifact",message:`Code Mode did not return the ${r}${n} artifact inline.`,hint:"patch"===t?"Retry the offline patch with the required artifact formats.":"Rebuild the document with the required offline artifact formats.",details:[n]}))},a=e.formats.find(e=>"scene"===e.format),s="export"!==t||a?nM.Uh.safeParse((yield*i("scene"))):void 0;if(s&&!s.success)return yield*nR.make({status:"invalid_scene_artifact",message:`Code Mode returned an invalid ${r}scene artifact.`,hint:n,details:s.error.issues.map(e=>e.message)});let o=nM.yE.safeParse((yield*i("excalidraw")));return o.success?{...s?.success?{scene:s.data}:{},excalidraw:o.data}:yield*nR.make({status:"invalid_excalidraw_artifact",message:`Code Mode returned an invalid ${r}Excalidraw artifact.`,hint:n,details:o.error.issues.map(e=>e.message)})});var nX=n(7086);function nq(e){return"string"==typeof e||"number"==typeof e||"symbol"==typeof e}let nG=nX.ID(),nV=nx._Re(nM.Ky,{errors:"all"}),nH=nx._Re(nM.e5,{errors:"all"}),nK=nx._Re(nM.nu,{errors:"all"}),nQ=nx._Re(nM.y1,{errors:"all"});function nZ(e){return nP.make({message:"The canonical diagram document is invalid.",hint:'Use {"type":"flowchart","spec":...}, {"type":"mindmap","spec":...}, or {"type":"sequence","spec":...}.',details:e})}function n0(e){return nG(e).issues.map(e=>{var t;let r=(e.path??[]).flatMap(e=>{let t=nq(e)?e:null!==e&&"object"==typeof e&&"key"in e&&nq(e.key)?e.key:void 0;return void 0===t?[]:[t]});return`${0===(t=["spec",...r]).length?"document":t.map(e=>"number"==typeof e?`[${e}]`:String(e)).join(".")}: ${e.message}`})}function n1(e){if(!("object"!=typeof e||null===e||Array.isArray(e))&&"type"in e&&"spec"in e)return{type:e.type,spec:e.spec}}let n2=B.fn("sketchi.cli.document.decodeCanonical")(function*(e){let t=n1(e);return t?"flowchart"===t.type?{type:"flowchart",spec:yield*nV(t.spec).pipe(B.xm_(e=>nZ(n0(e.issue))))}:"mindmap"===t.type?{type:"mindmap",spec:yield*nH(t.spec).pipe(B.xm_(e=>nZ(n0(e.issue))))}:"sequence"===t.type?{type:"sequence",spec:yield*nK(t.spec).pipe(B.xm_(e=>nZ(n0(e.issue))))}:yield*nZ(['document.type: Expected "flowchart", "mindmap", or "sequence".']):yield*nZ(["document: Expected an object with type and spec."])}),n5=B.fn("sketchi.cli.document.parseJson")(function*(e){let t=yield*B.SvU({try:()=>JSON.parse(e),catch:()=>nN.make({code:"invalid_json",message:"The input is not valid JSON.",hint:"Pass one complete canonical document object."})});return yield*n2(t)}),n3=B.fn("sketchi.cli.document.decodeStored")(function*(e){let t=n1(e);return t?.type!=="canvas"?yield*n2(e):{type:"canvas",spec:yield*nQ(t.spec).pipe(B.xm_(e=>nZ(n0(e.issue))))}});function n6(e){return`${JSON.stringify(e,null,2)}
3
- `}function n8(e){let t=e.spec.id?.trim();return t||e.spec.title.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||`sketchi-${e.type}`}function n9(e){return/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(e)?B.PyW(e):B.fJG(nP.make({message:`Diagram id "${e}" is not safe for local storage.`,hint:"Use 1-128 ASCII letters, digits, dots, underscores, or hyphens; start with a letter or digit.",details:["spec.id"]}))}class n4 extends Z.kl()("@sketchi/cli/DiagramBuilder"){}let n7=G.QZ(n4,B.JkU(function*(){let e=yield*nM.Ov,t=yield*nM.UA;return{build:B.fn("sketchi.cli.diagram.build")(function*(r){let n=yield*nW(e,t,e=>"flowchart"===r.type?(0,nM.XV)({spec:r.spec,options:e}):"mindmap"===r.type?(0,nM.r8)({spec:r.spec,options:e}):(0,nM.rC)({spec:r.spec,options:e}));if(!n.ok)return yield*nJ(n,"build");let i=yield*n9(n8(r)),{scene:a,excalidraw:s}=yield*nY(n.artifact,"build");return{id:i,type:r.type,title:r.spec.title,document:r,scene:a,excalidraw:s}})}})),ie=t("node:fs/promises");class it extends Z.kl()("@sketchi/cli/LocalFileSystem"){}function ir(e,t,r){return nA.make({cause:r,operation:e,path:t,message:`Filesystem ${e} failed for ${t}.`})}function ii(e,t){return"object"==typeof e&&null!==e&&"code"in e&&e.code===t}function ia(e){return e.reason.cause??e}let is=G.QZ(it,B.TjK(tR,function(e){let t=B.fn("sketchi.cli.fs.kind")(function*(t){let r=yield*e.readLink(t).pipe(B.Ket);if("Success"===r._tag)return"symbolic-link";let n=ia(r.failure);return ii(n,"ENOENT")?"missing":ii(n,"ELOOP")?"symbolic-link":ii(n,"EINVAL")?yield*e.stat(t).pipe(B.TjK(e=>"File"===e.type?"file":"Directory"===e.type?"directory":"SymbolicLink"===e.type?"symbolic-link":"other"),B.MfU(e=>{let r=ia(e);return ii(r,"ENOENT")?B.PyW("missing"):ii(r,"ELOOP")?B.PyW("symbolic-link"):B.fJG(ir("stat",t,r))})):yield*ir("stat",t,n)}),r=(e,t)=>r=>ir(e,t,ia(r));return{makeDirectory:(t,n=!1)=>e.makeDirectory(t,{recursive:n}).pipe(B.xm_(r("make-directory",t))),tryWriteText:(e,t)=>B.$mh({try:async r=>{try{let n=await (0,ie.open)(e,rN.constants.O_WRONLY|rN.constants.O_CREAT|rN.constants.O_EXCL|rN.constants.O_NOFOLLOW,384);try{await n.writeFile(t,{encoding:"utf8",signal:r}),await n.sync()}finally{await n.close()}return!0}catch(e){if(ii(e,"EEXIST"))return!1;throw e}},catch:t=>ir("write-exclusive",e,t)}),tryLinkFile:(t,r)=>e.link(t,r).pipe(B.as(!0),B.MfU(e=>{let n=ia(e);return ii(n,"EEXIST")||ii(n,"ENOENT")?B.PyW(!1):B.fJG(ir("link-exclusive",`${t} -> ${r}`,n))})),makeTempDirectory:(t,n)=>e.makeTempDirectory({directory:t,prefix:n}).pipe(B.xm_(r("make-temp-directory",t))),list:n=>e.readDirectory(n).pipe(B.xm_(r("read-directory",n)),B.qIB(e=>B.jJl(e,e=>t((0,rR.join)(n,e)).pipe(B.TjK(t=>"missing"===t?[]:[{name:e,kind:t}]))).pipe(B.TjK(e=>e.flat())))),kind:t,realPath:t=>e.realPath(t).pipe(B.xm_(r("resolve",t))),readText:e=>B.$mh({try:async t=>{let r=await (0,ie.open)(e,rN.constants.O_RDONLY|rN.constants.O_NOFOLLOW);try{return await r.readFile({encoding:"utf8",signal:t})}finally{await r.close()}},catch:t=>ir("read",e,t)}),readBytes:e=>B.$mh({try:async t=>{let r=await (0,ie.open)(e,rN.constants.O_RDONLY|rN.constants.O_NOFOLLOW);try{return new Uint8Array(await r.readFile({signal:t}))}finally{await r.close()}},catch:t=>ir("read",e,t)}),writeText:(e,t,r=!1)=>B.$mh({try:async n=>{let i=rN.constants.O_WRONLY|rN.constants.O_CREAT|rN.constants.O_NOFOLLOW|(r?rN.constants.O_TRUNC:rN.constants.O_EXCL),a=await (0,ie.open)(e,i,384);try{await a.writeFile(t,{encoding:"utf8",signal:n}),await a.sync()}finally{await a.close()}},catch:t=>ir("write",e,t)}),writeBytes:(e,t,r=!1)=>B.$mh({try:async n=>{let i=rN.constants.O_WRONLY|rN.constants.O_CREAT|rN.constants.O_NOFOLLOW|(r?rN.constants.O_TRUNC:rN.constants.O_EXCL),a=await (0,ie.open)(e,i,384);try{await a.writeFile(t,{signal:n}),await a.sync()}finally{await a.close()}},catch:t=>ir("write",e,t)}),rename:(t,n)=>e.rename(t,n).pipe(B.xm_(r("rename",`${t} -> ${n}`))),tryRenameDirectory:(r,n)=>e.rename(r,n).pipe(B.as(!0),B.MfU(e=>B.JkU(function*(){let i=ia(e);return!(ii(i,"EEXIST")||ii(i,"ENOTEMPTY")||ii(i,"EPERM")&&(yield*t(n).pipe(B.MfU(()=>B.PyW("missing"))))==="directory")&&(yield*ir("rename-exclusive-directory",`${r} -> ${n}`,i))}))),removeFile:t=>e.remove(t).pipe(B.as(!0),B.MfU(e=>{let r=ia(e);return ii(r,"ENOENT")?B.PyW(!1):B.fJG(ir("remove-file",t,r))})),remove:t=>e.remove(t,{recursive:!0,force:!0}).pipe(B.xm_(r("remove",t)))}})),io=nx._kM({operations:nM.x3.fields.operations,options:nM.x3.fields.options,intent:nM.x3.fields.intent});function il(e,t){return nP.make({message:e,hint:"Provide operations and optional options or intent only.",details:t})}let id=B.fn("sketchi.cli.patch.decodeInput")(function*(e){if("object"!=typeof e||null===e||Array.isArray(e))return yield*il("The diagram patch request is invalid.",["patch: Expected an object."]);if("source"in e)return yield*il("The diagram patch request cannot supply source.",["source: The CLI binds the stored scene."]);if("requestId"in e)return yield*il("The diagram patch request cannot supply requestId.",["requestId: The CLI owns the patch request id."]);let t=(0,nM.ie)(io,e);return t.success?{operations:t.data.operations,...t.data.options?{options:t.data.options}:{},...t.data.intent?{intent:t.data.intent}:{}}:yield*il("The diagram patch request is invalid.",t.error.issues.map(e=>e.message))}),ic=B.fn("sketchi.cli.patch.parseJson")(function*(e){let t=yield*B.SvU({try:()=>JSON.parse(e),catch:()=>nN.make({code:"invalid_json",message:"The patch input is not valid JSON.",hint:"Pass one complete diagram patch request object."})});return yield*id(t)});class iu extends Z.kl()("@sketchi/cli/DiagramPatcher"){}let ip=G.QZ(iu,B.JkU(function*(){let e=yield*nM.Ov,t=yield*nM.UA;return{patch:B.fn("sketchi.cli.diagram.patch")(function*(r,n,i){let a=yield*nW(e,t,e=>(0,nM.OF)({requestId:i,source:{scene:r},operations:n.operations,options:{...n.options,...e},...n.intent?{intent:n.intent}:{}}));if(!a.ok)return yield*nJ(a,"patch");let{scene:s,excalidraw:o}=yield*nY(a.artifact,"patch");return{scene:s,excalidraw:o}})}}));class ih extends Z.kl()("@sketchi/cli/InputReader"){}function im(e,t){return B.SvU({try:()=>new TextDecoder("utf-8",{fatal:!0}).decode(e),catch:()=>nN.make({code:"input_read_failed",message:"stdin"===t?"Standard input is not valid UTF-8.":"The input file is not valid UTF-8.",hint:"Provide one complete UTF-8 JSON document and retry."})})}let ig=function(e=()=>!0===process.stdin.isTTY){return G.QZ(ih,B.JkU(function*(){let t=yield*it,r=yield*nf;return{read:B.fn("sketchi.cli.input.read")(function*(n,i={content:"JSON document"}){if("InlineJson"===n._tag)return n.value;if("-"!==n.path){let e=yield*t.readBytes(n.path).pipe(B.xm_(()=>nN.make({code:"input_read_failed",message:`Unable to read input file ${n.path}.`,hint:"Check the path and file permissions, then retry."})));return yield*im(e,"file")}if(e())return yield*nN.make({code:"interactive_stdin",message:`${i.content} input requires piped or redirected stdin.`,hint:"share link"===i.content?"Pipe one complete Excalidraw share link to --link -.":"Pipe one JSON document, or use --file PATH / --json VALUE."});let a=yield*tN(r.stdin,()=>({chunks:[],size:0}),(e,t)=>{let r=t.byteLength+e.size;return void 0!==i.maxBytes&&r>i.maxBytes?B.fJG(nN.make({code:"input_read_failed",message:`Standard input exceeds the ${String(i.maxBytes)} byte limit for a ${i.content}.`,hint:`Pipe one complete ${i.content} within the documented limit.`})):B.PyW({chunks:[...e.chunks,t],size:r})}).pipe(B.xm_(e=>e instanceof nN?e:nN.make({code:"input_read_failed",message:`Unable to read the ${i.content} from stdin.`,hint:`Pipe one complete UTF-8 ${i.content} and retry.`})));return yield*im(function(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let n of e)t.set(n,r),r+=n.byteLength;return t}(a.chunks),"stdin")})}}))}(),iy=B.fn("sketchi.cli.input.readDocument")(function*(e){let t=yield*ih,r=yield*t.read(e);return yield*n5(r)}),iv=B.fn("sketchi.cli.input.readPatch")(function*(e){let t=yield*ih,r=yield*t.read(e,{content:"patch request"});return yield*ic(r)});var ib=n(6771);let i_=1,ix="manifest.json",iw="document.json",ik="scene.json",iS="diagram.excalidraw",iI="diagram.png",i$="revisions";class iE extends nx.Xsx("DiagramRecordManifest")({schemaVersion:nx.uSQ(i_),id:nx.QfV,type:nx.xCb(["canvas","flowchart","mindmap","sequence"]),title:nx.QfV,revision:nx.Aiz.check(nx.yJO(0)),authority:nx.xCb(["canonical","patched","detached"]).pipe(nx.E$i(B.PyW("canonical"))),formats:nx.O31(nx.xCb(["scene","excalidraw","png"]))}){}function iO(e){return{id:e.manifest.id,type:e.manifest.type,title:e.manifest.title,revision:e.manifest.revision,formats:e.manifest.formats,authority:e.authority,documentAuthoritative:"canonical"===e.authority}}function iC(e){return String(e).padStart(6,"0")}let iT=t("node:zlib");var iM=n(8689),iA=n(5030);let iN="https://json.excalidraw.com/api/v2/",iP=["rectangle","ellipse","diamond","arrow","line","freedraw","text"],iR=new Set(iP),ij=new TextEncoder,iD=new TextDecoder("utf-8",{fatal:!0}),iU=ij.encode(JSON.stringify({version:2,compression:"pako@1",encryption:"AES-GCM"}));function iF(e,t,r,n=[]){return nB.make({code:e,message:t,hint:r,details:n})}function iB(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function iL(e){return"number"==typeof e&&Number.isFinite(e)}function iz(e,t,r){new DataView(e.buffer,e.byteOffset,e.byteLength).setUint32(t,r)}function iW(e,t){if(t+4>e.byteLength)throw Error("truncated chunk header");return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(t)}function iJ(e,t){if(e.byteLength<4+4*t||1!==iW(e,0))throw Error("unsupported chunk format");let r=[],n=4;for(let i=0;i<t;i+=1){let t=iW(e,n),i=(n+=4)+t;if(i>e.byteLength)throw Error("truncated chunk");r.push(e.subarray(n,i)),n=i}if(n!==e.byteLength)throw Error("unexpected trailing chunk");return r}function iY(e){if(!/^[A-Za-z0-9_-]{22}$/.test(e))throw Error("invalid AES key encoding");let t=Buffer.from(e,"base64url");if(16!==t.byteLength)throw Error("invalid AES key length");return t}function iX(e,t){return crypto.subtle.importKey("raw",Uint8Array.from(iY(e)),{name:"AES-GCM",length:128},!1,[t])}function iq(e){if(!iB(e)||"excalidraw"!==e.type||!iL(e.version)||"string"!=typeof e.source||!Array.isArray(e.elements)||!iB(e.appState)||!(void 0===e.files||iB(e.files)))throw Error("invalid Excalidraw artifact shape");return{type:e.type,version:e.version,source:e.source,elements:e.elements,appState:e.appState,files:e.files??{}}}function iG(e,t){return"string"!=typeof e||!t.has(e)}function iV(e,t){if("number"==typeof e)return Number.isFinite(e)?void 0:`${t} must be finite`;if(Array.isArray(e))for(let r of e){let e=iV(r,`${t} item`);if(e)return e}else if(iB(e))for(let r of Object.values(e)){let e=iV(r,`${t} property`);if(e)return e}}function iH(e){return B.SvU({try:()=>{let t=iq(e);if(iB(e)&&"libraryItems"in e)throw Error("Excalidraw library state is unsupported");if(t.elements.length>1e4)throw Error("element count exceeds 10000");if(Object.keys(t.files).length>0)throw Error("binary files are unsupported");let r=new Set;for(let[e,n]of t.elements.entries()){if(!iB(n)||"string"!=typeof n.id)throw Error(`elements[${String(e)}].id is invalid`);if(r.has(n.id))throw Error(`elements[${String(e)}].id is duplicated`);r.add(n.id)}for(let[e,n]of t.elements.entries()){let t=function(e,t,r){let n=`elements[${String(t)}]`;if(!iB(e)||"string"!=typeof e.id||0===e.id.length||"string"!=typeof e.type)return`elements[${String(t)}] is not an Excalidraw element`;if(!iR.has(e.type))return`${n}.type is unsupported`;if("link"in e&&null!==e.link&&void 0!==e.link||"fileId"in e)return`${n} contains an external resource`;let i=iV(e,n);if(i)return i;for(let t of["x","y","width","height","angle"])if(!iL(e[t]))return`${n}.${t} must be finite`;if("text"===e.type){if(5!==e.fontFamily)return`${n}.fontFamily must be ${String(5)}`;if("string"!=typeof e.text)return`${n}.text is invalid`}if(["arrow","line","freedraw"].includes(e.type)&&(!Array.isArray(e.points)||e.points.some(e=>!Array.isArray(e)||e.length<2||!iL(e[0])||!iL(e[1]))))return`${n}.points contains invalid geometry`;for(let t of["containerId","frameId"])if(null!==e[t]&&void 0!==e[t]&&iG(e[t],r))return`${n}.${t} is an invalid element reference`;for(let t of["startBinding","endBinding"]){let i=e[t];if(null!=i&&(!iB(i)||iG(i.elementId,r)))return`${n}.${t} is an invalid element binding`}let a=e.boundElements;if(null!=a&&(!Array.isArray(a)||a.some(e=>!iB(e)||iG(e.id,r))))return`${n}.boundElements contains an invalid element reference`}(n,e,r);if(t)throw Error(t)}let n=(0,iA.Gd)(t.elements);if(n)throw Error(n);let i=function(e){if("viewBackgroundColor"in e&&"string"!=typeof e.viewBackgroundColor)return"appState.viewBackgroundColor must be a string";if("gridModeEnabled"in e&&"boolean"!=typeof e.gridModeEnabled)return"appState.gridModeEnabled must be boolean";for(let t of["gridSize","gridStep"])if(t in e&&null!==e[t]&&!iL(e[t]))return`appState.${t} must be finite or null`;if("lockedMultiSelections"in e){let t=e.lockedMultiSelections;if(!iB(t))return"appState.lockedMultiSelections must be an object";for(let[e,r]of Object.entries(t))if(0===e.length||!0!==r)return"appState.lockedMultiSelections contains an invalid lock entry"}return iV(e,"appState")}(t.appState);if(i)throw Error(i);return e},catch:e=>iF("unsupported_scene","The Excalidraw scene is unsupported by share/pull v1.",`Use only ${iP.join(", ")} elements, Excalifont fontFamily ${String(5)}, and no files or images.`,[e instanceof Error?e.message:"invalid scene"])})}function iK(e){let t=new Uint8Array(4);return iz(t,0,e),t}let iQ=nx._kM({buffer:nx.SEl,engine:nx._kM({bytesWritten:nx.wNn})});function iZ(e){let t=0xffffffff;for(let r of e){t^=r;for(let e=0;e<8;e+=1)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}function i0(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}let i1=[[0,0,8,8],[4,0,8,8],[0,4,4,8],[2,0,4,4],[0,2,2,4],[1,0,2,2],[0,1,1,2]];function i2(e,t,r){return e<=t?0:Math.ceil((e-t)/r)}function i5(e){let t,r,n,i,a,s=[137,80,78,71,13,10,26,10];if(e.byteLength<33||s.some((t,r)=>e[r]!==t))return!1;let o=s.length,l=0,d=!1,c=!1,u=!1,f=[];for(;o+12<=e.byteLength;){let s=i0(e,o),p=o+12+s;if(p>e.byteLength)break;let h=o+4,m=e.subarray(h,h+4),g=e=>e>=65&&e<=90||e>=97&&e<=122;if(4!==m.byteLength||!m.every(g)||(32&m[2])!=0)break;let y=String.fromCharCode(...m);if(0===l&&("IHDR"!==y||13!==s))break;if("IHDR"===y){if(0!==l||13!==s)return!1;t=i0(e,o+8),r=i0(e,o+12),i=e[o+16],n=e[o+17],a=e[o+20];let d={0:[1,2,4,8,16],2:[8,16],3:[1,2,4,8],4:[8,16],6:[8,16]};if(0===t||0===r||t>0x7fffffff||r>0x7fffffff||void 0===n||void 0===i||!d[n]?.includes(i)||0!==e[o+18]||0!==e[o+19]||![0,1].includes(a??-1))break}else if("PLTE"===y){if(d||c||0===s||s%3!=0||s>768||0===n||4===n||3===n&&void 0!==i&&s/3>2**i)return!1;d=!0}else if("IDAT"===y){if(u||3===n&&!d)return!1;c=!0,f.push(e.subarray(o+8,o+8+s))}else if("IEND"===y){if(0!==s||!c||3===n&&!d)break}else{c&&(u=!0);let t=e[h];if(void 0===t||(32&t)==0)break}let v=i0(e,o+8+s);if(iZ(e.subarray(h,o+8+s))!==v)break;if(o=p,l+=1,"IEND"===y)return o===e.byteLength&&void 0!==t&&void 0!==r&&void 0!==i&&void 0!==n&&void 0!==a&&function(e,t,r,n,i,a){let s={0:1,2:3,3:1,4:2,6:4}[i];if(void 0===s)return!1;let o=function(e,t,r,n){let i=[],a=0;for(let[s,o,l,d]of 0===n?[[0,0,1,1]]:i1){let n=i2(e,s,l),c=i2(t,o,d);if(0===n||0===c)continue;let u=Math.ceil(n*r/8)+1;if(u>0x1000000-a||c>Math.floor((0x1000000-a)/u))return null;a+=c*u,i.push({rows:c,rowBytes:u})}return i}(t,r,s*n,a);if(null===o)return!1;let l=o.reduce((e,t)=>e+t.rows*t.rowBytes,0);try{let t=function(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let n of e)t.set(n,r),r+=n.byteLength;return t}(e),r=(0,iT.inflateSync)(t,{info:!0,maxOutputLength:0x1000000}),n=nx.svK(iQ)(r);if(n.engine.bytesWritten!==t.byteLength)return!1;let i=n.buffer;if(i.byteLength!==l)return!1;let a=0;for(let e of o)for(let t=0;t<e.rows;t+=1){if((i[a]??5)>4)return!1;a+=e.rowBytes}return a===i.byteLength}catch{return!1}}(f,t,r,i,n,a)}return!1}class i3 extends Z.kl()("@sketchi/cli/StorageRoot"){}class i6 extends Z.kl()("@sketchi/cli/DiagramStore"){}let i8=".locks",i9="free.",i4="owner.",i7=".owner-candidate.",ae=".json",at="recovery",ar=".backup.",an=`.stage.${String(process.pid)}.`,ai=ib.ji("10 millis").pipe(ib.jB({times:50})),aa=G.Py(i3,{path:(0,rR.join)((0,rP.homedir)(),".sketchi","diagrams")});function as(e,t,r,n){return nF.make({code:e,message:t,hint:r,...n?{diagramId:n}:{}})}function ao(e){return Buffer.from(e,"utf8").toString("base64url")}function al(e,t){return e<t?-1:+(e>t)}function ad(e,t){let r=e.replace(/(?:\/|\.json)$/u,"").replace(/^0+/u,""),n=t.replace(/(?:\/|\.json)$/u,"").replace(/^0+/u,""),i=r.length-n.length;return 0!==i?i:al(r,n)||al(e,t)}function ac(e,t){let r="detached"===e?["excalidraw"]:["scene","excalidraw"];return t?[...r,"png"]:r}function au(e){if(!Number.isSafeInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(e){return"object"==typeof e&&null!==e&&"code"in e&&"EPERM"===e.code}}function af(e,t){return"object"==typeof e.cause&&null!==e.cause&&"code"in e.cause&&e.cause.code===t}function ap(e,t){return(0,rR.join)(e,t)}function ah(e){switch(e){case"scene":return ik;case"excalidraw":return iS;case"png":return iI}}function am(e,t){return as("unsafe_storage_entry",`Unsafe local storage entry at ${e}.`,"Replace symbolic links or special files with ordinary Sketchi record files.",t)}let ag=G.QZ(i6,B.JkU(function*(){let e=yield*it,t=yield*i3,r=B.fn("sketchi.cli.storage.ensureOwnedDirectory")(function*(t){let r=yield*e.kind(t);if("missing"===r&&(yield*e.makeDirectory(t).pipe(B.MfU(e=>af(e,"EEXIST")?B.rIH:B.fJG(e))),r=yield*e.kind(t)),"directory"!==r)return yield*am(t)}),n=B.fn("sketchi.cli.storage.ensureRoot")(function*(){yield*r((0,rR.dirname)(t.path)),yield*r(t.path),yield*r((0,rR.join)(t.path,i8))}),i=B.fn("sketchi.cli.storage.assertSafeTree")(function*(t,r){for(let n of yield*e.list(t)){let e=(0,rR.join)(t,n.name);if("symbolic-link"===n.kind||"other"===n.kind)return yield*am(e,r);"directory"===n.kind&&(yield*i(e,r))}}),a=B.fn("sketchi.cli.storage.recoverStages")(function*(r){for(let n of[...r??(yield*e.list(t.path))].sort((e,t)=>al(e.name,t.name))){if(!n.name.startsWith(".stage."))continue;let r=function(e){let t=Number(e.split(".").at(-2));return Number.isSafeInteger(t)?t:void 0}(n.name);void 0!==r&&au(r)||(yield*e.remove((0,rR.join)(t.path,n.name)))}}),s=B.fn("sketchi.cli.storage.recoverRecordTransactions")(function*(r){let n=`${ar}${ao(r)}.`;for(let i of[...yield*e.list(t.path)].filter(e=>e.name.startsWith(n)).sort((e,t)=>al(e.name,t.name))){let n=(0,rR.join)(t.path,i.name),a=ap(t.path,r);"missing"===(yield*e.kind(a))?yield*e.rename(n,a):yield*e.remove(n)}}),o=e=>(0,rR.join)(t.path,i8,`${ao(e)}.lock`),l=B.fn("sketchi.cli.storage.initializeLockDirectory")(function*(r){let n=o(r),i=yield*e.kind(n);if("directory"===i)return n;if("missing"!==i)return yield*am(n,r);let a=(0,rR.join)(t.path,i8);return yield*B.jGc(e.makeTempDirectory(a,`.init.${ao(r)}.`),t=>B.JkU(function*(){let i=crypto.randomUUID();return(yield*e.writeText((0,rR.join)(t,`${i9}${i}${ae}`),n6({token:i})),(yield*e.tryRenameDirectory(t,n))||"directory"===(yield*e.kind(n)))?n:yield*am(n,r)}),t=>e.remove(t))}),d=e=>as("diagram_busy",`Diagram "${e}" is being changed by another Sketchi process.`,"Wait for that command to finish, then retry.",e),c=B.fn("sketchi.cli.storage.readLockEntries")(function*(t,r){let n=[...yield*e.list(t)].sort((e,t)=>al(e.name,t.name)),i=[];for(let a of n){let n=(0,rR.join)(t,a.name);if("file"!==a.kind)return yield*am(n,r);let s=function(e){if(!e.startsWith(i9)||!e.endsWith(ae))return;let t=e.slice(i9.length,-ae.length).split(".");if(1!==t.length&&2!==t.length||t.some(e=>!/^[a-zA-Z0-9_-]+$/.test(e)))return;let[r,n]=t;if(r)return{token:r,...n?{releasedOwnerToken:n}:{}}}(a.name);if(s){i.push({name:a.name,path:n,state:"free",token:s.token,...s.releasedOwnerToken?{releasedOwnerToken:s.releasedOwnerToken}:{}});continue}if(a.name.startsWith(i9))return yield*am(n,r);let o=function(e){if(!e.startsWith(i7)||!e.endsWith(ae))return;let t=e.slice(i7.length,-ae.length);return/^[a-zA-Z0-9_-]+$/.test(t)?t:void 0}(a.name);if(o){i.push({name:a.name,path:n,state:"unpublished-owner",token:o});continue}if(a.name.startsWith(i7)||!a.name.startsWith(i4)||!a.name.endsWith(ae))return yield*am(n,r);let l=function(e){try{let t=JSON.parse(e);return"object"==typeof t&&null!==t&&"pid"in t&&"number"==typeof t.pid&&"token"in t&&"string"==typeof t.token&&t.token.length>0?{pid:t.pid,token:t.token}:void 0}catch{return}}((yield*e.readText(n).pipe(B.xm_(e=>af(e,"ENOENT")?d(r):e))));if(!l)return yield*d(r);if(a.name!==`${i4}${l.token}${ae}`)return yield*am(n,r);i.push({name:a.name,path:n,token:l.token,state:au(l.pid)?"live-owner":"stale-owner"})}return i}),u=B.fn("sketchi.cli.storage.acquireLockOnce")(function*(t){let r=yield*l(t),n=yield*c(r,t),i=new Set(n.flatMap(e=>e.releasedOwnerToken?[e.releasedOwnerToken]:[]));if(n.some(e=>"live-owner"===e.state&&!i.has(e.token)))return yield*d(t);let a=n.find(e=>"free"===e.state)??n.find(e=>"stale-owner"===e.state);if(!a){let n=(0,rR.join)(r,`${i9}${at}${ae}`);if(!(yield*e.tryWriteText(n,n6({token:at}))))return yield*d(t);a={name:`${i9}${at}${ae}`,path:n,state:"free",token:at}}let s=crypto.randomUUID(),o=(0,rR.join)(r,`${i4}${s}${ae}`),u=(0,rR.join)(r,`${i7}${s}${ae}`);return yield*B.rfi(B.jGc(B.PyW(u),()=>B.JkU(function*(){if(yield*e.writeText(u,n6({pid:process.pid,token:s})),!(yield*e.tryLinkFile(u,o)))return yield*d(t);if(!(yield*e.removeFile(a.path).pipe(B.MfU(t=>e.removeFile(o).pipe(B.hgn(B.fJG(t)))))))return yield*e.removeFile(o),yield*d(t);for(let t of n)t.path!==a.path&&(yield*e.removeFile(t.path).pipe(B.MfU(()=>B.rIH)));return{directory:r,ownerPath:o,token:s}}),t=>e.removeFile(t).pipe(B.MfU(()=>B.rIH))))}),f=B.fn("sketchi.cli.storage.releaseLock")(function*(t,r){let n=crypto.randomUUID(),i=(0,rR.join)(r.directory,`${i9}${n}.${r.token}${ae}`),a=n6({token:n,releasedOwnerToken:r.token});if(!(yield*e.tryWriteText(i,a).pipe(B.MfU(()=>e.kind(i).pipe(B.TjK(e=>"file"===e))),B.MfU(()=>B.PyW(!1))))){if(yield*e.removeFile(r.ownerPath))return;return yield*as("storage_commit_failed",`Diagram "${t}" lock ownership changed before release.`,"Retry after the active Sketchi command finishes.",t)}if(!(yield*e.removeFile(r.ownerPath).pipe(B.YWq({onFailure:()=>!0,onSuccess:e=>e}))))return yield*e.removeFile(i).pipe(B.MfU(()=>B.rIH)),yield*as("storage_commit_failed",`Diagram "${t}" lock ownership changed before release.`,"Retry after the active Sketchi command finishes.",t)}),p=e=>as("diagram_not_found",`Diagram "${e}" does not exist.`,"Run sketchi list to discover stored diagram ids.",e),h=(r,i,l=!1,d=!1)=>B.JkU(function*(){let c;if(l){let n=ap(t.path,r),i=yield*e.kind(n);if("missing"===i){let n=yield*e.kind(t.path);if("missing"===n)return yield*p(r);if("directory"!==n)return yield*am(t.path,r);let i=o(r),a=yield*e.kind(i);if("missing"===a){let n=yield*e.list(t.path),i=`${ar}${ao(r)}.`;if(!n.some(e=>e.name===r||e.name.startsWith(i)))return yield*p(r)}else if("directory"!==a)return yield*am(i,r)}else if("directory"!==i)return yield*am(n,r)}return d||(yield*n(),yield*a()),yield*B.jGc((c=u(r),l?c.pipe(B.L5P({schedule:ai,while:e=>"CliStorageError"===e._tag&&"diagram_busy"===e.code})):c),()=>s(r).pipe(B.hgn(i)),e=>f(r,e).pipe(B.MfU(()=>B.rIH)))}),m=B.fn("sketchi.cli.storage.decodeManifest")(function*(t,r){let n=yield*e.readText(t),i=yield*B.SvU({try:()=>JSON.parse(n),catch:()=>as("corrupt_record",`Diagram "${r}" has an invalid manifest.`,"Inspect manifest.json and restore it from a known-good backup.",r)});return yield*nx._Re(iE)(i).pipe(B.xm_(()=>as("corrupt_record",`Diagram "${r}" has an incompatible manifest.`,`Expected manifest schema version ${String(1)}.`,r)))}),g=B.fn("sketchi.cli.storage.decodeDocument")(function*(t,r){let n=yield*e.readText(t),i=yield*B.SvU({try:()=>JSON.parse(n),catch:()=>as("corrupt_record",`Diagram "${r}" has invalid document JSON.`,"Recover a prior canonical document from the revisions directory.",r)});return yield*n3(i).pipe(B.xm_(()=>as("corrupt_record",`Diagram "${r}" has an invalid canonical document.`,"Recover a prior canonical document from the revisions directory.",r)))}),y=B.fn("sketchi.cli.storage.loadUnlocked")(function*(r){var n;let a,s=ap(t.path,r),o=yield*e.kind(s);if("missing"===o)return yield*as("diagram_not_found",`Diagram "${r}" does not exist.`,"Run sketchi list to discover stored diagram ids.",r);if("directory"!==o)return yield*am(s,r);yield*i(s,r);let l=yield*m((0,rR.join)(s,ix),r);if(l.id!==r)return yield*as("corrupt_record",`Diagram directory "${r}" contains manifest id "${l.id}".`,"Make the directory name and manifest id agree before retrying.",r);let d=yield*g((0,rR.join)(s,iw),r);if(l.type!==d.type||l.title!==d.spec.title)return yield*as("corrupt_record",`Diagram "${r}" manifest does not match its canonical document.`,"Recover the canonical document and rebuild the record with sketchi edit.",r);for(let t of[ik,iS])if((yield*e.kind((0,rR.join)(s,t)))!=="file")return yield*as("corrupt_record",`Diagram "${r}" is missing required artifact ${t}.`,"Recover the canonical document and rebuild the record with sketchi edit.",r);let c=yield*e.kind((0,rR.join)(s,iI));if("file"!==c&&"missing"!==c)return yield*am((0,rR.join)(s,iI),r);if("file"===c&&(a=(n=yield*e.readBytes((0,rR.join)(s,iI))).byteLength-12,!(n.byteLength>=45&&[137,80,78,71,13,10,26,10].every((e,t)=>n[t]===e)&&13===i0(n,8)&&"IHDR"===String.fromCharCode(...n.subarray(12,16))&&i0(n,16)>0&&i0(n,20)>0)||iZ(n.subarray(12,29))!==i0(n,29)||0!==i0(n,a)||"IEND"!==String.fromCharCode(...n.subarray(a+4,a+8))||iZ(n.subarray(a+4,a+8))!==i0(n,a+8)))return yield*as("corrupt_record",`Diagram "${r}" has an invalid stored PNG artifact.`,"Recover a valid prior revision or rebuild the record.",r);let u=ac(l.authority,"file"===c);if(l.formats.length!==u.length||l.formats.some((e,t)=>e!==u[t]))return yield*as("corrupt_record",`Diagram "${r}" manifest formats do not match stored artifacts.`,"Recover the canonical document and rebuild the record with sketchi edit.",r);let f=(0,rR.join)(s,i$),p=[];for(let t of yield*e.list(f)){if("file"===t.kind&&/^\d{6,}\.json$/u.test(t.name)){p.push(t.name);continue}if("directory"===t.kind&&/^\d{6,}$/u.test(t.name)){p.push(`${t.name}/`);continue}return yield*am((0,rR.join)(f,t.name),r)}return p.sort(ad),{manifest:l,document:d,revisions:p,authority:l.authority}}),v=B.fn("sketchi.cli.storage.copySafeTree")(function*(t,r,n){for(let i of yield*e.list(t)){let a=(0,rR.join)(t,i.name),s=(0,rR.join)(r,i.name);if("directory"===i.kind)yield*e.makeDirectory(s),yield*v(a,s,n);else{if("file"!==i.kind)return yield*am(a,n);let t=yield*e.readBytes(a);yield*e.writeBytes(s,t)}}}),b=B.fn("sketchi.cli.storage.copyRecordSnapshot")(function*(t,r,n){for(let i of(yield*e.makeDirectory(r),yield*e.list(t))){if(i.name===i$)continue;let a=(0,rR.join)(t,i.name),s=(0,rR.join)(r,i.name);if("file"!==i.kind)return yield*am(a,n);yield*e.writeBytes(s,(yield*e.readBytes(a)))}}),_=B.fn("sketchi.cli.storage.commitStage")(function*(r,n){let i=ap(t.path,r),a=(0,rR.join)(t.path,`${ar}${ao(r)}.${String(process.pid)}.${crypto.randomUUID()}`);yield*e.rename(i,a),(yield*e.rename(n,i).pipe(B.tvg({onFailure:t=>e.rename(a,i).pipe(B.tvg({onFailure:()=>B.fJG(as("storage_commit_failed",`Atomic storage commit and rollback both failed for "${r}".`,"Retry; Sketchi will recover the backup transaction before the next operation.",r)),onSuccess:()=>B.fJG(t)})),onSuccess:()=>B.PyW(!0)})))&&(yield*e.remove(a).pipe(B.MfU(()=>B.rIH)))}),x=B.fn("sketchi.cli.storage.snapshotCurrent")(function*(r,n,i){let a=(0,rR.join)(n,i$,iC(i));if((yield*e.kind(a))!=="missing")return yield*as("corrupt_record",`Diagram "${r}" already has a snapshot for current revision ${String(i)}.`,"Inspect the revisions directory before retrying.",r);yield*b(ap(t.path,r),a,r)}),w=B.fn("sketchi.cli.storage.writeBuilt")(function*(t,r){if(r.png&&!i5(r.png))return yield*as("corrupt_record",`Diagram "${r.id}" has an invalid stored PNG artifact.`,"Recover a valid prior revision or rebuild the record.",r.id);yield*e.makeDirectory((0,rR.join)(t,i$),!0),yield*e.writeText((0,rR.join)(t,iw),n6(r.document),!0),yield*e.writeText((0,rR.join)(t,ik),n6(r.scene),!0),yield*e.writeText((0,rR.join)(t,iS),n6(r.excalidraw),!0);let n=(0,rR.join)(t,iI);yield*e.remove(n),r.png&&(yield*e.writeBytes(n,r.png))}),k=B.fn("sketchi.cli.storage.transition")(function*(r,n,i){return yield*h(r,B.JkU(function*(){let a=yield*y(r),s=yield*n(a);return yield*B.jGc(e.makeTempDirectory(t.path,an),n=>B.JkU(function*(){yield*v(ap(t.path,r),n,r),yield*x(r,n,a.manifest.revision);let o=yield*i(n,a,s);return yield*e.writeText((0,rR.join)(n,ix),n6(o.manifest),!0),yield*_(r,n),{...o,revisions:[...a.revisions,`${iC(a.manifest.revision)}/`].sort(ad),authority:o.manifest.authority}}),t=>e.remove(t))}))}),S=B.fn("sketchi.cli.storage.create")(function*(r){return yield*h(r.id,B.JkU(function*(){let n=ap(t.path,r.id);if((yield*e.kind(n))!=="missing")return yield*as("diagram_already_exists",`Diagram "${r.id}" already exists.`,"Use sketchi edit for full-document replacement.",r.id);let i=iE.make({schemaVersion:1,id:r.id,type:r.type,title:r.title,revision:1,authority:"canonical",formats:ac("canonical",void 0!==r.png)});return yield*B.jGc(e.makeTempDirectory(t.path,an),t=>B.JkU(function*(){return yield*w(t,r),yield*e.writeText((0,rR.join)(t,ix),n6(i),!0),yield*e.rename(t,n),{manifest:i,document:r.document,revisions:[],authority:"canonical"}}),t=>e.remove(t))}))}),I=B.fn("sketchi.cli.storage.edit")((e,t)=>k(e,r=>B.JkU(function*(){return"canonical"!==r.authority?yield*as("detached_edit",`Diagram "${e}" does not have an authoritative canonical document.`,"Restore a canonical revision before editing this diagram.",e):t.id!==e?yield*as("storage_commit_failed",`Edited document id "${t.id}" does not match "${e}".`,"Keep spec.id equal to the diagram id being edited.",e):iE.make({schemaVersion:1,id:e,type:t.type,title:t.title,revision:r.manifest.revision+1,authority:"canonical",formats:ac("canonical",void 0!==t.png)})}),(e,r,n)=>w(e,t).pipe(B.as({manifest:n,document:t.document})))),$=e=>as("patch_source_unavailable",`Diagram "${e}" has no current authoritative scene to patch.`,"Restore a canonical or patched revision before patching this diagram.",e),E=B.fn("sketchi.cli.storage.readPatchSourceUnlocked")(function*(r){let n=yield*y(r);if("detached"===n.authority||!n.manifest.formats.includes("scene"))return yield*$(r);let i=(0,rR.join)(ap(t.path,r),ik),a=yield*e.readText(i),s=yield*B.OH5(()=>{try{return nM.Uh.safeParse(JSON.parse(a))}catch{return}});return s?.success&&s.data.diagramId===r?{revision:n.manifest.revision,scene:s.data}:yield*as("corrupt_record",`Diagram "${r}" has an invalid current scene artifact.`,"Restore a valid prior revision before patching this diagram.",r)}),O=B.fn("sketchi.cli.storage.readPatchSource")(e=>h(e,E(e),!0)),C=B.fn("sketchi.cli.storage.commitPatch")((t,r,n)=>k(t,e=>B.JkU(function*(){return e.manifest.revision!==r?yield*as("patch_conflict",`Diagram "${t}" changed before the patch could commit.`,"Run sketchi show, verify the current record, and retry the patch if it is still intended.",t):"detached"!==e.authority&&e.manifest.formats.includes("scene")?n.scene.diagramId!==t?yield*as("storage_commit_failed",`Patched scene id "${n.scene.diagramId}" does not match "${t}".`,"Retry the patch against the named stored diagram.",t):iE.make({schemaVersion:1,id:t,type:e.manifest.type,title:e.manifest.title,revision:e.manifest.revision+1,authority:"patched",formats:ac("patched",!1)}):yield*$(t)}),(t,r,i)=>B.JkU(function*(){return yield*e.writeText((0,rR.join)(t,ik),n6(n.scene),!0),yield*e.writeText((0,rR.join)(t,iS),n6(n.excalidraw),!0),yield*e.remove((0,rR.join)(t,iI)),{manifest:i,document:r.document}}))),T=(e,t)=>as("corrupt_revision",`Diagram "${e}" revision ${String(t)} is corrupt.`,"Choose another revision or repair the corrupt snapshot.",e),M=B.fn("sketchi.cli.storage.validateArchivedJson")(function*(t,r,n){let i=yield*e.readText(t);return yield*B.SvU({try:()=>{let e=JSON.parse(i);if("object"!=typeof e||null===e)throw Error("archived JSON must contain an object");return e},catch:()=>T(r,n)})}),A=B.fn("sketchi.cli.storage.validateArchivedArtifact")(function*(e,t,r,n,i){let a=yield*M(e,n,i);if(!("scene"===t?nM.Uh.safeParse(a):nM.yE.safeParse(a)).success)return yield*T(n,i);"excalidraw"===t&&"detached"===r&&(yield*iH(a).pipe(B.xm_(()=>T(n,i))))}),N=B.fn("sketchi.cli.storage.validateArchivedPng")(function*(t,r,n){if(!i5((yield*e.readBytes(t))))return yield*T(r,n)}),P=B.fn("sketchi.cli.storage.readRevisionUnlocked")(function*(r,n){let a=(0,rR.join)(ap(t.path,r),i$),s=(0,rR.join)(a,iC(n)),o=yield*e.kind(s);if("directory"===o){yield*i(s,r);let t=yield*m((0,rR.join)(s,ix),r).pipe(B.xm_(()=>T(r,n))),a=yield*g((0,rR.join)(s,iw),r).pipe(B.xm_(()=>T(r,n)));if(t.id!==r||t.revision!==n||t.type!==a.type||t.title!==a.spec.title)return yield*as("corrupt_revision",`Diagram "${r}" revision ${String(n)} has inconsistent metadata.`,"Choose another revision or repair the corrupt snapshot.",r);for(let[i,a]of[[ik,"scene"],[iS,"excalidraw"]]){let o=(0,rR.join)(s,i);if((yield*e.kind(o))!=="file")return yield*as("corrupt_revision",`Diagram "${r}" revision ${String(n)} is missing ${i}.`,"Choose another revision or repair the corrupt snapshot.",r);yield*A(o,a,t.authority,r,n).pipe(B.xm_(e=>"CliFilesystemError"===e._tag?T(r,n):e))}let o=yield*e.kind((0,rR.join)(s,iI));if("file"!==o&&"missing"!==o)return yield*am((0,rR.join)(s,iI),r);"file"===o&&(yield*N((0,rR.join)(s,iI),r,n).pipe(B.xm_(e=>"CliFilesystemError"===e._tag?T(r,n):e)));let l=ac(t.authority,"file"===o);return t.formats.length!==l.length||t.formats.some((e,t)=>e!==l[t])?yield*as("corrupt_revision",`Diagram "${r}" revision ${String(n)} has inconsistent formats.`,"Choose another revision or repair the corrupt snapshot.",r):{_tag:"FullSnapshot",revision:n}}if("missing"!==o)return yield*am(s,r);let l=(0,rR.join)(a,`${String(n).padStart(6,"0")}.json`),d=yield*e.kind(l);if("missing"===d)return yield*as("revision_not_found",`Diagram "${r}" has no revision ${String(n)}.`,"Run sketchi show to inspect the available revision paths.",r);if("file"!==d)return yield*am(l,r);let c=yield*n2((yield*M(l,r,n))).pipe(B.xm_(()=>as("corrupt_revision",`Diagram "${r}" revision ${String(n)} is corrupt.`,"Choose another revision or repair the legacy revision file.",r)));return{_tag:"LegacyDocument",revision:n,document:c}}),R=B.fn("sketchi.cli.storage.replaceWithDetached")((t,r,n)=>k(t,e=>B.JkU(function*(){return void 0!==n&&e.manifest.revision!==n?yield*as("replacement_conflict",`Diagram "${t}" changed before the pulled replacement could commit.`,"Run sketchi show, verify the current record, and retry the pull if it is still intended.",t):iE.make({schemaVersion:1,id:t,type:e.manifest.type,title:e.manifest.title,revision:e.manifest.revision+1,authority:"detached",formats:ac("detached",!1)})}),(t,n,i)=>B.JkU(function*(){return yield*e.writeBytes((0,rR.join)(t,iS),r,!0),yield*e.remove((0,rR.join)(t,iI)),{manifest:i,document:n.document}}))),j=B.fn("sketchi.cli.storage.readRevision")((e,t)=>h(e,y(e).pipe(B.hgn(P(e,t))),!0)),D=B.fn("sketchi.cli.storage.restore")(function*(t,r,n){return{diagram:yield*k(t,e=>B.JkU(function*(){let i=yield*P(t,r);if("LegacyDocument"===i._tag){if("canonical"!==e.authority||!n)return yield*as("restore_conflict",`Legacy revision ${String(r)} requires a canonical rebuild for "${t}".`,"Restore a full canonical snapshot, or provide the rebuilt legacy document.",t);if(n.id!==t||n6(n.document)!==n6(i.document))return yield*as("storage_commit_failed",`Legacy revision ${String(r)} rebuild does not match its archived document.`,"Rebuild the exact archived canonical document before restoring.",t)}return i}),(i,a,s)=>B.JkU(function*(){if("FullSnapshot"===s._tag){let n=(0,rR.join)(i,i$,iC(r));for(let t of yield*e.list(i))t.name!==i$&&(yield*e.remove((0,rR.join)(i,t.name)));yield*v(n,i,t);let s=yield*m((0,rR.join)(i,ix),t),o=yield*g((0,rR.join)(i,iw),t);return{manifest:iE.make({...s,revision:a.manifest.revision+1}),document:o}}if(!n)return yield*as("storage_commit_failed",`Legacy revision ${String(r)} has no rebuilt document.`,"Rebuild the archived canonical document before restoring.",t);let o=iE.make({schemaVersion:1,id:t,type:n.type,title:n.title,revision:a.manifest.revision+1,authority:"canonical",formats:ac("canonical",void 0!==n.png)});return yield*w(i,n),{manifest:o,document:n.document}})),restoredFromRevision:r}}),U=B.fn("sketchi.cli.storage.show")(e=>h(e,y(e),!0));return{create:S,edit:I,readPatchSource:O,commitPatch:C,replaceWithDetached:R,readRevision:j,restore:D,show:U,list:B.fn("sketchi.cli.storage.list")(function*(){yield*n();let r=yield*e.list(t.path);yield*a(r);let i=new Set;for(let e of r){if("directory"===e.kind&&!e.name.startsWith(".")){i.add(e.name);continue}if(!e.name.startsWith(ar))continue;let t=function(e){try{let t=Buffer.from(e,"base64url").toString("utf8");return/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(t)?t:void 0}catch{return}}(e.name.split(".")[2]??"");t&&i.add(t)}return yield*B.jJl([...i].sort(al),e=>h(e,y(e),!0,!0).pipe(B.Ket,B.TjK(t=>{if(tL.oJ(t))return iO(t.success);let r=t.failure;return{id:e,status:"unavailable",code:"CliStorageError"===r._tag?r.code:"filesystem_error",message:r.message,hint:"CliStorageError"===r._tag?r.hint:"Check local paths and permissions, then retry."}})),{concurrency:4})}),readExportSource:B.fn("sketchi.cli.storage.readExportSource")(function*(r,n){return yield*h(r,B.JkU(function*(){let i=yield*y(r);if(i.manifest.formats.includes(n)){let i=yield*e.readBytes((0,rR.join)(ap(t.path,r),ah(n)));return"png"!==n||i5(i)?{_tag:"StoredArtifact",bytes:i}:yield*as("corrupt_record",`Diagram "${r}" has an invalid stored PNG artifact.`,"Recover a valid prior revision or rebuild the record.",r)}if("png"!==n)return yield*nL.make({code:"format_unavailable",format:n,message:`Diagram "${r}" has no stored ${n} artifact.`,hint:"Edit the diagram to rebuild its local artifacts."});if("detached"===i.authority)return{_tag:"RenderPng",excalidraw:yield*e.readBytes((0,rR.join)(ap(t.path,r),ah("excalidraw")))};for(let e of["scene","excalidraw"])if(!i.manifest.formats.includes(e))return yield*nL.make({code:"format_unavailable",format:e,message:`Diagram "${r}" has no stored ${e} artifact.`,hint:"Edit the diagram to rebuild its local artifacts."});let[a,s]=yield*B.Q7R([e.readBytes((0,rR.join)(ap(t.path,r),ah("scene"))),e.readBytes((0,rR.join)(ap(t.path,r),ah("excalidraw")))]);return{_tag:"RenderPng",scene:a,excalidraw:s}}),!0)})}})),ay=B.fn("sketchi.cli.export.writeFile")(function*(e,t){let r=yield*it,n=yield*i3,i=(0,rR.resolve)(e),a=(0,rR.dirname)(i),s=()=>nL.make({code:"export_write_failed",format:(0,rR.basename)(e),message:`Export destination directory does not exist: ${a}.`,hint:"Create the destination directory and retry."}),o=yield*r.realPath(a).pipe(B.xm_(s));if((yield*r.kind(o))!=="directory")return yield*s();let l=yield*r.realPath(n.path),d=(0,rR.join)(o,(0,rR.basename)(i)),c=(0,rR.relative)(l,d);if(""===c||!(".."===c||c.startsWith(".."+rR.sep)||(0,rR.isAbsolute)(c)))return yield*nL.make({code:"invalid_destination",format:(0,rR.basename)(e),message:`Export destination is inside Sketchi's diagram storage: ${e}.`,hint:"Choose a destination outside ~/.sketchi/diagrams so the stored record remains valid."});let u=(0,rR.join)(o,`.${(0,rR.basename)(e)}.sketchi.${String(process.pid)}.${crypto.randomUUID()}`);return yield*B.jGc(B.PyW(u),n=>r.writeBytes(n,t).pipe(B.hgn(r.rename(n,d)),B.xm_(()=>nL.make({code:"export_write_failed",format:(0,rR.basename)(e),message:`Unable to write export destination ${e}.`,hint:"Check the destination path and permissions, then retry."}))),e=>r.remove(e))}),av="90 seconds",ab=B.fn("sketchi.cli.response.readBoundedBody")(function*(e,t,r,n=r){let i,a=e.body,s=Number(e.headers.get("content-length"));if(Number.isFinite(s)&&s>t)return a&&(yield*B.$mh({try:()=>a.cancel(),catch:r}).pipe(B.XeO)),yield*B.fJG(r());if(!a)return new Uint8Array;let o=yield*tw((i={evaluate:()=>a,onError:n},e3((e,t)=>{var r;let n,a,s;return n=(r={scope:t,readable:i.evaluate(),onError:i.onError,releaseLockOnEnd:i.releaseLockOnEnd}).readable.getReader(),a=r.exit??ef(void 0),s=B.DYE(()=>a.current?a.current:B.khu(B.$mh({try:()=>n.read(),catch:r.onError}),{onFailure:e=>a.current??B.ATB(e),onSuccess:({done:e,value:t})=>a.current?a.current:e?F.Vw():B.PyW(K.of(t))})),B.as(e0.U9(r.scope,r.releaseLockOnEnd?B.OH5(()=>n.releaseLock()):B.ivC(()=>n.cancel().catch(z.Yi))),s)}))).pipe(tN(()=>({chunks:[],size:0}),(e,n)=>{let i=e.size+n.byteLength;return i>t?B.fJG(r()):(e.chunks.push(n),B.PyW({chunks:e.chunks,size:i}))})),l=new Uint8Array(o.size),d=0;for(let e of o.chunks)l.set(e,d),d+=e.byteLength;return l}),a_=B.fn("sketchi.cli.response.readBoundedText")(function*(e,t,r,n=r){let i=yield*ab(e,t,r,n);return yield*B.SvU({try:()=>new TextDecoder("utf-8",{fatal:!0}).decode(i),catch:r})}),ax="https://playground.sketchi.app/api/v1/canvases/create",aw="SKETCHI_CANVAS_ENDPOINT",ak=nX.ID();function aS(e){return ak(e.issue).issues.map(e=>{let t=(e.path??[]).map(e=>"object"==typeof e&&null!==e&&"key"in e?String(e.key):String(e)).join(".");return`${t||"spec"}: ${e.message}`})}let aI=nx._Re(nM.y1,{errors:"all"}),a$=nx._Re(nM.JH,{errors:"all"}),aE=B.fn("sketchi.cli.canvas.parseSpec")(function*(e){let t=yield*B.SvU({try:()=>JSON.parse(e),catch:()=>nN.make({code:"invalid_json",message:"The CanvasSpec input is not valid JSON.",hint:"Pass one complete CanvasSpec JSON object."})});return yield*aI(t).pipe(B.xm_(e=>nP.make({message:"The CanvasSpec document is invalid.",hint:"Use the version 1 CanvasSpec contract documented by sketchi docs.",details:aS(e)})))}),aO=B.fn("sketchi.cli.canvas.readSpecInput")(function*(e){let t=yield*ih,r=yield*t.read(e,{content:"CanvasSpec document"});return yield*aE(r)});function aC(){return nD.make({code:"network_failure",message:"The Sketchi create-canvas API could not be reached.",hint:"Check the network connection and endpoint, then retry.",details:["transport"]})}function aT(e=[]){return nD.make({code:"malformed_response",message:"The Sketchi create-canvas API returned an unreadable response.",hint:"Retry once; if the response remains invalid, report the endpoint.",details:e})}function aM(e){return nD.make({code:"endpoint_failure",message:`The Sketchi create-canvas API responded with HTTP ${String(e)}.`,hint:"Check the endpoint and retry.",details:[`http_status:${String(e)}`]})}let aA=B.fn("sketchi.cli.canvas.request")(function*(e){var t,r,n,i,a,s;let o=yield*B.$mh({try:t=>globalThis.fetch(e.endpoint,{method:"POST",headers:{"content-type":"application/json","x-sketchi-client":"sketchi-cli"},body:JSON.stringify({spec:e.spec,options:{artifactFormats:["scene","excalidraw"],inlineArtifacts:["excalidraw"]}}),signal:t}),catch:aC}),l=yield*a_(o,0x1000000,aT,aC),d=yield*B.SvU({try:()=>JSON.parse(l),catch:()=>aT()}),c=yield*a$(d).pipe(B.xm_(e=>o.ok?aT(aS(e)):aM(o.status)));if(!c.ok)switch(c.status){case"export_failed":case"render_failed":case"storage_failed":return yield*(t=c.status,r=o.status,n=c.issues,nD.make({code:"endpoint_failure",message:`The Sketchi create-canvas API failed with status ${t}.`,hint:"Retry once; if the failure persists, report the endpoint and status.",details:[`status:${t}`,`http_status:${String(r)}`,...n.map(e=>`${e.code}: ${e.message}`)]}));case"invalid_canvas":case"invalid_input":case"limit_exceeded":let u;return yield*(i=c.status,a=o.status,u=(s=c.issues)[0],nD.make({code:"canvas_rejected",message:u?.message??"The create-canvas API rejected the CanvasSpec.",hint:"Correct the reported CanvasSpec issue and retry.",details:[`status:${i}`,`http_status:${String(a)}`,...s.map(e=>`${e.code}: ${e.message}`)]}))}return o.ok?c:yield*aM(o.status)},B.mgX({duration:av,orElse:()=>B.fJG(nD.make({code:"canvas_timeout",message:"The Sketchi canvas API request timed out.",hint:"Retry once; if it persists, check the endpoint and try a smaller canvas.",details:[]}))})),aN=B.fn("sketchi.cli.canvas.create")(function*(e){let t=yield*i6;yield*n9(e.spec.diagramId).pipe(B.xm_(e=>nP.make({message:e.message,hint:e.hint,details:["spec.diagramId"]})));let r=yield*aA(e);if(r.normalizedSpec.diagramId!==e.spec.diagramId)return yield*aT(["normalizedSpec.diagramId does not match submitted spec.diagramId"]);let n=r.artifact.formats.find(e=>"excalidraw"===e.format);if(n?.inline===void 0)return yield*aT(["artifact.formats.excalidraw.inline"]);let i=nM.yE.safeParse(n.inline);if(!i.success)return yield*aT(i.error.issues.map(e=>`${e.path.join(".")}: ${e.message}`));let a=yield*n9(r.normalizedSpec.diagramId).pipe(B.xm_(()=>aT(["normalizedSpec.diagramId is not storage-safe"])));if(r.artifact.diagramId!==a)return yield*aT(["artifact.diagramId does not match normalizedSpec.diagramId"]);let s={id:a,type:"canvas",title:r.normalizedSpec.title,document:{type:"canvas",spec:r.normalizedSpec},scene:r.normalizedSpec,excalidraw:i.data},o=yield*t.create(s);return{artifactId:r.artifact.artifactId,diagram:o}});var aP=n(1688);class aR extends Z.kl()("@sketchi/cli/CliPngRenderer"){}let aj=G.Py(aR,{renderPng:function(e){return B.$mh({try:async()=>(await Promise.all([n.e(548),n.e(869)]).then(n.bind(n,7665))).renderPngBytes(e),catch:e=>e instanceof aP.FG?e:aP.FG.make({cause:e,code:"rasterization_failed",stage:"rasterization",message:"Unable to rasterize the stored diagram as PNG.",details:[]})})},normalizeExcalidraw:function(e){return B.$mh({try:async()=>(await Promise.all([n.e(548),n.e(869)]).then(n.bind(n,7665))).normalizeExcalidrawArtifact(e),catch:e=>e instanceof aP.FG?e:aP.FG.make({cause:e,code:"invalid_render_artifact",stage:"artifact",message:"Unable to restore the Excalidraw share artifact.",details:[]})})}});class aD extends Z.kl()("@sketchi/cli/DiagramExporter"){}function aU(e,t){let r=`sketchi export ${e} --format png --dest ${e}.png`;return nL.make({code:t?.code??"invalid_render_artifact",format:"png",diagramId:e,storagePath:`~/.sketchi/diagrams/${e}`,recoveryCommand:r,message:t?.message??"Unable to read the stored PNG source artifacts.",hint:`The canonical record is preserved. Retry with: ${r}`,details:t?[`stage:${t.stage}`,...t.details]:["stage:artifact"]})}function aF(e,t){return B.SvU({try:()=>JSON.parse(new TextDecoder().decode(t)),catch:()=>aU(e)})}let aB=G.QZ(aD,B.JkU(function*(){let e=yield*i6,t=yield*aR,r=B.fn("sketchi.cli.export.renderPng")(function*(e,r){let n=[{format:"excalidraw",inline:yield*aF(e,r.excalidraw)}];r.scene&&n.unshift({format:"scene",inline:yield*aF(e,r.scene)});let i=yield*nY({formats:n},"export").pipe(B.xm_(()=>aU(e)));return yield*t.renderPng({...i}).pipe(B.xm_(t=>aU(e,t)))});return{exportArtifact:B.fn("sketchi.cli.export.artifact")(function*(t,n){let i=yield*e.readExportSource(t,n);return"StoredArtifact"===i._tag?i.bytes:yield*r(t,i)})}})),aL="gemini-3.1-flash-lite",az="https://playground.sketchi.app/api/v1/generate",aW="SKETCHI_GENERATE_ENDPOINT";function aJ(){return nj.make({code:"provider_failure",message:"The Sketchi generate API could not be reached.",hint:"Check your network connection and retry. create/show/edit/list/export/restore remain offline; share and pull are separate explicit network commands.",details:["transport"]})}function aY(){return nj.make({code:"malformed_output",message:"The Sketchi generate API returned an unreadable response.",hint:"Retry once; if it persists, report the prompt without secrets.",details:[]})}function aX(){return nj.make({code:"invalid_generated_document",message:"The generated diagram failed Sketchi schema or semantic validation.",hint:"Refine the prompt with concrete diagram content, then retry.",details:[]})}let aq=nx._kM({status:nx.Qrq(nx.QfV),issues:nx.Qrq(nx.O31(nx._kM({message:nx.Qrq(nx.QfV),hint:nx.Qrq(nx.QfV)})))}),aG=nx._Re(nx.mj7(aq)),aV=nx.$r1.check(nx.HNH(e=>void 0!==e)),aH=nx._kM({ok:nx.uSQ(!0),diagram:nx._kM({document:aV,scene:aV,excalidraw:aV}),generation:nx._kM({model:nx.ukk,provider:nx.ukk})}),aK=nx._Re(nx.mj7(aH)),aQ=B.fn("sketchi.cli.generate.request")(function*(e){let t=yield*B.$mh({try:t=>globalThis.fetch(e.endpoint,{method:"POST",headers:{"content-type":"application/json","x-sketchi-client":"sketchi-cli"},body:JSON.stringify({prompt:e.prompt,...e.type?{type:e.type}:{},model:e.model}),signal:t}),catch:()=>aJ()}),r=yield*a_(t,0x1000000,aY,aJ);if(!t.ok){let e=yield*aG(r).pipe(B.xm_(aY));return yield*function(e,t){let r=t.issues?.[0],n=[`http_status:${String(e)}`,...(t.issues??[]).flatMap(e=>[...e.message?[e.message]:[],...e.hint?[e.hint]:[]])];switch(t.status){case"generation_timeout":return nj.make({code:"generation_timeout",message:r?.message??"The generate API timed out.",hint:r?.hint??"Retry once; if it persists, try a shorter prompt.",details:n});case"malformed_output":return nj.make({code:"malformed_output",message:r?.message??"The generate API returned unreadable model output.",hint:r?.hint??"Retry once; if it persists, try another prompt.",details:n});case"invalid_input":case"invalid_generated_document":case"quality_failed":return nj.make({code:"invalid_generated_document",message:r?.message??"The generated diagram failed Sketchi validation.",hint:r?.hint??"Refine the prompt with concrete content, then retry.",details:n});case"unsupported_diagram_type":return nj.make({code:"unsupported_diagram_type",message:r?.message??"Sketchi does not natively support the requested diagram type.",hint:r?.hint??"Request a flowchart, mindmap, or sequence diagram instead.",details:n});default:return nj.make({code:"provider_failure",message:r?.message??`The Sketchi generate API responded with HTTP ${String(e)}.`,hint:r?.hint??"Retry once; if it persists, report the prompt without secrets.",details:n})}}(t.status,e)}let n=yield*aK(r).pipe(B.xm_(aY));return{...n.diagram,...n.generation}},B.mgX({duration:av,orElse:()=>B.fJG(nj.make({code:"generation_timeout",message:"The Sketchi generate API request timed out.",hint:"Retry once; if it persists, try a shorter prompt.",details:[]}))})),aZ=B.fn("sketchi.cli.generate")(function*(e){var t,r;let n,i,a=yield*i6,s=yield*aQ(e),o=yield*n2(s.document).pipe(B.xm_(()=>aX())),l=yield*n9(n8(o)).pipe(B.xm_(()=>aX())),d=yield*(t=s.scene,(n=nM.Uh.safeParse(t)).success?B.PyW(n.data):B.fJG(aY())),c=yield*(r=s.excalidraw,(i=nM.yE.safeParse(r)).success?B.PyW(i.data):B.fJG(aY())),u={id:l,type:o.type,title:o.spec.title,document:o,scene:d,excalidraw:c};return{diagram:yield*a.create(u),model:s.model,provider:s.provider}});function a0(e,t){switch(t){case"png":return`${e}.png`;case"excalidraw":return`${e}.excalidraw`;case"scene":return`${e}.scene.json`}}let a1=B.fn("sketchi.cli.exportCreatedDiagram")(function*(e,t,r){let n=yield*aD,i=e.manifest.id,a=function(e,t,r){switch(r._tag){case"Default":return a0(e,t);case"CurrentDirectory":return(0,rR.resolve)(r.cwd,a0(e,"png"));case"ProjectDiagrams":return(0,rR.resolve)(r.cwd,"diagrams",a0(e,"png"));case"Custom":return r.path}}(i,t,r),s=yield*n.exportArtifact(i,t).pipe(B.xm_(e=>a2(e,i,t)));return yield*B.JkU(function*(){if("-"!==a){if("ProjectDiagrams"===r._tag){let e=yield*it;yield*e.makeDirectory((0,rR.join)(r.cwd,"diagrams"),!0)}yield*ay(a,s)}}).pipe(B.xm_(e=>a2(e,i,t))),{id:i,format:t,destination:a,sizeBytes:s.byteLength,..."-"===a?{stdoutBytes:s}:{}}});function a2(e,t,r){let n=a0(t,r),i=`sketchi export ${t} --format ${r} --dest ${n}`,a="CliExportError"===e._tag?e.details:"CliStorageError"===e._tag?[`storage_error:${e.code}`]:[`filesystem_operation:${e.operation}`,`path:${e.path}`];return nL.make({code:"CliExportError"===e._tag?e.code:"CliStorageError"===e._tag?"invalid_render_artifact":"export_write_failed",diagramId:t,storagePath:`~/.sketchi/diagrams/${t}`,recoveryCommand:i,...a?{details:a}:{},format:r,message:e.message,hint:`The local record is preserved. Retry with: ${i}`})}let a5=B.fn("sketchi.cli.generateWorkflow")(function*(e){let t=yield*aZ(e),r=yield*a1(t.diagram,e.format,e.destination);return{generated:t,artifact:r}}),a3=t("node:util"),a6=t("node:process"),a8=(A=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,e=>{let t=0;for(A.lastIndex=0;A.test(e);)t+=1;return e.length-t}),a9=e=>12288===e||e>=65281&&e<=65376||e>=65504&&e<=65510,a4=e=>8987===e||9001===e||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141,a7=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,se=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,st=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,sr=/\t{1,1000}/y,sn=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,si=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,sa=/\p{M}+/gu,ss={limit:1/0,ellipsis:""},so=(e,t={},r={})=>{let n=t.limit??1/0,i=t.ellipsis??"",a=t?.ellipsisWidth??(i?so(i,ss,r).width:0),s=r.controlWidth??0,o=r.tabWidth??8,l=r.emojiWidth??2,d=r.regularWidth??1,c=r.wideWidth??2,u=[[si,d],[a7,0],[se,s],[sr,o],[sn,l],[st,c]],f=0,p=0,h=e.length,m=0,g=!1,y=h,v=Math.max(0,n-a),b=0,_=0,x=0,w=0;e:for(;;){if(_>b||p>=h&&p>f){for(let t of(m=0,(e.slice(b,_)||e.slice(f,p)).replaceAll(sa,""))){let e=t.codePointAt(0)||0;if(x+(w=a9(e)?2:a4(e)?c:d)>v&&(y=Math.min(y,Math.max(b,f)+m)),x+w>n){g=!0;break e}m+=t.length,x+=w}b=_=0}if(p>=h)break;for(let t=0,r=u.length;t<r;t++){let[r,i]=u[t];if(r.lastIndex=p,r.test(e)){if(x+(w=(m=r===st?a8(e.slice(p,r.lastIndex)):r===sn?1:r.lastIndex-p)*i)>v&&(y=Math.min(y,p+Math.floor((v-x)/i))),x+w>n){g=!0;break e}x+=w,b=f,_=p,p=f=r.lastIndex;continue e}}p+=1}return{width:g?v:x,index:g?y:h,truncated:g,ellipsed:g&&n>=a}},sl={limit:1/0,ellipsis:"",ellipsisWidth:0},sd=(e,t={})=>so(e,sl,t).width,sc="]8;;",su=RegExp(`(?:\\[(?<code>\\d+)m|\\${sc}(?<uri>.*)\x07)`,"y"),sf=e=>e>=30&&e<=37||e>=90&&e<=97?39:e>=40&&e<=47||e>=100&&e<=107?49:1===e||2===e?22:3===e?23:4===e?24:7===e?27:8===e?28:9===e?29:0===e?0:void 0,sp=e=>`\x1b[${e}m`,sh=e=>`\x1b${sc}${e}\x07`,sm=(e,t,r)=>{let n=t[Symbol.iterator](),i=!1,a=!1,s=e.at(-1),o=void 0===s?0:sd(s),l=n.next(),d=n.next(),c=0;for(;!l.done;){let s=l.value,u=sd(s);o+u<=r?e[e.length-1]+=s:(e.push(s),o=0),("\x1b"===s||"›"===s)&&(i=!0,a=t.startsWith(sc,c+1)),i?a?"\x07"===s&&(i=!1,a=!1):"m"===s&&(i=!1):(o+=u)!==r||d.done||(e.push(""),o=0),l=d,d=n.next(),c+=s.length}s=e.at(-1),!o&&void 0!==s&&s.length&&e.length>1&&(e[e.length-2]+=e.pop())},sg=/\r?\n/;function sy(e,t,r){return String(e).normalize().split(sg).map(e=>((e,t,r={})=>{let n,i;if(!1!==r.trim&&""===e.trim())return"";let a="",s=e.split(" "),o=[""],l=0;for(let e=0;e<s.length;e++){let n=s[e];if(!1!==r.trim){let e=o.at(-1)??"",t=e.trimStart();e.length!==t.length&&(o[o.length-1]=t,l=sd(t))}0!==e&&(l>=t&&(!1===r.wordWrap||!1===r.trim)&&(o.push(""),l=0),(l||!1===r.trim)&&(o[o.length-1]+=" ",l++));let i=sd(n);if(r.hard&&i>t){let e=1+Math.floor((i-(t-l)-1)/t);Math.floor((i-1)/t)<e&&o.push(""),sm(o,n,t),l=sd(o.at(-1)??"");continue}if(l+i>t&&l&&i){if(!1===r.wordWrap&&l<t){sm(o,n,t),l=sd(o.at(-1)??"");continue}o.push(""),l=0}if(l+i>t&&!1===r.wordWrap){sm(o,n,t),l=sd(o.at(-1)??"");continue}o[o.length-1]+=n,l+=i}!1!==r.trim&&(o=o.map(e=>(e=>{let t=e.split(" "),r=t.length;for(;r&&!sd(t[r-1]);)r--;return r===t.length?e:t.slice(0,r).join(" ")+t.slice(r).join("")})(e)));let d=o.join("\n"),c=!1;for(let e=0;e<d.length;e++){let t=d[e];if(a+=t,c)c=!1;else if(c=t>="\uD800"&&t<="\uDBFF")continue;if("\x1b"===t||"›"===t){su.lastIndex=e+1;let t=su.exec(d),r=t?.groups;if(r?.code!==void 0){let e=Number.parseFloat(r.code);n=39===e?void 0:e}else r?.uri!==void 0&&(i=0===r.uri.length?void 0:r.uri)}if("\n"===d[e+1]){i&&(a+=sh(""));let e=n?sf(n):void 0;n&&e&&(a+=sp(e))}else"\n"===t&&(n&&sf(n)&&(a+=sp(n)),i&&(a+=sh(i)))}return a})(e,t,r)).join("\n")}var sv=n(5776);let sb=t("node:tty");function s_(e,t,r){if(!r.some(e=>!e.disabled))return e;let n=e+t,i=Math.max(r.length-1,0),a=n<0?i:n>i?0:n;return r[a]?.disabled?s_(a,t<0?-1:1,r):a}let sx={actions:new Set(["up","down","left","right","space","enter","cancel"]),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,accessible:void 0,date:{monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:e=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:e=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function sw(e,t){if("string"==typeof e)return sx.aliases.get(e)===t;for(let r of e)if(void 0!==r&&sw(r,t))return!0;return!1}let sk=globalThis.process.platform.startsWith("win"),sS=Symbol("clack:cancel");function sI(e,t){e.isTTY&&e.setRawMode(t)}let s$=e=>"columns"in e&&"number"==typeof e.columns?e.columns:80,sE=e=>"rows"in e&&"number"==typeof e.rows?e.rows:20;function sO(e,t,r,n=r,i=r,a){return sy(t,s$(e??a6.stdout)-r.length,{hard:!0,trim:!1}).split(`
2
+ import{createRequire as e}from"node:module";let t=e(import.meta.url);var r,n,i,a,s={5776(e){let t={to:(e,t)=>t?`\x1b[${t+1};${e+1}H`:`\x1b[${e+1}G`,move(e,t){let r="";return e<0?r+=`\x1b[${-e}D`:e>0&&(r+=`\x1b[${e}C`),t<0?r+=`\x1b[${-t}A`:t>0&&(r+=`\x1b[${t}B`),r},up:(e=1)=>`\x1b[${e}A`,down:(e=1)=>`\x1b[${e}B`,forward:(e=1)=>`\x1b[${e}C`,backward:(e=1)=>`\x1b[${e}D`,nextLine:(e=1)=>"\x1b[E".repeat(e),prevLine:(e=1)=>"\x1b[F".repeat(e),left:"\x1b[G",hide:"\x1b[?25l",show:"\x1b[?25h",save:"\x1b7",restore:"\x1b8"},r={screen:"\x1b[2J",up:(e=1)=>"\x1b[1J".repeat(e),down:(e=1)=>"\x1b[J".repeat(e),line:"\x1b[2K",lineEnd:"\x1b[K",lineStart:"\x1b[1K",lines(e){let r="";for(let n=0;n<e;n++)r+=this.line+(n<e-1?t.up():"");return e&&(r+=t.left),r}};e.exports={cursor:t,scroll:{up:(e=1)=>"\x1b[S".repeat(e),down:(e=1)=>"\x1b[T".repeat(e)},erase:r,beep:"\x07"}},1833(e,r,n){let i,a,s,o,l,d,c,u,f,p,h,m,g,y,v,b,_,x,w,k,S,I,$,E,O,C,T,M,A,N;var P,R,j,D,U,F=n(719),B=n(2842),L=n(6526),z=n(1594);let W=(e,t)=>t(L.oJ(e)?0:F.nn(e.cause)?130:Y(F.iw(e.cause))),J="~effect/Runtime/errorExitCode",Y=e=>{if("object"==typeof e&&null!==e&&J in e){let t=e[J];if("number"==typeof t)return t}return 1},X="~effect/Runtime/errorReported",q=(a=({fiber:e,teardown:t})=>{let r=!1;function n(){r=!0,e.interruptUnsafe(e.id)}e.addObserver(e=>{process.removeListener("SIGINT",n),process.removeListener("SIGTERM",n),t(e,e=>{(r||0!==e)&&process.exit(e)})}),process.on("SIGINT",n),process.on("SIGTERM",n)},(0,z.XY)(e=>B.yw5(e[0]),(e,t)=>{let r=t?.disableErrorReporting===!0?B.MY7(e):B.MY7(B.dGm(e,e=>F.nn(e)?B.rIH:(e=>{if("object"==typeof e&&null!==e&&X in e){let t=e[X];if("boolean"==typeof t)return t}return!0})(F.iw(e))?B.vVN(e):B.rIH));try{let e=globalThis.setInterval(z.Yi,0x7fffffff);r.addObserver(()=>{clearInterval(e)})}catch{}return a({fiber:r,teardown:t?.teardown??W})}));var G=n(5633),V=n(9237),H=n(3614),K=n(664),Q=n(3265),Z=n(1179),ee=n(1587),et=n(4942);let er="~effect/PlatformError";class en extends et.rN("BadArgument"){get message(){return`${this.module}.${this.method}${this.description?`: ${this.description}`:""}`}}class ei extends et.$D{get message(){return`${this._tag}: ${this.module}.${this.method}${void 0!==this.pathOrDescriptor?` (${this.pathOrDescriptor})`:""}${this.description?`: ${this.description}`:""}`}}class ea extends et.rN("PlatformError"){constructor(e){"cause"in e?super({reason:e,cause:e.cause}):super({reason:e})}[er]=er;get message(){return this.reason.message}}let es=e=>new ea(new ei(e)),eo=e=>new ea(new en(e));var el=n(3952),ed=n(2449);let ec="~effect/MutableRef",eu={[ec]:ec,...ed.fU,toJSON(){return{_id:"MutableRef",current:(0,el.aB)(this.current)}}},ef=e=>{let t=Object.create(eu);return t.current=e,t};var ep=n(1554),eh=n(4233),em=n(3753),eg=n(9771),ey=n(6297);let ev=Symbol.for("effect/MutableList/Empty"),eb=e=>{let t=e.head;t.offset>=1024&&t===e.tail&&t.mutable&&(t.array.length-t.offset)*8<=t.offset&&(e.head=e.tail={array:t.array.slice(t.offset),mutable:!0,offset:0,next:void 0})},e_=()=>({array:[],mutable:!0,offset:0,next:void 0}),ex=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=e_(),e.tail=e.tail.next):e.head=e.tail=e_(),e.tail.array.push(t),e.length++},ew=e=>{e.head=e.tail=void 0,e.length=0},ek=e=>{if(!e.head)return ev;let t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length?e.head.next?e.head=e.head.next:ew(e):eb(e),t},eS={_A:z.D_,_E:z.D_},eI={"~effect/Queue":eS,"~effect/Queue/Enqueue":eS,"~effect/Queue/Dequeue":eS,...ed.fU,toJSON(){return{_id:"effect/Queue",state:this.state._tag,size:eU(this)}}},e$=e=>ed.R6(t=>{let r=Object.create(eI);return r.dispatcher=t.currentDispatcher,r.capacity=e?.capacity??1/0,r.strategy=e?.strategy??"suspend",r.messages={head:void 0,tail:void 0,length:0},r.scheduleRunning=!1,r.state={_tag:"Open",takers:new Set,offers:new Set,awaiters:new Set},ey.PyW(r)}),eE=(0,z.XY)(2,(e,t)=>ey.DYE(()=>eO(e,t)?eB:"Open"===e.state._tag&&"suspend"===e.strategy?eG(e,t):eF)),eO=(e,t)=>"Open"===e.state._tag&&(e.messages.length>=e.capacity?"sliding"===e.strategy?(ek(e.messages),ex(e.messages,t),!0):e.capacity<=0&&e.state.takers.size>0&&(ex(e.messages,t),eW(e),!0):(ex(e.messages,t),eJ(e),!0)),eC=(0,z.XY)(2,(e,t)=>ey.OH5(()=>eT(e,t))),eT=(e,t)=>{if("Open"!==e.state._tag)return!1;let r=ed.cb(t),n=ey.il9(r,eL);return 0===e.state.offers.size&&0===e.messages.length?eZ(e,n):(e.state={...e.state,_tag:"Closing",exit:n},eJ(e)),!0},eM=e=>eT(e,ed.OE(ed.RS())),eA=e=>ey.OH5(()=>eN(e)),eN=e=>{if("Done"===e.state._tag)return!1;ew(e.messages);let t=e.state.offers;for(let r of(eZ(e,"Open"===e.state._tag?ez:e.state.exit),t))eH(r);return!0},eP=e=>eR(e,1,1/0),eR=(0,z.XY)(3,(e,t,r)=>(t=eg.S(t),r=eg.S(r),ey.DYE(()=>eY(e,t,r)??ey.hgn(eq(e,()=>eX(e,t)),eR(e,t,r))))),ej=e=>ey.DYE(()=>eD(e)??ey.hgn(eq(e,()=>eX(e,1)),ej(e))),eD=e=>{if("Done"===e.state._tag)return e.state.exit;if(e.messages.length>0){let t=ek(e.messages);return eQ(e),ed.xt(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=eK(e.state.offers);return eQ(e),ed.xt(t)}},eU=e=>"Done"===e.state._tag?0:e.messages.length,eF=ed.xt(!1),eB=ed.xt(!0),eL=ed.Rk(ed.RS()),ez=ey._sz(),eW=e=>{if("Done"!==e.state._tag&&0!==e.state.takers.size){for(let t of e.state.takers)if(t.ready()&&(e.state.takers.delete(t),t.resume(ey.x5l),0===e.messages.length))break}},eJ=e=>{e.scheduleRunning||"Done"===e.state._tag||0===e.state.takers.size||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,eW(e)},0))},eY=(e,t,r)=>{if("Done"===e.state._tag)return e.state.exit;if(r<=0||t<=0)return ed.xt([]);if(!eX(e,t))return;let n=e.messages.length>0?((e,t)=>{if((t=eg.S(t))<=0||!e.head)return[];if((t=Math.min(t,e.length))===e.length&&e.head?.offset===0&&!e.head.next){let t=e.head.array;return ew(e),t}let r=Array(t),n=0,i=e.head;for(;i;){for(;i.offset<i.array.length;)if(r[n++]=i.array[i.offset],i.mutable&&(i.array[i.offset]=void 0),i.offset++,n===t)return e.head=i.offset===i.array.length&&i.next?i.next:i,e.length-=t,0===e.length?ew(e):eb(e),r;i=i.next}return ew(e),r})(e.messages,r):[eK(e.state.offers)];return eQ(e),ed.xt(n)},eX=(e,t)=>e.messages.length>=("Closing"===e.state._tag?1:Math.min(t,e.capacity||1))||e.capacity<=0&&"Done"!==e.state._tag&&e.state.offers.size>0,eq=(e,t)=>ey.E2r(r=>{if("Done"===e.state._tag)return r(e.state.exit);if(t())return r(ey.x5l);let n={ready:t,resume:r};return e.state.takers.add(n),ey.OH5(()=>{"Done"!==e.state._tag&&e.state.takers.delete(n)})}),eG=(e,t)=>ey.E2r(r=>eO(e,t)?r(eB):eV(e,{_tag:"Single",message:t,resume:r})),eV=(e,t)=>{if("Open"!==e.state._tag)return eH(t);let r=e.state.offers;return r.add(t),ey.OH5(()=>{"Done"!==e.state._tag&&(r.delete(t),"Closing"===e.state._tag&&0===r.size&&0===e.messages.length&&eZ(e,e.state.exit))})},eH=e=>"Single"===e._tag?e.resume(eF):e.resume(ed.xt(e.remaining.slice(e.offset))),eK=e=>{let t=e.values().next().value;if("Single"===t._tag)return e.delete(t),t.resume(eB),t.message;let r=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(ed.xt([]))),r},eQ=e=>{if("Done"===e.state._tag)return em.Og(e.state.exit.cause);if(0===e.state.offers.size)return"Closing"===e.state._tag&&0===e.messages.length&&(eZ(e,e.state.exit),em.Og(e.state.exit.cause));for(let t of e.state.offers){let r=e.capacity-e.messages.length;if(r<=0)break;if("Single"===t._tag)ex(e.messages,t.message),e.state.offers.delete(t),t.resume(eB);else{for(;t.offset<t.remaining.length;t.offset++){if(0===r)return!1;ex(e.messages,t.remaining[t.offset]),r--}e.state.offers.delete(t),t.resume(ed.xt([]))}}return!1},eZ=(e,t)=>{if("Done"===e.state._tag)return;let r=e.state;for(let n of(e.state={_tag:"Done",exit:t},r.takers))n.resume(t);for(let e of(r.takers.clear(),r.awaiters))e(t);r.awaiters.clear()};var e0=n(5744);let e1="~effect/Channel",e2=e=>(0,eh.i5)(e,e1),e5={[e1]:{_Env:z.D_,_InErr:z.D_,_InElem:z.D_,_OutErr:z.D_,_OutElem:z.D_},pipe(){return(0,ep.tT)(this,arguments)}},e3=e=>{let t=Object.create(e5);return t.transform=(t,r)=>B.Tyx(e(t,r),e=>B.PyW(B.ATB(e))),t},e6=(e,t)=>e3((r,n)=>B.qIB(e9(e)(r,n),e=>t(e,n))),e8=e=>e3((t,r)=>e),e9=e=>e.transform,e4=e8(B.PyW(F.Vw()));B.ZmZ;let e7=(0,z.XY)(2,(e,t)=>e6(e,e=>B.OH5(()=>{let r=0;return B.TjK(e,e=>t(e,r++))}))),te=(0,z.XY)(2,(e,t)=>tt(e,e=>B.PyW(t(e)))),tt=(0,z.XY)(2,(e,t)=>e6(e,e=>B.PyW(em.m8(e,e=>B.qIB(t(e),F.Vw))))),tr=(0,z.XY)(e=>e2(e[0])&&e2(e[1]),(e,t,r)=>{let n;return n=B.D9k(function*(n,i,a){let s=r?.haltStrategy??"both",o=yield*e$({capacity:0});yield*e0.U9(a,eA(o));let l=0,d=(e,t,r)=>e9(t)(n,r).pipe(B.qIB(e=>e.pipe(B.qIB(e=>eE(o,e)),B.i4r)),B.S5A(t=>B.hgn(e0.VN(r,em.aU(t)),function(e,t){if(l++,!em.Og(t))return eC(o,t);switch(s){case"both":return 2===l?eC(o,t):B.rIH;case"left":case"right":return e===s?eC(o,t):B.rIH;case"either":return eC(o,t)}}(e,t))),B.ar0(a));return yield*d("left",e,e0.Fp(a)),yield*d("right",t,e0.Fp(a)),ej(o)}),e3(B.D9k(function*(e,t){let r=e0.Fp(t),i=e=>e0.VN(r,em.aU(e)),a=yield*B.S5A(n(e,t,r),i);return B.S5A(a,i)}))}),tn=(0,z.XY)(2,(e,t)=>e3((r,n)=>B.qIB(e9(e)(r,n),e=>e9(t)(e,n)))),ti=e=>e3((t,r)=>{let n;return B.PyW(B.DYE(()=>n||e.pipe(e0.Gt(r),B.qIB(e=>e9(e)(t,r)),B.qIB(e=>n=e))))}),ta=(e,t,r)=>B.DYE(()=>{let n=e0.LZ(),i=e9(e)(F.Vw(),n);return em.m8(B.qIB(i,t),r||B.PyW).pipe(B.cfM(e=>e0.VN(n,e)))}),ts=(0,z.XY)(2,(e,t)=>ta(e,e=>B.i4r(B.qIB(e,t),{disableYield:!0}))),to=(0,z.XY)(3,(e,t,r)=>B.DYE(()=>{let n=t();return ta(e,e=>B.iMI({while:z.ue,body:()=>e,step:e=>{n=r(n,e)}}),()=>B.PyW(n))})),tl=(0,z.XY)(3,(e,t,r)=>B.DYE(()=>{let n=t();return ta(e,e=>B.iMI({while:z.ue,body:(0,z.dY)(e.pipe(B.qIB(e=>r(n,e)),B.TjK(e=>{n=e}))),step:z.Yi}),()=>B.PyW(n))})),td=(e,t)=>e9(e)(F.Vw(),t),tc="~effect/Sink",tu=B.PyW([void 0]),tf={[tc]:{_A:z.D_,_In:z.D_,_L:z.D_,_E:z.D_,_R:z.D_},pipe(){return(0,ep.tT)(this,arguments)}},tp=e=>(0,eh.i5)(e,tc),th=e=>tm((t,r)=>e9(e)(t,r).pipe(B.qIB(B.i4r({disableYield:!0})),em.m8(B.PyW))),tm=e=>{let t=Object.create(tf);return t.transform=e,t},tg=e=>e3((t,r)=>B.PyW(B.qIB(e.transform(t,r),F.Vw)));B.ZmZ;let ty=tm(e=>em.m8(B.i4r(e,{disableYield:!0}),()=>tu));ee.none,ee.isNone,ee.none;let tv=e=>th(ti(B.TjK(e,tg))),tb={_R:z.D_,_E:z.D_,_A:z.D_},t_=function(e){this.channel=e};t_.prototype={"~effect/Stream":tb,pipe(){return(0,ep.tT)(this,arguments)}};let tx=e=>(0,eh.i5)(e,"~effect/Stream"),tw=e=>new t_(e),tk=e=>e.channel,tS=tw(e4),tI=e=>{let t;return tw((t=()=>e().channel,e3((e,r)=>B.DYE(()=>e9(t())(e,r)))))},t$=e=>{let t;return K.ET(e)?tw((t=B.PyW(e),e8(B.OH5(()=>{let e=!1;return B.DYE(()=>e?F.Vw():(e=!0,t))})))):tS},tE=e=>tw(ti(B.TjK(e,tk))),tO=(0,z.XY)(2,(e,t)=>tI(()=>{let r=0;return tw(e7(e.channel,K.Tj(e=>t(e,r++))))})),tC=(0,z.XY)(e=>tx(e[0])&&tx(e[1]),(e,t,r)=>tw(tr(tk(e),tk(t),r))),tT=(0,z.XY)(2,(e,t)=>{let r;return r=(e,r)=>B.OH5(()=>{let n,i,a=B.DYE(()=>{if(void 0!==i){let e=i;return i=void 0,B.PyW(e)}return e}).pipe(B.MfU(e=>(n=L.fJ(e),F.Vw()))),s=B.TjK(B.DYE(()=>t.transform(a,r)),([e,t])=>(i=t,K.of(e)));return B.DYE(()=>n||s)}),tw(e3((t,n)=>B.qIB(td(e.channel,n),e=>r(e,n))))}),tM=(0,z.XY)(e=>tx(e[0]),(e,t)=>tI(()=>{let r=new TextDecoder(t?.encoding);return tO(e,e=>r.decode(e,{stream:!0}))})),tA=(0,z.XY)(2,(e,t)=>B.Pxi(r=>td(e.channel,r).pipe(B.qIB(e=>t.transform(e,r)),B.TjK(([e])=>e)))),tN=(0,z.XY)(3,(e,t,r)=>tl(e.channel,t,(e,t)=>{let n=0,i=e;return B.TjK(B.iMI({while:()=>n<t.length,body:()=>r(i,t[n]),step(e){i=e,n++}}),()=>i)})),tP=((e,t)=>ts(e.channel,t),"~effect/FileSystem"),tR=Z.kl("effect/FileSystem"),tj="~effect/FileSystem/File";class tD extends(Z.kl())("effect/FileSystem/WatchBackend"){}let tU="~effect/Path",tF=Z.kl("effect/Path");var tB=n(3811),tL=n(9315);function tz(){return Object.assign(e=>e,{option:e=>ee.some(e),result:e=>tL.Py(e),is:e=>!0})}let tW=tz(),tJ=tz(),tY="~effect/process/ChildProcessSpawner/ChildProcessHandle",tX={[tY]:tY,...el.os,toJSON(){return{_id:"ChildProcessHandle",pid:this.pid}}},tq=e=>Object.setPrototypeOf({...e},tX);class tG extends(Z.kl())("effect/process/ChildProcessSpawner"){}let tV="~effect/process/ChildProcess",tH={...tB.bp({label:"Command",evaluate(e){return Z.fp(e.context,tG).spawn(this)}}),[tV]:tV},tK=(e,t,r)=>Object.assign(Object.create(tH),{_tag:"StandardCommand",command:e,args:t,options:r}),tQ=function(...e){if(tZ(e[0])){let[t,...r]=e,n=t2(t,r);return tK(n[0]??"",n.slice(1),{})}if("object"==typeof e[0]&&!Array.isArray(e[0])&&!tZ(e[0])){let t=e[0];return function(e,...r){let n=t2(e,r);return tK(n[0]??"",n.slice(1),t)}}if("string"==typeof e[0]&&!Array.isArray(e[1])){let[t,r={}]=e;return tK(t,[],r)}let[t,r=[],n={}]=e;return tK(t,r,n)},tZ=e=>Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw),t0=e=>{let t=/^fd(\d+)$/.exec(e);if(null===t)return;let r=parseInt(t[1],10);return r>=3?r:void 0},t1=e=>`fd${e}`,t2=(e,t)=>{let r=[];for(let[n,i]of e.entries())r=t5(e,t,r,i,n);return r},t5=(e,t,r,n,i)=>{let a=e.raw[i];if(void 0===a)throw Error(`Invalid backslash sequence: ${e.raw[i]}`);let{hasLeadingWhitespace:s,hasTrailingWhitespace:o,tokens:l}=t9(n,a),d=t4(r,l,s);if(i===t.length)return d;let c=t[i];return t4(d,Array.isArray(c)?c.map(e=>t3(e)):[t3(c)],o)},t3=e=>"string"==typeof e?e:String(e),t6=new Set([" "," ","\r","\n"]),t8={x:3,u:5},t9=(e,t)=>{if(0===t.length)return{tokens:[],hasLeadingWhitespace:!1,hasTrailingWhitespace:!1};let r=t6.has(t[0]),n=[],i=0;for(let r=0,a=0;r<e.length;r+=1,a+=1){let s=t[a];if(t6.has(s))i!==r&&n.push(e.slice(i,r)),i=r+1;else if("\\"===s){let e=t[a+1];if("\n"===e)r-=1,a+=1;else if("u"===e&&"{"===t[a+2]){let e=t.indexOf("}",a+3);parseInt(t.slice(a+3,e),16)>65535&&(r+=1),a=e}else a+=t8[e]??1}}let a=i===e.length;return a||n.push(e.slice(i)),{tokens:n,hasLeadingWhitespace:r,hasTrailingWhitespace:a}},t4=(e,t,r)=>r||0===e.length||0===t.length?[...e,...t]:[...e.slice(0,-1),`${e.at(-1)}${t.at(0)}`,...t.slice(1)],t7=t("node:child_process"),re=t("node:stream"),rt=(e,t)=>(r,[n])=>{let i="Unknown";switch(r.code){case"ENOENT":i="NotFound";break;case"EACCES":i="PermissionDenied";break;case"EEXIST":i="AlreadyExists";break;case"EISDIR":case"ENOTDIR":case"ELOOP":i="BadResource";break;case"EBUSY":i="Busy"}return es({_tag:i,module:e,method:t,pathOrDescriptor:n,syscall:r.syscall,cause:r})},rr=e=>th(te(rn(e),e=>[e])),rn=e=>e3(t=>{let r=e.evaluate();return B.PyW(ri({...e,writable:r,pull:t}))}),ri=e=>e.pull.pipe(B.qIB(t=>{let r=0;return B.E2r(n=>{let i=!1,a=()=>{for(;r<t.length;){if(i)return;if(!e.writable.write(t[r++],e.encoding)){i||e.writable.once("drain",a);return}}i||n(B.rIH)};return a(),B.OH5(()=>{i=!0,e.writable.off("drain",a)})})}),B.i4r({disableYield:!0}),!1!==e.endOnDone?em.m8(t=>"closed"in e.writable&&e.writable.closed?F.Vw(t):B.E2r(r=>{let n=()=>r(F.Vw(t));return e.writable.once("finish",n),e.writable.end(),B.OH5(()=>{e.writable.off("finish",n)})})):z.D_,B.KT6(B.E2r(t=>{let r=r=>t(B.fJG(e.onError(r)));return e.writable.once("error",r),B.OH5(()=>{e.writable.off("error",r)})})));ey.zFM,ey.C6p;let ra=ey.D7p;ey.INJ;let rs=ey.mKq;ey.eGS,ey.DKo,ey.$MQ;let ro=ey.Iku,rl=ey.vTQ,rd=ey.zzk;ey.Fbb;let rc=e=>tw(ru(e)),ru=e=>e3((t,r)=>rf({scope:r,readable:e.evaluate(),onError:e.onError??rp,chunkSize:e.chunkSize,closeOnDone:e.closeOnDone})),rf=e=>{let t=e.readable,r=e.closeOnDone??!0,n=e.exit??ef(void 0),i=e.latch??rd(!1);function a(){i.openUnsafe()}function s(t){n.current=L.fJ(e.onError(t)),i.openUnsafe()}function o(){n.current=L.fJ(F.RS()),i.openUnsafe()}t.on("readable",a),t.once("error",s),t.once("end",o);let l=B.DYE(function r(){let a=e.readable.read(e.chunkSize);if(null===a)return n.current?n.current:t.readableEnded?B.fJG(F.RS()):(i.closeUnsafe(),B.qIB(i.await,r));let s=K.of(a);for(;null!==(a=e.readable.read(e.chunkSize));)s.push(a);return B.PyW(s)});return B.as(e0.U9(e.scope,B.OH5(()=>{t.off("readable",a),t.off("error",s),t.off("end",o),r&&"closed"in e.readable&&!e.readable.closed&&e.readable.destroy()})),l)};re.Readable;let rp=e=>new F.Bk(e),rh=e=>e instanceof globalThis.Error?e:new globalThis.Error(String(e)),rm=(e,t,r)=>{let{commands:n}=r_(r),i=n.reduce((e,t)=>{let r=`${t.command} ${t.args.join(" ")}`;return 0===e.length?r:`${e} | ${r}`},"");return rt("ChildProcess",e)(t,[i])},rg=(e,t)=>{if(!V.NJ(t))return!0;if("win32"===globalThis.process.platform)return!1;try{return globalThis.process.kill(-e.pid,0),!0}catch{return!1}},ry=(e,t=()=>{})=>t7.execFile("taskkill",["/pid",String(e.pid),"/T","/F"],{windowsHide:!0},t),rv=B.JkU(function*(){let e,t,r=yield*tR,n=yield*tF,i=B.D9k(function*(e){if(!eh.b0(e.cwd))return yield*r.access(e.cwd),n.resolve(e.cwd)}),a=e=>tp(e)?"pipe":e,s=e=>{let t={stream:"pipe",encoding:"utf-8",endOnDone:!0};return eh.b0(e.stdin)?t:"string"==typeof e.stdin||tx(e.stdin)?{...t,stream:e.stdin}:{stream:e.stdin.stream,encoding:e.stdin.encoding??t.encoding,endOnDone:e.stdin.endOnDone??t.endOnDone}},o=(e,t)=>{let r=e[t];return eh.b0(r)?{stream:"pipe"}:"string"==typeof r||tp(r)?{stream:r}:{stream:r.stream}},l=B.D9k(function*(e,t,r){if(0===r.length)return{getInputFd:()=>ty,getOutputFd:()=>tS};let n=new Map,i=new Map;for(let{config:a,fd:s}of r){let r=t.stdio[s];switch(a.type){case"input":{let t=ty;r&&"write"in r&&(t=rr({evaluate:()=>r,onError:t=>rm(`fromWritable(fd${s})`,rh(t),e)})),a.stream&&(yield*B.x6Z(tA(a.stream,t))),n.set(s,t);break}case"output":{let t=tS;if(r&&"read"in r){let n=new re.PassThrough;r.on("error",e=>n.destroy(e)),r.pipe(n),t=rc({evaluate:()=>n,onError:t=>rm(`fromReadable(fd${s})`,rh(t),e)})}a.sink&&(t=tT(t,a.sink)),i.set(s,t)}}}return{getInputFd:e=>n.get(e)??ty,getOutputFd:e=>i.get(e)??tS}}),d=(e,t,r)=>B.E2r(n=>{let i,a=Date.now()+r,s=()=>{clearTimeout(i),e.removeListener("exit",o)},o=()=>{if(clearTimeout(i),Date.now()>=a||!rg(e,t)){s(),n(B.rIH);return}i=setTimeout(o,10)};return e.on("exit",o),o(),B.OH5(s)}),c=B.D9k(function*(e,t,r,n){let i=r=>("win32"===globalThis.process.platform?B.E2r(r=>{ry(t,t=>{t?r(B.fJG(rm("kill",rh(t),e))):r(B.rIH)})}):B.SvU({try:()=>{globalThis.process.kill(-t.pid,r)},catch:t=>rm("kill",rh(t),e)})).pipe(B.MfU(()=>B.DYE(()=>{if(!t.kill(r)){let t=new globalThis.Error("Failed to kill child process");return B.fJG(rm("kill",t,e))}return B.rIH})));yield*i(n?.killSignal??"SIGTERM"),eh.b0(n?.forceKillAfter)?yield*d(t,r,1e3):(yield*d(t,r,H.kE(n.forceKillAfter)),rg(t,r)&&(yield*i("SIGKILL"),yield*d(t,r,1e3))),yield*V.Tx(r)}),u=(e,t)=>{let r=t??"stdout";switch(r){case"stdout":return e.stdout;case"stderr":return e.stderr;case"all":return e.all;default:{let t=t0(r);if(eh.EA(t))return e.getOutputFd(t);return e.stdout}}},f=B.D9k(function*(e){switch(e._tag){case"StandardCommand":{var t,r,n;let d,u,f,p,h,m,g,y,v=s(e.options),b=o(e.options,"stdout"),_=o(e.options,"stderr"),x=(e=>{if(eh.b0(e.additionalFds))return[];let t=[];for(let[r,n]of Object.entries(e.additionalFds)){let e=t0(r);eh.EA(e)&&t.push({fd:e,config:n})}return t.sort((e,t)=>e.fd-t.fd)})(e.options),w=!0,k=yield*i(e.options),S=(d=e.options).extendEnv?{...globalThis.process.env,...d.env}:d.env,I=((e,t,r,n)=>{let i,s=[tx(i=e.stream)?"pipe":i,a(t.stream),a(r.stream)];if(0===n.length)return s;let o=n.reduce((e,{fd:t})=>Math.max(e,t),2);for(let e=3;e<=o;e++)s[e]="ignore";for(let{fd:e}of n)s[e]="pipe";return s})(v,b,_,x),[$,E]=yield*B.Q56((t=e.options,r={cwd:k,env:S,stdio:I},n=process.platform,u=t.detached??"win32"!==n,f={...r,detached:u,shell:t.shell,windowsHide:t.windowsHide??!u},B.E2r(t=>{let r=V.LZ(),n=t7.spawn(e.command,e.args,f);return n.on("error",r=>{t(B.fJG(rm("spawn",r,e)))}),n.on("exit",(...e)=>{V.$w(r,L.Py(e))}),n.on("spawn",()=>{t(B.PyW([n,r]))}),B.OH5(()=>{n.kill("SIGTERM")})})),B.D9k(function*([t,r]){if(yield*V.$L(r)){let[n]=yield*V.Tx(r);0!==n&&eh.Pe(n)?yield*B.XeO(c(e,t,r,e.options)):w&&"win32"!==process.platform&&!1!==e.options.detached&&(yield*B.XeO(c(e,t,r,e.options)));return}w&&(yield*B.XeO(c(e,t,r,e.options)))})),O=tJ($.pid);$.on("exit",t=>{0!==t&&eh.Pe(t)&&((e,t)=>{if("win32"===globalThis.process.platform)return ry(e);try{globalThis.process.kill(-e.pid,t)}catch{}})($,e.options.killSignal??"SIGTERM")});let C=B.OH5(()=>{w||($.ref(),w=!0)}),T=B.OH5(()=>(w&&($.unref(),w=!1),C)),M=yield*B.DYE(()=>{let t=ty;return(eh.Pe($.stdin)&&(t=rr({evaluate:()=>$.stdin,onError:t=>rm("fromWritable(stdin)",rh(t),e),endOnDone:v.endOnDone,encoding:v.encoding})),tx(v.stream))?B.as(B.x6Z(tA(v.stream,t)),t):B.PyW(t)}),{all:A,stderr:N,stdout:P}=(h=$.stdout?(p=new re.PassThrough,$.stdout.on("error",e=>p.destroy(e)),$.stdout.pipe(p),rc({evaluate:()=>p,onError:t=>rm("fromReadable(stdout)",rh(t),e)})):tS,g=$.stderr?(m=new re.PassThrough,$.stderr.on("error",e=>m.destroy(e)),$.stderr.pipe(m),rc({evaluate:()=>m,onError:t=>rm("fromReadable(stderr)",rh(t),e)})):tS,tp(b.stream)&&(h=tT(h,b.stream)),tp(_.stream)&&(g=tT(g,_.stream)),y=tC(h,g),{stdout:h,stderr:g,all:y}),{getInputFd:R,getOutputFd:j}=yield*l(e,$,x),D=B.TjK(V.$L(E),e=>!e);return tq({pid:O,exitCode:B.qIB(V.Tx(E),([t,r])=>{if(eh.Pe(t))return B.PyW(tW(t));let n=new globalThis.Error(`Process interrupted due to receipt of signal: '${r}'`);return B.fJG(rm("exitCode",n,e))}),isRunning:D,kill:t=>c(e,$,E,t),stdin:M,stdout:P,stderr:N,all:A,getInputFd:R,getOutputFd:j,unref:T})}case"PipedCommand":{let{commands:t,pipeOptions:r}=r_(e),[n,...i]=t,a=[(yield*f(n))];for(let e=0;e<i.length;e++){let t=i[e],n=r[e]??{},o=s(t.options),l=tE(B.PyW(u(a[a.length-1],n.from))),d=n.to??"stdin";if("stdin"===d)a.push((yield*f(tQ(t.command,t.args,{...t.options,stdin:{...o,stream:l}}))));else{let e=t0(d);if(eh.EA(e)){let r=t1(e),n=t.options.additionalFds??{};a.push((yield*f(tQ(t.command,t.args,{...t.options,additionalFds:{...n,[r]:{type:"input",stream:l}}}))))}else a.push((yield*f(tQ(t.command,t.args,{...t.options,stdin:{...o,stream:l}}))))}}let o=a[a.length-1],l=B.JkU(function*(){let e=[];for(let t of a)e.push((yield*t.unref));return B.jJl([...e].reverse(),e=>e,{discard:!0})});return tq({pid:o.pid,exitCode:o.exitCode,isRunning:o.isRunning,kill:e=>B.jJl([...a].reverse(),t=>B.XeO(t.kill(e)),{discard:!0}),stdin:a[0].stdin,stdout:o.stdout,stderr:o.stderr,all:o.all,getInputFd:o.getInputFd,getOutputFd:o.getOutputFd,unref:l})}}});return e=(e,t)=>f(e).pipe(B.TjK(e=>tM(t?.includeStderr===!0?e.all:e.stdout)),tE),t=(t,r)=>e(t,r).channel.pipe(tn(e3((e,t)=>B.OH5(()=>{let t="",r=!1,n=ee.none(),i=B.DYE(()=>"Some"===n._tag?F.Vw(n.value):em.tv(e,{onSuccess:a,onFailure:B.ATB,onDone:e=>{if(n=ee.some(e),t.length>0){let e=t;return t="",r=!1,B.PyW([e])}return F.Vw(e)}}));function a(e){let n=function(e){let n=[];function i(e){0===t.length?n.push(e):(n.push(t+e),t="")}for(let n=0;n<e.length;n++){let a=e[n];if(0!==a.length){let e=0,n=a.indexOf("\r"),s=a.indexOf("\n");for(r&&(0===s&&(e=1,s=a.indexOf("\n",e)),r=!1);-1!==n||-1!==s;)-1===n||-1!==s&&s<n?(i(a.substring(e,s)),e=s+1,s=a.indexOf("\n",e)):(i(a.substring(e,n)),a.length===n+1?(r=!0,e=a.length,n=-1):(e=n+(s===n+1?2:1),n=a.indexOf("\r",e),s=a.indexOf("\n",e)));t+=a.substring(e)}}return K.ET(n)?n:null}(e);return null!==n?B.PyW(n):i}return i}))),tw),tG.of({spawn:f,exitCode:e=>B.P1j(B.qIB(f(e),e=>e.exitCode)),streamString:e,streamLines:t,lines:(e,r)=>to(t(e,r).channel,()=>[],(e,t)=>{for(let r=0;r<t.length;r++)e.push(t[r]);return e}),string:(t,r)=>to(e(t,r).channel,()=>"",(e,t)=>e+t.join(""))})}),rb=G.QZ(tG,rv),r_=e=>{let t=[],r=[],n=e=>{switch(e._tag){case"StandardCommand":t.push(e);break;case"PipedCommand":n(e.left),r.push(e.options),n(e.right)}};if(n(e),0===t.length)throw Error("flattenCommand produced empty commands array");let[i,...a]=t;return{commands:[i,...a],pipeOptions:r}},rx="0123456789ABCDEFGHJKMNPQRSTVWXYZ",rw=e=>e.toString(16).padStart(2,"0"),rk=e=>[e.subarray(0,4),e.subarray(4,6),e.subarray(6,8),e.subarray(8,10),e.subarray(10,16)].map(e=>Array.from(e,rw).join("")).join("-"),rS=()=>globalThis.crypto.getRandomValues(new Uint8Array(16));function rI(e=rS()){return e[6]=15&e[6]|64,e[8]=63&e[8]|128,e}function r$(e,t=rS()){let r=Math.min(Math.max(0,Math.trunc(e)),0xffffffffffff);return t[0]=Math.floor(r/0x10000000000),t[1]=255&Math.floor(r/0x100000000),t[2]=255&Math.floor(r/0x1000000),t[3]=255&Math.floor(r/65536),t[4]=255&Math.floor(r/256),t[5]=255&r,t[6]=15&t[6]|112,t[8]=63&t[8]|128,t}let rE="~effect/Crypto",rO=Z.kl("effect/Crypto");var rC=n(7598);let rT=(s=(D={randomBytes:rC.randomBytes,digest:(e,t)=>B.SvU({try:()=>Uint8Array.from(rC.createHash((e=>{switch(e){case"SHA-1":return"sha1";case"SHA-256":return"sha256";case"SHA-384":return"sha384";case"SHA-512":return"sha512"}})(e)).update(t).digest()),catch:e=>es({module:"Crypto",method:"digest",_tag:"Unknown",description:"Could not compute digest",cause:e})})}).randomBytes,o=e=>(31&e[0])*0x1000000000000+0x10000000000*e[1]+0x100000000*e[2]+0x1000000*e[3]+65536*e[4]+256*e[5]+e[6],l=()=>o(s(7))/0x20000000000000,d=()=>{for(;;){let e=s(7),t=o(e);if((32&e[0])==0)return t+Number.MIN_SAFE_INTEGER;if(t<Number.MAX_SAFE_INTEGER)return t+1}},rO.of({[rE]:rE,randomBytes:e=>{let t,r;return B.TjK((t="randomBytes",Number.isSafeInteger(r=e)&&r>=0?B.PyW(r):B.fJG(eo({module:"Crypto",method:t,description:"size must be a non-negative safe integer"}))),s)},nextDoubleUnsafe:l,nextIntUnsafe:d,digest:D.digest,random:B.OH5(()=>l()),randomBoolean:B.OH5(()=>l()>.5),randomInt:B.OH5(()=>d()),randomBetween:(e,t)=>B.OH5(()=>((e,t,r)=>{let n=r*(t-e)+e;if(n!==t||e>=t||!Number.isFinite(t))return n;if(0===t)return -5e-324;let i=new DataView(new ArrayBuffer(8));i.setFloat64(0,t);let a=i.getBigUint64(0);return i.setBigUint64(0,t>0?a-BigInt(1):a+BigInt(1)),i.getFloat64(0)})(e,t,l())),randomIntBetween(e,t,r){let n=+(r?.halfOpen!==!0);return B.OH5(()=>{let r=Math.ceil(e),i=Math.floor(t);return Math.floor(l()*(i-r+n))+r})},randomShuffle:e=>B.OH5(()=>{let t=Array.from(e);for(let e=t.length-1;e>=1;e-=1){let r=Math.min(e,Math.floor(l()*(e+1))),n=t[e];t[e]=t[r],t[r]=n}return t}),randomUUIDv4:B.OH5(()=>{let e;return rk(void 0===(e=s(16))?rI():rI(e))}),randomUUIDv7:B.RKA(e=>{let t,r;return B.PyW((t=e.currentTimeMillisUnsafe(),rk(void 0===(r=s(16))?r$(t):r$(t,r))))}),randomULID:B.RKA(e=>B.PyW(((e,t)=>{if(10!==t.length)throw Error(`ULID randomness must be exactly 10 bytes, received ${t.length}`);let r=Math.min(Math.max(0,Math.trunc(e)),0xffffffffffff),n="";for(let e=45;e>=0;e-=5)n+=rx[31&Math.floor(r/2**e)];let i=0,a=0;for(let e of t){for(i=i<<8|e,a+=8;a>=5;)a-=5,n+=rx[i>>>a&31];i&=(1<<a)-1}return n})(e.currentTimeMillisUnsafe(),s(10))))})),rM=G.Py(rO,rT);var rA=n(5053);let rN=t("node:fs"),rP=t("node:os"),rR=t("node:path");var rj=n.t(rR,2);let rD=e=>t=>eo({module:"FileSystem",method:e,description:t.message??String(t)}),rU=(e,t)=>{let r=Number(e);if(!Number.isSafeInteger(r))throw RangeError(`${t} exceeds the safe integer range: ${e}`);return r},rF=e=>ee.flatMap(ee.fromNullishOr(e),rA.Ro),rB=(e,t)=>B.SvU({try:()=>rU(e,"position"),catch:rD(t)}),rL=(c=(0,B._r7)(rN.access,rt("FileSystem","access"),rD("access")),(e,t)=>{let r=rN.constants.F_OK;return t?.readable&&(r|=rN.constants.R_OK),t?.writable&&(r|=rN.constants.W_OK),c(e,r)}),rz=(u=(0,B._r7)(rN.cp,rt("FileSystem","copy"),rD("copy")),(e,t,r)=>u(e,t,{force:r?.overwrite??!1,preserveTimestamps:r?.preserveTimestamps??!1,recursive:!0})),rW=(f=(0,B._r7)(rN.copyFile,rt("FileSystem","copyFile"),rD("copyFile")),(e,t)=>f(e,t)),rJ=(p=(0,B._r7)(rN.chmod,rt("FileSystem","chmod"),rD("chmod")),(e,t)=>p(e,t)),rY=(h=(0,B._r7)(rN.chown,rt("FileSystem","chown"),rD("chown")),(e,t,r)=>h(e,t,r)),rX=(m=(0,B._r7)(rN.glob,rt("FileSystem","glob"),rD("glob")),(e,t)=>m(e,{cwd:t?.root,exclude:t?.exclude})),rq=(g=(0,B._r7)(rN.link,rt("FileSystem","link"),rD("link")),(e,t)=>g(e,t)),rG=(y=(0,B._r7)(rN.mkdir,rt("FileSystem","makeDirectory"),rD("makeDirectory")),(e,t)=>y(e,{recursive:t?.recursive??!1,mode:t?.mode})),rV=e=>{let t=(0,B._r7)(rN.mkdtemp,rt("FileSystem",e),rD(e));return e=>B.DYE(()=>{let r=e?.prefix??"",n="string"==typeof e?.directory?rR.join(e.directory,"."):rP.tmpdir();return t(r?rR.join(n,r):n+"/")})},rH=rV("makeTempDirectory"),rK=e=>{let t=(0,B._r7)(rN.rm,rt("FileSystem",e),rD(e));return(e,r)=>t(e,{recursive:r?.recursive??!1,force:r?.force??!1})},rQ=rK("remove"),rZ=(v=rV("makeTempDirectoryScoped"),b=rK("makeTempDirectoryScoped"),e=>B.Q56(v(e),e=>B.QgK(b(e,{recursive:!0})))),r0=(U="open",_=(0,B._r7)(rN.open,rt("FileSystem",U),rD(U)),x=(0,B._r7)(rN.close,rt("FileSystem",U),rD(U)),(e,t)=>(0,z.Fs)(B.Q56(_(e,t?.flag??"r",t?.mode),e=>B.QgK(x(e))),B.TjK(e=>r1(e,t?.flag?.startsWith("a")??!1)))),r1=(()=>{let e=e=>(0,B._r7)(rN.read,rt("FileSystem",e),rD(e)),t=e("read"),r=e("readAlloc"),n=(0,B._r7)(rN.fstat,rt("FileSystem","stat"),rD("stat")),i=(0,B._r7)(rN.ftruncate,rt("FileSystem","truncate"),rD("truncate")),a=(0,B._r7)(rN.fsync,rt("FileSystem","sync"),rD("sync")),s=e=>(0,B._r7)(rN.write,rt("FileSystem",e),rD(e)),o=s("write"),l=s("writeAll");class d{[tj];fd;append;position=BigInt(0);constructor(e,t){this[tj]=tj,this.fd=e,this.append=t}get stat(){return B.qIB(n(this.fd,{bigint:!0}),ne)}get sync(){return a(this.fd)}seek(e,t){return B.DYE(()=>{let r="start"===t?e:this.position+e;return r<BigInt(0)?B.fJG(eo({module:"FileSystem",method:"seek",description:"Cannot seek before the start of the file"})):(this.position=r,B.PyW(r))})}read(e){return B.DYE(()=>{let r=this.position;return B.TjK(t(this.fd,{buffer:e,position:r}),e=>(this.position=r+BigInt(e),e))})}readAlloc(e){return B.DYE(()=>{try{if(!Number.isInteger(e)||e<0)throw RangeError("size must be a non-negative integer");let t=Buffer.allocUnsafeSlow(e),n=this.position;return B.TjK(r(this.fd,{buffer:t,position:n}),r=>{if(0===r)return ee.none();if(this.position=n+BigInt(r),r===e)return ee.some(t);let i=Buffer.allocUnsafeSlow(r);return t.copy(i,0,0,r),ee.some(i)})}catch(e){return B.fJG(rD("readAlloc")(e))}})}truncate(e){return B.TjK(i(this.fd,e||void 0),()=>{if(!this.append){let t=BigInt(e??0);this.position>t&&(this.position=t)}})}write(e){return B.DYE(()=>{let t=this.position;return B.qIB(this.append?B.PyW(void 0):rB(t,"write"),r=>B.TjK(o(this.fd,e,void 0,void 0,r),e=>(this.append||(this.position=t+BigInt(e)),e)))})}writeAllChunk(e){return B.DYE(()=>{let t=this.position;return B.qIB(this.append?B.PyW(void 0):rB(t,"writeAll"),r=>B.qIB(l(this.fd,e,void 0,void 0,r),r=>0===r?B.fJG(es({module:"FileSystem",method:"writeAll",_tag:"WriteZero",pathOrDescriptor:this.fd,description:"write returned 0 bytes written"})):(this.append||(this.position=t+BigInt(r)),r<e.length?this.writeAllChunk(e.subarray(r)):B.rIH)))})}writeAll(e){return 0===e.length?B.rIH:this.writeAllChunk(e)}}return(e,t)=>new d(e,t)})(),r2=e=>{let t=rV(e);return B.D9k(function*(e){let r=yield*t(e),n=rC.randomBytes(6).toString("hex"),i=rR.join(r,e?.suffix?`${n}${e.suffix}`:n);return yield*na(i,new Uint8Array(0)),i})},r5=r2("makeTempFile"),r3=(w=r2("makeTempFileScoped"),k=rK("makeTempFileScoped"),e=>B.Q56(w(e),e=>B.QgK(k(rR.dirname(e),{recursive:!0})))),r6=(e,t)=>B.$mh({try:()=>rN.promises.readdir(e,t),catch:t=>rt("FileSystem","readDirectory")(t,[e])}),r8=e=>B.E2r((t,r)=>{try{rN.readFile(e,{signal:r},(r,n)=>{r?t(B.fJG(rt("FileSystem","readFile")(r,[e]))):t(B.PyW(n))})}catch(e){t(B.fJG(rD("readFile")(e)))}}),r9=(S=(0,B._r7)(rN.readlink,rt("FileSystem","readLink"),rD("readLink")),e=>S(e)),r4=(I=(0,B._r7)(rN.realpath,rt("FileSystem","realPath"),rD("realPath")),e=>I(e)),r7=($=(0,B._r7)(rN.rename,rt("FileSystem","rename"),rD("rename")),(e,t)=>$(e,t)),ne=e=>B.SvU({try:()=>({type:e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":e.isBlockDevice()?"BlockDevice":e.isCharacterDevice()?"CharacterDevice":e.isFIFO()?"FIFO":e.isSocket()?"Socket":"Unknown",mtime:ee.fromNullishOr(e.mtime),atime:ee.fromNullishOr(e.atime),birthtime:ee.fromNullishOr(e.birthtime),dev:rU(e.dev,"dev"),rdev:rF(e.rdev),ino:rF(e.ino),mode:rU(e.mode,"mode"),nlink:rF(e.nlink),uid:rF(e.uid),gid:rF(e.gid),size:Q.ee(e.size),blksize:void 0!==e.blksize?ee.some(Q.ee(e.blksize)):ee.none(),blocks:rF(e.blocks)}),catch:rD("stat")}),nt=(E=(0,B._r7)(rN.stat,rt("FileSystem","stat"),rD("stat")),e=>B.qIB(E(e,{bigint:!0}),ne)),nr=(O=(0,B._r7)(rN.symlink,rt("FileSystem","symlink"),rD("symlink")),(e,t)=>O(e,t)),nn=(C=(0,B._r7)(rN.truncate,rt("FileSystem","truncate"),rD("truncate")),(e,t)=>C(e,t)),ni=(T=(0,B._r7)(rN.utimes,rt("FileSystem","utime"),rD("utime")),(e,t,r)=>T(e,t,r)),na=(e,t,r)=>B.E2r((n,i)=>{try{rN.writeFile(e,t,{signal:i,flag:r?.flag,mode:r?.mode},t=>{t?n(B.fJG(rt("FileSystem","writeFile")(t,[e]))):n(B.rIH)})}catch(e){n(B.fJG(rD("writeFile")(e)))}}),ns=B.TjK(B.Nav(tD),e=>{let t;return t={access:rL,chmod:rJ,chown:rY,copy:rz,copyFile:rW,glob:rX,link:rq,makeDirectory:rG,makeTempDirectory:rH,makeTempDirectoryScoped:rZ,makeTempFile:r5,makeTempFileScoped:r3,open:r0,readDirectory:r6,readFile:r8,readLink:r9,realPath:r4,remove:rQ,rename:r7,stat:nt,symlink:nr,truncate:nn,utimes:ni,watch:(t,r)=>nt(t).pipe(B.TjK(n=>e.pipe(ee.flatMap(e=>e.register(t,n,r)),ee.getOrElse(()=>{let e,i;return tw((e=e=>B.Q56(B.OH5(()=>{let i="Directory"===n.type?t:rR.dirname(t),a=rN.watch(t,{recursive:r?.recursive??!1},(t,r)=>{if(r)switch(t){case"rename":return void B.MY7(B.tvg(nt(rR.resolve(i,r)),{onSuccess:t=>eE(e,{_tag:"Create",path:r}),onFailure:t=>eE(e,{_tag:"Remove",path:r})}));case"change":return void eO(e,{_tag:"Update",path:r})}});return a.on("error",r=>{eT(e,F.fJ(es({module:"FileSystem",_tag:"Unknown",method:"watch",pathOrDescriptor:t,cause:r})))}),a.on("close",()=>{eM(e)}),a}),e=>B.OH5(()=>e.close())),i=void 0,e3((t,r)=>B.TjK(e$({capacity:i?.bufferSize,strategy:i?.strategy}).pipe(B.Mim(e=>e0.U9(r,eA(e))),B.Mim(t=>B.ar0(e0.Gt(e(t),r),r))),eP))))}))),tE),writeFile:na},tR.of({...t,[tP]:tP,exists:e=>(0,z.Fs)(t.access(e),B.as(!0),B.KuX("PlatformError",e=>"NotFound"===e.reason._tag?B.PyW(!1):B.fJG(e))),readFileString:(e,r)=>B.qIB(t.readFile(e),e=>B.SvU({try:()=>new TextDecoder(r).decode(e),catch:e=>eo({module:"FileSystem",method:"readFileString",description:"invalid encoding",cause:e})})),stream:B.D9k(function*(e,r){let n=yield*t.open(e,{flag:"r"}),i=r?.offset===void 0?void 0:Q.bN(r.offset);i&&(yield*n.seek(i,"start"));let a=r?.bytesToRead===void 0?void 0:Q.bN(r.bytesToRead),s=BigInt(0),o=Number(BigInt(r?.chunkSize??65536)),l=n.readAlloc(o);return tw(e8(B.PyW(B.qIB(B.DYE(()=>void 0!==a&&a<=s?F.Vw():void 0!==a&&a-s<o?n.readAlloc(Number(a-s)):l),ee.match({onNone:()=>F.Vw(),onSome:e=>(s+=BigInt(e.length),B.PyW(K.of(e)))})))))},tE),sink:(e,r)=>(0,z.Fs)(t.open(e,{...r,flag:r?.flag??"w"}),B.TjK(e=>{let t,r;return t=t=>e.writeAll(t),r=B.jJl(e=>t(e),{discard:!0}),tm(e=>e.pipe(B.qIB(r),B.i4r({disableYield:!0}),em.m8(()=>tu)))}),tv),writeFileString:(e,r,n)=>B.qIB(B.SvU({try:()=>new TextEncoder().encode(r),catch:e=>eo({module:"FileSystem",method:"writeFileString",description:"could not encode string",cause:e})}),r=>t.writeFile(e,r,n))})}),no=(G.QZ(tR))(ns),nl=t("node:url"),nd=e=>({fromFileUrl:t=>B.SvU({try:()=>nl.fileURLToPath(t,{windows:e}),catch:e=>new en({module:"Path",method:"fromFileUrl",cause:e})}),toFileUrl:t=>B.SvU({try:()=>nl.pathToFileURL(t,{windows:e}),catch:e=>new en({module:"Path",method:"toFileUrl",cause:e})})});rR.posix,rR.win32;let nc=(G.Py(tF))({[tU]:tU,...rj,...nd(void 0)}),nu="~effect/Stdio",nf=Z.kl(nu),np=G.Py(nf,(M={args:B.OH5(()=>process.argv.slice(2)),stdinIsTerminal:B.OH5(()=>!0===process.stdin.isTTY),stdoutIsTerminal:B.OH5(()=>!0===process.stdout.isTTY),stdout:e=>rr({evaluate:()=>process.stdout,onError:e=>es({module:"Stdio",method:"stdout",_tag:"Unknown",cause:e}),endOnDone:e?.endOnDone??!1}),stderr:e=>rr({evaluate:()=>process.stderr,onError:e=>es({module:"Stdio",method:"stderr",_tag:"Unknown",cause:e}),endOnDone:e?.endOnDone??!1}),stdin:rc({evaluate:()=>process.stdin,onError:e=>es({module:"Stdio",method:"stdin",_tag:"Unknown",cause:e}),closeOnDone:!1})},{[nu]:nu,stdinIsTerminal:B.PyW(!1),stdoutIsTerminal:B.PyW(!1),...M})),nh={_tag:"Empty"},nm={_tag:"Closed"},ng={_A:z.D_,_E:z.D_};class ny{"~effect/RcRef"=ng;pipe(){return(0,ep.tT)(this,arguments)}state=nh;acquire;context;scope;idleTimeToLive;constructor(e,t,r,n){this.acquire=e,this.context=t,this.scope=r,this.idleTimeToLive=n}}let nv=(e,t,r)=>B.cfM(r(ra(t.fiber)),r=>{let n=t.acquired;return void 0!==n?L.N6(r)?nb(e,n):B.rIH:--t.awaiters>0||e.state!==t?B.rIH:(e.state=nh,rs(t.fiber))}),nb=(e,t)=>{if(t.refCount--,t.refCount>0)return B.rIH;let r=e.idleTimeToLive;return void 0===r||t.invalidated?(e.state===t&&(e.state=nh),e0.VN(t.scope,L.rI)):(H.MI(r)&&(t.fiber=B.FcF(n=>B.qIB(n(B.yy4(r)),()=>e.state===t&&0===t.refCount?(e.state=nh,e0.VN(t.scope,L.rI)):B.rIH)).pipe(B.yeE(B.OH5(()=>{t.fiber=void 0})),B.eJC(e.context),rl(e.scope))),B.rIH)},n_=e=>B.FcF(t=>B.qIB(B.z8E,r=>B.qIB(((e,t)=>{switch(e.state._tag){case"Closed":return B.GaK;case"Acquired":{let t=e.state;return t.refCount++,t.fiber?B.as(rs(t.fiber),t):B.PyW(t)}case"Acquiring":{let r=e.state;return r.awaiters++,nv(e,r,t)}case"Empty":{let r={_tag:"Acquiring",fiber:void 0,awaiters:1,acquired:void 0};e.state=r;let n=e0.LZ(),i=B.PpN(e.acquire,Z.WQ(e.context,e0.HG,n)).pipe(B.qIB(t=>{if(e.state!==r)return B.GaK;let i={_tag:"Acquired",value:t,scope:n,fiber:void 0,refCount:r.awaiters,invalidated:!1};return e.state=i,r.acquired=i,B.PyW(i)}),B.cfM(t=>L.oJ(t)?B.rIH:(e.state===r&&(e.state=nh),e0.VN(n,t))));return r.fiber=B.eJC(ro().context)(i),nv(e,r,t)}}})(e,t),t=>B.as(e0.a6(r,()=>nb(e,t)),t.value))));var nx=n(2718);let nw="~effect/Terminal",nk="~effect/Terminal/QuitError";class nS extends(nx.$DH("QuitError"))({_tag:nx.TcI("QuitError")}){[nk]=nk}let nI=Z.kl("effect/Terminal"),n$=t("node:readline"),nE=B.D9k(function*(e=nC){let t,r,n=process.stdin,i=process.stdout,a=yield*e$(),s=n.readableEnded,o=!1,l=()=>{s=!0,o||eM(a)};n.once("end",l),yield*B.U9h(()=>B.OH5(()=>n.off("end",l)));let d=yield*(t={acquire:B.Q56(B.OH5(()=>{let e=n$.createInterface({input:n,escapeCodeTimeout:50}),t=e=>eO(a,e),r=()=>{o=!1,eM(a)};return o=!0,n$.emitKeypressEvents(n,e),e.on("line",t),e.once("close",r),n.isTTY&&n.setRawMode(!0),{rl:e,onClose:r,onLine:t}}),({rl:e,onClose:t,onLine:r})=>B.OH5(()=>{o=!1,e.off("line",r),e.off("close",t),n.isTTY&&n.setRawMode(!1),e.close(),s&&eM(a)})),idleTimeToLive:"10 millis"},B.R6R(e=>{let r=e.context,n=Z.Jt(r,e0.HG),i=new ny(t.acquire,r,n,void 0!==t.idleTimeToLive?H.bN(t.idleTimeToLive):void 0);return B.as(e0.a6(n,()=>{let e=i.state;return(i.state=nm,"Acquired"===e._tag)?e0.VN(e.scope,L.rI):"Acquiring"===e._tag?rs(e.fiber):B.rIH}),i)})),c=B.OH5(()=>i.columns??0),u=B.OH5(()=>i.rows??0),f=B.JkU(function*(){let t=yield*e$(),r=(r,n)=>{let i={input:ee.fromUndefinedOr(r),key:{name:n.name??"",ctrl:!!n.ctrl,meta:!!n.meta,shift:!!n.shift}};eO(t,i),e(i)&&eM(t)},i=setInterval(()=>{},0x7fffffff),a=()=>{clearInterval(i),eM(t)};return yield*B.U9h(()=>B.OH5(()=>{clearInterval(i),n.off("keypress",r),n.off("end",a)})),n.on("keypress",r),s?a():(yield*n_(d),n.once("end",a)),t});return r={columns:c,rows:u,readInput:f,readLine:B.DYE(()=>ey.DYE(()=>{let e=eD(a);return void 0===e?ey.PyW(ee.none()):"Success"===e._tag?ey.PyW(ee.some(e.value)):ey.PyW(ee.none())}).pipe(B.qIB(ee.match({onNone:()=>B.P1j(B.hgn(n_(d),ej(a))),onSome:B.PyW})),B.xm_(()=>new nS({})))),display:e=>B.rfi(B.E2r(t=>{i.write(e,e=>eh.uy(e)?t(B.rIH):t(B.fJG(eo({module:"Terminal",method:"display",description:"Failed to write prompt to stdout",cause:e}))))}))},nI.of({...r,[nw]:nw})}),nO=G.QZ(nI,nE(nC));function nC(e){return e.key.ctrl&&("c"===e.key.name||"d"===e.key.name)}let nT=G.S5(rb,G.Um(no,rM,nc,np,nO));var nM=n(5967);class nA extends nx.rNF()("CliFilesystemError",{cause:nx.kld(),operation:nx.QfV,path:nx.QfV,message:nx.QfV}){}class nN extends nx.rNF()("CliInputError",{code:nx.xCb(["input_read_failed","invalid_json","interactive_stdin"]),message:nx.QfV,hint:nx.QfV}){}class nP extends nx.rNF()("CliValidationError",{message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nR extends nx.rNF()("CliBuildError",{status:nx.QfV,message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nj extends nx.rNF()("CliGenerationError",{code:nx.xCb(["provider_failure","generation_timeout","malformed_output","invalid_generated_document","unsupported_diagram_type"]),message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nD extends nx.rNF()("CliCanvasError",{code:nx.xCb(["canvas_rejected","canvas_timeout","endpoint_failure","malformed_response","network_failure"]),message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nU extends nx.rNF()("CliInteractiveError",{code:nx.xCb(["cancelled","prompt_failed"]),message:nx.QfV,hint:nx.QfV}){}class nF extends nx.rNF()("CliStorageError",{code:nx.xCb(["diagram_not_found","diagram_already_exists","diagram_busy","detached_edit","patch_source_unavailable","patch_conflict","replacement_conflict","restore_conflict","revision_not_found","corrupt_revision","corrupt_record","unsafe_storage_entry","storage_commit_failed"]),diagramId:nx.Qrq(nx.QfV),message:nx.QfV,hint:nx.QfV}){}class nB extends nx.rNF()("CliShareError",{code:nx.xCb(["invalid_share_link","unsupported_scene","share_payload_too_large","share_crypto_failed","share_transport_failed","share_timeout","share_api_changed","share_link_unavailable"]),message:nx.QfV,hint:nx.QfV,details:nx.O31(nx.QfV)}){}class nL extends nx.rNF()("CliExportError",{code:nx.xCb(["format_unavailable","invalid_destination","render_failed","invalid_render_artifact","render_limit_exceeded","unsupported_render_glyph","rasterization_failed","export_write_failed"]),diagramId:nx.Qrq(nx.QfV),storagePath:nx.Qrq(nx.QfV),recoveryCommand:nx.Qrq(nx.QfV),details:nx.Qrq(nx.O31(nx.QfV)),format:nx.QfV,message:nx.QfV,hint:nx.QfV}){}let nz=["scene","excalidraw"],nW=B.fn("sketchi.cli.codeMode.with")(function*(e,t,r){return yield*r({artifactFormats:[...nz],inlineArtifacts:[...nz]}).pipe(B.PfK(nM.Ov,e),B.PfK(nM.UA,t))});function nJ(e,t){let r=e.issues[0],n=r?.message??`Code Mode${"patch"===t?" patch":""} failed with ${e.status}.`,i=r?.hint??("patch"===t?"Repair the patch request and retry.":"Repair the document and retry."),a=e.issues.map(e=>`${e.code}${e.ref?.path?` (${e.ref.path})`:""}: ${e.message}`);return("patch"===t?["invalid_input","target_not_found","unsupported_operation","connectivity_changed"]:["invalid_input","invalid_flowchart","invalid_mindmap","invalid_sequence","quality_failed"]).includes(e.status)?nP.make({message:n,hint:i,details:a}):"storage_failed"===e.status?nF.make({code:"storage_commit_failed",message:n,hint:i}):nR.make({status:e.status,message:n,hint:i,details:a})}let nY=B.fn("sketchi.cli.codeMode.decodeArtifacts")(function*(e,t){let r="patch"===t?"patched ":"",n="patch"===t?"Inspect the Code Mode patch/export boundary.":"Inspect the Code Mode build/export boundary.",i=n=>{let i=e.formats.find(e=>e.format===n);return i?.inline!==void 0?B.PyW(i.inline):B.fJG(nR.make({status:"missing_inline_artifact",message:`Code Mode did not return the ${r}${n} artifact inline.`,hint:"patch"===t?"Retry the offline patch with the required artifact formats.":"Rebuild the document with the required offline artifact formats.",details:[n]}))},a=e.formats.find(e=>"scene"===e.format),s="export"!==t||a?nx.q$Z(nM.Uh,{errors:"all",reportInput:!0})((yield*i("scene"))):void 0;if(s&&!tL.oJ(s))return yield*nR.make({status:"invalid_scene_artifact",message:`Code Mode returned an invalid ${r}scene artifact.`,hint:n,details:(0,nM.z4)(s.failure).issues.map(e=>e.message)});let o=nx.q$Z(nM.yE,{errors:"all",reportInput:!0})((yield*i("excalidraw")));return tL.oJ(o)?{...s&&tL.oJ(s)?{scene:s.success}:{},excalidraw:o.success}:yield*nR.make({status:"invalid_excalidraw_artifact",message:`Code Mode returned an invalid ${r}Excalidraw artifact.`,hint:n,details:(0,nM.z4)(o.failure).issues.map(e=>e.message)})});var nX=n(7086);function nq(e){return"string"==typeof e||"number"==typeof e||"symbol"==typeof e}let nG=nX.ID(),nV=nx._Re(nM.Ky,{errors:"all"}),nH=nx._Re(nM.e5,{errors:"all"}),nK=nx._Re(nM.nu,{errors:"all"}),nQ=nx._Re(nM.y1,{errors:"all"});function nZ(e){return nP.make({message:"The canonical diagram document is invalid.",hint:'Use {"type":"flowchart","spec":...}, {"type":"mindmap","spec":...}, or {"type":"sequence","spec":...}.',details:e})}function n0(e){return nG(e).issues.map(e=>{var t;let r=(e.path??[]).flatMap(e=>{let t=nq(e)?e:null!==e&&"object"==typeof e&&"key"in e&&nq(e.key)?e.key:void 0;return void 0===t?[]:[t]});return`${0===(t=["spec",...r]).length?"document":t.map(e=>"number"==typeof e?`[${e}]`:String(e)).join(".")}: ${e.message}`})}function n1(e){if(!("object"!=typeof e||null===e||Array.isArray(e))&&"type"in e&&"spec"in e)return{type:e.type,spec:e.spec}}let n2=B.fn("sketchi.cli.document.decodeCanonical")(function*(e){let t=n1(e);return t?"flowchart"===t.type?{type:"flowchart",spec:yield*nV(t.spec).pipe(B.xm_(e=>nZ(n0(e.issue))))}:"mindmap"===t.type?{type:"mindmap",spec:yield*nH(t.spec).pipe(B.xm_(e=>nZ(n0(e.issue))))}:"sequence"===t.type?{type:"sequence",spec:yield*nK(t.spec).pipe(B.xm_(e=>nZ(n0(e.issue))))}:yield*nZ(['document.type: Expected "flowchart", "mindmap", or "sequence".']):yield*nZ(["document: Expected an object with type and spec."])}),n5=B.fn("sketchi.cli.document.parseJson")(function*(e){let t=yield*B.SvU({try:()=>JSON.parse(e),catch:()=>nN.make({code:"invalid_json",message:"The input is not valid JSON.",hint:"Pass one complete canonical document object."})});return yield*n2(t)}),n3=B.fn("sketchi.cli.document.decodeStored")(function*(e){let t=n1(e);return t?.type!=="canvas"?yield*n2(e):{type:"canvas",spec:yield*nQ(t.spec).pipe(B.xm_(e=>nZ(n0(e.issue))))}});function n6(e){return`${JSON.stringify(e,null,2)}
3
+ `}function n8(e){let t=e.spec.id?.trim();return t||e.spec.title.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||`sketchi-${e.type}`}function n9(e){return/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(e)?B.PyW(e):B.fJG(nP.make({message:`Diagram id "${e}" is not safe for local storage.`,hint:"Use 1-128 ASCII letters, digits, dots, underscores, or hyphens; start with a letter or digit.",details:["spec.id"]}))}class n4 extends Z.kl()("@sketchi/cli/DiagramBuilder"){}let n7=G.QZ(n4,B.JkU(function*(){let e=yield*nM.Ov,t=yield*nM.UA;return{build:B.fn("sketchi.cli.diagram.build")(function*(r){let n=yield*nW(e,t,e=>"flowchart"===r.type?(0,nM.XV)({spec:r.spec,options:e}):"mindmap"===r.type?(0,nM.r8)({spec:r.spec,options:e}):(0,nM.rC)({spec:r.spec,options:e}));if(!n.ok)return yield*nJ(n,"build");let i=yield*n9(n8(r)),{scene:a,excalidraw:s}=yield*nY(n.artifact,"build");return{id:i,type:r.type,title:r.spec.title,document:r,scene:a,excalidraw:s}})}})),ie=t("node:fs/promises");class it extends Z.kl()("@sketchi/cli/LocalFileSystem"){}function ir(e,t,r){return nA.make({cause:r,operation:e,path:t,message:`Filesystem ${e} failed for ${t}.`})}function ii(e,t){return"object"==typeof e&&null!==e&&"code"in e&&e.code===t}function ia(e){return e.reason.cause??e}let is=G.QZ(it,B.TjK(tR,function(e){let t=B.fn("sketchi.cli.fs.kind")(function*(t){let r=yield*e.readLink(t).pipe(B.Ket);if("Success"===r._tag)return"symbolic-link";let n=ia(r.failure);return ii(n,"ENOENT")?"missing":ii(n,"ELOOP")?"symbolic-link":ii(n,"EINVAL")?yield*e.stat(t).pipe(B.TjK(e=>"File"===e.type?"file":"Directory"===e.type?"directory":"SymbolicLink"===e.type?"symbolic-link":"other"),B.MfU(e=>{let r=ia(e);return ii(r,"ENOENT")?B.PyW("missing"):ii(r,"ELOOP")?B.PyW("symbolic-link"):B.fJG(ir("stat",t,r))})):yield*ir("stat",t,n)}),r=(e,t)=>r=>ir(e,t,ia(r));return{makeDirectory:(t,n=!1)=>e.makeDirectory(t,{recursive:n}).pipe(B.xm_(r("make-directory",t))),tryWriteText:(e,t)=>B.$mh({try:async r=>{try{let n=await (0,ie.open)(e,rN.constants.O_WRONLY|rN.constants.O_CREAT|rN.constants.O_EXCL|rN.constants.O_NOFOLLOW,384);try{await n.writeFile(t,{encoding:"utf8",signal:r}),await n.sync()}finally{await n.close()}return!0}catch(e){if(ii(e,"EEXIST"))return!1;throw e}},catch:t=>ir("write-exclusive",e,t)}),tryLinkFile:(t,r)=>e.link(t,r).pipe(B.as(!0),B.MfU(e=>{let n=ia(e);return ii(n,"EEXIST")||ii(n,"ENOENT")?B.PyW(!1):B.fJG(ir("link-exclusive",`${t} -> ${r}`,n))})),makeTempDirectory:(t,n)=>e.makeTempDirectory({directory:t,prefix:n}).pipe(B.xm_(r("make-temp-directory",t))),list:n=>e.readDirectory(n).pipe(B.xm_(r("read-directory",n)),B.qIB(e=>B.jJl(e,e=>t((0,rR.join)(n,e)).pipe(B.TjK(t=>"missing"===t?[]:[{name:e,kind:t}]))).pipe(B.TjK(e=>e.flat())))),kind:t,realPath:t=>e.realPath(t).pipe(B.xm_(r("resolve",t))),readText:e=>B.$mh({try:async t=>{let r=await (0,ie.open)(e,rN.constants.O_RDONLY|rN.constants.O_NOFOLLOW);try{return await r.readFile({encoding:"utf8",signal:t})}finally{await r.close()}},catch:t=>ir("read",e,t)}),readBytes:e=>B.$mh({try:async t=>{let r=await (0,ie.open)(e,rN.constants.O_RDONLY|rN.constants.O_NOFOLLOW);try{return new Uint8Array(await r.readFile({signal:t}))}finally{await r.close()}},catch:t=>ir("read",e,t)}),writeText:(e,t,r=!1)=>B.$mh({try:async n=>{let i=rN.constants.O_WRONLY|rN.constants.O_CREAT|rN.constants.O_NOFOLLOW|(r?rN.constants.O_TRUNC:rN.constants.O_EXCL),a=await (0,ie.open)(e,i,384);try{await a.writeFile(t,{encoding:"utf8",signal:n}),await a.sync()}finally{await a.close()}},catch:t=>ir("write",e,t)}),writeBytes:(e,t,r=!1)=>B.$mh({try:async n=>{let i=rN.constants.O_WRONLY|rN.constants.O_CREAT|rN.constants.O_NOFOLLOW|(r?rN.constants.O_TRUNC:rN.constants.O_EXCL),a=await (0,ie.open)(e,i,384);try{await a.writeFile(t,{signal:n}),await a.sync()}finally{await a.close()}},catch:t=>ir("write",e,t)}),rename:(t,n)=>e.rename(t,n).pipe(B.xm_(r("rename",`${t} -> ${n}`))),tryRenameDirectory:(r,n)=>e.rename(r,n).pipe(B.as(!0),B.MfU(e=>B.JkU(function*(){let i=ia(e);return!(ii(i,"EEXIST")||ii(i,"ENOTEMPTY")||ii(i,"EPERM")&&(yield*t(n).pipe(B.MfU(()=>B.PyW("missing"))))==="directory")&&(yield*ir("rename-exclusive-directory",`${r} -> ${n}`,i))}))),removeFile:t=>e.remove(t).pipe(B.as(!0),B.MfU(e=>{let r=ia(e);return ii(r,"ENOENT")?B.PyW(!1):B.fJG(ir("remove-file",t,r))})),remove:t=>e.remove(t,{recursive:!0,force:!0}).pipe(B.xm_(r("remove",t)))}})),io=nx._kM({operations:nM.x3.fields.operations,options:nM.x3.fields.options,intent:nM.x3.fields.intent});function il(e,t){return nP.make({message:e,hint:"Provide operations and optional options or intent only.",details:t})}let id=B.fn("sketchi.cli.patch.decodeInput")(function*(e){if("object"!=typeof e||null===e||Array.isArray(e))return yield*il("The diagram patch request is invalid.",["patch: Expected an object."]);if("source"in e)return yield*il("The diagram patch request cannot supply source.",["source: The CLI binds the stored scene."]);if("requestId"in e)return yield*il("The diagram patch request cannot supply requestId.",["requestId: The CLI owns the patch request id."]);let t=nx.q$Z(io,{errors:"all",reportInput:!0})(e);return tL.oJ(t)?{operations:t.success.operations,...t.success.options?{options:t.success.options}:{},...t.success.intent?{intent:t.success.intent}:{}}:yield*il("The diagram patch request is invalid.",(0,nM.z4)(t.failure).issues.map(e=>e.message))}),ic=B.fn("sketchi.cli.patch.parseJson")(function*(e){let t=yield*B.SvU({try:()=>JSON.parse(e),catch:()=>nN.make({code:"invalid_json",message:"The patch input is not valid JSON.",hint:"Pass one complete diagram patch request object."})});return yield*id(t)});class iu extends Z.kl()("@sketchi/cli/DiagramPatcher"){}let ip=G.QZ(iu,B.JkU(function*(){let e=yield*nM.Ov,t=yield*nM.UA;return{patch:B.fn("sketchi.cli.diagram.patch")(function*(r,n,i){let a=yield*nW(e,t,e=>(0,nM.OF)({requestId:i,source:{scene:r},operations:n.operations,options:{...n.options,...e},...n.intent?{intent:n.intent}:{}}));if(!a.ok)return yield*nJ(a,"patch");let{scene:s,excalidraw:o}=yield*nY(a.artifact,"patch");return{scene:s,excalidraw:o}})}}));class ih extends Z.kl()("@sketchi/cli/InputReader"){}function im(e,t){return B.SvU({try:()=>new TextDecoder("utf-8",{fatal:!0}).decode(e),catch:()=>nN.make({code:"input_read_failed",message:"stdin"===t?"Standard input is not valid UTF-8.":"The input file is not valid UTF-8.",hint:"Provide one complete UTF-8 JSON document and retry."})})}let ig=function(e=()=>!0===process.stdin.isTTY){return G.QZ(ih,B.JkU(function*(){let t=yield*it,r=yield*nf;return{read:B.fn("sketchi.cli.input.read")(function*(n,i={content:"JSON document"}){if("InlineJson"===n._tag)return n.value;if("-"!==n.path){let e=yield*t.readBytes(n.path).pipe(B.xm_(()=>nN.make({code:"input_read_failed",message:`Unable to read input file ${n.path}.`,hint:"Check the path and file permissions, then retry."})));return yield*im(e,"file")}if(e())return yield*nN.make({code:"interactive_stdin",message:`${i.content} input requires piped or redirected stdin.`,hint:"share link"===i.content?"Pipe one complete Excalidraw share link to --link -.":"Pipe one JSON document, or use --file PATH / --json VALUE."});let a=yield*tN(r.stdin,()=>({chunks:[],size:0}),(e,t)=>{let r=t.byteLength+e.size;return void 0!==i.maxBytes&&r>i.maxBytes?B.fJG(nN.make({code:"input_read_failed",message:`Standard input exceeds the ${String(i.maxBytes)} byte limit for a ${i.content}.`,hint:`Pipe one complete ${i.content} within the documented limit.`})):B.PyW({chunks:[...e.chunks,t],size:r})}).pipe(B.xm_(e=>e instanceof nN?e:nN.make({code:"input_read_failed",message:`Unable to read the ${i.content} from stdin.`,hint:`Pipe one complete UTF-8 ${i.content} and retry.`})));return yield*im(function(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let n of e)t.set(n,r),r+=n.byteLength;return t}(a.chunks),"stdin")})}}))}(),iy=B.fn("sketchi.cli.input.readDocument")(function*(e){let t=yield*ih,r=yield*t.read(e);return yield*n5(r)}),iv=B.fn("sketchi.cli.input.readPatch")(function*(e){let t=yield*ih,r=yield*t.read(e,{content:"patch request"});return yield*ic(r)});var ib=n(6771);let i_=1,ix="manifest.json",iw="document.json",ik="scene.json",iS="diagram.excalidraw",iI="diagram.png",i$="revisions";class iE extends nx.Xsx("DiagramRecordManifest")({schemaVersion:nx.uSQ(i_),id:nx.QfV,type:nx.xCb(["canvas","flowchart","mindmap","sequence"]),title:nx.QfV,revision:nx.Aiz.check(nx.yJO(0)),authority:nx.xCb(["canonical","patched","detached"]).pipe(nx.E$i(B.PyW("canonical"))),formats:nx.O31(nx.xCb(["scene","excalidraw","png"]))}){}function iO(e){return{id:e.manifest.id,type:e.manifest.type,title:e.manifest.title,revision:e.manifest.revision,formats:e.manifest.formats,authority:e.authority,documentAuthoritative:"canonical"===e.authority}}function iC(e){return String(e).padStart(6,"0")}let iT=t("node:zlib");var iM=n(8689),iA=n(5030);let iN="https://json.excalidraw.com/api/v2/",iP=["rectangle","ellipse","diamond","arrow","line","freedraw","text"],iR=new Set(iP),ij=new TextEncoder,iD=new TextDecoder("utf-8",{fatal:!0}),iU=ij.encode(JSON.stringify({version:2,compression:"pako@1",encryption:"AES-GCM"}));function iF(e,t,r,n=[]){return nB.make({code:e,message:t,hint:r,details:n})}function iB(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function iL(e){return"number"==typeof e&&Number.isFinite(e)}function iz(e,t,r){new DataView(e.buffer,e.byteOffset,e.byteLength).setUint32(t,r)}function iW(e,t){if(t+4>e.byteLength)throw Error("truncated chunk header");return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(t)}function iJ(e,t){if(e.byteLength<4+4*t||1!==iW(e,0))throw Error("unsupported chunk format");let r=[],n=4;for(let i=0;i<t;i+=1){let t=iW(e,n),i=(n+=4)+t;if(i>e.byteLength)throw Error("truncated chunk");r.push(e.subarray(n,i)),n=i}if(n!==e.byteLength)throw Error("unexpected trailing chunk");return r}function iY(e){if(!/^[A-Za-z0-9_-]{22}$/.test(e))throw Error("invalid AES key encoding");let t=Buffer.from(e,"base64url");if(16!==t.byteLength)throw Error("invalid AES key length");return t}function iX(e,t){return crypto.subtle.importKey("raw",Uint8Array.from(iY(e)),{name:"AES-GCM",length:128},!1,[t])}function iq(e){if(!iB(e)||"excalidraw"!==e.type||!iL(e.version)||"string"!=typeof e.source||!Array.isArray(e.elements)||!iB(e.appState)||!(void 0===e.files||iB(e.files)))throw Error("invalid Excalidraw artifact shape");return{type:e.type,version:e.version,source:e.source,elements:e.elements,appState:e.appState,files:e.files??{}}}function iG(e,t){return"string"!=typeof e||!t.has(e)}function iV(e,t){if("number"==typeof e)return Number.isFinite(e)?void 0:`${t} must be finite`;if(Array.isArray(e))for(let r of e){let e=iV(r,`${t} item`);if(e)return e}else if(iB(e))for(let r of Object.values(e)){let e=iV(r,`${t} property`);if(e)return e}}function iH(e){return B.SvU({try:()=>{let t=iq(e);if(iB(e)&&"libraryItems"in e)throw Error("Excalidraw library state is unsupported");if(t.elements.length>1e4)throw Error("element count exceeds 10000");if(Object.keys(t.files).length>0)throw Error("binary files are unsupported");let r=new Set;for(let[e,n]of t.elements.entries()){if(!iB(n)||"string"!=typeof n.id)throw Error(`elements[${String(e)}].id is invalid`);if(r.has(n.id))throw Error(`elements[${String(e)}].id is duplicated`);r.add(n.id)}for(let[e,n]of t.elements.entries()){let t=function(e,t,r){let n=`elements[${String(t)}]`;if(!iB(e)||"string"!=typeof e.id||0===e.id.length||"string"!=typeof e.type)return`elements[${String(t)}] is not an Excalidraw element`;if(!iR.has(e.type))return`${n}.type is unsupported`;if("link"in e&&null!==e.link&&void 0!==e.link||"fileId"in e)return`${n} contains an external resource`;let i=iV(e,n);if(i)return i;for(let t of["x","y","width","height","angle"])if(!iL(e[t]))return`${n}.${t} must be finite`;if("text"===e.type){if(5!==e.fontFamily)return`${n}.fontFamily must be ${String(5)}`;if("string"!=typeof e.text)return`${n}.text is invalid`}if(["arrow","line","freedraw"].includes(e.type)&&(!Array.isArray(e.points)||e.points.some(e=>!Array.isArray(e)||e.length<2||!iL(e[0])||!iL(e[1]))))return`${n}.points contains invalid geometry`;for(let t of["containerId","frameId"])if(null!==e[t]&&void 0!==e[t]&&iG(e[t],r))return`${n}.${t} is an invalid element reference`;for(let t of["startBinding","endBinding"]){let i=e[t];if(null!=i&&(!iB(i)||iG(i.elementId,r)))return`${n}.${t} is an invalid element binding`}let a=e.boundElements;if(null!=a&&(!Array.isArray(a)||a.some(e=>!iB(e)||iG(e.id,r))))return`${n}.boundElements contains an invalid element reference`}(n,e,r);if(t)throw Error(t)}let n=(0,iA.Gd)(t.elements);if(n)throw Error(n);let i=function(e){if("viewBackgroundColor"in e&&"string"!=typeof e.viewBackgroundColor)return"appState.viewBackgroundColor must be a string";if("gridModeEnabled"in e&&"boolean"!=typeof e.gridModeEnabled)return"appState.gridModeEnabled must be boolean";for(let t of["gridSize","gridStep"])if(t in e&&null!==e[t]&&!iL(e[t]))return`appState.${t} must be finite or null`;if("lockedMultiSelections"in e){let t=e.lockedMultiSelections;if(!iB(t))return"appState.lockedMultiSelections must be an object";for(let[e,r]of Object.entries(t))if(0===e.length||!0!==r)return"appState.lockedMultiSelections contains an invalid lock entry"}return iV(e,"appState")}(t.appState);if(i)throw Error(i);return e},catch:e=>iF("unsupported_scene","The Excalidraw scene is unsupported by share/pull v1.",`Use only ${iP.join(", ")} elements, Excalifont fontFamily ${String(5)}, and no files or images.`,[e instanceof Error?e.message:"invalid scene"])})}function iK(e){let t=new Uint8Array(4);return iz(t,0,e),t}let iQ=nx._kM({buffer:nx.SEl,engine:nx._kM({bytesWritten:nx.wNn})});function iZ(e){let t=0xffffffff;for(let r of e){t^=r;for(let e=0;e<8;e+=1)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}function i0(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}let i1=[[0,0,8,8],[4,0,8,8],[0,4,4,8],[2,0,4,4],[0,2,2,4],[1,0,2,2],[0,1,1,2]];function i2(e,t,r){return e<=t?0:Math.ceil((e-t)/r)}function i5(e){let t,r,n,i,a,s=[137,80,78,71,13,10,26,10];if(e.byteLength<33||s.some((t,r)=>e[r]!==t))return!1;let o=s.length,l=0,d=!1,c=!1,u=!1,f=[];for(;o+12<=e.byteLength;){let s=i0(e,o),p=o+12+s;if(p>e.byteLength)break;let h=o+4,m=e.subarray(h,h+4),g=e=>e>=65&&e<=90||e>=97&&e<=122;if(4!==m.byteLength||!m.every(g)||(32&m[2])!=0)break;let y=String.fromCharCode(...m);if(0===l&&("IHDR"!==y||13!==s))break;if("IHDR"===y){if(0!==l||13!==s)return!1;t=i0(e,o+8),r=i0(e,o+12),i=e[o+16],n=e[o+17],a=e[o+20];let d={0:[1,2,4,8,16],2:[8,16],3:[1,2,4,8],4:[8,16],6:[8,16]};if(0===t||0===r||t>0x7fffffff||r>0x7fffffff||void 0===n||void 0===i||!d[n]?.includes(i)||0!==e[o+18]||0!==e[o+19]||![0,1].includes(a??-1))break}else if("PLTE"===y){if(d||c||0===s||s%3!=0||s>768||0===n||4===n||3===n&&void 0!==i&&s/3>2**i)return!1;d=!0}else if("IDAT"===y){if(u||3===n&&!d)return!1;c=!0,f.push(e.subarray(o+8,o+8+s))}else if("IEND"===y){if(0!==s||!c||3===n&&!d)break}else{c&&(u=!0);let t=e[h];if(void 0===t||(32&t)==0)break}let v=i0(e,o+8+s);if(iZ(e.subarray(h,o+8+s))!==v)break;if(o=p,l+=1,"IEND"===y)return o===e.byteLength&&void 0!==t&&void 0!==r&&void 0!==i&&void 0!==n&&void 0!==a&&function(e,t,r,n,i,a){let s={0:1,2:3,3:1,4:2,6:4}[i];if(void 0===s)return!1;let o=function(e,t,r,n){let i=[],a=0;for(let[s,o,l,d]of 0===n?[[0,0,1,1]]:i1){let n=i2(e,s,l),c=i2(t,o,d);if(0===n||0===c)continue;let u=Math.ceil(n*r/8)+1;if(u>0x1000000-a||c>Math.floor((0x1000000-a)/u))return null;a+=c*u,i.push({rows:c,rowBytes:u})}return i}(t,r,s*n,a);if(null===o)return!1;let l=o.reduce((e,t)=>e+t.rows*t.rowBytes,0);try{let t=function(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let n of e)t.set(n,r),r+=n.byteLength;return t}(e),r=(0,iT.inflateSync)(t,{info:!0,maxOutputLength:0x1000000}),n=nx.svK(iQ)(r);if(n.engine.bytesWritten!==t.byteLength)return!1;let i=n.buffer;if(i.byteLength!==l)return!1;let a=0;for(let e of o)for(let t=0;t<e.rows;t+=1){if((i[a]??5)>4)return!1;a+=e.rowBytes}return a===i.byteLength}catch{return!1}}(f,t,r,i,n,a)}return!1}class i3 extends Z.kl()("@sketchi/cli/StorageRoot"){}class i6 extends Z.kl()("@sketchi/cli/DiagramStore"){}let i8=".locks",i9="free.",i4="owner.",i7=".owner-candidate.",ae=".json",at="recovery",ar=".backup.",an=`.stage.${String(process.pid)}.`,ai=ib.ji("10 millis").pipe(ib.jB({times:50})),aa=G.Py(i3,{path:(0,rR.join)((0,rP.homedir)(),".sketchi","diagrams")});function as(e,t,r,n){return nF.make({code:e,message:t,hint:r,...n?{diagramId:n}:{}})}function ao(e){return Buffer.from(e,"utf8").toString("base64url")}function al(e,t){return e<t?-1:+(e>t)}function ad(e,t){let r=e.replace(/(?:\/|\.json)$/u,"").replace(/^0+/u,""),n=t.replace(/(?:\/|\.json)$/u,"").replace(/^0+/u,""),i=r.length-n.length;return 0!==i?i:al(r,n)||al(e,t)}function ac(e,t){let r="detached"===e?["excalidraw"]:["scene","excalidraw"];return t?[...r,"png"]:r}function au(e){if(!Number.isSafeInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(e){return"object"==typeof e&&null!==e&&"code"in e&&"EPERM"===e.code}}function af(e,t){return"object"==typeof e.cause&&null!==e.cause&&"code"in e.cause&&e.cause.code===t}function ap(e,t){return(0,rR.join)(e,t)}function ah(e){switch(e){case"scene":return ik;case"excalidraw":return iS;case"png":return iI}}function am(e,t){return as("unsafe_storage_entry",`Unsafe local storage entry at ${e}.`,"Replace symbolic links or special files with ordinary Sketchi record files.",t)}let ag=G.QZ(i6,B.JkU(function*(){let e=yield*it,t=yield*i3,r=B.fn("sketchi.cli.storage.ensureOwnedDirectory")(function*(t){let r=yield*e.kind(t);if("missing"===r&&(yield*e.makeDirectory(t).pipe(B.MfU(e=>af(e,"EEXIST")?B.rIH:B.fJG(e))),r=yield*e.kind(t)),"directory"!==r)return yield*am(t)}),n=B.fn("sketchi.cli.storage.ensureRoot")(function*(){yield*r((0,rR.dirname)(t.path)),yield*r(t.path),yield*r((0,rR.join)(t.path,i8))}),i=B.fn("sketchi.cli.storage.assertSafeTree")(function*(t,r){for(let n of yield*e.list(t)){let e=(0,rR.join)(t,n.name);if("symbolic-link"===n.kind||"other"===n.kind)return yield*am(e,r);"directory"===n.kind&&(yield*i(e,r))}}),a=B.fn("sketchi.cli.storage.recoverStages")(function*(r){for(let n of[...r??(yield*e.list(t.path))].sort((e,t)=>al(e.name,t.name))){if(!n.name.startsWith(".stage."))continue;let r=function(e){let t=Number(e.split(".").at(-2));return Number.isSafeInteger(t)?t:void 0}(n.name);void 0!==r&&au(r)||(yield*e.remove((0,rR.join)(t.path,n.name)))}}),s=B.fn("sketchi.cli.storage.recoverRecordTransactions")(function*(r){let n=`${ar}${ao(r)}.`;for(let i of[...yield*e.list(t.path)].filter(e=>e.name.startsWith(n)).sort((e,t)=>al(e.name,t.name))){let n=(0,rR.join)(t.path,i.name),a=ap(t.path,r);"missing"===(yield*e.kind(a))?yield*e.rename(n,a):yield*e.remove(n)}}),o=e=>(0,rR.join)(t.path,i8,`${ao(e)}.lock`),l=B.fn("sketchi.cli.storage.initializeLockDirectory")(function*(r){let n=o(r),i=yield*e.kind(n);if("directory"===i)return n;if("missing"!==i)return yield*am(n,r);let a=(0,rR.join)(t.path,i8);return yield*B.jGc(e.makeTempDirectory(a,`.init.${ao(r)}.`),t=>B.JkU(function*(){let i=crypto.randomUUID();return(yield*e.writeText((0,rR.join)(t,`${i9}${i}${ae}`),n6({token:i})),(yield*e.tryRenameDirectory(t,n))||"directory"===(yield*e.kind(n)))?n:yield*am(n,r)}),t=>e.remove(t))}),d=e=>as("diagram_busy",`Diagram "${e}" is being changed by another Sketchi process.`,"Wait for that command to finish, then retry.",e),c=B.fn("sketchi.cli.storage.readLockEntries")(function*(t,r){let n=[...yield*e.list(t)].sort((e,t)=>al(e.name,t.name)),i=[];for(let a of n){let n=(0,rR.join)(t,a.name);if("file"!==a.kind)return yield*am(n,r);let s=function(e){if(!e.startsWith(i9)||!e.endsWith(ae))return;let t=e.slice(i9.length,-ae.length).split(".");if(1!==t.length&&2!==t.length||t.some(e=>!/^[a-zA-Z0-9_-]+$/.test(e)))return;let[r,n]=t;if(r)return{token:r,...n?{releasedOwnerToken:n}:{}}}(a.name);if(s){i.push({name:a.name,path:n,state:"free",token:s.token,...s.releasedOwnerToken?{releasedOwnerToken:s.releasedOwnerToken}:{}});continue}if(a.name.startsWith(i9))return yield*am(n,r);let o=function(e){if(!e.startsWith(i7)||!e.endsWith(ae))return;let t=e.slice(i7.length,-ae.length);return/^[a-zA-Z0-9_-]+$/.test(t)?t:void 0}(a.name);if(o){i.push({name:a.name,path:n,state:"unpublished-owner",token:o});continue}if(a.name.startsWith(i7)||!a.name.startsWith(i4)||!a.name.endsWith(ae))return yield*am(n,r);let l=function(e){try{let t=JSON.parse(e);return"object"==typeof t&&null!==t&&"pid"in t&&"number"==typeof t.pid&&"token"in t&&"string"==typeof t.token&&t.token.length>0?{pid:t.pid,token:t.token}:void 0}catch{return}}((yield*e.readText(n).pipe(B.xm_(e=>af(e,"ENOENT")?d(r):e))));if(!l)return yield*d(r);if(a.name!==`${i4}${l.token}${ae}`)return yield*am(n,r);i.push({name:a.name,path:n,token:l.token,state:au(l.pid)?"live-owner":"stale-owner"})}return i}),u=B.fn("sketchi.cli.storage.acquireLockOnce")(function*(t){let r=yield*l(t),n=yield*c(r,t),i=new Set(n.flatMap(e=>e.releasedOwnerToken?[e.releasedOwnerToken]:[]));if(n.some(e=>"live-owner"===e.state&&!i.has(e.token)))return yield*d(t);let a=n.find(e=>"free"===e.state)??n.find(e=>"stale-owner"===e.state);if(!a){let n=(0,rR.join)(r,`${i9}${at}${ae}`);if(!(yield*e.tryWriteText(n,n6({token:at}))))return yield*d(t);a={name:`${i9}${at}${ae}`,path:n,state:"free",token:at}}let s=crypto.randomUUID(),o=(0,rR.join)(r,`${i4}${s}${ae}`),u=(0,rR.join)(r,`${i7}${s}${ae}`);return yield*B.rfi(B.jGc(B.PyW(u),()=>B.JkU(function*(){if(yield*e.writeText(u,n6({pid:process.pid,token:s})),!(yield*e.tryLinkFile(u,o)))return yield*d(t);if(!(yield*e.removeFile(a.path).pipe(B.MfU(t=>e.removeFile(o).pipe(B.hgn(B.fJG(t)))))))return yield*e.removeFile(o),yield*d(t);for(let t of n)t.path!==a.path&&(yield*e.removeFile(t.path).pipe(B.MfU(()=>B.rIH)));return{directory:r,ownerPath:o,token:s}}),t=>e.removeFile(t).pipe(B.MfU(()=>B.rIH))))}),f=B.fn("sketchi.cli.storage.releaseLock")(function*(t,r){let n=crypto.randomUUID(),i=(0,rR.join)(r.directory,`${i9}${n}.${r.token}${ae}`),a=n6({token:n,releasedOwnerToken:r.token});if(!(yield*e.tryWriteText(i,a).pipe(B.MfU(()=>e.kind(i).pipe(B.TjK(e=>"file"===e))),B.MfU(()=>B.PyW(!1))))){if(yield*e.removeFile(r.ownerPath))return;return yield*as("storage_commit_failed",`Diagram "${t}" lock ownership changed before release.`,"Retry after the active Sketchi command finishes.",t)}if(!(yield*e.removeFile(r.ownerPath).pipe(B.YWq({onFailure:()=>!0,onSuccess:e=>e}))))return yield*e.removeFile(i).pipe(B.MfU(()=>B.rIH)),yield*as("storage_commit_failed",`Diagram "${t}" lock ownership changed before release.`,"Retry after the active Sketchi command finishes.",t)}),p=e=>as("diagram_not_found",`Diagram "${e}" does not exist.`,"Run sketchi list to discover stored diagram ids.",e),h=(r,i,l=!1,d=!1)=>B.JkU(function*(){let c;if(l){let n=ap(t.path,r),i=yield*e.kind(n);if("missing"===i){let n=yield*e.kind(t.path);if("missing"===n)return yield*p(r);if("directory"!==n)return yield*am(t.path,r);let i=o(r),a=yield*e.kind(i);if("missing"===a){let n=yield*e.list(t.path),i=`${ar}${ao(r)}.`;if(!n.some(e=>e.name===r||e.name.startsWith(i)))return yield*p(r)}else if("directory"!==a)return yield*am(i,r)}else if("directory"!==i)return yield*am(n,r)}return d||(yield*n(),yield*a()),yield*B.jGc((c=u(r),l?c.pipe(B.L5P({schedule:ai,while:e=>"CliStorageError"===e._tag&&"diagram_busy"===e.code})):c),()=>s(r).pipe(B.hgn(i)),e=>f(r,e).pipe(B.MfU(()=>B.rIH)))}),m=B.fn("sketchi.cli.storage.decodeManifest")(function*(t,r){let n=yield*e.readText(t),i=yield*B.SvU({try:()=>JSON.parse(n),catch:()=>as("corrupt_record",`Diagram "${r}" has an invalid manifest.`,"Inspect manifest.json and restore it from a known-good backup.",r)});return yield*nx._Re(iE)(i).pipe(B.xm_(()=>as("corrupt_record",`Diagram "${r}" has an incompatible manifest.`,`Expected manifest schema version ${String(1)}.`,r)))}),g=B.fn("sketchi.cli.storage.decodeDocument")(function*(t,r){let n=yield*e.readText(t),i=yield*B.SvU({try:()=>JSON.parse(n),catch:()=>as("corrupt_record",`Diagram "${r}" has invalid document JSON.`,"Recover a prior canonical document from the revisions directory.",r)});return yield*n3(i).pipe(B.xm_(()=>as("corrupt_record",`Diagram "${r}" has an invalid canonical document.`,"Recover a prior canonical document from the revisions directory.",r)))}),y=B.fn("sketchi.cli.storage.loadUnlocked")(function*(r){var n;let a,s=ap(t.path,r),o=yield*e.kind(s);if("missing"===o)return yield*as("diagram_not_found",`Diagram "${r}" does not exist.`,"Run sketchi list to discover stored diagram ids.",r);if("directory"!==o)return yield*am(s,r);yield*i(s,r);let l=yield*m((0,rR.join)(s,ix),r);if(l.id!==r)return yield*as("corrupt_record",`Diagram directory "${r}" contains manifest id "${l.id}".`,"Make the directory name and manifest id agree before retrying.",r);let d=yield*g((0,rR.join)(s,iw),r);if(l.type!==d.type||l.title!==d.spec.title)return yield*as("corrupt_record",`Diagram "${r}" manifest does not match its canonical document.`,"Recover the canonical document and rebuild the record with sketchi edit.",r);for(let t of[ik,iS])if((yield*e.kind((0,rR.join)(s,t)))!=="file")return yield*as("corrupt_record",`Diagram "${r}" is missing required artifact ${t}.`,"Recover the canonical document and rebuild the record with sketchi edit.",r);let c=yield*e.kind((0,rR.join)(s,iI));if("file"!==c&&"missing"!==c)return yield*am((0,rR.join)(s,iI),r);if("file"===c&&(a=(n=yield*e.readBytes((0,rR.join)(s,iI))).byteLength-12,!(n.byteLength>=45&&[137,80,78,71,13,10,26,10].every((e,t)=>n[t]===e)&&13===i0(n,8)&&"IHDR"===String.fromCharCode(...n.subarray(12,16))&&i0(n,16)>0&&i0(n,20)>0)||iZ(n.subarray(12,29))!==i0(n,29)||0!==i0(n,a)||"IEND"!==String.fromCharCode(...n.subarray(a+4,a+8))||iZ(n.subarray(a+4,a+8))!==i0(n,a+8)))return yield*as("corrupt_record",`Diagram "${r}" has an invalid stored PNG artifact.`,"Recover a valid prior revision or rebuild the record.",r);let u=ac(l.authority,"file"===c);if(l.formats.length!==u.length||l.formats.some((e,t)=>e!==u[t]))return yield*as("corrupt_record",`Diagram "${r}" manifest formats do not match stored artifacts.`,"Recover the canonical document and rebuild the record with sketchi edit.",r);let f=(0,rR.join)(s,i$),p=[];for(let t of yield*e.list(f)){if("file"===t.kind&&/^\d{6,}\.json$/u.test(t.name)){p.push(t.name);continue}if("directory"===t.kind&&/^\d{6,}$/u.test(t.name)){p.push(`${t.name}/`);continue}return yield*am((0,rR.join)(f,t.name),r)}return p.sort(ad),{manifest:l,document:d,revisions:p,authority:l.authority}}),v=B.fn("sketchi.cli.storage.copySafeTree")(function*(t,r,n){for(let i of yield*e.list(t)){let a=(0,rR.join)(t,i.name),s=(0,rR.join)(r,i.name);if("directory"===i.kind)yield*e.makeDirectory(s),yield*v(a,s,n);else{if("file"!==i.kind)return yield*am(a,n);let t=yield*e.readBytes(a);yield*e.writeBytes(s,t)}}}),b=B.fn("sketchi.cli.storage.copyRecordSnapshot")(function*(t,r,n){for(let i of(yield*e.makeDirectory(r),yield*e.list(t))){if(i.name===i$)continue;let a=(0,rR.join)(t,i.name),s=(0,rR.join)(r,i.name);if("file"!==i.kind)return yield*am(a,n);yield*e.writeBytes(s,(yield*e.readBytes(a)))}}),_=B.fn("sketchi.cli.storage.commitStage")(function*(r,n){let i=ap(t.path,r),a=(0,rR.join)(t.path,`${ar}${ao(r)}.${String(process.pid)}.${crypto.randomUUID()}`);yield*e.rename(i,a),(yield*e.rename(n,i).pipe(B.tvg({onFailure:t=>e.rename(a,i).pipe(B.tvg({onFailure:()=>B.fJG(as("storage_commit_failed",`Atomic storage commit and rollback both failed for "${r}".`,"Retry; Sketchi will recover the backup transaction before the next operation.",r)),onSuccess:()=>B.fJG(t)})),onSuccess:()=>B.PyW(!0)})))&&(yield*e.remove(a).pipe(B.MfU(()=>B.rIH)))}),x=B.fn("sketchi.cli.storage.snapshotCurrent")(function*(r,n,i){let a=(0,rR.join)(n,i$,iC(i));if((yield*e.kind(a))!=="missing")return yield*as("corrupt_record",`Diagram "${r}" already has a snapshot for current revision ${String(i)}.`,"Inspect the revisions directory before retrying.",r);yield*b(ap(t.path,r),a,r)}),w=B.fn("sketchi.cli.storage.writeBuilt")(function*(t,r){if(r.png&&!i5(r.png))return yield*as("corrupt_record",`Diagram "${r.id}" has an invalid stored PNG artifact.`,"Recover a valid prior revision or rebuild the record.",r.id);yield*e.makeDirectory((0,rR.join)(t,i$),!0),yield*e.writeText((0,rR.join)(t,iw),n6(r.document),!0),yield*e.writeText((0,rR.join)(t,ik),n6(r.scene),!0),yield*e.writeText((0,rR.join)(t,iS),n6(r.excalidraw),!0);let n=(0,rR.join)(t,iI);yield*e.remove(n),r.png&&(yield*e.writeBytes(n,r.png))}),k=B.fn("sketchi.cli.storage.transition")(function*(r,n,i){return yield*h(r,B.JkU(function*(){let a=yield*y(r),s=yield*n(a);return yield*B.jGc(e.makeTempDirectory(t.path,an),n=>B.JkU(function*(){yield*v(ap(t.path,r),n,r),yield*x(r,n,a.manifest.revision);let o=yield*i(n,a,s);return yield*e.writeText((0,rR.join)(n,ix),n6(o.manifest),!0),yield*_(r,n),{...o,revisions:[...a.revisions,`${iC(a.manifest.revision)}/`].sort(ad),authority:o.manifest.authority}}),t=>e.remove(t))}))}),S=B.fn("sketchi.cli.storage.create")(function*(r){return yield*h(r.id,B.JkU(function*(){let n=ap(t.path,r.id);if((yield*e.kind(n))!=="missing")return yield*as("diagram_already_exists",`Diagram "${r.id}" already exists.`,"Use sketchi edit for full-document replacement.",r.id);let i=iE.make({schemaVersion:1,id:r.id,type:r.type,title:r.title,revision:1,authority:"canonical",formats:ac("canonical",void 0!==r.png)});return yield*B.jGc(e.makeTempDirectory(t.path,an),t=>B.JkU(function*(){return yield*w(t,r),yield*e.writeText((0,rR.join)(t,ix),n6(i),!0),yield*e.rename(t,n),{manifest:i,document:r.document,revisions:[],authority:"canonical"}}),t=>e.remove(t))}))}),I=B.fn("sketchi.cli.storage.edit")((e,t)=>k(e,r=>B.JkU(function*(){return"canonical"!==r.authority?yield*as("detached_edit",`Diagram "${e}" does not have an authoritative canonical document.`,"Restore a canonical revision before editing this diagram.",e):t.id!==e?yield*as("storage_commit_failed",`Edited document id "${t.id}" does not match "${e}".`,"Keep spec.id equal to the diagram id being edited.",e):iE.make({schemaVersion:1,id:e,type:t.type,title:t.title,revision:r.manifest.revision+1,authority:"canonical",formats:ac("canonical",void 0!==t.png)})}),(e,r,n)=>w(e,t).pipe(B.as({manifest:n,document:t.document})))),$=e=>as("patch_source_unavailable",`Diagram "${e}" has no current authoritative scene to patch.`,"Restore a canonical or patched revision before patching this diagram.",e),E=B.fn("sketchi.cli.storage.readPatchSourceUnlocked")(function*(r){let n=yield*y(r);if("detached"===n.authority||!n.manifest.formats.includes("scene"))return yield*$(r);let i=(0,rR.join)(ap(t.path,r),ik),a=yield*e.readText(i),s=yield*B.OH5(()=>{try{return nx.q$Z(nM.Uh,{errors:"all",reportInput:!0})(JSON.parse(a))}catch{return}});return!s||tL.N6(s)||s.success.diagramId!==r?yield*as("corrupt_record",`Diagram "${r}" has an invalid current scene artifact.`,"Restore a valid prior revision before patching this diagram.",r):{revision:n.manifest.revision,scene:s.success}}),O=B.fn("sketchi.cli.storage.readPatchSource")(e=>h(e,E(e),!0)),C=B.fn("sketchi.cli.storage.commitPatch")((t,r,n)=>k(t,e=>B.JkU(function*(){return e.manifest.revision!==r?yield*as("patch_conflict",`Diagram "${t}" changed before the patch could commit.`,"Run sketchi show, verify the current record, and retry the patch if it is still intended.",t):"detached"!==e.authority&&e.manifest.formats.includes("scene")?n.scene.diagramId!==t?yield*as("storage_commit_failed",`Patched scene id "${n.scene.diagramId}" does not match "${t}".`,"Retry the patch against the named stored diagram.",t):iE.make({schemaVersion:1,id:t,type:e.manifest.type,title:e.manifest.title,revision:e.manifest.revision+1,authority:"patched",formats:ac("patched",!1)}):yield*$(t)}),(t,r,i)=>B.JkU(function*(){return yield*e.writeText((0,rR.join)(t,ik),n6(n.scene),!0),yield*e.writeText((0,rR.join)(t,iS),n6(n.excalidraw),!0),yield*e.remove((0,rR.join)(t,iI)),{manifest:i,document:r.document}}))),T=(e,t)=>as("corrupt_revision",`Diagram "${e}" revision ${String(t)} is corrupt.`,"Choose another revision or repair the corrupt snapshot.",e),M=B.fn("sketchi.cli.storage.validateArchivedJson")(function*(t,r,n){let i=yield*e.readText(t);return yield*B.SvU({try:()=>{let e=JSON.parse(i);if("object"!=typeof e||null===e)throw Error("archived JSON must contain an object");return e},catch:()=>T(r,n)})}),A=B.fn("sketchi.cli.storage.validateArchivedArtifact")(function*(e,t,r,n,i){let a=yield*M(e,n,i);if(!("scene"===t?tL.oJ(nx.q$Z(nM.Uh,{errors:"all",reportInput:!0})(a)):tL.oJ(nx.q$Z(nM.yE,{errors:"all",reportInput:!0})(a))))return yield*T(n,i);"excalidraw"===t&&"detached"===r&&(yield*iH(a).pipe(B.xm_(()=>T(n,i))))}),N=B.fn("sketchi.cli.storage.validateArchivedPng")(function*(t,r,n){if(!i5((yield*e.readBytes(t))))return yield*T(r,n)}),P=B.fn("sketchi.cli.storage.readRevisionUnlocked")(function*(r,n){let a=(0,rR.join)(ap(t.path,r),i$),s=(0,rR.join)(a,iC(n)),o=yield*e.kind(s);if("directory"===o){yield*i(s,r);let t=yield*m((0,rR.join)(s,ix),r).pipe(B.xm_(()=>T(r,n))),a=yield*g((0,rR.join)(s,iw),r).pipe(B.xm_(()=>T(r,n)));if(t.id!==r||t.revision!==n||t.type!==a.type||t.title!==a.spec.title)return yield*as("corrupt_revision",`Diagram "${r}" revision ${String(n)} has inconsistent metadata.`,"Choose another revision or repair the corrupt snapshot.",r);for(let[i,a]of[[ik,"scene"],[iS,"excalidraw"]]){let o=(0,rR.join)(s,i);if((yield*e.kind(o))!=="file")return yield*as("corrupt_revision",`Diagram "${r}" revision ${String(n)} is missing ${i}.`,"Choose another revision or repair the corrupt snapshot.",r);yield*A(o,a,t.authority,r,n).pipe(B.xm_(e=>"CliFilesystemError"===e._tag?T(r,n):e))}let o=yield*e.kind((0,rR.join)(s,iI));if("file"!==o&&"missing"!==o)return yield*am((0,rR.join)(s,iI),r);"file"===o&&(yield*N((0,rR.join)(s,iI),r,n).pipe(B.xm_(e=>"CliFilesystemError"===e._tag?T(r,n):e)));let l=ac(t.authority,"file"===o);return t.formats.length!==l.length||t.formats.some((e,t)=>e!==l[t])?yield*as("corrupt_revision",`Diagram "${r}" revision ${String(n)} has inconsistent formats.`,"Choose another revision or repair the corrupt snapshot.",r):{_tag:"FullSnapshot",revision:n}}if("missing"!==o)return yield*am(s,r);let l=(0,rR.join)(a,`${String(n).padStart(6,"0")}.json`),d=yield*e.kind(l);if("missing"===d)return yield*as("revision_not_found",`Diagram "${r}" has no revision ${String(n)}.`,"Run sketchi show to inspect the available revision paths.",r);if("file"!==d)return yield*am(l,r);let c=yield*n2((yield*M(l,r,n))).pipe(B.xm_(()=>as("corrupt_revision",`Diagram "${r}" revision ${String(n)} is corrupt.`,"Choose another revision or repair the legacy revision file.",r)));return{_tag:"LegacyDocument",revision:n,document:c}}),R=B.fn("sketchi.cli.storage.replaceWithDetached")((t,r,n)=>k(t,e=>B.JkU(function*(){return void 0!==n&&e.manifest.revision!==n?yield*as("replacement_conflict",`Diagram "${t}" changed before the pulled replacement could commit.`,"Run sketchi show, verify the current record, and retry the pull if it is still intended.",t):iE.make({schemaVersion:1,id:t,type:e.manifest.type,title:e.manifest.title,revision:e.manifest.revision+1,authority:"detached",formats:ac("detached",!1)})}),(t,n,i)=>B.JkU(function*(){return yield*e.writeBytes((0,rR.join)(t,iS),r,!0),yield*e.remove((0,rR.join)(t,iI)),{manifest:i,document:n.document}}))),j=B.fn("sketchi.cli.storage.readRevision")((e,t)=>h(e,y(e).pipe(B.hgn(P(e,t))),!0)),D=B.fn("sketchi.cli.storage.restore")(function*(t,r,n){return{diagram:yield*k(t,e=>B.JkU(function*(){let i=yield*P(t,r);if("LegacyDocument"===i._tag){if("canonical"!==e.authority||!n)return yield*as("restore_conflict",`Legacy revision ${String(r)} requires a canonical rebuild for "${t}".`,"Restore a full canonical snapshot, or provide the rebuilt legacy document.",t);if(n.id!==t||n6(n.document)!==n6(i.document))return yield*as("storage_commit_failed",`Legacy revision ${String(r)} rebuild does not match its archived document.`,"Rebuild the exact archived canonical document before restoring.",t)}return i}),(i,a,s)=>B.JkU(function*(){if("FullSnapshot"===s._tag){let n=(0,rR.join)(i,i$,iC(r));for(let t of yield*e.list(i))t.name!==i$&&(yield*e.remove((0,rR.join)(i,t.name)));yield*v(n,i,t);let s=yield*m((0,rR.join)(i,ix),t),o=yield*g((0,rR.join)(i,iw),t);return{manifest:iE.make({...s,revision:a.manifest.revision+1}),document:o}}if(!n)return yield*as("storage_commit_failed",`Legacy revision ${String(r)} has no rebuilt document.`,"Rebuild the archived canonical document before restoring.",t);let o=iE.make({schemaVersion:1,id:t,type:n.type,title:n.title,revision:a.manifest.revision+1,authority:"canonical",formats:ac("canonical",void 0!==n.png)});return yield*w(i,n),{manifest:o,document:n.document}})),restoredFromRevision:r}}),U=B.fn("sketchi.cli.storage.show")(e=>h(e,y(e),!0));return{create:S,edit:I,readPatchSource:O,commitPatch:C,replaceWithDetached:R,readRevision:j,restore:D,show:U,list:B.fn("sketchi.cli.storage.list")(function*(){yield*n();let r=yield*e.list(t.path);yield*a(r);let i=new Set;for(let e of r){if("directory"===e.kind&&!e.name.startsWith(".")){i.add(e.name);continue}if(!e.name.startsWith(ar))continue;let t=function(e){try{let t=Buffer.from(e,"base64url").toString("utf8");return/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(t)?t:void 0}catch{return}}(e.name.split(".")[2]??"");t&&i.add(t)}return yield*B.jJl([...i].sort(al),e=>h(e,y(e),!0,!0).pipe(B.Ket,B.TjK(t=>{if(tL.oJ(t))return iO(t.success);let r=t.failure;return{id:e,status:"unavailable",code:"CliStorageError"===r._tag?r.code:"filesystem_error",message:r.message,hint:"CliStorageError"===r._tag?r.hint:"Check local paths and permissions, then retry."}})),{concurrency:4})}),readExportSource:B.fn("sketchi.cli.storage.readExportSource")(function*(r,n){return yield*h(r,B.JkU(function*(){let i=yield*y(r);if(i.manifest.formats.includes(n)){let i=yield*e.readBytes((0,rR.join)(ap(t.path,r),ah(n)));return"png"!==n||i5(i)?{_tag:"StoredArtifact",bytes:i}:yield*as("corrupt_record",`Diagram "${r}" has an invalid stored PNG artifact.`,"Recover a valid prior revision or rebuild the record.",r)}if("png"!==n)return yield*nL.make({code:"format_unavailable",format:n,message:`Diagram "${r}" has no stored ${n} artifact.`,hint:"Edit the diagram to rebuild its local artifacts."});if("detached"===i.authority)return{_tag:"RenderPng",excalidraw:yield*e.readBytes((0,rR.join)(ap(t.path,r),ah("excalidraw")))};for(let e of["scene","excalidraw"])if(!i.manifest.formats.includes(e))return yield*nL.make({code:"format_unavailable",format:e,message:`Diagram "${r}" has no stored ${e} artifact.`,hint:"Edit the diagram to rebuild its local artifacts."});let[a,s]=yield*B.Q7R([e.readBytes((0,rR.join)(ap(t.path,r),ah("scene"))),e.readBytes((0,rR.join)(ap(t.path,r),ah("excalidraw")))]);return{_tag:"RenderPng",scene:a,excalidraw:s}}),!0)})}})),ay=B.fn("sketchi.cli.export.writeFile")(function*(e,t){let r=yield*it,n=yield*i3,i=(0,rR.resolve)(e),a=(0,rR.dirname)(i),s=()=>nL.make({code:"export_write_failed",format:(0,rR.basename)(e),message:`Export destination directory does not exist: ${a}.`,hint:"Create the destination directory and retry."}),o=yield*r.realPath(a).pipe(B.xm_(s));if((yield*r.kind(o))!=="directory")return yield*s();let l=yield*r.realPath(n.path),d=(0,rR.join)(o,(0,rR.basename)(i)),c=(0,rR.relative)(l,d);if(""===c||!(".."===c||c.startsWith(".."+rR.sep)||(0,rR.isAbsolute)(c)))return yield*nL.make({code:"invalid_destination",format:(0,rR.basename)(e),message:`Export destination is inside Sketchi's diagram storage: ${e}.`,hint:"Choose a destination outside ~/.sketchi/diagrams so the stored record remains valid."});let u=(0,rR.join)(o,`.${(0,rR.basename)(e)}.sketchi.${String(process.pid)}.${crypto.randomUUID()}`);return yield*B.jGc(B.PyW(u),n=>r.writeBytes(n,t).pipe(B.hgn(r.rename(n,d)),B.xm_(()=>nL.make({code:"export_write_failed",format:(0,rR.basename)(e),message:`Unable to write export destination ${e}.`,hint:"Check the destination path and permissions, then retry."}))),e=>r.remove(e))}),av="90 seconds",ab=B.fn("sketchi.cli.response.readBoundedBody")(function*(e,t,r,n=r){let i,a=e.body,s=Number(e.headers.get("content-length"));if(Number.isFinite(s)&&s>t)return a&&(yield*B.$mh({try:()=>a.cancel(),catch:r}).pipe(B.XeO)),yield*B.fJG(r());if(!a)return new Uint8Array;let o=yield*tw((i={evaluate:()=>a,onError:n},e3((e,t)=>{var r;let n,a,s;return n=(r={scope:t,readable:i.evaluate(),onError:i.onError,releaseLockOnEnd:i.releaseLockOnEnd}).readable.getReader(),a=r.exit??ef(void 0),s=B.DYE(()=>a.current?a.current:B.khu(B.$mh({try:()=>n.read(),catch:r.onError}),{onFailure:e=>a.current??B.ATB(e),onSuccess:({done:e,value:t})=>a.current?a.current:e?F.Vw():B.PyW(K.of(t))})),B.as(e0.U9(r.scope,r.releaseLockOnEnd?B.OH5(()=>n.releaseLock()):B.ivC(()=>n.cancel().catch(z.Yi))),s)}))).pipe(tN(()=>({chunks:[],size:0}),(e,n)=>{let i=e.size+n.byteLength;return i>t?B.fJG(r()):(e.chunks.push(n),B.PyW({chunks:e.chunks,size:i}))})),l=new Uint8Array(o.size),d=0;for(let e of o.chunks)l.set(e,d),d+=e.byteLength;return l}),a_=B.fn("sketchi.cli.response.readBoundedText")(function*(e,t,r,n=r){let i=yield*ab(e,t,r,n);return yield*B.SvU({try:()=>new TextDecoder("utf-8",{fatal:!0}).decode(i),catch:r})}),ax="https://playground.sketchi.app/api/v1/canvases/create",aw="SKETCHI_CANVAS_ENDPOINT",ak=nX.ID();function aS(e){return ak(e.issue).issues.map(e=>{let t=(e.path??[]).map(e=>"object"==typeof e&&null!==e&&"key"in e?String(e.key):String(e)).join(".");return`${t||"spec"}: ${e.message}`})}let aI=nx._Re(nM.y1,{errors:"all"}),a$=nx._Re(nM.JH,{errors:"all"}),aE=B.fn("sketchi.cli.canvas.parseSpec")(function*(e){let t=yield*B.SvU({try:()=>JSON.parse(e),catch:()=>nN.make({code:"invalid_json",message:"The CanvasSpec input is not valid JSON.",hint:"Pass one complete CanvasSpec JSON object."})});return yield*aI(t).pipe(B.xm_(e=>nP.make({message:"The CanvasSpec document is invalid.",hint:"Use the version 1 CanvasSpec contract documented by sketchi docs.",details:aS(e)})))}),aO=B.fn("sketchi.cli.canvas.readSpecInput")(function*(e){let t=yield*ih,r=yield*t.read(e,{content:"CanvasSpec document"});return yield*aE(r)});function aC(){return nD.make({code:"network_failure",message:"The Sketchi create-canvas API could not be reached.",hint:"Check the network connection and endpoint, then retry.",details:["transport"]})}function aT(e=[]){return nD.make({code:"malformed_response",message:"The Sketchi create-canvas API returned an unreadable response.",hint:"Retry once; if the response remains invalid, report the endpoint.",details:e})}function aM(e){return nD.make({code:"endpoint_failure",message:`The Sketchi create-canvas API responded with HTTP ${String(e)}.`,hint:"Check the endpoint and retry.",details:[`http_status:${String(e)}`]})}let aA=B.fn("sketchi.cli.canvas.request")(function*(e){var t,r,n,i,a,s;let o=yield*B.$mh({try:t=>globalThis.fetch(e.endpoint,{method:"POST",headers:{"content-type":"application/json","x-sketchi-client":"sketchi-cli"},body:JSON.stringify({spec:e.spec,options:{artifactFormats:["scene","excalidraw"],inlineArtifacts:["excalidraw"]}}),signal:t}),catch:aC}),l=yield*a_(o,0x1000000,aT,aC),d=yield*B.SvU({try:()=>JSON.parse(l),catch:()=>aT()}),c=yield*a$(d).pipe(B.xm_(e=>o.ok?aT(aS(e)):aM(o.status)));if(!c.ok)switch(c.status){case"export_failed":case"render_failed":case"storage_failed":return yield*(t=c.status,r=o.status,n=c.issues,nD.make({code:"endpoint_failure",message:`The Sketchi create-canvas API failed with status ${t}.`,hint:"Retry once; if the failure persists, report the endpoint and status.",details:[`status:${t}`,`http_status:${String(r)}`,...n.map(e=>`${e.code}: ${e.message}`)]}));case"invalid_canvas":case"invalid_input":case"limit_exceeded":let u;return yield*(i=c.status,a=o.status,u=(s=c.issues)[0],nD.make({code:"canvas_rejected",message:u?.message??"The create-canvas API rejected the CanvasSpec.",hint:"Correct the reported CanvasSpec issue and retry.",details:[`status:${i}`,`http_status:${String(a)}`,...s.map(e=>`${e.code}: ${e.message}`)]}))}return o.ok?c:yield*aM(o.status)},B.mgX({duration:av,orElse:()=>B.fJG(nD.make({code:"canvas_timeout",message:"The Sketchi canvas API request timed out.",hint:"Retry once; if it persists, check the endpoint and try a smaller canvas.",details:[]}))})),aN=B.fn("sketchi.cli.canvas.create")(function*(e){let t=yield*i6;yield*n9(e.spec.diagramId).pipe(B.xm_(e=>nP.make({message:e.message,hint:e.hint,details:["spec.diagramId"]})));let r=yield*aA(e);if(r.normalizedSpec.diagramId!==e.spec.diagramId)return yield*aT(["normalizedSpec.diagramId does not match submitted spec.diagramId"]);let n=r.artifact.formats.find(e=>"excalidraw"===e.format);if(n?.inline===void 0)return yield*aT(["artifact.formats.excalidraw.inline"]);let i=nx.q$Z(nM.yE,{errors:"all",reportInput:!0})(n.inline);if(!tL.oJ(i))return yield*aT((0,nM.z4)(i.failure).issues.map(e=>`${e.path.join(".")}: ${e.message}`));let a=yield*n9(r.normalizedSpec.diagramId).pipe(B.xm_(()=>aT(["normalizedSpec.diagramId is not storage-safe"])));if(r.artifact.diagramId!==a)return yield*aT(["artifact.diagramId does not match normalizedSpec.diagramId"]);let s={id:a,type:"canvas",title:r.normalizedSpec.title,document:{type:"canvas",spec:r.normalizedSpec},scene:r.normalizedSpec,excalidraw:i.success},o=yield*t.create(s);return{artifactId:r.artifact.artifactId,diagram:o}});var aP=n(1688);class aR extends Z.kl()("@sketchi/cli/CliPngRenderer"){}let aj=G.Py(aR,{renderPng:function(e){return B.$mh({try:async()=>(await Promise.all([n.e(548),n.e(869)]).then(n.bind(n,7665))).renderPngBytes(e),catch:e=>e instanceof aP.FG?e:aP.FG.make({cause:e,code:"rasterization_failed",stage:"rasterization",message:"Unable to rasterize the stored diagram as PNG.",details:[]})})},normalizeExcalidraw:function(e){return B.$mh({try:async()=>(await Promise.all([n.e(548),n.e(869)]).then(n.bind(n,7665))).normalizeExcalidrawArtifact(e),catch:e=>e instanceof aP.FG?e:aP.FG.make({cause:e,code:"invalid_render_artifact",stage:"artifact",message:"Unable to restore the Excalidraw share artifact.",details:[]})})}});class aD extends Z.kl()("@sketchi/cli/DiagramExporter"){}function aU(e,t){let r=`sketchi export ${e} --format png --dest ${e}.png`;return nL.make({code:t?.code??"invalid_render_artifact",format:"png",diagramId:e,storagePath:`~/.sketchi/diagrams/${e}`,recoveryCommand:r,message:t?.message??"Unable to read the stored PNG source artifacts.",hint:`The canonical record is preserved. Retry with: ${r}`,details:t?[`stage:${t.stage}`,...t.details]:["stage:artifact"]})}function aF(e,t){return B.SvU({try:()=>JSON.parse(new TextDecoder().decode(t)),catch:()=>aU(e)})}let aB=G.QZ(aD,B.JkU(function*(){let e=yield*i6,t=yield*aR,r=B.fn("sketchi.cli.export.renderPng")(function*(e,r){let n=[{format:"excalidraw",inline:yield*aF(e,r.excalidraw)}];r.scene&&n.unshift({format:"scene",inline:yield*aF(e,r.scene)});let i=yield*nY({formats:n},"export").pipe(B.xm_(()=>aU(e)));return yield*t.renderPng({...i}).pipe(B.xm_(t=>aU(e,t)))});return{exportArtifact:B.fn("sketchi.cli.export.artifact")(function*(t,n){let i=yield*e.readExportSource(t,n);return"StoredArtifact"===i._tag?i.bytes:yield*r(t,i)})}})),aL="gemini-3.1-flash-lite",az="https://playground.sketchi.app/api/v1/generate",aW="SKETCHI_GENERATE_ENDPOINT";function aJ(){return nj.make({code:"provider_failure",message:"The Sketchi generate API could not be reached.",hint:"Check your network connection and retry. create/show/edit/list/export/restore remain offline; share and pull are separate explicit network commands.",details:["transport"]})}function aY(){return nj.make({code:"malformed_output",message:"The Sketchi generate API returned an unreadable response.",hint:"Retry once; if it persists, report the prompt without secrets.",details:[]})}function aX(){return nj.make({code:"invalid_generated_document",message:"The generated diagram failed Sketchi schema or semantic validation.",hint:"Refine the prompt with concrete diagram content, then retry.",details:[]})}let aq=nx._kM({status:nx.Qrq(nx.QfV),issues:nx.Qrq(nx.O31(nx._kM({message:nx.Qrq(nx.QfV),hint:nx.Qrq(nx.QfV)})))}),aG=nx._Re(nx.mj7(aq)),aV=nx.$r1.check(nx.HNH(e=>void 0!==e)),aH=nx._kM({ok:nx.uSQ(!0),diagram:nx._kM({document:aV,scene:aV,excalidraw:aV}),generation:nx._kM({model:nx.ukk,provider:nx.ukk})}),aK=nx._Re(nx.mj7(aH)),aQ=B.fn("sketchi.cli.generate.request")(function*(e){let t=yield*B.$mh({try:t=>globalThis.fetch(e.endpoint,{method:"POST",headers:{"content-type":"application/json","x-sketchi-client":"sketchi-cli"},body:JSON.stringify({prompt:e.prompt,...e.type?{type:e.type}:{},model:e.model}),signal:t}),catch:()=>aJ()}),r=yield*a_(t,0x1000000,aY,aJ);if(!t.ok){let e=yield*aG(r).pipe(B.xm_(aY));return yield*function(e,t){let r=t.issues?.[0],n=[`http_status:${String(e)}`,...(t.issues??[]).flatMap(e=>[...e.message?[e.message]:[],...e.hint?[e.hint]:[]])];switch(t.status){case"generation_timeout":return nj.make({code:"generation_timeout",message:r?.message??"The generate API timed out.",hint:r?.hint??"Retry once; if it persists, try a shorter prompt.",details:n});case"malformed_output":return nj.make({code:"malformed_output",message:r?.message??"The generate API returned unreadable model output.",hint:r?.hint??"Retry once; if it persists, try another prompt.",details:n});case"invalid_input":case"invalid_generated_document":case"quality_failed":return nj.make({code:"invalid_generated_document",message:r?.message??"The generated diagram failed Sketchi validation.",hint:r?.hint??"Refine the prompt with concrete content, then retry.",details:n});case"unsupported_diagram_type":return nj.make({code:"unsupported_diagram_type",message:r?.message??"Sketchi does not natively support the requested diagram type.",hint:r?.hint??"Request a flowchart, mindmap, or sequence diagram instead.",details:n});default:return nj.make({code:"provider_failure",message:r?.message??`The Sketchi generate API responded with HTTP ${String(e)}.`,hint:r?.hint??"Retry once; if it persists, report the prompt without secrets.",details:n})}}(t.status,e)}let n=yield*aK(r).pipe(B.xm_(aY));return{...n.diagram,...n.generation}},B.mgX({duration:av,orElse:()=>B.fJG(nj.make({code:"generation_timeout",message:"The Sketchi generate API request timed out.",hint:"Retry once; if it persists, try a shorter prompt.",details:[]}))})),aZ=B.fn("sketchi.cli.generate")(function*(e){var t,r;let n,i,a=yield*i6,s=yield*aQ(e),o=yield*n2(s.document).pipe(B.xm_(()=>aX())),l=yield*n9(n8(o)).pipe(B.xm_(()=>aX())),d=yield*(t=s.scene,n=nx.q$Z(nM.Uh,{errors:"all",reportInput:!0})(t),tL.oJ(n)?B.PyW(n.success):B.fJG(aY())),c=yield*(r=s.excalidraw,i=nx.q$Z(nM.yE,{errors:"all",reportInput:!0})(r),tL.oJ(i)?B.PyW(i.success):B.fJG(aY())),u={id:l,type:o.type,title:o.spec.title,document:o,scene:d,excalidraw:c};return{diagram:yield*a.create(u),model:s.model,provider:s.provider}});function a0(e,t){switch(t){case"png":return`${e}.png`;case"excalidraw":return`${e}.excalidraw`;case"scene":return`${e}.scene.json`}}let a1=B.fn("sketchi.cli.exportCreatedDiagram")(function*(e,t,r){let n=yield*aD,i=e.manifest.id,a=function(e,t,r){switch(r._tag){case"Default":return a0(e,t);case"CurrentDirectory":return(0,rR.resolve)(r.cwd,a0(e,"png"));case"ProjectDiagrams":return(0,rR.resolve)(r.cwd,"diagrams",a0(e,"png"));case"Custom":return r.path}}(i,t,r),s=yield*n.exportArtifact(i,t).pipe(B.xm_(e=>a2(e,i,t)));return yield*B.JkU(function*(){if("-"!==a){if("ProjectDiagrams"===r._tag){let e=yield*it;yield*e.makeDirectory((0,rR.join)(r.cwd,"diagrams"),!0)}yield*ay(a,s)}}).pipe(B.xm_(e=>a2(e,i,t))),{id:i,format:t,destination:a,sizeBytes:s.byteLength,..."-"===a?{stdoutBytes:s}:{}}});function a2(e,t,r){let n=a0(t,r),i=`sketchi export ${t} --format ${r} --dest ${n}`,a="CliExportError"===e._tag?e.details:"CliStorageError"===e._tag?[`storage_error:${e.code}`]:[`filesystem_operation:${e.operation}`,`path:${e.path}`];return nL.make({code:"CliExportError"===e._tag?e.code:"CliStorageError"===e._tag?"invalid_render_artifact":"export_write_failed",diagramId:t,storagePath:`~/.sketchi/diagrams/${t}`,recoveryCommand:i,...a?{details:a}:{},format:r,message:e.message,hint:`The local record is preserved. Retry with: ${i}`})}let a5=B.fn("sketchi.cli.generateWorkflow")(function*(e){let t=yield*aZ(e),r=yield*a1(t.diagram,e.format,e.destination);return{generated:t,artifact:r}}),a3=t("node:util"),a6=t("node:process"),a8=(A=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,e=>{let t=0;for(A.lastIndex=0;A.test(e);)t+=1;return e.length-t}),a9=e=>12288===e||e>=65281&&e<=65376||e>=65504&&e<=65510,a4=e=>8987===e||9001===e||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141,a7=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,se=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,st=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,sr=/\t{1,1000}/y,sn=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,si=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,sa=/\p{M}+/gu,ss={limit:1/0,ellipsis:""},so=(e,t={},r={})=>{let n=t.limit??1/0,i=t.ellipsis??"",a=t?.ellipsisWidth??(i?so(i,ss,r).width:0),s=r.controlWidth??0,o=r.tabWidth??8,l=r.emojiWidth??2,d=r.regularWidth??1,c=r.wideWidth??2,u=[[si,d],[a7,0],[se,s],[sr,o],[sn,l],[st,c]],f=0,p=0,h=e.length,m=0,g=!1,y=h,v=Math.max(0,n-a),b=0,_=0,x=0,w=0;e:for(;;){if(_>b||p>=h&&p>f){for(let t of(m=0,(e.slice(b,_)||e.slice(f,p)).replaceAll(sa,""))){let e=t.codePointAt(0)||0;if(x+(w=a9(e)?2:a4(e)?c:d)>v&&(y=Math.min(y,Math.max(b,f)+m)),x+w>n){g=!0;break e}m+=t.length,x+=w}b=_=0}if(p>=h)break;for(let t=0,r=u.length;t<r;t++){let[r,i]=u[t];if(r.lastIndex=p,r.test(e)){if(x+(w=(m=r===st?a8(e.slice(p,r.lastIndex)):r===sn?1:r.lastIndex-p)*i)>v&&(y=Math.min(y,p+Math.floor((v-x)/i))),x+w>n){g=!0;break e}x+=w,b=f,_=p,p=f=r.lastIndex;continue e}}p+=1}return{width:g?v:x,index:g?y:h,truncated:g,ellipsed:g&&n>=a}},sl={limit:1/0,ellipsis:"",ellipsisWidth:0},sd=(e,t={})=>so(e,sl,t).width,sc="]8;;",su=RegExp(`(?:\\[(?<code>\\d+)m|\\${sc}(?<uri>.*)\x07)`,"y"),sf=e=>e>=30&&e<=37||e>=90&&e<=97?39:e>=40&&e<=47||e>=100&&e<=107?49:1===e||2===e?22:3===e?23:4===e?24:7===e?27:8===e?28:9===e?29:0===e?0:void 0,sp=e=>`\x1b[${e}m`,sh=e=>`\x1b${sc}${e}\x07`,sm=(e,t,r)=>{let n=t[Symbol.iterator](),i=!1,a=!1,s=e.at(-1),o=void 0===s?0:sd(s),l=n.next(),d=n.next(),c=0;for(;!l.done;){let s=l.value,u=sd(s);o+u<=r?e[e.length-1]+=s:(e.push(s),o=0),("\x1b"===s||"›"===s)&&(i=!0,a=t.startsWith(sc,c+1)),i?a?"\x07"===s&&(i=!1,a=!1):"m"===s&&(i=!1):(o+=u)!==r||d.done||(e.push(""),o=0),l=d,d=n.next(),c+=s.length}s=e.at(-1),!o&&void 0!==s&&s.length&&e.length>1&&(e[e.length-2]+=e.pop())},sg=/\r?\n/;function sy(e,t,r){return String(e).normalize().split(sg).map(e=>((e,t,r={})=>{let n,i;if(!1!==r.trim&&""===e.trim())return"";let a="",s=e.split(" "),o=[""],l=0;for(let e=0;e<s.length;e++){let n=s[e];if(!1!==r.trim){let e=o.at(-1)??"",t=e.trimStart();e.length!==t.length&&(o[o.length-1]=t,l=sd(t))}0!==e&&(l>=t&&(!1===r.wordWrap||!1===r.trim)&&(o.push(""),l=0),(l||!1===r.trim)&&(o[o.length-1]+=" ",l++));let i=sd(n);if(r.hard&&i>t){let e=1+Math.floor((i-(t-l)-1)/t);Math.floor((i-1)/t)<e&&o.push(""),sm(o,n,t),l=sd(o.at(-1)??"");continue}if(l+i>t&&l&&i){if(!1===r.wordWrap&&l<t){sm(o,n,t),l=sd(o.at(-1)??"");continue}o.push(""),l=0}if(l+i>t&&!1===r.wordWrap){sm(o,n,t),l=sd(o.at(-1)??"");continue}o[o.length-1]+=n,l+=i}!1!==r.trim&&(o=o.map(e=>(e=>{let t=e.split(" "),r=t.length;for(;r&&!sd(t[r-1]);)r--;return r===t.length?e:t.slice(0,r).join(" ")+t.slice(r).join("")})(e)));let d=o.join("\n"),c=!1;for(let e=0;e<d.length;e++){let t=d[e];if(a+=t,c)c=!1;else if(c=t>="\uD800"&&t<="\uDBFF")continue;if("\x1b"===t||"›"===t){su.lastIndex=e+1;let t=su.exec(d),r=t?.groups;if(r?.code!==void 0){let e=Number.parseFloat(r.code);n=39===e?void 0:e}else r?.uri!==void 0&&(i=0===r.uri.length?void 0:r.uri)}if("\n"===d[e+1]){i&&(a+=sh(""));let e=n?sf(n):void 0;n&&e&&(a+=sp(e))}else"\n"===t&&(n&&sf(n)&&(a+=sp(n)),i&&(a+=sh(i)))}return a})(e,t,r)).join("\n")}var sv=n(5776);let sb=t("node:tty");function s_(e,t,r){if(!r.some(e=>!e.disabled))return e;let n=e+t,i=Math.max(r.length-1,0),a=n<0?i:n>i?0:n;return r[a]?.disabled?s_(a,t<0?-1:1,r):a}let sx={actions:new Set(["up","down","left","right","space","enter","cancel"]),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,accessible:void 0,date:{monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:e=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:e=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function sw(e,t){if("string"==typeof e)return sx.aliases.get(e)===t;for(let r of e)if(void 0!==r&&sw(r,t))return!0;return!1}let sk=globalThis.process.platform.startsWith("win"),sS=Symbol("clack:cancel");function sI(e,t){e.isTTY&&e.setRawMode(t)}let s$=e=>"columns"in e&&"number"==typeof e.columns?e.columns:80,sE=e=>"rows"in e&&"number"==typeof e.rows?e.rows:20;function sO(e,t,r,n=r,i=r,a){return sy(t,s$(e??a6.stdout)-r.length,{hard:!0,trim:!1}).split(`
4
4
  `).map((e,t,s)=>{let o=a?a(e,t):e;return 0===t?`${n}${o}`:t===s.length-1?`${i}${o}`:`${r}${o}`}).join(`
5
5
  `)}class sC{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";get accessible(){var e=this.opts.accessible;if(void 0!==e)return e;if(void 0!==sx.accessible)return sx.accessible;let t=process.env.ACCESSIBLE;return void 0!==t&&""!==t&&"0"!==t&&"false"!==t}constructor(e,t=!0){let{input:r=a6.stdin,output:n=a6.stdout,render:i,signal:a,...s}=e;this.opts=s,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=t,this._abortSignal=a,this.input=r,this.output=n}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let r=this._subscribers.get(e)??[];r.push(t),this._subscribers.set(e,r)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let r=this._subscribers.get(e)??[],n=[];for(let e of r)e.cb(...t),e.once&&n.push(()=>r.splice(r.indexOf(e),1));for(let e of n)e()}prompt(){return new Promise(e=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),e(sS);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=n$.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),void 0!==this.opts.initialUserInput&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),sI(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(sv.cursor.show),this.output.off("resize",this.render),sI(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(sv.cursor.show),this.output.off("resize",this.render),sI(this.input,!1),e(sS)})})}_isActionKey(e,t){return" "===e}_shouldSubmit(e,t){return!0}_setValue(e){this.value=e,this.emit("value",this.value)}_setUserInput(e,t){this.userInput=e??"",this.emit("userInput",this.userInput),t&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}async onKeypress(e,t){if("validating"!==this.state){if(this._track&&"return"!==t.name&&(t.name&&this._isActionKey(e,t)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),"error"===this.state&&(this.state="active"),t?.name&&(!this._track&&sx.aliases.has(t.name)&&this.emit("cursor",sx.aliases.get(t.name)),sx.actions.has(t.name)&&this.emit("cursor",t.name)),e&&("y"===e.toLowerCase()||"n"===e.toLowerCase())&&this.emit("confirm","y"===e.toLowerCase()),this.emit("key",e,t),t?.name==="return"&&this._shouldSubmit(e,t)){if(this.opts.validate){let e,t=function(e,t){if("~standard"in e){let r=e["~standard"].validate(t);return r instanceof Promise?r.then(e=>e.issues?.at(0)?.message):r.issues?.at(0)?.message}return e(t)}(this.opts.validate,this.value);t instanceof Promise?(this.state="validating",this.render(),e=await t):e=t,e&&(this.error=e instanceof Error?e.message:e,this.state="error",this.rl?.write(this.userInput))}"error"!==this.state&&(this.state="submit")}sw([e,t?.name,t?.sequence],"cancel")&&(this.state="cancel"),("submit"===this.state||"cancel"===this.state)&&this.emit("finalize"),this.render(),("submit"===this.state||"cancel"===this.state)&&this.close()}}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
6
6
  `),sI(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=sy(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
@@ -227,7 +227,7 @@ authority: ${e.diagram.authority}`,e=>({id:e.diagram.manifest.id,restoredFromRev
227
227
  `:`error: usage_error
228
228
  ${r}
229
229
  next: ${a}
230
- `)}},d=new Proxy(globalThis.console,{get(e,t,r){if("log"===t)return(...t)=>{(1!==t.length||""!==t[0])&&e.log(...t)};let n=Reflect.get(e,t,r);return"function"==typeof n?n.bind(e):n}}),uy(pZ,{version:"0.6.2"})(e).pipe(B.sFT(e=>eh.i5(e,oi)&&"ShowHelp"!==e._tag?or(l.formatErrors([e])):B.rIH),B.PfK(dr,{builtIns:[l8,l9,l7]}),B.PfK(o3,l),B.PfK(oe,d))).pipe(B.khu({onFailure:e=>B.JkU(function*(){let t,r=ee.getOrUndefined(F.L$(e));if(r instanceof f8)return r.exitCode;if(r instanceof nA)return 7;let n=function(e){if(eh.i5(e,oi))return"ShowHelp"===e._tag?2*(e.errors.length>0):2}(r);if(void 0!==n)return n;let i=yield*f6;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?n6({ok:!1,command:"sketchi",error:t}):f7(t))).pipe(B.MfU(()=>B.rIH)),1}),onSuccess:()=>B.PyW(0)}))}),p1=G.Um(nM.Tx,(0,nM.rR)({createId:e=>`${e}_offline_cli`})),p2=G.Gt(n7,p1),p5=G.Gt(ip,p1),p3=G.Um(is,aa),p6=G.Gt(ag,p3),p8=G.Gt(aB,G.Um(p6,aj)),p9=G.Gt(py,pf),p4=G.Um(is,aa,p2,p5,p6,p8,aj,p9,pm,ig.pipe(G.Gt(is)),f4,s7),p7=G.S5(p4,nT);q(p0(process.argv.slice(2)).pipe(B.Mim(e=>B.OH5(()=>{process.exitCode=e})),B.Gte(p7)),{disableErrorReporting:!0})},1688(e,t,r){var n=r(2718);let i=n.xCb(["invalid_render_artifact","render_limit_exceeded","unsupported_render_glyph","rasterization_failed"]),a=n.xCb(["artifact","geometry","font","rasterization"]);class s extends n.rNF()("HeadlessPngRenderError",{cause:n.kld(),code:i,stage:a,message:n.QfV,details:n.O31(n.QfV)}){}r.d(t,{FG:()=>s})},5030(e,t,r){function n(e,t,r,n){return{code:e,message:t,...void 0===r?{}:{observed:r},...void 0===n?{}:{limit:n}}}function i(e,t=0){let r=1/0,a=1/0,s=-1/0,o=-1/0;for(let t of e){var l;if(!("object"==typeof(l=t)&&null!==l&&!Array.isArray(l)&&"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 n("invalid_geometry","element geometry is invalid");let e=Math.abs(t.width),i=Math.abs(t.height);if(e>8192||i>8192)return n("element_dimension",`element dimension exceeds ${String(8192)}`,Math.max(e,i),8192);let d=Math.hypot(e,i)/2,c=t.x+t.width/2,u=t.y+t.height/2;r=Math.min(r,c-d),a=Math.min(a,u-d),s=Math.max(s,c+d),o=Math.max(o,u+d)}if(0===e.length)return;let d=s-r,c=o-a;if(d>8192||c>8192)return n("canvas_dimension",`canvas dimension exceeds ${String(8192)}`,Math.max(d,c),8192);let u=d*c;if(u>6291456)return n("canvas_area",`canvas area exceeds ${String(6291456)}`,u,6291456);let f=(d+40)*1*((c+40+t)*1);if(f>0x1800000)return n("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,f,0x1800000)}function a(e,t=0){return i(e,t)?.message}function s(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return n("invalid_geometry","rendered SVG dimensions are invalid");let r=Math.min(2,16384/e,16384/t,Math.sqrt(0x1800000/(e*t)));if(r<1){let r=e*t;return r>0x1800000?n("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,r,0x1800000):n("output_dimension","rendered SVG dimension exceeds the PNG limit at minimum scale",Math.max(e,t),16384)}return Math.max(1,Math.floor(1e3*r)/1e3)}r.d(t,{Gd:()=>a,Ts:()=>i,Yu:()=>s},{Z4:6291456,ce:0x1800000})},6982(e){e.exports=t("crypto")},7598(e){e.exports=t("node:crypto")},76(e,t,r){let n=r(9095),i=process.env;function a(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:n.map(function(e){return e.constant})}),t.name=null,t.isPR=null,t.id=null,"false"!==i.CI&&n.forEach(function(e){let r=(Array.isArray(e.env)?e.env:[e.env]).every(function(e){return a(e)});t[e.constant]=r,r&&(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 a(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,r){e.exports=r(76).isCI},664(e,t,r){r.d(t,{CN:()=>p,BC:()=>g,Ie:()=>I,pb:()=>O,i8:()=>w,g9:()=>x,Uk:()=>k,Ts:()=>h,CZ:()=>y,ET:()=>v,HV:()=>b,T9:()=>M,Tj:()=>E,YW:()=>m,of:()=>$,jB:()=>C,TS:()=>T,di:()=>S});var n=r(7876),i=r(1594);let a=e=>e.length>0;var s=r(9771),o=r(592),l=r(1587),d=r(2860),c=r(915),u=r(9315);let f=globalThis.Array,p=e=>new f(s.S(e)),h=e=>f.isArray(e)?e:f.from(e);c.Wo,l.toArray;let m=(0,i.XY)(2,(e,{onEmpty:t,onNonEmpty:r})=>v(e)?r(e):t()),g=(0,i.XY)(2,(e,t)=>[...e,t]);f.isArray;let y=a,v=a,b=e=>v(e)?l.some(_(e)):l.none(),_=e=>e[e.length-1],x=(0,i.XY)(2,(e,t)=>{let r=0;for(let n of e){if(t(n,r))return l.some(r);r++}return l.none()}),w=o.i8,k=(0,i.XY)(2,(e,t)=>{let r=h(e);for(let e=r.length-1;e>=0;e--){let n=r[e],i=t(n,e);if("boolean"==typeof i){if(i)return l.some(n)}else if(l.isSome(i))return i}return l.none()}),S=(0,i.XY)(2,(e,t)=>{let r=f.from(e);return r.sort(t),r}),I=()=>[],$=e=>[e],E=(0,i.XY)(2,(e,t)=>e.map(t)),O=(0,i.XY)(2,(e,t)=>{let r=h(e),n=[];for(let e=0;e<r.length;e++)t(r[e],e)&&n.push(r[e]);return n}),C=(0,i.XY)(2,(e,t)=>{let r=[],n=[],i=0;for(let a of e){let e=t(a,i++);u.oJ(e)?r.push(e.success):n.push(e.failure)}return[r,n]}),T=(0,i.XY)(3,(e,t,r)=>h(e).reduce((e,t,n)=>r(e,t,n),t));d.O3;let M=n.O3},5053(e,t,r){var n=r(9519),i=r(7876),a=r(1594),s=r(1587),o=r(2860),l=r(4233),d=r(636);let c=globalThis.BigInt,u=c(0);l.sI;let f=(0,a.XY)(2,(e,t)=>e+t),p=o.Qw,h=i.Qw,m=o.hl(p),g=o.bi(p),y=o.yJ(p),v=o.OW(p),b=o.Bt(p),_=o.qE(p),x=o.jk(p),w=o.T9(p),k=d.L((e,t)=>e+t,u),S=n.T9(p),I=n.jk(p);r.d(t,{},{K0:I,OW:v,Ro:e=>e>c(Number.MAX_SAFE_INTEGER)||e<c(Number.MIN_SAFE_INTEGER)?s.none():s.some(Number(e)),T9:w,Tq:b,aD:k,bi:g,cz:f,hl:m,jk:x,pH:p,qE:_,rs:h,sO:S,yJ:y})},3265(e,t,r){var n=r(5053),i=r(1587);let a=BigInt(0),s=BigInt(1),o=BigInt(1e3),l=BigInt(1024),d=[{symbol:"B",factor:s,names:["B","byte","bytes"]},{symbol:"kB",factor:o,names:["kB","kilobyte","kilobytes"]},{symbol:"MB",factor:o**BigInt(2),names:["MB","megabyte","megabytes"]},{symbol:"GB",factor:o**BigInt(3),names:["GB","gigabyte","gigabytes"]},{symbol:"TB",factor:o**BigInt(4),names:["TB","terabyte","terabytes"]},{symbol:"PB",factor:o**BigInt(5),names:["PB","petabyte","petabytes"]},{symbol:"EB",factor:o**BigInt(6),names:["EB","exabyte","exabytes"]},{symbol:"ZB",factor:o**BigInt(7),names:["ZB","zettabyte","zettabytes"]},{symbol:"YB",factor:o**BigInt(8),names:["YB","yottabyte","yottabytes"]},{symbol:"RB",factor:o**BigInt(9),names:["RB","ronnabyte","ronnabytes"]},{symbol:"QB",factor:o**BigInt(10),names:["QB","quettabyte","quettabytes"]}],c=[d[0],{symbol:"KiB",factor:l,names:["KiB","kibibyte","kibibytes"]},{symbol:"MiB",factor:l**BigInt(2),names:["MiB","mebibyte","mebibytes"]},{symbol:"GiB",factor:l**BigInt(3),names:["GiB","gibibyte","gibibytes"]},{symbol:"TiB",factor:l**BigInt(4),names:["TiB","tebibyte","tebibytes"]},{symbol:"PiB",factor:l**BigInt(5),names:["PiB","pebibyte","pebibytes"]},{symbol:"EiB",factor:l**BigInt(6),names:["EiB","exbibyte","exbibytes"]},{symbol:"ZiB",factor:l**BigInt(7),names:["ZiB","zebibyte","zebibytes"]},{symbol:"YiB",factor:l**BigInt(8),names:["YiB","yobibyte","yobibytes"]}],u=new Map([...d,...c.slice(1)].flatMap(e=>e.names.map(t=>[t,e]))),f=e=>{throw Error(`Invalid ByteSize: ${e}`)},p=e=>!Number.isSafeInteger(e)||e<0?f(`expected a non-negative safe integer, received ${e}`):BigInt(e),h=e=>{let t=/^\s*(\d+)(?:\.(\d+))?\s*([A-Za-z]+)\s*$/.exec(e);if(null===t)return f(`unsupported syntax ${JSON.stringify(e)}`);let r=u.get(t[3]);if(void 0===r)return f(`unsupported unit ${JSON.stringify(t[3])}`);let n=t[2]??"",i=BigInt(10)**BigInt(n.length),s=BigInt(t[1]+n)*r.factor;return s%i!==a?f(`${JSON.stringify(e)} does not represent an integral number of bytes`):s/i},m=i.liftThrowable(h),g=e=>{switch(typeof e){case"bigint":if(e<a)return f(`expected a non-negative bigint, received ${e}`);return e;case"number":return p(e);case"string":return h(e)}return f(`unsupported input ${e}`)},y=i.liftThrowable(g),v=n.Ro;n.pH,n.rs,n.Tq,n.jk,n.T9,n.qE,n.hl,n.bi,n.yJ,n.OW,n.cz,n.aD,n.sO,n.K0,r.d(t,{},{Dg:e=>e,Ro:v,bN:g,ee:e=>"bigint"==typeof e?g(e):p(e),lX:y,sH:m,yp:e=>"bigint"==typeof e&&e>=a})},719(e,t,r){var n=r(2449),i=r(6297);n.PX,n.B4,n.Aj,n.Wg;let a=n.lC;n.Xb,n.ik;let s=n.b5;n.DH;let o=n.OE,l=n.Iu;i.nIy,i.ORc;let d=i.nn5,c=i.O$X;n.h2;let u=i.ReC;i.myX,i.QE5,i.khU;let f=i.L$u;i.gpn,i.k7S,i.BbX;let p=i.prj;i.tU5,i.h74,i.Bou,i.RJ6;let h=i.GyP;n.PW,n.qB,n.Xm;let m=n.$L;n.q_;let g=n.RS,y=n.Vw;i.DQo,i.c8t,i.MUS,i.t8c,i._y;let v=i.qwd;i.ASO,i.F7W,i.Aub,i.cOF,i.Rft,i.RD4,i.Kkt,i.PnV;let b=i.Bk6;n.Eh,i.tQ6,i.On5,r.d(t,{},{$L:m,Bk:b,F_:l,L$:f,RS:g,Tj:c,Vw:y,fJ:o,iw:u,j9:h,kO:s,lC:a,nn:d,pr:p,qw:v})},4238(e,t,r){var n=r(6297);n.a1U,n.RKA;let i=n.Rud;n.s0X,n.T13,r.d(t,{},{Ru:i})},9519(e,t,r){function n(e){return{combine:e}}function i(e){return n((t,r)=>-1===e(t,r)?t:r)}function a(e){return n((t,r)=>1===e(t,r)?t:r)}r.d(t,{L8:()=>n,T9:()=>a,jk:()=>i})},1179(e,t,r){var n=r(3811),i=r(3332),a=r(1594),s=r(5033),o=r(2449),l=r(1587),d=r(4233);let c="~effect/Context/Service",u=function(){let e=function(){};Object.setPrototypeOf(e,f);let t=(t,r)=>(e.key=t,r?.defaultValue&&(e[h]=h,e.defaultValue=r.defaultValue),r?.make&&(e.make=r.make),r?.fiberCached&&p.add(t),e);return arguments.length>0?t(arguments[0],arguments[1]):t},f={[c]:c,...n.bp({label:"Service",evaluate(e){return(0,o.xt)(A(e.context,this))}}),toJSON(){return{_id:"Service",key:this.key}},of:e=>e,context(e){return $(this,e)},use(e){return(0,o.R6)(t=>e(A(t.context,this)))},useSync(e){return(0,o.R6)(t=>(0,o.xt)(e(A(t.context,this))))}},p=new Set,h="~effect/Context/Reference",m="~effect/Context",g=(e,t,r,n)=>{let i=Object.create(w);return i.cacheRoot=e??i,i.base=t,i.overlay=r,i.depth=n,i._flat=void 0,i.baseHits=0,i},y=(e,t)=>{t&&(y(e,t.parent),e.set(t.key,t.value))},v=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return y(t,e.overlay),e._flat=t},b=Symbol(),_=(e,t)=>{for(let r=e.overlay;r;r=r.parent)if(r.key===t)return r.value;let r=e.base.get(t);return void 0!==r||e.base.has(t)?(e.overlay&&++e.baseHits>=e.base.size&&e.baseHits>=8&&(e.base=v(e),e.overlay=void 0,e.depth=0),r):b},x=e=>g(void 0,e,void 0,0),w={get mapUnsafe(){return v(this)},...o.fU,[m]:{_Services:e=>e},toJSON(){return{_id:"Context",services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[i.HR](e){if(!k(e))return!1;let t=this.mapUnsafe,r=e.mapUnsafe;if(t.size!==r.size)return!1;for(let[e,n]of t)if(!r.has(e)||!i.aI(n,r.get(e)))return!1;return!0},[s.HR](){return s.ai(this.mapUnsafe.size)}},k=e=>(0,d.i5)(e,m),S=e=>!!e[h],I=x(new Map),$=(e,t)=>x(new Map([[e.key,t]])),E=(0,a.XY)(3,(e,t,r)=>O(e,t.key,r)),O=(e,t,r)=>{let n=p.has(t)?void 0:e.cacheRoot;if(e.depth>=8){let i=new Map(e.mapUnsafe);return i.set(t,r),g(n,i,void 0,0)}return g(n,e.base,{key:t,value:r,parent:e.overlay},e.depth+1)},C=(0,a.XY)(2,(e,t)=>T(e,t.key)),T=(e,t)=>{let r=_(e,t);return r===b?void 0:r},M=(0,a.XY)(2,(e,t)=>{let r=_(e,t.key);if(r===b){if(S(t))return P(t);throw R(t)}return r}),A=M,N="~effect/Context/defaultValue",P=e=>N in e?e[N]:e[N]=e.defaultValue(),R=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},j=(0,a.XY)(2,(e,t)=>{let r=_(e,t.key);return r!==b?l.some(r):S(t)?l.some(P(t)):l.none()}),D=(0,a.XY)(2,(e,t)=>{let r;return 0===e.mapUnsafe.size?t:0===t.mapUnsafe.size?e:((e=>t.mapUnsafe.forEach((t,r)=>e.set(r,t)))(r=new Map(e.mapUnsafe)),x(r))});r.d(t,{},{Ie:()=>I,Jt:A,L8:$,LZ:x,Or:u,Pf:(e,t)=>e.cacheRoot===t.cacheRoot,Ub:T,Um:(...e)=>{let t=new Map;for(let r=0;r<e.length;r++)e[r].mapUnsafe.forEach((e,r)=>{t.set(r,e)});return x(t)},WQ:E,Y6:C,aE:k,fp:M,h1:D,kl:u,om:j})},4942(e,t,r){var n=r(2449),i=r(2275),a=r(1554),s=r(4233);let o=class extends a.Xs{constructor(e){super(),e&&i.z(this,e)}};function l(){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=n.$D,c=n.rN;r.d(t,{},{$D:d,Ij:()=>new Proxy({},{get:(e,t,r)=>"$is"===t?s.$J:"$match"===t?l:e=>({...e,_tag:t})}),Xs:o,rN:c})},9237(e,t,r){var n=r(1594),i=r(6297),a=r(1554);let s={"~effect/Deferred":{_A:n.D_,_E:n.D_},pipe(){return(0,a.tT)(this,arguments)}},o=function(){this.resumes=void 0,this.effect=void 0};o.prototype=s;let l=e=>void 0!==e.effect;r.d(t,{},{$L:e=>i.OH5(()=>l(e)),$w:(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let r=e.resumes;e.resumes=void 0;for(let e=0;e<r.length;e++)r[e](t)}return!0},LZ:()=>new o,NJ:l,Tx:e=>i.E2r(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),i.OH5(()=>{let r=e.resumes;if(void 0===r)return;let n=r.indexOf(t);n>=0&&r.splice(n,1)})))})},3614(e,t,r){var n=r(3332),i=r(1594),a=r(5033),s=r(3952),o=r(2860),l=r(1554),d=r(4233);let c="~effect/Duration",u=BigInt(0),f=BigInt(1),p=BigInt(2),h=BigInt(10),m=BigInt(24),g=BigInt(60),y=BigInt(1e3),v=BigInt(1e6),b=e=>BigInt(e<0?Math.ceil(e-.5):Math.floor(e+.5)),_=(e,t)=>{let r=e.indexOf(".");if(-1===r)return BigInt(e)*t;let n="-"===e[0],i=e.slice(r+1),a=h**BigInt(i.length),s=(BigInt(e.slice(+!!n,r))*a+BigInt(i))*t,o=s/a+(s%a*p>=a?f:u);return n?-o:o},x=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,w=e=>{switch(typeof e){case"number":return P(e);case"bigint":return N(e);case"string":{if("Infinity"===e)return M;if("-Infinity"===e)return A;let t=x.exec(e);if(!t)break;let[r,n,i]=t;if("nano"===i||"nanos"===i)return N(_(n,f));if("micro"===i||"micros"===i)return N(_(n,y));let a=Number(n);switch(i){case"milli":case"millis":return P(a);case"second":case"seconds":return R(a);case"minute":case"minutes":return j(a);case"hour":case"hours":return D(a);case"day":case"days":return U(a);case"week":case"weeks":return F(a)}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 k(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return T;if(-1/0===e[0]||-1/0===e[1])return A;if(1/0===e[0]||1/0===e[1])return M;return O(b(1e9*e[0]+e[1]))}let t=0;if(e.weeks&&(t+=6048e5*e.weeks),e.days&&(t+=864e5*e.days),e.hours&&(t+=36e5*e.hours),e.minutes&&(t+=6e4*e.minutes),e.seconds&&(t+=1e3*e.seconds),e.milliseconds&&(t+=e.milliseconds),!e.microseconds&&!e.nanoseconds)return O(t);return O(b(1e6*t+(e.microseconds??0)*1e3+(e.nanoseconds??0)))}}return k(e)},k=e=>{throw Error(`Invalid Input: ${e}`)},S={_tag:"Millis",millis:0},I={_tag:"Infinity"},$={_tag:"NegativeInfinity"},E={[c]:c,[a.HR](){switch(this.value._tag){case"Millis":{let e=1e6*this.value.millis;return Number.isFinite(e)?a.tW(b(e)):a.ai(this.value.millis)}case"Nanos":return a.tW(this.value.nanos);default:return a.QK(this.value)}},[n.HR](e){return C(e)&&Y(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"}}},[s.FX](){return this.toJSON()},pipe(){return(0,l.tT)(this,arguments)}},O=e=>{let t=Object.create(E);return"number"==typeof e?isNaN(e)||0===e||Object.is(e,-0)?t.value=S:Number.isFinite(e)?Number.isInteger(e)?t.value={_tag:"Millis",millis:e}:t.value={_tag:"Nanos",nanos:b(1e6*e)}:t.value=e>0?I:$:e===u?t.value=S:t.value={_tag:"Nanos",nanos:e},t},C=e=>(0,d.i5)(e,c),T=O(0),M=O(1/0),A=O(-1/0),N=e=>O(e),P=e=>O(e),R=e=>O(1e3*e),j=e=>O(6e4*e),D=e=>O(36e5*e),U=e=>O(864e5*e),F=e=>O(6048e5*e),B=e=>{let t=w(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 b(1e6*t.value.millis)}},L=(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)()}}),z=(0,i.XY)(3,(e,t,r)=>"Infinity"===e.value._tag||"NegativeInfinity"===e.value._tag||"Infinity"===t.value._tag||"NegativeInfinity"===t.value._tag?r.onInfinity(e,t):"Millis"===e.value._tag?"Millis"===t.value._tag?r.onMillis(e.value.millis,t.value.millis):r.onNanos(B(e),t.value.nanos):r.onNanos(e.value.nanos,B(t))),W=o.L8((e,t)=>z(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})),J=o.bi(W),Y=(0,i.XY)(2,(e,t)=>z(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag})),X=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===u;case"Infinity":case"NegativeInfinity":return!1}})(e))return"0";if((e=>{switch(e.value._tag){case"Millis":return e.value.millis<0;case"Nanos":return e.value.nanos<u;case"NegativeInfinity":return!0;case"Infinity":return!1}})(e))return"-"+X((e=>{switch(e.value._tag){case"Infinity":case"NegativeInfinity":return M;case"Millis":return e.value.millis<0?O(-e.value.millis):e;case"Nanos":return e.value.nanos<u?O(-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=B(e),r=t<u,n=r?-t:t,i=n/v,a=i/y,s=a/g,o=s/g,l=r?-1:1;return{days:l*Number(o/m),hours:l*Number(o%m),minutes:l*Number(s%g),seconds:l*Number(a%g),millis:l*Number(i%y),nanos:l*Number(n%v)}})(e),r=[];return 0!==t.days&&r.push(`${t.days}d`),0!==t.hours&&r.push(`${t.hours}h`),0!==t.minutes&&r.push(`${t.minutes}m`),0!==t.seconds&&r.push(`${t.seconds}s`),0!==t.millis&&r.push(`${t.millis}ms`),0!==t.nanos&&r.push(`${t.nanos}ns`),r.join(" ")};r.d(t,{},{GP:X,MI:e=>"Infinity"!==e.value._tag&&"NegativeInfinity"!==e.value._tag,Tn:M,YA:R,bN:w,bi:J,cF:N,fP:e=>L(w(e),{onMillis:e=>e/1e3,onNanos:e=>Number(e)/1e9,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),kE:e=>L(w(e),{onMillis:i.D_,onNanos:e=>Number(e)/1e6,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),n$:C,ne:P,qv:A,v_:T})},2842(e,t,r){r.d(t,{Q56:()=>e_,jGc:()=>ex,U9h:()=>ew,Q7R:()=>w,hgn:()=>z,swY:()=>ez,Muk:()=>eT,as:()=>G,E2r:()=>M,MfU:()=>V,Tyx:()=>Q,osR:()=>Z,KuX:()=>H,loE:()=>K,RKA:()=>eB,_32:()=>eM,F_Q:()=>D,_r7:()=>eW,yeE:()=>ek,NS5:()=>X,fJG:()=>P,ATB:()=>R,pVV:()=>j,qIB:()=>L,Ab9:()=>eq,fn:()=>eF,D9k:()=>eU,vCS:()=>eG,jJl:()=>k,i4r:()=>eC,ar0:()=>eN,x6Z:()=>eP,yUA:()=>B,JkU:()=>N,XeO:()=>ea,GaK:()=>e$,yw5:()=>x,vVN:()=>eL,TjK:()=>q,q7Y:()=>eX,jkJ:()=>eJ,xm_:()=>ee,Z9x:()=>eY,YWq:()=>ec,khu:()=>eu,tvg:()=>ef,ZmZ:()=>A,S5A:()=>eS,cfM:()=>eI,uKv:()=>Y,QgK:()=>et,ivC:()=>I,Gte:()=>ep,PpN:()=>eh,PfK:()=>eg,KT6:()=>ed,Ket:()=>J,L5P:()=>ei,MY7:()=>eR,eJC:()=>ej,lKS:()=>eD,z8E:()=>ey,P1j:()=>ev,Pxi:()=>eb,Nav:()=>em,yy4:()=>el,PyW:()=>E,DYE:()=>O,OH5:()=>C,Mim:()=>W,dGm:()=>en,sFT:()=>er,wRz:()=>es,mgX:()=>eo,SvU:()=>U,$mh:()=>$,rfi:()=>eE,FcF:()=>eO,rIH:()=>T,iMI:()=>S,R6R:()=>F,fRP:()=>eA});var n=r(1594),i=r(2449),a=r(6297),s=(r(3614),r(1179));r(9315);var o=r(6771),l=r(5633);let d=(0,n.XY)(e=>(0,i.yw)(e[0]),(e,t,r)=>{let n;return s.aE(t)?a.PpN(e,t):(n=Array.isArray(t)?l.Um(...t):t,a.Pxi(t=>a.qIB(r?.local?l.H7(n,l.j6(),t):l.LT(n,t),t=>a.PpN(e,t))))});var c=r(1587),u=r(3753),f=r(6481);(e,t,r)=>a.qIB(o.xn(t),t=>{let n=o.d3.defaultValue();return a.h_t(a.i4r(a.Mim(a.qIB(a.DYE(()=>a.PfK(e,o.d3,n)),t),e=>a.OH5(()=>{n=e})),{disableYield:!0}),e=>i.$L(e)?a.PyW(e.value):r(e,0===n.attempt?c.none():c.some(n)))});let p=(0,n.XY)(3,(e,t,r)=>a.qIB(o.xn(t),t=>{let n,i=o.d3.defaultValue(),s=a.h_t(a.DYE(()=>a.PfK(e,o.d3,i)),e=>(n=e,a.qIB(t(e),e=>(i=e,s))));return u.m8(s,e=>(0,f.s)(()=>r(n,e)))})),h=(0,n.XY)(2,(e,t)=>p(e,"function"==typeof t?t(n.D_):o.GM(t)?t:g(t),a.fJG)),m=o.le(o.i4),g=e=>{let t=e.schedule?o.le(e.schedule):m;return e.while&&(t=o.E6(t,({input:t})=>{let r=e.while(t);return i.yw(r)?r:a.PyW(r)})),e.until&&(t=o.E6(t,({input:t})=>{let r=e.until(t);return i.yw(r)?a.TjK(r,e=>!e):a.PyW(!r)})),void 0!==e.times&&(t=o.E6(t,({attempt:t})=>a.PyW(t<=e.times))),t},y=o.t5(1);var v=r(2275);let b=r(3332).Xq({_E:e=>e,_A:e=>e,_R:e=>e});({...i.In,"~effect/Request":b}),r(3909);var _=r(4600);i.$n;let x=i.yw,w=a.Q7R;a.jBG,a.TSs,a.tfT,a.i8i,a.kAe;let k=a.jJl;a.d5f;let S=a.iMI,I=a.ivC,$=a.$mh,E=a.PyW;a.lwU,a.nGE;let O=a.DYE,C=a.OH5,T=a.rIH;a.Vxk;let M=a.E2r,A=a.ZmZ;a.Do,a.JrD,a.uVU,a.oIE;let N=a.JkU,P=a.fJG;a.gOk;let R=a.ATB,j=a.pVV,D=a.F_Q,U=a.SvU;a.m9E,a.KN3;let F=i.R6;i.Hq;let B=a.yUA;a.sVm,a.pkL,a.bJ;let L=a.qIB;a.Bqz;let z=a.hgn,W=a.Mim,J=a.Ket,Y=a.uKv,X=a.NS5,q=a.TjK,G=a.as;a.Xx$,a.NLW,a.UUz,a.yU6,a.OYO;let V=a.h_t,H=a.KuX,K=a.loE;a.AXC,a.zt4,a.scW;let Q=a.Tyx;a.Fig,a.XWm;let Z=a.osR;a.U9Y,a.sJf,a.rNk;let ee=a.xm_;a.UcN;let et=a.QgK,er=a.sFT;a.k$L;let en=a.dGm;a.cA6,a.bKC,a.nAi,a.u4Y;let ei=h;a._Sg;let ea=a.XeO;a.GrF,a.$$g,a.DM4,a.Dd;let es=a.wRz;a.D52;let eo=a.mgX;a.cbG;let el=a.yy4;a.ayu,a.Vdx,a.FfP,a.O4F;let ed=a.KT6;a.pbD,a.x1Q,a.E8K,a.Pm0,a.VtY,a.W$I,a.ahH,a.z7s;let ec=a.YWq;a.G$Q,a.D$$,a.NZb,a.wR5;let eu=a.khu,ef=a.tvg;a.N6O,a.oJd,a._OA,a.sxi;let ep=d,eh=a.PpN;a.oao,a.euC;let em=a.Nav;a.r_d,a.bUZ,a.L_I;let eg=a.PfK;a.c7E;let ey=a.z8E,ev=a.P1j,eb=a.Pxi,e_=a.Q56;a.N24;let ex=a.jGc,ew=a.U9h,ek=a.yeE,eS=a.S5A;a.BeE,a.iKM,a.r7h;let eI=a.cfM;a.fGe,a.uRq,a.PO3,a.Rgn,a.CJw;let e$=a.GaK;a.Inz,a.nAr;let eE=a.rfi,eO=a.FcF;a.eMl,a.dsN;let eC=a.i4r;a.aAq,a.Xrv,a.kJM,a._o1,a.nDN,a.MaT;let eT=a.Muk;a.ww9;let eM=a._32;a.Wj8,a.Fu6,a.WbR,a.A_r,a.Z98,a.Rd$,a.gvr;let eA=a.fRP;a.zr8,a.hq,a.zhn;let eN=a.ar0,eP=a.x6Z;a.yxg,a.PCg,a.pEE,a.ABT;let eR=a.MY7,ej=a.eJC;a.lSz,a.bPG,a.pR5,a.v2Q,a.NpQ,a.jqV,a.HZF,a.lE;let eD=a.lKS;a.rfH;let eU=a.D9k,eF=a.fn,eB=a.RKA;a.lIX;let eL=a.lIX("Error"),ez=(0,n.XY)(e=>x(e[0]),(e,...t)=>a.bUZ(e,_.iL,e=>{let r=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||v.x(r,t[0],t[1]),r}));a.gsV;let eW=(e,t,r)=>(...n)=>M(i=>{try{e(...n,(e,r)=>{e?i(P(t?t(e,n):e)):i(E(r))})}catch(e){i(r?P(r(e,n)):D(e))}}),eJ=a.jkJ,eY=a.Z9x,eX=a.q7Y,eq=a.Ab9;a.UVN;let eG=a.vCS},3811(e,t,r){var n=r(2449);r.d(t,{},{bp:e=>(0,n.yj)({op:e.label,[n._3]:e.evaluate})})},3332(e,t,r){var n=r(5033),i=r(5844),a=r(4233);let s="~effect/Equal";function o(){return 1==arguments.length?e=>l(e,arguments[0]):l(arguments[0],arguments[1])}function l(e,t){if(e===t)return!0;if(null==e||null==t)return!1;let r=typeof e;return r===typeof t&&("number"===r&&e!=e&&t!=t||!("object"!==r&&"function"!==r||i.J3.has(e)||i.J3.has(t))&&function(e,t){let r=c.length;for(let n=r;n-- >0;)if(c[n]===e&&u[n]===t)return!0;if(r)return d(e,t);let n=f.get(e);n||f.set(e,n=new WeakMap);let i=n.get(t);return void 0===i&&n.set(t,i=d(e,t)),i}(e,t))}function d(e,t){c.push(e),u.push(t);try{return function(e,t){if(n.tW(e)!==n.tW(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let r=e.getTime(),n=t.getTime();return r===n||Number.isNaN(r)&&Number.isNaN(n)}if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let r=y(e);if(r!==y(t)||"function"==typeof e&&!r)return!1;if(r)return e[s](t);if(Array.isArray(e))return!!Array.isArray(t)&&e.length===t.length&&function(e,t){for(let r=0;r<e.length;r++)if(!l(e[r],t[r]))return!1;return!0}(e,t);if(ArrayBuffer.isView(e)){let r=e instanceof DataView;return!!ArrayBuffer.isView(t)&&e.byteLength===t.byteLength&&r===t instanceof DataView&&(r?p((0,i.j)(e),(0,i.j)(t)):p(e,t))}if(e instanceof Map)return t instanceof Map&&e.size===t.size&&h(e,t,m,g);else if(e instanceof Set)return t instanceof Set&&e.size===t.size&&h(e,t,n.tW,l);var a=e,o=t;let d=(0,i.Xp)(a),c=(0,i.Xp)(o);if(d.size!==c.size)return!1;for(let e of d)if(!c.has(e)||!l(a[e],o[e]))return!1;return!0}(e,t)}finally{c.pop(),u.pop()}}let c=[],u=[],f=new WeakMap;function p(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function h(e,t,r,n){let i=new Map;for(let e of t){let t=r(e),n=i.get(t);n?n.push(e):i.set(t,[e])}e:for(let t of e){let e=i.get(r(t));if(e){for(let r=0;r<e.length;r++)if(n(t,e[r])){e[r]=e[e.length-1],e.pop();continue e}}return!1}return!0}let m=e=>n.tW(e[0]),g=(e,t)=>l(e[0],t[0])&&l(e[1],t[1]),y=e=>(0,a.i5)(e,s);r.d(t,{aI:()=>o},{HR:s,Xq:e=>(i.J3.add(e),e),jI:()=>o})},7876(e,t,r){let n=e=>(t,r)=>t===r||e(t,r),i=(e,t)=>e===t,a=n((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t));function s(e){return n((t,r)=>{if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(!e[n](t[n],r[n]))return!1;return!0})}function o(e){return n((t,r)=>{if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(!e(t[n],r[n]))return!1;return!0})}function l(e){let t=Reflect.ownKeys(e);return n((r,n)=>{for(let i of t)if(!e[i](r[i],n[i]))return!1;return!0})}r.d(t,{O3:()=>o,_k:()=>l,rd:()=>s},{L8:n,Qw:i,YZ:()=>i,wN:a})},6526(e,t,r){var n=r(2449),i=r(6297);n.IH,n.b9;let a=n.xt,s=n.cb,o=n.Rk;n.V2,i._sz;let l=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,r.d(t,{},{AT:s,N6:c,Py:a,fJ:o,oJ:d,rI:l})},1958(e,t,r){var n=r(4233),i=r(1279);function a(e,t){let r=t?.space??0,a=new WeakSet,l=r?"number"==typeof r?" ".repeat(r):r:"",u=(e,t)=>{let r=e?.constructor;return r&&r!==Object.prototype.constructor&&r.name?`${r.name}(${t})`:t};return function e(r,f=0){try{return function(r,f=0){if("string"==typeof r)return JSON.stringify(r);if("number"==typeof r||null==r||"boolean"==typeof r||"symbol"==typeof r)return String(r);if("bigint"==typeof r)return String(r)+"n";if("object"==typeof r||"function"==typeof r){let p;if(a.has(r))return s;if(a.add(r),i.uC in r)p=e((0,i.f6)(r),f);else if(Array.isArray(r)){let t,n;p=!l||r.length<=1?`[${r.map(t=>e(t,f)).join(",")}]`:`[
230
+ `)}},d=new Proxy(globalThis.console,{get(e,t,r){if("log"===t)return(...t)=>{(1!==t.length||""!==t[0])&&e.log(...t)};let n=Reflect.get(e,t,r);return"function"==typeof n?n.bind(e):n}}),uy(pZ,{version:"0.6.3"})(e).pipe(B.sFT(e=>eh.i5(e,oi)&&"ShowHelp"!==e._tag?or(l.formatErrors([e])):B.rIH),B.PfK(dr,{builtIns:[l8,l9,l7]}),B.PfK(o3,l),B.PfK(oe,d))).pipe(B.khu({onFailure:e=>B.JkU(function*(){let t,r=ee.getOrUndefined(F.L$(e));if(r instanceof f8)return r.exitCode;if(r instanceof nA)return 7;let n=function(e){if(eh.i5(e,oi))return"ShowHelp"===e._tag?2*(e.errors.length>0):2}(r);if(void 0!==n)return n;let i=yield*f6;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?n6({ok:!1,command:"sketchi",error:t}):f7(t))).pipe(B.MfU(()=>B.rIH)),1}),onSuccess:()=>B.PyW(0)}))}),p1=G.Um(nM.Tx,(0,nM.rR)({createId:e=>`${e}_offline_cli`})),p2=G.Gt(n7,p1),p5=G.Gt(ip,p1),p3=G.Um(is,aa),p6=G.Gt(ag,p3),p8=G.Gt(aB,G.Um(p6,aj)),p9=G.Gt(py,pf),p4=G.Um(is,aa,p2,p5,p6,p8,aj,p9,pm,ig.pipe(G.Gt(is)),f4,s7),p7=G.S5(p4,nT);q(p0(process.argv.slice(2)).pipe(B.Mim(e=>B.OH5(()=>{process.exitCode=e})),B.Gte(p7)),{disableErrorReporting:!0})},1688(e,t,r){var n=r(2718);let i=n.xCb(["invalid_render_artifact","render_limit_exceeded","unsupported_render_glyph","rasterization_failed"]),a=n.xCb(["artifact","geometry","font","rasterization"]);class s extends n.rNF()("HeadlessPngRenderError",{cause:n.kld(),code:i,stage:a,message:n.QfV,details:n.O31(n.QfV)}){}r.d(t,{FG:()=>s})},5030(e,t,r){function n(e,t,r,n){return{code:e,message:t,...void 0===r?{}:{observed:r},...void 0===n?{}:{limit:n}}}function i(e,t=0){let r=1/0,a=1/0,s=-1/0,o=-1/0;for(let t of e){var l;if(!("object"==typeof(l=t)&&null!==l&&!Array.isArray(l)&&"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 n("invalid_geometry","element geometry is invalid");let e=Math.abs(t.width),i=Math.abs(t.height);if(e>8192||i>8192)return n("element_dimension",`element dimension exceeds ${String(8192)}`,Math.max(e,i),8192);let d=Math.hypot(e,i)/2,c=t.x+t.width/2,u=t.y+t.height/2;r=Math.min(r,c-d),a=Math.min(a,u-d),s=Math.max(s,c+d),o=Math.max(o,u+d)}if(0===e.length)return;let d=s-r,c=o-a;if(d>8192||c>8192)return n("canvas_dimension",`canvas dimension exceeds ${String(8192)}`,Math.max(d,c),8192);let u=d*c;if(u>6291456)return n("canvas_area",`canvas area exceeds ${String(6291456)}`,u,6291456);let f=(d+40)*1*((c+40+t)*1);if(f>0x1800000)return n("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,f,0x1800000)}function a(e,t=0){return i(e,t)?.message}function s(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return n("invalid_geometry","rendered SVG dimensions are invalid");let r=Math.min(2,16384/e,16384/t,Math.sqrt(0x1800000/(e*t)));if(r<1){let r=e*t;return r>0x1800000?n("output_pixels",`PNG output exceeds ${String(0x1800000)} pixels at minimum scale`,r,0x1800000):n("output_dimension","rendered SVG dimension exceeds the PNG limit at minimum scale",Math.max(e,t),16384)}return Math.max(1,Math.floor(1e3*r)/1e3)}r.d(t,{Gd:()=>a,Ts:()=>i,Yu:()=>s},{Z4:6291456,ce:0x1800000})},6982(e){e.exports=t("crypto")},7598(e){e.exports=t("node:crypto")},76(e,t,r){let n=r(9095),i=process.env;function a(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:n.map(function(e){return e.constant})}),t.name=null,t.isPR=null,t.id=null,"false"!==i.CI&&n.forEach(function(e){let r=(Array.isArray(e.env)?e.env:[e.env]).every(function(e){return a(e)});t[e.constant]=r,r&&(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 a(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,r){e.exports=r(76).isCI},664(e,t,r){r.d(t,{CN:()=>p,BC:()=>g,Ie:()=>I,pb:()=>O,i8:()=>w,g9:()=>x,Uk:()=>k,Ts:()=>h,CZ:()=>y,ET:()=>v,HV:()=>b,T9:()=>M,Tj:()=>E,YW:()=>m,of:()=>$,jB:()=>C,TS:()=>T,di:()=>S});var n=r(7876),i=r(1594);let a=e=>e.length>0;var s=r(9771),o=r(592),l=r(1587),d=r(2860),c=r(915),u=r(9315);let f=globalThis.Array,p=e=>new f(s.S(e)),h=e=>f.isArray(e)?e:f.from(e);c.Wo,l.toArray;let m=(0,i.XY)(2,(e,{onEmpty:t,onNonEmpty:r})=>v(e)?r(e):t()),g=(0,i.XY)(2,(e,t)=>[...e,t]);f.isArray;let y=a,v=a,b=e=>v(e)?l.some(_(e)):l.none(),_=e=>e[e.length-1],x=(0,i.XY)(2,(e,t)=>{let r=0;for(let n of e){if(t(n,r))return l.some(r);r++}return l.none()}),w=o.i8,k=(0,i.XY)(2,(e,t)=>{let r=h(e);for(let e=r.length-1;e>=0;e--){let n=r[e],i=t(n,e);if("boolean"==typeof i){if(i)return l.some(n)}else if(l.isSome(i))return i}return l.none()}),S=(0,i.XY)(2,(e,t)=>{let r=f.from(e);return r.sort(t),r}),I=()=>[],$=e=>[e],E=(0,i.XY)(2,(e,t)=>e.map(t)),O=(0,i.XY)(2,(e,t)=>{let r=h(e),n=[];for(let e=0;e<r.length;e++)t(r[e],e)&&n.push(r[e]);return n}),C=(0,i.XY)(2,(e,t)=>{let r=[],n=[],i=0;for(let a of e){let e=t(a,i++);u.oJ(e)?r.push(e.success):n.push(e.failure)}return[r,n]}),T=(0,i.XY)(3,(e,t,r)=>h(e).reduce((e,t,n)=>r(e,t,n),t));d.O3;let M=n.O3},5053(e,t,r){var n=r(9519),i=r(7876),a=r(1594),s=r(1587),o=r(2860),l=r(4233),d=r(636);let c=globalThis.BigInt,u=c(0);l.sI;let f=(0,a.XY)(2,(e,t)=>e+t),p=o.Qw,h=i.Qw,m=o.hl(p),g=o.bi(p),y=o.yJ(p),v=o.OW(p),b=o.Bt(p),_=o.qE(p),x=o.jk(p),w=o.T9(p),k=d.L((e,t)=>e+t,u),S=n.T9(p),I=n.jk(p);r.d(t,{},{K0:I,OW:v,Ro:e=>e>c(Number.MAX_SAFE_INTEGER)||e<c(Number.MIN_SAFE_INTEGER)?s.none():s.some(Number(e)),T9:w,Tq:b,aD:k,bi:g,cz:f,hl:m,jk:x,pH:p,qE:_,rs:h,sO:S,yJ:y})},3265(e,t,r){var n=r(5053),i=r(1587);let a=BigInt(0),s=BigInt(1),o=BigInt(1e3),l=BigInt(1024),d=[{symbol:"B",factor:s,names:["B","byte","bytes"]},{symbol:"kB",factor:o,names:["kB","kilobyte","kilobytes"]},{symbol:"MB",factor:o**BigInt(2),names:["MB","megabyte","megabytes"]},{symbol:"GB",factor:o**BigInt(3),names:["GB","gigabyte","gigabytes"]},{symbol:"TB",factor:o**BigInt(4),names:["TB","terabyte","terabytes"]},{symbol:"PB",factor:o**BigInt(5),names:["PB","petabyte","petabytes"]},{symbol:"EB",factor:o**BigInt(6),names:["EB","exabyte","exabytes"]},{symbol:"ZB",factor:o**BigInt(7),names:["ZB","zettabyte","zettabytes"]},{symbol:"YB",factor:o**BigInt(8),names:["YB","yottabyte","yottabytes"]},{symbol:"RB",factor:o**BigInt(9),names:["RB","ronnabyte","ronnabytes"]},{symbol:"QB",factor:o**BigInt(10),names:["QB","quettabyte","quettabytes"]}],c=[d[0],{symbol:"KiB",factor:l,names:["KiB","kibibyte","kibibytes"]},{symbol:"MiB",factor:l**BigInt(2),names:["MiB","mebibyte","mebibytes"]},{symbol:"GiB",factor:l**BigInt(3),names:["GiB","gibibyte","gibibytes"]},{symbol:"TiB",factor:l**BigInt(4),names:["TiB","tebibyte","tebibytes"]},{symbol:"PiB",factor:l**BigInt(5),names:["PiB","pebibyte","pebibytes"]},{symbol:"EiB",factor:l**BigInt(6),names:["EiB","exbibyte","exbibytes"]},{symbol:"ZiB",factor:l**BigInt(7),names:["ZiB","zebibyte","zebibytes"]},{symbol:"YiB",factor:l**BigInt(8),names:["YiB","yobibyte","yobibytes"]}],u=new Map([...d,...c.slice(1)].flatMap(e=>e.names.map(t=>[t,e]))),f=e=>{throw Error(`Invalid ByteSize: ${e}`)},p=e=>!Number.isSafeInteger(e)||e<0?f(`expected a non-negative safe integer, received ${e}`):BigInt(e),h=e=>{let t=/^\s*(\d+)(?:\.(\d+))?\s*([A-Za-z]+)\s*$/.exec(e);if(null===t)return f(`unsupported syntax ${JSON.stringify(e)}`);let r=u.get(t[3]);if(void 0===r)return f(`unsupported unit ${JSON.stringify(t[3])}`);let n=t[2]??"",i=BigInt(10)**BigInt(n.length),s=BigInt(t[1]+n)*r.factor;return s%i!==a?f(`${JSON.stringify(e)} does not represent an integral number of bytes`):s/i},m=i.liftThrowable(h),g=e=>{switch(typeof e){case"bigint":if(e<a)return f(`expected a non-negative bigint, received ${e}`);return e;case"number":return p(e);case"string":return h(e)}return f(`unsupported input ${e}`)},y=i.liftThrowable(g),v=n.Ro;n.pH,n.rs,n.Tq,n.jk,n.T9,n.qE,n.hl,n.bi,n.yJ,n.OW,n.cz,n.aD,n.sO,n.K0,r.d(t,{},{Dg:e=>e,Ro:v,bN:g,ee:e=>"bigint"==typeof e?g(e):p(e),lX:y,sH:m,yp:e=>"bigint"==typeof e&&e>=a})},719(e,t,r){var n=r(2449),i=r(6297);n.PX,n.B4,n.Aj,n.Wg;let a=n.lC;n.Xb,n.ik;let s=n.b5;n.DH;let o=n.OE,l=n.Iu;i.nIy,i.ORc;let d=i.nn5,c=i.O$X;n.h2;let u=i.ReC;i.myX,i.QE5,i.khU;let f=i.L$u;i.gpn,i.k7S,i.BbX;let p=i.prj;i.tU5,i.h74,i.Bou,i.RJ6;let h=i.GyP;n.PW,n.qB,n.Xm;let m=n.$L;n.q_;let g=n.RS,y=n.Vw;i.DQo,i.c8t,i.MUS,i.t8c,i._y;let v=i.qwd;i.ASO,i.F7W,i.Aub,i.cOF,i.Rft,i.RD4,i.Kkt,i.PnV;let b=i.Bk6;n.Eh,i.tQ6,i.On5,r.d(t,{},{$L:m,Bk:b,F_:l,L$:f,RS:g,Tj:c,Vw:y,fJ:o,iw:u,j9:h,kO:s,lC:a,nn:d,pr:p,qw:v})},4238(e,t,r){var n=r(6297);n.a1U,n.RKA;let i=n.Rud;n.s0X,n.T13,r.d(t,{},{Ru:i})},9519(e,t,r){function n(e){return{combine:e}}function i(e){return n((t,r)=>-1===e(t,r)?t:r)}function a(e){return n((t,r)=>1===e(t,r)?t:r)}r.d(t,{L8:()=>n,T9:()=>a,jk:()=>i})},1179(e,t,r){var n=r(3811),i=r(3332),a=r(1594),s=r(5033),o=r(2449),l=r(1587),d=r(4233);let c="~effect/Context/Service",u=function(){let e=function(){};Object.setPrototypeOf(e,f);let t=(t,r)=>(e.key=t,r?.defaultValue&&(e[h]=h,e.defaultValue=r.defaultValue),r?.make&&(e.make=r.make),r?.fiberCached&&p.add(t),e);return arguments.length>0?t(arguments[0],arguments[1]):t},f={[c]:c,...n.bp({label:"Service",evaluate(e){return(0,o.xt)(A(e.context,this))}}),toJSON(){return{_id:"Service",key:this.key}},of:e=>e,context(e){return $(this,e)},use(e){return(0,o.R6)(t=>e(A(t.context,this)))},useSync(e){return(0,o.R6)(t=>(0,o.xt)(e(A(t.context,this))))}},p=new Set,h="~effect/Context/Reference",m="~effect/Context",g=(e,t,r,n)=>{let i=Object.create(w);return i.cacheRoot=e??i,i.base=t,i.overlay=r,i.depth=n,i._flat=void 0,i.baseHits=0,i},y=(e,t)=>{t&&(y(e,t.parent),e.set(t.key,t.value))},v=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return y(t,e.overlay),e._flat=t},b=Symbol(),_=(e,t)=>{for(let r=e.overlay;r;r=r.parent)if(r.key===t)return r.value;let r=e.base.get(t);return void 0!==r||e.base.has(t)?(e.overlay&&++e.baseHits>=e.base.size&&e.baseHits>=8&&(e.base=v(e),e.overlay=void 0,e.depth=0),r):b},x=e=>g(void 0,e,void 0,0),w={get mapUnsafe(){return v(this)},...o.fU,[m]:{_Services:e=>e},toJSON(){return{_id:"Context",services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[i.HR](e){if(!k(e))return!1;let t=this.mapUnsafe,r=e.mapUnsafe;if(t.size!==r.size)return!1;for(let[e,n]of t)if(!r.has(e)||!i.aI(n,r.get(e)))return!1;return!0},[s.HR](){return s.ai(this.mapUnsafe.size)}},k=e=>(0,d.i5)(e,m),S=e=>!!e[h],I=x(new Map),$=(e,t)=>x(new Map([[e.key,t]])),E=(0,a.XY)(3,(e,t,r)=>O(e,t.key,r)),O=(e,t,r)=>{let n=p.has(t)?void 0:e.cacheRoot;if(e.depth>=8){let i=new Map(e.mapUnsafe);return i.set(t,r),g(n,i,void 0,0)}return g(n,e.base,{key:t,value:r,parent:e.overlay},e.depth+1)},C=(0,a.XY)(2,(e,t)=>T(e,t.key)),T=(e,t)=>{let r=_(e,t);return r===b?void 0:r},M=(0,a.XY)(2,(e,t)=>{let r=_(e,t.key);if(r===b){if(S(t))return P(t);throw R(t)}return r}),A=M,N="~effect/Context/defaultValue",P=e=>N in e?e[N]:e[N]=e.defaultValue(),R=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},j=(0,a.XY)(2,(e,t)=>{let r=_(e,t.key);return r!==b?l.some(r):S(t)?l.some(P(t)):l.none()}),D=(0,a.XY)(2,(e,t)=>{let r;return 0===e.mapUnsafe.size?t:0===t.mapUnsafe.size?e:((e=>t.mapUnsafe.forEach((t,r)=>e.set(r,t)))(r=new Map(e.mapUnsafe)),x(r))});r.d(t,{},{Ie:()=>I,Jt:A,L8:$,LZ:x,Or:u,Pf:(e,t)=>e.cacheRoot===t.cacheRoot,Ub:T,Um:(...e)=>{let t=new Map;for(let r=0;r<e.length;r++)e[r].mapUnsafe.forEach((e,r)=>{t.set(r,e)});return x(t)},WQ:E,Y6:C,aE:k,fp:M,h1:D,kl:u,om:j})},4942(e,t,r){var n=r(2449),i=r(2275),a=r(1554),s=r(4233);let o=class extends a.Xs{constructor(e){super(),e&&i.z(this,e)}};function l(){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=n.$D,c=n.rN;r.d(t,{},{$D:d,Ij:()=>new Proxy({},{get:(e,t,r)=>"$is"===t?s.$J:"$match"===t?l:e=>({...e,_tag:t})}),Xs:o,rN:c})},9237(e,t,r){var n=r(1594),i=r(6297),a=r(1554);let s={"~effect/Deferred":{_A:n.D_,_E:n.D_},pipe(){return(0,a.tT)(this,arguments)}},o=function(){this.resumes=void 0,this.effect=void 0};o.prototype=s;let l=e=>void 0!==e.effect;r.d(t,{},{$L:e=>i.OH5(()=>l(e)),$w:(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let r=e.resumes;e.resumes=void 0;for(let e=0;e<r.length;e++)r[e](t)}return!0},LZ:()=>new o,NJ:l,Tx:e=>i.E2r(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),i.OH5(()=>{let r=e.resumes;if(void 0===r)return;let n=r.indexOf(t);n>=0&&r.splice(n,1)})))})},3614(e,t,r){var n=r(3332),i=r(1594),a=r(5033),s=r(3952),o=r(2860),l=r(1554),d=r(4233);let c="~effect/Duration",u=BigInt(0),f=BigInt(1),p=BigInt(2),h=BigInt(10),m=BigInt(24),g=BigInt(60),y=BigInt(1e3),v=BigInt(1e6),b=e=>BigInt(e<0?Math.ceil(e-.5):Math.floor(e+.5)),_=(e,t)=>{let r=e.indexOf(".");if(-1===r)return BigInt(e)*t;let n="-"===e[0],i=e.slice(r+1),a=h**BigInt(i.length),s=(BigInt(e.slice(+!!n,r))*a+BigInt(i))*t,o=s/a+(s%a*p>=a?f:u);return n?-o:o},x=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,w=e=>{switch(typeof e){case"number":return P(e);case"bigint":return N(e);case"string":{if("Infinity"===e)return M;if("-Infinity"===e)return A;let t=x.exec(e);if(!t)break;let[r,n,i]=t;if("nano"===i||"nanos"===i)return N(_(n,f));if("micro"===i||"micros"===i)return N(_(n,y));let a=Number(n);switch(i){case"milli":case"millis":return P(a);case"second":case"seconds":return R(a);case"minute":case"minutes":return j(a);case"hour":case"hours":return D(a);case"day":case"days":return U(a);case"week":case"weeks":return F(a)}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 k(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return T;if(-1/0===e[0]||-1/0===e[1])return A;if(1/0===e[0]||1/0===e[1])return M;return O(b(1e9*e[0]+e[1]))}let t=0;if(e.weeks&&(t+=6048e5*e.weeks),e.days&&(t+=864e5*e.days),e.hours&&(t+=36e5*e.hours),e.minutes&&(t+=6e4*e.minutes),e.seconds&&(t+=1e3*e.seconds),e.milliseconds&&(t+=e.milliseconds),!e.microseconds&&!e.nanoseconds)return O(t);return O(b(1e6*t+(e.microseconds??0)*1e3+(e.nanoseconds??0)))}}return k(e)},k=e=>{throw Error(`Invalid Input: ${e}`)},S={_tag:"Millis",millis:0},I={_tag:"Infinity"},$={_tag:"NegativeInfinity"},E={[c]:c,[a.HR](){switch(this.value._tag){case"Millis":{let e=1e6*this.value.millis;return Number.isFinite(e)?a.tW(b(e)):a.ai(this.value.millis)}case"Nanos":return a.tW(this.value.nanos);default:return a.QK(this.value)}},[n.HR](e){return C(e)&&Y(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"}}},[s.FX](){return this.toJSON()},pipe(){return(0,l.tT)(this,arguments)}},O=e=>{let t=Object.create(E);return"number"==typeof e?isNaN(e)||0===e||Object.is(e,-0)?t.value=S:Number.isFinite(e)?Number.isInteger(e)?t.value={_tag:"Millis",millis:e}:t.value={_tag:"Nanos",nanos:b(1e6*e)}:t.value=e>0?I:$:e===u?t.value=S:t.value={_tag:"Nanos",nanos:e},t},C=e=>(0,d.i5)(e,c),T=O(0),M=O(1/0),A=O(-1/0),N=e=>O(e),P=e=>O(e),R=e=>O(1e3*e),j=e=>O(6e4*e),D=e=>O(36e5*e),U=e=>O(864e5*e),F=e=>O(6048e5*e),B=e=>{let t=w(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 b(1e6*t.value.millis)}},L=(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)()}}),z=(0,i.XY)(3,(e,t,r)=>"Infinity"===e.value._tag||"NegativeInfinity"===e.value._tag||"Infinity"===t.value._tag||"NegativeInfinity"===t.value._tag?r.onInfinity(e,t):"Millis"===e.value._tag?"Millis"===t.value._tag?r.onMillis(e.value.millis,t.value.millis):r.onNanos(B(e),t.value.nanos):r.onNanos(e.value.nanos,B(t))),W=o.L8((e,t)=>z(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})),J=o.bi(W),Y=(0,i.XY)(2,(e,t)=>z(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag})),X=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===u;case"Infinity":case"NegativeInfinity":return!1}})(e))return"0";if((e=>{switch(e.value._tag){case"Millis":return e.value.millis<0;case"Nanos":return e.value.nanos<u;case"NegativeInfinity":return!0;case"Infinity":return!1}})(e))return"-"+X((e=>{switch(e.value._tag){case"Infinity":case"NegativeInfinity":return M;case"Millis":return e.value.millis<0?O(-e.value.millis):e;case"Nanos":return e.value.nanos<u?O(-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=B(e),r=t<u,n=r?-t:t,i=n/v,a=i/y,s=a/g,o=s/g,l=r?-1:1;return{days:l*Number(o/m),hours:l*Number(o%m),minutes:l*Number(s%g),seconds:l*Number(a%g),millis:l*Number(i%y),nanos:l*Number(n%v)}})(e),r=[];return 0!==t.days&&r.push(`${t.days}d`),0!==t.hours&&r.push(`${t.hours}h`),0!==t.minutes&&r.push(`${t.minutes}m`),0!==t.seconds&&r.push(`${t.seconds}s`),0!==t.millis&&r.push(`${t.millis}ms`),0!==t.nanos&&r.push(`${t.nanos}ns`),r.join(" ")};r.d(t,{},{GP:X,MI:e=>"Infinity"!==e.value._tag&&"NegativeInfinity"!==e.value._tag,Tn:M,YA:R,bN:w,bi:J,cF:N,fP:e=>L(w(e),{onMillis:e=>e/1e3,onNanos:e=>Number(e)/1e9,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),kE:e=>L(w(e),{onMillis:i.D_,onNanos:e=>Number(e)/1e6,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),n$:C,ne:P,qv:A,v_:T})},2842(e,t,r){r.d(t,{Q56:()=>e_,jGc:()=>ex,U9h:()=>ew,Q7R:()=>w,hgn:()=>z,swY:()=>ez,Muk:()=>eT,as:()=>G,E2r:()=>M,MfU:()=>V,Tyx:()=>Q,osR:()=>Z,KuX:()=>H,loE:()=>K,RKA:()=>eB,_32:()=>eM,F_Q:()=>D,_r7:()=>eW,yeE:()=>ek,NS5:()=>X,fJG:()=>P,ATB:()=>R,pVV:()=>j,qIB:()=>L,Ab9:()=>eq,fn:()=>eF,D9k:()=>eU,vCS:()=>eG,jJl:()=>k,i4r:()=>eC,ar0:()=>eN,x6Z:()=>eP,yUA:()=>B,JkU:()=>N,XeO:()=>ea,GaK:()=>e$,yw5:()=>x,vVN:()=>eL,TjK:()=>q,q7Y:()=>eX,jkJ:()=>eJ,xm_:()=>ee,Z9x:()=>eY,YWq:()=>ec,khu:()=>eu,tvg:()=>ef,ZmZ:()=>A,S5A:()=>eS,cfM:()=>eI,uKv:()=>Y,QgK:()=>et,ivC:()=>I,Gte:()=>ep,PpN:()=>eh,PfK:()=>eg,KT6:()=>ed,Ket:()=>J,L5P:()=>ei,MY7:()=>eR,eJC:()=>ej,lKS:()=>eD,z8E:()=>ey,P1j:()=>ev,Pxi:()=>eb,Nav:()=>em,yy4:()=>el,PyW:()=>E,DYE:()=>O,OH5:()=>C,Mim:()=>W,dGm:()=>en,sFT:()=>er,wRz:()=>es,mgX:()=>eo,SvU:()=>U,$mh:()=>$,rfi:()=>eE,FcF:()=>eO,rIH:()=>T,iMI:()=>S,R6R:()=>F,fRP:()=>eA});var n=r(1594),i=r(2449),a=r(6297),s=(r(3614),r(1179));r(9315);var o=r(6771),l=r(5633);let d=(0,n.XY)(e=>(0,i.yw)(e[0]),(e,t,r)=>{let n;return s.aE(t)?a.PpN(e,t):(n=Array.isArray(t)?l.Um(...t):t,a.Pxi(t=>a.qIB(r?.local?l.H7(n,l.j6(),t):l.LT(n,t),t=>a.PpN(e,t))))});var c=r(1587),u=r(3753),f=r(6481);(e,t,r)=>a.qIB(o.xn(t),t=>{let n=o.d3.defaultValue();return a.h_t(a.i4r(a.Mim(a.qIB(a.DYE(()=>a.PfK(e,o.d3,n)),t),e=>a.OH5(()=>{n=e})),{disableYield:!0}),e=>i.$L(e)?a.PyW(e.value):r(e,0===n.attempt?c.none():c.some(n)))});let p=(0,n.XY)(3,(e,t,r)=>a.qIB(o.xn(t),t=>{let n,i=o.d3.defaultValue(),s=a.h_t(a.DYE(()=>a.PfK(e,o.d3,i)),e=>(n=e,a.qIB(t(e),e=>(i=e,s))));return u.m8(s,e=>(0,f.s)(()=>r(n,e)))})),h=(0,n.XY)(2,(e,t)=>p(e,"function"==typeof t?t(n.D_):o.GM(t)?t:g(t),a.fJG)),m=o.le(o.i4),g=e=>{let t=e.schedule?o.le(e.schedule):m;return e.while&&(t=o.E6(t,({input:t})=>{let r=e.while(t);return i.yw(r)?r:a.PyW(r)})),e.until&&(t=o.E6(t,({input:t})=>{let r=e.until(t);return i.yw(r)?a.TjK(r,e=>!e):a.PyW(!r)})),void 0!==e.times&&(t=o.E6(t,({attempt:t})=>a.PyW(t<=e.times))),t},y=o.t5(1);var v=r(2275);let b=r(3332).Xq({_E:e=>e,_A:e=>e,_R:e=>e});({...i.In,"~effect/Request":b}),r(3909);var _=r(4600);i.$n;let x=i.yw,w=a.Q7R;a.jBG,a.TSs,a.tfT,a.i8i,a.kAe;let k=a.jJl;a.d5f;let S=a.iMI,I=a.ivC,$=a.$mh,E=a.PyW;a.lwU,a.nGE;let O=a.DYE,C=a.OH5,T=a.rIH;a.Vxk;let M=a.E2r,A=a.ZmZ;a.Do,a.JrD,a.uVU,a.oIE;let N=a.JkU,P=a.fJG;a.gOk;let R=a.ATB,j=a.pVV,D=a.F_Q,U=a.SvU;a.m9E,a.KN3;let F=i.R6;i.Hq;let B=a.yUA;a.sVm,a.pkL,a.bJ;let L=a.qIB;a.Bqz;let z=a.hgn,W=a.Mim,J=a.Ket,Y=a.uKv,X=a.NS5,q=a.TjK,G=a.as;a.Xx$,a.NLW,a.UUz,a.yU6,a.OYO;let V=a.h_t,H=a.KuX,K=a.loE;a.AXC,a.zt4,a.scW;let Q=a.Tyx;a.Fig,a.XWm;let Z=a.osR;a.U9Y,a.sJf,a.rNk;let ee=a.xm_;a.UcN;let et=a.QgK,er=a.sFT;a.k$L;let en=a.dGm;a.cA6,a.bKC,a.nAi,a.u4Y;let ei=h;a._Sg;let ea=a.XeO;a.GrF,a.$$g,a.DM4,a.Dd;let es=a.wRz;a.D52;let eo=a.mgX;a.cbG;let el=a.yy4;a.ayu,a.Vdx,a.FfP,a.O4F;let ed=a.KT6;a.pbD,a.x1Q,a.E8K,a.Pm0,a.VtY,a.W$I,a.ahH,a.z7s;let ec=a.YWq;a.G$Q,a.D$$,a.NZb,a.wR5;let eu=a.khu,ef=a.tvg;a.N6O,a.oJd,a._OA,a.sxi;let ep=d,eh=a.PpN;a.oao,a.euC;let em=a.Nav;a.r_d,a.bUZ,a.L_I;let eg=a.PfK;a.c7E;let ey=a.z8E,ev=a.P1j,eb=a.Pxi,e_=a.Q56;a.N24;let ex=a.jGc,ew=a.U9h,ek=a.yeE,eS=a.S5A;a.BeE,a.iKM,a.r7h;let eI=a.cfM;a.fGe,a.uRq,a.PO3,a.Rgn,a.CJw;let e$=a.GaK;a.Inz,a.nAr;let eE=a.rfi,eO=a.FcF;a.eMl,a.dsN;let eC=a.i4r;a.aAq,a.Xrv,a.kJM,a._o1,a.nDN,a.MaT;let eT=a.Muk;a.ww9;let eM=a._32;a.Wj8,a.Fu6,a.WbR,a.A_r,a.Z98,a.Rd$,a.gvr;let eA=a.fRP;a.zr8,a.hq,a.zhn;let eN=a.ar0,eP=a.x6Z;a.yxg,a.PCg,a.pEE,a.ABT;let eR=a.MY7,ej=a.eJC;a.lSz,a.bPG,a.pR5,a.v2Q,a.NpQ,a.jqV,a.HZF,a.lE;let eD=a.lKS;a.rfH;let eU=a.D9k,eF=a.fn,eB=a.RKA;a.lIX;let eL=a.lIX("Error"),ez=(0,n.XY)(e=>x(e[0]),(e,...t)=>a.bUZ(e,_.iL,e=>{let r=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||v.x(r,t[0],t[1]),r}));a.gsV;let eW=(e,t,r)=>(...n)=>M(i=>{try{e(...n,(e,r)=>{e?i(P(t?t(e,n):e)):i(E(r))})}catch(e){i(r?P(r(e,n)):D(e))}}),eJ=a.jkJ,eY=a.Z9x,eX=a.q7Y,eq=a.Ab9;a.UVN;let eG=a.vCS},3811(e,t,r){var n=r(2449);r.d(t,{},{bp:e=>(0,n.yj)({op:e.label,[n._3]:e.evaluate})})},3332(e,t,r){var n=r(5033),i=r(5844),a=r(4233);let s="~effect/Equal";function o(){return 1==arguments.length?e=>l(e,arguments[0]):l(arguments[0],arguments[1])}function l(e,t){if(e===t)return!0;if(null==e||null==t)return!1;let r=typeof e;return r===typeof t&&("number"===r&&e!=e&&t!=t||!("object"!==r&&"function"!==r||i.J3.has(e)||i.J3.has(t))&&function(e,t){let r=c.length;for(let n=r;n-- >0;)if(c[n]===e&&u[n]===t)return!0;if(r)return d(e,t);let n=f.get(e);n||f.set(e,n=new WeakMap);let i=n.get(t);return void 0===i&&n.set(t,i=d(e,t)),i}(e,t))}function d(e,t){c.push(e),u.push(t);try{return function(e,t){if(n.tW(e)!==n.tW(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let r=e.getTime(),n=t.getTime();return r===n||Number.isNaN(r)&&Number.isNaN(n)}if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let r=y(e);if(r!==y(t)||"function"==typeof e&&!r)return!1;if(r)return e[s](t);if(Array.isArray(e))return!!Array.isArray(t)&&e.length===t.length&&function(e,t){for(let r=0;r<e.length;r++)if(!l(e[r],t[r]))return!1;return!0}(e,t);if(ArrayBuffer.isView(e)){let r=e instanceof DataView;return!!ArrayBuffer.isView(t)&&e.byteLength===t.byteLength&&r===t instanceof DataView&&(r?p((0,i.j)(e),(0,i.j)(t)):p(e,t))}if(e instanceof Map)return t instanceof Map&&e.size===t.size&&h(e,t,m,g);else if(e instanceof Set)return t instanceof Set&&e.size===t.size&&h(e,t,n.tW,l);var a=e,o=t;let d=(0,i.Xp)(a),c=(0,i.Xp)(o);if(d.size!==c.size)return!1;for(let e of d)if(!c.has(e)||!l(a[e],o[e]))return!1;return!0}(e,t)}finally{c.pop(),u.pop()}}let c=[],u=[],f=new WeakMap;function p(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function h(e,t,r,n){let i=new Map;for(let e of t){let t=r(e),n=i.get(t);n?n.push(e):i.set(t,[e])}e:for(let t of e){let e=i.get(r(t));if(e){for(let r=0;r<e.length;r++)if(n(t,e[r])){e[r]=e[e.length-1],e.pop();continue e}}return!1}return!0}let m=e=>n.tW(e[0]),g=(e,t)=>l(e[0],t[0])&&l(e[1],t[1]),y=e=>(0,a.i5)(e,s);r.d(t,{aI:()=>o},{HR:s,Xq:e=>(i.J3.add(e),e),jI:()=>o})},7876(e,t,r){let n=e=>(t,r)=>t===r||e(t,r),i=(e,t)=>e===t,a=n((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t));function s(e){return n((t,r)=>{if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(!e[n](t[n],r[n]))return!1;return!0})}function o(e){return n((t,r)=>{if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(!e(t[n],r[n]))return!1;return!0})}function l(e){let t=Reflect.ownKeys(e);return n((r,n)=>{for(let i of t)if(!e[i](r[i],n[i]))return!1;return!0})}r.d(t,{O3:()=>o,_k:()=>l,rd:()=>s},{L8:n,Qw:i,YZ:()=>i,wN:a})},6526(e,t,r){var n=r(2449),i=r(6297);n.IH,n.b9;let a=n.xt,s=n.cb,o=n.Rk;n.V2,i._sz;let l=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,r.d(t,{},{AT:s,N6:c,Py:a,fJ:o,oJ:d,rI:l})},1958(e,t,r){var n=r(4233),i=r(1279);function a(e,t){let r=t?.space??0,a=new WeakSet,l=r?"number"==typeof r?" ".repeat(r):r:"",u=(e,t)=>{let r=e?.constructor;return r&&r!==Object.prototype.constructor&&r.name?`${r.name}(${t})`:t};return function e(r,f=0){try{return function(r,f=0){if("string"==typeof r)return JSON.stringify(r);if("number"==typeof r||null==r||"boolean"==typeof r||"symbol"==typeof r)return String(r);if("bigint"==typeof r)return String(r)+"n";if("object"==typeof r||"function"==typeof r){let p;if(a.has(r))return s;if(a.add(r),i.uC in r)p=e((0,i.f6)(r),f);else if(Array.isArray(r)){let t,n;p=!l||r.length<=1?`[${r.map(t=>e(t,f)).join(",")}]`:`[
231
231
  ${t=f+1,l.repeat(t)}${r.map(t=>e(t,f+1)).join(",\n"+(n=f+1,l.repeat(n)))}
232
232
  ${l.repeat(f)}]`}else if(r instanceof Date)p=d(r);else if(!t?.ignoreToString&&n.i5(r,"toString")&&"function"==typeof r.toString&&r.toString!==Object.prototype.toString&&r.toString!==Array.prototype.toString){let t=function(e){try{let t=e.toString();return"string"==typeof t?t:String(t)}catch{return"[toString threw]"}}(r);p=r instanceof Error&&void 0!==r.cause?`${t} (cause: ${e(r.cause,f)})`:t}else if(Symbol.iterator in r)p=`${r.constructor.name}(${e(Array.from(r),f)})`;else{let t=(e=>{try{return Reflect.ownKeys(e)}catch{return["[ownKeys threw]"]}})(r);if(!l||t.length<=1){let n=`{${t.map(t=>`${o(t)}:${e(c(r,t),f)}`).join(",")}}`;p=u(r,n)}else{let n=`{
233
233
  ${t.map(t=>{let n;return`${n=f+1,l.repeat(n)}${o(t)}: ${e(c(r,t),f+1)}`}).join(",\n")}
@@ -239,4 +239,4 @@ ${ey(e.cause," ")}
239
239
  }`:e.stack,ey=(e,t)=>{let r=e.stack.split("\n"),n=`${t}[cause]: ${r[0]}`;for(let e=1,i=r.length;e<i;e++)n+=`
240
240
  ${t}${r[e]}`;return e.cause&&(n+=` {
241
241
  ${ey(e.cause,`${t} `)}
242
- ${t}}`),n},ev="~effect/Fiber",eb={_A:y.D_,_E:y.D_},e_={id:0},ex=(()=>{try{return globalThis.process?.getBuiltinModule?.("node:async_hooks")?.AsyncResource}catch{return}})(),ew=()=>void 0===ex?void 0:new ex("effect/Fiber"),ek=()=>globalThis[O.fL];class eS{constructor(e,t=!0){this.setContext(e),this.id=++e_.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[ev](){return eb}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return h.Jt(this.context,e)}addObserver(e){return this._exit?(e(this._exit),y.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 r=W(e);this.cache.stackFrame&&(r=(0,A.Eh)(r,h.L8(A.z8,this.cache.stackFrame))),t&&(r=(0,A.Eh)(r,t)),this._interruptedCause=this._interruptedCause?(0,A.h2)(this._interruptedCause,r):r,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(eB(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(void 0!==this._asyncContext){let t=this._asyncContext;return this._asyncContext=void 0,t.runInAsyncScope(this.evaluate,this,e)}if(void 0!==this._yielded){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===A.GN){this._asyncContext=ew();return}let r=eO.interruptChildren&&eO.interruptChildren(this);if(void 0!==r)return this.evaluate(tA(r,()=>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 r=0;r<e.length;r++)e[r](t)}this._stack.length=0,this._children=void 0,this.context=h.Ie()}runLoop(e){let t=globalThis[O.fL];globalThis[O.fL]=this;let r=this._running;this._running=!0;let n=!1,i=e;this.currentOpCount=0;try{for(;;){this._deferredInterrupt&&(this._deferredInterrupt=!1,i=eB(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!n&&!e.preventYield&&e.scheduler.shouldYield(this)){n=!0;let e=i;i=tA(eG,()=>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,b.i5)(i,A._3))return(0,A.V2)(`Fiber.runLoop: Not a valid effect: ${String(i)}`);return this.runLoop((0,A.V2)(e))}finally{this._running=r,globalThis[O.fL]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,e$;for(;;){let t=this._stack.pop();if(!t)return;let r=t[A.u4];if(void 0!==r){let n=r.call(t,this);if(n)return n[e]=n,n}if(t[e])return t}}succeedWith(e){if((++this.currentOpCount&eE-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,E.tT)(this,arguments)}setContext(e){let t=this.context;if(this.context=e,void 0!==t&&h.Pf(t,e))return;let r=e.cacheRoot,n=r._fiberCache??=eI(e);this.cache?.scheduler!==n.scheduler&&(this._dispatcher=void 0),this.cache=n}get currentSpanLocal(){let e=this.cache.span;return e?._tag==="Span"?e:void 0}}let eI=e=>{let t=h.Ub(e,T.RL);return{scheduler:h.Jt(e,C._F),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:h.Jt(e,j.rf),span:h.Ub(e,T.WG),logLevel:h.Jt(e,j.Gl),minimumLogLevel:h.Jt(e,j.zQ),stackFrame:h.Jt(e,j.vA),runtimeMetrics:h.Ub(e,P.F),maxOpsBeforeYield:h.Jt(e,C.Zm),preventYield:h.Jt(e,C.hf)}},e$={[A.ee]:(e,t)=>eB(t._interruptedCause),[A.Sc]:(e,t)=>eB(t._interruptedCause)},eE=32,eO={interruptChildren:void 0},eC=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(A.QJ.key,e.cache.stackFrame),h.LZ(t)},eT=e=>{if(void 0!==e._children&&0!==e._children.size)return eD(e._children)},eM=e=>e._exit?eF(e._exit):te(t=>e._exit?t(eF(e._exit)):ez(e.addObserver(e=>t(eF(e))))),eA=e=>te(t=>{let r,n=e[Symbol.iterator](),i=[];return!function e(){let a=n.next();for(;!a.done;){if(a.value._exit){i.push(a.value._exit),a=n.next();continue}r=a.value.addObserver(t=>{i.push(t),e()});return}t(eF(i))}(),ez(()=>r?.())}),eN=e=>e._exit?e._exit:te(t=>e._exit?t(e._exit):ez(e.addObserver(t))),eP=e=>te(t=>{let r=Array.from(e);if(0===r.length)return t(eF(p.Ie()));let n=Array(r.length),i=p.Ie(),a=()=>{for(let e=0;e<i.length;e++)r[e].removeObserver(i[e])},s=0,o=!1;for(let e=0;e<r.length&&!o;e++){let l=i=>{if(s++,"Failure"===i._tag)return o=!0,a(),t(i);n[e]=i.value,s===r.length&&t(eF(n))};i.push(l),r[e].addObserver(l)}return ez(()=>{o=!0,a()})}),eR=e=>(0,A.R6)(t=>ej(e,t.id)),ej=(0,y.XY)(e=>(0,b.i5)(e[0],ev),(e,t,r)=>(0,A.R6)(n=>{let i=eC(n);return i=i&&r?h.h1(i,r):i??r,e.interruptUnsafe(t,i),t$(eM(e))})),eD=e=>(0,A.R6)(t=>{let r=eC(t),n=p.Ie();for(let i of e)i.interruptUnsafe(t.id,r),n.push(i);return t$(eA(n))}),eU=(0,y.XY)(2,(e,t)=>(0,A.R6)(r=>{let n=eC(r),i=p.Ie();for(let r of e)r.interruptUnsafe(t,n),i.push(r);return t$(eA(i))})),eF=A.xt,eB=A.cb,eL=A.Rk,ez=(0,A.Uf)({op:"Sync",[A._3](e){let t=this[A.a2](),r=e.getCont(A.ee);return r?r[A.ee](t,e):e.yieldWith((0,A.xt)(t))}}),eW=(0,A.Uf)({op:"Suspend",[A._3](e){return this[A.a2]()}}),eJ=(0,y.XY)(e=>e.length>=2||v.isOption(e[0]),(e,t)=>v.isNone(e)?eL(t?t():new A.Xm("Effect.fromOption: Option.none")):eF(e.value)),eY=_.YW({onFailure:eL,onSuccess:eF}),eX=e=>null==e?eL(new A.Xm):eF(e),eq=(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})}}),eG=eq(0),eV=e=>eF(v.some(e)),eH=eF(v.none()),eK=e=>v.isNone(e)?eH:tD(e.value,v.some),eQ=e=>eW(()=>eB(e())),eZ=e=>(0,A.V2)(e),e0=e=>eW(()=>eL(e())),e1=eF(void 0),e2=e=>{let t="function"==typeof e?e:e.try,r="function"==typeof e?e=>new aj(e,"An error occurred in Effect.try"):e.catch;return eW(()=>{try{return eF(t())}catch(e){return eL(r(e))}})},e5=e=>e4(function(t,r){e(r).then(e=>t(eF(e)),e=>t(eZ(e)))},0!==e.length),e3=e=>{let t="function"==typeof e?e:e.try,r="function"==typeof e?e=>new aj(e,"An error occurred in Effect.tryPromise"):e.catch;return e4(function(e,n){let i=e=>eW(()=>{try{return eL((0,M.s)(()=>r(e)))}catch(e){return eZ(e)}});try{t(n).then(t=>e(eF(t)),t=>e(i(t)))}catch(t){e(i(t))}},0!==t.length)},e6=e=>(0,A.R6)(t=>e(t.id)),e8=(0,A.R6)(eF),e9=e6(eF),e4=(n=(0,A.yj)({op:"Async",[A._3](e){let t=!1,r=!1,n=this.withSignal?new AbortController:void 0,i=this.register.call(e.cache.scheduler,n=>{t||(t=!0,r?e.evaluate(n):r=n)},n?.signal);return!1!==r?r:(r=!0,e._yielded=()=>{t=!0},void 0===n&&void 0===i||e._stack.push(e7(()=>(t=!0,n?.abort(),i??t0))),A.GN)}}),(i=function(e,t){this.register=e,this.withSignal=t}).prototype=n,function(e,t){return new i(e,t)}),e7=(0,A.Uf)({op:"AsyncFinalizer",[A.u4](e){e.interruptible&&(e.interruptible=!1,e._stack.push(n2))},[A.Sc](e,t){return K(e)?tA(ng((0,A.cb)(e),this[A.a2]()),()=>eB(e)):eB(e)}}),te=e=>e4(e,e.length>=2),tt=te(y.Yi),tr=(...e)=>{if(1===e.length){let t=e[0];return eW(()=>tc(t()))}let[t,r]=e;return eW(()=>tc(r.call(t.self)))},tn=(e,...t)=>{let r=0===t.length?function(){return eW(()=>tc(e.apply(this,arguments)))}:function(){let r=eW(()=>tc(e.apply(this,arguments)));for(let e=0;e<t.length;e++)r=t[e](r,...arguments);return r};return ti(e.length,r)},ti=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),ta=F(2),ts=function(){let e,t="string"==typeof arguments[0],r=t?arguments[0]:"Effect.fn",n=t?arguments[1]:void 0,i=(0,D.jt)();return(0!==i&&((0,D.ft)(2),e=new globalThis.Error,(0,D.ft)(i)),t)?(i,...a)=>to(r,i,e,a,t,n):to(r,arguments[0],e,Array.prototype.slice.call(arguments,1),t,n)},to=(e,t,r,n,i,a)=>{let s="function"==typeof t?t:n.shift().bind(t.self),o=`${e} (definition)`,l=r?ta(()=>r.stack):y.MN;return ti(s.length,function(...t){let r,d=eW(()=>{let e=s.apply(this,arguments);return(0,A.yw)(e)?e:tc(e)});for(let e=0;e<n.length;e++)d=n[e](d,...t);if(!(0,A.yw)(d))return d;let c=(0,D.jt)();return 0!==c&&((0,D.ft)(2),r=new globalThis.Error,(0,D.ft)(c)),ra(i?ai(e,a,e=>aa(d,e)):d,j.vA,t=>({name:e,stack:r?ta(()=>r.stack):y.MN,parent:{name:o,stack:l,parent:t}}))})},tl=(e,...t)=>ti(e.length,0===t.length?function(){return td(()=>e.apply(this,arguments))}:function(){let r=td(()=>e.apply(this,arguments));for(let e of t)r=e(r,...arguments);return r}),td=e=>{try{let t,r=e();for(;;){let n=r.next(t);if(n.done)return eF(n.value);let i=n.value;if(i&&"Success"===i._tag){t=i.value;continue}{if(i&&"Failure"===i._tag)return n.value;let t=!0;return eW(()=>t?(t=!1,tA(n.value,e=>tc(r,e))):eW(()=>tc(e())))}}}catch(e){return eZ(e)}},tc=(a=(0,A.yj)({op:"Iterator",[A.ee](e,t){let r=this.iterator;for(;;){let n=r.next(e);if(n.done)return eF(n.value);if(!tP(n.value))return t._stack.push(this),n.value;if("Failure"===n.value._tag)return n.value;e=n.value.value}},[A._3](e){return this[A.ee](this.initial,e)}}),(s=function(e,t){this.iterator=e,this.initial=t}).prototype=a,function(e,t){return new s(e,t)}),tu=(0,y.XY)(2,(e,t)=>new th(e,tm,eF(t))),tf=function(e){return e._stack.push(this),this[A.a2]},tp=(0,A.yj)({op:"OnSuccess",[A._3]:tf}),th=function(e,t,r){this[A.a2]=e,this[A.ee]=t,this.payload=r};th.prototype=tp;let tm=function(){return this.payload},tg=function(e,t){return t.succeedWith(this.payload)},ty=(o="~effect/Effect/stackProbe",({[o]:function(){return Error().stack}})[o]()?.includes("[as "+o+"]")===!0),tv=function(e,t){let r=this.payload;return t.succeedWith(ty?r(e):(0,M.s)(()=>r(e)))},tb=function(e){return(0,this.payload)(e)},t_=function(e){return new th((0,this.payload)(e),tg,e)},tx=function(e){return new th(this.payload,tg,e)},tw=e=>tD(e,v.some),tk=e=>r9(e,{onFailure:eF,onSuccess:eL}),tS=(0,y.XY)(2,(e,t)=>new th(e,(0,A.yw)(t)?tm:tb,t)),tI=(0,y.XY)(2,(e,t)=>new th(e,(0,A.yw)(t)?tx:t_,t)),t$=e=>new th(e,tm,t0),tE=e=>rw(e,eL),tO=(e,t)=>(0,A.R6)(r=>{let n=new Set;return nD(r,()=>0===n.size?void 0:eD(n)),te(i=>{let a=p.Ts(e),s=a.length,o=0,l=!1,d=[],c=(e,n,a)=>{if(o++,"Failure"===e._tag){d.push(...e.cause.reasons),o>=s&&i(eB((0,A.b5)(d)));return}let c=!l;l=!0,i(e),c&&t?.onWinner&&t.onWinner({fiber:n,index:a,parentFiber:r})};for(let e=0;e<s;e++){let t=iT(r,a[e],!0,!0,!1);if(n.add(t),t.addObserver(r=>{n.delete(t),c(r,t,e)}),l)break}})}),tC=(e,t)=>(0,A.R6)(r=>{let n=new Set;return nD(r,()=>0===n.size?void 0:eD(n)),te(i=>{let a=!1,s=0;for(let o of e){if(a)break;let e=s++,l=iT(r,o,!0,!0,!1);n.add(l),l.addObserver(s=>{n.delete(l);let o=!a;a=!0,i(s),o&&t?.onWinner&&t.onWinner({fiber:l,index:e,parentFiber:r})})}})}),tT=(0,y.XY)(e=>(0,A.yw)(e[1]),(e,t,r)=>tO([e,t],r)),tM=(0,y.XY)(e=>(0,A.yw)(e[1]),(e,t,r)=>tC([e,t],r)),tA=(0,y.XY)(2,(e,t)=>new th(e,tb,t)),tN=(0,y.XY)(2,(e,t)=>tP(e)?"Success"===e._tag?t.onSuccess(e.value):t.onFailure(e.cause):rZ(e,t)),tP=e=>void 0!==e[A.IH],tR=(0,y.XY)(2,(e,t)=>tP(e)?"Success"===e._tag?t(e.value):e:tA(e,t)),tj=e=>tA(e,y.D_),tD=(0,y.XY)(2,(e,t)=>new th(e,tv,t)),tU=(0,y.XY)(2,(e,t)=>tP(e)?t1(e,t):tD(e,t)),tF=(0,y.XY)(2,(e,t)=>tP(e)?t2(e,t):rW(e,t)),tB=(0,y.XY)(2,(e,t)=>tP(e)?t5(e,t):rJ(e,t)),tL=(0,y.XY)(2,(e,t)=>{if(tP(e)){if("Success"===e._tag)return e;let r=X(e.cause);return _.N6(r)?e:t(r.success)}return rE(e,t)}),tz=e=>(0,A.cb)(W(e)),tW=e=>"Success"===e._tag,tJ=e=>"Success"===e._tag?_.Py(e):_.fJ(e),tY=e=>"Success"===e._tag?_.Py(e.value):_.fJ(e),tX=e=>"Failure"===e._tag,tq=e=>"Failure"===e._tag?_.Py(e):_.fJ(e),tG=e=>"Failure"===e._tag?_.Py(e.cause):_.fJ(e),tV=x(tG,X),tH=x(tG,H),tK=e=>"Failure"===e._tag&&K(e.cause),tQ=e=>"Failure"===e._tag&&G(e.cause),tZ=e=>"Failure"===e._tag&&J(e.cause),t0=(0,A.xt)(void 0),t1=(0,y.XY)(2,(e,t)=>"Success"===e._tag?(0,A.xt)(t(e.value)):e),t2=(0,y.XY)(2,(e,t)=>{if("Success"===e._tag)return e;let r=X(e.cause);return _.N6(r)?e:(0,A.Rk)(t(r.success))}),t5=(0,y.XY)(2,(e,t)=>{if("Success"===e._tag)return(0,A.xt)(t.onSuccess(e.value));let r=X(e.cause);return _.N6(r)?e:(0,A.Rk)(t.onFailure(r.success))}),t3=(0,y.XY)(2,(e,t)=>tW(e)?(0,A.xt)(t):e),t6=(0,y.XY)(2,(e,t)=>tW(e)?t:e),t8=(0,y.XY)(2,(e,t)=>tW(e)?t.onSuccess(e.value):t.onFailure(e.cause)),t9=t3(void 0),t4=e=>{let t=[];for(let r of e)"Failure"===r._tag&&t.push(...r.cause.reasons);return 0===t.length?t0:(0,A.cb)((0,A.b5)(t))},t7=e=>tW(e)?v.some(e.value):v.none(),re=e=>tX(e)?v.some(e.cause):v.none(),rt=e=>{let t=tV(e);return _.N6(t)?v.none():v.some(t.success)},rr=e=>e,rn=e=>(0,A.R6)(t=>eF(h.om(t.context,e))),ri=(0,y.XY)(2,(e,t)=>(0,A.R6)(r=>{let n=r.context,i=t(n);return n===i||(r.setContext(i),nD(r,()=>{r.setContext(n)})),e})),ra=(0,y.XY)(3,(e,t,r)=>ri(e,e=>{let n=h.fp(e,t),i=r(n);return n===i?e:h.WQ(e,t,i)})),rs=(e,t,r)=>n0((0,A.R6)(n=>{let i=h.fp(n.context,e),a=t(i);return n.setContext(h.WQ(n.context,e,a)),n_(h.fp(n.context,nf),t=>{let s,o=h.om(n.context,e);if(v.isNone(o))return e1;let l=o.value;if(r?.reset===void 0){if(l!==a)return e1;s=i}else s=r.reset(i,a,l);return n.setContext(h.WQ(n.context,e,s)),e1})})),ro=()=>rl,rl=(0,A.R6)(e=>eF(e.context)),rd=e=>(0,A.R6)(t=>e(t.context)),rc=(0,y.XY)(2,(e,t)=>ri(e,(0,y.dY)(t))),ru=(0,y.XY)(2,(e,t)=>tP(e)?e:ri(e,h.h1(t))),rf=function(){return 1==arguments.length?(0,y.XY)(2,(e,t)=>rp(e,arguments[0],t)):(0,y.XY)(3,(e,t,r)=>rp(e,t,r)).apply(this,arguments)},rp=(e,t,r)=>ri(e,h.WQ(t,r)),rh=(0,y.XY)(3,(e,t,r)=>tA(r,r=>rf(e,t,r))),rm=(0,y.XY)(e=>(0,A.yw)(e[1]),(e,t,r)=>rg(e,t,(e,t)=>[e,t],r)),rg=(0,y.XY)(e=>(0,A.yw)(e[1]),(e,t,r,n)=>n?.concurrent?tD(ie([e,t],{concurrency:2}),([e,t])=>r(e,t)):tA(e,e=>tD(t,t=>r(e,t)))),ry=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>ib(e,t,r?e=>eL(r(e)):()=>eL(new A.Xm))),rv=(0,y.XY)(2,(e,t)=>tA(t,t=>t?tw(e):eH)),rb=(0,y.XY)(2,(e,t)=>Array.from({length:t},()=>e)),r_=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>ie(rb(e,t),r)),rx=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>id({while:y.ue,body:(0,y.dY)(t?.disableYield?e:tA(e,e=>eG)),step:y.Yi})),rw=(0,y.XY)(2,(e,t)=>new rS(e,1!==t.length?e=>t(e):t)),rk=(0,A.yj)({op:"OnFailure",[A._3]:tf}),rS=function(e,t){this[A.a2]=e,this[A.Sc]=t};rS.prototype=rk;let rI=(0,y.XY)(3,(e,t,r)=>rw(e,e=>t(e)?r(e):eB(e))),r$=(0,y.XY)(3,(e,t,r)=>rw(e,e=>{let n=t(e);return _.N6(n)?eB(n.failure):r(n.success,e)})),rE=(0,y.XY)(2,(e,t)=>r$(e,X,e=>t(e))),rO=e=>r9(e,{onFailure:e=>(0,A.PW)(e)?eH:eL(e),onSuccess:eV}),rC=(0,y.XY)(2,(e,t)=>r$(e,H,t)),rT=(0,y.XY)(2,(e,t)=>rw(e,e=>tS(t(e),eB(e)))),rM=(0,y.XY)(3,(e,t,r)=>rI(e,t,e=>tS(r(e),eB(e)))),rA=(0,y.XY)(3,(e,t,r)=>rw(e,e=>{let n=t(e);return _.N6(n)?eB(e):tS(r(n.success,e),eB(e))})),rN=(0,y.XY)(2,(e,t)=>rA(e,X,e=>t(e))),rP=(0,y.XY)(3,(e,t,r)=>{let n=Array.isArray(t)?e=>(0,b.i5)(e,"_tag")&&t.includes(e._tag):(0,b.$J)(t);return rN(e,e=>n(e)?r(e):e1)}),rR=(0,y.XY)(2,(e,t)=>rA(e,H,e=>t(e))),rj=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n)=>rw(e,e=>{let i=X(e);return _.N6(i)?eB(i.failure):t(i.success)?r(i.success):n?n(i.success):eB(e)})),rD=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n)=>rw(e,e=>{let i=X(e);if(_.N6(i))return eB(i.failure);let a=t(i.success);return _.N6(a)?n?n(a.failure):eB(e):r(a.success)})),rU=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n)=>rj(e,Array.isArray(t)?e=>(0,b.i5)(e,"_tag")&&t.includes(e._tag):(0,b.$J)(t),r,n)),rF=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>{let n;return rD(e,e=>(n??=Object.keys(t),(0,b.i5)(e,"_tag")&&(0,b.Kg)(e._tag)&&n.includes(e._tag)?_.Py(e):_.fJ(e)),e=>t[e._tag](e),r)}),rB=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n,i)=>rj(e,e=>(0,b.$J)(e,t)&&(0,b.i5)(e,"reason")&&(void 0!==i||(0,b.$J)(e.reason,r)),e=>{let t=e.reason;return(0,b.$J)(t,r)?n(t,e):i?i(t,e):eL(e)})),rL=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n)=>{let i;return rj(e,e=>(0,b.$J)(e,t)&&(0,b.i5)(e,"reason")&&(0,b.i5)(e.reason,"_tag")&&(0,b.Kg)(e.reason._tag)&&(void 0!==n||(i??=Object.keys(r)).includes(e.reason._tag)),e=>{let t=e.reason;return(i??=Object.keys(r)).includes(t._tag)?r[t._tag](t,e):n?n(t,e):eL(e)})}),rz=(0,y.XY)(2,(e,t)=>rD(e,e=>(0,b.$J)(e,t)&&(0,b.i5)(e,"reason")?_.Py(e.reason):_.fJ(e),eL)),rW=(0,y.XY)(2,(e,t)=>rE(e,e=>e0(()=>t(e)))),rJ=(0,y.XY)(2,(e,t)=>r9(e,{onFailure:e=>e0(()=>t.onFailure(e)),onSuccess:e=>ez(()=>t.onSuccess(e))})),rY=e=>rE(e,eZ),rX=(0,y.XY)(2,(e,t)=>rE(e,e=>ez(()=>t(e)))),rq=e=>eW(()=>{let t=e[Symbol.iterator](),r=t.next();return r.done?eZ(Error("Received an empty collection of effects")):function e(r){let n=t.next();return n.done?r.value:rE(r.value,t=>e(n))}(r)}),rG=e=>rE(e,t=>tA(eG,()=>rG(e))),rV=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>{if(!t?.log)return r9(e,{onFailure:e=>e1,onSuccess:e=>e1});let r=aX(!0===t.log?void 0:t.log);return rZ(e,{onFailure(e){let n=Y(e);return _.N6(n)?eB(n.failure):void 0===t.message?r(e):r(t.message,e)},onSuccess:e=>e1})}),rH=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>{if(!t?.log)return rZ(e,{onFailure:e=>e1,onSuccess:e=>e1});let r=aX(!0===t.log?void 0:t.log);return rZ(e,{onFailure:e=>void 0===t.message?r(e):r(t.message,e),onSuccess:e=>e1})}),rK=e=>r4(e,{onFailure:v.none,onSuccess:v.some}),rQ=e=>r7(e,{onFailure:_.fJ,onSuccess:_.Py}),rZ=(0,y.XY)(2,(e,t)=>new r1(e,1!==t.onSuccess.length?e=>t.onSuccess(e):t.onSuccess,1!==t.onFailure.length?e=>t.onFailure(e):t.onFailure)),r0=(0,A.yj)({op:"OnSuccessAndFailure",[A._3]:tf}),r1=function(e,t,r){this[A.a2]=e,this[A.ee]=t,this[A.Sc]=r};r1.prototype=r0;let r2=function(e,t){let r=this.payload;return t.succeedWith(ty?r.onSuccess(e):(0,M.s)(()=>r.onSuccess(e)))},r5=(e,t)=>{let r=(0,A.yj)({op:e,[A._3]:tf,[A.ee]:r2,[A.Sc]:t}),n=function(e,t){this[A.a2]=e,this.payload=t};return n.prototype=r,n},r3=r5("Match",function(e,t){let r=e.reasons.find(A.lC);if(void 0===r)return eB(e);let n=this.payload;return t.succeedWith(ty?n.onFailure(r.error):(0,M.s)(()=>n.onFailure(r.error)))}),r6=r5("MatchCause",function(e,t){let r=this.payload;return t.succeedWith(ty?r.onFailure(e):(0,M.s)(()=>r.onFailure(e)))}),r8=(0,y.XY)(2,(e,t)=>new r6(e,t)),r9=(0,y.XY)(2,(e,t)=>rZ(e,{onFailure:e=>{let r=e.reasons.find(A.lC);return r?t.onFailure(r.error):eB(e)},onSuccess:t.onSuccess})),r4=(0,y.XY)(2,(e,t)=>new r3(e,t)),r7=(0,y.XY)(2,(e,t)=>{if(tP(e)){if("Success"===e._tag)return(0,A.xt)(t.onSuccess(e.value));let r=X(e.cause);return _.N6(r)?e:(0,A.xt)(t.onFailure(r.success))}return r4(e,t)}),ne=(0,y.XY)(2,(e,t)=>tP(e)?"Success"===e._tag?(0,A.xt)(t.onSuccess(e.value)):(0,A.xt)(t.onFailure(e.cause)):r8(e,t)),nt=e=>tP(e)?(0,A.xt)(e):nr(e),nr=(0,A.Uf)({op:"Exit",[A._3](e){return e._stack.push(this),this[A.a2]},[A.ee]:(e,t,r)=>t.succeedWith(r??(0,A.xt)(e)),[A.Sc]:(e,t,r)=>t.succeedWith(r??(0,A.cb)(e))}),nn=r7({onFailure:()=>!0,onSuccess:()=>!1}),ni=r7({onFailure:()=>!1,onSuccess:()=>!0}),na=(0,y.XY)(2,(e,t)=>tS(av(t),e)),ns=(0,y.XY)(2,(e,t)=>tA(nl(e,t.duration),e=>v.isNone(e)?t.orElse():eF(e.value))),no=(0,y.XY)(2,(e,t)=>{let r=m.bN(t);return ns(e,{duration:r,orElse:()=>eL(new aS(`Operation timed out after '${m.GP(r)}'`))})}),nl=(0,y.XY)(2,(e,t)=>tM(tw(e),tu(av(t),v.none()))),nd=e=>ay(t=>{let r=t.monotonicTimeNanosUnsafe();return tD(e,e=>[m.cF(t.monotonicTimeNanosUnsafe()-r),e])}),nc="~effect/Scope",nu="~effect/Scope/Closeable",nf=h.kl("effect/Scope"),np=(e,t)=>(0,A.R6)(r=>{let n=nh(e,t);return void 0===n?e1:(n6(r),n)}),nh=(e,t)=>{let r=e.state;if("Closed"===r._tag||(e.state={_tag:"Closed",exit:t},void 0!==e.parent&&nk(e.parent,e),"Empty"===r._tag))return;if(void 0!==r.finalizer)return nm(r.finalizer,t);let n=r.finalizers;return 1===n.size?nm(n.values().next().value,t):ny(e,n,t)},nm=(e,t)=>{try{return e(t)}catch(e){return(0,A.V2)(e)}},ng=(e,t)=>tW(e)?t:rw(t,t=>eB((0,A.h2)(e.cause,t))),ny=tn(function*(e,t,r){let n=[],i=[],a=Array.from(t.values()),s=ek();for(let t=a.length-1;t>=0;t--){let o=a[t];"sequential"===e.strategy?n.push((yield*nt(nm(o,r)))):i.push(iT(s,nm(o,r),!0,!0,"inherit"))}return i.length>0&&(n=yield*eA(i)),yield*t4(n)}),nv=(e,t)=>ez(()=>nb(e,t)),nb=(e,t)=>{let r=nI(t,e);return"Closed"===e.state._tag?r.state=e.state:nw(e,r,e=>np(r,e)),r},n_=(e,t)=>eW(()=>"Closed"===e.state._tag?t(e.state.exit):(nw(e,{},t),e1)),nx=(e,t)=>n_(e,(0,y.dY)(t)),nw=(e,t,r)=>{if("Empty"===e.state._tag)e.state={_tag:"Open",finalizerKey:t,finalizer:r,finalizers:void 0};else if("Open"===e.state._tag){let n=e.state;void 0!==n.finalizer&&(n.finalizers=new Map([[n.finalizerKey,n.finalizer]]),n.finalizerKey=void 0,n.finalizer=void 0),n.finalizers.set(t,r)}},nk=(e,t)=>{if("Open"!==e.state._tag)return;let r=e.state;r.finalizerKey===t?e.state=n$:void 0!==r.finalizers&&(r.finalizers.delete(t),0===r.finalizers.size&&(e.state=n$))},nS=e=>nI(e,void 0),nI=(e="sequential",t)=>({[nu]:nu,[nc]:nc,strategy:e,parent:t,state:n$}),n$={_tag:"Empty"},nE=e=>ez(()=>nS(e)),nO=nf,nC=rf(nf),nT=e=>(0,A.R6)(t=>{let r=t.context,n=nS();return t.setContext(h.WQ(t.context,nf,n)),nD(t,e=>(t.setContext(r),nh(n,e))),e}),nM=(0,y.XY)(2,(e,t)=>nU(nC(e,t),e=>eW(()=>nh(t,e)??e1))),nA=e=>eW(()=>{let t=nS();return nU(e(t),e=>eW(()=>nh(t,e)??e1))}),nN=(e,t,r)=>rd(n=>n9(i=>tA(nO,a=>tI(r?.interruptible?i(e):e,e=>n_(a,r=>ru(t(e,r),n)))))),nP=e=>tA(nO,t=>rd(r=>n_(t,t=>ru(e(t),r)))),nR=(l=(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(n2),e.interruptible=!1)},[A.ee](e,t,r){let n;r??=(0,A.xt)(e);try{n=this.onExit(r)}catch(e){n=(0,A.V2)(e)}return n?tA(n,e=>r):r},[A.Sc](e,t,r){let n;r??=(0,A.cb)(e);try{n=this.onExit(r)}catch(e){n=(0,A.V2)(e)}return n?tA(ng(r,n),e=>r):r}}),(d=function(e,t,r){this.effect=e,this.onExit=t,this.interruptible=r}).prototype=l,d),nj=(e,t,r)=>new nR(e,t,r),nD=(e,t)=>{e._stack.push(new nR(void 0,t,void 0))},nU=(0,y.XY)(2,nj),nF=(0,y.XY)(2,(e,t)=>nU(e,e=>t)),nB=(0,y.XY)(3,(e,t,r)=>nU(e,e=>t(e)?r(e):e1)),nL=(0,y.XY)(3,(e,t,r)=>nU(e,e=>{let n=t(e);return _.N6(n)?e1:r(n.success,e)})),nz=(0,y.XY)(2,(e,t)=>nL(e,tG,t)),nW=(0,y.XY)(3,(e,t,r)=>nB(e,e=>"Failure"===e._tag&&t(e.cause),e=>r(e.cause))),nJ=(0,y.XY)(3,(e,t,r)=>nU(e,e=>{if("Failure"!==e._tag)return e1;let n=t(e.cause);return _.N6(n)?e1:r(n.success,e.cause)})),nY=(0,y.XY)(2,(e,t)=>nJ(Z,t)(e)),nX=(e,t,r)=>n9(n=>tA(e,e=>nj(eW(()=>n(t(e))),t=>r(e,t),!0))),nq=e=>nN(e,e=>(0,b.i5)(e,Symbol.asyncDispose)?e5(()=>e[Symbol.asyncDispose]()):ez(()=>e[Symbol.dispose]())),nG=(0,y.XY)(2,(e,t)=>ez(()=>nH(e,"function"==typeof t?e=>m.kE(m.bN(t(e))):(0,y.dY)(m.kE(m.bN(t)))))),nV=(0,y.dY)(1/0),nH=(e,t)=>{let r,n,i=0,a=(e,t)=>(t.awaiters++,nD(e,()=>{if(!(--t.awaiters>0)&&n===t)return n=void 0,eR(t.fiber)}),eN(t.fiber));return[(0,A.R6)(s=>{if(void 0!==n)return a(s,n);if(void 0!==r&&(1/0===i||s.getRef(af).currentTimeMillisUnsafe()<i))return r;r=void 0;let o=s.getRef(af),l={fiber:void 0,awaiters:0};return n=l,l.fiber=iT(s,nj(e,e=>{if(n!==l||(n=void 0,tK(e)))return;let a=t(e);i=1/0===a?1/0:o.currentTimeMillisUnsafe()+a,r=e}),!0,!0),l.fiber._exit??a(s,l)}),ez(()=>{r=void 0})]},nK=(0,y.XY)(2,(e,t)=>tD(nG(e,t),e=>e[0])),nQ=e=>ez(()=>nH(e,nV)[0]),nZ=(0,A.R6)(e=>eB(W(e.id))),n0=e=>(0,A.R6)(t=>(t.interruptible&&(t.interruptible=!1,t._stack.push(n2)),e)),n1=(0,A.Uf)({op:"SetInterruptible",[A.u4](e){if(e.interruptible=this[A.a2],e._interruptedCause&&e.interruptible)return()=>eB(e._interruptedCause)}}),n2=n1(!0),n5=n1(!1),n3=e=>{if(e.interruptible=!0,e._stack.push(n5),e._interruptedCause)return eB(e._interruptedCause)},n6=e=>{e.interruptible&&(e.interruptible=!1,e._stack.push(n2))},n8=e=>(0,A.R6)(t=>t.interruptible?e:n3(t)??e),n9=e=>(0,A.R6)(t=>t.interruptible?(t.interruptible=!1,t._stack.push(n2),e(n8)):e(y.D_)),n4=e=>(0,A.R6)(t=>{if(t.interruptible)return e(y.D_);let r=n3(t),n=e(n0);return r??n}),n7=tD(nN(ez(()=>new AbortController),e=>ez(()=>e.abort())),e=>e.signal),ie=(e,t)=>(0,b.xZ)(e)?t?.mode==="result"?ic(e,rQ,t):ic(e,y.D_,t):t?.discard?"result"===t.mode?ic(Object.values(e),rQ,t):ic(Object.values(e),y.D_,t):eW(()=>{let r={};return tu(ic(Object.entries(e),([e,n])=>tD(t?.mode==="result"?rQ(n):n,t=>{R.x(r,e,t)}),{discard:!0,concurrency:t?.concurrency}),r)}),it=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,r)=>tD(ic(e,(e,r)=>rQ(t(e,r)),r),e=>p.jB(e,y.D_))),ir=(0,y.XY)(3,(e,t,r)=>{let n=p.Ts(e);return 0===n.length?ez(t):eW(()=>{let e=0,i=t();return tD(id({while:()=>e<n.length,body:()=>r(i,n[e],e),step(t){i=t,e++}}),()=>i)})}),ii=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,r)=>tA(it(e,t,{concurrency:r?.concurrency}),([e,t])=>p.CZ(t)?eL(t):r?.discard?e1:eF(e))),ia=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eW(()=>{let r=e[Symbol.iterator](),n=r.next();return n.done?eF(v.none()):is(r,0,t,n.value)})),is=(e,t,r,n)=>tA(r(n,t),i=>{if(i)return eF(v.some(n));let a=e.next();return a.done?eF(v.none()):is(e,t+1,r,a.value)}),io=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eW(()=>{let r=e[Symbol.iterator](),n=r.next();return n.done?eF(v.none()):il(r,0,t,n.value)})),il=(e,t,r,n)=>tA(r(n,t),n=>{if(_.oJ(n))return eF(v.some(n.success));let i=e.next();return i.done?eF(v.none()):il(e,t+1,r,i.value)}),id=(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}}),ic=(0,y.XY)(e=>"function"==typeof e[1],(e,t,r)=>eW(()=>{let n=ih(r?.concurrency);if(1===n)return ip(e,t,r);let i=p.Ts(e),a=i.length;if(0===a)return r?.discard?e1:eF([]);let s=r?.discard?void 0:Array(a),o=iv({f:t,out:s},i,{concurrency:n});return o?tu(o,s):eF(s)})),iu=e=>tA(e,e=>{let t=e[Symbol.iterator]().next();return t.done?eL(new A.Xm):eF(t.value)}),ip=(e,t,r)=>eW(()=>{let n=r?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),s=0;return tu(id({while:()=>!a.done,body:()=>t(a.value,s++),step:e=>{n&&n.push(e),a=i.next()}}),n)}),ih=e=>"unbounded"===e?1/0:Math.max(1,e??1),im=()=>e=>{let t=e.onItem,r=e.step,n=(e,t,n,a,s)=>tA(nt(s),s=>r(e,t[n],s,n)??i(e,t,n+1,a)??e1),i=(e,i,a=0,s=i.length)=>{for(;a<s;a++){let o=i[a],l=t(e,o,a);if(!tP(l))return n(e,i,a,s,l);let d=r(e,o,l,a);if(d)return"Failure"===d._tag?d:void 0}};return i},ig=e=>{let t=e.onItem,r=e.step;return(e,n,i)=>{let a,s,o,l,d,c=0,u=i.end??n.length,f=i.concurrency,p=!1,h=e=>{let t=(0,A.V2)(e);return l=t,p=!0,s&&s.size>0?tA(n0(eD(Array.from(s))),()=>l??t):t},m=()=>{let i=!1;for(;!l&&c<u;c++){let u=n[c],g=d??t(e,u,c);if(tP(g)){if(l=r(e,u,g,c))break}else{if(!a)return te(e=>{let t;a=ek(),s=new Set,d=g,o=e;try{t=m()}catch(t){return e(h(t))}return t?e(t):eW(()=>(l??=t0,tA(s?eD(s):e1,()=>l?._tag==="Failure"?l:e1)))});d=void 0;let t=iT(a,g,!0,!0,"inherit");if(t._exit){if(l=r(e,u,t._exit,c))break;continue}s.add(t);let n=c;if(t.addObserver(a=>{s.delete(t);try{if(l){if("Failure"===a._tag){let e=a.cause.reasons.filter(e=>"Interrupt"!==e._tag);if(e.length>0){let t=(0,A.b5)(e);l=(0,A.cb)("Failure"===l._tag?(0,A.h2)(l.cause,t):t)}}}else{let t=r(e,u,a,n);t&&(l=t,m())}if(i){let e=m();e&&o(e)}else p&&0===s.size&&o(l??e1)}catch(e){o(h(e))}}),s.size<f)continue;i=!0,c++;return}}if(p=!0,l){if(s&&s.size>0){let e=eC(a);s.forEach(t=>t.interruptUnsafe(a.id,e));return}if(o||"Failure"===l._tag)return l}else if(o)if(!s)return t0;else 0===s.size&&o(e1)};return m()}},iy=()=>e=>ig(e),iv=ig({onItem:(e,t,r)=>e.f(t,r),step(e,t,r,n){if("Failure"===r._tag)return r;e.out&&(e.out[n]=r.value)}}),ib=(0,y.XY)(3,(e,t,r)=>tA(e,e=>t(e)?eF(e):r(e))),i_=(0,y.XY)(3,(e,t,r)=>tA(e,e=>{let n=t(e);return _.N6(n)?r(n.failure):eF(n.success)})),ix=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>i_(e,t,r?e=>eL(r(e)):()=>eL(new A.Xm))),iw=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,r)=>eW(()=>{let n=[];return tu(ic(e,(e,r)=>{let i=t(e,r);return"boolean"==typeof i?(i&&n.push(e),e1):tD(i,t=>{t&&n.push(e)})},{discard:!0,concurrency:r?.concurrency}),n)})),ik=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eW(()=>{let r=[];for(let n of e){let e=t(n);_.oJ(e)&&r.push(e.success)}return eF(r)})),iS=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,r)=>eW(()=>{let n=[];return tu(ic(e,e=>tD(t(e),e=>{_.oJ(e)&&n.push(e.success)}),{discard:!0,concurrency:r?.concurrency}),n)})),iI=eF({}),i$=N.Jr(tD),iE=N.oI(tD,tA),iO=N.zM(tD),iC=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>(0,A.R6)(r=>(eO.interruptChildren??=eT,eF(iT(r,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),iT=(e,t,r=!1,n=!1,i=!1)=>{let a="inherit"===i?e.interruptible:!i,s=new eS(e.context,a);return r?s.evaluate(t):(s._asyncContext=ew(),e.currentDispatcher.scheduleTask(()=>s.evaluate(t),0)),n||s._exit||(e.children().add(s),s._parent=e),s},iM=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>(0,A.R6)(r=>eF(iT(r,e,t?.startImmediately,!0,t?.uninterruptible)))),iA=e=>(0,A.R6)(t=>{let r=t._children&&new Set(t._children),n=t.interruptible;return nj(e,e=>{let i=t._children;if(void 0===i||0===i.size)return e1;r&&(i=I.pb(i,e=>!r.has(e)));let a=t$(eA(i));return n?n8(a):a})}),iN=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>(0,A.R6)(n=>{let i=iT(n,e,r?.startImmediately,!0,r?.uninterruptible);if(!i._exit)if("Closed"!==t.state._tag){let e={};nw(t,e,()=>e6(e=>e===i.id?e1:eR(i))),i.addObserver(()=>nk(t,e))}else i.interruptUnsafe(n.id,eC(n));return eF(i)})),iP=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>tA(nO,r=>iN(e,r,t))),iR=e=>(t,r)=>{let n=new eS(r?.scheduler?h.WQ(e,C._F,r.scheduler):e,r?.uninterruptible!==!0);if(n.evaluate(t),n._exit)return n;if(r?.signal)if(r.signal.aborted)n.interruptUnsafe();else{let e=()=>n.interruptUnsafe();r.signal.addEventListener("abort",e,{once:!0}),n.addObserver(()=>r.signal.removeEventListener("abort",e))}return r?.onFiberStart&&r.onFiberStart(n),n},ij=(0,y.XY)(2,(e,t)=>{if(e._exit)return e;if("Closed"===t.state._tag)return e.interruptUnsafe(e.id),e;let r={};return nw(t,r,()=>eR(e)),e.addObserver(()=>nk(t,r)),e}),iD=iR(h.Ie()),iU=e=>{let t=iR(e);return(e,r)=>{let n=t(e,r);return r?.onExit&&n.addObserver(r.onExit),e=>n.interruptUnsafe(e)}},iF=iU(h.Ie()),iB=e=>{let t=iR(e);return(e,r)=>{let n=t(e,r);return new Promise(e=>{n.addObserver(t=>e(t))})}},iL=iB(h.Ie()),iz=e=>{let t=iB(e);return(e,r)=>t(e,r).then(e=>{if("Failure"===e._tag)throw es(e.cause);return e.value})},iW=iz(h.Ie()),iJ=e=>{let t=iR(e);return e=>{if(tP(e))return e;let r=t(e,{scheduler:new C.FG("sync")});return r._dispatcher?.flush(),r._exit??(0,A.V2)(new aN(r))}},iY=iJ(h.Ie()),iX=e=>{let t=iJ(e);return e=>{let r=t(e);if("Failure"===r._tag)throw es(r.cause);return r.value}},iq=iX(h.Ie()),iG=eF(!0),iV=eF(!1);class iH{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(0===this.waiters.length)return iG;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=[],iG}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?iV:(this._isOpen=!0,this.scheduleUnsafe(e)));release=(0,A.R6)(e=>this._isOpen?iV:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=te(e=>this._isOpen?e(e1):(this.waiters.push(e),ez(()=>{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=ez(()=>this.closeUnsafe());whenOpen=e=>tA(this.await,()=>e);isOpen(){return this._isOpen}}let iK=e=>new iH(e??!1),iQ=e=>ez(()=>iK(e)),iZ=(0,A.R6)(e=>eF(e.getRef(T.sh))),i0=(0,y.XY)(2,(e,t)=>rf(e,T.sh,t)),i1=rf(j.rf),i2=rf(j.nU),i5=BigInt(0),i3={_tag:"Span",spanId:"noop",traceId:"noop",sampled:!1,status:{_tag:"Ended",startTime:i5,endTime:i5,exit:t0},attributes:new Map,links:[],kind:"internal",attribute(){},event(){},end(){},addLinks(){}},i6=e=>e?h.Jt(e.annotations,T.DW)?"Span"===e._tag?i6(v.getOrUndefined(e.parent)):v.none():v.some(e):v.none(),i8=(e,t,r)=>{let n,i=!e.cache.tracerEnabled||r?.annotations&&h.Jt(r.annotations,T.DW),a=r?.parent!==void 0?v.some(r.parent):r?.root?v.none():i6(e.cache.span);if(i){let e;e={name:t,parent:a,annotations:h.WQ(r?.annotations??h.Ie(),T.DW,!0)},n=Object.assign(Object.create(i3),e)}else{let i=e.cache.tracer??T.Vv,s=e.getRef(af),o=e.getRef(j.nU),l=e.getRef(j.ce),d=e.getRef(j.ls),c=r?.level??e.getRef(T.pX),u=r?.links!==void 0?[...d,...r.links]:0===d.length?[]:d.slice();for(let d in n=i.span({name:t,parent:a,annotations:r?.annotations??h.Ie(),links:u,startTime:o?s.currentTimeNanosUnsafe():i5,kind:r?.kind??"internal",root:r?.root??v.isNone(a),sampled:r?.sampled??((!v.isSome(a)||!1!==a.value.sampled)&&!aF(e.getRef(T.EW),c))}),l)n.attribute(d,l[d]);if(r?.attributes!==void 0)for(let e in r.attributes)n.attribute(e,r.attributes[e])}return n},i9=(e,t)=>(0,A.R6)(r=>eF(i8(r,e,t))),i4=(e,t)=>n0((0,A.R6)(r=>{let n=h.fp(r.context,nf),i=i8(r,e,t??{}),a=r.getRef(af),s=r.getRef(j.nU);return tu(n_(n,e=>an(i,e,a,s)),i)})),i7=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],r=U(e?arguments[2]:arguments[1]);if(e){let e=arguments[0];return tA(i4(t,r),t=>as(e,t,r))}return e=>tA(i4(t,r),t=>as(e,t,r))},ae=j.ce,at=j.ls,ar=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r={})=>{let n=(Array.isArray(t)?t:[t]).map(e=>({span:e,attributes:r}));return ra(e,j.ls,e=>[...e,...n])}),an=(e,t,r,n)=>ez(()=>{"Ended"!==e.status._tag&&e.end(n?r.currentTimeNanosUnsafe():i5,t)}),ai=(e,...t)=>{let r=1===t.length?void 0:t[0],n=t[t.length-1];return(0,A.R6)(t=>{let i=i8(t,e,r),a=t.getRef(af),s=t.getRef(j.nU);return nD(t,e=>an(i,e,a,s)),n(i)})},aa=rf(T.Tv),as=function(){let e=(0,A.yw)(arguments[0]),t=e?arguments[1]:arguments[0],r=e?arguments[2]:arguments[1],n=y.D_;if("Span"===t._tag){var i,a;r=U(r),i=t.name,a="function"==typeof(a=r?.captureStackTrace)?a:y.MN,n=ra(j.vA,e=>({name:i,stack:a,parent:e}))}return e?aa(n(arguments[0]),t):e=>aa(n(e),t)},ao=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],r=U(arguments[2]);if(e){let e=arguments[0];return ai(t,arguments[2],t=>as(e,t,r))}let n="function"==typeof arguments[1]?arguments[1]:void 0,i=n?void 0:arguments[1];return(e,...a)=>ai(t,n?n(...a):i,t=>as(e,t,r))},al=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,...t)=>ra(e,j.ce,e=>{let r=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||R.x(r,t[0],t[1]),r})),ad=(...e)=>(0,A.R6)(t=>{let r=t.currentSpanLocal;if(r)if(1===e.length)for(let[t,n]of Object.entries(e[0]))r.attribute(t,n);else r.attribute(e[0],e[1]);return e1}),ac=(0,A.R6)(e=>{let t=e.currentSpanLocal;return t?eF(t):eL(new A.Xm)}),au=(c=T.Tv,(0,A.R6)(e=>eJ(h.om(e.context,c)))),af=h.Or("effect/Clock",{defaultValue:()=>new ap});class ap{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=ez(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return ag()}currentTimeNanos=ez(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return am()}monotonicTimeNanos=ez(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(m.kE(e))}sleepMillis(e){return e<=0?eG:Number.isFinite(e)?te(t=>{let r=e>0x7fffffff?this.sleepMillis(e-0x7fffffff):e1,n=setTimeout(()=>t(r),Math.min(e,0x7fffffff));return ez(()=>clearTimeout(n))}):tt}}let ah=BigInt(1e6),am=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())*ah;return e>t&&(t=e),t}}(),ag=(f=BigInt(1e9),()=>{let e=am(),t=BigInt(Date.now())*ah;if(void 0===u)u=t-e;else{let r=u+e;(t>r?t-r:r-t)>f&&(u=t-e)}return u+e}),ay=e=>(0,A.R6)(t=>e(t.getRef(af))),av=e=>ay(t=>t.sleep(m.bN(e))),ab=ay(e=>e.currentTimeMillis),a_=ay(e=>e.currentTimeNanos),ax=ay(e=>e.monotonicTimeNanos),aw="~effect/Cause/TimeoutError",ak=e=>(0,b.i5)(e,aw);class aS extends(0,A.rN)("TimeoutError"){[aw]=aw;constructor(e){super({message:e})}}let aI="~effect/Cause/IllegalArgumentError",a$=e=>(0,b.i5)(e,aI);class aE extends(0,A.rN)("IllegalArgumentError"){[aI]=aI;constructor(e){super({message:e})}}let aO="~effect/Cause/ExceededCapacityError",aC=e=>(0,b.i5)(e,aO);class aT extends(0,A.rN)("ExceededCapacityError"){[aO]=aO;constructor(e){super({message:e})}}let aM="~effect/Cause/AsyncFiberError",aA=e=>(0,b.i5)(e,aM);class aN extends(0,A.rN)("AsyncFiberError"){[aM]=aM;constructor(e){super({message:"An asynchronous Effect was executed with Effect.runSync",fiber:e})}}let aP="~effect/Cause/UnknownError",aR=e=>(0,b.i5)(e,aP);class aj extends(0,A.rN)("UnknownError"){[aP]=aP;constructor(e,t){super({message:t,cause:e})}}let aD=h.Or("effect/Console",{defaultValue:()=>globalThis.console}),aU=$.zQ($.wN,e=>{switch(e){case"All":return Number.MIN_SAFE_INTEGER;case"Fatal":return 5e4;case"Error":return 4e4;case"Warn":return 3e4;case"Info":return 2e4;case"Debug":return 1e4;case"Trace":return 0;case"None":return Number.MAX_SAFE_INTEGER}}),aF=$.yJ(aU),aB=h.Or("effect/Logger/CurrentLoggers",{defaultValue:()=>new Set([aq,aG])}),aL=h.Or("effect/Logger/LogToStderr",{defaultValue:y.f4}),az=function(){let e="string"==typeof arguments[0]?[[arguments[0],arguments[1]]]:Object.entries(arguments[0]);return n0((0,A.R6)(t=>{let r=t.getRef(j.iL),n={...r};for(let t=0;t<e.length;t++){let[r,i]=e[t];R.x(n,r,i)}return t.setContext(h.WQ(t.context,j.iL,n)),n_(h.fp(t.context,nf),n=>{let i=t.getRef(j.iL),a={...i};for(let t=0;t<e.length;t++){let[n,s]=e[t];(i[n]===s||Object.is(i[n],s))&&(Object.hasOwn(r,n)?R.x(a,n,r[n]):delete a[n])}return t.setContext(h.WQ(t.context,j.iL,a)),e1})}))},aW={"~effect/Logger":{_Message:y.D_,_Output:y.D_},pipe(){return(0,E.tT)(this,arguments)}},aJ=e=>{let t=Object.create(aW);return t.log=e,t},aY=(e,t)=>{let r=e[0].replace(/[\s="]/g,"_");return`${r}=${t-e[1]}ms`},aX=e=>(...t)=>{let r;for(let e=0,n=t.length;e<n;e++){let n=t[e];(0,A.Aj)(n)&&(r?t.splice(e,1):t=t.slice(0,e).concat(t.slice(e+1)),r=r?(0,A.b5)(r.reasons.concat(n.reasons)):n,e--)}return void 0===r&&(r=A.DH),(0,A.R6)(n=>{let i=e??n.cache.logLevel;if(aF(n.cache.minimumLogLevel,i))return e1;let a=n.getRef(af),s=n.getRef(aB);if(s.size>0){let e=new Date(a.currentTimeMillisUnsafe());for(let a of s)a.log({cause:r,fiber:n,date:e,logLevel:i,message:t})}return e1})},aq=aJ(({cause:e,date:t,fiber:r,logLevel:n,message:i})=>{let a=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&a.push(em(e));let s=t.getTime(),o=r.getRef(j.d8),l="";for(let e of o)l+=` ${aY(e,s)}`;let d=r.getRef(j.iL);Object.keys(d).length>0&&a.push(d);let c=r.getRef(aD);(r.getRef(aL)?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")}] ${n.toUpperCase()} (#${r.id})${l}:`,...a)}),aG=aJ(({cause:e,fiber:t,logLevel:r,message:n})=>{let i=t.getRef(af),a=t.getRef(j.iL),s=t.cache.span;if(void 0===s||"ExternalSpan"===s._tag)return;let o={};for(let[e,t]of Object.entries(a))R.x(o,e,t);o["effect.fiberId"]=t.id,o["effect.logLevel"]=r.toUpperCase(),e.reasons.length>0&&(o["effect.cause"]=em(e)),s.event((0,S.ZK)(Array.isArray(n)&&1===n.length?n[0]:n),i.currentTimeNanosUnsafe(),o)}),aV=eF(void 0),aH=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>nz(e,e=>(0,A.R6)(r=>(aK(r,e,t?.defectsOnly),e1)))),aK=(e,t,r)=>{let n=e.getRef(j.oQ);if(0===n.size||r&&!G(t))return;let i={cause:t,fiber:e,timestamp:e.getRef(af).currentTimeNanosUnsafe()};n.forEach(e=>e.report(i))}},5844(e,t,r){let n=new WeakSet;r.d(t,{},{J3:n,Xp:e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;e instanceof Error&&t.delete("stack");let r=Object.getPrototypeOf(e),n=r;for(;null!==n&&n!==Object.prototype;){let e=Reflect.ownKeys(n);for(let r=0;r<e.length;r++)t.add(e[r]);n=Object.getPrototypeOf(n)}return t.has("constructor")&&"function"==typeof e.constructor&&r===e.constructor.prototype&&t.delete("constructor"),t},j:e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength)})},7258(e,t,r){r.d(t,{},{F:"effect/Metric/FiberRuntimeMetrics"})},7731(e,t,r){var n=r(3332),i=r(1958),a=r(5033),s=r(3952),o=r(4233),l=r(6481),d=r(2449);let c="~effect/Option",u={[c]:{_A:e=>e},...d.fU,[Symbol.iterator](){return new l.B(this)}},f=Object.defineProperty(Object.assign(Object.create(u),{_tag:"Some",_op:"Some",[n.HR](e){return m(e)&&y(e)&&n.aI(this.value,e.value)},[a.HR](){return a.kg(a.tW(this._tag))(a.tW(this.value))},toString(){return`some(${(0,i.GP)(this.value)})`},toJSON(){return{_id:"Option",_tag:this._tag,value:(0,s.aB)(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),p=a.tW("None"),h=Object.assign(Object.create(u),{_tag:"None",_op:"None",valueOrUndefined:void 0,[n.HR]:e=>m(e)&&g(e),[a.HR]:()=>p,toString:()=>"none()",toJSON(){return{_id:"Option",_tag:this._tag}}}),m=e=>(0,o.i5)(e,c),g=e=>"None"===e._tag,y=e=>"Some"===e._tag,v=Object.create(h),b=function(e){this.value=e};b.prototype=f,r.d(t,{},{$I:g,Ru:y,dv:v,oL:m,zN:e=>new b(e)})},2275(e,t,r){function n(e,t,r){"__proto__"===t?Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}):e[t]=r}function i(e,t){for(let r of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,r)&&n(e,r,t[r])}r.d(t,{x:()=>n,z:()=>i})},6712(e,t,r){var n=r(1179),i=r(1594);let a=n.Or("effect/ErrorReporter/CurrentErrorReporters",{defaultValue:()=>new Set}),s=n.Or("effect/References/CurrentStackFrame",{fiberCached:!0,defaultValue:i.MN}),o=n.Or("effect/References/TracerEnabled",{fiberCached:!0,defaultValue:i.ue}),l=n.Or("effect/References/TracerTimingEnabled",{defaultValue:i.ue}),d=n.Or("effect/References/TracerSpanAnnotations",{defaultValue:()=>({})}),c=n.Or("effect/References/TracerSpanLinks",{defaultValue:()=>[]}),u=n.Or("effect/References/CurrentLogAnnotations",{defaultValue:()=>({})}),f=n.Or("effect/References/CurrentLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),p=n.Or("effect/References/MinimumLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),h=n.Or("effect/References/UnhandledLogLevel",{defaultValue:()=>"Error"}),m=n.Or("effect/References/CurrentLogSpans",{defaultValue:()=>[]});r.d(t,{},{Gl:f,aG:h,ce:d,d8:m,iL:u,ls:c,nU:l,oQ:a,rf:o,vA:s,zQ:p})},2563(e,t,r){var n=r(3332),i=r(1958),a=r(1594),s=r(5033),o=r(3952),l=r(4233),d=r(6481),c=r(2449),u=r(7731);let f="~effect/Result",p={[f]:{_A:e=>e,_E:e=>e},...c.fU,[Symbol.iterator](){return new d.B(this)}},h=Object.assign(Object.create(p),{_tag:"Success",_op:"Success",[n.HR](e){return g(e)&&v(e)&&n.aI(this.success,e.success)},[s.HR](){return s.kg(s.tW(this._tag))(s.tW(this.success))},toString(){return`success(${(0,i.GP)(this.success)})`},toJSON(){return{_id:"Result",_tag:this._tag,value:(0,o.aB)(this.success)}}}),m=Object.assign(Object.create(p),{_tag:"Failure",_op:"Failure",[n.HR](e){return g(e)&&y(e)&&n.aI(this.failure,e.failure)},[s.HR](){return s.kg(s.tW(this._tag))(s.tW(this.failure))},toString(){return`failure(${(0,i.GP)(this.failure)})`},toJSON(){return{_id:"Result",_tag:this._tag,failure:(0,o.aB)(this.failure)}}}),g=e=>(0,l.i5)(e,f),y=e=>"Failure"===e._tag,v=e=>"Success"===e._tag,b=function(e){this.failure=e};b.prototype=m;let _=e=>new b(e),x=function(e){this.success=e};x.prototype=h;let w=e=>new x(e),k=(0,a.XY)(2,(e,t)=>u.$I(e)?_(t()):w(e.value));r.d(t,{},{L8:e=>v(e)?u.dv:u.zN(e.failure),N6:y,Oz:e=>y(e)?u.dv:u.zN(e.success),Py:w,aI:g,fJ:_,oJ:v,sV:k})},2840(e,t,r){var n=r(1594);function i(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function a(e){return t=>i(t)?.[e]}let s="~structural",o="~identifier",l="~sentinels",d=a("identifier"),c=a(o),u=a("title"),f=a("description"),p=(0,n.Bj)(e=>{let t=i(e)?.identifier;return"string"==typeof t?t:e.getExpected(p)}),h=new Set([l,s,"representation","arbitraryConstraint","toJsonSchema","toCode","toEquivalence","toFormatter","toCodec","toCodecJson","toCodecStringTree","toCodecIso","toCodecArbitrary"]);r.d(t,{hd:()=>i,ip:()=>a},{C3:s,CD:c,DQ:u,I_:l,KE:d,L1:["title","description","default","examples","readOnly","writeOnly","format","contentEncoding","contentMediaType","contentSchema"],Pk:f,R4:o,UI:h,bo:p,py:"~constructor"})},8253(e,t,r){var n=r(719),i=r(7086);function a(e){let t;for(let r of e.reasons){if(!n.lC(r)||!i.gh(r.error))return;t??=r.error}return t}function s(e,t){let r=a(e);if(void 0===r)throw Error(t,{cause:e});return r}r.d(t,{R:()=>a,q:()=>s})},587(e,t,r){var n=r(6526),i=r(1587);let a=Symbol(),s=n.Py,o=s(a),l=s(a);r.d(t,{},{LO:a,Py:s,Rr:l,e8:e=>"None"===e._tag?o:s(e.value),r2:o,zL:e=>e===a?i.none():i.some(e)})},5340(e,t,r){let n,i=void 0===(n=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"))?Object.isExtensible(Error):Object.hasOwn(n,"writable")?!0===n.writable:void 0!==n.set;r.d(t,{},{ft:e=>{i&&(Error.stackTraceLimit=e)},jt:()=>Error.stackTraceLimit})},8689(e,t,r){let n,i,a,s,o;function l(e){let t=e.length;for(;--t>=0;)e[t]=0}let d=573,c=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),u=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),f=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),p=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),h=Array(576);l(h);let m=Array(60);l(m);let g=Array(512);l(g);let y=Array(256);l(y);let v=Array(29);l(v);let b=Array(30);function _(e,t,r,n,i){this.static_tree=e,this.extra_bits=t,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=e&&e.length}function x(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}l(b);let w=e=>e<256?g[e]:g[256+(e>>>7)],k=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},S=(e,t,r)=>{e.bi_valid>16-r?(e.bi_buf|=t<<e.bi_valid&65535,k(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=r-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r)},I=(e,t,r)=>{S(e,r[2*t],r[2*t+1])},$=(e,t)=>{let r=0;do r|=1&e,e>>>=1,r<<=1;while(--t>0)return r>>>1},E=(e,t,r)=>{let n,i,a=Array(16),s=0;for(n=1;n<=15;n++)a[n]=s=s+r[n-1]<<1;for(i=0;i<=t;i++){let t=e[2*i+1];0!==t&&(e[2*i]=$(a[t]++,t))}},O=e=>{let t;for(t=0;t<286;t++)e.dyn_ltree[2*t]=0;for(t=0;t<30;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0},C=e=>{e.bi_valid>8?k(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},T=(e,t,r,n)=>{let i=2*t,a=2*r;return e[i]<e[a]||e[i]===e[a]&&n[t]<=n[r]},M=(e,t,r)=>{let n=e.heap[r],i=r<<1;for(;i<=e.heap_len&&(i<e.heap_len&&T(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!T(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n},A=(e,t,r)=>{let n,i,a,s,o=0;if(0!==e.last_lit)do n=e.pending_buf[e.d_buf+2*o]<<8|e.pending_buf[e.d_buf+2*o+1],i=e.pending_buf[e.l_buf+o],o++,0===n?I(e,i,t):(I(e,(a=y[i])+256+1,t),0!==(s=c[a])&&S(e,i-=v[a],s),I(e,a=w(--n),r),0!==(s=u[a])&&S(e,n-=b[a],s));while(o<e.last_lit)I(e,256,t)},N=(e,t)=>{let r,n,i,a=t.dyn_tree,s=t.stat_desc.static_tree,o=t.stat_desc.has_stree,l=t.stat_desc.elems,c=-1;for(e.heap_len=0,e.heap_max=d,r=0;r<l;r++)0!==a[2*r]?(e.heap[++e.heap_len]=c=r,e.depth[r]=0):a[2*r+1]=0;for(;e.heap_len<2;)a[2*(i=e.heap[++e.heap_len]=c<2?++c:0)]=1,e.depth[i]=0,e.opt_len--,o&&(e.static_len-=s[2*i+1]);for(t.max_code=c,r=e.heap_len>>1;r>=1;r--)M(e,a,r);i=l;do r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],M(e,a,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,a[2*i]=a[2*r]+a[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,a[2*r+1]=a[2*n+1]=i,e.heap[1]=i++,M(e,a,1);while(e.heap_len>=2)e.heap[--e.heap_max]=e.heap[1],((e,t)=>{let r,n,i,a,s,o,l=t.dyn_tree,c=t.max_code,u=t.stat_desc.static_tree,f=t.stat_desc.has_stree,p=t.stat_desc.extra_bits,h=t.stat_desc.extra_base,m=t.stat_desc.max_length,g=0;for(a=0;a<=15;a++)e.bl_count[a]=0;for(l[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<d;r++)(a=l[2*l[2*(n=e.heap[r])+1]+1]+1)>m&&(a=m,g++),l[2*n+1]=a,!(n>c)&&(e.bl_count[a]++,s=0,n>=h&&(s=p[n-h]),o=l[2*n],e.opt_len+=o*(a+s),f&&(e.static_len+=o*(u[2*n+1]+s)));if(0!==g){do{for(a=m-1;0===e.bl_count[a];)a--;e.bl_count[a]--,e.bl_count[a+1]+=2,e.bl_count[m]--,g-=2}while(g>0)for(a=m;0!==a;a--)for(n=e.bl_count[a];0!==n;)!((i=e.heap[--r])>c)&&(l[2*i+1]!==a&&(e.opt_len+=(a-l[2*i+1])*l[2*i],l[2*i+1]=a),n--)}})(e,t),E(a,c,e.bl_count)},P=(e,t,r)=>{let n,i,a=-1,s=t[1],o=0,l=7,d=4;for(0===s&&(l=138,d=3),t[(r+1)*2+1]=65535,n=0;n<=r;n++)i=s,s=t[(n+1)*2+1],++o<l&&i===s||(o<d?e.bl_tree[2*i]+=o:0!==i?(i!==a&&e.bl_tree[2*i]++,e.bl_tree[32]++):o<=10?e.bl_tree[34]++:e.bl_tree[36]++,o=0,a=i,0===s?(l=138,d=3):i===s?(l=6,d=3):(l=7,d=4))},R=(e,t,r)=>{let n,i,a=-1,s=t[1],o=0,l=7,d=4;for(0===s&&(l=138,d=3),n=0;n<=r;n++)if(i=s,s=t[(n+1)*2+1],!(++o<l)||i!==s){if(o<d)do I(e,i,e.bl_tree);while(0!=--o)else 0!==i?(i!==a&&(I(e,i,e.bl_tree),o--),I(e,16,e.bl_tree),S(e,o-3,2)):o<=10?(I(e,17,e.bl_tree),S(e,o-3,3)):(I(e,18,e.bl_tree),S(e,o-11,7));o=0,a=i,0===s?(l=138,d=3):i===s?(l=6,d=3):(l=7,d=4)}},j=!1,D=(e,t,r,n)=>{S(e,0+ +!!n,3),C(e),k(e,r),k(e,~r),e.pending_buf.set(e.window.subarray(t,t+r),e.pending),e.pending+=r};var U={_tr_init:e=>{j||((()=>{let e,t,r,s,o,l=Array(16);for(s=0,r=0;s<28;s++)for(v[s]=r,e=0;e<1<<c[s];e++)y[r++]=s;for(y[r-1]=s,o=0,s=0;s<16;s++)for(b[s]=o,e=0;e<1<<u[s];e++)g[o++]=s;for(o>>=7;s<30;s++)for(b[s]=o<<7,e=0;e<1<<u[s]-7;e++)g[256+o++]=s;for(t=0;t<=15;t++)l[t]=0;for(e=0;e<=143;)h[2*e+1]=8,e++,l[8]++;for(;e<=255;)h[2*e+1]=9,e++,l[9]++;for(;e<=279;)h[2*e+1]=7,e++,l[7]++;for(;e<=287;)h[2*e+1]=8,e++,l[8]++;for(E(h,287,l),e=0;e<30;e++)m[2*e+1]=5,m[2*e]=$(e,5);n=new _(h,c,257,286,15),i=new _(m,u,0,30,15),a=new _([],f,0,19,7)})(),j=!0),e.l_desc=new x(e.dyn_ltree,n),e.d_desc=new x(e.dyn_dtree,i),e.bl_desc=new x(e.bl_tree,a),e.bi_buf=0,e.bi_valid=0,O(e)},_tr_stored_block:D,_tr_flush_block:(e,t,r,n)=>{let i,a,s=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,r=0xf3ffc07f;for(t=0;t<=31;t++,r>>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<256;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),N(e,e.l_desc),N(e,e.d_desc),s=(e=>{let t;for(P(e,e.dyn_ltree,e.l_desc.max_code),P(e,e.dyn_dtree,e.d_desc.max_code),N(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*p[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),i=e.opt_len+3+7>>>3,(a=e.static_len+3+7>>>3)<=i&&(i=a)):i=a=r+5,r+4<=i&&-1!==t?D(e,t,r,n):4===e.strategy||a===i?(S(e,2+ +!!n,3),A(e,h,m)):(S(e,4+ +!!n,3),((e,t,r,n)=>{let i;for(S(e,t-257,5),S(e,r-1,5),S(e,n-4,4),i=0;i<n;i++)S(e,e.bl_tree[2*p[i]+1],3);R(e,e.dyn_ltree,t-1),R(e,e.dyn_dtree,r-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,s+1),A(e,e.dyn_ltree,e.dyn_dtree)),O(e),n&&C(e)},_tr_tally:(e,t,r)=>(e.pending_buf[e.d_buf+2*e.last_lit]=t>>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&r,e.last_lit++,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[(y[r]+256+1)*2]++,e.dyn_dtree[2*w(t)]++),e.last_lit===e.lit_bufsize-1),_tr_align:e=>{S(e,2,3),I(e,256,h),16===e.bi_valid?(k(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}},F=(e,t,r,n)=>{let i=65535&e,a=e>>>16&65535,s=0;for(;0!==r;){s=r>2e3?2e3:r,r-=s;do a=a+(i=i+t[n++]|0)|0;while(--s)i%=65521,a%=65521}return i|a<<16};let B=new Uint32Array((()=>{let e,t=[];for(var r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?0xedb88320^e>>>1:e>>>1;t[r]=e}return t})());var L=(e,t,r,n)=>{let i=n+r;e^=-1;for(let r=n;r<i;r++)e=e>>>8^B[(e^t[r])&255];return -1^e},z={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},W={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};let{_tr_init:J,_tr_stored_block:Y,_tr_flush_block:X,_tr_tally:q,_tr_align:G}=U,{Z_NO_FLUSH:V,Z_PARTIAL_FLUSH:H,Z_FULL_FLUSH:K,Z_FINISH:Q,Z_BLOCK:Z,Z_OK:ee,Z_STREAM_END:et,Z_STREAM_ERROR:er,Z_DATA_ERROR:en,Z_BUF_ERROR:ei,Z_DEFAULT_COMPRESSION:ea,Z_FILTERED:es,Z_HUFFMAN_ONLY:eo,Z_RLE:el,Z_FIXED:ed,Z_DEFAULT_STRATEGY:ec,Z_UNKNOWN:eu,Z_DEFLATED:ef}=W,ep=573,eh=(e,t)=>(e.msg=z[t],t),em=e=>(e<<1)-9*(e>4),eg=e=>{let t=e.length;for(;--t>=0;)e[t]=0},ey=(e,t,r)=>(t<<e.hash_shift^r)&e.hash_mask,ev=e=>{let t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),0!==r&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+r),e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0))},eb=(e,t)=>{X(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ev(e.strm)},e_=(e,t)=>{e.pending_buf[e.pending++]=t},ex=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},ew=(e,t,r,n)=>{let i=e.avail_in;return(i>n&&(i=n),0===i)?0:(e.avail_in-=i,t.set(e.input.subarray(e.next_in,e.next_in+i),r),1===e.state.wrap?e.adler=F(e.adler,t,i,r):2===e.state.wrap&&(e.adler=L(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)},ek=(e,t)=>{let r,n,i=e.max_chain_length,a=e.strstart,s=e.prev_length,o=e.nice_match,l=e.strstart>e.w_size-262?e.strstart-(e.w_size-262):0,d=e.window,c=e.w_mask,u=e.prev,f=e.strstart+258,p=d[a+s-1],h=d[a+s];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(d[(r=t)+s]!==h||d[r+s-1]!==p||d[r]!==d[a]||d[++r]!==d[a+1])continue;a+=2,r++;do;while(d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&a<f)if(n=258-(f-a),a=f-258,n>s){if(e.match_start=t,s=n,n>=o)break;p=d[a+s-1],h=d[a+s]}}while((t=u[t&c])>l&&0!=--i)return s<=e.lookahead?s:e.lookahead},eS=e=>{let t,r,n,i,a,s=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=s+(s-262)){e.window.set(e.window.subarray(s,s+s),0),e.match_start-=s,e.strstart-=s,e.block_start-=s,t=r=e.hash_size;do n=e.head[--t],e.head[t]=n>=s?n-s:0;while(--r)t=r=s;do n=e.prev[--t],e.prev[t]=n>=s?n-s:0;while(--r)i+=s}if(0===e.strm.avail_in)break;if(r=ew(e.strm,e.window,e.strstart+e.lookahead,i),e.lookahead+=r,e.lookahead+e.insert>=3)for(a=e.strstart-e.insert,e.ins_h=e.window[a],e.ins_h=ey(e,e.ins_h,e.window[a+1]);e.insert&&(e.ins_h=ey(e,e.ins_h,e.window[a+3-1]),e.prev[a&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=a,a++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<262&&0!==e.strm.avail_in)},eI=(e,t)=>{let r,n;for(;;){if(e.lookahead<262){if(eS(e),e.lookahead<262&&t===V)return 1;if(0===e.lookahead)break}if(r=0,e.lookahead>=3&&(e.ins_h=ey(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==r&&e.strstart-r<=e.w_size-262&&(e.match_length=ek(e,r)),e.match_length>=3)if(n=q(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do e.strstart++,e.ins_h=ey(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(0!=--e.match_length)e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=ey(e,e.ins_h,e.window[e.strstart+1]);else n=q(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(eb(e,!1),0===e.strm.avail_out))return 1}return(e.insert=e.strstart<2?e.strstart:2,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(eb(e,!1),0===e.strm.avail_out)?1:2},e$=(e,t)=>{let r,n,i;for(;;){if(e.lookahead<262){if(eS(e),e.lookahead<262&&t===V)return 1;if(0===e.lookahead)break}if(r=0,e.lookahead>=3&&(e.ins_h=ey(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==r&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-262&&(e.match_length=ek(e,r),e.match_length<=5&&(e.strategy===es||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-3,n=q(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=ey(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(0!=--e.prev_length)if(e.match_available=0,e.match_length=2,e.strstart++,n&&(eb(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if((n=q(e,0,e.window[e.strstart-1]))&&eb(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return(e.match_available&&(n=q(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(eb(e,!1),0===e.strm.avail_out)?1:2};function eE(e,t,r,n,i){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=n,this.func=i}let eO=[new eE(0,0,0,0,(e,t)=>{let r=65535;for(65535>e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(eS(e),0===e.lookahead&&t===V)return 1;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;let n=e.block_start+r;if((0===e.strstart||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,eb(e,!1),0===e.strm.avail_out)||e.strstart-e.block_start>=e.w_size-262&&(eb(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:(e.strstart>e.block_start&&(eb(e,!1),e.strm.avail_out),1)}),new eE(4,4,8,4,eI),new eE(4,5,16,8,eI),new eE(4,6,32,32,eI),new eE(4,4,16,16,e$),new eE(8,16,32,32,e$),new eE(8,16,128,128,e$),new eE(8,32,128,256,e$),new eE(32,128,258,1024,e$),new eE(32,258,258,4096,e$)];function eC(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ef,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(2*ep),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),eg(this.dyn_ltree),eg(this.dyn_dtree),eg(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),eg(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),eg(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var eT=(e,t)=>{let r,n;if(!e||!e.state||t>Z||t<0)return e?eh(e,er):er;let i=e.state;if(!e.output||!e.input&&0!==e.avail_in||666===i.status&&t!==Q)return eh(e,0===e.avail_out?ei:er);i.strm=e;let a=i.last_flush;if(i.last_flush=t,42===i.status)if(2===i.wrap)e.adler=0,e_(i,31),e_(i,139),e_(i,8),i.gzhead?(e_(i,+!!i.gzhead.text+2*!!i.gzhead.hcrc+4*!!i.gzhead.extra+8*!!i.gzhead.name+16*!!i.gzhead.comment),e_(i,255&i.gzhead.time),e_(i,i.gzhead.time>>8&255),e_(i,i.gzhead.time>>16&255),e_(i,i.gzhead.time>>24&255),e_(i,9===i.level?2:4*(i.strategy>=eo||i.level<2)),e_(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(e_(i,255&i.gzhead.extra.length),e_(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=L(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(e_(i,0),e_(i,0),e_(i,0),e_(i,0),e_(i,0),e_(i,9===i.level?2:4*(i.strategy>=eo||i.level<2)),e_(i,3),i.status=113);else{let t=ef+(i.w_bits-8<<4)<<8;t|=(i.strategy>=eo||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(t|=32),t+=31-t%31,i.status=113,ex(i,t),0!==i.strstart&&(ex(i,e.adler>>>16),ex(i,65535&e.adler)),e.adler=1}if(69===i.status)if(i.gzhead.extra){for(r=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),ev(e),r=i.pending,i.pending!==i.pending_buf_size));)e_(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),ev(e),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindex<i.gzhead.name.length?255&i.gzhead.name.charCodeAt(i.gzindex++):0,e_(i,n)}while(0!==n)i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),ev(e),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindex<i.gzhead.comment.length?255&i.gzhead.comment.charCodeAt(i.gzindex++):0,e_(i,n)}while(0!==n)i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.status=103)}else i.status=103;if(103===i.status&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&ev(e),i.pending+2<=i.pending_buf_size&&(e_(i,255&e.adler),e_(i,e.adler>>8&255),e.adler=0,i.status=113)):i.status=113),0!==i.pending){if(ev(e),0===e.avail_out)return i.last_flush=-1,ee}else if(0===e.avail_in&&em(t)<=em(a)&&t!==Q)return eh(e,ei);if(666===i.status&&0!==e.avail_in)return eh(e,ei);if(0!==e.avail_in||0!==i.lookahead||t!==V&&666!==i.status){let r=i.strategy===eo?((e,t)=>{let r;for(;;){if(0===e.lookahead&&(eS(e),0===e.lookahead)){if(t===V)return 1;break}if(e.match_length=0,r=q(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(eb(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(eb(e,!1),0===e.strm.avail_out)?1:2})(i,t):i.strategy===el?((e,t)=>{let r,n,i,a,s=e.window;for(;;){if(e.lookahead<=258){if(eS(e),e.lookahead<=258&&t===V)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(n=s[i=e.strstart-1])===s[++i]&&n===s[++i]&&n===s[++i]){a=e.strstart+258;do;while(n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&i<a)e.match_length=258-(a-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(r=q(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=q(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(eb(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(eb(e,!1),0===e.strm.avail_out)?1:2})(i,t):eO[i.level].func(i,t);if((3===r||4===r)&&(i.status=666),1===r||3===r)return 0===e.avail_out&&(i.last_flush=-1),ee;if(2===r&&(t===H?G(i):t!==Z&&(Y(i,0,0,!1),t===K&&(eg(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),ev(e),0===e.avail_out))return i.last_flush=-1,ee}return t!==Q?ee:i.wrap<=0?et:(2===i.wrap?(e_(i,255&e.adler),e_(i,e.adler>>8&255),e_(i,e.adler>>16&255),e_(i,e.adler>>24&255),e_(i,255&e.total_in),e_(i,e.total_in>>8&255),e_(i,e.total_in>>16&255),e_(i,e.total_in>>24&255)):(ex(i,e.adler>>>16),ex(i,65535&e.adler)),ev(e),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?ee:et)},eM=e=>{if(!e||!e.state)return er;let t=e.state.status;return 42!==t&&69!==t&&73!==t&&91!==t&&103!==t&&113!==t&&666!==t?eh(e,er):(e.state=null,113===t?eh(e,en):ee)};let eA=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var eN=function(e){let t=Array.prototype.slice.call(arguments,1);for(;t.length;){let r=t.shift();if(r){if("object"!=typeof r)throw TypeError(r+"must be non-object");for(let t in r)eA(r,t)&&(e[t]=r[t])}}return e},eP=e=>{let t=0;for(let r=0,n=e.length;r<n;r++)t+=e[r].length;let r=new Uint8Array(t);for(let t=0,n=0,i=e.length;t<i;t++){let i=e[t];r.set(i,n),n+=i.length}return r};let eR=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){eR=!1}let ej=new Uint8Array(256);for(let e=0;e<256;e++)ej[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;ej[254]=ej[254]=1;var eD=e=>{let t,r,n,i,a,s=e.length,o=0;for(i=0;i<s;i++)(64512&(r=e.charCodeAt(i)))==55296&&i+1<s&&(64512&(n=e.charCodeAt(i+1)))==56320&&(r=65536+(r-55296<<10)+(n-56320),i++),o+=r<128?1:r<2048?2:r<65536?3:4;for(t=new Uint8Array(o),a=0,i=0;a<o;i++)(64512&(r=e.charCodeAt(i)))==55296&&i+1<s&&(64512&(n=e.charCodeAt(i+1)))==56320&&(r=65536+(r-55296<<10)+(n-56320),i++),r<128?t[a++]=r:(r<2048?t[a++]=192|r>>>6:(r<65536?t[a++]=224|r>>>12:(t[a++]=240|r>>>18,t[a++]=128|r>>>12&63),t[a++]=128|r>>>6&63),t[a++]=128|63&r);return t},eU=(e,t)=>{let r,n,i=t||e.length,a=Array(2*i);for(n=0,r=0;r<i;){let t=e[r++];if(t<128){a[n++]=t;continue}let s=ej[t];if(s>4){a[n++]=65533,r+=s-1;continue}for(t&=2===s?31:3===s?15:7;s>1&&r<i;)t=t<<6|63&e[r++],s--;if(s>1){a[n++]=65533;continue}t<65536?a[n++]=t:(t-=65536,a[n++]=55296|t>>10&1023,a[n++]=56320|1023&t)}var s=n;if(s<65534&&a.subarray&&eR)return String.fromCharCode.apply(null,a.length===s?a:a.subarray(0,s));let o="";for(let e=0;e<s;e++)o+=String.fromCharCode(a[e]);return o},eF=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let r=t-1;for(;r>=0&&(192&e[r])==128;)r--;return r<0||0===r?t:r+ej[e[r]]>t?r:t},eB=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};let eL=Object.prototype.toString,{Z_NO_FLUSH:ez,Z_SYNC_FLUSH:eW,Z_FULL_FLUSH:eJ,Z_FINISH:eY,Z_OK:eX,Z_STREAM_END:eq,Z_DEFAULT_COMPRESSION:eG,Z_DEFAULT_STRATEGY:eV,Z_DEFLATED:eH}=W;function eK(e){let t,r;this.options=eN({level:eG,method:eH,chunkSize:16384,windowBits:15,memLevel:8,strategy:eV},e||{});let n=this.options;n.raw&&n.windowBits>0?n.windowBits=-n.windowBits:n.gzip&&n.windowBits>0&&n.windowBits<16&&(n.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new eB,this.strm.avail_out=0;let i=((e,t,r,n,i,a)=>{var s,o;let l;if(!e)return er;let d=1;if(t===ea&&(t=6),n<0?(d=0,n=-n):n>15&&(d=2,n-=16),i<1||i>9||r!==ef||n<8||n>15||t<0||t>9||a<0||a>ed)return eh(e,er);8===n&&(n=9);let c=new eC;return e.state=c,c.strm=e,c.wrap=d,c.gzhead=null,c.w_bits=n,c.w_size=1<<c.w_bits,c.w_mask=c.w_size-1,c.hash_bits=i+7,c.hash_size=1<<c.hash_bits,c.hash_mask=c.hash_size-1,c.hash_shift=~~((c.hash_bits+3-1)/3),c.window=new Uint8Array(2*c.w_size),c.head=new Uint16Array(c.hash_size),c.prev=new Uint16Array(c.w_size),c.lit_bufsize=1<<i+6,c.pending_buf_size=4*c.lit_bufsize,c.pending_buf=new Uint8Array(c.pending_buf_size),c.d_buf=+c.lit_bufsize,c.l_buf=3*c.lit_bufsize,c.level=t,c.strategy=a,c.method=r,(l=(e=>{if(!e||!e.state)return eh(e,er);e.total_in=e.total_out=0,e.data_type=eu;let t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?42:113,e.adler=+(2!==t.wrap),t.last_flush=V,J(t),ee})(s=e))===ee&&((o=s.state).window_size=2*o.w_size,eg(o.head),o.max_lazy_match=eO[o.level].max_lazy,o.good_match=eO[o.level].good_length,o.nice_match=eO[o.level].nice_length,o.max_chain_length=eO[o.level].max_chain,o.strstart=0,o.block_start=0,o.lookahead=0,o.insert=0,o.match_length=o.prev_length=2,o.match_available=0,o.ins_h=0),l})(this.strm,n.level,n.method,n.windowBits,n.memLevel,n.strategy);if(i!==eX)throw Error(z[i]);if(n.header&&(t=this.strm,r=n.header,t&&t.state&&2===t.state.wrap&&(t.state.gzhead=r)),n.dictionary){let e;if(e="string"==typeof n.dictionary?eD(n.dictionary):"[object ArrayBuffer]"===eL.call(n.dictionary)?new Uint8Array(n.dictionary):n.dictionary,(i=((e,t)=>{let r=t.length;if(!e||!e.state)return er;let n=e.state,i=n.wrap;if(2===i||1===i&&42!==n.status||n.lookahead)return er;if(1===i&&(e.adler=F(e.adler,t,r,0)),n.wrap=0,r>=n.w_size){0===i&&(eg(n.head),n.strstart=0,n.block_start=0,n.insert=0);let e=new Uint8Array(n.w_size);e.set(t.subarray(r-n.w_size,r),0),t=e,r=n.w_size}let a=e.avail_in,s=e.next_in,o=e.input;for(e.avail_in=r,e.next_in=0,e.input=t,eS(n);n.lookahead>=3;){let e=n.strstart,t=n.lookahead-2;do n.ins_h=ey(n,n.ins_h,n.window[e+3-1]),n.prev[e&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=e,e++;while(--t)n.strstart=e,n.lookahead=2,eS(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,e.next_in=s,e.input=o,e.avail_in=a,n.wrap=i,ee})(this.strm,e))!==eX)throw Error(z[i]);this._dict_set=!0}}function eQ(e,t){let r=new eK(t);if(r.push(e,!0),r.err)throw r.msg||z[r.err];return r.result}eK.prototype.push=function(e,t){let r,n,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(n=t===~~t?t:!0===t?eY:ez,"string"==typeof e?i.input=eD(e):"[object ArrayBuffer]"===eL.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(n===eW||n===eJ)&&i.avail_out<=6){this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;continue}if((r=eT(i,n))===eq)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=eM(this.strm),this.onEnd(r),this.ended=!0,r===eX;if(0===i.avail_out){this.onData(i.output);continue}if(n>0&&i.next_out>0){this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;continue}if(0===i.avail_in)break}return!0},eK.prototype.onData=function(e){this.chunks.push(e)},eK.prototype.onEnd=function(e){e===eX&&(this.result=eP(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var eZ=function(e,t){let r,n,i,a,s,o,l,d,c,u,f,p,h,m,g,y,v,b,_,x,w,k,S,I,$=e.state;r=e.next_in,S=e.input,n=r+(e.avail_in-5),i=e.next_out,I=e.output,a=i-(t-e.avail_out),s=i+(e.avail_out-257),o=$.dmax,l=$.wsize,d=$.whave,c=$.wnext,u=$.window,f=$.hold,p=$.bits,h=$.lencode,m=$.distcode,g=(1<<$.lenbits)-1,y=(1<<$.distbits)-1;t:do for(p<15&&(f+=S[r++]<<p,p+=8,f+=S[r++]<<p,p+=8),v=h[f&g];;){if(f>>>=b=v>>>24,p-=b,0==(b=v>>>16&255))I[i++]=65535&v;else if(16&b)for(_=65535&v,(b&=15)&&(p<b&&(f+=S[r++]<<p,p+=8),_+=f&(1<<b)-1,f>>>=b,p-=b),p<15&&(f+=S[r++]<<p,p+=8,f+=S[r++]<<p,p+=8),v=m[f&y];;){if(f>>>=b=v>>>24,p-=b,16&(b=v>>>16&255)){if(x=65535&v,p<(b&=15)&&(f+=S[r++]<<p,(p+=8)<b&&(f+=S[r++]<<p,p+=8)),(x+=f&(1<<b)-1)>o){e.msg="invalid distance too far back",$.mode=30;break t}if(f>>>=b,p-=b,x>(b=i-a)){if((b=x-b)>d&&$.sane){e.msg="invalid distance too far back",$.mode=30;break t}if(w=0,k=u,0===c){if(w+=l-b,b<_){_-=b;do I[i++]=u[w++];while(--b)w=i-x,k=I}}else if(c<b){if(w+=l+c-b,(b-=c)<_){_-=b;do I[i++]=u[w++];while(--b)if(w=0,c<_){_-=b=c;do I[i++]=u[w++];while(--b)w=i-x,k=I}}}else if(w+=c-b,b<_){_-=b;do I[i++]=u[w++];while(--b)w=i-x,k=I}for(;_>2;)I[i++]=k[w++],I[i++]=k[w++],I[i++]=k[w++],_-=3;_&&(I[i++]=k[w++],_>1&&(I[i++]=k[w++]))}else{w=i-x;do I[i++]=I[w++],I[i++]=I[w++],I[i++]=I[w++],_-=3;while(_>2)_&&(I[i++]=I[w++],_>1&&(I[i++]=I[w++]))}}else if((64&b)==0){v=m[(65535&v)+(f&(1<<b)-1)];continue}else{e.msg="invalid distance code",$.mode=30;break t}break}else if((64&b)==0){v=h[(65535&v)+(f&(1<<b)-1)];continue}else if(32&b){$.mode=12;break t}else{e.msg="invalid literal/length code",$.mode=30;break t}break}while(r<n&&i<s)r-=_=p>>3,p-=_<<3,f&=(1<<p)-1,e.next_in=r,e.next_out=i,e.avail_in=r<n?5+(n-r):5-(r-n),e.avail_out=i<s?257+(s-i):257-(i-s),$.hold=f,$.bits=p};let e0=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),e1=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),e2=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),e5=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var e3=(e,t,r,n,i,a,s,o)=>{let l,d,c,u,f,p,h,m,g,y=o.bits,v=0,b=0,_=0,x=0,w=0,k=0,S=0,I=0,$=0,E=0,O=null,C=0,T=new Uint16Array(16),M=new Uint16Array(16),A=null,N=0;for(v=0;v<=15;v++)T[v]=0;for(b=0;b<n;b++)T[t[r+b]]++;for(w=y,x=15;x>=1&&0===T[x];x--);if(w>x&&(w=x),0===x)return i[a++]=0x1400000,i[a++]=0x1400000,o.bits=1,0;for(_=1;_<x&&0===T[_];_++);for(w<_&&(w=_),I=1,v=1;v<=15;v++)if(I<<=1,(I-=T[v])<0)return -1;if(I>0&&(0===e||1!==x))return -1;for(M[1]=0,v=1;v<15;v++)M[v+1]=M[v]+T[v];for(b=0;b<n;b++)0!==t[r+b]&&(s[M[t[r+b]]++]=b);if(0===e?(O=A=s,p=19):1===e?(O=e0,C-=257,A=e1,N-=257,p=256):(O=e2,A=e5,p=-1),E=0,b=0,v=_,f=a,k=w,S=0,c=-1,u=($=1<<w)-1,1===e&&$>852||2===e&&$>592)return 1;for(;;){h=v-S,s[b]<p?(m=0,g=s[b]):s[b]>p?(m=A[N+s[b]],g=O[C+s[b]]):(m=96,g=0),l=1<<v-S,_=d=1<<k;do i[f+(E>>S)+(d-=l)]=h<<24|m<<16|g;while(0!==d)for(l=1<<v-1;E&l;)l>>=1;if(0!==l?(E&=l-1,E+=l):E=0,b++,0==--T[v]){if(v===x)break;v=t[r+s[b]]}if(v>w&&(E&u)!==c){for(0===S&&(S=w),f+=_,I=1<<(k=v-S);k+S<x&&!((I-=T[k+S])<=0);)k++,I<<=1;if($+=1<<k,1===e&&$>852||2===e&&$>592)return 1;i[c=E&u]=w<<24|k<<16|f-a}}return 0!==E&&(i[f+E]=v-S<<24|4194304),o.bits=w,0};let{Z_FINISH:e6,Z_BLOCK:e8,Z_TREES:e9,Z_OK:e4,Z_STREAM_END:e7,Z_NEED_DICT:te,Z_STREAM_ERROR:tt,Z_DATA_ERROR:tr,Z_MEM_ERROR:tn,Z_BUF_ERROR:ti,Z_DEFLATED:ta}=W,ts=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function to(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}let tl=e=>{if(!e||!e.state)return tt;let t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,(e=>{if(!e||!e.state)return tt;let t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,e4})(e)},td=!0,tc=e=>{if(td){s=new Int32Array(512),o=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(e3(1,e.lens,0,288,s,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;e3(2,e.lens,0,32,o,0,e.work,{bits:5}),td=!1}e.lencode=s,e.lenbits=9,e.distcode=o,e.distbits=5},tu=(e,t,r,n)=>{let i,a=e.state;return null===a.window&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new Uint8Array(a.wsize)),n>=a.wsize?(a.window.set(t.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(t.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(t.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0};var tf=(e,t)=>{let r,n,i,a,s,o,l,d,c,u,f,p,h,m,g,y,v,b,_,x,w,k,S,I,$=0,E=new Uint8Array(4),O=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return tt;12===(r=e.state).mode&&(r.mode=13),s=e.next_out,i=e.output,l=e.avail_out,a=e.next_in,n=e.input,o=e.avail_in,d=r.hold,c=r.bits,u=o,f=l,k=e4;r:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(2&r.wrap&&35615===d){r.check=0,E[0]=255&d,E[1]=d>>>8&255,r.check=L(r.check,E,2,0),d=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&d)<<8)+(d>>8))%31){e.msg="incorrect header check",r.mode=30;break}if((15&d)!==ta){e.msg="unknown compression method",r.mode=30;break}if(d>>>=4,c-=4,w=(15&d)+8,0===r.wbits)r.wbits=w;else if(w>r.wbits){e.msg="invalid window size",r.mode=30;break}r.dmax=1<<r.wbits,e.adler=r.check=1,r.mode=512&d?10:12,d=0,c=0;break;case 2:for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(r.flags=d,(255&r.flags)!==ta){e.msg="unknown compression method",r.mode=30;break}if(57344&r.flags){e.msg="unknown header flags set",r.mode=30;break}r.head&&(r.head.text=d>>8&1),512&r.flags&&(E[0]=255&d,E[1]=d>>>8&255,r.check=L(r.check,E,2,0)),d=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.head&&(r.head.time=d),512&r.flags&&(E[0]=255&d,E[1]=d>>>8&255,E[2]=d>>>16&255,E[3]=d>>>24&255,r.check=L(r.check,E,4,0)),d=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.head&&(r.head.xflags=255&d,r.head.os=d>>8),512&r.flags&&(E[0]=255&d,E[1]=d>>>8&255,r.check=L(r.check,E,2,0)),d=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.length=d,r.head&&(r.head.extra_len=d),512&r.flags&&(E[0]=255&d,E[1]=d>>>8&255,r.check=L(r.check,E,2,0)),d=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((p=r.length)>o&&(p=o),p&&(r.head&&(w=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+p),w)),512&r.flags&&(r.check=L(r.check,n,p,a)),o-=p,a+=p,r.length-=p),r.length))break r;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break r;p=0;do w=n[a+p++],r.head&&w&&r.length<65536&&(r.head.name+=String.fromCharCode(w));while(w&&p<o)if(512&r.flags&&(r.check=L(r.check,n,p,a)),o-=p,a+=p,w)break r}else r.head&&(r.head.name=null);r.length=0,r.mode=8;case 8:if(4096&r.flags){if(0===o)break r;p=0;do w=n[a+p++],r.head&&w&&r.length<65536&&(r.head.comment+=String.fromCharCode(w));while(w&&p<o)if(512&r.flags&&(r.check=L(r.check,n,p,a)),o-=p,a+=p,w)break r}else r.head&&(r.head.comment=null);r.mode=9;case 9:if(512&r.flags){for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(d!==(65535&r.check)){e.msg="header crc mismatch",r.mode=30;break}d=0,c=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;c<32;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}e.adler=r.check=ts(d),d=0,c=0,r.mode=11;case 11:if(0===r.havedict)return e.next_out=s,e.avail_out=l,e.next_in=a,e.avail_in=o,r.hold=d,r.bits=c,te;e.adler=r.check=1,r.mode=12;case 12:if(t===e8||t===e9)break r;case 13:if(r.last){d>>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}switch(r.last=1&d,c-=1,3&(d>>>=1)){case 0:r.mode=14;break;case 1:if(tc(r),r.mode=20,t===e9){d>>>=2,c-=2;break r}break;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30}d>>>=2,c-=2;break;case 14:for(d>>>=7&c,c-=7&c;c<32;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if((65535&d)!=(d>>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&d,d=0,c=0,r.mode=15,t===e9)break r;case 15:r.mode=16;case 16:if(p=r.length){if(p>o&&(p=o),p>l&&(p=l),0===p)break r;i.set(n.subarray(a,a+p),s),o-=p,a+=p,l-=p,s+=p,r.length-=p;break}r.mode=12;break;case 17:for(;c<14;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(r.nlen=(31&d)+257,c-=5,r.ndist=(31&(d>>>=5))+1,c-=5,r.ncode=(15&(d>>>=5))+4,d>>>=4,c-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=30;break}r.have=0,r.mode=18;case 18:for(;r.have<r.ncode;){for(;c<3;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.lens[O[r.have++]]=7&d,d>>>=3,c-=3}for(;r.have<19;)r.lens[O[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},k=e3(0,r.lens,0,19,r.lencode,0,r.work,S),r.lenbits=S.bits,k){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have<r.nlen+r.ndist;){for(;g=($=r.lencode[d&(1<<r.lenbits)-1])>>>24,y=$>>>16&255,v=65535&$,!(g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(v<16)d>>>=g,c-=g,r.lens[r.have++]=v;else{if(16===v){for(I=g+2;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(d>>>=g,c-=g,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}w=r.lens[r.have-1],p=3+(3&d),d>>>=2,c-=2}else if(17===v){for(I=g+3;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}d>>>=g,c-=g,w=0,p=3+(7&d),d>>>=3,c-=3}else{for(I=g+7;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}d>>>=g,c-=g,w=0,p=11+(127&d),d>>>=7,c-=7}if(r.have+p>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;p--;)r.lens[r.have++]=w}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,S={bits:r.lenbits},k=e3(1,r.lens,0,r.nlen,r.lencode,0,r.work,S),r.lenbits=S.bits,k){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,S={bits:r.distbits},k=e3(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,S),r.distbits=S.bits,k){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,t===e9)break r;case 20:r.mode=21;case 21:if(o>=6&&l>=258){e.next_out=s,e.avail_out=l,e.next_in=a,e.avail_in=o,r.hold=d,r.bits=c,eZ(e,f),s=e.next_out,i=e.output,l=e.avail_out,a=e.next_in,n=e.input,o=e.avail_in,d=r.hold,c=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=($=r.lencode[d&(1<<r.lenbits)-1])>>>24,y=$>>>16&255,v=65535&$,!(g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(y&&(240&y)==0){for(b=g,_=y,x=v;g=($=r.lencode[x+((d&(1<<b+_)-1)>>b)])>>>24,y=$>>>16&255,v=65535&$,!(b+g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}d>>>=b,c-=b,r.back+=b}if(d>>>=g,c-=g,r.back+=g,r.length=v,0===y){r.mode=26;break}if(32&y){r.back=-1,r.mode=12;break}if(64&y){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&y,r.mode=22;case 22:if(r.extra){for(I=r.extra;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.length+=d&(1<<r.extra)-1,d>>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;g=($=r.distcode[d&(1<<r.distbits)-1])>>>24,y=$>>>16&255,v=65535&$,!(g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if((240&y)==0){for(b=g,_=y,x=v;g=($=r.distcode[x+((d&(1<<b+_)-1)>>b)])>>>24,y=$>>>16&255,v=65535&$,!(b+g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}d>>>=b,c-=b,r.back+=b}if(d>>>=g,c-=g,r.back+=g,64&y){e.msg="invalid distance code",r.mode=30;break}r.offset=v,r.extra=15&y,r.mode=24;case 24:if(r.extra){for(I=r.extra;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.offset+=d&(1<<r.extra)-1,d>>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===l)break r;if(p=f-l,r.offset>p){if((p=r.offset-p)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}p>r.wnext?(p-=r.wnext,h=r.wsize-p):h=r.wnext-p,p>r.length&&(p=r.length),m=r.window}else m=i,h=s-r.offset,p=r.length;p>l&&(p=l),l-=p,r.length-=p;do i[s++]=m[h++];while(--p)0===r.length&&(r.mode=21);break;case 26:if(0===l)break r;i[s++]=r.length,l--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===o)break r;o--,d|=n[a++]<<c,c+=8}if(f-=l,e.total_out+=f,r.total+=f,f&&(e.adler=r.check=r.flags?L(r.check,i,f,s-f):F(r.check,i,f,s-f)),f=l,(r.flags?d:ts(d))!==r.check){e.msg="incorrect data check",r.mode=30;break}d=0,c=0}r.mode=28;case 28:if(r.wrap&&r.flags){for(;c<32;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(d!==(0|r.total)){e.msg="incorrect length check",r.mode=30;break}d=0,c=0}r.mode=29;case 29:k=e7;break r;case 30:k=tr;break r;case 31:return tn;default:return tt}return e.next_out=s,e.avail_out=l,e.next_in=a,e.avail_in=o,r.hold=d,r.bits=c,(r.wsize||f!==e.avail_out&&r.mode<30&&(r.mode<27||t!==e6))&&tu(e,e.output,e.next_out,f-e.avail_out),u-=e.avail_in,f-=e.avail_out,e.total_in+=u,e.total_out+=f,r.total+=f,r.wrap&&f&&(e.adler=r.check=r.flags?L(r.check,i,f,e.next_out-f):F(r.check,i,f,e.next_out-f)),e.data_type=r.bits+64*!!r.last+128*(12===r.mode)+256*(20===r.mode||15===r.mode),(0===u&&0===f||t===e6)&&k===e4&&(k=ti),k},tp=e=>{if(!e||!e.state)return tt;let t=e.state;return t.window&&(t.window=null),e.state=null,e4},th=(e,t)=>{let r,n=t.length;return e&&e.state&&(0===(r=e.state).wrap||11===r.mode)?11===r.mode&&F(1,t,n,0)!==r.check?tr:tu(e,t,n,n)?(r.mode=31,tn):(r.havedict=1,e4):tt},tm=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};let tg=Object.prototype.toString,{Z_NO_FLUSH:ty,Z_FINISH:tv,Z_OK:tb,Z_STREAM_END:t_,Z_NEED_DICT:tx,Z_STREAM_ERROR:tw,Z_DATA_ERROR:tk,Z_MEM_ERROR:tS}=W;function tI(e){this.options=eN({chunkSize:65536,windowBits:15,to:""},e||{});let t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(e&&e.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(15&t.windowBits)==0&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new eB,this.strm.avail_out=0;let r=((e,t)=>{if(!e)return tt;let r=new to;e.state=r,r.window=null;let n=((e,t)=>{let r;if(!e||!e.state)return tt;let n=e.state;return(t<0?(r=0,t=-t):(r=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?tt:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,tl(e))})(e,t);return n!==e4&&(e.state=null),n})(this.strm,t.windowBits);if(r!==tb||(this.header=new tm,((e,t)=>{if(!e||!e.state)return;let r=e.state;return(2&r.wrap)==0||(r.head=t,t.done=!1)})(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=eD(t.dictionary):"[object ArrayBuffer]"===tg.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw)&&(r=th(this.strm,t.dictionary))!==tb))throw Error(z[r])}function t$(e,t){let r=new tI(t);if(r.push(e),r.err)throw r.msg||z[r.err];return r.result}tI.prototype.push=function(e,t){let r,n,i,a=this.strm,s=this.options.chunkSize,o=this.options.dictionary;if(this.ended)return!1;for(n=t===~~t?t:!0===t?tv:ty,"[object ArrayBuffer]"===tg.call(e)?a.input=new Uint8Array(e):a.input=e,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(s),a.next_out=0,a.avail_out=s),(r=tf(a,n))===tx&&o&&((r=th(a,o))===tb?r=tf(a,n):r===tk&&(r=tx));a.avail_in>0&&r===t_&&a.state.wrap>0&&0!==e[a.next_in];)tl(a),r=tf(a,n);switch(r){case tw:case tk:case tx:case tS:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===t_))if("string"===this.options.to){let e=eF(a.output,a.next_out),t=a.next_out-e,r=eU(a.output,e);a.next_out=t,a.avail_out=s-t,t&&a.output.set(a.output.subarray(e,e+t),0),this.onData(r)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==tb||0!==i){if(r===t_)return r=tp(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},tI.prototype.onData=function(e){this.chunks.push(e)},tI.prototype.onEnd=function(e){e===tb&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=eP(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};let{Deflate:tE,deflate:tO,deflateRaw:tC,gzip:tT}={Deflate:eK,deflate:eQ,deflateRaw:function(e,t){return(t=t||{}).raw=!0,eQ(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,eQ(e,t)},constants:W},{Inflate:tM,inflate:tA,inflateRaw:tN,ungzip:tP}={Inflate:tI,inflate:t$,inflateRaw:function(e,t){return(t=t||{}).raw=!0,t$(e,t)},ungzip:t$,constants:W};r.d(t,{Gy:()=>tE,Kc:()=>tO,UD:()=>tA})},3178(e,t,r){let n;r.d(t,{x3:()=>rT,y1:()=>t4,Ov:()=>r2,Tx:()=>r9,UA:()=>iY,JH:()=>rZ,yE:()=>ra,Ky:()=>tf,e5:()=>tD,Uh:()=>t7,nu:()=>ty,OF:()=>aq,XV:()=>aJ,r8:()=>aY,rC:()=>aX,rR:()=>iX,ie:()=>eb});var i=r(2718),a=r(1179),s=r(2842),o=r(4238),l=r(5633),d=r(2109),c=r(7086),u=r(9315),f=r(2981);let p=i.ukk,h=i.mSG(i.QfV,i.$r1),m=Object.freeze({paper:"#f6f1e7",card:"#fffdf8",ink:"#1a1712",accent:"#8f707f"}),g=Object.freeze({accentColor:m.accent,backgroundColor:m.card});function y(e,t){return e.pipe(i.tiU(s.PyW(t)))}function v(e,t){return i.svK(e,{errors:"all"})(t)}let b=c.ID();function _(e){return Object.assign(e,{parse:t=>v(e,t),safeParse:t=>{let r;return r=i.q$Z(e,{errors:"all"})(t),u.oJ(r)?{data:r.success,success:!0}:{error:{issues:b(r.failure.issue).issues.map(e=>({message:e.message,path:(e.path??[]).map(e=>"object"==typeof e?e.key:e)}))},success:!1}}})}let x=i.xCb(["flowchart","mindmap"]),w=i.xCb(["TB","BT","LR","RL"]),k=i.xCb(["straight","orthogonal","curved"]);class S extends i.Xsx("DiagramNode")({id:p,label:p,group:i.lqM(p),kind:i.lqM(p),metadata:y(h,{})}){}_(S);class I extends i.Xsx("DiagramEdge")({id:p,source:p,target:p,label:i.lqM(p),metadata:y(h,{})}){}_(I);let $=i.QfV.check(i.Pto(/^#[0-9a-fA-F]{6}$/));class E extends i.Xsx("DiagramStyle")({accentColor:y($,g.accentColor),backgroundColor:y($,g.backgroundColor)}){}_(E);class O extends i.Xsx("DiagramLayout")({direction:y(w,"LR"),edgeRouting:y(k,"orthogonal")}){}_(O);class C extends i.Xsx("IntermediateDiagram")({id:p,title:p,type:y(x,"flowchart"),nodes:i.O31(S).pipe(i.fXn).check(i.tJb(1)),edges:y(i.O31(I).pipe(i.fXn),[]),layout:y(O,{direction:"LR",edgeRouting:"orthogonal"}),style:y(E,g),metadata:y(h,{})}){}_(C);class T extends Error{constructor(e){super(e),this.name="DiagramValidationError"}}let M=e=>{let t=new Set;for(let r of e){if(t.has(r))return r;t.add(r)}};function A(e){let t=M(e.nodes.map(e=>e.id));if(t)throw new T(`Duplicate node id "${t}" is not allowed.`);let r=M(e.edges.map(e=>e.id));if(r)throw new T(`Duplicate edge id "${r}" is not allowed.`);let n=new Set(e.nodes.map(e=>e.id));for(let t of e.edges){if(!n.has(t.source))throw new T(`Edge "${t.id}" references missing source node "${t.source}".`);if(!n.has(t.target))throw new T(`Edge "${t.id}" references missing target node "${t.target}".`);if(t.source===t.target)throw new T(`Edge "${t.id}" cannot connect node "${t.source}" to itself.`)}return e}function N(e){return A(v(C,e))}let P="flowchart",R=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"]);class j extends i.Xsx("FlowchartValidationIssueRef")({kind:i.xCb(["diagram","node","edge"]),id:i.lqM(i.ukk),path:i.lqM(i.ukk)}){}i.Xsx("FlowchartValidationIssue")({code:R,ref:i.lqM(j),message:i.ukk,hint:i.ukk});let D=i.xCb(["start","process","decision","end"]);class U extends S.extend("FlowchartNode")({kind:D,description:i.lqM(i.ukk)}){}class F extends I.extend("FlowchartEdge")({label:i.lqM(i.ukk)}){}class B extends C.extend("FlowchartDiagram")({type:i.uSQ(P),nodes:i.O31(U).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(F).pipe(i.fXn).check(i.tJb(1))}){}let L=_(B);function z(e){let t=new Set,r=new Set;for(let n of e)t.has(n)?r.add(n):t.add(n);return[...r]}function W(e,t,r){let n=new Set,i=[...e];for(let e=0;e<i.length;e+=1){let a=i[e];if(!(void 0===a||n.has(a)))for(let e of(n.add(a),t.get(a)??[]))i.push(r(e))}return n}function J(e){let t=[],r=new Set(e.nodes.map(e=>e.id)),{incoming:n,outgoing:i}=function(e){let t=new Map,r=new Map;for(let n of e)t.set(n.target,[...t.get(n.target)??[],n]),r.set(n.source,[...r.get(n.source)??[],n]);return{incoming:t,outgoing:r}}(e.edges);for(let r of(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."}),z(e.nodes.map(e=>e.id))))t.push({code:"duplicate_node_id",ref:{kind:"node",id:r,path:"nodes"},message:`Node id "${r}" is used more than once.`,hint:"Give every node a stable unique id."});for(let r of z(e.edges.map(e=>e.id)))t.push({code:"duplicate_edge_id",ref:{kind:"edge",id:r,path:"edges"},message:`Edge id "${r}" is used more than once.`,hint:"Give every edge a stable unique id."});for(let n of e.edges)r.has(n.source)||t.push({code:"missing_edge_source",ref:{kind:"edge",id:n.id,path:"edges.source"},message:`Edge "${n.id}" references missing source node "${n.source}".`,hint:"Set edge.source to one of the diagram node ids."}),r.has(n.target)||t.push({code:"missing_edge_target",ref:{kind:"edge",id:n.id,path:"edges.target"},message:`Edge "${n.id}" references missing target node "${n.target}".`,hint:"Set edge.target to one of the diagram node ids."}),n.source===n.target&&t.push({code:"self_loop",ref:{kind:"edge",id:n.id},message:`Edge "${n.id}" connects node "${n.source}" to itself.`,hint:"Connect the edge to a different target node."});let a=e.nodes.filter(e=>"start"===e.kind),s=e.nodes.filter(e=>"end"===e.kind);for(let r of(0===a.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".'}):a.length>1&&t.push({code:"multiple_starts",ref:{kind:"diagram",id:e.id,path:"nodes"},message:`Flowchart has ${a.length} start nodes.`,hint:"Keep one start node and change the others to process, decision, or end."}),0===s.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=n.get(r.id)??[],a=i.get(r.id)??[];"start"===r.kind&&e.length>0&&t.push({code:"start_has_incoming",ref:{kind:"node",id:r.id},message:`Start node "${r.id}" cannot have incoming edges.`,hint:"Route the start node only to later nodes."}),"end"===r.kind&&a.length>0&&t.push({code:"end_has_outgoing",ref:{kind:"node",id:r.id},message:`End node "${r.id}" cannot have outgoing edges.`,hint:"End nodes must be terminal outcomes."}),"end"!==r.kind&&0===a.length&&t.push({code:"missing_outgoing_edge",ref:{kind:"node",id:r.id},message:`Node "${r.id}" must have at least one outgoing edge.`,hint:'Connect it to the next step, or mark it as kind: "end".'}),"decision"===r.kind&&t.push(...function(e,t){let r=[];t.length<2&&r.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 n=t.map(e=>e.label?.trim()??"");for(let n of t.filter(e=>!e.label?.trim()))r.push({code:"unlabeled_decision_branch",ref:{kind:"edge",id:n.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 z(n.filter(e=>e.length>0).map(e=>e.toLowerCase())))r.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 r}(r,a))}let o=1===a.length?a[0]:void 0;if(o){let r=W([o.id],i,e=>e.target);for(let n of e.nodes)r.has(n.id)||t.push({code:"unreachable_node",ref:{kind:"node",id:n.id},message:`Node "${n.id}" is not reachable from the start node.`,hint:"Connect every node to the flow that begins at the single start node."});if(s.length>0){let a=W(s.map(e=>e.id),n,e=>e.source);for(let n of e.nodes)r.has(n.id)&&!a.has(n.id)&&(i.get(n.id)?.length??0)>0&&t.push({code:"nonterminating_node",ref:{kind:"node",id:n.id},message:`Node "${n.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 Y extends T{issues;constructor(e){super(e[0]?.message??"Flowchart failed semantic validation."),this.issues=e,this.name="FlowchartValidationError"}}function X(e){let t=J(e);if(t.length>0)throw new Y(t);return e}let q=X(v(B,{id:"onboarding-flow",title:"Sketchi onboarding decision flow",type:P,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"}}));X(v(B,{id:"pharma-batch-disposition",title:"Pharma batch disposition flow",type:P,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"}}));let G="mindmap";class V extends i.Xsx("MindmapNodeMetadata")({depth:i.Aiz.check(i.OWK(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class H extends S.extend("MindmapNode")({kind:i.xCb(["root","topic"]),metadata:V}){}class K extends i.Xsx("MindmapEdgeMetadata")({depth:i.Aiz.check(i.yJO(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class Q extends I.extend("MindmapEdge")({metadata:K}){}class Z extends C.extend("MindmapDiagram")({type:i.uSQ(G),nodes:i.O31(H).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(Q).pipe(i.fXn).check(i.tJb(1))}){}function ee(e){return function(e){A(e);let t=e.nodes.filter(e=>"root"===e.kind);if(1!==t.length)throw new T(`Mindmap must contain exactly one root topic; found ${t.length}.`);let r=t[0];if(!r||0!==r.metadata.depth)throw new T("Mindmap root topic must have depth 0.");let n=new Map,i=new Map(e.nodes.map(e=>[e.id,e])),a=new Map;for(let t of e.edges){n.set(t.target,(n.get(t.target)??0)+1);let e=i.get(t.source)?.metadata.depth,r=i.get(t.target),s=r?.metadata.depth;if(void 0===e||s!==e+1)throw new T(`Mindmap edge "${t.id}" must connect a topic to its immediate child.`);if(!r||t.metadata.depth!==r.metadata.depth||t.metadata.siblingIndex!==r.metadata.siblingIndex)throw new T(`Mindmap edge "${t.id}" metadata must match its child topic.`);a.set(t.source,[...a.get(t.source)??[],r.metadata.siblingIndex])}for(let t of e.nodes){let e=n.get(t.id)??0;if(t.id===r.id?0!==e:1!==e)throw new T(`Mindmap topic "${t.id}" must have ${t.id===r.id?"no parent":"exactly one parent"}.`)}for(let[e,t]of a){let r=t.map((e,t)=>t);if([...t].sort((e,t)=>e-t).some((e,t)=>e!==r[t]))throw new T(`Mindmap children of "${e}" must use contiguous sibling ordering from 0.`)}return e}(v(Z,e))}_(Z);let et=ee({id:"public-mindmap-capability",title:"Public mindmap generation",type:G,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"}});N(q),N(et);let er=Object.freeze({maxDimension:16384,maxElements:600,maxGroupsPerElement:16,maxLayouts:128,maxLayers:64,maxPointsPerElement:256,maxSerializedBytes:15e5,maxTextLength:4096,maxZOrderEntries:600});function en(e){let t=new Set;for(let r of e){if(t.has(r))return r;t.add(r)}}function ei(e){return"x"in e&&"y"in e}function ea(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>er.maxElements&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${er.maxElements} elements.`,path:"elements"}),e.layers.length>er.maxLayers&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${er.maxLayers} layers.`,path:"layers"}),e.layouts.length>er.maxLayouts&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${er.maxLayouts} layout primitives.`,path:"layouts"}),(e.width>er.maxDimension||e.height>er.maxDimension)&&t.push({code:"limit_exceeded",message:`Canvas dimensions may not exceed ${er.maxDimension}.`,path:"width"});let r=en(e.elements.map(e=>e.id));r&&t.push({code:"duplicate_element_id",elementId:r,message:`Duplicate element id "${r}" is not allowed.`,path:"elements"});let n=en(e.layers.map(e=>e.id));n&&t.push({code:"duplicate_layer_id",message:`Duplicate layer id "${n}" is not allowed.`,path:"layers"});let i=en(e.zOrder);i&&t.push({code:"duplicate_z_order_element",elementId:i,message:`zOrder contains duplicate element "${i}".`,path:"zOrder"}),e.zOrder.length>er.maxZOrderEntries&&t.push({code:"limit_exceeded",message:`zOrder exceeds ${er.maxZOrderEntries} entries.`,path:"zOrder"});let a=new Map(e.elements.map(e=>[e.id,e])),s=e.elements.filter(e=>"node"===e.type),o=new Map(s.map(e=>[e.nodeId,e])),l=en(s.map(e=>e.nodeId));l&&t.push({code:"invalid_binding",message:`Duplicate nodeId "${l}" makes connector bindings ambiguous.`,path:"elements"});let d=en(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=en(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 u=new Map(e.layers.map(e=>[e.id,e])),f=new Set(u.keys()),p=e=>!e.layerId||u.get(e.layerId)?.visible!==!1,h=new Map;for(let[t,r]of e.elements.entries())"text"===r.type&&r.containerId&&p(r)&&h.set(r.containerId,{element:r,index:t});e.elements.forEach((e,r)=>{let n,i;if(t.push(...(n=[],i=`elements[${r}]`,"width"in e&&"height"in e&&(!(e.width>0)||!(e.height>0))&&n.push({code:"invalid_geometry",elementId:e.id,message:`Element "${e.id}" must have positive width and height.`,path:i}),"points"in e&&void 0!==e.points&&e.points.length>er.maxPointsPerElement&&n.push({code:"limit_exceeded",elementId:e.id,message:`Element "${e.id}" exceeds ${er.maxPointsPerElement} points.`,path:`${i}.points`}),"text"in e&&e.text.length>er.maxTextLength&&n.push({code:"limit_exceeded",elementId:e.id,message:`Text element "${e.id}" exceeds ${er.maxTextLength} characters.`,path:`${i}.text`}),"node"===e.type&&"polygon"===e.shape&&(!e.points||e.points.length<3)&&n.push({code:"invalid_polygon",elementId:e.id,message:`Polygon "${e.id}" requires at least three points.`,path:`${i}.points`}),e.groupIds&&e.groupIds.length>er.maxGroupsPerElement&&n.push({code:"limit_exceeded",elementId:e.id,message:`Element "${e.id}" exceeds ${er.maxGroupsPerElement} groups.`,path:`${i}.groupIds`}),n)),"node"===e.type&&"polygon"!==e.shape&&p(e)){let n=h.get(e.id);if(n||"sequence-lifeline"!==e.rendererRole){let i=n?.element.text??e.label,a=n?.element.fontSize??16,s=n?n.element.maxWidth??160:Math.max(1,e.width-24),o=i.split("\n"),l=Math.max(1,Math.min(s,o.reduce((e,t)=>Math.max(e,t.length*a*.62),0))),d=Math.ceil(o.length*a*1.35);(l+24>e.width||d+18>e.height)&&t.push({code:"label_overflow",elementId:n?.element.id??e.id,message:`Label does not fit inside node "${e.id}" without changing its geometry.`,path:n?`elements[${n.index}].text`:`elements[${r}].label`})}}if(e.frameId){let n=a.get(e.frameId);n&&"frame"===n.type||t.push({code:"invalid_composition",elementId:e.id,message:`Element "${e.id}" references missing frame "${e.frameId}".`,path:`elements[${r}].frameId`})}if(e.layerId&&!f.has(e.layerId)&&t.push({code:"invalid_composition",elementId:e.id,message:`Element "${e.id}" references missing layer "${e.layerId}".`,path:`elements[${r}].layerId`}),e.groupIds&&en(e.groupIds)&&t.push({code:"invalid_composition",elementId:e.id,message:`Element "${e.id}" contains duplicate group ids.`,path:`elements[${r}].groupIds`}),"text"===e.type&&e.containerId){let n=a.get(e.containerId);n&&("node"===n.type||"arrow"===n.type)||t.push({code:"invalid_binding",elementId:e.id,message:`Text "${e.id}" references unsupported container "${e.containerId}".`,path:`elements[${r}].containerId`})}if("arrow"===e.type&&(o.has(e.sourceNodeId)||t.push({code:"invalid_binding",elementId:e.id,message:`Connector "${e.id}" references missing source "${e.sourceNodeId}".`,path:`elements[${r}].sourceNodeId`}),o.has(e.targetNodeId)||t.push({code:"invalid_binding",elementId:e.id,message:`Connector "${e.id}" references missing target "${e.targetNodeId}".`,path:`elements[${r}].targetNodeId`})),"line"===e.type)for(let[n,i]of[["startBinding",e.startBinding],["endBinding",e.endBinding]]){let s=i?a.get(i.elementId):void 0;i&&(!s||"node"!==s.type&&"frame"!==s.type)&&t.push({code:"invalid_binding",elementId:e.id,message:`Line "${e.id}" references missing binding "${i.elementId}".`,path:`elements[${r}].${n}`})}});let m=new Set(e.zOrder);for(let r of e.elements)m.has(r.id)||t.push({code:"missing_z_order_element",elementId:r.id,message:`Element "${r.id}" is missing from zOrder.`,path:"zOrder"});for(let r of e.zOrder)a.has(r)||t.push({code:"unknown_z_order_element",elementId:r,message:`zOrder references missing element "${r}".`,path:"zOrder"});for(let[r,n]of e.layouts.entries())for(let e of n.ids){let n=a.get(e);n&&ei(n)||t.push({code:"unknown_layout_target",elementId:e,message:`Layout references missing or non-positioned element "${e}".`,path:`layouts[${r}].ids`})}for(let r of e.elements.filter(e=>"frame"===e.type)){let e=new Set([r.id]),n=r.frameId;for(;n;){if(e.has(n)){t.push({code:"invalid_composition",elementId:r.id,message:`Frame "${r.id}" participates in a frame nesting cycle.`,path:"elements"});break}e.add(n);let i=a.get(n);n=i?.type==="frame"?i.frameId:void 0}}return t}function es(e){if("text"===e.type){let t=e.text.split("\n");return{x:e.x,y:e.y,width:e.maxWidth??Math.max(...t.map(e=>e.length))*e.fontSize*.62,height:t.length*e.fontSize*1.35}}return{x:e.x,y:e.y,width:e.width,height:e.height}}function eo(e,t){let r=new Map(e.map(e=>[e.id,e]));return t.flatMap(e=>{let t=r.get(e);return t&&ei(t)?[t]:[]})}function el(e,t){return e.map(e=>{var r,n;let i=t.get(e.id);return i?(r=i.x,n=i.y,ei(e)?{...e,x:r,y:n}:e):e})}function ed(e,t){return"x"===t?e.x:e.y}function ec(e,t){return"x"===t?e.width:e.height}function eu(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function ef(e,t){let r=eu(e),n=t.x-r.x,i=t.y-r.y;return Math.abs(n)>=Math.abs(i)?{x:n>=0?e.x+e.width:e.x,y:r.y}:{x:r.x,y:i>=0?e.y+e.height:e.y}}let ep=/[,;]\s*(?:id|label|kind|group|source|target|title|direction|nodes|edges)\s*:?\s*$/i;function eh(e){let t=e.trim();for(;;){let e=t.replace(ep,"").trim();if(e===t)return t;t=e}}class em extends i.Xsx("ContractSchemaIssue")({code:eP("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 eg extends i.rNF()("ContractSchemaError",{issues:i.O31(i.O3D(em))}){}let ey=e=>{var t;if("InvalidType"!==e._tag)return c.vp(e);let r=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===r?"null":Array.isArray(r)?"array":typeof r}`},ev=c.ID({leafHook:ey});function eb(e,t){var r;let n,a,s=i.q$Z(e,{errors:"all",reportInput:!0})(t);return u.oJ(s)?{data:s.success,success:!0}:{error:new eg({issues:(r=s.failure,n=[],((a=(e,t,r)=>{switch(e._tag){case"Pointer":return a(e.issue,[...t,...e.path],r);case"Encoding":return a(e.issue,t,r);case"Composite":for(let r of e.issues)a(r,t,e.ast);return;case"AnyOf":if(e.issues.length>0){for(let r of e.issues)a(r,t,e.ast);return}break;case"Filter":if(void 0===c.VY(e)&&"InvalidValue"!==e.issue._tag)return a(e.issue,t,r)}let i="ast"in e?e.ast:r,s="MissingKey"===e._tag&&e.annotations?.[eI]==="invalid_type"?"invalid_type":void 0,o=i&&d.mi(i)&&i.types.every(d.c$)?"LiteralUnion":i?._tag,l=i?.annotations?.[eS],u="string"==typeof l?[...t,l]:t;for(let t of ev(e).issues)n.push({code:"custom",issueTag:e._tag,...s?{missingKeyCode:s}:{},...o?{astKind:o}:{},message:t.message,path:u})})(r.issue,[]),n.length>1&&n.every(e=>"source"===e.path[0]))?[{code:"custom",issueTag:"AnyOf",astKind:"Union",message:"Invalid input",path:["source"]}]:n)}),success:!1}}function e_(e){return Object.assign(e,{parse:t=>{let r=eb(e,t);if(r.success)return r.data;throw r.error},safeParse:t=>eb(e,t)})}let ex=new Set(["x-sketchi-default","x-sketchi-one-of","const","exclusiveMaximum","exclusiveMinimum","maximum","maxLength","maxItems","minimum","minItems","minLength","pattern"]),ew="x-sketchi-default",ek="x-sketchi-one-of",eS="codeModeDiscriminator",eI="codeModeMissingKeyCode";function e$(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function eE(e){let t=i._oz(i.AxX(e),{includeAnnotationKey:e=>ex.has(e),onExcessProperty:"error"});return function e(t){if(Array.isArray(t))return t.map(e);if(!e$(t))return t;let r=Object.fromEntries(Object.entries(t).map(([t,r])=>[t,e(r)])),n=!0===r[ek];delete r[ek],n&&Array.isArray(r.anyOf)&&(r.oneOf=r.anyOf,delete r.anyOf);let i=r.allOf;if(Array.isArray(i)){let e=[];for(let t of i)e$(t)&&Object.hasOwn(t,ew)?r.default=t[ew]:e.push(t);0===e.length?delete r.allOf:r.allOf=e}return r}({$schema:"https://json-schema.org/draft/2020-12/schema",...t.schema,...0===Object.keys(t.definitions).length?{}:{$defs:t.definitions}})}function eO(e){return i.O31(e).pipe(i.fXn).check(i.tJb(1,{message:"Too small: expected array to have >=1 items"}))}function eC(e){return i.Qrq(e)}function eT(e){return e.pipe(i.usV({[eI]:"invalid_type",messageMissingKey:"Invalid input: expected string, received undefined"}))}function eM(e){return e.pipe(i.usV({[eI]:"invalid_type",messageMissingKey:"Invalid input: expected object, received undefined"}))}function eA(e){return e.pipe(i.usV({[eI]:"invalid_type",messageMissingKey:"Invalid input: expected array, received undefined"}))}function eN(e){return i.xCb(e).annotate({message:`Invalid option: expected one of ${e.map(e=>JSON.stringify(e)).join("|")}`})}function eP(e){return eD(e,i.QfV)}function eR(e){return eD(e,i.wNn)}function ej(e){return eD(e,i.v8c)}function eD(e,t){let r=i.hzj()([],()=>(t,r,n)=>t===e?s.PyW(e):s.fJG(new c.eE(r,t,n)),{message:`Invalid literal value, expected ${JSON.stringify(e)}`,toCodecJson:()=>i.nfo()(t.annotate({const:e}),{decode:f.pd(()=>e),encode:f.pd(e=>e)})});return i.uSQ(e).pipe(i.GLL(r))}let eU=i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"})),eF=eT(eU),eB=i.wYs,eL=i.wNn.check(i.MIs(),i.yJO(0,{message:"Too small: expected number to be >0"})),ez=/^#[0-9a-fA-F]{6}$/u;function eW(e){return i.QfV.annotate(void 0===e?{}:{default:e}).check(i.Pto(ez,{message:`Invalid string: must match pattern /${ez.source}/`}))}let eJ=eW();e_(eJ);let eY=["excalidraw","scene","png"],eX=["excalidraw","scene"],eq=Object.assign(e_(eN(eY)),{options:eY}),eG=Object.assign(e_(eN(eX)),{options:eX});class eV extends i.Xsx("ArtifactProvenance")({sourceArtifactId:eF.pipe(i.Wa3)},{identifier:void 0}){}e_(eV);let eH=["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","mindmap_too_deep","mindmap_too_large","request_too_large","generic_label","label_too_long","quality_below_threshold","render_failed","text_overflow","arrow_binding_invalid","arrow_overlap","export_invalid_scene","storage_read_failed","storage_write_failed","unsupported_artifact_format","patch_source_unavailable","unknown_patch_target","unsupported_patch_operation","patch_preserve_connectivity_failed","patch_output_invalid","duplicate_element_id","duplicate_layer_id","invalid_canvas_binding","invalid_canvas_composition","invalid_canvas_geometry","invalid_polygon","canvas_limit_exceeded","invalid_z_order","unknown_layout_target"],eK=Object.assign(e_(eN(eH)),{options:eH}),eQ=eN(["request","diagram","node","edge","element","layer","artifact"]),eZ=eN(["input","canvas","flowchart","mindmap","quality","render","export","storage"]);class e0 extends i.Xsx("CodeModeIssueRef")({kind:eQ,id:eC(eU),path:eC(eU)},{identifier:void 0}){}e_(e0);class e1 extends i.Xsx("CodeModeIssue")({code:eK,severity:eN(["error","warning"]),stage:eZ,ref:eC(e0),message:eF,hint:eF},{identifier:void 0}){}let e2=e_(e1),e5=["start","process","decision","end"],e3=Object.assign(e_(eN(e5)),{options:e5}),e6=["setDefaultStyle","setStyle","setShape","translate","replaceText","rerouteEdges","insert","remove","replace","reorder","group","ungroup"];Object.assign(e_(eN(e6)),{options:e6});class e8 extends i.Xsx("FlowchartSpecNode")({id:eF,label:eF,kind:e3,description:eC(eU)},{identifier:void 0}){}class e9 extends i.Xsx("FlowchartSpecEdge")({id:eC(eU),source:eF,target:eF,label:eC(eU)},{identifier:void 0}){}let e4=eN(["TB","LR"]),e7=e4.annotate({default:"TB"}).pipe(i.E$i(s.PyW("TB")));class te extends i.Xsx("FlowchartSpecLayout")({direction:e7},{identifier:void 0}){}let tt=g.accentColor,tr=eW(tt).pipe(i.E$i(s.PyW(tt))),tn=g.backgroundColor,ti=eW(tn).pipe(i.E$i(s.PyW(tn)));class ta extends i.Xsx("FlowchartSpecStyle")({accentColor:tr,backgroundColor:ti},{identifier:void 0}){}let ts=[],to=i.O31(e9).pipe(i.fXn).annotate({default:ts}).pipe(i.E$i(s.PyW(ts))),tl={direction:"TB"},td=te.annotate({default:tl}).pipe(i.E$i(s.PyW(tl)),i.usV({[ew]:tl})),tc={accentColor:g.accentColor,backgroundColor:g.backgroundColor},tu=ta.annotate({default:tc}).pipe(i.E$i(s.PyW(tc)),i.usV({[ew]:tc}));class tf extends i.Xsx("FlowchartSpec")({id:eC(eU),title:eF,nodes:eA(eO(e8)),edges:to,layout:td,style:tu},{identifier:void 0}){}e_(tf),e_(e8),e_(e9),e_(te),e_(ta);class tp extends i.Xsx("SequenceParticipantSpec")({id:eF,label:eF,kind:eC(eU)},{identifier:void 0}){}class th extends i.Xsx("SequenceMessageSpec")({id:eC(eU),source:eF,target:eF,label:eF,type:eC(eN(["message","return"])),style:eC(eN(["solid","dashed"]))},{identifier:void 0}){}let tm=[],tg=i.O31(th).pipe(i.fXn).annotate({default:tm}).pipe(i.E$i(s.PyW(tm)));class ty extends i.Xsx("SequenceDiagramSpec")({id:eC(eU),title:eF,participants:eA(eO(tp)),messages:tg,style:tu},{identifier:void 0}){}e_(ty),e_(tp),e_(th);let tv=eC(eO(eq)),tb=eC(i.O31(eG).pipe(i.fXn)),t_=eC(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 tx extends i.Xsx("BuildFlowchartOptions")({artifactFormats:tv,inlineArtifacts:tb,minQualityScore:t_},{identifier:void 0}){}e_(eC(tx));class tw extends i.Xsx("BuildFlowchartRequest")({requestId:eC(eU),spec:eM(tf),options:eC(tx)},{identifier:void 0}){}let tk=tf.mapFields(({id:e,title:t,nodes:r,edges:n,layout:i})=>({id:e,title:t,nodes:r,edges:n,layout:i})),tS=i._kM({requestId:eC(eU),spec:eM(tk)}),tI=i.rcy(tS,{leafHook:ey,parseOptions:{errors:"all"}}),t$=Object.assign(tI,{"~standard":{...tI["~standard"],jsonSchema:{input:()=>eE(tS),output:()=>eE(tS)}}}),tE=Object.assign(e_(tw),{omit:e=>t$});class tO extends i.Xsx("BuildSequenceDiagramRequest")({requestId:eC(eU),spec:eM(ty),options:eC(tx)},{identifier:void 0}){}let tC=e_(tO),tT=i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"}),i.HNH(function(e){let t=eh(e);return t.length>0&&!/^(?:""|''|``)$/.test(t)},{message:"Must contain semantic text after normalization."})),tM=eM(i.DYE(()=>tA).annotate({identifier:"__schema0"})),tA=i._kM({label:eT(tT),children:i.Qrq(i.O31(tM).pipe(i.fXn))});e_(tM);class tN extends i.Xsx("MindmapSpecLayout")({direction:eN(["LR","RL"]).annotate({default:"LR"}).pipe(i.E$i(s.PyW("LR")))},{identifier:void 0}){}let tP={direction:"LR"},tR=tN.annotate({default:tP}).pipe(i.E$i(s.PyW(tP)),i.usV({[ew]:tP})),tj=i._kM({id:eC(eU),title:eT(tT),root:tM,layout:tR,style:tu});class tD extends i.Xsx("MindmapSpec")(tj,{identifier:void 0}){}e_(tD);let tU=i._kM({requestId:eC(eU),spec:eM(tj),options:eC(tx)});i.Xsx("BuildMindmapRequest")(tU,{identifier:void 0});let tF=e_(tU);class tB extends i.Xsx("ScenePoint")({x:eB.pipe(i.Wa3),y:eB.pipe(i.Wa3)},{identifier:void 0}){}e_(tB);let tL={frameId:eC(eU).pipe(i.Wa3),groupIds:eC(i.O31(eU).pipe(i.fXn).annotate({maxItems:er.maxGroupsPerElement})).pipe(i.Wa3),layerId:eC(eU).pipe(i.Wa3),locked:eC(i.v8c).pipe(i.Wa3),opacity:eC(i.wNn.check(i.MIs(),i.Bt9({minimum:0,maximum:100}))).pipe(i.Wa3),zIndex:eC(i.Aiz).pipe(i.Wa3)},tz={fillColor:eC(eJ).pipe(i.Wa3),fillStyle:eC(eN(["cross-hatch","hachure","solid"])).pipe(i.Wa3),roughness:eC(eN([0,1,2])).pipe(i.Wa3),strokeColor:eC(eJ).pipe(i.Wa3),strokeStyle:eC(eN(["dashed","dotted","solid"])).pipe(i.Wa3),strokeWidth:eC(eN([1,2,4])).pipe(i.Wa3)},tW=i.T9y(eN(["arrow","bar","circle","diamond","triangle"])),tJ=i.O31(tB).pipe(i.fXn).check(i.tJb(2,{message:"Too small: expected array to have >=2 items"}),i.NYj(er.maxPointsPerElement,{message:`Too big: expected array to have <=${er.maxPointsPerElement} items`}));class tY extends i.Xsx("NodeSceneElement")({...tL,...tz,type:eP("node"),id:eF,nodeId:eF,kind:eC(eU),rendererRole:eC(eN(["sequence-lifeline"])),shape:eN(["rectangle","ellipse","diamond","circle","polygon"]).pipe(i.Wa3),points:eC(tJ).pipe(i.Wa3),textColor:eC(eJ).pipe(i.Wa3),x:eB.pipe(i.Wa3),y:eB.pipe(i.Wa3),width:eL.pipe(i.Wa3),height:eL.pipe(i.Wa3),label:eF.pipe(i.Wa3)},{identifier:void 0}){}class tX extends i.Xsx("TextSceneElement")({...tL,type:eP("text"),id:eF,containerId:eC(eU),textColor:eC(eJ).pipe(i.Wa3),x:eB.pipe(i.Wa3),y:eB.pipe(i.Wa3),text:eF.pipe(i.Wa3),fontSize:eL,fontFamily:eC(eN(["hand","mono","sans"])),maxWidth:eC(eL),textAlign:eC(eN(["center","left","right"])),verticalAlign:eC(eN(["bottom","middle","top"]))},{identifier:void 0}){}class tq extends i.Xsx("ArrowSceneElement")({...tL,...tz,type:eP("arrow"),id:eF,edgeId:eF,sourceNodeId:eF,targetNodeId:eF.pipe(i.Wa3),startArrowhead:eC(tW).pipe(i.Wa3),endArrowhead:eC(tW).pipe(i.Wa3),textColor:eC(eJ).pipe(i.Wa3),points:eA(tJ).pipe(i.Wa3),label:eC(eU).pipe(i.Wa3)},{identifier:void 0}){}class tG extends i.Xsx("CanvasLineBinding")({elementId:eF,focus:eC(eB),gap:eC(eB)},{identifier:void 0}){}class tV extends i.Xsx("LineSceneElement")({...tL,...tz,type:eP("line"),id:eF,points:eA(tJ).pipe(i.Wa3),startBinding:eC(tG).pipe(i.Wa3),endBinding:eC(tG).pipe(i.Wa3),startArrowhead:eC(tW).pipe(i.Wa3),endArrowhead:eC(tW).pipe(i.Wa3),label:eC(eU).pipe(i.Wa3),textColor:eC(eJ).pipe(i.Wa3)},{identifier:void 0}){}class tH extends i.Xsx("FrameSceneElement")({...tL,...tz,type:eP("frame"),id:eF,name:eC(eU).pipe(i.Wa3),x:eB.pipe(i.Wa3),y:eB.pipe(i.Wa3),width:eL.pipe(i.Wa3),height:eL.pipe(i.Wa3)},{identifier:void 0}){}class tK extends i.Xsx("CanvasLayer")({id:eF,name:eC(eU),locked:eC(i.v8c),visible:eC(i.v8c)},{identifier:void 0}){}let tQ=eA(eO(eU));class tZ extends i.Xsx("CanvasFlowLayout")({type:eN(["row","column","stack"]),ids:tQ,x:eC(eB),y:eC(eB),gap:eC(eB)},{identifier:void 0}){}class t0 extends i.Xsx("CanvasGridLayout")({type:eP("grid"),ids:tQ,columns:i.Aiz.check(i.OWK(1,{message:"Too small: expected number to be >=1"})),x:eC(eB),y:eC(eB),columnGap:eC(eB),rowGap:eC(eB)},{identifier:void 0}){}class t1 extends i.Xsx("CanvasAlignLayout")({type:eP("align"),ids:tQ,axis:eN(["x","y"]),alignment:eN(["center","end","start"])},{identifier:void 0}){}class t2 extends i.Xsx("CanvasDistributeLayout")({type:eP("distribute"),ids:tQ,axis:eN(["x","y"]),gap:eC(eB)},{identifier:void 0}){}e_(tY),e_(tX),e_(tq),e_(tV),e_(tH);let t5=i.gPz([tY,tX,tq,tV,tH],{mode:"oneOf"}).annotate({[ek]:!0}),t3=i.gPz([tZ,t0,t1,t2],{mode:"oneOf"}),t6=i.O31(tK).pipe(i.fXn).annotate({default:[],maxItems:er.maxLayers}).pipe(i.E$i(s.PyW([]))),t8=i.O31(t3).pipe(i.fXn).annotate({default:[],maxItems:er.maxLayouts}).pipe(i.E$i(s.PyW([]))),t9=i.O31(eU).pipe(i.fXn).annotate({default:[],maxItems:er.maxZOrderEntries}).pipe(i.E$i(s.PyW([])));class t4 extends i.Xsx("CanvasSpec")({kind:eP("canvas"),version:eR(1),diagramId:eF,title:eF,width:eL.pipe(i.Wa3),height:eL.pipe(i.Wa3),accentColor:eJ.pipe(i.Wa3),backgroundColor:eJ.pipe(i.Wa3),elements:eA(i.O31(t5).pipe(i.fXn).annotate({maxItems:er.maxElements})),layers:t6,layouts:t8,zOrder:t9},{identifier:void 0}){}let t7=e_(t4);class re extends i.Xsx("CreateCanvasRequest")({requestId:eC(eU),spec:eM(t4),options:eC(tx)},{identifier:void 0}){}let rt=e_(re),rr=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"}));e_(rr);class rn extends i.Xsx("ExcalidrawScene")({appState:i.mSG(i.QfV,i.$r1),elements:i.O31(rr).pipe(i.fXn)},{identifier:void 0}){}e_(rn);class ri extends rn.extend("ExcalidrawFile")({files:i.mSG(i.QfV,i.$r1),source:eF,type:eP("excalidraw"),version:eR(2)},{identifier:void 0}){}let ra=e_(ri);class rs extends i.Xsx("GetArtifactRequest")({artifactId:eF,format:eC(eq),inline:eC(i.v8c)},{identifier:void 0}){}let ro=e_(rs);class rl extends i.Xsx("DiagramSelector")({ids:eC(i.O31(eU).pipe(i.fXn)),nodeIds:eC(i.O31(eU).pipe(i.fXn)),edgeIds:eC(i.O31(eU).pipe(i.fXn)),kinds:eC(i.O31(e3).pipe(i.fXn)),labels:eC(i.O31(eU).pipe(i.fXn)),scope:eC(eN(["all","nodes","edges"]))},{identifier:void 0}){}e_(rl);class rd extends i.Xsx("DiagramStylePatch")({strokeColor:eC(eJ),fillColor:eC(eJ),textColor:eC(eJ),backgroundColor:eC(eJ)},{identifier:void 0}){}e_(rd);let rc=["rectangle","diamond","ellipse","circle","polygon"],ru=Object.assign(e_(eN(rc)),{options:rc});class rf extends i.Xsx("SetDefaultStyleOperation")({op:eP("setDefaultStyle"),style:eM(rd)},{identifier:void 0}){}class rp extends i.Xsx("SetStyleOperation")({op:eP("setStyle"),selector:eM(rl),style:eM(rd)},{identifier:void 0}){}class rh extends i.Xsx("SetShapeOperation")({op:eP("setShape"),selector:eM(rl),shape:ru},{identifier:void 0}){}class rm extends i.Xsx("TranslateOperation")({op:eP("translate"),selector:eM(rl),dx:eB,dy:eB},{identifier:void 0}){}class rg extends i.Xsx("ReplaceTextOperation")({op:eP("replaceText"),selector:eM(rl),text:eF},{identifier:void 0}){}class ry extends i.Xsx("RerouteEdgesOperation")({op:eP("rerouteEdges"),selector:eC(rl)},{identifier:void 0}){}let rv=eA(eO(eU));class rb extends i.Xsx("InsertElementsOperation")({op:eP("insert"),elements:eA(eO(t5)),beforeId:eC(eU),afterId:eC(eU)},{identifier:void 0}){}class r_ extends i.Xsx("RemoveElementsOperation")({op:eP("remove"),selector:eM(rl)},{identifier:void 0}){}class rx extends i.Xsx("ReplaceElementOperation")({op:eP("replace"),id:eF,element:eM(t5)},{identifier:void 0}){}class rw extends i.Xsx("ReorderElementsOperation")({op:eP("reorder"),ids:rv,beforeId:eC(eU),afterId:eC(eU)},{identifier:void 0}){}class rk extends i.Xsx("GroupElementsOperation")({op:eP("group"),ids:rv,groupId:eF},{identifier:void 0}){}class rS extends i.Xsx("UngroupElementsOperation")({op:eP("ungroup"),ids:rv,groupId:eC(eU)},{identifier:void 0}){}let rI=i.gPz([rf,rp,rh,rm,rg,ry,rb,r_,rx,rw,rk,rS],{mode:"oneOf"}).annotate({[ek]:!0,[eS]:"op",message:`Invalid discriminator value. Expected ${e6.map(e=>`'${e}'`).join(" | ")}`});class r$ extends i.Xsx("ArtifactPatchSource")({artifactId:eF,format:eC(eP("scene"))},{identifier:void 0}){}class rE extends i.Xsx("InlineScenePatchSource")({scene:eM(t4)},{identifier:void 0}){}let rO=i.gPz([r$,rE]).annotate({message:"Invalid input"});class rC extends i.Xsx("ApplyDiagramPatchOptions")({artifactFormats:tv,inlineArtifacts:tb,preserveConnectivity:eC(i.v8c)},{identifier:void 0}){}e_(eC(rC));class rT extends i.Xsx("ApplyDiagramPatchRequest")({requestId:eC(eU),source:rO.annotateKey({messageMissingKey:"Invalid input"}),operations:eA(eO(rI)),options:eC(rC),intent:eC(eU)},{identifier:void 0}){}let rM=e_(rT);class rA extends i.Xsx("NormalizedMindmapTopic")({id:eU,label:eU,children:i.O31(i.DYE(()=>rA)).pipe(i.fXn)},{identifier:void 0}){}let rN=i._kM({id:eU,title:eU,nodes:i.O31(e8).pipe(i.fXn),edges:i.O31(e9.mapFields(e=>({...e,id:eU}))).pipe(i.fXn),layout:i._kM({direction:e4}),style:i._kM({accentColor:eJ,backgroundColor:eJ})}),rP=i._kM({id:eU,title:eU,root:rA,layout:i._kM({direction:eN(["LR","RL"])}),style:i._kM({accentColor:eJ,backgroundColor:eJ})}),rR=i._kM({id:eU,title:eU,participants:i.O31(tp).pipe(i.fXn),messages:i.O31(th.mapFields(e=>({...e,id:eU}))).pipe(i.fXn),style:i._kM({accentColor:eJ,backgroundColor:eJ})}),rj=i._kM({code:i.QfV,passed:i.v8c,severity:eN(["error","warning"]),message:i.QfV,refs:i.O31(e0).pipe(i.fXn)}),rD=i._kM({accepted:i.v8c,score:i.wNn,threshold:i.wNn,summary:i._kM({nodeCount:i.wNn,edgeCount:i.wNn}),checks:i.O31(rj).pipe(i.fXn)}),rU=i._kM({format:eq,mimeType:i.QfV,url:eC(i.QfV),expiresAt:eC(i.QfV),inline:eC(i.$r1),sizeBytes:eC(i.wNn)}),rF=i._kM({artifactId:i.QfV,diagramId:i.QfV,formats:i.O31(rU).pipe(i.fXn),provenance:eC(eV),preview:eC(rU)}),rB=i._kM({artifactId:eC(i.QfV),diagramId:eC(i.QfV),formats:eC(i.O31(rU).pipe(i.fXn))});class rL extends i.Xsx("BuildFlowchartAccepted")({ok:ej(!0),status:eP("accepted"),buildId:i.QfV,requestId:eC(i.QfV),normalizedSpec:rN,quality:rD,artifact:rF,issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}class rz extends i.Xsx("BuildFlowchartRejected")({ok:ej(!1),status:eN(["invalid_input","invalid_flowchart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:eC(i.QfV),requestId:eC(i.QfV),normalizedSpec:eC(rN),quality:eC(rD),partial:eC(rB),issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rL,rz]);class rW extends i.Xsx("BuildMindmapAccepted")({ok:ej(!0),status:eP("accepted"),buildId:i.QfV,requestId:eC(i.QfV),normalizedSpec:rP,quality:rD,artifact:rF,issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}class rJ extends i.Xsx("BuildMindmapRejected")({ok:ej(!1),status:eN(["invalid_input","invalid_mindmap","quality_failed","render_failed","export_failed","storage_failed"]),buildId:eC(i.QfV),requestId:eC(i.QfV),normalizedSpec:eC(rP),quality:eC(rD),partial:eC(rB),issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rW,rJ]);class rY extends i.Xsx("BuildSequenceDiagramAccepted")({ok:ej(!0),status:eP("accepted"),buildId:i.QfV,requestId:eC(i.QfV),normalizedSpec:rR,quality:rD,artifact:rF,issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}class rX extends i.Xsx("BuildSequenceDiagramRejected")({ok:ej(!1),status:eN(["invalid_input","invalid_sequence","quality_failed","render_failed","export_failed","storage_failed"]),buildId:eC(i.QfV),requestId:eC(i.QfV),normalizedSpec:eC(rR),quality:eC(rD),partial:eC(rB),issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rY,rX]);class rq extends i.Xsx("GetArtifactAccepted")({ok:ej(!0),artifactId:i.QfV,diagramId:i.QfV,format:eq,mimeType:i.QfV,url:eC(i.QfV),expiresAt:eC(i.QfV),inline:eC(i.$r1),sizeBytes:eC(i.wNn),provenance:eC(eV)},{identifier:void 0}){}class rG extends i.Xsx("GetArtifactRejected")({ok:ej(!1),status:eN(["invalid_input","not_found","format_unavailable","expired","storage_failed"]),issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rq,rG]);class rV extends i.Xsx("ApplyDiagramPatchAccepted")({ok:ej(!0),status:eP("accepted"),patchId:i.QfV,requestId:eC(i.QfV),sourceArtifactId:eC(i.QfV),artifact:rF,issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}class rH extends i.Xsx("ApplyDiagramPatchRejected")({ok:ej(!1),status:eN(["invalid_input","source_unavailable","target_not_found","unsupported_operation","connectivity_changed","render_failed","export_failed","storage_failed"]),patchId:eC(i.QfV),requestId:eC(i.QfV),sourceArtifactId:eC(i.QfV),partial:eC(rB),issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rV,rH]);class rK extends i.Xsx("CreateCanvasAccepted")({ok:ej(!0),status:eP("accepted"),buildId:i.QfV,requestId:eC(i.QfV),normalizedSpec:t4,artifact:rF,issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}class rQ extends i.Xsx("CreateCanvasRejected")({ok:ej(!1),status:eN(["invalid_input","invalid_canvas","limit_exceeded","render_failed","export_failed","storage_failed"]),buildId:eC(i.QfV),requestId:eC(i.QfV),normalizedSpec:eC(t4),partial:eC(rB),issues:i.O31(e1).pipe(i.fXn)},{identifier:void 0}){}let rZ=i.gPz([rK,rQ]),r0=i.xCb(["read","readManifest","write"]);class r1 extends i.rNF()("CodeModeArtifactStorageError",{cause:i.kld(),message:i.QfV,operation:r0}){}class r2 extends a.kl()("@sketchi/diagram-agent/CodeModeArtifactStorage"){}let r5={excalidraw:"application/vnd.excalidraw+json",png:"image/png",scene:"application/vnd.sketchi.scene+json"};function r3(e){return"excalidraw"===e||"scene"===e}function r6(e){return{format:e.format,mimeType:e.mimeType,sizeBytes:e.sizeBytes}}function r8(e){return new TextEncoder().encode(JSON.stringify(e)).length}let r9=l.QZ(r2)(s.Q56(s.OH5(function(){let e=new Map,t=new Map;return{close:s.OH5(()=>{t.clear(),e.clear()}),storage:{read:s.fn("codeMode.artifacts.memory.read")(function*(e,r){return yield*s.OH5(()=>{let n=t.get(`${e}:${r}`);return n?{...n,data:structuredClone(n.data)}:null})}),readManifest:s.fn("codeMode.artifacts.memory.readManifest")(function*(t){return yield*s.OH5(()=>{let r=e.get(t);return r?structuredClone(r):null})}),write:s.fn("codeMode.artifacts.memory.write")(function*(r){var n;let i=yield*o.Ru;return yield*s.SvU({try:()=>{var n;let a,s=r.formats.map(r6),o=r.provenance?structuredClone(r.provenance):void 0,l={artifactId:r.artifactId,diagramId:r.diagramId,formats:s,...o?{provenance:o}:{},createdAt:new Date(i).toISOString()};for(let n of(e.set(r.artifactId,l),r.formats))t.set(`${r.artifactId}:${n.format}`,{...n,data:structuredClone(n.data)});let d=r.formats.map(e=>{var t;return t=r.inlineFormats,{format:e.format,mimeType:e.mimeType,...r3(e.format)&&t.includes(e.format)?{inline:e.data}:{},sizeBytes:e.sizeBytes}});return a=(n={artifactId:r.artifactId,diagramId:r.diagramId,formats:d,...r.provenance?{provenance:structuredClone(r.provenance)}:{}}).formats.find(e=>"scene"===e.format),{artifactId:n.artifactId,diagramId:n.diagramId,formats:n.formats,...n.provenance?{provenance:n.provenance}:{},...a?{preview:a}:{}}},catch:(n="write",e=>{var t;return r1.make({cause:e,message:(t="Artifact storage failed.",e instanceof Error?e.message:t),operation:n})})})})}}}),e=>e.close).pipe(s.TjK(e=>e.storage)));function r4(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."}}function r7(e){return new Map(e.map((e,t)=>[e.id,t]))}function ne(e){return{type:"text",id:`label:${e.nodeId}`,containerId:e.id,x:e.x+e.width/2,y:e.y+e.height/2,text:e.label,fontSize:14,maxWidth:Math.max(1,e.width-36)}}function nt(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function nr(e,t,r){return Math.min(r,Math.max(t,e))}function nn(e,t,r=0){let n,i=(n="top"===t||"bottom"===t?e.width/2-16:e.height/2-16)>0?nr(r,-n,n):0,a=nt(e),s=e.width/2,o=e.height/2;if("diamond"===e.shape&&s>0&&o>0){if("top"===t||"bottom"===t){let e=a.x+i,r=o*(1-Math.abs(i)/s);return{x:e,y:"top"===t?a.y-r:a.y+r}}let e=a.y+i,r=s*(1-Math.abs(i)/o);return{x:"left"===t?a.x-r:a.x+r,y:e}}if(("ellipse"===e.shape||"circle"===e.shape)&&s>0&&o>0){if("top"===t||"bottom"===t){let e=a.x+i,r=o*Math.sqrt(Math.max(0,1-(i/s)**2));return{x:e,y:"top"===t?a.y-r:a.y+r}}let e=a.y+i,r=s*Math.sqrt(Math.max(0,1-(i/o)**2));return{x:"left"===t?a.x-r:a.x+r,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 ni(e){return`${e.edgeId}:${e.endpoint}`}function na(e){let t=[];for(let r of e){let e=t[t.length-1];e&&e.x===r.x&&e.y===r.y||t.push(r)}let r=t[0];return r?[r,...t.slice(1)]:[{x:0,y:0}]}function ns(e,t,r){return e>t+.01&&e<r-.01}function no(e,t,r,n){return Math.min(t,n)-Math.max(e,r)>.01}function nl(e,t,r){let n=0;for(let i=0;i<e.length-1;i+=1){let a=e[i],s=e[i+1];if(a&&s)for(let e of t)!r.has(e.nodeId)&&(a.y===s.y?ns(a.y,e.y,e.y+e.height)&&no(Math.min(a.x,s.x),Math.max(a.x,s.x),e.x,e.x+e.width):a.x===s.x&&ns(a.x,e.x,e.x+e.width)&&no(Math.min(a.y,s.y),Math.max(a.y,s.y),e.y,e.y+e.height))&&(n+=1)}return n}function nd(e){let t=0;for(let r=0;r<e.length-1;r+=1){let n=e[r],i=e[r+1];n&&i&&(t+=Math.abs(i.x-n.x)+Math.abs(i.y-n.y))}return t}function nc(e){let t=[];for(let r=0;r<e.points.length-1;r+=1){let n=e.points[r],i=e.points[r+1];if(n&&i){if(n.y===i.y){t.push({arrowId:e.arrowId,isFirstSegment:0===r,isLastSegment:r===e.points.length-2,max:Math.max(n.x,i.x),min:Math.min(n.x,i.x),orientation:"horizontal",segmentIndex:r,sourceNodeId:e.sourceNodeId,staticCoordinate:n.y,targetNodeId:e.targetNodeId});continue}n.x===i.x&&t.push({arrowId:e.arrowId,isFirstSegment:0===r,isLastSegment:r===e.points.length-2,max:Math.max(n.y,i.y),min:Math.min(n.y,i.y),orientation:"vertical",segmentIndex:r,sourceNodeId:e.sourceNodeId,staticCoordinate:n.x,targetNodeId:e.targetNodeId})}}return t.filter(e=>e.max-e.min>.01)}function nu(e,t){return Math.min(e.max,t.max)-Math.max(e.min,t.min)}function nf(e,t,r){let n=nc({arrowId:`edge:${r.edge.id}`,points:e,sourceNodeId:r.edge.source,targetNodeId:r.edge.target}),i=t.flatMap(e=>nc({arrowId:e.id,points:e.points,sourceNodeId:e.sourceNodeId,targetNodeId:e.targetNodeId})),a=0;for(let e of n)for(let t of i)e.arrowId===t.arrowId||e.orientation!==t.orientation||Math.abs(e.staticCoordinate-t.staticCoordinate)>.01||e.isFirstSegment&&t.isFirstSegment&&e.sourceNodeId===t.sourceNodeId||e.isLastSegment&&t.isLastSegment&&e.targetNodeId===t.targetNodeId||.01>=nu(e,t)||(a+=1);return a}function np(e,t){let r=nc({arrowId:`edge:${t.edge.id}`,points:e,sourceNodeId:t.edge.source,targetNodeId:t.edge.target}),n=0;for(let e=0;e<r.length;e+=1){let t=r[e];if(t)for(let i=e+1;i<r.length;i+=1){let e=r[i];!e||t.orientation!==e.orientation||Math.abs(t.staticCoordinate-e.staticCoordinate)>.01||.01>=nu(t,e)||(n+=1)}}return n}function nh(e){let t=e[0],r=e[e.length-1];if(!t||!r)return 0;let n=e.map(e=>e.x),i=e.map(e=>e.y),a=0;return r.x<t.x?a+=Math.max(0,Math.max(...n)-t.x):r.x>t.x&&(a+=Math.max(0,t.x-Math.min(...n))),r.y<t.y?a+=Math.max(0,Math.max(...i)-t.y):r.y>t.y&&(a+=Math.max(0,t.y-Math.min(...i))),a}function nm(e){let t=e[0],r=e[e.length-1];if(!t||!r)return 0;let n=e.map(e=>e.x),i=e.map(e=>e.y),a=0;return r.x<t.x?a+=Math.max(0,r.x-Math.min(...n)):r.x>t.x&&(a+=Math.max(0,Math.max(...n)-r.x)),r.y<t.y?a+=Math.max(0,r.y-Math.min(...i)):r.y>t.y&&(a+=Math.max(0,Math.max(...i)-r.y)),a}function ng(e,t,r){switch(r){case"top":return t.y<e.y;case"right":return t.x>e.x;case"bottom":return t.y>e.y;case"left":return t.x<e.x}}function ny(e,t){let r=e[0],n=e[1],i=e[e.length-1],a=e[e.length-2],s=0;return n&&ng(r,n,t.sourceEdge)&&(s+=1),a&&i&&ng(i,a,t.targetEdge)&&(s+=1),s}function nv(e,t,r){switch(t){case"top":return{x:e.x,y:e.y-r};case"right":return{x:e.x+r,y:e.y};case"bottom":return{x:e.x,y:e.y+r};case"left":return{x:e.x-r,y:e.y}}}function nb(e,t,r,n,i){var a;let s,o=Math.abs(r.x-t.x)>=Math.abs(r.y-t.y),l=new Set([e.source.nodeId,e.target.nodeId]),d=Math.min(...n.map(e=>e.x)),c=Math.max(...n.map(e=>e.x+e.width)),u=Math.min(...n.map(e=>e.y)),f=Math.max(...n.map(e=>e.y+e.height)),p="left"===e.sourceEdge||"left"===e.targetEdge||nt(e.target).x<nt(e.source).x,h="top"===e.sourceEdge||"top"===e.targetEdge||nt(e.source).y<=nt(e.target).y,m=18*e.index,g=d-56-m,y=c+56+m,v=u-48-m,b=f+48+m,_=e.index%4*18/2,x=Math.min(e.source.x,e.target.x)-56-_,w=Math.max(e.source.x+e.source.width,e.target.x+e.target.width)+56+_,k=Math.min(e.source.y,e.target.y)-48-_,S=Math.max(e.source.y+e.source.height,e.target.y+e.target.height)+48+_,I=p?g:y,$=p?y:g,E=h?v:b,O=h?b:v,C=p?x:w,T=p?w:x,M=h?k:S,A=h?S:k,N=[0,36+e.index%4*18],P=(n,i)=>{let a=i>0?nv(t,e.sourceEdge,i):t,s=i>0?nv(r,e.targetEdge,i):r;return na([t,a,{x:n,y:a.y},{x:n,y:s.y},s,r])},R=(n,i)=>{let a=i>0?nv(t,e.sourceEdge,i):t,s=i>0?nv(r,e.targetEdge,i):r;return na([t,a,{x:a.x,y:n},{x:s.x,y:n},s,r])},j=[...N.map(e=>R(M,e)),...N.map(e=>R(A,e)),...N.map(e=>P(C,e)),...N.map(e=>P(T,e)),...N.map(e=>R(E,e)),...N.map(e=>R(O,e)),...N.map(e=>P(I,e)),...N.map(e=>P($,e))],D=[...N.map(e=>P(C,e)),...N.map(e=>P(T,e)),...N.map(e=>R(M,e)),...N.map(e=>R(A,e)),...N.map(e=>P(I,e)),...N.map(e=>P($,e)),...N.map(e=>R(E,e)),...N.map(e=>R(O,e))];return(s=(a=o?j:D)[0])?a.slice(1).reduce((t,r)=>{let a=nl(t,n,l),s=nl(r,n,l);if(s<a)return r;if(a<s)return t;let o=np(t,e),d=np(r,e);if(d<o)return r;if(o<d)return t;let c=nf(t,i,e),u=nf(r,i,e);if(u<c)return r;if(c<u)return t;let f=ny(t,e),p=ny(r,e);if(p>f)return r;if(f>p)return t;let h=nh(t),m=nh(r);if(m<h)return r;if(h<m)return t;let g=nm(t),y=nm(r);return y<g?r:g<y?t:nd(r)<nd(t)?r:t},s):[{x:0,y:0}]}function n_(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,r=e.text.split("\n").length*e.fontSize*1.35/2;return[{x:e.x-t,y:e.y-r},{x:e.x+t,y:e.y+r}]}return[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]})}function nx(e,t,r){return{x:e.x+t,y:e.y+r}}function nw(e){var t;let r,n,i,a,s,o=N(e),l=function(e){let t="TB"===e.layout.direction||"BT"===e.layout.direction,r=new Map(e.nodes.map(e=>{let t,r,n,i,a;return[e.id,(a=(i=e.label.split("\n").flatMap(e=>(function(e){if(e.length<=18)return[e];let t=[],r="";for(let n of e.split(" ")){if(n.length>18){r&&(t.push(r),r=""),t.push(...function(e){if(e.length<=18)return[e];let t=[];for(let r=0;r<e.length;r+=18)t.push(e.slice(r,r+18));return t}(n));continue}let e=r?`${r} ${n}`:n;if(e.length<=18){r=e;continue}t.push(r),r=n}return r&&t.push(r),t})(e)).join("\n")).split("\n"),t={text:i,width:Math.ceil(14*Math.max(...a.map(e=>e.length))*.62+36),height:Math.ceil(14*a.length*1.35+28)},n="start"===(r=e.kind?.toLowerCase())||"end"===r?"ellipse":"decision"===r?"diamond":"rectangle",{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},shape:n,x:0,y:0,width:Math.max(184,t.width+("diamond"===n?32:20*("ellipse"===n))),height:Math.max(72,t.height+32*("diamond"===n)),label:t.text})]})),n=function(e){let t=new Map,r=new Map;for(let n of e)t.set(n.target,[...t.get(n.target)??[],n]),r.set(n.source,[...r.get(n.source)??[],n]);return{incoming:t,outgoing:r}}(e.edges),i=function(e,t,r){let n=new Map,i=new Set;function a(e){for(let t of(n.set(e,"visiting"),r.get(e)??[])){let e=n.get(t.target);if("visiting"===e){i.add(t.id);continue}e||a(t.target)}n.set(e,"visited")}let s=e.nodes.find(e=>0===(t.get(e.id)??[]).length)??e.nodes[0];for(let t of(s&&a(s.id),e.nodes))n.has(t.id)||a(t.id);return i}(e,n.incoming,n.outgoing),a=function(e,t,r){let n=r7(e.nodes),i=new Map(e.nodes.map(e=>[e.id,0])),a=new Map(e.nodes.map(e=>[e.id,0]));for(let t of e.edges)r.has(t.id)||i.set(t.target,(i.get(t.target)??0)+1);let s=[];for(let t of e.nodes)(i.get(t.id)??0)===0&&s.push(t.id);let o=new Set;for(let e=0;e<s.length;e+=1){let l=s[e];if(!l||o.has(l))continue;o.add(l);let d=a.get(l)??0;for(let o of t.outgoing.get(l)??[]){if(r.has(o.id))continue;a.set(o.target,Math.max(a.get(o.target)??0,d+1));let t=(i.get(o.target)??0)-1;i.set(o.target,t),0===t&&function(e,t,r,n){let i=r.get(t)??Number.MAX_SAFE_INTEGER,a=e.findIndex((e,t)=>t>n&&(r.get(e)??Number.MAX_SAFE_INTEGER)>i);-1===a?e.push(t):e.splice(a,0,t)}(s,o.target,n,e)}}for(let n of e.nodes)!function e(n){if(o.has(n))return a.get(n)??0;let i=0;for(let a of t.incoming.get(n)??[])r.has(a.id)||(i=Math.max(i,e(a.source)+1));return o.add(n),a.set(n,i),i}(n.id);return a}(e,n,i),s=Array.from((function(e,t,r,n,i){let a=r7(e.nodes),s=new Map;for(let n of e.nodes){let e=r.get(n.id)??0,i=t.get(n.id);i&&s.set(e,[...s.get(e)??[],i])}for(let e=0;e<4;e+=1)for(let e of Array.from(s.keys()).sort((e,t)=>e-t)){let t=s.get(e);if(!t||t.length<2)continue;let r=new Map;(s.get(e-1)??[]).forEach((e,t)=>{r.set(e.nodeId,t)});let o=new Map;(s.get(e+1)??[]).forEach((e,t)=>{o.set(e.nodeId,t)});let l=e=>{let t=[...(n.incoming.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>r.get(e.source)).filter(e=>void 0!==e),...(n.outgoing.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>o.get(e.target)).filter(e=>void 0!==e)];return 0===t.length?a.get(e.nodeId)??Number.MAX_SAFE_INTEGER:t.reduce((e,t)=>e+t,0)/t.length};s.set(e,[...t].sort((e,t)=>{let r=l(e)-l(t);return Math.abs(r)>.001?r:(a.get(e.nodeId)??Number.MAX_SAFE_INTEGER)-(a.get(t.nodeId)??Number.MAX_SAFE_INTEGER)}))}return s})(e,r,a,n,i).entries()).sort(([e],[t])=>e-t).map(([e,r])=>({breadth:r.reduce((e,r,n)=>e+(t?r.width:r.height)+112*(n>0),0),depth:Math.max(...r.map(e=>t?e.height:e.width)),rank:e,shapes:r})),o=Math.max(...s.map(e=>e.breadth)),l=48,d=[];for(let e of s){let r=48+Math.max(0,o-e.breadth)/2;for(let n of e.shapes)t?(d.push({...n,x:r,y:l+Math.max(0,e.depth-n.height)/2}),r+=n.width+112):(d.push({...n,x:l+Math.max(0,e.depth-n.width)/2,y:r}),r+=n.height+112);l+=e.depth+96}if("BT"===e.layout.direction){let e=Math.max(...d.map(e=>e.y+e.height));return d.map(t=>({...t,y:48+e-t.y-t.height}))}if("RL"===e.layout.direction){let e=Math.max(...d.map(e=>e.x+e.width));return d.map(t=>({...t,x:48+e-t.x-t.width}))}return d}(o),d=new Map(l.map(e=>[e.nodeId,e])),c=o.edges.map((e,t)=>(function(e,t,r,n){let i=r.get(e.source),a=r.get(e.target);if(!i||!a)throw Error(`Cannot render edge "${e.id}" with unresolved nodes.`);let{sourceEdge:s,targetEdge:o}=function(e,t,r){let n=nt(e),i=nt(t),a=i.x-n.x,s=i.y-n.y,o=e.kind?.toLowerCase();if("LR"===r||"RL"===r)return a>=0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"};if(s<0)return!(Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)>.01)&&Math.abs(a)>Math.abs(s)?{sourceEdge:a>0?"right":"left",targetEdge:"bottom"}:{sourceEdge:"top",targetEdge:"bottom"};let l="decision"===o&&s>e.height+96;return"decision"===o&&s>0&&(0!==a||l)?{sourceEdge:a<0?"left":"right",targetEdge:"top"}:s>0?{sourceEdge:"bottom",targetEdge:"top"}:Math.abs(a)>Math.abs(s)?a>0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"}:{sourceEdge:"top",targetEdge:"bottom"}}(i,a,n);return{edge:e,index:t,source:i,sourceEdge:s,target:a,targetEdge:o}})(e,t,d,o.layout.direction)),u=function(e){let t=new Map;for(let s of e){var r,n,i,a;let e=(r=s.source.nodeId,n=s.sourceEdge,`${r}:${n}`),o=(i=s.target.nodeId,a=s.targetEdge,`${i}:${a}`);t.set(e,[...t.get(e)??[],{edgeId:s.edge.id,endpoint:"source"}]),t.set(o,[...t.get(o)??[],{edgeId:s.edge.id,endpoint:"target"}])}let s=new Map;for(let e of t.values())e.forEach((t,r)=>{s.set(ni(t),(r-(e.length-1)/2)*18)});return s}(c),f=[];for(let e of c)f.push(function(e,t,r,n,i,a){let{edge:s,source:o,sourceEdge:l,target:d,targetEdge:c}=e,u=nn(o,l,r.get(ni({edgeId:s.id,endpoint:"source"}))??0),f=nn(d,c,r.get(ni({edgeId:s.id,endpoint:"target"}))??0),p=na([u,f]);if(function(e,t,r){let n=nt(e),i=nt(t);switch(r){case"TB":return i.y<n.y;case"BT":return i.y>n.y;case"LR":return i.x<n.x;case"RL":return i.x>n.x}}(o,d,a))p=nb(e,u,f,n,i);else if("orthogonal"===t&&u.x!==f.x&&u.y!==f.y){var h,m,g;let t,r,n,i=e.index%4*18,a=(h=u.y,m=f.y,g=f.y<u.y?-i:i,t=h+(m-h)/2,(r=Math.min(h,m)+18)<(n=Math.max(h,m)-18)?nr(t+g,r,n):t),s="left"===l?{x:u.x-36-i,y:u.y}:"right"===l?{x:u.x+36+i,y:u.y}:u,o="left"===c?{x:f.x-36-i,y:f.y}:"right"===c?{x:f.x+36+i,y:f.y}:f;p=na([u,s,{x:s.x,y:a},{x:o.x,y:a},o,f])}return"orthogonal"===t&&(nl(p,n,new Set([o.nodeId,d.nodeId]))>0||np(p,e)>0||nf(p,i,e)>0)&&(p=nb(e,u,f,n,i)),{type:"arrow",id:`edge:${s.id}`,edgeId:s.id,sourceNodeId:s.source,targetNodeId:s.target,points:p,...s.label?{label:s.label}:{}}}(e,o.layout.edgeRouting,u,l,f,o.layout.direction));let p=l.map(ne),h=(i=Math.max(0,48-(n={x:Math.min(...(r=n_(t=[...f,...l,...p])).map(e=>e.x)),y:Math.min(...r.map(e=>e.y))}).x),a=Math.max(0,48-n.y),0===i&&0===a?[...t]:t.map(e=>"arrow"===e.type?{...e,points:function(e,t,r){let[n,...i]=e;return[nx(n,t,r),...i.map(e=>nx(e,t,r))]}(e.points,i,a)}:"line"===e.type?{...e,points:function(e,t,r){let[n,i,...a]=e;return[nx(n,t,r),nx(i,t,r),...a.map(e=>nx(e,t,r))]}(e.points,i,a)}:{...e,x:e.x+i,y:e.y+a})),m={width:Math.max(...(s=n_(h)).map(e=>e.x))+48,height:Math.max(...s.map(e=>e.y))+48},g=[...l.map(e=>e.id),...p.map(e=>e.id),...f.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:o.id,title:o.title,width:m.width,height:m.height,accentColor:o.style.accentColor,backgroundColor:o.style.backgroundColor,elements:h,layers:[],layouts:[],zOrder:g}}let nk="sequence-lifeline";function nS(e){return`${e}:lifeline`}let nI="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",n$=nI.slice(10),nE=new Map;function nO(e){let t=nE.get(e);if(void 0===t){t=new Uint8Array(256);for(let r=0;r<e.length;r++)t[e.charCodeAt(r)]=r;nE.set(e,t)}return t}function nC(e,t,r,n){let i=r[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 a=0;for(;(e[a]||i)===t[a];)a++;if(a>0)return t.slice(0,a)+nC(e.slice(a),t.slice(a),r,n)}let a=e?n[e.charCodeAt(0)]:0,s=null!=t?n[t.charCodeAt(0)]:r.length;return s-a>1?r[Math.round(.5*(a+s))]:t&&t.length>1?t.slice(0,1):r[a]+nC(e.slice(1),null,r,n)}function nT(e,t,r){if(e.length!==nM(e[0],t,r))throw Error("invalid integer part of order key: "+e)}function nM(e,t,r){let n=r[e.charCodeAt(0)];if(t[n]===e){let e=t.length/2;return n<e?e-n+1:n-e+2}throw Error("invalid order key head: "+e)}function nA(e,t,r){let n=nM(e[0],t,r);if(n>e.length)throw Error("invalid order key: "+e);return e.slice(0,n)}function nN(e,t,r,n){if(nj(e,t,r))throw Error("invalid order key: "+e);let i=nA(e,r,n);if(e.slice(i.length).slice(-1)===t[0])throw Error("invalid order key: "+e)}function nP(e,t,r,n,i){nT(e,n,i);let a=e[0],s=t[0],o="";for(let n=e.length-1;n>=1;n--){let i=r[e.charCodeAt(n)]+1;if(i!==t.length)return a+e.slice(1,n)+t[i]+o;o=s+o}let l=i[a.charCodeAt(0)];if(l===n.length-1)return null;let d=n[l+1],c=nM(d,n,i)-nM(a,n,i);return d+(c>0?o+s:c<0?o.slice(1):o)}let nR=new Map;function nj(e,t,r){let n=nR.get(r);void 0===n&&(n=new Map,nR.set(r,n));let i=t.charCodeAt(0),a=n.get(i);return void 0===a&&(a=r[0]+t[0].repeat(r.length/2),n.set(i,a)),e===a}function nD(e){for(let t=1;t<e.length;t++)if(e.charCodeAt(t-1)>=e.charCodeAt(t))return!1;return!0}function nU(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}let nF=new Set,nB=new Set,nL=new Set(["rectangle","ellipse","diamond"]),nz=m.ink;function nW(e){return"number"==typeof e&&Number.isFinite(e)?e:null}function nJ(e){if(!Array.isArray(e)||e.length<2)return null;let t=nW(e[0]),r=nW(e[1]);return null===t||null===r?null:[t,r]}function nY(e){let t=nW(e.x),r=nW(e.y),n=nW(e.width),i=nW(e.height);return null===t||null===r||null===n||null===i?null:{x:t,y:r,width:n,height:i}}function nX(e){return 1e-4>Math.abs(e-.5)?.5001:e}function nq(e,t){let r=nY(e);return r&&0!==r.width&&0!==r.height?[nX((t.x-r.x)/r.width),nX((t.y-r.y)/r.height)]:null}function nG(e,t){return{elementId:e?.id??"",focus:0,gap:0,fixedPoint:e?nq(e,t):null}}function nV(e,t,r){let n=function(e){let t=0x811c9dc5;for(let r of e)t^=r.charCodeAt(0),t=Math.imul(t,0x1000193);return Math.abs(t)||1}(e);return{id:e,angle:0,fillStyle:r&&"fillStyle"in r?r.fillStyle??"solid":"solid",frameId:r?.frameId??null,groupIds:[...r?.groupIds??[]],index:t,isDeleted:!1,link:null,locked:r?.locked??!1,opacity:r?.opacity??100,roughness:r&&"roughness"in r?r.roughness??1:1,seed:n,strokeStyle:r&&"strokeStyle"in r?r.strokeStyle??"solid":"solid",strokeWidth:r&&"strokeWidth"in r?r.strokeWidth??2:2,updated:1,version:1,versionNonce:n+1}}function nH(e){var t,r,n,i;let a=Math.max(1,Math.min(e.maxWidth,(t=e.text,r=e.fontSize,Math.ceil(Math.max(...t.split("\n").map(e=>e.length))*r*.62)))),s=(n=e.text,i=e.fontSize,Math.ceil(n.split("\n").length*i*1.35));return{...nV(e.id,e.index,e.element),...void 0===e.locked?{}:{locked:e.locked},type:"text",x:e.x-a/2,y:e.y-s/2,width:a,height:s,backgroundColor:"transparent",boundElements:null,containerId:e.containerId??null,fontFamily:e.element?.fontFamily==="mono"?3:e.element?.fontFamily==="sans"?2:5,fontSize:e.fontSize,lineHeight:1.35,originalText:e.text,roundness:null,strokeColor:e.textColor??nz,text:e.text,textAlign:e.element?.textAlign??"center",verticalAlign:e.element?.verticalAlign??"middle",autoResize:!0}}function nK(e){return e.points[e.points.length-1]??e.points[0]}function nQ(e,t,r){if(!e)return null;let n=t.get(e.elementId);return n?{elementId:e.elementId,focus:e.focus??0,gap:e.gap??0,fixedPoint:nq(n,r)}:null}function nZ(e){return"node"===e.type}function n0(e){return"text"===e.type}function n1(e){return"arrow"===e.type}function n2(e){return"line"===e.type}function n5(e){return"frame"===e.type}function n3(e,t){let r=e[t];if(!(r&&"object"==typeof r))return null;let n=r.elementId;return"string"==typeof n?n:null}function n6(e){return nJ(e)}function n8(e){let t=nW(e.x)??0,r=nW(e.y)??0,n=n3(e,"startBinding"),i=n3(e,"endBinding"),a=Array.isArray(e.points)?e.points.map(n6).filter(e=>!!e):[],s=[];for(let o=0;o<a.length-1;o+=1){let l=a[o],d=a[o+1];if(!l||!d)continue;let[c,u]=l,[f,p]=d,h=t+c,m=r+u,g=t+f,y=r+p;if(.001>=Math.abs(m-y)){s.push({arrowId:e.id,endBindingElementId:i,isLastSegment:o===a.length-2,max:Math.max(h,g),min:Math.min(h,g),orientation:"horizontal",segmentIndex:o,startBindingElementId:n,staticCoordinate:m});continue}.001>=Math.abs(h-g)&&s.push({arrowId:e.id,endBindingElementId:i,isLastSegment:o===a.length-2,max:Math.max(m,y),min:Math.min(m,y),orientation:"vertical",segmentIndex:o,startBindingElementId:n,staticCoordinate:h})}return s.filter(e=>e.max-e.min>.001)}function n9(e,t,r){return e>t+.01&&e<r-.01}function n4(e,t,r,n){return Math.min(t,n)-Math.max(e,r)>.01}function n7(e){if(nL.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 ie(e,t,r){return e>=t-.01&&e<=r+.01}function it(e,t){return .01>=Math.abs(e-t)}var ir=r(664);r(3614);var ii=r(1594),ia=r(6297),is=r(7258),io=r(2275),il=r(2860),id=r(1554),ic=r(4233);let iu=a.Or("effect/Metric/CurrentMetricAttributes",{defaultValue:()=>({})}),ip=a.Or("effect/Metric/MetricRegistry",{defaultValue:()=>new Map}),ih="~effect/Metric";class im{[ih]=ih;#e;#t="";id;description;attributes;constructor(e,t,r){this.id=e,this.description=t,this.attributes=r}valueUnsafe(e){return this.hook(e).get(e)}modifyUnsafe(e,t){return this.hook(t).modify(e,t)}updateUnsafe(e,t){return this.hook(t).update(e,t)}hook(e){var t;let r,n=a.Jt(e,iu);n!==this.#e&&(this.#e=n,this.#t=(t=this,r=Object.entries(ik(this.attributes,n)).sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0])),JSON.stringify([t.type,t.id,t.description,r])));let i=a.Jt(e,ip),s=i.get(this.#t);return ic.b0(s)&&(s={id:this.id,type:this.type,description:this.description,attributes:Object.keys(n).length>0?ik(this.attributes,n):this.attributes,hooks:this.createHooks()},i.set(this.#t,s)),s.hooks}pipe(){return(0,id.tT)(this,arguments)}}let ig=BigInt(0);class iy extends im{type="Counter";#r;#n;constructor(e,t){super(e,t?.description,iS(t?.attributes)),this.#r=t?.bigint??!1,this.#n=t?.incremental??!1}createHooks(){let e=this.#r?ig:0,t=this.#n?this.#r?e=>e>=ig:e=>e>=0:e=>!0;return iw(()=>({count:e,incremental:this.#n}),r=>{t(r)&&(e+=r)})}}class iv extends im{type;metric;valueUnsafe;updateUnsafe;modifyUnsafe;constructor(e,t,r,n){super(e.id,e.description,e.attributes),this.metric=e,this.valueUnsafe=t,this.updateUnsafe=r,this.modifyUnsafe=n,this.type=e.type}createHooks(){return this.metric.createHooks()}}let ib=(e,t)=>new iy(e,t),i_=(0,ii.XY)(2,(e,t)=>ia.sxi(r=>ia.OH5(()=>e.updateUnsafe(t,r)))),ix=(0,ii.XY)(2,(e,t)=>{var r;let n,i,s=(r=t,i={},e=>{let t=a.Jt(e,iu);return t!==n&&(n=t,i=ik(t,r)),a.WQ(e,iu,i)});return new iv(e,t=>e.valueUnsafe(s(t)),(t,r)=>e.updateUnsafe(t,s(r)),(t,r)=>e.modifyUnsafe(t,s(r)))});function iw(e,t,r){return{get:e,update:t,modify:r??t}}function ik(e,t){return{...iS(e),...iS(t)}}function iS(e){return ic.EA(e)&&Array.isArray(e)?e.reduce((e,[t,r])=>(io.x(e,t,r),e),{}):e}is.F,is.F,ii.MN;var iI=r(1587),i$=(r(6526),r(719),r(2707));let iE=[["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"]],iO=new Set(["artifact_count","artifact_format","artifact_kind","attempt","cache_mode","duration_ms","error_category","error_tag","failure_category","format_count","method","model","operation","outcome","provider","request_kind","retry_kind","sink","status","status_code","surface","timeout_kind","timeout_ms"]),iC=([...iE.map(([,e])=>e),...iO],{metric:()=>void 0}),iT=a.Or("@sketchi/observability/TelemetryExporter",{defaultValue:()=>iC}),iM=a.Or("@sketchi/observability/TelemetryCorrelation",{defaultValue:()=>({})});function iA(e){let t=e?.trim();if(t&&!(t.length>128)&&/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(t))return t}function iN(e,t){return s.JkU(function*(){let r={...yield*iM,...function(e){let t={};for(let[r]of iE){let n=iA(e[r]);n&&(t[r]=n)}return t}(t)},n=function(e){let t={};for(let[r,n]of iE){let i=e[r];i&&(t[n]=i)}return t}(r);return yield*e.pipe(s.PfK(iM,r),s.Muk(n),s.swY(n))})}a.Or("@sketchi/observability/TelemetryResource",{defaultValue:()=>({serviceName:"sketchi"})});let iP=s.fn(function*(e,t,r={}){let n=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},r={};for(let[e,n]of Object.entries(t)){let t=iA(n);t&&(r[e]=t)}return r}(r);yield*i_(ix(e,n),t);let i=yield*iT,a=iI.getOrUndefined((yield*s._32.pipe(s.uKv)));yield*s.OH5(()=>i.metric({attributes:n,metric:e.id,metricType:e.type,...a?{spanId:a.spanId,traceId:a.traceId}:{},value:t}))});i$.W1;let iR=/^(node|step|item|box|thing|process|task)\s*\d*$/i,ij=/^(diagram|untitled|flowchart|chart|sketch)$/i;function iD(e){return e.map(e=>({kind:"node",id:e.id}))}function iU(e){if(void 0===e)return;let t=eh(e);return t.length>0?t:void 0}let iF=["excalidraw","scene"],iB=["scene"];m.card,m.accent,m.ink;let iL=ib("sketchi_codemode_requests",{description:"Code Mode boundary requests by terminal outcome",incremental:!0}),iz=ib("sketchi_codemode_failures",{description:"Code Mode boundary failures by typed status",incremental:!0}),iW=ib("sketchi_codemode_artifacts",{description:"Code Mode artifacts accepted at workflow boundaries",incremental:!0}),iJ=new class e extends im{type="Histogram";#i;constructor(e,t){super(e,t?.description,iS(t?.attributes)),this.#i=t.boundaries}createHooks(){let e=this.#i,t=e.length,r=new Uint32Array(t+1),n=new Float64Array(t),i=0,a=0,s=Number.MAX_VALUE,o=-Number.MAX_VALUE;return ir.Tj(ir.di(e,il.wN),(e,t)=>{n[t]=e}),iw(()=>({buckets:(()=>{let e=ir.CN(t),i=0;for(let a=0;a<t;a++){let t=n[a];i+=r[a],e[a]=[t,i]}return e})(),count:i,min:s,max:o,sum:a}),e=>{let l=0,d=t;for(;l!==d;){let t=Math.floor(l+(d-l)/2);e<=n[t]?d=t:l=t,d===l+1&&(e<=n[l]?d=l:l=d)}r[l]=r[l]+1,i+=1,a+=e,e<s&&(s=e),e>o&&(o=e)})}}("sketchi_codemode_duration_ms",{description:"Code Mode boundary duration in milliseconds",boundaries:(n=[1,5,10,25,50,100,250,500,1e3,2500,5e3,1e4],ir.BC(ir.pb(new Set(n),e=>e>0),1/0))});class iY extends a.kl()("@sketchi/diagram-agent/CodeModeRuntimeEnvironment"){}function iX(e={}){return l.Py(iY,{createId:e.createId??i8,...e.renderer?{renderer:e.renderer}:{},...e.artifactUrl?{artifactUrl:e.artifactUrl}:{}})}function iq(e){return null===e||"object"!=typeof e||Array.isArray(e)?void 0:Object.fromEntries(Object.entries(e))}l.Py(iY,{createId:i8});class iG extends i.rNF()("CodeModeArtifactRenderFailed",{cause:i.kld(),message:i.QfV}){}class iV extends i.rNF()("CodeModeArtifactRendererNotConfigured",{message:i.QfV}){}let iH=i._kM({issues:i.O31(i.O3D(e2)).pipe(i.fXn)});class iK extends i.rNF()("ArtifactExportFailure",{status:i.uSQ("export_failed"),issues:iH.fields.issues}){}class iQ extends i.rNF()("ArtifactStorageFailure",{status:i.uSQ("storage_failed"),cause:i.kld(),issues:iH.fields.issues}){}function iZ(e,t,r){class n extends i.rNF()(e,{message:i.QfV,status:t,context:r}){constructor(e){super({...e,message:e.context.issues[0]?.message??e.status},{disableChecks:!0})}}return n}let i0=iZ("BuildFlowchartFailure",rz.fields.status,rz.mapFields(({ok:e,status:t,...r})=>({...r,...iH.fields}))),i1=iZ("BuildMindmapFailure",rJ.fields.status,rJ.mapFields(({ok:e,status:t,...r})=>({...r,...iH.fields}))),i2=iZ("BuildSequenceDiagramFailure",rX.fields.status,rX.mapFields(({ok:e,status:t,...r})=>({...r,...iH.fields}))),i5=iZ("CreateCanvasFailure",rQ.fields.status,rQ.mapFields(({ok:e,status:t,...r})=>({...r,...iH.fields}))),i3=iZ("GetArtifactFailure",rG.fields.status,rG.mapFields(({ok:e,status:t,...r})=>({...r,...iH.fields}))),i6=iZ("ApplyDiagramPatchFailure",rH.fields.status,rH.mapFields(({ok:e,status:t,...r})=>({...r,...iH.fields})));function i8(e){return`${e}_${globalThis.crypto.randomUUID()}`}function i9(e){return{code:e.code,severity:e.severity??"error",stage:e.stage,...e.ref?{ref:e.ref}:{},message:e.message,hint:e.hint}}function i4(e){return 0===e.length?"input":e.map(e=>"number"==typeof e?`[${e}]`:String(e)).join(".")}function i7(e){let t=i4(e.path);return ae(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 ae(e){return/^operations\.\[\d+\]\.op$/.test(e)}function at(e){let t=e.issues.slice(0,20).map(e=>{let t=i4(e.path);return i9({code:i7(e),stage:"input",ref:{kind:"request",path:t},message:e.message,hint:ae(t)?`Use one of: ${e6.join(", ")}. For label edits, use replaceText with selector plus text.`:"source"===t?"Pass source: { artifactId } from an accepted build or patch, or source: { scene } for inline Sketchi scene patching.":`Fix ${t} so it matches the Code Mode API contract.`})});return e.issues.length>20&&t.push(i9({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."})),t}function ar(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)}function an(e){if(void 0===e)return;let t=eh(e);return t.length>0?t:void 0}function ai(e){return e.checks.map(e=>{var t;return i9({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 aa(e){return e?.artifactFormats??iF}function as(e){return e?.inlineArtifacts??iB}let ao=s.fn("codeMode.artifacts.exportFormats")(function*(e){let t=[];for(let a of e.formats){var r,n,i;let o=yield*(r=e,"scene"===(n=a)?s.PyW(r.scene):"excalidraw"===n?s.PyW(function(e,t={}){return{type:"excalidraw",version:2,source:t.source??"https://sketchi.app",elements:e.elements,appState:e.appState,files:{}}}(r.excalidraw)):r.renderer?r.renderer.renderPng({scene:r.scene,excalidraw:r.excalidraw}).pipe(s.xm_(e=>iG.make({cause:e,message:e.message}))):s.fJG(iV.make({message:"PNG artifact rendering is not configured for this runtime."})));t.push({format:a,mimeType:r5[a],data:o,sizeBytes:(i=o)instanceof ArrayBuffer||i instanceof Uint8Array?i.byteLength:r8(i)})}return t});function al(e){return e.map(e=>i9({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 ad(e){return e.slice(0,20).map(e=>i9({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_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 ac(e){return al(e.filter(e=>"overlapping-arrow-segment"!==e.code&&"arrow-segment-through-node"!==e.code))}function au(e){let t=[];for(let r of e.elements){if("arrow"===r.type){let e=r.points[0],n=r.points[1],i=r.points.slice(2);if(!e||!n)return null;let a=[e,n,...i];t.push({...r,type:"arrow",id:r.id,edgeId:r.edgeId,sourceNodeId:r.sourceNodeId,targetNodeId:r.targetNodeId,...r.strokeColor?{strokeColor:r.strokeColor}:{},...r.strokeStyle?{strokeStyle:r.strokeStyle}:{},...r.textColor?{textColor:r.textColor}:{},points:a,...r.label?{label:r.label}:{}});continue}if("node"===r.type){let n=r.points;if("polygon"===r.shape&&(!n||!n[0]||!n[1]||!n[2]))return null;t.push({type:"node",id:r.id,nodeId:r.nodeId,...r.kind?{kind:r.kind}:{},shape:r.shape,...r.fillColor?{fillColor:r.fillColor}:{},...r.strokeColor?{strokeColor:r.strokeColor}:{},x:r.x,y:r.y,width:r.width,height:r.height,label:r.label,...r.frameId?{frameId:r.frameId}:{},...r.groupIds?{groupIds:[...r.groupIds]}:{},...r.layerId?{layerId:r.layerId}:{},...void 0!==r.locked?{locked:r.locked}:{},...void 0!==r.opacity?{opacity:r.opacity}:{},...void 0!==r.zIndex?{zIndex:r.zIndex}:{},...r.fillStyle?{fillStyle:r.fillStyle}:{},...void 0!==r.roughness?{roughness:r.roughness}:{},...r.strokeStyle?{strokeStyle:r.strokeStyle}:{},...void 0!==r.strokeWidth?{strokeWidth:r.strokeWidth}:{},..."sequence-lifeline"===r.rendererRole&&function(e,t){let r=":lifeline";if(!t.nodeId.endsWith(r)||t.id!==`node:${t.nodeId}`||"rectangle"!==t.shape||2!==t.width||t.height<120)return!1;let n=t.nodeId.slice(0,-r.length);if(0===n.length)return!1;let i=e.elements.find(e=>"node"===e.type&&e.id===`node:${n}`&&e.nodeId===n);return!!i&&.01>=Math.abs(t.x+t.width/2-(i.x+i.width/2))&&t.y>=i.y+i.height-.01}(e,r)?{rendererRole:r.rendererRole}:{},...r.textColor?{textColor:r.textColor}:{},..."polygon"===r.shape&&n?.[0]&&n[1]&&n[2]?{points:[n[0],n[1],n[2],...n.slice(3)]}:{}});continue}if("line"===r.type){let e=r.points[0],n=r.points[1];if(!e||!n)return null;t.push({...r,points:[e,n,...r.points.slice(2)]});continue}t.push(structuredClone(r))}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 af(e){return structuredClone(e)}function ap(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 ah(e){return e.elements.filter(e=>"node"===e.type)}function am(e){return e.elements.filter(e=>"text"===e.type)}function ag(e){return e.elements.filter(e=>"arrow"===e.type)}function ay(e,t){if(!e||0===e.length||!t)return!1;let r=t.trim().toLowerCase();return e.some(e=>e.trim().toLowerCase()===r)}function av(e,t){let r=t?.scope??"all",n=!!(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??[]),a=new Set(t?.nodeIds??[]),s=new Set(t?.edgeIds??[]),o=new Set(t?.kinds??[]),l=ah(e).filter(e=>"edges"!==r&&(!t||!n||i.has(e.id)||a.has(e.nodeId)||!!e.kind&&[...o].some(t=>t===e.kind)||ay(t.labels,e.label))),d=ag(e).filter(e=>"nodes"!==r&&(!t||!n||i.has(e.id)||s.has(e.edgeId)||ay(t.labels,e.label))),c=new Set(l.map(e=>e.id)),u=new Set(d.map(e=>e.id));return{arrows:d,nodes:l,texts:am(e).filter(e=>t&&n?i.has(e.id)||!!e.containerId&&c.has(e.containerId)||!!e.containerId&&u.has(e.containerId)||ay(t.labels,e.text):"nodes"===r?!!e.containerId&&c.has(e.containerId):"edges"!==r||!!e.containerId&&u.has(e.containerId))}}function ab(e){return i9({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 a_(e,t){return am(e).find(e=>e.containerId===t)}function ax(e,t){let r=new Set(t);for(let t of ag(e))(r.has(t.sourceNodeId)||r.has(t.targetNodeId))&&aS(e,t)}function aw(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function ak(e,t,r){let n=aw(e),i=aw(t),a=i.x-n.x,s=i.y-n.y;return 0===a&&0===s?{x:n.x,y:"source"===r?e.y+e.height:e.y}:Math.abs(a)>Math.abs(s)?a>=0?{x:e.x+e.width,y:n.y}:{x:e.x,y:n.y}:s>=0?{x:n.x,y:e.y+e.height}:{x:n.x,y:e.y}}function aS(e,t){let r,n,i=new Map(ah(e).map(e=>[e.nodeId,e])),a=i.get(t.sourceNodeId),s=i.get(t.targetNodeId);if(!a||!s)return[i9({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."})];let o=ak(a,s,"source"),l=ak(s,a,"target");if(Math.abs(l.y-o.y)>=Math.abs(l.x-o.x)){let e=(o.y+l.y)/2;t.points=[o,{x:o.x,y:e},{x:l.x,y:e},l]}else{let e=(o.x+l.x)/2;t.points=[o,{x:e,y:o.y},{x:e,y:l.y},l]}return r=a_(e,t.id),n=function(e){let t=e[0],r=e[e.length-1];if(t&&r)return{x:(t.x+r.x)/2,y:(t.y+r.y)/2-10}}(t.points),r&&n&&(r.x=n.x,r.y=n.y),[]}function aI(e){let t=e.width,r=e.height;for(let n of e.elements)if("arrow"===n.type||"line"===n.type)for(let e of n.points)t=Math.max(t,e.x),r=Math.max(r,e.y);else"text"===n.type?(t=Math.max(t,n.x+(n.maxWidth??0)),r=Math.max(r,n.y+n.fontSize)):(t=Math.max(t,n.x+n.width),r=Math.max(r,n.y+n.height));e.width=t+48,e.height=r+48}function a$(e,t,r){if(!t||!r){if(t){let r=e.indexOf(t);return r>=0?r:void 0}if(r){let t=e.indexOf(r);return t>=0?t+1:void 0}return e.length}}function aE(e,t){return[i9({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 aO=s.fn("codeMode.patch.resolveSource")(function*(e){if("scene"in e.source)return{scene:af(e.source.scene)};let t=yield*r2,r=yield*t.readManifest(e.source.artifactId).pipe(s.xm_(e=>new i6({status:"storage_failed",context:{issues:[r4(e.message,"storage_read_failed")]}})));if(!r||r.artifactId!==e.source.artifactId||!r.formats.some(e=>"scene"===e.format))return yield*new i6({status:"source_unavailable",context:{issues:[i9({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 n=yield*t.read(e.source.artifactId,"scene").pipe(s.xm_(e=>new i6({status:"storage_failed",context:{issues:[r4(e.message,"storage_read_failed")]}})));if(!n)return yield*new i6({status:"source_unavailable",context:{issues:[i9({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 i=t7.safeParse(n.data);return i.success?{scene:af(i.data),sourceArtifactId:e.source.artifactId}:yield*new i6({status:"source_unavailable",context:{issues:[i9({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 aC(e){return e?{requestId:e}:{}}function aT(e){return{diagramId:e.diagramId,formats:[{format:"scene",mimeType:r5.scene,inline:e,sizeBytes:r8(e)}]}}function aM(e){return{ok:!1,status:e.status,...e.context}}function aA(e,t){return r4(e.message,t)}let aN=s.fn("codeMode.artifacts.exportAndStore")(function*(e){let t=yield*iY,r=yield*r2,{excalidraw:n,validation:i}=yield*s.OH5(()=>{let t=function(e){var t;let r,n,i,a,s,o,l,d=(r=new Map(e.layers.map(e=>[e.id,e])),i=new Set((n=e.elements.filter(e=>{let t=e.layerId?r.get(e.layerId):void 0;return t?.visible!==!1})).flatMap(e=>"node"===e.type?[e.nodeId]:[])),s=new Set((a=n.filter(e=>"arrow"!==e.type||i.has(e.sourceNodeId)&&i.has(e.targetNodeId))).flatMap(e=>"text"===e.type?[]:[e.id])),l=new Set((o=a.filter(e=>"text"!==e.type||!e.containerId||s.has(e.containerId))).map(e=>e.id)),o.map(e=>{let t=e.layerId?r.get(e.layerId):void 0;return{...e.frameId&&!l.has(e.frameId)?(({frameId:e,...t})=>t)(e):e,...t?.locked===!0?{locked:!0}:{}}})),c=d.filter(nZ),u=d.filter(n0),f=new Set(d.map(e=>e.id)),p=new Map,h=new Set(u.flatMap(e=>e.containerId?[e.containerId]:[]));for(let e of c){if(h.has(e.id)||e.rendererRole===nk)continue;let t=`__sketchi_node_label__${e.id}`,r=t,n=2;for(;f.has(r);)r=`${t}:${n}`,n+=1;f.add(r),p.set(r,e.id),u.push({type:"text",id:r,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)})}let m=new Map(u.map(e=>[e.containerId??"",e])),g=d.filter(n1),y=d.filter(n2),v=function(e,t,r){let n=new Map,i=new Map(e.map(e=>[e.nodeId,e.id]));for(let e of t)for(let t of[e.sourceNodeId,e.targetNodeId]){let r=i.get(t);r&&n.set(r,[...n.get(r)??[],e.id])}for(let e of r)for(let t of[e.startBinding,e.endBinding])t&&n.set(t.elementId,[...n.get(t.elementId)??[],e.id]);return n}(c,g,y),b=new Map,_=[],x=null,w=()=>{let e=function(e,t,r,n){if(void 0!==n){var i=n;if(!nB.has(i)){if(i.length<2||i.length%2!=0||!nD(i))throw Error("intDigits must be an even number of at least 2 characters in strictly ascending character code order: "+i);if(!nU(i))throw Error("intDigits must be single-byte (char code 0-255): "+i);nB.add(i)}}else n=r??n$;if(void 0!==r){var a=r;if(!nF.has(a)){if(a.length<2||!nD(a))throw Error("digits must be at least 2 characters in strictly ascending character code order: "+a);if(!nU(a))throw Error("digits must be single-byte (char code 0-255): "+a);nF.add(a)}}else r=nI;let s=nO(r),o=nO(n);if(null!=e&&nN(e,r,n,o),null!=t&&nN(t,r,n,o),null!=e&&null!=t&&e>t){let r=e;e=t,t=r}if(null==e){if(null==t)return n[n.length/2]+r[0];let e=nA(t,n,o),i=t.slice(e.length);if(nj(e,r,n))return e+nC("",i,r,s);if(e<t)return e;let a=function(e,t,r,n,i){nT(e,n,i);let a=e[0],s=t[t.length-1],o="";for(let n=e.length-1;n>=1;n--){let i=r[e.charCodeAt(n)]-1;if(-1!==i)return a+e.slice(1,n)+t[i]+o;o=s+o}let l=i[a.charCodeAt(0)];if(0===l)return null;let d=n[l-1],c=nM(d,n,i)-nM(a,n,i);return d+(c>0?o+s:c<0?o.slice(1):o)}(e,r,s,n,o);if(null==a)throw Error("cannot decrement any more");return a}if(null==t){let t=nA(e,n,o),i=e.slice(t.length),a=nP(t,r,s,n,o);return null==a?t+nC(i,null,r,s):a}let l=nA(e,n,o),d=e.slice(l.length),c=nA(t,n,o),u=t.slice(c.length);if(l===c)return l+nC(d,u,r,s);let f=nP(l,r,s,n,o);if(null==f)throw Error("cannot increment any more");return f<t?f:l+nC(d,null,r,s)}(x,null);return x=e,e};for(let t of c){let r=m.get(t.id),n=function(e){let t=e.shape.height,r="circle"===e.shape.shape?"ellipse":e.shape.shape,n=[...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}],[r,...n]=t;return{...nV(e.shape.id,e.index,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"},endArrowhead:null,endBinding:null,lastCommittedPoint:null,points:[...t,r].map(e=>[e.x,e.y]),roundness:null,startArrowhead:null,startBinding:null,strokeColor:e.shape.strokeColor??e.scene.accentColor}}return{...nV(e.shape.id,e.index,e.shape),type:r,x:e.shape.x,y:e.shape.y,width:e.shape.width,height:t,backgroundColor:e.shape.fillColor??"transparent",boundElements:n.length>0?n:null,roundness:"rectangle"===r?{type:3}:null,strokeColor:e.shape.strokeColor??e.scene.accentColor,...e.shape.rendererRole===nk?{customData:{sketchiRendererRole:nk}}:{}}}({scene:e,shape:t,arrowIds:v.get(t.id)??[],index:w(),...r?{text:r}:{}});b.set(t.nodeId,n),_.push(n)}for(let r of d.filter(n5)){let n={...nV((t={element:r,index:w(),scene:e}).element.id,t.index,t.element),type:"frame",x:t.element.x,y:t.element.y,width:t.element.width,height:t.element.height,backgroundColor:t.element.fillColor??"transparent",boundElements:null,name:t.element.name??null,roundness:null,strokeColor:t.element.strokeColor??t.scene.accentColor},i=v.get(r.id)??[];n.boundElements=i.length?i.map(e=>({id:e,type:"arrow"})):null,_.push(n)}for(let e of u){let t=e.containerId&&(c.some(t=>t.id===e.containerId&&"polygon"!==t.shape)||g.some(t=>t.id===e.containerId));_.push(nH({element:e,id:e.id,index:w(),...t?{containerId:e.containerId}:{},fontSize:e.fontSize,maxWidth:e.maxWidth??160,...e.textColor?{textColor:e.textColor}:{},text:e.text,x:e.x,y:e.y}))}for(let t of g){let r=m.get(t.id);_.push(function(e){let t=e.arrow.points[0],r=nK(e.arrow),n=e.arrow.points.length>2;return{...nV(e.arrow.id,e.index,e.arrow),type:"arrow",x:t.x,y:t.y,width:r.x-t.x,height:r.y-t.y,backgroundColor:"transparent",boundElements:e.text?[{id:e.text.id,type:"text"}]:e.arrow.label?[{id:`${e.arrow.id}:label`,type:"text"}]:null,elbowed:n,endArrowhead:void 0===e.arrow.endArrowhead?"arrow":e.arrow.endArrowhead,endBinding:nG(e.targetShape,r),...n?{fixedSegments:[],startIsSpecial:null,endIsSpecial:null}:{},points:e.arrow.points.map(e=>[e.x-t.x,e.y-t.y]),roundness:n?null:{type:2},startArrowhead:e.arrow.startArrowhead??null,startBinding:nG(e.sourceShape,t),strokeColor:e.arrow.strokeColor??e.scene.accentColor,strokeStyle:e.arrow.strokeStyle??"solid"}}({arrow:t,scene:e,index:w(),sourceShape:b.get(t.sourceNodeId),targetShape:b.get(t.targetNodeId),...r?{text:r}:{}}));let n=t.label&&!r?function(e){if(!e.arrow.label)return null;let t=e.arrow.points[0],r=nK(e.arrow);return nH({id:`${e.arrow.id}:label`,index:e.index,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,x:(t.x+r.x)/2,y:(t.y+r.y)/2-10})}({arrow:t,index:w()}):null;n&&_.push(n)}let k=new Map(_.map(e=>[e.id,e]));for(let t of y)if(_.push(function(e){let[t,...r]=e.element.points,n=r[r.length-1]??t,i=void 0!==e.element.startArrowhead||void 0!==e.element.endArrowhead||void 0!==e.element.startBinding||void 0!==e.element.endBinding,a=i&&e.element.points.length>2;return{...nV(e.element.id,e.index,e.element),type:i?"arrow":"line",x:t.x,y:t.y,width:n.x-t.x,height:n.y-t.y,backgroundColor:e.element.fillColor??"transparent",boundElements:null,...i?{elbowed:a}:{},endArrowhead:e.element.endArrowhead??null,endBinding:nQ(e.element.endBinding,e.elementsById,n),...a?{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&&!a?{type:2}:null,startArrowhead:e.element.startArrowhead??null,startBinding:nQ(e.element.startBinding,e.elementsById,t),strokeColor:e.element.strokeColor??e.scene.accentColor}}({element:t,elementsById:k,index:w(),scene:e})),t.label){let e=t.points[0],r=t.points[t.points.length-1]??e;_.push(nH({id:`${t.id}:label`,index:w(),fontSize:13,...void 0===t.locked?{}:{locked:t.locked},maxWidth:160,...t.textColor?{textColor:t.textColor}:{},text:t.label,x:(e.x+r.x)/2,y:(e.y+r.y)/2-10}))}let S=new Map(e.zOrder.map((e,t)=>[e,t])),I=e=>{if(S.has(e.id))return e.id;let t=p.get(e.id);return t||(e.id.endsWith(":label")?e.id.slice(0,-6):e.id)};for(let e of(_.sort((e,t)=>(S.get(I(e))??Number.MAX_SAFE_INTEGER)-(S.get(I(t))??Number.MAX_SAFE_INTEGER)),x=null,_))e.index=w();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:_}}(e.scene);return{excalidraw:t,validation:function(e){let t=[],r=new Map(e.elements.map(e=>[e.id,e])),n=new Set(e.elements.filter(n7).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("arrow"===i.type){let e=!0===i.elbowed;for(let a of((Array.isArray(i.points)?i.points:[]).length>2&&!e&&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[a]||void 0===i[a])continue;let s=n3(i,a);if(!(s&&n.has(s))){t.push({code:"missing-arrow-binding",elementId:i.id,message:`Arrow "${i.id}" has invalid ${a}.`});continue}let o=r.get(s);o&&!function(e,t,r){let n=e.boundElements;return!!Array.isArray(n)&&n.some(e=>!!(e&&"object"==typeof e)&&e.id===t&&e.type===r)}(o,i.id,"arrow")&&t.push({code:"missing-bound-arrow",elementId:o.id,message:`Shape "${o.id}" does not include bound arrow "${i.id}".`});let l=function(e,t){let r=nW(e.x)??0,n=nW(e.y)??0,i=Array.isArray(e.points)?e.points.map(n6).filter(e=>!!e):[],a="startBinding"===t?i[0]:i[i.length-1];return a?{x:r+a[0],y:n+a[1]}:null}(i,a);if(o&&l&&!function(e,t){let r=nY(t);if(!r)return!1;if("diamond"===t.type){let t=r.width/2,n=r.height/2;if(0===t||0===n)return!1;let i=r.x+t,a=r.y+n;return it(Math.abs(e.x-i)/t+Math.abs(e.y-a)/n,1)}if("ellipse"===t.type){let t=r.width/2,n=r.height/2;if(0===t||0===n)return!1;let i=r.x+t,a=r.y+n;return it(((e.x-i)/t)**2+((e.y-a)/n)**2,1)}let n=(it(e.x,r.x)||it(e.x,r.x+r.width))&&ie(e.y,r.y,r.y+r.height),i=(it(e.y,r.y)||it(e.y,r.y+r.height))&&ie(e.x,r.x,r.x+r.width);return n||i}(l,o)&&t.push({code:"arrow-endpoint-off-shape",elementId:i.id,message:`Arrow "${i.id}" ${a} endpoint does not land on "${o.id}".`}),o&&l&&e){let e=function(e,t){let r=e[t];return r&&"object"==typeof r?nJ(r.fixedPoint):null}(i,a);e&&function(e,t,r){let n=nY(r);if(!n)return!1;let i=1e-4>Math.abs(e[0]-.5001)?.5:e[0],a=1e-4>Math.abs(e[1]-.5001)?.5:e[1];return it(n.x+i*n.width,t.x)&&it(n.y+a*n.height,t.y)}(e,l,o)||t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Elbow arrow "${i.id}" has invalid ${a} fixedPoint metadata.`})}}}if("text"===i.type){let e=i.containerId;if("string"!=typeof e)continue;let n=r.get(e);if(!n){t.push({code:"missing-container",elementId:i.id,message:`Text "${i.id}" references missing container "${e}".`});continue}let a="number"==typeof i.width?i.width:0,s="number"==typeof i.height?i.height:0,o="number"==typeof n.width?n.width:0,l="number"==typeof n.height?n.height:0;n7(n)&&(a+24>o||s+18>l)&&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(n8),r=e.filter(n7),n=[],i=new Set;for(let e of t)for(let t of r){if(function(e){let t=e.customData;return null!==t&&"object"==typeof t&&t.sketchiRendererRole===nk}(t)||t.id===e.startBindingElementId||t.id===e.endBindingElementId)continue;let r=nY(t);if(!r||("horizontal"===e.orientation?!(n9(e.staticCoordinate,r.y,r.y+r.height)&&n4(e.min,e.max,r.x,r.x+r.width)):!(n9(e.staticCoordinate,r.x,r.x+r.width)&&n4(e.min,e.max,r.y,r.y+r.height))))continue;let a=`${e.arrowId}:${e.segmentIndex}:${t.id}`;i.has(a)||(i.add(a),n.push({code:"arrow-segment-through-node",elementId:e.arrowId,message:`Arrow "${e.arrowId}" passes through shape "${t.id}".`}))}return n}(e.elements)),t.push(...function(e){let t=e.filter(e=>"arrow"===e.type).flatMap(n8),r=[],n=new Set;for(let e=0;e<t.length;e+=1){let i=t[e];if(i)for(let a=e+1;a<t.length;a+=1){let e=t[a];if(!e||i.arrowId===e.arrowId||i.orientation!==e.orientation||Math.abs(i.staticCoordinate-e.staticCoordinate)>.001||0===i.segmentIndex&&0===e.segmentIndex&&null!==i.startBindingElementId&&i.startBindingElementId===e.startBindingElementId||i.isLastSegment&&e.isLastSegment&&null!==i.endBindingElementId&&i.endBindingElementId===e.endBindingElementId||Math.min(i.max,e.max)-Math.max(i.min,e.min)<=.001)continue;let s=[i.arrowId,i.segmentIndex,e.arrowId,e.segmentIndex].sort().join(":");n.has(s)||(n.add(s),r.push({code:"overlapping-arrow-segment",elementId:i.arrowId,message:`Arrow "${i.arrowId}" overlaps arrow "${e.arrowId}".`}))}}return r}(e.elements)),{ok:0===t.length,issues:t}}(t)}}).pipe(s.fRP("codeMode.artifacts.exportValidate")),a=e.validationIssues(i.issues);if(a.length>0)return yield*new iK({status:"export_failed",issues:a});let o=yield*ao({formats:e.formats,scene:e.scene,excalidraw:n,renderer:t.renderer}).pipe(s.xm_(e=>new iK({status:"export_failed",issues:[i9({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."})]}))),l=yield*s.OH5(()=>t.createId("artifact"));var d=yield*iN(r.write({artifactId:l,diagramId:e.scene.diagramId,formats:o,inlineFormats:e.inlineFormats,...e.provenance?{provenance:e.provenance}:{}}).pipe(s.fRP("codeMode.artifacts.store")),{artifactId:l,...e.requestId?{requestId:e.requestId}:{}}).pipe(s.xm_(e=>new iQ({status:"storage_failed",cause:e,issues:[aA(e,"storage_write_failed")]}))),c=t.artifactUrl;if(!c)return d;let u=d.formats.map(e=>({...e,url:c({artifactId:d.artifactId,format:e.format})})),f=d.preview?u.find(e=>e.format===d.preview?.format):void 0;return{...d,formats:u,...f?{preview:f}:{}}}),aP=s.fn("codeMode.buildMindmap.workflow")(function*(e){var t,r;let n,i,a,o,l,d,c,u,f,p=function(e){let t=iq(iq(iq(e)?.spec)?.root);if(!t)return[];let r=[{depth:0,topic:t}],n=1;for(;r.length>0;){let e=r.pop();if(!e)continue;if(e.depth>8)return[i9({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((n+=t.length)>100)return[i9({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 n=t.length-1;n>=0;n-=1){let i=iq(t[n]);i&&r.push({depth:e.depth+1,topic:i})}}}return[]}(e);if(p.length>0)return yield*new i1({status:"invalid_mindmap",context:{issues:p}});let h=tF.safeParse(e);if(!h.success)return yield*new i1({status:"invalid_input",context:{issues:at(h.error)}});let m=yield*iY,y=h.data,v=yield*s.OH5(()=>m.createId("build")),b=(t=y.spec,n=(e,t)=>({id:`topic-${t.join("-")}`,label:eh(e.label),children:(e.children??[]).map((e,r)=>n(e,[...t,r]))}),i=eh(t.title),{id:an(t.id)??(ar(i)||"sketchi-mindmap"),title:i,root:n(t.root,[0]),layout:{direction:t.layout.direction},style:{...g}}),_={buildId:v,...aC(y.requestId),normalizedSpec:b},x=(a=0,o=0,(l=(e,t)=>{a+=1,o=Math.max(o,t),e.children.forEach(e=>l(e,t+1))})(b.root,0),c=[],(d={count:a,depth:o}).count<2&&c.push(i9({code:"disconnected_graph",stage:"mindmap",ref:{kind:"diagram",id:b.id},message:"Mindmap root must contain at least one child topic.",hint:"Add one or more nested topics under spec.root.children."})),d.depth>8&&c.push(i9({code:"mindmap_too_deep",stage:"mindmap",ref:{kind:"diagram",id:b.id},message:`Mindmap depth ${d.depth} exceeds the supported maximum of 8.`,hint:"Combine overly deep topics into a shallower hierarchy."})),d.count>100&&c.push(i9({code:"mindmap_too_large",stage:"mindmap",ref:{kind:"diagram",id:b.id},message:`Mindmap has ${d.count} topics; the supported maximum is 100.`,hint:"Split this hierarchy into smaller focused mindmaps."})),c);if(x.length>0)return yield*new i1({status:"invalid_mindmap",context:{..._,issues:x}});let w=yield*s.SvU({try:()=>{let e,t,r;return e=[],t=[],(r=(n,i,a,s)=>{e.push({id:n.id,label:n.label,kind:0===i?"root":"topic",metadata:{depth:i,siblingIndex:a}}),s&&t.push({id:`branch-${n.id.slice(6)}`,source:s,target:n.id,metadata:{depth:i,siblingIndex:a}}),n.children.forEach((e,t)=>r(e,i+1,t,n.id))})(b.root,0,0),ee({id:b.id,title:b.title,type:"mindmap",nodes:e,edges:t,layout:{direction:b.layout.direction,edgeRouting:"curved"},style:{...g}})},catch:e=>new i1({status:"invalid_mindmap",context:{..._,issues:[i9({code:"disconnected_graph",stage:"mindmap",ref:{kind:"diagram",id:b.id},message:e instanceof Error?e.message:"Mindmap failed core validation.",hint:"Repair the nested topic hierarchy and call buildMindmap again."})]}})}),k=(r=y.options?.minQualityScore??8,{accepted:(f=Math.max(0,10-2*(u=w.nodes.filter(e=>/^(topic|branch|item|mindmap)$/i.test(e.label.trim()))).length))>=r,score:f,threshold:r,summary:{nodeCount:w.nodes.length,edgeCount:w.edges.length},checks:u.map(e=>({code:"generic_label",passed:!1,severity:"warning",message:`Topic "${e.label}" is too generic.`,refs:[{kind:"node",id:e.id}]}))}),S={..._,quality:k};if(!k.accepted)return yield*new i1({status:"quality_failed",context:{...S,issues:ai(k)}});let I=yield*s.SvU({try:()=>nw(w),catch:e=>new i1({status:"render_failed",context:{...S,issues:[i9({code:"render_failed",stage:"render",ref:{kind:"diagram",id:b.id},message:e instanceof Error?e.message:"Unable to render mindmap scene.",hint:"Simplify the hierarchy or retry with a smaller mindmap."})]}})}).pipe(s.fRP("codeMode.buildMindmap.render")),$={...S,partial:aT(I)},E=yield*aN({scene:I,formats:aa(y.options),inlineFormats:as(y.options),...y.requestId?{requestId:y.requestId}:{},validationIssues:al}).pipe(s.xm_(e=>new i1({status:e.status,context:{..."export_failed"===e.status?$:{...S,partial:{diagramId:I.diagramId}},issues:e.issues}})));return{ok:!0,status:"accepted",buildId:v,...aC(y.requestId),normalizedSpec:b,quality:k,artifact:E,issues:[]}}),aR=s.fn("codeMode.buildSequenceDiagram.workflow")(function*(e){var t,r;let n,i,a,o,l,d=tC.safeParse(e);if(!d.success)return yield*new i2({status:"invalid_input",context:{issues:at(d.error)}});let c=yield*iY,u=d.data,f=yield*s.OH5(()=>c.createId("build")),p=(n=eh((t=u.spec).title),{id:an(t.id)??(ar(n)||"sketchi-sequence"),title:n,participants:t.participants.map(e=>({id:eh(e.id),label:eh(e.label),...e.kind?{kind:eh(e.kind)}:{}})),messages:t.messages.map((e,t)=>({id:an(e.id)??`message-${t+1}-${ar(e.source)}-${ar(e.target)}`,source:eh(e.source),target:eh(e.target),label:eh(e.label),...e.type?{type:e.type}:{},...e.style?{style:e.style}:{}})),style:{...g}}),h={buildId:f,...aC(u.requestId),normalizedSpec:p},m=(i=[],a=new Set,p.participants.forEach((e,t)=>{a.has(e.id)&&i.push(i9({code:"duplicate_node_id",stage:"input",ref:{kind:"request",path:`spec.participants.[${t}].id`},message:`Participant id "${e.id}" is duplicated.`,hint:"Give every participant a unique stable id and update message references."})),a.add(e.id)}),o=new Map(p.participants.map((e,t)=>[e.id,t])),p.participants.forEach(e=>{let t=nS(e.id),r=o.get(t);void 0!==r&&i.push(i9({code:"duplicate_node_id",stage:"input",ref:{kind:"request",path:`spec.participants.[${r}].id`},message:`Participant id "${t}" collides with the generated lifeline for "${e.id}".`,hint:"Rename the participant so its id does not equal another participant id followed by :lifeline."}))}),l=new Set,p.messages.forEach((e,t)=>{l.has(e.id)&&i.push(i9({code:"duplicate_edge_id",stage:"input",ref:{kind:"request",path:`spec.messages.[${t}].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)||i.push(i9({code:"missing_edge_source",stage:"input",ref:{kind:"request",path:`spec.messages.[${t}].source`},message:`Message source "${e.source}" is not a participant.`,hint:"Use the id of a participant declared in spec.participants."})),a.has(e.target)||i.push(i9({code:"missing_edge_target",stage:"input",ref:{kind:"request",path:`spec.messages.[${t}].target`},message:`Message target "${e.target}" is not a participant.`,hint:"Use the id of a participant declared in spec.participants."})),e.source===e.target&&i.push(i9({code:"self_loop",stage:"input",ref:{kind:"request",path:`spec.messages.[${t}]`},message:`Message "${e.id}" is self-referential.`,hint:"Choose a different target participant; self messages are not supported."}))}),i);if(m.length>0)return yield*new i2({status:"invalid_sequence",context:{...h,issues:m}});let y={accepted:10>=(r=u.options?.minQualityScore??8),score:10,threshold:r,summary:{nodeCount:p.participants.length,edgeCount:p.messages.length},checks:[]},v={...h,quality:y};if(!y.accepted)return yield*new i2({status:"quality_failed",context:{...v,issues:ai(y)}});let b=yield*s.SvU({try:()=>(function(e){let t=new Set(e.participants.map(e=>e.id));for(let r of e.participants){let e=nS(r.id);if(t.has(e))throw Error(`Sequence participant "${e}" collides with the generated lifeline for "${r.id}".`)}let r=e.participants.reduce((e,t)=>Math.max(e,Math.ceil(14*t.label.split("\n").length*1.35)+18),72),n=48+r,i=n+64,a=i+88*Math.max(0,e.messages.length-1),s=Math.max(i,a)-n+56,o=new Map,l=[],d=[],c=[];e.participants.forEach((t,i)=>{let a=48+320*i,u=a+90;o.set(t.id,u),l.push({type:"node",id:`node:${t.id}`,nodeId:t.id,...t.kind?{kind:t.kind}:{},shape:"rectangle",x:a,y:48,width:180,height:r,label:t.label}),d.push({type:"text",id:`label:${t.id}`,containerId:`node:${t.id}`,x:u,y:48+r/2,text:t.label,fontSize:14,maxWidth:156}),c.push({type:"node",id:`node:${nS(t.id)}`,nodeId:nS(t.id),rendererRole:nk,shape:"rectangle",fillColor:e.style.backgroundColor,strokeColor:e.style.accentColor,x:u-1,y:n,width:2,height:s,label:`${t.label} lifeline`})});let u=e.messages.map((e,t)=>{let r=o.get(e.source),n=o.get(e.target);if(void 0===r||void 0===n)throw Error(`Sequence message "${e.id}" references an unknown participant.`);if(r===n)throw Error(`Sequence message "${e.id}" cannot target its source participant.`);let a=i+88*t,s=n>r?1:-1;return{type:"arrow",id:`arrow:${e.id}`,edgeId:e.id,sourceNodeId:nS(e.source),targetNodeId:nS(e.target),..."return"===e.type?{strokeColor:"#6b7280"}:{},..."dashed"===e.style||"return"===e.type?{strokeStyle:"dashed"}:{},points:[{x:r+2*s/2,y:a},{x:n-2*s/2,y:a}],label:e.label}}),f=[...u,...c,...l,...d],p=[...c.map(e=>e.id),...l.map(e=>e.id),...d.map(e=>e.id),...u.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:276+320*Math.max(0,e.participants.length-1),height:n+s+48,accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:f,layers:[],layouts:[],zOrder:p}})(p),catch:e=>new i2({status:"render_failed",context:{...v,issues:[i9({code:"render_failed",stage:"render",ref:{kind:"diagram",id:p.id},message:e instanceof Error?e.message:"Unable to render sequence diagram scene.",hint:"Repair the participant/message structure and retry."})]}})}).pipe(s.fRP("codeMode.buildSequenceDiagram.render")),_=ea(b);if(_.length>0)return yield*new i2({status:"render_failed",context:{...v,issues:ad(_).map(e=>({...e,hint:"Reduce participant label lines, participants, or messages and retry buildSequenceDiagram."}))}});let x={...v,partial:aT(b)},w=yield*aN({scene:b,formats:aa(u.options),inlineFormats:as(u.options),...u.requestId?{requestId:u.requestId}:{},validationIssues:al}).pipe(s.xm_(e=>new i2({status:e.status,context:{..."export_failed"===e.status?x:v,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:f,...aC(u.requestId),normalizedSpec:p,quality:y,artifact:w,issues:[]}}),aj=i._kM({spec:i.$r1,requestId:i.Qrq(i.$r1)}),aD=i._kM({source:i._kM({scene:i.$r1})}),aU=s.fn("codeMode.canvas.serializedLimit")((e,t)=>s.SvU(()=>r8(e)).pipe(s.YWq({onFailure:()=>i9({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<=er.maxSerializedBytes?void 0:i9({code:"canvas_limit_exceeded",stage:"canvas",ref:{kind:"request",path:t},message:`CanvasSpec exceeds ${er.maxSerializedBytes} serialized bytes.`,hint:"Split the visualization into a smaller canvas or reduce repeated text and points."})}))),aF=s.fn("codeMode.createCanvas.workflow")(function*(e){let t=yield*iY,r=yield*s.OH5(()=>t.createId("build")),n=i.q$Z(aj)(e),a=u.oJ(n)?{spec:n.success.spec,requestId:i.is(i.QfV)(n.success.requestId)?n.success.requestId:void 0}:void 0;if(a){let e=yield*aU(a.spec,"spec");if(e)return yield*new i5({status:"canvas_limit_exceeded"===e.code?"limit_exceeded":"invalid_input",context:{buildId:r,...aC(a.requestId),issues:[e]}})}let o=rt.safeParse(e);if(!o.success)return yield*new i5({status:"invalid_input",context:{issues:at(o.error)}});let l=o.data,d={buildId:r,...aC(l.requestId)},c=au(l.spec);if(!c)return yield*new i5({status:"invalid_canvas",context:{...d,issues:[i9({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 f=ea(c).filter(e=>"limit_exceeded"===e.code);if(f.length>0)return yield*new i5({status:"limit_exceeded",context:{...d,issues:ad(f)}});let p=function(e){let t=[...e.elements];for(let r of e.layouts)t=function(e,t){switch(t.type){case"row":case"column":case"stack":return function(e,t){let r=eo(e,t.ids),n=r[0];if(!n)return[...e];let i=es(n),a=t.x??i.x,s=t.y??i.y,o="stack"===t.type?t.gap??0:t.gap??32,l=new Map,d="column"===t.type?s:a;for(let e of r){let r=es(e);l.set(e.id,{x:"column"===t.type||"stack"===t.type?a:d,y:"column"===t.type?d:s}),"stack"!==t.type&&(d+=("column"===t.type?r.height:r.width)+o)}return el(e,l)}(e,t);case"grid":return function(e,t){let r=eo(e,t.ids);if(0===r.length)return[...e];let n=Math.max(1,Math.floor(t.columns)),i=r.map(es),a=Array.from({length:n},(e,t)=>Math.max(0,...i.filter((e,r)=>r%n===t).map(e=>e.width))),s=Array.from({length:Math.ceil(r.length/n)},(e,t)=>Math.max(0,...i.filter((e,r)=>Math.floor(r/n)===t).map(e=>e.height))),o=i[0];if(!o)return[...e];let l=t.x??o.x,d=t.y??o.y,c=t.columnGap??32,u=t.rowGap??32,f=new Map;return r.forEach((e,t)=>{let r=t%n,i=Math.floor(t/n);f.set(e.id,{x:l+a.slice(0,r).reduce((e,t)=>e+t,0)+c*r,y:d+s.slice(0,i).reduce((e,t)=>e+t,0)+u*i})}),el(e,f)}(e,t);case"align":return function(e,t){let r=eo(e,t.ids);if(0===r.length)return[...e];let n=r.map(es),i=n.map(e=>ed(e,t.axis)),a=n.map(e=>ed(e,t.axis)+ec(e,t.axis)),s=n.map(e=>ed(e,t.axis)+ec(e,t.axis)/2),o="start"===t.alignment?Math.min(...i):"end"===t.alignment?Math.max(...a):s.reduce((e,t)=>e+t,0)/s.length,l=new Map;return r.forEach((e,r)=>{let i=n[r];if(!i)return;let a="start"===t.alignment?o:"end"===t.alignment?o-ec(i,t.axis):o-ec(i,t.axis)/2;l.set(e.id,{x:"x"===t.axis?a:i.x,y:"y"===t.axis?a:i.y})}),el(e,l)}(e,t);case"distribute":return function(e,t){let r=eo(e,t.ids).sort((e,r)=>ed(es(e),t.axis)-ed(es(r),t.axis));if(r.length<2)return[...e];let n=r.map(es),i=n[0],a=n[n.length-1];if(!i||!a)return[...e];let s=ed(i,t.axis),o=ed(a,t.axis)+ec(a,t.axis),l=n.reduce((e,r)=>e+ec(r,t.axis),0),d=t.gap??Math.max(0,(o-s-l)/(r.length-1)),c=new Map,u=s;return r.forEach((e,r)=>{let i=n[r];i&&(c.set(e.id,{x:"x"===t.axis?u:i.x,y:"y"===t.axis?u:i.y}),u+=ec(i,t.axis)+d)}),el(e,c)}(e,t)}}(t,r);let r=function(e){let t=1,r=1;for(let n of e)if(ei(n)){let e=es(n);t=Math.max(t,e.x+e.width),r=Math.max(r,e.y+e.height)}else if("arrow"===n.type||"line"===n.type)for(let e of n.points)t=Math.max(t,e.x),r=Math.max(r,e.y);return{width:t+48,height:r+48}}(t=function(e){let t=new Map(e.filter(e=>"node"===e.type).map(e=>[e.nodeId,e])),r=new Map;for(let t of e)("node"===t.type||"frame"===t.type)&&r.set(t.id,t);let n=e.map(e=>{if("arrow"===e.type){let r=t.get(e.sourceNodeId),n=t.get(e.targetNodeId);return r&&n?{...e,points:[ef(r,eu(n)),...e.points.slice(1,-1),ef(n,eu(r))]}:e}if("line"===e.type){let t=e.startBinding?r.get(e.startBinding.elementId):void 0,n=e.endBinding?r.get(e.endBinding.elementId):void 0;if(!t&&!n)return e;let i=[e.points[0],e.points[1],...e.points.slice(2)];return t&&(i[0]=ef(t,n?eu(n):i[i.length-1]??i[0])),n&&(i[i.length-1]=ef(n,t?eu(t):i[0])),{...e,points:i}}return e}),i=new Map(n.map(e=>[e.id,e]));return n.map(e=>{if("text"!==e.type||!e.containerId)return e;let t=i.get(e.containerId);if(t?.type==="node"){let r=eu(t);return{...e,x:r.x,y:r.y}}if(t?.type==="arrow"){let r=t.points[0],n=t.points[t.points.length-1]??r;return{...e,x:(r.x+n.x)/2,y:(r.y+n.y)/2}}return e})}(t)),n=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,r.width),height:Math.max(e.height,r.height),elements:t,zOrder:n}}(c),h=ea(p);if(h.length>0){let e=ad(h);return yield*new i5({status:e.some(e=>"canvas_limit_exceeded"===e.code)?"limit_exceeded":"invalid_canvas",context:{...d,normalizedSpec:p,issues:e}})}let m={...d,normalizedSpec:p,partial:aT(p)},g=yield*aN({scene:p,formats:aa(l.options),inlineFormats:as(l.options),...l.requestId?{requestId:l.requestId}:{},validationIssues:ac}).pipe(s.xm_(e=>new i5({status:e.status,context:{...m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:r,...aC(l.requestId),normalizedSpec:p,artifact:g,issues:[]}}),aB=s.fn("codeMode.buildFlowchart.workflow")(function*(e){var t,r;let n,i=tE.safeParse(e);if(!i.success)return yield*new i0({status:"invalid_input",context:{issues:at(i.error)}});let a=yield*iY,o=i.data,l=yield*s.OH5(()=>a.createId("build")),d=(n=eh((r=o.spec).title),{id:iU(r.id)??(n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"sketchi-flowchart"),title:n,nodes:r.nodes.map(e=>({id:eh(e.id),label:eh(e.label),kind:e.kind,...e.description?{description:eh(e.description)}:{}})),edges:r.edges.map((e,t)=>({id:iU(e.id)??`edge-${t+1}`,source:eh(e.source),target:eh(e.target),...e.label?{label:eh(e.label)}:{}})),layout:{direction:r.layout.direction},style:{...g}}),c={buildId:l,...aC(o.requestId),normalizedSpec:d},u=eb(L,{id:d.id,title:d.title,type:"flowchart",nodes:d.nodes.map(e=>({...e,metadata:{}})),edges:d.edges.map(e=>({...e,metadata:{}})),layout:{direction:d.layout.direction,edgeRouting:"orthogonal"},style:d.style,metadata:{}});if(!u.success)return yield*new i0({status:"invalid_flowchart",context:{...c,issues:(t=u.error,t.issues.slice(0,20).map(e=>{let t=function(e,t){let r=i4(e.path),n="input"===r?"spec":`spec.${r}`,[i,a]=e.path;if("nodes"===i&&"number"==typeof a){let e=t.nodes[a]?.id;return{kind:"node",...e?{id:e}:{},path:n}}if("edges"===i&&"number"==typeof a){let e=t.edges[a]?.id;return{kind:"edge",...e?{id:e}:{},path:n}}return{kind:"diagram",id:t.id,path:n}}(e,d);return i9({code:i7(e),stage:"flowchart",ref:t,message:e.message,hint:`Fix ${t.path??"spec"} so normalization produces a valid canonical flowchart value.`})}))}});let f=u.data,p=J(f).map(e=>{let t=function(e){if(e)return{kind:e.kind,...e.id?{id:e.id}:{},...e.path?{path:`spec.${e.path}`}:{}}}(e.ref);return i9({code:e.code,stage:"flowchart",...t?{ref:t}:{},message:e.message,hint:e.hint})});if(p.length>0)return yield*new i0({status:"invalid_flowchart",context:{...c,issues:p}});X(f);let h=function(e,t){let r=[],n=0,i=(e,t,i,a=!1)=>{n+=e,r.push({...i,passed:!1,severity:a?"error":"warning",message:t})},a=new Map,s=new Map;for(let t of e.edges)a.set(t.source,(a.get(t.source)??0)+1),a.set(t.target,(a.get(t.target)??0)+1),s.set(t.source,[...s.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:iD(e.nodes)},!0);else{let t=e.nodes.filter(e=>(a.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:iD(t)},!0);let r=function(e){let t=new Map;for(let r of e.nodes)t.set(r.id,[]);for(let r of e.edges)t.get(r.source)?.push(r.target),t.get(r.target)?.push(r.source);let r=new Set,n=0;for(let i of e.nodes){if(r.has(i.id))continue;n+=1;let e=[i.id];for(r.add(i.id);e.length>0;){let n=e.pop();if(void 0===n)break;for(let i of t.get(n)??[])r.has(i)||(r.add(i),e.push(i))}}return n}(e);r>1&&0===t.length&&i(2,`diagram splits into ${r} disconnected islands`,{code:"disconnected_graph",refs:iD(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 o=new Map;for(let t of e.nodes){let e=t.label.trim().toLowerCase();o.set(e,(o.get(e)??0)+1)}let l=[...o.entries()].filter(([,e])=>e>1);l.length>0&&i(Math.min(l.length,3),`duplicate label(s): ${l.map(([e])=>`"${e}"`).join(", ")}`,{code:"duplicate_label",refs:iD(e.nodes.filter(e=>(o.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:iD([t])});continue}let e=s.get(t.id)??[];e.length<2?(d+=1,i(0,`decision "${t.id}" needs at least 2 outgoing branches`,{code:"underbranched_decision",refs:iD([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:iD([t])}))}n+=Math.min(1.5*d,4.5)+Math.min(c,3);let u=e.nodes.filter(e=>e.label.length>42);u.length>0&&i(Math.min(.5*u.length,2),`shorten label(s): ${u.map(e=>e.id).join(", ")}`,{code:"label_too_long",refs:iD(u)});let f=e.nodes.filter(e=>iR.test(e.label.trim()));f.length>0&&i(Math.min(f.length,3),`generic label(s) say nothing: ${f.map(e=>`"${e.label}"`).join(", ")}`,{code:"generic_label",refs:iD(f)}),(e.title.trim().length<4||ij.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 p=Math.max(0,Math.round((10-n)*10)/10);return{accepted:p>=t&&!r.some(e=>"error"===e.severity),score:p,threshold:t,summary:{nodeCount:e.nodes.length,edgeCount:e.edges.length},checks:r}}(f,o.options?.minQualityScore??8),m={...c,quality:h};if(!h.accepted)return yield*new i0({status:"quality_failed",context:{...m,issues:ai(h)}});let y=yield*s.SvU({try:()=>nw(f),catch:e=>new i0({status:"render_failed",context:{...m,issues:[i9({code:"render_failed",stage:"render",ref:{kind:"diagram",id:d.id},message:e instanceof Error?e.message:"Unable to render flowchart scene.",hint:"Simplify the graph or retry with a smaller flowchart."})]}})}).pipe(s.fRP("codeMode.buildFlowchart.render")),v={...m,partial:aT(y)},b=yield*aN({scene:y,formats:aa(o.options),inlineFormats:as(o.options),...o.requestId?{requestId:o.requestId}:{},validationIssues:al}).pipe(s.xm_(e=>new i0({status:e.status,context:{..."export_failed"===e.status?v:m,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:l,...aC(o.requestId),normalizedSpec:d,quality:h,artifact:b,issues:[]}}),aL=s.fn("codeMode.getArtifact.workflow")(function*(e){let t=ro.safeParse(e);if(!t.success)return yield*new i3({status:"invalid_input",context:{issues:at(t.error)}});let r=yield*iY,n=yield*r2,i=t.data,a=yield*n.readManifest(i.artifactId).pipe(s.xm_(e=>new i3({status:"storage_failed",context:{issues:[aA(e,"storage_read_failed")]}})));if(!a)return yield*new i3({status:"not_found",context:{issues:[i9({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:i.artifactId},message:`Artifact "${i.artifactId}" was not found.`,hint:"Use the artifactId returned by buildFlowchart or applyDiagramPatch."})]}});let o=i.format??"scene";if(!a.formats.some(e=>e.format===o))return yield*new i3({status:"format_unavailable",context:{issues:[i9({code:"unsupported_artifact_format",stage:"storage",ref:{kind:"artifact",id:i.artifactId},message:`Artifact "${i.artifactId}" does not include format "${o}".`,hint:"Request a format listed in the artifact bundle."})]}});let l=yield*n.read(i.artifactId,o).pipe(s.xm_(e=>new i3({status:"storage_failed",context:{issues:[aA(e,"storage_read_failed")]}})));return l?{ok:!0,artifactId:i.artifactId,diagramId:a.diagramId,format:o,mimeType:l.mimeType,...r.artifactUrl?{url:r.artifactUrl({artifactId:i.artifactId,format:o})}:{},...!0!==i.inline||!r3(o)?{}:{inline:l.data},sizeBytes:l.sizeBytes,...a.provenance?{provenance:a.provenance}:{}}:yield*new i3({status:"format_unavailable",context:{issues:[i9({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:i.artifactId},message:`Artifact "${i.artifactId}" format "${o}" could not be read.`,hint:"Retry retrieval or rebuild the artifact."})]}})}),az=s.fn("codeMode.applyDiagramPatch.workflow")(function*(e){let t,r=i.q$Z(aD)(e),n=u.oJ(r)?yield*aU(r.success.source.scene,"source.scene"):void 0;if(n)return yield*new i6({status:"invalid_input",context:{issues:[n]}});let a=rM.safeParse(e);if(!a.success)return yield*new i6({status:"invalid_input",context:{issues:at(a.error)}});let o=yield*iY,l=a.data,d=yield*s.OH5(()=>o.createId("patch")),c={patchId:d,...aC(l.requestId)},f=yield*aO(l).pipe(s.xm_(e=>new i6({status:e.status,context:{...c,...e.context}}))),p={...c,...f.sourceArtifactId?{sourceArtifactId:f.sourceArtifactId}:{}},h=f.scene;if(h.elements.length>er.maxElements)t=[{code:"limit_exceeded",message:`Canvas exceeds ${er.maxElements} elements.`,path:"elements"}];else{let e=au(h);t=e?ea(e).filter(e=>"limit_exceeded"===e.code):[]}if(t.length>0)return yield*new i6({status:"invalid_input",context:{...p,issues:ad(t)}});let m=ap(h),g=[];for(let e of l.operations)if((g=function(e,t){switch(t.op){case"setDefaultStyle":case"setStyle":if(t.style.backgroundColor&&(e.backgroundColor=t.style.backgroundColor),"setDefaultStyle"===t.op){for(let r of(t.style.strokeColor&&(e.accentColor=t.style.strokeColor),ah(e)))t.style.fillColor&&(r.fillColor=t.style.fillColor),t.style.strokeColor&&(r.strokeColor=t.style.strokeColor),t.style.textColor&&(r.textColor=t.style.textColor);for(let r of ag(e))t.style.strokeColor&&(r.strokeColor=t.style.strokeColor),t.style.textColor&&(r.textColor=t.style.textColor);for(let r of am(e))t.style.textColor&&(r.textColor=t.style.textColor);return[]}let r=av(e,t.selector);if(0===r.nodes.length&&0===r.arrows.length&&0===r.texts.length)return[ab(t)];for(let n of r.nodes)if(t.style.fillColor&&(n.fillColor=t.style.fillColor),t.style.strokeColor&&(n.strokeColor=t.style.strokeColor),t.style.textColor){n.textColor=t.style.textColor;let r=a_(e,n.id);r&&(r.textColor=t.style.textColor)}for(let n of r.arrows)if(t.style.strokeColor&&(n.strokeColor=t.style.strokeColor),t.style.textColor){n.textColor=t.style.textColor;let r=a_(e,n.id);r&&(r.textColor=t.style.textColor)}for(let e of r.texts)t.style.textColor&&(e.textColor=t.style.textColor);return[];case"setShape":let n=av(e,t.selector);if(0===n.nodes.length)return[ab(t)];let i=[];for(let r of n.nodes){if(r.shape=t.shape,"polygon"===t.shape?r.points=[{x:r.width/2,y:0},{x:r.width,y:r.height/2},{x:r.width/2,y:r.height},{x:0,y:r.height/2}]:delete r.points,"circle"===t.shape){let e=Math.max(r.width,r.height);r.x-=(e-r.width)/2,r.y-=(e-r.height)/2,r.width=e,r.height=e,i.push(r.nodeId)}!function(e,t){let r=a_(e,t.id);r&&(r.x=t.x+t.width/2,r.y=t.y+t.height/2)}(e,r)}return ax(e,i),[];case"translate":return function(e,t){let r=av(e,t.selector);if(0===r.nodes.length&&0===r.arrows.length&&0===r.texts.length)return[ab(t)];let n=new Set,i=new Set;for(let a of r.nodes){a.x+=t.dx,a.y+=t.dy,n.add(a.nodeId);let r=a_(e,a.id);r&&(r.x+=t.dx,r.y+=t.dy,i.add(r.id))}for(let n of r.arrows){n.points=n.points.map(e=>{var r,n;return r=t.dx,n=t.dy,{x:e.x+r,y:e.y+n}});let r=a_(e,n.id);r&&(r.x+=t.dx,r.y+=t.dy,i.add(r.id))}for(let e of r.texts)i.has(e.id)||(e.x+=t.dx,e.y+=t.dy);return ax(e,[...n]),aI(e),[]}(e,t);case"replaceText":let a=av(e,t.selector);if(0===a.nodes.length&&0===a.arrows.length&&0===a.texts.length)return[ab(t)];for(let r of a.nodes){r.label=t.text;let n=a_(e,r.id);n&&(n.text=t.text)}for(let r of a.arrows){r.label=t.text;let n=a_(e,r.id);n&&(n.text=t.text)}for(let e of a.texts)e.text=t.text;return[];case"rerouteEdges":let s;return 0===(s=av(e,t.selector)).arrows.length?[ab(t)]:s.arrows.flatMap(t=>aS(e,t));case"insert":let o=new Set(e.elements.map(e=>e.id)),l=t.elements.map(e=>e.id);if(new Set(l).size!==l.length||l.some(e=>o.has(e)))return aE(t,"Inserted elements must use ids that are unique within the canvas.");let d=a$(e.zOrder,t.beforeId,t.afterId);return void 0===d?aE(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,...l),[]);case"remove":return function(e,t){let r,n=function(e,t){let r=av(e,t),n=new Set([...r.nodes.map(e=>e.id),...r.arrows.map(e=>e.id),...r.texts.map(e=>e.id)]),i=new Set(t.ids??[]);for(let t of e.elements)i.has(t.id)&&n.add(t.id);return n}(e,t.selector);if(0===n.size)return[ab(t)];let i=new Set(e.elements.flatMap(e=>"node"===e.type&&n.has(e.id)?[e.nodeId]:[]));do for(let t of(r=n.size,e.elements))("text"===t.type&&t.containerId&&n.has(t.containerId)||"arrow"===t.type&&(i.has(t.sourceNodeId)||i.has(t.targetNodeId))||"line"===t.type&&(t.startBinding&&n.has(t.startBinding.elementId)||t.endBinding&&n.has(t.endBinding.elementId)))&&n.add(t.id);while(n.size!==r)let a=e.elements.filter(e=>!n.has(e.id)).map(e=>{if(e.frameId&&n.has(e.frameId)){let{frameId:t,...r}=e;return r}return e});e.elements.splice(0,e.elements.length,...a);let s=e.zOrder.filter(e=>!n.has(e));e.zOrder.splice(0,e.zOrder.length,...s);let o=e.layouts.map(e=>({...e,ids:e.ids.filter(e=>!n.has(e))})).filter(e=>e.ids.length>0);return e.layouts.splice(0,e.layouts.length,...o),aI(e),[]}(e,t);case"replace":let c;return(c=e.elements.findIndex(e=>e.id===t.id))<0?[ab(t)]:t.element.id!==t.id?aE(t,"Replacement element id must match the stable id being replaced."):(e.elements.splice(c,1,structuredClone(t.element)),aI(e),[]);case"reorder":let u=new Set(t.ids);if(u.size!==t.ids.length||t.ids.some(t=>!e.zOrder.includes(t)))return aE(t,"Reorder ids must be unique ids already present in zOrder.");let f=e.zOrder.filter(e=>!u.has(e)),p=a$(f,t.beforeId,t.afterId);return void 0===p?aE(t,"Reorder specifies an unknown anchor or both beforeId and afterId."):(f.splice(p,0,...t.ids),e.zOrder.splice(0,e.zOrder.length,...f),[]);case"group":case"ungroup":let h=new Set(t.ids);if(t.ids.some(t=>!e.elements.some(e=>e.id===t)))return[ab(t)];let m=e.elements.map(e=>h.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,...m),[]}}(h,e)).length>0)break;if(g.length>0)return yield*new i6({status:g[0]?.code==="unknown_patch_target"?"target_not_found":"unsupported_operation",context:{...p,issues:g}});if(l.options?.preserveConnectivity!==!1){let e=ap(h);if(!(m.length===e.length&&m.every((t,r)=>t===e[r])))return yield*new i6({status:"connectivity_changed",context:{...p,issues:[i9({code:"patch_preserve_connectivity_failed",stage:"flowchart",ref:{kind:"diagram",id:h.diagramId},message:"Patch changed the diagram edge connectivity.",hint:"Use buildFlowchart for process-graph structure or buildMindmap for hierarchy structure."})]}})}let y=au(h);if(!y)return yield*new i6({status:"render_failed",context:{...p,issues:[i9({code:"patch_output_invalid",stage:"render",ref:{kind:"diagram",id:h.diagramId},message:"Patched scene has an invalid arrow point list.",hint:"Reroute edges or rebuild the flowchart artifact."})]}});let v=ea(y);if(v.length>0)return yield*new i6({status:"render_failed",context:{...p,partial:aT(y),issues:ad(v)}});let b={...p,partial:aT(y)},_=yield*aN({scene:y,formats:aa(l.options),inlineFormats:as(l.options),...l.requestId?{requestId:l.requestId}:{},validationIssues:ac,...f.sourceArtifactId?{provenance:{sourceArtifactId:f.sourceArtifactId}}:{}}).pipe(s.xm_(e=>new i6({status:e.status,context:{..."export_failed"===e.status?b:p,issues:e.issues}})));return{ok:!0,status:"accepted",patchId:d,...aC(l.requestId),...f.sourceArtifactId?{sourceArtifactId:f.sourceArtifactId}:{},artifact:_,issues:[]}});function aW(e,t,r){return s.fn(`codeMode.${e}`)(n=>{var i,a,l;let d,c,u,f;return i=e,a=n,l=t(n).pipe(s.YWq({onFailure:r,onSuccess:e=>e})),iN(s.JkU(function*(){let e=yield*o.Ru,t=yield*l,r=yield*o.Ru,n=t.ok?"success":"failure",a=t.ok?void 0:t.status??"unknown_failure";yield*iP(iL,1,{...a?{failureCategory:a}:{},operation:i,outcome:n,surface:"code_mode"}),yield*iP(iJ,r-e,{...a?{failureCategory:a}:{},operation:i,outcome:n,surface:"code_mode"}),a&&(yield*iP(iz,1,{failureCategory:a,operation:i,surface:"code_mode"}));let s="buildFlowchart"===i?"flowchart":"buildMindmap"===i?"mindmap":"buildSequenceDiagram"===i?"sequence":"createCanvas"===i?"canvas":"applyDiagramPatch"===i?"patch":void 0;return t.ok&&s&&(yield*iP(iW,1,{artifactKind:s,operation:i,surface:"code_mode"})),t}),(d=iq(a),c=iq(d?.source),u="string"==typeof d?.artifactId?d.artifactId:"string"==typeof c?.artifactId?c.artifactId:void 0,f="string"==typeof d?.requestId?d.requestId:void 0,{...u?{artifactId:u}:{},...f?{requestId:f}:{}}))})}let aJ=aW("buildFlowchart",aB,aM),aY=aW("buildMindmap",aP,aM),aX=aW("buildSequenceDiagram",aR,aM);aW("createCanvas",aF,aM),aW("getArtifact",aL,aM);let aq=aW("applyDiagramPatch",az,aM)},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"}]')}},o={};function l(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return s[e].call(r.exports,r,r.exports,l),r.exports}l.m=s,l.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return l.d(t,{a:t}),t},n=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,l.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);l.r(i);var a={};r=r||[null,n({}),n([]),n(n)];for(var s=2&t&&e;("object"==typeof s||"function"==typeof s)&&!~r.indexOf(s);s=n(s))Object.getOwnPropertyNames(s).forEach(t=>{a[t]=()=>e[t]});return a.default=()=>e,l.d(i,a),i},l.d=(e,t,r)=>{var n=(t,r)=>{for(var n in t)l.o(t,n)&&!l.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,[r]:t[n]})};n(t,"get"),n(r,"value")},l.f={},l.e=e=>Promise.all(Object.keys(l.f).reduce((t,r)=>(l.f[r](e,t),t),[])),l.u=e=>"chunks/"+e+"."+({548:"416192d3a8231af0",869:"cb4ed780b3b9a21a"})[e]+".js",l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.nc=void 0,i={889:0},a=e=>{var t,r,n=e.__rspack_esm_ids,a=e.__webpack_modules__,s=e.__rspack_esm_runtime,o=0;for(t in a)l.o(a,t)&&(l.m[t]=a[t]);for(s&&s(l);o<n.length;o++)r=n[o],l.o(i,r)&&i[r]&&i[r][0](),i[n[o]]=0},l.f.j=function(e,t){var r=l.o(i,e)?i[e]:void 0;if(0!==r)if(r)t.push(r[1]);else{var n=import("./"+l.u(e)).then(a,t=>{throw 0!==i[e]&&(i[e]=void 0),t}),n=Promise.race([n,new Promise(t=>{r=i[e]=[t]})]);t.push(r[1]=n)}},l(1833);
242
+ ${t}}`),n},ev="~effect/Fiber",eb={_A:y.D_,_E:y.D_},e_={id:0},ex=(()=>{try{return globalThis.process?.getBuiltinModule?.("node:async_hooks")?.AsyncResource}catch{return}})(),ew=()=>void 0===ex?void 0:new ex("effect/Fiber"),ek=()=>globalThis[O.fL];class eS{constructor(e,t=!0){this.setContext(e),this.id=++e_.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[ev](){return eb}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return h.Jt(this.context,e)}addObserver(e){return this._exit?(e(this._exit),y.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 r=W(e);this.cache.stackFrame&&(r=(0,A.Eh)(r,h.L8(A.z8,this.cache.stackFrame))),t&&(r=(0,A.Eh)(r,t)),this._interruptedCause=this._interruptedCause?(0,A.h2)(this._interruptedCause,r):r,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(eB(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(void 0!==this._asyncContext){let t=this._asyncContext;return this._asyncContext=void 0,t.runInAsyncScope(this.evaluate,this,e)}if(void 0!==this._yielded){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===A.GN){this._asyncContext=ew();return}let r=eO.interruptChildren&&eO.interruptChildren(this);if(void 0!==r)return this.evaluate(tA(r,()=>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 r=0;r<e.length;r++)e[r](t)}this._stack.length=0,this._children=void 0,this.context=h.Ie()}runLoop(e){let t=globalThis[O.fL];globalThis[O.fL]=this;let r=this._running;this._running=!0;let n=!1,i=e;this.currentOpCount=0;try{for(;;){this._deferredInterrupt&&(this._deferredInterrupt=!1,i=eB(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!n&&!e.preventYield&&e.scheduler.shouldYield(this)){n=!0;let e=i;i=tA(eG,()=>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,b.i5)(i,A._3))return(0,A.V2)(`Fiber.runLoop: Not a valid effect: ${String(i)}`);return this.runLoop((0,A.V2)(e))}finally{this._running=r,globalThis[O.fL]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,e$;for(;;){let t=this._stack.pop();if(!t)return;let r=t[A.u4];if(void 0!==r){let n=r.call(t,this);if(n)return n[e]=n,n}if(t[e])return t}}succeedWith(e){if((++this.currentOpCount&eE-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,E.tT)(this,arguments)}setContext(e){let t=this.context;if(this.context=e,void 0!==t&&h.Pf(t,e))return;let r=e.cacheRoot,n=r._fiberCache??=eI(e);this.cache?.scheduler!==n.scheduler&&(this._dispatcher=void 0),this.cache=n}get currentSpanLocal(){let e=this.cache.span;return e?._tag==="Span"?e:void 0}}let eI=e=>{let t=h.Ub(e,T.RL);return{scheduler:h.Jt(e,C._F),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:h.Jt(e,j.rf),span:h.Ub(e,T.WG),logLevel:h.Jt(e,j.Gl),minimumLogLevel:h.Jt(e,j.zQ),stackFrame:h.Jt(e,j.vA),runtimeMetrics:h.Ub(e,P.F),maxOpsBeforeYield:h.Jt(e,C.Zm),preventYield:h.Jt(e,C.hf)}},e$={[A.ee]:(e,t)=>eB(t._interruptedCause),[A.Sc]:(e,t)=>eB(t._interruptedCause)},eE=32,eO={interruptChildren:void 0},eC=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(A.QJ.key,e.cache.stackFrame),h.LZ(t)},eT=e=>{if(void 0!==e._children&&0!==e._children.size)return eD(e._children)},eM=e=>e._exit?eF(e._exit):te(t=>e._exit?t(eF(e._exit)):ez(e.addObserver(e=>t(eF(e))))),eA=e=>te(t=>{let r,n=e[Symbol.iterator](),i=[];return!function e(){let a=n.next();for(;!a.done;){if(a.value._exit){i.push(a.value._exit),a=n.next();continue}r=a.value.addObserver(t=>{i.push(t),e()});return}t(eF(i))}(),ez(()=>r?.())}),eN=e=>e._exit?e._exit:te(t=>e._exit?t(e._exit):ez(e.addObserver(t))),eP=e=>te(t=>{let r=Array.from(e);if(0===r.length)return t(eF(p.Ie()));let n=Array(r.length),i=p.Ie(),a=()=>{for(let e=0;e<i.length;e++)r[e].removeObserver(i[e])},s=0,o=!1;for(let e=0;e<r.length&&!o;e++){let l=i=>{if(s++,"Failure"===i._tag)return o=!0,a(),t(i);n[e]=i.value,s===r.length&&t(eF(n))};i.push(l),r[e].addObserver(l)}return ez(()=>{o=!0,a()})}),eR=e=>(0,A.R6)(t=>ej(e,t.id)),ej=(0,y.XY)(e=>(0,b.i5)(e[0],ev),(e,t,r)=>(0,A.R6)(n=>{let i=eC(n);return i=i&&r?h.h1(i,r):i??r,e.interruptUnsafe(t,i),t$(eM(e))})),eD=e=>(0,A.R6)(t=>{let r=eC(t),n=p.Ie();for(let i of e)i.interruptUnsafe(t.id,r),n.push(i);return t$(eA(n))}),eU=(0,y.XY)(2,(e,t)=>(0,A.R6)(r=>{let n=eC(r),i=p.Ie();for(let r of e)r.interruptUnsafe(t,n),i.push(r);return t$(eA(i))})),eF=A.xt,eB=A.cb,eL=A.Rk,ez=(0,A.Uf)({op:"Sync",[A._3](e){let t=this[A.a2](),r=e.getCont(A.ee);return r?r[A.ee](t,e):e.yieldWith((0,A.xt)(t))}}),eW=(0,A.Uf)({op:"Suspend",[A._3](e){return this[A.a2]()}}),eJ=(0,y.XY)(e=>e.length>=2||v.isOption(e[0]),(e,t)=>v.isNone(e)?eL(t?t():new A.Xm("Effect.fromOption: Option.none")):eF(e.value)),eY=_.YW({onFailure:eL,onSuccess:eF}),eX=e=>null==e?eL(new A.Xm):eF(e),eq=(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})}}),eG=eq(0),eV=e=>eF(v.some(e)),eH=eF(v.none()),eK=e=>v.isNone(e)?eH:tD(e.value,v.some),eQ=e=>eW(()=>eB(e())),eZ=e=>(0,A.V2)(e),e0=e=>eW(()=>eL(e())),e1=eF(void 0),e2=e=>{let t="function"==typeof e?e:e.try,r="function"==typeof e?e=>new aj(e,"An error occurred in Effect.try"):e.catch;return eW(()=>{try{return eF(t())}catch(e){return eL(r(e))}})},e5=e=>e4(function(t,r){e(r).then(e=>t(eF(e)),e=>t(eZ(e)))},0!==e.length),e3=e=>{let t="function"==typeof e?e:e.try,r="function"==typeof e?e=>new aj(e,"An error occurred in Effect.tryPromise"):e.catch;return e4(function(e,n){let i=e=>eW(()=>{try{return eL((0,M.s)(()=>r(e)))}catch(e){return eZ(e)}});try{t(n).then(t=>e(eF(t)),t=>e(i(t)))}catch(t){e(i(t))}},0!==t.length)},e6=e=>(0,A.R6)(t=>e(t.id)),e8=(0,A.R6)(eF),e9=e6(eF),e4=(n=(0,A.yj)({op:"Async",[A._3](e){let t=!1,r=!1,n=this.withSignal?new AbortController:void 0,i=this.register.call(e.cache.scheduler,n=>{t||(t=!0,r?e.evaluate(n):r=n)},n?.signal);return!1!==r?r:(r=!0,e._yielded=()=>{t=!0},void 0===n&&void 0===i||e._stack.push(e7(()=>(t=!0,n?.abort(),i??t0))),A.GN)}}),(i=function(e,t){this.register=e,this.withSignal=t}).prototype=n,function(e,t){return new i(e,t)}),e7=(0,A.Uf)({op:"AsyncFinalizer",[A.u4](e){e.interruptible&&(e.interruptible=!1,e._stack.push(n2))},[A.Sc](e,t){return K(e)?tA(ng((0,A.cb)(e),this[A.a2]()),()=>eB(e)):eB(e)}}),te=e=>e4(e,e.length>=2),tt=te(y.Yi),tr=(...e)=>{if(1===e.length){let t=e[0];return eW(()=>tc(t()))}let[t,r]=e;return eW(()=>tc(r.call(t.self)))},tn=(e,...t)=>{let r=0===t.length?function(){return eW(()=>tc(e.apply(this,arguments)))}:function(){let r=eW(()=>tc(e.apply(this,arguments)));for(let e=0;e<t.length;e++)r=t[e](r,...arguments);return r};return ti(e.length,r)},ti=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),ta=F(2),ts=function(){let e,t="string"==typeof arguments[0],r=t?arguments[0]:"Effect.fn",n=t?arguments[1]:void 0,i=(0,D.jt)();return(0!==i&&((0,D.ft)(2),e=new globalThis.Error,(0,D.ft)(i)),t)?(i,...a)=>to(r,i,e,a,t,n):to(r,arguments[0],e,Array.prototype.slice.call(arguments,1),t,n)},to=(e,t,r,n,i,a)=>{let s="function"==typeof t?t:n.shift().bind(t.self),o=`${e} (definition)`,l=r?ta(()=>r.stack):y.MN;return ti(s.length,function(...t){let r,d=eW(()=>{let e=s.apply(this,arguments);return(0,A.yw)(e)?e:tc(e)});for(let e=0;e<n.length;e++)d=n[e](d,...t);if(!(0,A.yw)(d))return d;let c=(0,D.jt)();return 0!==c&&((0,D.ft)(2),r=new globalThis.Error,(0,D.ft)(c)),ra(i?ai(e,a,e=>aa(d,e)):d,j.vA,t=>({name:e,stack:r?ta(()=>r.stack):y.MN,parent:{name:o,stack:l,parent:t}}))})},tl=(e,...t)=>ti(e.length,0===t.length?function(){return td(()=>e.apply(this,arguments))}:function(){let r=td(()=>e.apply(this,arguments));for(let e of t)r=e(r,...arguments);return r}),td=e=>{try{let t,r=e();for(;;){let n=r.next(t);if(n.done)return eF(n.value);let i=n.value;if(i&&"Success"===i._tag){t=i.value;continue}{if(i&&"Failure"===i._tag)return n.value;let t=!0;return eW(()=>t?(t=!1,tA(n.value,e=>tc(r,e))):eW(()=>tc(e())))}}}catch(e){return eZ(e)}},tc=(a=(0,A.yj)({op:"Iterator",[A.ee](e,t){let r=this.iterator;for(;;){let n=r.next(e);if(n.done)return eF(n.value);if(!tP(n.value))return t._stack.push(this),n.value;if("Failure"===n.value._tag)return n.value;e=n.value.value}},[A._3](e){return this[A.ee](this.initial,e)}}),(s=function(e,t){this.iterator=e,this.initial=t}).prototype=a,function(e,t){return new s(e,t)}),tu=(0,y.XY)(2,(e,t)=>new th(e,tm,eF(t))),tf=function(e){return e._stack.push(this),this[A.a2]},tp=(0,A.yj)({op:"OnSuccess",[A._3]:tf}),th=function(e,t,r){this[A.a2]=e,this[A.ee]=t,this.payload=r};th.prototype=tp;let tm=function(){return this.payload},tg=function(e,t){return t.succeedWith(this.payload)},ty=(o="~effect/Effect/stackProbe",({[o]:function(){return Error().stack}})[o]()?.includes("[as "+o+"]")===!0),tv=function(e,t){let r=this.payload;return t.succeedWith(ty?r(e):(0,M.s)(()=>r(e)))},tb=function(e){return(0,this.payload)(e)},t_=function(e){return new th((0,this.payload)(e),tg,e)},tx=function(e){return new th(this.payload,tg,e)},tw=e=>tD(e,v.some),tk=e=>r9(e,{onFailure:eF,onSuccess:eL}),tS=(0,y.XY)(2,(e,t)=>new th(e,(0,A.yw)(t)?tm:tb,t)),tI=(0,y.XY)(2,(e,t)=>new th(e,(0,A.yw)(t)?tx:t_,t)),t$=e=>new th(e,tm,t0),tE=e=>rw(e,eL),tO=(e,t)=>(0,A.R6)(r=>{let n=new Set;return nD(r,()=>0===n.size?void 0:eD(n)),te(i=>{let a=p.Ts(e),s=a.length,o=0,l=!1,d=[],c=(e,n,a)=>{if(o++,"Failure"===e._tag){d.push(...e.cause.reasons),o>=s&&i(eB((0,A.b5)(d)));return}let c=!l;l=!0,i(e),c&&t?.onWinner&&t.onWinner({fiber:n,index:a,parentFiber:r})};for(let e=0;e<s;e++){let t=iT(r,a[e],!0,!0,!1);if(n.add(t),t.addObserver(r=>{n.delete(t),c(r,t,e)}),l)break}})}),tC=(e,t)=>(0,A.R6)(r=>{let n=new Set;return nD(r,()=>0===n.size?void 0:eD(n)),te(i=>{let a=!1,s=0;for(let o of e){if(a)break;let e=s++,l=iT(r,o,!0,!0,!1);n.add(l),l.addObserver(s=>{n.delete(l);let o=!a;a=!0,i(s),o&&t?.onWinner&&t.onWinner({fiber:l,index:e,parentFiber:r})})}})}),tT=(0,y.XY)(e=>(0,A.yw)(e[1]),(e,t,r)=>tO([e,t],r)),tM=(0,y.XY)(e=>(0,A.yw)(e[1]),(e,t,r)=>tC([e,t],r)),tA=(0,y.XY)(2,(e,t)=>new th(e,tb,t)),tN=(0,y.XY)(2,(e,t)=>tP(e)?"Success"===e._tag?t.onSuccess(e.value):t.onFailure(e.cause):rZ(e,t)),tP=e=>void 0!==e[A.IH],tR=(0,y.XY)(2,(e,t)=>tP(e)?"Success"===e._tag?t(e.value):e:tA(e,t)),tj=e=>tA(e,y.D_),tD=(0,y.XY)(2,(e,t)=>new th(e,tv,t)),tU=(0,y.XY)(2,(e,t)=>tP(e)?t1(e,t):tD(e,t)),tF=(0,y.XY)(2,(e,t)=>tP(e)?t2(e,t):rW(e,t)),tB=(0,y.XY)(2,(e,t)=>tP(e)?t5(e,t):rJ(e,t)),tL=(0,y.XY)(2,(e,t)=>{if(tP(e)){if("Success"===e._tag)return e;let r=X(e.cause);return _.N6(r)?e:t(r.success)}return rE(e,t)}),tz=e=>(0,A.cb)(W(e)),tW=e=>"Success"===e._tag,tJ=e=>"Success"===e._tag?_.Py(e):_.fJ(e),tY=e=>"Success"===e._tag?_.Py(e.value):_.fJ(e),tX=e=>"Failure"===e._tag,tq=e=>"Failure"===e._tag?_.Py(e):_.fJ(e),tG=e=>"Failure"===e._tag?_.Py(e.cause):_.fJ(e),tV=x(tG,X),tH=x(tG,H),tK=e=>"Failure"===e._tag&&K(e.cause),tQ=e=>"Failure"===e._tag&&G(e.cause),tZ=e=>"Failure"===e._tag&&J(e.cause),t0=(0,A.xt)(void 0),t1=(0,y.XY)(2,(e,t)=>"Success"===e._tag?(0,A.xt)(t(e.value)):e),t2=(0,y.XY)(2,(e,t)=>{if("Success"===e._tag)return e;let r=X(e.cause);return _.N6(r)?e:(0,A.Rk)(t(r.success))}),t5=(0,y.XY)(2,(e,t)=>{if("Success"===e._tag)return(0,A.xt)(t.onSuccess(e.value));let r=X(e.cause);return _.N6(r)?e:(0,A.Rk)(t.onFailure(r.success))}),t3=(0,y.XY)(2,(e,t)=>tW(e)?(0,A.xt)(t):e),t6=(0,y.XY)(2,(e,t)=>tW(e)?t:e),t8=(0,y.XY)(2,(e,t)=>tW(e)?t.onSuccess(e.value):t.onFailure(e.cause)),t9=t3(void 0),t4=e=>{let t=[];for(let r of e)"Failure"===r._tag&&t.push(...r.cause.reasons);return 0===t.length?t0:(0,A.cb)((0,A.b5)(t))},t7=e=>tW(e)?v.some(e.value):v.none(),re=e=>tX(e)?v.some(e.cause):v.none(),rt=e=>{let t=tV(e);return _.N6(t)?v.none():v.some(t.success)},rr=e=>e,rn=e=>(0,A.R6)(t=>eF(h.om(t.context,e))),ri=(0,y.XY)(2,(e,t)=>(0,A.R6)(r=>{let n=r.context,i=t(n);return n===i||(r.setContext(i),nD(r,()=>{r.setContext(n)})),e})),ra=(0,y.XY)(3,(e,t,r)=>ri(e,e=>{let n=h.fp(e,t),i=r(n);return n===i?e:h.WQ(e,t,i)})),rs=(e,t,r)=>n0((0,A.R6)(n=>{let i=h.fp(n.context,e),a=t(i);return n.setContext(h.WQ(n.context,e,a)),n_(h.fp(n.context,nf),t=>{let s,o=h.om(n.context,e);if(v.isNone(o))return e1;let l=o.value;if(r?.reset===void 0){if(l!==a)return e1;s=i}else s=r.reset(i,a,l);return n.setContext(h.WQ(n.context,e,s)),e1})})),ro=()=>rl,rl=(0,A.R6)(e=>eF(e.context)),rd=e=>(0,A.R6)(t=>e(t.context)),rc=(0,y.XY)(2,(e,t)=>ri(e,(0,y.dY)(t))),ru=(0,y.XY)(2,(e,t)=>tP(e)?e:ri(e,h.h1(t))),rf=function(){return 1==arguments.length?(0,y.XY)(2,(e,t)=>rp(e,arguments[0],t)):(0,y.XY)(3,(e,t,r)=>rp(e,t,r)).apply(this,arguments)},rp=(e,t,r)=>ri(e,h.WQ(t,r)),rh=(0,y.XY)(3,(e,t,r)=>tA(r,r=>rf(e,t,r))),rm=(0,y.XY)(e=>(0,A.yw)(e[1]),(e,t,r)=>rg(e,t,(e,t)=>[e,t],r)),rg=(0,y.XY)(e=>(0,A.yw)(e[1]),(e,t,r,n)=>n?.concurrent?tD(ie([e,t],{concurrency:2}),([e,t])=>r(e,t)):tA(e,e=>tD(t,t=>r(e,t)))),ry=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>ib(e,t,r?e=>eL(r(e)):()=>eL(new A.Xm))),rv=(0,y.XY)(2,(e,t)=>tA(t,t=>t?tw(e):eH)),rb=(0,y.XY)(2,(e,t)=>Array.from({length:t},()=>e)),r_=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>ie(rb(e,t),r)),rx=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>id({while:y.ue,body:(0,y.dY)(t?.disableYield?e:tA(e,e=>eG)),step:y.Yi})),rw=(0,y.XY)(2,(e,t)=>new rS(e,1!==t.length?e=>t(e):t)),rk=(0,A.yj)({op:"OnFailure",[A._3]:tf}),rS=function(e,t){this[A.a2]=e,this[A.Sc]=t};rS.prototype=rk;let rI=(0,y.XY)(3,(e,t,r)=>rw(e,e=>t(e)?r(e):eB(e))),r$=(0,y.XY)(3,(e,t,r)=>rw(e,e=>{let n=t(e);return _.N6(n)?eB(n.failure):r(n.success,e)})),rE=(0,y.XY)(2,(e,t)=>r$(e,X,e=>t(e))),rO=e=>r9(e,{onFailure:e=>(0,A.PW)(e)?eH:eL(e),onSuccess:eV}),rC=(0,y.XY)(2,(e,t)=>r$(e,H,t)),rT=(0,y.XY)(2,(e,t)=>rw(e,e=>tS(t(e),eB(e)))),rM=(0,y.XY)(3,(e,t,r)=>rI(e,t,e=>tS(r(e),eB(e)))),rA=(0,y.XY)(3,(e,t,r)=>rw(e,e=>{let n=t(e);return _.N6(n)?eB(e):tS(r(n.success,e),eB(e))})),rN=(0,y.XY)(2,(e,t)=>rA(e,X,e=>t(e))),rP=(0,y.XY)(3,(e,t,r)=>{let n=Array.isArray(t)?e=>(0,b.i5)(e,"_tag")&&t.includes(e._tag):(0,b.$J)(t);return rN(e,e=>n(e)?r(e):e1)}),rR=(0,y.XY)(2,(e,t)=>rA(e,H,e=>t(e))),rj=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n)=>rw(e,e=>{let i=X(e);return _.N6(i)?eB(i.failure):t(i.success)?r(i.success):n?n(i.success):eB(e)})),rD=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n)=>rw(e,e=>{let i=X(e);if(_.N6(i))return eB(i.failure);let a=t(i.success);return _.N6(a)?n?n(a.failure):eB(e):r(a.success)})),rU=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n)=>rj(e,Array.isArray(t)?e=>(0,b.i5)(e,"_tag")&&t.includes(e._tag):(0,b.$J)(t),r,n)),rF=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>{let n;return rD(e,e=>(n??=Object.keys(t),(0,b.i5)(e,"_tag")&&(0,b.Kg)(e._tag)&&n.includes(e._tag)?_.Py(e):_.fJ(e)),e=>t[e._tag](e),r)}),rB=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n,i)=>rj(e,e=>(0,b.$J)(e,t)&&(0,b.i5)(e,"reason")&&(void 0!==i||(0,b.$J)(e.reason,r)),e=>{let t=e.reason;return(0,b.$J)(t,r)?n(t,e):i?i(t,e):eL(e)})),rL=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r,n)=>{let i;return rj(e,e=>(0,b.$J)(e,t)&&(0,b.i5)(e,"reason")&&(0,b.i5)(e.reason,"_tag")&&(0,b.Kg)(e.reason._tag)&&(void 0!==n||(i??=Object.keys(r)).includes(e.reason._tag)),e=>{let t=e.reason;return(i??=Object.keys(r)).includes(t._tag)?r[t._tag](t,e):n?n(t,e):eL(e)})}),rz=(0,y.XY)(2,(e,t)=>rD(e,e=>(0,b.$J)(e,t)&&(0,b.i5)(e,"reason")?_.Py(e.reason):_.fJ(e),eL)),rW=(0,y.XY)(2,(e,t)=>rE(e,e=>e0(()=>t(e)))),rJ=(0,y.XY)(2,(e,t)=>r9(e,{onFailure:e=>e0(()=>t.onFailure(e)),onSuccess:e=>ez(()=>t.onSuccess(e))})),rY=e=>rE(e,eZ),rX=(0,y.XY)(2,(e,t)=>rE(e,e=>ez(()=>t(e)))),rq=e=>eW(()=>{let t=e[Symbol.iterator](),r=t.next();return r.done?eZ(Error("Received an empty collection of effects")):function e(r){let n=t.next();return n.done?r.value:rE(r.value,t=>e(n))}(r)}),rG=e=>rE(e,t=>tA(eG,()=>rG(e))),rV=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>{if(!t?.log)return r9(e,{onFailure:e=>e1,onSuccess:e=>e1});let r=aX(!0===t.log?void 0:t.log);return rZ(e,{onFailure(e){let n=Y(e);return _.N6(n)?eB(n.failure):void 0===t.message?r(e):r(t.message,e)},onSuccess:e=>e1})}),rH=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>{if(!t?.log)return rZ(e,{onFailure:e=>e1,onSuccess:e=>e1});let r=aX(!0===t.log?void 0:t.log);return rZ(e,{onFailure:e=>void 0===t.message?r(e):r(t.message,e),onSuccess:e=>e1})}),rK=e=>r4(e,{onFailure:v.none,onSuccess:v.some}),rQ=e=>r7(e,{onFailure:_.fJ,onSuccess:_.Py}),rZ=(0,y.XY)(2,(e,t)=>new r1(e,1!==t.onSuccess.length?e=>t.onSuccess(e):t.onSuccess,1!==t.onFailure.length?e=>t.onFailure(e):t.onFailure)),r0=(0,A.yj)({op:"OnSuccessAndFailure",[A._3]:tf}),r1=function(e,t,r){this[A.a2]=e,this[A.ee]=t,this[A.Sc]=r};r1.prototype=r0;let r2=function(e,t){let r=this.payload;return t.succeedWith(ty?r.onSuccess(e):(0,M.s)(()=>r.onSuccess(e)))},r5=(e,t)=>{let r=(0,A.yj)({op:e,[A._3]:tf,[A.ee]:r2,[A.Sc]:t}),n=function(e,t){this[A.a2]=e,this.payload=t};return n.prototype=r,n},r3=r5("Match",function(e,t){let r=e.reasons.find(A.lC);if(void 0===r)return eB(e);let n=this.payload;return t.succeedWith(ty?n.onFailure(r.error):(0,M.s)(()=>n.onFailure(r.error)))}),r6=r5("MatchCause",function(e,t){let r=this.payload;return t.succeedWith(ty?r.onFailure(e):(0,M.s)(()=>r.onFailure(e)))}),r8=(0,y.XY)(2,(e,t)=>new r6(e,t)),r9=(0,y.XY)(2,(e,t)=>rZ(e,{onFailure:e=>{let r=e.reasons.find(A.lC);return r?t.onFailure(r.error):eB(e)},onSuccess:t.onSuccess})),r4=(0,y.XY)(2,(e,t)=>new r3(e,t)),r7=(0,y.XY)(2,(e,t)=>{if(tP(e)){if("Success"===e._tag)return(0,A.xt)(t.onSuccess(e.value));let r=X(e.cause);return _.N6(r)?e:(0,A.xt)(t.onFailure(r.success))}return r4(e,t)}),ne=(0,y.XY)(2,(e,t)=>tP(e)?"Success"===e._tag?(0,A.xt)(t.onSuccess(e.value)):(0,A.xt)(t.onFailure(e.cause)):r8(e,t)),nt=e=>tP(e)?(0,A.xt)(e):nr(e),nr=(0,A.Uf)({op:"Exit",[A._3](e){return e._stack.push(this),this[A.a2]},[A.ee]:(e,t,r)=>t.succeedWith(r??(0,A.xt)(e)),[A.Sc]:(e,t,r)=>t.succeedWith(r??(0,A.cb)(e))}),nn=r7({onFailure:()=>!0,onSuccess:()=>!1}),ni=r7({onFailure:()=>!1,onSuccess:()=>!0}),na=(0,y.XY)(2,(e,t)=>tS(av(t),e)),ns=(0,y.XY)(2,(e,t)=>tA(nl(e,t.duration),e=>v.isNone(e)?t.orElse():eF(e.value))),no=(0,y.XY)(2,(e,t)=>{let r=m.bN(t);return ns(e,{duration:r,orElse:()=>eL(new aS(`Operation timed out after '${m.GP(r)}'`))})}),nl=(0,y.XY)(2,(e,t)=>tM(tw(e),tu(av(t),v.none()))),nd=e=>ay(t=>{let r=t.monotonicTimeNanosUnsafe();return tD(e,e=>[m.cF(t.monotonicTimeNanosUnsafe()-r),e])}),nc="~effect/Scope",nu="~effect/Scope/Closeable",nf=h.kl("effect/Scope"),np=(e,t)=>(0,A.R6)(r=>{let n=nh(e,t);return void 0===n?e1:(n6(r),n)}),nh=(e,t)=>{let r=e.state;if("Closed"===r._tag||(e.state={_tag:"Closed",exit:t},void 0!==e.parent&&nk(e.parent,e),"Empty"===r._tag))return;if(void 0!==r.finalizer)return nm(r.finalizer,t);let n=r.finalizers;return 1===n.size?nm(n.values().next().value,t):ny(e,n,t)},nm=(e,t)=>{try{return e(t)}catch(e){return(0,A.V2)(e)}},ng=(e,t)=>tW(e)?t:rw(t,t=>eB((0,A.h2)(e.cause,t))),ny=tn(function*(e,t,r){let n=[],i=[],a=Array.from(t.values()),s=ek();for(let t=a.length-1;t>=0;t--){let o=a[t];"sequential"===e.strategy?n.push((yield*nt(nm(o,r)))):i.push(iT(s,nm(o,r),!0,!0,"inherit"))}return i.length>0&&(n=yield*eA(i)),yield*t4(n)}),nv=(e,t)=>ez(()=>nb(e,t)),nb=(e,t)=>{let r=nI(t,e);return"Closed"===e.state._tag?r.state=e.state:nw(e,r,e=>np(r,e)),r},n_=(e,t)=>eW(()=>"Closed"===e.state._tag?t(e.state.exit):(nw(e,{},t),e1)),nx=(e,t)=>n_(e,(0,y.dY)(t)),nw=(e,t,r)=>{if("Empty"===e.state._tag)e.state={_tag:"Open",finalizerKey:t,finalizer:r,finalizers:void 0};else if("Open"===e.state._tag){let n=e.state;void 0!==n.finalizer&&(n.finalizers=new Map([[n.finalizerKey,n.finalizer]]),n.finalizerKey=void 0,n.finalizer=void 0),n.finalizers.set(t,r)}},nk=(e,t)=>{if("Open"!==e.state._tag)return;let r=e.state;r.finalizerKey===t?e.state=n$:void 0!==r.finalizers&&(r.finalizers.delete(t),0===r.finalizers.size&&(e.state=n$))},nS=e=>nI(e,void 0),nI=(e="sequential",t)=>({[nu]:nu,[nc]:nc,strategy:e,parent:t,state:n$}),n$={_tag:"Empty"},nE=e=>ez(()=>nS(e)),nO=nf,nC=rf(nf),nT=e=>(0,A.R6)(t=>{let r=t.context,n=nS();return t.setContext(h.WQ(t.context,nf,n)),nD(t,e=>(t.setContext(r),nh(n,e))),e}),nM=(0,y.XY)(2,(e,t)=>nU(nC(e,t),e=>eW(()=>nh(t,e)??e1))),nA=e=>eW(()=>{let t=nS();return nU(e(t),e=>eW(()=>nh(t,e)??e1))}),nN=(e,t,r)=>rd(n=>n9(i=>tA(nO,a=>tI(r?.interruptible?i(e):e,e=>n_(a,r=>ru(t(e,r),n)))))),nP=e=>tA(nO,t=>rd(r=>n_(t,t=>ru(e(t),r)))),nR=(l=(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(n2),e.interruptible=!1)},[A.ee](e,t,r){let n;r??=(0,A.xt)(e);try{n=this.onExit(r)}catch(e){n=(0,A.V2)(e)}return n?tA(n,e=>r):r},[A.Sc](e,t,r){let n;r??=(0,A.cb)(e);try{n=this.onExit(r)}catch(e){n=(0,A.V2)(e)}return n?tA(ng(r,n),e=>r):r}}),(d=function(e,t,r){this.effect=e,this.onExit=t,this.interruptible=r}).prototype=l,d),nj=(e,t,r)=>new nR(e,t,r),nD=(e,t)=>{e._stack.push(new nR(void 0,t,void 0))},nU=(0,y.XY)(2,nj),nF=(0,y.XY)(2,(e,t)=>nU(e,e=>t)),nB=(0,y.XY)(3,(e,t,r)=>nU(e,e=>t(e)?r(e):e1)),nL=(0,y.XY)(3,(e,t,r)=>nU(e,e=>{let n=t(e);return _.N6(n)?e1:r(n.success,e)})),nz=(0,y.XY)(2,(e,t)=>nL(e,tG,t)),nW=(0,y.XY)(3,(e,t,r)=>nB(e,e=>"Failure"===e._tag&&t(e.cause),e=>r(e.cause))),nJ=(0,y.XY)(3,(e,t,r)=>nU(e,e=>{if("Failure"!==e._tag)return e1;let n=t(e.cause);return _.N6(n)?e1:r(n.success,e.cause)})),nY=(0,y.XY)(2,(e,t)=>nJ(Z,t)(e)),nX=(e,t,r)=>n9(n=>tA(e,e=>nj(eW(()=>n(t(e))),t=>r(e,t),!0))),nq=e=>nN(e,e=>(0,b.i5)(e,Symbol.asyncDispose)?e5(()=>e[Symbol.asyncDispose]()):ez(()=>e[Symbol.dispose]())),nG=(0,y.XY)(2,(e,t)=>ez(()=>nH(e,"function"==typeof t?e=>m.kE(m.bN(t(e))):(0,y.dY)(m.kE(m.bN(t)))))),nV=(0,y.dY)(1/0),nH=(e,t)=>{let r,n,i=0,a=(e,t)=>(t.awaiters++,nD(e,()=>{if(!(--t.awaiters>0)&&n===t)return n=void 0,eR(t.fiber)}),eN(t.fiber));return[(0,A.R6)(s=>{if(void 0!==n)return a(s,n);if(void 0!==r&&(1/0===i||s.getRef(af).currentTimeMillisUnsafe()<i))return r;r=void 0;let o=s.getRef(af),l={fiber:void 0,awaiters:0};return n=l,l.fiber=iT(s,nj(e,e=>{if(n!==l||(n=void 0,tK(e)))return;let a=t(e);i=1/0===a?1/0:o.currentTimeMillisUnsafe()+a,r=e}),!0,!0),l.fiber._exit??a(s,l)}),ez(()=>{r=void 0})]},nK=(0,y.XY)(2,(e,t)=>tD(nG(e,t),e=>e[0])),nQ=e=>ez(()=>nH(e,nV)[0]),nZ=(0,A.R6)(e=>eB(W(e.id))),n0=e=>(0,A.R6)(t=>(t.interruptible&&(t.interruptible=!1,t._stack.push(n2)),e)),n1=(0,A.Uf)({op:"SetInterruptible",[A.u4](e){if(e.interruptible=this[A.a2],e._interruptedCause&&e.interruptible)return()=>eB(e._interruptedCause)}}),n2=n1(!0),n5=n1(!1),n3=e=>{if(e.interruptible=!0,e._stack.push(n5),e._interruptedCause)return eB(e._interruptedCause)},n6=e=>{e.interruptible&&(e.interruptible=!1,e._stack.push(n2))},n8=e=>(0,A.R6)(t=>t.interruptible?e:n3(t)??e),n9=e=>(0,A.R6)(t=>t.interruptible?(t.interruptible=!1,t._stack.push(n2),e(n8)):e(y.D_)),n4=e=>(0,A.R6)(t=>{if(t.interruptible)return e(y.D_);let r=n3(t),n=e(n0);return r??n}),n7=tD(nN(ez(()=>new AbortController),e=>ez(()=>e.abort())),e=>e.signal),ie=(e,t)=>(0,b.xZ)(e)?t?.mode==="result"?ic(e,rQ,t):ic(e,y.D_,t):t?.discard?"result"===t.mode?ic(Object.values(e),rQ,t):ic(Object.values(e),y.D_,t):eW(()=>{let r={};return tu(ic(Object.entries(e),([e,n])=>tD(t?.mode==="result"?rQ(n):n,t=>{R.x(r,e,t)}),{discard:!0,concurrency:t?.concurrency}),r)}),it=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,r)=>tD(ic(e,(e,r)=>rQ(t(e,r)),r),e=>p.jB(e,y.D_))),ir=(0,y.XY)(3,(e,t,r)=>{let n=p.Ts(e);return 0===n.length?ez(t):eW(()=>{let e=0,i=t();return tD(id({while:()=>e<n.length,body:()=>r(i,n[e],e),step(t){i=t,e++}}),()=>i)})}),ii=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,r)=>tA(it(e,t,{concurrency:r?.concurrency}),([e,t])=>p.CZ(t)?eL(t):r?.discard?e1:eF(e))),ia=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eW(()=>{let r=e[Symbol.iterator](),n=r.next();return n.done?eF(v.none()):is(r,0,t,n.value)})),is=(e,t,r,n)=>tA(r(n,t),i=>{if(i)return eF(v.some(n));let a=e.next();return a.done?eF(v.none()):is(e,t+1,r,a.value)}),io=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eW(()=>{let r=e[Symbol.iterator](),n=r.next();return n.done?eF(v.none()):il(r,0,t,n.value)})),il=(e,t,r,n)=>tA(r(n,t),n=>{if(_.oJ(n))return eF(v.some(n.success));let i=e.next();return i.done?eF(v.none()):il(e,t+1,r,i.value)}),id=(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}}),ic=(0,y.XY)(e=>"function"==typeof e[1],(e,t,r)=>eW(()=>{let n=ih(r?.concurrency);if(1===n)return ip(e,t,r);let i=p.Ts(e),a=i.length;if(0===a)return r?.discard?e1:eF([]);let s=r?.discard?void 0:Array(a),o=iv({f:t,out:s},i,{concurrency:n});return o?tu(o,s):eF(s)})),iu=e=>tA(e,e=>{let t=e[Symbol.iterator]().next();return t.done?eL(new A.Xm):eF(t.value)}),ip=(e,t,r)=>eW(()=>{let n=r?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),s=0;return tu(id({while:()=>!a.done,body:()=>t(a.value,s++),step:e=>{n&&n.push(e),a=i.next()}}),n)}),ih=e=>"unbounded"===e?1/0:Math.max(1,e??1),im=()=>e=>{let t=e.onItem,r=e.step,n=(e,t,n,a,s)=>tA(nt(s),s=>r(e,t[n],s,n)??i(e,t,n+1,a)??e1),i=(e,i,a=0,s=i.length)=>{for(;a<s;a++){let o=i[a],l=t(e,o,a);if(!tP(l))return n(e,i,a,s,l);let d=r(e,o,l,a);if(d)return"Failure"===d._tag?d:void 0}};return i},ig=e=>{let t=e.onItem,r=e.step;return(e,n,i)=>{let a,s,o,l,d,c=0,u=i.end??n.length,f=i.concurrency,p=!1,h=e=>{let t=(0,A.V2)(e);return l=t,p=!0,s&&s.size>0?tA(n0(eD(Array.from(s))),()=>l??t):t},m=()=>{let i=!1;for(;!l&&c<u;c++){let u=n[c],g=d??t(e,u,c);if(tP(g)){if(l=r(e,u,g,c))break}else{if(!a)return te(e=>{let t;a=ek(),s=new Set,d=g,o=e;try{t=m()}catch(t){return e(h(t))}return t?e(t):eW(()=>(l??=t0,tA(s?eD(s):e1,()=>l?._tag==="Failure"?l:e1)))});d=void 0;let t=iT(a,g,!0,!0,"inherit");if(t._exit){if(l=r(e,u,t._exit,c))break;continue}s.add(t);let n=c;if(t.addObserver(a=>{s.delete(t);try{if(l){if("Failure"===a._tag){let e=a.cause.reasons.filter(e=>"Interrupt"!==e._tag);if(e.length>0){let t=(0,A.b5)(e);l=(0,A.cb)("Failure"===l._tag?(0,A.h2)(l.cause,t):t)}}}else{let t=r(e,u,a,n);t&&(l=t,m())}if(i){let e=m();e&&o(e)}else p&&0===s.size&&o(l??e1)}catch(e){o(h(e))}}),s.size<f)continue;i=!0,c++;return}}if(p=!0,l){if(s&&s.size>0){let e=eC(a);s.forEach(t=>t.interruptUnsafe(a.id,e));return}if(o||"Failure"===l._tag)return l}else if(o)if(!s)return t0;else 0===s.size&&o(e1)};return m()}},iy=()=>e=>ig(e),iv=ig({onItem:(e,t,r)=>e.f(t,r),step(e,t,r,n){if("Failure"===r._tag)return r;e.out&&(e.out[n]=r.value)}}),ib=(0,y.XY)(3,(e,t,r)=>tA(e,e=>t(e)?eF(e):r(e))),i_=(0,y.XY)(3,(e,t,r)=>tA(e,e=>{let n=t(e);return _.N6(n)?r(n.failure):eF(n.success)})),ix=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>i_(e,t,r?e=>eL(r(e)):()=>eL(new A.Xm))),iw=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,r)=>eW(()=>{let n=[];return tu(ic(e,(e,r)=>{let i=t(e,r);return"boolean"==typeof i?(i&&n.push(e),e1):tD(i,t=>{t&&n.push(e)})},{discard:!0,concurrency:r?.concurrency}),n)})),ik=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t)=>eW(()=>{let r=[];for(let n of e){let e=t(n);_.oJ(e)&&r.push(e.success)}return eF(r)})),iS=(0,y.XY)(e=>(0,b.xZ)(e[0])&&!(0,A.yw)(e[0]),(e,t,r)=>eW(()=>{let n=[];return tu(ic(e,e=>tD(t(e),e=>{_.oJ(e)&&n.push(e.success)}),{discard:!0,concurrency:r?.concurrency}),n)})),iI=eF({}),i$=N.Jr(tD),iE=N.oI(tD,tA),iO=N.zM(tD),iC=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>(0,A.R6)(r=>(eO.interruptChildren??=eT,eF(iT(r,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),iT=(e,t,r=!1,n=!1,i=!1)=>{let a="inherit"===i?e.interruptible:!i,s=new eS(e.context,a);return r?s.evaluate(t):(s._asyncContext=ew(),e.currentDispatcher.scheduleTask(()=>s.evaluate(t),0)),n||s._exit||(e.children().add(s),s._parent=e),s},iM=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>(0,A.R6)(r=>eF(iT(r,e,t?.startImmediately,!0,t?.uninterruptible)))),iA=e=>(0,A.R6)(t=>{let r=t._children&&new Set(t._children),n=t.interruptible;return nj(e,e=>{let i=t._children;if(void 0===i||0===i.size)return e1;r&&(i=I.pb(i,e=>!r.has(e)));let a=t$(eA(i));return n?n8(a):a})}),iN=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r)=>(0,A.R6)(n=>{let i=iT(n,e,r?.startImmediately,!0,r?.uninterruptible);if(!i._exit)if("Closed"!==t.state._tag){let e={};nw(t,e,()=>e6(e=>e===i.id?e1:eR(i))),i.addObserver(()=>nk(t,e))}else i.interruptUnsafe(n.id,eC(n));return eF(i)})),iP=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>tA(nO,r=>iN(e,r,t))),iR=e=>(t,r)=>{let n=new eS(r?.scheduler?h.WQ(e,C._F,r.scheduler):e,r?.uninterruptible!==!0);if(n.evaluate(t),n._exit)return n;if(r?.signal)if(r.signal.aborted)n.interruptUnsafe();else{let e=()=>n.interruptUnsafe();r.signal.addEventListener("abort",e,{once:!0}),n.addObserver(()=>r.signal.removeEventListener("abort",e))}return r?.onFiberStart&&r.onFiberStart(n),n},ij=(0,y.XY)(2,(e,t)=>{if(e._exit)return e;if("Closed"===t.state._tag)return e.interruptUnsafe(e.id),e;let r={};return nw(t,r,()=>eR(e)),e.addObserver(()=>nk(t,r)),e}),iD=iR(h.Ie()),iU=e=>{let t=iR(e);return(e,r)=>{let n=t(e,r);return r?.onExit&&n.addObserver(r.onExit),e=>n.interruptUnsafe(e)}},iF=iU(h.Ie()),iB=e=>{let t=iR(e);return(e,r)=>{let n=t(e,r);return new Promise(e=>{n.addObserver(t=>e(t))})}},iL=iB(h.Ie()),iz=e=>{let t=iB(e);return(e,r)=>t(e,r).then(e=>{if("Failure"===e._tag)throw es(e.cause);return e.value})},iW=iz(h.Ie()),iJ=e=>{let t=iR(e);return e=>{if(tP(e))return e;let r=t(e,{scheduler:new C.FG("sync")});return r._dispatcher?.flush(),r._exit??(0,A.V2)(new aN(r))}},iY=iJ(h.Ie()),iX=e=>{let t=iJ(e);return e=>{let r=t(e);if("Failure"===r._tag)throw es(r.cause);return r.value}},iq=iX(h.Ie()),iG=eF(!0),iV=eF(!1);class iH{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(0===this.waiters.length)return iG;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=[],iG}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?iV:(this._isOpen=!0,this.scheduleUnsafe(e)));release=(0,A.R6)(e=>this._isOpen?iV:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=te(e=>this._isOpen?e(e1):(this.waiters.push(e),ez(()=>{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=ez(()=>this.closeUnsafe());whenOpen=e=>tA(this.await,()=>e);isOpen(){return this._isOpen}}let iK=e=>new iH(e??!1),iQ=e=>ez(()=>iK(e)),iZ=(0,A.R6)(e=>eF(e.getRef(T.sh))),i0=(0,y.XY)(2,(e,t)=>rf(e,T.sh,t)),i1=rf(j.rf),i2=rf(j.nU),i5=BigInt(0),i3={_tag:"Span",spanId:"noop",traceId:"noop",sampled:!1,status:{_tag:"Ended",startTime:i5,endTime:i5,exit:t0},attributes:new Map,links:[],kind:"internal",attribute(){},event(){},end(){},addLinks(){}},i6=e=>e?h.Jt(e.annotations,T.DW)?"Span"===e._tag?i6(v.getOrUndefined(e.parent)):v.none():v.some(e):v.none(),i8=(e,t,r)=>{let n,i=!e.cache.tracerEnabled||r?.annotations&&h.Jt(r.annotations,T.DW),a=r?.parent!==void 0?v.some(r.parent):r?.root?v.none():i6(e.cache.span);if(i){let e;e={name:t,parent:a,annotations:h.WQ(r?.annotations??h.Ie(),T.DW,!0)},n=Object.assign(Object.create(i3),e)}else{let i=e.cache.tracer??T.Vv,s=e.getRef(af),o=e.getRef(j.nU),l=e.getRef(j.ce),d=e.getRef(j.ls),c=r?.level??e.getRef(T.pX),u=r?.links!==void 0?[...d,...r.links]:0===d.length?[]:d.slice();for(let d in n=i.span({name:t,parent:a,annotations:r?.annotations??h.Ie(),links:u,startTime:o?s.currentTimeNanosUnsafe():i5,kind:r?.kind??"internal",root:r?.root??v.isNone(a),sampled:r?.sampled??((!v.isSome(a)||!1!==a.value.sampled)&&!aF(e.getRef(T.EW),c))}),l)n.attribute(d,l[d]);if(r?.attributes!==void 0)for(let e in r.attributes)n.attribute(e,r.attributes[e])}return n},i9=(e,t)=>(0,A.R6)(r=>eF(i8(r,e,t))),i4=(e,t)=>n0((0,A.R6)(r=>{let n=h.fp(r.context,nf),i=i8(r,e,t??{}),a=r.getRef(af),s=r.getRef(j.nU);return tu(n_(n,e=>an(i,e,a,s)),i)})),i7=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],r=U(e?arguments[2]:arguments[1]);if(e){let e=arguments[0];return tA(i4(t,r),t=>as(e,t,r))}return e=>tA(i4(t,r),t=>as(e,t,r))},ae=j.ce,at=j.ls,ar=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t,r={})=>{let n=(Array.isArray(t)?t:[t]).map(e=>({span:e,attributes:r}));return ra(e,j.ls,e=>[...e,...n])}),an=(e,t,r,n)=>ez(()=>{"Ended"!==e.status._tag&&e.end(n?r.currentTimeNanosUnsafe():i5,t)}),ai=(e,...t)=>{let r=1===t.length?void 0:t[0],n=t[t.length-1];return(0,A.R6)(t=>{let i=i8(t,e,r),a=t.getRef(af),s=t.getRef(j.nU);return nD(t,e=>an(i,e,a,s)),n(i)})},aa=rf(T.Tv),as=function(){let e=(0,A.yw)(arguments[0]),t=e?arguments[1]:arguments[0],r=e?arguments[2]:arguments[1],n=y.D_;if("Span"===t._tag){var i,a;r=U(r),i=t.name,a="function"==typeof(a=r?.captureStackTrace)?a:y.MN,n=ra(j.vA,e=>({name:i,stack:a,parent:e}))}return e?aa(n(arguments[0]),t):e=>aa(n(e),t)},ao=function(){let e="string"!=typeof arguments[0],t=e?arguments[1]:arguments[0],r=U(arguments[2]);if(e){let e=arguments[0];return ai(t,arguments[2],t=>as(e,t,r))}let n="function"==typeof arguments[1]?arguments[1]:void 0,i=n?void 0:arguments[1];return(e,...a)=>ai(t,n?n(...a):i,t=>as(e,t,r))},al=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,...t)=>ra(e,j.ce,e=>{let r=1===t.length?{...e,...t[0]}:{...e};return 1===t.length||R.x(r,t[0],t[1]),r})),ad=(...e)=>(0,A.R6)(t=>{let r=t.currentSpanLocal;if(r)if(1===e.length)for(let[t,n]of Object.entries(e[0]))r.attribute(t,n);else r.attribute(e[0],e[1]);return e1}),ac=(0,A.R6)(e=>{let t=e.currentSpanLocal;return t?eF(t):eL(new A.Xm)}),au=(c=T.Tv,(0,A.R6)(e=>eJ(h.om(e.context,c)))),af=h.Or("effect/Clock",{defaultValue:()=>new ap});class ap{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=ez(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return ag()}currentTimeNanos=ez(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return am()}monotonicTimeNanos=ez(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(m.kE(e))}sleepMillis(e){return e<=0?eG:Number.isFinite(e)?te(t=>{let r=e>0x7fffffff?this.sleepMillis(e-0x7fffffff):e1,n=setTimeout(()=>t(r),Math.min(e,0x7fffffff));return ez(()=>clearTimeout(n))}):tt}}let ah=BigInt(1e6),am=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())*ah;return e>t&&(t=e),t}}(),ag=(f=BigInt(1e9),()=>{let e=am(),t=BigInt(Date.now())*ah;if(void 0===u)u=t-e;else{let r=u+e;(t>r?t-r:r-t)>f&&(u=t-e)}return u+e}),ay=e=>(0,A.R6)(t=>e(t.getRef(af))),av=e=>ay(t=>t.sleep(m.bN(e))),ab=ay(e=>e.currentTimeMillis),a_=ay(e=>e.currentTimeNanos),ax=ay(e=>e.monotonicTimeNanos),aw="~effect/Cause/TimeoutError",ak=e=>(0,b.i5)(e,aw);class aS extends(0,A.rN)("TimeoutError"){[aw]=aw;constructor(e){super({message:e})}}let aI="~effect/Cause/IllegalArgumentError",a$=e=>(0,b.i5)(e,aI);class aE extends(0,A.rN)("IllegalArgumentError"){[aI]=aI;constructor(e){super({message:e})}}let aO="~effect/Cause/ExceededCapacityError",aC=e=>(0,b.i5)(e,aO);class aT extends(0,A.rN)("ExceededCapacityError"){[aO]=aO;constructor(e){super({message:e})}}let aM="~effect/Cause/AsyncFiberError",aA=e=>(0,b.i5)(e,aM);class aN extends(0,A.rN)("AsyncFiberError"){[aM]=aM;constructor(e){super({message:"An asynchronous Effect was executed with Effect.runSync",fiber:e})}}let aP="~effect/Cause/UnknownError",aR=e=>(0,b.i5)(e,aP);class aj extends(0,A.rN)("UnknownError"){[aP]=aP;constructor(e,t){super({message:t,cause:e})}}let aD=h.Or("effect/Console",{defaultValue:()=>globalThis.console}),aU=$.zQ($.wN,e=>{switch(e){case"All":return Number.MIN_SAFE_INTEGER;case"Fatal":return 5e4;case"Error":return 4e4;case"Warn":return 3e4;case"Info":return 2e4;case"Debug":return 1e4;case"Trace":return 0;case"None":return Number.MAX_SAFE_INTEGER}}),aF=$.yJ(aU),aB=h.Or("effect/Logger/CurrentLoggers",{defaultValue:()=>new Set([aq,aG])}),aL=h.Or("effect/Logger/LogToStderr",{defaultValue:y.f4}),az=function(){let e="string"==typeof arguments[0]?[[arguments[0],arguments[1]]]:Object.entries(arguments[0]);return n0((0,A.R6)(t=>{let r=t.getRef(j.iL),n={...r};for(let t=0;t<e.length;t++){let[r,i]=e[t];R.x(n,r,i)}return t.setContext(h.WQ(t.context,j.iL,n)),n_(h.fp(t.context,nf),n=>{let i=t.getRef(j.iL),a={...i};for(let t=0;t<e.length;t++){let[n,s]=e[t];(i[n]===s||Object.is(i[n],s))&&(Object.hasOwn(r,n)?R.x(a,n,r[n]):delete a[n])}return t.setContext(h.WQ(t.context,j.iL,a)),e1})}))},aW={"~effect/Logger":{_Message:y.D_,_Output:y.D_},pipe(){return(0,E.tT)(this,arguments)}},aJ=e=>{let t=Object.create(aW);return t.log=e,t},aY=(e,t)=>{let r=e[0].replace(/[\s="]/g,"_");return`${r}=${t-e[1]}ms`},aX=e=>(...t)=>{let r;for(let e=0,n=t.length;e<n;e++){let n=t[e];(0,A.Aj)(n)&&(r?t.splice(e,1):t=t.slice(0,e).concat(t.slice(e+1)),r=r?(0,A.b5)(r.reasons.concat(n.reasons)):n,e--)}return void 0===r&&(r=A.DH),(0,A.R6)(n=>{let i=e??n.cache.logLevel;if(aF(n.cache.minimumLogLevel,i))return e1;let a=n.getRef(af),s=n.getRef(aB);if(s.size>0){let e=new Date(a.currentTimeMillisUnsafe());for(let a of s)a.log({cause:r,fiber:n,date:e,logLevel:i,message:t})}return e1})},aq=aJ(({cause:e,date:t,fiber:r,logLevel:n,message:i})=>{let a=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&a.push(em(e));let s=t.getTime(),o=r.getRef(j.d8),l="";for(let e of o)l+=` ${aY(e,s)}`;let d=r.getRef(j.iL);Object.keys(d).length>0&&a.push(d);let c=r.getRef(aD);(r.getRef(aL)?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")}] ${n.toUpperCase()} (#${r.id})${l}:`,...a)}),aG=aJ(({cause:e,fiber:t,logLevel:r,message:n})=>{let i=t.getRef(af),a=t.getRef(j.iL),s=t.cache.span;if(void 0===s||"ExternalSpan"===s._tag)return;let o={};for(let[e,t]of Object.entries(a))R.x(o,e,t);o["effect.fiberId"]=t.id,o["effect.logLevel"]=r.toUpperCase(),e.reasons.length>0&&(o["effect.cause"]=em(e)),s.event((0,S.ZK)(Array.isArray(n)&&1===n.length?n[0]:n),i.currentTimeNanosUnsafe(),o)}),aV=eF(void 0),aH=(0,y.XY)(e=>(0,A.yw)(e[0]),(e,t)=>nz(e,e=>(0,A.R6)(r=>(aK(r,e,t?.defectsOnly),e1)))),aK=(e,t,r)=>{let n=e.getRef(j.oQ);if(0===n.size||r&&!G(t))return;let i={cause:t,fiber:e,timestamp:e.getRef(af).currentTimeNanosUnsafe()};n.forEach(e=>e.report(i))}},5844(e,t,r){let n=new WeakSet;r.d(t,{},{J3:n,Xp:e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;e instanceof Error&&t.delete("stack");let r=Object.getPrototypeOf(e),n=r;for(;null!==n&&n!==Object.prototype;){let e=Reflect.ownKeys(n);for(let r=0;r<e.length;r++)t.add(e[r]);n=Object.getPrototypeOf(n)}return t.has("constructor")&&"function"==typeof e.constructor&&r===e.constructor.prototype&&t.delete("constructor"),t},j:e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength)})},7258(e,t,r){r.d(t,{},{F:"effect/Metric/FiberRuntimeMetrics"})},7731(e,t,r){var n=r(3332),i=r(1958),a=r(5033),s=r(3952),o=r(4233),l=r(6481),d=r(2449);let c="~effect/Option",u={[c]:{_A:e=>e},...d.fU,[Symbol.iterator](){return new l.B(this)}},f=Object.defineProperty(Object.assign(Object.create(u),{_tag:"Some",_op:"Some",[n.HR](e){return m(e)&&y(e)&&n.aI(this.value,e.value)},[a.HR](){return a.kg(a.tW(this._tag))(a.tW(this.value))},toString(){return`some(${(0,i.GP)(this.value)})`},toJSON(){return{_id:"Option",_tag:this._tag,value:(0,s.aB)(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),p=a.tW("None"),h=Object.assign(Object.create(u),{_tag:"None",_op:"None",valueOrUndefined:void 0,[n.HR]:e=>m(e)&&g(e),[a.HR]:()=>p,toString:()=>"none()",toJSON(){return{_id:"Option",_tag:this._tag}}}),m=e=>(0,o.i5)(e,c),g=e=>"None"===e._tag,y=e=>"Some"===e._tag,v=Object.create(h),b=function(e){this.value=e};b.prototype=f,r.d(t,{},{$I:g,Ru:y,dv:v,oL:m,zN:e=>new b(e)})},2275(e,t,r){function n(e,t,r){"__proto__"===t?Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}):e[t]=r}function i(e,t){for(let r of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,r)&&n(e,r,t[r])}r.d(t,{x:()=>n,z:()=>i})},6712(e,t,r){var n=r(1179),i=r(1594);let a=n.Or("effect/ErrorReporter/CurrentErrorReporters",{defaultValue:()=>new Set}),s=n.Or("effect/References/CurrentStackFrame",{fiberCached:!0,defaultValue:i.MN}),o=n.Or("effect/References/TracerEnabled",{fiberCached:!0,defaultValue:i.ue}),l=n.Or("effect/References/TracerTimingEnabled",{defaultValue:i.ue}),d=n.Or("effect/References/TracerSpanAnnotations",{defaultValue:()=>({})}),c=n.Or("effect/References/TracerSpanLinks",{defaultValue:()=>[]}),u=n.Or("effect/References/CurrentLogAnnotations",{defaultValue:()=>({})}),f=n.Or("effect/References/CurrentLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),p=n.Or("effect/References/MinimumLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),h=n.Or("effect/References/UnhandledLogLevel",{defaultValue:()=>"Error"}),m=n.Or("effect/References/CurrentLogSpans",{defaultValue:()=>[]});r.d(t,{},{Gl:f,aG:h,ce:d,d8:m,iL:u,ls:c,nU:l,oQ:a,rf:o,vA:s,zQ:p})},2563(e,t,r){var n=r(3332),i=r(1958),a=r(1594),s=r(5033),o=r(3952),l=r(4233),d=r(6481),c=r(2449),u=r(7731);let f="~effect/Result",p={[f]:{_A:e=>e,_E:e=>e},...c.fU,[Symbol.iterator](){return new d.B(this)}},h=Object.assign(Object.create(p),{_tag:"Success",_op:"Success",[n.HR](e){return g(e)&&v(e)&&n.aI(this.success,e.success)},[s.HR](){return s.kg(s.tW(this._tag))(s.tW(this.success))},toString(){return`success(${(0,i.GP)(this.success)})`},toJSON(){return{_id:"Result",_tag:this._tag,value:(0,o.aB)(this.success)}}}),m=Object.assign(Object.create(p),{_tag:"Failure",_op:"Failure",[n.HR](e){return g(e)&&y(e)&&n.aI(this.failure,e.failure)},[s.HR](){return s.kg(s.tW(this._tag))(s.tW(this.failure))},toString(){return`failure(${(0,i.GP)(this.failure)})`},toJSON(){return{_id:"Result",_tag:this._tag,failure:(0,o.aB)(this.failure)}}}),g=e=>(0,l.i5)(e,f),y=e=>"Failure"===e._tag,v=e=>"Success"===e._tag,b=function(e){this.failure=e};b.prototype=m;let _=e=>new b(e),x=function(e){this.success=e};x.prototype=h;let w=e=>new x(e),k=(0,a.XY)(2,(e,t)=>u.$I(e)?_(t()):w(e.value));r.d(t,{},{L8:e=>v(e)?u.dv:u.zN(e.failure),N6:y,Oz:e=>y(e)?u.dv:u.zN(e.success),Py:w,aI:g,fJ:_,oJ:v,sV:k})},2840(e,t,r){var n=r(1594);function i(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function a(e){return t=>i(t)?.[e]}let s="~structural",o="~identifier",l="~sentinels",d=a("identifier"),c=a(o),u=a("title"),f=a("description"),p=(0,n.Bj)(e=>{let t=i(e)?.identifier;return"string"==typeof t?t:e.getExpected(p)}),h=new Set([l,s,"representation","arbitraryConstraint","toJsonSchema","toCode","toEquivalence","toFormatter","toCodec","toCodecJson","toCodecStringTree","toCodecIso","toCodecArbitrary"]);r.d(t,{hd:()=>i,ip:()=>a},{C3:s,CD:c,DQ:u,I_:l,KE:d,L1:["title","description","default","examples","readOnly","writeOnly","format","contentEncoding","contentMediaType","contentSchema"],Pk:f,R4:o,UI:h,bo:p,py:"~constructor"})},8253(e,t,r){var n=r(719),i=r(7086);function a(e){let t;for(let r of e.reasons){if(!n.lC(r)||!i.gh(r.error))return;t??=r.error}return t}function s(e,t){let r=a(e);if(void 0===r)throw Error(t,{cause:e});return r}r.d(t,{R:()=>a,q:()=>s})},587(e,t,r){var n=r(6526),i=r(1587);let a=Symbol(),s=n.Py,o=s(a),l=s(a);r.d(t,{},{LO:a,Py:s,Rr:l,e8:e=>"None"===e._tag?o:s(e.value),r2:o,zL:e=>e===a?i.none():i.some(e)})},5340(e,t,r){let n,i=void 0===(n=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit"))?Object.isExtensible(Error):Object.hasOwn(n,"writable")?!0===n.writable:void 0!==n.set;r.d(t,{},{ft:e=>{i&&(Error.stackTraceLimit=e)},jt:()=>Error.stackTraceLimit})},8689(e,t,r){let n,i,a,s,o;function l(e){let t=e.length;for(;--t>=0;)e[t]=0}let d=573,c=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),u=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),f=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),p=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),h=Array(576);l(h);let m=Array(60);l(m);let g=Array(512);l(g);let y=Array(256);l(y);let v=Array(29);l(v);let b=Array(30);function _(e,t,r,n,i){this.static_tree=e,this.extra_bits=t,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=e&&e.length}function x(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}l(b);let w=e=>e<256?g[e]:g[256+(e>>>7)],k=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},S=(e,t,r)=>{e.bi_valid>16-r?(e.bi_buf|=t<<e.bi_valid&65535,k(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=r-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r)},I=(e,t,r)=>{S(e,r[2*t],r[2*t+1])},$=(e,t)=>{let r=0;do r|=1&e,e>>>=1,r<<=1;while(--t>0)return r>>>1},E=(e,t,r)=>{let n,i,a=Array(16),s=0;for(n=1;n<=15;n++)a[n]=s=s+r[n-1]<<1;for(i=0;i<=t;i++){let t=e[2*i+1];0!==t&&(e[2*i]=$(a[t]++,t))}},O=e=>{let t;for(t=0;t<286;t++)e.dyn_ltree[2*t]=0;for(t=0;t<30;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0},C=e=>{e.bi_valid>8?k(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},T=(e,t,r,n)=>{let i=2*t,a=2*r;return e[i]<e[a]||e[i]===e[a]&&n[t]<=n[r]},M=(e,t,r)=>{let n=e.heap[r],i=r<<1;for(;i<=e.heap_len&&(i<e.heap_len&&T(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!T(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n},A=(e,t,r)=>{let n,i,a,s,o=0;if(0!==e.last_lit)do n=e.pending_buf[e.d_buf+2*o]<<8|e.pending_buf[e.d_buf+2*o+1],i=e.pending_buf[e.l_buf+o],o++,0===n?I(e,i,t):(I(e,(a=y[i])+256+1,t),0!==(s=c[a])&&S(e,i-=v[a],s),I(e,a=w(--n),r),0!==(s=u[a])&&S(e,n-=b[a],s));while(o<e.last_lit)I(e,256,t)},N=(e,t)=>{let r,n,i,a=t.dyn_tree,s=t.stat_desc.static_tree,o=t.stat_desc.has_stree,l=t.stat_desc.elems,c=-1;for(e.heap_len=0,e.heap_max=d,r=0;r<l;r++)0!==a[2*r]?(e.heap[++e.heap_len]=c=r,e.depth[r]=0):a[2*r+1]=0;for(;e.heap_len<2;)a[2*(i=e.heap[++e.heap_len]=c<2?++c:0)]=1,e.depth[i]=0,e.opt_len--,o&&(e.static_len-=s[2*i+1]);for(t.max_code=c,r=e.heap_len>>1;r>=1;r--)M(e,a,r);i=l;do r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],M(e,a,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,a[2*i]=a[2*r]+a[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,a[2*r+1]=a[2*n+1]=i,e.heap[1]=i++,M(e,a,1);while(e.heap_len>=2)e.heap[--e.heap_max]=e.heap[1],((e,t)=>{let r,n,i,a,s,o,l=t.dyn_tree,c=t.max_code,u=t.stat_desc.static_tree,f=t.stat_desc.has_stree,p=t.stat_desc.extra_bits,h=t.stat_desc.extra_base,m=t.stat_desc.max_length,g=0;for(a=0;a<=15;a++)e.bl_count[a]=0;for(l[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<d;r++)(a=l[2*l[2*(n=e.heap[r])+1]+1]+1)>m&&(a=m,g++),l[2*n+1]=a,!(n>c)&&(e.bl_count[a]++,s=0,n>=h&&(s=p[n-h]),o=l[2*n],e.opt_len+=o*(a+s),f&&(e.static_len+=o*(u[2*n+1]+s)));if(0!==g){do{for(a=m-1;0===e.bl_count[a];)a--;e.bl_count[a]--,e.bl_count[a+1]+=2,e.bl_count[m]--,g-=2}while(g>0)for(a=m;0!==a;a--)for(n=e.bl_count[a];0!==n;)!((i=e.heap[--r])>c)&&(l[2*i+1]!==a&&(e.opt_len+=(a-l[2*i+1])*l[2*i],l[2*i+1]=a),n--)}})(e,t),E(a,c,e.bl_count)},P=(e,t,r)=>{let n,i,a=-1,s=t[1],o=0,l=7,d=4;for(0===s&&(l=138,d=3),t[(r+1)*2+1]=65535,n=0;n<=r;n++)i=s,s=t[(n+1)*2+1],++o<l&&i===s||(o<d?e.bl_tree[2*i]+=o:0!==i?(i!==a&&e.bl_tree[2*i]++,e.bl_tree[32]++):o<=10?e.bl_tree[34]++:e.bl_tree[36]++,o=0,a=i,0===s?(l=138,d=3):i===s?(l=6,d=3):(l=7,d=4))},R=(e,t,r)=>{let n,i,a=-1,s=t[1],o=0,l=7,d=4;for(0===s&&(l=138,d=3),n=0;n<=r;n++)if(i=s,s=t[(n+1)*2+1],!(++o<l)||i!==s){if(o<d)do I(e,i,e.bl_tree);while(0!=--o)else 0!==i?(i!==a&&(I(e,i,e.bl_tree),o--),I(e,16,e.bl_tree),S(e,o-3,2)):o<=10?(I(e,17,e.bl_tree),S(e,o-3,3)):(I(e,18,e.bl_tree),S(e,o-11,7));o=0,a=i,0===s?(l=138,d=3):i===s?(l=6,d=3):(l=7,d=4)}},j=!1,D=(e,t,r,n)=>{S(e,0+ +!!n,3),C(e),k(e,r),k(e,~r),e.pending_buf.set(e.window.subarray(t,t+r),e.pending),e.pending+=r};var U={_tr_init:e=>{j||((()=>{let e,t,r,s,o,l=Array(16);for(s=0,r=0;s<28;s++)for(v[s]=r,e=0;e<1<<c[s];e++)y[r++]=s;for(y[r-1]=s,o=0,s=0;s<16;s++)for(b[s]=o,e=0;e<1<<u[s];e++)g[o++]=s;for(o>>=7;s<30;s++)for(b[s]=o<<7,e=0;e<1<<u[s]-7;e++)g[256+o++]=s;for(t=0;t<=15;t++)l[t]=0;for(e=0;e<=143;)h[2*e+1]=8,e++,l[8]++;for(;e<=255;)h[2*e+1]=9,e++,l[9]++;for(;e<=279;)h[2*e+1]=7,e++,l[7]++;for(;e<=287;)h[2*e+1]=8,e++,l[8]++;for(E(h,287,l),e=0;e<30;e++)m[2*e+1]=5,m[2*e]=$(e,5);n=new _(h,c,257,286,15),i=new _(m,u,0,30,15),a=new _([],f,0,19,7)})(),j=!0),e.l_desc=new x(e.dyn_ltree,n),e.d_desc=new x(e.dyn_dtree,i),e.bl_desc=new x(e.bl_tree,a),e.bi_buf=0,e.bi_valid=0,O(e)},_tr_stored_block:D,_tr_flush_block:(e,t,r,n)=>{let i,a,s=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,r=0xf3ffc07f;for(t=0;t<=31;t++,r>>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<256;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),N(e,e.l_desc),N(e,e.d_desc),s=(e=>{let t;for(P(e,e.dyn_ltree,e.l_desc.max_code),P(e,e.dyn_dtree,e.d_desc.max_code),N(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*p[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),i=e.opt_len+3+7>>>3,(a=e.static_len+3+7>>>3)<=i&&(i=a)):i=a=r+5,r+4<=i&&-1!==t?D(e,t,r,n):4===e.strategy||a===i?(S(e,2+ +!!n,3),A(e,h,m)):(S(e,4+ +!!n,3),((e,t,r,n)=>{let i;for(S(e,t-257,5),S(e,r-1,5),S(e,n-4,4),i=0;i<n;i++)S(e,e.bl_tree[2*p[i]+1],3);R(e,e.dyn_ltree,t-1),R(e,e.dyn_dtree,r-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,s+1),A(e,e.dyn_ltree,e.dyn_dtree)),O(e),n&&C(e)},_tr_tally:(e,t,r)=>(e.pending_buf[e.d_buf+2*e.last_lit]=t>>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&r,e.last_lit++,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[(y[r]+256+1)*2]++,e.dyn_dtree[2*w(t)]++),e.last_lit===e.lit_bufsize-1),_tr_align:e=>{S(e,2,3),I(e,256,h),16===e.bi_valid?(k(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}},F=(e,t,r,n)=>{let i=65535&e,a=e>>>16&65535,s=0;for(;0!==r;){s=r>2e3?2e3:r,r-=s;do a=a+(i=i+t[n++]|0)|0;while(--s)i%=65521,a%=65521}return i|a<<16};let B=new Uint32Array((()=>{let e,t=[];for(var r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?0xedb88320^e>>>1:e>>>1;t[r]=e}return t})());var L=(e,t,r,n)=>{let i=n+r;e^=-1;for(let r=n;r<i;r++)e=e>>>8^B[(e^t[r])&255];return -1^e},z={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},W={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};let{_tr_init:J,_tr_stored_block:Y,_tr_flush_block:X,_tr_tally:q,_tr_align:G}=U,{Z_NO_FLUSH:V,Z_PARTIAL_FLUSH:H,Z_FULL_FLUSH:K,Z_FINISH:Q,Z_BLOCK:Z,Z_OK:ee,Z_STREAM_END:et,Z_STREAM_ERROR:er,Z_DATA_ERROR:en,Z_BUF_ERROR:ei,Z_DEFAULT_COMPRESSION:ea,Z_FILTERED:es,Z_HUFFMAN_ONLY:eo,Z_RLE:el,Z_FIXED:ed,Z_DEFAULT_STRATEGY:ec,Z_UNKNOWN:eu,Z_DEFLATED:ef}=W,ep=573,eh=(e,t)=>(e.msg=z[t],t),em=e=>(e<<1)-9*(e>4),eg=e=>{let t=e.length;for(;--t>=0;)e[t]=0},ey=(e,t,r)=>(t<<e.hash_shift^r)&e.hash_mask,ev=e=>{let t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),0!==r&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+r),e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0))},eb=(e,t)=>{X(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ev(e.strm)},e_=(e,t)=>{e.pending_buf[e.pending++]=t},ex=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},ew=(e,t,r,n)=>{let i=e.avail_in;return(i>n&&(i=n),0===i)?0:(e.avail_in-=i,t.set(e.input.subarray(e.next_in,e.next_in+i),r),1===e.state.wrap?e.adler=F(e.adler,t,i,r):2===e.state.wrap&&(e.adler=L(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)},ek=(e,t)=>{let r,n,i=e.max_chain_length,a=e.strstart,s=e.prev_length,o=e.nice_match,l=e.strstart>e.w_size-262?e.strstart-(e.w_size-262):0,d=e.window,c=e.w_mask,u=e.prev,f=e.strstart+258,p=d[a+s-1],h=d[a+s];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(d[(r=t)+s]!==h||d[r+s-1]!==p||d[r]!==d[a]||d[++r]!==d[a+1])continue;a+=2,r++;do;while(d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&d[++a]===d[++r]&&a<f)if(n=258-(f-a),a=f-258,n>s){if(e.match_start=t,s=n,n>=o)break;p=d[a+s-1],h=d[a+s]}}while((t=u[t&c])>l&&0!=--i)return s<=e.lookahead?s:e.lookahead},eS=e=>{let t,r,n,i,a,s=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=s+(s-262)){e.window.set(e.window.subarray(s,s+s),0),e.match_start-=s,e.strstart-=s,e.block_start-=s,t=r=e.hash_size;do n=e.head[--t],e.head[t]=n>=s?n-s:0;while(--r)t=r=s;do n=e.prev[--t],e.prev[t]=n>=s?n-s:0;while(--r)i+=s}if(0===e.strm.avail_in)break;if(r=ew(e.strm,e.window,e.strstart+e.lookahead,i),e.lookahead+=r,e.lookahead+e.insert>=3)for(a=e.strstart-e.insert,e.ins_h=e.window[a],e.ins_h=ey(e,e.ins_h,e.window[a+1]);e.insert&&(e.ins_h=ey(e,e.ins_h,e.window[a+3-1]),e.prev[a&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=a,a++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<262&&0!==e.strm.avail_in)},eI=(e,t)=>{let r,n;for(;;){if(e.lookahead<262){if(eS(e),e.lookahead<262&&t===V)return 1;if(0===e.lookahead)break}if(r=0,e.lookahead>=3&&(e.ins_h=ey(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==r&&e.strstart-r<=e.w_size-262&&(e.match_length=ek(e,r)),e.match_length>=3)if(n=q(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do e.strstart++,e.ins_h=ey(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(0!=--e.match_length)e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=ey(e,e.ins_h,e.window[e.strstart+1]);else n=q(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(eb(e,!1),0===e.strm.avail_out))return 1}return(e.insert=e.strstart<2?e.strstart:2,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(eb(e,!1),0===e.strm.avail_out)?1:2},e$=(e,t)=>{let r,n,i;for(;;){if(e.lookahead<262){if(eS(e),e.lookahead<262&&t===V)return 1;if(0===e.lookahead)break}if(r=0,e.lookahead>=3&&(e.ins_h=ey(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==r&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-262&&(e.match_length=ek(e,r),e.match_length<=5&&(e.strategy===es||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-3,n=q(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=ey(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(0!=--e.prev_length)if(e.match_available=0,e.match_length=2,e.strstart++,n&&(eb(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if((n=q(e,0,e.window[e.strstart-1]))&&eb(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return(e.match_available&&(n=q(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(eb(e,!1),0===e.strm.avail_out)?1:2};function eE(e,t,r,n,i){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=n,this.func=i}let eO=[new eE(0,0,0,0,(e,t)=>{let r=65535;for(65535>e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(eS(e),0===e.lookahead&&t===V)return 1;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;let n=e.block_start+r;if((0===e.strstart||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,eb(e,!1),0===e.strm.avail_out)||e.strstart-e.block_start>=e.w_size-262&&(eb(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:(e.strstart>e.block_start&&(eb(e,!1),e.strm.avail_out),1)}),new eE(4,4,8,4,eI),new eE(4,5,16,8,eI),new eE(4,6,32,32,eI),new eE(4,4,16,16,e$),new eE(8,16,32,32,e$),new eE(8,16,128,128,e$),new eE(8,32,128,256,e$),new eE(32,128,258,1024,e$),new eE(32,258,258,4096,e$)];function eC(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ef,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(2*ep),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),eg(this.dyn_ltree),eg(this.dyn_dtree),eg(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),eg(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),eg(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var eT=(e,t)=>{let r,n;if(!e||!e.state||t>Z||t<0)return e?eh(e,er):er;let i=e.state;if(!e.output||!e.input&&0!==e.avail_in||666===i.status&&t!==Q)return eh(e,0===e.avail_out?ei:er);i.strm=e;let a=i.last_flush;if(i.last_flush=t,42===i.status)if(2===i.wrap)e.adler=0,e_(i,31),e_(i,139),e_(i,8),i.gzhead?(e_(i,+!!i.gzhead.text+2*!!i.gzhead.hcrc+4*!!i.gzhead.extra+8*!!i.gzhead.name+16*!!i.gzhead.comment),e_(i,255&i.gzhead.time),e_(i,i.gzhead.time>>8&255),e_(i,i.gzhead.time>>16&255),e_(i,i.gzhead.time>>24&255),e_(i,9===i.level?2:4*(i.strategy>=eo||i.level<2)),e_(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(e_(i,255&i.gzhead.extra.length),e_(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=L(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(e_(i,0),e_(i,0),e_(i,0),e_(i,0),e_(i,0),e_(i,9===i.level?2:4*(i.strategy>=eo||i.level<2)),e_(i,3),i.status=113);else{let t=ef+(i.w_bits-8<<4)<<8;t|=(i.strategy>=eo||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(t|=32),t+=31-t%31,i.status=113,ex(i,t),0!==i.strstart&&(ex(i,e.adler>>>16),ex(i,65535&e.adler)),e.adler=1}if(69===i.status)if(i.gzhead.extra){for(r=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),ev(e),r=i.pending,i.pending!==i.pending_buf_size));)e_(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),ev(e),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindex<i.gzhead.name.length?255&i.gzhead.name.charCodeAt(i.gzindex++):0,e_(i,n)}while(0!==n)i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),ev(e),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindex<i.gzhead.comment.length?255&i.gzhead.comment.charCodeAt(i.gzindex++):0,e_(i,n)}while(0!==n)i.gzhead.hcrc&&i.pending>r&&(e.adler=L(e.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.status=103)}else i.status=103;if(103===i.status&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&ev(e),i.pending+2<=i.pending_buf_size&&(e_(i,255&e.adler),e_(i,e.adler>>8&255),e.adler=0,i.status=113)):i.status=113),0!==i.pending){if(ev(e),0===e.avail_out)return i.last_flush=-1,ee}else if(0===e.avail_in&&em(t)<=em(a)&&t!==Q)return eh(e,ei);if(666===i.status&&0!==e.avail_in)return eh(e,ei);if(0!==e.avail_in||0!==i.lookahead||t!==V&&666!==i.status){let r=i.strategy===eo?((e,t)=>{let r;for(;;){if(0===e.lookahead&&(eS(e),0===e.lookahead)){if(t===V)return 1;break}if(e.match_length=0,r=q(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(eb(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(eb(e,!1),0===e.strm.avail_out)?1:2})(i,t):i.strategy===el?((e,t)=>{let r,n,i,a,s=e.window;for(;;){if(e.lookahead<=258){if(eS(e),e.lookahead<=258&&t===V)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(n=s[i=e.strstart-1])===s[++i]&&n===s[++i]&&n===s[++i]){a=e.strstart+258;do;while(n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&n===s[++i]&&i<a)e.match_length=258-(a-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(r=q(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=q(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(eb(e,!1),0===e.strm.avail_out))return 1}return(e.insert=0,t===Q)?(eb(e,!0),0===e.strm.avail_out)?3:4:e.last_lit&&(eb(e,!1),0===e.strm.avail_out)?1:2})(i,t):eO[i.level].func(i,t);if((3===r||4===r)&&(i.status=666),1===r||3===r)return 0===e.avail_out&&(i.last_flush=-1),ee;if(2===r&&(t===H?G(i):t!==Z&&(Y(i,0,0,!1),t===K&&(eg(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),ev(e),0===e.avail_out))return i.last_flush=-1,ee}return t!==Q?ee:i.wrap<=0?et:(2===i.wrap?(e_(i,255&e.adler),e_(i,e.adler>>8&255),e_(i,e.adler>>16&255),e_(i,e.adler>>24&255),e_(i,255&e.total_in),e_(i,e.total_in>>8&255),e_(i,e.total_in>>16&255),e_(i,e.total_in>>24&255)):(ex(i,e.adler>>>16),ex(i,65535&e.adler)),ev(e),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?ee:et)},eM=e=>{if(!e||!e.state)return er;let t=e.state.status;return 42!==t&&69!==t&&73!==t&&91!==t&&103!==t&&113!==t&&666!==t?eh(e,er):(e.state=null,113===t?eh(e,en):ee)};let eA=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var eN=function(e){let t=Array.prototype.slice.call(arguments,1);for(;t.length;){let r=t.shift();if(r){if("object"!=typeof r)throw TypeError(r+"must be non-object");for(let t in r)eA(r,t)&&(e[t]=r[t])}}return e},eP=e=>{let t=0;for(let r=0,n=e.length;r<n;r++)t+=e[r].length;let r=new Uint8Array(t);for(let t=0,n=0,i=e.length;t<i;t++){let i=e[t];r.set(i,n),n+=i.length}return r};let eR=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){eR=!1}let ej=new Uint8Array(256);for(let e=0;e<256;e++)ej[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;ej[254]=ej[254]=1;var eD=e=>{let t,r,n,i,a,s=e.length,o=0;for(i=0;i<s;i++)(64512&(r=e.charCodeAt(i)))==55296&&i+1<s&&(64512&(n=e.charCodeAt(i+1)))==56320&&(r=65536+(r-55296<<10)+(n-56320),i++),o+=r<128?1:r<2048?2:r<65536?3:4;for(t=new Uint8Array(o),a=0,i=0;a<o;i++)(64512&(r=e.charCodeAt(i)))==55296&&i+1<s&&(64512&(n=e.charCodeAt(i+1)))==56320&&(r=65536+(r-55296<<10)+(n-56320),i++),r<128?t[a++]=r:(r<2048?t[a++]=192|r>>>6:(r<65536?t[a++]=224|r>>>12:(t[a++]=240|r>>>18,t[a++]=128|r>>>12&63),t[a++]=128|r>>>6&63),t[a++]=128|63&r);return t},eU=(e,t)=>{let r,n,i=t||e.length,a=Array(2*i);for(n=0,r=0;r<i;){let t=e[r++];if(t<128){a[n++]=t;continue}let s=ej[t];if(s>4){a[n++]=65533,r+=s-1;continue}for(t&=2===s?31:3===s?15:7;s>1&&r<i;)t=t<<6|63&e[r++],s--;if(s>1){a[n++]=65533;continue}t<65536?a[n++]=t:(t-=65536,a[n++]=55296|t>>10&1023,a[n++]=56320|1023&t)}var s=n;if(s<65534&&a.subarray&&eR)return String.fromCharCode.apply(null,a.length===s?a:a.subarray(0,s));let o="";for(let e=0;e<s;e++)o+=String.fromCharCode(a[e]);return o},eF=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let r=t-1;for(;r>=0&&(192&e[r])==128;)r--;return r<0||0===r?t:r+ej[e[r]]>t?r:t},eB=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};let eL=Object.prototype.toString,{Z_NO_FLUSH:ez,Z_SYNC_FLUSH:eW,Z_FULL_FLUSH:eJ,Z_FINISH:eY,Z_OK:eX,Z_STREAM_END:eq,Z_DEFAULT_COMPRESSION:eG,Z_DEFAULT_STRATEGY:eV,Z_DEFLATED:eH}=W;function eK(e){let t,r;this.options=eN({level:eG,method:eH,chunkSize:16384,windowBits:15,memLevel:8,strategy:eV},e||{});let n=this.options;n.raw&&n.windowBits>0?n.windowBits=-n.windowBits:n.gzip&&n.windowBits>0&&n.windowBits<16&&(n.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new eB,this.strm.avail_out=0;let i=((e,t,r,n,i,a)=>{var s,o;let l;if(!e)return er;let d=1;if(t===ea&&(t=6),n<0?(d=0,n=-n):n>15&&(d=2,n-=16),i<1||i>9||r!==ef||n<8||n>15||t<0||t>9||a<0||a>ed)return eh(e,er);8===n&&(n=9);let c=new eC;return e.state=c,c.strm=e,c.wrap=d,c.gzhead=null,c.w_bits=n,c.w_size=1<<c.w_bits,c.w_mask=c.w_size-1,c.hash_bits=i+7,c.hash_size=1<<c.hash_bits,c.hash_mask=c.hash_size-1,c.hash_shift=~~((c.hash_bits+3-1)/3),c.window=new Uint8Array(2*c.w_size),c.head=new Uint16Array(c.hash_size),c.prev=new Uint16Array(c.w_size),c.lit_bufsize=1<<i+6,c.pending_buf_size=4*c.lit_bufsize,c.pending_buf=new Uint8Array(c.pending_buf_size),c.d_buf=+c.lit_bufsize,c.l_buf=3*c.lit_bufsize,c.level=t,c.strategy=a,c.method=r,(l=(e=>{if(!e||!e.state)return eh(e,er);e.total_in=e.total_out=0,e.data_type=eu;let t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?42:113,e.adler=+(2!==t.wrap),t.last_flush=V,J(t),ee})(s=e))===ee&&((o=s.state).window_size=2*o.w_size,eg(o.head),o.max_lazy_match=eO[o.level].max_lazy,o.good_match=eO[o.level].good_length,o.nice_match=eO[o.level].nice_length,o.max_chain_length=eO[o.level].max_chain,o.strstart=0,o.block_start=0,o.lookahead=0,o.insert=0,o.match_length=o.prev_length=2,o.match_available=0,o.ins_h=0),l})(this.strm,n.level,n.method,n.windowBits,n.memLevel,n.strategy);if(i!==eX)throw Error(z[i]);if(n.header&&(t=this.strm,r=n.header,t&&t.state&&2===t.state.wrap&&(t.state.gzhead=r)),n.dictionary){let e;if(e="string"==typeof n.dictionary?eD(n.dictionary):"[object ArrayBuffer]"===eL.call(n.dictionary)?new Uint8Array(n.dictionary):n.dictionary,(i=((e,t)=>{let r=t.length;if(!e||!e.state)return er;let n=e.state,i=n.wrap;if(2===i||1===i&&42!==n.status||n.lookahead)return er;if(1===i&&(e.adler=F(e.adler,t,r,0)),n.wrap=0,r>=n.w_size){0===i&&(eg(n.head),n.strstart=0,n.block_start=0,n.insert=0);let e=new Uint8Array(n.w_size);e.set(t.subarray(r-n.w_size,r),0),t=e,r=n.w_size}let a=e.avail_in,s=e.next_in,o=e.input;for(e.avail_in=r,e.next_in=0,e.input=t,eS(n);n.lookahead>=3;){let e=n.strstart,t=n.lookahead-2;do n.ins_h=ey(n,n.ins_h,n.window[e+3-1]),n.prev[e&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=e,e++;while(--t)n.strstart=e,n.lookahead=2,eS(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,e.next_in=s,e.input=o,e.avail_in=a,n.wrap=i,ee})(this.strm,e))!==eX)throw Error(z[i]);this._dict_set=!0}}function eQ(e,t){let r=new eK(t);if(r.push(e,!0),r.err)throw r.msg||z[r.err];return r.result}eK.prototype.push=function(e,t){let r,n,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(n=t===~~t?t:!0===t?eY:ez,"string"==typeof e?i.input=eD(e):"[object ArrayBuffer]"===eL.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(n===eW||n===eJ)&&i.avail_out<=6){this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;continue}if((r=eT(i,n))===eq)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=eM(this.strm),this.onEnd(r),this.ended=!0,r===eX;if(0===i.avail_out){this.onData(i.output);continue}if(n>0&&i.next_out>0){this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;continue}if(0===i.avail_in)break}return!0},eK.prototype.onData=function(e){this.chunks.push(e)},eK.prototype.onEnd=function(e){e===eX&&(this.result=eP(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var eZ=function(e,t){let r,n,i,a,s,o,l,d,c,u,f,p,h,m,g,y,v,b,_,x,w,k,S,I,$=e.state;r=e.next_in,S=e.input,n=r+(e.avail_in-5),i=e.next_out,I=e.output,a=i-(t-e.avail_out),s=i+(e.avail_out-257),o=$.dmax,l=$.wsize,d=$.whave,c=$.wnext,u=$.window,f=$.hold,p=$.bits,h=$.lencode,m=$.distcode,g=(1<<$.lenbits)-1,y=(1<<$.distbits)-1;t:do for(p<15&&(f+=S[r++]<<p,p+=8,f+=S[r++]<<p,p+=8),v=h[f&g];;){if(f>>>=b=v>>>24,p-=b,0==(b=v>>>16&255))I[i++]=65535&v;else if(16&b)for(_=65535&v,(b&=15)&&(p<b&&(f+=S[r++]<<p,p+=8),_+=f&(1<<b)-1,f>>>=b,p-=b),p<15&&(f+=S[r++]<<p,p+=8,f+=S[r++]<<p,p+=8),v=m[f&y];;){if(f>>>=b=v>>>24,p-=b,16&(b=v>>>16&255)){if(x=65535&v,p<(b&=15)&&(f+=S[r++]<<p,(p+=8)<b&&(f+=S[r++]<<p,p+=8)),(x+=f&(1<<b)-1)>o){e.msg="invalid distance too far back",$.mode=30;break t}if(f>>>=b,p-=b,x>(b=i-a)){if((b=x-b)>d&&$.sane){e.msg="invalid distance too far back",$.mode=30;break t}if(w=0,k=u,0===c){if(w+=l-b,b<_){_-=b;do I[i++]=u[w++];while(--b)w=i-x,k=I}}else if(c<b){if(w+=l+c-b,(b-=c)<_){_-=b;do I[i++]=u[w++];while(--b)if(w=0,c<_){_-=b=c;do I[i++]=u[w++];while(--b)w=i-x,k=I}}}else if(w+=c-b,b<_){_-=b;do I[i++]=u[w++];while(--b)w=i-x,k=I}for(;_>2;)I[i++]=k[w++],I[i++]=k[w++],I[i++]=k[w++],_-=3;_&&(I[i++]=k[w++],_>1&&(I[i++]=k[w++]))}else{w=i-x;do I[i++]=I[w++],I[i++]=I[w++],I[i++]=I[w++],_-=3;while(_>2)_&&(I[i++]=I[w++],_>1&&(I[i++]=I[w++]))}}else if((64&b)==0){v=m[(65535&v)+(f&(1<<b)-1)];continue}else{e.msg="invalid distance code",$.mode=30;break t}break}else if((64&b)==0){v=h[(65535&v)+(f&(1<<b)-1)];continue}else if(32&b){$.mode=12;break t}else{e.msg="invalid literal/length code",$.mode=30;break t}break}while(r<n&&i<s)r-=_=p>>3,p-=_<<3,f&=(1<<p)-1,e.next_in=r,e.next_out=i,e.avail_in=r<n?5+(n-r):5-(r-n),e.avail_out=i<s?257+(s-i):257-(i-s),$.hold=f,$.bits=p};let e0=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),e1=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),e2=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),e5=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var e3=(e,t,r,n,i,a,s,o)=>{let l,d,c,u,f,p,h,m,g,y=o.bits,v=0,b=0,_=0,x=0,w=0,k=0,S=0,I=0,$=0,E=0,O=null,C=0,T=new Uint16Array(16),M=new Uint16Array(16),A=null,N=0;for(v=0;v<=15;v++)T[v]=0;for(b=0;b<n;b++)T[t[r+b]]++;for(w=y,x=15;x>=1&&0===T[x];x--);if(w>x&&(w=x),0===x)return i[a++]=0x1400000,i[a++]=0x1400000,o.bits=1,0;for(_=1;_<x&&0===T[_];_++);for(w<_&&(w=_),I=1,v=1;v<=15;v++)if(I<<=1,(I-=T[v])<0)return -1;if(I>0&&(0===e||1!==x))return -1;for(M[1]=0,v=1;v<15;v++)M[v+1]=M[v]+T[v];for(b=0;b<n;b++)0!==t[r+b]&&(s[M[t[r+b]]++]=b);if(0===e?(O=A=s,p=19):1===e?(O=e0,C-=257,A=e1,N-=257,p=256):(O=e2,A=e5,p=-1),E=0,b=0,v=_,f=a,k=w,S=0,c=-1,u=($=1<<w)-1,1===e&&$>852||2===e&&$>592)return 1;for(;;){h=v-S,s[b]<p?(m=0,g=s[b]):s[b]>p?(m=A[N+s[b]],g=O[C+s[b]]):(m=96,g=0),l=1<<v-S,_=d=1<<k;do i[f+(E>>S)+(d-=l)]=h<<24|m<<16|g;while(0!==d)for(l=1<<v-1;E&l;)l>>=1;if(0!==l?(E&=l-1,E+=l):E=0,b++,0==--T[v]){if(v===x)break;v=t[r+s[b]]}if(v>w&&(E&u)!==c){for(0===S&&(S=w),f+=_,I=1<<(k=v-S);k+S<x&&!((I-=T[k+S])<=0);)k++,I<<=1;if($+=1<<k,1===e&&$>852||2===e&&$>592)return 1;i[c=E&u]=w<<24|k<<16|f-a}}return 0!==E&&(i[f+E]=v-S<<24|4194304),o.bits=w,0};let{Z_FINISH:e6,Z_BLOCK:e8,Z_TREES:e9,Z_OK:e4,Z_STREAM_END:e7,Z_NEED_DICT:te,Z_STREAM_ERROR:tt,Z_DATA_ERROR:tr,Z_MEM_ERROR:tn,Z_BUF_ERROR:ti,Z_DEFLATED:ta}=W,ts=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function to(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}let tl=e=>{if(!e||!e.state)return tt;let t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,(e=>{if(!e||!e.state)return tt;let t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,e4})(e)},td=!0,tc=e=>{if(td){s=new Int32Array(512),o=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(e3(1,e.lens,0,288,s,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;e3(2,e.lens,0,32,o,0,e.work,{bits:5}),td=!1}e.lencode=s,e.lenbits=9,e.distcode=o,e.distbits=5},tu=(e,t,r,n)=>{let i,a=e.state;return null===a.window&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new Uint8Array(a.wsize)),n>=a.wsize?(a.window.set(t.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(t.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(t.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0};var tf=(e,t)=>{let r,n,i,a,s,o,l,d,c,u,f,p,h,m,g,y,v,b,_,x,w,k,S,I,$=0,E=new Uint8Array(4),O=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return tt;12===(r=e.state).mode&&(r.mode=13),s=e.next_out,i=e.output,l=e.avail_out,a=e.next_in,n=e.input,o=e.avail_in,d=r.hold,c=r.bits,u=o,f=l,k=e4;r:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(2&r.wrap&&35615===d){r.check=0,E[0]=255&d,E[1]=d>>>8&255,r.check=L(r.check,E,2,0),d=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&d)<<8)+(d>>8))%31){e.msg="incorrect header check",r.mode=30;break}if((15&d)!==ta){e.msg="unknown compression method",r.mode=30;break}if(d>>>=4,c-=4,w=(15&d)+8,0===r.wbits)r.wbits=w;else if(w>r.wbits){e.msg="invalid window size",r.mode=30;break}r.dmax=1<<r.wbits,e.adler=r.check=1,r.mode=512&d?10:12,d=0,c=0;break;case 2:for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(r.flags=d,(255&r.flags)!==ta){e.msg="unknown compression method",r.mode=30;break}if(57344&r.flags){e.msg="unknown header flags set",r.mode=30;break}r.head&&(r.head.text=d>>8&1),512&r.flags&&(E[0]=255&d,E[1]=d>>>8&255,r.check=L(r.check,E,2,0)),d=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.head&&(r.head.time=d),512&r.flags&&(E[0]=255&d,E[1]=d>>>8&255,E[2]=d>>>16&255,E[3]=d>>>24&255,r.check=L(r.check,E,4,0)),d=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.head&&(r.head.xflags=255&d,r.head.os=d>>8),512&r.flags&&(E[0]=255&d,E[1]=d>>>8&255,r.check=L(r.check,E,2,0)),d=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.length=d,r.head&&(r.head.extra_len=d),512&r.flags&&(E[0]=255&d,E[1]=d>>>8&255,r.check=L(r.check,E,2,0)),d=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((p=r.length)>o&&(p=o),p&&(r.head&&(w=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+p),w)),512&r.flags&&(r.check=L(r.check,n,p,a)),o-=p,a+=p,r.length-=p),r.length))break r;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break r;p=0;do w=n[a+p++],r.head&&w&&r.length<65536&&(r.head.name+=String.fromCharCode(w));while(w&&p<o)if(512&r.flags&&(r.check=L(r.check,n,p,a)),o-=p,a+=p,w)break r}else r.head&&(r.head.name=null);r.length=0,r.mode=8;case 8:if(4096&r.flags){if(0===o)break r;p=0;do w=n[a+p++],r.head&&w&&r.length<65536&&(r.head.comment+=String.fromCharCode(w));while(w&&p<o)if(512&r.flags&&(r.check=L(r.check,n,p,a)),o-=p,a+=p,w)break r}else r.head&&(r.head.comment=null);r.mode=9;case 9:if(512&r.flags){for(;c<16;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(d!==(65535&r.check)){e.msg="header crc mismatch",r.mode=30;break}d=0,c=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;c<32;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}e.adler=r.check=ts(d),d=0,c=0,r.mode=11;case 11:if(0===r.havedict)return e.next_out=s,e.avail_out=l,e.next_in=a,e.avail_in=o,r.hold=d,r.bits=c,te;e.adler=r.check=1,r.mode=12;case 12:if(t===e8||t===e9)break r;case 13:if(r.last){d>>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}switch(r.last=1&d,c-=1,3&(d>>>=1)){case 0:r.mode=14;break;case 1:if(tc(r),r.mode=20,t===e9){d>>>=2,c-=2;break r}break;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30}d>>>=2,c-=2;break;case 14:for(d>>>=7&c,c-=7&c;c<32;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if((65535&d)!=(d>>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&d,d=0,c=0,r.mode=15,t===e9)break r;case 15:r.mode=16;case 16:if(p=r.length){if(p>o&&(p=o),p>l&&(p=l),0===p)break r;i.set(n.subarray(a,a+p),s),o-=p,a+=p,l-=p,s+=p,r.length-=p;break}r.mode=12;break;case 17:for(;c<14;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(r.nlen=(31&d)+257,c-=5,r.ndist=(31&(d>>>=5))+1,c-=5,r.ncode=(15&(d>>>=5))+4,d>>>=4,c-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=30;break}r.have=0,r.mode=18;case 18:for(;r.have<r.ncode;){for(;c<3;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.lens[O[r.have++]]=7&d,d>>>=3,c-=3}for(;r.have<19;)r.lens[O[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},k=e3(0,r.lens,0,19,r.lencode,0,r.work,S),r.lenbits=S.bits,k){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have<r.nlen+r.ndist;){for(;g=($=r.lencode[d&(1<<r.lenbits)-1])>>>24,y=$>>>16&255,v=65535&$,!(g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(v<16)d>>>=g,c-=g,r.lens[r.have++]=v;else{if(16===v){for(I=g+2;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(d>>>=g,c-=g,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}w=r.lens[r.have-1],p=3+(3&d),d>>>=2,c-=2}else if(17===v){for(I=g+3;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}d>>>=g,c-=g,w=0,p=3+(7&d),d>>>=3,c-=3}else{for(I=g+7;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}d>>>=g,c-=g,w=0,p=11+(127&d),d>>>=7,c-=7}if(r.have+p>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;p--;)r.lens[r.have++]=w}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,S={bits:r.lenbits},k=e3(1,r.lens,0,r.nlen,r.lencode,0,r.work,S),r.lenbits=S.bits,k){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,S={bits:r.distbits},k=e3(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,S),r.distbits=S.bits,k){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,t===e9)break r;case 20:r.mode=21;case 21:if(o>=6&&l>=258){e.next_out=s,e.avail_out=l,e.next_in=a,e.avail_in=o,r.hold=d,r.bits=c,eZ(e,f),s=e.next_out,i=e.output,l=e.avail_out,a=e.next_in,n=e.input,o=e.avail_in,d=r.hold,c=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=($=r.lencode[d&(1<<r.lenbits)-1])>>>24,y=$>>>16&255,v=65535&$,!(g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(y&&(240&y)==0){for(b=g,_=y,x=v;g=($=r.lencode[x+((d&(1<<b+_)-1)>>b)])>>>24,y=$>>>16&255,v=65535&$,!(b+g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}d>>>=b,c-=b,r.back+=b}if(d>>>=g,c-=g,r.back+=g,r.length=v,0===y){r.mode=26;break}if(32&y){r.back=-1,r.mode=12;break}if(64&y){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&y,r.mode=22;case 22:if(r.extra){for(I=r.extra;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.length+=d&(1<<r.extra)-1,d>>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;g=($=r.distcode[d&(1<<r.distbits)-1])>>>24,y=$>>>16&255,v=65535&$,!(g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if((240&y)==0){for(b=g,_=y,x=v;g=($=r.distcode[x+((d&(1<<b+_)-1)>>b)])>>>24,y=$>>>16&255,v=65535&$,!(b+g<=c);){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}d>>>=b,c-=b,r.back+=b}if(d>>>=g,c-=g,r.back+=g,64&y){e.msg="invalid distance code",r.mode=30;break}r.offset=v,r.extra=15&y,r.mode=24;case 24:if(r.extra){for(I=r.extra;c<I;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}r.offset+=d&(1<<r.extra)-1,d>>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===l)break r;if(p=f-l,r.offset>p){if((p=r.offset-p)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}p>r.wnext?(p-=r.wnext,h=r.wsize-p):h=r.wnext-p,p>r.length&&(p=r.length),m=r.window}else m=i,h=s-r.offset,p=r.length;p>l&&(p=l),l-=p,r.length-=p;do i[s++]=m[h++];while(--p)0===r.length&&(r.mode=21);break;case 26:if(0===l)break r;i[s++]=r.length,l--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===o)break r;o--,d|=n[a++]<<c,c+=8}if(f-=l,e.total_out+=f,r.total+=f,f&&(e.adler=r.check=r.flags?L(r.check,i,f,s-f):F(r.check,i,f,s-f)),f=l,(r.flags?d:ts(d))!==r.check){e.msg="incorrect data check",r.mode=30;break}d=0,c=0}r.mode=28;case 28:if(r.wrap&&r.flags){for(;c<32;){if(0===o)break r;o--,d+=n[a++]<<c,c+=8}if(d!==(0|r.total)){e.msg="incorrect length check",r.mode=30;break}d=0,c=0}r.mode=29;case 29:k=e7;break r;case 30:k=tr;break r;case 31:return tn;default:return tt}return e.next_out=s,e.avail_out=l,e.next_in=a,e.avail_in=o,r.hold=d,r.bits=c,(r.wsize||f!==e.avail_out&&r.mode<30&&(r.mode<27||t!==e6))&&tu(e,e.output,e.next_out,f-e.avail_out),u-=e.avail_in,f-=e.avail_out,e.total_in+=u,e.total_out+=f,r.total+=f,r.wrap&&f&&(e.adler=r.check=r.flags?L(r.check,i,f,e.next_out-f):F(r.check,i,f,e.next_out-f)),e.data_type=r.bits+64*!!r.last+128*(12===r.mode)+256*(20===r.mode||15===r.mode),(0===u&&0===f||t===e6)&&k===e4&&(k=ti),k},tp=e=>{if(!e||!e.state)return tt;let t=e.state;return t.window&&(t.window=null),e.state=null,e4},th=(e,t)=>{let r,n=t.length;return e&&e.state&&(0===(r=e.state).wrap||11===r.mode)?11===r.mode&&F(1,t,n,0)!==r.check?tr:tu(e,t,n,n)?(r.mode=31,tn):(r.havedict=1,e4):tt},tm=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};let tg=Object.prototype.toString,{Z_NO_FLUSH:ty,Z_FINISH:tv,Z_OK:tb,Z_STREAM_END:t_,Z_NEED_DICT:tx,Z_STREAM_ERROR:tw,Z_DATA_ERROR:tk,Z_MEM_ERROR:tS}=W;function tI(e){this.options=eN({chunkSize:65536,windowBits:15,to:""},e||{});let t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(e&&e.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(15&t.windowBits)==0&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new eB,this.strm.avail_out=0;let r=((e,t)=>{if(!e)return tt;let r=new to;e.state=r,r.window=null;let n=((e,t)=>{let r;if(!e||!e.state)return tt;let n=e.state;return(t<0?(r=0,t=-t):(r=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?tt:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,tl(e))})(e,t);return n!==e4&&(e.state=null),n})(this.strm,t.windowBits);if(r!==tb||(this.header=new tm,((e,t)=>{if(!e||!e.state)return;let r=e.state;return(2&r.wrap)==0||(r.head=t,t.done=!1)})(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=eD(t.dictionary):"[object ArrayBuffer]"===tg.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw)&&(r=th(this.strm,t.dictionary))!==tb))throw Error(z[r])}function t$(e,t){let r=new tI(t);if(r.push(e),r.err)throw r.msg||z[r.err];return r.result}tI.prototype.push=function(e,t){let r,n,i,a=this.strm,s=this.options.chunkSize,o=this.options.dictionary;if(this.ended)return!1;for(n=t===~~t?t:!0===t?tv:ty,"[object ArrayBuffer]"===tg.call(e)?a.input=new Uint8Array(e):a.input=e,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(s),a.next_out=0,a.avail_out=s),(r=tf(a,n))===tx&&o&&((r=th(a,o))===tb?r=tf(a,n):r===tk&&(r=tx));a.avail_in>0&&r===t_&&a.state.wrap>0&&0!==e[a.next_in];)tl(a),r=tf(a,n);switch(r){case tw:case tk:case tx:case tS:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===t_))if("string"===this.options.to){let e=eF(a.output,a.next_out),t=a.next_out-e,r=eU(a.output,e);a.next_out=t,a.avail_out=s-t,t&&a.output.set(a.output.subarray(e,e+t),0),this.onData(r)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==tb||0!==i){if(r===t_)return r=tp(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},tI.prototype.onData=function(e){this.chunks.push(e)},tI.prototype.onEnd=function(e){e===tb&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=eP(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};let{Deflate:tE,deflate:tO,deflateRaw:tC,gzip:tT}={Deflate:eK,deflate:eQ,deflateRaw:function(e,t){return(t=t||{}).raw=!0,eQ(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,eQ(e,t)},constants:W},{Inflate:tM,inflate:tA,inflateRaw:tN,ungzip:tP}={Inflate:tI,inflate:t$,inflateRaw:function(e,t){return(t=t||{}).raw=!0,t$(e,t)},ungzip:t$,constants:W};r.d(t,{Gy:()=>tE,Kc:()=>tO,UD:()=>tA})},5967(e,t,r){let n;r.d(t,{x3:()=>rP,y1:()=>ri,Ov:()=>r6,Tx:()=>ne,UA:()=>iF,JH:()=>r2,yE:()=>rc,Ky:()=>t_,e5:()=>tJ,Uh:()=>ra,nu:()=>tI,OF:()=>aL,XV:()=>aU,r8:()=>aF,rC:()=>aB,z4:()=>eC,rR:()=>iB});var i=r(2718),a=r(1179),s=r(2842),o=r(4238),l=r(5633),d=r(2109),c=r(7086),u=r(2981);let f=i.ukk,p=i.mSG(i.QfV,i.$r1),h=Object.freeze({paper:"#f6f1e7",card:"#fffdf8",ink:"#1a1712",accent:"#8f707f"}),m=Object.freeze({accentColor:h.accent,backgroundColor:h.card});function g(e,t){return e.pipe(i.tiU(s.PyW(t)))}let y=i.xCb(["flowchart","mindmap"]),v=i.xCb(["TB","BT","LR","RL"]),b=i.xCb(["straight","orthogonal","curved"]);class _ extends i.Xsx("DiagramNode")({id:f,label:f,group:i.lqM(f),kind:i.lqM(f),metadata:g(p,{})}){}class x extends i.Xsx("DiagramEdge")({id:f,source:f,target:f,label:i.lqM(f),metadata:g(p,{})}){}let w=i.QfV.check(i.Pto(/^#[0-9a-fA-F]{6}$/));class k extends i.Xsx("DiagramStyle")({accentColor:g(w,m.accentColor),backgroundColor:g(w,m.backgroundColor)}){}class S extends i.Xsx("DiagramLayout")({direction:g(v,"LR"),edgeRouting:g(b,"orthogonal")}){}class I extends i.Xsx("IntermediateDiagram")({id:f,title:f,type:g(y,"flowchart"),nodes:i.O31(_).pipe(i.fXn).check(i.tJb(1)),edges:g(i.O31(x).pipe(i.fXn),[]),layout:g(S,{direction:"LR",edgeRouting:"orthogonal"}),style:g(k,m),metadata:g(p,{})}){}class $ extends Error{constructor(e){super(e),this.name="DiagramValidationError"}}let E=e=>{let t=new Set;for(let r of e){if(t.has(r))return r;t.add(r)}};function O(e){let t=E(e.nodes.map(e=>e.id));if(t)throw new $(`Duplicate node id "${t}" is not allowed.`);let r=E(e.edges.map(e=>e.id));if(r)throw new $(`Duplicate edge id "${r}" is not allowed.`);let n=new Set(e.nodes.map(e=>e.id));for(let t of e.edges){if(!n.has(t.source))throw new $(`Edge "${t.id}" references missing source node "${t.source}".`);if(!n.has(t.target))throw new $(`Edge "${t.id}" references missing target node "${t.target}".`);if(t.source===t.target)throw new $(`Edge "${t.id}" cannot connect node "${t.source}" to itself.`)}return e}function C(e){return O(i.svK(I,{errors:"all"})(e))}let T="flowchart",M=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"]);class A extends i.Xsx("FlowchartValidationIssueRef")({kind:i.xCb(["diagram","node","edge"]),id:i.lqM(i.ukk),path:i.lqM(i.ukk)}){}i.Xsx("FlowchartValidationIssue")({code:M,ref:i.lqM(A),message:i.ukk,hint:i.ukk});let N=i.xCb(["start","process","decision","end"]);class P extends _.extend("FlowchartNode")({kind:N,description:i.lqM(i.ukk)}){}class R extends x.extend("FlowchartEdge")({label:i.lqM(i.ukk)}){}class j extends I.extend("FlowchartDiagram")({type:i.uSQ(T),nodes:i.O31(P).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(R).pipe(i.fXn).check(i.tJb(1))}){}function D(e){let t=new Set,r=new Set;for(let n of e)t.has(n)?r.add(n):t.add(n);return[...r]}function U(e,t,r){let n=new Set,i=[...e];for(let e=0;e<i.length;e+=1){let a=i[e];if(!(void 0===a||n.has(a)))for(let e of(n.add(a),t.get(a)??[]))i.push(r(e))}return n}function F(e){let t=[],r=new Set(e.nodes.map(e=>e.id)),{incoming:n,outgoing:i}=function(e){let t=new Map,r=new Map;for(let n of e)t.set(n.target,[...t.get(n.target)??[],n]),r.set(n.source,[...r.get(n.source)??[],n]);return{incoming:t,outgoing:r}}(e.edges);for(let r of(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."}),D(e.nodes.map(e=>e.id))))t.push({code:"duplicate_node_id",ref:{kind:"node",id:r,path:"nodes"},message:`Node id "${r}" is used more than once.`,hint:"Give every node a stable unique id."});for(let r of D(e.edges.map(e=>e.id)))t.push({code:"duplicate_edge_id",ref:{kind:"edge",id:r,path:"edges"},message:`Edge id "${r}" is used more than once.`,hint:"Give every edge a stable unique id."});for(let n of e.edges)r.has(n.source)||t.push({code:"missing_edge_source",ref:{kind:"edge",id:n.id,path:"edges.source"},message:`Edge "${n.id}" references missing source node "${n.source}".`,hint:"Set edge.source to one of the diagram node ids."}),r.has(n.target)||t.push({code:"missing_edge_target",ref:{kind:"edge",id:n.id,path:"edges.target"},message:`Edge "${n.id}" references missing target node "${n.target}".`,hint:"Set edge.target to one of the diagram node ids."}),n.source===n.target&&t.push({code:"self_loop",ref:{kind:"edge",id:n.id},message:`Edge "${n.id}" connects node "${n.source}" to itself.`,hint:"Connect the edge to a different target node."});let a=e.nodes.filter(e=>"start"===e.kind),s=e.nodes.filter(e=>"end"===e.kind);for(let r of(0===a.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".'}):a.length>1&&t.push({code:"multiple_starts",ref:{kind:"diagram",id:e.id,path:"nodes"},message:`Flowchart has ${a.length} start nodes.`,hint:"Keep one start node and change the others to process, decision, or end."}),0===s.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=n.get(r.id)??[],a=i.get(r.id)??[];"start"===r.kind&&e.length>0&&t.push({code:"start_has_incoming",ref:{kind:"node",id:r.id},message:`Start node "${r.id}" cannot have incoming edges.`,hint:"Route the start node only to later nodes."}),"end"===r.kind&&a.length>0&&t.push({code:"end_has_outgoing",ref:{kind:"node",id:r.id},message:`End node "${r.id}" cannot have outgoing edges.`,hint:"End nodes must be terminal outcomes."}),"end"!==r.kind&&0===a.length&&t.push({code:"missing_outgoing_edge",ref:{kind:"node",id:r.id},message:`Node "${r.id}" must have at least one outgoing edge.`,hint:'Connect it to the next step, or mark it as kind: "end".'}),"decision"===r.kind&&t.push(...function(e,t){let r=[];t.length<2&&r.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 n=t.map(e=>e.label?.trim()??"");for(let n of t.filter(e=>!e.label?.trim()))r.push({code:"unlabeled_decision_branch",ref:{kind:"edge",id:n.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 D(n.filter(e=>e.length>0).map(e=>e.toLowerCase())))r.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 r}(r,a))}let o=1===a.length?a[0]:void 0;if(o){let r=U([o.id],i,e=>e.target);for(let n of e.nodes)r.has(n.id)||t.push({code:"unreachable_node",ref:{kind:"node",id:n.id},message:`Node "${n.id}" is not reachable from the start node.`,hint:"Connect every node to the flow that begins at the single start node."});if(s.length>0){let a=U(s.map(e=>e.id),n,e=>e.source);for(let n of e.nodes)r.has(n.id)&&!a.has(n.id)&&(i.get(n.id)?.length??0)>0&&t.push({code:"nonterminating_node",ref:{kind:"node",id:n.id},message:`Node "${n.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 B extends ${issues;constructor(e){super(e[0]?.message??"Flowchart failed semantic validation."),this.issues=e,this.name="FlowchartValidationError"}}function L(e){let t=F(e);if(t.length>0)throw new B(t);return e}function z(e){return L(i.svK(j,{errors:"all"})(e))}let W=z({id:"onboarding-flow",title:"Sketchi onboarding decision flow",type:T,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"}});z({id:"pharma-batch-disposition",title:"Pharma batch disposition flow",type:T,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"}});let J="mindmap";class Y extends i.Xsx("MindmapNodeMetadata")({depth:i.Aiz.check(i.OWK(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class X extends _.extend("MindmapNode")({kind:i.xCb(["root","topic"]),metadata:Y}){}class q extends i.Xsx("MindmapEdgeMetadata")({depth:i.Aiz.check(i.yJO(0)),siblingIndex:i.Aiz.check(i.OWK(0))}){}class G extends x.extend("MindmapEdge")({metadata:q}){}class V extends I.extend("MindmapDiagram")({type:i.uSQ(J),nodes:i.O31(X).pipe(i.fXn).check(i.tJb(2)),edges:i.O31(G).pipe(i.fXn).check(i.tJb(1))}){}function H(e){return function(e){O(e);let t=e.nodes.filter(e=>"root"===e.kind);if(1!==t.length)throw new $(`Mindmap must contain exactly one root topic; found ${t.length}.`);let r=t[0];if(!r||0!==r.metadata.depth)throw new $("Mindmap root topic must have depth 0.");let n=new Map,i=new Map(e.nodes.map(e=>[e.id,e])),a=new Map;for(let t of e.edges){n.set(t.target,(n.get(t.target)??0)+1);let e=i.get(t.source)?.metadata.depth,r=i.get(t.target),s=r?.metadata.depth;if(void 0===e||s!==e+1)throw new $(`Mindmap edge "${t.id}" must connect a topic to its immediate child.`);if(!r||t.metadata.depth!==r.metadata.depth||t.metadata.siblingIndex!==r.metadata.siblingIndex)throw new $(`Mindmap edge "${t.id}" metadata must match its child topic.`);a.set(t.source,[...a.get(t.source)??[],r.metadata.siblingIndex])}for(let t of e.nodes){let e=n.get(t.id)??0;if(t.id===r.id?0!==e:1!==e)throw new $(`Mindmap topic "${t.id}" must have ${t.id===r.id?"no parent":"exactly one parent"}.`)}for(let[e,t]of a){let r=t.map((e,t)=>t);if([...t].sort((e,t)=>e-t).some((e,t)=>e!==r[t]))throw new $(`Mindmap children of "${e}" must use contiguous sibling ordering from 0.`)}return e}(i.svK(V,{errors:"all"})(e))}let K=H({id:"public-mindmap-capability",title:"Public mindmap generation",type:J,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"}});C(W),C(K);let Q=new Intl.Segmenter(void 0,{granularity:"grapheme"}),Z=/\p{Emoji_Presentation}|\uFE0F|\p{Regional_Indicator}|\u20E3/u,ee=/^[\u200B-\u200D\u2060\uFE00-\uFE0F]+$/u;function et(e){return Array.from(Q.segment(e),e=>e.segment)}function er(e){var t;return ee.test(e)?0:Z.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 en(e){return et(e).reduce((e,t)=>e+er(t),0)}function ei(e,t){return Math.max(...e.split("\n").map(e=>(function(e,t){let r=0,n=0;for(let t of et(e)){let e=er(t);62===e?r+=1:n+=e}return r*t*.62+n*t/100})(e,t)))}function ea(e,t,r){let n=ei(e,t);return Math.max(1,Math.min(r,Math.ceil(n)),Math.ceil(n-t))}function es(e,t){return e.split("\n").flatMap(e=>(function(e,t){if(en(e)<=t)return[e];let r=[],n="";for(let i of e.split(" ")){if(en(i)>t){n&&(r.push(n),n=""),r.push(...function(e,t){let r=[],n="",i=0;for(let a of et(e)){let e=er(a);n&&i+e>t&&(r.push(n),n="",i=0),n+=a,i+=e}return n&&r.push(n),r}(i,t));continue}let e=n?`${n} ${i}`:i;if(en(e)<=t){n=e;continue}r.push(n),n=i}return n&&r.push(n),r})(e,t)).join("\n")}function eo(e,t,r){return es(e,Math.floor(100*t/r+1e-6))}let el=Object.freeze({maxDimension:16384,maxElements:600,maxGroupsPerElement:16,maxLayouts:128,maxLayers:64,maxPointsPerElement:256,maxSerializedBytes:15e5,maxTextLength:4096,maxZOrderEntries:600});function ed(e){let t=new Set;for(let r of e){if(t.has(r))return r;t.add(r)}}function ec(e){return"x"in e&&"y"in e}function eu(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>el.maxElements&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${el.maxElements} elements.`,path:"elements"}),e.layers.length>el.maxLayers&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${el.maxLayers} layers.`,path:"layers"}),e.layouts.length>el.maxLayouts&&t.push({code:"limit_exceeded",message:`Canvas exceeds ${el.maxLayouts} layout primitives.`,path:"layouts"}),(e.width>el.maxDimension||e.height>el.maxDimension)&&t.push({code:"limit_exceeded",message:`Canvas dimensions may not exceed ${el.maxDimension}.`,path:"width"});let r=ed(e.elements.map(e=>e.id));r&&t.push({code:"duplicate_element_id",elementId:r,message:`Duplicate element id "${r}" is not allowed.`,path:"elements"});let n=ed(e.layers.map(e=>e.id));n&&t.push({code:"duplicate_layer_id",message:`Duplicate layer id "${n}" is not allowed.`,path:"layers"});let i=ed(e.zOrder);i&&t.push({code:"duplicate_z_order_element",elementId:i,message:`zOrder contains duplicate element "${i}".`,path:"zOrder"}),e.zOrder.length>el.maxZOrderEntries&&t.push({code:"limit_exceeded",message:`zOrder exceeds ${el.maxZOrderEntries} entries.`,path:"zOrder"});let a=new Map(e.elements.map(e=>[e.id,e])),s=e.elements.filter(e=>"node"===e.type),o=new Map(s.map(e=>[e.nodeId,e])),l=ed(s.map(e=>e.nodeId));l&&t.push({code:"invalid_binding",message:`Duplicate nodeId "${l}" makes connector bindings ambiguous.`,path:"elements"});let d=ed(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=ed(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 u=new Map(e.layers.map(e=>[e.id,e])),f=new Set(u.keys()),p=e=>!e.layerId||u.get(e.layerId)?.visible!==!1,h=new Map;for(let[t,r]of e.elements.entries())"text"===r.type&&r.containerId&&p(r)&&h.set(r.containerId,{element:r,index:t});e.elements.forEach((e,r)=>{let n,i;if(t.push(...(n=[],i=`elements[${r}]`,"width"in e&&"height"in e&&(!(e.width>0)||!(e.height>0))&&n.push({code:"invalid_geometry",elementId:e.id,message:`Element "${e.id}" must have positive width and height.`,path:i}),"points"in e&&void 0!==e.points&&e.points.length>el.maxPointsPerElement&&n.push({code:"limit_exceeded",elementId:e.id,message:`Element "${e.id}" exceeds ${el.maxPointsPerElement} points.`,path:`${i}.points`}),"text"in e&&e.text.length>el.maxTextLength&&n.push({code:"limit_exceeded",elementId:e.id,message:`Text element "${e.id}" exceeds ${el.maxTextLength} characters.`,path:`${i}.text`}),"node"===e.type&&"polygon"===e.shape&&(!e.points||e.points.length<3)&&n.push({code:"invalid_polygon",elementId:e.id,message:`Polygon "${e.id}" requires at least three points.`,path:`${i}.points`}),e.groupIds&&e.groupIds.length>el.maxGroupsPerElement&&n.push({code:"limit_exceeded",elementId:e.id,message:`Element "${e.id}" exceeds ${el.maxGroupsPerElement} groups.`,path:`${i}.groupIds`}),n)),"node"===e.type&&"polygon"!==e.shape&&p(e)){let n=h.get(e.id);if(n||"sequence-lifeline"!==e.rendererRole){let i=n?.element.text??e.label,a=n?.element.fontSize??16,s=n?n.element.maxWidth??160:Math.max(1,e.width-24),o=i.split("\n"),l=Math.max(1,Math.min(s,ei(i,a))),d=Math.ceil(o.length*a*1.35),c=ea(i,a,s)-a;(l+24>e.width||c+24>e.width||d+18>e.height)&&t.push({code:"label_overflow",elementId:n?.element.id??e.id,message:`Label does not fit inside node "${e.id}" without changing its geometry.`,path:n?`elements[${n.index}].text`:`elements[${r}].label`})}}if(e.frameId){let n=a.get(e.frameId);n&&"frame"===n.type||t.push({code:"invalid_composition",elementId:e.id,message:`Element "${e.id}" references missing frame "${e.frameId}".`,path:`elements[${r}].frameId`})}if(e.layerId&&!f.has(e.layerId)&&t.push({code:"invalid_composition",elementId:e.id,message:`Element "${e.id}" references missing layer "${e.layerId}".`,path:`elements[${r}].layerId`}),e.groupIds&&ed(e.groupIds)&&t.push({code:"invalid_composition",elementId:e.id,message:`Element "${e.id}" contains duplicate group ids.`,path:`elements[${r}].groupIds`}),"text"===e.type&&e.containerId){let n=a.get(e.containerId);n&&("node"===n.type||"arrow"===n.type)||t.push({code:"invalid_binding",elementId:e.id,message:`Text "${e.id}" references unsupported container "${e.containerId}".`,path:`elements[${r}].containerId`})}if("arrow"===e.type&&(o.has(e.sourceNodeId)||t.push({code:"invalid_binding",elementId:e.id,message:`Connector "${e.id}" references missing source "${e.sourceNodeId}".`,path:`elements[${r}].sourceNodeId`}),o.has(e.targetNodeId)||t.push({code:"invalid_binding",elementId:e.id,message:`Connector "${e.id}" references missing target "${e.targetNodeId}".`,path:`elements[${r}].targetNodeId`})),"line"===e.type)for(let[n,i]of[["startBinding",e.startBinding],["endBinding",e.endBinding]]){let s=i?a.get(i.elementId):void 0;i&&(!s||"node"!==s.type&&"frame"!==s.type)&&t.push({code:"invalid_binding",elementId:e.id,message:`Line "${e.id}" references missing binding "${i.elementId}".`,path:`elements[${r}].${n}`})}});let m=new Set(e.zOrder);for(let r of e.elements)m.has(r.id)||t.push({code:"missing_z_order_element",elementId:r.id,message:`Element "${r.id}" is missing from zOrder.`,path:"zOrder"});for(let r of e.zOrder)a.has(r)||t.push({code:"unknown_z_order_element",elementId:r,message:`zOrder references missing element "${r}".`,path:"zOrder"});for(let[r,n]of e.layouts.entries())for(let e of n.ids){let n=a.get(e);n&&ec(n)||t.push({code:"unknown_layout_target",elementId:e,message:`Layout references missing or non-positioned element "${e}".`,path:`layouts[${r}].ids`})}for(let r of e.elements.filter(e=>"frame"===e.type)){let e=new Set([r.id]),n=r.frameId;for(;n;){if(e.has(n)){t.push({code:"invalid_composition",elementId:r.id,message:`Frame "${r.id}" participates in a frame nesting cycle.`,path:"elements"});break}e.add(n);let i=a.get(n);n=i?.type==="frame"?i.frameId:void 0}}return t}function ef(e){if("text"===e.type){let t=e.text.split("\n");return{x:e.x,y:e.y,width:e.maxWidth??ei(e.text,e.fontSize),height:t.length*e.fontSize*1.35}}return{x:e.x,y:e.y,width:e.width,height:e.height}}function ep(e,t){let r=new Map(e.map(e=>[e.id,e]));return t.flatMap(e=>{let t=r.get(e);return t&&ec(t)?[t]:[]})}function eh(e,t){return e.map(e=>{var r,n;let i=t.get(e.id);return i?(r=i.x,n=i.y,ec(e)?{...e,x:r,y:n}:e):e})}function em(e,t){return"x"===t?e.x:e.y}function eg(e,t){return"x"===t?e.width:e.height}function ey(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function ev(e,t){let r=ey(e),n=t.x-r.x,i=t.y-r.y;return Math.abs(n)>=Math.abs(i)?{x:n>=0?e.x+e.width:e.x,y:r.y}:{x:r.x,y:i>=0?e.y+e.height:e.y}}function eb(e,t=.01){let r=[];for(let n=0;n<e.length-1;n+=1){let i=e[n],a=e[n+1];if(!i||!a)continue;let s=Math.abs(i.y-a.y)<=t,o=Math.abs(i.x-a.x)<=t;if(!s&&!o)continue;let l=Math.min(s?i.x:i.y,s?a.x:a.y),d=Math.max(s?i.x:i.y,s?a.x:a.y);d-l<=t||r.push({min:l,max:d,orientation:s?"horizontal":"vertical",staticCoordinate:s?i.y:i.x,segmentIndex:n,isFirstSegment:0===n,isLastSegment:n===e.length-2})}return r}function e_(e,t,r=.01){return e.orientation===t.orientation&&Math.abs(e.staticCoordinate-t.staticCoordinate)<=r&&Math.min(e.max,t.max)-Math.max(e.min,t.min)>r}function ex(e,t,r=.01){let n="horizontal"===e.orientation,i=n?t.y:t.x,a=i+(n?t.height:t.width),s=n?t.x:t.y,o=s+(n?t.width:t.height);return e.staticCoordinate>i+r&&e.staticCoordinate<a-r&&Math.min(e.max,o)-Math.max(e.min,s)>r}function ew(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}let ek=/[,;]\s*(?:id|label|kind|group|source|target|title|direction|nodes|edges)\s*:?\s*$/i;function eS(e){let t=e.trim();for(;;){let e=t.replace(ek,"").trim();if(e===t)return t;t=e}}class eI extends i.Xsx("ContractSchemaIssue")({code:eW("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 e$ extends i.rNF()("ContractSchemaError",{issues:i.O31(i.O3D(eI))}){}let eE=e=>{var t;if("InvalidType"!==e._tag)return c.vp(e);let r=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===r?"null":Array.isArray(r)?"array":typeof r}`},eO=c.ID({leafHook:eE});function eC(e){let t,r;return new e$({issues:(t=[],((r=(e,n,i)=>{switch(e._tag){case"Pointer":return r(e.issue,[...n,...e.path],i);case"Encoding":return r(e.issue,n,i);case"Composite":for(let t of e.issues)r(t,n,e.ast);return;case"AnyOf":if(e.issues.length>0){for(let t of e.issues)r(t,n,e.ast);return}break;case"Filter":if(void 0===c.VY(e)&&"InvalidValue"!==e.issue._tag)return r(e.issue,n,i)}let a="ast"in e?e.ast:i,s="MissingKey"===e._tag&&e.annotations?.[eP]==="invalid_type"?"invalid_type":void 0,o=a&&d.mi(a)&&a.types.every(d.c$)?"LiteralUnion":a?._tag,l=a?.annotations?.[eN],u="string"==typeof l?[...n,l]:n;for(let r of eO(e).issues)t.push({code:"custom",issueTag:e._tag,...s?{missingKeyCode:s}:{},...o?{astKind:o}:{},message:r.message,path:u})})(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 eT=new Set(["x-sketchi-default","x-sketchi-one-of","const","exclusiveMaximum","exclusiveMinimum","maximum","maxLength","maxItems","minimum","minItems","minLength","pattern"]),eM="x-sketchi-default",eA="x-sketchi-one-of",eN="codeModeDiscriminator",eP="codeModeMissingKeyCode";function eR(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function ej(e){let t=i._oz(i.AxX(e),{includeAnnotationKey:e=>eT.has(e),onExcessProperty:"error"});return function e(t){if(Array.isArray(t))return t.map(e);if(!eR(t))return t;let r=Object.fromEntries(Object.entries(t).map(([t,r])=>[t,e(r)])),n=!0===r[eA];delete r[eA],n&&Array.isArray(r.anyOf)&&(r.oneOf=r.anyOf,delete r.anyOf);let i=r.allOf;if(Array.isArray(i)){let e=[];for(let t of i)eR(t)&&Object.hasOwn(t,eM)?r.default=t[eM]:e.push(t);0===e.length?delete r.allOf:r.allOf=e}return r}({$schema:"https://json-schema.org/draft/2020-12/schema",...t.schema,...0===Object.keys(t.definitions).length?{}:{$defs:t.definitions}})}function eD(e){return i.O31(e).pipe(i.fXn).check(i.tJb(1,{message:"Too small: expected array to have >=1 items"}))}function eU(e){return i.Qrq(e)}function eF(e){return e.pipe(i.usV({[eP]:"invalid_type",messageMissingKey:"Invalid input: expected string, received undefined"}))}function eB(e){return e.pipe(i.usV({[eP]:"invalid_type",messageMissingKey:"Invalid input: expected object, received undefined"}))}function eL(e){return e.pipe(i.usV({[eP]:"invalid_type",messageMissingKey:"Invalid input: expected array, received undefined"}))}function ez(e){return i.xCb(e).annotate({message:`Invalid option: expected one of ${e.map(e=>JSON.stringify(e)).join("|")}`})}function eW(e){return eX(e,i.QfV)}function eJ(e){return eX(e,i.wNn)}function eY(e){return eX(e,i.v8c)}function eX(e,t){let r=i.hzj()([],()=>(t,r,n)=>t===e?s.PyW(e):s.fJG(new c.eE(r,t,n)),{message:`Invalid literal value, expected ${JSON.stringify(e)}`,toCodecJson:()=>i.nfo()(t.annotate({const:e}),{decode:u.pd(()=>e),encode:u.pd(e=>e)})});return i.uSQ(e).pipe(i.GLL(r))}let eq=i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"})),eG=eF(eq),eV=i.wYs,eH=i.wNn.check(i.MIs(),i.yJO(0,{message:"Too small: expected number to be >0"})),eK=/^#[0-9a-fA-F]{6}$/u;function eQ(e){return i.QfV.annotate(void 0===e?{}:{default:e}).check(i.Pto(eK,{message:`Invalid string: must match pattern /${eK.source}/`}))}let eZ=eQ(),e0=["excalidraw","scene","png"],e1=["excalidraw","scene"],e2=Object.assign(ez(e0),{options:e0}),e5=Object.assign(ez(e1),{options:e1});class e3 extends i.Xsx("ArtifactProvenance")({sourceArtifactId:eG.pipe(i.Wa3)},{identifier:void 0}){}let e6=["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","mindmap_too_deep","mindmap_too_large","request_too_large","generic_label","label_too_long","quality_below_threshold","render_failed","text_overflow","arrow_binding_invalid","arrow_overlap","export_invalid_scene","storage_read_failed","storage_write_failed","unsupported_artifact_format","patch_source_unavailable","unknown_patch_target","unsupported_patch_operation","patch_preserve_connectivity_failed","patch_output_invalid","duplicate_element_id","duplicate_layer_id","invalid_canvas_binding","invalid_canvas_composition","invalid_canvas_geometry","invalid_polygon","canvas_limit_exceeded","invalid_z_order","unknown_layout_target"],e8=Object.assign(ez(e6),{options:e6}),e9=ez(["request","diagram","node","edge","element","layer","artifact"]),e4=ez(["input","canvas","flowchart","mindmap","quality","render","export","storage"]);class e7 extends i.Xsx("CodeModeIssueRef")({kind:e9,id:eU(eq),path:eU(eq)},{identifier:void 0}){}class te extends i.Xsx("CodeModeIssue")({code:e8,severity:ez(["error","warning"]),stage:e4,ref:eU(e7),message:eG,hint:eG},{identifier:void 0}){}let tt=["start","process","decision","end"],tr=Object.assign(ez(tt),{options:tt}),tn=["setDefaultStyle","setStyle","setShape","translate","replaceText","rerouteEdges","insert","remove","replace","reorder","group","ungroup"];Object.assign(ez(tn),{options:tn});class ti extends i.Xsx("FlowchartSpecNode")({id:eG,label:eG,kind:tr,description:eU(eq)},{identifier:void 0}){}class ta extends i.Xsx("FlowchartSpecEdge")({id:eU(eq),source:eG,target:eG,label:eU(eq)},{identifier:void 0}){}let ts=ez(["TB","LR"]),to=ts.annotate({default:"TB"}).pipe(i.E$i(s.PyW("TB")));class tl extends i.Xsx("FlowchartSpecLayout")({direction:to},{identifier:void 0}){}let td=m.accentColor,tc=eQ(td).pipe(i.E$i(s.PyW(td))),tu=m.backgroundColor,tf=eQ(tu).pipe(i.E$i(s.PyW(tu)));class tp extends i.Xsx("FlowchartSpecStyle")({accentColor:tc,backgroundColor:tf},{identifier:void 0}){}let th=[],tm=i.O31(ta).pipe(i.fXn).annotate({default:th}).pipe(i.E$i(s.PyW(th))),tg={direction:"TB"},ty=tl.annotate({default:tg}).pipe(i.E$i(s.PyW(tg)),i.usV({[eM]:tg})),tv={accentColor:m.accentColor,backgroundColor:m.backgroundColor},tb=tp.annotate({default:tv}).pipe(i.E$i(s.PyW(tv)),i.usV({[eM]:tv}));class t_ extends i.Xsx("FlowchartSpec")({id:eU(eq),title:eG,nodes:eL(eD(ti)),edges:tm,layout:ty,style:tb},{identifier:void 0}){}class tx extends i.Xsx("SequenceParticipantSpec")({id:eG,label:eG,kind:eU(eq)},{identifier:void 0}){}class tw extends i.Xsx("SequenceMessageSpec")({id:eU(eq),source:eG,target:eG,label:eG,type:eU(ez(["message","return"])),style:eU(ez(["solid","dashed"]))},{identifier:void 0}){}let tk=[],tS=i.O31(tw).pipe(i.fXn).annotate({default:tk}).pipe(i.E$i(s.PyW(tk)));class tI extends i.Xsx("SequenceDiagramSpec")({id:eU(eq),title:eG,participants:eL(eD(tx)),messages:tS,style:tb},{identifier:void 0}){}let t$=eU(eD(e2)),tE=eU(i.O31(e5).pipe(i.fXn)),tO=eU(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 tC extends i.Xsx("BuildFlowchartOptions")({artifactFormats:t$,inlineArtifacts:tE,minQualityScore:tO},{identifier:void 0}){}eU(tC);class tT extends i.Xsx("BuildFlowchartRequest")({requestId:eU(eq),spec:eB(t_),options:eU(tC)},{identifier:void 0}){}let tM=t_.mapFields(({id:e,title:t,nodes:r,edges:n,layout:i})=>({id:e,title:t,nodes:r,edges:n,layout:i})),tA=i._kM({requestId:eU(eq),spec:eB(tM)}),tN=i.rcy(tA,{leafHook:eE,parseOptions:{errors:"all"}}),tP=Object.assign(tN,{"~standard":{...tN["~standard"],jsonSchema:{input:()=>ej(tA),output:()=>ej(tA)}}}),tR=Object.assign(tT,{omit:e=>tP});class tj extends i.Xsx("BuildSequenceDiagramRequest")({requestId:eU(eq),spec:eB(tI),options:eU(tC)},{identifier:void 0}){}let tD=i.QfV.check(i.tJb(1,{message:"Too small: expected string to have >=1 characters"}),i.HNH(function(e){let t=eS(e);return t.length>0&&!/^(?:""|''|``)$/.test(t)},{message:"Must contain semantic text after normalization."})),tU=eB(i.DYE(()=>tF).annotate({identifier:"__schema0"})),tF=i._kM({label:eF(tD),children:i.Qrq(i.O31(tU).pipe(i.fXn))});class tB extends i.Xsx("MindmapSpecLayout")({direction:ez(["LR","RL"]).annotate({default:"LR"}).pipe(i.E$i(s.PyW("LR")))},{identifier:void 0}){}let tL={direction:"LR"},tz=tB.annotate({default:tL}).pipe(i.E$i(s.PyW(tL)),i.usV({[eM]:tL})),tW=i._kM({id:eU(eq),title:eF(tD),root:tU,layout:tz,style:tb});class tJ extends i.Xsx("MindmapSpec")(tW,{identifier:void 0}){}let tY=i._kM({requestId:eU(eq),spec:eB(tW),options:eU(tC)});i.Xsx("BuildMindmapRequest")(tY,{identifier:void 0});class tX extends i.Xsx("ScenePoint")({x:eV.pipe(i.Wa3),y:eV.pipe(i.Wa3)},{identifier:void 0}){}let tq={frameId:eU(eq).pipe(i.Wa3),groupIds:eU(i.O31(eq).pipe(i.fXn).annotate({maxItems:el.maxGroupsPerElement})).pipe(i.Wa3),layerId:eU(eq).pipe(i.Wa3),locked:eU(i.v8c).pipe(i.Wa3),opacity:eU(i.wNn.check(i.MIs(),i.Bt9({minimum:0,maximum:100}))).pipe(i.Wa3),zIndex:eU(i.Aiz).pipe(i.Wa3)},tG={fillColor:eU(eZ).pipe(i.Wa3),fillStyle:eU(ez(["cross-hatch","hachure","solid"])).pipe(i.Wa3),roughness:eU(ez([0,1,2])).pipe(i.Wa3),strokeColor:eU(eZ).pipe(i.Wa3),strokeStyle:eU(ez(["dashed","dotted","solid"])).pipe(i.Wa3),strokeWidth:eU(ez([1,2,4])).pipe(i.Wa3)},tV=i.T9y(ez(["arrow","bar","circle","diamond","triangle"])),tH=i.O31(tX).pipe(i.fXn).check(i.tJb(2,{message:"Too small: expected array to have >=2 items"}),i.NYj(el.maxPointsPerElement,{message:`Too big: expected array to have <=${el.maxPointsPerElement} items`}));class tK extends i.Xsx("NodeSceneElement")({...tq,...tG,type:eW("node"),id:eG,nodeId:eG,kind:eU(eq),rendererRole:eU(ez(["sequence-lifeline"])),shape:ez(["rectangle","ellipse","diamond","circle","polygon"]).pipe(i.Wa3),points:eU(tH).pipe(i.Wa3),textColor:eU(eZ).pipe(i.Wa3),x:eV.pipe(i.Wa3),y:eV.pipe(i.Wa3),width:eH.pipe(i.Wa3),height:eH.pipe(i.Wa3),label:eG.pipe(i.Wa3)},{identifier:void 0}){}class tQ extends i.Xsx("TextSceneElement")({...tq,type:eW("text"),id:eG,containerId:eU(eq),textColor:eU(eZ).pipe(i.Wa3),x:eV.pipe(i.Wa3),y:eV.pipe(i.Wa3),text:eG.pipe(i.Wa3),fontSize:eH,fontFamily:eU(ez(["hand","mono","sans"])),maxWidth:eU(eH),textAlign:eU(ez(["center","left","right"])),verticalAlign:eU(ez(["bottom","middle","top"]))},{identifier:void 0}){}class tZ extends i.Xsx("ArrowSceneElement")({...tq,...tG,type:eW("arrow"),id:eG,edgeId:eG,sourceNodeId:eG,targetNodeId:eG.pipe(i.Wa3),startArrowhead:eU(tV).pipe(i.Wa3),endArrowhead:eU(tV).pipe(i.Wa3),textColor:eU(eZ).pipe(i.Wa3),points:eL(tH).pipe(i.Wa3),label:eU(eq).pipe(i.Wa3)},{identifier:void 0}){}class t0 extends i.Xsx("CanvasLineBinding")({elementId:eG,focus:eU(eV),gap:eU(eV)},{identifier:void 0}){}class t1 extends i.Xsx("LineSceneElement")({...tq,...tG,type:eW("line"),id:eG,points:eL(tH).pipe(i.Wa3),startBinding:eU(t0).pipe(i.Wa3),endBinding:eU(t0).pipe(i.Wa3),startArrowhead:eU(tV).pipe(i.Wa3),endArrowhead:eU(tV).pipe(i.Wa3),label:eU(eq).pipe(i.Wa3),textColor:eU(eZ).pipe(i.Wa3)},{identifier:void 0}){}class t2 extends i.Xsx("FrameSceneElement")({...tq,...tG,type:eW("frame"),id:eG,name:eU(eq).pipe(i.Wa3),x:eV.pipe(i.Wa3),y:eV.pipe(i.Wa3),width:eH.pipe(i.Wa3),height:eH.pipe(i.Wa3)},{identifier:void 0}){}class t5 extends i.Xsx("CanvasLayer")({id:eG,name:eU(eq),locked:eU(i.v8c),visible:eU(i.v8c)},{identifier:void 0}){}let t3=eL(eD(eq));class t6 extends i.Xsx("CanvasFlowLayout")({type:ez(["row","column","stack"]),ids:t3,x:eU(eV),y:eU(eV),gap:eU(eV)},{identifier:void 0}){}class t8 extends i.Xsx("CanvasGridLayout")({type:eW("grid"),ids:t3,columns:i.Aiz.check(i.OWK(1,{message:"Too small: expected number to be >=1"})),x:eU(eV),y:eU(eV),columnGap:eU(eV),rowGap:eU(eV)},{identifier:void 0}){}class t9 extends i.Xsx("CanvasAlignLayout")({type:eW("align"),ids:t3,axis:ez(["x","y"]),alignment:ez(["center","end","start"])},{identifier:void 0}){}class t4 extends i.Xsx("CanvasDistributeLayout")({type:eW("distribute"),ids:t3,axis:ez(["x","y"]),gap:eU(eV)},{identifier:void 0}){}let t7=i.gPz([tK,tQ,tZ,t1,t2],{mode:"oneOf"}).annotate({[eA]:!0}),re=i.gPz([t6,t8,t9,t4],{mode:"oneOf"}),rt=i.O31(t5).pipe(i.fXn).annotate({default:[],maxItems:el.maxLayers}).pipe(i.E$i(s.PyW([]))),rr=i.O31(re).pipe(i.fXn).annotate({default:[],maxItems:el.maxLayouts}).pipe(i.E$i(s.PyW([]))),rn=i.O31(eq).pipe(i.fXn).annotate({default:[],maxItems:el.maxZOrderEntries}).pipe(i.E$i(s.PyW([])));class ri extends i.Xsx("CanvasSpec")({kind:eW("canvas"),version:eJ(1),diagramId:eG,title:eG,width:eH.pipe(i.Wa3),height:eH.pipe(i.Wa3),accentColor:eZ.pipe(i.Wa3),backgroundColor:eZ.pipe(i.Wa3),elements:eL(i.O31(t7).pipe(i.fXn).annotate({maxItems:el.maxElements})),layers:rt,layouts:rr,zOrder:rn},{identifier:void 0}){}let ra=ri;class rs extends i.Xsx("CreateCanvasRequest")({requestId:eU(eq),spec:eB(ri),options:eU(tC)},{identifier:void 0}){}let ro=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 rl extends i.Xsx("ExcalidrawScene")({appState:i.mSG(i.QfV,i.$r1),elements:i.O31(ro).pipe(i.fXn)},{identifier:void 0}){}class rd extends rl.extend("ExcalidrawFile")({files:i.mSG(i.QfV,i.$r1),source:eG,type:eW("excalidraw"),version:eJ(2)},{identifier:void 0}){}let rc=rd;class ru extends i.Xsx("GetArtifactRequest")({artifactId:eG,format:eU(e2),inline:eU(i.v8c)},{identifier:void 0}){}class rf extends i.Xsx("DiagramSelector")({ids:eU(i.O31(eq).pipe(i.fXn)),nodeIds:eU(i.O31(eq).pipe(i.fXn)),edgeIds:eU(i.O31(eq).pipe(i.fXn)),kinds:eU(i.O31(tr).pipe(i.fXn)),labels:eU(i.O31(eq).pipe(i.fXn)),scope:eU(ez(["all","nodes","edges"]))},{identifier:void 0}){}class rp extends i.Xsx("DiagramStylePatch")({strokeColor:eU(eZ),fillColor:eU(eZ),textColor:eU(eZ),backgroundColor:eU(eZ)},{identifier:void 0}){}let rh=["rectangle","diamond","ellipse","circle","polygon"],rm=Object.assign(ez(rh),{options:rh});class rg extends i.Xsx("SetDefaultStyleOperation")({op:eW("setDefaultStyle"),style:eB(rp)},{identifier:void 0}){}class ry extends i.Xsx("SetStyleOperation")({op:eW("setStyle"),selector:eB(rf),style:eB(rp)},{identifier:void 0}){}class rv extends i.Xsx("SetShapeOperation")({op:eW("setShape"),selector:eB(rf),shape:rm},{identifier:void 0}){}class rb extends i.Xsx("TranslateOperation")({op:eW("translate"),selector:eB(rf),dx:eV,dy:eV},{identifier:void 0}){}class r_ extends i.Xsx("ReplaceTextOperation")({op:eW("replaceText"),selector:eB(rf),text:eG},{identifier:void 0}){}class rx extends i.Xsx("RerouteEdgesOperation")({op:eW("rerouteEdges"),selector:eU(rf)},{identifier:void 0}){}let rw=eL(eD(eq));class rk extends i.Xsx("InsertElementsOperation")({op:eW("insert"),elements:eL(eD(t7)),beforeId:eU(eq),afterId:eU(eq)},{identifier:void 0}){}class rS extends i.Xsx("RemoveElementsOperation")({op:eW("remove"),selector:eB(rf)},{identifier:void 0}){}class rI extends i.Xsx("ReplaceElementOperation")({op:eW("replace"),id:eG,element:eB(t7)},{identifier:void 0}){}class r$ extends i.Xsx("ReorderElementsOperation")({op:eW("reorder"),ids:rw,beforeId:eU(eq),afterId:eU(eq)},{identifier:void 0}){}class rE extends i.Xsx("GroupElementsOperation")({op:eW("group"),ids:rw,groupId:eG},{identifier:void 0}){}class rO extends i.Xsx("UngroupElementsOperation")({op:eW("ungroup"),ids:rw,groupId:eU(eq)},{identifier:void 0}){}let rC=i.gPz([rg,ry,rv,rb,r_,rx,rk,rS,rI,r$,rE,rO],{mode:"oneOf"}).annotate({[eA]:!0,[eN]:"op",message:`Invalid discriminator value. Expected ${tn.map(e=>`'${e}'`).join(" | ")}`});class rT extends i.Xsx("ArtifactPatchSource")({artifactId:eG,format:eU(eW("scene"))},{identifier:void 0}){}class rM extends i.Xsx("InlineScenePatchSource")({scene:eB(ri)},{identifier:void 0}){}let rA=i.gPz([rT,rM]).annotate({message:"Invalid input"});class rN extends i.Xsx("ApplyDiagramPatchOptions")({artifactFormats:t$,inlineArtifacts:tE,preserveConnectivity:eU(i.v8c)},{identifier:void 0}){}eU(rN);class rP extends i.Xsx("ApplyDiagramPatchRequest")({requestId:eU(eq),source:rA.annotateKey({messageMissingKey:"Invalid input"}),operations:eL(eD(rC)),options:eU(rN),intent:eU(eq)},{identifier:void 0}){}class rR extends i.Xsx("NormalizedMindmapTopic")({id:eq,label:eq,children:i.O31(i.DYE(()=>rR)).pipe(i.fXn)},{identifier:void 0}){}let rj=i._kM({id:eq,title:eq,nodes:i.O31(ti).pipe(i.fXn),edges:i.O31(ta.mapFields(e=>({...e,id:eq}))).pipe(i.fXn),layout:i._kM({direction:ts}),style:i._kM({accentColor:eZ,backgroundColor:eZ})}),rD=i._kM({id:eq,title:eq,root:rR,layout:i._kM({direction:ez(["LR","RL"])}),style:i._kM({accentColor:eZ,backgroundColor:eZ})}),rU=i._kM({id:eq,title:eq,participants:i.O31(tx).pipe(i.fXn),messages:i.O31(tw.mapFields(e=>({...e,id:eq}))).pipe(i.fXn),style:i._kM({accentColor:eZ,backgroundColor:eZ})}),rF=i._kM({code:i.QfV,passed:i.v8c,severity:ez(["error","warning"]),message:i.QfV,refs:i.O31(e7).pipe(i.fXn)}),rB=i._kM({accepted:i.v8c,score:i.wNn,threshold:i.wNn,summary:i._kM({nodeCount:i.wNn,edgeCount:i.wNn}),checks:i.O31(rF).pipe(i.fXn)}),rL=i._kM({format:e2,mimeType:i.QfV,url:eU(i.QfV),expiresAt:eU(i.QfV),inline:eU(i.$r1),sizeBytes:eU(i.wNn)}),rz=i._kM({artifactId:i.QfV,diagramId:i.QfV,formats:i.O31(rL).pipe(i.fXn),provenance:eU(e3),preview:eU(rL)}),rW=i._kM({artifactId:eU(i.QfV),diagramId:eU(i.QfV),formats:eU(i.O31(rL).pipe(i.fXn))});class rJ extends i.Xsx("BuildFlowchartAccepted")({ok:eY(!0),status:eW("accepted"),buildId:i.QfV,requestId:eU(i.QfV),normalizedSpec:rj,quality:rB,artifact:rz,issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}class rY extends i.Xsx("BuildFlowchartRejected")({ok:eY(!1),status:ez(["invalid_input","invalid_flowchart","quality_failed","render_failed","export_failed","storage_failed"]),buildId:eU(i.QfV),requestId:eU(i.QfV),normalizedSpec:eU(rj),quality:eU(rB),partial:eU(rW),issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rJ,rY]);class rX extends i.Xsx("BuildMindmapAccepted")({ok:eY(!0),status:eW("accepted"),buildId:i.QfV,requestId:eU(i.QfV),normalizedSpec:rD,quality:rB,artifact:rz,issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}class rq extends i.Xsx("BuildMindmapRejected")({ok:eY(!1),status:ez(["invalid_input","invalid_mindmap","quality_failed","render_failed","export_failed","storage_failed"]),buildId:eU(i.QfV),requestId:eU(i.QfV),normalizedSpec:eU(rD),quality:eU(rB),partial:eU(rW),issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rX,rq]);class rG extends i.Xsx("BuildSequenceDiagramAccepted")({ok:eY(!0),status:eW("accepted"),buildId:i.QfV,requestId:eU(i.QfV),normalizedSpec:rU,quality:rB,artifact:rz,issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}class rV extends i.Xsx("BuildSequenceDiagramRejected")({ok:eY(!1),status:ez(["invalid_input","invalid_sequence","quality_failed","render_failed","export_failed","storage_failed"]),buildId:eU(i.QfV),requestId:eU(i.QfV),normalizedSpec:eU(rU),quality:eU(rB),partial:eU(rW),issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rG,rV]);class rH extends i.Xsx("GetArtifactAccepted")({ok:eY(!0),artifactId:i.QfV,diagramId:i.QfV,format:e2,mimeType:i.QfV,url:eU(i.QfV),expiresAt:eU(i.QfV),inline:eU(i.$r1),sizeBytes:eU(i.wNn),provenance:eU(e3)},{identifier:void 0}){}class rK extends i.Xsx("GetArtifactRejected")({ok:eY(!1),status:ez(["invalid_input","not_found","format_unavailable","expired","storage_failed"]),issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rH,rK]);class rQ extends i.Xsx("ApplyDiagramPatchAccepted")({ok:eY(!0),status:eW("accepted"),patchId:i.QfV,requestId:eU(i.QfV),sourceArtifactId:eU(i.QfV),artifact:rz,issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}class rZ extends i.Xsx("ApplyDiagramPatchRejected")({ok:eY(!1),status:ez(["invalid_input","source_unavailable","target_not_found","unsupported_operation","connectivity_changed","render_failed","export_failed","storage_failed"]),patchId:eU(i.QfV),requestId:eU(i.QfV),sourceArtifactId:eU(i.QfV),partial:eU(rW),issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}i.gPz([rQ,rZ]);class r0 extends i.Xsx("CreateCanvasAccepted")({ok:eY(!0),status:eW("accepted"),buildId:i.QfV,requestId:eU(i.QfV),normalizedSpec:ri,artifact:rz,issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}class r1 extends i.Xsx("CreateCanvasRejected")({ok:eY(!1),status:ez(["invalid_input","invalid_canvas","limit_exceeded","render_failed","export_failed","storage_failed"]),buildId:eU(i.QfV),requestId:eU(i.QfV),normalizedSpec:eU(ri),partial:eU(rW),issues:i.O31(te).pipe(i.fXn)},{identifier:void 0}){}let r2=i.gPz([r0,r1]),r5=i.xCb(["read","readManifest","write"]);class r3 extends i.rNF()("CodeModeArtifactStorageError",{cause:i.kld(),message:i.QfV,operation:r5}){}class r6 extends a.kl()("@sketchi/diagram-agent/CodeModeArtifactStorage"){}let r8={excalidraw:"application/vnd.excalidraw+json",png:"image/png",scene:"application/vnd.sketchi.scene+json"};function r9(e){return"excalidraw"===e||"scene"===e}function r4(e){return{format:e.format,mimeType:e.mimeType,sizeBytes:e.sizeBytes}}function r7(e){return new TextEncoder().encode(JSON.stringify(e)).length}let ne=l.QZ(r6)(s.Q56(s.OH5(function(){let e=new Map,t=new Map;return{close:s.OH5(()=>{t.clear(),e.clear()}),storage:{read:s.fn("codeMode.artifacts.memory.read")(function*(e,r){return yield*s.OH5(()=>{let n=t.get(`${e}:${r}`);return n?{...n,data:structuredClone(n.data)}:null})}),readManifest:s.fn("codeMode.artifacts.memory.readManifest")(function*(t){return yield*s.OH5(()=>{let r=e.get(t);return r?structuredClone(r):null})}),write:s.fn("codeMode.artifacts.memory.write")(function*(r){var n;let i=yield*o.Ru;return yield*s.SvU({try:()=>{var n;let a,s=r.formats.map(r4),o=r.provenance?structuredClone(r.provenance):void 0,l={artifactId:r.artifactId,diagramId:r.diagramId,formats:s,...o?{provenance:o}:{},createdAt:new Date(i).toISOString()};for(let n of(e.set(r.artifactId,l),r.formats))t.set(`${r.artifactId}:${n.format}`,{...n,data:structuredClone(n.data)});let d=r.formats.map(e=>{var t;return t=r.inlineFormats,{format:e.format,mimeType:e.mimeType,...r9(e.format)&&t.includes(e.format)?{inline:e.data}:{},sizeBytes:e.sizeBytes}});return a=(n={artifactId:r.artifactId,diagramId:r.diagramId,formats:d,...r.provenance?{provenance:structuredClone(r.provenance)}:{}}).formats.find(e=>"scene"===e.format),{artifactId:n.artifactId,diagramId:n.diagramId,formats:n.formats,...n.provenance?{provenance:n.provenance}:{},...a?{preview:a}:{}}},catch:(n="write",e=>{var t;return r3.make({cause:e,message:(t="Artifact storage failed.",e instanceof Error?e.message:t),operation:n})})})})}}}),e=>e.close).pipe(s.TjK(e=>e.storage)));function nt(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."}}function nr(e){return new Map(e.map((e,t)=>[e.id,t]))}function nn(e){return{type:"text",id:`label:${e.nodeId}`,containerId:e.id,x:e.x+e.width/2,y:e.y+e.height/2,text:e.label,fontSize:14,maxWidth:Math.max(1,e.width-36)}}function ni(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function na(e,t,r){return Math.min(r,Math.max(t,e))}function ns(e,t,r=0){let n,i=(n="top"===t||"bottom"===t?e.width/2-16:e.height/2-16)>0?na(r,-n,n):0,a=ni(e),s=e.width/2,o=e.height/2;if("diamond"===e.shape&&s>0&&o>0){if("top"===t||"bottom"===t){let e=a.x+i,r=o*(1-Math.abs(i)/s);return{x:e,y:"top"===t?a.y-r:a.y+r}}let e=a.y+i,r=s*(1-Math.abs(i)/o);return{x:"left"===t?a.x-r:a.x+r,y:e}}if(("ellipse"===e.shape||"circle"===e.shape)&&s>0&&o>0){if("top"===t||"bottom"===t){let e=a.x+i,r=o*Math.sqrt(Math.max(0,1-(i/s)**2));return{x:e,y:"top"===t?a.y-r:a.y+r}}let e=a.y+i,r=s*Math.sqrt(Math.max(0,1-(i/o)**2));return{x:"left"===t?a.x-r:a.x+r,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 no(e){return`${e.edgeId}:${e.endpoint}`}function nl(e){let t=[];for(let r of e){let e=t[t.length-1];e&&e.x===r.x&&e.y===r.y||t.push(r)}let r=t[0];return r?[r,...t.slice(1)]:[{x:0,y:0}]}function nd(e,t,r){let n=0;for(let i of eb(e))for(let e of t)!r.has(e.nodeId)&&ex(i,e)&&(n+=1);return n}function nc(e){return eb(e.points).map(t=>({...t,arrowId:e.arrowId,startBindingId:e.sourceNodeId,endBindingId:e.targetNodeId}))}function nu(e,t,r){let n=nc({arrowId:`edge:${r.edge.id}`,points:e,sourceNodeId:r.edge.source,targetNodeId:r.edge.target}),i=t.flatMap(e=>nc({arrowId:e.id,points:e.points,sourceNodeId:e.sourceNodeId,targetNodeId:e.targetNodeId})),a=0;for(let e of n)for(let t of i)!(e.arrowId===t.arrowId||ew(e,t))&&e_(e,t)&&(a+=1);return a}function nf(e,t){let r=nc({arrowId:`edge:${t.edge.id}`,points:e,sourceNodeId:t.edge.source,targetNodeId:t.edge.target}),n=0;for(let e=0;e<r.length;e+=1){let t=r[e];if(t)for(let i=e+1;i<r.length;i+=1){let e=r[i];e&&e_(t,e)&&(n+=1)}}return n}function np(e,t,r){switch(r){case"top":return t.y<e.y;case"right":return t.x>e.x;case"bottom":return t.y>e.y;case"left":return t.x<e.x}}function nh(e,t,r){switch(t){case"top":return{x:e.x,y:e.y-r};case"right":return{x:e.x+r,y:e.y};case"bottom":return{x:e.x,y:e.y+r};case"left":return{x:e.x-r,y:e.y}}}function nm(e,t,r,n,i){let a=Math.abs(r.x-t.x)>=Math.abs(r.y-t.y),s=new Set([e.source.nodeId,e.target.nodeId]),o=Math.min(...n.map(e=>e.x)),l=Math.max(...n.map(e=>e.x+e.width)),d=Math.min(...n.map(e=>e.y)),c=Math.max(...n.map(e=>e.y+e.height)),u="left"===e.sourceEdge||"left"===e.targetEdge||ni(e.target).x<ni(e.source).x,f="top"===e.sourceEdge||"top"===e.targetEdge||ni(e.source).y<=ni(e.target).y,p=18*e.index,h=o-56-p,m=l+56+p,g=d-48-p,y=c+48+p,v=e.index%4*18/2,b=Math.min(e.source.x,e.target.x)-56-v,_=Math.max(e.source.x+e.source.width,e.target.x+e.target.width)+56+v,x=Math.min(e.source.y,e.target.y)-48-v,w=Math.max(e.source.y+e.source.height,e.target.y+e.target.height)+48+v,k=[0,36+e.index%4*18],S=(n,i)=>{let a=i>0?nh(t,e.sourceEdge,i):t,s=i>0?nh(r,e.targetEdge,i):r;return nl([t,a,{x:n,y:a.y},{x:n,y:s.y},s,r])},I=(n,i)=>{let a=i>0?nh(t,e.sourceEdge,i):t,s=i>0?nh(r,e.targetEdge,i):r;return nl([t,a,{x:a.x,y:n},{x:s.x,y:n},s,r])},$=[[f?x:w,I],[f?w:x,I],[f?g:y,I],[f?y:g,I]],E=[[u?b:_,S],[u?_:b,S],[u?h:m,S],[u?m:h,S]],[O,C]=a?[$,E]:[E,$];return function(e,t,r,n,i){let a=e[0];if(!a)return[{x:0,y:0}];let s=e=>{let a,s,o,l,d;return[nd(e,t,r),nf(e,n),nu(e,i,n),-(a=e[0],s=e[1],o=e[e.length-1],l=e[e.length-2],d=0,s&&np(a,s,n.sourceEdge)&&(d+=1),l&&o&&np(o,l,n.targetEdge)&&(d+=1),d),function(e){let t=e[0],r=e[e.length-1];if(!t||!r)return 0;let n=e.map(e=>e.x),i=e.map(e=>e.y),a=0;return r.x<t.x?a+=Math.max(0,Math.max(...n)-t.x):r.x>t.x&&(a+=Math.max(0,t.x-Math.min(...n))),r.y<t.y?a+=Math.max(0,Math.max(...i)-t.y):r.y>t.y&&(a+=Math.max(0,t.y-Math.min(...i))),a}(e),function(e){let t=e[0],r=e[e.length-1];if(!t||!r)return 0;let n=e.map(e=>e.x),i=e.map(e=>e.y),a=0;return r.x<t.x?a+=Math.max(0,r.x-Math.min(...n)):r.x>t.x&&(a+=Math.max(0,Math.max(...n)-r.x)),r.y<t.y?a+=Math.max(0,r.y-Math.min(...i)):r.y>t.y&&(a+=Math.max(0,Math.max(...i)-r.y)),a}(e),function(e){let t=0;for(let r=0;r<e.length-1;r+=1){let n=e[r],i=e[r+1];n&&i&&(t+=Math.abs(i.x-n.x)+Math.abs(i.y-n.y))}return t}(e)]},o=(e,t)=>{for(let r=0;r<e.length;r+=1){let n=(e[r]??0)-(t[r]??0);if(0!==n)return n<0}return!1},l=a,d=s(a);for(let t of e.slice(1)){let e=s(t);o(e,d)&&(l=t,d=e)}return l}([...O.slice(0,2),...C.slice(0,2),...O.slice(2),...C.slice(2)].flatMap(([e,t])=>k.map(r=>t(e,r))),n,s,e,i)}function ng(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,r=e.text.split("\n").length*e.fontSize*1.35/2;return[{x:e.x-t,y:e.y-r},{x:e.x+t,y:e.y+r}]}return[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]})}function ny(e,t,r){return{x:e.x+t,y:e.y+r}}function nv(e){var t;let r,n,i,a,s,o=C(e),l=function(e){let t="TB"===e.layout.direction||"BT"===e.layout.direction,r=new Map(e.nodes.map(e=>[e.id,function(e){let t,r,n,i,a=(r=(t=es(e.label,1116)).split("\n"),n=Math.ceil(ei(t,14)+36),{text:t,width:n,height:Math.ceil(14*r.length*1.35+28)}),s="start"===(i=e.kind?.toLowerCase())||"end"===i?"ellipse":"decision"===i?"diamond":"rectangle";return{type:"node",id:`node:${e.id}`,nodeId:e.id,...e.kind?{kind:e.kind}:{},shape:s,x:0,y:0,width:Math.max(184,a.width+("diamond"===s?32:20*("ellipse"===s))),height:Math.max(72,a.height+32*("diamond"===s)),label:a.text}}(e)])),n=function(e){let t=new Map,r=new Map;for(let n of e)t.set(n.target,[...t.get(n.target)??[],n]),r.set(n.source,[...r.get(n.source)??[],n]);return{incoming:t,outgoing:r}}(e.edges),i=function(e,t,r){let n=new Map,i=new Set;function a(e){for(let t of(n.set(e,"visiting"),r.get(e)??[])){let e=n.get(t.target);if("visiting"===e){i.add(t.id);continue}e||a(t.target)}n.set(e,"visited")}let s=e.nodes.find(e=>0===(t.get(e.id)??[]).length)??e.nodes[0];for(let t of(s&&a(s.id),e.nodes))n.has(t.id)||a(t.id);return i}(e,n.incoming,n.outgoing),a=function(e,t,r){let n=nr(e.nodes),i=new Map(e.nodes.map(e=>[e.id,0])),a=new Map(e.nodes.map(e=>[e.id,0]));for(let t of e.edges)r.has(t.id)||i.set(t.target,(i.get(t.target)??0)+1);let s=[];for(let t of e.nodes)(i.get(t.id)??0)===0&&s.push(t.id);let o=new Set;for(let e=0;e<s.length;e+=1){let l=s[e];if(!l||o.has(l))continue;o.add(l);let d=a.get(l)??0;for(let o of t.outgoing.get(l)??[]){if(r.has(o.id))continue;a.set(o.target,Math.max(a.get(o.target)??0,d+1));let t=(i.get(o.target)??0)-1;i.set(o.target,t),0===t&&function(e,t,r,n){let i=r.get(t)??Number.MAX_SAFE_INTEGER,a=e.findIndex((e,t)=>t>n&&(r.get(e)??Number.MAX_SAFE_INTEGER)>i);-1===a?e.push(t):e.splice(a,0,t)}(s,o.target,n,e)}}for(let n of e.nodes)!function e(n){if(o.has(n))return a.get(n)??0;let i=0;for(let a of t.incoming.get(n)??[])r.has(a.id)||(i=Math.max(i,e(a.source)+1));return o.add(n),a.set(n,i),i}(n.id);return a}(e,n,i),s=Array.from((function(e,t,r,n,i){let a=nr(e.nodes),s=new Map;for(let n of e.nodes){let e=r.get(n.id)??0,i=t.get(n.id);i&&s.set(e,[...s.get(e)??[],i])}for(let e=0;e<4;e+=1)for(let e of Array.from(s.keys()).sort((e,t)=>e-t)){let t=s.get(e);if(!t||t.length<2)continue;let r=new Map;(s.get(e-1)??[]).forEach((e,t)=>{r.set(e.nodeId,t)});let o=new Map;(s.get(e+1)??[]).forEach((e,t)=>{o.set(e.nodeId,t)});let l=e=>{let t=[...(n.incoming.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>r.get(e.source)).filter(e=>void 0!==e),...(n.outgoing.get(e.nodeId)??[]).filter(e=>!i.has(e.id)).map(e=>o.get(e.target)).filter(e=>void 0!==e)];return 0===t.length?a.get(e.nodeId)??Number.MAX_SAFE_INTEGER:t.reduce((e,t)=>e+t,0)/t.length};s.set(e,[...t].sort((e,t)=>{let r=l(e)-l(t);return Math.abs(r)>.001?r:(a.get(e.nodeId)??Number.MAX_SAFE_INTEGER)-(a.get(t.nodeId)??Number.MAX_SAFE_INTEGER)}))}return s})(e,r,a,n,i).entries()).sort(([e],[t])=>e-t).map(([e,r])=>({breadth:r.reduce((e,r,n)=>e+(t?r.width:r.height)+112*(n>0),0),depth:Math.max(...r.map(e=>t?e.height:e.width)),rank:e,shapes:r})),o=Math.max(...s.map(e=>e.breadth)),l=48,d=[];for(let e of s){let r=48+Math.max(0,o-e.breadth)/2;for(let n of e.shapes)t?(d.push({...n,x:r,y:l+Math.max(0,e.depth-n.height)/2}),r+=n.width+112):(d.push({...n,x:l+Math.max(0,e.depth-n.width)/2,y:r}),r+=n.height+112);l+=e.depth+96}if("BT"===e.layout.direction){let e=Math.max(...d.map(e=>e.y+e.height));return d.map(t=>({...t,y:48+e-t.y-t.height}))}if("RL"===e.layout.direction){let e=Math.max(...d.map(e=>e.x+e.width));return d.map(t=>({...t,x:48+e-t.x-t.width}))}return d}(o),d=new Map(l.map(e=>[e.nodeId,e])),c=o.edges.map((e,t)=>(function(e,t,r,n){let i=r.get(e.source),a=r.get(e.target);if(!i||!a)throw Error(`Cannot render edge "${e.id}" with unresolved nodes.`);let{sourceEdge:s,targetEdge:o}=function(e,t,r){let n=ni(e),i=ni(t),a=i.x-n.x,s=i.y-n.y,o=e.kind?.toLowerCase();if("LR"===r||"RL"===r)return a>=0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"};if(s<0)return!(Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)>.01)&&Math.abs(a)>Math.abs(s)?{sourceEdge:a>0?"right":"left",targetEdge:"bottom"}:{sourceEdge:"top",targetEdge:"bottom"};let l="decision"===o&&s>e.height+96;return"decision"===o&&s>0&&(0!==a||l)?{sourceEdge:a<0?"left":"right",targetEdge:"top"}:s>0?{sourceEdge:"bottom",targetEdge:"top"}:Math.abs(a)>Math.abs(s)?a>0?{sourceEdge:"right",targetEdge:"left"}:{sourceEdge:"left",targetEdge:"right"}:{sourceEdge:"top",targetEdge:"bottom"}}(i,a,n);return{edge:e,index:t,source:i,sourceEdge:s,target:a,targetEdge:o}})(e,t,d,o.layout.direction)),u=function(e){let t=new Map;for(let s of e){var r,n,i,a;let e=(r=s.source.nodeId,n=s.sourceEdge,`${r}:${n}`),o=(i=s.target.nodeId,a=s.targetEdge,`${i}:${a}`);t.set(e,[...t.get(e)??[],{edgeId:s.edge.id,endpoint:"source"}]),t.set(o,[...t.get(o)??[],{edgeId:s.edge.id,endpoint:"target"}])}let s=new Map;for(let e of t.values())e.forEach((t,r)=>{s.set(no(t),(r-(e.length-1)/2)*18)});return s}(c),f=[];for(let e of c)f.push(function(e,t,r,n,i,a){let{edge:s,source:o,sourceEdge:l,target:d,targetEdge:c}=e,u=ns(o,l,r.get(no({edgeId:s.id,endpoint:"source"}))??0),f=ns(d,c,r.get(no({edgeId:s.id,endpoint:"target"}))??0),p=nl([u,f]);if(function(e,t,r){let n=ni(e),i=ni(t);switch(r){case"TB":return i.y<n.y;case"BT":return i.y>n.y;case"LR":return i.x<n.x;case"RL":return i.x>n.x}}(o,d,a))p=nm(e,u,f,n,i);else if("orthogonal"===t&&u.x!==f.x&&u.y!==f.y){var h,m,g;let t,r,n,i=e.index%4*18,a=(h=u.y,m=f.y,g=f.y<u.y?-i:i,t=h+(m-h)/2,(r=Math.min(h,m)+18)<(n=Math.max(h,m)-18)?na(t+g,r,n):t),s="left"===l?{x:u.x-36-i,y:u.y}:"right"===l?{x:u.x+36+i,y:u.y}:u,o="left"===c?{x:f.x-36-i,y:f.y}:"right"===c?{x:f.x+36+i,y:f.y}:f;p=nl([u,s,{x:s.x,y:a},{x:o.x,y:a},o,f])}return"orthogonal"===t&&(nd(p,n,new Set([o.nodeId,d.nodeId]))>0||nf(p,e)>0||nu(p,i,e)>0)&&(p=nm(e,u,f,n,i)),{type:"arrow",id:`edge:${s.id}`,edgeId:s.id,sourceNodeId:s.source,targetNodeId:s.target,points:p,...s.label?{label:s.label}:{}}}(e,o.layout.edgeRouting,u,l,f,o.layout.direction));let p=l.map(nn),h=(i=Math.max(0,48-(n={x:Math.min(...(r=ng(t=[...f,...l,...p])).map(e=>e.x)),y:Math.min(...r.map(e=>e.y))}).x),a=Math.max(0,48-n.y),0===i&&0===a?[...t]:t.map(e=>"arrow"===e.type?{...e,points:function(e,t,r){let[n,...i]=e;return[ny(n,t,r),...i.map(e=>ny(e,t,r))]}(e.points,i,a)}:"line"===e.type?{...e,points:function(e,t,r){let[n,i,...a]=e;return[ny(n,t,r),ny(i,t,r),...a.map(e=>ny(e,t,r))]}(e.points,i,a)}:{...e,x:e.x+i,y:e.y+a})),m={width:Math.max(...(s=ng(h)).map(e=>e.x))+48,height:Math.max(...s.map(e=>e.y))+48},g=[...l.map(e=>e.id),...p.map(e=>e.id),...f.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:o.id,title:o.title,width:m.width,height:m.height,accentColor:o.style.accentColor,backgroundColor:o.style.backgroundColor,elements:h,layers:[],layouts:[],zOrder:g}}let nb="sequence-lifeline";function n_(e){return`${e}:lifeline`}let nx="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",nw=nx.slice(10),nk=new Map;function nS(e){let t=nk.get(e);if(void 0===t){t=new Uint8Array(256);for(let r=0;r<e.length;r++)t[e.charCodeAt(r)]=r;nk.set(e,t)}return t}function nI(e,t,r,n){let i=r[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 a=0;for(;(e[a]||i)===t[a];)a++;if(a>0)return t.slice(0,a)+nI(e.slice(a),t.slice(a),r,n)}let a=e?n[e.charCodeAt(0)]:0,s=null!=t?n[t.charCodeAt(0)]:r.length;return s-a>1?r[Math.round(.5*(a+s))]:t&&t.length>1?t.slice(0,1):r[a]+nI(e.slice(1),null,r,n)}function n$(e,t,r){if(e.length!==nE(e[0],t,r))throw Error("invalid integer part of order key: "+e)}function nE(e,t,r){let n=r[e.charCodeAt(0)];if(t[n]===e){let e=t.length/2;return n<e?e-n+1:n-e+2}throw Error("invalid order key head: "+e)}function nO(e,t,r){let n=nE(e[0],t,r);if(n>e.length)throw Error("invalid order key: "+e);return e.slice(0,n)}function nC(e,t,r,n){if(nA(e,t,r))throw Error("invalid order key: "+e);let i=nO(e,r,n);if(e.slice(i.length).slice(-1)===t[0])throw Error("invalid order key: "+e)}function nT(e,t,r,n,i){n$(e,n,i);let a=e[0],s=t[0],o="";for(let n=e.length-1;n>=1;n--){let i=r[e.charCodeAt(n)]+1;if(i!==t.length)return a+e.slice(1,n)+t[i]+o;o=s+o}let l=i[a.charCodeAt(0)];if(l===n.length-1)return null;let d=n[l+1],c=nE(d,n,i)-nE(a,n,i);return d+(c>0?o+s:c<0?o.slice(1):o)}let nM=new Map;function nA(e,t,r){let n=nM.get(r);void 0===n&&(n=new Map,nM.set(r,n));let i=t.charCodeAt(0),a=n.get(i);return void 0===a&&(a=r[0]+t[0].repeat(r.length/2),n.set(i,a)),e===a}function nN(e){for(let t=1;t<e.length;t++)if(e.charCodeAt(t-1)>=e.charCodeAt(t))return!1;return!0}function nP(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}let nR=new Set,nj=new Set,nD=new Set(["rectangle","ellipse","diamond"]),nU=h.ink;function nF(e){return"number"==typeof e&&Number.isFinite(e)?e:null}function nB(e){if(!Array.isArray(e)||e.length<2)return null;let t=nF(e[0]),r=nF(e[1]);return null===t||null===r?null:[t,r]}function nL(e){let t=nF(e.x),r=nF(e.y),n=nF(e.width),i=nF(e.height);return null===t||null===r||null===n||null===i?null:{x:t,y:r,width:n,height:i}}function nz(e){return 1e-4>Math.abs(e-.5)?.5001:e}function nW(e,t){let r=nL(e);return r&&0!==r.width&&0!==r.height?[nz((t.x-r.x)/r.width),nz((t.y-r.y)/r.height)]:null}function nJ(e,t){return{elementId:e?.id??"",focus:0,gap:0,fixedPoint:e?nW(e,t):null}}function nY(e,t){let r=function(e,t,r="characters"){let n=0x811c9dc5;for(let t=0;t<e.length;t+=1)n^=e.charCodeAt(t),n=Math.imul(n,0x1000193),"characters"===r&&(e.codePointAt(t)??0)>65535&&(t+=1);return"seed"===t?Math.abs(n)||1:(n>>>0).toString(16).padStart(8,"0")}(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:r,strokeStyle:t&&"strokeStyle"in t?t.strokeStyle??"solid":"solid",strokeWidth:t&&"strokeWidth"in t?t.strokeWidth??2:2,updated:1,version:1,versionNonce:r+1}}function nX(e){var t;let r=e.wrap?eo(e.text,e.maxWidth,e.fontSize):e.text,n=ea(r,e.fontSize,e.maxWidth),i=(t=e.fontSize,Math.ceil(r.split("\n").length*t*1.35));return{...nY(e.id,e.element),...void 0===e.locked?{}:{locked:e.locked},type:"text",x:e.x-n/2,y:e.y-i/2,width:n,height:i,backgroundColor:"transparent",boundElements:null,containerId:e.containerId??null,fontFamily:e.element?.fontFamily==="mono"?3:e.element?.fontFamily==="sans"?2:5,fontSize:e.fontSize,lineHeight:1.35,originalText:e.text,roundness:null,strokeColor:e.textColor??nU,text:r,textAlign:e.element?.textAlign??"center",verticalAlign:e.element?.verticalAlign??"middle",autoResize:!(e.wrap&&!e.containerId)}}function nq(e){return e.points[e.points.length-1]??e.points[0]}function nG(e,t,r){if(!e)return null;let n=t.get(e.elementId);return n?{elementId:e.elementId,focus:e.focus??0,gap:e.gap??0,fixedPoint:nW(n,r)}:null}function nV(e){return"node"===e.type}function nH(e){return"text"===e.type}function nK(e){return"arrow"===e.type}function nQ(e){return"line"===e.type}function nZ(e){return"frame"===e.type}function n0(e,t){let r=e[t];if(!(r&&"object"==typeof r))return null;let n=r.elementId;return"string"==typeof n?n:null}function n1(e){let t=nF(e.x)??0,r=nF(e.y)??0,n=n0(e,"startBinding"),i=n0(e,"endBinding");return eb(Array.isArray(e.points)?e.points.map(nB).filter(e=>null!==e).map(([e,n])=>({x:t+e,y:r+n})):[]).map(t=>({...t,arrowId:e.id,startBindingId:n,endBindingId:i}))}function n2(e){if(nD.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 n5(e,t,r){return e>=t-.01&&e<=r+.01}function n3(e,t){return .01>=Math.abs(e-t)}var n6=r(664);r(3614);var n8=r(1594),n9=r(6297),n4=r(7258),n7=r(2275),ie=r(2860),it=r(1554),ir=r(4233);let ii=a.Or("effect/Metric/CurrentMetricAttributes",{defaultValue:()=>({})}),ia=a.Or("effect/Metric/MetricRegistry",{defaultValue:()=>new Map}),is="~effect/Metric";class io{[is]=is;#e;#t="";id;description;attributes;constructor(e,t,r){this.id=e,this.description=t,this.attributes=r}valueUnsafe(e){return this.hook(e).get(e)}modifyUnsafe(e,t){return this.hook(t).modify(e,t)}updateUnsafe(e,t){return this.hook(t).update(e,t)}hook(e){var t;let r,n=a.Jt(e,ii);n!==this.#e&&(this.#e=n,this.#t=(t=this,r=Object.entries(ig(this.attributes,n)).sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0])),JSON.stringify([t.type,t.id,t.description,r])));let i=a.Jt(e,ia),s=i.get(this.#t);return ir.b0(s)&&(s={id:this.id,type:this.type,description:this.description,attributes:Object.keys(n).length>0?ig(this.attributes,n):this.attributes,hooks:this.createHooks()},i.set(this.#t,s)),s.hooks}pipe(){return(0,it.tT)(this,arguments)}}let il=BigInt(0);class id extends io{type="Counter";#r;#n;constructor(e,t){super(e,t?.description,iy(t?.attributes)),this.#r=t?.bigint??!1,this.#n=t?.incremental??!1}createHooks(){let e=this.#r?il:0,t=this.#n?this.#r?e=>e>=il:e=>e>=0:e=>!0;return im(()=>({count:e,incremental:this.#n}),r=>{t(r)&&(e+=r)})}}class ic extends io{type;metric;valueUnsafe;updateUnsafe;modifyUnsafe;constructor(e,t,r,n){super(e.id,e.description,e.attributes),this.metric=e,this.valueUnsafe=t,this.updateUnsafe=r,this.modifyUnsafe=n,this.type=e.type}createHooks(){return this.metric.createHooks()}}let iu=(e,t)=>new id(e,t),ip=(0,n8.XY)(2,(e,t)=>n9.sxi(r=>n9.OH5(()=>e.updateUnsafe(t,r)))),ih=(0,n8.XY)(2,(e,t)=>{var r;let n,i,s=(r=t,i={},e=>{let t=a.Jt(e,ii);return t!==n&&(n=t,i=ig(t,r)),a.WQ(e,ii,i)});return new ic(e,t=>e.valueUnsafe(s(t)),(t,r)=>e.updateUnsafe(t,s(r)),(t,r)=>e.modifyUnsafe(t,s(r)))});function im(e,t,r){return{get:e,update:t,modify:r??t}}function ig(e,t){return{...iy(e),...iy(t)}}function iy(e){return ir.EA(e)&&Array.isArray(e)?e.reduce((e,[t,r])=>(n7.x(e,t,r),e),{}):e}n4.F,n4.F,n8.MN;var iv=r(1587),ib=(r(6526),r(719),r(2707));let i_=[["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"]],ix=new Set(["artifact_count","artifact_format","artifact_kind","attempt","cache_mode","duration_ms","error_category","error_tag","failure_category","format_count","method","model","operation","outcome","provider","request_kind","retry_kind","sink","status","status_code","surface","timeout_kind","timeout_ms"]),iw=([...i_.map(([,e])=>e),...ix],{metric:()=>void 0}),ik=a.Or("@sketchi/observability/TelemetryExporter",{defaultValue:()=>iw}),iS=a.Or("@sketchi/observability/TelemetryCorrelation",{defaultValue:()=>({})});function iI(e){let t=e?.trim();if(t&&!(t.length>128)&&/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(t))return t}function i$(e,t){return s.JkU(function*(){let r={...yield*iS,...function(e){let t={};for(let[r]of i_){let n=iI(e[r]);n&&(t[r]=n)}return t}(t)},n=function(e){let t={};for(let[r,n]of i_){let i=e[r];i&&(t[n]=i)}return t}(r);return yield*e.pipe(s.PfK(iS,r),s.Muk(n),s.swY(n))})}a.Or("@sketchi/observability/TelemetryResource",{defaultValue:()=>({serviceName:"sketchi"})});let iE=s.fn(function*(e,t,r={}){let n=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},r={};for(let[e,n]of Object.entries(t)){let t=iI(n);t&&(r[e]=t)}return r}(r);yield*ip(ih(e,n),t);let i=yield*ik,a=iv.getOrUndefined((yield*s._32.pipe(s.uKv)));yield*s.OH5(()=>i.metric({attributes:n,metric:e.id,metricType:e.type,...a?{spanId:a.spanId,traceId:a.traceId}:{},value:t}))});ib.W1;var iO=r(9315);let iC=/^(node|step|item|box|thing|process|task)\s*\d*$/i,iT=/^(diagram|untitled|flowchart|chart|sketch)$/i;function iM(e){return e.map(e=>({kind:"node",id:e.id}))}function iA(e){if(void 0===e)return;let t=eS(e);return t.length>0?t:void 0}let iN=["excalidraw","scene"],iP=["scene"];h.card,h.accent,h.ink;let iR=iu("sketchi_codemode_requests",{description:"Code Mode boundary requests by terminal outcome",incremental:!0}),ij=iu("sketchi_codemode_failures",{description:"Code Mode boundary failures by typed status",incremental:!0}),iD=iu("sketchi_codemode_artifacts",{description:"Code Mode artifacts accepted at workflow boundaries",incremental:!0}),iU=new class e extends io{type="Histogram";#i;constructor(e,t){super(e,t?.description,iy(t?.attributes)),this.#i=t.boundaries}createHooks(){let e=this.#i,t=e.length,r=new Uint32Array(t+1),n=new Float64Array(t),i=0,a=0,s=Number.MAX_VALUE,o=-Number.MAX_VALUE;return n6.Tj(n6.di(e,ie.wN),(e,t)=>{n[t]=e}),im(()=>({buckets:(()=>{let e=n6.CN(t),i=0;for(let a=0;a<t;a++){let t=n[a];i+=r[a],e[a]=[t,i]}return e})(),count:i,min:s,max:o,sum:a}),e=>{let l=0,d=t;for(;l!==d;){let t=Math.floor(l+(d-l)/2);e<=n[t]?d=t:l=t,d===l+1&&(e<=n[l]?d=l:l=d)}r[l]=r[l]+1,i+=1,a+=e,e<s&&(s=e),e>o&&(o=e)})}}("sketchi_codemode_duration_ms",{description:"Code Mode boundary duration in milliseconds",boundaries:(n=[1,5,10,25,50,100,250,500,1e3,2500,5e3,1e4],n6.BC(n6.pb(new Set(n),e=>e>0),1/0))});class iF extends a.kl()("@sketchi/diagram-agent/CodeModeRuntimeEnvironment"){}function iB(e={}){return l.Py(iF,{createId:e.createId??i0,...e.renderer?{renderer:e.renderer}:{},...e.artifactUrl?{artifactUrl:e.artifactUrl}:{}})}function iL(e){return null===e||"object"!=typeof e||Array.isArray(e)?void 0:Object.fromEntries(Object.entries(e))}l.Py(iF,{createId:i0});class iz extends i.rNF()("CodeModeArtifactRenderFailed",{cause:i.kld(),message:i.QfV}){}class iW extends i.rNF()("CodeModeArtifactRendererNotConfigured",{message:i.QfV}){}let iJ=i._kM({issues:i.O31(i.O3D(te)).pipe(i.fXn)});class iY extends i.rNF()("ArtifactExportFailure",{status:i.uSQ("export_failed"),issues:iJ.fields.issues}){}class iX extends i.rNF()("ArtifactStorageFailure",{status:i.uSQ("storage_failed"),cause:i.kld(),issues:iJ.fields.issues}){}function iq(e,t,r){class n extends i.rNF()(e,{message:i.QfV,status:t,context:r}){constructor(e){super({...e,message:e.context.issues[0]?.message??e.status},{disableChecks:!0})}}return n}let iG=iq("BuildFlowchartFailure",rY.fields.status,rY.mapFields(({ok:e,status:t,...r})=>({...r,...iJ.fields}))),iV=iq("BuildMindmapFailure",rq.fields.status,rq.mapFields(({ok:e,status:t,...r})=>({...r,...iJ.fields}))),iH=iq("BuildSequenceDiagramFailure",rV.fields.status,rV.mapFields(({ok:e,status:t,...r})=>({...r,...iJ.fields}))),iK=iq("CreateCanvasFailure",r1.fields.status,r1.mapFields(({ok:e,status:t,...r})=>({...r,...iJ.fields}))),iQ=iq("GetArtifactFailure",rK.fields.status,rK.mapFields(({ok:e,status:t,...r})=>({...r,...iJ.fields}))),iZ=iq("ApplyDiagramPatchFailure",rZ.fields.status,rZ.mapFields(({ok:e,status:t,...r})=>({...r,...iJ.fields})));function i0(e){return`${e}_${globalThis.crypto.randomUUID()}`}function i1(e){return{code:e.code,severity:e.severity??"error",stage:e.stage,...e.ref?{ref:e.ref}:{},message:e.message,hint:e.hint}}function i2(e){return 0===e.length?"input":e.map(e=>"number"==typeof e?`[${e}]`:String(e)).join(".")}function i5(e){let t=i2(e.path);return i3(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 i3(e){return/^operations\.\[\d+\]\.op$/.test(e)}function i6(e){let t=e.issues.slice(0,20).map(e=>{let t=i2(e.path);return i1({code:i5(e),stage:"input",ref:{kind:"request",path:t},message:e.message,hint:i3(t)?`Use one of: ${tn.join(", ")}. For label edits, use replaceText with selector plus text.`:"source"===t?"Pass source: { artifactId } from an accepted build or patch, or source: { scene } for inline Sketchi scene patching.":`Fix ${t} so it matches the Code Mode API contract.`})});return e.issues.length>20&&t.push(i1({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."})),t}function i8(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)}function i9(e){if(void 0===e)return;let t=eS(e);return t.length>0?t:void 0}function i4(e){return e.checks.map(e=>{var t;return i1({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 i7(e){return e?.artifactFormats??iN}function ae(e){return e?.inlineArtifacts??iP}let at=s.fn("codeMode.artifacts.exportFormats")(function*(e){let t=[];for(let a of e.formats){var r,n,i;let o=yield*(r=e,"scene"===(n=a)?s.PyW(r.scene):"excalidraw"===n?s.PyW(function(e,t={}){return{type:"excalidraw",version:2,source:t.source??"https://sketchi.app",elements:e.elements,appState:e.appState,files:{}}}(r.excalidraw)):r.renderer?r.renderer.renderPng({scene:r.scene,excalidraw:r.excalidraw}).pipe(s.xm_(e=>iz.make({cause:e,message:e.message}))):s.fJG(iW.make({message:"PNG artifact rendering is not configured for this runtime."})));t.push({format:a,mimeType:r8[a],data:o,sizeBytes:(i=o)instanceof ArrayBuffer||i instanceof Uint8Array?i.byteLength:r7(i)})}return t});function ar(e){return e.map(e=>i1({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 an(e){return e.slice(0,20).map(e=>i1({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_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 ai(e){return ar(e.filter(e=>"overlapping-arrow-segment"!==e.code&&"arrow-segment-through-node"!==e.code))}function aa(e){let t=[];for(let r of e.elements){if("arrow"===r.type){let e=r.points[0],n=r.points[1],i=r.points.slice(2);if(!e||!n)return null;let a=[e,n,...i];t.push({...r,type:"arrow",id:r.id,edgeId:r.edgeId,sourceNodeId:r.sourceNodeId,targetNodeId:r.targetNodeId,...r.strokeColor?{strokeColor:r.strokeColor}:{},...r.strokeStyle?{strokeStyle:r.strokeStyle}:{},...r.textColor?{textColor:r.textColor}:{},points:a,...r.label?{label:r.label}:{}});continue}if("node"===r.type){let n=r.points;if("polygon"===r.shape&&(!n||!n[0]||!n[1]||!n[2]))return null;t.push({type:"node",id:r.id,nodeId:r.nodeId,...r.kind?{kind:r.kind}:{},shape:r.shape,...r.fillColor?{fillColor:r.fillColor}:{},...r.strokeColor?{strokeColor:r.strokeColor}:{},x:r.x,y:r.y,width:r.width,height:r.height,label:r.label,...r.frameId?{frameId:r.frameId}:{},...r.groupIds?{groupIds:[...r.groupIds]}:{},...r.layerId?{layerId:r.layerId}:{},...void 0!==r.locked?{locked:r.locked}:{},...void 0!==r.opacity?{opacity:r.opacity}:{},...void 0!==r.zIndex?{zIndex:r.zIndex}:{},...r.fillStyle?{fillStyle:r.fillStyle}:{},...void 0!==r.roughness?{roughness:r.roughness}:{},...r.strokeStyle?{strokeStyle:r.strokeStyle}:{},...void 0!==r.strokeWidth?{strokeWidth:r.strokeWidth}:{},..."sequence-lifeline"===r.rendererRole&&function(e,t){let r=":lifeline";if(!t.nodeId.endsWith(r)||t.id!==`node:${t.nodeId}`||"rectangle"!==t.shape||2!==t.width||t.height<120)return!1;let n=t.nodeId.slice(0,-r.length);if(0===n.length)return!1;let i=e.elements.find(e=>"node"===e.type&&e.id===`node:${n}`&&e.nodeId===n);return!!i&&.01>=Math.abs(t.x+t.width/2-(i.x+i.width/2))&&t.y>=i.y+i.height-.01}(e,r)?{rendererRole:r.rendererRole}:{},...r.textColor?{textColor:r.textColor}:{},..."polygon"===r.shape&&n?.[0]&&n[1]&&n[2]?{points:[n[0],n[1],n[2],...n.slice(3)]}:{}});continue}if("line"===r.type){let e=r.points[0],n=r.points[1];if(!e||!n)return null;t.push({...r,points:[e,n,...r.points.slice(2)]});continue}t.push(structuredClone(r))}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 as(e){return structuredClone(e)}function ao(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 al(e){return e.elements.filter(e=>"node"===e.type)}function ad(e){return e.elements.filter(e=>"text"===e.type)}function ac(e){return e.elements.filter(e=>"arrow"===e.type)}function au(e,t){if(!e||0===e.length||!t)return!1;let r=t.trim().toLowerCase();return e.some(e=>e.trim().toLowerCase()===r)}function af(e,t){let r=t?.scope??"all",n=!!(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??[]),a=new Set(t?.nodeIds??[]),s=new Set(t?.edgeIds??[]),o=new Set(t?.kinds??[]),l=al(e).filter(e=>"edges"!==r&&(!t||!n||i.has(e.id)||a.has(e.nodeId)||!!e.kind&&[...o].some(t=>t===e.kind)||au(t.labels,e.label))),d=ac(e).filter(e=>"nodes"!==r&&(!t||!n||i.has(e.id)||s.has(e.edgeId)||au(t.labels,e.label))),c=new Set(l.map(e=>e.id)),u=new Set(d.map(e=>e.id));return{arrows:d,nodes:l,texts:ad(e).filter(e=>t&&n?i.has(e.id)||!!e.containerId&&c.has(e.containerId)||!!e.containerId&&u.has(e.containerId)||au(t.labels,e.text):"nodes"===r?!!e.containerId&&c.has(e.containerId):"edges"!==r||!!e.containerId&&u.has(e.containerId))}}function ap(e){return i1({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 ah(e,t){return ad(e).find(e=>e.containerId===t)}function am(e,t){let r=new Set(t);for(let t of ac(e))(r.has(t.sourceNodeId)||r.has(t.targetNodeId))&&av(e,t)}function ag(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function ay(e,t,r){let n=ag(e),i=ag(t),a=i.x-n.x,s=i.y-n.y;return 0===a&&0===s?{x:n.x,y:"source"===r?e.y+e.height:e.y}:Math.abs(a)>Math.abs(s)?a>=0?{x:e.x+e.width,y:n.y}:{x:e.x,y:n.y}:s>=0?{x:n.x,y:e.y+e.height}:{x:n.x,y:e.y}}function av(e,t){let r,n,i=new Map(al(e).map(e=>[e.nodeId,e])),a=i.get(t.sourceNodeId),s=i.get(t.targetNodeId);if(!a||!s)return[i1({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."})];let o=ay(a,s,"source"),l=ay(s,a,"target");if(Math.abs(l.y-o.y)>=Math.abs(l.x-o.x)){let e=(o.y+l.y)/2;t.points=[o,{x:o.x,y:e},{x:l.x,y:e},l]}else{let e=(o.x+l.x)/2;t.points=[o,{x:e,y:o.y},{x:e,y:l.y},l]}return r=ah(e,t.id),n=function(e){let t=e[0],r=e[e.length-1];if(t&&r)return{x:(t.x+r.x)/2,y:(t.y+r.y)/2-10}}(t.points),r&&n&&(r.x=n.x,r.y=n.y),[]}function ab(e){let t=e.width,r=e.height;for(let n of e.elements)if("arrow"===n.type||"line"===n.type)for(let e of n.points)t=Math.max(t,e.x),r=Math.max(r,e.y);else"text"===n.type?(t=Math.max(t,n.x+(n.maxWidth??0)),r=Math.max(r,n.y+n.fontSize)):(t=Math.max(t,n.x+n.width),r=Math.max(r,n.y+n.height));e.width=t+48,e.height=r+48}function a_(e,t,r){if(!t||!r){if(t){let r=e.indexOf(t);return r>=0?r:void 0}if(r){let t=e.indexOf(r);return t>=0?t+1:void 0}return e.length}}function ax(e,t){return[i1({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 aw=s.fn("codeMode.patch.resolveSource")(function*(e){if("scene"in e.source)return{scene:as(e.source.scene)};let t=yield*r6,r=yield*t.readManifest(e.source.artifactId).pipe(s.xm_(e=>new iZ({status:"storage_failed",context:{issues:[nt(e.message,"storage_read_failed")]}})));if(!r||r.artifactId!==e.source.artifactId||!r.formats.some(e=>"scene"===e.format))return yield*new iZ({status:"source_unavailable",context:{issues:[i1({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 n=yield*t.read(e.source.artifactId,"scene").pipe(s.xm_(e=>new iZ({status:"storage_failed",context:{issues:[nt(e.message,"storage_read_failed")]}})));if(!n)return yield*new iZ({status:"source_unavailable",context:{issues:[i1({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 a=i.q$Z(ra,{errors:"all",reportInput:!0})(n.data);return iO.oJ(a)?{scene:as(a.success),sourceArtifactId:e.source.artifactId}:yield*new iZ({status:"source_unavailable",context:{issues:[i1({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 ak(e){return e?{requestId:e}:{}}function aS(e){return{diagramId:e.diagramId,formats:[{format:"scene",mimeType:r8.scene,inline:e,sizeBytes:r7(e)}]}}function aI(e){return{ok:!1,status:e.status,...e.context}}function a$(e,t){return nt(e.message,t)}let aE=s.fn("codeMode.artifacts.exportAndStore")(function*(e){let t=yield*iF,r=yield*r6,{excalidraw:n,validation:i}=yield*s.OH5(()=>{let t=function(e){let t,r,n,i,a,s,o,l=(t=new Map(e.layers.map(e=>[e.id,e])),n=new Set((r=e.elements.filter(e=>{let r=e.layerId?t.get(e.layerId):void 0;return r?.visible!==!1})).flatMap(e=>"node"===e.type?[e.nodeId]:[])),a=new Set((i=r.filter(e=>"arrow"!==e.type||n.has(e.sourceNodeId)&&n.has(e.targetNodeId))).flatMap(e=>"text"===e.type?[]:[e.id])),o=new Set((s=i.filter(e=>"text"!==e.type||!e.containerId||a.has(e.containerId))).map(e=>e.id)),s.map(e=>{let r=e.layerId?t.get(e.layerId):void 0,{frameId:n,...i}=e;return{...e.frameId&&!o.has(e.frameId)?i:e,...r?.locked===!0?{locked:!0}:{}}})),{textElements:d,generatedLabelSourceIds:c}=function(e){let t=e.filter(nV),r=e.filter(nH),n=new Set(e.map(e=>e.id)),i=new Map,a=new Set(r.flatMap(e=>e.containerId?[e.containerId]:[]));for(let e of t){if(a.has(e.id)||e.rendererRole===nb)continue;let t=`__sketchi_node_label__${e.id}`,s=t,o=2;for(;n.has(s);)s=`${t}:${o}`,o+=1;n.add(s),i.set(s,e.id),r.push({type:"text",id:s,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:r,generatedLabelSourceIds:i}}(l),u=function(e,t,r){let n=t.filter(nV),i=new Map;for(let e of r)e.containerId&&i.set(e.containerId,e);let a=t.filter(nK),s=t.filter(nQ),o=function(e,t,r){let n=new Map,i=new Map(e.map(e=>[e.nodeId,e.id]));for(let e of t)for(let t of[e.sourceNodeId,e.targetNodeId]){let r=i.get(t);r&&n.set(r,[...n.get(r)??[],e.id])}for(let e of r)for(let t of[e.startBinding,e.endBinding])t&&n.set(t.elementId,[...n.get(t.elementId)??[],e.id]);return n}(n,a,s),l=new Map,d=[];for(let t of n){let r=i.get(t.id),n=function(e){let t=e.shape.height,r="circle"===e.shape.shape?"ellipse":e.shape.shape,n=[...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}],[r,...n]=t;return{...nY(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"},endArrowhead:null,endBinding:null,lastCommittedPoint:null,points:[...t,r].map(e=>[e.x,e.y]),roundness:null,startArrowhead:null,startBinding:null,strokeColor:e.shape.strokeColor??e.scene.accentColor}}return{...nY(e.shape.id,e.shape),type:r,x:e.shape.x,y:e.shape.y,width:e.shape.width,height:t,backgroundColor:e.shape.fillColor??"transparent",boundElements:n.length>0?n:null,roundness:"rectangle"===r?{type:3}:null,strokeColor:e.shape.strokeColor??e.scene.accentColor,...e.shape.rendererRole===nb?{customData:{sketchiRendererRole:nb}}:{}}}({scene:e,shape:t,arrowIds:o.get(t.id)??[],...r?{text:r}:{}});l.set(t.nodeId,n),d.push(n)}for(let r of t.filter(nZ)){var c;let t={...nY((c={element:r,scene:e}).element.id,c.element),type:"frame",x:c.element.x,y:c.element.y,width:c.element.width,height:c.element.height,backgroundColor:c.element.fillColor??"transparent",boundElements:null,name:c.element.name??null,roundness:null,strokeColor:c.element.strokeColor??c.scene.accentColor},n=o.get(r.id)??[];t.boundElements=n.length?n.map(e=>({id:e,type:"arrow"})):null,d.push(t)}for(let e of r){let t=a.some(t=>t.id===e.containerId),r=e.containerId&&(n.some(t=>t.id===e.containerId&&"polygon"!==t.shape)||t);d.push(nX({element:e,id:e.id,...r?{containerId:e.containerId}:{},fontSize:e.fontSize,maxWidth:e.maxWidth??160,...e.textColor?{textColor:e.textColor}:{},text:e.text,wrap:t,x:e.x,y:e.y}))}for(let t of a){let r=i.get(t.id);d.push(function(e){let t=e.arrow.points[0],r=nq(e.arrow),n=e.arrow.points.length>2;return{...nY(e.arrow.id,e.arrow),type:"arrow",x:t.x,y:t.y,width:r.x-t.x,height:r.y-t.y,backgroundColor:"transparent",boundElements:e.text?[{id:e.text.id,type:"text"}]:e.arrow.label?[{id:`${e.arrow.id}:label`,type:"text"}]:null,elbowed:n,endArrowhead:void 0===e.arrow.endArrowhead?"arrow":e.arrow.endArrowhead,endBinding:nJ(e.targetShape,r),...n?{fixedSegments:[],startIsSpecial:null,endIsSpecial:null}:{},points:e.arrow.points.map(e=>[e.x-t.x,e.y-t.y]),roundness:n?null:{type:2},startArrowhead:e.arrow.startArrowhead??null,startBinding:nJ(e.sourceShape,t),strokeColor:e.arrow.strokeColor??e.scene.accentColor,strokeStyle:e.arrow.strokeStyle??"solid"}}({arrow:t,scene:e,sourceShape:l.get(t.sourceNodeId),targetShape:l.get(t.targetNodeId),...r?{text:r}:{}}));let n=t.label&&!r?function(e){if(!e.arrow.label)return null;let t=e.arrow.points[0],r=nq(e.arrow);return nX({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+r.x)/2,y:(t.y+r.y)/2-10})}({arrow:t}):null;n&&d.push(n)}let u=new Map(d.map(e=>[e.id,e]));for(let t of s)if(d.push(function(e){let[t,...r]=e.element.points,n=r[r.length-1]??t,i=void 0!==e.element.startArrowhead||void 0!==e.element.endArrowhead||void 0!==e.element.startBinding||void 0!==e.element.endBinding,a=i&&e.element.points.length>2;return{...nY(e.element.id,e.element),type:i?"arrow":"line",x:t.x,y:t.y,width:n.x-t.x,height:n.y-t.y,backgroundColor:e.element.fillColor??"transparent",boundElements:null,...i?{elbowed:a}:{},endArrowhead:e.element.endArrowhead??null,endBinding:nG(e.element.endBinding,e.elementsById,n),...a?{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&&!a?{type:2}:null,startArrowhead:e.element.startArrowhead??null,startBinding:nG(e.element.startBinding,e.elementsById,t),strokeColor:e.element.strokeColor??e.scene.accentColor}}({element:t,elementsById:u,scene:e})),t.label){let e=t.points[0],r=t.points[t.points.length-1]??e;d.push(nX({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+r.x)/2,y:(e.y+r.y)/2-10}))}return d}(e,l,d),f=new Map(e.zOrder.map((e,t)=>[e,t])),p=e=>{if(f.has(e.id))return e.id;let t=c.get(e.id);return t||(e.id.endsWith(":label")?e.id.slice(0,-6):e.id)};u.sort((e,t)=>(f.get(p(e))??Number.MAX_SAFE_INTEGER)-(f.get(p(t))??Number.MAX_SAFE_INTEGER));let h=null;for(let e of u){let t=function(e,t,r,n){if(void 0!==n){var i=n;if(!nj.has(i)){if(i.length<2||i.length%2!=0||!nN(i))throw Error("intDigits must be an even number of at least 2 characters in strictly ascending character code order: "+i);if(!nP(i))throw Error("intDigits must be single-byte (char code 0-255): "+i);nj.add(i)}}else n=r??nw;if(void 0!==r){var a=r;if(!nR.has(a)){if(a.length<2||!nN(a))throw Error("digits must be at least 2 characters in strictly ascending character code order: "+a);if(!nP(a))throw Error("digits must be single-byte (char code 0-255): "+a);nR.add(a)}}else r=nx;let s=nS(r),o=nS(n);if(null!=e&&nC(e,r,n,o),null!=t&&nC(t,r,n,o),null!=e&&null!=t&&e>t){let r=e;e=t,t=r}if(null==e){if(null==t)return n[n.length/2]+r[0];let e=nO(t,n,o),i=t.slice(e.length);if(nA(e,r,n))return e+nI("",i,r,s);if(e<t)return e;let a=function(e,t,r,n,i){n$(e,n,i);let a=e[0],s=t[t.length-1],o="";for(let n=e.length-1;n>=1;n--){let i=r[e.charCodeAt(n)]-1;if(-1!==i)return a+e.slice(1,n)+t[i]+o;o=s+o}let l=i[a.charCodeAt(0)];if(0===l)return null;let d=n[l-1],c=nE(d,n,i)-nE(a,n,i);return d+(c>0?o+s:c<0?o.slice(1):o)}(e,r,s,n,o);if(null==a)throw Error("cannot decrement any more");return a}if(null==t){let t=nO(e,n,o),i=e.slice(t.length),a=nT(t,r,s,n,o);return null==a?t+nI(i,null,r,s):a}let l=nO(e,n,o),d=e.slice(l.length),c=nO(t,n,o),u=t.slice(c.length);if(l===c)return l+nI(d,u,r,s);let f=nT(l,r,s,n,o);if(null==f)throw Error("cannot increment any more");return f<t?f:l+nI(d,null,r,s)}(h,null);e.index=t,h=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:u}}(e.scene);return{excalidraw:t,validation:function(e){let t=[],r=new Map(e.elements.map(e=>[e.id,e])),n=new Set(e.elements.filter(n2).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("arrow"===i.type){let e=!0===i.elbowed;for(let a of((Array.isArray(i.points)?i.points:[]).length>2&&!e&&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[a]||void 0===i[a])continue;let s=n0(i,a);if(!(s&&n.has(s))){t.push({code:"missing-arrow-binding",elementId:i.id,message:`Arrow "${i.id}" has invalid ${a}.`});continue}let o=r.get(s);o&&!function(e,t,r){let n=e.boundElements;return!!Array.isArray(n)&&n.some(e=>!!(e&&"object"==typeof e)&&e.id===t&&e.type===r)}(o,i.id,"arrow")&&t.push({code:"missing-bound-arrow",elementId:o.id,message:`Shape "${o.id}" does not include bound arrow "${i.id}".`});let l=function(e,t){let r=nF(e.x)??0,n=nF(e.y)??0,i=Array.isArray(e.points)?e.points.map(nB).filter(e=>!!e):[],a="startBinding"===t?i[0]:i[i.length-1];return a?{x:r+a[0],y:n+a[1]}:null}(i,a);if(o&&l&&!function(e,t){let r=nL(t);if(!r)return!1;if("diamond"===t.type){let t=r.width/2,n=r.height/2;if(0===t||0===n)return!1;let i=r.x+t,a=r.y+n;return n3(Math.abs(e.x-i)/t+Math.abs(e.y-a)/n,1)}if("ellipse"===t.type){let t=r.width/2,n=r.height/2;if(0===t||0===n)return!1;let i=r.x+t,a=r.y+n;return n3(((e.x-i)/t)**2+((e.y-a)/n)**2,1)}let n=(n3(e.x,r.x)||n3(e.x,r.x+r.width))&&n5(e.y,r.y,r.y+r.height),i=(n3(e.y,r.y)||n3(e.y,r.y+r.height))&&n5(e.x,r.x,r.x+r.width);return n||i}(l,o)&&t.push({code:"arrow-endpoint-off-shape",elementId:i.id,message:`Arrow "${i.id}" ${a} endpoint does not land on "${o.id}".`}),o&&l&&e){let e=function(e,t){let r=e[t];return r&&"object"==typeof r?nB(r.fixedPoint):null}(i,a);e&&function(e,t,r){let n=nL(r);if(!n)return!1;let i=1e-4>Math.abs(e[0]-.5001)?.5:e[0],a=1e-4>Math.abs(e[1]-.5001)?.5:e[1];return n3(n.x+i*n.width,t.x)&&n3(n.y+a*n.height,t.y)}(e,l,o)||t.push({code:"invalid-elbow-binding",elementId:i.id,message:`Elbow arrow "${i.id}" has invalid ${a} fixedPoint metadata.`})}}}if("text"===i.type){let e=i.containerId;if("string"!=typeof e)continue;let n=r.get(e);if(!n){t.push({code:"missing-container",elementId:i.id,message:`Text "${i.id}" references missing container "${e}".`});continue}let a=("number"==typeof i.width?i.width:0)-("number"==typeof i.fontSize?i.fontSize:0),s="number"==typeof i.height?i.height:0,o="number"==typeof n.width?n.width:0,l="number"==typeof n.height?n.height:0;n2(n)&&(a+24>o||s+18>l)&&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(n1),r=e.filter(n2),n=[],i=new Set;for(let e of t)for(let t of r){if(function(e){let t=e.customData;return null!==t&&"object"==typeof t&&t.sketchiRendererRole===nb}(t)||t.id===e.startBindingId||t.id===e.endBindingId)continue;let r=nL(t);if(!r||!ex(e,r))continue;let a=`${e.arrowId}:${e.segmentIndex}:${t.id}`;i.has(a)||(i.add(a),n.push({code:"arrow-segment-through-node",elementId:e.arrowId,message:`Arrow "${e.arrowId}" passes through shape "${t.id}".`}))}return n}(e.elements)),t.push(...function(e){let t=e.filter(e=>"arrow"===e.type).flatMap(n1),r=[],n=new Set;for(let e=0;e<t.length;e+=1){let i=t[e];if(i)for(let a=e+1;a<t.length;a+=1){let e=t[a];if(!e||i.arrowId===e.arrowId||ew(i,e)||!e_(i,e))continue;let s=[i.arrowId,i.segmentIndex,e.arrowId,e.segmentIndex].sort().join(":");n.has(s)||(n.add(s),r.push({code:"overlapping-arrow-segment",elementId:i.arrowId,message:`Arrow "${i.arrowId}" overlaps arrow "${e.arrowId}".`}))}}return r}(e.elements)),{ok:0===t.length,issues:t}}(t)}}).pipe(s.fRP("codeMode.artifacts.exportValidate")),a=e.validationIssues(i.issues);if(a.length>0)return yield*new iY({status:"export_failed",issues:a});let o=yield*at({formats:e.formats,scene:e.scene,excalidraw:n,renderer:t.renderer}).pipe(s.xm_(e=>new iY({status:"export_failed",issues:[i1({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."})]}))),l=yield*s.OH5(()=>t.createId("artifact"));var d=yield*i$(r.write({artifactId:l,diagramId:e.scene.diagramId,formats:o,inlineFormats:e.inlineFormats,...e.provenance?{provenance:e.provenance}:{}}).pipe(s.fRP("codeMode.artifacts.store")),{artifactId:l,...e.requestId?{requestId:e.requestId}:{}}).pipe(s.xm_(e=>new iX({status:"storage_failed",cause:e,issues:[a$(e,"storage_write_failed")]}))),c=t.artifactUrl;if(!c)return d;let u=d.formats.map(e=>({...e,url:c({artifactId:d.artifactId,format:e.format})})),f=d.preview?u.find(e=>e.format===d.preview?.format):void 0;return{...d,formats:u,...f?{preview:f}:{}}}),aO=s.fn("codeMode.buildMindmap.workflow")(function*(e){var t,r;let n,a,o,l,d,c,u,f,p,h=function(e){let t=iL(iL(iL(e)?.spec)?.root);if(!t)return[];let r=[{depth:0,topic:t}],n=1;for(;r.length>0;){let e=r.pop();if(!e)continue;if(e.depth>8)return[i1({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((n+=t.length)>100)return[i1({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 n=t.length-1;n>=0;n-=1){let i=iL(t[n]);i&&r.push({depth:e.depth+1,topic:i})}}}return[]}(e);if(h.length>0)return yield*new iV({status:"invalid_mindmap",context:{issues:h}});let g=i.q$Z(tY,{errors:"all",reportInput:!0})(e);if(!iO.oJ(g))return yield*new iV({status:"invalid_input",context:{issues:i6(eC(g.failure))}});let y=yield*iF,v=g.success,b=yield*s.OH5(()=>y.createId("build")),_=(t=v.spec,n=(e,t)=>({id:`topic-${t.join("-")}`,label:eS(e.label),children:(e.children??[]).map((e,r)=>n(e,[...t,r]))}),a=eS(t.title),{id:i9(t.id)??(i8(a)||"sketchi-mindmap"),title:a,root:n(t.root,[0]),layout:{direction:t.layout.direction},style:{...m}}),x={buildId:b,...ak(v.requestId),normalizedSpec:_},w=(o=0,l=0,(d=(e,t)=>{o+=1,l=Math.max(l,t),e.children.forEach(e=>d(e,t+1))})(_.root,0),u=[],(c={count:o,depth:l}).count<2&&u.push(i1({code:"disconnected_graph",stage:"mindmap",ref:{kind:"diagram",id:_.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&&u.push(i1({code:"mindmap_too_deep",stage:"mindmap",ref:{kind:"diagram",id:_.id},message:`Mindmap depth ${c.depth} exceeds the supported maximum of 8.`,hint:"Combine overly deep topics into a shallower hierarchy."})),c.count>100&&u.push(i1({code:"mindmap_too_large",stage:"mindmap",ref:{kind:"diagram",id:_.id},message:`Mindmap has ${c.count} topics; the supported maximum is 100.`,hint:"Split this hierarchy into smaller focused mindmaps."})),u);if(w.length>0)return yield*new iV({status:"invalid_mindmap",context:{...x,issues:w}});let k=yield*s.SvU({try:()=>{let e,t,r;return e=[],t=[],(r=(n,i,a,s)=>{e.push({id:n.id,label:n.label,kind:0===i?"root":"topic",metadata:{depth:i,siblingIndex:a}}),s&&t.push({id:`branch-${n.id.slice(6)}`,source:s,target:n.id,metadata:{depth:i,siblingIndex:a}}),n.children.forEach((e,t)=>r(e,i+1,t,n.id))})(_.root,0,0),H({id:_.id,title:_.title,type:"mindmap",nodes:e,edges:t,layout:{direction:_.layout.direction,edgeRouting:"curved"},style:{...m}})},catch:e=>new iV({status:"invalid_mindmap",context:{...x,issues:[i1({code:"disconnected_graph",stage:"mindmap",ref:{kind:"diagram",id:_.id},message:e instanceof Error?e.message:"Mindmap failed core validation.",hint:"Repair the nested topic hierarchy and call buildMindmap again."})]}})}),S=(r=v.options?.minQualityScore??8,{accepted:(p=Math.max(0,10-2*(f=k.nodes.filter(e=>/^(topic|branch|item|mindmap)$/i.test(e.label.trim()))).length))>=r,score:p,threshold:r,summary:{nodeCount:k.nodes.length,edgeCount:k.edges.length},checks:f.map(e=>({code:"generic_label",passed:!1,severity:"warning",message:`Topic "${e.label}" is too generic.`,refs:[{kind:"node",id:e.id}]}))}),I={...x,quality:S};if(!S.accepted)return yield*new iV({status:"quality_failed",context:{...I,issues:i4(S)}});let $=yield*s.SvU({try:()=>nv(k),catch:e=>new iV({status:"render_failed",context:{...I,issues:[i1({code:"render_failed",stage:"render",ref:{kind:"diagram",id:_.id},message:e instanceof Error?e.message:"Unable to render mindmap scene.",hint:"Simplify the hierarchy or retry with a smaller mindmap."})]}})}).pipe(s.fRP("codeMode.buildMindmap.render")),E={...I,partial:aS($)},O=yield*aE({scene:$,formats:i7(v.options),inlineFormats:ae(v.options),...v.requestId?{requestId:v.requestId}:{},validationIssues:ar}).pipe(s.xm_(e=>new iV({status:e.status,context:{..."export_failed"===e.status?E:{...I,partial:{diagramId:$.diagramId}},issues:e.issues}})));return{ok:!0,status:"accepted",buildId:b,...ak(v.requestId),normalizedSpec:_,quality:S,artifact:O,issues:[]}}),aC=s.fn("codeMode.buildSequenceDiagram.workflow")(function*(e){var t,r;let n,a,o,l,d,c=i.q$Z(tj,{errors:"all",reportInput:!0})(e);if(!iO.oJ(c))return yield*new iH({status:"invalid_input",context:{issues:i6(eC(c.failure))}});let u=yield*iF,f=c.success,p=yield*s.OH5(()=>u.createId("build")),h=(n=eS((t=f.spec).title),{id:i9(t.id)??(i8(n)||"sketchi-sequence"),title:n,participants:t.participants.map(e=>({id:eS(e.id),label:eS(e.label),...e.kind?{kind:eS(e.kind)}:{}})),messages:t.messages.map((e,t)=>({id:i9(e.id)??`message-${t+1}-${i8(e.source)}-${i8(e.target)}`,source:eS(e.source),target:eS(e.target),label:eS(e.label),...e.type?{type:e.type}:{},...e.style?{style:e.style}:{}})),style:{...m}}),g={buildId:p,...ak(f.requestId),normalizedSpec:h},y=(a=[],o=new Set,h.participants.forEach((e,t)=>{o.has(e.id)&&a.push(i1({code:"duplicate_node_id",stage:"input",ref:{kind:"request",path:`spec.participants.[${t}].id`},message:`Participant id "${e.id}" is duplicated.`,hint:"Give every participant a unique stable id and update message references."})),o.add(e.id)}),l=new Map(h.participants.map((e,t)=>[e.id,t])),h.participants.forEach(e=>{let t=n_(e.id),r=l.get(t);void 0!==r&&a.push(i1({code:"duplicate_node_id",stage:"input",ref:{kind:"request",path:`spec.participants.[${r}].id`},message:`Participant id "${t}" collides with the generated lifeline for "${e.id}".`,hint:"Rename the participant so its id does not equal another participant id followed by :lifeline."}))}),d=new Set,h.messages.forEach((e,t)=>{d.has(e.id)&&a.push(i1({code:"duplicate_edge_id",stage:"input",ref:{kind:"request",path:`spec.messages.[${t}].id`},message:`Message id "${e.id}" is duplicated.`,hint:"Give every message a unique id or omit message ids to generate them deterministically."})),d.add(e.id),o.has(e.source)||a.push(i1({code:"missing_edge_source",stage:"input",ref:{kind:"request",path:`spec.messages.[${t}].source`},message:`Message source "${e.source}" is not a participant.`,hint:"Use the id of a participant declared in spec.participants."})),o.has(e.target)||a.push(i1({code:"missing_edge_target",stage:"input",ref:{kind:"request",path:`spec.messages.[${t}].target`},message:`Message target "${e.target}" is not a participant.`,hint:"Use the id of a participant declared in spec.participants."})),e.source===e.target&&a.push(i1({code:"self_loop",stage:"input",ref:{kind:"request",path:`spec.messages.[${t}]`},message:`Message "${e.id}" is self-referential.`,hint:"Choose a different target participant; self messages are not supported."}))}),a);if(y.length>0)return yield*new iH({status:"invalid_sequence",context:{...g,issues:y}});let v={accepted:10>=(r=f.options?.minQualityScore??8),score:10,threshold:r,summary:{nodeCount:h.participants.length,edgeCount:h.messages.length},checks:[]},b={...g,quality:v};if(!v.accepted)return yield*new iH({status:"quality_failed",context:{...b,issues:i4(v)}});let _=yield*s.SvU({try:()=>(function(e){let t=new Set(e.participants.map(e=>e.id));for(let r of e.participants){let e=n_(r.id);if(t.has(e))throw Error(`Sequence participant "${e}" collides with the generated lifeline for "${r.id}".`)}let r=new Map(e.participants.map(e=>[e.id,eo(e.label,156,14)])),n=e.participants.reduce((e,t)=>Math.max(e,Math.ceil(14*(r.get(t.id)??t.label).split("\n").length*1.35)+18),72),i=48+n,a=i+64,s=a+88*Math.max(0,e.messages.length-1),o=Math.max(a,s)-i+56,l=new Map,d=[],c=[],u=[];e.participants.forEach((t,a)=>{let s=48+320*a,f=s+90;l.set(t.id,f),d.push({type:"node",id:`node:${t.id}`,nodeId:t.id,...t.kind?{kind:t.kind}:{},shape:"rectangle",x:s,y:48,width:180,height:n,label:r.get(t.id)??t.label}),c.push({type:"text",id:`label:${t.id}`,containerId:`node:${t.id}`,x:f,y:48+n/2,text:r.get(t.id)??t.label,fontSize:14,maxWidth:156}),u.push({type:"node",id:`node:${n_(t.id)}`,nodeId:n_(t.id),rendererRole:nb,shape:"rectangle",fillColor:e.style.backgroundColor,strokeColor:e.style.accentColor,x:f-1,y:i,width:2,height:o,label:`${t.label} lifeline`})});let f=e.messages.map((e,t)=>{let r=l.get(e.source),n=l.get(e.target);if(void 0===r||void 0===n)throw Error(`Sequence message "${e.id}" references an unknown participant.`);if(r===n)throw Error(`Sequence message "${e.id}" cannot target its source participant.`);let i=a+88*t,s=n>r?1:-1;return{type:"arrow",id:`arrow:${e.id}`,edgeId:e.id,sourceNodeId:n_(e.source),targetNodeId:n_(e.target),..."return"===e.type?{strokeColor:"#6b7280"}:{},..."dashed"===e.style||"return"===e.type?{strokeStyle:"dashed"}:{},points:[{x:r+2*s/2,y:i},{x:n-2*s/2,y:i}],label:e.label}}),p=[...f,...u,...d,...c],h=[...u.map(e=>e.id),...d.map(e=>e.id),...c.map(e=>e.id),...f.map(e=>e.id)];return{kind:"canvas",version:1,diagramId:e.id,title:e.title,width:276+320*Math.max(0,e.participants.length-1),height:i+o+48,accentColor:e.style.accentColor,backgroundColor:e.style.backgroundColor,elements:p,layers:[],layouts:[],zOrder:h}})(h),catch:e=>new iH({status:"render_failed",context:{...b,issues:[i1({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(s.fRP("codeMode.buildSequenceDiagram.render")),x=eu(_);if(x.length>0)return yield*new iH({status:"render_failed",context:{...b,issues:an(x).map(e=>({...e,hint:"Reduce participant label lines, participants, or messages and retry buildSequenceDiagram."}))}});let w={...b,partial:aS(_)},k=yield*aE({scene:_,formats:i7(f.options),inlineFormats:ae(f.options),...f.requestId?{requestId:f.requestId}:{},validationIssues:ar}).pipe(s.xm_(e=>new iH({status:e.status,context:{..."export_failed"===e.status?w:b,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:p,...ak(f.requestId),normalizedSpec:h,quality:v,artifact:k,issues:[]}}),aT=i._kM({spec:i.$r1,requestId:i.Qrq(i.$r1)}),aM=i._kM({source:i._kM({scene:i.$r1})}),aA=s.fn("codeMode.canvas.serializedLimit")((e,t)=>s.SvU(()=>r7(e)).pipe(s.YWq({onFailure:()=>i1({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<=el.maxSerializedBytes?void 0:i1({code:"canvas_limit_exceeded",stage:"canvas",ref:{kind:"request",path:t},message:`CanvasSpec exceeds ${el.maxSerializedBytes} serialized bytes.`,hint:"Split the visualization into a smaller canvas or reduce repeated text and points."})}))),aN=s.fn("codeMode.createCanvas.workflow")(function*(e){let t=yield*iF,r=yield*s.OH5(()=>t.createId("build")),n=i.q$Z(aT)(e),a=iO.oJ(n)?{spec:n.success.spec,requestId:i.is(i.QfV)(n.success.requestId)?n.success.requestId:void 0}:void 0;if(a){let e=yield*aA(a.spec,"spec");if(e)return yield*new iK({status:"canvas_limit_exceeded"===e.code?"limit_exceeded":"invalid_input",context:{buildId:r,...ak(a.requestId),issues:[e]}})}let o=i.q$Z(rs,{errors:"all",reportInput:!0})(e);if(!iO.oJ(o))return yield*new iK({status:"invalid_input",context:{issues:i6(eC(o.failure))}});let l=o.success,d={buildId:r,...ak(l.requestId)},c=aa(l.spec);if(!c)return yield*new iK({status:"invalid_canvas",context:{...d,issues:[i1({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 u=eu(c).filter(e=>"limit_exceeded"===e.code);if(u.length>0)return yield*new iK({status:"limit_exceeded",context:{...d,issues:an(u)}});let f=function(e){let t=[...e.elements];for(let r of e.layouts)t=function(e,t){switch(t.type){case"row":case"column":case"stack":return function(e,t){let r=ep(e,t.ids),n=r[0];if(!n)return[...e];let i=ef(n),a=t.x??i.x,s=t.y??i.y,o="stack"===t.type?t.gap??0:t.gap??32,l=new Map,d="column"===t.type?s:a;for(let e of r){let r=ef(e);l.set(e.id,{x:"column"===t.type||"stack"===t.type?a:d,y:"column"===t.type?d:s}),"stack"!==t.type&&(d+=("column"===t.type?r.height:r.width)+o)}return eh(e,l)}(e,t);case"grid":return function(e,t){let r=ep(e,t.ids);if(0===r.length)return[...e];let n=Math.max(1,Math.floor(t.columns)),i=r.map(ef),a=Array.from({length:n},(e,t)=>Math.max(0,...i.filter((e,r)=>r%n===t).map(e=>e.width))),s=Array.from({length:Math.ceil(r.length/n)},(e,t)=>Math.max(0,...i.filter((e,r)=>Math.floor(r/n)===t).map(e=>e.height))),o=i[0];if(!o)return[...e];let l=t.x??o.x,d=t.y??o.y,c=t.columnGap??32,u=t.rowGap??32,f=new Map;return r.forEach((e,t)=>{let r=t%n,i=Math.floor(t/n);f.set(e.id,{x:l+a.slice(0,r).reduce((e,t)=>e+t,0)+c*r,y:d+s.slice(0,i).reduce((e,t)=>e+t,0)+u*i})}),eh(e,f)}(e,t);case"align":return function(e,t){let r=ep(e,t.ids);if(0===r.length)return[...e];let n=r.map(ef),i=n.map(e=>em(e,t.axis)),a=n.map(e=>em(e,t.axis)+eg(e,t.axis)),s=n.map(e=>em(e,t.axis)+eg(e,t.axis)/2),o="start"===t.alignment?Math.min(...i):"end"===t.alignment?Math.max(...a):s.reduce((e,t)=>e+t,0)/s.length,l=new Map;return r.forEach((e,r)=>{let i=n[r];if(!i)return;let a="start"===t.alignment?o:"end"===t.alignment?o-eg(i,t.axis):o-eg(i,t.axis)/2;l.set(e.id,{x:"x"===t.axis?a:i.x,y:"y"===t.axis?a:i.y})}),eh(e,l)}(e,t);case"distribute":return function(e,t){let r=ep(e,t.ids).sort((e,r)=>em(ef(e),t.axis)-em(ef(r),t.axis));if(r.length<2)return[...e];let n=r.map(ef),i=n[0],a=n[n.length-1];if(!i||!a)return[...e];let s=em(i,t.axis),o=em(a,t.axis)+eg(a,t.axis),l=n.reduce((e,r)=>e+eg(r,t.axis),0),d=t.gap??Math.max(0,(o-s-l)/(r.length-1)),c=new Map,u=s;return r.forEach((e,r)=>{let i=n[r];i&&(c.set(e.id,{x:"x"===t.axis?u:i.x,y:"y"===t.axis?u:i.y}),u+=eg(i,t.axis)+d)}),eh(e,c)}(e,t)}}(t,r);let r=function(e){let t=1,r=1;for(let n of e)if(ec(n)){let e=ef(n);t=Math.max(t,e.x+e.width),r=Math.max(r,e.y+e.height)}else if("arrow"===n.type||"line"===n.type)for(let e of n.points)t=Math.max(t,e.x),r=Math.max(r,e.y);return{width:t+48,height:r+48}}(t=function(e){let t=new Map(e.filter(e=>"node"===e.type).map(e=>[e.nodeId,e])),r=new Map;for(let t of e)("node"===t.type||"frame"===t.type)&&r.set(t.id,t);let n=e.map(e=>{if("arrow"===e.type){let r=t.get(e.sourceNodeId),n=t.get(e.targetNodeId);return r&&n?{...e,points:[ev(r,ey(n)),...e.points.slice(1,-1),ev(n,ey(r))]}:e}if("line"===e.type){let t=e.startBinding?r.get(e.startBinding.elementId):void 0,n=e.endBinding?r.get(e.endBinding.elementId):void 0;if(!t&&!n)return e;let i=[e.points[0],e.points[1],...e.points.slice(2)];return t&&(i[0]=ev(t,n?ey(n):i[i.length-1]??i[0])),n&&(i[i.length-1]=ev(n,t?ey(t):i[0])),{...e,points:i}}return e}),i=new Map(n.map(e=>[e.id,e]));return n.map(e=>{if("text"!==e.type||!e.containerId)return e;let t=i.get(e.containerId);if(t?.type==="node"){let r=ey(t);return{...e,x:r.x,y:r.y}}if(t?.type==="arrow"){let r=t.points[0],n=t.points[t.points.length-1]??r;return{...e,x:(r.x+n.x)/2,y:(r.y+n.y)/2}}return e})}(t)),n=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,r.width),height:Math.max(e.height,r.height),elements:t,zOrder:n}}(c),p=eu(f);if(p.length>0){let e=an(p);return yield*new iK({status:e.some(e=>"canvas_limit_exceeded"===e.code)?"limit_exceeded":"invalid_canvas",context:{...d,normalizedSpec:f,issues:e}})}let h={...d,normalizedSpec:f,partial:aS(f)},m=yield*aE({scene:f,formats:i7(l.options),inlineFormats:ae(l.options),...l.requestId?{requestId:l.requestId}:{},validationIssues:ai}).pipe(s.xm_(e=>new iK({status:e.status,context:{...h,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:r,...ak(l.requestId),normalizedSpec:f,artifact:m,issues:[]}}),aP=s.fn("codeMode.buildFlowchart.workflow")(function*(e){var t,r;let n,a=i.q$Z(tR,{errors:"all",reportInput:!0})(e);if(!iO.oJ(a))return yield*new iG({status:"invalid_input",context:{issues:i6(eC(a.failure))}});let o=yield*iF,l=a.success,d=yield*s.OH5(()=>o.createId("build")),c=(n=eS((r=l.spec).title),{id:iA(r.id)??(n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"sketchi-flowchart"),title:n,nodes:r.nodes.map(e=>({id:eS(e.id),label:eS(e.label),kind:e.kind,...e.description?{description:eS(e.description)}:{}})),edges:r.edges.map((e,t)=>({id:iA(e.id)??`edge-${t+1}`,source:eS(e.source),target:eS(e.target),...e.label?{label:eS(e.label)}:{}})),layout:{direction:r.layout.direction},style:{...m}}),u={buildId:d,...ak(l.requestId),normalizedSpec:c},f=i.q$Z(j,{errors:"all",reportInput:!0})({id:c.id,title:c.title,type:"flowchart",nodes:c.nodes.map(e=>({...e,metadata:{}})),edges:c.edges.map(e=>({...e,metadata:{}})),layout:{direction:c.layout.direction,edgeRouting:"orthogonal"},style:c.style,metadata:{}});if(!iO.oJ(f))return yield*new iG({status:"invalid_flowchart",context:{...u,issues:(t=eC(f.failure),t.issues.slice(0,20).map(e=>{let t=function(e,t){let r=i2(e.path),n="input"===r?"spec":`spec.${r}`,[i,a]=e.path;if("nodes"===i&&"number"==typeof a){let e=t.nodes[a]?.id;return{kind:"node",...e?{id:e}:{},path:n}}if("edges"===i&&"number"==typeof a){let e=t.edges[a]?.id;return{kind:"edge",...e?{id:e}:{},path:n}}return{kind:"diagram",id:t.id,path:n}}(e,c);return i1({code:i5(e),stage:"flowchart",ref:t,message:e.message,hint:`Fix ${t.path??"spec"} so normalization produces a valid canonical flowchart value.`})}))}});let p=f.success,h=F(p).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 i1({code:e.code,stage:"flowchart",...t?{ref:t}:{},message:e.message,hint:e.hint})});if(h.length>0)return yield*new iG({status:"invalid_flowchart",context:{...u,issues:h}});L(p);let g=function(e,t){let r=[],n=0,i=(e,t,i,a=!1)=>{n+=e,r.push({...i,passed:!1,severity:a?"error":"warning",message:t})},a=new Map,s=new Map;for(let t of e.edges)a.set(t.source,(a.get(t.source)??0)+1),a.set(t.target,(a.get(t.target)??0)+1),s.set(t.source,[...s.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:iM(e.nodes)},!0);else{let t=e.nodes.filter(e=>(a.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:iM(t)},!0);let r=function(e){let t=new Map;for(let r of e.nodes)t.set(r.id,[]);for(let r of e.edges)t.get(r.source)?.push(r.target),t.get(r.target)?.push(r.source);let r=new Set,n=0;for(let i of e.nodes){if(r.has(i.id))continue;n+=1;let e=[i.id];for(r.add(i.id);e.length>0;){let n=e.pop();if(void 0===n)break;for(let i of t.get(n)??[])r.has(i)||(r.add(i),e.push(i))}}return n}(e);r>1&&0===t.length&&i(2,`diagram splits into ${r} disconnected islands`,{code:"disconnected_graph",refs:iM(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 o=new Map;for(let t of e.nodes){let e=t.label.trim().toLowerCase();o.set(e,(o.get(e)??0)+1)}let l=[...o.entries()].filter(([,e])=>e>1);l.length>0&&i(Math.min(l.length,3),`duplicate label(s): ${l.map(([e])=>`"${e}"`).join(", ")}`,{code:"duplicate_label",refs:iM(e.nodes.filter(e=>(o.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:iM([t])});continue}let e=s.get(t.id)??[];e.length<2?(d+=1,i(0,`decision "${t.id}" needs at least 2 outgoing branches`,{code:"underbranched_decision",refs:iM([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:iM([t])}))}n+=Math.min(1.5*d,4.5)+Math.min(c,3);let u=e.nodes.filter(e=>e.label.length>42);u.length>0&&i(Math.min(.5*u.length,2),`shorten label(s): ${u.map(e=>e.id).join(", ")}`,{code:"label_too_long",refs:iM(u)});let f=e.nodes.filter(e=>iC.test(e.label.trim()));f.length>0&&i(Math.min(f.length,3),`generic label(s) say nothing: ${f.map(e=>`"${e.label}"`).join(", ")}`,{code:"generic_label",refs:iM(f)}),(e.title.trim().length<4||iT.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 p=Math.max(0,Math.round((10-n)*10)/10);return{accepted:p>=t&&!r.some(e=>"error"===e.severity),score:p,threshold:t,summary:{nodeCount:e.nodes.length,edgeCount:e.edges.length},checks:r}}(p,l.options?.minQualityScore??8),y={...u,quality:g};if(!g.accepted)return yield*new iG({status:"quality_failed",context:{...y,issues:i4(g)}});let v=yield*s.SvU({try:()=>nv(p),catch:e=>new iG({status:"render_failed",context:{...y,issues:[i1({code:"render_failed",stage:"render",ref:{kind:"diagram",id:c.id},message:e instanceof Error?e.message:"Unable to render flowchart scene.",hint:"Simplify the graph or retry with a smaller flowchart."})]}})}).pipe(s.fRP("codeMode.buildFlowchart.render")),b={...y,partial:aS(v)},_=yield*aE({scene:v,formats:i7(l.options),inlineFormats:ae(l.options),...l.requestId?{requestId:l.requestId}:{},validationIssues:ar}).pipe(s.xm_(e=>new iG({status:e.status,context:{..."export_failed"===e.status?b:y,issues:e.issues}})));return{ok:!0,status:"accepted",buildId:d,...ak(l.requestId),normalizedSpec:c,quality:g,artifact:_,issues:[]}}),aR=s.fn("codeMode.getArtifact.workflow")(function*(e){let t=i.q$Z(ru,{errors:"all",reportInput:!0})(e);if(!iO.oJ(t))return yield*new iQ({status:"invalid_input",context:{issues:i6(eC(t.failure))}});let r=yield*iF,n=yield*r6,a=t.success,o=yield*n.readManifest(a.artifactId).pipe(s.xm_(e=>new iQ({status:"storage_failed",context:{issues:[a$(e,"storage_read_failed")]}})));if(!o)return yield*new iQ({status:"not_found",context:{issues:[i1({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:a.artifactId},message:`Artifact "${a.artifactId}" was not found.`,hint:"Use the artifactId returned by buildFlowchart or applyDiagramPatch."})]}});let l=a.format??"scene";if(!o.formats.some(e=>e.format===l))return yield*new iQ({status:"format_unavailable",context:{issues:[i1({code:"unsupported_artifact_format",stage:"storage",ref:{kind:"artifact",id:a.artifactId},message:`Artifact "${a.artifactId}" does not include format "${l}".`,hint:"Request a format listed in the artifact bundle."})]}});let d=yield*n.read(a.artifactId,l).pipe(s.xm_(e=>new iQ({status:"storage_failed",context:{issues:[a$(e,"storage_read_failed")]}})));return d?{ok:!0,artifactId:a.artifactId,diagramId:o.diagramId,format:l,mimeType:d.mimeType,...r.artifactUrl?{url:r.artifactUrl({artifactId:a.artifactId,format:l})}:{},...!0!==a.inline||!r9(l)?{}:{inline:d.data},sizeBytes:d.sizeBytes,...o.provenance?{provenance:o.provenance}:{}}:yield*new iQ({status:"format_unavailable",context:{issues:[i1({code:"patch_source_unavailable",stage:"storage",ref:{kind:"artifact",id:a.artifactId},message:`Artifact "${a.artifactId}" format "${l}" could not be read.`,hint:"Retry retrieval or rebuild the artifact."})]}})}),aj=s.fn("codeMode.applyDiagramPatch.workflow")(function*(e){let t,r=i.q$Z(aM)(e),n=iO.oJ(r)?yield*aA(r.success.source.scene,"source.scene"):void 0;if(n)return yield*new iZ({status:"invalid_input",context:{issues:[n]}});let a=i.q$Z(rP,{errors:"all",reportInput:!0})(e);if(!iO.oJ(a))return yield*new iZ({status:"invalid_input",context:{issues:i6(eC(a.failure))}});let o=yield*iF,l=a.success,d=yield*s.OH5(()=>o.createId("patch")),c={patchId:d,...ak(l.requestId)},u=yield*aw(l).pipe(s.xm_(e=>new iZ({status:e.status,context:{...c,...e.context}}))),f={...c,...u.sourceArtifactId?{sourceArtifactId:u.sourceArtifactId}:{}},p=u.scene;if(p.elements.length>el.maxElements)t=[{code:"limit_exceeded",message:`Canvas exceeds ${el.maxElements} elements.`,path:"elements"}];else{let e=aa(p);t=e?eu(e).filter(e=>"limit_exceeded"===e.code):[]}if(t.length>0)return yield*new iZ({status:"invalid_input",context:{...f,issues:an(t)}});let h=ao(p),m=[];for(let e of l.operations)if((m=function(e,t){switch(t.op){case"setDefaultStyle":case"setStyle":if(t.style.backgroundColor&&(e.backgroundColor=t.style.backgroundColor),"setDefaultStyle"===t.op){for(let r of(t.style.strokeColor&&(e.accentColor=t.style.strokeColor),al(e)))t.style.fillColor&&(r.fillColor=t.style.fillColor),t.style.strokeColor&&(r.strokeColor=t.style.strokeColor),t.style.textColor&&(r.textColor=t.style.textColor);for(let r of ac(e))t.style.strokeColor&&(r.strokeColor=t.style.strokeColor),t.style.textColor&&(r.textColor=t.style.textColor);for(let r of ad(e))t.style.textColor&&(r.textColor=t.style.textColor);return[]}let r=af(e,t.selector);if(0===r.nodes.length&&0===r.arrows.length&&0===r.texts.length)return[ap(t)];for(let n of r.nodes)if(t.style.fillColor&&(n.fillColor=t.style.fillColor),t.style.strokeColor&&(n.strokeColor=t.style.strokeColor),t.style.textColor){n.textColor=t.style.textColor;let r=ah(e,n.id);r&&(r.textColor=t.style.textColor)}for(let n of r.arrows)if(t.style.strokeColor&&(n.strokeColor=t.style.strokeColor),t.style.textColor){n.textColor=t.style.textColor;let r=ah(e,n.id);r&&(r.textColor=t.style.textColor)}for(let e of r.texts)t.style.textColor&&(e.textColor=t.style.textColor);return[];case"setShape":let n=af(e,t.selector);if(0===n.nodes.length)return[ap(t)];let i=[];for(let r of n.nodes){if(r.shape=t.shape,"polygon"===t.shape?r.points=[{x:r.width/2,y:0},{x:r.width,y:r.height/2},{x:r.width/2,y:r.height},{x:0,y:r.height/2}]:delete r.points,"circle"===t.shape){let e=Math.max(r.width,r.height);r.x-=(e-r.width)/2,r.y-=(e-r.height)/2,r.width=e,r.height=e,i.push(r.nodeId)}!function(e,t){let r=ah(e,t.id);r&&(r.x=t.x+t.width/2,r.y=t.y+t.height/2)}(e,r)}return am(e,i),[];case"translate":return function(e,t){let r=af(e,t.selector);if(0===r.nodes.length&&0===r.arrows.length&&0===r.texts.length)return[ap(t)];let n=new Set,i=new Set;for(let a of r.nodes){a.x+=t.dx,a.y+=t.dy,n.add(a.nodeId);let r=ah(e,a.id);r&&(r.x+=t.dx,r.y+=t.dy,i.add(r.id))}for(let n of r.arrows){n.points=n.points.map(e=>{var r,n;return r=t.dx,n=t.dy,{x:e.x+r,y:e.y+n}});let r=ah(e,n.id);r&&(r.x+=t.dx,r.y+=t.dy,i.add(r.id))}for(let e of r.texts)i.has(e.id)||(e.x+=t.dx,e.y+=t.dy);return am(e,[...n]),ab(e),[]}(e,t);case"replaceText":let a=af(e,t.selector);if(0===a.nodes.length&&0===a.arrows.length&&0===a.texts.length)return[ap(t)];for(let r of a.nodes){r.label=t.text;let n=ah(e,r.id);n&&(n.text=t.text)}for(let r of a.arrows){r.label=t.text;let n=ah(e,r.id);n&&(n.text=t.text)}for(let e of a.texts)e.text=t.text;return[];case"rerouteEdges":let s;return 0===(s=af(e,t.selector)).arrows.length?[ap(t)]:s.arrows.flatMap(t=>av(e,t));case"insert":let o=new Set(e.elements.map(e=>e.id)),l=t.elements.map(e=>e.id);if(new Set(l).size!==l.length||l.some(e=>o.has(e)))return ax(t,"Inserted elements must use ids that are unique within the canvas.");let d=a_(e.zOrder,t.beforeId,t.afterId);return void 0===d?ax(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,...l),[]);case"remove":return function(e,t){let r,n=function(e,t){let r=af(e,t),n=new Set([...r.nodes.map(e=>e.id),...r.arrows.map(e=>e.id),...r.texts.map(e=>e.id)]),i=new Set(t.ids??[]);for(let t of e.elements)i.has(t.id)&&n.add(t.id);return n}(e,t.selector);if(0===n.size)return[ap(t)];let i=new Set(e.elements.flatMap(e=>"node"===e.type&&n.has(e.id)?[e.nodeId]:[]));do for(let t of(r=n.size,e.elements))("text"===t.type&&t.containerId&&n.has(t.containerId)||"arrow"===t.type&&(i.has(t.sourceNodeId)||i.has(t.targetNodeId))||"line"===t.type&&(t.startBinding&&n.has(t.startBinding.elementId)||t.endBinding&&n.has(t.endBinding.elementId)))&&n.add(t.id);while(n.size!==r)let a=e.elements.filter(e=>!n.has(e.id)).map(e=>{if(e.frameId&&n.has(e.frameId)){let{frameId:t,...r}=e;return r}return e});e.elements.splice(0,e.elements.length,...a);let s=e.zOrder.filter(e=>!n.has(e));e.zOrder.splice(0,e.zOrder.length,...s);let o=e.layouts.map(e=>({...e,ids:e.ids.filter(e=>!n.has(e))})).filter(e=>e.ids.length>0);return e.layouts.splice(0,e.layouts.length,...o),ab(e),[]}(e,t);case"replace":let c;return(c=e.elements.findIndex(e=>e.id===t.id))<0?[ap(t)]:t.element.id!==t.id?ax(t,"Replacement element id must match the stable id being replaced."):(e.elements.splice(c,1,structuredClone(t.element)),ab(e),[]);case"reorder":let u=new Set(t.ids);if(u.size!==t.ids.length||t.ids.some(t=>!e.zOrder.includes(t)))return ax(t,"Reorder ids must be unique ids already present in zOrder.");let f=e.zOrder.filter(e=>!u.has(e)),p=a_(f,t.beforeId,t.afterId);return void 0===p?ax(t,"Reorder specifies an unknown anchor or both beforeId and afterId."):(f.splice(p,0,...t.ids),e.zOrder.splice(0,e.zOrder.length,...f),[]);case"group":case"ungroup":let h=new Set(t.ids);if(t.ids.some(t=>!e.elements.some(e=>e.id===t)))return[ap(t)];let m=e.elements.map(e=>h.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,...m),[]}}(p,e)).length>0)break;if(m.length>0)return yield*new iZ({status:m[0]?.code==="unknown_patch_target"?"target_not_found":"unsupported_operation",context:{...f,issues:m}});if(l.options?.preserveConnectivity!==!1){let e=ao(p);if(!(h.length===e.length&&h.every((t,r)=>t===e[r])))return yield*new iZ({status:"connectivity_changed",context:{...f,issues:[i1({code:"patch_preserve_connectivity_failed",stage:"flowchart",ref:{kind:"diagram",id:p.diagramId},message:"Patch changed the diagram edge connectivity.",hint:"Use buildFlowchart for process-graph structure or buildMindmap for hierarchy structure."})]}})}let g=aa(p);if(!g)return yield*new iZ({status:"render_failed",context:{...f,issues:[i1({code:"patch_output_invalid",stage:"render",ref:{kind:"diagram",id:p.diagramId},message:"Patched scene has an invalid arrow point list.",hint:"Reroute edges or rebuild the flowchart artifact."})]}});let y=eu(g);if(y.length>0)return yield*new iZ({status:"render_failed",context:{...f,partial:aS(g),issues:an(y)}});let v={...f,partial:aS(g)},b=yield*aE({scene:g,formats:i7(l.options),inlineFormats:ae(l.options),...l.requestId?{requestId:l.requestId}:{},validationIssues:ai,...u.sourceArtifactId?{provenance:{sourceArtifactId:u.sourceArtifactId}}:{}}).pipe(s.xm_(e=>new iZ({status:e.status,context:{..."export_failed"===e.status?v:f,issues:e.issues}})));return{ok:!0,status:"accepted",patchId:d,...ak(l.requestId),...u.sourceArtifactId?{sourceArtifactId:u.sourceArtifactId}:{},artifact:b,issues:[]}});function aD(e,t,r){return s.fn(`codeMode.${e}`)(n=>{var i,a,l;let d,c,u,f;return i=e,a=n,l=t(n).pipe(s.YWq({onFailure:r,onSuccess:e=>e})),i$(s.JkU(function*(){let e=yield*o.Ru,t=yield*l,r=yield*o.Ru,n=t.ok?"success":"failure",a=t.ok?void 0:t.status??"unknown_failure";yield*iE(iR,1,{...a?{failureCategory:a}:{},operation:i,outcome:n,surface:"code_mode"}),yield*iE(iU,r-e,{...a?{failureCategory:a}:{},operation:i,outcome:n,surface:"code_mode"}),a&&(yield*iE(ij,1,{failureCategory:a,operation:i,surface:"code_mode"}));let s="buildFlowchart"===i?"flowchart":"buildMindmap"===i?"mindmap":"buildSequenceDiagram"===i?"sequence":"createCanvas"===i?"canvas":"applyDiagramPatch"===i?"patch":void 0;return t.ok&&s&&(yield*iE(iD,1,{artifactKind:s,operation:i,surface:"code_mode"})),t}),(d=iL(a),c=iL(d?.source),u="string"==typeof d?.artifactId?d.artifactId:"string"==typeof c?.artifactId?c.artifactId:void 0,f="string"==typeof d?.requestId?d.requestId:void 0,{...u?{artifactId:u}:{},...f?{requestId:f}:{}}))})}let aU=aD("buildFlowchart",aP,aI),aF=aD("buildMindmap",aO,aI),aB=aD("buildSequenceDiagram",aC,aI);aD("createCanvas",aN,aI),aD("getArtifact",aR,aI);let aL=aD("applyDiagramPatch",aj,aI)},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"}]')}},o={};function l(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return s[e].call(r.exports,r,r.exports,l),r.exports}l.m=s,l.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return l.d(t,{a:t}),t},n=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,l.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);l.r(i);var a={};r=r||[null,n({}),n([]),n(n)];for(var s=2&t&&e;("object"==typeof s||"function"==typeof s)&&!~r.indexOf(s);s=n(s))Object.getOwnPropertyNames(s).forEach(t=>{a[t]=()=>e[t]});return a.default=()=>e,l.d(i,a),i},l.d=(e,t,r)=>{var n=(t,r)=>{for(var n in t)l.o(t,n)&&!l.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,[r]:t[n]})};n(t,"get"),n(r,"value")},l.f={},l.e=e=>Promise.all(Object.keys(l.f).reduce((t,r)=>(l.f[r](e,t),t),[])),l.u=e=>"chunks/"+e+"."+({548:"416192d3a8231af0",869:"6f2420c99d28c2f5"})[e]+".js",l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.nc=void 0,i={889:0},a=e=>{var t,r,n=e.__rspack_esm_ids,a=e.__webpack_modules__,s=e.__rspack_esm_runtime,o=0;for(t in a)l.o(a,t)&&(l.m[t]=a[t]);for(s&&s(l);o<n.length;o++)r=n[o],l.o(i,r)&&i[r]&&i[r][0](),i[n[o]]=0},l.f.j=function(e,t){var r=l.o(i,e)?i[e]:void 0;if(0!==r)if(r)t.push(r[1]);else{var n=import("./"+l.u(e)).then(a,t=>{throw 0!==i[e]&&(i[e]=void 0),t}),n=Promise.race([n,new Promise(t=>{r=i[e]=[t]})]);t.push(r[1]=n)}},l(1833);