@p4code/cli 0.7.12 → 0.7.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +14 -12
- package/dist/client/assets/{DiffPanel-CjaHqa_8.js → DiffPanel-CeEGroRp.js} +2 -2
- package/dist/client/assets/{FilePreviewPanel-C2PYAtLd.js → FilePreviewPanel-DYlVNx6G.js} +2 -2
- package/dist/client/assets/{P4DesignScreen-DC7SIQVB.js → P4DesignScreen-CAko1RXc.js} +2 -2
- package/dist/client/assets/{PreviewPanel-BZDO7-Mk.js → PreviewPanel-DV8ek6zP.js} +2 -2
- package/dist/client/assets/{PullRequestCodeTab-C_tIdavh.js → PullRequestCodeTab-B9ZcowFy.js} +2 -2
- package/dist/client/assets/{collapsible-SgMHVGmw.js → collapsible-BYB8Vm7J.js} +2 -2
- package/dist/client/assets/{entities-B4SwAa71.js → entities-rFZO2CnH.js} +2 -2
- package/dist/client/assets/{fileCommentAnnotations-5NB78l1R.js → fileCommentAnnotations-DMZJf240.js} +2 -2
- package/dist/client/assets/{index-C5KWoWnj.js → index-BtOOP_4i.js} +11 -7
- package/dist/client/assets/{input-DXewBWN5.js → input-COb8u_Ms.js} +2 -2
- package/dist/client/assets/{renderFileChildren-DyCrUihH.js → renderFileChildren-gCX998tv.js} +2 -2
- package/dist/client/assets/{textarea-nbGt7Tak.js → textarea-CWiSD-BA.js} +3 -3
- package/dist/client/assets/{timestampFormat-C0cLmm_Q.js → timestampFormat-CPEoBq-v.js} +2 -2
- package/dist/client/assets/{toggle-group-wBnK735z.js → toggle-group-CnELn-Lg.js} +2 -2
- package/dist/client/index.html +6 -6
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{a as i,i as a,n as o,o as s,r as c,s as l,t as u}from"./collapsible-SgMHVGmw.js";import{$l as d,$s as f,Ap as p,Bl as m,Cl as h,Di as g,Ei as _,El as v,Fi as y,G as b,Gl as x,H as S,Hi as C,Ii as w,Im as T,Js as E,Kl as D,Ks as O,Lf as k,Li as A,Lm as j,Mm as M,Ni as N,Ol as P,Pi as F,Pm as I,Qr as L,Qs as R,Rl as ee,S as z,Tl as B,Ul as te,Vh as ne,Vm as re,Vu as ie,W as ae,Wm as V,Xs as oe,Yl as se,Yp as ce,Ys as le,Zf as ue,Zs as de,_p as fe,al as pe,b as H,bl as me,cu as he,dt as ge,g as _e,gh as ve,gl as ye,gm as be,gp as xe,ii as Se,jp as Ce,ki as we,kl as U,kp as Te,ll as Ee,lu as De,mp as Oe,n as ke,ni as Ae,oc as je,ol as Me,op as Ne,ou as Pe,q as Fe,qc as Ie,qs as Le,r as Re,ri as ze,rl as Be,sh as Ve,su as He,t as Ue,th as We,ti as Ge,ut as Ke,v as qe,vp as Je,wc as Ye,x as Xe,xm as Ze,y as Qe,yl as $e,yp as et,zf as tt,zm as nt}from"./textarea-nbGt7Tak.js";import{t as rt}from"./env-jW24S9HL.js";import{C as it,k as at,w as ot,y as st}from"./entities-B4SwAa71.js";import{n as ct,t as lt}from"./input-DXewBWN5.js";import{$r as ut,Ar as dt,Bi as ft,C as pt,Ci as mt,Di as ht,E as gt,Ei as _t,Fi as vt,Fr as yt,G as bt,Ii as xt,Ir as St,J as Ct,Ji as wt,K as Tt,Ki as Et,Li as Dt,Mi as Ot,Mr as kt,Nr as At,Pi as jt,Pr as Mt,Qi as Nt,Qr as Pt,S as Ft,Si as It,T as Lt,Ti as Rt,U as zt,Vi as Bt,W as Vt,Wi as Ht,X as Ut,Xi as Wt,Y as Gt,Yr as Kt,Zi as qt,Zr as Jt,_ as Yt,_r as Xt,aa as Zt,b as Qt,bi as $t,ca as en,ei as tn,fa as nn,g as rn,ga as an,gr as on,h as sn,ha as cn,hr as ln,ii as un,ji as dn,jr as fn,m as pn,ma as mn,mr as hn,na as gn,ni as _n,pa as vn,pr as yn,q as bn,qi as xn,ri as Sn,sa as Cn,ti as wn,v as Tn,vr as En,w as Dn,wi as On,x as kn,xi as An,y as jn,yi as Mn}from"./index-C5KWoWnj.js";var Nn=R(`boxes`,[[`path`,{d:`M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z`,key:`lc1i9w`}],[`path`,{d:`m7 16.5-4.74-2.85`,key:`1o9zyk`}],[`path`,{d:`m7 16.5 5-3`,key:`va8pkn`}],[`path`,{d:`M7 16.5v5.17`,key:`jnp8gn`}],[`path`,{d:`M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z`,key:`8zsnat`}],[`path`,{d:`m17 16.5-5-3`,key:`8arw3v`}],[`path`,{d:`m17 16.5 4.74-2.85`,key:`8rfmw`}],[`path`,{d:`M17 16.5v5.17`,key:`k6z78m`}],[`path`,{d:`M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z`,key:`1xygjf`}],[`path`,{d:`M12 8 7.26 5.15`,key:`1vbdud`}],[`path`,{d:`m12 8 4.74-2.85`,key:`3rx089`}],[`path`,{d:`M12 13.5V8`,key:`1io7kd`}]]),Pn=R(`focus`,[[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}],[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}]]),Fn=R(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),In=R(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),Ln=R(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),Rn=R(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]),zn=R(`swatch-book`,[[`path`,{d:`M11 17a4 4 0 0 1-8 0V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2Z`,key:`1ldrpk`}],[`path`,{d:`M16.7 13H19a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2H7`,key:`11i5po`}],[`path`,{d:`M 7 17h.01`,key:`1euzgo`}],[`path`,{d:`m11 8 2.3-2.3a2.4 2.4 0 0 1 3.404.004L18.6 7.6a2.4 2.4 0 0 1 .026 3.434L9.9 19.8`,key:`o2gii7`}]]),Bn=R(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),W=r(),G=e(n(),1),K=t(),Vn=(0,G.createContext)(null);function Hn(e){let t=(0,W.c)(3),{host:n,children:r}=e,i=n,a;return t[0]!==r||t[1]!==i?(a=(0,K.jsx)(Vn,{value:i,children:r}),t[0]=r,t[1]=i,t[2]=a):a=t[2],a}function Un(){let e=(0,G.use)(Vn);if(!e)throw Error(`Design workspace rendered outside a DesignHostProvider`);return e}var Wn=m(se(!1)).pipe(te(`design-query:empty`));function Gn(e){let t=Ve(e);return t instanceof Error&&t.message.trim().length>0?t.message:`The environment request failed.`}function Kn(e){let t=(0,W.c)(10),n=e??Wn,r=pe(n),i=Be(n),a;t[0]===r?a=t[1]:(a=ne(d(r)),t[0]=r,t[1]=a);let o;t[2]!==r._tag||t[3]!==r.cause?(o=r._tag===`Failure`?Gn(r.cause):null,t[2]=r._tag,t[3]=r.cause,t[4]=o):o=t[4];let s=e!==null&&r.waiting,c;return t[5]!==i||t[6]!==a||t[7]!==o||t[8]!==s?(c={data:a,error:o,isPending:s,refresh:i},t[5]=i,t[6]=a,t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function qn(){let e=Un(),t=(0,G.useContext)(Me);return(0,G.useCallback)(async n=>{let r=e.runtime.atom(n),i=await T(j(Ze(function*(){return yield*D(t,r),yield*x(t,r,{suspendOnWaiting:!0})})));if(ve(i))throw Ve(i.cause);return i.value},[e,t])}function Jn(e){let t=(0,W.c)(71),{target:n,path:r,revision:i,fileHash:a,disabled:o}=e,{transport:s}=Un(),c=qn(),[l,u]=(0,G.useState)(!1),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(null),[h,g]=(0,G.useState)(null),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(0),S;t[0]!==l||t[1]!==r||t[2]!==c||t[3]!==n||t[4]!==s?(S=()=>{if(!l)return;let e=!0;return f(null),m(null),c(s.revisions(n,r)).then(t=>{e&&f(t)},()=>{e&&m(`Could not load revisions.`)}),()=>{e=!1}},t[0]=l,t[1]=r,t[2]=c,t[3]=n,t[4]=s,t[5]=S):S=t[5];let w;t[6]!==b||t[7]!==l||t[8]!==r||t[9]!==c||t[10]!==n||t[11]!==s?(w=[l,b,n,r,s,c],t[6]=b,t[7]=l,t[8]=r,t[9]=c,t[10]=n,t[11]=s,t[12]=w):w=t[12],(0,G.useEffect)(S,w);let T=o||v,E;t[13]===T?E=t[14]:(E=(0,K.jsx)(_,{size:`sm`,variant:`ghost`,disabled:T,"aria-label":`Design revisions`,className:`design-mono`}),t[13]=T,t[14]=E);let D;t[15]===i?D=t[16]:(D=i?.slice(0,8)??`unavailable`,t[15]=i,t[16]=D);let O;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,K.jsx)(oe,{"aria-hidden":`true`}),t[17]=O):O=t[17];let k;t[18]!==E||t[19]!==D?(k=(0,K.jsxs)(C,{render:E,children:[`Revision `,D,O]}),t[18]=E,t[19]=D,t[20]=k):k=t[20];let A;t[21]!==b||t[22]!==p||t[23]!==a||t[24]!==d?(A=p?(0,K.jsxs)(N,{onClick:()=>x(b+1),children:[p,` Retry`]}):d===null?(0,K.jsx)(N,{disabled:!0,children:`Loading revisions...`}):d.length===0?(0,K.jsx)(N,{disabled:!0,children:`No saved revisions yet`}):d.map(e=>(0,K.jsx)(N,{disabled:e.fileHash===a,onClick:()=>{m(null),g({entry:e,expectedFileHash:a})},children:(0,K.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,K.jsxs)(`span`,{className:`font-mono`,children:[e.revision.slice(0,8),e.fileHash===a?` · Current`:``]}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.savedAt).toLocaleString()})]})},e.id)),t[21]=b,t[22]=p,t[23]=a,t[24]=d,t[25]=A):A=t[25];let j;t[26]===A?j=t[27]:(j=(0,K.jsx)(F,{align:`start`,className:`max-h-80 overflow-y-auto`,children:A}),t[26]=A,t[27]=j);let M;t[28]!==l||t[29]!==k||t[30]!==j?(M=(0,K.jsxs)(we,{open:l,onOpenChange:u,children:[k,j]}),t[28]=l,t[29]=k,t[30]=j,t[31]=M):M=t[31];let P=h!==null,I;t[32]===v?I=t[33]:(I=e=>{!e&&!v&&(g(null),m(null))},t[32]=v,t[33]=I);let L;t[34]===h?.entry.revision?L=t[35]:(L=h?.entry.revision.slice(0,8),t[34]=h?.entry.revision,t[35]=L);let R;t[36]===L?R=t[37]:(R=(0,K.jsxs)(z,{children:[`Restore revision `,L,`?`]}),t[36]=L,t[37]=R);let ee;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,K.jsx)(qe,{children:`Replace this design with the saved version. Your current version stays in revision history. Libraries and assets are unchanged.`}),t[38]=ee):ee=t[38];let B;t[39]===p?B=t[40]:(B=p?(0,K.jsx)(`p`,{role:`alert`,className:`design-revision-error`,children:p}):null,t[39]=p,t[40]=B);let te;t[41]!==R||t[42]!==B?(te=(0,K.jsxs)(H,{children:[R,ee,B]}),t[41]=R,t[42]=B,t[43]=te):te=t[43];let ne;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(ne=()=>{g(null),m(null)},t[44]=ne):ne=t[44];let re;t[45]===v?re=t[46]:(re=(0,K.jsx)(_,{size:`sm`,variant:`ghost`,disabled:v,onClick:ne,children:`Cancel`}),t[45]=v,t[46]=re);let ie=v||o||!h,ae;t[47]!==v||t[48]!==r||t[49]!==c||t[50]!==h||t[51]!==n||t[52]!==s?(ae=()=>{!h||v||(y(!0),m(null),c(s.restoreRevision(n,r,h.entry.id,h.expectedFileHash)).then(()=>g(null),e=>m(e instanceof Error&&`code`in e&&e.code===`conflict`?`The design changed. Reopen revision history and try again.`:e instanceof Error&&`code`in e&&e.code===`invalid-document`?`This revision cannot be restored with the current libraries and assets.`:`Could not restore this revision. Reopen revision history and try again.`)).finally(()=>y(!1)))},t[47]=v,t[48]=r,t[49]=c,t[50]=h,t[51]=n,t[52]=s,t[53]=ae):ae=t[53];let V=v?`Restoring...`:`Restore revision`,se;t[54]!==ie||t[55]!==ae||t[56]!==V?(se=(0,K.jsx)(_,{size:`sm`,disabled:ie,onClick:ae,children:V}),t[54]=ie,t[55]=ae,t[56]=V,t[57]=se):se=t[57];let ce;t[58]!==re||t[59]!==se?(ce=(0,K.jsxs)(Qe,{children:[re,se]}),t[58]=re,t[59]=se,t[60]=ce):ce=t[60];let le;t[61]!==te||t[62]!==ce?(le=(0,K.jsxs)(Xe,{className:`max-w-md`,children:[te,ce]}),t[61]=te,t[62]=ce,t[63]=le):le=t[63];let ue;t[64]!==P||t[65]!==I||t[66]!==le?(ue=(0,K.jsx)(_e,{open:P,onOpenChange:I,children:le}),t[64]=P,t[65]=I,t[66]=le,t[67]=ue):ue=t[67];let de;return t[68]!==M||t[69]!==ue?(de=(0,K.jsxs)(K.Fragment,{children:[M,ue]}),t[68]=M,t[69]=ue,t[70]=de):de=t[70],de}var Yn=()=>null;function Xn({target:e,path:t,revision:n,compact:r=!1}){let{navigation:i}=Un(),a=(i.useWorkspaceRoot??Yn)(e),[o,s]=(0,G.useState)(null);if(!e||!a||!t||!n)return null;let c=En({projectRoot:a,documentPath:t,revision:n,...i.linkEnvironment?{environmentId:e.environmentId}:{}}),l=o?.link===c?o:null;return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,K.jsxs)(_,{size:`sm`,variant:r?`ghost`:`outline`,onClick:()=>{Promise.resolve().then(()=>navigator.clipboard.writeText(c)).then(()=>s({link:c,error:!1}),()=>s({link:c,error:!0}))},children:[(0,K.jsx)(qt,{"aria-hidden":`true`}),l&&!l.error?`Link copied`:r?`Copy link`:`Copy design link`]}),l?.error?(0,K.jsx)(`span`,{role:`alert`,className:`text-xs`,children:`Could not copy. Try again.`}):null,l&&!l.error?(0,K.jsx)(`span`,{role:`status`,className:`sr-only`,children:`Paste into a P4 Code thread in this project.`}):null]})}function Zn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function Qn(e,...t){if(!Zn(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function $n(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function er(e,t){Qn(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function tr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function nr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function rr(e,t){return e<<32-t|e>>>t}var ir=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,ar=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function or(e){if(Qn(e),ir)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=ar[e[n]];return t}function sr(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function cr(e){return typeof e==`string`&&(e=sr(e)),Qn(e),e}var lr=class{};function ur(e){let t=t=>e().update(cr(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function dr(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function fr(e,t,n){return e&t^~e&n}function pr(e,t,n){return e&t^e&n^t&n}var mr=class extends lr{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=nr(this.buffer)}update(e){$n(this),e=cr(e),Qn(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=nr(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){$n(this),er(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,tr(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;dr(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=nr(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},hr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),gr=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),_r=new Uint32Array(64),vr=class extends mr{constructor(e=32){super(64,e,8,!1),this.A=hr[0]|0,this.B=hr[1]|0,this.C=hr[2]|0,this.D=hr[3]|0,this.E=hr[4]|0,this.F=hr[5]|0,this.G=hr[6]|0,this.H=hr[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)_r[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=_r[e-15],n=_r[e-2],r=rr(t,7)^rr(t,18)^t>>>3;_r[e]=(rr(n,17)^rr(n,19)^n>>>10)+_r[e-7]+r+_r[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=rr(o,6)^rr(o,11)^rr(o,25),u=l+t+fr(o,s,c)+gr[e]+_r[e]|0,d=(rr(n,2)^rr(n,13)^rr(n,22))+pr(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){tr(_r)}destroy(){this.set(0,0,0,0,0,0,0,0),tr(this.buffer)}},yr=ur(()=>new vr),br=Te(He),xr=Te(De),Sr=(e,t,n,r=`error`)=>({code:e,message:t,severity:r,...n?{nodeId:n}:{}});function Cr(e){let t=e=>{if(e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e))return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t).join(`,`)}]`;if(typeof e==`object`&&e&&Object.getPrototypeOf(e)===Object.prototype){let n=e;return`{${Object.keys(n).sort().map(e=>`${JSON.stringify(e)}:${t(n[e])}`).join(`,`)}}`}throw Error(`Design JSON must contain only finite JSON values`)};return`${t(e)}\n`}function wr(e){return or(yr(typeof e==`string`?new TextEncoder().encode(e):e))}function Tr(e){try{let t=JSON.parse(e);if(typeof t!=`object`||!t||!(`version`in t)||typeof t.version!=`string`||!/^\d+\.\d+$/.test(t.version))throw Error(`Missing or invalid format version`);return t.version.split(`.`)[0]===`1`?{status:`editable`,document:br(t,{onExcessProperty:`error`}),fileHash:wr(e),diagnostics:[]}:{status:`read-only`,raw:t,source:e,fileHash:wr(e),diagnostics:[Sr(`unknown-major`,`Unsupported design version ${t.version}`)]}}catch{return{status:`invalid`,source:e,diagnostics:[Sr(`invalid-schema`,`Invalid .p4design JSON or schema`)]}}}function Er(e,t){return xr({...e,...t},{onExcessProperty:`error`})}function Dr(e){let t=new Map,n=new Map,r=[],i=(i,a,o)=>{e.nodes[i]||r.push(Sr(`missing-node`,`Referenced node is missing`,a??i)),t.has(i)?r.push(Sr(`multiple-parents`,`Node occurs in more than one ordered child list`,i)):(t.set(i,a),n.set(i,o))};e.roots.forEach((e,t)=>i(e,null,t));for(let[t,n]of Object.entries(e.nodes))`children`in n&&n.children.forEach((e,n)=>i(e,t,n));for(let[t,n]of Object.entries(e.instances))for(let e of Object.values(n.slots))e.forEach((e,n)=>i(e,t,n));let a=new Set,o=new Set,s=(t,n)=>{if(a.has(t)){r.push(Sr(`tree-cycle`,`Child lists contain a cycle`,t));return}if(n>256){r.push(Sr(`depth-limit`,`Scene exceeds 256 levels`,t));return}if(o.has(t))return;a.add(t);let i=e.nodes[t];if(i&&`children`in i)for(let e of i.children)s(e,n+1);a.delete(t),o.add(t)};for(let t of Object.keys(e.nodes))s(t,0);return{parents:t,order:n,diagnostics:r}}function Or(e,t,n={},r=new Set){if(r.has(t))throw Error(`token-cycle`);if(r.size>=256)throw Error(`token-depth-limit`);let i=e.tokens[t];if(!i)throw Error(`missing-token`);let a=new Set(r).add(t),o=i.variants.filter(e=>Object.entries(e.theme).every(([e,t])=>n[e]===t));if(o.sort((e,t)=>Object.keys(t.theme).length-Object.keys(e.theme).length),o[0]&&o.some(e=>Object.keys(e.theme).length===Object.keys(o[0].theme).length&&Cr(e.value)!==Cr(o[0].value)))throw Error(`ambiguous-token`);let s=o[0]?.value??i.value,c=typeof s==`object`?Or(e,s.tokenId,n,a):s;if((i.kind===`number`?typeof c!=`number`:typeof c!=`string`)||i.kind===`color`&&(typeof c!=`string`||!/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(c)))throw Error(`token-type`);return c}function kr(e,t,n={}){return typeof t==`object`?Or(e,t.tokenId,n):t}function Ar(e,t={}){let n=[],r=(e,i,a,o,s,c,l)=>{let u=e.nodes[i];if(!u){n.push(Sr(`missing-node`,`Expansion target is missing`,o));return}if(l>256||s.has(`${e.documentId}/node/${i}`)){n.push(Sr(`component-cycle`,`Expansion contains a cycle or exceeds 256 levels`,o));return}let d=u;try{c[i]&&(d=Er(d,c[i]))}catch{n.push(Sr(`invalid-override`,`Override does not match its source node`,o))}let f=new Set(s).add(`${e.documentId}/node/${i}`);if(d.type===`ref`){let s=d.importId?e.imports[d.importId]:void 0,u=s?t.manifest?.libraries[s.libraryId]:void 0,p=d.importId?u?.exports.includes(d.componentId)&&s?t.documents?.[s.libraryId]:void 0:e,m=p?.components[d.componentId];if(!p||!m)return n.push(Sr(`missing-import`,`Component or exported library symbol is unavailable`,o)),{key:a,sourceId:i,ownerId:o,document:e,node:d,children:[]};let h=e.instances[i],g={...c,...h?.overrides},_=p===e?p:{...p,tokens:{...p.tokens,...e.tokens},themeAxes:{...p.themeAxes,...e.themeAxes}},v=r(_,m.rootId,`${a}/${m.rootId}`,o,f,g,l+1);if(!v)return;let y=t=>{let n=Object.entries(m.slots).find(([,e])=>e.nodeId===t.sourceId),i=n?h?.slots[n[0]]:void 0;return i?{...t,children:i.flatMap(n=>{let i=r(e,n,`${t.key}/slot/${n}`,o,f,{},l+1);return i?[i]:[]})}:{...t,children:t.children.map(y)}},{type:b,componentId:x,importId:S,...C}=d;return{...y(v),key:a,ownerId:o,node:{...v.node,...C}}}let p=`children`in d?d.children.flatMap(t=>{let n=r(e,t,`${a}/${t}`,o===i?t:o,f,c,l+1);return n?[n]:[]}):[];return{key:a,sourceId:i,ownerId:o,document:e,node:d,children:p}};return{roots:e.roots.flatMap(t=>{let n=r(e,t,t,t,new Set,{},0);return n?[n]:[]}),diagnostics:n}}function jr(e,t){let n=new Set(t),r=new Set(e.filter(e=>n.has(e.ownerId)).map(e=>e.key));return e.filter(e=>{let t=e.key;for(;t;){if(r.has(t))return!0;let e=t.lastIndexOf(`/`);if(e<0)break;t=t.slice(0,e)}return!1})}function Mr(e,t={},n={}){let r=Ar(e,n),i=[...r.diagnostics],a=[],o=(e,n)=>{try{let r=kr(e.document,n,t);if(typeof r!=`number`||!Number.isFinite(r))throw Error(`token-type`);return r}catch{return i.push(Sr(`invalid-layout-token`,`Layout value requires a finite number`,e.ownerId)),0}},s=new Map,c=e=>{let t=s.get(e.key);if(t)return t;let n=e.node,r=e.children.map(c),a=`layout`in n?n.layout:void 0,l=a?Object.fromEntries(Object.entries(a.padding).map(([t,n])=>[t,o(e,n)])):{top:0,right:0,bottom:0,left:0},u=a?o(e,a.gap):0,d=a?.direction??`none`,f=d===`horizontal`?r.reduce((e,t)=>e+t.width,0)+Math.max(0,r.length-1)*u:Math.max(0,...r.map(e=>e.width)),p=d===`vertical`?r.reduce((e,t)=>e+t.height,0)+Math.max(0,r.length-1)*u:Math.max(0,...r.map(e=>e.height));if(d===`none`&&(f=Math.max(0,...e.children.map((e,t)=>o(e,e.node.x)+r[t].width)),p=Math.max(0,...e.children.map((e,t)=>o(e,e.node.y)+r[t].height))),n.type===`text`){let t=o(e,n.fontSize),r=n.lineHeight?o(e,n.lineHeight):1.2,i=n.text.split(`
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{a as i,i as a,n as o,o as s,r as c,s as l,t as u}from"./collapsible-BYB8Vm7J.js";import{$l as d,$s as f,Ap as p,Bl as m,Cl as h,Di as g,Ei as _,El as v,Fi as y,G as b,Gl as x,H as S,Hi as C,Ii as w,Im as T,Js as E,Kl as D,Ks as O,Lf as k,Li as A,Lm as j,Mm as M,Ni as N,Ol as P,Pi as F,Pm as I,Qr as L,Qs as R,Rl as ee,S as z,Tl as B,Ul as te,Vh as ne,Vm as re,Vu as ie,W as ae,Wm as V,Xs as oe,Yl as se,Yp as ce,Ys as le,Zf as ue,Zs as de,_p as fe,al as pe,b as H,bl as me,cu as he,dt as ge,g as _e,gh as ve,gl as ye,gm as be,gp as xe,ii as Se,jp as Ce,ki as we,kl as U,kp as Te,ll as Ee,lu as De,mp as Oe,n as ke,ni as Ae,oc as je,ol as Me,op as Ne,ou as Pe,q as Fe,qc as Ie,qs as Le,r as Re,ri as ze,rl as Be,sh as Ve,su as He,t as Ue,th as We,ti as Ge,ut as Ke,v as qe,vp as Je,wc as Ye,x as Xe,xm as Ze,y as Qe,yl as $e,yp as et,zf as tt,zm as nt}from"./textarea-CWiSD-BA.js";import{t as rt}from"./env-jW24S9HL.js";import{C as it,k as at,w as ot,y as st}from"./entities-rFZO2CnH.js";import{n as ct,t as lt}from"./input-COb8u_Ms.js";import{$r as ut,Ar as dt,Bi as ft,C as pt,Ci as mt,Di as ht,E as gt,Ei as _t,Fi as vt,Fr as yt,G as bt,Ii as xt,Ir as St,J as Ct,Ji as wt,K as Tt,Ki as Et,Li as Dt,Mi as Ot,Mr as kt,Nr as At,Pi as jt,Pr as Mt,Qi as Nt,Qr as Pt,S as Ft,Si as It,T as Lt,Ti as Rt,U as zt,Vi as Bt,W as Vt,Wi as Ht,X as Ut,Xi as Wt,Y as Gt,Yr as Kt,Zi as qt,Zr as Jt,_ as Yt,_r as Xt,aa as Zt,b as Qt,bi as $t,ca as en,ei as tn,fa as nn,g as rn,ga as an,gr as on,h as sn,ha as cn,hr as ln,ii as un,ji as dn,jr as fn,m as pn,ma as mn,mr as hn,na as gn,ni as _n,pa as vn,pr as yn,q as bn,qi as xn,ri as Sn,sa as Cn,ti as wn,v as Tn,vr as En,w as Dn,wi as On,x as kn,xi as An,y as jn,yi as Mn}from"./index-BtOOP_4i.js";var Nn=R(`boxes`,[[`path`,{d:`M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z`,key:`lc1i9w`}],[`path`,{d:`m7 16.5-4.74-2.85`,key:`1o9zyk`}],[`path`,{d:`m7 16.5 5-3`,key:`va8pkn`}],[`path`,{d:`M7 16.5v5.17`,key:`jnp8gn`}],[`path`,{d:`M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z`,key:`8zsnat`}],[`path`,{d:`m17 16.5-5-3`,key:`8arw3v`}],[`path`,{d:`m17 16.5 4.74-2.85`,key:`8rfmw`}],[`path`,{d:`M17 16.5v5.17`,key:`k6z78m`}],[`path`,{d:`M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z`,key:`1xygjf`}],[`path`,{d:`M12 8 7.26 5.15`,key:`1vbdud`}],[`path`,{d:`m12 8 4.74-2.85`,key:`3rx089`}],[`path`,{d:`M12 13.5V8`,key:`1io7kd`}]]),Pn=R(`focus`,[[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}],[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}]]),Fn=R(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),In=R(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),Ln=R(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),Rn=R(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]),zn=R(`swatch-book`,[[`path`,{d:`M11 17a4 4 0 0 1-8 0V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2Z`,key:`1ldrpk`}],[`path`,{d:`M16.7 13H19a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2H7`,key:`11i5po`}],[`path`,{d:`M 7 17h.01`,key:`1euzgo`}],[`path`,{d:`m11 8 2.3-2.3a2.4 2.4 0 0 1 3.404.004L18.6 7.6a2.4 2.4 0 0 1 .026 3.434L9.9 19.8`,key:`o2gii7`}]]),Bn=R(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),W=r(),G=e(n(),1),K=t(),Vn=(0,G.createContext)(null);function Hn(e){let t=(0,W.c)(3),{host:n,children:r}=e,i=n,a;return t[0]!==r||t[1]!==i?(a=(0,K.jsx)(Vn,{value:i,children:r}),t[0]=r,t[1]=i,t[2]=a):a=t[2],a}function Un(){let e=(0,G.use)(Vn);if(!e)throw Error(`Design workspace rendered outside a DesignHostProvider`);return e}var Wn=m(se(!1)).pipe(te(`design-query:empty`));function Gn(e){let t=Ve(e);return t instanceof Error&&t.message.trim().length>0?t.message:`The environment request failed.`}function Kn(e){let t=(0,W.c)(10),n=e??Wn,r=pe(n),i=Be(n),a;t[0]===r?a=t[1]:(a=ne(d(r)),t[0]=r,t[1]=a);let o;t[2]!==r._tag||t[3]!==r.cause?(o=r._tag===`Failure`?Gn(r.cause):null,t[2]=r._tag,t[3]=r.cause,t[4]=o):o=t[4];let s=e!==null&&r.waiting,c;return t[5]!==i||t[6]!==a||t[7]!==o||t[8]!==s?(c={data:a,error:o,isPending:s,refresh:i},t[5]=i,t[6]=a,t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function qn(){let e=Un(),t=(0,G.useContext)(Me);return(0,G.useCallback)(async n=>{let r=e.runtime.atom(n),i=await T(j(Ze(function*(){return yield*D(t,r),yield*x(t,r,{suspendOnWaiting:!0})})));if(ve(i))throw Ve(i.cause);return i.value},[e,t])}function Jn(e){let t=(0,W.c)(71),{target:n,path:r,revision:i,fileHash:a,disabled:o}=e,{transport:s}=Un(),c=qn(),[l,u]=(0,G.useState)(!1),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(null),[h,g]=(0,G.useState)(null),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(0),S;t[0]!==l||t[1]!==r||t[2]!==c||t[3]!==n||t[4]!==s?(S=()=>{if(!l)return;let e=!0;return f(null),m(null),c(s.revisions(n,r)).then(t=>{e&&f(t)},()=>{e&&m(`Could not load revisions.`)}),()=>{e=!1}},t[0]=l,t[1]=r,t[2]=c,t[3]=n,t[4]=s,t[5]=S):S=t[5];let w;t[6]!==b||t[7]!==l||t[8]!==r||t[9]!==c||t[10]!==n||t[11]!==s?(w=[l,b,n,r,s,c],t[6]=b,t[7]=l,t[8]=r,t[9]=c,t[10]=n,t[11]=s,t[12]=w):w=t[12],(0,G.useEffect)(S,w);let T=o||v,E;t[13]===T?E=t[14]:(E=(0,K.jsx)(_,{size:`sm`,variant:`ghost`,disabled:T,"aria-label":`Design revisions`,className:`design-mono`}),t[13]=T,t[14]=E);let D;t[15]===i?D=t[16]:(D=i?.slice(0,8)??`unavailable`,t[15]=i,t[16]=D);let O;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,K.jsx)(oe,{"aria-hidden":`true`}),t[17]=O):O=t[17];let k;t[18]!==E||t[19]!==D?(k=(0,K.jsxs)(C,{render:E,children:[`Revision `,D,O]}),t[18]=E,t[19]=D,t[20]=k):k=t[20];let A;t[21]!==b||t[22]!==p||t[23]!==a||t[24]!==d?(A=p?(0,K.jsxs)(N,{onClick:()=>x(b+1),children:[p,` Retry`]}):d===null?(0,K.jsx)(N,{disabled:!0,children:`Loading revisions...`}):d.length===0?(0,K.jsx)(N,{disabled:!0,children:`No saved revisions yet`}):d.map(e=>(0,K.jsx)(N,{disabled:e.fileHash===a,onClick:()=>{m(null),g({entry:e,expectedFileHash:a})},children:(0,K.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,K.jsxs)(`span`,{className:`font-mono`,children:[e.revision.slice(0,8),e.fileHash===a?` · Current`:``]}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.savedAt).toLocaleString()})]})},e.id)),t[21]=b,t[22]=p,t[23]=a,t[24]=d,t[25]=A):A=t[25];let j;t[26]===A?j=t[27]:(j=(0,K.jsx)(F,{align:`start`,className:`max-h-80 overflow-y-auto`,children:A}),t[26]=A,t[27]=j);let M;t[28]!==l||t[29]!==k||t[30]!==j?(M=(0,K.jsxs)(we,{open:l,onOpenChange:u,children:[k,j]}),t[28]=l,t[29]=k,t[30]=j,t[31]=M):M=t[31];let P=h!==null,I;t[32]===v?I=t[33]:(I=e=>{!e&&!v&&(g(null),m(null))},t[32]=v,t[33]=I);let L;t[34]===h?.entry.revision?L=t[35]:(L=h?.entry.revision.slice(0,8),t[34]=h?.entry.revision,t[35]=L);let R;t[36]===L?R=t[37]:(R=(0,K.jsxs)(z,{children:[`Restore revision `,L,`?`]}),t[36]=L,t[37]=R);let ee;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,K.jsx)(qe,{children:`Replace this design with the saved version. Your current version stays in revision history. Libraries and assets are unchanged.`}),t[38]=ee):ee=t[38];let B;t[39]===p?B=t[40]:(B=p?(0,K.jsx)(`p`,{role:`alert`,className:`design-revision-error`,children:p}):null,t[39]=p,t[40]=B);let te;t[41]!==R||t[42]!==B?(te=(0,K.jsxs)(H,{children:[R,ee,B]}),t[41]=R,t[42]=B,t[43]=te):te=t[43];let ne;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(ne=()=>{g(null),m(null)},t[44]=ne):ne=t[44];let re;t[45]===v?re=t[46]:(re=(0,K.jsx)(_,{size:`sm`,variant:`ghost`,disabled:v,onClick:ne,children:`Cancel`}),t[45]=v,t[46]=re);let ie=v||o||!h,ae;t[47]!==v||t[48]!==r||t[49]!==c||t[50]!==h||t[51]!==n||t[52]!==s?(ae=()=>{!h||v||(y(!0),m(null),c(s.restoreRevision(n,r,h.entry.id,h.expectedFileHash)).then(()=>g(null),e=>m(e instanceof Error&&`code`in e&&e.code===`conflict`?`The design changed. Reopen revision history and try again.`:e instanceof Error&&`code`in e&&e.code===`invalid-document`?`This revision cannot be restored with the current libraries and assets.`:`Could not restore this revision. Reopen revision history and try again.`)).finally(()=>y(!1)))},t[47]=v,t[48]=r,t[49]=c,t[50]=h,t[51]=n,t[52]=s,t[53]=ae):ae=t[53];let V=v?`Restoring...`:`Restore revision`,se;t[54]!==ie||t[55]!==ae||t[56]!==V?(se=(0,K.jsx)(_,{size:`sm`,disabled:ie,onClick:ae,children:V}),t[54]=ie,t[55]=ae,t[56]=V,t[57]=se):se=t[57];let ce;t[58]!==re||t[59]!==se?(ce=(0,K.jsxs)(Qe,{children:[re,se]}),t[58]=re,t[59]=se,t[60]=ce):ce=t[60];let le;t[61]!==te||t[62]!==ce?(le=(0,K.jsxs)(Xe,{className:`max-w-md`,children:[te,ce]}),t[61]=te,t[62]=ce,t[63]=le):le=t[63];let ue;t[64]!==P||t[65]!==I||t[66]!==le?(ue=(0,K.jsx)(_e,{open:P,onOpenChange:I,children:le}),t[64]=P,t[65]=I,t[66]=le,t[67]=ue):ue=t[67];let de;return t[68]!==M||t[69]!==ue?(de=(0,K.jsxs)(K.Fragment,{children:[M,ue]}),t[68]=M,t[69]=ue,t[70]=de):de=t[70],de}var Yn=()=>null;function Xn({target:e,path:t,revision:n,compact:r=!1}){let{navigation:i}=Un(),a=(i.useWorkspaceRoot??Yn)(e),[o,s]=(0,G.useState)(null);if(!e||!a||!t||!n)return null;let c=En({projectRoot:a,documentPath:t,revision:n,...i.linkEnvironment?{environmentId:e.environmentId}:{}}),l=o?.link===c?o:null;return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,K.jsxs)(_,{size:`sm`,variant:r?`ghost`:`outline`,onClick:()=>{Promise.resolve().then(()=>navigator.clipboard.writeText(c)).then(()=>s({link:c,error:!1}),()=>s({link:c,error:!0}))},children:[(0,K.jsx)(qt,{"aria-hidden":`true`}),l&&!l.error?`Link copied`:r?`Copy link`:`Copy design link`]}),l?.error?(0,K.jsx)(`span`,{role:`alert`,className:`text-xs`,children:`Could not copy. Try again.`}):null,l&&!l.error?(0,K.jsx)(`span`,{role:`status`,className:`sr-only`,children:`Paste into a P4 Code thread in this project.`}):null]})}function Zn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function Qn(e,...t){if(!Zn(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function $n(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function er(e,t){Qn(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function tr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function nr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function rr(e,t){return e<<32-t|e>>>t}var ir=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,ar=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function or(e){if(Qn(e),ir)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=ar[e[n]];return t}function sr(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function cr(e){return typeof e==`string`&&(e=sr(e)),Qn(e),e}var lr=class{};function ur(e){let t=t=>e().update(cr(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function dr(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function fr(e,t,n){return e&t^~e&n}function pr(e,t,n){return e&t^e&n^t&n}var mr=class extends lr{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=nr(this.buffer)}update(e){$n(this),e=cr(e),Qn(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=nr(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){$n(this),er(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,tr(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;dr(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=nr(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},hr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),gr=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),_r=new Uint32Array(64),vr=class extends mr{constructor(e=32){super(64,e,8,!1),this.A=hr[0]|0,this.B=hr[1]|0,this.C=hr[2]|0,this.D=hr[3]|0,this.E=hr[4]|0,this.F=hr[5]|0,this.G=hr[6]|0,this.H=hr[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)_r[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=_r[e-15],n=_r[e-2],r=rr(t,7)^rr(t,18)^t>>>3;_r[e]=(rr(n,17)^rr(n,19)^n>>>10)+_r[e-7]+r+_r[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=rr(o,6)^rr(o,11)^rr(o,25),u=l+t+fr(o,s,c)+gr[e]+_r[e]|0,d=(rr(n,2)^rr(n,13)^rr(n,22))+pr(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){tr(_r)}destroy(){this.set(0,0,0,0,0,0,0,0),tr(this.buffer)}},yr=ur(()=>new vr),br=Te(He),xr=Te(De),Sr=(e,t,n,r=`error`)=>({code:e,message:t,severity:r,...n?{nodeId:n}:{}});function Cr(e){let t=e=>{if(e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e))return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t).join(`,`)}]`;if(typeof e==`object`&&e&&Object.getPrototypeOf(e)===Object.prototype){let n=e;return`{${Object.keys(n).sort().map(e=>`${JSON.stringify(e)}:${t(n[e])}`).join(`,`)}}`}throw Error(`Design JSON must contain only finite JSON values`)};return`${t(e)}\n`}function wr(e){return or(yr(typeof e==`string`?new TextEncoder().encode(e):e))}function Tr(e){try{let t=JSON.parse(e);if(typeof t!=`object`||!t||!(`version`in t)||typeof t.version!=`string`||!/^\d+\.\d+$/.test(t.version))throw Error(`Missing or invalid format version`);return t.version.split(`.`)[0]===`1`?{status:`editable`,document:br(t,{onExcessProperty:`error`}),fileHash:wr(e),diagnostics:[]}:{status:`read-only`,raw:t,source:e,fileHash:wr(e),diagnostics:[Sr(`unknown-major`,`Unsupported design version ${t.version}`)]}}catch{return{status:`invalid`,source:e,diagnostics:[Sr(`invalid-schema`,`Invalid .p4design JSON or schema`)]}}}function Er(e,t){return xr({...e,...t},{onExcessProperty:`error`})}function Dr(e){let t=new Map,n=new Map,r=[],i=(i,a,o)=>{e.nodes[i]||r.push(Sr(`missing-node`,`Referenced node is missing`,a??i)),t.has(i)?r.push(Sr(`multiple-parents`,`Node occurs in more than one ordered child list`,i)):(t.set(i,a),n.set(i,o))};e.roots.forEach((e,t)=>i(e,null,t));for(let[t,n]of Object.entries(e.nodes))`children`in n&&n.children.forEach((e,n)=>i(e,t,n));for(let[t,n]of Object.entries(e.instances))for(let e of Object.values(n.slots))e.forEach((e,n)=>i(e,t,n));let a=new Set,o=new Set,s=(t,n)=>{if(a.has(t)){r.push(Sr(`tree-cycle`,`Child lists contain a cycle`,t));return}if(n>256){r.push(Sr(`depth-limit`,`Scene exceeds 256 levels`,t));return}if(o.has(t))return;a.add(t);let i=e.nodes[t];if(i&&`children`in i)for(let e of i.children)s(e,n+1);a.delete(t),o.add(t)};for(let t of Object.keys(e.nodes))s(t,0);return{parents:t,order:n,diagnostics:r}}function Or(e,t,n={},r=new Set){if(r.has(t))throw Error(`token-cycle`);if(r.size>=256)throw Error(`token-depth-limit`);let i=e.tokens[t];if(!i)throw Error(`missing-token`);let a=new Set(r).add(t),o=i.variants.filter(e=>Object.entries(e.theme).every(([e,t])=>n[e]===t));if(o.sort((e,t)=>Object.keys(t.theme).length-Object.keys(e.theme).length),o[0]&&o.some(e=>Object.keys(e.theme).length===Object.keys(o[0].theme).length&&Cr(e.value)!==Cr(o[0].value)))throw Error(`ambiguous-token`);let s=o[0]?.value??i.value,c=typeof s==`object`?Or(e,s.tokenId,n,a):s;if((i.kind===`number`?typeof c!=`number`:typeof c!=`string`)||i.kind===`color`&&(typeof c!=`string`||!/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(c)))throw Error(`token-type`);return c}function kr(e,t,n={}){return typeof t==`object`?Or(e,t.tokenId,n):t}function Ar(e,t={}){let n=[],r=(e,i,a,o,s,c,l)=>{let u=e.nodes[i];if(!u){n.push(Sr(`missing-node`,`Expansion target is missing`,o));return}if(l>256||s.has(`${e.documentId}/node/${i}`)){n.push(Sr(`component-cycle`,`Expansion contains a cycle or exceeds 256 levels`,o));return}let d=u;try{c[i]&&(d=Er(d,c[i]))}catch{n.push(Sr(`invalid-override`,`Override does not match its source node`,o))}let f=new Set(s).add(`${e.documentId}/node/${i}`);if(d.type===`ref`){let s=d.importId?e.imports[d.importId]:void 0,u=s?t.manifest?.libraries[s.libraryId]:void 0,p=d.importId?u?.exports.includes(d.componentId)&&s?t.documents?.[s.libraryId]:void 0:e,m=p?.components[d.componentId];if(!p||!m)return n.push(Sr(`missing-import`,`Component or exported library symbol is unavailable`,o)),{key:a,sourceId:i,ownerId:o,document:e,node:d,children:[]};let h=e.instances[i],g={...c,...h?.overrides},_=p===e?p:{...p,tokens:{...p.tokens,...e.tokens},themeAxes:{...p.themeAxes,...e.themeAxes}},v=r(_,m.rootId,`${a}/${m.rootId}`,o,f,g,l+1);if(!v)return;let y=t=>{let n=Object.entries(m.slots).find(([,e])=>e.nodeId===t.sourceId),i=n?h?.slots[n[0]]:void 0;return i?{...t,children:i.flatMap(n=>{let i=r(e,n,`${t.key}/slot/${n}`,o,f,{},l+1);return i?[i]:[]})}:{...t,children:t.children.map(y)}},{type:b,componentId:x,importId:S,...C}=d;return{...y(v),key:a,ownerId:o,node:{...v.node,...C}}}let p=`children`in d?d.children.flatMap(t=>{let n=r(e,t,`${a}/${t}`,o===i?t:o,f,c,l+1);return n?[n]:[]}):[];return{key:a,sourceId:i,ownerId:o,document:e,node:d,children:p}};return{roots:e.roots.flatMap(t=>{let n=r(e,t,t,t,new Set,{},0);return n?[n]:[]}),diagnostics:n}}function jr(e,t){let n=new Set(t),r=new Set(e.filter(e=>n.has(e.ownerId)).map(e=>e.key));return e.filter(e=>{let t=e.key;for(;t;){if(r.has(t))return!0;let e=t.lastIndexOf(`/`);if(e<0)break;t=t.slice(0,e)}return!1})}function Mr(e,t={},n={}){let r=Ar(e,n),i=[...r.diagnostics],a=[],o=(e,n)=>{try{let r=kr(e.document,n,t);if(typeof r!=`number`||!Number.isFinite(r))throw Error(`token-type`);return r}catch{return i.push(Sr(`invalid-layout-token`,`Layout value requires a finite number`,e.ownerId)),0}},s=new Map,c=e=>{let t=s.get(e.key);if(t)return t;let n=e.node,r=e.children.map(c),a=`layout`in n?n.layout:void 0,l=a?Object.fromEntries(Object.entries(a.padding).map(([t,n])=>[t,o(e,n)])):{top:0,right:0,bottom:0,left:0},u=a?o(e,a.gap):0,d=a?.direction??`none`,f=d===`horizontal`?r.reduce((e,t)=>e+t.width,0)+Math.max(0,r.length-1)*u:Math.max(0,...r.map(e=>e.width)),p=d===`vertical`?r.reduce((e,t)=>e+t.height,0)+Math.max(0,r.length-1)*u:Math.max(0,...r.map(e=>e.height));if(d===`none`&&(f=Math.max(0,...e.children.map((e,t)=>o(e,e.node.x)+r[t].width)),p=Math.max(0,...e.children.map((e,t)=>o(e,e.node.y)+r[t].height))),n.type===`text`){let t=o(e,n.fontSize),r=n.lineHeight?o(e,n.lineHeight):1.2,i=n.text.split(`
|
|
2
2
|
`);f=Math.max(0,...i.map(e=>e.length))*t*.6,p=i.length*t*r}f+=l.left+l.right,p+=l.top+l.bottom;let m={width:n.width.mode===`fixed`?o(e,n.width.value):n.width.mode===`hug`?f:0,height:n.height.mode===`fixed`?o(e,n.height.value):n.height.mode===`hug`?p:0};for(let t of[`width`,`height`])m[t]<0&&(i.push(Sr(`negative-size`,`Dimensions cannot be negative`,e.ownerId)),m[t]=0),n[t].mode===`hug`&&e.children.some(e=>e.node[t].mode===`fill`)&&i.push(Sr(`layout-cycle`,`A hug dimension cannot contain fill on the same axis`,e.ownerId));return s.set(e.key,m),m},l=(e,t,n,r,i,s,u=!0)=>{let d={x:t,y:n,width:r,height:i},f=u&&e.node.visible!==!1;a.push({...e,node:{...e.node,visible:f},bounds:d,clips:s});let p=`layout`in e.node?e.node.layout:void 0,m=p?Object.fromEntries(Object.entries(p.padding).map(([t,n])=>[t,o(e,n)])):{top:0,right:0,bottom:0,left:0},h=p?o(e,p.gap):0,g=p?.direction??`none`,_={width:Math.max(0,r-m.left-m.right),height:Math.max(0,i-m.top-m.bottom)},v=g===`horizontal`?`width`:`height`,y=e.children.filter(e=>e.node[v].mode===`fill`).length,b=e.children.reduce((e,t)=>e+(t.node[v].mode===`fill`?0:c(t)[v]),0)+Math.max(0,e.children.length-1)*h,x=y?Math.max(0,_[v]-b)/y:0,S=0,C=e.node.type===`frame`&&e.node.clip?[...s,d]:s;for(let r of e.children){let e=c(r),i={width:r.node.width.mode===`fill`?g===`horizontal`?x:_.width:e.width,height:r.node.height.mode===`fill`?g===`vertical`?x:_.height:e.height},a=t+m.left+(g===`horizontal`?S:g===`none`?o(r,r.node.x):0),s=n+m.top+(g===`vertical`?S:g===`none`?o(r,r.node.y):0);l(r,a,s,i.width,i.height,C,f),S+=i[v]+h}};for(let e of r.roots){let t=c(e);(e.node.width.mode===`fill`||e.node.height.mode===`fill`)&&i.push(Sr(`root-fill`,`Root dimensions need fixed or hug sizing`,e.ownerId)),l(e,o(e,e.node.x),o(e,e.node.y),t.width,t.height,[])}return{items:a,diagnostics:i}}function Nr(e,t){let n=[],r=(e,t,i)=>{if(e===void 0){n.push({path:i,kind:`added`,after:t});return}if(t===void 0){n.push({path:i,kind:`removed`,before:e});return}if(Cr(e)!==Cr(t))if(e&&t&&typeof e==`object`&&typeof t==`object`&&!Array.isArray(e)&&!Array.isArray(t)){let n=e,a=t;for(let e of[...new Set([...Object.keys(n),...Object.keys(a)])].sort())r(n[e],a[e],`${i}/${e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}`)}else n.push({path:i,kind:`changed`,before:e,after:t})};return r(e,t,``),n}function Pr(e){let t=(0,W.c)(11),{label:n,onClick:r,children:i}=e,a;t[0]!==n||t[1]!==r?(a=(0,K.jsx)(_,{size:`icon-sm`,variant:`ghost`,"aria-label":n,onClick:r}),t[0]=n,t[1]=r,t[2]=a):a=t[2];let o;t[3]!==i||t[4]!==a?(o=(0,K.jsx)(Fe,{render:a,children:i}),t[3]=i,t[4]=a,t[5]=o):o=t[5];let s;t[6]===n?s=t[7]:(s=(0,K.jsx)(b,{children:n}),t[6]=n,t[7]=s);let c;return t[8]!==o||t[9]!==s?(c=(0,K.jsxs)(ae,{children:[o,s]}),t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function Fr(e){let t=(0,W.c)(27),{title:n,heading:r,card:i,thread:a,hostLabel:o,onOpenThread:c,onCollapse:l}=e,u=n===void 0?`Design agent`:n,d;t[0]!==r||t[1]!==u?(d=r??(0,K.jsxs)(`h2`,{children:[(0,K.jsx)(Wt,{"aria-hidden":`true`,size:16}),u]}),t[0]=r,t[1]=u,t[2]=d):d=t[2];let f;t[3]===o?f=t[4]:(f=o?(0,K.jsx)(`span`,{className:`design-small-muted`,children:o}):null,t[3]=o,t[4]=f);let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,K.jsx)(`span`,{className:`design-agent-header-spacer`}),t[5]=p):p=t[5];let m;t[6]===c?m=t[7]:(m=c?(0,K.jsx)(Pr,{label:`Open full thread`,onClick:c,children:(0,K.jsx)(vn,{"aria-hidden":`true`})}):null,t[6]=c,t[7]=m);let h;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,K.jsx)(s,{"aria-hidden":`true`}),t[8]=h):h=t[8];let g;t[9]===l?g=t[10]:(g=(0,K.jsx)(Pr,{label:`Hide agent`,onClick:l,children:h}),t[9]=l,t[10]=g);let _;t[11]!==d||t[12]!==f||t[13]!==m||t[14]!==g?(_=(0,K.jsxs)(`header`,{className:`design-agent-header`,children:[d,f,p,m,g]}),t[11]=d,t[12]=f,t[13]=m,t[14]=g,t[15]=_):_=t[15];let v;t[16]===i?v=t[17]:(v=i?(0,K.jsx)(`div`,{className:`design-agent-card`,children:i}):null,t[16]=i,t[17]=v);let y;t[18]===a?y=t[19]:(y=a??(0,K.jsx)(`p`,{className:`design-agent-empty`,children:`Open this design from a thread to talk to the agent.`}),t[18]=a,t[19]=y);let b;t[20]===y?b=t[21]:(b=(0,K.jsx)(`div`,{className:`design-agent-thread`,children:y}),t[20]=y,t[21]=b);let x;return t[22]!==b||t[23]!==_||t[24]!==v||t[25]!==u?(x=(0,K.jsxs)(`aside`,{className:`design-agent`,"aria-label":u,children:[_,v,b]}),t[22]=b,t[23]=_,t[24]=v,t[25]=u,t[26]=x):x=t[26],x}function Ir(e){let t=(0,W.c)(3),{onOpen:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,K.jsx)(Wt,{"aria-hidden":`true`}),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,K.jsxs)(_,{size:`sm`,variant:`outline`,className:`design-float-pill`,onClick:n,children:[r,`Agent`]}),t[1]=n,t[2]=i),i}function Lr(e,t,n,r,i=0){if(!e.length)return{x:0,y:0,width:t,height:n};let a=Math.min(...e.map(e=>e.x)),o=Math.min(...e.map(e=>e.y)),s=Math.max(...e.map(e=>e.x+e.width)),c=Math.max(...e.map(e=>e.y+e.height)),l=r===`workspace`?{left:32,right:32+i,top:72,bottom:72}:{left:56,right:24,top:56,bottom:100},u=Math.max(40,t-l.left-l.right),d=Math.max(40,n-l.top-l.bottom),f=Math.max(1,s-a),p=Math.max(1,c-o),m=Math.max(.05,Math.min(2,u/f,d/p));return{x:a-(l.left+(u-f*m)/2)/m,y:o-(l.top+(d-p*m)/2)/m,width:t/m,height:n/m}}var Rr=(e,t,n)=>Math.min(Math.max(e,t),n),zr=(e,t)=>e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height;function Br(e,t,n,r={top:60,right:12,bottom:12,left:12},i={below:32,above:12},a=null){if(e.x+e.width<0||e.x>n.width||e.y+e.height<0||e.y>n.height)return null;let o=e=>Rr(e,r.left,Math.max(r.left,n.width-r.right-t.width)),s=o(e.x+e.width/2-t.width/2),c=n.height-r.bottom,l=Math.max(r.top,e.y+e.height+i.below),u=e.y-i.above-t.height,d=[];l+t.height<=c&&d.push({x:s,y:l,side:`below`}),u>=r.top&&d.push({x:s,y:u,side:`above`});let f={x:s,y:Rr(l,r.top,Math.max(r.top,c-t.height)),side:`below`};if(!a)return d[0]??f;let p=e=>!zr({...e,width:t.width,height:t.height},a),m=[...d,f],h=m.flatMap(e=>[{...e,x:o(a.x-i.above-t.width)},{...e,x:o(a.x+a.width+i.above)}]);return[...m,...h].find(p)??d[0]??f}var Vr={width:280,height:110};function Hr(e,t,n,r=null,i=Vr){let a=(t,r,a)=>({side:r,placement:a,reach:r===`left`?e.x-t.x:t.x+t.width-(e.x+e.width),fits:r===`right`?t.x+t.width+i.width<=n.width:t.x>=i.width,box:{x:r===`right`?t.x+t.width:t.x-i.width,y:e.y,width:i.width,height:i.height}}),o=[...t?[a(t,`right`,`margin`),a(t,`left`,`margin`)]:[],a(e,`right`,`node`),a(e,`left`,`node`)],s=o.filter(e=>e.fits),c=s.find(e=>!r||!zr(e.box,r))??s[0]??o.at(-2);return{side:c.side,placement:c.placement,reach:Math.max(0,c.reach)}}var Ur=Math.PI/180;function Wr(){return typeof window<`u`&&({}.toString.call(window)===`[object Window]`||{}.toString.call(window)===`[object global]`)}var Gr=typeof global<`u`?global:typeof window<`u`?window:typeof WorkerGlobalScope<`u`?self:{},q={_global:Gr,version:`10.7.1`,isBrowser:Wr(),isUnminified:/param/.test(function(e){}.toString()),dblClickWindow:400,getAngle(e){return q.angleDeg?e*Ur:e},enableTrace:!1,pointerEventsEnabled:!0,autoDrawEnabled:!0,hitOnDragEnabled:!1,capturePointerEventsEnabled:!1,_renderBackend:`web`,legacyTextRendering:!1,pixelRatio:typeof window<`u`&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging(){return q.DD.isDragging},isTransforming(){return q.Transformer?.isTransforming()??!1},isDragReady(){return!!q.DD.node},releaseCanvasOnDestroy:!0,document:Gr.document,_injectGlobal(e){Gr.Konva!==void 0&&console.error(`Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment.`),Gr.Konva=e}},Kr=new Set,qr=(e,t=!1)=>{q[e.prototype.getClassName()]=e,t&&Kr.add(e)};q._injectGlobal(q);var Jr=`Konva.js unsupported environment.
|
|
3
3
|
|
|
4
4
|
Looks like you are trying to use Konva.js in Node.js environment (or in a Web Worker), because "document" object is undefined.
|
|
@@ -16,4 +16,4 @@ js: import "konva/skia-backend";
|
|
|
16
16
|
`),t=+this.fontSize(),n=this.lineHeight()*t,r=this.attrs.width,i=this.attrs.height,a=r!==xs&&r!==void 0,o=i!==xs&&i!==void 0,s=this.padding(),c=r-s*2,l=i-s*2,u=0,d=this.wrap(),f=d!==Bs&&d!==Vs,p=this.ellipsis(),m=this.measureSize(`M`);this._baselineShift=(m.fontBoundingBoxAscent-m.fontBoundingBoxDescent)/2,this.textArr=[];let h=Js();h.font=this._getContextFont(),h.fontKerning=this.direction()!==Rs&&(this.letterSpacing()!==0||this.align()===ws||this.charRenderFunc())?`none`:`auto`;let g=p?this._getTextWidth(Hs):0;for(let t=0,r=e.length;t<r;++t){let i=e[t],s=this._getTextWidth(i);if(a&&s>c){let e=bs(i),a=e.length,d=0,m=t=>e.slice(d,t).join(``),h=e=>e===Is||e===Ds,_=Math.max(1,Math.ceil(a*c/s));for(;d<a;){let i=p&&o&&u+n>l?g:0,s=e=>!(this._getTextWidth(m(e),e-d)+i>c),v=d,y=Math.min(a,d+_);for(;s(y)&&(v=y,y!==a);)y=Math.min(a,y+(y-d));for(;y-v>1;){let e=v+y>>>1;s(e)?v=e:y=e}if(v===d)break;if(v===a){this._addTextLine(m(a)),u+=n,o&&u+n>l&&t<r-1&&this._tryToAddEllipsisToLastLine();break}if(f&&!h(e[v])){let t=v-1;for(;t>=d&&!h(e[t]);)t--;t>=d&&(v=t+1)}if(this._addTextLine(m(v).trimRight()),u+=n,this._shouldHandleEllipsis(u)){this._tryToAddEllipsisToLastLine();break}for(d=v;d<a&&!e[d].trim();)d++}}else this._addTextLine(i),u+=n,o&&u+n>l&&t<r-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),o&&u+n>l)break}this.textHeight=t,this.textWidth=this.textArr.reduce((e,t)=>Math.max(e,t.width),0)}_shouldHandleEllipsis(e){let t=+this.fontSize(),n=this.lineHeight()*t,r=this.attrs.height,i=r!==xs&&r!==void 0,a=r-this.padding()*2;return this.wrap()===Vs||i&&e+n>a}_tryToAddEllipsisToLastLine(){let e=this.attrs.width,t=e!==xs&&e!==void 0,n=e-this.padding()*2,r=this.ellipsis(),i=this.textArr[this.textArr.length-1];if(!i||!r)return;let a=i.text+Hs;if(t){let e=bs(i.text);for(;e.length&&this._getTextWidth(a)>n;)e.pop(),a=e.join(``)+Hs;this._getTextWidth(a)>n&&(a=``)}i.text=a,i.width=this._getTextWidth(a)}getStrokeScaleEnabled(){return!0}_getStrokePadding(){return super._getStrokePadding(2)}_useBufferCanvas(e,t=this.getAbsoluteOpacity()){if(this.attrs.perfectDrawEnabled===!1)return!1;let n=this.textDecoration().indexOf(`underline`)!==-1||this.textDecoration().indexOf(`line-through`)!==-1,r=this.hasShadow();return n&&r||r&&t!==1&&Gs()?!0:super._useBufferCanvas(e,t)}};Qs.prototype._fillFunc=Ys,Qs.prototype._strokeFunc=Xs,Qs.prototype.className=As,Qs.prototype._attrsAffectingSize=Us.filter(e=>e!==`width`&&e!==`height`).concat([`textDecoration`,`underlineOffset`]),qr(Qs,!0),Qs.prototype.on(Us.map(e=>e+Ts).join(` `),function(){this._setTextData()}),X.overWriteSetter(Qs,`width`,$i()),X.overWriteSetter(Qs,`height`,$i()),X.addGetterSetter(Qs,`direction`,Cs),X.addGetterSetter(Qs,`fontFamily`,`Arial`),X.addGetterSetter(Qs,`fontSize`,12,Y()),X.addGetterSetter(Qs,`fontStyle`,Ps),X.addGetterSetter(Qs,`fontVariant`,Ps),X.addGetterSetter(Qs,`padding`,0,Y()),X.addGetterSetter(Qs,`align`,Os),X.addGetterSetter(Qs,`verticalAlign`,js),X.addGetterSetter(Qs,`lineHeight`,1,Y()),X.addGetterSetter(Qs,`wrap`,zs),X.addGetterSetter(Qs,`ellipsis`,!1,ra()),X.addGetterSetter(Qs,`letterSpacing`,0,Y()),X.addGetterSetter(Qs,`text`,``,ea()),X.addGetterSetter(Qs,`textDecoration`,``),X.addGetterSetter(Qs,`underlineOffset`,void 0,Y()),X.addGetterSetter(Qs,`charRenderFunc`,void 0);var $s=[...Qs.prototype._attrsAffectingSize,`width`,`height`,`pointerDirection`,`pointerWidth`,`pointerHeight`].map(e=>e+`Change.konva`).join(` `),ec=`none`,tc=`up`,nc=`right`,rc=`down`,ic=`left`,ac=class extends Po{constructor(e){super(e),this._sync=this._sync.bind(this),this.on(`add.konva`,function(e){e.child.off($s,this._sync).on($s,this._sync),this._sync()})}getText(){return this.find(`Text`)[0]}getTag(){return this.find(`Tag`)[0]}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let e=this.getText(),t=this.getTag(),n,r,i,a,o,s,c;if(e&&t){switch(n=e.width(),r=e.height(),i=t.pointerDirection(),a=t.pointerWidth(),c=t.pointerHeight(),o=0,s=0,i){case tc:o=n/2,s=-1*c;break;case nc:o=n+a,s=r/2;break;case rc:o=n/2,s=r+c;break;case ic:o=-1*a,s=r/2;break}t.setAttrs({x:-1*o,y:-1*s,width:n,height:r}),e.setAttrs({x:-1*o,y:-1*s})}}};ac.prototype.className=`Label`,qr(ac);var oc=class extends Q{_sceneFunc(e){let t=this.width(),n=this.height(),r=this.pointerDirection(),i=this.pointerWidth(),a=this.pointerHeight(),o=this.cornerRadius(),[s,c,l,u]=J._cornerRadii(o,t,n);e.beginPath(),e.moveTo(s,0),r===tc&&(e.lineTo((t-i)/2,0),e.lineTo(t/2,-1*a),e.lineTo((t+i)/2,0)),e.lineTo(t-c,0),e.arc(t-c,c,c,Math.PI*3/2,0,!1),r===nc&&(e.lineTo(t,(n-a)/2),e.lineTo(t+i,n/2),e.lineTo(t,(n+a)/2)),e.lineTo(t,n-l),e.arc(t-l,n-l,l,0,Math.PI/2,!1),r===rc&&(e.lineTo((t+i)/2,n),e.lineTo(t/2,n+a),e.lineTo((t-i)/2,n)),e.lineTo(u,n),e.arc(u,n-u,u,Math.PI/2,Math.PI,!1),r===ic&&(e.lineTo(0,(n+a)/2),e.lineTo(-1*i,n/2),e.lineTo(0,(n-a)/2)),e.lineTo(0,s),e.arc(s,s,s,Math.PI,Math.PI*3/2,!1),e.closePath(),e.fillStrokeShape(this)}getSelfRect(){let e=this.pointerWidth(),t=this.pointerHeight(),n=this.pointerDirection(),r=this.width(),i=this.height();return n===tc||n===rc?{x:Math.min(0,(r-e)/2),y:n===tc?-t:0,width:Math.max(r,e),height:i+t}:n===ic||n===nc?{x:n===ic?-e:0,y:Math.min(0,(i-t)/2),width:r+e,height:Math.max(i,t)}:{x:0,y:0,width:r,height:i}}};oc.prototype.className=`Tag`,qr(oc,!0),X.addGetterSetter(oc,`pointerDirection`,ec),X.addGetterSetter(oc,`pointerWidth`,0,Y()),X.addGetterSetter(oc,`pointerHeight`,0,Y()),X.addGetterSetter(oc,`cornerRadius`,0,Qi(4));var sc=class extends Q{_getStrokePadding(){return super._getStrokePadding(this.strokeScaleEnabled()?1:void 0)}_sceneFunc(e){let t=this.cornerRadius(),n=this.width(),r=this.height();e.beginPath(),t?J.drawRoundedRectPath(e,n,r,t):e.rect(0,0,n,r),e.closePath(),e.fillStrokeShape(this)}};sc.prototype.className=`Rect`,qr(sc,!0),X.addGetterSetter(sc,`cornerRadius`,0,Qi(4));var cc=class extends Q{_sceneFunc(e){let t=this._getPoints(),n=this.radius(),r=this.sides(),i=this.cornerRadius();if(t.length){if(e.beginPath(),i)J.drawRoundedPolygonPath(e,t,r,n,i);else{e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y)}e.closePath(),e.fillStrokeShape(this)}}_getPoints(){let e=this.attrs.sides,t=this.attrs.radius||0,n=[];for(let r=0;r<e;r++)n.push({x:t*Math.sin(r*2*Math.PI/e),y:-1*t*Math.cos(r*2*Math.PI/e)});return n}getSelfRect(){let e=this._getPoints();if(!e.length)return{x:0,y:0,width:0,height:0};let t=e[0].x,n=e[0].x,r=e[0].y,i=e[0].y;return e.forEach(e=>{t=Math.min(t,e.x),n=Math.max(n,e.x),r=Math.min(r,e.y),i=Math.max(i,e.y)}),{x:t,y:r,width:n-t,height:i-r}}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius(e/2)}setHeight(e){this.radius(e/2)}};cc.prototype.className=`RegularPolygon`,cc.prototype._centroid=!0,cc.prototype._attrsAffectingSize=[`radius`,`sides`],qr(cc,!0),X.addGetterSetter(cc,`radius`,0,Y()),X.addGetterSetter(cc,`sides`,0,Y()),X.addGetterSetter(cc,`cornerRadius`,0,Qi(4));var lc=Math.PI*2,uc=class extends Q{_getStrokePadding(){return super._getStrokePadding(1)}_sceneFunc(e){let t=Math.abs(this.innerRadius()),n=Math.abs(this.outerRadius());e.beginPath(),e.arc(0,0,t,0,lc,!1),e.moveTo(n,0),e.arc(0,0,n,lc,0,!0),e.closePath(),e.fillStrokeShape(this)}getSelfRect(){let e=Math.max(Math.abs(this.innerRadius()),Math.abs(this.outerRadius()));return{x:-e,y:-e,width:e*2,height:e*2}}getWidth(){return Math.abs(this.outerRadius())*2}getHeight(){return Math.abs(this.outerRadius())*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}};uc.prototype.className=`Ring`,uc.prototype._centroid=!0,uc.prototype._attrsAffectingSize=[`innerRadius`,`outerRadius`],qr(uc,!0),X.addGetterSetter(uc,`innerRadius`,0,Y()),X.addGetterSetter(uc,`outerRadius`,0,Y());var dc=class extends Q{constructor(e){super(e),this._updated=!0,this.anim=new Io(()=>{let e=this._updated;return this._updated=!1,e}),this.on(`animationChange.konva`,function(){this.frameIndex(0)}),this.on(`frameIndexChange.konva`,function(){this._updated=!0}),this.on(`frameRateChange.konva`,function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_getFrame(){let e=this.animation(),t=this.animations()?.[e],n=this.frameIndex(),r=n*4;if(!t||!Number.isInteger(n)||r<0||r+4>t.length)return;let i=this.frameOffsets()?.[e]||[];return{x:t[r],y:t[r+1],width:t[r+2],height:t[r+3],offsetX:i[n*2]||0,offsetY:i[n*2+1]||0}}_getStrokePadding(){return super._getStrokePadding(this.strokeScaleEnabled()?1:void 0)}_sceneFunc(e){let t=this._getFrame();if(!t)return;let{x:n,y:r,width:i,height:a,offsetX:o,offsetY:s}=t,c=this.image();(this.hasFill()||this.hasStroke())&&(e.beginPath(),e.rect(o,s,i,a),e.closePath(),e.fillStrokeShape(this)),c&&e.drawImage(c,n,r,i,a,o,s,i,a)}_hitFunc(e){let{x:t,y:n,width:r,height:i}=this.getSelfRect();e.beginPath(),e.rect(t,n,r,i),e.closePath(),e.fillShape(this)}getSelfRect(){let e=this._getFrame();return e?{x:e.offsetX,y:e.offsetY,width:e.width,height:e.height}:{x:0,y:0,width:0,height:0}}_useBufferCanvas(e,t=this.getAbsoluteOpacity()){return super._useBufferCanvas(!0,t)}_setInterval(){let e=this;this.interval=setInterval(function(){e._updateIndex()},1e3/this.frameRate())}start(){if(this.isRunning())return;let e=this.getLayer();this.anim.setLayers(e),this._setInterval(),this.anim.start()}stop(){this.anim.stop(),clearInterval(this.interval)}destroy(){return this.stop(),super.destroy()}isRunning(){return this.anim.isRunning()}_updateIndex(){let e=this.frameIndex(),t=this.animations()?.[this.animation()],n=t?t.length/4:0;this.frameIndex(e<n-1?e+1:0)}};dc.prototype.className=`Sprite`,qr(dc,!0),X.addGetterSetter(dc,`animation`),X.addGetterSetter(dc,`animations`),X.addGetterSetter(dc,`frameOffsets`),X.addGetterSetter(dc,`image`),X.addGetterSetter(dc,`frameIndex`,0,Y()),X.addGetterSetter(dc,`frameRate`,17,Y()),X.backCompat(dc,{index:`frameIndex`,getIndex:`getFrameIndex`,setIndex:`setFrameIndex`});var fc=class extends Q{_sceneFunc(e){let t=this.innerRadius(),n=this.outerRadius(),r=this.numPoints();e.beginPath(),e.moveTo(0,0-n);for(let i=1;i<r*2;i++){let a=i%2==0?n:t,o=a*Math.sin(i*Math.PI/r),s=-1*a*Math.cos(i*Math.PI/r);e.lineTo(o,s)}e.closePath(),e.fillStrokeShape(this)}getSelfRect(){let e=Math.max(Math.abs(this.innerRadius()),Math.abs(this.outerRadius()));return{x:-e,y:-e,width:e*2,height:e*2}}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}};fc.prototype.className=`Star`,fc.prototype._centroid=!0,fc.prototype._attrsAffectingSize=[`innerRadius`,`outerRadius`],qr(fc,!0),X.addGetterSetter(fc,`numPoints`,5,Y()),X.addGetterSetter(fc,`innerRadius`,0,Y()),X.addGetterSetter(fc,`outerRadius`,0,Y());var pc=``,mc=`normal`;function hc(e){e.fillText(this.partialText,0,0)}function gc(e){e.strokeText(this.partialText,0,0)}var _c=class extends Q{constructor(e){super(e),this.dataArray=[],this._readDataAttribute(),this._setTextData()}_getTextPathLength(){return ps.getPathLength(this.dataArray)}_getPointAtLength(e,t){return!this.attrs.data||e>this.pathLength?null:ps.getPointAtLengthOfDataArray(e,this.dataArray,t)}_readDataAttribute(){this.dataArray=ps.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(e){e.setAttr(`font`,this._getContextFont()),e.setAttr(`textBaseline`,this.textBaseline()),e.setAttr(`textAlign`,`left`),e.save();let t=this.textDecoration(),n=this.fill(),r=this.fontSize(),i=this.glyphInfo,a=t.indexOf(`underline`)!==-1,o=t.indexOf(`line-through`)!==-1;a&&e.beginPath();for(let t=0;t<i.length;t++){e.save();let n=i[t].p0;e.translate(n.x,n.y),e.rotate(i[t].rotation),this.partialText=i[t].text,e.fillStrokeShape(this),a&&(t===0&&e.moveTo(0,r/2+1),e.lineTo(i[t].width,r/2+1)),e.restore()}if(a&&(e.strokeStyle=n,e.lineWidth=ys(r),e.stroke()),o){e.beginPath();for(let t=0;t<i.length;t++){e.save();let n=i[t].p0;e.translate(n.x,n.y),e.rotate(i[t].rotation),t===0&&e.moveTo(0,0),e.lineTo(i[t].width,0),e.restore()}e.strokeStyle=n,e.lineWidth=ys(r),e.stroke()}e.restore()}_hitFunc(e){e.beginPath();let t=this.glyphInfo;if(t.length>=1){let n=t[0].p0;e.moveTo(n.x,n.y)}for(let n=0;n<t.length;n++){let r=t[n].p1;e.lineTo(r.x,r.y)}e.setAttr(`lineWidth`,this.fontSize()),e.setAttr(`strokeStyle`,this.colorKey),e.stroke()}getTextWidth(){return this.textWidth}getTextHeight(){return J.warn(`text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.`),this.textHeight}setText(e){return Qs.prototype.setText.call(this,e)}_getContextFont(){return Qs.prototype._getContextFont.call(this)}_getTextSize(e){let t=Js();t.save(),t.font=this._getContextFont(),t.fontKerning=`auto`;let n=t.measureText(e);return t.restore(),{width:n.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){let e=bs(this.text());this.direction()===`rtl`&&e.reverse();let t=this.kerningFunc(),n=[],r=0;for(let i=0;i<e.length;i++){let a=0;if(t&&i>0)try{a=t(e[i-1],e[i])*this.fontSize()}catch{}n.push({char:e[i],width:this._getTextSize(e[i]).width,kern:a}),r+=n[i].width+a}let{width:i,height:a}=this._getTextSize(this.attrs.text);if(this.textWidth=r,this.textHeight=a,this.glyphInfo=[],!this.attrs.data)return null;let o=this.letterSpacing(),s=this.align(),c=s===`justify`?this.text().split(` `).length-1:0,l=Math.max(0,r-i),u=Math.max(this.textWidth+(e.length-1)*o,0),d=0;s===`center`&&(d=Math.max(0,this.pathLength/2-u/2)),s===`right`&&(d=Math.max(0,this.pathLength-u));let f=d,p=this.dataArray.some((e,t)=>t>0&&e.command===`M`)?void 0:{index:0,offset:0};for(let t=0;t<n.length;t++){f+=n[t].kern;let r=this._getPointAtLength(f,p);if(!r)return;let i=n[t].char,a=n[t].width+(t<n.length-1?o:0);i===` `&&s===`justify`&&(a+=(this.pathLength-u)/c);let d=f+a,m=this._getPointAtLength(d>this.pathLength&&d-this.pathLength<=l?this.pathLength:d,p);if(!m)return;let h=ps.getLineLength(r.x,r.y,m.x,m.y),g=Math.atan2(m.y-r.y,m.x-r.x);this.glyphInfo.push({text:e[t],rotation:g,p0:r,p1:m,width:h}),f+=a}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};let e=[];this.glyphInfo.forEach(function(t){e.push(t.p0.x),e.push(t.p0.y),e.push(t.p1.x),e.push(t.p1.y)});let t=J._getPointsRect(e),n=this.fontSize();return{x:t.x-n/2,y:t.y-n/2,width:t.width+n,height:t.height+n}}getStrokeScaleEnabled(){return!0}_getSelfRectForDrawing(){let e=this.getSelfRect(),t=this.fontSize();return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}};_c.prototype._fillFunc=hc,_c.prototype._strokeFunc=gc,_c.prototype._fillFuncHit=hc,_c.prototype._strokeFuncHit=gc,_c.prototype.className=`TextPath`,_c.prototype._attrsAffectingSize=[`text`,`fontSize`,`data`,`align`,`letterSpacing`,`kerningFunc`,`fontFamily`,`fontStyle`,`fontVariant`,`direction`],qr(_c,!0),_c.prototype.on(`dataChange.konva`,function(){this._readDataAttribute(),this._setTextData()}),_c.prototype.on(_c.prototype._attrsAffectingSize.filter(e=>e!==`data`).map(e=>e+`Change.konva`).join(` `),function(){this._setTextData()}),X.addGetterSetter(_c,`data`),X.addGetterSetter(_c,`fontFamily`,`Arial`),X.addGetterSetter(_c,`fontSize`,12,Y()),X.addGetterSetter(_c,`fontStyle`,mc),X.addGetterSetter(_c,`align`,`left`),X.addGetterSetter(_c,`letterSpacing`,0,Y()),X.addGetterSetter(_c,`textBaseline`,`middle`),X.addGetterSetter(_c,`fontVariant`,mc),X.addGetterSetter(_c,`text`,pc),X.addGetterSetter(_c,`textDecoration`,``),X.addGetterSetter(_c,`kerningFunc`,void 0),X.addGetterSetter(_c,`direction`,`inherit`);var vc=`tr-konva`,yc=[`resizeEnabledChange`,`rotateAnchorOffsetChange`,`rotateAnchorAngleChange`,`rotateEnabledChange`,`enabledAnchorsChange`,`anchorSizeChange`,`borderEnabledChange`,`shouldOverdrawWholeAreaChange`,`borderStrokeChange`,`borderStrokeWidthChange`,`borderDashChange`,`anchorStrokeChange`,`anchorStrokeWidthChange`,`anchorFillChange`,`anchorCornerRadiusChange`,`ignoreStrokeChange`,`anchorStyleFuncChange`,`paddingChange`].map(e=>e+`.${vc}`).join(` `),bc=`nodesRect`,xc=[`widthChange`,`heightChange`,`scaleXChange`,`scaleYChange`,`skewXChange`,`skewYChange`,`rotationChange`,`offsetXChange`,`offsetYChange`,`transformsEnabledChange`,`strokeWidthChange`,`strokeChange`,`selfRectFuncChange`,`strokeLinearGradientColorStopsChange`,`strokeScaleEnabledChange`,`strokeEnabledChange`,`draggableChange`],Sc={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},Cc=`ontouchstart`in q._global;function wc(e,t,n){if(e===`rotater`)return n;t+=J.degToRad(Sc[e]||0);let r=(J.radToDeg(t)%360+360)%360;return J._inRange(r,337.5,360)||J._inRange(r,0,22.5)?`ns-resize`:J._inRange(r,22.5,67.5)?`nesw-resize`:J._inRange(r,67.5,112.5)?`ew-resize`:J._inRange(r,112.5,157.5)?`nwse-resize`:J._inRange(r,157.5,202.5)?`ns-resize`:J._inRange(r,202.5,247.5)?`nesw-resize`:J._inRange(r,247.5,292.5)?`ew-resize`:J._inRange(r,292.5,337.5)?`nwse-resize`:(J.error(`Transformer has unknown angle for cursor detection: `+r),`pointer`)}var Tc=[`top-left`,`top-center`,`top-right`,`middle-right`,`middle-left`,`bottom-left`,`bottom-center`,`bottom-right`];function Ec(e){return{x:e.x+e.width/2*Math.cos(e.rotation)+e.height/2*Math.sin(-e.rotation),y:e.y+e.height/2*Math.cos(e.rotation)+e.width/2*Math.sin(e.rotation)}}function Dc(e,t,n){let r=n.x+(e.x-n.x)*Math.cos(t)-(e.y-n.y)*Math.sin(t),i=n.y+(e.x-n.x)*Math.sin(t)+(e.y-n.y)*Math.cos(t);return{...e,rotation:e.rotation+t,x:r,y:i}}function Oc(e,t){return Dc(e,t,Ec(e))}function kc(e,t,n){let r=t,i=n;for(let n=0;n<e.length;n++){let a=q.getAngle(e[n]),o=Math.abs(a-t)%(Math.PI*2),s=Math.min(o,Math.PI*2-o);s<i&&(i=s,r=a)}return r}function Ac(e,t,n){let r=J.degToRad(e.rotateAnchorAngle()),i=Math.sin(r),a=-Math.cos(r),o=t/2,s=n/2,c=1/0;a<0?c=Math.min(c,-s/a):a>0&&(c=Math.min(c,(n-s)/a)),i<0?c=Math.min(c,-o/i):i>0&&(c=Math.min(c,(t-o)/i));let l=o+i*c,u=s+a*c,d=e.rotateAnchorOffset()+e.padding();return{edgeX:l,edgeY:u,endX:l+i*d,endY:u+a*d}}var jc=new Set,$=class extends Po{static _isLayerTransforming(e){for(let t of jc)if(t.getLayer()===e||t._nodes.some(t=>t.getLayer()===e))return!0;return!1}constructor(e){super(e),this._movingAnchorName=null,this._anchors={},this._transforming=!1,this._fitting=!1,this._transformWindow=null,this._elementsCreated=!1,this._updateScheduled=!1,this._subtreeChanged=!1,this._createElements(),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(yc,e=>{e.type===`ignoreStrokeChange`&&this._resetTransformCache(),this.update()}),this.on(`rotationChange.${vc}`,()=>this._clearCache(bc)),this.getNode()&&this.update()}attachTo(e){return this.setNode(e),this}setNode(e){return J.warn(`tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead.`),this.setNodes([e])}getNode(){return this._nodes&&this._nodes[0]}_getEventNamespace(){return vc+this._id}setNodes(e=[]){this._nodes&&this._nodes.length&&this.detach();let t=new Set(e);for(let e of t)e.isAncestorOf(this)&&(J.error(`Konva.Transformer cannot be an a child of the node you are trying to attach`),t.delete(e));let n=Array.from(t).filter(e=>{for(let n=e.getParent();n;n=n.getParent())if(t.has(n))return!1;return!0});return this._nodes=e=n,e.length===1&&this.useSingleNodeRotation()?this.rotation(e[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(e=>{let t=()=>{var t;if(this._fitting){(t=this._nodeRectCache)==null||t.delete(e);return}this.nodes().length===1&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(e),this.isDragging()||this._scheduleUpdate()};if(e._attrsAffectingSize.length){let n=e._attrsAffectingSize.map(e=>e+`Change.`+this._getEventNamespace()).join(` `);e.on(n,t)}e.on(xc.map(e=>e+`.${this._getEventNamespace()}`).join(` `),t),e.on(`absoluteTransformChange.${this._getEventNamespace()}`,t),e instanceof Ta&&e._addSubtreeObserver(this),e.on(`destroy.${this._getEventNamespace()}`,()=>{this.setNodes(this._nodes.filter(t=>t!==e))}),this._proxyDrag(e)}),this._resetTransformCache(),this._elementsCreated&&this.update(),this}_proxyDrag(e){let t;e.on(`dragstart.${this._getEventNamespace()}`,n=>{t=e.getAbsolutePosition(),!this.isDragging()&&e!==this._back&&this.startDrag(n,!1)}),e.on(`dragmove.${this._getEventNamespace()}`,n=>{if(!t)return;let r=e.getAbsolutePosition(),i=r.x-t.x,a=r.y-t.y;this.nodes().forEach(t=>{if(t===e||t.isDragging())return;let r=t.getAbsolutePosition();t.setAbsolutePosition({x:r.x+i,y:r.y+a}),t.startDrag(n)}),t=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){var e;this._nodes&&this._nodes.forEach(e=>{e.off(`.`+this._getEventNamespace()),e._removeSubtreeObserver(this)}),this._nodes=[],this._resetTransformCache(),(e=this.getLayer())==null||e.batchDraw()}_resetTransformCache(e){var t,n;e?(t=this._nodeRectCache)==null||t.delete(e):(n=this._nodeRectCache)==null||n.clear(),this._clearCache(bc),this._clearCache(`transform`),this._clearSelfAndDescendantCache(`absoluteTransform`)}_onSubtreeChange(e){var t;this._fitting||this._subtreeChanged&&!this._cache[bc]||(this._resetTransformCache(e),this._subtreeChanged||(this._subtreeChanged=!0,J.requestAnimFrame(()=>this._syncSubtreeChange(),this.getStage()?._getOwnerWindow()),(t=this.getLayer())==null||t.batchDraw()))}_syncSubtreeChange(){this._subtreeChanged&&this._nodes?.length&&!this.isDragging()&&this._update()}drawScene(e,t){return this._syncSubtreeChange(),super.drawScene(e,t)}drawHit(e,t){return this._syncSubtreeChange(),super.drawHit(e,t)}_getNodeRect(){return this._getCache(bc,this.__getNodeRect)}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};let e=q.getAngle(this.rotation()),t=this.ignoreStroke(),n=new Xr;n.rotate(-e);let r=this._nodeRectCache||=new Map,i=1/0,a=1/0,o=-1/0,s=-1/0;for(let c of this.nodes()){let l=c instanceof Q&&c.getSelfRect===Q.prototype.getSelfRect&&!c.attrs.selfRectFunc&&!c._hasCachedAncestor(),u=l?c.width():0,d=l?c.height():0;l&&(c._attrsVersion??=0);let f=l?r.get(c):void 0;if(!f||f.rotation!==e||f.ignoreStroke!==t||f.version!==c._attrsVersion||f.width!==u||f.height!==d){let i=c.getAbsoluteTransform(),[a,o,s,p]=i.getMatrix(),m=a*p-o*s===0,h=c.getClientRect({skipTransform:!m,skipShadow:!0,skipStroke:t}),g=[{x:h.x,y:h.y},{x:h.x+h.width,y:h.y},{x:h.x+h.width,y:h.y+h.height},{x:h.x,y:h.y+h.height}];m&&(i=new Xr),f={rotation:e,ignoreStroke:t,width:u,height:d,version:c._attrsVersion||0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};for(let e of g){let t=n.point(i.point(e));f.minX=Math.min(f.minX,t.x),f.minY=Math.min(f.minY,t.y),f.maxX=Math.max(f.maxX,t.x),f.maxY=Math.max(f.maxY,t.y)}l&&r.set(c,f)}i=Math.min(i,f.minX),a=Math.min(a,f.minY),o=Math.max(o,f.maxX),s=Math.max(s,f.maxY)}n.invert();let c=n.point({x:i,y:a});return{x:c.x,y:c.y,width:o-i,height:s-a,rotation:q.getAngle(this.rotation())}}getX(){return this._getNodeRect().x}getY(){return this._getNodeRect().y}getWidth(){return this._getNodeRect().width}getHeight(){return this._getNodeRect().height}_createElements(){this._createBack(),Tc.forEach(e=>{this._createAnchor(e)}),this._createAnchor(`rotater`),this._elementsCreated=!0}_createAnchor(e){let t=new sc({stroke:`rgb(0, 161, 255)`,fill:`white`,strokeWidth:1,name:e+` _anchor`,dragDistance:0,draggable:!0,hitStrokeWidth:Cc?10:`auto`});this._anchors[e]=t;let n=this;t.on(`mousedown touchstart`,function(e){n._handleMouseDown(e)}),t.on(`dragstart`,e=>{t.stopDrag(),e.cancelBubble=!0}),t.on(`dragend`,e=>{e.cancelBubble=!0}),t.on(`mouseenter`,()=>{if(this.isTransforming())return;let n=wc(e,q.getAngle(this.rotation()),this.rotateAnchorCursor());t.getStage().content&&(t.getStage().content.style.cursor=n),this._cursorChange=!0}),t.on(`mouseout`,()=>{this._cursorChange=!1,!this.isTransforming()&&t.getStage().content&&(t.getStage().content.style.cursor=``)}),this.add(t)}_createBack(){let e=new Q({name:`back`,width:0,height:0,sceneFunc(e,t){let n=t.getParent();if(!n.borderEnabled())return;let r=n.padding(),i=t.width(),a=t.height();if(e.beginPath(),e.rect(-r,-r,i+r*2,a+r*2),n.rotateEnabled()&&n.rotateLineVisible()){let t=Ac(n,i,a);e.moveTo(t.edgeX,t.edgeY),e.lineTo(t.endX,t.endY)}e.fillStrokeShape(t)},hitFunc:(e,t)=>{if(!this.shouldOverdrawWholeArea())return;let n=this.padding();e.beginPath(),e.rect(-n,-n,t.width()+n*2,t.height()+n*2),e.fillStrokeShape(t)}});this._back=e,this.add(e),this._proxyDrag(e),e.on(`dragstart`,e=>{e.cancelBubble=!0}),e.on(`dragmove`,e=>{e.cancelBubble=!0}),e.on(`dragend`,e=>{e.cancelBubble=!0}),this.on(`dragmove`,e=>{this.update()})}_handleMouseDown(e){if(e.evt.button!==void 0&&!q.dragButtons.includes(e.evt.button)||this._transforming)return;this._movingAnchorName=e.target.name().split(` `)[0];let t=this._getNodeRect(),n=t.width,r=t.height,i=Math.sqrt(n**2+r**2);this.sin=Math.abs(r/i),this.cos=Math.abs(n/i);let a=this.getStage()?._getOwnerWindow();this._transformWindow=a||null,a&&(a.addEventListener(`mousemove`,this._handleMouseMove),a.addEventListener(`touchmove`,this._handleMouseMove),a.addEventListener(`mouseup`,this._handleMouseUp,!0),a.addEventListener(`touchend`,this._handleMouseUp,!0),a.addEventListener(`touchcancel`,this._handleMouseUp,!0)),this._transforming=!0,this._pointerId=e.pointerId??J._getFirstPointerId(e.evt);let o=e.target.getAbsolutePosition(),s=e.target.getStage()._getPointerById(this._pointerId);this._anchorDragOffset={x:s.x-o.x,y:s.y-o.y},jc.add(this),this._fire(`transformstart`,{evt:e.evt,target:this.getNode()}),this._nodes.forEach(t=>{t._fire(`transformstart`,{evt:e.evt,target:t})})}_handleMouseMove(e){var t;(t=this.getStage())==null||t._batchEvents(()=>this._moveTransform(e))}_moveTransform(e){this._syncSubtreeChange();let t,n,r,i=this._anchors[this._movingAnchorName],a=i.getStage();a.setPointersPositions(e);let o=a._getPointerById(this._pointerId);if(!o)return;let s={x:o.x-this._anchorDragOffset.x,y:o.y-this._anchorDragOffset.y},c=i.getAbsolutePosition();this.anchorDragBoundFunc()&&(s=this.anchorDragBoundFunc()(c,s,e)),i.setAbsolutePosition(s);let l=i.getAbsolutePosition();if(c.x===l.x&&c.y===l.y)return;if(this._movingAnchorName===`rotater`){let r=this._getNodeRect();t=i.x()-r.width/2,n=-i.y()+r.height/2;let a=J.degToRad(this.rotateAnchorAngle()),o=Math.atan2(-n,t)+Math.PI/2-a,s=q.getAngle(this.rotation())+o,c=q.getAngle(this.rotationSnapTolerance()),l=Oc(r,kc(this.rotationSnaps(),s,c)-r.rotation);this._fitNodesInto(l,e);return}let u=this.shiftBehavior(),d;d=u===`inverted`?this.keepRatio()&&!e.shiftKey:u===`none`?this.keepRatio():this.keepRatio()||e.shiftKey;let f=this.centeredScaling()||e.altKey,p=!1;if(this._movingAnchorName===`top-left`){if(d){p=!0;let e=f?{x:this.width()/2,y:this.height()/2}:{x:this._anchors[`bottom-right`].x(),y:this._anchors[`bottom-right`].y()};r=Math.sqrt((e.x-i.x())**2+(e.y-i.y())**2);let a=this._anchors[`top-left`].x()>e.x?-1:1,o=this._anchors[`top-left`].y()>e.y?-1:1;t=r*this.cos*a,n=r*this.sin*o,this._anchors[`top-left`].x(e.x-t),this._anchors[`top-left`].y(e.y-n)}}else if(this._movingAnchorName===`top-center`)this._anchors[`top-left`].y(i.y());else if(this._movingAnchorName===`top-right`){if(d){p=!0;let e=f?{x:this.width()/2,y:this.height()/2}:{x:this._anchors[`bottom-left`].x(),y:this._anchors[`bottom-left`].y()};r=Math.sqrt((i.x()-e.x)**2+(e.y-i.y())**2);let a=this._anchors[`top-right`].x()<e.x?-1:1,o=this._anchors[`top-right`].y()>e.y?-1:1;t=r*this.cos*a,n=r*this.sin*o,this._anchors[`top-right`].x(e.x+t),this._anchors[`top-right`].y(e.y-n)}var m=i.position();this._anchors[`top-left`].y(m.y),this._anchors[`bottom-right`].x(m.x)}else if(this._movingAnchorName===`middle-left`)this._anchors[`top-left`].x(i.x());else if(this._movingAnchorName===`middle-right`)this._anchors[`bottom-right`].x(i.x());else if(this._movingAnchorName===`bottom-left`){if(d){p=!0;let e=f?{x:this.width()/2,y:this.height()/2}:{x:this._anchors[`top-right`].x(),y:this._anchors[`top-right`].y()};r=Math.sqrt((e.x-i.x())**2+(i.y()-e.y)**2);let a=e.x<i.x()?-1:1,o=i.y()<e.y?-1:1;t=r*this.cos*a,n=r*this.sin*o,i.x(e.x-t),i.y(e.y+n)}m=i.position(),this._anchors[`top-left`].x(m.x),this._anchors[`bottom-right`].y(m.y)}else if(this._movingAnchorName===`bottom-center`)this._anchors[`bottom-right`].y(i.y());else if(this._movingAnchorName===`bottom-right`){if(d){p=!0;let e=f?{x:this.width()/2,y:this.height()/2}:{x:this._anchors[`top-left`].x(),y:this._anchors[`top-left`].y()};r=Math.sqrt((i.x()-e.x)**2+(i.y()-e.y)**2);let a=this._anchors[`bottom-right`].x()<e.x?-1:1,o=this._anchors[`bottom-right`].y()<e.y?-1:1;t=r*this.cos*a,n=r*this.sin*o,this._anchors[`bottom-right`].x(e.x+t),this._anchors[`bottom-right`].y(e.y+n)}}else console.error(Error(`Wrong position argument of selection resizer: `+this._movingAnchorName));if(f=this.centeredScaling()||e.altKey,f){let e=this._anchors[`top-left`],t=this._anchors[`bottom-right`],n=e.x(),r=e.y(),i=this.getWidth()-t.x(),a=this.getHeight()-t.y();t.move({x:-n,y:-r}),e.move({x:i,y:a})}let h=this._anchors[`top-left`].getAbsolutePosition();t=h.x,n=h.y;let g=this._anchors[`bottom-right`].x()-this._anchors[`top-left`].x(),_=this._anchors[`bottom-right`].y()-this._anchors[`top-left`].y();this._fitNodesInto({x:t,y:n,width:g,height:_,rotation:q.getAngle(this.rotation())},e,p)}_handleMouseUp(e){let t=this.getStage();t&&(t.setPointersPositions(e),!t._changedPointerPositions.some(e=>e.id===this._pointerId))||(t?t._batchEvents(()=>this._removeEvents(e)):this._removeEvents(e))}getAbsoluteTransform(e){let t=this.getTransform();return e?e.getAbsoluteTransform().copy().invert().multiply(t):t}_removeEvents(e){var t;if(this._transforming){this._transforming=!1;let n=this.getStage()?.content;n&&!this._cursorChange&&(n.style.cursor=``);let r=this._transformWindow;this._transformWindow=null,r&&(r.removeEventListener(`mousemove`,this._handleMouseMove),r.removeEventListener(`touchmove`,this._handleMouseMove),r.removeEventListener(`mouseup`,this._handleMouseUp,!0),r.removeEventListener(`touchend`,this._handleMouseUp,!0),r.removeEventListener(`touchcancel`,this._handleMouseUp,!0));let i=this.getNode();jc.delete(this),this._fire(`transformend`,{evt:e,target:i}),(t=this.getLayer())==null||t.batchDraw(),i&&this._nodes.forEach(t=>{var n;t._fire(`transformend`,{evt:e,target:t}),(n=t.getLayer())==null||n.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(e,t,n=!1){this._fitting=!0;try{return this._doFitNodesInto(e,t,n)}finally{this._fitting=!1}}_doFitNodesInto(e,t,n=!1){let r=this._getNodeRect();if(!r.width||!r.height||J._inRange(e.width,-this.padding()*2-1,1)||J._inRange(e.height,-this.padding()*2-1,1)){this.update();return}let i=new Xr;i.rotate(q.getAngle(this.rotation()));let a=n?0:this.padding()*2,o=null,s=null;if(this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf(`left`)>=0){let t=i.point({x:-a,y:0});e.x+=t.x,e.y+=t.y,e.width+=a,o={axis:`width`,from:`left`,to:`right`,offset:t}}else if(this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf(`right`)>=0){let t=i.point({x:a,y:0});e.width+=a,o={axis:`width`,from:`right`,to:`left`,offset:t}}if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf(`top`)>=0){let t=i.point({x:0,y:-a});e.x+=t.x,e.y+=t.y,e.height+=a,s={axis:`height`,from:`top`,to:`bottom`,offset:t}}else if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf(`bottom`)>=0){let t=i.point({x:0,y:a});e.height+=a,s={axis:`height`,from:`bottom`,to:`top`,offset:t}}if(this.boundBoxFunc()){let t=this.boundBoxFunc()(r,e);t?e=t:J.warn(`boundBoxFunc returned falsy. You should return new bound rect from it!`)}for(let t of[o,s])t&&e[t.axis]<0&&this._movingAnchorName&&(this._movingAnchorName=this._movingAnchorName.replace(t.from,t.to),this._anchorDragOffset.x-=t.offset.x,this._anchorDragOffset.y-=t.offset.y);let c=1e7,l=new Xr;l.translate(r.x,r.y),l.rotate(r.rotation),l.scale(r.width/c,r.height/c);let u=new Xr,d=e.width/c,f=e.height/c;this.flipEnabled()===!1?(u.translate(e.x,e.y),u.rotate(e.rotation),u.translate(e.width<0?e.width:0,e.height<0?e.height:0),u.scale(Math.abs(d),Math.abs(f))):(u.translate(e.x,e.y),u.rotate(e.rotation),u.scale(d,f));let p=u.multiply(l.invert()),m=new Set;this._nodes.forEach(e=>{if(!e.getStage())return;let t=e.getParent().getAbsoluteTransform(),n=e.getTransform().copy();n.translate(e.offsetX(),e.offsetY());let r=new Xr;r.multiply(t.copy().invert()).multiply(p).multiply(t).multiply(n);let i=r.decompose();e.setAttrs(i);let a=e.getLayer();a&&m.add(a)}),this.rotation(J._getRotation(e.rotation)),this._nodes.forEach(e=>{this._fire(`transform`,{evt:t,target:e}),e._fire(`transform`,{evt:t,target:e})}),this._resetTransformCache(),this.update(),m.add(this.getLayer()),m.forEach(e=>e&&e.batchDraw())}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=!0,Z._runAfterAbsTransformCascade(()=>{this._updateScheduled=!1,!(!this._nodes?.length||this._fitting||this.isDragging())&&this._update()}))}forceUpdate(){this._resetTransformCache(),this.update()}update(){this._lastNodeRect=void 0,this._update()}_update(){var e;this._subtreeChanged=!1;let t=this._getNodeRect();this._updateElements(t);let n=this.nodes().some(e=>e.draggable());this._back.draggable()!==n&&this._back.draggable(n);let r=this.anchorStyleFunc();r&&Object.values(this._anchors).forEach(e=>r(e)),(e=this.getLayer())==null||e.batchDraw()}_updateElements(e){let t=this._lastNodeRect;if(t&&!this.anchorStyleFunc()&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height&&e.rotation===t.rotation)return;this._lastNodeRect={...e};let n=e.width,r=e.height,i=this.enabledAnchors(),a=this.resizeEnabled(),o=this.padding(),s=this.anchorSize();Object.values(this._anchors).forEach(e=>{e.setAttrs({width:s,height:s,offsetX:s/2,offsetY:s/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._anchors[`top-left`].setAttrs({x:0,y:0,offsetX:s/2+o,offsetY:s/2+o,visible:a&&i.indexOf(`top-left`)>=0}),this._anchors[`top-center`].setAttrs({x:n/2,y:0,offsetY:s/2+o,visible:a&&i.indexOf(`top-center`)>=0}),this._anchors[`top-right`].setAttrs({x:n,y:0,offsetX:s/2-o,offsetY:s/2+o,visible:a&&i.indexOf(`top-right`)>=0}),this._anchors[`middle-left`].setAttrs({x:0,y:r/2,offsetX:s/2+o,visible:a&&i.indexOf(`middle-left`)>=0}),this._anchors[`middle-right`].setAttrs({x:n,y:r/2,offsetX:s/2-o,visible:a&&i.indexOf(`middle-right`)>=0}),this._anchors[`bottom-left`].setAttrs({x:0,y:r,offsetX:s/2+o,offsetY:s/2-o,visible:a&&i.indexOf(`bottom-left`)>=0}),this._anchors[`bottom-center`].setAttrs({x:n/2,y:r,offsetY:s/2-o,visible:a&&i.indexOf(`bottom-center`)>=0}),this._anchors[`bottom-right`].setAttrs({x:n,y:r,offsetX:s/2-o,offsetY:s/2-o,visible:a&&i.indexOf(`bottom-right`)>=0});let c=Ac(this,n,r);this._anchors.rotater.setAttrs({x:c.endX,y:c.endY,visible:this.rotateEnabled()}),this._back.setAttrs({width:n,height:r,visible:this.borderEnabled()||this.shouldOverdrawWholeArea(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),x:0,y:0})}isTransforming(){return this._transforming}stopTransform(){this._transforming&&this._removeEvents()}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=``),Po.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}add(...e){return this._elementsCreated?(J.error(`You cannot add external nodes to the Transformer. Use tr.nodes([node]) instead.`),this):super.add(...e)}toObject(){return Z.prototype.toObject.call(this)}clone(e){return Z.prototype.clone.call(this,e)}getClientRect(e){return this.nodes().length>0?super.getClientRect(e):{x:0,y:0,width:0,height:0}}};$.isTransforming=()=>jc.size>0;function Mc(e){return e instanceof Array||J.warn(`enabledAnchors value should be an array`),e instanceof Array&&e.forEach(function(e){Tc.indexOf(e)===-1&&J.warn(`Unknown anchor name: `+e+`. Available names are: `+Tc.join(`, `))}),e||[]}$.prototype.className=`Transformer`,qr($),X.addGetterSetter($,`enabledAnchors`,Tc,Mc),X.addGetterSetter($,`flipEnabled`,!0,ra()),X.addGetterSetter($,`resizeEnabled`,!0),X.addGetterSetter($,`anchorSize`,10,Y()),X.addGetterSetter($,`rotateEnabled`,!0),X.addGetterSetter($,`rotateLineVisible`,!0),X.addGetterSetter($,`rotationSnaps`,[]),X.addGetterSetter($,`rotateAnchorOffset`,50,Y()),X.addGetterSetter($,`rotateAnchorAngle`,0,Y()),X.addGetterSetter($,`rotateAnchorCursor`,`crosshair`),X.addGetterSetter($,`rotationSnapTolerance`,5,Y()),X.addGetterSetter($,`borderEnabled`,!0),X.addGetterSetter($,`anchorStroke`,`rgb(0, 161, 255)`),X.addGetterSetter($,`anchorStrokeWidth`,1,Y()),X.addGetterSetter($,`anchorFill`,`white`),X.addGetterSetter($,`anchorCornerRadius`,0,Y()),X.addGetterSetter($,`borderStroke`,`rgb(0, 161, 255)`),X.addGetterSetter($,`borderStrokeWidth`,1,Y()),X.addGetterSetter($,`borderDash`),X.addGetterSetter($,`keepRatio`,!0),X.addGetterSetter($,`shiftBehavior`,`default`),X.addGetterSetter($,`centeredScaling`,!1),X.addGetterSetter($,`ignoreStroke`,!1),X.addGetterSetter($,`padding`,0,Y()),X.addGetterSetter($,`nodes`),X.addGetterSetter($,`node`),X.addGetterSetter($,`boundBoxFunc`),X.addGetterSetter($,`anchorDragBoundFunc`),X.addGetterSetter($,`anchorStyleFunc`),X.addGetterSetter($,`shouldOverdrawWholeArea`,!1),X.addGetterSetter($,`useSingleNodeRotation`,!0),X.backCompat($,{lineEnabled:`borderEnabled`,rotateHandlerOffset:`rotateAnchorOffset`,enabledHandlers:`enabledAnchors`});var Nc=class extends Q{_sceneFunc(e){e.beginPath(),e.arc(0,0,Math.abs(this.radius()),0,q.getAngle(this.angle()),this.clockwise()),e.lineTo(0,0),e.closePath(),e.fillStrokeShape(this)}getWidth(){return Math.abs(this.radius())*2}getHeight(){return Math.abs(this.radius())*2}setWidth(e){this.radius(e/2)}setHeight(e){this.radius(e/2)}};Nc.prototype.className=`Wedge`,Nc.prototype._centroid=!0,Nc.prototype._attrsAffectingSize=[`radius`],qr(Nc,!0),X.addGetterSetter(Nc,`radius`,0,Y()),X.addGetterSetter(Nc,`angle`,0,Y()),X.addGetterSetter(Nc,`clockwise`,!1),X.backCompat(Nc,{angleDeg:`angle`,getAngleDeg:`getAngle`,setAngleDeg:`setAngle`});function Pc(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var Fc=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],Ic=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function Lc(e,t){return t===255?e:e*t/255}var Rc=180;function zc(e,t){let n=e.data,r=e.width,i=e.height,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=t+t+1,E=r-1,D=i-1,O=t+1,k=O*(O+1)/2,A=new Pc,j=t<=Rc?Fc[t]/2**Ic[t]:1/(O*O),M=null,N=A,P=null,F=null;for(let e=1;e<T;e++)N=N.next=new Pc,e===O&&(M=N);N.next=A,s=o=0;for(let e=0;e<i;e++){g=_=v=y=c=l=u=d=0,C=n[o+3],b=Lc(n[o],C),x=Lc(n[o+1],C),S=Lc(n[o+2],C),f=O*b,p=O*x,m=O*S,h=O*C,c+=k*b,l+=k*x,u+=k*S,d+=k*C,N=A;for(let e=0;e<O;e++)N.r=b,N.g=x,N.b=S,N.a=C,N=N.next;for(let e=1;e<O;e++)a=o+((E<e?E:e)<<2),C=n[a+3],c+=(N.r=b=Lc(n[a],C))*(w=O-e),l+=(N.g=x=Lc(n[a+1],C))*w,u+=(N.b=S=Lc(n[a+2],C))*w,d+=(N.a=C)*w,g+=b,_+=x,v+=S,y+=C,N=N.next;P=A,F=M;for(let e=0;e<r;e++)n[o]=Math.floor(c*j),n[o+1]=Math.floor(l*j),n[o+2]=Math.floor(u*j),n[o+3]=Math.floor(d*j),c-=f,l-=p,u-=m,d-=h,f-=P.r,p-=P.g,m-=P.b,h-=P.a,a=s+((a=e+t+1)<E?a:E)<<2,C=n[a+3],g+=P.r=Lc(n[a],C),_+=P.g=Lc(n[a+1],C),v+=P.b=Lc(n[a+2],C),y+=P.a=C,c+=g,l+=_,u+=v,d+=y,P=P.next,f+=b=F.r,p+=x=F.g,m+=S=F.b,h+=C=F.a,g-=b,_-=x,v-=S,y-=C,F=F.next,o+=4;s+=r}for(let e=0;e<r;e++){_=v=y=g=l=u=d=c=0,o=e<<2,f=O*(b=n[o]),p=O*(x=n[o+1]),m=O*(S=n[o+2]),h=O*(C=n[o+3]),c+=k*b,l+=k*x,u+=k*S,d+=k*C,N=A;for(let e=0;e<O;e++)N.r=b,N.g=x,N.b=S,N.a=C,N=N.next;let s=Math.min(1,D)*r;for(let i=1;i<=t;i++)o=s+e<<2,c+=(N.r=b=n[o])*(w=O-i),l+=(N.g=x=n[o+1])*w,u+=(N.b=S=n[o+2])*w,d+=(N.a=C=n[o+3])*w,g+=b,_+=x,v+=S,y+=C,N=N.next,i<D&&(s+=r);o=e,P=A,F=M;for(let t=0;t<i;t++)a=o<<2,n[a+3]=C=Math.floor(d*j),C>0?(C=255/C,n[a]=Math.floor(c*j)*C,n[a+1]=Math.floor(l*j)*C,n[a+2]=Math.floor(u*j)*C):n[a]=n[a+1]=n[a+2]=0,c-=f,l-=p,u-=m,d-=h,f-=P.r,p-=P.g,m-=P.b,h-=P.a,a=e+((a=t+O)<D?a:D)*r<<2,c+=g+=P.r=n[a],l+=_+=P.g=n[a+1],u+=v+=P.b=n[a+2],d+=y+=P.a=n[a+3],P=P.next,f+=b=F.r,p+=x=F.g,m+=S=F.b,h+=C=F.a,g-=b,_-=x,v-=S,y-=C,F=F.next,o+=r}}var Bc=function(e,t=1){let n=Math.round(Math.min(this.blurRadius(),Rc)*t);n>0&&zc(e,n)};X.addGetterSetter(Z,`blurRadius`,0,Y(),X.afterSetFilter);var Vc=function(e){let t=this.brightness()*255,n=e.data,r=n.length;for(let e=0;e<r;e+=4)n[e]+=t,n[e+1]+=t,n[e+2]+=t};X.addGetterSetter(Z,`brightness`,0,Y(),X.afterSetFilter);var Hc=function(e){let t=this.attrs.brightness===void 0?1:this.brightness(),n=e.data,r=n.length;for(let e=0;e<r;e+=4)n[e]=Math.min(255,n[e]*t),n[e+1]=Math.min(255,n[e+1]*t),n[e+2]=Math.min(255,n[e+2]*t)},Uc=function(e){let t=((this.contrast()+100)/100)**2,n=e.data,r=n.length,i=150,a=150,o=150;for(let e=0;e<r;e+=4)i=n[e],a=n[e+1],o=n[e+2],i/=255,i-=.5,i*=t,i+=.5,i*=255,a/=255,a-=.5,a*=t,a+=.5,a*=255,o/=255,o-=.5,o*=t,o+=.5,o*=255,i=i<0?0:i>255?255:i,a=a<0?0:a>255?255:a,o=o<0?0:o>255?255:o,n[e]=i,n[e+1]=a,n[e+2]=o};X.addGetterSetter(Z,`contrast`,0,Y(),X.afterSetFilter);var Wc=function(e){let t=e.data,n=e.width,r=e.height,i=Math.min(1,Math.max(0,this.embossStrength?.call(this)??.5)),a=Math.min(1,Math.max(0,this.embossWhiteLevel?.call(this)??.5)),o={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[this.embossDirection?.call(this)??`top-left`]??315,s=!!(this.embossBlend?.call(this)??!1),c=i*10,l=a*255,u=o*Math.PI/180,d=Math.cos(u),f=Math.sin(u),p=128/1020*c,m=new Float32Array(n*r);for(let e=0,n=0;n<t.length;n+=4,e++)m[e]=.2126*t[n]+.7152*t[n+1]+.0722*t[n+2];let h=[-1,0,1,-2,0,2,-1,0,1],g=[-1,-2,-1,0,0,0,1,2,1],_=e=>e<0?0:e>255?255:e;for(let e=0;e<r;e++)for(let i=0;i<n;i++){let a=0,o=0,c=0;for(let t=-1;t<=1;t++){let s=Math.max(0,Math.min(r-1,e+t))*n;for(let e=-1;e<=1;e++,c++){let t=m[s+Math.max(0,Math.min(n-1,i+e))];a+=t*h[c],o+=t*g[c]}}let u=e*n+i,v=_(l+(d*a+f*o)*p),y=u*4;if(s){let e=v-l;t[y]=_(t[y]+e),t[y+1]=_(t[y+1]+e),t[y+2]=_(t[y+2]+e)}else t[y]=t[y+1]=t[y+2]=v}return e};X.addGetterSetter(Z,`embossStrength`,.5,Y(),X.afterSetFilter),X.addGetterSetter(Z,`embossWhiteLevel`,.5,Y(),X.afterSetFilter),X.addGetterSetter(Z,`embossDirection`,`top-left`,void 0,X.afterSetFilter),X.addGetterSetter(Z,`embossBlend`,!1,void 0,X.afterSetFilter);function Gc(e,t,n,r,i){let a=n-t,o=i-r;if(a===0)return r+o/2;if(o===0)return r;let s=(e-t)/a;return s=o*s+r,s}var Kc=function(e){let t=e.data,n=t.length,r=t[0],i=r,a,o=t[1],s=o,c,l=t[2],u=l,d,f=this.enhance();if(f===0)return;for(let e=0;e<n;e+=4)a=t[e+0],a<r?r=a:a>i&&(i=a),c=t[e+1],c<o?o=c:c>s&&(s=c),d=t[e+2],d<l?l=d:d>u&&(u=d);i===r&&(i=255,r=0),s===o&&(s=255,o=0),u===l&&(u=255,l=0);let p,m,h,g,_,v;if(f>0)p=i+f*(255-i),m=r-f*(r-0),h=s+f*(255-s),g=o-f*(o-0),_=u+f*(255-u),v=l-f*(l-0);else{let e=(i+r)*.5;p=i+f*(i-e),m=r+f*(r-e);let t=(s+o)*.5;h=s+f*(s-t),g=o+f*(o-t);let n=(u+l)*.5;_=u+f*(u-n),v=l+f*(l-n)}for(let e=0;e<n;e+=4)t[e+0]=Gc(t[e+0],r,i,m,p),t[e+1]=Gc(t[e+1],o,s,g,h),t[e+2]=Gc(t[e+2],l,u,v,_)};X.addGetterSetter(Z,`enhance`,0,Y(),X.afterSetFilter);var qc=function(e){let t=e.data,n=t.length;for(let e=0;e<n;e+=4){let n=.34*t[e]+.5*t[e+1]+.16*t[e+2];t[e]=n,t[e+1]=n,t[e+2]=n}};X.addGetterSetter(Z,`hue`,0,Y(),X.afterSetFilter),X.addGetterSetter(Z,`saturation`,0,Y(),X.afterSetFilter),X.addGetterSetter(Z,`luminance`,0,Y(),X.afterSetFilter);var Jc=function(e){let t=e.data,n=t.length,r=2**this.saturation(),i=(this.hue()%360+360)%360,a=this.luminance()*127,o=1*r*Math.cos(i*Math.PI/180),s=1*r*Math.sin(i*Math.PI/180),c=.299*1+.701*o+.168*s,l=.587*1-.587*o+.33*s,u=.114*1-.114*o-.497*s,d=.299*1-.299*o-.328*s,f=.587*1+.413*o+.035*s,p=.114*1-.114*o+.292*s,m=.299*1-.3*o+1.25*s,h=.587*1-.588*o-1.05*s,g=.114*1+.886*o-.203*s,_,v,y,b;for(let e=0;e<n;e+=4)_=t[e+0],v=t[e+1],y=t[e+2],b=t[e+3],t[e+0]=c*_+l*v+u*y+a,t[e+1]=d*_+f*v+p*y+a,t[e+2]=m*_+h*v+g*y+a,t[e+3]=b},Yc=function(e){let t=e.data,n=t.length,r=2**this.value(),i=2**this.saturation(),a=(this.hue()%360+360)%360,o=r*i*Math.cos(a*Math.PI/180),s=r*i*Math.sin(a*Math.PI/180),c=.299*r+.701*o+.168*s,l=.587*r-.587*o+.33*s,u=.114*r-.114*o-.497*s,d=.299*r-.299*o-.328*s,f=.587*r+.413*o+.035*s,p=.114*r-.114*o+.292*s,m=.299*r-.3*o+1.25*s,h=.587*r-.588*o-1.05*s,g=.114*r+.886*o-.203*s;for(let e=0;e<n;e+=4){let n=t[e+0],r=t[e+1],i=t[e+2],a=t[e+3];t[e+0]=c*n+l*r+u*i,t[e+1]=d*n+f*r+p*i,t[e+2]=m*n+h*r+g*i,t[e+3]=a}};X.addGetterSetter(Z,`hue`,0,Y(),X.afterSetFilter),X.addGetterSetter(Z,`saturation`,0,Y(),X.afterSetFilter),X.addGetterSetter(Z,`value`,0,Y(),X.afterSetFilter);var Xc=function(e){let t=e.data,n=t.length;for(let e=0;e<n;e+=4)t[e]=255-t[e],t[e+1]=255-t[e+1],t[e+2]=255-t[e+2]},Zc=function(e,t,n){let r=e.data,i=t.data,a=e.width,o=e.height,s=n.polarCenterX||a/2,c=n.polarCenterY||o/2,l=Math.sqrt(s*s+c*c),u=a-s,d=o-c,f=Math.sqrt(u*u+d*d);l=f>l?f:l;let p=o,m=a,h=360/m*Math.PI/180;for(let e=0;e<m;e+=1){let t=Math.sin(e*h),n=Math.cos(e*h);for(let o=0;o<p;o+=1){u=Math.floor(s+l*o/p*n),d=Math.floor(c+l*o/p*t);let f=(d*a+u)*4,m=r[f+0],h=r[f+1],g=r[f+2],_=r[f+3];f=(e+o*a)*4,i[f+0]=m,i[f+1]=h,i[f+2]=g,i[f+3]=_}}},Qc=function(e,t,n){let r=e.data,i=t.data,a=e.width,o=e.height,s=n.polarCenterX||a/2,c=n.polarCenterY||o/2,l=Math.sqrt(s*s+c*c),u=a-s,d=o-c,f=Math.sqrt(u*u+d*d);l=f>l?f:l;let p=o,m=a,h=n.polarRotation||0,g,_;for(u=0;u<a;u+=1)for(d=0;d<o;d+=1){let e=u-s,t=d-c,n=Math.sqrt(e*e+t*t)*p/l,o=(Math.atan2(t,e)*180/Math.PI+360+h)%360;o=o*m/360,g=Math.floor(o),_=Math.floor(n);let f=(_*a+g)*4,v=r[f+0],y=r[f+1],b=r[f+2],x=r[f+3];f=(d*a+u)*4,i[f+0]=v,i[f+1]=y,i[f+2]=b,i[f+3]=x}},$c=function(e){let t=e.width,n=e.height,r,i,a,o,s,c,l,u,d,f,p=Math.round(this.kaleidoscopePower()),m=Math.round(this.kaleidoscopeAngle()),h=Math.floor(t*((m%360+360)%360)/360);if(p<1)return;let g={width:t,height:n,data:new Uint8ClampedArray(t*n*4)};Zc(e,g,{polarCenterX:t/2,polarCenterY:n/2});let _=t/2**p;for(;_<=8;)_*=2,--p;_=Math.ceil(_);let v=_,y=0,b=v,x=1;for(h+_>t&&(y=v,b=0,x=-1),i=0;i<n;i+=1)for(r=y;r!==b;r+=x)a=Math.round(r+h)%t,d=(t*i+a)*4,s=g.data[d+0],c=g.data[d+1],l=g.data[d+2],u=g.data[d+3],f=(t*i+r)*4,g.data[f+0]=s,g.data[f+1]=c,g.data[f+2]=l,g.data[f+3]=u;for(i=0;i<n;i+=1)for(v=Math.floor(_),o=0;o<p;o+=1){for(r=0;r<v+1;r+=1)d=(t*i+r)*4,s=g.data[d+0],c=g.data[d+1],l=g.data[d+2],u=g.data[d+3],f=(t*i+v*2-r-1)*4,g.data[f+0]=s,g.data[f+1]=c,g.data[f+2]=l,g.data[f+3]=u;v*=2}Qc(g,e,{polarRotation:0})};X.addGetterSetter(Z,`kaleidoscopePower`,2,Y(),X.afterSetFilter),X.addGetterSetter(Z,`kaleidoscopeAngle`,0,Y(),X.afterSetFilter);function el(e,t,n){let r=(n*e.width+t)*4,i=[];return i.push(e.data[r++],e.data[r++],e.data[r++],e.data[r++]),i}function tl(e,t){return Math.sqrt((e[0]-t[0])**2+(e[1]-t[1])**2+(e[2]-t[2])**2)}function nl(e){let t=[0,0,0];for(let n=0;n<e.length;n++)t[0]+=e[n][0],t[1]+=e[n][1],t[2]+=e[n][2];return t[0]/=e.length,t[1]/=e.length,t[2]/=e.length,t}function rl(e,t){let n=el(e,0,0),r=el(e,e.width-1,0),i=el(e,0,e.height-1),a=el(e,e.width-1,e.height-1);if(tl(n,r)<t&&tl(r,a)<t&&tl(a,i)<t&&tl(i,n)<t){let o=nl([r,n,a,i]),s=[];for(let n=0;n<e.width*e.height;n++)s[n]=tl(o,[e.data[n*4],e.data[n*4+1],e.data[n*4+2]])<t?0:255;return s}}function il(e,t){for(let n=0;n<e.width*e.height;n++)e.data[4*n+3]=t[n]}function al(e,t,n){let r=[1,1,1,1,0,1,1,1,1],i=Math.round(Math.sqrt(r.length)),a=Math.floor(i/2),o=[];for(let s=0;s<n;s++)for(let c=0;c<t;c++){let l=s*t+c,u=0;for(let o=0;o<i;o++)for(let l=0;l<i;l++){let d=s+o-a,f=c+l-a;if(d>=0&&d<n&&f>=0&&f<t){let n=d*t+f,a=r[o*i+l];u+=e[n]*a}}o[l]=u===2040?255:0}return o}function ol(e,t,n){let r=[1,1,1,1,1,1,1,1,1],i=Math.round(Math.sqrt(r.length)),a=Math.floor(i/2),o=[];for(let s=0;s<n;s++)for(let c=0;c<t;c++){let l=s*t+c,u=0;for(let o=0;o<i;o++)for(let l=0;l<i;l++){let d=s+o-a,f=c+l-a;if(d>=0&&d<n&&f>=0&&f<t){let n=d*t+f,a=r[o*i+l];u+=e[n]*a}}o[l]=u>=1020?255:0}return o}function sl(e,t,n){let r=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],i=Math.round(Math.sqrt(r.length)),a=Math.floor(i/2),o=[];for(let s=0;s<n;s++)for(let c=0;c<t;c++){let l=s*t+c,u=0;for(let o=0;o<i;o++)for(let l=0;l<i;l++){let d=s+o-a,f=c+l-a;if(d>=0&&d<n&&f>=0&&f<t){let n=d*t+f,a=r[o*i+l];u+=e[n]*a}}o[l]=u}return o}var cl=function(e){let t=rl(e,this.attrs.threshold??10);return t&&(t=al(t,e.width,e.height),t=ol(t,e.width,e.height),t=sl(t,e.width,e.height),il(e,t)),e};X.addGetterSetter(Z,`threshold`,.5,Y(),X.afterSetFilter);var ll=function(e){let t=this.noise()*255,n=e.data,r=n.length,i=t/2;for(let e=0;e<r;e+=4)n[e+0]+=i-2*i*Math.random(),n[e+1]+=i-2*i*Math.random(),n[e+2]+=i-2*i*Math.random()};X.addGetterSetter(Z,`noise`,.2,Y(),X.afterSetFilter);var ul=function(e,t=1){let n=Math.ceil(this.pixelSize()*t),r=e.width,i=e.height,a=Math.ceil(r/n),o=Math.ceil(i/n),s=e.data;if(n<=0){J.error(`pixelSize value can not be <= 0`);return}for(let e=0;e<a;e+=1)for(let t=0;t<o;t+=1){let a=0,o=0,c=0,l=0,u=e*n,d=Math.min(u+n,r),f=t*n,p=Math.min(f+n,i);for(let e=u;e<d;e+=1)for(let t=f;t<p;t+=1){let n=(r*t+e)*4,i=s[n+3];a+=s[n+0]*i,o+=s[n+1]*i,c+=s[n+2]*i,l+=i}l&&(a/=l,o/=l,c/=l),l/=(d-u)*(p-f);for(let e=u;e<d;e+=1)for(let t=f;t<p;t+=1){let n=(r*t+e)*4;s[n+0]=a,s[n+1]=o,s[n+2]=c,s[n+3]=l}}};X.addGetterSetter(Z,`pixelSize`,8,Y(),X.afterSetFilter);var dl=function(e){let t=Math.round(this.levels()*254)+1,n=e.data,r=n.length,i=255/t;for(let e=0;e<r;e+=1)n[e]=Math.floor(n[e]/i)*i};X.addGetterSetter(Z,`levels`,.5,Y(),X.afterSetFilter);var fl=function(e){let t=e.data,n=t.length,r=this.red(),i=this.green(),a=this.blue();for(let e=0;e<n;e+=4){let n=(.34*t[e]+.5*t[e+1]+.16*t[e+2])/255;t[e]=n*r,t[e+1]=n*i,t[e+2]=n*a,t[e+3]=t[e+3]}};X.addGetterSetter(Z,`red`,0,Zi,X.afterSetFilter),X.addGetterSetter(Z,`green`,0,Zi,X.afterSetFilter),X.addGetterSetter(Z,`blue`,0,Zi,X.afterSetFilter);var pl=function(e){let t=e.data,n=t.length,r=this.red(),i=this.green(),a=this.blue(),o=this.alpha();for(let e=0;e<n;e+=4){let n=1-o;t[e]=r*o+t[e]*n,t[e+1]=i*o+t[e+1]*n,t[e+2]=a*o+t[e+2]*n}};X.addGetterSetter(Z,`alpha`,1,e=>Math.min(1,Math.max(0,e)),X.afterSetFilter);var ml=function(e){let t=e.data,n=t.length;for(let e=0;e<n;e+=4){let n=t[e+0],r=t[e+1],i=t[e+2];t[e+0]=Math.min(255,n*.393+r*.769+i*.189),t[e+1]=Math.min(255,n*.349+r*.686+i*.168),t[e+2]=Math.min(255,n*.272+r*.534+i*.131)}},hl=function(e){let t=e.data;for(let e=0;e<t.length;e+=4){let n=t[e],r=t[e+1],i=t[e+2];.2126*n+.7152*r+.0722*i>=128&&(t[e]=255-n,t[e+1]=255-r,t[e+2]=255-i)}return e},gl=function(e){let t=this.threshold()*255,n=e.data,r=n.length;for(let e=0;e<r;e+=1)n[e]=n[e]<t?0:255};X.addGetterSetter(Z,`threshold`,.5,Y(),X.afterSetFilter);var _l=Yo.Util._assign(Yo,{Arc:Xo,Arrow:ms,Circle:hs,Ellipse:gs,Image:_s,Label:ac,Tag:oc,Line:us,Path:ps,Rect:sc,RegularPolygon:cc,Ring:uc,Sprite:dc,Star:fc,Text:Qs,TextPath:_c,Transformer:$,Wedge:Nc,Filters:{Blur:Bc,Brightness:Hc,Brighten:Vc,Contrast:Uc,Emboss:Wc,Enhance:Kc,Grayscale:qc,HSL:Jc,HSV:Yc,Invert:Xc,Kaleidoscope:$c,Mask:cl,Noise:ll,Pixelate:ul,Posterize:dl,RGB:fl,RGBA:pl,Sepia:ml,Solarize:hl,Threshold:gl}});function vl(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function yl(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}var bl=class{cells=new Map;large=[];items;cellSize;constructor(e,t=256){if(this.items=e,this.cellSize=t,!Number.isFinite(t)||t<=0)throw Error(`Invalid spatial cell size`);e.forEach((e,t)=>{let[n,r,i,a]=this.range(e.bounds);if((i-n+1)*(a-r+1)>256){this.large.push(t);return}for(let e=n;e<=i;e++)for(let n=r;n<=a;n++){let r=`${e},${n}`,i=this.cells.get(r)??[];i.push(t),this.cells.set(r,i)}})}range(e){return[Math.floor(e.x/this.cellSize),Math.floor(e.y/this.cellSize),Math.floor((e.x+e.width)/this.cellSize),Math.floor((e.y+e.height)/this.cellSize)]}query(e){let[t,n,r,i]=this.range(e),a=new Set(this.large);if((r-t+1)*(i-n+1)>1e4)this.items.forEach((e,t)=>a.add(t));else for(let e=t;e<=r;e++)for(let t=n;t<=i;t++)for(let n of this.cells.get(`${e},${t}`)??[])a.add(n);let o=t=>e.width===0&&e.height===0?yl(t,e.x,e.y):vl(t,e);return[...a].sort((e,t)=>e-t).map(e=>this.items[e]).filter(e=>e.node.visible!==!1&&o(e.bounds)&&e.clips.every(o))}hitTest(e,t){return this.query({x:e,y:t,width:0,height:0}).toReversed().find(n=>yl(n.bounds,e,t)&&n.clips.every(n=>yl(n,e,t)))}};function xl(e,t,n=new Map,r,i,a,o=!1){_l.autoDrawEnabled=!1,_l.pixelRatio=1;let s=new _l.Stage({width:e,height:t,...r?{container:r}:{}}),c=new _l.Layer({listening:!1}),l=new _l.Layer({listening:!1}),u=new _l.Layer({listening:!1});s.add(c,l,u);for(let e of[c,l,u])a?.(e.getCanvas()._canvas);let d={x:0,y:0,width:e,height:t},f=new bl([]),p={},m=[],h=[],g={selection:`#2563EB`,changes:`#B45309`},_=!1,v=!1,y=0,b=[],x=new Map,S=(e,t)=>{let n=kr(e.document,t,p);return typeof n==`number`?n:0},C=(e,t)=>String(kr(e.document,t,p)),w=e=>{let t=e.node,r=e.bounds,i=t.fills?.[0],a={x:r.x,y:r.y,width:r.width,height:r.height,listening:!1,opacity:t.opacity??1,rotation:t.rotation??0};if(i?.kind===`solid`&&(a.fill=C(e,i.color)),i?.kind===`image`){let t=n.get(`${e.document.documentId}:${i.assetId}`);if(!t)a.fill=`#D4D4D8`;else{let e=r.width/t.width,n=r.height/t.height,o=i.mode===`cover`?Math.max(e,n):Math.min(e,n);a.fillPriority=`pattern`,a.fillPatternRepeat=`no-repeat`,a.fillPatternScale=i.mode===`stretch`?{x:e,y:n}:{x:o,y:o},a.fillPatternX=(r.width-t.width*(i.mode===`stretch`?e:o))/2,a.fillPatternY=(r.height-t.height*(i.mode===`stretch`?n:o))/2}}if(i?.kind===`gradient`){let t=i.stops.flatMap(t=>[t.offset,C(e,t.color)]);i.gradient===`linear`?(a.fillLinearGradientStartPoint={x:0,y:0},a.fillLinearGradientEndPoint={x:r.width*Math.cos(i.angle*Math.PI/180),y:r.height*Math.sin(i.angle*Math.PI/180)},a.fillLinearGradientColorStops=t):(a.fillRadialGradientStartPoint={x:r.width/2,y:r.height/2},a.fillRadialGradientEndPoint={x:r.width/2,y:r.height/2},a.fillRadialGradientStartRadius=0,a.fillRadialGradientEndRadius=Math.max(r.width,r.height)/2,a.fillRadialGradientColorStops=t)}t.stroke&&(a.stroke=C(e,t.stroke),a.strokeWidth=t.strokeWidth?S(e,t.strokeWidth):1);let o=t.effects?.find(e=>e.kind===`shadow`);o?.kind===`shadow`&&(a.shadowColor=C(e,o.color),a.shadowBlur=S(e,o.blur),a.shadowOffset={x:S(e,o.x),y:S(e,o.y)});let s;if(s=t.type===`text`?new _l.Text({...a,text:t.text,fontFamily:C(e,t.fontFamily),fontSize:S(e,t.fontSize),fontStyle:(t.fontWeight??400)>=600?`bold`:`normal`,lineHeight:t.lineHeight?S(e,t.lineHeight):1.2}):t.type===`ellipse`?new _l.Ellipse({...a,x:r.x+r.width/2,y:r.y+r.height/2,radiusX:r.width/2,radiusY:r.height/2}):t.type===`path`?new _l.Path({...a,data:t.geometry,scaleX:r.width/(t.viewBox.width||1),scaleY:r.height/(t.viewBox.height||1)}):new _l.Rect({...a,cornerRadius:`radius`in t&&t.radius?S(e,t.radius):0}),i?.kind===`image`){let t=n.get(`${e.document.documentId}:${i.assetId}`);t&&s.setAttrs({fillPatternImage:t})}let c=t.effects?.find(e=>e.kind===`blur`);if(c?.kind===`blur`&&(s.cache(),s.filters([_l.Filters.Blur]),s.blurRadius(S(e,c.radius))),!e.clips.length)return s;let l=e.clips.reduce((e,t)=>{let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y);return{x:n,y:r,width:Math.max(0,Math.min(e.x+e.width,t.x+t.width)-n),height:Math.max(0,Math.min(e.y+e.height,t.y+t.height)-r)}}),u=new _l.Group({clipX:l.x,clipY:l.y,clipWidth:l.width,clipHeight:l.height,listening:!1});return u.add(s),u},T=(e,t,n)=>{e.destroyChildren();for(let r of b)if(t.includes(r.ownerId)){let t=r.bounds;e.add(new _l.Rect({...t,stroke:n,strokeWidth:1,listening:!1}))}},E={setDocument(e,t={},n={},r){let i=Mr(e,t,n);if(i.diagnostics.some(e=>e.severity===`error`))throw Error(`Invalid layout for renderer spike`);f=new bl(r?jr(i.items,r):i.items),p=t,_=!0,v=!0},setViewport(e){if(e.width<=0||e.height<=0)throw Error(`Viewport needs positive dimensions`);JSON.stringify(e)!==JSON.stringify(d)&&(d=e,_=!0)},setSelection(e){m=e,_=!0},setChanges(e){h=e,_=!0},setStrokes(e){e.selection===g.selection&&e.changes===g.changes||(g=e,_=!0)},render(){if(!_)return!1;b=f.query(d);let n=new Set(b.map(e=>e.key));for(let[e,t]of x)(v||!n.has(e))&&(t.destroy(),x.delete(e));for(let e of b)if(!x.has(e.key)){let t=w(e);c.add(t),x.set(e.key,t)}b.forEach((e,t)=>{let n=x.get(e.key);n.zIndex()!==t&&n.zIndex(t)});let r=e/d.width,i=t/d.height;for(let e of[c,l,u])e.scale({x:r,y:i}),e.position({x:-d.x*r,y:-d.y*i});return T(l,m,g.selection),T(u,h,g.changes),c.draw(),l.draw(),u.draw(),y++,_=!1,v=!1,!0},hitTest(e,t){return f.hitTest(e,t)?.ownerId},async exportPng(){E.render();let e=o?c.getCanvas()._canvas:s.toCanvas({pixelRatio:1});if(i)return i(e);let t=await new Promise((t,n)=>e.toBlob(e=>e?t(e):n(Error(`PNG export failed`)),`image/png`));return new Uint8Array(await t.arrayBuffer())},stats(){return{visible:b.length,sceneShapes:x.size,draws:y}},destroy(){s.destroy(),x.clear()}};return E}var Sl=0;async function Cl(e,t,n,r=new Map,i){let a=new Map;return await Promise.all([...r].map(async([e,t])=>{let n=URL.createObjectURL(new Blob([t.slice().buffer]));try{let t=new Image;t.src=n,await t.decode(),a.set(e,t)}catch{i?.(e)}finally{URL.revokeObjectURL(n)}})),e.id||=`design-canvas-${++Sl}`,xl(t,n,a,e.id)}var wl={flash:650,cursorGlide:450,cursorFade:240,cursorLinger:900,batchLinger:1600,wipe:400,fade:160},Tl=(e,t)=>{let n=e.nodes[t];return n&&`children`in n?n.children:[]};function El(e){let t=new Map;for(let n of Object.keys(e.nodes))for(let r of Tl(e,n))t.set(r,n);return t}function Dl(e,t,n=El(e)){if(!e.nodes[t])return null;let r=t;for(let e=0;e<1e4;e++){let e=n.get(r);if(!e)return r;r=e}return null}function Ol(e,t){if(!t)return null;let n=El(e);for(let r=t.nodeIds.length-1;r>=0;r--){let i=Dl(e,t.nodeIds[r],n);if(i)return i}return null}function kl(e,t,n=24){let r=El(e),i=[...new Set(t)].filter(t=>e.nodes[t]),a=e=>{let t=new Set(e);return e.filter(e=>{for(let n=r.get(e);n;n=r.get(n))if(t.has(n))return!1;return!0})},o=a(i);for(;o.length>n;){let e=[...new Set(o.map(e=>r.get(e)??e))];if(e.length===o.length)return o.slice(0,n);o=a(e)}return o}var Al=e=>{if(!e.length)return null;let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t,y:n,width:r-t,height:i-n}},jl=e=>({x:e.x+Math.min(20,e.width/3),y:e.y+Math.min(14,e.height/3)});function Ml(e,t){for(let n=e.length-1;n>=0;n--){let r=t(e[n]);if(r)return{nodeId:e[n],bounds:r}}return null}var Nl=(e,t)=>e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height;function Pl(e,t,n,r={top:64,right:16,bottom:72,left:16}){let i=n.width/t.width,a=(e.x+e.width/2-t.x)*i,o=(e.y+e.height/2-t.y)*i,s=a-n.width/2,c=o-n.height/2,l=Math.abs(s)/n.width>=Math.abs(c)/n.height,u=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n));if(l){let e=s<0?`left`:`right`;return{side:e,x:e===`left`?r.left:n.width-r.right,y:u(o,r.top,n.height-r.bottom)}}let d=c<0?`top`:`bottom`;return{side:d,x:u(a,r.left+90,n.width-r.right-90),y:d===`top`?r.top:n.height-r.bottom}}function Fl(e,t,n,r=72){let i=n.width/t.width,a=Math.min((n.width-r*2)/e.width,(n.height-r*2)/e.height),o=Math.max(.05,Math.min(i,a)),s=n.width/o,c=n.height/o;return{x:e.x+e.width/2-s/2,y:e.y+e.height/2-c/2,width:s,height:c}}var Il=/^(apply|design_[a-z]+)\s+[a-z-]*:\s*/i;function Ll(e,t=56){let n=(e.replace(Il,``).split(`
|
|
17
17
|
`,1)[0]??``).trim().replace(/\.$/,``)||`see the agent's reply`;return n.length>t?`${n.slice(0,t-1).trimEnd()}…`:n}function Rl(e){let t=new Map;return{start(n){t.set(n,setTimeout(()=>{t.delete(n),e(n)},wl.wipe+100))},dispose(){for(let e of t.values())clearTimeout(e);t.clear()}}}var zl=`(prefers-reduced-motion: reduce)`,Bl=e=>{let t=matchMedia(zl);return t.addEventListener(`change`,e),()=>t.removeEventListener(`change`,e)},Vl=()=>(0,G.useSyncExternalStore)(Bl,Ql,$l),Hl=e=>(document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)),Ul=`cubic-bezier(0.77, 0, 0.175, 1)`,Wl={left:mn,right:ct,top:nn,bottom:cn},Gl=64;function Kl(e,t,n){let r=n.width/t.width,i=(e.x-t.x)*r,a=(e.y-t.y)*r,o=e.width*r,s=e.height*r,c=Math.max(i,-64),l=Math.max(a,-64),u=Math.min(i+o,n.width+Gl),d=Math.min(a+s,n.height+Gl);return{corner:{x:i,y:a},visible:u>c&&d>l,style:{left:c,top:l,width:Math.max(0,u-c),height:Math.max(0,d-l),"--paint-ox":`${i-c}px`,"--paint-oy":`${a-l}px`}}}function ql({cursorSize:e=`small`,cursorLabel:t=`name`,animations:n=!0,document:r,bounds:i,viewport:a,canvas:o,batch:s,agents:c,onReveal:l}){let u=(0,G.useSyncExternalStore)(Hl,()=>!globalThis.document.hidden,()=>!1),d=Vl()||!n,f=o.width/a.width,p=c?.some(e=>e.active)??!1,m=(c?.find(e=>e.active)??c?.[0])?.label??`Agent`,h=c?.find(e=>e.lastError!==null)?.lastError??null,g=(0,G.useMemo)(()=>{let e=new Set;return(c??[]).flatMap(t=>{let n=t.workingNodeId,a=n?i.get(n):void 0;return!n||!a||e.has(n)?[]:(e.add(n),[{id:n,label:t.label,box:a,root:r.roots.includes(n)}])})},[c,i,r.roots]),[_,v]=(0,G.useState)(null),[y,b]=(0,G.useState)([]),[x,S]=(0,G.useState)(!1),[C,w]=(0,G.useState)(null),T=(0,G.useRef)({document:r,bounds:i,working:g,active:p,failed:h!==null});T.current={document:r,bounds:i,working:g,active:p,failed:h!==null};let E=(0,G.useRef)(p?null:s?.sequence??null),D=(0,G.useRef)({}),O=(0,G.useRef)(0),k=(0,G.useRef)(null);k.current??=Rl(e=>b(t=>t.filter(t=>t.id!==e))),(0,G.useEffect)(()=>{if(!s||s.sequence===E.current)return;E.current=s.sequence;let{document:e,bounds:t}=T.current,n=kl(e,s.nodeIds).flatMap(e=>t.get(e)??[]),r=Ml(s.nodeIds,e=>t.get(e));v({id:s.sequence,rects:n}),r&&w({point:jl(r.bounds),box:r.bounds,name:e.nodes[r.nodeId]?.name??``}),S(!0),clearTimeout(D.current.flash),clearTimeout(D.current.linger),D.current.flash=window.setTimeout(()=>v(e=>e?.id===s.sequence?null:e),wl.flash+80),D.current.linger=window.setTimeout(()=>S(!1),wl.batchLinger)},[s]),(0,G.useEffect)(()=>()=>{clearTimeout(D.current.flash),clearTimeout(D.current.linger),k.current?.dispose()},[]);let A=g.map(e=>e.id).join(`|`),j=(0,G.useRef)(new Map);(0,G.useEffect)(()=>{let e=new Map(T.current.working.map(e=>[e.id,{id:0,bounds:e.box,label:e.label,failed:T.current.failed}])),t=[...j.current].filter(([t])=>!e.has(t)),n=T.current.working.find(e=>!j.current.has(e.id));if(j.current=e,n&&w({point:jl(n.box),box:n.box,name:T.current.document.nodes[n.id]?.name??``}),!t.length)return;let r=t.map(([,e])=>({...e,id:++O.current}));b(e=>[...e,...r]);for(let e of r)k.current?.start(e.id)},[A]),(0,G.useEffect)(()=>{j.current=new Map(g.map(e=>[e.id,{id:0,bounds:e.box,label:e.label,failed:h!==null}]))},[g,h]);let M=(0,G.useMemo)(()=>{if(C)return C;if(!h)return null;let e=r.roots.map(e=>i.get(e)).find(Boolean);return e?{point:jl(e),box:e,name:``}:null},[C,h,r.roots,i]),N=M!==null&&(p||x||g.length>0||h!==null),P=(0,G.useRef)(!1),F=(0,G.useRef)(null),I=(0,G.useRef)(null),L=(0,G.useRef)(null);(0,G.useLayoutEffect)(()=>{let e=M?.point??null,t=F.current,n=P.current;F.current=e,P.current=N;let r=I.current;if(!r||!e||!t||!n||d){L.current?.cancel();return}if(t.x===e.x&&t.y===e.y)return;let i=0,a=0;if(L.current?.playState===`running`){let e=new DOMMatrixReadOnly(getComputedStyle(r).transform);i=e.e,a=e.f}L.current?.cancel(),L.current=r.animate([{transform:`translate(${(t.x-e.x)*f+i}px, ${(t.y-e.y)*f+a}px)`},{transform:`translate(0px, 0px)`}],{duration:wl.cursorGlide,easing:Ul})},[M?.point.x,M?.point.y,d]),(0,G.useEffect)(()=>{P.current=N},[N]),(0,G.useEffect)(()=>()=>L.current?.cancel(),[]);let R=g[0]?.box??(N?M?.box:void 0)??null,ee=R&&(p||x||g.length>0)&&!Nl(R,a)?R:null,z=ee?Pl(ee,a,o):null;if(!o.width)return null;let B=h?`${m}: change not applied - ${Ll(h)}`:g[0]?`${g[0].label} is generating ${r.nodes[g[0].id]?.name??`a frame`}`:``,te=h!==null,ne=M?{x:(M.point.x-a.x)*f,y:(M.point.y-a.y)*f}:null,re=ne?ne.x>o.width-240:!1;return(0,K.jsxs)(`div`,{className:`design-paint`,"data-reduced":d?``:void 0,"data-paused":u?void 0:``,style:{"--paint-cycle":`${wl.batchLinger}ms`},children:[(0,K.jsx)(`span`,{className:`sr-only`,role:`status`,children:B}),g.map(e=>{let t=Kl(e.box,a,o);return t.visible?(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`design-paint-field`,"data-failed":te?``:void 0,style:t.style}),e.root&&e.box.width*f>80?(0,K.jsxs)(`span`,{className:`design-paint-label`,"data-inside":e.root?void 0:``,style:{left:t.corner.x,top:t.corner.y},children:[(0,K.jsx)(Yl,{size:14}),(0,K.jsx)(`span`,{children:(0,K.jsx)(`b`,{children:e.label})})]}):null]},e.id):null}),y.map(e=>{let t=Kl(e.bounds,a,o);return t.visible?(0,K.jsx)(`div`,{className:`design-paint-field design-paint-wipe`,"data-failed":e.failed?``:void 0,style:t.style},e.id):null}),_?.rects.map(e=>{let t=Kl(e,a,o);return t.visible?(0,K.jsx)(`div`,{className:`design-paint-flash`,style:t.style},`${_.id}:${e.x}:${e.y}:${e.width}`):null}),M&&ne?(0,K.jsx)(`div`,{className:`design-paint-cursor`,"data-size":e,"data-shown":N?``:void 0,"data-failed":te?``:void 0,"data-flip":re?``:void 0,style:{transform:`translate3d(${ne.x}px, ${ne.y}px, 0)`},children:(0,K.jsxs)(`div`,{ref:I,className:`design-paint-glide`,children:[(0,K.jsx)(Yl,{animate:N&&u&&!d&&!te&&ne.x>=0&&ne.y>=0&&ne.x<=o.width&&ne.y<=o.height,sequence:s?.sequence}),(0,K.jsx)(`span`,{className:`design-paint-pill`,hidden:t===`none`&&!te,children:te?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`b`,{children:[m,`:`]}),` change not applied - `,Ll(h??``)]}):(0,K.jsx)(K.Fragment,{children:(0,K.jsx)(`b`,{children:t===`agent`?`Agent`:m})})})]})}):null,z?(0,K.jsx)(Jl,{label:m,chip:z,onClick:()=>ee&&l(ee)}):null]})}function Jl(e){let t=(0,W.c)(11),{label:n,chip:r,onClick:i}=e,a=Wl[r.side],o;t[0]!==r.x||t[1]!==r.y?(o={left:r.x,top:r.y},t[0]=r.x,t[1]=r.y,t[2]=o):o=t[2];let s;t[3]===a?s=t[4]:(s=(0,K.jsx)(a,{"aria-hidden":`true`}),t[3]=a,t[4]=s);let c;return t[5]!==r.side||t[6]!==n||t[7]!==i||t[8]!==o||t[9]!==s?(c=(0,K.jsxs)(`button`,{type:`button`,className:`design-paint-chip`,"data-side":r.side,style:o,onClick:i,children:[s,n,` is working here`]}),t[5]=r.side,t[6]=n,t[7]=i,t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function Yl(e){let t=(0,W.c)(10),{size:n,animate:r,sequence:i}=e,a=n===void 0?22:n,o=r===void 0?!1:r,s=(0,G.useRef)(null),c=(0,G.useRef)(null),l;t[0]===o?l=t[1]:(l=()=>{if(!o)return;let e=[],t=()=>{document.hidden||(e=[s.current?.animate(Lt,{duration:gt,easing:`linear`}),c.current?.animate(Tn,{duration:gt,easing:`ease-in-out`})].filter(Zl))},n,r=setTimeout(()=>{t(),n=setInterval(t,Ft)},kn);return()=>{clearTimeout(r),clearInterval(n),e.forEach(Xl)}},t[0]=o,t[1]=l);let u;t[2]!==o||t[3]!==i?(u=[o,i],t[2]=o,t[3]=i,t[4]=u):u=t[4],(0,G.useEffect)(l,u);let d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d={overflow:`visible`,filter:Qt},t[5]=d):d=t[5];let f,p;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,K.jsx)(`path`,{ref:c,d:pt,fill:Yt,stroke:Yt,strokeWidth:6,strokeLinejoin:`round`,strokeLinecap:`round`,style:{filter:rn,opacity:jn}}),p=(0,K.jsx)(`path`,{d:pt,fill:sn,stroke:pn,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`}),t[6]=f,t[7]=p):(f=t[6],p=t[7]);let m;return t[8]===a?m=t[9]:(m=(0,K.jsxs)(`svg`,{ref:s,className:`design-cu-cursor`,width:a,height:a,viewBox:Dn,shapeRendering:`geometricPrecision`,"aria-hidden":`true`,style:d,children:[f,p]}),t[8]=a,t[9]=m),m}function Xl(e){return e.cancel()}function Zl(e){return!!e}function Ql(){return matchMedia(zl).matches}function $l(){return!0}function eu(e){return e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function tu(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).toLowerCase()}function nu(e){return String(Number.isInteger(e)?e:Math.round(e*100)/100)}var ru=e=>`${Math.round(e*100)}%`,iu=e=>e?`Shown`:`Hidden`,au=e=>e?`On`:`Off`,ou=e=>e?String(e):`None`;function su(e){return new Map(Object.entries(e).toSorted(([e,t],[n,r])=>t.createdAt.localeCompare(r.createdAt)||e.localeCompare(n)).map(([e],t)=>[e,t+1]))}var cu=new Set([`nodes`,`tokens`,`components`,`instances`,`imports`,`assets`]),lu=e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`,uu=e=>typeof e==`number`?nu(e):String(e);function du(e,t,n){let[r=``,...i]=e.path.split(`/`).slice(1).map(e=>e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`)),a=cu.has(r),o=a?i[0]:void 0,s=a?i.slice(1):i,c=e=>{if(o){if(r===`nodes`)return e.nodes[o]?.name;if(r===`tokens`)return e.tokens[o]?.name;if(r===`components`)return e.components[o]?.name}},l=c(n)??c(t)??(r?eu(tu(r)):`Document`),u=s.filter(e=>!/^\d+$/.test(e)).map(tu).join(` `);return u?e.kind===`changed`&&lu(e.before)&&lu(e.after)?`${l} - ${u} ${uu(e.before)} to ${uu(e.after)}`:e.kind===`added`&&lu(e.after)?`${l} - ${u} set to ${uu(e.after)}`:`${l} - ${u} ${e.kind}`:`${l} - ${e.kind}`}function fu(e){return e.accepted||e.busy?null:e.hasThread?e.hasBaseline?e.revision?e.cached?`Showing a cached revision. Reload to accept.`:e.reviewLocked?`Exit compare to accept the current revision.`:e.blockers?`Resolve ${e.blockers} blocking ${e.blockers===1?`comment`:`comments`} to accept`:e.canAccept?null:`Accept is unavailable for this revision.`:`Revision unavailable. Reload to accept.`:e.baselineNotice??`No turn baseline is available yet.`:`Open this design from a thread to accept.`}function pu(e){let t=getComputedStyle(e);return{selection:t.getPropertyValue(`--design-selection`).trim()||`#2563EB`,changes:t.getPropertyValue(`--design-change-stroke`).trim()||`#B45309`}}var mu=new Map;function hu(e){let t=(0,W.c)(9),{name:n,x:r,y:i,hidden:a}=e,o;t[0]!==r||t[1]!==i?(o={left:r,top:i},t[0]=r,t[1]=i,t[2]=o):o=t[2];let s;t[3]===n?s=t[4]:(s=(0,K.jsx)(on,{children:n}),t[3]=n,t[4]=s);let c;return t[5]!==a||t[6]!==o||t[7]!==s?(c=(0,K.jsx)(`span`,{className:`design-frame-label`,style:o,hidden:a,children:s}),t[5]=a,t[6]=o,t[7]=s,t[8]=c):c=t[8],c}function gu(e){let t=(0,W.c)(19),{screen:n,frame:r,canvas:i,avoid:a,decoration:o,callout:s}=e;if(n.x+n.width<0||n.y+n.height<0||n.x>i.width||n.y>i.height||!i.width)return null;let c=s?a:null,l;t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==c?(l=Hr(n,r,i,c),t[0]=i,t[1]=r,t[2]=n,t[3]=c,t[4]=l):l=t[4];let{side:u,placement:d,reach:f}=l,p=`${f}px`,m;t[5]!==n.height||t[6]!==n.width||t[7]!==n.x||t[8]!==n.y||t[9]!==p?(m={left:n.x,top:n.y,width:n.width,height:n.height,"--design-agent-edit-reach":p},t[5]=n.height,t[6]=n.width,t[7]=n.x,t[8]=n.y,t[9]=p,t[10]=m):m=t[10];let h=m,g;t[11]===s?g=t[12]:(g=s?(0,K.jsx)(`div`,{className:`design-agent-edit-callout`,children:s}):null,t[11]=s,t[12]=g);let _;return t[13]!==o||t[14]!==d||t[15]!==u||t[16]!==h||t[17]!==g?(_=(0,K.jsxs)(`div`,{className:`design-agent-edit`,"data-side":u,"data-placement":d,style:h,children:[o,g]}),t[13]=o,t[14]=d,t[15]=u,t[16]=h,t[17]=g,t[18]=_):_=t[18],_}var _u=(e,t,n,r,i,a,o=0)=>Lr(Mr(e,t,n).items.map(e=>e.bounds),r,i,a,o);function vu({preferences:e,viewKey:t,chrome:n=`panel`,document:r,theme:i,context:a,assets:o,selection:s,changedNodeIds:c,onSelect:l,annotationMode:u,onAnnotationModeChange:d,onAnchor:f,onOpenAnnotation:p,revision:m,externalViewport:h,onViewportChange:g,renderSelectionOverlay:v,agentEdit:y,frameDecoration:x,batch:S,agents:C}){let w=(0,G.useRef)(null),T=(0,G.useRef)(null),E=(0,G.useRef)({x:0,y:0,width:1,height:1}),D=(0,G.useRef)({width:1,height:1}),O=(0,G.useRef)(0);O.current=!y||n!==`workspace`?0:y.callout?Vr.width:120;let k=(0,G.useRef)(null),A=(0,G.useRef)(null),j=(0,G.useRef)(new Map),M=(0,G.useRef)(null),N=(0,G.useRef)(null),P=(0,G.useRef)(null),F=(0,G.useRef)({document:r,theme:i,context:a,selection:s,changedNodeIds:c,externalViewport:h});F.current={document:r,theme:i,context:a,selection:s,changedNodeIds:c,externalViewport:h};let[I,L]=(0,G.useState)({width:0,height:0}),[R,ee]=(0,G.useState)(!1),[z,B]=(0,G.useState)(E.current),[te,ne]=(0,G.useState)(100),[re,ie]=(0,G.useState)(null),V=(0,G.useCallback)(()=>{let e=w.current,t=[...j.current.keys()];j.current.clear(),A.current=null,M.current=null,N.current&&(N.current.hidden=!0);for(let n of t)e?.hasPointerCapture(n)&&e.releasePointerCapture(n)},[]);(0,G.useEffect)(()=>{let e=()=>{window.document.hidden&&V()};return window.addEventListener(`blur`,V),window.document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`blur`,V),window.document.removeEventListener(`visibilitychange`,e)}},[V]),(0,G.useEffect)(V,[t,u,R,V]);let oe=(0,G.useMemo)(()=>{try{return Mr(r,i,a).items}catch{return null}},[r,i,a]),se=(0,G.useMemo)(()=>{try{let e=oe??Mr(r,i,a).items,t=new Set(r.roots),n=new Set(s),o=e.filter(e=>t.has(e.ownerId)&&e.node.type===`frame`),c=e.filter(e=>n.has(e.ownerId));if(!c.length)return{frames:o,selectionBounds:null};let l=Math.min(...c.map(e=>e.bounds.x)),u=Math.min(...c.map(e=>e.bounds.y)),d=Math.max(...c.map(e=>e.bounds.x+e.bounds.width)),f=Math.max(...c.map(e=>e.bounds.y+e.bounds.height));return{frames:o,selectionBounds:{x:l,y:u,width:d-l,height:f-u}}}catch{return{frames:[],selectionBounds:null}}},[oe,r,i,a,s]),ce=!!y,le=(0,G.useMemo)(()=>{if(!ce||!c.length)return null;let e=new Set(c.flatMap(e=>{let t=r.nodes[e];return t&&`children`in t?t.children:[]})),t=c.findLast(t=>r.nodes[t]&&!e.has(t));if(!t)return null;try{let e=(oe??Mr(r,i,a).items).filter(e=>e.ownerId===t);if(!e.length)return null;let n=Math.min(...e.map(e=>e.bounds.x)),o=Math.min(...e.map(e=>e.bounds.y)),s=Math.max(...e.map(e=>e.bounds.x+e.bounds.width)),c=Math.max(...e.map(e=>e.bounds.y+e.bounds.height));return{nodeId:t,name:r.nodes[t]?.name??``,bounds:{x:n,y:o,width:s-n,height:c-o}}}catch{return null}},[ce,c,oe,r,i,a]),ue=S!==void 0,de=(0,G.useMemo)(()=>{if(!ue||!oe)return null;let e=new Map;for(let t of oe){let n=e.get(t.ownerId);n?n.push(t.bounds):e.set(t.ownerId,[t.bounds])}return new Map([...e].flatMap(([e,t])=>{let n=Al(t);return n?[[e,n]]:[]}))},[ue,oe]),fe=C?.some(e=>e.active)??!1,pe=(0,G.useMemo)(()=>new Set(C?.flatMap(e=>e.workingNodeId?[e.workingNodeId]:[])),[C]),H=I.width/z.width,me=e=>({x:(e.x-z.x)*H,y:(e.y-z.y)*H,width:e.width*H,height:e.height*H}),he=y&&le?me(le.bounds):null,ge=(()=>{if(!le||!he)return null;let{x:e,y:t,width:n,height:r}=le.bounds,i=e+n/2,a=t+r/2,o=se.frames.find(({bounds:e})=>i>=e.x&&i<=e.x+e.width&&a>=e.y&&a<=e.y+e.height)?.bounds;return o?me(o):null})(),[_e,ve]=(0,G.useState)(null),ye=(0,G.useCallback)(e=>{ve(t=>t===e||t&&e&&Math.round(t.x)===Math.round(e.x)&&Math.round(t.y)===Math.round(e.y)&&Math.round(t.width)===Math.round(e.width)&&Math.round(t.height)===Math.round(e.height)?t:e)},[]),be=se.frames.filter(({bounds:e})=>e.x+e.width>=z.x&&e.x<=z.x+z.width&&e.y+e.height>=z.y&&e.y<=z.y+z.height).slice(0,100),xe=se.selectionBounds,Se=xe?{x:(xe.x+xe.width/2-z.x)*H,y:(xe.y+xe.height-z.y)*H}:null,Ce=(0,G.useMemo)(()=>su(r.annotations),[r.annotations]),we=(0,G.useMemo)(()=>{if(!Object.keys(r.annotations).length)return[];let e;try{e=new Map(Mr(r,i,a).items.map(e=>[e.ownerId,e.bounds]))}catch{e=new Map}return Object.entries(r.annotations).flatMap(([t,n])=>{if(n.revision!==m)return[];let r=n.anchor,i=r.kind===`point`?{x:r.x,y:r.y}:r.kind===`region`?{x:r.bounds.x+r.bounds.width/2,y:r.bounds.y+r.bounds.height/2}:(()=>{let t=r.nodeIds.map(t=>e.get(t)).find(Boolean);return t?{x:t.x+t.width,y:t.y}:null})();return i?[{id:t,annotation:n,point:i}]:[]})},[r,i,a,m]),U=(0,G.useCallback)(e=>{let t=P.current;if(t)for(let n of t.querySelectorAll(`[data-design-pin]`)){let t=Number(n.dataset.x),r=Number(n.dataset.y),i=(t-e.x)/e.width*D.current.width,a=(r-e.y)/e.height*D.current.height;n.style.left=`${i}px`,n.style.top=`${a}px`,n.hidden=i<0||a<0||i>D.current.width||a>D.current.height}},[]);(0,G.useEffect)(()=>{let e=w.current;if(!e)return;let t=new ResizeObserver(()=>{if(!e.clientWidth||!e.clientHeight)return;let t=Math.max(1,Math.round(e.clientWidth)),n=Math.max(1,Math.round(e.clientHeight));L(e=>e.width===t&&e.height===n?e:{width:t,height:n})});t.observe(e);let n=e=>e.preventDefault();return e.addEventListener(`wheel`,n,{passive:!1}),()=>{t.disconnect(),e.removeEventListener(`wheel`,n)}},[]);let Te=(0,G.useCallback)(e=>{E.current=e,B(e);let n=T.current;n&&(n.setViewport(e),n.render()),ne(Math.round(D.current.width/e.width*100)),mu.set(t,{bounds:e,width:D.current.width}),U(e),g?.(e)},[t,U,g]);(0,G.useLayoutEffect)(()=>U(E.current),[we,U]),(0,G.useEffect)(()=>{h&&T.current&&Te(h)},[h,Te]),(0,G.useEffect)(()=>{if(!I.width||!I.height||!w.current)return;let e=!1,r=w.current,i=D.current;return D.current=I,ie(null),Cl(r,I.width,I.height,o,()=>{e||ie(`An image could not be decoded. Its placeholder remains visible.`)}).then(a=>{if(e){a.destroy();return}let o=F.current;T.current=a,a.setStrokes(pu(r)),a.setDocument(o.document,o.theme,o.context),a.setSelection(o.selection),a.setChanges(o.changedNodeIds);let s=E.current;if(o.externalViewport)k.current=o.document.documentId,Te(o.externalViewport);else if(k.current!==o.document.documentId){k.current=o.document.documentId;let e=mu.get(t);if(e){let t=e.width/e.bounds.width;Te({...e.bounds,width:I.width/t,height:I.height/t})}else Te(_u(o.document,o.theme,o.context,I.width,I.height,n,O.current))}else{let e=i.width/s.width,t=I.width/e,n=I.height/e;Te({x:s.x+(s.width-t)/2,y:s.y+(s.height-n)/2,width:t,height:n})}}).catch(()=>{e||(T.current?.destroy(),T.current=null,ie(`Canvas could not load. Try reopening this design.`))}),()=>{e=!0,T.current?.destroy(),T.current=null,r.replaceChildren()}},[I.width,I.height,o,t]),(0,G.useEffect)(()=>{let e=T.current;if(e)try{e.setDocument(r,i,a),k.current!==r.documentId&&(k.current=r.documentId,Te(_u(r,i,a,D.current.width,D.current.height,n,O.current))),e.render(),ie(null)}catch{ie(`This design has layout problems. Check diagnostics.`)}},[r,i,a,Te,n]),(0,G.useEffect)(()=>{let e=T.current;e&&(e.setSelection(s),e.render())},[s]),(0,G.useEffect)(()=>{let e=T.current;e&&(e.setChanges(c),e.render())},[c]),(0,G.useEffect)(()=>{let e=w.current;if(!e)return;let t=new MutationObserver(()=>{let t=T.current;t&&(t.setStrokes(pu(e)),t.render())});return t.observe(window.document.documentElement,{attributes:!0,attributeFilter:[`class`,`data-theme`,`style`]}),()=>t.disconnect()},[]);let Ee=(0,G.useCallback)((e,t,n)=>{let r=E.current,i=D.current.width,a=D.current.height,o=Math.max(.05,Math.min(8,i/r.width*e)),s=i/o,c=a/o,l=r.x+t/i*r.width,u=r.y+n/a*r.height;Te({x:l-t/i*s,y:u-n/a*c,width:s,height:c})},[Te]),De=t=>{let n=t.currentTarget.getBoundingClientRect();if(t.ctrlKey||t.metaKey||e?.scrollWheelZoom){let r=e?.invertZoom?1:-1;Ee(Math.exp(r*t.deltaY*.006),t.clientX-n.left,t.clientY-n.top)}else{let e=E.current;Te({...e,x:e.x+t.deltaX*e.width/D.current.width,y:e.y+t.deltaY*e.height/D.current.height})}},Oe=e=>{if(!(e.button!==0&&e.button!==1)){if(e.currentTarget.focus({preventScroll:!0}),j.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),u===`region`&&e.button===0){let t=e.currentTarget.getBoundingClientRect();M.current={x:e.clientX-t.left,y:e.clientY-t.top},e.currentTarget.setPointerCapture(e.pointerId);return}if(u&&e.button===0){A.current={x:e.clientX,y:e.clientY,moved:!1},e.currentTarget.setPointerCapture(e.pointerId);return}A.current=j.current.size===1?{x:e.clientX,y:e.clientY,moved:!1}:null,e.currentTarget.setPointerCapture(e.pointerId)}},ke=e=>{if(e.pointerType!==`touch`&&e.buttons===0){V();return}if(M.current){let t=N.current,n=e.currentTarget.getBoundingClientRect(),r={x:e.clientX-n.left,y:e.clientY-n.top};t&&(t.hidden=!1,t.style.left=`${Math.min(M.current.x,r.x)}px`,t.style.top=`${Math.min(M.current.y,r.y)}px`,t.style.width=`${Math.abs(r.x-M.current.x)}px`,t.style.height=`${Math.abs(r.y-M.current.y)}px`);return}if(u){let t=A.current;t&&Math.abs(e.clientX-t.x)+Math.abs(e.clientY-t.y)>4&&(t.moved=!0);return}let t=j.current;if(!t.has(e.pointerId))return;let n=[...t.values()];if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===2){let r=[...t.values()],i=n[0],a=n[1],o=r[0],s=r[1];if(!i||!a||!o||!s)return;let c=Math.hypot(i.x-a.x,i.y-a.y),l=Math.hypot(o.x-s.x,o.y-s.y);if(c<1||l<1)return;let u=e.currentTarget.getBoundingClientRect(),d={x:(i.x+a.x)/2,y:(i.y+a.y)/2},f={x:(o.x+s.x)/2,y:(o.y+s.y)/2},p=E.current,m=D.current.width,h=D.current.height,g=Math.max(.05,Math.min(8,m/p.width*l/c)),_=m/g,v=h/g,y=p.x+(d.x-u.left)/m*p.width,b=p.y+(d.y-u.top)/h*p.height;Te({x:y-(f.x-u.left)/m*_,y:b-(f.y-u.top)/h*v,width:_,height:v});return}let r=A.current;if(!r)return;let i=e.clientX-r.x,a=e.clientY-r.y;if(Math.abs(i)+Math.abs(a)>2&&(r.moved=!0),r.moved){let e=E.current;Te({...e,x:e.x-i*e.width/D.current.width,y:e.y-a*e.height/D.current.height})}r.x=e.clientX,r.y=e.clientY},Ae=e=>{if(M.current){let t=M.current;M.current=null,j.current.delete(e.pointerId),N.current&&(N.current.hidden=!0);let n=e.currentTarget.getBoundingClientRect(),r={x:e.clientX-n.left,y:e.clientY-n.top};if(Math.abs(r.x-t.x)<4||Math.abs(r.y-t.y)<4)return;let i=E.current,a=i.x+Math.min(t.x,r.x)/n.width*i.width,o=i.y+Math.min(t.y,r.y)/n.height*i.height;f?.({kind:`region`,bounds:{x:a,y:o,width:Math.abs(r.x-t.x)/n.width*i.width,height:Math.abs(r.y-t.y)/n.height*i.height}});return}let t=j.current.size>1;if(j.current.delete(e.pointerId),t){let e=j.current.values().next().value;A.current=e?{...e,moved:!0}:null;return}let n=A.current;if(A.current=null,!n||n.moved||R||e.button===1)return;let r=e.currentTarget.getBoundingClientRect(),i=E.current,a=i.x+(e.clientX-r.left)/r.width*i.width,o=i.y+(e.clientY-r.top)/r.height*i.height,s=T.current?.hitTest(a,o);if(u===`pin`){f?.({kind:`point`,x:a,y:o});return}if(u===`nodes`){s&&f?.({kind:`nodes`,nodeIds:[s]});return}l(s?[s]:[])};return(0,K.jsxs)(`div`,{className:`design-canvas-wrap`,children:[(0,K.jsx)(`div`,{className:`design-canvas-tools`,role:`toolbar`,"aria-label":`Canvas controls`,children:[{label:`Select`,icon:Et,active:!R&&!u,run:()=>{ee(!1),d?.(null)}},{label:`Pan`,icon:Fn,active:R&&!u,run:()=>{ee(!0),d?.(null)}},...d?[{label:`Pin`,mode:`pin`,icon:Ln},{label:`Region`,mode:`region`,icon:xt},{label:`Node`,mode:`nodes`,icon:Pn}].map(({label:e,mode:t,icon:n})=>({label:e,icon:n,active:u===t,run:()=>{ee(!1),d(t)}})):[],{label:`Fit`,icon:Dt,active:void 0,run:()=>Te(_u(r,i,a,D.current.width,D.current.height,n,O.current))}].map(({label:e,icon:t,active:n,run:r})=>(0,K.jsxs)(G.Fragment,{children:[e===`Fit`?(0,K.jsx)(`span`,{className:`design-tool-separator`,"aria-hidden":`true`}):null,(0,K.jsxs)(ae,{children:[(0,K.jsx)(Fe,{render:(0,K.jsx)(_,{size:`icon-sm`,variant:`ghost`,"aria-label":e,"aria-pressed":n,className:`aria-pressed:bg-accent`,onClick:r}),children:(0,K.jsx)(t,{"aria-hidden":`true`})}),(0,K.jsx)(b,{children:e})]})]},e))}),(0,K.jsxs)(`div`,{className:`design-canvas-zoom`,"aria-label":`Canvas zoom`,children:[(0,K.jsxs)(ae,{children:[(0,K.jsx)(Fe,{render:(0,K.jsx)(_,{size:`icon-sm`,variant:`ghost`,"aria-label":`Zoom out`,onClick:()=>Ee(1/1.5,D.current.width/2,D.current.height/2)}),children:(0,K.jsx)(wt,{"aria-hidden":`true`})}),(0,K.jsx)(b,{children:`Zoom out`})]}),(0,K.jsxs)(`output`,{"aria-label":`Zoom level`,children:[te,`%`]}),(0,K.jsxs)(ae,{children:[(0,K.jsx)(Fe,{render:(0,K.jsx)(_,{size:`icon-sm`,variant:`ghost`,"aria-label":`Zoom in`,onClick:()=>Ee(1.5,D.current.width/2,D.current.height/2)}),children:(0,K.jsx)(Bt,{"aria-hidden":`true`})}),(0,K.jsx)(b,{children:`Zoom in`})]})]}),(0,K.jsxs)(`div`,{className:`design-frame-labels`,children:[x?be.map(e=>(0,K.jsx)(`div`,{className:`design-frame-mark`,style:{left:(e.bounds.x-z.x)*H,top:(e.bounds.y-z.y)*H,width:e.bounds.width*H,height:e.bounds.height*H},children:typeof x==`function`?x({name:e.node.name,width:e.bounds.width,height:e.bounds.height}):x},`mark:${e.key}`)):null,be.map(e=>(0,K.jsx)(hu,{name:e.node.name,x:(e.bounds.x-z.x)*H,y:(e.bounds.y-z.y)*H,hidden:pe.has(e.ownerId)},e.key))]}),Se&&xe&&Se.x>=0&&Se.x<=I.width&&Se.y>=0&&Se.y<=I.height?(0,K.jsxs)(`output`,{className:`design-selection-badge`,"aria-label":`Selection dimensions`,style:{left:Se.x,top:Se.y},children:[Math.round(xe.width),` × `,Math.round(xe.height)]}):null,y&&le&&he?(0,K.jsx)(gu,{frame:ge,screen:he,canvas:I,avoid:v&&xe?_e:null,decoration:fe?void 0:y.decoration,callout:fe?void 0:y.callout?.({nodeId:le.nodeId,name:le.name})},le.nodeId):null,de&&I.width&&I.height?(0,K.jsx)(ql,{document:r,bounds:de,viewport:z,canvas:I,batch:S??null,agents:C,cursorSize:e?.agentCursorSize,cursorLabel:e?.agentCursorLabel,animations:e?.animations,onReveal:e=>Te(Fl(e,E.current,D.current))}):null,v&&xe&&I.width&&I.height?v({screen:{x:(xe.x-z.x)*H,y:(xe.y-z.y)*H,width:xe.width*H,height:xe.height*H},world:xe,canvas:I,avoid:he,onPlaced:ye}):null,(0,K.jsx)(`div`,{ref:w,className:`design-canvas-surface ${R?`design-canvas-pan`:``}`,role:`application`,"aria-label":u?`Design canvas. ${u===`region`?`Drag a region`:`Click to place an annotation`}; arrow keys move the view and Enter anchors the selection or view center.`:`Design canvas. Drag to pan, ${e?.scrollWheelZoom?`scroll or pinch`:`pinch or Control and wheel`} to zoom, click to select.`,tabIndex:0,onWheel:De,onPointerDown:Oe,onPointerMove:ke,onPointerUp:Ae,onPointerCancel:V,onLostPointerCapture:e=>{j.current.has(e.pointerId)&&V()},onBlur:V,onKeyDown:e=>{if(e.key===`Enter`&&u){let t=E.current,n=t.x+t.width/2,r=t.y+t.height/2;if(u===`pin`)f?.({kind:`point`,x:n,y:r});else if(u===`region`)f?.({kind:`region`,bounds:{x:n-t.width/8,y:r-t.height/8,width:t.width/4,height:t.height/4}});else{let e=s[0]??T.current?.hitTest(n,r);e&&f?.({kind:`nodes`,nodeIds:[e]})}e.preventDefault();return}(e.key===`+`||e.key===`=`)&&(Ee(1.5,D.current.width/2,D.current.height/2),e.preventDefault()),e.key===`-`&&(Ee(1/1.5,D.current.width/2,D.current.height/2),e.preventDefault()),e.key===`Escape`&&(V(),d?.(null),ee(!1),l([]),e.preventDefault()),e.key===`Home`&&(Te(_u(r,i,a,D.current.width,D.current.height,n,O.current)),e.preventDefault());let t=e.key===`ArrowLeft`?[-40,0]:e.key===`ArrowRight`?[40,0]:e.key===`ArrowUp`?[0,-40]:e.key===`ArrowDown`?[0,40]:null;if(t){let n=E.current;Te({...n,x:n.x+t[0]*n.width/D.current.width,y:n.y+t[1]*n.height/D.current.height}),e.preventDefault()}}}),e?.showPixelGrid&&H>=4?(0,K.jsx)(`div`,{className:`design-pixel-grid`,"aria-hidden":`true`,style:{backgroundSize:`${H}px ${H}px`,backgroundPosition:`${-z.x*H}px ${-z.y*H}px`}}):null,(0,K.jsx)(`div`,{ref:P,className:`design-annotation-pins`,children:p?we.map(({id:e,annotation:t,point:n})=>{let r=t.blocking&&t.status===`open`,i=Ce.get(e)??0;return(0,K.jsxs)(ae,{children:[(0,K.jsx)(Fe,{render:(0,K.jsx)(`button`,{type:`button`,"data-design-pin":!0,"data-x":n.x,"data-y":n.y,"aria-label":`Open ${r?`blocking `:``}comment ${i} by ${t.author}`,className:`design-annotation-pin${r?` design-annotation-pin-blocking`:``}${t.status===`resolved`?` design-annotation-pin-resolved`:``}`,onClick:()=>p?.(e)}),children:(0,K.jsx)(`span`,{"aria-hidden":`true`,children:r?`!`:i})}),(0,K.jsxs)(b,{children:[(0,K.jsx)(`strong`,{children:t.author}),` `,t.body.split(`
|
|
18
18
|
`,1)[0]]})]},e)}):null}),(0,K.jsx)(`div`,{ref:N,className:`design-annotation-region`,hidden:!0}),re?(0,K.jsx)(`div`,{className:`design-canvas-error`,role:`alert`,children:re}):null]})}function yu(e){return e===void 0?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?`${e.length} items`:`Object`}function bu(e){let t=(0,W.c)(43),{preferences:n,before:r,after:i,beforeRevision:a,afterRevision:o,viewKey:s,theme:c,beforeContext:l,beforeAssets:u,context:d,assets:f,selection:p,onSelect:m,onExit:h}=e,[g,v]=(0,G.useState)(`Before / after`),[y,b]=(0,G.useState)(50),[x,S]=(0,G.useState)(),C;t[0]!==i||t[1]!==r?(C=Nr(r,i).filter(wu),t[0]=i,t[1]=r,t[2]=C):C=t[2];let w=C,T;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,K.jsx)(`strong`,{children:`Compare revisions`}),t[3]=T):T=t[3];let E;t[4]===a?E=t[5]:(E=a.slice(0,8),t[4]=a,t[5]=E);let D;t[6]===o?D=t[7]:(D=o.slice(0,8),t[6]=o,t[7]=D);let O;t[8]!==E||t[9]!==D?(O=(0,K.jsxs)(`div`,{className:`design-compare-revisions`,children:[T,(0,K.jsxs)(`span`,{className:`design-small-muted`,children:[`Before `,E,` · After `,D]})]}),t[8]=E,t[9]=D,t[10]=O):O=t[10];let k;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(k=[`Before / after`,`Overlay`,`Changes`],t[11]=k):k=t[11];let A;t[12]===g?A=t[13]:(A=(0,K.jsx)(`nav`,{"aria-label":`Compare display`,children:k.map(e=>(0,K.jsx)(`button`,{type:`button`,"aria-current":g===e?`page`:void 0,onClick:()=>v(e),children:e},e))}),t[12]=g,t[13]=A);let j;t[14]===h?j=t[15]:(j=(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:h,children:`Exit compare`}),t[14]=h,t[15]=j);let M;t[16]!==A||t[17]!==j?(M=(0,K.jsxs)(`div`,{className:`design-compare-controls`,children:[A,j]}),t[16]=A,t[17]=j,t[18]=M):M=t[18];let N;t[19]!==O||t[20]!==M?(N=(0,K.jsxs)(`header`,{className:`design-compare-header`,children:[O,M]}),t[19]=O,t[20]=M,t[21]=N):N=t[21];let P;t[22]!==i||t[23]!==o||t[24]!==f||t[25]!==r||t[26]!==u||t[27]!==l||t[28]!==a||t[29]!==w||t[30]!==d||t[31]!==g||t[32]!==m||t[33]!==y||t[34]!==x||t[35]!==n||t[36]!==p||t[37]!==c||t[38]!==s?(P=g===`Changes`?(0,K.jsx)(`div`,{className:`design-compare-changes`,children:w.length?(0,K.jsx)(`ol`,{children:w.map(Cu)}):(0,K.jsx)(`p`,{children:`No content changes between these revisions.`})}):g===`Before / after`?(0,K.jsxs)(`div`,{className:`design-compare-pair`,children:[(0,K.jsxs)(`section`,{"aria-label":`Before revision ${a}`,children:[(0,K.jsxs)(`div`,{className:`design-compare-caption`,children:[`Before · `,a.slice(0,8)]}),(0,K.jsx)(vu,{preferences:n,viewKey:`${s}:compare-before`,document:r,theme:c,context:l,assets:u,selection:[],changedNodeIds:[],onSelect:Su})]}),(0,K.jsxs)(`section`,{"aria-label":`After revision ${o}`,children:[(0,K.jsxs)(`div`,{className:`design-compare-caption`,children:[`After · `,o.slice(0,8)]}),(0,K.jsx)(vu,{preferences:n,viewKey:`${s}:compare-after`,document:i,theme:c,context:d,assets:f,selection:p,changedNodeIds:[],onSelect:m})]})]}):(0,K.jsxs)(`div`,{className:`design-compare-overlay`,children:[(0,K.jsxs)(`label`,{className:`design-compare-opacity`,children:[`After opacity`,` `,(0,K.jsx)(`input`,{type:`range`,min:`0`,max:`100`,value:y,onChange:e=>b(Number(e.target.value))}),` `,y,`%`]}),(0,K.jsxs)(`div`,{className:`design-compare-overlay-stack`,children:[(0,K.jsx)(vu,{preferences:n,viewKey:`${s}:compare-overlay-before`,document:r,theme:c,context:l,assets:u,selection:[],changedNodeIds:[],onSelect:xu,externalViewport:x}),(0,K.jsx)(`div`,{style:{"--design-after-opacity":y/100},"aria-label":`After revision ${o}`,children:(0,K.jsx)(vu,{preferences:n,viewKey:`${s}:compare-overlay-after`,document:i,theme:c,context:d,assets:f,selection:p,changedNodeIds:[],onSelect:m,onViewportChange:S})})]})]}),t[22]=i,t[23]=o,t[24]=f,t[25]=r,t[26]=u,t[27]=l,t[28]=a,t[29]=w,t[30]=d,t[31]=g,t[32]=m,t[33]=y,t[34]=x,t[35]=n,t[36]=p,t[37]=c,t[38]=s,t[39]=P):P=t[39];let F;return t[40]!==N||t[41]!==P?(F=(0,K.jsxs)(`div`,{className:`design-compare`,children:[N,P]}),t[40]=N,t[41]=P,t[42]=F):F=t[42],F}function xu(){}function Su(){}function Cu(e){return(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`strong`,{children:e.kind}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`code`,{children:e.path}),(0,K.jsxs)(`small`,{children:[yu(e.before),` → `,yu(e.after)]})]})]},e.path)}function wu(e){return!/^\/(annotations|reviews|acceptances)(\/|$)/.test(e.path)}function Tu(e){let t=(0,W.c)(16),n=Un(),r=qn(),i=(0,G.useRef)(null),[a,o]=(0,G.useState)(!1),[s,c]=(0,G.useState)(null),[l,u]=(0,G.useState)(null),d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=[],t[0]=d):d=t[0];let[f,p]=(0,G.useState)(d),[m,h]=(0,G.useState)(null),g,_;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>()=>i.current?.abort(),_=[],t[1]=g,t[2]=_):(g=t[1],_=t[2]),(0,G.useEffect)(g,_);let v;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(v=()=>i.current?.abort(),t[3]=v):v=t[3];let y=v,b;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(b=()=>{y(),c(null),u(null),p([]),h(null)},t[4]=b):b=t[4];let x=b,S;t[5]!==n||t[6]!==r||t[7]!==e?(S=async t=>{if(!e)return null;y();let a=new AbortController;i.current=a,o(!0),c(null),u(null),p([]),h(null);let s=[],l=null,d=M(()=>new Promise(e=>{a.signal.aborted?e():a.signal.addEventListener(`abort`,()=>e(),{once:!0})})),f=null;try{await r(I(tt(n.transport.transfer(e,t),e=>re(()=>{a.signal.aborted||(e.kind===`progress`&&c(e),e.kind===`chunk`&&s.push(Uint8Array.from(atob(e.base64),Eu)),e.kind===`complete`&&(l=e))})),d))}catch(e){f={cause:e}}if(i.current!==a)return null;let m=a.signal.aborted;return i.current===a&&(i.current=null),a.abort(),o(!1),m?null:f?(h(f.cause instanceof Error?f.cause.message:String(f.cause)),null):l?(u(l),p(s),l):(h(`Transfer ended before a result was received.`),null)},t[5]=n,t[6]=r,t[7]=e,t[8]=S):S=t[8];let C=S,w;return t[9]!==a||t[10]!==f||t[11]!==m||t[12]!==s||t[13]!==l||t[14]!==C?(w={busy:a,progress:s,result:l,bytes:f,error:m,run:C,cancel:y,reset:x},t[9]=a,t[10]=f,t[11]=m,t[12]=s,t[13]=l,t[14]=C,t[15]=w):w=t[15],w}function Eu(e){return e.charCodeAt(0)}var Du={svg:`.svg,image/svg+xml`,png:`.png,image/png`,jpeg:`.jpg,.jpeg,image/jpeg`,webp:`.webp,image/webp`,"figma-rest":``,"figma-plugin":`.json,application/json`},Ou=[[`svg`,`SVG`],[`png`,`PNG`],[`jpeg`,`JPEG`],[`webp`,`WebP`],[`figma-rest`,`Figma URL`],[`figma-plugin`,`Figma plugin bundle`]];function ku(e){let t=(0,W.c)(18),{id:n,value:r,onChange:i,options:a,disabled:o}=e,s;t[0]===a?s=t[1]:(s=a.map(ju),t[0]=a,t[1]=s);let c;t[2]===i?c=t[3]:(c=e=>{e!==null&&i(e)},t[2]=i,t[3]=c);let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,K.jsx)(Se,{}),t[4]=l):l=t[4];let u;t[5]===n?u=t[6]:(u=(0,K.jsx)(ze,{id:n,children:l}),t[5]=n,t[6]=u);let d;t[7]===a?d=t[8]:(d=a.map(Au),t[7]=a,t[8]=d);let f;t[9]===d?f=t[10]:(f=(0,K.jsx)(Ae,{children:d}),t[9]=d,t[10]=f);let p;return t[11]!==o||t[12]!==s||t[13]!==c||t[14]!==u||t[15]!==f||t[16]!==r?(p=(0,K.jsxs)(L,{modal:!1,value:r,disabled:o,items:s,onValueChange:c,children:[u,f]}),t[11]=o,t[12]=s,t[13]=c,t[14]=u,t[15]=f,t[16]=r,t[17]=p):p=t[17],p}function Au(e){let[t,n,r]=e;return(0,K.jsx)(Ge,{value:t,disabled:r,children:n},String(t))}function ju(e){let[t,n]=e;return{value:t,label:n}}async function Mu(e){let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=8192)n+=String.fromCharCode(...t.subarray(e,e+8192));return btoa(n)}function Nu(e,t,n){let r=new Blob(e.map(e=>new Uint8Array(e)),{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,a.click(),setTimeout(()=>URL.revokeObjectURL(i),3e4)}function Pu({open:e,mode:t,onModeChange:n,onOpenChange:r,target:i,documentPath:a,revision:o,document:s,selection:c,theme:l,onImportComplete:u,onOpenImported:d}){let f=Tu(i),[p,m]=(0,G.useState)(`svg`),[h,g]=(0,G.useState)(`png`),[v,y]=(0,G.useState)(null),[b,x]=(0,G.useState)(``),[S,C]=(0,G.useState)(``),[w,T]=(0,G.useState)(``),[E,D]=(0,G.useState)(!1),[O,k]=(0,G.useState)(`selection`),[A,j]=(0,G.useState)(1),[M,N]=(0,G.useState)(`transparent`),[P,F]=(0,G.useState)(null),[I,L]=(0,G.useState)(!1),R=(0,G.useRef)(0),ee=(0,G.useRef)(null),z=f.busy&&f.progress?.stage===`Saving document`,B=s?Object.entries(s.nodes).filter(([,e])=>e.type===`frame`):[],te=i?{projectId:i.projectId,...i.threadId?{threadId:i.threadId}:{}}:null,ne=e=>{if(!e){if(z)return;R.current+=1,f.reset(),L(!1),C(``),y(null),x(``),T(``),F(null)}r(e)},re=async()=>{if(!te)return;if(F(null),t===`import`){let e=w.trim();if(!e.toLowerCase().endsWith(`.p4design`)){F(`Choose a new .p4design destination path.`);return}if(p===`figma-rest`?!b.trim():!v){F(p===`figma-rest`?`Enter a Figma file URL.`:`Choose a file.`);return}L(!0);let t=++R.current,n;try{v&&p!==`figma-rest`&&(n=await Mu(v))}catch{F(`The selected file could not be read. Choose it again.`),L(!1);return}if(R.current!==t)return;L(!1),await f.run({kind:`import`,target:te,documentPath:e,format:p,sourceName:v?.name??b.trim(),...n?{payload:n}:{},...p===`figma-rest`?{url:b.trim(),...S.trim()?{token:S.trim()}:{}}:{},allowMissingAssets:E})&&u();return}let e=O===`selection`?c.length?[...c]:B[0]?[B[0][0]]:[]:[O];if(!s||!a||!o||!e.length){F(`Select a node or frame in a ready design to export.`);return}await f.run({kind:`export`,target:te,documentPath:a,expectedContentHash:o,nodeIds:e,format:h,scale:A,background:M,theme:l})};return(0,K.jsx)($t,{open:e,onOpenChange:ne,children:(0,K.jsxs)(Rt,{className:`design-transfer-dialog max-w-lg`,showCloseButton:!z,children:[(0,K.jsxs)(mt,{children:[(0,K.jsx)(_t,{children:`Design transfer`}),(0,K.jsx)(An,{children:`Import a design or export selected canvas content.`})]}),(0,K.jsxs)(On,{className:`design-transfer-panel`,children:[(0,K.jsx)(`div`,{className:`design-transfer-tabs`,role:`tablist`,"aria-label":`Transfer direction`,children:[`import`,`export`].map(e=>(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t===e,disabled:f.busy||I,onClick:()=>{n(e),f.reset(),F(null)},children:e===`import`?`Import`:`Export`},e))}),t===`import`?(0,K.jsxs)(`div`,{className:`design-transfer-fields`,children:[(0,K.jsx)(Mn,{htmlFor:`design-import-format`,children:`Source format`}),(0,K.jsx)(ku,{id:`design-import-format`,value:p,disabled:f.busy||I,options:Ou,onChange:e=>{m(e),y(null),f.reset()}}),p===`figma-rest`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Mn,{htmlFor:`design-figma-url`,children:`Figma file URL`}),(0,K.jsx)(lt,{id:`design-figma-url`,type:`url`,value:b,onChange:e=>x(e.target.value)}),(0,K.jsx)(Mn,{htmlFor:`design-figma-token`,children:`Figma token`}),(0,K.jsx)(lt,{id:`design-figma-token`,type:`password`,value:S,onChange:e=>C(e.target.value),placeholder:`Leave blank to use stored token`,autoComplete:`off`})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Mn,{htmlFor:`design-import-file`,children:`Source file`}),(0,K.jsxs)(`div`,{className:`design-transfer-file`,children:[(0,K.jsx)(_,{id:`design-import-file`,size:`sm`,variant:`outline`,disabled:f.busy||I,onClick:()=>ee.current?.click(),children:`Choose file`}),(0,K.jsx)(`span`,{className:`design-truncate design-small-muted`,"aria-live":`polite`,children:v?v.name:`No file chosen`}),(0,K.jsx)(`input`,{ref:ee,type:`file`,hidden:!0,accept:Du[p],onChange:e=>{let t=e.target.files?.[0]??null;e.target.value=``,y(t),t&&!w.trim()&&T(`${t.name.replace(/\.[^.]+$/,``)}.p4design`)}})]}),p===`figma-plugin`?(0,K.jsx)(`p`,{className:`design-transfer-hint`,children:`Choose the JSON bundle exported by the Figma plugin.`}):null]}),(0,K.jsx)(Mn,{htmlFor:`design-import-destination`,children:`New design path`}),(0,K.jsx)(lt,{id:`design-import-destination`,value:w,onChange:e=>T(e.target.value),placeholder:`home.p4design`}),(0,K.jsxs)(`label`,{className:`design-transfer-checkbox`,children:[(0,K.jsx)(un,{checked:E,onCheckedChange:e=>D(e===!0)}),`Import with placeholders if assets fail`]})]}):(0,K.jsxs)(`div`,{className:`design-transfer-fields`,children:[!s||!o?(0,K.jsx)(`p`,{className:`design-transfer-hint`,children:`Open a ready design to export.`}):null,(0,K.jsx)(Mn,{htmlFor:`design-export-scope`,children:`Export content`}),(0,K.jsx)(ku,{id:`design-export-scope`,value:!c.length&&O===`selection`?B[0]?.[0]??O:O,onChange:k,options:[[`selection`,`Selection (${c.length})`,!c.length],...B.map(([e,t])=>[e,`Frame: ${t.name||e.slice(0,8)}`])]}),(0,K.jsx)(Mn,{htmlFor:`design-export-format`,children:`Format`}),(0,K.jsx)(ku,{id:`design-export-format`,value:h,onChange:g,options:[[`png`,`PNG`],[`svg`,`SVG`],[`pdf`,`PDF`]]}),(0,K.jsx)(Mn,{htmlFor:`design-export-scale`,children:`Scale`}),(0,K.jsx)(ku,{id:`design-export-scale`,value:A,onChange:j,options:[[.5,`0.5x`],[1,`1x`],[2,`2x`],[4,`4x`]]}),(0,K.jsx)(Mn,{htmlFor:`design-export-background`,children:`Background`}),(0,K.jsx)(ku,{id:`design-export-background`,value:M,onChange:N,options:[[`transparent`,`Transparent`],[`#FFFFFF`,`White`]]})]}),I?(0,K.jsx)(`p`,{role:`status`,children:`Reading source file…`}):null,f.progress&&!f.result&&!f.error&&!P?(0,K.jsxs)(`div`,{className:`design-transfer-progress`,role:`status`,children:[(0,K.jsx)(`span`,{children:z?`Finishing save`:f.progress.stage}),(0,K.jsx)(`progress`,{value:f.progress.total>0?f.progress.completed:void 0,max:f.progress.total||void 0}),f.progress.total>0?(0,K.jsxs)(`small`,{children:[f.progress.completed,` / `,f.progress.total]}):null]}):null,P||f.error?(0,K.jsx)(`p`,{className:`design-transfer-error`,role:`alert`,children:P??f.error}):null,f.result?(0,K.jsxs)(`div`,{className:`design-transfer-result`,role:`status`,children:[(0,K.jsx)(`strong`,{children:t===`import`?`Import complete`:`Export ready`}),(0,K.jsxs)(`span`,{children:[`Source: `,f.result.provenance]}),f.result.unsupported.length?(0,K.jsxs)(`span`,{children:[`Unsupported: `,f.result.unsupported.join(`, `)]}):null,f.result.failedAssets.length?(0,K.jsxs)(`span`,{children:[`Failed assets: `,f.result.failedAssets.join(`, `)]}):null,f.result.diagnostics.length?(0,K.jsx)(`ul`,{children:[...new Set(f.result.diagnostics.map(e=>e.message))].map(e=>(0,K.jsx)(`li`,{children:e},e))}):null,t===`import`?(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:()=>{d(f.result.documentPath),ne(!1)},children:`Open design`}):f.result.filename&&f.result.mimeType&&f.bytes.length?(0,K.jsxs)(_,{size:`sm`,variant:`outline`,onClick:()=>Nu(f.bytes,f.result.filename,f.result.mimeType),children:[`Download `,f.result.filename]}):null]}):null]}),(0,K.jsxs)(It,{children:[(0,K.jsx)(_,{variant:`outline`,disabled:z,onClick:()=>ne(!1),children:z?`Finishing save`:f.busy||I?`Cancel`:`Close`}),(0,K.jsx)(_,{disabled:!i||f.busy||I||t===`export`&&(!s||!o||!c.length&&!B.length),onClick:()=>void re(),children:f.error||P?`Retry`:t===`import`?`Import`:`Export`})]})]})})}var Fu=e=>`${e}T00:00:00.000Z`;function Iu(e,t,n){let r=e.slice(0,10);return`${t===`open`&&r<n?`Overdue`:`Due`} ${r}`}var Lu=e=>{Promise.resolve().then(e).catch(()=>{})};function Ru(e){let t=(0,W.c)(49),{anchor:n,onSubmit:r,onCancel:i,busy:a}=e,o=a===void 0?!1:a,[s,c]=(0,G.useState)(``),[l,u]=(0,G.useState)(``),[d,f]=(0,G.useState)(``),[p,m]=(0,G.useState)(``),[h,g]=(0,G.useState)(!1),v=n.kind===`nodes`?`${n.nodeIds.length} selected ${n.nodeIds.length===1?`node`:`nodes`}`:n.kind===`region`?`Canvas region`:`Canvas pin`,y;t[0]!==n||t[1]!==l||t[2]!==h||t[3]!==s||t[4]!==o||t[5]!==p||t[6]!==d||t[7]!==r?(y=e=>{e.preventDefault(),!(!s.trim()||o)&&Lu(()=>r({anchor:n,body:s.trim(),blocking:h,labels:d.split(`,`).map(zu).filter(Boolean),...l.trim()?{assignee:l.trim()}:{},...p?{dueAt:Fu(p)}:{}}))},t[0]=n,t[1]=l,t[2]=h,t[3]=s,t[4]=o,t[5]=p,t[6]=d,t[7]=r,t[8]=y):y=t[8];let b;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,K.jsx)(`strong`,{children:`New comment`}),t[9]=b):b=t[9];let x;t[10]===v?x=t[11]:(x=(0,K.jsxs)(`div`,{className:`design-editor-heading`,children:[b,(0,K.jsxs)(`span`,{className:`design-small-muted`,children:[`Anchored to `,v,` in this revision`]})]}),t[10]=v,t[11]=x);let S;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(S=e=>c(e.target.value),t[12]=S):S=t[12];let C;t[13]===s?C=t[14]:(C=(0,K.jsxs)(`label`,{children:[`Comment`,(0,K.jsx)(`textarea`,{value:s,onChange:S,rows:3,required:!0,placeholder:`What should be reviewed?`})]}),t[13]=s,t[14]=C);let w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w=e=>u(e.target.value),t[15]=w):w=t[15];let T;t[16]===l?T=t[17]:(T=(0,K.jsxs)(`label`,{children:[`Assignee`,(0,K.jsx)(`input`,{value:l,onChange:w})]}),t[16]=l,t[17]=T);let E;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(E=e=>m(e.target.value),t[18]=E):E=t[18];let D;t[19]===p?D=t[20]:(D=(0,K.jsxs)(`label`,{children:[`Due`,(0,K.jsx)(`input`,{type:`date`,value:p,onChange:E})]}),t[19]=p,t[20]=D);let O;t[21]!==D||t[22]!==T?(O=(0,K.jsxs)(`div`,{className:`design-editor-fields`,children:[T,D]}),t[21]=D,t[22]=T,t[23]=O):O=t[23];let k;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,K.jsx)(`span`,{className:`design-small-muted`,children:`(comma separated)`}),t[24]=k):k=t[24];let A;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(A=e=>f(e.target.value),t[25]=A):A=t[25];let j;t[26]===d?j=t[27]:(j=(0,K.jsxs)(`label`,{children:[`Labels `,k,(0,K.jsx)(`input`,{value:d,onChange:A})]}),t[26]=d,t[27]=j);let M;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(M=e=>g(e.target.checked),t[28]=M):M=t[28];let N;t[29]===h?N=t[30]:(N=(0,K.jsxs)(`label`,{className:`design-editor-checkbox`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:M}),`Block acceptance until resolved`]}),t[29]=h,t[30]=N);let P;t[31]===i?P=t[32]:(P=(0,K.jsx)(_,{type:`button`,size:`sm`,variant:`ghost`,onClick:i,children:`Cancel`}),t[31]=i,t[32]=P);let F;t[33]!==s||t[34]!==o?(F=o||!s.trim(),t[33]=s,t[34]=o,t[35]=F):F=t[35];let I;t[36]===F?I=t[37]:(I=(0,K.jsx)(_,{type:`submit`,size:`sm`,disabled:F,children:`Post comment`}),t[36]=F,t[37]=I);let L;t[38]!==P||t[39]!==I?(L=(0,K.jsxs)(`div`,{className:`design-editor-actions`,children:[P,I]}),t[38]=P,t[39]=I,t[40]=L):L=t[40];let R;return t[41]!==O||t[42]!==j||t[43]!==N||t[44]!==y||t[45]!==L||t[46]!==x||t[47]!==C?(R=(0,K.jsxs)(`form`,{className:`design-annotation-editor`,onSubmit:y,children:[x,C,O,j,N,L]}),t[41]=O,t[42]=j,t[43]=N,t[44]=y,t[45]=L,t[46]=x,t[47]=C,t[48]=R):R=t[48],R}function zu(e){return e.trim()}function Bu(e){let t=(0,W.c)(17),{document:n,currentRevision:r,actions:i,busy:a,focusedId:o}=e,s=a===void 0?!1:a,[c,l]=(0,G.useState)(null),[u,d]=(0,G.useState)(``),f=Object.entries(n.annotations).sort(Uu),p;t[0]===n.annotations?p=t[1]:(p=su(n.annotations),t[0]=n.annotations,t[1]=p);let m=p,h;t[2]===o?h=t[3]:(h=()=>{o&&globalThis.document.getElementById(`design-comment-${o}`)?.scrollIntoView({block:`nearest`})},t[2]=o,t[3]=h);let v;if(t[4]!==n||t[5]!==o?(v=[o,n],t[4]=n,t[5]=o,t[6]=v):v=t[6],(0,G.useEffect)(h,v),!f.length){let e;return t[7]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,K.jsx)(`div`,{className:`design-notice`,children:(0,K.jsx)(`strong`,{children:`No comments`})}),t[7]=e):e=t[7],e}let y;t[8]!==i||t[9]!==s||t[10]!==r||t[11]!==m||t[12]!==u||t[13]!==c?(y=e=>{let[t,n]=e;return(0,K.jsxs)(`article`,{id:`design-comment-${t}`,className:`design-comment`,children:[(0,K.jsxs)(`div`,{className:`design-comment-heading`,children:[(0,K.jsx)(`span`,{className:`design-comment-number${n.blocking&&n.status===`open`?` design-comment-number-blocking`:``}`,"aria-label":`Comment ${m.get(t)??``}`,children:m.get(t)}),(0,K.jsx)(`strong`,{children:n.author}),(0,K.jsx)(`span`,{className:`design-small-muted`,children:n.status===`open`?`Open`:`Resolved`})]}),(0,K.jsx)(`p`,{children:n.body}),(0,K.jsxs)(`div`,{className:`design-comment-meta`,children:[n.blocking&&n.status===`open`?(0,K.jsx)(g,{variant:`warning`,children:`Blocking`}):null,(0,K.jsx)(`span`,{children:n.anchor.kind===`nodes`?`${n.anchor.nodeIds.length} ${n.anchor.nodeIds.length===1?`layer`:`layers`}`:n.anchor.kind===`region`?`Region`:`Pin`}),n.revision===r?null:(0,K.jsxs)(`span`,{children:[`Revision `,n.revision.slice(0,8)]}),n.assignee?(0,K.jsxs)(`span`,{children:[`Assigned to `,n.assignee]}):null,n.dueAt?(0,K.jsx)(`span`,{children:Iu(n.dueAt,n.status,new Date().toISOString().slice(0,10))}):null,n.labels.map(Hu)]}),n.replies.map(Vu),i?(0,K.jsxs)(`div`,{className:`design-comment-actions`,children:[(0,K.jsx)(_,{size:`sm`,variant:`ghost`,disabled:s,onClick:()=>{l(t),d(``)},children:`Reply`}),(0,K.jsx)(_,{size:`sm`,variant:`ghost`,disabled:s,onClick:()=>Lu(()=>i.setResolved(t,n.status===`open`)),children:n.status===`open`?`Resolve`:`Reopen`})]}):null,c===t&&i?(0,K.jsxs)(`form`,{className:`design-reply-form`,onSubmit:e=>{e.preventDefault(),!(!u.trim()||s)&&Lu(async()=>{await i.reply(t,u.trim()),l(null),d(``)})},children:[(0,K.jsxs)(`label`,{children:[`Reply`,(0,K.jsx)(`textarea`,{rows:2,value:u,onChange:e=>d(e.target.value),required:!0})]}),(0,K.jsxs)(`div`,{className:`design-editor-actions`,children:[(0,K.jsx)(_,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>l(null),children:`Cancel`}),(0,K.jsx)(_,{type:`submit`,size:`sm`,disabled:s||!u.trim(),children:`Send reply`})]})]}):null]},t)},t[8]=i,t[9]=s,t[10]=r,t[11]=m,t[12]=u,t[13]=c,t[14]=y):y=t[14];let b=f.map(y),x;return t[15]===b?x=t[16]:(x=(0,K.jsx)(`div`,{className:`design-comments`,"aria-label":`Design comments`,children:b}),t[15]=b,t[16]=x),x}function Vu(e){return(0,K.jsxs)(`div`,{className:`design-reply`,children:[(0,K.jsx)(`strong`,{children:e.author}),(0,K.jsx)(`p`,{children:e.body})]},e.id)}function Hu(e){return(0,K.jsx)(`span`,{className:`design-comment-label`,children:e},e)}function Uu(e,t){let[,n]=e,[,r]=t;return r.createdAt.localeCompare(n.createdAt)}function Wu(e){let t=(0,W.c)(21),n,r,i,a,o;if(t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({reason:o,disabled:r,onClick:i,children:n,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o),!r||!o){let e;return t[6]!==n||t[7]!==r||t[8]!==i||t[9]!==a?(e=(0,K.jsx)(_,{...a,disabled:r,onClick:i,children:n}),t[6]=n,t[7]=r,t[8]=i,t[9]=a,t[10]=e):e=t[10],e}let s;t[11]===a?s=t[12]:(s=(0,K.jsx)(_,{...a,"aria-disabled":`true`,className:`cursor-not-allowed opacity-64`,onClick:Gu}),t[11]=a,t[12]=s);let c;t[13]!==n||t[14]!==s?(c=(0,K.jsx)(Fe,{render:s,children:n}),t[13]=n,t[14]=s,t[15]=c):c=t[15];let l;t[16]===o?l=t[17]:(l=(0,K.jsx)(b,{children:o}),t[16]=o,t[17]=l);let u;return t[18]!==c||t[19]!==l?(u=(0,K.jsxs)(ae,{children:[c,l]}),t[18]=c,t[19]=l,t[20]=u):u=t[20],u}function Gu(e){return e.preventDefault()}function Ku(e){let t=(0,W.c)(13),{open:n,onOpenChange:r,onConfirm:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,K.jsxs)(H,{children:[(0,K.jsx)(z,{children:`Reject this turn?`}),(0,K.jsx)(qe,{children:`Design, code, assets, comments, and acceptances return to the turn baseline. Newer messages and turn diffs are discarded. This cannot be undone.`})]}),t[0]=a):a=t[0];let o;t[1]===r?o=t[2]:(o=(0,K.jsx)(_,{size:`sm`,variant:`ghost`,onClick:()=>r(!1),children:`Cancel`}),t[1]=r,t[2]=o);let s;t[3]!==i||t[4]!==r?(s=(0,K.jsx)(_,{size:`sm`,variant:`destructive`,onClick:()=>{r(!1),Lu(i)},children:`Reject turn`}),t[3]=i,t[4]=r,t[5]=s):s=t[5];let c;t[6]!==o||t[7]!==s?(c=(0,K.jsxs)(Xe,{className:`max-w-sm`,children:[a,(0,K.jsxs)(Qe,{children:[o,s]})]}),t[6]=o,t[7]=s,t[8]=c):c=t[8];let l;return t[9]!==r||t[10]!==n||t[11]!==c?(l=(0,K.jsx)(_e,{open:n,onOpenChange:r,children:c}),t[9]=r,t[10]=n,t[11]=c,t[12]=l):l=t[12],l}var qu=e=>`${e} ${e===1?`change`:`changes`}`;function Ju(e,t=new Date){let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=n.toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`}),i=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),a=Math.round((i(t).getTime()-i(n).getTime())/864e5);return a===0?`today at ${r}`:a===1?`yesterday at ${r}`:`${n.toLocaleDateString(void 0,{month:`short`,day:`numeric`})} at ${r}`}function Yu(e){let t=(0,W.c)(43),{open:n,onOpenChange:r,restore:i}=e,[a,o]=(0,G.useState)(null),[s,c]=(0,G.useState)(!1),l;t[0]!==i.acceptedAt||t[1]!==i.acceptedBy?(l=i.acceptedBy?`the version ${i.acceptedBy} accepted${i.acceptedAt?` ${Ju(i.acceptedAt)}`:``}`:`the accepted version`,t[0]=i.acceptedAt,t[1]=i.acceptedBy,t[2]=l):l=t[2];let u=l,d;t[3]!==s||t[4]!==r?(d=e=>{s||(o(null),r(e))},t[3]=s,t[4]=r,t[5]=d):d=t[5];let f;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,K.jsx)(z,{children:`Restore the accepted version?`}),t[6]=f):f=t[6];let p;t[7]===i.changedCount?p=t[8]:(p=qu(i.changedCount).replace(`change`,`unaccepted change`),t[7]=i.changedCount,t[8]=p);let m;t[9]!==i.documentName||t[10]!==p||t[11]!==u?(m=(0,K.jsxs)(qe,{children:[`This discards`,` `,p,` to`,` `,i.documentName,` and restores `,u,`.`]}),t[9]=i.documentName,t[10]=p,t[11]=u,t[12]=m):m=t[12];let h;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,K.jsx)(`p`,{className:`design-restore-help`,children:`Discarded changes cannot be recovered here. Commit first if you want to keep them in git.`}),t[13]=h):h=t[13];let g;t[14]===a?g=t[15]:(g=a?(0,K.jsx)(`p`,{className:`design-revision-error`,role:`alert`,children:a}):null,t[14]=a,t[15]=g);let v;t[16]!==m||t[17]!==g?(v=(0,K.jsxs)(H,{children:[f,m,h,g]}),t[16]=m,t[17]=g,t[18]=v):v=t[18];let y;t[19]===r?y=t[20]:(y=()=>r(!1),t[19]=r,t[20]=y);let b;t[21]!==s||t[22]!==y?(b=(0,K.jsx)(_,{size:`sm`,variant:`ghost`,disabled:s,onClick:y,children:`Cancel`}),t[21]=s,t[22]=y,t[23]=b):b=t[23];let x;t[24]!==r||t[25]!==i?(x=()=>{c(!0),o(null),i.run().then(()=>r(!1)).catch(e=>o(e instanceof Error?e.message:String(e))).finally(()=>c(!1))},t[24]=r,t[25]=i,t[26]=x):x=t[26];let S;t[27]===i.changedCount?S=t[28]:(S=qu(i.changedCount),t[27]=i.changedCount,t[28]=S);let C;t[29]!==s||t[30]!==x||t[31]!==S?(C=(0,K.jsxs)(_,{size:`sm`,variant:`destructive`,disabled:s,onClick:x,children:[`Discard `,S]}),t[29]=s,t[30]=x,t[31]=S,t[32]=C):C=t[32];let w;t[33]!==b||t[34]!==C?(w=(0,K.jsxs)(Qe,{children:[b,C]}),t[33]=b,t[34]=C,t[35]=w):w=t[35];let T;t[36]!==w||t[37]!==v?(T=(0,K.jsxs)(Xe,{className:`max-w-md`,children:[v,w]}),t[36]=w,t[37]=v,t[38]=T):T=t[38];let E;return t[39]!==n||t[40]!==T||t[41]!==d?(E=(0,K.jsx)(_e,{open:n,onOpenChange:d,children:T}),t[39]=n,t[40]=T,t[41]=d,t[42]=E):E=t[42],E}function Xu(e){let t=(0,W.c)(26),{followUp:n,onPrepared:r,onCancel:i}=e,[a,o]=(0,G.useState)(n.prompt),s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,K.jsx)(`h3`,{children:`Request changes`}),t[0]=s):s=t[0];let c=n.openComments===1?`comment`:`comments`,l;t[1]!==n.openComments||t[2]!==c?(l=(0,K.jsxs)(`header`,{className:`design-follow-up-heading`,children:[s,(0,K.jsxs)(g,{variant:`outline`,children:[n.openComments,` open `,c]})]}),t[1]=n.openComments,t[2]=c,t[3]=l):l=t[3];let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>o(e.target.value),t[4]=u):u=t[4];let d;t[5]===a?d=t[6]:(d=(0,K.jsx)(Ue,{"aria-label":`Requested changes`,value:a,onChange:u,rows:5}),t[5]=a,t[6]=d);let f;t[7]===i?f=t[8]:(f=(0,K.jsx)(_,{size:`sm`,variant:`ghost`,onClick:i,children:`Cancel`}),t[7]=i,t[8]=f);let p;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,K.jsx)(`span`,{className:`design-revision-spacer`}),t[9]=p):p=t[9];let m;t[10]===a?m=t[11]:(m=a.trim(),t[10]=a,t[11]=m);let h=!m,v;t[12]!==n||t[13]!==r||t[14]!==a?(v=()=>{n.prepare(a),r()},t[12]=n,t[13]=r,t[14]=a,t[15]=v):v=t[15];let y;t[16]!==v||t[17]!==h?(y=(0,K.jsx)(_,{size:`sm`,disabled:h,onClick:v,children:`Add to message`}),t[16]=v,t[17]=h,t[18]=y):y=t[18];let b;t[19]!==y||t[20]!==f?(b=(0,K.jsxs)(`div`,{className:`design-revision-actions`,children:[f,p,y]}),t[19]=y,t[20]=f,t[21]=b):b=t[21];let x;return t[22]!==b||t[23]!==l||t[24]!==d?(x=(0,K.jsxs)(`section`,{className:`design-follow-up`,"aria-label":`Request changes`,children:[l,d,b]}),t[22]=b,t[23]=l,t[24]=d,t[25]=x):x=t[25],x}function Zu(e){let t=(0,W.c)(105),{review:n,changes:r,changesNotice:i,notice:a,error:s}=e,[l,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(!1),[m,h]=(0,G.useState)(!1),[g,v]=(0,G.useState)(!1),[y,x]=(0,G.useState)(!1),S;t[0]!==r||t[1]!==f?(S=r&&!f?r.slice(0,4):r,t[0]=r,t[1]=f,t[2]=S):S=t[2];let w=S,T=n.rejectSupported??!0;if(!r?.length&&!n.accepted&&!n.blockers&&!s&&!n.restore&&!n.statusLabel)return null;let E=n.accepted?`Accepted`:n.blockers?`${n.blockers} blocking ${n.blockers===1?`comment`:`comments`}`:n.statusLabel&&n.statusLabel!==`Awaiting review`?n.statusLabel:r?.length?`${n.changedCount} ${n.changedCount===1?`change`:`changes`}`:n.statusLabel??`Review`,D;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,K.jsx)(`section`,{}),t[3]=D):D=t[3];let k;t[4]===E?k=t[5]:(k=(0,K.jsx)(`span`,{children:E}),t[4]=E,t[5]=k);let A;t[6]!==n.accepted||t[7]!==n.blockers||t[8]!==n.statusLabel?(A=n.accepted||n.statusLabel===`Approved`?(0,K.jsx)(O,{className:`design-revision-success`,"aria-hidden":`true`}):n.blockers?(0,K.jsx)(Le,{className:`design-revision-warning`,"aria-hidden":`true`}):null,t[6]=n.accepted,t[7]=n.blockers,t[8]=n.statusLabel,t[9]=A):A=t[9];let j;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,K.jsx)(oe,{className:`design-revision-chevron`,"aria-hidden":`true`}),t[10]=j):j=t[10];let M;t[11]!==k||t[12]!==A?(M=(0,K.jsxs)(c,{className:`design-revision-heading`,children:[k,A,j]}),t[11]=k,t[12]=A,t[13]=M):M=t[13];let P;t[14]!==r||t[15]!==i||t[16]!==f||t[17]!==w?(P=r?r.length?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`ul`,{className:`design-revision-changes`,children:w?.map($u)}),r.length>4?(0,K.jsx)(_,{size:`xs`,variant:`ghost`,className:`design-revision-more`,"aria-expanded":f,onClick:()=>p(Qu),children:f?`Show fewer`:`Show all ${r.length} changes`}):null]}):(0,K.jsx)(`p`,{className:`design-revision-note`,children:`No content changes in this turn.`}):(0,K.jsx)(`p`,{className:`design-revision-note`,children:i??`Changes unavailable.`}),t[14]=r,t[15]=i,t[16]=f,t[17]=w,t[18]=P):P=t[18];let I;t[19]===a?I=t[20]:(I=a?(0,K.jsx)(`p`,{className:`design-revision-note`,children:a}):null,t[19]=a,t[20]=I);let L;t[21]!==n.blockers||t[22]!==n.onComments?(L=n.blockers?(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:n.onComments,children:`Resolve comments`}):null,t[21]=n.blockers,t[22]=n.onComments,t[23]=L):L=t[23];let R;t[24]===n.onCompare?R=t[25]:(R=n.onCompare?(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:n.onCompare,children:`Compare`}):null,t[24]=n.onCompare,t[25]=R);let ee;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,K.jsx)(`span`,{className:`design-revision-spacer`}),t[26]=ee):ee=t[26];let z=n.busy||n.accepted||!n.canAccept,B;t[27]===n.actions.accept?B=t[28]:(B=()=>Lu(n.actions.accept),t[27]=n.actions.accept,t[28]=B);let te;t[29]===n.accepted?te=t[30]:(te=n.accepted?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(de,{"aria-hidden":`true`}),`Accepted`]}):`Accept`,t[29]=n.accepted,t[30]=te);let ne;t[31]!==z||t[32]!==B||t[33]!==te?(ne=(0,K.jsx)(_,{size:`sm`,disabled:z,onClick:B,children:te}),t[31]=z,t[32]=B,t[33]=te,t[34]=ne):ne=t[34];let re;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,K.jsxs)(ae,{children:[(0,K.jsx)(Fe,{render:(0,K.jsx)(C,{render:(0,K.jsx)(_,{size:`icon-sm`,variant:`ghost`,"aria-label":`More review actions`})}),children:(0,K.jsx)(Zt,{"aria-hidden":`true`})}),(0,K.jsx)(b,{children:`More review actions`})]}),t[35]=re):re=t[35];let ie=n.busy||!n.canReview||n.blockers>0,V;t[36]===n.actions.approve?V=t[37]:(V=()=>Lu(n.actions.approve),t[36]=n.actions.approve,t[37]=V);let se;t[38]!==ie||t[39]!==V?(se=(0,K.jsx)(N,{disabled:ie,onClick:V,children:`Approve`}),t[38]=ie,t[39]=V,t[40]=se):se=t[40];let ce;t[41]!==n.accepted||t[42]!==n.actions.requestChanges||t[43]!==n.busy||t[44]!==n.canReview||t[45]!==n.followUp?(ce=n.followUp?(0,K.jsx)(N,{disabled:n.busy||n.accepted,onClick:()=>x(!0),children:`Request changes`}):(0,K.jsx)(N,{disabled:n.busy||!n.canReview,onClick:()=>Lu(n.actions.requestChanges),children:`Request changes`}),t[41]=n.accepted,t[42]=n.actions.requestChanges,t[43]=n.busy,t[44]=n.canReview,t[45]=n.followUp,t[46]=ce):ce=t[46];let le;t[47]!==T||t[48]!==n.busy||t[49]!==n.canReject?(le=T?(0,K.jsx)(N,{disabled:n.busy||!n.canReject,onClick:()=>h(!0),children:`Reject turn...`}):null,t[47]=T,t[48]=n.busy,t[49]=n.canReject,t[50]=le):le=t[50];let ue;t[51]!==n.busy||t[52]!==n.restore?(ue=n.restore?(0,K.jsx)(N,{disabled:n.busy,onClick:()=>v(!0),children:`Restore accepted version...`}):null,t[51]=n.busy,t[52]=n.restore,t[53]=ue):ue=t[53];let fe;t[54]!==se||t[55]!==ce||t[56]!==le||t[57]!==ue?(fe=(0,K.jsxs)(we,{children:[re,(0,K.jsxs)(F,{align:`end`,children:[se,ce,le,ue]})]}),t[54]=se,t[55]=ce,t[56]=le,t[57]=ue,t[58]=fe):fe=t[58];let pe;t[59]!==R||t[60]!==ne||t[61]!==fe?(pe=(0,K.jsxs)(`div`,{className:`design-revision-actions`,children:[R,ee,ne,fe]}),t[59]=R,t[60]=ne,t[61]=fe,t[62]=pe):pe=t[62];let H;t[63]!==y||t[64]!==n.actions.requestChanges||t[65]!==n.canReview||t[66]!==n.followUp||t[67]!==n.statusLabel?(H=y&&n.followUp?(0,K.jsx)(Xu,{followUp:n.followUp,onCancel:()=>x(!1),onPrepared:()=>{x(!1),n.canReview&&n.statusLabel!==`Changes requested`&&Lu(n.actions.requestChanges)}}):null,t[63]=y,t[64]=n.actions.requestChanges,t[65]=n.canReview,t[66]=n.followUp,t[67]=n.statusLabel,t[68]=H):H=t[68];let me;t[69]!==i||t[70]!==s||t[71]!==n.acceptReason||t[72]!==n.blockers?(me=n.acceptReason&&n.acceptReason!==i&&!n.blockers&&!s?(0,K.jsxs)(`p`,{className:`design-revision-reason`,role:`status`,children:[(0,K.jsx)(Le,{"aria-hidden":`true`}),n.acceptReason]}):null,t[69]=i,t[70]=s,t[71]=n.acceptReason,t[72]=n.blockers,t[73]=me):me=t[73];let he;t[74]!==n.accepted||t[75]!==n.acceptedBy||t[76]!==n.author||t[77]!==n.authorFromHost?(he=n.accepted&&n.acceptedBy?(0,K.jsxs)(`p`,{className:`design-revision-signer`,children:[`Accepted by `,n.acceptedBy.author,` `,Ju(n.acceptedBy.at)]}):n.authorFromHost&&n.author.trim()&&!n.accepted?(0,K.jsxs)(`p`,{className:`design-revision-signer`,children:[`Accepting signs as `,n.author.trim()]}):null,t[74]=n.accepted,t[75]=n.acceptedBy,t[76]=n.author,t[77]=n.authorFromHost,t[78]=he):he=t[78];let ge;t[79]!==pe||t[80]!==H||t[81]!==me||t[82]!==he||t[83]!==P||t[84]!==I||t[85]!==L?(ge=(0,K.jsx)(o,{children:(0,K.jsxs)(`div`,{className:`design-revision-details`,children:[P,I,L,pe,H,me,he]})}),t[79]=pe,t[80]=H,t[81]=me,t[82]=he,t[83]=P,t[84]=I,t[85]=L,t[86]=ge):ge=t[86];let _e;t[87]!==s||t[88]!==n.conflict||t[89]!==n.onReload?(_e=s?(0,K.jsxs)(`div`,{className:`design-revision-error-row`,children:[(0,K.jsx)(`p`,{className:`design-revision-error`,role:`alert`,children:s}),n.conflict&&n.onReload?(0,K.jsxs)(_,{size:`sm`,onClick:n.onReload,children:[(0,K.jsx)(ft,{"aria-hidden":`true`}),`Reload`]}):null]}):null,t[87]=s,t[88]=n.conflict,t[89]=n.onReload,t[90]=_e):_e=t[90];let ve;t[91]!==T||t[92]!==m||t[93]!==n.actions.rejectTurn?(ve=T?(0,K.jsx)(Ku,{open:m,onOpenChange:h,onConfirm:n.actions.rejectTurn}):null,t[91]=T,t[92]=m,t[93]=n.actions.rejectTurn,t[94]=ve):ve=t[94];let ye;t[95]!==g||t[96]!==n.restore?(ye=n.restore?(0,K.jsx)(Yu,{open:g,onOpenChange:v,restore:n.restore}):null,t[95]=g,t[96]=n.restore,t[97]=ye):ye=t[97];let be;return t[98]!==l||t[99]!==ge||t[100]!==_e||t[101]!==ve||t[102]!==ye||t[103]!==M?(be=(0,K.jsxs)(u,{render:D,className:`design-revision-card`,"aria-label":`Revision review`,open:l,onOpenChange:d,children:[M,ge,_e,ve,ye]}),t[98]=l,t[99]=ge,t[100]=_e,t[101]=ve,t[102]=ye,t[103]=M,t[104]=be):be=t[104],be}function Qu(e){return!e}function $u(e){return(0,K.jsx)(`li`,{children:e.text},e.key)}function ed(e){let t=(0,W.c)(39),{review:n,cached:r,baselineNotice:i,reviewLocked:a}=e,[o,s]=(0,G.useState)(!1),c=n.blockers?`${n.blockers} blocking ${n.blockers===1?`comment`:`comments`}`:n.statusLabel??(n.changedCount?`${n.changedCount} ${n.changedCount===1?`change`:`changes`}`:`Design revision`),l;t[0]===c?l=t[1]:(l=(0,K.jsx)(`strong`,{children:c}),t[0]=c,t[1]=l);let u;t[2]===n.revision?u=t[3]:(u=n.revision?`Revision ${n.revision.slice(0,8)}`:`Revision unavailable`,t[2]=n.revision,t[3]=u);let d=r?` - cached`:``,f;t[4]!==u||t[5]!==d?(f=(0,K.jsxs)(`span`,{className:`design-small-muted`,children:[u,d]}),t[4]=u,t[5]=d,t[6]=f):f=t[6];let p;t[7]===i?p=t[8]:(p=i?(0,K.jsx)(`small`,{children:i}):null,t[7]=i,t[8]=p);let m;t[9]===a?m=t[10]:(m=a?(0,K.jsx)(`small`,{children:`Design changed during compare. Exit compare to review the current revision.`}):null,t[9]=a,t[10]=m);let h;t[11]!==l||t[12]!==f||t[13]!==p||t[14]!==m?(h=(0,K.jsxs)(`div`,{className:`design-review-summary`,role:`status`,children:[l,f,p,m]}),t[11]=l,t[12]=f,t[13]=p,t[14]=m,t[15]=h):h=t[15];let g;t[16]!==n.acceptReason||t[17]!==n.accepted||t[18]!==n.actions.accept||t[19]!==n.actions.approve||t[20]!==n.actions.requestChanges||t[21]!==n.blockers||t[22]!==n.busy||t[23]!==n.canAccept||t[24]!==n.canReject||t[25]!==n.canReview||t[26]!==n.onComments||t[27]!==n.onCompare||t[28]!==n.rejectReason||t[29]!==n.reviewReason||t[30]!==n.revision?(g=n.revision||n.canReject?(0,K.jsxs)(Jt,{children:[(0,K.jsx)(ut,{render:(0,K.jsx)(_,{size:`sm`,variant:`outline`}),children:`Review`}),(0,K.jsx)(Pt,{side:`top`,align:`end`,className:`w-80`,children:(0,K.jsx)(`div`,{className:`design-review-popover`,children:(0,K.jsxs)(`div`,{className:`design-review-actions`,children:[n.revision&&n.onCompare?(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:n.onCompare,children:`Compare`}):null,n.blockers?(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:n.onComments,children:`Comments`}):null,(0,K.jsx)(Wu,{size:`sm`,variant:`outline`,disabled:n.busy||!n.canReview,reason:n.reviewReason,onClick:()=>Lu(n.actions.requestChanges),children:`Request changes`}),(0,K.jsx)(Wu,{size:`sm`,variant:`outline`,disabled:n.busy||!n.canReview||n.blockers>0,reason:n.reviewReason??(n.blockers?`Resolve blocking comments to approve`:null),onClick:()=>Lu(n.actions.approve),children:`Approve`}),(0,K.jsx)(Wu,{size:`sm`,variant:`outline`,disabled:n.busy||!n.canReject,reason:n.rejectReason,onClick:()=>s(!0),children:`Reject turn`}),(0,K.jsx)(Wu,{size:`sm`,disabled:n.busy||n.accepted||!n.canAccept,reason:n.acceptReason,onClick:()=>Lu(n.actions.accept),children:n.accepted?`Accepted`:`Accept`})]})})})]}):null,t[16]=n.acceptReason,t[17]=n.accepted,t[18]=n.actions.accept,t[19]=n.actions.approve,t[20]=n.actions.requestChanges,t[21]=n.blockers,t[22]=n.busy,t[23]=n.canAccept,t[24]=n.canReject,t[25]=n.canReview,t[26]=n.onComments,t[27]=n.onCompare,t[28]=n.rejectReason,t[29]=n.reviewReason,t[30]=n.revision,t[31]=g):g=t[31];let v;t[32]!==o||t[33]!==n.actions.rejectTurn?(v=(0,K.jsx)(Ku,{open:o,onOpenChange:s,onConfirm:n.actions.rejectTurn}),t[32]=o,t[33]=n.actions.rejectTurn,t[34]=v):v=t[34];let y;return t[35]!==h||t[36]!==g||t[37]!==v?(y=(0,K.jsxs)(`footer`,{className:`design-review-strip`,"aria-label":`Revision status`,children:[h,g,v]}),t[35]=h,t[36]=g,t[37]=v,t[38]=y):y=t[38],y}function td(e,t){let n=structuredClone(e),r=Dr(n),i=n,a=i.nodes,o=e=>{if(e===null)return i.roots;let t=a[e];if(!t||!(`children`in t))throw Error(`Parent must be a frame or group`);return t.children},s=e=>{if(!a[e])throw Error(`Node is missing`);let t=r.parents.get(e)??null,i=t&&a[t]?.type===`ref`?Object.values(n.instances[t]?.slots??{}).find(t=>t.includes(e)):o(t);if(!i)throw Error(`Node has no tree position`);let s=i.indexOf(e);if(s<0)throw Error(`Node has no tree position`);i.splice(s,1)},c=(e,t,n)=>{let r=o(t);if(n>r.length)throw Error(`Position is outside the ordered child list`);r.splice(n,0,e)},l=(e,t,n)=>{let r=e;n===null?delete r[t]:r[t]=n};switch(t.kind){case`insert`:case`instantiate`:if(a[t.nodeId])throw Error(`Node ID already exists`);a[t.nodeId]=t.node,c(t.nodeId,t.parentId,t.index),t.kind===`instantiate`&&l(n.instances,t.nodeId,t.instance);break;case`patch`:if(!a[t.nodeId])throw Error(`Node is missing`);a[t.nodeId]=Er(a[t.nodeId],t.patch);break;case`move`:s(t.nodeId),c(t.nodeId,t.parentId,t.index);break;case`remove`:{s(t.nodeId);let e=t=>{let r=a[t];r&&`children`in r&&r.children.forEach(e);for(let r of Object.values(n.instances[t]?.slots??{}))r.forEach(e);delete a[t],l(n.instances,t,null)};e(t.nodeId);break}case`override`:{let e=n.instances[t.instanceId];if(!e)throw Error(`Instance is missing`);l(e.overrides,t.sourceNodeId,t.patch);break}case`slots`:{let e=n.instances[t.instanceId];if(!e)throw Error(`Instance is missing`);let r=e.slots[t.slotId]??[];for(let e of t.children)s(e);for(let e of r)t.children.includes(e)||i.roots.push(e);l(e.slots,t.slotId,t.children);break}case`component`:l(n.components,t.componentId,t.value);break;case`library`:l(n.imports,t.importId,t.value);break;case`token`:l(n.tokens,t.tokenId,t.value);break;case`theme`:l(n.themeAxes,t.axis,t.values);break;case`asset`:l(n.assets,t.assetId,t.value);break;case`annotation`:l(n.annotations,t.annotationId,t.value);break;case`review`:l(n.reviews,t.reviewId,t.value);break;case`acceptance`:i.acceptances??={},l(i.acceptances,t.acceptanceId,t.value);break}let u=Tr(Cr(n));if(u.status!==`editable`)throw Error(`Operation violates the document schema`);return u.document}var nd=()=>({fileHash:null,contentHash:null,diagnostics:[],readOnly:!1,status:`loading`,selection:[],changedNodeIds:[],batch:null,sequence:-1}),rd=new Set([`component`,`library`,`token`,`theme`,`asset`]);function id(e){let t=new Set,n=new Set(e.changedNodeIds);for(let r of e.operations){let e=`nodeId`in r?r.nodeId:`instanceId`in r?r.instanceId:null;e&&n.has(e)&&t.add(e)}if(e.operations.some(e=>rd.has(e.kind)))for(let n of e.changedNodeIds)t.add(n);return[...t]}function ad(e,t,n,r){if(t.kind!==`snapshot`&&t.sequence<e.sequence)return e;if(t.kind===`snapshot`){if(n===void 0)throw Error(`Snapshot payload must be decoded`);let i=Tr(n);return{...e,documentPath:t.documentPath,...i.status===`editable`?{document:i.document}:{document:void 0},fileHash:t.fileHash,contentHash:t.contentHash,diagnostics:t.diagnostics,readOnly:t.readOnly,status:`ready`,sequence:t.sequence,changedNodeIds:[],batch:null,...r?{context:r}:{},selection:e.selection.filter(e=>i.status===`editable`&&!!i.document.nodes[e])}}if(t.sequence===e.sequence&&t.fileHash===e.fileHash)return e;if(e.status===`conflict`||!e.document||t.sequence!==e.sequence+1||t.previousFileHash!==e.fileHash)return{...e,status:`conflict`,readOnly:!0};try{let n=e.document;for(let e of t.operations)n=td(n,e);if(wr(Cr(n))!==t.fileHash)throw Error(`Committed operation hash mismatch`);return{...e,document:n,fileHash:t.fileHash,contentHash:t.contentHash,diagnostics:t.diagnostics,sequence:t.sequence,status:`ready`,readOnly:!1,changedNodeIds:[...t.changedNodeIds],batch:t.changedNodeIds.length?{sequence:t.sequence,nodeIds:id(t)}:null,selection:(t.selection&&t.selection.documentPath===e.documentPath&&t.selection.revision===t.contentHash?t.selection.nodeIds:e.selection).filter(e=>!!n.nodes[e]),...r?{context:r}:{}}}catch{return{...e,status:`conflict`,readOnly:!0}}}var od=class extends We(`DesignSyncError`){},sd=(e,t)=>JSON.stringify([e,t]),cd=nd(),ld=Ie(e=>({records:{},setRecord:(t,n)=>e(e=>({records:{...e.records,[t]:n}}))}));async function ud(e){let t=Uint8Array.from(atob(e),e=>e.charCodeAt(0)),n=new Blob([t]).stream().pipeThrough(new DecompressionStream(`gzip`));return new Response(n).text()}var dd=Te(p(Pe));async function fd(e,{event:t,fetchAsset:n}){let r=t.kind===`snapshot`?await ud(t.payload):void 0,i;if(t.dependencies){let e=dd(await ud(t.dependencies));i={...e.manifest?{manifest:e.manifest}:{},documents:e.documents,documentPath:e.documentPath,availableAssets:new Set(e.availableAssets)}}let a=ad(ld.getState().records[e]??nd(),t,r,i);if(ld.getState().setRecord(e,a),a.status===`conflict`)throw Error(`Design revision changed; reload the document`);let[o,s]=JSON.parse(e),c=a.context;if(!a.document||!c||!t.dependencies||!n)return;let l=new Map,u=[],d=[a.document,...Object.values(c.documents??{})].flatMap(e=>Object.keys(e.assets).map(t=>({document:e,assetId:t})));await Promise.all(Array.from({length:Math.min(4,d.length)},async()=>{for(;d.length;){let{document:e,assetId:t}=d.pop();try{let r=await n({projectId:o.projectId,...o.threadId?{threadId:o.threadId}:{},documentPath:s,assetId:t,sourceDocumentId:e.documentId,...a.contentHash?{expectedContentHash:a.contentHash}:{}});r?l.set(`${e.documentId}:${t}`,r):u.push(t)}catch{u.push(t)}}}));let f=ld.getState().records[e];f&&f.sequence===a.sequence&&ld.getState().setRecord(e,{...f,assets:l,diagnostics:[...f.diagnostics,...u.map(e=>({code:`asset-unavailable`,severity:`warning`,message:`Image ${e.slice(0,8)} could not load. Reload to retry.`}))]})}var pd=e=>ee(t=>{let[n,r]=JSON.parse(t);return e.runtime.atom(e.transport.subscribe(n,r).pipe(k(be(`DesignCache.accept`)(function*(e){return yield*V({try:()=>fd(t,e),catch:e=>new od({message:e instanceof Error?e.message:String(e)})})}))))}),md=new WeakMap;function hd(e){let t=md.get(e.transport);return t||(t=pd(e),md.set(e.transport,t)),t}var gd=m(se());function _d(e,t){let n=Un(),r=e&&t?sd(e,t):null,i=r?hd(n)(r):gd,a=pe(i),o=Be(i),s=ld(e=>r?e.records[r]??cd:cd),c=n.useConnected(e?.environmentId??null),l=!!(r&&!c&&s.document),u=(0,G.useMemo)(()=>l?{...s,status:`disconnected`,readOnly:!0}:s,[l,s]);return(0,G.useEffect)(()=>{if(r&&a._tag===`Failure`){let e=ld.getState().records[r]??nd();ld.getState().setRecord(r,{...e,status:e.document?`conflict`:`error`,readOnly:!0})}},[r,a]),{record:u,select:(0,G.useCallback)(e=>{if(r){let t=ld.getState().records[r]??nd();ld.getState().setRecord(r,{...t,selection:e})}},[r]),reload:o}}function vd(e,t){let n=(0,W.c)(5),r;n[0]!==t||n[1]!==e?(r=e&&t?sd(e,t):null,n[0]=t,n[1]=e,n[2]=r):r=n[2];let i=r,a;return n[3]===i?a=n[4]:(a=e=>{let t=i?e.records[i]:void 0;return t?.document?Ol(t.document,t.batch):null},n[3]=i,n[4]=a),ld(a)}function yd(e,t){let n=(0,W.c)(5),r;n[0]!==t||n[1]!==e?(r=e&&t?sd(e,t):null,n[0]=t,n[1]=e,n[2]=r):r=n[2];let i=r,a;return n[3]===i?a=n[4]:(a=e=>i?e.records[i]?.batch?.sequence??null:null,n[3]=i,n[4]=a),ld(a)}function bd(e){let t=(0,W.c)(10),n=Un(),r;t[0]!==n||t[1]!==e?(r=e?n.transport.catalog(e):null,t[0]=n,t[1]=e,t[2]=r):r=t[2];let i=Kn(r),a;t[3]===i.data?.paths?a=t[4]:(a=i.data?.paths??[],t[3]=i.data?.paths,t[4]=a);let o=i.error??void 0,s;return t[5]!==i.isPending||t[6]!==i.refresh||t[7]!==a||t[8]!==o?(s={paths:a,loading:i.isPending,error:o,reload:i.refresh},t[5]=i.isPending,t[6]=i.refresh,t[7]=a,t[8]=o,t[9]=s):s=t[9],s}var xd=16,Sd=6,Cd=8;function wd(){let e=globalThis.crypto.getRandomValues(new Uint8Array(xd));e[Sd]=e[Sd]&15|64,e[Cd]=e[Cd]&63|128;let t=ce(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}var Td=Te(p(fe(Je,Je)));function Ed(e,t,n){let r=e.document,i=e.contentHash,a=Object.values(r?.annotations??{}).filter(e=>e.blocking&&e.status===`open`),o=Object.values(r?.reviews??{}).toSorted((e,t)=>(e.sequence??0)-(t.sequence??0)||e.createdAt.localeCompare(t.createdAt)),s=o.findLast(e=>e.revision===i),c=!!(t&&Object.values(r?.acceptances??{}).some(e=>e.revision===i&&e.turnId===t.turnId&&e.threadId===n)),l=!!(i&&t&&i!==t.revision&&!c);return{status:a.length?`blocked`:s?.decision===`request-changes`?`request-changes`:s?.decision===`approve`?`approved`:o.some(e=>e.decision===`approve`)?`stale-approval`:l?`unreviewed`:`reviewed`,unreviewed:l,blocked:a.length>0}}var Dd={blockReason:`Reject is not available here.`,reject:async()=>{}},Od=()=>Dd;function kd(){let[e]=(0,G.useState)(()=>{try{return localStorage.getItem(`p4-design-review-author`)?.trim()||`You`}catch{return`You`}});return{author:e,hostOwned:!1}}var Ad=()=>null;function jd(e,t,n){let r=Un(),i=qn(),a=r.review.useBaselineKey(e),o=Kn(e&&t&&a?.baselineId?r.transport.baseline(e,t,a.baselineId):null),[s,c]=(0,G.useState)(null),[l,u]=(0,G.useState)(null),[d,f]=(0,G.useState)(!1),[p,m]=(0,G.useState)(!1),h=kd(),g=(r.review.useReviewer??Ad)(),_=g===null?h:{author:g.trim()||h.author,hostOwned:!0},{author:v}=_,y=(r.review.useRejectTurn??Od)(e,s);(0,G.useEffect)(()=>{let e=!1;c(null);let t=o.data;if(t?.status===`available`)return(async()=>{let n=t.snapshot?Tr(await ud(t.snapshot.payload)):null,r=t.snapshot?.dependencies?dd(await ud(t.snapshot.dependencies)):null,i=Td(await ud(t.assets)),a={turnId:t.turnId,turnCount:t.turnCount,revision:t.snapshot?.contentHash??null,...n?.status===`editable`?{document:n.document}:{},...r?{context:{...r.manifest?{manifest:r.manifest}:{},documents:r.documents,documentPath:r.documentPath,availableAssets:new Set(r.availableAssets)}}:{},assets:new Map(Object.entries(i).map(([e,t])=>[e,Uint8Array.from(atob(t),e=>e.charCodeAt(0))]))};e||c(a)})().catch(()=>{e||u(`The baseline snapshot could not be decoded.`)}),()=>{e=!0}},[o.data]);let b=(0,G.useMemo)(()=>Ed(n,s,a?.scopeId),[n,s,a?.scopeId]);(0,G.useEffect)(()=>{u(null),m(!1)},[t,a?.scopeId]);let x=(0,G.useRef)(null);(0,G.useEffect)(()=>{if(!p){x.current=null;return}x.current===null?x.current=n.fileHash??``:n.fileHash!==x.current&&(m(!1),u(null))},[p,n.fileHash]);let S=!!(e&&t&&n.document&&n.fileHash&&n.contentHash&&n.status===`ready`&&!n.readOnly),C=async a=>{if(!(!S||!e||!t||!n.fileHash||d)){f(!0),u(null),m(!1);try{let o=await i(r.transport.review(e,{tool:`design.apply`,documentPath:t,expectedFileHash:n.fileHash,operations:a}));if(o.status===`conflict`&&m(!0),o.status!==`committed`)throw Error(o.status===`conflict`?a.some(e=>e.kind===`acceptance`)?`Not accepted. ${t.split(`/`).at(-1)} changed after you opened this review. Reload to review the latest version.`:`The design changed. Reload before reviewing.`:o.diagnostics.at(-1)?.message??`The review could not be saved.`)}catch(e){throw u(e instanceof Error?e.message:String(e)),e}finally{f(!1)}}},w=async e=>{n.contentHash&&await C([{operationId:he.make(wd()),kind:`review`,reviewId:he.make(wd()),value:{revision:n.contentHash,decision:e,author:v.trim(),createdAt:new Date().toISOString()}}])},T=d?null:s?n.status===`ready`?y.blockReason:`Reload the design to reject this turn.`:`No turn baseline is available yet.`,E=n.status===`ready`&&!!s&&!y.blockReason&&!d;return{baseline:s,baselineLoading:o.isPending,baselineReason:o.data?.status===`unavailable`?o.data.reason:o.error??(a?.baselineId?null:`No turn baseline is available yet.`),error:l,conflict:p,busy:d,author:v,authorFromHost:_.hostOwned,status:b.status,unreviewed:b.unreviewed,canAccept:S&&!!s&&!b.blocked&&!d,rejectBlockReason:T,canReject:E,annotate:async(e,t)=>C([{operationId:he.make(wd()),kind:`annotation`,annotationId:he.make(e),value:t}]),approve:()=>w(`approve`),requestChanges:()=>w(`request-changes`),accept:async()=>{!s||!a||!n.contentHash||b.blocked||await C([{operationId:he.make(wd()),kind:`acceptance`,acceptanceId:he.make(wd()),value:{revision:n.contentHash,threadId:Ne.make(a.scopeId),turnId:s.turnId,author:v.trim(),createdAt:new Date().toISOString()}}])},reject:async()=>{if(!(!s||d||y.blockReason)){f(!0),u(null);try{await y.reject(),o.refresh()}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(!1)}}},attach:(t,n)=>{!e?.threadId||!r.attachment||(r.attachment.set(e,t),n?.stay||r.navigation.returnToThread?.(e))}}}var Md=[[`Layers`,Nt],[`Comments`,Wt],[`Components`,Nn],[`Libraries`,In],[`Tokens`,zn]];function Nd(e){return e.split(`/`).at(-1)??e}function Pd(e){return e?e.slice(0,8):`unavailable`}function Fd(e){let t=(0,W.c)(12),{title:n,detail:r,action:i,actionLabel:a}=e,o=a===void 0?`Reload`:a,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,K.jsx)(gn,{"aria-hidden":`true`,size:24}),t[0]=s):s=t[0];let c;t[1]===n?c=t[2]:(c=(0,K.jsx)(`strong`,{children:n}),t[1]=n,t[2]=c);let l;t[3]===r?l=t[4]:(l=r?(0,K.jsx)(`p`,{children:r}):null,t[3]=r,t[4]=l);let u;t[5]!==i||t[6]!==o?(u=i?(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:i,children:o}):null,t[5]=i,t[6]=o,t[7]=u):u=t[7];let d;return t[8]!==c||t[9]!==l||t[10]!==u?(d=(0,K.jsxs)(`div`,{className:`design-notice`,role:`status`,children:[s,c,l,u]}),t[8]=c,t[9]=l,t[10]=u,t[11]=d):d=t[11],d}function Id(e){let t=(0,W.c)(13),{items:n,diagnostics:r}=e,i;t[0]===r?i=t[1]:(i=r.length?(0,K.jsxs)(Jt,{children:[(0,K.jsxs)(ut,{render:(0,K.jsx)(_,{size:`xs`,variant:`ghost`}),children:[`Details (`,r.length,`)`]}),(0,K.jsx)(Pt,{className:`w-80`,children:(0,K.jsx)(`ul`,{className:`design-diagnostics-list`,children:r.map(Ld)})})]}):null,t[0]=r,t[1]=i);let a=i,o;t[2]!==a||t[3]!==r.length||t[4]!==n?(o=n.length||!a?n:[{key:`diagnostics`,variant:`info`,role:`status`,icon:Le,message:`${r.length} design ${r.length===1?`diagnostic`:`diagnostics`}`}],t[2]=a,t[3]=r.length,t[4]=n,t[5]=o):o=t[5];let s=o;if(!s.length)return null;let c;if(t[6]!==a||t[7]!==s){let e;t[9]===a?e=t[10]:(e=(e,t)=>(0,K.jsxs)(wn,{variant:e.variant,role:e.role,className:`design-notice-alert`,children:[(0,K.jsx)(e.icon,{"aria-hidden":`true`}),(0,K.jsx)(Sn,{children:e.message}),e.action||t===0&&a?(0,K.jsxs)(_n,{children:[e.action?(0,K.jsxs)(_,{size:`xs`,variant:`ghost`,onClick:e.action.run,children:[(0,K.jsx)(ft,{"aria-hidden":`true`}),e.action.label]}):null,t===0?a:null]}):null]},e.key),t[9]=a,t[10]=e),c=s.map(e),t[6]=a,t[7]=s,t[8]=c}else c=t[8];let l;return t[11]===c?l=t[12]:(l=(0,K.jsx)(`div`,{className:`design-notices`,children:c}),t[11]=c,t[12]=l),l}function Ld(e){return(0,K.jsx)(`li`,{children:e.message},`${e.code}:${e.nodeId??e.path}:${e.message}`)}var Rd=`\0start`,zd=`\0project`;function Bd(e){let t=(0,W.c)(32),{path:n,paths:r,onOpen:i,statuses:a,onStartDesign:o,open:s,onOpenChange:c}=e,l=(0,G.useRef)(null),u;t[0]===n?u=t[1]:(u=n?Nd(n).replace(/\.p4design$/,``):`Choose design`,t[0]=n,t[1]=u);let d=u;if(!r.length&&!o){let e=n||d,r;return t[2]!==e||t[3]!==d?(r=(0,K.jsx)(`h1`,{className:`design-title`,children:(0,K.jsx)(on,{full:e,children:d})}),t[2]=e,t[3]=d,t[4]=r):r=t[4],r}let f=n||null,p;t[5]!==i||t[6]!==o?(p=e=>{e===Rd?o?.():typeof e==`string`&&e&&i(e)},t[5]=i,t[6]=o,t[7]=p):p=t[7];let m=n||d,h,_;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,K.jsx)(ze,{variant:`ghost`,size:`sm`,className:`design-document-switcher`}),_=(0,K.jsx)(`span`,{className:`sr-only`,children:`Design document: `}),t[8]=h,t[9]=_):(h=t[8],_=t[9]);let v;t[10]===d?v=t[11]:(v=(0,K.jsx)(`span`,{ref:l,className:`design-truncate`,children:d}),t[10]=d,t[11]=v);let y;t[12]!==m||t[13]!==v?(y=(0,K.jsxs)(Xt,{full:m,labelRef:l,render:h,children:[_,v]}),t[12]=m,t[13]=v,t[14]=y):y=t[14];let b;if(t[15]!==r||t[16]!==a){let e;t[18]===a?e=t[19]:(e=e=>{let t=a?.get(e);return(0,K.jsx)(Ge,{value:e,children:(0,K.jsxs)(`span`,{className:`design-switcher-item`,children:[(0,K.jsx)(on,{full:e,children:e.replace(/\.p4design$/,``)}),t?(0,K.jsx)(g,{variant:t.tone,size:`sm`,children:t.label}):null]})},e)},t[18]=a,t[19]=e),b=r.map(e),t[15]=r,t[16]=a,t[17]=b}else b=t[17];let x;t[20]===o?x=t[21]:(x=o?(0,K.jsx)(Ge,{value:Rd,children:(0,K.jsxs)(`span`,{className:`design-switcher-item`,children:[(0,K.jsx)(Bt,{"aria-hidden":`true`,size:14}),`New design`]})}):null,t[20]=o,t[21]=x);let S;t[22]!==x||t[23]!==b?(S=(0,K.jsxs)(Ae,{matchTriggerWidth:!1,alignItemWithTrigger:!1,className:`max-w-md`,children:[b,x]}),t[22]=x,t[23]=b,t[24]=S):S=t[24];let C;return t[25]!==c||t[26]!==s||t[27]!==S||t[28]!==f||t[29]!==p||t[30]!==y?(C=(0,K.jsxs)(L,{modal:!1,open:s,onOpenChange:c,value:f,onValueChange:p,children:[y,S]}),t[25]=c,t[26]=s,t[27]=S,t[28]=f,t[29]=p,t[30]=y,t[31]=C):C=t[31],C}function Vd(e){let t=(0,W.c)(16),{icon:n,label:r,kind:i,className:a,onClick:o,trailing:s}=e,c=(0,G.useRef)(null),l;t[0]!==a||t[1]!==o?(l=(0,K.jsx)(`button`,{type:`button`,className:a,onClick:o}),t[0]=a,t[1]=o,t[2]=l):l=t[2];let u;t[3]===n?u=t[4]:(u=(0,K.jsx)(`span`,{className:`design-row-icon`,"aria-hidden":`true`,children:(0,K.jsx)(n,{size:14})}),t[3]=n,t[4]=u);let d;t[5]===r?d=t[6]:(d=(0,K.jsx)(`span`,{ref:c,className:`design-truncate`,children:r}),t[5]=r,t[6]=d);let f;t[7]===i?f=t[8]:(f=i?(0,K.jsxs)(`span`,{className:`sr-only`,children:[`, `,i]}):null,t[7]=i,t[8]=f);let p;return t[9]!==r||t[10]!==l||t[11]!==u||t[12]!==d||t[13]!==f||t[14]!==s?(p=(0,K.jsxs)(Xt,{full:r,labelRef:c,render:l,children:[u,d,f,s]}),t[9]=r,t[10]=l,t[11]=u,t[12]=d,t[13]=f,t[14]=s,t[15]=p):p=t[15],p}function Hd(e){let t=(0,W.c)(35),{document:n,selection:r,select:i,query:a}=e,o=a===void 0?``:a,s;t[0]===n.roots?s=t[1]:(s=()=>new Set(n.roots),t[0]=n.roots,t[1]=s);let[c,l]=(0,G.useState)(s),[u,d]=(0,G.useState)(0),[f,p]=(0,G.useState)(400),m=(0,G.useRef)(null),h,g;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{let e=m.current;if(!e)return;let t=new ResizeObserver(()=>p(e.clientHeight));return t.observe(e),()=>t.disconnect()},g=[],t[2]=h,t[3]=g):(h=t[2],g=t[3]),(0,G.useEffect)(h,g);let _;t[4]===n.roots?_=t[5]:(_=()=>l(new Set(n.roots)),t[4]=n.roots,t[5]=_);let v;t[6]===n.documentId?v=t[7]:(v=[n.documentId],t[6]=n.documentId,t[7]=v),(0,G.useEffect)(_,v);let y;if(t[8]!==n.nodes||t[9]!==n.roots||t[10]!==c||t[11]!==o){y=[];let e=new Set,r=(t,i)=>{for(let a of t){let t=n.nodes[a];if(!t||e.has(a))continue;let s=`children`in t?t.children:[];y.push({id:a,node:t,depth:i,children:s.length>0}),(c.has(a)||o.trim())&&s.length&&i<256&&(e.add(a),r(s,i+1),e.delete(a))}};r(n.roots,0),t[8]=n.nodes,t[9]=n.roots,t[10]=c,t[11]=o,t[12]=y}else y=t[12];let b;t[13]!==o||t[14]!==y?(b=o.trim()?y.filter(e=>{let{node:t}=e;return`${t.name} ${t.type}`.toLocaleLowerCase().includes(o.trim().toLocaleLowerCase())}):y,t[13]=o,t[14]=y,t[15]=b):b=t[15];let x=b,S=Math.max(0,Math.floor(u/32)-6),C=Math.min(x.length,Math.ceil((u+f)/32)+6),w;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(w=e=>d(e.currentTarget.scrollTop),t[16]=w):w=t[16];let T;t[17]!==o||t[18]!==x.length?(T=!x.length&&o.trim()?(0,K.jsx)(`p`,{className:`design-small-muted design-search-empty`,children:`No matching layers`}):null,t[17]=o,t[18]=x.length,t[19]=T):T=t[19];let E=x.length*32,D;t[20]===E?D=t[21]:(D={height:E,position:`relative`},t[20]=E,t[21]=D);let O;t[22]!==C||t[23]!==c||t[24]!==x||t[25]!==i||t[26]!==r||t[27]!==S?(O=x.slice(S,C).map((e,t)=>{let{id:n,node:a,depth:o,children:s}=e,u=ln(a);return(0,K.jsxs)(`div`,{className:`design-layer-row`,role:`treeitem`,"aria-level":o+1,"aria-selected":r.includes(n),"aria-expanded":s?c.has(n):void 0,style:{top:(S+t)*32,paddingInlineStart:Math.min(o,12)*13+4},children:[s?(0,K.jsx)(`button`,{type:`button`,className:`design-layer-disclosure`,"aria-label":`${c.has(n)?`Collapse`:`Expand`} ${a.name}`,onClick:()=>l(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),children:c.has(n)?(0,K.jsx)(oe,{size:14}):(0,K.jsx)(le,{size:14})}):(0,K.jsx)(`span`,{className:`design-layer-spacer`}),(0,K.jsx)(Vd,{icon:u.icon,label:a.name||u.label,kind:u.label,className:`design-layer-select`,onClick:()=>i([n])})]},n)}),t[22]=C,t[23]=c,t[24]=x,t[25]=i,t[26]=r,t[27]=S,t[28]=O):O=t[28];let k;t[29]!==D||t[30]!==O?(k=(0,K.jsx)(`div`,{style:D,children:O}),t[29]=D,t[30]=O,t[31]=k):k=t[31];let A;return t[32]!==k||t[33]!==T?(A=(0,K.jsxs)(`div`,{ref:m,className:`design-layer-viewport`,role:`tree`,"aria-label":`Layers`,onScroll:w,children:[T,k]}),t[32]=k,t[33]=T,t[34]=A):A=t[34],A}function Ud(e){let t=(0,W.c)(40),{tab:n,document:r,onOpen:i,selection:a,select:o,context:s,query:c}=e,l;t[0]===c?l=t[1]:(l=e=>e.toLocaleLowerCase().includes(c.trim().toLocaleLowerCase()),t[0]=c,t[1]=l);let u=l;if(n===`Layers`){let e;return t[2]!==r||t[3]!==c||t[4]!==o||t[5]!==a?(e=r?(0,K.jsx)(Hd,{document:r,selection:a,select:o,query:c}):(0,K.jsx)(Fd,{title:`No layers yet`,detail:`Open a design document to inspect its layers.`}),t[2]=r,t[3]=c,t[4]=o,t[5]=a,t[6]=e):e=t[6],e}if(n===`Libraries`){let e,n,r;if(t[7]!==s?.manifest?.libraries||t[8]!==u||t[9]!==i){let a=Object.entries(s?.manifest?.libraries??{});e=`design-catalog-list`,n=a.length>0&&!a.some(e=>{let[,t]=e;return u(t.path)})?(0,K.jsx)(`p`,{className:`design-small-muted design-search-empty`,children:`No matching libraries`}):null,r=a.length?a.filter(e=>{let[,t]=e;return u(t.path)}).map(e=>{let[t,n]=e;return(0,K.jsx)(Vd,{icon:gn,label:n.path,className:`design-catalog-row`,onClick:()=>i(n.path),trailing:(0,K.jsx)(`small`,{children:n.exports.length})},t)}):(0,K.jsx)(Fd,{title:`No libraries`,detail:`Libraries declared in p4.design.json appear here.`}),t[7]=s?.manifest?.libraries,t[8]=u,t[9]=i,t[10]=e,t[11]=n,t[12]=r}else e=t[10],n=t[11],r=t[12];let a;return t[13]!==e||t[14]!==n||t[15]!==r?(a=(0,K.jsxs)(`div`,{className:e,children:[n,r]}),t[13]=e,t[14]=n,t[15]=r,t[16]=a):a=t[16],a}if(!r){let e;t[17]===n?e=t[18]:(e=n.toLowerCase(),t[17]=n,t[18]=e);let r=`No ${e} yet`,i;return t[19]===r?i=t[20]:(i=(0,K.jsx)(Fd,{title:r,detail:`Open a design document first.`}),t[19]=r,t[20]=i),i}if(n===`Components`){let e,n,i;if(t[21]!==r.components||t[22]!==u||t[23]!==o){let a=Object.entries(r.components);e=`design-catalog-list`,n=a.length>0&&!a.some(e=>{let[,t]=e;return u(t.name)})?(0,K.jsx)(`p`,{className:`design-small-muted design-search-empty`,children:`No matching components`}):null,i=a.length?a.filter(e=>{let[,t]=e;return u(t.name)}).map(e=>{let[t,n]=e;return(0,K.jsx)(Vd,{icon:en,label:n.name,className:`design-catalog-row`,onClick:()=>o([n.rootId])},t)}):(0,K.jsx)(Fd,{title:`No components`,detail:`Components created by an agent appear here.`}),t[21]=r.components,t[22]=u,t[23]=o,t[24]=e,t[25]=n,t[26]=i}else e=t[24],n=t[25],i=t[26];let a;return t[27]!==e||t[28]!==n||t[29]!==i?(a=(0,K.jsxs)(`div`,{className:e,children:[n,i]}),t[27]=e,t[28]=n,t[29]=i,t[30]=a):a=t[30],a}let d,f,p;if(t[31]!==r.tokens||t[32]!==u){let e=Object.entries(r.tokens);d=`design-catalog-list`,f=e.length>0&&!e.some(e=>{let[,t]=e;return u(t.name)})?(0,K.jsx)(`p`,{className:`design-small-muted design-search-empty`,children:`No matching tokens`}):null,p=e.length?e.filter(e=>{let[,t]=e;return u(t.name)}).map(Wd):(0,K.jsx)(Fd,{title:`No tokens`,detail:`Design tokens created by an agent appear here.`}),t[31]=r.tokens,t[32]=u,t[33]=d,t[34]=f,t[35]=p}else d=t[33],f=t[34],p=t[35];let m;return t[36]!==d||t[37]!==f||t[38]!==p?(m=(0,K.jsxs)(`div`,{className:d,children:[f,p]}),t[36]=d,t[37]=f,t[38]=p,t[39]=m):m=t[39],m}function Wd(e){let[t,n]=e;return(0,K.jsxs)(`div`,{className:`design-token-row`,children:[(0,K.jsx)(on,{children:n.name}),(0,K.jsx)(`span`,{className:`design-small-muted`,children:eu(n.kind)})]},t)}function Gd(e){let t=(0,W.c)(21),{open:n,onOpenChange:r,tab:i,onTabChange:a,counts:o,query:s,onQueryChange:c,comments:l,children:u}=e,d=(0,G.useRef)(null),f=(0,G.useRef)(new Map),p;t[0]===i?p=t[1]:(p=Md.find(e=>{let[t]=e;return t===i})?.[1]??Nt,t[0]=i,t[1]=p);let m=p,h=e=>{let t=Md.findIndex(e=>{let[t]=e;return t===i}),n=Md[e===`first`?0:e===`last`?Md.length-1:(t+e+Md.length)%Md.length][0];a(n),f.current.get(n)?.focus()},g;t[2]!==r||t[3]!==n?(g=()=>r(!n),t[2]=r,t[3]=n,t[4]=g):g=t[4];let v;t[5]===m?v=t[6]:(v=(0,K.jsx)(m,{"aria-hidden":`true`}),t[5]=m,t[6]=v);let y=o[i],x;t[7]===y?x=t[8]:(x=(0,K.jsx)(`span`,{className:`design-pill-count`,children:y}),t[7]=y,t[8]=x);let S;t[9]===n?S=t[10]:(S=n?(0,K.jsx)(E,{"aria-hidden":`true`}):(0,K.jsx)(oe,{"aria-hidden":`true`}),t[9]=n,t[10]=S);let C;t[11]!==n||t[12]!==g||t[13]!==v||t[14]!==x||t[15]!==S||t[16]!==i?(C=(0,K.jsxs)(_,{ref:d,size:`sm`,variant:`outline`,className:`design-float-pill`,"aria-expanded":n,"aria-controls":`design-catalog-panel`,onClick:g,children:[v,i,x,S]}),t[11]=n,t[12]=g,t[13]=v,t[14]=x,t[15]=S,t[16]=i,t[17]=C):C=t[17];let w=n?(0,K.jsxs)(`div`,{id:`design-catalog-panel`,className:`design-catalog-panel`,role:`region`,"aria-label":`Design catalog`,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),r(!1),d.current?.focus())},children:[(0,K.jsx)(`div`,{className:`design-catalog-tabs`,role:`tablist`,"aria-label":`Catalog`,onKeyDown:e=>{let t=e.key===`ArrowRight`?1:e.key===`ArrowLeft`?-1:e.key===`Home`?`first`:e.key===`End`?`last`:null;t!==null&&(e.preventDefault(),h(t))},children:Md.map(e=>{let[t,n]=e,r=i===t,o=(0,K.jsx)(`button`,{ref:e=>{e?f.current.set(t,e):f.current.delete(t)},type:`button`,role:`tab`,id:`design-catalog-tab-${t}`,"aria-selected":r,"aria-controls":`design-catalog-tabpanel`,"aria-label":r?void 0:t,tabIndex:r?0:-1,onClick:()=>a(t)});return r?(0,K.jsxs)(`button`,{ref:e=>{e?f.current.set(t,e):f.current.delete(t)},type:`button`,role:`tab`,id:`design-catalog-tab-${t}`,"aria-selected":!0,"aria-controls":`design-catalog-tabpanel`,tabIndex:0,onClick:()=>a(t),children:[(0,K.jsx)(n,{size:14,"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:t})]},t):(0,K.jsxs)(ae,{children:[(0,K.jsx)(Fe,{render:o,children:(0,K.jsx)(n,{size:14,"aria-hidden":`true`})}),(0,K.jsx)(b,{children:t})]},t)})}),(0,K.jsx)(`div`,{id:`design-catalog-tabpanel`,className:`design-catalog-tabpanel`,role:`tabpanel`,"aria-labelledby":`design-catalog-tab-${i}`,children:i===`Comments`?l:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`label`,{className:`design-catalog-search`,children:[(0,K.jsx)(vt,{size:14,"aria-hidden":`true`}),(0,K.jsx)(`input`,{type:`search`,"aria-label":`Search ${i.toLowerCase()}`,placeholder:`Search ${i.toLowerCase()}`,value:s,onChange:e=>c(e.target.value)})]}),u]})})]}):null,T;return t[18]!==w||t[19]!==C?(T=(0,K.jsxs)(`div`,{className:`design-catalog-float`,children:[C,w]}),t[18]=w,t[19]=C,t[20]=T):T=t[20],T}function Kd(e,t){if(e==null)return`None`;if(typeof e==`object`&&`tokenId`in e)return`Token ${t?.tokens[String(e.tokenId)]?.name??String(e.tokenId)}`;if(typeof e==`object`&&`mode`in e){let n=e;return n.mode===`fixed`?`Fixed ${Kd(n.value,t)}`:eu(n.mode)}return Array.isArray(e)?`${e.length} ${e.length===1?`item`:`items`}`:typeof e==`number`?nu(e):String(e)}function qd({document:e,selection:t,theme:n,context:r,compact:i=!1}){let a=(0,G.useMemo)(()=>Mr(e,n,r),[e,n,r]);if(!t.length)return(0,K.jsx)(Fd,{title:`Nothing selected`,detail:`Select a layer or click an item on the canvas.`});if(t.length>1)return(0,K.jsx)(Fd,{title:`${t.length} items selected`,detail:`Select one item to inspect its properties.`});let o=t[0],s=o?e.nodes[o]:void 0;if(!s)return(0,K.jsx)(Fd,{title:`Selection unavailable`,detail:`The selected item is no longer in this revision.`});let c=t=>{if(t&&typeof t==`object`&&`mode`in t&&`value`in t)return`${t.mode===`fixed`?`Fixed`:eu(String(t.mode))} ${c(t.value)}`;if(!t||typeof t!=`object`||!(`tokenId`in t))return Kd(t,e);try{let r=kr(e,t,n);return typeof r==`number`?nu(r):String(r)}catch{return`Unresolved token`}},l=o?e.instances[o]:void 0,u=a.items.find(e=>e.ownerId===o)?.bounds,d=s.type===`ref`&&s.importId?e.imports[s.importId]:void 0,f=d?r?.documents?.[d.libraryId]:e,p=s.type===`ref`?f?.components[s.componentId]:void 0,m=t=>(0,K.jsx)(`dl`,{className:`design-property-list`,children:t.map(([t,n,r])=>(0,K.jsxs)(`div`,{className:`design-property`,children:[(0,K.jsx)(`dt`,{children:t}),(0,K.jsxs)(`dd`,{children:[r??(0,K.jsx)(`span`,{children:Kd(n,e)}),r===void 0&&Kd(n,e)!==c(n)?(0,K.jsxs)(`small`,{children:[`Resolved: `,c(n)]}):null]})]},t))}),h=(e,t)=>(0,K.jsxs)(`section`,{className:`design-inspector-section`,"aria-label":e,children:[(0,K.jsx)(`h3`,{children:e}),m(t)]}),_=s.fills?.[0],v=_?.kind===`solid`?c(_.color):null,y=ln(s),b=y.icon;return(0,K.jsxs)(`div`,{className:`design-inspector-content`,children:[i?null:(0,K.jsxs)(`div`,{className:`design-inspector-identity`,children:[(0,K.jsxs)(`h2`,{className:`design-inspector-title`,children:[(0,K.jsx)(b,{size:14,"aria-hidden":`true`}),(0,K.jsx)(on,{children:s.name||y.label})]}),(0,K.jsxs)(`span`,{className:`design-inspector-meta`,children:[(0,K.jsx)(`span`,{className:`design-small-muted`,children:y.label}),(0,K.jsx)(g,{variant:`outline`,size:`sm`,children:`Read only`})]})]}),`clip`in s?h(`Alignment`,[[`Clip contents`,null,au(s.clip)]]):null,h(`Position`,[[`X`,s.x],[`Y`,s.y],[`Rotation`,s.rotation??0,`${nu(s.rotation??0)}°`]]),h(`Layout`,`layout`in s?[[`Mode`,null,eu(s.layout.direction)],[`Gap`,s.layout.gap],[`Padding`,null,[s.layout.padding.top,s.layout.padding.right,s.layout.padding.bottom,s.layout.padding.left].map(t=>Kd(t,e)).join(` `)]]:[[`Mode`,null,`Absolute`]]),h(`Dimensions`,[[`Width`,s.width],[`Height`,s.height],[`Computed`,null,u?`${nu(u.width)} × ${nu(u.height)}`:`Unavailable`]]),h(`Appearance`,[[`Opacity`,null,ru(s.opacity??1)],[`Visibility`,null,iu(s.visible??!0)],[`Stroke`,s.stroke??`None`],[`Effects`,null,ou(s.effects?.length??0)],...`radius`in s?[[`Radius`,s.radius??0]]:[],...`text`in s?[[`Text`,null,(0,K.jsx)(on,{children:s.text},`text`)],[`Font`,s.fontFamily],[`Font size`,s.fontSize]]:[]]),h(`Fill`,[[`Type`,null,_?eu(_.kind):`None`],..._?.kind===`solid`?[[`Color`,null,(0,K.jsxs)(`span`,{className:`design-fill-value`,children:[(0,K.jsx)(`span`,{className:`design-swatch`,style:{background:v??`transparent`},"aria-hidden":`true`}),(0,K.jsx)(`span`,{className:`design-mono`,children:v}),typeof _.color==`object`?(0,K.jsx)(`small`,{children:Kd(_.color,e)}):null]},`color`)]]:_?.kind===`image`?[[`Asset`,null,(0,K.jsx)(on,{className:`design-truncate design-mono`,children:_.assetId},`asset`)]]:_?.kind===`gradient`?[[`Gradient`,null,eu(_.gradient)]]:[]]),h(`Theme`,Object.entries(e.themeAxes).length?Object.entries(e.themeAxes).map(([e,t])=>[e,null,n[e]??`Default (${t[0]??`none`})`]):[[`Preview`,null,`Default`]]),p?(0,K.jsxs)(`section`,{className:`design-inspector-section`,"aria-label":`Source component`,children:[(0,K.jsx)(`h3`,{children:`Source component`}),(0,K.jsx)(`p`,{children:p.name}),d?(0,K.jsx)(on,{className:`design-truncate design-small-muted`,children:`Library ${r?.manifest?.libraries[d.libraryId]?.path??d.libraryId}`}):null]}):null,l?(0,K.jsxs)(`section`,{className:`design-inspector-section`,"aria-label":`Overrides`,children:[(0,K.jsx)(`h3`,{children:`Overrides`}),(0,K.jsxs)(`p`,{children:[Object.keys(l.overrides).length,` source`,` `,Object.keys(l.overrides).length===1?`node`:`nodes`]}),Object.entries(l.overrides).map(([e,t])=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(on,{className:`design-truncate design-small-muted`,children:f?.nodes[e]?.name??e}),m(Object.entries(t))]},e))]}):null,h(`Code`,[[`Mapping`,null,e.codeMappings?`Document mapping available`:`No code mapping`]]),i?null:(0,K.jsx)(`p`,{className:`design-inspector-hint`,children:`Ask the agent to change this selection.`})]})}function Jd(e){let t=(0,W.c)(67),{geometry:n,document:r,selection:i,theme:a,context:o,collapsed:s,onCollapsedChange:c,onComment:l,extraAction:u}=e,d=(0,G.useRef)(null),f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f={width:300,height:148},t[0]=f):f=t[0];let[p,m]=(0,G.useState)(f),[h,v]=(0,G.useState)(!1),y,x;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{let e=d.current;if(!e)return;let t=new ResizeObserver(()=>{let t=e.offsetWidth,n=e.offsetHeight;!t||!n||m(e=>e.width===t&&e.height===n?e:{width:t,height:n})});return t.observe(e),()=>t.disconnect()},x=[],t[1]=y,t[2]=x):(y=t[1],x=t[2]),(0,G.useLayoutEffect)(y,x);let S;t[3]!==n.avoid||t[4]!==n.canvas||t[5]!==n.screen||t[6]!==p?(S=Br(n.screen,p,n.canvas,void 0,void 0,n.avoid),t[3]=n.avoid,t[4]=n.canvas,t[5]=n.screen,t[6]=p,t[7]=S):S=t[7];let C=S,{onPlaced:w}=n,T=C?.x,D=C?.y,O,k;t[8]!==w||t[9]!==T||t[10]!==D||t[11]!==p.height||t[12]!==p.width?(O=()=>{w(T===void 0||D===void 0?null:{x:T,y:D,width:p.width,height:p.height})},k=[w,T,D,p.width,p.height],t[8]=w,t[9]=T,t[10]=D,t[11]=p.height,t[12]=p.width,t[13]=O,t[14]=k):(O=t[13],k=t[14]),(0,G.useLayoutEffect)(O,k);let A,j;t[15]===w?(A=t[16],j=t[17]):(A=()=>()=>w(null),j=[w],t[15]=w,t[16]=A,t[17]=j),(0,G.useLayoutEffect)(A,j);let M=i.length===1?r.nodes[i[0]]:void 0,N;t[18]===M?N=t[19]:(N=M?ln(M):{label:`Selection`,icon:Nt},t[18]=M,t[19]=N);let P=N,F=P.icon,I=M?M.name||P.label:`${i.length} layers`,L=!C,R;t[20]===C?R=t[21]:(R=C?{transform:`translate(${C.x}px, ${C.y}px)`}:void 0,t[20]=C,t[21]=R);let ee;t[22]===F?ee=t[23]:(ee=(0,K.jsx)(F,{size:14,"aria-hidden":`true`}),t[22]=F,t[23]=ee);let z;t[24]===I?z=t[25]:(z=(0,K.jsx)(`h2`,{children:(0,K.jsx)(on,{children:I})}),t[24]=I,t[25]=z);let B;t[26]!==P.label||t[27]!==M?(B=M?(0,K.jsx)(`span`,{className:`sr-only`,children:P.label}):null,t[26]=P.label,t[27]=M,t[28]=B):B=t[28];let te;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,K.jsx)(g,{variant:`outline`,size:`sm`,children:`Read only`}),t[29]=te):te=t[29];let ne=s?`Expand inspector`:`Collapse inspector`,re=!s,ie;t[30]!==s||t[31]!==c?(ie=()=>c(!s),t[30]=s,t[31]=c,t[32]=ie):ie=t[32];let V;t[33]!==ne||t[34]!==re||t[35]!==ie?(V=(0,K.jsx)(_,{size:`icon-xs`,variant:`ghost`,"aria-label":ne,"aria-expanded":re,onClick:ie}),t[33]=ne,t[34]=re,t[35]=ie,t[36]=V):V=t[36];let se;t[37]===s?se=t[38]:(se=s?(0,K.jsx)(oe,{"aria-hidden":`true`}):(0,K.jsx)(E,{"aria-hidden":`true`}),t[37]=s,t[38]=se);let ce;t[39]!==V||t[40]!==se?(ce=(0,K.jsx)(Fe,{render:V,children:se}),t[39]=V,t[40]=se,t[41]=ce):ce=t[41];let le=s?`Expand inspector`:`Collapse inspector`,ue;t[42]===le?ue=t[43]:(ue=(0,K.jsx)(b,{children:le}),t[42]=le,t[43]=ue);let de;t[44]!==ce||t[45]!==ue?(de=(0,K.jsxs)(ae,{children:[ce,ue]}),t[44]=ce,t[45]=ue,t[46]=de):de=t[46];let fe;t[47]!==ee||t[48]!==z||t[49]!==B||t[50]!==de?(fe=(0,K.jsxs)(`header`,{className:`design-selection-card-header`,children:[ee,z,B,te,de]}),t[47]=ee,t[48]=z,t[49]=B,t[50]=de,t[51]=fe):fe=t[51];let pe;t[52]!==s||t[53]!==o||t[54]!==r||t[55]!==u||t[56]!==n.world||t[57]!==h||t[58]!==l||t[59]!==i||t[60]!==a?(pe=s?null:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dl`,{className:`design-geometry`,children:[[`W`,n.world.width],[`H`,n.world.height],[`X`,n.world.x],[`Y`,n.world.y]].map(Xd)}),(0,K.jsxs)(`div`,{className:`design-selection-card-actions`,children:[l?(0,K.jsxs)(_,{size:`xs`,variant:`outline`,onClick:l,children:[(0,K.jsx)(Rn,{"aria-hidden":`true`}),`Comment`]}):null,(0,K.jsx)(_,{size:`xs`,variant:`ghost`,"aria-expanded":h,onClick:()=>v(Yd),children:h?`Less`:`More`}),u]}),h?(0,K.jsx)(`div`,{className:`design-selection-card-more`,children:(0,K.jsx)(qd,{document:r,selection:i,theme:a,context:o,compact:!0})}):null]}),t[52]=s,t[53]=o,t[54]=r,t[55]=u,t[56]=n.world,t[57]=h,t[58]=l,t[59]=i,t[60]=a,t[61]=pe):pe=t[61];let H;return t[62]!==L||t[63]!==R||t[64]!==fe||t[65]!==pe?(H=(0,K.jsxs)(`section`,{ref:d,className:`design-selection-card`,"aria-label":`Selection inspector`,hidden:L,style:R,children:[fe,pe]}),t[62]=L,t[63]=R,t[64]=fe,t[65]=pe,t[66]=H):H=t[66],H}function Yd(e){return!e}function Xd(e){let[t,n]=e;return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:t}),(0,K.jsx)(`dd`,{children:nu(Math.round(n*100)/100)})]},t)}var Zd=new Map,Qd=e=>Zd,$d=(e,t)=>null,ef=(e,t)=>void 0,tf=(e,t,n)=>null;function nf({resourceId:e,surface:t,agentEdit:n,frameDecoration:r,canvasPreferences:o}){let s=Un(),{navigation:c,attachment:l}=s,u=c.useTarget(),d=c.useProjects(),f=c.useActivePath(u),p=e??f??``,m=bd(u),{record:h,select:g,reload:v}=_d(u,p),y=jd(u,p,h),x=(c.useDocumentStatuses??Qd)(u),S=(s.review.useAcceptHold??$d)(u,p),w=(s.useAgentPresence??ef)(u,p),T=(s.useCanvasPlaceholder??tf)(u,{paths:m.paths,loading:m.loading,failed:!!m.error},{openImport:()=>he(!0)}),[E,D]=(0,G.useState)(`Layers`),[O,k]=(0,G.useState)(!1),[j,M]=(0,G.useState)(!1),[P,I]=(0,G.useState)(`Canvas`),[R,ee]=(0,G.useState)(``),[z,B]=(0,G.useState)(()=>typeof window>`u`||window.innerWidth>=1024),[te,ne]=(0,G.useState)(!1),[re,ie]=(0,G.useState)(null),[V,oe]=(0,G.useState)(null),[se,ce]=(0,G.useState)(null),[le,ue]=(0,G.useState)(null),[de,fe]=(0,G.useState)([]),[pe,H]=(0,G.useState)({}),[me,he]=(0,G.useState)(!1),[ge,_e]=(0,G.useState)(`import`),ve=t===`panel`,ye=JSON.stringify([u,p,t]),be=le?.key===ye?le:null,xe=!!be,Ce=!!(be&&be.afterRevision!==h.contentHash);(0,G.useEffect)(()=>ue(null),[ye]);let U=h.document,Te=h.diagnostics??[],Ee=U?Object.values(U.annotations).filter(e=>e.blocking&&e.status===`open`).length:0,De=Te.find(e=>e.severity===`error`),Oe=Te.find(e=>e.code.includes(`asset`)),ke=y.baseline,je=(0,G.useMemo)(()=>ke?.document&&U?Nr(ke.document,U).filter(e=>!/^\/(annotations|reviews|acceptances)(\/|$)/.test(e.path)):null,[ke?.document,U]),Me=je?je.length:h.changedNodeIds.length,Ne=(0,G.useMemo)(()=>je&&ke?.document&&U?je.map(e=>({key:e.path,text:du(e,ke.document,U)})):null,[je,ke?.document,U]),Pe=(0,G.useMemo)(()=>U?Object.entries(U.themeAxes):[],[U?.themeAxes]),Ie=(0,G.useMemo)(()=>Object.fromEntries(Pe.flatMap(([e,t])=>pe[e]&&t.includes(pe[e])?[[e,pe[e]]]:[])),[pe,Pe]),Re=u?.threadId,Be=(0,G.useMemo)(()=>u&&Re?{environmentId:u.environmentId,projectId:u.projectId,threadId:Re}:null,[u?.environmentId,u?.projectId,Re]),Ve=!ve&&!!(Re&&s.thread),He=Ve&&z,Ue=(e,t=ve?`panel`:`workspace`)=>{u&&c.openDocument(u,e,t)},We=U&&(h.status===`ready`||h.status===`disconnected`||h.status===`conflict`||h.readOnly),Ke=!!(h.contentHash&&h.status===`ready`&&!h.readOnly),qe=()=>{!ke?.document||!ke.revision||!U||!h.contentHash||(ue({key:ye,before:ke.document,after:U,beforeRevision:ke.revision,afterRevision:h.contentHash,beforeContext:ke.context,beforeAssets:ke.assets,afterContext:h.context,afterAssets:h.assets,theme:Ie,priorSelection:[...h.selection]}),fe([...h.selection]),ie(null),I(`Canvas`))},Je=()=>{be&&g(be.priorSelection),ue(null)},Ye=e=>{ce(e??null),ve?I(`Comments`):(D(`Comments`),k(!0))},Xe=e=>{Ve&&B(!0),y.attach(e,{stay:Ve})},Ze=h.selection.join(`\0`),Qe=(0,G.useRef)(h.contentHash);Qe.current=h.contentHash;let $e=(0,G.useRef)(null);(0,G.useEffect)(()=>{let e=$e.current;if($e.current=Ze,!He||!Be||!l||xe||(e===null||e===Ze)&&l.current(Be))return;let t=Qe.current,n=Ze?Ze.split(`\0`):[];if(!n.length||!t||!p){l.set(Be,null);return}let r=n.length===1?U?.nodes[n[0]]:void 0;l.set(Be,{documentPath:p,revision:t,nodeIds:n},r?{name:r.name,type:{type:r.type,fills:r.fills}}:void 0)},[He,Be,xe,Ze,p]),(0,G.useEffect)(()=>{if(!He||!Be||!l||!h.contentHash)return;let e=l.current(Be);!e||e.selection.documentPath!==p||e.selection.revision===h.contentHash||l.set(Be,{...e.selection,revision:h.contentHash},e.label)},[He,Be,p,h.contentHash]);let et=async e=>{if(xe||!h.contentHash||!y.author.trim()||V?.path!==p||V.revision!==h.contentHash)return;let t=wd();await y.annotate(t,{...e,revision:h.contentHash,author:y.author.trim(),createdAt:new Date().toISOString(),replies:[],status:`open`}),oe(null),ie(null)},tt=async(e,t)=>{if(xe)return;let n=U?.annotations[e];!n||!y.author.trim()||await y.annotate(e,{...n,replies:[...n.replies,{id:wd(),body:t,author:y.author.trim(),createdAt:new Date().toISOString()}]})},nt=async(e,t)=>{if(xe)return;let n=U?.annotations[e];n&&await y.annotate(e,{...n,status:t?`resolved`:`open`})},rt=V?.anchor.kind===`region`&&V.path===p&&V.revision===h.contentHash?V.anchor.bounds:null,it=U?(0,K.jsxs)(`div`,{className:`design-comments-panel`,children:[xe?(0,K.jsx)(`p`,{className:`design-author-hint`,children:`Exit compare to comment or attach a selection.`}):null,h.selection.length&&!xe&&Ke?(0,K.jsx)(`div`,{className:`design-inspector-actions`,children:(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:()=>oe({path:p,revision:h.contentHash,anchor:{kind:`nodes`,nodeIds:h.selection}}),children:`Comment on selection`})}):null,V&&!xe&&V.path===p&&V.revision===h.contentHash&&Ke?(0,K.jsx)(Ru,{anchor:V.anchor,onSubmit:et,onCancel:()=>{oe(null),ie(null)},busy:y.busy||!y.author.trim()},JSON.stringify(V)):null,V?.path===p&&V.revision!==h.contentHash?(0,K.jsxs)(`div`,{className:`design-annotation-stale`,role:`status`,children:[(0,K.jsx)(`span`,{children:`The revision changed. Place this comment again.`}),(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:()=>{oe(null),ie(null)},children:`Clear`})]}):null,rt&&!xe&&u?.threadId?(0,K.jsx)(`div`,{className:`design-inspector-actions`,children:(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:()=>Xe({documentPath:p,revision:h.contentHash,nodeIds:[],region:rt}),children:`Attach region`})}):null,(0,K.jsx)(Bu,{document:U,currentRevision:h.contentHash,focusedId:se,actions:h.status!==`ready`||h.readOnly||xe?void 0:{reply:tt,setResolved:nt},busy:y.busy||!y.author.trim()})]}):(0,K.jsx)(Fd,{title:`No comments`}),at=!!(ke&&u?.threadId&&Object.values(U?.acceptances??{}).some(e=>e.revision===h.contentHash&&(e.turnId===ke.turnId||ke.revision===h.contentHash)&&e.threadId===u.threadId)),ot=h.status!==`ready`||h.readOnly,st=ke?ke.document?ke.revision?null:`The turn baseline has no resolved content revision. Compare is unavailable.`:`No design existed at the turn baseline. Compare is unavailable.`:y.baselineLoading?`Loading turn baseline…`:y.baselineReason,ct=ot?`Showing a cached revision. Reload to review.`:Ce?`Exit compare to review the current revision.`:h.contentHash?null:`Revision unavailable. Reload to review.`,lt=!at&&S||fu({accepted:at,busy:y.busy,hasThread:!!u?.threadId,hasBaseline:!!ke,baselineNotice:st,revision:h.contentHash,cached:ot,reviewLocked:Ce,blockers:Ee,canAccept:y.canAccept}),[ut,dt]=at?[`Accepted`,`success`]:y.status===`approved`?[`Approved`,`success`]:y.status===`request-changes`?[`Changes requested`,`info`]:y.status===`stale-approval`?[`Approval is stale`,`warning`]:y.unreviewed?[`Awaiting review`,`outline`]:[null,`outline`],pt=U?Object.values(U.annotations).filter(e=>e.status===`open`).sort((e,t)=>e.createdAt.localeCompare(t.createdAt)):[],mt=s.review.followUpPrompt,ht=s.review.restore,gt=Object.values(U?.acceptances??{}).filter(e=>e.threadId===u?.threadId).sort((e,t)=>e.createdAt.localeCompare(t.createdAt)).at(-1),_t={revision:h.contentHash,changedCount:Me,blockers:Ee,statusLabel:ut,statusTone:dt,accepted:at,canReview:!ct,canAccept:!lt&&!at,canReject:y.canReject,acceptReason:lt,rejectReason:y.canReject?null:y.rejectBlockReason,reviewReason:ct,busy:y.busy,author:y.author,actions:{approve:y.approve,requestChanges:y.requestChanges,accept:y.accept,rejectTurn:y.reject},onCompare:ke?.document&&ke.revision&&U&&h.contentHash?qe:void 0,onComments:()=>Ye(),authorFromHost:y.authorFromHost,rejectSupported:!!s.review.useRejectTurn,followUp:mt&&s.review.prepareFollowUp&&u&&U&&p?{prepare:e=>s.review.prepareFollowUp(u,p,e),openComments:pt.length,prompt:()=>mt({documentPath:p,comments:pt.map(({author:e,body:t})=>({author:e,body:t}))})}:void 0,restore:ht&&u&&p&&h.fileHash&&ke?.document&&Me>0&&!at&&!ot?{documentName:Nd(p),changedCount:Me,acceptedBy:gt?.author??null,acceptedAt:gt?.createdAt??null,run:()=>ht(u,p,h.fileHash)}:void 0,acceptedBy:y.authorFromHost&>?.revision===h.contentHash?{author:gt.author,at:gt.createdAt}:void 0,conflict:y.conflict,onReload:()=>{v(),m.reload()}},vt=[];U&&h.status===`disconnected`&&vt.push({key:`disconnected`,variant:`warning`,role:`status`,icon:Ot,message:`Disconnected. Showing cached revision ${Pd(h.contentHash)}.`,action:{label:`Retry`,run:v}}),U&&h.status===`conflict`&&vt.push({key:`conflict`,variant:`warning`,role:`alert`,icon:Le,message:`This view is out of date.`,action:{label:`Reload`,run:v}}),U&&(h.readOnly||De)&&!Oe&&h.status===`ready`&&vt.push({key:`issue`,variant:De?`error`:`info`,role:`alert`,icon:Le,message:De?.message??`This design is read-only.`,action:{label:`Reload`,run:v}}),U&&Oe&&vt.push({key:`asset`,variant:`warning`,role:`status`,icon:Le,message:`An image asset is missing. Its placeholder remains visible.`,action:{label:`Reload`,run:v}});let yt=U?(0,K.jsx)(Id,{items:vt,diagnostics:Te}):null,bt=u?(0,K.jsxs)(ae,{children:[(0,K.jsx)(Fe,{render:(0,K.jsx)(_,{size:`icon-sm`,variant:`ghost`,onClick:()=>{v(),m.reload()},"aria-label":`Reload design`}),children:(0,K.jsx)(ft,{"aria-hidden":`true`})}),(0,K.jsx)(b,{children:`Reload design`})]}):null,xt=Pe.map(([e,t])=>(0,K.jsxs)(L,{modal:!1,value:Ie[e]??``,onValueChange:t=>H(n=>{let r={...n};return typeof t==`string`&&t?r[e]=t:delete r[e],r}),children:[(0,K.jsxs)(ze,{variant:`ghost`,size:`sm`,className:`design-topbar-select`,"aria-label":`Preview ${eu(e)}`,children:[(0,K.jsx)(xn,{"aria-hidden":`true`,size:16}),(0,K.jsx)(`span`,{className:`design-small-muted`,children:Pe.length===1?`Preview`:eu(e)}),(0,K.jsx)(Se,{children:e=>e||`Default`})]}),(0,K.jsxs)(Ae,{children:[(0,K.jsx)(Ge,{value:``,children:`Default`}),t.map(e=>(0,K.jsx)(Ge,{value:e,children:e},e))]})]},e)),St=u?(0,K.jsxs)(_,{size:`sm`,variant:`outline`,onClick:()=>{_e(`import`),he(!0)},children:[(0,K.jsx)(an,{"aria-hidden":`true`}),`Import / export`]}):null,Ct=T||(u?p?h.status===`loading`&&!U?(0,K.jsx)(Fd,{title:`Loading design…`}):U?(0,K.jsxs)(K.Fragment,{children:[ve?yt:null,We&&!U.roots.length?(0,K.jsx)(Fd,{title:`No layers yet`,detail:`Ask an agent to add a frame or shape.`}):null,We&&U.roots.length?be?(0,K.jsx)(bu,{preferences:o,before:be.before,after:be.after,beforeRevision:be.beforeRevision,afterRevision:be.afterRevision,viewKey:ye,theme:be.theme,beforeContext:be.beforeContext,beforeAssets:be.beforeAssets,context:be.afterContext,assets:be.afterAssets,selection:de,onSelect:fe,onExit:Je}):(0,K.jsx)(vu,{preferences:o,chrome:ve?`panel`:`workspace`,viewKey:ye,document:U,theme:Ie,context:h.context,assets:h.assets,selection:h.selection,changedNodeIds:h.changedNodeIds,batch:h.batch,agents:w,agentEdit:n,frameDecoration:r,onSelect:g,annotationMode:re,onAnnotationModeChange:Ke?ie:void 0,onAnchor:e=>{h.contentHash&&oe({path:p,revision:h.contentHash,anchor:e}),Ye()},onOpenAnnotation:Ye,revision:h.contentHash,renderSelectionOverlay:ve?void 0:e=>(0,K.jsx)(Jd,{geometry:e,document:U,selection:h.selection,theme:Ie,context:h.context,collapsed:te,onCollapsedChange:ne,onComment:Ke?()=>ie(`pin`):void 0,extraAction:Be&&l&&!Ve&&h.contentHash?(0,K.jsx)(_,{size:`xs`,variant:`ghost`,onClick:()=>Xe({documentPath:p,revision:h.contentHash,nodeIds:h.selection}),children:`Attach selection`}):null})},p):null]}):(0,K.jsx)(Fd,{title:Te.some(e=>e.code===`unknown-major`)?`Newer design version`:`Design could not be opened`,detail:De?.message??`Check the file and try again.`,action:v}):(0,K.jsx)(Fd,{title:`Choose a design`,detail:`Open a .p4design document from this project.`,action:m.paths.length?()=>M(!0):void 0,actionLabel:`Choose design`}):(0,K.jsx)(Fd,{title:`Open a project`,detail:`Choose a project to view its design documents.`})),wt=(0,K.jsx)(Pu,{open:me,mode:ge,onModeChange:_e,onOpenChange:he,target:u,documentPath:p,revision:h.contentHash,document:h.status===`ready`&&!h.readOnly?U:void 0,selection:h.selection,onImportComplete:m.reload,theme:Ie,onOpenImported:e=>{Ue(e)}});if(!ve){let e={Layers:U?Object.keys(U.nodes).length:0,Comments:U?Object.keys(U.annotations).length:0,Components:U?Object.keys(U.components).length:0,Libraries:Object.keys(h.context?.manifest?.libraries??{}).length,Tokens:U?Object.keys(U.tokens).length:0};return(0,K.jsxs)(`section`,{className:`design-workspace design-workspace-full${xe?` design-workspace-comparing`:``}`,"aria-label":`P4 Design workspace`,children:[(0,K.jsxs)(`header`,{className:`design-topbar`,children:[(0,K.jsxs)(`div`,{className:`design-topbar-title`,children:[s.TopbarStart?(0,K.jsx)(s.TopbarStart,{target:u}):null,(0,K.jsx)(Bd,{path:p,paths:m.paths,open:j,onOpenChange:M,onOpen:e=>Ue(e),statuses:x,onStartDesign:u&&c.startDesign?()=>{B(!0),c.startDesign?.(u)}:void 0}),p?(0,K.jsx)(Jn,{target:u,path:p,revision:h.contentHash,fileHash:h.fileHash??``,disabled:ot||!!be||!u||!h.fileHash},`${u?.environmentId}:${u?.projectId}:${u?.threadId}:${p}`):null]}),(0,K.jsx)(`div`,{className:`design-topbar-notices`,children:yt}),(0,K.jsxs)(`div`,{className:`design-topbar-actions`,children:[d.length||c.createProject?(0,K.jsxs)(L,{modal:!1,value:u?`${u.environmentId}\u0000${u.projectId}`:null,onValueChange:e=>{if(e===zd){c.createProject?.();return}let t=d.find(t=>`${t.environmentId}\u0000${t.projectId}`===e);t&&c.openProject(t)},children:[(0,K.jsxs)(ze,{variant:`ghost`,size:`sm`,className:`design-topbar-select`,"aria-label":`Project`,children:[(0,K.jsx)(i,{"aria-hidden":`true`,size:16}),(0,K.jsx)(Se,{children:e=>(0,K.jsx)(on,{children:d.find(t=>`${t.environmentId}\u0000${t.projectId}`===e)?.name??`Select project`})})]}),(0,K.jsxs)(Ae,{children:[d.map(e=>(0,K.jsx)(Ge,{value:`${e.environmentId}\u0000${e.projectId}`,children:e.name},`${e.environmentId}\u0000${e.projectId}`)),c.createProject?(0,K.jsx)(Ge,{value:zd,children:(0,K.jsxs)(`span`,{className:`design-switcher-item`,children:[(0,K.jsx)(Bt,{"aria-hidden":`true`,size:14}),`New project`]})}):null]})]}):null,u&&c.startDesign?(0,K.jsxs)(_,{size:`default`,variant:`default`,onClick:()=>{B(!0),c.startDesign?.(u)},children:[(0,K.jsx)(Bt,{"aria-hidden":`true`}),`New design`]}):null,Pe.length?(0,K.jsx)(`span`,{className:`design-topbar-divider`,"aria-hidden":`true`}):null,xt,(0,K.jsx)(`span`,{className:`design-topbar-divider`,"aria-hidden":`true`}),(0,K.jsx)(Xn,{target:u,path:p,revision:h.contentHash,compact:!0}),s.TopbarEnd?(0,K.jsx)(s.TopbarEnd,{target:u,path:p}):null,(0,K.jsxs)(we,{children:[(0,K.jsxs)(ae,{children:[(0,K.jsx)(Fe,{render:(0,K.jsx)(C,{render:(0,K.jsx)(_,{size:`icon`,variant:`ghost`,"aria-label":`More actions`})}),children:(0,K.jsx)(Zt,{"aria-hidden":`true`})}),(0,K.jsx)(b,{children:`More actions`})]}),(0,K.jsxs)(F,{align:`end`,className:`w-56`,children:[(0,K.jsxs)(N,{disabled:!u,onClick:()=>{_e(`import`),he(!0)},children:[(0,K.jsx)(Bn,{"aria-hidden":`true`}),` Import design…`]}),(0,K.jsxs)(N,{disabled:!U||h.status!==`ready`||h.readOnly,onClick:()=>{_e(`export`),he(!0)},children:[(0,K.jsx)(Cn,{"aria-hidden":`true`}),` Export design…`]}),(0,K.jsxs)(N,{disabled:!u,onClick:()=>{v(),m.reload()},children:[(0,K.jsx)(ft,{"aria-hidden":`true`}),` Reload design`]}),c.openSettings?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(A,{}),(0,K.jsxs)(N,{onClick:()=>c.openSettings?.(),children:[(0,K.jsx)(jt,{"aria-hidden":`true`}),` Settings`]})]}):null]})]})]})]}),(0,K.jsxs)(`div`,{className:`design-body`,children:[z?(0,K.jsx)(Fr,{title:s.agentColumnTitle,heading:s.AgentHeader?(0,K.jsx)(s.AgentHeader,{target:u}):void 0,hostLabel:Ve&&!s.AgentHeader?s.thread?.label:void 0,onOpenThread:u?.threadId&&c.returnToThread?()=>p?Ue(p,`panel`):c.returnToThread?.(u):void 0,onCollapse:()=>B(!1),card:U&&p&&!T?(0,K.jsx)(Zu,{review:_t,changes:Ne,changesNotice:st,notice:Ce?`Design changed during compare. Exit compare to review the current revision.`:null,error:y.error}):null,thread:Ve&&u?s.thread.render(u):s.AgentPanel?(0,K.jsx)(s.AgentPanel,{target:u}):null}):null,(0,K.jsxs)(`main`,{className:`design-main`,children:[(0,K.jsxs)(`div`,{className:`design-canvas-topleft`,children:[z?null:(0,K.jsx)(Ir,{onOpen:()=>B(!0)}),U&&!xe&&!T?(0,K.jsx)(Gd,{open:O,onOpenChange:k,tab:E,onTabChange:D,counts:e,query:R,onQueryChange:ee,comments:it,children:E===`Comments`?null:(0,K.jsx)(Ud,{tab:E,document:U,onOpen:Ue,selection:h.selection,select:g,context:h.context,query:R})}):null]}),Ct]})]}),wt]})}return(0,K.jsxs)(`section`,{className:`design-workspace design-workspace-pane${xe?` design-workspace-comparing`:``}`,"aria-label":`P4 Design workspace`,children:[(0,K.jsxs)(`header`,{className:`design-header`,children:[(0,K.jsxs)(`div`,{className:`design-heading`,children:[(0,K.jsx)(Bd,{path:p,paths:m.paths,onStartDesign:u&&c.startDesign?()=>c.startDesign?.(u):void 0,onOpen:e=>Ue(e),open:j,onOpenChange:M}),p&&u?(0,K.jsx)(Jn,{target:u,path:p,revision:h.contentHash,fileHash:h.fileHash??``,disabled:ot||!!be||!h.fileHash},`${u.environmentId}:${u.projectId}:${u.threadId}:${p}`):(0,K.jsx)(`span`,{className:`design-small-muted`,children:`Project designs`})]}),(0,K.jsxs)(`div`,{className:`design-header-actions`,children:[xt,_t.onCompare?(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:qe,children:`Compare`}):null,(0,K.jsx)(Xn,{target:u,path:p,revision:h.contentHash}),St,u&&p?(0,K.jsxs)(_,{size:`sm`,variant:`outline`,onClick:()=>Ue(p,`workspace`),children:[(0,K.jsx)(a,{"aria-hidden":`true`}),`Expand`]}):null,bt]})]}),(0,K.jsx)(`nav`,{className:`design-pane-tabs`,"aria-label":`Design views`,children:[`Canvas`,`Layers`,`Inspect`,`Comments`].map(e=>(0,K.jsx)(`button`,{type:`button`,"aria-current":P===e?`page`:void 0,onClick:()=>I(e),children:e},e))}),(0,K.jsx)(`main`,{className:`design-main ${P===`Canvas`?``:`design-main-hidden`}`,children:Ct}),P===`Layers`?(0,K.jsx)(`div`,{className:`design-pane-content`,children:U?(0,K.jsx)(Hd,{document:U,selection:h.selection,select:g}):(0,K.jsx)(Fd,{title:`No layers yet`})}):null,P===`Inspect`?(0,K.jsx)(`div`,{className:`design-pane-content`,children:U?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(qd,{document:U,selection:h.selection,theme:Ie,context:h.context}),xe?(0,K.jsx)(`p`,{className:`design-author-hint`,children:`Exit compare to comment or attach a selection.`}):null,h.selection.length&&h.contentHash&&u?.threadId&&!xe?(0,K.jsx)(`div`,{className:`design-inspector-actions`,children:(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:()=>Xe({documentPath:p,revision:h.contentHash,nodeIds:h.selection}),children:`Attach selection`})}):null]}):(0,K.jsx)(Fd,{title:`Nothing to inspect`})}):null,P===`Comments`?(0,K.jsx)(`div`,{className:`design-pane-content`,children:it}):null,y.error?(0,K.jsx)(`p`,{className:`design-review-error`,role:`alert`,children:y.error}):null,(0,K.jsx)(ed,{review:_t,cached:ot,baselineNotice:st,reviewLocked:Ce}),wt]})}var rf=[`draftsman`,`atelier`,`night`],af={draftsman:`Draftsman`,atelier:`Atelier`,night:`Night studio`},of=e=>typeof e==`string`&&rf.includes(e),sf=e=>e!==`atelier`;function cf(e){let t=(0,W.c)(11),{target:n}=e,r=Un(),i;t[0]!==n.environmentId||t[1]!==n.threadId?(i=n.threadId?{environmentId:n.environmentId,threadId:n.threadId}:null,t[0]=n.environmentId,t[1]=n.threadId,t[2]=i):i=t[2];let a=i,o;t[3]===a?o=t[4]:(o=e=>a?e.creating[yn(a)]:!1,t[3]=a,t[4]=o);let s=hn(o),c,l;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,K.jsx)(`h2`,{className:`text-base font-medium`,children:`Design this project`}),l=(0,K.jsx)(`p`,{className:`max-w-sm text-sm text-muted-foreground`,children:`Create a design or redesign using this project's code and components.`}),t[5]=c,t[6]=l):(c=t[5],l=t[6]);let u;return t[7]!==s||t[8]!==r||t[9]!==n?(u=(0,K.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 p-6 text-center`,children:[c,l,s?(0,K.jsx)(`p`,{role:`status`,className:`text-sm`,children:`Describe what you want in the thread composer.`}):(0,K.jsx)(_,{onClick:()=>r.navigation.startDesign?.(n),children:`Create design`})]}),t[7]=s,t[8]=r,t[9]=n,t[10]=u):u=t[10],u}var lf=e=>{let t=e;return ue[t]??f(t)};function uf(e){if(!e.running)return[];let t=e.sequence!==null&&e.sequence!==e.baseline;return[{label:e.label,active:!0,workingNodeId:t?e.frame:null,lastError:null}]}var df=Ce(et({detail:Je,turnCount:xe}));function ff(e,t,n){let r=n.find(e=>e.kind===`checkpoint.revert.failed`&&!t.activities.has(e.id)&&df(e.payload)&&e.payload.turnCount===t.turnCount);return r?{status:`failed`,reason:df(r.payload)?r.payload.detail:r.summary}:{status:e===t.turnId?`pending`:`complete`}}var pf=e=>e?.threadId?{environmentId:e.environmentId,threadId:e.threadId}:null,mf=e=>{let t=(0,W.c)(5),n;t[0]===e?n=t[1]:(n=pf(e),t[0]=e,t[1]=n);let r=it(n),i;return t[2]!==r?.latestTurn?.turnId||t[3]!==e?(i=e?.threadId?{scopeId:e.threadId,baselineId:r?.latestTurn?.turnId??null}:null,t[2]=r?.latestTurn?.turnId,t[3]=e,t[4]=i):i=t[4],i},hf=(e,t)=>{let n=(0,W.c)(20),r;n[0]===e?r=n[1]:(r=pf(e),n[0]=e,n[1]=r);let i=r,a=it(i),o=st(i),s;n[2]===Symbol.for(`react.memo_cache_sentinel`)?(s={reportFailure:!1},n[2]=s):s=n[2];let c=ke(at.revertCheckpoint,s),[l,u]=(0,G.useState)(null),d;n[3]!==o||n[4]!==l||n[5]!==a?.latestTurn?.turnId?(d=()=>{if(!l||!o)return;let e=ff(a?.latestTurn?.turnId,l,o.activities);e.status!==`pending`&&(u(null),e.status===`failed`?l.reject(Error(e.reason)):l.resolve())},n[3]=o,n[4]=l,n[5]=a?.latestTurn?.turnId,n[6]=d):d=n[6];let f=a?.latestTurn?.turnId,p;n[7]!==o||n[8]!==l||n[9]!==f?(p=[o,f,l],n[7]=o,n[8]=l,n[9]=f,n[10]=p):p=n[10],(0,G.useEffect)(d,p);let m=t?a?.latestTurn?.state===`running`?`Wait for the turn to finish to reject it.`:t.turnId!==a?.latestTurn?.turnId||!o?`Only the latest finished turn can be rejected.`:null:null,g;n[11]!==t||n[12]!==m||n[13]!==o?.activities||n[14]!==i||n[15]!==c?(g=()=>new Promise((e,n)=>{if(!i||!t||m)return e();u({turnId:t.turnId,turnCount:t.turnCount,activities:new Set(o?.activities.map(gf)),resolve:e,reject:n}),c({environmentId:i.environmentId,input:{threadId:i.threadId,turnCount:t.turnCount}}).then(e=>{e._tag===`Failure`&&(u(null),n(h(e)))})}),n[11]=t,n[12]=m,n[13]=o?.activities,n[14]=i,n[15]=c,n[16]=g):g=n[16];let _;return n[17]!==m||n[18]!==g?(_={blockReason:m,reject:g},n[17]=m,n[18]=g,n[19]=_):_=n[19],_};function gf(e){return e.id}var _f=Ee(ge,{label:`design-catalog`,execute:e=>B(`design.catalog`,e)}),vf=Ee(ge,{label:`design-baseline`,execute:e=>{let{turnId:t,...n}=e;return B(`design.baseline`,n)}}),yf=e=>({projectId:e.projectId,...e.threadId?{threadId:e.threadId}:{}});async function bf(e,t){let n=new URL(`/api/design/asset`,e.httpBaseUrl);n.searchParams.set(`target`,JSON.stringify(t));let r=await(e.httpFetch??fetch)(n,{headers:{...Ye(e.httpAuthorization)},credentials:e.httpAuthorization?`omit`:`include`});return r.ok?new Uint8Array(await r.arrayBuffer()):null}var xf={revisions:(e,t)=>$e(e.environmentId,B(`design.revisions`,{...yf(e),documentPath:t})),restoreRevision:(e,t,n,r)=>$e(e.environmentId,B(`design.revisions.restore`,{...yf(e),documentPath:t,revisionId:n,expectedFileHash:r})),subscribe:(e,t)=>ye(e.environmentId,P(`design.subscribe`,()=>nt({...yf(e),documentPath:t})).pipe(k(be(`DesignTransport.prepare`)(function*(e){let t=ne(yield*ie((yield*U).prepared));return{event:e,fetchAsset:t?e=>bf(t,e):null}})))),catalog:e=>_f({environmentId:e.environmentId,input:yf(e)}),baseline:(e,t,n)=>vf({environmentId:e.environmentId,input:{...yf(e),threadId:e.threadId,documentPath:t,turnId:n}}),review:(e,t)=>$e(e.environmentId,B(`design.review`,{target:yf(e),request:t})),transfer:(e,t)=>me(e.environmentId,v(`design.transfer`,t))};function Sf(e){let t=(0,W.c)(80),{target:n,compact:r}=e,i=r===void 0?!1:r,a=dn(),o=bn(n),s=ot(),c;t[0]!==s||t[1]!==n?(c=zt(s,n),t[0]=s,t[1]=n,t[2]=c):c=t[2];let l=c,[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(``),m=(0,G.useRef)(null),h;t[3]!==n.threadId||t[4]!==l?(h=l.find(e=>e.id===n.threadId)?.title??`Choose thread`,t[3]=n.threadId,t[4]=l,t[5]=h):h=t[5];let g=h,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M;if(t[6]!==i||t[7]!==a||t[8]!==g||t[9]!==u||t[10]!==o||t[11]!==f||t[12]!==n||t[13]!==l){let e;t[29]===f?e=t[30]:(e=e=>e.title.toLocaleLowerCase().includes(f.toLocaleLowerCase()),t[29]=f,t[30]=e);let r=l.filter(e);b=dt,t[31]===l?M=t[32]:(M=l.map(Tf),t[31]=l,t[32]=M),x=r.map(wf),S=n.threadId??null,C=u,t[33]===Symbol.for(`react.memo_cache_sentinel`)?(w=e=>{d(e),e||p(``)},t[33]=w):w=t[33],t[34]!==a||t[35]!==o||t[36]!==n||t[37]!==l?(T=e=>{let t=l.find(t=>t.id===e);t&&(d(!1),p(``),Tt(a,n,t.id,o))},t[34]=a,t[35]=o,t[36]=n,t[37]=l,t[38]=T):T=t[38];let s=i?`ghost`:`default`,c=i?`min-w-0 max-w-full`:`w-full`,h=`Choose thread: ${g}`,N;t[39]!==s||t[40]!==c||t[41]!==h?(N=(0,K.jsx)(St,{render:(0,K.jsx)(_,{size:`sm`,variant:s,className:c,"aria-label":h})}),t[39]=s,t[40]=c,t[41]=h,t[42]=N):N=t[42];let P;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,K.jsx)(Wt,{"aria-hidden":`true`}),t[43]=P):P=t[43];let F;t[44]===g?F=t[45]:(F=(0,K.jsx)(`span`,{ref:m,className:`min-w-0 truncate`,children:g}),t[44]=g,t[45]=F);let I;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,K.jsx)(oe,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),t[46]=I):I=t[46],t[47]!==g||t[48]!==N||t[49]!==F?(E=(0,K.jsxs)(Xt,{full:g,labelRef:m,render:N,children:[P,F,I]}),t[47]=g,t[48]=N,t[49]=F,t[50]=E):E=t[50],y=yt,k=`w-80 max-w-[calc(100vw-1rem)]`;let L;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(L=e=>p(e.target.value),t[51]=L):L=t[51],t[52]===f?A=t[53]:(A=(0,K.jsx)(`div`,{className:`p-2`,children:(0,K.jsx)(kt,{"aria-label":`Search threads`,placeholder:`Search threads`,showTrigger:!1,value:f,onChange:L})}),t[52]=f,t[53]=A),t[54]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,K.jsx)(fn,{children:`No matching threads`}),t[54]=j):j=t[54],v=Mt,D=`max-h-64 overflow-auto`,O=r.map(Cf),t[6]=i,t[7]=a,t[8]=g,t[9]=u,t[10]=o,t[11]=f,t[12]=n,t[13]=l,t[14]=v,t[15]=y,t[16]=b,t[17]=x,t[18]=S,t[19]=C,t[20]=w,t[21]=T,t[22]=E,t[23]=D,t[24]=O,t[25]=k,t[26]=A,t[27]=j,t[28]=M}else v=t[14],y=t[15],b=t[16],x=t[17],S=t[18],C=t[19],w=t[20],T=t[21],E=t[22],D=t[23],O=t[24],k=t[25],A=t[26],j=t[27],M=t[28];let N;t[55]!==v||t[56]!==D||t[57]!==O?(N=(0,K.jsx)(v,{className:D,children:O}),t[55]=v,t[56]=D,t[57]=O,t[58]=N):N=t[58];let P;t[59]!==a||t[60]!==o||t[61]!==n?(P=n.threadId?(0,K.jsx)(`div`,{className:`border-t border-border p-2`,children:(0,K.jsx)(_,{size:`sm`,variant:`ghost`,className:`w-full`,onClick:()=>{d(!1),Tt(a,n,null,o)},children:`Disconnect thread`})}):null,t[59]=a,t[60]=o,t[61]=n,t[62]=P):P=t[62];let F;t[63]!==y||t[64]!==N||t[65]!==P||t[66]!==k||t[67]!==A||t[68]!==j?(F=(0,K.jsxs)(y,{className:k,children:[A,j,N,P]}),t[63]=y,t[64]=N,t[65]=P,t[66]=k,t[67]=A,t[68]=j,t[69]=F):F=t[69];let I;return t[70]!==b||t[71]!==x||t[72]!==S||t[73]!==C||t[74]!==w||t[75]!==T||t[76]!==E||t[77]!==F||t[78]!==M?(I=(0,K.jsxs)(b,{items:M,filteredItems:x,value:S,open:C,onOpenChange:w,onValueChange:T,children:[E,F]}),t[70]=b,t[71]=x,t[72]=S,t[73]=C,t[74]=w,t[75]=T,t[76]=E,t[77]=F,t[78]=M,t[79]=I):I=t[79],I}function Cf(e){return(0,K.jsx)(At,{value:e.id,children:(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1 py-1`,children:[(0,K.jsx)(`span`,{className:`whitespace-normal break-words`,children:e.title}),e.worktreePath?(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Worktree`,e.branch?` · ${e.branch}`:``]}):null]})},e.id)}function wf(e){return e.id}function Tf(e){return e.id}function Ef(e){let t=(0,W.c)(2),{target:n}=e,r;return t[0]===n?r=t[1]:(r=n?.threadId?(0,K.jsx)(Sf,{target:n,compact:!0}):(0,K.jsxs)(`h2`,{children:[(0,K.jsx)(Wt,{"aria-hidden":`true`,size:16}),`Design agent`]}),t[0]=n,t[1]=r),r}function Df({target:e}){let t=Un(),n=l(),r=ot(),i=Re(e?.environmentId??null),a=ke(Ke.retryNow),o=(0,G.useMemo)(()=>zt(r,e),[r,e]),s=t.navigation.useProjects().find(t=>t.projectId===e?.projectId&&t.environmentId===e.environmentId);return e?i?.connection.phase===`connected`?(0,K.jsxs)(`div`,{className:`design-agent-connect`,children:[(0,K.jsx)(`h3`,{children:o.length?`Connect a thread`:`No threads in this project`}),(0,K.jsx)(`p`,{children:o.length?`Choose a thread in ${s?.name??`this project`} to design with its agent.`:`Start a design to open a new thread for this project.`}),o.length?(0,K.jsx)(Sf,{target:e}):(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:()=>t.navigation.startDesign?.(e),children:`New design`})]}):(0,K.jsxs)(`div`,{className:`design-agent-connect`,role:`status`,children:[(0,K.jsx)(Ot,{"aria-hidden":`true`,className:`text-muted-foreground`}),(0,K.jsx)(`h3`,{children:`Environment disconnected`}),(0,K.jsx)(`p`,{children:`Reconnect to choose a thread.`}),(0,K.jsx)(_,{size:`sm`,variant:`outline`,onClick:()=>void a(e.environmentId),children:`Retry connection`}),(0,K.jsx)(_,{size:`sm`,variant:`ghost`,onClick:()=>void n({to:`/settings/connections`}),children:`Connections`})]}):(0,K.jsxs)(`div`,{className:`design-agent-connect`,children:[(0,K.jsx)(`h3`,{children:`Choose a project`}),(0,K.jsx)(`p`,{children:`Select a project in the top bar to connect a thread.`})]})}var Of=Oe([`p4code`,...rf]),kf=()=>je(`p4code:design-theme`,`p4code`,Of);function Af(){let e=(0,W.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,K.jsx)(`div`,{style:{paddingInlineStart:rt?`var(--workspace-controls-left)`:void 0},children:(0,K.jsx)(Kt,{onBackdrop:!1,insetForTitlebar:!1})}),e[0]=t):t=e[0],t}function jf(){let e=(0,W.c)(16),[t,n]=kf(),r=l(),i,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,K.jsx)(_,{size:`sm`,variant:`ghost`}),a=(0,K.jsx)(Ht,{"aria-hidden":`true`}),e[0]=i,e[1]=a):(i=e[0],a=e[1]);let o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,K.jsxs)(C,{render:i,children:[a,`Theme`,(0,K.jsx)(oe,{"aria-hidden":`true`,className:`size-3`})]}),e[2]=o):o=e[2];let s;e[3]===n?s=e[4]:(s=e=>{(e===`p4code`||of(e))&&n(e)},e[3]=n,e[4]=s);let c,u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,K.jsx)(w,{value:`p4code`,children:`P4 Code`}),u=rf.map(Mf),e[5]=c,e[6]=u):(c=e[5],u=e[6]);let d;e[7]!==s||e[8]!==t?(d=(0,K.jsxs)(y,{value:t,onValueChange:s,children:[c,u]}),e[7]=s,e[8]=t,e[9]=d):d=e[9];let f;e[10]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,K.jsx)(A,{}),e[10]=f):f=e[10];let p;e[11]===r?p=e[12]:(p=(0,K.jsx)(N,{onClick:()=>void r({to:`/settings/appearance`}),children:`P4 Code appearance`}),e[11]=r,e[12]=p);let m;return e[13]!==d||e[14]!==p?(m=(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)(we,{children:[o,(0,K.jsxs)(F,{children:[d,f,p]})]})}),e[13]=d,e[14]=p,e[15]=m):m=e[15],m}function Mf(e){return(0,K.jsx)(w,{value:e,children:af[e]},e)}var Nf=e=>e.threadId?{environmentId:e.environmentId,threadId:e.threadId}:null;function Pf(e){return Re(e)?.connection.phase===`connected`}function Ff(e,t){let n=(0,W.c)(9),r;n[0]===e?r=n[1]:(r=e?Nf(e):null,n[0]=e,n[1]=r);let i=it(r),a=i?.latestTurn?.state===`running`,o=vd(e,t),s=yd(e,t),c;n[2]===Symbol.for(`react.memo_cache_sentinel`)?(c={running:!1,sequence:null},n[2]=c):c=n[2];let[l,u]=(0,G.useState)(c);l.running!==a&&u({running:a,sequence:s});let d=i?.session?.providerInstanceId??i?.modelSelection.instanceId??``,f;return n[3]!==l.sequence||n[4]!==o||n[5]!==d||n[6]!==a||n[7]!==s?(f=uf({running:a,label:d?lf(d):`Agent`,frame:o,sequence:s,baseline:l.sequence}),n[3]=l.sequence,n[4]=o,n[5]=d,n[6]=a,n[7]=s,n[8]=f):f=n[8],f}var If={current(e){let t=Nf(e);if(!t)return;let n=hn.getState(),r=yn(t),i=n.selections[r];return i?{selection:i,label:n.labels[r]}:void 0},set(e,t,n){let r=Nf(e);r&&hn.getState().set(r,t,n)}};function Lf(e){let t=l(),n=ht(),r=(0,G.useRef)(!1);return(0,G.useMemo)(()=>({runtime:ge,transport:xf,AgentHeader:Ef,AgentPanel:Df,TopbarStart:Af,TopbarEnd:jf,useConnected:Pf,useCanvasPlaceholder:(e,t)=>e&&!t.loading&&!t.failed&&t.paths.length===0?(0,G.createElement)(cf,{target:e}):null,navigation:{useWorkspaceRoot:Ut,linkEnvironment:!0,startDesign:e=>{let t=Nf(e);if(t){hn.getState().begin(t);return}r.current||(r.current=!0,n(e,{exactProject:!0,forceNew:!0}).then(({draftId:e})=>hn.getState().begin(e)).catch(()=>{S.add({type:`error`,title:`Could not start a design. Try again.`})}).finally(()=>{r.current=!1}))},createProject:()=>tn({open:`add-project`}),openSettings:()=>{t({to:`/settings/plugins`})},useTarget:()=>Gt(e),useActivePath:bn,useProjects:Ct,openProject:t=>bt(e,t),openDocument:(t,n,r)=>Vt(t,n,e,r),...e.returnToThread?{returnToThread:t=>{let n=Nf(t);n&&e.returnToThread?.(n)}}:{}},review:{useBaselineKey:mf,useRejectTurn:hf},...e.renderThread?{thread:{label:`Thread in P4 Code`,render:t=>{let n=Nf(t);return n?e.renderThread?.(n):null}}}:{},attachment:If,useAgentPresence:Ff}),[e,n,t])}function Rf(e){let t=(0,W.c)(10),{context:n,resourceId:r,surface:i}=e,a=Lf(n),[o]=kf(),s=`h-full min-h-0 min-w-0 flex-1 ${o!==`p4code`&&sf(o)?`dark`:``}`,c=o===`p4code`?void 0:o,l;t[0]!==r||t[1]!==i?(l=(0,K.jsx)(nf,{resourceId:r,surface:i}),t[0]=r,t[1]=i,t[2]=l):l=t[2];let u;t[3]!==s||t[4]!==c||t[5]!==l?(u=(0,K.jsx)(`div`,{className:s,"data-design-theme":c,children:l}),t[3]=s,t[4]=c,t[5]=l,t[6]=u):u=t[6];let d;return t[7]!==a||t[8]!==u?(d=(0,K.jsx)(Hn,{host:a,children:u}),t[7]=a,t[8]=u,t[9]=d):d=t[9],d}export{Rf as default};
|
|
19
|
-
//# sourceMappingURL=P4DesignScreen-
|
|
19
|
+
//# sourceMappingURL=P4DesignScreen-CAko1RXc.js.map
|