@getv.design/embed 0.1.2 → 0.1.4

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/edit.js CHANGED
@@ -1,41 +1,41 @@
1
- /*! @getv.design/embed v0.1.2. Free to use under the vDesign Embed Licence. © 2026 Sagar Saini. https://getv.design/docs/licence/ */
2
- function St(e){return{expr:e}}function pe(e){return typeof e=="object"&&e!==null&&typeof e.expr=="string"}var Ut=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],_t=["left","center","right","justify"],Ct=["top","middle","bottom"],Et=["cover","contain","fill"],Vt=["nonzero","evenodd"],zt=["butt","round","square"],qt=["miter","round","bevel"],pf=["canvas","frame","group"];function so(e){return pf.includes(e)}function ce(e){return so(e.type)}function Se(e){return e.type==="group"}function de(e){return ce(e)?e.children:[]}var hf={canvas:["w","h"],ellipse:["x","y","w","h","rotation","strokeWidth","opacity"],frame:["x","y","w","h"],group:[],image:["x","y","w","h","rotation","radius","opacity"],rect:["x","y","w","h","rotation","strokeWidth","radius","opacity"],text:["x","y","w","h","rotation","size","weight","lineHeight","letterSpacing","opacity"],vector:["x","y","w","h","rotation","strokeWidth","opacity"]};function rt(e){return hf[e.type]}function oe(e,t,r){if(t(e,r)!==!1&&ce(e))for(let n of e.children)oe(n,t,e)}function V(e,t){let r;return oe(e,n=>{if(r)return!1;n.id===t&&(r=n)}),r}function nt(e,t){let r;return oe(e,(n,o)=>{n.id===t&&o&&(r=o)}),r}function io(e){return mf(e,"hidden")}function lo(e){return mf(e,"locked")}function mf(e,t){let r=new Set,n=(o,a)=>{let i=a||o[t]===!0;i&&r.add(o.id);for(let l of de(o))n(l,i)};return n(e,!1),r}function en(e,t,r){let n,o=(a,i)=>{let l=i??(a[r]===!0?a.id:void 0);return a.id===t?(n=l,!0):de(a).some(d=>o(d,l))};return o(e,void 0),n}var jt=["design"],At="design";var tn=[1,2,3,4],ot="doc";function pr(e){return{type:"canvas",...e}}function Wa(e){return{type:"ellipse",...e}}function Xa(e){return{type:"frame",...e}}function Ya(e){return{type:"group",...e}}function Ja(e){return{type:"image",...e}}function Za(e){return{type:"rect",...e}}function Qa(e){return{type:"text",...e}}function fo(e){return{type:"vector",...e}}function rn(e={}){return{version:4,kind:e.kind??At,...e.title===void 0?{}:{title:e.title},tokens:e.tokens??{},fonts:e.fonts??{},assets:e.assets??{},...e.motion===void 0||Object.keys(e.motion).length===0?{}:{motion:e.motion},root:e.root??pr({id:ot,children:[]})}}function uo(e){let t=new Set;return oe(e,r=>{t.add(r.id)}),t}function Kt(e,t){let r=uo(e),n=0;for(let o of r){if(!o.startsWith(`${t}.`))continue;let a=Number(o.slice(t.length+1));Number.isInteger(a)&&a>n&&(n=a)}return`${t}.${n+1}`}function Je(e){let t=e.trim();if(t.startsWith("#")){let n=t.slice(1);return n===""?void 0:{kind:"frame",id:n}}let r;try{r=new URL(t)}catch{return}if(!(r.protocol!=="https:"&&r.protocol!=="mailto:"))return{kind:"url",url:t}}var mr=["cut","fade","push","slide"],nn=["cut","fade","rise","drop","pop"];var Gt=1e4;function dt(e){let t=e.trim();return t==="back"?{kind:"back"}:t==="next"?{kind:"next"}:Je(t)}function ft(e){return e===void 0||e.enter===void 0&&e.duration===void 0&&e.lines.length===0}function xr(e){return e.enter!==void 0||e.exit!==void 0||e.go!==void 0}var wh=["id","enter","exit","duration","delay","step","together","go"];function co(e,t){return e===t?!0:e===void 0||t===void 0||e.enter!==t.enter||e.duration!==t.duration||e.lines.length!==t.lines.length?!1:e.lines.every((r,n)=>{let o=t.lines[n];return wh.every(a=>r[a]===o[a])})}function gr(e){let t=e.motion;if(!t)return[];let r=e.root.children.map(o=>o.id).filter(o=>o in t),n=Object.keys(t).filter(o=>!r.includes(o)).sort();return[...r,...n]}function po(e){return new Set(e.root.children.filter(t=>t.type==="frame").map(t=>t.id))}function hr(e){let t=new Map;for(let r of e.root.children)r.type==="frame"&&oe(r,n=>{t.set(n.id,r.id)});return t}function es(e){let t=new Set;return oe(e,r=>{t.add(r.id)}),t}function yr(e,t){let r=e.motion;if(!r)return[];let n=[],o=po(e),a=hr(e),i=es(e.root),l=(d,c)=>{let h=t?.(d,c);return h===void 0?"":`Line ${h}: `};for(let d of gr(e)){let c=r[d];if(c){if(!o.has(d)){n.push({severity:"warning",code:"motion-not-a-page",message:`${l(d)}motion ${d}: ${d} is not a page (a top-level frame), so none of it plays`,nodeId:d});continue}for(let h of c.lines){let x=l(d,h.id);i.has(h.id)?a.get(h.id)!==d&&n.push({severity:"warning",code:"motion-wrong-page",message:`${x}motion ${d}: ${h.id} is not on ${d}, so Play skips it`,nodeId:h.id}):n.push({severity:"warning",code:"unknown-reference",message:`${x}motion ${d}: no node ${h.id}`,nodeId:h.id});let y=h.go===void 0?void 0:dt(h.go);y?.kind==="frame"&&!kh(e,y.id)&&n.push({severity:"warning",code:"unknown-reference",message:`${x}motion ${d}: go=#${y.id} names no frame`,nodeId:h.id})}}}return n}function kh(e,t){let r=!1;return oe(e.root,n=>{if(r)return!1;n.id===t&&(r=n.type==="frame")}),r}function xf(e,t){let r=t.motion;if(!r||!e.motion)return r;let n=hr(e),o=hr(t),a=es(e.root),i=es(t.root),l=x=>a.has(x)&&!i.has(x),d=!1,c={},h=[];for(let[x,y]of Object.entries(r)){if(l(x)){d=!0;continue}let b=[];for(let k of y.lines){let _=k,B=k.go===void 0?void 0:dt(k.go);if(B?.kind==="frame"&&l(B.id)){let R=Sh(k);_=xr(R)?R:void 0,d=!0}if(_&&l(k.id))_=void 0,d=!0;else if(_&&n.get(k.id)===x&&o.get(k.id)!==x){let R=o.get(k.id);R!==void 0&&h.push([R,_]),_=void 0,d=!0}_&&b.push(_)}let P={...y,lines:b};ft(P)||(c[x]=P)}for(let[x,y]of h){let b=c[x]??{lines:[]};c[x]={...b,lines:[...b.lines,y]}}return d?Object.keys(c).length===0?void 0:c:r}function Sh(e){let t={...e};return delete t.go,t}function ts(e,t){let r={...e};return t===void 0||Object.keys(t).length===0?delete r.motion:r.motion=t,r}function rs(e,t){let r=xf(e,t);if(r===t.motion)return[];let n=new Set([...Object.keys(t.motion??{}),...Object.keys(r??{})]),o=[];for(let a of n){let i=r?.[a];co(t.motion?.[a],i)||o.push({op:"setMotion",page:a,value:i})}return o}var _h={canvas:["type","id","name","w","h","background","children"],frame:["type","id","name","x","y","w","h","background","clip","skip","blend","shadow","hidden","locked","children"],ellipse:["type","id","name","x","y","w","h","rotation","fill","stroke","strokeWidth","opacity","blend","shadow","hidden","locked"],group:["type","id","name","hidden","locked","children"],image:["type","id","name","x","y","w","h","rotation","src","fit","radius","opacity","blend","shadow","hidden","locked"],rect:["type","id","name","x","y","w","h","rotation","fill","stroke","strokeWidth","radius","opacity","blend","shadow","hidden","locked"],text:["type","id","name","x","y","w","h","rotation","content","font","size","weight","lineHeight","letterSpacing","align","valign","italic","fill","opacity","blend","shadow","hidden","locked"],vector:["type","id","name","x","y","w","h","rotation","view","d","fill","stroke","strokeWidth","opacity","rule","cap","join","blend","shadow","hidden","locked"]},Ch=["text","font","size","weight","italic","underline","strike","fill","letterSpacing","link"],Eh=["family","fallback","faces"],Ah=["src","weight","style"],_e=" ";function ns(e){let t=["{",`${_e}"version": ${ee(e.version)},`,`${_e}"kind": ${JSON.stringify(e.kind)},`,...e.title===void 0?[]:[`${_e}"title": ${JSON.stringify(e.title)},`],`${_e}"tokens": ${$h(e.tokens,_e)},`];return Object.keys(e.fonts).length>0&&t.push(`${_e}"fonts": ${Th(e.fonts,_e)},`),e.motion!==void 0&&t.push(`${_e}"motion": ${Mh(e,_e)},`),t.push(`${_e}"root": ${gf(e.root,_e)}`,"}"),`${t.join(`
1
+ /*! @getv.design/embed v0.1.4. Free to use under the vDesign Embed Licence. © 2026 Sagar Saini. https://getv.design/docs/licence/ */
2
+ function Et(e){return{expr:e}}function me(e){return typeof e=="object"&&e!==null&&typeof e.expr=="string"}var Kt=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],Mt=["left","center","right","justify"],At=["top","middle","bottom"],$t=["cover","contain","fill"],jt=["nonzero","evenodd"],Gt=["butt","round","square"],Wt=["miter","round","bevel"],xf=["canvas","frame","group"];function co(e){return xf.includes(e)}function pe(e){return co(e.type)}function _e(e){return e.type==="group"}function ae(e){return pe(e)?e.children:[]}var gf={canvas:["w","h"],ellipse:["x","y","w","h","rotation","strokeWidth","opacity"],frame:["x","y","w","h"],group:[],image:["x","y","w","h","rotation","radius","opacity"],rect:["x","y","w","h","rotation","strokeWidth","radius","opacity"],text:["x","y","w","h","rotation","size","weight","lineHeight","letterSpacing","opacity"],vector:["x","y","w","h","rotation","strokeWidth","opacity"]};function it(e){return gf[e.type]}function se(e,t,r){if(t(e,r)!==!1&&pe(e))for(let n of e.children)se(n,t,e)}function q(e,t){let r;return se(e,n=>{if(r)return!1;n.id===t&&(r=n)}),r}function rt(e,t){let r;return se(e,(n,o)=>{n.id===t&&o&&(r=o)}),r}function po(e){return yf(e,"hidden")}function ho(e){return yf(e,"locked")}function yf(e,t){let r=new Set,n=(o,a)=>{let i=a||o[t]===!0;i&&r.add(o.id);for(let l of ae(o))n(l,i)};return n(e,!1),r}function an(e,t,r){let n,o=(a,i)=>{let l=i??(a[r]===!0?a.id:void 0);return a.id===t?(n=l,!0):ae(a).some(d=>o(d,l))};return o(e,void 0),n}var Xt=["design"],Tt="design";var sn=[1,2,3,4],lt="doc";function yr(e){return{type:"canvas",...e}}function Qa(e){return{type:"ellipse",...e}}function mo(e){return{type:"frame",...e}}function es(e){return{type:"group",...e}}function ts(e){return{type:"image",...e}}function rs(e){return{type:"rect",...e}}function ns(e){return{type:"text",...e}}function xo(e){return{type:"vector",...e}}function ln(e={}){return{version:4,kind:e.kind??Tt,...e.title===void 0?{}:{title:e.title},tokens:e.tokens??{},fonts:e.fonts??{},assets:e.assets??{},...e.motion===void 0||Object.keys(e.motion).length===0?{}:{motion:e.motion},root:e.root??yr({id:lt,children:[]})}}function go(e){let t=new Set;return se(e,r=>{t.add(r.id)}),t}function Lt(e,t){let r=go(e),n=0;for(let o of r){if(!o.startsWith(`${t}.`))continue;let a=Number(o.slice(t.length+1));Number.isInteger(a)&&a>n&&(n=a)}return`${t}.${n+1}`}function nt(e){let t=e.trim();if(t.startsWith("#")){let n=t.slice(1);return n===""?void 0:{kind:"frame",id:n}}let r;try{r=new URL(t)}catch{return}if(!(r.protocol!=="https:"&&r.protocol!=="mailto:"))return{kind:"url",url:t}}var br=["cut","fade","push","slide"],dn=["cut","fade","rise","drop","pop"];var Yt=1e4;function pt(e){let t=e.trim();return t==="back"?{kind:"back"}:t==="next"?{kind:"next"}:nt(t)}function ht(e){return e===void 0||e.enter===void 0&&e.duration===void 0&&e.scroll!==!0&&e.lines.length===0}function wr(e){return e.enter!==void 0||e.exit!==void 0||e.go!==void 0}var Mh=["id","enter","exit","duration","delay","step","together","go"];function yo(e,t){return e===t?!0:e===void 0||t===void 0||e.enter!==t.enter||e.duration!==t.duration||e.scroll===!0!=(t.scroll===!0)||e.lines.length!==t.lines.length?!1:e.lines.every((r,n)=>{let o=t.lines[n];return Mh.every(a=>r[a]===o[a])})}function kr(e){let t=e.motion;if(!t)return[];let r=e.root.children.map(o=>o.id).filter(o=>o in t),n=Object.keys(t).filter(o=>!r.includes(o)).sort();return[...r,...n]}function vo(e){return new Set(e.root.children.filter(t=>t.type==="frame").map(t=>t.id))}function vr(e){let t=new Map;for(let r of e.root.children)r.type==="frame"&&se(r,n=>{t.set(n.id,r.id)});return t}function os(e){let t=new Set;return se(e,r=>{t.add(r.id)}),t}function Sr(e,t){let r=e.motion;if(!r)return[];let n=[],o=vo(e),a=vr(e),i=os(e.root),l=(d,c)=>{let h=t?.(d,c);return h===void 0?"":`Line ${h}: `};for(let d of kr(e)){let c=r[d];if(c){if(!o.has(d)){n.push({severity:"warning",code:"motion-not-a-page",message:`${l(d)}motion ${d}: ${d} is not a page (a top-level frame), so none of it plays`,nodeId:d});continue}for(let h of c.lines){let x=l(d,h.id);i.has(h.id)?a.get(h.id)!==d&&n.push({severity:"warning",code:"motion-wrong-page",message:`${x}motion ${d}: ${h.id} is not on ${d}, so Play skips it`,nodeId:h.id}):n.push({severity:"warning",code:"unknown-reference",message:`${x}motion ${d}: no node ${h.id}`,nodeId:h.id});let y=h.go===void 0?void 0:pt(h.go);y?.kind==="frame"&&!Ah(e,y.id)&&n.push({severity:"warning",code:"unknown-reference",message:`${x}motion ${d}: go=#${y.id} names no frame`,nodeId:h.id})}}}return n}function Ah(e,t){let r=!1;return se(e.root,n=>{if(r)return!1;n.id===t&&(r=n.type==="frame")}),r}function vf(e,t){let r=t.motion;if(!r||!e.motion)return r;let n=vr(e),o=vr(t),a=os(e.root),i=os(t.root),l=x=>a.has(x)&&!i.has(x),d=!1,c={},h=[];for(let[x,y]of Object.entries(r)){if(l(x)){d=!0;continue}let v=[];for(let k of y.lines){let S=k,B=k.go===void 0?void 0:pt(k.go);if(B?.kind==="frame"&&l(B.id)){let N=$h(k);S=wr(N)?N:void 0,d=!0}if(S&&l(k.id))S=void 0,d=!0;else if(S&&n.get(k.id)===x&&o.get(k.id)!==x){let N=o.get(k.id);N!==void 0&&h.push([N,S]),S=void 0,d=!0}S&&v.push(S)}let D={...y,lines:v};ht(D)||(c[x]=D)}for(let[x,y]of h){let v=c[x]??{lines:[]};c[x]={...v,lines:[...v.lines,y]}}return d?Object.keys(c).length===0?void 0:c:r}function $h(e){let t={...e};return delete t.go,t}function as(e,t){let r={...e};return t===void 0||Object.keys(t).length===0?delete r.motion:r.motion=t,r}function ss(e,t){let r=vf(e,t);if(r===t.motion)return[];let n=new Set([...Object.keys(t.motion??{}),...Object.keys(r??{})]),o=[];for(let a of n){let i=r?.[a];yo(t.motion?.[a],i)||o.push({op:"setMotion",page:a,value:i})}return o}var Th={canvas:["type","id","name","w","h","background","children"],frame:["type","id","name","x","y","w","h","background","clip","skip","blend","shadow","hidden","locked","children"],ellipse:["type","id","name","x","y","w","h","rotation","fill","stroke","strokeWidth","opacity","blend","shadow","hidden","locked"],group:["type","id","name","hidden","locked","children"],image:["type","id","name","x","y","w","h","rotation","src","fit","radius","opacity","blend","shadow","hidden","locked"],rect:["type","id","name","x","y","w","h","rotation","fill","stroke","strokeWidth","radius","opacity","blend","shadow","hidden","locked"],text:["type","id","name","x","y","w","h","rotation","content","font","size","weight","lineHeight","letterSpacing","align","valign","italic","fill","opacity","blend","shadow","hidden","locked"],vector:["type","id","name","x","y","w","h","rotation","view","d","fill","stroke","strokeWidth","opacity","rule","cap","join","blend","shadow","hidden","locked"]},Lh=["text","font","size","weight","italic","underline","strike","fill","letterSpacing","link"],Oh=["family","fallback","faces"],Dh=["src","weight","style"],Ce=" ";function is(e){let t=["{",`${Ce}"version": ${Q(e.version)},`,`${Ce}"kind": ${JSON.stringify(e.kind)},`,...e.title===void 0?[]:[`${Ce}"title": ${JSON.stringify(e.title)},`],`${Ce}"tokens": ${Nh(e.tokens,Ce)},`];return Object.keys(e.fonts).length>0&&t.push(`${Ce}"fonts": ${Rh(e.fonts,Ce)},`),e.motion!==void 0&&t.push(`${Ce}"motion": ${Ph(e,Ce)},`),t.push(`${Ce}"root": ${bf(e.root,Ce)}`,"}"),`${t.join(`
3
3
  `)}
4
- `}function Mh(e,t){let r=t+_e,n=gr(e).map(o=>`${r}${JSON.stringify(o)}: ${JSON.stringify(e.motion?.[o])}`).join(`,
4
+ `}function Ph(e,t){let r=t+Ce,n=kr(e).map(o=>`${r}${JSON.stringify(o)}: ${JSON.stringify(e.motion?.[o])}`).join(`,
5
5
  `);return n===""?"{}":`{
6
6
  ${n}
7
- ${t}}`}function $h(e,t){let r=Object.keys(e).sort();if(r.length===0)return"{}";let n=t+_e;return`{
8
- ${r.map(a=>`${n}${JSON.stringify(a)}: ${ho(e[a])}`).join(`,
7
+ ${t}}`}function Nh(e,t){let r=Object.keys(e).sort();if(r.length===0)return"{}";let n=t+Ce;return`{
8
+ ${r.map(a=>`${n}${JSON.stringify(a)}: ${bo(e[a])}`).join(`,
9
9
  `)}
10
- ${t}}`}function Th(e,t){let r=Object.keys(e).sort();if(r.length===0)return"{}";let n=t+_e;return`{
11
- ${r.map(a=>`${n}${JSON.stringify(a)}: ${Lh(e[a],n)}`).join(`,
10
+ ${t}}`}function Rh(e,t){let r=Object.keys(e).sort();if(r.length===0)return"{}";let n=t+Ce;return`{
11
+ ${r.map(a=>`${n}${JSON.stringify(a)}: ${Ih(e[a],n)}`).join(`,
12
12
  `)}
13
- ${t}}`}function Lh(e,t){if(!e)return"{}";let r=t+_e,n=e,o=[];for(let a of Eh){let i=n[a];if(i!==void 0){if(a==="faces"){o.push(`${r}"faces": ${Oh(i,r)}`);continue}o.push(`${r}${JSON.stringify(a)}: ${ho(i)}`)}}return`{
13
+ ${t}}`}function Ih(e,t){if(!e)return"{}";let r=t+Ce,n=e,o=[];for(let a of Oh){let i=n[a];if(i!==void 0){if(a==="faces"){o.push(`${r}"faces": ${Fh(i,r)}`);continue}o.push(`${r}${JSON.stringify(a)}: ${bo(i)}`)}}return`{
14
14
  ${o.join(`,
15
15
  `)}
16
- ${t}}`}function Oh(e,t){if(e.length===0)return"[]";let r=t+_e;return`[
17
- ${e.map(o=>r+yf(o,Ah)).join(`,
16
+ ${t}}`}function Fh(e,t){if(e.length===0)return"[]";let r=t+Ce;return`[
17
+ ${e.map(o=>r+wf(o,Dh)).join(`,
18
18
  `)}
19
- ${t}]`}function gf(e,t){let r=t+_e,n=e,o=[];for(let a of _h[e.type]){let i=n[a];if(i!==void 0){if(a==="children"){o.push(`${r}"children": ${Ph(i,r)}`);continue}if(a==="content"){o.push(`${r}"content": ${Dh(i,r)}`);continue}o.push(`${r}${JSON.stringify(a)}: ${ho(i)}`)}}return`{
19
+ ${t}]`}function bf(e,t){let r=t+Ce,n=e,o=[];for(let a of Th[e.type]){let i=n[a];if(i!==void 0){if(a==="children"){o.push(`${r}"children": ${Hh(i,r)}`);continue}if(a==="content"){o.push(`${r}"content": ${Bh(i,r)}`);continue}o.push(`${r}${JSON.stringify(a)}: ${bo(i)}`)}}return`{
20
20
  ${o.join(`,
21
21
  `)}
22
- ${t}}`}function Dh(e,t){if(typeof e=="string")return JSON.stringify(e);if(e.length===0)return"[]";let r=t+_e;return`[
23
- ${e.map(o=>typeof o=="string"?r+JSON.stringify(o):r+yf(o,Ch)).join(`,
22
+ ${t}}`}function Bh(e,t){if(typeof e=="string")return JSON.stringify(e);if(e.length===0)return"[]";let r=t+Ce;return`[
23
+ ${e.map(o=>typeof o=="string"?r+JSON.stringify(o):r+wf(o,Lh)).join(`,
24
24
  `)}
25
- ${t}]`}function yf(e,t){let r=[];for(let n of t){let o=e[n];o!==void 0&&r.push(`${JSON.stringify(n)}: ${ho(o)}`)}return`{ ${r.join(", ")} }`}function Ph(e,t){if(e.length===0)return"[]";let r=t+_e;return`[
26
- ${e.map(o=>r+gf(o,r)).join(`,
25
+ ${t}]`}function wf(e,t){let r=[];for(let n of t){let o=e[n];o!==void 0&&r.push(`${JSON.stringify(n)}: ${bo(o)}`)}return`{ ${r.join(", ")} }`}function Hh(e,t){if(e.length===0)return"[]";let r=t+Ce;return`[
26
+ ${e.map(o=>r+bf(o,r)).join(`,
27
27
  `)}
28
- ${t}]`}function ho(e){return pe(e)?JSON.stringify(`=${e.expr}`):typeof e=="number"?ee(e):JSON.stringify(e)}function ee(e){if(!Number.isFinite(e))return"0";let t=Math.round(e*1e4)/1e4,r=Object.is(t,-0)?0:t;return Math.abs(r)>=1e21?r.toFixed(0):String(r)}var Nh={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function sn(e){let t=[],r,n=0,o=0,a=0,i=0,l,d,c=Rh(e),h=()=>(r||(r={anchors:[{x:n,y:o}],closed:!1},t.push(r)),r.anchors[r.anchors.length-1]),x=(k,_)=>{h(),r?.anchors.push({x:k,y:_}),n=k,o=_},y=(k,_,B,R)=>{h().out=k,r?.anchors.push({x:B,y:R,in:_}),n=B,o=R},b="",P=!0;for(;c.more();){let k=c.command();if(k!==void 0)b=k,P=!0;else if(b===""||b.toUpperCase()==="Z")return{contours:mo(t),error:`Expected a command at ${c.at()}`};let _=b.toUpperCase(),B=b!==_,R=Nh[_];if(R===void 0)return{contours:mo(t),error:`Unknown command ${b}`};if(_==="Z"){r&&(r.closed=!0),r=void 0,n=a,o=i,l=void 0,d=void 0,b="";continue}let J=_==="A"?c.arc():c.numbers(R);if(J===void 0)return{contours:mo(t),error:`${b} expects ${R} numbers at ${c.at()}`};let E=B?n:0,D=B?o:0,N=A=>J[A];switch(_){case"M":P&&(r={anchors:[{x:E+N(0),y:D+N(1)}],closed:!1},t.push(r),n=a=E+N(0),o=i=D+N(1),b=B?"l":"L"),l=d=void 0;break;case"L":x(E+N(0),D+N(1)),l=d=void 0;break;case"H":x(E+N(0),o),l=d=void 0;break;case"V":x(n,D+N(0)),l=d=void 0;break;case"C":{let A={x:E+N(2),y:D+N(3)};y({x:E+N(0),y:D+N(1)},A,E+N(4),D+N(5)),l=A,d=void 0;break}case"S":{let A=l?{x:2*n-l.x,y:2*o-l.y}:{x:n,y:o},G={x:E+N(0),y:D+N(1)};y(A,G,E+N(2),D+N(3)),l=G,d=void 0;break}case"Q":case"T":{let A=_==="Q"?{x:E+N(0),y:D+N(1)}:d?{x:2*n-d.x,y:2*o-d.y}:{x:n,y:o},G=_==="Q"?E+N(2):E+N(0),se=_==="Q"?D+N(3):D+N(1),me={x:n+2/3*(A.x-n),y:o+2/3*(A.y-o)},he={x:G+2/3*(A.x-G),y:se+2/3*(A.y-se)};y(me,he,G,se),d=A,l=void 0;break}case"A":{let A=E+N(5),G=D+N(6);for(let[se,me,he]of Ih(n,o,N(0),N(1),N(2),N(3)!==0,N(4)!==0,A,G))y(se,me,he.x,he.y);(n!==A||o!==G)&&x(A,G),l=d=void 0;break}}P=!1}return{contours:mo(t)}}function mo(e){return e.map(t=>{let r=[...t.anchors];if(t.closed&&r.length>1){let n=r[0],o=r[r.length-1];Wt(n,o)&&(r.pop(),r[0]={...n,...o.in?{in:o.in}:{}})}return{anchors:r.map(on),closed:t.closed}})}function at(e,t,r){return on({x:e.x,y:e.y,...t?{in:t}:{},...r?{out:r}:{}})}function on(e){let t={x:e.x,y:e.y};return e.in&&!Wt(e.in,e)&&(t.in=e.in),e.out&&!Wt(e.out,e)&&(t.out=e.out),t}function Wt(e,t,r=1e-6){return Math.abs(e.x-t.x)<r&&Math.abs(e.y-t.y)<r}function Rh(e){let t=0,r=()=>{for(;t<e.length&&/[\s,]/.test(e[t]);)t+=1},n=()=>{r();let a=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(t));if(a)return t+=a[0].length,Number(a[0])},o=()=>{r();let a=e[t];if(!(a!=="0"&&a!=="1"))return t+=1,Number(a)};return{more(){return r(),t<e.length},command(){r();let a=e[t];if(/[a-zA-Z]/.test(a))return t+=1,a},numbers(a){let i=[];for(let l=0;l<a;l+=1){let d=n();if(d===void 0)return;i.push(d)}return i},arc(){let a=this.numbers(3),i=o(),l=o(),d=this.numbers(2);if(!(!a||i===void 0||l===void 0||!d))return[...a,i,l,...d]},at(){return t}}}function Ih(e,t,r,n,o,a,i,l,d){let c=Math.abs(r),h=Math.abs(n);if(c===0||h===0||e===l&&t===d)return[];let x=o*Math.PI/180,y=Math.cos(x),b=Math.sin(x),P=(e-l)/2,k=(t-d)/2,_=y*P+b*k,B=-b*P+y*k,R=_*_/(c*c)+B*B/(h*h);R>1&&(c*=Math.sqrt(R),h*=Math.sqrt(R));let J=c*c*h*h-c*c*B*B-h*h*_*_,E=c*c*B*B+h*h*_*_,D=(a===i?-1:1)*Math.sqrt(Math.max(0,J/E)),N=D*c*B/h,A=-D*h*_/c,G=y*N-b*A+(e+l)/2,se=b*N+y*A+(t+d)/2,me=(L,H,q,S)=>{let U=L*q+H*S,W=Math.hypot(L,H)*Math.hypot(q,S),I=Math.acos(Math.min(1,Math.max(-1,U/W)));return L*S-H*q<0?-I:I},he=me(1,0,(_-N)/c,(B-A)/h),ke=me((_-N)/c,(B-A)/h,(-_-N)/c,(-B-A)/h);!i&&ke>0&&(ke-=2*Math.PI),i&&ke<0&&(ke+=2*Math.PI);let we=Math.max(1,Math.ceil(Math.abs(ke)/(Math.PI/2)-1e-9)),T=ke/we,Q=4/3*Math.tan(T/4),w=L=>({x:G+c*Math.cos(L)*y-h*Math.sin(L)*b,y:se+c*Math.cos(L)*b+h*Math.sin(L)*y}),$=L=>({x:-c*Math.sin(L)*y-h*Math.cos(L)*b,y:-c*Math.sin(L)*b+h*Math.cos(L)*y}),M=[];for(let L=0;L<we;L+=1){let H=he+L*T,q=H+T,S=w(H),U=L===we-1?{x:l,y:d}:w(q),W=$(H),I=$(q);M.push([{x:S.x+Q*W.x,y:S.y+Q*W.y},{x:U.x-Q*I.x,y:U.y-Q*I.y},U])}return M}function ut(e){let t=[],r=n=>`${ee(n.x)} ${ee(n.y)}`;for(let n of e){let{anchors:o}=n,a=o[0];if(!a)continue;t.push(`M${r(a)}`);let i=ln(n);for(let l=0;l<i;l+=1){let d=o[l],c=o[(l+1)%o.length],h=n.closed&&l===o.length-1;!d.out&&!c.in?h||t.push(`L${r(c)}`):t.push(`C${r(d.out??d)} ${r(c.in??c)} ${r(c)}`)}n.closed&&t.push("Z")}return t.join(" ")}function ln(e){let t=e.anchors.length;return t<2?0:e.closed?t:t-1}function dn(e,t){let r=e.anchors[t],n=e.anchors[(t+1)%e.anchors.length];return[{x:r.x,y:r.y},r.out??{x:r.x,y:r.y},n.in??{x:n.x,y:n.y},{x:n.x,y:n.y}]}function vf(e,t){let r=e.anchors[t],n=e.anchors[(t+1)%e.anchors.length];return!r.out&&!n.in}function an(e,t){let[r,n,o,a]=e,i=1-t,l=i*i*i,d=3*i*i*t,c=3*i*t*t,h=t*t*t;return{x:l*r.x+d*n.x+c*o.x+h*a.x,y:l*r.y+d*n.y+c*o.y+h*a.y}}function ct(e,t){return e.map(r=>({closed:r.closed,anchors:r.anchors.map(n=>{let o=t(n);return{x:o.x,y:o.y,...n.in?{in:t(n.in)}:{},...n.out?{out:t(n.out)}:{}}})}))}function Xt(e){let t=1/0,r=1/0,n=-1/0,o=-1/0,a=i=>{t=Math.min(t,i.x),r=Math.min(r,i.y),n=Math.max(n,i.x),o=Math.max(o,i.y)};for(let i of e){for(let d of i.anchors)a(d);let l=ln(i);for(let d=0;d<l;d+=1){let c=dn(i,d);for(let h of Fh(c))a(an(c,h))}}if(t!==1/0)return{x:t,y:r,w:n-t,h:o-r}}function Fh(e){let[t,r,n,o]=e,a=[];for(let i of["x","y"]){let l=-t[i]+3*r[i]-3*n[i]+o[i],d=2*(t[i]-2*r[i]+n[i]),c=r[i]-t[i];if(Math.abs(l)<1e-12){Math.abs(d)>1e-12&&a.push(-c/d);continue}let h=d*d-4*l*c;if(h<0)continue;let x=Math.sqrt(h);a.push((-d+x)/(2*l),(-d-x)/(2*l))}return a.filter(i=>i>0&&i<1)}function go(e){if(e===void 0)return;let t=e.trim().split(/[\s,]+/).map(Number);if(t.length!==4||t.some(i=>!Number.isFinite(i)))return;let[r,n,o,a]=t;return{x:r,y:n,w:o,h:a}}function Yt(e){return[e.x,e.y,e.w,e.h].map(ee).join(" ")}function fn(e,t,r){return go(e)??{x:0,y:0,w:t,h:r}}function un(e,t){let r=e.w===0?1:t.w/e.w,n=e.h===0?1:t.h/e.h;return o=>({x:t.x+(o.x-e.x)*r,y:t.y+(o.y-e.y)*n})}function os(e,t){let r=e.w===0||t.w===0?1:e.w/t.w,n=e.h===0||t.h===0?1:e.h/t.h;return o=>({x:e.x+(o.x-t.x)*r,y:e.y+(o.y-t.y)*n})}function bf(e,t=.5){let[r,n,o,a]=e;if(Wt(r,n)&&Wt(o,a))return[r,a];let l=Math.hypot(n.x-r.x,n.y-r.y)+Math.hypot(o.x-n.x,o.y-n.y)+Math.hypot(a.x-o.x,a.y-o.y),d=Math.min(256,Math.max(4,Math.ceil(Math.sqrt(l/t)))),c=[];for(let h=0;h<=d;h+=1)c.push(an(e,h/d));return c}function as(e,t,r){let n=0,o=0;for(let a of e){let i=Bh(a);if(i.length!==0){if(r.reach>0){let l=a.closed?i.length:i.length-1;for(let d=0;d<l;d+=1){let c=i[d],h=i[(d+1)%i.length];if(Hh(t,c,h)<=r.reach)return!0}if(i.length===1&&Math.hypot(t.x-i[0].x,t.y-i[0].y)<=r.reach)return!0}if(r.fill)for(let l=0;l<i.length;l+=1){let d=i[l],c=i[(l+1)%i.length];d.y<=t.y!=c.y<=t.y&&d.x+(t.y-d.y)/(c.y-d.y)*(c.x-d.x)>t.x&&(o+=1,n+=c.y>d.y?1:-1)}}}return r.fill?r.rule==="evenodd"?o%2===1:n!==0:!1}function Bh(e){let t=e.anchors[0];if(!t)return[];let r=[{x:t.x,y:t.y}],n=ln(e);for(let o=0;o<n;o+=1)r.push(...bf(dn(e,o)).slice(1));return e.closed&&r.length>1&&r.pop(),r}function Hh(e,t,r){let n=r.x-t.x,o=r.y-t.y,a=n*n+o*o,i=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*o)/a));return Math.hypot(e.x-(t.x+i*n),e.y-(t.y+i*o))}function ss(e,t){let r;return e.forEach((n,o)=>{let a=ln(n);for(let i=0;i<a;i+=1){let l=dn(n,i),d=k=>{let _=an(l,k);return Math.hypot(_.x-t.x,_.y-t.y)},c=32,h=0;for(let k=1;k<=c;k+=1)d(k/c)<d(h)&&(h=k/c);let x=Math.max(0,h-1/c),y=Math.min(1,h+1/c);for(let k=0;k<24;k+=1){let _=x+(y-x)/3,B=y-(y-x)/3;d(_)<d(B)?y=B:x=_}let b=(x+y)/2,P=d(b);(!r||P<r.distance)&&(r={contour:o,segment:i,t:b,point:an(l,b),distance:P})}}),r}function is(e,t,r,n){return e.map((o,a)=>{if(a!==t)return o;let i=[...o.anchors],l=i.length,d=i[r],c=(r+1)%l,h=i[c];if(vf(o,r)){let N={x:d.x+(h.x-d.x)*n,y:d.y+(h.y-d.y)*n};return i.splice(r+1,0,N),{...o,anchors:i}}let[x,y,b,P]=dn(o,r),k=(N,A)=>({x:N.x+(A.x-N.x)*n,y:N.y+(A.y-N.y)*n}),_=k(x,y),B=k(y,b),R=k(b,P),J=k(_,B),E=k(B,R),D=k(J,E);return i[r]=on({...d,out:_}),i[c]=on({...h,in:R}),i.splice(r+1,0,on({x:D.x,y:D.y,in:J,out:E})),{...o,anchors:i}})}var xo=.5522847498;function ls(e,t,r=0){let n=Math.max(0,Math.min(r,e/2,t/2));if(n===0)return[{closed:!0,anchors:[{x:0,y:0},{x:e,y:0},{x:e,y:t},{x:0,y:t}]}];let o=xo*n,a=[{x:n,y:0,in:{x:n-o,y:0}},{x:e-n,y:0,out:{x:e-n+o,y:0}},{x:e,y:n,in:{x:e,y:n-o}},{x:e,y:t-n,out:{x:e,y:t-n+o}},{x:e-n,y:t,in:{x:e-n+o,y:t}},{x:n,y:t,out:{x:n-o,y:t}},{x:0,y:t-n,in:{x:0,y:t-n+o}},{x:0,y:n,out:{x:0,y:n-o}}];return[{closed:!0,anchors:Uh(a)}]}function ds(e,t){let r=e/2,n=t/2,o=xo*r,a=xo*n;return[{closed:!0,anchors:[{x:r,y:0,in:{x:r-o,y:0},out:{x:r+o,y:0}},{x:e,y:n,in:{x:e,y:n-a},out:{x:e,y:n+a}},{x:r,y:t,in:{x:r+o,y:t},out:{x:r-o,y:t}},{x:0,y:n,in:{x:0,y:n+a},out:{x:0,y:n-a}}]}]}function Uh(e){let t=[];for(let o of e){let a=t[t.length-1];if(a&&Wt(a,o)&&!a.out&&!o.in){t[t.length-1]=at(a,a.in,o.out);continue}t.push(o)}let r=t[0],n=t[t.length-1];return t.length>1&&r&&n&&Wt(r,n)&&!n.out&&!r.in&&(t[0]=at(r,n.in,r.out),t.pop()),t}var st=class extends Error{op;constructor(t,r){super(t),this.op=r,this.name="OpError"}};function ve(e,t){let r=e,n=[];for(let o of t){let a=Sf(r,o);r=a.document,n.push(a.inverse)}return n.reverse(),{document:r,inverse:n}}function Sf(e,t){switch(t.op){case"set":{let r=V(e.root,t.id);if(!r)throw new st(`No node ${t.id}`,t);let n=r[t.prop];return{document:yo(e,us(e.root,t.id,o=>Vh(o,t.prop,t.value),t)),inverse:{op:"set",id:t.id,prop:t.prop,value:n}}}case"insert":{if(V(e.root,t.node.id))throw new st(`Duplicate id ${t.node.id}`,t);let r=vo(e.root,t.parent,n=>{let o=kf(t.index,0,n.length);return[...n.slice(0,o),t.node,...n.slice(o)]},t);return{document:yo(e,r),inverse:{op:"remove",id:t.node.id}}}case"remove":{let r=wf(e,t.id,t),n=vo(e.root,r.parent.id,o=>o.filter(a=>a.id!==t.id),t);return{document:yo(e,n),inverse:{op:"insert",parent:r.parent.id,index:r.index,node:r.node}}}case"move":{let r=wf(e,t.id,t),n=vo(e.root,r.parent.id,a=>a.filter(i=>i.id!==t.id),t),o=vo(n,t.parent,a=>{let i=kf(t.index,0,a.length);return[...a.slice(0,i),r.node,...a.slice(i)]},t);return{document:yo(e,o),inverse:{op:"move",id:t.id,parent:r.parent.id,index:r.index}}}case"setTitle":{let{title:r,...n}=e;return{document:t.value===void 0?n:{...n,title:t.value},inverse:{op:"setTitle",value:r}}}case"setToken":{let r=Object.prototype.hasOwnProperty.call(e.tokens,t.name)?e.tokens[t.name]:void 0,n={...e.tokens};return t.value===void 0?delete n[t.name]:n[t.name]=t.value,{document:{...e,tokens:n},inverse:{op:"setToken",name:t.name,value:r}}}case"setAsset":{let r=Object.prototype.hasOwnProperty.call(e.assets,t.name)?e.assets[t.name]:void 0,n={...e.assets};return t.value===void 0?delete n[t.name]:n[t.name]=t.value,{document:{...e,assets:n},inverse:{op:"setAsset",name:t.name,value:r}}}case"setFont":{let r=Object.prototype.hasOwnProperty.call(e.fonts,t.name)?e.fonts[t.name]:void 0,n={...e.fonts};return t.family===void 0?delete n[t.name]:n[t.name]=t.family,{document:{...e,fonts:n},inverse:{op:"setFont",name:t.name,family:r}}}case"setMotion":{let r=e.motion&&Object.prototype.hasOwnProperty.call(e.motion,t.page)?e.motion[t.page]:void 0,n={...e.motion};return ft(t.value)?delete n[t.page]:n[t.page]=t.value,{document:ts(e,n),inverse:{op:"setMotion",page:t.page,value:r}}}}}function bo(e,t){if(!e.motion||!t.some(n=>n.op==="remove"||n.op==="move"))return t;let r=rs(e,ve(e,t).document);return r.length===0?t:[...t,...r]}function yo(e,t){if(t.type!=="canvas")throw new Error("The document root must stay a canvas");return{...e,root:t}}function Vh(e,t,r){let n={...e};return r===void 0?delete n[t]:n[t]=r,n}function us(e,t,r,n){if(e.id===t)return r(e);if(!ce(e))return e;let o=!1,a=e.children.map(i=>{let l=us(i,t,r,n);return l!==i&&(o=!0),l});return o?{...e,children:a}:e}function vo(e,t,r,n){let o=V(e,t);if(!o)throw new st(`No node ${t}`,n);if(!ce(o))throw new st(`${t} cannot hold children`,n);return us(e,t,a=>({...a,children:r(a.children)}),n)}function wf(e,t,r){if(t===e.root.id)throw new st("The document root cannot be removed or moved",r);let n,o=a=>{ce(a)&&a.children.forEach((i,l)=>{i.id===t&&(n={node:i,parent:a,index:l}),o(i)})};if(o(e.root),!n)throw new st(`No node ${t}`,r);return n}function kf(e,t,r){return Math.min(Math.max(e,t),r)}function cs(e,t){let r=[];e.title!==t.title&&r.push({op:"setTitle",value:t.title});for(let a of vr(e.tokens,t.tokens)){let i=t.tokens[a];e.tokens[a]!==i&&r.push({op:"setToken",name:a,value:i})}for(let a of vr(e.fonts,t.fonts)){let i=t.fonts[a];qh(e.fonts[a],i)||r.push({op:"setFont",name:a,family:i})}for(let a of vr(e.assets,t.assets)){let i=t.assets[a];e.assets[a]?.hash!==i?.hash&&r.push({op:"setAsset",name:a,value:i})}if(!zh(e.root.children,t.root.children)){for(let a of e.root.children)r.push({op:"remove",id:a.id});t.root.children.forEach((a,i)=>{r.push({op:"insert",parent:e.root.id,index:i,node:a})})}for(let a of vr(e.motion??{},t.motion??{})){let i=t.motion?.[a];co(e.motion?.[a],i)||r.push({op:"setMotion",page:a,value:i})}let n=e.root,o=t.root;for(let a of vr(n,o))a==="type"||a==="id"||a==="children"||_f(n[a],o[a])||r.push({op:"set",id:e.root.id,prop:a,value:o[a]});return r}function vr(e,t){return[...new Set([...Object.keys(e),...Object.keys(t)])]}function _f(e,t){return e===t?!0:pe(e)&&pe(t)&&e.expr===t.expr}function zh(e,t){return e.length===t.length&&e.every((r,n)=>fs(r,t[n]))}function fs(e,t){if(_f(e,t))return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((a,i)=>fs(a,t[i]));let r=e,n=t;return vr(r,n).every(a=>fs(r[a],n[a]))}function qh(e,t){if(e===t)return!0;if(!e||!t||e.family!==t.family||e.fallback!==t.fallback)return!1;let r=e.faces??[],n=t.faces??[];return r.length===n.length&&r.every((o,a)=>{let i=n[a];return o.src===i.src&&o.weight===i.weight&&o.style===i.style})}var cn={canvas:[["name","string"],["w","numberValue"],["h","numberValue"],["background","stringValue"]],frame:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["background","stringValue"],["clip","boolean"],["skip","boolean"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],group:[["name","string"],["hidden","boolean"],["locked","boolean"]],ellipse:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],vector:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["view","string"],["d","string"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["opacity","numberValue"],["rule","fillRule"],["cap","lineCap"],["join","lineJoin"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],rect:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["radius","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],image:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["src","stringValue"],["fit","imageFit"],["radius","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],text:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["font","stringValue"],["size","numberValue"],["weight","numberValue"],["lineHeight","numberValue"],["letterSpacing","numberValue"],["align","align"],["valign","valign"],["italic","boolean"],["fill","stringValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]]},pn=[["font","string"],["size","number"],["weight","number"],["italic","boolean"],["underline","boolean"],["strike","boolean"],["fill","string"],["letterSpacing","number"],["link","string"]],ps=[["weight","number"],["style","fontStyle"]],wo=[["enter","pageEffect"],["duration","number"]],hn=[["enter","nodeEffect"],["exit","nodeEffect"],["duration","number"],["delay","number"],["step","boolean"],["together","boolean"],["go","string"]],Af=Object.keys(cn);function ko(e){return Af.includes(e)}function hs(e,t){return cn[e].find(([r])=>r===t)?.[1]}var Jt=" ";function Ge(e){if(pe(e))return/^[$@]/.test(e.expr)&&!/\s/.test(e.expr)?e.expr:`(${e.expr})`;if(typeof e=="number")return ee(e);let t=String(e);return jh(t)?JSON.stringify(t):t}function jh(e){return e===""||/[\s"=()]/.test(e)||/^[$@]/.test(e)}function Be(e,t){if(t==="boolean")return e===""||e==="true"?{value:!0}:e==="false"?{value:!1}:{error:`Expected true or false, got ${e}`};if(e.startsWith('"')){let n=wr(e);return n===void 0?{error:`Malformed quoted string ${e}`}:Cf(n,t,e)}if(Xh(e)){if(!Kh(t))return{error:Gh(e,t)};let n=$f(e).trim();return n===""?{error:"Empty expression"}:{value:St(n)}}return t==="numberValue"&&Mf.test(e)?{value:St(e)}:Cf(e,t,e)}var Mf=/^-?\d+(?:\.\d+)?%$/;function Kh(e){return e==="numberValue"||e==="stringValue"}function Gh(e,t){return t==="number"?`Expected a plain number, not an expression, got ${e}`:t==="string"&&/^\$\w+$/.test(e)?`Expected a literal, got ${e} \u2014 name a token without the $: ${e.slice(1)}`:`Expected a literal, not an expression, got ${e} \u2014 quote it if you meant the text`}function Wh(e,t){let r=/^(-?\d+(?:\.\d+)?)([A-Za-z]+)$/.exec(e);return r?r[2]==="s"&&t==="number"?` \u2014 durations are milliseconds: ${Number(r[1])*1e3}`:/^(?:px|pt|deg|ms)$/.test(r[2])?` \u2014 drop the unit: ${r[1]}`:" \u2014 units are not supported: use a number, a percentage like (100%), or an expression":t==="number"?Mf.test(e)?" \u2014 a percentage is not allowed here":"":/^-[$@(]/.test(e)?` \u2014 wrap an expression in parentheses: (${e})`:/^-?[A-Za-z_]\w*(?:\.\w+)+$/.test(e)?` \u2014 wrap an expression in parentheses: (${e})`:""}function Cf(e,t,r){switch(t){case"numberValue":case"number":{let n=Number(e);return Number.isFinite(n)&&e.trim()!==""?{value:n}:{error:`Expected a number, got ${r}${Wh(e,t)}`}}case"align":return _t.includes(e)?{value:e}:{error:`Expected one of ${_t.join(", ")}, got ${r}`};case"valign":return Ct.includes(e)?{value:e}:{error:`Expected one of ${Ct.join(", ")}, got ${r}`};case"fontStyle":return e==="normal"||e==="italic"?{value:e}:{error:`Expected normal or italic, got ${r}`};case"imageFit":return Et.includes(e)?{value:e}:{error:`Expected one of ${Et.join(", ")}, got ${r}`};case"fillRule":return br(Vt,e,r);case"lineCap":return br(zt,e,r);case"lineJoin":return br(qt,e,r);case"blendMode":return br(Ut,e,r);case"pageEffect":return br(mr,e,r);case"nodeEffect":return br(nn,e,r);default:return{value:e}}}function br(e,t,r){return e.includes(t)?{value:t}:{error:`Expected one of ${e.join(", ")}, got ${r}`}}function Xh(e){return/^[$@(]/.test(e)}function wr(e){try{let t=JSON.parse(e);return typeof t=="string"?t:void 0}catch{return}}function $f(e){if(!e.startsWith("("))return e;let t=0;for(let r=0;r<e.length;r+=1){let n=e[r];if(n==="(")t+=1;else if(n===")"&&(t-=1,t===0))return r===e.length-1?e.slice(1,-1):e}return e}function Tf(e){let t=[],r="",n=0,o=!1;for(let a=0;a<e.length;a+=1){let i=e[a];if(o){r+=i,i==="\\"?(r+=e[a+1]??"",a+=1):i==='"'&&(o=!1);continue}if(i==='"'){o=!0,r+=i;continue}if(i==="("?n+=1:i===")"&&(n=Math.max(0,n-1)),n===0&&/\s/.test(i)){r!==""&&t.push(r),r="";continue}r+=i}return r!==""&&t.push(r),t}function ms(e,t,r){let n=r===void 0?void 0:He(r);if(n?.value===void 0||!Ef(e[t]??""))return;let o=t;for(;o<e.length&&Ef(e[o]??"");)o+=1;let a=[$f(n.value),...e.slice(t,o)].join(" ");return{end:o,message:`${n.key}: an expression with spaces needs parentheses \u2014 write ${n.key}=(${a})`}}function Ef(e){return!e.includes("=")&&/^(?:[-+*/]|-?\d+(?:\.\d+)?%?|[$@][\w.]*|[A-Za-z_]\w*(?:\.\w+)+|\(.*|.*\))$/.test(e)}function He(e){let t=e.indexOf("=");return t===-1?{key:e,value:void 0}:{key:e.slice(0,t),value:e.slice(t+1)}}var Yh=new Set(["exit","delay","step","together","go"]);function xs(e,t){let r=e.words[1];if(r===void 0||r.includes("=")){t(e.number,"invalid-motion","Expected motion <page>, e.g. motion intro enter=fade");return}let n={};for(let o of e.words.slice(2)){let{key:a,value:i}=He(o),l=wo.find(([c])=>c===a)?.[1];if(l===void 0){let c=Yh.has(a)?` \u2014 ${a} goes on a node's line, under the header`:"";t(e.number,"invalid-motion",`motion ${r} has no "${a}"${c}`,r);continue}let d=Be(i??"",l);"error"in d?t(e.number,"invalid-motion",`${a}: ${d.error}`,r):a==="duration"&&!Of(d.value)?t(e.number,"invalid-motion",Df(a,i),r):n[a]=d.value}return{page:r,number:e.number,head:n,lines:[],where:new Map,taken:new Map}}function gs(e,t,r){let n=t.words[0];if(t.indent!==1){r(t.number,"invalid-motion","A motion line sits one level under its page");return}if(n.includes("=")){r(t.number,"invalid-motion",`Expected a node id first, got ${n}`);return}if(n===e.page){r(t.number,"invalid-motion",`${n} is the page: its transition goes on the header (motion ${n} enter=fade)`,n);return}let o={id:n},a=!0;for(let l of t.words.slice(1)){let{key:d,value:c}=He(l),h=hn.find(([y])=>y===d)?.[1];if(h===void 0){r(t.number,"invalid-motion",`A motion line has no "${d}"`,n),a=!1;continue}let x=Be(c??"",h);"error"in x?(r(t.number,"invalid-motion",`${d}: ${x.error}`,n),a=!1):(d==="duration"||d==="delay")&&!Of(x.value)?(r(t.number,"invalid-motion",Df(d,c),n),a=!1):d==="go"&&dt(x.value)===void 0?(r(t.number,"invalid-motion",`go: expected #<page>, back, next, or an https: or mailto: link, got ${c??""}`,n),a=!1):x.value!==!1&&(o[d]=x.value)}if(o.enter!==void 0&&o.exit!==void 0&&(r(t.number,"invalid-motion",`${n} either enters or exits on one line \u2014 write a second line for the other`,n),a=!1),o.step===!0&&o.together===!0&&(r(t.number,"invalid-motion",`${n} waits for a step or starts together with the line above, not both`,n),a=!1),!a)return;let i=Jh(o);if(!xr(i)){r(t.number,"invalid-motion",`${n} says nothing: give it enter=, exit= or go=`,n);return}for(let l of["enter","exit","go"]){if(i[l]===void 0)continue;let d=e.taken.get(`${n} ${l}`);if(d!==void 0){let c=l==="go"?"has a go=":l==="enter"?"enters":"exits";r(t.number,"invalid-motion",`${n} already ${c} on line ${d}`,n);return}}for(let l of["enter","exit","go"])i[l]!==void 0&&e.taken.set(`${n} ${l}`,t.number);e.where.has(n)||e.where.set(n,t.number),e.lines.push(i)}function ys(e){let t={...e.head.enter===void 0?{}:{enter:e.head.enter},...e.head.duration===void 0?{}:{duration:e.head.duration},lines:e.lines};return ft(t)?void 0:t}function Lf(e,t){let r=t.motion;if(r)for(let n of gr(t)){let o=r[n];if(o===void 0||ft(o))continue;e.at(-1)!==""&&e.push("");let a=["motion",n];for(let[i]of wo){let l=o[i];l!==void 0&&a.push(`${i}=${Ge(l)}`)}e.push(a.join(" "));for(let i of o.lines){let l=[i.id];for(let[d,c]of hn){let h=i[d];if(h!==void 0){if(c==="boolean"){h===!0&&l.push(d);continue}l.push(`${d}=${Ge(h)}`)}}e.push(Jt+l.join(" "))}}}function Jh(e){let t={id:e.id};for(let[r]of hn)e[r]!==void 0&&(t[r]=e[r]);return t}function Of(e){return typeof e=="number"&&e>=0&&e<=Gt}function Df(e,t){return`${e}: expected 0 to ${Gt} milliseconds, got ${t??""}`}var Zh=24;function bs(e,t={}){let r=[`version ${ee(e.version)}`,`kind ${e.kind}`];e.title!==void 0&&r.push(`title ${JSON.stringify(e.title)}`);for(let[n,o]of Object.entries(e.tokens))r.push(`$${n} = ${Ge(o)}`);r.push("");for(let[n,o]of Object.entries(e.fonts))tm(r,n,o,t),r.push("");if(Object.keys(e.assets).length>0){for(let[n,o]of Object.entries(e.assets))r.push(em(n,o));r.push("")}return Qh(e.root)?e.root.children.forEach((n,o)=>{o>0&&r.push(""),vs(r,n,0)}):vs(r,e.root,0),Lf(r,e),r.join(`
29
- `)}function Qh(e){return e.id===ot&&e.w===void 0&&e.h===void 0&&e.background===void 0&&e.name===void 0}function em(e,t){let r=[`asset ${e} = ${t.type}`,`hash=${t.hash}`,`bytes=${ee(t.bytes)}`];for(let n of["credit","source","license"]){let o=t[n];o!==void 0&&r.push(`${n}=${Ge(o)}`)}return r.join(" ")}function tm(e,t,r,n){e.push(`font ${t} = ${Ge(r.family)}`),r.fallback!==void 0&&e.push(`${Jt}fallback ${Ge(r.fallback)}`);for(let o of r.faces??[]){let a=n.abbreviateFaces?rm(o.src):o.src,i=[`face ${Ge(a)}`];for(let[l]of ps){let d=o[l];d!==void 0&&i.push(`${l}=${Ge(d)}`)}e.push(Jt+i.join(" "))}}function rm(e){return e.startsWith("data:")?`${e.slice(0,Zh)}\u2026 ${ee(Math.round(e.length/1024))} kB`:e}function vs(e,t,r){let n=Jt.repeat(r),o=t,a=[t.type,t.id];for(let[i,l]of cn[t.type]){let d=o[i];if(d!==void 0){if(l==="boolean"){d===!0&&a.push(i);continue}a.push(`${i}=${Ge(d)}`)}}if(e.push(n+a.join(" ")),t.type==="text"&&nm(e,t.content,r+1),ce(t))for(let i of de(t))vs(e,i,r+1)}function nm(e,t,r){let n=Jt.repeat(r),o=typeof t=="string"?[t]:t;for(let a of o){if(typeof a=="string"){e.push(n+JSON.stringify(a));continue}e.push(n+[JSON.stringify(a.text),...om(a)].join(" "))}}function om(e){let t=[];for(let[r,n]of pn){let o=e[r];if(o!==void 0){if(n==="boolean"){o===!0&&t.push(r);continue}t.push(`${r}=${Ge(o)}`)}}return t}var Zt="--- payload base64 ---",Pf="sha256-";function Nf(e){let t=am(e);return t===-1?{head:e,payload:""}:{head:e.slice(0,t),payload:e.slice(t+Zt.length)}}function ws(e){let{head:t,payload:r}=Nf(e);return{head:t,blocks:Rf(r)}}function ks(e,t){let r=new Map;for(let n of sm(e)){let o=t.get(n);o!==void 0&&r.set(n,o)}return r.size===0?e:`${e.trimEnd()}
28
+ ${t}]`}function bo(e){return me(e)?JSON.stringify(`=${e.expr}`):typeof e=="number"?Q(e):JSON.stringify(e)}function Q(e){if(!Number.isFinite(e))return"0";let t=Math.round(e*1e4)/1e4,r=Object.is(t,-0)?0:t;return Math.abs(r)>=1e21?r.toFixed(0):String(r)}var zh={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function cn(e){let t=[],r,n=0,o=0,a=0,i=0,l,d,c=Uh(e),h=()=>(r||(r={anchors:[{x:n,y:o}],closed:!1},t.push(r)),r.anchors[r.anchors.length-1]),x=(k,S)=>{h(),r?.anchors.push({x:k,y:S}),n=k,o=S},y=(k,S,B,N)=>{h().out=k,r?.anchors.push({x:B,y:N,in:S}),n=B,o=N},v="",D=!0;for(;c.more();){let k=c.command();if(k!==void 0)v=k,D=!0;else if(v===""||v.toUpperCase()==="Z")return{contours:wo(t),error:`Expected a command at ${c.at()}`};let S=v.toUpperCase(),B=v!==S,N=zh[S];if(N===void 0)return{contours:wo(t),error:`Unknown command ${v}`};if(S==="Z"){r&&(r.closed=!0),r=void 0,n=a,o=i,l=void 0,d=void 0,v="";continue}let J=S==="A"?c.arc():c.numbers(N);if(J===void 0)return{contours:wo(t),error:`${v} expects ${N} numbers at ${c.at()}`};let E=B?n:0,P=B?o:0,R=C=>J[C];switch(S){case"M":D&&(r={anchors:[{x:E+R(0),y:P+R(1)}],closed:!1},t.push(r),n=a=E+R(0),o=i=P+R(1),v=B?"l":"L"),l=d=void 0;break;case"L":x(E+R(0),P+R(1)),l=d=void 0;break;case"H":x(E+R(0),o),l=d=void 0;break;case"V":x(n,P+R(0)),l=d=void 0;break;case"C":{let C={x:E+R(2),y:P+R(3)};y({x:E+R(0),y:P+R(1)},C,E+R(4),P+R(5)),l=C,d=void 0;break}case"S":{let C=l?{x:2*n-l.x,y:2*o-l.y}:{x:n,y:o},G={x:E+R(0),y:P+R(1)};y(C,G,E+R(2),P+R(3)),l=G,d=void 0;break}case"Q":case"T":{let C=S==="Q"?{x:E+R(0),y:P+R(1)}:d?{x:2*n-d.x,y:2*o-d.y}:{x:n,y:o},G=S==="Q"?E+R(2):E+R(0),de=S==="Q"?P+R(3):P+R(1),ye={x:n+2/3*(C.x-n),y:o+2/3*(C.y-o)},xe={x:G+2/3*(C.x-G),y:de+2/3*(C.y-de)};y(ye,xe,G,de),d=C,l=void 0;break}case"A":{let C=E+R(5),G=P+R(6);for(let[de,ye,xe]of Vh(n,o,R(0),R(1),R(2),R(3)!==0,R(4)!==0,C,G))y(de,ye,xe.x,xe.y);(n!==C||o!==G)&&x(C,G),l=d=void 0;break}}D=!1}return{contours:wo(t)}}function wo(e){return e.map(t=>{let r=[...t.anchors];if(t.closed&&r.length>1){let n=r[0],o=r[r.length-1];Jt(n,o)&&(r.pop(),r[0]={...n,...o.in?{in:o.in}:{}})}return{anchors:r.map(fn),closed:t.closed}})}function dt(e,t,r){return fn({x:e.x,y:e.y,...t?{in:t}:{},...r?{out:r}:{}})}function fn(e){let t={x:e.x,y:e.y};return e.in&&!Jt(e.in,e)&&(t.in=e.in),e.out&&!Jt(e.out,e)&&(t.out=e.out),t}function Jt(e,t,r=1e-6){return Math.abs(e.x-t.x)<r&&Math.abs(e.y-t.y)<r}function Uh(e){let t=0,r=()=>{for(;t<e.length&&/[\s,]/.test(e[t]);)t+=1},n=()=>{r();let a=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(t));if(a)return t+=a[0].length,Number(a[0])},o=()=>{r();let a=e[t];if(!(a!=="0"&&a!=="1"))return t+=1,Number(a)};return{more(){return r(),t<e.length},command(){r();let a=e[t];if(/[a-zA-Z]/.test(a))return t+=1,a},numbers(a){let i=[];for(let l=0;l<a;l+=1){let d=n();if(d===void 0)return;i.push(d)}return i},arc(){let a=this.numbers(3),i=o(),l=o(),d=this.numbers(2);if(!(!a||i===void 0||l===void 0||!d))return[...a,i,l,...d]},at(){return t}}}function Vh(e,t,r,n,o,a,i,l,d){let c=Math.abs(r),h=Math.abs(n);if(c===0||h===0||e===l&&t===d)return[];let x=o*Math.PI/180,y=Math.cos(x),v=Math.sin(x),D=(e-l)/2,k=(t-d)/2,S=y*D+v*k,B=-v*D+y*k,N=S*S/(c*c)+B*B/(h*h);N>1&&(c*=Math.sqrt(N),h*=Math.sqrt(N));let J=c*c*h*h-c*c*B*B-h*h*S*S,E=c*c*B*B+h*h*S*S,P=(a===i?-1:1)*Math.sqrt(Math.max(0,J/E)),R=P*c*B/h,C=-P*h*S/c,G=y*R-v*C+(e+l)/2,de=v*R+y*C+(t+d)/2,ye=(T,H,j,F)=>{let O=T*j+H*F,X=Math.hypot(T,H)*Math.hypot(j,F),z=Math.acos(Math.min(1,Math.max(-1,O/X)));return T*F-H*j<0?-z:z},xe=ye(1,0,(S-R)/c,(B-C)/h),ke=ye((S-R)/c,(B-C)/h,(-S-R)/c,(-B-C)/h);!i&&ke>0&&(ke-=2*Math.PI),i&&ke<0&&(ke+=2*Math.PI);let Se=Math.max(1,Math.ceil(Math.abs(ke)/(Math.PI/2)-1e-9)),A=ke/Se,te=4/3*Math.tan(A/4),w=T=>({x:G+c*Math.cos(T)*y-h*Math.sin(T)*v,y:de+c*Math.cos(T)*v+h*Math.sin(T)*y}),$=T=>({x:-c*Math.sin(T)*y-h*Math.cos(T)*v,y:-c*Math.sin(T)*v+h*Math.cos(T)*y}),M=[];for(let T=0;T<Se;T+=1){let H=xe+T*A,j=H+A,F=w(H),O=T===Se-1?{x:l,y:d}:w(j),X=$(H),z=$(j);M.push([{x:F.x+te*X.x,y:F.y+te*X.y},{x:O.x-te*z.x,y:O.y-te*z.y},O])}return M}function mt(e){let t=[],r=n=>`${Q(n.x)} ${Q(n.y)}`;for(let n of e){let{anchors:o}=n,a=o[0];if(!a)continue;t.push(`M${r(a)}`);let i=pn(n);for(let l=0;l<i;l+=1){let d=o[l],c=o[(l+1)%o.length],h=n.closed&&l===o.length-1;!d.out&&!c.in?h||t.push(`L${r(c)}`):t.push(`C${r(d.out??d)} ${r(c.in??c)} ${r(c)}`)}n.closed&&t.push("Z")}return t.join(" ")}function pn(e){let t=e.anchors.length;return t<2?0:e.closed?t:t-1}function hn(e,t){let r=e.anchors[t],n=e.anchors[(t+1)%e.anchors.length];return[{x:r.x,y:r.y},r.out??{x:r.x,y:r.y},n.in??{x:n.x,y:n.y},{x:n.x,y:n.y}]}function kf(e,t){let r=e.anchors[t],n=e.anchors[(t+1)%e.anchors.length];return!r.out&&!n.in}function un(e,t){let[r,n,o,a]=e,i=1-t,l=i*i*i,d=3*i*i*t,c=3*i*t*t,h=t*t*t;return{x:l*r.x+d*n.x+c*o.x+h*a.x,y:l*r.y+d*n.y+c*o.y+h*a.y}}function xt(e,t){return e.map(r=>({closed:r.closed,anchors:r.anchors.map(n=>{let o=t(n);return{x:o.x,y:o.y,...n.in?{in:t(n.in)}:{},...n.out?{out:t(n.out)}:{}}})}))}function Zt(e){let t=1/0,r=1/0,n=-1/0,o=-1/0,a=i=>{t=Math.min(t,i.x),r=Math.min(r,i.y),n=Math.max(n,i.x),o=Math.max(o,i.y)};for(let i of e){for(let d of i.anchors)a(d);let l=pn(i);for(let d=0;d<l;d+=1){let c=hn(i,d);for(let h of qh(c))a(un(c,h))}}if(t!==1/0)return{x:t,y:r,w:n-t,h:o-r}}function qh(e){let[t,r,n,o]=e,a=[];for(let i of["x","y"]){let l=-t[i]+3*r[i]-3*n[i]+o[i],d=2*(t[i]-2*r[i]+n[i]),c=r[i]-t[i];if(Math.abs(l)<1e-12){Math.abs(d)>1e-12&&a.push(-c/d);continue}let h=d*d-4*l*c;if(h<0)continue;let x=Math.sqrt(h);a.push((-d+x)/(2*l),(-d-x)/(2*l))}return a.filter(i=>i>0&&i<1)}function So(e){if(e===void 0)return;let t=e.trim().split(/[\s,]+/).map(Number);if(t.length!==4||t.some(i=>!Number.isFinite(i)))return;let[r,n,o,a]=t;return{x:r,y:n,w:o,h:a}}function Qt(e){return[e.x,e.y,e.w,e.h].map(Q).join(" ")}function mn(e,t,r){return So(e)??{x:0,y:0,w:t,h:r}}function xn(e,t){let r=e.w===0?1:t.w/e.w,n=e.h===0?1:t.h/e.h;return o=>({x:t.x+(o.x-e.x)*r,y:t.y+(o.y-e.y)*n})}function ls(e,t){let r=e.w===0||t.w===0?1:e.w/t.w,n=e.h===0||t.h===0?1:e.h/t.h;return o=>({x:e.x+(o.x-t.x)*r,y:e.y+(o.y-t.y)*n})}function Sf(e,t=.5){let[r,n,o,a]=e;if(Jt(r,n)&&Jt(o,a))return[r,a];let l=Math.hypot(n.x-r.x,n.y-r.y)+Math.hypot(o.x-n.x,o.y-n.y)+Math.hypot(a.x-o.x,a.y-o.y),d=Math.min(256,Math.max(4,Math.ceil(Math.sqrt(l/t)))),c=[];for(let h=0;h<=d;h+=1)c.push(un(e,h/d));return c}function ds(e,t,r){let n=0,o=0;for(let a of e){let i=Kh(a);if(i.length!==0){if(r.reach>0){let l=a.closed?i.length:i.length-1;for(let d=0;d<l;d+=1){let c=i[d],h=i[(d+1)%i.length];if(jh(t,c,h)<=r.reach)return!0}if(i.length===1&&Math.hypot(t.x-i[0].x,t.y-i[0].y)<=r.reach)return!0}if(r.fill)for(let l=0;l<i.length;l+=1){let d=i[l],c=i[(l+1)%i.length];d.y<=t.y!=c.y<=t.y&&d.x+(t.y-d.y)/(c.y-d.y)*(c.x-d.x)>t.x&&(o+=1,n+=c.y>d.y?1:-1)}}}return r.fill?r.rule==="evenodd"?o%2===1:n!==0:!1}function Kh(e){let t=e.anchors[0];if(!t)return[];let r=[{x:t.x,y:t.y}],n=pn(e);for(let o=0;o<n;o+=1)r.push(...Sf(hn(e,o)).slice(1));return e.closed&&r.length>1&&r.pop(),r}function jh(e,t,r){let n=r.x-t.x,o=r.y-t.y,a=n*n+o*o,i=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*o)/a));return Math.hypot(e.x-(t.x+i*n),e.y-(t.y+i*o))}function fs(e,t){let r;return e.forEach((n,o)=>{let a=pn(n);for(let i=0;i<a;i+=1){let l=hn(n,i),d=k=>{let S=un(l,k);return Math.hypot(S.x-t.x,S.y-t.y)},c=32,h=0;for(let k=1;k<=c;k+=1)d(k/c)<d(h)&&(h=k/c);let x=Math.max(0,h-1/c),y=Math.min(1,h+1/c);for(let k=0;k<24;k+=1){let S=x+(y-x)/3,B=y-(y-x)/3;d(S)<d(B)?y=B:x=S}let v=(x+y)/2,D=d(v);(!r||D<r.distance)&&(r={contour:o,segment:i,t:v,point:un(l,v),distance:D})}}),r}function us(e,t,r,n){return e.map((o,a)=>{if(a!==t)return o;let i=[...o.anchors],l=i.length,d=i[r],c=(r+1)%l,h=i[c];if(kf(o,r)){let R={x:d.x+(h.x-d.x)*n,y:d.y+(h.y-d.y)*n};return i.splice(r+1,0,R),{...o,anchors:i}}let[x,y,v,D]=hn(o,r),k=(R,C)=>({x:R.x+(C.x-R.x)*n,y:R.y+(C.y-R.y)*n}),S=k(x,y),B=k(y,v),N=k(v,D),J=k(S,B),E=k(B,N),P=k(J,E);return i[r]=fn({...d,out:S}),i[c]=fn({...h,in:N}),i.splice(r+1,0,fn({x:P.x,y:P.y,in:J,out:E})),{...o,anchors:i}})}var ko=.5522847498;function cs(e,t,r=0){let n=Math.max(0,Math.min(r,e/2,t/2));if(n===0)return[{closed:!0,anchors:[{x:0,y:0},{x:e,y:0},{x:e,y:t},{x:0,y:t}]}];let o=ko*n,a=[{x:n,y:0,in:{x:n-o,y:0}},{x:e-n,y:0,out:{x:e-n+o,y:0}},{x:e,y:n,in:{x:e,y:n-o}},{x:e,y:t-n,out:{x:e,y:t-n+o}},{x:e-n,y:t,in:{x:e-n+o,y:t}},{x:n,y:t,out:{x:n-o,y:t}},{x:0,y:t-n,in:{x:0,y:t-n+o}},{x:0,y:n,out:{x:0,y:n-o}}];return[{closed:!0,anchors:Gh(a)}]}function ps(e,t){let r=e/2,n=t/2,o=ko*r,a=ko*n;return[{closed:!0,anchors:[{x:r,y:0,in:{x:r-o,y:0},out:{x:r+o,y:0}},{x:e,y:n,in:{x:e,y:n-a},out:{x:e,y:n+a}},{x:r,y:t,in:{x:r+o,y:t},out:{x:r-o,y:t}},{x:0,y:n,in:{x:0,y:n+a},out:{x:0,y:n-a}}]}]}function Gh(e){let t=[];for(let o of e){let a=t[t.length-1];if(a&&Jt(a,o)&&!a.out&&!o.in){t[t.length-1]=dt(a,a.in,o.out);continue}t.push(o)}let r=t[0],n=t[t.length-1];return t.length>1&&r&&n&&Jt(r,n)&&!n.out&&!r.in&&(t[0]=dt(r,n.in,r.out),t.pop()),t}var ft=class extends Error{op;constructor(t,r){super(t),this.op=r,this.name="OpError"}};function be(e,t){let r=e,n=[];for(let o of t){let a=Ef(r,o);r=a.document,n.push(a.inverse)}return n.reverse(),{document:r,inverse:n}}function Ef(e,t){switch(t.op){case"set":{let r=q(e.root,t.id);if(!r)throw new ft(`No node ${t.id}`,t);let n=r[t.prop];return{document:_o(e,ms(e.root,t.id,o=>Wh(o,t.prop,t.value),t)),inverse:{op:"set",id:t.id,prop:t.prop,value:n}}}case"insert":{if(q(e.root,t.node.id))throw new ft(`Duplicate id ${t.node.id}`,t);let r=Co(e.root,t.parent,n=>{let o=Cf(t.index,0,n.length);return[...n.slice(0,o),t.node,...n.slice(o)]},t);return{document:_o(e,r),inverse:{op:"remove",id:t.node.id}}}case"remove":{let r=_f(e,t.id,t),n=Co(e.root,r.parent.id,o=>o.filter(a=>a.id!==t.id),t);return{document:_o(e,n),inverse:{op:"insert",parent:r.parent.id,index:r.index,node:r.node}}}case"move":{let r=_f(e,t.id,t),n=Co(e.root,r.parent.id,a=>a.filter(i=>i.id!==t.id),t),o=Co(n,t.parent,a=>{let i=Cf(t.index,0,a.length);return[...a.slice(0,i),r.node,...a.slice(i)]},t);return{document:_o(e,o),inverse:{op:"move",id:t.id,parent:r.parent.id,index:r.index}}}case"setTitle":{let{title:r,...n}=e;return{document:t.value===void 0?n:{...n,title:t.value},inverse:{op:"setTitle",value:r}}}case"setToken":{let r=Object.prototype.hasOwnProperty.call(e.tokens,t.name)?e.tokens[t.name]:void 0,n={...e.tokens};return t.value===void 0?delete n[t.name]:n[t.name]=t.value,{document:{...e,tokens:n},inverse:{op:"setToken",name:t.name,value:r}}}case"setAsset":{let r=Object.prototype.hasOwnProperty.call(e.assets,t.name)?e.assets[t.name]:void 0,n={...e.assets};return t.value===void 0?delete n[t.name]:n[t.name]=t.value,{document:{...e,assets:n},inverse:{op:"setAsset",name:t.name,value:r}}}case"setFont":{let r=Object.prototype.hasOwnProperty.call(e.fonts,t.name)?e.fonts[t.name]:void 0,n={...e.fonts};return t.family===void 0?delete n[t.name]:n[t.name]=t.family,{document:{...e,fonts:n},inverse:{op:"setFont",name:t.name,family:r}}}case"setMotion":{let r=e.motion&&Object.prototype.hasOwnProperty.call(e.motion,t.page)?e.motion[t.page]:void 0,n={...e.motion};return ht(t.value)?delete n[t.page]:n[t.page]=t.value,{document:as(e,n),inverse:{op:"setMotion",page:t.page,value:r}}}}}function Eo(e,t){if(!e.motion||!t.some(n=>n.op==="remove"||n.op==="move"))return t;let r=ss(e,be(e,t).document);return r.length===0?t:[...t,...r]}function _o(e,t){if(t.type!=="canvas")throw new Error("The document root must stay a canvas");return{...e,root:t}}function Wh(e,t,r){let n={...e};return r===void 0?delete n[t]:n[t]=r,n}function ms(e,t,r,n){if(e.id===t)return r(e);if(!pe(e))return e;let o=!1,a=e.children.map(i=>{let l=ms(i,t,r,n);return l!==i&&(o=!0),l});return o?{...e,children:a}:e}function Co(e,t,r,n){let o=q(e,t);if(!o)throw new ft(`No node ${t}`,n);if(!pe(o))throw new ft(`${t} cannot hold children`,n);return ms(e,t,a=>({...a,children:r(a.children)}),n)}function _f(e,t,r){if(t===e.root.id)throw new ft("The document root cannot be removed or moved",r);let n,o=a=>{pe(a)&&a.children.forEach((i,l)=>{i.id===t&&(n={node:i,parent:a,index:l}),o(i)})};if(o(e.root),!n)throw new ft(`No node ${t}`,r);return n}function Cf(e,t,r){return Math.min(Math.max(e,t),r)}function xs(e,t){let r=[];e.title!==t.title&&r.push({op:"setTitle",value:t.title});for(let a of _r(e.tokens,t.tokens)){let i=t.tokens[a];e.tokens[a]!==i&&r.push({op:"setToken",name:a,value:i})}for(let a of _r(e.fonts,t.fonts)){let i=t.fonts[a];Yh(e.fonts[a],i)||r.push({op:"setFont",name:a,family:i})}for(let a of _r(e.assets,t.assets)){let i=t.assets[a];e.assets[a]?.hash!==i?.hash&&r.push({op:"setAsset",name:a,value:i})}if(!Xh(e.root.children,t.root.children)){for(let a of e.root.children)r.push({op:"remove",id:a.id});t.root.children.forEach((a,i)=>{r.push({op:"insert",parent:e.root.id,index:i,node:a})})}for(let a of _r(e.motion??{},t.motion??{})){let i=t.motion?.[a];yo(e.motion?.[a],i)||r.push({op:"setMotion",page:a,value:i})}let n=e.root,o=t.root;for(let a of _r(n,o))a==="type"||a==="id"||a==="children"||Mf(n[a],o[a])||r.push({op:"set",id:e.root.id,prop:a,value:o[a]});return r}function _r(e,t){return[...new Set([...Object.keys(e),...Object.keys(t)])]}function Mf(e,t){return e===t?!0:me(e)&&me(t)&&e.expr===t.expr}function Xh(e,t){return e.length===t.length&&e.every((r,n)=>hs(r,t[n]))}function hs(e,t){if(Mf(e,t))return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((a,i)=>hs(a,t[i]));let r=e,n=t;return _r(r,n).every(a=>hs(r[a],n[a]))}function Yh(e,t){if(e===t)return!0;if(!e||!t||e.family!==t.family||e.fallback!==t.fallback)return!1;let r=e.faces??[],n=t.faces??[];return r.length===n.length&&r.every((o,a)=>{let i=n[a];return o.src===i.src&&o.weight===i.weight&&o.style===i.style})}var gn={canvas:[["name","string"],["w","numberValue"],["h","numberValue"],["background","stringValue"]],frame:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["background","stringValue"],["clip","boolean"],["skip","boolean"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],group:[["name","string"],["hidden","boolean"],["locked","boolean"]],ellipse:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],vector:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["view","string"],["d","string"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["opacity","numberValue"],["rule","fillRule"],["cap","lineCap"],["join","lineJoin"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],rect:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["radius","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],image:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["src","stringValue"],["fit","imageFit"],["radius","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],text:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["font","stringValue"],["size","numberValue"],["weight","numberValue"],["lineHeight","numberValue"],["letterSpacing","numberValue"],["align","align"],["valign","valign"],["italic","boolean"],["fill","stringValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]]},yn=[["font","string"],["size","number"],["weight","number"],["italic","boolean"],["underline","boolean"],["strike","boolean"],["fill","string"],["letterSpacing","number"],["link","string"]],gs=[["weight","number"],["style","fontStyle"]],Mo=[["enter","pageEffect"],["duration","number"],["scroll","boolean"]],vn=[["enter","nodeEffect"],["exit","nodeEffect"],["duration","number"],["delay","number"],["step","boolean"],["together","boolean"],["go","string"]],Tf=Object.keys(gn);function Ao(e){return Tf.includes(e)}function ys(e,t){return gn[e].find(([r])=>r===t)?.[1]}var er=" ";function Ze(e){if(me(e))return/^[$@]/.test(e.expr)&&!/\s/.test(e.expr)?e.expr:`(${e.expr})`;if(typeof e=="number")return Q(e);let t=String(e);return Jh(t)?JSON.stringify(t):t}function Jh(e){return e===""||/[\s"=()]/.test(e)||/^[$@]/.test(e)}function qe(e,t){if(t==="boolean")return e===""||e==="true"?{value:!0}:e==="false"?{value:!1}:{error:`Expected true or false, got ${e}`};if(e.startsWith('"')){let n=Er(e);return n===void 0?{error:`Malformed quoted string ${e}`}:Af(n,t,e)}if(tm(e)){if(!Zh(t))return{error:Qh(e,t)};let n=Of(e).trim();return n===""?{error:"Empty expression"}:{value:Et(n)}}return t==="numberValue"&&Lf.test(e)?{value:Et(e)}:Af(e,t,e)}var Lf=/^-?\d+(?:\.\d+)?%$/;function Zh(e){return e==="numberValue"||e==="stringValue"}function Qh(e,t){return t==="number"?`Expected a plain number, not an expression, got ${e}`:t==="string"&&/^\$\w+$/.test(e)?`Expected a literal, got ${e} \u2014 name a token without the $: ${e.slice(1)}`:`Expected a literal, not an expression, got ${e} \u2014 quote it if you meant the text`}function em(e,t){let r=/^(-?\d+(?:\.\d+)?)([A-Za-z]+)$/.exec(e);return r?r[2]==="s"&&t==="number"?` \u2014 durations are milliseconds: ${Number(r[1])*1e3}`:/^(?:px|pt|deg|ms)$/.test(r[2])?` \u2014 drop the unit: ${r[1]}`:" \u2014 units are not supported: use a number, a percentage like (100%), or an expression":t==="number"?Lf.test(e)?" \u2014 a percentage is not allowed here":"":/^-[$@(]/.test(e)?` \u2014 wrap an expression in parentheses: (${e})`:/^-?[A-Za-z_]\w*(?:\.\w+)+$/.test(e)?` \u2014 wrap an expression in parentheses: (${e})`:""}function Af(e,t,r){switch(t){case"numberValue":case"number":{let n=Number(e);return Number.isFinite(n)&&e.trim()!==""?{value:n}:{error:`Expected a number, got ${r}${em(e,t)}`}}case"align":return Mt.includes(e)?{value:e}:{error:`Expected one of ${Mt.join(", ")}, got ${r}`};case"valign":return At.includes(e)?{value:e}:{error:`Expected one of ${At.join(", ")}, got ${r}`};case"fontStyle":return e==="normal"||e==="italic"?{value:e}:{error:`Expected normal or italic, got ${r}`};case"imageFit":return $t.includes(e)?{value:e}:{error:`Expected one of ${$t.join(", ")}, got ${r}`};case"fillRule":return Cr(jt,e,r);case"lineCap":return Cr(Gt,e,r);case"lineJoin":return Cr(Wt,e,r);case"blendMode":return Cr(Kt,e,r);case"pageEffect":return Cr(br,e,r);case"nodeEffect":return Cr(dn,e,r);default:return{value:e}}}function Cr(e,t,r){return e.includes(t)?{value:t}:{error:`Expected one of ${e.join(", ")}, got ${r}`}}function tm(e){return/^[$@(]/.test(e)}function Er(e){try{let t=JSON.parse(e);return typeof t=="string"?t:void 0}catch{return}}function Of(e){if(!e.startsWith("("))return e;let t=0;for(let r=0;r<e.length;r+=1){let n=e[r];if(n==="(")t+=1;else if(n===")"&&(t-=1,t===0))return r===e.length-1?e.slice(1,-1):e}return e}function Df(e){let t=[],r="",n=0,o=!1;for(let a=0;a<e.length;a+=1){let i=e[a];if(o){r+=i,i==="\\"?(r+=e[a+1]??"",a+=1):i==='"'&&(o=!1);continue}if(i==='"'){o=!0,r+=i;continue}if(i==="("?n+=1:i===")"&&(n=Math.max(0,n-1)),n===0&&/\s/.test(i)){r!==""&&t.push(r),r="";continue}r+=i}return r!==""&&t.push(r),t}function vs(e,t,r){let n=r===void 0?void 0:Ke(r);if(n?.value===void 0||!$f(e[t]??""))return;let o=t;for(;o<e.length&&$f(e[o]??"");)o+=1;let a=[Of(n.value),...e.slice(t,o)].join(" ");return{end:o,message:`${n.key}: an expression with spaces needs parentheses \u2014 write ${n.key}=(${a})`}}function $f(e){return!e.includes("=")&&/^(?:[-+*/]|-?\d+(?:\.\d+)?%?|[$@][\w.]*|[A-Za-z_]\w*(?:\.\w+)+|\(.*|.*\))$/.test(e)}function Ke(e){let t=e.indexOf("=");return t===-1?{key:e,value:void 0}:{key:e.slice(0,t),value:e.slice(t+1)}}var rm=new Set(["exit","delay","step","together","go"]);function bs(e,t){let r=e.words[1];if(r===void 0||r.includes("=")){t(e.number,"invalid-motion","Expected motion <page>, e.g. motion intro enter=fade");return}let n={};for(let o of e.words.slice(2)){let{key:a,value:i}=Ke(o),l=Mo.find(([c])=>c===a)?.[1];if(l===void 0){let c=rm.has(a)?` \u2014 ${a} goes on a node's line, under the header`:"";t(e.number,"invalid-motion",`motion ${r} has no "${a}"${c}`,r);continue}let d=qe(i??"",l);"error"in d?t(e.number,"invalid-motion",`${a}: ${d.error}`,r):a==="duration"&&!Nf(d.value)?t(e.number,"invalid-motion",Rf(a,i),r):d.value!==!1&&(n[a]=d.value)}return{page:r,number:e.number,head:n,lines:[],where:new Map,taken:new Map}}function ws(e,t,r){let n=t.words[0];if(t.indent!==1){r(t.number,"invalid-motion","A motion line sits one level under its page");return}if(n.includes("=")){r(t.number,"invalid-motion",`Expected a node id first, got ${n}`);return}if(n===e.page){r(t.number,"invalid-motion",`${n} is the page: its transition goes on the header (motion ${n} enter=fade)`,n);return}let o={id:n},a=!0;for(let l of t.words.slice(1)){let{key:d,value:c}=Ke(l),h=vn.find(([y])=>y===d)?.[1];if(h===void 0){r(t.number,"invalid-motion",`A motion line has no "${d}"`,n),a=!1;continue}let x=qe(c??"",h);"error"in x?(r(t.number,"invalid-motion",`${d}: ${x.error}`,n),a=!1):(d==="duration"||d==="delay")&&!Nf(x.value)?(r(t.number,"invalid-motion",Rf(d,c),n),a=!1):d==="go"&&pt(x.value)===void 0?(r(t.number,"invalid-motion",`go: expected #<page>, back, next, or an https: or mailto: link, got ${c??""}`,n),a=!1):x.value!==!1&&(o[d]=x.value)}if(o.enter!==void 0&&o.exit!==void 0&&(r(t.number,"invalid-motion",`${n} either enters or exits on one line \u2014 write a second line for the other`,n),a=!1),o.step===!0&&o.together===!0&&(r(t.number,"invalid-motion",`${n} waits for a step or starts together with the line above, not both`,n),a=!1),!a)return;let i=nm(o);if(!wr(i)){r(t.number,"invalid-motion",`${n} says nothing: give it enter=, exit= or go=`,n);return}for(let l of["enter","exit","go"]){if(i[l]===void 0)continue;let d=e.taken.get(`${n} ${l}`);if(d!==void 0){let c=l==="go"?"has a go=":l==="enter"?"enters":"exits";r(t.number,"invalid-motion",`${n} already ${c} on line ${d}`,n);return}}for(let l of["enter","exit","go"])i[l]!==void 0&&e.taken.set(`${n} ${l}`,t.number);e.where.has(n)||e.where.set(n,t.number),e.lines.push(i)}function ks(e){let t={...e.head.enter===void 0?{}:{enter:e.head.enter},...e.head.duration===void 0?{}:{duration:e.head.duration},...e.head.scroll===!0?{scroll:!0}:{},lines:e.lines};return ht(t)?void 0:t}function Pf(e,t){let r=t.motion;if(r)for(let n of kr(t)){let o=r[n];if(o===void 0||ht(o))continue;e.at(-1)!==""&&e.push("");let a=["motion",n];for(let[i,l]of Mo){let d=o[i];if(d!==void 0){if(l==="boolean"){d===!0&&a.push(i);continue}a.push(`${i}=${Ze(d)}`)}}e.push(a.join(" "));for(let i of o.lines){let l=[i.id];for(let[d,c]of vn){let h=i[d];if(h!==void 0){if(c==="boolean"){h===!0&&l.push(d);continue}l.push(`${d}=${Ze(h)}`)}}e.push(er+l.join(" "))}}}function nm(e){let t={id:e.id};for(let[r]of vn)e[r]!==void 0&&(t[r]=e[r]);return t}function Nf(e){return typeof e=="number"&&e>=0&&e<=Yt}function Rf(e,t){return`${e}: expected 0 to ${Yt} milliseconds, got ${t??""}`}var om=24;function _s(e,t={}){let r=[`version ${Q(e.version)}`,`kind ${e.kind}`];e.title!==void 0&&r.push(`title ${JSON.stringify(e.title)}`);for(let[n,o]of Object.entries(e.tokens))r.push(`$${n} = ${Ze(o)}`);r.push("");for(let[n,o]of Object.entries(e.fonts))im(r,n,o,t),r.push("");if(Object.keys(e.assets).length>0){for(let[n,o]of Object.entries(e.assets))r.push(sm(n,o));r.push("")}return am(e.root)?e.root.children.forEach((n,o)=>{o>0&&r.push(""),Ss(r,n,0)}):Ss(r,e.root,0),Pf(r,e),r.join(`
29
+ `)}function am(e){return e.id===lt&&e.w===void 0&&e.h===void 0&&e.background===void 0&&e.name===void 0}function sm(e,t){let r=[`asset ${e} = ${t.type}`,`hash=${t.hash}`,`bytes=${Q(t.bytes)}`];for(let n of["credit","source","license"]){let o=t[n];o!==void 0&&r.push(`${n}=${Ze(o)}`)}return r.join(" ")}function im(e,t,r,n){e.push(`font ${t} = ${Ze(r.family)}`),r.fallback!==void 0&&e.push(`${er}fallback ${Ze(r.fallback)}`);for(let o of r.faces??[]){let a=n.abbreviateFaces?lm(o.src):o.src,i=[`face ${Ze(a)}`];for(let[l]of gs){let d=o[l];d!==void 0&&i.push(`${l}=${Ze(d)}`)}e.push(er+i.join(" "))}}function lm(e){return e.startsWith("data:")?`${e.slice(0,om)}\u2026 ${Q(Math.round(e.length/1024))} kB`:e}function Ss(e,t,r){let n=er.repeat(r),o=t,a=[t.type,t.id];for(let[i,l]of gn[t.type]){let d=o[i];if(d!==void 0){if(l==="boolean"){d===!0&&a.push(i);continue}a.push(`${i}=${Ze(d)}`)}}if(e.push(n+a.join(" ")),t.type==="text"&&dm(e,t.content,r+1),pe(t))for(let i of ae(t))Ss(e,i,r+1)}function dm(e,t,r){let n=er.repeat(r),o=typeof t=="string"?[t]:t;for(let a of o){if(typeof a=="string"){e.push(n+JSON.stringify(a));continue}e.push(n+[JSON.stringify(a.text),...fm(a)].join(" "))}}function fm(e){let t=[];for(let[r,n]of yn){let o=e[r];if(o!==void 0){if(n==="boolean"){o===!0&&t.push(r);continue}t.push(`${r}=${Ze(o)}`)}}return t}var tr="--- payload base64 ---",If="sha256-";function Ff(e){let t=um(e);return t===-1?{head:e,payload:""}:{head:e.slice(0,t),payload:e.slice(t+tr.length)}}function Cs(e){let{head:t,payload:r}=Ff(e);return{head:t,blocks:Bf(r)}}function Es(e,t){let r=new Map;for(let n of cm(e)){let o=t.get(n);o!==void 0&&r.set(n,o)}return r.size===0?e:`${e.trimEnd()}
30
30
 
31
- ${If(r)}`}function Rf(e){let t=new Map;for(let r of e.split(`
32
- `)){let n=r.indexOf(" ");if(n===-1)continue;let o=r.slice(0,n);o.startsWith(Pf)&&t.set(o,r.slice(n+1).trim())}return t}function If(e){let t=[...e.entries()].sort(([r],[n])=>r<n?-1:r>n?1:0).map(([r,n])=>`${r} ${n}`);return`${Zt}
31
+ ${Hf(r)}`}function Bf(e){let t=new Map;for(let r of e.split(`
32
+ `)){let n=r.indexOf(" ");if(n===-1)continue;let o=r.slice(0,n);o.startsWith(If)&&t.set(o,r.slice(n+1).trim())}return t}function Hf(e){let t=[...e.entries()].sort(([r],[n])=>r<n?-1:r>n?1:0).map(([r,n])=>`${r} ${n}`);return`${tr}
33
33
  ${t.join(`
34
34
  `)}
35
- `}async function Ss(e){let t=await crypto.subtle.digest("SHA-256",e),r=[...new Uint8Array(t)].map(n=>n.toString(16).padStart(2,"0"));return`${Pf}${r.join("")}`}function _s(e,t){return`data:${e};base64,${t}`}function Cs(e){let t=e.toBase64;if(typeof t=="function")return t.call(e);let r="";for(let n=0;n<e.length;n+=32768)r+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(r)}function Es(e){let t=Uint8Array.fromBase64;if(typeof t=="function")return t(e);let r=atob(e),n=new Uint8Array(r.length);for(let o=0;o<r.length;o+=1)n[o]=r.charCodeAt(o);return n}function am(e){if(e.startsWith(Zt))return 0;let t=e.indexOf(`
36
- ${Zt}`);return t===-1?-1:t+1}function sm(e){let t=new Set;for(let r of e.matchAll(/sha256-[0-9a-f]{64}/g))t.add(r[0]);return t}function As(e){return(t,r,n,o)=>{e.push({severity:"error",code:r,message:`Line ${t}: ${n}`,...o===void 0?{}:{nodeId:o}})}}function Ms(e){let t=[],r=e.split(`
37
- `);for(let n=0;n<r.length;n+=1){let o=r[n],a=o.trim();if(a===Zt)break;if(a===""||a.startsWith("```"))continue;let i=o.length-o.trimStart().length;t.push({number:n+1,indent:Math.floor(i/2),text:a,words:Tf(a)})}return t}function $s(e){let t=[],r=[],n=o=>{for(;t.length>0&&t[t.length-1].indent>=o;)lm(t.pop())};return{push(o){let a=o.words[0];if(a.startsWith('"')){let c=t[t.length-1];if(!c||c.type!=="text")return e(o.number,"invalid-content","A quoted line must sit inside a text node"),!0;let h=fm(o,e);return h!==void 0&&c.runs.push(h),!0}if(!ko(a))return!1;n(o.indent);let i=o.words[1];if(i===void 0||i.includes("="))return e(o.number,"missing-id",`A ${a} needs an id`),!0;let l=im(a,i,o.words.slice(2),o,e),d=t[t.length-1];return d?d.children.push(l.record):r.push(l.record),t.push(l),!0},finish(){return n(0),r}}}function im(e,t,r,n,o){let a={type:e,id:t},i=[];for(let l=0;l<r.length;l+=1){let{key:d,value:c}=He(r[l]),h=hs(e,d);if(h===void 0){let y=ms(r,l,r[l-1]);y?(o(n.number,"invalid-value",y.message,t),l=y.end-1):o(n.number,"invalid-value",`${e} has no property "${d}"`,t);continue}let x=Be(c??"",h);"error"in x?o(n.number,"invalid-value",`${d}: ${x.error}`,t):a[d]=x.value}return so(e)&&(a.children=i),e==="text"&&(a.content=""),{indent:n.indent,type:e,record:a,children:i,runs:[]}}function lm(e){e.type==="text"&&(e.record.content=dm(e.runs))}function dm(e){if(e.length===0)return"";let t=e[0];return e.length===1&&typeof t=="string"?t:[...e]}function fm(e,t){let r=wr(e.words[0]);if(r===void 0){t(e.number,"invalid-run","Malformed quoted string");return}if(e.words.length===1)return r;let n={text:r};for(let o of e.words.slice(1)){let{key:a,value:i}=He(o),l=pn.find(([c])=>c===a);if(!l){t(e.number,"invalid-run",`A run has no mark "${a}"`);continue}let d=Be(i??"",l[1]);"error"in d?t(e.number,"invalid-run",`${a}: ${d.error}`):n[a]=d.value}return n}function So(e){let t=[],r=As(t),n=At,o,a=!1,i={},l={},d={},c=$s(r),h,x={},y=new Map,b,P=!1,k=()=>{if(!b)return;let E=b;b=void 0;let D=y.get(E.page);if(D!==void 0){r(E.number,"invalid-motion",`motion ${E.page} is written twice \u2014 put its lines in the block on line ${D}`,E.page);return}y.set(E.page,E.number);for(let[A,G]of E.where)y.set(`${E.page} ${A}`,G);let N=ys(E);N&&(x[E.page]=N)};for(let E of Ms(e)){let D=E.words[0];if(b&&E.indent>0){gs(b,E,r);continue}if(!(P&&E.indent>0)){if(P=!1,k(),D==="motion"&&E.indent===0){h=void 0,b=xs(E,r),P=b===void 0;continue}if(D==="version"){a=!0,cm(E,t);continue}if(D==="kind"&&E.indent===0){n=pm(E,t);continue}if(D==="title"&&E.indent===0){o=Ff(E,r);continue}if(D.startsWith("$")){h=void 0,hm(E,i,r);continue}if(D==="asset"&&E.indent===0){h=void 0,mm(E,d,r);continue}if(D==="font"&&E.indent===0){h=gm(E,l,r);continue}if((D==="fallback"||D==="face")&&h){ym(D,E,h,r);continue}h=void 0,!c.push(E)&&r(E.number,"unknown-node-type",`Unknown statement "${D}"`)}}k();let _=um(c.finish(),t),B=Object.keys(x).length===0?{}:{motion:x},R=(E,D)=>y.get(D===void 0?E:`${E} ${D}`);if(!_){a||t.push({severity:"error",code:"invalid-document",message:"No nodes found"});let E=pr({id:ot,children:[]}),D=rn({kind:n,...o===void 0?{}:{title:o},tokens:i,fonts:l,assets:d,...B,root:E});return t.push(...yr(D,R)),{document:D,problems:t}}let J={version:4,kind:n,...o===void 0?{}:{title:o},tokens:i,fonts:l,assets:d,...B,root:_};return t.push(...yr(J,R)),{document:J,problems:t}}function um(e,t){let r=e[0];if(r!==void 0){if(e.length===1&&r.type==="canvas")return r;for(let n of e){if(n.type!=="canvas")continue;let o=n.id;t.push({severity:"error",code:"invalid-document",message:"A canvas must be the only top-level node",...typeof o=="string"?{nodeId:o}:{}})}return{type:"canvas",id:ot,children:[...e]}}}function cm(e,t){tn.includes(Number(e.words[1]))||t.push({severity:"warning",code:"version-mismatch",message:`Line ${e.number}: expected version ${4} or older, got ${e.words[1]??"nothing"}`})}function pm(e,t){let r=e.words[1];return r!==void 0&&jt.includes(r)?r:(t.push({severity:"error",code:"unknown-kind",message:`Line ${e.number}: unknown kind "${r??"nothing"}" \u2014 this build reads ${jt.join(", ")}`}),At)}function Ff(e,t){let r=e.words.slice(1).join(" ").trim();if(r===""){t(e.number,"invalid-value",'title needs a name, e.g. title "Pitch deck"');return}let n=r.startsWith('"')?wr(r):r;if(n===void 0){t(e.number,"invalid-value",`Could not read the title ${r}`);return}return n.trim()===""?void 0:n}function hm(e,t,r){let{name:n,value:o}=Ts(e.words);if(n===void 0||o===void 0){r(e.number,"invalid-token","Expected $name = value");return}if(!o.startsWith('"')&&/\s/.test(o)){r(e.number,"invalid-token",`$${n}: expected one value, got "${o}". Quote it if the value has spaces; there are no comments.`);return}let a=Be(o,"stringValue");if("error"in a){r(e.number,"invalid-token",`$${n}: ${a.error}`);return}if(typeof a.value!="string"){r(e.number,"invalid-token",`$${n} may not be an expression`);return}t[n]=Bf(a.value,o)}function Bf(e,t){let r=Number(e);return t.startsWith('"')||!Number.isFinite(r)||e.trim()===""?e:r}function Ts(e){let t=e[0],r=a=>a.startsWith("$")?a.slice(1):a;if(e[1]==="=")return{name:r(t),value:e.slice(2).join(" ")||void 0};let{key:n,value:o}=He(t);return o!==void 0?{name:r(n),value:o}:{name:r(t)}}function mm(e,t,r){let n=e.words.slice(1),o=n[0],a=n[1]==="=",i=o===void 0?void 0:He(o),l=i?.key,d=a?n[2]:i?.value,c=n.slice(a?3:1);if(l===void 0||l===""||d===void 0){r(e.number,"invalid-asset","Expected asset <name> = <type> hash=\u2026 bytes=\u2026");return}let h={};for(let b of c){let{key:P,value:k}=He(b);if(k===void 0){r(e.number,"invalid-asset",`Asset "${l}" has a stray word "${b}"`);continue}h[P]=xm(k)}let x=h.hash,y=Number(h.bytes);if(x===void 0||!Number.isFinite(y)){r(e.number,"invalid-asset",`Asset "${l}" needs a hash and a bytes count`);return}t[l]={type:d,hash:x,bytes:y,...h.credit===void 0?{}:{credit:h.credit},...h.source===void 0?{}:{source:h.source},...h.license===void 0?{}:{license:h.license}}}function xm(e){return e.startsWith('"')?wr(e)??e:e}function gm(e,t,r){let{name:n,value:o}=Ts(e.words.slice(1));if(n===void 0||o===void 0){r(e.number,"invalid-font","Expected font <name> = <family>");return}let a=Be(o,"string"),i={family:"error"in a?o:a.value};return t[n]=i,{family:i,faces:[]}}function ym(e,t,r,n){if(e==="fallback"){let l=Be(t.words.slice(1).join(" "),"string");"error"in l?n(t.number,"invalid-font",`fallback: ${l.error}`):r.family.fallback=l.value;return}let o=t.words[1];if(o===void 0){n(t.number,"invalid-font-face","A face needs a src");return}let a=Be(o,"string"),i={src:"error"in a?o:a.value};for(let l of t.words.slice(2)){let{key:d,value:c}=He(l);if(d!=="weight"&&d!=="style"){n(t.number,"invalid-font-face",`A face has no property "${d}"`);continue}let h=Be(c??"",d==="weight"?"number":"fontStyle");"error"in h?n(t.number,"invalid-font-face",`${d}: ${h.error}`):i[d]=h.value}r.faces.push(i),r.family.faces=r.faces}function Ds(e){let t=[],r=Ue(e);if(!r)return t.push({severity:"error",code:"invalid-document",message:"Expected an object"}),{document:rn(),problems:t};tn.includes(r.version)||t.push({severity:"warning",code:"version-mismatch",message:`Expected version ${4} or older, got ${JSON.stringify(r.version)}`});let n=Uf(r.root,t),o=vm(r.motion,t),a={version:4,kind:wm(r.kind,t),...typeof r.title=="string"&&r.title.trim()!==""?{title:r.title}:{},tokens:km(r.tokens,t),fonts:_m(r.fonts,t),assets:Sm(r.assets,t),...o===void 0?{}:{motion:o},root:n??pr({id:ot,children:[]})};return Rm(a.root,t),t.push(...yr(a)),{document:a,problems:t}}function vm(e,t){if(e===void 0)return;let r=Ue(e),n=a=>{t.push({severity:"error",code:"invalid-motion",message:a})};if(!r){n("`motion` must be an object");return}let o={};for(let[a,i]of Object.entries(r)){let l=Ue(i);if(!l||!Array.isArray(l.lines)){n(`motion ${a} must be an object with a lines array`);continue}let d=l.enter,c=l.duration;if(d!==void 0&&!mr.includes(d)){n(`motion ${a}: enter must be one of ${mr.join(", ")}`);continue}if(c!==void 0&&!Ls(c)){n(`motion ${a}: duration must be 0 to ${Gt} milliseconds`);continue}let h=l.lines.flatMap(y=>{let b=bm(y);return b===void 0&&n(`motion ${a}: a line that is not one: ${JSON.stringify(y)}`),b===void 0?[]:[b]}),x={...d===void 0?{}:{enter:d},...c===void 0?{}:{duration:c},lines:h};ft(x)||(o[a]=x)}return Object.keys(o).length===0?void 0:o}function bm(e){let t=Ue(e);if(!t||typeof t.id!="string")return;let{enter:r,exit:n,duration:o,delay:a,step:i,together:l,go:d}=t,c=x=>x===void 0||nn.includes(x);if(!c(r)||!c(n)||r!==void 0&&n!==void 0||o!==void 0&&!Ls(o)||a!==void 0&&!Ls(a)||i!==void 0&&i!==!0||l!==void 0&&l!==!0||i===!0&&l===!0||d!==void 0&&(typeof d!="string"||dt(d)===void 0))return;let h={id:t.id,...r===void 0?{}:{enter:r},...n===void 0?{}:{exit:n},...o===void 0?{}:{duration:o},...a===void 0?{}:{delay:a},...i===void 0?{}:{step:i},...l===void 0?{}:{together:l},...d===void 0?{}:{go:d}};return xr(h)?h:void 0}function Ls(e){return typeof e=="number"&&e>=0&&e<=Gt}function wm(e,t){return e==null?At:typeof e=="string"&&jt.includes(e)?e:(t.push({severity:"error",code:"unknown-kind",message:`Unknown kind ${JSON.stringify(e)} \u2014 this build reads ${jt.join(", ")}`}),At)}function km(e,t){let r={};if(e===void 0)return r;let n=Ue(e);if(!n)return t.push({severity:"error",code:"invalid-tokens",message:"`tokens` must be an object"}),r;for(let[o,a]of Object.entries(n))typeof a=="number"||typeof a=="string"?r[o]=a:t.push({severity:"error",code:"invalid-token",message:`Token $${o} must be a number or string`});return r}function Sm(e,t){let r={};if(e===void 0)return r;let n=Ue(e);if(!n)return t.push({severity:"error",code:"invalid-assets",message:"`assets` must be an object"}),r;for(let[o,a]of Object.entries(n)){let i=Ue(a);if(!i||typeof i.type!="string"||typeof i.hash!="string"||typeof i.bytes!="number"){t.push({severity:"error",code:"invalid-asset",message:`Asset "${o}" must have a "type", a "hash" and a "bytes" count`});continue}r[o]={type:i.type,hash:i.hash,bytes:i.bytes,...We(i.credit,"credit"),...We(i.source,"source"),...We(i.license,"license")}}return r}function _m(e,t){let r={};if(e===void 0)return r;let n=Ue(e);if(!n)return t.push({severity:"error",code:"invalid-fonts",message:"`fonts` must be an object"}),r;for(let[o,a]of Object.entries(n)){let i=Ue(a);if(!i||typeof i.family!="string"){t.push({severity:"error",code:"invalid-font",message:`Font "${o}" must be an object with a "family"`});continue}r[o]={family:i.family,...typeof i.fallback=="string"?{fallback:i.fallback}:{},...Cm(i.faces,o,t)}}return r}function Cm(e,t,r){if(e===void 0)return{};if(!Array.isArray(e))return r.push({severity:"error",code:"invalid-font",message:`Font "${t}" has a "faces" that is not an array`}),{};let n=[];for(let o of e){let a=Ue(o);if(!a||typeof a.src!="string"){r.push({severity:"error",code:"invalid-font-face",message:`A face of font "${t}" is missing its "src"`});continue}let i=a.style;n.push({src:a.src,...typeof a.weight=="number"?{weight:a.weight}:{},...i==="italic"||i==="normal"?{style:i}:{}})}return n.length>0?{faces:n}:{}}function Em(e,t){let r=Ue(e);if(!r){t.push({severity:"error",code:"invalid-node",message:"Expected a node object"});return}switch(r.type){case"canvas":return Uf(e,t);case"ellipse":return Lm(r,t);case"frame":return Am(r,t);case"group":return Mm(r,t);case"image":return $m(r,t);case"rect":return Tm(r,t);case"text":return Dm(r,t);case"vector":return Om(r,t);default:t.push({severity:"error",code:"unknown-node-type",message:`Unknown node type ${JSON.stringify(r.type)}`,...typeof r.id=="string"?{nodeId:r.id}:{}});return}}function Uf(e,t){let r=Ue(e);if(!r){t.push({severity:"error",code:"invalid-node",message:"`root` must be a canvas node"});return}let n=Mt(r,ot,t);return{type:"canvas",id:n,...We(r.name,"name"),...Hf(r,"w",1280,n,t),...Hf(r,"h",720,n,t),...Xe(r.background,n,"background",t),children:Ps(r.children,n,t)}}function Hf(e,t,r,n,o){return e[t]===void 0?{}:{[t]:xe(e[t],n,t,r,o)}}function Am(e,t){let r=Mt(e,"frame",t);return{type:"frame",id:r,...We(e.name,"name"),x:xe(e.x,r,"x",0,t),y:xe(e.y,r,"y",0,t),w:xe(e.w,r,"w",0,t),h:xe(e.h,r,"h",0,t),...Xe(e.background,r,"background",t),...Os(e.clip,"clip"),...Os(e.skip,"skip"),..._r(e,r,t),...Qt(e),children:Ps(e.children,r,t)}}function Mm(e,t){let r=Mt(e,"group",t);return{type:"group",id:r,...We(e.name,"name"),...Qt(e),children:Ps(e.children,r,t)}}function Ps(e,t,r){let n=[];if(Array.isArray(e))for(let o of e){let a=Em(o,r);a&&n.push(a)}else e!==void 0&&r.push({severity:"error",code:"invalid-children",message:"`children` must be an array",nodeId:t});return n}function $m(e,t){let r=Mt(e,"image",t),n=e.fit,o=Xe(e.src,r,"src",t);return{type:"image",id:r,...We(e.name,"name"),x:xe(e.x,r,"x",0,t),y:xe(e.y,r,"y",0,t),w:xe(e.w,r,"w",100,t),h:xe(e.h,r,"h",100,t),...Ce(e.rotation,r,"rotation",t),src:o.src??"",...Et.includes(n)?{fit:n}:{},...Ce(e.radius,r,"radius",t),...Ce(e.opacity,r,"opacity",t),..._r(e,r,t),...Qt(e)}}function Tm(e,t){let r=Mt(e,"rect",t);return{type:"rect",id:r,...We(e.name,"name"),x:xe(e.x,r,"x",0,t),y:xe(e.y,r,"y",0,t),w:xe(e.w,r,"w",100,t),h:xe(e.h,r,"h",100,t),...Ce(e.rotation,r,"rotation",t),...Xe(e.fill,r,"fill",t),...Xe(e.stroke,r,"stroke",t),...Ce(e.strokeWidth,r,"strokeWidth",t),...Ce(e.radius,r,"radius",t),...Ce(e.opacity,r,"opacity",t),..._r(e,r,t),...Qt(e)}}function Lm(e,t){let r=Mt(e,"ellipse",t);return{type:"ellipse",id:r,...We(e.name,"name"),x:xe(e.x,r,"x",0,t),y:xe(e.y,r,"y",0,t),w:xe(e.w,r,"w",100,t),h:xe(e.h,r,"h",100,t),...Ce(e.rotation,r,"rotation",t),...Xe(e.fill,r,"fill",t),...Xe(e.stroke,r,"stroke",t),...Ce(e.strokeWidth,r,"strokeWidth",t),...Ce(e.opacity,r,"opacity",t),..._r(e,r,t),...Qt(e)}}function Om(e,t){let r=Mt(e,"vector",t);return{type:"vector",id:r,...We(e.name,"name"),x:xe(e.x,r,"x",0,t),y:xe(e.y,r,"y",0,t),w:xe(e.w,r,"w",100,t),h:xe(e.h,r,"h",100,t),...Ce(e.rotation,r,"rotation",t),...We(e.view,"view"),d:typeof e.d=="string"?e.d:"",...Xe(e.fill,r,"fill",t),...Xe(e.stroke,r,"stroke",t),...Ce(e.strokeWidth,r,"strokeWidth",t),...Ce(e.opacity,r,"opacity",t),...Sr(e.rule,Vt,r,"rule",t),...Sr(e.cap,zt,r,"cap",t),...Sr(e.join,qt,r,"join",t),..._r(e,r,t),...Qt(e)}}function Dm(e,t){let r=Mt(e,"text",t);return{type:"text",id:r,...We(e.name,"name"),x:xe(e.x,r,"x",0,t),y:xe(e.y,r,"y",0,t),w:xe(e.w,r,"w",200,t),h:xe(e.h,r,"h",40,t),...Ce(e.rotation,r,"rotation",t),content:Pm(e.content,r,t),...Xe(e.font,r,"font",t),...Ce(e.size,r,"size",t),...Ce(e.weight,r,"weight",t),...Ce(e.lineHeight,r,"lineHeight",t),...Ce(e.letterSpacing,r,"letterSpacing",t),...Sr(e.align,_t,r,"align",t),...Sr(e.valign,Ct,r,"valign",t),...Os(e.italic,"italic"),...Xe(e.fill,r,"fill",t),...Ce(e.opacity,r,"opacity",t),..._r(e,r,t),...Qt(e)}}function Pm(e,t,r){if(e===void 0)return"";if(typeof e=="string")return e;if(!Array.isArray(e))return r.push({severity:"error",code:"invalid-content",message:`Expected a string or an array of runs for content, got ${JSON.stringify(e)}`,nodeId:t,prop:"content"}),"";let n=[];for(let o of e){if(typeof o=="string"){n.push(o);continue}let a=Ue(o);if(!a||typeof a.text!="string"){r.push({severity:"error",code:"invalid-run",message:'A text run must be a string or an object with a "text"',nodeId:t,prop:"content"});continue}n.push({text:a.text,...pt(a,"font","string"),...pt(a,"size","number"),...pt(a,"weight","number"),...pt(a,"italic","boolean"),...pt(a,"underline","boolean"),...pt(a,"strike","boolean"),...pt(a,"fill","string"),...pt(a,"letterSpacing","number"),...pt(a,"link","string")})}return n}function pt(e,t,r){let n=e[t];return typeof n!==r?{}:r==="number"&&!Number.isFinite(n)?{}:{[t]:n}}function _r(e,t,r){return{...Sr(e.blend,Ut,t,"blend",r),...Xe(e.shadow,t,"shadow",r)}}function Qt(e){return{...e.hidden===!0?{hidden:!0}:{},...e.locked===!0?{locked:!0}:{}}}function Os(e,t){return typeof e=="boolean"?{[t]:e}:{}}function Sr(e,t,r,n,o){return e===void 0?{}:typeof e=="string"&&t.includes(e)?{[n]:e}:(o.push({severity:"error",code:"invalid-value",message:`Expected one of ${t.join(", ")} for ${n}, got ${JSON.stringify(e)}`,nodeId:r,prop:n}),{})}function Mt(e,t,r){let n=e.id;return typeof n=="string"&&n.length>0?n:(r.push({severity:"error",code:"missing-id",message:`Node is missing an id; using "${t}"`}),t)}function xe(e,t,r,n,o){let a=Nm(e);return a!==void 0?a:(o.push({severity:"error",code:"invalid-value",message:`Expected a number or expression for ${r}, got ${JSON.stringify(e)}`,nodeId:t,prop:r}),n)}function Nm(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.startsWith("="))return St(e.slice(1))}function Ce(e,t,r,n){return e===void 0?{}:{[r]:xe(e,t,r,0,n)}}function Xe(e,t,r,n){return e===void 0?{}:typeof e=="string"?{[r]:e.startsWith("=")?St(e.slice(1)):e}:(n.push({severity:"error",code:"invalid-value",message:`Expected a string for ${r}, got ${JSON.stringify(e)}`,nodeId:t,prop:r}),{})}function We(e,t){return typeof e=="string"?{[t]:e}:{}}function Rm(e,t){let r=new Set,n=o=>{r.has(o.id)&&t.push({severity:"error",code:"duplicate-id",message:`Duplicate id ${o.id}. Addresses must be unique or patches land on the wrong node.`,nodeId:o.id}),r.add(o.id),ce(o)&&o.children.forEach(n)};n(e)}function Ue(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}function _o(e){return/^\s*(linear|radial|conic|repeating-[a-z]+)-gradient\s*\(/i.test(e)}function mn(e){let t=e.trim(),r=/^([a-z-]+)-gradient\s*\(([\s\S]*)\)$/i.exec(t);if(!r)return _o(t)?{error:'A gradient needs its closing ")"'}:{kind:"solid",colour:t};let n=r[1].toLowerCase(),o=Im(r[2]).map(a=>a.trim());if(o.some(a=>a===""))return{error:"A gradient has an empty argument"};if(n==="linear"){let a=Bm(o[0]),i=zf(a===void 0?o:o.slice(1));return"error"in i?i:{kind:"linear",angle:a??180,stops:i.stops}}if(n==="radial"){let a=Um(o[0]);if(a&&"error"in a)return a;let i=zf(a?o.slice(1):o);return"error"in i?i:{kind:"radial",shape:a?.shape??"ellipse",cx:a?.cx??.5,cy:a?.cy??.5,stops:i.stops}}return{error:`${n}-gradient is not supported; use linear-gradient or radial-gradient`}}function Ns(e){let t=e.map(n=>n.at);t[0]===void 0&&(t[0]=0),t[t.length-1]===void 0&&(t[t.length-1]=1);let r=0;for(let n=0;n<t.length;n+=1){let o=t[n];o!==void 0&&(r=Math.max(r,o),t[n]=r)}for(let n=1;n<t.length;n+=1){if(t[n]!==void 0)continue;let o=n-1,a=n;for(;t[a]===void 0;)a+=1;let i=t[o],l=t[a];for(let d=n;d<a;d+=1)t[d]=i+(l-i)*(d-o)/(a-o);n=a}return e.map((n,o)=>({colour:n.colour,at:t[o]}))}function Im(e){let t=[],r=0,n=0;for(let o=0;o<e.length;o+=1){let a=e[o];a==="("?r+=1:a===")"?r=Math.max(0,r-1):a===","&&r===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}var Fm={top:[0,-1],bottom:[0,1],left:[-1,0],right:[1,0]};function Bm(e){let t=/^(-?\d*\.?\d+)(deg|turn|rad)$/i.exec(e);if(t){let a=Number(t[1]),i=t[2].toLowerCase();return i==="turn"?a*360:i==="rad"?a*180/Math.PI:a}let r=/^to\s+([a-z]+)(?:\s+([a-z]+))?$/i.exec(e);if(!r)return;let n=0,o=0;for(let a of[r[1],r[2]]){if(a===void 0)continue;let i=Fm[a.toLowerCase()];if(!i)return;n+=i[0],o+=i[1]}return(Math.atan2(n,-o)*180/Math.PI+360)%360}var Hm={left:0,top:0,center:.5,right:1,bottom:1};function Um(e){let t=/^(circle|ellipse)?\s*(?:at\s+(\S+)(?:\s+(\S+))?)?$/i.exec(e);if(!t||t[1]===void 0&&t[2]===void 0)return;let r=t[1]?.toLowerCase();if(t[2]===void 0)return r?{shape:r}:void 0;let n=Vf(t[2]),o=t[3]===void 0?.5:Vf(t[3]);return n===void 0||o===void 0?{error:`A radial centre is two percentages or keywords, not "${e}"`}:{...r?{shape:r}:{},cx:n,cy:o}}function Vf(e){let t=Hm[e.toLowerCase()];if(t!==void 0)return t;let r=/^(-?\d*\.?\d+)%$/.exec(e);return r?Number(r[1])/100:void 0}function zf(e){if(e.length<2)return{error:"A gradient needs at least two colours"};let t=[];for(let r of e){let n=/^([\s\S]*?\S)\s+(-?\d*\.?\d+)%$/.exec(r);if(n&&Vm(n[1]))t.push({colour:n[1],at:Number(n[2])/100});else{if(/\s/.test(r.replace(/\([^)]*\)/g,"")))return{error:`"${r}" is not a colour with an optional percentage`};t.push({colour:r})}}return{stops:t}}function Vm(e){let t=0;for(let r of e)if(r==="("&&(t+=1),r===")"&&(t-=1),t<0)return!1;return t===0}function Co(e){let t=mn(e);return"error"in t?[]:t.kind==="solid"?[t.colour]:t.stops.map(r=>r.colour)}function Cr(e){let t=e.trim();if(t===""||t==="none")return{shadows:[]};let r=[];for(let n of zm(t)){let o=qm(n.trim());if(o.includes("inset"))return{error:"Inner shadows (inset) are not supported yet"};let a=[],i=[];for(let x of o){let y=/^(-?\d*\.?\d+)(px)?$/.exec(x);y&&i.length===0?a.push(Number(y[1])):i.push(x)}if(a.length<2||a.length>4)return{error:`"${n.trim()}" needs x, y, then optional blur and spread`};if(i.length!==1)return{error:`"${n.trim()}" needs one colour after its numbers`};let[l=0,d=0,c=0,h=0]=a;if(c<0)return{error:"A shadow cannot have a negative blur"};r.push({x:l,y:d,blur:c,spread:h,colour:i[0]})}return{shadows:r}}function zm(e){let t=[],r=0,n=0;for(let o=0;o<e.length;o+=1){let a=e[o];a==="("?r+=1:a===")"?r=Math.max(0,r-1):a===","&&r===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}function qm(e){let t=[],r=0,n="";for(let o of e){if(o==="("&&(r+=1),o===")"&&(r=Math.max(0,r-1)),/\s/.test(o)&&r===0){n!==""&&t.push(n),n="";continue}n+=o}return n!==""&&t.push(n),t}var Rs=["rect","ellipse","vector","image","text"];function Ve(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function Pe(e,t,r){if(r===0)return e;let n=r*Math.PI/180,o=Math.cos(n),a=Math.sin(n),i=e.x-t.x,l=e.y-t.y;return{x:t.x+i*o-l*a,y:t.y+i*a+l*o}}function xn(e,t,r=Ve(e)){if(t%360===0)return e;let n=[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}].map(d=>Pe(d,r,t)),o=n.map(d=>d.x),a=n.map(d=>d.y),i=Math.min(...o),l=Math.min(...a);return{x:i,y:l,w:Math.max(...o)-i,h:Math.max(...a)-l}}function gn(e){let t=(e%360+360)%360,r=Math.round(t*100)/100;return r===360?0:r}var Is=["x","y","w","h","left","right","top","bottom","cx","cy"];function yn(e){return Is.includes(e)}var Fs=["parent","prev","next","self","root"];function Bs(e){return Fs.includes(e)}var Te=class extends Error{position;constructor(t,r){super(t),this.position=r,this.name="ExprSyntaxError"}},jf=/[A-Za-z_]/,Hs=/[A-Za-z0-9_]/;function Us(e){let t=[],r=0,n=()=>{if(!jf.test(e[r]??""))throw new Te(`Expected a name at position ${r}`,r);let i=r;for(;r<e.length&&Hs.test(e[r]??"");)r++;return e.slice(i,r)},o=()=>{if(!Hs.test(e[r]??""))throw new Te(`Expected a name at position ${r}`,r);let i=r;for(;r<e.length&&Hs.test(e[r]??"");)r++;return e.slice(i,r)},a=()=>{let i=[n()];for(;e[r]===".";)r++,i.push(o());return i};for(;r<e.length;){let i=e[r]??"";if(/\s/.test(i)){r++;continue}if(/[0-9]/.test(i)){let l=r;for(;r<e.length&&/[0-9]/.test(e[r]??"");)r++;if(e[r]==="."&&/[0-9]/.test(e[r+1]??""))for(r++;r<e.length&&/[0-9]/.test(e[r]??"");)r++;let d=e.slice(l,r),c=Number(d);if(!Number.isFinite(c))throw new Te(`Bad number "${d}"`,l);e[r]==="%"?(r++,t.push({type:"percent",value:c})):t.push({type:"number",value:c});continue}if(i==="$"){r++,t.push({type:"token",name:n()});continue}if(i==="@"){r++,t.push({type:"ref",path:a()});continue}if(jf.test(i)){t.push({type:"word",path:a()});continue}if("+-*/()".includes(i)){r++,t.push({type:"op",value:i});continue}throw new Te(`Unexpected character "${i}" at position ${r}`,r)}return t.push({type:"eof"}),t}var Wm={"+":1,"-":1,"*":2,"/":2};function Ze(e){try{let t=Us(e),r=new Vs(t),n=r.parseBinary(0);return r.expectEof(),{ok:!0,ast:n}}catch(t){if(t instanceof Te)return{ok:!1,message:t.message};throw t}}var Vs=class{tokens;index=0;constructor(t){this.tokens=t}peek(){return this.tokens[this.index]??{type:"eof"}}next(){let t=this.peek();return this.index++,t}expectEof(){if(this.peek().type!=="eof")throw new Te("Unexpected trailing input",this.index)}parseBinary(t){let r=this.parseUnary();for(;;){let n=this.peek();if(n.type!=="op"||!Xm(n.value))break;let o=Wm[n.value];if(o<t)break;this.next();let a=this.parseBinary(o+1);r={kind:"binary",op:n.value,left:r,right:a}}return r}parseUnary(){let t=this.peek();return t.type==="op"&&(t.value==="-"||t.value==="+")?(this.next(),{kind:"unary",op:t.value,operand:this.parseUnary()}):this.parsePrimary()}parsePrimary(){let t=this.next();switch(t.type){case"number":return{kind:"number",value:t.value};case"percent":return{kind:"percent",value:t.value};case"token":return{kind:"token",name:t.name};case"ref":{if(t.path.length<2)throw new Te(`@${t.path.join(".")} needs an edge, for example @${t.path.join(".")}.right`,this.index);return{kind:"nodeRef",path:t.path}}case"word":{let[r,n,...o]=t.path;if(r===void 0||!Bs(r))throw new Te(`Unknown name "${t.path.join(".")}". Use $token for a token or @id.edge for a node.`,this.index);if(n===void 0||!yn(n)||o.length>0)throw new Te(`${r} needs an edge, for example ${r}.w`,this.index);return{kind:"relRef",word:r,edge:n}}case"op":{if(t.value==="("){let r=this.parseBinary(0),n=this.next();if(n.type!=="op"||n.value!==")")throw new Te("Missing closing parenthesis",this.index);return r}throw new Te(`Unexpected "${t.value}"`,this.index)}case"eof":throw new Te("Unexpected end of expression",this.index)}}};function Xm(e){return e==="+"||e==="-"||e==="*"||e==="/"}var Kf={"+":1,"-":1,"*":2,"/":2},Gf=3,Ym=4;function Jm(e){return e.kind==="binary"?Kf[e.op]??1:e.kind==="unary"?Gf:Ym}function vn(e){return Eo(e,0)}function Eo(e,t){let r=Zm(e);return Jm(e)<t?`(${r})`:r}function Zm(e){switch(e.kind){case"number":return ee(e.value);case"percent":return`${ee(e.value)}%`;case"token":return`$${e.name}`;case"nodeRef":return`@${e.path.join(".")}`;case"relRef":return`${e.word}.${e.edge}`;case"unary":return`${e.op}${Eo(e.operand,Gf)}`;case"binary":{let t=Kf[e.op]??1;return`${Eo(e.left,t)} ${e.op} ${Eo(e.right,t+1)}`}}}function zs(e){return e.slice(0,-1).join(".")}function $t(e,t){switch(e.kind){case"nodeRef":{let r=e.path[e.path.length-1],n=t(zs(e.path));return r===void 0||n===void 0?e:{kind:"nodeRef",path:[...n.split("."),r]}}case"unary":return{...e,operand:$t(e.operand,t)};case"binary":return{...e,left:$t(e.left,t),right:$t(e.right,t)};default:return e}}function er(e){let t=new Set,r=new Set,n=o=>{switch(o.kind){case"nodeRef":t.add(zs(o.path));return;case"token":r.add(o.name);return;case"unary":n(o.operand);return;case"binary":n(o.left),n(o.right);return;default:return}};return n(e),{nodes:[...t],tokens:[...r]}}function Oe(e,t){return`${e} ${t}`}function qs(e){switch(e){case"x":case"left":return["x"];case"y":case"top":return["y"];case"w":return["w"];case"h":return["h"];case"right":case"cx":return["x","w"];case"bottom":case"cy":return["y","h"]}}function Ao(e,t,r,n,o){switch(e){case"x":case"left":return t;case"y":case"top":return r;case"w":return n;case"h":return o;case"right":return t+n;case"bottom":return r+o;case"cx":return t+n/2;case"cy":return r+o/2}}function js(e){switch(e){case"x":case"left":case"right":case"cx":return"x";case"y":case"top":case"bottom":case"cy":return"y";case"w":case"h":return}}function Ks(e,t,r){let n=x=>{let y=[];for(let b=r.parentOf.get(x);b!==void 0;b=r.parentOf.get(b))y.push(b);return y},o=n(e),a=n(t),i=new Set(a),l=o.find(x=>i.has(x)),d=x=>l===void 0?x:x.slice(0,x.indexOf(l)),c=new Map([[e,1]]),h=(x,y)=>{let b=(c.get(x)??0)+y;b===0?c.delete(x):c.set(x,b)};for(let x of d(o))h(x,1);for(let x of d(a))h(x,-1);return c}function Gs(e){switch(e){case"right":case"bottom":return 1;case"cx":case"cy":return .5;default:return 0}}function Mo(e){if(e==="x"||e==="w")return"w";if(e==="y"||e==="h")return"h"}function bn(e){let t=new Map,r=new Map,n=new Map,o=new Map,a=[];oe(e.root,(h,x)=>{t.has(h.id)||t.set(h.id,h),a.push(h),x&&r.set(h.id,x.id),ce(h)&&h.children.forEach((y,b)=>{let P=h.children[b-1],k=h.children[b+1];P&&n.set(y.id,P.id),k&&o.set(y.id,k.id)})});let i=new Map;for(let h of a){let x=r.get(h.id);for(;x!==void 0;){let y=t.get(x);if(!y||!Se(y))break;x=r.get(x)}x!==void 0&&i.set(h.id,x)}let l=new Map,d=new Map,c=h=>{if(ce(h)){if(!Se(h)){let x=Wf(h);x.forEach((y,b)=>{let P=x[b-1],k=x[b+1];P&&l.set(y.id,P.id),k&&d.set(y.id,k.id)})}for(let x of h.children)c(x)}};return c(e.root),{rootId:e.root.id,byId:t,parentOf:r,prevOf:n,nextOf:o,layoutParentOf:i,layoutPrevOf:l,layoutNextOf:d,order:a}}function Wf(e){let t=[];for(let r of e.children)ce(r)&&Se(r)?t.push(...Wf(r)):t.push(r);return t}function $o(e,t,r){if(e.kind==="relRef"){let a=Qm(e.word,t,r);return a===void 0?{ok:!1,message:`${t} has no ${e.word}`}:{ok:!0,nodeId:a,edge:e.edge}}let n=e.path[e.path.length-1]??"",o=e.path.slice(0,-1).join(".");return yn(n)?r.byId.has(o)?{ok:!0,nodeId:o,edge:n}:{ok:!1,message:`No node @${o}`}:{ok:!1,message:`"${n}" is not an edge of @${o}`}}function Qm(e,t,r){switch(e){case"self":return t;case"root":return r.rootId;case"parent":return r.layoutParentOf.get(t);case"prev":return r.layoutPrevOf.get(t);case"next":return r.layoutNextOf.get(t)}}function Ae(e){let t=[],r=bn(e),n=Xf(r),o=new Set;Yf(n,t),Jf(n,e,r,o,t);let a=ex(n);tx(n,a,t);let i=rx(n,a,e,r,o,t);return{nodes:ox(e.root,i,n,t),problems:t}}function Er(e){let t=bn(e),r=Xf(t),n=[];Yf(r,n),Jf(r,e,t,new Set,n);let o=new Map;for(let a of r.values())for(let i of a.deps){let l=o.get(i),d={nodeId:a.nodeId,prop:a.prop};l?l.push(d):o.set(i,[d])}return o}function Xf(e){let t=new Map;for(let r of e.order){let n=r;for(let o of rt(r)){let a=n[o];a!==void 0&&t.set(Oe(r.id,o),{nodeId:r.id,prop:o,value:a,deps:[]})}}return t}function Yf(e,t){for(let r of e.values()){if(!pe(r.value))continue;let n=Ze(r.value.expr);if(n.ok){r.ast=n.ast;continue}t.push({severity:"error",code:"expression-syntax",message:n.message,nodeId:r.nodeId,prop:r.prop})}}function Jf(e,t,r,n,o){for(let a of e.values()){if(!a.ast)continue;let i=new Set,l=d=>{switch(d.kind){case"number":return;case"token":{let c=t.tokens[d.name];typeof c!="number"&&o.push({severity:"error",code:c===void 0?"unknown-token":"token-not-a-number",message:c===void 0?`Unknown token $${d.name}`:`Token $${d.name} is not a number`,nodeId:a.nodeId,prop:a.prop});return}case"percent":{let c=Mo(a.prop);if(!c)return;let h=r.layoutParentOf.get(a.nodeId),x=h===void 0?void 0:Oe(h,c);if(x===void 0||!e.has(x)){o.push({severity:"error",code:"percent-without-parent",message:`${a.nodeId}.${a.prop} uses a percentage but has no parent to measure against`,nodeId:a.nodeId,prop:a.prop});return}i.add(x);return}case"nodeRef":case"relRef":{let c=$o(d,a.nodeId,r);if(!c.ok){n.add(d),o.push({severity:"error",code:"unknown-reference",message:c.message,nodeId:a.nodeId,prop:a.prop});return}let h=y=>{e.has(y)&&i.add(y)},x=js(c.edge);if(!x){for(let y of qs(c.edge))h(Oe(c.nodeId,y));return}for(let y of Ks(c.nodeId,a.nodeId,r).keys())h(Oe(y,x));Gs(c.edge)!==0&&h(Oe(c.nodeId,x==="x"?"w":"h"));return}case"unary":l(d.operand);return;case"binary":l(d.left),l(d.right);return}};l(a.ast),a.deps=[...i]}}function ex(e){let t=new Map,r=new Map;for(let[a,i]of e){t.set(a,i.deps.length);for(let l of i.deps){let d=r.get(l);d?d.push(a):r.set(l,[a])}}let n=[];for(let[a,i]of t)i===0&&n.push(a);let o=[];for(let a=0;a<n.length;a++){let i=n[a];o.push(i);for(let l of r.get(i)??[]){let d=(t.get(l)??0)-1;t.set(l,d),d===0&&n.push(l)}}return o}function tx(e,t,r){if(t.length===e.size)return;let n=new Set(t);for(let[o,a]of e)n.has(o)||r.push({severity:"error",code:"cycle",message:`${a.nodeId}.${a.prop} is part of a dependency cycle`,nodeId:a.nodeId,prop:a.prop})}function rx(e,t,r,n,o,a){let i=new Map,l=(d,c)=>i.get(Oe(d,c))??0;for(let d of t){let c=e.get(d);if(c){if(!pe(c.value)){i.set(d,c.value);continue}if(!c.ast){i.set(d,0);continue}i.set(d,Zf(c.ast,c,r,n,o,a,l))}}return i}function Zf(e,t,r,n,o,a,i){let l=d=>Zf(d,t,r,n,o,a,i);switch(e.kind){case"number":return e.value;case"token":{let d=r.tokens[e.name];return typeof d=="number"?d:0}case"percent":{let d=Mo(t.prop);if(!d)return e.value/100;let c=n.layoutParentOf.get(t.nodeId);return c===void 0?0:e.value/100*i(c,d)}case"nodeRef":case"relRef":{if(o.has(e))return 0;let d=$o(e,t.nodeId,n);if(!d.ok)return 0;let c=js(d.edge);if(!c)return Ao(d.edge,i(d.nodeId,"x"),i(d.nodeId,"y"),i(d.nodeId,"w"),i(d.nodeId,"h"));let h=Gs(d.edge)*i(d.nodeId,c==="x"?"w":"h");for(let[x,y]of Ks(d.nodeId,t.nodeId,n))h+=y*i(x,c);return h}case"unary":{let d=l(e.operand);return e.op==="-"?-d:d}case"binary":{let d=l(e.left),c=l(e.right);if(e.op==="/"&&c===0)return a.push({severity:"error",code:"divide-by-zero",message:`${t.nodeId}.${t.prop} divides by zero`,nodeId:t.nodeId,prop:t.prop}),0;let h=nx(e.op,d,c);return Number.isFinite(h)?h:(a.push({severity:"error",code:"not-a-number",message:`${t.nodeId}.${t.prop} did not produce a finite number`,nodeId:t.nodeId,prop:t.prop}),0)}}}function nx(e,t,r){switch(e){case"+":return t+r;case"-":return t-r;case"*":return t*r;case"/":return t/r}}function ox(e,t,r,n){let o=new Map,a=(l,d)=>t.get(Oe(l,d))??0,i=(l,d,c)=>{let h=a(l.id,"x"),x=a(l.id,"y"),y=a(l.id,"w"),b=a(l.id,"h"),P={};for(let B of rt(l)){let R=Oe(l.id,B);r.has(R)&&(P[B]=t.get(R)??0)}(y<0||b<0)&&n.push({severity:"warning",code:"negative-size",message:`${l.id} resolved to a negative size`,nodeId:l.id});let k=d+h,_=c+x;if(o.set(l.id,{id:l.id,type:l.type,x:h,y:x,w:y,h:b,left:h,top:x,right:h+y,bottom:x+b,cx:h+y/2,cy:x+b/2,absX:k,absY:_,values:P}),ce(l))for(let B of l.children)i(B,k,_)};return i(e,0,0),o}function To(e){if(!pe(e))return{kind:"literal",value:e};let t=Ze(e.expr);return t.ok?t.ast.kind==="number"?{kind:"literal",value:t.ast.value}:t.ast.kind==="token"?{kind:"token",name:t.ast.name}:{kind:"complex",source:e.expr,ast:t.ast}:{kind:"complex",source:e.expr,error:t.message}}var eu="system-ui, -apple-system, Segoe UI, Roboto, sans-serif",tu=16,ru=400,nu=1.2,Lo="#0F172A";function wn(){return{advance(e,t){return e.length*(t.size*.5+t.letterSpacing)},metrics(e){return{ascent:e.size*.8,descent:e.size*.2,lineGap:0}}}}function Ws(e,t){if(e===void 0)return eu;let r=t[e];return r?r.fallback?`${Qf(r.family)}, ${r.fallback}`:Qf(r.family):e}function Qf(e){return/^[A-Za-z][A-Za-z0-9 -]*$/.test(e)?e:JSON.stringify(e)}function ou(e,t,r,n){let o={family:Ws(t.font,r),size:t.size,weight:t.weight,italic:t.italic,underline:!1,strike:!1,fill:n(t.fill),letterSpacing:t.letterSpacing},a=typeof e=="string"?[e]:e,i=[];for(let l of a){if(typeof l=="string"){l.length>0&&i.push({text:l,style:o});continue}let d=l;d.text.length!==0&&i.push({text:d.text,style:{family:d.font===void 0?o.family:Ws(d.font,r),size:d.size??o.size,weight:d.weight??o.weight,italic:d.italic??o.italic,underline:d.underline??!1,strike:d.strike??!1,fill:d.fill===void 0?o.fill:n(d.fill),letterSpacing:d.letterSpacing??o.letterSpacing,...d.link!==void 0&&Je(d.link)?{link:d.link}:{}}})}return i}function ax(e,t){let r=[];for(let n of e)for(let o of n.text.split(/(\n)/))if(o!==""){if(o===`
38
- `){let a=r[r.length-1];a&&!a.hardBreak?r[r.length-1]={...a,hardBreak:!0}:r.push({text:"",style:n.style,w:0,hardBreak:!0});continue}for(let a of o.match(/\S+\s*|\s+/g)??[])r.push({text:a,style:n.style,w:t.advance(a,n.style),hardBreak:!1})}return r}function sx(e,t,r){let n=[...e.text],o=[],a="";for(let i of n){let l=a+i;if(a!==""&&r.advance(l,e.style)>t){o.push({text:a,style:e.style,w:r.advance(a,e.style),hardBreak:!1}),a=i;continue}a=l}return a!==""&&o.push({text:a,style:e.style,w:r.advance(a,e.style),hardBreak:e.hardBreak}),o.length>0?o:[e]}function au(e,t){let{width:r,measure:n}=t,o=ax(n.itemize?e.flatMap(c=>n.itemize?.(c)??[c]):e,n);if(o.length===0){let c=e[0]?.style,h=c?t.lineHeight*c.size:0;return{lines:c?[ix(c,t.lineHeight)]:[],width:0,height:h}}let a=[],i=[],l=0,d=()=>{a.push(i),i=[],l=0};for(let c of o){let h=i.length===0&&c.w>r&&r>0?sx(c,r,n):[c];for(let x of h){let y=x.text.trimEnd(),b=y===x.text?x.w:n.advance(y,x.style);i.length>0&&l+b>r&&d(),i.push(x),l+=x.w,x.hardBreak&&d()}}return i.length>0&&a.push(i),lx(a,t)}function ix(e,t){let r=t*e.size;return{y:0,h:r,baseline:r*.8,w:0,spans:[]}}function lx(e,t){let r=[],n=0,o=0;return e.forEach((a,i)=>{let l=a.map(A=>A.style.size),d=Math.max(...l,0),c=t.lineHeight*d,h=a.map(A=>t.measure.metrics(A.style)),x=Math.max(...h.map(A=>A.ascent),0),y=Math.max(...h.map(A=>A.descent),0),b=n+(c-(x+y))/2+x,P=dx(a,t.measure),k=P.reduce((A,G)=>A+G.w,0);o=Math.max(o,k);let _=i===e.length-1||(a[a.length-1]?.hardBreak??!1),B=t.align==="justify"&&!_&&P.length>1,R=Math.max(0,t.width-k),J=t.align==="center"?R/2:t.align==="right"?R:0,E=B?R/(P.length-1):0,D=[],N=J;P.forEach((A,G)=>{D.push({text:A.text,style:A.style,x:N,w:A.w}),N+=A.w+(G<P.length-1?E:0)}),r.push({y:n,h:c,baseline:b,w:k,spans:fx(D,B)}),n+=c}),{lines:r,width:o,height:n}}function dx(e,t){let r=[...e];for(;r.length>0;){let n=r[r.length-1],o=n.text.trimEnd();if(o===n.text)break;if(o===""){r.pop();continue}r[r.length-1]={...n,text:o,w:t.advance(o,n.style)};break}return r}function fx(e,t){if(t)return[...e];let r=[];for(let n of e){let o=r[r.length-1];if(o&&su(o.style,n.style)&&Math.abs(o.x+o.w-n.x)<.01){r[r.length-1]={...o,text:o.text+n.text,w:o.w+n.w};continue}r.push(n)}return r}function su(e,t){return e.family===t.family&&e.size===t.size&&e.weight===t.weight&&e.italic===t.italic&&e.underline===t.underline&&e.strike===t.strike&&e.fill===t.fill&&e.letterSpacing===t.letterSpacing&&e.link===t.link}function Xs(e,t,r,n,o,a){let i={size:t.size??tu,weight:t.weight??ru,lineHeight:t.lineHeight??nu,letterSpacing:t.letterSpacing??0,italic:e.italic??!1,font:typeof e.font=="string"?e.font:void 0,fill:typeof e.fill=="string"?e.fill:Lo};return au(ou(e.content,i,n,o),{width:r,align:e.align??"left",lineHeight:i.lineHeight,measure:a})}function Ys(e,t,r){let n=t-r;return e.valign==="middle"?n/2:e.valign==="bottom"?n:0}function Js(e){switch(e.kind){case"text":{let t=Math.max(e.w,...e.lines.map(n=>n.w)),r=Math.max(e.y+e.h,...e.lines.map(n=>n.y+n.h));return{x:e.x,y:e.y,w:t,h:r-e.y}}case"vector":{let t=Xt(e.contours)??{x:e.x,y:e.y,w:e.w,h:e.h},r=e.stroke!==void 0?e.strokeWidth*2:0;return{x:t.x-r,y:t.y-r,w:t.w+r*2,h:t.h+r*2}}case"rect":case"ellipse":{let t=e.stroke!==void 0?e.strokeWidth/2:0;return{x:e.x-t,y:e.y-t,w:e.w+t*2,h:e.h+t*2}}case"frame":case"image":return{x:e.x,y:e.y,w:e.w,h:e.h}}}function Po(e,t){let r=e.x,n=e.y,o=e.x+e.w,a=e.y+e.h;for(let i of t){let l=i.spread+i.blur;r=Math.min(r,e.x+i.x-l),n=Math.min(n,e.y+i.y-l),o=Math.max(o,e.x+e.w+i.x+l),a=Math.max(a,e.y+e.h+i.y+l)}return{x:r,y:n,w:o-r,h:a-n}}var du="vd-paint-";var Do="#CBD5E1",fu="#FFFFFF";function _n(e,t,r={}){let n=[...t.problems],o=[],a=[],i=r.measure??wn(),l=yx(e.tokens,n),d=l.paint,c=new Map;oe(e.root,(k,_)=>{if("hidden"in k&&k.hidden===!0)return!1;let B=_?c.get(_.id):void 0,R=t.nodes.get(k.id);if(!R){c.set(k.id,B);return}if(k.type==="frame"){k.skip===!0&&_!==e.root&&n.push({severity:"warning",code:"skip-not-a-page",message:`${k.id}: skip only applies to a page, a frame at the top level`,nodeId:k.id,prop:"skip"});let E={x:R.absX,y:R.absY,w:Math.max(0,R.w),h:Math.max(0,R.h)};c.set(k.id,k.clip===!0?k.id:B),k.clip===!0&&a.push({id:k.id,...E,parent:B}),o.push({kind:"frame",id:k.id,...E,background:d(k.background,k.id,"background",E),clip:B,blend:k.blend??"normal",shadows:Ar(k.shadow,k.id,e.tokens,n),rotation:0});return}if(c.set(k.id,B),k.type==="text"){o.push(cx(k,R,e,i,n,B,d));return}if(k.type==="image"){o.push({kind:"image",id:k.id,x:R.absX,y:R.absY,w:Math.max(0,R.w),h:Math.max(0,R.h),href:wx(k,e,r.resolveAsset,n),fit:k.fit??"fill",radius:Math.max(0,R.values.radius??0),opacity:Sn(R.values.opacity??1),clip:B,blend:k.blend??"normal",shadows:Ar(k.shadow,k.id,e.tokens,n),rotation:R.values.rotation??0});return}if(k.type==="ellipse"){let E=lu(R);o.push({kind:"ellipse",id:k.id,...E,fill:d(k.fill,k.id,"fill",E)??Do,stroke:d(k.stroke,k.id,"stroke",E),strokeWidth:R.values.strokeWidth??0,opacity:Sn(R.values.opacity??1),clip:B,blend:k.blend??"normal",shadows:Ar(k.shadow,k.id,e.tokens,n),rotation:R.values.rotation??0});return}if(k.type==="vector"){o.push(gx(k,R,n,B,d,Ar(k.shadow,k.id,e.tokens,n)));return}if(k.type!=="rect")return;let J=lu(R);o.push({kind:"rect",id:k.id,...J,fill:d(k.fill,k.id,"fill",J)??Do,stroke:d(k.stroke,k.id,"stroke",J),strokeWidth:R.values.strokeWidth??0,radius:Math.max(0,R.values.radius??0),opacity:Sn(R.values.opacity??1),clip:B,blend:k.blend??"normal",shadows:Ar(k.shadow,k.id,e.tokens,n),rotation:R.values.rotation??0})});let h=t.nodes.get(e.root.id),x=e.root.w!==void 0&&e.root.h!==void 0,y=x?{x:0,y:0,width:Math.max(0,h?.w??0),height:Math.max(0,h?.h??0)}:ux(o,a),b={x:y.x,y:y.y,w:y.width,h:y.height},P=d(e.root.background,e.root.id,"background",b);return{...y,background:x?P??fu:P,items:o,clips:a,gradients:l.gradients,problems:n}}function ux(e,t){let r=new Map;for(let l of t){let d=l.parent===void 0?void 0:r.get(l.parent);r.set(l.id,d?iu(l,d):l)}let n=1/0,o=1/0,a=-1/0,i=-1/0;for(let l of e){let d=l.kind==="text"?Math.max(l.h,l.height):l.h,c=l.clip===void 0?void 0:r.get(l.clip),h=xn(Po({x:l.x,y:l.y,w:l.w,h:d},l.shadows),l.rotation,Ve(l)),x=c?iu(h,c):h;x.w<=0||x.h<=0||(n=Math.min(n,x.x),o=Math.min(o,x.y),a=Math.max(a,x.x+x.w),i=Math.max(i,x.y+x.h))}return Number.isFinite(n)?{x:n,y:o,width:a-n,height:i-o}:{x:0,y:0,width:0,height:0}}function iu(e,t){let r=Math.max(e.x,t.x),n=Math.max(e.y,t.y);return{x:r,y:n,w:Math.min(e.x+e.w,t.x+t.w)-r,h:Math.min(e.y+e.h,t.y+t.h)-n}}function cx(e,t,r,n,o,a,i){let l=Math.max(0,t.w),d=Math.max(0,t.h),c={x:t.absX,y:t.absY,w:l,h:d},h=Xs(e,t.values,l,r.fonts,y=>i(y,e.id,"fill",c)??Lo,n);h.height>d+.5&&o.push({severity:"warning",code:"text-overflow",message:`${e.id} needs ${Math.ceil(h.height)}px but its height is ${Math.round(d)}px`,nodeId:e.id,prop:"h"}),px(e,r,o);let x=t.absY+Ys(e,d,h.height);return{kind:"text",id:e.id,x:t.absX,y:t.absY,w:l,h:d,clip:a,blend:e.blend??"normal",shadows:Ar(e.shadow,e.id,r.tokens,o),rotation:t.values.rotation??0,opacity:Sn(t.values.opacity??1),height:h.height,lines:h.lines.map(y=>({y:x+y.y,h:y.h,baseline:x+y.baseline,w:y.w,spans:y.spans.map(b=>({text:b.text,x:t.absX+b.x,y:x+y.baseline,w:b.w,style:b.style}))}))}}function px(e,t,r){if(typeof e.content!="string")for(let n of e.content){if(typeof n=="string"||n.link===void 0)continue;let o=Je(n.link);if(!o){r.push({severity:"warning",code:"invalid-link",message:`${e.id}: links go to https:, mailto: or #<frame>, not ${JSON.stringify(n.link)}`,nodeId:e.id,prop:"content"});continue}o.kind==="frame"&&!hx(t,o.id)&&r.push({severity:"warning",code:"link-target-missing",message:`${e.id}: links to #${o.id}, which is not a frame`,nodeId:e.id,prop:"content"})}}function hx(e,t){let r=!1;return oe(e.root,n=>{if(r)return!1;n.id===t&&n.type==="frame"&&(r=!0)}),r}var kn=new Map,mx=512;function xx(e){let t=kn.get(e);if(t)return t;let r=sn(e);return kn.size>=mx&&kn.delete(kn.keys().next().value),kn.set(e,r),r}function gx(e,t,r,n,o,a){let i=Math.max(0,t.w),l=Math.max(0,t.h),d={x:t.absX,y:t.absY,w:i,h:l},{contours:c,error:h}=xx(e.d);h!==void 0&&r.push({severity:"error",code:"bad-path",message:`${e.id}: ${h}`,nodeId:e.id,prop:"d"}),e.view!==void 0&&go(e.view)===void 0&&r.push({severity:"warning",code:"bad-view",message:`${e.id}: view must be four numbers, like "0 0 24 24"`,nodeId:e.id,prop:"view"});let x=ct(c,un(fn(e.view,i,l),d));return{kind:"vector",id:e.id,...d,d:ut(x),contours:x,fill:o(e.fill,e.id,"fill",d)??Do,stroke:o(e.stroke,e.id,"stroke",d),strokeWidth:t.values.strokeWidth??0,opacity:Sn(t.values.opacity??1),rule:e.rule??"nonzero",cap:e.cap??"butt",join:e.join??"miter",clip:n,blend:e.blend??"normal",shadows:a,rotation:t.values.rotation??0}}function uu(e,t,r,n,o){if(e===void 0)return;if(pe(e)){o.push({severity:"warning",code:"expression-not-supported",message:`Expressions are not supported for ${n} yet; grammar v0 is numeric only`,nodeId:r,prop:n});return}let a=t[e];if(a===void 0)return e;if(typeof a=="string")return a;o.push({severity:"error",code:"token-not-a-colour",message:`Token $${e} is a number, not a colour`,nodeId:r,prop:n})}function lu(e){return{x:e.absX,y:e.absY,w:Math.max(0,e.w),h:Math.max(0,e.h)}}function yx(e,t){let r=[],n=new Map;return{paint:(a,i,l,d)=>{let c=uu(a,e,i,l,t);if(c===void 0)return;let h=mn(c);if("error"in h){t.push({severity:"error",code:"invalid-paint",message:`${i}: ${h.error}`,nodeId:i,prop:l});return}if(h.kind==="solid")return c;let x=`${i}\0${l}\0${c}`,y=n.get(x);if(y!==void 0)return`url(#${y})`;let b=[...n.keys()].filter(_=>_.startsWith(`${i}\0${l}\0`)).length,P=`${du}${i}-${l}${b===0?"":`-${b+1}`}`;n.set(x,P);let k=Ns(h.stops).map(_=>({offset:_.at,colour:cu(_.colour,e,i,l,t)}));return r.push(bx(h,P,d,vx(k))),`url(#${P})`},gradients:r}}function Ar(e,t,r,n){let o=uu(e,r,t,"shadow",n);if(o===void 0)return[];let a=Cr(o);return"error"in a?(n.push({severity:"error",code:"invalid-shadow",message:`${t}: ${a.error}`,nodeId:t,prop:"shadow"}),[]):a.shadows.map(i=>({...i,colour:cu(i.colour,r,t,"shadow",n)}))}function vx(e){return e.map((t,r)=>{if(t.colour.trim().toLowerCase()!=="transparent")return t;let n=[e[r-1],e[r+1]].find(o=>o!==void 0&&o.colour.trim().toLowerCase()!=="transparent");return n===void 0?t:{offset:t.offset,colour:n.colour,opacity:0}})}function cu(e,t,r,n,o){let a=t[e];return a===void 0?e:typeof a=="string"&&!_o(a)?a:(o.push({severity:"error",code:"invalid-paint",message:`${r}: a gradient stop names $${e}, which is not a colour`,nodeId:r,prop:n}),"transparent")}function bx(e,t,r,n){if(e.kind==="linear"){let c=e.angle*Math.PI/180,h=Math.sin(c),x=-Math.cos(c),y=(Math.abs(r.w*h)+Math.abs(r.h*x))/2,b=r.x+r.w/2,P=r.y+r.h/2;return{id:t,kind:"linear",x1:Oo(b-h*y),y1:Oo(P-x*y),x2:Oo(b+h*y),y2:Oo(P+x*y),stops:n}}let o=r.x+r.w*e.cx,a=r.y+r.h*e.cy,i={x:Math.max(o-r.x,r.x+r.w-o),y:Math.max(a-r.y,r.y+r.h-a)};if(e.shape==="circle"||i.x===0||i.y===0){let c=Math.hypot(i.x,i.y);return{id:t,kind:"radial",cx:o,cy:a,rx:c,ry:c,stops:n}}let l=i.x/i.y,d=Math.hypot(i.x/l,i.y);return{id:t,kind:"radial",cx:o,cy:a,rx:d*l,ry:d,stops:n}}function Oo(e){return Math.round(e*1e6)/1e6}function Sn(e){return Math.min(Math.max(e,0),1)}function wx(e,t,r,n){let o=pe(e.src)?void 0:e.src,a=o===void 0?void 0:t.assets[o];if(!a){n.push({severity:"warning",code:"missing-asset",message:`No picture for ${JSON.stringify(o??e.src)} yet: an image slot waiting for one`,nodeId:e.id,prop:"src"});return}let i=r?.(a,o);return i===void 0&&n.push({severity:"warning",code:"unresolved-asset",message:`The bytes for asset "${o}" are not available here`,nodeId:e.id,prop:"src"}),i}function Zs(e){return Sx(e,"")}function Sx(e,t){let r=e.stops.map(o=>`<stop offset="${ee(o.offset)}" stop-color="${No(o.colour)}"${o.opacity===void 0?"":` stop-opacity="${ee(o.opacity)}"`}/>`).join(""),n=No(t+e.id);return e.kind==="linear"?`<linearGradient id="${n}" gradientUnits="userSpaceOnUse" x1="${ee(e.x1)}" y1="${ee(e.y1)}" x2="${ee(e.x2)}" y2="${ee(e.y2)}">${r}</linearGradient>`:`<radialGradient id="${n}" gradientUnits="userSpaceOnUse" cx="0" cy="0" r="1" gradientTransform="matrix(${ee(e.rx)} 0 0 ${ee(e.ry)} ${ee(e.cx)} ${ee(e.cy)})">${r}</radialGradient>`}var Ro="vd-shadow-";function Qs(e,t=!1){return _x(e,t,"")}function _x(e,t,r){let n=Po(Js(e),e.shadows),o=2,a=[];e.shadows.forEach((l,d)=>{let c=`s${d}`,h="SourceAlpha";l.spread!==0&&(a.push(`<feMorphology in="${h}" operator="${l.spread>0?"dilate":"erode"}" radius="${ee(Math.abs(l.spread))}" result="${c}m"/>`),h=`${c}m`),l.blur>0&&(a.push(`<feGaussianBlur in="${h}" stdDeviation="${ee(l.blur/2)}" result="${c}b"/>`),h=`${c}b`),a.push(`<feOffset in="${h}" dx="${ee(l.x)}" dy="${ee(l.y)}" result="${c}o"/>`,`<feFlood flood-color="${No(l.colour)}" result="${c}c"/>`,`<feComposite in="${c}c" in2="${c}o" operator="in" result="${c}"/>`)});let i=e.shadows.map((l,d)=>`<feMergeNode in="s${e.shadows.length-1-d}"/>`).join("");return`<filter id="${No(r+Ro+e.id)}" filterUnits="userSpaceOnUse" x="${ee(n.x-o)}" y="${ee(n.y-o)}" width="${ee(n.w+o*2)}" height="${ee(n.h+o*2)}" color-interpolation-filters="sRGB">`+a.join("")+`<feMerge>${i}${t?"":'<feMergeNode in="SourceGraphic"/>'}</feMerge></filter>`}function ei(e){return`rotate(${ee(e.rotation)} ${ee(e.x+e.w/2)} ${ee(e.y+e.h/2)})`}function ti(e){return e.rotation!==0&&e.clip!==void 0}function No(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var Ax=.8,Mx=.2;function ri(e,t){let n=e.createElement("canvas").getContext("2d"),o=wn(),a=new Map,i=new Map,l=new Set;function d(h){return`${h.italic?"italic ":""}${h.weight} ${h.size}px ${h.family}`}function c(){a.clear(),i.clear()}return{advance(h,x){if(!n)return o.advance(h,x);let y=d(x),b=`${y}\0${x.letterSpacing}\0${h}`,P=a.get(b);if(P!==void 0)return P;n.font=y;let k=n.measureText(h).width+x.letterSpacing*[...h].length;return a.set(b,k),k},metrics(h){if(!n)return o.metrics(h);let x=d(h),y=i.get(x);if(y)return y;n.font=x;let b=n.measureText("Hxg"),P=b.fontBoundingBoxAscent??h.size*Ax,k=b.fontBoundingBoxDescent??h.size*Mx,_={ascent:P,descent:k,lineGap:0};return i.set(x,_),_},load(h,x){let y=e.fonts;if(!y||typeof FontFace!="function")return!1;let b=!1;for(let P of Object.values(h.fonts))for(let k of $x(P)){let _=`${P.family}\0${k.src}\0${k.weight??400}\0${k.style??"normal"}`;if(l.has(_))continue;l.add(_);let B=k.src.startsWith("data:")?void 0:x?.(k.src),R={weight:String(k.weight??400),style:k.style??"normal"},J=E=>{let D=new FontFace(P.family,typeof E=="string"?`url(${E})`:Tx(E),R);y.add(D),D.load().then(()=>{c(),t?.()},()=>{y.delete(D)})};B===void 0?J(k.src):(b=!0,B.then(J,()=>{}))}return b},invalidate:c,destroy(){c(),l.clear()}}}function $x(e){return e.faces??[]}function Tx(e){return e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}var Io={x:0,y:0,zoom:1},hu=.02,mu=64;function Cn(e){return Number.isFinite(e)?Math.min(Math.max(e,hu),mu):1}function Fo(e,t){return{x:(t.x-e.x)/e.zoom,y:(t.y-e.y)/e.zoom}}function ni(e,t){return{x:t.x*e.zoom+e.x,y:t.y*e.zoom+e.y}}function Bo(e,t,r){let n=Cn(e.zoom*r),o=Fo(e,t);return{zoom:n,x:t.x-o.x*n,y:t.y-o.y*n}}function Tt(e,t,r){return{...e,x:e.x+t,y:e.y+r}}function oi(e){return`translate(${e.x} ${e.y}) scale(${e.zoom})`}function Mr(e,t,r){let n={width:Math.max(1,t.width-r*2),height:Math.max(1,t.height-r*2)};if(e.width<=0||e.height<=0)return Io;let o=Cn(Math.min(n.width/e.width,n.height/e.height));return{zoom:o,x:(t.width-e.width*o)/2-(e.x??0)*o,y:(t.height-e.height*o)/2-(e.y??0)*o}}var ne="http://www.w3.org/2000/svg",xu="vd-viewer-styles",gu=`
35
+ `}async function Ms(e){let t=await crypto.subtle.digest("SHA-256",e),r=[...new Uint8Array(t)].map(n=>n.toString(16).padStart(2,"0"));return`${If}${r.join("")}`}function As(e,t){return`data:${e};base64,${t}`}function $s(e){let t=e.toBase64;if(typeof t=="function")return t.call(e);let r="";for(let n=0;n<e.length;n+=32768)r+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(r)}function Ts(e){let t=Uint8Array.fromBase64;if(typeof t=="function")return t(e);let r=atob(e),n=new Uint8Array(r.length);for(let o=0;o<r.length;o+=1)n[o]=r.charCodeAt(o);return n}function um(e){if(e.startsWith(tr))return 0;let t=e.indexOf(`
36
+ ${tr}`);return t===-1?-1:t+1}function cm(e){let t=new Set;for(let r of e.matchAll(/sha256-[0-9a-f]{64}/g))t.add(r[0]);return t}function Ls(e){return(t,r,n,o)=>{e.push({severity:"error",code:r,message:`Line ${t}: ${n}`,...o===void 0?{}:{nodeId:o}})}}function Os(e){let t=[],r=e.split(`
37
+ `);for(let n=0;n<r.length;n+=1){let o=r[n],a=o.trim();if(a===tr)break;if(a===""||a.startsWith("```"))continue;let i=o.length-o.trimStart().length;t.push({number:n+1,indent:Math.floor(i/2),text:a,words:Df(a)})}return t}function Ds(e){let t=[],r=[],n=o=>{for(;t.length>0&&t[t.length-1].indent>=o;)hm(t.pop())};return{push(o){let a=o.words[0];if(a.startsWith('"')){let c=t[t.length-1];if(!c||c.type!=="text")return e(o.number,"invalid-content","A quoted line must sit inside a text node"),!0;let h=xm(o,e);return h!==void 0&&c.runs.push(h),!0}if(!Ao(a))return!1;n(o.indent);let i=o.words[1];if(i===void 0||i.includes("="))return e(o.number,"missing-id",`A ${a} needs an id`),!0;let l=pm(a,i,o.words.slice(2),o,e),d=t[t.length-1];return d?d.children.push(l.record):r.push(l.record),t.push(l),!0},finish(){return n(0),r}}}function pm(e,t,r,n,o){let a={type:e,id:t},i=[];for(let l=0;l<r.length;l+=1){let{key:d,value:c}=Ke(r[l]),h=ys(e,d);if(h===void 0){let y=vs(r,l,r[l-1]);y?(o(n.number,"invalid-value",y.message,t),l=y.end-1):o(n.number,"invalid-value",`${e} has no property "${d}"`,t);continue}let x=qe(c??"",h);"error"in x?o(n.number,"invalid-value",`${d}: ${x.error}`,t):a[d]=x.value}return co(e)&&(a.children=i),e==="text"&&(a.content=""),{indent:n.indent,type:e,record:a,children:i,runs:[]}}function hm(e){e.type==="text"&&(e.record.content=mm(e.runs))}function mm(e){if(e.length===0)return"";let t=e[0];return e.length===1&&typeof t=="string"?t:[...e]}function xm(e,t){let r=Er(e.words[0]);if(r===void 0){t(e.number,"invalid-run","Malformed quoted string");return}if(e.words.length===1)return r;let n={text:r};for(let o of e.words.slice(1)){let{key:a,value:i}=Ke(o),l=yn.find(([c])=>c===a);if(!l){t(e.number,"invalid-run",`A run has no mark "${a}"`);continue}let d=qe(i??"",l[1]);"error"in d?t(e.number,"invalid-run",`${a}: ${d.error}`):n[a]=d.value}return n}function $o(e){let t=[],r=Ls(t),n=Tt,o,a=!1,i={},l={},d={},c=Ds(r),h,x={},y=new Map,v,D=!1,k=()=>{if(!v)return;let E=v;v=void 0;let P=y.get(E.page);if(P!==void 0){r(E.number,"invalid-motion",`motion ${E.page} is written twice \u2014 put its lines in the block on line ${P}`,E.page);return}y.set(E.page,E.number);for(let[C,G]of E.where)y.set(`${E.page} ${C}`,G);let R=ks(E);R&&(x[E.page]=R)};for(let E of Os(e)){let P=E.words[0];if(v&&E.indent>0){ws(v,E,r);continue}if(!(D&&E.indent>0)){if(D=!1,k(),P==="motion"&&E.indent===0){h=void 0,v=bs(E,r),D=v===void 0;continue}if(P==="version"){a=!0,ym(E,t);continue}if(P==="kind"&&E.indent===0){n=vm(E,t);continue}if(P==="title"&&E.indent===0){o=zf(E,r);continue}if(P.startsWith("$")){h=void 0,bm(E,i,r);continue}if(P==="asset"&&E.indent===0){h=void 0,wm(E,d,r);continue}if(P==="font"&&E.indent===0){h=Sm(E,l,r);continue}if((P==="fallback"||P==="face")&&h){_m(P,E,h,r);continue}h=void 0,!c.push(E)&&r(E.number,"unknown-node-type",`Unknown statement "${P}"`)}}k();let S=gm(c.finish(),t),B=Object.keys(x).length===0?{}:{motion:x},N=(E,P)=>y.get(P===void 0?E:`${E} ${P}`);if(!S){a||t.push({severity:"error",code:"invalid-document",message:"No nodes found"});let E=yr({id:lt,children:[]}),P=ln({kind:n,...o===void 0?{}:{title:o},tokens:i,fonts:l,assets:d,...B,root:E});return t.push(...Sr(P,N)),{document:P,problems:t}}let J={version:4,kind:n,...o===void 0?{}:{title:o},tokens:i,fonts:l,assets:d,...B,root:S};return t.push(...Sr(J,N)),{document:J,problems:t}}function gm(e,t){let r=e[0];if(r!==void 0){if(e.length===1&&r.type==="canvas")return r;for(let n of e){if(n.type!=="canvas")continue;let o=n.id;t.push({severity:"error",code:"invalid-document",message:"A canvas must be the only top-level node",...typeof o=="string"?{nodeId:o}:{}})}return{type:"canvas",id:lt,children:[...e]}}}function ym(e,t){sn.includes(Number(e.words[1]))||t.push({severity:"warning",code:"version-mismatch",message:`Line ${e.number}: expected version ${4} or older, got ${e.words[1]??"nothing"}`})}function vm(e,t){let r=e.words[1];return r!==void 0&&Xt.includes(r)?r:(t.push({severity:"error",code:"unknown-kind",message:`Line ${e.number}: unknown kind "${r??"nothing"}" \u2014 this build reads ${Xt.join(", ")}`}),Tt)}function zf(e,t){let r=e.words.slice(1).join(" ").trim();if(r===""){t(e.number,"invalid-value",'title needs a name, e.g. title "Pitch deck"');return}let n=r.startsWith('"')?Er(r):r;if(n===void 0){t(e.number,"invalid-value",`Could not read the title ${r}`);return}return n.trim()===""?void 0:n}function bm(e,t,r){let{name:n,value:o}=Ps(e.words);if(n===void 0||o===void 0){r(e.number,"invalid-token","Expected $name = value");return}if(!o.startsWith('"')&&/\s/.test(o)){r(e.number,"invalid-token",`$${n}: expected one value, got "${o}". Quote it if the value has spaces; there are no comments.`);return}let a=qe(o,"stringValue");if("error"in a){r(e.number,"invalid-token",`$${n}: ${a.error}`);return}if(typeof a.value!="string"){r(e.number,"invalid-token",`$${n} may not be an expression`);return}t[n]=Uf(a.value,o)}function Uf(e,t){let r=Number(e);return t.startsWith('"')||!Number.isFinite(r)||e.trim()===""?e:r}function Ps(e){let t=e[0],r=a=>a.startsWith("$")?a.slice(1):a;if(e[1]==="=")return{name:r(t),value:e.slice(2).join(" ")||void 0};let{key:n,value:o}=Ke(t);return o!==void 0?{name:r(n),value:o}:{name:r(t)}}function wm(e,t,r){let n=e.words.slice(1),o=n[0],a=n[1]==="=",i=o===void 0?void 0:Ke(o),l=i?.key,d=a?n[2]:i?.value,c=n.slice(a?3:1);if(l===void 0||l===""||d===void 0){r(e.number,"invalid-asset","Expected asset <name> = <type> hash=\u2026 bytes=\u2026");return}let h={};for(let v of c){let{key:D,value:k}=Ke(v);if(k===void 0){r(e.number,"invalid-asset",`Asset "${l}" has a stray word "${v}"`);continue}h[D]=km(k)}let x=h.hash,y=Number(h.bytes);if(x===void 0||!Number.isFinite(y)){r(e.number,"invalid-asset",`Asset "${l}" needs a hash and a bytes count`);return}t[l]={type:d,hash:x,bytes:y,...h.credit===void 0?{}:{credit:h.credit},...h.source===void 0?{}:{source:h.source},...h.license===void 0?{}:{license:h.license}}}function km(e){return e.startsWith('"')?Er(e)??e:e}function Sm(e,t,r){let{name:n,value:o}=Ps(e.words.slice(1));if(n===void 0||o===void 0){r(e.number,"invalid-font","Expected font <name> = <family>");return}let a=qe(o,"string"),i={family:"error"in a?o:a.value};return t[n]=i,{family:i,faces:[]}}function _m(e,t,r,n){if(e==="fallback"){let l=qe(t.words.slice(1).join(" "),"string");"error"in l?n(t.number,"invalid-font",`fallback: ${l.error}`):r.family.fallback=l.value;return}let o=t.words[1];if(o===void 0){n(t.number,"invalid-font-face","A face needs a src");return}let a=qe(o,"string"),i={src:"error"in a?o:a.value};for(let l of t.words.slice(2)){let{key:d,value:c}=Ke(l);if(d!=="weight"&&d!=="style"){n(t.number,"invalid-font-face",`A face has no property "${d}"`);continue}let h=qe(c??"",d==="weight"?"number":"fontStyle");"error"in h?n(t.number,"invalid-font-face",`${d}: ${h.error}`):i[d]=h.value}r.faces.push(i),r.family.faces=r.faces}function Is(e){let t=[],r=je(e);if(!r)return t.push({severity:"error",code:"invalid-document",message:"Expected an object"}),{document:ln(),problems:t};sn.includes(r.version)||t.push({severity:"warning",code:"version-mismatch",message:`Expected version ${4} or older, got ${JSON.stringify(r.version)}`});let n=qf(r.root,t),o=Cm(r.motion,t),a={version:4,kind:Mm(r.kind,t),...typeof r.title=="string"&&r.title.trim()!==""?{title:r.title}:{},tokens:Am(r.tokens,t),fonts:Tm(r.fonts,t),assets:$m(r.assets,t),...o===void 0?{}:{motion:o},root:n??yr({id:lt,children:[]})};return Um(a.root,t),t.push(...Sr(a)),{document:a,problems:t}}function Cm(e,t){if(e===void 0)return;let r=je(e),n=a=>{t.push({severity:"error",code:"invalid-motion",message:a})};if(!r){n("`motion` must be an object");return}let o={};for(let[a,i]of Object.entries(r)){let l=je(i);if(!l||!Array.isArray(l.lines)){n(`motion ${a} must be an object with a lines array`);continue}let d=l.enter,c=l.duration;if(d!==void 0&&!br.includes(d)){n(`motion ${a}: enter must be one of ${br.join(", ")}`);continue}if(c!==void 0&&!Ns(c)){n(`motion ${a}: duration must be 0 to ${Yt} milliseconds`);continue}let h=l.scroll;if(h!==void 0&&typeof h!="boolean"){n(`motion ${a}: scroll must be true or false`);continue}let x=l.lines.flatMap(v=>{let D=Em(v);return D===void 0&&n(`motion ${a}: a line that is not one: ${JSON.stringify(v)}`),D===void 0?[]:[D]}),y={...d===void 0?{}:{enter:d},...c===void 0?{}:{duration:c},...h===!0?{scroll:!0}:{},lines:x};ht(y)||(o[a]=y)}return Object.keys(o).length===0?void 0:o}function Em(e){let t=je(e);if(!t||typeof t.id!="string")return;let{enter:r,exit:n,duration:o,delay:a,step:i,together:l,go:d}=t,c=x=>x===void 0||dn.includes(x);if(!c(r)||!c(n)||r!==void 0&&n!==void 0||o!==void 0&&!Ns(o)||a!==void 0&&!Ns(a)||i!==void 0&&i!==!0||l!==void 0&&l!==!0||i===!0&&l===!0||d!==void 0&&(typeof d!="string"||pt(d)===void 0))return;let h={id:t.id,...r===void 0?{}:{enter:r},...n===void 0?{}:{exit:n},...o===void 0?{}:{duration:o},...a===void 0?{}:{delay:a},...i===void 0?{}:{step:i},...l===void 0?{}:{together:l},...d===void 0?{}:{go:d}};return wr(h)?h:void 0}function Ns(e){return typeof e=="number"&&e>=0&&e<=Yt}function Mm(e,t){return e==null?Tt:typeof e=="string"&&Xt.includes(e)?e:(t.push({severity:"error",code:"unknown-kind",message:`Unknown kind ${JSON.stringify(e)} \u2014 this build reads ${Xt.join(", ")}`}),Tt)}function Am(e,t){let r={};if(e===void 0)return r;let n=je(e);if(!n)return t.push({severity:"error",code:"invalid-tokens",message:"`tokens` must be an object"}),r;for(let[o,a]of Object.entries(n))typeof a=="number"||typeof a=="string"?r[o]=a:t.push({severity:"error",code:"invalid-token",message:`Token $${o} must be a number or string`});return r}function $m(e,t){let r={};if(e===void 0)return r;let n=je(e);if(!n)return t.push({severity:"error",code:"invalid-assets",message:"`assets` must be an object"}),r;for(let[o,a]of Object.entries(n)){let i=je(a);if(!i||typeof i.type!="string"||typeof i.hash!="string"||typeof i.bytes!="number"){t.push({severity:"error",code:"invalid-asset",message:`Asset "${o}" must have a "type", a "hash" and a "bytes" count`});continue}r[o]={type:i.type,hash:i.hash,bytes:i.bytes,...Qe(i.credit,"credit"),...Qe(i.source,"source"),...Qe(i.license,"license")}}return r}function Tm(e,t){let r={};if(e===void 0)return r;let n=je(e);if(!n)return t.push({severity:"error",code:"invalid-fonts",message:"`fonts` must be an object"}),r;for(let[o,a]of Object.entries(n)){let i=je(a);if(!i||typeof i.family!="string"){t.push({severity:"error",code:"invalid-font",message:`Font "${o}" must be an object with a "family"`});continue}r[o]={family:i.family,...typeof i.fallback=="string"?{fallback:i.fallback}:{},...Lm(i.faces,o,t)}}return r}function Lm(e,t,r){if(e===void 0)return{};if(!Array.isArray(e))return r.push({severity:"error",code:"invalid-font",message:`Font "${t}" has a "faces" that is not an array`}),{};let n=[];for(let o of e){let a=je(o);if(!a||typeof a.src!="string"){r.push({severity:"error",code:"invalid-font-face",message:`A face of font "${t}" is missing its "src"`});continue}let i=a.style;n.push({src:a.src,...typeof a.weight=="number"?{weight:a.weight}:{},...i==="italic"||i==="normal"?{style:i}:{}})}return n.length>0?{faces:n}:{}}function Om(e,t){let r=je(e);if(!r){t.push({severity:"error",code:"invalid-node",message:"Expected a node object"});return}switch(r.type){case"canvas":return qf(e,t);case"ellipse":return Im(r,t);case"frame":return Dm(r,t);case"group":return Pm(r,t);case"image":return Nm(r,t);case"rect":return Rm(r,t);case"text":return Bm(r,t);case"vector":return Fm(r,t);default:t.push({severity:"error",code:"unknown-node-type",message:`Unknown node type ${JSON.stringify(r.type)}`,...typeof r.id=="string"?{nodeId:r.id}:{}});return}}function qf(e,t){let r=je(e);if(!r){t.push({severity:"error",code:"invalid-node",message:"`root` must be a canvas node"});return}let n=Ot(r,lt,t);return{type:"canvas",id:n,...Qe(r.name,"name"),...Vf(r,"w",1280,n,t),...Vf(r,"h",720,n,t),...et(r.background,n,"background",t),children:Fs(r.children,n,t)}}function Vf(e,t,r,n,o){return e[t]===void 0?{}:{[t]:ge(e[t],n,t,r,o)}}function Dm(e,t){let r=Ot(e,"frame",t);return{type:"frame",id:r,...Qe(e.name,"name"),x:ge(e.x,r,"x",0,t),y:ge(e.y,r,"y",0,t),w:ge(e.w,r,"w",0,t),h:ge(e.h,r,"h",0,t),...et(e.background,r,"background",t),...Rs(e.clip,"clip"),...Rs(e.skip,"skip"),...$r(e,r,t),...rr(e),children:Fs(e.children,r,t)}}function Pm(e,t){let r=Ot(e,"group",t);return{type:"group",id:r,...Qe(e.name,"name"),...rr(e),children:Fs(e.children,r,t)}}function Fs(e,t,r){let n=[];if(Array.isArray(e))for(let o of e){let a=Om(o,r);a&&n.push(a)}else e!==void 0&&r.push({severity:"error",code:"invalid-children",message:"`children` must be an array",nodeId:t});return n}function Nm(e,t){let r=Ot(e,"image",t),n=e.fit,o=et(e.src,r,"src",t);return{type:"image",id:r,...Qe(e.name,"name"),x:ge(e.x,r,"x",0,t),y:ge(e.y,r,"y",0,t),w:ge(e.w,r,"w",100,t),h:ge(e.h,r,"h",100,t),...Ee(e.rotation,r,"rotation",t),src:o.src??"",...$t.includes(n)?{fit:n}:{},...Ee(e.radius,r,"radius",t),...Ee(e.opacity,r,"opacity",t),...$r(e,r,t),...rr(e)}}function Rm(e,t){let r=Ot(e,"rect",t);return{type:"rect",id:r,...Qe(e.name,"name"),x:ge(e.x,r,"x",0,t),y:ge(e.y,r,"y",0,t),w:ge(e.w,r,"w",100,t),h:ge(e.h,r,"h",100,t),...Ee(e.rotation,r,"rotation",t),...et(e.fill,r,"fill",t),...et(e.stroke,r,"stroke",t),...Ee(e.strokeWidth,r,"strokeWidth",t),...Ee(e.radius,r,"radius",t),...Ee(e.opacity,r,"opacity",t),...$r(e,r,t),...rr(e)}}function Im(e,t){let r=Ot(e,"ellipse",t);return{type:"ellipse",id:r,...Qe(e.name,"name"),x:ge(e.x,r,"x",0,t),y:ge(e.y,r,"y",0,t),w:ge(e.w,r,"w",100,t),h:ge(e.h,r,"h",100,t),...Ee(e.rotation,r,"rotation",t),...et(e.fill,r,"fill",t),...et(e.stroke,r,"stroke",t),...Ee(e.strokeWidth,r,"strokeWidth",t),...Ee(e.opacity,r,"opacity",t),...$r(e,r,t),...rr(e)}}function Fm(e,t){let r=Ot(e,"vector",t);return{type:"vector",id:r,...Qe(e.name,"name"),x:ge(e.x,r,"x",0,t),y:ge(e.y,r,"y",0,t),w:ge(e.w,r,"w",100,t),h:ge(e.h,r,"h",100,t),...Ee(e.rotation,r,"rotation",t),...Qe(e.view,"view"),d:typeof e.d=="string"?e.d:"",...et(e.fill,r,"fill",t),...et(e.stroke,r,"stroke",t),...Ee(e.strokeWidth,r,"strokeWidth",t),...Ee(e.opacity,r,"opacity",t),...Ar(e.rule,jt,r,"rule",t),...Ar(e.cap,Gt,r,"cap",t),...Ar(e.join,Wt,r,"join",t),...$r(e,r,t),...rr(e)}}function Bm(e,t){let r=Ot(e,"text",t);return{type:"text",id:r,...Qe(e.name,"name"),x:ge(e.x,r,"x",0,t),y:ge(e.y,r,"y",0,t),w:ge(e.w,r,"w",200,t),h:ge(e.h,r,"h",40,t),...Ee(e.rotation,r,"rotation",t),content:Hm(e.content,r,t),...et(e.font,r,"font",t),...Ee(e.size,r,"size",t),...Ee(e.weight,r,"weight",t),...Ee(e.lineHeight,r,"lineHeight",t),...Ee(e.letterSpacing,r,"letterSpacing",t),...Ar(e.align,Mt,r,"align",t),...Ar(e.valign,At,r,"valign",t),...Rs(e.italic,"italic"),...et(e.fill,r,"fill",t),...Ee(e.opacity,r,"opacity",t),...$r(e,r,t),...rr(e)}}function Hm(e,t,r){if(e===void 0)return"";if(typeof e=="string")return e;if(!Array.isArray(e))return r.push({severity:"error",code:"invalid-content",message:`Expected a string or an array of runs for content, got ${JSON.stringify(e)}`,nodeId:t,prop:"content"}),"";let n=[];for(let o of e){if(typeof o=="string"){n.push(o);continue}let a=je(o);if(!a||typeof a.text!="string"){r.push({severity:"error",code:"invalid-run",message:'A text run must be a string or an object with a "text"',nodeId:t,prop:"content"});continue}n.push({text:a.text,...gt(a,"font","string"),...gt(a,"size","number"),...gt(a,"weight","number"),...gt(a,"italic","boolean"),...gt(a,"underline","boolean"),...gt(a,"strike","boolean"),...gt(a,"fill","string"),...gt(a,"letterSpacing","number"),...gt(a,"link","string")})}return n}function gt(e,t,r){let n=e[t];return typeof n!==r?{}:r==="number"&&!Number.isFinite(n)?{}:{[t]:n}}function $r(e,t,r){return{...Ar(e.blend,Kt,t,"blend",r),...et(e.shadow,t,"shadow",r)}}function rr(e){return{...e.hidden===!0?{hidden:!0}:{},...e.locked===!0?{locked:!0}:{}}}function Rs(e,t){return typeof e=="boolean"?{[t]:e}:{}}function Ar(e,t,r,n,o){return e===void 0?{}:typeof e=="string"&&t.includes(e)?{[n]:e}:(o.push({severity:"error",code:"invalid-value",message:`Expected one of ${t.join(", ")} for ${n}, got ${JSON.stringify(e)}`,nodeId:r,prop:n}),{})}function Ot(e,t,r){let n=e.id;return typeof n=="string"&&n.length>0?n:(r.push({severity:"error",code:"missing-id",message:`Node is missing an id; using "${t}"`}),t)}function ge(e,t,r,n,o){let a=zm(e);return a!==void 0?a:(o.push({severity:"error",code:"invalid-value",message:`Expected a number or expression for ${r}, got ${JSON.stringify(e)}`,nodeId:t,prop:r}),n)}function zm(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.startsWith("="))return Et(e.slice(1))}function Ee(e,t,r,n){return e===void 0?{}:{[r]:ge(e,t,r,0,n)}}function et(e,t,r,n){return e===void 0?{}:typeof e=="string"?{[r]:e.startsWith("=")?Et(e.slice(1)):e}:(n.push({severity:"error",code:"invalid-value",message:`Expected a string for ${r}, got ${JSON.stringify(e)}`,nodeId:t,prop:r}),{})}function Qe(e,t){return typeof e=="string"?{[t]:e}:{}}function Um(e,t){let r=new Set,n=o=>{r.has(o.id)&&t.push({severity:"error",code:"duplicate-id",message:`Duplicate id ${o.id}. Addresses must be unique or patches land on the wrong node.`,nodeId:o.id}),r.add(o.id),pe(o)&&o.children.forEach(n)};n(e)}function je(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}function To(e){return/^\s*(linear|radial|conic|repeating-[a-z]+)-gradient\s*\(/i.test(e)}function bn(e){let t=e.trim(),r=/^([a-z-]+)-gradient\s*\(([\s\S]*)\)$/i.exec(t);if(!r)return To(t)?{error:'A gradient needs its closing ")"'}:{kind:"solid",colour:t};let n=r[1].toLowerCase(),o=Vm(r[2]).map(a=>a.trim());if(o.some(a=>a===""))return{error:"A gradient has an empty argument"};if(n==="linear"){let a=Km(o[0]),i=jf(a===void 0?o:o.slice(1));return"error"in i?i:{kind:"linear",angle:a??180,stops:i.stops}}if(n==="radial"){let a=Gm(o[0]);if(a&&"error"in a)return a;let i=jf(a?o.slice(1):o);return"error"in i?i:{kind:"radial",shape:a?.shape??"ellipse",cx:a?.cx??.5,cy:a?.cy??.5,stops:i.stops}}return{error:`${n}-gradient is not supported; use linear-gradient or radial-gradient`}}function Bs(e){let t=e.map(n=>n.at);t[0]===void 0&&(t[0]=0),t[t.length-1]===void 0&&(t[t.length-1]=1);let r=0;for(let n=0;n<t.length;n+=1){let o=t[n];o!==void 0&&(r=Math.max(r,o),t[n]=r)}for(let n=1;n<t.length;n+=1){if(t[n]!==void 0)continue;let o=n-1,a=n;for(;t[a]===void 0;)a+=1;let i=t[o],l=t[a];for(let d=n;d<a;d+=1)t[d]=i+(l-i)*(d-o)/(a-o);n=a}return e.map((n,o)=>({colour:n.colour,at:t[o]}))}function Vm(e){let t=[],r=0,n=0;for(let o=0;o<e.length;o+=1){let a=e[o];a==="("?r+=1:a===")"?r=Math.max(0,r-1):a===","&&r===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}var qm={top:[0,-1],bottom:[0,1],left:[-1,0],right:[1,0]};function Km(e){let t=/^(-?\d*\.?\d+)(deg|turn|rad)$/i.exec(e);if(t){let a=Number(t[1]),i=t[2].toLowerCase();return i==="turn"?a*360:i==="rad"?a*180/Math.PI:a}let r=/^to\s+([a-z]+)(?:\s+([a-z]+))?$/i.exec(e);if(!r)return;let n=0,o=0;for(let a of[r[1],r[2]]){if(a===void 0)continue;let i=qm[a.toLowerCase()];if(!i)return;n+=i[0],o+=i[1]}return(Math.atan2(n,-o)*180/Math.PI+360)%360}var jm={left:0,top:0,center:.5,right:1,bottom:1};function Gm(e){let t=/^(circle|ellipse)?\s*(?:at\s+(\S+)(?:\s+(\S+))?)?$/i.exec(e);if(!t||t[1]===void 0&&t[2]===void 0)return;let r=t[1]?.toLowerCase();if(t[2]===void 0)return r?{shape:r}:void 0;let n=Kf(t[2]),o=t[3]===void 0?.5:Kf(t[3]);return n===void 0||o===void 0?{error:`A radial centre is two percentages or keywords, not "${e}"`}:{...r?{shape:r}:{},cx:n,cy:o}}function Kf(e){let t=jm[e.toLowerCase()];if(t!==void 0)return t;let r=/^(-?\d*\.?\d+)%$/.exec(e);return r?Number(r[1])/100:void 0}function jf(e){if(e.length<2)return{error:"A gradient needs at least two colours"};let t=[];for(let r of e){let n=/^([\s\S]*?\S)\s+(-?\d*\.?\d+)%$/.exec(r);if(n&&Wm(n[1]))t.push({colour:n[1],at:Number(n[2])/100});else{if(/\s/.test(r.replace(/\([^)]*\)/g,"")))return{error:`"${r}" is not a colour with an optional percentage`};t.push({colour:r})}}return{stops:t}}function Wm(e){let t=0;for(let r of e)if(r==="("&&(t+=1),r===")"&&(t-=1),t<0)return!1;return t===0}function Lo(e){let t=bn(e);return"error"in t?[]:t.kind==="solid"?[t.colour]:t.stops.map(r=>r.colour)}function Tr(e){let t=e.trim();if(t===""||t==="none")return{shadows:[]};let r=[];for(let n of Xm(t)){let o=Ym(n.trim());if(o.includes("inset"))return{error:"Inner shadows (inset) are not supported yet"};let a=[],i=[];for(let x of o){let y=/^(-?\d*\.?\d+)(px)?$/.exec(x);y&&i.length===0?a.push(Number(y[1])):i.push(x)}if(a.length<2||a.length>4)return{error:`"${n.trim()}" needs x, y, then optional blur and spread`};if(i.length!==1)return{error:`"${n.trim()}" needs one colour after its numbers`};let[l=0,d=0,c=0,h=0]=a;if(c<0)return{error:"A shadow cannot have a negative blur"};r.push({x:l,y:d,blur:c,spread:h,colour:i[0]})}return{shadows:r}}function Xm(e){let t=[],r=0,n=0;for(let o=0;o<e.length;o+=1){let a=e[o];a==="("?r+=1:a===")"?r=Math.max(0,r-1):a===","&&r===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}function Ym(e){let t=[],r=0,n="";for(let o of e){if(o==="("&&(r+=1),o===")"&&(r=Math.max(0,r-1)),/\s/.test(o)&&r===0){n!==""&&t.push(n),n="";continue}n+=o}return n!==""&&t.push(n),t}var Hs=["rect","ellipse","vector","image","text"];function Ge(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function Be(e,t,r){if(r===0)return e;let n=r*Math.PI/180,o=Math.cos(n),a=Math.sin(n),i=e.x-t.x,l=e.y-t.y;return{x:t.x+i*o-l*a,y:t.y+i*a+l*o}}function wn(e,t,r=Ge(e)){if(t%360===0)return e;let n=[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}].map(d=>Be(d,r,t)),o=n.map(d=>d.x),a=n.map(d=>d.y),i=Math.min(...o),l=Math.min(...a);return{x:i,y:l,w:Math.max(...o)-i,h:Math.max(...a)-l}}function kn(e){let t=(e%360+360)%360,r=Math.round(t*100)/100;return r===360?0:r}var zs=["x","y","w","h","left","right","top","bottom","cx","cy"];function Sn(e){return zs.includes(e)}var Us=["parent","prev","next","self","root"];function Vs(e){return Us.includes(e)}var Pe=class extends Error{position;constructor(t,r){super(t),this.position=r,this.name="ExprSyntaxError"}},Wf=/[A-Za-z_]/,qs=/[A-Za-z0-9_]/;function Ks(e){let t=[],r=0,n=()=>{if(!Wf.test(e[r]??""))throw new Pe(`Expected a name at position ${r}`,r);let i=r;for(;r<e.length&&qs.test(e[r]??"");)r++;return e.slice(i,r)},o=()=>{if(!qs.test(e[r]??""))throw new Pe(`Expected a name at position ${r}`,r);let i=r;for(;r<e.length&&qs.test(e[r]??"");)r++;return e.slice(i,r)},a=()=>{let i=[n()];for(;e[r]===".";)r++,i.push(o());return i};for(;r<e.length;){let i=e[r]??"";if(/\s/.test(i)){r++;continue}if(/[0-9]/.test(i)){let l=r;for(;r<e.length&&/[0-9]/.test(e[r]??"");)r++;if(e[r]==="."&&/[0-9]/.test(e[r+1]??""))for(r++;r<e.length&&/[0-9]/.test(e[r]??"");)r++;let d=e.slice(l,r),c=Number(d);if(!Number.isFinite(c))throw new Pe(`Bad number "${d}"`,l);e[r]==="%"?(r++,t.push({type:"percent",value:c})):t.push({type:"number",value:c});continue}if(i==="$"){r++,t.push({type:"token",name:n()});continue}if(i==="@"){r++,t.push({type:"ref",path:a()});continue}if(Wf.test(i)){t.push({type:"word",path:a()});continue}if("+-*/()".includes(i)){r++,t.push({type:"op",value:i});continue}throw new Pe(`Unexpected character "${i}" at position ${r}`,r)}return t.push({type:"eof"}),t}var ex={"+":1,"-":1,"*":2,"/":2};function ot(e){try{let t=Ks(e),r=new js(t),n=r.parseBinary(0);return r.expectEof(),{ok:!0,ast:n}}catch(t){if(t instanceof Pe)return{ok:!1,message:t.message};throw t}}var js=class{tokens;index=0;constructor(t){this.tokens=t}peek(){return this.tokens[this.index]??{type:"eof"}}next(){let t=this.peek();return this.index++,t}expectEof(){if(this.peek().type!=="eof")throw new Pe("Unexpected trailing input",this.index)}parseBinary(t){let r=this.parseUnary();for(;;){let n=this.peek();if(n.type!=="op"||!tx(n.value))break;let o=ex[n.value];if(o<t)break;this.next();let a=this.parseBinary(o+1);r={kind:"binary",op:n.value,left:r,right:a}}return r}parseUnary(){let t=this.peek();return t.type==="op"&&(t.value==="-"||t.value==="+")?(this.next(),{kind:"unary",op:t.value,operand:this.parseUnary()}):this.parsePrimary()}parsePrimary(){let t=this.next();switch(t.type){case"number":return{kind:"number",value:t.value};case"percent":return{kind:"percent",value:t.value};case"token":return{kind:"token",name:t.name};case"ref":{if(t.path.length<2)throw new Pe(`@${t.path.join(".")} needs an edge, for example @${t.path.join(".")}.right`,this.index);return{kind:"nodeRef",path:t.path}}case"word":{let[r,n,...o]=t.path;if(r===void 0||!Vs(r))throw new Pe(`Unknown name "${t.path.join(".")}". Use $token for a token or @id.edge for a node.`,this.index);if(n===void 0||!Sn(n)||o.length>0)throw new Pe(`${r} needs an edge, for example ${r}.w`,this.index);return{kind:"relRef",word:r,edge:n}}case"op":{if(t.value==="("){let r=this.parseBinary(0),n=this.next();if(n.type!=="op"||n.value!==")")throw new Pe("Missing closing parenthesis",this.index);return r}throw new Pe(`Unexpected "${t.value}"`,this.index)}case"eof":throw new Pe("Unexpected end of expression",this.index)}}};function tx(e){return e==="+"||e==="-"||e==="*"||e==="/"}var Xf={"+":1,"-":1,"*":2,"/":2},Yf=3,rx=4;function nx(e){return e.kind==="binary"?Xf[e.op]??1:e.kind==="unary"?Yf:rx}function _n(e){return Oo(e,0)}function Oo(e,t){let r=ox(e);return nx(e)<t?`(${r})`:r}function ox(e){switch(e.kind){case"number":return Q(e.value);case"percent":return`${Q(e.value)}%`;case"token":return`$${e.name}`;case"nodeRef":return`@${e.path.join(".")}`;case"relRef":return`${e.word}.${e.edge}`;case"unary":return`${e.op}${Oo(e.operand,Yf)}`;case"binary":{let t=Xf[e.op]??1;return`${Oo(e.left,t)} ${e.op} ${Oo(e.right,t+1)}`}}}function Gs(e){return e.slice(0,-1).join(".")}function Dt(e,t){switch(e.kind){case"nodeRef":{let r=e.path[e.path.length-1],n=t(Gs(e.path));return r===void 0||n===void 0?e:{kind:"nodeRef",path:[...n.split("."),r]}}case"unary":return{...e,operand:Dt(e.operand,t)};case"binary":return{...e,left:Dt(e.left,t),right:Dt(e.right,t)};default:return e}}function nr(e){let t=new Set,r=new Set,n=o=>{switch(o.kind){case"nodeRef":t.add(Gs(o.path));return;case"token":r.add(o.name);return;case"unary":n(o.operand);return;case"binary":n(o.left),n(o.right);return;default:return}};return n(e),{nodes:[...t],tokens:[...r]}}function Ie(e,t){return`${e} ${t}`}function Ws(e){switch(e){case"x":case"left":return["x"];case"y":case"top":return["y"];case"w":return["w"];case"h":return["h"];case"right":case"cx":return["x","w"];case"bottom":case"cy":return["y","h"]}}function Do(e,t,r,n,o){switch(e){case"x":case"left":return t;case"y":case"top":return r;case"w":return n;case"h":return o;case"right":return t+n;case"bottom":return r+o;case"cx":return t+n/2;case"cy":return r+o/2}}function Xs(e){switch(e){case"x":case"left":case"right":case"cx":return"x";case"y":case"top":case"bottom":case"cy":return"y";case"w":case"h":return}}function Ys(e,t,r){let n=x=>{let y=[];for(let v=r.parentOf.get(x);v!==void 0;v=r.parentOf.get(v))y.push(v);return y},o=n(e),a=n(t),i=new Set(a),l=o.find(x=>i.has(x)),d=x=>l===void 0?x:x.slice(0,x.indexOf(l)),c=new Map([[e,1]]),h=(x,y)=>{let v=(c.get(x)??0)+y;v===0?c.delete(x):c.set(x,v)};for(let x of d(o))h(x,1);for(let x of d(a))h(x,-1);return c}function Js(e){switch(e){case"right":case"bottom":return 1;case"cx":case"cy":return .5;default:return 0}}function Po(e){if(e==="x"||e==="w")return"w";if(e==="y"||e==="h")return"h"}function Cn(e){let t=new Map,r=new Map,n=new Map,o=new Map,a=[];se(e.root,(h,x)=>{t.has(h.id)||t.set(h.id,h),a.push(h),x&&r.set(h.id,x.id),pe(h)&&h.children.forEach((y,v)=>{let D=h.children[v-1],k=h.children[v+1];D&&n.set(y.id,D.id),k&&o.set(y.id,k.id)})});let i=new Map;for(let h of a){let x=r.get(h.id);for(;x!==void 0;){let y=t.get(x);if(!y||!_e(y))break;x=r.get(x)}x!==void 0&&i.set(h.id,x)}let l=new Map,d=new Map,c=h=>{if(pe(h)){if(!_e(h)){let x=Jf(h);x.forEach((y,v)=>{let D=x[v-1],k=x[v+1];D&&l.set(y.id,D.id),k&&d.set(y.id,k.id)})}for(let x of h.children)c(x)}};return c(e.root),{rootId:e.root.id,byId:t,parentOf:r,prevOf:n,nextOf:o,layoutParentOf:i,layoutPrevOf:l,layoutNextOf:d,order:a}}function Jf(e){let t=[];for(let r of e.children)pe(r)&&_e(r)?t.push(...Jf(r)):t.push(r);return t}function No(e,t,r){if(e.kind==="relRef"){let a=ax(e.word,t,r);return a===void 0?{ok:!1,message:`${t} has no ${e.word}`}:{ok:!0,nodeId:a,edge:e.edge}}let n=e.path[e.path.length-1]??"",o=e.path.slice(0,-1).join(".");return Sn(n)?r.byId.has(o)?{ok:!0,nodeId:o,edge:n}:{ok:!1,message:`No node @${o}`}:{ok:!1,message:`"${n}" is not an edge of @${o}`}}function ax(e,t,r){switch(e){case"self":return t;case"root":return r.rootId;case"parent":return r.layoutParentOf.get(t);case"prev":return r.layoutPrevOf.get(t);case"next":return r.layoutNextOf.get(t)}}function Ae(e){let t=[],r=Cn(e),n=Zf(r),o=new Set;Qf(n,t),eu(n,e,r,o,t);let a=sx(n);ix(n,a,t);let i=lx(n,a,e,r,o,t);return{nodes:fx(e.root,i,n,t),problems:t}}function Lr(e){let t=Cn(e),r=Zf(t),n=[];Qf(r,n),eu(r,e,t,new Set,n);let o=new Map;for(let a of r.values())for(let i of a.deps){let l=o.get(i),d={nodeId:a.nodeId,prop:a.prop};l?l.push(d):o.set(i,[d])}return o}function Zf(e){let t=new Map;for(let r of e.order){let n=r;for(let o of it(r)){let a=n[o];a!==void 0&&t.set(Ie(r.id,o),{nodeId:r.id,prop:o,value:a,deps:[]})}}return t}function Qf(e,t){for(let r of e.values()){if(!me(r.value))continue;let n=ot(r.value.expr);if(n.ok){r.ast=n.ast;continue}t.push({severity:"error",code:"expression-syntax",message:n.message,nodeId:r.nodeId,prop:r.prop})}}function eu(e,t,r,n,o){for(let a of e.values()){if(!a.ast)continue;let i=new Set,l=d=>{switch(d.kind){case"number":return;case"token":{let c=t.tokens[d.name];typeof c!="number"&&o.push({severity:"error",code:c===void 0?"unknown-token":"token-not-a-number",message:c===void 0?`Unknown token $${d.name}`:`Token $${d.name} is not a number`,nodeId:a.nodeId,prop:a.prop});return}case"percent":{let c=Po(a.prop);if(!c)return;let h=r.layoutParentOf.get(a.nodeId),x=h===void 0?void 0:Ie(h,c);if(x===void 0||!e.has(x)){o.push({severity:"error",code:"percent-without-parent",message:`${a.nodeId}.${a.prop} uses a percentage but has no parent to measure against`,nodeId:a.nodeId,prop:a.prop});return}i.add(x);return}case"nodeRef":case"relRef":{let c=No(d,a.nodeId,r);if(!c.ok){n.add(d),o.push({severity:"error",code:"unknown-reference",message:c.message,nodeId:a.nodeId,prop:a.prop});return}let h=y=>{e.has(y)&&i.add(y)},x=Xs(c.edge);if(!x){for(let y of Ws(c.edge))h(Ie(c.nodeId,y));return}for(let y of Ys(c.nodeId,a.nodeId,r).keys())h(Ie(y,x));Js(c.edge)!==0&&h(Ie(c.nodeId,x==="x"?"w":"h"));return}case"unary":l(d.operand);return;case"binary":l(d.left),l(d.right);return}};l(a.ast),a.deps=[...i]}}function sx(e){let t=new Map,r=new Map;for(let[a,i]of e){t.set(a,i.deps.length);for(let l of i.deps){let d=r.get(l);d?d.push(a):r.set(l,[a])}}let n=[];for(let[a,i]of t)i===0&&n.push(a);let o=[];for(let a=0;a<n.length;a++){let i=n[a];o.push(i);for(let l of r.get(i)??[]){let d=(t.get(l)??0)-1;t.set(l,d),d===0&&n.push(l)}}return o}function ix(e,t,r){if(t.length===e.size)return;let n=new Set(t);for(let[o,a]of e)n.has(o)||r.push({severity:"error",code:"cycle",message:`${a.nodeId}.${a.prop} is part of a dependency cycle`,nodeId:a.nodeId,prop:a.prop})}function lx(e,t,r,n,o,a){let i=new Map,l=(d,c)=>i.get(Ie(d,c))??0;for(let d of t){let c=e.get(d);if(c){if(!me(c.value)){i.set(d,c.value);continue}if(!c.ast){i.set(d,0);continue}i.set(d,tu(c.ast,c,r,n,o,a,l))}}return i}function tu(e,t,r,n,o,a,i){let l=d=>tu(d,t,r,n,o,a,i);switch(e.kind){case"number":return e.value;case"token":{let d=r.tokens[e.name];return typeof d=="number"?d:0}case"percent":{let d=Po(t.prop);if(!d)return e.value/100;let c=n.layoutParentOf.get(t.nodeId);return c===void 0?0:e.value/100*i(c,d)}case"nodeRef":case"relRef":{if(o.has(e))return 0;let d=No(e,t.nodeId,n);if(!d.ok)return 0;let c=Xs(d.edge);if(!c)return Do(d.edge,i(d.nodeId,"x"),i(d.nodeId,"y"),i(d.nodeId,"w"),i(d.nodeId,"h"));let h=Js(d.edge)*i(d.nodeId,c==="x"?"w":"h");for(let[x,y]of Ys(d.nodeId,t.nodeId,n))h+=y*i(x,c);return h}case"unary":{let d=l(e.operand);return e.op==="-"?-d:d}case"binary":{let d=l(e.left),c=l(e.right);if(e.op==="/"&&c===0)return a.push({severity:"error",code:"divide-by-zero",message:`${t.nodeId}.${t.prop} divides by zero`,nodeId:t.nodeId,prop:t.prop}),0;let h=dx(e.op,d,c);return Number.isFinite(h)?h:(a.push({severity:"error",code:"not-a-number",message:`${t.nodeId}.${t.prop} did not produce a finite number`,nodeId:t.nodeId,prop:t.prop}),0)}}}function dx(e,t,r){switch(e){case"+":return t+r;case"-":return t-r;case"*":return t*r;case"/":return t/r}}function fx(e,t,r,n){let o=new Map,a=(l,d)=>t.get(Ie(l,d))??0,i=(l,d,c)=>{let h=a(l.id,"x"),x=a(l.id,"y"),y=a(l.id,"w"),v=a(l.id,"h"),D={};for(let B of it(l)){let N=Ie(l.id,B);r.has(N)&&(D[B]=t.get(N)??0)}(y<0||v<0)&&n.push({severity:"warning",code:"negative-size",message:`${l.id} resolved to a negative size`,nodeId:l.id});let k=d+h,S=c+x;if(o.set(l.id,{id:l.id,type:l.type,x:h,y:x,w:y,h:v,left:h,top:x,right:h+y,bottom:x+v,cx:h+y/2,cy:x+v/2,absX:k,absY:S,values:D}),pe(l))for(let B of l.children)i(B,k,S)};return i(e,0,0),o}function Ro(e){if(!me(e))return{kind:"literal",value:e};let t=ot(e.expr);return t.ok?t.ast.kind==="number"?{kind:"literal",value:t.ast.value}:t.ast.kind==="token"?{kind:"token",name:t.ast.name}:{kind:"complex",source:e.expr,ast:t.ast}:{kind:"complex",source:e.expr,error:t.message}}var nu="system-ui, -apple-system, Segoe UI, Roboto, sans-serif",ou=16,au=400,su=1.2,Io="#0F172A";function En(){return{advance(e,t){return e.length*(t.size*.5+t.letterSpacing)},metrics(e){return{ascent:e.size*.8,descent:e.size*.2,lineGap:0}}}}function Zs(e,t){if(e===void 0)return nu;let r=t[e];return r?r.fallback?`${ru(r.family)}, ${r.fallback}`:ru(r.family):e}function ru(e){return/^[A-Za-z][A-Za-z0-9 -]*$/.test(e)?e:JSON.stringify(e)}function Qs(e,t,r,n){let o={family:Zs(t.font,r),size:t.size,weight:t.weight,italic:t.italic,underline:!1,strike:!1,fill:n(t.fill),letterSpacing:t.letterSpacing},a=typeof e=="string"?[e]:e,i=[];for(let l of a){if(typeof l=="string"){l.length>0&&i.push({text:l,style:o});continue}let d=l;d.text.length!==0&&i.push({text:d.text,style:{family:d.font===void 0?o.family:Zs(d.font,r),size:d.size??o.size,weight:d.weight??o.weight,italic:d.italic??o.italic,underline:d.underline??!1,strike:d.strike??!1,fill:d.fill===void 0?o.fill:n(d.fill),letterSpacing:d.letterSpacing??o.letterSpacing,...d.link!==void 0&&nt(d.link)?{link:d.link}:{}}})}return i}function ux(e,t){let r=[];for(let n of e)for(let o of n.text.split(/(\n)/))if(o!==""){if(o===`
38
+ `){let a=r[r.length-1];a&&!a.hardBreak?r[r.length-1]={...a,hardBreak:!0}:r.push({text:"",style:n.style,w:0,hardBreak:!0});continue}for(let a of o.match(/\S+\s*|\s+/g)??[])r.push({text:a,style:n.style,w:t.advance(a,n.style),hardBreak:!1})}return r}function cx(e,t,r){let n=[...e.text],o=[],a="";for(let i of n){let l=a+i;if(a!==""&&r.advance(l,e.style)>t){o.push({text:a,style:e.style,w:r.advance(a,e.style),hardBreak:!1}),a=i;continue}a=l}return a!==""&&o.push({text:a,style:e.style,w:r.advance(a,e.style),hardBreak:e.hardBreak}),o.length>0?o:[e]}function iu(e,t){let{width:r,measure:n}=t,o=ux(n.itemize?e.flatMap(c=>n.itemize?.(c)??[c]):e,n);if(o.length===0){let c=e[0]?.style,h=c?t.lineHeight*c.size:0;return{lines:c?[px(c,t.lineHeight)]:[],width:0,height:h}}let a=[],i=[],l=0,d=()=>{a.push(i),i=[],l=0};for(let c of o){let h=i.length===0&&c.w>r&&r>0?cx(c,r,n):[c];for(let x of h){let y=x.text.trimEnd(),v=y===x.text?x.w:n.advance(y,x.style);i.length>0&&l+v>r&&d(),i.push(x),l+=x.w,x.hardBreak&&d()}}return i.length>0&&a.push(i),hx(a,t)}function px(e,t){let r=t*e.size;return{y:0,h:r,baseline:r*.8,w:0,spans:[],style:e}}function hx(e,t){let r=[],n=0,o=0;return e.forEach((a,i)=>{let l=a.map(C=>C.style.size),d=Math.max(...l,0),c=t.lineHeight*d,h=a.map(C=>t.measure.metrics(C.style)),x=Math.max(...h.map(C=>C.ascent),0),y=Math.max(...h.map(C=>C.descent),0),v=n+(c-(x+y))/2+x,D=mx(a,t.measure),k=D.reduce((C,G)=>C+G.w,0);o=Math.max(o,k);let S=i===e.length-1||(a[a.length-1]?.hardBreak??!1),B=t.align==="justify"&&!S&&D.length>1,N=Math.max(0,t.width-k),J=t.align==="center"?N/2:t.align==="right"?N:0,E=B?N/(D.length-1):0,P=[],R=J;D.forEach((C,G)=>{P.push({text:C.text,style:C.style,x:R,w:C.w}),R+=C.w+(G<D.length-1?E:0)}),r.push({y:n,h:c,baseline:v,w:k,spans:xx(P,B)}),n+=c}),{lines:r,width:o,height:n}}function mx(e,t){let r=[...e];for(;r.length>0;){let n=r[r.length-1],o=n.text.trimEnd();if(o===n.text)break;if(o===""){r.pop();continue}r[r.length-1]={...n,text:o,w:t.advance(o,n.style)};break}return r}function xx(e,t){if(t)return[...e];let r=[];for(let n of e){let o=r[r.length-1];if(o&&lu(o.style,n.style)&&Math.abs(o.x+o.w-n.x)<.01){r[r.length-1]={...o,text:o.text+n.text,w:o.w+n.w};continue}r.push(n)}return r}function lu(e,t){return e.family===t.family&&e.size===t.size&&e.weight===t.weight&&e.italic===t.italic&&e.underline===t.underline&&e.strike===t.strike&&e.fill===t.fill&&e.letterSpacing===t.letterSpacing&&e.link===t.link}function ei(e,t,r,n,o,a){let i={size:t.size??ou,weight:t.weight??au,lineHeight:t.lineHeight??su,letterSpacing:t.letterSpacing??0,italic:e.italic??!1,font:typeof e.font=="string"?e.font:void 0,fill:typeof e.fill=="string"?e.fill:Io},l=Qs(e.content,i,n,o),d=Qs(" ",i,n,o).map(c=>({...c,text:""}));return iu(l.length>0?l:d,{width:r,align:e.align??"left",lineHeight:i.lineHeight,measure:a})}function ti(e,t,r){let n=t-r;return e.valign==="middle"?n/2:e.valign==="bottom"?n:0}function ri(e){return e.lines.filter(t=>t.spans.length>0)}function ni(e){switch(e.kind){case"text":{let t=ri(e),r=Math.max(e.w,...t.map(o=>o.w)),n=Math.max(e.y+e.h,...t.map(o=>o.y+o.h));return{x:e.x,y:e.y,w:r,h:n-e.y}}case"vector":{let t=Zt(e.contours)??{x:e.x,y:e.y,w:e.w,h:e.h},r=e.stroke!==void 0?e.strokeWidth*2:0;return{x:t.x-r,y:t.y-r,w:t.w+r*2,h:t.h+r*2}}case"rect":case"ellipse":{let t=e.stroke!==void 0?e.strokeWidth/2:0;return{x:e.x-t,y:e.y-t,w:e.w+t*2,h:e.h+t*2}}case"frame":case"image":return{x:e.x,y:e.y,w:e.w,h:e.h}}}function Ho(e,t){let r=e.x,n=e.y,o=e.x+e.w,a=e.y+e.h;for(let i of t){let l=i.spread+i.blur;r=Math.min(r,e.x+i.x-l),n=Math.min(n,e.y+i.y-l),o=Math.max(o,e.x+e.w+i.x+l),a=Math.max(a,e.y+e.h+i.y+l)}return{x:r,y:n,w:o-r,h:a-n}}var uu="vd-paint-";var Bo="#CBD5E1",cu="#FFFFFF";function $n(e,t,r={}){let n=[...t.problems],o=[],a=[],i=r.measure??En(),l=_x(e.tokens,n),d=l.paint,c=new Map;se(e.root,(k,S)=>{if("hidden"in k&&k.hidden===!0)return!1;let B=S?c.get(S.id):void 0,N=t.nodes.get(k.id);if(!N){c.set(k.id,B);return}if(k.type==="frame"){k.skip===!0&&S!==e.root&&n.push({severity:"warning",code:"skip-not-a-page",message:`${k.id}: skip only applies to a page, a frame at the top level`,nodeId:k.id,prop:"skip"});let E={x:N.absX,y:N.absY,w:Math.max(0,N.w),h:Math.max(0,N.h)};c.set(k.id,k.clip===!0?k.id:B),k.clip===!0&&a.push({id:k.id,...E,parent:B}),o.push({kind:"frame",id:k.id,...E,background:d(k.background,k.id,"background",E),clip:B,blend:k.blend??"normal",shadows:Or(k.shadow,k.id,e.tokens,n),rotation:0});return}if(c.set(k.id,B),k.type==="text"){o.push(yx(k,N,e,i,n,B,d));return}if(k.type==="image"){o.push({kind:"image",id:k.id,x:N.absX,y:N.absY,w:Math.max(0,N.w),h:Math.max(0,N.h),href:Mx(k,e,r.resolveAsset,n),fit:k.fit??"fill",radius:Math.max(0,N.values.radius??0),opacity:An(N.values.opacity??1),clip:B,blend:k.blend??"normal",shadows:Or(k.shadow,k.id,e.tokens,n),rotation:N.values.rotation??0});return}if(k.type==="ellipse"){let E=fu(N);o.push({kind:"ellipse",id:k.id,...E,fill:d(k.fill,k.id,"fill",E)??Bo,stroke:d(k.stroke,k.id,"stroke",E),strokeWidth:N.values.strokeWidth??0,opacity:An(N.values.opacity??1),clip:B,blend:k.blend??"normal",shadows:Or(k.shadow,k.id,e.tokens,n),rotation:N.values.rotation??0});return}if(k.type==="vector"){o.push(Sx(k,N,n,B,d,Or(k.shadow,k.id,e.tokens,n)));return}if(k.type!=="rect")return;let J=fu(N);o.push({kind:"rect",id:k.id,...J,fill:d(k.fill,k.id,"fill",J)??Bo,stroke:d(k.stroke,k.id,"stroke",J),strokeWidth:N.values.strokeWidth??0,radius:Math.max(0,N.values.radius??0),opacity:An(N.values.opacity??1),clip:B,blend:k.blend??"normal",shadows:Or(k.shadow,k.id,e.tokens,n),rotation:N.values.rotation??0})});let h=t.nodes.get(e.root.id),x=e.root.w!==void 0&&e.root.h!==void 0,y=x?{x:0,y:0,width:Math.max(0,h?.w??0),height:Math.max(0,h?.h??0)}:gx(o,a),v={x:y.x,y:y.y,w:y.width,h:y.height},D=d(e.root.background,e.root.id,"background",v);return{...y,background:x?D??cu:D,items:o,clips:a,gradients:l.gradients,problems:n}}function gx(e,t){let r=new Map;for(let l of t){let d=l.parent===void 0?void 0:r.get(l.parent);r.set(l.id,d?du(l,d):l)}let n=1/0,o=1/0,a=-1/0,i=-1/0;for(let l of e){let d=l.kind==="text"&&ri(l).length>0?Math.max(l.h,l.height):l.h,c=l.clip===void 0?void 0:r.get(l.clip),h=wn(Ho({x:l.x,y:l.y,w:l.w,h:d},l.shadows),l.rotation,Ge(l)),x=c?du(h,c):h;x.w<=0||x.h<=0||(n=Math.min(n,x.x),o=Math.min(o,x.y),a=Math.max(a,x.x+x.w),i=Math.max(i,x.y+x.h))}return Number.isFinite(n)?{x:n,y:o,width:a-n,height:i-o}:{x:0,y:0,width:0,height:0}}function du(e,t){let r=Math.max(e.x,t.x),n=Math.max(e.y,t.y);return{x:r,y:n,w:Math.min(e.x+e.w,t.x+t.w)-r,h:Math.min(e.y+e.h,t.y+t.h)-n}}function yx(e,t,r,n,o,a,i){let l=Math.max(0,t.w),d=Math.max(0,t.h),c={x:t.absX,y:t.absY,w:l,h:d},h=ei(e,t.values,l,r.fonts,v=>i(v,e.id,"fill",c)??Io,n);!h.lines.every(v=>v.spans.length===0)&&h.height>d+.5&&o.push({severity:"warning",code:"text-overflow",message:`${e.id} needs ${Math.ceil(h.height)}px but its height is ${Math.round(d)}px`,nodeId:e.id,prop:"h"}),vx(e,r,o);let y=t.absY+ti(e,d,h.height);return{kind:"text",id:e.id,x:t.absX,y:t.absY,w:l,h:d,clip:a,blend:e.blend??"normal",shadows:Or(e.shadow,e.id,r.tokens,o),rotation:t.values.rotation??0,opacity:An(t.values.opacity??1),height:h.height,lines:h.lines.map(v=>({y:y+v.y,h:v.h,baseline:y+v.baseline,w:v.w,spans:v.spans.map(D=>({text:D.text,x:t.absX+D.x,y:y+v.baseline,w:D.w,style:D.style})),...v.style?{style:v.style}:{}}))}}function vx(e,t,r){if(typeof e.content!="string")for(let n of e.content){if(typeof n=="string"||n.link===void 0)continue;let o=nt(n.link);if(!o){r.push({severity:"warning",code:"invalid-link",message:`${e.id}: links go to https:, mailto: or #<frame>, not ${JSON.stringify(n.link)}`,nodeId:e.id,prop:"content"});continue}o.kind==="frame"&&!bx(t,o.id)&&r.push({severity:"warning",code:"link-target-missing",message:`${e.id}: links to #${o.id}, which is not a frame`,nodeId:e.id,prop:"content"})}}function bx(e,t){let r=!1;return se(e.root,n=>{if(r)return!1;n.id===t&&n.type==="frame"&&(r=!0)}),r}var Mn=new Map,wx=512;function kx(e){let t=Mn.get(e);if(t)return t;let r=cn(e);return Mn.size>=wx&&Mn.delete(Mn.keys().next().value),Mn.set(e,r),r}function Sx(e,t,r,n,o,a){let i=Math.max(0,t.w),l=Math.max(0,t.h),d={x:t.absX,y:t.absY,w:i,h:l},{contours:c,error:h}=kx(e.d);h!==void 0&&r.push({severity:"error",code:"bad-path",message:`${e.id}: ${h}`,nodeId:e.id,prop:"d"}),e.view!==void 0&&So(e.view)===void 0&&r.push({severity:"warning",code:"bad-view",message:`${e.id}: view must be four numbers, like "0 0 24 24"`,nodeId:e.id,prop:"view"});let x=xt(c,xn(mn(e.view,i,l),d));return{kind:"vector",id:e.id,...d,d:mt(x),contours:x,fill:o(e.fill,e.id,"fill",d)??Bo,stroke:o(e.stroke,e.id,"stroke",d),strokeWidth:t.values.strokeWidth??0,opacity:An(t.values.opacity??1),rule:e.rule??"nonzero",cap:e.cap??"butt",join:e.join??"miter",clip:n,blend:e.blend??"normal",shadows:a,rotation:t.values.rotation??0}}function pu(e,t,r,n,o){if(e===void 0)return;if(me(e)){o.push({severity:"warning",code:"expression-not-supported",message:`Expressions are not supported for ${n} yet; grammar v0 is numeric only`,nodeId:r,prop:n});return}let a=t[e];if(a===void 0)return e;if(typeof a=="string")return a;o.push({severity:"error",code:"token-not-a-colour",message:`Token $${e} is a number, not a colour`,nodeId:r,prop:n})}function fu(e){return{x:e.absX,y:e.absY,w:Math.max(0,e.w),h:Math.max(0,e.h)}}function _x(e,t){let r=[],n=new Map;return{paint:(a,i,l,d)=>{let c=pu(a,e,i,l,t);if(c===void 0)return;let h=bn(c);if("error"in h){t.push({severity:"error",code:"invalid-paint",message:`${i}: ${h.error}`,nodeId:i,prop:l});return}if(h.kind==="solid")return c;let x=`${i}\0${l}\0${c}`,y=n.get(x);if(y!==void 0)return`url(#${y})`;let v=[...n.keys()].filter(S=>S.startsWith(`${i}\0${l}\0`)).length,D=`${uu}${i}-${l}${v===0?"":`-${v+1}`}`;n.set(x,D);let k=Bs(h.stops).map(S=>({offset:S.at,colour:hu(S.colour,e,i,l,t)}));return r.push(Ex(h,D,d,Cx(k))),`url(#${D})`},gradients:r}}function Or(e,t,r,n){let o=pu(e,r,t,"shadow",n);if(o===void 0)return[];let a=Tr(o);return"error"in a?(n.push({severity:"error",code:"invalid-shadow",message:`${t}: ${a.error}`,nodeId:t,prop:"shadow"}),[]):a.shadows.map(i=>({...i,colour:hu(i.colour,r,t,"shadow",n)}))}function Cx(e){return e.map((t,r)=>{if(t.colour.trim().toLowerCase()!=="transparent")return t;let n=[e[r-1],e[r+1]].find(o=>o!==void 0&&o.colour.trim().toLowerCase()!=="transparent");return n===void 0?t:{offset:t.offset,colour:n.colour,opacity:0}})}function hu(e,t,r,n,o){let a=t[e];return a===void 0?e:typeof a=="string"&&!To(a)?a:(o.push({severity:"error",code:"invalid-paint",message:`${r}: a gradient stop names $${e}, which is not a colour`,nodeId:r,prop:n}),"transparent")}function Ex(e,t,r,n){if(e.kind==="linear"){let c=e.angle*Math.PI/180,h=Math.sin(c),x=-Math.cos(c),y=(Math.abs(r.w*h)+Math.abs(r.h*x))/2,v=r.x+r.w/2,D=r.y+r.h/2;return{id:t,kind:"linear",x1:Fo(v-h*y),y1:Fo(D-x*y),x2:Fo(v+h*y),y2:Fo(D+x*y),stops:n}}let o=r.x+r.w*e.cx,a=r.y+r.h*e.cy,i={x:Math.max(o-r.x,r.x+r.w-o),y:Math.max(a-r.y,r.y+r.h-a)};if(e.shape==="circle"||i.x===0||i.y===0){let c=Math.hypot(i.x,i.y);return{id:t,kind:"radial",cx:o,cy:a,rx:c,ry:c,stops:n}}let l=i.x/i.y,d=Math.hypot(i.x/l,i.y);return{id:t,kind:"radial",cx:o,cy:a,rx:d*l,ry:d,stops:n}}function Fo(e){return Math.round(e*1e6)/1e6}function An(e){return Math.min(Math.max(e,0),1)}function Mx(e,t,r,n){let o=me(e.src)?void 0:e.src,a=o===void 0?void 0:t.assets[o];if(!a){n.push({severity:"warning",code:"missing-asset",message:`No picture for ${JSON.stringify(o??e.src)} yet: an image slot waiting for one`,nodeId:e.id,prop:"src"});return}let i=r?.(a,o);return i===void 0&&n.push({severity:"warning",code:"unresolved-asset",message:`The bytes for asset "${o}" are not available here`,nodeId:e.id,prop:"src"}),i}var mu="vd-clip-";function oi(e){return $x(e,"")}function $x(e,t){let r=e.parent===void 0?"":` clip-path="url(#${Dr(t+mu+e.parent)})"`;return`<clipPath id="${Dr(t+mu+e.id)}"${r}><rect x="${Q(e.x)}" y="${Q(e.y)}" width="${Q(e.w)}" height="${Q(e.h)}"/></clipPath>`}function ai(e){return Tx(e,"")}function Tx(e,t){let r=e.stops.map(o=>`<stop offset="${Q(o.offset)}" stop-color="${Dr(o.colour)}"${o.opacity===void 0?"":` stop-opacity="${Q(o.opacity)}"`}/>`).join(""),n=Dr(t+e.id);return e.kind==="linear"?`<linearGradient id="${n}" gradientUnits="userSpaceOnUse" x1="${Q(e.x1)}" y1="${Q(e.y1)}" x2="${Q(e.x2)}" y2="${Q(e.y2)}">${r}</linearGradient>`:`<radialGradient id="${n}" gradientUnits="userSpaceOnUse" cx="0" cy="0" r="1" gradientTransform="matrix(${Q(e.rx)} 0 0 ${Q(e.ry)} ${Q(e.cx)} ${Q(e.cy)})">${r}</radialGradient>`}var zo="vd-shadow-";function si(e,t=!1){return Lx(e,t,"")}function Lx(e,t,r){let n=Ho(ni(e),e.shadows),o=2,a=[];e.shadows.forEach((l,d)=>{let c=`s${d}`,h="SourceAlpha";l.spread!==0&&(a.push(`<feMorphology in="${h}" operator="${l.spread>0?"dilate":"erode"}" radius="${Q(Math.abs(l.spread))}" result="${c}m"/>`),h=`${c}m`),l.blur>0&&(a.push(`<feGaussianBlur in="${h}" stdDeviation="${Q(l.blur/2)}" result="${c}b"/>`),h=`${c}b`),a.push(`<feOffset in="${h}" dx="${Q(l.x)}" dy="${Q(l.y)}" result="${c}o"/>`,`<feFlood flood-color="${Dr(l.colour)}" result="${c}c"/>`,`<feComposite in="${c}c" in2="${c}o" operator="in" result="${c}"/>`)});let i=e.shadows.map((l,d)=>`<feMergeNode in="s${e.shadows.length-1-d}"/>`).join("");return`<filter id="${Dr(r+zo+e.id)}" filterUnits="userSpaceOnUse" x="${Q(n.x-o)}" y="${Q(n.y-o)}" width="${Q(n.w+o*2)}" height="${Q(n.h+o*2)}" color-interpolation-filters="sRGB">`+a.join("")+`<feMerge>${i}${t?"":'<feMergeNode in="SourceGraphic"/>'}</feMerge></filter>`}function ii(e){return`rotate(${Q(e.rotation)} ${Q(e.x+e.w/2)} ${Q(e.y+e.h/2)})`}function li(e){return e.rotation!==0&&e.clip!==void 0}function Dr(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var Px=.8,Nx=.2;function di(e,t){let n=e.createElement("canvas").getContext("2d"),o=En(),a=new Map,i=new Map,l=new Set;function d(h){return`${h.italic?"italic ":""}${h.weight} ${h.size}px ${h.family}`}function c(){a.clear(),i.clear()}return{advance(h,x){if(!n)return o.advance(h,x);let y=d(x),v=`${y}\0${x.letterSpacing}\0${h}`,D=a.get(v);if(D!==void 0)return D;n.font=y;let k=n.measureText(h).width+x.letterSpacing*[...h].length;return a.set(v,k),k},metrics(h){if(!n)return o.metrics(h);let x=d(h),y=i.get(x);if(y)return y;n.font=x;let v=n.measureText("Hxg"),D=v.fontBoundingBoxAscent??h.size*Px,k=v.fontBoundingBoxDescent??h.size*Nx,S={ascent:D,descent:k,lineGap:0};return i.set(x,S),S},load(h,x){let y=e.fonts;if(!y||typeof FontFace!="function")return!1;let v=!1;for(let D of Object.values(h.fonts))for(let k of Rx(D)){let S=`${D.family}\0${k.src}\0${k.weight??400}\0${k.style??"normal"}`;if(l.has(S))continue;l.add(S);let B=k.src.startsWith("data:")?void 0:x?.(k.src),N={weight:String(k.weight??400),style:k.style??"normal"},J=E=>{let P=new FontFace(D.family,typeof E=="string"?`url(${E})`:Ix(E),N);y.add(P),P.load().then(()=>{c(),t?.()},()=>{y.delete(P)})};B===void 0?J(k.src):(v=!0,B.then(J,()=>{}))}return v},invalidate:c,destroy(){c(),l.clear()}}}function Rx(e){return e.faces??[]}function Ix(e){return e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}var Uo={x:0,y:0,zoom:1},gu=.02,yu=64;function Pr(e){return Number.isFinite(e)?Math.min(Math.max(e,gu),yu):1}function Vo(e,t){return{x:(t.x-e.x)/e.zoom,y:(t.y-e.y)/e.zoom}}function fi(e,t){return{x:t.x*e.zoom+e.x,y:t.y*e.zoom+e.y}}function qo(e,t,r){let n=Pr(e.zoom*r),o=Vo(e,t);return{zoom:n,x:t.x-o.x*n,y:t.y-o.y*n}}function Pt(e,t,r){return{...e,x:e.x+t,y:e.y+r}}function ui(e){return`translate(${e.x} ${e.y}) scale(${e.zoom})`}function or(e,t,r){let n={width:Math.max(1,t.width-r*2),height:Math.max(1,t.height-r*2)};if(e.width<=0||e.height<=0)return Uo;let o=Pr(Math.min(n.width/e.width,n.height/e.height));return{zoom:o,x:(t.width-e.width*o)/2-(e.x??0)*o,y:(t.height-e.height*o)/2-(e.y??0)*o}}var ie="http://www.w3.org/2000/svg",vu="vd-viewer-styles",bu=`
39
39
  .vd-viewer {
40
40
  position: relative;
41
41
  overflow: hidden;
@@ -57,10 +57,11 @@ ${Zt}`);return t===-1?-1:t+1}function sm(e){let t=new Set;for(let r of e.matchAl
57
57
  .vd-viewer__surface text {
58
58
  white-space: pre;
59
59
  }
60
- .vd-viewer__camera {
61
- /* Hints the compositor that this subtree is about to be transformed. */
62
- will-change: transform;
63
- }
60
+ /* No \`will-change\` on the camera group. It made the document its own
61
+ composited layer, and every camera step then rebuilt the compositor's layer
62
+ list from one entry per clipped or filtered item: 40 ms a step at 60 pages,
63
+ most of a pan. Without it a step repaints what is on screen instead, which is
64
+ cheap except under a large blur. */
64
65
  .vd-viewer__page {
65
66
  /* An embedder with a no-shadow brand sets --vd-page-shadow: none. */
66
67
  filter: var(--vd-page-shadow, drop-shadow(0 6px 24px rgb(0 0 0 / 0.35)));
@@ -133,7 +134,7 @@ ${Zt}`);return t===-1?-1:t+1}function sm(e){let t=new Set;for(let r of e.matchAl
133
134
  .vd-viewer--interacting .vd-viewer__page {
134
135
  filter: none;
135
136
  }
136
- `;function yu(e){if(e.getElementById(xu))return;let t=e.createElement("style");t.id=xu,t.textContent=gu,e.head.appendChild(t)}function bu(e,t,r,n){return t?Ox(e,t,r,n):Lx(e,r,n)}function Lx(e,t,r){let n=ri(e,r);return{measurer:n,update:o=>{n.load(o,t)},afterPaint:()=>{},destroy:()=>n.destroy()}}var vu=new WeakMap;function Ox(e,t,r,n){let o,a,i,l=()=>{if(!o)throw new Error("canvasFonts: update() before measuring");return o};return{measurer:{advance:(c,h)=>l().measurer.advance(c,h),metrics:c=>l().measurer.metrics(c),itemize:c=>l().measurer.itemize(c)},update(c){o&&c.fonts===a||(i?.(),o?.dispose(),o=t.forDocument(c,r?{loader:r}:{}),a=c.fonts,i=o.onChange(n))},afterPaint(){let c=e.fonts;if(!o||!c||typeof FontFace!="function")return;let h=vu.get(e);h||vu.set(e,h=new Set);for(let x of o.usedFaces()){if(h.has(x.id))continue;h.add(x.id);let y=new FontFace(x.id,Dx(x.bytes),{weight:String(x.weight),style:x.style});c.add(y),y.load().catch(()=>c.delete(y))}},destroy(){i?.(),o?.dispose(),o=void 0}}}function Dx(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}var Px=.01,Nx=.004,wu=40,Rx=16;function Ho(e,t){yu(e.ownerDocument);let r=t.document,n=S=>bu(e.ownerDocument,S,t.loadFont,()=>{E(r)}),o=n(t.fonts),a={advance:(S,U)=>o.measurer.advance(S,U),metrics:S=>o.measurer.metrics(S),itemize:S=>o.measurer.itemize?.(S)??[S]};o.update(r);let i=Ae(r),l=()=>t.resolveAsset?{measure:a,resolveAsset:t.resolveAsset}:{measure:a},d=_n(r,i,l()),c=t.camera??Io,h=t.interactive??!0,x=t.wheel??"always";e.classList.add("vd-viewer"),t.surface&&(e.style.background=t.surface);let y=e.ownerDocument.createElementNS(ne,"svg");y.setAttribute("class","vd-viewer__surface"),y.setAttribute("width","100%"),y.setAttribute("height","100%");let b=e.ownerDocument.createElementNS(ne,"g");b.setAttribute("class","vd-viewer__camera"),b.style.isolation="isolate",y.appendChild(b);let P=e.ownerDocument.createElementNS(ne,"defs");b.appendChild(P);let k=e.ownerDocument.createElementNS(ne,"rect");k.setAttribute("class","vd-viewer__page"),b.appendChild(k),e.appendChild(y);let _=new Map;function B(){b.setAttribute("transform",oi(c))}function R(){J();let S=d.background!==void 0;k.setAttribute("x",String(d.x)),k.setAttribute("y",String(d.y)),k.setAttribute("width",String(S?d.width:0)),k.setAttribute("height",String(S?d.height:0)),ye(k,"fill",d.background??null);let U=new Set,W=k;for(let I of d.items){U.add(I.id);let z=_.get(I.id);(!z||z.tagName!==ku(I))&&(z?.remove(),z=e.ownerDocument.createElementNS(ne,ku(I)),z.setAttribute("data-vd-id",I.id),_.set(I.id,z)),Fx(z,I),W.nextSibling!==z&&b.insertBefore(z,W.nextSibling),W=z}for(let[I,z]of _)U.has(I)||(z.remove(),_.delete(I));o.afterPaint(),t.onSceneChange?.(d,r)}function J(){P.replaceChildren();let S=d.items.filter(U=>U.shadows.length>0);if(d.gradients.length>0||S.length>0){let U=`<svg xmlns="${ne}">${d.gradients.map(Zs).join("")}${S.map(I=>Qs(I)).join("")}</svg>`,W=new DOMParser().parseFromString(U,"image/svg+xml");for(let I of[...W.documentElement.children])P.appendChild(e.ownerDocument.importNode(I,!0))}for(let U of d.clips){let W=e.ownerDocument.createElementNS(ne,"clipPath");W.setAttribute("id",_u(U.id)),U.parent!==void 0&&W.setAttribute("clip-path",si(U.parent));let I=e.ownerDocument.createElementNS(ne,"rect");I.setAttribute("x",String(U.x)),I.setAttribute("y",String(U.y)),I.setAttribute("width",String(U.w)),I.setAttribute("height",String(U.h)),W.appendChild(I),P.appendChild(W)}}function E(S){r=S,o.update(r),i=Ae(r),d=_n(r,i,l()),R()}function D(S){let U=e.getBoundingClientRect();return{x:S.clientX-U.left,y:S.clientY-U.top}}let N=0,A=0;function G(){e.classList.add("vd-viewer--interacting"),A&&clearTimeout(A),A=setTimeout(()=>{A=0,e.classList.remove("vd-viewer--interacting")},180)}function se(){N&&(cancelAnimationFrame(N),N=0),B(),t.onCameraChange?.(c)}function me(S){c=S,se()}function he(S){c=S,G(),!N&&(N=requestAnimationFrame(()=>{N=0,B(),t.onCameraChange?.(c)}))}let ke=null,we=null,T=!1,Q=S=>{if(x==="modifier"&&!S.ctrlKey&&!S.metaKey)return;S.preventDefault();let U=D(S),W=S.deltaMode===1?Rx:S.deltaMode===2?e.clientHeight||800:1,I=S.deltaX*W,z=S.deltaY*W;if(S.ctrlKey||S.metaKey){let X=S.ctrlKey?Px:Nx,tt=Math.max(-wu,Math.min(wu,z));he(Bo(c,U,Math.exp(-tt*X)));return}if(S.shiftKey&&I===0){he(Tt(c,-z,0));return}he(Tt(c,-I,-z))},w=S=>{(S.button===1||S.button===0&&T)&&(S.preventDefault(),ke=S.pointerId,we=D(S),e.setPointerCapture(S.pointerId))},$=S=>{if(ke!==S.pointerId||!we)return;let U=D(S);he(Tt(c,U.x-we.x,U.y-we.y)),we=U},M=S=>{ke===S.pointerId&&(ke=null,we=null,e.hasPointerCapture(S.pointerId)&&e.releasePointerCapture(S.pointerId))},L=S=>{S.code==="Space"&&(T=!0)},H=S=>{S.code==="Space"&&(T=!1)};h&&(e.addEventListener("wheel",Q,{passive:!1}),e.addEventListener("pointerdown",w),e.addEventListener("pointermove",$),e.addEventListener("pointerup",M),e.addEventListener("pointercancel",M),e.ownerDocument.addEventListener("keydown",L),e.ownerDocument.addEventListener("keyup",H)),B(),R();let q={element:e,surface:y,update:E,getDocument:()=>r,getScene:()=>d,getResolution:()=>i,getMeasurer:()=>a,setFonts(S){o.destroy(),o=n(S),E(r)},getCamera:()=>c,setCamera:me,zoomBy(S,U){let W=e.getBoundingClientRect(),I=U??{x:W.width/2,y:W.height/2};me(Bo(c,I,S))},fitToContent(S=32){let U=e.getBoundingClientRect();me(Mr({x:d.x,y:d.y,width:d.width,height:d.height},{width:U.width||d.width,height:U.height||d.height},S))},screenToDocument:S=>Fo(c,S),documentToScreen:S=>ni(c,S),pointerPoint:D,hitTest(S,U){for(let W=d.items.length-1;W>=0;W--){let I=d.items[W];if(I&&Gx(I,S,Kx/c.zoom)&&(!U||U(I.id)))return I.id}return null},linkAt(S,U){for(let W=d.items.length-1;W>=0;W--){let I=d.items[W];if(I?.kind!=="text"||U&&!U(I.id))continue;let z=I.rotation===0?S:Pe(S,{x:I.x+I.w/2,y:I.y+I.h/2},-I.rotation);for(let X of I.lines){if(z.y<X.y||z.y>X.y+X.h)continue;let tt=X.spans.find(ie=>z.x>=ie.x&&z.x<=ie.x+ie.w);if(tt)return tt.style.link}}},itemOf:S=>d.items.find(U=>U.id===S),elementOf:S=>_.get(S),destroy(){h&&(e.removeEventListener("wheel",Q),e.removeEventListener("pointerdown",w),e.removeEventListener("pointermove",$),e.removeEventListener("pointerup",M),e.removeEventListener("pointercancel",M),e.ownerDocument.removeEventListener("keydown",L),e.ownerDocument.removeEventListener("keyup",H)),N&&cancelAnimationFrame(N),A&&clearTimeout(A),N=0,A=0,o.destroy(),e.classList.remove("vd-viewer--interacting"),y.remove(),_.clear(),e.classList.remove("vd-viewer")}};return t.autoFit&&q.fitToContent(),q}var Ix="vd-clip-";function _u(e){return Ix+e}function si(e){return`url(#${_u(e)})`}function ku(e){return ti(e)?"g":ai(e)}function ai(e){switch(e.kind){case"ellipse":return"ellipse";case"frame":return"rect";case"image":return e.href===void 0?"rect":"image";case"rect":return"rect";case"text":return"text";case"vector":return"path"}}function Fx(e,t){if(e.tagName!=="g"){Su(e,t);return}ye(e,"clip-path",t.clip===void 0?null:si(t.clip)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend;let r=e.firstElementChild;(!r||r.tagName!==ai(t))&&(r?.remove(),r=e.ownerDocument.createElementNS(ne,ai(t)),e.appendChild(r)),Su(r,{...t,clip:void 0,blend:"normal"})}function Su(e,t){switch(ye(e,"clip-path",t.clip===void 0?null:si(t.clip)),ye(e,"transform",t.rotation===0?null:ei(t)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend,e.style.filter=t.shadows.length>0?`url(#${Ro}${t.id})`:"",t.kind){case"ellipse":qx(e,t);return;case"frame":Bx(e,t);return;case"image":Hx(e,t);return;case"rect":zx(e,t);return;case"text":Vx(e,t);return;case"vector":jx(e,t);return}}function Bx(e,t){e.setAttribute("class","vd-viewer__page"),e.setAttribute("x",String(t.x)),e.setAttribute("y",String(t.y)),e.setAttribute("width",String(t.w)),e.setAttribute("height",String(t.h)),ye(e,"fill",t.background??null)}function Hx(e,t){if(e.setAttribute("x",String(t.x)),e.setAttribute("y",String(t.y)),e.setAttribute("width",String(t.w)),e.setAttribute("height",String(t.h)),ye(e,"opacity",t.opacity<1?String(t.opacity):null),t.href===void 0){e.setAttribute("class","vd-viewer__missing"),ye(e,"rx",t.radius>0?String(t.radius):null);return}e.setAttribute("href",t.href),e.setAttribute("preserveAspectRatio",Ux[t.fit])}var Ux={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"};function Vx(e,t){ye(e,"opacity",t.opacity<1?String(t.opacity):null),e.setAttribute("xml:space","preserve");let r=t.lines.flatMap(o=>o.spans).filter(o=>o.text!==""),n=e.ownerDocument;for(;e.childNodes.length>r.length;)e.lastChild?.remove();for(;e.childNodes.length<r.length;)e.appendChild(n.createElementNS(ne,"tspan"));r.forEach((o,a)=>{let i=e.childNodes[a];i.textContent=o.text,i.setAttribute("x",String(o.x)),i.setAttribute("y",String(o.y)),i.setAttribute("font-family",o.style.family),i.setAttribute("font-size",String(o.style.size)),i.setAttribute("fill",o.style.fill),ye(i,"font-weight",o.style.weight===400?null:String(o.style.weight)),ye(i,"font-style",o.style.italic?"italic":null),ye(i,"letter-spacing",o.style.letterSpacing===0?null:String(o.style.letterSpacing)),ye(i,"data-vd-link",o.style.link??null);let l=[o.style.underline?"underline":"",o.style.strike?"line-through":""].filter(Boolean).join(" ");ye(i,"text-decoration",l===""?null:l)})}function zx(e,t){e.removeAttribute("class"),e.setAttribute("x",String(t.x)),e.setAttribute("y",String(t.y)),e.setAttribute("width",String(t.w)),e.setAttribute("height",String(t.h)),e.setAttribute("fill",t.fill),ye(e,"rx",t.radius>0?String(t.radius):null),ye(e,"stroke",t.stroke??null),ye(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),ye(e,"opacity",t.opacity<1?String(t.opacity):null)}function Cu(e,t){e.setAttribute("fill",t.fill),ye(e,"stroke",t.stroke??null),ye(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),ye(e,"opacity",t.opacity<1?String(t.opacity):null)}function qx(e,t){e.setAttribute("cx",String(t.x+t.w/2)),e.setAttribute("cy",String(t.y+t.h/2)),e.setAttribute("rx",String(t.w/2)),e.setAttribute("ry",String(t.h/2)),Cu(e,t)}function jx(e,t){e.setAttribute("d",t.d),Cu(e,t),ye(e,"fill-rule",t.rule==="nonzero"?null:t.rule),ye(e,"stroke-linecap",t.cap==="butt"?null:t.cap),ye(e,"stroke-linejoin",t.join==="miter"?null:t.join)}function ye(e,t,r){r===null?e.removeAttribute(t):e.setAttribute(t,r)}var Kx=4;function Gx(e,t,r){let n=e.rotation===0?t:Pe(t,{x:e.x+e.w/2,y:e.y+e.h/2},-e.rotation),o=n.x>=e.x&&n.x<=e.x+e.w&&n.y>=e.y&&n.y<=e.y+e.h;if(e.kind==="ellipse"){let a=e.stroke!==void 0?e.strokeWidth/2:0,i=e.w/2+a,l=e.h/2+a;if(i<=0||l<=0)return!1;let d=(n.x-(e.x+e.w/2))/i,c=(n.y-(e.y+e.h/2))/l;return d*d+c*c<=1}if(e.kind==="vector"){let a=e.stroke!==void 0&&e.strokeWidth>0;return as(e.contours,n,{fill:e.fill!=="none",rule:e.rule,reach:(a?e.strokeWidth/2:0)+r})}return o}function ii(e,t){let r=e.root.id;if(r===t)return e;let n=o=>{if(!pe(o))return o;let a=Ze(o.expr);return!a.ok||!er(a.ast).nodes.includes(r)?o:{expr:vn($t(a.ast,i=>i===r?t:void 0))}};return{...e,root:{...Eu(e.root,n),id:t}}}function Eu(e,t){let r=e,n={};for(let[o,a]of Object.entries(r)){if(o==="children"&&Array.isArray(a)){n[o]=a.map(i=>Eu(i,t));continue}n[o]=t(a)}return n}var di=["nw","n","ne","e","se","s","sw","w"],Mn=["nw","ne","se","sw"];function Uo(e){let t=[];return e.includes("w")&&t.push("x","w"),e.includes("e")&&t.push("w"),e.includes("n")&&t.push("y","h"),e.includes("s")&&t.push("h"),t}function $r(e){let t=e.includes("w")?0:e.includes("e")?1:.5,r=e.includes("n")?0:e.includes("s")?1:.5;return{u:t,v:r}}function fi(e){switch(e){case"e":case"w":return 0;case"n":case"s":return 90;case"nw":case"se":return 45;case"ne":case"sw":return 135}}var An=1;function ht(e,t,r,n){let{x:o,y:a,w:i,h:l}=e;if(t.includes("w")){let d=o+i;o=Math.min(o+r,d-An),i=d-o}if(t.includes("e")&&(i=Math.max(An,i+r)),t.includes("n")){let d=a+l;a=Math.min(a+n,d-An),l=d-a}return t.includes("s")&&(l=Math.max(An,l+n)),{x:o,y:a,w:i,h:l}}function tr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Vo(e,t){let r=[];return t.x!==e.x&&r.push("x"),t.y!==e.y&&r.push("y"),t.w!==e.w&&r.push("w"),t.h!==e.h&&r.push("h"),r}function Qe(e){if(e.length===0)return null;let t=1/0,r=1/0,n=-1/0,o=-1/0;for(let a of e)t=Math.min(t,a.x),r=Math.min(r,a.y),n=Math.max(n,a.x+a.w),o=Math.max(o,a.y+a.h);return{x:t,y:r,w:n-t,h:o-r}}function ui(e,t){return e.x<t.x+t.w&&e.x+e.w>t.x&&e.y<t.y+t.h&&e.y+e.h>t.y}function et(e,t,r){return t>=e.x&&t<=e.x+e.w&&r>=e.y&&r<=e.y+e.h}var Tr=7,li=15,En=9;function ci(e){let t=[],r=li/2;for(let l of Mn){let{u:d,v:c}=$r(l);t.push({handle:l,rect:{x:e.x+e.w*d-r,y:e.y+e.h*c-r,w:li,h:li}})}let n=r,o=Math.max(0,e.w-n*2),a=Math.max(0,e.h-n*2),i=En/2;return t.push({handle:"n",rect:{x:e.x+n,y:e.y-i,w:o,h:En}},{handle:"s",rect:{x:e.x+n,y:e.y+e.h-i,w:o,h:En}},{handle:"w",rect:{x:e.x-i,y:e.y+n,w:En,h:a}},{handle:"e",rect:{x:e.x+e.w-i,y:e.y+n,w:En,h:a}}),t}function Mu(e,t,r,n,o){if(o===0)return ht(e,t,r,n);let a=Pe({x:r,y:n},{x:0,y:0},-o),i=ht(e,t,a.x,a.y),l=Ve(e),d=Ve(i),c={x:l.x-d.x,y:l.y-d.y},h=Pe(c,{x:0,y:0},o);return{...i,x:i.x+c.x-h.x,y:i.y+c.y-h.y}}function Au(e,t){return Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI}function $u(e,t,r,n,o){let a=Au(e,r)-Au(e,t);return o?Math.round((n+a)/o)*o-n:a}function Tu(e,t,r){return e.map(n=>{let o=Ve(n.frame),a=Pe(o,t,r);return{id:n.id,frame:{...n.frame,x:a.x-n.frame.w/2,y:a.y-n.frame.h/2},rotation:gn(n.rotation+r)}})}function Lu(e,t,r,n){let o=r.w===0?1:n.w/r.w,a=r.h===0?1:n.h/r.h,i=t*Math.PI/180,l=Math.cos(i),d=Math.sin(i),c=e.w*Math.hypot(o*l,a*d),h=e.h*Math.hypot(o*d,a*l),x=Ve(e),y=n.x+(x.x-r.x)*o,b=n.y+(x.y-r.y)*a;return{x:y-c/2,y:b-h/2,w:c,h}}function Me(e,t){return`${e}:${t}`}function jo(e){let[t,r]=e.split(":").map(Number);if(!(t===void 0||r===void 0||!Number.isInteger(t)||!Number.isInteger(r)))return{contour:t,index:r}}function Ou(e){let t=e.split(":"),r=t[2],n=jo(t.slice(0,2).join(":"));if(!(!n||r!=="in"&&r!=="out"))return{...n,side:r}}function hi(e,t){let r=jo(t);return r?e[r.contour]?.anchors[r.index]:void 0}function mi(e,t){let r=[];for(let n of t){let o=jo(n);o&&e[o.contour]?.anchors[o.index]&&r.push(Me(o.contour,o.index))}return r}function xi(e){return e.flatMap((t,r)=>t.anchors.map((n,o)=>Me(r,o)))}function pi(e,t,r,n){return e.map((o,a)=>a===t?{...o,anchors:o.anchors.map((i,l)=>l===r?n:i)}:o)}var $n=(e,t,r)=>({x:e.x+t,y:e.y+r});function Ko(e,t,r,n){return e.map((o,a)=>({...o,anchors:o.anchors.map((i,l)=>t.has(Me(a,l))?at($n(i,r,n),i.in&&$n(i.in,r,n),i.out&&$n(i.out,r,n)):i)}))}function zo(e){if(!e.in||!e.out)return!1;let t=e.in.x-e.x,r=e.in.y-e.y,n=e.out.x-e.x,o=e.out.y-e.y,a=Math.hypot(t,r),i=Math.hypot(n,o);return a===0||i===0?!1:(t*n+r*o)/(a*i)<-.995}function qo(e,t,r,n,o,a){let i=e[t]?.anchors[r];if(!i)return[...e];let d=i[n==="in"?"out":"in"];if(a.smooth&&!a.breakSmooth&&d){let h=Math.hypot(d.x-i.x,d.y-i.y),x=o.x-i.x,y=o.y-i.y,b=Math.hypot(x,y);b>0&&(d={x:i.x-x/b*h,y:i.y-y/b*h})}let c=n==="in"?at(i,o,d):at(i,d,o);return pi(e,t,r,c)}function Du(e,t){let r=jo(t),n=r?e[r.contour]:void 0,o=n?.anchors[r?.index??-1];if(!r||!n||!o)return[...e];if(o.in||o.out)return pi(e,r.contour,r.index,at(o));let a=n.anchors.length,i=r.index>0?n.anchors[r.index-1]:n.closed?n.anchors[a-1]:void 0,l=r.index<a-1?n.anchors[r.index+1]:n.closed?n.anchors[0]:void 0;if(!i&&!l)return[...e];let d=i??o,c=l??o,h=c.x-d.x,x=c.y-d.y,y=Math.hypot(h,x);if(y===0)return[...e];h/=y,x/=y;let b=i?Math.hypot(o.x-i.x,o.y-i.y)/3:0,P=l?Math.hypot(l.x-o.x,l.y-o.y)/3:0,k=i?{x:o.x-h*b,y:o.y-x*b}:void 0,_=l?{x:o.x+h*P,y:o.y+x*P}:void 0;return pi(e,r.contour,r.index,at(o,k,_))}function Pu(e,t){let r=[];return e.forEach((n,o)=>{let a=n.anchors.filter((i,l)=>!t.has(Me(o,l)));a.length>=2&&r.push({closed:n.closed,anchors:a})}),r}function Nu(e,t,r,n,o,a,i){let l=e[t];if(!l)return[...e];let d=l.anchors.length,c=(r+1)%d;if(i)return Ko(e,new Set([Me(t,r),Me(t,c)]),o,a);let h=Math.min(.85,Math.max(.15,n)),x=1/(3*(1-h)*h),y=l.anchors[r],b=l.anchors[c],P=$n(y.out??y,o*x,a*x),k=$n(b.in??b,o*x,a*x),_=qo(e,t,r,"out",P,{smooth:zo(y),breakSmooth:!1});return _=qo(_,t,c,"in",k,{smooth:zo(b),breakSmooth:!1}),_}function Ru(e,t){return e.map((r,n)=>r.closed||r.anchors.length<2?r:t.size===0||t.has(Me(n,0))&&t.has(Me(n,r.anchors.length-1))?{...r,closed:!0}:r)}function gi(e,t){let r=[],n=new Set,o=(a,i,l)=>{let d=e[a]?.anchors[i],c=d?.[l],h=`${Me(a,i)}:${l}`;!d||!c||n.has(h)||(n.add(h),r.push({key:h,at:c,anchor:d}))};return e.forEach((a,i)=>{let l=a.anchors.length;a.anchors.forEach((d,c)=>{if(!t.has(Me(i,c)))return;o(i,c,"in"),o(i,c,"out");let h=c>0?c-1:a.closed?l-1:-1,x=c<l-1?c+1:a.closed?0:-1;h>=0&&o(i,h,"out"),x>=0&&o(i,x,"in")})}),r}function Tn(e,t){let r=t.x-e.x,n=t.y-e.y,o=Math.round(Math.atan2(n,r)/(Math.PI/4))*(Math.PI/4),a=r*Math.cos(o)+n*Math.sin(o);return{x:e.x+Math.cos(o)*a,y:e.y+Math.sin(o)*a}}function Iu(e){return{closed:e.closed,anchors:[...e.anchors].reverse().map(t=>at(t,t.out,t.in))}}function yi(e){if(!e)return null;for(let t of e.items){if(t.kind!=="file"||!t.type.startsWith("image/"))continue;let r=t.getAsFile();if(r)return r}return null}async function Go(e,t){let r;try{r=await createImageBitmap(e)}catch{return null}try{let n=Math.min(1,t/Math.max(r.width,r.height));return n>=1?{bytes:new Uint8Array(await e.arrayBuffer()),type:e.type||"image/png",width:r.width,height:r.height}:await Jx(r,n,e.type)}finally{r.close()}}async function Jx(e,t,r){let n=Math.max(1,Math.round(e.width*t)),o=Math.max(1,Math.round(e.height*t)),a=document.createElement("canvas");a.width=n,a.height=o;let i=a.getContext("2d");if(!i)return null;i.drawImage(e,0,0,n,o);let l=r==="image/png"?"image/png":"image/webp",d=await new Promise(c=>{a.toBlob(c,l,.9)});return d?{bytes:new Uint8Array(await d.arrayBuffer()),type:d.type||l,width:n,height:o}:null}function Fu(e,t,r,n){let o=Math.min(1,r/e,n/t);return{w:Math.round(e*o),h:Math.round(t*o)}}var Zx={left:"x",hcenter:"x",right:"x",top:"y",vcenter:"y",bottom:"y"};function Wo(e){return Zx[e]}function Qx(e,t,r){switch(e){case"left":return t.x;case"hcenter":return t.x+(t.w-r)/2;case"right":return t.x+t.w-r;case"top":return t.y;case"vcenter":return t.y+(t.h-r)/2;case"bottom":return t.y+t.h-r}}function vi(e,t,r){let n=Wo(r),o=new Map;for(let a of e){let i=n==="x"?a.frame.w:a.frame.h,l=n==="x"?a.frame.x:a.frame.y;o.set(a.id,Qx(r,t,i)-l)}return o}var Bu=[{key:"nw",sx:0,sy:0},{key:"ne",sx:1,sy:0},{key:"se",sx:1,sy:1},{key:"sw",sx:0,sy:1}],eg={id:"radius",prop:"radius",handles(e,t,r){let n=this.max(e),o=Math.min(Math.max(t,r),Math.max(n,r));return Bu.map(({key:a,sx:i,sy:l})=>({id:`radius:${a}`,at:{x:e.x+(i===0?o:e.w-o),y:e.y+(l===0?o:e.h-o)}}))},valueAt(e,t,r){let n=rg(t);if(!n)return 0;let o=e.x+(n.sx===0?0:e.w),a=e.y+(n.sy===0?0:e.h),i=Math.max(0,n.sx===0?r.x-o:o-r.x),l=Math.max(0,n.sy===0?r.y-a:a-r.y);return Math.min((i+l)/2,this.max(e))},max(e){return Math.max(0,Math.min(e.w,e.h)/2)}},tg={canvas:[],frame:[],group:[],rect:[eg]};function Ln(e){return tg[e.type]??[]}function Xo(e,t){let r=t.split(":")[0];return Ln(e).find(n=>n.id===r)}function rg(e){let t=e.split(":")[1];return Bu.find(r=>r.key===t)}var bi=[["path",{d:"m15 16 2.536-7.328a1.02 1.02 1 0 1 1.928 0L22 16"}],["path",{d:"M15.697 14h5.606"}],["path",{d:"m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16"}],["path",{d:"M3.304 13h6.392"}]];var wi=[["path",{d:"M2 12h20"}],["path",{d:"M10 16v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-4"}],["path",{d:"M10 8V4a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v4"}],["path",{d:"M20 16v1a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-1"}],["path",{d:"M14 8V7c0-1.1.9-2 2-2h2a2 2 0 0 1 2 2v1"}]];var ki=[["path",{d:"M12 2v20"}],["path",{d:"M8 10H4a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h4"}],["path",{d:"M16 10h4a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-4"}],["path",{d:"M8 20H7a2 2 0 0 1-2-2v-2c0-1.1.9-2 2-2h1"}],["path",{d:"M16 14h1a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2h-1"}]];var Si=[["rect",{width:"6",height:"16",x:"4",y:"2",rx:"2"}],["rect",{width:"6",height:"9",x:"14",y:"9",rx:"2"}],["path",{d:"M22 22H2"}]];var _i=[["rect",{width:"16",height:"6",x:"2",y:"4",rx:"2"}],["rect",{width:"9",height:"6",x:"9",y:"14",rx:"2"}],["path",{d:"M22 22V2"}]];var Ci=[["rect",{width:"6",height:"14",x:"4",y:"5",rx:"2"}],["rect",{width:"6",height:"10",x:"14",y:"7",rx:"2"}],["path",{d:"M17 22v-5"}],["path",{d:"M17 7V2"}],["path",{d:"M7 22v-3"}],["path",{d:"M7 5V2"}]];var Ei=[["rect",{width:"6",height:"16",x:"4",y:"6",rx:"2"}],["rect",{width:"6",height:"9",x:"14",y:"6",rx:"2"}],["path",{d:"M22 2H2"}]];var Ai=[["rect",{width:"9",height:"6",x:"6",y:"14",rx:"2"}],["rect",{width:"16",height:"6",x:"6",y:"4",rx:"2"}],["path",{d:"M2 2v20"}]];var Mi=[["path",{d:"M22 17h-3"}],["path",{d:"M22 7h-5"}],["path",{d:"M5 17H2"}],["path",{d:"M7 7H2"}],["rect",{x:"5",y:"14",width:"14",height:"6",rx:"2"}],["rect",{x:"7",y:"4",width:"10",height:"6",rx:"2"}]];var $i=[["rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"}],["rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"}],["path",{d:"M2 12h20"}]];var Ti=[["rect",{width:"14",height:"6",x:"5",y:"12",rx:"2"}],["rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"}],["path",{d:"M2 22h20"}]];var Li=[["rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"}],["rect",{width:"10",height:"6",x:"7",y:"6",rx:"2"}],["path",{d:"M2 2h20"}]];var Oi=[["circle",{cx:"15",cy:"9",r:"7"}],["circle",{cx:"9",cy:"15",r:"7"}]];var Di=[["path",{d:"M20 6 9 17l-5-5"}]];var Pi=[["path",{d:"m6 9 6 6 6-6"}]];var Ni=[["path",{d:"m9 18 6-6-6-6"}]];var Ri=[["circle",{cx:"12",cy:"12",r:"10"}]];var Ii=[["path",{d:"M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z"}]];var Fi=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}],["circle",{cx:"12",cy:"12",r:"3"}]];var Bi=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}],["path",{d:"m2 2 20 20"}]];var Hi=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M10 9H8"}],["path",{d:"M16 13H8"}],["path",{d:"M16 17H8"}]];var Ui=[["line",{x1:"22",x2:"2",y1:"6",y2:"6"}],["line",{x1:"22",x2:"2",y1:"18",y2:"18"}],["line",{x1:"6",x2:"6",y1:"2",y2:"22"}],["line",{x1:"18",x2:"18",y1:"2",y2:"22"}]];var Vi=[["path",{d:"M3 7V5c0-1.1.9-2 2-2h2"}],["path",{d:"M17 3h2c1.1 0 2 .9 2 2v2"}],["path",{d:"M21 17v2c0 1.1-.9 2-2 2h-2"}],["path",{d:"M7 21H5c-1.1 0-2-.9-2-2v-2"}],["rect",{width:"7",height:"5",x:"7",y:"7",rx:"1"}],["rect",{width:"7",height:"5",x:"10",y:"12",rx:"1"}]];var zi=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}],["circle",{cx:"9",cy:"9",r:"2"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"}]];var qi=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"}]];var Yo=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1"}]];var ji=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}]];var Ki=[["path",{d:"M5 12h14"}]];var Gi=[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"}]];var Wi=[["path",{d:"m18 8 4 4-4 4"}],["path",{d:"M2 12h20"}],["path",{d:"m6 8-4 4 4 4"}]];var Xi=[["path",{d:"M12 2v20"}],["path",{d:"m8 18 4 4 4-4"}],["path",{d:"m8 6 4-4 4 4"}]];var Yi=[["path",{d:"M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z"}],["path",{d:"m18 13-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18"}],["path",{d:"m2.3 2.3 7.286 7.286"}],["circle",{cx:"11",cy:"11",r:"2"}]];var Ji=[["path",{d:"m12 9-8.414 8.414A2 2 0 0 0 3 18.828v1.344a2 2 0 0 1-.586 1.414A2 2 0 0 1 3.828 21h1.344a2 2 0 0 0 1.414-.586L15 12"}],["path",{d:"m18 9 .4.4a1 1 0 1 1-3 3l-3.8-3.8a1 1 0 1 1 3-3l.4.4 3.4-3.4a1 1 0 1 1 3 3z"}],["path",{d:"m2 22 .414-.414"}]];var Zi=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"}]];var Qi=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];var el=[["path",{d:"m15 14 5-5-5-5"}],["path",{d:"M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13"}]];var tl=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}],["path",{d:"M21 3v5h-5"}]];var rl=[["circle",{cx:"19",cy:"5",r:"2"}],["circle",{cx:"5",cy:"19",r:"2"}],["path",{d:"M5 17A12 12 0 0 1 17 5"}]];var nl=[["path",{d:"M21 11a8 8 0 0 0-8-8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}]];var ol=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];var Jo=[["path",{d:"M21 5H3"}],["path",{d:"M21 12H9"}],["path",{d:"M21 19H7"}]];var Zo=[["path",{d:"M21 5H3"}],["path",{d:"M17 12H7"}],["path",{d:"M19 19H5"}]];var Qo=[["path",{d:"M3 5h18"}],["path",{d:"M3 12h18"}],["path",{d:"M3 19h18"}]];var On=[["path",{d:"M21 5H3"}],["path",{d:"M15 12H3"}],["path",{d:"M17 19H3"}]];var al=[["path",{d:"M12 4v16"}],["path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"}],["path",{d:"M9 20h6"}]];var sl=[["path",{d:"M9 14 4 9l5-5"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"}]];var il=[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16"}]];var ll=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var Dn=e=>e.replace(/\b(?:CmdOrCtrl|CommandOrControl)\b/g,"Ctrl");function Hu(e,t){let n=e.ownerDocument.createElement("div");n.className="vd-chrome",n.setAttribute("role","toolbar"),n.setAttribute("aria-label","Canvas tools"),n.innerHTML=ng(t),e.appendChild(n);let o=new Map;for(let h of n.querySelectorAll("[data-tool]"))o.set(h.dataset.tool,h);let a=n.querySelector('[data-act="undo"]'),i=n.querySelector('[data-act="redo"]'),l=n.querySelector('[data-act="zoom"]'),d=h=>{let x=h.target?.closest("button");if(!x)return;h.stopPropagation();let y=x.dataset.tool;if(y){t.onTool(y);return}switch(x.dataset.act){case"undo":t.onUndo();return;case"redo":t.onRedo();return;case"zoom":t.onZoomReset();return;case"play":t.onPlay?.();return}},c=h=>h.stopPropagation();return n.addEventListener("click",d),n.addEventListener("pointerdown",c),{element:n,setTool(h){for(let[x,y]of o)y.setAttribute("aria-pressed",String(x===h))},setHistory(h,x){a&&(a.disabled=!h),i&&(i.disabled=!x)},setZoom(h){l&&(l.textContent=`${Math.round(h*100)}%`)},destroy(){n.removeEventListener("click",d),n.removeEventListener("pointerdown",c),n.remove()}}}function ng(e){let t=e.formatKeys??Dn;return[mt({tool:"select",label:"Select",hint:"V",icon:"select"}),mt({tool:"frame",label:"Frame",hint:"F",icon:"frame"}),mt({tool:"rect",label:"Rectangle",hint:"R",icon:"rect"}),mt({tool:"ellipse",label:"Ellipse",hint:"O",icon:"ellipse"}),mt({tool:"pen",label:"Pen",hint:"P",icon:"pen"}),mt({tool:"text",label:"Text",hint:"T",icon:"text"}),'<span class="vd-chrome__divider"></span>',mt({act:"undo",label:"Undo",hint:t("CmdOrCtrl+Z"),icon:"undo"}),mt({act:"redo",label:"Redo",hint:t("CmdOrCtrl+Shift+Z"),icon:"redo"}),'<span class="vd-chrome__divider"></span>','<button type="button" class="vd-chrome__zoom" data-act="zoom" title="Fit to screen">100%</button>',...e.onPlay?['<span class="vd-chrome__divider"></span>',mt({act:"play",label:"Play",hint:e.playHint,icon:"play"})]:[]].join("")}function mt(e){let t=e.tool?`data-tool="${e.tool}"`:`data-act="${e.act??""}"`,r=e.tool?' aria-pressed="false"':"";return`<button type="button" class="vd-chrome__tool" ${t}${r} title="${e.hint?`${e.label} \xB7 ${e.hint}`:e.label}" aria-label="${e.label}">`+Ne(e.icon)+"</button>"}var og={select:Gi,frame:Ui,rect:ol,ellipse:Ri,pen:Yi,vector:rl,text:al,undo:sl,redo:el,"align-left":Ai,"align-hcenter":ki,"align-right":_i,"align-top":Ei,"align-vcenter":wi,"align-bottom":Si,"distribute-h":Ci,"distribute-v":Mi,group:Vi,image:zi,eye:Fi,"eye-off":Bi,lock:ji,unlock:Yo,chevron:Ni,"text-left":On,"text-center":Zo,"text-right":Jo,"text-justify":Qo,"text-top":Li,"text-middle":$i,"text-bottom":Ti,unlink:il,rotate:tl,opacity:Ii,radius:nl,blend:Oi,plus:Qi,minus:Ki,close:ll,"chevron-down":Pi,check:Di,link:qi,"font-size":bi,"line-height":Xi,"letter-spacing":Wi,eyedropper:Ji,document:Hi,play:Zi};function Ne(e){return`<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">${og[e].map(([r,n])=>{let o=Object.entries(n).filter(([a])=>a!=="key").map(([a,i])=>` ${a}="${String(i)}"`).join("");return`<${r}${o} vector-effect="non-scaling-stroke"/>`}).join("")}</svg>`}var dl="clipboard";function Pn(e,t){let r=new Set(t),n=[];return oe(e.root,o=>{if(o.id!==e.root.id&&r.has(o.id))return n.push(o),!1}),n}function Uu(e,t){let r={};for(let a of e)oe(a,i=>{for(let[l,d]of Object.entries(i)){if(pe(d)){let c=Ze(d.expr);if(!c.ok)continue;for(let h of er(c.ast).tokens){let x=t[h];x!==void 0&&(r[h]=x)}continue}typeof d=="string"&&o(d),l==="shadow"&&typeof d=="string"&&n(d)}for(let l of zu(i.content))o(l)});return r;function n(a){let i=t[a],d=Cr(typeof i=="string"?i:a);if(!("error"in d))for(let c of d.shadows)o(c.colour)}function o(a){for(let i of Co(a)){let l=t[i];if(l!==void 0&&(r[i]=l,!(typeof l!="string"||l===a)))for(let d of Co(l)){let c=t[d];c!==void 0&&d!==i&&(r[d]=c)}}}}function ag(e,t){let r={};for(let n of e)oe(n,o=>{if(o.type!=="image"||typeof o.src!="string")return;let a=t[o.src];a!==void 0&&(r[o.src]=a)});return r}function Vu(e,t){let r={},n=o=>{if(typeof o!="string")return;let a=t[o];a!==void 0&&(r[o]=a)};for(let o of e)oe(o,a=>{let i=a;n(i.font);for(let l of zu(i.content,"font"))n(l)});return r}function zu(e,t="fill"){if(!Array.isArray(e))return[];let r=[];for(let n of e){if(typeof n=="string")continue;let o=n[t];o!==void 0&&r.push(o)}return r}function fl(e,t,r){let n=Pn(e,t);if(n.length===0)return null;let o={};for(let l of n)oe(l,d=>{let c=r.nodes.get(d.id)?.values;c&&Object.keys(c).length>0&&(o[d.id]=c)});let a={version:e.version,kind:e.kind,tokens:Uu(n,e.tokens),fonts:Vu(n,e.fonts),assets:ag(n,e.assets),root:{...e.root,children:n}},i=JSON.parse(ns(a));return i[dl]={resolved:o},JSON.stringify(i,null,2)}function ul(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!="object"||t===null)return null;let r=t;if(typeof r.root!="object"||r.root===null)return null;let{document:n}=Ds(t),o=n.root.children;if(o.length===0)return null;let a=r[dl],i=typeof a=="object"&&a!==null?a.resolved??{}:{};return{nodes:o,tokens:n.tokens,fonts:n.fonts,resolved:typeof i=="object"&&i!==null?i:{}}}function cl(e,t){let r=uo(t.root),n=new Map;for(let i of e.nodes)oe(i,l=>{let d=sg(l.id,r);r.add(d),n.set(l.id,d)});let o=i=>r.has(i),a={...e.tokens,...t.tokens};return{nodes:e.nodes.map(i=>qu(i,{payload:e,remap:n,exists:o,tokens:a})),remap:n}}function sg(e,t){let r=e.lastIndexOf("."),n=r===-1?"":e.slice(r+1),o=/^[0-9]+$/.test(n)?e.slice(0,r):e,a=1;for(let i of t){if(!i.startsWith(`${o}.`))continue;let l=Number(i.slice(o.length+1));Number.isInteger(l)&&l>=a&&(a=l+1)}return`${o}.${a}`}function qu(e,t){let r=e,n={};for(let[o,a]of Object.entries(r))o==="id"||o==="children"||(n[o]=pe(a)?ig(a.expr,e.id,o,t):a);return n.id=t.remap.get(e.id)??e.id,ce(e)&&(n.children=de(e).map(o=>qu(o,t))),n}function ig(e,t,r,n){let o={expr:e},a=Ze(e);if(!a.ok)return o;let i=er(a.ast).nodes.some(h=>n.remap.has(h)),l=i?$t(a.ast,h=>n.remap.get(h)):a.ast,d=er(l);if(d.nodes.some(h=>!n.exists(h))||d.tokens.some(h=>n.tokens[h]===void 0)){let h=n.payload.resolved[t]?.[r];return h===void 0?o:h}return i?{expr:vn(l)}:o}var xt="#ffffff",Lt="#0b0d0c",Xu="#c6ff3d",lg="#ffb224";var ju=new Map;function $e(e,t={}){let r=t.badge??"none",n=e==="resize"?Yu(t.angle??0):e==="rotate"?fg(t.angle??0):0,o=`${e}:${n}:${r}`,a=ju.get(o);if(a!==void 0)return a;let{at:i,fallback:l}=dg[e],d=pg(ug(e,n,r),i[0],i[1],l);return ju.set(o,d),d}var Ku=[2,2],Lr=[12,12],dg={arrow:{at:Ku,fallback:"default"},radius:{at:Ku,fallback:"default"},resize:{at:Lr,fallback:"ew-resize"},rotate:{at:Lr,fallback:"crosshair"},crosshair:{at:Lr,fallback:"crosshair"},grab:{at:Lr,fallback:"grab"},grabbing:{at:Lr,fallback:"grabbing"},text:{at:Lr,fallback:"text"}};function fg(e){let t=(e%360+360)%360;return Math.round(t/15)*15%360}function Yu(e){let t=(e%180+180)%180;return Math.round(t/15)*15%180}function ug(e,t,r){switch(e){case"arrow":return Ju(r);case"resize":return hg(t,r);case"rotate":return mg(t);case"crosshair":return gg();case"grab":return Wu(!1);case"grabbing":return Wu(!0);case"radius":return yg(r);case"text":return xg()}}function cg(e){return`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">${e}</svg>`}function pg(e,t,r,n){return`url("data:image/svg+xml,${encodeURIComponent(cg(e))}") ${t} ${r}, ${n}`}var Gu="M2 2 L2 20.4 L6.7 15.9 L9.9 22.8 L12.6 21.5 L9.5 14.8 L15.4 14.6 Z";function Ju(e){return`<path d="${Gu}" fill="${xt}" stroke="${xt}" stroke-width="3" stroke-linejoin="round"/><path d="${Gu}" fill="${Lt}"/>`+Zu(e)}function hg(e,t){let r=["M6.6 12 H17.4","M9.7 8.7 L6.2 12 L9.7 15.3","M14.3 8.7 L17.8 12 L14.3 15.3"],n=(o,a)=>r.map(i=>`<path d="${i}" stroke="${a}" stroke-width="${o}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+n(3.6,xt)+n(1.6,Lt)+"</g>"+Zu(t)}function mg(e){let t=["M7 17.5 A10 10 0 0 0 17.5 7","M14.2 4.6 L17.6 7 L15 10.3","M4.6 14.2 L7 17.6 L10.3 15"],r=(n,o)=>t.map(a=>`<path d="${a}" stroke="${o}" stroke-width="${n}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+r(3.6,xt)+r(1.6,Lt)+"</g>"}function xg(){let e=["M12 4.5 V19.5","M9 4.5 H15","M9 19.5 H15"],t=(r,n)=>e.map(o=>`<path d="${o}" stroke="${n}" stroke-width="${r}"/>`).join("");return'<g fill="none" stroke-linecap="round">'+t(3.4,xt)+t(1.5,Lt)+"</g>"}function gg(){let e="M12 2.5 V9 M12 15 V21.5 M2.5 12 H9 M15 12 H21.5";return`<g fill="none" stroke-linecap="round"><path d="${e}" stroke="${xt}" stroke-width="3"/><path d="${e}" stroke="${Lt}" stroke-width="1.2"/></g>`}function Wu(e){let t=e?"M6.8 13.8v-1.3a1.35 1.35 0 0 1 1.35-1.35h7.7a1.35 1.35 0 0 1 1.35 1.35v2.6c0 3.2-2.2 5.2-5.1 5.2h-1.1c-1.9 0-3-.8-3.9-2.1l-1.4-2":"M9 14.6V6.4a1.25 1.25 0 0 1 2.5 0v5.1V5.1a1.25 1.25 0 0 1 2.5 0v6.4V6.2a1.25 1.25 0 0 1 2.5 0v6.6m0 0v2.3c0 3.1-2.1 5-4.8 5h-.7c-1.6 0-2.7-.6-3.6-1.9l-2.2-3a1.3 1.3 0 0 1 .45-1.85c.6-.35 1.35-.2 1.85.4L9 15.9";return`<g fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="${t}" stroke="${xt}" stroke-width="3.4"/><path d="${t}" stroke="${Lt}" stroke-width="1.5"/></g>`}function yg(e){return Ju("none")+vg(e)}function vg(e){return`<g><rect x="17.5" y="17.5" width="14" height="14" rx="4.5" fill="${xt}"/><rect x="18.7" y="18.7" width="11.6" height="11.6" rx="3.4" fill="${e==="none"?Xu:lg}"/><path d="M21.6 27.9 V25.4 A3.8 3.8 0 0 1 25.4 21.6 H27.9" fill="none" stroke="${Lt}" stroke-width="1.5" stroke-linecap="round"/></g>`}function Zu(e){return e==="none"?"":`<g><rect x="18.5" y="18.5" width="13" height="13" rx="4" fill="${xt}"/><rect x="19.6" y="19.6" width="10.8" height="10.8" rx="3" fill="${Xu}"/><text x="25" y="28.4" text-anchor="middle" fill="${Lt}" font-family="ui-sans-serif, system-ui, -apple-system, Helvetica, sans-serif" font-size="10" font-weight="700">${e==="token"?"$":"\u0192"}</text></g>`}function De(e,t){let r=[],n=o=>{if(r.push(o.id),o.id===t)return!0;for(let a of de(o))if(n(a))return!0;return r.pop(),!1};return n(e)?r:[]}function ea(e,t,r){let n=De(t.root,e);if(n.length===0)return e;let o=r!==null&&n.includes(r)?r:bg(n,t),a=n.indexOf(o);return a===-1?e:n[a+1]??e}function bg(e,t){for(let r=e.length-2;r>=0;r-=1){let n=e[r];if(V(t.root,n)?.type==="frame")return n}return t.root.id}function Qu(e,t){let r=e.map(o=>De(t.root,o)).filter(o=>o.length>0);if(r.length===0)return t.root.id;let n=t.root.id;for(let o=0;;o+=1){let a=r[0]?.[o];if(a===void 0||r.some(i=>i[o]!==a||o===i.length-1))break;n=a}return n}function rr(e,t){let r=V(t.root,e);if(!r)return[];let n=[],o=a=>{if(Se(a)){for(let i of de(a))o(i);return}n.push(a.id)};return o(r),n}function nr(e,t,r){let n=V(t.root,e);if(!n)return;if(!Se(n)){let i=r.nodes.get(e);return i?pl(i):void 0}let o=[],a=i=>{if(!(i.id!==e&&"hidden"in i&&i.hidden===!0)){if(i.id!==e&&!Se(i)){let l=nr(i.id,t,r);l&&o.push(l);return}for(let l of de(i))a(l)}};return a(n),Qe(o)??void 0}function pl(e){let t={x:e.absX,y:e.absY,w:e.w,h:e.h},r=e.values.rotation??0;return r===0?t:xn(t,r)}function Nn(e,t,r){return t.flatMap(n=>{let o=nr(n,e,r);return o?[{id:n,frame:o}]:[]})}function hl(e,t){let r=t.filter(x=>x!==e.root.id&&V(e.root,x));if(r.length<2)return null;let n=Qu(r,e),o=V(e.root,n);if(!o)return null;let a=de(o),i=new Set(r.map(x=>ea(x,e,n))),l=a.filter(x=>i.has(x.id));if(l.length<2)return null;let d=a.findIndex(x=>x.id===l[l.length-1]?.id),c=Kt(e.root,"group"),h=[{op:"insert",parent:n,index:d+1,node:Ya({id:c,children:[]})}];return l.forEach((x,y)=>{h.push({op:"move",id:x.id,parent:c,index:y})}),{ops:h,groupId:c}}function ml(e,t){let r=V(e.root,t);if(!r||!Se(r))return[];let n=De(e.root,t),o=n[n.length-2];if(o===void 0)return[];let a=V(e.root,o);if(!a)return[];let i=de(a).findIndex(d=>d.id===t);if(i===-1)return[];let l=de(r).map((d,c)=>({op:"move",id:d.id,parent:o,index:i+c}));return l.push({op:"remove",id:t}),l}function xl(e,t,r){let n=new Map;for(let a of t){let i=De(e.root,a),l=i[i.length-2];if(l===void 0)continue;let d=n.get(l)??new Set;d.add(a),n.set(l,d)}let o=[];for(let[a,i]of n){let l=V(e.root,a);if(!l)continue;let d=de(l).map(c=>c.id);o.push(...kg(a,d,wg(d,i,r)))}return o}function wg(e,t,r){if(r==="front"||r==="back"){let i=e.filter(d=>t.has(d)),l=e.filter(d=>!t.has(d));return r==="front"?[...l,...i]:[...i,...l]}let n=r==="forward"?1:-1,o=[...e],a=o.flatMap((i,l)=>t.has(i)?[l]:[]);n===1&&a.reverse();for(let i of a){let l=i+n,d=o[l];d===void 0||t.has(d)||(o[l]=o[i],o[i]=d)}return o}function kg(e,t,r){let n=[...t],o=[];for(let a=0;a<r.length;a+=1){let i=r[a];i===void 0||n[a]===i||(n.splice(n.indexOf(i),1),n.splice(a,0,i),o.push({op:"move",id:i,parent:e,index:a}))}return o}function gl(e,t,r){let n=t.w===0?1:r.w/t.w,o=t.h===0?1:r.h/t.h,a=new Map;for(let[i,l]of e)a.set(i,{x:r.x+(l.x-t.x)*n,y:r.y+(l.y-t.y)*o,w:l.w*n,h:l.h*o});return a}var yl=6,gt=.01,ze={dx:0,dy:0,guides:[],measures:[]},ta=["lo","mid","hi"];function vl(e,t,r){let n=[],o=(a,i)=>{let l=t.nodes.get(a);l&&n.push({id:a,frame:pl(l),isPage:i})};return e.root.w!==void 0&&e.root.h!==void 0&&o(e.root.id,!0),oe(e.root,a=>{if(r.has(a.id)||"hidden"in a&&a.hidden===!0)return!1;if(a.id!==e.root.id){if(a.type==="frame"){o(a.id,!0);return}ce(a)||o(a.id,!1)}}),n}function bl(e,t,r){if(r<=0||t.length===0)return ze;let n=Or("x",e,t,r,ta,!0),o=Or("y",e,t,r,ta,!0);return kl(e,t,n,o)}function ra(e,t,r,n){if(n<=0||r.length===0)return ze;let o=t.includes("w")?["lo"]:t.includes("e")?["hi"]:[],a=t.includes("n")?["lo"]:t.includes("s")?["hi"]:[],i=Or("x",e,r,n,o,!1),l=Or("y",e,r,n,a,!1);return kl(e,r,i,l)}function wl(e,t,r){let n={x:e.x,y:e.y,w:0,h:0};if(r<=0||t.length===0)return ze;let o=Or("x",n,t,r,["lo"],!1),a=Or("y",n,t,r,["lo"],!1);return kl(n,t,o,a)}function Or(e,t,r,n,o,a){let i={axis:e,delta:0,kind:"none"};if(o.length===0)return i;let l=Sg(e,t,r,n,o),d=a?Cg(e,t,r,n):null;return l&&d?Math.abs(d.delta)<Math.abs(l.delta)-gt?{axis:e,delta:d.delta,kind:"space",gap:d.gap}:{axis:e,delta:l.delta,kind:"align",at:l.at}:l?{axis:e,delta:l.delta,kind:"align",at:l.at}:d?{axis:e,delta:d.delta,kind:"space",gap:d.gap}:i}function Sg(e,t,r,n,o){let a=null;for(let i of r)for(let l of ta){let d=fe(i.frame,e,l);for(let c of o){let h=d-fe(t,e,c);if(Math.abs(h)>n)continue;let x=c==="mid"&&l==="mid";(a===null||_g(h,x,a))&&(a={at:d,delta:h,centred:x})}}return a?{at:a.at,delta:a.delta}:null}function _g(e,t,r){let n=Math.abs(e),o=Math.abs(r.delta);return n<o-gt?!0:n>o+gt?!1:t&&!r.centred}function Cg(e,t,r,n){let o=ec(e,t,r);if(o.length<2)return null;let a=tc(t,e),i=fe(t,e,"lo"),l=[];for(let c of Eg(o,e))for(let h of o)l.push({delta:fe(h,e,"hi")+c-i,gap:c}),l.push({delta:fe(h,e,"lo")-c-a-i,gap:c});for(let c=0;c+1<o.length;c+=1){let h=o[c],x=o[c+1];if(!h||!x)continue;let y=fe(x,e,"lo")-fe(h,e,"hi")-a;y<=gt||l.push({delta:fe(h,e,"hi")+y/2-i,gap:y/2})}let d=null;for(let c of l)Math.abs(c.delta)>n||(d===null||Math.abs(c.delta)<Math.abs(d.delta)-gt)&&(d=c);return d}function ec(e,t,r){let n=Sl(e);return r.filter(o=>!o.isPage&&$g(o.frame,t,n)).map(o=>o.frame).sort((o,a)=>fe(o,e,"lo")-fe(a,e,"lo"))}function Eg(e,t){let r=[];for(let n=0;n+1<e.length;n+=1){let o=e[n],a=e[n+1];if(!o||!a)continue;let i=fe(a,t,"lo")-fe(o,t,"hi");i<=gt||r.some(l=>Math.abs(l-i)<gt)||r.push(i)}return r}function kl(e,t,r,n){let o={...e,x:e.x+r.delta,y:e.y+n.delta},a=[],i=[];for(let l of[r,n]){if(l.kind==="align"&&l.at!==void 0){let d=Ag(l.axis,l.at,o,t);d&&a.push(d)}l.kind==="space"&&l.gap!==void 0&&i.push(...Mg(l.axis,l.gap,o,t))}return{dx:r.delta,dy:n.delta,guides:a,measures:i}}function Ag(e,t,r,n){let o=Sl(e),a=fe(r,o,"lo"),i=fe(r,o,"hi"),l=!1;for(let d of n)ta.some(c=>Tg(fe(d.frame,e,c),t))&&(l=!0,a=Math.min(a,fe(d.frame,o,"lo")),i=Math.max(i,fe(d.frame,o,"hi")));return l?{axis:e,at:t,from:a,to:i}:null}function Mg(e,t,r,n){let o=Sl(e),a=[...ec(e,r,n),r].sort((l,d)=>fe(l,e,"lo")-fe(d,e,"lo")),i=[];for(let l=0;l+1<a.length;l+=1){let d=a[l],c=a[l+1];if(!d||!c)continue;let h=fe(c,e,"lo")-fe(d,e,"hi");if(Math.abs(h-t)>gt)continue;let x=Math.max(fe(d,o,"lo"),fe(c,o,"lo")),y=Math.min(fe(d,o,"hi"),fe(c,o,"hi"));i.push({axis:e,at:(x+y)/2,from:fe(d,e,"hi"),to:fe(c,e,"lo"),label:Lg(h)})}return i}function Sl(e){return e==="x"?"y":"x"}function tc(e,t){return t==="x"?e.w:e.h}function fe(e,t,r){let n=t==="x"?e.x:e.y,o=tc(e,t);return r==="lo"?n:r==="hi"?n+o:n+o/2}function $g(e,t,r){return fe(e,r,"lo")<fe(t,r,"hi")&&fe(e,r,"hi")>fe(t,r,"lo")}function Tg(e,t){return Math.abs(e-t)<gt}function Lg(e){return String(Math.round(e*100)/100)}var Rn=class{limit;past=[];future=[];constructor(t=500){this.limit=t}push(t){this.past.push(t),this.past.length>this.limit&&this.past.shift(),this.future.length=0}amend(t){let r=this.past[this.past.length-1];return r?(this.past[this.past.length-1]={label:t.label,ops:[...r.ops,...t.ops],inverse:[...t.inverse,...r.inverse]},this.future.length=0,!0):!1}get canUndo(){return this.past.length>0}get top(){return this.past[this.past.length-1]??null}isTail(t){if(t.length===0||t.length>this.past.length)return!1;let r=this.past.length-t.length;return t.every((n,o)=>this.past[r+o]===n)}get canRedo(){return this.future.length>0}undo(){let t=this.past.pop();if(t)return this.future.push(t),{entry:t,ops:t.inverse}}redo(){let t=this.future.pop();if(t)return this.past.push(t),{entry:t,ops:t.ops}}snapshot(){return{past:[...this.past],future:[...this.future]}}restore(t){this.past.length=0,this.future.length=0,this.past.push(...t.past),this.future.push(...t.future)}clear(){this.past.length=0,this.future.length=0}};var rc=1,Og=48,Dg=.06,Pg=.5;function nc(e){return Math.max(Og,Math.min(e.width,e.height)*Dg)}function _l(e,t){let r=new Set(t),n=[];for(let o of e.root.children)(r.has(o.id)||oc(o,r))&&n.push(o.id);return n}function oc(e,t){for(let r of de(e))if(t.has(r.id)||oc(r,t))return!0;return!1}function na(e){let t=e.filter(i=>i.w>0&&i.h>0);if(t.length===0)return null;let r=Math.min(...t.map(i=>i.x)),n=Math.min(...t.map(i=>i.y)),o=Math.max(...t.map(i=>i.x+i.w)),a=Math.max(...t.map(i=>i.y+i.h));return{x:r,y:n,w:o-r,h:a-n}}function oa(e,t){let r=nc(t),n={width:Math.max(1,t.width-r*2),height:Math.max(1,t.height-r*2)},o=Cn(Math.min(n.width/e.w,n.height/e.h,rc));return{zoom:o,x:t.width/2-(e.x+e.w/2)*o,y:t.height/2-(e.y+e.h/2)*o}}function Cl(e,t,r){let n=oa(e,t);return Ng(e,t,r)&&r.zoom>=n.zoom*Pg?null:n}function Ng(e,t,r){let n=e.x*r.zoom+r.x,o=e.y*r.zoom+r.y,a=(e.x+e.w)*r.zoom+r.x,i=(e.y+e.h)*r.zoom+r.y;return n>=0&&o>=0&&a<=t.width&&i<=t.height}function ac(e,t,r,n){let o=Math.exp(Math.log(e.zoom)+(Math.log(t.zoom)-Math.log(e.zoom))*r),a={x:n.width/2,y:n.height/2},i={x:(a.x-e.x)/e.zoom,y:(a.y-e.y)/e.zoom},l={x:(a.x-t.x)/t.zoom,y:(a.y-t.y)/t.zoom},d={x:i.x+(l.x-i.x)*r,y:i.y+(l.y-i.y)*r};return{zoom:o,x:a.x-d.x*o,y:a.y-d.y*o}}function sc(e){return 1-(1-e)**3}function Rg(e){return!("separator"in e)}function El(e,t=[]){let r=t.length>0?[{separator:!0},...t]:[];if(e.count===0)return[{id:"paste",label:"Paste",keys:"CmdOrCtrl+V",disabled:!e.canPaste},{separator:!0},{id:"selectAll",label:"Select all",keys:"CmdOrCtrl+A"},...ic(e),{separator:!0},{id:"fit",label:"Fit to screen",keys:"Shift+1"},{id:"zoom100",label:"Zoom to 100%",keys:"CmdOrCtrl+0"},...r];let n=[];e.isText&&e.count===1&&n.push({id:"editText",label:"Edit text",keys:"Enter"},{separator:!0}),e.isVector&&e.count===1&&n.push({id:"editPoints",label:"Edit points",keys:"Enter"},{separator:!0}),(e.convertible??0)>0&&n.push({id:"toVector",label:"Convert to vector",keys:"CmdOrCtrl+Shift+O"},{separator:!0}),n.push({id:"cut",label:"Cut",keys:"CmdOrCtrl+X"},{id:"copy",label:"Copy",keys:"CmdOrCtrl+C"},{id:"paste",label:"Paste",keys:"CmdOrCtrl+V",disabled:!e.canPaste},{id:"duplicate",label:"Duplicate",keys:"CmdOrCtrl+D"},{separator:!0},{id:"group",label:"Group",keys:"CmdOrCtrl+G",disabled:e.count<2},{id:"ungroup",label:"Ungroup",keys:"CmdOrCtrl+Shift+G",disabled:!e.hasGroup});let o=[];if(e.hide&&o.push({id:"toggleHidden",label:e.hide==="show"?"Show":"Hide",keys:"CmdOrCtrl+Shift+H"}),e.lock&&o.push({id:"toggleLock",label:e.lock==="unlock"?"Unlock":"Lock",keys:"CmdOrCtrl+Shift+L"}),o.length>0&&n.push({separator:!0},...o),n.push({separator:!0},{id:"front",label:"Bring to front",keys:"CmdOrCtrl+]"},{id:"forward",label:"Bring forward",keys:"]"},{id:"backward",label:"Send backward",keys:"["},{id:"back",label:"Send to back",keys:"CmdOrCtrl+["}),e.bound.length>0){n.push({separator:!0});for(let a of e.bound)n.push({id:`detach:${a.prop}`,label:`Detach ${a.prop}`,hint:a.source})}return n.push(...ic(e)),n.push(...r),n.push({separator:!0},{id:"delete",label:"Delete",keys:"Delete"}),n}var Ig=4;function ic(e){let t=(e.locksHere??[]).slice(0,Ig).map(n=>({id:`unlock:${n}`,label:`Unlock ${n}`}));e.anyLocked&&t.push({id:"unlockAll",label:"Unlock all"});let r=e.hiddenCount??0;return r>0&&t.push({id:"showAll",label:`Show all hidden (${r})`}),t.length===0?[]:[{separator:!0},...t]}function Al(e,t){let r=e.ownerDocument,n=t.formatKeys??Dn,o=r.createElement("div");o.className="vd-menu",o.setAttribute("role","menu"),o.hidden=!0,e.appendChild(o);let a=!1,i=[],l=-1;function d(_){o.replaceChildren(),i=[];for(let B of _){if(!Rg(B)){let D=r.createElement("div");D.className="vd-menu__separator",o.appendChild(D);continue}let R=r.createElement("button");R.type="button",R.className="vd-menu__item",R.dataset.command=B.id,R.disabled=B.disabled===!0,R.setAttribute("role","menuitem");let J=r.createElement("span");J.textContent=B.label,R.appendChild(J);let E=B.hint??(B.keys===void 0?void 0:n(B.keys));if(E!==void 0){let D=r.createElement("span");D.className="vd-menu__hint",D.textContent=E,R.appendChild(D)}o.appendChild(R),R.disabled||i.push(R)}}function c(_){o.style.left=`${_.x}px`,o.style.top=`${_.y}px`;let B=e.getBoundingClientRect(),R=o.getBoundingClientRect();if(R.width===0&&R.height===0)return;let J=_.x+R.width-B.width,E=_.y+R.height-B.height;J>0&&(o.style.left=`${Math.max(0,_.x-R.width)}px`),E>0&&(o.style.top=`${Math.max(0,_.y-R.height)}px`)}function h(_){i.length!==0&&(l=(_+i.length)%i.length,i[l]?.focus())}let x=_=>{let B=_.target?.closest("button");if(!B||B.disabled)return;_.stopPropagation();let R=B.dataset.command;k(),R&&t.onCommand(R)},y=_=>_.stopPropagation(),b=_=>{_.key==="ArrowDown"?(_.preventDefault(),h(l+1)):_.key==="ArrowUp"?(_.preventDefault(),h(l-1)):_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),k(),e.focus())},P=_=>{a&&(_.target instanceof Node&&o.contains(_.target)||k())};function k(){a&&(a=!1,l=-1,o.hidden=!0,r.removeEventListener("pointerdown",P,!0),r.removeEventListener("wheel",P,!0))}return o.addEventListener("click",x),o.addEventListener("pointerdown",y),o.addEventListener("keydown",b),{element:o,get isOpen(){return a},open(_,B){d(B),o.hidden=!1,a=!0,c(_),r.addEventListener("pointerdown",P,!0),r.addEventListener("wheel",P,!0),h(0)},close:k,destroy(){k(),o.removeEventListener("click",x),o.removeEventListener("pointerdown",y),o.removeEventListener("keydown",b),o.remove()}}}var Dr=2,lc=1.5,dc=1.5,fc=1.5,vc={hover:null,members:[],box:null,spacers:[],rings:[],lead:null,badge:null,caret:null,textSelection:[],draft:null,marquee:null,guides:[],measures:[],presence:null,highlight:[],parked:[],lockHint:null},uc=3.6,Fg=22,aa=14,sa=15,Ml=4,cc=15,pc=23,In=7,Bg=3.5,ia=12,Hg=4.5,la=16,qe=18,$l=9,Tl=6.1,hc="Drop or double-click",Ug=6.4,mc=16,Ot=3,xc=5,Vg=11,gc=6,yc=6.4;function bc(e,t){let r=e.ownerDocument,n=r.createElementNS(ne,"svg");n.setAttribute("class","vd-editor__overlay"),e.appendChild(n);let o=[],a=[],i=[],l=[],d=[],c=null,h=null,x=[],y=[];function b(w){let $=t({x:w.x,y:w.y}),M=t({x:w.x+w.w,y:w.y+w.h});return{x:$.x,y:$.y,w:M.x-$.x,h:M.y-$.y}}function P(w){for(;n.firstChild;)n.removeChild(n.firstChild);o=[],a=[],i=[],l=[],d=[],c=null,h=null,x=[],y=(w.pageLabels??[]).flatMap(M=>me(M));let $=w.turn&&w.turn.angle!==0?{angle:w.turn.angle,centre:t(w.turn.centre)}:null;for(let M of w.slots??[])ke(M);w.presence&&we(w.presence);for(let M of w.highlight)T("vd-editor__highlight",Pr(b(M),Dr),Dr);w.lockHint&&he(w.lockHint),w.hover&&T("vd-editor__hover",Fn(b(w.hover)),dc);for(let M of w.parked)T("vd-editor__parked",Fn(b(M)),dc);for(let M of w.members)T("vd-editor__member",Pr(b(M),lc),lc);w.lead&&T("vd-editor__lead",Fn(b(w.lead)),Dr);for(let M of w.guides)A(M);for(let M of w.measures)G(M);if(k($,()=>{for(let M of w.textSelection)n.appendChild(Q("vd-editor__text-selection",b(M)))}),w.box&&D(w.box),w.caret&&k($,()=>R(w.caret)),l=w.rings.map(J),i=w.spacers.map(E),w.badge&&w.box){let M=b(w.box.frame),L=c?Math.max(...[{x:M.x,y:M.y},{x:M.x+M.w,y:M.y},{x:M.x,y:M.y+M.h},{x:M.x+M.w,y:M.y+M.h}].map(H=>Pe(H,c.centre,c.angle).y)):M.y+M.h;se(w.badge,{x:M.x+M.w/2,y:L+$l+qe/2})}if(w.draft){let M=b(w.draft);if(w.draftEllipse){let L=r.createElementNS(ne,"ellipse");L.setAttribute("class","vd-editor__draft"),L.setAttribute("cx",String(M.x+M.w/2)),L.setAttribute("cy",String(M.y+M.h/2)),L.setAttribute("rx",String(Math.abs(M.w)/2)),L.setAttribute("ry",String(Math.abs(M.h)/2)),n.appendChild(L)}else n.appendChild(Q("vd-editor__draft",M))}w.marquee&&n.appendChild(Q("vd-editor__marquee",b(w.marquee))),w.path&&(h=$,k($,()=>B(w.path)))}function k(w,$){if(!w){$();return}let M=n.childNodes.length;$();let L=r.createElementNS(ne,"g");for(L.setAttribute("transform",`rotate(${w.angle} ${w.centre.x} ${w.centre.y})`);n.childNodes.length>M;)L.insertBefore(n.childNodes[n.childNodes.length-1],L.firstChild);n.appendChild(L)}function _(w,$){return $?Pe(w,$.centre,-$.angle):w}function B(w){let $=r.createElementNS(ne,"path");if($.setAttribute("class","vd-editor__path"),$.setAttribute("d",ut(ct(w.contours,t))),n.appendChild($),w.pending){let L=t(w.pending.from),H=t(w.pending.to),q=w.pending.c1?t(w.pending.c1):L,S=r.createElementNS(ne,"path");S.setAttribute("class","vd-editor__pending"),S.setAttribute("d",`M${L.x} ${L.y} C${q.x} ${q.y} ${H.x} ${H.y} ${H.x} ${H.y}`),n.appendChild(S)}for(let L of w.handles){let H=t(L.at),q=t(L.anchor),S=r.createElementNS(ne,"line");S.setAttribute("class","vd-editor__arm"),S.setAttribute("x1",String(q.x)),S.setAttribute("y1",String(q.y)),S.setAttribute("x2",String(H.x)),S.setAttribute("y2",String(H.y)),n.appendChild(S)}for(let L of w.handles){let H=t(L.at),q=r.createElementNS(ne,"circle");q.setAttribute("class","vd-editor__knob"),q.setAttribute("cx",String(H.x)),q.setAttribute("cy",String(H.y)),q.setAttribute("r",String(Bg)),n.appendChild(q)}for(let L of w.anchors){let H=t(L.at),q=Q(L.selected?"vd-editor__anchor vd-editor__anchor--on":"vd-editor__anchor",{x:Math.round(H.x-In/2)+.5,y:Math.round(H.y-In/2)+.5,w:In,h:In});q.setAttribute("data-key",L.key),n.appendChild(q)}if(w.closeAt){let L=t(w.closeAt),H=r.createElementNS(ne,"circle");H.setAttribute("class","vd-editor__close"),H.setAttribute("cx",String(L.x)),H.setAttribute("cy",String(L.y)),H.setAttribute("r",String(In)),n.appendChild(H)}let M=L=>({x:L.x-ia/2,y:L.y-ia/2,w:ia,h:ia});d=[...[...w.handles].reverse().map(L=>({kind:"handle",key:L.key,rect:M(t(L.at))})),...[...w.anchors].reverse().map(L=>({kind:"anchor",key:L.key,rect:M(t(L.at))}))]}function R(w){let $=t({x:w.x,y:w.y}),M=t({x:w.x,y:w.y+w.h}),L=r.createElementNS(ne,"line");L.setAttribute("class","vd-editor__caret");let H=Math.round($.x)+.5;L.setAttribute("x1",String(H)),L.setAttribute("y1",String($.y)),L.setAttribute("x2",String(H)),L.setAttribute("y2",String(M.y)),n.appendChild(L)}function J(w){let $=t(w.at),M=r.createElementNS(ne,"circle");return M.setAttribute("class","vd-editor__ring"),M.setAttribute("cx",String($.x)),M.setAttribute("cy",String($.y)),M.setAttribute("r",String(Hg)),n.appendChild(M),{id:w.id,rect:{x:$.x-la/2,y:$.y-la/2,w:la,h:la}}}function E(w){let $=t(w.at),M=w.axis==="x"?Ml:sa,L=w.axis==="x"?sa:Ml,H=Q("vd-editor__spacer",{x:$.x-M/2,y:$.y-L/2,w:M,h:L});H.setAttribute("rx",String(Ml/2)),n.appendChild(H),w.label!==null&&se(w.label,w.axis==="x"?{x:$.x,y:$.y-sa/2-$l-qe/2}:{x:$.x+sa/2+$l+qe,y:$.y});let q=w.axis==="x"?cc:pc,S=w.axis==="x"?pc:cc;return{id:w.id,rect:{x:$.x-q/2,y:$.y-S/2,w:q,h:S}}}function D(w){let $=b(w.frame),M=w.rotation??0;c=M===0?null:{angle:M,centre:{x:$.x+$.w/2,y:$.y+$.h/2}},k(c,()=>N(w,$)),w.handles&&w.rotatable&&(x=Mn.map(L=>{let{u:H,v:q}=$r(L);return{handle:L,at:{x:$.x+$.w*H,y:$.y+$.h*q}}}))}function N(w,$){if(T("vd-editor__outline",Pr($,Dr),Dr),!!w.handles){o=ci($).map(M=>({...M,bound:w.boundHandles.has(M.handle)}));for(let M of Mn){let{u:L,v:H}=$r(M),q={x:$.x+$.w*L-Tr/2,y:$.y+$.h*H-Tr/2,w:Tr,h:Tr};n.appendChild(Q("vd-editor__halo",Pr(q,fc+1))),n.appendChild(Q("vd-editor__handle",q))}a=w.adjusters.map(M=>{let L=t(M.at),H=r.createElementNS(ne,"circle");H.setAttribute("class","vd-editor__halo"),H.setAttribute("cx",String(L.x)),H.setAttribute("cy",String(L.y)),H.setAttribute("r",String(uc+fc/2+.5)),n.appendChild(H);let q=r.createElementNS(ne,"circle");return q.setAttribute("class","vd-editor__adjuster"),q.setAttribute("cx",String(L.x)),q.setAttribute("cy",String(L.y)),q.setAttribute("r",String(uc)),n.appendChild(q),{id:M.id,bound:M.bound,rect:{x:L.x-aa/2,y:L.y-aa/2,w:aa,h:aa}}})}}function A(w){let $=t(w.axis==="x"?{x:w.at,y:w.from}:{x:w.from,y:w.at}),M=t(w.axis==="x"?{x:w.at,y:w.to}:{x:w.to,y:w.at}),L=r.createElementNS(ne,"line");L.setAttribute("class","vd-editor__guide"),L.setAttribute("x1",String(be($.x))),L.setAttribute("y1",String(be($.y))),L.setAttribute("x2",String(be(M.x))),L.setAttribute("y2",String(be(M.y))),n.appendChild(L)}function G(w){let $=t(w.axis==="x"?{x:w.from,y:w.at}:{x:w.at,y:w.from}),M=t(w.axis==="x"?{x:w.to,y:w.at}:{x:w.at,y:w.to}),L=r.createElementNS(ne,"path");L.setAttribute("class","vd-editor__measure"),L.setAttribute("d",w.axis==="x"?`M${be($.x)} ${be($.y)-Ot} V${be($.y)+Ot} M${be($.x)} ${be($.y)} H${be(M.x)} M${be(M.x)} ${be(M.y)-Ot} V${be(M.y)+Ot}`:`M${be($.x)-Ot} ${be($.y)} H${be($.x)+Ot} M${be($.x)} ${be($.y)} V${be(M.y)} M${be(M.x)-Ot} ${be(M.y)} H${be(M.x)+Ot}`),n.appendChild(L);let H=r.createElementNS(ne,"text");H.setAttribute("class","vd-editor__measure-text"),H.setAttribute("x",String(($.x+M.x)/2)),H.setAttribute("y",String(($.y+M.y)/2-(w.axis==="x"?xc:0))),w.axis==="y"&&H.setAttribute("dx",String(xc)),H.textContent=w.label,n.appendChild(H)}function se(w,$){let M=Math.max(34,w.length*Tl+14),L=$.x-M/2,H=$.y-qe/2,q=Q("vd-editor__badge",{x:L,y:H,w:M,h:qe});q.setAttribute("rx",String(qe/2)),n.appendChild(q);let S=r.createElementNS(ne,"text");S.setAttribute("class","vd-editor__badge-text"),S.setAttribute("x",String(L+M/2)),S.setAttribute("y",String(H+qe/2)),S.textContent=w,n.appendChild(S)}function me(w){let $=b(w.frame),M=Math.floor($.w/yc);if(M<3)return[];let L=w.label.length>M?`${w.label.slice(0,M-1)}\u2026`:w.label,H=r.createElementNS(ne,"text");H.setAttribute("class",`vd-editor__page-label vd-editor__page-label--${w.state}`),H.setAttribute("x",String($.x)),H.setAttribute("y",String($.y-gc)),H.textContent=L,n.appendChild(H);let q=Math.min($.w,L.length*yc+4),S=Vg+6;return[{id:w.id,rect:{x:$.x,y:$.y-gc-S+3,w:q,h:S}}]}function he(w){let $=Fn(b(w.frame));n.appendChild(Q("vd-editor__lock",$));let M=`${w.label} \xB7 locked`,L=M.length*Tl+14,H=$.y+4,q=Q("vd-editor__lock-tag",{x:$.x+4,y:H,w:L,h:qe});q.setAttribute("rx","4"),n.appendChild(q);let S=r.createElementNS(ne,"text");S.setAttribute("class","vd-editor__lock-text"),S.setAttribute("x",String($.x+4+L/2)),S.setAttribute("y",String(H+qe/2)),S.textContent=M,n.appendChild(S)}function ke(w){let $=Fn(b(w.frame)),M=Q(w.target?"vd-editor__slot vd-editor__slot--target":"vd-editor__slot",$);M.setAttribute("rx","3"),n.appendChild(M);let L=S=>S.length*Ug+16<=$.w,H=[];$.h>=20&&L(w.label)&&H.push([w.label,"vd-editor__slot-label"]),H.length>0&&$.h>=48&&L(hc)&&H.push([hc,"vd-editor__slot-hint"]);let q=$.y+$.h/2-(H.length-1)*mc/2;H.forEach(([S,U],W)=>{let I=r.createElementNS(ne,"text");I.setAttribute("class",U),I.setAttribute("x",String($.x+$.w/2)),I.setAttribute("y",String(q+W*mc)),I.textContent=S,n.appendChild(I)})}function we(w){let $=w.frames.map(U=>Pr(b(U),Dr));for(let U of $)n.appendChild(Q("vd-editor__presence",U));let M=$[0];if(!M||!w.label)return;let L=Math.max(34,w.label.length*Tl+14),H=M.y-qe-3<0?M.y+3:M.y-qe-3,q=Q("vd-editor__presence-tag",{x:M.x,y:H,w:L,h:qe});q.setAttribute("rx","4"),n.appendChild(q);let S=r.createElementNS(ne,"text");S.setAttribute("class","vd-editor__presence-text"),S.setAttribute("x",String(M.x+L/2)),S.setAttribute("y",String(H+qe/2)),S.textContent=w.label,n.appendChild(S)}function T(w,$,M){let H=w==="vd-editor__highlight"?"vd-editor__halo vd-editor__halo--highlight":w==="vd-editor__hover"||w==="vd-editor__member"?"vd-editor__halo vd-editor__halo--quiet":"vd-editor__halo";n.appendChild(Q(H,Pr($,M+1))),n.appendChild(Q(w,$))}function Q(w,$){let M=r.createElementNS(ne,"rect");return M.setAttribute("class",w),M.setAttribute("x",String($.x)),M.setAttribute("y",String($.y)),M.setAttribute("width",String(Math.max(0,$.w))),M.setAttribute("height",String(Math.max(0,$.h))),M}return{element:n,render:P,hitHandle(w){let $=_(w,c);for(let M of o)if(et(M.rect,$.x,$.y))return{handle:M.handle,bound:M.bound};return null},hitAdjuster(w){let $=_(w,c);for(let M of a)if(et(M.rect,$.x,$.y))return{id:M.id,bound:M.bound};return null},hitSpacer(w){return Ll(i,w)},hitPath(w){let $=_(w,h),M=d.find(L=>et(L.rect,$.x,$.y));return M?{kind:M.kind,key:M.key}:null},hitRotate(w){let $=_(w,c),M=o.length===0?null:x;if(!M)return null;for(let L of M){let H=Math.hypot($.x-L.at.x,$.y-L.at.y);if(H<Tr/2+2||H>Fg)continue;let{u:q,v:S}=$r(L.handle);if(($.x-L.at.x)*(q*2-1)+($.y-L.at.y)*(S*2-1)>0)return L.handle}return null},hitRing(w){return Ll(l,w)},hitPageLabel(w){return Ll(y,w)},pageLabelRect(w){return y.find($=>$.id===w)?.rect??null},destroy(){n.remove(),o=[],a=[],i=[],l=[]}}}function Ll(e,t){for(let r of e)if(et(r.rect,t.x,t.y))return r.id;return null}function be(e){return Math.round(e)+.5}function Fn(e){return{x:e.x+.5,y:e.y+.5,w:Math.max(0,e.w-1),h:Math.max(0,e.h-1)}}function Pr(e,t){let r=t/2;return{x:e.x-r,y:e.y-r,w:e.w+t,h:e.h+t}}function wc(e,t){let r=[];return oe(e.root,n=>{if(t.has(n.id))return!1;n.type!=="image"||pe(n.src)||e.assets[n.src]===void 0&&r.push({id:n.id,src:n.src,label:n.name??n.src})}),r}function Dl(e){if(e.length<2)return null;let t=Ol("x",e),r=Ol("y",e);return r.length===1&&t.length===e.length?kc("x",e,t):t.length===1&&r.length===e.length?kc("y",e,r):r.length>=2&&t.length>=2?zg(e,t,r):null}function Ol(e,t){let r=[...t].sort((o,a)=>Nr(o.frame,e)-Nr(a.frame,e)),n=[];for(let o of r){let a=n[n.length-1];if(a&&Nr(o.frame,e)<a.hi-.01){n[n.length-1]={lo:a.lo,hi:Math.max(a.hi,fa(o.frame,e)),from:Math.min(a.from,Nr(o.frame,da(e))),to:Math.max(a.to,fa(o.frame,da(e))),members:[...a.members,o.id]};continue}n.push({lo:Nr(o.frame,e),hi:fa(o.frame,e),from:Nr(o.frame,da(e)),to:fa(o.frame,da(e)),members:[o.id]})}return n}function kc(e,t,r){return{kind:"run",items:t,series:[ua(e,r)],order:r.flatMap(n=>n.members)}}function zg(e,t,r){if(t.length*r.length!==e.length)return null;let n=[];for(let o of r)for(let a of t){let i=o.members.filter(l=>a.members.includes(l));if(i.length!==1||i[0]===void 0)return null;n.push(i[0])}return{kind:"grid",items:e,series:[ua("x",t),ua("y",r)],order:n}}function ua(e,t){let r=[];for(let n=0;n+1<t.length;n+=1){let o=t[n],a=t[n+1];!o||!a||r.push(a.lo-o.hi)}return{axis:e,tracks:t,gaps:r}}function it(e,t){return e.series.find(r=>r.axis===t)}function Pl(e){let t=e[0];return t===void 0?!1:e.every(r=>Math.abs(r-t)<.01)}function Nl(e){let t=[];for(let r of e.series){let n=e.series.find(o=>o.axis!==r.axis);for(let o=0;o<r.gaps.length;o+=1){let a=r.tracks[o],i=r.tracks[o+1],l=r.gaps[o];if(!a||!i||l===void 0)continue;let d=(a.hi+i.lo)/2,c=n?n.tracks.map(h=>(h.lo+h.hi)/2):[(Math.max(a.from,i.from)+Math.min(a.to,i.to))/2];for(let h of c)t.push({id:Sc(r.axis,o),axis:r.axis,index:o,gap:l,at:r.axis==="x"?{x:d,y:h}:{x:h,y:d}})}}return t}function Sc(e,t){return`${e}:${t}`}function ca(e){let[t,r]=e.split(":");if(t!=="x"&&t!=="y"||r===void 0)return null;let n=Number(r);return Number.isInteger(n)&&n>=0?{axis:t,index:n}:null}function Rl(e){return e.items.map(t=>({id:t.id,at:{x:t.frame.x+t.frame.w/2,y:t.frame.y+t.frame.h/2}}))}function pa(e,t,r){let n=it(e,t);return n?ha(n,r):new Map}function ha(e,t){let r=new Map,n=e.tracks[0];if(!n)return r;let o=n.hi;for(let a=1;a<e.tracks.length;a+=1){let i=e.tracks[a];if(!i)continue;let l=o+t;for(let d of i.members)r.set(d,l-i.lo);o=l+(i.hi-i.lo)}return r}function Il(e,t){return ua(t,Ol(t,e))}function Fl(e){let t=e.tracks,r=t[0],n=t[t.length-1];if(!r||!n||t.length<3)return null;let o=t.reduce((a,i)=>a+(i.hi-i.lo),0);return(n.hi-r.lo-o)/(t.length-1)}function Bl(e,t){let r=qg(e),n=0,o=1/0;for(let a=0;a<r.length;a+=1){let i=r[a];if(!i)continue;let l=Math.hypot(i.x-t.x,i.y-t.y);l<o&&(o=l,n=a)}return n}function qg(e){if(e.kind==="grid"){let r=it(e,"x")?.tracks??[];return(it(e,"y")?.tracks??[]).flatMap(o=>r.map(a=>({x:(a.lo+a.hi)/2,y:(o.lo+o.hi)/2})))}let t=e.series[0];return t?t.tracks.map(r=>t.axis==="x"?{x:(r.lo+r.hi)/2,y:(r.from+r.to)/2}:{x:(r.from+r.to)/2,y:(r.lo+r.hi)/2}):[]}function Hl(e,t,r){let n=[...e],[o]=n.splice(t,1);return o===void 0?[...e]:(n.splice(Math.max(0,Math.min(r,n.length)),0,o),n)}function Ul(e,t){let r=new Map(e.items.map(l=>[l.id,l.frame])),n=new Map;if(e.kind==="grid"){let l=it(e,"x")?.tracks??[],d=it(e,"y")?.tracks??[];return t.forEach((c,h)=>{let x=l[h%l.length],y=d[Math.floor(h/l.length)];x&&y&&n.set(c,{x:x.lo,y:y.lo})}),n}let o=e.series[0],a=o?.tracks[0];if(!o||!a)return n;let i=a.lo;return t.forEach((l,d)=>{let c=r.get(l);if(!c)return;let h=o.axis==="x"?c.w:c.h;n.set(l,o.axis==="x"?{x:i,y:c.y}:{x:c.x,y:i}),i+=h+(o.gaps[d]??0)}),n}function Vl(e,t,r){let n=new Map,o=e.items.find(d=>d.id===t),a=e.items.find(d=>d.id===r);if(!o||!a||t===r)return n;let i=e.kind==="grid"?["x","y"]:[e.series[0]?.axis??"x"],l=(d,c)=>({x:i.includes("x")?c.frame.x:d.frame.x,y:i.includes("y")?c.frame.y:d.frame.y});return n.set(t,l(o,a)),n.set(r,l(a,o)),n}function da(e){return e==="x"?"y":"x"}function Nr(e,t){return t==="x"?e.x:e.y}function fa(e,t){return t==="x"?e.x+e.w:e.y+e.h}var _c="vd-editor-styles",Cc=`
137
+ `;function wu(e){if(e.getElementById(vu))return;let t=e.createElement("style");t.id=vu,t.textContent=bu,e.head.appendChild(t)}function Su(e,t,r,n){return t?Bx(e,t,r,n):Fx(e,r,n)}function Fx(e,t,r){let n=di(e,r);return{measurer:n,update:o=>{n.load(o,t)},afterPaint:()=>{},destroy:()=>n.destroy()}}var ku=new WeakMap;function Bx(e,t,r,n){let o,a,i,l=()=>{if(!o)throw new Error("canvasFonts: update() before measuring");return o};return{measurer:{advance:(c,h)=>l().measurer.advance(c,h),metrics:c=>l().measurer.metrics(c),itemize:c=>l().measurer.itemize(c)},update(c){o&&c.fonts===a||(i?.(),o?.dispose(),o=t.forDocument(c,r?{loader:r}:{}),a=c.fonts,i=o.onChange(n))},afterPaint(){let c=e.fonts;if(!o||!c||typeof FontFace!="function")return;let h=ku.get(e);h||ku.set(e,h=new Set);for(let x of o.usedFaces()){if(h.has(x.id))continue;h.add(x.id);let y=new FontFace(x.id,Hx(x.bytes),{weight:String(x.weight),style:x.style});c.add(y),y.load().catch(()=>c.delete(y))}},destroy(){i?.(),o?.dispose(),o=void 0}}}function Hx(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}var zx=.01,Ux=.004,_u=40,Vx=16;function Ko(e,t){wu(e.ownerDocument);let r=t.document,n=O=>Su(e.ownerDocument,O,t.loadFont,()=>{P(r)}),o=n(t.fonts),a={advance:(O,X)=>o.measurer.advance(O,X),metrics:O=>o.measurer.metrics(O),itemize:O=>o.measurer.itemize?.(O)??[O]};o.update(r);let i=Ae(r),l=()=>t.resolveAsset?{measure:a,resolveAsset:t.resolveAsset}:{measure:a},d=$n(r,i,l()),c=t.camera??Uo,h=t.interactive??!0,x=t.wheel??"always";e.classList.add("vd-viewer"),t.surface&&(e.style.background=t.surface);let y=e.ownerDocument.createElementNS(ie,"svg");y.setAttribute("class","vd-viewer__surface"),y.setAttribute("width","100%"),y.setAttribute("height","100%");let v=e.ownerDocument.createElementNS(ie,"g");v.setAttribute("class","vd-viewer__camera"),v.style.isolation="isolate",y.appendChild(v);let D=e.ownerDocument.createElementNS(ie,"defs");v.appendChild(D);let k=e.ownerDocument.createElementNS(ie,"rect");k.setAttribute("class","vd-viewer__page"),v.appendChild(k),e.appendChild(y);let S=new Map;function B(){v.setAttribute("transform",ui(c))}function N(){E();let O=d.background!==void 0;oe(k,"x",String(d.x)),oe(k,"y",String(d.y)),oe(k,"width",String(O?d.width:0)),oe(k,"height",String(O?d.height:0)),ve(k,"fill",d.background??null);let X=new Set,z=k;for(let V of d.items){X.add(V.id);let U=S.get(V.id);(!U||U.tagName!==Cu(V))&&(U?.remove(),U=e.ownerDocument.createElementNS(ie,Cu(V)),U.setAttribute("data-vd-id",V.id),S.set(V.id,U)),jx(U,V),z.nextSibling!==U&&v.insertBefore(U,z.nextSibling),z=U}for(let[V,U]of S)X.has(V)||(U.remove(),S.delete(V));o.afterPaint(),t.onSceneChange?.(d,r)}let J=new Map;function E(){let O=[...d.gradients.map(ai),...d.items.filter(U=>U.shadows.length>0).map(U=>si(U)),...d.clips.map(oi)],X=new Set(O);for(let[U,Le]of J)X.has(U)||(Le.remove(),J.delete(U));let z=O.filter(U=>!J.has(U));if(z.length===0)return;[...new DOMParser().parseFromString(`<svg xmlns="${ie}">${z.join("")}</svg>`,"image/svg+xml").documentElement.children].forEach((U,Le)=>{let ne=e.ownerDocument.importNode(U,!0);D.appendChild(ne),J.set(z[Le],ne)})}function P(O){r=O,o.update(r),i=Ae(r),d=$n(r,i,l()),N()}function R(O){let X=e.getBoundingClientRect();return{x:O.clientX-X.left,y:O.clientY-X.top}}let C=0,G=0;function de(){e.classList.add("vd-viewer--interacting"),G&&clearTimeout(G),G=setTimeout(()=>{G=0,e.classList.remove("vd-viewer--interacting")},180)}function ye(){C&&(cancelAnimationFrame(C),C=0),B(),t.onCameraChange?.(c)}function xe(O){c=O,ye()}function ke(O){c=O,de(),!C&&(C=requestAnimationFrame(()=>{C=0,B(),t.onCameraChange?.(c)}))}let Se=null,A=null,te=!1,w=O=>{if(x==="modifier"&&!O.ctrlKey&&!O.metaKey)return;O.preventDefault();let X=R(O),z=O.deltaMode===1?Vx:O.deltaMode===2?e.clientHeight||800:1,V=O.deltaX*z,U=O.deltaY*z;if(O.ctrlKey||O.metaKey){let Le=O.ctrlKey?zx:Ux,ne=Math.max(-_u,Math.min(_u,U));ke(qo(c,X,Math.exp(-ne*Le)));return}if(O.shiftKey&&V===0){ke(Pt(c,-U,0));return}ke(Pt(c,-V,-U))},$=O=>{(O.button===1||O.button===0&&te)&&(O.preventDefault(),Se=O.pointerId,A=R(O),e.setPointerCapture(O.pointerId))},M=O=>{if(Se!==O.pointerId||!A)return;let X=R(O);ke(Pt(c,X.x-A.x,X.y-A.y)),A=X},T=O=>{Se===O.pointerId&&(Se=null,A=null,e.hasPointerCapture(O.pointerId)&&e.releasePointerCapture(O.pointerId))},H=O=>{O.code==="Space"&&(te=!0)},j=O=>{O.code==="Space"&&(te=!1)};h&&(e.addEventListener("wheel",w,{passive:!1}),e.addEventListener("pointerdown",$),e.addEventListener("pointermove",M),e.addEventListener("pointerup",T),e.addEventListener("pointercancel",T),e.ownerDocument.addEventListener("keydown",H),e.ownerDocument.addEventListener("keyup",j)),B(),N();let F={element:e,surface:y,update:P,getDocument:()=>r,getScene:()=>d,getResolution:()=>i,getMeasurer:()=>a,setFonts(O){o.destroy(),o=n(O),P(r)},getCamera:()=>c,setCamera:xe,zoomBy(O,X){let z=e.getBoundingClientRect(),V=X??{x:z.width/2,y:z.height/2};xe(qo(c,V,O))},fitToContent(O=32){let X=e.getBoundingClientRect();xe(or({x:d.x,y:d.y,width:d.width,height:d.height},{width:X.width||d.width,height:X.height||d.height},O))},screenToDocument:O=>Vo(c,O),documentToScreen:O=>fi(c,O),pointerPoint:R,hitTest(O,X){for(let z=d.items.length-1;z>=0;z--){let V=d.items[z];if(V&&tg(V,O,eg/c.zoom)&&(!X||X(V.id)))return V.id}return null},linkAt(O,X){for(let z=d.items.length-1;z>=0;z--){let V=d.items[z];if(V?.kind!=="text"||X&&!X(V.id))continue;let U=V.rotation===0?O:Be(O,{x:V.x+V.w/2,y:V.y+V.h/2},-V.rotation);for(let Le of V.lines){if(U.y<Le.y||U.y>Le.y+Le.h)continue;let ne=Le.spans.find(Ne=>U.x>=Ne.x&&U.x<=Ne.x+Ne.w);if(ne)return ne.style.link}}},itemOf:O=>d.items.find(X=>X.id===O),elementOf:O=>S.get(O),destroy(){h&&(e.removeEventListener("wheel",w),e.removeEventListener("pointerdown",$),e.removeEventListener("pointermove",M),e.removeEventListener("pointerup",T),e.removeEventListener("pointercancel",T),e.ownerDocument.removeEventListener("keydown",H),e.ownerDocument.removeEventListener("keyup",j)),C&&cancelAnimationFrame(C),G&&clearTimeout(G),C=0,G=0,o.destroy(),e.classList.remove("vd-viewer--interacting"),y.remove(),S.clear(),e.classList.remove("vd-viewer")}};return t.autoFit&&F.fitToContent(),F}var qx="vd-clip-";function Kx(e){return qx+e}function Mu(e){return`url(#${Kx(e)})`}function Cu(e){return li(e)?"g":ci(e)}function ci(e){switch(e.kind){case"ellipse":return"ellipse";case"frame":return"rect";case"image":return e.href===void 0?"rect":"image";case"rect":return"rect";case"text":return"text";case"vector":return"path"}}function jx(e,t){if(e.tagName!=="g"){Eu(e,t);return}ve(e,"clip-path",t.clip===void 0?null:Mu(t.clip)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend;let r=e.firstElementChild;(!r||r.tagName!==ci(t))&&(r?.remove(),r=e.ownerDocument.createElementNS(ie,ci(t)),e.appendChild(r)),Eu(r,{...t,clip:void 0,blend:"normal"})}function Eu(e,t){switch(ve(e,"clip-path",t.clip===void 0?null:Mu(t.clip)),ve(e,"transform",t.rotation===0?null:ii(t)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend,e.style.filter=t.shadows.length>0?`url(#${zo}${t.id})`:"",t.kind){case"ellipse":Zx(e,t);return;case"frame":Gx(e,t);return;case"image":Wx(e,t);return;case"rect":Jx(e,t);return;case"text":Yx(e,t);return;case"vector":Qx(e,t);return}}function Gx(e,t){oe(e,"class","vd-viewer__page"),oe(e,"x",String(t.x)),oe(e,"y",String(t.y)),oe(e,"width",String(t.w)),oe(e,"height",String(t.h)),ve(e,"fill",t.background??null)}function Wx(e,t){if(oe(e,"x",String(t.x)),oe(e,"y",String(t.y)),oe(e,"width",String(t.w)),oe(e,"height",String(t.h)),ve(e,"opacity",t.opacity<1?String(t.opacity):null),t.href===void 0){oe(e,"class","vd-viewer__missing"),ve(e,"rx",t.radius>0?String(t.radius):null);return}oe(e,"href",t.href),oe(e,"preserveAspectRatio",Xx[t.fit])}var Xx={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"};function Yx(e,t){ve(e,"opacity",t.opacity<1?String(t.opacity):null),oe(e,"xml:space","preserve");let r=t.lines.flatMap(o=>o.spans).filter(o=>o.text!==""),n=e.ownerDocument;for(;e.childNodes.length>r.length;)e.lastChild?.remove();for(;e.childNodes.length<r.length;)e.appendChild(n.createElementNS(ie,"tspan"));r.forEach((o,a)=>{let i=e.childNodes[a];i.textContent!==o.text&&(i.textContent=o.text),oe(i,"x",String(o.x)),oe(i,"y",String(o.y)),oe(i,"font-family",o.style.family),oe(i,"font-size",String(o.style.size)),oe(i,"fill",o.style.fill),ve(i,"font-weight",o.style.weight===400?null:String(o.style.weight)),ve(i,"font-style",o.style.italic?"italic":null),ve(i,"letter-spacing",o.style.letterSpacing===0?null:String(o.style.letterSpacing)),ve(i,"data-vd-link",o.style.link??null);let l=[o.style.underline?"underline":"",o.style.strike?"line-through":""].filter(Boolean).join(" ");ve(i,"text-decoration",l===""?null:l)})}function Jx(e,t){ve(e,"class",null),oe(e,"x",String(t.x)),oe(e,"y",String(t.y)),oe(e,"width",String(t.w)),oe(e,"height",String(t.h)),oe(e,"fill",t.fill),ve(e,"rx",t.radius>0?String(t.radius):null),ve(e,"stroke",t.stroke??null),ve(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),ve(e,"opacity",t.opacity<1?String(t.opacity):null)}function Au(e,t){oe(e,"fill",t.fill),ve(e,"stroke",t.stroke??null),ve(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),ve(e,"opacity",t.opacity<1?String(t.opacity):null)}function Zx(e,t){oe(e,"cx",String(t.x+t.w/2)),oe(e,"cy",String(t.y+t.h/2)),oe(e,"rx",String(t.w/2)),oe(e,"ry",String(t.h/2)),Au(e,t)}function Qx(e,t){oe(e,"d",t.d),Au(e,t),ve(e,"fill-rule",t.rule==="nonzero"?null:t.rule),ve(e,"stroke-linecap",t.cap==="butt"?null:t.cap),ve(e,"stroke-linejoin",t.join==="miter"?null:t.join)}function oe(e,t,r){e.getAttribute(t)!==r&&e.setAttribute(t,r)}function ve(e,t,r){r===null?e.hasAttribute(t)&&e.removeAttribute(t):oe(e,t,r)}var eg=4;function tg(e,t,r){let n=e.rotation===0?t:Be(t,{x:e.x+e.w/2,y:e.y+e.h/2},-e.rotation),o=n.x>=e.x&&n.x<=e.x+e.w&&n.y>=e.y&&n.y<=e.y+e.h;if(e.kind==="ellipse"){let a=e.stroke!==void 0?e.strokeWidth/2:0,i=e.w/2+a,l=e.h/2+a;if(i<=0||l<=0)return!1;let d=(n.x-(e.x+e.w/2))/i,c=(n.y-(e.y+e.h/2))/l;return d*d+c*c<=1}if(e.kind==="vector"){let a=e.stroke!==void 0&&e.strokeWidth>0;return ds(e.contours,n,{fill:e.fill!=="none",rule:e.rule,reach:(a?e.strokeWidth/2:0)+r})}return o}function pi(e,t){let r=e.root.id;if(r===t)return e;let n=o=>{if(!me(o))return o;let a=ot(o.expr);return!a.ok||!nr(a.ast).nodes.includes(r)?o:{expr:_n(Dt(a.ast,i=>i===r?t:void 0))}};return{...e,root:{...$u(e.root,n),id:t}}}function $u(e,t){let r=e,n={};for(let[o,a]of Object.entries(r)){if(o==="children"&&Array.isArray(a)){n[o]=a.map(i=>$u(i,t));continue}n[o]=t(a)}return n}var mi=["nw","n","ne","e","se","s","sw","w"],On=["nw","ne","se","sw"];function jo(e){let t=[];return e.includes("w")&&t.push("x","w"),e.includes("e")&&t.push("w"),e.includes("n")&&t.push("y","h"),e.includes("s")&&t.push("h"),t}function Nr(e){let t=e.includes("w")?0:e.includes("e")?1:.5,r=e.includes("n")?0:e.includes("s")?1:.5;return{u:t,v:r}}function xi(e){switch(e){case"e":case"w":return 0;case"n":case"s":return 90;case"nw":case"se":return 45;case"ne":case"sw":return 135}}var Ln=1;function yt(e,t,r,n){let{x:o,y:a,w:i,h:l}=e;if(t.includes("w")){let d=o+i;o=Math.min(o+r,d-Ln),i=d-o}if(t.includes("e")&&(i=Math.max(Ln,i+r)),t.includes("n")){let d=a+l;a=Math.min(a+n,d-Ln),l=d-a}return t.includes("s")&&(l=Math.max(Ln,l+n)),{x:o,y:a,w:i,h:l}}function ar(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Go(e,t){let r=[];return t.x!==e.x&&r.push("x"),t.y!==e.y&&r.push("y"),t.w!==e.w&&r.push("w"),t.h!==e.h&&r.push("h"),r}function at(e){if(e.length===0)return null;let t=1/0,r=1/0,n=-1/0,o=-1/0;for(let a of e)t=Math.min(t,a.x),r=Math.min(r,a.y),n=Math.max(n,a.x+a.w),o=Math.max(o,a.y+a.h);return{x:t,y:r,w:n-t,h:o-r}}function gi(e,t){return e.x<t.x+t.w&&e.x+e.w>t.x&&e.y<t.y+t.h&&e.y+e.h>t.y}function st(e,t,r){return t>=e.x&&t<=e.x+e.w&&r>=e.y&&r<=e.y+e.h}var Rr=7,hi=15,Tn=9;function yi(e){let t=[],r=hi/2;for(let l of On){let{u:d,v:c}=Nr(l);t.push({handle:l,rect:{x:e.x+e.w*d-r,y:e.y+e.h*c-r,w:hi,h:hi}})}let n=r,o=Math.max(0,e.w-n*2),a=Math.max(0,e.h-n*2),i=Tn/2;return t.push({handle:"n",rect:{x:e.x+n,y:e.y-i,w:o,h:Tn}},{handle:"s",rect:{x:e.x+n,y:e.y+e.h-i,w:o,h:Tn}},{handle:"w",rect:{x:e.x-i,y:e.y+n,w:Tn,h:a}},{handle:"e",rect:{x:e.x+e.w-i,y:e.y+n,w:Tn,h:a}}),t}function Lu(e,t,r,n,o){if(o===0)return yt(e,t,r,n);let a=Be({x:r,y:n},{x:0,y:0},-o),i=yt(e,t,a.x,a.y),l=Ge(e),d=Ge(i),c={x:l.x-d.x,y:l.y-d.y},h=Be(c,{x:0,y:0},o);return{...i,x:i.x+c.x-h.x,y:i.y+c.y-h.y}}function Tu(e,t){return Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI}function Ou(e,t,r,n,o){let a=Tu(e,r)-Tu(e,t);return o?Math.round((n+a)/o)*o-n:a}function Du(e,t,r){return e.map(n=>{let o=Ge(n.frame),a=Be(o,t,r);return{id:n.id,frame:{...n.frame,x:a.x-n.frame.w/2,y:a.y-n.frame.h/2},rotation:kn(n.rotation+r)}})}function Pu(e,t,r,n){let o=r.w===0?1:n.w/r.w,a=r.h===0?1:n.h/r.h,i=t*Math.PI/180,l=Math.cos(i),d=Math.sin(i),c=e.w*Math.hypot(o*l,a*d),h=e.h*Math.hypot(o*d,a*l),x=Ge(e),y=n.x+(x.x-r.x)*o,v=n.y+(x.y-r.y)*a;return{x:y-c/2,y:v-h/2,w:c,h}}function $e(e,t){return`${e}:${t}`}function Yo(e){let[t,r]=e.split(":").map(Number);if(!(t===void 0||r===void 0||!Number.isInteger(t)||!Number.isInteger(r)))return{contour:t,index:r}}function Nu(e){let t=e.split(":"),r=t[2],n=Yo(t.slice(0,2).join(":"));if(!(!n||r!=="in"&&r!=="out"))return{...n,side:r}}function bi(e,t){let r=Yo(t);return r?e[r.contour]?.anchors[r.index]:void 0}function wi(e,t){let r=[];for(let n of t){let o=Yo(n);o&&e[o.contour]?.anchors[o.index]&&r.push($e(o.contour,o.index))}return r}function ki(e){return e.flatMap((t,r)=>t.anchors.map((n,o)=>$e(r,o)))}function vi(e,t,r,n){return e.map((o,a)=>a===t?{...o,anchors:o.anchors.map((i,l)=>l===r?n:i)}:o)}var Dn=(e,t,r)=>({x:e.x+t,y:e.y+r});function Jo(e,t,r,n){return e.map((o,a)=>({...o,anchors:o.anchors.map((i,l)=>t.has($e(a,l))?dt(Dn(i,r,n),i.in&&Dn(i.in,r,n),i.out&&Dn(i.out,r,n)):i)}))}function Wo(e){if(!e.in||!e.out)return!1;let t=e.in.x-e.x,r=e.in.y-e.y,n=e.out.x-e.x,o=e.out.y-e.y,a=Math.hypot(t,r),i=Math.hypot(n,o);return a===0||i===0?!1:(t*n+r*o)/(a*i)<-.995}function Xo(e,t,r,n,o,a){let i=e[t]?.anchors[r];if(!i)return[...e];let d=i[n==="in"?"out":"in"];if(a.smooth&&!a.breakSmooth&&d){let h=Math.hypot(d.x-i.x,d.y-i.y),x=o.x-i.x,y=o.y-i.y,v=Math.hypot(x,y);v>0&&(d={x:i.x-x/v*h,y:i.y-y/v*h})}let c=n==="in"?dt(i,o,d):dt(i,d,o);return vi(e,t,r,c)}function Ru(e,t){let r=Yo(t),n=r?e[r.contour]:void 0,o=n?.anchors[r?.index??-1];if(!r||!n||!o)return[...e];if(o.in||o.out)return vi(e,r.contour,r.index,dt(o));let a=n.anchors.length,i=r.index>0?n.anchors[r.index-1]:n.closed?n.anchors[a-1]:void 0,l=r.index<a-1?n.anchors[r.index+1]:n.closed?n.anchors[0]:void 0;if(!i&&!l)return[...e];let d=i??o,c=l??o,h=c.x-d.x,x=c.y-d.y,y=Math.hypot(h,x);if(y===0)return[...e];h/=y,x/=y;let v=i?Math.hypot(o.x-i.x,o.y-i.y)/3:0,D=l?Math.hypot(l.x-o.x,l.y-o.y)/3:0,k=i?{x:o.x-h*v,y:o.y-x*v}:void 0,S=l?{x:o.x+h*D,y:o.y+x*D}:void 0;return vi(e,r.contour,r.index,dt(o,k,S))}function Iu(e,t){let r=[];return e.forEach((n,o)=>{let a=n.anchors.filter((i,l)=>!t.has($e(o,l)));a.length>=2&&r.push({closed:n.closed,anchors:a})}),r}function Fu(e,t,r,n,o,a,i){let l=e[t];if(!l)return[...e];let d=l.anchors.length,c=(r+1)%d;if(i)return Jo(e,new Set([$e(t,r),$e(t,c)]),o,a);let h=Math.min(.85,Math.max(.15,n)),x=1/(3*(1-h)*h),y=l.anchors[r],v=l.anchors[c],D=Dn(y.out??y,o*x,a*x),k=Dn(v.in??v,o*x,a*x),S=Xo(e,t,r,"out",D,{smooth:Wo(y),breakSmooth:!1});return S=Xo(S,t,c,"in",k,{smooth:Wo(v),breakSmooth:!1}),S}function Bu(e,t){return e.map((r,n)=>r.closed||r.anchors.length<2?r:t.size===0||t.has($e(n,0))&&t.has($e(n,r.anchors.length-1))?{...r,closed:!0}:r)}function Si(e,t){let r=[],n=new Set,o=(a,i,l)=>{let d=e[a]?.anchors[i],c=d?.[l],h=`${$e(a,i)}:${l}`;!d||!c||n.has(h)||(n.add(h),r.push({key:h,at:c,anchor:d}))};return e.forEach((a,i)=>{let l=a.anchors.length;a.anchors.forEach((d,c)=>{if(!t.has($e(i,c)))return;o(i,c,"in"),o(i,c,"out");let h=c>0?c-1:a.closed?l-1:-1,x=c<l-1?c+1:a.closed?0:-1;h>=0&&o(i,h,"out"),x>=0&&o(i,x,"in")})}),r}function Pn(e,t){let r=t.x-e.x,n=t.y-e.y,o=Math.round(Math.atan2(n,r)/(Math.PI/4))*(Math.PI/4),a=r*Math.cos(o)+n*Math.sin(o);return{x:e.x+Math.cos(o)*a,y:e.y+Math.sin(o)*a}}function Hu(e){return{closed:e.closed,anchors:[...e.anchors].reverse().map(t=>dt(t,t.out,t.in))}}function _i(e){if(!e)return null;for(let t of e.items){if(t.kind!=="file"||!t.type.startsWith("image/"))continue;let r=t.getAsFile();if(r)return r}return null}async function Zo(e,t){let r;try{r=await createImageBitmap(e)}catch{return null}try{let n=Math.min(1,t/Math.max(r.width,r.height));return n>=1?{bytes:new Uint8Array(await e.arrayBuffer()),type:e.type||"image/png",width:r.width,height:r.height}:await ag(r,n,e.type)}finally{r.close()}}async function ag(e,t,r){let n=Math.max(1,Math.round(e.width*t)),o=Math.max(1,Math.round(e.height*t)),a=document.createElement("canvas");a.width=n,a.height=o;let i=a.getContext("2d");if(!i)return null;i.drawImage(e,0,0,n,o);let l=r==="image/png"?"image/png":"image/webp",d=await new Promise(c=>{a.toBlob(c,l,.9)});return d?{bytes:new Uint8Array(await d.arrayBuffer()),type:d.type||l,width:n,height:o}:null}function zu(e,t,r,n){let o=Math.min(1,r/e,n/t);return{w:Math.round(e*o),h:Math.round(t*o)}}var sg={left:"x",hcenter:"x",right:"x",top:"y",vcenter:"y",bottom:"y"};function Qo(e){return sg[e]}function ig(e,t,r){switch(e){case"left":return t.x;case"hcenter":return t.x+(t.w-r)/2;case"right":return t.x+t.w-r;case"top":return t.y;case"vcenter":return t.y+(t.h-r)/2;case"bottom":return t.y+t.h-r}}function Ci(e,t,r){let n=Qo(r),o=new Map;for(let a of e){let i=n==="x"?a.frame.w:a.frame.h,l=n==="x"?a.frame.x:a.frame.y;o.set(a.id,ig(r,t,i)-l)}return o}var Uu=[{key:"nw",sx:0,sy:0},{key:"ne",sx:1,sy:0},{key:"se",sx:1,sy:1},{key:"sw",sx:0,sy:1}],lg={id:"radius",prop:"radius",handles(e,t,r){let n=this.max(e),o=Math.min(Math.max(t,r),Math.max(n,r));return Uu.map(({key:a,sx:i,sy:l})=>({id:`radius:${a}`,at:{x:e.x+(i===0?o:e.w-o),y:e.y+(l===0?o:e.h-o)}}))},valueAt(e,t,r){let n=fg(t);if(!n)return 0;let o=e.x+(n.sx===0?0:e.w),a=e.y+(n.sy===0?0:e.h),i=Math.max(0,n.sx===0?r.x-o:o-r.x),l=Math.max(0,n.sy===0?r.y-a:a-r.y);return Math.min((i+l)/2,this.max(e))},max(e){return Math.max(0,Math.min(e.w,e.h)/2)}},dg={canvas:[],frame:[],group:[],rect:[lg]};function Nn(e){return dg[e.type]??[]}function ea(e,t){let r=t.split(":")[0];return Nn(e).find(n=>n.id===r)}function fg(e){let t=e.split(":")[1];return Uu.find(r=>r.key===t)}var Ei=[["path",{d:"m15 16 2.536-7.328a1.02 1.02 1 0 1 1.928 0L22 16"}],["path",{d:"M15.697 14h5.606"}],["path",{d:"m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16"}],["path",{d:"M3.304 13h6.392"}]];var Mi=[["path",{d:"M2 12h20"}],["path",{d:"M10 16v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-4"}],["path",{d:"M10 8V4a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v4"}],["path",{d:"M20 16v1a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-1"}],["path",{d:"M14 8V7c0-1.1.9-2 2-2h2a2 2 0 0 1 2 2v1"}]];var Ai=[["path",{d:"M12 2v20"}],["path",{d:"M8 10H4a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h4"}],["path",{d:"M16 10h4a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-4"}],["path",{d:"M8 20H7a2 2 0 0 1-2-2v-2c0-1.1.9-2 2-2h1"}],["path",{d:"M16 14h1a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2h-1"}]];var $i=[["rect",{width:"6",height:"16",x:"4",y:"2",rx:"2"}],["rect",{width:"6",height:"9",x:"14",y:"9",rx:"2"}],["path",{d:"M22 22H2"}]];var Ti=[["rect",{width:"16",height:"6",x:"2",y:"4",rx:"2"}],["rect",{width:"9",height:"6",x:"9",y:"14",rx:"2"}],["path",{d:"M22 22V2"}]];var Li=[["rect",{width:"6",height:"14",x:"4",y:"5",rx:"2"}],["rect",{width:"6",height:"10",x:"14",y:"7",rx:"2"}],["path",{d:"M17 22v-5"}],["path",{d:"M17 7V2"}],["path",{d:"M7 22v-3"}],["path",{d:"M7 5V2"}]];var Oi=[["rect",{width:"6",height:"16",x:"4",y:"6",rx:"2"}],["rect",{width:"6",height:"9",x:"14",y:"6",rx:"2"}],["path",{d:"M22 2H2"}]];var Di=[["rect",{width:"9",height:"6",x:"6",y:"14",rx:"2"}],["rect",{width:"16",height:"6",x:"6",y:"4",rx:"2"}],["path",{d:"M2 2v20"}]];var Pi=[["path",{d:"M22 17h-3"}],["path",{d:"M22 7h-5"}],["path",{d:"M5 17H2"}],["path",{d:"M7 7H2"}],["rect",{x:"5",y:"14",width:"14",height:"6",rx:"2"}],["rect",{x:"7",y:"4",width:"10",height:"6",rx:"2"}]];var Ni=[["rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"}],["rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"}],["path",{d:"M2 12h20"}]];var Ri=[["rect",{width:"14",height:"6",x:"5",y:"12",rx:"2"}],["rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"}],["path",{d:"M2 22h20"}]];var Ii=[["rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"}],["rect",{width:"10",height:"6",x:"7",y:"6",rx:"2"}],["path",{d:"M2 2h20"}]];var Fi=[["circle",{cx:"15",cy:"9",r:"7"}],["circle",{cx:"9",cy:"15",r:"7"}]];var Bi=[["path",{d:"M20 6 9 17l-5-5"}]];var Hi=[["path",{d:"m6 9 6 6 6-6"}]];var zi=[["path",{d:"m9 18 6-6-6-6"}]];var Ui=[["circle",{cx:"12",cy:"12",r:"10"}]];var Vi=[["path",{d:"M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z"}]];var qi=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}],["circle",{cx:"12",cy:"12",r:"3"}]];var Ki=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}],["path",{d:"m2 2 20 20"}]];var ji=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M10 9H8"}],["path",{d:"M16 13H8"}],["path",{d:"M16 17H8"}]];var Gi=[["line",{x1:"22",x2:"2",y1:"6",y2:"6"}],["line",{x1:"22",x2:"2",y1:"18",y2:"18"}],["line",{x1:"6",x2:"6",y1:"2",y2:"22"}],["line",{x1:"18",x2:"18",y1:"2",y2:"22"}]];var Wi=[["path",{d:"M3 7V5c0-1.1.9-2 2-2h2"}],["path",{d:"M17 3h2c1.1 0 2 .9 2 2v2"}],["path",{d:"M21 17v2c0 1.1-.9 2-2 2h-2"}],["path",{d:"M7 21H5c-1.1 0-2-.9-2-2v-2"}],["rect",{width:"7",height:"5",x:"7",y:"7",rx:"1"}],["rect",{width:"7",height:"5",x:"10",y:"12",rx:"1"}]];var Xi=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}],["circle",{cx:"9",cy:"9",r:"2"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"}]];var Yi=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"}]];var ta=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1"}]];var Ji=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}]];var Zi=[["path",{d:"M5 12h14"}]];var Qi=[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"}]];var el=[["path",{d:"m18 8 4 4-4 4"}],["path",{d:"M2 12h20"}],["path",{d:"m6 8-4 4 4 4"}]];var tl=[["path",{d:"M12 2v20"}],["path",{d:"m8 18 4 4 4-4"}],["path",{d:"m8 6 4-4 4 4"}]];var rl=[["path",{d:"M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z"}],["path",{d:"m18 13-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18"}],["path",{d:"m2.3 2.3 7.286 7.286"}],["circle",{cx:"11",cy:"11",r:"2"}]];var nl=[["path",{d:"m12 9-8.414 8.414A2 2 0 0 0 3 18.828v1.344a2 2 0 0 1-.586 1.414A2 2 0 0 1 3.828 21h1.344a2 2 0 0 0 1.414-.586L15 12"}],["path",{d:"m18 9 .4.4a1 1 0 1 1-3 3l-3.8-3.8a1 1 0 1 1 3-3l.4.4 3.4-3.4a1 1 0 1 1 3 3z"}],["path",{d:"m2 22 .414-.414"}]];var ol=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"}]];var al=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];var sl=[["path",{d:"m15 14 5-5-5-5"}],["path",{d:"M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13"}]];var il=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}],["path",{d:"M21 3v5h-5"}]];var ll=[["circle",{cx:"19",cy:"5",r:"2"}],["circle",{cx:"5",cy:"19",r:"2"}],["path",{d:"M5 17A12 12 0 0 1 17 5"}]];var dl=[["path",{d:"M21 11a8 8 0 0 0-8-8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}]];var fl=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];var ra=[["path",{d:"M21 5H3"}],["path",{d:"M21 12H9"}],["path",{d:"M21 19H7"}]];var na=[["path",{d:"M21 5H3"}],["path",{d:"M17 12H7"}],["path",{d:"M19 19H5"}]];var oa=[["path",{d:"M3 5h18"}],["path",{d:"M3 12h18"}],["path",{d:"M3 19h18"}]];var Rn=[["path",{d:"M21 5H3"}],["path",{d:"M15 12H3"}],["path",{d:"M17 19H3"}]];var ul=[["path",{d:"M12 4v16"}],["path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"}],["path",{d:"M9 20h6"}]];var cl=[["path",{d:"M9 14 4 9l5-5"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"}]];var pl=[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16"}]];var hl=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var In=e=>e.replace(/\b(?:CmdOrCtrl|CommandOrControl)\b/g,"Ctrl");function Vu(e,t){let n=e.ownerDocument.createElement("div");n.className="vd-chrome",n.setAttribute("role","toolbar"),n.setAttribute("aria-label","Canvas tools"),n.innerHTML=ug(t),e.appendChild(n);let o=new Map;for(let h of n.querySelectorAll("[data-tool]"))o.set(h.dataset.tool,h);let a=n.querySelector('[data-act="undo"]'),i=n.querySelector('[data-act="redo"]'),l=n.querySelector('[data-act="zoom"]'),d=h=>{let x=h.target?.closest("button");if(!x)return;h.stopPropagation();let y=x.dataset.tool;if(y){t.onTool(y);return}switch(x.dataset.act){case"undo":t.onUndo();return;case"redo":t.onRedo();return;case"zoom":t.onZoomReset();return;case"play":t.onPlay?.();return}},c=h=>h.stopPropagation();return n.addEventListener("click",d),n.addEventListener("pointerdown",c),{element:n,setTool(h){for(let[x,y]of o)y.setAttribute("aria-pressed",String(x===h))},setHistory(h,x){a&&(a.disabled=!h),i&&(i.disabled=!x)},setZoom(h){l&&(l.textContent=`${Math.round(h*100)}%`)},destroy(){n.removeEventListener("click",d),n.removeEventListener("pointerdown",c),n.remove()}}}function ug(e){let t=e.formatKeys??In;return[vt({tool:"select",label:"Select",hint:"V",icon:"select"}),vt({tool:"frame",label:"Frame",hint:"F",icon:"frame"}),vt({tool:"rect",label:"Rectangle",hint:"R",icon:"rect"}),vt({tool:"ellipse",label:"Ellipse",hint:"O",icon:"ellipse"}),vt({tool:"pen",label:"Pen",hint:"P",icon:"pen"}),vt({tool:"text",label:"Text",hint:"T",icon:"text"}),'<span class="vd-chrome__divider"></span>',vt({act:"undo",label:"Undo",hint:t("CmdOrCtrl+Z"),icon:"undo"}),vt({act:"redo",label:"Redo",hint:t("CmdOrCtrl+Shift+Z"),icon:"redo"}),'<span class="vd-chrome__divider"></span>','<button type="button" class="vd-chrome__zoom" data-act="zoom" title="Fit to screen">100%</button>',...e.onPlay?['<span class="vd-chrome__divider"></span>',vt({act:"play",label:"Play",hint:e.playHint,icon:"play"})]:[]].join("")}function vt(e){let t=e.tool?`data-tool="${e.tool}"`:`data-act="${e.act??""}"`,r=e.tool?' aria-pressed="false"':"";return`<button type="button" class="vd-chrome__tool" ${t}${r} title="${e.hint?`${e.label} \xB7 ${e.hint}`:e.label}" aria-label="${e.label}">`+He(e.icon)+"</button>"}var cg={select:Qi,frame:Gi,rect:fl,ellipse:Ui,pen:rl,vector:ll,text:ul,undo:cl,redo:sl,"align-left":Di,"align-hcenter":Ai,"align-right":Ti,"align-top":Oi,"align-vcenter":Mi,"align-bottom":$i,"distribute-h":Li,"distribute-v":Pi,group:Wi,image:Xi,eye:qi,"eye-off":Ki,lock:Ji,unlock:ta,chevron:zi,"text-left":Rn,"text-center":na,"text-right":ra,"text-justify":oa,"text-top":Ii,"text-middle":Ni,"text-bottom":Ri,unlink:pl,rotate:il,opacity:Vi,radius:dl,blend:Fi,plus:al,minus:Zi,close:hl,"chevron-down":Hi,check:Bi,link:Yi,"font-size":Ei,"line-height":tl,"letter-spacing":el,eyedropper:nl,document:ji,play:ol};function He(e){return`<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">${cg[e].map(([r,n])=>{let o=Object.entries(n).filter(([a])=>a!=="key").map(([a,i])=>` ${a}="${String(i)}"`).join("");return`<${r}${o} vector-effect="non-scaling-stroke"/>`}).join("")}</svg>`}var ml="clipboard";function Fn(e,t){let r=new Set(t),n=[];return se(e.root,o=>{if(o.id!==e.root.id&&r.has(o.id))return n.push(o),!1}),n}function qu(e,t){let r={};for(let a of e)se(a,i=>{for(let[l,d]of Object.entries(i)){if(me(d)){let c=ot(d.expr);if(!c.ok)continue;for(let h of nr(c.ast).tokens){let x=t[h];x!==void 0&&(r[h]=x)}continue}typeof d=="string"&&o(d),l==="shadow"&&typeof d=="string"&&n(d)}for(let l of ju(i.content))o(l)});return r;function n(a){let i=t[a],d=Tr(typeof i=="string"?i:a);if(!("error"in d))for(let c of d.shadows)o(c.colour)}function o(a){for(let i of Lo(a)){let l=t[i];if(l!==void 0&&(r[i]=l,!(typeof l!="string"||l===a)))for(let d of Lo(l)){let c=t[d];c!==void 0&&d!==i&&(r[d]=c)}}}}function pg(e,t){let r={};for(let n of e)se(n,o=>{if(o.type!=="image"||typeof o.src!="string")return;let a=t[o.src];a!==void 0&&(r[o.src]=a)});return r}function Ku(e,t){let r={},n=o=>{if(typeof o!="string")return;let a=t[o];a!==void 0&&(r[o]=a)};for(let o of e)se(o,a=>{let i=a;n(i.font);for(let l of ju(i.content,"font"))n(l)});return r}function ju(e,t="fill"){if(!Array.isArray(e))return[];let r=[];for(let n of e){if(typeof n=="string")continue;let o=n[t];o!==void 0&&r.push(o)}return r}function xl(e,t,r){let n=Fn(e,t);if(n.length===0)return null;let o={};for(let l of n)se(l,d=>{let c=r.nodes.get(d.id)?.values;c&&Object.keys(c).length>0&&(o[d.id]=c)});let a={version:e.version,kind:e.kind,tokens:qu(n,e.tokens),fonts:Ku(n,e.fonts),assets:pg(n,e.assets),root:{...e.root,children:n}},i=JSON.parse(is(a));return i[ml]={resolved:o},JSON.stringify(i,null,2)}function gl(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!="object"||t===null)return null;let r=t;if(typeof r.root!="object"||r.root===null)return null;let{document:n}=Is(t),o=n.root.children;if(o.length===0)return null;let a=r[ml],i=typeof a=="object"&&a!==null?a.resolved??{}:{};return{nodes:o,tokens:n.tokens,fonts:n.fonts,resolved:typeof i=="object"&&i!==null?i:{}}}function yl(e,t){let r=go(t.root),n=new Map;for(let i of e.nodes)se(i,l=>{let d=hg(l.id,r);r.add(d),n.set(l.id,d)});let o=i=>r.has(i),a={...e.tokens,...t.tokens};return{nodes:e.nodes.map(i=>Gu(i,{payload:e,remap:n,exists:o,tokens:a})),remap:n}}function hg(e,t){let r=e.lastIndexOf("."),n=r===-1?"":e.slice(r+1),o=/^[0-9]+$/.test(n)?e.slice(0,r):e,a=1;for(let i of t){if(!i.startsWith(`${o}.`))continue;let l=Number(i.slice(o.length+1));Number.isInteger(l)&&l>=a&&(a=l+1)}return`${o}.${a}`}function Gu(e,t){let r=e,n={};for(let[o,a]of Object.entries(r))o==="id"||o==="children"||(n[o]=me(a)?mg(a.expr,e.id,o,t):a);return n.id=t.remap.get(e.id)??e.id,pe(e)&&(n.children=ae(e).map(o=>Gu(o,t))),n}function mg(e,t,r,n){let o={expr:e},a=ot(e);if(!a.ok)return o;let i=nr(a.ast).nodes.some(h=>n.remap.has(h)),l=i?Dt(a.ast,h=>n.remap.get(h)):a.ast,d=nr(l);if(d.nodes.some(h=>!n.exists(h))||d.tokens.some(h=>n.tokens[h]===void 0)){let h=n.payload.resolved[t]?.[r];return h===void 0?o:h}return i?{expr:_n(l)}:o}var bt="#ffffff",Nt="#0b0d0c",Zu="#c6ff3d",xg="#ffb224";var Wu=new Map;function Te(e,t={}){let r=t.badge??"none",n=e==="resize"?Qu(t.angle??0):e==="rotate"?yg(t.angle??0):0,o=`${e}:${n}:${r}`,a=Wu.get(o);if(a!==void 0)return a;let{at:i,fallback:l}=gg[e],d=wg(vg(e,n,r),i[0],i[1],l);return Wu.set(o,d),d}var Xu=[2,2],Ir=[12,12],gg={arrow:{at:Xu,fallback:"default"},radius:{at:Xu,fallback:"default"},resize:{at:Ir,fallback:"ew-resize"},rotate:{at:Ir,fallback:"crosshair"},crosshair:{at:Ir,fallback:"crosshair"},grab:{at:Ir,fallback:"grab"},grabbing:{at:Ir,fallback:"grabbing"},text:{at:Ir,fallback:"text"}};function yg(e){let t=(e%360+360)%360;return Math.round(t/15)*15%360}function Qu(e){let t=(e%180+180)%180;return Math.round(t/15)*15%180}function vg(e,t,r){switch(e){case"arrow":return ec(r);case"resize":return kg(t,r);case"rotate":return Sg(t);case"crosshair":return Cg();case"grab":return Ju(!1);case"grabbing":return Ju(!0);case"radius":return Eg(r);case"text":return _g()}}function bg(e){return`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">${e}</svg>`}function wg(e,t,r,n){return`url("data:image/svg+xml,${encodeURIComponent(bg(e))}") ${t} ${r}, ${n}`}var Yu="M2 2 L2 20.4 L6.7 15.9 L9.9 22.8 L12.6 21.5 L9.5 14.8 L15.4 14.6 Z";function ec(e){return`<path d="${Yu}" fill="${bt}" stroke="${bt}" stroke-width="3" stroke-linejoin="round"/><path d="${Yu}" fill="${Nt}"/>`+tc(e)}function kg(e,t){let r=["M6.6 12 H17.4","M9.7 8.7 L6.2 12 L9.7 15.3","M14.3 8.7 L17.8 12 L14.3 15.3"],n=(o,a)=>r.map(i=>`<path d="${i}" stroke="${a}" stroke-width="${o}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+n(3.6,bt)+n(1.6,Nt)+"</g>"+tc(t)}function Sg(e){let t=["M7 17.5 A10 10 0 0 0 17.5 7","M14.2 4.6 L17.6 7 L15 10.3","M4.6 14.2 L7 17.6 L10.3 15"],r=(n,o)=>t.map(a=>`<path d="${a}" stroke="${o}" stroke-width="${n}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+r(3.6,bt)+r(1.6,Nt)+"</g>"}function _g(){let e=["M12 4.5 V19.5","M9 4.5 H15","M9 19.5 H15"],t=(r,n)=>e.map(o=>`<path d="${o}" stroke="${n}" stroke-width="${r}"/>`).join("");return'<g fill="none" stroke-linecap="round">'+t(3.4,bt)+t(1.5,Nt)+"</g>"}function Cg(){let e="M12 2.5 V9 M12 15 V21.5 M2.5 12 H9 M15 12 H21.5";return`<g fill="none" stroke-linecap="round"><path d="${e}" stroke="${bt}" stroke-width="3"/><path d="${e}" stroke="${Nt}" stroke-width="1.2"/></g>`}function Ju(e){let t=e?"M6.8 13.8v-1.3a1.35 1.35 0 0 1 1.35-1.35h7.7a1.35 1.35 0 0 1 1.35 1.35v2.6c0 3.2-2.2 5.2-5.1 5.2h-1.1c-1.9 0-3-.8-3.9-2.1l-1.4-2":"M9 14.6V6.4a1.25 1.25 0 0 1 2.5 0v5.1V5.1a1.25 1.25 0 0 1 2.5 0v6.4V6.2a1.25 1.25 0 0 1 2.5 0v6.6m0 0v2.3c0 3.1-2.1 5-4.8 5h-.7c-1.6 0-2.7-.6-3.6-1.9l-2.2-3a1.3 1.3 0 0 1 .45-1.85c.6-.35 1.35-.2 1.85.4L9 15.9";return`<g fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="${t}" stroke="${bt}" stroke-width="3.4"/><path d="${t}" stroke="${Nt}" stroke-width="1.5"/></g>`}function Eg(e){return ec("none")+Mg(e)}function Mg(e){return`<g><rect x="17.5" y="17.5" width="14" height="14" rx="4.5" fill="${bt}"/><rect x="18.7" y="18.7" width="11.6" height="11.6" rx="3.4" fill="${e==="none"?Zu:xg}"/><path d="M21.6 27.9 V25.4 A3.8 3.8 0 0 1 25.4 21.6 H27.9" fill="none" stroke="${Nt}" stroke-width="1.5" stroke-linecap="round"/></g>`}function tc(e){return e==="none"?"":`<g><rect x="18.5" y="18.5" width="13" height="13" rx="4" fill="${bt}"/><rect x="19.6" y="19.6" width="10.8" height="10.8" rx="3" fill="${Zu}"/><text x="25" y="28.4" text-anchor="middle" fill="${Nt}" font-family="ui-sans-serif, system-ui, -apple-system, Helvetica, sans-serif" font-size="10" font-weight="700">${e==="token"?"$":"\u0192"}</text></g>`}function Fe(e,t){let r=[],n=o=>{if(r.push(o.id),o.id===t)return!0;for(let a of ae(o))if(n(a))return!0;return r.pop(),!1};return n(e)?r:[]}function aa(e,t,r){let n=Fe(t.root,e);if(n.length===0)return e;let o=r!==null&&n.includes(r)?r:Ag(n,t),a=n.indexOf(o);return a===-1?e:n[a+1]??e}function Ag(e,t){for(let r=e.length-2;r>=0;r-=1){let n=e[r];if(q(t.root,n)?.type==="frame")return n}return t.root.id}function rc(e,t){let r=e.map(o=>Fe(t.root,o)).filter(o=>o.length>0);if(r.length===0)return t.root.id;let n=t.root.id;for(let o=0;;o+=1){let a=r[0]?.[o];if(a===void 0||r.some(i=>i[o]!==a||o===i.length-1))break;n=a}return n}function sr(e,t){let r=q(t.root,e);if(!r)return[];let n=[],o=a=>{if(_e(a)){for(let i of ae(a))o(i);return}n.push(a.id)};return o(r),n}function ir(e,t,r){let n=q(t.root,e);if(!n)return;if(!_e(n)){let i=r.nodes.get(e);return i?Bn(i):void 0}let o=[],a=i=>{if(!(i.id!==e&&"hidden"in i&&i.hidden===!0)){if(i.id!==e&&!_e(i)){let l=ir(i.id,t,r);l&&o.push(l);return}for(let l of ae(i))a(l)}};return a(n),at(o)??void 0}function Bn(e){let t={x:e.absX,y:e.absY,w:e.w,h:e.h},r=e.values.rotation??0;return r===0?t:wn(t,r)}function Hn(e,t,r){return t.flatMap(n=>{let o=ir(n,e,r);return o?[{id:n,frame:o}]:[]})}function vl(e,t){let r=t.filter(x=>x!==e.root.id&&q(e.root,x));if(r.length<2)return null;let n=rc(r,e),o=q(e.root,n);if(!o)return null;let a=ae(o),i=new Set(r.map(x=>aa(x,e,n))),l=a.filter(x=>i.has(x.id));if(l.length<2)return null;let d=a.findIndex(x=>x.id===l[l.length-1]?.id),c=Lt(e.root,"group"),h=[{op:"insert",parent:n,index:d+1,node:es({id:c,children:[]})}];return l.forEach((x,y)=>{h.push({op:"move",id:x.id,parent:c,index:y})}),{ops:h,groupId:c}}function bl(e,t){let r=q(e.root,t);if(!r||!_e(r))return[];let n=Fe(e.root,t),o=n[n.length-2];if(o===void 0)return[];let a=q(e.root,o);if(!a)return[];let i=ae(a).findIndex(d=>d.id===t);if(i===-1)return[];let l=ae(r).map((d,c)=>({op:"move",id:d.id,parent:o,index:i+c}));return l.push({op:"remove",id:t}),l}function wl(e,t,r){let n=new Map;for(let a of t){let i=Fe(e.root,a),l=i[i.length-2];if(l===void 0)continue;let d=n.get(l)??new Set;d.add(a),n.set(l,d)}let o=[];for(let[a,i]of n){let l=q(e.root,a);if(!l)continue;let d=ae(l).map(c=>c.id);o.push(...Tg(a,d,$g(d,i,r)))}return o}function $g(e,t,r){if(r==="front"||r==="back"){let i=e.filter(d=>t.has(d)),l=e.filter(d=>!t.has(d));return r==="front"?[...l,...i]:[...i,...l]}let n=r==="forward"?1:-1,o=[...e],a=o.flatMap((i,l)=>t.has(i)?[l]:[]);n===1&&a.reverse();for(let i of a){let l=i+n,d=o[l];d===void 0||t.has(d)||(o[l]=o[i],o[i]=d)}return o}function Tg(e,t,r){let n=[...t],o=[];for(let a=0;a<r.length;a+=1){let i=r[a];i===void 0||n[a]===i||(n.splice(n.indexOf(i),1),n.splice(a,0,i),o.push({op:"move",id:i,parent:e,index:a}))}return o}function kl(e,t,r){let n=t.w===0?1:r.w/t.w,o=t.h===0?1:r.h/t.h,a=new Map;for(let[i,l]of e)a.set(i,{x:r.x+(l.x-t.x)*n,y:r.y+(l.y-t.y)*o,w:l.w*n,h:l.h*o});return a}var Sl=6,wt=.01,We={dx:0,dy:0,guides:[],measures:[]},sa=["lo","mid","hi"];function _l(e,t,r){let n=[],o=(a,i)=>{let l=t.nodes.get(a);l&&n.push({id:a,frame:Bn(l),isPage:i})};return e.root.w!==void 0&&e.root.h!==void 0&&o(e.root.id,!0),se(e.root,a=>{if(r.has(a.id)||"hidden"in a&&a.hidden===!0)return!1;if(a.id!==e.root.id){if(a.type==="frame"){o(a.id,!0);return}pe(a)||o(a.id,!1)}}),n}function Cl(e,t,r){if(r<=0||t.length===0)return We;let n=Fr("x",e,t,r,sa,!0),o=Fr("y",e,t,r,sa,!0);return Ml(e,t,n,o)}function ia(e,t,r,n){if(n<=0||r.length===0)return We;let o=t.includes("w")?["lo"]:t.includes("e")?["hi"]:[],a=t.includes("n")?["lo"]:t.includes("s")?["hi"]:[],i=Fr("x",e,r,n,o,!1),l=Fr("y",e,r,n,a,!1);return Ml(e,r,i,l)}function El(e,t,r){let n={x:e.x,y:e.y,w:0,h:0};if(r<=0||t.length===0)return We;let o=Fr("x",n,t,r,["lo"],!1),a=Fr("y",n,t,r,["lo"],!1);return Ml(n,t,o,a)}function Fr(e,t,r,n,o,a){let i={axis:e,delta:0,kind:"none"};if(o.length===0)return i;let l=Lg(e,t,r,n,o),d=a?Dg(e,t,r,n):null;return l&&d?Math.abs(d.delta)<Math.abs(l.delta)-wt?{axis:e,delta:d.delta,kind:"space",gap:d.gap}:{axis:e,delta:l.delta,kind:"align",at:l.at}:l?{axis:e,delta:l.delta,kind:"align",at:l.at}:d?{axis:e,delta:d.delta,kind:"space",gap:d.gap}:i}function Lg(e,t,r,n,o){let a=null;for(let i of r)for(let l of sa){let d=ue(i.frame,e,l);for(let c of o){let h=d-ue(t,e,c);if(Math.abs(h)>n)continue;let x=c==="mid"&&l==="mid";(a===null||Og(h,x,a))&&(a={at:d,delta:h,centred:x})}}return a?{at:a.at,delta:a.delta}:null}function Og(e,t,r){let n=Math.abs(e),o=Math.abs(r.delta);return n<o-wt?!0:n>o+wt?!1:t&&!r.centred}function Dg(e,t,r,n){let o=nc(e,t,r);if(o.length<2)return null;let a=oc(t,e),i=ue(t,e,"lo"),l=[];for(let c of Pg(o,e))for(let h of o)l.push({delta:ue(h,e,"hi")+c-i,gap:c}),l.push({delta:ue(h,e,"lo")-c-a-i,gap:c});for(let c=0;c+1<o.length;c+=1){let h=o[c],x=o[c+1];if(!h||!x)continue;let y=ue(x,e,"lo")-ue(h,e,"hi")-a;y<=wt||l.push({delta:ue(h,e,"hi")+y/2-i,gap:y/2})}let d=null;for(let c of l)Math.abs(c.delta)>n||(d===null||Math.abs(c.delta)<Math.abs(d.delta)-wt)&&(d=c);return d}function nc(e,t,r){let n=Al(e);return r.filter(o=>!o.isPage&&Ig(o.frame,t,n)).map(o=>o.frame).sort((o,a)=>ue(o,e,"lo")-ue(a,e,"lo"))}function Pg(e,t){let r=[];for(let n=0;n+1<e.length;n+=1){let o=e[n],a=e[n+1];if(!o||!a)continue;let i=ue(a,t,"lo")-ue(o,t,"hi");i<=wt||r.some(l=>Math.abs(l-i)<wt)||r.push(i)}return r}function Ml(e,t,r,n){let o={...e,x:e.x+r.delta,y:e.y+n.delta},a=[],i=[];for(let l of[r,n]){if(l.kind==="align"&&l.at!==void 0){let d=Ng(l.axis,l.at,o,t);d&&a.push(d)}l.kind==="space"&&l.gap!==void 0&&i.push(...Rg(l.axis,l.gap,o,t))}return{dx:r.delta,dy:n.delta,guides:a,measures:i}}function Ng(e,t,r,n){let o=Al(e),a=ue(r,o,"lo"),i=ue(r,o,"hi"),l=!1;for(let d of n)sa.some(c=>Fg(ue(d.frame,e,c),t))&&(l=!0,a=Math.min(a,ue(d.frame,o,"lo")),i=Math.max(i,ue(d.frame,o,"hi")));return l?{axis:e,at:t,from:a,to:i}:null}function Rg(e,t,r,n){let o=Al(e),a=[...nc(e,r,n),r].sort((l,d)=>ue(l,e,"lo")-ue(d,e,"lo")),i=[];for(let l=0;l+1<a.length;l+=1){let d=a[l],c=a[l+1];if(!d||!c)continue;let h=ue(c,e,"lo")-ue(d,e,"hi");if(Math.abs(h-t)>wt)continue;let x=Math.max(ue(d,o,"lo"),ue(c,o,"lo")),y=Math.min(ue(d,o,"hi"),ue(c,o,"hi"));i.push({axis:e,at:(x+y)/2,from:ue(d,e,"hi"),to:ue(c,e,"lo"),label:Bg(h)})}return i}function Al(e){return e==="x"?"y":"x"}function oc(e,t){return t==="x"?e.w:e.h}function ue(e,t,r){let n=t==="x"?e.x:e.y,o=oc(e,t);return r==="lo"?n:r==="hi"?n+o:n+o/2}function Ig(e,t,r){return ue(e,r,"lo")<ue(t,r,"hi")&&ue(e,r,"hi")>ue(t,r,"lo")}function Fg(e,t){return Math.abs(e-t)<wt}function Bg(e){return String(Math.round(e*100)/100)}var zn=class{limit;past=[];future=[];constructor(t=500){this.limit=t}push(t){this.past.push(t),this.past.length>this.limit&&this.past.shift(),this.future.length=0}amend(t){let r=this.past[this.past.length-1];return r?(this.past[this.past.length-1]={label:t.label,ops:[...r.ops,...t.ops],inverse:[...t.inverse,...r.inverse]},this.future.length=0,!0):!1}get canUndo(){return this.past.length>0}get top(){return this.past[this.past.length-1]??null}isTail(t){if(t.length===0||t.length>this.past.length)return!1;let r=this.past.length-t.length;return t.every((n,o)=>this.past[r+o]===n)}get canRedo(){return this.future.length>0}undo(){let t=this.past.pop();if(t)return this.future.push(t),{entry:t,ops:t.inverse}}redo(){let t=this.future.pop();if(t)return this.past.push(t),{entry:t,ops:t.ops}}snapshot(){return{past:[...this.past],future:[...this.future]}}restore(t){this.past.length=0,this.future.length=0,this.past.push(...t.past),this.future.push(...t.future)}clear(){this.past.length=0,this.future.length=0}};var ac=1,Hg=48,zg=.06,Ug=.5;function sc(e){return Math.max(Hg,Math.min(e.width,e.height)*zg)}function $l(e,t){let r=new Set(t),n=[];for(let o of e.root.children)(r.has(o.id)||ic(o,r))&&n.push(o.id);return n}function ic(e,t){for(let r of ae(e))if(t.has(r.id)||ic(r,t))return!0;return!1}function la(e){let t=e.filter(i=>i.w>0&&i.h>0);if(t.length===0)return null;let r=Math.min(...t.map(i=>i.x)),n=Math.min(...t.map(i=>i.y)),o=Math.max(...t.map(i=>i.x+i.w)),a=Math.max(...t.map(i=>i.y+i.h));return{x:r,y:n,w:o-r,h:a-n}}function da(e,t){let r=sc(t),n={width:Math.max(1,t.width-r*2),height:Math.max(1,t.height-r*2)},o=Pr(Math.min(n.width/e.w,n.height/e.h,ac));return{zoom:o,x:t.width/2-(e.x+e.w/2)*o,y:t.height/2-(e.y+e.h/2)*o}}function Tl(e,t,r){let n=da(e,t);return Vg(e,t,r)&&r.zoom>=n.zoom*Ug?null:n}function Vg(e,t,r){let n=e.x*r.zoom+r.x,o=e.y*r.zoom+r.y,a=(e.x+e.w)*r.zoom+r.x,i=(e.y+e.h)*r.zoom+r.y;return n>=0&&o>=0&&a<=t.width&&i<=t.height}function lc(e,t,r,n){let o=Math.exp(Math.log(e.zoom)+(Math.log(t.zoom)-Math.log(e.zoom))*r),a={x:n.width/2,y:n.height/2},i={x:(a.x-e.x)/e.zoom,y:(a.y-e.y)/e.zoom},l={x:(a.x-t.x)/t.zoom,y:(a.y-t.y)/t.zoom},d={x:i.x+(l.x-i.x)*r,y:i.y+(l.y-i.y)*r};return{zoom:o,x:a.x-d.x*o,y:a.y-d.y*o}}function dc(e){return 1-(1-e)**3}function qg(e){return!("separator"in e)}function Ll(e,t=[]){let r=t.length>0?[{separator:!0},...t]:[];if(e.count===0)return[{id:"paste",label:"Paste",keys:"CmdOrCtrl+V",disabled:!e.canPaste},{separator:!0},{id:"selectAll",label:"Select all",keys:"CmdOrCtrl+A"},...fc(e),{separator:!0},{id:"fit",label:"Fit to screen",keys:"Shift+1"},{id:"zoom100",label:"Zoom to 100%",keys:"CmdOrCtrl+0"},...r];let n=[];e.isText&&e.count===1&&n.push({id:"editText",label:"Edit text",keys:"Enter"},{separator:!0}),e.isVector&&e.count===1&&n.push({id:"editPoints",label:"Edit points",keys:"Enter"},{separator:!0}),(e.convertible??0)>0&&n.push({id:"toVector",label:"Convert to vector",keys:"CmdOrCtrl+Shift+O"},{separator:!0}),n.push({id:"cut",label:"Cut",keys:"CmdOrCtrl+X"},{id:"copy",label:"Copy",keys:"CmdOrCtrl+C"},{id:"paste",label:"Paste",keys:"CmdOrCtrl+V",disabled:!e.canPaste},{id:"duplicate",label:"Duplicate",keys:"CmdOrCtrl+D"},{separator:!0},{id:"group",label:"Group",keys:"CmdOrCtrl+G",disabled:e.count<2},{id:"ungroup",label:"Ungroup",keys:"CmdOrCtrl+Shift+G",disabled:!e.hasGroup});let o=[];if(e.hide&&o.push({id:"toggleHidden",label:e.hide==="show"?"Show":"Hide",keys:"CmdOrCtrl+Shift+H"}),e.lock&&o.push({id:"toggleLock",label:e.lock==="unlock"?"Unlock":"Lock",keys:"CmdOrCtrl+Shift+L"}),o.length>0&&n.push({separator:!0},...o),n.push({separator:!0},{id:"front",label:"Bring to front",keys:"CmdOrCtrl+]"},{id:"forward",label:"Bring forward",keys:"]"},{id:"backward",label:"Send backward",keys:"["},{id:"back",label:"Send to back",keys:"CmdOrCtrl+["}),e.bound.length>0){n.push({separator:!0});for(let a of e.bound)n.push({id:`detach:${a.prop}`,label:`Detach ${a.prop}`,hint:a.source})}return n.push(...fc(e)),n.push(...r),n.push({separator:!0},{id:"delete",label:"Delete",keys:"Delete"}),n}var Kg=4;function fc(e){let t=(e.locksHere??[]).slice(0,Kg).map(n=>({id:`unlock:${n}`,label:`Unlock ${n}`}));e.anyLocked&&t.push({id:"unlockAll",label:"Unlock all"});let r=e.hiddenCount??0;return r>0&&t.push({id:"showAll",label:`Show all hidden (${r})`}),t.length===0?[]:[{separator:!0},...t]}function fa(e,t){let r=e.ownerDocument,n=t.formatKeys??In,o=r.createElement("div");o.className="vd-menu",o.setAttribute("role","menu"),o.hidden=!0,e.appendChild(o);let a=!1,i=[],l=-1;function d(S){o.replaceChildren(),i=[];for(let B of S){if(!qg(B)){let P=r.createElement("div");P.className="vd-menu__separator",o.appendChild(P);continue}let N=r.createElement("button");N.type="button",N.className="vd-menu__item",N.dataset.command=B.id,N.disabled=B.disabled===!0,N.setAttribute("role","menuitem");let J=r.createElement("span");J.textContent=B.label,N.appendChild(J);let E=B.hint??(B.keys===void 0?void 0:n(B.keys));if(E!==void 0){let P=r.createElement("span");P.className="vd-menu__hint",P.textContent=E,N.appendChild(P)}o.appendChild(N),N.disabled||i.push(N)}}function c(S){o.style.left=`${S.x}px`,o.style.top=`${S.y}px`;let B=e.getBoundingClientRect(),N=t.bounds?.()??B,J=o.getBoundingClientRect();if(J.width===0&&J.height===0)return;let E=B.left+S.x+J.width-N.right,P=B.top+S.y+J.height-N.bottom;E>0&&(o.style.left=`${Math.max(N.left-B.left,S.x-J.width)}px`),P>0&&(o.style.top=`${Math.max(N.top-B.top,S.y-J.height)}px`)}function h(S){i.length!==0&&(l=(S+i.length)%i.length,i[l]?.focus())}let x=S=>{let B=S.target?.closest("button");if(!B||B.disabled)return;S.stopPropagation();let N=B.dataset.command;k(),N&&t.onCommand(N)},y=S=>S.stopPropagation(),v=S=>{S.key==="ArrowDown"?(S.preventDefault(),h(l+1)):S.key==="ArrowUp"?(S.preventDefault(),h(l-1)):S.key==="Escape"&&(S.preventDefault(),S.stopPropagation(),k(),t.returnFocus?t.returnFocus():e.focus())},D=S=>{a&&(S.target instanceof Node&&o.contains(S.target)||k())};function k(){a&&(a=!1,l=-1,o.hidden=!0,r.removeEventListener("pointerdown",D,!0),r.removeEventListener("wheel",D,!0))}return o.addEventListener("click",x),o.addEventListener("pointerdown",y),o.addEventListener("keydown",v),{element:o,get isOpen(){return a},open(S,B){d(B),o.hidden=!1,a=!0,c(S),r.addEventListener("pointerdown",D,!0),r.addEventListener("wheel",D,!0),h(0)},close:k,destroy(){k(),o.removeEventListener("click",x),o.removeEventListener("pointerdown",y),o.removeEventListener("keydown",v),o.remove()}}}var Br=2,uc=1.5,cc=1.5,pc=1.5,kc={hover:null,members:[],box:null,spacers:[],rings:[],lead:null,badge:null,caret:null,textSelection:[],draft:null,marquee:null,guides:[],measures:[],presence:null,highlight:[],parked:[],lockHint:null},hc=3.6,jg=22,ua=14,ca=15,Ol=4,mc=15,xc=23,Un=7,Gg=3.5,pa=12,Wg=4.5,ha=16,Xe=18,Dl=9,Pl=6.1,gc="Drop or double-click",Xg=6.4,yc=16,Rt=3,vc=5,Yg=11,bc=6,wc=6.4;function Sc(e,t){let r=e.ownerDocument,n=r.createElementNS(ie,"svg");n.setAttribute("class","vd-editor__overlay"),e.appendChild(n);let o=[],a=[],i=[],l=[],d=[],c=null,h=null,x=[],y=[];function v(w){let $=t({x:w.x,y:w.y}),M=t({x:w.x+w.w,y:w.y+w.h});return{x:$.x,y:$.y,w:M.x-$.x,h:M.y-$.y}}function D(w){for(;n.firstChild;)n.removeChild(n.firstChild);o=[],a=[],i=[],l=[],d=[],c=null,h=null,x=[],y=(w.pageLabels??[]).flatMap(M=>ye(M));let $=w.turn&&w.turn.angle!==0?{angle:w.turn.angle,centre:t(w.turn.centre)}:null;for(let M of w.slots??[])ke(M);w.presence&&Se(w.presence);for(let M of w.highlight)A("vd-editor__highlight",Hr(v(M),Br),Br);w.lockHint&&xe(w.lockHint),w.hover&&A("vd-editor__hover",Vn(v(w.hover)),cc);for(let M of w.parked)A("vd-editor__parked",Vn(v(M)),cc);for(let M of w.members)A("vd-editor__member",Hr(v(M),uc),uc);w.lead&&A("vd-editor__lead",Vn(v(w.lead)),Br);for(let M of w.guides)C(M);for(let M of w.measures)G(M);if(k($,()=>{for(let M of w.textSelection)n.appendChild(te("vd-editor__text-selection",v(M)))}),w.box&&P(w.box),w.caret&&k($,()=>N(w.caret)),l=w.rings.map(J),i=w.spacers.map(E),w.badge&&w.box){let M=v(w.box.frame),T=c?Math.max(...[{x:M.x,y:M.y},{x:M.x+M.w,y:M.y},{x:M.x,y:M.y+M.h},{x:M.x+M.w,y:M.y+M.h}].map(H=>Be(H,c.centre,c.angle).y)):M.y+M.h;de(w.badge,{x:M.x+M.w/2,y:T+Dl+Xe/2})}if(w.draft){let M=v(w.draft);if(w.draftEllipse){let T=r.createElementNS(ie,"ellipse");T.setAttribute("class","vd-editor__draft"),T.setAttribute("cx",String(M.x+M.w/2)),T.setAttribute("cy",String(M.y+M.h/2)),T.setAttribute("rx",String(Math.abs(M.w)/2)),T.setAttribute("ry",String(Math.abs(M.h)/2)),n.appendChild(T)}else n.appendChild(te("vd-editor__draft",M))}w.marquee&&n.appendChild(te("vd-editor__marquee",v(w.marquee))),w.path&&(h=$,k($,()=>B(w.path)))}function k(w,$){if(!w){$();return}let M=n.childNodes.length;$();let T=r.createElementNS(ie,"g");for(T.setAttribute("transform",`rotate(${w.angle} ${w.centre.x} ${w.centre.y})`);n.childNodes.length>M;)T.insertBefore(n.childNodes[n.childNodes.length-1],T.firstChild);n.appendChild(T)}function S(w,$){return $?Be(w,$.centre,-$.angle):w}function B(w){let $=r.createElementNS(ie,"path");if($.setAttribute("class","vd-editor__path"),$.setAttribute("d",mt(xt(w.contours,t))),n.appendChild($),w.pending){let T=t(w.pending.from),H=t(w.pending.to),j=w.pending.c1?t(w.pending.c1):T,F=r.createElementNS(ie,"path");F.setAttribute("class","vd-editor__pending"),F.setAttribute("d",`M${T.x} ${T.y} C${j.x} ${j.y} ${H.x} ${H.y} ${H.x} ${H.y}`),n.appendChild(F)}for(let T of w.handles){let H=t(T.at),j=t(T.anchor),F=r.createElementNS(ie,"line");F.setAttribute("class","vd-editor__arm"),F.setAttribute("x1",String(j.x)),F.setAttribute("y1",String(j.y)),F.setAttribute("x2",String(H.x)),F.setAttribute("y2",String(H.y)),n.appendChild(F)}for(let T of w.handles){let H=t(T.at),j=r.createElementNS(ie,"circle");j.setAttribute("class","vd-editor__knob"),j.setAttribute("cx",String(H.x)),j.setAttribute("cy",String(H.y)),j.setAttribute("r",String(Gg)),n.appendChild(j)}for(let T of w.anchors){let H=t(T.at),j=te(T.selected?"vd-editor__anchor vd-editor__anchor--on":"vd-editor__anchor",{x:Math.round(H.x-Un/2)+.5,y:Math.round(H.y-Un/2)+.5,w:Un,h:Un});j.setAttribute("data-key",T.key),n.appendChild(j)}if(w.closeAt){let T=t(w.closeAt),H=r.createElementNS(ie,"circle");H.setAttribute("class","vd-editor__close"),H.setAttribute("cx",String(T.x)),H.setAttribute("cy",String(T.y)),H.setAttribute("r",String(Un)),n.appendChild(H)}let M=T=>({x:T.x-pa/2,y:T.y-pa/2,w:pa,h:pa});d=[...[...w.handles].reverse().map(T=>({kind:"handle",key:T.key,rect:M(t(T.at))})),...[...w.anchors].reverse().map(T=>({kind:"anchor",key:T.key,rect:M(t(T.at))}))]}function N(w){let $=t({x:w.x,y:w.y}),M=t({x:w.x,y:w.y+w.h}),T=r.createElementNS(ie,"line");T.setAttribute("class","vd-editor__caret");let H=Math.round($.x)+.5;T.setAttribute("x1",String(H)),T.setAttribute("y1",String($.y)),T.setAttribute("x2",String(H)),T.setAttribute("y2",String(M.y)),w.fill!==void 0&&!w.fill.startsWith("url(")&&(T.style.stroke=w.fill),n.appendChild(T)}function J(w){let $=t(w.at),M=r.createElementNS(ie,"circle");return M.setAttribute("class","vd-editor__ring"),M.setAttribute("cx",String($.x)),M.setAttribute("cy",String($.y)),M.setAttribute("r",String(Wg)),n.appendChild(M),{id:w.id,rect:{x:$.x-ha/2,y:$.y-ha/2,w:ha,h:ha}}}function E(w){let $=t(w.at),M=w.axis==="x"?Ol:ca,T=w.axis==="x"?ca:Ol,H=te("vd-editor__spacer",{x:$.x-M/2,y:$.y-T/2,w:M,h:T});H.setAttribute("rx",String(Ol/2)),n.appendChild(H),w.label!==null&&de(w.label,w.axis==="x"?{x:$.x,y:$.y-ca/2-Dl-Xe/2}:{x:$.x+ca/2+Dl+Xe,y:$.y});let j=w.axis==="x"?mc:xc,F=w.axis==="x"?xc:mc;return{id:w.id,rect:{x:$.x-j/2,y:$.y-F/2,w:j,h:F}}}function P(w){let $=v(w.frame),M=w.rotation??0;c=M===0?null:{angle:M,centre:{x:$.x+$.w/2,y:$.y+$.h/2}},k(c,()=>R(w,$)),w.handles&&w.rotatable&&(x=On.map(T=>{let{u:H,v:j}=Nr(T);return{handle:T,at:{x:$.x+$.w*H,y:$.y+$.h*j}}}))}function R(w,$){if(A("vd-editor__outline",Hr($,Br),Br),!!w.handles){o=yi($).map(M=>({...M,bound:w.boundHandles.has(M.handle)}));for(let M of On){let{u:T,v:H}=Nr(M),j={x:$.x+$.w*T-Rr/2,y:$.y+$.h*H-Rr/2,w:Rr,h:Rr};n.appendChild(te("vd-editor__halo",Hr(j,pc+1))),n.appendChild(te("vd-editor__handle",j))}a=w.adjusters.map(M=>{let T=t(M.at),H=r.createElementNS(ie,"circle");H.setAttribute("class","vd-editor__halo"),H.setAttribute("cx",String(T.x)),H.setAttribute("cy",String(T.y)),H.setAttribute("r",String(hc+pc/2+.5)),n.appendChild(H);let j=r.createElementNS(ie,"circle");return j.setAttribute("class","vd-editor__adjuster"),j.setAttribute("cx",String(T.x)),j.setAttribute("cy",String(T.y)),j.setAttribute("r",String(hc)),n.appendChild(j),{id:M.id,bound:M.bound,rect:{x:T.x-ua/2,y:T.y-ua/2,w:ua,h:ua}}})}}function C(w){let $=t(w.axis==="x"?{x:w.at,y:w.from}:{x:w.from,y:w.at}),M=t(w.axis==="x"?{x:w.at,y:w.to}:{x:w.to,y:w.at}),T=r.createElementNS(ie,"line");T.setAttribute("class","vd-editor__guide"),T.setAttribute("x1",String(we($.x))),T.setAttribute("y1",String(we($.y))),T.setAttribute("x2",String(we(M.x))),T.setAttribute("y2",String(we(M.y))),n.appendChild(T)}function G(w){let $=t(w.axis==="x"?{x:w.from,y:w.at}:{x:w.at,y:w.from}),M=t(w.axis==="x"?{x:w.to,y:w.at}:{x:w.at,y:w.to}),T=r.createElementNS(ie,"path");T.setAttribute("class","vd-editor__measure"),T.setAttribute("d",w.axis==="x"?`M${we($.x)} ${we($.y)-Rt} V${we($.y)+Rt} M${we($.x)} ${we($.y)} H${we(M.x)} M${we(M.x)} ${we(M.y)-Rt} V${we(M.y)+Rt}`:`M${we($.x)-Rt} ${we($.y)} H${we($.x)+Rt} M${we($.x)} ${we($.y)} V${we(M.y)} M${we(M.x)-Rt} ${we(M.y)} H${we(M.x)+Rt}`),n.appendChild(T);let H=r.createElementNS(ie,"text");H.setAttribute("class","vd-editor__measure-text"),H.setAttribute("x",String(($.x+M.x)/2)),H.setAttribute("y",String(($.y+M.y)/2-(w.axis==="x"?vc:0))),w.axis==="y"&&H.setAttribute("dx",String(vc)),H.textContent=w.label,n.appendChild(H)}function de(w,$){let M=Math.max(34,w.length*Pl+14),T=$.x-M/2,H=$.y-Xe/2,j=te("vd-editor__badge",{x:T,y:H,w:M,h:Xe});j.setAttribute("rx",String(Xe/2)),n.appendChild(j);let F=r.createElementNS(ie,"text");F.setAttribute("class","vd-editor__badge-text"),F.setAttribute("x",String(T+M/2)),F.setAttribute("y",String(H+Xe/2)),F.textContent=w,n.appendChild(F)}function ye(w){let $=v(w.frame),M=Math.floor($.w/wc);if(M<3)return[];let T=w.label.length>M?`${w.label.slice(0,M-1)}\u2026`:w.label,H=r.createElementNS(ie,"text");H.setAttribute("class",`vd-editor__page-label vd-editor__page-label--${w.state}`),H.setAttribute("x",String($.x)),H.setAttribute("y",String($.y-bc)),H.textContent=T,n.appendChild(H);let j=Math.min($.w,T.length*wc+4),F=Yg+6;return[{id:w.id,rect:{x:$.x,y:$.y-bc-F+3,w:j,h:F}}]}function xe(w){let $=Vn(v(w.frame));n.appendChild(te("vd-editor__lock",$));let M=`${w.label} \xB7 locked`,T=M.length*Pl+14,H=$.y+4,j=te("vd-editor__lock-tag",{x:$.x+4,y:H,w:T,h:Xe});j.setAttribute("rx","4"),n.appendChild(j);let F=r.createElementNS(ie,"text");F.setAttribute("class","vd-editor__lock-text"),F.setAttribute("x",String($.x+4+T/2)),F.setAttribute("y",String(H+Xe/2)),F.textContent=M,n.appendChild(F)}function ke(w){let $=Vn(v(w.frame)),M=te(w.target?"vd-editor__slot vd-editor__slot--target":"vd-editor__slot",$);M.setAttribute("rx","3"),n.appendChild(M);let T=F=>F.length*Xg+16<=$.w,H=[];$.h>=20&&T(w.label)&&H.push([w.label,"vd-editor__slot-label"]),H.length>0&&$.h>=48&&T(gc)&&H.push([gc,"vd-editor__slot-hint"]);let j=$.y+$.h/2-(H.length-1)*yc/2;H.forEach(([F,O],X)=>{let z=r.createElementNS(ie,"text");z.setAttribute("class",O),z.setAttribute("x",String($.x+$.w/2)),z.setAttribute("y",String(j+X*yc)),z.textContent=F,n.appendChild(z)})}function Se(w){let $=w.frames.map(O=>Hr(v(O),Br));for(let O of $)n.appendChild(te("vd-editor__presence",O));let M=$[0];if(!M||!w.label)return;let T=Math.max(34,w.label.length*Pl+14),H=M.y-Xe-3<0?M.y+3:M.y-Xe-3,j=te("vd-editor__presence-tag",{x:M.x,y:H,w:T,h:Xe});j.setAttribute("rx","4"),n.appendChild(j);let F=r.createElementNS(ie,"text");F.setAttribute("class","vd-editor__presence-text"),F.setAttribute("x",String(M.x+T/2)),F.setAttribute("y",String(H+Xe/2)),F.textContent=w.label,n.appendChild(F)}function A(w,$,M){let H=w==="vd-editor__highlight"?"vd-editor__halo vd-editor__halo--highlight":w==="vd-editor__hover"||w==="vd-editor__member"?"vd-editor__halo vd-editor__halo--quiet":"vd-editor__halo";n.appendChild(te(H,Hr($,M+1))),n.appendChild(te(w,$))}function te(w,$){let M=r.createElementNS(ie,"rect");return M.setAttribute("class",w),M.setAttribute("x",String($.x)),M.setAttribute("y",String($.y)),M.setAttribute("width",String(Math.max(0,$.w))),M.setAttribute("height",String(Math.max(0,$.h))),M}return{element:n,render:D,hitHandle(w){let $=S(w,c);for(let M of o)if(st(M.rect,$.x,$.y))return{handle:M.handle,bound:M.bound};return null},hitAdjuster(w){let $=S(w,c);for(let M of a)if(st(M.rect,$.x,$.y))return{id:M.id,bound:M.bound};return null},hitSpacer(w){return Nl(i,w)},hitPath(w){let $=S(w,h),M=d.find(T=>st(T.rect,$.x,$.y));return M?{kind:M.kind,key:M.key}:null},hitRotate(w){let $=S(w,c),M=o.length===0?null:x;if(!M)return null;for(let T of M){let H=Math.hypot($.x-T.at.x,$.y-T.at.y);if(H<Rr/2+2||H>jg)continue;let{u:j,v:F}=Nr(T.handle);if(($.x-T.at.x)*(j*2-1)+($.y-T.at.y)*(F*2-1)>0)return T.handle}return null},hitRing(w){return Nl(l,w)},hitPageLabel(w){return Nl(y,w)},pageLabelRect(w){return y.find($=>$.id===w)?.rect??null},destroy(){n.remove(),o=[],a=[],i=[],l=[]}}}function Nl(e,t){for(let r of e)if(st(r.rect,t.x,t.y))return r.id;return null}function we(e){return Math.round(e)+.5}function Vn(e){return{x:e.x+.5,y:e.y+.5,w:Math.max(0,e.w-1),h:Math.max(0,e.h-1)}}function Hr(e,t){let r=t/2;return{x:e.x-r,y:e.y-r,w:e.w+t,h:e.h+t}}function _c(e,t){let r=[];return se(e.root,n=>{if(t.has(n.id))return!1;n.type!=="image"||me(n.src)||e.assets[n.src]===void 0&&r.push({id:n.id,src:n.src,label:n.name??n.src})}),r}function Il(e){if(e.length<2)return null;let t=Rl("x",e),r=Rl("y",e);return r.length===1&&t.length===e.length?Cc("x",e,t):t.length===1&&r.length===e.length?Cc("y",e,r):r.length>=2&&t.length>=2?Jg(e,t,r):null}function Rl(e,t){let r=[...t].sort((o,a)=>zr(o.frame,e)-zr(a.frame,e)),n=[];for(let o of r){let a=n[n.length-1];if(a&&zr(o.frame,e)<a.hi-.01){n[n.length-1]={lo:a.lo,hi:Math.max(a.hi,xa(o.frame,e)),from:Math.min(a.from,zr(o.frame,ma(e))),to:Math.max(a.to,xa(o.frame,ma(e))),members:[...a.members,o.id]};continue}n.push({lo:zr(o.frame,e),hi:xa(o.frame,e),from:zr(o.frame,ma(e)),to:xa(o.frame,ma(e)),members:[o.id]})}return n}function Cc(e,t,r){return{kind:"run",items:t,series:[ga(e,r)],order:r.flatMap(n=>n.members)}}function Jg(e,t,r){if(t.length*r.length!==e.length)return null;let n=[];for(let o of r)for(let a of t){let i=o.members.filter(l=>a.members.includes(l));if(i.length!==1||i[0]===void 0)return null;n.push(i[0])}return{kind:"grid",items:e,series:[ga("x",t),ga("y",r)],order:n}}function ga(e,t){let r=[];for(let n=0;n+1<t.length;n+=1){let o=t[n],a=t[n+1];!o||!a||r.push(a.lo-o.hi)}return{axis:e,tracks:t,gaps:r}}function ut(e,t){return e.series.find(r=>r.axis===t)}function Fl(e){let t=e[0];return t===void 0?!1:e.every(r=>Math.abs(r-t)<.01)}function Bl(e){let t=[];for(let r of e.series){let n=e.series.find(o=>o.axis!==r.axis);for(let o=0;o<r.gaps.length;o+=1){let a=r.tracks[o],i=r.tracks[o+1],l=r.gaps[o];if(!a||!i||l===void 0)continue;let d=(a.hi+i.lo)/2,c=n?n.tracks.map(h=>(h.lo+h.hi)/2):[(Math.max(a.from,i.from)+Math.min(a.to,i.to))/2];for(let h of c)t.push({id:Ec(r.axis,o),axis:r.axis,index:o,gap:l,at:r.axis==="x"?{x:d,y:h}:{x:h,y:d}})}}return t}function Ec(e,t){return`${e}:${t}`}function ya(e){let[t,r]=e.split(":");if(t!=="x"&&t!=="y"||r===void 0)return null;let n=Number(r);return Number.isInteger(n)&&n>=0?{axis:t,index:n}:null}function Hl(e){return e.items.map(t=>({id:t.id,at:{x:t.frame.x+t.frame.w/2,y:t.frame.y+t.frame.h/2}}))}function va(e,t,r){let n=ut(e,t);return n?ba(n,r):new Map}function ba(e,t){let r=new Map,n=e.tracks[0];if(!n)return r;let o=n.hi;for(let a=1;a<e.tracks.length;a+=1){let i=e.tracks[a];if(!i)continue;let l=o+t;for(let d of i.members)r.set(d,l-i.lo);o=l+(i.hi-i.lo)}return r}function zl(e,t){return ga(t,Rl(t,e))}function Ul(e){let t=e.tracks,r=t[0],n=t[t.length-1];if(!r||!n||t.length<3)return null;let o=t.reduce((a,i)=>a+(i.hi-i.lo),0);return(n.hi-r.lo-o)/(t.length-1)}function Vl(e,t){let r=Zg(e),n=0,o=1/0;for(let a=0;a<r.length;a+=1){let i=r[a];if(!i)continue;let l=Math.hypot(i.x-t.x,i.y-t.y);l<o&&(o=l,n=a)}return n}function Zg(e){if(e.kind==="grid"){let r=ut(e,"x")?.tracks??[];return(ut(e,"y")?.tracks??[]).flatMap(o=>r.map(a=>({x:(a.lo+a.hi)/2,y:(o.lo+o.hi)/2})))}let t=e.series[0];return t?t.tracks.map(r=>t.axis==="x"?{x:(r.lo+r.hi)/2,y:(r.from+r.to)/2}:{x:(r.from+r.to)/2,y:(r.lo+r.hi)/2}):[]}function ql(e,t,r){let n=[...e],[o]=n.splice(t,1);return o===void 0?[...e]:(n.splice(Math.max(0,Math.min(r,n.length)),0,o),n)}function Kl(e,t){let r=new Map(e.items.map(l=>[l.id,l.frame])),n=new Map;if(e.kind==="grid"){let l=ut(e,"x")?.tracks??[],d=ut(e,"y")?.tracks??[];return t.forEach((c,h)=>{let x=l[h%l.length],y=d[Math.floor(h/l.length)];x&&y&&n.set(c,{x:x.lo,y:y.lo})}),n}let o=e.series[0],a=o?.tracks[0];if(!o||!a)return n;let i=a.lo;return t.forEach((l,d)=>{let c=r.get(l);if(!c)return;let h=o.axis==="x"?c.w:c.h;n.set(l,o.axis==="x"?{x:i,y:c.y}:{x:c.x,y:i}),i+=h+(o.gaps[d]??0)}),n}function jl(e,t,r){let n=new Map,o=e.items.find(d=>d.id===t),a=e.items.find(d=>d.id===r);if(!o||!a||t===r)return n;let i=e.kind==="grid"?["x","y"]:[e.series[0]?.axis??"x"],l=(d,c)=>({x:i.includes("x")?c.frame.x:d.frame.x,y:i.includes("y")?c.frame.y:d.frame.y});return n.set(t,l(o,a)),n.set(r,l(a,o)),n}function ma(e){return e==="x"?"y":"x"}function zr(e,t){return t==="x"?e.x:e.y}function xa(e,t){return t==="x"?e.x+e.w:e.y+e.h}var Mc="vd-editor-styles",Ac=`
137
138
  .vd-editor {
138
139
  position: relative;
139
140
  width: 100%;
@@ -761,6 +762,8 @@ ${Zt}`);return t===-1?-1:t+1}function sm(e){let t=new Set;for(let r of e.matchAl
761
762
  */
762
763
  .vd-strip {
763
764
  box-sizing: border-box;
765
+ /* The drop line and the context menu are placed against it. */
766
+ position: relative;
764
767
  display: flex;
765
768
  flex: 0 0 104px;
766
769
  height: 104px;
@@ -787,21 +790,121 @@ ${Zt}`);return t===-1?-1:t+1}function sm(e){let t=new Set;for(let r of e.matchAl
787
790
  }
788
791
 
789
792
  .vd-strip__list[hidden],
790
- .vd-strip__empty[hidden] {
793
+ .vd-strip__blank[hidden],
794
+ .vd-strip__drop[hidden] {
791
795
  display: none;
792
796
  }
793
797
 
794
- .vd-strip__empty {
798
+ /* No frames: what the strip is for, and the way to start one. */
799
+ .vd-strip__blank {
800
+ display: flex;
795
801
  flex: 1 1 auto;
796
- align-self: center;
797
- margin: 0;
802
+ align-items: center;
803
+ justify-content: center;
804
+ gap: 12px;
805
+ min-width: 0;
798
806
  padding: 0 16px;
807
+ }
808
+
809
+ .vd-strip__empty {
810
+ min-width: 0;
811
+ margin: 0;
799
812
  font-size: 12px;
800
813
  line-height: 1.5;
801
- text-align: center;
802
814
  color: var(--vd-muted, rgb(0 0 0 / 0.55));
803
815
  }
804
816
 
817
+ .vd-strip__add {
818
+ flex: 0 0 auto;
819
+ height: 28px;
820
+ padding: 0 12px;
821
+ border: 1px solid var(--vd-rule, rgb(0 0 0 / 0.12));
822
+ border-radius: 6px;
823
+ background: none;
824
+ color: var(--vd-ink, #1a1a1f);
825
+ font: inherit;
826
+ font-size: 12px;
827
+ cursor: default;
828
+ }
829
+
830
+ .vd-strip__add:hover {
831
+ background: var(--vd-row-hover, rgb(0 0 0 / 0.06));
832
+ }
833
+
834
+ .vd-strip__add:focus-visible {
835
+ outline: 2px solid var(--vd-focus, var(--vd-accent, #3b82f6));
836
+ outline-offset: 2px;
837
+ }
838
+
839
+ /* Where a dragged tile lands: a line in the gap, the tile's height, level
840
+ with the pictures (the list's 11 px top padding). */
841
+ .vd-strip__drop {
842
+ position: absolute;
843
+ top: 11px;
844
+ width: 2px;
845
+ height: 64px;
846
+ border-radius: 1px;
847
+ background: var(--vd-chosen, var(--vd-accent, #3b82f6));
848
+ pointer-events: none;
849
+ }
850
+
851
+ /* The tiles being dragged stay in place, faded, until the drop moves them. */
852
+ .vd-strip__tile[data-dragging='true'] {
853
+ opacity: 0.35;
854
+ }
855
+
856
+ .vd-strip--dragging,
857
+ .vd-strip--dragging * {
858
+ cursor: grabbing;
859
+ }
860
+
861
+ /* The picture under the pointer while dragging, with a count for several. */
862
+ .vd-strip__ghost {
863
+ position: fixed;
864
+ top: 0;
865
+ left: 0;
866
+ z-index: 10;
867
+ pointer-events: none;
868
+ opacity: 0.9;
869
+ }
870
+
871
+ .vd-strip__ghost .vd-strip__thumb {
872
+ outline: 2px solid var(--vd-chosen, var(--vd-accent, #3b82f6));
873
+ outline-offset: 1px;
874
+ }
875
+
876
+ .vd-strip__count {
877
+ position: absolute;
878
+ top: -8px;
879
+ right: -8px;
880
+ min-width: 18px;
881
+ height: 18px;
882
+ padding: 0 5px;
883
+ box-sizing: border-box;
884
+ border-radius: 9px;
885
+ background: var(--vd-chosen, var(--vd-accent, #3b82f6));
886
+ color: var(--vd-on-chosen, #ffffff);
887
+ font-family: var(--vd-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
888
+ font-size: 11px;
889
+ line-height: 18px;
890
+ text-align: center;
891
+ }
892
+
893
+ /* Read by a screen reader, never seen. */
894
+ .vd-strip__status {
895
+ position: absolute;
896
+ width: 1px;
897
+ height: 1px;
898
+ overflow: hidden;
899
+ clip-path: inset(50%);
900
+ white-space: nowrap;
901
+ }
902
+
903
+ /* The menu opens up over the canvas, so it sits above the canvas's chrome. */
904
+ .vd-strip > .vd-menu {
905
+ z-index: 10;
906
+ }
907
+
805
908
  .vd-strip__tile {
806
909
  display: flex;
807
910
  flex: 0 0 auto;
@@ -824,7 +927,9 @@ ${Zt}`);return t===-1?-1:t+1}function sm(e){let t=new Set;for(let r of e.matchAl
824
927
  box-sizing: border-box;
825
928
  overflow: hidden;
826
929
  border-radius: 4px;
827
- outline: 1px solid var(--vd-rule, rgb(0 0 0 / 0.12));
930
+ /* Its own variable, not the strip's rule: a dark slide on a dark strip
931
+ needs a stronger edge than a panel's hairline to be told apart. */
932
+ outline: 1px solid var(--vd-thumb-rule, var(--vd-rule, rgb(0 0 0 / 0.12)));
828
933
  outline-offset: -1px;
829
934
  background: var(--vd-thumb-bg, #f2f2f2);
830
935
  }
@@ -2464,9 +2569,9 @@ button.vd-field__swatch:focus-visible {
2464
2569
  background: rgb(255 255 255 / 0.09);
2465
2570
  color: #fff;
2466
2571
  }
2467
- `;function Bn(e){if(e.getElementById(_c))return;let t=e.createElement("style");t.id=_c,t.textContent=Cc,e.head.appendChild(t)}var Dt=["font","size","weight","italic","underline","strike","fill","letterSpacing","link"];function ar(e){return typeof e=="string"?e===""?[]:[{text:e}]:e.flatMap(t=>typeof t=="string"?t===""?[]:[{text:t}]:t.text===""?[]:[t])}function sr(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function ir(e){return sr(e).length}function or(e){let t={};for(let r of Dt){let n=e[r];n!==void 0&&(t[r]=n)}return t}function Mc(e,t){return Dt.every(r=>e[r]===t[r])}function jg(e,t){let r={text:e};for(let n of Dt){let o=t[n];o!==void 0&&(r[n]=o)}return r}function Hn(e){let t=ar(e),r=[];for(let o of t){let a=r[r.length-1];if(a&&Mc(or(a),or(o))){r[r.length-1]={...a,text:a.text+o.text};continue}r.push(o)}if(r.length===0)return"";let n=r[0];return r.length===1&&Ec(n)?n.text:r.map(o=>Ec(o)?o.text:o)}function Ec(e){return Dt.every(t=>e[t]===void 0)}function zl(e,t,r){let[n,o]=ma(t,r,ir(e)),a=[],i=0;for(let l of ar(e)){let d=i+l.text.length,c=Math.max(n,i),h=Math.min(o,d);h>c&&a.push({...l,text:l.text.slice(c-i,h-i)}),i=d}return Hn(a)}function Rr(e,t,r,n,o){let a=ir(e),[i,l]=ma(t,r,a),d=o??Un(e,i),c=[],h=0,x=!1,y=()=>{x||n===""||(c.push(jg(n,d)),x=!0)};for(let b of ar(e)){let P=h+b.text.length,k=Math.min(i,P);k>h&&c.push({...b,text:b.text.slice(0,k-h)}),i>=h&&i<=P&&y();let _=Math.max(l,h);P>_&&c.push({...b,text:b.text.slice(_-h)}),h=P}return y(),Hn(c)}function Un(e,t){let r=ar(e);if(r.length===0)return{};let n=0,o=r[0];for(let a of r){let i=n+a.text.length;if(t>n&&t<=i)return or(a);if(t<=n)return or(o);o=a,n=i}return or(o)}function ql(e,t,r,n){let[o,a]=ma(t,r,ir(e));if(o===a)return Hn(e);let i=Object.keys(n),l=[],d=0;for(let c of ar(e)){let h=d+c.text.length;for(let[x,y,b]of Kg(d,h,o,a)){if(y<=x)continue;let P=c.text.slice(x-d,y-d);if(!b){l.push({...c,text:P});continue}let k={...c,text:P};for(let _ of i)n[_]===void 0?delete k[_]:k[_]=n[_];l.push(k)}d=h}return Hn(l)}function Kg(e,t,r,n){return[[e,Math.min(t,r),!1],[Math.max(e,r),Math.min(t,n),!0],[Math.max(e,n),t,!1]]}function jl(e,t,r){let[n,o]=ma(t,r,ir(e));if(n===o)return Un(e,n);let a,i=0;for(let l of ar(e)){let d=i+l.text.length;if(Math.min(d,o)>Math.max(i,n)){let c=or(l);if(!a)a=c;else{let h={};for(let x of Dt)a[x]===c[x]&&a[x]!==void 0&&(h[x]=a[x]);a=h}}i=d}return a??{}}function ma(e,t,r){let n=Ac(Math.min(e,t),r),o=Ac(Math.max(e,t),r);return[n,o]}function Ac(e,t){return Math.max(0,Math.min(Math.round(e),t))}function Ir(e,t){let r=[],n=0;return e.lines.forEach((o,a)=>{let i=o.spans.map(h=>h.text).join(""),l=i===""?n:Gg(t,i,n),d=l+i.length,c=a===e.lines.length-1;r.push({start:l,end:c?t.length:d}),n=d}),r.length===0&&r.push({start:0,end:t.length}),r}function Gg(e,t,r){let n=e.indexOf(t,r);return n===-1?r:n}function xa(e,t){for(let r=0;r<e.length;r+=1){let n=e[r];if(t<=n.end)return r}return Math.max(0,e.length-1)}function ga(e,t,r,n){let o=Ir(e,t),a=xa(o,r),i=e.lines[a],l=o[a];if(!i||!l)return{x:0,y:0,h:0,line:0};let d=Math.max(0,Math.min(r-l.start,Tc(i)));return{x:Kl(i,d,n),y:i.y,h:i.h,line:a}}function Vn(e,t,r,n){let o=Ir(e,t);if(e.lines.length===0)return 0;let a=e.lines.findIndex(d=>r.y<d.y+d.h);a===-1&&(a=e.lines.length-1);let i=e.lines[a];return o[a].start+$c(i,r.x,n)}function $c(e,t,r){let n=0,o=1/0,a=0,i=(l,d)=>{let c=Math.abs(d-t);c<o&&(o=c,n=l)};i(0,e.spans[0]?.x??0);for(let l of e.spans){let d=[...l.text],c=0;d.forEach((h,x)=>{c=r.advance(d.slice(0,x+1).join(""),l.style),i(a+x+1,l.x+c)}),a+=d.length}return n}function Kl(e,t,r){let n=0,o=e.spans[0]?.x??0;for(let a of e.spans){let i=[...a.text];if(t<=n)return a.x;if(t>=n+i.length){o=a.x+a.w,n+=i.length;continue}let l=i.slice(0,t-n).join("");return a.x+r.advance(l,a.style)}return o}function Tc(e){return e.spans.reduce((t,r)=>t+[...r.text].length,0)}function Gl(e,t,r,n,o){let a=Math.min(r,n),i=Math.max(r,n);if(a===i)return[];let l=Ir(e,t),d=[];return e.lines.forEach((c,h)=>{let x=l[h];if(!x)return;let y=Math.max(a,x.start),b=Math.min(i,x.end);if(b<=y)return;let P=Tc(c),k=Kl(c,Math.min(y-x.start,P),o),_=Kl(c,Math.min(b-x.start,P),o),B=Math.max(_-k,b>x.end-1&&b>y?4:0);B>0&&d.push({x:k,y:c.y,w:B,h:c.h})}),d}function Wl(e,t,r,n,o){let a=Ir(e,t),l=xa(a,r)+n,d=e.lines[l],c=a[l];if(!d||!c)return n===-1?0:t.length;let h=ga(e,t,r,o);return Math.min(c.start+$c(d,h.x,o),c.end)}var Wg=/[\p{L}\p{N}_]/u;function Xl(e,t){let r=Math.max(0,Math.min(t,e.length)),n=l=>Wg.test(e[l]??""),o=r;if(!n(o)&&o>0&&n(o-1)&&(o-=1),!n(o))return{from:r,to:r};let a=o,i=o;for(;a>0&&n(a-1);)a-=1;for(;i<e.length&&n(i);)i+=1;return{from:a,to:i}}function ya(e,t,r){let n=Ir(e,t),o=n[xa(n,r)];return o?{from:o.start,to:o.end}:{from:0,to:t.length}}var Pc=700;function Yl(e){let t=0,r=0,n=null,o=!1,a=0,i=!1,l=0,d=0;function c(){return sr(e.content())}function h(E){return Math.max(0,Math.min(Math.round(E),c().length))}function x(){return{from:Math.min(t,r),to:Math.max(t,r)}}function y(E,D=E){let N=t!==E||r!==D;t=h(E),r=h(D),N&&b(),n=null,e.invalidate()}function b(){o=!1,a&&(clearTimeout(a),a=0)}function P(){a&&clearTimeout(a),a=setTimeout(b,Pc)}function k(E,D){e.write(E,o,D),o=!0,P()}function _(E,D){let{from:N,to:A}=x(),G=n??void 0;k(Rr(e.content(),N,A,E,G),D),t=r=N+E.length,n=null,e.invalidate()}function B(E,D){E!==D&&(k(Rr(e.content(),E,D,""),"Delete text"),t=r=Math.min(E,D),e.invalidate())}function R(E,D){let{from:N,to:A}=x();if(N!==A){B(N,A);return}let G=c();if(E===-1){if(N===0)return;let me=D?Oc(G,N):N-1;B(me,N);return}if(N>=G.length)return;let se=D?Dc(G,N):N+1;B(N,se)}function J(E,D){let N=c();return D?E===-1?Oc(N,r):Dc(N,r):h(r+E)}return{id:e.id,getSelection:()=>({anchor:t,head:r}),setSelection(E,D){y(E,D??E)},caret(){return ga(e.layout(),c(),r,e.measure())},highlight(){let{from:E,to:D}=x();return Gl(e.layout(),c(),E,D,e.measure())},pointTo(E,D){let N=Vn(e.layout(),c(),E,e.measure());y(D?t:N,N)},selectWordAt(E){let D=Vn(e.layout(),c(),E,e.measure()),N=Xl(c(),D);y(N.from,N.to)},selectLineAt(E){let D=Vn(e.layout(),c(),E,e.measure()),N=ya(e.layout(),c(),D);y(N.from,N.to)},selectAll(){y(0,c().length)},format(E){let{from:D,to:N}=x();if(D===N){n={...Un(e.content(),D),...E},e.invalidate();return}b(),k(ql(e.content(),D,N,E),"Format text"),b(),e.invalidate()},activeMark(){if(n)return n;let{from:E,to:D}=x();return jl(e.content(),E,D)},composing:()=>i,handleKey(E){if(i)return!1;let D=E.metaKey||E.ctrlKey,N=E.altKey||E.ctrlKey&&!E.metaKey;switch(E.key){case"Escape":return e.close("escape"),!0;case"ArrowLeft":case"ArrowRight":{let A=E.key==="ArrowLeft"?-1:1,{from:G,to:se}=x();if(!E.shiftKey&&G!==se)y(A===-1?G:se);else{let me=D?Lc(e,c(),r,A):J(A,N);y(E.shiftKey?t:me,me)}return!0}case"ArrowUp":case"ArrowDown":{let A=E.key==="ArrowUp"?-1:1,G=D?A===-1?0:c().length:Wl(e.layout(),c(),r,A,e.measure());return y(E.shiftKey?t:G,G),!0}case"Home":case"End":{let A=Lc(e,c(),r,E.key==="Home"?-1:1);return y(E.shiftKey?t:A,A),!0}case"Backspace":return R(-1,N||D),!0;case"Delete":return R(1,N||D),!0;case"Enter":return D?e.close("done"):_(`
2468
- `,"Type text"),!0;case"Tab":return!1;case"a":case"A":return D?(y(0,c().length),!0):!1;case"b":case"B":{if(!D)return!1;let A=this.activeMark().weight===700;return this.format({weight:A?void 0:700}),!0}case"i":case"I":return D?(this.format({italic:this.activeMark().italic===!0?void 0:!0}),!0):!1;case"u":case"U":return D?(this.format({underline:this.activeMark().underline===!0?void 0:!0}),!0):!1;default:return!1}},handleInput(E){if(!i)switch(E.inputType){case"insertText":case"insertReplacementText":case"insertFromPaste":case"insertFromDrop":case"insertFromYank":_(Xg(E),"Type text");return;case"insertParagraph":case"insertLineBreak":_(`
2469
- `,"Type text");return;case"deleteContentBackward":case"deleteWordBackward":R(-1,E.inputType==="deleteWordBackward");return;case"deleteContentForward":case"deleteWordForward":R(1,E.inputType==="deleteWordForward");return;case"deleteByCut":case"deleteByDrag":{let{from:D,to:N}=x();B(D,N);return}default:return}},handleCompositionStart(){i=!0;let{from:E,to:D}=x();l=E,d=D,b()},handleCompositionUpdate(E){k(Rr(e.content(),l,d,E),"Type text"),d=l+E.length,t=r=d,e.invalidate()},handleCompositionEnd(E){k(Rr(e.content(),l,d,E),"Type text"),i=!1,d=l+E.length,t=r=d,b(),e.invalidate()},breakBurst:b,destroy(){b()}}}function Xg(e){return typeof e.data=="string"?e.data:e.dataTransfer?.getData("text/plain")??""}function Lc(e,t,r,n){let o=ya(e.layout(),t,r);return n===-1?o.from:o.to}var va=/[\p{L}\p{N}_]/u;function Oc(e,t){let r=t;for(;r>0&&!va.test(e[r-1]??"");)r-=1;for(;r>0&&va.test(e[r-1]??"");)r-=1;return r}function Dc(e,t){let r=t;for(;r<e.length&&!va.test(e[r]??"");)r+=1;for(;r<e.length&&va.test(e[r]??"");)r+=1;return r}function Jl(e){return ir(e)===0}var Zl={v:"select",f:"frame",r:"rect",o:"ellipse",p:"pen",t:"text"};function Fr(e,t){let r=[];for(let n of t){if(!V(e.root,n.nodeId))continue;let o=re(n.to);re(n.from)!==o&&r.push({op:"set",id:n.nodeId,prop:n.prop,value:o})}return r}function re(e){return Math.round(e*100)/100}function Br(e,t,r,n){let o=new Set,a=[];for(let d of t)d.op==="set"&&(o.add(Oe(d.id,d.prop)),a.push({nodeId:d.id,prop:d.prop}));if(a.length===0)return[];let i=[],l=new Set;for(let d of a)for(let c of r.get(Oe(d.nodeId,d.prop))??[]){let h=Oe(c.nodeId,c.prop);if(o.has(h)||l.has(h)||!V(e.root,c.nodeId))continue;let x=n.nodes.get(c.nodeId)?.values[c.prop];x!==void 0&&(l.add(h),i.push({op:"set",id:c.nodeId,prop:c.prop,value:re(x)}))}return i}function Ql(e,t,r,n={x:0,y:0}){let o=[],a=new Set,i=e;for(;;){let l=[],d=Ae(i);for(let[c,h]of t){let x=r.get(c),y=V(i.root,h),b=d.nodes.get(h);if(!(!x||!y||!b))for(let P of rt(y)){let k=Oe(h,P);if(a.has(k))continue;let _=x[P],B=b.values[P];if(_===void 0||B===void 0)continue;let R=_+(P==="x"?n.x:P==="y"?n.y:0);re(R)!==re(B)&&(a.add(k),l.push({op:"set",id:h,prop:P,value:re(R)}))}}if(l.length===0)return o;o.push(...l),i=ve(i,l).document}}function Hr(e,t,r=new Set){let n=Ae(e),o=Ae(t),a=[];for(let[i,l]of o.nodes){if(r.has(i))continue;let d=n.nodes.get(i),c=V(t.root,i);if(!(!d||!c))for(let h of rt(c)){let x=d.values[h],y=l.values[h];x===void 0||y===void 0||re(x)!==re(y)&&a.push({op:"set",id:i,prop:h,value:re(x)})}}return a}function ba(e,t,r){let n=new Set,o=[];for(let a of t)a.op==="set"&&a.prop==="view"&&n.add(a.id);for(let a of t){if(a.op!=="set"||a.prop!=="w"&&a.prop!=="h"||n.has(a.id))continue;let i=V(e.root,a.id);if(i?.type!=="vector"||i.view!==void 0)continue;let l=r(a.id);l&&(n.add(a.id),o.push({op:"set",id:a.id,prop:"view",value:Yt({x:0,y:0,w:l.w,h:l.h})}))}return o.length===0?[...t]:[...o,...t]}var ed="host:",Yg="#ffffff",wa=20,Jg=15,Zg={ne:0,se:90,sw:180,nw:270,n:0,e:90,s:180,w:270},Nc={w:240,h:28},Qg={text:"Add text",frame:"Add page",rect:"Draw rectangle",ellipse:"Draw ellipse"};function ey(e,t){let r=t.x-e.x,n=t.y-e.y,o=Math.max(Math.abs(r),Math.abs(n));return{x:e.x+Math.sign(r||1)*o,y:e.y+Math.sign(n||1)*o}}var ty={KeyA:"left",KeyD:"right",KeyW:"top",KeyS:"bottom",KeyH:"hcenter",KeyV:"vcenter"},ry={KeyH:"x",KeyV:"y"},ny={left:"Align left",hcenter:"Align horizontal centres",right:"Align right",top:"Align top",vcenter:"Align vertical centres",bottom:"Align bottom"},td=null,oy=220,Rc={lock:!0,hide:!0},ay=["x","y","w","h"],sy={front:"Bring to front",forward:"Bring forward",backward:"Send backward",back:"Send to back"},iy=11,Pt=2;function nd(e,t){Bn(e.ownerDocument),e.classList.add("vd-editor"),e.hasAttribute("tabindex")||(e.tabIndex=0);let r=t.document,n=[],o=t.tool??"select",a=null,i=null,l=null,d={ids:[],label:null},c=null,h=[],x=!1,y=!1,b=null,P={...Rc,...t.features},k=null,_=new Rn,B=0,R=null,J={dx:0,dy:0},E=null,D=new Map,N=e.ownerDocument.createElement("div");N.style.position="absolute",N.style.inset="0",e.appendChild(N);let A=Ho(N,{document:r,...t.camera?{camera:t.camera}:{},...t.surface?{surface:t.surface}:{},...t.interactive===void 0?{}:{interactive:t.interactive},...t.wheel?{wheel:t.wheel}:{},...t.resolveAsset?{resolveAsset:t.resolveAsset}:{},...t.fonts?{fonts:t.fonts}:{},onSceneChange:(s,f)=>{f===r&&Ye("scene",{scene:s,document:f})},onCameraChange:s=>{se?.setZoom(s.zoom),Y(),Ye("camera",s),!(B>0)&&(Ca(),Ye("navigate",s))}}),G=bc(e,s=>A.documentToScreen(s)),se=t.chrome===!1?null:Hu(e,{onTool:wt,onUndo:Zr,onRedo:ao,onZoomReset:()=>A.fitToContent(),onPlay:t.onPlay,playHint:t.playHint,formatKeys:t.formatKeys}),me=t.chrome===!1?null:Al(e,{onCommand:Qp,...t.formatKeys?{formatKeys:t.formatKeys}:{}}),he=r,ke=r,we=[],T=null,Q=[],w=null,$=null,M=new Map,L=null,H=null,q=null,S=[],U=ze,W=null,I=null,z=null,X=null,tt=!1,ie=e.ownerDocument.createElement("textarea");ie.className="vd-editor__input",ie.setAttribute("aria-hidden","true"),ie.tabIndex=-1,ie.autocapitalize="off",ie.autocomplete="off",ie.spellcheck=!1,e.appendChild(ie);function Ye(s,f){let u=D.get(s);if(u)for(let p of u)p(f)}function sp(s,f){let u=D.get(s)??new Set;return u.add(f),D.set(s,u),()=>u.delete(f)}function jn(s){B+=1;try{s()}finally{B-=1}}function Ca(){R!==null&&(e.ownerDocument.defaultView?.cancelAnimationFrame(R),R=null)}function ip(s){let f=A.linkAt(s),u=f===void 0?void 0:Je(f);return u?u.kind==="url"?t.onOpenLink?(t.onOpenLink(u.url),!0):!1:V(r.root,u.id)?(le([u.id]),Ea([u.id]),!0):!1:!1}function Ea(s,f={}){if(T!==null)return E={target:s,options:f},!1;let u=fp(s);if(!u)return!1;let p=e.getBoundingClientRect(),m=p.width>0&&p.height>0,g=m?{width:p.width,height:p.height-lp(p)}:{width:u.w+96,height:u.h+96},v=f.fit==="always"?oa(u,g):Cl(u,g,A.getCamera());if(!v)return!1;Ca(),f.by==="person"&&Ye("navigate",v);let C=e.ownerDocument.defaultView,O=C?.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;if(f.animate===!1||O||!m||!C?.requestAnimationFrame)return jn(()=>A.setCamera(v)),!0;let F=A.getCamera(),j=C.performance.now();J={dx:0,dy:0};let K=ae=>{let Z=Math.min(1,Math.max(0,(ae-j)/oy)),ge=Z===1?v:ac(F,v,sc(Z),g);jn(()=>A.setCamera(Tt(ge,J.dx,J.dy))),R=Z===1?null:C.requestAnimationFrame(K)};return R=C.requestAnimationFrame(K),!0}function lp(s){let f=se?.element.getBoundingClientRect();return!f||f.height===0?0:Math.max(0,s.bottom-f.top)}function dp(s,f){R!==null&&(J={dx:J.dx+s,dy:J.dy+f}),jn(()=>A.setCamera(Tt(A.getCamera(),s,f)))}function Kn(){if(E===null||T!==null)return;let{target:s,options:f}=E;E=null,Ea(s,f)}function fp(s){if(s==="content"){let u=A.getScene();return na([{x:u.x,y:u.y,w:u.width,h:u.height}])}let f=[];for(let u of _l(r,s)){let p=Ee(u);p&&f.push(p)}return na(f)}function lt(s){return A.getResolution().nodes.get(s)}function yt(s){let f=lt(s);return f?{x:f.x,y:f.y,w:f.w,h:f.h}:void 0}function Ee(s){return nr(s,r,A.getResolution())}function Nt(s){let f=lt(s);return f?{x:f.absX,y:f.absY,w:f.w,h:f.h}:void 0}function Rt(s){return lt(s)?.values.rotation??0}function pd(){let s=zr();if(s.length===0)return null;for(let f of s){let u=V(r.root,f);if(!u||!Rs.includes(u.type))return null}return s}function Gn(s,f=new Set){let u=A.getResolution(),p=null;return oe(r.root,m=>{if(f.has(m.id)||!Ft(m.id))return!1;if(m.type!=="frame")return;let g=u.nodes.get(m.id);if(!g)return!1;let v={x:g.absX,y:g.absY,w:g.w,h:g.h};if(!et(v,s.x,s.y))return!1;p=m.id}),p}function It(s){let f=lt(s);return f?{x:f.absX,y:f.absY}:{x:0,y:0}}function Re(){return k?.of!==r&&(k={of:r,hidden:io(r.root),locked:lo(r.root)}),k}function Ft(s){let{hidden:f,locked:u}=Re();return!f.has(s)&&!u.has(s)}function te(){return n.filter(Ft)}function Wn(s){let f=A.hitTest(s,p=>!Re().locked.has(p));if(f===null)return null;let u=b===null||De(r.root,f).includes(b);return ea(f,r,u?b:null)}function up(){return Nn(r,te(),A.getResolution())}function Vr(){return te().length<2?null:Dl(up())}function Xn(s){let f=[];for(let u of s)for(let p of rr(u,r)){let m=yt(p);m&&f.push({member:u,node:p,frame:m})}return f}function Yn(s,f){let u=V(r.root,s);if(!u)return"literal";let p=u[f];return p===void 0?"literal":To(p).kind}function cp(s){let f=V(r.root,s),u={};if(!f)return u;let p=[...ay,...Ln(f).map(m=>m.prop)];for(let m of p)u[m]=Yn(s,m);return u}function hd(s,f){let u="none";for(let p of s){let m=Aa(p,f);if(m==="expression")return"expression";m==="token"&&(u="token")}return u}function Aa(s,f){let u="none";for(let p of f){let m=Yn(s,p);if(m==="complex")return"expression";m==="token"&&(u="token")}return u}let Ie=null;function ue(s,f){if(s.length===0)return;let u=bo(r,ba(r,s,yt)),p=ve(r,u);r=p.document,Ie?(Ta(Ie.started,Ie.label,u,p.inverse),Ie.started=!0):_.push({label:f,ops:u,inverse:p.inverse}),Jn(u,f)}function pp(s){Ie={label:s,started:!1}}function hp(){Ie=null}function md(s,f){s.length!==0&&(r=ve(r,s).document,Jn(s,f))}function Jn(s,f){a=null,H=null,q=null,A.update(r),se?.setHistory(_.canUndo,_.canRedo),Y(),Ye("change",{document:r,ops:s,label:f}),Ye("problems",A.getScene().problems)}function le(s){let f=s.filter(p=>p!==r.root.id&&V(r.root,p)),u=f.length!==n.length||f.some((p,m)=>n[m]!==p);n=[...f],z&&(f.length!==1||f[0]!==z.id)&&(z=null),u&&(me?.close(),q=null,Ye("selection",n)),Y()}function mp(s,f){let u=V(r.root,s);if(!u)return[];let p=A.getCamera().zoom;if(Math.min(f.w,f.h)*p<24)return[];let m=iy/p,g=lt(s);return Ln(u).flatMap(v=>{let C=g?.values[v.prop]??0,O=Yn(s,v.prop)!=="literal";return v.handles(f,C,m).map(F=>({id:F.id,at:F.at,bound:O}))})}function xp(){let s=[];for(let F of te()){let j=Ee(F);j&&s.push(j)}let f=Qe(s);if(!f)return null;let u=te().length===1?te()[0]:void 0,p=u===void 0?void 0:V(r.root,u),m=u===void 0||!p||ce(p),g=new Set,v=zr();for(let F of di){let j=Uo(F);v.some(K=>j.some(ae=>Yn(K,ae)!=="literal"))&&g.add(F)}let C=!m&&u!==void 0?Rt(u):0,O=C!==0&&u!==void 0?Nt(u):void 0;return{frame:O??f,...O?{rotation:C}:{},rotatable:pd()!==null,handles:I===null,boundHandles:g,adjusters:I!==null||m||u===void 0||O?[]:mp(u,f)}}function zr(){return[...new Set(te().flatMap(s=>rr(s,r)))]}function gp(s){if(!s)return null;if(T?.kind==="adjust")return`r ${re(w??T.from)}`;if(T?.kind==="rotate")return`${re($??0)}\xB0`;if(!T&&H&&te().length===1){let f=lt(te()[0])?.values[H.prop]??0;return`r ${re(f)}`}return T?.kind==="move"?`${re(s.frame.x)}, ${re(s.frame.y)}`:`${re(s.frame.w)} \xD7 ${re(s.frame.h)}`}function yp(){let f=T!==null&&T.kind!=="space"&&T.kind!=="reorder"?null:Vr();if(!f)return{spacers:[],rings:[],lead:null};let u=T?.kind==="space"?T.spacer:null;return{spacers:Nl(f).map(p=>({id:p.id,axis:p.axis,at:p.at,label:p.id===(u??q)?String(re(p.gap)):null})),rings:Rl(f).map(p=>({id:p.id,at:p.at})),lead:T?.kind==="reorder"?Ee(T.id)??null:null}}function Y(){if(!y)return;let s=Bp(),f=s?null:xp(),u=a!==null&&!n.includes(a)&&!T?Ee(a)??null:null,p={...vc,...yp(),hover:u,members:te().length>1?te().flatMap(m=>Ee(m)??[]):[],box:f,badge:gp(f),caret:xd(),textSelection:gd(),draft:T?.kind==="create"?tr(T.origin,T.current):null,draftEllipse:T?.kind==="create"&&o==="ellipse",marquee:T?.kind==="marquee"?tr(T.origin,T.current):null,guides:T?U.guides:[],measures:T?U.measures:[],presence:d.ids.length===0?null:{frames:d.ids.flatMap(m=>Ee(m)??[]),label:d.label},highlight:Pn(r,h).flatMap(m=>Ee(m.id)??[]),slots:lh(),parked:n.filter(m=>!Ft(m)).flatMap(m=>Ee(m)??[]),lockHint:wp(),path:s,turn:kp(),pageLabels:vp()};G.render(p)}function vp(){return i?[]:r.root.children.flatMap(s=>{if(s.type!=="frame")return[];let f=Ee(s.id);if(!f)return[];let u=s.name;return[{id:s.id,frame:f,label:typeof u=="string"&&u!==""?u:s.id,state:n.includes(s.id)?"selected":a===s.id?"hover":"idle"}]})}function bp(s){let f=G.pageLabelRect(s),u=V(r.root,s);if(!f||!u)return;let p=u.name,m=e.ownerDocument.createElement("input");m.className="vd-editor__rename",m.type="text",m.spellcheck=!1,m.value=typeof p=="string"&&p!==""?p:"",m.placeholder=s,m.setAttribute("aria-label",`Name of ${s}`),m.style.left=`${f.x-4}px`,m.style.top=`${f.y-2}px`,m.style.width=`${Math.max(120,f.w+40)}px`;let g=!1,v=C=>{if(g)return;g=!0;let O=m.value.trim();m.remove(),i=null,C&&O!==(typeof p=="string"?p:"")&&nf(s,"name",O===""?void 0:O,"Rename"),Y(),e.focus({preventScroll:!0})};m.addEventListener("keydown",C=>{C.stopPropagation(),C.key==="Enter"?(C.preventDefault(),v(!0)):C.key==="Escape"&&(C.preventDefault(),v(!1))}),m.addEventListener("pointerdown",C=>C.stopPropagation()),m.addEventListener("blur",()=>v(!0)),i=m,e.appendChild(m),Y(),m.focus(),m.select()}function wp(){if(l===null||T||!Re().locked.has(l))return null;let s=Ee(l);return s?{frame:s,label:l}:null}function Zn(s){let f=A.itemOf(s);if(f?.kind!=="text")return null;let u=f.lines[0]?.y??f.y,p={lines:f.lines.map(m=>({y:m.y-u,h:m.h,baseline:m.baseline-u,w:m.w,spans:m.spans.map(g=>({text:g.text,style:g.style,x:g.x-f.x,w:g.w}))})),width:Math.max(0,...f.lines.map(m=>m.w)),height:f.height};return{item:f,layout:p,top:u}}function Ma(){return o==="text"?"text":o!=="select"?"crosshair":"arrow"}function xd(){if(!I)return null;let s=Zn(I.id);if(!s)return null;let f=I.caret();return{x:s.item.x+f.x,y:s.top+f.y,h:f.h}}function gd(){if(!I)return[];let s=Zn(I.id);return s?I.highlight().map(f=>({x:s.item.x+f.x,y:s.top+f.y,w:f.w,h:f.h})):[]}function $a(s){if(!I)return null;let f=Zn(I.id);if(!f)return null;let u=qr(I.id,s);return{x:u.x-f.item.x,y:u.y-f.top}}function qr(s,f){let u=Rt(s),p=u===0?void 0:Nt(s);return p?Pe(f,Ve(p),-u):f}function kp(){let s=I?.id??z?.id;if(s===void 0)return null;let f=Rt(s),u=f===0?void 0:Nt(s);return u?{angle:f,centre:Ve(u)}:null}function Sp(s){let f=V(r.root,s);if(!f||f.type!=="text"||typeof f.h!="number")return[];let u=A.itemOf(s);if(u?.kind!=="text")return[];let p=re(Math.ceil(u.height));return p>f.h?[{op:"set",id:s,prop:"h",value:p}]:[]}function _p(s,f,u,p){let m=Ie?Ie.started:u,g=Ie?.label??p;Ie&&(Ie.started=!0);let v=[{op:"set",id:s,prop:"content",value:f}],C=ve(r,v);r=C.document,A.update(r);let O=Sp(s);if(O.length===0){Ta(m,g,v,C.inverse),Jn(v,g);return}let F=ve(r,O);r=F.document,A.update(r);let j=[...v,...O];Ta(m,g,j,[...F.inverse,...C.inverse]),Jn(j,g)}function Ta(s,f,u,p){let m={label:f,ops:u,inverse:p};s&&_.amend(m)||_.push(m)}function jr(s,f){let u=V(r.root,s);if(!u||u.type!=="text"||I?.id===s)return;lr("done"),wt("select"),le([s]),I=Yl({id:s,content:()=>{let m=V(r.root,s);return m?.type==="text"?m.content:""},layout:()=>Zn(s)?.layout??{lines:[],width:0,height:0},measure:()=>A.getMeasurer(),write:(m,g,v)=>_p(s,m,g,v),invalidate:()=>{Y(),yd(),Ye("selection",n)},close:m=>lr(m)});let p=f?$a(f):null;p?I.pointTo(p,!1):I.selectAll(),e.classList.add("vd-editor--editing"),ie.value="",ie.focus({preventScroll:!0}),Y(),yd()}function lr(s){let f=I;if(!f)return;I=null,tt=!1,f.destroy(),e.classList.remove("vd-editor--editing","vd-editor--typing"),Ye("selection",n);let u=V(r.root,f.id);u?.type==="text"&&Jl(u.content)&&(ue([{op:"remove",id:f.id}],"Remove empty text"),le([])),e.ownerDocument.activeElement===ie&&e.focus({preventScroll:!0}),Y()}function yd(){let s=xd();if(!s)return;let f=A.documentToScreen({x:s.x,y:s.y});ie.style.left=`${Math.round(f.x)}px`,ie.style.top=`${Math.round(f.y)}px`}let dr=0;function vd(){e.classList.add("vd-editor--typing"),dr&&clearTimeout(dr),dr=setTimeout(()=>{dr=0,e.classList.remove("vd-editor--typing")},520)}function La(s){let f=Fr(he,s);return f.length>0&&L?[...f,...Br(he,f,M,L)]:f}function Bt(s){Oa(La(s))}function Oa(s,f=s){let u=m=>{let g=L?.nodes.get(m);return g?{x:0,y:0,w:g.w,h:g.h}:void 0},p=ba(he,s,u);Q=ba(he,f,u),A.update(p.length>0?ve(he,p).document:he),Y()}function bd(){let s=Qe(te().flatMap(p=>Ee(p)??[]));if(!s)return null;let f=new Map,u=new Map;for(let p of zr()){let m=Nt(p),g=yt(p);!m||!g||(f.set(p,m),u.set(p,{x:m.x-g.x,y:m.y-g.y}))}return f.size===0?null:{bounds:s,frames:f,offsets:u}}function wd(s,f){let u=gl(s.frames,s.bounds,f),p=[];for(let[m,g]of u){let v=s.frames.get(m),C=s.offsets.get(m);if(!v||!C)continue;let O=Rt(m),F=O===0?g:Lu(v,O,s.bounds,f);p.push({nodeId:m,prop:"x",from:v.x-C.x,to:F.x-C.x},{nodeId:m,prop:"y",from:v.y-C.y,to:F.y-C.y},{nodeId:m,prop:"w",from:v.w,to:F.w},{nodeId:m,prop:"h",from:v.h,to:F.h})}return p}function Cp(s,f){let u=pd();if(!u)return!1;let p=te().length===1&&u.length===1?u[0]:void 0,m=Qe(te().flatMap(C=>Ee(C)??[])),g=p!==void 0?Nt(p):m;if(!g)return!1;let v=u.flatMap(C=>{let O=Nt(C),F=yt(C);return!O||!F?[]:[{id:C,frame:O,rotation:Rt(C),offset:{x:O.x-F.x,y:O.y-F.y}}]});return v.length===0?!1:(Ke(f),Fe({kind:"rotate",pointerId:f,origin:s,centre:Ve(g),targets:v}),!0)}function Ep(s,f,u){let p=bd();return p?(Ke(u),Fe({kind:"scale",pointerId:u,origin:s,handle:f,...p}),!0):!1}function Ap(s){let f=bd();if(!f)return;let u=Fr(r,wd(f,s));if(u.length===0)return;let p=s.w!==f.bounds.w||s.h!==f.bounds.h;ue([...u,...Br(r,u,Er(r),Ae(r))],p?"Resize":"Move")}function Mp(s,f,u){let p=ca(s),m=Vr();if(!p||!m)return!1;let g=it(m,p.axis)?.gaps[p.index],v=Xn(te());return g===void 0||v.length===0?!1:(Ke(u),Fe({kind:"space",pointerId:u,origin:f,axis:p.axis,spacer:s,layout:m,gap:g,parts:v}),!0)}function $p(s,f){let u=s.axis==="x"?f.x-s.origin.x:f.y-s.origin.y,p=Math.max(0,s.gap+u);Bt(Da(s.parts,s.axis,pa(s.layout,s.axis,p)))}function Tp(s,f){let u=Vr(),p=u?it(u,s):void 0;if(!u||!p||p.gaps.length===0)return;let m=Fr(r,Da(Xn(te()),s,pa(u,s,Math.max(0,f))));m.length!==0&&ue([...m,...Br(r,m,Er(r),Ae(r))],"Spacing")}function Lp(s){let f=Vr(),u=f?it(f,s)?.gaps:void 0;return!u||u.length===0?null:Pl(u)?u[0]??null:"mixed"}function Da(s,f,u){return s.map(p=>{let m=f==="x"?p.frame.x:p.frame.y;return{nodeId:p.node,prop:f,from:m,to:m+(u.get(p.member)??0)}})}function Op(s,f,u){let p=Vr();if(!p||!p.order.includes(s))return!1;let m=Xn(te()),g=p.items.find(v=>v.id===s)?.frame;return m.length===0||!g?!1:(Ke(u),Fe({kind:"reorder",pointerId:u,id:s,layout:p,parts:m,grab:{x:f.x-g.x,y:f.y-g.y},to:p.order.indexOf(s),swap:!1}),!0)}function Dp(s,f,u){s.to=Bl(s.layout,f),s.swap=u;let p=Pp(s),m=new Map(p);m.set(s.id,{x:f.x-s.grab.x,y:f.y-s.grab.y}),Oa(La(kd(s,m)),La(kd(s,p)))}function Pp(s){let f=s.layout.order.indexOf(s.id);if(f===-1||s.to===f)return new Map;if(s.swap){let u=s.layout.order[s.to];return u===void 0?new Map:Vl(s.layout,s.id,u)}return Ul(s.layout,Hl(s.layout.order,f,s.to))}function kd(s,f){let u=new Map(s.layout.items.map(m=>[m.id,m.frame])),p=[];for(let m of s.parts){let g=f.get(m.member),v=u.get(m.member);!g||!v||p.push({nodeId:m.node,prop:"x",from:m.frame.x,to:m.frame.x+(g.x-v.x)},{nodeId:m.node,prop:"y",from:m.frame.y,to:m.frame.y+(g.y-v.y)})}return p}function Fe(s,f=[],u=r){ke=u,we=f,he=r,T=s,Q=[],M=Er(r),L=Ae(r),U=ze,S=Np(s)?vl(r,L,Rp(s)):[]}function Np(s){return s.kind==="move"||s.kind==="resize"||s.kind==="scale"||s.kind==="create"}function Rp(s){return s.kind==="move"||s.kind==="scale"?new Set(te()):s.kind==="resize"?new Set([s.id]):new Set}function Kr(s){return s.metaKey||s.ctrlKey?0:yl/A.getCamera().zoom}function vt(s){let f=[...we,...Q];T=null,Q=[],we=[],w=null,$=null,U=ze,r=ke,A.update(r),ue(f,s),Y()}function Ip(){let s=Q.length>0?ve(he,Q).document:he,f=new Set(te().flatMap(m=>Sd(m,s))),u=[];for(let m of te()){let g=V(s.root,m),v=nt(s.root,m);if(!g||!v)continue;let C=Ee(m);if(!C)continue;let O={x:C.x+C.w/2,y:C.y+C.h/2},F=Gn(O,f)??r.root.id;if(F===v.id)continue;let j=V(s.root,F);if(!j||!ce(j))continue;u.push({op:"move",id:m,parent:F,index:de(j).length});let K={x:It(v.id).x-It(F).x,y:It(v.id).y-It(F).y};if(!(K.x===0&&K.y===0))for(let ae of rr(m,s)){let Z=yt(ae);Z&&(u.push({op:"set",id:ae,prop:"x",value:re(Z.x+K.x)}),u.push({op:"set",id:ae,prop:"y",value:re(Z.y+K.y)}))}}if(u.length===0)return[];let p=ve(s,u).document;return[...u,...Hr(s,p,f)]}function Sd(s,f){let u=V(f.root,s);if(!u)return[];let p=[];return oe(u,m=>{p.push(m.id)}),p}function Pa(){if(!T)return;T=null,Q=[],w=null,$=null,U=ze;let s=we.length>0;r=ke,we=[],s&&le(n.filter(f=>V(r.root,f))),A.update(r),Y()}let Fp=5,Qn=8;function _d(s,f=r,u=A.getResolution()){let p=V(f.root,s),m=u.nodes.get(s);if(p?.type!=="vector"||!m)return;let g={x:m.absX,y:m.absY,w:Math.max(0,m.w),h:Math.max(0,m.h)};return{node:p,view:fn(p.view,g.w,g.h),box:g}}function Gr(s,f=r,u=A.getResolution()){let p=_d(s,f,u);if(p)return ct(sn(p.node.d).contours,un(p.view,p.box))}function bt(s,f,u,p=r,m=A.getResolution()){let g=_d(s,p,m);if(!g)return[];let{node:v,view:C,box:O}=g,F=ct(f,os(C,O)),j=[],K=(Ga,cf,bh)=>{cf!==bh&&j.push({op:"set",id:s,prop:Ga,value:cf})};K("d",ut(F),v.d);let ae=[v.x,v.y,v.w,v.h].every(Ga=>typeof Ga=="number"),Z=Xt(F),ge=Xt(f);if(!u||!ae||!Z||!ge)return j;let kt=O.x-v.x,Qr=O.y-v.y;return K("view",Yt(Z),v.view),K("x",re(ge.x-kt),v.x),K("y",re(ge.y-Qr),v.y),K("w",re(ge.w),v.w),K("h",re(ge.h),v.h),j}function Ht(s){return V(r.root,s)?.type!=="vector"||!Ft(s)?!1:(I&&lr("done"),X&&eo(),le([s]),z={id:s,picked:new Set},o!=="select"&&wt("select"),je(null),Y(),!0)}function Wr(){z&&(z=null,Y())}function Bp(){if(X){let u=X.contours[X.contour],p=u?.anchors??[],m=p[p.length-1],g=p[0],v=X.hover,C=v!==null&&g!==void 0&&p.length>=2&&!u?.closed&&Xr(g,v)<=Qn;return{contours:X.contours,anchors:p.map((O,F)=>({key:Me(X?.contour??0,F),at:O,selected:F===p.length-1})),handles:m?gi(X.contours,new Set([Me(X.contour,p.length-1)])):[],pending:m&&v&&!X.dragging&&!u?.closed?{from:m,...m.out?{c1:m.out}:{},to:v}:null,closeAt:C?g:null}}if(!z)return null;let s=Gr(z.id);if(!s)return null;let f=new Set(mi(s,z.picked));return{contours:s,anchors:s.flatMap((u,p)=>u.anchors.map((m,g)=>({key:Me(p,g),at:m,selected:f.has(Me(p,g))}))),handles:gi(s,f)}}function Xr(s,f){return Math.hypot(s.x-f.x,s.y-f.y)*A.getCamera().zoom}function Hp(s,f,u,p){if(!z)return!1;let m=z.id,g=Gr(m);if(!g)return z=null,!1;s.preventDefault(),Ke(s.pointerId);let v=G.hitPath(f);if(v?.kind==="handle"){let O=Ou(v.key),F=O?g[O.contour]?.anchors[O.index]:void 0;if(O&&F)return Fe({kind:"pathHandle",pointerId:s.pointerId,id:m,start:g,contour:O.contour,index:O.index,side:O.side,smooth:zo(F),last:g}),!0}if(v?.kind==="anchor")return s.altKey?(z.picked=new Set([v.key]),ue(bt(m,Du(g,v.key),!1),"Convert point"),!0):(s.shiftKey?z.picked.has(v.key)?z.picked.delete(v.key):z.picked.add(v.key):z.picked.has(v.key)||(z.picked=new Set([v.key])),Fe({kind:"points",pointerId:s.pointerId,id:m,origin:u,start:g,keys:new Set(z.picked),lead:v.key,moved:!1,last:g}),Y(),!0);let C=ss(g,u);if(C&&C.distance*A.getCamera().zoom<=Fp){if(p>=2){let K=is(g,C.contour,C.segment,C.t);return z.picked=new Set([Me(C.contour,C.segment+1)]),ue(bt(m,K,!1),"Add point"),!0}let O=g[C.contour],F=O.anchors[C.segment],j=O.anchors[(C.segment+1)%O.anchors.length];return Fe({kind:"segment",pointerId:s.pointerId,id:m,origin:u,start:g,contour:C.contour,segment:C.segment,t:C.t,straight:!F?.out&&!j?.in,last:g}),!0}return Fe({kind:"pointMarquee",pointerId:s.pointerId,origin:u,current:u,additive:s.shiftKey}),!0}function Up(s,f,u,p){let m=hi(s.start,s.lead);if(!m||p===0)return{dx:f,dy:u};let g=m.x+f,v=m.y+u,C=p,O=p,F=f,j=u;return s.start.forEach((K,ae)=>K.anchors.forEach((Z,ge)=>{s.keys.has(Me(ae,ge))||(Math.abs(Z.x-g)<C&&(C=Math.abs(Z.x-g),F=Z.x-m.x),Math.abs(Z.y-v)<O&&(O=Math.abs(Z.y-v),j=Z.y-m.y))})),{dx:F,dy:j}}function Vp(s,f){if(!T)return!1;let u=(p,m)=>{L&&Oa(bt(m,p,!1,he,L))};switch(T.kind){case"points":{let p=f;s.shiftKey&&(p=Tn(T.origin,f));let m={dx:p.x-T.origin.x,dy:p.y-T.origin.y};if(!T.moved&&Math.hypot(m.dx,m.dy)*A.getCamera().zoom<Pt)return!0;T.moved=!0;let{dx:g,dy:v}=s.shiftKey?m:Up(T,m.dx,m.dy,Kr(s));return T.last=Ko(T.start,T.keys,g,v),u(T.last,T.id),!0}case"pathHandle":{let p=T.start[T.contour]?.anchors[T.index],m=s.shiftKey&&p?Tn(p,f):f;return T.last=qo(T.start,T.contour,T.index,T.side,m,{smooth:T.smooth,breakSmooth:s.altKey}),u(T.last,T.id),!0}case"segment":return T.last=Nu(T.start,T.contour,T.segment,T.t,f.x-T.origin.x,f.y-T.origin.y,T.straight),u(T.last,T.id),!0;case"pointMarquee":return T.current=f,Y(),!0;default:return!1}}function zp(s){if(!T)return!1;switch(T.kind){case"points":case"pathHandle":case"segment":{let f=T.kind!=="points"||T.moved,u=T.kind==="points"?T.keys.size===1?"Move point":"Move points":T.kind==="pathHandle"?"Adjust curve":"Reshape";return Q=f&&L?bt(T.id,T.last,!0,he,L):[],vt(u),!0}case"pointMarquee":{let f=tr(T.origin,T.current),u=T.additive;if(T=null,U=ze,!z)return!0;let p=A.getCamera().zoom;if(f.w*p<Pt&&f.h*p<Pt){if(A.hitTest(s)===z.id)z.picked=new Set;else{Wr();let v=Wn(s);le(v===null?[]:[v])}return Y(),!0}let m=Gr(z.id)??[],g=xi(m).filter(v=>{let C=hi(m,v);return C!==void 0&&et(f,C.x,C.y)});return z.picked=new Set(u?[...z.picked,...g]:g),Y(),!0}default:return!1}}function qp(s){if(!z)return!1;let f=z.id,u=s.metaKey||s.ctrlKey;if(s.key==="Escape"||s.key==="Enter"&&!u)return s.preventDefault(),T?Pa():Wr(),!0;let p=Gr(f);if(!p)return!1;let m=new Set(mi(p,z.picked));if(s.key==="Delete"||s.key==="Backspace"){if(s.preventDefault(),m.size===0)return!0;let O=Pu(p,m);return z.picked=new Set,O.length===0?(Wr(),cr(),!0):(ue(bt(f,O,!0),m.size===1?"Delete point":"Delete points"),!0)}let g=s.shiftKey?10:1,C={ArrowLeft:[-g,0],ArrowRight:[g,0],ArrowUp:[0,-g],ArrowDown:[0,g]}[s.key];return C&&!u?(s.preventDefault(),m.size>0&&ue(bt(f,Ko(p,m,C[0],C[1]),!0),"Nudge points"),!0):u&&s.key.toLowerCase()==="a"?(s.preventDefault(),z.picked=new Set(xi(p)),Y(),!0):u&&!s.shiftKey&&s.code==="KeyJ"?(s.preventDefault(),ue(bt(f,Ru(p,m),!0),"Close path"),!0):!1}function jp(s,f){if(s.preventDefault(),Ke(s.pointerId),!X){X=Kp(f)??{contours:[{closed:!1,anchors:[{x:f.x,y:f.y}]}],contour:0,target:null,hover:null,dragging:null};let v=X.contours[X.contour];X.dragging={pointerId:s.pointerId,index:v.anchors.length-1,origin:f},Y();return}let u=X.contours[X.contour],p=u.anchors[0],m=u.anchors[u.anchors.length-1];if(p&&u.anchors.length>=2&&Xr(p,f)<=Qn){X.contours[X.contour]={...u,closed:!0},X.dragging={pointerId:s.pointerId,index:0,origin:p},Y();return}let g=s.shiftKey&&m?Tn(m,f):f;X.contours[X.contour]={...u,anchors:[...u.anchors,{x:g.x,y:g.y}]},X.dragging={pointerId:s.pointerId,index:u.anchors.length,origin:g},Y()}function Kp(s){let f=n.length===1?n[0]:null;if(f===null||!Ft(f))return null;let u=Gr(f);if(!u)return null;for(let p=0;p<u.length;p+=1){let m=u[p];if(m.closed||m.anchors.length<1)continue;let g=m.anchors[0],v=m.anchors[m.anchors.length-1],C=Xr(v,s)<=Qn,O=!C&&Xr(g,s)<=Qn;if(!C&&!O)continue;let F=[...u];return O&&(F[p]=Iu(m)),{contours:F,contour:p,target:f,hover:null,dragging:null}}return null}function Gp(s,f){if(!X)return;let u=X.dragging;if(!u||u.pointerId!==s.pointerId){let O=X.contours[X.contour],F=O?.anchors[O.anchors.length-1];X.hover=s.shiftKey&&F?Tn(F,f):f,Y();return}if(Xr(u.origin,f)<Pt)return;let p=X.contours[X.contour],m=p.anchors[u.index];if(!m)return;let g={x:2*m.x-f.x,y:2*m.y-f.y},v=s.altKey?m.in:g,C=[...p.anchors];C[u.index]={x:m.x,y:m.y,...v?{in:v}:{},out:f},X.contours[X.contour]={...p,anchors:C},Y()}function Wp(s){!X?.dragging||X.dragging.pointerId!==s.pointerId||(Ka(s.pointerId),X.dragging=null,X.contours[X.contour]?.closed?eo():Y())}function eo(){if(!X)return;let s=X;X=null;let f=s.contours[s.contour];if(!f||f.anchors.length<2){Y();return}if(s.target!==null){ue(bt(s.target,s.contours,!0),"Extend path"),wt("select"),Ht(s.target);return}let u=Xt(s.contours),p=f.anchors[0];if(!u)return;let m=Gn(p)??b??r.root.id,g=V(r.root,m)??r.root,v=It(m),C=ct(s.contours,F=>({x:F.x-u.x,y:F.y-u.y})),O=Kt(r.root,"path");ue([{op:"insert",parent:m,index:de(g).length,node:fo({id:O,x:re(u.x-v.x),y:re(u.y-v.y),w:re(u.w),h:re(u.h),view:Yt({x:0,y:0,w:u.w,h:u.h}),d:ut(C),fill:"none",stroke:t.defaultStroke??"#1f2937",strokeWidth:2,cap:"round",join:"round"})}],"Draw path"),wt("select"),Ht(O)}function Na(s=te()){let f=[],u=[];for(let p of s){let m=V(r.root,p),g=nt(r.root,p),v=lt(p);if(!m||!g||!v||m.type!=="rect"&&m.type!=="ellipse")continue;let C=Math.max(0,v.w),O=Math.max(0,v.h),F=m.type==="rect"?ls(C,O,v.values.radius??0):ds(C,O),j=fo({id:p,...m.name===void 0?{}:{name:m.name},x:m.x,y:m.y,w:m.w,h:m.h,view:Yt({x:0,y:0,w:C,h:O}),d:ut(F),...m.fill===void 0?{}:{fill:m.fill},...m.stroke===void 0?{}:{stroke:m.stroke},...m.strokeWidth===void 0?{}:{strokeWidth:m.strokeWidth},...m.opacity===void 0?{}:{opacity:m.opacity},...m.hidden?{hidden:!0}:{},...m.locked?{locked:!0}:{}}),K=g.children.findIndex(ae=>ae.id===p);f.push({op:"remove",id:p},{op:"insert",parent:g.id,index:K,node:j}),u.push(p)}u.length!==0&&(ue(f,u.length===1?"Convert to vector":`Convert ${u.length} to vector`),le(u),u.length===1&&Ht(u[0]))}function Cd(){return te().filter(s=>{let f=V(r.root,s)?.type;return f==="rect"||f==="ellipse"}).length}let Xp=450,Ed=4,Yr={x:0,y:0,at:0,count:0};function Yp(s){let f=Date.now(),p=Math.abs(s.x-Yr.x)<=Ed&&Math.abs(s.y-Yr.y)<=Ed&&f-Yr.at<=Xp?Yr.count+1:1;return Yr={x:s.x,y:s.y,at:f,count:p},p}let Ad=s=>{if(s.button!==0||x)return;let f=A.pointerPoint(s),u=A.screenToDocument(f);W=u;let p=Yp(f);if(I){let O=$a(u),F=A.itemOf(I.id),j=qr(I.id,u);if(O&&F&&et(F,j.x,j.y)){s.preventDefault(),Ke(s.pointerId),tt=!0,p>=3?I.selectLineAt(O):p===2?I.selectWordAt(O):I.pointTo(O,s.shiftKey),ie.focus({preventScroll:!0}),Y();return}lr("blur")}if(e.focus({preventScroll:!0}),o==="select"&&(s.metaKey||s.ctrlKey)&&ip(u)){s.preventDefault();return}if(o==="pen"){jp(s,u);return}if(z&&o==="select"&&Hp(s,f,qr(z.id,u),p))return;if(o!=="select"){s.preventDefault(),Ke(s.pointerId),Fe({kind:"create",pointerId:s.pointerId,origin:u,current:u}),Y();return}let m=te().length===1?te()[0]:null;if(m!==null){let O=V(r.root,m),F=G.hitAdjuster(f),j=O&&F?Xo(O,F.id):void 0,K=j?Ee(m):void 0;if(j&&K&&F){s.preventDefault(),Ke(s.pointerId),Fe({kind:"adjust",pointerId:s.pointerId,id:m,adjuster:j,handleId:F.id,frame:K,from:lt(m)?.values[j.prop]??0});return}let ae=O&&!ce(O)?G.hitHandle(f):null,Z=ae?yt(m):void 0,ge=Z?Nt(m):void 0;if(ae&&Z&&ge){s.preventDefault(),Ke(s.pointerId),Fe({kind:"resize",pointerId:s.pointerId,origin:u,id:m,handle:ae.handle,frame:Z,offset:{x:ge.x-Z.x,y:ge.y-Z.y},rotation:Rt(m)});return}}let g=te().length>0?G.hitHandle(f):null;if(g&&Ep(u,g.handle,s.pointerId)){s.preventDefault();return}let v=G.hitPageLabel(f);if(v!==null){if(s.preventDefault(),b=null,s.shiftKey){le(n.includes(v)?n.filter(O=>O!==v):[...n,v]);return}if(n.includes(v)||le([v]),p===2){bp(v);return}Md(u,s.pointerId,s.altKey);return}if(te().length>0&&G.hitRotate(f)!==null&&Cp(u,s.pointerId)){s.preventDefault();return}if(te().length>1){let O=G.hitRing(f);if(O!==null&&Op(O,u,s.pointerId)){s.preventDefault();return}let F=G.hitSpacer(f);if(F!==null&&Mp(F,u,s.pointerId)){s.preventDefault();return}}let C=Wn(u);if(C===null){s.preventDefault(),Ke(s.pointerId),b=null,s.shiftKey||le([]),Fe({kind:"marquee",pointerId:s.pointerId,origin:u,current:u});return}b!==null&&!De(r.root,C).includes(b)&&(b=null),s.shiftKey?le(n.includes(C)?n.filter(O=>O!==C):[...n,C]):n.includes(C)||le([C]),Md(u,s.pointerId,s.altKey)&&s.preventDefault()};function Md(s,f,u){let p=r,m=[];if(u){let v=Xd({x:0,y:0});v&&(m=v.ops,r=ve(r,m).document,A.update(r),le(v.ids))}let g=new Map;for(let v of te())for(let C of rr(v,r)){let O=yt(C);O&&g.set(C,O)}return g.size===0?(r=p,A.update(r),!1):(Ke(f),Fe({kind:"move",pointerId:f,origin:s,frames:g,bounds:Qe(te().flatMap(v=>Ee(v)??[]))},m,p),!0)}let $d=s=>{let f=A.pointerPoint(s);if(W=A.screenToDocument(f),tt&&I){let p=$a(W);p&&I.pointTo(p,!0);return}if(X&&o==="pen"){Gp(s,W);return}if(!T){eh(f);return}if(T.pointerId!==s.pointerId)return;let u=W;if(!Vp(s,z?qr(z.id,u):u))switch(T.kind){case"move":{let p=u.x-T.origin.x,m=u.y-T.origin.y;if(T.bounds){let v={...T.bounds,x:T.bounds.x+p,y:T.bounds.y+m};U=bl(v,S,Kr(s)),p+=U.dx,m+=U.dy}let g=[];for(let[v,C]of T.frames)g.push({nodeId:v,prop:"x",from:C.x,to:C.x+p}),g.push({nodeId:v,prop:"y",from:C.y,to:C.y+m});Bt(g);return}case"resize":{let{id:p,handle:m,frame:g,origin:v,offset:C,rotation:O}=T,F=u.x-v.x,j=u.y-v.y;if(O!==0){U=ze;let Z=Mu(g,m,F,j,O);Bt(Vo(g,Z).map(ge=>({nodeId:p,prop:ge,from:g[ge],to:Z[ge]})));return}let K=ht(g,m,F,j);U=ra({...K,x:K.x+C.x,y:K.y+C.y},m,S,Kr(s)),F+=U.dx,j+=U.dy;let ae=ht(g,m,F,j);Bt(Vo(g,ae).map(Z=>({nodeId:p,prop:Z,from:g[Z],to:ae[Z]})));return}case"scale":{let{handle:p,bounds:m,origin:g,frames:v,offsets:C}=T,O=u.x-g.x,F=u.y-g.y,j=ht(m,p,O,F);U=ra(j,p,S,Kr(s)),O+=U.dx,F+=U.dy,Bt(wd({bounds:m,frames:v,offsets:C},ht(m,p,O,F)));return}case"space":$p(T,u);return;case"reorder":Dp(T,u,s.metaKey||s.ctrlKey);return;case"rotate":{let{centre:p,origin:m,targets:g}=T,v=g[0],C=$u(p,m,u,v?.rotation??0,s.shiftKey?Jg:void 0);$=gn((v?.rotation??0)+C);let O=[],F=g.length===1;for(let j of Tu(g,p,C)){let K=g.find(ae=>ae.id===j.id);K&&(O.push({nodeId:j.id,prop:"rotation",from:K.rotation,to:j.rotation}),!F&&O.push({nodeId:j.id,prop:"x",from:K.frame.x-K.offset.x,to:re(j.frame.x-K.offset.x)},{nodeId:j.id,prop:"y",from:K.frame.y-K.offset.y,to:re(j.frame.y-K.offset.y)}))}Bt(O);return}case"adjust":{let p=T.adjuster.valueAt(T.frame,T.handleId,u);w=p,Bt([{nodeId:T.id,prop:T.adjuster.prop,from:T.from,to:p}]);return}case"create":{U=wl(u,S,Kr(s));let p={x:u.x+U.dx,y:u.y+U.dy};T.current=s.shiftKey&&o!=="text"?ey(T.origin,p):p,Y();return}case"marquee":{T.current=u,Y();return}}},to=s=>{if(tt){tt=!1,Ka(s.pointerId),ie.focus({preventScroll:!0});return}if(X){Wp(s);return}if(!T||T.pointerId!==s.pointerId)return;Ka(s.pointerId);let f=A.screenToDocument(A.pointerPoint(s));if(!zp(z?qr(z.id,f):f))switch(T.kind){case"create":{let u=tr(T.origin,T.current),p=o==="text"?"text":o==="frame"?"frame":o==="ellipse"?"ellipse":"rect";T=null,U=ze,Y();let m=u.w<Pt||u.h<Pt;if(m&&p!=="text")return;let g=m?{x:u.x,y:u.y,w:Nc.w,h:Nc.h}:u,v=Gn({x:g.x,y:g.y})??b??r.root.id,C=V(r.root,v)??r.root,O=It(v),F={x:Math.round(g.x-O.x),y:Math.round(g.y-O.y),w:Math.round(g.w),h:Math.round(g.h)},j=Kt(r.root,p);ue([{op:"insert",parent:v,index:de(C).length,node:p==="text"?Qa({...F,id:j,content:""}):p==="frame"?Xa({...F,id:j,background:Yg,children:[]}):p==="ellipse"?Wa({...F,id:j,fill:t.defaultFill??"#3b82f6"}):Za({...F,id:j,fill:t.defaultFill??"#3b82f6"})}],Qg[p]),le([j]),wt("select"),p==="text"&&jr(j);return}case"marquee":{let u=tr(T.origin,T.current),p=s.shiftKey;if(T=null,U=ze,u.w>=Pt||u.h>=Pt){let m=vh(u);le(p?[...new Set([...n,...m])]:m)}Y();return}case"move":{let u=Ip();u.length>0&&(Q=[...Q,...u]),vt(we.length>0?"Duplicate":"Move");return}case"resize":vt("Resize");return;case"scale":vt(n.length===1?"Resize group":`Resize ${n.length} elements`);return;case"space":vt("Spacing");return;case"reorder":vt(T.swap?"Swap":"Reorder");return;case"adjust":vt("Corner radius");return;case"rotate":vt("Rotate");return}},Td=s=>{if(ka(s.target))return;if(I){if(!((s.metaKey||s.ctrlKey)&&s.key.toLowerCase()==="z"))return;s.preventDefault(),I.breakBurst(),s.shiftKey?ao():Zr();return}if(X&&(s.key==="Enter"||s.key==="Escape")){s.preventDefault(),eo();return}if(qp(s))return;if((s.metaKey||s.ctrlKey)&&s.shiftKey&&s.code==="KeyO"){if(Cd()===0)return;s.preventDefault(),Na();return}if(s.key==="Enter"&&!Ic(s)&&n.length===1){let p=n[0];if(V(r.root,p)?.type==="vector"&&Ht(p)){s.preventDefault();return}}if(s.key==="Enter"&&!Ic(s)&&n.length===1){let p=n[0];if(V(r.root,p)?.type==="text"){s.preventDefault(),jr(p);return}}if(s.code==="Space"&&!x){x=!0,Le($e("grab"));return}let f=s.metaKey||s.ctrlKey;if(f&&s.key.toLowerCase()==="z"){s.preventDefault(),s.shiftKey?ao():Zr();return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyL"){if(!P.lock||n.length===0)return;s.preventDefault(),ur(n,"locked");return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyH"){if(!P.hide||n.length===0)return;s.preventDefault(),ur(n,"hidden");return}if(f&&s.key.toLowerCase()==="g"){s.preventDefault(),s.shiftKey?Va():Ua();return}if(f&&s.key.toLowerCase()==="a"){s.preventDefault(),qa();return}if(f&&!s.altKey&&s.key.toLowerCase()==="d"){s.preventDefault(),Ba();return}if(s.altKey){let p=ty[s.code];if(p&&!f){s.preventDefault(),jd(p);return}let m=ry[s.code];if(m&&s.ctrlKey){s.preventDefault(),Gd(m);return}}if(s.key==="]"||s.key==="["){if(n.length===0)return;s.preventDefault();let p=s.key==="]";za(f?p?"front":"back":p?"forward":"backward");return}if(s.key==="Escape"){T?Pa():b!==null?tf():le([]);return}if(s.key==="Delete"||s.key==="Backspace"){if(n.length===0)return;s.preventDefault(),cr();return}let u=f||s.altKey?void 0:Zl[s.key.toLowerCase()];u&&wt(u)};function Ld(){if(!I)return null;let s=V(r.root,I.id);if(s?.type!=="text")return null;let{anchor:f,head:u}=I.getSelection();return f===u?null:sr(zl(s.content,f,u))}let Od=s=>{if(ka(s.target))return;let f=Ld()??Jr();f!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",f))},Dd=s=>{if(ka(s.target))return;let f=Ld();if(f!==null&&I){s.preventDefault(),s.clipboardData?.setData("text/plain",f);let{anchor:p,head:m}=I.getSelection();I.breakBurst(),I.setSelection(p,m),I.handleInput({inputType:"deleteByCut",data:null});return}let u=Jr();u!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",u),cr())},Pd=s=>{if(ka(s.target))return;s.preventDefault();let f=yi(s.clipboardData);if(f&&!I){let p=dh();p?Fa(p,f):Jd(f,W??void 0);return}let u=s.clipboardData?.getData("text/plain")||void 0;if(I&&u!==void 0){I.handleInput({inputType:"insertFromPaste",data:u});return}Ia(u)},Nd=s=>{s.code==="Space"&&(x=!1,Le($e(Ma())))},Rd=s=>{if(!me)return;s.preventDefault(),T&&Pa();let f=A.pointerPoint(s),u=A.screenToDocument(f),p=Wn(u),m=Jp(u),g=A.hitTest(u),v=g!==null&&n.some(O=>De(r.root,g).includes(O));p===null?v||le([]):n.includes(p)||le([p]);let C=(t.menuExtras?.(n)??[]).map(O=>"separator"in O?O:{...O,id:`${ed}${O.id}`});me.open(f,El(Zp(m),C))};function Jp(s){let{locked:f}=Re(),u=[];for(let p of[...A.getScene().items].reverse()){if(!f.has(p.id)||!A.hitTest(s,g=>g===p.id))continue;let m=en(r.root,p.id,"locked");m!==void 0&&!u.includes(m)&&u.push(m)}return u}function Zp(s=[]){let f=n.length===1?V(r.root,n[0]):void 0,u=[];if(f){let p=f;for(let m of rt(f)){let g=p[m];g===void 0||!pe(g)||To(g).kind!=="literal"&&u.push({prop:m,source:`=${g.expr}`})}}return{count:n.length,hasGroup:n.some(p=>{let m=V(r.root,p);return m!==void 0&&Se(m)}),canPaste:td!==null,isText:n.length===1&&V(r.root,n[0])?.type==="text",isVector:te().length===1&&V(r.root,te()[0])?.type==="vector",convertible:Cd(),bound:u,lock:P.lock?n.every(p=>Re().locked.has(p))?"unlock":"lock":null,hide:P.hide?n.every(p=>Re().hidden.has(p))?"show":"hide":null,locksHere:s,anyLocked:ja("locked").length>0,hiddenCount:ja("hidden").length}}function Qp(s){if(e.focus({preventScroll:!0}),s.startsWith(ed)){t.onMenuCommand?.(s.slice(ed.length),[...n]);return}if(s.startsWith("unlock:")){fr([s.slice(7)],"locked",!1);return}if(s.startsWith("detach:")){let f=s.slice(7),u=n[0];u!==void 0&&of(u,f);return}switch(s){case"copy":Jr();return;case"cut":Yd();return;case"editText":{let f=n[0];f!==void 0&&jr(f);return}case"editPoints":{let f=n[0];f!==void 0&&Ht(f);return}case"toVector":return Na();case"duplicate":return Ba();case"paste":return Ia();case"group":return Ua();case"ungroup":return Va();case"front":case"forward":case"backward":case"back":return za(s);case"delete":return cr();case"selectAll":return qa();case"toggleLock":return ur(n,"locked");case"toggleHidden":return ur(n,"hidden");case"unlockAll":return oo("locked");case"showAll":return oo("hidden");case"fit":return A.fitToContent();case"zoom100":return A.setCamera({...A.getCamera(),zoom:1})}}let Id=s=>{if(o!=="select"||x||z)return;let f=A.screenToDocument(A.pointerPoint(s)),u=A.hitTest(f,C=>!Re().locked.has(C));if(u===null)return;let p=no().find(C=>C.id===u);if(p){s.preventDefault(),fh(p);return}let m=V(r.root,u);if(m?.type==="text"){s.preventDefault(),jr(u,f);return}if(m?.type==="vector"){s.preventDefault(),Ht(u);return}let g=De(r.root,u),v=b===null?1:g.indexOf(b)+1;for(let C=Math.max(v,1);C<g.length;C+=1){let O=g[C];if(O===void 0)break;let F=V(r.root,O);if(!(!F||!Se(F))){s.preventDefault(),ef(O),le([g[C+1]??O]);return}}},Fd=s=>Array.from(s.dataTransfer?.types??[]).includes("Files"),Bd=s=>{if(!Fd(s)||!t.importImage)return;s.preventDefault(),s.dataTransfer&&(s.dataTransfer.dropEffect="copy");let f=A.screenToDocument(A.pointerPoint(s)),u=Zd(f)?.id??null;u!==c&&(c=u,Y())},Hd=s=>{s.relatedTarget instanceof Node&&e.contains(s.relatedTarget)||c!==null&&(c=null,Y())},Ud=s=>{if(!Fd(s)||!t.importImage)return;s.preventDefault();let f=A.screenToDocument(A.pointerPoint(s)),u=Zd(f);c=null,Y();let p=Array.from(s.dataTransfer?.files??[]).find(m=>m.type.startsWith("image/"));p&&(u?Fa(u,p):Jd(p,f))},Vd=()=>{W=null,l=null,!T&&(a===null&&H===null&&q===null||(a=null,H=null,q=null,Y()))};function zd(){let s=te().length===1?te()[0]:void 0,f=s===void 0?void 0:V(r.root,s);return s!==void 0&&f&&!ce(f)?Rt(s):0}function eh(s){if(x){Le($e("grab"));return}if(z){je(null),Le($e("arrow"));return}if(o!=="select"){je(null),Ra(null),ro(null),Le($e(o==="text"?"text":"crosshair"));return}let f=te().length===1?te()[0]:null;if(f!==null){let g=G.hitAdjuster(s);if(g){let v=V(r.root,f),C=v?Xo(v,g.id):void 0;je(null),Ra(C?{id:g.id,prop:C.prop}:null),Le($e("radius",{badge:C?Aa(f,[C.prop]):"none"}));return}Ra(null)}if(te().length>0){let g=G.hitHandle(s);if(g){je(null);let O=Uo(g.handle);Le($e("resize",{angle:fi(g.handle)+zd(),badge:hd(zr(),O)}));return}let v=G.hitPageLabel(s);if(v!==null){je(v),Le($e("arrow"));return}let C=G.hitRotate(s);if(C!==null){je(null),Le($e("rotate",{angle:Zg[C]+zd()}));return}}let u=G.hitPageLabel(s);if(u!==null){l=null,je(u),Le($e("arrow"));return}if(te().length>1){if(G.hitRing(s)!==null){je(null),ro(null),Le($e("grab"));return}let v=G.hitSpacer(s),C=v===null?null:ca(v);if(v!==null&&C){je(null),ro(v),Le($e("resize",{angle:C.axis==="x"?0:90,badge:hd(zr(),[C.axis])}));return}ro(null)}let p=A.screenToDocument(s),m=Wn(p);l=th(p,m),je(m),Y(),Le($e("arrow",{badge:m===null?"none":Aa(m,["x","y"])}))}function th(s,f){let u=A.hitTest(s);if(u===null||!Re().locked.has(u))return null;let p=en(r.root,u,"locked");return p===void 0?null:f===null||De(r.root,p).includes(f)?p:null}function je(s){a!==s&&(a=s,Y())}function Ra(s){H?.id!==s?.id&&(H=s,Y())}function ro(s){q!==s&&(q=s,Y())}function Le(s){e.style.cursor!==s&&(e.style.cursor=s)}function wt(s){o!==s&&(o=s,X&&s!=="pen"&&eo(),s!=="select"&&Wr(),se?.setTool(o),s!=="select"&&je(null),Le($e(Ma())),Ye("tool",o))}function rh(s){if(s.length===0)return null;if(s.length>1)return Qe(s.map(p=>p.frame))??null;let f=s[0],u=nt(r.root,f.id);return u?nr(u.id,r,A.getResolution())??null:null}function qd(s,f,u){let p=Fr(r,Da(Xn(n),s,f));p.length!==0&&ue([...p,...Br(r,p,Er(r),Ae(r))],u)}function jd(s){let f=Nn(r,n,A.getResolution()),u=rh(f);u&&qd(Wo(s),vi(f,u,s),ny[s])}function Kd(s){let f=Nn(r,n,A.getResolution());if(f.length<3)return null;let u=Il(f,s),p=Fl(u);return p===null?null:{gap:p,series:u}}function Gd(s){let f=Kd(s);f&&qd(s,ha(f.series,f.gap),s==="x"?"Distribute horizontally":"Distribute vertically")}function nh(){let s=Pn(r,n);if(s.length===0)return null;let f=A.getResolution(),u={};for(let p of s)oe(p,m=>{let g=f.nodes.get(m.id)?.values;g&&(u[m.id]=g)});return{nodes:s,tokens:r.tokens,fonts:r.fonts,resolved:u}}function oh(s){return new Map(Object.entries(s.resolved))}function ah(s){let f=Object.entries(s.tokens).filter(([u])=>r.tokens[u]===void 0).map(([u,p])=>({op:"setToken",name:u,value:p}));for(let[u,p]of Object.entries(s.fonts))r.fonts[u]===void 0&&f.push({op:"setFont",name:u,family:p});return f}function Wd(s,f,u){let{nodes:p,remap:m}=cl(s,r);if(p.length===0)return null;let g=ah(s),v=g.length>0?ve(r,g).document:r;p.forEach((F,j)=>{let K=s.nodes[j];if(!K)return;let ae=f(K,j,v),Z={op:"insert",parent:ae.parent,index:ae.index,node:F};g.push(Z),v=ve(v,[Z]).document});let C=Ql(v,m,oh(s),u);C.length>0&&(v=ve(v,C).document);let O=sh(p);return{ops:[...g,...C,...Hr(r,v)],ids:[...m.values()].filter(F=>O.has(F))}}function sh(s){let f=new Set;for(let u of s)f.add(u.id);return f}function Xd(s){let f=nh();return f?Wd(f,(u,p,m)=>{let g=nt(m.root,u.id)??m.root,v=de(g).findIndex(C=>C.id===u.id);return{parent:g.id,index:v===-1?de(g).length:v+1}},s):null}function Jr(){let s=fl(r,n,A.getResolution());return s!==null&&(td=s),s}function Yd(){let s=Jr();return s!==null&&cr(),s}function ih(s){let f=[];for(let u of s.nodes){let p=s.resolved[u.id];if(!p)continue;let{x:m,y:g,w:v,h:C}=p;m===void 0||g===void 0||v===void 0||C===void 0||f.push({x:m,y:g,w:v,h:C})}return Qe(f)??null}function Ia(s,f){let u=ul(s??td??"");if(!u)return;let p=f??W,m=ih(u),g=p&&m?{x:p.x-(m.x+m.w/2),y:p.y-(m.y+m.h/2)}:{x:wa,y:wa},v=b??r.root.id,C=Wd(u,(O,F,j)=>({parent:v,index:de(V(j.root,v)??j.root).length}),g);C&&(ue(C.ops,C.ids.length===1?"Paste":`Paste ${C.ids.length} elements`),le(C.ids))}async function Jd(s,f){let u=t.importImage;if(!u)return;let p=await Go(s,t.maxImageEdge??2560);if(!p)return;let m=await u(new File([p.bytes],s.name,{type:p.type}));if(!m)return;let g=(f?Gn(f):void 0)??b??r.root.id,v=V(r.root,g)??r.root,C=It(g),O=A.getResolution().nodes.get(g),{w:F,h:j}=Fu(p.width,p.height,O?.w&&O.w>0?O.w:p.width,O?.h&&O.h>0?O.h:p.height),K=f??W,ae=Math.round((K?K.x-F/2:C.x)-C.x),Z=Math.round((K?K.y-j/2:C.y)-C.y),ge=uh(r,s.name),kt=Kt(r.root,"image");ue([{op:"setAsset",name:ge,value:m},{op:"insert",parent:g,index:de(v).length,node:Ja({id:kt,x:ae,y:Z,w:F,h:j,src:ge,fit:"cover"})}],"Place image"),le([kt])}function no(){return t.importImage?wc(r,Re().hidden):[]}function lh(){return no().flatMap(s=>{let f=Ee(s.id);return f?[{frame:f,label:s.label,target:s.id===c}]:[]})}function Zd(s){return no().filter(u=>{let p=Ee(u.id);return p!==void 0&&et(p,s.x,s.y)}).at(-1)??null}function dh(){return n.length!==1?null:no().find(s=>s.id===n[0])??null}async function Fa(s,f){let u=t.importImage;if(!u)return;let p=await Go(f,t.maxImageEdge??2560);if(!p)return;let m=await u(new File([p.bytes],f.name,{type:p.type}));!m||r.assets[s.src]!==void 0||(ue([{op:"setAsset",name:s.src,value:m}],"Add image"),le([s.id]))}function fh(s){let f=e.ownerDocument.createElement("input");f.type="file",f.accept="image/*",f.addEventListener("change",()=>{let u=f.files?.[0];u&&Fa(s,u)}),f.click()}function uh(s,f){let u=f.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"image";if(s.assets[u]===void 0)return u;for(let p=2;;p+=1){let m=`${u}-${p}`;if(s.assets[m]===void 0)return m}}function Ba(){let s=Xd({x:wa,y:wa});s&&(ue(s.ops,s.ids.length===1?"Duplicate":`Duplicate ${s.ids.length} elements`),le(s.ids))}function Ha(s,f){if(s.length===0)return;let u=ve(r,s).document;ue([...s,...Hr(r,u)],f)}function Ua(){let s=hl(r,n);s&&(Ha(s.ops,"Group"),le([s.groupId]))}function Va(){let s=n.filter(m=>{let g=V(r.root,m);return g!==void 0&&Se(g)});if(s.length===0)return;let f=r,u=[],p=[];for(let m of s){let g=V(f.root,m);g&&p.push(...de(g).map(C=>C.id));let v=ml(f,m);v.length!==0&&(u.push(...v),f=ve(f,v).document)}b!==null&&s.includes(b)&&(b=null),Ha(u,s.length===1?"Ungroup":`Ungroup ${s.length} groups`),le(p)}function za(s){Ha(xl(r,n,s),sy[s])}function ch(s,f,u){let p=V(r.root,f);if(!p||!ce(p))return;let m=new Set(De(r.root,f)),g=s.filter(K=>K!==r.root.id&&V(r.root,K)&&!m.has(K));if(g.length===0)return;let v=[],C=r;if(g.forEach((K,ae)=>{let Z={op:"move",id:K,parent:f,index:u+ae};v.push(Z),C=ve(C,[Z]).document}),g.every(K=>ph(r,C,K)))return;let O=new Set(g.flatMap(K=>Sd(K,C))),F=[];for(let K of g){let ae=Qd(r,K),Z=Qd(C,K),ge={x:ae.x-Z.x,y:ae.y-Z.y};if(!(ge.x===0&&ge.y===0))for(let kt of rr(K,C)){let Qr=yt(kt);Qr&&(F.push({op:"set",id:kt,prop:"x",value:re(Qr.x+ge.x)}),F.push({op:"set",id:kt,prop:"y",value:re(Qr.y+ge.y)}))}}let j=ve(C,F).document;ue([...v,...F,...Hr(r,j,O)],g.length===1?`Move ${g[0]}`:`Move ${g.length} layers`)}function ph(s,f,u){let p=nt(s.root,u),m=nt(f.root,u);return p?.id===m?.id&&p?.children.findIndex(g=>g.id===u)===m?.children.findIndex(g=>g.id===u)}function Qd(s,f){let u=De(s.root,f).slice(0,-1).reverse(),p=Ae(s);for(let m of u){let g=V(s.root,m);if(!g||Se(g))continue;let v=p.nodes.get(m);return v?{x:v.absX,y:v.absY}:{x:0,y:0}}return{x:0,y:0}}function ef(s){let f=V(r.root,s);!f||!Se(f)||(b=s,Y())}function tf(){if(b===null)return;let s=b;b=De(r.root,s).slice(0,-1).reverse().find(u=>{let p=V(r.root,u);return p!==void 0&&Se(p)})??null,le([s])}function qa(){let s=V(r.root,b??r.root.id)??r.root;le(de(s).map(f=>f.id).filter(Ft))}let hh={locked:["Lock","Unlock"],hidden:["Hide","Show"]};function rf(s){return s==="locked"?Re().locked:Re().hidden}function fr(s,f,u){let p=s.filter(v=>v!==r.root.id&&V(r.root,v)),m=u?p.filter(v=>!rf(f).has(v)):[...new Set(p.flatMap(v=>{let C=en(r.root,v,f);return C===void 0?[]:[C]}))];if(m.length===0)return;let g=hh[f][u?0:1];ue(m.map(v=>({op:"set",id:v,prop:f,value:u?!0:void 0})),m.length===1?`${g} ${m[0]}`:`${g} ${m.length} layers`)}function ur(s,f){s.length!==0&&fr(s,f,!s.every(u=>rf(f).has(u)))}function ja(s){let f=[];return oe(r.root,u=>{u[s]===!0&&f.push(u.id)}),f}function oo(s){let f=ja(s);if(f.length===0)return;let u=s==="locked"?"Unlock all":"Show all";ue(f.map(p=>({op:"set",id:p,prop:s,value:void 0})),u)}function mh(s){P={...Rc,...s},me?.close()}function cr(){let s=n.filter(u=>u!==r.root.id).map(u=>({op:"remove",id:u}));if(s.length===0)return;let f=s.length;le([]),ue(s,f===1?"Delete element":`Delete ${f} elements`)}function Zr(){Ie=null;let s=_.undo();s&&md(s.ops,`Undo ${s.entry.label}`)}function ao(){Ie=null;let s=_.redo();s&&md(s.ops,`Redo ${s.entry.label}`)}function xh(s){if(!_.isTail(s))return!1;for(let f=s.length;f>0;f-=1)Zr();return!0}function nf(s,f,u,p){let m=V(r.root,s);if(!m)return;let g=m[f];ly(g,u)||ue([{op:"set",id:s,prop:f,value:u}],p??`Set ${f}`)}function gh(s,f){r.tokens[s]!==f&&ue([{op:"setToken",name:s,value:f}],`Set $${s}`)}function yh(s){s in r.tokens&&ue([{op:"setToken",name:s,value:void 0}],`Remove $${s}`)}function of(s,f){let u=lt(s)?.values[f];u!==void 0&&ue([{op:"set",id:s,prop:f,value:re(u)}],`Detach ${f}`)}function vh(s){let f=V(r.root,b??r.root.id)??r.root,u=[];for(let p of de(f)){if(!Ft(p.id))continue;let m=Ee(p.id);m&&ui(m,s)&&u.push(p.id)}return u}function Ke(s){typeof e.setPointerCapture=="function"&&e.setPointerCapture(s)}function Ka(s){e.hasPointerCapture?.(s)&&e.releasePointerCapture(s)}let af=s=>{I&&(vd(),I.handleKey(s)&&(s.preventDefault(),s.stopPropagation()))},sf=s=>{I&&(s.preventDefault(),vd(),I.handleInput(s))},lf=()=>I?.handleCompositionStart(),df=s=>I?.handleCompositionUpdate(s.data??""),ff=s=>I?.handleCompositionEnd(s.data??""),uf=s=>{if(!e.ownerDocument.hasFocus())return;let f=s.relatedTarget;f instanceof Element&&f.closest("[data-vd-keeps-text]")||lr("blur")};return ie.addEventListener("keydown",af),ie.addEventListener("beforeinput",sf),ie.addEventListener("compositionstart",lf),ie.addEventListener("compositionupdate",df),ie.addEventListener("compositionend",ff),ie.addEventListener("blur",uf),e.addEventListener("pointerdown",Ad),e.addEventListener("pointermove",$d),e.addEventListener("pointerup",to),e.addEventListener("pointercancel",to),e.addEventListener("pointerup",Kn),e.addEventListener("pointercancel",Kn),e.addEventListener("pointerleave",Vd),e.addEventListener("dblclick",Id),e.addEventListener("contextmenu",Rd),e.addEventListener("keydown",Td),e.addEventListener("keyup",Nd),e.addEventListener("copy",Od),e.addEventListener("cut",Dd),e.addEventListener("paste",Pd),e.addEventListener("dragover",Bd),e.addEventListener("dragleave",Hd),e.addEventListener("drop",Ud),y=!0,se?.setTool(o),se?.setHistory(!1,!1),se?.setZoom(A.getCamera().zoom),Le($e(Ma())),t.autoFit&&!t.camera&&jn(()=>A.fitToContent()),t.history&&(_.restore(t.history),se?.setHistory(_.canUndo,_.canRedo)),t.selection&&t.selection.length>0&&le(t.selection),Y(),{element:e,viewer:A,getDocument:()=>r,update(s){r=s,A.update(r),le(n),Y(),Ye("problems",A.getScene().problems)},applyOps:(s,f)=>ue(s,f??"Apply changes"),setDocument:(s,f)=>ue(cs(r,ii(s,r.root.id)),f??"Replace document"),getSelection:()=>n,setSelection:le,selectAll:qa,deleteSelection:cr,lock:s=>fr(s??n,"locked",!0),unlock:s=>fr(s??n,"locked",!1),toggleLock:s=>ur(s??n,"locked"),unlockAll:()=>oo("locked"),hide:s=>fr(s??n,"hidden",!0),show:s=>fr(s??n,"hidden",!1),toggleHidden:s=>ur(s??n,"hidden"),showAll:()=>oo("hidden"),isLocked:s=>Re().locked.has(s),isHidden:s=>Re().hidden.has(s),setFeatures:mh,getFeatures:()=>P,moveLayers:ch,copy:Jr,cut:Yd,paste:Ia,duplicate:Ba,group:Ua,ungroup:Va,reorder:za,scaleSelection:Ap,getSpacing:Lp,setSpacing:Tp,align:jd,distribute:Gd,canDistribute:s=>Kd(s)!==null,editText:jr,endTextEditing:()=>lr("done"),getEditingText:()=>I?.id??null,formatText:s=>I?.format(s),getTextFormat:()=>I?.activeMark()??{},getTextSelectionRects:gd,getTextRange:()=>{if(!I)return null;let{anchor:s,head:f}=I.getSelection();return{from:Math.min(s,f),to:Math.max(s,f)}},getEnteredGroup:()=>b,enterGroup:ef,exitGroup:tf,getTool:()=>o,editPoints:Ht,stopEditingPoints:Wr,getPointEditing:()=>z?.id??null,convertToVector:s=>Na(s),setTool:wt,beginEdit:pp,endEdit:hp,undo:Zr,redo:ao,canUndo:()=>_.canUndo,canRedo:()=>_.canRedo,getHistory:()=>_.snapshot(),setProperty:nf,fontFamilies:()=>{let s=new Map;for(let f of t.fonts?.faces()??[]){let u=s.get(f.family)??{weights:new Set,italic:!1};u.weights.add(f.weight),f.style==="italic"?u.italic=!0:(u.css===void 0||f.weight===400)&&(u.css=f.id),s.set(f.family,u)}return[...s.entries()].sort(([f],[u])=>f.localeCompare(u)).map(([f,u])=>({family:f,weights:[...u.weights].sort((p,m)=>p-m),italic:u.italic,...u.css===void 0?{}:{css:u.css}}))},assetUrl:s=>{let f=r.assets[s];return f?t.resolveAsset?.(f,s):void 0},setToken:gh,removeToken:yh,bindingsOf:cp,unbind:of,getResolution:()=>A.getResolution(),getCamera:()=>A.getCamera(),getProblems:()=>A.getScene().problems,on:sp,reveal:Ea,panBy:dp,setPresence(s,f){d={ids:[...s],label:f??null},Y()},setHighlight(s){s.length===0&&h.length===0||(h=[...s],Y())},isHistoryTail:s=>_.isTail(s),undoTail:xh,historyTop:()=>_.top,destroy(){Ca(),e.removeEventListener("pointerup",Kn),e.removeEventListener("pointercancel",Kn),e.removeEventListener("pointerdown",Ad),e.removeEventListener("pointermove",$d),e.removeEventListener("pointerup",to),e.removeEventListener("pointercancel",to),e.removeEventListener("pointerleave",Vd),ie.removeEventListener("keydown",af),ie.removeEventListener("beforeinput",sf),ie.removeEventListener("compositionstart",lf),ie.removeEventListener("compositionupdate",df),ie.removeEventListener("compositionend",ff),ie.removeEventListener("blur",uf),ie.remove(),dr&&clearTimeout(dr),e.removeEventListener("dblclick",Id),e.removeEventListener("contextmenu",Rd),e.removeEventListener("copy",Od),e.removeEventListener("cut",Dd),e.removeEventListener("paste",Pd),e.removeEventListener("dragover",Bd),e.removeEventListener("dragleave",Hd),e.removeEventListener("drop",Ud),e.removeEventListener("keydown",Td),e.removeEventListener("keyup",Nd),me?.destroy(),se?.destroy(),G.destroy(),A.destroy(),N.remove(),D.clear(),e.style.cursor="",e.classList.remove("vd-editor")}}}function ly(e,t){return e===t?!0:pe(e)&&pe(t)?e.expr===t.expr:!1}function Ic(e){return e.metaKey||e.ctrlKey||e.altKey}function ka(e){if(!(e instanceof HTMLElement)||e.classList.contains("vd-editor__input"))return!1;let t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||e.isContentEditable}var e_=new Set(Dt);function sd(e){return e.map(t=>({value:t,label:`${t.charAt(0).toUpperCase()}${t.slice(1)}`}))}var uy=[{value:"nonzero",label:"Non-zero"},{value:"evenodd",label:"Even-odd"}].filter(e=>Vt.includes(e.value)),cy=sd(zt),py=sd(Et),hy=sd(qt),my=[{value:"left",label:"Left",icon:Ne("text-left")},{value:"center",label:"Centre",icon:Ne("text-center")},{value:"right",label:"Right",icon:Ne("text-right")},{value:"justify",label:"Justify",icon:Ne("text-justify")}].filter(e=>_t.includes(e.value)),xy=[{value:"top",label:"Top",icon:Ne("text-top")},{value:"middle",label:"Middle",icon:Ne("text-middle")},{value:"bottom",label:"Bottom",icon:Ne("text-bottom")}].filter(e=>Ct.includes(e.value)),Uc={prop:"x",label:"X",kind:"number",prefix:"X"},Vc={prop:"y",label:"Y",kind:"number",prefix:"Y"},od={prop:"w",label:"W",kind:"number",prefix:"W"},ad={prop:"h",label:"H",kind:"number",prefix:"H"},gy={prop:"rotation",label:"Rotation",kind:"number",icon:"rotate",fallback:"0"},yy={prop:"opacity",label:"Opacity",kind:"number",icon:"opacity",percent:!0,fallback:"100%"},Bc={prop:"radius",label:"Radius",kind:"number",icon:"radius",span:"wide",fallback:"0"},zn={heading:"Position",props:[Uc,Vc,od,ad,gy,yy]},Sa={prop:"fill",label:"Fill",kind:"colour"},zc={prop:"stroke",label:"Stroke",kind:"colour",span:"half"},qc={prop:"strokeWidth",label:"Stroke width",kind:"number",prefix:"Width",fallback:"1"},jc={present:"stroke",empty:"No stroke",add:{stroke:"#000000",strokeWidth:1},clear:["stroke","strokeWidth","cap","join"]},Hc={heading:"Stroke",props:[zc,qc],optional:jc},t_={frame:[{heading:"Frame",props:[Uc,Vc,od,ad,{prop:"clip",label:"Clip content",kind:"toggle"}]},{heading:"Fill",props:[{prop:"background",label:"Fill",kind:"colour"}]}],canvas:[{heading:"Canvas",props:[od,ad,{prop:"background",label:"Fill",kind:"colour"}]}],text:[zn,{heading:"Text",props:[{prop:"font",label:"Font",kind:"font",fallback:"Default"},{prop:"weight",label:"Style",kind:"style",span:"half"},{prop:"size",label:"Size",kind:"number",icon:"font-size",fallback:"16"},{prop:"lineHeight",label:"Line height",kind:"number",icon:"line-height",fallback:"Auto"},{prop:"letterSpacing",label:"Letter spacing",kind:"number",icon:"letter-spacing",fallback:"0"},{prop:"align",label:"Align",kind:"segmented",options:my,span:"half"},{prop:"valign",label:"Vertical",kind:"segmented",options:xy,span:"half"}]},{heading:"Fill",props:[Sa]},{heading:"Link",props:[{prop:"content",label:"Link",kind:"link",icon:"link"}]}],rect:[{heading:"Position",props:[...zn.props,Bc]},{heading:"Fill",props:[Sa]},Hc],ellipse:[zn,{heading:"Fill",props:[Sa]},Hc],image:[{heading:"Position",props:[...zn.props,Bc]},{heading:"Image",props:[{prop:"fit",label:"Fit",kind:"select",options:py,prefix:"Fit"}]}],vector:[zn,{heading:"Fill",props:[{...Sa,span:"half"},{prop:"rule",label:"Fill rule",kind:"select",options:uy,prefix:"Rule",span:"half"}]},{heading:"Stroke",props:[zc,qc,{prop:"cap",label:"Cap",kind:"select",options:cy,prefix:"Cap",span:"half"},{prop:"join",label:"Join",kind:"select",options:hy,prefix:"Join",span:"half"}],optional:jc}]};var r_=Ut.map(e=>({value:e,label:e.split("-").map((t,r)=>r===0?t.charAt(0).toUpperCase()+t.slice(1):t).join(" ")}));function Kc(e){let t=e,r=new Map,n=typeof URL.createObjectURL=="function"&&typeof URL.revokeObjectURL=="function";return{resolve(o){let a=r.get(o.hash);if(a!==void 0)return a;let i=t.get(o.hash);if(i===void 0)return;if(!n)return _s(o.type,i);let l;try{l=Es(i)}catch{return}let d=URL.createObjectURL(new Blob([l],{type:o.type}));return r.set(o.hash,d),d},replace(o){t=o;for(let[a,i]of r)o.has(a)||(URL.revokeObjectURL(i),r.delete(a))},destroy(){for(let o of r.values())URL.revokeObjectURL(o);r.clear(),t=new Map}}}var id="0.1.2",Gc="https://cdn.jsdelivr.net/npm/@getv.design/embed@0.1.2/fonts/";var wy=Symbol.for(`vdesign.embed.documents@${id}`),Wc=globalThis[wy]??=new WeakMap,ky=/^Line (\d+): /;function fd(e){let t=ky.exec(e.message);return{...t?{line:Number(t[1])}:{},code:e.code,message:e.message,severity:e.severity}}function ld(e){if(typeof e!="string")return dd(So("").document,new Map,[{code:"not-text",message:`parse() takes .vd text, not ${e===null?"null":typeof e}.`,severity:"error"}]);let{head:t,blocks:r}=ws(e),n=So(t);return dd(n.document,r,n.problems.map(fd))}function dd(e,t,r){let n=Object.freeze({});return Wc.set(n,{document:e,blocks:t,problems:r}),{document:n,problems:r}}function Xc(e,t,r){return dd(e,t,[...r]).document}function _a(e){let t=Wc.get(e);if(!t)throw new TypeError("Not a vDesign document: pass .vd text or what parse() returned.");return t}async function Yc(e){if(typeof e=="string")return _a(ld(e).document);if(e instanceof URL){let t=await fetch(e);if(!t.ok)throw new Error(`Could not fetch ${e.href}: ${t.status}`);return _a(ld(await t.text()).document)}return Sy(e)?_a(ld(await e.text()).document):_a(e)}function Sy(e){let t=e;return typeof t.text=="function"&&typeof t.size=="number"}function Ur(e){return e.root.children.filter(t=>t.type==="frame"&&t.hidden!==!0)}function Jc(e,t){let r=Ur(e),n=typeof t=="number"?r[t]:r.find(o=>o.id===t);if(!n){let o=r.map(a=>a.id).join(", ")||"none";throw new RangeError(`No page ${JSON.stringify(t)} in this document; its pages: ${o}.`)}return n}var ud=["page","content","none"],Zc=24;function qn(e){let t=e.getBoundingClientRect();return{width:t.width,height:t.height}}function Qc(e,t){let r=t===void 0?void 0:e.itemOf(t);if(!(!r||r.w<=0||r.h<=0))return{x:r.x,y:r.y,width:r.w,height:r.h}}function ep(e,t,r,n){if(r==="none")return;let o=r==="page"?Qc(e,n):void 0;if(!o){e.fitToContent(Zc);return}let a=qn(t);e.setCamera(Mr(o,{width:a.width||o.width,height:a.height||o.height},Zc))}function tp(e,t,r){let n=e.getCamera(),o=qn(t),a={x:(o.width/2-n.x)/n.zoom,y:(o.height/2-n.y)/n.zoom},i;for(let l of Ur(e.getDocument())){let d=Qc(e,l.id);if(!d)continue;let c=Math.max(d.x-a.x,0,a.x-(d.x+d.width)),h=Math.max(d.y-a.y,0,a.y-(d.y+d.height)),x=Math.hypot(c,h);(!i||x<i.distance)&&(i={id:l.id,distance:x})}return i?.id??r}function rp(e,t,r){let n=e===void 0?t:String(e);if(n===void 0)return;let o;try{o=new URL(n,r??globalThis.location?.href)}catch{throw new TypeError(`fontBase must be a URL, or a path on this page; got ${n}.`)}return o.pathname.endsWith("/")||(o.pathname+="/"),o}var cd=Symbol.for("vdesign.embed.handover");function np(e){return e[cd]}var op=["exact","browser"],ap=["change"],_y=250;async function OC(e,t,r={}){let n=r.fit??"page";if(!ud.includes(n))throw new TypeError(`edit: fit must be one of ${ud.join(", ")}; got ${String(n)}.`);let o=r.fonts??"exact";if(!op.includes(o))throw new TypeError(`edit: fonts must be one of ${op.join(", ")}; got ${String(o)}.`);let a=o==="exact"?rp(r.fontBase,Gc,e.ownerDocument.baseURI):void 0,i=np(r),l=await Yc(t),d=i?.page!==void 0&&Ur(l.document).some(S=>S.id===i.page)?i.page:r.page===void 0?Ur(l.document)[0]?.id:Jc(l.document,r.page).id,c=i?.exact&&a?await Cy(a,l.document):void 0,h=e.ownerDocument,x=h.defaultView,y=new Map(l.blocks),b=Kc(y),P=h.createElement("div");P.className="vd-embed vd-embed--edit",P.style.position="relative",P.style.width="100%",P.style.height="100%",e.appendChild(P);let k=S=>{r.onLink?r.onLink(S):x?.open(S,"_blank","noopener,noreferrer")},_;try{_=nd(P,{document:l.document,chrome:r.toolbar??!0,interactive:r.interactive??!0,wheel:"modifier",resolveAsset:S=>b.resolve(S),importImage:he,onOpenLink:k,...r.surface?{surface:r.surface}:{},...i?{camera:i.camera}:{},...c?{fonts:c.library}:{}})}catch(S){throw P.remove(),b.destroy(),S}let B=new Set,R=!1,J=!1,E=0,D=i===void 0,N,A,G,se;function me(S){return G?.of!==S&&(G={of:S,text:ks(bs(S),y)}),G.text}async function he(S){if(R||!S.type.startsWith("image/"))return null;let U=new Uint8Array(await S.arrayBuffer()),W=await Ss(U);return R?null:(y.has(W)||y.set(W,Cs(U)),{type:S.type,hash:W,bytes:U.length})}function ke(){E+=1;try{ep(_.viewer,P,n,d)}finally{E-=1}}let we=_.on("navigate",()=>{E===0&&(D=!1)}),T=_.on("change",({document:S})=>{let U={text:()=>me(S)};for(let W of[...B])W(U);c&&L()}),Q=qn(P),w=x&&"ResizeObserver"in x?new x.ResizeObserver(()=>{let S=qn(P);S.width===Q.width&&S.height===Q.height||(Q=S,D&&ke())}):void 0;w?.observe(P),i||ke(),!c&&o==="exact"&&M();function $(){return A??=(async()=>{if(a)try{let{exactFontsAt:S}=await import("./chunks/fonts.js");return S(a)}catch{return}})(),A}async function M(){let S=await $();if(!(R||!S)){for(;;){let U=_.getDocument(),W=await S.ensure(U);if(R||W.length>0)return;if(_.getDocument()===U)break}c=S,_.viewer.setFonts(S.library)}}function L(){N!==void 0&&clearTimeout(N),N=setTimeout(()=>{N=void 0;let S=c;R||!S||S.ensure(_.getDocument()).then(U=>{R||c!==S||U.length===0||(c=void 0,_.viewer.setFonts(void 0))})},_y)}function H(){R||(R=!0,N!==void 0&&clearTimeout(N),T(),we(),w?.disconnect(),_.destroy(),b.destroy(),P.remove(),B.clear())}let q={getText:()=>me(_.getDocument()),getDocument(){let S=_.getDocument();return se?.of!==S&&(se={of:S,document:Xc(S,new Map(y),_.getProblems().map(fd))}),se.document},on(S,U){if(!ap.includes(S))throw new TypeError(`edit: on() takes one of ${ap.join(", ")}; got ${String(S)}.`);return B.add(U),()=>{B.delete(U)}},undo(){R||_.undo()},redo(){R||_.redo()},async view(){if(R)throw new Error("edit: this editor was destroyed.");if(J)throw new Error("edit: view() is already opening a view.");J=!0,P.inert=!0;try{_.endTextEditing();let{view:S}=await import("./view.js");if(R)throw new Error("edit: this editor was destroyed.");d=tp(_.viewer,P,d);let U={camera:_.viewer.getCamera(),page:d,exact:c!==void 0},W=_.getDocument(),I=await S(e,q.getDocument(),{...Ey(r),[cd]:U});if(R)throw I.destroy(),new Error("edit: this editor was destroyed.");let z=_.getDocument()===W?void 0:q.getDocument();return H(),z&&await I.load(z),I}finally{J=!1,P.inert=!1}},destroy:H};return q}async function Cy(e,t){try{let{exactFontsAt:r}=await import("./chunks/fonts.js"),n=r(e);return(await n.ensure(t)).length===0?n:void 0}catch{return}}function Ey(e){let{toolbar:t,...r}=e;return r}export{OC as edit,id as version};
2572
+ `;function qn(e){if(e.getElementById(Mc))return;let t=e.createElement("style");t.id=Mc,t.textContent=Ac,e.head.appendChild(t)}var It=["font","size","weight","italic","underline","strike","fill","letterSpacing","link"];function dr(e){return typeof e=="string"?e===""?[]:[{text:e}]:e.flatMap(t=>typeof t=="string"?t===""?[]:[{text:t}]:t.text===""?[]:[t])}function fr(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function ur(e){return fr(e).length}function lr(e){let t={};for(let r of It){let n=e[r];n!==void 0&&(t[r]=n)}return t}function Lc(e,t){return It.every(r=>e[r]===t[r])}function Qg(e,t){let r={text:e};for(let n of It){let o=t[n];o!==void 0&&(r[n]=o)}return r}function Kn(e){let t=dr(e),r=[];for(let o of t){let a=r[r.length-1];if(a&&Lc(lr(a),lr(o))){r[r.length-1]={...a,text:a.text+o.text};continue}r.push(o)}if(r.length===0)return"";let n=r[0];return r.length===1&&$c(n)?n.text:r.map(o=>$c(o)?o.text:o)}function $c(e){return It.every(t=>e[t]===void 0)}function Gl(e,t,r){let[n,o]=wa(t,r,ur(e)),a=[],i=0;for(let l of dr(e)){let d=i+l.text.length,c=Math.max(n,i),h=Math.min(o,d);h>c&&a.push({...l,text:l.text.slice(c-i,h-i)}),i=d}return Kn(a)}function Ur(e,t,r,n,o){let a=ur(e),[i,l]=wa(t,r,a),d=o??jn(e,i),c=[],h=0,x=!1,y=()=>{x||n===""||(c.push(Qg(n,d)),x=!0)};for(let v of dr(e)){let D=h+v.text.length,k=Math.min(i,D);k>h&&c.push({...v,text:v.text.slice(0,k-h)}),i>=h&&i<=D&&y();let S=Math.max(l,h);D>S&&c.push({...v,text:v.text.slice(S-h)}),h=D}return y(),Kn(c)}function jn(e,t){let r=dr(e);if(r.length===0)return{};let n=0,o=r[0];for(let a of r){let i=n+a.text.length;if(t>n&&t<=i)return lr(a);if(t<=n)return lr(o);o=a,n=i}return lr(o)}function Wl(e,t,r,n){let[o,a]=wa(t,r,ur(e));if(o===a)return Kn(e);let i=Object.keys(n),l=[],d=0;for(let c of dr(e)){let h=d+c.text.length;for(let[x,y,v]of ey(d,h,o,a)){if(y<=x)continue;let D=c.text.slice(x-d,y-d);if(!v){l.push({...c,text:D});continue}let k={...c,text:D};for(let S of i)n[S]===void 0?delete k[S]:k[S]=n[S];l.push(k)}d=h}return Kn(l)}function ey(e,t,r,n){return[[e,Math.min(t,r),!1],[Math.max(e,r),Math.min(t,n),!0],[Math.max(e,n),t,!1]]}function Xl(e,t,r){let[n,o]=wa(t,r,ur(e));if(n===o)return jn(e,n);let a,i=0;for(let l of dr(e)){let d=i+l.text.length;if(Math.min(d,o)>Math.max(i,n)){let c=lr(l);if(!a)a=c;else{let h={};for(let x of It)a[x]===c[x]&&a[x]!==void 0&&(h[x]=a[x]);a=h}}i=d}return a??{}}function wa(e,t,r){let n=Tc(Math.min(e,t),r),o=Tc(Math.max(e,t),r);return[n,o]}function Tc(e,t){return Math.max(0,Math.min(Math.round(e),t))}function Vr(e,t){let r=[],n=0;return e.lines.forEach((o,a)=>{let i=o.spans.map(h=>h.text).join(""),l=i===""?n:ty(t,i,n),d=l+i.length,c=a===e.lines.length-1;r.push({start:l,end:c?t.length:d}),n=d}),r.length===0&&r.push({start:0,end:t.length}),r}function ty(e,t,r){let n=e.indexOf(t,r);return n===-1?r:n}function ka(e,t){for(let r=0;r<e.length;r+=1){let n=e[r];if(t<=n.end)return r}return Math.max(0,e.length-1)}function Sa(e,t,r,n){let o=Vr(e,t),a=ka(o,r),i=e.lines[a],l=o[a];if(!i||!l)return{x:0,y:0,h:0,line:0};let d=Math.max(0,Math.min(r-l.start,Dc(i))),c=(ry(i,d)??i.style)?.fill;return{x:Yl(i,d,n),y:i.y,h:i.h,line:a,...c!==void 0?{fill:c}:{}}}function ry(e,t){let r=0;for(let n of e.spans)if(r+=[...n.text].length,t<=r)return n.style;return e.spans[e.spans.length-1]?.style}function Gn(e,t,r,n){let o=Vr(e,t);if(e.lines.length===0)return 0;let a=e.lines.findIndex(d=>r.y<d.y+d.h);a===-1&&(a=e.lines.length-1);let i=e.lines[a];return o[a].start+Oc(i,r.x,n)}function Oc(e,t,r){let n=0,o=1/0,a=0,i=(l,d)=>{let c=Math.abs(d-t);c<o&&(o=c,n=l)};i(0,e.spans[0]?.x??0);for(let l of e.spans){let d=[...l.text],c=0;d.forEach((h,x)=>{c=r.advance(d.slice(0,x+1).join(""),l.style),i(a+x+1,l.x+c)}),a+=d.length}return n}function Yl(e,t,r){let n=0,o=e.spans[0]?.x??0;for(let a of e.spans){let i=[...a.text];if(t<=n)return a.x;if(t>=n+i.length){o=a.x+a.w,n+=i.length;continue}let l=i.slice(0,t-n).join("");return a.x+r.advance(l,a.style)}return o}function Dc(e){return e.spans.reduce((t,r)=>t+[...r.text].length,0)}function Jl(e,t,r,n,o){let a=Math.min(r,n),i=Math.max(r,n);if(a===i)return[];let l=Vr(e,t),d=[];return e.lines.forEach((c,h)=>{let x=l[h];if(!x)return;let y=Math.max(a,x.start),v=Math.min(i,x.end);if(v<=y)return;let D=Dc(c),k=Yl(c,Math.min(y-x.start,D),o),S=Yl(c,Math.min(v-x.start,D),o),B=Math.max(S-k,v>x.end-1&&v>y?4:0);B>0&&d.push({x:k,y:c.y,w:B,h:c.h})}),d}function Zl(e,t,r,n,o){let a=Vr(e,t),l=ka(a,r)+n,d=e.lines[l],c=a[l];if(!d||!c)return n===-1?0:t.length;let h=Sa(e,t,r,o);return Math.min(c.start+Oc(d,h.x,o),c.end)}var ny=/[\p{L}\p{N}_]/u;function Ql(e,t){let r=Math.max(0,Math.min(t,e.length)),n=l=>ny.test(e[l]??""),o=r;if(!n(o)&&o>0&&n(o-1)&&(o-=1),!n(o))return{from:r,to:r};let a=o,i=o;for(;a>0&&n(a-1);)a-=1;for(;i<e.length&&n(i);)i+=1;return{from:a,to:i}}function _a(e,t,r){let n=Vr(e,t),o=n[ka(n,r)];return o?{from:o.start,to:o.end}:{from:0,to:t.length}}var Ic=700;function ed(e){let t=0,r=0,n=null,o=!1,a=0,i=!1,l=0,d=0;function c(){return fr(e.content())}function h(E){return Math.max(0,Math.min(Math.round(E),c().length))}function x(){return{from:Math.min(t,r),to:Math.max(t,r)}}function y(E,P=E){let R=t!==E||r!==P;t=h(E),r=h(P),R&&v(),n=null,e.invalidate()}function v(){o=!1,a&&(clearTimeout(a),a=0)}function D(){a&&clearTimeout(a),a=setTimeout(v,Ic)}function k(E,P){e.write(E,o,P),o=!0,D()}function S(E,P){let{from:R,to:C}=x(),G=n??void 0;k(Ur(e.content(),R,C,E,G),P),t=r=R+E.length,n=null,e.invalidate()}function B(E,P){E!==P&&(k(Ur(e.content(),E,P,""),"Delete text"),t=r=Math.min(E,P),e.invalidate())}function N(E,P){let{from:R,to:C}=x();if(R!==C){B(R,C);return}let G=c();if(E===-1){if(R===0)return;let ye=P?Nc(G,R):R-1;B(ye,R);return}if(R>=G.length)return;let de=P?Rc(G,R):R+1;B(R,de)}function J(E,P){let R=c();return P?E===-1?Nc(R,r):Rc(R,r):h(r+E)}return{id:e.id,getSelection:()=>({anchor:t,head:r}),setSelection(E,P){y(E,P??E)},caret(){return Sa(e.layout(),c(),r,e.measure())},highlight(){let{from:E,to:P}=x();return Jl(e.layout(),c(),E,P,e.measure())},pointTo(E,P){let R=Gn(e.layout(),c(),E,e.measure());y(P?t:R,R)},selectWordAt(E){let P=Gn(e.layout(),c(),E,e.measure()),R=Ql(c(),P);y(R.from,R.to)},selectLineAt(E){let P=Gn(e.layout(),c(),E,e.measure()),R=_a(e.layout(),c(),P);y(R.from,R.to)},selectAll(){y(0,c().length)},format(E){let{from:P,to:R}=x();if(P===R){n={...jn(e.content(),P),...E},e.invalidate();return}v(),k(Wl(e.content(),P,R,E),"Format text"),v(),e.invalidate()},activeMark(){if(n)return n;let{from:E,to:P}=x();return Xl(e.content(),E,P)},composing:()=>i,handleKey(E){if(i)return!1;let P=E.metaKey||E.ctrlKey,R=E.altKey||E.ctrlKey&&!E.metaKey;switch(E.key){case"Escape":return e.close("escape"),!0;case"ArrowLeft":case"ArrowRight":{let C=E.key==="ArrowLeft"?-1:1,{from:G,to:de}=x();if(!E.shiftKey&&G!==de)y(C===-1?G:de);else{let ye=P?Pc(e,c(),r,C):J(C,R);y(E.shiftKey?t:ye,ye)}return!0}case"ArrowUp":case"ArrowDown":{let C=E.key==="ArrowUp"?-1:1,G=P?C===-1?0:c().length:Zl(e.layout(),c(),r,C,e.measure());return y(E.shiftKey?t:G,G),!0}case"Home":case"End":{let C=Pc(e,c(),r,E.key==="Home"?-1:1);return y(E.shiftKey?t:C,C),!0}case"Backspace":return N(-1,R||P),!0;case"Delete":return N(1,R||P),!0;case"Enter":return P?e.close("done"):S(`
2573
+ `,"Type text"),!0;case"Tab":return!1;case"a":case"A":return P?(y(0,c().length),!0):!1;case"b":case"B":{if(!P)return!1;let C=this.activeMark().weight===700;return this.format({weight:C?void 0:700}),!0}case"i":case"I":return P?(this.format({italic:this.activeMark().italic===!0?void 0:!0}),!0):!1;case"u":case"U":return P?(this.format({underline:this.activeMark().underline===!0?void 0:!0}),!0):!1;default:return!1}},handleInput(E){if(!i)switch(E.inputType){case"insertText":case"insertReplacementText":case"insertFromPaste":case"insertFromDrop":case"insertFromYank":S(oy(E),"Type text");return;case"insertParagraph":case"insertLineBreak":S(`
2574
+ `,"Type text");return;case"deleteContentBackward":case"deleteWordBackward":N(-1,E.inputType==="deleteWordBackward");return;case"deleteContentForward":case"deleteWordForward":N(1,E.inputType==="deleteWordForward");return;case"deleteByCut":case"deleteByDrag":{let{from:P,to:R}=x();B(P,R);return}default:return}},handleCompositionStart(){i=!0;let{from:E,to:P}=x();l=E,d=P,v()},handleCompositionUpdate(E){k(Ur(e.content(),l,d,E),"Type text"),d=l+E.length,t=r=d,e.invalidate()},handleCompositionEnd(E){k(Ur(e.content(),l,d,E),"Type text"),i=!1,d=l+E.length,t=r=d,v(),e.invalidate()},breakBurst:v,destroy(){v()}}}function oy(e){return typeof e.data=="string"?e.data:e.dataTransfer?.getData("text/plain")??""}function Pc(e,t,r,n){let o=_a(e.layout(),t,r);return n===-1?o.from:o.to}var Ca=/[\p{L}\p{N}_]/u;function Nc(e,t){let r=t;for(;r>0&&!Ca.test(e[r-1]??"");)r-=1;for(;r>0&&Ca.test(e[r-1]??"");)r-=1;return r}function Rc(e,t){let r=t;for(;r<e.length&&!Ca.test(e[r]??"");)r+=1;for(;r<e.length&&Ca.test(e[r]??"");)r+=1;return r}function td(e){return ur(e)===0}var rd={v:"select",f:"frame",r:"rect",o:"ellipse",p:"pen",t:"text"};function qr(e,t){let r=[];for(let n of t){if(!q(e.root,n.nodeId))continue;let o=ee(n.to);ee(n.from)!==o&&r.push({op:"set",id:n.nodeId,prop:n.prop,value:o})}return r}function ee(e){return Math.round(e*100)/100}function Kr(e,t,r,n){let o=new Set,a=[];for(let d of t)d.op==="set"&&(o.add(Ie(d.id,d.prop)),a.push({nodeId:d.id,prop:d.prop}));if(a.length===0)return[];let i=[],l=new Set;for(let d of a)for(let c of r.get(Ie(d.nodeId,d.prop))??[]){let h=Ie(c.nodeId,c.prop);if(o.has(h)||l.has(h)||!q(e.root,c.nodeId))continue;let x=n.nodes.get(c.nodeId)?.values[c.prop];x!==void 0&&(l.add(h),i.push({op:"set",id:c.nodeId,prop:c.prop,value:ee(x)}))}return i}function nd(e,t,r,n={x:0,y:0}){let o=[],a=new Set,i=e;for(;;){let l=[],d=Ae(i);for(let[c,h]of t){let x=r.get(c),y=q(i.root,h),v=d.nodes.get(h);if(!(!x||!y||!v))for(let D of it(y)){let k=Ie(h,D);if(a.has(k))continue;let S=x[D],B=v.values[D];if(S===void 0||B===void 0)continue;let N=S+(D==="x"?n.x:D==="y"?n.y:0);ee(N)!==ee(B)&&(a.add(k),l.push({op:"set",id:h,prop:D,value:ee(N)}))}}if(l.length===0)return o;o.push(...l),i=be(i,l).document}}function jr(e,t,r=new Set){let n=Ae(e),o=Ae(t),a=[];for(let[i,l]of o.nodes){if(r.has(i))continue;let d=n.nodes.get(i),c=q(t.root,i);if(!(!d||!c))for(let h of it(c)){let x=d.values[h],y=l.values[h];x===void 0||y===void 0||ee(x)!==ee(y)&&a.push({op:"set",id:i,prop:h,value:ee(x)})}}return a}function Ea(e,t,r){let n=new Set,o=[];for(let a of t)a.op==="set"&&a.prop==="view"&&n.add(a.id);for(let a of t){if(a.op!=="set"||a.prop!=="w"&&a.prop!=="h"||n.has(a.id))continue;let i=q(e.root,a.id);if(i?.type!=="vector"||i.view!==void 0)continue;let l=r(a.id);l&&(n.add(a.id),o.push({op:"set",id:a.id,prop:"view",value:Qt({x:0,y:0,w:l.w,h:l.h})}))}return o.length===0?[...t]:[...o,...t]}var od="host:",Fc="#ffffff",Bc={w:1920,h:1080},ay=100,Ma=20,sy=15,iy={ne:0,se:90,sw:180,nw:270,n:0,e:90,s:180,w:270},Hc={w:240,h:28},ly={text:"Add text",frame:"Add page",rect:"Draw rectangle",ellipse:"Draw ellipse"};function dy(e,t){let r=t.x-e.x,n=t.y-e.y,o=Math.max(Math.abs(r),Math.abs(n));return{x:e.x+Math.sign(r||1)*o,y:e.y+Math.sign(n||1)*o}}var fy={KeyA:"left",KeyD:"right",KeyW:"top",KeyS:"bottom",KeyH:"hcenter",KeyV:"vcenter"},uy={KeyH:"x",KeyV:"y"},cy={left:"Align left",hcenter:"Align horizontal centres",right:"Align right",top:"Align top",vcenter:"Align vertical centres",bottom:"Align bottom"},ad=null,py=220,zc={lock:!0,hide:!0},hy=["x","y","w","h"],my={front:"Bring to front",forward:"Bring forward",backward:"Send backward",back:"Send to back"},xy=11,Ft=2;function id(e,t){qn(e.ownerDocument),e.classList.add("vd-editor"),e.hasAttribute("tabindex")||(e.tabIndex=0);let r=t.document,n=[],o=t.tool??"select",a=null,i=null,l=null,d={ids:[],label:null},c=null,h=[],x=!1,y=!1,v=null,D={...zc,...t.features},k=null,S=new zn,B=0,N=null,J={dx:0,dy:0},E=null,P=new Map,R=e.ownerDocument.createElement("div");R.style.position="absolute",R.style.inset="0",e.appendChild(R);let C=Ko(R,{document:r,...t.camera?{camera:t.camera}:{},...t.surface?{surface:t.surface}:{},...t.interactive===void 0?{}:{interactive:t.interactive},...t.wheel?{wheel:t.wheel}:{},...t.resolveAsset?{resolveAsset:t.resolveAsset}:{},...t.fonts?{fonts:t.fonts}:{},onSceneChange:(s,f)=>{f===r&&Ne("scene",{scene:s,document:f})},onCameraChange:s=>{de?.setZoom(s.zoom),Z(),Ne("camera",s),!(B>0)&&(La(),Ne("navigate",s))}}),G=Sc(e,s=>C.documentToScreen(s)),de=t.chrome===!1?null:Vu(e,{onTool:Ct,onUndo:on,onRedo:uo,onZoomReset:()=>C.fitToContent(),onPlay:t.onPlay,playHint:t.playHint,formatKeys:t.formatKeys}),ye=t.chrome===!1?null:fa(e,{onCommand:oh,...t.formatKeys?{formatKeys:t.formatKeys}:{}}),xe=r,ke=r,Se=[],A=null,te=[],w=null,$=null,M=new Map,T=null,H=null,j=null,F=[],O=We,X=null,z=null,V=null,U=null,Le=!1,ne=e.ownerDocument.createElement("textarea");ne.className="vd-editor__input",ne.setAttribute("aria-hidden","true"),ne.tabIndex=-1,ne.autocapitalize="off",ne.autocomplete="off",ne.spellcheck=!1,e.appendChild(ne);function Ne(s,f){let u=P.get(s);if(u)for(let p of u)p(f)}function up(s,f){let u=P.get(s)??new Set;return u.add(f),P.set(s,u),()=>u.delete(f)}function Yn(s){B+=1;try{s()}finally{B-=1}}function La(){N!==null&&(e.ownerDocument.defaultView?.cancelAnimationFrame(N),N=null)}function cp(s){let f=C.linkAt(s),u=f===void 0?void 0:nt(f);return u?u.kind==="url"?t.onOpenLink?(t.onOpenLink(u.url),!0):!1:q(r.root,u.id)?(le([u.id]),Oa([u.id]),!0):!1:!1}function Oa(s,f={}){if(A!==null)return E={target:s,options:f},!1;let u=mp(s);if(!u)return!1;let p=e.getBoundingClientRect(),m=p.width>0&&p.height>0,g=m?{width:p.width,height:p.height-pp(p)}:{width:u.w+96,height:u.h+96},b=f.fit==="always"?da(u,g):Tl(u,g,C.getCamera());if(!b)return!1;La(),f.by==="person"&&Ne("navigate",b);let _=e.ownerDocument.defaultView,L=_?.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;if(f.animate===!1||L||!m||!_?.requestAnimationFrame)return Yn(()=>C.setCamera(b)),!0;let I=C.getCamera(),K=_.performance.now();J={dx:0,dy:0};let Y=fe=>{let W=Math.min(1,Math.max(0,(fe-K)/py)),he=W===1?b:lc(I,b,dc(W),g);Yn(()=>C.setCamera(Pt(he,J.dx,J.dy))),N=W===1?null:_.requestAnimationFrame(Y)};return N=_.requestAnimationFrame(Y),!0}function pp(s){let f=de?.element.getBoundingClientRect();return!f||f.height===0?0:Math.max(0,s.bottom-f.top)}function hp(s,f){N!==null&&(J={dx:J.dx+s,dy:J.dy+f}),Yn(()=>C.setCamera(Pt(C.getCamera(),s,f)))}function Jn(){if(E===null||A!==null)return;let{target:s,options:f}=E;E=null,Oa(s,f)}function mp(s){if(s==="content"){let u=C.getScene();return la([{x:u.x,y:u.y,w:u.width,h:u.height}])}let f=[];for(let u of $l(r,s)){let p=Me(u);p&&f.push(p)}return la(f)}function ct(s){return C.getResolution().nodes.get(s)}function kt(s){let f=ct(s);return f?{x:f.x,y:f.y,w:f.w,h:f.h}:void 0}function Me(s){return ir(s,r,C.getResolution())}function Bt(s){let f=ct(s);return f?{x:f.absX,y:f.absY,w:f.w,h:f.h}:void 0}function Ht(s){return ct(s)?.values.rotation??0}function gd(){let s=Xr();if(s.length===0)return null;for(let f of s){let u=q(r.root,f);if(!u||!Hs.includes(u.type))return null}return s}function Zn(s,f=new Set){let u=C.getResolution(),p=null;return se(r.root,m=>{if(f.has(m.id)||!Ut(m.id))return!1;if(m.type!=="frame")return;let g=u.nodes.get(m.id);if(!g)return!1;let b={x:g.absX,y:g.absY,w:g.w,h:g.h};if(!st(b,s.x,s.y))return!1;p=m.id}),p}function zt(s){let f=ct(s);return f?{x:f.absX,y:f.absY}:{x:0,y:0}}function ze(){return k?.of!==r&&(k={of:r,hidden:po(r.root),locked:ho(r.root)}),k}function Ut(s){let{hidden:f,locked:u}=ze();return!f.has(s)&&!u.has(s)}function re(){return n.filter(Ut)}function Qn(s){let f=C.hitTest(s,p=>!ze().locked.has(p));if(f===null)return null;let u=v===null||Fe(r.root,f).includes(v);return aa(f,r,u?v:null)}function xp(){return Hn(r,re(),C.getResolution())}function Wr(){return re().length<2?null:Il(xp())}function eo(s){let f=[];for(let u of s)for(let p of sr(u,r)){let m=kt(p);m&&f.push({member:u,node:p,frame:m})}return f}function to(s,f){let u=q(r.root,s);if(!u)return"literal";let p=u[f];return p===void 0?"literal":Ro(p).kind}function gp(s){let f=q(r.root,s),u={};if(!f)return u;let p=[...hy,...Nn(f).map(m=>m.prop)];for(let m of p)u[m]=to(s,m);return u}function yd(s,f){let u="none";for(let p of s){let m=Da(p,f);if(m==="expression")return"expression";m==="token"&&(u="token")}return u}function Da(s,f){let u="none";for(let p of f){let m=to(s,p);if(m==="complex")return"expression";m==="token"&&(u="token")}return u}let Ue=null;function ce(s,f){if(s.length===0)return;let u=Eo(r,Ea(r,s,kt)),p=be(r,u);r=p.document,Ue?(Ra(Ue.started,Ue.label,u,p.inverse),Ue.started=!0):S.push({label:f,ops:u,inverse:p.inverse}),ro(u,f)}function yp(s){Ue={label:s,started:!1}}function vp(){Ue=null}function vd(s,f){s.length!==0&&(r=be(r,s).document,ro(s,f))}function ro(s,f){a=null,H=null,j=null,C.update(r),de?.setHistory(S.canUndo,S.canRedo),Z(),Ne("change",{document:r,ops:s,label:f}),Ne("problems",C.getScene().problems)}function le(s){let f=s.filter(p=>p!==r.root.id&&q(r.root,p)),u=f.length!==n.length||f.some((p,m)=>n[m]!==p);n=[...f],V&&(f.length!==1||f[0]!==V.id)&&(V=null),u&&(ye?.close(),j=null,Ne("selection",n)),Z()}function bp(s,f){let u=q(r.root,s);if(!u)return[];let p=C.getCamera().zoom;if(Math.min(f.w,f.h)*p<24)return[];let m=xy/p,g=ct(s);return Nn(u).flatMap(b=>{let _=g?.values[b.prop]??0,L=to(s,b.prop)!=="literal";return b.handles(f,_,m).map(I=>({id:I.id,at:I.at,bound:L}))})}function wp(){let s=[];for(let I of re()){let K=Me(I);K&&s.push(K)}let f=at(s);if(!f)return null;let u=re().length===1?re()[0]:void 0,p=u===void 0?void 0:q(r.root,u),m=u===void 0||!p||pe(p),g=new Set,b=Xr();for(let I of mi){let K=jo(I);b.some(Y=>K.some(fe=>to(Y,fe)!=="literal"))&&g.add(I)}let _=!m&&u!==void 0?Ht(u):0,L=_!==0&&u!==void 0?Bt(u):void 0;return{frame:L??f,...L?{rotation:_}:{},rotatable:gd()!==null,handles:z===null,boundHandles:g,adjusters:z!==null||m||u===void 0||L?[]:bp(u,f)}}function Xr(){return[...new Set(re().flatMap(s=>sr(s,r)))]}function kp(s){if(!s)return null;if(A?.kind==="adjust")return`r ${ee(w??A.from)}`;if(A?.kind==="rotate")return`${ee($??0)}\xB0`;if(!A&&H&&re().length===1){let f=ct(re()[0])?.values[H.prop]??0;return`r ${ee(f)}`}return A?.kind==="move"?`${ee(s.frame.x)}, ${ee(s.frame.y)}`:`${ee(s.frame.w)} \xD7 ${ee(s.frame.h)}`}function Sp(){let f=A!==null&&A.kind!=="space"&&A.kind!=="reorder"?null:Wr();if(!f)return{spacers:[],rings:[],lead:null};let u=A?.kind==="space"?A.spacer:null;return{spacers:Bl(f).map(p=>({id:p.id,axis:p.axis,at:p.at,label:p.id===(u??j)?String(ee(p.gap)):null})),rings:Hl(f).map(p=>({id:p.id,at:p.at})),lead:A?.kind==="reorder"?Me(A.id)??null:null}}function Z(){if(!y)return;let s=qp(),f=s?null:wp(),u=a!==null&&!n.includes(a)&&!A?Me(a)??null:null,p={...kc,...Sp(),hover:u,members:re().length>1?re().flatMap(m=>Me(m)??[]):[],box:f,badge:kp(f),caret:bd(),textSelection:wd(),draft:A?.kind==="create"?ar(A.origin,A.current):null,draftEllipse:A?.kind==="create"&&o==="ellipse",marquee:A?.kind==="marquee"?ar(A.origin,A.current):null,guides:A?O.guides:[],measures:A?O.measures:[],presence:d.ids.length===0?null:{frames:d.ids.flatMap(m=>Me(m)??[]),label:d.label},highlight:Fn(r,h).flatMap(m=>Me(m.id)??[]),slots:ph(),parked:n.filter(m=>!Ut(m)).flatMap(m=>Me(m)??[]),lockHint:Ep(),path:s,turn:Mp(),pageLabels:_p()};G.render(p)}function _p(){if(i)return[];let s=C.getResolution().nodes;return r.root.children.flatMap(f=>{if(f.type!=="frame")return[];let u=s.get(f.id);if(!u)return[];let p=Bn(u),m=f.name;return[{id:f.id,frame:p,label:typeof m=="string"&&m!==""?m:f.id,state:n.includes(f.id)?"selected":a===f.id?"hover":"idle"}]})}function Cp(s){let f=G.pageLabelRect(s),u=q(r.root,s);if(!f||!u)return;let p=u.name,m=e.ownerDocument.createElement("input");m.className="vd-editor__rename",m.type="text",m.spellcheck=!1,m.value=typeof p=="string"&&p!==""?p:"",m.placeholder=s,m.setAttribute("aria-label",`Name of ${s}`),m.style.left=`${f.x-4}px`,m.style.top=`${f.y-2}px`,m.style.width=`${Math.max(120,f.w+40)}px`;let g=!1,b=_=>{if(g)return;g=!0;let L=m.value.trim();m.remove(),i=null,_&&L!==(typeof p=="string"?p:"")&&lf(s,"name",L===""?void 0:L,"Rename"),Z(),e.focus({preventScroll:!0})};m.addEventListener("keydown",_=>{_.stopPropagation(),_.key==="Enter"?(_.preventDefault(),b(!0)):_.key==="Escape"&&(_.preventDefault(),b(!1))}),m.addEventListener("pointerdown",_=>_.stopPropagation()),m.addEventListener("blur",()=>b(!0)),i=m,e.appendChild(m),Z(),m.focus(),m.select()}function Ep(){if(l===null||A||!ze().locked.has(l))return null;let s=Me(l);return s?{frame:s,label:l}:null}function no(s){let f=C.itemOf(s);if(f?.kind!=="text")return null;let u=f.lines[0]?.y??f.y,p={lines:f.lines.map(m=>({y:m.y-u,h:m.h,baseline:m.baseline-u,w:m.w,spans:m.spans.map(g=>({text:g.text,style:g.style,x:g.x-f.x,w:g.w})),...m.style?{style:m.style}:{}})),width:Math.max(0,...f.lines.map(m=>m.w)),height:f.height};return{item:f,layout:p,top:u}}function Pa(){return o==="text"?"text":o!=="select"?"crosshair":"arrow"}function bd(){if(!z)return null;let s=no(z.id);if(!s)return null;let f=z.caret();return{x:s.item.x+f.x,y:s.top+f.y,h:f.h,...f.fill!==void 0?{fill:f.fill}:{}}}function wd(){if(!z)return[];let s=no(z.id);return s?z.highlight().map(f=>({x:s.item.x+f.x,y:s.top+f.y,w:f.w,h:f.h})):[]}function Na(s){if(!z)return null;let f=no(z.id);if(!f)return null;let u=Yr(z.id,s);return{x:u.x-f.item.x,y:u.y-f.top}}function Yr(s,f){let u=Ht(s),p=u===0?void 0:Bt(s);return p?Be(f,Ge(p),-u):f}function Mp(){let s=z?.id??V?.id;if(s===void 0)return null;let f=Ht(s),u=f===0?void 0:Bt(s);return u?{angle:f,centre:Ge(u)}:null}function Ap(s){let f=q(r.root,s);if(!f||f.type!=="text"||typeof f.h!="number")return[];let u=C.itemOf(s);if(u?.kind!=="text")return[];let p=ee(Math.ceil(u.height));return p>f.h?[{op:"set",id:s,prop:"h",value:p}]:[]}function $p(s,f,u,p){let m=Ue?Ue.started:u,g=Ue?.label??p;Ue&&(Ue.started=!0);let b=[{op:"set",id:s,prop:"content",value:f}],_=be(r,b);r=_.document,C.update(r);let L=Ap(s);if(L.length===0){Ra(m,g,b,_.inverse),ro(b,g);return}let I=be(r,L);r=I.document,C.update(r);let K=[...b,...L];Ra(m,g,K,[...I.inverse,..._.inverse]),ro(K,g)}function Ra(s,f,u,p){let m={label:f,ops:u,inverse:p};s&&S.amend(m)||S.push(m)}function Jr(s,f){let u=q(r.root,s);if(!u||u.type!=="text"||z?.id===s)return;cr("done"),Ct("select"),le([s]),z=ed({id:s,content:()=>{let m=q(r.root,s);return m?.type==="text"?m.content:""},layout:()=>no(s)?.layout??{lines:[],width:0,height:0},measure:()=>C.getMeasurer(),write:(m,g,b)=>$p(s,m,g,b),invalidate:()=>{Z(),kd(),Ne("selection",n)},close:m=>cr(m)});let p=f?Na(f):null;p?z.pointTo(p,!1):z.selectAll(),e.classList.add("vd-editor--editing"),ne.value="",ne.focus({preventScroll:!0}),Z(),kd()}function cr(s){let f=z;if(!f)return;z=null,Le=!1,f.destroy(),e.classList.remove("vd-editor--editing","vd-editor--typing"),Ne("selection",n);let u=q(r.root,f.id);u?.type==="text"&&td(u.content)&&(ce([{op:"remove",id:f.id}],"Remove empty text"),le([])),e.ownerDocument.activeElement===ne&&e.focus({preventScroll:!0}),Z()}function kd(){let s=bd();if(!s)return;let f=C.documentToScreen({x:s.x,y:s.y});ne.style.left=`${Math.round(f.x)}px`,ne.style.top=`${Math.round(f.y)}px`}let pr=0;function Sd(){e.classList.add("vd-editor--typing"),pr&&clearTimeout(pr),pr=setTimeout(()=>{pr=0,e.classList.remove("vd-editor--typing")},520)}function Ia(s){let f=qr(xe,s);return f.length>0&&T?[...f,...Kr(xe,f,M,T)]:f}function Vt(s){Fa(Ia(s))}function Fa(s,f=s){let u=m=>{let g=T?.nodes.get(m);return g?{x:0,y:0,w:g.w,h:g.h}:void 0},p=Ea(xe,s,u);te=Ea(xe,f,u),C.update(p.length>0?be(xe,p).document:xe),Z()}function _d(){let s=at(re().flatMap(p=>Me(p)??[]));if(!s)return null;let f=new Map,u=new Map;for(let p of Xr()){let m=Bt(p),g=kt(p);!m||!g||(f.set(p,m),u.set(p,{x:m.x-g.x,y:m.y-g.y}))}return f.size===0?null:{bounds:s,frames:f,offsets:u}}function Cd(s,f){let u=kl(s.frames,s.bounds,f),p=[];for(let[m,g]of u){let b=s.frames.get(m),_=s.offsets.get(m);if(!b||!_)continue;let L=Ht(m),I=L===0?g:Pu(b,L,s.bounds,f);p.push({nodeId:m,prop:"x",from:b.x-_.x,to:I.x-_.x},{nodeId:m,prop:"y",from:b.y-_.y,to:I.y-_.y},{nodeId:m,prop:"w",from:b.w,to:I.w},{nodeId:m,prop:"h",from:b.h,to:I.h})}return p}function Tp(s,f){let u=gd();if(!u)return!1;let p=re().length===1&&u.length===1?u[0]:void 0,m=at(re().flatMap(_=>Me(_)??[])),g=p!==void 0?Bt(p):m;if(!g)return!1;let b=u.flatMap(_=>{let L=Bt(_),I=kt(_);return!L||!I?[]:[{id:_,frame:L,rotation:Ht(_),offset:{x:L.x-I.x,y:L.y-I.y}}]});return b.length===0?!1:(Je(f),Ve({kind:"rotate",pointerId:f,origin:s,centre:Ge(g),targets:b}),!0)}function Lp(s,f,u){let p=_d();return p?(Je(u),Ve({kind:"scale",pointerId:u,origin:s,handle:f,...p}),!0):!1}function Op(s){let f=_d();if(!f)return;let u=qr(r,Cd(f,s));if(u.length===0)return;let p=s.w!==f.bounds.w||s.h!==f.bounds.h;ce([...u,...Kr(r,u,Lr(r),Ae(r))],p?"Resize":"Move")}function Dp(s,f,u){let p=ya(s),m=Wr();if(!p||!m)return!1;let g=ut(m,p.axis)?.gaps[p.index],b=eo(re());return g===void 0||b.length===0?!1:(Je(u),Ve({kind:"space",pointerId:u,origin:f,axis:p.axis,spacer:s,layout:m,gap:g,parts:b}),!0)}function Pp(s,f){let u=s.axis==="x"?f.x-s.origin.x:f.y-s.origin.y,p=Math.max(0,s.gap+u);Vt(Ba(s.parts,s.axis,va(s.layout,s.axis,p)))}function Np(s,f){let u=Wr(),p=u?ut(u,s):void 0;if(!u||!p||p.gaps.length===0)return;let m=qr(r,Ba(eo(re()),s,va(u,s,Math.max(0,f))));m.length!==0&&ce([...m,...Kr(r,m,Lr(r),Ae(r))],"Spacing")}function Rp(s){let f=Wr(),u=f?ut(f,s)?.gaps:void 0;return!u||u.length===0?null:Fl(u)?u[0]??null:"mixed"}function Ba(s,f,u){return s.map(p=>{let m=f==="x"?p.frame.x:p.frame.y;return{nodeId:p.node,prop:f,from:m,to:m+(u.get(p.member)??0)}})}function Ip(s,f,u){let p=Wr();if(!p||!p.order.includes(s))return!1;let m=eo(re()),g=p.items.find(b=>b.id===s)?.frame;return m.length===0||!g?!1:(Je(u),Ve({kind:"reorder",pointerId:u,id:s,layout:p,parts:m,grab:{x:f.x-g.x,y:f.y-g.y},to:p.order.indexOf(s),swap:!1}),!0)}function Fp(s,f,u){s.to=Vl(s.layout,f),s.swap=u;let p=Bp(s),m=new Map(p);m.set(s.id,{x:f.x-s.grab.x,y:f.y-s.grab.y}),Fa(Ia(Ed(s,m)),Ia(Ed(s,p)))}function Bp(s){let f=s.layout.order.indexOf(s.id);if(f===-1||s.to===f)return new Map;if(s.swap){let u=s.layout.order[s.to];return u===void 0?new Map:jl(s.layout,s.id,u)}return Kl(s.layout,ql(s.layout.order,f,s.to))}function Ed(s,f){let u=new Map(s.layout.items.map(m=>[m.id,m.frame])),p=[];for(let m of s.parts){let g=f.get(m.member),b=u.get(m.member);!g||!b||p.push({nodeId:m.node,prop:"x",from:m.frame.x,to:m.frame.x+(g.x-b.x)},{nodeId:m.node,prop:"y",from:m.frame.y,to:m.frame.y+(g.y-b.y)})}return p}function Ve(s,f=[],u=r){ke=u,Se=f,xe=r,A=s,te=[],M=Lr(r),T=Ae(r),O=We,F=Hp(s)?_l(r,T,zp(s)):[]}function Hp(s){return s.kind==="move"||s.kind==="resize"||s.kind==="scale"||s.kind==="create"}function zp(s){return s.kind==="move"||s.kind==="scale"?new Set(re()):s.kind==="resize"?new Set([s.id]):new Set}function Zr(s){return s.metaKey||s.ctrlKey?0:Sl/C.getCamera().zoom}function St(s){let f=[...Se,...te];A=null,te=[],Se=[],w=null,$=null,O=We,r=ke,C.update(r),ce(f,s),Z()}function Up(){let s=te.length>0?be(xe,te).document:xe,f=new Set(re().flatMap(m=>Md(m,s))),u=[];for(let m of re()){let g=q(s.root,m),b=rt(s.root,m);if(!g||!b)continue;let _=Me(m);if(!_)continue;let L={x:_.x+_.w/2,y:_.y+_.h/2},I=Zn(L,f)??r.root.id;if(I===b.id)continue;let K=q(s.root,I);if(!K||!pe(K))continue;u.push({op:"move",id:m,parent:I,index:ae(K).length});let Y={x:zt(b.id).x-zt(I).x,y:zt(b.id).y-zt(I).y};if(!(Y.x===0&&Y.y===0))for(let fe of sr(m,s)){let W=kt(fe);W&&(u.push({op:"set",id:fe,prop:"x",value:ee(W.x+Y.x)}),u.push({op:"set",id:fe,prop:"y",value:ee(W.y+Y.y)}))}}if(u.length===0)return[];let p=be(s,u).document;return[...u,...jr(s,p,f)]}function Md(s,f){let u=q(f.root,s);if(!u)return[];let p=[];return se(u,m=>{p.push(m.id)}),p}function Ha(){if(!A)return;A=null,te=[],w=null,$=null,O=We;let s=Se.length>0;r=ke,Se=[],s&&le(n.filter(f=>q(r.root,f))),C.update(r),Z()}let Vp=5,oo=8;function Ad(s,f=r,u=C.getResolution()){let p=q(f.root,s),m=u.nodes.get(s);if(p?.type!=="vector"||!m)return;let g={x:m.absX,y:m.absY,w:Math.max(0,m.w),h:Math.max(0,m.h)};return{node:p,view:mn(p.view,g.w,g.h),box:g}}function Qr(s,f=r,u=C.getResolution()){let p=Ad(s,f,u);if(p)return xt(cn(p.node.d).contours,xn(p.view,p.box))}function _t(s,f,u,p=r,m=C.getResolution()){let g=Ad(s,p,m);if(!g)return[];let{node:b,view:_,box:L}=g,I=xt(f,ls(_,L)),K=[],Y=(tt,gr,Eh)=>{gr!==Eh&&K.push({op:"set",id:s,prop:tt,value:gr})};Y("d",mt(I),b.d);let fe=[b.x,b.y,b.w,b.h].every(tt=>typeof tt=="number"),W=Zt(I),he=Zt(f);if(!u||!fe||!W||!he)return K;let Oe=L.x-b.x,De=L.y-b.y;return Y("view",Qt(W),b.view),Y("x",ee(he.x-Oe),b.x),Y("y",ee(he.y-De),b.y),Y("w",ee(he.w),b.w),Y("h",ee(he.h),b.h),K}function qt(s){return q(r.root,s)?.type!=="vector"||!Ut(s)?!1:(z&&cr("done"),U&&ao(),le([s]),V={id:s,picked:new Set},o!=="select"&&Ct("select"),Ye(null),Z(),!0)}function en(){V&&(V=null,Z())}function qp(){if(U){let u=U.contours[U.contour],p=u?.anchors??[],m=p[p.length-1],g=p[0],b=U.hover,_=b!==null&&g!==void 0&&p.length>=2&&!u?.closed&&tn(g,b)<=oo;return{contours:U.contours,anchors:p.map((L,I)=>({key:$e(U?.contour??0,I),at:L,selected:I===p.length-1})),handles:m?Si(U.contours,new Set([$e(U.contour,p.length-1)])):[],pending:m&&b&&!U.dragging&&!u?.closed?{from:m,...m.out?{c1:m.out}:{},to:b}:null,closeAt:_?g:null}}if(!V)return null;let s=Qr(V.id);if(!s)return null;let f=new Set(wi(s,V.picked));return{contours:s,anchors:s.flatMap((u,p)=>u.anchors.map((m,g)=>({key:$e(p,g),at:m,selected:f.has($e(p,g))}))),handles:Si(s,f)}}function tn(s,f){return Math.hypot(s.x-f.x,s.y-f.y)*C.getCamera().zoom}function Kp(s,f,u,p){if(!V)return!1;let m=V.id,g=Qr(m);if(!g)return V=null,!1;s.preventDefault(),Je(s.pointerId);let b=G.hitPath(f);if(b?.kind==="handle"){let L=Nu(b.key),I=L?g[L.contour]?.anchors[L.index]:void 0;if(L&&I)return Ve({kind:"pathHandle",pointerId:s.pointerId,id:m,start:g,contour:L.contour,index:L.index,side:L.side,smooth:Wo(I),last:g}),!0}if(b?.kind==="anchor")return s.altKey?(V.picked=new Set([b.key]),ce(_t(m,Ru(g,b.key),!1),"Convert point"),!0):(s.shiftKey?V.picked.has(b.key)?V.picked.delete(b.key):V.picked.add(b.key):V.picked.has(b.key)||(V.picked=new Set([b.key])),Ve({kind:"points",pointerId:s.pointerId,id:m,origin:u,start:g,keys:new Set(V.picked),lead:b.key,moved:!1,last:g}),Z(),!0);let _=fs(g,u);if(_&&_.distance*C.getCamera().zoom<=Vp){if(p>=2){let Y=us(g,_.contour,_.segment,_.t);return V.picked=new Set([$e(_.contour,_.segment+1)]),ce(_t(m,Y,!1),"Add point"),!0}let L=g[_.contour],I=L.anchors[_.segment],K=L.anchors[(_.segment+1)%L.anchors.length];return Ve({kind:"segment",pointerId:s.pointerId,id:m,origin:u,start:g,contour:_.contour,segment:_.segment,t:_.t,straight:!I?.out&&!K?.in,last:g}),!0}return Ve({kind:"pointMarquee",pointerId:s.pointerId,origin:u,current:u,additive:s.shiftKey}),!0}function jp(s,f,u,p){let m=bi(s.start,s.lead);if(!m||p===0)return{dx:f,dy:u};let g=m.x+f,b=m.y+u,_=p,L=p,I=f,K=u;return s.start.forEach((Y,fe)=>Y.anchors.forEach((W,he)=>{s.keys.has($e(fe,he))||(Math.abs(W.x-g)<_&&(_=Math.abs(W.x-g),I=W.x-m.x),Math.abs(W.y-b)<L&&(L=Math.abs(W.y-b),K=W.y-m.y))})),{dx:I,dy:K}}function Gp(s,f){if(!A)return!1;let u=(p,m)=>{T&&Fa(_t(m,p,!1,xe,T))};switch(A.kind){case"points":{let p=f;s.shiftKey&&(p=Pn(A.origin,f));let m={dx:p.x-A.origin.x,dy:p.y-A.origin.y};if(!A.moved&&Math.hypot(m.dx,m.dy)*C.getCamera().zoom<Ft)return!0;A.moved=!0;let{dx:g,dy:b}=s.shiftKey?m:jp(A,m.dx,m.dy,Zr(s));return A.last=Jo(A.start,A.keys,g,b),u(A.last,A.id),!0}case"pathHandle":{let p=A.start[A.contour]?.anchors[A.index],m=s.shiftKey&&p?Pn(p,f):f;return A.last=Xo(A.start,A.contour,A.index,A.side,m,{smooth:A.smooth,breakSmooth:s.altKey}),u(A.last,A.id),!0}case"segment":return A.last=Fu(A.start,A.contour,A.segment,A.t,f.x-A.origin.x,f.y-A.origin.y,A.straight),u(A.last,A.id),!0;case"pointMarquee":return A.current=f,Z(),!0;default:return!1}}function Wp(s){if(!A)return!1;switch(A.kind){case"points":case"pathHandle":case"segment":{let f=A.kind!=="points"||A.moved,u=A.kind==="points"?A.keys.size===1?"Move point":"Move points":A.kind==="pathHandle"?"Adjust curve":"Reshape";return te=f&&T?_t(A.id,A.last,!0,xe,T):[],St(u),!0}case"pointMarquee":{let f=ar(A.origin,A.current),u=A.additive;if(A=null,O=We,!V)return!0;let p=C.getCamera().zoom;if(f.w*p<Ft&&f.h*p<Ft){if(C.hitTest(s)===V.id)V.picked=new Set;else{en();let b=Qn(s);le(b===null?[]:[b])}return Z(),!0}let m=Qr(V.id)??[],g=ki(m).filter(b=>{let _=bi(m,b);return _!==void 0&&st(f,_.x,_.y)});return V.picked=new Set(u?[...V.picked,...g]:g),Z(),!0}default:return!1}}function Xp(s){if(!V)return!1;let f=V.id,u=s.metaKey||s.ctrlKey;if(s.key==="Escape"||s.key==="Enter"&&!u)return s.preventDefault(),A?Ha():en(),!0;let p=Qr(f);if(!p)return!1;let m=new Set(wi(p,V.picked));if(s.key==="Delete"||s.key==="Backspace"){if(s.preventDefault(),m.size===0)return!0;let L=Iu(p,m);return V.picked=new Set,L.length===0?(en(),xr(),!0):(ce(_t(f,L,!0),m.size===1?"Delete point":"Delete points"),!0)}let g=s.shiftKey?10:1,_={ArrowLeft:[-g,0],ArrowRight:[g,0],ArrowUp:[0,-g],ArrowDown:[0,g]}[s.key];return _&&!u?(s.preventDefault(),m.size>0&&ce(_t(f,Jo(p,m,_[0],_[1]),!0),"Nudge points"),!0):u&&s.key.toLowerCase()==="a"?(s.preventDefault(),V.picked=new Set(ki(p)),Z(),!0):u&&!s.shiftKey&&s.code==="KeyJ"?(s.preventDefault(),ce(_t(f,Bu(p,m),!0),"Close path"),!0):!1}function Yp(s,f){if(s.preventDefault(),Je(s.pointerId),!U){U=Jp(f)??{contours:[{closed:!1,anchors:[{x:f.x,y:f.y}]}],contour:0,target:null,hover:null,dragging:null};let b=U.contours[U.contour];U.dragging={pointerId:s.pointerId,index:b.anchors.length-1,origin:f},Z();return}let u=U.contours[U.contour],p=u.anchors[0],m=u.anchors[u.anchors.length-1];if(p&&u.anchors.length>=2&&tn(p,f)<=oo){U.contours[U.contour]={...u,closed:!0},U.dragging={pointerId:s.pointerId,index:0,origin:p},Z();return}let g=s.shiftKey&&m?Pn(m,f):f;U.contours[U.contour]={...u,anchors:[...u.anchors,{x:g.x,y:g.y}]},U.dragging={pointerId:s.pointerId,index:u.anchors.length,origin:g},Z()}function Jp(s){let f=n.length===1?n[0]:null;if(f===null||!Ut(f))return null;let u=Qr(f);if(!u)return null;for(let p=0;p<u.length;p+=1){let m=u[p];if(m.closed||m.anchors.length<1)continue;let g=m.anchors[0],b=m.anchors[m.anchors.length-1],_=tn(b,s)<=oo,L=!_&&tn(g,s)<=oo;if(!_&&!L)continue;let I=[...u];return L&&(I[p]=Hu(m)),{contours:I,contour:p,target:f,hover:null,dragging:null}}return null}function Zp(s,f){if(!U)return;let u=U.dragging;if(!u||u.pointerId!==s.pointerId){let L=U.contours[U.contour],I=L?.anchors[L.anchors.length-1];U.hover=s.shiftKey&&I?Pn(I,f):f,Z();return}if(tn(u.origin,f)<Ft)return;let p=U.contours[U.contour],m=p.anchors[u.index];if(!m)return;let g={x:2*m.x-f.x,y:2*m.y-f.y},b=s.altKey?m.in:g,_=[...p.anchors];_[u.index]={x:m.x,y:m.y,...b?{in:b}:{},out:f},U.contours[U.contour]={...p,anchors:_},Z()}function Qp(s){!U?.dragging||U.dragging.pointerId!==s.pointerId||(Za(s.pointerId),U.dragging=null,U.contours[U.contour]?.closed?ao():Z())}function ao(){if(!U)return;let s=U;U=null;let f=s.contours[s.contour];if(!f||f.anchors.length<2){Z();return}if(s.target!==null){ce(_t(s.target,s.contours,!0),"Extend path"),Ct("select"),qt(s.target);return}let u=Zt(s.contours),p=f.anchors[0];if(!u)return;let m=Zn(p)??v??r.root.id,g=q(r.root,m)??r.root,b=zt(m),_=xt(s.contours,I=>({x:I.x-u.x,y:I.y-u.y})),L=Lt(r.root,"path");ce([{op:"insert",parent:m,index:ae(g).length,node:xo({id:L,x:ee(u.x-b.x),y:ee(u.y-b.y),w:ee(u.w),h:ee(u.h),view:Qt({x:0,y:0,w:u.w,h:u.h}),d:mt(_),fill:"none",stroke:t.defaultStroke??"#1f2937",strokeWidth:2,cap:"round",join:"round"})}],"Draw path"),Ct("select"),qt(L)}function za(s=re()){let f=[],u=[];for(let p of s){let m=q(r.root,p),g=rt(r.root,p),b=ct(p);if(!m||!g||!b||m.type!=="rect"&&m.type!=="ellipse")continue;let _=Math.max(0,b.w),L=Math.max(0,b.h),I=m.type==="rect"?cs(_,L,b.values.radius??0):ps(_,L),K=xo({id:p,...m.name===void 0?{}:{name:m.name},x:m.x,y:m.y,w:m.w,h:m.h,view:Qt({x:0,y:0,w:_,h:L}),d:mt(I),...m.fill===void 0?{}:{fill:m.fill},...m.stroke===void 0?{}:{stroke:m.stroke},...m.strokeWidth===void 0?{}:{strokeWidth:m.strokeWidth},...m.opacity===void 0?{}:{opacity:m.opacity},...m.hidden?{hidden:!0}:{},...m.locked?{locked:!0}:{}}),Y=g.children.findIndex(fe=>fe.id===p);f.push({op:"remove",id:p},{op:"insert",parent:g.id,index:Y,node:K}),u.push(p)}u.length!==0&&(ce(f,u.length===1?"Convert to vector":`Convert ${u.length} to vector`),le(u),u.length===1&&qt(u[0]))}function $d(){return re().filter(s=>{let f=q(r.root,s)?.type;return f==="rect"||f==="ellipse"}).length}let eh=450,Td=4,rn={x:0,y:0,at:0,count:0};function th(s){let f=Date.now(),p=Math.abs(s.x-rn.x)<=Td&&Math.abs(s.y-rn.y)<=Td&&f-rn.at<=eh?rn.count+1:1;return rn={x:s.x,y:s.y,at:f,count:p},p}let Ld=s=>{if(s.button!==0||x)return;let f=C.pointerPoint(s),u=C.screenToDocument(f);X=u;let p=th(f);if(z){let L=Na(u),I=C.itemOf(z.id),K=Yr(z.id,u);if(L&&I&&st(I,K.x,K.y)){s.preventDefault(),Je(s.pointerId),Le=!0,p>=3?z.selectLineAt(L):p===2?z.selectWordAt(L):z.pointTo(L,s.shiftKey),ne.focus({preventScroll:!0}),Z();return}cr("blur")}if(e.focus({preventScroll:!0}),o==="select"&&(s.metaKey||s.ctrlKey)&&cp(u)){s.preventDefault();return}if(o==="pen"){Yp(s,u);return}if(V&&o==="select"&&Kp(s,f,Yr(V.id,u),p))return;if(o!=="select"){s.preventDefault(),Je(s.pointerId),Ve({kind:"create",pointerId:s.pointerId,origin:u,current:u}),Z();return}let m=re().length===1?re()[0]:null;if(m!==null){let L=q(r.root,m),I=G.hitAdjuster(f),K=L&&I?ea(L,I.id):void 0,Y=K?Me(m):void 0;if(K&&Y&&I){s.preventDefault(),Je(s.pointerId),Ve({kind:"adjust",pointerId:s.pointerId,id:m,adjuster:K,handleId:I.id,frame:Y,from:ct(m)?.values[K.prop]??0});return}let fe=L&&!pe(L)?G.hitHandle(f):null,W=fe?kt(m):void 0,he=W?Bt(m):void 0;if(fe&&W&&he){s.preventDefault(),Je(s.pointerId),Ve({kind:"resize",pointerId:s.pointerId,origin:u,id:m,handle:fe.handle,frame:W,offset:{x:he.x-W.x,y:he.y-W.y},rotation:Ht(m)});return}}let g=re().length>0?G.hitHandle(f):null;if(g&&Lp(u,g.handle,s.pointerId)){s.preventDefault();return}let b=G.hitPageLabel(f);if(b!==null){if(s.preventDefault(),v=null,s.shiftKey){le(n.includes(b)?n.filter(L=>L!==b):[...n,b]);return}if(n.includes(b)||le([b]),p===2){Cp(b);return}Od(u,s.pointerId,s.altKey);return}if(re().length>0&&G.hitRotate(f)!==null&&Tp(u,s.pointerId)){s.preventDefault();return}if(re().length>1){let L=G.hitRing(f);if(L!==null&&Ip(L,u,s.pointerId)){s.preventDefault();return}let I=G.hitSpacer(f);if(I!==null&&Dp(I,u,s.pointerId)){s.preventDefault();return}}let _=Qn(u);if(_===null){s.preventDefault(),Je(s.pointerId),v=null,s.shiftKey||le([]),Ve({kind:"marquee",pointerId:s.pointerId,origin:u,current:u});return}v!==null&&!Fe(r.root,_).includes(v)&&(v=null),s.shiftKey?le(n.includes(_)?n.filter(L=>L!==_):[...n,_]):n.includes(_)||le([_]),Od(u,s.pointerId,s.altKey)&&s.preventDefault()};function Od(s,f,u){let p=r,m=[];if(u){let b=Qd({x:0,y:0});b&&(m=b.ops,r=be(r,m).document,C.update(r),le(b.ids))}let g=new Map;for(let b of re())for(let _ of sr(b,r)){let L=kt(_);L&&g.set(_,L)}return g.size===0?(r=p,C.update(r),!1):(Je(f),Ve({kind:"move",pointerId:f,origin:s,frames:g,bounds:at(re().flatMap(b=>Me(b)??[]))},m,p),!0)}let Dd=s=>{let f=C.pointerPoint(s);if(X=C.screenToDocument(f),Le&&z){let p=Na(X);p&&z.pointTo(p,!0);return}if(U&&o==="pen"){Zp(s,X);return}if(!A){ah(f);return}if(A.pointerId!==s.pointerId)return;let u=X;if(!Gp(s,V?Yr(V.id,u):u))switch(A.kind){case"move":{let p=u.x-A.origin.x,m=u.y-A.origin.y;if(A.bounds){let b={...A.bounds,x:A.bounds.x+p,y:A.bounds.y+m};O=Cl(b,F,Zr(s)),p+=O.dx,m+=O.dy}let g=[];for(let[b,_]of A.frames)g.push({nodeId:b,prop:"x",from:_.x,to:_.x+p}),g.push({nodeId:b,prop:"y",from:_.y,to:_.y+m});Vt(g);return}case"resize":{let{id:p,handle:m,frame:g,origin:b,offset:_,rotation:L}=A,I=u.x-b.x,K=u.y-b.y;if(L!==0){O=We;let W=Lu(g,m,I,K,L);Vt(Go(g,W).map(he=>({nodeId:p,prop:he,from:g[he],to:W[he]})));return}let Y=yt(g,m,I,K);O=ia({...Y,x:Y.x+_.x,y:Y.y+_.y},m,F,Zr(s)),I+=O.dx,K+=O.dy;let fe=yt(g,m,I,K);Vt(Go(g,fe).map(W=>({nodeId:p,prop:W,from:g[W],to:fe[W]})));return}case"scale":{let{handle:p,bounds:m,origin:g,frames:b,offsets:_}=A,L=u.x-g.x,I=u.y-g.y,K=yt(m,p,L,I);O=ia(K,p,F,Zr(s)),L+=O.dx,I+=O.dy,Vt(Cd({bounds:m,frames:b,offsets:_},yt(m,p,L,I)));return}case"space":Pp(A,u);return;case"reorder":Fp(A,u,s.metaKey||s.ctrlKey);return;case"rotate":{let{centre:p,origin:m,targets:g}=A,b=g[0],_=Ou(p,m,u,b?.rotation??0,s.shiftKey?sy:void 0);$=kn((b?.rotation??0)+_);let L=[],I=g.length===1;for(let K of Du(g,p,_)){let Y=g.find(fe=>fe.id===K.id);Y&&(L.push({nodeId:K.id,prop:"rotation",from:Y.rotation,to:K.rotation}),!I&&L.push({nodeId:K.id,prop:"x",from:Y.frame.x-Y.offset.x,to:ee(K.frame.x-Y.offset.x)},{nodeId:K.id,prop:"y",from:Y.frame.y-Y.offset.y,to:ee(K.frame.y-Y.offset.y)}))}Vt(L);return}case"adjust":{let p=A.adjuster.valueAt(A.frame,A.handleId,u);w=p,Vt([{nodeId:A.id,prop:A.adjuster.prop,from:A.from,to:p}]);return}case"create":{O=El(u,F,Zr(s));let p={x:u.x+O.dx,y:u.y+O.dy};A.current=s.shiftKey&&o!=="text"?dy(A.origin,p):p,Z();return}case"marquee":{A.current=u,Z();return}}},so=s=>{if(Le){Le=!1,Za(s.pointerId),ne.focus({preventScroll:!0});return}if(U){Qp(s);return}if(!A||A.pointerId!==s.pointerId)return;Za(s.pointerId);let f=C.screenToDocument(C.pointerPoint(s));if(!Wp(V?Yr(V.id,f):f))switch(A.kind){case"create":{let u=ar(A.origin,A.current),p=o==="text"?"text":o==="frame"?"frame":o==="ellipse"?"ellipse":"rect";A=null,O=We,Z();let m=u.w<Ft||u.h<Ft;if(m&&p!=="text")return;let g=m?{x:u.x,y:u.y,w:Hc.w,h:Hc.h}:u,b=Zn({x:g.x,y:g.y})??v??r.root.id,_=q(r.root,b)??r.root,L=zt(b),I={x:Math.round(g.x-L.x),y:Math.round(g.y-L.y),w:Math.round(g.w),h:Math.round(g.h)},K=Lt(r.root,p);ce([{op:"insert",parent:b,index:ae(_).length,node:p==="text"?ns({...I,id:K,content:""}):p==="frame"?mo({...I,id:K,background:Fc,children:[]}):p==="ellipse"?Qa({...I,id:K,fill:t.defaultFill??"#3b82f6"}):rs({...I,id:K,fill:t.defaultFill??"#3b82f6"})}],ly[p]),le([K]),Ct("select"),p==="text"&&Jr(K);return}case"marquee":{let u=ar(A.origin,A.current),p=s.shiftKey;if(A=null,O=We,u.w>=Ft||u.h>=Ft){let m=Ch(u);le(p?[...new Set([...n,...m])]:m)}Z();return}case"move":{let u=Up();u.length>0&&(te=[...te,...u]),St(Se.length>0?"Duplicate":"Move");return}case"resize":St("Resize");return;case"scale":St(n.length===1?"Resize group":`Resize ${n.length} elements`);return;case"space":St("Spacing");return;case"reorder":St(A.swap?"Swap":"Reorder");return;case"adjust":St("Corner radius");return;case"rotate":St("Rotate");return}},Pd=s=>{if(Aa(s.target))return;if(z){if(!((s.metaKey||s.ctrlKey)&&s.key.toLowerCase()==="z"))return;s.preventDefault(),z.breakBurst(),s.shiftKey?uo():on();return}if(U&&(s.key==="Enter"||s.key==="Escape")){s.preventDefault(),ao();return}if(Xp(s))return;if((s.metaKey||s.ctrlKey)&&s.shiftKey&&s.code==="KeyO"){if($d()===0)return;s.preventDefault(),za();return}if(s.key==="Enter"&&!Uc(s)&&n.length===1){let p=n[0];if(q(r.root,p)?.type==="vector"&&qt(p)){s.preventDefault();return}}if(s.key==="Enter"&&!Uc(s)&&n.length===1){let p=n[0];if(q(r.root,p)?.type==="text"){s.preventDefault(),Jr(p);return}}if(s.code==="Space"&&!x){x=!0,Re(Te("grab"));return}let f=s.metaKey||s.ctrlKey;if(f&&s.key.toLowerCase()==="z"){s.preventDefault(),s.shiftKey?uo():on();return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyL"){if(!D.lock||n.length===0)return;s.preventDefault(),mr(n,"locked");return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyH"){if(!D.hide||n.length===0)return;s.preventDefault(),mr(n,"hidden");return}if(f&&s.key.toLowerCase()==="g"){s.preventDefault(),s.shiftKey?Wa():Ga();return}if(f&&s.key.toLowerCase()==="a"){s.preventDefault(),Ya();return}if(f&&!s.altKey&&s.key.toLowerCase()==="d"){s.preventDefault(),Ka();return}if(s.altKey){let p=fy[s.code];if(p&&!f){s.preventDefault(),Xd(p);return}let m=uy[s.code];if(m&&s.ctrlKey){s.preventDefault(),Jd(m);return}}if(s.key==="]"||s.key==="["){if(n.length===0)return;s.preventDefault();let p=s.key==="]";Xa(f?p?"front":"back":p?"forward":"backward");return}if(s.key==="Escape"){A?Ha():v!==null?af():le([]);return}if(s.key==="Delete"||s.key==="Backspace"){if(n.length===0)return;s.preventDefault(),xr();return}let u=f||s.altKey?void 0:rd[s.key.toLowerCase()];u&&Ct(u)};function Nd(){if(!z)return null;let s=q(r.root,z.id);if(s?.type!=="text")return null;let{anchor:f,head:u}=z.getSelection();return f===u?null:fr(Gl(s.content,f,u))}let Rd=s=>{if(Aa(s.target))return;let f=Nd()??nn();f!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",f))},Id=s=>{if(Aa(s.target))return;let f=Nd();if(f!==null&&z){s.preventDefault(),s.clipboardData?.setData("text/plain",f);let{anchor:p,head:m}=z.getSelection();z.breakBurst(),z.setSelection(p,m),z.handleInput({inputType:"deleteByCut",data:null});return}let u=nn();u!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",u),xr())},Fd=s=>{if(Aa(s.target))return;s.preventDefault();let f=_i(s.clipboardData);if(f&&!z){let p=hh();p?qa(p,f):tf(f,X??void 0);return}let u=s.clipboardData?.getData("text/plain")||void 0;if(z&&u!==void 0){z.handleInput({inputType:"insertFromPaste",data:u});return}Va(u)},Bd=s=>{s.code==="Space"&&(x=!1,Re(Te(Pa())))},Hd=s=>{if(!ye)return;s.preventDefault(),A&&Ha();let f=C.pointerPoint(s),u=C.screenToDocument(f),p=Qn(u),m=rh(u),g=C.hitTest(u),b=g!==null&&n.some(L=>Fe(r.root,g).includes(L));p===null?b||le([]):n.includes(p)||le([p]);let _=(t.menuExtras?.(n)??[]).map(L=>"separator"in L?L:{...L,id:`${od}${L.id}`});ye.open(f,Ll(nh(m),_))};function rh(s){let{locked:f}=ze(),u=[];for(let p of[...C.getScene().items].reverse()){if(!f.has(p.id)||!C.hitTest(s,g=>g===p.id))continue;let m=an(r.root,p.id,"locked");m!==void 0&&!u.includes(m)&&u.push(m)}return u}function nh(s=[]){let f=n.length===1?q(r.root,n[0]):void 0,u=[];if(f){let p=f;for(let m of it(f)){let g=p[m];g===void 0||!me(g)||Ro(g).kind!=="literal"&&u.push({prop:m,source:`=${g.expr}`})}}return{count:n.length,hasGroup:n.some(p=>{let m=q(r.root,p);return m!==void 0&&_e(m)}),canPaste:ad!==null,isText:n.length===1&&q(r.root,n[0])?.type==="text",isVector:re().length===1&&q(r.root,re()[0])?.type==="vector",convertible:$d(),bound:u,lock:D.lock?n.every(p=>ze().locked.has(p))?"unlock":"lock":null,hide:D.hide?n.every(p=>ze().hidden.has(p))?"show":"hide":null,locksHere:s,anyLocked:Ja("locked").length>0,hiddenCount:Ja("hidden").length}}function oh(s){if(e.focus({preventScroll:!0}),s.startsWith(od)){t.onMenuCommand?.(s.slice(od.length),[...n]);return}if(s.startsWith("unlock:")){hr([s.slice(7)],"locked",!1);return}if(s.startsWith("detach:")){let f=s.slice(7),u=n[0];u!==void 0&&df(u,f);return}switch(s){case"copy":nn();return;case"cut":ef();return;case"editText":{let f=n[0];f!==void 0&&Jr(f);return}case"editPoints":{let f=n[0];f!==void 0&&qt(f);return}case"toVector":return za();case"duplicate":return Ka();case"paste":return Va();case"group":return Ga();case"ungroup":return Wa();case"front":case"forward":case"backward":case"back":return Xa(s);case"delete":return xr();case"selectAll":return Ya();case"toggleLock":return mr(n,"locked");case"toggleHidden":return mr(n,"hidden");case"unlockAll":return fo("locked");case"showAll":return fo("hidden");case"fit":return C.fitToContent();case"zoom100":return C.setCamera({...C.getCamera(),zoom:1})}}let zd=s=>{if(o!=="select"||x||V)return;let f=C.screenToDocument(C.pointerPoint(s)),u=C.hitTest(f,_=>!ze().locked.has(_));if(u===null)return;let p=lo().find(_=>_.id===u);if(p){s.preventDefault(),mh(p);return}let m=q(r.root,u);if(m?.type==="text"){s.preventDefault(),Jr(u,f);return}if(m?.type==="vector"){s.preventDefault(),qt(u);return}let g=Fe(r.root,u),b=v===null?1:g.indexOf(v)+1;for(let _=Math.max(b,1);_<g.length;_+=1){let L=g[_];if(L===void 0)break;let I=q(r.root,L);if(!(!I||!_e(I))){s.preventDefault(),of(L),le([g[_+1]??L]);return}}},Ud=s=>Array.from(s.dataTransfer?.types??[]).includes("Files"),Vd=s=>{if(!Ud(s)||!t.importImage)return;s.preventDefault(),s.dataTransfer&&(s.dataTransfer.dropEffect="copy");let f=C.screenToDocument(C.pointerPoint(s)),u=rf(f)?.id??null;u!==c&&(c=u,Z())},qd=s=>{s.relatedTarget instanceof Node&&e.contains(s.relatedTarget)||c!==null&&(c=null,Z())},Kd=s=>{if(!Ud(s)||!t.importImage)return;s.preventDefault();let f=C.screenToDocument(C.pointerPoint(s)),u=rf(f);c=null,Z();let p=Array.from(s.dataTransfer?.files??[]).find(m=>m.type.startsWith("image/"));p&&(u?qa(u,p):tf(p,f))},jd=()=>{X=null,l=null,!A&&(a===null&&H===null&&j===null||(a=null,H=null,j=null,Z()))};function Gd(){let s=re().length===1?re()[0]:void 0,f=s===void 0?void 0:q(r.root,s);return s!==void 0&&f&&!pe(f)?Ht(s):0}function ah(s){if(x){Re(Te("grab"));return}if(V){Ye(null),Re(Te("arrow"));return}if(o!=="select"){Ye(null),Ua(null),io(null),Re(Te(o==="text"?"text":"crosshair"));return}let f=re().length===1?re()[0]:null;if(f!==null){let g=G.hitAdjuster(s);if(g){let b=q(r.root,f),_=b?ea(b,g.id):void 0;Ye(null),Ua(_?{id:g.id,prop:_.prop}:null),Re(Te("radius",{badge:_?Da(f,[_.prop]):"none"}));return}Ua(null)}if(re().length>0){let g=G.hitHandle(s);if(g){Ye(null);let L=jo(g.handle);Re(Te("resize",{angle:xi(g.handle)+Gd(),badge:yd(Xr(),L)}));return}let b=G.hitPageLabel(s);if(b!==null){Ye(b),Re(Te("arrow"));return}let _=G.hitRotate(s);if(_!==null){Ye(null),Re(Te("rotate",{angle:iy[_]+Gd()}));return}}let u=G.hitPageLabel(s);if(u!==null){l=null,Ye(u),Re(Te("arrow"));return}if(re().length>1){if(G.hitRing(s)!==null){Ye(null),io(null),Re(Te("grab"));return}let b=G.hitSpacer(s),_=b===null?null:ya(b);if(b!==null&&_){Ye(null),io(b),Re(Te("resize",{angle:_.axis==="x"?0:90,badge:yd(Xr(),[_.axis])}));return}io(null)}let p=C.screenToDocument(s),m=Qn(p);l=sh(p,m),Ye(m),Z(),Re(Te("arrow",{badge:m===null?"none":Da(m,["x","y"])}))}function sh(s,f){let u=C.hitTest(s);if(u===null||!ze().locked.has(u))return null;let p=an(r.root,u,"locked");return p===void 0?null:f===null||Fe(r.root,p).includes(f)?p:null}function Ye(s){a!==s&&(a=s,Z())}function Ua(s){H?.id!==s?.id&&(H=s,Z())}function io(s){j!==s&&(j=s,Z())}function Re(s){e.style.cursor!==s&&(e.style.cursor=s)}function Ct(s){o!==s&&(o=s,U&&s!=="pen"&&ao(),s!=="select"&&en(),de?.setTool(o),s!=="select"&&Ye(null),Re(Te(Pa())),Ne("tool",o))}function ih(s){if(s.length===0)return null;if(s.length>1)return at(s.map(p=>p.frame))??null;let f=s[0],u=rt(r.root,f.id);return u?ir(u.id,r,C.getResolution())??null:null}function Wd(s,f,u){let p=qr(r,Ba(eo(n),s,f));p.length!==0&&ce([...p,...Kr(r,p,Lr(r),Ae(r))],u)}function Xd(s){let f=Hn(r,n,C.getResolution()),u=ih(f);u&&Wd(Qo(s),Ci(f,u,s),cy[s])}function Yd(s){let f=Hn(r,n,C.getResolution());if(f.length<3)return null;let u=zl(f,s),p=Ul(u);return p===null?null:{gap:p,series:u}}function Jd(s){let f=Yd(s);f&&Wd(s,ba(f.series,f.gap),s==="x"?"Distribute horizontally":"Distribute vertically")}function lh(){let s=Fn(r,n);if(s.length===0)return null;let f=C.getResolution(),u={};for(let p of s)se(p,m=>{let g=f.nodes.get(m.id)?.values;g&&(u[m.id]=g)});return{nodes:s,tokens:r.tokens,fonts:r.fonts,resolved:u}}function dh(s){return new Map(Object.entries(s.resolved))}function fh(s){let f=Object.entries(s.tokens).filter(([u])=>r.tokens[u]===void 0).map(([u,p])=>({op:"setToken",name:u,value:p}));for(let[u,p]of Object.entries(s.fonts))r.fonts[u]===void 0&&f.push({op:"setFont",name:u,family:p});return f}function Zd(s,f,u){let{nodes:p,remap:m}=yl(s,r);if(p.length===0)return null;let g=fh(s),b=g.length>0?be(r,g).document:r;p.forEach((I,K)=>{let Y=s.nodes[K];if(!Y)return;let fe=f(Y,K,b),W={op:"insert",parent:fe.parent,index:fe.index,node:I};g.push(W),b=be(b,[W]).document});let _=nd(b,m,dh(s),u);_.length>0&&(b=be(b,_).document);let L=uh(p);return{ops:[...g,..._,...jr(r,b)],ids:[...m.values()].filter(I=>L.has(I))}}function uh(s){let f=new Set;for(let u of s)f.add(u.id);return f}function Qd(s){let f=lh();return f?Zd(f,(u,p,m)=>{let g=rt(m.root,u.id)??m.root,b=ae(g).findIndex(_=>_.id===u.id);return{parent:g.id,index:b===-1?ae(g).length:b+1}},s):null}function nn(){let s=xl(r,n,C.getResolution());return s!==null&&(ad=s),s}function ef(){let s=nn();return s!==null&&xr(),s}function ch(s){let f=[];for(let u of s.nodes){let p=s.resolved[u.id];if(!p)continue;let{x:m,y:g,w:b,h:_}=p;m===void 0||g===void 0||b===void 0||_===void 0||f.push({x:m,y:g,w:b,h:_})}return at(f)??null}function Va(s,f){let u=gl(s??ad??"");if(!u)return;let p=f??X,m=ch(u),g=p&&m?{x:p.x-(m.x+m.w/2),y:p.y-(m.y+m.h/2)}:{x:Ma,y:Ma},b=v??r.root.id,_=Zd(u,(L,I,K)=>({parent:b,index:ae(q(K.root,b)??K.root).length}),g);_&&(ce(_.ops,_.ids.length===1?"Paste":`Paste ${_.ids.length} elements`),le(_.ids))}async function tf(s,f){let u=t.importImage;if(!u)return;let p=await Zo(s,t.maxImageEdge??2560);if(!p)return;let m=await u(new File([p.bytes],s.name,{type:p.type}));if(!m)return;let g=(f?Zn(f):void 0)??v??r.root.id,b=q(r.root,g)??r.root,_=zt(g),L=C.getResolution().nodes.get(g),{w:I,h:K}=zu(p.width,p.height,L?.w&&L.w>0?L.w:p.width,L?.h&&L.h>0?L.h:p.height),Y=f??X,fe=Math.round((Y?Y.x-I/2:_.x)-_.x),W=Math.round((Y?Y.y-K/2:_.y)-_.y),he=xh(r,s.name),Oe=Lt(r.root,"image");ce([{op:"setAsset",name:he,value:m},{op:"insert",parent:g,index:ae(b).length,node:ts({id:Oe,x:fe,y:W,w:I,h:K,src:he,fit:"cover"})}],"Place image"),le([Oe])}function lo(){return t.importImage?_c(r,ze().hidden):[]}function ph(){return lo().flatMap(s=>{let f=Me(s.id);return f?[{frame:f,label:s.label,target:s.id===c}]:[]})}function rf(s){return lo().filter(u=>{let p=Me(u.id);return p!==void 0&&st(p,s.x,s.y)}).at(-1)??null}function hh(){return n.length!==1?null:lo().find(s=>s.id===n[0])??null}async function qa(s,f){let u=t.importImage;if(!u)return;let p=await Zo(f,t.maxImageEdge??2560);if(!p)return;let m=await u(new File([p.bytes],f.name,{type:p.type}));!m||r.assets[s.src]!==void 0||(ce([{op:"setAsset",name:s.src,value:m}],"Add image"),le([s.id]))}function mh(s){let f=e.ownerDocument.createElement("input");f.type="file",f.accept="image/*",f.addEventListener("change",()=>{let u=f.files?.[0];u&&qa(s,u)}),f.click()}function xh(s,f){let u=f.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"image";if(s.assets[u]===void 0)return u;for(let p=2;;p+=1){let m=`${u}-${p}`;if(s.assets[m]===void 0)return m}}function Ka(){let s=Qd({x:Ma,y:Ma});s&&(ce(s.ops,s.ids.length===1?"Duplicate":`Duplicate ${s.ids.length} elements`),le(s.ids))}function ja(s,f){if(s.length===0)return;let u=be(r,s).document;ce([...s,...jr(r,u)],f)}function Ga(){let s=vl(r,n);s&&(ja(s.ops,"Group"),le([s.groupId]))}function Wa(){let s=n.filter(m=>{let g=q(r.root,m);return g!==void 0&&_e(g)});if(s.length===0)return;let f=r,u=[],p=[];for(let m of s){let g=q(f.root,m);g&&p.push(...ae(g).map(_=>_.id));let b=bl(f,m);b.length!==0&&(u.push(...b),f=be(f,b).document)}v!==null&&s.includes(v)&&(v=null),ja(u,s.length===1?"Ungroup":`Ungroup ${s.length} groups`),le(p)}function Xa(s){ja(wl(r,n,s),my[s])}function gh(s,f,u){let p=q(r.root,f);if(!p||!pe(p))return;let m=new Set(Fe(r.root,f)),g=s.filter(W=>W!==r.root.id&&q(r.root,W)&&!m.has(W));if(g.length===0)return;let b=new Set(g),_=ae(p).filter(W=>!b.has(W.id))[u]?.id,L=[],I=r;for(let W of g){let he=ae(q(I.root,f)??I.root).filter(tt=>tt.id!==W),Oe=_===void 0?-1:he.findIndex(tt=>tt.id===_),De={op:"move",id:W,parent:f,index:Oe===-1?he.length:Oe};L.push(De),I=be(I,[De]).document}if(g.every(W=>vh(r,I,W)))return;let K=new Set(g.filter(W=>rt(r.root,W)?.id!==f).flatMap(W=>Md(W,I))),Y=[];for(let W of g){let he=nf(r,W),Oe=nf(I,W),De={x:he.x-Oe.x,y:he.y-Oe.y};if(!(De.x===0&&De.y===0))for(let tt of sr(W,I)){let gr=kt(tt);gr&&(Y.push({op:"set",id:tt,prop:"x",value:ee(gr.x+De.x)}),Y.push({op:"set",id:tt,prop:"y",value:ee(gr.y+De.y)}))}}let fe=be(I,Y).document;ce([...L,...Y,...jr(r,fe,K)],g.length===1?`Move ${g[0]}`:`Move ${g.length} layers`)}function yh(s={}){let f=r.root.children,u=f.filter(Oe=>Oe.type==="frame"),p=u.find(Oe=>Oe.id===s.after),m=C.getResolution(),g=p?m.nodes.get(p.id):void 0,b=g&&g.w>0?g.w:Bc.w,_=g&&g.h>0?g.h:Bc.h,L=null,I=-1/0;for(let Oe of u.length>0?u:f){let De=m.nodes.get(Oe.id);!De||De.absX+De.w<=I||(I=De.absX+De.w,L={x:I+ay,y:De.absY})}let K=L??{x:0,y:0},Y=p??u[u.length-1],fe=Y?f.indexOf(Y)+1:f.length,W=Lt(r.root,"frame"),he=p?.type==="frame"?p.background:void 0;return ce([{op:"insert",parent:r.root.id,index:fe,node:mo({id:W,x:ee(K.x),y:ee(K.y),w:ee(b),h:ee(_),background:he??Fc,children:[]})}],"Add frame"),le([W]),W}function vh(s,f,u){let p=rt(s.root,u),m=rt(f.root,u);return p?.id===m?.id&&p?.children.findIndex(g=>g.id===u)===m?.children.findIndex(g=>g.id===u)}function nf(s,f){let u=Fe(s.root,f).slice(0,-1).reverse(),p=Ae(s);for(let m of u){let g=q(s.root,m);if(!g||_e(g))continue;let b=p.nodes.get(m);return b?{x:b.absX,y:b.absY}:{x:0,y:0}}return{x:0,y:0}}function of(s){let f=q(r.root,s);!f||!_e(f)||(v=s,Z())}function af(){if(v===null)return;let s=v;v=Fe(r.root,s).slice(0,-1).reverse().find(u=>{let p=q(r.root,u);return p!==void 0&&_e(p)})??null,le([s])}function Ya(){let s=q(r.root,v??r.root.id)??r.root;le(ae(s).map(f=>f.id).filter(Ut))}let bh={locked:["Lock","Unlock"],hidden:["Hide","Show"]};function sf(s){return s==="locked"?ze().locked:ze().hidden}function hr(s,f,u){let p=s.filter(b=>b!==r.root.id&&q(r.root,b)),m=u?p.filter(b=>!sf(f).has(b)):[...new Set(p.flatMap(b=>{let _=an(r.root,b,f);return _===void 0?[]:[_]}))];if(m.length===0)return;let g=bh[f][u?0:1];ce(m.map(b=>({op:"set",id:b,prop:f,value:u?!0:void 0})),m.length===1?`${g} ${m[0]}`:`${g} ${m.length} layers`)}function mr(s,f){s.length!==0&&hr(s,f,!s.every(u=>sf(f).has(u)))}function Ja(s){let f=[];return se(r.root,u=>{u[s]===!0&&f.push(u.id)}),f}function fo(s){let f=Ja(s);if(f.length===0)return;let u=s==="locked"?"Unlock all":"Show all";ce(f.map(p=>({op:"set",id:p,prop:s,value:void 0})),u)}function wh(s){D={...zc,...s},ye?.close()}function xr(){let s=n.filter(u=>u!==r.root.id).map(u=>({op:"remove",id:u}));if(s.length===0)return;let f=s.length;le([]),ce(s,f===1?"Delete element":`Delete ${f} elements`)}function on(){Ue=null;let s=S.undo();s&&vd(s.ops,`Undo ${s.entry.label}`)}function uo(){Ue=null;let s=S.redo();s&&vd(s.ops,`Redo ${s.entry.label}`)}function kh(s){if(!S.isTail(s))return!1;for(let f=s.length;f>0;f-=1)on();return!0}function lf(s,f,u,p){let m=q(r.root,s);if(!m)return;let g=m[f];gy(g,u)||ce([{op:"set",id:s,prop:f,value:u}],p??`Set ${f}`)}function Sh(s,f){r.tokens[s]!==f&&ce([{op:"setToken",name:s,value:f}],`Set $${s}`)}function _h(s){s in r.tokens&&ce([{op:"setToken",name:s,value:void 0}],`Remove $${s}`)}function df(s,f){let u=ct(s)?.values[f];u!==void 0&&ce([{op:"set",id:s,prop:f,value:ee(u)}],`Detach ${f}`)}function Ch(s){let f=q(r.root,v??r.root.id)??r.root,u=[];for(let p of ae(f)){if(!Ut(p.id))continue;let m=Me(p.id);m&&gi(m,s)&&u.push(p.id)}return u}function Je(s){typeof e.setPointerCapture=="function"&&e.setPointerCapture(s)}function Za(s){e.hasPointerCapture?.(s)&&e.releasePointerCapture(s)}let ff=s=>{z&&(Sd(),z.handleKey(s)&&(s.preventDefault(),s.stopPropagation()))},uf=s=>{z&&(s.preventDefault(),Sd(),z.handleInput(s))},cf=()=>z?.handleCompositionStart(),pf=s=>z?.handleCompositionUpdate(s.data??""),hf=s=>z?.handleCompositionEnd(s.data??""),mf=s=>{if(!e.ownerDocument.hasFocus())return;let f=s.relatedTarget;f instanceof Element&&f.closest("[data-vd-keeps-text]")||cr("blur")};return ne.addEventListener("keydown",ff),ne.addEventListener("beforeinput",uf),ne.addEventListener("compositionstart",cf),ne.addEventListener("compositionupdate",pf),ne.addEventListener("compositionend",hf),ne.addEventListener("blur",mf),e.addEventListener("pointerdown",Ld),e.addEventListener("pointermove",Dd),e.addEventListener("pointerup",so),e.addEventListener("pointercancel",so),e.addEventListener("pointerup",Jn),e.addEventListener("pointercancel",Jn),e.addEventListener("pointerleave",jd),e.addEventListener("dblclick",zd),e.addEventListener("contextmenu",Hd),e.addEventListener("keydown",Pd),e.addEventListener("keyup",Bd),e.addEventListener("copy",Rd),e.addEventListener("cut",Id),e.addEventListener("paste",Fd),e.addEventListener("dragover",Vd),e.addEventListener("dragleave",qd),e.addEventListener("drop",Kd),y=!0,de?.setTool(o),de?.setHistory(!1,!1),de?.setZoom(C.getCamera().zoom),Re(Te(Pa())),t.autoFit&&!t.camera&&Yn(()=>C.fitToContent()),t.history&&(S.restore(t.history),de?.setHistory(S.canUndo,S.canRedo)),t.selection&&t.selection.length>0&&le(t.selection),Z(),{element:e,viewer:C,getDocument:()=>r,update(s){r=s,C.update(r),le(n),Z(),Ne("problems",C.getScene().problems)},applyOps:(s,f)=>ce(s,f??"Apply changes"),setDocument:(s,f)=>ce(xs(r,pi(s,r.root.id)),f??"Replace document"),getSelection:()=>n,setSelection:le,selectAll:Ya,deleteSelection:xr,lock:s=>hr(s??n,"locked",!0),unlock:s=>hr(s??n,"locked",!1),toggleLock:s=>mr(s??n,"locked"),unlockAll:()=>fo("locked"),hide:s=>hr(s??n,"hidden",!0),show:s=>hr(s??n,"hidden",!1),toggleHidden:s=>mr(s??n,"hidden"),showAll:()=>fo("hidden"),isLocked:s=>ze().locked.has(s),isHidden:s=>ze().hidden.has(s),setFeatures:wh,getFeatures:()=>D,moveLayers:gh,addFrame:yh,copy:nn,cut:ef,paste:Va,duplicate:Ka,group:Ga,ungroup:Wa,reorder:Xa,scaleSelection:Op,getSpacing:Rp,setSpacing:Np,align:Xd,distribute:Jd,canDistribute:s=>Yd(s)!==null,editText:Jr,endTextEditing:()=>cr("done"),getEditingText:()=>z?.id??null,formatText:s=>z?.format(s),getTextFormat:()=>z?.activeMark()??{},getTextSelectionRects:wd,getTextRange:()=>{if(!z)return null;let{anchor:s,head:f}=z.getSelection();return{from:Math.min(s,f),to:Math.max(s,f)}},getEnteredGroup:()=>v,enterGroup:of,exitGroup:af,getTool:()=>o,editPoints:qt,stopEditingPoints:en,getPointEditing:()=>V?.id??null,convertToVector:s=>za(s),setTool:Ct,beginEdit:yp,endEdit:vp,undo:on,redo:uo,canUndo:()=>S.canUndo,canRedo:()=>S.canRedo,getHistory:()=>S.snapshot(),setProperty:lf,fontFamilies:()=>{let s=new Map;for(let f of t.fonts?.faces()??[]){let u=s.get(f.family)??{weights:new Set,italic:!1};u.weights.add(f.weight),f.style==="italic"?u.italic=!0:(u.css===void 0||f.weight===400)&&(u.css=f.id),s.set(f.family,u)}return[...s.entries()].sort(([f],[u])=>f.localeCompare(u)).map(([f,u])=>({family:f,weights:[...u.weights].sort((p,m)=>p-m),italic:u.italic,...u.css===void 0?{}:{css:u.css}}))},assetUrl:s=>{let f=r.assets[s];return f?t.resolveAsset?.(f,s):void 0},setToken:Sh,removeToken:_h,bindingsOf:gp,unbind:df,getResolution:()=>C.getResolution(),getCamera:()=>C.getCamera(),getProblems:()=>C.getScene().problems,on:up,reveal:Oa,panBy:hp,setPresence(s,f){d={ids:[...s],label:f??null},Z()},setHighlight(s){s.length===0&&h.length===0||(h=[...s],Z())},isHistoryTail:s=>S.isTail(s),undoTail:kh,historyTop:()=>S.top,destroy(){La(),e.removeEventListener("pointerup",Jn),e.removeEventListener("pointercancel",Jn),e.removeEventListener("pointerdown",Ld),e.removeEventListener("pointermove",Dd),e.removeEventListener("pointerup",so),e.removeEventListener("pointercancel",so),e.removeEventListener("pointerleave",jd),ne.removeEventListener("keydown",ff),ne.removeEventListener("beforeinput",uf),ne.removeEventListener("compositionstart",cf),ne.removeEventListener("compositionupdate",pf),ne.removeEventListener("compositionend",hf),ne.removeEventListener("blur",mf),ne.remove(),pr&&clearTimeout(pr),e.removeEventListener("dblclick",zd),e.removeEventListener("contextmenu",Hd),e.removeEventListener("copy",Rd),e.removeEventListener("cut",Id),e.removeEventListener("paste",Fd),e.removeEventListener("dragover",Vd),e.removeEventListener("dragleave",qd),e.removeEventListener("drop",Kd),e.removeEventListener("keydown",Pd),e.removeEventListener("keyup",Bd),ye?.destroy(),de?.destroy(),G.destroy(),C.destroy(),R.remove(),P.clear(),e.style.cursor="",e.classList.remove("vd-editor")}}}function gy(e,t){return e===t?!0:me(e)&&me(t)?e.expr===t.expr:!1}function Uc(e){return e.metaKey||e.ctrlKey||e.altKey}function Aa(e){if(!(e instanceof HTMLElement)||e.classList.contains("vd-editor__input"))return!1;let t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||e.isContentEditable}var w_=new Set(It);function fd(e){return e.map(t=>({value:t,label:`${t.charAt(0).toUpperCase()}${t.slice(1)}`}))}var by=[{value:"nonzero",label:"Non-zero"},{value:"evenodd",label:"Even-odd"}].filter(e=>jt.includes(e.value)),wy=fd(Gt),ky=fd($t),Sy=fd(Wt),_y=[{value:"left",label:"Left",icon:He("text-left")},{value:"center",label:"Centre",icon:He("text-center")},{value:"right",label:"Right",icon:He("text-right")},{value:"justify",label:"Justify",icon:He("text-justify")}].filter(e=>Mt.includes(e.value)),Cy=[{value:"top",label:"Top",icon:He("text-top")},{value:"middle",label:"Middle",icon:He("text-middle")},{value:"bottom",label:"Bottom",icon:He("text-bottom")}].filter(e=>At.includes(e.value)),jc={prop:"x",label:"X",kind:"number",prefix:"X"},Gc={prop:"y",label:"Y",kind:"number",prefix:"Y"},ld={prop:"w",label:"W",kind:"number",prefix:"W"},dd={prop:"h",label:"H",kind:"number",prefix:"H"},Ey={prop:"rotation",label:"Rotation",kind:"number",icon:"rotate",fallback:"0"},My={prop:"opacity",label:"Opacity",kind:"number",icon:"opacity",percent:!0,fallback:"100%"},qc={prop:"radius",label:"Radius",kind:"number",icon:"radius",span:"wide",fallback:"0"},Wn={heading:"Position",props:[jc,Gc,ld,dd,Ey,My]},$a={prop:"fill",label:"Fill",kind:"colour"},Wc={prop:"stroke",label:"Stroke",kind:"colour",span:"half"},Xc={prop:"strokeWidth",label:"Stroke width",kind:"number",prefix:"Width",fallback:"1"},Yc={present:"stroke",empty:"No stroke",add:{stroke:"#000000",strokeWidth:1},clear:["stroke","strokeWidth","cap","join"]},Kc={heading:"Stroke",props:[Wc,Xc],optional:Yc},k_={frame:[{heading:"Frame",props:[jc,Gc,ld,dd,{prop:"clip",label:"Clip content",kind:"toggle"}]},{heading:"Fill",props:[{prop:"background",label:"Fill",kind:"colour"}]}],canvas:[{heading:"Canvas",props:[ld,dd,{prop:"background",label:"Fill",kind:"colour"}]}],text:[Wn,{heading:"Text",props:[{prop:"font",label:"Font",kind:"font",fallback:"Default"},{prop:"weight",label:"Style",kind:"style",span:"half"},{prop:"size",label:"Size",kind:"number",icon:"font-size",fallback:"16"},{prop:"lineHeight",label:"Line height",kind:"number",icon:"line-height",fallback:"Auto"},{prop:"letterSpacing",label:"Letter spacing",kind:"number",icon:"letter-spacing",fallback:"0"},{prop:"align",label:"Align",kind:"segmented",options:_y,span:"half"},{prop:"valign",label:"Vertical",kind:"segmented",options:Cy,span:"half"}]},{heading:"Fill",props:[$a]},{heading:"Link",props:[{prop:"content",label:"Link",kind:"link",icon:"link"}]}],rect:[{heading:"Position",props:[...Wn.props,qc]},{heading:"Fill",props:[$a]},Kc],ellipse:[Wn,{heading:"Fill",props:[$a]},Kc],image:[{heading:"Position",props:[...Wn.props,qc]},{heading:"Image",props:[{prop:"fit",label:"Fit",kind:"select",options:ky,prefix:"Fit"}]}],vector:[Wn,{heading:"Fill",props:[{...$a,span:"half"},{prop:"rule",label:"Fill rule",kind:"select",options:by,prefix:"Rule",span:"half"}]},{heading:"Stroke",props:[Wc,Xc,{prop:"cap",label:"Cap",kind:"select",options:wy,prefix:"Cap",span:"half"},{prop:"join",label:"Join",kind:"select",options:Sy,prefix:"Join",span:"half"}],optional:Yc}]};var S_=Kt.map(e=>({value:e,label:e.split("-").map((t,r)=>r===0?t.charAt(0).toUpperCase()+t.slice(1):t).join(" ")}));function Jc(e){let t=e,r=new Map,n=typeof URL.createObjectURL=="function"&&typeof URL.revokeObjectURL=="function";return{resolve(o){let a=r.get(o.hash);if(a!==void 0)return a;let i=t.get(o.hash);if(i===void 0)return;if(!n)return As(o.type,i);let l;try{l=Ts(i)}catch{return}let d=URL.createObjectURL(new Blob([l],{type:o.type}));return r.set(o.hash,d),d},replace(o){t=o;for(let[a,i]of r)o.has(a)||(URL.revokeObjectURL(i),r.delete(a))},destroy(){for(let o of r.values())URL.revokeObjectURL(o);r.clear(),t=new Map}}}var ud="0.1.4",Zc="https://cdn.jsdelivr.net/npm/@getv.design/embed@0.1.4/fonts/";var Ny=Symbol.for(`vdesign.embed.documents@${ud}`),Qc=globalThis[Ny]??=new WeakMap,Ry=/^Line (\d+): /;function hd(e){let t=Ry.exec(e.message);return{...t?{line:Number(t[1])}:{},code:e.code,message:e.message,severity:e.severity}}function cd(e){if(typeof e!="string")return pd($o("").document,new Map,[{code:"not-text",message:`parse() takes .vd text, not ${e===null?"null":typeof e}.`,severity:"error"}]);let{head:t,blocks:r}=Cs(e),n=$o(t);return pd(n.document,r,n.problems.map(hd))}function pd(e,t,r){let n=Object.freeze({});return Qc.set(n,{document:e,blocks:t,problems:r}),{document:n,problems:r}}function ep(e,t,r){return pd(e,t,[...r]).document}function Ta(e){let t=Qc.get(e);if(!t)throw new TypeError("Not a vDesign document: pass .vd text or what parse() returned.");return t}async function tp(e){if(typeof e=="string")return Ta(cd(e).document);if(e instanceof URL){let t=await fetch(e);if(!t.ok)throw new Error(`Could not fetch ${e.href}: ${t.status}`);return Ta(cd(await t.text()).document)}return Iy(e)?Ta(cd(await e.text()).document):Ta(e)}function Iy(e){let t=e;return typeof t.text=="function"&&typeof t.size=="number"}function Gr(e){return e.root.children.filter(t=>t.type==="frame"&&t.hidden!==!0)}function rp(e,t){let r=Gr(e),n=typeof t=="number"?r[t]:r.find(o=>o.id===t);if(!n){let o=r.map(a=>a.id).join(", ")||"none";throw new RangeError(`No page ${JSON.stringify(t)} in this document; its pages: ${o}.`)}return n}var md=["page","content","none"],np=24;function Xn(e){let t=e.getBoundingClientRect();return{width:t.width,height:t.height}}function op(e,t){let r=t===void 0?void 0:e.itemOf(t);if(!(!r||r.w<=0||r.h<=0))return{x:r.x,y:r.y,width:r.w,height:r.h}}function ap(e,t,r,n){if(r==="none")return;let o=r==="page"?op(e,n):void 0;if(!o){e.fitToContent(np);return}let a=Xn(t);e.setCamera(or(o,{width:a.width||o.width,height:a.height||o.height},np))}function sp(e,t,r){let n=e.getCamera(),o=Xn(t),a={x:(o.width/2-n.x)/n.zoom,y:(o.height/2-n.y)/n.zoom},i;for(let l of Gr(e.getDocument())){let d=op(e,l.id);if(!d)continue;let c=Math.max(d.x-a.x,0,a.x-(d.x+d.width)),h=Math.max(d.y-a.y,0,a.y-(d.y+d.height)),x=Math.hypot(c,h);(!i||x<i.distance)&&(i={id:l.id,distance:x})}return i?.id??r}function ip(e,t,r){let n=e===void 0?t:String(e);if(n===void 0)return;let o;try{o=new URL(n,r??globalThis.location?.href)}catch{throw new TypeError(`fontBase must be a URL, or a path on this page; got ${n}.`)}return o.pathname.endsWith("/")||(o.pathname+="/"),o}var xd=Symbol.for("vdesign.embed.handover");function lp(e){return e[xd]}var dp=["exact","browser"],fp=["change"],Fy=250;async function eE(e,t,r={}){let n=r.fit??"page";if(!md.includes(n))throw new TypeError(`edit: fit must be one of ${md.join(", ")}; got ${String(n)}.`);let o=r.fonts??"exact";if(!dp.includes(o))throw new TypeError(`edit: fonts must be one of ${dp.join(", ")}; got ${String(o)}.`);let a=o==="exact"?ip(r.fontBase,Zc,e.ownerDocument.baseURI):void 0,i=lp(r),l=await tp(t),d=i?.page!==void 0&&Gr(l.document).some(F=>F.id===i.page)?i.page:r.page===void 0?Gr(l.document)[0]?.id:rp(l.document,r.page).id,c=i?.exact&&a?await By(a,l.document):void 0,h=e.ownerDocument,x=h.defaultView,y=new Map(l.blocks),v=Jc(y),D=h.createElement("div");D.className="vd-embed vd-embed--edit",D.style.position="relative",D.style.width="100%",D.style.height="100%",e.appendChild(D);let k=F=>{r.onLink?r.onLink(F):x?.open(F,"_blank","noopener,noreferrer")},S;try{S=id(D,{document:l.document,chrome:r.toolbar??!0,interactive:r.interactive??!0,wheel:"modifier",resolveAsset:F=>v.resolve(F),importImage:xe,onOpenLink:k,...r.surface?{surface:r.surface}:{},...i?{camera:i.camera}:{},...c?{fonts:c.library}:{}})}catch(F){throw D.remove(),v.destroy(),F}let B=new Set,N=!1,J=!1,E=0,P=i===void 0,R,C,G,de;function ye(F){return G?.of!==F&&(G={of:F,text:Es(_s(F),y)}),G.text}async function xe(F){if(N||!F.type.startsWith("image/"))return null;let O=new Uint8Array(await F.arrayBuffer()),X=await Ms(O);return N?null:(y.has(X)||y.set(X,$s(O)),{type:F.type,hash:X,bytes:O.length})}function ke(){E+=1;try{ap(S.viewer,D,n,d)}finally{E-=1}}let Se=S.on("navigate",()=>{E===0&&(P=!1)}),A=S.on("change",({document:F})=>{let O={text:()=>ye(F)};for(let X of[...B])X(O);c&&T()}),te=Xn(D),w=x&&"ResizeObserver"in x?new x.ResizeObserver(()=>{let F=Xn(D);F.width===te.width&&F.height===te.height||(te=F,P&&ke())}):void 0;w?.observe(D),i||ke(),!c&&o==="exact"&&M();function $(){return C??=(async()=>{if(a)try{let{exactFontsAt:F}=await import("./chunks/fonts.js");return F(a)}catch{return}})(),C}async function M(){let F=await $();if(!(N||!F)){for(;;){let O=S.getDocument(),X=await F.ensure(O);if(N||X.length>0)return;if(S.getDocument()===O)break}c=F,S.viewer.setFonts(F.library)}}function T(){R!==void 0&&clearTimeout(R),R=setTimeout(()=>{R=void 0;let F=c;N||!F||F.ensure(S.getDocument()).then(O=>{N||c!==F||O.length===0||(c=void 0,S.viewer.setFonts(void 0))})},Fy)}function H(){N||(N=!0,R!==void 0&&clearTimeout(R),A(),Se(),w?.disconnect(),S.destroy(),v.destroy(),D.remove(),B.clear())}let j={getText:()=>ye(S.getDocument()),getDocument(){let F=S.getDocument();return de?.of!==F&&(de={of:F,document:ep(F,new Map(y),S.getProblems().map(hd))}),de.document},on(F,O){if(!fp.includes(F))throw new TypeError(`edit: on() takes one of ${fp.join(", ")}; got ${String(F)}.`);return B.add(O),()=>{B.delete(O)}},undo(){N||S.undo()},redo(){N||S.redo()},async view(){if(N)throw new Error("edit: this editor was destroyed.");if(J)throw new Error("edit: view() is already opening a view.");J=!0,D.inert=!0;try{S.endTextEditing();let{view:F}=await import("./view.js");if(N)throw new Error("edit: this editor was destroyed.");d=sp(S.viewer,D,d);let O={camera:S.viewer.getCamera(),page:d,exact:c!==void 0},X=S.getDocument(),z=await F(e,j.getDocument(),{...Hy(r),[xd]:O});if(N)throw z.destroy(),new Error("edit: this editor was destroyed.");let V=S.getDocument()===X?void 0:j.getDocument();return H(),V&&await z.load(V),z}finally{J=!1,D.inert=!1}},destroy:H};return j}async function By(e,t){try{let{exactFontsAt:r}=await import("./chunks/fonts.js"),n=r(e);return(await n.ensure(t)).length===0?n:void 0}catch{return}}function Hy(e){let{toolbar:t,...r}=e;return r}export{eE as edit,ud as version};
2470
2575
  /*! Bundled license information:
2471
2576
 
2472
2577
  lucide/dist/esm/icons/a-large-small.mjs: