@getv.design/embed 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/edit.js CHANGED
@@ -1,43 +1,43 @@
1
- /*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
2
- function zt(e){return{expr:e}}function be(e){return typeof e=="object"&&e!==null&&typeof e.expr=="string"}var mn=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],jt=["left","center","right","justify"],qt=["top","middle","bottom"],Kt=["cover","contain","fill"],hn=["nonzero","evenodd"],xn=["butt","round","square"],gn=["miter","round","bevel"],Lu=["canvas","frame","group"];function Xo(e){return Lu.includes(e)}function ye(e){return Xo(e.type)}function Oe(e){return e.type==="group"}function re(e){return ye(e)?e.children:[]}var Ou={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 yt(e){return Ou[e.type]}function se(e,t,n){if(t(e,n)!==!1&&ye(e))for(let r of e.children)se(r,t,e)}function U(e,t){let n;return se(e,r=>{if(n)return!1;r.id===t&&(n=r)}),n}function ct(e,t){let n;return se(e,(r,o)=>{r.id===t&&o&&(n=o)}),n}function Yo(e){return Du(e,"hidden")}function Jo(e){return Du(e,"locked")}function Du(e,t){let n=new Set,r=(o,a)=>{let i=a||o[t]===!0;i&&n.add(o.id);for(let l of re(o))r(l,i)};return r(e,!1),n}function Rr(e,t,n){let r,o=(a,i)=>{let l=i??(a[n]===!0?a.id:void 0);return a.id===t?(r=l,!0):re(a).some(d=>o(d,l))};return o(e,void 0),r}var yn=["design"],Gt="design";var Fr=[1,2,3,4],vt="doc";function Vn(e){return{type:"canvas",...e}}function Ui(e){return{type:"ellipse",...e}}function Zo(e){return{type:"frame",...e}}function Vi(e){return{type:"group",...e}}function zi(e){return{type:"image",...e}}function ji(e){return{type:"rect",...e}}function qi(e){return{type:"text",...e}}function Qo(e){return{type:"vector",...e}}function Br(e={}){return{version:4,kind:e.kind??Gt,...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??Vn({id:vt,children:[]})}}function ea(e){let t=new Set;return se(e,n=>{t.add(n.id)}),t}function Wt(e,t){let n=ea(e),r=0;for(let o of n){if(!o.startsWith(`${t}.`))continue;let a=Number(o.slice(t.length+1));Number.isInteger(a)&&a>r&&(r=a)}return`${t}.${r+1}`}function pt(e){let t=e.trim();if(t.startsWith("#")){let r=t.slice(1);return r===""?void 0:{kind:"frame",id:r}}let n;try{n=new URL(t)}catch{return}if(!(n.protocol!=="https:"&&n.protocol!=="mailto:"))return{kind:"url",url:t}}var Hr=["beat","bar"];var px=/^(\d+(?:\.\d+)?)(beats?|bars?)$/;function vn(e){let t=px.exec(e);if(!t)return;let n=Number(t[1]);if(Number.isFinite(n))return{count:n,unit:t[2].startsWith("bar")?"bar":"beat"}}function bn(e,t){return`${String(Math.round(e*1e6)/1e6)}${t}${e===1?"":"s"}`}function wn(e){return typeof e=="string"&&vn(e)!==void 0}function mt(e){let t=e?.bpm;if(t===void 0)return;let n=e?.meter??4,r=6e4/t;return{bpm:t,meter:n,beat:r,bar:r*n}}function Ve(e,t,n){if(e===void 0)return n;if(typeof e=="number")return e;let r=vn(e);return!r||!t?n:r.count*(r.unit==="bar"?t.bar:t.beat)}function Ki(e,t,n){let r=t==="bar"?n.bar:n.beat,o=Math.ceil((e-1)/r);return Math.max(0,o)*r}function Ur(e){return`${Math.round(e)} ms`}var zn=36e5;var Gi=50,Wi=16e3,Xi=320,Vr=["from","volume","fadein","fadeout","loop"];function Yi(e,t){return e===t?!0:e===void 0||t===void 0?!1:e.asset===t.asset&&Vr.every(n=>e[n]===t[n])}function Ji(e,t){let n=e?.music;if(!n)return[];let r=mt(e),o=t[n.asset]?.ms,a=Ve(n.fadeout,r);return[{asset:n.asset,at:0,from:n.from??0,volume:n.volume??1,fadeIn:Ve(n.fadein,r,0),...a===void 0?{}:{fadeOut:a},loop:n.loop===!0,...o===void 0?{}:{sourceMs:o}}]}var qn=["cut","fade","push","slide"],zr=["cut","fade","rise","drop","pop","wipe","grow","count","draw"],jn=["cut","fade","rise","drop","pop"],jr=["pulse"],qr=["out","in","inout","linear","spring"],Kr=["word","letter"],Xt=["left","right","top","bottom"],Gr=400,bt=1e4,Yt=18e4,wt=7680;function Mt(e){let t=e.trim();return t==="back"?{kind:"back"}:t==="next"?{kind:"next"}:pt(t)}function At(e){return e===void 0||e.enter===void 0&&e.duration===void 0&&e.scroll!==!0&&e.length===void 0&&e.w===void 0&&e.h===void 0&&e.bpm===void 0&&e.meter===void 0&&e.music===void 0&&e.lines.length===0}function Kn(e){return e.camera===!0||e.enter!==void 0||e.exit!==void 0||e.emphasis!==void 0||e.go!==void 0}var mx=["id","camera","enter","exit","emphasis","from","by","stagger","duration","hold","delay","at","after","with","step","together","on","ease","pad","go"],hx=["camera","emphasis","from","by","stagger","hold","at","after","with","on","ease","pad"];function kn(e){return e===void 0?!1:e.length!==void 0||e.w!==void 0||e.h!==void 0||e.bpm!==void 0||e.meter!==void 0||e.music!==void 0?!0:e.lines.some(t=>hx.some(n=>t[n]!==void 0)||t.enter!==void 0&&!jn.includes(t.enter)||t.exit!==void 0&&!jn.includes(t.exit))}function ta(e,t){return e===t?!0:e===void 0||t===void 0||e.enter!==t.enter||e.duration!==t.duration||e.length!==t.length||e.w!==t.w||e.h!==t.h||e.bpm!==t.bpm||e.meter!==t.meter||!Yi(e.music,t.music)||e.scroll===!0!=(t.scroll===!0)||e.lines.length!==t.lines.length?!1:e.lines.every((n,r)=>{let o=t.lines[r];return mx.every(a=>n[a]===o[a])})}function Gn(e){let t=e.motion;if(!t)return[];let n=e.root.children.map(o=>o.id).filter(o=>o in t),r=Object.keys(t).filter(o=>!n.includes(o)).sort();return[...n,...r]}function $t(e){return new Set(e.root.children.filter(t=>t.type==="frame").map(t=>t.id))}function lt(e){let t=new Map;for(let n of e.root.children)n.type==="frame"&&se(n,r=>{t.set(r.id,n.id)});return t}function Zi(e){let t=new Set;return se(e,n=>{t.add(n.id)}),t}function Wn(e,t){let n=e.motion;if(!n)return[];let r=[],o=$t(e),a=lt(e),i=Zi(e.root),l=(d,u)=>{let p=t?.(d,u);return p===void 0?"":`Line ${p}: `};for(let d of Gn(e)){let u=n[d];if(!u)continue;if(!o.has(d)){r.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}let p=new Set;for(let x of u.lines){let y=l(d,x.id);for(let v of["after","with"]){let w=x[v];w!==void 0&&!p.has(w)&&r.push({severity:"warning",code:"motion-anchor-missing",message:`${y}motion ${d}: ${v}=${w} names no line above, so it starts after the line above instead`,nodeId:x.id})}x.camera!==!0&&p.add(x.id);let k=i.has(x.id)?U(e.root,x.id):void 0;k&&r.push(...xx(x,k,y,d)),i.has(x.id)?a.get(x.id)!==d&&r.push({severity:"warning",code:"motion-wrong-page",message:`${y}motion ${d}: ${x.id} is not on ${d}, so Play skips it`,nodeId:x.id}):r.push({severity:"warning",code:"unknown-reference",message:`${y}motion ${d}: no node ${x.id}`,nodeId:x.id});let M=x.go===void 0?void 0:Mt(x.go);M?.kind==="frame"&&!vx(e,M.id)&&r.push({severity:"warning",code:"unknown-reference",message:`${y}motion ${d}: go=#${M.id} names no frame`,nodeId:x.id})}}return r}function xx(e,t,n,r){let o=[],a=(l,d)=>{o.push({severity:"warning",code:l,message:`${n}motion ${r}: ${d}`,nodeId:t.id})};if(e.camera===!0)return o;let i=e.enter??e.exit;return i==="count"&&(t.type!=="text"||!/\d/.test(Jt(t.content)))&&a("count-no-number",`${t.id} has no number to count, so it fades in instead`),i==="draw"&&!yx(t)&&a("draw-no-stroke",`${t.id} has no stroked vector to draw, so it fades in instead`),e.by!==void 0&&t.type!=="text"?a("by-not-text",`by=${e.by} splits text, and ${t.id} is a ${t.type}`):e.by!==void 0&&t.type==="text"&&gx(t)&&a("by-rotated",`${t.id} is rotated, so by=${e.by} enters it whole`),e.stagger!==void 0&&e.by===void 0&&re(t).length===0&&a("stagger-no-children",`${t.id} has no children to stagger: split a text with by=word`),o}function gx(e){let t=e.rotation;return t!==void 0&&t!==0}function yx(e){let t=!1;return se(e,n=>(n.type==="vector"&&n.stroke!==void 0&&(t=!0),t?!1:void 0)),t}function Jt(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function vx(e,t){let n=!1;return se(e.root,r=>{if(n)return!1;r.id===t&&(n=r.type==="frame")}),n}function Pu(e,t){let n=t.motion;if(!n||!e.motion)return n;let r=lt(e),o=lt(t),a=Zi(e.root),i=Zi(t.root),l=x=>a.has(x)&&!i.has(x),d=!1,u={},p=[];for(let[x,y]of Object.entries(n)){if(l(x)){d=!0;continue}let k=[];for(let v of y.lines){let w=v,D=v.go===void 0?void 0:Mt(v.go);if(D?.kind==="frame"&&l(D.id)){let A=wx(v);w=Kn(A)?A:void 0,d=!0}if(w&&(w.after!==void 0&&l(w.after)||w.with!==void 0&&l(w.with))&&(w=bx(w,l),d=!0),w&&l(v.id))w=void 0,d=!0;else if(w&&r.get(v.id)===x&&o.get(v.id)!==x){let A=o.get(v.id);A!==void 0&&p.push([A,w]),w=void 0,d=!0}w&&k.push(w)}let M={...y,lines:k};At(M)||(u[x]=M)}for(let[x,y]of p){let k=u[x]??{lines:[]};u[x]={...k,lines:[...k.lines,y]}}return d?Object.keys(u).length===0?void 0:u:n}function bx(e,t){let n={...e};return e.after!==void 0&&t(e.after)&&delete n.after,e.with!==void 0&&t(e.with)&&delete n.with,n}function wx(e){let t={...e};return delete t.go,t}function Qi(e,t){let n={...e};return t===void 0||Object.keys(t).length===0?delete n.motion:n.motion=t,n}function es(e,t){let n=Pu(e,t);if(n===t.motion)return[];let r=new Set([...Object.keys(t.motion??{}),...Object.keys(n??{})]),o=[];for(let a of r){let i=n?.[a];ta(t.motion?.[a],i)||o.push({op:"setMotion",page:a,value:i})}return o}var kx={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"]},_x=["text","font","size","weight","italic","underline","strike","fill","letterSpacing","link"],Sx=["family","fallback","faces"],Ex=["src","weight","style"],De=" ";function ts(e){let t=["{",`${De}"version": ${J(e.version)},`,`${De}"kind": ${JSON.stringify(e.kind)},`,...e.title===void 0?[]:[`${De}"title": ${JSON.stringify(e.title)},`],`${De}"tokens": ${Mx(e.tokens,De)},`];return Object.keys(e.fonts).length>0&&t.push(`${De}"fonts": ${Ax(e.fonts,De)},`),e.motion!==void 0&&t.push(`${De}"motion": ${Cx(e,De)},`),t.push(`${De}"root": ${Iu(e.root,De)}`,"}"),`${t.join(`
1
+ /*! @getv.design/embed v0.4.0. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
2
+ function Xt(e){return{expr:e}}function ke(e){return typeof e=="object"&&e!==null&&typeof e.expr=="string"}var vn=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],Yt=["left","center","right","justify"],Jt=["top","middle","bottom"],Zt=["cover","contain","fill"],bn=["nonzero","evenodd"],wn=["butt","round","square"],kn=["miter","round","bevel"],Yf=["canvas","frame","group"];function na(e){return Yf.includes(e)}function be(e){return na(e.type)}function De(e){return e.type==="group"}function de(e){return be(e)?e.children:[]}var Jf={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 wt(e){return Jf[e.type]}function ce(e,t,n){if(t(e,n)!==!1&&be(e))for(let r of e.children)ce(r,t,e)}function K(e,t){let n;return ce(e,r=>{if(n)return!1;r.id===t&&(n=r)}),n}function ht(e,t){let n;return ce(e,(r,o)=>{r.id===t&&o&&(n=o)}),n}function ra(e){return Zf(e,"hidden")}function oa(e){return Zf(e,"locked")}function Zf(e,t){let n=new Set,r=(o,a)=>{let s=a||o[t]===!0;s&&n.add(o.id);for(let d of de(o))r(d,s)};return r(e,!1),n}function zr(e,t,n){let r,o=(a,s)=>{let d=s??(a[n]===!0?a.id:void 0);return a.id===t?(r=d,!0):de(a).some(l=>o(l,d))};return o(e,void 0),r}var aa=["light","dark"],sa=["must","should"],ia=["no-gradient","contrast","font-only","logo-min"];var Qf=["role","logo","rule","guide","review"];function da(e){return Qf.includes(e)}function la(e="",t=1){return{slug:e,version:t,changes:[],sources:[],roles:{},logos:{},rules:{},guides:{},review:[]}}function ei(e){let t=/^([a-z0-9][a-z0-9-]*)(?:@(\d+))?$/.exec(e);if(!t)return;let n=t[2]===void 0?1:Number(t[2]);if(!(!Number.isSafeInteger(n)||n<1))return{slug:t[1],version:n}}function ti(e){return`${e.slug}@${e.version}`}function _n(e){return ri(e,()=>{})??e}function ni(e,t){return e===t?!0:e===void 0||t===void 0?!1:JSON.stringify(_n(e))===JSON.stringify(_n(t))}function ri(e,t){let n=jr(e),r=n?.version;if(!n||typeof n.slug!="string"||typeof r!="number"||!Number.isSafeInteger(r)||r<1){t('`brand` must be an object with a "slug" and a "version" counting from 1');return}let o=c=>{let m={};for(let[g,b]of Object.entries(jr(c)??{}))typeof b=="string"&&(m[g]=b);return m},a=(c,m)=>{let g={};for(let[b,E]of Object.entries(jr(c)??{})){let v=jr(E),w=v?m(v):void 0;w===void 0?t(`brand: could not read ${b}`):g[b]=w}return g},s=(c,m)=>{let g=[];for(let b of Array.isArray(c)?c:[]){let E=jr(b),v=E?m(E):void 0;v===void 0?t("brand: could not read a list entry"):g.push(v)}return g},d=c=>typeof c=="string"?c:void 0,l=c=>typeof c=="number"?c:void 0,f=(c,m)=>m===void 0?{}:{[c]:m};return{slug:n.slug,version:r,...f("id",d(n.id)),...f("theme",aa.includes(n.theme)?n.theme:void 0),...f("strict",n.strict===!0?!0:void 0),...f("summary",d(n.summary)),changes:s(n.changes,c=>{let m=l(c.version),g=d(c.note);if(!(m===void 0||g===void 0))return{version:m,note:g,...f("at",d(c.at))}}),sources:s(n.sources,c=>{let m=d(c.kind);return m===void 0?void 0:{kind:m,props:o(c.props)}}),roles:a(n.roles,c=>{let m=d(c.light);return m===void 0?void 0:{light:m,...f("dark",d(c.dark))}}),logos:a(n.logos,c=>{let m=d(c.asset);if(m!==void 0)return{asset:m,...f("min",l(c.min)),...f("clear",l(c.clear))}}),rules:a(n.rules,c=>{let m=c.level,g=d(c.text);if(!sa.includes(m)||g===void 0)return;let b=o(c.params);return delete b.check,{level:m,text:g,...f("check",d(c.check)),...Object.keys(b).length===0?{}:{params:b}}}),guides:a(n.guides,c=>({entries:s(c.entries,Vx)})),review:s(n.review,c=>{let m=d(c.target);if(m!==void 0)return{target:m,...f("from",d(c.from)),...f("note",d(c.note))}})}}function Vx(e){let t=e.kind,n=e.text;if(t==="line"||t==="banned"||t==="avoid")return typeof n=="string"?{kind:t,text:n}:void 0;if(t==="rewrite"){let{from:r,to:o}=e;return typeof r=="string"&&typeof o=="string"?{kind:t,from:r,to:o}:void 0}if(t==="ref"||t==="approved"||t==="rejected"){let{asset:r,note:o}=e;return typeof r!="string"?void 0:{kind:t,asset:r,...typeof o=="string"?{note:o}:{}}}}function jr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}var Sn=["design","brand"],Qt="design",ec=new WeakMap;function Qe(e){let t=e.brand?.theme==="dark"?e.themes?.dark:void 0;if(t===void 0)return e.tokens;let n=ec.get(e);if(n!==void 0)return n;let r={...e.tokens,...t};return ec.set(e,r),r}var tc=4,Wn=5,Kr=[1,2,3,4,5];function et(e){return e.kind==="brand"||e.brand!==void 0||e.themes!==void 0||zx(e.fonts)?Wn:tc}function zx(e){return Object.values(e??{}).some(t=>(t.faces??[]).some(n=>n.asset!==void 0))}var kt="doc";function Xn(e){return{type:"canvas",...e}}function oi(e){return{type:"ellipse",...e}}function ua(e){return{type:"frame",...e}}function ai(e){return{type:"group",...e}}function si(e){return{type:"image",...e}}function ii(e){return{type:"rect",...e}}function di(e){return{type:"text",...e}}function fa(e){return{type:"vector",...e}}function qr(e={}){let t=e.kind??Qt,n=_t(e.themes);return{version:et({kind:t,...e.fonts===void 0?{}:{fonts:e.fonts},...e.brand===void 0?{}:{brand:e.brand},...n===void 0?{}:{themes:n}}),kind:t,...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},...e.brand===void 0?{}:{brand:e.brand},...n===void 0?{}:{themes:n},root:e.root??Xn({id:kt,children:[]})}}function _t(e){let t=e?.dark;return t===void 0||Object.keys(t).length===0?void 0:{dark:t}}function ca(e){let t=new Set;return ce(e,n=>{t.add(n.id)}),t}function en(e,t){let n=ca(e),r=0;for(let o of n){if(!o.startsWith(`${t}.`))continue;let a=Number(o.slice(t.length+1));Number.isInteger(a)&&a>r&&(r=a)}return`${t}.${r+1}`}function xt(e){let t=e.trim();if(t.startsWith("#")){let r=t.slice(1);return r===""?void 0:{kind:"frame",id:r}}let n;try{n=new URL(t)}catch{return}if(!(n.protocol!=="https:"&&n.protocol!=="mailto:"))return{kind:"url",url:t}}var Gr=["beat","bar"];var jx=/^(\d+(?:\.\d+)?)(beats?|bars?)$/;function En(e){let t=jx.exec(e);if(!t)return;let n=Number(t[1]);if(Number.isFinite(n))return{count:n,unit:t[2].startsWith("bar")?"bar":"beat"}}function Cn(e,t){return`${String(Math.round(e*1e6)/1e6)}${t}${e===1?"":"s"}`}function Mn(e){return typeof e=="string"&&En(e)!==void 0}function gt(e){let t=e?.bpm;if(t===void 0)return;let n=e?.meter??4,r=6e4/t;return{bpm:t,meter:n,beat:r,bar:r*n}}function ze(e,t,n){if(e===void 0)return n;if(typeof e=="number")return e;let r=En(e);return!r||!t?n:r.count*(r.unit==="bar"?t.bar:t.beat)}function li(e,t,n){let r=t==="bar"?n.bar:n.beat,o=Math.ceil((e-1)/r);return Math.max(0,o)*r}function Wr(e){return`${Math.round(e)} ms`}var Yn=36e5;var ui=50,fi=16e3,ci=320,Xr=["from","volume","fadein","fadeout","loop"];function pi(e,t){return e===t?!0:e===void 0||t===void 0?!1:e.asset===t.asset&&Xr.every(n=>e[n]===t[n])}function mi(e,t){let n=e?.music;if(!n)return[];let r=gt(e),o=t[n.asset]?.ms,a=ze(n.fadeout,r);return[{asset:n.asset,at:0,from:n.from??0,volume:n.volume??1,fadeIn:ze(n.fadein,r,0),...a===void 0?{}:{fadeOut:a},loop:n.loop===!0,...o===void 0?{}:{sourceMs:o}}]}var Zn=["cut","fade","push","slide"],Yr=["cut","fade","rise","drop","pop","wipe","grow","count","draw"],Jn=["cut","fade","rise","drop","pop"],Jr=["pulse"],Zr=["out","in","inout","linear","spring"],Qr=["word","letter"],tn=["left","right","top","bottom"],eo=400,St=1e4,nn=18e4,Et=7680;function Lt(e){let t=e.trim();return t==="back"?{kind:"back"}:t==="next"?{kind:"next"}:xt(t)}function Dt(e){return e===void 0||e.enter===void 0&&e.duration===void 0&&e.scroll!==!0&&e.length===void 0&&e.w===void 0&&e.h===void 0&&e.bpm===void 0&&e.meter===void 0&&e.music===void 0&&e.lines.length===0}function Qn(e){return e.camera===!0||e.enter!==void 0||e.exit!==void 0||e.emphasis!==void 0||e.go!==void 0}var Kx=["id","camera","enter","exit","emphasis","from","by","stagger","duration","hold","delay","at","after","with","step","together","on","ease","pad","go"],qx=["camera","emphasis","from","by","stagger","hold","at","after","with","on","ease","pad"];function An(e){return e===void 0?!1:e.length!==void 0||e.w!==void 0||e.h!==void 0||e.bpm!==void 0||e.meter!==void 0||e.music!==void 0?!0:e.lines.some(t=>qx.some(n=>t[n]!==void 0)||t.enter!==void 0&&!Jn.includes(t.enter)||t.exit!==void 0&&!Jn.includes(t.exit))}function pa(e,t){return e===t?!0:e===void 0||t===void 0||e.enter!==t.enter||e.duration!==t.duration||e.length!==t.length||e.w!==t.w||e.h!==t.h||e.bpm!==t.bpm||e.meter!==t.meter||!pi(e.music,t.music)||e.scroll===!0!=(t.scroll===!0)||e.lines.length!==t.lines.length?!1:e.lines.every((n,r)=>{let o=t.lines[r];return Kx.every(a=>n[a]===o[a])})}function er(e){let t=e.motion;if(!t)return[];let n=e.root.children.map(o=>o.id).filter(o=>o in t),r=Object.keys(t).filter(o=>!n.includes(o)).sort();return[...n,...r]}function Pt(e){return new Set(e.root.children.filter(t=>t.type==="frame").map(t=>t.id))}function ft(e){let t=new Map;for(let n of e.root.children)n.type==="frame"&&ce(n,r=>{t.set(r.id,n.id)});return t}function hi(e){let t=new Set;return ce(e,n=>{t.add(n.id)}),t}function tr(e,t){let n=e.motion;if(!n)return[];let r=[],o=Pt(e),a=ft(e),s=hi(e.root),d=(l,f)=>{let c=t?.(l,f);return c===void 0?"":`Line ${c}: `};for(let l of er(e)){let f=n[l];if(!f)continue;if(!o.has(l)){r.push({severity:"warning",code:"motion-not-a-page",message:`${d(l)}motion ${l}: ${l} is not a page (a top-level frame), so none of it plays`,nodeId:l});continue}let c=new Set;for(let m of f.lines){let g=d(l,m.id);for(let v of["after","with"]){let w=m[v];w!==void 0&&!c.has(w)&&r.push({severity:"warning",code:"motion-anchor-missing",message:`${g}motion ${l}: ${v}=${w} names no line above, so it starts after the line above instead`,nodeId:m.id})}m.camera!==!0&&c.add(m.id);let b=s.has(m.id)?K(e.root,m.id):void 0;b&&r.push(...Gx(m,b,g,l)),s.has(m.id)?a.get(m.id)!==l&&r.push({severity:"warning",code:"motion-wrong-page",message:`${g}motion ${l}: ${m.id} is not on ${l}, so Play skips it`,nodeId:m.id}):r.push({severity:"warning",code:"unknown-reference",message:`${g}motion ${l}: no node ${m.id}`,nodeId:m.id});let E=m.go===void 0?void 0:Lt(m.go);E?.kind==="frame"&&!Yx(e,E.id)&&r.push({severity:"warning",code:"unknown-reference",message:`${g}motion ${l}: go=#${E.id} names no frame`,nodeId:m.id})}}return r}function Gx(e,t,n,r){let o=[],a=(d,l)=>{o.push({severity:"warning",code:d,message:`${n}motion ${r}: ${l}`,nodeId:t.id})};if(e.camera===!0)return o;let s=e.enter??e.exit;return s==="count"&&(t.type!=="text"||!/\d/.test(rn(t.content)))&&a("count-no-number",`${t.id} has no number to count, so it fades in instead`),s==="draw"&&!Xx(t)&&a("draw-no-stroke",`${t.id} has no stroked vector to draw, so it fades in instead`),e.by!==void 0&&t.type!=="text"?a("by-not-text",`by=${e.by} splits text, and ${t.id} is a ${t.type}`):e.by!==void 0&&t.type==="text"&&Wx(t)&&a("by-rotated",`${t.id} is rotated, so by=${e.by} enters it whole`),e.stagger!==void 0&&e.by===void 0&&de(t).length===0&&a("stagger-no-children",`${t.id} has no children to stagger: split a text with by=word`),o}function Wx(e){let t=e.rotation;return t!==void 0&&t!==0}function Xx(e){let t=!1;return ce(e,n=>(n.type==="vector"&&n.stroke!==void 0&&(t=!0),t?!1:void 0)),t}function rn(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function Yx(e,t){let n=!1;return ce(e.root,r=>{if(n)return!1;r.id===t&&(n=r.type==="frame")}),n}function nc(e,t){let n=t.motion;if(!n||!e.motion)return n;let r=ft(e),o=ft(t),a=hi(e.root),s=hi(t.root),d=m=>a.has(m)&&!s.has(m),l=!1,f={},c=[];for(let[m,g]of Object.entries(n)){if(d(m)){l=!0;continue}let b=[];for(let v of g.lines){let w=v,L=v.go===void 0?void 0:Lt(v.go);if(L?.kind==="frame"&&d(L.id)){let $=Zx(v);w=Qn($)?$:void 0,l=!0}if(w&&(w.after!==void 0&&d(w.after)||w.with!==void 0&&d(w.with))&&(w=Jx(w,d),l=!0),w&&d(v.id))w=void 0,l=!0;else if(w&&r.get(v.id)===m&&o.get(v.id)!==m){let $=o.get(v.id);$!==void 0&&c.push([$,w]),w=void 0,l=!0}w&&b.push(w)}let E={...g,lines:b};Dt(E)||(f[m]=E)}for(let[m,g]of c){let b=f[m]??{lines:[]};f[m]={...b,lines:[...b.lines,g]}}return l?Object.keys(f).length===0?void 0:f:n}function Jx(e,t){let n={...e};return e.after!==void 0&&t(e.after)&&delete n.after,e.with!==void 0&&t(e.with)&&delete n.with,n}function Zx(e){let t={...e};return delete t.go,t}function xi(e,t){let n={...e};return t===void 0||Object.keys(t).length===0?delete n.motion:n.motion=t,n}function gi(e,t){let n=nc(e,t);if(n===t.motion)return[];let r=new Set([...Object.keys(t.motion??{}),...Object.keys(n??{})]),o=[];for(let a of r){let s=n?.[a];pa(t.motion?.[a],s)||o.push({op:"setMotion",page:a,value:s})}return o}var Qx={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"]},eg=["text","font","size","weight","italic","underline","strike","fill","letterSpacing","link"],tg=["family","fallback","faces"],ng=["src","asset","weight","style"],Le=" ";function yi(e){let t=["{",`${Le}"version": ${Q(et(e))},`,`${Le}"kind": ${JSON.stringify(e.kind)},`,...e.title===void 0?[]:[`${Le}"title": ${JSON.stringify(e.title)},`],`${Le}"tokens": ${og(e.tokens,Le)},`];return Object.keys(e.fonts).length>0&&t.push(`${Le}"fonts": ${ag(e.fonts,Le)},`),e.motion!==void 0&&t.push(`${Le}"motion": ${rg(e,Le)},`),e.brand!==void 0&&t.push(`${Le}"brand": ${JSON.stringify(_n(e.brand))},`),e.themes?.dark!==void 0&&Object.keys(e.themes.dark).length>0&&t.push(`${Le}"themes": ${JSON.stringify({dark:e.themes.dark})},`),t.push(`${Le}"root": ${rc(e.root,Le)}`,"}"),`${t.join(`
3
3
  `)}
4
- `}function Cx(e,t){let n=t+De,r=Gn(e).map(o=>`${n}${JSON.stringify(o)}: ${JSON.stringify(e.motion?.[o])}`).join(`,
4
+ `}function rg(e,t){let n=t+Le,r=er(e).map(o=>`${n}${JSON.stringify(o)}: ${JSON.stringify(e.motion?.[o])}`).join(`,
5
5
  `);return r===""?"{}":`{
6
6
  ${r}
7
- ${t}}`}function Mx(e,t){let n=Object.keys(e).sort();if(n.length===0)return"{}";let r=t+De;return`{
8
- ${n.map(a=>`${r}${JSON.stringify(a)}: ${na(e[a])}`).join(`,
7
+ ${t}}`}function og(e,t){let n=Object.keys(e).sort();if(n.length===0)return"{}";let r=t+Le;return`{
8
+ ${n.map(a=>`${r}${JSON.stringify(a)}: ${ma(e[a])}`).join(`,
9
9
  `)}
10
- ${t}}`}function Ax(e,t){let n=Object.keys(e).sort();if(n.length===0)return"{}";let r=t+De;return`{
11
- ${n.map(a=>`${r}${JSON.stringify(a)}: ${$x(e[a],r)}`).join(`,
10
+ ${t}}`}function ag(e,t){let n=Object.keys(e).sort();if(n.length===0)return"{}";let r=t+Le;return`{
11
+ ${n.map(a=>`${r}${JSON.stringify(a)}: ${sg(e[a],r)}`).join(`,
12
12
  `)}
13
- ${t}}`}function $x(e,t){if(!e)return"{}";let n=t+De,r=e,o=[];for(let a of Sx){let i=r[a];if(i!==void 0){if(a==="faces"){o.push(`${n}"faces": ${Tx(i,n)}`);continue}o.push(`${n}${JSON.stringify(a)}: ${na(i)}`)}}return`{
13
+ ${t}}`}function sg(e,t){if(!e)return"{}";let n=t+Le,r=e,o=[];for(let a of tg){let s=r[a];if(s!==void 0){if(a==="faces"){o.push(`${n}"faces": ${ig(s,n)}`);continue}o.push(`${n}${JSON.stringify(a)}: ${ma(s)}`)}}return`{
14
14
  ${o.join(`,
15
15
  `)}
16
- ${t}}`}function Tx(e,t){if(e.length===0)return"[]";let n=t+De;return`[
17
- ${e.map(o=>n+Nu(o,Ex)).join(`,
16
+ ${t}}`}function ig(e,t){if(e.length===0)return"[]";let n=t+Le;return`[
17
+ ${e.map(o=>n+oc(o,ng)).join(`,
18
18
  `)}
19
- ${t}]`}function Iu(e,t){let n=t+De,r=e,o=[];for(let a of kx[e.type]){let i=r[a];if(i!==void 0){if(a==="children"){o.push(`${n}"children": ${Ox(i,n)}`);continue}if(a==="content"){o.push(`${n}"content": ${Lx(i,n)}`);continue}o.push(`${n}${JSON.stringify(a)}: ${na(i)}`)}}return`{
19
+ ${t}]`}function rc(e,t){let n=t+Le,r=e,o=[];for(let a of Qx[e.type]){let s=r[a];if(s!==void 0){if(a==="children"){o.push(`${n}"children": ${lg(s,n)}`);continue}if(a==="content"){o.push(`${n}"content": ${dg(s,n)}`);continue}o.push(`${n}${JSON.stringify(a)}: ${ma(s)}`)}}return`{
20
20
  ${o.join(`,
21
21
  `)}
22
- ${t}}`}function Lx(e,t){if(typeof e=="string")return JSON.stringify(e);if(e.length===0)return"[]";let n=t+De;return`[
23
- ${e.map(o=>typeof o=="string"?n+JSON.stringify(o):n+Nu(o,_x)).join(`,
22
+ ${t}}`}function dg(e,t){if(typeof e=="string")return JSON.stringify(e);if(e.length===0)return"[]";let n=t+Le;return`[
23
+ ${e.map(o=>typeof o=="string"?n+JSON.stringify(o):n+oc(o,eg)).join(`,
24
24
  `)}
25
- ${t}]`}function Nu(e,t){let n=[];for(let r of t){let o=e[r];o!==void 0&&n.push(`${JSON.stringify(r)}: ${na(o)}`)}return`{ ${n.join(", ")} }`}function Ox(e,t){if(e.length===0)return"[]";let n=t+De;return`[
26
- ${e.map(o=>n+Iu(o,n)).join(`,
25
+ ${t}]`}function oc(e,t){let n=[];for(let r of t){let o=e[r];o!==void 0&&n.push(`${JSON.stringify(r)}: ${ma(o)}`)}return`{ ${n.join(", ")} }`}function lg(e,t){if(e.length===0)return"[]";let n=t+Le;return`[
26
+ ${e.map(o=>n+rc(o,n)).join(`,
27
27
  `)}
28
- ${t}]`}function na(e){return be(e)?JSON.stringify(`=${e.expr}`):typeof e=="number"?J(e):JSON.stringify(e)}function J(e){if(!Number.isFinite(e))return"0";let t=Math.round(e*1e4)/1e4,n=Object.is(t,-0)?0:t;return Math.abs(n)>=1e21?n.toFixed(0):String(n)}var Dx={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Yr(e){let t=[],n,r=0,o=0,a=0,i=0,l,d,u=Px(e),p=()=>(n||(n={anchors:[{x:r,y:o}],closed:!1},t.push(n)),n.anchors[n.anchors.length-1]),x=(v,w)=>{p(),n?.anchors.push({x:v,y:w}),r=v,o=w},y=(v,w,D,A)=>{p().out=v,n?.anchors.push({x:D,y:A,in:w}),r=D,o=A},k="",M=!0;for(;u.more();){let v=u.command();if(v!==void 0)k=v,M=!0;else if(k===""||k.toUpperCase()==="Z")return{contours:ra(t),error:`Expected a command at ${u.at()}`};let w=k.toUpperCase(),D=k!==w,A=Dx[w];if(A===void 0)return{contours:ra(t),error:`Unknown command ${k}`};if(w==="Z"){n&&(n.closed=!0),n=void 0,r=a,o=i,l=void 0,d=void 0,k="";continue}let H=w==="A"?u.arc():u.numbers(A);if(H===void 0)return{contours:ra(t),error:`${k} expects ${A} numbers at ${u.at()}`};let E=D?r:0,T=D?o:0,P=V=>H[V];switch(w){case"M":M&&(n={anchors:[{x:E+P(0),y:T+P(1)}],closed:!1},t.push(n),r=a=E+P(0),o=i=T+P(1),k=D?"l":"L"),l=d=void 0;break;case"L":x(E+P(0),T+P(1)),l=d=void 0;break;case"H":x(E+P(0),o),l=d=void 0;break;case"V":x(r,T+P(0)),l=d=void 0;break;case"C":{let V={x:E+P(2),y:T+P(3)};y({x:E+P(0),y:T+P(1)},V,E+P(4),T+P(5)),l=V,d=void 0;break}case"S":{let V=l?{x:2*r-l.x,y:2*o-l.y}:{x:r,y:o},X={x:E+P(0),y:T+P(1)};y(V,X,E+P(2),T+P(3)),l=X,d=void 0;break}case"Q":case"T":{let V=w==="Q"?{x:E+P(0),y:T+P(1)}:d?{x:2*r-d.x,y:2*o-d.y}:{x:r,y:o},X=w==="Q"?E+P(2):E+P(0),te=w==="Q"?T+P(3):T+P(1),I={x:r+2/3*(V.x-r),y:o+2/3*(V.y-o)},fe={x:X+2/3*(V.x-X),y:te+2/3*(V.y-te)};y(I,fe,X,te),d=V,l=void 0;break}case"A":{let V=E+P(5),X=T+P(6);for(let[te,I,fe]of Ix(r,o,P(0),P(1),P(2),P(3)!==0,P(4)!==0,V,X))y(te,I,fe.x,fe.y);(r!==V||o!==X)&&x(V,X),l=d=void 0;break}}M=!1}return{contours:ra(t)}}function ra(e){return e.map(t=>{let n=[...t.anchors];if(t.closed&&n.length>1){let r=n[0],o=n[n.length-1];_n(r,o)&&(n.pop(),n[0]={...r,...o.in?{in:o.in}:{}})}return{anchors:n.map(Wr),closed:t.closed}})}function kt(e,t,n){return Wr({x:e.x,y:e.y,...t?{in:t}:{},...n?{out:n}:{}})}function Wr(e){let t={x:e.x,y:e.y};return e.in&&!_n(e.in,e)&&(t.in=e.in),e.out&&!_n(e.out,e)&&(t.out=e.out),t}function _n(e,t,n=1e-6){return Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n}function Px(e){let t=0,n=()=>{for(;t<e.length&&/[\s,]/.test(e[t]);)t+=1},r=()=>{n();let a=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(t));if(a)return t+=a[0].length,Number(a[0])},o=()=>{n();let a=e[t];if(!(a!=="0"&&a!=="1"))return t+=1,Number(a)};return{more(){return n(),t<e.length},command(){n();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=r();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 Ix(e,t,n,r,o,a,i,l,d){let u=Math.abs(n),p=Math.abs(r);if(u===0||p===0||e===l&&t===d)return[];let x=o*Math.PI/180,y=Math.cos(x),k=Math.sin(x),M=(e-l)/2,v=(t-d)/2,w=y*M+k*v,D=-k*M+y*v,A=w*w/(u*u)+D*D/(p*p);A>1&&(u*=Math.sqrt(A),p*=Math.sqrt(A));let H=u*u*p*p-u*u*D*D-p*p*w*w,E=u*u*D*D+p*p*w*w,T=(a===i?-1:1)*Math.sqrt(Math.max(0,H/E)),P=T*u*D/p,V=-T*p*w/u,X=y*P-k*V+(e+l)/2,te=k*P+y*V+(t+d)/2,I=(L,B,q,F)=>{let ne=L*q+B*F,ke=Math.hypot(L,B)*Math.hypot(q,F),Me=Math.acos(Math.min(1,Math.max(-1,ne/ke)));return L*F-B*q<0?-Me:Me},fe=I(1,0,(w-P)/u,(D-V)/p),we=I((w-P)/u,(D-V)/p,(-w-P)/u,(-D-V)/p);!i&&we>0&&(we-=2*Math.PI),i&&we<0&&(we+=2*Math.PI);let Se=Math.max(1,Math.ceil(Math.abs(we)/(Math.PI/2)-1e-9)),me=we/Se,ue=4/3*Math.tan(me/4),S=L=>({x:X+u*Math.cos(L)*y-p*Math.sin(L)*k,y:te+u*Math.cos(L)*k+p*Math.sin(L)*y}),g=L=>({x:-u*Math.sin(L)*y-p*Math.cos(L)*k,y:-u*Math.sin(L)*k+p*Math.cos(L)*y}),$=[];for(let L=0;L<Se;L+=1){let B=fe+L*me,q=B+me,F=S(B),ne=L===Se-1?{x:l,y:d}:S(q),ke=g(B),Me=g(q);$.push([{x:F.x+ue*ke.x,y:F.y+ue*ke.y},{x:ne.x-ue*Me.x,y:ne.y-ue*Me.y},ne])}return $}function Tt(e){let t=[],n=r=>`${J(r.x)} ${J(r.y)}`;for(let r of e){let{anchors:o}=r,a=o[0];if(!a)continue;t.push(`M${n(a)}`);let i=Xn(r);for(let l=0;l<i;l+=1){let d=o[l],u=o[(l+1)%o.length],p=r.closed&&l===o.length-1;!d.out&&!u.in?p||t.push(`L${n(u)}`):t.push(`C${n(d.out??d)} ${n(u.in??u)} ${n(u)}`)}r.closed&&t.push("Z")}return t.join(" ")}function Xn(e){let t=e.anchors.length;return t<2?0:e.closed?t:t-1}function Yn(e,t){let n=e.anchors[t],r=e.anchors[(t+1)%e.anchors.length];return[{x:n.x,y:n.y},n.out??{x:n.x,y:n.y},r.in??{x:r.x,y:r.y},{x:r.x,y:r.y}]}function Ru(e,t){let n=e.anchors[t],r=e.anchors[(t+1)%e.anchors.length];return!n.out&&!r.in}function Xr(e,t){let[n,r,o,a]=e,i=1-t,l=i*i*i,d=3*i*i*t,u=3*i*t*t,p=t*t*t;return{x:l*n.x+d*r.x+u*o.x+p*a.x,y:l*n.y+d*r.y+u*o.y+p*a.y}}function Lt(e,t){return e.map(n=>({closed:n.closed,anchors:n.anchors.map(r=>{let o=t(r);return{x:o.x,y:o.y,...r.in?{in:t(r.in)}:{},...r.out?{out:t(r.out)}:{}}})}))}function Sn(e){let t=1/0,n=1/0,r=-1/0,o=-1/0,a=i=>{t=Math.min(t,i.x),n=Math.min(n,i.y),r=Math.max(r,i.x),o=Math.max(o,i.y)};for(let i of e){for(let d of i.anchors)a(d);let l=Xn(i);for(let d=0;d<l;d+=1){let u=Yn(i,d);for(let p of Nx(u))a(Xr(u,p))}}if(t!==1/0)return{x:t,y:n,w:r-t,h:o-n}}function Nx(e){let[t,n,r,o]=e,a=[];for(let i of["x","y"]){let l=-t[i]+3*n[i]-3*r[i]+o[i],d=2*(t[i]-2*n[i]+r[i]),u=n[i]-t[i];if(Math.abs(l)<1e-12){Math.abs(d)>1e-12&&a.push(-u/d);continue}let p=d*d-4*l*u;if(p<0)continue;let x=Math.sqrt(p);a.push((-d+x)/(2*l),(-d-x)/(2*l))}return a.filter(i=>i>0&&i<1)}function aa(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[n,r,o,a]=t;return{x:n,y:r,w:o,h:a}}function En(e){return[e.x,e.y,e.w,e.h].map(J).join(" ")}function Jr(e,t,n){return aa(e)??{x:0,y:0,w:t,h:n}}function Zr(e,t){let n=e.w===0?1:t.w/e.w,r=e.h===0?1:t.h/e.h;return o=>({x:t.x+(o.x-e.x)*n,y:t.y+(o.y-e.y)*r})}function ns(e,t){let n=e.w===0||t.w===0?1:e.w/t.w,r=e.h===0||t.h===0?1:e.h/t.h;return o=>({x:e.x+(o.x-t.x)*n,y:e.y+(o.y-t.y)*r})}function rs(e,t=.5){let[n,r,o,a]=e;if(_n(n,r)&&_n(o,a))return[n,a];let l=Math.hypot(r.x-n.x,r.y-n.y)+Math.hypot(o.x-r.x,o.y-r.y)+Math.hypot(a.x-o.x,a.y-o.y),d=Math.min(256,Math.max(4,Math.ceil(Math.sqrt(l/t)))),u=[];for(let p=0;p<=d;p+=1)u.push(Xr(e,p/d));return u}function ia(e){let t=0;for(let n of e)for(let r=0;r<Xn(n);r+=1){let o=rs(Yn(n,r),.25);for(let a=1;a<o.length;a+=1){let i=o[a-1],l=o[a];t+=Math.hypot(l.x-i.x,l.y-i.y)}}return t}function os(e,t,n){let r=0,o=0;for(let a of e){let i=Rx(a);if(i.length!==0){if(n.reach>0){let l=a.closed?i.length:i.length-1;for(let d=0;d<l;d+=1){let u=i[d],p=i[(d+1)%i.length];if(Fx(t,u,p)<=n.reach)return!0}if(i.length===1&&Math.hypot(t.x-i[0].x,t.y-i[0].y)<=n.reach)return!0}if(n.fill)for(let l=0;l<i.length;l+=1){let d=i[l],u=i[(l+1)%i.length];d.y<=t.y!=u.y<=t.y&&d.x+(t.y-d.y)/(u.y-d.y)*(u.x-d.x)>t.x&&(o+=1,r+=u.y>d.y?1:-1)}}}return n.fill?n.rule==="evenodd"?o%2===1:r!==0:!1}function Rx(e){let t=e.anchors[0];if(!t)return[];let n=[{x:t.x,y:t.y}],r=Xn(e);for(let o=0;o<r;o+=1)n.push(...rs(Yn(e,o)).slice(1));return e.closed&&n.length>1&&n.pop(),n}function Fx(e,t,n){let r=n.x-t.x,o=n.y-t.y,a=r*r+o*o,i=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*o)/a));return Math.hypot(e.x-(t.x+i*r),e.y-(t.y+i*o))}function as(e,t){let n;return e.forEach((r,o)=>{let a=Xn(r);for(let i=0;i<a;i+=1){let l=Yn(r,i),d=v=>{let w=Xr(l,v);return Math.hypot(w.x-t.x,w.y-t.y)},u=32,p=0;for(let v=1;v<=u;v+=1)d(v/u)<d(p)&&(p=v/u);let x=Math.max(0,p-1/u),y=Math.min(1,p+1/u);for(let v=0;v<24;v+=1){let w=x+(y-x)/3,D=y-(y-x)/3;d(w)<d(D)?y=D:x=w}let k=(x+y)/2,M=d(k);(!n||M<n.distance)&&(n={contour:o,segment:i,t:k,point:Xr(l,k),distance:M})}}),n}function is(e,t,n,r){return e.map((o,a)=>{if(a!==t)return o;let i=[...o.anchors],l=i.length,d=i[n],u=(n+1)%l,p=i[u];if(Ru(o,n)){let P={x:d.x+(p.x-d.x)*r,y:d.y+(p.y-d.y)*r};return i.splice(n+1,0,P),{...o,anchors:i}}let[x,y,k,M]=Yn(o,n),v=(P,V)=>({x:P.x+(V.x-P.x)*r,y:P.y+(V.y-P.y)*r}),w=v(x,y),D=v(y,k),A=v(k,M),H=v(w,D),E=v(D,A),T=v(H,E);return i[n]=Wr({...d,out:w}),i[u]=Wr({...p,in:A}),i.splice(n+1,0,Wr({x:T.x,y:T.y,in:H,out:E})),{...o,anchors:i}})}var oa=.5522847498;function ss(e,t,n=0){let r=Math.max(0,Math.min(n,e/2,t/2));if(r===0)return[{closed:!0,anchors:[{x:0,y:0},{x:e,y:0},{x:e,y:t},{x:0,y:t}]}];let o=oa*r,a=[{x:r,y:0,in:{x:r-o,y:0}},{x:e-r,y:0,out:{x:e-r+o,y:0}},{x:e,y:r,in:{x:e,y:r-o}},{x:e,y:t-r,out:{x:e,y:t-r+o}},{x:e-r,y:t,in:{x:e-r+o,y:t}},{x:r,y:t,out:{x:r-o,y:t}},{x:0,y:t-r,in:{x:0,y:t-r+o}},{x:0,y:r,out:{x:0,y:r-o}}];return[{closed:!0,anchors:Bx(a)}]}function ls(e,t){let n=e/2,r=t/2,o=oa*n,a=oa*r;return[{closed:!0,anchors:[{x:n,y:0,in:{x:n-o,y:0},out:{x:n+o,y:0}},{x:e,y:r,in:{x:e,y:r-a},out:{x:e,y:r+a}},{x:n,y:t,in:{x:n+o,y:t},out:{x:n-o,y:t}},{x:0,y:r,in:{x:0,y:r+a},out:{x:0,y:r-a}}]}]}function Bx(e){let t=[];for(let o of e){let a=t[t.length-1];if(a&&_n(a,o)&&!a.out&&!o.in){t[t.length-1]=kt(a,a.in,o.out);continue}t.push(o)}let n=t[0],r=t[t.length-1];return t.length>1&&n&&r&&_n(n,r)&&!r.out&&!n.in&&(t[0]=kt(n,r.in,n.out),t.pop()),t}var _t=class extends Error{op;constructor(t,n){super(t),this.op=n,this.name="OpError"}};function Ae(e,t){let n=e,r=[];for(let o of t){let a=Hu(n,o);n=a.document,r.push(a.inverse)}return r.reverse(),{document:n,inverse:r}}function Hu(e,t){switch(t.op){case"set":{let n=U(e.root,t.id);if(!n)throw new _t(`No node ${t.id}`,t);let r=n[t.prop];return{document:sa(e,fs(e.root,t.id,o=>Hx(o,t.prop,t.value),t)),inverse:{op:"set",id:t.id,prop:t.prop,value:r}}}case"insert":{if(U(e.root,t.node.id))throw new _t(`Duplicate id ${t.node.id}`,t);let n=la(e.root,t.parent,r=>{let o=Bu(t.index,0,r.length);return[...r.slice(0,o),t.node,...r.slice(o)]},t);return{document:sa(e,n),inverse:{op:"remove",id:t.node.id}}}case"remove":{let n=Fu(e,t.id,t),r=la(e.root,n.parent.id,o=>o.filter(a=>a.id!==t.id),t);return{document:sa(e,r),inverse:{op:"insert",parent:n.parent.id,index:n.index,node:n.node}}}case"move":{let n=Fu(e,t.id,t),r=la(e.root,n.parent.id,a=>a.filter(i=>i.id!==t.id),t),o=la(r,t.parent,a=>{let i=Bu(t.index,0,a.length);return[...a.slice(0,i),n.node,...a.slice(i)]},t);return{document:sa(e,o),inverse:{op:"move",id:t.id,parent:n.parent.id,index:n.index}}}case"setTitle":{let{title:n,...r}=e;return{document:t.value===void 0?r:{...r,title:t.value},inverse:{op:"setTitle",value:n}}}case"setToken":{let n=Object.prototype.hasOwnProperty.call(e.tokens,t.name)?e.tokens[t.name]:void 0,r={...e.tokens};return t.value===void 0?delete r[t.name]:r[t.name]=t.value,{document:{...e,tokens:r},inverse:{op:"setToken",name:t.name,value:n}}}case"setAsset":{let n=Object.prototype.hasOwnProperty.call(e.assets,t.name)?e.assets[t.name]:void 0,r={...e.assets};return t.value===void 0?delete r[t.name]:r[t.name]=t.value,{document:{...e,assets:r},inverse:{op:"setAsset",name:t.name,value:n}}}case"setFont":{let n=Object.prototype.hasOwnProperty.call(e.fonts,t.name)?e.fonts[t.name]:void 0,r={...e.fonts};return t.family===void 0?delete r[t.name]:r[t.name]=t.family,{document:{...e,fonts:r},inverse:{op:"setFont",name:t.name,family:n}}}case"setMotion":{let n=e.motion&&Object.prototype.hasOwnProperty.call(e.motion,t.page)?e.motion[t.page]:void 0,r={...e.motion};return At(t.value)?delete r[t.page]:r[t.page]=t.value,{document:Qi(e,r),inverse:{op:"setMotion",page:t.page,value:n}}}}}function da(e,t){if(!e.motion||!t.some(r=>r.op==="remove"||r.op==="move"))return t;let n=es(e,Ae(e,t).document);return n.length===0?t:[...t,...n]}function sa(e,t){if(t.type!=="canvas")throw new Error("The document root must stay a canvas");return{...e,root:t}}function Hx(e,t,n){let r={...e};return n===void 0?delete r[t]:r[t]=n,r}function fs(e,t,n,r){if(e.id===t)return n(e);if(!ye(e))return e;let o=!1,a=e.children.map(i=>{let l=fs(i,t,n,r);return l!==i&&(o=!0),l});return o?{...e,children:a}:e}function la(e,t,n,r){let o=U(e,t);if(!o)throw new _t(`No node ${t}`,r);if(!ye(o))throw new _t(`${t} cannot hold children`,r);return fs(e,t,a=>({...a,children:n(a.children)}),r)}function Fu(e,t,n){if(t===e.root.id)throw new _t("The document root cannot be removed or moved",n);let r,o=a=>{ye(a)&&a.children.forEach((i,l)=>{i.id===t&&(r={node:i,parent:a,index:l}),o(i)})};if(o(e.root),!r)throw new _t(`No node ${t}`,n);return r}function Bu(e,t,n){return Math.min(Math.max(e,t),n)}function us(e,t){let n=[];e.title!==t.title&&n.push({op:"setTitle",value:t.title});for(let a of Jn(e.tokens,t.tokens)){let i=t.tokens[a];e.tokens[a]!==i&&n.push({op:"setToken",name:a,value:i})}for(let a of Jn(e.fonts,t.fonts)){let i=t.fonts[a];Vx(e.fonts[a],i)||n.push({op:"setFont",name:a,family:i})}for(let a of Jn(e.assets,t.assets)){let i=t.assets[a];(e.assets[a]?.hash!==i?.hash||e.assets[a]?.ms!==i?.ms)&&n.push({op:"setAsset",name:a,value:i})}if(!Ux(e.root.children,t.root.children)){for(let a of e.root.children)n.push({op:"remove",id:a.id});t.root.children.forEach((a,i)=>{n.push({op:"insert",parent:e.root.id,index:i,node:a})})}for(let a of Jn(e.motion??{},t.motion??{})){let i=t.motion?.[a];ta(e.motion?.[a],i)||n.push({op:"setMotion",page:a,value:i})}let r=e.root,o=t.root;for(let a of Jn(r,o))a==="type"||a==="id"||a==="children"||Uu(r[a],o[a])||n.push({op:"set",id:e.root.id,prop:a,value:o[a]});return n}function Jn(e,t){return[...new Set([...Object.keys(e),...Object.keys(t)])]}function Uu(e,t){return e===t?!0:be(e)&&be(t)&&e.expr===t.expr}function Ux(e,t){return e.length===t.length&&e.every((n,r)=>ds(n,t[r]))}function ds(e,t){if(Uu(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)=>ds(a,t[i]));let n=e,r=t;return Jn(n,r).every(a=>ds(n[a],r[a]))}function Vx(e,t){if(e===t)return!0;if(!e||!t||e.family!==t.family||e.fallback!==t.fallback)return!1;let n=e.faces??[],r=t.faces??[];return n.length===r.length&&n.every((o,a)=>{let i=r[a];return o.src===i.src&&o.weight===i.weight&&o.style===i.style})}var Qr={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"]]},eo=[["font","string"],["size","number"],["weight","number"],["italic","boolean"],["underline","boolean"],["strike","boolean"],["fill","string"],["letterSpacing","number"],["link","string"]],cs=[["weight","number"],["style","fontStyle"]],to=[["enter","pageEffect"],["duration","number"],["scroll","boolean"],["length","time"],["w","number"],["h","number"],["bpm","number"],["meter","number"]],Cn=[["enter","nodeEffect"],["exit","nodeEffect"],["emphasis","emphasisEffect"],["from","from"],["by","piece"],["stagger","time"],["duration","time"],["hold","time"],["delay","time"],["at","time"],["after","string"],["with","string"],["step","boolean"],["together","boolean"],["on","on"],["ease","ease"],["pad","number"],["go","string"]],no=[["from","number"],["volume","number"],["fadein","time"],["fadeout","time"],["loop","boolean"]],ju=Object.keys(Qr);function fa(e){return ju.includes(e)}function ps(e,t){return Qr[e].find(([n])=>n===t)?.[1]}var Zt=" ";function nt(e){if(be(e))return/^[$@]/.test(e.expr)&&!/\s/.test(e.expr)?e.expr:`(${e.expr})`;if(typeof e=="number")return J(e);let t=String(e);return zx(t)?JSON.stringify(t):t}function zx(e){return e===""||/[\s"=()]/.test(e)||/^[$@]/.test(e)}function Xe(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 r=Zn(e);return r===void 0?{error:`Malformed quoted string ${e}`}:Vu(r,t,e)}if(Gx(e)){if(!jx(t))return{error:qx(e,t)};let r=Gu(e).trim();return r===""?{error:"Empty expression"}:{value:zt(r)}}return t==="numberValue"&&qu.test(e)?{value:zt(e)}:Vu(e,t,e)}var qu=/^-?\d+(?:\.\d+)?%$/;function jx(e){return e==="numberValue"||e==="stringValue"}function qx(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 Ku(e,t){let n=/^(-?\d+(?:\.\d+)?)([A-Za-z]+)$/.exec(e);return n?/^(?:beats?|bars?)$/.test(n[2])?" \u2014 beats and bars count motion times on a page with bpm=; this is milliseconds":n[2]==="s"&&t==="number"?` \u2014 durations are milliseconds: ${Number(n[1])*1e3}`:/^(?:px|pt|deg|ms)$/.test(n[2])?` \u2014 drop the unit: ${n[1]}`:" \u2014 units are not supported: use a number, a percentage like (100%), or an expression":t==="number"?qu.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 Vu(e,t,n){switch(t){case"numberValue":case"number":{let r=Number(e);return Number.isFinite(r)&&e.trim()!==""?{value:r}:{error:`Expected a number, got ${n}${Ku(e,t)}`}}case"align":return jt.includes(e)?{value:e}:{error:`Expected one of ${jt.join(", ")}, got ${n}`};case"valign":return qt.includes(e)?{value:e}:{error:`Expected one of ${qt.join(", ")}, got ${n}`};case"fontStyle":return e==="normal"||e==="italic"?{value:e}:{error:`Expected normal or italic, got ${n}`};case"imageFit":return Kt.includes(e)?{value:e}:{error:`Expected one of ${Kt.join(", ")}, got ${n}`};case"fillRule":return Ot(hn,e,n);case"lineCap":return Ot(xn,e,n);case"lineJoin":return Ot(gn,e,n);case"blendMode":return Ot(mn,e,n);case"pageEffect":return Ot(qn,e,n);case"nodeEffect":return Ot(zr,e,n);case"emphasisEffect":return Ot(jr,e,n);case"ease":return Ot(qr,e,n);case"piece":return Ot(Kr,e,n);case"time":{let r=vn(e);if(r)return{value:bn(r.count,r.unit)};let o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{value:o}:{error:`Expected milliseconds or beats, got ${n}${Kx(e)}`}}case"on":return Hr.includes(e)?{value:e}:e==="downbeat"?{error:`Expected beat or bar, got ${n} \u2014 write on=bar: a bar starts on its downbeat`}:e==="beats"||e==="bars"?{error:`Expected beat or bar, got ${n} \u2014 write on=${e.slice(0,-1)}`}:{error:`Expected beat or bar, got ${n}`};case"from":{if(Xt.includes(e))return{value:e};let r=Number(e);return Number.isFinite(r)&&e.trim()!==""?{value:r}:{error:`Expected a number or one of ${Xt.join(", ")}, got ${n}`}}default:return{value:e}}}function Kx(e){let t=/^(beat|bar|b)[:\s#]?(\d+(?:\.\d+)?)$/.exec(e);if(t){let r=t[1]==="bar"?"bar":"beat",o=Number(t[2]);return` \u2014 write ${bn(Math.max(0,o-1),r)} (counted from the start: ${r} ${o}'s ${r==="bar"?"downbeat":"start"})`}let n=/^(\d+(?:\.\d+)?)\s*(b|bt|beat|bars?|beats?)$/.exec(e);if(n){let r=n[2]?.startsWith("bar")?"bar":"beat";return` \u2014 write ${bn(Number(n[1]),r)} (counted from the start)`}return Ku(e,"number")}function Ot(e,t,n){return e.includes(t)?{value:t}:{error:`Expected one of ${e.join(", ")}, got ${n}`}}function Gx(e){return/^[$@(]/.test(e)}function Zn(e){try{let t=JSON.parse(e);return typeof t=="string"?t:void 0}catch{return}}function Gu(e){if(!e.startsWith("("))return e;let t=0;for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="(")t+=1;else if(r===")"&&(t-=1,t===0))return n===e.length-1?e.slice(1,-1):e}return e}function Wu(e){let t=[],n="",r=0,o=!1;for(let a=0;a<e.length;a+=1){let i=e[a];if(o){n+=i,i==="\\"?(n+=e[a+1]??"",a+=1):i==='"'&&(o=!1);continue}if(i==='"'){o=!0,n+=i;continue}if(i==="("?r+=1:i===")"&&(r=Math.max(0,r-1)),r===0&&/\s/.test(i)){n!==""&&t.push(n),n="";continue}n+=i}return n!==""&&t.push(n),t}function ms(e,t,n){let r=n===void 0?void 0:Ye(n);if(r?.value===void 0||!zu(e[t]??""))return;let o=t;for(;o<e.length&&zu(e[o]??"");)o+=1;let a=[Gu(r.value),...e.slice(t,o)].join(" ");return{end:o,message:`${r.key}: an expression with spaces needs parentheses \u2014 write ${r.key}=(${a})`}}function zu(e){return!e.includes("=")&&/^(?:[-+*/]|-?\d+(?:\.\d+)?%?|[$@][\w.]*|[A-Za-z_]\w*(?:\.\w+)+|\(.*|.*\))$/.test(e)}function Ye(e){let t=e.indexOf("=");return t===-1?{key:e,value:void 0}:{key:e.slice(0,t),value:e.slice(t+1)}}var Wx=new Set(["exit","delay","step","together","go","at","after","with"]),Yu=["at","after","with","together","step"],Xx=new Set(["pad","duration","delay","ease","on",...Yu]);function hs(e){if(e==="at"||e==="length")return Yt;if(e==="w"||e==="h")return wt;if(e==="duration"||e==="delay"||e==="stagger"||e==="hold")return bt;if(e==="pad")return wt}function xs(e,t){let n=e.words[1];if(n===void 0||n.includes("=")){t(e.number,"invalid-motion","Expected motion <page>, e.g. motion intro enter=fade");return}let r={};for(let a of e.words.slice(2)){let{key:i,value:l}=Ye(a),d=to.find(([p])=>p===i)?.[1];if(d===void 0){let p=Wx.has(i)?` \u2014 ${i} goes on a node's line, under the header`:"";t(e.number,"invalid-motion",`motion ${n} has no "${i}"${p}`,n);continue}let u=Xe(l??"",d);"error"in u?t(e.number,"invalid-motion",`${i}: ${ng(i,l)??u.error}`,n):i==="bpm"&&!eg(u.value)?t(e.number,"invalid-motion",`bpm: expected ${20} to ${300} beats a minute, got ${l??""}`,n):i==="meter"&&!tg(u.value)?t(e.number,"invalid-motion",`meter: expected a whole number of beats in a bar, 1 to ${16}, got ${l??""}`,n):u.value!==!1&&(r[i]=u.value)}let o=mt({...r,lines:[]});for(let[a]of to){let i=r[a];if(i===void 0||hs(a)===void 0)continue;let l=vs(a,i,o,n);l!==void 0&&(t(e.number,"invalid-motion",l,n),delete r[a])}return{page:n,number:e.number,head:r,lines:[],where:new Map,taken:new Map,numbers:[]}}function gs(e,t,n){if(t.words[0]==="music"&&!(t.words[1]??"").includes("=")){Jx(e,t,n);return}let r=t.words[0]==="camera"&&t.words[1]!==void 0&&!t.words[1].includes("="),o=r?t.words.slice(1):t.words,a=o[0];if(t.indent!==1){n(t.number,"invalid-motion","A motion line sits one level under its page");return}if(a.includes("=")){n(t.number,"invalid-motion",`Expected a node id first, got ${a}`);return}if(a===e.page&&!r){n(t.number,"invalid-motion",`${a} is the page: its transition goes on the header (motion ${a} enter=fade)`,a);return}let i=r?{id:a,camera:!0}:{id:a},l=!0;for(let p of o.slice(1)){let{key:x,value:y}=Ye(p),k=Cn.find(([w])=>w===x)?.[1];if(k===void 0){n(t.number,"invalid-motion",`A motion line has no "${x}"${rg(x)}`,a),l=!1;continue}if(r&&!Xx.has(x)){n(t.number,"invalid-motion",`A camera line moves the shot and says only pad=, duration=, delay=, ease= and when: not ${x}=`,a),l=!1;continue}let M=Xe(y??"",k),v="error"in M||hs(x)===void 0?void 0:vs(x,M.value,mt(Zu(e)),e.page);"error"in M?(n(t.number,"invalid-motion",`${x}: ${M.error}`,a),l=!1):v!==void 0?(n(t.number,"invalid-motion",`${a}: ${v}`,a),l=!1):x==="on"&&e.head.bpm===void 0?(n(t.number,"invalid-motion",`${a}: on=${String(M.value)} needs a tempo \u2014 motion ${e.page} bpm=120`,a),l=!1):x==="go"&&Mt(M.value)===void 0?(n(t.number,"invalid-motion",`go: expected #<page>, back, next, or an https: or mailto: link, got ${y??""}`,a),l=!1):M.value!==!1&&(i[x]=M.value)}i.enter!==void 0&&i.exit!==void 0&&(n(t.number,"invalid-motion",`${a} either enters or exits on one line \u2014 write a second line for the other`,a),l=!1),i.emphasis!==void 0&&(i.enter!==void 0||i.exit!==void 0)&&(n(t.number,"invalid-motion",`${a} either ${i.enter!==void 0?"enters":"exits"} or is stressed on one line \u2014 write a second line for emphasis=`,a),l=!1);let d=Yu.filter(p=>i[p]!==void 0);if(i.step===!0&&i.together===!0?(n(t.number,"invalid-motion",`${a} waits for a step or starts together with the line above, not both`,a),l=!1):d.length>1?(n(t.number,"invalid-motion",`${a} says when it starts twice (${d.join(", ")}): keep one`,a),l=!1):i.on!==void 0&&(i.with!==void 0||i.together===!0)&&(n(t.number,"invalid-motion",`${a} starts with another line (${i.with===void 0?"together":"with="}), so on= could only pull it apart: keep one`,a),l=!1),l){let p=og(i);p!==void 0&&(n(t.number,"invalid-motion",`${a}: ${p}`,a),l=!1)}if(!l)return;let u=Qx(i);if(!Kn(u)){n(t.number,"invalid-motion",`${a} says nothing: give it enter=, exit=, emphasis= or go=`,a);return}if(r){e.where.has(a)||e.where.set(a,t.number),e.lines.push(u),e.numbers.push(t.number);return}for(let p of["enter","exit","emphasis","go"]){if(u[p]===void 0)continue;let x=e.taken.get(`${a} ${p}`);if(x!==void 0){let y=p==="go"?"has a go=":p==="enter"?"enters":p==="exit"?"exits":"has an emphasis=";n(t.number,"invalid-motion",`${a} already ${y} on line ${x}`,a);return}}for(let p of["enter","exit","emphasis","go"])u[p]!==void 0&&e.taken.set(`${a} ${p}`,t.number);e.where.has(a)||e.where.set(a,t.number),e.lines.push(u),e.numbers.push(t.number)}function ys(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}:{},...e.head.length===void 0?{}:{length:e.head.length},...e.head.w===void 0?{}:{w:e.head.w},...e.head.h===void 0?{}:{h:e.head.h},...e.head.bpm===void 0?{}:{bpm:e.head.bpm},...e.head.meter===void 0?{}:{meter:e.head.meter},...e.music===void 0?{}:{music:e.music},lines:e.lines};return At(t)?void 0:t}function Ju(e,t){let n=t.motion;if(n)for(let r of Gn(t)){let o=n[r];if(o===void 0||At(o))continue;e.at(-1)!==""&&e.push("");let a=["motion",r];for(let[i,l]of to){let d=o[i];if(d!==void 0){if(l==="boolean"){d===!0&&a.push(i);continue}a.push(`${i}=${nt(d)}`)}}if(e.push(a.join(" ")),o.music){let i=["music",o.music.asset];for(let[l,d]of no){let u=o.music[l];if(u!==void 0){if(d==="boolean"){u===!0&&i.push(l);continue}i.push(`${l}=${nt(u)}`)}}e.push(Zt+i.join(" "))}for(let i of o.lines){let l=i.camera===!0?["camera",i.id]:[i.id];for(let[d,u]of Cn){let p=i[d];if(p!==void 0){if(u==="boolean"){p===!0&&l.push(d);continue}l.push(`${d}=${nt(p)}`)}}e.push(Zt+l.join(" "))}}}var Yx=new Set(["loop","step","together"]);function Jx(e,t,n){let r=t.words[1];if(t.indent!==1){n(t.number,"invalid-motion","A motion line sits one level under its page");return}if(r===void 0){n(t.number,"invalid-motion","Expected music <asset>, e.g. music bed fadeout=1500");return}if(Yx.has(r)){n(t.number,"invalid-motion",`music names its track first: music <asset> ${r}`);return}if(e.musicLine!==void 0){n(t.number,"invalid-motion",`motion ${e.page} already has music on line ${e.musicLine}: a page has one track`);return}let o={asset:r},a=mt(Zu(e)),i=!0,l=u=>{n(t.number,"invalid-motion",`music ${r}: ${u}`),i=!1};for(let u of t.words.slice(2)){let{key:p,value:x}=Ye(u),y=no.find(([M])=>M===p)?.[1];if(y===void 0){l(`the music line has no "${p}"${Zx(p)}`);continue}if(p==="from"&&x!==void 0&&/\d(?:beats?|bars?)$/.test(x)){l(`from= is where in the track to begin, in milliseconds, not ${x}`);continue}let k=Xe(x??"",y);if("error"in k){l(`${p}: ${k.error}`);continue}if(p==="from"&&!Xu(k.value,0,zn)){l(`from: expected 0 to ${zn} milliseconds, got ${x??""}`);continue}if(p==="volume"&&!Xu(k.value,0,1)){l(`volume: expected 0 to 1, got ${x??""}`);continue}if(p==="fadein"||p==="fadeout"){let M=vs(p,k.value,a,e.page);if(M!==void 0){l(M);continue}}k.value!==!1&&(o[p]=k.value)}if(!i)return;let d={asset:r};for(let[u]of no)o[u]!==void 0&&(d[u]=o[u]);e.music=d,e.musicLine=t.number}function Xu(e,t,n){return typeof e=="number"&&e>=t&&e<=n}function Zx(e){return e==="fade"?" \u2014 write fadein= and fadeout=":e==="fade-in"||e==="fadeIn"||e==="fade_in"?" \u2014 write fadein=":e==="fade-out"||e==="fadeOut"||e==="fade_out"?" \u2014 write fadeout=":e==="start"||e==="offset"||e==="seek"?" \u2014 write from= (where in the track to begin, in milliseconds)":e==="gain"||e==="level"?" \u2014 write volume= (0 to 1)":e==="at"||e==="delay"||e==="after"||e==="with"?": the music starts with the video; from= picks where in the track":": it takes from=, volume=, fadein=, fadeout= and loop"}function Qx(e){let t=e.camera===!0?{id:e.id,camera:!0}:{id:e.id};for(let[n]of Cn)e[n]!==void 0&&(t[n]=e[n]);return t}function Zu(e){let{bpm:t,meter:n}=e.head;return{...t===void 0?{}:{bpm:t},...n===void 0?{}:{meter:n},lines:[]}}function vs(e,t,n,r){if(wn(t)&&!n)return`${t} needs a tempo \u2014 motion ${r} bpm=120`;let o=typeof t=="number"||wn(t)?Ve(t,n):void 0,a=hs(e)??bt;if(o!==void 0&&o>=(e==="w"||e==="h"?16:0)&&o<=a)return;let l=String(t),d=wn(t)&&o!==void 0?` (${Math.round(o)} ms)`:"";return e==="w"||e==="h"?`${e}: expected 16 to ${wt} pixels, got ${l}`:e==="pad"?`pad: expected 0 to ${wt}, got ${l}`:`${e}: expected 0 to ${a} milliseconds, got ${l}${d}`}function eg(e){return typeof e=="number"&&e>=20&&e<=300}function tg(e){return typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=16}function ng(e,t){if(e==="meter"&&t!==void 0&&/^\d+\/\d+$/.test(t))return`Expected beats in a bar, got ${t} \u2014 meter is beats per bar: meter=${t.split("/")[0]??""}`;if(e==="duration"&&t!==void 0&&/\d(?:beats?|bars?)$/.test(t))return`Expected milliseconds, got ${t} \u2014 the page transition is milliseconds; beats are for the lines`}function rg(e){return e==="emphasise"||e==="emphasize"?" \u2014 write emphasis=pulse":e==="easing"?" \u2014 write ease=":e==="split"?" \u2014 write by=word or by=letter":e==="start"?" \u2014 write at= (milliseconds), after= or with=":""}function og(e){let t=e.enter,n=e.exit,r=t??n,o=e.from;if(n==="count")return"count only enters: it runs a number up to its written value";if(o!==void 0)if(r==="count"){if(typeof o!="number")return"from= on count is the number it starts at, e.g. from=0"}else if(r==="wipe"||r==="grow"){if(typeof o=="number")return`from= on ${r} is a side: ${Xt.join(", ")}`}else return"from= goes with count (a number), or wipe and grow (a side)";if(e.by!==void 0&&r!==void 0&&!jn.includes(r))return`by= splits a text for ${jn.join(", ")}, not ${r}`;if(e.by!==void 0&&r===void 0)return"by= goes with enter= or exit=";if(e.stagger!==void 0&&r===void 0)return"stagger= goes with enter= or exit=";if(e.hold!==void 0&&t===void 0)return"hold= goes with enter=: how long to stay before leaving the way it came"}var ag=24;function ws(e,t={}){let n=[`version ${J(e.version)}`,`kind ${e.kind}`];e.title!==void 0&&n.push(`title ${JSON.stringify(e.title)}`);for(let[r,o]of Object.entries(e.tokens))n.push(`$${r} = ${nt(o)}`);n.push("");for(let[r,o]of Object.entries(e.fonts))lg(n,r,o,t),n.push("");if(Object.keys(e.assets).length>0){for(let[r,o]of Object.entries(e.assets))n.push(sg(r,o));n.push("")}return ig(e.root)?e.root.children.forEach((r,o)=>{o>0&&n.push(""),bs(n,r,0)}):bs(n,e.root,0),Ju(n,e),n.join(`
29
- `)}function ig(e){return e.id===vt&&e.w===void 0&&e.h===void 0&&e.background===void 0&&e.name===void 0}function sg(e,t){let n=[`asset ${e} = ${t.type}`,`hash=${t.hash}`,`bytes=${J(t.bytes)}`];t.ms!==void 0&&n.push(`ms=${J(t.ms)}`);for(let r of["credit","source","license"]){let o=t[r];o!==void 0&&n.push(`${r}=${nt(o)}`)}return n.join(" ")}function lg(e,t,n,r){e.push(`font ${t} = ${nt(n.family)}`),n.fallback!==void 0&&e.push(`${Zt}fallback ${nt(n.fallback)}`);for(let o of n.faces??[]){let a=r.abbreviateFaces?dg(o.src):o.src,i=[`face ${nt(a)}`];for(let[l]of cs){let d=o[l];d!==void 0&&i.push(`${l}=${nt(d)}`)}e.push(Zt+i.join(" "))}}function dg(e){return e.startsWith("data:")?`${e.slice(0,ag)}\u2026 ${J(Math.round(e.length/1024))} kB`:e}function bs(e,t,n){let r=Zt.repeat(n),o=t,a=[t.type,t.id];for(let[i,l]of Qr[t.type]){let d=o[i];if(d!==void 0){if(l==="boolean"){d===!0&&a.push(i);continue}a.push(`${i}=${nt(d)}`)}}if(e.push(r+a.join(" ")),t.type==="text"&&fg(e,t.content,n+1),ye(t))for(let i of re(t))bs(e,i,n+1)}function fg(e,t,n){let r=Zt.repeat(n),o=typeof t=="string"?[t]:t;for(let a of o){if(typeof a=="string"){e.push(r+JSON.stringify(a));continue}e.push(r+[JSON.stringify(a.text),...ug(a)].join(" "))}}function ug(e){let t=[];for(let[n,r]of eo){let o=e[n];if(o!==void 0){if(r==="boolean"){o===!0&&t.push(n);continue}t.push(`${n}=${nt(o)}`)}}return t}var Mn="--- payload base64 ---",Qu="sha256-";function ec(e){let t=cg(e);return t===-1?{head:e,payload:""}:{head:e.slice(0,t),payload:e.slice(t+Mn.length)}}function ks(e){let{head:t,payload:n}=ec(e);return{head:t,blocks:tc(n)}}function _s(e,t){let n=new Map;for(let r of pg(e)){let o=t.get(r);o!==void 0&&n.set(r,o)}return n.size===0?e:`${e.trimEnd()}
28
+ ${t}]`}function ma(e){return ke(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,n=Object.is(t,-0)?0:t;return Math.abs(n)>=1e21?n.toFixed(0):String(n)}var ug={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function ro(e){let t=[],n,r=0,o=0,a=0,s=0,d,l,f=fg(e),c=()=>(n||(n={anchors:[{x:r,y:o}],closed:!1},t.push(n)),n.anchors[n.anchors.length-1]),m=(v,w)=>{c(),n?.anchors.push({x:v,y:w}),r=v,o=w},g=(v,w,L,$)=>{c().out=v,n?.anchors.push({x:L,y:$,in:w}),r=L,o=$},b="",E=!0;for(;f.more();){let v=f.command();if(v!==void 0)b=v,E=!0;else if(b===""||b.toUpperCase()==="Z")return{contours:ha(t),error:`Expected a command at ${f.at()}`};let w=b.toUpperCase(),L=b!==w,$=ug[w];if($===void 0)return{contours:ha(t),error:`Unknown command ${b}`};if(w==="Z"){n&&(n.closed=!0),n=void 0,r=a,o=s,d=void 0,l=void 0,b="";continue}let z=w==="A"?f.arc():f.numbers($);if(z===void 0)return{contours:ha(t),error:`${b} expects ${$} numbers at ${f.at()}`};let A=L?r:0,N=L?o:0,I=j=>z[j];switch(w){case"M":E&&(n={anchors:[{x:A+I(0),y:N+I(1)}],closed:!1},t.push(n),r=a=A+I(0),o=s=N+I(1),b=L?"l":"L"),d=l=void 0;break;case"L":m(A+I(0),N+I(1)),d=l=void 0;break;case"H":m(A+I(0),o),d=l=void 0;break;case"V":m(r,N+I(0)),d=l=void 0;break;case"C":{let j={x:A+I(2),y:N+I(3)};g({x:A+I(0),y:N+I(1)},j,A+I(4),N+I(5)),d=j,l=void 0;break}case"S":{let j=d?{x:2*r-d.x,y:2*o-d.y}:{x:r,y:o},O={x:A+I(0),y:N+I(1)};g(j,O,A+I(2),N+I(3)),d=O,l=void 0;break}case"Q":case"T":{let j=w==="Q"?{x:A+I(0),y:N+I(1)}:l?{x:2*r-l.x,y:2*o-l.y}:{x:r,y:o},O=w==="Q"?A+I(2):A+I(0),V=w==="Q"?N+I(3):N+I(1),C={x:r+2/3*(j.x-r),y:o+2/3*(j.y-o)},R={x:O+2/3*(j.x-O),y:V+2/3*(j.y-V)};g(C,R,O,V),l=j,d=void 0;break}case"A":{let j=A+I(5),O=N+I(6);for(let[V,C,R]of cg(r,o,I(0),I(1),I(2),I(3)!==0,I(4)!==0,j,O))g(V,C,R.x,R.y);(r!==j||o!==O)&&m(j,O),d=l=void 0;break}}E=!1}return{contours:ha(t)}}function ha(e){return e.map(t=>{let n=[...t.anchors];if(t.closed&&n.length>1){let r=n[0],o=n[n.length-1];$n(r,o)&&(n.pop(),n[0]={...r,...o.in?{in:o.in}:{}})}return{anchors:n.map(to),closed:t.closed}})}function Ct(e,t,n){return to({x:e.x,y:e.y,...t?{in:t}:{},...n?{out:n}:{}})}function to(e){let t={x:e.x,y:e.y};return e.in&&!$n(e.in,e)&&(t.in=e.in),e.out&&!$n(e.out,e)&&(t.out=e.out),t}function $n(e,t,n=1e-6){return Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n}function fg(e){let t=0,n=()=>{for(;t<e.length&&/[\s,]/.test(e[t]);)t+=1},r=()=>{n();let a=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(t));if(a)return t+=a[0].length,Number(a[0])},o=()=>{n();let a=e[t];if(!(a!=="0"&&a!=="1"))return t+=1,Number(a)};return{more(){return n(),t<e.length},command(){n();let a=e[t];if(/[a-zA-Z]/.test(a))return t+=1,a},numbers(a){let s=[];for(let d=0;d<a;d+=1){let l=r();if(l===void 0)return;s.push(l)}return s},arc(){let a=this.numbers(3),s=o(),d=o(),l=this.numbers(2);if(!(!a||s===void 0||d===void 0||!l))return[...a,s,d,...l]},at(){return t}}}function cg(e,t,n,r,o,a,s,d,l){let f=Math.abs(n),c=Math.abs(r);if(f===0||c===0||e===d&&t===l)return[];let m=o*Math.PI/180,g=Math.cos(m),b=Math.sin(m),E=(e-d)/2,v=(t-l)/2,w=g*E+b*v,L=-b*E+g*v,$=w*w/(f*f)+L*L/(c*c);$>1&&(f*=Math.sqrt($),c*=Math.sqrt($));let z=f*f*c*c-f*f*L*L-c*c*w*w,A=f*f*L*L+c*c*w*w,N=(a===s?-1:1)*Math.sqrt(Math.max(0,z/A)),I=N*f*L/c,j=-N*c*w/f,O=g*I-b*j+(e+d)/2,V=b*I+g*j+(t+l)/2,C=(D,U,X,H)=>{let ie=D*X+U*H,_e=Math.hypot(D,U)*Math.hypot(X,H),Me=Math.acos(Math.min(1,Math.max(-1,ie/_e)));return D*H-U*X<0?-Me:Me},R=C(1,0,(w-I)/f,(L-j)/c),q=C((w-I)/f,(L-j)/c,(-w-I)/f,(-L-j)/c);!s&&q>0&&(q-=2*Math.PI),s&&q<0&&(q+=2*Math.PI);let ee=Math.max(1,Math.ceil(Math.abs(q)/(Math.PI/2)-1e-9)),oe=q/ee,se=4/3*Math.tan(oe/4),S=D=>({x:O+f*Math.cos(D)*g-c*Math.sin(D)*b,y:V+f*Math.cos(D)*b+c*Math.sin(D)*g}),y=D=>({x:-f*Math.sin(D)*g-c*Math.cos(D)*b,y:-f*Math.sin(D)*b+c*Math.cos(D)*g}),T=[];for(let D=0;D<ee;D+=1){let U=R+D*oe,X=U+oe,H=S(U),ie=D===ee-1?{x:d,y:l}:S(X),_e=y(U),Me=y(X);T.push([{x:H.x+se*_e.x,y:H.y+se*_e.y},{x:ie.x-se*Me.x,y:ie.y-se*Me.y},ie])}return T}function Nt(e){let t=[],n=r=>`${Q(r.x)} ${Q(r.y)}`;for(let r of e){let{anchors:o}=r,a=o[0];if(!a)continue;t.push(`M${n(a)}`);let s=nr(r);for(let d=0;d<s;d+=1){let l=o[d],f=o[(d+1)%o.length],c=r.closed&&d===o.length-1;!l.out&&!f.in?c||t.push(`L${n(f)}`):t.push(`C${n(l.out??l)} ${n(f.in??f)} ${n(f)}`)}r.closed&&t.push("Z")}return t.join(" ")}function nr(e){let t=e.anchors.length;return t<2?0:e.closed?t:t-1}function rr(e,t){let n=e.anchors[t],r=e.anchors[(t+1)%e.anchors.length];return[{x:n.x,y:n.y},n.out??{x:n.x,y:n.y},r.in??{x:r.x,y:r.y},{x:r.x,y:r.y}]}function ac(e,t){let n=e.anchors[t],r=e.anchors[(t+1)%e.anchors.length];return!n.out&&!r.in}function no(e,t){let[n,r,o,a]=e,s=1-t,d=s*s*s,l=3*s*s*t,f=3*s*t*t,c=t*t*t;return{x:d*n.x+l*r.x+f*o.x+c*a.x,y:d*n.y+l*r.y+f*o.y+c*a.y}}function It(e,t){return e.map(n=>({closed:n.closed,anchors:n.anchors.map(r=>{let o=t(r);return{x:o.x,y:o.y,...r.in?{in:t(r.in)}:{},...r.out?{out:t(r.out)}:{}}})}))}function Tn(e){let t=1/0,n=1/0,r=-1/0,o=-1/0,a=s=>{t=Math.min(t,s.x),n=Math.min(n,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y)};for(let s of e){for(let l of s.anchors)a(l);let d=nr(s);for(let l=0;l<d;l+=1){let f=rr(s,l);for(let c of pg(f))a(no(f,c))}}if(t!==1/0)return{x:t,y:n,w:r-t,h:o-n}}function pg(e){let[t,n,r,o]=e,a=[];for(let s of["x","y"]){let d=-t[s]+3*n[s]-3*r[s]+o[s],l=2*(t[s]-2*n[s]+r[s]),f=n[s]-t[s];if(Math.abs(d)<1e-12){Math.abs(l)>1e-12&&a.push(-f/l);continue}let c=l*l-4*d*f;if(c<0)continue;let m=Math.sqrt(c);a.push((-l+m)/(2*d),(-l-m)/(2*d))}return a.filter(s=>s>0&&s<1)}function ga(e){if(e===void 0)return;let t=e.trim().split(/[\s,]+/).map(Number);if(t.length!==4||t.some(s=>!Number.isFinite(s)))return;let[n,r,o,a]=t;return{x:n,y:r,w:o,h:a}}function On(e){return[e.x,e.y,e.w,e.h].map(Q).join(" ")}function oo(e,t,n){return ga(e)??{x:0,y:0,w:t,h:n}}function ao(e,t){let n=e.w===0?1:t.w/e.w,r=e.h===0?1:t.h/e.h;return o=>({x:t.x+(o.x-e.x)*n,y:t.y+(o.y-e.y)*r})}function vi(e,t){let n=e.w===0||t.w===0?1:e.w/t.w,r=e.h===0||t.h===0?1:e.h/t.h;return o=>({x:e.x+(o.x-t.x)*n,y:e.y+(o.y-t.y)*r})}function bi(e,t=.5){let[n,r,o,a]=e;if($n(n,r)&&$n(o,a))return[n,a];let d=Math.hypot(r.x-n.x,r.y-n.y)+Math.hypot(o.x-r.x,o.y-r.y)+Math.hypot(a.x-o.x,a.y-o.y),l=Math.min(256,Math.max(4,Math.ceil(Math.sqrt(d/t)))),f=[];for(let c=0;c<=l;c+=1)f.push(no(e,c/l));return f}function ya(e){let t=0;for(let n of e)for(let r=0;r<nr(n);r+=1){let o=bi(rr(n,r),.25);for(let a=1;a<o.length;a+=1){let s=o[a-1],d=o[a];t+=Math.hypot(d.x-s.x,d.y-s.y)}}return t}function wi(e,t,n){let r=0,o=0;for(let a of e){let s=mg(a);if(s.length!==0){if(n.reach>0){let d=a.closed?s.length:s.length-1;for(let l=0;l<d;l+=1){let f=s[l],c=s[(l+1)%s.length];if(hg(t,f,c)<=n.reach)return!0}if(s.length===1&&Math.hypot(t.x-s[0].x,t.y-s[0].y)<=n.reach)return!0}if(n.fill)for(let d=0;d<s.length;d+=1){let l=s[d],f=s[(d+1)%s.length];l.y<=t.y!=f.y<=t.y&&l.x+(t.y-l.y)/(f.y-l.y)*(f.x-l.x)>t.x&&(o+=1,r+=f.y>l.y?1:-1)}}}return n.fill?n.rule==="evenodd"?o%2===1:r!==0:!1}function mg(e){let t=e.anchors[0];if(!t)return[];let n=[{x:t.x,y:t.y}],r=nr(e);for(let o=0;o<r;o+=1)n.push(...bi(rr(e,o)).slice(1));return e.closed&&n.length>1&&n.pop(),n}function hg(e,t,n){let r=n.x-t.x,o=n.y-t.y,a=r*r+o*o,s=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*o)/a));return Math.hypot(e.x-(t.x+s*r),e.y-(t.y+s*o))}function ki(e,t){let n;return e.forEach((r,o)=>{let a=nr(r);for(let s=0;s<a;s+=1){let d=rr(r,s),l=v=>{let w=no(d,v);return Math.hypot(w.x-t.x,w.y-t.y)},f=32,c=0;for(let v=1;v<=f;v+=1)l(v/f)<l(c)&&(c=v/f);let m=Math.max(0,c-1/f),g=Math.min(1,c+1/f);for(let v=0;v<24;v+=1){let w=m+(g-m)/3,L=g-(g-m)/3;l(w)<l(L)?g=L:m=w}let b=(m+g)/2,E=l(b);(!n||E<n.distance)&&(n={contour:o,segment:s,t:b,point:no(d,b),distance:E})}}),n}function _i(e,t,n,r){return e.map((o,a)=>{if(a!==t)return o;let s=[...o.anchors],d=s.length,l=s[n],f=(n+1)%d,c=s[f];if(ac(o,n)){let I={x:l.x+(c.x-l.x)*r,y:l.y+(c.y-l.y)*r};return s.splice(n+1,0,I),{...o,anchors:s}}let[m,g,b,E]=rr(o,n),v=(I,j)=>({x:I.x+(j.x-I.x)*r,y:I.y+(j.y-I.y)*r}),w=v(m,g),L=v(g,b),$=v(b,E),z=v(w,L),A=v(L,$),N=v(z,A);return s[n]=to({...l,out:w}),s[f]=to({...c,in:$}),s.splice(n+1,0,to({x:N.x,y:N.y,in:z,out:A})),{...o,anchors:s}})}var xa=.5522847498;function Si(e,t,n=0){let r=Math.max(0,Math.min(n,e/2,t/2));if(r===0)return[{closed:!0,anchors:[{x:0,y:0},{x:e,y:0},{x:e,y:t},{x:0,y:t}]}];let o=xa*r,a=[{x:r,y:0,in:{x:r-o,y:0}},{x:e-r,y:0,out:{x:e-r+o,y:0}},{x:e,y:r,in:{x:e,y:r-o}},{x:e,y:t-r,out:{x:e,y:t-r+o}},{x:e-r,y:t,in:{x:e-r+o,y:t}},{x:r,y:t,out:{x:r-o,y:t}},{x:0,y:t-r,in:{x:0,y:t-r+o}},{x:0,y:r,out:{x:0,y:r-o}}];return[{closed:!0,anchors:xg(a)}]}function Ei(e,t){let n=e/2,r=t/2,o=xa*n,a=xa*r;return[{closed:!0,anchors:[{x:n,y:0,in:{x:n-o,y:0},out:{x:n+o,y:0}},{x:e,y:r,in:{x:e,y:r-a},out:{x:e,y:r+a}},{x:n,y:t,in:{x:n+o,y:t},out:{x:n-o,y:t}},{x:0,y:r,in:{x:0,y:r+a},out:{x:0,y:r-a}}]}]}function xg(e){let t=[];for(let o of e){let a=t[t.length-1];if(a&&$n(a,o)&&!a.out&&!o.in){t[t.length-1]=Ct(a,a.in,o.out);continue}t.push(o)}let n=t[0],r=t[t.length-1];return t.length>1&&n&&r&&$n(n,r)&&!r.out&&!n.in&&(t[0]=Ct(n,r.in,n.out),t.pop()),t}var Mt=class extends Error{op;constructor(t,n){super(t),this.op=n,this.name="OpError"}};function Ae(e,t){let n=e,r=[];for(let o of t){let a=dc(n,o);n=a.document,r.push(a.inverse)}return r.reverse(),{document:n,inverse:r}}function dc(e,t){switch(t.op){case"set":{let n=K(e.root,t.id);if(!n)throw new Mt(`No node ${t.id}`,t);let r=n[t.prop];return{document:va(e,Mi(e.root,t.id,o=>gg(o,t.prop,t.value),t)),inverse:{op:"set",id:t.id,prop:t.prop,value:r}}}case"insert":{if(K(e.root,t.node.id))throw new Mt(`Duplicate id ${t.node.id}`,t);let n=ba(e.root,t.parent,r=>{let o=ic(t.index,0,r.length);return[...r.slice(0,o),t.node,...r.slice(o)]},t);return{document:va(e,n),inverse:{op:"remove",id:t.node.id}}}case"remove":{let n=sc(e,t.id,t),r=ba(e.root,n.parent.id,o=>o.filter(a=>a.id!==t.id),t);return{document:va(e,r),inverse:{op:"insert",parent:n.parent.id,index:n.index,node:n.node}}}case"move":{let n=sc(e,t.id,t),r=ba(e.root,n.parent.id,a=>a.filter(s=>s.id!==t.id),t),o=ba(r,t.parent,a=>{let s=ic(t.index,0,a.length);return[...a.slice(0,s),n.node,...a.slice(s)]},t);return{document:va(e,o),inverse:{op:"move",id:t.id,parent:n.parent.id,index:n.index}}}case"setTitle":{let{title:n,...r}=e;return{document:t.value===void 0?r:{...r,title:t.value},inverse:{op:"setTitle",value:n}}}case"setToken":{let n=Object.prototype.hasOwnProperty.call(e.tokens,t.name)?e.tokens[t.name]:void 0,r={...e.tokens};return t.value===void 0?delete r[t.name]:r[t.name]=t.value,{document:{...e,tokens:r},inverse:{op:"setToken",name:t.name,value:n}}}case"setAsset":{let n=Object.prototype.hasOwnProperty.call(e.assets,t.name)?e.assets[t.name]:void 0,r={...e.assets};return t.value===void 0?delete r[t.name]:r[t.name]=t.value,{document:{...e,assets:r},inverse:{op:"setAsset",name:t.name,value:n}}}case"setFont":{let n=Object.prototype.hasOwnProperty.call(e.fonts,t.name)?e.fonts[t.name]:void 0,r={...e.fonts};return t.family===void 0?delete r[t.name]:r[t.name]=t.family,{document:{...e,fonts:r},inverse:{op:"setFont",name:t.name,family:n}}}case"setBrand":{let{brand:n,...r}=e,o=t.value===void 0?r:{...r,brand:_n(t.value)};return{document:{...o,version:et(o)},inverse:{op:"setBrand",value:n}}}case"setTheme":{let{themes:n,...r}=e,o=_t(t.value),a=o===void 0?r:{...r,themes:o};return{document:{...a,version:et(a)},inverse:{op:"setTheme",value:n}}}case"setKind":{let n={...e,kind:t.value};return{document:{...n,version:et(n)},inverse:{op:"setKind",value:e.kind}}}case"setMotion":{let n=e.motion&&Object.prototype.hasOwnProperty.call(e.motion,t.page)?e.motion[t.page]:void 0,r={...e.motion};return Dt(t.value)?delete r[t.page]:r[t.page]=t.value,{document:xi(e,r),inverse:{op:"setMotion",page:t.page,value:n}}}}}function wa(e,t){if(!e.motion||!t.some(r=>r.op==="remove"||r.op==="move"))return t;let n=gi(e,Ae(e,t).document);return n.length===0?t:[...t,...n]}function va(e,t){if(t.type!=="canvas")throw new Error("The document root must stay a canvas");return{...e,root:t}}function gg(e,t,n){let r={...e};return n===void 0?delete r[t]:r[t]=n,r}function Mi(e,t,n,r){if(e.id===t)return n(e);if(!be(e))return e;let o=!1,a=e.children.map(s=>{let d=Mi(s,t,n,r);return d!==s&&(o=!0),d});return o?{...e,children:a}:e}function ba(e,t,n,r){let o=K(e,t);if(!o)throw new Mt(`No node ${t}`,r);if(!be(o))throw new Mt(`${t} cannot hold children`,r);return Mi(e,t,a=>({...a,children:n(a.children)}),r)}function sc(e,t,n){if(t===e.root.id)throw new Mt("The document root cannot be removed or moved",n);let r,o=a=>{be(a)&&a.children.forEach((s,d)=>{s.id===t&&(r={node:s,parent:a,index:d}),o(s)})};if(o(e.root),!r)throw new Mt(`No node ${t}`,n);return r}function ic(e,t,n){return Math.min(Math.max(e,t),n)}function Ai(e,t){let n=[];e.kind!==t.kind&&n.push({op:"setKind",value:t.kind}),e.title!==t.title&&n.push({op:"setTitle",value:t.title});for(let a of or(e.tokens,t.tokens)){let s=t.tokens[a];e.tokens[a]!==s&&n.push({op:"setToken",name:a,value:s})}for(let a of or(e.fonts,t.fonts)){let s=t.fonts[a];vg(e.fonts[a],s)||n.push({op:"setFont",name:a,family:s})}for(let a of or(e.assets,t.assets)){let s=t.assets[a];(e.assets[a]?.hash!==s?.hash||e.assets[a]?.ms!==s?.ms)&&n.push({op:"setAsset",name:a,value:s})}if(!yg(e.root.children,t.root.children)){for(let a of e.root.children)n.push({op:"remove",id:a.id});t.root.children.forEach((a,s)=>{n.push({op:"insert",parent:e.root.id,index:s,node:a})})}for(let a of or(e.motion??{},t.motion??{})){let s=t.motion?.[a];pa(e.motion?.[a],s)||n.push({op:"setMotion",page:a,value:s})}ni(e.brand,t.brand)||n.push({op:"setBrand",value:t.brand}),bg(e.themes,t.themes)||n.push({op:"setTheme",value:t.themes});let r=e.root,o=t.root;for(let a of or(r,o))a==="type"||a==="id"||a==="children"||lc(r[a],o[a])||n.push({op:"set",id:e.root.id,prop:a,value:o[a]});return n}function or(e,t){return[...new Set([...Object.keys(e),...Object.keys(t)])]}function lc(e,t){return e===t?!0:ke(e)&&ke(t)&&e.expr===t.expr}function yg(e,t){return e.length===t.length&&e.every((n,r)=>Ci(n,t[r]))}function Ci(e,t){if(lc(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,s)=>Ci(a,t[s]));let n=e,r=t;return or(n,r).every(a=>Ci(n[a],r[a]))}function vg(e,t){if(e===t)return!0;if(!e||!t||e.family!==t.family||e.fallback!==t.fallback)return!1;let n=e.faces??[],r=t.faces??[];return n.length===r.length&&n.every((o,a)=>{let s=r[a];return o.src===s.src&&o.asset===s.asset&&o.weight===s.weight&&o.style===s.style})}function bg(e,t){let n=_t(e)?.dark??{},r=_t(t)?.dark??{},o=Object.keys(n);return o.length===Object.keys(r).length&&o.every(a=>n[a]===r[a])}var so={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"]]},io=[["font","string"],["size","number"],["weight","number"],["italic","boolean"],["underline","boolean"],["strike","boolean"],["fill","string"],["letterSpacing","number"],["link","string"]],$i=[["weight","number"],["style","fontStyle"]],lo=[["enter","pageEffect"],["duration","number"],["scroll","boolean"],["length","time"],["w","number"],["h","number"],["bpm","number"],["meter","number"]],Ln=[["enter","nodeEffect"],["exit","nodeEffect"],["emphasis","emphasisEffect"],["from","from"],["by","piece"],["stagger","time"],["duration","time"],["hold","time"],["delay","time"],["at","time"],["after","string"],["with","string"],["step","boolean"],["together","boolean"],["on","on"],["ease","ease"],["pad","number"],["go","string"]],uo=[["from","number"],["volume","number"],["fadein","time"],["fadeout","time"],["loop","boolean"]],cc=Object.keys(so);function ka(e){return cc.includes(e)}function Ti(e,t){return so[e].find(([n])=>n===t)?.[1]}var je=" ";function Ne(e){if(ke(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 wg(t)?JSON.stringify(t):t}function wg(e){return e===""||/[\s"=()]/.test(e)||/^[$@]/.test(e)}function tt(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 r=At(e);return r===void 0?{error:`Malformed quoted string ${e}`}:uc(r,t,e)}if(Eg(e)){if(!kg(t))return{error:_g(e,t)};let r=hc(e).trim();return r===""?{error:"Empty expression"}:{value:Xt(r)}}return t==="numberValue"&&pc.test(e)?{value:Xt(e)}:uc(e,t,e)}var pc=/^-?\d+(?:\.\d+)?%$/;function kg(e){return e==="numberValue"||e==="stringValue"}function _g(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 mc(e,t){let n=/^(-?\d+(?:\.\d+)?)([A-Za-z]+)$/.exec(e);return n?/^(?:beats?|bars?)$/.test(n[2])?" \u2014 beats and bars count motion times on a page with bpm=; this is milliseconds":n[2]==="s"&&t==="number"?` \u2014 durations are milliseconds: ${Number(n[1])*1e3}`:/^(?:px|pt|deg|ms)$/.test(n[2])?` \u2014 drop the unit: ${n[1]}`:" \u2014 units are not supported: use a number, a percentage like (100%), or an expression":t==="number"?pc.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 uc(e,t,n){switch(t){case"numberValue":case"number":{let r=Number(e);return Number.isFinite(r)&&e.trim()!==""?{value:r}:{error:`Expected a number, got ${n}${mc(e,t)}`}}case"align":return Yt.includes(e)?{value:e}:{error:`Expected one of ${Yt.join(", ")}, got ${n}`};case"valign":return Jt.includes(e)?{value:e}:{error:`Expected one of ${Jt.join(", ")}, got ${n}`};case"fontStyle":return e==="normal"||e==="italic"?{value:e}:{error:`Expected normal or italic, got ${n}`};case"imageFit":return Zt.includes(e)?{value:e}:{error:`Expected one of ${Zt.join(", ")}, got ${n}`};case"fillRule":return Rt(bn,e,n);case"lineCap":return Rt(wn,e,n);case"lineJoin":return Rt(kn,e,n);case"blendMode":return Rt(vn,e,n);case"pageEffect":return Rt(Zn,e,n);case"nodeEffect":return Rt(Yr,e,n);case"emphasisEffect":return Rt(Jr,e,n);case"ease":return Rt(Zr,e,n);case"piece":return Rt(Qr,e,n);case"time":{let r=En(e);if(r)return{value:Cn(r.count,r.unit)};let o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{value:o}:{error:`Expected milliseconds or beats, got ${n}${Sg(e)}`}}case"on":return Gr.includes(e)?{value:e}:e==="downbeat"?{error:`Expected beat or bar, got ${n} \u2014 write on=bar: a bar starts on its downbeat`}:e==="beats"||e==="bars"?{error:`Expected beat or bar, got ${n} \u2014 write on=${e.slice(0,-1)}`}:{error:`Expected beat or bar, got ${n}`};case"from":{if(tn.includes(e))return{value:e};let r=Number(e);return Number.isFinite(r)&&e.trim()!==""?{value:r}:{error:`Expected a number or one of ${tn.join(", ")}, got ${n}`}}default:return{value:e}}}function Sg(e){let t=/^(beat|bar|b)[:\s#]?(\d+(?:\.\d+)?)$/.exec(e);if(t){let r=t[1]==="bar"?"bar":"beat",o=Number(t[2]);return` \u2014 write ${Cn(Math.max(0,o-1),r)} (counted from the start: ${r} ${o}'s ${r==="bar"?"downbeat":"start"})`}let n=/^(\d+(?:\.\d+)?)\s*(b|bt|beat|bars?|beats?)$/.exec(e);if(n){let r=n[2]?.startsWith("bar")?"bar":"beat";return` \u2014 write ${Cn(Number(n[1]),r)} (counted from the start)`}return mc(e,"number")}function Rt(e,t,n){return e.includes(t)?{value:t}:{error:`Expected one of ${e.join(", ")}, got ${n}`}}function Eg(e){return/^[$@(]/.test(e)}function At(e){try{let t=JSON.parse(e);return typeof t=="string"?t:void 0}catch{return}}function hc(e){if(!e.startsWith("("))return e;let t=0;for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="(")t+=1;else if(r===")"&&(t-=1,t===0))return n===e.length-1?e.slice(1,-1):e}return e}function xc(e){let t=[],n="",r=0,o=!1;for(let a=0;a<e.length;a+=1){let s=e[a];if(o){n+=s,s==="\\"?(n+=e[a+1]??"",a+=1):s==='"'&&(o=!1);continue}if(s==='"'){o=!0,n+=s;continue}if(s==="("?r+=1:s===")"&&(r=Math.max(0,r-1)),r===0&&/\s/.test(s)){n!==""&&t.push(n),n="";continue}n+=s}return n!==""&&t.push(n),t}function Oi(e,t,n){let r=n===void 0?void 0:Ke(n);if(r?.value===void 0||!fc(e[t]??""))return;let o=t;for(;o<e.length&&fc(e[o]??"");)o+=1;let a=[hc(r.value),...e.slice(t,o)].join(" ");return{end:o,message:`${r.key}: an expression with spaces needs parentheses \u2014 write ${r.key}=(${a})`}}function fc(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)}}function Li(e,t){let n,r=0,o,a=[],s=[],d={},l={},f={},c={},m=[],g=!1,b=!1,E,v=(O,V,C)=>{t.push({severity:"warning",code:V,message:`Line ${O}: ${C}`})},w=(O,V,C)=>{e(O.number,"invalid-brand",`${V} ${C} is written twice \u2014 keep one`)},L=O=>{if(n){e(O.number,"invalid-brand",`A document has one brand line; the first is on line ${r}`);return}let V=O.words[1]===void 0?void 0:ei(O.words[1]);if(!V){e(O.number,"invalid-brand","Expected brand <slug>@<version>, e.g. brand ember@3 \u2014 a slug is lower case, digits and dashes");return}let C=O.words.slice(2).includes("strict"),R=Ft({...O,words:O.words.filter((ee,oe)=>oe<2||ee!=="strict")},2,["id","theme"],e),q=R.theme;q!==void 0&&!aa.includes(q)&&e(O.number,"invalid-brand",`theme= is light or dark, got ${q}`),n={...V,...R.id===void 0?{}:{id:R.id},...q==="dark"||q==="light"?{theme:q}:{},...C?{strict:!0}:{}},r=O.number,E={kind:"brand"}},$=O=>{let V=O.words[0];if(V==="summary"){let C=_a(O,1);C===void 0?e(O.number,"invalid-brand",'Expected summary "\u2026"'):o=C;return}if(V==="change"){let C=Number(O.words[1]),R=O.words[2]===void 0?void 0:yc(O.words[2]);if(!Number.isSafeInteger(C)||C<1||R===void 0){e(O.number,"invalid-brand",'Expected change <version> "<what changed>" at=<date>');return}let q=Ft(O,3,["at"],e);a.push({version:C,note:R,...q.at===void 0?{}:{at:q.at}});return}if(V==="source"){let C=O.words[1];if(C===void 0||C.includes("=")){e(O.number,"invalid-brand","Expected source <kind> key=value\u2026, e.g. source site url=\u2026");return}s.push({kind:C,props:Ft(O,2,void 0,e)});return}if(V==="rule"){N(O);return}if(V==="banned"){let C=_a(O,1);if(C===void 0){e(O.number,"invalid-brand",'Expected banned "\u2026"');return}(c.voice??={entries:[]}).entries.push({kind:"banned",text:C});return}e(O.number,"invalid-brand",`"${V}" is not a line of the brand block \u2014 it holds summary, change and source, and in a design rule and banned`)},z=O=>{let V=O.words[1];if(V===void 0||V.includes("=")){e(O.number,"invalid-role","Expected role <name> light=<token or colour> dark=\u2026");return}let C=Ft(O,2,["light","dark"],e),R=C.light;if(R===void 0){e(O.number,"invalid-role",`role ${V} needs light=`);return}if(Object.prototype.hasOwnProperty.call(d,V))return w(O,"role",V);let q=C.dark;d[V]={light:gc(R),...q===void 0?{}:{dark:gc(q)}}},A=O=>{let V=O.words[1];if(V===void 0||V.includes("=")){e(O.number,"invalid-logo","Expected logo <id> asset=<name> min=<px> clear=<fraction>");return}let C=Ft(O,2,["asset","min","clear"],e),R=C.asset;if(R===void 0){e(O.number,"invalid-logo",`logo ${V} needs asset=`);return}let q={asset:R};for(let ee of["min","clear"]){let oe=C[ee];if(oe===void 0)continue;let se=Number(oe);if(!Number.isFinite(se)||se<0){e(O.number,"invalid-logo",`logo ${V}: ${ee} must be a number, got ${oe}`);continue}q[ee]=se}if(Object.prototype.hasOwnProperty.call(l,V))return w(O,"logo",V);l[V]=q},N=O=>{let V=O.words[1],C=O.words[2],R=O.words[3],q=R?.startsWith('"')===!0?At(R):void 0;if(V===void 0||V.includes("=")){e(O.number,"invalid-rule",'Expected rule <id> must|should "<what it asks>" check=\u2026');return}if(C===void 0||!sa.includes(C)){e(O.number,"invalid-rule",`rule ${V}: the second word is must or should`);return}if(q===void 0){e(O.number,"invalid-rule",`rule ${V} needs its words, quoted: rule ${V} ${C} "\u2026"`);return}let{check:ee,...oe}=Ft(O,4,void 0,e);if(ee!==void 0&&!ia.includes(ee)&&v(O.number,"unknown-check",`rule ${V}: this build has no check "${ee}", so it is kept as words only \u2014 the checks are ${ia.join(", ")}`),Object.prototype.hasOwnProperty.call(f,V))return w(O,"rule",V);f[V]={level:C,text:q,...ee===void 0?{}:{check:ee},...Object.keys(oe).length===0?{}:{params:oe}}},I=(O,V)=>{let C=O.words[0];if(C.startsWith('"')){let R=_a(O,0);R===void 0?e(O.number,"invalid-guide",`Could not read ${O.text}`):V.push({kind:"line",text:R});return}if(C==="banned"||C==="avoid"){let R=_a(O,1);R===void 0?e(O.number,"invalid-guide",`Expected ${C} "\u2026"`):V.push({kind:C,text:R});return}if(C==="rewrite"){let R=Ft(O,1,["from","to"],e),q=R.from,ee=R.to;if(q===void 0||ee===void 0){e(O.number,"invalid-guide",'Expected rewrite from="\u2026" to="\u2026"');return}V.push({kind:"rewrite",from:q,to:ee});return}if(C==="ref"||C==="approved"||C==="rejected"){let R=Ft(O,1,["asset","note"],e),q=R.asset;if(q===void 0){e(O.number,"invalid-guide",`Expected ${C} asset=<name> note="\u2026"`);return}let ee=R.note;V.push({kind:C,asset:q,...ee===void 0?{}:{note:ee}});return}e(O.number,"invalid-guide",`"${C}" is not a guide line \u2014 a guide holds quoted lines, banned, avoid, rewrite, ref, approved and rejected`)},j=O=>{let V=O.words[0];if(V.includes("=")||V.startsWith('"')){e(O.number,"invalid-review",'Expected <what>.<id> from=\u2026 note="\u2026", e.g. role.muted from=site');return}let C=Ft(O,1,["from","note"],e);m.push({target:V,...C.from===void 0?{}:{from:C.from},...C.note===void 0?{}:{note:C.note}})};return{take(O){if(O.indent>0)return E?(E.kind==="brand"?$(O):E.kind==="guide"?I(O,E.entries):j(O),!0):!1;E=void 0;let V=O.words[0];if(V!=="brand"&&!da(V))return!1;switch(b=!0,V){case"brand":L(O);break;case"role":z(O);break;case"logo":A(O);break;case"rule":N(O);break;case"guide":{let C=O.words[1];if(C===void 0||C.includes("=")||O.words.length>2){e(O.number,"invalid-guide","Expected guide <id> on its own line, e.g. guide voice"),E={kind:"guide",id:"",entries:[]};break}if(Object.prototype.hasOwnProperty.call(c,C)){w(O,"guide",C),E={kind:"guide",id:"",entries:[]};break}let R=[];c[C]={entries:R},E={kind:"guide",id:C,entries:R};break}case"review":O.words.length>1&&e(O.number,"invalid-review","review is a block: its items go on the lines under it"),g=!0,E={kind:"review"};break}return!0},finish(){if(!b)return{header:!1,review:!1};let O=n??la();return{brand:{slug:O.slug,version:O.version,...n?.id===void 0?{}:{id:n.id},...n?.theme===void 0?{}:{theme:n.theme},...n?.strict===!0?{strict:!0}:{},...o===void 0?{}:{summary:o},changes:a,sources:s,roles:d,logos:l,rules:f,guides:c,review:m},header:n!==void 0,review:g}}}}function Ft(e,t,n,r){let o={};for(let a of e.words.slice(t)){let{key:s,value:d}=Ke(a);if(d===void 0){r(e.number,"invalid-brand",`A stray word "${a}" \u2014 expected key=value`);continue}if(n!==void 0&&!n.includes(s)){r(e.number,"invalid-brand",`"${s}" is not allowed here; this line takes ${n.join(", ")}`);continue}o[s]=yc(d)}return o}function _a(e,t){if(e.words.length!==t+1)return;let n=e.words[t];return n.startsWith('"')?At(n):void 0}function yc(e){return e.startsWith('"')?At(e)??e:e}function gc(e){return e.startsWith("$")?e.slice(1):e}function vc(e,t,n="brand"){if(!t||t.slug==="")return;let r=["brand",ti(t)];t.id!==void 0&&r.push(`id=${Ne(t.id)}`),t.theme!==void 0&&r.push(`theme=${t.theme}`),t.strict===!0&&r.push("strict"),e.push(r.join(" ")),t.summary!==void 0&&e.push(`${je}summary ${JSON.stringify(t.summary)}`);for(let o of t.changes){let a=["change",Q(o.version),JSON.stringify(o.note)];o.at!==void 0&&a.push(`at=${Ne(o.at)}`),e.push(je+a.join(" "))}for(let o of t.sources)e.push(je+["source",o.kind,...ar(o.props)].join(" "));if(n==="design"){for(let o of bc(t))e.push(je+o);for(let o of Cg(t))e.push(`${je}banned ${JSON.stringify(o)}`)}e.push("")}function bc(e){return Object.entries(e.rules).map(([t,n])=>["rule",t,n.level,JSON.stringify(n.text),...ar({check:n.check,...n.params})].join(" "))}function Cg(e){return(e.guides.voice?.entries??[]).flatMap(t=>t.kind==="banned"?[t.text]:[])}function wc(e,t,n="brand"){if(!t)return;let r=n==="design",o=a=>{a.length!==0&&e.push(...a,"")};o(Object.entries(t.roles).map(([a,s])=>["role",a,...ar({light:s.light,dark:s.dark})].join(" "))),o(Object.entries(t.logos).map(([a,s])=>["logo",a,...ar({asset:s.asset,min:s.min===void 0?void 0:Q(s.min),clear:s.clear===void 0?void 0:Q(s.clear)})].join(" "))),r||o(bc(t));for(let[a,s]of Object.entries(t.guides)){let d=r&&a==="voice"?s.entries.filter(l=>l.kind!=="banned"):s.entries;if(!(r&&d.length===0)){e.push(`guide ${a}`);for(let l of d)e.push(je+Mg(l));e.push("")}}if(t.review.length>0){e.push("review");for(let a of t.review)e.push(je+[a.target,...ar({from:a.from,note:a.note})].join(" "));e.push("")}}function Mg(e){switch(e.kind){case"line":return JSON.stringify(e.text);case"banned":case"avoid":return`${e.kind} ${JSON.stringify(e.text)}`;case"rewrite":return`rewrite from=${JSON.stringify(e.from)} to=${JSON.stringify(e.to)}`;case"ref":case"approved":case"rejected":return[e.kind,...ar({asset:e.asset,note:e.note})].join(" ")}}function ar(e){let t=[];for(let[n,r]of Object.entries(e))r!==void 0&&t.push(`${n}=${Ne(r)}`);return t}var Ag=new Set(["exit","delay","step","together","go","at","after","with"]),_c=["at","after","with","together","step"],$g=new Set(["pad","duration","delay","ease","on",..._c]);function Di(e){if(e==="at"||e==="length")return nn;if(e==="w"||e==="h")return Et;if(e==="duration"||e==="delay"||e==="stagger"||e==="hold")return St;if(e==="pad")return Et}function Pi(e,t){let n=e.words[1];if(n===void 0||n.includes("=")){t(e.number,"invalid-motion","Expected motion <page>, e.g. motion intro enter=fade");return}let r={};for(let a of e.words.slice(2)){let{key:s,value:d}=Ke(a),l=lo.find(([c])=>c===s)?.[1];if(l===void 0){let c=Ag.has(s)?` \u2014 ${s} goes on a node's line, under the header`:"";t(e.number,"invalid-motion",`motion ${n} has no "${s}"${c}`,n);continue}let f=tt(d??"",l);"error"in f?t(e.number,"invalid-motion",`${s}: ${Ig(s,d)??f.error}`,n):s==="bpm"&&!Pg(f.value)?t(e.number,"invalid-motion",`bpm: expected ${20} to ${300} beats a minute, got ${d??""}`,n):s==="meter"&&!Ng(f.value)?t(e.number,"invalid-motion",`meter: expected a whole number of beats in a bar, 1 to ${16}, got ${d??""}`,n):f.value!==!1&&(r[s]=f.value)}let o=gt({...r,lines:[]});for(let[a]of lo){let s=r[a];if(s===void 0||Di(a)===void 0)continue;let d=Ri(a,s,o,n);d!==void 0&&(t(e.number,"invalid-motion",d,n),delete r[a])}return{page:n,number:e.number,head:r,lines:[],where:new Map,taken:new Map,numbers:[]}}function Ni(e,t,n){if(t.words[0]==="music"&&!(t.words[1]??"").includes("=")){Og(e,t,n);return}let r=t.words[0]==="camera"&&t.words[1]!==void 0&&!t.words[1].includes("="),o=r?t.words.slice(1):t.words,a=o[0];if(t.indent!==1){n(t.number,"invalid-motion","A motion line sits one level under its page");return}if(a.includes("=")){n(t.number,"invalid-motion",`Expected a node id first, got ${a}`);return}if(a===e.page&&!r){n(t.number,"invalid-motion",`${a} is the page: its transition goes on the header (motion ${a} enter=fade)`,a);return}let s=r?{id:a,camera:!0}:{id:a},d=!0;for(let c of o.slice(1)){let{key:m,value:g}=Ke(c),b=Ln.find(([w])=>w===m)?.[1];if(b===void 0){n(t.number,"invalid-motion",`A motion line has no "${m}"${Rg(m)}`,a),d=!1;continue}if(r&&!$g.has(m)){n(t.number,"invalid-motion",`A camera line moves the shot and says only pad=, duration=, delay=, ease= and when: not ${m}=`,a),d=!1;continue}let E=tt(g??"",b),v="error"in E||Di(m)===void 0?void 0:Ri(m,E.value,gt(Ec(e)),e.page);"error"in E?(n(t.number,"invalid-motion",`${m}: ${E.error}`,a),d=!1):v!==void 0?(n(t.number,"invalid-motion",`${a}: ${v}`,a),d=!1):m==="on"&&e.head.bpm===void 0?(n(t.number,"invalid-motion",`${a}: on=${String(E.value)} needs a tempo \u2014 motion ${e.page} bpm=120`,a),d=!1):m==="go"&&Lt(E.value)===void 0?(n(t.number,"invalid-motion",`go: expected #<page>, back, next, or an https: or mailto: link, got ${g??""}`,a),d=!1):E.value!==!1&&(s[m]=E.value)}s.enter!==void 0&&s.exit!==void 0&&(n(t.number,"invalid-motion",`${a} either enters or exits on one line \u2014 write a second line for the other`,a),d=!1),s.emphasis!==void 0&&(s.enter!==void 0||s.exit!==void 0)&&(n(t.number,"invalid-motion",`${a} either ${s.enter!==void 0?"enters":"exits"} or is stressed on one line \u2014 write a second line for emphasis=`,a),d=!1);let l=_c.filter(c=>s[c]!==void 0);if(s.step===!0&&s.together===!0?(n(t.number,"invalid-motion",`${a} waits for a step or starts together with the line above, not both`,a),d=!1):l.length>1?(n(t.number,"invalid-motion",`${a} says when it starts twice (${l.join(", ")}): keep one`,a),d=!1):s.on!==void 0&&(s.with!==void 0||s.together===!0)&&(n(t.number,"invalid-motion",`${a} starts with another line (${s.with===void 0?"together":"with="}), so on= could only pull it apart: keep one`,a),d=!1),d){let c=Fg(s);c!==void 0&&(n(t.number,"invalid-motion",`${a}: ${c}`,a),d=!1)}if(!d)return;let f=Dg(s);if(!Qn(f)){n(t.number,"invalid-motion",`${a} says nothing: give it enter=, exit=, emphasis= or go=`,a);return}if(r){e.where.has(a)||e.where.set(a,t.number),e.lines.push(f),e.numbers.push(t.number);return}for(let c of["enter","exit","emphasis","go"]){if(f[c]===void 0)continue;let m=e.taken.get(`${a} ${c}`);if(m!==void 0){let g=c==="go"?"has a go=":c==="enter"?"enters":c==="exit"?"exits":"has an emphasis=";n(t.number,"invalid-motion",`${a} already ${g} on line ${m}`,a);return}}for(let c of["enter","exit","emphasis","go"])f[c]!==void 0&&e.taken.set(`${a} ${c}`,t.number);e.where.has(a)||e.where.set(a,t.number),e.lines.push(f),e.numbers.push(t.number)}function Ii(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}:{},...e.head.length===void 0?{}:{length:e.head.length},...e.head.w===void 0?{}:{w:e.head.w},...e.head.h===void 0?{}:{h:e.head.h},...e.head.bpm===void 0?{}:{bpm:e.head.bpm},...e.head.meter===void 0?{}:{meter:e.head.meter},...e.music===void 0?{}:{music:e.music},lines:e.lines};return Dt(t)?void 0:t}function Sc(e,t){let n=t.motion;if(n)for(let r of er(t)){let o=n[r];if(o===void 0||Dt(o))continue;e.at(-1)!==""&&e.push("");let a=["motion",r];for(let[s,d]of lo){let l=o[s];if(l!==void 0){if(d==="boolean"){l===!0&&a.push(s);continue}a.push(`${s}=${Ne(l)}`)}}if(e.push(a.join(" ")),o.music){let s=["music",o.music.asset];for(let[d,l]of uo){let f=o.music[d];if(f!==void 0){if(l==="boolean"){f===!0&&s.push(d);continue}s.push(`${d}=${Ne(f)}`)}}e.push(je+s.join(" "))}for(let s of o.lines){let d=s.camera===!0?["camera",s.id]:[s.id];for(let[l,f]of Ln){let c=s[l];if(c!==void 0){if(f==="boolean"){c===!0&&d.push(l);continue}d.push(`${l}=${Ne(c)}`)}}e.push(je+d.join(" "))}}}var Tg=new Set(["loop","step","together"]);function Og(e,t,n){let r=t.words[1];if(t.indent!==1){n(t.number,"invalid-motion","A motion line sits one level under its page");return}if(r===void 0){n(t.number,"invalid-motion","Expected music <asset>, e.g. music bed fadeout=1500");return}if(Tg.has(r)){n(t.number,"invalid-motion",`music names its track first: music <asset> ${r}`);return}if(e.musicLine!==void 0){n(t.number,"invalid-motion",`motion ${e.page} already has music on line ${e.musicLine}: a page has one track`);return}let o={asset:r},a=gt(Ec(e)),s=!0,d=f=>{n(t.number,"invalid-motion",`music ${r}: ${f}`),s=!1};for(let f of t.words.slice(2)){let{key:c,value:m}=Ke(f),g=uo.find(([E])=>E===c)?.[1];if(g===void 0){d(`the music line has no "${c}"${Lg(c)}`);continue}if(c==="from"&&m!==void 0&&/\d(?:beats?|bars?)$/.test(m)){d(`from= is where in the track to begin, in milliseconds, not ${m}`);continue}let b=tt(m??"",g);if("error"in b){d(`${c}: ${b.error}`);continue}if(c==="from"&&!kc(b.value,0,Yn)){d(`from: expected 0 to ${Yn} milliseconds, got ${m??""}`);continue}if(c==="volume"&&!kc(b.value,0,1)){d(`volume: expected 0 to 1, got ${m??""}`);continue}if(c==="fadein"||c==="fadeout"){let E=Ri(c,b.value,a,e.page);if(E!==void 0){d(E);continue}}b.value!==!1&&(o[c]=b.value)}if(!s)return;let l={asset:r};for(let[f]of uo)o[f]!==void 0&&(l[f]=o[f]);e.music=l,e.musicLine=t.number}function kc(e,t,n){return typeof e=="number"&&e>=t&&e<=n}function Lg(e){return e==="fade"?" \u2014 write fadein= and fadeout=":e==="fade-in"||e==="fadeIn"||e==="fade_in"?" \u2014 write fadein=":e==="fade-out"||e==="fadeOut"||e==="fade_out"?" \u2014 write fadeout=":e==="start"||e==="offset"||e==="seek"?" \u2014 write from= (where in the track to begin, in milliseconds)":e==="gain"||e==="level"?" \u2014 write volume= (0 to 1)":e==="at"||e==="delay"||e==="after"||e==="with"?": the music starts with the video; from= picks where in the track":": it takes from=, volume=, fadein=, fadeout= and loop"}function Dg(e){let t=e.camera===!0?{id:e.id,camera:!0}:{id:e.id};for(let[n]of Ln)e[n]!==void 0&&(t[n]=e[n]);return t}function Ec(e){let{bpm:t,meter:n}=e.head;return{...t===void 0?{}:{bpm:t},...n===void 0?{}:{meter:n},lines:[]}}function Ri(e,t,n,r){if(Mn(t)&&!n)return`${t} needs a tempo \u2014 motion ${r} bpm=120`;let o=typeof t=="number"||Mn(t)?ze(t,n):void 0,a=Di(e)??St;if(o!==void 0&&o>=(e==="w"||e==="h"?16:0)&&o<=a)return;let d=String(t),l=Mn(t)&&o!==void 0?` (${Math.round(o)} ms)`:"";return e==="w"||e==="h"?`${e}: expected 16 to ${Et} pixels, got ${d}`:e==="pad"?`pad: expected 0 to ${Et}, got ${d}`:`${e}: expected 0 to ${a} milliseconds, got ${d}${l}`}function Pg(e){return typeof e=="number"&&e>=20&&e<=300}function Ng(e){return typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=16}function Ig(e,t){if(e==="meter"&&t!==void 0&&/^\d+\/\d+$/.test(t))return`Expected beats in a bar, got ${t} \u2014 meter is beats per bar: meter=${t.split("/")[0]??""}`;if(e==="duration"&&t!==void 0&&/\d(?:beats?|bars?)$/.test(t))return`Expected milliseconds, got ${t} \u2014 the page transition is milliseconds; beats are for the lines`}function Rg(e){return e==="emphasise"||e==="emphasize"?" \u2014 write emphasis=pulse":e==="easing"?" \u2014 write ease=":e==="split"?" \u2014 write by=word or by=letter":e==="start"?" \u2014 write at= (milliseconds), after= or with=":""}function Fg(e){let t=e.enter,n=e.exit,r=t??n,o=e.from;if(n==="count")return"count only enters: it runs a number up to its written value";if(o!==void 0)if(r==="count"){if(typeof o!="number")return"from= on count is the number it starts at, e.g. from=0"}else if(r==="wipe"||r==="grow"){if(typeof o=="number")return`from= on ${r} is a side: ${tn.join(", ")}`}else return"from= goes with count (a number), or wipe and grow (a side)";if(e.by!==void 0&&r!==void 0&&!Jn.includes(r))return`by= splits a text for ${Jn.join(", ")}, not ${r}`;if(e.by!==void 0&&r===void 0)return"by= goes with enter= or exit=";if(e.stagger!==void 0&&r===void 0)return"stagger= goes with enter= or exit=";if(e.hold!==void 0&&t===void 0)return"hold= goes with enter=: how long to stay before leaving the way it came"}var Bg=24;function Bi(e,t={}){let n=[`version ${Q(et(e))}`,`kind ${e.kind}`];e.title!==void 0&&n.push(`title ${JSON.stringify(e.title)}`),vc(n,e.brand,e.kind);for(let[o,a]of Object.entries(e.tokens))n.push(`$${o} = ${Ne(a)}`);n.at(-1)!==""&&n.push("");let r=e.themes?.dark;if(r!==void 0&&Object.keys(r).length>0){n.push("theme dark");for(let[o,a]of Object.entries(r))n.push(` $${o} = ${Ne(a)}`);n.push("")}for(let[o,a]of Object.entries(e.fonts))Vg(n,o,a,t),n.push("");if(Object.keys(e.assets).length>0){for(let[o,a]of Object.entries(e.assets))n.push(Ug(o,a));n.push("")}return wc(n,e.brand,e.kind),Hg(e.root)?e.root.children.forEach((o,a)=>{a>0&&n.push(""),Fi(n,o,0)}):Fi(n,e.root,0),Sc(n,e),n.join(`
29
+ `)}function Hg(e){return e.id===kt&&e.w===void 0&&e.h===void 0&&e.background===void 0&&e.name===void 0}function Ug(e,t){let n=[`asset ${e} = ${t.type}`,`hash=${t.hash}`,`bytes=${Q(t.bytes)}`];t.ms!==void 0&&n.push(`ms=${Q(t.ms)}`);for(let r of["credit","source","license"]){let o=t[r];o!==void 0&&n.push(`${r}=${Ne(o)}`)}return n.join(" ")}function Vg(e,t,n,r){e.push(`font ${t} = ${Ne(n.family)}`),n.fallback!==void 0&&e.push(`${je}fallback ${Ne(n.fallback)}`);for(let o of n.faces??[]){let a=o.asset!==void 0?[`face asset=${o.asset}`]:[`face ${Ne(r.abbreviateFaces?zg(o.src??""):o.src??"")}`];for(let[s]of $i){let d=o[s];d!==void 0&&a.push(`${s}=${Ne(d)}`)}e.push(je+a.join(" "))}}function zg(e){return e.startsWith("data:")?`${e.slice(0,Bg)}\u2026 ${Q(Math.round(e.length/1024))} kB`:e}function Fi(e,t,n){let r=je.repeat(n),o=t,a=[t.type,t.id];for(let[s,d]of so[t.type]){let l=o[s];if(l!==void 0){if(d==="boolean"){l===!0&&a.push(s);continue}a.push(`${s}=${Ne(l)}`)}}if(e.push(r+a.join(" ")),t.type==="text"&&jg(e,t.content,n+1),be(t))for(let s of de(t))Fi(e,s,n+1)}function jg(e,t,n){let r=je.repeat(n),o=typeof t=="string"?[t]:t;for(let a of o){if(typeof a=="string"){e.push(r+JSON.stringify(a));continue}e.push(r+[JSON.stringify(a.text),...Kg(a)].join(" "))}}function Kg(e){let t=[];for(let[n,r]of io){let o=e[n];if(o!==void 0){if(r==="boolean"){o===!0&&t.push(n);continue}t.push(`${n}=${Ne(o)}`)}}return t}var Dn="--- payload base64 ---",Cc="sha256-";function Mc(e){let t=qg(e);return t===-1?{head:e,payload:""}:{head:e.slice(0,t),payload:e.slice(t+Dn.length)}}function Hi(e){let{head:t,payload:n}=Mc(e);return{head:t,blocks:Ac(n)}}function Ui(e,t){let n=new Map;for(let r of Gg(e)){let o=t.get(r);o!==void 0&&n.set(r,o)}return n.size===0?e:`${e.trimEnd()}
30
30
 
31
- ${nc(n)}`}function tc(e){let t=new Map;for(let n of e.split(`
32
- `)){let r=n.indexOf(" ");if(r===-1)continue;let o=n.slice(0,r);o.startsWith(Qu)&&t.set(o,n.slice(r+1).trim())}return t}function nc(e){let t=[...e.entries()].sort(([n],[r])=>n<r?-1:n>r?1:0).map(([n,r])=>`${n} ${r}`);return`${Mn}
31
+ ${$c(n)}`}function Ac(e){let t=new Map;for(let n of e.split(`
32
+ `)){let r=n.indexOf(" ");if(r===-1)continue;let o=n.slice(0,r);o.startsWith(Cc)&&t.set(o,n.slice(r+1).trim())}return t}function $c(e){let t=[...e.entries()].sort(([n],[r])=>n<r?-1:n>r?1:0).map(([n,r])=>`${n} ${r}`);return`${Dn}
33
33
  ${t.join(`
34
34
  `)}
35
- `}async function Ss(e){let t=await crypto.subtle.digest("SHA-256",e),n=[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0"));return`${Qu}${n.join("")}`}function Es(e,t){return`data:${e};base64,${t}`}function Cs(e){let t=e.toBase64;if(typeof t=="function")return t.call(e);let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function Ms(e){let t=Uint8Array.fromBase64;if(typeof t=="function")return t(e);let n=atob(e),r=new Uint8Array(n.length);for(let o=0;o<n.length;o+=1)r[o]=n.charCodeAt(o);return r}function cg(e){if(e.startsWith(Mn))return 0;let t=e.indexOf(`
36
- ${Mn}`);return t===-1?-1:t+1}function pg(e){let t=new Set;for(let n of e.matchAll(/sha256-[0-9a-f]{64}/g))t.add(n[0]);return t}function As(e){return(t,n,r,o)=>{e.push({severity:"error",code:n,message:`Line ${t}: ${r}`,...o===void 0?{}:{nodeId:o}})}}function $s(e){let t=[],n=e.split(`
37
- `);for(let r=0;r<n.length;r+=1){let o=n[r],a=o.trim();if(a===Mn)break;if(a===""||a.startsWith("```"))continue;let i=o.length-o.trimStart().length;t.push({number:r+1,indent:Math.floor(i/2),text:a,words:Wu(a)})}return t}function Ts(e){let t=[],n=[],r=o=>{for(;t.length>0&&t[t.length-1].indent>=o;)hg(t.pop())};return{push(o){let a=o.words[0];if(a.startsWith('"')){let u=t[t.length-1];if(!u||u.type!=="text")return e(o.number,"invalid-content","A quoted line must sit inside a text node"),!0;let p=gg(o,e);return p!==void 0&&u.runs.push(p),!0}if(!fa(a))return!1;r(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=mg(a,i,o.words.slice(2),o,e),d=t[t.length-1];return d?d.children.push(l.record):n.push(l.record),t.push(l),!0},finish(){return r(0),n}}}function mg(e,t,n,r,o){let a={type:e,id:t},i=[];for(let l=0;l<n.length;l+=1){let{key:d,value:u}=Ye(n[l]),p=ps(e,d);if(p===void 0){let y=ms(n,l,n[l-1]);y?(o(r.number,"invalid-value",y.message,t),l=y.end-1):o(r.number,"invalid-value",`${e} has no property "${d}"`,t);continue}let x=Xe(u??"",p);"error"in x?o(r.number,"invalid-value",`${d}: ${x.error}`,t):a[d]=x.value}return Xo(e)&&(a.children=i),e==="text"&&(a.content=""),{indent:r.indent,type:e,record:a,children:i,runs:[]}}function hg(e){e.type==="text"&&(e.record.content=xg(e.runs))}function xg(e){if(e.length===0)return"";let t=e[0];return e.length===1&&typeof t=="string"?t:[...e]}function gg(e,t){let n=Zn(e.words[0]);if(n===void 0){t(e.number,"invalid-run","Malformed quoted string");return}if(e.words.length===1)return n;let r={text:n};for(let o of e.words.slice(1)){let{key:a,value:i}=Ye(o),l=eo.find(([u])=>u===a);if(!l){t(e.number,"invalid-run",`A run has no mark "${a}"`);continue}let d=Xe(i??"",l[1]);"error"in d?t(e.number,"invalid-run",`${a}: ${d.error}`):r[a]=d.value}return r}function ro(e){let t=[],n=As(t),r=Gt,o,a=!1,i={},l={},d={},u=Ts(n),p,x={},y=new Map,k,M=!1,v=()=>{if(!k)return;let E=k;k=void 0;let T=y.get(E.page);if(T!==void 0){n(E.number,"invalid-motion",`motion ${E.page} is written twice \u2014 put its lines in the block on line ${T}`,E.page);return}y.set(E.page,E.number);for(let[V,X]of E.where)y.set(`${E.page} ${V}`,X);let P=ys(E);P&&(x[E.page]=P)};for(let E of $s(e)){let T=E.words[0];if(k&&E.indent>0){gs(k,E,n);continue}if(!(M&&E.indent>0)){if(M=!1,v(),T==="motion"&&E.indent===0){p=void 0,k=xs(E,n),M=k===void 0;continue}if(T==="version"){a=!0,vg(E,t);continue}if(T==="kind"&&E.indent===0){r=bg(E,t);continue}if(T==="title"&&E.indent===0){o=rc(E,n);continue}if(T.startsWith("$")){p=void 0,wg(E,i,n);continue}if(T==="asset"&&E.indent===0){p=void 0,kg(E,d,n);continue}if(T==="font"&&E.indent===0){p=Sg(E,l,n);continue}if((T==="fallback"||T==="face")&&p){Eg(T,E,p,n);continue}p=void 0,!u.push(E)&&n(E.number,"unknown-node-type",`Unknown statement "${T}"`)}}v();let w=yg(u.finish(),t),D=Object.keys(x).length===0?{}:{motion:x},A=(E,T)=>y.get(T===void 0?E:`${E} ${T}`);if(!w){a||t.push({severity:"error",code:"invalid-document",message:"No nodes found"});let E=Vn({id:vt,children:[]}),T=Br({kind:r,...o===void 0?{}:{title:o},tokens:i,fonts:l,assets:d,...D,root:E});return t.push(...Wn(T,A)),{document:T,problems:t}}let H={version:4,kind:r,...o===void 0?{}:{title:o},tokens:i,fonts:l,assets:d,...D,root:w};return t.push(...Wn(H,A)),{document:H,problems:t}}function yg(e,t){let n=e[0];if(n!==void 0){if(e.length===1&&n.type==="canvas")return n;for(let r of e){if(r.type!=="canvas")continue;let o=r.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:vt,children:[...e]}}}function vg(e,t){Fr.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 bg(e,t){let n=e.words[1];return n!==void 0&&yn.includes(n)?n:(t.push({severity:"error",code:"unknown-kind",message:`Line ${e.number}: unknown kind "${n??"nothing"}" \u2014 this build reads ${yn.join(", ")}`}),Gt)}function rc(e,t){let n=e.words.slice(1).join(" ").trim();if(n===""){t(e.number,"invalid-value",'title needs a name, e.g. title "Pitch deck"');return}let r=n.startsWith('"')?Zn(n):n;if(r===void 0){t(e.number,"invalid-value",`Could not read the title ${n}`);return}return r.trim()===""?void 0:r}function wg(e,t,n){let{name:r,value:o}=Ls(e.words);if(r===void 0||o===void 0){n(e.number,"invalid-token","Expected $name = value");return}if(!o.startsWith('"')&&/\s/.test(o)){n(e.number,"invalid-token",`$${r}: expected one value, got "${o}". Quote it if the value has spaces; there are no comments.`);return}let a=Xe(o,"stringValue");if("error"in a){n(e.number,"invalid-token",`$${r}: ${a.error}`);return}if(typeof a.value!="string"){n(e.number,"invalid-token",`$${r} may not be an expression`);return}t[r]=oc(a.value,o)}function oc(e,t){let n=Number(e);return t.startsWith('"')||!Number.isFinite(n)||e.trim()===""?e:n}function Ls(e){let t=e[0],n=a=>a.startsWith("$")?a.slice(1):a;if(e[1]==="=")return{name:n(t),value:e.slice(2).join(" ")||void 0};let{key:r,value:o}=Ye(t);return o!==void 0?{name:n(r),value:o}:{name:n(t)}}function kg(e,t,n){let r=e.words.slice(1),o=r[0],a=r[1]==="=",i=o===void 0?void 0:Ye(o),l=i?.key,d=a?r[2]:i?.value,u=r.slice(a?3:1);if(l===void 0||l===""||d===void 0){n(e.number,"invalid-asset","Expected asset <name> = <type> hash=\u2026 bytes=\u2026");return}let p={};for(let M of u){let{key:v,value:w}=Ye(M);if(w===void 0){n(e.number,"invalid-asset",`Asset "${l}" has a stray word "${M}"`);continue}p[v]=_g(w)}let x=p.hash,y=Number(p.bytes);if(x===void 0||!Number.isFinite(y)){n(e.number,"invalid-asset",`Asset "${l}" needs a hash and a bytes count`);return}let k=p.ms===void 0?void 0:Number(p.ms);if(k!==void 0&&!(Number.isFinite(k)&&k>=0)){n(e.number,"invalid-asset",`Asset "${l}": ms is the track's length, in milliseconds`);return}t[l]={type:d,hash:x,bytes:y,...k===void 0?{}:{ms:k},...p.credit===void 0?{}:{credit:p.credit},...p.source===void 0?{}:{source:p.source},...p.license===void 0?{}:{license:p.license}}}function _g(e){return e.startsWith('"')?Zn(e)??e:e}function Sg(e,t,n){let{name:r,value:o}=Ls(e.words.slice(1));if(r===void 0||o===void 0){n(e.number,"invalid-font","Expected font <name> = <family>");return}let a=Xe(o,"string"),i={family:"error"in a?o:a.value};return t[r]=i,{family:i,faces:[]}}function Eg(e,t,n,r){if(e==="fallback"){let l=Xe(t.words.slice(1).join(" "),"string");"error"in l?r(t.number,"invalid-font",`fallback: ${l.error}`):n.family.fallback=l.value;return}let o=t.words[1];if(o===void 0){r(t.number,"invalid-font-face","A face needs a src");return}let a=Xe(o,"string"),i={src:"error"in a?o:a.value};for(let l of t.words.slice(2)){let{key:d,value:u}=Ye(l);if(d!=="weight"&&d!=="style"){r(t.number,"invalid-font-face",`A face has no property "${d}"`);continue}let p=Xe(u??"",d==="weight"?"number":"fontStyle");"error"in p?r(t.number,"invalid-font-face",`${d}: ${p.error}`):i[d]=p.value}n.faces.push(i),n.family.faces=n.faces}var ic="https://getv.design/ns/vd",bw=`<metadata><vd:document xmlns:vd="${ic}" version="1"><![CDATA[
38
- `;var Cg=/<vd:document\b[^>]*>([\s\S]*?)<\/vd:document\s*>/;function Os(e){let t=Cg.exec(e);if(!t)return;let n=t[1]??"",r="",o=n;for(;;){let a=o.indexOf("<![CDATA[");if(a===-1){r+=ac(o);break}r+=ac(o.slice(0,a));let i=o.indexOf("]]>",a);if(i===-1){r+=o.slice(a+9);break}r+=o.slice(a+9,i),o=o.slice(i+3)}return`${r.replace(/^\n/,"").replace(/\n$/,"")}
39
- `}function Ds(e){return/^\uFEFF?\s*</.test(e)}function ac(e){return e.replace(/&(lt|gt|quot|apos|amp|#\d+|#x[0-9a-fA-F]+);/g,(t,n)=>{switch(n){case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";case"amp":return"&";default:{let r=n.startsWith("#x")?parseInt(n.slice(2),16):parseInt(n.slice(1),10);return Number.isFinite(r)&&r<=1114111?String.fromCodePoint(r):t}}})}function Is(e){let t=[],n=Je(e);if(!n)return t.push({severity:"error",code:"invalid-document",message:"Expected an object"}),{document:Br(),problems:t};Fr.includes(n.version)||t.push({severity:"warning",code:"version-mismatch",message:`Expected version ${4} or older, got ${JSON.stringify(n.version)}`});let r=lc(n.root,t),o=Mg(n.motion,t),a={version:4,kind:Og(n.kind,t),...typeof n.title=="string"&&n.title.trim()!==""?{title:n.title}:{},tokens:Dg(n.tokens,t),fonts:Ig(n.fonts,t),assets:Pg(n.assets,t),...o===void 0?{}:{motion:o},root:r??Vn({id:vt,children:[]})};return Gg(a.root,t),t.push(...Wn(a)),{document:a,problems:t}}function Mg(e,t){if(e===void 0)return;let n=Je(e),r=a=>{t.push({severity:"error",code:"invalid-motion",message:a})};if(!n){r("`motion` must be an object");return}let o={};for(let[a,i]of Object.entries(n)){let l=Je(i);if(!l||!Array.isArray(l.lines)){r(`motion ${a} must be an object with a lines array`);continue}let d=l.enter,u=l.duration;if(d!==void 0&&!qn.includes(d)){r(`motion ${a}: enter must be one of ${qn.join(", ")}`);continue}if(u!==void 0&&!Lg(u)){r(`motion ${a}: duration must be 0 to ${bt} milliseconds`);continue}let p=l.scroll;if(p!==void 0&&typeof p!="boolean"){r(`motion ${a}: scroll must be true or false`);continue}let x=l.bpm,y=l.meter;if(x!==void 0&&!(typeof x=="number"&&x>=20&&x<=300)){r(`motion ${a}: bpm must be ${20} to ${300}`);continue}if(y!==void 0&&!(typeof y=="number"&&Number.isInteger(y)&&y>=1&&y<=16)){r(`motion ${a}: meter must be a whole number from 1 to ${16}`);continue}let k=mt({...x===void 0?{}:{bpm:x},...y===void 0?{}:{meter:y},lines:[]}),M=Tg(l.music,k);if(M===null){r(`motion ${a}: music must be { asset, from?, volume?, fadein?, fadeout?, loop? }`);continue}let v=l.length;if(v!==void 0&&!Ns(v,Yt,k)){r(`motion ${a}: length must be 0 to ${Yt} milliseconds, or beats with a bpm`);continue}let w=H=>H===void 0||typeof H=="number"&&H>=16&&H<=wt;if(!w(l.w)||!w(l.h)){r(`motion ${a}: w and h must be 16 to ${wt} pixels`);continue}let D=l.lines.flatMap(H=>{let E=Ag(H,k);return E===void 0&&r(`motion ${a}: a line that is not one: ${JSON.stringify(H)}`),E===void 0?[]:[E]}),A={...d===void 0?{}:{enter:d},...u===void 0?{}:{duration:u},...p===!0?{scroll:!0}:{},...v===void 0?{}:{length:v},...l.w===void 0?{}:{w:l.w},...l.h===void 0?{}:{h:l.h},...x===void 0?{}:{bpm:x},...y===void 0?{}:{meter:y},...M===void 0?{}:{music:M},lines:D};At(A)||(o[a]=A)}return Object.keys(o).length===0?void 0:o}function Ag(e,t){let n=Je(e);if(!n||typeof n.id!="string")return;let r={id:n.id};if(n.camera!==void 0){if(n.camera!==!0)return;r.camera=!0}for(let[x,y]of Cn){let k=n[x];if(k!==void 0){if(!$g(x,y,k,t))return;r[x]=k}}if(r.on!==void 0&&(!t||r.with!==void 0||r.together))return;let{enter:o,exit:a,emphasis:i,step:l,together:d}=r;if(o!==void 0&&a!==void 0||i!==void 0&&(o!==void 0||a!==void 0)||l===!0&&d===!0||["at","after","with","together","step"].filter(x=>r[x]!==void 0).length>1||r.camera===!0&&(o??a??i??r.go)!==void 0)return;let p=r;return Kn(p)?p:void 0}function $g(e,t,n,r){switch(t){case"time":return Ns(n,e==="at"?Yt:bt,r);case"on":return Hr.includes(n);case"boolean":return n===!0;case"number":return typeof n!="number"||!Number.isFinite(n)||n<0?!1:e==="at"?n<=Yt:e==="pad"?n<=wt:n<=bt;case"string":return typeof n=="string"&&(e!=="go"||Mt(n)!==void 0);case"nodeEffect":return zr.includes(n);case"emphasisEffect":return jr.includes(n);case"ease":return qr.includes(n);case"piece":return Kr.includes(n);case"from":return typeof n=="number"&&Number.isFinite(n)||Xt.includes(n);default:return!1}}function Tg(e,t){if(e===void 0)return;let n=Je(e);if(!n||typeof n.asset!="string"||n.asset==="")return null;let r={asset:n.asset};for(let i of Object.keys(n))if(i!=="asset"&&!Vr.includes(i))return null;let o=n.from;if(o!==void 0&&!(typeof o=="number"&&o>=0&&o<=zn))return null;let a=n.volume;if(a!==void 0&&!(typeof a=="number"&&a>=0&&a<=1))return null;for(let i of["fadein","fadeout"])if(n[i]!==void 0&&!Ns(n[i],bt,t))return null;if(n.loop!==void 0&&n.loop!==!0)return null;for(let i of Vr)n[i]!==void 0&&(r[i]=n[i]);return r}function Ns(e,t,n){if(typeof e=="number")return Number.isFinite(e)&&e>=0&&e<=t;if(!wn(e)||!n)return!1;let r=vn(e);if(!r||bn(r.count,r.unit)!==e)return!1;let o=Ve(e,n);return o!==void 0&&o<=t}function Lg(e){return typeof e=="number"&&e>=0&&e<=bt}function Og(e,t){return e==null?Gt:typeof e=="string"&&yn.includes(e)?e:(t.push({severity:"error",code:"unknown-kind",message:`Unknown kind ${JSON.stringify(e)} \u2014 this build reads ${yn.join(", ")}`}),Gt)}function Dg(e,t){let n={};if(e===void 0)return n;let r=Je(e);if(!r)return t.push({severity:"error",code:"invalid-tokens",message:"`tokens` must be an object"}),n;for(let[o,a]of Object.entries(r))typeof a=="number"||typeof a=="string"?n[o]=a:t.push({severity:"error",code:"invalid-token",message:`Token $${o} must be a number or string`});return n}function Pg(e,t){let n={};if(e===void 0)return n;let r=Je(e);if(!r)return t.push({severity:"error",code:"invalid-assets",message:"`assets` must be an object"}),n;for(let[o,a]of Object.entries(r)){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}n[o]={type:i.type,hash:i.hash,bytes:i.bytes,...typeof i.ms=="number"&&i.ms>=0?{ms:i.ms}:{},...dt(i.credit,"credit"),...dt(i.source,"source"),...dt(i.license,"license")}}return n}function Ig(e,t){let n={};if(e===void 0)return n;let r=Je(e);if(!r)return t.push({severity:"error",code:"invalid-fonts",message:"`fonts` must be an object"}),n;for(let[o,a]of Object.entries(r)){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}n[o]={family:i.family,...typeof i.fallback=="string"?{fallback:i.fallback}:{},...Ng(i.faces,o,t)}}return n}function Ng(e,t,n){if(e===void 0)return{};if(!Array.isArray(e))return n.push({severity:"error",code:"invalid-font",message:`Font "${t}" has a "faces" that is not an array`}),{};let r=[];for(let o of e){let a=Je(o);if(!a||typeof a.src!="string"){n.push({severity:"error",code:"invalid-font-face",message:`A face of font "${t}" is missing its "src"`});continue}let i=a.style;r.push({src:a.src,...typeof a.weight=="number"?{weight:a.weight}:{},...i==="italic"||i==="normal"?{style:i}:{}})}return r.length>0?{faces:r}:{}}function Rg(e,t){let n=Je(e);if(!n){t.push({severity:"error",code:"invalid-node",message:"Expected a node object"});return}switch(n.type){case"canvas":return lc(e,t);case"ellipse":return Vg(n,t);case"frame":return Fg(n,t);case"group":return Bg(n,t);case"image":return Hg(n,t);case"rect":return Ug(n,t);case"text":return jg(n,t);case"vector":return zg(n,t);default:t.push({severity:"error",code:"unknown-node-type",message:`Unknown node type ${JSON.stringify(n.type)}`,...typeof n.id=="string"?{nodeId:n.id}:{}});return}}function lc(e,t){let n=Je(e);if(!n){t.push({severity:"error",code:"invalid-node",message:"`root` must be a canvas node"});return}let r=Qt(n,vt,t);return{type:"canvas",id:r,...dt(n.name,"name"),...sc(n,"w",1280,r,t),...sc(n,"h",720,r,t),...ft(n.background,r,"background",t),children:Rs(n.children,r,t)}}function sc(e,t,n,r,o){return e[t]===void 0?{}:{[t]:Ee(e[t],r,t,n,o)}}function Fg(e,t){let n=Qt(e,"frame",t);return{type:"frame",id:n,...dt(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",0,t),h:Ee(e.h,n,"h",0,t),...ft(e.background,n,"background",t),...Ps(e.clip,"clip"),...Ps(e.skip,"skip"),...or(e,n,t),...An(e),children:Rs(e.children,n,t)}}function Bg(e,t){let n=Qt(e,"group",t);return{type:"group",id:n,...dt(e.name,"name"),...An(e),children:Rs(e.children,n,t)}}function Rs(e,t,n){let r=[];if(Array.isArray(e))for(let o of e){let a=Rg(o,n);a&&r.push(a)}else e!==void 0&&n.push({severity:"error",code:"invalid-children",message:"`children` must be an array",nodeId:t});return r}function Hg(e,t){let n=Qt(e,"image",t),r=e.fit,o=ft(e.src,n,"src",t);return{type:"image",id:n,...dt(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",100,t),h:Ee(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),src:o.src??"",...Kt.includes(r)?{fit:r}:{},...Pe(e.radius,n,"radius",t),...Pe(e.opacity,n,"opacity",t),...or(e,n,t),...An(e)}}function Ug(e,t){let n=Qt(e,"rect",t);return{type:"rect",id:n,...dt(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",100,t),h:Ee(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...ft(e.fill,n,"fill",t),...ft(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.radius,n,"radius",t),...Pe(e.opacity,n,"opacity",t),...or(e,n,t),...An(e)}}function Vg(e,t){let n=Qt(e,"ellipse",t);return{type:"ellipse",id:n,...dt(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",100,t),h:Ee(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...ft(e.fill,n,"fill",t),...ft(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.opacity,n,"opacity",t),...or(e,n,t),...An(e)}}function zg(e,t){let n=Qt(e,"vector",t);return{type:"vector",id:n,...dt(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",100,t),h:Ee(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...dt(e.view,"view"),d:typeof e.d=="string"?e.d:"",...ft(e.fill,n,"fill",t),...ft(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.opacity,n,"opacity",t),...rr(e.rule,hn,n,"rule",t),...rr(e.cap,xn,n,"cap",t),...rr(e.join,gn,n,"join",t),...or(e,n,t),...An(e)}}function jg(e,t){let n=Qt(e,"text",t);return{type:"text",id:n,...dt(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",200,t),h:Ee(e.h,n,"h",40,t),...Pe(e.rotation,n,"rotation",t),content:qg(e.content,n,t),...ft(e.font,n,"font",t),...Pe(e.size,n,"size",t),...Pe(e.weight,n,"weight",t),...Pe(e.lineHeight,n,"lineHeight",t),...Pe(e.letterSpacing,n,"letterSpacing",t),...rr(e.align,jt,n,"align",t),...rr(e.valign,qt,n,"valign",t),...Ps(e.italic,"italic"),...ft(e.fill,n,"fill",t),...Pe(e.opacity,n,"opacity",t),...or(e,n,t),...An(e)}}function qg(e,t,n){if(e===void 0)return"";if(typeof e=="string")return e;if(!Array.isArray(e))return n.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 r=[];for(let o of e){if(typeof o=="string"){r.push(o);continue}let a=Je(o);if(!a||typeof a.text!="string"){n.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}r.push({text:a.text,...Dt(a,"font","string"),...Dt(a,"size","number"),...Dt(a,"weight","number"),...Dt(a,"italic","boolean"),...Dt(a,"underline","boolean"),...Dt(a,"strike","boolean"),...Dt(a,"fill","string"),...Dt(a,"letterSpacing","number"),...Dt(a,"link","string")})}return r}function Dt(e,t,n){let r=e[t];return typeof r!==n?{}:n==="number"&&!Number.isFinite(r)?{}:{[t]:r}}function or(e,t,n){return{...rr(e.blend,mn,t,"blend",n),...ft(e.shadow,t,"shadow",n)}}function An(e){return{...e.hidden===!0?{hidden:!0}:{},...e.locked===!0?{locked:!0}:{}}}function Ps(e,t){return typeof e=="boolean"?{[t]:e}:{}}function rr(e,t,n,r,o){return e===void 0?{}:typeof e=="string"&&t.includes(e)?{[r]:e}:(o.push({severity:"error",code:"invalid-value",message:`Expected one of ${t.join(", ")} for ${r}, got ${JSON.stringify(e)}`,nodeId:n,prop:r}),{})}function Qt(e,t,n){let r=e.id;return typeof r=="string"&&r.length>0?r:(n.push({severity:"error",code:"missing-id",message:`Node is missing an id; using "${t}"`}),t)}function Ee(e,t,n,r,o){let a=Kg(e);return a!==void 0?a:(o.push({severity:"error",code:"invalid-value",message:`Expected a number or expression for ${n}, got ${JSON.stringify(e)}`,nodeId:t,prop:n}),r)}function Kg(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.startsWith("="))return zt(e.slice(1))}function Pe(e,t,n,r){return e===void 0?{}:{[n]:Ee(e,t,n,0,r)}}function ft(e,t,n,r){return e===void 0?{}:typeof e=="string"?{[n]:e.startsWith("=")?zt(e.slice(1)):e}:(r.push({severity:"error",code:"invalid-value",message:`Expected a string for ${n}, got ${JSON.stringify(e)}`,nodeId:t,prop:n}),{})}function dt(e,t){return typeof e=="string"?{[t]:e}:{}}function Gg(e,t){let n=new Set,r=o=>{n.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}),n.add(o.id),ye(o)&&o.children.forEach(r)};r(e)}function Je(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}var dc=1500,Fs=5e3,fc=1200,uc=800,cc=600,pc=800,mc={letter:30,word:80,children:100},oo=.04,ao=.85,Bs=1.06,ua=[.2,0,0,1],ca=[.4,0,1,1],pa=[.4,0,.2,1],hc=[.34,1.56,.64,1],Wg={out:ua,in:ca,inout:pa,linear:null,spring:hc};function Hs(e,t){let n=e.motion?.[t],r=n?.w!==void 0||n?.h!==void 0?Xg(e,t,n):void 0,o=mt(n),a=o?{tempo:o}:{},i=Ji(n,e.assets);if(!n||!$t(e).has(t))return{page:t,length:Ve(n?.length,o,Fs),beats:[],camera:!1,steps:[],...r?{size:r}:{},...a,clips:i};let l=lt(e),d=[],u=[],p,x=new Map;for(let[M,v]of n.lines.entries()){if(l.get(v.id)!==t||v.camera!==!0&&v.enter===void 0&&v.exit===void 0&&v.emphasis===void 0)continue;let w=U(e.root,v.id);if(!w)continue;let D=Se=>Se===void 0?void 0:x.get(Se),A;v.at!==void 0?A=Ve(v.at,o,0):v.with!==void 0&&D(v.with)?A=D(v.with).start:v.after!==void 0&&D(v.after)?A=D(v.after).end:v.together===!0?A=p?.start??0:A=p?.end??0,A+=Ve(v.delay,o,0);let H;if(v.on!==void 0&&o){let Se=Ki(A,v.on,o);Se!==A&&(H=A),A=Se}v.step===!0&&u.push(A);let E=v.camera===!0?"camera":v.enter!==void 0?"enter":v.exit!==void 0?"exit":"emphasis",T=v.enter??v.exit??v.emphasis,P=Yg(v,T,o),V=E==="camera"||E==="emphasis"?void 0:Jg(v,w),X=V===void 0?1:Math.max(1,xc(w,V)),te=X>1&&V!==void 0?Ve(v.stagger,o,mc[V]):0,I=A+(X-1)*te+P,fe=v.ease??(E==="enter"?"out":E==="exit"?"in":"inout");d.push({index:M,line:v,kind:E,...H===void 0?{}:{asked:H},...T===void 0?{}:{effect:T},start:A,end:I,duration:P,ease:fe,pieces:X,stagger:te,...V===void 0||X===1?{}:{split:V}});let we=I;if(E==="enter"&&v.hold!==void 0&&v.enter!=="count"){let Se=I+Ve(v.hold,o,0);we=Se+P,d.push({index:M,line:v,kind:"exit",...T===void 0?{}:{effect:T},start:Se,end:we,duration:P,ease:"in",pieces:1,stagger:0})}p={start:A,end:we},v.camera!==!0&&x.set(v.id,p)}let y=Math.max(0,...d.map(M=>M.end)),k=Ve(n.length,o,d.length===0?Fs:y+dc);return{page:t,length:k,beats:d,camera:d.some(M=>M.kind==="camera"),steps:u,...r?{size:r}:{},...a,clips:i}}function Xg(e,t,n){let r=n.w,o=n.h;if(r!==void 0&&o!==void 0)return{w:r,h:o};let a=U(e.root,t),i=a&&"w"in a&&typeof a.w=="number"?a.w:void 0,l=a&&"h"in a&&typeof a.h=="number"?a.h:void 0;if(r!==void 0)return{w:r,h:i&&l?Math.round(r*l/i):r};if(o!==void 0)return{w:i&&l?Math.round(o*i/l):o,h:o}}function Yg(e,t,n){return t==="cut"?0:e.duration!==void 0?Ve(e.duration,n,Gr):e.camera===!0?pc:e.emphasis!==void 0?cc:t==="count"?fc:t==="draw"?uc:Gr}function Jg(e,t){if(e.by!==void 0){if(t.type!=="text")return;let n=t.rotation;return n!==void 0&&n!==0?void 0:e.by}if(e.stagger!==void 0&&re(t).length>0)return"children"}function xc(e,t){return t==="children"?re(e).length:e.type!=="text"?1:t==="word"?Us(Jt(e.content)).length:gc(Jt(e.content)).length}function Us(e){return e.split(/\s+/).filter(t=>t!=="")}function gc(e){return[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(e)].map(n=>n.segment).filter(n=>n.trim()!=="")}function ma(e,t){if(t<=0)return 0;if(t>=1)return 1;let n=Wg[e];return n===null?t:Zg(n,t)}function Zg(e,t){let[n,r,o,a]=e,i=(p,x,y)=>3*p*y*(1-y)**2+3*x*y*y*(1-y)+y**3,l=0,d=1,u=t;for(let p=0;p<40;p++){u=(l+d)/2;let x=i(n,o,u);if(Math.abs(x-t)<1e-7)break;x<t?l=u:d=u}return i(r,a,u)}function Vs(e){let t=/-?\d{1,3}(?:,\d{3})+(?:\.\d+)?|-?\d+(?:\.\d+)?/.exec(e);if(!t)return;let n=t[0],r=n.includes(",")?",":"",o=n.replaceAll(",",""),a=o.includes(".")?o.split(".")[1].length:0;return{before:e.slice(0,t.index),value:Number(o),decimals:a,grouping:r,after:e.slice(t.index+n.length)}}function zs(e,t){let n=Math.abs(t).toFixed(e.decimals),[r,o]=n.split("."),a=e.grouping===""?r:r.replace(/\B(?=(\d{3})+(?!\d))/g,e.grouping),i=t<0&&Number(n)!==0?"-":"";return`${e.before}${i}${a}${o===void 0?"":`.${o}`}${e.after}`}var yc=1200,vc=3.5;function bc(e){return Math.max(yc,Math.round(Us(e).length/vc*1e3))}function js(e){let t=[];for(let n of Object.keys(e.motion??{})){let r=e.motion?.[n];if(!kn(r)||!$t(e).has(n))continue;let o=Hs(e,n);t.push(...Qg(e,n,o));for(let i of o.beats)i.start>o.length&&t.push({severity:"warning",code:"motion-after-length",message:`motion ${n}: ${i.line.camera===!0?"camera ":""}${i.line.id} starts at ${Ur(i.start)}, after the video ends at ${Ur(o.length)}`,nodeId:i.line.id});let a=new Map;for(let i of o.beats)if(i.kind==="enter"&&!a.has(i.line.id))a.set(i.line.id,{from:i.start,to:o.length});else if(i.kind==="exit"){let l=a.get(i.line.id);a.set(i.line.id,{from:l?.from??0,to:i.start})}for(let[i,{from:l,to:d}]of a){let u=U(e.root,i);if(u?.type!=="text")continue;let p=Jt(u.content),x=bc(p);d-l<x&&t.push({severity:"warning",code:"video-text-brief",message:`motion ${n}: ${i} is on screen for ${Ur(d-l)}; "${ey(p)}" takes about ${x} ms to read`,nodeId:i})}}return t}function Qg(e,t,n){let r=e.motion?.[t]?.music,o=n.clips[0];if(!r||!o)return[];let a=(y,k)=>({severity:"warning",code:y,message:`motion ${t}: ${k}`,nodeId:t}),i=y=>`${(y/1e3).toFixed(2)} s`,l=e.assets[r.asset];if(!l)return[a("music-missing",`${r.asset} has no file yet, so the video is silent. Add it with vd_add_asset (a URL), or the person drops a track on the canvas`)];if(!l.type.startsWith("audio/"))return[a("music-not-audio",`music ${r.asset} is ${l.type}, not a sound`)];let d=[],u=o.from;l.ms!==void 0&&u>=l.ms?d.push(a("music-from-past-end",`from=${u} is past the end of ${r.asset}, which is ${i(l.ms)} long`)):l.ms!==void 0&&!o.loop&&l.ms-u<n.length-Gi&&d.push(a("music-short",`${r.asset} runs out at ${i(l.ms-u)} and the video at ${i(n.length)}: add loop, or set length=`));let p=l.ms!==void 0&&l.ms>0?l.bytes*8/l.ms:void 0,x=2*(n.length+u)*Wi/1e3;return p!==void 0&&p>Xi?d.push(a("audio-heavy",`${r.asset} is ${Math.round(p)} kbps: re-encode it as a 128 kbps MP3 or M4A, about 1 MB a minute`)):l.bytes>x&&d.push(a("audio-heavy",`${r.asset} is ${(l.bytes/1e6).toFixed(1)} MB for ${i(n.length)} of video: trim it to the part the video uses, as a 128 kbps MP3 or M4A`)),d}function ey(e){return e.length>40?`${e.slice(0,37)}\u2026`:e}function ha(e){return/^\s*(linear|radial|conic|repeating-[a-z]+)-gradient\s*\(/i.test(e)}function io(e){let t=e.trim(),n=/^([a-z-]+)-gradient\s*\(([\s\S]*)\)$/i.exec(t);if(!n)return ha(t)?{error:'A gradient needs its closing ")"'}:{kind:"solid",colour:t};let r=n[1].toLowerCase(),o=ty(n[2]).map(a=>a.trim());if(o.some(a=>a===""))return{error:"A gradient has an empty argument"};if(r==="linear"){let a=ry(o[0]),i=kc(a===void 0?o:o.slice(1));return"error"in i?i:{kind:"linear",angle:a??180,stops:i.stops}}if(r==="radial"){let a=ay(o[0]);if(a&&"error"in a)return a;let i=kc(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:`${r}-gradient is not supported; use linear-gradient or radial-gradient`}}function qs(e){let t=e.map(r=>r.at);t[0]===void 0&&(t[0]=0),t[t.length-1]===void 0&&(t[t.length-1]=1);let n=0;for(let r=0;r<t.length;r+=1){let o=t[r];o!==void 0&&(n=Math.max(n,o),t[r]=n)}for(let r=1;r<t.length;r+=1){if(t[r]!==void 0)continue;let o=r-1,a=r;for(;t[a]===void 0;)a+=1;let i=t[o],l=t[a];for(let d=r;d<a;d+=1)t[d]=i+(l-i)*(d-o)/(a-o);r=a}return e.map((r,o)=>({colour:r.colour,at:t[o]}))}function ty(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o+=1){let a=e[o];a==="("?n+=1:a===")"?n=Math.max(0,n-1):a===","&&n===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}var ny={top:[0,-1],bottom:[0,1],left:[-1,0],right:[1,0]};function ry(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 n=/^to\s+([a-z]+)(?:\s+([a-z]+))?$/i.exec(e);if(!n)return;let r=0,o=0;for(let a of[n[1],n[2]]){if(a===void 0)continue;let i=ny[a.toLowerCase()];if(!i)return;r+=i[0],o+=i[1]}return(Math.atan2(r,-o)*180/Math.PI+360)%360}var oy={left:0,top:0,center:.5,right:1,bottom:1};function ay(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 n=t[1]?.toLowerCase();if(t[2]===void 0)return n?{shape:n}:void 0;let r=wc(t[2]),o=t[3]===void 0?.5:wc(t[3]);return r===void 0||o===void 0?{error:`A radial centre is two percentages or keywords, not "${e}"`}:{...n?{shape:n}:{},cx:r,cy:o}}function wc(e){let t=oy[e.toLowerCase()];if(t!==void 0)return t;let n=/^(-?\d*\.?\d+)%$/.exec(e);return n?Number(n[1])/100:void 0}function kc(e){if(e.length<2)return{error:"A gradient needs at least two colours"};let t=[];for(let n of e){let r=/^([\s\S]*?\S)\s+(-?\d*\.?\d+)%$/.exec(n);if(r&&iy(r[1]))t.push({colour:r[1],at:Number(r[2])/100});else{if(/\s/.test(n.replace(/\([^)]*\)/g,"")))return{error:`"${n}" is not a colour with an optional percentage`};t.push({colour:n})}}return{stops:t}}function iy(e){let t=0;for(let n of e)if(n==="("&&(t+=1),n===")"&&(t-=1),t<0)return!1;return t===0}function xa(e){let t=io(e);return"error"in t?[]:t.kind==="solid"?[t.colour]:t.stops.map(n=>n.colour)}function ar(e){let t=e.trim();if(t===""||t==="none")return{shadows:[]};let n=[];for(let r of sy(t)){let o=ly(r.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:`"${r.trim()}" needs x, y, then optional blur and spread`};if(i.length!==1)return{error:`"${r.trim()}" needs one colour after its numbers`};let[l=0,d=0,u=0,p=0]=a;if(u<0)return{error:"A shadow cannot have a negative blur"};n.push({x:l,y:d,blur:u,spread:p,colour:i[0]})}return{shadows:n}}function sy(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o+=1){let a=e[o];a==="("?n+=1:a===")"?n=Math.max(0,n-1):a===","&&n===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}function ly(e){let t=[],n=0,r="";for(let o of e){if(o==="("&&(n+=1),o===")"&&(n=Math.max(0,n-1)),/\s/.test(o)&&n===0){r!==""&&t.push(r),r="";continue}r+=o}return r!==""&&t.push(r),t}var Ks=["rect","ellipse","vector","image","text"];function rt(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function Ze(e,t,n){if(n===0)return e;let r=n*Math.PI/180,o=Math.cos(r),a=Math.sin(r),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 so(e,t,n=rt(e)){if(t%360===0)return e;let r=[{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=>Ze(d,n,t)),o=r.map(d=>d.x),a=r.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 lo(e){let t=(e%360+360)%360,n=Math.round(t*100)/100;return n===360?0:n}var Gs=["x","y","w","h","left","right","top","bottom","cx","cy"];function fo(e){return Gs.includes(e)}var Ws=["parent","prev","next","self","root"];function Xs(e){return Ws.includes(e)}var ze=class extends Error{position;constructor(t,n){super(t),this.position=n,this.name="ExprSyntaxError"}},Sc=/[A-Za-z_]/,Ys=/[A-Za-z0-9_]/;function Js(e){let t=[],n=0,r=()=>{if(!Sc.test(e[n]??""))throw new ze(`Expected a name at position ${n}`,n);let i=n;for(;n<e.length&&Ys.test(e[n]??"");)n++;return e.slice(i,n)},o=()=>{if(!Ys.test(e[n]??""))throw new ze(`Expected a name at position ${n}`,n);let i=n;for(;n<e.length&&Ys.test(e[n]??"");)n++;return e.slice(i,n)},a=()=>{let i=[r()];for(;e[n]===".";)n++,i.push(o());return i};for(;n<e.length;){let i=e[n]??"";if(/\s/.test(i)){n++;continue}if(/[0-9]/.test(i)){let l=n;for(;n<e.length&&/[0-9]/.test(e[n]??"");)n++;if(e[n]==="."&&/[0-9]/.test(e[n+1]??""))for(n++;n<e.length&&/[0-9]/.test(e[n]??"");)n++;let d=e.slice(l,n),u=Number(d);if(!Number.isFinite(u))throw new ze(`Bad number "${d}"`,l);e[n]==="%"?(n++,t.push({type:"percent",value:u})):t.push({type:"number",value:u});continue}if(i==="$"){n++,t.push({type:"token",name:r()});continue}if(i==="@"){n++,t.push({type:"ref",path:a()});continue}if(Sc.test(i)){t.push({type:"word",path:a()});continue}if("+-*/()".includes(i)){n++,t.push({type:"op",value:i});continue}throw new ze(`Unexpected character "${i}" at position ${n}`,n)}return t.push({type:"eof"}),t}var cy={"+":1,"-":1,"*":2,"/":2};function ht(e){try{let t=Js(e),n=new Zs(t),r=n.parseBinary(0);return n.expectEof(),{ok:!0,ast:r}}catch(t){if(t instanceof ze)return{ok:!1,message:t.message};throw t}}var Zs=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 ze("Unexpected trailing input",this.index)}parseBinary(t){let n=this.parseUnary();for(;;){let r=this.peek();if(r.type!=="op"||!py(r.value))break;let o=cy[r.value];if(o<t)break;this.next();let a=this.parseBinary(o+1);n={kind:"binary",op:r.value,left:n,right:a}}return n}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 ze(`@${t.path.join(".")} needs an edge, for example @${t.path.join(".")}.right`,this.index);return{kind:"nodeRef",path:t.path}}case"word":{let[n,r,...o]=t.path;if(n===void 0||!Xs(n))throw new ze(`Unknown name "${t.path.join(".")}". Use $token for a token or @id.edge for a node.`,this.index);if(r===void 0||!fo(r)||o.length>0)throw new ze(`${n} needs an edge, for example ${n}.w`,this.index);return{kind:"relRef",word:n,edge:r}}case"op":{if(t.value==="("){let n=this.parseBinary(0),r=this.next();if(r.type!=="op"||r.value!==")")throw new ze("Missing closing parenthesis",this.index);return n}throw new ze(`Unexpected "${t.value}"`,this.index)}case"eof":throw new ze("Unexpected end of expression",this.index)}}};function py(e){return e==="+"||e==="-"||e==="*"||e==="/"}var Ec={"+":1,"-":1,"*":2,"/":2},Cc=3,my=4;function hy(e){return e.kind==="binary"?Ec[e.op]??1:e.kind==="unary"?Cc:my}function uo(e){return ga(e,0)}function ga(e,t){let n=xy(e);return hy(e)<t?`(${n})`:n}function xy(e){switch(e.kind){case"number":return J(e.value);case"percent":return`${J(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}${ga(e.operand,Cc)}`;case"binary":{let t=Ec[e.op]??1;return`${ga(e.left,t)} ${e.op} ${ga(e.right,t+1)}`}}}function Qs(e){return e.slice(0,-1).join(".")}function en(e,t){switch(e.kind){case"nodeRef":{let n=e.path[e.path.length-1],r=t(Qs(e.path));return n===void 0||r===void 0?e:{kind:"nodeRef",path:[...r.split("."),n]}}case"unary":return{...e,operand:en(e.operand,t)};case"binary":return{...e,left:en(e.left,t),right:en(e.right,t)};default:return e}}function $n(e){let t=new Set,n=new Set,r=o=>{switch(o.kind){case"nodeRef":t.add(Qs(o.path));return;case"token":n.add(o.name);return;case"unary":r(o.operand);return;case"binary":r(o.left),r(o.right);return;default:return}};return r(e),{nodes:[...t],tokens:[...n]}}function Ke(e,t){return`${e} ${t}`}function el(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 ya(e,t,n,r,o){switch(e){case"x":case"left":return t;case"y":case"top":return n;case"w":return r;case"h":return o;case"right":return t+r;case"bottom":return n+o;case"cx":return t+r/2;case"cy":return n+o/2}}function tl(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 nl(e,t,n){let r=x=>{let y=[];for(let k=n.parentOf.get(x);k!==void 0;k=n.parentOf.get(k))y.push(k);return y},o=r(e),a=r(t),i=new Set(a),l=o.find(x=>i.has(x)),d=x=>l===void 0?x:x.slice(0,x.indexOf(l)),u=new Map([[e,1]]),p=(x,y)=>{let k=(u.get(x)??0)+y;k===0?u.delete(x):u.set(x,k)};for(let x of d(o))p(x,1);for(let x of d(a))p(x,-1);return u}function rl(e){switch(e){case"right":case"bottom":return 1;case"cx":case"cy":return .5;default:return 0}}function va(e){if(e==="x"||e==="w")return"w";if(e==="y"||e==="h")return"h"}function co(e){let t=new Map,n=new Map,r=new Map,o=new Map,a=[];se(e.root,(p,x)=>{t.has(p.id)||t.set(p.id,p),a.push(p),x&&n.set(p.id,x.id),ye(p)&&p.children.forEach((y,k)=>{let M=p.children[k-1],v=p.children[k+1];M&&r.set(y.id,M.id),v&&o.set(y.id,v.id)})});let i=new Map;for(let p of a){let x=n.get(p.id);for(;x!==void 0;){let y=t.get(x);if(!y||!Oe(y))break;x=n.get(x)}x!==void 0&&i.set(p.id,x)}let l=new Map,d=new Map,u=p=>{if(ye(p)){if(!Oe(p)){let x=Mc(p);x.forEach((y,k)=>{let M=x[k-1],v=x[k+1];M&&l.set(y.id,M.id),v&&d.set(y.id,v.id)})}for(let x of p.children)u(x)}};return u(e.root),{rootId:e.root.id,byId:t,parentOf:n,prevOf:r,nextOf:o,layoutParentOf:i,layoutPrevOf:l,layoutNextOf:d,order:a}}function Mc(e){let t=[];for(let n of e.children)ye(n)&&Oe(n)?t.push(...Mc(n)):t.push(n);return t}function ba(e,t,n){if(e.kind==="relRef"){let a=gy(e.word,t,n);return a===void 0?{ok:!1,message:`${t} has no ${e.word}`}:{ok:!0,nodeId:a,edge:e.edge}}let r=e.path[e.path.length-1]??"",o=e.path.slice(0,-1).join(".");return fo(r)?n.byId.has(o)?{ok:!0,nodeId:o,edge:r}:{ok:!1,message:`No node @${o}`}:{ok:!1,message:`"${r}" is not an edge of @${o}`}}function gy(e,t,n){switch(e){case"self":return t;case"root":return n.rootId;case"parent":return n.layoutParentOf.get(t);case"prev":return n.layoutPrevOf.get(t);case"next":return n.layoutNextOf.get(t)}}function Ne(e){let t=[],n=co(e),r=Ac(n),o=new Set;$c(r,t),Tc(r,e,n,o,t);let a=yy(r);vy(r,a,t);let i=by(r,a,e,n,o,t);return{nodes:ky(e.root,i,r,t),problems:t}}function ir(e){let t=co(e),n=Ac(t),r=[];$c(n,r),Tc(n,e,t,new Set,r);let o=new Map;for(let a of n.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 Ac(e){let t=new Map;for(let n of e.order){let r=n;for(let o of yt(n)){let a=r[o];a!==void 0&&t.set(Ke(n.id,o),{nodeId:n.id,prop:o,value:a,deps:[]})}}return t}function $c(e,t){for(let n of e.values()){if(!be(n.value))continue;let r=ht(n.value.expr);if(r.ok){n.ast=r.ast;continue}t.push({severity:"error",code:"expression-syntax",message:r.message,nodeId:n.nodeId,prop:n.prop})}}function Tc(e,t,n,r,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 u=t.tokens[d.name];typeof u!="number"&&o.push({severity:"error",code:u===void 0?"unknown-token":"token-not-a-number",message:u===void 0?`Unknown token $${d.name}`:`Token $${d.name} is not a number`,nodeId:a.nodeId,prop:a.prop});return}case"percent":{let u=va(a.prop);if(!u)return;let p=n.layoutParentOf.get(a.nodeId),x=p===void 0?void 0:Ke(p,u);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 u=ba(d,a.nodeId,n);if(!u.ok){r.add(d),o.push({severity:"error",code:"unknown-reference",message:u.message,nodeId:a.nodeId,prop:a.prop});return}let p=y=>{e.has(y)&&i.add(y)},x=tl(u.edge);if(!x){for(let y of el(u.edge))p(Ke(u.nodeId,y));return}for(let y of nl(u.nodeId,a.nodeId,n).keys())p(Ke(y,x));rl(u.edge)!==0&&p(Ke(u.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 yy(e){let t=new Map,n=new Map;for(let[a,i]of e){t.set(a,i.deps.length);for(let l of i.deps){let d=n.get(l);d?d.push(a):n.set(l,[a])}}let r=[];for(let[a,i]of t)i===0&&r.push(a);let o=[];for(let a=0;a<r.length;a++){let i=r[a];o.push(i);for(let l of n.get(i)??[]){let d=(t.get(l)??0)-1;t.set(l,d),d===0&&r.push(l)}}return o}function vy(e,t,n){if(t.length===e.size)return;let r=new Set(t);for(let[o,a]of e)r.has(o)||n.push({severity:"error",code:"cycle",message:`${a.nodeId}.${a.prop} is part of a dependency cycle`,nodeId:a.nodeId,prop:a.prop})}function by(e,t,n,r,o,a){let i=new Map,l=(d,u)=>i.get(Ke(d,u))??0;for(let d of t){let u=e.get(d);if(u){if(!be(u.value)){i.set(d,u.value);continue}if(!u.ast){i.set(d,0);continue}i.set(d,Lc(u.ast,u,n,r,o,a,l))}}return i}function Lc(e,t,n,r,o,a,i){let l=d=>Lc(d,t,n,r,o,a,i);switch(e.kind){case"number":return e.value;case"token":{let d=n.tokens[e.name];return typeof d=="number"?d:0}case"percent":{let d=va(t.prop);if(!d)return e.value/100;let u=r.layoutParentOf.get(t.nodeId);return u===void 0?0:e.value/100*i(u,d)}case"nodeRef":case"relRef":{if(o.has(e))return 0;let d=ba(e,t.nodeId,r);if(!d.ok)return 0;let u=tl(d.edge);if(!u)return ya(d.edge,i(d.nodeId,"x"),i(d.nodeId,"y"),i(d.nodeId,"w"),i(d.nodeId,"h"));let p=rl(d.edge)*i(d.nodeId,u==="x"?"w":"h");for(let[x,y]of nl(d.nodeId,t.nodeId,r))p+=y*i(x,u);return p}case"unary":{let d=l(e.operand);return e.op==="-"?-d:d}case"binary":{let d=l(e.left),u=l(e.right);if(e.op==="/"&&u===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 p=wy(e.op,d,u);return Number.isFinite(p)?p:(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 wy(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n}}function ky(e,t,n,r){let o=new Map,a=(l,d)=>t.get(Ke(l,d))??0,i=(l,d,u)=>{let p=a(l.id,"x"),x=a(l.id,"y"),y=a(l.id,"w"),k=a(l.id,"h"),M={};for(let D of yt(l)){let A=Ke(l.id,D);n.has(A)&&(M[D]=t.get(A)??0)}(y<0||k<0)&&r.push({severity:"warning",code:"negative-size",message:`${l.id} resolved to a negative size`,nodeId:l.id});let v=d+p,w=u+x;if(o.set(l.id,{id:l.id,type:l.type,x:p,y:x,w:y,h:k,left:p,top:x,right:p+y,bottom:x+k,cx:p+y/2,cy:x+k/2,absX:v,absY:w,values:M}),ye(l))for(let D of l.children)i(D,v,w)};return i(e,0,0),o}function wa(e){if(!be(e))return{kind:"literal",value:e};let t=ht(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 Dc="system-ui, -apple-system, Segoe UI, Roboto, sans-serif",Pc=16,Ic=400,Nc=1.2,ka="#0F172A";function Pt(){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 ol(e,t){if(e===void 0)return Dc;let n=t[e];return n?n.fallback?`${Oc(n.family)}, ${n.fallback}`:Oc(n.family):e}function Oc(e){return/^[A-Za-z][A-Za-z0-9 -]*$/.test(e)?e:JSON.stringify(e)}function al(e,t,n,r){let o={family:ol(t.font,n),size:t.size,weight:t.weight,italic:t.italic,underline:!1,strike:!1,fill:r(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:ol(d.font,n),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:r(d.fill),letterSpacing:d.letterSpacing??o.letterSpacing,...d.link!==void 0&&pt(d.link)?{link:d.link}:{}}})}return i}function _y(e,t){let n=[];for(let r of e)for(let o of r.text.split(/(\n)/))if(o!==""){if(o===`
40
- `){let a=n[n.length-1];a&&!a.hardBreak?n[n.length-1]={...a,hardBreak:!0}:n.push({text:"",style:r.style,w:0,hardBreak:!0});continue}for(let a of o.match(/\S+\s*|\s+/g)??[])n.push({text:a,style:r.style,w:t.advance(a,r.style),hardBreak:!1})}return n}function Sy(e,t,n){let r=[...e.text],o=[],a="";for(let i of r){let l=a+i;if(a!==""&&n.advance(l,e.style)>t){o.push({text:a,style:e.style,w:n.advance(a,e.style),hardBreak:!1}),a=i;continue}a=l}return a!==""&&o.push({text:a,style:e.style,w:n.advance(a,e.style),hardBreak:e.hardBreak}),o.length>0?o:[e]}function Rc(e,t){let{width:n,measure:r}=t,o=_y(r.itemize?e.flatMap(u=>r.itemize?.(u)??[u]):e,r);if(o.length===0){let u=e[0]?.style,p=u?t.lineHeight*u.size:0;return{lines:u?[Ey(u,t.lineHeight)]:[],width:0,height:p}}let a=[],i=[],l=0,d=()=>{a.push(i),i=[],l=0};for(let u of o){let p=i.length===0&&u.w>n&&n>0?Sy(u,n,r):[u];for(let x of p){let y=x.text.trimEnd(),k=y===x.text?x.w:r.advance(y,x.style);i.length>0&&l+k>n&&d(),i.push(x),l+=x.w,x.hardBreak&&d()}}return i.length>0&&a.push(i),Cy(a,t)}function Ey(e,t){let n=t*e.size;return{y:0,h:n,baseline:n*.8,w:0,spans:[],style:e}}function Cy(e,t){let n=[],r=0,o=0;return e.forEach((a,i)=>{let l=a.map(V=>V.style.size),d=Math.max(...l,0),u=t.lineHeight*d,p=a.map(V=>t.measure.metrics(V.style)),x=Math.max(...p.map(V=>V.ascent),0),y=Math.max(...p.map(V=>V.descent),0),k=r+(u-(x+y))/2+x,M=My(a,t.measure),v=M.reduce((V,X)=>V+X.w,0);o=Math.max(o,v);let w=i===e.length-1||(a[a.length-1]?.hardBreak??!1),D=t.align==="justify"&&!w&&M.length>1,A=Math.max(0,t.width-v),H=t.align==="center"?A/2:t.align==="right"?A:0,E=D?A/(M.length-1):0,T=[],P=H;M.forEach((V,X)=>{T.push({text:V.text,style:V.style,x:P,w:V.w}),P+=V.w+(X<M.length-1?E:0)}),n.push({y:r,h:u,baseline:k,w:v,spans:Ay(T,D)}),r+=u}),{lines:n,width:o,height:r}}function My(e,t){let n=[...e];for(;n.length>0;){let r=n[n.length-1],o=r.text.trimEnd();if(o===r.text)break;if(o===""){n.pop();continue}n[n.length-1]={...r,text:o,w:t.advance(o,r.style)};break}return n}function Ay(e,t){if(t)return[...e];let n=[];for(let r of e){let o=n[n.length-1];if(o&&Fc(o.style,r.style)&&Math.abs(o.x+o.w-r.x)<.01){n[n.length-1]={...o,text:o.text+r.text,w:o.w+r.w};continue}n.push(r)}return n}function Fc(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 il(e,t,n,r,o,a){let i={size:t.size??Pc,weight:t.weight??Ic,lineHeight:t.lineHeight??Nc,letterSpacing:t.letterSpacing??0,italic:e.italic??!1,font:typeof e.font=="string"?e.font:void 0,fill:typeof e.fill=="string"?e.fill:ka},l=al(e.content,i,r,o),d=al(" ",i,r,o).map(u=>({...u,text:""}));return Rc(l.length>0?l:d,{width:n,align:e.align??"left",lineHeight:i.lineHeight,measure:a})}function sl(e,t,n){let r=t-n;return e.valign==="middle"?r/2:e.valign==="bottom"?r:0}function ll(e){return e.lines.filter(t=>t.spans.length>0)}function ho(e){switch(e.kind){case"text":{let t=ll(e),n=Math.max(e.w,...t.map(o=>o.w)),r=Math.max(e.y+e.h,...t.map(o=>o.y+o.h));return{x:e.x,y:e.y,w:n,h:r-e.y}}case"vector":{let t=Sn(e.contours)??{x:e.x,y:e.y,w:e.w,h:e.h},n=e.stroke!==void 0?e.strokeWidth*2:0;return{x:t.x-n,y:t.y-n,w:t.w+n*2,h:t.h+n*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 Ea(e,t){let n=e.x,r=e.y,o=e.x+e.w,a=e.y+e.h;for(let i of t){let l=i.spread+i.blur;n=Math.min(n,e.x+i.x-l),r=Math.min(r,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:n,y:r,w:o-n,h:a-r}}var Uc="vd-paint-";var Sa="#CBD5E1",Vc="#FFFFFF";function xo(e,t,n={}){let r=[...t.problems],o=[],a=[],i=n.measure??Pt(),l=qc(e.tokens,r),d=l.paint,u=new Map;se(e.root,(v,w)=>{if("hidden"in v&&v.hidden===!0)return!1;let D=w?u.get(w.id):void 0,A=t.nodes.get(v.id);if(!A){u.set(v.id,D);return}if(v.type==="frame"){v.skip===!0&&w!==e.root&&r.push({severity:"warning",code:"skip-not-a-page",message:`${v.id}: skip only applies to a page, a frame at the top level`,nodeId:v.id,prop:"skip"});let E={x:A.absX,y:A.absY,w:Math.max(0,A.w),h:Math.max(0,A.h)};u.set(v.id,v.clip===!0?v.id:D),v.clip===!0&&a.push({id:v.id,...E,parent:D}),o.push({kind:"frame",id:v.id,...E,background:d(v.background,v.id,"background",E),clip:D,blend:v.blend??"normal",shadows:sr(v.shadow,v.id,e.tokens,r),rotation:0});return}if(u.set(v.id,D),v.type==="text"){o.push(zc(v,A,e,i,r,D,d));return}if(v.type==="image"){o.push({kind:"image",id:v.id,x:A.absX,y:A.absY,w:Math.max(0,A.w),h:Math.max(0,A.h),href:Ry(v,e,n.resolveAsset,r),fit:v.fit??"fill",radius:Math.max(0,A.values.radius??0),opacity:mo(A.values.opacity??1),clip:D,blend:v.blend??"normal",shadows:sr(v.shadow,v.id,e.tokens,r),rotation:A.values.rotation??0});return}if(v.type==="ellipse"){let E=Hc(A);o.push({kind:"ellipse",id:v.id,...E,fill:d(v.fill,v.id,"fill",E)??Sa,stroke:d(v.stroke,v.id,"stroke",E),strokeWidth:A.values.strokeWidth??0,opacity:mo(A.values.opacity??1),clip:D,blend:v.blend??"normal",shadows:sr(v.shadow,v.id,e.tokens,r),rotation:A.values.rotation??0});return}if(v.type==="vector"){o.push(Py(v,A,r,D,d,sr(v.shadow,v.id,e.tokens,r)));return}if(v.type!=="rect")return;let H=Hc(A);o.push({kind:"rect",id:v.id,...H,fill:d(v.fill,v.id,"fill",H)??Sa,stroke:d(v.stroke,v.id,"stroke",H),strokeWidth:A.values.strokeWidth??0,radius:Math.max(0,A.values.radius??0),opacity:mo(A.values.opacity??1),clip:D,blend:v.blend??"normal",shadows:sr(v.shadow,v.id,e.tokens,r),rotation:A.values.rotation??0})});let p=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,p?.w??0),height:Math.max(0,p?.h??0)}:$y(o,a),k={x:y.x,y:y.y,w:y.width,h:y.height},M=d(e.root.background,e.root.id,"background",k);return{...y,background:x?M??Vc:M,items:o,clips:a,gradients:l.gradients,problems:r}}function dl(e,t,n,r,o={}){let a=U(e.root,n.id),i=t.nodes.get(n.id);if(a?.type!=="text"||!i)return;let l=[],d=qc(e.tokens,l);return zc({...a,content:r},i,e,o.measure??Pt(),l,n.clip,d.paint)}function $y(e,t){let n=new Map;for(let l of t){let d=l.parent===void 0?void 0:n.get(l.parent);n.set(l.id,d?Bc(l,d):l)}let r=1/0,o=1/0,a=-1/0,i=-1/0;for(let l of e){let d=l.kind==="text"&&ll(l).length>0?Math.max(l.h,l.height):l.h,u=l.clip===void 0?void 0:n.get(l.clip),p=so(Ea({x:l.x,y:l.y,w:l.w,h:d},l.shadows),l.rotation,rt(l)),x=u?Bc(p,u):p;x.w<=0||x.h<=0||(r=Math.min(r,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(r)?{x:r,y:o,width:a-r,height:i-o}:{x:0,y:0,width:0,height:0}}function Bc(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y);return{x:n,y:r,w:Math.min(e.x+e.w,t.x+t.w)-n,h:Math.min(e.y+e.h,t.y+t.h)-r}}function zc(e,t,n,r,o,a,i){let l=Math.max(0,t.w),d=Math.max(0,t.h),u={x:t.absX,y:t.absY,w:l,h:d},p=il(e,t.values,l,n.fonts,k=>i(k,e.id,"fill",u)??ka,r);!p.lines.every(k=>k.spans.length===0)&&p.height>d+.5&&o.push({severity:"warning",code:"text-overflow",message:`${e.id} needs ${Math.ceil(p.height)}px but its height is ${Math.round(d)}px`,nodeId:e.id,prop:"h"}),Ty(e,n,o);let y=t.absY+sl(e,d,p.height);return{kind:"text",id:e.id,x:t.absX,y:t.absY,w:l,h:d,clip:a,blend:e.blend??"normal",shadows:sr(e.shadow,e.id,n.tokens,o),rotation:t.values.rotation??0,opacity:mo(t.values.opacity??1),height:p.height,lines:p.lines.map(k=>({y:y+k.y,h:k.h,baseline:y+k.baseline,w:k.w,spans:k.spans.map(M=>({text:M.text,x:t.absX+M.x,y:y+k.baseline,w:M.w,style:M.style})),...k.style?{style:k.style}:{}}))}}function Ty(e,t,n){if(typeof e.content!="string")for(let r of e.content){if(typeof r=="string"||r.link===void 0)continue;let o=pt(r.link);if(!o){n.push({severity:"warning",code:"invalid-link",message:`${e.id}: links go to https:, mailto: or #<frame>, not ${JSON.stringify(r.link)}`,nodeId:e.id,prop:"content"});continue}o.kind==="frame"&&!Ly(t,o.id)&&n.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 Ly(e,t){let n=!1;return se(e.root,r=>{if(n)return!1;r.id===t&&r.type==="frame"&&(n=!0)}),n}var po=new Map,Oy=512;function Dy(e){let t=po.get(e);if(t)return t;let n=Yr(e);return po.size>=Oy&&po.delete(po.keys().next().value),po.set(e,n),n}function Py(e,t,n,r,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:u,error:p}=Dy(e.d);p!==void 0&&n.push({severity:"error",code:"bad-path",message:`${e.id}: ${p}`,nodeId:e.id,prop:"d"}),e.view!==void 0&&aa(e.view)===void 0&&n.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=Lt(u,Zr(Jr(e.view,i,l),d));return{kind:"vector",id:e.id,...d,d:Tt(x),contours:x,fill:o(e.fill,e.id,"fill",d)??Sa,stroke:o(e.stroke,e.id,"stroke",d),strokeWidth:t.values.strokeWidth??0,opacity:mo(t.values.opacity??1),rule:e.rule??"nonzero",cap:e.cap??"butt",join:e.join??"miter",clip:r,blend:e.blend??"normal",shadows:a,rotation:t.values.rotation??0}}function jc(e,t,n,r,o){if(e===void 0)return;if(be(e)){o.push({severity:"warning",code:"expression-not-supported",message:`Expressions are not supported for ${r} yet; grammar v0 is numeric only`,nodeId:n,prop:r});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:n,prop:r})}function Hc(e){return{x:e.absX,y:e.absY,w:Math.max(0,e.w),h:Math.max(0,e.h)}}function qc(e,t){let n=[],r=new Map;return{paint:(a,i,l,d)=>{let u=jc(a,e,i,l,t);if(u===void 0)return;if(/url\(/i.test(u)){t.push({severity:"error",code:"invalid-paint",message:`${i}: a paint is a colour or a gradient, not ${JSON.stringify(u)}`,nodeId:i,prop:l});return}let p=io(u);if("error"in p){t.push({severity:"error",code:"invalid-paint",message:`${i}: ${p.error}`,nodeId:i,prop:l});return}if(p.kind==="solid")return u;let x=`${i}\0${l}\0${u}`,y=r.get(x);if(y!==void 0)return`url(#${y})`;let k=[...r.keys()].filter(w=>w.startsWith(`${i}\0${l}\0`)).length,M=`${Uc}${i}-${l}${k===0?"":`-${k+1}`}`;r.set(x,M);let v=qs(p.stops).map(w=>({offset:w.at,colour:Kc(w.colour,e,i,l,t)}));return n.push(Ny(p,M,d,Iy(v))),`url(#${M})`},gradients:n}}function sr(e,t,n,r){let o=jc(e,n,t,"shadow",r);if(o===void 0)return[];let a=ar(o);return"error"in a?(r.push({severity:"error",code:"invalid-shadow",message:`${t}: ${a.error}`,nodeId:t,prop:"shadow"}),[]):a.shadows.map(i=>({...i,colour:Kc(i.colour,n,t,"shadow",r)}))}function Iy(e){return e.map((t,n)=>{if(t.colour.trim().toLowerCase()!=="transparent")return t;let r=[e[n-1],e[n+1]].find(o=>o!==void 0&&o.colour.trim().toLowerCase()!=="transparent");return r===void 0?t:{offset:t.offset,colour:r.colour,opacity:0}})}function Kc(e,t,n,r,o){let a=t[e];return a===void 0?e:typeof a=="string"&&!ha(a)?a:(o.push({severity:"error",code:"invalid-paint",message:`${n}: a gradient stop names $${e}, which is not a colour`,nodeId:n,prop:r}),"transparent")}function Ny(e,t,n,r){if(e.kind==="linear"){let u=e.angle*Math.PI/180,p=Math.sin(u),x=-Math.cos(u),y=(Math.abs(n.w*p)+Math.abs(n.h*x))/2,k=n.x+n.w/2,M=n.y+n.h/2;return{id:t,kind:"linear",x1:_a(k-p*y),y1:_a(M-x*y),x2:_a(k+p*y),y2:_a(M+x*y),stops:r}}let o=n.x+n.w*e.cx,a=n.y+n.h*e.cy,i={x:Math.max(o-n.x,n.x+n.w-o),y:Math.max(a-n.y,n.y+n.h-a)};if(e.shape==="circle"||i.x===0||i.y===0){let u=Math.hypot(i.x,i.y);return{id:t,kind:"radial",cx:o,cy:a,rx:u,ry:u,stops:r}}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:r}}function _a(e){return Math.round(e*1e6)/1e6}function mo(e){return Math.min(Math.max(e,0),1)}function Ry(e,t,n,r){let o=be(e.src)?void 0:e.src,a=o===void 0?void 0:t.assets[o];if(!a){r.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=n?.(a,o);return i===void 0&&r.push({severity:"warning",code:"unresolved-asset",message:`The bytes for asset "${o}" are not available here`,nodeId:e.id,prop:"src"}),i}function Fy(e,t){let n=new Map,r=(o,a)=>{n.set(o,[...n.get(o)??[],a])};for(let o of e.beats){if(o.kind==="camera")continue;let a=o.kind;if(o.split==="children"){let i=U(t.root,o.line.id);(i&&"children"in i?i.children:[]).forEach((d,u)=>{r(d.id,{beat:o,kind:a,start:o.start+u*o.stagger})})}else if(o.split!==void 0)for(let i=0;i<o.pieces;i+=1)r(o.line.id,{beat:o,kind:a,start:o.start+i*o.stagger,piece:i});else r(o.line.id,{beat:o,kind:a,start:o.start})}for(let o of n.values())o.sort((a,i)=>a.start-i.start);return n}function By(e,t){let n=t.nodes.get(e.page);return n?Math.min(n.w,n.h):1e3}function Gc(e,t,n,r,o){let a=e[0]?.kind==="enter",i,l,d;for(let u of e){if(u.start>t)break;let p=u.beat.effect,x=u.beat.duration,y=x<=0?1:Math.min(1,(t-u.start)/x),k=y>=1;if(u.kind==="emphasis"){if(a||k){i=void 0;continue}let A=1+(Bs-1)*Math.sin(Math.PI*ma(u.beat.ease,y));i=Ca(n,A,A,"centre",1);continue}if(k){a=u.kind==="exit",i=void 0,l=void 0,d=void 0;continue}let M=ma(u.beat.ease,y),v=u.kind==="enter"?M:1-M,w=Yc(u.kind==="enter"?M:1-M);a=!1,l=void 0,d=void 0;let D=u.beat.line.from;switch(p){case"cut":i=void 0;break;case"fade":i=Wc(w);break;case"rise":case"drop":{let A=p==="rise"?1:-1;i={sx:1,sy:1,tx:0,ty:u.kind==="enter"?A*r*(1-M):-A*r*M,opacity:w};break}case"pop":{let A=ao+(1-ao)*v;i=Ca(n,A,A,"centre",w);break}case"grow":{let A=typeof D=="string"?D:"bottom",H=Math.max(0,v);i=A==="left"||A==="right"?Ca(n,H,1,A,1):Ca(n,1,H,A,1);break}case"wipe":{let A=typeof D=="string"?D:"left";l=u.kind==="enter"?Jc(n,A,v):Hy(n,A,M),i=void 0;break}case"count":{let A=o.text===void 0?void 0:Vs(o.text);if(!A){i=Wc(w);break}let H=typeof D=="number"?D:0;d=zs(A,H+(A.value-H)*M),i=void 0;break}case"draw":i={sx:1,sy:1,tx:0,ty:0,opacity:1,trace:v,fillOpacity:Yc((v-.75)/.25)};break;case"pulse":case void 0:i=void 0;break}}return{hidden:a,pose:i,...l?{reveal:l}:{},...d===void 0?{}:{text:d}}}function Wc(e){return{sx:1,sy:1,tx:0,ty:0,opacity:e}}function Ca(e,t,n,r,o){let a=r==="left"?e.x:r==="right"?e.x+e.w:e.x+e.w/2,i=r==="top"?e.y:r==="bottom"?e.y+e.h:e.y+e.h/2;return{sx:t,sy:n,tx:a*(1-t),ty:i*(1-n),opacity:o}}function Jc(e,t,n){let r=e.w*n,o=e.h*n;switch(t){case"left":return{x:e.x,y:e.y,w:r,h:e.h};case"right":return{x:e.x+e.w-r,y:e.y,w:r,h:e.h};case"top":return{x:e.x,y:e.y,w:e.w,h:o};case"bottom":return{x:e.x,y:e.y+e.h-o,w:e.w,h:o}}}function Hy(e,t,n){return Jc(e,{left:"right",right:"left",top:"bottom",bottom:"top"}[t],1-n)}function Xc(e,t){let n=t.trace??e.trace,r=t.fillOpacity??e.fillOpacity;return{sx:e.sx*t.sx,sy:e.sy*t.sy,tx:e.sx*t.tx+e.tx,ty:e.sy*t.ty+e.ty,opacity:e.opacity*t.opacity,...n===void 0?{}:{trace:n},...r===void 0?{}:{fillOpacity:r}}}function Yc(e){return e<0?0:e>1?1:e}function Uy(e,t){let n=new Map;se(t.root,(o,a)=>{a&&n.set(o.id,a.id)});let r=new Map;for(let o of e.items){let a=o.kind==="frame"?{x:o.x,y:o.y,w:o.w,h:o.h}:ho(o);for(let i=o.id;i!==void 0;i=n.get(i)){let l=r.get(i);if(r.set(i,l?Vy(l,a):a),i===t.root.id)break}}return{parents:n,boxes:r}}function Vy(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{x:n,y:r,w:Math.max(e.x+e.w,t.x+t.w)-n,h:Math.max(e.y+e.h,t.y+t.h)-r}}function fl(e,t,n,r){let o=Fy(t,r.doc);if(o.size===0)return e;let{parents:a,boxes:i}=Uy(e,r.doc),l=oo*By(t,r.resolution),d=r.options?.measure??Pt(),u=new Map,p=new Map;for(let[k,M]of o){let v=i.get(k)??{x:0,y:0,w:0,h:0},w=U(r.doc.root,k),D=w?.type==="text"?Jt(w.content):void 0,A=M.filter(E=>E.piece===void 0),H=M.find(E=>E.piece!==void 0);if(A.length>0&&u.set(k,Gc(A,n,v,l,{...D===void 0?{}:{text:D}})),H&&(H.beat.split==="word"||H.beat.split==="letter")){let E=[];for(let T=0;T<H.beat.pieces;T+=1){let P=M.filter(V=>V.piece===T);E.push(Gc(P,n,v,l,{}))}E.some(T=>T.hidden||T.pose!==void 0)&&p.set(k,{split:H.beat.split,moments:E})}}let x=[...e.clips],y=[];for(let k of e.items){let M=[],v;for(let E=k.id;E!==void 0;E=a.get(E)){let T=u.get(E);T&&(M.unshift(T),T.reveal&&!v&&(v={id:E,box:T.reveal}))}if(M.some(E=>E.hidden))continue;let w;for(let E of M)E.pose&&(w=w?Xc(w,E.pose):E.pose);let D=k,A=u.get(k.id)?.text;if(A!==void 0&&k.kind==="text"&&(D=dl(r.doc,r.resolution,k,A,r.options)??k),v){let E=`${v.id}~wipe${k.clip===void 0?"":`~${k.clip}`}`;x.some(T=>T.id===E)||x.push({id:E,...v.box,parent:k.clip}),D={...D,clip:E}}let H=p.get(k.id);if(H&&D.kind==="text"){Zc(D,H.split,d).forEach((E,T)=>{let P=H.moments[T];if(!P||P.hidden)return;let V=P.pose&&w?Xc(w,P.pose):P.pose??w;y.push({...E,part:T,...V?{pose:V}:{}})});continue}y.push(w&&!zy(w)?{...D,pose:w}:D)}return{...e,items:y,clips:x}}function zy(e){return e.sx===1&&e.sy===1&&e.tx===0&&e.ty===0&&e.opacity===1&&e.trace===void 0&&e.fillOpacity===void 0}function Zc(e,t,n=Pt()){let r=[],o=new Intl.Segmenter(void 0,{granularity:"grapheme"}),a=!1;for(let i of e.lines){a=!1;for(let l of i.spans){let d=0,u=t==="word"?l.text.split(/(\s+)/).filter(p=>p!==""):[...o.segment(l.text)].map(p=>p.segment);for(let p of u){if(p.trim()==="")a=!1;else{(t==="letter"||!a)&&r.push([]);let y=l.x+n.advance(l.text.slice(0,d),l.style);r.at(-1).push({...l,text:p,x:y,w:n.advance(p,l.style)}),a=!0}d+=p.length}}}return r.map(i=>({...e,lines:e.lines.map(l=>({...l,spans:i.filter(d=>d.y===l.baseline)})).filter(l=>l.spans.length>0)}))}var Qc="vd-clip-";function ul(e){return qy(e,"")}function qy(e,t){let n=e.parent===void 0?"":` clip-path="url(#${lr(t+Qc+e.parent)})"`;return`<clipPath id="${lr(t+Qc+e.id)}"${n}><rect x="${J(e.x)}" y="${J(e.y)}" width="${J(e.w)}" height="${J(e.h)}"/></clipPath>`}function cl(e){return Ky(e,"")}function Ky(e,t){let n=e.stops.map(o=>`<stop offset="${J(o.offset)}" stop-color="${lr(o.colour)}"${o.opacity===void 0?"":` stop-opacity="${J(o.opacity)}"`}/>`).join(""),r=lr(t+e.id);return e.kind==="linear"?`<linearGradient id="${r}" gradientUnits="userSpaceOnUse" x1="${J(e.x1)}" y1="${J(e.y1)}" x2="${J(e.x2)}" y2="${J(e.y2)}">${n}</linearGradient>`:`<radialGradient id="${r}" gradientUnits="userSpaceOnUse" cx="0" cy="0" r="1" gradientTransform="matrix(${J(e.rx)} 0 0 ${J(e.ry)} ${J(e.cx)} ${J(e.cy)})">${n}</radialGradient>`}var Ma="vd-shadow-";function pl(e,t=!1){return Gy(e,t,"")}function Gy(e,t,n){let r=Ea(ho(e),e.shadows),o=2,a=[];e.shadows.forEach((l,d)=>{let u=`s${d}`,p="SourceAlpha";l.spread!==0&&(a.push(`<feMorphology in="${p}" operator="${l.spread>0?"dilate":"erode"}" radius="${J(Math.abs(l.spread))}" result="${u}m"/>`),p=`${u}m`),l.blur>0&&(a.push(`<feGaussianBlur in="${p}" stdDeviation="${J(l.blur/2)}" result="${u}b"/>`),p=`${u}b`),a.push(`<feOffset in="${p}" dx="${J(l.x)}" dy="${J(l.y)}" result="${u}o"/>`,`<feFlood flood-color="${lr(l.colour)}" result="${u}c"/>`,`<feComposite in="${u}c" in2="${u}o" operator="in" result="${u}"/>`)});let i=e.shadows.map((l,d)=>`<feMergeNode in="s${e.shadows.length-1-d}"/>`).join("");return`<filter id="${lr(n+Ma+e.id)}" filterUnits="userSpaceOnUse" x="${J(r.x-o)}" y="${J(r.y-o)}" width="${J(r.w+o*2)}" height="${J(r.h+o*2)}" color-interpolation-filters="sRGB">`+a.join("")+`<feMerge>${i}${t?"":'<feMergeNode in="SourceGraphic"/>'}</feMerge></filter>`}function Aa(e){return`rotate(${J(e.rotation)} ${J(e.x+e.w/2)} ${J(e.y+e.h/2)})`}function ml(e){return e.rotation!==0&&e.clip!==void 0}function hl(e){return`matrix(${J(e.sx)} 0 0 ${J(e.sy)} ${J(e.tx)} ${J(e.ty)})`}function lr(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var Jy=.8,Zy=.2;function xl(e,t){let r=e.createElement("canvas").getContext("2d"),o=Pt(),a=new Map,i=new Map,l=new Set;function d(p){return`${p.italic?"italic ":""}${p.weight} ${p.size}px ${p.family}`}function u(){a.clear(),i.clear()}return{advance(p,x){if(!r)return o.advance(p,x);let y=d(x),k=`${y}\0${x.letterSpacing}\0${p}`,M=a.get(k);if(M!==void 0)return M;r.font=y;let v=r.measureText(p).width+x.letterSpacing*[...p].length;return a.set(k,v),v},metrics(p){if(!r)return o.metrics(p);let x=d(p),y=i.get(x);if(y)return y;r.font=x;let k=r.measureText("Hxg"),M=k.fontBoundingBoxAscent??p.size*Jy,v=k.fontBoundingBoxDescent??p.size*Zy,w={ascent:M,descent:v,lineGap:0};return i.set(x,w),w},load(p,x){let y=e.fonts;if(!y||typeof FontFace!="function")return!1;let k=!1;for(let M of Object.values(p.fonts))for(let v of Qy(M)){let w=`${M.family}\0${v.src}\0${v.weight??400}\0${v.style??"normal"}`;if(l.has(w))continue;l.add(w);let D=v.src.startsWith("data:")?void 0:x?.(v.src),A={weight:String(v.weight??400),style:v.style??"normal"},H=E=>{let T=new FontFace(M.family,typeof E=="string"?`url(${E})`:ev(E),A);y.add(T),T.load().then(()=>{u(),t?.()},()=>{y.delete(T)})};D===void 0?H(v.src):(k=!0,D.then(H,()=>{}))}return k},invalidate:u,destroy(){u(),l.clear()}}}function Qy(e){return e.faces??[]}function ev(e){return e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}var $a={x:0,y:0,zoom:1},tp=.02,np=64;function dr(e){return Number.isFinite(e)?Math.min(Math.max(e,tp),np):1}function Ta(e,t){return{x:(t.x-e.x)/e.zoom,y:(t.y-e.y)/e.zoom}}function gl(e,t){return{x:t.x*e.zoom+e.x,y:t.y*e.zoom+e.y}}function go(e,t,n){let r=dr(e.zoom*n),o=Ta(e,t);return{zoom:r,x:t.x-o.x*r,y:t.y-o.y*r}}function St(e,t,n){return{...e,x:e.x+t,y:e.y+n}}function yl(e){return`translate(${e.x} ${e.y}) scale(${e.zoom})`}function tn(e,t,n){let r={width:Math.max(1,t.width-n*2),height:Math.max(1,t.height-n*2)};if(e.width<=0||e.height<=0)return $a;let o=dr(Math.min(r.width/e.width,r.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 pe="http://www.w3.org/2000/svg",rp="vd-viewer-styles",op=`
35
+ `}async function Vi(e){let t=await crypto.subtle.digest("SHA-256",e),n=[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0"));return`${Cc}${n.join("")}`}function zi(e,t){return`data:${e};base64,${t}`}function ji(e){let t=e.toBase64;if(typeof t=="function")return t.call(e);let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function Ki(e){let t=Uint8Array.fromBase64;if(typeof t=="function")return t(e);let n=atob(e),r=new Uint8Array(n.length);for(let o=0;o<n.length;o+=1)r[o]=n.charCodeAt(o);return r}function qg(e){if(e.startsWith(Dn))return 0;let t=e.indexOf(`
36
+ ${Dn}`);return t===-1?-1:t+1}function Gg(e){let t=new Set;for(let n of e.matchAll(/sha256-[0-9a-f]{64}/g))t.add(n[0]);return t}function qi(e){return(t,n,r,o)=>{e.push({severity:"error",code:n,message:`Line ${t}: ${r}`,...o===void 0?{}:{nodeId:o}})}}function Gi(e){let t=[],n=e.split(`
37
+ `);for(let r=0;r<n.length;r+=1){let o=n[r],a=o.trim();if(a===Dn)break;if(a===""||a.startsWith("```"))continue;let s=o.length-o.trimStart().length;t.push({number:r+1,indent:Math.floor(s/2),text:a,words:xc(a)})}return t}function Wi(e){let t=[],n=[],r=o=>{for(;t.length>0&&t[t.length-1].indent>=o;)Xg(t.pop())};return{push(o){let a=o.words[0];if(a.startsWith('"')){let f=t[t.length-1];if(!f||f.type!=="text")return e(o.number,"invalid-content","A quoted line must sit inside a text node"),!0;let c=Jg(o,e);return c!==void 0&&f.runs.push(c),!0}if(!ka(a))return!1;r(o.indent);let s=o.words[1];if(s===void 0||s.includes("="))return e(o.number,"missing-id",`A ${a} needs an id`),!0;let d=Wg(a,s,o.words.slice(2),o,e),l=t[t.length-1];return l?l.children.push(d.record):n.push(d.record),t.push(d),!0},finish(){return r(0),n}}}function Wg(e,t,n,r,o){let a={type:e,id:t},s=[];for(let d=0;d<n.length;d+=1){let{key:l,value:f}=Ke(n[d]),c=Ti(e,l);if(c===void 0){let g=Oi(n,d,n[d-1]);g?(o(r.number,"invalid-value",g.message,t),d=g.end-1):o(r.number,"invalid-value",`${e} has no property "${l}"`,t);continue}let m=tt(f??"",c);"error"in m?o(r.number,"invalid-value",`${l}: ${m.error}`,t):a[l]=m.value}return na(e)&&(a.children=s),e==="text"&&(a.content=""),{indent:r.indent,type:e,record:a,children:s,runs:[]}}function Xg(e){e.type==="text"&&(e.record.content=Yg(e.runs))}function Yg(e){if(e.length===0)return"";let t=e[0];return e.length===1&&typeof t=="string"?t:[...e]}function Jg(e,t){let n=At(e.words[0]);if(n===void 0){t(e.number,"invalid-run","Malformed quoted string");return}if(e.words.length===1)return n;let r={text:n};for(let o of e.words.slice(1)){let{key:a,value:s}=Ke(o),d=io.find(([f])=>f===a);if(!d){t(e.number,"invalid-run",`A run has no mark "${a}"`);continue}let l=tt(s??"",d[1]);"error"in l?t(e.number,"invalid-run",`${a}: ${l.error}`):r[a]=l.value}return r}function fo(e){let t=[],n=qi(t),r=Qt,o,a=!1,s={},d={},l={},f=Wi(n),c=Li(n,t),m,g={},b=!1,E=!1,v={},w=new Map,L,$=!1,z=()=>{if(!L)return;let R=L;L=void 0;let q=w.get(R.page);if(q!==void 0){n(R.number,"invalid-motion",`motion ${R.page} is written twice \u2014 put its lines in the block on line ${q}`,R.page);return}w.set(R.page,R.number);for(let[oe,se]of R.where)w.set(`${R.page} ${oe}`,se);let ee=Ii(R);ee&&(v[R.page]=ee)};for(let R of Gi(e)){let q=R.words[0];if(L&&R.indent>0){Ni(L,R,n);continue}if(!($&&R.indent>0)){if($=!1,z(),q==="motion"&&R.indent===0){m=void 0,L=Pi(R,n),$=L===void 0;continue}if(c.take(R)){m=void 0;continue}if(q==="version"){a=!0,ey(R,t);continue}if(q==="kind"&&R.indent===0){r=ty(R,t);continue}if(q==="title"&&R.indent===0){o=Tc(R,n);continue}if(q==="theme"&&R.indent===0){m=void 0,b=!0,E&&n(R.number,"invalid-theme","theme dark is written twice \u2014 keep one block"),E=!0,(R.words[1]!=="dark"||R.words.length>2)&&n(R.number,"invalid-theme","Expected theme dark on its own line, with the tokens that differ indented under it");continue}if(q.startsWith("$")){if(m=void 0,b&&R.indent>0){Xi(R,g,n);continue}b=!1,Xi(R,s,n);continue}if(R.indent===0)b=!1;else if(b){n(R.number,"invalid-theme","A theme block holds only $name = value lines");continue}if(q==="asset"&&R.indent===0){m=void 0,ny(R,l,n);continue}if(q==="font"&&R.indent===0){m=oy(R,d,n);continue}if((q==="fallback"||q==="face")&&m){sy(q,R,m,n);continue}m=void 0,!f.push(R)&&n(R.number,"unknown-node-type",`Unknown statement "${q}"`)}}z();let A=Qg(c.finish(),r,t),N=_t({dark:g}),I={...A===void 0?{}:{brand:A},...N===void 0?{}:{themes:N}},j=Zg(f.finish(),t),O=Object.keys(v).length===0?{}:{motion:v},V=(R,q)=>w.get(q===void 0?R:`${R} ${q}`);if(!j){a||t.push({severity:"error",code:"invalid-document",message:"No nodes found"});let R=Xn({id:kt,children:[]}),q=qr({kind:r,...o===void 0?{}:{title:o},tokens:s,fonts:d,assets:l,...O,...I,root:R});return t.push(...tr(q,V)),{document:q,problems:t}}let C={version:et({kind:r,fonts:d,...I}),kind:r,...o===void 0?{}:{title:o},tokens:s,fonts:d,assets:l,...O,...I,root:j};return t.push(...tr(C,V)),{document:C,problems:t}}function Zg(e,t){let n=e[0];if(n!==void 0){if(e.length===1&&n.type==="canvas")return n;for(let r of e){if(r.type!=="canvas")continue;let o=r.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:kt,children:[...e]}}}function Qg(e,t,n){let r=e.brand;if(!r)return;e.header||n.push({severity:"error",code:"invalid-brand",message:"A brand needs its brand line first, e.g. brand ember@1"});let o=Object.entries(r.guides).filter(([s,d])=>s!=="voice"||d.entries.some(l=>l.kind!=="banned")),a=Object.keys(r.roles).length+Object.keys(r.logos).length+o.length+r.review.length;return t!=="brand"&&a>0&&n.push({severity:"warning",code:"brand-only",message:"Roles, logos, guides and review define a brand, and are read in a kind brand document"}),r}function ey(e,t){Kr.includes(Number(e.words[1]))||t.push({severity:"warning",code:"version-mismatch",message:`Line ${e.number}: expected version ${Wn} or older, got ${e.words[1]??"nothing"}`})}function ty(e,t){let n=e.words[1];return n!==void 0&&Sn.includes(n)?n:(t.push({severity:"error",code:"unknown-kind",message:`Line ${e.number}: unknown kind "${n??"nothing"}" \u2014 this build reads ${Sn.join(", ")}`}),Qt)}function Tc(e,t){let n=e.words.slice(1).join(" ").trim();if(n===""){t(e.number,"invalid-value",'title needs a name, e.g. title "Pitch deck"');return}let r=n.startsWith('"')?At(n):n;if(r===void 0){t(e.number,"invalid-value",`Could not read the title ${n}`);return}return r.trim()===""?void 0:r}function Xi(e,t,n){let{name:r,value:o}=Yi(e.words);if(r===void 0||o===void 0){n(e.number,"invalid-token","Expected $name = value");return}if(!o.startsWith('"')&&/\s/.test(o)){n(e.number,"invalid-token",`$${r}: expected one value, got "${o}". Quote it if the value has spaces; there are no comments.`);return}let a=tt(o,"stringValue");if("error"in a){n(e.number,"invalid-token",`$${r}: ${a.error}`);return}if(typeof a.value!="string"){n(e.number,"invalid-token",`$${r} may not be an expression`);return}t[r]=Oc(a.value,o)}function Oc(e,t){let n=Number(e);return t.startsWith('"')||!Number.isFinite(n)||e.trim()===""?e:n}function Yi(e){let t=e[0],n=a=>a.startsWith("$")?a.slice(1):a;if(e[1]==="=")return{name:n(t),value:e.slice(2).join(" ")||void 0};let{key:r,value:o}=Ke(t);return o!==void 0?{name:n(r),value:o}:{name:n(t)}}function ny(e,t,n){let r=e.words.slice(1),o=r[0],a=r[1]==="=",s=o===void 0?void 0:Ke(o),d=s?.key,l=a?r[2]:s?.value,f=r.slice(a?3:1);if(d===void 0||d===""||l===void 0){n(e.number,"invalid-asset","Expected asset <name> = <type> hash=\u2026 bytes=\u2026");return}let c={};for(let E of f){let{key:v,value:w}=Ke(E);if(w===void 0){n(e.number,"invalid-asset",`Asset "${d}" has a stray word "${E}"`);continue}c[v]=ry(w)}let m=c.hash,g=Number(c.bytes);if(m===void 0||!Number.isFinite(g)){n(e.number,"invalid-asset",`Asset "${d}" needs a hash and a bytes count`);return}let b=c.ms===void 0?void 0:Number(c.ms);if(b!==void 0&&!(Number.isFinite(b)&&b>=0)){n(e.number,"invalid-asset",`Asset "${d}": ms is the track's length, in milliseconds`);return}t[d]={type:l,hash:m,bytes:g,...b===void 0?{}:{ms:b},...c.credit===void 0?{}:{credit:c.credit},...c.source===void 0?{}:{source:c.source},...c.license===void 0?{}:{license:c.license}}}function ry(e){return e.startsWith('"')?At(e)??e:e}function oy(e,t,n){let{name:r,value:o}=Yi(e.words.slice(1));if(r===void 0||o===void 0){n(e.number,"invalid-font","Expected font <name> = <family>");return}let a=tt(o,"string"),s={family:"error"in a?o:a.value};return t[r]=s,{family:s,faces:[]}}var ay=/^[A-Za-z_][\w-]*$/;function sy(e,t,n,r){if(e==="fallback"){let d=tt(t.words.slice(1).join(" "),"string");"error"in d?r(t.number,"invalid-font",`fallback: ${d.error}`):n.family.fallback=d.value;return}let o=t.words[1];if(o===void 0){r(t.number,"invalid-font-face","A face needs a src, or asset=");return}let a=o.startsWith("asset=")?o.slice(6):void 0,s={};if(a!==void 0){if(!ay.test(a)){r(t.number,"invalid-font-face",`asset=${a}: not an asset name`);return}s.asset=a}else{let d=tt(o,"string");s.src="error"in d?o:d.value}for(let d of t.words.slice(2)){let{key:l,value:f}=Ke(d);if(l!=="weight"&&l!=="style"){r(t.number,"invalid-font-face",`A face has no property "${l}"`);continue}let c=tt(f??"",l==="weight"?"number":"fontStyle");"error"in c?r(t.number,"invalid-font-face",`${l}: ${c.error}`):s[l]=c.value}n.faces.push(s),n.family.faces=n.faces}var Dc="https://getv.design/ns/vd",mk=`<metadata><vd:document xmlns:vd="${Dc}" version="1"><![CDATA[
38
+ `;var iy=/<vd:document\b[^>]*>([\s\S]*?)<\/vd:document\s*>/;function Ji(e){let t=iy.exec(e);if(!t)return;let n=t[1]??"",r="",o=n;for(;;){let a=o.indexOf("<![CDATA[");if(a===-1){r+=Lc(o);break}r+=Lc(o.slice(0,a));let s=o.indexOf("]]>",a);if(s===-1){r+=o.slice(a+9);break}r+=o.slice(a+9,s),o=o.slice(s+3)}return`${r.replace(/^\n/,"").replace(/\n$/,"")}
39
+ `}function Zi(e){return/^\uFEFF?\s*</.test(e)}function Lc(e){return e.replace(/&(lt|gt|quot|apos|amp|#\d+|#x[0-9a-fA-F]+);/g,(t,n)=>{switch(n){case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";case"amp":return"&";default:{let r=n.startsWith("#x")?parseInt(n.slice(2),16):parseInt(n.slice(1),10);return Number.isFinite(r)&&r<=1114111?String.fromCodePoint(r):t}}})}function ed(e){let t=[],n=qe(e);if(!n)return t.push({severity:"error",code:"invalid-document",message:"Expected an object"}),{document:qr(),problems:t};Kr.includes(n.version)||t.push({severity:"warning",code:"version-mismatch",message:`Expected version ${Wn} or older, got ${JSON.stringify(n.version)}`});let r=Ic(n.root,t),o=dy(n.motion,t),a=py(n.kind,t),s=n.brand===void 0?void 0:ri(n.brand,g=>{t.push({severity:"error",code:"invalid-brand",message:g})}),d=qe(qe(n.themes)?.dark),l=d===void 0?void 0:_t({dark:Pc(d,t)}),f={...s===void 0?{}:{brand:s},...l===void 0?{}:{themes:l}},c=hy(n.fonts,t),m={version:et({kind:a,fonts:c,...f}),kind:a,...typeof n.title=="string"&&n.title.trim()!==""?{title:n.title}:{},tokens:Pc(n.tokens,t),fonts:c,assets:my(n.assets,t),...o===void 0?{}:{motion:o},...f,root:r??Xn({id:kt,children:[]})};return My(m.root,t),t.push(...tr(m)),{document:m,problems:t}}function dy(e,t){if(e===void 0)return;let n=qe(e),r=a=>{t.push({severity:"error",code:"invalid-motion",message:a})};if(!n){r("`motion` must be an object");return}let o={};for(let[a,s]of Object.entries(n)){let d=qe(s);if(!d||!Array.isArray(d.lines)){r(`motion ${a} must be an object with a lines array`);continue}let l=d.enter,f=d.duration;if(l!==void 0&&!Zn.includes(l)){r(`motion ${a}: enter must be one of ${Zn.join(", ")}`);continue}if(f!==void 0&&!cy(f)){r(`motion ${a}: duration must be 0 to ${St} milliseconds`);continue}let c=d.scroll;if(c!==void 0&&typeof c!="boolean"){r(`motion ${a}: scroll must be true or false`);continue}let m=d.bpm,g=d.meter;if(m!==void 0&&!(typeof m=="number"&&m>=20&&m<=300)){r(`motion ${a}: bpm must be ${20} to ${300}`);continue}if(g!==void 0&&!(typeof g=="number"&&Number.isInteger(g)&&g>=1&&g<=16)){r(`motion ${a}: meter must be a whole number from 1 to ${16}`);continue}let b=gt({...m===void 0?{}:{bpm:m},...g===void 0?{}:{meter:g},lines:[]}),E=fy(d.music,b);if(E===null){r(`motion ${a}: music must be { asset, from?, volume?, fadein?, fadeout?, loop? }`);continue}let v=d.length;if(v!==void 0&&!td(v,nn,b)){r(`motion ${a}: length must be 0 to ${nn} milliseconds, or beats with a bpm`);continue}let w=z=>z===void 0||typeof z=="number"&&z>=16&&z<=Et;if(!w(d.w)||!w(d.h)){r(`motion ${a}: w and h must be 16 to ${Et} pixels`);continue}let L=d.lines.flatMap(z=>{let A=ly(z,b);return A===void 0&&r(`motion ${a}: a line that is not one: ${JSON.stringify(z)}`),A===void 0?[]:[A]}),$={...l===void 0?{}:{enter:l},...f===void 0?{}:{duration:f},...c===!0?{scroll:!0}:{},...v===void 0?{}:{length:v},...d.w===void 0?{}:{w:d.w},...d.h===void 0?{}:{h:d.h},...m===void 0?{}:{bpm:m},...g===void 0?{}:{meter:g},...E===void 0?{}:{music:E},lines:L};Dt($)||(o[a]=$)}return Object.keys(o).length===0?void 0:o}function ly(e,t){let n=qe(e);if(!n||typeof n.id!="string")return;let r={id:n.id};if(n.camera!==void 0){if(n.camera!==!0)return;r.camera=!0}for(let[m,g]of Ln){let b=n[m];if(b!==void 0){if(!uy(m,g,b,t))return;r[m]=b}}if(r.on!==void 0&&(!t||r.with!==void 0||r.together))return;let{enter:o,exit:a,emphasis:s,step:d,together:l}=r;if(o!==void 0&&a!==void 0||s!==void 0&&(o!==void 0||a!==void 0)||d===!0&&l===!0||["at","after","with","together","step"].filter(m=>r[m]!==void 0).length>1||r.camera===!0&&(o??a??s??r.go)!==void 0)return;let c=r;return Qn(c)?c:void 0}function uy(e,t,n,r){switch(t){case"time":return td(n,e==="at"?nn:St,r);case"on":return Gr.includes(n);case"boolean":return n===!0;case"number":return typeof n!="number"||!Number.isFinite(n)||n<0?!1:e==="at"?n<=nn:e==="pad"?n<=Et:n<=St;case"string":return typeof n=="string"&&(e!=="go"||Lt(n)!==void 0);case"nodeEffect":return Yr.includes(n);case"emphasisEffect":return Jr.includes(n);case"ease":return Zr.includes(n);case"piece":return Qr.includes(n);case"from":return typeof n=="number"&&Number.isFinite(n)||tn.includes(n);default:return!1}}function fy(e,t){if(e===void 0)return;let n=qe(e);if(!n||typeof n.asset!="string"||n.asset==="")return null;let r={asset:n.asset};for(let s of Object.keys(n))if(s!=="asset"&&!Xr.includes(s))return null;let o=n.from;if(o!==void 0&&!(typeof o=="number"&&o>=0&&o<=Yn))return null;let a=n.volume;if(a!==void 0&&!(typeof a=="number"&&a>=0&&a<=1))return null;for(let s of["fadein","fadeout"])if(n[s]!==void 0&&!td(n[s],St,t))return null;if(n.loop!==void 0&&n.loop!==!0)return null;for(let s of Xr)n[s]!==void 0&&(r[s]=n[s]);return r}function td(e,t,n){if(typeof e=="number")return Number.isFinite(e)&&e>=0&&e<=t;if(!Mn(e)||!n)return!1;let r=En(e);if(!r||Cn(r.count,r.unit)!==e)return!1;let o=ze(e,n);return o!==void 0&&o<=t}function cy(e){return typeof e=="number"&&e>=0&&e<=St}function py(e,t){return e==null?Qt:typeof e=="string"&&Sn.includes(e)?e:(t.push({severity:"error",code:"unknown-kind",message:`Unknown kind ${JSON.stringify(e)} \u2014 this build reads ${Sn.join(", ")}`}),Qt)}function Pc(e,t){let n={};if(e===void 0)return n;let r=qe(e);if(!r)return t.push({severity:"error",code:"invalid-tokens",message:"`tokens` must be an object"}),n;for(let[o,a]of Object.entries(r))typeof a=="number"||typeof a=="string"?n[o]=a:t.push({severity:"error",code:"invalid-token",message:`Token $${o} must be a number or string`});return n}function my(e,t){let n={};if(e===void 0)return n;let r=qe(e);if(!r)return t.push({severity:"error",code:"invalid-assets",message:"`assets` must be an object"}),n;for(let[o,a]of Object.entries(r)){let s=qe(a);if(!s||typeof s.type!="string"||typeof s.hash!="string"||typeof s.bytes!="number"){t.push({severity:"error",code:"invalid-asset",message:`Asset "${o}" must have a "type", a "hash" and a "bytes" count`});continue}n[o]={type:s.type,hash:s.hash,bytes:s.bytes,...typeof s.ms=="number"&&s.ms>=0?{ms:s.ms}:{},...ct(s.credit,"credit"),...ct(s.source,"source"),...ct(s.license,"license")}}return n}function hy(e,t){let n={};if(e===void 0)return n;let r=qe(e);if(!r)return t.push({severity:"error",code:"invalid-fonts",message:"`fonts` must be an object"}),n;for(let[o,a]of Object.entries(r)){let s=qe(a);if(!s||typeof s.family!="string"){t.push({severity:"error",code:"invalid-font",message:`Font "${o}" must be an object with a "family"`});continue}n[o]={family:s.family,...typeof s.fallback=="string"?{fallback:s.fallback}:{},...xy(s.faces,o,t)}}return n}function xy(e,t,n){if(e===void 0)return{};if(!Array.isArray(e))return n.push({severity:"error",code:"invalid-font",message:`Font "${t}" has a "faces" that is not an array`}),{};let r=[];for(let o of e){let a=qe(o),s=a?.src,d=a?.asset;if(!a||typeof s=="string"==(typeof d=="string")){n.push({severity:"error",code:"invalid-font-face",message:`A face of font "${t}" needs a "src" or an "asset", and not both`});continue}let l=a.style;r.push({...typeof s=="string"?{src:s}:{asset:d},...typeof a.weight=="number"?{weight:a.weight}:{},...l==="italic"||l==="normal"?{style:l}:{}})}return r.length>0?{faces:r}:{}}function gy(e,t){let n=qe(e);if(!n){t.push({severity:"error",code:"invalid-node",message:"Expected a node object"});return}switch(n.type){case"canvas":return Ic(e,t);case"ellipse":return ky(n,t);case"frame":return yy(n,t);case"group":return vy(n,t);case"image":return by(n,t);case"rect":return wy(n,t);case"text":return Sy(n,t);case"vector":return _y(n,t);default:t.push({severity:"error",code:"unknown-node-type",message:`Unknown node type ${JSON.stringify(n.type)}`,...typeof n.id=="string"?{nodeId:n.id}:{}});return}}function Ic(e,t){let n=qe(e);if(!n){t.push({severity:"error",code:"invalid-node",message:"`root` must be a canvas node"});return}let r=on(n,kt,t);return{type:"canvas",id:r,...ct(n.name,"name"),...Nc(n,"w",1280,r,t),...Nc(n,"h",720,r,t),...pt(n.background,r,"background",t),children:nd(n.children,r,t)}}function Nc(e,t,n,r,o){return e[t]===void 0?{}:{[t]:Ee(e[t],r,t,n,o)}}function yy(e,t){let n=on(e,"frame",t);return{type:"frame",id:n,...ct(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",0,t),h:Ee(e.h,n,"h",0,t),...pt(e.background,n,"background",t),...Qi(e.clip,"clip"),...Qi(e.skip,"skip"),...ur(e,n,t),...Pn(e),children:nd(e.children,n,t)}}function vy(e,t){let n=on(e,"group",t);return{type:"group",id:n,...ct(e.name,"name"),...Pn(e),children:nd(e.children,n,t)}}function nd(e,t,n){let r=[];if(Array.isArray(e))for(let o of e){let a=gy(o,n);a&&r.push(a)}else e!==void 0&&n.push({severity:"error",code:"invalid-children",message:"`children` must be an array",nodeId:t});return r}function by(e,t){let n=on(e,"image",t),r=e.fit,o=pt(e.src,n,"src",t);return{type:"image",id:n,...ct(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",100,t),h:Ee(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),src:o.src??"",...Zt.includes(r)?{fit:r}:{},...Pe(e.radius,n,"radius",t),...Pe(e.opacity,n,"opacity",t),...ur(e,n,t),...Pn(e)}}function wy(e,t){let n=on(e,"rect",t);return{type:"rect",id:n,...ct(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",100,t),h:Ee(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...pt(e.fill,n,"fill",t),...pt(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.radius,n,"radius",t),...Pe(e.opacity,n,"opacity",t),...ur(e,n,t),...Pn(e)}}function ky(e,t){let n=on(e,"ellipse",t);return{type:"ellipse",id:n,...ct(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",100,t),h:Ee(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...pt(e.fill,n,"fill",t),...pt(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.opacity,n,"opacity",t),...ur(e,n,t),...Pn(e)}}function _y(e,t){let n=on(e,"vector",t);return{type:"vector",id:n,...ct(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",100,t),h:Ee(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...ct(e.view,"view"),d:typeof e.d=="string"?e.d:"",...pt(e.fill,n,"fill",t),...pt(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.opacity,n,"opacity",t),...lr(e.rule,bn,n,"rule",t),...lr(e.cap,wn,n,"cap",t),...lr(e.join,kn,n,"join",t),...ur(e,n,t),...Pn(e)}}function Sy(e,t){let n=on(e,"text",t);return{type:"text",id:n,...ct(e.name,"name"),x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),w:Ee(e.w,n,"w",200,t),h:Ee(e.h,n,"h",40,t),...Pe(e.rotation,n,"rotation",t),content:Ey(e.content,n,t),...pt(e.font,n,"font",t),...Pe(e.size,n,"size",t),...Pe(e.weight,n,"weight",t),...Pe(e.lineHeight,n,"lineHeight",t),...Pe(e.letterSpacing,n,"letterSpacing",t),...lr(e.align,Yt,n,"align",t),...lr(e.valign,Jt,n,"valign",t),...Qi(e.italic,"italic"),...pt(e.fill,n,"fill",t),...Pe(e.opacity,n,"opacity",t),...ur(e,n,t),...Pn(e)}}function Ey(e,t,n){if(e===void 0)return"";if(typeof e=="string")return e;if(!Array.isArray(e))return n.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 r=[];for(let o of e){if(typeof o=="string"){r.push(o);continue}let a=qe(o);if(!a||typeof a.text!="string"){n.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}r.push({text:a.text,...Bt(a,"font","string"),...Bt(a,"size","number"),...Bt(a,"weight","number"),...Bt(a,"italic","boolean"),...Bt(a,"underline","boolean"),...Bt(a,"strike","boolean"),...Bt(a,"fill","string"),...Bt(a,"letterSpacing","number"),...Bt(a,"link","string")})}return r}function Bt(e,t,n){let r=e[t];return typeof r!==n?{}:n==="number"&&!Number.isFinite(r)?{}:{[t]:r}}function ur(e,t,n){return{...lr(e.blend,vn,t,"blend",n),...pt(e.shadow,t,"shadow",n)}}function Pn(e){return{...e.hidden===!0?{hidden:!0}:{},...e.locked===!0?{locked:!0}:{}}}function Qi(e,t){return typeof e=="boolean"?{[t]:e}:{}}function lr(e,t,n,r,o){return e===void 0?{}:typeof e=="string"&&t.includes(e)?{[r]:e}:(o.push({severity:"error",code:"invalid-value",message:`Expected one of ${t.join(", ")} for ${r}, got ${JSON.stringify(e)}`,nodeId:n,prop:r}),{})}function on(e,t,n){let r=e.id;return typeof r=="string"&&r.length>0?r:(n.push({severity:"error",code:"missing-id",message:`Node is missing an id; using "${t}"`}),t)}function Ee(e,t,n,r,o){let a=Cy(e);return a!==void 0?a:(o.push({severity:"error",code:"invalid-value",message:`Expected a number or expression for ${n}, got ${JSON.stringify(e)}`,nodeId:t,prop:n}),r)}function Cy(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.startsWith("="))return Xt(e.slice(1))}function Pe(e,t,n,r){return e===void 0?{}:{[n]:Ee(e,t,n,0,r)}}function pt(e,t,n,r){return e===void 0?{}:typeof e=="string"?{[n]:e.startsWith("=")?Xt(e.slice(1)):e}:(r.push({severity:"error",code:"invalid-value",message:`Expected a string for ${n}, got ${JSON.stringify(e)}`,nodeId:t,prop:n}),{})}function ct(e,t){return typeof e=="string"?{[t]:e}:{}}function My(e,t){let n=new Set,r=o=>{n.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}),n.add(o.id),be(o)&&o.children.forEach(r)};r(e)}function qe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}var Rc=1500,rd=5e3,Fc=1200,Bc=800,Hc=600,Uc=800,Vc={letter:30,word:80,children:100},co=.04,po=.85,od=1.06,Sa=[.2,0,0,1],Ea=[.4,0,1,1],Ca=[.4,0,.2,1],zc=[.34,1.56,.64,1],Ay={out:Sa,in:Ea,inout:Ca,linear:null,spring:zc};function ad(e,t){let n=e.motion?.[t],r=n?.w!==void 0||n?.h!==void 0?$y(e,t,n):void 0,o=gt(n),a=o?{tempo:o}:{},s=mi(n,e.assets);if(!n||!Pt(e).has(t))return{page:t,length:ze(n?.length,o,rd),beats:[],camera:!1,steps:[],...r?{size:r}:{},...a,clips:s};let d=ft(e),l=[],f=[],c,m=new Map;for(let[E,v]of n.lines.entries()){if(d.get(v.id)!==t||v.camera!==!0&&v.enter===void 0&&v.exit===void 0&&v.emphasis===void 0)continue;let w=K(e.root,v.id);if(!w)continue;let L=ee=>ee===void 0?void 0:m.get(ee),$;v.at!==void 0?$=ze(v.at,o,0):v.with!==void 0&&L(v.with)?$=L(v.with).start:v.after!==void 0&&L(v.after)?$=L(v.after).end:v.together===!0?$=c?.start??0:$=c?.end??0,$+=ze(v.delay,o,0);let z;if(v.on!==void 0&&o){let ee=li($,v.on,o);ee!==$&&(z=$),$=ee}v.step===!0&&f.push($);let A=v.camera===!0?"camera":v.enter!==void 0?"enter":v.exit!==void 0?"exit":"emphasis",N=v.enter??v.exit??v.emphasis,I=Ty(v,N,o),j=A==="camera"||A==="emphasis"?void 0:Oy(v,w),O=j===void 0?1:Math.max(1,jc(w,j)),V=O>1&&j!==void 0?ze(v.stagger,o,Vc[j]):0,C=$+(O-1)*V+I,R=v.ease??(A==="enter"?"out":A==="exit"?"in":"inout");l.push({index:E,line:v,kind:A,...z===void 0?{}:{asked:z},...N===void 0?{}:{effect:N},start:$,end:C,duration:I,ease:R,pieces:O,stagger:V,...j===void 0||O===1?{}:{split:j}});let q=C;if(A==="enter"&&v.hold!==void 0&&v.enter!=="count"){let ee=C+ze(v.hold,o,0);q=ee+I,l.push({index:E,line:v,kind:"exit",...N===void 0?{}:{effect:N},start:ee,end:q,duration:I,ease:"in",pieces:1,stagger:0})}c={start:$,end:q},v.camera!==!0&&m.set(v.id,c)}let g=Math.max(0,...l.map(E=>E.end)),b=ze(n.length,o,l.length===0?rd:g+Rc);return{page:t,length:b,beats:l,camera:l.some(E=>E.kind==="camera"),steps:f,...r?{size:r}:{},...a,clips:s}}function $y(e,t,n){let r=n.w,o=n.h;if(r!==void 0&&o!==void 0)return{w:r,h:o};let a=K(e.root,t),s=a&&"w"in a&&typeof a.w=="number"?a.w:void 0,d=a&&"h"in a&&typeof a.h=="number"?a.h:void 0;if(r!==void 0)return{w:r,h:s&&d?Math.round(r*d/s):r};if(o!==void 0)return{w:s&&d?Math.round(o*s/d):o,h:o}}function Ty(e,t,n){return t==="cut"?0:e.duration!==void 0?ze(e.duration,n,eo):e.camera===!0?Uc:e.emphasis!==void 0?Hc:t==="count"?Fc:t==="draw"?Bc:eo}function Oy(e,t){if(e.by!==void 0){if(t.type!=="text")return;let n=t.rotation;return n!==void 0&&n!==0?void 0:e.by}if(e.stagger!==void 0&&de(t).length>0)return"children"}function jc(e,t){return t==="children"?de(e).length:e.type!=="text"?1:t==="word"?sd(rn(e.content)).length:Kc(rn(e.content)).length}function sd(e){return e.split(/\s+/).filter(t=>t!=="")}function Kc(e){return[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(e)].map(n=>n.segment).filter(n=>n.trim()!=="")}function Ma(e,t){if(t<=0)return 0;if(t>=1)return 1;let n=Ay[e];return n===null?t:Ly(n,t)}function Ly(e,t){let[n,r,o,a]=e,s=(c,m,g)=>3*c*g*(1-g)**2+3*m*g*g*(1-g)+g**3,d=0,l=1,f=t;for(let c=0;c<40;c++){f=(d+l)/2;let m=s(n,o,f);if(Math.abs(m-t)<1e-7)break;m<t?d=f:l=f}return s(r,a,f)}function id(e){let t=/-?\d{1,3}(?:,\d{3})+(?:\.\d+)?|-?\d+(?:\.\d+)?/.exec(e);if(!t)return;let n=t[0],r=n.includes(",")?",":"",o=n.replaceAll(",",""),a=o.includes(".")?o.split(".")[1].length:0;return{before:e.slice(0,t.index),value:Number(o),decimals:a,grouping:r,after:e.slice(t.index+n.length)}}function dd(e,t){let n=Math.abs(t).toFixed(e.decimals),[r,o]=n.split("."),a=e.grouping===""?r:r.replace(/\B(?=(\d{3})+(?!\d))/g,e.grouping),s=t<0&&Number(n)!==0?"-":"";return`${e.before}${s}${a}${o===void 0?"":`.${o}`}${e.after}`}var qc=1200,Gc=3.5;function Wc(e){return Math.max(qc,Math.round(sd(e).length/Gc*1e3))}function ld(e){let t=[];for(let n of Object.keys(e.motion??{})){let r=e.motion?.[n];if(!An(r)||!Pt(e).has(n))continue;let o=ad(e,n);t.push(...Dy(e,n,o));for(let s of o.beats)s.start>o.length&&t.push({severity:"warning",code:"motion-after-length",message:`motion ${n}: ${s.line.camera===!0?"camera ":""}${s.line.id} starts at ${Wr(s.start)}, after the video ends at ${Wr(o.length)}`,nodeId:s.line.id});let a=new Map;for(let s of o.beats)if(s.kind==="enter"&&!a.has(s.line.id))a.set(s.line.id,{from:s.start,to:o.length});else if(s.kind==="exit"){let d=a.get(s.line.id);a.set(s.line.id,{from:d?.from??0,to:s.start})}for(let[s,{from:d,to:l}]of a){let f=K(e.root,s);if(f?.type!=="text")continue;let c=rn(f.content),m=Wc(c);l-d<m&&t.push({severity:"warning",code:"video-text-brief",message:`motion ${n}: ${s} is on screen for ${Wr(l-d)}; "${Py(c)}" takes about ${m} ms to read`,nodeId:s})}}return t}function Dy(e,t,n){let r=e.motion?.[t]?.music,o=n.clips[0];if(!r||!o)return[];let a=(g,b)=>({severity:"warning",code:g,message:`motion ${t}: ${b}`,nodeId:t}),s=g=>`${(g/1e3).toFixed(2)} s`,d=e.assets[r.asset];if(!d)return[a("music-missing",`${r.asset} has no file yet, so the video is silent. Add it with vd_add_asset (a URL), or the person drops a track on the canvas`)];if(!d.type.startsWith("audio/"))return[a("music-not-audio",`music ${r.asset} is ${d.type}, not a sound`)];let l=[],f=o.from;d.ms!==void 0&&f>=d.ms?l.push(a("music-from-past-end",`from=${f} is past the end of ${r.asset}, which is ${s(d.ms)} long`)):d.ms!==void 0&&!o.loop&&d.ms-f<n.length-ui&&l.push(a("music-short",`${r.asset} runs out at ${s(d.ms-f)} and the video at ${s(n.length)}: add loop, or set length=`));let c=d.ms!==void 0&&d.ms>0?d.bytes*8/d.ms:void 0,m=2*(n.length+f)*fi/1e3;return c!==void 0&&c>ci?l.push(a("audio-heavy",`${r.asset} is ${Math.round(c)} kbps: re-encode it as a 128 kbps MP3 or M4A, about 1 MB a minute`)):d.bytes>m&&l.push(a("audio-heavy",`${r.asset} is ${(d.bytes/1e6).toFixed(1)} MB for ${s(n.length)} of video: trim it to the part the video uses, as a 128 kbps MP3 or M4A`)),l}function Py(e){return e.length>40?`${e.slice(0,37)}\u2026`:e}function Aa(e){return/^\s*(linear|radial|conic|repeating-[a-z]+)-gradient\s*\(/i.test(e)}function mo(e){let t=e.trim(),n=/^([a-z-]+)-gradient\s*\(([\s\S]*)\)$/i.exec(t);if(!n)return Aa(t)?{error:'A gradient needs its closing ")"'}:{kind:"solid",colour:t};let r=n[1].toLowerCase(),o=Ny(n[2]).map(a=>a.trim());if(o.some(a=>a===""))return{error:"A gradient has an empty argument"};if(r==="linear"){let a=Ry(o[0]),s=Yc(a===void 0?o:o.slice(1));return"error"in s?s:{kind:"linear",angle:a??180,stops:s.stops}}if(r==="radial"){let a=By(o[0]);if(a&&"error"in a)return a;let s=Yc(a?o.slice(1):o);return"error"in s?s:{kind:"radial",shape:a?.shape??"ellipse",cx:a?.cx??.5,cy:a?.cy??.5,stops:s.stops}}return{error:`${r}-gradient is not supported; use linear-gradient or radial-gradient`}}function ud(e){let t=e.map(r=>r.at);t[0]===void 0&&(t[0]=0),t[t.length-1]===void 0&&(t[t.length-1]=1);let n=0;for(let r=0;r<t.length;r+=1){let o=t[r];o!==void 0&&(n=Math.max(n,o),t[r]=n)}for(let r=1;r<t.length;r+=1){if(t[r]!==void 0)continue;let o=r-1,a=r;for(;t[a]===void 0;)a+=1;let s=t[o],d=t[a];for(let l=r;l<a;l+=1)t[l]=s+(d-s)*(l-o)/(a-o);r=a}return e.map((r,o)=>({colour:r.colour,at:t[o]}))}function Ny(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o+=1){let a=e[o];a==="("?n+=1:a===")"?n=Math.max(0,n-1):a===","&&n===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}var Iy={top:[0,-1],bottom:[0,1],left:[-1,0],right:[1,0]};function Ry(e){let t=/^(-?\d*\.?\d+)(deg|turn|rad)$/i.exec(e);if(t){let a=Number(t[1]),s=t[2].toLowerCase();return s==="turn"?a*360:s==="rad"?a*180/Math.PI:a}let n=/^to\s+([a-z]+)(?:\s+([a-z]+))?$/i.exec(e);if(!n)return;let r=0,o=0;for(let a of[n[1],n[2]]){if(a===void 0)continue;let s=Iy[a.toLowerCase()];if(!s)return;r+=s[0],o+=s[1]}return(Math.atan2(r,-o)*180/Math.PI+360)%360}var Fy={left:0,top:0,center:.5,right:1,bottom:1};function By(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 n=t[1]?.toLowerCase();if(t[2]===void 0)return n?{shape:n}:void 0;let r=Xc(t[2]),o=t[3]===void 0?.5:Xc(t[3]);return r===void 0||o===void 0?{error:`A radial centre is two percentages or keywords, not "${e}"`}:{...n?{shape:n}:{},cx:r,cy:o}}function Xc(e){let t=Fy[e.toLowerCase()];if(t!==void 0)return t;let n=/^(-?\d*\.?\d+)%$/.exec(e);return n?Number(n[1])/100:void 0}function Yc(e){if(e.length<2)return{error:"A gradient needs at least two colours"};let t=[];for(let n of e){let r=/^([\s\S]*?\S)\s+(-?\d*\.?\d+)%$/.exec(n);if(r&&Hy(r[1]))t.push({colour:r[1],at:Number(r[2])/100});else{if(/\s/.test(n.replace(/\([^)]*\)/g,"")))return{error:`"${n}" is not a colour with an optional percentage`};t.push({colour:n})}}return{stops:t}}function Hy(e){let t=0;for(let n of e)if(n==="("&&(t+=1),n===")"&&(t-=1),t<0)return!1;return t===0}function $a(e){let t=mo(e);return"error"in t?[]:t.kind==="solid"?[t.colour]:t.stops.map(n=>n.colour)}function fr(e){let t=e.trim();if(t===""||t==="none")return{shadows:[]};let n=[];for(let r of Uy(t)){let o=Vy(r.trim());if(o.includes("inset"))return{error:"Inner shadows (inset) are not supported yet"};let a=[],s=[];for(let m of o){let g=/^(-?\d*\.?\d+)(px)?$/.exec(m);g&&s.length===0?a.push(Number(g[1])):s.push(m)}if(a.length<2||a.length>4)return{error:`"${r.trim()}" needs x, y, then optional blur and spread`};if(s.length!==1)return{error:`"${r.trim()}" needs one colour after its numbers`};let[d=0,l=0,f=0,c=0]=a;if(f<0)return{error:"A shadow cannot have a negative blur"};n.push({x:d,y:l,blur:f,spread:c,colour:s[0]})}return{shadows:n}}function Uy(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o+=1){let a=e[o];a==="("?n+=1:a===")"?n=Math.max(0,n-1):a===","&&n===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}function Vy(e){let t=[],n=0,r="";for(let o of e){if(o==="("&&(n+=1),o===")"&&(n=Math.max(0,n-1)),/\s/.test(o)&&n===0){r!==""&&t.push(r),r="";continue}r+=o}return r!==""&&t.push(r),t}var fd=["rect","ellipse","vector","image","text"];function st(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function nt(e,t,n){if(n===0)return e;let r=n*Math.PI/180,o=Math.cos(r),a=Math.sin(r),s=e.x-t.x,d=e.y-t.y;return{x:t.x+s*o-d*a,y:t.y+s*a+d*o}}function ho(e,t,n=st(e)){if(t%360===0)return e;let r=[{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(l=>nt(l,n,t)),o=r.map(l=>l.x),a=r.map(l=>l.y),s=Math.min(...o),d=Math.min(...a);return{x:s,y:d,w:Math.max(...o)-s,h:Math.max(...a)-d}}function xo(e){let t=(e%360+360)%360,n=Math.round(t*100)/100;return n===360?0:n}var cd=["x","y","w","h","left","right","top","bottom","cx","cy"];function go(e){return cd.includes(e)}var pd=["parent","prev","next","self","root"];function md(e){return pd.includes(e)}var Ge=class extends Error{position;constructor(t,n){super(t),this.position=n,this.name="ExprSyntaxError"}},Zc=/[A-Za-z_]/,hd=/[A-Za-z0-9_]/;function xd(e){let t=[],n=0,r=()=>{if(!Zc.test(e[n]??""))throw new Ge(`Expected a name at position ${n}`,n);let s=n;for(;n<e.length&&hd.test(e[n]??"");)n++;return e.slice(s,n)},o=()=>{if(!hd.test(e[n]??""))throw new Ge(`Expected a name at position ${n}`,n);let s=n;for(;n<e.length&&hd.test(e[n]??"");)n++;return e.slice(s,n)},a=()=>{let s=[r()];for(;e[n]===".";)n++,s.push(o());return s};for(;n<e.length;){let s=e[n]??"";if(/\s/.test(s)){n++;continue}if(/[0-9]/.test(s)){let d=n;for(;n<e.length&&/[0-9]/.test(e[n]??"");)n++;if(e[n]==="."&&/[0-9]/.test(e[n+1]??""))for(n++;n<e.length&&/[0-9]/.test(e[n]??"");)n++;let l=e.slice(d,n),f=Number(l);if(!Number.isFinite(f))throw new Ge(`Bad number "${l}"`,d);e[n]==="%"?(n++,t.push({type:"percent",value:f})):t.push({type:"number",value:f});continue}if(s==="$"){n++,t.push({type:"token",name:r()});continue}if(s==="@"){n++,t.push({type:"ref",path:a()});continue}if(Zc.test(s)){t.push({type:"word",path:a()});continue}if("+-*/()".includes(s)){n++,t.push({type:"op",value:s});continue}throw new Ge(`Unexpected character "${s}" at position ${n}`,n)}return t.push({type:"eof"}),t}var Gy={"+":1,"-":1,"*":2,"/":2};function yt(e){try{let t=xd(e),n=new gd(t),r=n.parseBinary(0);return n.expectEof(),{ok:!0,ast:r}}catch(t){if(t instanceof Ge)return{ok:!1,message:t.message};throw t}}var gd=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 Ge("Unexpected trailing input",this.index)}parseBinary(t){let n=this.parseUnary();for(;;){let r=this.peek();if(r.type!=="op"||!Wy(r.value))break;let o=Gy[r.value];if(o<t)break;this.next();let a=this.parseBinary(o+1);n={kind:"binary",op:r.value,left:n,right:a}}return n}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 Ge(`@${t.path.join(".")} needs an edge, for example @${t.path.join(".")}.right`,this.index);return{kind:"nodeRef",path:t.path}}case"word":{let[n,r,...o]=t.path;if(n===void 0||!md(n))throw new Ge(`Unknown name "${t.path.join(".")}". Use $token for a token or @id.edge for a node.`,this.index);if(r===void 0||!go(r)||o.length>0)throw new Ge(`${n} needs an edge, for example ${n}.w`,this.index);return{kind:"relRef",word:n,edge:r}}case"op":{if(t.value==="("){let n=this.parseBinary(0),r=this.next();if(r.type!=="op"||r.value!==")")throw new Ge("Missing closing parenthesis",this.index);return n}throw new Ge(`Unexpected "${t.value}"`,this.index)}case"eof":throw new Ge("Unexpected end of expression",this.index)}}};function Wy(e){return e==="+"||e==="-"||e==="*"||e==="/"}var Qc={"+":1,"-":1,"*":2,"/":2},ep=3,Xy=4;function Yy(e){return e.kind==="binary"?Qc[e.op]??1:e.kind==="unary"?ep:Xy}function yo(e){return Ta(e,0)}function Ta(e,t){let n=Jy(e);return Yy(e)<t?`(${n})`:n}function Jy(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}${Ta(e.operand,ep)}`;case"binary":{let t=Qc[e.op]??1;return`${Ta(e.left,t)} ${e.op} ${Ta(e.right,t+1)}`}}}function yd(e){return e.slice(0,-1).join(".")}function an(e,t){switch(e.kind){case"nodeRef":{let n=e.path[e.path.length-1],r=t(yd(e.path));return n===void 0||r===void 0?e:{kind:"nodeRef",path:[...r.split("."),n]}}case"unary":return{...e,operand:an(e.operand,t)};case"binary":return{...e,left:an(e.left,t),right:an(e.right,t)};default:return e}}function Nn(e){let t=new Set,n=new Set,r=o=>{switch(o.kind){case"nodeRef":t.add(yd(o.path));return;case"token":n.add(o.name);return;case"unary":r(o.operand);return;case"binary":r(o.left),r(o.right);return;default:return}};return r(e),{nodes:[...t],tokens:[...n]}}function Ye(e,t){return`${e} ${t}`}function vd(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 Oa(e,t,n,r,o){switch(e){case"x":case"left":return t;case"y":case"top":return n;case"w":return r;case"h":return o;case"right":return t+r;case"bottom":return n+o;case"cx":return t+r/2;case"cy":return n+o/2}}function bd(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 wd(e,t,n){let r=m=>{let g=[];for(let b=n.parentOf.get(m);b!==void 0;b=n.parentOf.get(b))g.push(b);return g},o=r(e),a=r(t),s=new Set(a),d=o.find(m=>s.has(m)),l=m=>d===void 0?m:m.slice(0,m.indexOf(d)),f=new Map([[e,1]]),c=(m,g)=>{let b=(f.get(m)??0)+g;b===0?f.delete(m):f.set(m,b)};for(let m of l(o))c(m,1);for(let m of l(a))c(m,-1);return f}function kd(e){switch(e){case"right":case"bottom":return 1;case"cx":case"cy":return .5;default:return 0}}function La(e){if(e==="x"||e==="w")return"w";if(e==="y"||e==="h")return"h"}function vo(e){let t=new Map,n=new Map,r=new Map,o=new Map,a=[];ce(e.root,(c,m)=>{t.has(c.id)||t.set(c.id,c),a.push(c),m&&n.set(c.id,m.id),be(c)&&c.children.forEach((g,b)=>{let E=c.children[b-1],v=c.children[b+1];E&&r.set(g.id,E.id),v&&o.set(g.id,v.id)})});let s=new Map;for(let c of a){let m=n.get(c.id);for(;m!==void 0;){let g=t.get(m);if(!g||!De(g))break;m=n.get(m)}m!==void 0&&s.set(c.id,m)}let d=new Map,l=new Map,f=c=>{if(be(c)){if(!De(c)){let m=tp(c);m.forEach((g,b)=>{let E=m[b-1],v=m[b+1];E&&d.set(g.id,E.id),v&&l.set(g.id,v.id)})}for(let m of c.children)f(m)}};return f(e.root),{rootId:e.root.id,byId:t,parentOf:n,prevOf:r,nextOf:o,layoutParentOf:s,layoutPrevOf:d,layoutNextOf:l,order:a}}function tp(e){let t=[];for(let n of e.children)be(n)&&De(n)?t.push(...tp(n)):t.push(n);return t}function Da(e,t,n){if(e.kind==="relRef"){let a=Zy(e.word,t,n);return a===void 0?{ok:!1,message:`${t} has no ${e.word}`}:{ok:!0,nodeId:a,edge:e.edge}}let r=e.path[e.path.length-1]??"",o=e.path.slice(0,-1).join(".");return go(r)?n.byId.has(o)?{ok:!0,nodeId:o,edge:r}:{ok:!1,message:`No node @${o}`}:{ok:!1,message:`"${r}" is not an edge of @${o}`}}function Zy(e,t,n){switch(e){case"self":return t;case"root":return n.rootId;case"parent":return n.layoutParentOf.get(t);case"prev":return n.layoutPrevOf.get(t);case"next":return n.layoutNextOf.get(t)}}function Re(e){let t=[],n=vo(e),r=np(n),o=new Set;rp(r,t),op(r,e,n,o,t);let a=Qy(r);ev(r,a,t);let s=tv(r,a,e,n,o,t);return{nodes:rv(e.root,s,r,t),problems:t}}function cr(e){let t=vo(e),n=np(t),r=[];rp(n,r),op(n,e,t,new Set,r);let o=new Map;for(let a of n.values())for(let s of a.deps){let d=o.get(s),l={nodeId:a.nodeId,prop:a.prop};d?d.push(l):o.set(s,[l])}return o}function np(e){let t=new Map;for(let n of e.order){let r=n;for(let o of wt(n)){let a=r[o];a!==void 0&&t.set(Ye(n.id,o),{nodeId:n.id,prop:o,value:a,deps:[]})}}return t}function rp(e,t){for(let n of e.values()){if(!ke(n.value))continue;let r=yt(n.value.expr);if(r.ok){n.ast=r.ast;continue}t.push({severity:"error",code:"expression-syntax",message:r.message,nodeId:n.nodeId,prop:n.prop})}}function op(e,t,n,r,o){for(let a of e.values()){if(!a.ast)continue;let s=new Set,d=l=>{switch(l.kind){case"number":return;case"token":{let f=Qe(t)[l.name];typeof f!="number"&&o.push({severity:"error",code:f===void 0?"unknown-token":"token-not-a-number",message:f===void 0?`Unknown token $${l.name}`:`Token $${l.name} is not a number`,nodeId:a.nodeId,prop:a.prop});return}case"percent":{let f=La(a.prop);if(!f)return;let c=n.layoutParentOf.get(a.nodeId),m=c===void 0?void 0:Ye(c,f);if(m===void 0||!e.has(m)){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}s.add(m);return}case"nodeRef":case"relRef":{let f=Da(l,a.nodeId,n);if(!f.ok){r.add(l),o.push({severity:"error",code:"unknown-reference",message:f.message,nodeId:a.nodeId,prop:a.prop});return}let c=g=>{e.has(g)&&s.add(g)},m=bd(f.edge);if(!m){for(let g of vd(f.edge))c(Ye(f.nodeId,g));return}for(let g of wd(f.nodeId,a.nodeId,n).keys())c(Ye(g,m));kd(f.edge)!==0&&c(Ye(f.nodeId,m==="x"?"w":"h"));return}case"unary":d(l.operand);return;case"binary":d(l.left),d(l.right);return}};d(a.ast),a.deps=[...s]}}function Qy(e){let t=new Map,n=new Map;for(let[a,s]of e){t.set(a,s.deps.length);for(let d of s.deps){let l=n.get(d);l?l.push(a):n.set(d,[a])}}let r=[];for(let[a,s]of t)s===0&&r.push(a);let o=[];for(let a=0;a<r.length;a++){let s=r[a];o.push(s);for(let d of n.get(s)??[]){let l=(t.get(d)??0)-1;t.set(d,l),l===0&&r.push(d)}}return o}function ev(e,t,n){if(t.length===e.size)return;let r=new Set(t);for(let[o,a]of e)r.has(o)||n.push({severity:"error",code:"cycle",message:`${a.nodeId}.${a.prop} is part of a dependency cycle`,nodeId:a.nodeId,prop:a.prop})}function tv(e,t,n,r,o,a){let s=new Map,d=(l,f)=>s.get(Ye(l,f))??0;for(let l of t){let f=e.get(l);if(f){if(!ke(f.value)){s.set(l,f.value);continue}if(!f.ast){s.set(l,0);continue}s.set(l,ap(f.ast,f,n,r,o,a,d))}}return s}function ap(e,t,n,r,o,a,s){let d=l=>ap(l,t,n,r,o,a,s);switch(e.kind){case"number":return e.value;case"token":{let l=Qe(n)[e.name];return typeof l=="number"?l:0}case"percent":{let l=La(t.prop);if(!l)return e.value/100;let f=r.layoutParentOf.get(t.nodeId);return f===void 0?0:e.value/100*s(f,l)}case"nodeRef":case"relRef":{if(o.has(e))return 0;let l=Da(e,t.nodeId,r);if(!l.ok)return 0;let f=bd(l.edge);if(!f)return Oa(l.edge,s(l.nodeId,"x"),s(l.nodeId,"y"),s(l.nodeId,"w"),s(l.nodeId,"h"));let c=kd(l.edge)*s(l.nodeId,f==="x"?"w":"h");for(let[m,g]of wd(l.nodeId,t.nodeId,r))c+=g*s(m,f);return c}case"unary":{let l=d(e.operand);return e.op==="-"?-l:l}case"binary":{let l=d(e.left),f=d(e.right);if(e.op==="/"&&f===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 c=nv(e.op,l,f);return Number.isFinite(c)?c:(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 nv(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n}}function rv(e,t,n,r){let o=new Map,a=(d,l)=>t.get(Ye(d,l))??0,s=(d,l,f)=>{let c=a(d.id,"x"),m=a(d.id,"y"),g=a(d.id,"w"),b=a(d.id,"h"),E={};for(let L of wt(d)){let $=Ye(d.id,L);n.has($)&&(E[L]=t.get($)??0)}(g<0||b<0)&&r.push({severity:"warning",code:"negative-size",message:`${d.id} resolved to a negative size`,nodeId:d.id});let v=l+c,w=f+m;if(o.set(d.id,{id:d.id,type:d.type,x:c,y:m,w:g,h:b,left:c,top:m,right:c+g,bottom:m+b,cx:c+g/2,cy:m+b/2,absX:v,absY:w,values:E}),be(d))for(let L of d.children)s(L,v,w)};return s(e,0,0),o}function Pa(e){if(!ke(e))return{kind:"literal",value:e};let t=yt(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 ip="system-ui, -apple-system, Segoe UI, Roboto, sans-serif",dp=16,lp=400,up=1.2,Na="#0F172A";function Ht(){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 _d(e,t){if(e===void 0)return ip;let n=t[e];return n?n.fallback?`${sp(n.family)}, ${n.fallback}`:sp(n.family):e}function sp(e){return/^[A-Za-z][A-Za-z0-9 -]*$/.test(e)?e:JSON.stringify(e)}function Sd(e,t,n,r){let o={family:_d(t.font,n),size:t.size,weight:t.weight,italic:t.italic,underline:!1,strike:!1,fill:r(t.fill),letterSpacing:t.letterSpacing},a=typeof e=="string"?[e]:e,s=[];for(let d of a){if(typeof d=="string"){d.length>0&&s.push({text:d,style:o});continue}let l=d;l.text.length!==0&&s.push({text:l.text,style:{family:l.font===void 0?o.family:_d(l.font,n),size:l.size??o.size,weight:l.weight??o.weight,italic:l.italic??o.italic,underline:l.underline??!1,strike:l.strike??!1,fill:l.fill===void 0?o.fill:r(l.fill),letterSpacing:l.letterSpacing??o.letterSpacing,...l.link!==void 0&&xt(l.link)?{link:l.link}:{}}})}return s}function ov(e,t){let n=[];for(let r of e)for(let o of r.text.split(/(\n)/))if(o!==""){if(o===`
40
+ `){let a=n[n.length-1];a&&!a.hardBreak?n[n.length-1]={...a,hardBreak:!0}:n.push({text:"",style:r.style,w:0,hardBreak:!0});continue}for(let a of o.match(/\S+\s*|\s+/g)??[])n.push({text:a,style:r.style,w:t.advance(a,r.style),hardBreak:!1})}return n}function av(e,t,n){let r=[...e.text],o=[],a="";for(let s of r){let d=a+s;if(a!==""&&n.advance(d,e.style)>t){o.push({text:a,style:e.style,w:n.advance(a,e.style),hardBreak:!1}),a=s;continue}a=d}return a!==""&&o.push({text:a,style:e.style,w:n.advance(a,e.style),hardBreak:e.hardBreak}),o.length>0?o:[e]}function fp(e,t){let{width:n,measure:r}=t,o=ov(r.itemize?e.flatMap(f=>r.itemize?.(f)??[f]):e,r);if(o.length===0){let f=e[0]?.style,c=f?t.lineHeight*f.size:0;return{lines:f?[sv(f,t.lineHeight)]:[],width:0,height:c}}let a=[],s=[],d=0,l=()=>{a.push(s),s=[],d=0};for(let f of o){let c=s.length===0&&f.w>n&&n>0?av(f,n,r):[f];for(let m of c){let g=m.text.trimEnd(),b=g===m.text?m.w:r.advance(g,m.style);s.length>0&&d+b>n&&l(),s.push(m),d+=m.w,m.hardBreak&&l()}}return s.length>0&&a.push(s),iv(a,t)}function sv(e,t){let n=t*e.size;return{y:0,h:n,baseline:n*.8,w:0,spans:[],style:e}}function iv(e,t){let n=[],r=0,o=0;return e.forEach((a,s)=>{let d=a.map(j=>j.style.size),l=Math.max(...d,0),f=t.lineHeight*l,c=a.map(j=>t.measure.metrics(j.style)),m=Math.max(...c.map(j=>j.ascent),0),g=Math.max(...c.map(j=>j.descent),0),b=r+(f-(m+g))/2+m,E=dv(a,t.measure),v=E.reduce((j,O)=>j+O.w,0);o=Math.max(o,v);let w=s===e.length-1||(a[a.length-1]?.hardBreak??!1),L=t.align==="justify"&&!w&&E.length>1,$=Math.max(0,t.width-v),z=t.align==="center"?$/2:t.align==="right"?$:0,A=L?$/(E.length-1):0,N=[],I=z;E.forEach((j,O)=>{N.push({text:j.text,style:j.style,x:I,w:j.w}),I+=j.w+(O<E.length-1?A:0)}),n.push({y:r,h:f,baseline:b,w:v,spans:lv(N,L)}),r+=f}),{lines:n,width:o,height:r}}function dv(e,t){let n=[...e];for(;n.length>0;){let r=n[n.length-1],o=r.text.trimEnd();if(o===r.text)break;if(o===""){n.pop();continue}n[n.length-1]={...r,text:o,w:t.advance(o,r.style)};break}return n}function lv(e,t){if(t)return[...e];let n=[];for(let r of e){let o=n[n.length-1];if(o&&cp(o.style,r.style)&&Math.abs(o.x+o.w-r.x)<.01){n[n.length-1]={...o,text:o.text+r.text,w:o.w+r.w};continue}n.push(r)}return n}function cp(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 Ed(e,t,n,r,o,a){let s={size:t.size??dp,weight:t.weight??lp,lineHeight:t.lineHeight??up,letterSpacing:t.letterSpacing??0,italic:e.italic??!1,font:typeof e.font=="string"?e.font:void 0,fill:typeof e.fill=="string"?e.fill:Na},d=Sd(e.content,s,r,o),l=Sd(" ",s,r,o).map(f=>({...f,text:""}));return fp(d.length>0?d:l,{width:n,align:e.align??"left",lineHeight:s.lineHeight,measure:a})}function Cd(e,t,n){let r=t-n;return e.valign==="middle"?r/2:e.valign==="bottom"?r:0}function Md(e){return e.lines.filter(t=>t.spans.length>0)}function ko(e){switch(e.kind){case"text":{let t=Md(e),n=Math.max(e.w,...t.map(o=>o.w)),r=Math.max(e.y+e.h,...t.map(o=>o.y+o.h));return{x:e.x,y:e.y,w:n,h:r-e.y}}case"vector":{let t=Tn(e.contours)??{x:e.x,y:e.y,w:e.w,h:e.h},n=e.stroke!==void 0?e.strokeWidth*2:0;return{x:t.x-n,y:t.y-n,w:t.w+n*2,h:t.h+n*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 Fa(e,t){let n=e.x,r=e.y,o=e.x+e.w,a=e.y+e.h;for(let s of t){let d=s.spread+s.blur;n=Math.min(n,e.x+s.x-d),r=Math.min(r,e.y+s.y-d),o=Math.max(o,e.x+e.w+s.x+d),a=Math.max(a,e.y+e.h+s.y+d)}return{x:n,y:r,w:o-n,h:a-r}}var hp="vd-paint-";var Ra="#CBD5E1",xp="#FFFFFF";function _o(e,t,n={}){let r=[...t.problems],o=[],a=[],s=n.measure??Ht(),d=vp(Qe(e),r),l=d.paint,f=new Map;ce(e.root,(v,w)=>{if("hidden"in v&&v.hidden===!0)return!1;let L=w?f.get(w.id):void 0,$=t.nodes.get(v.id);if(!$){f.set(v.id,L);return}if(v.type==="frame"){v.skip===!0&&w!==e.root&&r.push({severity:"warning",code:"skip-not-a-page",message:`${v.id}: skip only applies to a page, a frame at the top level`,nodeId:v.id,prop:"skip"});let A={x:$.absX,y:$.absY,w:Math.max(0,$.w),h:Math.max(0,$.h)};f.set(v.id,v.clip===!0?v.id:L),v.clip===!0&&a.push({id:v.id,...A,parent:L}),o.push({kind:"frame",id:v.id,...A,background:l(v.background,v.id,"background",A),clip:L,blend:v.blend??"normal",shadows:pr(v.shadow,v.id,Qe(e),r),rotation:0});return}if(f.set(v.id,L),v.type==="text"){o.push(gp(v,$,e,s,r,L,l));return}if(v.type==="image"){o.push({kind:"image",id:v.id,x:$.absX,y:$.absY,w:Math.max(0,$.w),h:Math.max(0,$.h),href:yv(v,e,n.resolveAsset,r),fit:v.fit??"fill",radius:Math.max(0,$.values.radius??0),opacity:wo($.values.opacity??1),clip:L,blend:v.blend??"normal",shadows:pr(v.shadow,v.id,Qe(e),r),rotation:$.values.rotation??0});return}if(v.type==="ellipse"){let A=mp($);o.push({kind:"ellipse",id:v.id,...A,fill:l(v.fill,v.id,"fill",A)??Ra,stroke:l(v.stroke,v.id,"stroke",A),strokeWidth:$.values.strokeWidth??0,opacity:wo($.values.opacity??1),clip:L,blend:v.blend??"normal",shadows:pr(v.shadow,v.id,Qe(e),r),rotation:$.values.rotation??0});return}if(v.type==="vector"){o.push(hv(v,$,r,L,l,pr(v.shadow,v.id,Qe(e),r)));return}if(v.type!=="rect")return;let z=mp($);o.push({kind:"rect",id:v.id,...z,fill:l(v.fill,v.id,"fill",z)??Ra,stroke:l(v.stroke,v.id,"stroke",z),strokeWidth:$.values.strokeWidth??0,radius:Math.max(0,$.values.radius??0),opacity:wo($.values.opacity??1),clip:L,blend:v.blend??"normal",shadows:pr(v.shadow,v.id,Qe(e),r),rotation:$.values.rotation??0})});let c=t.nodes.get(e.root.id),m=e.root.w!==void 0&&e.root.h!==void 0,g=m?{x:0,y:0,width:Math.max(0,c?.w??0),height:Math.max(0,c?.h??0)}:uv(o,a),b={x:g.x,y:g.y,w:g.width,h:g.height},E=l(e.root.background,e.root.id,"background",b);return{...g,background:m?E??xp:E,items:o,clips:a,gradients:d.gradients,problems:r}}function Ad(e,t,n,r,o={}){let a=K(e.root,n.id),s=t.nodes.get(n.id);if(a?.type!=="text"||!s)return;let d=[],l=vp(Qe(e),d);return gp({...a,content:r},s,e,o.measure??Ht(),d,n.clip,l.paint)}function uv(e,t){let n=new Map;for(let d of t){let l=d.parent===void 0?void 0:n.get(d.parent);n.set(d.id,l?pp(d,l):d)}let r=1/0,o=1/0,a=-1/0,s=-1/0;for(let d of e){let l=d.kind==="text"&&Md(d).length>0?Math.max(d.h,d.height):d.h,f=d.clip===void 0?void 0:n.get(d.clip),c=ho(Fa({x:d.x,y:d.y,w:d.w,h:l},d.shadows),d.rotation,st(d)),m=f?pp(c,f):c;m.w<=0||m.h<=0||(r=Math.min(r,m.x),o=Math.min(o,m.y),a=Math.max(a,m.x+m.w),s=Math.max(s,m.y+m.h))}return Number.isFinite(r)?{x:r,y:o,width:a-r,height:s-o}:{x:0,y:0,width:0,height:0}}function pp(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y);return{x:n,y:r,w:Math.min(e.x+e.w,t.x+t.w)-n,h:Math.min(e.y+e.h,t.y+t.h)-r}}function gp(e,t,n,r,o,a,s){let d=Math.max(0,t.w),l=Math.max(0,t.h),f={x:t.absX,y:t.absY,w:d,h:l},c=Ed(e,t.values,d,n.fonts,b=>s(b,e.id,"fill",f)??Na,r);!c.lines.every(b=>b.spans.length===0)&&c.height>l+.5&&o.push({severity:"warning",code:"text-overflow",message:`${e.id} needs ${Math.ceil(c.height)}px but its height is ${Math.round(l)}px`,nodeId:e.id,prop:"h"}),fv(e,n,o);let g=t.absY+Cd(e,l,c.height);return{kind:"text",id:e.id,x:t.absX,y:t.absY,w:d,h:l,clip:a,blend:e.blend??"normal",shadows:pr(e.shadow,e.id,Qe(n),o),rotation:t.values.rotation??0,opacity:wo(t.values.opacity??1),height:c.height,lines:c.lines.map(b=>({y:g+b.y,h:b.h,baseline:g+b.baseline,w:b.w,spans:b.spans.map(E=>({text:E.text,x:t.absX+E.x,y:g+b.baseline,w:E.w,style:E.style})),...b.style?{style:b.style}:{}}))}}function fv(e,t,n){if(typeof e.content!="string")for(let r of e.content){if(typeof r=="string"||r.link===void 0)continue;let o=xt(r.link);if(!o){n.push({severity:"warning",code:"invalid-link",message:`${e.id}: links go to https:, mailto: or #<frame>, not ${JSON.stringify(r.link)}`,nodeId:e.id,prop:"content"});continue}o.kind==="frame"&&!cv(t,o.id)&&n.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 cv(e,t){let n=!1;return ce(e.root,r=>{if(n)return!1;r.id===t&&r.type==="frame"&&(n=!0)}),n}var bo=new Map,pv=512;function mv(e){let t=bo.get(e);if(t)return t;let n=ro(e);return bo.size>=pv&&bo.delete(bo.keys().next().value),bo.set(e,n),n}function hv(e,t,n,r,o,a){let s=Math.max(0,t.w),d=Math.max(0,t.h),l={x:t.absX,y:t.absY,w:s,h:d},{contours:f,error:c}=mv(e.d);c!==void 0&&n.push({severity:"error",code:"bad-path",message:`${e.id}: ${c}`,nodeId:e.id,prop:"d"}),e.view!==void 0&&ga(e.view)===void 0&&n.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 m=It(f,ao(oo(e.view,s,d),l));return{kind:"vector",id:e.id,...l,d:Nt(m),contours:m,fill:o(e.fill,e.id,"fill",l)??Ra,stroke:o(e.stroke,e.id,"stroke",l),strokeWidth:t.values.strokeWidth??0,opacity:wo(t.values.opacity??1),rule:e.rule??"nonzero",cap:e.cap??"butt",join:e.join??"miter",clip:r,blend:e.blend??"normal",shadows:a,rotation:t.values.rotation??0}}function yp(e,t,n,r,o){if(e===void 0)return;if(ke(e)){o.push({severity:"warning",code:"expression-not-supported",message:`Expressions are not supported for ${r} yet; grammar v0 is numeric only`,nodeId:n,prop:r});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:n,prop:r})}function mp(e){return{x:e.absX,y:e.absY,w:Math.max(0,e.w),h:Math.max(0,e.h)}}function vp(e,t){let n=[],r=new Map;return{paint:(a,s,d,l)=>{let f=yp(a,e,s,d,t);if(f===void 0)return;if(/url\(/i.test(f)){t.push({severity:"error",code:"invalid-paint",message:`${s}: a paint is a colour or a gradient, not ${JSON.stringify(f)}`,nodeId:s,prop:d});return}let c=mo(f);if("error"in c){t.push({severity:"error",code:"invalid-paint",message:`${s}: ${c.error}`,nodeId:s,prop:d});return}if(c.kind==="solid")return f;let m=`${s}\0${d}\0${f}`,g=r.get(m);if(g!==void 0)return`url(#${g})`;let b=[...r.keys()].filter(w=>w.startsWith(`${s}\0${d}\0`)).length,E=`${hp}${s}-${d}${b===0?"":`-${b+1}`}`;r.set(m,E);let v=ud(c.stops).map(w=>({offset:w.at,colour:bp(w.colour,e,s,d,t)}));return n.push(gv(c,E,l,xv(v))),`url(#${E})`},gradients:n}}function pr(e,t,n,r){let o=yp(e,n,t,"shadow",r);if(o===void 0)return[];let a=fr(o);return"error"in a?(r.push({severity:"error",code:"invalid-shadow",message:`${t}: ${a.error}`,nodeId:t,prop:"shadow"}),[]):a.shadows.map(s=>({...s,colour:bp(s.colour,n,t,"shadow",r)}))}function xv(e){return e.map((t,n)=>{if(t.colour.trim().toLowerCase()!=="transparent")return t;let r=[e[n-1],e[n+1]].find(o=>o!==void 0&&o.colour.trim().toLowerCase()!=="transparent");return r===void 0?t:{offset:t.offset,colour:r.colour,opacity:0}})}function bp(e,t,n,r,o){let a=t[e];return a===void 0?e:typeof a=="string"&&!Aa(a)?a:(o.push({severity:"error",code:"invalid-paint",message:`${n}: a gradient stop names $${e}, which is not a colour`,nodeId:n,prop:r}),"transparent")}function gv(e,t,n,r){if(e.kind==="linear"){let f=e.angle*Math.PI/180,c=Math.sin(f),m=-Math.cos(f),g=(Math.abs(n.w*c)+Math.abs(n.h*m))/2,b=n.x+n.w/2,E=n.y+n.h/2;return{id:t,kind:"linear",x1:Ia(b-c*g),y1:Ia(E-m*g),x2:Ia(b+c*g),y2:Ia(E+m*g),stops:r}}let o=n.x+n.w*e.cx,a=n.y+n.h*e.cy,s={x:Math.max(o-n.x,n.x+n.w-o),y:Math.max(a-n.y,n.y+n.h-a)};if(e.shape==="circle"||s.x===0||s.y===0){let f=Math.hypot(s.x,s.y);return{id:t,kind:"radial",cx:o,cy:a,rx:f,ry:f,stops:r}}let d=s.x/s.y,l=Math.hypot(s.x/d,s.y);return{id:t,kind:"radial",cx:o,cy:a,rx:l*d,ry:l,stops:r}}function Ia(e){return Math.round(e*1e6)/1e6}function wo(e){return Math.min(Math.max(e,0),1)}function yv(e,t,n,r){let o=ke(e.src)?void 0:e.src,a=o===void 0?void 0:t.assets[o];if(!a){r.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 s=n?.(a,o);return s===void 0&&r.push({severity:"warning",code:"unresolved-asset",message:`The bytes for asset "${o}" are not available here`,nodeId:e.id,prop:"src"}),s}function vv(e,t){let n=new Map,r=(o,a)=>{n.set(o,[...n.get(o)??[],a])};for(let o of e.beats){if(o.kind==="camera")continue;let a=o.kind;if(o.split==="children"){let s=K(t.root,o.line.id);(s&&"children"in s?s.children:[]).forEach((l,f)=>{r(l.id,{beat:o,kind:a,start:o.start+f*o.stagger})})}else if(o.split!==void 0)for(let s=0;s<o.pieces;s+=1)r(o.line.id,{beat:o,kind:a,start:o.start+s*o.stagger,piece:s});else r(o.line.id,{beat:o,kind:a,start:o.start})}for(let o of n.values())o.sort((a,s)=>a.start-s.start);return n}function bv(e,t){let n=t.nodes.get(e.page);return n?Math.min(n.w,n.h):1e3}function wp(e,t,n,r,o){let a=e[0]?.kind==="enter",s,d,l;for(let f of e){if(f.start>t)break;let c=f.beat.effect,m=f.beat.duration,g=m<=0?1:Math.min(1,(t-f.start)/m),b=g>=1;if(f.kind==="emphasis"){if(a||b){s=void 0;continue}let $=1+(od-1)*Math.sin(Math.PI*Ma(f.beat.ease,g));s=Ba(n,$,$,"centre",1);continue}if(b){a=f.kind==="exit",s=void 0,d=void 0,l=void 0;continue}let E=Ma(f.beat.ease,g),v=f.kind==="enter"?E:1-E,w=Sp(f.kind==="enter"?E:1-E);a=!1,d=void 0,l=void 0;let L=f.beat.line.from;switch(c){case"cut":s=void 0;break;case"fade":s=kp(w);break;case"rise":case"drop":{let $=c==="rise"?1:-1;s={sx:1,sy:1,tx:0,ty:f.kind==="enter"?$*r*(1-E):-$*r*E,opacity:w};break}case"pop":{let $=po+(1-po)*v;s=Ba(n,$,$,"centre",w);break}case"grow":{let $=typeof L=="string"?L:"bottom",z=Math.max(0,v);s=$==="left"||$==="right"?Ba(n,z,1,$,1):Ba(n,1,z,$,1);break}case"wipe":{let $=typeof L=="string"?L:"left";d=f.kind==="enter"?Ep(n,$,v):wv(n,$,E),s=void 0;break}case"count":{let $=o.text===void 0?void 0:id(o.text);if(!$){s=kp(w);break}let z=typeof L=="number"?L:0;l=dd($,z+($.value-z)*E),s=void 0;break}case"draw":s={sx:1,sy:1,tx:0,ty:0,opacity:1,trace:v,fillOpacity:Sp((v-.75)/.25)};break;case"pulse":case void 0:s=void 0;break}}return{hidden:a,pose:s,...d?{reveal:d}:{},...l===void 0?{}:{text:l}}}function kp(e){return{sx:1,sy:1,tx:0,ty:0,opacity:e}}function Ba(e,t,n,r,o){let a=r==="left"?e.x:r==="right"?e.x+e.w:e.x+e.w/2,s=r==="top"?e.y:r==="bottom"?e.y+e.h:e.y+e.h/2;return{sx:t,sy:n,tx:a*(1-t),ty:s*(1-n),opacity:o}}function Ep(e,t,n){let r=e.w*n,o=e.h*n;switch(t){case"left":return{x:e.x,y:e.y,w:r,h:e.h};case"right":return{x:e.x+e.w-r,y:e.y,w:r,h:e.h};case"top":return{x:e.x,y:e.y,w:e.w,h:o};case"bottom":return{x:e.x,y:e.y+e.h-o,w:e.w,h:o}}}function wv(e,t,n){return Ep(e,{left:"right",right:"left",top:"bottom",bottom:"top"}[t],1-n)}function _p(e,t){let n=t.trace??e.trace,r=t.fillOpacity??e.fillOpacity;return{sx:e.sx*t.sx,sy:e.sy*t.sy,tx:e.sx*t.tx+e.tx,ty:e.sy*t.ty+e.ty,opacity:e.opacity*t.opacity,...n===void 0?{}:{trace:n},...r===void 0?{}:{fillOpacity:r}}}function Sp(e){return e<0?0:e>1?1:e}function kv(e,t){let n=new Map;ce(t.root,(o,a)=>{a&&n.set(o.id,a.id)});let r=new Map;for(let o of e.items){let a=o.kind==="frame"?{x:o.x,y:o.y,w:o.w,h:o.h}:ko(o);for(let s=o.id;s!==void 0;s=n.get(s)){let d=r.get(s);if(r.set(s,d?_v(d,a):a),s===t.root.id)break}}return{parents:n,boxes:r}}function _v(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{x:n,y:r,w:Math.max(e.x+e.w,t.x+t.w)-n,h:Math.max(e.y+e.h,t.y+t.h)-r}}function $d(e,t,n,r){let o=vv(t,r.doc);if(o.size===0)return e;let{parents:a,boxes:s}=kv(e,r.doc),d=co*bv(t,r.resolution),l=r.options?.measure??Ht(),f=new Map,c=new Map;for(let[b,E]of o){let v=s.get(b)??{x:0,y:0,w:0,h:0},w=K(r.doc.root,b),L=w?.type==="text"?rn(w.content):void 0,$=E.filter(A=>A.piece===void 0),z=E.find(A=>A.piece!==void 0);if($.length>0&&f.set(b,wp($,n,v,d,{...L===void 0?{}:{text:L}})),z&&(z.beat.split==="word"||z.beat.split==="letter")){let A=[];for(let N=0;N<z.beat.pieces;N+=1){let I=E.filter(j=>j.piece===N);A.push(wp(I,n,v,d,{}))}A.some(N=>N.hidden||N.pose!==void 0)&&c.set(b,{split:z.beat.split,moments:A})}}let m=[...e.clips],g=[];for(let b of e.items){let E=[],v;for(let A=b.id;A!==void 0;A=a.get(A)){let N=f.get(A);N&&(E.unshift(N),N.reveal&&!v&&(v={id:A,box:N.reveal}))}if(E.some(A=>A.hidden))continue;let w;for(let A of E)A.pose&&(w=w?_p(w,A.pose):A.pose);let L=b,$=f.get(b.id)?.text;if($!==void 0&&b.kind==="text"&&(L=Ad(r.doc,r.resolution,b,$,r.options)??b),v){let A=`${v.id}~wipe${b.clip===void 0?"":`~${b.clip}`}`;m.some(N=>N.id===A)||m.push({id:A,...v.box,parent:b.clip}),L={...L,clip:A}}let z=c.get(b.id);if(z&&L.kind==="text"){Cp(L,z.split,l).forEach((A,N)=>{let I=z.moments[N];if(!I||I.hidden)return;let j=I.pose&&w?_p(w,I.pose):I.pose??w;g.push({...A,part:N,...j?{pose:j}:{}})});continue}g.push(w&&!Sv(w)?{...L,pose:w}:L)}return{...e,items:g,clips:m}}function Sv(e){return e.sx===1&&e.sy===1&&e.tx===0&&e.ty===0&&e.opacity===1&&e.trace===void 0&&e.fillOpacity===void 0}function Cp(e,t,n=Ht()){let r=[],o=new Intl.Segmenter(void 0,{granularity:"grapheme"}),a=!1;for(let s of e.lines){a=!1;for(let d of s.spans){let l=0,f=t==="word"?d.text.split(/(\s+)/).filter(c=>c!==""):[...o.segment(d.text)].map(c=>c.segment);for(let c of f){if(c.trim()==="")a=!1;else{(t==="letter"||!a)&&r.push([]);let g=d.x+n.advance(d.text.slice(0,l),d.style);r.at(-1).push({...d,text:c,x:g,w:n.advance(c,d.style)}),a=!0}l+=c.length}}}return r.map(s=>({...e,lines:e.lines.map(d=>({...d,spans:s.filter(l=>l.y===d.baseline)})).filter(d=>d.spans.length>0)}))}var Mp="vd-clip-";function Td(e){return Cv(e,"")}function Cv(e,t){let n=e.parent===void 0?"":` clip-path="url(#${mr(t+Mp+e.parent)})"`;return`<clipPath id="${mr(t+Mp+e.id)}"${n}><rect x="${Q(e.x)}" y="${Q(e.y)}" width="${Q(e.w)}" height="${Q(e.h)}"/></clipPath>`}function Od(e){return Mv(e,"")}function Mv(e,t){let n=e.stops.map(o=>`<stop offset="${Q(o.offset)}" stop-color="${mr(o.colour)}"${o.opacity===void 0?"":` stop-opacity="${Q(o.opacity)}"`}/>`).join(""),r=mr(t+e.id);return e.kind==="linear"?`<linearGradient id="${r}" gradientUnits="userSpaceOnUse" x1="${Q(e.x1)}" y1="${Q(e.y1)}" x2="${Q(e.x2)}" y2="${Q(e.y2)}">${n}</linearGradient>`:`<radialGradient id="${r}" gradientUnits="userSpaceOnUse" cx="0" cy="0" r="1" gradientTransform="matrix(${Q(e.rx)} 0 0 ${Q(e.ry)} ${Q(e.cx)} ${Q(e.cy)})">${n}</radialGradient>`}var Ha="vd-shadow-";function Ld(e,t=!1){return Av(e,t,"")}function Av(e,t,n){let r=Fa(ko(e),e.shadows),o=2,a=[];e.shadows.forEach((d,l)=>{let f=`s${l}`,c="SourceAlpha";d.spread!==0&&(a.push(`<feMorphology in="${c}" operator="${d.spread>0?"dilate":"erode"}" radius="${Q(Math.abs(d.spread))}" result="${f}m"/>`),c=`${f}m`),d.blur>0&&(a.push(`<feGaussianBlur in="${c}" stdDeviation="${Q(d.blur/2)}" result="${f}b"/>`),c=`${f}b`),a.push(`<feOffset in="${c}" dx="${Q(d.x)}" dy="${Q(d.y)}" result="${f}o"/>`,`<feFlood flood-color="${mr(d.colour)}" result="${f}c"/>`,`<feComposite in="${f}c" in2="${f}o" operator="in" result="${f}"/>`)});let s=e.shadows.map((d,l)=>`<feMergeNode in="s${e.shadows.length-1-l}"/>`).join("");return`<filter id="${mr(n+Ha+e.id)}" filterUnits="userSpaceOnUse" x="${Q(r.x-o)}" y="${Q(r.y-o)}" width="${Q(r.w+o*2)}" height="${Q(r.h+o*2)}" color-interpolation-filters="sRGB">`+a.join("")+`<feMerge>${s}${t?"":'<feMergeNode in="SourceGraphic"/>'}</feMerge></filter>`}function Ua(e){return`rotate(${Q(e.rotation)} ${Q(e.x+e.w/2)} ${Q(e.y+e.h/2)})`}function Dd(e){return e.rotation!==0&&e.clip!==void 0}function Pd(e){return`matrix(${Q(e.sx)} 0 0 ${Q(e.sy)} ${Q(e.tx)} ${Q(e.ty)})`}function mr(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var Lv=.8,Dv=.2;function Nd(e,t){let r=e.createElement("canvas").getContext("2d"),o=Ht(),a=new Map,s=new Map,d=new Set;function l(c){return`${c.italic?"italic ":""}${c.weight} ${c.size}px ${c.family}`}function f(){a.clear(),s.clear()}return{advance(c,m){if(!r)return o.advance(c,m);let g=l(m),b=`${g}\0${m.letterSpacing}\0${c}`,E=a.get(b);if(E!==void 0)return E;r.font=g;let v=r.measureText(c).width+m.letterSpacing*[...c].length;return a.set(b,v),v},metrics(c){if(!r)return o.metrics(c);let m=l(c),g=s.get(m);if(g)return g;r.font=m;let b=r.measureText("Hxg"),E=b.fontBoundingBoxAscent??c.size*Lv,v=b.fontBoundingBoxDescent??c.size*Dv,w={ascent:E,descent:v,lineGap:0};return s.set(m,w),w},load(c,m){let g=e.fonts;if(!g||typeof FontFace!="function")return!1;let b=!1;for(let E of Object.values(c.fonts))for(let v of Pv(E)){let w=`${E.family}\0${v.src}\0${v.weight??400}\0${v.style??"normal"}`;if(d.has(w))continue;d.add(w);let L=v.src.startsWith("data:")?void 0:m?.(v.src),$={weight:String(v.weight??400),style:v.style??"normal"},z=A=>{let N=new FontFace(E.family,typeof A=="string"?`url(${A})`:Nv(A),$);g.add(N),N.load().then(()=>{f(),t?.()},()=>{g.delete(N)})};L===void 0?z(v.src):(b=!0,L.then(z,()=>{}))}return b},invalidate:f,destroy(){f(),d.clear()}}}function Pv(e){return(e.faces??[]).flatMap(t=>t.src===void 0?[]:[{...t,src:t.src}])}function Nv(e){return e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}var Va={x:0,y:0,zoom:1},$p=.02,Tp=64;function hr(e){return Number.isFinite(e)?Math.min(Math.max(e,$p),Tp):1}function za(e,t){return{x:(t.x-e.x)/e.zoom,y:(t.y-e.y)/e.zoom}}function Id(e,t){return{x:t.x*e.zoom+e.x,y:t.y*e.zoom+e.y}}function So(e,t,n){let r=hr(e.zoom*n),o=za(e,t);return{zoom:r,x:t.x-o.x*r,y:t.y-o.y*r}}function $t(e,t,n){return{...e,x:e.x+t,y:e.y+n}}function Rd(e){return`translate(${e.x} ${e.y}) scale(${e.zoom})`}function sn(e,t,n){let r={width:Math.max(1,t.width-n*2),height:Math.max(1,t.height-n*2)};if(e.width<=0||e.height<=0)return Va;let o=hr(Math.min(r.width/e.width,r.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 xe="http://www.w3.org/2000/svg",Op="vd-viewer-styles",Lp=`
41
41
  .vd-viewer {
42
42
  position: relative;
43
43
  overflow: hidden;
@@ -136,7 +136,7 @@ ${Mn}`);return t===-1?-1:t+1}function pg(e){let t=new Set;for(let n of e.matchAl
136
136
  .vd-viewer--interacting .vd-viewer__page {
137
137
  filter: none;
138
138
  }
139
- `;function ap(e){if(e.getElementById(rp))return;let t=e.createElement("style");t.id=rp,t.textContent=op,e.head.appendChild(t)}function sp(e,t,n,r){return t?nv(e,t,n,r):tv(e,n,r)}function tv(e,t,n){let r=xl(e,n);return{measurer:r,update:o=>{r.load(o,t)},afterPaint:()=>{},destroy:()=>r.destroy()}}var ip=new WeakMap;function nv(e,t,n,r){let o,a,i,l=()=>{if(!o)throw new Error("canvasFonts: update() before measuring");return o};return{measurer:{advance:(u,p)=>l().measurer.advance(u,p),metrics:u=>l().measurer.metrics(u),itemize:u=>l().measurer.itemize(u)},update(u){o&&u.fonts===a||(i?.(),o?.dispose(),o=t.forDocument(u,n?{loader:n}:{}),a=u.fonts,i=o.onChange(r))},afterPaint(){let u=e.fonts;if(!o||!u||typeof FontFace!="function")return;let p=ip.get(e);p||ip.set(e,p=new Set);for(let x of o.usedFaces()){if(p.has(x.id))continue;p.add(x.id);let y=new FontFace(x.id,rv(x.bytes),{weight:String(x.weight),style:x.style});u.add(y),y.load().catch(()=>u.delete(y))}},destroy(){i?.(),o?.dispose(),o=void 0}}}function rv(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}var ov=.01,av=.004,lp=40,iv=16;function La(e,t){ap(e.ownerDocument);let n=t.document,r=N=>sp(e.ownerDocument,N,t.loadFont,()=>{V(n)}),o=r(t.fonts),a={advance:(N,z)=>o.measurer.advance(N,z),metrics:N=>o.measurer.metrics(N),itemize:N=>o.measurer.itemize?.(N)??[N]};o.update(n);let i=Ne(n),l=()=>t.resolveAsset?{measure:a,resolveAsset:t.resolveAsset}:{measure:a},d=xo(n,i,l()),u=t.camera??$a,p=t.interactive??!0,x=t.wheel??"always";e.classList.add("vd-viewer"),t.surface&&(e.style.background=t.surface);let y=e.ownerDocument.createElementNS(pe,"svg");y.setAttribute("class","vd-viewer__surface"),y.setAttribute("width","100%"),y.setAttribute("height","100%");let k=e.ownerDocument.createElementNS(pe,"g");k.setAttribute("class","vd-viewer__camera"),k.style.isolation="isolate",y.appendChild(k);let M=e.ownerDocument.createElementNS(pe,"defs");k.appendChild(M);let v=e.ownerDocument.createElementNS(pe,"rect");v.setAttribute("class","vd-viewer__page"),k.appendChild(v),e.appendChild(y);let w=new Map,D=null;function A(){let N=t.sample;return D&&N?N(d,D.timeline,D.t,{doc:n,resolution:i,options:l()}):d}function H(){k.setAttribute("transform",yl(u))}function E(N=!0){let z=A();P(z);let de=d.background!==void 0;oe(v,"x",String(d.x)),oe(v,"y",String(d.y)),oe(v,"width",String(de?d.width:0)),oe(v,"height",String(de?d.height:0)),Ce(v,"fill",d.background??null);let le=new Set,Te=v;for(let ae of z.items){let Be=ae.part===void 0?ae.id:`${ae.id}\0${ae.part}`;le.add(Be);let Le=w.get(Be);(!Le||Le.tagName!==dp(ae))&&(Le?.remove(),Le=e.ownerDocument.createElementNS(pe,dp(ae)),Le.setAttribute("data-vd-id",ae.id),w.set(Be,Le)),dv(Le,ae),Te.nextSibling!==Le&&k.insertBefore(Le,Te.nextSibling),Te=Le}for(let[ae,Be]of w)le.has(ae)||(Be.remove(),w.delete(ae));o.afterPaint(),N&&t.onSceneChange?.(d,n)}let T=new Map;function P(N){let z=[...N.gradients.map(cl),...[...new Map(N.items.filter(ae=>ae.shadows.length>0).map(ae=>[ae.id,ae])).values()].map(ae=>pl(ae)),...N.clips.map(ul)],de=new Set(z);for(let[ae,Be]of T)de.has(ae)||(Be.remove(),T.delete(ae));let le=z.filter(ae=>!T.has(ae));if(le.length===0)return;[...new DOMParser().parseFromString(`<svg xmlns="${pe}">${le.join("")}</svg>`,"image/svg+xml").documentElement.children].forEach((ae,Be)=>{let Le=e.ownerDocument.importNode(ae,!0);M.appendChild(Le),T.set(le[Be],Le)})}function V(N){n=N,o.update(n),i=Ne(n),d=xo(n,i,l()),E()}function X(N){let z=e.getBoundingClientRect();return{x:N.clientX-z.left,y:N.clientY-z.top}}let te=0,I=0;function fe(){e.classList.add("vd-viewer--interacting"),I&&clearTimeout(I),I=setTimeout(()=>{I=0,e.classList.remove("vd-viewer--interacting")},180)}function we(){te&&(cancelAnimationFrame(te),te=0),H(),t.onCameraChange?.(u)}function Se(N){u=N,we()}function me(N){u=N,fe(),!te&&(te=requestAnimationFrame(()=>{te=0,H(),t.onCameraChange?.(u)}))}let ue=null,S=null,g=!1,$=p&&x==="always",L=new Map,B=null,q=()=>{let[N,z]=[...L.values()];return!N||!z?null:{mid:{x:(N.x+z.x)/2,y:(N.y+z.y)/2},distance:Math.hypot(N.x-z.x,N.y-z.y)}},F=N=>{let z=L.get(N.pointerId);if(!z)return;let de=X(N);if(L.set(N.pointerId,de),L.size===1){me(St(u,de.x-z.x,de.y-z.y));return}let le=q();if(B&&le){let Te=St(u,le.mid.x-B.mid.x,le.mid.y-B.mid.y);me(B.distance>0?go(Te,le.mid,le.distance/B.distance):Te)}B=le},ne=N=>{L.delete(N.pointerId)&&(e.hasPointerCapture(N.pointerId)&&e.releasePointerCapture(N.pointerId),B=q())},ke=N=>{if(x==="modifier"&&!N.ctrlKey&&!N.metaKey)return;N.preventDefault();let z=X(N),de=N.deltaMode===1?iv:N.deltaMode===2?e.clientHeight||800:1,le=N.deltaX*de,Te=N.deltaY*de;if(N.ctrlKey||N.metaKey){let ae=N.ctrlKey?ov:av,Be=Math.max(-lp,Math.min(lp,Te));me(go(u,z,Math.exp(-Be*ae)));return}if(N.shiftKey&&le===0){me(St(u,-Te,0));return}me(St(u,-le,-Te))},Me=N=>{if(N.pointerType==="touch"){if(!$)return;N.preventDefault(),L.set(N.pointerId,X(N)),e.setPointerCapture(N.pointerId),B=q();return}(N.button===1||N.button===0&&g)&&(N.preventDefault(),ue=N.pointerId,S=X(N),e.setPointerCapture(N.pointerId))},_e=N=>{if(N.pointerType==="touch"){F(N);return}if(ue!==N.pointerId||!S)return;let z=X(N);me(St(u,z.x-S.x,z.y-S.y)),S=z},We=N=>{if(N.pointerType==="touch"){ne(N);return}ue===N.pointerId&&(ue=null,S=null,e.hasPointerCapture(N.pointerId)&&e.releasePointerCapture(N.pointerId))},G=N=>{N.code==="Space"&&(g=!0)},Z=N=>{N.code==="Space"&&(g=!1)};$&&(e.style.touchAction="none"),p&&(e.addEventListener("wheel",ke,{passive:!1}),e.addEventListener("pointerdown",Me),e.addEventListener("pointermove",_e),e.addEventListener("pointerup",We),e.addEventListener("pointercancel",We),e.ownerDocument.addEventListener("keydown",G),e.ownerDocument.addEventListener("keyup",Z)),H(),E();let Y={element:e,surface:y,update:V,getDocument:()=>n,getScene:()=>d,setTime(N){N===null&&D===null||(D=N,E(!1))},getTime:()=>D,getResolution:()=>i,getMeasurer:()=>a,setFonts(N){o.destroy(),o=r(N),V(n)},getCamera:()=>u,setCamera:Se,zoomBy(N,z){let de=e.getBoundingClientRect(),le=z??{x:de.width/2,y:de.height/2};Se(go(u,le,N))},fitToContent(N=32){let z=e.getBoundingClientRect();Se(tn({x:d.x,y:d.y,width:d.width,height:d.height},{width:z.width||d.width,height:z.height||d.height},N))},screenToDocument:N=>Ta(u,N),documentToScreen:N=>gl(u,N),pointerPoint:X,hitTest(N,z){for(let de=d.items.length-1;de>=0;de--){let le=d.items[de];if(le&&vv(le,N,yv/u.zoom)&&(!z||z(le.id)))return le.id}return null},linkAt(N,z){for(let de=d.items.length-1;de>=0;de--){let le=d.items[de];if(le?.kind!=="text"||z&&!z(le.id))continue;let Te=le.rotation===0?N:Ze(N,{x:le.x+le.w/2,y:le.y+le.h/2},-le.rotation);for(let ae of le.lines){if(Te.y<ae.y||Te.y>ae.y+ae.h)continue;let Be=ae.spans.find(Le=>Te.x>=Le.x&&Te.x<=Le.x+Le.w);if(Be)return Be.style.link}}},itemOf:N=>d.items.find(z=>z.id===N),elementOf:N=>w.get(N),destroy(){p&&(e.removeEventListener("wheel",ke),e.removeEventListener("pointerdown",Me),e.removeEventListener("pointermove",_e),e.removeEventListener("pointerup",We),e.removeEventListener("pointercancel",We),e.ownerDocument.removeEventListener("keydown",G),e.ownerDocument.removeEventListener("keyup",Z)),te&&cancelAnimationFrame(te),I&&clearTimeout(I),te=0,I=0,o.destroy(),e.classList.remove("vd-viewer--interacting"),y.remove(),w.clear(),e.classList.remove("vd-viewer")}};return t.autoFit&&Y.fitToContent(),Y}var sv="vd-clip-";function lv(e){return sv+e}function up(e){return`url(#${lv(e)})`}function dp(e){return ml(e)||e.pose!==void 0?"g":vl(e)}function vl(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 dv(e,t){if(e.tagName!=="g"){fp(e,t);return}Ce(e,"clip-path",t.clip===void 0?null:up(t.clip)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend;let n=t.pose;Ce(e,"opacity",n&&n.opacity<1?String(n.opacity):null);let r=e.firstElementChild;if((!r||r.tagName!==vl(t))&&(r?.remove(),r=e.ownerDocument.createElementNS(pe,vl(t)),e.appendChild(r)),fp(r,{...t,clip:void 0,blend:"normal"}),n){let o=t.rotation===0?"":` ${Aa(t)}`;oe(r,"transform",`${hl(n)}${o}`),t.kind==="vector"&&fv(r,t)}}function fv(e,t){let n=t.pose?.trace;if(n!==void 0&&t.stroke!==void 0){let o=ia(t.contours)+1;oe(e,"stroke-dasharray",`${o} ${o}`),oe(e,"stroke-dashoffset",String(o*(1-n)))}let r=t.pose?.fillOpacity;Ce(e,"fill-opacity",r!==void 0&&r<1?String(r):null)}function fp(e,t){switch(Ce(e,"clip-path",t.clip===void 0?null:up(t.clip)),Ce(e,"transform",t.rotation===0?null:Aa(t)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend,e.style.filter=t.shadows.length>0?`url(#${Ma}${t.id})`:"",t.kind){case"ellipse":xv(e,t);return;case"frame":uv(e,t);return;case"image":cv(e,t);return;case"rect":hv(e,t);return;case"text":mv(e,t);return;case"vector":gv(e,t);return}}function uv(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)),Ce(e,"fill",t.background??null)}function cv(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)),Ce(e,"opacity",t.opacity<1?String(t.opacity):null),t.href===void 0){oe(e,"class","vd-viewer__missing"),Ce(e,"rx",t.radius>0?String(t.radius):null);return}oe(e,"href",t.href),oe(e,"preserveAspectRatio",pv[t.fit])}var pv={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"};function mv(e,t){Ce(e,"opacity",t.opacity<1?String(t.opacity):null),oe(e,"xml:space","preserve");let n=t.lines.flatMap(o=>o.spans).filter(o=>o.text!==""),r=e.ownerDocument;for(;e.childNodes.length>n.length;)e.lastChild?.remove();for(;e.childNodes.length<n.length;)e.appendChild(r.createElementNS(pe,"tspan"));n.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),Ce(i,"font-weight",o.style.weight===400?null:String(o.style.weight)),Ce(i,"font-style",o.style.italic?"italic":null),Ce(i,"letter-spacing",o.style.letterSpacing===0?null:String(o.style.letterSpacing)),Ce(i,"data-vd-link",o.style.link??null);let l=[o.style.underline?"underline":"",o.style.strike?"line-through":""].filter(Boolean).join(" ");Ce(i,"text-decoration",l===""?null:l)})}function hv(e,t){Ce(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),Ce(e,"rx",t.radius>0?String(t.radius):null),Ce(e,"stroke",t.stroke??null),Ce(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),Ce(e,"opacity",t.opacity<1?String(t.opacity):null)}function cp(e,t){oe(e,"fill",t.fill),Ce(e,"stroke",t.stroke??null),Ce(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),Ce(e,"opacity",t.opacity<1?String(t.opacity):null)}function xv(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)),cp(e,t)}function gv(e,t){oe(e,"d",t.d),cp(e,t),Ce(e,"fill-rule",t.rule==="nonzero"?null:t.rule),Ce(e,"stroke-linecap",t.cap==="butt"?null:t.cap),Ce(e,"stroke-linejoin",t.join==="miter"?null:t.join)}function oe(e,t,n){e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Ce(e,t,n){n===null?e.hasAttribute(t)&&e.removeAttribute(t):oe(e,t,n)}var yv=4;function vv(e,t,n){let r=e.rotation===0?t:Ze(t,{x:e.x+e.w/2,y:e.y+e.h/2},-e.rotation),o=r.x>=e.x&&r.x<=e.x+e.w&&r.y>=e.y&&r.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=(r.x-(e.x+e.w/2))/i,u=(r.y-(e.y+e.h/2))/l;return d*d+u*u<=1}if(e.kind==="vector"){let a=e.stroke!==void 0&&e.strokeWidth>0;return os(e.contours,r,{fill:e.fill!=="none",rule:e.rule,reach:(a?e.strokeWidth/2:0)+n})}return o}var G1=bl(ua),W1=bl(ca),bv=bl(pa);function bl(e){return`cubic-bezier(${e.join(", ")})`}function wl(e,t){let n=e.root.id;if(n===t)return e;let r=o=>{if(!be(o))return o;let a=ht(o.expr);return!a.ok||!$n(a.ast).nodes.includes(n)?o:{expr:uo(en(a.ast,i=>i===n?t:void 0))}};return{...e,root:{...pp(e.root,r),id:t}}}function pp(e,t){let n=e,r={};for(let[o,a]of Object.entries(n)){if(o==="children"&&Array.isArray(a)){r[o]=a.map(i=>pp(i,t));continue}r[o]=t(a)}return r}var _l=["nw","n","ne","e","se","s","sw","w"],bo=["nw","ne","se","sw"];function Oa(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 fr(e){let t=e.includes("w")?0:e.includes("e")?1:.5,n=e.includes("n")?0:e.includes("s")?1:.5;return{u:t,v:n}}function Sl(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 vo=1;function It(e,t,n,r){let{x:o,y:a,w:i,h:l}=e;if(t.includes("w")){let d=o+i;o=Math.min(o+n,d-vo),i=d-o}if(t.includes("e")&&(i=Math.max(vo,i+n)),t.includes("n")){let d=a+l;a=Math.min(a+r,d-vo),l=d-a}return t.includes("s")&&(l=Math.max(vo,l+r)),{x:o,y:a,w:i,h:l}}function Tn(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 Da(e,t){let n=[];return t.x!==e.x&&n.push("x"),t.y!==e.y&&n.push("y"),t.w!==e.w&&n.push("w"),t.h!==e.h&&n.push("h"),n}function xt(e){if(e.length===0)return null;let t=1/0,n=1/0,r=-1/0,o=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.w),o=Math.max(o,a.y+a.h);return{x:t,y:n,w:r-t,h:o-n}}function El(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 gt(e,t,n){return t>=e.x&&t<=e.x+e.w&&n>=e.y&&n<=e.y+e.h}var ur=7,kl=15,yo=9;function Cl(e){let t=[],n=kl/2;for(let l of bo){let{u:d,v:u}=fr(l);t.push({handle:l,rect:{x:e.x+e.w*d-n,y:e.y+e.h*u-n,w:kl,h:kl}})}let r=n,o=Math.max(0,e.w-r*2),a=Math.max(0,e.h-r*2),i=yo/2;return t.push({handle:"n",rect:{x:e.x+r,y:e.y-i,w:o,h:yo}},{handle:"s",rect:{x:e.x+r,y:e.y+e.h-i,w:o,h:yo}},{handle:"w",rect:{x:e.x-i,y:e.y+r,w:yo,h:a}},{handle:"e",rect:{x:e.x+e.w-i,y:e.y+r,w:yo,h:a}}),t}function hp(e,t,n,r,o){if(o===0)return It(e,t,n,r);let a=Ze({x:n,y:r},{x:0,y:0},-o),i=It(e,t,a.x,a.y),l=rt(e),d=rt(i),u={x:l.x-d.x,y:l.y-d.y},p=Ze(u,{x:0,y:0},o);return{...i,x:i.x+u.x-p.x,y:i.y+u.y-p.y}}function mp(e,t){return Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI}function xp(e,t,n,r,o){let a=mp(e,n)-mp(e,t);return o?Math.round((r+a)/o)*o-r:a}function gp(e,t,n){return e.map(r=>{let o=rt(r.frame),a=Ze(o,t,n);return{id:r.id,frame:{...r.frame,x:a.x-r.frame.w/2,y:a.y-r.frame.h/2},rotation:lo(r.rotation+n)}})}function yp(e,t,n,r){let o=n.w===0?1:r.w/n.w,a=n.h===0?1:r.h/n.h,i=t*Math.PI/180,l=Math.cos(i),d=Math.sin(i),u=e.w*Math.hypot(o*l,a*d),p=e.h*Math.hypot(o*d,a*l),x=rt(e),y=r.x+(x.x-n.x)*o,k=r.y+(x.y-n.y)*a;return{x:y-u/2,y:k-p/2,w:u,h:p}}function Re(e,t){return`${e}:${t}`}function Na(e){let[t,n]=e.split(":").map(Number);if(!(t===void 0||n===void 0||!Number.isInteger(t)||!Number.isInteger(n)))return{contour:t,index:n}}function vp(e){let t=e.split(":"),n=t[2],r=Na(t.slice(0,2).join(":"));if(!(!r||n!=="in"&&n!=="out"))return{...r,side:n}}function Al(e,t){let n=Na(t);return n?e[n.contour]?.anchors[n.index]:void 0}function $l(e,t){let n=[];for(let r of t){let o=Na(r);o&&e[o.contour]?.anchors[o.index]&&n.push(Re(o.contour,o.index))}return n}function Tl(e){return e.flatMap((t,n)=>t.anchors.map((r,o)=>Re(n,o)))}function Ml(e,t,n,r){return e.map((o,a)=>a===t?{...o,anchors:o.anchors.map((i,l)=>l===n?r:i)}:o)}var wo=(e,t,n)=>({x:e.x+t,y:e.y+n});function Ra(e,t,n,r){return e.map((o,a)=>({...o,anchors:o.anchors.map((i,l)=>t.has(Re(a,l))?kt(wo(i,n,r),i.in&&wo(i.in,n,r),i.out&&wo(i.out,n,r)):i)}))}function Pa(e){if(!e.in||!e.out)return!1;let t=e.in.x-e.x,n=e.in.y-e.y,r=e.out.x-e.x,o=e.out.y-e.y,a=Math.hypot(t,n),i=Math.hypot(r,o);return a===0||i===0?!1:(t*r+n*o)/(a*i)<-.995}function Ia(e,t,n,r,o,a){let i=e[t]?.anchors[n];if(!i)return[...e];let d=i[r==="in"?"out":"in"];if(a.smooth&&!a.breakSmooth&&d){let p=Math.hypot(d.x-i.x,d.y-i.y),x=o.x-i.x,y=o.y-i.y,k=Math.hypot(x,y);k>0&&(d={x:i.x-x/k*p,y:i.y-y/k*p})}let u=r==="in"?kt(i,o,d):kt(i,d,o);return Ml(e,t,n,u)}function bp(e,t){let n=Na(t),r=n?e[n.contour]:void 0,o=r?.anchors[n?.index??-1];if(!n||!r||!o)return[...e];if(o.in||o.out)return Ml(e,n.contour,n.index,kt(o));let a=r.anchors.length,i=n.index>0?r.anchors[n.index-1]:r.closed?r.anchors[a-1]:void 0,l=n.index<a-1?r.anchors[n.index+1]:r.closed?r.anchors[0]:void 0;if(!i&&!l)return[...e];let d=i??o,u=l??o,p=u.x-d.x,x=u.y-d.y,y=Math.hypot(p,x);if(y===0)return[...e];p/=y,x/=y;let k=i?Math.hypot(o.x-i.x,o.y-i.y)/3:0,M=l?Math.hypot(l.x-o.x,l.y-o.y)/3:0,v=i?{x:o.x-p*k,y:o.y-x*k}:void 0,w=l?{x:o.x+p*M,y:o.y+x*M}:void 0;return Ml(e,n.contour,n.index,kt(o,v,w))}function wp(e,t){let n=[];return e.forEach((r,o)=>{let a=r.anchors.filter((i,l)=>!t.has(Re(o,l)));a.length>=2&&n.push({closed:r.closed,anchors:a})}),n}function kp(e,t,n,r,o,a,i){let l=e[t];if(!l)return[...e];let d=l.anchors.length,u=(n+1)%d;if(i)return Ra(e,new Set([Re(t,n),Re(t,u)]),o,a);let p=Math.min(.85,Math.max(.15,r)),x=1/(3*(1-p)*p),y=l.anchors[n],k=l.anchors[u],M=wo(y.out??y,o*x,a*x),v=wo(k.in??k,o*x,a*x),w=Ia(e,t,n,"out",M,{smooth:Pa(y),breakSmooth:!1});return w=Ia(w,t,u,"in",v,{smooth:Pa(k),breakSmooth:!1}),w}function _p(e,t){return e.map((n,r)=>n.closed||n.anchors.length<2?n:t.size===0||t.has(Re(r,0))&&t.has(Re(r,n.anchors.length-1))?{...n,closed:!0}:n)}function Ll(e,t){let n=[],r=new Set,o=(a,i,l)=>{let d=e[a]?.anchors[i],u=d?.[l],p=`${Re(a,i)}:${l}`;!d||!u||r.has(p)||(r.add(p),n.push({key:p,at:u,anchor:d}))};return e.forEach((a,i)=>{let l=a.anchors.length;a.anchors.forEach((d,u)=>{if(!t.has(Re(i,u)))return;o(i,u,"in"),o(i,u,"out");let p=u>0?u-1:a.closed?l-1:-1,x=u<l-1?u+1:a.closed?0:-1;p>=0&&o(i,p,"out"),x>=0&&o(i,x,"in")})}),n}function ko(e,t){let n=t.x-e.x,r=t.y-e.y,o=Math.round(Math.atan2(r,n)/(Math.PI/4))*(Math.PI/4),a=n*Math.cos(o)+r*Math.sin(o);return{x:e.x+Math.cos(o)*a,y:e.y+Math.sin(o)*a}}function Sp(e){return{closed:e.closed,anchors:[...e.anchors].reverse().map(t=>kt(t,t.out,t.in))}}function Ol(e){if(!e)return null;for(let t of e.items){if(t.kind!=="file"||!t.type.startsWith("image/"))continue;let n=t.getAsFile();if(n)return n}return null}async function Fa(e,t){let n;try{n=await createImageBitmap(e)}catch{return null}try{let r=Math.min(1,t/Math.max(n.width,n.height));return r>=1?{bytes:new Uint8Array(await e.arrayBuffer()),type:e.type||"image/png",width:n.width,height:n.height}:await Sv(n,r,e.type)}finally{n.close()}}async function Sv(e,t,n){let r=Math.max(1,Math.round(e.width*t)),o=Math.max(1,Math.round(e.height*t)),a=document.createElement("canvas");a.width=r,a.height=o;let i=a.getContext("2d");if(!i)return null;i.drawImage(e,0,0,r,o);let l=n==="image/png"?"image/png":"image/webp",d=await new Promise(u=>{a.toBlob(u,l,.9)});return d?{bytes:new Uint8Array(await d.arrayBuffer()),type:d.type||l,width:r,height:o}:null}function Ep(e,t,n,r){let o=Math.min(1,n/e,r/t);return{w:Math.round(e*o),h:Math.round(t*o)}}function Ba(e){let t=$t(e);return e.root.children.filter(n=>t.has(n.id)&&kn(e.motion?.[n.id])).map(n=>n.id)}function Ha(e,t,n){let r=Ba(e);if(r.length===0)return null;let o=lt(e);for(let a of t){let i=o.get(a);if(i!==void 0&&r.includes(i))return i}return n!==null&&r.includes(n)?n:r[0]??null}var Ev=1e3/30;var Cv=/\.(?:mp3|m4a|aac|wav|ogg|oga|opus|flac|webm)$/i;function Cp(e){return e.type.startsWith("audio/")||e.type===""&&Cv.test(e.name)}var Mv=new Set(["loop","step","together"]);function Mp(e,t,n){let r=e.motion?.[t]?.music?.asset;if(r!==void 0&&e.assets[r]===void 0)return r;let o=n.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"music";if((!/^[a-z]/.test(o)||Mv.has(o))&&(o=`track-${o}`),e.assets[o]===void 0)return o;for(let a=2;;a+=1)if(e.assets[`${o}-${a}`]===void 0)return`${o}-${a}`}function Ap(e,t,n,r){let o=e.motion?.[t]??{lines:[]},a=o.music,i={asset:n};if(a&&a.asset===n)i=a;else if(a){let l={...a,asset:n};delete l.from,i=l}return[{op:"setAsset",name:n,value:r},{op:"setMotion",page:t,value:{...o,music:i}}]}var Av={left:"x",hcenter:"x",right:"x",top:"y",vcenter:"y",bottom:"y"};function Ua(e){return Av[e]}function $v(e,t,n){switch(e){case"left":return t.x;case"hcenter":return t.x+(t.w-n)/2;case"right":return t.x+t.w-n;case"top":return t.y;case"vcenter":return t.y+(t.h-n)/2;case"bottom":return t.y+t.h-n}}function Dl(e,t,n){let r=Ua(n),o=new Map;for(let a of e){let i=r==="x"?a.frame.w:a.frame.h,l=r==="x"?a.frame.x:a.frame.y;o.set(a.id,$v(n,t,i)-l)}return o}var $p=[{key:"nw",sx:0,sy:0},{key:"ne",sx:1,sy:0},{key:"se",sx:1,sy:1},{key:"sw",sx:0,sy:1}],Tv={id:"radius",prop:"radius",handles(e,t,n){let r=this.max(e),o=Math.min(Math.max(t,n),Math.max(r,n));return $p.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,n){let r=Ov(t);if(!r)return 0;let o=e.x+(r.sx===0?0:e.w),a=e.y+(r.sy===0?0:e.h),i=Math.max(0,r.sx===0?n.x-o:o-n.x),l=Math.max(0,r.sy===0?n.y-a:a-n.y);return Math.min((i+l)/2,this.max(e))},max(e){return Math.max(0,Math.min(e.w,e.h)/2)}},Lv={canvas:[],frame:[],group:[],rect:[Tv]};function _o(e){return Lv[e.type]??[]}function Va(e,t){let n=t.split(":")[0];return _o(e).find(r=>r.id===n)}function Ov(e){let t=e.split(":")[1];return $p.find(n=>n.key===t)}var Pl=[["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 Il=[["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 Nl=[["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 Rl=[["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 Fl=[["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 Bl=[["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 Hl=[["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 Ul=[["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 Vl=[["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 zl=[["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 jl=[["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 ql=[["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 Kl=[["circle",{cx:"15",cy:"9",r:"7"}],["circle",{cx:"9",cy:"15",r:"7"}]];var Gl=[["path",{d:"M20 6 9 17l-5-5"}]];var Wl=[["path",{d:"m6 9 6 6 6-6"}]];var Xl=[["path",{d:"m9 18 6-6-6-6"}]];var Yl=[["circle",{cx:"12",cy:"12",r:"10"}]];var Jl=[["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 Zl=[["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 Ql=[["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 ed=[["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 td=[["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 nd=[["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 rd=[["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 od=[["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 za=[["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 ad=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}]];var id=[["path",{d:"M12 11.4V9.1"}],["path",{d:"m12 17 6.59-6.59"}],["path",{d:"m15.05 5.7-.218-.691a3 3 0 0 0-5.663 0L4.418 19.695A1 1 0 0 0 5.37 21h13.253a1 1 0 0 0 .951-1.31L18.45 16.2"}],["circle",{cx:"20",cy:"9",r:"2"}]];var sd=[["path",{d:"M5 12h14"}]];var ld=[["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 dd=[["path",{d:"m18 8 4 4-4 4"}],["path",{d:"M2 12h20"}],["path",{d:"m6 8-4 4 4 4"}]];var fd=[["path",{d:"M12 2v20"}],["path",{d:"m8 18 4 4 4-4"}],["path",{d:"m8 6 4-4 4 4"}]];var ud=[["path",{d:"M9 18V5l12-2v13"}],["circle",{cx:"6",cy:"18",r:"3"}],["circle",{cx:"18",cy:"16",r:"3"}]];var cd=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"}]];var pd=[["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 md=[["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 hd=[["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 xd=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];var gd=[["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 yd=[["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 vd=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2"}],["circle",{cx:"12",cy:"12",r:"1"}],["path",{d:"M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0"}]];var bd=[["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 wd=[["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 kd=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];var ja=[["path",{d:"M21 5H3"}],["path",{d:"M21 12H9"}],["path",{d:"M21 19H7"}]];var qa=[["path",{d:"M21 5H3"}],["path",{d:"M17 12H7"}],["path",{d:"M19 19H5"}]];var Ka=[["path",{d:"M3 5h18"}],["path",{d:"M3 12h18"}],["path",{d:"M3 19h18"}]];var So=[["path",{d:"M21 5H3"}],["path",{d:"M15 12H3"}],["path",{d:"M17 19H3"}]];var _d=[["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 Sd=[["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 Ed=[["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 Cd=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}],["path",{d:"M16 9a5 5 0 0 1 0 6"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728"}]];var Md=[["path",{d:"M11 4.702a.7.7 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.7.7 0 0 0 11 19.298z"}],["path",{d:"m16.5 14.5 5-5"}],["path",{d:"m16.5 9.5 5 5"}]];var Ad=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var Eo=e=>e.replace(/\b(?:CmdOrCtrl|CommandOrControl)\b/g,"Ctrl");function Tp(e,t){let r=e.ownerDocument.createElement("div");r.className="vd-chrome",r.setAttribute("role","toolbar"),r.setAttribute("aria-label","Canvas tools"),r.innerHTML=Dv(t),e.appendChild(r);let o=new Map;for(let p of r.querySelectorAll("[data-tool]"))o.set(p.dataset.tool,p);let a=r.querySelector('[data-act="undo"]'),i=r.querySelector('[data-act="redo"]'),l=r.querySelector('[data-act="zoom"]'),d=p=>{let x=p.target?.closest("button");if(!x)return;p.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}},u=p=>p.stopPropagation();return r.addEventListener("click",d),r.addEventListener("pointerdown",u),{element:r,setTool(p){for(let[x,y]of o)y.setAttribute("aria-pressed",String(x===p))},setHistory(p,x){a&&(a.disabled=!p),i&&(i.disabled=!x)},setZoom(p){l&&(l.textContent=`${Math.round(p*100)}%`)},destroy(){r.removeEventListener("click",d),r.removeEventListener("pointerdown",u),r.remove()}}}function Dv(e){let t=e.formatKeys??Eo;return[Nt({tool:"select",label:"Select",hint:"V",icon:"select"}),Nt({tool:"frame",label:"Frame",hint:"F",icon:"frame"}),Nt({tool:"rect",label:"Rectangle",hint:"R",icon:"rect"}),Nt({tool:"ellipse",label:"Ellipse",hint:"O",icon:"ellipse"}),Nt({tool:"pen",label:"Pen",hint:"P",icon:"pen"}),Nt({tool:"text",label:"Text",hint:"T",icon:"text"}),'<span class="vd-chrome__divider"></span>',Nt({act:"undo",label:"Undo",hint:t("CmdOrCtrl+Z"),icon:"undo"}),Nt({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>',Nt({act:"play",label:"Play",hint:e.playHint,icon:"play"})]:[]].join("")}function Nt(e){let t=e.tool?`data-tool="${e.tool}"`:`data-act="${e.act??""}"`,n=e.tool?' aria-pressed="false"':"";return`<button type="button" class="vd-chrome__tool" ${t}${n} title="${e.hint?`${e.label} \xB7 ${e.hint}`:e.label}" aria-label="${e.label}">`+Ge(e.icon)+"</button>"}var Pv={select:ld,frame:td,rect:kd,ellipse:Yl,pen:pd,vector:bd,text:_d,undo:Sd,redo:gd,"align-left":Ul,"align-hcenter":Nl,"align-right":Fl,"align-top":Hl,"align-vcenter":Il,"align-bottom":Rl,"distribute-h":Bl,"distribute-v":Vl,group:nd,image:rd,eye:Zl,"eye-off":Ql,lock:ad,unlock:za,chevron:Xl,"text-left":So,"text-center":qa,"text-right":ja,"text-justify":Ka,"text-top":ql,"text-middle":zl,"text-bottom":jl,unlink:Ed,rotate:yd,opacity:Jl,radius:wd,blend:Kl,plus:xd,minus:sd,close:Ad,"chevron-down":Wl,check:Gl,link:od,"font-size":Pl,"line-height":fd,"letter-spacing":dd,eyedropper:md,document:ed,play:hd,pause:cd,scan:vd,music:ud,metronome:id,sound:Cd,"sound-off":Md};function Ge(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">${Pv[e].map(([n,r])=>{let o=Object.entries(r).filter(([a])=>a!=="key").map(([a,i])=>` ${a}="${String(i)}"`).join("");return`<${n}${o} vector-effect="non-scaling-stroke"/>`}).join("")}</svg>`}var $d="clipboard";function Co(e,t){let n=new Set(t),r=[];return se(e.root,o=>{if(o.id!==e.root.id&&n.has(o.id))return r.push(o),!1}),r}function Lp(e,t){let n={};for(let a of e)se(a,i=>{for(let[l,d]of Object.entries(i)){if(be(d)){let u=ht(d.expr);if(!u.ok)continue;for(let p of $n(u.ast).tokens){let x=t[p];x!==void 0&&(n[p]=x)}continue}typeof d=="string"&&o(d),l==="shadow"&&typeof d=="string"&&r(d)}for(let l of Dp(i.content))o(l)});return n;function r(a){let i=t[a],d=ar(typeof i=="string"?i:a);if(!("error"in d))for(let u of d.shadows)o(u.colour)}function o(a){for(let i of xa(a)){let l=t[i];if(l!==void 0&&(n[i]=l,!(typeof l!="string"||l===a)))for(let d of xa(l)){let u=t[d];u!==void 0&&d!==i&&(n[d]=u)}}}}function Iv(e,t){let n={};for(let r of e)se(r,o=>{if(o.type!=="image"||typeof o.src!="string")return;let a=t[o.src];a!==void 0&&(n[o.src]=a)});return n}function Op(e,t){let n={},r=o=>{if(typeof o!="string")return;let a=t[o];a!==void 0&&(n[o]=a)};for(let o of e)se(o,a=>{let i=a;r(i.font);for(let l of Dp(i.content,"font"))r(l)});return n}function Dp(e,t="fill"){if(!Array.isArray(e))return[];let n=[];for(let r of e){if(typeof r=="string")continue;let o=r[t];o!==void 0&&n.push(o)}return n}function Td(e,t,n){let r=Co(e,t);if(r.length===0)return null;let o={};for(let l of r)se(l,d=>{let u=n.nodes.get(d.id)?.values;u&&Object.keys(u).length>0&&(o[d.id]=u)});let a={version:e.version,kind:e.kind,tokens:Lp(r,e.tokens),fonts:Op(r,e.fonts),assets:Iv(r,e.assets),root:{...e.root,children:r}},i=JSON.parse(ts(a));return i[$d]={resolved:o},JSON.stringify(i,null,2)}function Ld(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!="object"||t===null)return null;let n=t;if(typeof n.root!="object"||n.root===null)return null;let{document:r}=Is(t),o=r.root.children;if(o.length===0)return null;let a=n[$d],i=typeof a=="object"&&a!==null?a.resolved??{}:{};return{nodes:o,tokens:r.tokens,fonts:r.fonts,resolved:typeof i=="object"&&i!==null?i:{}}}function Od(e,t){let n=ea(t.root),r=new Map;for(let i of e.nodes)se(i,l=>{let d=Nv(l.id,n);n.add(d),r.set(l.id,d)});let o=i=>n.has(i),a={...e.tokens,...t.tokens};return{nodes:e.nodes.map(i=>Pp(i,{payload:e,remap:r,exists:o,tokens:a})),remap:r}}function Nv(e,t){let n=e.lastIndexOf("."),r=n===-1?"":e.slice(n+1),o=/^[0-9]+$/.test(r)?e.slice(0,n):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 Pp(e,t){let n=e,r={};for(let[o,a]of Object.entries(n))o==="id"||o==="children"||(r[o]=be(a)?Rv(a.expr,e.id,o,t):a);return r.id=t.remap.get(e.id)??e.id,ye(e)&&(r.children=re(e).map(o=>Pp(o,t))),r}function Rv(e,t,n,r){let o={expr:e},a=ht(e);if(!a.ok)return o;let i=$n(a.ast).nodes.some(p=>r.remap.has(p)),l=i?en(a.ast,p=>r.remap.get(p)):a.ast,d=$n(l);if(d.nodes.some(p=>!r.exists(p))||d.tokens.some(p=>r.tokens[p]===void 0)){let p=r.payload.resolved[t]?.[n];return p===void 0?o:p}return i?{expr:uo(l)}:o}var Rt="#ffffff",nn="#0b0d0c",Bp="#c6ff3d",Fv="#ffb224";var Ip=new Map;function Fe(e,t={}){let n=t.badge??"none",r=e==="resize"?Hp(t.angle??0):e==="rotate"?Hv(t.angle??0):0,o=`${e}:${r}:${n}`,a=Ip.get(o);if(a!==void 0)return a;let{at:i,fallback:l}=Bv[e],d=zv(Uv(e,r,n),i[0],i[1],l);return Ip.set(o,d),d}var Np=[2,2],cr=[12,12],Bv={arrow:{at:Np,fallback:"default"},radius:{at:Np,fallback:"default"},resize:{at:cr,fallback:"ew-resize"},rotate:{at:cr,fallback:"crosshair"},crosshair:{at:cr,fallback:"crosshair"},grab:{at:cr,fallback:"grab"},grabbing:{at:cr,fallback:"grabbing"},text:{at:cr,fallback:"text"}};function Hv(e){let t=(e%360+360)%360;return Math.round(t/15)*15%360}function Hp(e){let t=(e%180+180)%180;return Math.round(t/15)*15%180}function Uv(e,t,n){switch(e){case"arrow":return Up(n);case"resize":return jv(t,n);case"rotate":return qv(t);case"crosshair":return Gv();case"grab":return Fp(!1);case"grabbing":return Fp(!0);case"radius":return Wv(n);case"text":return Kv()}}function Vv(e){return`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">${e}</svg>`}function zv(e,t,n,r){return`url("data:image/svg+xml,${encodeURIComponent(Vv(e))}") ${t} ${n}, ${r}`}var Rp="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 Up(e){return`<path d="${Rp}" fill="${Rt}" stroke="${Rt}" stroke-width="3" stroke-linejoin="round"/><path d="${Rp}" fill="${nn}"/>`+Vp(e)}function jv(e,t){let n=["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"],r=(o,a)=>n.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">`+r(3.6,Rt)+r(1.6,nn)+"</g>"+Vp(t)}function qv(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"],n=(r,o)=>t.map(a=>`<path d="${a}" stroke="${o}" stroke-width="${r}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+n(3.6,Rt)+n(1.6,nn)+"</g>"}function Kv(){let e=["M12 4.5 V19.5","M9 4.5 H15","M9 19.5 H15"],t=(n,r)=>e.map(o=>`<path d="${o}" stroke="${r}" stroke-width="${n}"/>`).join("");return'<g fill="none" stroke-linecap="round">'+t(3.4,Rt)+t(1.5,nn)+"</g>"}function Gv(){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="${Rt}" stroke-width="3"/><path d="${e}" stroke="${nn}" stroke-width="1.2"/></g>`}function Fp(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="${Rt}" stroke-width="3.4"/><path d="${t}" stroke="${nn}" stroke-width="1.5"/></g>`}function Wv(e){return Up("none")+Xv(e)}function Xv(e){return`<g><rect x="17.5" y="17.5" width="14" height="14" rx="4.5" fill="${Rt}"/><rect x="18.7" y="18.7" width="11.6" height="11.6" rx="3.4" fill="${e==="none"?Bp:Fv}"/><path d="M21.6 27.9 V25.4 A3.8 3.8 0 0 1 25.4 21.6 H27.9" fill="none" stroke="${nn}" stroke-width="1.5" stroke-linecap="round"/></g>`}function Vp(e){return e==="none"?"":`<g><rect x="18.5" y="18.5" width="13" height="13" rx="4" fill="${Rt}"/><rect x="19.6" y="19.6" width="10.8" height="10.8" rx="3" fill="${Bp}"/><text x="25" y="28.4" text-anchor="middle" fill="${nn}" font-family="ui-sans-serif, system-ui, -apple-system, Helvetica, sans-serif" font-size="10" font-weight="700">${e==="token"?"$":"\u0192"}</text></g>`}function je(e,t){let n=[],r=o=>{if(n.push(o.id),o.id===t)return!0;for(let a of re(o))if(r(a))return!0;return n.pop(),!1};return r(e)?n:[]}function Ga(e,t,n){let r=je(t.root,e);if(r.length===0)return e;let o=n!==null&&r.includes(n)?n:Yv(r,t),a=r.indexOf(o);return a===-1?e:r[a+1]??e}function Yv(e,t){for(let n=e.length-2;n>=0;n-=1){let r=e[n];if(U(t.root,r)?.type==="frame")return r}return t.root.id}function zp(e,t){let n=e.map(o=>je(t.root,o)).filter(o=>o.length>0);if(n.length===0)return t.root.id;let r=t.root.id;for(let o=0;;o+=1){let a=n[0]?.[o];if(a===void 0||n.some(i=>i[o]!==a||o===i.length-1))break;r=a}return r}function Ln(e,t){let n=U(t.root,e);if(!n)return[];let r=[],o=a=>{if(Oe(a)){for(let i of re(a))o(i);return}r.push(a.id)};return o(n),r}function On(e,t,n){let r=U(t.root,e);if(!r)return;if(!Oe(r)){let i=n.nodes.get(e);return i?Mo(i):void 0}let o=[],a=i=>{if(!(i.id!==e&&"hidden"in i&&i.hidden===!0)){if(i.id!==e&&!Oe(i)){let l=On(i.id,t,n);l&&o.push(l);return}for(let l of re(i))a(l)}};return a(r),xt(o)??void 0}function Mo(e){let t={x:e.absX,y:e.absY,w:e.w,h:e.h},n=e.values.rotation??0;return n===0?t:so(t,n)}function Ao(e,t,n){return t.flatMap(r=>{let o=On(r,e,n);return o?[{id:r,frame:o}]:[]})}function Dd(e,t){let n=t.filter(x=>x!==e.root.id&&U(e.root,x));if(n.length<2)return null;let r=zp(n,e),o=U(e.root,r);if(!o)return null;let a=re(o),i=new Set(n.map(x=>Ga(x,e,r))),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),u=Wt(e.root,"group"),p=[{op:"insert",parent:r,index:d+1,node:Vi({id:u,children:[]})}];return l.forEach((x,y)=>{p.push({op:"move",id:x.id,parent:u,index:y})}),{ops:p,groupId:u}}function Pd(e,t){let n=U(e.root,t);if(!n||!Oe(n))return[];let r=je(e.root,t),o=r[r.length-2];if(o===void 0)return[];let a=U(e.root,o);if(!a)return[];let i=re(a).findIndex(d=>d.id===t);if(i===-1)return[];let l=re(n).map((d,u)=>({op:"move",id:d.id,parent:o,index:i+u}));return l.push({op:"remove",id:t}),l}function Id(e,t,n){let r=new Map;for(let a of t){let i=je(e.root,a),l=i[i.length-2];if(l===void 0)continue;let d=r.get(l)??new Set;d.add(a),r.set(l,d)}let o=[];for(let[a,i]of r){let l=U(e.root,a);if(!l)continue;let d=re(l).map(u=>u.id);o.push(...Zv(a,d,Jv(d,i,n)))}return o}function Jv(e,t,n){if(n==="front"||n==="back"){let i=e.filter(d=>t.has(d)),l=e.filter(d=>!t.has(d));return n==="front"?[...l,...i]:[...i,...l]}let r=n==="forward"?1:-1,o=[...e],a=o.flatMap((i,l)=>t.has(i)?[l]:[]);r===1&&a.reverse();for(let i of a){let l=i+r,d=o[l];d===void 0||t.has(d)||(o[l]=o[i],o[i]=d)}return o}function Zv(e,t,n){let r=[...t],o=[];for(let a=0;a<n.length;a+=1){let i=n[a];i===void 0||r[a]===i||(r.splice(r.indexOf(i),1),r.splice(a,0,i),o.push({op:"move",id:i,parent:e,index:a}))}return o}function Nd(e,t,n){let r=t.w===0?1:n.w/t.w,o=t.h===0?1:n.h/t.h,a=new Map;for(let[i,l]of e)a.set(i,{x:n.x+(l.x-t.x)*r,y:n.y+(l.y-t.y)*o,w:l.w*r,h:l.h*o});return a}var Rd=6,Ft=.01,ot={dx:0,dy:0,guides:[],measures:[]},Wa=["lo","mid","hi"];function Fd(e,t,n){let r=[],o=(a,i)=>{let l=t.nodes.get(a);l&&r.push({id:a,frame:Mo(l),isPage:i})};return e.root.w!==void 0&&e.root.h!==void 0&&o(e.root.id,!0),se(e.root,a=>{if(n.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}ye(a)||o(a.id,!1)}}),r}function Bd(e,t,n){if(n<=0||t.length===0)return ot;let r=pr("x",e,t,n,Wa,!0),o=pr("y",e,t,n,Wa,!0);return Ud(e,t,r,o)}function Xa(e,t,n,r){if(r<=0||n.length===0)return ot;let o=t.includes("w")?["lo"]:t.includes("e")?["hi"]:[],a=t.includes("n")?["lo"]:t.includes("s")?["hi"]:[],i=pr("x",e,n,r,o,!1),l=pr("y",e,n,r,a,!1);return Ud(e,n,i,l)}function Hd(e,t,n){let r={x:e.x,y:e.y,w:0,h:0};if(n<=0||t.length===0)return ot;let o=pr("x",r,t,n,["lo"],!1),a=pr("y",r,t,n,["lo"],!1);return Ud(r,t,o,a)}function pr(e,t,n,r,o,a){let i={axis:e,delta:0,kind:"none"};if(o.length===0)return i;let l=Qv(e,t,n,r,o),d=a?t0(e,t,n,r):null;return l&&d?Math.abs(d.delta)<Math.abs(l.delta)-Ft?{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 Qv(e,t,n,r,o){let a=null;for(let i of n)for(let l of Wa){let d=ge(i.frame,e,l);for(let u of o){let p=d-ge(t,e,u);if(Math.abs(p)>r)continue;let x=u==="mid"&&l==="mid";(a===null||e0(p,x,a))&&(a={at:d,delta:p,centred:x})}}return a?{at:a.at,delta:a.delta}:null}function e0(e,t,n){let r=Math.abs(e),o=Math.abs(n.delta);return r<o-Ft?!0:r>o+Ft?!1:t&&!n.centred}function t0(e,t,n,r){let o=jp(e,t,n);if(o.length<2)return null;let a=qp(t,e),i=ge(t,e,"lo"),l=[];for(let u of n0(o,e))for(let p of o)l.push({delta:ge(p,e,"hi")+u-i,gap:u}),l.push({delta:ge(p,e,"lo")-u-a-i,gap:u});for(let u=0;u+1<o.length;u+=1){let p=o[u],x=o[u+1];if(!p||!x)continue;let y=ge(x,e,"lo")-ge(p,e,"hi")-a;y<=Ft||l.push({delta:ge(p,e,"hi")+y/2-i,gap:y/2})}let d=null;for(let u of l)Math.abs(u.delta)>r||(d===null||Math.abs(u.delta)<Math.abs(d.delta)-Ft)&&(d=u);return d}function jp(e,t,n){let r=Vd(e);return n.filter(o=>!o.isPage&&a0(o.frame,t,r)).map(o=>o.frame).sort((o,a)=>ge(o,e,"lo")-ge(a,e,"lo"))}function n0(e,t){let n=[];for(let r=0;r+1<e.length;r+=1){let o=e[r],a=e[r+1];if(!o||!a)continue;let i=ge(a,t,"lo")-ge(o,t,"hi");i<=Ft||n.some(l=>Math.abs(l-i)<Ft)||n.push(i)}return n}function Ud(e,t,n,r){let o={...e,x:e.x+n.delta,y:e.y+r.delta},a=[],i=[];for(let l of[n,r]){if(l.kind==="align"&&l.at!==void 0){let d=r0(l.axis,l.at,o,t);d&&a.push(d)}l.kind==="space"&&l.gap!==void 0&&i.push(...o0(l.axis,l.gap,o,t))}return{dx:n.delta,dy:r.delta,guides:a,measures:i}}function r0(e,t,n,r){let o=Vd(e),a=ge(n,o,"lo"),i=ge(n,o,"hi"),l=!1;for(let d of r)Wa.some(u=>i0(ge(d.frame,e,u),t))&&(l=!0,a=Math.min(a,ge(d.frame,o,"lo")),i=Math.max(i,ge(d.frame,o,"hi")));return l?{axis:e,at:t,from:a,to:i}:null}function o0(e,t,n,r){let o=Vd(e),a=[...jp(e,n,r),n].sort((l,d)=>ge(l,e,"lo")-ge(d,e,"lo")),i=[];for(let l=0;l+1<a.length;l+=1){let d=a[l],u=a[l+1];if(!d||!u)continue;let p=ge(u,e,"lo")-ge(d,e,"hi");if(Math.abs(p-t)>Ft)continue;let x=Math.max(ge(d,o,"lo"),ge(u,o,"lo")),y=Math.min(ge(d,o,"hi"),ge(u,o,"hi"));i.push({axis:e,at:(x+y)/2,from:ge(d,e,"hi"),to:ge(u,e,"lo"),label:s0(p)})}return i}function Vd(e){return e==="x"?"y":"x"}function qp(e,t){return t==="x"?e.w:e.h}function ge(e,t,n){let r=t==="x"?e.x:e.y,o=qp(e,t);return n==="lo"?r:n==="hi"?r+o:r+o/2}function a0(e,t,n){return ge(e,n,"lo")<ge(t,n,"hi")&&ge(e,n,"hi")>ge(t,n,"lo")}function i0(e,t){return Math.abs(e-t)<Ft}function s0(e){return String(Math.round(e*100)/100)}var $o=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 n=this.past[this.past.length-1];return n?(this.past[this.past.length-1]={label:t.label,ops:[...n.ops,...t.ops],inverse:[...t.inverse,...n.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 n=this.past.length-t.length;return t.every((r,o)=>this.past[n+o]===r)}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 Kp=1,l0=48,d0=.06,f0=.5;function Gp(e){return Math.max(l0,Math.min(e.width,e.height)*d0)}function zd(e,t){let n=new Set(t),r=[];for(let o of e.root.children)(n.has(o.id)||Wp(o,n))&&r.push(o.id);return r}function Wp(e,t){for(let n of re(e))if(t.has(n.id)||Wp(n,t))return!0;return!1}function Ya(e){let t=e.filter(i=>i.w>0&&i.h>0);if(t.length===0)return null;let n=Math.min(...t.map(i=>i.x)),r=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:n,y:r,w:o-n,h:a-r}}function Ja(e,t){let n=Gp(t),r={width:Math.max(1,t.width-n*2),height:Math.max(1,t.height-n*2)},o=dr(Math.min(r.width/e.w,r.height/e.h,Kp));return{zoom:o,x:t.width/2-(e.x+e.w/2)*o,y:t.height/2-(e.y+e.h/2)*o}}function jd(e,t,n){let r=Ja(e,t);return u0(e,t,n)&&n.zoom>=r.zoom*f0?null:r}function u0(e,t,n){let r=e.x*n.zoom+n.x,o=e.y*n.zoom+n.y,a=(e.x+e.w)*n.zoom+n.x,i=(e.y+e.h)*n.zoom+n.y;return r>=0&&o>=0&&a<=t.width&&i<=t.height}function Xp(e,t,n,r){let o=Math.exp(Math.log(e.zoom)+(Math.log(t.zoom)-Math.log(e.zoom))*n),a={x:r.width/2,y:r.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)*n,y:i.y+(l.y-i.y)*n};return{zoom:o,x:a.x-d.x*o,y:a.y-d.y*o}}function Yp(e){return 1-(1-e)**3}function c0(e){return!("separator"in e)}function qd(e,t=[]){let n=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"},...Jp(e),{separator:!0},{id:"fit",label:"Fit to screen",keys:"Shift+1"},{id:"zoom100",label:"Zoom to 100%",keys:"CmdOrCtrl+0"},...n];let r=[];e.isText&&e.count===1&&r.push({id:"editText",label:"Edit text",keys:"Enter"},{separator:!0}),e.isVector&&e.count===1&&r.push({id:"editPoints",label:"Edit points",keys:"Enter"},{separator:!0}),(e.convertible??0)>0&&r.push({id:"toVector",label:"Convert to vector",keys:"CmdOrCtrl+Shift+O"},{separator:!0}),r.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&&r.push({separator:!0},...o),r.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){r.push({separator:!0});for(let a of e.bound)r.push({id:`detach:${a.prop}`,label:`Detach ${a.prop}`,hint:a.source})}return r.push(...Jp(e)),r.push(...n),r.push({separator:!0},{id:"delete",label:"Delete",keys:"Delete"}),r}var p0=4;function Jp(e){let t=(e.locksHere??[]).slice(0,p0).map(r=>({id:`unlock:${r}`,label:`Unlock ${r}`}));e.anyLocked&&t.push({id:"unlockAll",label:"Unlock all"});let n=e.hiddenCount??0;return n>0&&t.push({id:"showAll",label:`Show all hidden (${n})`}),t.length===0?[]:[{separator:!0},...t]}function Za(e,t){let n=e.ownerDocument,r=t.formatKeys??Eo,o=n.createElement("div");o.className="vd-menu",o.setAttribute("role","menu"),o.hidden=!0,e.appendChild(o);let a=!1,i=[],l=-1;function d(w){o.replaceChildren(),i=[];for(let D of w){if(!c0(D)){let T=n.createElement("div");T.className="vd-menu__separator",o.appendChild(T);continue}let A=n.createElement("button");A.type="button",A.className="vd-menu__item",A.dataset.command=D.id,A.disabled=D.disabled===!0,A.setAttribute("role","menuitem");let H=n.createElement("span");H.textContent=D.label,A.appendChild(H);let E=D.hint??(D.keys===void 0?void 0:r(D.keys));if(E!==void 0){let T=n.createElement("span");T.className="vd-menu__hint",T.textContent=E,A.appendChild(T)}o.appendChild(A),A.disabled||i.push(A)}}function u(w){o.style.left=`${w.x}px`,o.style.top=`${w.y}px`;let D=e.getBoundingClientRect(),A=t.bounds?.()??D,H=o.getBoundingClientRect();if(H.width===0&&H.height===0)return;let E=D.left+w.x+H.width-A.right,T=D.top+w.y+H.height-A.bottom;E>0&&(o.style.left=`${Math.max(A.left-D.left,w.x-H.width)}px`),T>0&&(o.style.top=`${Math.max(A.top-D.top,w.y-H.height)}px`)}function p(w){i.length!==0&&(l=(w+i.length)%i.length,i[l]?.focus())}let x=w=>{let D=w.target?.closest("button");if(!D||D.disabled)return;w.stopPropagation();let A=D.dataset.command;v(),A&&t.onCommand(A)},y=w=>w.stopPropagation(),k=w=>{w.key==="ArrowDown"?(w.preventDefault(),p(l+1)):w.key==="ArrowUp"?(w.preventDefault(),p(l-1)):w.key==="Escape"&&(w.preventDefault(),w.stopPropagation(),v(),t.returnFocus?t.returnFocus():e.focus())},M=w=>{a&&(w.target instanceof Node&&o.contains(w.target)||v())};function v(){a&&(a=!1,l=-1,o.hidden=!0,n.removeEventListener("pointerdown",M,!0),n.removeEventListener("wheel",M,!0))}return o.addEventListener("click",x),o.addEventListener("pointerdown",y),o.addEventListener("keydown",k),{element:o,get isOpen(){return a},open(w,D){d(D),o.hidden=!1,a=!0,u(w),n.addEventListener("pointerdown",M,!0),n.addEventListener("wheel",M,!0),p(0)},close:v,destroy(){v(),o.removeEventListener("click",x),o.removeEventListener("pointerdown",y),o.removeEventListener("keydown",k),o.remove()}}}var mr=2,Zp=1.5,Qp=1.5,em=1.5,dm={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},tm=3.6,m0=22,Qa=14,ei=15,Kd=4,nm=15,rm=23,To=7,h0=3.5,ti=12,x0=4.5,ni=16,at=18,Gd=9,Wd=6.1,om="Drop or double-click",g0=6.4,am=16,rn=3,im=5,y0=11,sm=6,lm=6.4;function fm(e,t){let n=e.ownerDocument,r=n.createElementNS(pe,"svg");r.setAttribute("class","vd-editor__overlay"),e.appendChild(r);let o=[],a=[],i=[],l=[],d=[],u=null,p=null,x=[],y=[];function k(S){let g=t({x:S.x,y:S.y}),$=t({x:S.x+S.w,y:S.y+S.h});return{x:g.x,y:g.y,w:$.x-g.x,h:$.y-g.y}}function M(S){for(;r.firstChild;)r.removeChild(r.firstChild);o=[],a=[],i=[],l=[],d=[],u=null,p=null,x=[],y=(S.pageLabels??[]).flatMap($=>I($));let g=S.turn&&S.turn.angle!==0?{angle:S.turn.angle,centre:t(S.turn.centre)}:null;for(let $ of S.slots??[])we($);S.presence&&Se(S.presence);for(let $ of S.highlight)me("vd-editor__highlight",hr(k($),mr),mr);S.lockHint&&fe(S.lockHint),S.hover&&me("vd-editor__hover",Lo(k(S.hover)),Qp);for(let $ of S.parked)me("vd-editor__parked",Lo(k($)),Qp);for(let $ of S.members)me("vd-editor__member",hr(k($),Zp),Zp);S.lead&&me("vd-editor__lead",Lo(k(S.lead)),mr);for(let $ of S.guides)V($);for(let $ of S.measures)X($);if(v(g,()=>{for(let $ of S.textSelection)r.appendChild(ue("vd-editor__text-selection",k($)))}),S.box&&T(S.box),S.caret&&v(g,()=>A(S.caret)),l=S.rings.map(H),i=S.spacers.map(E),S.badge&&S.box){let $=k(S.box.frame),L=u?Math.max(...[{x:$.x,y:$.y},{x:$.x+$.w,y:$.y},{x:$.x,y:$.y+$.h},{x:$.x+$.w,y:$.y+$.h}].map(B=>Ze(B,u.centre,u.angle).y)):$.y+$.h;te(S.badge,{x:$.x+$.w/2,y:L+Gd+at/2})}if(S.draft){let $=k(S.draft);if(S.draftEllipse){let L=n.createElementNS(pe,"ellipse");L.setAttribute("class","vd-editor__draft"),L.setAttribute("cx",String($.x+$.w/2)),L.setAttribute("cy",String($.y+$.h/2)),L.setAttribute("rx",String(Math.abs($.w)/2)),L.setAttribute("ry",String(Math.abs($.h)/2)),r.appendChild(L)}else r.appendChild(ue("vd-editor__draft",$))}S.marquee&&r.appendChild(ue("vd-editor__marquee",k(S.marquee))),S.path&&(p=g,v(g,()=>D(S.path)))}function v(S,g){if(!S){g();return}let $=r.childNodes.length;g();let L=n.createElementNS(pe,"g");for(L.setAttribute("transform",`rotate(${S.angle} ${S.centre.x} ${S.centre.y})`);r.childNodes.length>$;)L.insertBefore(r.childNodes[r.childNodes.length-1],L.firstChild);r.appendChild(L)}function w(S,g){return g?Ze(S,g.centre,-g.angle):S}function D(S){let g=n.createElementNS(pe,"path");if(g.setAttribute("class","vd-editor__path"),g.setAttribute("d",Tt(Lt(S.contours,t))),r.appendChild(g),S.pending){let L=t(S.pending.from),B=t(S.pending.to),q=S.pending.c1?t(S.pending.c1):L,F=n.createElementNS(pe,"path");F.setAttribute("class","vd-editor__pending"),F.setAttribute("d",`M${L.x} ${L.y} C${q.x} ${q.y} ${B.x} ${B.y} ${B.x} ${B.y}`),r.appendChild(F)}for(let L of S.handles){let B=t(L.at),q=t(L.anchor),F=n.createElementNS(pe,"line");F.setAttribute("class","vd-editor__arm"),F.setAttribute("x1",String(q.x)),F.setAttribute("y1",String(q.y)),F.setAttribute("x2",String(B.x)),F.setAttribute("y2",String(B.y)),r.appendChild(F)}for(let L of S.handles){let B=t(L.at),q=n.createElementNS(pe,"circle");q.setAttribute("class","vd-editor__knob"),q.setAttribute("cx",String(B.x)),q.setAttribute("cy",String(B.y)),q.setAttribute("r",String(h0)),r.appendChild(q)}for(let L of S.anchors){let B=t(L.at),q=ue(L.selected?"vd-editor__anchor vd-editor__anchor--on":"vd-editor__anchor",{x:Math.round(B.x-To/2)+.5,y:Math.round(B.y-To/2)+.5,w:To,h:To});q.setAttribute("data-key",L.key),r.appendChild(q)}if(S.closeAt){let L=t(S.closeAt),B=n.createElementNS(pe,"circle");B.setAttribute("class","vd-editor__close"),B.setAttribute("cx",String(L.x)),B.setAttribute("cy",String(L.y)),B.setAttribute("r",String(To)),r.appendChild(B)}let $=L=>({x:L.x-ti/2,y:L.y-ti/2,w:ti,h:ti});d=[...[...S.handles].reverse().map(L=>({kind:"handle",key:L.key,rect:$(t(L.at))})),...[...S.anchors].reverse().map(L=>({kind:"anchor",key:L.key,rect:$(t(L.at))}))]}function A(S){let g=t({x:S.x,y:S.y}),$=t({x:S.x,y:S.y+S.h}),L=n.createElementNS(pe,"line");L.setAttribute("class","vd-editor__caret");let B=Math.round(g.x)+.5;L.setAttribute("x1",String(B)),L.setAttribute("y1",String(g.y)),L.setAttribute("x2",String(B)),L.setAttribute("y2",String($.y)),S.fill!==void 0&&!S.fill.startsWith("url(")&&(L.style.stroke=S.fill),r.appendChild(L)}function H(S){let g=t(S.at),$=n.createElementNS(pe,"circle");return $.setAttribute("class","vd-editor__ring"),$.setAttribute("cx",String(g.x)),$.setAttribute("cy",String(g.y)),$.setAttribute("r",String(x0)),r.appendChild($),{id:S.id,rect:{x:g.x-ni/2,y:g.y-ni/2,w:ni,h:ni}}}function E(S){let g=t(S.at),$=S.axis==="x"?Kd:ei,L=S.axis==="x"?ei:Kd,B=ue("vd-editor__spacer",{x:g.x-$/2,y:g.y-L/2,w:$,h:L});B.setAttribute("rx",String(Kd/2)),r.appendChild(B),S.label!==null&&te(S.label,S.axis==="x"?{x:g.x,y:g.y-ei/2-Gd-at/2}:{x:g.x+ei/2+Gd+at,y:g.y});let q=S.axis==="x"?nm:rm,F=S.axis==="x"?rm:nm;return{id:S.id,rect:{x:g.x-q/2,y:g.y-F/2,w:q,h:F}}}function T(S){let g=k(S.frame),$=S.rotation??0;u=$===0?null:{angle:$,centre:{x:g.x+g.w/2,y:g.y+g.h/2}},v(u,()=>P(S,g)),S.handles&&S.rotatable&&(x=bo.map(L=>{let{u:B,v:q}=fr(L);return{handle:L,at:{x:g.x+g.w*B,y:g.y+g.h*q}}}))}function P(S,g){if(me("vd-editor__outline",hr(g,mr),mr),!!S.handles){o=Cl(g).map($=>({...$,bound:S.boundHandles.has($.handle)}));for(let $ of bo){let{u:L,v:B}=fr($),q={x:g.x+g.w*L-ur/2,y:g.y+g.h*B-ur/2,w:ur,h:ur};r.appendChild(ue("vd-editor__halo",hr(q,em+1))),r.appendChild(ue("vd-editor__handle",q))}a=S.adjusters.map($=>{let L=t($.at),B=n.createElementNS(pe,"circle");B.setAttribute("class","vd-editor__halo"),B.setAttribute("cx",String(L.x)),B.setAttribute("cy",String(L.y)),B.setAttribute("r",String(tm+em/2+.5)),r.appendChild(B);let q=n.createElementNS(pe,"circle");return q.setAttribute("class","vd-editor__adjuster"),q.setAttribute("cx",String(L.x)),q.setAttribute("cy",String(L.y)),q.setAttribute("r",String(tm)),r.appendChild(q),{id:$.id,bound:$.bound,rect:{x:L.x-Qa/2,y:L.y-Qa/2,w:Qa,h:Qa}}})}}function V(S){let g=t(S.axis==="x"?{x:S.at,y:S.from}:{x:S.from,y:S.at}),$=t(S.axis==="x"?{x:S.at,y:S.to}:{x:S.to,y:S.at}),L=n.createElementNS(pe,"line");L.setAttribute("class","vd-editor__guide"),L.setAttribute("x1",String($e(g.x))),L.setAttribute("y1",String($e(g.y))),L.setAttribute("x2",String($e($.x))),L.setAttribute("y2",String($e($.y))),r.appendChild(L)}function X(S){let g=t(S.axis==="x"?{x:S.from,y:S.at}:{x:S.at,y:S.from}),$=t(S.axis==="x"?{x:S.to,y:S.at}:{x:S.at,y:S.to}),L=n.createElementNS(pe,"path");L.setAttribute("class","vd-editor__measure"),L.setAttribute("d",S.axis==="x"?`M${$e(g.x)} ${$e(g.y)-rn} V${$e(g.y)+rn} M${$e(g.x)} ${$e(g.y)} H${$e($.x)} M${$e($.x)} ${$e($.y)-rn} V${$e($.y)+rn}`:`M${$e(g.x)-rn} ${$e(g.y)} H${$e(g.x)+rn} M${$e(g.x)} ${$e(g.y)} V${$e($.y)} M${$e($.x)-rn} ${$e($.y)} H${$e($.x)+rn}`),r.appendChild(L);let B=n.createElementNS(pe,"text");B.setAttribute("class","vd-editor__measure-text"),B.setAttribute("x",String((g.x+$.x)/2)),B.setAttribute("y",String((g.y+$.y)/2-(S.axis==="x"?im:0))),S.axis==="y"&&B.setAttribute("dx",String(im)),B.textContent=S.label,r.appendChild(B)}function te(S,g){let $=Math.max(34,S.length*Wd+14),L=g.x-$/2,B=g.y-at/2,q=ue("vd-editor__badge",{x:L,y:B,w:$,h:at});q.setAttribute("rx",String(at/2)),r.appendChild(q);let F=n.createElementNS(pe,"text");F.setAttribute("class","vd-editor__badge-text"),F.setAttribute("x",String(L+$/2)),F.setAttribute("y",String(B+at/2)),F.textContent=S,r.appendChild(F)}function I(S){let g=k(S.frame),$=Math.floor(g.w/lm);if($<3)return[];let L=S.label.length>$?`${S.label.slice(0,$-1)}\u2026`:S.label,B=n.createElementNS(pe,"text");B.setAttribute("class",`vd-editor__page-label vd-editor__page-label--${S.state}`),B.setAttribute("x",String(g.x)),B.setAttribute("y",String(g.y-sm)),B.textContent=L,r.appendChild(B);let q=Math.min(g.w,L.length*lm+4),F=y0+6;return[{id:S.id,rect:{x:g.x,y:g.y-sm-F+3,w:q,h:F}}]}function fe(S){let g=Lo(k(S.frame));r.appendChild(ue("vd-editor__lock",g));let $=`${S.label} \xB7 locked`,L=$.length*Wd+14,B=g.y+4,q=ue("vd-editor__lock-tag",{x:g.x+4,y:B,w:L,h:at});q.setAttribute("rx","4"),r.appendChild(q);let F=n.createElementNS(pe,"text");F.setAttribute("class","vd-editor__lock-text"),F.setAttribute("x",String(g.x+4+L/2)),F.setAttribute("y",String(B+at/2)),F.textContent=$,r.appendChild(F)}function we(S){let g=Lo(k(S.frame)),$=ue(S.target?"vd-editor__slot vd-editor__slot--target":"vd-editor__slot",g);$.setAttribute("rx","3"),r.appendChild($);let L=F=>F.length*g0+16<=g.w,B=[];g.h>=20&&L(S.label)&&B.push([S.label,"vd-editor__slot-label"]),B.length>0&&g.h>=48&&L(om)&&B.push([om,"vd-editor__slot-hint"]);let q=g.y+g.h/2-(B.length-1)*am/2;B.forEach(([F,ne],ke)=>{let Me=n.createElementNS(pe,"text");Me.setAttribute("class",ne),Me.setAttribute("x",String(g.x+g.w/2)),Me.setAttribute("y",String(q+ke*am)),Me.textContent=F,r.appendChild(Me)})}function Se(S){let g=S.frames.map(ne=>hr(k(ne),mr));for(let ne of g)r.appendChild(ue("vd-editor__presence",ne));let $=g[0];if(!$||!S.label)return;let L=Math.max(34,S.label.length*Wd+14),B=$.y-at-3<0?$.y+3:$.y-at-3,q=ue("vd-editor__presence-tag",{x:$.x,y:B,w:L,h:at});q.setAttribute("rx","4"),r.appendChild(q);let F=n.createElementNS(pe,"text");F.setAttribute("class","vd-editor__presence-text"),F.setAttribute("x",String($.x+L/2)),F.setAttribute("y",String(B+at/2)),F.textContent=S.label,r.appendChild(F)}function me(S,g,$){let B=S==="vd-editor__highlight"?"vd-editor__halo vd-editor__halo--highlight":S==="vd-editor__hover"||S==="vd-editor__member"?"vd-editor__halo vd-editor__halo--quiet":"vd-editor__halo";r.appendChild(ue(B,hr(g,$+1))),r.appendChild(ue(S,g))}function ue(S,g){let $=n.createElementNS(pe,"rect");return $.setAttribute("class",S),$.setAttribute("x",String(g.x)),$.setAttribute("y",String(g.y)),$.setAttribute("width",String(Math.max(0,g.w))),$.setAttribute("height",String(Math.max(0,g.h))),$}return{element:r,render:M,hitHandle(S){let g=w(S,u);for(let $ of o)if(gt($.rect,g.x,g.y))return{handle:$.handle,bound:$.bound};return null},hitAdjuster(S){let g=w(S,u);for(let $ of a)if(gt($.rect,g.x,g.y))return{id:$.id,bound:$.bound};return null},hitSpacer(S){return Xd(i,S)},hitPath(S){let g=w(S,p),$=d.find(L=>gt(L.rect,g.x,g.y));return $?{kind:$.kind,key:$.key}:null},hitRotate(S){let g=w(S,u),$=o.length===0?null:x;if(!$)return null;for(let L of $){let B=Math.hypot(g.x-L.at.x,g.y-L.at.y);if(B<ur/2+2||B>m0)continue;let{u:q,v:F}=fr(L.handle);if((g.x-L.at.x)*(q*2-1)+(g.y-L.at.y)*(F*2-1)>0)return L.handle}return null},hitRing(S){return Xd(l,S)},hitPageLabel(S){return Xd(y,S)},pageLabelRect(S){return y.find(g=>g.id===S)?.rect??null},destroy(){r.remove(),o=[],a=[],i=[],l=[]}}}function Xd(e,t){for(let n of e)if(gt(n.rect,t.x,t.y))return n.id;return null}function $e(e){return Math.round(e)+.5}function Lo(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 n=t/2;return{x:e.x-n,y:e.y-n,w:e.w+t,h:e.h+t}}function um(e,t){let n=[];return se(e.root,r=>{if(t.has(r.id))return!1;r.type!=="image"||be(r.src)||e.assets[r.src]===void 0&&n.push({id:r.id,src:r.src,label:r.name??r.src})}),n}function Jd(e){if(e.length<2)return null;let t=Yd("x",e),n=Yd("y",e);return n.length===1&&t.length===e.length?cm("x",e,t):t.length===1&&n.length===e.length?cm("y",e,n):n.length>=2&&t.length>=2?v0(e,t,n):null}function Yd(e,t){let n=[...t].sort((o,a)=>xr(o.frame,e)-xr(a.frame,e)),r=[];for(let o of n){let a=r[r.length-1];if(a&&xr(o.frame,e)<a.hi-.01){r[r.length-1]={lo:a.lo,hi:Math.max(a.hi,oi(o.frame,e)),from:Math.min(a.from,xr(o.frame,ri(e))),to:Math.max(a.to,oi(o.frame,ri(e))),members:[...a.members,o.id]};continue}r.push({lo:xr(o.frame,e),hi:oi(o.frame,e),from:xr(o.frame,ri(e)),to:oi(o.frame,ri(e)),members:[o.id]})}return r}function cm(e,t,n){return{kind:"run",items:t,series:[ai(e,n)],order:n.flatMap(r=>r.members)}}function v0(e,t,n){if(t.length*n.length!==e.length)return null;let r=[];for(let o of n)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;r.push(i[0])}return{kind:"grid",items:e,series:[ai("x",t),ai("y",n)],order:r}}function ai(e,t){let n=[];for(let r=0;r+1<t.length;r+=1){let o=t[r],a=t[r+1];!o||!a||n.push(a.lo-o.hi)}return{axis:e,tracks:t,gaps:n}}function Et(e,t){return e.series.find(n=>n.axis===t)}function Zd(e){let t=e[0];return t===void 0?!1:e.every(n=>Math.abs(n-t)<.01)}function Qd(e){let t=[];for(let n of e.series){let r=e.series.find(o=>o.axis!==n.axis);for(let o=0;o<n.gaps.length;o+=1){let a=n.tracks[o],i=n.tracks[o+1],l=n.gaps[o];if(!a||!i||l===void 0)continue;let d=(a.hi+i.lo)/2,u=r?r.tracks.map(p=>(p.lo+p.hi)/2):[(Math.max(a.from,i.from)+Math.min(a.to,i.to))/2];for(let p of u)t.push({id:pm(n.axis,o),axis:n.axis,index:o,gap:l,at:n.axis==="x"?{x:d,y:p}:{x:p,y:d}})}}return t}function pm(e,t){return`${e}:${t}`}function ii(e){let[t,n]=e.split(":");if(t!=="x"&&t!=="y"||n===void 0)return null;let r=Number(n);return Number.isInteger(r)&&r>=0?{axis:t,index:r}:null}function ef(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 si(e,t,n){let r=Et(e,t);return r?li(r,n):new Map}function li(e,t){let n=new Map,r=e.tracks[0];if(!r)return n;let o=r.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)n.set(d,l-i.lo);o=l+(i.hi-i.lo)}return n}function tf(e,t){return ai(t,Yd(t,e))}function nf(e){let t=e.tracks,n=t[0],r=t[t.length-1];if(!n||!r||t.length<3)return null;let o=t.reduce((a,i)=>a+(i.hi-i.lo),0);return(r.hi-n.lo-o)/(t.length-1)}function rf(e,t){let n=b0(e),r=0,o=1/0;for(let a=0;a<n.length;a+=1){let i=n[a];if(!i)continue;let l=Math.hypot(i.x-t.x,i.y-t.y);l<o&&(o=l,r=a)}return r}function b0(e){if(e.kind==="grid"){let n=Et(e,"x")?.tracks??[];return(Et(e,"y")?.tracks??[]).flatMap(o=>n.map(a=>({x:(a.lo+a.hi)/2,y:(o.lo+o.hi)/2})))}let t=e.series[0];return t?t.tracks.map(n=>t.axis==="x"?{x:(n.lo+n.hi)/2,y:(n.from+n.to)/2}:{x:(n.from+n.to)/2,y:(n.lo+n.hi)/2}):[]}function of(e,t,n){let r=[...e],[o]=r.splice(t,1);return o===void 0?[...e]:(r.splice(Math.max(0,Math.min(n,r.length)),0,o),r)}function af(e,t){let n=new Map(e.items.map(l=>[l.id,l.frame])),r=new Map;if(e.kind==="grid"){let l=Et(e,"x")?.tracks??[],d=Et(e,"y")?.tracks??[];return t.forEach((u,p)=>{let x=l[p%l.length],y=d[Math.floor(p/l.length)];x&&y&&r.set(u,{x:x.lo,y:y.lo})}),r}let o=e.series[0],a=o?.tracks[0];if(!o||!a)return r;let i=a.lo;return t.forEach((l,d)=>{let u=n.get(l);if(!u)return;let p=o.axis==="x"?u.w:u.h;r.set(l,o.axis==="x"?{x:i,y:u.y}:{x:u.x,y:i}),i+=p+(o.gaps[d]??0)}),r}function sf(e,t,n){let r=new Map,o=e.items.find(d=>d.id===t),a=e.items.find(d=>d.id===n);if(!o||!a||t===n)return r;let i=e.kind==="grid"?["x","y"]:[e.series[0]?.axis??"x"],l=(d,u)=>({x:i.includes("x")?u.frame.x:d.frame.x,y:i.includes("y")?u.frame.y:d.frame.y});return r.set(t,l(o,a)),r.set(n,l(a,o)),r}function ri(e){return e==="x"?"y":"x"}function xr(e,t){return t==="x"?e.x:e.y}function oi(e,t){return t==="x"?e.x+e.w:e.y+e.h}var mm="vd-editor-styles",hm=`
139
+ `;function Dp(e){if(e.getElementById(Op))return;let t=e.createElement("style");t.id=Op,t.textContent=Lp,e.head.appendChild(t)}function Np(e){if(!(e===void 0||typeof fetch!="function"))return async(t,n)=>{let r=e(t,n);if(r===void 0)return;let o=await fetch(r);return o.ok?new Uint8Array(await o.arrayBuffer()):void 0}}function Ip(e,t,n,r,o){return t?Rv(e,t,n,r,o):Iv(e,n,r)}function Iv(e,t,n){let r=Nd(e,n);return{measurer:r,update:o=>{r.load(o,t)},afterPaint:()=>{},destroy:()=>r.destroy()}}var Pp=new WeakMap;function Rv(e,t,n,r,o){let a,s,d,l=()=>{if(!a)throw new Error("canvasFonts: update() before measuring");return a};return{measurer:{advance:(c,m)=>l().measurer.advance(c,m),metrics:c=>l().measurer.metrics(c),itemize:c=>l().measurer.itemize(c)},update(c){a&&c.fonts===s||(d?.(),a?.dispose(),a=t.forDocument(c,{...n?{loader:n}:{},...o?{asset:o}:{}}),s=c.fonts,d=a.onChange(r))},afterPaint(){let c=e.fonts;if(!a||!c||typeof FontFace!="function")return;let m=Pp.get(e);m||Pp.set(e,m=new Set);for(let g of a.usedFaces()){if(m.has(g.id))continue;m.add(g.id);let b=new FontFace(g.id,Fv(g.bytes),{weight:String(g.weight),style:g.style});c.add(b),b.load().catch(()=>c.delete(b))}},destroy(){d?.(),a?.dispose(),a=void 0}}}function Fv(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}var Bv=.01,Hv=.004,Rp=40,Uv=16;function ja(e,t){Dp(e.ownerDocument);let n=t.document,r=F=>Ip(e.ownerDocument,F,t.loadFont,()=>{j(n)},Np(t.resolveAsset)),o=r(t.fonts),a={advance:(F,G)=>o.measurer.advance(F,G),metrics:F=>o.measurer.metrics(F),itemize:F=>o.measurer.itemize?.(F)??[F]};o.update(n);let s=Re(n),d=()=>t.resolveAsset?{measure:a,resolveAsset:t.resolveAsset}:{measure:a},l=_o(n,s,d()),f=t.camera??Va,c=t.interactive??!0,m=t.wheel??"always";e.classList.add("vd-viewer"),t.surface&&(e.style.background=t.surface);let g=e.ownerDocument.createElementNS(xe,"svg");g.setAttribute("class","vd-viewer__surface"),g.setAttribute("width","100%"),g.setAttribute("height","100%");let b=e.ownerDocument.createElementNS(xe,"g");b.setAttribute("class","vd-viewer__camera"),b.style.isolation="isolate",g.appendChild(b);let E=e.ownerDocument.createElementNS(xe,"defs");b.appendChild(E);let v=e.ownerDocument.createElementNS(xe,"rect");v.setAttribute("class","vd-viewer__page"),b.appendChild(v),e.appendChild(g);let w=new Map,L=null;function $(){let F=t.sample;return L&&F?F(l,L.timeline,L.t,{doc:n,resolution:s,options:d()}):l}function z(){b.setAttribute("transform",Rd(f))}function A(F=!0){let G=$();I(G);let me=l.background!==void 0;le(v,"x",String(l.x)),le(v,"y",String(l.y)),le(v,"width",String(me?l.width:0)),le(v,"height",String(me?l.height:0)),Ce(v,"fill",l.background??null);let pe=new Set,Te=v;for(let ue of G.items){let He=ue.part===void 0?ue.id:`${ue.id}\0${ue.part}`;pe.add(He);let Oe=w.get(He);(!Oe||Oe.tagName!==Fp(ue))&&(Oe?.remove(),Oe=e.ownerDocument.createElementNS(xe,Fp(ue)),Oe.setAttribute("data-vd-id",ue.id),w.set(He,Oe)),jv(Oe,ue),Te.nextSibling!==Oe&&b.insertBefore(Oe,Te.nextSibling),Te=Oe}for(let[ue,He]of w)pe.has(ue)||(He.remove(),w.delete(ue));o.afterPaint(),F&&t.onSceneChange?.(l,n)}let N=new Map;function I(F){let G=[...F.gradients.map(Od),...[...new Map(F.items.filter(ue=>ue.shadows.length>0).map(ue=>[ue.id,ue])).values()].map(ue=>Ld(ue)),...F.clips.map(Td)],me=new Set(G);for(let[ue,He]of N)me.has(ue)||(He.remove(),N.delete(ue));let pe=G.filter(ue=>!N.has(ue));if(pe.length===0)return;[...new DOMParser().parseFromString(`<svg xmlns="${xe}">${pe.join("")}</svg>`,"image/svg+xml").documentElement.children].forEach((ue,He)=>{let Oe=e.ownerDocument.importNode(ue,!0);E.appendChild(Oe),N.set(pe[He],Oe)})}function j(F){n=F,o.update(n),s=Re(n),l=_o(n,s,d()),A()}function O(F){let G=e.getBoundingClientRect();return{x:F.clientX-G.left,y:F.clientY-G.top}}let V=0,C=0;function R(){e.classList.add("vd-viewer--interacting"),C&&clearTimeout(C),C=setTimeout(()=>{C=0,e.classList.remove("vd-viewer--interacting")},180)}function q(){V&&(cancelAnimationFrame(V),V=0),z(),t.onCameraChange?.(f)}function ee(F){f=F,q()}function oe(F){f=F,R(),!V&&(V=requestAnimationFrame(()=>{V=0,z(),t.onCameraChange?.(f)}))}let se=null,S=null,y=!1,T=c&&m==="always",D=new Map,U=null,X=()=>{let[F,G]=[...D.values()];return!F||!G?null:{mid:{x:(F.x+G.x)/2,y:(F.y+G.y)/2},distance:Math.hypot(F.x-G.x,F.y-G.y)}},H=F=>{let G=D.get(F.pointerId);if(!G)return;let me=O(F);if(D.set(F.pointerId,me),D.size===1){oe($t(f,me.x-G.x,me.y-G.y));return}let pe=X();if(U&&pe){let Te=$t(f,pe.mid.x-U.mid.x,pe.mid.y-U.mid.y);oe(U.distance>0?So(Te,pe.mid,pe.distance/U.distance):Te)}U=pe},ie=F=>{D.delete(F.pointerId)&&(e.hasPointerCapture(F.pointerId)&&e.releasePointerCapture(F.pointerId),U=X())},_e=F=>{if(m==="modifier"&&!F.ctrlKey&&!F.metaKey)return;F.preventDefault();let G=O(F),me=F.deltaMode===1?Uv:F.deltaMode===2?e.clientHeight||800:1,pe=F.deltaX*me,Te=F.deltaY*me;if(F.ctrlKey||F.metaKey){let ue=F.ctrlKey?Bv:Hv,He=Math.max(-Rp,Math.min(Rp,Te));oe(So(f,G,Math.exp(-He*ue)));return}if(F.shiftKey&&pe===0){oe($t(f,-Te,0));return}oe($t(f,-pe,-Te))},Me=F=>{if(F.pointerType==="touch"){if(!T)return;F.preventDefault(),D.set(F.pointerId,O(F)),e.setPointerCapture(F.pointerId),U=X();return}(F.button===1||F.button===0&&y)&&(F.preventDefault(),se=F.pointerId,S=O(F),e.setPointerCapture(F.pointerId))},Se=F=>{if(F.pointerType==="touch"){H(F);return}if(se!==F.pointerId||!S)return;let G=O(F);oe($t(f,G.x-S.x,G.y-S.y)),S=G},Ze=F=>{if(F.pointerType==="touch"){ie(F);return}se===F.pointerId&&(se=null,S=null,e.hasPointerCapture(F.pointerId)&&e.releasePointerCapture(F.pointerId))},J=F=>{F.code==="Space"&&(y=!0)},ne=F=>{F.code==="Space"&&(y=!1)};T&&(e.style.touchAction="none"),c&&(e.addEventListener("wheel",_e,{passive:!1}),e.addEventListener("pointerdown",Me),e.addEventListener("pointermove",Se),e.addEventListener("pointerup",Ze),e.addEventListener("pointercancel",Ze),e.ownerDocument.addEventListener("keydown",J),e.ownerDocument.addEventListener("keyup",ne)),z(),A();let te={element:e,surface:g,update:j,getDocument:()=>n,getScene:()=>l,setTime(F){F===null&&L===null||(L=F,A(!1))},getTime:()=>L,getResolution:()=>s,getMeasurer:()=>a,setFonts(F){o.destroy(),o=r(F),j(n)},getCamera:()=>f,setCamera:ee,zoomBy(F,G){let me=e.getBoundingClientRect(),pe=G??{x:me.width/2,y:me.height/2};ee(So(f,pe,F))},fitToContent(F=32){let G=e.getBoundingClientRect();ee(sn({x:l.x,y:l.y,width:l.width,height:l.height},{width:G.width||l.width,height:G.height||l.height},F))},screenToDocument:F=>za(f,F),documentToScreen:F=>Id(f,F),pointerPoint:O,hitTest(F,G){for(let me=l.items.length-1;me>=0;me--){let pe=l.items[me];if(pe&&eb(pe,F,Qv/f.zoom)&&(!G||G(pe.id)))return pe.id}return null},linkAt(F,G){for(let me=l.items.length-1;me>=0;me--){let pe=l.items[me];if(pe?.kind!=="text"||G&&!G(pe.id))continue;let Te=pe.rotation===0?F:nt(F,{x:pe.x+pe.w/2,y:pe.y+pe.h/2},-pe.rotation);for(let ue of pe.lines){if(Te.y<ue.y||Te.y>ue.y+ue.h)continue;let He=ue.spans.find(Oe=>Te.x>=Oe.x&&Te.x<=Oe.x+Oe.w);if(He)return He.style.link}}},itemOf:F=>l.items.find(G=>G.id===F),elementOf:F=>w.get(F),destroy(){c&&(e.removeEventListener("wheel",_e),e.removeEventListener("pointerdown",Me),e.removeEventListener("pointermove",Se),e.removeEventListener("pointerup",Ze),e.removeEventListener("pointercancel",Ze),e.ownerDocument.removeEventListener("keydown",J),e.ownerDocument.removeEventListener("keyup",ne)),V&&cancelAnimationFrame(V),C&&clearTimeout(C),V=0,C=0,o.destroy(),e.classList.remove("vd-viewer--interacting"),g.remove(),w.clear(),e.classList.remove("vd-viewer")}};return t.autoFit&&te.fitToContent(),te}var Vv="vd-clip-";function zv(e){return Vv+e}function Hp(e){return`url(#${zv(e)})`}function Fp(e){return Dd(e)||e.pose!==void 0?"g":Fd(e)}function Fd(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 jv(e,t){if(e.tagName!=="g"){Bp(e,t);return}Ce(e,"clip-path",t.clip===void 0?null:Hp(t.clip)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend;let n=t.pose;Ce(e,"opacity",n&&n.opacity<1?String(n.opacity):null);let r=e.firstElementChild;if((!r||r.tagName!==Fd(t))&&(r?.remove(),r=e.ownerDocument.createElementNS(xe,Fd(t)),e.appendChild(r)),Bp(r,{...t,clip:void 0,blend:"normal"}),n){let o=t.rotation===0?"":` ${Ua(t)}`;le(r,"transform",`${Pd(n)}${o}`),t.kind==="vector"&&Kv(r,t)}}function Kv(e,t){let n=t.pose?.trace;if(n!==void 0&&t.stroke!==void 0){let o=ya(t.contours)+1;le(e,"stroke-dasharray",`${o} ${o}`),le(e,"stroke-dashoffset",String(o*(1-n)))}let r=t.pose?.fillOpacity;Ce(e,"fill-opacity",r!==void 0&&r<1?String(r):null)}function Bp(e,t){switch(Ce(e,"clip-path",t.clip===void 0?null:Hp(t.clip)),Ce(e,"transform",t.rotation===0?null:Ua(t)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend,e.style.filter=t.shadows.length>0?`url(#${Ha}${t.id})`:"",t.kind){case"ellipse":Jv(e,t);return;case"frame":qv(e,t);return;case"image":Gv(e,t);return;case"rect":Yv(e,t);return;case"text":Xv(e,t);return;case"vector":Zv(e,t);return}}function qv(e,t){le(e,"class","vd-viewer__page"),le(e,"x",String(t.x)),le(e,"y",String(t.y)),le(e,"width",String(t.w)),le(e,"height",String(t.h)),Ce(e,"fill",t.background??null)}function Gv(e,t){if(le(e,"x",String(t.x)),le(e,"y",String(t.y)),le(e,"width",String(t.w)),le(e,"height",String(t.h)),Ce(e,"opacity",t.opacity<1?String(t.opacity):null),t.href===void 0){le(e,"class","vd-viewer__missing"),Ce(e,"rx",t.radius>0?String(t.radius):null);return}le(e,"href",t.href),le(e,"preserveAspectRatio",Wv[t.fit])}var Wv={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"};function Xv(e,t){Ce(e,"opacity",t.opacity<1?String(t.opacity):null),le(e,"xml:space","preserve");let n=t.lines.flatMap(o=>o.spans).filter(o=>o.text!==""),r=e.ownerDocument;for(;e.childNodes.length>n.length;)e.lastChild?.remove();for(;e.childNodes.length<n.length;)e.appendChild(r.createElementNS(xe,"tspan"));n.forEach((o,a)=>{let s=e.childNodes[a];s.textContent!==o.text&&(s.textContent=o.text),le(s,"x",String(o.x)),le(s,"y",String(o.y)),le(s,"font-family",o.style.family),le(s,"font-size",String(o.style.size)),le(s,"fill",o.style.fill),Ce(s,"font-weight",o.style.weight===400?null:String(o.style.weight)),Ce(s,"font-style",o.style.italic?"italic":null),Ce(s,"letter-spacing",o.style.letterSpacing===0?null:String(o.style.letterSpacing)),Ce(s,"data-vd-link",o.style.link??null);let d=[o.style.underline?"underline":"",o.style.strike?"line-through":""].filter(Boolean).join(" ");Ce(s,"text-decoration",d===""?null:d)})}function Yv(e,t){Ce(e,"class",null),le(e,"x",String(t.x)),le(e,"y",String(t.y)),le(e,"width",String(t.w)),le(e,"height",String(t.h)),le(e,"fill",t.fill),Ce(e,"rx",t.radius>0?String(t.radius):null),Ce(e,"stroke",t.stroke??null),Ce(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),Ce(e,"opacity",t.opacity<1?String(t.opacity):null)}function Up(e,t){le(e,"fill",t.fill),Ce(e,"stroke",t.stroke??null),Ce(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),Ce(e,"opacity",t.opacity<1?String(t.opacity):null)}function Jv(e,t){le(e,"cx",String(t.x+t.w/2)),le(e,"cy",String(t.y+t.h/2)),le(e,"rx",String(t.w/2)),le(e,"ry",String(t.h/2)),Up(e,t)}function Zv(e,t){le(e,"d",t.d),Up(e,t),Ce(e,"fill-rule",t.rule==="nonzero"?null:t.rule),Ce(e,"stroke-linecap",t.cap==="butt"?null:t.cap),Ce(e,"stroke-linejoin",t.join==="miter"?null:t.join)}function le(e,t,n){e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Ce(e,t,n){n===null?e.hasAttribute(t)&&e.removeAttribute(t):le(e,t,n)}var Qv=4;function eb(e,t,n){let r=e.rotation===0?t:nt(t,{x:e.x+e.w/2,y:e.y+e.h/2},-e.rotation),o=r.x>=e.x&&r.x<=e.x+e.w&&r.y>=e.y&&r.y<=e.y+e.h;if(e.kind==="ellipse"){let a=e.stroke!==void 0?e.strokeWidth/2:0,s=e.w/2+a,d=e.h/2+a;if(s<=0||d<=0)return!1;let l=(r.x-(e.x+e.w/2))/s,f=(r.y-(e.y+e.h/2))/d;return l*l+f*f<=1}if(e.kind==="vector"){let a=e.stroke!==void 0&&e.strokeWidth>0;return wi(e.contours,r,{fill:e.fill!=="none",rule:e.rule,reach:(a?e.strokeWidth/2:0)+n})}return o}var q_=Bd(Sa),G_=Bd(Ea),tb=Bd(Ca);function Bd(e){return`cubic-bezier(${e.join(", ")})`}function Hd(e,t){let n=e.root.id;if(n===t)return e;let r=o=>{if(!ke(o))return o;let a=yt(o.expr);return!a.ok||!Nn(a.ast).nodes.includes(n)?o:{expr:yo(an(a.ast,s=>s===n?t:void 0))}};return{...e,root:{...Vp(e.root,r),id:t}}}function Vp(e,t){let n=e,r={};for(let[o,a]of Object.entries(n)){if(o==="children"&&Array.isArray(a)){r[o]=a.map(s=>Vp(s,t));continue}r[o]=t(a)}return r}var Vd=["nw","n","ne","e","se","s","sw","w"],Mo=["nw","ne","se","sw"];function Ka(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 xr(e){let t=e.includes("w")?0:e.includes("e")?1:.5,n=e.includes("n")?0:e.includes("s")?1:.5;return{u:t,v:n}}function zd(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 Co=1;function Ut(e,t,n,r){let{x:o,y:a,w:s,h:d}=e;if(t.includes("w")){let l=o+s;o=Math.min(o+n,l-Co),s=l-o}if(t.includes("e")&&(s=Math.max(Co,s+n)),t.includes("n")){let l=a+d;a=Math.min(a+r,l-Co),d=l-a}return t.includes("s")&&(d=Math.max(Co,d+r)),{x:o,y:a,w:s,h:d}}function In(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 qa(e,t){let n=[];return t.x!==e.x&&n.push("x"),t.y!==e.y&&n.push("y"),t.w!==e.w&&n.push("w"),t.h!==e.h&&n.push("h"),n}function vt(e){if(e.length===0)return null;let t=1/0,n=1/0,r=-1/0,o=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.w),o=Math.max(o,a.y+a.h);return{x:t,y:n,w:r-t,h:o-n}}function jd(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 bt(e,t,n){return t>=e.x&&t<=e.x+e.w&&n>=e.y&&n<=e.y+e.h}var gr=7,Ud=15,Eo=9;function Kd(e){let t=[],n=Ud/2;for(let d of Mo){let{u:l,v:f}=xr(d);t.push({handle:d,rect:{x:e.x+e.w*l-n,y:e.y+e.h*f-n,w:Ud,h:Ud}})}let r=n,o=Math.max(0,e.w-r*2),a=Math.max(0,e.h-r*2),s=Eo/2;return t.push({handle:"n",rect:{x:e.x+r,y:e.y-s,w:o,h:Eo}},{handle:"s",rect:{x:e.x+r,y:e.y+e.h-s,w:o,h:Eo}},{handle:"w",rect:{x:e.x-s,y:e.y+r,w:Eo,h:a}},{handle:"e",rect:{x:e.x+e.w-s,y:e.y+r,w:Eo,h:a}}),t}function jp(e,t,n,r,o){if(o===0)return Ut(e,t,n,r);let a=nt({x:n,y:r},{x:0,y:0},-o),s=Ut(e,t,a.x,a.y),d=st(e),l=st(s),f={x:d.x-l.x,y:d.y-l.y},c=nt(f,{x:0,y:0},o);return{...s,x:s.x+f.x-c.x,y:s.y+f.y-c.y}}function zp(e,t){return Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI}function Kp(e,t,n,r,o){let a=zp(e,n)-zp(e,t);return o?Math.round((r+a)/o)*o-r:a}function qp(e,t,n){return e.map(r=>{let o=st(r.frame),a=nt(o,t,n);return{id:r.id,frame:{...r.frame,x:a.x-r.frame.w/2,y:a.y-r.frame.h/2},rotation:xo(r.rotation+n)}})}function Gp(e,t,n,r){let o=n.w===0?1:r.w/n.w,a=n.h===0?1:r.h/n.h,s=t*Math.PI/180,d=Math.cos(s),l=Math.sin(s),f=e.w*Math.hypot(o*d,a*l),c=e.h*Math.hypot(o*l,a*d),m=st(e),g=r.x+(m.x-n.x)*o,b=r.y+(m.y-n.y)*a;return{x:g-f/2,y:b-c/2,w:f,h:c}}function Fe(e,t){return`${e}:${t}`}function Xa(e){let[t,n]=e.split(":").map(Number);if(!(t===void 0||n===void 0||!Number.isInteger(t)||!Number.isInteger(n)))return{contour:t,index:n}}function Wp(e){let t=e.split(":"),n=t[2],r=Xa(t.slice(0,2).join(":"));if(!(!r||n!=="in"&&n!=="out"))return{...r,side:n}}function Gd(e,t){let n=Xa(t);return n?e[n.contour]?.anchors[n.index]:void 0}function Wd(e,t){let n=[];for(let r of t){let o=Xa(r);o&&e[o.contour]?.anchors[o.index]&&n.push(Fe(o.contour,o.index))}return n}function Xd(e){return e.flatMap((t,n)=>t.anchors.map((r,o)=>Fe(n,o)))}function qd(e,t,n,r){return e.map((o,a)=>a===t?{...o,anchors:o.anchors.map((s,d)=>d===n?r:s)}:o)}var Ao=(e,t,n)=>({x:e.x+t,y:e.y+n});function Ya(e,t,n,r){return e.map((o,a)=>({...o,anchors:o.anchors.map((s,d)=>t.has(Fe(a,d))?Ct(Ao(s,n,r),s.in&&Ao(s.in,n,r),s.out&&Ao(s.out,n,r)):s)}))}function Ga(e){if(!e.in||!e.out)return!1;let t=e.in.x-e.x,n=e.in.y-e.y,r=e.out.x-e.x,o=e.out.y-e.y,a=Math.hypot(t,n),s=Math.hypot(r,o);return a===0||s===0?!1:(t*r+n*o)/(a*s)<-.995}function Wa(e,t,n,r,o,a){let s=e[t]?.anchors[n];if(!s)return[...e];let l=s[r==="in"?"out":"in"];if(a.smooth&&!a.breakSmooth&&l){let c=Math.hypot(l.x-s.x,l.y-s.y),m=o.x-s.x,g=o.y-s.y,b=Math.hypot(m,g);b>0&&(l={x:s.x-m/b*c,y:s.y-g/b*c})}let f=r==="in"?Ct(s,o,l):Ct(s,l,o);return qd(e,t,n,f)}function Xp(e,t){let n=Xa(t),r=n?e[n.contour]:void 0,o=r?.anchors[n?.index??-1];if(!n||!r||!o)return[...e];if(o.in||o.out)return qd(e,n.contour,n.index,Ct(o));let a=r.anchors.length,s=n.index>0?r.anchors[n.index-1]:r.closed?r.anchors[a-1]:void 0,d=n.index<a-1?r.anchors[n.index+1]:r.closed?r.anchors[0]:void 0;if(!s&&!d)return[...e];let l=s??o,f=d??o,c=f.x-l.x,m=f.y-l.y,g=Math.hypot(c,m);if(g===0)return[...e];c/=g,m/=g;let b=s?Math.hypot(o.x-s.x,o.y-s.y)/3:0,E=d?Math.hypot(d.x-o.x,d.y-o.y)/3:0,v=s?{x:o.x-c*b,y:o.y-m*b}:void 0,w=d?{x:o.x+c*E,y:o.y+m*E}:void 0;return qd(e,n.contour,n.index,Ct(o,v,w))}function Yp(e,t){let n=[];return e.forEach((r,o)=>{let a=r.anchors.filter((s,d)=>!t.has(Fe(o,d)));a.length>=2&&n.push({closed:r.closed,anchors:a})}),n}function Jp(e,t,n,r,o,a,s){let d=e[t];if(!d)return[...e];let l=d.anchors.length,f=(n+1)%l;if(s)return Ya(e,new Set([Fe(t,n),Fe(t,f)]),o,a);let c=Math.min(.85,Math.max(.15,r)),m=1/(3*(1-c)*c),g=d.anchors[n],b=d.anchors[f],E=Ao(g.out??g,o*m,a*m),v=Ao(b.in??b,o*m,a*m),w=Wa(e,t,n,"out",E,{smooth:Ga(g),breakSmooth:!1});return w=Wa(w,t,f,"in",v,{smooth:Ga(b),breakSmooth:!1}),w}function Zp(e,t){return e.map((n,r)=>n.closed||n.anchors.length<2?n:t.size===0||t.has(Fe(r,0))&&t.has(Fe(r,n.anchors.length-1))?{...n,closed:!0}:n)}function Yd(e,t){let n=[],r=new Set,o=(a,s,d)=>{let l=e[a]?.anchors[s],f=l?.[d],c=`${Fe(a,s)}:${d}`;!l||!f||r.has(c)||(r.add(c),n.push({key:c,at:f,anchor:l}))};return e.forEach((a,s)=>{let d=a.anchors.length;a.anchors.forEach((l,f)=>{if(!t.has(Fe(s,f)))return;o(s,f,"in"),o(s,f,"out");let c=f>0?f-1:a.closed?d-1:-1,m=f<d-1?f+1:a.closed?0:-1;c>=0&&o(s,c,"out"),m>=0&&o(s,m,"in")})}),n}function $o(e,t){let n=t.x-e.x,r=t.y-e.y,o=Math.round(Math.atan2(r,n)/(Math.PI/4))*(Math.PI/4),a=n*Math.cos(o)+r*Math.sin(o);return{x:e.x+Math.cos(o)*a,y:e.y+Math.sin(o)*a}}function Qp(e){return{closed:e.closed,anchors:[...e.anchors].reverse().map(t=>Ct(t,t.out,t.in))}}function Jd(e){if(!e)return null;for(let t of e.items){if(t.kind!=="file"||!t.type.startsWith("image/"))continue;let n=t.getAsFile();if(n)return n}return null}async function Ja(e,t){let n;try{n=await createImageBitmap(e)}catch{return null}try{let r=Math.min(1,t/Math.max(n.width,n.height));return r>=1?{bytes:new Uint8Array(await e.arrayBuffer()),type:e.type||"image/png",width:n.width,height:n.height}:await ab(n,r,e.type)}finally{n.close()}}async function ab(e,t,n){let r=Math.max(1,Math.round(e.width*t)),o=Math.max(1,Math.round(e.height*t)),a=document.createElement("canvas");a.width=r,a.height=o;let s=a.getContext("2d");if(!s)return null;s.drawImage(e,0,0,r,o);let d=n==="image/png"?"image/png":"image/webp",l=await new Promise(f=>{a.toBlob(f,d,.9)});return l?{bytes:new Uint8Array(await l.arrayBuffer()),type:l.type||d,width:r,height:o}:null}function em(e,t,n,r){let o=Math.min(1,n/e,r/t);return{w:Math.round(e*o),h:Math.round(t*o)}}function Za(e){let t=Pt(e);return e.root.children.filter(n=>t.has(n.id)&&An(e.motion?.[n.id])).map(n=>n.id)}function Qa(e,t,n){let r=Za(e);if(r.length===0)return null;let o=ft(e);for(let a of t){let s=o.get(a);if(s!==void 0&&r.includes(s))return s}return n!==null&&r.includes(n)?n:r[0]??null}var sb=1e3/30;var ib=/\.(?:mp3|m4a|aac|wav|ogg|oga|opus|flac|webm)$/i;function tm(e){return e.type.startsWith("audio/")||e.type===""&&ib.test(e.name)}var db=new Set(["loop","step","together"]);function nm(e,t,n){let r=e.motion?.[t]?.music?.asset;if(r!==void 0&&e.assets[r]===void 0)return r;let o=n.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"music";if((!/^[a-z]/.test(o)||db.has(o))&&(o=`track-${o}`),e.assets[o]===void 0)return o;for(let a=2;;a+=1)if(e.assets[`${o}-${a}`]===void 0)return`${o}-${a}`}function rm(e,t,n,r){let o=e.motion?.[t]??{lines:[]},a=o.music,s={asset:n};if(a&&a.asset===n)s=a;else if(a){let d={...a,asset:n};delete d.from,s=d}return[{op:"setAsset",name:n,value:r},{op:"setMotion",page:t,value:{...o,music:s}}]}var lb={left:"x",hcenter:"x",right:"x",top:"y",vcenter:"y",bottom:"y"};function es(e){return lb[e]}function ub(e,t,n){switch(e){case"left":return t.x;case"hcenter":return t.x+(t.w-n)/2;case"right":return t.x+t.w-n;case"top":return t.y;case"vcenter":return t.y+(t.h-n)/2;case"bottom":return t.y+t.h-n}}function Zd(e,t,n){let r=es(n),o=new Map;for(let a of e){let s=r==="x"?a.frame.w:a.frame.h,d=r==="x"?a.frame.x:a.frame.y;o.set(a.id,ub(n,t,s)-d)}return o}var om=[{key:"nw",sx:0,sy:0},{key:"ne",sx:1,sy:0},{key:"se",sx:1,sy:1},{key:"sw",sx:0,sy:1}],fb={id:"radius",prop:"radius",handles(e,t,n){let r=this.max(e),o=Math.min(Math.max(t,n),Math.max(r,n));return om.map(({key:a,sx:s,sy:d})=>({id:`radius:${a}`,at:{x:e.x+(s===0?o:e.w-o),y:e.y+(d===0?o:e.h-o)}}))},valueAt(e,t,n){let r=pb(t);if(!r)return 0;let o=e.x+(r.sx===0?0:e.w),a=e.y+(r.sy===0?0:e.h),s=Math.max(0,r.sx===0?n.x-o:o-n.x),d=Math.max(0,r.sy===0?n.y-a:a-n.y);return Math.min((s+d)/2,this.max(e))},max(e){return Math.max(0,Math.min(e.w,e.h)/2)}},cb={canvas:[],frame:[],group:[],rect:[fb]};function To(e){return cb[e.type]??[]}function ts(e,t){let n=t.split(":")[0];return To(e).find(r=>r.id===n)}function pb(e){let t=e.split(":")[1];return om.find(n=>n.key===t)}var Qd=[["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 el=[["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 tl=[["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 nl=[["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 rl=[["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 ol=[["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 al=[["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 sl=[["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 il=[["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 dl=[["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 ll=[["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 ul=[["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 fl=[["circle",{cx:"15",cy:"9",r:"7"}],["circle",{cx:"9",cy:"15",r:"7"}]];var cl=[["path",{d:"M20 6 9 17l-5-5"}]];var pl=[["path",{d:"m6 9 6 6 6-6"}]];var ml=[["path",{d:"m9 18 6-6-6-6"}]];var hl=[["circle",{cx:"12",cy:"12",r:"10"}]];var xl=[["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 gl=[["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 yl=[["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 vl=[["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 bl=[["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 wl=[["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 kl=[["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 _l=[["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 ns=[["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 Sl=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}]];var El=[["path",{d:"M12 11.4V9.1"}],["path",{d:"m12 17 6.59-6.59"}],["path",{d:"m15.05 5.7-.218-.691a3 3 0 0 0-5.663 0L4.418 19.695A1 1 0 0 0 5.37 21h13.253a1 1 0 0 0 .951-1.31L18.45 16.2"}],["circle",{cx:"20",cy:"9",r:"2"}]];var Cl=[["path",{d:"M5 12h14"}]];var Ml=[["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 Al=[["path",{d:"m18 8 4 4-4 4"}],["path",{d:"M2 12h20"}],["path",{d:"m6 8-4 4 4 4"}]];var $l=[["path",{d:"M12 2v20"}],["path",{d:"m8 18 4 4 4-4"}],["path",{d:"m8 6 4-4 4 4"}]];var Tl=[["path",{d:"M9 18V5l12-2v13"}],["circle",{cx:"6",cy:"18",r:"3"}],["circle",{cx:"18",cy:"16",r:"3"}]];var Ol=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"}]];var Ll=[["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 Dl=[["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 Pl=[["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 Nl=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];var Il=[["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 Rl=[["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 Fl=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2"}],["circle",{cx:"12",cy:"12",r:"1"}],["path",{d:"M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0"}]];var Bl=[["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 Hl=[["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 Ul=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];var rs=[["path",{d:"M21 5H3"}],["path",{d:"M21 12H9"}],["path",{d:"M21 19H7"}]];var os=[["path",{d:"M21 5H3"}],["path",{d:"M17 12H7"}],["path",{d:"M19 19H5"}]];var as=[["path",{d:"M3 5h18"}],["path",{d:"M3 12h18"}],["path",{d:"M3 19h18"}]];var Oo=[["path",{d:"M21 5H3"}],["path",{d:"M15 12H3"}],["path",{d:"M17 19H3"}]];var Vl=[["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 zl=[["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 jl=[["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 Kl=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}],["path",{d:"M16 9a5 5 0 0 1 0 6"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728"}]];var ql=[["path",{d:"M11 4.702a.7.7 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.7.7 0 0 0 11 19.298z"}],["path",{d:"m16.5 14.5 5-5"}],["path",{d:"m16.5 9.5 5 5"}]];var Gl=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var Lo=e=>e.replace(/\b(?:CmdOrCtrl|CommandOrControl)\b/g,"Ctrl");function am(e,t){let r=e.ownerDocument.createElement("div");r.className="vd-chrome",r.setAttribute("role","toolbar"),r.setAttribute("aria-label","Canvas tools"),r.innerHTML=mb(t),e.appendChild(r);let o=new Map;for(let c of r.querySelectorAll("[data-tool]"))o.set(c.dataset.tool,c);let a=r.querySelector('[data-act="undo"]'),s=r.querySelector('[data-act="redo"]'),d=r.querySelector('[data-act="zoom"]'),l=c=>{let m=c.target?.closest("button");if(!m)return;c.stopPropagation();let g=m.dataset.tool;if(g){t.onTool(g);return}switch(m.dataset.act){case"undo":t.onUndo();return;case"redo":t.onRedo();return;case"zoom":t.onZoomReset();return;case"play":t.onPlay?.();return}},f=c=>c.stopPropagation();return r.addEventListener("click",l),r.addEventListener("pointerdown",f),{element:r,setTool(c){for(let[m,g]of o)g.setAttribute("aria-pressed",String(m===c))},setHistory(c,m){a&&(a.disabled=!c),s&&(s.disabled=!m)},setZoom(c){d&&(d.textContent=`${Math.round(c*100)}%`)},destroy(){r.removeEventListener("click",l),r.removeEventListener("pointerdown",f),r.remove()}}}function mb(e){let t=e.formatKeys??Lo;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??""}"`,n=e.tool?' aria-pressed="false"':"";return`<button type="button" class="vd-chrome__tool" ${t}${n} title="${e.hint?`${e.label} \xB7 ${e.hint}`:e.label}" aria-label="${e.label}">`+Je(e.icon)+"</button>"}var hb={select:Ml,frame:bl,rect:Ul,ellipse:hl,pen:Ll,vector:Bl,text:Vl,undo:zl,redo:Il,"align-left":sl,"align-hcenter":tl,"align-right":rl,"align-top":al,"align-vcenter":el,"align-bottom":nl,"distribute-h":ol,"distribute-v":il,group:wl,image:kl,eye:gl,"eye-off":yl,lock:Sl,unlock:ns,chevron:ml,"text-left":Oo,"text-center":os,"text-right":rs,"text-justify":as,"text-top":ul,"text-middle":dl,"text-bottom":ll,unlink:jl,rotate:Rl,opacity:xl,radius:Hl,blend:fl,plus:Nl,minus:Cl,close:Gl,"chevron-down":pl,check:cl,link:_l,"font-size":Qd,"line-height":$l,"letter-spacing":Al,eyedropper:Dl,document:vl,play:Pl,pause:Ol,scan:Fl,music:Tl,metronome:El,sound:Kl,"sound-off":ql};function Je(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">${hb[e].map(([n,r])=>{let o=Object.entries(r).filter(([a])=>a!=="key").map(([a,s])=>` ${a}="${String(s)}"`).join("");return`<${n}${o} vector-effect="non-scaling-stroke"/>`}).join("")}</svg>`}var Wl="clipboard";function Do(e,t){let n=new Set(t),r=[];return ce(e.root,o=>{if(o.id!==e.root.id&&n.has(o.id))return r.push(o),!1}),r}function sm(e,t){let n={};for(let a of e)ce(a,s=>{for(let[d,l]of Object.entries(s)){if(ke(l)){let f=yt(l.expr);if(!f.ok)continue;for(let c of Nn(f.ast).tokens){let m=t[c];m!==void 0&&(n[c]=m)}continue}typeof l=="string"&&o(l),d==="shadow"&&typeof l=="string"&&r(l)}for(let d of dm(s.content))o(d)});return n;function r(a){let s=t[a],l=fr(typeof s=="string"?s:a);if(!("error"in l))for(let f of l.shadows)o(f.colour)}function o(a){for(let s of $a(a)){let d=t[s];if(d!==void 0&&(n[s]=d,!(typeof d!="string"||d===a)))for(let l of $a(d)){let f=t[l];f!==void 0&&l!==s&&(n[l]=f)}}}}function xb(e,t){let n={};for(let r of e)ce(r,o=>{if(o.type!=="image"||typeof o.src!="string")return;let a=t[o.src];a!==void 0&&(n[o.src]=a)});return n}function im(e,t){let n={},r=o=>{if(typeof o!="string")return;let a=t[o];a!==void 0&&(n[o]=a)};for(let o of e)ce(o,a=>{let s=a;r(s.font);for(let d of dm(s.content,"font"))r(d)});return n}function dm(e,t="fill"){if(!Array.isArray(e))return[];let n=[];for(let r of e){if(typeof r=="string")continue;let o=r[t];o!==void 0&&n.push(o)}return n}function Xl(e,t,n){let r=Do(e,t);if(r.length===0)return null;let o={};for(let d of r)ce(d,l=>{let f=n.nodes.get(l.id)?.values;f&&Object.keys(f).length>0&&(o[l.id]=f)});let a={version:e.version,kind:e.kind,tokens:sm(r,e.tokens),fonts:im(r,e.fonts),assets:xb(r,e.assets),root:{...e.root,children:r}},s=JSON.parse(yi(a));return s[Wl]={resolved:o},JSON.stringify(s,null,2)}function Yl(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!="object"||t===null)return null;let n=t;if(typeof n.root!="object"||n.root===null)return null;let{document:r}=ed(t),o=r.root.children;if(o.length===0)return null;let a=n[Wl],s=typeof a=="object"&&a!==null?a.resolved??{}:{};return{nodes:o,tokens:r.tokens,fonts:r.fonts,resolved:typeof s=="object"&&s!==null?s:{}}}function Jl(e,t){let n=ca(t.root),r=new Map;for(let s of e.nodes)ce(s,d=>{let l=gb(d.id,n);n.add(l),r.set(d.id,l)});let o=s=>n.has(s),a={...e.tokens,...t.tokens};return{nodes:e.nodes.map(s=>lm(s,{payload:e,remap:r,exists:o,tokens:a})),remap:r}}function gb(e,t){let n=e.lastIndexOf("."),r=n===-1?"":e.slice(n+1),o=/^[0-9]+$/.test(r)?e.slice(0,n):e,a=1;for(let s of t){if(!s.startsWith(`${o}.`))continue;let d=Number(s.slice(o.length+1));Number.isInteger(d)&&d>=a&&(a=d+1)}return`${o}.${a}`}function lm(e,t){let n=e,r={};for(let[o,a]of Object.entries(n))o==="id"||o==="children"||(r[o]=ke(a)?yb(a.expr,e.id,o,t):a);return r.id=t.remap.get(e.id)??e.id,be(e)&&(r.children=de(e).map(o=>lm(o,t))),r}function yb(e,t,n,r){let o={expr:e},a=yt(e);if(!a.ok)return o;let s=Nn(a.ast).nodes.some(c=>r.remap.has(c)),d=s?an(a.ast,c=>r.remap.get(c)):a.ast,l=Nn(d);if(l.nodes.some(c=>!r.exists(c))||l.tokens.some(c=>r.tokens[c]===void 0)){let c=r.payload.resolved[t]?.[n];return c===void 0?o:c}return s?{expr:yo(d)}:o}var zt="#ffffff",dn="#0b0d0c",mm="#c6ff3d",vb="#ffb224";var um=new Map;function Be(e,t={}){let n=t.badge??"none",r=e==="resize"?hm(t.angle??0):e==="rotate"?wb(t.angle??0):0,o=`${e}:${r}:${n}`,a=um.get(o);if(a!==void 0)return a;let{at:s,fallback:d}=bb[e],l=Sb(kb(e,r,n),s[0],s[1],d);return um.set(o,l),l}var fm=[2,2],yr=[12,12],bb={arrow:{at:fm,fallback:"default"},radius:{at:fm,fallback:"default"},resize:{at:yr,fallback:"ew-resize"},rotate:{at:yr,fallback:"crosshair"},crosshair:{at:yr,fallback:"crosshair"},grab:{at:yr,fallback:"grab"},grabbing:{at:yr,fallback:"grabbing"},text:{at:yr,fallback:"text"}};function wb(e){let t=(e%360+360)%360;return Math.round(t/15)*15%360}function hm(e){let t=(e%180+180)%180;return Math.round(t/15)*15%180}function kb(e,t,n){switch(e){case"arrow":return xm(n);case"resize":return Eb(t,n);case"rotate":return Cb(t);case"crosshair":return Ab();case"grab":return pm(!1);case"grabbing":return pm(!0);case"radius":return $b(n);case"text":return Mb()}}function _b(e){return`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">${e}</svg>`}function Sb(e,t,n,r){return`url("data:image/svg+xml,${encodeURIComponent(_b(e))}") ${t} ${n}, ${r}`}var cm="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 xm(e){return`<path d="${cm}" fill="${zt}" stroke="${zt}" stroke-width="3" stroke-linejoin="round"/><path d="${cm}" fill="${dn}"/>`+gm(e)}function Eb(e,t){let n=["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"],r=(o,a)=>n.map(s=>`<path d="${s}" stroke="${a}" stroke-width="${o}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+r(3.6,zt)+r(1.6,dn)+"</g>"+gm(t)}function Cb(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"],n=(r,o)=>t.map(a=>`<path d="${a}" stroke="${o}" stroke-width="${r}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+n(3.6,zt)+n(1.6,dn)+"</g>"}function Mb(){let e=["M12 4.5 V19.5","M9 4.5 H15","M9 19.5 H15"],t=(n,r)=>e.map(o=>`<path d="${o}" stroke="${r}" stroke-width="${n}"/>`).join("");return'<g fill="none" stroke-linecap="round">'+t(3.4,zt)+t(1.5,dn)+"</g>"}function Ab(){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="${zt}" stroke-width="3"/><path d="${e}" stroke="${dn}" stroke-width="1.2"/></g>`}function pm(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="${zt}" stroke-width="3.4"/><path d="${t}" stroke="${dn}" stroke-width="1.5"/></g>`}function $b(e){return xm("none")+Tb(e)}function Tb(e){return`<g><rect x="17.5" y="17.5" width="14" height="14" rx="4.5" fill="${zt}"/><rect x="18.7" y="18.7" width="11.6" height="11.6" rx="3.4" fill="${e==="none"?mm:vb}"/><path d="M21.6 27.9 V25.4 A3.8 3.8 0 0 1 25.4 21.6 H27.9" fill="none" stroke="${dn}" stroke-width="1.5" stroke-linecap="round"/></g>`}function gm(e){return e==="none"?"":`<g><rect x="18.5" y="18.5" width="13" height="13" rx="4" fill="${zt}"/><rect x="19.6" y="19.6" width="10.8" height="10.8" rx="3" fill="${mm}"/><text x="25" y="28.4" text-anchor="middle" fill="${dn}" font-family="ui-sans-serif, system-ui, -apple-system, Helvetica, sans-serif" font-size="10" font-weight="700">${e==="token"?"$":"\u0192"}</text></g>`}function We(e,t){let n=[],r=o=>{if(n.push(o.id),o.id===t)return!0;for(let a of de(o))if(r(a))return!0;return n.pop(),!1};return r(e)?n:[]}function ss(e,t,n){let r=We(t.root,e);if(r.length===0)return e;let o=n!==null&&r.includes(n)?n:Ob(r,t),a=r.indexOf(o);return a===-1?e:r[a+1]??e}function Ob(e,t){for(let n=e.length-2;n>=0;n-=1){let r=e[n];if(K(t.root,r)?.type==="frame")return r}return t.root.id}function ym(e,t){let n=e.map(o=>We(t.root,o)).filter(o=>o.length>0);if(n.length===0)return t.root.id;let r=t.root.id;for(let o=0;;o+=1){let a=n[0]?.[o];if(a===void 0||n.some(s=>s[o]!==a||o===s.length-1))break;r=a}return r}function Rn(e,t){let n=K(t.root,e);if(!n)return[];let r=[],o=a=>{if(De(a)){for(let s of de(a))o(s);return}r.push(a.id)};return o(n),r}function Fn(e,t,n){let r=K(t.root,e);if(!r)return;if(!De(r)){let s=n.nodes.get(e);return s?Po(s):void 0}let o=[],a=s=>{if(!(s.id!==e&&"hidden"in s&&s.hidden===!0)){if(s.id!==e&&!De(s)){let d=Fn(s.id,t,n);d&&o.push(d);return}for(let d of de(s))a(d)}};return a(r),vt(o)??void 0}function Po(e){let t={x:e.absX,y:e.absY,w:e.w,h:e.h},n=e.values.rotation??0;return n===0?t:ho(t,n)}function No(e,t,n){return t.flatMap(r=>{let o=Fn(r,e,n);return o?[{id:r,frame:o}]:[]})}function Zl(e,t){let n=t.filter(m=>m!==e.root.id&&K(e.root,m));if(n.length<2)return null;let r=ym(n,e),o=K(e.root,r);if(!o)return null;let a=de(o),s=new Set(n.map(m=>ss(m,e,r))),d=a.filter(m=>s.has(m.id));if(d.length<2)return null;let l=a.findIndex(m=>m.id===d[d.length-1]?.id),f=en(e.root,"group"),c=[{op:"insert",parent:r,index:l+1,node:ai({id:f,children:[]})}];return d.forEach((m,g)=>{c.push({op:"move",id:m.id,parent:f,index:g})}),{ops:c,groupId:f}}function Ql(e,t){let n=K(e.root,t);if(!n||!De(n))return[];let r=We(e.root,t),o=r[r.length-2];if(o===void 0)return[];let a=K(e.root,o);if(!a)return[];let s=de(a).findIndex(l=>l.id===t);if(s===-1)return[];let d=de(n).map((l,f)=>({op:"move",id:l.id,parent:o,index:s+f}));return d.push({op:"remove",id:t}),d}function eu(e,t,n){let r=new Map;for(let a of t){let s=We(e.root,a),d=s[s.length-2];if(d===void 0)continue;let l=r.get(d)??new Set;l.add(a),r.set(d,l)}let o=[];for(let[a,s]of r){let d=K(e.root,a);if(!d)continue;let l=de(d).map(f=>f.id);o.push(...Db(a,l,Lb(l,s,n)))}return o}function Lb(e,t,n){if(n==="front"||n==="back"){let s=e.filter(l=>t.has(l)),d=e.filter(l=>!t.has(l));return n==="front"?[...d,...s]:[...s,...d]}let r=n==="forward"?1:-1,o=[...e],a=o.flatMap((s,d)=>t.has(s)?[d]:[]);r===1&&a.reverse();for(let s of a){let d=s+r,l=o[d];l===void 0||t.has(l)||(o[d]=o[s],o[s]=l)}return o}function Db(e,t,n){let r=[...t],o=[];for(let a=0;a<n.length;a+=1){let s=n[a];s===void 0||r[a]===s||(r.splice(r.indexOf(s),1),r.splice(a,0,s),o.push({op:"move",id:s,parent:e,index:a}))}return o}function tu(e,t,n){let r=t.w===0?1:n.w/t.w,o=t.h===0?1:n.h/t.h,a=new Map;for(let[s,d]of e)a.set(s,{x:n.x+(d.x-t.x)*r,y:n.y+(d.y-t.y)*o,w:d.w*r,h:d.h*o});return a}var nu=6,jt=.01,it={dx:0,dy:0,guides:[],measures:[]},is=["lo","mid","hi"];function ru(e,t,n){let r=[],o=(a,s)=>{let d=t.nodes.get(a);d&&r.push({id:a,frame:Po(d),isPage:s})};return e.root.w!==void 0&&e.root.h!==void 0&&o(e.root.id,!0),ce(e.root,a=>{if(n.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}be(a)||o(a.id,!1)}}),r}function ou(e,t,n){if(n<=0||t.length===0)return it;let r=vr("x",e,t,n,is,!0),o=vr("y",e,t,n,is,!0);return su(e,t,r,o)}function ds(e,t,n,r){if(r<=0||n.length===0)return it;let o=t.includes("w")?["lo"]:t.includes("e")?["hi"]:[],a=t.includes("n")?["lo"]:t.includes("s")?["hi"]:[],s=vr("x",e,n,r,o,!1),d=vr("y",e,n,r,a,!1);return su(e,n,s,d)}function au(e,t,n){let r={x:e.x,y:e.y,w:0,h:0};if(n<=0||t.length===0)return it;let o=vr("x",r,t,n,["lo"],!1),a=vr("y",r,t,n,["lo"],!1);return su(r,t,o,a)}function vr(e,t,n,r,o,a){let s={axis:e,delta:0,kind:"none"};if(o.length===0)return s;let d=Pb(e,t,n,r,o),l=a?Ib(e,t,n,r):null;return d&&l?Math.abs(l.delta)<Math.abs(d.delta)-jt?{axis:e,delta:l.delta,kind:"space",gap:l.gap}:{axis:e,delta:d.delta,kind:"align",at:d.at}:d?{axis:e,delta:d.delta,kind:"align",at:d.at}:l?{axis:e,delta:l.delta,kind:"space",gap:l.gap}:s}function Pb(e,t,n,r,o){let a=null;for(let s of n)for(let d of is){let l=ve(s.frame,e,d);for(let f of o){let c=l-ve(t,e,f);if(Math.abs(c)>r)continue;let m=f==="mid"&&d==="mid";(a===null||Nb(c,m,a))&&(a={at:l,delta:c,centred:m})}}return a?{at:a.at,delta:a.delta}:null}function Nb(e,t,n){let r=Math.abs(e),o=Math.abs(n.delta);return r<o-jt?!0:r>o+jt?!1:t&&!n.centred}function Ib(e,t,n,r){let o=vm(e,t,n);if(o.length<2)return null;let a=bm(t,e),s=ve(t,e,"lo"),d=[];for(let f of Rb(o,e))for(let c of o)d.push({delta:ve(c,e,"hi")+f-s,gap:f}),d.push({delta:ve(c,e,"lo")-f-a-s,gap:f});for(let f=0;f+1<o.length;f+=1){let c=o[f],m=o[f+1];if(!c||!m)continue;let g=ve(m,e,"lo")-ve(c,e,"hi")-a;g<=jt||d.push({delta:ve(c,e,"hi")+g/2-s,gap:g/2})}let l=null;for(let f of d)Math.abs(f.delta)>r||(l===null||Math.abs(f.delta)<Math.abs(l.delta)-jt)&&(l=f);return l}function vm(e,t,n){let r=iu(e);return n.filter(o=>!o.isPage&&Hb(o.frame,t,r)).map(o=>o.frame).sort((o,a)=>ve(o,e,"lo")-ve(a,e,"lo"))}function Rb(e,t){let n=[];for(let r=0;r+1<e.length;r+=1){let o=e[r],a=e[r+1];if(!o||!a)continue;let s=ve(a,t,"lo")-ve(o,t,"hi");s<=jt||n.some(d=>Math.abs(d-s)<jt)||n.push(s)}return n}function su(e,t,n,r){let o={...e,x:e.x+n.delta,y:e.y+r.delta},a=[],s=[];for(let d of[n,r]){if(d.kind==="align"&&d.at!==void 0){let l=Fb(d.axis,d.at,o,t);l&&a.push(l)}d.kind==="space"&&d.gap!==void 0&&s.push(...Bb(d.axis,d.gap,o,t))}return{dx:n.delta,dy:r.delta,guides:a,measures:s}}function Fb(e,t,n,r){let o=iu(e),a=ve(n,o,"lo"),s=ve(n,o,"hi"),d=!1;for(let l of r)is.some(f=>Ub(ve(l.frame,e,f),t))&&(d=!0,a=Math.min(a,ve(l.frame,o,"lo")),s=Math.max(s,ve(l.frame,o,"hi")));return d?{axis:e,at:t,from:a,to:s}:null}function Bb(e,t,n,r){let o=iu(e),a=[...vm(e,n,r),n].sort((d,l)=>ve(d,e,"lo")-ve(l,e,"lo")),s=[];for(let d=0;d+1<a.length;d+=1){let l=a[d],f=a[d+1];if(!l||!f)continue;let c=ve(f,e,"lo")-ve(l,e,"hi");if(Math.abs(c-t)>jt)continue;let m=Math.max(ve(l,o,"lo"),ve(f,o,"lo")),g=Math.min(ve(l,o,"hi"),ve(f,o,"hi"));s.push({axis:e,at:(m+g)/2,from:ve(l,e,"hi"),to:ve(f,e,"lo"),label:Vb(c)})}return s}function iu(e){return e==="x"?"y":"x"}function bm(e,t){return t==="x"?e.w:e.h}function ve(e,t,n){let r=t==="x"?e.x:e.y,o=bm(e,t);return n==="lo"?r:n==="hi"?r+o:r+o/2}function Hb(e,t,n){return ve(e,n,"lo")<ve(t,n,"hi")&&ve(e,n,"hi")>ve(t,n,"lo")}function Ub(e,t){return Math.abs(e-t)<jt}function Vb(e){return String(Math.round(e*100)/100)}var Io=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 n=this.past[this.past.length-1];return n?(this.past[this.past.length-1]={label:t.label,ops:[...n.ops,...t.ops],inverse:[...t.inverse,...n.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 n=this.past.length-t.length;return t.every((r,o)=>this.past[n+o]===r)}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 wm=1,zb=48,jb=.06,Kb=.5;function km(e){return Math.max(zb,Math.min(e.width,e.height)*jb)}function du(e,t){let n=new Set(t),r=[];for(let o of e.root.children)(n.has(o.id)||_m(o,n))&&r.push(o.id);return r}function _m(e,t){for(let n of de(e))if(t.has(n.id)||_m(n,t))return!0;return!1}function ls(e){let t=e.filter(s=>s.w>0&&s.h>0);if(t.length===0)return null;let n=Math.min(...t.map(s=>s.x)),r=Math.min(...t.map(s=>s.y)),o=Math.max(...t.map(s=>s.x+s.w)),a=Math.max(...t.map(s=>s.y+s.h));return{x:n,y:r,w:o-n,h:a-r}}function us(e,t){let n=km(t),r={width:Math.max(1,t.width-n*2),height:Math.max(1,t.height-n*2)},o=hr(Math.min(r.width/e.w,r.height/e.h,wm));return{zoom:o,x:t.width/2-(e.x+e.w/2)*o,y:t.height/2-(e.y+e.h/2)*o}}function lu(e,t,n){let r=us(e,t);return qb(e,t,n)&&n.zoom>=r.zoom*Kb?null:r}function qb(e,t,n){let r=e.x*n.zoom+n.x,o=e.y*n.zoom+n.y,a=(e.x+e.w)*n.zoom+n.x,s=(e.y+e.h)*n.zoom+n.y;return r>=0&&o>=0&&a<=t.width&&s<=t.height}function Sm(e,t,n,r){let o=Math.exp(Math.log(e.zoom)+(Math.log(t.zoom)-Math.log(e.zoom))*n),a={x:r.width/2,y:r.height/2},s={x:(a.x-e.x)/e.zoom,y:(a.y-e.y)/e.zoom},d={x:(a.x-t.x)/t.zoom,y:(a.y-t.y)/t.zoom},l={x:s.x+(d.x-s.x)*n,y:s.y+(d.y-s.y)*n};return{zoom:o,x:a.x-l.x*o,y:a.y-l.y*o}}function Em(e){return 1-(1-e)**3}function Gb(e){return!("separator"in e)}function uu(e,t=[]){let n=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"},...Cm(e),{separator:!0},{id:"fit",label:"Fit to screen",keys:"Shift+1"},{id:"zoom100",label:"Zoom to 100%",keys:"CmdOrCtrl+0"},...n];let r=[];e.isText&&e.count===1&&r.push({id:"editText",label:"Edit text",keys:"Enter"},{separator:!0}),e.isVector&&e.count===1&&r.push({id:"editPoints",label:"Edit points",keys:"Enter"},{separator:!0}),(e.convertible??0)>0&&r.push({id:"toVector",label:"Convert to vector",keys:"CmdOrCtrl+Shift+O"},{separator:!0}),r.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&&r.push({separator:!0},...o),r.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){r.push({separator:!0});for(let a of e.bound)r.push({id:`detach:${a.prop}`,label:`Detach ${a.prop}`,hint:a.source})}return r.push(...Cm(e)),r.push(...n),r.push({separator:!0},{id:"delete",label:"Delete",keys:"Delete"}),r}var Wb=4;function Cm(e){let t=(e.locksHere??[]).slice(0,Wb).map(r=>({id:`unlock:${r}`,label:`Unlock ${r}`}));e.anyLocked&&t.push({id:"unlockAll",label:"Unlock all"});let n=e.hiddenCount??0;return n>0&&t.push({id:"showAll",label:`Show all hidden (${n})`}),t.length===0?[]:[{separator:!0},...t]}function fs(e,t){let n=e.ownerDocument,r=t.formatKeys??Lo,o=n.createElement("div");o.className="vd-menu",o.setAttribute("role","menu"),o.hidden=!0,e.appendChild(o);let a=!1,s=[],d=-1;function l(w){o.replaceChildren(),s=[];for(let L of w){if(!Gb(L)){let N=n.createElement("div");N.className="vd-menu__separator",o.appendChild(N);continue}let $=n.createElement("button");$.type="button",$.className="vd-menu__item",$.dataset.command=L.id,$.disabled=L.disabled===!0,$.setAttribute("role","menuitem");let z=n.createElement("span");z.textContent=L.label,$.appendChild(z);let A=L.hint??(L.keys===void 0?void 0:r(L.keys));if(A!==void 0){let N=n.createElement("span");N.className="vd-menu__hint",N.textContent=A,$.appendChild(N)}o.appendChild($),$.disabled||s.push($)}}function f(w){o.style.left=`${w.x}px`,o.style.top=`${w.y}px`;let L=e.getBoundingClientRect(),$=t.bounds?.()??L,z=o.getBoundingClientRect();if(z.width===0&&z.height===0)return;let A=L.left+w.x+z.width-$.right,N=L.top+w.y+z.height-$.bottom;A>0&&(o.style.left=`${Math.max($.left-L.left,w.x-z.width)}px`),N>0&&(o.style.top=`${Math.max($.top-L.top,w.y-z.height)}px`)}function c(w){s.length!==0&&(d=(w+s.length)%s.length,s[d]?.focus())}let m=w=>{let L=w.target?.closest("button");if(!L||L.disabled)return;w.stopPropagation();let $=L.dataset.command;v(),$&&t.onCommand($)},g=w=>w.stopPropagation(),b=w=>{w.key==="ArrowDown"?(w.preventDefault(),c(d+1)):w.key==="ArrowUp"?(w.preventDefault(),c(d-1)):w.key==="Escape"&&(w.preventDefault(),w.stopPropagation(),v(),t.returnFocus?t.returnFocus():e.focus())},E=w=>{a&&(w.target instanceof Node&&o.contains(w.target)||v())};function v(){a&&(a=!1,d=-1,o.hidden=!0,n.removeEventListener("pointerdown",E,!0),n.removeEventListener("wheel",E,!0))}return o.addEventListener("click",m),o.addEventListener("pointerdown",g),o.addEventListener("keydown",b),{element:o,get isOpen(){return a},open(w,L){l(L),o.hidden=!1,a=!0,f(w),n.addEventListener("pointerdown",E,!0),n.addEventListener("wheel",E,!0),c(0)},close:v,destroy(){v(),o.removeEventListener("click",m),o.removeEventListener("pointerdown",g),o.removeEventListener("keydown",b),o.remove()}}}var br=2,Mm=1.5,Am=1.5,$m=1.5,Fm={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},Tm=3.6,Xb=22,cs=14,ps=15,fu=4,Om=15,Lm=23,Ro=7,Yb=3.5,ms=12,Jb=4.5,hs=16,dt=18,cu=9,pu=6.1,Dm="Drop or double-click",Zb=6.4,Pm=16,ln=3,Nm=5,Qb=11,Im=6,Rm=6.4;function Bm(e,t){let n=e.ownerDocument,r=n.createElementNS(xe,"svg");r.setAttribute("class","vd-editor__overlay"),e.appendChild(r);let o=[],a=[],s=[],d=[],l=[],f=null,c=null,m=[],g=[];function b(S){let y=t({x:S.x,y:S.y}),T=t({x:S.x+S.w,y:S.y+S.h});return{x:y.x,y:y.y,w:T.x-y.x,h:T.y-y.y}}function E(S){for(;r.firstChild;)r.removeChild(r.firstChild);o=[],a=[],s=[],d=[],l=[],f=null,c=null,m=[],g=(S.pageLabels??[]).flatMap(T=>C(T));let y=S.turn&&S.turn.angle!==0?{angle:S.turn.angle,centre:t(S.turn.centre)}:null;for(let T of S.slots??[])q(T);S.presence&&ee(S.presence);for(let T of S.highlight)oe("vd-editor__highlight",wr(b(T),br),br);S.lockHint&&R(S.lockHint),S.hover&&oe("vd-editor__hover",Fo(b(S.hover)),Am);for(let T of S.parked)oe("vd-editor__parked",Fo(b(T)),Am);for(let T of S.members)oe("vd-editor__member",wr(b(T),Mm),Mm);S.lead&&oe("vd-editor__lead",Fo(b(S.lead)),br);for(let T of S.guides)j(T);for(let T of S.measures)O(T);if(v(y,()=>{for(let T of S.textSelection)r.appendChild(se("vd-editor__text-selection",b(T)))}),S.box&&N(S.box),S.caret&&v(y,()=>$(S.caret)),d=S.rings.map(z),s=S.spacers.map(A),S.badge&&S.box){let T=b(S.box.frame),D=f?Math.max(...[{x:T.x,y:T.y},{x:T.x+T.w,y:T.y},{x:T.x,y:T.y+T.h},{x:T.x+T.w,y:T.y+T.h}].map(U=>nt(U,f.centre,f.angle).y)):T.y+T.h;V(S.badge,{x:T.x+T.w/2,y:D+cu+dt/2})}if(S.draft){let T=b(S.draft);if(S.draftEllipse){let D=n.createElementNS(xe,"ellipse");D.setAttribute("class","vd-editor__draft"),D.setAttribute("cx",String(T.x+T.w/2)),D.setAttribute("cy",String(T.y+T.h/2)),D.setAttribute("rx",String(Math.abs(T.w)/2)),D.setAttribute("ry",String(Math.abs(T.h)/2)),r.appendChild(D)}else r.appendChild(se("vd-editor__draft",T))}S.marquee&&r.appendChild(se("vd-editor__marquee",b(S.marquee))),S.path&&(c=y,v(y,()=>L(S.path)))}function v(S,y){if(!S){y();return}let T=r.childNodes.length;y();let D=n.createElementNS(xe,"g");for(D.setAttribute("transform",`rotate(${S.angle} ${S.centre.x} ${S.centre.y})`);r.childNodes.length>T;)D.insertBefore(r.childNodes[r.childNodes.length-1],D.firstChild);r.appendChild(D)}function w(S,y){return y?nt(S,y.centre,-y.angle):S}function L(S){let y=n.createElementNS(xe,"path");if(y.setAttribute("class","vd-editor__path"),y.setAttribute("d",Nt(It(S.contours,t))),r.appendChild(y),S.pending){let D=t(S.pending.from),U=t(S.pending.to),X=S.pending.c1?t(S.pending.c1):D,H=n.createElementNS(xe,"path");H.setAttribute("class","vd-editor__pending"),H.setAttribute("d",`M${D.x} ${D.y} C${X.x} ${X.y} ${U.x} ${U.y} ${U.x} ${U.y}`),r.appendChild(H)}for(let D of S.handles){let U=t(D.at),X=t(D.anchor),H=n.createElementNS(xe,"line");H.setAttribute("class","vd-editor__arm"),H.setAttribute("x1",String(X.x)),H.setAttribute("y1",String(X.y)),H.setAttribute("x2",String(U.x)),H.setAttribute("y2",String(U.y)),r.appendChild(H)}for(let D of S.handles){let U=t(D.at),X=n.createElementNS(xe,"circle");X.setAttribute("class","vd-editor__knob"),X.setAttribute("cx",String(U.x)),X.setAttribute("cy",String(U.y)),X.setAttribute("r",String(Yb)),r.appendChild(X)}for(let D of S.anchors){let U=t(D.at),X=se(D.selected?"vd-editor__anchor vd-editor__anchor--on":"vd-editor__anchor",{x:Math.round(U.x-Ro/2)+.5,y:Math.round(U.y-Ro/2)+.5,w:Ro,h:Ro});X.setAttribute("data-key",D.key),r.appendChild(X)}if(S.closeAt){let D=t(S.closeAt),U=n.createElementNS(xe,"circle");U.setAttribute("class","vd-editor__close"),U.setAttribute("cx",String(D.x)),U.setAttribute("cy",String(D.y)),U.setAttribute("r",String(Ro)),r.appendChild(U)}let T=D=>({x:D.x-ms/2,y:D.y-ms/2,w:ms,h:ms});l=[...[...S.handles].reverse().map(D=>({kind:"handle",key:D.key,rect:T(t(D.at))})),...[...S.anchors].reverse().map(D=>({kind:"anchor",key:D.key,rect:T(t(D.at))}))]}function $(S){let y=t({x:S.x,y:S.y}),T=t({x:S.x,y:S.y+S.h}),D=n.createElementNS(xe,"line");D.setAttribute("class","vd-editor__caret");let U=Math.round(y.x)+.5;D.setAttribute("x1",String(U)),D.setAttribute("y1",String(y.y)),D.setAttribute("x2",String(U)),D.setAttribute("y2",String(T.y)),S.fill!==void 0&&!S.fill.startsWith("url(")&&(D.style.stroke=S.fill),r.appendChild(D)}function z(S){let y=t(S.at),T=n.createElementNS(xe,"circle");return T.setAttribute("class","vd-editor__ring"),T.setAttribute("cx",String(y.x)),T.setAttribute("cy",String(y.y)),T.setAttribute("r",String(Jb)),r.appendChild(T),{id:S.id,rect:{x:y.x-hs/2,y:y.y-hs/2,w:hs,h:hs}}}function A(S){let y=t(S.at),T=S.axis==="x"?fu:ps,D=S.axis==="x"?ps:fu,U=se("vd-editor__spacer",{x:y.x-T/2,y:y.y-D/2,w:T,h:D});U.setAttribute("rx",String(fu/2)),r.appendChild(U),S.label!==null&&V(S.label,S.axis==="x"?{x:y.x,y:y.y-ps/2-cu-dt/2}:{x:y.x+ps/2+cu+dt,y:y.y});let X=S.axis==="x"?Om:Lm,H=S.axis==="x"?Lm:Om;return{id:S.id,rect:{x:y.x-X/2,y:y.y-H/2,w:X,h:H}}}function N(S){let y=b(S.frame),T=S.rotation??0;f=T===0?null:{angle:T,centre:{x:y.x+y.w/2,y:y.y+y.h/2}},v(f,()=>I(S,y)),S.handles&&S.rotatable&&(m=Mo.map(D=>{let{u:U,v:X}=xr(D);return{handle:D,at:{x:y.x+y.w*U,y:y.y+y.h*X}}}))}function I(S,y){if(oe("vd-editor__outline",wr(y,br),br),!!S.handles){o=Kd(y).map(T=>({...T,bound:S.boundHandles.has(T.handle)}));for(let T of Mo){let{u:D,v:U}=xr(T),X={x:y.x+y.w*D-gr/2,y:y.y+y.h*U-gr/2,w:gr,h:gr};r.appendChild(se("vd-editor__halo",wr(X,$m+1))),r.appendChild(se("vd-editor__handle",X))}a=S.adjusters.map(T=>{let D=t(T.at),U=n.createElementNS(xe,"circle");U.setAttribute("class","vd-editor__halo"),U.setAttribute("cx",String(D.x)),U.setAttribute("cy",String(D.y)),U.setAttribute("r",String(Tm+$m/2+.5)),r.appendChild(U);let X=n.createElementNS(xe,"circle");return X.setAttribute("class","vd-editor__adjuster"),X.setAttribute("cx",String(D.x)),X.setAttribute("cy",String(D.y)),X.setAttribute("r",String(Tm)),r.appendChild(X),{id:T.id,bound:T.bound,rect:{x:D.x-cs/2,y:D.y-cs/2,w:cs,h:cs}}})}}function j(S){let y=t(S.axis==="x"?{x:S.at,y:S.from}:{x:S.from,y:S.at}),T=t(S.axis==="x"?{x:S.at,y:S.to}:{x:S.to,y:S.at}),D=n.createElementNS(xe,"line");D.setAttribute("class","vd-editor__guide"),D.setAttribute("x1",String($e(y.x))),D.setAttribute("y1",String($e(y.y))),D.setAttribute("x2",String($e(T.x))),D.setAttribute("y2",String($e(T.y))),r.appendChild(D)}function O(S){let y=t(S.axis==="x"?{x:S.from,y:S.at}:{x:S.at,y:S.from}),T=t(S.axis==="x"?{x:S.to,y:S.at}:{x:S.at,y:S.to}),D=n.createElementNS(xe,"path");D.setAttribute("class","vd-editor__measure"),D.setAttribute("d",S.axis==="x"?`M${$e(y.x)} ${$e(y.y)-ln} V${$e(y.y)+ln} M${$e(y.x)} ${$e(y.y)} H${$e(T.x)} M${$e(T.x)} ${$e(T.y)-ln} V${$e(T.y)+ln}`:`M${$e(y.x)-ln} ${$e(y.y)} H${$e(y.x)+ln} M${$e(y.x)} ${$e(y.y)} V${$e(T.y)} M${$e(T.x)-ln} ${$e(T.y)} H${$e(T.x)+ln}`),r.appendChild(D);let U=n.createElementNS(xe,"text");U.setAttribute("class","vd-editor__measure-text"),U.setAttribute("x",String((y.x+T.x)/2)),U.setAttribute("y",String((y.y+T.y)/2-(S.axis==="x"?Nm:0))),S.axis==="y"&&U.setAttribute("dx",String(Nm)),U.textContent=S.label,r.appendChild(U)}function V(S,y){let T=Math.max(34,S.length*pu+14),D=y.x-T/2,U=y.y-dt/2,X=se("vd-editor__badge",{x:D,y:U,w:T,h:dt});X.setAttribute("rx",String(dt/2)),r.appendChild(X);let H=n.createElementNS(xe,"text");H.setAttribute("class","vd-editor__badge-text"),H.setAttribute("x",String(D+T/2)),H.setAttribute("y",String(U+dt/2)),H.textContent=S,r.appendChild(H)}function C(S){let y=b(S.frame),T=Math.floor(y.w/Rm);if(T<3)return[];let D=S.label.length>T?`${S.label.slice(0,T-1)}\u2026`:S.label,U=n.createElementNS(xe,"text");U.setAttribute("class",`vd-editor__page-label vd-editor__page-label--${S.state}`),U.setAttribute("x",String(y.x)),U.setAttribute("y",String(y.y-Im)),U.textContent=D,r.appendChild(U);let X=Math.min(y.w,D.length*Rm+4),H=Qb+6;return[{id:S.id,rect:{x:y.x,y:y.y-Im-H+3,w:X,h:H}}]}function R(S){let y=Fo(b(S.frame));r.appendChild(se("vd-editor__lock",y));let T=`${S.label} \xB7 locked`,D=T.length*pu+14,U=y.y+4,X=se("vd-editor__lock-tag",{x:y.x+4,y:U,w:D,h:dt});X.setAttribute("rx","4"),r.appendChild(X);let H=n.createElementNS(xe,"text");H.setAttribute("class","vd-editor__lock-text"),H.setAttribute("x",String(y.x+4+D/2)),H.setAttribute("y",String(U+dt/2)),H.textContent=T,r.appendChild(H)}function q(S){let y=Fo(b(S.frame)),T=se(S.target?"vd-editor__slot vd-editor__slot--target":"vd-editor__slot",y);T.setAttribute("rx","3"),r.appendChild(T);let D=H=>H.length*Zb+16<=y.w,U=[];y.h>=20&&D(S.label)&&U.push([S.label,"vd-editor__slot-label"]),U.length>0&&y.h>=48&&D(Dm)&&U.push([Dm,"vd-editor__slot-hint"]);let X=y.y+y.h/2-(U.length-1)*Pm/2;U.forEach(([H,ie],_e)=>{let Me=n.createElementNS(xe,"text");Me.setAttribute("class",ie),Me.setAttribute("x",String(y.x+y.w/2)),Me.setAttribute("y",String(X+_e*Pm)),Me.textContent=H,r.appendChild(Me)})}function ee(S){let y=S.frames.map(ie=>wr(b(ie),br));for(let ie of y)r.appendChild(se("vd-editor__presence",ie));let T=y[0];if(!T||!S.label)return;let D=Math.max(34,S.label.length*pu+14),U=T.y-dt-3<0?T.y+3:T.y-dt-3,X=se("vd-editor__presence-tag",{x:T.x,y:U,w:D,h:dt});X.setAttribute("rx","4"),r.appendChild(X);let H=n.createElementNS(xe,"text");H.setAttribute("class","vd-editor__presence-text"),H.setAttribute("x",String(T.x+D/2)),H.setAttribute("y",String(U+dt/2)),H.textContent=S.label,r.appendChild(H)}function oe(S,y,T){let U=S==="vd-editor__highlight"?"vd-editor__halo vd-editor__halo--highlight":S==="vd-editor__hover"||S==="vd-editor__member"?"vd-editor__halo vd-editor__halo--quiet":"vd-editor__halo";r.appendChild(se(U,wr(y,T+1))),r.appendChild(se(S,y))}function se(S,y){let T=n.createElementNS(xe,"rect");return T.setAttribute("class",S),T.setAttribute("x",String(y.x)),T.setAttribute("y",String(y.y)),T.setAttribute("width",String(Math.max(0,y.w))),T.setAttribute("height",String(Math.max(0,y.h))),T}return{element:r,render:E,hitHandle(S){let y=w(S,f);for(let T of o)if(bt(T.rect,y.x,y.y))return{handle:T.handle,bound:T.bound};return null},hitAdjuster(S){let y=w(S,f);for(let T of a)if(bt(T.rect,y.x,y.y))return{id:T.id,bound:T.bound};return null},hitSpacer(S){return mu(s,S)},hitPath(S){let y=w(S,c),T=l.find(D=>bt(D.rect,y.x,y.y));return T?{kind:T.kind,key:T.key}:null},hitRotate(S){let y=w(S,f),T=o.length===0?null:m;if(!T)return null;for(let D of T){let U=Math.hypot(y.x-D.at.x,y.y-D.at.y);if(U<gr/2+2||U>Xb)continue;let{u:X,v:H}=xr(D.handle);if((y.x-D.at.x)*(X*2-1)+(y.y-D.at.y)*(H*2-1)>0)return D.handle}return null},hitRing(S){return mu(d,S)},hitPageLabel(S){return mu(g,S)},pageLabelRect(S){return g.find(y=>y.id===S)?.rect??null},destroy(){r.remove(),o=[],a=[],s=[],d=[]}}}function mu(e,t){for(let n of e)if(bt(n.rect,t.x,t.y))return n.id;return null}function $e(e){return Math.round(e)+.5}function Fo(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 wr(e,t){let n=t/2;return{x:e.x-n,y:e.y-n,w:e.w+t,h:e.h+t}}function Hm(e,t){let n=[];return ce(e.root,r=>{if(t.has(r.id))return!1;r.type!=="image"||ke(r.src)||e.assets[r.src]===void 0&&n.push({id:r.id,src:r.src,label:r.name??r.src})}),n}function xu(e){if(e.length<2)return null;let t=hu("x",e),n=hu("y",e);return n.length===1&&t.length===e.length?Um("x",e,t):t.length===1&&n.length===e.length?Um("y",e,n):n.length>=2&&t.length>=2?e0(e,t,n):null}function hu(e,t){let n=[...t].sort((o,a)=>kr(o.frame,e)-kr(a.frame,e)),r=[];for(let o of n){let a=r[r.length-1];if(a&&kr(o.frame,e)<a.hi-.01){r[r.length-1]={lo:a.lo,hi:Math.max(a.hi,gs(o.frame,e)),from:Math.min(a.from,kr(o.frame,xs(e))),to:Math.max(a.to,gs(o.frame,xs(e))),members:[...a.members,o.id]};continue}r.push({lo:kr(o.frame,e),hi:gs(o.frame,e),from:kr(o.frame,xs(e)),to:gs(o.frame,xs(e)),members:[o.id]})}return r}function Um(e,t,n){return{kind:"run",items:t,series:[ys(e,n)],order:n.flatMap(r=>r.members)}}function e0(e,t,n){if(t.length*n.length!==e.length)return null;let r=[];for(let o of n)for(let a of t){let s=o.members.filter(d=>a.members.includes(d));if(s.length!==1||s[0]===void 0)return null;r.push(s[0])}return{kind:"grid",items:e,series:[ys("x",t),ys("y",n)],order:r}}function ys(e,t){let n=[];for(let r=0;r+1<t.length;r+=1){let o=t[r],a=t[r+1];!o||!a||n.push(a.lo-o.hi)}return{axis:e,tracks:t,gaps:n}}function Tt(e,t){return e.series.find(n=>n.axis===t)}function gu(e){let t=e[0];return t===void 0?!1:e.every(n=>Math.abs(n-t)<.01)}function yu(e){let t=[];for(let n of e.series){let r=e.series.find(o=>o.axis!==n.axis);for(let o=0;o<n.gaps.length;o+=1){let a=n.tracks[o],s=n.tracks[o+1],d=n.gaps[o];if(!a||!s||d===void 0)continue;let l=(a.hi+s.lo)/2,f=r?r.tracks.map(c=>(c.lo+c.hi)/2):[(Math.max(a.from,s.from)+Math.min(a.to,s.to))/2];for(let c of f)t.push({id:Vm(n.axis,o),axis:n.axis,index:o,gap:d,at:n.axis==="x"?{x:l,y:c}:{x:c,y:l}})}}return t}function Vm(e,t){return`${e}:${t}`}function vs(e){let[t,n]=e.split(":");if(t!=="x"&&t!=="y"||n===void 0)return null;let r=Number(n);return Number.isInteger(r)&&r>=0?{axis:t,index:r}:null}function vu(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 bs(e,t,n){let r=Tt(e,t);return r?ws(r,n):new Map}function ws(e,t){let n=new Map,r=e.tracks[0];if(!r)return n;let o=r.hi;for(let a=1;a<e.tracks.length;a+=1){let s=e.tracks[a];if(!s)continue;let d=o+t;for(let l of s.members)n.set(l,d-s.lo);o=d+(s.hi-s.lo)}return n}function bu(e,t){return ys(t,hu(t,e))}function wu(e){let t=e.tracks,n=t[0],r=t[t.length-1];if(!n||!r||t.length<3)return null;let o=t.reduce((a,s)=>a+(s.hi-s.lo),0);return(r.hi-n.lo-o)/(t.length-1)}function ku(e,t){let n=t0(e),r=0,o=1/0;for(let a=0;a<n.length;a+=1){let s=n[a];if(!s)continue;let d=Math.hypot(s.x-t.x,s.y-t.y);d<o&&(o=d,r=a)}return r}function t0(e){if(e.kind==="grid"){let n=Tt(e,"x")?.tracks??[];return(Tt(e,"y")?.tracks??[]).flatMap(o=>n.map(a=>({x:(a.lo+a.hi)/2,y:(o.lo+o.hi)/2})))}let t=e.series[0];return t?t.tracks.map(n=>t.axis==="x"?{x:(n.lo+n.hi)/2,y:(n.from+n.to)/2}:{x:(n.from+n.to)/2,y:(n.lo+n.hi)/2}):[]}function _u(e,t,n){let r=[...e],[o]=r.splice(t,1);return o===void 0?[...e]:(r.splice(Math.max(0,Math.min(n,r.length)),0,o),r)}function Su(e,t){let n=new Map(e.items.map(d=>[d.id,d.frame])),r=new Map;if(e.kind==="grid"){let d=Tt(e,"x")?.tracks??[],l=Tt(e,"y")?.tracks??[];return t.forEach((f,c)=>{let m=d[c%d.length],g=l[Math.floor(c/d.length)];m&&g&&r.set(f,{x:m.lo,y:g.lo})}),r}let o=e.series[0],a=o?.tracks[0];if(!o||!a)return r;let s=a.lo;return t.forEach((d,l)=>{let f=n.get(d);if(!f)return;let c=o.axis==="x"?f.w:f.h;r.set(d,o.axis==="x"?{x:s,y:f.y}:{x:f.x,y:s}),s+=c+(o.gaps[l]??0)}),r}function Eu(e,t,n){let r=new Map,o=e.items.find(l=>l.id===t),a=e.items.find(l=>l.id===n);if(!o||!a||t===n)return r;let s=e.kind==="grid"?["x","y"]:[e.series[0]?.axis??"x"],d=(l,f)=>({x:s.includes("x")?f.frame.x:l.frame.x,y:s.includes("y")?f.frame.y:l.frame.y});return r.set(t,d(o,a)),r.set(n,d(a,o)),r}function xs(e){return e==="x"?"y":"x"}function kr(e,t){return t==="x"?e.x:e.y}function gs(e,t){return t==="x"?e.x+e.w:e.y+e.h}var zm="vd-editor-styles",jm=`
140
140
  .vd-editor {
141
141
  position: relative;
142
142
  width: 100%;
@@ -2786,13 +2786,13 @@ button.vd-field__swatch:focus-visible {
2786
2786
  background: rgb(255 255 255 / 0.09);
2787
2787
  color: #fff;
2788
2788
  }
2789
- `;function gr(e){if(e.getElementById(mm))return;let t=e.createElement("style");t.id=mm,t.textContent=hm,e.head.appendChild(t)}var on=["font","size","weight","italic","underline","strike","fill","letterSpacing","link"];function Pn(e){return typeof e=="string"?e===""?[]:[{text:e}]:e.flatMap(t=>typeof t=="string"?t===""?[]:[{text:t}]:t.text===""?[]:[t])}function In(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function Nn(e){return In(e).length}function Dn(e){let t={};for(let n of on){let r=e[n];r!==void 0&&(t[n]=r)}return t}function ym(e,t){return on.every(n=>e[n]===t[n])}function w0(e,t){let n={text:e};for(let r of on){let o=t[r];o!==void 0&&(n[r]=o)}return n}function Oo(e){let t=Pn(e),n=[];for(let o of t){let a=n[n.length-1];if(a&&ym(Dn(a),Dn(o))){n[n.length-1]={...a,text:a.text+o.text};continue}n.push(o)}if(n.length===0)return"";let r=n[0];return n.length===1&&xm(r)?r.text:n.map(o=>xm(o)?o.text:o)}function xm(e){return on.every(t=>e[t]===void 0)}function lf(e,t,n){let[r,o]=di(t,n,Nn(e)),a=[],i=0;for(let l of Pn(e)){let d=i+l.text.length,u=Math.max(r,i),p=Math.min(o,d);p>u&&a.push({...l,text:l.text.slice(u-i,p-i)}),i=d}return Oo(a)}function yr(e,t,n,r,o){let a=Nn(e),[i,l]=di(t,n,a),d=o??Do(e,i),u=[],p=0,x=!1,y=()=>{x||r===""||(u.push(w0(r,d)),x=!0)};for(let k of Pn(e)){let M=p+k.text.length,v=Math.min(i,M);v>p&&u.push({...k,text:k.text.slice(0,v-p)}),i>=p&&i<=M&&y();let w=Math.max(l,p);M>w&&u.push({...k,text:k.text.slice(w-p)}),p=M}return y(),Oo(u)}function Do(e,t){let n=Pn(e);if(n.length===0)return{};let r=0,o=n[0];for(let a of n){let i=r+a.text.length;if(t>r&&t<=i)return Dn(a);if(t<=r)return Dn(o);o=a,r=i}return Dn(o)}function df(e,t,n,r){let[o,a]=di(t,n,Nn(e));if(o===a)return Oo(e);let i=Object.keys(r),l=[],d=0;for(let u of Pn(e)){let p=d+u.text.length;for(let[x,y,k]of k0(d,p,o,a)){if(y<=x)continue;let M=u.text.slice(x-d,y-d);if(!k){l.push({...u,text:M});continue}let v={...u,text:M};for(let w of i)r[w]===void 0?delete v[w]:v[w]=r[w];l.push(v)}d=p}return Oo(l)}function k0(e,t,n,r){return[[e,Math.min(t,n),!1],[Math.max(e,n),Math.min(t,r),!0],[Math.max(e,r),t,!1]]}function ff(e,t,n){let[r,o]=di(t,n,Nn(e));if(r===o)return Do(e,r);let a,i=0;for(let l of Pn(e)){let d=i+l.text.length;if(Math.min(d,o)>Math.max(i,r)){let u=Dn(l);if(!a)a=u;else{let p={};for(let x of on)a[x]===u[x]&&a[x]!==void 0&&(p[x]=a[x]);a=p}}i=d}return a??{}}function di(e,t,n){let r=gm(Math.min(e,t),n),o=gm(Math.max(e,t),n);return[r,o]}function gm(e,t){return Math.max(0,Math.min(Math.round(e),t))}function vr(e,t){let n=[],r=0;return e.lines.forEach((o,a)=>{let i=o.spans.map(p=>p.text).join(""),l=i===""?r:_0(t,i,r),d=l+i.length,u=a===e.lines.length-1;n.push({start:l,end:u?t.length:d}),r=d}),n.length===0&&n.push({start:0,end:t.length}),n}function _0(e,t,n){let r=e.indexOf(t,n);return r===-1?n:r}function fi(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if(t<=r.end)return n}return Math.max(0,e.length-1)}function ui(e,t,n,r){let o=vr(e,t),a=fi(o,n),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(n-l.start,bm(i))),u=(S0(i,d)??i.style)?.fill;return{x:uf(i,d,r),y:i.y,h:i.h,line:a,...u!==void 0?{fill:u}:{}}}function S0(e,t){let n=0;for(let r of e.spans)if(n+=[...r.text].length,t<=n)return r.style;return e.spans[e.spans.length-1]?.style}function Po(e,t,n,r){let o=vr(e,t);if(e.lines.length===0)return 0;let a=e.lines.findIndex(d=>n.y<d.y+d.h);a===-1&&(a=e.lines.length-1);let i=e.lines[a];return o[a].start+vm(i,n.x,r)}function vm(e,t,n){let r=0,o=1/0,a=0,i=(l,d)=>{let u=Math.abs(d-t);u<o&&(o=u,r=l)};i(0,e.spans[0]?.x??0);for(let l of e.spans){let d=[...l.text],u=0;d.forEach((p,x)=>{u=n.advance(d.slice(0,x+1).join(""),l.style),i(a+x+1,l.x+u)}),a+=d.length}return r}function uf(e,t,n){let r=0,o=e.spans[0]?.x??0;for(let a of e.spans){let i=[...a.text];if(t<=r)return a.x;if(t>=r+i.length){o=a.x+a.w,r+=i.length;continue}let l=i.slice(0,t-r).join("");return a.x+n.advance(l,a.style)}return o}function bm(e){return e.spans.reduce((t,n)=>t+[...n.text].length,0)}function cf(e,t,n,r,o){let a=Math.min(n,r),i=Math.max(n,r);if(a===i)return[];let l=vr(e,t),d=[];return e.lines.forEach((u,p)=>{let x=l[p];if(!x)return;let y=Math.max(a,x.start),k=Math.min(i,x.end);if(k<=y)return;let M=bm(u),v=uf(u,Math.min(y-x.start,M),o),w=uf(u,Math.min(k-x.start,M),o),D=Math.max(w-v,k>x.end-1&&k>y?4:0);D>0&&d.push({x:v,y:u.y,w:D,h:u.h})}),d}function pf(e,t,n,r,o){let a=vr(e,t),l=fi(a,n)+r,d=e.lines[l],u=a[l];if(!d||!u)return r===-1?0:t.length;let p=ui(e,t,n,o);return Math.min(u.start+vm(d,p.x,o),u.end)}var E0=/[\p{L}\p{N}_]/u;function mf(e,t){let n=Math.max(0,Math.min(t,e.length)),r=l=>E0.test(e[l]??""),o=n;if(!r(o)&&o>0&&r(o-1)&&(o-=1),!r(o))return{from:n,to:n};let a=o,i=o;for(;a>0&&r(a-1);)a-=1;for(;i<e.length&&r(i);)i+=1;return{from:a,to:i}}function ci(e,t,n){let r=vr(e,t),o=r[fi(r,n)];return o?{from:o.start,to:o.end}:{from:0,to:t.length}}var Sm=700;function hf(e){let t=0,n=0,r=null,o=!1,a=0,i=!1,l=0,d=0;function u(){return In(e.content())}function p(E){return Math.max(0,Math.min(Math.round(E),u().length))}function x(){return{from:Math.min(t,n),to:Math.max(t,n)}}function y(E,T=E){let P=t!==E||n!==T;t=p(E),n=p(T),P&&k(),r=null,e.invalidate()}function k(){o=!1,a&&(clearTimeout(a),a=0)}function M(){a&&clearTimeout(a),a=setTimeout(k,Sm)}function v(E,T){e.write(E,o,T),o=!0,M()}function w(E,T){let{from:P,to:V}=x(),X=r??void 0;v(yr(e.content(),P,V,E,X),T),t=n=P+E.length,r=null,e.invalidate()}function D(E,T){E!==T&&(v(yr(e.content(),E,T,""),"Delete text"),t=n=Math.min(E,T),e.invalidate())}function A(E,T){let{from:P,to:V}=x();if(P!==V){D(P,V);return}let X=u();if(E===-1){if(P===0)return;let I=T?km(X,P):P-1;D(I,P);return}if(P>=X.length)return;let te=T?_m(X,P):P+1;D(P,te)}function H(E,T){let P=u();return T?E===-1?km(P,n):_m(P,n):p(n+E)}return{id:e.id,getSelection:()=>({anchor:t,head:n}),setSelection(E,T){y(E,T??E)},caret(){return ui(e.layout(),u(),n,e.measure())},highlight(){let{from:E,to:T}=x();return cf(e.layout(),u(),E,T,e.measure())},pointTo(E,T){let P=Po(e.layout(),u(),E,e.measure());y(T?t:P,P)},selectWordAt(E){let T=Po(e.layout(),u(),E,e.measure()),P=mf(u(),T);y(P.from,P.to)},selectLineAt(E){let T=Po(e.layout(),u(),E,e.measure()),P=ci(e.layout(),u(),T);y(P.from,P.to)},selectAll(){y(0,u().length)},format(E){let{from:T,to:P}=x();if(T===P){r={...Do(e.content(),T),...E},e.invalidate();return}k(),v(df(e.content(),T,P,E),"Format text"),k(),e.invalidate()},activeMark(){if(r)return r;let{from:E,to:T}=x();return ff(e.content(),E,T)},composing:()=>i,handleKey(E){if(i)return!1;let T=E.metaKey||E.ctrlKey,P=E.altKey||E.ctrlKey&&!E.metaKey;switch(E.key){case"Escape":return e.close("escape"),!0;case"ArrowLeft":case"ArrowRight":{let V=E.key==="ArrowLeft"?-1:1,{from:X,to:te}=x();if(!E.shiftKey&&X!==te)y(V===-1?X:te);else{let I=T?wm(e,u(),n,V):H(V,P);y(E.shiftKey?t:I,I)}return!0}case"ArrowUp":case"ArrowDown":{let V=E.key==="ArrowUp"?-1:1,X=T?V===-1?0:u().length:pf(e.layout(),u(),n,V,e.measure());return y(E.shiftKey?t:X,X),!0}case"Home":case"End":{let V=wm(e,u(),n,E.key==="Home"?-1:1);return y(E.shiftKey?t:V,V),!0}case"Backspace":return A(-1,P||T),!0;case"Delete":return A(1,P||T),!0;case"Enter":return T?e.close("done"):w(`
2790
- `,"Type text"),!0;case"Tab":return!1;case"a":case"A":return T?(y(0,u().length),!0):!1;case"b":case"B":{if(!T)return!1;let V=this.activeMark().weight===700;return this.format({weight:V?void 0:700}),!0}case"i":case"I":return T?(this.format({italic:this.activeMark().italic===!0?void 0:!0}),!0):!1;case"u":case"U":return T?(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":w(C0(E),"Type text");return;case"insertParagraph":case"insertLineBreak":w(`
2791
- `,"Type text");return;case"deleteContentBackward":case"deleteWordBackward":A(-1,E.inputType==="deleteWordBackward");return;case"deleteContentForward":case"deleteWordForward":A(1,E.inputType==="deleteWordForward");return;case"deleteByCut":case"deleteByDrag":{let{from:T,to:P}=x();D(T,P);return}default:return}},handleCompositionStart(){i=!0;let{from:E,to:T}=x();l=E,d=T,k()},handleCompositionUpdate(E){v(yr(e.content(),l,d,E),"Type text"),d=l+E.length,t=n=d,e.invalidate()},handleCompositionEnd(E){v(yr(e.content(),l,d,E),"Type text"),i=!1,d=l+E.length,t=n=d,k(),e.invalidate()},breakBurst:k,destroy(){k()}}}function C0(e){return typeof e.data=="string"?e.data:e.dataTransfer?.getData("text/plain")??""}function wm(e,t,n,r){let o=ci(e.layout(),t,n);return r===-1?o.from:o.to}var pi=/[\p{L}\p{N}_]/u;function km(e,t){let n=t;for(;n>0&&!pi.test(e[n-1]??"");)n-=1;for(;n>0&&pi.test(e[n-1]??"");)n-=1;return n}function _m(e,t){let n=t;for(;n<e.length&&!pi.test(e[n]??"");)n+=1;for(;n<e.length&&pi.test(e[n]??"");)n+=1;return n}function xf(e){return Nn(e)===0}var gf={v:"select",f:"frame",r:"rect",o:"ellipse",p:"pen",t:"text"};function br(e,t){let n=[];for(let r of t){if(!U(e.root,r.nodeId))continue;let o=ee(r.to);ee(r.from)!==o&&n.push({op:"set",id:r.nodeId,prop:r.prop,value:o})}return n}function ee(e){return Math.round(e*100)/100}function wr(e,t,n,r){let o=new Set,a=[];for(let d of t)d.op==="set"&&(o.add(Ke(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 u of n.get(Ke(d.nodeId,d.prop))??[]){let p=Ke(u.nodeId,u.prop);if(o.has(p)||l.has(p)||!U(e.root,u.nodeId))continue;let x=r.nodes.get(u.nodeId)?.values[u.prop];x!==void 0&&(l.add(p),i.push({op:"set",id:u.nodeId,prop:u.prop,value:ee(x)}))}return i}function yf(e,t,n,r={x:0,y:0}){let o=[],a=new Set,i=e;for(;;){let l=[],d=Ne(i);for(let[u,p]of t){let x=n.get(u),y=U(i.root,p),k=d.nodes.get(p);if(!(!x||!y||!k))for(let M of yt(y)){let v=Ke(p,M);if(a.has(v))continue;let w=x[M],D=k.values[M];if(w===void 0||D===void 0)continue;let A=w+(M==="x"?r.x:M==="y"?r.y:0);ee(A)!==ee(D)&&(a.add(v),l.push({op:"set",id:p,prop:M,value:ee(A)}))}}if(l.length===0)return o;o.push(...l),i=Ae(i,l).document}}function kr(e,t,n=new Set){let r=Ne(e),o=Ne(t),a=[];for(let[i,l]of o.nodes){if(n.has(i))continue;let d=r.nodes.get(i),u=U(t.root,i);if(!(!d||!u))for(let p of yt(u)){let x=d.values[p],y=l.values[p];x===void 0||y===void 0||ee(x)!==ee(y)&&a.push({op:"set",id:i,prop:p,value:ee(x)})}}return a}function mi(e,t,n){let r=new Set,o=[];for(let a of t)a.op==="set"&&a.prop==="view"&&r.add(a.id);for(let a of t){if(a.op!=="set"||a.prop!=="w"&&a.prop!=="h"||r.has(a.id))continue;let i=U(e.root,a.id);if(i?.type!=="vector"||i.view!==void 0)continue;let l=n(a.id);l&&(r.add(a.id),o.push({op:"set",id:a.id,prop:"view",value:En({x:0,y:0,w:l.w,h:l.h})}))}return o.length===0?[...t]:[...o,...t]}var vf="host:",Em="#ffffff",Cm={w:1920,h:1080},M0=100,hi=20,A0=15,$0={ne:0,se:90,sw:180,nw:270,n:0,e:90,s:180,w:270},Mm={w:240,h:28},T0={text:"Add text",frame:"Add page",rect:"Draw rectangle",ellipse:"Draw ellipse"};function L0(e,t){let n=t.x-e.x,r=t.y-e.y,o=Math.max(Math.abs(n),Math.abs(r));return{x:e.x+Math.sign(n||1)*o,y:e.y+Math.sign(r||1)*o}}var O0={KeyA:"left",KeyD:"right",KeyW:"top",KeyS:"bottom",KeyH:"hcenter",KeyV:"vcenter"},D0={KeyH:"x",KeyV:"y"},P0={left:"Align left",hcenter:"Align horizontal centres",right:"Align right",top:"Align top",vcenter:"Align vertical centres",bottom:"Align bottom"},bf=null,I0=220,Am={lock:!0,hide:!0},N0=["x","y","w","h"],R0={front:"Bring to front",forward:"Bring forward",backward:"Send backward",back:"Send to back"},F0=11,an=2,B0=10;function kf(e,t){gr(e.ownerDocument),e.classList.add("vd-editor"),e.hasAttribute("tabindex")||(e.tabIndex=0);let n=t.document,r=[],o=t.tool??"select",a=null,i=null,l=null,d={ids:[],label:null},u=null,p=[],x=!1,y=new Set,k=null,M=!1,v=!1,w=null,D={...Am,...t.features},A=null,H=new $o,E=0,T=null,P={dx:0,dy:0},V=null,X=new Map,te=e.ownerDocument.createElement("div");te.style.position="absolute",te.style.inset="0",e.appendChild(te),e.style.touchAction="none";let I=La(te,{sample:fl,document:n,...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===n&&de("scene",{scene:s,document:f})},onCameraChange:s=>{we?.setZoom(s.zoom),Q(),de("camera",s),!(E>0)&&(ae(),de("navigate",s))}}),fe=fm(e,s=>I.documentToScreen(s)),we=t.chrome===!1?null:Tp(e,{onTool:Vt,onUndo:Nr,onRedo:Wo,onZoomReset:()=>I.fitToContent(),onPlay:t.onPlay,playHint:t.playHint,formatKeys:t.formatKeys}),Se=t.chrome===!1?null:Za(e,{onCommand:jh,...t.formatKeys?{formatKeys:t.formatKeys}:{}}),me=n,ue=n,S=[],g=null,$=[],L=null,B=null,q=new Map,F=null,ne=null,ke=null,Me=[],_e=ot,We=null,G=null,Z=null,Y=null,N=!1,z=e.ownerDocument.createElement("textarea");z.className="vd-editor__input",z.setAttribute("aria-hidden","true"),z.tabIndex=-1,z.autocapitalize="off",z.autocomplete="off",z.spellcheck=!1,e.appendChild(z);function de(s,f){let c=X.get(s);if(c)for(let m of c)m(f)}function le(s,f){let c=X.get(s)??new Set;return c.add(f),X.set(s,c),()=>c.delete(f)}function Te(s){E+=1;try{s()}finally{E-=1}}function ae(){T!==null&&(e.ownerDocument.defaultView?.cancelAnimationFrame(T),T=null)}function Be(s){let f=I.linkAt(s),c=f===void 0?void 0:pt(f);return c?c.kind==="url"?t.onOpenLink?(t.onOpenLink(c.url),!0):!1:U(n.root,c.id)?(ce([c.id]),Le([c.id]),!0):!1:!1}function Le(s,f={}){if(g!==null)return V={target:s,options:f},!1;let c=eh(s);if(!c)return!1;let m=e.getBoundingClientRect(),h=m.width>0&&m.height>0,b=h?{width:m.width,height:m.height-Zm(m)}:{width:c.w+96,height:c.h+96},_=f.fit==="always"?Ja(c,b):jd(c,b,I.getCamera());if(!_)return!1;ae(),f.by==="person"&&de("navigate",_);let C=e.ownerDocument.defaultView,O=C?.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;if(f.animate===!1||O||!h||!C?.requestAnimationFrame)return Te(()=>I.setCamera(_)),!0;let R=I.getCamera(),j=C.performance.now();P={dx:0,dy:0};let W=xe=>{let K=Math.min(1,Math.max(0,(xe-j)/I0)),ve=K===1?_:Xp(R,_,Yp(K),b);Te(()=>I.setCamera(St(ve,P.dx,P.dy))),T=K===1?null:C.requestAnimationFrame(W)};return T=C.requestAnimationFrame(W),!0}function Zm(s){let f=we?.element.getBoundingClientRect();return!f||f.height===0?0:Math.max(0,s.bottom-f.top)}function Qm(s,f){T!==null&&(P={dx:P.dx+s,dy:P.dy+f}),Te(()=>I.setCamera(St(I.getCamera(),s,f)))}function Ro(){if(V===null||g!==null)return;let{target:s,options:f}=V;V=null,Le(s,f)}function eh(s){if(s==="content"){let c=I.getScene();return Ya([{x:c.x,y:c.y,w:c.width,h:c.height}])}let f=[];for(let c of zd(n,s)){let m=Ie(c);m&&f.push(m)}return Ya(f)}function Ct(s){return I.getResolution().nodes.get(s)}function Bt(s){let f=Ct(s);return f?{x:f.x,y:f.y,w:f.w,h:f.h}:void 0}function Ie(s){return On(s,n,I.getResolution())}function sn(s){let f=Ct(s);return f?{x:f.absX,y:f.absY,w:f.w,h:f.h}:void 0}function ln(s){return Ct(s)?.values.rotation??0}function Lf(){let s=Mr();if(s.length===0)return null;for(let f of s){let c=U(n.root,f);if(!c||!Ks.includes(c.type))return null}return s}function Sr(s,f=new Set){let c=I.getResolution(),m=null;return se(n.root,h=>{if(f.has(h.id)||!fn(h.id))return!1;if(h.type!=="frame")return;let b=c.nodes.get(h.id);if(!b)return!1;let _={x:b.absX,y:b.absY,w:b.w,h:b.h};if(!gt(_,s.x,s.y))return!1;m=h.id}),m}function dn(s){let f=Ct(s);return f?{x:f.absX,y:f.absY}:{x:0,y:0}}function Qe(){return A?.of!==n&&(A={of:n,hidden:Yo(n.root),locked:Jo(n.root)}),A}function fn(s){let{hidden:f,locked:c}=Qe();return!f.has(s)&&!c.has(s)}function ie(){return r.filter(fn)}function Er(s){let f=I.hitTest(s,m=>!Qe().locked.has(m));if(f===null)return null;let c=w===null||je(n.root,f).includes(w);return Ga(f,n,c?w:null)}function th(){return Ao(n,ie(),I.getResolution())}function Cr(){return ie().length<2?null:Jd(th())}function Fo(s){let f=[];for(let c of s)for(let m of Ln(c,n)){let h=Bt(m);h&&f.push({member:c,node:m,frame:h})}return f}function Bo(s,f){let c=U(n.root,s);if(!c)return"literal";let m=c[f];return m===void 0?"literal":wa(m).kind}function nh(s){let f=U(n.root,s),c={};if(!f)return c;let m=[...N0,..._o(f).map(h=>h.prop)];for(let h of m)c[h]=Bo(s,h);return c}function Of(s,f){let c="none";for(let m of s){let h=bi(m,f);if(h==="expression")return"expression";h==="token"&&(c="token")}return c}function bi(s,f){let c="none";for(let m of f){let h=Bo(s,m);if(h==="complex")return"expression";h==="token"&&(c="token")}return c}let et=null;function he(s,f){if(s.length===0)return;let c=da(n,mi(n,s,Bt)),m=Ae(n,c);n=m.document,et?(Si(et.started,et.label,c,m.inverse),et.started=!0):H.push({label:f,ops:c,inverse:m.inverse}),Ho(c,f)}function rh(s){et={label:s,started:!1}}function oh(){et=null}function Df(s,f){s.length!==0&&(n=Ae(n,s).document,Ho(s,f))}function Ho(s,f){a=null,ne=null,ke=null,I.update(n),we?.setHistory(H.canUndo,H.canRedo),Q(),de("change",{document:n,ops:s,label:f}),de("problems",wi())}function wi(){return[...I.getScene().problems,...js(n)]}function ce(s){let f=s.filter(m=>m!==n.root.id&&U(n.root,m)),c=f.length!==r.length||f.some((m,h)=>r[h]!==m);r=[...f],Z&&(f.length!==1||f[0]!==Z.id)&&(Z=null),c&&(Se?.close(),ke=null,de("selection",r)),Q()}function ah(s,f){let c=U(n.root,s);if(!c)return[];let m=I.getCamera().zoom;if(Math.min(f.w,f.h)*m<24)return[];let h=F0/m,b=Ct(s);return _o(c).flatMap(_=>{let C=b?.values[_.prop]??0,O=Bo(s,_.prop)!=="literal";return _.handles(f,C,h).map(R=>({id:R.id,at:R.at,bound:O}))})}function ih(){let s=[];for(let R of ie()){let j=Ie(R);j&&s.push(j)}let f=xt(s);if(!f)return null;let c=ie().length===1?ie()[0]:void 0,m=c===void 0?void 0:U(n.root,c),h=c===void 0||!m||ye(m),b=new Set,_=Mr();for(let R of _l){let j=Oa(R);_.some(W=>j.some(xe=>Bo(W,xe)!=="literal"))&&b.add(R)}let C=!h&&c!==void 0?ln(c):0,O=C!==0&&c!==void 0?sn(c):void 0;return{frame:O??f,...O?{rotation:C}:{},rotatable:Lf()!==null,handles:G===null,boundHandles:b,adjusters:G!==null||h||c===void 0||O?[]:ah(c,f)}}function Mr(){return[...new Set(ie().flatMap(s=>Ln(s,n)))]}function sh(s){if(!s)return null;if(g?.kind==="adjust")return`r ${ee(L??g.from)}`;if(g?.kind==="rotate")return`${ee(B??0)}\xB0`;if(!g&&ne&&ie().length===1){let f=Ct(ie()[0])?.values[ne.prop]??0;return`r ${ee(f)}`}return g?.kind==="move"?`${ee(s.frame.x)}, ${ee(s.frame.y)}`:`${ee(s.frame.w)} \xD7 ${ee(s.frame.h)}`}function lh(){let f=g!==null&&g.kind!=="space"&&g.kind!=="reorder"?null:Cr();if(!f)return{spacers:[],rings:[],lead:null};let c=g?.kind==="space"?g.spacer:null;return{spacers:Qd(f).map(m=>({id:m.id,axis:m.axis,at:m.at,label:m.id===(c??ke)?String(ee(m.gap)):null})),rings:ef(f).map(m=>({id:m.id,at:m.at})),lead:g?.kind==="reorder"?Ie(g.id)??null:null}}function Q(){if(!v)return;let s=$h(),f=s?null:ih(),c=a!==null&&!r.includes(a)&&!g?Ie(a)??null:null,m={...dm,...lh(),hover:c,members:ie().length>1?ie().flatMap(h=>Ie(h)??[]):[],box:f,badge:sh(f),caret:Pf(),textSelection:If(),draft:g?.kind==="create"?Tn(g.origin,g.current):null,draftEllipse:g?.kind==="create"&&o==="ellipse",marquee:g?.kind==="marquee"?Tn(g.origin,g.current):null,guides:g?_e.guides:[],measures:g?_e.measures:[],presence:d.ids.length===0?null:{frames:d.ids.flatMap(h=>Ie(h)??[]),label:d.label},highlight:Co(n,p).flatMap(h=>Ie(h.id)??[]),slots:Qh(),parked:r.filter(h=>!fn(h)).flatMap(h=>Ie(h)??[]),lockHint:uh(),path:s,turn:ch(),pageLabels:dh()};fe.render(m)}function dh(){if(i)return[];let s=I.getResolution().nodes;return n.root.children.flatMap(f=>{if(f.type!=="frame")return[];let c=s.get(f.id);if(!c)return[];let m=Mo(c),h=f.name;return[{id:f.id,frame:m,label:typeof h=="string"&&h!==""?h:f.id,state:r.includes(f.id)?"selected":a===f.id?"hover":"idle"}]})}function fh(s){let f=fe.pageLabelRect(s),c=U(n.root,s);if(!f||!c)return;let m=c.name,h=e.ownerDocument.createElement("input");h.className="vd-editor__rename",h.type="text",h.spellcheck=!1,h.value=typeof m=="string"&&m!==""?m:"",h.placeholder=s,h.setAttribute("aria-label",`Name of ${s}`),h.style.left=`${f.x-4}px`,h.style.top=`${f.y-2}px`,h.style.width=`${Math.max(120,f.w+40)}px`;let b=!1,_=C=>{if(b)return;b=!0;let O=h.value.trim();h.remove(),i=null,C&&O!==(typeof m=="string"?m:"")&&_u(s,"name",O===""?void 0:O,"Rename"),Q(),e.focus({preventScroll:!0})};h.addEventListener("keydown",C=>{C.stopPropagation(),C.key==="Enter"?(C.preventDefault(),_(!0)):C.key==="Escape"&&(C.preventDefault(),_(!1))}),h.addEventListener("pointerdown",C=>C.stopPropagation()),h.addEventListener("blur",()=>_(!0)),i=h,e.appendChild(h),Q(),h.focus(),h.select()}function uh(){if(l===null||g||!Qe().locked.has(l))return null;let s=Ie(l);return s?{frame:s,label:l}:null}function Uo(s){let f=I.itemOf(s);if(f?.kind!=="text")return null;let c=f.lines[0]?.y??f.y,m={lines:f.lines.map(h=>({y:h.y-c,h:h.h,baseline:h.baseline-c,w:h.w,spans:h.spans.map(b=>({text:b.text,style:b.style,x:b.x-f.x,w:b.w})),...h.style?{style:h.style}:{}})),width:Math.max(0,...f.lines.map(h=>h.w)),height:f.height};return{item:f,layout:m,top:c}}function ki(){return o==="text"?"text":o!=="select"?"crosshair":"arrow"}function Pf(){if(!G)return null;let s=Uo(G.id);if(!s)return null;let f=G.caret();return{x:s.item.x+f.x,y:s.top+f.y,h:f.h,...f.fill!==void 0?{fill:f.fill}:{}}}function If(){if(!G)return[];let s=Uo(G.id);return s?G.highlight().map(f=>({x:s.item.x+f.x,y:s.top+f.y,w:f.w,h:f.h})):[]}function _i(s){if(!G)return null;let f=Uo(G.id);if(!f)return null;let c=Ar(G.id,s);return{x:c.x-f.item.x,y:c.y-f.top}}function Ar(s,f){let c=ln(s),m=c===0?void 0:sn(s);return m?Ze(f,rt(m),-c):f}function ch(){let s=G?.id??Z?.id;if(s===void 0)return null;let f=ln(s),c=f===0?void 0:sn(s);return c?{angle:f,centre:rt(c)}:null}function ph(s){let f=U(n.root,s);if(!f||f.type!=="text"||typeof f.h!="number")return[];let c=I.itemOf(s);if(c?.kind!=="text")return[];let m=ee(Math.ceil(c.height));return m>f.h?[{op:"set",id:s,prop:"h",value:m}]:[]}function mh(s,f,c,m){let h=et?et.started:c,b=et?.label??m;et&&(et.started=!0);let _=[{op:"set",id:s,prop:"content",value:f}],C=Ae(n,_);n=C.document,I.update(n);let O=ph(s);if(O.length===0){Si(h,b,_,C.inverse),Ho(_,b);return}let R=Ae(n,O);n=R.document,I.update(n);let j=[..._,...O];Si(h,b,j,[...R.inverse,...C.inverse]),Ho(j,b)}function Si(s,f,c,m){let h={label:f,ops:c,inverse:m};s&&H.amend(h)||H.push(h)}function $r(s,f){let c=U(n.root,s);if(!c||c.type!=="text"||G?.id===s)return;un("done"),Vt("select"),ce([s]),G=hf({id:s,content:()=>{let h=U(n.root,s);return h?.type==="text"?h.content:""},layout:()=>Uo(s)?.layout??{lines:[],width:0,height:0},measure:()=>I.getMeasurer(),write:(h,b,_)=>mh(s,h,b,_),invalidate:()=>{Q(),Nf(),de("selection",r)},close:h=>un(h)});let m=f?_i(f):null;m?G.pointTo(m,!1):G.selectAll(),e.classList.add("vd-editor--editing"),z.value="",z.focus({preventScroll:!0}),Q(),Nf()}function un(s){let f=G;if(!f)return;G=null,N=!1,f.destroy(),e.classList.remove("vd-editor--editing","vd-editor--typing"),de("selection",r);let c=U(n.root,f.id);c?.type==="text"&&xf(c.content)&&(he([{op:"remove",id:f.id}],"Remove empty text"),ce([])),e.ownerDocument.activeElement===z&&e.focus({preventScroll:!0}),Q()}function Nf(){let s=Pf();if(!s)return;let f=I.documentToScreen({x:s.x,y:s.y});z.style.left=`${Math.round(f.x)}px`,z.style.top=`${Math.round(f.y)}px`}let Rn=0;function Rf(){e.classList.add("vd-editor--typing"),Rn&&clearTimeout(Rn),Rn=setTimeout(()=>{Rn=0,e.classList.remove("vd-editor--typing")},520)}function Ei(s){let f=br(me,s);return f.length>0&&F?[...f,...wr(me,f,q,F)]:f}function cn(s){Ci(Ei(s))}function Ci(s,f=s){let c=h=>{let b=F?.nodes.get(h);return b?{x:0,y:0,w:b.w,h:b.h}:void 0},m=mi(me,s,c);$=mi(me,f,c),I.update(m.length>0?Ae(me,m).document:me),Q()}function Ff(){let s=xt(ie().flatMap(m=>Ie(m)??[]));if(!s)return null;let f=new Map,c=new Map;for(let m of Mr()){let h=sn(m),b=Bt(m);!h||!b||(f.set(m,h),c.set(m,{x:h.x-b.x,y:h.y-b.y}))}return f.size===0?null:{bounds:s,frames:f,offsets:c}}function Bf(s,f){let c=Nd(s.frames,s.bounds,f),m=[];for(let[h,b]of c){let _=s.frames.get(h),C=s.offsets.get(h);if(!_||!C)continue;let O=ln(h),R=O===0?b:yp(_,O,s.bounds,f);m.push({nodeId:h,prop:"x",from:_.x-C.x,to:R.x-C.x},{nodeId:h,prop:"y",from:_.y-C.y,to:R.y-C.y},{nodeId:h,prop:"w",from:_.w,to:R.w},{nodeId:h,prop:"h",from:_.h,to:R.h})}return m}function hh(s,f){let c=Lf();if(!c)return!1;let m=ie().length===1&&c.length===1?c[0]:void 0,h=xt(ie().flatMap(C=>Ie(C)??[])),b=m!==void 0?sn(m):h;if(!b)return!1;let _=c.flatMap(C=>{let O=sn(C),R=Bt(C);return!O||!R?[]:[{id:C,frame:O,rotation:ln(C),offset:{x:O.x-R.x,y:O.y-R.y}}]});return _.length===0?!1:(st(f),tt({kind:"rotate",pointerId:f,origin:s,centre:rt(b),targets:_}),!0)}function xh(s,f,c){let m=Ff();return m?(st(c),tt({kind:"scale",pointerId:c,origin:s,handle:f,...m}),!0):!1}function gh(s){let f=Ff();if(!f)return;let c=br(n,Bf(f,s));if(c.length===0)return;let m=s.w!==f.bounds.w||s.h!==f.bounds.h;he([...c,...wr(n,c,ir(n),Ne(n))],m?"Resize":"Move")}function yh(s,f,c){let m=ii(s),h=Cr();if(!m||!h)return!1;let b=Et(h,m.axis)?.gaps[m.index],_=Fo(ie());return b===void 0||_.length===0?!1:(st(c),tt({kind:"space",pointerId:c,origin:f,axis:m.axis,spacer:s,layout:h,gap:b,parts:_}),!0)}function vh(s,f){let c=s.axis==="x"?f.x-s.origin.x:f.y-s.origin.y,m=Math.max(0,s.gap+c);cn(Mi(s.parts,s.axis,si(s.layout,s.axis,m)))}function bh(s,f){let c=Cr(),m=c?Et(c,s):void 0;if(!c||!m||m.gaps.length===0)return;let h=br(n,Mi(Fo(ie()),s,si(c,s,Math.max(0,f))));h.length!==0&&he([...h,...wr(n,h,ir(n),Ne(n))],"Spacing")}function wh(s){let f=Cr(),c=f?Et(f,s)?.gaps:void 0;return!c||c.length===0?null:Zd(c)?c[0]??null:"mixed"}function Mi(s,f,c){return s.map(m=>{let h=f==="x"?m.frame.x:m.frame.y;return{nodeId:m.node,prop:f,from:h,to:h+(c.get(m.member)??0)}})}function kh(s,f,c){let m=Cr();if(!m||!m.order.includes(s))return!1;let h=Fo(ie()),b=m.items.find(_=>_.id===s)?.frame;return h.length===0||!b?!1:(st(c),tt({kind:"reorder",pointerId:c,id:s,layout:m,parts:h,grab:{x:f.x-b.x,y:f.y-b.y},to:m.order.indexOf(s),swap:!1}),!0)}function _h(s,f,c){s.to=rf(s.layout,f),s.swap=c;let m=Sh(s),h=new Map(m);h.set(s.id,{x:f.x-s.grab.x,y:f.y-s.grab.y}),Ci(Ei(Hf(s,h)),Ei(Hf(s,m)))}function Sh(s){let f=s.layout.order.indexOf(s.id);if(f===-1||s.to===f)return new Map;if(s.swap){let c=s.layout.order[s.to];return c===void 0?new Map:sf(s.layout,s.id,c)}return af(s.layout,of(s.layout.order,f,s.to))}function Hf(s,f){let c=new Map(s.layout.items.map(h=>[h.id,h.frame])),m=[];for(let h of s.parts){let b=f.get(h.member),_=c.get(h.member);!b||!_||m.push({nodeId:h.node,prop:"x",from:h.frame.x,to:h.frame.x+(b.x-_.x)},{nodeId:h.node,prop:"y",from:h.frame.y,to:h.frame.y+(b.y-_.y)})}return m}function tt(s,f=[],c=n){ue=c,S=f,me=n,g=s,$=[],q=ir(n),F=Ne(n),_e=ot,Me=Eh(s)?Fd(n,F,Ch(s)):[]}function Eh(s){return s.kind==="move"||s.kind==="resize"||s.kind==="scale"||s.kind==="create"}function Ch(s){return s.kind==="move"||s.kind==="scale"?new Set(ie()):s.kind==="resize"?new Set([s.id]):new Set}function Tr(s){return s.metaKey||s.ctrlKey?0:Rd/I.getCamera().zoom}function Ht(s){let f=[...S,...$];g=null,$=[],S=[],L=null,B=null,_e=ot,n=ue,I.update(n),he(f,s),Q()}function Mh(){let s=$.length>0?Ae(me,$).document:me,f=new Set(ie().flatMap(h=>Uf(h,s))),c=[];for(let h of ie()){let b=U(s.root,h),_=ct(s.root,h);if(!b||!_)continue;let C=Ie(h);if(!C)continue;let O={x:C.x+C.w/2,y:C.y+C.h/2},R=Sr(O,f)??n.root.id;if(R===_.id)continue;let j=U(s.root,R);if(!j||!ye(j))continue;c.push({op:"move",id:h,parent:R,index:re(j).length});let W={x:dn(_.id).x-dn(R).x,y:dn(_.id).y-dn(R).y};if(!(W.x===0&&W.y===0))for(let xe of Ln(h,s)){let K=Bt(xe);K&&(c.push({op:"set",id:xe,prop:"x",value:ee(K.x+W.x)}),c.push({op:"set",id:xe,prop:"y",value:ee(K.y+W.y)}))}}if(c.length===0)return[];let m=Ae(s,c).document;return[...c,...kr(s,m,f)]}function Uf(s,f){let c=U(f.root,s);if(!c)return[];let m=[];return se(c,h=>{m.push(h.id)}),m}function Ai(){if(!g)return;g=null,$=[],L=null,B=null,_e=ot;let s=S.length>0;n=ue,S=[],s&&ce(r.filter(f=>U(n.root,f))),I.update(n),Q()}let Ah=5,Vo=8;function Vf(s,f=n,c=I.getResolution()){let m=U(f.root,s),h=c.nodes.get(s);if(m?.type!=="vector"||!h)return;let b={x:h.absX,y:h.absY,w:Math.max(0,h.w),h:Math.max(0,h.h)};return{node:m,view:Jr(m.view,b.w,b.h),box:b}}function Lr(s,f=n,c=I.getResolution()){let m=Vf(s,f,c);if(m)return Lt(Yr(m.node.d).contours,Zr(m.view,m.box))}function Ut(s,f,c,m=n,h=I.getResolution()){let b=Vf(s,m,h);if(!b)return[];let{node:_,view:C,box:O}=b,R=Lt(f,ns(C,O)),j=[],W=(ut,Un,cx)=>{Un!==cx&&j.push({op:"set",id:s,prop:ut,value:Un})};W("d",Tt(R),_.d);let xe=[_.x,_.y,_.w,_.h].every(ut=>typeof ut=="number"),K=Sn(R),ve=Sn(f);if(!c||!xe||!K||!ve)return j;let He=O.x-_.x,Ue=O.y-_.y;return W("view",En(K),_.view),W("x",ee(ve.x-He),_.x),W("y",ee(ve.y-Ue),_.y),W("w",ee(ve.w),_.w),W("h",ee(ve.h),_.h),j}function pn(s){return U(n.root,s)?.type!=="vector"||!fn(s)?!1:(G&&un("done"),Y&&zo(),ce([s]),Z={id:s,picked:new Set},o!=="select"&&Vt("select"),it(null),Q(),!0)}function Or(){Z&&(Z=null,Q())}function $h(){if(Y){let c=Y.contours[Y.contour],m=c?.anchors??[],h=m[m.length-1],b=m[0],_=Y.hover,C=_!==null&&b!==void 0&&m.length>=2&&!c?.closed&&Dr(b,_)<=Vo;return{contours:Y.contours,anchors:m.map((O,R)=>({key:Re(Y?.contour??0,R),at:O,selected:R===m.length-1})),handles:h?Ll(Y.contours,new Set([Re(Y.contour,m.length-1)])):[],pending:h&&_&&!Y.dragging&&!c?.closed?{from:h,...h.out?{c1:h.out}:{},to:_}:null,closeAt:C?b:null}}if(!Z)return null;let s=Lr(Z.id);if(!s)return null;let f=new Set($l(s,Z.picked));return{contours:s,anchors:s.flatMap((c,m)=>c.anchors.map((h,b)=>({key:Re(m,b),at:h,selected:f.has(Re(m,b))}))),handles:Ll(s,f)}}function Dr(s,f){return Math.hypot(s.x-f.x,s.y-f.y)*I.getCamera().zoom}function Th(s,f,c,m){if(!Z)return!1;let h=Z.id,b=Lr(h);if(!b)return Z=null,!1;s.preventDefault(),st(s.pointerId);let _=fe.hitPath(f);if(_?.kind==="handle"){let O=vp(_.key),R=O?b[O.contour]?.anchors[O.index]:void 0;if(O&&R)return tt({kind:"pathHandle",pointerId:s.pointerId,id:h,start:b,contour:O.contour,index:O.index,side:O.side,smooth:Pa(R),last:b}),!0}if(_?.kind==="anchor")return s.altKey?(Z.picked=new Set([_.key]),he(Ut(h,bp(b,_.key),!1),"Convert point"),!0):(s.shiftKey?Z.picked.has(_.key)?Z.picked.delete(_.key):Z.picked.add(_.key):Z.picked.has(_.key)||(Z.picked=new Set([_.key])),tt({kind:"points",pointerId:s.pointerId,id:h,origin:c,start:b,keys:new Set(Z.picked),lead:_.key,moved:!1,last:b}),Q(),!0);let C=as(b,c);if(C&&C.distance*I.getCamera().zoom<=Ah){if(m>=2){let W=is(b,C.contour,C.segment,C.t);return Z.picked=new Set([Re(C.contour,C.segment+1)]),he(Ut(h,W,!1),"Add point"),!0}let O=b[C.contour],R=O.anchors[C.segment],j=O.anchors[(C.segment+1)%O.anchors.length];return tt({kind:"segment",pointerId:s.pointerId,id:h,origin:c,start:b,contour:C.contour,segment:C.segment,t:C.t,straight:!R?.out&&!j?.in,last:b}),!0}return tt({kind:"pointMarquee",pointerId:s.pointerId,origin:c,current:c,additive:s.shiftKey}),!0}function Lh(s,f,c,m){let h=Al(s.start,s.lead);if(!h||m===0)return{dx:f,dy:c};let b=h.x+f,_=h.y+c,C=m,O=m,R=f,j=c;return s.start.forEach((W,xe)=>W.anchors.forEach((K,ve)=>{s.keys.has(Re(xe,ve))||(Math.abs(K.x-b)<C&&(C=Math.abs(K.x-b),R=K.x-h.x),Math.abs(K.y-_)<O&&(O=Math.abs(K.y-_),j=K.y-h.y))})),{dx:R,dy:j}}function Oh(s,f){if(!g)return!1;let c=(m,h)=>{F&&Ci(Ut(h,m,!1,me,F))};switch(g.kind){case"points":{let m=f;s.shiftKey&&(m=ko(g.origin,f));let h={dx:m.x-g.origin.x,dy:m.y-g.origin.y};if(!g.moved&&Math.hypot(h.dx,h.dy)*I.getCamera().zoom<an)return!0;g.moved=!0;let{dx:b,dy:_}=s.shiftKey?h:Lh(g,h.dx,h.dy,Tr(s));return g.last=Ra(g.start,g.keys,b,_),c(g.last,g.id),!0}case"pathHandle":{let m=g.start[g.contour]?.anchors[g.index],h=s.shiftKey&&m?ko(m,f):f;return g.last=Ia(g.start,g.contour,g.index,g.side,h,{smooth:g.smooth,breakSmooth:s.altKey}),c(g.last,g.id),!0}case"segment":return g.last=kp(g.start,g.contour,g.segment,g.t,f.x-g.origin.x,f.y-g.origin.y,g.straight),c(g.last,g.id),!0;case"pointMarquee":return g.current=f,Q(),!0;default:return!1}}function Dh(s){if(!g)return!1;switch(g.kind){case"points":case"pathHandle":case"segment":{let f=g.kind!=="points"||g.moved,c=g.kind==="points"?g.keys.size===1?"Move point":"Move points":g.kind==="pathHandle"?"Adjust curve":"Reshape";return $=f&&F?Ut(g.id,g.last,!0,me,F):[],Ht(c),!0}case"pointMarquee":{let f=Tn(g.origin,g.current),c=g.additive;if(g=null,_e=ot,!Z)return!0;let m=I.getCamera().zoom;if(f.w*m<an&&f.h*m<an){if(I.hitTest(s)===Z.id)Z.picked=new Set;else{Or();let _=Er(s);ce(_===null?[]:[_])}return Q(),!0}let h=Lr(Z.id)??[],b=Tl(h).filter(_=>{let C=Al(h,_);return C!==void 0&&gt(f,C.x,C.y)});return Z.picked=new Set(c?[...Z.picked,...b]:b),Q(),!0}default:return!1}}function Ph(s){if(!Z)return!1;let f=Z.id,c=s.metaKey||s.ctrlKey;if(s.key==="Escape"||s.key==="Enter"&&!c)return s.preventDefault(),g?Ai():Or(),!0;let m=Lr(f);if(!m)return!1;let h=new Set($l(m,Z.picked));if(s.key==="Delete"||s.key==="Backspace"){if(s.preventDefault(),h.size===0)return!0;let O=wp(m,h);return Z.picked=new Set,O.length===0?(Or(),Hn(),!0):(he(Ut(f,O,!0),h.size===1?"Delete point":"Delete points"),!0)}let b=s.shiftKey?10:1,C={ArrowLeft:[-b,0],ArrowRight:[b,0],ArrowUp:[0,-b],ArrowDown:[0,b]}[s.key];return C&&!c?(s.preventDefault(),h.size>0&&he(Ut(f,Ra(m,h,C[0],C[1]),!0),"Nudge points"),!0):c&&s.key.toLowerCase()==="a"?(s.preventDefault(),Z.picked=new Set(Tl(m)),Q(),!0):c&&!s.shiftKey&&s.code==="KeyJ"?(s.preventDefault(),he(Ut(f,_p(m,h),!0),"Close path"),!0):!1}function Ih(s,f){if(s.preventDefault(),st(s.pointerId),!Y){Y=Nh(f)??{contours:[{closed:!1,anchors:[{x:f.x,y:f.y}]}],contour:0,target:null,hover:null,dragging:null};let _=Y.contours[Y.contour];Y.dragging={pointerId:s.pointerId,index:_.anchors.length-1,origin:f},Q();return}let c=Y.contours[Y.contour],m=c.anchors[0],h=c.anchors[c.anchors.length-1];if(m&&c.anchors.length>=2&&Dr(m,f)<=Vo){Y.contours[Y.contour]={...c,closed:!0},Y.dragging={pointerId:s.pointerId,index:0,origin:m},Q();return}let b=s.shiftKey&&h?ko(h,f):f;Y.contours[Y.contour]={...c,anchors:[...c.anchors,{x:b.x,y:b.y}]},Y.dragging={pointerId:s.pointerId,index:c.anchors.length,origin:b},Q()}function Nh(s){let f=r.length===1?r[0]:null;if(f===null||!fn(f))return null;let c=Lr(f);if(!c)return null;for(let m=0;m<c.length;m+=1){let h=c[m];if(h.closed||h.anchors.length<1)continue;let b=h.anchors[0],_=h.anchors[h.anchors.length-1],C=Dr(_,s)<=Vo,O=!C&&Dr(b,s)<=Vo;if(!C&&!O)continue;let R=[...c];return O&&(R[m]=Sp(h)),{contours:R,contour:m,target:f,hover:null,dragging:null}}return null}function Rh(s,f){if(!Y)return;let c=Y.dragging;if(!c||c.pointerId!==s.pointerId){let O=Y.contours[Y.contour],R=O?.anchors[O.anchors.length-1];Y.hover=s.shiftKey&&R?ko(R,f):f,Q();return}if(Dr(c.origin,f)<an)return;let m=Y.contours[Y.contour],h=m.anchors[c.index];if(!h)return;let b={x:2*h.x-f.x,y:2*h.y-f.y},_=s.altKey?h.in:b,C=[...m.anchors];C[c.index]={x:h.x,y:h.y,..._?{in:_}:{},out:f},Y.contours[Y.contour]={...m,anchors:C},Q()}function Fh(s){!Y?.dragging||Y.dragging.pointerId!==s.pointerId||(Hi(s.pointerId),Y.dragging=null,Y.contours[Y.contour]?.closed?zo():Q())}function zo(){if(!Y)return;let s=Y;Y=null;let f=s.contours[s.contour];if(!f||f.anchors.length<2){Q();return}if(s.target!==null){he(Ut(s.target,s.contours,!0),"Extend path"),Vt("select"),pn(s.target);return}let c=Sn(s.contours),m=f.anchors[0];if(!c)return;let h=Sr(m)??w??n.root.id,b=U(n.root,h)??n.root,_=dn(h),C=Lt(s.contours,R=>({x:R.x-c.x,y:R.y-c.y})),O=Wt(n.root,"path");he([{op:"insert",parent:h,index:re(b).length,node:Qo({id:O,x:ee(c.x-_.x),y:ee(c.y-_.y),w:ee(c.w),h:ee(c.h),view:En({x:0,y:0,w:c.w,h:c.h}),d:Tt(C),fill:"none",stroke:t.defaultStroke??"#1f2937",strokeWidth:2,cap:"round",join:"round"})}],"Draw path"),Vt("select"),pn(O)}function $i(s=ie()){let f=[],c=[];for(let m of s){let h=U(n.root,m),b=ct(n.root,m),_=Ct(m);if(!h||!b||!_||h.type!=="rect"&&h.type!=="ellipse")continue;let C=Math.max(0,_.w),O=Math.max(0,_.h),R=h.type==="rect"?ss(C,O,_.values.radius??0):ls(C,O),j=Qo({id:m,...h.name===void 0?{}:{name:h.name},x:h.x,y:h.y,w:h.w,h:h.h,view:En({x:0,y:0,w:C,h:O}),d:Tt(R),...h.fill===void 0?{}:{fill:h.fill},...h.stroke===void 0?{}:{stroke:h.stroke},...h.strokeWidth===void 0?{}:{strokeWidth:h.strokeWidth},...h.opacity===void 0?{}:{opacity:h.opacity},...h.hidden?{hidden:!0}:{},...h.locked?{locked:!0}:{}}),W=b.children.findIndex(xe=>xe.id===m);f.push({op:"remove",id:m},{op:"insert",parent:b.id,index:W,node:j}),c.push(m)}c.length!==0&&(he(f,c.length===1?"Convert to vector":`Convert ${c.length} to vector`),ce(c),c.length===1&&pn(c[0]))}function zf(){return ie().filter(s=>{let f=U(n.root,s)?.type;return f==="rect"||f==="ellipse"}).length}let Bh=450,jf=4,Pr={x:0,y:0,at:0,count:0};function Hh(s){let f=Date.now(),m=Math.abs(s.x-Pr.x)<=jf&&Math.abs(s.y-Pr.y)<=jf&&f-Pr.at<=Bh?Pr.count+1:1;return Pr={x:s.x,y:s.y,at:f,count:m},m}let qf=s=>{if(M=s.pointerType==="touch",M){y.add(s.pointerId),k=y.size===1?{pointerId:s.pointerId,screen:I.pointerPoint(s)}:null;return}if(s.button!==0||x)return;let f=I.pointerPoint(s),c=I.screenToDocument(f);We=c;let m=Hh(f);if(G){let O=_i(c),R=I.itemOf(G.id),j=Ar(G.id,c);if(O&&R&&gt(R,j.x,j.y)){s.preventDefault(),st(s.pointerId),N=!0,m>=3?G.selectLineAt(O):m===2?G.selectWordAt(O):G.pointTo(O,s.shiftKey),z.focus({preventScroll:!0}),Q();return}un("blur")}if(e.focus({preventScroll:!0}),o==="select"&&(s.metaKey||s.ctrlKey)&&Be(c)){s.preventDefault();return}if(o==="pen"){Ih(s,c);return}if(Z&&o==="select"&&Th(s,f,Ar(Z.id,c),m))return;if(o!=="select"){s.preventDefault(),st(s.pointerId),tt({kind:"create",pointerId:s.pointerId,origin:c,current:c}),Q();return}let h=ie().length===1?ie()[0]:null;if(h!==null){let O=U(n.root,h),R=fe.hitAdjuster(f),j=O&&R?Va(O,R.id):void 0,W=j?Ie(h):void 0;if(j&&W&&R){s.preventDefault(),st(s.pointerId),tt({kind:"adjust",pointerId:s.pointerId,id:h,adjuster:j,handleId:R.id,frame:W,from:Ct(h)?.values[j.prop]??0});return}let xe=O&&!ye(O)?fe.hitHandle(f):null,K=xe?Bt(h):void 0,ve=K?sn(h):void 0;if(xe&&K&&ve){s.preventDefault(),st(s.pointerId),tt({kind:"resize",pointerId:s.pointerId,origin:c,id:h,handle:xe.handle,frame:K,offset:{x:ve.x-K.x,y:ve.y-K.y},rotation:ln(h)});return}}let b=ie().length>0?fe.hitHandle(f):null;if(b&&xh(c,b.handle,s.pointerId)){s.preventDefault();return}let _=fe.hitPageLabel(f);if(_!==null){if(s.preventDefault(),w=null,s.shiftKey){ce(r.includes(_)?r.filter(O=>O!==_):[...r,_]);return}if(r.includes(_)||ce([_]),m===2){fh(_);return}Kf(c,s.pointerId,s.altKey);return}if(ie().length>0&&fe.hitRotate(f)!==null&&hh(c,s.pointerId)){s.preventDefault();return}if(ie().length>1){let O=fe.hitRing(f);if(O!==null&&kh(O,c,s.pointerId)){s.preventDefault();return}let R=fe.hitSpacer(f);if(R!==null&&yh(R,c,s.pointerId)){s.preventDefault();return}}let C=Er(c);if(C===null){s.preventDefault(),st(s.pointerId),w=null,s.shiftKey||ce([]),tt({kind:"marquee",pointerId:s.pointerId,origin:c,current:c});return}w!==null&&!je(n.root,C).includes(w)&&(w=null),s.shiftKey?ce(r.includes(C)?r.filter(O=>O!==C):[...r,C]):r.includes(C)||ce([C]),Kf(c,s.pointerId,s.altKey)&&s.preventDefault()};function Uh(s){G&&un("blur");let f=Er(I.screenToDocument(s));f!==null&&w!==null&&!je(n.root,f).includes(w)&&(w=null),f===null&&(w=null),ce(f===null?[]:[f])}function Kf(s,f,c){let m=n,h=[];if(c){let _=mu({x:0,y:0});_&&(h=_.ops,n=Ae(n,h).document,I.update(n),ce(_.ids))}let b=new Map;for(let _ of ie())for(let C of Ln(_,n)){let O=Bt(C);O&&b.set(C,O)}return b.size===0?(n=m,I.update(n),!1):(st(f),tt({kind:"move",pointerId:f,origin:s,frames:b,bounds:xt(ie().flatMap(_=>Ie(_)??[]))},h,m),!0)}let Gf=s=>{let f=I.pointerPoint(s);if(s.pointerType==="touch"){k?.pointerId===s.pointerId&&Math.hypot(k.screen.x-f.x,k.screen.y-f.y)>B0&&(k=null);return}if(We=I.screenToDocument(f),N&&G){let m=_i(We);m&&G.pointTo(m,!0);return}if(Y&&o==="pen"){Rh(s,We);return}if(!g){qh(f);return}if(g.pointerId!==s.pointerId)return;let c=We;if(!Oh(s,Z?Ar(Z.id,c):c))switch(g.kind){case"move":{let m=c.x-g.origin.x,h=c.y-g.origin.y;if(g.bounds){let _={...g.bounds,x:g.bounds.x+m,y:g.bounds.y+h};_e=Bd(_,Me,Tr(s)),m+=_e.dx,h+=_e.dy}let b=[];for(let[_,C]of g.frames)b.push({nodeId:_,prop:"x",from:C.x,to:C.x+m}),b.push({nodeId:_,prop:"y",from:C.y,to:C.y+h});cn(b);return}case"resize":{let{id:m,handle:h,frame:b,origin:_,offset:C,rotation:O}=g,R=c.x-_.x,j=c.y-_.y;if(O!==0){_e=ot;let K=hp(b,h,R,j,O);cn(Da(b,K).map(ve=>({nodeId:m,prop:ve,from:b[ve],to:K[ve]})));return}let W=It(b,h,R,j);_e=Xa({...W,x:W.x+C.x,y:W.y+C.y},h,Me,Tr(s)),R+=_e.dx,j+=_e.dy;let xe=It(b,h,R,j);cn(Da(b,xe).map(K=>({nodeId:m,prop:K,from:b[K],to:xe[K]})));return}case"scale":{let{handle:m,bounds:h,origin:b,frames:_,offsets:C}=g,O=c.x-b.x,R=c.y-b.y,j=It(h,m,O,R);_e=Xa(j,m,Me,Tr(s)),O+=_e.dx,R+=_e.dy,cn(Bf({bounds:h,frames:_,offsets:C},It(h,m,O,R)));return}case"space":vh(g,c);return;case"reorder":_h(g,c,s.metaKey||s.ctrlKey);return;case"rotate":{let{centre:m,origin:h,targets:b}=g,_=b[0],C=xp(m,h,c,_?.rotation??0,s.shiftKey?A0:void 0);B=lo((_?.rotation??0)+C);let O=[],R=b.length===1;for(let j of gp(b,m,C)){let W=b.find(xe=>xe.id===j.id);W&&(O.push({nodeId:j.id,prop:"rotation",from:W.rotation,to:j.rotation}),!R&&O.push({nodeId:j.id,prop:"x",from:W.frame.x-W.offset.x,to:ee(j.frame.x-W.offset.x)},{nodeId:j.id,prop:"y",from:W.frame.y-W.offset.y,to:ee(j.frame.y-W.offset.y)}))}cn(O);return}case"adjust":{let m=g.adjuster.valueAt(g.frame,g.handleId,c);L=m,cn([{nodeId:g.id,prop:g.adjuster.prop,from:g.from,to:m}]);return}case"create":{_e=Hd(c,Me,Tr(s));let m={x:c.x+_e.dx,y:c.y+_e.dy};g.current=s.shiftKey&&o!=="text"?L0(g.origin,m):m,Q();return}case"marquee":{g.current=c,Q();return}}},jo=s=>{if(s.pointerType==="touch"){if(y.delete(s.pointerId),k?.pointerId!==s.pointerId)return;k=null,s.type==="pointerup"&&Uh(I.pointerPoint(s));return}if(N){N=!1,Hi(s.pointerId),z.focus({preventScroll:!0});return}if(Y){Fh(s);return}if(!g||g.pointerId!==s.pointerId)return;Hi(s.pointerId);let f=I.screenToDocument(I.pointerPoint(s));if(!Dh(Z?Ar(Z.id,f):f))switch(g.kind){case"create":{let c=Tn(g.origin,g.current),m=o==="text"?"text":o==="frame"?"frame":o==="ellipse"?"ellipse":"rect";g=null,_e=ot,Q();let h=c.w<an||c.h<an;if(h&&m!=="text")return;let b=h?{x:c.x,y:c.y,w:Mm.w,h:Mm.h}:c,_=Sr({x:b.x,y:b.y})??w??n.root.id,C=U(n.root,_)??n.root,O=dn(_),R={x:Math.round(b.x-O.x),y:Math.round(b.y-O.y),w:Math.round(b.w),h:Math.round(b.h)},j=Wt(n.root,m);he([{op:"insert",parent:_,index:re(C).length,node:m==="text"?qi({...R,id:j,content:""}):m==="frame"?Zo({...R,id:j,background:Em,children:[]}):m==="ellipse"?Ui({...R,id:j,fill:t.defaultFill??"#3b82f6"}):ji({...R,id:j,fill:t.defaultFill??"#3b82f6"})}],T0[m]),ce([j]),Vt("select"),m==="text"&&$r(j);return}case"marquee":{let c=Tn(g.origin,g.current),m=s.shiftKey;if(g=null,_e=ot,c.w>=an||c.h>=an){let h=ux(c);ce(m?[...new Set([...r,...h])]:h)}Q();return}case"move":{let c=Mh();c.length>0&&($=[...$,...c]),Ht(S.length>0?"Duplicate":"Move");return}case"resize":Ht("Resize");return;case"scale":Ht(r.length===1?"Resize group":`Resize ${r.length} elements`);return;case"space":Ht("Spacing");return;case"reorder":Ht(g.swap?"Swap":"Reorder");return;case"adjust":Ht("Corner radius");return;case"rotate":Ht("Rotate");return}},Wf=s=>{if(xi(s.target))return;if(G){if(!((s.metaKey||s.ctrlKey)&&s.key.toLowerCase()==="z"))return;s.preventDefault(),G.breakBurst(),s.shiftKey?Wo():Nr();return}if(Y&&(s.key==="Enter"||s.key==="Escape")){s.preventDefault(),zo();return}if(Ph(s))return;if((s.metaKey||s.ctrlKey)&&s.shiftKey&&s.code==="KeyO"){if(zf()===0)return;s.preventDefault(),$i();return}if(s.key==="Enter"&&!$m(s)&&r.length===1){let m=r[0];if(U(n.root,m)?.type==="vector"&&pn(m)){s.preventDefault();return}}if(s.key==="Enter"&&!$m(s)&&r.length===1){let m=r[0];if(U(n.root,m)?.type==="text"){s.preventDefault(),$r(m);return}}if(s.code==="Space"&&!x){x=!0,qe(Fe("grab"));return}let f=s.metaKey||s.ctrlKey;if(f&&s.key.toLowerCase()==="z"){s.preventDefault(),s.shiftKey?Wo():Nr();return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyL"){if(!D.lock||r.length===0)return;s.preventDefault(),Bn(r,"locked");return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyH"){if(!D.hide||r.length===0)return;s.preventDefault(),Bn(r,"hidden");return}if(f&&s.key.toLowerCase()==="g"){s.preventDefault(),s.shiftKey?Ni():Ii();return}if(f&&s.key.toLowerCase()==="a"){s.preventDefault(),Fi();return}if(f&&!s.altKey&&s.key.toLowerCase()==="d"){s.preventDefault(),Di();return}if(s.altKey){let m=O0[s.code];if(m&&!f){s.preventDefault(),fu(m);return}let h=D0[s.code];if(h&&s.ctrlKey){s.preventDefault(),cu(h);return}}if(s.key==="]"||s.key==="["){if(r.length===0)return;s.preventDefault();let m=s.key==="]";Ri(f?m?"front":"back":m?"forward":"backward");return}if(s.key==="Escape"){g?Ai():w!==null?wu():ce([]);return}if(s.key==="Delete"||s.key==="Backspace"){if(r.length===0)return;s.preventDefault(),Hn();return}let c=f||s.altKey?void 0:gf[s.key.toLowerCase()];c&&Vt(c)};function Xf(){if(!G)return null;let s=U(n.root,G.id);if(s?.type!=="text")return null;let{anchor:f,head:c}=G.getSelection();return f===c?null:In(lf(s.content,f,c))}let Yf=s=>{if(xi(s.target))return;let f=Xf()??Ir();f!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",f))},Jf=s=>{if(xi(s.target))return;let f=Xf();if(f!==null&&G){s.preventDefault(),s.clipboardData?.setData("text/plain",f);let{anchor:m,head:h}=G.getSelection();G.breakBurst(),G.setSelection(m,h),G.handleInput({inputType:"deleteByCut",data:null});return}let c=Ir();c!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",c),Hn())},Zf=s=>{if(xi(s.target))return;s.preventDefault();let f=Ol(s.clipboardData);if(f&&!G){let m=ex();m?Oi(m,f):xu(f,We??void 0);return}let c=s.clipboardData?.getData("text/plain")||void 0;if(G&&c!==void 0){G.handleInput({inputType:"insertFromPaste",data:c});return}Li(c)},Qf=s=>{s.code==="Space"&&(x=!1,qe(Fe(ki())))},eu=s=>{if(!Se)return;s.preventDefault(),g&&Ai();let f=I.pointerPoint(s),c=I.screenToDocument(f),m=Er(c),h=Vh(c),b=I.hitTest(c),_=b!==null&&r.some(O=>je(n.root,b).includes(O));m===null?_||ce([]):r.includes(m)||ce([m]);let C=(t.menuExtras?.(r)??[]).map(O=>"separator"in O?O:{...O,id:`${vf}${O.id}`});Se.open(f,qd(zh(h),C))};function Vh(s){let{locked:f}=Qe(),c=[];for(let m of[...I.getScene().items].reverse()){if(!f.has(m.id)||!I.hitTest(s,b=>b===m.id))continue;let h=Rr(n.root,m.id,"locked");h!==void 0&&!c.includes(h)&&c.push(h)}return c}function zh(s=[]){let f=r.length===1?U(n.root,r[0]):void 0,c=[];if(f){let m=f;for(let h of yt(f)){let b=m[h];b===void 0||!be(b)||wa(b).kind!=="literal"&&c.push({prop:h,source:`=${b.expr}`})}}return{count:r.length,hasGroup:r.some(m=>{let h=U(n.root,m);return h!==void 0&&Oe(h)}),canPaste:bf!==null,isText:r.length===1&&U(n.root,r[0])?.type==="text",isVector:ie().length===1&&U(n.root,ie()[0])?.type==="vector",convertible:zf(),bound:c,lock:D.lock?r.every(m=>Qe().locked.has(m))?"unlock":"lock":null,hide:D.hide?r.every(m=>Qe().hidden.has(m))?"show":"hide":null,locksHere:s,anyLocked:Bi("locked").length>0,hiddenCount:Bi("hidden").length}}function jh(s){if(e.focus({preventScroll:!0}),s.startsWith(vf)){t.onMenuCommand?.(s.slice(vf.length),[...r]);return}if(s.startsWith("unlock:")){Fn([s.slice(7)],"locked",!1);return}if(s.startsWith("detach:")){let f=s.slice(7),c=r[0];c!==void 0&&Su(c,f);return}switch(s){case"copy":Ir();return;case"cut":hu();return;case"editText":{let f=r[0];f!==void 0&&$r(f);return}case"editPoints":{let f=r[0];f!==void 0&&pn(f);return}case"toVector":return $i();case"duplicate":return Di();case"paste":return Li();case"group":return Ii();case"ungroup":return Ni();case"front":case"forward":case"backward":case"back":return Ri(s);case"delete":return Hn();case"selectAll":return Fi();case"toggleLock":return Bn(r,"locked");case"toggleHidden":return Bn(r,"hidden");case"unlockAll":return Go("locked");case"showAll":return Go("hidden");case"fit":return I.fitToContent();case"zoom100":return I.setCamera({...I.getCamera(),zoom:1})}}let tu=s=>{if(M||o!=="select"||x||Z)return;let f=I.screenToDocument(I.pointerPoint(s)),c=I.hitTest(f,C=>!Qe().locked.has(C));if(c===null)return;let m=Ko().find(C=>C.id===c);if(m){s.preventDefault(),tx(m);return}let h=U(n.root,c);if(h?.type==="text"){s.preventDefault(),$r(c,f);return}if(h?.type==="vector"){s.preventDefault(),pn(c);return}let b=je(n.root,c),_=w===null?1:b.indexOf(w)+1;for(let C=Math.max(_,1);C<b.length;C+=1){let O=b[C];if(O===void 0)break;let R=U(n.root,O);if(!(!R||!Oe(R))){s.preventDefault(),bu(O),ce([b[C+1]??O]);return}}},nu=s=>Array.from(s.dataTransfer?.types??[]).includes("Files"),ru=()=>t.importImage!==void 0||t.importAudio!==void 0,ou=s=>{if(!nu(s)||!ru())return;s.preventDefault(),s.dataTransfer&&(s.dataTransfer.dropEffect="copy");let f=I.screenToDocument(I.pointerPoint(s)),c=yu(f)?.id??null;c!==u&&(u=c,Q())},au=s=>{s.relatedTarget instanceof Node&&e.contains(s.relatedTarget)||u!==null&&(u=null,Q())},iu=s=>{if(!nu(s)||!ru())return;s.preventDefault();let f=I.screenToDocument(I.pointerPoint(s)),c=yu(f);u=null,Q();let m=Array.from(s.dataTransfer?.files??[]),h=m.find(Cp);if(h&&t.importAudio){let _=Sr(f),C=_===null?void 0:lt(n).get(_),O=Ba(n),R=C!==void 0&&O.includes(C)?C:Ha(n,r,null)??C??null;R!==null&&gu(h,R);return}if(!t.importImage)return;let b=m.find(_=>_.type.startsWith("image/"));b&&(c?Oi(c,b):xu(b,f))},su=()=>{We=null,l=null,!g&&(a===null&&ne===null&&ke===null||(a=null,ne=null,ke=null,Q()))};function lu(){let s=ie().length===1?ie()[0]:void 0,f=s===void 0?void 0:U(n.root,s);return s!==void 0&&f&&!ye(f)?ln(s):0}function qh(s){if(x){qe(Fe("grab"));return}if(Z){it(null),qe(Fe("arrow"));return}if(o!=="select"){it(null),Ti(null),qo(null),qe(Fe(o==="text"?"text":"crosshair"));return}let f=ie().length===1?ie()[0]:null;if(f!==null){let b=fe.hitAdjuster(s);if(b){let _=U(n.root,f),C=_?Va(_,b.id):void 0;it(null),Ti(C?{id:b.id,prop:C.prop}:null),qe(Fe("radius",{badge:C?bi(f,[C.prop]):"none"}));return}Ti(null)}if(ie().length>0){let b=fe.hitHandle(s);if(b){it(null);let O=Oa(b.handle);qe(Fe("resize",{angle:Sl(b.handle)+lu(),badge:Of(Mr(),O)}));return}let _=fe.hitPageLabel(s);if(_!==null){it(_),qe(Fe("arrow"));return}let C=fe.hitRotate(s);if(C!==null){it(null),qe(Fe("rotate",{angle:$0[C]+lu()}));return}}let c=fe.hitPageLabel(s);if(c!==null){l=null,it(c),qe(Fe("arrow"));return}if(ie().length>1){if(fe.hitRing(s)!==null){it(null),qo(null),qe(Fe("grab"));return}let _=fe.hitSpacer(s),C=_===null?null:ii(_);if(_!==null&&C){it(null),qo(_),qe(Fe("resize",{angle:C.axis==="x"?0:90,badge:Of(Mr(),[C.axis])}));return}qo(null)}let m=I.screenToDocument(s),h=Er(m);l=Kh(m,h),it(h),Q(),qe(Fe("arrow",{badge:h===null?"none":bi(h,["x","y"])}))}function Kh(s,f){let c=I.hitTest(s);if(c===null||!Qe().locked.has(c))return null;let m=Rr(n.root,c,"locked");return m===void 0?null:f===null||je(n.root,m).includes(f)?m:null}function it(s){a!==s&&(a=s,Q())}function Ti(s){ne?.id!==s?.id&&(ne=s,Q())}function qo(s){ke!==s&&(ke=s,Q())}function qe(s){e.style.cursor!==s&&(e.style.cursor=s)}function Vt(s){o!==s&&(o=s,Y&&s!=="pen"&&zo(),s!=="select"&&Or(),we?.setTool(o),s!=="select"&&it(null),qe(Fe(ki())),de("tool",o))}function Gh(s){if(s.length===0)return null;if(s.length>1)return xt(s.map(m=>m.frame))??null;let f=s[0],c=ct(n.root,f.id);return c?On(c.id,n,I.getResolution())??null:null}function du(s,f,c){let m=br(n,Mi(Fo(r),s,f));m.length!==0&&he([...m,...wr(n,m,ir(n),Ne(n))],c)}function fu(s){let f=Ao(n,r,I.getResolution()),c=Gh(f);c&&du(Ua(s),Dl(f,c,s),P0[s])}function uu(s){let f=Ao(n,r,I.getResolution());if(f.length<3)return null;let c=tf(f,s),m=nf(c);return m===null?null:{gap:m,series:c}}function cu(s){let f=uu(s);f&&du(s,li(f.series,f.gap),s==="x"?"Distribute horizontally":"Distribute vertically")}function Wh(){let s=Co(n,r);if(s.length===0)return null;let f=I.getResolution(),c={};for(let m of s)se(m,h=>{let b=f.nodes.get(h.id)?.values;b&&(c[h.id]=b)});return{nodes:s,tokens:n.tokens,fonts:n.fonts,resolved:c}}function Xh(s){return new Map(Object.entries(s.resolved))}function Yh(s){let f=Object.entries(s.tokens).filter(([c])=>n.tokens[c]===void 0).map(([c,m])=>({op:"setToken",name:c,value:m}));for(let[c,m]of Object.entries(s.fonts))n.fonts[c]===void 0&&f.push({op:"setFont",name:c,family:m});return f}function pu(s,f,c){let{nodes:m,remap:h}=Od(s,n);if(m.length===0)return null;let b=Yh(s),_=b.length>0?Ae(n,b).document:n;m.forEach((R,j)=>{let W=s.nodes[j];if(!W)return;let xe=f(W,j,_),K={op:"insert",parent:xe.parent,index:xe.index,node:R};b.push(K),_=Ae(_,[K]).document});let C=yf(_,h,Xh(s),c);C.length>0&&(_=Ae(_,C).document);let O=Jh(m);return{ops:[...b,...C,...kr(n,_)],ids:[...h.values()].filter(R=>O.has(R))}}function Jh(s){let f=new Set;for(let c of s)f.add(c.id);return f}function mu(s){let f=Wh();return f?pu(f,(c,m,h)=>{let b=ct(h.root,c.id)??h.root,_=re(b).findIndex(C=>C.id===c.id);return{parent:b.id,index:_===-1?re(b).length:_+1}},s):null}function Ir(){let s=Td(n,r,I.getResolution());return s!==null&&(bf=s),s}function hu(){let s=Ir();return s!==null&&Hn(),s}function Zh(s){let f=[];for(let c of s.nodes){let m=s.resolved[c.id];if(!m)continue;let{x:h,y:b,w:_,h:C}=m;h===void 0||b===void 0||_===void 0||C===void 0||f.push({x:h,y:b,w:_,h:C})}return xt(f)??null}function Li(s,f){let c=Ld(s??bf??"");if(!c)return;let m=f??We,h=Zh(c),b=m&&h?{x:m.x-(h.x+h.w/2),y:m.y-(h.y+h.h/2)}:{x:hi,y:hi},_=w??n.root.id,C=pu(c,(O,R,j)=>({parent:_,index:re(U(j.root,_)??j.root).length}),b);C&&(he(C.ops,C.ids.length===1?"Paste":`Paste ${C.ids.length} elements`),ce(C.ids))}async function xu(s,f){let c=t.importImage;if(!c)return;let m=await Fa(s,t.maxImageEdge??2560);if(!m)return;let h=await c(new File([m.bytes],s.name,{type:m.type}));if(!h)return;let b=(f?Sr(f):void 0)??w??n.root.id,_=U(n.root,b)??n.root,C=dn(b),O=I.getResolution().nodes.get(b),{w:R,h:j}=Ep(m.width,m.height,O?.w&&O.w>0?O.w:m.width,O?.h&&O.h>0?O.h:m.height),W=f??We,xe=Math.round((W?W.x-R/2:C.x)-C.x),K=Math.round((W?W.y-j/2:C.y)-C.y),ve=nx(n,s.name),He=Wt(n.root,"image");he([{op:"setAsset",name:ve,value:h},{op:"insert",parent:b,index:re(_).length,node:zi({id:He,x:xe,y:K,w:R,h:j,src:ve,fit:"cover"})}],"Place image"),ce([He])}async function gu(s,f){let c=t.importAudio;if(!c)return!1;let m=await c(s);return m?(he(Ap(n,f,Mp(n,f,s.name),m),"Add music"),!0):!1}function Ko(){return t.importImage?um(n,Qe().hidden):[]}function Qh(){return Ko().flatMap(s=>{let f=Ie(s.id);return f?[{frame:f,label:s.label,target:s.id===u}]:[]})}function yu(s){return Ko().filter(c=>{let m=Ie(c.id);return m!==void 0&&gt(m,s.x,s.y)}).at(-1)??null}function ex(){return r.length!==1?null:Ko().find(s=>s.id===r[0])??null}async function Oi(s,f){let c=t.importImage;if(!c)return;let m=await Fa(f,t.maxImageEdge??2560);if(!m)return;let h=await c(new File([m.bytes],f.name,{type:m.type}));!h||n.assets[s.src]!==void 0||(he([{op:"setAsset",name:s.src,value:h}],"Add image"),ce([s.id]))}function tx(s){let f=e.ownerDocument.createElement("input");f.type="file",f.accept="image/*",f.addEventListener("change",()=>{let c=f.files?.[0];c&&Oi(s,c)}),f.click()}function nx(s,f){let c=f.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"image";if(s.assets[c]===void 0)return c;for(let m=2;;m+=1){let h=`${c}-${m}`;if(s.assets[h]===void 0)return h}}function Di(){let s=mu({x:hi,y:hi});s&&(he(s.ops,s.ids.length===1?"Duplicate":`Duplicate ${s.ids.length} elements`),ce(s.ids))}function Pi(s,f){if(s.length===0)return;let c=Ae(n,s).document;he([...s,...kr(n,c)],f)}function Ii(){let s=Dd(n,r);s&&(Pi(s.ops,"Group"),ce([s.groupId]))}function Ni(){let s=r.filter(h=>{let b=U(n.root,h);return b!==void 0&&Oe(b)});if(s.length===0)return;let f=n,c=[],m=[];for(let h of s){let b=U(f.root,h);b&&m.push(...re(b).map(C=>C.id));let _=Pd(f,h);_.length!==0&&(c.push(..._),f=Ae(f,_).document)}w!==null&&s.includes(w)&&(w=null),Pi(c,s.length===1?"Ungroup":`Ungroup ${s.length} groups`),ce(m)}function Ri(s){Pi(Id(n,r,s),R0[s])}function rx(s,f,c){let m=U(n.root,f);if(!m||!ye(m))return;let h=new Set(je(n.root,f)),b=s.filter(K=>K!==n.root.id&&U(n.root,K)&&!h.has(K));if(b.length===0)return;let _=new Set(b),C=re(m).filter(K=>!_.has(K.id))[c]?.id,O=[],R=n;for(let K of b){let ve=re(U(R.root,f)??R.root).filter(ut=>ut.id!==K),He=C===void 0?-1:ve.findIndex(ut=>ut.id===C),Ue={op:"move",id:K,parent:f,index:He===-1?ve.length:He};O.push(Ue),R=Ae(R,[Ue]).document}if(b.every(K=>ax(n,R,K)))return;let j=new Set(b.filter(K=>ct(n.root,K)?.id!==f).flatMap(K=>Uf(K,R))),W=[];for(let K of b){let ve=vu(n,K),He=vu(R,K),Ue={x:ve.x-He.x,y:ve.y-He.y};if(!(Ue.x===0&&Ue.y===0))for(let ut of Ln(K,R)){let Un=Bt(ut);Un&&(W.push({op:"set",id:ut,prop:"x",value:ee(Un.x+Ue.x)}),W.push({op:"set",id:ut,prop:"y",value:ee(Un.y+Ue.y)}))}}let xe=Ae(R,W).document;he([...O,...W,...kr(n,xe,j)],b.length===1?`Move ${b[0]}`:`Move ${b.length} layers`)}function ox(s={}){let f=n.root.children,c=f.filter(He=>He.type==="frame"),m=c.find(He=>He.id===s.after),h=I.getResolution(),b=m?h.nodes.get(m.id):void 0,_=b&&b.w>0?b.w:Cm.w,C=b&&b.h>0?b.h:Cm.h,O=null,R=-1/0;for(let He of c.length>0?c:f){let Ue=h.nodes.get(He.id);!Ue||Ue.absX+Ue.w<=R||(R=Ue.absX+Ue.w,O={x:R+M0,y:Ue.absY})}let j=O??{x:0,y:0},W=m??c[c.length-1],xe=W?f.indexOf(W)+1:f.length,K=Wt(n.root,"frame"),ve=m?.type==="frame"?m.background:void 0;return he([{op:"insert",parent:n.root.id,index:xe,node:Zo({id:K,x:ee(j.x),y:ee(j.y),w:ee(_),h:ee(C),background:ve??Em,children:[]})}],"Add frame"),ce([K]),K}function ax(s,f,c){let m=ct(s.root,c),h=ct(f.root,c);return m?.id===h?.id&&m?.children.findIndex(b=>b.id===c)===h?.children.findIndex(b=>b.id===c)}function vu(s,f){let c=je(s.root,f).slice(0,-1).reverse(),m=Ne(s);for(let h of c){let b=U(s.root,h);if(!b||Oe(b))continue;let _=m.nodes.get(h);return _?{x:_.absX,y:_.absY}:{x:0,y:0}}return{x:0,y:0}}function bu(s){let f=U(n.root,s);!f||!Oe(f)||(w=s,Q())}function wu(){if(w===null)return;let s=w;w=je(n.root,s).slice(0,-1).reverse().find(c=>{let m=U(n.root,c);return m!==void 0&&Oe(m)})??null,ce([s])}function Fi(){let s=U(n.root,w??n.root.id)??n.root;ce(re(s).map(f=>f.id).filter(fn))}let ix={locked:["Lock","Unlock"],hidden:["Hide","Show"]};function ku(s){return s==="locked"?Qe().locked:Qe().hidden}function Fn(s,f,c){let m=s.filter(_=>_!==n.root.id&&U(n.root,_)),h=c?m.filter(_=>!ku(f).has(_)):[...new Set(m.flatMap(_=>{let C=Rr(n.root,_,f);return C===void 0?[]:[C]}))];if(h.length===0)return;let b=ix[f][c?0:1];he(h.map(_=>({op:"set",id:_,prop:f,value:c?!0:void 0})),h.length===1?`${b} ${h[0]}`:`${b} ${h.length} layers`)}function Bn(s,f){s.length!==0&&Fn(s,f,!s.every(c=>ku(f).has(c)))}function Bi(s){let f=[];return se(n.root,c=>{c[s]===!0&&f.push(c.id)}),f}function Go(s){let f=Bi(s);if(f.length===0)return;let c=s==="locked"?"Unlock all":"Show all";he(f.map(m=>({op:"set",id:m,prop:s,value:void 0})),c)}function sx(s){D={...Am,...s},Se?.close()}function Hn(){let s=r.filter(c=>c!==n.root.id).map(c=>({op:"remove",id:c}));if(s.length===0)return;let f=s.length;ce([]),he(s,f===1?"Delete element":`Delete ${f} elements`)}function Nr(){et=null;let s=H.undo();s&&Df(s.ops,`Undo ${s.entry.label}`)}function Wo(){et=null;let s=H.redo();s&&Df(s.ops,`Redo ${s.entry.label}`)}function lx(s){if(!H.isTail(s))return!1;for(let f=s.length;f>0;f-=1)Nr();return!0}function _u(s,f,c,m){let h=U(n.root,s);if(!h)return;let b=h[f];H0(b,c)||he([{op:"set",id:s,prop:f,value:c}],m??`Set ${f}`)}function dx(s,f){n.tokens[s]!==f&&he([{op:"setToken",name:s,value:f}],`Set $${s}`)}function fx(s){s in n.tokens&&he([{op:"setToken",name:s,value:void 0}],`Remove $${s}`)}function Su(s,f){let c=Ct(s)?.values[f];c!==void 0&&he([{op:"set",id:s,prop:f,value:ee(c)}],`Detach ${f}`)}function ux(s){let f=U(n.root,w??n.root.id)??n.root,c=[];for(let m of re(f)){if(!fn(m.id))continue;let h=Ie(m.id);h&&El(h,s)&&c.push(m.id)}return c}function st(s){typeof e.setPointerCapture=="function"&&e.setPointerCapture(s)}function Hi(s){e.hasPointerCapture?.(s)&&e.releasePointerCapture(s)}let Eu=s=>{G&&(Rf(),G.handleKey(s)&&(s.preventDefault(),s.stopPropagation()))},Cu=s=>{G&&(s.preventDefault(),Rf(),G.handleInput(s))},Mu=()=>G?.handleCompositionStart(),Au=s=>G?.handleCompositionUpdate(s.data??""),$u=s=>G?.handleCompositionEnd(s.data??""),Tu=s=>{if(!e.ownerDocument.hasFocus())return;let f=s.relatedTarget;f instanceof Element&&f.closest("[data-vd-keeps-text]")||un("blur")};return z.addEventListener("keydown",Eu),z.addEventListener("beforeinput",Cu),z.addEventListener("compositionstart",Mu),z.addEventListener("compositionupdate",Au),z.addEventListener("compositionend",$u),z.addEventListener("blur",Tu),e.addEventListener("pointerdown",qf),e.addEventListener("pointermove",Gf),e.addEventListener("pointerup",jo),e.addEventListener("pointercancel",jo),e.addEventListener("pointerup",Ro),e.addEventListener("pointercancel",Ro),e.addEventListener("pointerleave",su),e.addEventListener("dblclick",tu),e.addEventListener("contextmenu",eu),e.addEventListener("keydown",Wf),e.addEventListener("keyup",Qf),e.addEventListener("copy",Yf),e.addEventListener("cut",Jf),e.addEventListener("paste",Zf),e.addEventListener("dragover",ou),e.addEventListener("dragleave",au),e.addEventListener("drop",iu),v=!0,we?.setTool(o),we?.setHistory(!1,!1),we?.setZoom(I.getCamera().zoom),qe(Fe(ki())),t.autoFit&&!t.camera&&Te(()=>I.fitToContent()),t.history&&(H.restore(t.history),we?.setHistory(H.canUndo,H.canRedo)),t.selection&&t.selection.length>0&&ce(t.selection),Q(),{element:e,viewer:I,getDocument:()=>n,update(s){n=s,I.update(n),ce(r),Q(),de("problems",wi())},applyOps:(s,f)=>he(s,f??"Apply changes"),setDocument:(s,f)=>he(us(n,wl(s,n.root.id)),f??"Replace document"),getSelection:()=>r,setSelection:ce,selectAll:Fi,deleteSelection:Hn,lock:s=>Fn(s??r,"locked",!0),unlock:s=>Fn(s??r,"locked",!1),toggleLock:s=>Bn(s??r,"locked"),unlockAll:()=>Go("locked"),hide:s=>Fn(s??r,"hidden",!0),show:s=>Fn(s??r,"hidden",!1),toggleHidden:s=>Bn(s??r,"hidden"),showAll:()=>Go("hidden"),isLocked:s=>Qe().locked.has(s),isHidden:s=>Qe().hidden.has(s),setFeatures:sx,getFeatures:()=>D,moveLayers:rx,addFrame:ox,copy:Ir,cut:hu,paste:Li,duplicate:Di,group:Ii,ungroup:Ni,reorder:Ri,scaleSelection:gh,getSpacing:wh,setSpacing:bh,align:fu,distribute:cu,canDistribute:s=>uu(s)!==null,editText:$r,endTextEditing:()=>un("done"),getEditingText:()=>G?.id??null,formatText:s=>G?.format(s),getTextFormat:()=>G?.activeMark()??{},getTextSelectionRects:If,getTextRange:()=>{if(!G)return null;let{anchor:s,head:f}=G.getSelection();return{from:Math.min(s,f),to:Math.max(s,f)}},getEnteredGroup:()=>w,enterGroup:bu,exitGroup:wu,getTool:()=>o,editPoints:pn,stopEditingPoints:Or,getPointEditing:()=>Z?.id??null,convertToVector:s=>$i(s),setTool:Vt,beginEdit:rh,endEdit:oh,undo:Nr,redo:Wo,canUndo:()=>H.canUndo,canRedo:()=>H.canRedo,getHistory:()=>H.snapshot(),setProperty:_u,fontFamilies:()=>{let s=new Map;for(let f of t.fonts?.faces()??[]){let c=s.get(f.family)??{weights:new Set,italic:!1};c.weights.add(f.weight),f.style==="italic"?c.italic=!0:(c.css===void 0||f.weight===400)&&(c.css=f.id),s.set(f.family,c)}return[...s.entries()].sort(([f],[c])=>f.localeCompare(c)).map(([f,c])=>({family:f,weights:[...c.weights].sort((m,h)=>m-h),italic:c.italic,...c.css===void 0?{}:{css:c.css}}))},assetUrl:s=>{let f=n.assets[s];return f?t.resolveAsset?.(f,s):void 0},addMusic:gu,canAddMusic:()=>t.importAudio!==void 0,setToken:dx,removeToken:fx,bindingsOf:nh,unbind:Su,getResolution:()=>I.getResolution(),getCamera:()=>I.getCamera(),getProblems:wi,on:le,reveal:Le,panBy:Qm,setPresence(s,f){d={ids:[...s],label:f??null},Q()},setHighlight(s){s.length===0&&p.length===0||(p=[...s],Q())},isHistoryTail:s=>H.isTail(s),undoTail:lx,historyTop:()=>H.top,destroy(){ae(),e.removeEventListener("pointerup",Ro),e.removeEventListener("pointercancel",Ro),e.removeEventListener("pointerdown",qf),e.removeEventListener("pointermove",Gf),e.removeEventListener("pointerup",jo),e.removeEventListener("pointercancel",jo),e.removeEventListener("pointerleave",su),z.removeEventListener("keydown",Eu),z.removeEventListener("beforeinput",Cu),z.removeEventListener("compositionstart",Mu),z.removeEventListener("compositionupdate",Au),z.removeEventListener("compositionend",$u),z.removeEventListener("blur",Tu),z.remove(),Rn&&clearTimeout(Rn),e.removeEventListener("dblclick",tu),e.removeEventListener("contextmenu",eu),e.removeEventListener("copy",Yf),e.removeEventListener("cut",Jf),e.removeEventListener("paste",Zf),e.removeEventListener("dragover",ou),e.removeEventListener("dragleave",au),e.removeEventListener("drop",iu),e.removeEventListener("keydown",Wf),e.removeEventListener("keyup",Qf),Se?.destroy(),we?.destroy(),fe.destroy(),I.destroy(),te.remove(),X.clear(),e.style.cursor="",e.classList.remove("vd-editor")}}}function H0(e,t){return e===t?!0:be(e)&&be(t)?e.expr===t.expr:!1}function $m(e){return e.metaKey||e.ctrlKey||e.altKey}function xi(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 HM=new Set(on);function Ef(e){return e.map(t=>({value:t,label:`${t.charAt(0).toUpperCase()}${t.slice(1)}`}))}var z0=[{value:"nonzero",label:"Non-zero"},{value:"evenodd",label:"Even-odd"}].filter(e=>hn.includes(e.value)),j0=Ef(xn),q0=Ef(Kt),K0=Ef(gn),G0=[{value:"left",label:"Left",icon:Ge("text-left")},{value:"center",label:"Centre",icon:Ge("text-center")},{value:"right",label:"Right",icon:Ge("text-right")},{value:"justify",label:"Justify",icon:Ge("text-justify")}].filter(e=>jt.includes(e.value)),W0=[{value:"top",label:"Top",icon:Ge("text-top")},{value:"middle",label:"Middle",icon:Ge("text-middle")},{value:"bottom",label:"Bottom",icon:Ge("text-bottom")}].filter(e=>qt.includes(e.value)),Dm={prop:"x",label:"X",kind:"number",prefix:"X"},Pm={prop:"y",label:"Y",kind:"number",prefix:"Y"},_f={prop:"w",label:"W",kind:"number",prefix:"W"},Sf={prop:"h",label:"H",kind:"number",prefix:"H"},X0={prop:"rotation",label:"Rotation",kind:"number",icon:"rotate",fallback:"0"},Y0={prop:"opacity",label:"Opacity",kind:"number",icon:"opacity",percent:!0,fallback:"100%"},Lm={prop:"radius",label:"Radius",kind:"number",icon:"radius",span:"wide",fallback:"0"},Io={heading:"Position",props:[Dm,Pm,_f,Sf,X0,Y0]},gi={prop:"fill",label:"Fill",kind:"colour"},Im={prop:"stroke",label:"Stroke",kind:"colour",span:"half"},Nm={prop:"strokeWidth",label:"Stroke width",kind:"number",prefix:"Width",fallback:"1"},Rm={present:"stroke",empty:"No stroke",add:{stroke:"#000000",strokeWidth:1},clear:["stroke","strokeWidth","cap","join"]},Om={heading:"Stroke",props:[Im,Nm],optional:Rm},UM={frame:[{heading:"Frame",props:[Dm,Pm,_f,Sf,{prop:"clip",label:"Clip content",kind:"toggle"}]},{heading:"Fill",props:[{prop:"background",label:"Fill",kind:"colour"}]}],canvas:[{heading:"Canvas",props:[_f,Sf,{prop:"background",label:"Fill",kind:"colour"}]}],text:[Io,{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:G0,span:"half"},{prop:"valign",label:"Vertical",kind:"segmented",options:W0,span:"half"}]},{heading:"Fill",props:[gi]},{heading:"Link",props:[{prop:"content",label:"Link",kind:"link",icon:"link"}]}],rect:[{heading:"Position",props:[...Io.props,Lm]},{heading:"Fill",props:[gi]},Om],ellipse:[Io,{heading:"Fill",props:[gi]},Om],image:[{heading:"Position",props:[...Io.props,Lm]},{heading:"Image",props:[{prop:"fit",label:"Fit",kind:"select",options:q0,prefix:"Fit"}]}],vector:[Io,{heading:"Fill",props:[{...gi,span:"half"},{prop:"rule",label:"Fill rule",kind:"select",options:z0,prefix:"Rule",span:"half"}]},{heading:"Stroke",props:[Im,Nm,{prop:"cap",label:"Cap",kind:"select",options:j0,prefix:"Cap",span:"half"},{prop:"join",label:"Join",kind:"select",options:K0,prefix:"Join",span:"half"}],optional:Rm}]};var VM=mn.map(e=>({value:e,label:e.split("-").map((t,n)=>n===0?t.charAt(0).toUpperCase()+t.slice(1):t).join(" ")}));function Fm(e){let t=e,n=new Map,r=typeof URL.createObjectURL=="function"&&typeof URL.revokeObjectURL=="function";return{resolve(o){let a=n.get(o.hash);if(a!==void 0)return a;let i=t.get(o.hash);if(i===void 0)return;if(!r)return Es(o.type,i);let l;try{l=Ms(i)}catch{return}let d=URL.createObjectURL(new Blob([l],{type:o.type}));return n.set(o.hash,d),d},replace(o){t=o;for(let[a,i]of n)o.has(a)||(URL.revokeObjectURL(i),n.delete(a))},destroy(){for(let o of n.values())URL.revokeObjectURL(o);n.clear(),t=new Map}}}var Cf="0.3.2",Bm="https://cdn.jsdelivr.net/npm/@getv.design/embed@0.3.2/fonts/";var ib=Symbol.for(`vdesign.embed.documents@${Cf}`),Hm=globalThis[ib]??=new WeakMap,sb=/^Line (\d+): /;function Af(e){let t=sb.exec(e.message);return{...t?{line:Number(t[1])}:{},code:e.code,message:e.message,severity:e.severity}}function Mf(e){if(typeof e!="string")return vi(ro("").document,new Map,[{code:"not-text",message:`parse() takes .vd text, not ${e===null?"null":typeof e}.`,severity:"error"}]);let t=lb(e);if(t.vd===void 0)return vi(ro("").document,new Map,[{code:"not-vd",message:"This SVG carries no vDesign document: only a .vd.svg exported from vDesign does.",severity:"error"}]);let{head:n,blocks:r}=ks(t.vd),o=ro(n),a=o.problems.map(Af).map(i=>i.line===void 0?i:{...i,line:i.line+t.offset});return vi(o.document,r,a)}function lb(e){if(!Ds(e))return{vd:e,offset:0};let t=Os(e);if(t===void 0)return{vd:void 0,offset:0};let n=e.indexOf("<vd:document"),r=e.indexOf("</vd:document",n),o=e.indexOf("<![CDATA[",n);if(o===-1||r!==-1&&o>r){let l=e.indexOf(">",n)+1,d=e.slice(0,l).split(`
2792
- `).length-1;return{vd:t,offset:d+(e[l]===`
2793
- `?1:0)}}let a=o+9,i=e.slice(0,a).split(`
2794
- `).length-1;return{vd:t,offset:i+(e[a]===`
2795
- `?1:0)}}function vi(e,t,n){let r=Object.freeze({});return Hm.set(r,{document:e,blocks:t,problems:n}),{document:r,problems:n}}function Um(e,t,n){return vi(e,t,[...n]).document}function yi(e){let t=Hm.get(e);if(!t)throw new TypeError("Not a vDesign document: pass .vd text or what parse() returned.");return t}async function Vm(e){if(typeof e=="string")return yi(Mf(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 yi(Mf(await t.text()).document)}return db(e)?yi(Mf(await e.text()).document):yi(e)}function db(e){let t=e;return typeof t.text=="function"&&typeof t.size=="number"}function _r(e){return e.root.children.filter(t=>t.type==="frame"&&t.hidden!==!0)}function zm(e,t){let n=_r(e),r=typeof t=="number"?n[t]:n.find(o=>o.id===t);if(!r){let o=n.map(a=>a.id).join(", ")||"none";throw new RangeError(`No page ${JSON.stringify(t)} in this document; its pages: ${o}.`)}return r}var $f=["page","content","none"],jm=24;function No(e){let t=e.getBoundingClientRect();return{width:t.width,height:t.height}}function qm(e,t){let n=t===void 0?void 0:e.itemOf(t);if(!(!n||n.w<=0||n.h<=0))return{x:n.x,y:n.y,width:n.w,height:n.h}}function Km(e,t,n,r){if(n==="none")return;let o=n==="page"?qm(e,r):void 0;if(!o){e.fitToContent(jm);return}let a=No(t);e.setCamera(tn(o,{width:a.width||o.width,height:a.height||o.height},jm))}function Gm(e,t,n){let r=e.getCamera(),o=No(t),a={x:(o.width/2-r.x)/r.zoom,y:(o.height/2-r.y)/r.zoom},i;for(let l of _r(e.getDocument())){let d=qm(e,l.id);if(!d)continue;let u=Math.max(d.x-a.x,0,a.x-(d.x+d.width)),p=Math.max(d.y-a.y,0,a.y-(d.y+d.height)),x=Math.hypot(u,p);(!i||x<i.distance)&&(i={id:l.id,distance:x})}return i?.id??n}function Wm(e,t,n){let r=e===void 0?t:String(e);if(r===void 0)return;let o;try{o=new URL(r,n??globalThis.location?.href)}catch{throw new TypeError(`fontBase must be a URL, or a path on this page; got ${r}.`)}return o.pathname.endsWith("/")||(o.pathname+="/"),o}var Tf=Symbol.for("vdesign.embed.handover");function Xm(e){return e[Tf]}var Ym=["exact","browser"],Jm=["change"],fb=250;async function L2(e,t,n={}){let r=n.fit??"page";if(!$f.includes(r))throw new TypeError(`edit: fit must be one of ${$f.join(", ")}; got ${String(r)}.`);let o=n.fonts??"exact";if(!Ym.includes(o))throw new TypeError(`edit: fonts must be one of ${Ym.join(", ")}; got ${String(o)}.`);let a=o==="exact"?Wm(n.fontBase,Bm,e.ownerDocument.baseURI):void 0,i=Xm(n),l=await Vm(t),d=i?.page!==void 0&&_r(l.document).some(F=>F.id===i.page)?i.page:n.page===void 0?_r(l.document)[0]?.id:zm(l.document,n.page).id,u=i?.exact&&a?await ub(a,l.document):void 0,p=e.ownerDocument,x=p.defaultView,y=new Map(l.blocks),k=Fm(y),M=p.createElement("div");M.className="vd-embed vd-embed--edit",M.style.position="relative",M.style.width="100%",M.style.height="100%",e.appendChild(M);let v=F=>{n.onLink?n.onLink(F):x?.open(F,"_blank","noopener,noreferrer")},w;try{w=kf(M,{document:l.document,chrome:n.toolbar??!0,interactive:n.interactive??!0,wheel:"modifier",resolveAsset:F=>k.resolve(F),importImage:fe,onOpenLink:v,...n.surface?{surface:n.surface}:{},...i?{camera:i.camera}:{},...u?{fonts:u.library}:{}})}catch(F){throw M.remove(),k.destroy(),F}let D=new Set,A=!1,H=!1,E=0,T=i===void 0,P,V,X,te;function I(F){return X?.of!==F&&(X={of:F,text:_s(ws(F),y)}),X.text}async function fe(F){if(A||!F.type.startsWith("image/"))return null;let ne=new Uint8Array(await F.arrayBuffer()),ke=await Ss(ne);return A?null:(y.has(ke)||y.set(ke,Cs(ne)),{type:F.type,hash:ke,bytes:ne.length})}function we(){E+=1;try{Km(w.viewer,M,r,d)}finally{E-=1}}let Se=w.on("navigate",()=>{E===0&&(T=!1)}),me=w.on("change",({document:F})=>{let ne={text:()=>I(F)};for(let ke of[...D])ke(ne);u&&L()}),ue=No(M),S=x&&"ResizeObserver"in x?new x.ResizeObserver(()=>{let F=No(M);F.width===ue.width&&F.height===ue.height||(ue=F,T&&we())}):void 0;S?.observe(M),i||we(),!u&&o==="exact"&&$();function g(){return V??=(async()=>{if(a)try{let{exactFontsAt:F}=await import("./chunks/fonts.js");return F(a)}catch{return}})(),V}async function $(){let F=await g();if(!(A||!F)){for(;;){let ne=w.getDocument(),ke=await F.ensure(ne);if(A||ke.length>0)return;if(w.getDocument()===ne)break}u=F,w.viewer.setFonts(F.library)}}function L(){P!==void 0&&clearTimeout(P),P=setTimeout(()=>{P=void 0;let F=u;A||!F||F.ensure(w.getDocument()).then(ne=>{A||u!==F||ne.length===0||(u=void 0,w.viewer.setFonts(void 0))})},fb)}function B(){A||(A=!0,P!==void 0&&clearTimeout(P),me(),Se(),S?.disconnect(),w.destroy(),k.destroy(),M.remove(),D.clear())}let q={getText:()=>I(w.getDocument()),getDocument(){let F=w.getDocument();return te?.of!==F&&(te={of:F,document:Um(F,new Map(y),w.getProblems().map(Af))}),te.document},on(F,ne){if(!Jm.includes(F))throw new TypeError(`edit: on() takes one of ${Jm.join(", ")}; got ${String(F)}.`);return D.add(ne),()=>{D.delete(ne)}},undo(){A||w.undo()},redo(){A||w.redo()},async view(){if(A)throw new Error("edit: this editor was destroyed.");if(H)throw new Error("edit: view() is already opening a view.");H=!0,M.inert=!0;try{w.endTextEditing();let{view:F}=await import("./view.js");if(A)throw new Error("edit: this editor was destroyed.");d=Gm(w.viewer,M,d);let ne={camera:w.viewer.getCamera(),page:d,exact:u!==void 0},ke=w.getDocument(),Me=await F(e,q.getDocument(),{...cb(n),[Tf]:ne});if(A)throw Me.destroy(),new Error("edit: this editor was destroyed.");let _e=w.getDocument()===ke?void 0:q.getDocument();return B(),_e&&await Me.load(_e),Me}finally{H=!1,M.inert=!1}},destroy:B};return q}async function ub(e,t){try{let{exactFontsAt:n}=await import("./chunks/fonts.js"),r=n(e);return(await r.ensure(t)).length===0?r:void 0}catch{return}}function cb(e){let{toolbar:t,...n}=e;return n}export{L2 as edit,Cf as version};
2789
+ `;function _r(e){if(e.getElementById(zm))return;let t=e.createElement("style");t.id=zm,t.textContent=jm,e.head.appendChild(t)}var un=["font","size","weight","italic","underline","strike","fill","letterSpacing","link"];function Hn(e){return typeof e=="string"?e===""?[]:[{text:e}]:e.flatMap(t=>typeof t=="string"?t===""?[]:[{text:t}]:t.text===""?[]:[t])}function Un(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function Vn(e){return Un(e).length}function Bn(e){let t={};for(let n of un){let r=e[n];r!==void 0&&(t[n]=r)}return t}function Gm(e,t){return un.every(n=>e[n]===t[n])}function n0(e,t){let n={text:e};for(let r of un){let o=t[r];o!==void 0&&(n[r]=o)}return n}function Bo(e){let t=Hn(e),n=[];for(let o of t){let a=n[n.length-1];if(a&&Gm(Bn(a),Bn(o))){n[n.length-1]={...a,text:a.text+o.text};continue}n.push(o)}if(n.length===0)return"";let r=n[0];return n.length===1&&Km(r)?r.text:n.map(o=>Km(o)?o.text:o)}function Km(e){return un.every(t=>e[t]===void 0)}function Cu(e,t,n){let[r,o]=ks(t,n,Vn(e)),a=[],s=0;for(let d of Hn(e)){let l=s+d.text.length,f=Math.max(r,s),c=Math.min(o,l);c>f&&a.push({...d,text:d.text.slice(f-s,c-s)}),s=l}return Bo(a)}function Sr(e,t,n,r,o){let a=Vn(e),[s,d]=ks(t,n,a),l=o??Ho(e,s),f=[],c=0,m=!1,g=()=>{m||r===""||(f.push(n0(r,l)),m=!0)};for(let b of Hn(e)){let E=c+b.text.length,v=Math.min(s,E);v>c&&f.push({...b,text:b.text.slice(0,v-c)}),s>=c&&s<=E&&g();let w=Math.max(d,c);E>w&&f.push({...b,text:b.text.slice(w-c)}),c=E}return g(),Bo(f)}function Ho(e,t){let n=Hn(e);if(n.length===0)return{};let r=0,o=n[0];for(let a of n){let s=r+a.text.length;if(t>r&&t<=s)return Bn(a);if(t<=r)return Bn(o);o=a,r=s}return Bn(o)}function Mu(e,t,n,r){let[o,a]=ks(t,n,Vn(e));if(o===a)return Bo(e);let s=Object.keys(r),d=[],l=0;for(let f of Hn(e)){let c=l+f.text.length;for(let[m,g,b]of r0(l,c,o,a)){if(g<=m)continue;let E=f.text.slice(m-l,g-l);if(!b){d.push({...f,text:E});continue}let v={...f,text:E};for(let w of s)r[w]===void 0?delete v[w]:v[w]=r[w];d.push(v)}l=c}return Bo(d)}function r0(e,t,n,r){return[[e,Math.min(t,n),!1],[Math.max(e,n),Math.min(t,r),!0],[Math.max(e,r),t,!1]]}function Au(e,t,n){let[r,o]=ks(t,n,Vn(e));if(r===o)return Ho(e,r);let a,s=0;for(let d of Hn(e)){let l=s+d.text.length;if(Math.min(l,o)>Math.max(s,r)){let f=Bn(d);if(!a)a=f;else{let c={};for(let m of un)a[m]===f[m]&&a[m]!==void 0&&(c[m]=a[m]);a=c}}s=l}return a??{}}function ks(e,t,n){let r=qm(Math.min(e,t),n),o=qm(Math.max(e,t),n);return[r,o]}function qm(e,t){return Math.max(0,Math.min(Math.round(e),t))}function Er(e,t){let n=[],r=0;return e.lines.forEach((o,a)=>{let s=o.spans.map(c=>c.text).join(""),d=s===""?r:o0(t,s,r),l=d+s.length,f=a===e.lines.length-1;n.push({start:d,end:f?t.length:l}),r=l}),n.length===0&&n.push({start:0,end:t.length}),n}function o0(e,t,n){let r=e.indexOf(t,n);return r===-1?n:r}function _s(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if(t<=r.end)return n}return Math.max(0,e.length-1)}function Ss(e,t,n,r){let o=Er(e,t),a=_s(o,n),s=e.lines[a],d=o[a];if(!s||!d)return{x:0,y:0,h:0,line:0};let l=Math.max(0,Math.min(n-d.start,Xm(s))),f=(a0(s,l)??s.style)?.fill;return{x:$u(s,l,r),y:s.y,h:s.h,line:a,...f!==void 0?{fill:f}:{}}}function a0(e,t){let n=0;for(let r of e.spans)if(n+=[...r.text].length,t<=n)return r.style;return e.spans[e.spans.length-1]?.style}function Uo(e,t,n,r){let o=Er(e,t);if(e.lines.length===0)return 0;let a=e.lines.findIndex(l=>n.y<l.y+l.h);a===-1&&(a=e.lines.length-1);let s=e.lines[a];return o[a].start+Wm(s,n.x,r)}function Wm(e,t,n){let r=0,o=1/0,a=0,s=(d,l)=>{let f=Math.abs(l-t);f<o&&(o=f,r=d)};s(0,e.spans[0]?.x??0);for(let d of e.spans){let l=[...d.text],f=0;l.forEach((c,m)=>{f=n.advance(l.slice(0,m+1).join(""),d.style),s(a+m+1,d.x+f)}),a+=l.length}return r}function $u(e,t,n){let r=0,o=e.spans[0]?.x??0;for(let a of e.spans){let s=[...a.text];if(t<=r)return a.x;if(t>=r+s.length){o=a.x+a.w,r+=s.length;continue}let d=s.slice(0,t-r).join("");return a.x+n.advance(d,a.style)}return o}function Xm(e){return e.spans.reduce((t,n)=>t+[...n.text].length,0)}function Tu(e,t,n,r,o){let a=Math.min(n,r),s=Math.max(n,r);if(a===s)return[];let d=Er(e,t),l=[];return e.lines.forEach((f,c)=>{let m=d[c];if(!m)return;let g=Math.max(a,m.start),b=Math.min(s,m.end);if(b<=g)return;let E=Xm(f),v=$u(f,Math.min(g-m.start,E),o),w=$u(f,Math.min(b-m.start,E),o),L=Math.max(w-v,b>m.end-1&&b>g?4:0);L>0&&l.push({x:v,y:f.y,w:L,h:f.h})}),l}function Ou(e,t,n,r,o){let a=Er(e,t),d=_s(a,n)+r,l=e.lines[d],f=a[d];if(!l||!f)return r===-1?0:t.length;let c=Ss(e,t,n,o);return Math.min(f.start+Wm(l,c.x,o),f.end)}var s0=/[\p{L}\p{N}_]/u;function Lu(e,t){let n=Math.max(0,Math.min(t,e.length)),r=d=>s0.test(e[d]??""),o=n;if(!r(o)&&o>0&&r(o-1)&&(o-=1),!r(o))return{from:n,to:n};let a=o,s=o;for(;a>0&&r(a-1);)a-=1;for(;s<e.length&&r(s);)s+=1;return{from:a,to:s}}function Es(e,t,n){let r=Er(e,t),o=r[_s(r,n)];return o?{from:o.start,to:o.end}:{from:0,to:t.length}}var Qm=700;function Du(e){let t=0,n=0,r=null,o=!1,a=0,s=!1,d=0,l=0;function f(){return Un(e.content())}function c(A){return Math.max(0,Math.min(Math.round(A),f().length))}function m(){return{from:Math.min(t,n),to:Math.max(t,n)}}function g(A,N=A){let I=t!==A||n!==N;t=c(A),n=c(N),I&&b(),r=null,e.invalidate()}function b(){o=!1,a&&(clearTimeout(a),a=0)}function E(){a&&clearTimeout(a),a=setTimeout(b,Qm)}function v(A,N){e.write(A,o,N),o=!0,E()}function w(A,N){let{from:I,to:j}=m(),O=r??void 0;v(Sr(e.content(),I,j,A,O),N),t=n=I+A.length,r=null,e.invalidate()}function L(A,N){A!==N&&(v(Sr(e.content(),A,N,""),"Delete text"),t=n=Math.min(A,N),e.invalidate())}function $(A,N){let{from:I,to:j}=m();if(I!==j){L(I,j);return}let O=f();if(A===-1){if(I===0)return;let C=N?Jm(O,I):I-1;L(C,I);return}if(I>=O.length)return;let V=N?Zm(O,I):I+1;L(I,V)}function z(A,N){let I=f();return N?A===-1?Jm(I,n):Zm(I,n):c(n+A)}return{id:e.id,getSelection:()=>({anchor:t,head:n}),setSelection(A,N){g(A,N??A)},caret(){return Ss(e.layout(),f(),n,e.measure())},highlight(){let{from:A,to:N}=m();return Tu(e.layout(),f(),A,N,e.measure())},pointTo(A,N){let I=Uo(e.layout(),f(),A,e.measure());g(N?t:I,I)},selectWordAt(A){let N=Uo(e.layout(),f(),A,e.measure()),I=Lu(f(),N);g(I.from,I.to)},selectLineAt(A){let N=Uo(e.layout(),f(),A,e.measure()),I=Es(e.layout(),f(),N);g(I.from,I.to)},selectAll(){g(0,f().length)},format(A){let{from:N,to:I}=m();if(N===I){r={...Ho(e.content(),N),...A},e.invalidate();return}b(),v(Mu(e.content(),N,I,A),"Format text"),b(),e.invalidate()},activeMark(){if(r)return r;let{from:A,to:N}=m();return Au(e.content(),A,N)},composing:()=>s,handleKey(A){if(s)return!1;let N=A.metaKey||A.ctrlKey,I=A.altKey||A.ctrlKey&&!A.metaKey;switch(A.key){case"Escape":return e.close("escape"),!0;case"ArrowLeft":case"ArrowRight":{let j=A.key==="ArrowLeft"?-1:1,{from:O,to:V}=m();if(!A.shiftKey&&O!==V)g(j===-1?O:V);else{let C=N?Ym(e,f(),n,j):z(j,I);g(A.shiftKey?t:C,C)}return!0}case"ArrowUp":case"ArrowDown":{let j=A.key==="ArrowUp"?-1:1,O=N?j===-1?0:f().length:Ou(e.layout(),f(),n,j,e.measure());return g(A.shiftKey?t:O,O),!0}case"Home":case"End":{let j=Ym(e,f(),n,A.key==="Home"?-1:1);return g(A.shiftKey?t:j,j),!0}case"Backspace":return $(-1,I||N),!0;case"Delete":return $(1,I||N),!0;case"Enter":return N?e.close("done"):w(`
2790
+ `,"Type text"),!0;case"Tab":return!1;case"a":case"A":return N?(g(0,f().length),!0):!1;case"b":case"B":{if(!N)return!1;let j=this.activeMark().weight===700;return this.format({weight:j?void 0:700}),!0}case"i":case"I":return N?(this.format({italic:this.activeMark().italic===!0?void 0:!0}),!0):!1;case"u":case"U":return N?(this.format({underline:this.activeMark().underline===!0?void 0:!0}),!0):!1;default:return!1}},handleInput(A){if(!s)switch(A.inputType){case"insertText":case"insertReplacementText":case"insertFromPaste":case"insertFromDrop":case"insertFromYank":w(i0(A),"Type text");return;case"insertParagraph":case"insertLineBreak":w(`
2791
+ `,"Type text");return;case"deleteContentBackward":case"deleteWordBackward":$(-1,A.inputType==="deleteWordBackward");return;case"deleteContentForward":case"deleteWordForward":$(1,A.inputType==="deleteWordForward");return;case"deleteByCut":case"deleteByDrag":{let{from:N,to:I}=m();L(N,I);return}default:return}},handleCompositionStart(){s=!0;let{from:A,to:N}=m();d=A,l=N,b()},handleCompositionUpdate(A){v(Sr(e.content(),d,l,A),"Type text"),l=d+A.length,t=n=l,e.invalidate()},handleCompositionEnd(A){v(Sr(e.content(),d,l,A),"Type text"),s=!1,l=d+A.length,t=n=l,b(),e.invalidate()},breakBurst:b,destroy(){b()}}}function i0(e){return typeof e.data=="string"?e.data:e.dataTransfer?.getData("text/plain")??""}function Ym(e,t,n,r){let o=Es(e.layout(),t,n);return r===-1?o.from:o.to}var Cs=/[\p{L}\p{N}_]/u;function Jm(e,t){let n=t;for(;n>0&&!Cs.test(e[n-1]??"");)n-=1;for(;n>0&&Cs.test(e[n-1]??"");)n-=1;return n}function Zm(e,t){let n=t;for(;n<e.length&&!Cs.test(e[n]??"");)n+=1;for(;n<e.length&&Cs.test(e[n]??"");)n+=1;return n}function Pu(e){return Vn(e)===0}var Nu={v:"select",f:"frame",r:"rect",o:"ellipse",p:"pen",t:"text"};function Cr(e,t){let n=[];for(let r of t){if(!K(e.root,r.nodeId))continue;let o=ae(r.to);ae(r.from)!==o&&n.push({op:"set",id:r.nodeId,prop:r.prop,value:o})}return n}function ae(e){return Math.round(e*100)/100}function Mr(e,t,n,r){let o=new Set,a=[];for(let l of t)l.op==="set"&&(o.add(Ye(l.id,l.prop)),a.push({nodeId:l.id,prop:l.prop}));if(a.length===0)return[];let s=[],d=new Set;for(let l of a)for(let f of n.get(Ye(l.nodeId,l.prop))??[]){let c=Ye(f.nodeId,f.prop);if(o.has(c)||d.has(c)||!K(e.root,f.nodeId))continue;let m=r.nodes.get(f.nodeId)?.values[f.prop];m!==void 0&&(d.add(c),s.push({op:"set",id:f.nodeId,prop:f.prop,value:ae(m)}))}return s}function Iu(e,t,n,r={x:0,y:0}){let o=[],a=new Set,s=e;for(;;){let d=[],l=Re(s);for(let[f,c]of t){let m=n.get(f),g=K(s.root,c),b=l.nodes.get(c);if(!(!m||!g||!b))for(let E of wt(g)){let v=Ye(c,E);if(a.has(v))continue;let w=m[E],L=b.values[E];if(w===void 0||L===void 0)continue;let $=w+(E==="x"?r.x:E==="y"?r.y:0);ae($)!==ae(L)&&(a.add(v),d.push({op:"set",id:c,prop:E,value:ae($)}))}}if(d.length===0)return o;o.push(...d),s=Ae(s,d).document}}function Ar(e,t,n=new Set){let r=Re(e),o=Re(t),a=[];for(let[s,d]of o.nodes){if(n.has(s))continue;let l=r.nodes.get(s),f=K(t.root,s);if(!(!l||!f))for(let c of wt(f)){let m=l.values[c],g=d.values[c];m===void 0||g===void 0||ae(m)!==ae(g)&&a.push({op:"set",id:s,prop:c,value:ae(m)})}}return a}function Ms(e,t,n){let r=new Set,o=[];for(let a of t)a.op==="set"&&a.prop==="view"&&r.add(a.id);for(let a of t){if(a.op!=="set"||a.prop!=="w"&&a.prop!=="h"||r.has(a.id))continue;let s=K(e.root,a.id);if(s?.type!=="vector"||s.view!==void 0)continue;let d=n(a.id);d&&(r.add(a.id),o.push({op:"set",id:a.id,prop:"view",value:On({x:0,y:0,w:d.w,h:d.h})}))}return o.length===0?[...t]:[...o,...t]}var Ru="host:",eh="#ffffff",th={w:1920,h:1080},d0=100,As=20,l0=15,u0={ne:0,se:90,sw:180,nw:270,n:0,e:90,s:180,w:270},nh={w:240,h:28},f0={text:"Add text",frame:"Add page",rect:"Draw rectangle",ellipse:"Draw ellipse"};function c0(e,t){let n=t.x-e.x,r=t.y-e.y,o=Math.max(Math.abs(n),Math.abs(r));return{x:e.x+Math.sign(n||1)*o,y:e.y+Math.sign(r||1)*o}}var p0={KeyA:"left",KeyD:"right",KeyW:"top",KeyS:"bottom",KeyH:"hcenter",KeyV:"vcenter"},m0={KeyH:"x",KeyV:"y"},h0={left:"Align left",hcenter:"Align horizontal centres",right:"Align right",top:"Align top",vcenter:"Align vertical centres",bottom:"Align bottom"},Fu=null,x0=220,rh={lock:!0,hide:!0},g0=["x","y","w","h"],y0={front:"Bring to front",forward:"Bring forward",backward:"Send backward",back:"Send to back"},v0=11,fn=2,b0=10;function Hu(e,t){_r(e.ownerDocument),e.classList.add("vd-editor"),e.hasAttribute("tabindex")||(e.tabIndex=0);let n=t.document,r=[],o=t.tool??"select",a=null,s=null,d=null,l={ids:[],label:null},f=null,c=[],m=!1,g=new Set,b=null,E=!1,v=!1,w=null,L={...rh,...t.features},$=null,z=new Io,A=0,N=null,I={dx:0,dy:0},j=null,O=new Map,V=e.ownerDocument.createElement("div");V.style.position="absolute",V.style.inset="0",e.appendChild(V),e.style.touchAction="none";let C=ja(V,{sample:$d,document:n,...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:(i,u)=>{u===n&&me("scene",{scene:i,document:u})},onCameraChange:i=>{q?.setZoom(i.zoom),re(),me("camera",i),!(A>0)&&(ue(),me("navigate",i))}}),R=Bm(e,i=>C.documentToScreen(i)),q=t.chrome===!1?null:am(e,{onTool:Wt,onUndo:Vr,onRedo:ta,onZoomReset:()=>C.fitToContent(),onPlay:t.onPlay,playHint:t.playHint,formatKeys:t.formatKeys}),ee=t.chrome===!1?null:fs(e,{onCommand:vx,...t.formatKeys?{formatKeys:t.formatKeys}:{}}),oe=n,se=n,S=[],y=null,T=[],D=null,U=null,X=new Map,H=null,ie=null,_e=null,Me=[],Se=it,Ze=null,J=null,ne=null,te=null,F=!1,G=e.ownerDocument.createElement("textarea");G.className="vd-editor__input",G.setAttribute("aria-hidden","true"),G.tabIndex=-1,G.autocapitalize="off",G.autocomplete="off",G.spellcheck=!1,e.appendChild(G);function me(i,u){let p=O.get(i);if(p)for(let h of p)h(u)}function pe(i,u){let p=O.get(i)??new Set;return p.add(u),O.set(i,p),()=>p.delete(u)}function Te(i){A+=1;try{i()}finally{A-=1}}function ue(){N!==null&&(e.ownerDocument.defaultView?.cancelAnimationFrame(N),N=null)}function He(i){let u=C.linkAt(i),p=u===void 0?void 0:xt(u);return p?p.kind==="url"?t.onOpenLink?(t.onOpenLink(p.url),!0):!1:K(n.root,p.id)?(he([p.id]),Oe([p.id]),!0):!1:!1}function Oe(i,u={}){if(y!==null)return j={target:i,options:u},!1;let p=$h(i);if(!p)return!1;let h=e.getBoundingClientRect(),x=h.width>0&&h.height>0,k=x?{width:h.width,height:h.height-Mh(h)}:{width:p.w+96,height:p.h+96},_=u.fit==="always"?us(p,k):lu(p,k,C.getCamera());if(!_)return!1;ue(),u.by==="person"&&me("navigate",_);let M=e.ownerDocument.defaultView,P=M?.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;if(u.animate===!1||P||!x||!M?.requestAnimationFrame)return Te(()=>C.setCamera(_)),!0;let B=C.getCamera(),W=M.performance.now();I={dx:0,dy:0};let Z=ye=>{let Y=Math.min(1,Math.max(0,(ye-W)/x0)),we=Y===1?_:Sm(B,_,Em(Y),k);Te(()=>C.setCamera($t(we,I.dx,I.dy))),N=Y===1?null:M.requestAnimationFrame(Z)};return N=M.requestAnimationFrame(Z),!0}function Mh(i){let u=q?.element.getBoundingClientRect();return!u||u.height===0?0:Math.max(0,i.bottom-u.top)}function Ah(i,u){N!==null&&(I={dx:I.dx+i,dy:I.dy+u}),Te(()=>C.setCamera($t(C.getCamera(),i,u)))}function jo(){if(j===null||y!==null)return;let{target:i,options:u}=j;j=null,Oe(i,u)}function $h(i){if(i==="content"){let p=C.getScene();return ls([{x:p.x,y:p.y,w:p.width,h:p.height}])}let u=[];for(let p of du(n,i)){let h=Ie(p);h&&u.push(h)}return ls(u)}function Ot(i){return C.getResolution().nodes.get(i)}function Kt(i){let u=Ot(i);return u?{x:u.x,y:u.y,w:u.w,h:u.h}:void 0}function Ie(i){return Fn(i,n,C.getResolution())}function cn(i){let u=Ot(i);return u?{x:u.absX,y:u.absY,w:u.w,h:u.h}:void 0}function pn(i){return Ot(i)?.values.rotation??0}function Xu(){let i=Dr();if(i.length===0)return null;for(let u of i){let p=K(n.root,u);if(!p||!fd.includes(p.type))return null}return i}function Tr(i,u=new Set){let p=C.getResolution(),h=null;return ce(n.root,x=>{if(u.has(x.id)||!hn(x.id))return!1;if(x.type!=="frame")return;let k=p.nodes.get(x.id);if(!k)return!1;let _={x:k.absX,y:k.absY,w:k.w,h:k.h};if(!bt(_,i.x,i.y))return!1;h=x.id}),h}function mn(i){let u=Ot(i);return u?{x:u.absX,y:u.absY}:{x:0,y:0}}function rt(){return $?.of!==n&&($={of:n,hidden:ra(n.root),locked:oa(n.root)}),$}function hn(i){let{hidden:u,locked:p}=rt();return!u.has(i)&&!p.has(i)}function fe(){return r.filter(hn)}function Or(i){let u=C.hitTest(i,h=>!rt().locked.has(h));if(u===null)return null;let p=w===null||We(n.root,u).includes(w);return ss(u,n,p?w:null)}function Th(){return No(n,fe(),C.getResolution())}function Lr(){return fe().length<2?null:xu(Th())}function Ko(i){let u=[];for(let p of i)for(let h of Rn(p,n)){let x=Kt(h);x&&u.push({member:p,node:h,frame:x})}return u}function qo(i,u){let p=K(n.root,i);if(!p)return"literal";let h=p[u];return h===void 0?"literal":Pa(h).kind}function Oh(i){let u=K(n.root,i),p={};if(!u)return p;let h=[...g0,...To(u).map(x=>x.prop)];for(let x of h)p[x]=qo(i,x);return p}function Yu(i,u){let p="none";for(let h of i){let x=Ds(h,u);if(x==="expression")return"expression";x==="token"&&(p="token")}return p}function Ds(i,u){let p="none";for(let h of u){let x=qo(i,h);if(x==="complex")return"expression";x==="token"&&(p="token")}return p}let ot=null;function ge(i,u){if(i.length===0)return;let p=wa(n,Ms(n,i,Kt)),h=Ae(n,p);n=h.document,ot?(Rs(ot.started,ot.label,p,h.inverse),ot.started=!0):z.push({label:u,ops:p,inverse:h.inverse}),Go(p,u)}function Lh(i){ot={label:i,started:!1}}function Dh(){ot=null}function Ju(i,u){i.length!==0&&(n=Ae(n,i).document,Go(i,u))}function Go(i,u){a=null,ie=null,_e=null,C.update(n),q?.setHistory(z.canUndo,z.canRedo),re(),me("change",{document:n,ops:i,label:u}),me("problems",Ps())}function Ps(){return[...C.getScene().problems,...ld(n)]}function he(i){let u=i.filter(h=>h!==n.root.id&&K(n.root,h)),p=u.length!==r.length||u.some((h,x)=>r[x]!==h);r=[...u],ne&&(u.length!==1||u[0]!==ne.id)&&(ne=null),p&&(ee?.close(),_e=null,me("selection",r)),re()}function Ph(i,u){let p=K(n.root,i);if(!p)return[];let h=C.getCamera().zoom;if(Math.min(u.w,u.h)*h<24)return[];let x=v0/h,k=Ot(i);return To(p).flatMap(_=>{let M=k?.values[_.prop]??0,P=qo(i,_.prop)!=="literal";return _.handles(u,M,x).map(B=>({id:B.id,at:B.at,bound:P}))})}function Nh(){let i=[];for(let B of fe()){let W=Ie(B);W&&i.push(W)}let u=vt(i);if(!u)return null;let p=fe().length===1?fe()[0]:void 0,h=p===void 0?void 0:K(n.root,p),x=p===void 0||!h||be(h),k=new Set,_=Dr();for(let B of Vd){let W=Ka(B);_.some(Z=>W.some(ye=>qo(Z,ye)!=="literal"))&&k.add(B)}let M=!x&&p!==void 0?pn(p):0,P=M!==0&&p!==void 0?cn(p):void 0;return{frame:P??u,...P?{rotation:M}:{},rotatable:Xu()!==null,handles:J===null,boundHandles:k,adjusters:J!==null||x||p===void 0||P?[]:Ph(p,u)}}function Dr(){return[...new Set(fe().flatMap(i=>Rn(i,n)))]}function Ih(i){if(!i)return null;if(y?.kind==="adjust")return`r ${ae(D??y.from)}`;if(y?.kind==="rotate")return`${ae(U??0)}\xB0`;if(!y&&ie&&fe().length===1){let u=Ot(fe()[0])?.values[ie.prop]??0;return`r ${ae(u)}`}return y?.kind==="move"?`${ae(i.frame.x)}, ${ae(i.frame.y)}`:`${ae(i.frame.w)} \xD7 ${ae(i.frame.h)}`}function Rh(){let u=y!==null&&y.kind!=="space"&&y.kind!=="reorder"?null:Lr();if(!u)return{spacers:[],rings:[],lead:null};let p=y?.kind==="space"?y.spacer:null;return{spacers:yu(u).map(h=>({id:h.id,axis:h.axis,at:h.at,label:h.id===(p??_e)?String(ae(h.gap)):null})),rings:vu(u).map(h=>({id:h.id,at:h.at})),lead:y?.kind==="reorder"?Ie(y.id)??null:null}}function re(){if(!v)return;let i=ox(),u=i?null:Nh(),p=a!==null&&!r.includes(a)&&!y?Ie(a)??null:null,h={...Fm,...Rh(),hover:p,members:fe().length>1?fe().flatMap(x=>Ie(x)??[]):[],box:u,badge:Ih(u),caret:Zu(),textSelection:Qu(),draft:y?.kind==="create"?In(y.origin,y.current):null,draftEllipse:y?.kind==="create"&&o==="ellipse",marquee:y?.kind==="marquee"?In(y.origin,y.current):null,guides:y?Se.guides:[],measures:y?Se.measures:[],presence:l.ids.length===0?null:{frames:l.ids.flatMap(x=>Ie(x)??[]),label:l.label},highlight:Do(n,c).flatMap(x=>Ie(x.id)??[]),slots:Ax(),parked:r.filter(x=>!hn(x)).flatMap(x=>Ie(x)??[]),lockHint:Hh(),path:i,turn:Uh(),pageLabels:Fh()};R.render(h)}function Fh(){if(s)return[];let i=C.getResolution().nodes;return n.root.children.flatMap(u=>{if(u.type!=="frame")return[];let p=i.get(u.id);if(!p)return[];let h=Po(p),x=u.name;return[{id:u.id,frame:h,label:typeof x=="string"&&x!==""?x:u.id,state:r.includes(u.id)?"selected":a===u.id?"hover":"idle"}]})}function Bh(i){let u=R.pageLabelRect(i),p=K(n.root,i);if(!u||!p)return;let h=p.name,x=e.ownerDocument.createElement("input");x.className="vd-editor__rename",x.type="text",x.spellcheck=!1,x.value=typeof h=="string"&&h!==""?h:"",x.placeholder=i,x.setAttribute("aria-label",`Name of ${i}`),x.style.left=`${u.x-4}px`,x.style.top=`${u.y-2}px`,x.style.width=`${Math.max(120,u.w+40)}px`;let k=!1,_=M=>{if(k)return;k=!0;let P=x.value.trim();x.remove(),s=null,M&&P!==(typeof h=="string"?h:"")&&Vf(i,"name",P===""?void 0:P,"Rename"),re(),e.focus({preventScroll:!0})};x.addEventListener("keydown",M=>{M.stopPropagation(),M.key==="Enter"?(M.preventDefault(),_(!0)):M.key==="Escape"&&(M.preventDefault(),_(!1))}),x.addEventListener("pointerdown",M=>M.stopPropagation()),x.addEventListener("blur",()=>_(!0)),s=x,e.appendChild(x),re(),x.focus(),x.select()}function Hh(){if(d===null||y||!rt().locked.has(d))return null;let i=Ie(d);return i?{frame:i,label:d}:null}function Wo(i){let u=C.itemOf(i);if(u?.kind!=="text")return null;let p=u.lines[0]?.y??u.y,h={lines:u.lines.map(x=>({y:x.y-p,h:x.h,baseline:x.baseline-p,w:x.w,spans:x.spans.map(k=>({text:k.text,style:k.style,x:k.x-u.x,w:k.w})),...x.style?{style:x.style}:{}})),width:Math.max(0,...u.lines.map(x=>x.w)),height:u.height};return{item:u,layout:h,top:p}}function Ns(){return o==="text"?"text":o!=="select"?"crosshair":"arrow"}function Zu(){if(!J)return null;let i=Wo(J.id);if(!i)return null;let u=J.caret();return{x:i.item.x+u.x,y:i.top+u.y,h:u.h,...u.fill!==void 0?{fill:u.fill}:{}}}function Qu(){if(!J)return[];let i=Wo(J.id);return i?J.highlight().map(u=>({x:i.item.x+u.x,y:i.top+u.y,w:u.w,h:u.h})):[]}function Is(i){if(!J)return null;let u=Wo(J.id);if(!u)return null;let p=Pr(J.id,i);return{x:p.x-u.item.x,y:p.y-u.top}}function Pr(i,u){let p=pn(i),h=p===0?void 0:cn(i);return h?nt(u,st(h),-p):u}function Uh(){let i=J?.id??ne?.id;if(i===void 0)return null;let u=pn(i),p=u===0?void 0:cn(i);return p?{angle:u,centre:st(p)}:null}function Vh(i){let u=K(n.root,i);if(!u||u.type!=="text"||typeof u.h!="number")return[];let p=C.itemOf(i);if(p?.kind!=="text")return[];let h=ae(Math.ceil(p.height));return h>u.h?[{op:"set",id:i,prop:"h",value:h}]:[]}function zh(i,u,p,h){let x=ot?ot.started:p,k=ot?.label??h;ot&&(ot.started=!0);let _=[{op:"set",id:i,prop:"content",value:u}],M=Ae(n,_);n=M.document,C.update(n);let P=Vh(i);if(P.length===0){Rs(x,k,_,M.inverse),Go(_,k);return}let B=Ae(n,P);n=B.document,C.update(n);let W=[..._,...P];Rs(x,k,W,[...B.inverse,...M.inverse]),Go(W,k)}function Rs(i,u,p,h){let x={label:u,ops:p,inverse:h};i&&z.amend(x)||z.push(x)}function Nr(i,u){let p=K(n.root,i);if(!p||p.type!=="text"||J?.id===i)return;xn("done"),Wt("select"),he([i]),J=Du({id:i,content:()=>{let x=K(n.root,i);return x?.type==="text"?x.content:""},layout:()=>Wo(i)?.layout??{lines:[],width:0,height:0},measure:()=>C.getMeasurer(),write:(x,k,_)=>zh(i,x,k,_),invalidate:()=>{re(),ef(),me("selection",r)},close:x=>xn(x)});let h=u?Is(u):null;h?J.pointTo(h,!1):J.selectAll(),e.classList.add("vd-editor--editing"),G.value="",G.focus({preventScroll:!0}),re(),ef()}function xn(i){let u=J;if(!u)return;J=null,F=!1,u.destroy(),e.classList.remove("vd-editor--editing","vd-editor--typing"),me("selection",r);let p=K(n.root,u.id);p?.type==="text"&&Pu(p.content)&&(ge([{op:"remove",id:u.id}],"Remove empty text"),he([])),e.ownerDocument.activeElement===G&&e.focus({preventScroll:!0}),re()}function ef(){let i=Zu();if(!i)return;let u=C.documentToScreen({x:i.x,y:i.y});G.style.left=`${Math.round(u.x)}px`,G.style.top=`${Math.round(u.y)}px`}let zn=0;function tf(){e.classList.add("vd-editor--typing"),zn&&clearTimeout(zn),zn=setTimeout(()=>{zn=0,e.classList.remove("vd-editor--typing")},520)}function Fs(i){let u=Cr(oe,i);return u.length>0&&H?[...u,...Mr(oe,u,X,H)]:u}function gn(i){Bs(Fs(i))}function Bs(i,u=i){let p=x=>{let k=H?.nodes.get(x);return k?{x:0,y:0,w:k.w,h:k.h}:void 0},h=Ms(oe,i,p);T=Ms(oe,u,p),C.update(h.length>0?Ae(oe,h).document:oe),re()}function nf(){let i=vt(fe().flatMap(h=>Ie(h)??[]));if(!i)return null;let u=new Map,p=new Map;for(let h of Dr()){let x=cn(h),k=Kt(h);!x||!k||(u.set(h,x),p.set(h,{x:x.x-k.x,y:x.y-k.y}))}return u.size===0?null:{bounds:i,frames:u,offsets:p}}function rf(i,u){let p=tu(i.frames,i.bounds,u),h=[];for(let[x,k]of p){let _=i.frames.get(x),M=i.offsets.get(x);if(!_||!M)continue;let P=pn(x),B=P===0?k:Gp(_,P,i.bounds,u);h.push({nodeId:x,prop:"x",from:_.x-M.x,to:B.x-M.x},{nodeId:x,prop:"y",from:_.y-M.y,to:B.y-M.y},{nodeId:x,prop:"w",from:_.w,to:B.w},{nodeId:x,prop:"h",from:_.h,to:B.h})}return h}function jh(i,u){let p=Xu();if(!p)return!1;let h=fe().length===1&&p.length===1?p[0]:void 0,x=vt(fe().flatMap(M=>Ie(M)??[])),k=h!==void 0?cn(h):x;if(!k)return!1;let _=p.flatMap(M=>{let P=cn(M),B=Kt(M);return!P||!B?[]:[{id:M,frame:P,rotation:pn(M),offset:{x:P.x-B.x,y:P.y-B.y}}]});return _.length===0?!1:(ut(u),at({kind:"rotate",pointerId:u,origin:i,centre:st(k),targets:_}),!0)}function Kh(i,u,p){let h=nf();return h?(ut(p),at({kind:"scale",pointerId:p,origin:i,handle:u,...h}),!0):!1}function qh(i){let u=nf();if(!u)return;let p=Cr(n,rf(u,i));if(p.length===0)return;let h=i.w!==u.bounds.w||i.h!==u.bounds.h;ge([...p,...Mr(n,p,cr(n),Re(n))],h?"Resize":"Move")}function Gh(i,u,p){let h=vs(i),x=Lr();if(!h||!x)return!1;let k=Tt(x,h.axis)?.gaps[h.index],_=Ko(fe());return k===void 0||_.length===0?!1:(ut(p),at({kind:"space",pointerId:p,origin:u,axis:h.axis,spacer:i,layout:x,gap:k,parts:_}),!0)}function Wh(i,u){let p=i.axis==="x"?u.x-i.origin.x:u.y-i.origin.y,h=Math.max(0,i.gap+p);gn(Hs(i.parts,i.axis,bs(i.layout,i.axis,h)))}function Xh(i,u){let p=Lr(),h=p?Tt(p,i):void 0;if(!p||!h||h.gaps.length===0)return;let x=Cr(n,Hs(Ko(fe()),i,bs(p,i,Math.max(0,u))));x.length!==0&&ge([...x,...Mr(n,x,cr(n),Re(n))],"Spacing")}function Yh(i){let u=Lr(),p=u?Tt(u,i)?.gaps:void 0;return!p||p.length===0?null:gu(p)?p[0]??null:"mixed"}function Hs(i,u,p){return i.map(h=>{let x=u==="x"?h.frame.x:h.frame.y;return{nodeId:h.node,prop:u,from:x,to:x+(p.get(h.member)??0)}})}function Jh(i,u,p){let h=Lr();if(!h||!h.order.includes(i))return!1;let x=Ko(fe()),k=h.items.find(_=>_.id===i)?.frame;return x.length===0||!k?!1:(ut(p),at({kind:"reorder",pointerId:p,id:i,layout:h,parts:x,grab:{x:u.x-k.x,y:u.y-k.y},to:h.order.indexOf(i),swap:!1}),!0)}function Zh(i,u,p){i.to=ku(i.layout,u),i.swap=p;let h=Qh(i),x=new Map(h);x.set(i.id,{x:u.x-i.grab.x,y:u.y-i.grab.y}),Bs(Fs(of(i,x)),Fs(of(i,h)))}function Qh(i){let u=i.layout.order.indexOf(i.id);if(u===-1||i.to===u)return new Map;if(i.swap){let p=i.layout.order[i.to];return p===void 0?new Map:Eu(i.layout,i.id,p)}return Su(i.layout,_u(i.layout.order,u,i.to))}function of(i,u){let p=new Map(i.layout.items.map(x=>[x.id,x.frame])),h=[];for(let x of i.parts){let k=u.get(x.member),_=p.get(x.member);!k||!_||h.push({nodeId:x.node,prop:"x",from:x.frame.x,to:x.frame.x+(k.x-_.x)},{nodeId:x.node,prop:"y",from:x.frame.y,to:x.frame.y+(k.y-_.y)})}return h}function at(i,u=[],p=n){se=p,S=u,oe=n,y=i,T=[],X=cr(n),H=Re(n),Se=it,Me=ex(i)?ru(n,H,tx(i)):[]}function ex(i){return i.kind==="move"||i.kind==="resize"||i.kind==="scale"||i.kind==="create"}function tx(i){return i.kind==="move"||i.kind==="scale"?new Set(fe()):i.kind==="resize"?new Set([i.id]):new Set}function Ir(i){return i.metaKey||i.ctrlKey?0:nu/C.getCamera().zoom}function qt(i){let u=[...S,...T];y=null,T=[],S=[],D=null,U=null,Se=it,n=se,C.update(n),ge(u,i),re()}function nx(){let i=T.length>0?Ae(oe,T).document:oe,u=new Set(fe().flatMap(x=>af(x,i))),p=[];for(let x of fe()){let k=K(i.root,x),_=ht(i.root,x);if(!k||!_)continue;let M=Ie(x);if(!M)continue;let P={x:M.x+M.w/2,y:M.y+M.h/2},B=Tr(P,u)??n.root.id;if(B===_.id)continue;let W=K(i.root,B);if(!W||!be(W))continue;p.push({op:"move",id:x,parent:B,index:de(W).length});let Z={x:mn(_.id).x-mn(B).x,y:mn(_.id).y-mn(B).y};if(!(Z.x===0&&Z.y===0))for(let ye of Rn(x,i)){let Y=Kt(ye);Y&&(p.push({op:"set",id:ye,prop:"x",value:ae(Y.x+Z.x)}),p.push({op:"set",id:ye,prop:"y",value:ae(Y.y+Z.y)}))}}if(p.length===0)return[];let h=Ae(i,p).document;return[...p,...Ar(i,h,u)]}function af(i,u){let p=K(u.root,i);if(!p)return[];let h=[];return ce(p,x=>{h.push(x.id)}),h}function Us(){if(!y)return;y=null,T=[],D=null,U=null,Se=it;let i=S.length>0;n=se,S=[],i&&he(r.filter(u=>K(n.root,u))),C.update(n),re()}let rx=5,Xo=8;function sf(i,u=n,p=C.getResolution()){let h=K(u.root,i),x=p.nodes.get(i);if(h?.type!=="vector"||!x)return;let k={x:x.absX,y:x.absY,w:Math.max(0,x.w),h:Math.max(0,x.h)};return{node:h,view:oo(h.view,k.w,k.h),box:k}}function Rr(i,u=n,p=C.getResolution()){let h=sf(i,u,p);if(h)return It(ro(h.node.d).contours,ao(h.view,h.box))}function Gt(i,u,p,h=n,x=C.getResolution()){let k=sf(i,h,x);if(!k)return[];let{node:_,view:M,box:P}=k,B=It(u,vi(M,P)),W=[],Z=(mt,Gn,Ux)=>{Gn!==Ux&&W.push({op:"set",id:i,prop:mt,value:Gn})};Z("d",Nt(B),_.d);let ye=[_.x,_.y,_.w,_.h].every(mt=>typeof mt=="number"),Y=Tn(B),we=Tn(u);if(!p||!ye||!Y||!we)return W;let Ue=P.x-_.x,Ve=P.y-_.y;return Z("view",On(Y),_.view),Z("x",ae(we.x-Ue),_.x),Z("y",ae(we.y-Ve),_.y),Z("w",ae(we.w),_.w),Z("h",ae(we.h),_.h),W}function yn(i){return K(n.root,i)?.type!=="vector"||!hn(i)?!1:(J&&xn("done"),te&&Yo(),he([i]),ne={id:i,picked:new Set},o!=="select"&&Wt("select"),lt(null),re(),!0)}function Fr(){ne&&(ne=null,re())}function ox(){if(te){let p=te.contours[te.contour],h=p?.anchors??[],x=h[h.length-1],k=h[0],_=te.hover,M=_!==null&&k!==void 0&&h.length>=2&&!p?.closed&&Br(k,_)<=Xo;return{contours:te.contours,anchors:h.map((P,B)=>({key:Fe(te?.contour??0,B),at:P,selected:B===h.length-1})),handles:x?Yd(te.contours,new Set([Fe(te.contour,h.length-1)])):[],pending:x&&_&&!te.dragging&&!p?.closed?{from:x,...x.out?{c1:x.out}:{},to:_}:null,closeAt:M?k:null}}if(!ne)return null;let i=Rr(ne.id);if(!i)return null;let u=new Set(Wd(i,ne.picked));return{contours:i,anchors:i.flatMap((p,h)=>p.anchors.map((x,k)=>({key:Fe(h,k),at:x,selected:u.has(Fe(h,k))}))),handles:Yd(i,u)}}function Br(i,u){return Math.hypot(i.x-u.x,i.y-u.y)*C.getCamera().zoom}function ax(i,u,p,h){if(!ne)return!1;let x=ne.id,k=Rr(x);if(!k)return ne=null,!1;i.preventDefault(),ut(i.pointerId);let _=R.hitPath(u);if(_?.kind==="handle"){let P=Wp(_.key),B=P?k[P.contour]?.anchors[P.index]:void 0;if(P&&B)return at({kind:"pathHandle",pointerId:i.pointerId,id:x,start:k,contour:P.contour,index:P.index,side:P.side,smooth:Ga(B),last:k}),!0}if(_?.kind==="anchor")return i.altKey?(ne.picked=new Set([_.key]),ge(Gt(x,Xp(k,_.key),!1),"Convert point"),!0):(i.shiftKey?ne.picked.has(_.key)?ne.picked.delete(_.key):ne.picked.add(_.key):ne.picked.has(_.key)||(ne.picked=new Set([_.key])),at({kind:"points",pointerId:i.pointerId,id:x,origin:p,start:k,keys:new Set(ne.picked),lead:_.key,moved:!1,last:k}),re(),!0);let M=ki(k,p);if(M&&M.distance*C.getCamera().zoom<=rx){if(h>=2){let Z=_i(k,M.contour,M.segment,M.t);return ne.picked=new Set([Fe(M.contour,M.segment+1)]),ge(Gt(x,Z,!1),"Add point"),!0}let P=k[M.contour],B=P.anchors[M.segment],W=P.anchors[(M.segment+1)%P.anchors.length];return at({kind:"segment",pointerId:i.pointerId,id:x,origin:p,start:k,contour:M.contour,segment:M.segment,t:M.t,straight:!B?.out&&!W?.in,last:k}),!0}return at({kind:"pointMarquee",pointerId:i.pointerId,origin:p,current:p,additive:i.shiftKey}),!0}function sx(i,u,p,h){let x=Gd(i.start,i.lead);if(!x||h===0)return{dx:u,dy:p};let k=x.x+u,_=x.y+p,M=h,P=h,B=u,W=p;return i.start.forEach((Z,ye)=>Z.anchors.forEach((Y,we)=>{i.keys.has(Fe(ye,we))||(Math.abs(Y.x-k)<M&&(M=Math.abs(Y.x-k),B=Y.x-x.x),Math.abs(Y.y-_)<P&&(P=Math.abs(Y.y-_),W=Y.y-x.y))})),{dx:B,dy:W}}function ix(i,u){if(!y)return!1;let p=(h,x)=>{H&&Bs(Gt(x,h,!1,oe,H))};switch(y.kind){case"points":{let h=u;i.shiftKey&&(h=$o(y.origin,u));let x={dx:h.x-y.origin.x,dy:h.y-y.origin.y};if(!y.moved&&Math.hypot(x.dx,x.dy)*C.getCamera().zoom<fn)return!0;y.moved=!0;let{dx:k,dy:_}=i.shiftKey?x:sx(y,x.dx,x.dy,Ir(i));return y.last=Ya(y.start,y.keys,k,_),p(y.last,y.id),!0}case"pathHandle":{let h=y.start[y.contour]?.anchors[y.index],x=i.shiftKey&&h?$o(h,u):u;return y.last=Wa(y.start,y.contour,y.index,y.side,x,{smooth:y.smooth,breakSmooth:i.altKey}),p(y.last,y.id),!0}case"segment":return y.last=Jp(y.start,y.contour,y.segment,y.t,u.x-y.origin.x,u.y-y.origin.y,y.straight),p(y.last,y.id),!0;case"pointMarquee":return y.current=u,re(),!0;default:return!1}}function dx(i){if(!y)return!1;switch(y.kind){case"points":case"pathHandle":case"segment":{let u=y.kind!=="points"||y.moved,p=y.kind==="points"?y.keys.size===1?"Move point":"Move points":y.kind==="pathHandle"?"Adjust curve":"Reshape";return T=u&&H?Gt(y.id,y.last,!0,oe,H):[],qt(p),!0}case"pointMarquee":{let u=In(y.origin,y.current),p=y.additive;if(y=null,Se=it,!ne)return!0;let h=C.getCamera().zoom;if(u.w*h<fn&&u.h*h<fn){if(C.hitTest(i)===ne.id)ne.picked=new Set;else{Fr();let _=Or(i);he(_===null?[]:[_])}return re(),!0}let x=Rr(ne.id)??[],k=Xd(x).filter(_=>{let M=Gd(x,_);return M!==void 0&&bt(u,M.x,M.y)});return ne.picked=new Set(p?[...ne.picked,...k]:k),re(),!0}default:return!1}}function lx(i){if(!ne)return!1;let u=ne.id,p=i.metaKey||i.ctrlKey;if(i.key==="Escape"||i.key==="Enter"&&!p)return i.preventDefault(),y?Us():Fr(),!0;let h=Rr(u);if(!h)return!1;let x=new Set(Wd(h,ne.picked));if(i.key==="Delete"||i.key==="Backspace"){if(i.preventDefault(),x.size===0)return!0;let P=Yp(h,x);return ne.picked=new Set,P.length===0?(Fr(),qn(),!0):(ge(Gt(u,P,!0),x.size===1?"Delete point":"Delete points"),!0)}let k=i.shiftKey?10:1,M={ArrowLeft:[-k,0],ArrowRight:[k,0],ArrowUp:[0,-k],ArrowDown:[0,k]}[i.key];return M&&!p?(i.preventDefault(),x.size>0&&ge(Gt(u,Ya(h,x,M[0],M[1]),!0),"Nudge points"),!0):p&&i.key.toLowerCase()==="a"?(i.preventDefault(),ne.picked=new Set(Xd(h)),re(),!0):p&&!i.shiftKey&&i.code==="KeyJ"?(i.preventDefault(),ge(Gt(u,Zp(h,x),!0),"Close path"),!0):!1}function ux(i,u){if(i.preventDefault(),ut(i.pointerId),!te){te=fx(u)??{contours:[{closed:!1,anchors:[{x:u.x,y:u.y}]}],contour:0,target:null,hover:null,dragging:null};let _=te.contours[te.contour];te.dragging={pointerId:i.pointerId,index:_.anchors.length-1,origin:u},re();return}let p=te.contours[te.contour],h=p.anchors[0],x=p.anchors[p.anchors.length-1];if(h&&p.anchors.length>=2&&Br(h,u)<=Xo){te.contours[te.contour]={...p,closed:!0},te.dragging={pointerId:i.pointerId,index:0,origin:h},re();return}let k=i.shiftKey&&x?$o(x,u):u;te.contours[te.contour]={...p,anchors:[...p.anchors,{x:k.x,y:k.y}]},te.dragging={pointerId:i.pointerId,index:p.anchors.length,origin:k},re()}function fx(i){let u=r.length===1?r[0]:null;if(u===null||!hn(u))return null;let p=Rr(u);if(!p)return null;for(let h=0;h<p.length;h+=1){let x=p[h];if(x.closed||x.anchors.length<1)continue;let k=x.anchors[0],_=x.anchors[x.anchors.length-1],M=Br(_,i)<=Xo,P=!M&&Br(k,i)<=Xo;if(!M&&!P)continue;let B=[...p];return P&&(B[h]=Qp(x)),{contours:B,contour:h,target:u,hover:null,dragging:null}}return null}function cx(i,u){if(!te)return;let p=te.dragging;if(!p||p.pointerId!==i.pointerId){let P=te.contours[te.contour],B=P?.anchors[P.anchors.length-1];te.hover=i.shiftKey&&B?$o(B,u):u,re();return}if(Br(p.origin,u)<fn)return;let h=te.contours[te.contour],x=h.anchors[p.index];if(!x)return;let k={x:2*x.x-u.x,y:2*x.y-u.y},_=i.altKey?x.in:k,M=[...h.anchors];M[p.index]={x:x.x,y:x.y,..._?{in:_}:{},out:u},te.contours[te.contour]={...h,anchors:M},re()}function px(i){!te?.dragging||te.dragging.pointerId!==i.pointerId||(Qs(i.pointerId),te.dragging=null,te.contours[te.contour]?.closed?Yo():re())}function Yo(){if(!te)return;let i=te;te=null;let u=i.contours[i.contour];if(!u||u.anchors.length<2){re();return}if(i.target!==null){ge(Gt(i.target,i.contours,!0),"Extend path"),Wt("select"),yn(i.target);return}let p=Tn(i.contours),h=u.anchors[0];if(!p)return;let x=Tr(h)??w??n.root.id,k=K(n.root,x)??n.root,_=mn(x),M=It(i.contours,B=>({x:B.x-p.x,y:B.y-p.y})),P=en(n.root,"path");ge([{op:"insert",parent:x,index:de(k).length,node:fa({id:P,x:ae(p.x-_.x),y:ae(p.y-_.y),w:ae(p.w),h:ae(p.h),view:On({x:0,y:0,w:p.w,h:p.h}),d:Nt(M),fill:"none",stroke:t.defaultStroke??"#1f2937",strokeWidth:2,cap:"round",join:"round"})}],"Draw path"),Wt("select"),yn(P)}function Vs(i=fe()){let u=[],p=[];for(let h of i){let x=K(n.root,h),k=ht(n.root,h),_=Ot(h);if(!x||!k||!_||x.type!=="rect"&&x.type!=="ellipse")continue;let M=Math.max(0,_.w),P=Math.max(0,_.h),B=x.type==="rect"?Si(M,P,_.values.radius??0):Ei(M,P),W=fa({id:h,...x.name===void 0?{}:{name:x.name},x:x.x,y:x.y,w:x.w,h:x.h,view:On({x:0,y:0,w:M,h:P}),d:Nt(B),...x.fill===void 0?{}:{fill:x.fill},...x.stroke===void 0?{}:{stroke:x.stroke},...x.strokeWidth===void 0?{}:{strokeWidth:x.strokeWidth},...x.opacity===void 0?{}:{opacity:x.opacity},...x.hidden?{hidden:!0}:{},...x.locked?{locked:!0}:{}}),Z=k.children.findIndex(ye=>ye.id===h);u.push({op:"remove",id:h},{op:"insert",parent:k.id,index:Z,node:W}),p.push(h)}p.length!==0&&(ge(u,p.length===1?"Convert to vector":`Convert ${p.length} to vector`),he(p),p.length===1&&yn(p[0]))}function df(){return fe().filter(i=>{let u=K(n.root,i)?.type;return u==="rect"||u==="ellipse"}).length}let mx=450,lf=4,Hr={x:0,y:0,at:0,count:0};function hx(i){let u=Date.now(),h=Math.abs(i.x-Hr.x)<=lf&&Math.abs(i.y-Hr.y)<=lf&&u-Hr.at<=mx?Hr.count+1:1;return Hr={x:i.x,y:i.y,at:u,count:h},h}let uf=i=>{if(E=i.pointerType==="touch",E){g.add(i.pointerId),b=g.size===1?{pointerId:i.pointerId,screen:C.pointerPoint(i)}:null;return}if(i.button!==0||m)return;let u=C.pointerPoint(i),p=C.screenToDocument(u);Ze=p;let h=hx(u);if(J){let P=Is(p),B=C.itemOf(J.id),W=Pr(J.id,p);if(P&&B&&bt(B,W.x,W.y)){i.preventDefault(),ut(i.pointerId),F=!0,h>=3?J.selectLineAt(P):h===2?J.selectWordAt(P):J.pointTo(P,i.shiftKey),G.focus({preventScroll:!0}),re();return}xn("blur")}if(e.focus({preventScroll:!0}),o==="select"&&(i.metaKey||i.ctrlKey)&&He(p)){i.preventDefault();return}if(o==="pen"){ux(i,p);return}if(ne&&o==="select"&&ax(i,u,Pr(ne.id,p),h))return;if(o!=="select"){i.preventDefault(),ut(i.pointerId),at({kind:"create",pointerId:i.pointerId,origin:p,current:p}),re();return}let x=fe().length===1?fe()[0]:null;if(x!==null){let P=K(n.root,x),B=R.hitAdjuster(u),W=P&&B?ts(P,B.id):void 0,Z=W?Ie(x):void 0;if(W&&Z&&B){i.preventDefault(),ut(i.pointerId),at({kind:"adjust",pointerId:i.pointerId,id:x,adjuster:W,handleId:B.id,frame:Z,from:Ot(x)?.values[W.prop]??0});return}let ye=P&&!be(P)?R.hitHandle(u):null,Y=ye?Kt(x):void 0,we=Y?cn(x):void 0;if(ye&&Y&&we){i.preventDefault(),ut(i.pointerId),at({kind:"resize",pointerId:i.pointerId,origin:p,id:x,handle:ye.handle,frame:Y,offset:{x:we.x-Y.x,y:we.y-Y.y},rotation:pn(x)});return}}let k=fe().length>0?R.hitHandle(u):null;if(k&&Kh(p,k.handle,i.pointerId)){i.preventDefault();return}let _=R.hitPageLabel(u);if(_!==null){if(i.preventDefault(),w=null,i.shiftKey){he(r.includes(_)?r.filter(P=>P!==_):[...r,_]);return}if(r.includes(_)||he([_]),h===2){Bh(_);return}ff(p,i.pointerId,i.altKey);return}if(fe().length>0&&R.hitRotate(u)!==null&&jh(p,i.pointerId)){i.preventDefault();return}if(fe().length>1){let P=R.hitRing(u);if(P!==null&&Jh(P,p,i.pointerId)){i.preventDefault();return}let B=R.hitSpacer(u);if(B!==null&&Gh(B,p,i.pointerId)){i.preventDefault();return}}let M=Or(p);if(M===null){i.preventDefault(),ut(i.pointerId),w=null,i.shiftKey||he([]),at({kind:"marquee",pointerId:i.pointerId,origin:p,current:p});return}w!==null&&!We(n.root,M).includes(w)&&(w=null),i.shiftKey?he(r.includes(M)?r.filter(P=>P!==M):[...r,M]):r.includes(M)||he([M]),ff(p,i.pointerId,i.altKey)&&i.preventDefault()};function xx(i){J&&xn("blur");let u=Or(C.screenToDocument(i));u!==null&&w!==null&&!We(n.root,u).includes(w)&&(w=null),u===null&&(w=null),he(u===null?[]:[u])}function ff(i,u,p){let h=n,x=[];if(p){let _=Df({x:0,y:0});_&&(x=_.ops,n=Ae(n,x).document,C.update(n),he(_.ids))}let k=new Map;for(let _ of fe())for(let M of Rn(_,n)){let P=Kt(M);P&&k.set(M,P)}return k.size===0?(n=h,C.update(n),!1):(ut(u),at({kind:"move",pointerId:u,origin:i,frames:k,bounds:vt(fe().flatMap(_=>Ie(_)??[]))},x,h),!0)}let cf=i=>{let u=C.pointerPoint(i);if(i.pointerType==="touch"){b?.pointerId===i.pointerId&&Math.hypot(b.screen.x-u.x,b.screen.y-u.y)>b0&&(b=null);return}if(Ze=C.screenToDocument(u),F&&J){let h=Is(Ze);h&&J.pointTo(h,!0);return}if(te&&o==="pen"){cx(i,Ze);return}if(!y){bx(u);return}if(y.pointerId!==i.pointerId)return;let p=Ze;if(!ix(i,ne?Pr(ne.id,p):p))switch(y.kind){case"move":{let h=p.x-y.origin.x,x=p.y-y.origin.y;if(y.bounds){let _={...y.bounds,x:y.bounds.x+h,y:y.bounds.y+x};Se=ou(_,Me,Ir(i)),h+=Se.dx,x+=Se.dy}let k=[];for(let[_,M]of y.frames)k.push({nodeId:_,prop:"x",from:M.x,to:M.x+h}),k.push({nodeId:_,prop:"y",from:M.y,to:M.y+x});gn(k);return}case"resize":{let{id:h,handle:x,frame:k,origin:_,offset:M,rotation:P}=y,B=p.x-_.x,W=p.y-_.y;if(P!==0){Se=it;let Y=jp(k,x,B,W,P);gn(qa(k,Y).map(we=>({nodeId:h,prop:we,from:k[we],to:Y[we]})));return}let Z=Ut(k,x,B,W);Se=ds({...Z,x:Z.x+M.x,y:Z.y+M.y},x,Me,Ir(i)),B+=Se.dx,W+=Se.dy;let ye=Ut(k,x,B,W);gn(qa(k,ye).map(Y=>({nodeId:h,prop:Y,from:k[Y],to:ye[Y]})));return}case"scale":{let{handle:h,bounds:x,origin:k,frames:_,offsets:M}=y,P=p.x-k.x,B=p.y-k.y,W=Ut(x,h,P,B);Se=ds(W,h,Me,Ir(i)),P+=Se.dx,B+=Se.dy,gn(rf({bounds:x,frames:_,offsets:M},Ut(x,h,P,B)));return}case"space":Wh(y,p);return;case"reorder":Zh(y,p,i.metaKey||i.ctrlKey);return;case"rotate":{let{centre:h,origin:x,targets:k}=y,_=k[0],M=Kp(h,x,p,_?.rotation??0,i.shiftKey?l0:void 0);U=xo((_?.rotation??0)+M);let P=[],B=k.length===1;for(let W of qp(k,h,M)){let Z=k.find(ye=>ye.id===W.id);Z&&(P.push({nodeId:W.id,prop:"rotation",from:Z.rotation,to:W.rotation}),!B&&P.push({nodeId:W.id,prop:"x",from:Z.frame.x-Z.offset.x,to:ae(W.frame.x-Z.offset.x)},{nodeId:W.id,prop:"y",from:Z.frame.y-Z.offset.y,to:ae(W.frame.y-Z.offset.y)}))}gn(P);return}case"adjust":{let h=y.adjuster.valueAt(y.frame,y.handleId,p);D=h,gn([{nodeId:y.id,prop:y.adjuster.prop,from:y.from,to:h}]);return}case"create":{Se=au(p,Me,Ir(i));let h={x:p.x+Se.dx,y:p.y+Se.dy};y.current=i.shiftKey&&o!=="text"?c0(y.origin,h):h,re();return}case"marquee":{y.current=p,re();return}}},Jo=i=>{if(i.pointerType==="touch"){if(g.delete(i.pointerId),b?.pointerId!==i.pointerId)return;b=null,i.type==="pointerup"&&xx(C.pointerPoint(i));return}if(F){F=!1,Qs(i.pointerId),G.focus({preventScroll:!0});return}if(te){px(i);return}if(!y||y.pointerId!==i.pointerId)return;Qs(i.pointerId);let u=C.screenToDocument(C.pointerPoint(i));if(!dx(ne?Pr(ne.id,u):u))switch(y.kind){case"create":{let p=In(y.origin,y.current),h=o==="text"?"text":o==="frame"?"frame":o==="ellipse"?"ellipse":"rect";y=null,Se=it,re();let x=p.w<fn||p.h<fn;if(x&&h!=="text")return;let k=x?{x:p.x,y:p.y,w:nh.w,h:nh.h}:p,_=Tr({x:k.x,y:k.y})??w??n.root.id,M=K(n.root,_)??n.root,P=mn(_),B={x:Math.round(k.x-P.x),y:Math.round(k.y-P.y),w:Math.round(k.w),h:Math.round(k.h)},W=en(n.root,h);ge([{op:"insert",parent:_,index:de(M).length,node:h==="text"?di({...B,id:W,content:""}):h==="frame"?ua({...B,id:W,background:eh,children:[]}):h==="ellipse"?oi({...B,id:W,fill:t.defaultFill??"#3b82f6"}):ii({...B,id:W,fill:t.defaultFill??"#3b82f6"})}],f0[h]),he([W]),Wt("select"),h==="text"&&Nr(W);return}case"marquee":{let p=In(y.origin,y.current),h=i.shiftKey;if(y=null,Se=it,p.w>=fn||p.h>=fn){let x=Hx(p);he(h?[...new Set([...r,...x])]:x)}re();return}case"move":{let p=nx();p.length>0&&(T=[...T,...p]),qt(S.length>0?"Duplicate":"Move");return}case"resize":qt("Resize");return;case"scale":qt(r.length===1?"Resize group":`Resize ${r.length} elements`);return;case"space":qt("Spacing");return;case"reorder":qt(y.swap?"Swap":"Reorder");return;case"adjust":qt("Corner radius");return;case"rotate":qt("Rotate");return}},pf=i=>{if($s(i.target))return;if(J){if(!((i.metaKey||i.ctrlKey)&&i.key.toLowerCase()==="z"))return;i.preventDefault(),J.breakBurst(),i.shiftKey?ta():Vr();return}if(te&&(i.key==="Enter"||i.key==="Escape")){i.preventDefault(),Yo();return}if(lx(i))return;if((i.metaKey||i.ctrlKey)&&i.shiftKey&&i.code==="KeyO"){if(df()===0)return;i.preventDefault(),Vs();return}if(i.key==="Enter"&&!oh(i)&&r.length===1){let h=r[0];if(K(n.root,h)?.type==="vector"&&yn(h)){i.preventDefault();return}}if(i.key==="Enter"&&!oh(i)&&r.length===1){let h=r[0];if(K(n.root,h)?.type==="text"){i.preventDefault(),Nr(h);return}}if(i.code==="Space"&&!m){m=!0,Xe(Be("grab"));return}let u=i.metaKey||i.ctrlKey;if(u&&i.key.toLowerCase()==="z"){i.preventDefault(),i.shiftKey?ta():Vr();return}if(u&&i.shiftKey&&!i.altKey&&i.code==="KeyL"){if(!L.lock||r.length===0)return;i.preventDefault(),Kn(r,"locked");return}if(u&&i.shiftKey&&!i.altKey&&i.code==="KeyH"){if(!L.hide||r.length===0)return;i.preventDefault(),Kn(r,"hidden");return}if(u&&i.key.toLowerCase()==="g"){i.preventDefault(),i.shiftKey?Xs():Ws();return}if(u&&i.key.toLowerCase()==="a"){i.preventDefault(),Js();return}if(u&&!i.altKey&&i.key.toLowerCase()==="d"){i.preventDefault(),qs();return}if(i.altKey){let h=p0[i.code];if(h&&!u){i.preventDefault(),$f(h);return}let x=m0[i.code];if(x&&i.ctrlKey){i.preventDefault(),Of(x);return}}if(i.key==="]"||i.key==="["){if(r.length===0)return;i.preventDefault();let h=i.key==="]";Ys(u?h?"front":"back":h?"forward":"backward");return}if(i.key==="Escape"){y?Us():w!==null?Hf():he([]);return}if(i.key==="Delete"||i.key==="Backspace"){if(r.length===0)return;i.preventDefault(),qn();return}let p=u||i.altKey?void 0:Nu[i.key.toLowerCase()];p&&Wt(p)};function mf(){if(!J)return null;let i=K(n.root,J.id);if(i?.type!=="text")return null;let{anchor:u,head:p}=J.getSelection();return u===p?null:Un(Cu(i.content,u,p))}let hf=i=>{if($s(i.target))return;let u=mf()??Ur();u!==null&&(i.preventDefault(),i.clipboardData?.setData("text/plain",u))},xf=i=>{if($s(i.target))return;let u=mf();if(u!==null&&J){i.preventDefault(),i.clipboardData?.setData("text/plain",u);let{anchor:h,head:x}=J.getSelection();J.breakBurst(),J.setSelection(h,x),J.handleInput({inputType:"deleteByCut",data:null});return}let p=Ur();p!==null&&(i.preventDefault(),i.clipboardData?.setData("text/plain",p),qn())},gf=i=>{if($s(i.target))return;i.preventDefault();let u=Jd(i.clipboardData);if(u&&!J){let h=$x();h?Ks(h,u):Nf(u,Ze??void 0);return}let p=i.clipboardData?.getData("text/plain")||void 0;if(J&&p!==void 0){J.handleInput({inputType:"insertFromPaste",data:p});return}js(p)},yf=i=>{i.code==="Space"&&(m=!1,Xe(Be(Ns())))},vf=i=>{if(!ee)return;i.preventDefault(),y&&Us();let u=C.pointerPoint(i),p=C.screenToDocument(u),h=Or(p),x=gx(p),k=C.hitTest(p),_=k!==null&&r.some(P=>We(n.root,k).includes(P));h===null?_||he([]):r.includes(h)||he([h]);let M=(t.menuExtras?.(r)??[]).map(P=>"separator"in P?P:{...P,id:`${Ru}${P.id}`});ee.open(u,uu(yx(x),M))};function gx(i){let{locked:u}=rt(),p=[];for(let h of[...C.getScene().items].reverse()){if(!u.has(h.id)||!C.hitTest(i,k=>k===h.id))continue;let x=zr(n.root,h.id,"locked");x!==void 0&&!p.includes(x)&&p.push(x)}return p}function yx(i=[]){let u=r.length===1?K(n.root,r[0]):void 0,p=[];if(u){let h=u;for(let x of wt(u)){let k=h[x];k===void 0||!ke(k)||Pa(k).kind!=="literal"&&p.push({prop:x,source:`=${k.expr}`})}}return{count:r.length,hasGroup:r.some(h=>{let x=K(n.root,h);return x!==void 0&&De(x)}),canPaste:Fu!==null,isText:r.length===1&&K(n.root,r[0])?.type==="text",isVector:fe().length===1&&K(n.root,fe()[0])?.type==="vector",convertible:df(),bound:p,lock:L.lock?r.every(h=>rt().locked.has(h))?"unlock":"lock":null,hide:L.hide?r.every(h=>rt().hidden.has(h))?"show":"hide":null,locksHere:i,anyLocked:Zs("locked").length>0,hiddenCount:Zs("hidden").length}}function vx(i){if(e.focus({preventScroll:!0}),i.startsWith(Ru)){t.onMenuCommand?.(i.slice(Ru.length),[...r]);return}if(i.startsWith("unlock:")){jn([i.slice(7)],"locked",!1);return}if(i.startsWith("detach:")){let u=i.slice(7),p=r[0];p!==void 0&&zf(p,u);return}switch(i){case"copy":Ur();return;case"cut":Pf();return;case"editText":{let u=r[0];u!==void 0&&Nr(u);return}case"editPoints":{let u=r[0];u!==void 0&&yn(u);return}case"toVector":return Vs();case"duplicate":return qs();case"paste":return js();case"group":return Ws();case"ungroup":return Xs();case"front":case"forward":case"backward":case"back":return Ys(i);case"delete":return qn();case"selectAll":return Js();case"toggleLock":return Kn(r,"locked");case"toggleHidden":return Kn(r,"hidden");case"unlockAll":return ea("locked");case"showAll":return ea("hidden");case"fit":return C.fitToContent();case"zoom100":return C.setCamera({...C.getCamera(),zoom:1})}}let bf=i=>{if(E||o!=="select"||m||ne)return;let u=C.screenToDocument(C.pointerPoint(i)),p=C.hitTest(u,M=>!rt().locked.has(M));if(p===null)return;let h=Qo().find(M=>M.id===p);if(h){i.preventDefault(),Tx(h);return}let x=K(n.root,p);if(x?.type==="text"){i.preventDefault(),Nr(p,u);return}if(x?.type==="vector"){i.preventDefault(),yn(p);return}let k=We(n.root,p),_=w===null?1:k.indexOf(w)+1;for(let M=Math.max(_,1);M<k.length;M+=1){let P=k[M];if(P===void 0)break;let B=K(n.root,P);if(!(!B||!De(B))){i.preventDefault(),Bf(P),he([k[M+1]??P]);return}}},wf=i=>Array.from(i.dataTransfer?.types??[]).includes("Files"),kf=()=>t.importImage!==void 0||t.importAudio!==void 0,_f=i=>{if(!wf(i)||!kf())return;i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect="copy");let u=C.screenToDocument(C.pointerPoint(i)),p=Rf(u)?.id??null;p!==f&&(f=p,re())},Sf=i=>{i.relatedTarget instanceof Node&&e.contains(i.relatedTarget)||f!==null&&(f=null,re())},Ef=i=>{if(!wf(i)||!kf())return;i.preventDefault();let u=C.screenToDocument(C.pointerPoint(i)),p=Rf(u);f=null,re();let h=Array.from(i.dataTransfer?.files??[]),x=h.find(tm);if(x&&t.importAudio){let _=Tr(u),M=_===null?void 0:ft(n).get(_),P=Za(n),B=M!==void 0&&P.includes(M)?M:Qa(n,r,null)??M??null;B!==null&&If(x,B);return}if(!t.importImage)return;let k=h.find(_=>_.type.startsWith("image/"));k&&(p?Ks(p,k):Nf(k,u))},Cf=()=>{Ze=null,d=null,!y&&(a===null&&ie===null&&_e===null||(a=null,ie=null,_e=null,re()))};function Mf(){let i=fe().length===1?fe()[0]:void 0,u=i===void 0?void 0:K(n.root,i);return i!==void 0&&u&&!be(u)?pn(i):0}function bx(i){if(m){Xe(Be("grab"));return}if(ne){lt(null),Xe(Be("arrow"));return}if(o!=="select"){lt(null),zs(null),Zo(null),Xe(Be(o==="text"?"text":"crosshair"));return}let u=fe().length===1?fe()[0]:null;if(u!==null){let k=R.hitAdjuster(i);if(k){let _=K(n.root,u),M=_?ts(_,k.id):void 0;lt(null),zs(M?{id:k.id,prop:M.prop}:null),Xe(Be("radius",{badge:M?Ds(u,[M.prop]):"none"}));return}zs(null)}if(fe().length>0){let k=R.hitHandle(i);if(k){lt(null);let P=Ka(k.handle);Xe(Be("resize",{angle:zd(k.handle)+Mf(),badge:Yu(Dr(),P)}));return}let _=R.hitPageLabel(i);if(_!==null){lt(_),Xe(Be("arrow"));return}let M=R.hitRotate(i);if(M!==null){lt(null),Xe(Be("rotate",{angle:u0[M]+Mf()}));return}}let p=R.hitPageLabel(i);if(p!==null){d=null,lt(p),Xe(Be("arrow"));return}if(fe().length>1){if(R.hitRing(i)!==null){lt(null),Zo(null),Xe(Be("grab"));return}let _=R.hitSpacer(i),M=_===null?null:vs(_);if(_!==null&&M){lt(null),Zo(_),Xe(Be("resize",{angle:M.axis==="x"?0:90,badge:Yu(Dr(),[M.axis])}));return}Zo(null)}let h=C.screenToDocument(i),x=Or(h);d=wx(h,x),lt(x),re(),Xe(Be("arrow",{badge:x===null?"none":Ds(x,["x","y"])}))}function wx(i,u){let p=C.hitTest(i);if(p===null||!rt().locked.has(p))return null;let h=zr(n.root,p,"locked");return h===void 0?null:u===null||We(n.root,h).includes(u)?h:null}function lt(i){a!==i&&(a=i,re())}function zs(i){ie?.id!==i?.id&&(ie=i,re())}function Zo(i){_e!==i&&(_e=i,re())}function Xe(i){e.style.cursor!==i&&(e.style.cursor=i)}function Wt(i){o!==i&&(o=i,te&&i!=="pen"&&Yo(),i!=="select"&&Fr(),q?.setTool(o),i!=="select"&&lt(null),Xe(Be(Ns())),me("tool",o))}function kx(i){if(i.length===0)return null;if(i.length>1)return vt(i.map(h=>h.frame))??null;let u=i[0],p=ht(n.root,u.id);return p?Fn(p.id,n,C.getResolution())??null:null}function Af(i,u,p){let h=Cr(n,Hs(Ko(r),i,u));h.length!==0&&ge([...h,...Mr(n,h,cr(n),Re(n))],p)}function $f(i){let u=No(n,r,C.getResolution()),p=kx(u);p&&Af(es(i),Zd(u,p,i),h0[i])}function Tf(i){let u=No(n,r,C.getResolution());if(u.length<3)return null;let p=bu(u,i),h=wu(p);return h===null?null:{gap:h,series:p}}function Of(i){let u=Tf(i);u&&Af(i,ws(u.series,u.gap),i==="x"?"Distribute horizontally":"Distribute vertically")}function _x(){let i=Do(n,r);if(i.length===0)return null;let u=C.getResolution(),p={};for(let h of i)ce(h,x=>{let k=u.nodes.get(x.id)?.values;k&&(p[x.id]=k)});return{nodes:i,tokens:n.tokens,fonts:n.fonts,resolved:p}}function Sx(i){return new Map(Object.entries(i.resolved))}function Ex(i){let u=Object.entries(i.tokens).filter(([p])=>n.tokens[p]===void 0).map(([p,h])=>({op:"setToken",name:p,value:h}));for(let[p,h]of Object.entries(i.fonts))n.fonts[p]===void 0&&u.push({op:"setFont",name:p,family:h});return u}function Lf(i,u,p){let{nodes:h,remap:x}=Jl(i,n);if(h.length===0)return null;let k=Ex(i),_=k.length>0?Ae(n,k).document:n;h.forEach((B,W)=>{let Z=i.nodes[W];if(!Z)return;let ye=u(Z,W,_),Y={op:"insert",parent:ye.parent,index:ye.index,node:B};k.push(Y),_=Ae(_,[Y]).document});let M=Iu(_,x,Sx(i),p);M.length>0&&(_=Ae(_,M).document);let P=Cx(h);return{ops:[...k,...M,...Ar(n,_)],ids:[...x.values()].filter(B=>P.has(B))}}function Cx(i){let u=new Set;for(let p of i)u.add(p.id);return u}function Df(i){let u=_x();return u?Lf(u,(p,h,x)=>{let k=ht(x.root,p.id)??x.root,_=de(k).findIndex(M=>M.id===p.id);return{parent:k.id,index:_===-1?de(k).length:_+1}},i):null}function Ur(){let i=Xl(n,r,C.getResolution());return i!==null&&(Fu=i),i}function Pf(){let i=Ur();return i!==null&&qn(),i}function Mx(i){let u=[];for(let p of i.nodes){let h=i.resolved[p.id];if(!h)continue;let{x,y:k,w:_,h:M}=h;x===void 0||k===void 0||_===void 0||M===void 0||u.push({x,y:k,w:_,h:M})}return vt(u)??null}function js(i,u){let p=Yl(i??Fu??"");if(!p)return;let h=u??Ze,x=Mx(p),k=h&&x?{x:h.x-(x.x+x.w/2),y:h.y-(x.y+x.h/2)}:{x:As,y:As},_=w??n.root.id,M=Lf(p,(P,B,W)=>({parent:_,index:de(K(W.root,_)??W.root).length}),k);M&&(ge(M.ops,M.ids.length===1?"Paste":`Paste ${M.ids.length} elements`),he(M.ids))}async function Nf(i,u){let p=t.importImage;if(!p)return;let h=await Ja(i,t.maxImageEdge??2560);if(!h)return;let x=await p(new File([h.bytes],i.name,{type:h.type}));if(!x)return;let k=(u?Tr(u):void 0)??w??n.root.id,_=K(n.root,k)??n.root,M=mn(k),P=C.getResolution().nodes.get(k),{w:B,h:W}=em(h.width,h.height,P?.w&&P.w>0?P.w:h.width,P?.h&&P.h>0?P.h:h.height),Z=u??Ze,ye=Math.round((Z?Z.x-B/2:M.x)-M.x),Y=Math.round((Z?Z.y-W/2:M.y)-M.y),we=Ox(n,i.name),Ue=en(n.root,"image");ge([{op:"setAsset",name:we,value:x},{op:"insert",parent:k,index:de(_).length,node:si({id:Ue,x:ye,y:Y,w:B,h:W,src:we,fit:"cover"})}],"Place image"),he([Ue])}async function If(i,u){let p=t.importAudio;if(!p)return!1;let h=await p(i);return h?(ge(rm(n,u,nm(n,u,i.name),h),"Add music"),!0):!1}function Qo(){return t.importImage?Hm(n,rt().hidden):[]}function Ax(){return Qo().flatMap(i=>{let u=Ie(i.id);return u?[{frame:u,label:i.label,target:i.id===f}]:[]})}function Rf(i){return Qo().filter(p=>{let h=Ie(p.id);return h!==void 0&&bt(h,i.x,i.y)}).at(-1)??null}function $x(){return r.length!==1?null:Qo().find(i=>i.id===r[0])??null}async function Ks(i,u){let p=t.importImage;if(!p)return;let h=await Ja(u,t.maxImageEdge??2560);if(!h)return;let x=await p(new File([h.bytes],u.name,{type:h.type}));!x||n.assets[i.src]!==void 0||(ge([{op:"setAsset",name:i.src,value:x}],"Add image"),he([i.id]))}function Tx(i){let u=e.ownerDocument.createElement("input");u.type="file",u.accept="image/*",u.addEventListener("change",()=>{let p=u.files?.[0];p&&Ks(i,p)}),u.click()}function Ox(i,u){let p=u.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"image";if(i.assets[p]===void 0)return p;for(let h=2;;h+=1){let x=`${p}-${h}`;if(i.assets[x]===void 0)return x}}function qs(){let i=Df({x:As,y:As});i&&(ge(i.ops,i.ids.length===1?"Duplicate":`Duplicate ${i.ids.length} elements`),he(i.ids))}function Gs(i,u){if(i.length===0)return;let p=Ae(n,i).document;ge([...i,...Ar(n,p)],u)}function Ws(){let i=Zl(n,r);i&&(Gs(i.ops,"Group"),he([i.groupId]))}function Xs(){let i=r.filter(x=>{let k=K(n.root,x);return k!==void 0&&De(k)});if(i.length===0)return;let u=n,p=[],h=[];for(let x of i){let k=K(u.root,x);k&&h.push(...de(k).map(M=>M.id));let _=Ql(u,x);_.length!==0&&(p.push(..._),u=Ae(u,_).document)}w!==null&&i.includes(w)&&(w=null),Gs(p,i.length===1?"Ungroup":`Ungroup ${i.length} groups`),he(h)}function Ys(i){Gs(eu(n,r,i),y0[i])}function Lx(i,u,p){let h=K(n.root,u);if(!h||!be(h))return;let x=new Set(We(n.root,u)),k=i.filter(Y=>Y!==n.root.id&&K(n.root,Y)&&!x.has(Y));if(k.length===0)return;let _=new Set(k),M=de(h).filter(Y=>!_.has(Y.id))[p]?.id,P=[],B=n;for(let Y of k){let we=de(K(B.root,u)??B.root).filter(mt=>mt.id!==Y),Ue=M===void 0?-1:we.findIndex(mt=>mt.id===M),Ve={op:"move",id:Y,parent:u,index:Ue===-1?we.length:Ue};P.push(Ve),B=Ae(B,[Ve]).document}if(k.every(Y=>Px(n,B,Y)))return;let W=new Set(k.filter(Y=>ht(n.root,Y)?.id!==u).flatMap(Y=>af(Y,B))),Z=[];for(let Y of k){let we=Ff(n,Y),Ue=Ff(B,Y),Ve={x:we.x-Ue.x,y:we.y-Ue.y};if(!(Ve.x===0&&Ve.y===0))for(let mt of Rn(Y,B)){let Gn=Kt(mt);Gn&&(Z.push({op:"set",id:mt,prop:"x",value:ae(Gn.x+Ve.x)}),Z.push({op:"set",id:mt,prop:"y",value:ae(Gn.y+Ve.y)}))}}let ye=Ae(B,Z).document;ge([...P,...Z,...Ar(n,ye,W)],k.length===1?`Move ${k[0]}`:`Move ${k.length} layers`)}function Dx(i={}){let u=n.root.children,p=u.filter(Ue=>Ue.type==="frame"),h=p.find(Ue=>Ue.id===i.after),x=C.getResolution(),k=h?x.nodes.get(h.id):void 0,_=k&&k.w>0?k.w:th.w,M=k&&k.h>0?k.h:th.h,P=null,B=-1/0;for(let Ue of p.length>0?p:u){let Ve=x.nodes.get(Ue.id);!Ve||Ve.absX+Ve.w<=B||(B=Ve.absX+Ve.w,P={x:B+d0,y:Ve.absY})}let W=P??{x:0,y:0},Z=h??p[p.length-1],ye=Z?u.indexOf(Z)+1:u.length,Y=en(n.root,"frame"),we=h?.type==="frame"?h.background:void 0;return ge([{op:"insert",parent:n.root.id,index:ye,node:ua({id:Y,x:ae(W.x),y:ae(W.y),w:ae(_),h:ae(M),background:we??eh,children:[]})}],"Add frame"),he([Y]),Y}function Px(i,u,p){let h=ht(i.root,p),x=ht(u.root,p);return h?.id===x?.id&&h?.children.findIndex(k=>k.id===p)===x?.children.findIndex(k=>k.id===p)}function Ff(i,u){let p=We(i.root,u).slice(0,-1).reverse(),h=Re(i);for(let x of p){let k=K(i.root,x);if(!k||De(k))continue;let _=h.nodes.get(x);return _?{x:_.absX,y:_.absY}:{x:0,y:0}}return{x:0,y:0}}function Bf(i){let u=K(n.root,i);!u||!De(u)||(w=i,re())}function Hf(){if(w===null)return;let i=w;w=We(n.root,i).slice(0,-1).reverse().find(p=>{let h=K(n.root,p);return h!==void 0&&De(h)})??null,he([i])}function Js(){let i=K(n.root,w??n.root.id)??n.root;he(de(i).map(u=>u.id).filter(hn))}let Nx={locked:["Lock","Unlock"],hidden:["Hide","Show"]};function Uf(i){return i==="locked"?rt().locked:rt().hidden}function jn(i,u,p){let h=i.filter(_=>_!==n.root.id&&K(n.root,_)),x=p?h.filter(_=>!Uf(u).has(_)):[...new Set(h.flatMap(_=>{let M=zr(n.root,_,u);return M===void 0?[]:[M]}))];if(x.length===0)return;let k=Nx[u][p?0:1];ge(x.map(_=>({op:"set",id:_,prop:u,value:p?!0:void 0})),x.length===1?`${k} ${x[0]}`:`${k} ${x.length} layers`)}function Kn(i,u){i.length!==0&&jn(i,u,!i.every(p=>Uf(u).has(p)))}function Zs(i){let u=[];return ce(n.root,p=>{p[i]===!0&&u.push(p.id)}),u}function ea(i){let u=Zs(i);if(u.length===0)return;let p=i==="locked"?"Unlock all":"Show all";ge(u.map(h=>({op:"set",id:h,prop:i,value:void 0})),p)}function Ix(i){L={...rh,...i},ee?.close()}function qn(){let i=r.filter(p=>p!==n.root.id).map(p=>({op:"remove",id:p}));if(i.length===0)return;let u=i.length;he([]),ge(i,u===1?"Delete element":`Delete ${u} elements`)}function Vr(){ot=null;let i=z.undo();i&&Ju(i.ops,`Undo ${i.entry.label}`)}function ta(){ot=null;let i=z.redo();i&&Ju(i.ops,`Redo ${i.entry.label}`)}function Rx(i){if(!z.isTail(i))return!1;for(let u=i.length;u>0;u-=1)Vr();return!0}function Vf(i,u,p,h){let x=K(n.root,i);if(!x)return;let k=x[u];w0(k,p)||ge([{op:"set",id:i,prop:u,value:p}],h??`Set ${u}`)}function Fx(i,u){let p=n.brand?.theme==="dark"?n.themes?.dark:void 0;if(p!==void 0&&i in p){if(p[i]===u)return;ge([{op:"setTheme",value:{...n.themes,dark:{...p,[i]:u}}}],`Set $${i} in dark`);return}n.tokens[i]!==u&&ge([{op:"setToken",name:i,value:u}],`Set $${i}`)}function Bx(i){i in n.tokens&&ge([{op:"setToken",name:i,value:void 0}],`Remove $${i}`)}function zf(i,u){let p=Ot(i)?.values[u];p!==void 0&&ge([{op:"set",id:i,prop:u,value:ae(p)}],`Detach ${u}`)}function Hx(i){let u=K(n.root,w??n.root.id)??n.root,p=[];for(let h of de(u)){if(!hn(h.id))continue;let x=Ie(h.id);x&&jd(x,i)&&p.push(h.id)}return p}function ut(i){typeof e.setPointerCapture=="function"&&e.setPointerCapture(i)}function Qs(i){e.hasPointerCapture?.(i)&&e.releasePointerCapture(i)}let jf=i=>{J&&(tf(),J.handleKey(i)&&(i.preventDefault(),i.stopPropagation()))},Kf=i=>{J&&(i.preventDefault(),tf(),J.handleInput(i))},qf=()=>J?.handleCompositionStart(),Gf=i=>J?.handleCompositionUpdate(i.data??""),Wf=i=>J?.handleCompositionEnd(i.data??""),Xf=i=>{if(!e.ownerDocument.hasFocus())return;let u=i.relatedTarget;u instanceof Element&&u.closest("[data-vd-keeps-text]")||xn("blur")};return G.addEventListener("keydown",jf),G.addEventListener("beforeinput",Kf),G.addEventListener("compositionstart",qf),G.addEventListener("compositionupdate",Gf),G.addEventListener("compositionend",Wf),G.addEventListener("blur",Xf),e.addEventListener("pointerdown",uf),e.addEventListener("pointermove",cf),e.addEventListener("pointerup",Jo),e.addEventListener("pointercancel",Jo),e.addEventListener("pointerup",jo),e.addEventListener("pointercancel",jo),e.addEventListener("pointerleave",Cf),e.addEventListener("dblclick",bf),e.addEventListener("contextmenu",vf),e.addEventListener("keydown",pf),e.addEventListener("keyup",yf),e.addEventListener("copy",hf),e.addEventListener("cut",xf),e.addEventListener("paste",gf),e.addEventListener("dragover",_f),e.addEventListener("dragleave",Sf),e.addEventListener("drop",Ef),v=!0,q?.setTool(o),q?.setHistory(!1,!1),q?.setZoom(C.getCamera().zoom),Xe(Be(Ns())),t.autoFit&&!t.camera&&Te(()=>C.fitToContent()),t.history&&(z.restore(t.history),q?.setHistory(z.canUndo,z.canRedo)),t.selection&&t.selection.length>0&&he(t.selection),re(),{element:e,viewer:C,getDocument:()=>n,update(i){n=i,C.update(n),he(r),re(),me("problems",Ps())},applyOps:(i,u)=>ge(i,u??"Apply changes"),setDocument:(i,u)=>ge(Ai(n,Hd(i,n.root.id)),u??"Replace document"),getSelection:()=>r,setSelection:he,selectAll:Js,deleteSelection:qn,lock:i=>jn(i??r,"locked",!0),unlock:i=>jn(i??r,"locked",!1),toggleLock:i=>Kn(i??r,"locked"),unlockAll:()=>ea("locked"),hide:i=>jn(i??r,"hidden",!0),show:i=>jn(i??r,"hidden",!1),toggleHidden:i=>Kn(i??r,"hidden"),showAll:()=>ea("hidden"),isLocked:i=>rt().locked.has(i),isHidden:i=>rt().hidden.has(i),setFeatures:Ix,getFeatures:()=>L,moveLayers:Lx,addFrame:Dx,copy:Ur,cut:Pf,paste:js,duplicate:qs,group:Ws,ungroup:Xs,reorder:Ys,scaleSelection:qh,getSpacing:Yh,setSpacing:Xh,align:$f,distribute:Of,canDistribute:i=>Tf(i)!==null,editText:Nr,endTextEditing:()=>xn("done"),getEditingText:()=>J?.id??null,formatText:i=>J?.format(i),getTextFormat:()=>J?.activeMark()??{},getTextSelectionRects:Qu,getTextRange:()=>{if(!J)return null;let{anchor:i,head:u}=J.getSelection();return{from:Math.min(i,u),to:Math.max(i,u)}},getEnteredGroup:()=>w,enterGroup:Bf,exitGroup:Hf,getTool:()=>o,editPoints:yn,stopEditingPoints:Fr,getPointEditing:()=>ne?.id??null,convertToVector:i=>Vs(i),setTool:Wt,beginEdit:Lh,endEdit:Dh,undo:Vr,redo:ta,canUndo:()=>z.canUndo,canRedo:()=>z.canRedo,getHistory:()=>z.snapshot(),setProperty:Vf,fontFamilies:()=>{let i=new Map;for(let u of t.fonts?.faces()??[]){let p=i.get(u.family)??{weights:new Set,italic:!1};p.weights.add(u.weight),u.style==="italic"?p.italic=!0:(p.css===void 0||u.weight===400)&&(p.css=u.id),i.set(u.family,p)}return[...i.entries()].sort(([u],[p])=>u.localeCompare(p)).map(([u,p])=>({family:u,weights:[...p.weights].sort((h,x)=>h-x),italic:p.italic,...p.css===void 0?{}:{css:p.css}}))},assetUrl:i=>{let u=n.assets[i];return u?t.resolveAsset?.(u,i):void 0},addMusic:If,canAddMusic:()=>t.importAudio!==void 0,setToken:Fx,removeToken:Bx,bindingsOf:Oh,unbind:zf,getResolution:()=>C.getResolution(),getCamera:()=>C.getCamera(),getProblems:Ps,on:pe,reveal:Oe,panBy:Ah,setPresence(i,u){l={ids:[...i],label:u??null},re()},setHighlight(i){i.length===0&&c.length===0||(c=[...i],re())},isHistoryTail:i=>z.isTail(i),undoTail:Rx,historyTop:()=>z.top,destroy(){ue(),e.removeEventListener("pointerup",jo),e.removeEventListener("pointercancel",jo),e.removeEventListener("pointerdown",uf),e.removeEventListener("pointermove",cf),e.removeEventListener("pointerup",Jo),e.removeEventListener("pointercancel",Jo),e.removeEventListener("pointerleave",Cf),G.removeEventListener("keydown",jf),G.removeEventListener("beforeinput",Kf),G.removeEventListener("compositionstart",qf),G.removeEventListener("compositionupdate",Gf),G.removeEventListener("compositionend",Wf),G.removeEventListener("blur",Xf),G.remove(),zn&&clearTimeout(zn),e.removeEventListener("dblclick",bf),e.removeEventListener("contextmenu",vf),e.removeEventListener("copy",hf),e.removeEventListener("cut",xf),e.removeEventListener("paste",gf),e.removeEventListener("dragover",_f),e.removeEventListener("dragleave",Sf),e.removeEventListener("drop",Ef),e.removeEventListener("keydown",pf),e.removeEventListener("keyup",yf),ee?.destroy(),q?.destroy(),R.destroy(),C.destroy(),V.remove(),O.clear(),e.style.cursor="",e.classList.remove("vd-editor")}}}function w0(e,t){return e===t?!0:ke(e)&&ke(t)?e.expr===t.expr:!1}function oh(e){return e.metaKey||e.ctrlKey||e.altKey}function $s(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 BA=new Set(un);function zu(e){return e.map(t=>({value:t,label:`${t.charAt(0).toUpperCase()}${t.slice(1)}`}))}var S0=[{value:"nonzero",label:"Non-zero"},{value:"evenodd",label:"Even-odd"}].filter(e=>bn.includes(e.value)),E0=zu(wn),C0=zu(Zt),M0=zu(kn),A0=[{value:"left",label:"Left",icon:Je("text-left")},{value:"center",label:"Centre",icon:Je("text-center")},{value:"right",label:"Right",icon:Je("text-right")},{value:"justify",label:"Justify",icon:Je("text-justify")}].filter(e=>Yt.includes(e.value)),$0=[{value:"top",label:"Top",icon:Je("text-top")},{value:"middle",label:"Middle",icon:Je("text-middle")},{value:"bottom",label:"Bottom",icon:Je("text-bottom")}].filter(e=>Jt.includes(e.value)),dh={prop:"x",label:"X",kind:"number",prefix:"X"},lh={prop:"y",label:"Y",kind:"number",prefix:"Y"},Uu={prop:"w",label:"W",kind:"number",prefix:"W"},Vu={prop:"h",label:"H",kind:"number",prefix:"H"},T0={prop:"rotation",label:"Rotation",kind:"number",icon:"rotate",fallback:"0"},O0={prop:"opacity",label:"Opacity",kind:"number",icon:"opacity",percent:!0,fallback:"100%"},sh={prop:"radius",label:"Radius",kind:"number",icon:"radius",span:"wide",fallback:"0"},Vo={heading:"Position",props:[dh,lh,Uu,Vu,T0,O0]},Ts={prop:"fill",label:"Fill",kind:"colour"},uh={prop:"stroke",label:"Stroke",kind:"colour",span:"half"},fh={prop:"strokeWidth",label:"Stroke width",kind:"number",prefix:"Width",fallback:"1"},ch={present:"stroke",empty:"No stroke",add:{stroke:"#000000",strokeWidth:1},clear:["stroke","strokeWidth","cap","join"]},ih={heading:"Stroke",props:[uh,fh],optional:ch},HA={frame:[{heading:"Frame",props:[dh,lh,Uu,Vu,{prop:"clip",label:"Clip content",kind:"toggle"}]},{heading:"Fill",props:[{prop:"background",label:"Fill",kind:"colour"}]}],canvas:[{heading:"Canvas",props:[Uu,Vu,{prop:"background",label:"Fill",kind:"colour"}]}],text:[Vo,{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:A0,span:"half"},{prop:"valign",label:"Vertical",kind:"segmented",options:$0,span:"half"}]},{heading:"Fill",props:[Ts]},{heading:"Link",props:[{prop:"content",label:"Link",kind:"link",icon:"link"}]}],rect:[{heading:"Position",props:[...Vo.props,sh]},{heading:"Fill",props:[Ts]},ih],ellipse:[Vo,{heading:"Fill",props:[Ts]},ih],image:[{heading:"Position",props:[...Vo.props,sh]},{heading:"Image",props:[{prop:"fit",label:"Fit",kind:"select",options:C0,prefix:"Fit"}]}],vector:[Vo,{heading:"Fill",props:[{...Ts,span:"half"},{prop:"rule",label:"Fill rule",kind:"select",options:S0,prefix:"Rule",span:"half"}]},{heading:"Stroke",props:[uh,fh,{prop:"cap",label:"Cap",kind:"select",options:E0,prefix:"Cap",span:"half"},{prop:"join",label:"Join",kind:"select",options:M0,prefix:"Join",span:"half"}],optional:ch}]};var UA=vn.map(e=>({value:e,label:e.split("-").map((t,n)=>n===0?t.charAt(0).toUpperCase()+t.slice(1):t).join(" ")}));function ph(e){let t=e,n=new Map,r=typeof URL.createObjectURL=="function"&&typeof URL.revokeObjectURL=="function";return{resolve(o){let a=n.get(o.hash);if(a!==void 0)return a;let s=t.get(o.hash);if(s===void 0)return;if(!r)return zi(o.type,s);let d;try{d=Ki(s)}catch{return}let l=URL.createObjectURL(new Blob([d],{type:o.type}));return n.set(o.hash,l),l},replace(o){t=o;for(let[a,s]of n)o.has(a)||(URL.revokeObjectURL(s),n.delete(a))},destroy(){for(let o of n.values())URL.revokeObjectURL(o);n.clear(),t=new Map}}}var ju="0.4.0",mh="https://cdn.jsdelivr.net/npm/@getv.design/embed@0.4.0/fonts/";var U0=Symbol.for(`vdesign.embed.documents@${ju}`),hh=globalThis[U0]??=new WeakMap,V0=/^Line (\d+): /;function qu(e){let t=V0.exec(e.message);return{...t?{line:Number(t[1])}:{},code:e.code,message:e.message,severity:e.severity}}function Ku(e){if(typeof e!="string")return Ls(fo("").document,new Map,[{code:"not-text",message:`parse() takes .vd text, not ${e===null?"null":typeof e}.`,severity:"error"}]);let t=z0(e);if(t.vd===void 0)return Ls(fo("").document,new Map,[{code:"not-vd",message:"This SVG carries no vDesign document: only a .vd.svg exported from vDesign does.",severity:"error"}]);let{head:n,blocks:r}=Hi(t.vd),o=fo(n),a=o.problems.map(qu).map(s=>s.line===void 0?s:{...s,line:s.line+t.offset});return Ls(o.document,r,a)}function z0(e){if(!Zi(e))return{vd:e,offset:0};let t=Ji(e);if(t===void 0)return{vd:void 0,offset:0};let n=e.indexOf("<vd:document"),r=e.indexOf("</vd:document",n),o=e.indexOf("<![CDATA[",n);if(o===-1||r!==-1&&o>r){let d=e.indexOf(">",n)+1,l=e.slice(0,d).split(`
2792
+ `).length-1;return{vd:t,offset:l+(e[d]===`
2793
+ `?1:0)}}let a=o+9,s=e.slice(0,a).split(`
2794
+ `).length-1;return{vd:t,offset:s+(e[a]===`
2795
+ `?1:0)}}function Ls(e,t,n){let r=Object.freeze({});return hh.set(r,{document:e,blocks:t,problems:n}),{document:r,problems:n}}function xh(e,t,n){return Ls(e,t,[...n]).document}function Os(e){let t=hh.get(e);if(!t)throw new TypeError("Not a vDesign document: pass .vd text or what parse() returned.");return t}async function gh(e){if(typeof e=="string")return Os(Ku(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 Os(Ku(await t.text()).document)}return j0(e)?Os(Ku(await e.text()).document):Os(e)}function j0(e){let t=e;return typeof t.text=="function"&&typeof t.size=="number"}function $r(e){return e.root.children.filter(t=>t.type==="frame"&&t.hidden!==!0)}function yh(e,t){let n=$r(e),r=typeof t=="number"?n[t]:n.find(o=>o.id===t);if(!r){let o=n.map(a=>a.id).join(", ")||"none";throw new RangeError(`No page ${JSON.stringify(t)} in this document; its pages: ${o}.`)}return r}var Gu=["page","content","none"],vh=24;function zo(e){let t=e.getBoundingClientRect();return{width:t.width,height:t.height}}function bh(e,t){let n=t===void 0?void 0:e.itemOf(t);if(!(!n||n.w<=0||n.h<=0))return{x:n.x,y:n.y,width:n.w,height:n.h}}function wh(e,t,n,r){if(n==="none")return;let o=n==="page"?bh(e,r):void 0;if(!o){e.fitToContent(vh);return}let a=zo(t);e.setCamera(sn(o,{width:a.width||o.width,height:a.height||o.height},vh))}function kh(e,t,n){let r=e.getCamera(),o=zo(t),a={x:(o.width/2-r.x)/r.zoom,y:(o.height/2-r.y)/r.zoom},s;for(let d of $r(e.getDocument())){let l=bh(e,d.id);if(!l)continue;let f=Math.max(l.x-a.x,0,a.x-(l.x+l.width)),c=Math.max(l.y-a.y,0,a.y-(l.y+l.height)),m=Math.hypot(f,c);(!s||m<s.distance)&&(s={id:d.id,distance:m})}return s?.id??n}function _h(e,t,n){let r=e===void 0?t:String(e);if(r===void 0)return;let o;try{o=new URL(r,n??globalThis.location?.href)}catch{throw new TypeError(`fontBase must be a URL, or a path on this page; got ${r}.`)}return o.pathname.endsWith("/")||(o.pathname+="/"),o}var Wu=Symbol.for("vdesign.embed.handover");function Sh(e){return e[Wu]}var Eh=["exact","browser"],Ch=["change"],K0=250;async function T$(e,t,n={}){let r=n.fit??"page";if(!Gu.includes(r))throw new TypeError(`edit: fit must be one of ${Gu.join(", ")}; got ${String(r)}.`);let o=n.fonts??"exact";if(!Eh.includes(o))throw new TypeError(`edit: fonts must be one of ${Eh.join(", ")}; got ${String(o)}.`);let a=o==="exact"?_h(n.fontBase,mh,e.ownerDocument.baseURI):void 0,s=Sh(n),d=await gh(t),l=s?.page!==void 0&&$r(d.document).some(H=>H.id===s.page)?s.page:n.page===void 0?$r(d.document)[0]?.id:yh(d.document,n.page).id,f=s?.exact&&a?await q0(a,d.document):void 0,c=e.ownerDocument,m=c.defaultView,g=new Map(d.blocks),b=ph(g),E=c.createElement("div");E.className="vd-embed vd-embed--edit",E.style.position="relative",E.style.width="100%",E.style.height="100%",e.appendChild(E);let v=H=>{n.onLink?n.onLink(H):m?.open(H,"_blank","noopener,noreferrer")},w;try{w=Hu(E,{document:d.document,chrome:n.toolbar??!0,interactive:n.interactive??!0,wheel:"modifier",resolveAsset:H=>b.resolve(H),importImage:R,onOpenLink:v,...n.surface?{surface:n.surface}:{},...s?{camera:s.camera}:{},...f?{fonts:f.library}:{}})}catch(H){throw E.remove(),b.destroy(),H}let L=new Set,$=!1,z=!1,A=0,N=s===void 0,I,j,O,V;function C(H){return O?.of!==H&&(O={of:H,text:Ui(Bi(H),g)}),O.text}async function R(H){if($||!H.type.startsWith("image/"))return null;let ie=new Uint8Array(await H.arrayBuffer()),_e=await Vi(ie);return $?null:(g.has(_e)||g.set(_e,ji(ie)),{type:H.type,hash:_e,bytes:ie.length})}function q(){A+=1;try{wh(w.viewer,E,r,l)}finally{A-=1}}let ee=w.on("navigate",()=>{A===0&&(N=!1)}),oe=w.on("change",({document:H})=>{let ie={text:()=>C(H)};for(let _e of[...L])_e(ie);f&&D()}),se=zo(E),S=m&&"ResizeObserver"in m?new m.ResizeObserver(()=>{let H=zo(E);H.width===se.width&&H.height===se.height||(se=H,N&&q())}):void 0;S?.observe(E),s||q(),!f&&o==="exact"&&T();function y(){return j??=(async()=>{if(a)try{let{exactFontsAt:H}=await import("./chunks/fonts.js");return H(a)}catch{return}})(),j}async function T(){let H=await y();if(!($||!H)){for(;;){let ie=w.getDocument(),_e=await H.ensure(ie);if($||_e.length>0)return;if(w.getDocument()===ie)break}f=H,w.viewer.setFonts(H.library)}}function D(){I!==void 0&&clearTimeout(I),I=setTimeout(()=>{I=void 0;let H=f;$||!H||H.ensure(w.getDocument()).then(ie=>{$||f!==H||ie.length===0||(f=void 0,w.viewer.setFonts(void 0))})},K0)}function U(){$||($=!0,I!==void 0&&clearTimeout(I),oe(),ee(),S?.disconnect(),w.destroy(),b.destroy(),E.remove(),L.clear())}let X={getText:()=>C(w.getDocument()),getDocument(){let H=w.getDocument();return V?.of!==H&&(V={of:H,document:xh(H,new Map(g),w.getProblems().map(qu))}),V.document},on(H,ie){if(!Ch.includes(H))throw new TypeError(`edit: on() takes one of ${Ch.join(", ")}; got ${String(H)}.`);return L.add(ie),()=>{L.delete(ie)}},undo(){$||w.undo()},redo(){$||w.redo()},async view(){if($)throw new Error("edit: this editor was destroyed.");if(z)throw new Error("edit: view() is already opening a view.");z=!0,E.inert=!0;try{w.endTextEditing();let{view:H}=await import("./view.js");if($)throw new Error("edit: this editor was destroyed.");l=kh(w.viewer,E,l);let ie={camera:w.viewer.getCamera(),page:l,exact:f!==void 0},_e=w.getDocument(),Me=await H(e,X.getDocument(),{...G0(n),[Wu]:ie});if($)throw Me.destroy(),new Error("edit: this editor was destroyed.");let Se=w.getDocument()===_e?void 0:X.getDocument();return U(),Se&&await Me.load(Se),Me}finally{z=!1,E.inert=!1}},destroy:U};return X}async function q0(e,t){try{let{exactFontsAt:n}=await import("./chunks/fonts.js"),r=n(e);return(await r.ensure(t)).length===0?r:void 0}catch{return}}function G0(e){let{toolbar:t,...n}=e;return n}export{T$ as edit,ju as version};
2796
2796
  /*! Bundled license information:
2797
2797
 
2798
2798
  lucide/dist/esm/icons/a-large-small.mjs: