@oh-just-another/diagram 0.1.0 → 0.2.0

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.
@@ -1,5 +1,5 @@
1
- var Pe=Object.defineProperty;var K=(t,e)=>{for(var n in e)Pe(t,n,{get:e[n],enumerable:!0})};var ce=new Map,_=(t,e)=>{ce.set(t,e)},de=t=>ce.get(t);var q=(t,e,n)=>{if(!t||t.type==="sharp")return 0;let o=Math.min(Math.abs(e),Math.abs(n));if(o<=0)return 0;if(t.value!==void 0)return Math.max(0,Math.min(t.value,o/2));let r=32/.25;return o<=r?o*.25:32};var x=t=>{if(t===void 0)throw new Error("required value is undefined");return t};var A={};K(A,{IDENTITY:()=>Ne,applyToBounds:()=>qe,applyToPoint:()=>D,decompose:()=>Ve,equals:()=>Ye,inverse:()=>Ke,multiply:()=>Xe,of:()=>He,rotation:()=>Ue,scaling:()=>ze,translation:()=>Ge});var Ne=Object.freeze({a:1,b:0,c:0,d:1,e:0,f:0}),He=(t,e,n,o,r,i)=>({a:t,b:e,c:n,d:o,e:r,f:i}),Ge=(t,e)=>({a:1,b:0,c:0,d:1,e:t,f:e}),ze=(t,e=t)=>({a:t,b:0,c:0,d:e,e:0,f:0}),Ue=t=>{let e=Math.cos(t),n=Math.sin(t);return{a:e,b:n,c:-n,d:e,e:0,f:0}},Xe=(t,e)=>({a:t.a*e.a+t.c*e.b,b:t.b*e.a+t.d*e.b,c:t.a*e.c+t.c*e.d,d:t.b*e.c+t.d*e.d,e:t.a*e.e+t.c*e.f+t.e,f:t.b*e.e+t.d*e.f+t.f}),Ke=t=>{let e=t.a*t.d-t.b*t.c;if(e===0)throw new Error("Cannot invert singular matrix");return{a:t.d/e,b:-t.b/e,c:-t.c/e,d:t.a/e,e:(t.c*t.f-t.d*t.e)/e,f:(t.b*t.e-t.a*t.f)/e}},D=(t,e)=>({x:t.a*e.x+t.c*e.y+t.e,y:t.b*e.x+t.d*e.y+t.f}),qe=(t,e)=>{let n=D(t,{x:e.x,y:e.y}),o=D(t,{x:e.x+e.width,y:e.y}),r=D(t,{x:e.x,y:e.y+e.height}),i=D(t,{x:e.x+e.width,y:e.y+e.height}),a=Math.min(n.x,o.x,r.x,i.x),l=Math.min(n.y,o.y,r.y,i.y),s=Math.max(n.x,o.x,r.x,i.x),c=Math.max(n.y,o.y,r.y,i.y);return{x:a,y:l,width:s-a,height:c-l}},Ve=t=>{let e=Math.sqrt(t.a*t.a+t.b*t.b),n=Math.sqrt(t.c*t.c+t.d*t.d),r=t.a*t.d-t.b*t.c<0?-n:n;return{translation:{x:t.e,y:t.f},rotation:Math.atan2(t.b,t.a),scale:{x:e,y:r}}},Ye=(t,e,n=0)=>{let o=["a","b","c","d","e","f"];return n===0?o.every(r=>t[r]===e[r]):o.every(r=>Math.abs(t[r]-e[r])<=n)};var E={};K(E,{EMPTY:()=>me,centerOf:()=>Ze,contains:()=>tt,containsBounds:()=>nt,equals:()=>it,expand:()=>ot,fromCenter:()=>$e,fromPoints:()=>Je,intersection:()=>he,intersects:()=>et,isEmpty:()=>V,maxX:()=>L,maxY:()=>I,normalize:()=>rt,of:()=>je,union:()=>Qe});var me=Object.freeze({x:0,y:0,width:0,height:0}),je=(t,e,n,o)=>({x:t,y:e,width:n,height:o}),Je=t=>{if(t.length===0)return me;let e=1/0,n=1/0,o=-1/0,r=-1/0;for(let i of t)i.x<e&&(e=i.x),i.y<n&&(n=i.y),i.x>o&&(o=i.x),i.y>r&&(r=i.y);return{x:e,y:n,width:o-e,height:r-n}},$e=(t,e,n)=>({x:t.x-e/2,y:t.y-n/2,width:e,height:n}),Ze=t=>({x:t.x+t.width/2,y:t.y+t.height/2}),L=t=>t.x+t.width,I=t=>t.y+t.height,V=t=>t.width<=0||t.height<=0,Qe=(t,e)=>{if(V(t))return e;if(V(e))return t;let n=Math.min(t.x,e.x),o=Math.min(t.y,e.y),r=Math.max(L(t),L(e)),i=Math.max(I(t),I(e));return{x:n,y:o,width:r-n,height:i-o}},he=(t,e)=>{let n=Math.max(t.x,e.x),o=Math.max(t.y,e.y),r=Math.min(L(t),L(e)),i=Math.min(I(t),I(e));return r<=n||i<=o?null:{x:n,y:o,width:r-n,height:i-o}},et=(t,e)=>he(t,e)!==null,tt=(t,e)=>e.x>=t.x&&e.x<=L(t)&&e.y>=t.y&&e.y<=I(t),nt=(t,e)=>e.x>=t.x&&e.y>=t.y&&L(e)<=L(t)&&I(e)<=I(t),ot=(t,e)=>({x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}),rt=t=>({x:t.width<0?t.x+t.width:t.x,y:t.height<0?t.y+t.height:t.y,width:Math.abs(t.width),height:Math.abs(t.height)}),it=(t,e,n=0)=>n===0?t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height:Math.abs(t.x-e.x)<=n&&Math.abs(t.y-e.y)<=n&&Math.abs(t.width-e.width)<=n&&Math.abs(t.height-e.height)<=n;var M={};K(M,{offsetClosedPath:()=>st,signedArea:()=>at});var st=(t,e)=>{if(t.length<3||e===0)return t.map(s=>({x:s.x,y:s.y}));let n=0,o=0;for(let s of t)n+=s.x,o+=s.y;n/=t.length,o/=t.length;let r=t.length,i=new Array(r),a=new Array(r);for(let s=0;s<r;s++){let c=x(t[s]),d=x(t[(s+1)%r]),m=d.x-c.x,f=d.y-c.y,y=Math.hypot(m,f)||1;i[s]=-f/y,a[s]=m/y}let l=[];for(let s=0;s<r;s++){let c=(s-1+r)%r,d=x(i[c]),m=x(a[c]),f=x(i[s]),y=x(a[s]),w=d+f,p=m+y,T=Math.hypot(w,p);T<1e-6?(w=d,p=m):(w/=T,p/=T);let O=x(t[s]),b=n-O.x,h=o-O.y,R=w*b+p*h>=0?1:-1,ae=w*d+p*m,le=ae>1e-6?e/ae:e;l.push({x:O.x+R*w*le,y:O.y+R*p*le})}return l},at=t=>{let e=0;for(let n=0;n<t.length;n++){let o=x(t[n]),r=x(t[(n+1)%t.length]);e+=o.x*r.y-r.x*o.y}return e/2};var lt=null;var ue=()=>lt;var Y=t=>t.type==="text";var fe=new Map,k=(t,e)=>{fe.set(t,e)};var xe=t=>{let e=fe.get(t.type);if(!e)throw new Error(`No bounder registered for shape type: ${t.type}`);return e(t)},j=t=>{let e=xe(t),n=[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x,y:e.y+e.height},{x:e.x+e.width,y:e.y+e.height}],o=Math.sin(t.rotation),r=Math.cos(t.rotation),i=n.map(a=>{let l=a.x*t.scale.x,s=a.y*t.scale.y;return{x:t.position.x+(l*r-s*o),y:t.position.y+(l*o+s*r)}});return E.fromPoints(i)};k("rectangle",t=>({x:0,y:0,width:t.width,height:t.height}));k("ellipse",t=>({x:0,y:0,width:t.width,height:t.height}));k("polygon",t=>E.fromPoints(t.points));k("path",t=>{let e=[],n={x:0,y:0};for(let o of t.commands)switch(o.kind){case"M":case"L":e.push(o.to),n=o.to;break;case"Q":e.push(o.control,o.to),n=o.to;break;case"C":e.push(o.control1,o.control2,o.to),n=o.to;break;case"Z":break}return E.fromPoints(e)});k("text",t=>{let e=t.fontSize*1.2,n=t.text.split(`
2
- `),o=ue(),r={bold:t.style.fontWeight==="bold",italic:t.style.fontStyle==="italic"},i=l=>{if(o){let s=o(l,t.fontFamily,t.fontSize,r);if(s!==null)return s}return l.length*t.fontSize*.6};if(t.maxWidth===void 0){let l=0;for(let s of n)l=Math.max(l,i(s));return l=Math.max(l,t.fontSize*.5),{x:0,y:0,width:l,height:Math.max(1,n.length)*e}}let a=0;for(let l of n)a+=Math.max(1,Math.ceil(i(l)/t.maxWidth));return{x:0,y:0,width:t.maxWidth,height:Math.max(1,a)*e}});k("image",t=>({x:0,y:0,width:t.width,height:t.height}));k("template",t=>({x:0,y:0,width:t.width,height:t.height}));k("brush",t=>{if(t.points.length===0)return{x:0,y:0,width:0,height:0};let e=1/0,n=1/0,o=-1/0,r=-1/0;for(let i of t.points)i.x-i.width<e&&(e=i.x-i.width),i.y-i.width<n&&(n=i.y-i.width),i.x+i.width>o&&(o=i.x+i.width),i.y+i.width>r&&(r=i.y+i.width);return{x:e,y:n,width:o-e,height:r-n}});k("group",()=>({x:0,y:0,width:0,height:0}));k("frame",t=>({x:0,y:0,width:t.width,height:t.height}));k("block-arrow",t=>({x:0,y:0,width:t.width,height:t.height}));var J=(t,e)=>t.order<e.order?-1:t.order>e.order?1:0;var $=t=>[...t.layers.values()].sort(J),H=(t,e)=>[...t.elements.values()].filter(n=>n.layerId===e).sort(J);var ct=new Map,Z=(t,e)=>{ct.set(t,e)};var dt=Object.freeze({pan:{x:0,y:0},zoom:1,rotation:0,size:{width:0,height:0},gridEnabled:!1}),Q=t=>{let e=A.translation(-t.pan.x,-t.pan.y),n=A.rotation(t.rotation),o=A.scaling(t.zoom);return A.multiply(o,A.multiply(n,e))};var F=class{entries=new Map;get(e){let n=this.entries.get(e.id);if(n){if(n.ref!==e){this.entries.delete(e.id);return}return n.value}}set(e,n){return this.entries.set(e.id,{ref:e,value:n}),n}getOrCompute(e,n){let o=this.get(e);return o!==void 0?o:this.set(e,n(e))}invalidate(e){this.entries.delete(e)}clear(){this.entries.clear()}prune(e){for(let n of this.entries.keys())e.elements.has(n)||this.entries.delete(n)}get size(){return this.entries.size}},$n=new F,P=(t,e)=>t.getOrCompute(e,j);var ye="#bbb";var pe=.06,ge=.92,be=.5;var Re=.4,Te=.5,ee=.1,te=.9,we="#888",Ee="#ffffff",ke="#222",_e="#ddd";var v=class{cap;onEvict;map=new Map;constructor(e,n){this.cap=e,this.onEvict=n}get(e){let n=this.map.get(e);if(n!==void 0)return this.map.delete(e),this.map.set(e,n),n}has(e){return this.map.has(e)}set(e,n){for(this.map.delete(e),this.map.set(e,n);this.map.size>this.cap;){let o=this.map.keys().next().value,r=this.map.get(o);this.map.delete(o),r!==void 0&&this.onEvict?.(o,r)}}delete(e){return this.map.delete(e)}clear(){this.map.clear()}get size(){return this.map.size}keys(){return this.map.keys()}values(){return this.map.values()}};var Ae=t=>t<=0?1:2**Math.round(Math.log2(t));var ne=(t,e,n={})=>{let o=Q(t.viewport),r=n.dirtyWorld;if(!n.skipClear)if(r){let b=[A.applyToPoint(o,{x:r.x,y:r.y}),A.applyToPoint(o,{x:r.x+r.width,y:r.y+r.height})],h=E.expand(E.fromPoints(b),2);e.clear(h)}else e.clear();e.save(),e.setTransform(o);let i=n.boundsCache??new F,a=n.viewport,l=null;a&&n.spatialIndex&&(l=n.spatialIndex.query(a));let s=t.viewport.zoom,c=n.lod,d=c?.placeholder!==void 0&&s<c.placeholder,m=c?.hideText!==void 0&&s<c.hideText,f=n.placeholderFill??ye,y=n.layerCompositeCache,w=n.dirtyLayerIds,p=n.compositeLayerBitmap,T=Ae(s),O=b=>{let h=null;for(let g of H(t,b)){let R=P(i,g);h=h?E.union(h,R):R}return h};for(let b of $(t))if(b.visible){if(y&&p){w?.has(b.id)&&y.invalidateLayer(b.id);let h=y.get(b.id,T);if(h===void 0){let g=p(b.id,T,t);g!==null&&(y.set(b.id,T,g),h=g)}if(h!==void 0){let g=O(b.id);g&&e.drawImage(h,g.x,g.y,g.width,g.height);continue}}for(let h of H(t,b.id)){if(n.hideElements?.has(h.id)||l&&!l.has(h.id))continue;if(a){let R=P(i,h);if(!E.intersects(R,a))continue}if(r){let R=P(i,h);if(!E.intersects(R,r))continue}if(m&&Y(h))continue;if(d){let R=P(i,h);e.setFill(f),e.setStrokeWidth(0),e.beginPath(),e.rect(R.x,R.y,R.width,R.height),e.fill();continue}let g=de(h.type);if(!g){n.onUnknownElement?.(h);continue}e.save(),n.dimElements?.has(h.id)&&n.dimOpacity!==void 0&&e.setOpacity(n.dimOpacity),e.translate(h.position.x,h.position.y),h.rotation!==0&&e.rotate(h.rotation),(h.scale.x!==1||h.scale.y!==1)&&e.scale(h.scale.x,h.scale.y),g(h,e,{zoom:s}),e.restore()}}e.restore()};var mt=1.2,ht=(t,e,n,o,r)=>{if(t===""){r.push({text:"",start:e,end:e,width:0});return}let i=[],a=/\S+/g,l;for(;(l=a.exec(t))!==null;)i.push({s:l.index,e:l.index+l[0].length});if(i.length===0){r.push({text:t,start:e,end:e+t.length,width:o(t)});return}let s=0,c=(m,f)=>{let y=t.slice(m,f);r.push({text:y,start:e+m,end:e+f,width:o(y)})},d=0;for(;d<i.length;){let m=x(i[d]);if(o(t.slice(s,m.e))<=n){d++;continue}if(m.s>s){c(s,m.s),s=m.s;continue}let f=m.s+1;for(;f<m.e&&o(t.slice(s,f+1))<=n;)f++;if(f>=m.e){d++;continue}c(s,f),s=f,m.s=f}c(s,t.length)},Le=(t,e,n)=>{let o=n.fontSize*(n.lineHeightFactor??mt),r=[],i=0;for(let s=0;s<=t.length;s++)if(s===t.length||t[s]===`
3
- `){let c=t.slice(i,s);n.maxWidth===void 0?r.push({text:c,start:i,end:s,width:e(c)}):ht(c,i,n.maxWidth,e,r),i=s+1}r.length===0&&r.push({text:"",start:0,end:0,width:0});let a=0;for(let s of r)a=Math.max(a,s.width);let l=n.maxWidth??a;return{lines:r,lineHeight:o,blockWidth:l}};var ut=new Map;var ft=()=>typeof performance<"u"?performance.now():0;var oe=(t,e=ft(t))=>{if(!t.animationKind)return t.src;let n=ut.get(t.animationKind);if(!n)return t.src;try{return n.getFrameAt(t.animationData,e)}catch{return t.src}};var B=(t,e)=>{let n=t.fill!==void 0&&t.fill!=="transparent",o=t.stroke!==void 0&&t.stroke!=="transparent"&&(t.strokeWidth??1)>0;return n&&e.setFill(t.fill),o&&(e.setStroke(t.stroke),e.setStrokeWidth(t.strokeWidth??1),t.lineCap&&e.setLineCap(t.lineCap),t.lineJoin&&e.setLineJoin(t.lineJoin),t.dashArray&&e.setDashArray(t.dashArray)),t.opacity!==void 0&&e.setOpacity(t.opacity),{fill:n,stroke:o}},yt=(t,e)=>{let{fill:n,stroke:o}=B(t.style,e);if(!n&&!o)return;let r=q(t.style.roundness,t.width,t.height);if(n&&(e.beginPath(),r>0?Ie(e,0,0,t.width,t.height,r):e.rect(0,0,t.width,t.height),e.fill()),o){let i=U(t.style),a=i,l=i,s=t.width-2*i,c=t.height-2*i;if(s<=0||c<=0)return;let d=r>0?Math.max(0,r-i):0;e.beginPath(),d>0?Ie(e,a,l,s,c,d):e.rect(a,l,s,c),e.stroke()}},U=t=>{let e=t.strokeAlign??"center";if(e==="center")return 0;let n=(t.strokeWidth??1)/2;return e==="inside"?n:-n},Ie=(t,e,n,o,r,i)=>{t.moveTo(e+i,n),t.lineTo(e+o-i,n),t.quadraticCurveTo(e+o,n,e+o,n+i),t.lineTo(e+o,n+r-i),t.quadraticCurveTo(e+o,n+r,e+o-i,n+r),t.lineTo(e+i,n+r),t.quadraticCurveTo(e,n+r,e,n+r-i),t.lineTo(e,n+i),t.quadraticCurveTo(e,n,e+i,n),t.closePath()},pt=(t,e)=>{let{fill:n,stroke:o}=B(t.style,e);if(!n&&!o)return;let r=t.width/2,i=t.height/2;if(n&&(e.beginPath(),e.ellipse(r,i,r,i),e.fill()),o){let a=U(t.style),l=r-a,s=i-a;if(l<=0||s<=0)return;e.beginPath(),e.ellipse(r,i,l,s),e.stroke()}},gt=(t,e)=>{if(t.points.length<2)return;let{fill:n,stroke:o}=B(t.style,e);if(!(!n&&!o)&&(n&&(e.beginPath(),z(e,t.points),e.fill()),o)){let r=U(t.style),i=r!==0?M.offsetClosedPath(t.points,r):t.points;e.beginPath(),z(e,i),e.stroke()}},z=(t,e)=>{let n=e[0];if(n!==void 0){t.moveTo(n.x,n.y);for(let o=1;o<e.length;o++){let r=e[o];r!==void 0&&t.lineTo(r.x,r.y)}t.closePath()}},bt=(t,e)=>{if(t.commands.length===0)return;let{fill:n,stroke:o}=B(t.style,e);if(!(!n&&!o)){e.beginPath();for(let r of t.commands)switch(r.kind){case"M":e.moveTo(r.to.x,r.to.y);break;case"L":e.lineTo(r.to.x,r.to.y);break;case"Q":e.quadraticCurveTo(r.control.x,r.control.y,r.to.x,r.to.y);break;case"C":e.bezierCurveTo(r.control1.x,r.control1.y,r.control2.x,r.control2.y,r.to.x,r.to.y);break;case"Z":e.closePath();break}n&&e.fill(),o&&e.stroke()}},Rt=(t,e)=>{let n=t.style.textAlign??"left",o=t.style.fontWeight,r=t.style.fontStyle;e.setFont(t.fontFamily,t.fontSize,{...o?{weight:o}:{},...r?{style:r}:{}}),e.setTextAlign("left"),e.setTextBaseline(t.style.textBaseline??"top");let i=t.style.fill??"#000";e.setFill(i),t.style.opacity!==void 0&&e.setOpacity(t.style.opacity);let a=t.fontSize,l;if(t.maxWidth===void 0&&!t.text.includes(`
4
- `))l=[{text:t.text,x:0,width:e.measureText(t.text).width,top:0}];else{let c=m=>e.measureText(m).width,d=Le(t.text,c,{fontSize:a,...t.maxWidth!==void 0?{maxWidth:t.maxWidth}:{}});l=d.lines.map((m,f)=>({text:m.text,x:n==="center"?d.blockWidth/2-m.width/2:n==="right"?d.blockWidth-m.width:0,width:m.width,top:f*d.lineHeight}))}for(let c of l)e.fillText(c.text,c.x,c.top);let s=t.style.textDecoration;if(s?.underline||s?.strikethrough){let c=Math.max(1,a*pe);for(let d of l)d.width<=0||(s.underline&&(e.beginPath(),e.rect(d.x,d.top+a*ge,d.width,c),e.fill()),s.strikethrough&&(e.beginPath(),e.rect(d.x,d.top+a*be-c/2,d.width,c),e.fill()))}},Tt=(t,e)=>{let n=t.points;if(n.length===0)return;let o=t.style.fill??t.style.stroke??"#000";if(e.setFill(o),e.setStroke(null),n.length===1){let r=x(n[0]);e.beginPath(),e.ellipse(r.x,r.y,r.width,r.width),e.fill();return}for(let r=0;r<n.length-1;r++){let i=x(n[r]),a=x(n[r+1]),l=a.x-i.x,s=a.y-i.y,c=Math.hypot(l,s)||1,d=-s/c,m=l/c;e.beginPath(),e.moveTo(i.x+d*i.width,i.y+m*i.width),e.lineTo(a.x+d*a.width,a.y+m*a.width),e.lineTo(a.x-d*a.width,a.y-m*a.width),e.lineTo(i.x-d*i.width,i.y-m*i.width),e.closePath(),e.fill(),e.beginPath(),e.ellipse(a.x,a.y,a.width,a.width),e.fill()}},wt=(t,e)=>{let n=t.animationKind?oe(t):t.metadata?.image??oe(t),o=t.metadata?.animated===!0||t.animationKind!==void 0;e.drawImage(n,0,0,t.width,t.height,o)},se=()=>{_("rectangle",yt),_("ellipse",pt),_("polygon",gt),_("path",bt),_("text",Rt),_("image",wt),_("group",()=>{}),_("frame",At),Z("frame",()=>({top:24})),_("block-arrow",Et),_("brush",Tt)},Et=(t,e)=>{let{fill:n,stroke:o}=B(t.style,e),r=t.direction??"right",i=Math.max(ee,Math.min(te,t.headRatio??Re)),a=Math.max(ee,Math.min(te,t.bodyThickness??Te)),l=t.width,s=t.height,c=l*i,d=l-c,m=s*a/2,f=s/2,y=[[0,f-m],[d,f-m],[d,0],[l,f],[d,s],[d,f+m],[0,f+m]];r!=="right"&&(y=y.map(([p,T])=>kt([p,T],r,l,s)));let w=y.map(([p,T])=>({x:p,y:T}));if(n&&(e.beginPath(),z(e,w),e.fill()),o){let p=U(t.style),T=p!==0?M.offsetClosedPath(w,p):w;e.beginPath(),z(e,T),e.stroke()}},kt=([t,e],n,o,r)=>{switch(n){case"left":return[o-t,e];case"up":return[e*(o/r),r-t*(r/o)];case"down":return[(r-e)*(o/r),t*(r/o)]}},ie="\u2026",_t=(t,e,n)=>{if(e<=0)return"";if(n.measureText(t).width<=e)return t;let o=0,r=t.length;for(;o<r;){let i=Math.ceil((o+r)/2);n.measureText(t.slice(0,i)+ie).width<=e?o=i:r=i-1}return o>0?t.slice(0,o)+ie:ie},At=(t,e,n)=>{e.setFill(t.style.fill??Ee),e.setStroke(null),e.setDashArray(null),e.beginPath(),e.rect(0,0,t.width,t.height),e.fill();let o=(n?.zoom??1)*(t.scale.x||1);e.setFill(null),e.setStroke(we),e.setStrokeWidth(1/(o||1)),e.setDashArray(null),e.beginPath(),e.rect(0,0,t.width,t.height),e.stroke();let r=t.name??"Frame";e.setFont("system-ui, sans-serif",12);let i=t.width-16,a=e.measureText(r).width<=i,l=a?r:_t(r,i,e),s=a?Math.min(e.measureText(r).width+16,t.width):t.width;e.setFill(ke),e.beginPath(),e.rect(0,-24,s,24),e.fill(),e.setFill(_e),e.setTextBaseline("middle"),e.setTextAlign("left"),e.fillText(l,8,-24/2)};var S="Roboto",W="PT Serif",N="Roboto Mono",ve=t=>{let e=t.toLowerCase();return e.includes("mono")?N:e.includes("sans")?S:e.includes("serif")||e.includes("slab")||e.includes("georgia")||e.includes("times")?W:S},Lt=[{family:S,weight:"400",style:"normal",url:new URL("../fonts/Roboto-Regular.woff2",import.meta.url)},{family:S,weight:"700",style:"normal",url:new URL("../fonts/Roboto-Bold.woff2",import.meta.url)},{family:S,weight:"400",style:"italic",url:new URL("../fonts/Roboto-Italic.woff2",import.meta.url)},{family:S,weight:"700",style:"italic",url:new URL("../fonts/Roboto-BoldItalic.woff2",import.meta.url)},{family:W,weight:"400",style:"normal",url:new URL("../fonts/PTSerif-Regular.woff2",import.meta.url)},{family:W,weight:"700",style:"normal",url:new URL("../fonts/PTSerif-Bold.woff2",import.meta.url)},{family:W,weight:"400",style:"italic",url:new URL("../fonts/PTSerif-Italic.woff2",import.meta.url)},{family:W,weight:"700",style:"italic",url:new URL("../fonts/PTSerif-BoldItalic.woff2",import.meta.url)},{family:N,weight:"400",style:"normal",url:new URL("../fonts/RobotoMono-Regular.woff2",import.meta.url)},{family:N,weight:"700",style:"normal",url:new URL("../fonts/RobotoMono-Bold.woff2",import.meta.url)},{family:N,weight:"400",style:"italic",url:new URL("../fonts/RobotoMono-Italic.woff2",import.meta.url)},{family:N,weight:"700",style:"italic",url:new URL("../fonts/RobotoMono-BoldItalic.woff2",import.meta.url)}],Ce=async(t=globalThis)=>{let e=t.fonts;!e||typeof FontFace>"u"||await Promise.allSettled(Lt.map(async n=>{let o=new FontFace(n.family,`url(${n.url.href})`,{weight:n.weight,style:n.style});await o.load(),e.add(o)}))};var It=["HTMLImageElement","HTMLCanvasElement","HTMLVideoElement","ImageBitmap","OffscreenCanvas","SVGImageElement","VideoFrame"],Se=t=>{if(typeof t!="object"||t===null)return!1;let e=globalThis;for(let n of It){let o=e[n];if(typeof o=="function"&&t instanceof o)return!0}return!1},Oe=new Set,De=t=>{if(typeof console>"u")return;let e=typeof t=="string"?t.startsWith("blob:")?"dead-blob-url":"string-src":t==null?"empty":"stale-object";Oe.has(e)||(Oe.add(e),console.warn(`[renderer] skipped a non-drawable image source (kind: ${e}). The shape's image handle isn't a live HTMLImageElement / canvas / bitmap \u2014 likely a scene restored from storage where the <img> was lost (metadata.image) and src is a dead blob: URL. The image won't render until rehydrated from Scene.files.`))};var X=class{ctx;_width;_height;dpr;constructor(e,n,o,r=1){this.ctx=e,this._width=n,this._height=o,this.dpr=r}get size(){return{width:this._width,height:this._height}}resize(e,n,o){this._width=e,this._height=n,o!==void 0&&(this.dpr=o)}setFill(e){this.ctx.fillStyle=e??"transparent"}setStroke(e){this.ctx.strokeStyle=e??"transparent"}setStrokeWidth(e){this.ctx.lineWidth=e}setOpacity(e){this.ctx.globalAlpha=e}setLineCap(e){this.ctx.lineCap=e}setLineJoin(e){this.ctx.lineJoin=e}setDashArray(e){this.ctx.setLineDash(e?[...e]:[])}setFont(e,n,o){let r=o?.style==="italic"?"italic ":"",i=o?.weight==="bold"?"bold ":"";this.ctx.font=`${r}${i}${n}px "${ve(e)}", ${e}`}setTextAlign(e){this.ctx.textAlign=e==="center"?"center":e}setTextBaseline(e){this.ctx.textBaseline=e==="middle"?"middle":e==="top"?"top":"bottom"}save(){this.ctx.save()}restore(){this.ctx.restore()}translate(e,n){this.ctx.translate(e,n)}rotate(e){this.ctx.rotate(e)}scale(e,n){this.ctx.scale(e,n)}setTransform(e){let n=this.dpr;this.ctx.setTransform(n*e.a,n*e.b,n*e.c,n*e.d,n*e.e,n*e.f)}resetTransform(){this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0)}beginPath(){this.ctx.beginPath()}closePath(){this.ctx.closePath()}moveTo(e,n){this.ctx.moveTo(e,n)}lineTo(e,n){this.ctx.lineTo(e,n)}quadraticCurveTo(e,n,o,r){this.ctx.quadraticCurveTo(e,n,o,r)}bezierCurveTo(e,n,o,r,i,a){this.ctx.bezierCurveTo(e,n,o,r,i,a)}rect(e,n,o,r){this.ctx.rect(e,n,o,r)}ellipse(e,n,o,r){this.ctx.ellipse(e,n,o,r,0,0,Math.PI*2)}fill(e){this.ctx.fill(e)}stroke(){this.ctx.stroke()}fillText(e,n,o,r){r!==void 0?this.ctx.fillText(e,n,o,r):this.ctx.fillText(e,n,o)}measureText(e){return{width:this.ctx.measureText(e).width}}drawImage(e,n,o,r,i,a){if(!Se(e)){De(e);return}this.ctx.drawImage(e,n,o,r,i)}clear(e){this.dirtyRect=null,e?this.ctx.clearRect(e.x,e.y,e.width,e.height):(this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore())}dirtyRect=null;markDirty(e){if(!this.dirtyRect){this.dirtyRect=e;return}let n=Math.min(this.dirtyRect.x,e.x),o=Math.min(this.dirtyRect.y,e.y),r=Math.max(this.dirtyRect.x+this.dirtyRect.width,e.x+e.width),i=Math.max(this.dirtyRect.y+this.dirtyRect.height,e.y+e.height);this.dirtyRect={x:n,y:o,width:r-n,height:i-o}}getDirtyRect(){return this.dirtyRect}};var Me=(t,e,n=new v(64))=>{for(let o of e)switch(o.k){case"setFill":t.setFill(o.color);break;case"setStroke":t.setStroke(o.color);break;case"setStrokeWidth":t.setStrokeWidth(o.w);break;case"setOpacity":t.setOpacity(o.a);break;case"setLineCap":t.setLineCap(o.cap);break;case"setLineJoin":t.setLineJoin(o.join);break;case"setDashArray":t.setDashArray(o.dash);break;case"setFont":t.setFont(o.family,o.size,o.options);break;case"setTextAlign":t.setTextAlign(o.align);break;case"setTextBaseline":t.setTextBaseline(o.baseline);break;case"save":t.save();break;case"restore":t.restore();break;case"translate":t.translate(o.x,o.y);break;case"rotate":t.rotate(o.r);break;case"scale":t.scale(o.sx,o.sy);break;case"setTransform":t.setTransform(o.t);break;case"resetTransform":t.resetTransform();break;case"beginPath":t.beginPath();break;case"closePath":t.closePath();break;case"moveTo":t.moveTo(o.x,o.y);break;case"lineTo":t.lineTo(o.x,o.y);break;case"quadraticCurveTo":t.quadraticCurveTo(o.cx,o.cy,o.x,o.y);break;case"bezierCurveTo":t.bezierCurveTo(o.c1x,o.c1y,o.c2x,o.c2y,o.x,o.y);break;case"rect":t.rect(o.x,o.y,o.w,o.h);break;case"ellipse":t.ellipse(o.cx,o.cy,o.rx,o.ry);break;case"fill":o.rule!==void 0?t.fill(o.rule):t.fill();break;case"stroke":t.stroke();break;case"fillText":o.maxWidth!==void 0?t.fillText(o.text,o.x,o.y,o.maxWidth):t.fillText(o.text,o.x,o.y);break;case"clear":o.bounds!==void 0?t.clear(o.bounds):t.clear();break;case"markDirty":t.markDirty?.(o.bounds);break;case"resize":break;case"defineImage":n.set(o.id,o.bitmap);break;case"drawImage":{let r=n.get(o.id);r&&t.drawImage(r,o.dx,o.dy,o.dw,o.dh);break}}};var u={canvas:null,target:null,dpr:1,images:new v(64,(t,e)=>{e.close()})},Fe=!1,Ct=()=>{Fe||(se(),Fe=!0)},C=(t,e)=>{e&&e.length>0?self.postMessage(t,e):self.postMessage(t)},Ot=(t,e,n,o)=>{Ce(self),u.canvas=t,u.dpr=o,t.width=Math.max(1,Math.round(e*o)),t.height=Math.max(1,Math.round(n*o));let r=t.getContext("2d");if(!r)throw new Error("OffscreenCanvas 2D context unavailable");r.setTransform(o,0,0,o,0,0),u.target=new X(r,e,n,o),C({type:"ready"})},St=(t,e)=>{if(!u.canvas||!u.target)return;u.canvas.width=Math.max(1,Math.round(t*u.dpr)),u.canvas.height=Math.max(1,Math.round(e*u.dpr));let n=u.canvas.getContext("2d");n&&(n.setTransform(u.dpr,0,0,u.dpr,0,0),u.target.resize(t,e,u.dpr))},Dt=t=>{if(!u.canvas||!u.target){C({type:"error",message:"Worker not initialised"});return}Ct();let e=u.canvas.getContext("2d");if(e===null){C({type:"error",message:"Worker not initialised"});return}e.save(),e.setTransform(u.dpr,0,0,u.dpr,0,0),e.clearRect(0,0,u.target.size.width,u.target.size.height),ne(t,u.target),e.restore();let n=u.canvas.transferToImageBitmap();C({type:"frame-done",bitmap:n},[n])},Mt=t=>{if(!u.target){C({type:"error",message:"Worker not initialised"});return}Me(u.target,t,u.images)};self.addEventListener("message",t=>{let e=t.data;try{switch(e.type){case"init":Ot(e.canvas,e.width,e.height,e.dpr);break;case"resize":St(e.width,e.height);break;case"snapshot":Dt(e.scene);break;case"replay":Mt(e.commands);break;case"frame":C({type:"error",message:"patch-stream frames not implemented"});break}}catch(n){C({type:"error",message:n instanceof Error?n.message:String(n)})}});
1
+ var ct=Object.defineProperty;var K=(t,e)=>{for(var n in e)ct(t,n,{get:e[n],enumerable:!0})};var Re=new Map,A=(t,e)=>{Re.set(t,e)},Te=t=>Re.get(t);var Q=(t,e,n)=>{if(!t||t.type==="sharp")return 0;let o=Math.min(Math.abs(e),Math.abs(n));if(o<=0)return 0;if(t.value!==void 0)return Math.max(0,Math.min(t.value,o/2));let r=32/.25;return o<=r?o*.25:32};var be=t=>{if(!t)return"";let e=Object.entries(t).filter(([,n])=>n!==void 0).sort(([n],[o])=>n<o?-1:n>o?1:0);return JSON.stringify(e)},we=t=>{let e=[];for(let n of t){if(n.text==="")continue;let o=e[e.length-1];o!==void 0&&be(o.style)===be(n.style)?e[e.length-1]={text:o.text+n.text,...o.style!==void 0?{style:o.style}:{}}:e.push(n)}return e},dt=t=>{let e=t.runs;return e!==void 0&&e.length>0?we(e):t.text===""?[]:[{text:t.text}]},ee=(t,e,n)=>{let o=Math.min(e,n),r=Math.max(e,n),s=[],i=0;for(let l of dt(t)){let c=i,u=i+l.text.length;i=u;let d=Math.max(c,o),a=Math.min(u,r);d>=a||s.push({text:l.text.slice(d-c,a-c),...l.style!==void 0?{style:l.style}:{}})}return s};var y=t=>{if(t===void 0)throw new Error("required value is undefined");return t};var m={};K(m,{ZERO:()=>Le,add:()=>ut,angle:()=>bt,cross:()=>gt,distance:()=>Et,distanceSq:()=>Oe,div:()=>xt,dot:()=>pt,equals:()=>It,length:()=>Ie,lengthSq:()=>Ae,lerp:()=>Rt,midpoint:()=>Tt,mul:()=>mt,negate:()=>yt,normalize:()=>_t,of:()=>ht,perp:()=>At,rotate:()=>wt,rotateAround:()=>Lt,sub:()=>ft});var Le=Object.freeze({x:0,y:0}),ht=(t,e)=>({x:t,y:e}),ut=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),ft=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),mt=(t,e)=>({x:t.x*e,y:t.y*e}),xt=(t,e)=>({x:t.x/e,y:t.y/e}),yt=t=>({x:-t.x,y:-t.y}),pt=(t,e)=>t.x*e.x+t.y*e.y,gt=(t,e)=>t.x*e.y-t.y*e.x,Ae=t=>t.x*t.x+t.y*t.y,Ie=t=>Math.sqrt(Ae(t)),Oe=(t,e)=>{let n=e.x-t.x,o=e.y-t.y;return n*n+o*o},Et=(t,e)=>Math.sqrt(Oe(t,e)),_t=t=>{let e=Ie(t);return e===0?Le:{x:t.x/e,y:t.y/e}},Rt=(t,e,n)=>({x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}),Tt=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),bt=t=>Math.atan2(t.y,t.x),wt=(t,e)=>{let n=Math.cos(e),o=Math.sin(e);return{x:t.x*n-t.y*o,y:t.x*o+t.y*n}},Lt=(t,e,n)=>{let o=Math.cos(n),r=Math.sin(n),s=t.x-e.x,i=t.y-e.y;return{x:e.x+(s*o-i*r),y:e.y+(s*r+i*o)}},At=t=>({x:-t.y,y:t.x}),It=(t,e,n=0)=>n===0?t.x===e.x&&t.y===e.y:Math.abs(t.x-e.x)<=n&&Math.abs(t.y-e.y)<=n;var I={};K(I,{IDENTITY:()=>Ot,applyToBounds:()=>vt,applyToPoint:()=>N,decompose:()=>Ft,equals:()=>Bt,inverse:()=>Dt,multiply:()=>Pt,of:()=>kt,rotation:()=>Mt,scaling:()=>Ct,translation:()=>St});var Ot=Object.freeze({a:1,b:0,c:0,d:1,e:0,f:0}),kt=(t,e,n,o,r,s)=>({a:t,b:e,c:n,d:o,e:r,f:s}),St=(t,e)=>({a:1,b:0,c:0,d:1,e:t,f:e}),Ct=(t,e=t)=>({a:t,b:0,c:0,d:e,e:0,f:0}),Mt=t=>{let e=Math.cos(t),n=Math.sin(t);return{a:e,b:n,c:-n,d:e,e:0,f:0}},Pt=(t,e)=>({a:t.a*e.a+t.c*e.b,b:t.b*e.a+t.d*e.b,c:t.a*e.c+t.c*e.d,d:t.b*e.c+t.d*e.d,e:t.a*e.e+t.c*e.f+t.e,f:t.b*e.e+t.d*e.f+t.f}),Dt=t=>{let e=t.a*t.d-t.b*t.c;if(e===0)throw new Error("Cannot invert singular matrix");return{a:t.d/e,b:-t.b/e,c:-t.c/e,d:t.a/e,e:(t.c*t.f-t.d*t.e)/e,f:(t.b*t.e-t.a*t.f)/e}},N=(t,e)=>({x:t.a*e.x+t.c*e.y+t.e,y:t.b*e.x+t.d*e.y+t.f}),vt=(t,e)=>{let n=N(t,{x:e.x,y:e.y}),o=N(t,{x:e.x+e.width,y:e.y}),r=N(t,{x:e.x,y:e.y+e.height}),s=N(t,{x:e.x+e.width,y:e.y+e.height}),i=Math.min(n.x,o.x,r.x,s.x),l=Math.min(n.y,o.y,r.y,s.y),c=Math.max(n.x,o.x,r.x,s.x),u=Math.max(n.y,o.y,r.y,s.y);return{x:i,y:l,width:c-i,height:u-l}},Ft=t=>{let e=Math.sqrt(t.a*t.a+t.b*t.b),n=Math.sqrt(t.c*t.c+t.d*t.d),r=t.a*t.d-t.b*t.c<0?-n:n;return{translation:{x:t.e,y:t.f},rotation:Math.atan2(t.b,t.a),scale:{x:e,y:r}}},Bt=(t,e,n=0)=>{let o=["a","b","c","d","e","f"];return n===0?o.every(r=>t[r]===e[r]):o.every(r=>Math.abs(t[r]-e[r])<=n)};var w={};K(w,{EMPTY:()=>ke,centerOf:()=>Gt,contains:()=>Xt,containsBounds:()=>Kt,equals:()=>Yt,expand:()=>qt,fromCenter:()=>Ht,fromPoints:()=>Wt,intersection:()=>Se,intersects:()=>Ut,isEmpty:()=>te,maxX:()=>k,maxY:()=>S,normalize:()=>Vt,of:()=>Nt,union:()=>zt});var ke=Object.freeze({x:0,y:0,width:0,height:0}),Nt=(t,e,n,o)=>({x:t,y:e,width:n,height:o}),Wt=t=>{if(t.length===0)return ke;let e=1/0,n=1/0,o=-1/0,r=-1/0;for(let s of t)s.x<e&&(e=s.x),s.y<n&&(n=s.y),s.x>o&&(o=s.x),s.y>r&&(r=s.y);return{x:e,y:n,width:o-e,height:r-n}},Ht=(t,e,n)=>({x:t.x-e/2,y:t.y-n/2,width:e,height:n}),Gt=t=>({x:t.x+t.width/2,y:t.y+t.height/2}),k=t=>t.x+t.width,S=t=>t.y+t.height,te=t=>t.width<=0||t.height<=0,zt=(t,e)=>{if(te(t))return e;if(te(e))return t;let n=Math.min(t.x,e.x),o=Math.min(t.y,e.y),r=Math.max(k(t),k(e)),s=Math.max(S(t),S(e));return{x:n,y:o,width:r-n,height:s-o}},Se=(t,e)=>{let n=Math.max(t.x,e.x),o=Math.max(t.y,e.y),r=Math.min(k(t),k(e)),s=Math.min(S(t),S(e));return r<=n||s<=o?null:{x:n,y:o,width:r-n,height:s-o}},Ut=(t,e)=>Se(t,e)!==null,Xt=(t,e)=>e.x>=t.x&&e.x<=k(t)&&e.y>=t.y&&e.y<=S(t),Kt=(t,e)=>e.x>=t.x&&e.y>=t.y&&k(e)<=k(t)&&S(e)<=S(t),qt=(t,e)=>({x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}),Vt=t=>({x:t.width<0?t.x+t.width:t.x,y:t.height<0?t.y+t.height:t.y,width:Math.abs(t.width),height:Math.abs(t.height)}),Yt=(t,e,n=0)=>n===0?t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height:Math.abs(t.x-e.x)<=n&&Math.abs(t.y-e.y)<=n&&Math.abs(t.width-e.width)<=n&&Math.abs(t.height-e.height)<=n;var W={};K(W,{offsetClosedPath:()=>jt,signedArea:()=>Jt});var jt=(t,e)=>{if(t.length<3||e===0)return t.map(c=>({x:c.x,y:c.y}));let n=0,o=0;for(let c of t)n+=c.x,o+=c.y;n/=t.length,o/=t.length;let r=t.length,s=new Array(r),i=new Array(r);for(let c=0;c<r;c++){let u=y(t[c]),d=y(t[(c+1)%r]),a=d.x-u.x,h=d.y-u.y,f=Math.hypot(a,h)||1;s[c]=-h/f,i[c]=a/f}let l=[];for(let c=0;c<r;c++){let u=(c-1+r)%r,d=y(s[u]),a=y(i[u]),h=y(s[c]),f=y(i[c]),p=d+h,g=a+f,_=Math.hypot(p,g);_<1e-6?(p=d,g=a):(p/=_,g/=_);let b=y(t[c]),D=n-b.x,Z=o-b.y,v=p*D+g*Z>=0?1:-1,R=p*d+g*a,x=R>1e-6?e/R:e;l.push({x:b.x+v*p*x,y:b.y+v*g*x})}return l},Jt=t=>{let e=0;for(let n=0;n<t.length;n++){let o=y(t[n]),r=y(t[(n+1)%t.length]);e+=o.x*r.y-r.x*o.y}return e/2};var Zt=null;var Ce=()=>Zt;var ne=t=>t.type==="text";var oe=t=>t.stroke??t.fill??"#000",Me=new Map,L=(t,e)=>{Me.set(t,e)};var Pe=t=>{let e=Me.get(t.type);if(!e)throw new Error(`No bounder registered for shape type: ${t.type}`);return e(t)},re=t=>{let e=Pe(t),n=[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x,y:e.y+e.height},{x:e.x+e.width,y:e.y+e.height}],o=Math.sin(t.rotation),r=Math.cos(t.rotation),s=n.map(i=>{let l=i.x*t.scale.x,c=i.y*t.scale.y;return{x:t.position.x+(l*r-c*o),y:t.position.y+(l*o+c*r)}});return w.fromPoints(s)};L("rectangle",t=>({x:0,y:0,width:t.width,height:t.height}));L("ellipse",t=>({x:0,y:0,width:t.width,height:t.height}));L("polygon",t=>w.fromPoints(t.points));L("path",t=>{let e=[],n={x:0,y:0};for(let o of t.commands)switch(o.kind){case"M":case"L":e.push(o.to),n=o.to;break;case"Q":e.push(o.control,o.to),n=o.to;break;case"C":e.push(o.control1,o.control2,o.to),n=o.to;break;case"Z":break}return w.fromPoints(e)});L("text",t=>{let e=t.fontSize*1.2,n=t.text.split(`
2
+ `),o=Ce(),r={bold:t.style.fontWeight==="bold",italic:t.style.fontStyle==="italic"},s=l=>{if(o){let c=o(l,t.fontFamily,t.fontSize,r);if(c!==null)return c}return l.length*t.fontSize*.6};if(t.maxWidth===void 0){let l=0;for(let c of n)l=Math.max(l,s(c));return l=Math.max(l,t.fontSize*.5),{x:0,y:0,width:l,height:Math.max(1,n.length)*e}}let i=0;for(let l of n)i+=Math.max(1,Math.ceil(s(l)/t.maxWidth));return{x:0,y:0,width:t.maxWidth,height:Math.max(1,i)*e}});L("image",t=>({x:0,y:0,width:t.width,height:t.height}));L("template",t=>({x:0,y:0,width:t.width,height:t.height}));L("brush",t=>{if(t.points.length===0)return{x:0,y:0,width:0,height:0};let e=1/0,n=1/0,o=-1/0,r=-1/0;for(let s of t.points)s.x-s.width<e&&(e=s.x-s.width),s.y-s.width<n&&(n=s.y-s.width),s.x+s.width>o&&(o=s.x+s.width),s.y+s.width>r&&(r=s.y+s.width);return{x:e,y:n,width:o-e,height:r-n}});L("group",()=>({x:0,y:0,width:0,height:0}));L("frame",t=>({x:0,y:0,width:t.width,height:t.height}));L("block-arrow",t=>({x:0,y:0,width:t.width,height:t.height}));var ie=(t,e)=>t.order<e.order?-1:t.order>e.order?1:0;var se=t=>[...t.layers.values()].sort(ie),q=(t,e)=>[...t.elements.values()].filter(n=>n.layerId===e).sort(ie);var ce=t=>{let e=t.length;if(e<2)return[];let n=a=>{let h=y(t[a]);return{x:h.x,y:h.y}},o=a=>y(t[a]).width,r=[],s=[];for(let a=0;a<e-1;a++){let h=m.sub(n(a+1),n(a)),f=m.lengthSq(h)>0?m.normalize(h):{x:1,y:0};r.push(f),s.push(m.perp(f))}let i=[],l=[];for(let a=0;a<e;a++){let h=o(a),f=n(a);if(a===0){let b=y(s[0]);i.push(m.add(f,m.mul(b,h))),l.push(m.sub(f,m.mul(b,h)));continue}if(a===e-1){let b=y(s[e-2]);i.push(m.add(f,m.mul(b,h))),l.push(m.sub(f,m.mul(b,h)));continue}let p=y(s[a-1]),g=y(s[a]),_=m.cross(y(r[a-1]),y(r[a]));if(Math.abs(_)<1e-9){i.push(m.add(f,m.mul(p,h))),l.push(m.sub(f,m.mul(p,h)));continue}_>0?(i.push(...De(f,p,g,h,1)),l.push(...ve(f,p,g,h,-1))):(i.push(...ve(f,p,g,h,1)),l.push(...De(f,p,g,h,-1)))}let c=Fe(n(e-1),y(s[e-2]),o(e-1),!1),u=Fe(n(0),y(s[0]),o(0),!0),d=[];for(let a of i)d.push(a);for(let a of c)d.push(a);for(let a=l.length-1;a>=0;a--)d.push(y(l[a]));for(let a of u)d.push(a);return d},De=(t,e,n,o,r)=>{let s=m.normalize(m.add(e,n)),i=m.dot(s,e);return i>.001&&1/i<=2.5?[m.add(t,m.mul(s,r*(o/i)))]:[m.add(t,m.mul(e,r*o)),m.add(t,m.mul(n,r*o))]},ve=(t,e,n,o,r)=>Be(t,o,m.angle(m.mul(e,r)),m.angle(m.mul(n,r))),Fe=(t,e,n,o)=>{let r=m.angle(e)+(o?Math.PI:0);return Be(t,n,r,r-Math.PI)},Be=(t,e,n,o)=>{let r=o-n;for(;r>Math.PI+1e-9;)r-=2*Math.PI;for(;r<-Math.PI-1e-9;)r+=2*Math.PI;let s=Math.max(1,Math.ceil(Math.abs(r)/.35)),i=[];for(let l=0;l<=s;l++){let c=n+r*l/s;i.push({x:t.x+e*Math.cos(c),y:t.y+e*Math.sin(c)})}return i};var $t=new Map,le=(t,e)=>{$t.set(t,e)};var Qt=Object.freeze({pan:{x:0,y:0},zoom:1,rotation:0,size:{width:0,height:0},gridEnabled:!1}),ae=t=>{let e=I.translation(-t.pan.x,-t.pan.y),n=I.rotation(t.rotation),o=I.scaling(t.zoom);return I.multiply(o,I.multiply(n,e))};var Ne=(t,e)=>{let n=new Map,o=s=>{t.setOpacity(s*e)},r={get(s,i){if(i==="setOpacity")return o;if(n.has(i))return n.get(i);let l=Reflect.get(s,i),c=typeof l=="function"?l.bind(s):l;return n.set(i,c),c}};return new Proxy(t,r)};var H=class{entries=new Map;get(e){let n=this.entries.get(e.id);if(n){if(n.ref!==e){this.entries.delete(e.id);return}return n.value}}set(e,n){return this.entries.set(e.id,{ref:e,value:n}),n}getOrCompute(e,n){let o=this.get(e);return o!==void 0?o:this.set(e,n(e))}invalidate(e){this.entries.delete(e)}clear(){this.entries.clear()}prune(e){for(let n of this.entries.keys())e.elements.has(n)||this.entries.delete(n)}get size(){return this.entries.size}},Fr=new H,G=(t,e)=>t.getOrCompute(e,re);var We="#bbb";var de=.06,he=.92,ue=.5;var He=.4,Ge=.5,fe=.1,me=.9,ze="#888",Ue="#ffffff",Xe="#222",Ke="#ddd";var C=class{cap;onEvict;map=new Map;constructor(e,n){this.cap=e,this.onEvict=n}get(e){let n=this.map.get(e);if(n!==void 0)return this.map.delete(e),this.map.set(e,n),n}has(e){return this.map.has(e)}set(e,n){for(this.map.delete(e),this.map.set(e,n);this.map.size>this.cap;){let o=this.map.keys().next().value,r=this.map.get(o);this.map.delete(o),r!==void 0&&this.onEvict?.(o,r)}}delete(e){return this.map.delete(e)}clear(){this.map.clear()}get size(){return this.map.size}keys(){return this.map.keys()}values(){return this.map.values()}};var qe=t=>t<=0?1:2**Math.round(Math.log2(t));var xe=(t,e,n={})=>{let o=ae(t.viewport),r=n.dirtyWorld;if(!n.skipClear)if(r){let R=[I.applyToPoint(o,{x:r.x,y:r.y}),I.applyToPoint(o,{x:r.x+r.width,y:r.y+r.height})],x=w.expand(w.fromPoints(R),2);e.clear(x)}else e.clear();e.save(),e.setTransform(o);let s=n.boundsCache??new H,i=n.viewport,l=null;i&&n.spatialIndex&&(l=n.spatialIndex.query(i));let c=t.viewport.zoom,u=n.clock,d=u?{zoom:c,clock:u}:{zoom:c},a=n.lod,h=a?.placeholder!==void 0&&c<a.placeholder,f=a?.hideText!==void 0&&c<a.hideText,p=n.placeholderFill??We,g=n.layerCompositeCache,_=n.dirtyLayerIds,b=n.compositeLayerBitmap,D=qe(c),Z=R=>{let x=null;for(let T of q(t,R)){let F=G(s,T);x=x?w.union(x,F):F}return x},$=n.dimOpacity,v=n.dimElements!==void 0&&$!==void 0?Ne(e,$):null;for(let R of se(t))if(R.visible){if(g&&b){_?.has(R.id)&&g.invalidateLayer(R.id);let x=g.get(R.id,D);if(x===void 0){let T=b(R.id,D,t);T!==null&&(g.set(R.id,D,T),x=T)}if(x!==void 0){let T=Z(R.id);T&&e.drawImage(x,T.x,T.y,T.width,T.height);continue}}for(let x of q(t,R.id)){if(n.hideElements?.has(x.id)||l&&!l.has(x.id))continue;if(i){let O=G(s,x);if(!w.intersects(O,i))continue}if(r){let O=G(s,x);if(!w.intersects(O,r))continue}if(f&&ne(x))continue;if(h){let O=G(s,x);e.setFill(p),e.setStrokeWidth(0),e.beginPath(),e.rect(O.x,O.y,O.width,O.height),e.fill();continue}let T=Te(x.type);if(!T){n.onUnknownElement?.(x);continue}e.save();let F=v!==null&&n.dimElements?.has(x.id)===!0,B=F?v:e;F&&B.setOpacity(1),B.translate(x.position.x,x.position.y),x.rotation!==0&&B.rotate(x.rotation),(x.scale.x!==1||x.scale.y!==1)&&B.scale(x.scale.x,x.scale.y),T(x,B,d),e.restore()}}e.restore()};var en=1.2,tn=(t,e,n,o,r)=>{if(t===""){r.push({text:"",start:e,end:e,width:0});return}let s=[],i=/\S+/g,l;for(;(l=i.exec(t))!==null;)s.push({s:l.index,e:l.index+l[0].length});if(s.length===0){r.push({text:t,start:e,end:e+t.length,width:o(t)});return}let c=0,u=(a,h)=>{let f=t.slice(a,h);r.push({text:f,start:e+a,end:e+h,width:o(f)})},d=0;for(;d<s.length;){let a=y(s[d]);if(o(t.slice(c,a.e))<=n){d++;continue}if(a.s>c){u(c,a.s),c=a.s;continue}let h=a.s+1;for(;h<a.e&&o(t.slice(c,h+1))<=n;)h++;if(h>=a.e){d++;continue}u(c,h),c=h,a.s=h}u(c,t.length)},ye=(t,e,n)=>{let o=n.fontSize*(n.lineHeightFactor??en),r=[],s=0;for(let c=0;c<=t.length;c++)if(c===t.length||t[c]===`
3
+ `){let u=t.slice(s,c);n.maxWidth===void 0?r.push({text:u,start:s,end:c,width:e(u)}):tn(u,s,n.maxWidth,e,r),s=c+1}r.length===0&&r.push({text:"",start:0,end:0,width:0});let i=0;for(let c of r)i=Math.max(i,c.width);let l=n.maxWidth??i;return{lines:r,lineHeight:o,blockWidth:l}};var nn=new Map;var on=()=>typeof performance<"u"?performance.now():0;var pe=(t,e=on(t))=>{if(!t.animationKind)return t.src;let n=nn.get(t.animationKind);if(!n)return t.src;try{return n.getFrameAt(t.animationData,e)}catch{return t.src}};var z=(t,e)=>{let n=t.fill!==void 0&&t.fill!=="transparent",o=t.stroke!==void 0&&t.stroke!=="transparent"&&(t.strokeWidth??1)>0;return n&&e.setFill(t.fill),o&&(e.setStroke(t.stroke),e.setStrokeWidth(t.strokeWidth??1),t.lineCap&&e.setLineCap(t.lineCap),t.lineJoin&&e.setLineJoin(t.lineJoin),t.dashArray&&e.setDashArray(t.dashArray)),t.opacity!==void 0&&e.setOpacity(t.opacity),{fill:n,stroke:o}},sn=(t,e)=>{let{fill:n,stroke:o}=z(t.style,e);if(!n&&!o)return;let r=Q(t.style.roundness,t.width,t.height);if(n&&(e.beginPath(),r>0?Ve(e,0,0,t.width,t.height,r):e.rect(0,0,t.width,t.height),e.fill()),o){let s=j(t.style),i=s,l=s,c=t.width-2*s,u=t.height-2*s;if(c<=0||u<=0)return;let d=r>0?Math.max(0,r-s):0;e.beginPath(),d>0?Ve(e,i,l,c,u,d):e.rect(i,l,c,u),e.stroke()}},j=t=>{let e=t.strokeAlign??"center";if(e==="center")return 0;let n=(t.strokeWidth??1)/2;return e==="inside"?n:-n},Ve=(t,e,n,o,r,s)=>{t.moveTo(e+s,n),t.lineTo(e+o-s,n),t.quadraticCurveTo(e+o,n,e+o,n+s),t.lineTo(e+o,n+r-s),t.quadraticCurveTo(e+o,n+r,e+o-s,n+r),t.lineTo(e+s,n+r),t.quadraticCurveTo(e,n+r,e,n+r-s),t.lineTo(e,n+s),t.quadraticCurveTo(e,n,e+s,n),t.closePath()},cn=(t,e)=>{let{fill:n,stroke:o}=z(t.style,e);if(!n&&!o)return;let r=t.width/2,s=t.height/2;if(n&&(e.beginPath(),e.ellipse(r,s,r,s),e.fill()),o){let i=j(t.style),l=r-i,c=s-i;if(l<=0||c<=0)return;e.beginPath(),e.ellipse(r,s,l,c),e.stroke()}},ln=(t,e)=>{if(t.points.length<2)return;let{fill:n,stroke:o}=z(t.style,e);if(!(!n&&!o)&&(n&&(e.beginPath(),Y(e,t.points),e.fill()),o)){let r=j(t.style),s=r!==0?W.offsetClosedPath(t.points,r):t.points;e.beginPath(),Y(e,s),e.stroke()}},Y=(t,e)=>{let n=e[0];if(n!==void 0){t.moveTo(n.x,n.y);for(let o=1;o<e.length;o++){let r=e[o];r!==void 0&&t.lineTo(r.x,r.y)}t.closePath()}},an=(t,e)=>{if(t.commands.length===0)return;let{fill:n,stroke:o}=z(t.style,e);if(!(!n&&!o)){e.beginPath();for(let r of t.commands)switch(r.kind){case"M":e.moveTo(r.to.x,r.to.y);break;case"L":e.lineTo(r.to.x,r.to.y);break;case"Q":e.quadraticCurveTo(r.control.x,r.control.y,r.to.x,r.to.y);break;case"C":e.bezierCurveTo(r.control1.x,r.control1.y,r.control2.x,r.control2.y,r.to.x,r.to.y);break;case"Z":e.closePath();break}n&&e.fill(),o&&e.stroke()}},dn=(t,e)=>{let n=t.style.textAlign??"left",o=t.fontSize;e.setTextAlign("left"),e.setTextBaseline(t.style.textBaseline??"top");let r=u=>{let d=u?.fontWeight??t.style.fontWeight,a=u?.fontStyle??t.style.fontStyle;e.setFont(t.fontFamily,o,{...d?{weight:d}:{},...a?{style:a}:{}})};r(void 0);let s=ye(t.text,u=>e.measureText(u).width,{fontSize:o,...t.maxWidth!==void 0?{maxWidth:t.maxWidth}:{}}),i=s.lines.map(u=>{let d=ee(t,u.start,u.end).map(h=>(r(h.style),{text:h.text,style:h.style,width:e.measureText(h.text).width})),a=d.reduce((h,f)=>h+f.width,0);return{segs:d,total:a}}),l=t.maxWidth??i.reduce((u,d)=>Math.max(u,d.total),0),c=Math.max(1,o*de);i.forEach((u,d)=>{let a=d*s.lineHeight,h=n==="center"?l/2-u.total/2:n==="right"?l-u.total:0;for(let f of u.segs){let p=f.style?.fill??t.style.fill??"#000",g=f.style?.opacity??t.style.opacity;r(f.style),e.setFill(p),g!==void 0&&e.setOpacity(g),e.fillText(f.text,h,a);let _=f.style?.textDecoration??t.style.textDecoration;f.width>0&&(_?.underline||_?.strikethrough)&&(_.underline&&(e.beginPath(),e.rect(h,a+o*he,f.width,c),e.fill()),_.strikethrough&&(e.beginPath(),e.rect(h,a+o*ue-c/2,f.width,c),e.fill())),h+=f.width}})},hn=(t,e)=>{if(t.runs!==void 0&&t.runs.length>0){dn(t,e);return}let n=t.style.textAlign??"left",o=t.style.fontWeight,r=t.style.fontStyle;e.setFont(t.fontFamily,t.fontSize,{...o?{weight:o}:{},...r?{style:r}:{}}),e.setTextAlign("left"),e.setTextBaseline(t.style.textBaseline??"top");let s=t.style.fill??"#000";e.setFill(s),t.style.opacity!==void 0&&e.setOpacity(t.style.opacity);let i=t.fontSize,l;if(t.maxWidth===void 0&&!t.text.includes(`
4
+ `))l=[{text:t.text,x:0,width:e.measureText(t.text).width,top:0}];else{let u=a=>e.measureText(a).width,d=ye(t.text,u,{fontSize:i,...t.maxWidth!==void 0?{maxWidth:t.maxWidth}:{}});l=d.lines.map((a,h)=>({text:a.text,x:n==="center"?d.blockWidth/2-a.width/2:n==="right"?d.blockWidth-a.width:0,width:a.width,top:h*d.lineHeight}))}for(let u of l)e.fillText(u.text,u.x,u.top);let c=t.style.textDecoration;if(c?.underline||c?.strikethrough){let u=Math.max(1,i*de);for(let d of l)d.width<=0||(c.underline&&(e.beginPath(),e.rect(d.x,d.top+i*he,d.width,u),e.fill()),c.strikethrough&&(e.beginPath(),e.rect(d.x,d.top+i*ue-u/2,d.width,u),e.fill()))}},un=(t,e)=>{let n=t.points;if(n.length===0)return;if(t.style.opacity!==void 0&&e.setOpacity(t.style.opacity),t.closed===!0&&t.style.fill!==void 0&&n.length>=3){e.setFill(t.style.fill),e.setStroke(null),e.beginPath();let s=y(n[0]);e.moveTo(s.x,s.y);for(let i=1;i<n.length;i++){let l=y(n[i]);e.lineTo(l.x,l.y)}e.closePath(),e.fill()}let o=oe(t.style);if(e.setFill(o),e.setStroke(null),n.length===1){let s=y(n[0]);e.beginPath(),e.ellipse(s.x,s.y,s.width,s.width),e.fill();return}let r=ce(n);if(r.length>=3){e.beginPath();let s=y(r[0]);e.moveTo(s.x,s.y);for(let i=1;i<r.length;i++){let l=y(r[i]);e.lineTo(l.x,l.y)}e.closePath(),e.fill()}},fn=(t,e,n)=>{let o=n?.clock?.(t),r=t.animationKind?pe(t,o):t.metadata?.image??pe(t,o),s=t.metadata?.animated===!0||t.animationKind!==void 0;e.drawImage(r,0,0,t.width,t.height,s,t.crop)},_e=()=>{A("rectangle",sn),A("ellipse",cn),A("polygon",ln),A("path",an),A("text",hn),A("image",fn),A("group",()=>{}),A("frame",pn),le("frame",()=>({top:24})),A("block-arrow",mn),A("brush",un)},mn=(t,e)=>{let{fill:n,stroke:o}=z(t.style,e),r=t.direction??"right",s=Math.max(fe,Math.min(me,t.headRatio??He)),i=Math.max(fe,Math.min(me,t.bodyThickness??Ge)),l=t.width,c=t.height,u=l*s,d=l-u,a=c*i/2,h=c/2,f=[[0,h-a],[d,h-a],[d,0],[l,h],[d,c],[d,h+a],[0,h+a]];r!=="right"&&(f=f.map(([g,_])=>xn([g,_],r,l,c)));let p=f.map(([g,_])=>({x:g,y:_}));if(n&&(e.beginPath(),Y(e,p),e.fill()),o){let g=j(t.style),_=g!==0?W.offsetClosedPath(p,g):p;e.beginPath(),Y(e,_),e.stroke()}},xn=([t,e],n,o,r)=>{switch(n){case"left":return[o-t,e];case"up":return[e*(o/r),r-t*(r/o)];case"down":return[(r-e)*(o/r),t*(r/o)]}},Ee="\u2026",yn=(t,e,n)=>{if(e<=0)return"";if(n.measureText(t).width<=e)return t;let o=0,r=t.length;for(;o<r;){let s=Math.ceil((o+r)/2);n.measureText(t.slice(0,s)+Ee).width<=e?o=s:r=s-1}return o>0?t.slice(0,o)+Ee:Ee},pn=(t,e,n)=>{e.setFill(t.style.fill??Ue),e.setStroke(null),e.setDashArray(null),e.beginPath(),e.rect(0,0,t.width,t.height),e.fill();let o=(n?.zoom??1)*(t.scale.x||1);e.setFill(null),e.setStroke(ze),e.setStrokeWidth(1/(o||1)),e.setDashArray(null),e.beginPath(),e.rect(0,0,t.width,t.height),e.stroke();let r=t.name??"Frame";e.setFont("system-ui, sans-serif",12);let s=t.width-16,i=e.measureText(r).width<=s,l=i?r:yn(r,s,e),c=i?Math.min(e.measureText(r).width+16,t.width):t.width;e.setFill(Xe),e.beginPath(),e.rect(0,-24,c,24),e.fill(),e.setFill(Ke),e.setTextBaseline("middle"),e.setTextAlign("left"),e.fillText(l,8,-24/2)};var P="Roboto",U="PT Serif",X="Roboto Mono",Ye=t=>{let e=t.toLowerCase();return e.includes("mono")?X:e.includes("sans")?P:e.includes("serif")||e.includes("slab")||e.includes("georgia")||e.includes("times")?U:P},gn=[{family:P,weight:"400",style:"normal",url:new URL("../fonts/Roboto-Regular.woff2",import.meta.url)},{family:P,weight:"700",style:"normal",url:new URL("../fonts/Roboto-Bold.woff2",import.meta.url)},{family:P,weight:"400",style:"italic",url:new URL("../fonts/Roboto-Italic.woff2",import.meta.url)},{family:P,weight:"700",style:"italic",url:new URL("../fonts/Roboto-BoldItalic.woff2",import.meta.url)},{family:U,weight:"400",style:"normal",url:new URL("../fonts/PTSerif-Regular.woff2",import.meta.url)},{family:U,weight:"700",style:"normal",url:new URL("../fonts/PTSerif-Bold.woff2",import.meta.url)},{family:U,weight:"400",style:"italic",url:new URL("../fonts/PTSerif-Italic.woff2",import.meta.url)},{family:U,weight:"700",style:"italic",url:new URL("../fonts/PTSerif-BoldItalic.woff2",import.meta.url)},{family:X,weight:"400",style:"normal",url:new URL("../fonts/RobotoMono-Regular.woff2",import.meta.url)},{family:X,weight:"700",style:"normal",url:new URL("../fonts/RobotoMono-Bold.woff2",import.meta.url)},{family:X,weight:"400",style:"italic",url:new URL("../fonts/RobotoMono-Italic.woff2",import.meta.url)},{family:X,weight:"700",style:"italic",url:new URL("../fonts/RobotoMono-BoldItalic.woff2",import.meta.url)}],je=async(t=globalThis)=>{let e=t.fonts;!e||typeof FontFace>"u"||await Promise.allSettled(gn.map(async n=>{let o=new FontFace(n.family,`url(${n.url.href})`,{weight:n.weight,style:n.style});await o.load(),e.add(o)}))};var En=["HTMLImageElement","HTMLCanvasElement","HTMLVideoElement","ImageBitmap","OffscreenCanvas","SVGImageElement","VideoFrame"],Ze=t=>{if(typeof t!="object"||t===null)return!1;let e=globalThis;for(let n of En){let o=e[n];if(typeof o=="function"&&t instanceof o)return!0}return!1},$e=t=>{let e=t;return typeof e.naturalWidth=="number"&&e.naturalWidth>0?{width:e.naturalWidth,height:e.naturalHeight??e.naturalWidth}:typeof e.videoWidth=="number"&&e.videoWidth>0?{width:e.videoWidth,height:e.videoHeight??e.videoWidth}:typeof e.width=="number"&&e.width>0&&typeof e.height=="number"?{width:e.width,height:e.height}:null},Je=new Set,Qe=t=>{if(typeof console>"u")return;let e=typeof t=="string"?t.startsWith("blob:")?"dead-blob-url":"string-src":t==null?"empty":"stale-object";Je.has(e)||(Je.add(e),console.warn(`[renderer] skipped a non-drawable image source (kind: ${e}). The shape's image handle isn't a live HTMLImageElement / canvas / bitmap \u2014 likely a scene restored from storage where the <img> was lost (metadata.image) and src is a dead blob: URL. The image won't render until rehydrated from Scene.files.`))};var J=class{ctx;_width;_height;dpr;constructor(e,n,o,r=1){this.ctx=e,this._width=n,this._height=o,this.dpr=r}get size(){return{width:this._width,height:this._height}}resize(e,n,o){this._width=e,this._height=n,o!==void 0&&(this.dpr=o)}setFill(e){this.ctx.fillStyle=e??"transparent"}setStroke(e){this.ctx.strokeStyle=e??"transparent"}setStrokeWidth(e){this.ctx.lineWidth=e}setOpacity(e){this.ctx.globalAlpha=e}setLineCap(e){this.ctx.lineCap=e}setLineJoin(e){this.ctx.lineJoin=e}setDashArray(e){this.ctx.setLineDash(e?[...e]:[])}setFont(e,n,o){let r=o?.style==="italic"?"italic ":"",s=o?.weight==="bold"?"bold ":"";this.ctx.font=`${r}${s}${n}px "${Ye(e)}", ${e}`}setTextAlign(e){this.ctx.textAlign=e==="center"?"center":e}setTextBaseline(e){this.ctx.textBaseline=e==="middle"?"middle":e==="top"?"top":"bottom"}save(){this.ctx.save()}restore(){this.ctx.restore()}translate(e,n){this.ctx.translate(e,n)}rotate(e){this.ctx.rotate(e)}scale(e,n){this.ctx.scale(e,n)}setTransform(e){let n=this.dpr;this.ctx.setTransform(n*e.a,n*e.b,n*e.c,n*e.d,n*e.e,n*e.f)}resetTransform(){this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0)}beginPath(){this.ctx.beginPath()}closePath(){this.ctx.closePath()}moveTo(e,n){this.ctx.moveTo(e,n)}lineTo(e,n){this.ctx.lineTo(e,n)}quadraticCurveTo(e,n,o,r){this.ctx.quadraticCurveTo(e,n,o,r)}bezierCurveTo(e,n,o,r,s,i){this.ctx.bezierCurveTo(e,n,o,r,s,i)}rect(e,n,o,r){this.ctx.rect(e,n,o,r)}ellipse(e,n,o,r){this.ctx.ellipse(e,n,o,r,0,0,Math.PI*2)}fill(e){this.ctx.fill(e)}stroke(){this.ctx.stroke()}fillText(e,n,o,r){r!==void 0?this.ctx.fillText(e,n,o,r):this.ctx.fillText(e,n,o)}measureText(e){return{width:this.ctx.measureText(e).width}}drawImage(e,n,o,r,s,i,l){if(!Ze(e)){Qe(e);return}if(l&&(l.x!==0||l.y!==0||l.width!==1||l.height!==1)){let c=$e(e);if(c){this.ctx.drawImage(e,l.x*c.width,l.y*c.height,l.width*c.width,l.height*c.height,n,o,r,s);return}}this.ctx.drawImage(e,n,o,r,s)}clear(e){this.dirtyRect=null,e?this.ctx.clearRect(e.x,e.y,e.width,e.height):(this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore())}dirtyRect=null;markDirty(e){if(!this.dirtyRect){this.dirtyRect=e;return}let n=Math.min(this.dirtyRect.x,e.x),o=Math.min(this.dirtyRect.y,e.y),r=Math.max(this.dirtyRect.x+this.dirtyRect.width,e.x+e.width),s=Math.max(this.dirtyRect.y+this.dirtyRect.height,e.y+e.height);this.dirtyRect={x:n,y:o,width:r-n,height:s-o}}getDirtyRect(){return this.dirtyRect}};var Rn=0,Tn=1,bn=2,wn=3,Ln=4,An=5,In=6,On=7,kn=8,Sn=9,Cn=10,Mn=11,Pn=12,Dn=13,vn=14,Fn=15,Bn=16,Nn=17,Wn=18,Hn=19,Gn=20,zn=21,Un=22,Xn=23,Kn=24,qn=25,Vn=26,Yn=27,jn=28,Jn=29,Zn=30,$n=31,et=-1,Qn=-1,eo=["butt","round","square"];var to=["miter","round","bevel"];var no=["left","center","right"];var oo=["top","middle","bottom"];var tt={nonzero:1,evenodd:2},nt={normal:1,bold:2},ot={normal:1,italic:2},ro=0,rt=1;var it=(t,e,n,o=new C(64))=>{let r=new Float64Array(e),s=0,i=()=>{let u=r[s++];if(u===void 0)throw new Error("replayPackedFrame: truncated stream");return u},l=u=>{let d=n[u];if(d===void 0)throw new Error(`replayPackedFrame: bad string index ${String(u)}`);return d},c=(u,d)=>{let a=u[d];if(a===void 0)throw new Error(`replayPackedFrame: bad enum code ${String(d)}`);return a};for(;s<r.length;){let u=i();switch(u){case Rn:{let d=i();t.setFill(d===et?null:l(d));break}case Tn:{let d=i();t.setStroke(d===et?null:l(d));break}case bn:t.setStrokeWidth(i());break;case wn:t.setOpacity(i());break;case Ln:t.setLineCap(c(eo,i()));break;case An:t.setLineJoin(c(to,i()));break;case In:{let d=i();if(d===Qn)t.setDashArray(null);else{let a=[];for(let h=0;h<d;h++)a.push(i());t.setDashArray(a)}break}case On:{let d=l(i()),a=i();if(i()===ro){t.setFont(d,a);break}let h=i(),f=i(),p={};h===nt.normal?p.weight="normal":h===nt.bold&&(p.weight="bold"),f===ot.normal?p.style="normal":f===ot.italic&&(p.style="italic"),t.setFont(d,a,p);break}case kn:t.setTextAlign(c(no,i()));break;case Sn:t.setTextBaseline(c(oo,i()));break;case Cn:t.save();break;case Mn:t.restore();break;case Pn:t.translate(i(),i());break;case Dn:t.rotate(i());break;case vn:t.scale(i(),i());break;case Fn:t.setTransform({a:i(),b:i(),c:i(),d:i(),e:i(),f:i()});break;case Bn:t.resetTransform();break;case Nn:t.beginPath();break;case Wn:t.closePath();break;case Hn:t.moveTo(i(),i());break;case Gn:t.lineTo(i(),i());break;case zn:t.quadraticCurveTo(i(),i(),i(),i());break;case Un:t.bezierCurveTo(i(),i(),i(),i(),i(),i());break;case Xn:t.rect(i(),i(),i(),i());break;case Kn:t.ellipse(i(),i(),i(),i());break;case qn:{let d=i();d===tt.nonzero?t.fill("nonzero"):d===tt.evenodd?t.fill("evenodd"):t.fill();break}case Vn:t.stroke();break;case Yn:{let d=l(i()),a=i(),h=i();i()===rt?t.fillText(d,a,h,i()):t.fillText(d,a,h);break}case jn:if(i()===rt){let d={x:i(),y:i(),width:i(),height:i()};t.clear(d)}else t.clear();break;case Jn:t.markDirty?.({x:i(),y:i(),width:i(),height:i()});break;case Zn:i(),i();break;case $n:{let d=i(),a=i(),h=i(),f=i(),p=i(),g=o.get(d);g&&t.drawImage(g,a,h,f,p);break}default:throw new Error(`replayPackedFrame: unknown opcode ${String(u)}`)}}};var E={canvas:null,target:null,dpr:1,images:new C(64,(t,e)=>{e.close()})},st=!1,io=()=>{st||(_e(),st=!0)},M=(t,e)=>{e&&e.length>0?self.postMessage(t,e):self.postMessage(t)},so=(t,e,n,o)=>{je(self),E.canvas=t,E.dpr=o,t.width=Math.max(1,Math.round(e*o)),t.height=Math.max(1,Math.round(n*o));let r=t.getContext("2d");if(!r)throw new Error("OffscreenCanvas 2D context unavailable");r.setTransform(o,0,0,o,0,0),E.target=new J(r,e,n,o),M({type:"ready"})},co=(t,e)=>{if(!E.canvas||!E.target)return;E.canvas.width=Math.max(1,Math.round(t*E.dpr)),E.canvas.height=Math.max(1,Math.round(e*E.dpr));let n=E.canvas.getContext("2d");n&&(n.setTransform(E.dpr,0,0,E.dpr,0,0),E.target.resize(t,e,E.dpr))},lo=t=>{if(!E.canvas||!E.target){M({type:"error",message:"Worker not initialised"});return}io();let e=E.canvas.getContext("2d");if(e===null){M({type:"error",message:"Worker not initialised"});return}e.save(),e.setTransform(E.dpr,0,0,E.dpr,0,0),e.clearRect(0,0,E.target.size.width,E.target.size.height),xe(t,E.target),e.restore();let n=E.canvas.transferToImageBitmap();M({type:"frame-done",bitmap:n},[n])},ao=t=>{if(!E.target){M({type:"error",message:"Worker not initialised"});return}for(let{id:e,bitmap:n}of t.bitmaps){let o=E.images.get(e);o&&o!==n&&o.close(),E.images.set(e,n)}it(E.target,t.buffer,t.strings,E.images)};self.addEventListener("message",t=>{let e=t.data;try{switch(e.type){case"init":so(e.canvas,e.width,e.height,e.dpr);break;case"resize":co(e.width,e.height);break;case"snapshot":lo(e.scene);break;case"replay":ao(e);break;case"frame":M({type:"error",message:"patch-stream frames not implemented"});break}}catch(n){M({type:"error",message:n instanceof Error?n.message:String(n)})}});
5
5
  //# sourceMappingURL=render-worker.js.map