@getv.design/embed 0.5.5 → 0.6.1

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,47 +1,47 @@
1
- /*! @getv.design/embed v0.5.5. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
2
- function kt(e){return{expr:e}}function ye(e){return typeof e=="object"&&e!==null&&typeof e.expr=="string"}var Tn=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],fn=["left","center","right","justify"],cn=["top","middle","bottom"],pn=["cover","contain","fill"],Ln=["nonzero","evenodd"],Dn=["butt","round","square"],Pn=["miter","round","bevel"],yp=["canvas","frame","group","instance"];function Es(e){return yp.includes(e)}function fe(e){return Es(e.type)}function $e(e){return e.type==="group"}function ne(e){return fe(e)?e.children:[]}var vp={canvas:["w","h"],ellipse:["x","y","w","h","rotation","strokeWidth","opacity"],frame:["x","y","w","h"],group:[],instance:["x","y","w","h"],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 Ct(e){return vp[e.type]}function oe(e,t,n){if(t(e,n)!==!1&&fe(e))for(let r of e.children)oe(r,t,e)}function F(e,t){let n;return oe(e,r=>{if(n)return!1;r.id===t&&(n=r)}),n}function Fe(e,t){let n;return oe(e,(r,o)=>{r.id===t&&o&&(n=o)}),n}function Cs(e){return bp(e,"hidden")}function Ms(e){return bp(e,"locked")}function bp(e,t){let n=new Set,r=(o,s)=>{let i=s||o[t]===!0;i&&n.add(o.id);for(let d of ne(o))r(d,i)};return r(e,!1),n}function so(e,t,n){let r,o=(s,i)=>{let d=i??(s[n]===!0?s.id:void 0);return s.id===t?(r=d,!0):ne(s).some(l=>o(l,d))};return o(e,void 0),r}var As=["light","dark"],$s=["must","should"],Os=["no-gradient","contrast","font-only","logo-min"];var wp=["role","logo","rule","guide","review"];function Ts(e){return wp.includes(e)}function Ls(e="",t=1){return{slug:e,version:t,changes:[],sources:[],roles:{},logos:{},rules:{},guides:{},review:[]}}function Ga(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 qa(e){return`${e.slug}@${e.version}`}function Nn(e){return Xa(e,()=>{})??e}function Wa(e,t){return e===t?!0:e===void 0||t===void 0?!1:JSON.stringify(Nn(e))===JSON.stringify(Nn(t))}function Xa(e,t){let n=io(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=p=>{let m={};for(let[y,v]of Object.entries(io(p)??{}))typeof v=="string"&&(m[y]=v);return m},s=(p,m)=>{let y={};for(let[v,C]of Object.entries(io(p)??{})){let S=io(C),g=S?m(S):void 0;g===void 0?t(`brand: could not read ${v}`):y[v]=g}return y},i=(p,m)=>{let y=[];for(let v of Array.isArray(p)?p:[]){let C=io(v),S=C?m(C):void 0;S===void 0?t("brand: could not read a list entry"):y.push(S)}return y},d=p=>typeof p=="string"?p:void 0,l=p=>typeof p=="number"?p:void 0,f=(p,m)=>m===void 0?{}:{[p]:m};return{slug:n.slug,version:r,...f("id",d(n.id)),...f("theme",As.includes(n.theme)?n.theme:void 0),...f("strict",n.strict===!0?!0:void 0),...f("summary",d(n.summary)),changes:i(n.changes,p=>{let m=l(p.version),y=d(p.note);if(!(m===void 0||y===void 0))return{version:m,note:y,...f("at",d(p.at))}}),sources:i(n.sources,p=>{let m=d(p.kind);return m===void 0?void 0:{kind:m,props:o(p.props)}}),roles:s(n.roles,p=>{let m=d(p.light);return m===void 0?void 0:{light:m,...f("dark",d(p.dark))}}),logos:s(n.logos,p=>{let m=d(p.asset);if(m!==void 0)return{asset:m,...f("min",l(p.min)),...f("clear",l(p.clear))}}),rules:s(n.rules,p=>{let m=p.level,y=d(p.text);if(!$s.includes(m)||y===void 0)return;let v=o(p.params);return delete v.check,{level:m,text:y,...f("check",d(p.check)),...Object.keys(v).length===0?{}:{params:v}}}),guides:s(n.guides,p=>({entries:i(p.entries,Uy)})),review:i(n.review,p=>{let m=d(p.target);if(m!==void 0)return{target:m,...f("from",d(p.from)),...f("note",d(p.note))}})}}function Uy(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 io(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}var Vy=8,zy=new Set(["type","id","children","component","overrides"]);function mn(e){return!zy.has(e)}function Mt(e,t){return`${e}.${t}`}function Ye(e){let t=new Map,n=r=>{if(r.type!=="instance"){r.type==="frame"&&r.component===!0&&t.set(r.id,r);for(let o of ne(r))n(o)}};return n(e),t}function Ut(e,t){let n=[],r=o=>{if(o.type==="instance"){(t===void 0||o.component===t)&&n.push(o);return}for(let s of ne(o))r(s)};return r(e),n}function At(e,t){let n,r=(o,s)=>{if(o.id===t)return s&&(n={instance:s,key:t.slice(s.id.length+1)}),!0;let i=s??(o.type==="instance"?o:void 0);return ne(o).some(d=>r(d,i))};return r(e,void 0),n}function Za(e,t){let n,r=(o,s)=>{if(o.id===t)return n=s,!0;let i=o.type==="instance"?o:s;return ne(o).some(d=>r(d,i))};return r(e,void 0),n}function Qa(e,t,n,r){let o=Ye(e).get(t.component),s=o?F(o,n):void 0;return s?s[r]:void 0}function ed(e,t,n,r,o){let s={...e?.[t]};r===void 0||Ps(r,o)?delete s[n]:s[n]=r;let i={...e};return Object.keys(s).length===0?delete i[t]:i[t]=s,Object.keys(i).length===0?void 0:i}function Vt(e){let t=e;for(let n=0;n<Vy;n+=1){let r=Ye(t),o=kp(t,r);if(o===t)return t;t=o}return t}var Ya=new WeakMap;function kp(e,t){if(e.type==="instance"){let o=t.get(e.component)??null;if(Ya.has(e)&&Ya.get(e)===o)return e;let s=_p(e,t,new Set),i=Ps(s,e.children)?e:{...e,children:s};return Ya.set(i,o),i}if(!fe(e))return e;let n=!1,r=e.children.map(o=>{let s=kp(o,t);return s!==o&&(n=!0),s});return n?{...e,children:r}:e}function _p(e,t,n){let r=t.get(e.component);if(!r||n.has(r.id))return[];let o=new Set(n).add(r.id),s=r.children.map(i=>Ja(i,e.id,t,o));return jy(s,e.id,e.overrides)}function Ja(e,t,n,r){let o=Mt(t,e.id);if(e.type==="instance"){let s={...e,id:o};return{...s,children:_p(s,n,r)}}if(e.type==="frame"){let s={...e};return delete s.component,{...s,id:o,children:e.children.map(i=>Ja(i,t,n,r))}}return fe(e)?{...e,id:o,children:e.children.map(s=>Ja(s,t,n,r))}:{...e,id:o}}function jy(e,t,n){if(n===void 0)return[...e];let r=new Map;for(let[s,i]of Object.entries(n))r.set(Mt(t,s),i);let o=s=>{let i=r.get(s.id),d=s;if(i){let l={...s};for(let[f,p]of Object.entries(i))mn(f)&&(l[f]=p);d=l}return fe(d)?{...d,children:d.children.map(o)}:d};return e.map(o)}function ao(e){let t=[],n=Ye(e);for(let s of Ut(e)){let i=n.get(s.component);if(!i){t.push({severity:"error",code:"missing-component",message:`${s.id} places ${s.component}, which is not a component \u2014 mark a frame with component, or point component= at one`,nodeId:s.id});continue}if(Ds(i,i.id,n,new Set)){t.push({severity:"error",code:"component-cycle",message:`${i.id} holds an instance of itself, so ${s.id} cannot be drawn`,nodeId:s.id});continue}for(let d of Object.keys(s.overrides??{}))F(s,Mt(s.id,d))||t.push({severity:"warning",code:"orphaned-override",message:`${s.id} overrides ${d}, which ${i.id} no longer has`,nodeId:s.id})}for(let[s]of n)e.type==="canvas"&&e.children.some(i=>i.id===s)||t.push({severity:"warning",code:"component-not-top-level",message:`${s} is a component inside another frame \u2014 keep components in the row below the pages, at the top level`,nodeId:s});let r=new Map,o=s=>{r.set(s.id,(r.get(s.id)??0)+1);for(let i of ne(s))o(i)};o(e);for(let s of Ut(e))for(let i of s.children){let d=l=>{(r.get(l.id)??0)>1&&t.push({severity:"error",code:"duplicate-id",message:`${l.id} is both a node and a part of ${s.id} \u2014 rename one`,nodeId:l.id});for(let f of ne(l))d(f)};d(i)}return t}function Ds(e,t,n,r){return ne(e).some(o=>{if(o.type==="instance"){if(o.component===t)return!0;if(r.has(o.component))return!1;r.add(o.component);let s=n.get(o.component);return s!==void 0&&Ds(s,t,n,r)}return Ds(o,t,n,r)})}function td(e,t,n){if(t===n)return!0;let r=Ye(e),o=r.get(t);return o!==void 0&&Ds(o,n,r,new Set)}function nd(e,t){let n,r=(o,s)=>{let i=o.type==="frame"&&o.component===!0?o.id:s;return o.id===t?(n=s,!0):o.type==="instance"?!1:ne(o).some(d=>r(d,i))};return r(e,void 0),n}function lo(e,t){let n=e.overrides??{},r=[],o=new Set,s=d=>{let l=d.id.slice(e.id.length+1);n[l]!==void 0&&!o.has(l)&&(r.push({key:l,type:d.type}),o.add(l));for(let f of ne(d))s(f)};for(let d of e.children)s(d);let i=Object.keys(n).filter(d=>!o.has(d)).sort().map(d=>({key:d,type:void 0}));return[...r,...i].map(({key:d,type:l})=>{let f=l===void 0?[]:t(l),p=y=>y==="content"?-1:f.includes(y)?f.indexOf(y):f.length,m=Object.entries(n[d]??{}).sort(([y],[v])=>p(y)-p(v)||(y<v?-1:y>v?1:0));return[d,m]})}function uo(e){return Ye(e).size>0||Ut(e).length>0}function Ps(e,t){if(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((s,i)=>Ps(s,t[i]));let n=e,r=t,o=new Set([...Object.keys(n),...Object.keys(r)]);for(let s of o)if(!Ps(n[s],r[s]))return!1;return!0}var In=["design","brand"],hn="design",Sp=new WeakMap;function st(e){let t=e.brand?.theme==="dark"?e.themes?.dark:void 0;if(t===void 0)return e.tokens;let n=Sp.get(e);if(n!==void 0)return n;let r={...e.tokens,...t};return Sp.set(e,r),r}var Ep=4,Cp=5,rd=6,fo=[1,2,3,4,5,6],co=rd;function it(e){return e.root!==void 0&&uo(e.root)?rd:e.kind==="brand"||e.brand!==void 0||e.themes!==void 0||Ky(e.fonts)?Cp:Ep}function Ky(e){return Object.values(e??{}).some(t=>(t.faces??[]).some(n=>n.asset!==void 0))}var $t="doc";function ur(e){return{type:"canvas",...e}}function od(e){return{type:"ellipse",...e}}function Ns(e){return{type:"frame",...e}}function sd(e){return{type:"group",...e}}function id(e){return{type:"image",...e}}function ad(e){return{type:"rect",...e}}function dd(e){return{type:"text",...e}}function Is(e){return{type:"vector",...e}}function po(e={}){let t=e.kind??hn,n=Ot(e.themes),r=Vt(e.root??ur({id:$t,children:[]}));return{version:it({kind:t,root:r,...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:r}}function Ot(e){let t=e?.dark;return t===void 0||Object.keys(t).length===0?void 0:{dark:t}}function xn(e){let t=new Set;return oe(e,n=>{t.add(n.id)}),t}function gn(e,t){let n=xn(e),r=0;for(let o of n){if(!o.startsWith(`${t}.`))continue;let s=Number(o.slice(t.length+1));Number.isInteger(s)&&s>r&&(r=s)}return`${t}.${r+1}`}function _t(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 mo=["beat","bar"];var Gy=/^(\d+(?:\.\d+)?)(beats?|bars?)$/;function Rn(e){let t=Gy.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 Fn(e,t){return`${String(Math.round(e*1e6)/1e6)}${t}${e===1?"":"s"}`}function Bn(e){return typeof e=="string"&&Rn(e)!==void 0}function St(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 Je(e,t,n){if(e===void 0)return n;if(typeof e=="number")return e;let r=Rn(e);return!r||!t?n:r.count*(r.unit==="bar"?t.bar:t.beat)}function ld(e,t,n){let r=t==="bar"?n.bar:n.beat,o=Math.ceil((e-1)/r);return Math.max(0,o)*r}function ho(e){return`${Math.round(e)} ms`}var fr=36e5;var ud=50,fd=16e3,cd=320,xo=["from","volume","fadein","fadeout","loop"];function pd(e,t){return e===t?!0:e===void 0||t===void 0?!1:e.asset===t.asset&&xo.every(n=>e[n]===t[n])}function md(e,t){let n=e?.music;if(!n)return[];let r=St(e),o=t[n.asset]?.ms,s=Je(n.fadeout,r);return[{asset:n.asset,at:0,from:n.from??0,volume:n.volume??1,fadeIn:Je(n.fadein,r,0),...s===void 0?{}:{fadeOut:s},loop:n.loop===!0,...o===void 0?{}:{sourceMs:o}}]}var pr=["cut","fade","push","slide"],go=["cut","fade","rise","drop","pop","wipe","grow","count","draw"],cr=["cut","fade","rise","drop","pop"],yo=["pulse"],vo=["out","in","inout","linear","spring"],bo=["word","letter"],yn=["left","right","top","bottom"],wo=400,Tt=1e4,vn=18e4,Lt=7680;function zt(e){let t=e.trim();return t==="back"?{kind:"back"}:t==="next"?{kind:"next"}:_t(t)}function jt(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 mr(e){return e.camera===!0||e.enter!==void 0||e.exit!==void 0||e.emphasis!==void 0||e.go!==void 0}var qy=["id","camera","enter","exit","emphasis","from","by","stagger","duration","hold","delay","at","after","with","step","together","on","ease","pad","go"],Wy=["camera","emphasis","from","by","stagger","hold","at","after","with","on","ease","pad"];function Hn(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=>Wy.some(n=>t[n]!==void 0)||t.enter!==void 0&&!cr.includes(t.enter)||t.exit!==void 0&&!cr.includes(t.exit))}function Rs(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||!pd(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 qy.every(s=>n[s]===o[s])})}function hr(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 Kt(e){return new Set(e.root.children.filter(t=>t.type==="frame"&&t.component!==!0).map(t=>t.id))}function yt(e){let t=new Map;for(let n of e.root.children)n.type!=="frame"||n.component===!0||oe(n,r=>{t.set(r.id,n.id)});return t}function hd(e){let t=new Set;return oe(e,n=>{t.add(n.id)}),t}function xr(e,t){let n=e.motion;if(!n)return[];let r=[],o=Kt(e),s=yt(e),i=hd(e.root),d=(l,f)=>{let p=t?.(l,f);return p===void 0?"":`Line ${p}: `};for(let l of hr(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 p=new Set;for(let m of f.lines){let y=d(l,m.id);for(let S of["after","with"]){let g=m[S];g!==void 0&&!p.has(g)&&r.push({severity:"warning",code:"motion-anchor-missing",message:`${y}motion ${l}: ${S}=${g} names no line above, so it starts after the line above instead`,nodeId:m.id})}m.camera!==!0&&p.add(m.id);let v=i.has(m.id)?F(e.root,m.id):void 0;v&&r.push(...Xy(m,v,y,l)),i.has(m.id)?s.get(m.id)!==l&&r.push({severity:"warning",code:"motion-wrong-page",message:`${y}motion ${l}: ${m.id} is not on ${l}, so Play skips it`,nodeId:m.id}):r.push({severity:"warning",code:"unknown-reference",message:`${y}motion ${l}: no node ${m.id}`,nodeId:m.id});let C=m.go===void 0?void 0:zt(m.go);C?.kind==="frame"&&!Zy(e,C.id)&&r.push({severity:"warning",code:"unknown-reference",message:`${y}motion ${l}: go=#${C.id} names no frame`,nodeId:m.id})}}return r}function Xy(e,t,n,r){let o=[],s=(d,l)=>{o.push({severity:"warning",code:d,message:`${n}motion ${r}: ${l}`,nodeId:t.id})};if(e.camera===!0)return o;let i=e.enter??e.exit;return i==="count"&&(t.type!=="text"||!/\d/.test(bn(t.content)))&&s("count-no-number",`${t.id} has no number to count, so it fades in instead`),i==="draw"&&!Jy(t)&&s("draw-no-stroke",`${t.id} has no stroked vector to draw, so it fades in instead`),e.by!==void 0&&t.type!=="text"?s("by-not-text",`by=${e.by} splits text, and ${t.id} is a ${t.type}`):e.by!==void 0&&t.type==="text"&&Yy(t)&&s("by-rotated",`${t.id} is rotated, so by=${e.by} enters it whole`),e.stagger!==void 0&&e.by===void 0&&ne(t).length===0&&s("stagger-no-children",`${t.id} has no children to stagger: split a text with by=word`),o}function Yy(e){let t=e.rotation;return t!==void 0&&t!==0}function Jy(e){let t=!1;return oe(e,n=>(n.type==="vector"&&n.stroke!==void 0&&(t=!0),t?!1:void 0)),t}function bn(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function Zy(e,t){let n=!1;return oe(e.root,r=>{if(n)return!1;r.id===t&&(n=r.type==="frame")}),n}function Mp(e,t){let n=t.motion;if(!n||!e.motion)return n;let r=yt(e),o=yt(t),s=hd(e.root),i=hd(t.root),d=m=>s.has(m)&&!i.has(m),l=!1,f={},p=[];for(let[m,y]of Object.entries(n)){if(d(m)){l=!0;continue}let v=[];for(let S of y.lines){let g=S,L=S.go===void 0?void 0:zt(S.go);if(L?.kind==="frame"&&d(L.id)){let A=ev(S);g=mr(A)?A:void 0,l=!0}if(g&&(g.after!==void 0&&d(g.after)||g.with!==void 0&&d(g.with))&&(g=Qy(g,d),l=!0),g&&d(S.id))g=void 0,l=!0;else if(g&&r.get(S.id)===m&&o.get(S.id)!==m){let A=o.get(S.id);A!==void 0&&p.push([A,g]),g=void 0,l=!0}g&&v.push(g)}let C={...y,lines:v};jt(C)||(f[m]=C)}for(let[m,y]of p){let v=f[m]??{lines:[]};f[m]={...v,lines:[...v.lines,y]}}return l?Object.keys(f).length===0?void 0:f:n}function Qy(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 ev(e){let t={...e};return delete t.go,t}function xd(e,t){let n={...e};return t===void 0||Object.keys(t).length===0?delete n.motion:n.motion=t,n}function gd(e,t){let n=Mp(e,t);if(n===t.motion)return[];let r=new Set([...Object.keys(t.motion??{}),...Object.keys(n??{})]),o=[];for(let s of r){let i=n?.[s];Rs(t.motion?.[s],i)||o.push({op:"setMotion",page:s,value:i})}return o}var Ap={canvas:["type","id","name","w","h","background","children"],frame:["type","id","name","x","y","w","h","background","clip","skip","component","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"],instance:["type","id","name","component","x","y","w","h","overrides","hidden","locked"],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"]},$p=["text","font","size","weight","italic","underline","strike","fill","letterSpacing","link"],tv=["family","fallback","faces"],nv=["src","asset","weight","style"],Te=" ";function yd(e){let t=["{",`${Te}"version": ${se(it(e))},`,`${Te}"kind": ${JSON.stringify(e.kind)},`,...e.title===void 0?[]:[`${Te}"title": ${JSON.stringify(e.title)},`],`${Te}"tokens": ${ov(e.tokens,Te)},`];return Object.keys(e.fonts).length>0&&t.push(`${Te}"fonts": ${sv(e.fonts,Te)},`),e.motion!==void 0&&t.push(`${Te}"motion": ${rv(e,Te)},`),e.brand!==void 0&&t.push(`${Te}"brand": ${JSON.stringify(Nn(e.brand))},`),e.themes?.dark!==void 0&&Object.keys(e.themes.dark).length>0&&t.push(`${Te}"themes": ${JSON.stringify({dark:e.themes.dark})},`),t.push(`${Te}"root": ${vd(e.root,Te)}`,"}"),`${t.join(`
1
+ /*! @getv.design/embed v0.6.1. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
2
+ function _t(e){return{expr:e}}function ve(e){return typeof e=="object"&&e!==null&&typeof e.expr=="string"}var Bt=["radiusTL","radiusTR","radiusBR","radiusBL"],Cn=["radius",...Bt];var F1={radiusTL:"tl",radiusTR:"tr",radiusBR:"br",radiusBL:"bl"};function Zn(e){let t=e.radius??0,n=r=>Math.max(0,e[r]??t);return{tl:n("radiusTL"),tr:n("radiusTR"),br:n("radiusBR"),bl:n("radiusBL")}}function Ao(e,t,n){let r=Math.max(0,t),o=Math.max(0,n),s=1,i=(a,d)=>{d>0&&(s=Math.min(s,a/d))};return i(r,e.tl+e.tr),i(r,e.bl+e.br),i(o,e.tl+e.bl),i(o,e.tr+e.br),s>=1?e:{tl:e.tl*s,tr:e.tr*s,br:e.br*s,bl:e.bl*s}}function $o(e,t,n){return Ao(Zn(e),t,n)}function Jt(e){return e.tl<=0&&e.tr<=0&&e.br<=0&&e.bl<=0}function Vc(e){return e.tl===e.tr&&e.tr===e.br&&e.br===e.bl}function Hc(e,t){return e[F1[t]]}function zs(e){let t=e;return Bt.some(n=>t[n]!==void 0)}var B1=/^(?:\d+(?:\.\d*)?|\.\d+)$/;function Uc(e){if(!e.startsWith('"'))return;let t;try{let a=JSON.parse(e);if(typeof a!="string")return;t=a}catch{return}let n=t.trim().split(/\s+/).filter(a=>a!=="");if(n.length<2)return;if(n.length>4)return{error:`the shorthand takes one to four corners, got ${n.length}: "${t}"`};for(let a of n){if(/^[$@(]/.test(a))return{error:`the shorthand takes numbers \u2014 bind one corner with its own cell, e.g. radiusTL=${a}`};if(!B1.test(a))return/^(-?\d+(?:\.\d+)?)px$/.exec(a)&&!a.startsWith("-")?{error:`drop the unit: radius="${n.map(c=>c.replace(/px$/,"")).join(" ")}"`}:{error:/^-\d/.test(a)?`a radius cannot be negative, got ${a}`:`the shorthand takes plain numbers, got "${a}"`}}let[r,o=r,s=r,i=o]=n;return{corners:[["radiusTL",r],["radiusTR",o],["radiusBR",s],["radiusBL",i]]}}function Ca(e){if(e.radius!==void 0)return;let t=[];for(let n of Bt){let r=e[n];if(typeof r!="number"||!(r>=0)||!Number.isFinite(r))return;t.push(r)}return t}var Cr=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],kg=["frame","rect","ellipse","vector"];function Aa(e){return kg.includes(e)}var Qn=["left","center","right","justify"],er=["top","middle","bottom"],Zt=["cover","contain","fill"],Ar=["nonzero","evenodd"],tr=["butt","round","square"],$r=["miter","round","bevel"],Sg=["canvas","frame","group","instance"];function $a(e){return Sg.includes(e)}function me(e){return $a(e.type)}function Ne(e){return e.type==="group"}function te(e){return me(e)?e.children:[]}var _g={canvas:["w","h"],connector:["x1","y1","x2","y2","strokeWidth","opacity","blur"],ellipse:["x","y","w","h","rotation","strokeWidth","opacity","blur","backdrop"],frame:["x","y","w","h","strokeWidth",...Cn,"blur","backdrop"],group:[],instance:["x","y","w","h"],image:["x","y","w","h","rotation","strokeWidth",...Cn,"opacity","blur"],rect:["x","y","w","h","rotation","strokeWidth",...Cn,"opacity","blur","backdrop"],text:["x","y","w","h","rotation","size","weight","lineHeight","letterSpacing","strokeWidth","opacity","blur"],video:["x","y","w","h","rotation","strokeWidth",...Cn,"opacity","blur"],vector:["x","y","w","h","rotation","strokeWidth","opacity","blur","backdrop"]};function Vt(e){return _g[e.type]}function de(e,t,n){if(t(e,n)!==!1&&me(e))for(let r of e.children)de(r,t,e)}function z(e,t){let n;return de(e,r=>{if(n)return!1;r.id===t&&(n=r)}),n}function Le(e,t){let n;return de(e,(r,o)=>{r.id===t&&o&&(n=o)}),n}function Oa(e){return Eg(e,"hidden")}function Ta(e){return Eg(e,"locked")}function Eg(e,t){let n=new Set,r=(o,s)=>{let i=s||o[t]===!0;i&&n.add(o.id);for(let a of te(o))r(a,i)};return r(e,!1),n}function js(e,t,n){let r,o=(s,i)=>{let a=i??(s[n]===!0?s.id:void 0);return s.id===t?(r=a,!0):te(s).some(d=>o(d,a))};return o(e,void 0),r}var La=["light","dark"],Pa=["must","should"],Da=["no-gradient","contrast","font-only","logo-min"];var Mg=["role","logo","rule","guide","review"];function Na(e){return Mg.includes(e)}function Ra(e="",t=1){return{slug:e,version:t,changes:[],sources:[],roles:{},logos:{},rules:{},guides:{},review:[]}}function zc(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 jc(e){return`${e.slug}@${e.version}`}function Or(e){return Gc(e,()=>{})??e}function Kc(e,t){return e===t?!0:e===void 0||t===void 0?!1:JSON.stringify(Or(e))===JSON.stringify(Or(t))}function Gc(e,t){let n=Ks(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=l=>{let p={};for(let[m,g]of Object.entries(Ks(l)??{}))typeof g=="string"&&(p[m]=g);return p},s=(l,p)=>{let m={};for(let[g,b]of Object.entries(Ks(l)??{})){let w=Ks(b),k=w?p(w):void 0;k===void 0?t(`brand: could not read ${g}`):m[g]=k}return m},i=(l,p)=>{let m=[];for(let g of Array.isArray(l)?l:[]){let b=Ks(g),w=b?p(b):void 0;w===void 0?t("brand: could not read a list entry"):m.push(w)}return m},a=l=>typeof l=="string"?l:void 0,d=l=>typeof l=="number"?l:void 0,c=(l,p)=>p===void 0?{}:{[l]:p};return{slug:n.slug,version:r,...c("id",a(n.id)),...c("theme",La.includes(n.theme)?n.theme:void 0),...c("strict",n.strict===!0?!0:void 0),...c("summary",a(n.summary)),changes:i(n.changes,l=>{let p=d(l.version),m=a(l.note);if(!(p===void 0||m===void 0))return{version:p,note:m,...c("at",a(l.at))}}),sources:i(n.sources,l=>{let p=a(l.kind);return p===void 0?void 0:{kind:p,props:o(l.props)}}),roles:s(n.roles,l=>{let p=a(l.light);return p===void 0?void 0:{light:p,...c("dark",a(l.dark))}}),logos:s(n.logos,l=>{let p=a(l.asset);if(p!==void 0)return{asset:p,...c("min",d(l.min)),...c("clear",d(l.clear))}}),rules:s(n.rules,l=>{let p=l.level,m=a(l.text);if(!Pa.includes(p)||m===void 0)return;let g=o(l.params);return delete g.check,{level:p,text:m,...c("check",a(l.check)),...Object.keys(g).length===0?{}:{params:g}}}),guides:s(n.guides,l=>({entries:i(l.entries,V1)})),review:i(n.review,l=>{let p=a(l.target);if(p!==void 0)return{target:p,...c("from",a(l.from)),...c("note",a(l.note))}})}}function V1(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 Ks(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}var H1=8,U1=new Set(["type","id","children","component","overrides"]);function nr(e){return!U1.has(e)}function Ht(e,t){return`${e}.${t}`}function lt(e){let t=new Map,n=r=>{if(r.type!=="instance"){r.type==="frame"&&r.component===!0&&t.set(r.id,r);for(let o of te(r))n(o)}};return n(e),t}function An(e,t){let n=[],r=o=>{if(o.type==="instance"){(t===void 0||o.component===t)&&n.push(o);return}for(let s of te(o))r(s)};return r(e),n}function Lt(e,t){let n,r=(o,s)=>{if(o.id===t)return s&&(n={instance:s,key:t.slice(s.id.length+1)}),!0;let i=s??(o.type==="instance"?o:void 0);return te(o).some(a=>r(a,i))};return r(e,void 0),n}function Ba(e,t){let n,r=(o,s)=>{if(o.id===t)return n=s,!0;let i=o.type==="instance"?o:s;return te(o).some(a=>r(a,i))};return r(e,void 0),n}function Xc(e,t,n,r){let o=lt(e).get(t.component),s=o?z(o,n):void 0;return s?s[r]:void 0}function Yc(e,t,n,r,o){let s={...e?.[t]};r===void 0||Fa(r,o)?delete s[n]:s[n]=r;let i={...e};return Object.keys(s).length===0?delete i[t]:i[t]=s,Object.keys(i).length===0?void 0:i}function $n(e){let t=e;for(let n=0;n<H1;n+=1){let r=lt(t),o=Cg(t,r);if(o===t)return t;t=o}return t}var qc=new WeakMap;function Cg(e,t){if(e.type==="instance"){let o=t.get(e.component)??null;if(qc.has(e)&&qc.get(e)===o)return e;let s=Ag(e,t,new Set),i=Fa(s,e.children)?e:{...e,children:s};return qc.set(i,o),i}if(!me(e))return e;let n=!1,r=e.children.map(o=>{let s=Cg(o,t);return s!==o&&(n=!0),s});return n?{...e,children:r}:e}function Ag(e,t,n){let r=t.get(e.component);if(!r||n.has(r.id))return[];let o=new Set(n).add(r.id),s=r.children.map(i=>Wc(i,e.id,t,o));return z1(s,e.id,e.overrides)}function Wc(e,t,n,r){let o=Ht(t,e.id);if(e.type==="instance"){let s={...e,id:o};return{...s,children:Ag(s,n,r)}}if(e.type==="frame"){let s={...e};return delete s.component,{...s,id:o,children:e.children.map(i=>Wc(i,t,n,r))}}return me(e)?{...e,id:o,children:e.children.map(s=>Wc(s,t,n,r))}:{...e,id:o}}function z1(e,t,n){if(n===void 0)return[...e];let r=new Map;for(let[s,i]of Object.entries(n))r.set(Ht(t,s),i);let o=s=>{let i=r.get(s.id),a=s;if(i){let d={...s};for(let[c,l]of Object.entries(i))nr(c)&&(d[c]=l);a=d}return me(a)?{...a,children:a.children.map(o)}:a};return e.map(o)}function Gs(e){let t=[],n=lt(e);for(let s of An(e)){let i=n.get(s.component);if(!i){t.push({severity:"error",code:"missing-component",message:`${s.id} places ${s.component}, which is not a component \u2014 mark a frame with component, or point component= at one`,nodeId:s.id});continue}if(Ia(i,i.id,n,new Set)){t.push({severity:"error",code:"component-cycle",message:`${i.id} holds an instance of itself, so ${s.id} cannot be drawn`,nodeId:s.id});continue}for(let a of Object.keys(s.overrides??{}))z(s,Ht(s.id,a))||t.push({severity:"warning",code:"orphaned-override",message:`${s.id} overrides ${a}, which ${i.id} no longer has`,nodeId:s.id})}for(let[s]of n)e.type==="canvas"&&e.children.some(i=>i.id===s)||t.push({severity:"warning",code:"component-not-top-level",message:`${s} is a component inside another frame \u2014 keep components in the row below the pages, at the top level`,nodeId:s});let r=new Map,o=s=>{r.set(s.id,(r.get(s.id)??0)+1);for(let i of te(s))o(i)};o(e);for(let s of An(e))for(let i of s.children){let a=d=>{(r.get(d.id)??0)>1&&t.push({severity:"error",code:"duplicate-id",message:`${d.id} is both a node and a part of ${s.id} \u2014 rename one`,nodeId:d.id});for(let c of te(d))a(c)};a(i)}return t}function Ia(e,t,n,r){return te(e).some(o=>{if(o.type==="instance"){if(o.component===t)return!0;if(r.has(o.component))return!1;r.add(o.component);let s=n.get(o.component);return s!==void 0&&Ia(s,t,n,r)}return Ia(o,t,n,r)})}function Jc(e,t,n){if(t===n)return!0;let r=lt(e),o=r.get(t);return o!==void 0&&Ia(o,n,r,new Set)}function Zc(e,t){let n,r=(o,s)=>{let i=o.type==="frame"&&o.component===!0?o.id:s;return o.id===t?(n=s,!0):o.type==="instance"?!1:te(o).some(a=>r(a,i))};return r(e,void 0),n}function qs(e,t){let n=e.overrides??{},r=[],o=new Set,s=a=>{let d=a.id.slice(e.id.length+1);n[d]!==void 0&&!o.has(d)&&(r.push({key:d,type:a.type}),o.add(d));for(let c of te(a))s(c)};for(let a of e.children)s(a);let i=Object.keys(n).filter(a=>!o.has(a)).sort().map(a=>({key:a,type:void 0}));return[...r,...i].map(({key:a,type:d})=>{let c=d===void 0?[]:t(d),l=m=>m==="content"?-1:c.includes(m)?c.indexOf(m):c.length,p=Object.entries(n[a]??{}).sort(([m],[g])=>l(m)-l(g)||(m<g?-1:m>g?1:0));return[a,p]})}function Ws(e){return lt(e).size>0||An(e).length>0}function Fa(e,t){if(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((s,i)=>Fa(s,t[i]));let n=e,r=t,o=new Set([...Object.keys(n),...Object.keys(r)]);for(let s of o)if(!Fa(n[s],r[s]))return!1;return!0}var Tr=["design","brand"],rr="design",$g=new WeakMap;function Ze(e){let t=e.brand?.theme==="dark"?e.themes?.dark:void 0;if(t===void 0)return e.tokens;let n=$g.get(e);if(n!==void 0)return n;let r={...e.tokens,...t};return $g.set(e,r),r}var Og=4,Tg=5,Lg=6,Pg=7,Qc=8,Xs=[1,2,3,4,5,6,7,8],Ys=Qc;function Et(e){return e.root!==void 0&&Dg(e.root)?Qc:e.root!==void 0&&Ng(e.root)?Pg:e.root!==void 0&&Ws(e.root)?Lg:e.kind==="brand"||e.brand!==void 0||e.themes!==void 0||j1(e.fonts)?Tg:Og}function Dg(e){let t=!1;return de(e,n=>(n.type==="video"&&(t=!0),t?!1:void 0)),t}function Ng(e){let t=!1;return de(e,n=>(n.type==="connector"&&(t=!0),t?!1:void 0)),t}function j1(e){return Object.values(e??{}).some(t=>(t.faces??[]).some(n=>n.asset!==void 0))}var dn="doc";function Oo(e){return{type:"canvas",...e}}function el(e){return{type:"connector",...e}}function tl(e){return{type:"ellipse",...e}}function Va(e){return{type:"frame",...e}}function nl(e){return{type:"group",...e}}function rl(e){return{type:"video",...e}}function ol(e){return{type:"image",...e}}function sl(e){return{type:"rect",...e}}function il(e){return{type:"text",...e}}function To(e){return{type:"vector",...e}}function Js(e={}){let t=e.kind??rr,n=un(e.themes),r=$n(e.root??Oo({id:dn,children:[]}));return{version:Et({kind:t,root:r,...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:r}}function un(e){let t=e?.dark;return t===void 0||Object.keys(t).length===0?void 0:{dark:t}}function Qt(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 Zs=["beat","bar"];var K1=/^(\d+(?:\.\d+)?)(beats?|bars?)$/;function Lr(e){let t=K1.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 Pr(e,t){return`${String(Math.round(e*1e6)/1e6)}${t}${e===1?"":"s"}`}function Dr(e){return typeof e=="string"&&Lr(e)!==void 0}function en(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 ft(e,t,n){if(e===void 0)return n;if(typeof e=="number")return e;let r=Lr(e);return!r||!t?n:r.count*(r.unit==="bar"?t.bar:t.beat)}function al(e,t,n){let r=t==="bar"?n.bar:n.beat,o=Math.ceil((e-1)/r);return Math.max(0,o)*r}function Qs(e){return`${Math.round(e)} ms`}var Lo=36e5;var dl=50,ul=16e3,cl=320,ei=["from","volume","fadein","fadeout","loop"];function ll(e,t){return e===t?!0:e===void 0||t===void 0?!1:e.asset===t.asset&&ei.every(n=>e[n]===t[n])}function fl(e,t){let n=e?.music;if(!n)return[];let r=en(e),o=t[n.asset]?.ms,s=ft(n.fadeout,r);return[{asset:n.asset,at:0,from:n.from??0,volume:n.volume??1,fadeIn:ft(n.fadein,r,0),...s===void 0?{}:{fadeOut:s},loop:n.loop===!0,...o===void 0?{}:{sourceMs:o}}]}var Do=["cut","fade","push","slide"],ti=["cut","fade","rise","drop","pop","wipe","grow","count","draw"],Po=["cut","fade","rise","drop","pop"],ni=["pulse"],ri=["out","in","inout","linear","spring"],oi=["word","letter"],or=["left","right","top","bottom"],si=400,cn=1e4,sr=18e4,ln=7680;function On(e){let t=e.trim();return t==="back"?{kind:"back"}:t==="next"?{kind:"next"}:Qt(t)}function Tn(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 No(e){return e.camera===!0||e.enter!==void 0||e.exit!==void 0||e.emphasis!==void 0||e.go!==void 0}var G1=["id","camera","enter","exit","emphasis","from","by","stagger","duration","hold","delay","at","after","with","step","together","on","ease","pad","go"],q1=["camera","emphasis","from","by","stagger","hold","at","after","with","on","ease","pad"];function Nr(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=>q1.some(n=>t[n]!==void 0)||t.enter!==void 0&&!Po.includes(t.enter)||t.exit!==void 0&&!Po.includes(t.exit))}function Ha(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||!ll(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 G1.every(s=>n[s]===o[s])})}function Ro(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 Ln(e){return new Set(e.root.children.filter(t=>t.type==="frame"&&t.component!==!0).map(t=>t.id))}function Ut(e){let t=new Map;for(let n of e.root.children)n.type!=="frame"||n.component===!0||de(n,r=>{t.set(r.id,n.id)});return t}function pl(e){let t=new Set;return de(e,n=>{t.add(n.id)}),t}function Io(e,t){let n=e.motion;if(!n)return[];let r=[],o=Ln(e),s=Ut(e),i=pl(e.root),a=(d,c)=>{let l=t?.(d,c);return l===void 0?"":`Line ${l}: `};for(let d of Ro(e)){let c=n[d];if(!c)continue;if(!o.has(d)){r.push({severity:"warning",code:"motion-not-a-page",message:`${a(d)}motion ${d}: ${d} is not a page (a top-level frame), so none of it plays`,nodeId:d});continue}let l=new Set;for(let p of c.lines){let m=a(d,p.id);for(let w of["after","with"]){let k=p[w];k!==void 0&&!l.has(k)&&r.push({severity:"warning",code:"motion-anchor-missing",message:`${m}motion ${d}: ${w}=${k} names no line above, so it starts after the line above instead`,nodeId:p.id})}p.camera!==!0&&l.add(p.id);let g=i.has(p.id)?z(e.root,p.id):void 0;g&&r.push(...W1(p,g,m,d)),i.has(p.id)?s.get(p.id)!==d&&r.push({severity:"warning",code:"motion-wrong-page",message:`${m}motion ${d}: ${p.id} is not on ${d}, so Play skips it`,nodeId:p.id}):r.push({severity:"warning",code:"unknown-reference",message:`${m}motion ${d}: no node ${p.id}`,nodeId:p.id});let b=p.go===void 0?void 0:On(p.go);b?.kind==="frame"&&!J1(e,b.id)&&r.push({severity:"warning",code:"unknown-reference",message:`${m}motion ${d}: go=#${b.id} names no frame`,nodeId:p.id})}}return r}function W1(e,t,n,r){let o=[],s=(a,d)=>{o.push({severity:"warning",code:a,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(ir(t.content)))&&s("count-no-number",`${t.id} has no number to count, so it fades in instead`),i==="draw"&&!Y1(t)&&s("draw-no-stroke",`${t.id} has no stroked vector to draw, so it fades in instead`),e.by!==void 0&&t.type!=="text"?s("by-not-text",`by=${e.by} splits text, and ${t.id} is a ${t.type}`):e.by!==void 0&&t.type==="text"&&X1(t)&&s("by-rotated",`${t.id} is rotated, so by=${e.by} enters it whole`),e.stagger!==void 0&&e.by===void 0&&te(t).length===0&&s("stagger-no-children",`${t.id} has no children to stagger: split a text with by=word`),o}function X1(e){let t=e.rotation;return t!==void 0&&t!==0}function Y1(e){let t=!1;return de(e,n=>((n.type==="vector"&&n.stroke!==void 0||n.type==="connector")&&(t=!0),t?!1:void 0)),t}function ir(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function J1(e,t){let n=!1;return de(e.root,r=>{if(n)return!1;r.id===t&&(n=r.type==="frame")}),n}function Rg(e,t){let n=t.motion;if(!n||!e.motion)return n;let r=Ut(e),o=Ut(t),s=pl(e.root),i=pl(t.root),a=p=>s.has(p)&&!i.has(p),d=!1,c={},l=[];for(let[p,m]of Object.entries(n)){if(a(p)){d=!0;continue}let g=[];for(let w of m.lines){let k=w,_=w.go===void 0?void 0:On(w.go);if(_?.kind==="frame"&&a(_.id)){let M=Q1(w);k=No(M)?M:void 0,d=!0}if(k&&(k.after!==void 0&&a(k.after)||k.with!==void 0&&a(k.with))&&(k=Z1(k,a),d=!0),k&&a(w.id))k=void 0,d=!0;else if(k&&r.get(w.id)===p&&o.get(w.id)!==p){let M=o.get(w.id);M!==void 0&&l.push([M,k]),k=void 0,d=!0}k&&g.push(k)}let b={...m,lines:g};Tn(b)||(c[p]=b)}for(let[p,m]of l){let g=c[p]??{lines:[]};c[p]={...g,lines:[...g.lines,m]}}return d?Object.keys(c).length===0?void 0:c:n}function Z1(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 Q1(e){let t={...e};return delete t.go,t}function hl(e,t){let n={...e};return t===void 0||Object.keys(t).length===0?delete n.motion:n.motion=t,n}function ml(e,t){let n=Rg(e,t);if(n===t.motion)return[];let r=new Set([...Object.keys(t.motion??{}),...Object.keys(n??{})]),o=[];for(let s of r){let i=n?.[s];Ha(t.motion?.[s],i)||o.push({op:"setMotion",page:s,value:i})}return o}var Ig={canvas:["type","id","name","w","h","background","children"],connector:["type","id","name","x1","y1","x2","y2","route","start","end","stroke","strokeWidth","dash","cap","opacity","blend","shadow","blur","hidden","locked"],frame:["type","id","name","x","y","w","h","background","stroke","strokeWidth","dash","strokeAlign","cap","radius","radiusTL","radiusTR","radiusBR","radiusBL","clip","skip","component","blend","shadow","blur","backdrop","hidden","locked","children"],ellipse:["type","id","name","x","y","w","h","rotation","fill","stroke","strokeWidth","dash","strokeAlign","cap","opacity","blend","shadow","blur","backdrop","hidden","locked"],group:["type","id","name","hidden","locked","children"],instance:["type","id","name","component","x","y","w","h","overrides","hidden","locked"],image:["type","id","name","x","y","w","h","rotation","src","fit","mask","stroke","strokeWidth","dash","strokeAlign","cap","radius","radiusTL","radiusTR","radiusBR","radiusBL","opacity","blend","shadow","blur","hidden","locked"],rect:["type","id","name","x","y","w","h","rotation","fill","stroke","strokeWidth","dash","strokeAlign","cap","radius","radiusTL","radiusTR","radiusBR","radiusBL","opacity","blend","shadow","blur","backdrop","hidden","locked"],text:["type","id","name","x","y","w","h","rotation","content","font","size","weight","lineHeight","letterSpacing","align","valign","italic","fill","stroke","strokeWidth","dash","opacity","blend","shadow","blur","hidden","locked"],vector:["type","id","name","x","y","w","h","rotation","view","d","fill","stroke","strokeWidth","dash","strokeAlign","opacity","rule","cap","join","blend","shadow","blur","backdrop","hidden","locked"],video:["type","id","name","x","y","w","h","rotation","src","fit","start","end","poster","muted","loop","mask","stroke","strokeWidth","dash","strokeAlign","cap","radius","radiusTL","radiusTR","radiusBR","radiusBL","opacity","blend","shadow","blur","hidden","locked"]},Fg=["text","font","size","weight","italic","underline","strike","fill","letterSpacing","link"],eS=["family","fallback","faces"],tS=["src","asset","weight","style"],Fe=" ";function xl(e){let t=["{",`${Fe}"version": ${K(Et(e))},`,`${Fe}"kind": ${JSON.stringify(e.kind)},`,...e.title===void 0?[]:[`${Fe}"title": ${JSON.stringify(e.title)},`],`${Fe}"tokens": ${rS(e.tokens,Fe)},`];return Object.keys(e.fonts).length>0&&t.push(`${Fe}"fonts": ${oS(e.fonts,Fe)},`),e.motion!==void 0&&t.push(`${Fe}"motion": ${nS(e,Fe)},`),e.brand!==void 0&&t.push(`${Fe}"brand": ${JSON.stringify(Or(e.brand))},`),e.themes?.dark!==void 0&&Object.keys(e.themes.dark).length>0&&t.push(`${Fe}"themes": ${JSON.stringify({dark:e.themes.dark})},`),t.push(`${Fe}"root": ${gl(e.root,Fe)}`,"}"),`${t.join(`
3
3
  `)}
4
- `}function Fs(e){return`${vd(e,"")}
5
- `}function rv(e,t){let n=t+Te,r=hr(e).map(o=>`${n}${JSON.stringify(o)}: ${JSON.stringify(e.motion?.[o])}`).join(`,
4
+ `}function Ua(e){return`${gl(e,"")}
5
+ `}function nS(e,t){let n=t+Fe,r=Ro(e).map(o=>`${n}${JSON.stringify(o)}: ${JSON.stringify(e.motion?.[o])}`).join(`,
6
6
  `);return r===""?"{}":`{
7
7
  ${r}
8
- ${t}}`}function ov(e,t){let n=Object.keys(e).sort();if(n.length===0)return"{}";let r=t+Te;return`{
9
- ${n.map(s=>`${r}${JSON.stringify(s)}: ${ko(e[s])}`).join(`,
8
+ ${t}}`}function rS(e,t){let n=Object.keys(e).sort();if(n.length===0)return"{}";let r=t+Fe;return`{
9
+ ${n.map(s=>`${r}${JSON.stringify(s)}: ${ii(e[s])}`).join(`,
10
10
  `)}
11
- ${t}}`}function sv(e,t){let n=Object.keys(e).sort();if(n.length===0)return"{}";let r=t+Te;return`{
12
- ${n.map(s=>`${r}${JSON.stringify(s)}: ${iv(e[s],r)}`).join(`,
11
+ ${t}}`}function oS(e,t){let n=Object.keys(e).sort();if(n.length===0)return"{}";let r=t+Fe;return`{
12
+ ${n.map(s=>`${r}${JSON.stringify(s)}: ${sS(e[s],r)}`).join(`,
13
13
  `)}
14
- ${t}}`}function iv(e,t){if(!e)return"{}";let n=t+Te,r=e,o=[];for(let s of tv){let i=r[s];if(i!==void 0){if(s==="faces"){o.push(`${n}"faces": ${av(i,n)}`);continue}o.push(`${n}${JSON.stringify(s)}: ${ko(i)}`)}}return`{
14
+ ${t}}`}function sS(e,t){if(!e)return"{}";let n=t+Fe,r=e,o=[];for(let s of eS){let i=r[s];if(i!==void 0){if(s==="faces"){o.push(`${n}"faces": ${iS(i,n)}`);continue}o.push(`${n}${JSON.stringify(s)}: ${ii(i)}`)}}return`{
15
15
  ${o.join(`,
16
16
  `)}
17
- ${t}}`}function av(e,t){if(e.length===0)return"[]";let n=t+Te;return`[
18
- ${e.map(o=>n+bd(o,nv)).join(`,
17
+ ${t}}`}function iS(e,t){if(e.length===0)return"[]";let n=t+Fe;return`[
18
+ ${e.map(o=>n+yl(o,tS)).join(`,
19
19
  `)}
20
- ${t}]`}function vd(e,t){let n=t+Te,r=e,o=[];for(let s of Ap[e.type]){let i=r[s];if(i!==void 0){if(s==="children"){o.push(`${n}"children": ${fv(i,n)}`);continue}if(s==="content"){o.push(`${n}"content": ${uv(i,n)}`);continue}if(s==="overrides"&&e.type==="instance"){o.push(`${n}"overrides": ${dv(e,n)}`);continue}o.push(`${n}${JSON.stringify(s)}: ${ko(i)}`)}}return`{
20
+ ${t}]`}function gl(e,t){let n=t+Fe,r=e,o=[];for(let s of Ig[e.type]){let i=r[s];if(i!==void 0){if(s==="children"){o.push(`${n}"children": ${cS(i,n)}`);continue}if(s==="content"){o.push(`${n}"content": ${uS(i,n)}`);continue}if(s==="overrides"&&e.type==="instance"){o.push(`${n}"overrides": ${aS(e,n)}`);continue}o.push(`${n}${JSON.stringify(s)}: ${ii(i)}`)}}return`{
21
21
  ${o.join(`,
22
22
  `)}
23
- ${t}}`}function dv(e,t){let n=lo(e,s=>Ap[s]);if(n.length===0)return"{}";let r=t+Te;return`{
24
- ${n.map(([s,i])=>{let d=i.map(([l,f])=>l==="content"?`${JSON.stringify(l)}: ${lv(f)}`:`${JSON.stringify(l)}: ${ko(f)}`).join(", ");return`${r}${JSON.stringify(s)}: { ${d} }`}).join(`,
23
+ ${t}}`}function aS(e,t){let n=qs(e,s=>Ig[s]);if(n.length===0)return"{}";let r=t+Fe;return`{
24
+ ${n.map(([s,i])=>{let a=i.map(([d,c])=>d==="content"?`${JSON.stringify(d)}: ${dS(c)}`:`${JSON.stringify(d)}: ${ii(c)}`).join(", ");return`${r}${JSON.stringify(s)}: { ${a} }`}).join(`,
25
25
  `)}
26
- ${t}}`}function lv(e){return typeof e=="string"?JSON.stringify(e):`[${e.map(n=>typeof n=="string"?JSON.stringify(n):bd(n,$p)).join(", ")}]`}function uv(e,t){if(typeof e=="string")return JSON.stringify(e);if(e.length===0)return"[]";let n=t+Te;return`[
27
- ${e.map(o=>typeof o=="string"?n+JSON.stringify(o):n+bd(o,$p)).join(`,
26
+ ${t}}`}function dS(e){return typeof e=="string"?JSON.stringify(e):`[${e.map(n=>typeof n=="string"?JSON.stringify(n):yl(n,Fg)).join(", ")}]`}function uS(e,t){if(typeof e=="string")return JSON.stringify(e);if(e.length===0)return"[]";let n=t+Fe;return`[
27
+ ${e.map(o=>typeof o=="string"?n+JSON.stringify(o):n+yl(o,Fg)).join(`,
28
28
  `)}
29
- ${t}]`}function bd(e,t){let n=[];for(let r of t){let o=e[r];o!==void 0&&n.push(`${JSON.stringify(r)}: ${ko(o)}`)}return`{ ${n.join(", ")} }`}function fv(e,t){if(e.length===0)return"[]";let n=t+Te;return`[
30
- ${e.map(o=>n+vd(o,n)).join(`,
29
+ ${t}]`}function yl(e,t){let n=[];for(let r of t){let o=e[r];o!==void 0&&n.push(`${JSON.stringify(r)}: ${ii(o)}`)}return`{ ${n.join(", ")} }`}function cS(e,t){if(e.length===0)return"[]";let n=t+Fe;return`[
30
+ ${e.map(o=>n+gl(o,n)).join(`,
31
31
  `)}
32
- ${t}]`}function ko(e){return ye(e)?JSON.stringify(`=${e.expr}`):typeof e=="number"?se(e):JSON.stringify(e)}function se(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 cv={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Eo(e){let t=[],n,r=0,o=0,s=0,i=0,d,l,f=pv(e),p=()=>(n||(n={anchors:[{x:r,y:o}],closed:!1},t.push(n)),n.anchors[n.anchors.length-1]),m=(S,g)=>{p(),n?.anchors.push({x:S,y:g}),r=S,o=g},y=(S,g,L,A)=>{p().out=S,n?.anchors.push({x:L,y:A,in:g}),r=L,o=A},v="",C=!0;for(;f.more();){let S=f.command();if(S!==void 0)v=S,C=!0;else if(v===""||v.toUpperCase()==="Z")return{contours:Bs(t),error:`Expected a command at ${f.at()}`};let g=v.toUpperCase(),L=v!==g,A=cv[g];if(A===void 0)return{contours:Bs(t),error:`Unknown command ${v}`};if(g==="Z"){n&&(n.closed=!0),n=void 0,r=s,o=i,d=void 0,l=void 0,v="";continue}let I=g==="A"?f.arc():f.numbers(A);if(I===void 0)return{contours:Bs(t),error:`${v} expects ${A} numbers at ${f.at()}`};let U=L?r:0,j=L?o:0,R=q=>I[q];switch(g){case"M":C&&(n={anchors:[{x:U+R(0),y:j+R(1)}],closed:!1},t.push(n),r=s=U+R(0),o=i=j+R(1),v=L?"l":"L"),d=l=void 0;break;case"L":m(U+R(0),j+R(1)),d=l=void 0;break;case"H":m(U+R(0),o),d=l=void 0;break;case"V":m(r,j+R(0)),d=l=void 0;break;case"C":{let q={x:U+R(2),y:j+R(3)};y({x:U+R(0),y:j+R(1)},q,U+R(4),j+R(5)),d=q,l=void 0;break}case"S":{let q=d?{x:2*r-d.x,y:2*o-d.y}:{x:r,y:o},$={x:U+R(0),y:j+R(1)};y(q,$,U+R(2),j+R(3)),d=$,l=void 0;break}case"Q":case"T":{let q=g==="Q"?{x:U+R(0),y:j+R(1)}:l?{x:2*r-l.x,y:2*o-l.y}:{x:r,y:o},$=g==="Q"?U+R(2):U+R(0),V=g==="Q"?j+R(3):j+R(1),b={x:r+2/3*(q.x-r),y:o+2/3*(q.y-o)},D={x:$+2/3*(q.x-$),y:V+2/3*(q.y-V)};y(b,D,$,V),l=q,d=void 0;break}case"A":{let q=U+R(5),$=j+R(6);for(let[V,b,D]of mv(r,o,R(0),R(1),R(2),R(3)!==0,R(4)!==0,q,$))y(V,b,D.x,D.y);(r!==q||o!==$)&&m(q,$),d=l=void 0;break}}C=!1}return{contours:Bs(t)}}function Bs(e){return e.map(t=>{let n=[...t.anchors];if(t.closed&&n.length>1){let r=n[0],o=n[n.length-1];Un(r,o)&&(n.pop(),n[0]={...r,...o.in?{in:o.in}:{}})}return{anchors:n.map(_o),closed:t.closed}})}function Dt(e,t,n){return _o({x:e.x,y:e.y,...t?{in:t}:{},...n?{out:n}:{}})}function _o(e){let t={x:e.x,y:e.y};return e.in&&!Un(e.in,e)&&(t.in=e.in),e.out&&!Un(e.out,e)&&(t.out=e.out),t}function Un(e,t,n=1e-6){return Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n}function pv(e){let t=0,n=()=>{for(;t<e.length&&/[\s,]/.test(e[t]);)t+=1},r=()=>{n();let s=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(t));if(s)return t+=s[0].length,Number(s[0])},o=()=>{n();let s=e[t];if(!(s!=="0"&&s!=="1"))return t+=1,Number(s)};return{more(){return n(),t<e.length},command(){n();let s=e[t];if(/[a-zA-Z]/.test(s))return t+=1,s},numbers(s){let i=[];for(let d=0;d<s;d+=1){let l=r();if(l===void 0)return;i.push(l)}return i},arc(){let s=this.numbers(3),i=o(),d=o(),l=this.numbers(2);if(!(!s||i===void 0||d===void 0||!l))return[...s,i,d,...l]},at(){return t}}}function mv(e,t,n,r,o,s,i,d,l){let f=Math.abs(n),p=Math.abs(r);if(f===0||p===0||e===d&&t===l)return[];let m=o*Math.PI/180,y=Math.cos(m),v=Math.sin(m),C=(e-d)/2,S=(t-l)/2,g=y*C+v*S,L=-v*C+y*S,A=g*g/(f*f)+L*L/(p*p);A>1&&(f*=Math.sqrt(A),p*=Math.sqrt(A));let I=f*f*p*p-f*f*L*L-p*p*g*g,U=f*f*L*L+p*p*g*g,j=(s===i?-1:1)*Math.sqrt(Math.max(0,I/U)),R=j*f*L/p,q=-j*p*g/f,$=y*R-v*q+(e+d)/2,V=v*R+y*q+(t+l)/2,b=(P,K,Z,z)=>{let ce=P*Z+K*z,Ee=Math.hypot(P,K)*Math.hypot(Z,z),Ae=Math.acos(Math.min(1,Math.max(-1,ce/Ee)));return P*z-K*Z<0?-Ae:Ae},D=b(1,0,(g-R)/f,(L-q)/p),T=b((g-R)/f,(L-q)/p,(-g-R)/f,(-L-q)/p);!i&&T>0&&(T-=2*Math.PI),i&&T<0&&(T+=2*Math.PI);let G=Math.max(1,Math.ceil(Math.abs(T)/(Math.PI/2)-1e-9)),Y=T/G,re=4/3*Math.tan(Y/4),E=P=>({x:$+f*Math.cos(P)*y-p*Math.sin(P)*v,y:V+f*Math.cos(P)*v+p*Math.sin(P)*y}),k=P=>({x:-f*Math.sin(P)*y-p*Math.cos(P)*v,y:-f*Math.sin(P)*v+p*Math.cos(P)*y}),O=[];for(let P=0;P<G;P+=1){let K=D+P*Y,Z=K+Y,z=E(K),ce=P===G-1?{x:d,y:l}:E(Z),Ee=k(K),Ae=k(Z);O.push([{x:z.x+re*Ee.x,y:z.y+re*Ee.y},{x:ce.x-re*Ae.x,y:ce.y-re*Ae.y},ce])}return O}function Gt(e){let t=[],n=r=>`${se(r.x)} ${se(r.y)}`;for(let r of e){let{anchors:o}=r,s=o[0];if(!s)continue;t.push(`M${n(s)}`);let i=gr(r);for(let d=0;d<i;d+=1){let l=o[d],f=o[(d+1)%o.length],p=r.closed&&d===o.length-1;!l.out&&!f.in?p||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 gr(e){let t=e.anchors.length;return t<2?0:e.closed?t:t-1}function yr(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 Op(e,t){let n=e.anchors[t],r=e.anchors[(t+1)%e.anchors.length];return!n.out&&!r.in}function So(e,t){let[n,r,o,s]=e,i=1-t,d=i*i*i,l=3*i*i*t,f=3*i*t*t,p=t*t*t;return{x:d*n.x+l*r.x+f*o.x+p*s.x,y:d*n.y+l*r.y+f*o.y+p*s.y}}function qt(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 Vn(e){let t=1/0,n=1/0,r=-1/0,o=-1/0,s=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 l of i.anchors)s(l);let d=gr(i);for(let l=0;l<d;l+=1){let f=yr(i,l);for(let p of hv(f))s(So(f,p))}}if(t!==1/0)return{x:t,y:n,w:r-t,h:o-n}}function hv(e){let[t,n,r,o]=e,s=[];for(let i of["x","y"]){let d=-t[i]+3*n[i]-3*r[i]+o[i],l=2*(t[i]-2*n[i]+r[i]),f=n[i]-t[i];if(Math.abs(d)<1e-12){Math.abs(l)>1e-12&&s.push(-f/l);continue}let p=l*l-4*d*f;if(p<0)continue;let m=Math.sqrt(p);s.push((-l+m)/(2*d),(-l-m)/(2*d))}return s.filter(i=>i>0&&i<1)}function Us(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,s]=t;return{x:n,y:r,w:o,h:s}}function zn(e){return[e.x,e.y,e.w,e.h].map(se).join(" ")}function Co(e,t,n){return Us(e)??{x:0,y:0,w:t,h:n}}function Mo(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 wd(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 kd(e,t=.5){let[n,r,o,s]=e;if(Un(n,r)&&Un(o,s))return[n,s];let d=Math.hypot(r.x-n.x,r.y-n.y)+Math.hypot(o.x-r.x,o.y-r.y)+Math.hypot(s.x-o.x,s.y-o.y),l=Math.min(256,Math.max(4,Math.ceil(Math.sqrt(d/t)))),f=[];for(let p=0;p<=l;p+=1)f.push(So(e,p/l));return f}function Vs(e){let t=0;for(let n of e)for(let r=0;r<gr(n);r+=1){let o=kd(yr(n,r),.25);for(let s=1;s<o.length;s+=1){let i=o[s-1],d=o[s];t+=Math.hypot(d.x-i.x,d.y-i.y)}}return t}function _d(e,t,n){let r=0,o=0;for(let s of e){let i=xv(s);if(i.length!==0){if(n.reach>0){let d=s.closed?i.length:i.length-1;for(let l=0;l<d;l+=1){let f=i[l],p=i[(l+1)%i.length];if(gv(t,f,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 d=0;d<i.length;d+=1){let l=i[d],f=i[(d+1)%i.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 xv(e){let t=e.anchors[0];if(!t)return[];let n=[{x:t.x,y:t.y}],r=gr(e);for(let o=0;o<r;o+=1)n.push(...kd(yr(e,o)).slice(1));return e.closed&&n.length>1&&n.pop(),n}function gv(e,t,n){let r=n.x-t.x,o=n.y-t.y,s=r*r+o*o,i=s===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*o)/s));return Math.hypot(e.x-(t.x+i*r),e.y-(t.y+i*o))}function Sd(e,t){let n;return e.forEach((r,o)=>{let s=gr(r);for(let i=0;i<s;i+=1){let d=yr(r,i),l=S=>{let g=So(d,S);return Math.hypot(g.x-t.x,g.y-t.y)},f=32,p=0;for(let S=1;S<=f;S+=1)l(S/f)<l(p)&&(p=S/f);let m=Math.max(0,p-1/f),y=Math.min(1,p+1/f);for(let S=0;S<24;S+=1){let g=m+(y-m)/3,L=y-(y-m)/3;l(g)<l(L)?y=L:m=g}let v=(m+y)/2,C=l(v);(!n||C<n.distance)&&(n={contour:o,segment:i,t:v,point:So(d,v),distance:C})}}),n}function Ed(e,t,n,r){return e.map((o,s)=>{if(s!==t)return o;let i=[...o.anchors],d=i.length,l=i[n],f=(n+1)%d,p=i[f];if(Op(o,n)){let R={x:l.x+(p.x-l.x)*r,y:l.y+(p.y-l.y)*r};return i.splice(n+1,0,R),{...o,anchors:i}}let[m,y,v,C]=yr(o,n),S=(R,q)=>({x:R.x+(q.x-R.x)*r,y:R.y+(q.y-R.y)*r}),g=S(m,y),L=S(y,v),A=S(v,C),I=S(g,L),U=S(L,A),j=S(I,U);return i[n]=_o({...l,out:g}),i[f]=_o({...p,in:A}),i.splice(n+1,0,_o({x:j.x,y:j.y,in:I,out:U})),{...o,anchors:i}})}var Hs=.5522847498;function Cd(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=Hs*r,s=[{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:yv(s)}]}function Md(e,t){let n=e/2,r=t/2,o=Hs*n,s=Hs*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-s},out:{x:e,y:r+s}},{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+s},out:{x:0,y:r-s}}]}]}function yv(e){let t=[];for(let o of e){let s=t[t.length-1];if(s&&Un(s,o)&&!s.out&&!o.in){t[t.length-1]=Dt(s,s.in,o.out);continue}t.push(o)}let n=t[0],r=t[t.length-1];return t.length>1&&n&&r&&Un(n,r)&&!r.out&&!n.in&&(t[0]=Dt(n,r.in,n.out),t.pop()),t}var tt=class extends Error{op;constructor(t,n){super(t),this.op=n,this.name="OpError"}};function _e(e,t){let n=e,r=[];for(let o of t){let s=Dp(n,o);n=s.document,r.push(s.inverse)}return r.reverse(),{document:n,inverse:r}}function Dp(e,t){let n=wv(e,t);if(!vv(e.root)&&!bv(t))return Ad.add(n.document.root),n;let r=Vt(n.document.root);return r===n.document.root?n:{document:{...n.document,root:r},inverse:n.inverse}}var Ad=new WeakSet;function vv(e){return Ad.has(e)?!1:uo(e)?!0:(Ad.add(e),!1)}function bv(e){if(e.op==="set")return e.prop==="component";if(e.op!=="insert")return!1;let t=!1;return oe(e.node,n=>((n.type==="instance"||n.type==="frame"&&n.component===!0)&&(t=!0),t?!1:void 0)),t}function wv(e,t){switch(t.op){case"set":{let n=At(e.root,t.id);if(n)return kv(e,t,n.instance.id,n.key);if(t.prop==="children"&&F(e.root,t.id)?.type==="instance")throw new tt(`${t.id}'s contents come from its component`,t);let r=F(e.root,t.id);if(!r)throw new tt(`No node ${t.id}`,t);let o=r[t.prop];return{document:Ao(e,Gs(e.root,t.id,s=>Pp(s,t.prop,t.value),t)),inverse:{op:"set",id:t.id,prop:t.prop,value:o}}}case"insert":{if(zs(e,t.parent,t,!0),F(e.root,t.node.id))throw new tt(`Duplicate id ${t.node.id}`,t);let n=js(e.root,t.parent,r=>{let o=Lp(t.index,0,r.length);return[...r.slice(0,o),t.node,...r.slice(o)]},t);return{document:Ao(e,n),inverse:{op:"remove",id:t.node.id}}}case"remove":{zs(e,t.id,t,!1);let n=Tp(e,t.id,t),r=js(e.root,n.parent.id,o=>o.filter(s=>s.id!==t.id),t);return{document:Ao(e,r),inverse:{op:"insert",parent:n.parent.id,index:n.index,node:n.node}}}case"move":{zs(e,t.id,t,!1),zs(e,t.parent,t,!0);let n=Tp(e,t.id,t),r=js(e.root,n.parent.id,s=>s.filter(i=>i.id!==t.id),t),o=js(r,t.parent,s=>{let i=Lp(t.index,0,s.length);return[...s.slice(0,i),n.node,...s.slice(i)]},t);return{document:Ao(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:Nn(t.value)};return{document:{...o,version:it(o)},inverse:{op:"setBrand",value:n}}}case"setTheme":{let{themes:n,...r}=e,o=Ot(t.value),s=o===void 0?r:{...r,themes:o};return{document:{...s,version:it(s)},inverse:{op:"setTheme",value:n}}}case"setKind":{let n={...e,kind:t.value};return{document:{...n,version:it(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 jt(t.value)?delete r[t.page]:r[t.page]=t.value,{document:xd(e,r),inverse:{op:"setMotion",page:t.page,value:n}}}}}function Ks(e,t){if(!e.motion||!t.some(r=>r.op==="remove"||r.op==="move"))return t;let n=gd(e,_e(e,t).document);return n.length===0?t:[...t,...n]}function kv(e,t,n,r){if(!mn(t.prop))throw new tt(`${t.id} is part of ${n}; its ${t.prop} comes from the component`,t);let o=F(e.root,n);if(o?.type!=="instance")throw new tt(`No instance ${n}`,t);let s=o.overrides?.[r]?.[t.prop],i=ed(o.overrides,r,t.prop,t.value,Qa(e.root,o,r,t.prop));return{document:Ao(e,Gs(e.root,n,d=>Pp(d,"overrides",i),t)),inverse:{op:"set",id:t.id,prop:t.prop,value:s}}}function zs(e,t,n,r){let o=At(e.root,t),s=r&&F(e.root,t)?.type==="instance";if(o)throw new tt(`${t} is inside ${o.instance.id} \u2014 change its component, or detach the instance first`,n);if(s)throw new tt(`${t} holds only copies of its component \u2014 change the component, or detach ${t} first`,n)}function Ao(e,t){if(t.type!=="canvas")throw new Error("The document root must stay a canvas");return{...e,root:t}}function Pp(e,t,n){let r={...e};return n===void 0?delete r[t]:r[t]=n,r}function Gs(e,t,n,r){if(e.id===t)return n(e);if(!fe(e))return e;let o=!1,s=e.children.map(i=>{let d=Gs(i,t,n,r);return d!==i&&(o=!0),d});return o?{...e,children:s}:e}function js(e,t,n,r){let o=F(e,t);if(!o)throw new tt(`No node ${t}`,r);if(!fe(o))throw new tt(`${t} cannot hold children`,r);return Gs(e,t,s=>({...s,children:n(s.children)}),r)}function Tp(e,t,n){if(t===e.root.id)throw new tt("The document root cannot be removed or moved",n);let r,o=s=>{fe(s)&&s.children.forEach((i,d)=>{i.id===t&&(r={node:i,parent:s,index:d}),o(i)})};if(o(e.root),!r)throw new tt(`No node ${t}`,n);return r}function Lp(e,t,n){return Math.min(Math.max(e,t),n)}function Od(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 s of vr(e.tokens,t.tokens)){let i=t.tokens[s];e.tokens[s]!==i&&n.push({op:"setToken",name:s,value:i})}for(let s of vr(e.fonts,t.fonts)){let i=t.fonts[s];Sv(e.fonts[s],i)||n.push({op:"setFont",name:s,family:i})}for(let s of vr(e.assets,t.assets)){let i=t.assets[s];(e.assets[s]?.hash!==i?.hash||e.assets[s]?.ms!==i?.ms)&&n.push({op:"setAsset",name:s,value:i})}if(!_v(e.root.children,t.root.children)){for(let s of e.root.children)n.push({op:"remove",id:s.id});t.root.children.forEach((s,i)=>{n.push({op:"insert",parent:e.root.id,index:i,node:s})})}for(let s of vr(e.motion??{},t.motion??{})){let i=t.motion?.[s];Rs(e.motion?.[s],i)||n.push({op:"setMotion",page:s,value:i})}Wa(e.brand,t.brand)||n.push({op:"setBrand",value:t.brand}),Ev(e.themes,t.themes)||n.push({op:"setTheme",value:t.themes});let r=e.root,o=t.root;for(let s of vr(r,o))s==="type"||s==="id"||s==="children"||Np(r[s],o[s])||n.push({op:"set",id:e.root.id,prop:s,value:o[s]});return n}function vr(e,t){return[...new Set([...Object.keys(e),...Object.keys(t)])]}function Np(e,t){return e===t?!0:ye(e)&&ye(t)&&e.expr===t.expr}function _v(e,t){return e.length===t.length&&e.every((n,r)=>$d(n,t[r]))}function $d(e,t){if(Np(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((s,i)=>$d(s,t[i]));let n=e,r=t;return vr(n,r).every(s=>$d(n[s],r[s]))}function Sv(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,s)=>{let i=r[s];return o.src===i.src&&o.asset===i.asset&&o.weight===i.weight&&o.style===i.style})}function Ev(e,t){let n=Ot(e)?.dark??{},r=Ot(t)?.dark??{},o=Object.keys(n);return o.length===Object.keys(r).length&&o.every(s=>n[s]===r[s])}var br={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"],["component","boolean"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],group:[["name","string"],["hidden","boolean"],["locked","boolean"]],instance:[["name","string"],["component","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["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"]]},$o=[["font","string"],["size","number"],["weight","number"],["italic","boolean"],["underline","boolean"],["strike","boolean"],["fill","string"],["letterSpacing","number"],["link","string"]],Td=[["weight","number"],["style","fontStyle"]],Oo=[["enter","pageEffect"],["duration","number"],["scroll","boolean"],["length","time"],["w","number"],["h","number"],["bpm","number"],["meter","number"]],jn=[["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"]],To=[["from","number"],["volume","number"],["fadein","time"],["fadeout","time"],["loop","boolean"]],Ld=Object.keys(br);function qs(e){return Ld.includes(e)}function Ws(e,t){return br[e].find(([n])=>n===t)?.[1]}function Xs(e){for(let t of Ld){if(t==="canvas"||t==="instance")continue;let n=Ws(t,e);if(n!==void 0)return n}}var Ys="override",ze=" ";function Be(e){if(ye(e))return/^[$@]/.test(e.expr)&&!/\s/.test(e.expr)?e.expr:`(${e.expr})`;if(typeof e=="number")return se(e);let t=String(e);return Cv(t)?JSON.stringify(t):t}function Cv(e){return e===""||/[\s"=()]/.test(e)||/^[$@]/.test(e)}function je(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=Pt(e);return r===void 0?{error:`Malformed quoted string ${e}`}:Ip(r,t,e)}if(Ov(e)){if(!Mv(t))return{error:Av(e,t)};let r=Hp(e).trim();return r===""?{error:"Empty expression"}:{value:kt(r)}}return t==="numberValue"&&Fp.test(e)?{value:kt(e)}:Ip(e,t,e)}var Fp=/^-?\d+(?:\.\d+)?%$/;function Mv(e){return e==="numberValue"||e==="stringValue"}function Av(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 Bp(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"?Fp.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 Ip(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}${Bp(e,t)}`}}case"align":return fn.includes(e)?{value:e}:{error:`Expected one of ${fn.join(", ")}, got ${n}`};case"valign":return cn.includes(e)?{value:e}:{error:`Expected one of ${cn.join(", ")}, got ${n}`};case"fontStyle":return e==="normal"||e==="italic"?{value:e}:{error:`Expected normal or italic, got ${n}`};case"imageFit":return pn.includes(e)?{value:e}:{error:`Expected one of ${pn.join(", ")}, got ${n}`};case"fillRule":return Wt(Ln,e,n);case"lineCap":return Wt(Dn,e,n);case"lineJoin":return Wt(Pn,e,n);case"blendMode":return Wt(Tn,e,n);case"pageEffect":return Wt(pr,e,n);case"nodeEffect":return Wt(go,e,n);case"emphasisEffect":return Wt(yo,e,n);case"ease":return Wt(vo,e,n);case"piece":return Wt(bo,e,n);case"time":{let r=Rn(e);if(r)return{value:Fn(r.count,r.unit)};let o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{value:o}:{error:`Expected milliseconds or beats, got ${n}${$v(e)}`}}case"on":return mo.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(yn.includes(e))return{value:e};let r=Number(e);return Number.isFinite(r)&&e.trim()!==""?{value:r}:{error:`Expected a number or one of ${yn.join(", ")}, got ${n}`}}default:return{value:e}}}function $v(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 ${Fn(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 ${Fn(Number(n[1]),r)} (counted from the start)`}return Bp(e,"number")}function Wt(e,t,n){return e.includes(t)?{value:t}:{error:`Expected one of ${e.join(", ")}, got ${n}`}}function Ov(e){return/^[$@(]/.test(e)}function Pt(e){try{let t=JSON.parse(e);return typeof t=="string"?t:void 0}catch{return}}function Hp(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 Up(e){let t=[],n="",r=0,o=!1;for(let s=0;s<e.length;s+=1){let i=e[s];if(o){n+=i,i==="\\"?(n+=e[s+1]??"",s+=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 Js(e,t,n){let r=n===void 0?void 0:Ke(n);if(r?.value===void 0||!Rp(e[t]??""))return;let o=t;for(;o<e.length&&Rp(e[o]??"");)o+=1;let s=[Hp(r.value),...e.slice(t,o)].join(" ");return{end:o,message:`${r.key}: an expression with spaces needs parentheses \u2014 write ${r.key}=(${s})`}}function Rp(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 Dd(e,t){let n,r=0,o,s=[],i=[],d={},l={},f={},p={},m=[],y=!1,v=!1,C,S=($,V,b)=>{t.push({severity:"warning",code:V,message:`Line ${$}: ${b}`})},g=($,V,b)=>{e($.number,"invalid-brand",`${V} ${b} is written twice \u2014 keep one`)},L=$=>{if(n){e($.number,"invalid-brand",`A document has one brand line; the first is on line ${r}`);return}let V=$.words[1]===void 0?void 0:Ga($.words[1]);if(!V){e($.number,"invalid-brand","Expected brand <slug>@<version>, e.g. brand ember@3 \u2014 a slug is lower case, digits and dashes");return}let b=$.words.slice(2).includes("strict"),D=Xt({...$,words:$.words.filter((G,Y)=>Y<2||G!=="strict")},2,["id","theme"],e),T=D.theme;T!==void 0&&!As.includes(T)&&e($.number,"invalid-brand",`theme= is light or dark, got ${T}`),n={...V,...D.id===void 0?{}:{id:D.id},...T==="dark"||T==="light"?{theme:T}:{},...b?{strict:!0}:{}},r=$.number,C={kind:"brand"}},A=$=>{let V=$.words[0];if(V==="summary"){let b=Zs($,1);b===void 0?e($.number,"invalid-brand",'Expected summary "\u2026"'):o=b;return}if(V==="change"){let b=Number($.words[1]),D=$.words[2]===void 0?void 0:zp($.words[2]);if(!Number.isSafeInteger(b)||b<1||D===void 0){e($.number,"invalid-brand",'Expected change <version> "<what changed>" at=<date>');return}let T=Xt($,3,["at"],e);s.push({version:b,note:D,...T.at===void 0?{}:{at:T.at}});return}if(V==="source"){let b=$.words[1];if(b===void 0||b.includes("=")){e($.number,"invalid-brand","Expected source <kind> key=value\u2026, e.g. source site url=\u2026");return}i.push({kind:b,props:Xt($,2,void 0,e)});return}if(V==="rule"){j($);return}if(V==="banned"){let b=Zs($,1);if(b===void 0){e($.number,"invalid-brand",'Expected banned "\u2026"');return}(p.voice??={entries:[]}).entries.push({kind:"banned",text:b});return}e($.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`)},I=$=>{let V=$.words[1];if(V===void 0||V.includes("=")){e($.number,"invalid-role","Expected role <name> light=<token or colour> dark=\u2026");return}let b=Xt($,2,["light","dark"],e),D=b.light;if(D===void 0){e($.number,"invalid-role",`role ${V} needs light=`);return}if(Object.prototype.hasOwnProperty.call(d,V))return g($,"role",V);let T=b.dark;d[V]={light:Vp(D),...T===void 0?{}:{dark:Vp(T)}}},U=$=>{let V=$.words[1];if(V===void 0||V.includes("=")){e($.number,"invalid-logo","Expected logo <id> asset=<name> min=<px> clear=<fraction>");return}let b=Xt($,2,["asset","min","clear"],e),D=b.asset;if(D===void 0){e($.number,"invalid-logo",`logo ${V} needs asset=`);return}let T={asset:D};for(let G of["min","clear"]){let Y=b[G];if(Y===void 0)continue;let re=Number(Y);if(!Number.isFinite(re)||re<0){e($.number,"invalid-logo",`logo ${V}: ${G} must be a number, got ${Y}`);continue}T[G]=re}if(Object.prototype.hasOwnProperty.call(l,V))return g($,"logo",V);l[V]=T},j=$=>{let V=$.words[1],b=$.words[2],D=$.words[3],T=D?.startsWith('"')===!0?Pt(D):void 0;if(V===void 0||V.includes("=")){e($.number,"invalid-rule",'Expected rule <id> must|should "<what it asks>" check=\u2026');return}if(b===void 0||!$s.includes(b)){e($.number,"invalid-rule",`rule ${V}: the second word is must or should`);return}if(T===void 0){e($.number,"invalid-rule",`rule ${V} needs its words, quoted: rule ${V} ${b} "\u2026"`);return}let{check:G,...Y}=Xt($,4,void 0,e);if(G!==void 0&&!Os.includes(G)&&S($.number,"unknown-check",`rule ${V}: this build has no check "${G}", so it is kept as words only \u2014 the checks are ${Os.join(", ")}`),Object.prototype.hasOwnProperty.call(f,V))return g($,"rule",V);f[V]={level:b,text:T,...G===void 0?{}:{check:G},...Object.keys(Y).length===0?{}:{params:Y}}},R=($,V)=>{let b=$.words[0];if(b.startsWith('"')){let D=Zs($,0);D===void 0?e($.number,"invalid-guide",`Could not read ${$.text}`):V.push({kind:"line",text:D});return}if(b==="banned"||b==="avoid"){let D=Zs($,1);D===void 0?e($.number,"invalid-guide",`Expected ${b} "\u2026"`):V.push({kind:b,text:D});return}if(b==="rewrite"){let D=Xt($,1,["from","to"],e),T=D.from,G=D.to;if(T===void 0||G===void 0){e($.number,"invalid-guide",'Expected rewrite from="\u2026" to="\u2026"');return}V.push({kind:"rewrite",from:T,to:G});return}if(b==="ref"||b==="approved"||b==="rejected"){let D=Xt($,1,["asset","note"],e),T=D.asset;if(T===void 0){e($.number,"invalid-guide",`Expected ${b} asset=<name> note="\u2026"`);return}let G=D.note;V.push({kind:b,asset:T,...G===void 0?{}:{note:G}});return}e($.number,"invalid-guide",`"${b}" is not a guide line \u2014 a guide holds quoted lines, banned, avoid, rewrite, ref, approved and rejected`)},q=$=>{let V=$.words[0];if(V.includes("=")||V.startsWith('"')){e($.number,"invalid-review",'Expected <what>.<id> from=\u2026 note="\u2026", e.g. role.muted from=site');return}let b=Xt($,1,["from","note"],e);m.push({target:V,...b.from===void 0?{}:{from:b.from},...b.note===void 0?{}:{note:b.note}})};return{take($){if($.indent>0)return C?(C.kind==="brand"?A($):C.kind==="guide"?R($,C.entries):q($),!0):!1;C=void 0;let V=$.words[0];if(V!=="brand"&&!Ts(V))return!1;switch(v=!0,V){case"brand":L($);break;case"role":I($);break;case"logo":U($);break;case"rule":j($);break;case"guide":{let b=$.words[1];if(b===void 0||b.includes("=")||$.words.length>2){e($.number,"invalid-guide","Expected guide <id> on its own line, e.g. guide voice"),C={kind:"guide",id:"",entries:[]};break}if(Object.prototype.hasOwnProperty.call(p,b)){g($,"guide",b),C={kind:"guide",id:"",entries:[]};break}let D=[];p[b]={entries:D},C={kind:"guide",id:b,entries:D};break}case"review":$.words.length>1&&e($.number,"invalid-review","review is a block: its items go on the lines under it"),y=!0,C={kind:"review"};break}return!0},finish(){if(!v)return{header:!1,review:!1};let $=n??Ls();return{brand:{slug:$.slug,version:$.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:s,sources:i,roles:d,logos:l,rules:f,guides:p,review:m},header:n!==void 0,review:y}}}}function Xt(e,t,n,r){let o={};for(let s of e.words.slice(t)){let{key:i,value:d}=Ke(s);if(d===void 0){r(e.number,"invalid-brand",`A stray word "${s}" \u2014 expected key=value`);continue}if(n!==void 0&&!n.includes(i)){r(e.number,"invalid-brand",`"${i}" is not allowed here; this line takes ${n.join(", ")}`);continue}o[i]=zp(d)}return o}function Zs(e,t){if(e.words.length!==t+1)return;let n=e.words[t];return n.startsWith('"')?Pt(n):void 0}function zp(e){return e.startsWith('"')?Pt(e)??e:e}function Vp(e){return e.startsWith("$")?e.slice(1):e}function jp(e,t,n="brand"){if(!t||t.slug==="")return;let r=["brand",qa(t)];t.id!==void 0&&r.push(`id=${Be(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(`${ze}summary ${JSON.stringify(t.summary)}`);for(let o of t.changes){let s=["change",se(o.version),JSON.stringify(o.note)];o.at!==void 0&&s.push(`at=${Be(o.at)}`),e.push(ze+s.join(" "))}for(let o of t.sources)e.push(ze+["source",o.kind,...wr(o.props)].join(" "));if(n==="design"){for(let o of Kp(t))e.push(ze+o);for(let o of Tv(t))e.push(`${ze}banned ${JSON.stringify(o)}`)}e.push("")}function Kp(e){return Object.entries(e.rules).map(([t,n])=>["rule",t,n.level,JSON.stringify(n.text),...wr({check:n.check,...n.params})].join(" "))}function Tv(e){return(e.guides.voice?.entries??[]).flatMap(t=>t.kind==="banned"?[t.text]:[])}function Gp(e,t,n="brand"){if(!t)return;let r=n==="design",o=s=>{s.length!==0&&e.push(...s,"")};o(Object.entries(t.roles).map(([s,i])=>["role",s,...wr({light:i.light,dark:i.dark})].join(" "))),o(Object.entries(t.logos).map(([s,i])=>["logo",s,...wr({asset:i.asset,min:i.min===void 0?void 0:se(i.min),clear:i.clear===void 0?void 0:se(i.clear)})].join(" "))),r||o(Kp(t));for(let[s,i]of Object.entries(t.guides)){let d=r&&s==="voice"?i.entries.filter(l=>l.kind!=="banned"):i.entries;if(!(r&&d.length===0)){e.push(`guide ${s}`);for(let l of d)e.push(ze+Lv(l));e.push("")}}if(t.review.length>0){e.push("review");for(let s of t.review)e.push(ze+[s.target,...wr({from:s.from,note:s.note})].join(" "));e.push("")}}function Lv(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,...wr({asset:e.asset,note:e.note})].join(" ")}}function wr(e){let t=[];for(let[n,r]of Object.entries(e))r!==void 0&&t.push(`${n}=${Be(r)}`);return t}var Dv=new Set(["exit","delay","step","together","go","at","after","with"]),Wp=["at","after","with","together","step"],Pv=new Set(["pad","duration","delay","ease","on",...Wp]);function Pd(e){if(e==="at"||e==="length")return vn;if(e==="w"||e==="h")return Lt;if(e==="duration"||e==="delay"||e==="stagger"||e==="hold")return Tt;if(e==="pad")return Lt}function Nd(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 s of e.words.slice(2)){let{key:i,value:d}=Ke(s),l=Oo.find(([p])=>p===i)?.[1];if(l===void 0){let p=Dv.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 f=je(d??"",l);"error"in f?t(e.number,"invalid-motion",`${i}: ${Uv(i,d)??f.error}`,n):i==="bpm"&&!Bv(f.value)?t(e.number,"invalid-motion",`bpm: expected ${20} to ${300} beats a minute, got ${d??""}`,n):i==="meter"&&!Hv(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[i]=f.value)}let o=St({...r,lines:[]});for(let[s]of Oo){let i=r[s];if(i===void 0||Pd(s)===void 0)continue;let d=Fd(s,i,o,n);d!==void 0&&(t(e.number,"invalid-motion",d,n),delete r[s])}return{page:n,number:e.number,head:r,lines:[],where:new Map,taken:new Map,numbers:[]}}function Id(e,t,n){if(t.words[0]==="music"&&!(t.words[1]??"").includes("=")){Iv(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,s=o[0];if(t.indent!==1){n(t.number,"invalid-motion","A motion line sits one level under its page");return}if(s.includes("=")){n(t.number,"invalid-motion",`Expected a node id first, got ${s}`);return}if(s===e.page&&!r){n(t.number,"invalid-motion",`${s} is the page: its transition goes on the header (motion ${s} enter=fade)`,s);return}let i=r?{id:s,camera:!0}:{id:s},d=!0;for(let p of o.slice(1)){let{key:m,value:y}=Ke(p),v=jn.find(([g])=>g===m)?.[1];if(v===void 0){n(t.number,"invalid-motion",`A motion line has no "${m}"${Vv(m)}`,s),d=!1;continue}if(r&&!Pv.has(m)){n(t.number,"invalid-motion",`A camera line moves the shot and says only pad=, duration=, delay=, ease= and when: not ${m}=`,s),d=!1;continue}let C=je(y??"",v),S="error"in C||Pd(m)===void 0?void 0:Fd(m,C.value,St(Yp(e)),e.page);"error"in C?(n(t.number,"invalid-motion",`${m}: ${C.error}`,s),d=!1):S!==void 0?(n(t.number,"invalid-motion",`${s}: ${S}`,s),d=!1):m==="on"&&e.head.bpm===void 0?(n(t.number,"invalid-motion",`${s}: on=${String(C.value)} needs a tempo \u2014 motion ${e.page} bpm=120`,s),d=!1):m==="go"&&zt(C.value)===void 0?(n(t.number,"invalid-motion",`go: expected #<page>, back, next, or an https: or mailto: link, got ${y??""}`,s),d=!1):C.value!==!1&&(i[m]=C.value)}i.enter!==void 0&&i.exit!==void 0&&(n(t.number,"invalid-motion",`${s} either enters or exits on one line \u2014 write a second line for the other`,s),d=!1),i.emphasis!==void 0&&(i.enter!==void 0||i.exit!==void 0)&&(n(t.number,"invalid-motion",`${s} either ${i.enter!==void 0?"enters":"exits"} or is stressed on one line \u2014 write a second line for emphasis=`,s),d=!1);let l=Wp.filter(p=>i[p]!==void 0);if(i.step===!0&&i.together===!0?(n(t.number,"invalid-motion",`${s} waits for a step or starts together with the line above, not both`,s),d=!1):l.length>1?(n(t.number,"invalid-motion",`${s} says when it starts twice (${l.join(", ")}): keep one`,s),d=!1):i.on!==void 0&&(i.with!==void 0||i.together===!0)&&(n(t.number,"invalid-motion",`${s} starts with another line (${i.with===void 0?"together":"with="}), so on= could only pull it apart: keep one`,s),d=!1),d){let p=zv(i);p!==void 0&&(n(t.number,"invalid-motion",`${s}: ${p}`,s),d=!1)}if(!d)return;let f=Fv(i);if(!mr(f)){n(t.number,"invalid-motion",`${s} says nothing: give it enter=, exit=, emphasis= or go=`,s);return}if(r){e.where.has(s)||e.where.set(s,t.number),e.lines.push(f),e.numbers.push(t.number);return}for(let p of["enter","exit","emphasis","go"]){if(f[p]===void 0)continue;let m=e.taken.get(`${s} ${p}`);if(m!==void 0){let y=p==="go"?"has a go=":p==="enter"?"enters":p==="exit"?"exits":"has an emphasis=";n(t.number,"invalid-motion",`${s} already ${y} on line ${m}`,s);return}}for(let p of["enter","exit","emphasis","go"])f[p]!==void 0&&e.taken.set(`${s} ${p}`,t.number);e.where.has(s)||e.where.set(s,t.number),e.lines.push(f),e.numbers.push(t.number)}function Rd(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 jt(t)?void 0:t}function Xp(e,t){let n=t.motion;if(n)for(let r of hr(t)){let o=n[r];if(o===void 0||jt(o))continue;e.at(-1)!==""&&e.push("");let s=["motion",r];for(let[i,d]of Oo){let l=o[i];if(l!==void 0){if(d==="boolean"){l===!0&&s.push(i);continue}s.push(`${i}=${Be(l)}`)}}if(e.push(s.join(" ")),o.music){let i=["music",o.music.asset];for(let[d,l]of To){let f=o.music[d];if(f!==void 0){if(l==="boolean"){f===!0&&i.push(d);continue}i.push(`${d}=${Be(f)}`)}}e.push(ze+i.join(" "))}for(let i of o.lines){let d=i.camera===!0?["camera",i.id]:[i.id];for(let[l,f]of jn){let p=i[l];if(p!==void 0){if(f==="boolean"){p===!0&&d.push(l);continue}d.push(`${l}=${Be(p)}`)}}e.push(ze+d.join(" "))}}}var Nv=new Set(["loop","step","together"]);function Iv(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(Nv.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},s=St(Yp(e)),i=!0,d=f=>{n(t.number,"invalid-motion",`music ${r}: ${f}`),i=!1};for(let f of t.words.slice(2)){let{key:p,value:m}=Ke(f),y=To.find(([C])=>C===p)?.[1];if(y===void 0){d(`the music line has no "${p}"${Rv(p)}`);continue}if(p==="from"&&m!==void 0&&/\d(?:beats?|bars?)$/.test(m)){d(`from= is where in the track to begin, in milliseconds, not ${m}`);continue}let v=je(m??"",y);if("error"in v){d(`${p}: ${v.error}`);continue}if(p==="from"&&!qp(v.value,0,fr)){d(`from: expected 0 to ${fr} milliseconds, got ${m??""}`);continue}if(p==="volume"&&!qp(v.value,0,1)){d(`volume: expected 0 to 1, got ${m??""}`);continue}if(p==="fadein"||p==="fadeout"){let C=Fd(p,v.value,s,e.page);if(C!==void 0){d(C);continue}}v.value!==!1&&(o[p]=v.value)}if(!i)return;let l={asset:r};for(let[f]of To)o[f]!==void 0&&(l[f]=o[f]);e.music=l,e.musicLine=t.number}function qp(e,t,n){return typeof e=="number"&&e>=t&&e<=n}function Rv(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 Fv(e){let t=e.camera===!0?{id:e.id,camera:!0}:{id:e.id};for(let[n]of jn)e[n]!==void 0&&(t[n]=e[n]);return t}function Yp(e){let{bpm:t,meter:n}=e.head;return{...t===void 0?{}:{bpm:t},...n===void 0?{}:{meter:n},lines:[]}}function Fd(e,t,n,r){if(Bn(t)&&!n)return`${t} needs a tempo \u2014 motion ${r} bpm=120`;let o=typeof t=="number"||Bn(t)?Je(t,n):void 0,s=Pd(e)??Tt;if(o!==void 0&&o>=(e==="w"||e==="h"?16:0)&&o<=s)return;let d=String(t),l=Bn(t)&&o!==void 0?` (${Math.round(o)} ms)`:"";return e==="w"||e==="h"?`${e}: expected 16 to ${Lt} pixels, got ${d}`:e==="pad"?`pad: expected 0 to ${Lt}, got ${d}`:`${e}: expected 0 to ${s} milliseconds, got ${d}${l}`}function Bv(e){return typeof e=="number"&&e>=20&&e<=300}function Hv(e){return typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=16}function Uv(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 Vv(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 zv(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: ${yn.join(", ")}`}else return"from= goes with count (a number), or wipe and grow (a side)";if(e.by!==void 0&&r!==void 0&&!cr.includes(r))return`by= splits a text for ${cr.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 jv=24;function Hd(e,t={}){let n=[`version ${se(it(e))}`,`kind ${e.kind}`];e.title!==void 0&&n.push(`title ${JSON.stringify(e.title)}`),jp(n,e.brand,e.kind);for(let[o,s]of Object.entries(e.tokens))n.push(`$${o} = ${Be(s)}`);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,s]of Object.entries(r))n.push(` $${o} = ${Be(s)}`);n.push("")}for(let[o,s]of Object.entries(e.fonts))qv(n,o,s,t),n.push("");if(Object.keys(e.assets).length>0){for(let[o,s]of Object.entries(e.assets))n.push(Gv(o,s));n.push("")}return Gp(n,e.brand,e.kind),Kv(e.root)?e.root.children.forEach((o,s)=>{s>0&&n.push(""),Bd(n,o,0)}):Bd(n,e.root,0),Xp(n,e),n.join(`
33
- `)}function Kv(e){return e.id===$t&&e.w===void 0&&e.h===void 0&&e.background===void 0&&e.name===void 0}function Gv(e,t){let n=[`asset ${e} = ${t.type}`,`hash=${t.hash}`,`bytes=${se(t.bytes)}`];t.ms!==void 0&&n.push(`ms=${se(t.ms)}`);for(let r of["credit","source","license"]){let o=t[r];o!==void 0&&n.push(`${r}=${Be(o)}`)}return n.join(" ")}function qv(e,t,n,r){e.push(`font ${t} = ${Be(n.family)}`),n.fallback!==void 0&&e.push(`${ze}fallback ${Be(n.fallback)}`);for(let o of n.faces??[]){let s=o.asset!==void 0?[`face asset=${o.asset}`]:[`face ${Be(r.abbreviateFaces?Wv(o.src??""):o.src??"")}`];for(let[i]of Td){let d=o[i];d!==void 0&&s.push(`${i}=${Be(d)}`)}e.push(ze+s.join(" "))}}function Wv(e){return e.startsWith("data:")?`${e.slice(0,jv)}\u2026 ${se(Math.round(e.length/1024))} kB`:e}function Bd(e,t,n){let r=ze.repeat(n),o=t,s=[t.type,t.id];for(let[i,d]of br[t.type]){let l=o[i];if(l!==void 0){if(d==="boolean"){l===!0&&s.push(i);continue}s.push(`${i}=${Be(l)}`)}}if(e.push(r+s.join(" ")),t.type==="text"&&Jp(e,t.content,n+1),t.type==="instance"){Xv(e,t,n+1);return}if(fe(t))for(let i of ne(t))Bd(e,i,n+1)}function Xv(e,t,n){let r=ze.repeat(n),o=s=>br[s].map(([i])=>i);for(let[s,i]of lo(t,o)){let d=[Ys,s];for(let[f,p]of i)f!=="content"&&(typeof p=="boolean"?d.push(p?f:`${f}=false`):d.push(`${f}=${Be(p)}`));e.push(r+d.join(" "));let l=i.find(([f])=>f==="content")?.[1];l!==void 0&&Jp(e,l,n+1)}}function Jp(e,t,n){let r=ze.repeat(n),o=typeof t=="string"?[t]:t;for(let s of o){if(typeof s=="string"){e.push(r+JSON.stringify(s));continue}e.push(r+[JSON.stringify(s.text),...Yv(s)].join(" "))}}function Yv(e){let t=[];for(let[n,r]of $o){let o=e[n];if(o!==void 0){if(r==="boolean"){o===!0&&t.push(n);continue}t.push(`${n}=${Be(o)}`)}}return t}var Kn="--- payload base64 ---",Zp="sha256-";function Qp(e){let t=Jv(e);return t===-1?{head:e,payload:""}:{head:e.slice(0,t),payload:e.slice(t+Kn.length)}}function Ud(e){let{head:t,payload:n}=Qp(e);return{head:t,blocks:em(n)}}function Vd(e,t){let n=new Map;for(let r of Zv(e)){let o=t.get(r);o!==void 0&&n.set(r,o)}return n.size===0?e:`${e.trimEnd()}
32
+ ${t}]`}function ii(e){return ve(e)?JSON.stringify(`=${e.expr}`):typeof e=="number"?K(e):JSON.stringify(e)}function K(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 lS={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function ar(e){let t=[],n,r=0,o=0,s=0,i=0,a,d,c=fS(e),l=()=>(n||(n={anchors:[{x:r,y:o}],closed:!1},t.push(n)),n.anchors[n.anchors.length-1]),p=(w,k)=>{l(),n?.anchors.push({x:w,y:k}),r=w,o=k},m=(w,k,_,M)=>{l().out=w,n?.anchors.push({x:_,y:M,in:k}),r=_,o=M},g="",b=!0;for(;c.more();){let w=c.command();if(w!==void 0)g=w,b=!0;else if(g===""||g.toUpperCase()==="Z")return{contours:za(t),error:`Expected a command at ${c.at()}`};let k=g.toUpperCase(),_=g!==k,M=lS[k];if(M===void 0)return{contours:za(t),error:`Unknown command ${g}`};if(k==="Z"){n&&(n.closed=!0),n=void 0,r=s,o=i,a=void 0,d=void 0,g="";continue}let R=k==="A"?c.arc():c.numbers(M);if(R===void 0)return{contours:za(t),error:`${g} expects ${M} numbers at ${c.at()}`};let B=_?r:0,D=_?o:0,V=T=>R[T];switch(k){case"M":b&&(n={anchors:[{x:B+V(0),y:D+V(1)}],closed:!1},t.push(n),r=s=B+V(0),o=i=D+V(1),g=_?"l":"L"),a=d=void 0;break;case"L":p(B+V(0),D+V(1)),a=d=void 0;break;case"H":p(B+V(0),o),a=d=void 0;break;case"V":p(r,D+V(0)),a=d=void 0;break;case"C":{let T={x:B+V(2),y:D+V(3)};m({x:B+V(0),y:D+V(1)},T,B+V(4),D+V(5)),a=T,d=void 0;break}case"S":{let T=a?{x:2*r-a.x,y:2*o-a.y}:{x:r,y:o},O={x:B+V(0),y:D+V(1)};m(T,O,B+V(2),D+V(3)),a=O,d=void 0;break}case"Q":case"T":{let T=k==="Q"?{x:B+V(0),y:D+V(1)}:d?{x:2*r-d.x,y:2*o-d.y}:{x:r,y:o},O=k==="Q"?B+V(2):B+V(0),j=k==="Q"?D+V(3):D+V(1),$={x:r+2/3*(T.x-r),y:o+2/3*(T.y-o)},P={x:O+2/3*(T.x-O),y:j+2/3*(T.y-j)};m($,P,O,j),d=T,a=void 0;break}case"A":{let T=B+V(5),O=D+V(6);for(let[j,$,P]of pS(r,o,V(0),V(1),V(2),V(3)!==0,V(4)!==0,T,O))m(j,$,P.x,P.y);(r!==T||o!==O)&&p(T,O),a=d=void 0;break}}b=!1}return{contours:za(t)}}function za(e){return e.map(t=>{let n=[...t.anchors];if(t.closed&&n.length>1){let r=n[0],o=n[n.length-1];Rr(r,o)&&(n.pop(),n[0]={...r,...o.in?{in:o.in}:{}})}return{anchors:n.map(ai),closed:t.closed}})}function fn(e,t,n){return ai({x:e.x,y:e.y,...t?{in:t}:{},...n?{out:n}:{}})}function ai(e){let t={x:e.x,y:e.y};return e.in&&!Rr(e.in,e)&&(t.in=e.in),e.out&&!Rr(e.out,e)&&(t.out=e.out),t}function Rr(e,t,n=1e-6){return Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n}function fS(e){let t=0,n=()=>{for(;t<e.length&&/[\s,]/.test(e[t]);)t+=1},r=()=>{n();let s=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(t));if(s)return t+=s[0].length,Number(s[0])},o=()=>{n();let s=e[t];if(!(s!=="0"&&s!=="1"))return t+=1,Number(s)};return{more(){return n(),t<e.length},command(){n();let s=e[t];if(/[a-zA-Z]/.test(s))return t+=1,s},numbers(s){let i=[];for(let a=0;a<s;a+=1){let d=r();if(d===void 0)return;i.push(d)}return i},arc(){let s=this.numbers(3),i=o(),a=o(),d=this.numbers(2);if(!(!s||i===void 0||a===void 0||!d))return[...s,i,a,...d]},at(){return t}}}function pS(e,t,n,r,o,s,i,a,d){let c=Math.abs(n),l=Math.abs(r);if(c===0||l===0||e===a&&t===d)return[];let p=o*Math.PI/180,m=Math.cos(p),g=Math.sin(p),b=(e-a)/2,w=(t-d)/2,k=m*b+g*w,_=-g*b+m*w,M=k*k/(c*c)+_*_/(l*l);M>1&&(c*=Math.sqrt(M),l*=Math.sqrt(M));let R=c*c*l*l-c*c*_*_-l*l*k*k,B=c*c*_*_+l*l*k*k,D=(s===i?-1:1)*Math.sqrt(Math.max(0,R/B)),V=D*c*_/l,T=-D*l*k/c,O=m*V-g*T+(e+a)/2,j=g*V+m*T+(t+d)/2,$=(v,N,I,F)=>{let q=v*I+N*F,Y=Math.hypot(v,N)*Math.hypot(I,F),Q=Math.acos(Math.min(1,Math.max(-1,q/Y)));return v*F-N*I<0?-Q:Q},P=$(1,0,(k-V)/c,(_-T)/l),C=$((k-V)/c,(_-T)/l,(-k-V)/c,(-_-T)/l);!i&&C>0&&(C-=2*Math.PI),i&&C<0&&(C+=2*Math.PI);let G=Math.max(1,Math.ceil(Math.abs(C)/(Math.PI/2)-1e-9)),ee=C/G,fe=4/3*Math.tan(ee/4),oe=v=>({x:O+c*Math.cos(v)*m-l*Math.sin(v)*g,y:j+c*Math.cos(v)*g+l*Math.sin(v)*m}),Se=v=>({x:-c*Math.sin(v)*m-l*Math.cos(v)*g,y:-c*Math.sin(v)*g+l*Math.cos(v)*m}),be=[];for(let v=0;v<G;v+=1){let N=P+v*ee,I=N+ee,F=oe(N),q=v===G-1?{x:a,y:d}:oe(I),Y=Se(N),Q=Se(I);be.push([{x:F.x+fe*Y.x,y:F.y+fe*Y.y},{x:q.x-fe*Q.x,y:q.y-fe*Q.y},q])}return be}function ze(e){let t=[],n=r=>`${K(r.x)} ${K(r.y)}`;for(let r of e){let{anchors:o}=r,s=o[0];if(!s)continue;t.push(`M${n(s)}`);let i=zt(r);for(let a=0;a<i;a+=1){let d=o[a],c=o[(a+1)%o.length],l=r.closed&&a===o.length-1;!d.out&&!c.in?l||t.push(`L${n(c)}`):t.push(`C${n(d.out??d)} ${n(c.in??c)} ${n(c)}`)}r.closed&&t.push("Z")}return t.join(" ")}function zt(e){let t=e.anchors.length;return t<2?0:e.closed?t:t-1}function jt(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 ja(e,t){let n=e.anchors[t],r=e.anchors[(t+1)%e.anchors.length];return!n.out&&!r.in}function di(e,t){let[n,r,o,s]=e,i=1-t,a=i*i*i,d=3*i*i*t,c=3*i*t*t,l=t*t*t;return{x:a*n.x+d*r.x+c*o.x+l*s.x,y:a*n.y+d*r.y+c*o.y+l*s.y}}function Be(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 Kt(e){let t=1/0,n=1/0,r=-1/0,o=-1/0,s=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)s(d);let a=zt(i);for(let d=0;d<a;d+=1){let c=jt(i,d);for(let l of hS(c))s(di(c,l))}}if(t!==1/0)return{x:t,y:n,w:r-t,h:o-n}}function hS(e){let[t,n,r,o]=e,s=[];for(let i of["x","y"]){let a=-t[i]+3*n[i]-3*r[i]+o[i],d=2*(t[i]-2*n[i]+r[i]),c=n[i]-t[i];if(Math.abs(a)<1e-12){Math.abs(d)>1e-12&&s.push(-c/d);continue}let l=d*d-4*a*c;if(l<0)continue;let p=Math.sqrt(l);s.push((-d+p)/(2*a),(-d-p)/(2*a))}return s.filter(i=>i>0&&i<1)}function Ka(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,s]=t;return{x:n,y:r,w:o,h:s}}function Pn(e){return[e.x,e.y,e.w,e.h].map(K).join(" ")}function Ir(e,t,n){return Ka(e)??{x:0,y:0,w:t,h:n}}function Fr(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 bl(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 dr(e,t=.5){let[n,r,o,s]=e;if(Rr(n,r)&&Rr(o,s))return[n,s];let a=Math.hypot(r.x-n.x,r.y-n.y)+Math.hypot(o.x-r.x,o.y-r.y)+Math.hypot(s.x-o.x,s.y-o.y),d=Math.min(256,Math.max(4,Math.ceil(Math.sqrt(a/t)))),c=[];for(let l=0;l<=d;l+=1)c.push(di(e,l/d));return c}function ui(e){let t=0;for(let n of e)for(let r=0;r<zt(n);r+=1){let o=dr(jt(n,r),.25);for(let s=1;s<o.length;s+=1){let i=o[s-1],a=o[s];t+=Math.hypot(a.x-i.x,a.y-i.y)}}return t}function Br(e,t,n){let r=0,o=0;for(let s of e){let i=mS(s);if(i.length!==0){if(n.reach>0){let a=s.closed?i.length:i.length-1;for(let d=0;d<a;d+=1){let c=i[d],l=i[(d+1)%i.length];if(xS(t,c,l)<=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 a=0;a<i.length;a+=1){let d=i[a],c=i[(a+1)%i.length];d.y<=t.y!=c.y<=t.y&&d.x+(t.y-d.y)/(c.y-d.y)*(c.x-d.x)>t.x&&(o+=1,r+=c.y>d.y?1:-1)}}}return n.fill?n.rule==="evenodd"?o%2===1:r!==0:!1}function mS(e){let t=e.anchors[0];if(!t)return[];let n=[{x:t.x,y:t.y}],r=zt(e);for(let o=0;o<r;o+=1)n.push(...dr(jt(e,o)).slice(1));return e.closed&&n.length>1&&n.pop(),n}function xS(e,t,n){let r=n.x-t.x,o=n.y-t.y,s=r*r+o*o,i=s===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*o)/s));return Math.hypot(e.x-(t.x+i*r),e.y-(t.y+i*o))}function vl(e,t){let n;return e.forEach((r,o)=>{let s=zt(r);for(let i=0;i<s;i+=1){let a=jt(r,i),d=w=>{let k=di(a,w);return Math.hypot(k.x-t.x,k.y-t.y)},c=32,l=0;for(let w=1;w<=c;w+=1)d(w/c)<d(l)&&(l=w/c);let p=Math.max(0,l-1/c),m=Math.min(1,l+1/c);for(let w=0;w<24;w+=1){let k=p+(m-p)/3,_=m-(m-p)/3;d(k)<d(_)?m=_:p=k}let g=(p+m)/2,b=d(g);(!n||b<n.distance)&&(n={contour:o,segment:i,t:g,point:di(a,g),distance:b})}}),n}function wl(e,t,n,r){return e.map((o,s)=>{if(s!==t)return o;let i=[...o.anchors],a=i.length,d=i[n],c=(n+1)%a,l=i[c];if(ja(o,n)){let V={x:d.x+(l.x-d.x)*r,y:d.y+(l.y-d.y)*r};return i.splice(n+1,0,V),{...o,anchors:i}}let[p,m,g,b]=jt(o,n),w=(V,T)=>({x:V.x+(T.x-V.x)*r,y:V.y+(T.y-V.y)*r}),k=w(p,m),_=w(m,g),M=w(g,b),R=w(k,_),B=w(_,M),D=w(R,B);return i[n]=ai({...d,out:k}),i[c]=ai({...l,in:M}),i.splice(n+1,0,ai({x:D.x,y:D.y,in:R,out:B})),{...o,anchors:i}})}var Fo=.5522847498;function Dn(e,t,n=0){let r=Ao(typeof n=="number"?{tl:Math.max(0,n),tr:Math.max(0,n),br:Math.max(0,n),bl:Math.max(0,n)}:n,e,t),o=[],s=(a,d,c,l)=>{if(a<=0){o.push({x:d.x,y:d.y});return}let p=Fo*a,m={x:d.x+c.x*a,y:d.y+c.y*a},g={x:d.x+l.x*a,y:d.y+l.y*a};o.push({x:m.x,y:m.y,out:{x:m.x-c.x*p,y:m.y-c.y*p}}),o.push({x:g.x,y:g.y,in:{x:g.x-l.x*p,y:g.y-l.y*p}})};s(r.tl,{x:0,y:0},{x:0,y:1},{x:1,y:0}),s(r.tr,{x:e,y:0},{x:-1,y:0},{x:0,y:1}),s(r.br,{x:e,y:t},{x:0,y:-1},{x:-1,y:0}),s(r.bl,{x:0,y:t},{x:1,y:0},{x:0,y:-1});let i=r.tl>0?o.slice(1).concat(o.slice(0,1)):o;return[{closed:!0,anchors:gS(i)}]}function Vr(e,t){let n=e/2,r=t/2,o=Fo*n,s=Fo*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-s},out:{x:e,y:r+s}},{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+s},out:{x:0,y:r-s}}]}]}function gS(e){let t=[];for(let o of e){let s=t[t.length-1];if(s&&Rr(s,o)&&!s.out&&!o.in){t[t.length-1]=fn(s,s.in,o.out);continue}t.push(o)}let n=t[0],r=t[t.length-1];return t.length>1&&n&&r&&Rr(n,r)&&!r.out&&!n.in&&(t[0]=fn(n,r.in,n.out),t.pop()),t}var Hr=["straight","elbow","curve"],ur=["none","arrow","triangle","dot","bar"],Sl=["x1","y1","x2","y2"],ci="#1F2937",li=2;function fi(e){return{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}}function Bg(e){return Math.abs(e.x2-e.x1)>=Math.abs(e.y2-e.y1)?"x":"y"}function Vg(e,t){let n=Bg(e);return{start:t.start??n,end:t.end??n}}function Hg(e,t,n={}){let{x1:r,y1:o,x2:s,y2:i}=e,a=(r+s)/2,d=(o+i)/2,c=Vg(e,n);switch(t){case"straight":return{closed:!1,anchors:[{x:r,y:o},{x:s,y:i}]};case"elbow":{let l=c.start==="x"?c.end==="x"?[{x:a,y:o},{x:a,y:i}]:[{x:s,y:o}]:c.end==="y"?[{x:r,y:d},{x:s,y:d}]:[{x:r,y:i}];return{closed:!1,anchors:[{x:r,y:o},...l,{x:s,y:i}]}}case"curve":{let l=c.start!==c.end,p=c.start==="x"?{x:l?s:a,y:o}:{x:r,y:l?i:d},m=c.end==="x"?{x:l?r:a,y:i}:{x:s,y:l?o:d};return{closed:!1,anchors:[{x:r,y:o,out:p},{x:s,y:i,in:m}]}}}}function Ug(e,t,n={}){let r=e.x2-e.x1,o=e.y2-e.y1;if(r===0&&o===0)return;if(t==="straight"||r===0||o===0){let d=Math.hypot(r,o),c={x:r/d,y:o/d};return{start:{x:-c.x,y:-c.y},end:c}}let s=Vg(e,n),i=d=>d==="x"?{x:Math.sign(r),y:0}:{x:0,y:Math.sign(o)},a=i(s.start);return{start:{x:-a.x,y:-a.y},end:i(s.end)}}function Ga(e){return 3*Math.max(0,e)+4}function kl(e,t,n,r){let o=Ga(r),s=o/2,i={x:-n.x,y:-n.y},a={x:-n.y,y:n.x},d=(c,l)=>({x:t.x+i.x*c+a.x*l,y:t.y+i.y*c+a.y*l});switch(e){case"none":return;case"triangle":return{filled:!0,inset:s,contours:[{closed:!0,anchors:[d(0,0),d(o,s),d(o,-s)]}]};case"arrow":return{filled:!1,inset:r/2,contours:[{closed:!1,anchors:[d(o,s),d(0,0),d(o,-s)]}]};case"bar":return{filled:!1,inset:0,contours:[{closed:!1,anchors:[d(0,s),d(0,-s)]}]};case"dot":return{filled:!0,inset:0,contours:[yS(t,o*.4)]}}}function yS(e,t){let n=t*Fo,{x:r,y:o}=e;return{closed:!0,anchors:[{x:r+t,y:o,in:{x:r+t,y:o-n},out:{x:r+t,y:o+n}},{x:r,y:o+t,in:{x:r+n,y:o+t},out:{x:r-n,y:o+t}},{x:r-t,y:o,in:{x:r-t,y:o+n},out:{x:r-t,y:o-n}},{x:r,y:o-t,in:{x:r-n,y:o-t},out:{x:r+n,y:o-t}}]}}function _l(e,t,n,r,o,s={}){let i=Hg(e,t,s),a=Ug(e,t,s);if(!a)return{route:i,filled:[],lined:[]};let d=[kl(n,{x:e.x1,y:e.y1},a.start,o),kl(r,{x:e.x2,y:e.y2},a.end,o)],c=bS(i,a,d[0]?.inset??0,d[1]?.inset??0),l=[],p=[];for(let m of d)m&&(m.filled?l:p).push(...m.contours);return{route:c,filled:l,lined:p}}function bS(e,t,n,r){if(n===0&&r===0)return e;let o=[...e.anchors],s=(i,a,d,c)=>{let l=o[i],p=o[a];if(!l||!p||d<=0)return;let m=Math.hypot(p.x-l.x,p.y-l.y),g=o.length===2?Math.min(d,m/2):Math.min(d,m),b=-c.x*g,w=-c.y*g,k=B=>B===void 0?void 0:{x:B.x+b,y:B.y+w},_={x:l.x+b,y:l.y+w},M=k(l.in),R=k(l.out);o[i]={..._,...M===void 0?{}:{in:M},...R===void 0?{}:{out:R}}};return s(0,1,n,t.start),s(o.length-1,o.length-2,r,t.end),{...e,anchors:o}}function cr(e){let t=new Set;return de(e,n=>{t.add(n.id)}),t}function pn(e,t){let n=cr(e),r=0;for(let o of n){if(!o.startsWith(`${t}.`))continue;let s=Number(o.slice(t.length+1));Number.isInteger(s)&&s>r&&(r=s)}return`${t}.${r+1}`}var gt=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 s=Kg(n,o);n=s.document,r.push(s.inverse)}return r.reverse(),{document:n,inverse:r}}function Kg(e,t){let n=kS(e,t);if(!vS(e.root)&&!wS(t))return El.add(n.document.root),n;let r=$n(n.document.root);return r===n.document.root?n:{document:{...n.document,root:r},inverse:n.inverse}}var El=new WeakSet;function vS(e){return El.has(e)?!1:Ws(e)?!0:(El.add(e),!1)}function wS(e){if(e.op==="set")return e.prop==="component";if(e.op!=="insert")return!1;let t=!1;return de(e.node,n=>((n.type==="instance"||n.type==="frame"&&n.component===!0)&&(t=!0),t?!1:void 0)),t}function kS(e,t){switch(t.op){case"set":{let n=Lt(e.root,t.id);if(n)return SS(e,t,n.instance.id,n.key);if(t.prop==="children"&&z(e.root,t.id)?.type==="instance")throw new gt(`${t.id}'s contents come from its component`,t);let r=z(e.root,t.id);if(!r)throw new gt(`No node ${t.id}`,t);let o=r[t.prop];return{document:pi(e,Xa(e.root,t.id,s=>Gg(s,t.prop,t.value),t)),inverse:{op:"set",id:t.id,prop:t.prop,value:o}}}case"insert":{if(qa(e,t.parent,t,!0),z(e.root,t.node.id))throw new gt(`Duplicate id ${t.node.id}`,t);let n=Wa(e.root,t.parent,r=>{let o=jg(t.index,0,r.length);return[...r.slice(0,o),t.node,...r.slice(o)]},t);return{document:pi(e,n),inverse:{op:"remove",id:t.node.id}}}case"remove":{qa(e,t.id,t,!1);let n=zg(e,t.id,t),r=Wa(e.root,n.parent.id,o=>o.filter(s=>s.id!==t.id),t);return{document:pi(e,r),inverse:{op:"insert",parent:n.parent.id,index:n.index,node:n.node}}}case"move":{qa(e,t.id,t,!1),qa(e,t.parent,t,!0);let n=zg(e,t.id,t),r=Wa(e.root,n.parent.id,s=>s.filter(i=>i.id!==t.id),t),o=Wa(r,t.parent,s=>{let i=jg(t.index,0,s.length);return[...s.slice(0,i),n.node,...s.slice(i)]},t);return{document:pi(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:Or(t.value)};return{document:{...o,version:Et(o)},inverse:{op:"setBrand",value:n}}}case"setTheme":{let{themes:n,...r}=e,o=un(t.value),s=o===void 0?r:{...r,themes:o};return{document:{...s,version:Et(s)},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 Tn(t.value)?delete r[t.page]:r[t.page]=t.value,{document:hl(e,r),inverse:{op:"setMotion",page:t.page,value:n}}}}}function Vo(e,t){if(!e.motion||!t.some(r=>r.op==="remove"||r.op==="move"))return t;let n=ml(e,Ae(e,t).document);return n.length===0?t:[...t,...n]}function SS(e,t,n,r){if(!nr(t.prop))throw new gt(`${t.id} is part of ${n}; its ${t.prop} comes from the component`,t);let o=z(e.root,n);if(o?.type!=="instance")throw new gt(`No instance ${n}`,t);let s=o.overrides?.[r]?.[t.prop],i=Yc(o.overrides,r,t.prop,t.value,Xc(e.root,o,r,t.prop));return{document:pi(e,Xa(e.root,n,a=>Gg(a,"overrides",i),t)),inverse:{op:"set",id:t.id,prop:t.prop,value:s}}}function qa(e,t,n,r){let o=Lt(e.root,t),s=r&&z(e.root,t)?.type==="instance";if(o)throw new gt(`${t} is inside ${o.instance.id} \u2014 change its component, or detach the instance first`,n);if(s)throw new gt(`${t} holds only copies of its component \u2014 change the component, or detach ${t} first`,n)}function pi(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 Xa(e,t,n,r){if(e.id===t)return n(e);if(!me(e))return e;let o=!1,s=e.children.map(i=>{let a=Xa(i,t,n,r);return a!==i&&(o=!0),a});return o?{...e,children:s}:e}function Wa(e,t,n,r){let o=z(e,t);if(!o)throw new gt(`No node ${t}`,r);if(!me(o))throw new gt(`${t} cannot hold children`,r);return Xa(e,t,s=>({...s,children:n(s.children)}),r)}function zg(e,t,n){if(t===e.root.id)throw new gt("The document root cannot be removed or moved",n);let r,o=s=>{me(s)&&s.children.forEach((i,a)=>{i.id===t&&(r={node:i,parent:s,index:a}),o(i)})};if(o(e.root),!r)throw new gt(`No node ${t}`,n);return r}function jg(e,t,n){return Math.min(Math.max(e,t),n)}function Cl(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 s of Bo(e.tokens,t.tokens)){let i=t.tokens[s];e.tokens[s]!==i&&n.push({op:"setToken",name:s,value:i})}for(let s of Bo(e.fonts,t.fonts)){let i=t.fonts[s];ES(e.fonts[s],i)||n.push({op:"setFont",name:s,family:i})}for(let s of Bo(e.assets,t.assets)){let i=t.assets[s];(e.assets[s]?.hash!==i?.hash||e.assets[s]?.ms!==i?.ms)&&n.push({op:"setAsset",name:s,value:i})}if(!_S(e.root.children,t.root.children)){for(let s of e.root.children)n.push({op:"remove",id:s.id});t.root.children.forEach((s,i)=>{n.push({op:"insert",parent:e.root.id,index:i,node:s})})}for(let s of Bo(e.motion??{},t.motion??{})){let i=t.motion?.[s];Ha(e.motion?.[s],i)||n.push({op:"setMotion",page:s,value:i})}Kc(e.brand,t.brand)||n.push({op:"setBrand",value:t.brand}),MS(e.themes,t.themes)||n.push({op:"setTheme",value:t.themes});let r=e.root,o=t.root;for(let s of Bo(r,o))s==="type"||s==="id"||s==="children"||qg(r[s],o[s])||n.push({op:"set",id:e.root.id,prop:s,value:o[s]});return n}function Bo(e,t){return[...new Set([...Object.keys(e),...Object.keys(t)])]}function qg(e,t){return e===t?!0:ve(e)&&ve(t)&&e.expr===t.expr}function _S(e,t){return e.length===t.length&&e.every((n,r)=>Ml(n,t[r]))}function Ml(e,t){if(qg(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((s,i)=>Ml(s,t[i]));let n=e,r=t;return Bo(n,r).every(s=>Ml(n[s],r[s]))}function ES(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,s)=>{let i=r[s];return o.src===i.src&&o.asset===i.asset&&o.weight===i.weight&&o.style===i.style})}function MS(e,t){let n=un(e)?.dark??{},r=un(t)?.dark??{},o=Object.keys(n);return o.length===Object.keys(r).length&&o.every(s=>n[s]===r[s])}var Ur=["center","inside","outside"];function zr(e){let t=e.trim();if(t===""||t==="none"||t==="solid")return{error:"a solid line has no dash \u2014 unset dash rather than writing one"};let n=t.split(/[\s,]+/),r=[];for(let o of n){if(!/^\d*\.?\d+$/.test(o)){let s=/^(\d*\.?\d+)[a-z%]+$/i.exec(o);return s?{error:`lengths have no unit \u2014 write ${s[1]} for ${o}`}:/^-/.test(o)?{error:`a dash length cannot be negative, got ${o}`}:{error:`expected lengths like "6 4", got ${JSON.stringify(e)}`}}r.push(Number(K(Number(o))))}return r.some(o=>o>0)?{dash:r}:{error:"a dash needs one length above zero \u2014 unset dash for a solid line"}}function Ho(e){return e.map(t=>K(t)).join(" ")}function Al(e){if(e===void 0)return[];let t=zr(e);return"error"in t?[]:t.dash.length%2===1?[...t.dash,...t.dash]:t.dash}var Uo={canvas:[["name","string"],["w","numberValue"],["h","numberValue"],["background","stringValue"]],frame:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["background","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["dash","dash"],["strokeAlign","strokeAlign"],["cap","lineCap"],["radius","numberValue"],["radiusTL","numberValue"],["radiusTR","numberValue"],["radiusBR","numberValue"],["radiusBL","numberValue"],["clip","boolean"],["skip","boolean"],["component","boolean"],["blend","blendMode"],["shadow","stringValue"],["blur","numberValue"],["backdrop","numberValue"],["hidden","boolean"],["locked","boolean"]],connector:[["name","string"],["x1","numberValue"],["y1","numberValue"],["x2","numberValue"],["y2","numberValue"],["route","route"],["start","connectorEnd"],["end","connectorEnd"],["stroke","stringValue"],["strokeWidth","numberValue"],["dash","dash"],["cap","lineCap"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["blur","numberValue"],["hidden","boolean"],["locked","boolean"]],group:[["name","string"],["hidden","boolean"],["locked","boolean"]],instance:[["name","string"],["component","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["hidden","boolean"],["locked","boolean"]],ellipse:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["dash","dash"],["strokeAlign","strokeAlign"],["cap","lineCap"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["blur","numberValue"],["backdrop","numberValue"],["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"],["dash","dash"],["strokeAlign","strokeAlign"],["opacity","numberValue"],["rule","fillRule"],["cap","lineCap"],["join","lineJoin"],["blend","blendMode"],["shadow","stringValue"],["blur","numberValue"],["backdrop","numberValue"],["hidden","boolean"],["locked","boolean"]],video:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["src","stringValue"],["fit","imageFit"],["start","number"],["end","number"],["poster","number"],["muted","boolean"],["loop","boolean"],["mask","string"],["stroke","stringValue"],["strokeWidth","numberValue"],["dash","dash"],["strokeAlign","strokeAlign"],["cap","lineCap"],["radius","numberValue"],["radiusTL","numberValue"],["radiusTR","numberValue"],["radiusBR","numberValue"],["radiusBL","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["blur","numberValue"],["hidden","boolean"],["locked","boolean"]],rect:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["dash","dash"],["strokeAlign","strokeAlign"],["cap","lineCap"],["radius","numberValue"],["radiusTL","numberValue"],["radiusTR","numberValue"],["radiusBR","numberValue"],["radiusBL","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["blur","numberValue"],["backdrop","numberValue"],["hidden","boolean"],["locked","boolean"]],image:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["src","stringValue"],["fit","imageFit"],["mask","string"],["stroke","stringValue"],["strokeWidth","numberValue"],["dash","dash"],["strokeAlign","strokeAlign"],["cap","lineCap"],["radius","numberValue"],["radiusTL","numberValue"],["radiusTR","numberValue"],["radiusBR","numberValue"],["radiusBL","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["blur","numberValue"],["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"],["stroke","stringValue"],["strokeWidth","numberValue"],["dash","dash"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["blur","numberValue"],["hidden","boolean"],["locked","boolean"]]},hi=[["font","string"],["size","number"],["weight","number"],["italic","boolean"],["underline","boolean"],["strike","boolean"],["fill","string"],["letterSpacing","number"],["link","string"]],$l=[["weight","number"],["style","fontStyle"]],mi=[["enter","pageEffect"],["duration","number"],["scroll","boolean"],["length","time"],["w","number"],["h","number"],["bpm","number"],["meter","number"]],jr=[["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"]],xi=[["from","number"],["volume","number"],["fadein","time"],["fadeout","time"],["loop","boolean"]],Ol=Object.keys(Uo);function Ya(e){return Ol.includes(e)}function zo(e,t){return Uo[e].find(([n])=>n===t)?.[1]}function Ja(e){for(let t of Ol){if(t==="canvas"||t==="instance")continue;let n=zo(t,e);if(n!==void 0)return n}}var Za="override",rt=" ";function Xe(e){if(ve(e))return/^[$@]/.test(e.expr)&&!/\s/.test(e.expr)?e.expr:`(${e.expr})`;if(typeof e=="number")return K(e);let t=String(e);return CS(t)?JSON.stringify(t):t}function CS(e){return e===""||/[\s"=()]/.test(e)||/^[$@]/.test(e)}function Qe(e,t){if(t==="boolean")return e===""||e==="true"?{value:!0}:e==="false"?{value:!1}:{error:`Expected true or false, got ${e}`};if(e.startsWith('"')){let r=hn(e);return r===void 0?{error:`Malformed quoted string ${e}`}:Wg(r,t,e)}if(TS(e)){if(!AS(t))return{error:$S(e,t)};let r=Zg(e).trim();return r===""?{error:"Empty expression"}:{value:_t(r)}}return t==="numberValue"&&Yg.test(e)?{value:_t(e)}:Wg(e,t,e)}var Yg=/^-?\d+(?:\.\d+)?%$/;function AS(e){return e==="numberValue"||e==="stringValue"}function $S(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 Jg(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"?Yg.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 Wg(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}${Jg(e,t)}`}}case"align":return Qn.includes(e)?{value:e}:{error:`Expected one of ${Qn.join(", ")}, got ${n}`};case"valign":return er.includes(e)?{value:e}:{error:`Expected one of ${er.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 Gt(Ar,e,n);case"lineCap":return Gt(tr,e,n);case"lineJoin":return Gt($r,e,n);case"dash":{let r=zr(e);return"error"in r?{error:r.error}:{value:Ho(r.dash)}}case"strokeAlign":return Gt(Ur,e,n);case"blendMode":return Gt(Cr,e,n);case"route":return Gt(Hr,e,n);case"connectorEnd":return Gt(ur,e,n);case"pageEffect":return Gt(Do,e,n);case"nodeEffect":return Gt(ti,e,n);case"emphasisEffect":return Gt(ni,e,n);case"ease":return Gt(ri,e,n);case"piece":return Gt(oi,e,n);case"time":{let r=Lr(e);if(r)return{value:Pr(r.count,r.unit)};let o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{value:o}:{error:`Expected milliseconds or beats, got ${n}${OS(e)}`}}case"on":return Zs.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(or.includes(e))return{value:e};let r=Number(e);return Number.isFinite(r)&&e.trim()!==""?{value:r}:{error:`Expected a number or one of ${or.join(", ")}, got ${n}`}}default:return{value:e}}}function OS(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 ${Pr(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 ${Pr(Number(n[1]),r)} (counted from the start)`}return Jg(e,"number")}function Gt(e,t,n){return e.includes(t)?{value:t}:{error:`Expected one of ${e.join(", ")}, got ${n}`}}function TS(e){return/^[$@(]/.test(e)}function Qa(e,t){if(e!=="radius")return;let n=Uc(t);if(n===void 0)return;if("error"in n)return n;let r=[];for(let[o,s]of n.corners){let i=Qe(s,"numberValue");if("error"in i)return i;r.push([o,i.value])}return{cells:r}}function hn(e){try{let t=JSON.parse(e);return typeof t=="string"?t:void 0}catch{return}}function Zg(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 Qg(e){let t=[],n="",r=0,o=!1;for(let s=0;s<e.length;s+=1){let i=e[s];if(o){n+=i,i==="\\"?(n+=e[s+1]??"",s+=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 ed(e,t,n){let r=n===void 0?void 0:ot(n);if(r?.value===void 0||!Xg(e[t]??""))return;let o=t;for(;o<e.length&&Xg(e[o]??"");)o+=1;let s=[Zg(r.value),...e.slice(t,o)].join(" ");return r.key==="dash"&&s.split(" ").every(i=>/^\d*\.?\d+$/.test(i))?{end:o,message:`dash: quote a pattern of several lengths \u2014 write dash="${s}"`}:r.key==="radius"&&s.split(" ").every(i=>/^-?\d+(?:\.\d+)?$/.test(i))?{end:o,message:`radius: quote the four-corner shorthand \u2014 write radius="${s}"`}:{end:o,message:`${r.key}: an expression with spaces needs parentheses \u2014 write ${r.key}=(${s})`}}function Xg(e){return!e.includes("=")&&/^(?:[-+*/]|-?\d+(?:\.\d+)?%?|[$@][\w.]*|[A-Za-z_]\w*(?:\.\w+)+|\(.*|.*\))$/.test(e)}function ot(e){let t=e.indexOf("=");return t===-1?{key:e,value:void 0}:{key:e.slice(0,t),value:e.slice(t+1)}}function Tl(e,t){let n,r=0,o,s=[],i=[],a={},d={},c={},l={},p=[],m=!1,g=!1,b,w=(O,j,$)=>{t.push({severity:"warning",code:j,message:`Line ${O}: ${$}`})},k=(O,j,$)=>{e(O.number,"invalid-brand",`${j} ${$} is written twice \u2014 keep one`)},_=O=>{if(n){e(O.number,"invalid-brand",`A document has one brand line; the first is on line ${r}`);return}let j=O.words[1]===void 0?void 0:zc(O.words[1]);if(!j){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 $=O.words.slice(2).includes("strict"),P=Nn({...O,words:O.words.filter((G,ee)=>ee<2||G!=="strict")},2,["id","theme"],e),C=P.theme;C!==void 0&&!La.includes(C)&&e(O.number,"invalid-brand",`theme= is light or dark, got ${C}`),n={...j,...P.id===void 0?{}:{id:P.id},...C==="dark"||C==="light"?{theme:C}:{},...$?{strict:!0}:{}},r=O.number,b={kind:"brand"}},M=O=>{let j=O.words[0];if(j==="summary"){let $=td(O,1);$===void 0?e(O.number,"invalid-brand",'Expected summary "\u2026"'):o=$;return}if(j==="change"){let $=Number(O.words[1]),P=O.words[2]===void 0?void 0:ty(O.words[2]);if(!Number.isSafeInteger($)||$<1||P===void 0){e(O.number,"invalid-brand",'Expected change <version> "<what changed>" at=<date>');return}let C=Nn(O,3,["at"],e);s.push({version:$,note:P,...C.at===void 0?{}:{at:C.at}});return}if(j==="source"){let $=O.words[1];if($===void 0||$.includes("=")){e(O.number,"invalid-brand","Expected source <kind> key=value\u2026, e.g. source site url=\u2026");return}i.push({kind:$,props:Nn(O,2,void 0,e)});return}if(j==="rule"){D(O);return}if(j==="banned"){let $=td(O,1);if($===void 0){e(O.number,"invalid-brand",'Expected banned "\u2026"');return}(l.voice??={entries:[]}).entries.push({kind:"banned",text:$});return}e(O.number,"invalid-brand",`"${j}" is not a line of the brand block \u2014 it holds summary, change and source, and in a design rule and banned`)},R=O=>{let j=O.words[1];if(j===void 0||j.includes("=")){e(O.number,"invalid-role","Expected role <name> light=<token or colour> dark=\u2026");return}let $=Nn(O,2,["light","dark"],e),P=$.light;if(P===void 0){e(O.number,"invalid-role",`role ${j} needs light=`);return}if(Object.prototype.hasOwnProperty.call(a,j))return k(O,"role",j);let C=$.dark;a[j]={light:ey(P),...C===void 0?{}:{dark:ey(C)}}},B=O=>{let j=O.words[1];if(j===void 0||j.includes("=")){e(O.number,"invalid-logo","Expected logo <id> asset=<name> min=<px> clear=<fraction>");return}let $=Nn(O,2,["asset","min","clear"],e),P=$.asset;if(P===void 0){e(O.number,"invalid-logo",`logo ${j} needs asset=`);return}let C={asset:P};for(let G of["min","clear"]){let ee=$[G];if(ee===void 0)continue;let fe=Number(ee);if(!Number.isFinite(fe)||fe<0){e(O.number,"invalid-logo",`logo ${j}: ${G} must be a number, got ${ee}`);continue}C[G]=fe}if(Object.prototype.hasOwnProperty.call(d,j))return k(O,"logo",j);d[j]=C},D=O=>{let j=O.words[1],$=O.words[2],P=O.words[3],C=P?.startsWith('"')===!0?hn(P):void 0;if(j===void 0||j.includes("=")){e(O.number,"invalid-rule",'Expected rule <id> must|should "<what it asks>" check=\u2026');return}if($===void 0||!Pa.includes($)){e(O.number,"invalid-rule",`rule ${j}: the second word is must or should`);return}if(C===void 0){e(O.number,"invalid-rule",`rule ${j} needs its words, quoted: rule ${j} ${$} "\u2026"`);return}let{check:G,...ee}=Nn(O,4,void 0,e);if(G!==void 0&&!Da.includes(G)&&w(O.number,"unknown-check",`rule ${j}: this build has no check "${G}", so it is kept as words only \u2014 the checks are ${Da.join(", ")}`),Object.prototype.hasOwnProperty.call(c,j))return k(O,"rule",j);c[j]={level:$,text:C,...G===void 0?{}:{check:G},...Object.keys(ee).length===0?{}:{params:ee}}},V=(O,j)=>{let $=O.words[0];if($.startsWith('"')){let P=td(O,0);P===void 0?e(O.number,"invalid-guide",`Could not read ${O.text}`):j.push({kind:"line",text:P});return}if($==="banned"||$==="avoid"){let P=td(O,1);P===void 0?e(O.number,"invalid-guide",`Expected ${$} "\u2026"`):j.push({kind:$,text:P});return}if($==="rewrite"){let P=Nn(O,1,["from","to"],e),C=P.from,G=P.to;if(C===void 0||G===void 0){e(O.number,"invalid-guide",'Expected rewrite from="\u2026" to="\u2026"');return}j.push({kind:"rewrite",from:C,to:G});return}if($==="ref"||$==="approved"||$==="rejected"){let P=Nn(O,1,["asset","note"],e),C=P.asset;if(C===void 0){e(O.number,"invalid-guide",`Expected ${$} asset=<name> note="\u2026"`);return}let G=P.note;j.push({kind:$,asset:C,...G===void 0?{}:{note:G}});return}e(O.number,"invalid-guide",`"${$}" is not a guide line \u2014 a guide holds quoted lines, banned, avoid, rewrite, ref, approved and rejected`)},T=O=>{let j=O.words[0];if(j.includes("=")||j.startsWith('"')){e(O.number,"invalid-review",'Expected <what>.<id> from=\u2026 note="\u2026", e.g. role.muted from=site');return}let $=Nn(O,1,["from","note"],e);p.push({target:j,...$.from===void 0?{}:{from:$.from},...$.note===void 0?{}:{note:$.note}})};return{take(O){if(O.indent>0)return b?(b.kind==="brand"?M(O):b.kind==="guide"?V(O,b.entries):T(O),!0):!1;b=void 0;let j=O.words[0];if(j!=="brand"&&!Na(j))return!1;switch(g=!0,j){case"brand":_(O);break;case"role":R(O);break;case"logo":B(O);break;case"rule":D(O);break;case"guide":{let $=O.words[1];if($===void 0||$.includes("=")||O.words.length>2){e(O.number,"invalid-guide","Expected guide <id> on its own line, e.g. guide voice"),b={kind:"guide",id:"",entries:[]};break}if(Object.prototype.hasOwnProperty.call(l,$)){k(O,"guide",$),b={kind:"guide",id:"",entries:[]};break}let P=[];l[$]={entries:P},b={kind:"guide",id:$,entries:P};break}case"review":O.words.length>1&&e(O.number,"invalid-review","review is a block: its items go on the lines under it"),m=!0,b={kind:"review"};break}return!0},finish(){if(!g)return{header:!1,review:!1};let O=n??Ra();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:s,sources:i,roles:a,logos:d,rules:c,guides:l,review:p},header:n!==void 0,review:m}}}}function Nn(e,t,n,r){let o={};for(let s of e.words.slice(t)){let{key:i,value:a}=ot(s);if(a===void 0){r(e.number,"invalid-brand",`A stray word "${s}" \u2014 expected key=value`);continue}if(n!==void 0&&!n.includes(i)){r(e.number,"invalid-brand",`"${i}" is not allowed here; this line takes ${n.join(", ")}`);continue}o[i]=ty(a)}return o}function td(e,t){if(e.words.length!==t+1)return;let n=e.words[t];return n.startsWith('"')?hn(n):void 0}function ty(e){return e.startsWith('"')?hn(e)??e:e}function ey(e){return e.startsWith("$")?e.slice(1):e}function ny(e,t,n="brand"){if(!t||t.slug==="")return;let r=["brand",jc(t)];t.id!==void 0&&r.push(`id=${Xe(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(`${rt}summary ${JSON.stringify(t.summary)}`);for(let o of t.changes){let s=["change",K(o.version),JSON.stringify(o.note)];o.at!==void 0&&s.push(`at=${Xe(o.at)}`),e.push(rt+s.join(" "))}for(let o of t.sources)e.push(rt+["source",o.kind,...jo(o.props)].join(" "));if(n==="design"){for(let o of ry(t))e.push(rt+o);for(let o of LS(t))e.push(`${rt}banned ${JSON.stringify(o)}`)}e.push("")}function ry(e){return Object.entries(e.rules).map(([t,n])=>["rule",t,n.level,JSON.stringify(n.text),...jo({check:n.check,...n.params})].join(" "))}function LS(e){return(e.guides.voice?.entries??[]).flatMap(t=>t.kind==="banned"?[t.text]:[])}function oy(e,t,n="brand"){if(!t)return;let r=n==="design",o=s=>{s.length!==0&&e.push(...s,"")};o(Object.entries(t.roles).map(([s,i])=>["role",s,...jo({light:i.light,dark:i.dark})].join(" "))),o(Object.entries(t.logos).map(([s,i])=>["logo",s,...jo({asset:i.asset,min:i.min===void 0?void 0:K(i.min),clear:i.clear===void 0?void 0:K(i.clear)})].join(" "))),r||o(ry(t));for(let[s,i]of Object.entries(t.guides)){let a=r&&s==="voice"?i.entries.filter(d=>d.kind!=="banned"):i.entries;if(!(r&&a.length===0)){e.push(`guide ${s}`);for(let d of a)e.push(rt+PS(d));e.push("")}}if(t.review.length>0){e.push("review");for(let s of t.review)e.push(rt+[s.target,...jo({from:s.from,note:s.note})].join(" "));e.push("")}}function PS(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,...jo({asset:e.asset,note:e.note})].join(" ")}}function jo(e){let t=[];for(let[n,r]of Object.entries(e))r!==void 0&&t.push(`${n}=${Xe(r)}`);return t}var DS=new Set(["exit","delay","step","together","go","at","after","with"]),iy=["at","after","with","together","step"],NS=new Set(["pad","duration","delay","ease","on",...iy]);function Ll(e){if(e==="at"||e==="length")return sr;if(e==="w"||e==="h")return ln;if(e==="duration"||e==="delay"||e==="stagger"||e==="hold")return cn;if(e==="pad")return ln}function Pl(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 s of e.words.slice(2)){let{key:i,value:a}=ot(s),d=mi.find(([l])=>l===i)?.[1];if(d===void 0){let l=DS.has(i)?` \u2014 ${i} goes on a node's line, under the header`:"";t(e.number,"invalid-motion",`motion ${n} has no "${i}"${l}`,n);continue}let c=Qe(a??"",d);"error"in c?t(e.number,"invalid-motion",`${i}: ${US(i,a)??c.error}`,n):i==="bpm"&&!VS(c.value)?t(e.number,"invalid-motion",`bpm: expected ${20} to ${300} beats a minute, got ${a??""}`,n):i==="meter"&&!HS(c.value)?t(e.number,"invalid-motion",`meter: expected a whole number of beats in a bar, 1 to ${16}, got ${a??""}`,n):c.value!==!1&&(r[i]=c.value)}let o=en({...r,lines:[]});for(let[s]of mi){let i=r[s];if(i===void 0||Ll(s)===void 0)continue;let a=Rl(s,i,o,n);a!==void 0&&(t(e.number,"invalid-motion",a,n),delete r[s])}return{page:n,number:e.number,head:r,lines:[],where:new Map,taken:new Map,numbers:[]}}function Dl(e,t,n){if(t.words[0]==="music"&&!(t.words[1]??"").includes("=")){IS(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,s=o[0];if(t.indent!==1){n(t.number,"invalid-motion","A motion line sits one level under its page");return}if(s.includes("=")){n(t.number,"invalid-motion",`Expected a node id first, got ${s}`);return}if(s===e.page&&!r){n(t.number,"invalid-motion",`${s} is the page: its transition goes on the header (motion ${s} enter=fade)`,s);return}let i=r?{id:s,camera:!0}:{id:s},a=!0;for(let l of o.slice(1)){let{key:p,value:m}=ot(l),g=jr.find(([k])=>k===p)?.[1];if(g===void 0){n(t.number,"invalid-motion",`A motion line has no "${p}"${zS(p)}`,s),a=!1;continue}if(r&&!NS.has(p)){n(t.number,"invalid-motion",`A camera line moves the shot and says only pad=, duration=, delay=, ease= and when: not ${p}=`,s),a=!1;continue}let b=Qe(m??"",g),w="error"in b||Ll(p)===void 0?void 0:Rl(p,b.value,en(dy(e)),e.page);"error"in b?(n(t.number,"invalid-motion",`${p}: ${b.error}`,s),a=!1):w!==void 0?(n(t.number,"invalid-motion",`${s}: ${w}`,s),a=!1):p==="on"&&e.head.bpm===void 0?(n(t.number,"invalid-motion",`${s}: on=${String(b.value)} needs a tempo \u2014 motion ${e.page} bpm=120`,s),a=!1):p==="go"&&On(b.value)===void 0?(n(t.number,"invalid-motion",`go: expected #<page>, back, next, or an https: or mailto: link, got ${m??""}`,s),a=!1):b.value!==!1&&(i[p]=b.value)}i.enter!==void 0&&i.exit!==void 0&&(n(t.number,"invalid-motion",`${s} either enters or exits on one line \u2014 write a second line for the other`,s),a=!1),i.emphasis!==void 0&&(i.enter!==void 0||i.exit!==void 0)&&(n(t.number,"invalid-motion",`${s} either ${i.enter!==void 0?"enters":"exits"} or is stressed on one line \u2014 write a second line for emphasis=`,s),a=!1);let d=iy.filter(l=>i[l]!==void 0);if(i.step===!0&&i.together===!0?(n(t.number,"invalid-motion",`${s} waits for a step or starts together with the line above, not both`,s),a=!1):d.length>1?(n(t.number,"invalid-motion",`${s} says when it starts twice (${d.join(", ")}): keep one`,s),a=!1):i.on!==void 0&&(i.with!==void 0||i.together===!0)&&(n(t.number,"invalid-motion",`${s} starts with another line (${i.with===void 0?"together":"with="}), so on= could only pull it apart: keep one`,s),a=!1),a){let l=jS(i);l!==void 0&&(n(t.number,"invalid-motion",`${s}: ${l}`,s),a=!1)}if(!a)return;let c=BS(i);if(!No(c)){n(t.number,"invalid-motion",`${s} says nothing: give it enter=, exit=, emphasis= or go=`,s);return}if(r){e.where.has(s)||e.where.set(s,t.number),e.lines.push(c),e.numbers.push(t.number);return}for(let l of["enter","exit","emphasis","go"]){if(c[l]===void 0)continue;let p=e.taken.get(`${s} ${l}`);if(p!==void 0){let m=l==="go"?"has a go=":l==="enter"?"enters":l==="exit"?"exits":"has an emphasis=";n(t.number,"invalid-motion",`${s} already ${m} on line ${p}`,s);return}}for(let l of["enter","exit","emphasis","go"])c[l]!==void 0&&e.taken.set(`${s} ${l}`,t.number);e.where.has(s)||e.where.set(s,t.number),e.lines.push(c),e.numbers.push(t.number)}function Nl(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 Tn(t)?void 0:t}function ay(e,t){let n=t.motion;if(n)for(let r of Ro(t)){let o=n[r];if(o===void 0||Tn(o))continue;e.at(-1)!==""&&e.push("");let s=["motion",r];for(let[i,a]of mi){let d=o[i];if(d!==void 0){if(a==="boolean"){d===!0&&s.push(i);continue}s.push(`${i}=${Xe(d)}`)}}if(e.push(s.join(" ")),o.music){let i=["music",o.music.asset];for(let[a,d]of xi){let c=o.music[a];if(c!==void 0){if(d==="boolean"){c===!0&&i.push(a);continue}i.push(`${a}=${Xe(c)}`)}}e.push(rt+i.join(" "))}for(let i of o.lines){let a=i.camera===!0?["camera",i.id]:[i.id];for(let[d,c]of jr){let l=i[d];if(l!==void 0){if(c==="boolean"){l===!0&&a.push(d);continue}a.push(`${d}=${Xe(l)}`)}}e.push(rt+a.join(" "))}}}var RS=new Set(["loop","step","together"]);function IS(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(RS.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},s=en(dy(e)),i=!0,a=c=>{n(t.number,"invalid-motion",`music ${r}: ${c}`),i=!1};for(let c of t.words.slice(2)){let{key:l,value:p}=ot(c),m=xi.find(([b])=>b===l)?.[1];if(m===void 0){a(`the music line has no "${l}"${FS(l)}`);continue}if(l==="from"&&p!==void 0&&/\d(?:beats?|bars?)$/.test(p)){a(`from= is where in the track to begin, in milliseconds, not ${p}`);continue}let g=Qe(p??"",m);if("error"in g){a(`${l}: ${g.error}`);continue}if(l==="from"&&!sy(g.value,0,Lo)){a(`from: expected 0 to ${Lo} milliseconds, got ${p??""}`);continue}if(l==="volume"&&!sy(g.value,0,1)){a(`volume: expected 0 to 1, got ${p??""}`);continue}if(l==="fadein"||l==="fadeout"){let b=Rl(l,g.value,s,e.page);if(b!==void 0){a(b);continue}}g.value!==!1&&(o[l]=g.value)}if(!i)return;let d={asset:r};for(let[c]of xi)o[c]!==void 0&&(d[c]=o[c]);e.music=d,e.musicLine=t.number}function sy(e,t,n){return typeof e=="number"&&e>=t&&e<=n}function FS(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 BS(e){let t=e.camera===!0?{id:e.id,camera:!0}:{id:e.id};for(let[n]of jr)e[n]!==void 0&&(t[n]=e[n]);return t}function dy(e){let{bpm:t,meter:n}=e.head;return{...t===void 0?{}:{bpm:t},...n===void 0?{}:{meter:n},lines:[]}}function Rl(e,t,n,r){if(Dr(t)&&!n)return`${t} needs a tempo \u2014 motion ${r} bpm=120`;let o=typeof t=="number"||Dr(t)?ft(t,n):void 0,s=Ll(e)??cn;if(o!==void 0&&o>=(e==="w"||e==="h"?16:0)&&o<=s)return;let a=String(t),d=Dr(t)&&o!==void 0?` (${Math.round(o)} ms)`:"";return e==="w"||e==="h"?`${e}: expected 16 to ${ln} pixels, got ${a}`:e==="pad"?`pad: expected 0 to ${ln}, got ${a}`:`${e}: expected 0 to ${s} milliseconds, got ${a}${d}`}function VS(e){return typeof e=="number"&&e>=20&&e<=300}function HS(e){return typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=16}function US(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 zS(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 jS(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: ${or.join(", ")}`}else return"from= goes with count (a number), or wipe and grow (a side)";if(e.by!==void 0&&r!==void 0&&!Po.includes(r))return`by= splits a text for ${Po.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 KS=24;function Fl(e,t={}){let n=[`version ${K(Et(e))}`,`kind ${e.kind}`];e.title!==void 0&&n.push(`title ${JSON.stringify(e.title)}`),ny(n,e.brand,e.kind);for(let[o,s]of Object.entries(e.tokens))n.push(`$${o} = ${Xe(s)}`);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,s]of Object.entries(r))n.push(` $${o} = ${Xe(s)}`);n.push("")}for(let[o,s]of Object.entries(e.fonts))WS(n,o,s,t),n.push("");if(Object.keys(e.assets).length>0){for(let[o,s]of Object.entries(e.assets))n.push(qS(o,s));n.push("")}return oy(n,e.brand,e.kind),GS(e.root)?e.root.children.forEach((o,s)=>{s>0&&n.push(""),Il(n,o,0)}):Il(n,e.root,0),ay(n,e),n.join(`
33
+ `)}function GS(e){return e.id===dn&&e.w===void 0&&e.h===void 0&&e.background===void 0&&e.name===void 0}function qS(e,t){let n=[`asset ${e} = ${t.type}`,`hash=${t.hash}`,`bytes=${K(t.bytes)}`];t.ms!==void 0&&n.push(`ms=${K(t.ms)}`);for(let r of["credit","source","license"]){let o=t[r];o!==void 0&&n.push(`${r}=${Xe(o)}`)}return n.join(" ")}function WS(e,t,n,r){e.push(`font ${t} = ${Xe(n.family)}`),n.fallback!==void 0&&e.push(`${rt}fallback ${Xe(n.fallback)}`);for(let o of n.faces??[]){let s=o.asset!==void 0?[`face asset=${o.asset}`]:[`face ${Xe(r.abbreviateFaces?XS(o.src??""):o.src??"")}`];for(let[i]of $l){let a=o[i];a!==void 0&&s.push(`${i}=${Xe(a)}`)}e.push(rt+s.join(" "))}}function XS(e){return e.startsWith("data:")?`${e.slice(0,KS)}\u2026 ${K(Math.round(e.length/1024))} kB`:e}function Il(e,t,n){let r=rt.repeat(n),o=t,s=[t.type,t.id],i=Ca(o);for(let[a,d]of Uo[t.type]){if(i!==void 0&&uy(a)){a===Bt[0]&&s.push(`radius=${cy(i)}`);continue}let c=o[a];if(c!==void 0){if(d==="boolean"){c===!0&&s.push(a);continue}s.push(`${a}=${Xe(c)}`)}}if(e.push(r+s.join(" ")),t.type==="text"&&ly(e,t.content,n+1),t.type==="instance"){YS(e,t,n+1);return}if(me(t))for(let a of te(t))Il(e,a,n+1)}function uy(e){return Bt.includes(e)}function cy(e){return`"${e.map(K).join(" ")}"`}function YS(e,t,n){let r=rt.repeat(n),o=s=>Uo[s].map(([i])=>i);for(let[s,i]of qs(t,o)){let a=[Za,s],d=Ca(Object.fromEntries(i));for(let[l,p]of i)if(l!=="content"){if(d!==void 0&&uy(l)){l===Bt[0]&&a.push(`radius=${cy(d)}`);continue}typeof p=="boolean"?a.push(p?l:`${l}=false`):a.push(`${l}=${Xe(p)}`)}e.push(r+a.join(" "));let c=i.find(([l])=>l==="content")?.[1];c!==void 0&&ly(e,c,n+1)}}function ly(e,t,n){let r=rt.repeat(n),o=typeof t=="string"?[t]:t;for(let s of o){if(typeof s=="string"){e.push(r+JSON.stringify(s));continue}e.push(r+[JSON.stringify(s.text),...JS(s)].join(" "))}}function JS(e){let t=[];for(let[n,r]of hi){let o=e[n];if(o!==void 0){if(r==="boolean"){o===!0&&t.push(n);continue}t.push(`${n}=${Xe(o)}`)}}return t}var Kr="--- payload base64 ---",fy="sha256-";function py(e){let t=ZS(e);return t===-1?{head:e,payload:""}:{head:e.slice(0,t),payload:e.slice(t+Kr.length)}}function Bl(e){let{head:t,payload:n}=py(e);return{head:t,blocks:hy(n)}}function Vl(e,t){let n=new Map;for(let r of QS(e)){let o=t.get(r);o!==void 0&&n.set(r,o)}return n.size===0?e:`${e.trimEnd()}
34
34
 
35
- ${tm(n)}`}function em(e){let t=new Map;for(let n of e.split(`
36
- `)){let r=n.indexOf(" ");if(r===-1)continue;let o=n.slice(0,r);o.startsWith(Zp)&&t.set(o,n.slice(r+1).trim())}return t}function tm(e){let t=[...e.entries()].sort(([n],[r])=>n<r?-1:n>r?1:0).map(([n,r])=>`${n} ${r}`);return`${Kn}
35
+ ${my(n)}`}function hy(e){let t=new Map;for(let n of e.split(`
36
+ `)){let r=n.indexOf(" ");if(r===-1)continue;let o=n.slice(0,r);o.startsWith(fy)&&t.set(o,n.slice(r+1).trim())}return t}function my(e){let t=[...e.entries()].sort(([n],[r])=>n<r?-1:n>r?1:0).map(([n,r])=>`${n} ${r}`);return`${Kr}
37
37
  ${t.join(`
38
38
  `)}
39
- `}async function zd(e){let t=await crypto.subtle.digest("SHA-256",e),n=[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0"));return`${Zp}${n.join("")}`}function jd(e,t){return`data:${e};base64,${t}`}function Kd(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 Gd(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 Jv(e){if(e.startsWith(Kn))return 0;let t=e.indexOf(`
40
- ${Kn}`);return t===-1?-1:t+1}function Zv(e){let t=new Set;for(let n of e.matchAll(/sha256-[0-9a-f]{64}/g))t.add(n[0]);return t}function qd(e){return(t,n,r,o)=>{e.push({severity:"error",code:n,message:`Line ${t}: ${r}`,...o===void 0?{}:{nodeId:o}})}}function Wd(e){let t=[],n=e.split(`
41
- `);for(let r=0;r<n.length;r+=1){let o=n[r],s=o.trim();if(s===Kn)break;if(s===""||s.startsWith("```"))continue;let i=o.length-o.trimStart().length;t.push({number:r+1,indent:Math.floor(i/2),text:s,words:Up(s)})}return t}function Xd(e){let t=[],n=[],r,o=()=>{r&&r.runs.length>0&&(r.props.content=rm(r.runs)),r=void 0},s=i=>{for(o();t.length>0&&t[t.length-1].indent>=i;)tb(t.pop())};return{push(i){let d=i.words[0];if(d.startsWith('"')&&r&&i.indent>r.indent){let m=nm(i,e);return m!==void 0&&r.runs.push(m),!0}if(d===Ys){s(i.indent);let m=t[t.length-1];return!m||m.type!=="instance"?(e(i.number,"invalid-override","An override line must sit inside an instance"),!0):(r=eb(m,i,e),!0)}if(d.startsWith('"')){let m=t[t.length-1];if(!m||m.type!=="text")return e(i.number,"invalid-content","A quoted line must sit inside a text node"),!0;let y=nm(i,e);return y!==void 0&&m.runs.push(y),!0}if(!qs(d))return!1;s(i.indent);let l=i.words[1];if(l===void 0||l.includes("="))return e(i.number,"missing-id",`A ${d} needs an id`),!0;let f=Qv(d,l,i.words.slice(2),i,e),p=t[t.length-1];return p?.type==="instance"?e(i.number,"invalid-override",`${p.record.id} takes its contents from its component \u2014 change the component, or write an override line`,l):p?p.children.push(f.record):n.push(f.record),t.push(f),!0},finish(){return s(0),n}}}function Qv(e,t,n,r,o){let s={type:e,id:t},i=[];for(let d=0;d<n.length;d+=1){let{key:l,value:f}=Ke(n[d]),p=Ws(e,l);if(p===void 0){let y=Js(n,d,n[d-1]);y?(o(r.number,"invalid-value",y.message,t),d=y.end-1):o(r.number,"invalid-value",`${e} has no property "${l}"`,t);continue}let m=je(f??"",p);"error"in m?o(r.number,"invalid-value",`${l}: ${m.error}`,t):s[l]=m.value}return Es(e)&&(s.children=i),e==="text"&&(s.content=""),{indent:r.indent,type:e,record:s,children:i,runs:[]}}function eb(e,t,n){let r=e.record.id,o=t.words[1];if(o===void 0||o.includes("=")){n(t.number,"invalid-override","An override names the part it changes, e.g. override item.title fill=accent",r);return}let s=e.record.overrides??={},i=s[o]??={},d=t.words.slice(2);for(let l=0;l<d.length;l+=1){let{key:f,value:p}=Ke(d[l]),m=mn(f)?Xs(f):void 0;if(m===void 0){let v=Js(d,l,d[l-1]);v?(n(t.number,"invalid-value",v.message,r),l=v.end-1):f==="content"?n(t.number,"invalid-value","Write the text as quoted lines under the override",r):n(t.number,"invalid-value",`An override cannot set "${f}"`,r);continue}let y=je(p??"",m);"error"in y?n(t.number,"invalid-value",`${f}: ${y.error}`,r):i[f]=y.value}return{indent:t.indent,props:i,runs:[]}}function tb(e){if(e.type==="text"&&(e.record.content=rm(e.runs)),e.type==="instance"){let t=e.record.overrides;for(let[n,r]of Object.entries(t??{}))Object.keys(r).length===0&&delete t?.[n];t&&Object.keys(t).length===0&&delete e.record.overrides}}function rm(e){if(e.length===0)return"";let t=e[0];return e.length===1&&typeof t=="string"?t:[...e]}function nm(e,t){let n=Pt(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:s,value:i}=Ke(o),d=$o.find(([f])=>f===s);if(!d){t(e.number,"invalid-run",`A run has no mark "${s}"`);continue}let l=je(i??"",d[1]);"error"in l?t(e.number,"invalid-run",`${s}: ${l.error}`):r[s]=l.value}return r}function Lo(e){let t=[],n=qd(t),r=hn,o,s=!1,i={},d={},l={},f=Xd(n),p=Dd(n,t),m,y={},v=!1,C=!1,S={},g=new Map,L,A=!1,I=()=>{if(!L)return;let T=L;L=void 0;let G=g.get(T.page);if(G!==void 0){n(T.number,"invalid-motion",`motion ${T.page} is written twice \u2014 put its lines in the block on line ${G}`,T.page);return}g.set(T.page,T.number);for(let[re,E]of T.where)g.set(`${T.page} ${re}`,E);let Y=Rd(T);Y&&(S[T.page]=Y)};for(let T of Wd(e)){let G=T.words[0];if(L&&T.indent>0){Id(L,T,n);continue}if(!(A&&T.indent>0)){if(A=!1,I(),G==="motion"&&T.indent===0){m=void 0,L=Nd(T,n),A=L===void 0;continue}if(p.take(T)){m=void 0;continue}if(G==="version"){s=!0,ob(T,t);continue}if(G==="kind"&&T.indent===0){r=sb(T,t);continue}if(G==="title"&&T.indent===0){o=om(T,n);continue}if(G==="theme"&&T.indent===0){m=void 0,v=!0,C&&n(T.number,"invalid-theme","theme dark is written twice \u2014 keep one block"),C=!0,(T.words[1]!=="dark"||T.words.length>2)&&n(T.number,"invalid-theme","Expected theme dark on its own line, with the tokens that differ indented under it");continue}if(G.startsWith("$")){if(m=void 0,v&&T.indent>0){Yd(T,y,n);continue}v=!1,Yd(T,i,n);continue}if(T.indent===0)v=!1;else if(v){n(T.number,"invalid-theme","A theme block holds only $name = value lines");continue}if(G==="asset"&&T.indent===0){m=void 0,ib(T,l,n);continue}if(G==="font"&&T.indent===0){m=db(T,d,n);continue}if((G==="fallback"||G==="face")&&m){ub(G,T,m,n);continue}m=void 0,!f.push(T)&&n(T.number,"unknown-node-type",`Unknown statement "${G}"`)}}I();let U=rb(p.finish(),r,t),j=Ot({dark:y}),R={...U===void 0?{}:{brand:U},...j===void 0?{}:{themes:j}},q=nb(f.finish(),t),$=Object.keys(S).length===0?{}:{motion:S},V=(T,G)=>g.get(G===void 0?T:`${T} ${G}`);if(!q){s||t.push({severity:"error",code:"invalid-document",message:"No nodes found"});let T=ur({id:$t,children:[]}),G=po({kind:r,...o===void 0?{}:{title:o},tokens:i,fonts:d,assets:l,...$,...R,root:T});return t.push(...xr(G,V)),{document:G,problems:t}}let b=Vt(q),D={version:it({kind:r,fonts:d,...R,root:b}),kind:r,...o===void 0?{}:{title:o},tokens:i,fonts:d,assets:l,...$,...R,root:b};return t.push(...xr(D,V)),{document:D,problems:t}}function nb(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:$t,children:[...e]}}}function rb(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(([i,d])=>i!=="voice"||d.entries.some(l=>l.kind!=="banned")),s=Object.keys(r.roles).length+Object.keys(r.logos).length+o.length+r.review.length;return t!=="brand"&&s>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 ob(e,t){fo.includes(Number(e.words[1]))||t.push({severity:"warning",code:"version-mismatch",message:`Line ${e.number}: expected version ${co} or older, got ${e.words[1]??"nothing"}`})}function sb(e,t){let n=e.words[1];return n!==void 0&&In.includes(n)?n:(t.push({severity:"error",code:"unknown-kind",message:`Line ${e.number}: unknown kind "${n??"nothing"}" \u2014 this build reads ${In.join(", ")}`}),hn)}function om(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('"')?Pt(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 Yd(e,t,n){let{name:r,value:o}=Jd(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 s=je(o,"stringValue");if("error"in s){n(e.number,"invalid-token",`$${r}: ${s.error}`);return}if(typeof s.value!="string"){n(e.number,"invalid-token",`$${r} may not be an expression`);return}t[r]=sm(s.value,o)}function sm(e,t){let n=Number(e);return t.startsWith('"')||!Number.isFinite(n)||e.trim()===""?e:n}function Jd(e){let t=e[0],n=s=>s.startsWith("$")?s.slice(1):s;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 ib(e,t,n){let r=e.words.slice(1),o=r[0],s=r[1]==="=",i=o===void 0?void 0:Ke(o),d=i?.key,l=s?r[2]:i?.value,f=r.slice(s?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 p={};for(let C of f){let{key:S,value:g}=Ke(C);if(g===void 0){n(e.number,"invalid-asset",`Asset "${d}" has a stray word "${C}"`);continue}p[S]=ab(g)}let m=p.hash,y=Number(p.bytes);if(m===void 0||!Number.isFinite(y)){n(e.number,"invalid-asset",`Asset "${d}" needs a hash and a bytes count`);return}let v=p.ms===void 0?void 0:Number(p.ms);if(v!==void 0&&!(Number.isFinite(v)&&v>=0)){n(e.number,"invalid-asset",`Asset "${d}": ms is the track's length, in milliseconds`);return}t[d]={type:l,hash:m,bytes:y,...v===void 0?{}:{ms:v},...p.credit===void 0?{}:{credit:p.credit},...p.source===void 0?{}:{source:p.source},...p.license===void 0?{}:{license:p.license}}}function ab(e){return e.startsWith('"')?Pt(e)??e:e}function db(e,t,n){let{name:r,value:o}=Jd(e.words.slice(1));if(r===void 0||o===void 0){n(e.number,"invalid-font","Expected font <name> = <family>");return}let s=je(o,"string"),i={family:"error"in s?o:s.value};return t[r]=i,{family:i,faces:[]}}var lb=/^[A-Za-z_][\w-]*$/;function ub(e,t,n,r){if(e==="fallback"){let d=je(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 s=o.startsWith("asset=")?o.slice(6):void 0,i={};if(s!==void 0){if(!lb.test(s)){r(t.number,"invalid-font-face",`asset=${s}: not an asset name`);return}i.asset=s}else{let d=je(o,"string");i.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 p=je(f??"",l==="weight"?"number":"fontStyle");"error"in p?r(t.number,"invalid-font-face",`${l}: ${p.error}`):i[l]=p.value}n.faces.push(i),n.family.faces=n.faces}var am="https://getv.design/ns/vd",Z_=`<metadata><vd:document xmlns:vd="${am}" version="1"><![CDATA[
42
- `;var fb=/<vd:document\b[^>]*>([\s\S]*?)<\/vd:document\s*>/;function Zd(e){let t=fb.exec(e);if(!t)return;let n=t[1]??"",r="",o=n;for(;;){let s=o.indexOf("<![CDATA[");if(s===-1){r+=im(o);break}r+=im(o.slice(0,s));let i=o.indexOf("]]>",s);if(i===-1){r+=o.slice(s+9);break}r+=o.slice(s+9,i),o=o.slice(i+3)}return`${r.replace(/^\n/,"").replace(/\n$/,"")}
43
- `}function Qd(e){return/^\uFEFF?\s*</.test(e)}function im(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 el(e){let t=[],n=Ue(e);if(!n)return t.push({severity:"error",code:"invalid-document",message:"Expected an object"}),{document:po(),problems:t};fo.includes(n.version)||t.push({severity:"warning",code:"version-mismatch",message:`Expected version ${co} or older, got ${JSON.stringify(n.version)}`});let r=um(n.root,t);r&&Lb(r,t);let o=r&&Vt(r),s=cb(n.motion,t),i=gb(n.kind,t),d=n.brand===void 0?void 0:Xa(n.brand,v=>{t.push({severity:"error",code:"invalid-brand",message:v})}),l=Ue(Ue(n.themes)?.dark),f=l===void 0?void 0:Ot({dark:dm(l,t)}),p={...d===void 0?{}:{brand:d},...f===void 0?{}:{themes:f}},m=vb(n.fonts,t),y={version:it({kind:i,fonts:m,...p,...o?{root:o}:{}}),kind:i,...typeof n.title=="string"&&n.title.trim()!==""?{title:n.title}:{},tokens:dm(n.tokens,t),fonts:m,assets:yb(n.assets,t),...s===void 0?{}:{motion:s},...p,root:o??ur({id:$t,children:[]})};return t.push(...xr(y)),{document:y,problems:t}}function cb(e,t){if(e===void 0)return;let n=Ue(e),r=s=>{t.push({severity:"error",code:"invalid-motion",message:s})};if(!n){r("`motion` must be an object");return}let o={};for(let[s,i]of Object.entries(n)){let d=Ue(i);if(!d||!Array.isArray(d.lines)){r(`motion ${s} must be an object with a lines array`);continue}let l=d.enter,f=d.duration;if(l!==void 0&&!pr.includes(l)){r(`motion ${s}: enter must be one of ${pr.join(", ")}`);continue}if(f!==void 0&&!xb(f)){r(`motion ${s}: duration must be 0 to ${Tt} milliseconds`);continue}let p=d.scroll;if(p!==void 0&&typeof p!="boolean"){r(`motion ${s}: scroll must be true or false`);continue}let m=d.bpm,y=d.meter;if(m!==void 0&&!(typeof m=="number"&&m>=20&&m<=300)){r(`motion ${s}: bpm must be ${20} to ${300}`);continue}if(y!==void 0&&!(typeof y=="number"&&Number.isInteger(y)&&y>=1&&y<=16)){r(`motion ${s}: meter must be a whole number from 1 to ${16}`);continue}let v=St({...m===void 0?{}:{bpm:m},...y===void 0?{}:{meter:y},lines:[]}),C=hb(d.music,v);if(C===null){r(`motion ${s}: music must be { asset, from?, volume?, fadein?, fadeout?, loop? }`);continue}let S=d.length;if(S!==void 0&&!tl(S,vn,v)){r(`motion ${s}: length must be 0 to ${vn} milliseconds, or beats with a bpm`);continue}let g=I=>I===void 0||typeof I=="number"&&I>=16&&I<=Lt;if(!g(d.w)||!g(d.h)){r(`motion ${s}: w and h must be 16 to ${Lt} pixels`);continue}let L=d.lines.flatMap(I=>{let U=pb(I,v);return U===void 0&&r(`motion ${s}: a line that is not one: ${JSON.stringify(I)}`),U===void 0?[]:[U]}),A={...l===void 0?{}:{enter:l},...f===void 0?{}:{duration:f},...p===!0?{scroll:!0}:{},...S===void 0?{}:{length:S},...d.w===void 0?{}:{w:d.w},...d.h===void 0?{}:{h:d.h},...m===void 0?{}:{bpm:m},...y===void 0?{}:{meter:y},...C===void 0?{}:{music:C},lines:L};jt(A)||(o[s]=A)}return Object.keys(o).length===0?void 0:o}function pb(e,t){let n=Ue(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,y]of jn){let v=n[m];if(v!==void 0){if(!mb(m,y,v,t))return;r[m]=v}}if(r.on!==void 0&&(!t||r.with!==void 0||r.together))return;let{enter:o,exit:s,emphasis:i,step:d,together:l}=r;if(o!==void 0&&s!==void 0||i!==void 0&&(o!==void 0||s!==void 0)||d===!0&&l===!0||["at","after","with","together","step"].filter(m=>r[m]!==void 0).length>1||r.camera===!0&&(o??s??i??r.go)!==void 0)return;let p=r;return mr(p)?p:void 0}function mb(e,t,n,r){switch(t){case"time":return tl(n,e==="at"?vn:Tt,r);case"on":return mo.includes(n);case"boolean":return n===!0;case"number":return typeof n!="number"||!Number.isFinite(n)||n<0?!1:e==="at"?n<=vn:e==="pad"?n<=Lt:n<=Tt;case"string":return typeof n=="string"&&(e!=="go"||zt(n)!==void 0);case"nodeEffect":return go.includes(n);case"emphasisEffect":return yo.includes(n);case"ease":return vo.includes(n);case"piece":return bo.includes(n);case"from":return typeof n=="number"&&Number.isFinite(n)||yn.includes(n);default:return!1}}function hb(e,t){if(e===void 0)return;let n=Ue(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"&&!xo.includes(i))return null;let o=n.from;if(o!==void 0&&!(typeof o=="number"&&o>=0&&o<=fr))return null;let s=n.volume;if(s!==void 0&&!(typeof s=="number"&&s>=0&&s<=1))return null;for(let i of["fadein","fadeout"])if(n[i]!==void 0&&!tl(n[i],Tt,t))return null;if(n.loop!==void 0&&n.loop!==!0)return null;for(let i of xo)n[i]!==void 0&&(r[i]=n[i]);return r}function tl(e,t,n){if(typeof e=="number")return Number.isFinite(e)&&e>=0&&e<=t;if(!Bn(e)||!n)return!1;let r=Rn(e);if(!r||Fn(r.count,r.unit)!==e)return!1;let o=Je(e,n);return o!==void 0&&o<=t}function xb(e){return typeof e=="number"&&e>=0&&e<=Tt}function gb(e,t){return e==null?hn:typeof e=="string"&&In.includes(e)?e:(t.push({severity:"error",code:"unknown-kind",message:`Unknown kind ${JSON.stringify(e)} \u2014 this build reads ${In.join(", ")}`}),hn)}function dm(e,t){let n={};if(e===void 0)return n;let r=Ue(e);if(!r)return t.push({severity:"error",code:"invalid-tokens",message:"`tokens` must be an object"}),n;for(let[o,s]of Object.entries(r))typeof s=="number"||typeof s=="string"?n[o]=s:t.push({severity:"error",code:"invalid-token",message:`Token $${o} must be a number or string`});return n}function yb(e,t){let n={};if(e===void 0)return n;let r=Ue(e);if(!r)return t.push({severity:"error",code:"invalid-assets",message:"`assets` must be an object"}),n;for(let[o,s]of Object.entries(r)){let i=Ue(s);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}:{},...ft(i.credit,"credit"),...ft(i.source,"source"),...ft(i.license,"license")}}return n}function vb(e,t){let n={};if(e===void 0)return n;let r=Ue(e);if(!r)return t.push({severity:"error",code:"invalid-fonts",message:"`fonts` must be an object"}),n;for(let[o,s]of Object.entries(r)){let i=Ue(s);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}:{},...bb(i.faces,o,t)}}return n}function bb(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 s=Ue(o),i=s?.src,d=s?.asset;if(!s||typeof i=="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=s.style;r.push({...typeof i=="string"?{src:i}:{asset:d},...typeof s.weight=="number"?{weight:s.weight}:{},...l==="italic"||l==="normal"?{style:l}:{}})}return r.length>0?{faces:r}:{}}function wb(e,t){let n=Ue(e);if(!n){t.push({severity:"error",code:"invalid-node",message:"Expected a node object"});return}switch(n.type){case"canvas":return um(e,t);case"ellipse":return $b(n,t);case"frame":return kb(n,t);case"group":return _b(n,t);case"image":return Mb(n,t);case"instance":return Sb(n,t);case"rect":return Ab(n,t);case"text":return Tb(n,t);case"vector":return Ob(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 um(e,t){let n=Ue(e);if(!n){t.push({severity:"error",code:"invalid-node",message:"`root` must be a canvas node"});return}let r=Jt(n,$t,t);return{type:"canvas",id:r,...ft(n.name,"name"),...lm(n,"w",1280,r,t),...lm(n,"h",720,r,t),...vt(n.background,r,"background",t),children:nl(n.children,r,t)}}function lm(e,t,n,r,o){return e[t]===void 0?{}:{[t]:Se(e[t],r,t,n,o)}}function kb(e,t){let n=Jt(e,"frame",t);return{type:"frame",id:n,...ft(e.name,"name"),x:Se(e.x,n,"x",0,t),y:Se(e.y,n,"y",0,t),w:Se(e.w,n,"w",0,t),h:Se(e.h,n,"h",0,t),...vt(e.background,n,"background",t),...Qs(e.clip,"clip"),...Qs(e.skip,"skip"),...Qs(e.component,"component"),...Cr(e,n,t),...wn(e),children:nl(e.children,n,t)}}function _b(e,t){let n=Jt(e,"group",t);return{type:"group",id:n,...ft(e.name,"name"),...wn(e),children:nl(e.children,n,t)}}function Sb(e,t){let n=Jt(e,"instance",t),r=e.component;(typeof r!="string"||r==="")&&t.push({severity:"error",code:"invalid-value",message:"An instance needs the id of the component it places",nodeId:n,prop:"component"});let o=Eb(e.overrides,n,t);return{type:"instance",id:n,...ft(e.name,"name"),component:typeof r=="string"?r:"",x:Se(e.x,n,"x",0,t),y:Se(e.y,n,"y",0,t),...Pe(e.w,n,"w",t),...Pe(e.h,n,"h",t),...o===void 0?{}:{overrides:o},...wn(e),children:[]}}function Eb(e,t,n){if(e===void 0)return;let r=Ue(e);if(!r){n.push({severity:"error",code:"invalid-value",message:"`overrides` must be an object of inner id to properties",nodeId:t,prop:"overrides"});return}let o={};for(let[s,i]of Object.entries(r)){let d=Ue(i);if(!d)continue;let l={};for(let[f,p]of Object.entries(d)){let m=Cb(f,p,t,n);m!==void 0&&(l[f]=m)}Object.keys(l).length>0&&(o[s]=l)}return Object.keys(o).length===0?void 0:o}function Cb(e,t,n,r){let o=()=>{r.push({severity:"error",code:"invalid-value",message:`${n} overrides ${e} with ${JSON.stringify(t)}, which it cannot hold`,nodeId:n,prop:e})};if(!mn(e))return o();if(e==="content")return typeof t=="string"||Array.isArray(t)&&t.every(l=>typeof l=="string"||typeof l=="object"&&l!==null&&typeof l.text=="string")?fm(t,n,r):o();let s=Xs(e);if(s===void 0)return o();if(s==="numberValue")return cm(t)??o();if(s==="stringValue")return typeof t!="string"?o():t.startsWith("=")?kt(t.slice(1)):t;if(s==="boolean")return typeof t=="boolean"?t:o();if(s==="number")return typeof t=="number"&&Number.isFinite(t)?t:o();if(typeof t!="string")return o();let i=je(JSON.stringify(t),s);return"error"in i?o():i.value}function nl(e,t,n){let r=[];if(Array.isArray(e))for(let o of e){let s=wb(o,n);s&&r.push(s)}else e!==void 0&&n.push({severity:"error",code:"invalid-children",message:"`children` must be an array",nodeId:t});return r}function Mb(e,t){let n=Jt(e,"image",t),r=e.fit,o=vt(e.src,n,"src",t);return{type:"image",id:n,...ft(e.name,"name"),x:Se(e.x,n,"x",0,t),y:Se(e.y,n,"y",0,t),w:Se(e.w,n,"w",100,t),h:Se(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),src:o.src??"",...pn.includes(r)?{fit:r}:{},...Pe(e.radius,n,"radius",t),...Pe(e.opacity,n,"opacity",t),...Cr(e,n,t),...wn(e)}}function Ab(e,t){let n=Jt(e,"rect",t);return{type:"rect",id:n,...ft(e.name,"name"),x:Se(e.x,n,"x",0,t),y:Se(e.y,n,"y",0,t),w:Se(e.w,n,"w",100,t),h:Se(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...vt(e.fill,n,"fill",t),...vt(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.radius,n,"radius",t),...Pe(e.opacity,n,"opacity",t),...Cr(e,n,t),...wn(e)}}function $b(e,t){let n=Jt(e,"ellipse",t);return{type:"ellipse",id:n,...ft(e.name,"name"),x:Se(e.x,n,"x",0,t),y:Se(e.y,n,"y",0,t),w:Se(e.w,n,"w",100,t),h:Se(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...vt(e.fill,n,"fill",t),...vt(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.opacity,n,"opacity",t),...Cr(e,n,t),...wn(e)}}function Ob(e,t){let n=Jt(e,"vector",t);return{type:"vector",id:n,...ft(e.name,"name"),x:Se(e.x,n,"x",0,t),y:Se(e.y,n,"y",0,t),w:Se(e.w,n,"w",100,t),h:Se(e.h,n,"h",100,t),...Pe(e.rotation,n,"rotation",t),...ft(e.view,"view"),d:typeof e.d=="string"?e.d:"",...vt(e.fill,n,"fill",t),...vt(e.stroke,n,"stroke",t),...Pe(e.strokeWidth,n,"strokeWidth",t),...Pe(e.opacity,n,"opacity",t),...Er(e.rule,Ln,n,"rule",t),...Er(e.cap,Dn,n,"cap",t),...Er(e.join,Pn,n,"join",t),...Cr(e,n,t),...wn(e)}}function Tb(e,t){let n=Jt(e,"text",t);return{type:"text",id:n,...ft(e.name,"name"),x:Se(e.x,n,"x",0,t),y:Se(e.y,n,"y",0,t),w:Se(e.w,n,"w",200,t),h:Se(e.h,n,"h",40,t),...Pe(e.rotation,n,"rotation",t),content:fm(e.content,n,t),...vt(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),...Er(e.align,fn,n,"align",t),...Er(e.valign,cn,n,"valign",t),...Qs(e.italic,"italic"),...vt(e.fill,n,"fill",t),...Pe(e.opacity,n,"opacity",t),...Cr(e,n,t),...wn(e)}}function fm(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 s=Ue(o);if(!s||typeof s.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:s.text,...Yt(s,"font","string"),...Yt(s,"size","number"),...Yt(s,"weight","number"),...Yt(s,"italic","boolean"),...Yt(s,"underline","boolean"),...Yt(s,"strike","boolean"),...Yt(s,"fill","string"),...Yt(s,"letterSpacing","number"),...Yt(s,"link","string")})}return r}function Yt(e,t,n){let r=e[t];return typeof r!==n?{}:n==="number"&&!Number.isFinite(r)?{}:{[t]:r}}function Cr(e,t,n){return{...Er(e.blend,Tn,t,"blend",n),...vt(e.shadow,t,"shadow",n)}}function wn(e){return{...e.hidden===!0?{hidden:!0}:{},...e.locked===!0?{locked:!0}:{}}}function Qs(e,t){return typeof e=="boolean"?{[t]:e}:{}}function Er(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 Jt(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 Se(e,t,n,r,o){let s=cm(e);return s!==void 0?s:(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 cm(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.startsWith("="))return kt(e.slice(1))}function Pe(e,t,n,r){return e===void 0?{}:{[n]:Se(e,t,n,0,r)}}function vt(e,t,n,r){return e===void 0?{}:typeof e=="string"?{[n]:e.startsWith("=")?kt(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 ft(e,t){return typeof e=="string"?{[t]:e}:{}}function Lb(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),fe(o)&&o.children.forEach(r)};r(e)}function Ue(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}var pm=1500,rl=5e3,mm=1200,hm=800,xm=600,gm=800,ym={letter:30,word:80,children:100},Do=.04,Po=.85,ol=1.06,ei=[.2,0,0,1],ti=[.4,0,1,1],ni=[.4,0,.2,1],vm=[.34,1.56,.64,1],Db={out:ei,in:ti,inout:ni,linear:null,spring:vm};function sl(e,t){let n=e.motion?.[t],r=n?.w!==void 0||n?.h!==void 0?Pb(e,t,n):void 0,o=St(n),s=o?{tempo:o}:{},i=md(n,e.assets);if(!n||!Kt(e).has(t))return{page:t,length:Je(n?.length,o,rl),beats:[],camera:!1,steps:[],...r?{size:r}:{},...s,clips:i};let d=yt(e),l=[],f=[],p,m=new Map;for(let[C,S]of n.lines.entries()){if(d.get(S.id)!==t||S.camera!==!0&&S.enter===void 0&&S.exit===void 0&&S.emphasis===void 0)continue;let g=F(e.root,S.id);if(!g)continue;let L=G=>G===void 0?void 0:m.get(G),A;S.at!==void 0?A=Je(S.at,o,0):S.with!==void 0&&L(S.with)?A=L(S.with).start:S.after!==void 0&&L(S.after)?A=L(S.after).end:S.together===!0?A=p?.start??0:A=p?.end??0,A+=Je(S.delay,o,0);let I;if(S.on!==void 0&&o){let G=ld(A,S.on,o);G!==A&&(I=A),A=G}S.step===!0&&f.push(A);let U=S.camera===!0?"camera":S.enter!==void 0?"enter":S.exit!==void 0?"exit":"emphasis",j=S.enter??S.exit??S.emphasis,R=Nb(S,j,o),q=U==="camera"||U==="emphasis"?void 0:Ib(S,g),$=q===void 0?1:Math.max(1,bm(g,q)),V=$>1&&q!==void 0?Je(S.stagger,o,ym[q]):0,b=A+($-1)*V+R,D=S.ease??(U==="enter"?"out":U==="exit"?"in":"inout");l.push({index:C,line:S,kind:U,...I===void 0?{}:{asked:I},...j===void 0?{}:{effect:j},start:A,end:b,duration:R,ease:D,pieces:$,stagger:V,...q===void 0||$===1?{}:{split:q}});let T=b;if(U==="enter"&&S.hold!==void 0&&S.enter!=="count"){let G=b+Je(S.hold,o,0);T=G+R,l.push({index:C,line:S,kind:"exit",...j===void 0?{}:{effect:j},start:G,end:T,duration:R,ease:"in",pieces:1,stagger:0})}p={start:A,end:T},S.camera!==!0&&m.set(S.id,p)}let y=Math.max(0,...l.map(C=>C.end)),v=Je(n.length,o,l.length===0?rl:y+pm);return{page:t,length:v,beats:l,camera:l.some(C=>C.kind==="camera"),steps:f,...r?{size:r}:{},...s,clips:i}}function Pb(e,t,n){let r=n.w,o=n.h;if(r!==void 0&&o!==void 0)return{w:r,h:o};let s=F(e.root,t),i=s&&"w"in s&&typeof s.w=="number"?s.w:void 0,d=s&&"h"in s&&typeof s.h=="number"?s.h:void 0;if(r!==void 0)return{w:r,h:i&&d?Math.round(r*d/i):r};if(o!==void 0)return{w:i&&d?Math.round(o*i/d):o,h:o}}function Nb(e,t,n){return t==="cut"?0:e.duration!==void 0?Je(e.duration,n,wo):e.camera===!0?gm:e.emphasis!==void 0?xm:t==="count"?mm:t==="draw"?hm:wo}function Ib(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&&ne(t).length>0)return"children"}function bm(e,t){return t==="children"?ne(e).length:e.type!=="text"?1:t==="word"?il(bn(e.content)).length:wm(bn(e.content)).length}function il(e){return e.split(/\s+/).filter(t=>t!=="")}function wm(e){return[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(e)].map(n=>n.segment).filter(n=>n.trim()!=="")}function ri(e,t){if(t<=0)return 0;if(t>=1)return 1;let n=Db[e];return n===null?t:Rb(n,t)}function Rb(e,t){let[n,r,o,s]=e,i=(p,m,y)=>3*p*y*(1-y)**2+3*m*y*y*(1-y)+y**3,d=0,l=1,f=t;for(let p=0;p<40;p++){f=(d+l)/2;let m=i(n,o,f);if(Math.abs(m-t)<1e-7)break;m<t?d=f:l=f}return i(r,s,f)}function al(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(",",""),s=o.includes(".")?o.split(".")[1].length:0;return{before:e.slice(0,t.index),value:Number(o),decimals:s,grouping:r,after:e.slice(t.index+n.length)}}function dl(e,t){let n=Math.abs(t).toFixed(e.decimals),[r,o]=n.split("."),s=e.grouping===""?r:r.replace(/\B(?=(\d{3})+(?!\d))/g,e.grouping),i=t<0&&Number(n)!==0?"-":"";return`${e.before}${i}${s}${o===void 0?"":`.${o}`}${e.after}`}var km=1200,_m=3.5;function Sm(e){return Math.max(km,Math.round(il(e).length/_m*1e3))}function ll(e){let t=[];for(let n of Object.keys(e.motion??{})){let r=e.motion?.[n];if(!Hn(r)||!Kt(e).has(n))continue;let o=sl(e,n);t.push(...Fb(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 ${ho(i.start)}, after the video ends at ${ho(o.length)}`,nodeId:i.line.id});let s=new Map;for(let i of o.beats)if(i.kind==="enter"&&!s.has(i.line.id))s.set(i.line.id,{from:i.start,to:o.length});else if(i.kind==="exit"){let d=s.get(i.line.id);s.set(i.line.id,{from:d?.from??0,to:i.start})}for(let[i,{from:d,to:l}]of s){let f=F(e.root,i);if(f?.type!=="text")continue;let p=bn(f.content),m=Sm(p);l-d<m&&t.push({severity:"warning",code:"video-text-brief",message:`motion ${n}: ${i} is on screen for ${ho(l-d)}; "${Bb(p)}" takes about ${m} ms to read`,nodeId:i})}}return t}function Fb(e,t,n){let r=e.motion?.[t]?.music,o=n.clips[0];if(!r||!o)return[];let s=(y,v)=>({severity:"warning",code:y,message:`motion ${t}: ${v}`,nodeId:t}),i=y=>`${(y/1e3).toFixed(2)} s`,d=e.assets[r.asset];if(!d)return[s("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[s("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(s("music-from-past-end",`from=${f} is past the end of ${r.asset}, which is ${i(d.ms)} long`)):d.ms!==void 0&&!o.loop&&d.ms-f<n.length-ud&&l.push(s("music-short",`${r.asset} runs out at ${i(d.ms-f)} and the video at ${i(n.length)}: add loop, or set length=`));let p=d.ms!==void 0&&d.ms>0?d.bytes*8/d.ms:void 0,m=2*(n.length+f)*fd/1e3;return p!==void 0&&p>cd?l.push(s("audio-heavy",`${r.asset} is ${Math.round(p)} kbps: re-encode it as a 128 kbps MP3 or M4A, about 1 MB a minute`)):d.bytes>m&&l.push(s("audio-heavy",`${r.asset} is ${(d.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`)),l}function Bb(e){return e.length>40?`${e.slice(0,37)}\u2026`:e}function oi(e){return/^\s*(linear|radial|conic|repeating-[a-z]+)-gradient\s*\(/i.test(e)}function No(e){let t=e.trim(),n=/^([a-z-]+)-gradient\s*\(([\s\S]*)\)$/i.exec(t);if(!n)return oi(t)?{error:'A gradient needs its closing ")"'}:{kind:"solid",colour:t};let r=n[1].toLowerCase(),o=Hb(n[2]).map(s=>s.trim());if(o.some(s=>s===""))return{error:"A gradient has an empty argument"};if(r==="linear"){let s=Vb(o[0]),i=Cm(s===void 0?o:o.slice(1));return"error"in i?i:{kind:"linear",angle:s??180,stops:i.stops}}if(r==="radial"){let s=jb(o[0]);if(s&&"error"in s)return s;let i=Cm(s?o.slice(1):o);return"error"in i?i:{kind:"radial",shape:s?.shape??"ellipse",cx:s?.cx??.5,cy:s?.cy??.5,stops:i.stops}}return{error:`${r}-gradient is not supported; use linear-gradient or radial-gradient`}}function ul(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,s=r;for(;t[s]===void 0;)s+=1;let i=t[o],d=t[s];for(let l=r;l<s;l+=1)t[l]=i+(d-i)*(l-o)/(s-o);r=s}return e.map((r,o)=>({colour:r.colour,at:t[o]}))}function Hb(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o+=1){let s=e[o];s==="("?n+=1:s===")"?n=Math.max(0,n-1):s===","&&n===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}var Ub={top:[0,-1],bottom:[0,1],left:[-1,0],right:[1,0]};function Vb(e){let t=/^(-?\d*\.?\d+)(deg|turn|rad)$/i.exec(e);if(t){let s=Number(t[1]),i=t[2].toLowerCase();return i==="turn"?s*360:i==="rad"?s*180/Math.PI:s}let n=/^to\s+([a-z]+)(?:\s+([a-z]+))?$/i.exec(e);if(!n)return;let r=0,o=0;for(let s of[n[1],n[2]]){if(s===void 0)continue;let i=Ub[s.toLowerCase()];if(!i)return;r+=i[0],o+=i[1]}return(Math.atan2(r,-o)*180/Math.PI+360)%360}var zb={left:0,top:0,center:.5,right:1,bottom:1};function jb(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=Em(t[2]),o=t[3]===void 0?.5:Em(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 Em(e){let t=zb[e.toLowerCase()];if(t!==void 0)return t;let n=/^(-?\d*\.?\d+)%$/.exec(e);return n?Number(n[1])/100:void 0}function Cm(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&&Kb(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 Kb(e){let t=0;for(let n of e)if(n==="("&&(t+=1),n===")"&&(t-=1),t<0)return!1;return t===0}function si(e){let t=No(e);return"error"in t?[]:t.kind==="solid"?[t.colour]:t.stops.map(n=>n.colour)}function Mr(e){let t=e.trim();if(t===""||t==="none")return{shadows:[]};let n=[];for(let r of Gb(t)){let o=qb(r.trim());if(o.includes("inset"))return{error:"Inner shadows (inset) are not supported yet"};let s=[],i=[];for(let m of o){let y=/^(-?\d*\.?\d+)(px)?$/.exec(m);y&&i.length===0?s.push(Number(y[1])):i.push(m)}if(s.length<2||s.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[d=0,l=0,f=0,p=0]=s;if(f<0)return{error:"A shadow cannot have a negative blur"};n.push({x:d,y:l,blur:f,spread:p,colour:i[0]})}return{shadows:n}}function Gb(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o+=1){let s=e[o];s==="("?n+=1:s===")"?n=Math.max(0,n-1):s===","&&n===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}function qb(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 fl=["rect","ellipse","vector","image","text"];function ct(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function at(e,t,n){if(n===0)return e;let r=n*Math.PI/180,o=Math.cos(r),s=Math.sin(r),i=e.x-t.x,d=e.y-t.y;return{x:t.x+i*o-d*s,y:t.y+i*s+d*o}}function Io(e,t,n=ct(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=>at(l,n,t)),o=r.map(l=>l.x),s=r.map(l=>l.y),i=Math.min(...o),d=Math.min(...s);return{x:i,y:d,w:Math.max(...o)-i,h:Math.max(...s)-d}}function Ro(e){let t=(e%360+360)%360,n=Math.round(t*100)/100;return n===360?0:n}var cl=["x","y","w","h","left","right","top","bottom","cx","cy"];function Fo(e){return cl.includes(e)}var pl=["parent","prev","next","self","root"];function ml(e){return pl.includes(e)}var Ze=class extends Error{position;constructor(t,n){super(t),this.position=n,this.name="ExprSyntaxError"}},Am=/[A-Za-z_]/,hl=/[A-Za-z0-9_]/;function xl(e){let t=[],n=0,r=()=>{if(!Am.test(e[n]??""))throw new Ze(`Expected a name at position ${n}`,n);let i=n;for(;n<e.length&&hl.test(e[n]??"");)n++;return e.slice(i,n)},o=()=>{if(!hl.test(e[n]??""))throw new Ze(`Expected a name at position ${n}`,n);let i=n;for(;n<e.length&&hl.test(e[n]??"");)n++;return e.slice(i,n)},s=()=>{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 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 Ze(`Bad number "${l}"`,d);e[n]==="%"?(n++,t.push({type:"percent",value:f})):t.push({type:"number",value:f});continue}if(i==="$"){n++,t.push({type:"token",name:r()});continue}if(i==="@"){n++,t.push({type:"ref",path:s()});continue}if(Am.test(i)){t.push({type:"word",path:s()});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 Zb={"+":1,"-":1,"*":2,"/":2};function pt(e){try{let t=xl(e),n=new gl(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 gl=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"||!Qb(r.value))break;let o=Zb[r.value];if(o<t)break;this.next();let s=this.parseBinary(o+1);n={kind:"binary",op:r.value,left:n,right:s}}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||!ml(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 Qb(e){return e==="+"||e==="-"||e==="*"||e==="/"}var $m={"+":1,"-":1,"*":2,"/":2},Om=3,e0=4;function t0(e){return e.kind==="binary"?$m[e.op]??1:e.kind==="unary"?Om:e0}function Gn(e){return ii(e,0)}function ii(e,t){let n=n0(e);return t0(e)<t?`(${n})`:n}function n0(e){switch(e.kind){case"number":return se(e.value);case"percent":return`${se(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}${ii(e.operand,Om)}`;case"binary":{let t=$m[e.op]??1;return`${ii(e.left,t)} ${e.op} ${ii(e.right,t+1)}`}}}function yl(e){return e.slice(0,-1).join(".")}function Nt(e,t){switch(e.kind){case"nodeRef":{let n=e.path[e.path.length-1],r=t(yl(e.path));return n===void 0||r===void 0?e:{kind:"nodeRef",path:[...r.split("."),n]}}case"unary":return{...e,operand:Nt(e.operand,t)};case"binary":return{...e,left:Nt(e.left,t),right:Nt(e.right,t)};default:return e}}function Zt(e){let t=new Set,n=new Set,r=o=>{switch(o.kind){case"nodeRef":t.add(yl(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 nt(e,t){return`${e} ${t}`}function vl(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 ai(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 bl(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 wl(e,t,n){let r=m=>{let y=[];for(let v=n.parentOf.get(m);v!==void 0;v=n.parentOf.get(v))y.push(v);return y},o=r(e),s=r(t),i=new Set(s),d=o.find(m=>i.has(m)),l=m=>d===void 0?m:m.slice(0,m.indexOf(d)),f=new Map([[e,1]]),p=(m,y)=>{let v=(f.get(m)??0)+y;v===0?f.delete(m):f.set(m,v)};for(let m of l(o))p(m,1);for(let m of l(s))p(m,-1);return f}function kl(e){switch(e){case"right":case"bottom":return 1;case"cx":case"cy":return .5;default:return 0}}function di(e){if(e==="x"||e==="w")return"w";if(e==="y"||e==="h")return"h"}function Bo(e){let t=new Map,n=new Map,r=new Map,o=new Map,s=new Map,i=[];oe(e.root,(m,y)=>{if(t.has(m.id)||t.set(m.id,m),i.push(m),y){n.set(m.id,y.id);let v=s.get(y.id)??[],C=y.type==="instance"?[y.id,...v]:v;C.length>0&&s.set(m.id,C)}fe(m)&&m.children.forEach((v,C)=>{let S=m.children[C-1],g=m.children[C+1];S&&r.set(v.id,S.id),g&&o.set(v.id,g.id)})});let d=new Map;for(let m of i){let y=n.get(m.id);for(;y!==void 0;){let v=t.get(y);if(!v||!$e(v))break;y=n.get(y)}y!==void 0&&d.set(m.id,y)}let l=new Map,f=new Map,p=m=>{if(fe(m)){if(!$e(m)){let y=Tm(m);y.forEach((v,C)=>{let S=y[C-1],g=y[C+1];S&&l.set(v.id,S.id),g&&f.set(v.id,g.id)})}for(let y of m.children)p(y)}};return p(e.root),{rootId:e.root.id,byId:t,parentOf:n,prevOf:r,nextOf:o,layoutParentOf:d,layoutPrevOf:l,layoutNextOf:f,scopeOf:s,order:i}}function Tm(e){let t=[];for(let n of e.children)fe(n)&&$e(n)?t.push(...Tm(n)):t.push(n);return t}function li(e,t,n){if(e.kind==="relRef"){let s=r0(e.word,t,n);return s===void 0?{ok:!1,message:`${t} has no ${e.word}`}:{ok:!0,nodeId:s,edge:e.edge}}let r=e.path[e.path.length-1]??"",o=e.path.slice(0,-1).join(".");if(!Fo(r))return{ok:!1,message:`"${r}" is not an edge of @${o}`};for(let s of n.scopeOf.get(t)??[]){let i=`${s}.${o}`;if(n.byId.has(i))return{ok:!0,nodeId:i,edge:r};let d=n.byId.get(s);if(d?.type==="instance"&&d.component===o)return{ok:!0,nodeId:s,edge:r}}return n.byId.has(o)?{ok:!0,nodeId:o,edge:r}:{ok:!1,message:`No node @${o}`}}function r0(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=[...ao(e.root)],n=Bo(e),r=Lm(n),o=new Set;Dm(r,t),Pm(r,e,n,o,t);let s=s0(r);i0(r,s,t);let i=a0(r,s,e,n,o,t);return{nodes:l0(e.root,i,r,t),problems:t}}function qn(e){let t=Bo(e),n=Lm(t),r=[];Dm(n,r),Pm(n,e,t,new Set,r);let o=new Map;for(let s of n.values())for(let i of s.deps){let d=o.get(i),l={nodeId:s.nodeId,prop:s.prop};d?d.push(l):o.set(i,[l])}return o}function Lm(e){let t=new Map;for(let n of e.order){let r=n;for(let o of Ct(n)){let s=r[o]??o0(n,o,e);s!==void 0&&t.set(nt(n.id,o),{nodeId:n.id,prop:o,value:s,deps:[]})}}return t}function o0(e,t,n){if(!(e.type!=="instance"||t!=="w"&&t!=="h")&&n.byId.get(e.component)?.type==="frame")return kt(`@${e.component}.${t}`)}function Dm(e,t){for(let n of e.values()){if(!ye(n.value))continue;let r=pt(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 Pm(e,t,n,r,o){for(let s of e.values()){if(!s.ast)continue;let i=new Set,d=l=>{switch(l.kind){case"number":return;case"token":{let f=st(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:s.nodeId,prop:s.prop});return}case"percent":{let f=di(s.prop);if(!f)return;let p=n.layoutParentOf.get(s.nodeId),m=p===void 0?void 0:nt(p,f);if(m===void 0||!e.has(m)){o.push({severity:"error",code:"percent-without-parent",message:`${s.nodeId}.${s.prop} uses a percentage but has no parent to measure against`,nodeId:s.nodeId,prop:s.prop});return}i.add(m);return}case"nodeRef":case"relRef":{let f=li(l,s.nodeId,n);if(!f.ok){r.add(l),o.push({severity:"error",code:"unknown-reference",message:f.message,nodeId:s.nodeId,prop:s.prop});return}let p=y=>{e.has(y)&&i.add(y)},m=bl(f.edge);if(!m){for(let y of vl(f.edge))p(nt(f.nodeId,y));return}for(let y of wl(f.nodeId,s.nodeId,n).keys())p(nt(y,m));kl(f.edge)!==0&&p(nt(f.nodeId,m==="x"?"w":"h"));return}case"unary":d(l.operand);return;case"binary":d(l.left),d(l.right);return}};d(s.ast),s.deps=[...i]}}function s0(e){let t=new Map,n=new Map;for(let[s,i]of e){t.set(s,i.deps.length);for(let d of i.deps){let l=n.get(d);l?l.push(s):n.set(d,[s])}}let r=[];for(let[s,i]of t)i===0&&r.push(s);let o=[];for(let s=0;s<r.length;s++){let i=r[s];o.push(i);for(let d of n.get(i)??[]){let l=(t.get(d)??0)-1;t.set(d,l),l===0&&r.push(d)}}return o}function i0(e,t,n){if(t.length===e.size)return;let r=new Set(t);for(let[o,s]of e)r.has(o)||n.push({severity:"error",code:"cycle",message:`${s.nodeId}.${s.prop} is part of a dependency cycle`,nodeId:s.nodeId,prop:s.prop})}function a0(e,t,n,r,o,s){let i=new Map,d=(l,f)=>i.get(nt(l,f))??0;for(let l of t){let f=e.get(l);if(f){if(!ye(f.value)){i.set(l,f.value);continue}if(!f.ast){i.set(l,0);continue}i.set(l,Nm(f.ast,f,n,r,o,s,d))}}return i}function Nm(e,t,n,r,o,s,i){let d=l=>Nm(l,t,n,r,o,s,i);switch(e.kind){case"number":return e.value;case"token":{let l=st(n)[e.name];return typeof l=="number"?l:0}case"percent":{let l=di(t.prop);if(!l)return e.value/100;let f=r.layoutParentOf.get(t.nodeId);return f===void 0?0:e.value/100*i(f,l)}case"nodeRef":case"relRef":{if(o.has(e))return 0;let l=li(e,t.nodeId,r);if(!l.ok)return 0;let f=bl(l.edge);if(!f)return ai(l.edge,i(l.nodeId,"x"),i(l.nodeId,"y"),i(l.nodeId,"w"),i(l.nodeId,"h"));let p=kl(l.edge)*i(l.nodeId,f==="x"?"w":"h");for(let[m,y]of wl(l.nodeId,t.nodeId,r))p+=y*i(m,f);return p}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 s.push({severity:"error",code:"divide-by-zero",message:`${t.nodeId}.${t.prop} divides by zero`,nodeId:t.nodeId,prop:t.prop}),0;let p=d0(e.op,l,f);return Number.isFinite(p)?p:(s.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 d0(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n}}function l0(e,t,n,r){let o=new Map,s=(d,l)=>t.get(nt(d,l))??0,i=(d,l,f)=>{let p=s(d.id,"x"),m=s(d.id,"y"),y=s(d.id,"w"),v=s(d.id,"h"),C={};for(let L of Ct(d)){let A=nt(d.id,L);n.has(A)&&(C[L]=t.get(A)??0)}(y<0||v<0)&&r.push({severity:"warning",code:"negative-size",message:`${d.id} resolved to a negative size`,nodeId:d.id});let S=l+p,g=f+m;if(o.set(d.id,{id:d.id,type:d.type,x:p,y:m,w:y,h:v,left:p,top:m,right:p+y,bottom:m+v,cx:p+y/2,cy:m+v/2,absX:S,absY:g,values:C}),fe(d))for(let L of d.children)i(L,S,g)};return i(e,0,0),o}function ui(e){if(!ye(e))return{kind:"literal",value:e};let t=pt(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 Rm="system-ui, -apple-system, Segoe UI, Roboto, sans-serif",fi=16,ci=400,Fm=1.2,pi="#0F172A";function Qt(){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 _l(e,t){if(e===void 0)return Rm;let n=t[e];return n?n.fallback?`${Im(n.family)}, ${n.fallback}`:Im(n.family):e}function Im(e){return/^[A-Za-z][A-Za-z0-9 -]*$/.test(e)?e:JSON.stringify(e)}function Sl(e,t,n,r){let o={family:_l(t.font,n),size:t.size,weight:t.weight,italic:t.italic,underline:!1,strike:!1,fill:r(t.fill),letterSpacing:t.letterSpacing},s=typeof e=="string"?[e]:e,i=[];for(let d of s){if(typeof d=="string"){d.length>0&&i.push({text:d,style:o});continue}let l=d;l.text.length!==0&&i.push({text:l.text,style:{family:l.font===void 0?o.family:_l(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&&_t(l.link)?{link:l.link}:{}}})}return i}function u0(e,t){let n=[];for(let r of e)for(let o of r.text.split(/(\n)/))if(o!==""){if(o===`
44
- `){let s=n[n.length-1];s&&!s.hardBreak?n[n.length-1]={...s,hardBreak:!0}:n.push({text:"",style:r.style,w:0,hardBreak:!0,glued:!1});continue}for(let s of o.match(/\S+\s*|\s+/g)??[]){let i=n[n.length-1];n.push({text:s,style:r.style,w:t.advance(s,r.style),hardBreak:!1,glued:i!==void 0&&!i.hardBreak&&/\S$/.test(i.text)&&/^\S/.test(s)})}}return n}function f0(e,t,n){let r=[...e.text],o=[],s="";for(let i of r){let d=s+i;if(s!==""&&n.advance(d,e.style)>t){o.push({text:s,style:e.style,w:n.advance(s,e.style),hardBreak:!1,glued:o.length===0&&e.glued}),s=i;continue}s=d}return s!==""&&o.push({text:s,style:e.style,w:n.advance(s,e.style),hardBreak:e.hardBreak,glued:o.length===0&&e.glued}),o.length>0?o:[e]}function Bm(e,t){let{width:n,measure:r}=t,o=u0(r.itemize?e.flatMap(f=>r.itemize?.(f)??[f]):e,r);if(o.length===0){let f=e[0]?.style,p=f?t.lineHeight*f.size:0;return{lines:f?[p0(f,t.lineHeight)]:[],width:0,height:p}}let s=[],i=[],d=0,l=()=>{s.push(i),i=[],d=0};for(let f=0;f<o.length;){let p=f+1;for(;o[p]?.glued;)p+=1;let m=o.slice(f,p);f=p,m.length>1&&i.length>0&&d+c0(m,r)>n&&l();for(let y of m){let v=i.length===0&&y.w>n&&n>0?f0(y,n,r):[y];for(let C of v){let S=C.text.trimEnd(),g=S===C.text?C.w:r.advance(S,C.style);i.length>0&&d+g>n&&l(),i.push(C),d+=C.w,C.hardBreak&&l()}}}return i.length>0&&s.push(i),m0(s,t)}function c0(e,t){let n=e[e.length-1],r=n.text.trimEnd(),o=r===n.text?n.w:t.advance(r,n.style);return e.slice(0,-1).reduce((s,i)=>s+i.w,0)+o}function p0(e,t){let n=t*e.size;return{y:0,h:n,baseline:n*.8,w:0,spans:[],style:e}}function m0(e,t){let n=[],r=0,o=0;return e.forEach((s,i)=>{let d=s.map($=>$.style.size),l=Math.max(...d,0),f=t.lineHeight*l,p=s.map($=>t.measure.metrics($.style)),m=Math.max(...p.map($=>$.ascent),0),y=Math.max(...p.map($=>$.descent),0),v=r+(f-(m+y))/2+m,C=h0(s,t.measure),S=C.reduce(($,V)=>$+V.w,0);o=Math.max(o,S);let g=i===e.length-1||(s[s.length-1]?.hardBreak??!1),L=C.filter(($,V)=>V>0&&!$.glued).length,A=t.align==="justify"&&!g&&L>0,I=Math.max(0,t.width-S),U=t.align==="center"?I/2:t.align==="right"?I:0,j=A?I/L:0,R=[],q=U;C.forEach(($,V)=>{R.push({text:$.text,style:$.style,x:q,w:$.w});let b=C[V+1];q+=$.w+(b&&!b.glued?j:0)}),n.push({y:r,h:f,baseline:v,w:S,spans:x0(R,A)}),r+=f}),{lines:n,width:o,height:r}}function h0(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 x0(e,t){if(t)return[...e];let n=[];for(let r of e){let o=n[n.length-1];if(o&&Hm(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 Hm(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 El(e,t,n,r,o,s){let i={size:t.size??fi,weight:t.weight??ci,lineHeight:t.lineHeight??Fm,letterSpacing:t.letterSpacing??0,italic:e.italic??!1,font:typeof e.font=="string"?e.font:void 0,fill:typeof e.fill=="string"?e.fill:pi},d=Sl(e.content,i,r,o),l=Sl(" ",i,r,o).map(f=>({...f,text:""}));return Bm(d.length>0?d:l,{width:n,align:e.align??"left",lineHeight:i.lineHeight,measure:s})}function Cl(e,t,n){let r=t-n;return e.valign==="middle"?r/2:e.valign==="bottom"?r:0}function Ml(e){return e.lines.filter(t=>t.spans.length>0)}function Vo(e){switch(e.kind){case"text":{let t=Ml(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=Vn(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 xi(e,t){let n=e.x,r=e.y,o=e.x+e.w,s=e.y+e.h;for(let i of t){let d=i.spread+i.blur;n=Math.min(n,e.x+i.x-d),r=Math.min(r,e.y+i.y-d),o=Math.max(o,e.x+e.w+i.x+d),s=Math.max(s,e.y+e.h+i.y+d)}return{x:n,y:r,w:o-n,h:s-r}}var zm="vd-paint-";var hi="#CBD5E1",jm="#FFFFFF";function zo(e,t,n={}){let r=[...t.problems],o=[],s=[],i=n.measure??Qt(),d=qm(st(e),r),l=d.paint,f=new Map,p=Ye(e.root);oe(e.root,(g,L)=>{if("hidden"in g&&g.hidden===!0)return!1;let A=L?f.get(L.id):void 0,I=t.nodes.get(g.id);if(!I){f.set(g.id,A);return}let U=g.type==="frame"?g:g.type==="instance"?p.get(g.component):void 0;if(g.type==="instance"&&!U){f.set(g.id,A);return}if(U){g.type==="frame"&&g.skip===!0&&L!==e.root&&r.push({severity:"warning",code:"skip-not-a-page",message:`${g.id}: skip only applies to a page, a frame at the top level`,nodeId:g.id,prop:"skip"});let R={x:I.absX,y:I.absY,w:Math.max(0,I.w),h:Math.max(0,I.h)};f.set(g.id,U.clip===!0?g.id:A),U.clip===!0&&s.push({id:g.id,...R,parent:A}),o.push({kind:"frame",id:g.id,...R,background:l(U.background,g.id,"background",R),clip:A,blend:U.blend??"normal",shadows:Ar(U.shadow,g.id,st(e),r),rotation:0});return}if(f.set(g.id,A),g.type==="text"){o.push(Km(g,I,e,i,r,A,l));return}if(g.type==="image"){o.push({kind:"image",id:g.id,x:I.absX,y:I.absY,w:Math.max(0,I.w),h:Math.max(0,I.h),href:E0(g,e,n.resolveAsset,r),fit:g.fit??"fill",radius:Math.max(0,I.values.radius??0),opacity:Uo(I.values.opacity??1),clip:A,blend:g.blend??"normal",shadows:Ar(g.shadow,g.id,st(e),r),rotation:I.values.rotation??0});return}if(g.type==="ellipse"){let R=Vm(I);o.push({kind:"ellipse",id:g.id,...R,fill:l(g.fill,g.id,"fill",R)??hi,stroke:l(g.stroke,g.id,"stroke",R),strokeWidth:I.values.strokeWidth??0,opacity:Uo(I.values.opacity??1),clip:A,blend:g.blend??"normal",shadows:Ar(g.shadow,g.id,st(e),r),rotation:I.values.rotation??0});return}if(g.type==="vector"){o.push(k0(g,I,r,A,l,Ar(g.shadow,g.id,st(e),r)));return}if(g.type!=="rect")return;let j=Vm(I);o.push({kind:"rect",id:g.id,...j,fill:l(g.fill,g.id,"fill",j)??hi,stroke:l(g.stroke,g.id,"stroke",j),strokeWidth:I.values.strokeWidth??0,radius:Math.max(0,I.values.radius??0),opacity:Uo(I.values.opacity??1),clip:A,blend:g.blend??"normal",shadows:Ar(g.shadow,g.id,st(e),r),rotation:I.values.rotation??0})});let m=t.nodes.get(e.root.id),y=e.root.w!==void 0&&e.root.h!==void 0,v=y?{x:0,y:0,width:Math.max(0,m?.w??0),height:Math.max(0,m?.h??0)}:g0(o,s),C={x:v.x,y:v.y,w:v.width,h:v.height},S=l(e.root.background,e.root.id,"background",C);return{...v,background:y?S??jm:S,items:o,clips:s,gradients:d.gradients,problems:r}}function Al(e,t,n,r,o={}){let s=F(e.root,n.id),i=t.nodes.get(n.id);if(s?.type!=="text"||!i)return;let d=[],l=qm(st(e),d);return Km({...s,content:r},i,e,o.measure??Qt(),d,n.clip,l.paint)}function g0(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?Um(d,l):d)}let r=1/0,o=1/0,s=-1/0,i=-1/0;for(let d of e){let l=d.kind==="text"&&Ml(d).length>0?Math.max(d.h,d.height):d.h,f=d.clip===void 0?void 0:n.get(d.clip),p=Io(xi({x:d.x,y:d.y,w:d.w,h:l},d.shadows),d.rotation,ct(d)),m=f?Um(p,f):p;m.w<=0||m.h<=0||(r=Math.min(r,m.x),o=Math.min(o,m.y),s=Math.max(s,m.x+m.w),i=Math.max(i,m.y+m.h))}return Number.isFinite(r)?{x:r,y:o,width:s-r,height:i-o}:{x:0,y:0,width:0,height:0}}function Um(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 Km(e,t,n,r,o,s,i){let d=Math.max(0,t.w),l=Math.max(0,t.h),f={x:t.absX,y:t.absY,w:d,h:l},p=El(e,t.values,d,n.fonts,v=>i(v,e.id,"fill",f)??pi,r);!p.lines.every(v=>v.spans.length===0)&&p.height>l+.5&&o.push({severity:"warning",code:"text-overflow",message:`${e.id} needs ${Math.ceil(p.height)}px but its height is ${Math.round(l)}px`,nodeId:e.id,prop:"h"}),y0(e,n,o);let y=t.absY+Cl(e,l,p.height);return{kind:"text",id:e.id,x:t.absX,y:t.absY,w:d,h:l,clip:s,blend:e.blend??"normal",shadows:Ar(e.shadow,e.id,st(n),o),rotation:t.values.rotation??0,opacity:Uo(t.values.opacity??1),height:p.height,lines:p.lines.map(v=>({y:y+v.y,h:v.h,baseline:y+v.baseline,w:v.w,spans:v.spans.map(C=>({text:C.text,x:t.absX+C.x,y:y+v.baseline,w:C.w,style:C.style})),...v.style?{style:v.style}:{}}))}}function y0(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=_t(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"&&!v0(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 v0(e,t){let n=!1;return oe(e.root,r=>{if(n)return!1;r.id===t&&r.type==="frame"&&(n=!0)}),n}var Ho=new Map,b0=512;function w0(e){let t=Ho.get(e);if(t)return t;let n=Eo(e);return Ho.size>=b0&&Ho.delete(Ho.keys().next().value),Ho.set(e,n),n}function k0(e,t,n,r,o,s){let i=Math.max(0,t.w),d=Math.max(0,t.h),l={x:t.absX,y:t.absY,w:i,h:d},{contours:f,error:p}=w0(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&&Us(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=qt(f,Mo(Co(e.view,i,d),l));return{kind:"vector",id:e.id,...l,d:Gt(m),contours:m,fill:o(e.fill,e.id,"fill",l)??hi,stroke:o(e.stroke,e.id,"stroke",l),strokeWidth:t.values.strokeWidth??0,opacity:Uo(t.values.opacity??1),rule:e.rule??"nonzero",cap:e.cap??"butt",join:e.join??"miter",clip:r,blend:e.blend??"normal",shadows:s,rotation:t.values.rotation??0}}function Gm(e,t,n,r,o){if(e===void 0)return;if(ye(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 s=t[e];if(s===void 0)return e;if(typeof s=="string")return s;o.push({severity:"error",code:"token-not-a-colour",message:`Token $${e} is a number, not a colour`,nodeId:n,prop:r})}function Vm(e){return{x:e.absX,y:e.absY,w:Math.max(0,e.w),h:Math.max(0,e.h)}}function qm(e,t){let n=[],r=new Map;return{paint:(s,i,d,l)=>{let f=Gm(s,e,i,d,t);if(f===void 0)return;if(/url\(/i.test(f)){t.push({severity:"error",code:"invalid-paint",message:`${i}: a paint is a colour or a gradient, not ${JSON.stringify(f)}`,nodeId:i,prop:d});return}let p=No(f);if("error"in p){t.push({severity:"error",code:"invalid-paint",message:`${i}: ${p.error}`,nodeId:i,prop:d});return}if(p.kind==="solid")return f;let m=`${i}\0${d}\0${f}`,y=r.get(m);if(y!==void 0)return`url(#${y})`;let v=[...r.keys()].filter(g=>g.startsWith(`${i}\0${d}\0`)).length,C=`${zm}${i}-${d}${v===0?"":`-${v+1}`}`;r.set(m,C);let S=ul(p.stops).map(g=>({offset:g.at,colour:Wm(g.colour,e,i,d,t)}));return n.push(S0(p,C,l,_0(S))),`url(#${C})`},gradients:n}}function Ar(e,t,n,r){let o=Gm(e,n,t,"shadow",r);if(o===void 0)return[];let s=Mr(o);return"error"in s?(r.push({severity:"error",code:"invalid-shadow",message:`${t}: ${s.error}`,nodeId:t,prop:"shadow"}),[]):s.shadows.map(i=>({...i,colour:Wm(i.colour,n,t,"shadow",r)}))}function _0(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 Wm(e,t,n,r,o){let s=t[e];return s===void 0?e:typeof s=="string"&&!oi(s)?s:(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 S0(e,t,n,r){if(e.kind==="linear"){let f=e.angle*Math.PI/180,p=Math.sin(f),m=-Math.cos(f),y=(Math.abs(n.w*p)+Math.abs(n.h*m))/2,v=n.x+n.w/2,C=n.y+n.h/2;return{id:t,kind:"linear",x1:mi(v-p*y),y1:mi(C-m*y),x2:mi(v+p*y),y2:mi(C+m*y),stops:r}}let o=n.x+n.w*e.cx,s=n.y+n.h*e.cy,i={x:Math.max(o-n.x,n.x+n.w-o),y:Math.max(s-n.y,n.y+n.h-s)};if(e.shape==="circle"||i.x===0||i.y===0){let f=Math.hypot(i.x,i.y);return{id:t,kind:"radial",cx:o,cy:s,rx:f,ry:f,stops:r}}let d=i.x/i.y,l=Math.hypot(i.x/d,i.y);return{id:t,kind:"radial",cx:o,cy:s,rx:l*d,ry:l,stops:r}}function mi(e){return Math.round(e*1e6)/1e6}function Uo(e){return Math.min(Math.max(e,0),1)}function E0(e,t,n,r){let o=ye(e.src)?void 0:e.src,s=o===void 0?void 0:t.assets[o];if(!s){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?.(s,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 C0(e,t){let n=new Map,r=(o,s)=>{n.set(o,[...n.get(o)??[],s])};for(let o of e.beats){if(o.kind==="camera")continue;let s=o.kind;if(o.split==="children"){let i=F(t.root,o.line.id);(i&&"children"in i?i.children:[]).forEach((l,f)=>{r(l.id,{beat:o,kind:s,start:o.start+f*o.stagger})})}else if(o.split!==void 0)for(let i=0;i<o.pieces;i+=1)r(o.line.id,{beat:o,kind:s,start:o.start+i*o.stagger,piece:i});else r(o.line.id,{beat:o,kind:s,start:o.start})}for(let o of n.values())o.sort((s,i)=>s.start-i.start);return n}function M0(e,t){let n=t.nodes.get(e.page);return n?Math.min(n.w,n.h):1e3}function Xm(e,t,n,r,o){let s=e[0]?.kind==="enter",i,d,l;for(let f of e){if(f.start>t)break;let p=f.beat.effect,m=f.beat.duration,y=m<=0?1:Math.min(1,(t-f.start)/m),v=y>=1;if(f.kind==="emphasis"){if(s||v){i=void 0;continue}let A=1+(ol-1)*Math.sin(Math.PI*ri(f.beat.ease,y));i=gi(n,A,A,"centre",1);continue}if(v){s=f.kind==="exit",i=void 0,d=void 0,l=void 0;continue}let C=ri(f.beat.ease,y),S=f.kind==="enter"?C:1-C,g=Zm(f.kind==="enter"?C:1-C);s=!1,d=void 0,l=void 0;let L=f.beat.line.from;switch(p){case"cut":i=void 0;break;case"fade":i=Ym(g);break;case"rise":case"drop":{let A=p==="rise"?1:-1;i={sx:1,sy:1,tx:0,ty:f.kind==="enter"?A*r*(1-C):-A*r*C,opacity:g};break}case"pop":{let A=Po+(1-Po)*S;i=gi(n,A,A,"centre",g);break}case"grow":{let A=typeof L=="string"?L:"bottom",I=Math.max(0,S);i=A==="left"||A==="right"?gi(n,I,1,A,1):gi(n,1,I,A,1);break}case"wipe":{let A=typeof L=="string"?L:"left";d=f.kind==="enter"?Qm(n,A,S):A0(n,A,C),i=void 0;break}case"count":{let A=o.text===void 0?void 0:al(o.text);if(!A){i=Ym(g);break}let I=typeof L=="number"?L:0;l=dl(A,I+(A.value-I)*C),i=void 0;break}case"draw":i={sx:1,sy:1,tx:0,ty:0,opacity:1,trace:S,fillOpacity:Zm((S-.75)/.25)};break;case"pulse":case void 0:i=void 0;break}}return{hidden:s,pose:i,...d?{reveal:d}:{},...l===void 0?{}:{text:l}}}function Ym(e){return{sx:1,sy:1,tx:0,ty:0,opacity:e}}function gi(e,t,n,r,o){let s=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:s*(1-t),ty:i*(1-n),opacity:o}}function Qm(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 A0(e,t,n){return Qm(e,{left:"right",right:"left",top:"bottom",bottom:"top"}[t],1-n)}function Jm(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 Zm(e){return e<0?0:e>1?1:e}function $0(e,t){let n=new Map;oe(t.root,(o,s)=>{s&&n.set(o.id,s.id)});let r=new Map;for(let o of e.items){let s=o.kind==="frame"?{x:o.x,y:o.y,w:o.w,h:o.h}:Vo(o);for(let i=o.id;i!==void 0;i=n.get(i)){let d=r.get(i);if(r.set(i,d?O0(d,s):s),i===t.root.id)break}}return{parents:n,boxes:r}}function O0(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 $l(e,t,n,r){let o=C0(t,r.doc);if(o.size===0)return e;let{parents:s,boxes:i}=$0(e,r.doc),d=Do*M0(t,r.resolution),l=r.options?.measure??Qt(),f=new Map,p=new Map;for(let[v,C]of o){let S=i.get(v)??{x:0,y:0,w:0,h:0},g=F(r.doc.root,v),L=g?.type==="text"?bn(g.content):void 0,A=C.filter(U=>U.piece===void 0),I=C.find(U=>U.piece!==void 0);if(A.length>0&&f.set(v,Xm(A,n,S,d,{...L===void 0?{}:{text:L}})),I&&(I.beat.split==="word"||I.beat.split==="letter")){let U=[];for(let j=0;j<I.beat.pieces;j+=1){let R=C.filter(q=>q.piece===j);U.push(Xm(R,n,S,d,{}))}U.some(j=>j.hidden||j.pose!==void 0)&&p.set(v,{split:I.beat.split,moments:U})}}let m=[...e.clips],y=[];for(let v of e.items){let C=[],S;for(let U=v.id;U!==void 0;U=s.get(U)){let j=f.get(U);j&&(C.unshift(j),j.reveal&&!S&&(S={id:U,box:j.reveal}))}if(C.some(U=>U.hidden))continue;let g;for(let U of C)U.pose&&(g=g?Jm(g,U.pose):U.pose);let L=v,A=f.get(v.id)?.text;if(A!==void 0&&v.kind==="text"&&(L=Al(r.doc,r.resolution,v,A,r.options)??v),S){let U=`${S.id}~wipe${v.clip===void 0?"":`~${v.clip}`}`;m.some(j=>j.id===U)||m.push({id:U,...S.box,parent:v.clip}),L={...L,clip:U}}let I=p.get(v.id);if(I&&L.kind==="text"){eh(L,I.split,l).forEach((U,j)=>{let R=I.moments[j];if(!R||R.hidden)return;let q=R.pose&&g?Jm(g,R.pose):R.pose??g;y.push({...U,part:j,...q?{pose:q}:{}})});continue}y.push(g&&!T0(g)?{...L,pose:g}:L)}return{...e,items:y,clips:m}}function T0(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 eh(e,t,n=Qt()){let r=[],o=new Intl.Segmenter(void 0,{granularity:"grapheme"}),s=!1;for(let i of e.lines){s=!1;for(let d of i.spans){let l=0,f=t==="word"?d.text.split(/(\s+)/).filter(p=>p!==""):[...o.segment(d.text)].map(p=>p.segment);for(let p of f){if(p.trim()==="")s=!1;else{(t==="letter"||!s)&&r.push([]);let y=d.x+n.advance(d.text.slice(0,l),d.style);r.at(-1).push({...d,text:p,x:y,w:n.advance(p,d.style)}),s=!0}l+=p.length}}}return r.map(i=>({...e,lines:e.lines.map(d=>({...d,spans:i.filter(l=>l.y===d.baseline)})).filter(d=>d.spans.length>0)}))}var th="vd-clip-";function Ol(e){return D0(e,"")}function D0(e,t){let n=e.parent===void 0?"":` clip-path="url(#${$r(t+th+e.parent)})"`;return`<clipPath id="${$r(t+th+e.id)}"${n}><rect x="${se(e.x)}" y="${se(e.y)}" width="${se(e.w)}" height="${se(e.h)}"/></clipPath>`}function Tl(e){return P0(e,"")}function P0(e,t){let n=e.stops.map(o=>`<stop offset="${se(o.offset)}" stop-color="${$r(o.colour)}"${o.opacity===void 0?"":` stop-opacity="${se(o.opacity)}"`}/>`).join(""),r=$r(t+e.id);return e.kind==="linear"?`<linearGradient id="${r}" gradientUnits="userSpaceOnUse" x1="${se(e.x1)}" y1="${se(e.y1)}" x2="${se(e.x2)}" y2="${se(e.y2)}">${n}</linearGradient>`:`<radialGradient id="${r}" gradientUnits="userSpaceOnUse" cx="0" cy="0" r="1" gradientTransform="matrix(${se(e.rx)} 0 0 ${se(e.ry)} ${se(e.cx)} ${se(e.cy)})">${n}</radialGradient>`}var yi="vd-shadow-";function Ll(e,t=!1){return N0(e,t,"")}function N0(e,t,n){let r=xi(Vo(e),e.shadows),o=2,s=[];e.shadows.forEach((d,l)=>{let f=`s${l}`,p="SourceAlpha";d.spread!==0&&(s.push(`<feMorphology in="${p}" operator="${d.spread>0?"dilate":"erode"}" radius="${se(Math.abs(d.spread))}" result="${f}m"/>`),p=`${f}m`),d.blur>0&&(s.push(`<feGaussianBlur in="${p}" stdDeviation="${se(d.blur/2)}" result="${f}b"/>`),p=`${f}b`),s.push(`<feOffset in="${p}" dx="${se(d.x)}" dy="${se(d.y)}" result="${f}o"/>`,`<feFlood flood-color="${$r(d.colour)}" result="${f}c"/>`,`<feComposite in="${f}c" in2="${f}o" operator="in" result="${f}"/>`)});let i=e.shadows.map((d,l)=>`<feMergeNode in="s${e.shadows.length-1-l}"/>`).join("");return`<filter id="${$r(n+yi+e.id)}" filterUnits="userSpaceOnUse" x="${se(r.x-o)}" y="${se(r.y-o)}" width="${se(r.w+o*2)}" height="${se(r.h+o*2)}" color-interpolation-filters="sRGB">`+s.join("")+`<feMerge>${i}${t?"":'<feMergeNode in="SourceGraphic"/>'}</feMerge></filter>`}function vi(e){return`rotate(${se(e.rotation)} ${se(e.x+e.w/2)} ${se(e.y+e.h/2)})`}function Dl(e){return e.rotation!==0&&e.clip!==void 0}function Pl(e){return`matrix(${se(e.sx)} 0 0 ${se(e.sy)} ${se(e.tx)} ${se(e.ty)})`}function $r(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var B0=.8,H0=.2;function Nl(e,t){let r=e.createElement("canvas").getContext("2d"),o=Qt(),s=new Map,i=new Map,d=new Set;function l(p){return`${p.italic?"italic ":""}${p.weight} ${p.size}px ${p.family}`}function f(){s.clear(),i.clear()}return{advance(p,m){if(!r)return o.advance(p,m);let y=l(m),v=`${y}\0${m.letterSpacing}\0${p}`,C=s.get(v);if(C!==void 0)return C;r.font=y;let S=r.measureText(p).width+m.letterSpacing*[...p].length;return s.set(v,S),S},metrics(p){if(!r)return o.metrics(p);let m=l(p),y=i.get(m);if(y)return y;r.font=m;let v=r.measureText("Hxg"),C=v.fontBoundingBoxAscent??p.size*B0,S=v.fontBoundingBoxDescent??p.size*H0,g={ascent:C,descent:S,lineGap:0};return i.set(m,g),g},load(p,m){let y=e.fonts;if(!y||typeof FontFace!="function")return!1;let v=!1;for(let C of Object.values(p.fonts))for(let S of U0(C)){let g=`${C.family}\0${S.src}\0${S.weight??400}\0${S.style??"normal"}`;if(d.has(g))continue;d.add(g);let L=S.src.startsWith("data:")?void 0:m?.(S.src),A={weight:String(S.weight??400),style:S.style??"normal"},I=U=>{let j=new FontFace(C.family,typeof U=="string"?`url(${U})`:V0(U),A);y.add(j),j.load().then(()=>{f(),t?.()},()=>{y.delete(j)})};L===void 0?I(S.src):(v=!0,L.then(I,()=>{}))}return v},invalidate:f,destroy(){f(),d.clear()}}}function U0(e){return(e.faces??[]).flatMap(t=>t.src===void 0?[]:[{...t,src:t.src}])}function V0(e){return e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}var bi={x:0,y:0,zoom:1},rh=.02,oh=64;function Or(e){return Number.isFinite(e)?Math.min(Math.max(e,rh),oh):1}function wi(e,t){return{x:(t.x-e.x)/e.zoom,y:(t.y-e.y)/e.zoom}}function Il(e,t){return{x:t.x*e.zoom+e.x,y:t.y*e.zoom+e.y}}function jo(e,t,n){let r=Or(e.zoom*n),o=wi(e,t);return{zoom:r,x:t.x-o.x*r,y:t.y-o.y*r}}function It(e,t,n){return{...e,x:e.x+t,y:e.y+n}}function Rl(e){return`translate(${e.x} ${e.y}) scale(${e.zoom})`}function Rt(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 bi;let o=Or(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 ve="http://www.w3.org/2000/svg",sh="vd-viewer-styles",ih=`
39
+ `}async function Hl(e){let t=await crypto.subtle.digest("SHA-256",e),n=[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0"));return`${fy}${n.join("")}`}function Ul(e,t){return`data:${e};base64,${t}`}function zl(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 jl(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 ZS(e){if(e.startsWith(Kr))return 0;let t=e.indexOf(`
40
+ ${Kr}`);return t===-1?-1:t+1}function QS(e){let t=new Set;for(let n of e.matchAll(/sha256-[0-9a-f]{64}/g))t.add(n[0]);return t}function Kl(e){return(t,n,r,o)=>{e.push({severity:"error",code:n,message:`Line ${t}: ${r}`,...o===void 0?{}:{nodeId:o}})}}function Gl(e){let t=[],n=e.split(`
41
+ `);for(let r=0;r<n.length;r+=1){let o=n[r],s=o.trim();if(s===Kr)break;if(s===""||s.startsWith("```"))continue;let i=o.length-o.trimStart().length;t.push({number:r+1,indent:Math.floor(i/2),text:s,words:Qg(s)})}return t}function ql(e){let t=[],n=[],r,o=()=>{r&&r.runs.length>0&&(r.props.content=gy(r.runs)),r=void 0},s=i=>{for(o();t.length>0&&t[t.length-1].indent>=i;)n_(t.pop())};return{push(i){let a=i.words[0];if(a.startsWith('"')&&r&&i.indent>r.indent){let p=xy(i,e);return p!==void 0&&r.runs.push(p),!0}if(a===Za){s(i.indent);let p=t[t.length-1];return!p||p.type!=="instance"?(e(i.number,"invalid-override","An override line must sit inside an instance"),!0):(r=t_(p,i,e),!0)}if(a.startsWith('"')){let p=t[t.length-1];if(!p||p.type!=="text")return e(i.number,"invalid-content","A quoted line must sit inside a text node"),!0;let m=xy(i,e);return m!==void 0&&p.runs.push(m),!0}if(!Ya(a))return!1;s(i.indent);let d=i.words[1];if(d===void 0||d.includes("="))return e(i.number,"missing-id",`A ${a} needs an id`),!0;let c=e_(a,d,i.words.slice(2),i,e),l=t[t.length-1];return l?.type==="instance"?e(i.number,"invalid-override",`${l.record.id} takes its contents from its component \u2014 change the component, or write an override line`,d):l?l.children.push(c.record):n.push(c.record),t.push(c),!0},finish(){return s(0),n}}}function e_(e,t,n,r,o){let s={type:e,id:t},i=[];for(let a=0;a<n.length;a+=1){let{key:d,value:c}=ot(n[a]),l=zo(e,d);if(l===void 0){let g=ed(n,a,n[a-1]);g?(o(r.number,"invalid-value",g.message,t),a=g.end-1):o(r.number,"invalid-value",`${e} has no property "${d}"`,t);continue}let p=Qa(d,c??"");if(p!==void 0){if("error"in p)o(r.number,"invalid-value",`${d}: ${p.error}`,t);else for(let[g,b]of p.cells)s[g]=b;continue}let m=Qe(c??"",l);"error"in m?o(r.number,"invalid-value",`${d}: ${m.error}`,t):s[d]=m.value}return $a(e)&&(s.children=i),e==="text"&&(s.content=""),{indent:r.indent,type:e,record:s,children:i,runs:[]}}function t_(e,t,n){let r=e.record.id,o=t.words[1];if(o===void 0||o.includes("=")){n(t.number,"invalid-override","An override names the part it changes, e.g. override item.title fill=accent",r);return}let s=e.record.overrides??={},i=s[o]??={},a=t.words.slice(2);for(let d=0;d<a.length;d+=1){let{key:c,value:l}=ot(a[d]),p=nr(c)?Ja(c):void 0;if(p===void 0){let b=ed(a,d,a[d-1]);b?(n(t.number,"invalid-value",b.message,r),d=b.end-1):c==="content"?n(t.number,"invalid-value","Write the text as quoted lines under the override",r):n(t.number,"invalid-value",`An override cannot set "${c}"`,r);continue}let m=Qa(c,l??"");if(m!==void 0){if("error"in m)n(t.number,"invalid-value",`${c}: ${m.error}`,r);else for(let[b,w]of m.cells)i[b]=w;continue}let g=Qe(l??"",p);"error"in g?n(t.number,"invalid-value",`${c}: ${g.error}`,r):i[c]=g.value}return{indent:t.indent,props:i,runs:[]}}function n_(e){if(e.type==="text"&&(e.record.content=gy(e.runs)),e.type==="instance"){let t=e.record.overrides;for(let[n,r]of Object.entries(t??{}))Object.keys(r).length===0&&delete t?.[n];t&&Object.keys(t).length===0&&delete e.record.overrides}}function gy(e){if(e.length===0)return"";let t=e[0];return e.length===1&&typeof t=="string"?t:[...e]}function xy(e,t){let n=hn(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:s,value:i}=ot(o),a=hi.find(([c])=>c===s);if(!a){t(e.number,"invalid-run",`A run has no mark "${s}"`);continue}let d=Qe(i??"",a[1]);"error"in d?t(e.number,"invalid-run",`${s}: ${d.error}`):r[s]=d.value}return r}function gi(e){let t=[],n=Kl(t),r=rr,o,s=!1,i={},a={},d={},c=ql(n),l=Tl(n,t),p,m={},g=!1,b=!1,w={},k=new Map,_,M=!1,R=()=>{if(!_)return;let C=_;_=void 0;let G=k.get(C.page);if(G!==void 0){n(C.number,"invalid-motion",`motion ${C.page} is written twice \u2014 put its lines in the block on line ${G}`,C.page);return}k.set(C.page,C.number);for(let[fe,oe]of C.where)k.set(`${C.page} ${fe}`,oe);let ee=Nl(C);ee&&(w[C.page]=ee)};for(let C of Gl(e)){let G=C.words[0];if(_&&C.indent>0){Dl(_,C,n);continue}if(!(M&&C.indent>0)){if(M=!1,R(),G==="motion"&&C.indent===0){p=void 0,_=Pl(C,n),M=_===void 0;continue}if(l.take(C)){p=void 0;continue}if(G==="version"){s=!0,s_(C,t);continue}if(G==="kind"&&C.indent===0){r=i_(C,t);continue}if(G==="title"&&C.indent===0){o=yy(C,n);continue}if(G==="theme"&&C.indent===0){p=void 0,g=!0,b&&n(C.number,"invalid-theme","theme dark is written twice \u2014 keep one block"),b=!0,(C.words[1]!=="dark"||C.words.length>2)&&n(C.number,"invalid-theme","Expected theme dark on its own line, with the tokens that differ indented under it");continue}if(G.startsWith("$")){if(p=void 0,g&&C.indent>0){Wl(C,m,n);continue}g=!1,Wl(C,i,n);continue}if(C.indent===0)g=!1;else if(g){n(C.number,"invalid-theme","A theme block holds only $name = value lines");continue}if(G==="asset"&&C.indent===0){p=void 0,a_(C,d,n);continue}if(G==="font"&&C.indent===0){p=u_(C,a,n);continue}if((G==="fallback"||G==="face")&&p){l_(G,C,p,n);continue}p=void 0,!c.push(C)&&n(C.number,"unknown-node-type",`Unknown statement "${G}"`)}}R();let B=o_(l.finish(),r,t),D=un({dark:m}),V={...B===void 0?{}:{brand:B},...D===void 0?{}:{themes:D}},T=r_(c.finish(),t),O=Object.keys(w).length===0?{}:{motion:w},j=(C,G)=>k.get(G===void 0?C:`${C} ${G}`);if(!T){s||t.push({severity:"error",code:"invalid-document",message:"No nodes found"});let C=Oo({id:dn,children:[]}),G=Js({kind:r,...o===void 0?{}:{title:o},tokens:i,fonts:a,assets:d,...O,...V,root:C});return t.push(...Io(G,j)),{document:G,problems:t}}let $=$n(T),P={version:Et({kind:r,fonts:a,...V,root:$}),kind:r,...o===void 0?{}:{title:o},tokens:i,fonts:a,assets:d,...O,...V,root:$};return t.push(...Io(P,j)),{document:P,problems:t}}function r_(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:dn,children:[...e]}}}function o_(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(([i,a])=>i!=="voice"||a.entries.some(d=>d.kind!=="banned")),s=Object.keys(r.roles).length+Object.keys(r.logos).length+o.length+r.review.length;return t!=="brand"&&s>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 s_(e,t){Xs.includes(Number(e.words[1]))||t.push({severity:"warning",code:"version-mismatch",message:`Line ${e.number}: expected version ${Ys} or older, got ${e.words[1]??"nothing"}`})}function i_(e,t){let n=e.words[1];return n!==void 0&&Tr.includes(n)?n:(t.push({severity:"error",code:"unknown-kind",message:`Line ${e.number}: unknown kind "${n??"nothing"}" \u2014 this build reads ${Tr.join(", ")}`}),rr)}function yy(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('"')?hn(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 Wl(e,t,n){let{name:r,value:o}=Xl(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 s=Qe(o,"stringValue");if("error"in s){n(e.number,"invalid-token",`$${r}: ${s.error}`);return}if(typeof s.value!="string"){n(e.number,"invalid-token",`$${r} may not be an expression`);return}t[r]=by(s.value,o)}function by(e,t){let n=Number(e);return t.startsWith('"')||!Number.isFinite(n)||e.trim()===""?e:n}function Xl(e){let t=e[0],n=s=>s.startsWith("$")?s.slice(1):s;if(e[1]==="=")return{name:n(t),value:e.slice(2).join(" ")||void 0};let{key:r,value:o}=ot(t);return o!==void 0?{name:n(r),value:o}:{name:n(t)}}function a_(e,t,n){let r=e.words.slice(1),o=r[0],s=r[1]==="=",i=o===void 0?void 0:ot(o),a=i?.key,d=s?r[2]:i?.value,c=r.slice(s?3:1);if(a===void 0||a===""||d===void 0){n(e.number,"invalid-asset","Expected asset <name> = <type> hash=\u2026 bytes=\u2026");return}let l={};for(let b of c){let{key:w,value:k}=ot(b);if(k===void 0){n(e.number,"invalid-asset",`Asset "${a}" has a stray word "${b}"`);continue}l[w]=d_(k)}let p=l.hash,m=Number(l.bytes);if(p===void 0||!Number.isFinite(m)){n(e.number,"invalid-asset",`Asset "${a}" needs a hash and a bytes count`);return}let g=l.ms===void 0?void 0:Number(l.ms);if(g!==void 0&&!(Number.isFinite(g)&&g>=0)){n(e.number,"invalid-asset",`Asset "${a}": ms is the track's length, in milliseconds`);return}t[a]={type:d,hash:p,bytes:m,...g===void 0?{}:{ms:g},...l.credit===void 0?{}:{credit:l.credit},...l.source===void 0?{}:{source:l.source},...l.license===void 0?{}:{license:l.license}}}function d_(e){return e.startsWith('"')?hn(e)??e:e}function u_(e,t,n){let{name:r,value:o}=Xl(e.words.slice(1));if(r===void 0||o===void 0){n(e.number,"invalid-font","Expected font <name> = <family>");return}let s=Qe(o,"string"),i={family:"error"in s?o:s.value};return t[r]=i,{family:i,faces:[]}}var c_=/^[A-Za-z_][\w-]*$/;function l_(e,t,n,r){if(e==="fallback"){let a=Qe(t.words.slice(1).join(" "),"string");"error"in a?r(t.number,"invalid-font",`fallback: ${a.error}`):n.family.fallback=a.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 s=o.startsWith("asset=")?o.slice(6):void 0,i={};if(s!==void 0){if(!c_.test(s)){r(t.number,"invalid-font-face",`asset=${s}: not an asset name`);return}i.asset=s}else{let a=Qe(o,"string");i.src="error"in a?o:a.value}for(let a of t.words.slice(2)){let{key:d,value:c}=ot(a);if(d!=="weight"&&d!=="style"){r(t.number,"invalid-font-face",`A face has no property "${d}"`);continue}let l=Qe(c??"",d==="weight"?"number":"fontStyle");"error"in l?r(t.number,"invalid-font-face",`${d}: ${l.error}`):i[d]=l.value}n.faces.push(i),n.family.faces=n.faces}var Yl=["rect","ellipse","vector","image","text","video"];function Re(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function je(e,t,n){if(n===0)return e;let r=n*Math.PI/180,o=Math.cos(r),s=Math.sin(r),i=e.x-t.x,a=e.y-t.y;return{x:t.x+i*o-a*s,y:t.y+i*s+a*o}}function lr(e,t,n=Re(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=>je(d,n,t)),o=r.map(d=>d.x),s=r.map(d=>d.y),i=Math.min(...o),a=Math.min(...s);return{x:i,y:a,w:Math.max(...o)-i,h:Math.max(...s)-a}}function Wo(e){let t=(e%360+360)%360,n=Math.round(t*100)/100;return n===360?0:n}var vy=["image","video"],wy=["rect","ellipse","vector"];function st(e){return vy.includes(e.type)}function yi(e){return wy.includes(e.type)}function Ye(e){let t=new Map,n=[],r=(i,a,d)=>{let c={node:i,page:a,instance:d};t.has(i.id)||t.set(i.id,c),st(i)&&i.mask!==void 0&&n.push(c);let l=i.type==="instance"?i.id:d;for(let p of te(i)){let m=i===e&&p.type==="frame"?p.id:a;r(p,m,l)}};r(e,e.id,void 0);let o=new Map,s=[];for(let i of n){let a=i.node,d=a.mask,c=i.instance===void 0?void 0:Ht(i.instance,d),l=(c===void 0?void 0:t.get(c))??t.get(d);if(!l){s.push({severity:"error",code:"unknown-reference",message:`${a.id}: mask=${d} names nothing in the document, so it is drawn unmasked \u2014 point mask= at a rect, ellipse or vector on its page`,nodeId:a.id,prop:"mask"});continue}if(!yi(l.node)){s.push({severity:"error",code:"mask-not-a-shape",message:l.node.id===a.id?`${a.id} cannot be its own mask, so it is drawn unmasked \u2014 point mask= at a rect, ellipse or vector`:`${a.id}: mask=${d} is ${f_(l.node.type)} ${l.node.type}, so it is drawn unmasked \u2014 a mask is a rect, ellipse or vector`,nodeId:a.id,prop:"mask"});continue}if(l.page!==i.page){s.push({severity:"error",code:"mask-wrong-page",message:`${a.id}: mask=${d} is on ${l.page}, not ${i.page}, so it is drawn unmasked \u2014 move the shape onto the image's page`,nodeId:a.id,prop:"mask"});continue}o.set(a.id,l.node.id)}return{links:o,shapes:new Set(o.values()),problems:s}}function Jl(e){return[...Ye(e).problems]}function fr(e,t){if(t===e.id)return e.id;for(let n of te(e))if(Sy(n,t))return n.type==="frame"?n.id:e.id}function nd(e,t){let n=new Set,r=a=>{n.add(a.id);for(let d of te(a))r(d)};for(let a of t){let d=ky(e,a);d&&r(d)}let o=Ye(e).links,s=[],i=a=>{if(st(a)&&a.mask!==void 0&&!n.has(a.id)){let d=o.get(a.id);(n.has(a.mask)||d!==void 0&&n.has(d))&&s.push(a.id)}for(let d of te(a))i(d)};return i(e),s}function ky(e,t){if(e.id===t)return e;for(let n of te(e)){let r=ky(n,t);if(r)return r}}function Sy(e,t){return e.id===t||te(e).some(n=>Sy(n,t))}function f_(e){return/^[aeiou]/.test(e)?"an":"a"}function bi(e,t,n){let r={x:t.x,y:t.y,w:Math.max(0,t.w),h:Math.max(0,t.h)},o=d=>({x:d.x+r.x,y:d.y+r.y}),s,i="nonzero";switch(e.type){case"rect":s=Be(Dn(r.w,r.h,Zn(n)),o);break;case"ellipse":s=Be(Vr(r.w,r.h),o);break;case"vector":s=Be(ar(e.d).contours,Fr(Ir(e.view,r.w,r.h),r)),i=e.rule??"nonzero";break;case"canvas":case"connector":case"frame":case"group":case"image":case"instance":case"text":case"video":return}let a=n.rotation??0;if(a%360!==0){let d=Re(r);s=Be(s,c=>je(c,d,a))}return{contours:s,rule:i}}var p_=/^[A-Za-z_][\w-]*$/;function mn(e){return Ql(e).map(t=>t.trim())}function vi(e){return/^\s*image\s*\(/i.test(e)}function Xo(e){let t=e.trim();if(t==="")return{error:"A paint list has an empty layer"};if(!vi(t))return wi(t);let n=/^image\s*\(([\s\S]*)\)$/i.exec(t);if(!n)return{error:'An image paint needs its closing ")"'};let r=Ql(n[1]).map(i=>i.trim()),o=r[0]??"";if(!p_.test(o))return{error:`image() names an asset, like image(photo, cover), not ${JSON.stringify(o)}`};if(r.length>2)return{error:"image() takes an asset and a fit: image(photo, cover)"};let s=(r[1]??"cover").toLowerCase();return Zt.includes(s)?{kind:"image",asset:o,fit:s}:{error:`An image paint's fit is cover, contain or fill, not ${JSON.stringify(s)}`}}function rd(e){return/^\s*(linear|radial|conic|repeating-[a-z]+)-gradient\s*\(/i.test(e)}function wi(e){let t=e.trim(),n=/^([a-z-]+)-gradient\s*\(([\s\S]*)\)$/i.exec(t);if(!n)return rd(t)?{error:'A gradient needs its closing ")"'}:{kind:"solid",colour:t};let r=n[1].toLowerCase(),o=Ql(n[2]).map(s=>s.trim());if(o.some(s=>s===""))return{error:"A gradient has an empty argument"};if(r==="linear"){let s=m_(o[0]),i=Ey(s===void 0?o:o.slice(1));return"error"in i?i:{kind:"linear",angle:s??180,stops:i.stops}}if(r==="radial"){let s=g_(o[0]);if(s&&"error"in s)return s;let i=Ey(s?o.slice(1):o);return"error"in i?i:{kind:"radial",shape:s?.shape??"ellipse",cx:s?.cx??.5,cy:s?.cy??.5,stops:i.stops}}return{error:`${r}-gradient is not supported; use linear-gradient or radial-gradient`}}function Zl(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,s=r;for(;t[s]===void 0;)s+=1;let i=t[o],a=t[s];for(let d=r;d<s;d+=1)t[d]=i+(a-i)*(d-o)/(s-o);r=s}return e.map((r,o)=>({colour:r.colour,at:t[o]}))}function Ql(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o+=1){let s=e[o];s==="("?n+=1:s===")"?n=Math.max(0,n-1):s===","&&n===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}var h_={top:[0,-1],bottom:[0,1],left:[-1,0],right:[1,0]};function m_(e){let t=/^(-?\d*\.?\d+)(deg|turn|rad)$/i.exec(e);if(t){let s=Number(t[1]),i=t[2].toLowerCase();return i==="turn"?s*360:i==="rad"?s*180/Math.PI:s}let n=/^to\s+([a-z]+)(?:\s+([a-z]+))?$/i.exec(e);if(!n)return;let r=0,o=0;for(let s of[n[1],n[2]]){if(s===void 0)continue;let i=h_[s.toLowerCase()];if(!i)return;r+=i[0],o+=i[1]}return(Math.atan2(r,-o)*180/Math.PI+360)%360}var x_={left:0,top:0,center:.5,right:1,bottom:1};function g_(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=_y(t[2]),o=t[3]===void 0?.5:_y(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 _y(e){let t=x_[e.toLowerCase()];if(t!==void 0)return t;let n=/^(-?\d*\.?\d+)%$/.exec(e);return n?Number(n[1])/100:void 0}function Ey(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&&y_(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 y_(e){let t=0;for(let n of e)if(n==="("&&(t+=1),n===")"&&(t-=1),t<0)return!1;return t===0}function od(e){return mn(e).flatMap(t=>{let n=Xo(t);return"error"in n||n.kind==="image"?[]:n.kind==="solid"?[n.colour]:n.stops.map(r=>r.colour)})}function My(e,t={}){if(typeof e!="string")return[];let n=o=>{let s=t[o];return typeof s=="string"?s:o},r=[];for(let o of mn(n(e.trim())))for(let s of mn(n(o))){let i=Xo(s);!("error"in i)&&i.kind==="image"&&!r.includes(i.asset)&&r.push(i.asset)}return r}function sd(e,t={}){let n=e,r=[];(e.type==="image"||e.type==="video")&&typeof n.src=="string"&&r.push(n.src);for(let o of["fill","background"])for(let s of My(n[o],t))r.includes(s)||r.push(s);return r}var Yo={union:"Union",subtract:"Subtract",intersect:"Intersect",exclude:"Exclude"};var $y=["rect","ellipse","vector"];function b_(e,t){let n=[],r,o=s=>{if(s.id===t)return r={node:s,path:[...n]},!0;if(!me(s))return!1;n.push(s);for(let i of s.children)if(o(i))return!0;return n.pop(),!1};return o(e),r}function Cy(e){for(let t=e.path.length-1;t>=0;t-=1){let n=e.path[t];if(!Ne(n))return n}}function Jo(e,t,n){let r=[...new Set(t)];if(r.length<2)return{code:"merge-too-few",message:`merge needs two or more shapes, got ${r.length===0?"none":"one"}`};let o=[];for(let i of r){let a=b_(e.root,i);if(!a)return{code:"unknown-reference",message:`No node ${i}`,nodeId:i};let d=a.node.type;if(d==="text")return{code:"merge-not-a-shape",message:`${i} is text, which cannot be merged: there is no outline-text operation yet. Merge rects, ellipses and vectors`,nodeId:i};if(!$y.includes(d))return{code:"merge-not-a-shape",message:`${i} is ${/^[aeiou]/.test(d)?"an":"a"} ${d}; only rects, ellipses and vectors can be merged${d==="group"?" (name the shapes inside it)":""}`,nodeId:i};if(!Ay(e,a.node,"fill"))return{code:"merge-stroke-only",message:Ay(e,a.node,"stroke")?`Merge works on filled areas; ${i} is only a stroke`:`Merge works on filled areas; ${i} paints nothing`,nodeId:i};if([a.node,...a.path].some(c=>c.hidden===!0))return{code:"merge-hidden",message:`${i} is hidden; show it before merging it`,nodeId:i};if(a.path.some(c=>c.type==="instance"))return{code:"merge-in-instance",message:`${i} is part of an instance, which its component decides; merge the shapes in the component`,nodeId:i};o.push(a)}let s=Cy(o[0]);for(let i of o.slice(1))if(Cy(i)!==s)return{code:"merge-across-frames",message:`${o[0].node.id} and ${i.node.id} are in different frames; merge shapes that share a page or frame`,nodeId:i.node.id};if(n!==void 0&&!r.includes(n)&&z(e.root,n))return{code:"duplicate-id",message:`${n} already names a node`,nodeId:n}}function Zo(e){return{code:"merge-failed",message:`The shapes could not be merged (${e instanceof Error?e.message:String(e)}); nothing was changed`}}function Ay(e,t,n){let r=t[n];if(r===void 0)return n==="fill";if(typeof r!="string")return!0;let o=Ze(e),s=o[r];return mn(typeof s=="string"?s:r).some(i=>{let a=o[i];return v_(typeof a=="string"?a:i)})}function v_(e){let t=e.trim().toLowerCase();if(t==="none"||t==="transparent")return!1;let n=/^#([0-9a-f]{4}|[0-9a-f]{8})$/.exec(t);if(n){let o=n[1];return o.length===4?o[3]!=="0":o.slice(6)!=="00"}let r=/^(?:rgba?|hsla?)\((.*)\)$/.exec(t);if(r){let o=r[1].split(/[\s,/]+/).filter(s=>s!=="");if(o.length===4)return parseFloat(o[3])!==0}return!0}function ef(e,t){let n=new Set(t),r=[],o=s=>{if(n.has(s.id)&&r.push(s.id),me(s))for(let i of s.children)o(i)};return o(e.root),r}var Ly="https://getv.design/ns/vd",pL=`<metadata><vd:document xmlns:vd="${Ly}" version="1"><![CDATA[
42
+ `;var S_=/<vd:document\b[^>]*>([\s\S]*?)<\/vd:document\s*>/;function tf(e){let t=S_.exec(e);if(!t)return;let n=t[1]??"",r="",o=n;for(;;){let s=o.indexOf("<![CDATA[");if(s===-1){r+=Ty(o);break}r+=Ty(o.slice(0,s));let i=o.indexOf("]]>",s);if(i===-1){r+=o.slice(s+9);break}r+=o.slice(s+9,i),o=o.slice(i+3)}return`${r.replace(/^\n/,"").replace(/\n$/,"")}
43
+ `}function nf(e){return/^\uFEFF?\s*</.test(e)}function Ty(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 sf(e){let t=[],n=et(e);if(!n)return t.push({severity:"error",code:"invalid-document",message:"Expected an object"}),{document:Js(),problems:t};Xs.includes(n.version)||t.push({severity:"warning",code:"version-mismatch",message:`Expected version ${Ys} or older, got ${JSON.stringify(n.version)}`});let r=Ny(n.root,t);r&&q_(r,t);let o=r&&$n(r),s=__(n.motion,t),i=$_(n.kind,t),a=n.brand===void 0?void 0:Gc(n.brand,g=>{t.push({severity:"error",code:"invalid-brand",message:g})}),d=et(et(n.themes)?.dark),c=d===void 0?void 0:un({dark:Py(d,t)}),l={...a===void 0?{}:{brand:a},...c===void 0?{}:{themes:c}},p=T_(n.fonts,t),m={version:Et({kind:i,fonts:p,...l,...o?{root:o}:{}}),kind:i,...typeof n.title=="string"&&n.title.trim()!==""?{title:n.title}:{},tokens:Py(n.tokens,t),fonts:p,assets:O_(n.assets,t),...s===void 0?{}:{motion:s},...l,root:o??Oo({id:dn,children:[]})};return t.push(...Io(m)),{document:m,problems:t}}function __(e,t){if(e===void 0)return;let n=et(e),r=s=>{t.push({severity:"error",code:"invalid-motion",message:s})};if(!n){r("`motion` must be an object");return}let o={};for(let[s,i]of Object.entries(n)){let a=et(i);if(!a||!Array.isArray(a.lines)){r(`motion ${s} must be an object with a lines array`);continue}let d=a.enter,c=a.duration;if(d!==void 0&&!Do.includes(d)){r(`motion ${s}: enter must be one of ${Do.join(", ")}`);continue}if(c!==void 0&&!A_(c)){r(`motion ${s}: duration must be 0 to ${cn} milliseconds`);continue}let l=a.scroll;if(l!==void 0&&typeof l!="boolean"){r(`motion ${s}: scroll must be true or false`);continue}let p=a.bpm,m=a.meter;if(p!==void 0&&!(typeof p=="number"&&p>=20&&p<=300)){r(`motion ${s}: bpm must be ${20} to ${300}`);continue}if(m!==void 0&&!(typeof m=="number"&&Number.isInteger(m)&&m>=1&&m<=16)){r(`motion ${s}: meter must be a whole number from 1 to ${16}`);continue}let g=en({...p===void 0?{}:{bpm:p},...m===void 0?{}:{meter:m},lines:[]}),b=C_(a.music,g);if(b===null){r(`motion ${s}: music must be { asset, from?, volume?, fadein?, fadeout?, loop? }`);continue}let w=a.length;if(w!==void 0&&!af(w,sr,g)){r(`motion ${s}: length must be 0 to ${sr} milliseconds, or beats with a bpm`);continue}let k=R=>R===void 0||typeof R=="number"&&R>=16&&R<=ln;if(!k(a.w)||!k(a.h)){r(`motion ${s}: w and h must be 16 to ${ln} pixels`);continue}let _=a.lines.flatMap(R=>{let B=E_(R,g);return B===void 0&&r(`motion ${s}: a line that is not one: ${JSON.stringify(R)}`),B===void 0?[]:[B]}),M={...d===void 0?{}:{enter:d},...c===void 0?{}:{duration:c},...l===!0?{scroll:!0}:{},...w===void 0?{}:{length:w},...a.w===void 0?{}:{w:a.w},...a.h===void 0?{}:{h:a.h},...p===void 0?{}:{bpm:p},...m===void 0?{}:{meter:m},...b===void 0?{}:{music:b},lines:_};Tn(M)||(o[s]=M)}return Object.keys(o).length===0?void 0:o}function E_(e,t){let n=et(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[p,m]of jr){let g=n[p];if(g!==void 0){if(!M_(p,m,g,t))return;r[p]=g}}if(r.on!==void 0&&(!t||r.with!==void 0||r.together))return;let{enter:o,exit:s,emphasis:i,step:a,together:d}=r;if(o!==void 0&&s!==void 0||i!==void 0&&(o!==void 0||s!==void 0)||a===!0&&d===!0||["at","after","with","together","step"].filter(p=>r[p]!==void 0).length>1||r.camera===!0&&(o??s??i??r.go)!==void 0)return;let l=r;return No(l)?l:void 0}function M_(e,t,n,r){switch(t){case"time":return af(n,e==="at"?sr:cn,r);case"on":return Zs.includes(n);case"boolean":return n===!0;case"number":return typeof n!="number"||!Number.isFinite(n)||n<0?!1:e==="at"?n<=sr:e==="pad"?n<=ln:n<=cn;case"string":return typeof n=="string"&&(e!=="go"||On(n)!==void 0);case"nodeEffect":return ti.includes(n);case"emphasisEffect":return ni.includes(n);case"ease":return ri.includes(n);case"piece":return oi.includes(n);case"from":return typeof n=="number"&&Number.isFinite(n)||or.includes(n);default:return!1}}function C_(e,t){if(e===void 0)return;let n=et(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"&&!ei.includes(i))return null;let o=n.from;if(o!==void 0&&!(typeof o=="number"&&o>=0&&o<=Lo))return null;let s=n.volume;if(s!==void 0&&!(typeof s=="number"&&s>=0&&s<=1))return null;for(let i of["fadein","fadeout"])if(n[i]!==void 0&&!af(n[i],cn,t))return null;if(n.loop!==void 0&&n.loop!==!0)return null;for(let i of ei)n[i]!==void 0&&(r[i]=n[i]);return r}function af(e,t,n){if(typeof e=="number")return Number.isFinite(e)&&e>=0&&e<=t;if(!Dr(e)||!n)return!1;let r=Lr(e);if(!r||Pr(r.count,r.unit)!==e)return!1;let o=ft(e,n);return o!==void 0&&o<=t}function A_(e){return typeof e=="number"&&e>=0&&e<=cn}function $_(e,t){return e==null?rr:typeof e=="string"&&Tr.includes(e)?e:(t.push({severity:"error",code:"unknown-kind",message:`Unknown kind ${JSON.stringify(e)} \u2014 this build reads ${Tr.join(", ")}`}),rr)}function Py(e,t){let n={};if(e===void 0)return n;let r=et(e);if(!r)return t.push({severity:"error",code:"invalid-tokens",message:"`tokens` must be an object"}),n;for(let[o,s]of Object.entries(r))typeof s=="number"||typeof s=="string"?n[o]=s:t.push({severity:"error",code:"invalid-token",message:`Token $${o} must be a number or string`});return n}function O_(e,t){let n={};if(e===void 0)return n;let r=et(e);if(!r)return t.push({severity:"error",code:"invalid-assets",message:"`assets` must be an object"}),n;for(let[o,s]of Object.entries(r)){let i=et(s);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}:{},...yt(i.credit,"credit"),...yt(i.source,"source"),...yt(i.license,"license")}}return n}function T_(e,t){let n={};if(e===void 0)return n;let r=et(e);if(!r)return t.push({severity:"error",code:"invalid-fonts",message:"`fonts` must be an object"}),n;for(let[o,s]of Object.entries(r)){let i=et(s);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}:{},...L_(i.faces,o,t)}}return n}function L_(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 s=et(o),i=s?.src,a=s?.asset;if(!s||typeof i=="string"==(typeof a=="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 d=s.style;r.push({...typeof i=="string"?{src:i}:{asset:a},...typeof s.weight=="number"?{weight:s.weight}:{},...d==="italic"||d==="normal"?{style:d}:{}})}return r.length>0?{faces:r}:{}}function P_(e,t){let n=et(e);if(!n){t.push({severity:"error",code:"invalid-node",message:"Expected a node object"});return}switch(n.type){case"canvas":return Ny(e,t);case"connector":return j_(n,t);case"ellipse":return U_(n,t);case"frame":return D_(n,t);case"group":return N_(n,t);case"image":return V_(n,t);case"instance":return R_(n,t);case"rect":return H_(n,t);case"text":return K_(n,t);case"vector":return z_(n,t);case"video":return B_(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 Ny(e,t){let n=et(e);if(!n){t.push({severity:"error",code:"invalid-node",message:"`root` must be a canvas node"});return}let r=rn(n,dn,t);return{type:"canvas",id:r,...yt(n.name,"name"),...Dy(n,"w",1280,r,t),...Dy(n,"h",720,r,t),...nn(n.background,r,"background",t),children:df(n.children,r,t)}}function Dy(e,t,n,r,o){return e[t]===void 0?{}:{[t]:Ee(e[t],r,t,n,o)}}function D_(e,t){let n=rn(e,"frame",t);return{type:"frame",id:n,...yt(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),...nn(e.background,n,"background",t),...hr(e,n,t,{align:!0,cap:!0}),...id(e,n,t),...Qo(e.clip,"clip"),...Qo(e.skip,"skip"),...Qo(e.component,"component"),...pr(e,n,t),...xn(e),children:df(e.children,n,t)}}function N_(e,t){let n=rn(e,"group",t);return{type:"group",id:n,...yt(e.name,"name"),...xn(e),children:df(e.children,n,t)}}function R_(e,t){let n=rn(e,"instance",t),r=e.component;(typeof r!="string"||r==="")&&t.push({severity:"error",code:"invalid-value",message:"An instance needs the id of the component it places",nodeId:n,prop:"component"});let o=I_(e.overrides,n,t);return{type:"instance",id:n,...yt(e.name,"name"),component:typeof r=="string"?r:"",x:Ee(e.x,n,"x",0,t),y:Ee(e.y,n,"y",0,t),...Ie(e.w,n,"w",t),...Ie(e.h,n,"h",t),...o===void 0?{}:{overrides:o},...xn(e),children:[]}}function I_(e,t,n){if(e===void 0)return;let r=et(e);if(!r){n.push({severity:"error",code:"invalid-value",message:"`overrides` must be an object of inner id to properties",nodeId:t,prop:"overrides"});return}let o={};for(let[s,i]of Object.entries(r)){let a=et(i);if(!a)continue;let d={};for(let[c,l]of Object.entries(a)){let p=F_(c,l,t,n);p!==void 0&&(d[c]=p)}Object.keys(d).length>0&&(o[s]=d)}return Object.keys(o).length===0?void 0:o}function F_(e,t,n,r){let o=()=>{r.push({severity:"error",code:"invalid-value",message:`${n} overrides ${e} with ${JSON.stringify(t)}, which it cannot hold`,nodeId:n,prop:e})};if(!nr(e))return o();if(e==="content")return typeof t=="string"||Array.isArray(t)&&t.every(d=>typeof d=="string"||typeof d=="object"&&d!==null&&typeof d.text=="string")?Iy(t,n,r):o();let s=Ja(e);if(s===void 0)return o();if(s==="numberValue")return Fy(t)??o();if(s==="stringValue")return typeof t!="string"?o():t.startsWith("=")?_t(t.slice(1)):t;if(s==="boolean")return typeof t=="boolean"?t:o();if(s==="number")return typeof t=="number"&&Number.isFinite(t)?t:o();if(typeof t!="string")return o();let i=Qe(JSON.stringify(t),s);return"error"in i?o():i.value}function df(e,t,n){let r=[];if(Array.isArray(e))for(let o of e){let s=P_(o,n);s&&r.push(s)}else e!==void 0&&n.push({severity:"error",code:"invalid-children",message:"`children` must be an array",nodeId:t});return r}function B_(e,t){let n=rn(e,"video",t),r=e.fit,o=nn(e.src,n,"src",t);return{type:"video",id:n,...yt(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",160,t),h:Ee(e.h,n,"h",90,t),...Ie(e.rotation,n,"rotation",t),src:o.src??"",...Zt.includes(r)?{fit:r}:{},...rf(e.start,n,"start",t),...rf(e.end,n,"end",t),...rf(e.poster,n,"poster",t),...Qo(e.muted,"muted"),...Qo(e.loop,"loop"),...Ry(e,n,t),...hr(e,n,t,{align:!0,cap:!0}),...id(e,n,t),...Ie(e.opacity,n,"opacity",t),...pr(e,n,t),...xn(e)}}function V_(e,t){let n=rn(e,"image",t),r=e.fit,o=nn(e.src,n,"src",t);return{type:"image",id:n,...yt(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),...Ie(e.rotation,n,"rotation",t),src:o.src??"",...Zt.includes(r)?{fit:r}:{},...Ry(e,n,t),...hr(e,n,t,{align:!0,cap:!0}),...id(e,n,t),...Ie(e.opacity,n,"opacity",t),...pr(e,n,t),...xn(e)}}function Ry(e,t,n){let r=e.mask;return r===void 0?{}:typeof r=="string"&&r!==""?{mask:r}:(n.push({severity:"error",code:"invalid-value",message:`${t}: mask must be the id of a rect, ellipse or vector`,nodeId:t,prop:"mask"}),{})}function H_(e,t){let n=rn(e,"rect",t);return{type:"rect",id:n,...yt(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),...Ie(e.rotation,n,"rotation",t),...nn(e.fill,n,"fill",t),...hr(e,n,t,{align:!0,cap:!0}),...id(e,n,t),...Ie(e.opacity,n,"opacity",t),...pr(e,n,t),...xn(e)}}function U_(e,t){let n=rn(e,"ellipse",t);return{type:"ellipse",id:n,...yt(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),...Ie(e.rotation,n,"rotation",t),...nn(e.fill,n,"fill",t),...hr(e,n,t,{align:!0,cap:!0}),...Ie(e.opacity,n,"opacity",t),...pr(e,n,t),...xn(e)}}function z_(e,t){let n=rn(e,"vector",t);return{type:"vector",id:n,...yt(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),...Ie(e.rotation,n,"rotation",t),...yt(e.view,"view"),d:typeof e.d=="string"?e.d:"",...nn(e.fill,n,"fill",t),...hr(e,n,t,{align:!0,cap:!1}),...Ie(e.opacity,n,"opacity",t),...tn(e.rule,Ar,n,"rule",t),...tn(e.cap,tr,n,"cap",t),...tn(e.join,$r,n,"join",t),...pr(e,n,t),...xn(e)}}function j_(e,t){let n=rn(e,"connector",t);return{type:"connector",id:n,...yt(e.name,"name"),x1:Ee(e.x1??0,n,"x1",0,t),y1:Ee(e.y1??0,n,"y1",0,t),x2:Ee(e.x2??0,n,"x2",0,t),y2:Ee(e.y2??0,n,"y2",0,t),...tn(e.route,Hr,n,"route",t),...tn(e.start,ur,n,"start",t),...tn(e.end,ur,n,"end",t),...hr(e,n,t,{align:!1,cap:!0}),...Ie(e.opacity,n,"opacity",t),...pr(e,n,t),...xn(e)}}function K_(e,t){let n=rn(e,"text",t);return{type:"text",id:n,...yt(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),...Ie(e.rotation,n,"rotation",t),content:Iy(e.content,n,t),...nn(e.font,n,"font",t),...Ie(e.size,n,"size",t),...Ie(e.weight,n,"weight",t),...Ie(e.lineHeight,n,"lineHeight",t),...Ie(e.letterSpacing,n,"letterSpacing",t),...tn(e.align,Qn,n,"align",t),...tn(e.valign,er,n,"valign",t),...Qo(e.italic,"italic"),...nn(e.fill,n,"fill",t),...hr(e,n,t,{align:!1,cap:!1}),...Ie(e.opacity,n,"opacity",t),...pr(e,n,t),...xn(e)}}function Iy(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 s=et(o);if(!s||typeof s.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:s.text,...Rn(s,"font","string"),...Rn(s,"size","number"),...Rn(s,"weight","number"),...Rn(s,"italic","boolean"),...Rn(s,"underline","boolean"),...Rn(s,"strike","boolean"),...Rn(s,"fill","string"),...Rn(s,"letterSpacing","number"),...Rn(s,"link","string")})}return r}function Rn(e,t,n){let r=e[t];return typeof r!==n?{}:n==="number"&&!Number.isFinite(r)?{}:{[t]:r}}function pr(e,t,n){return{...tn(e.blend,Cr,t,"blend",n),...nn(e.shadow,t,"shadow",n),...Ie(e.blur,t,"blur",n),...Aa(e.type)?Ie(e.backdrop,t,"backdrop",n):of(e,"backdrop",t,n)}}function hr(e,t,n,r){return{...nn(e.stroke,t,"stroke",n),...Ie(e.strokeWidth,t,"strokeWidth",n),...G_(e.dash,t,n),...r.align?tn(e.strokeAlign,Ur,t,"strokeAlign",n):of(e,"strokeAlign",t,n),...r.cap?tn(e.cap,tr,t,"cap",n):e.type==="vector"?{}:of(e,"cap",t,n)}}function of(e,t,n,r){return e[t]===void 0?{}:(r.push({severity:"error",code:"invalid-value",message:`${n}: ${String(e.type)} has no property "${t}"`,nodeId:n,prop:t}),{})}function G_(e,t,n){if(e===void 0)return{};let r=typeof e=="string"?zr(e):{error:'expected text like "6 4"'};return"dash"in r?{dash:Ho(r.dash)}:(n.push({severity:"error",code:"invalid-value",message:`${t}: dash \u2014 ${r.error}`,nodeId:t,prop:"dash"}),{})}function id(e,t,n){return Object.assign({},...Cn.map(r=>Ie(e[r],t,r,n)))}function xn(e){return{...e.hidden===!0?{hidden:!0}:{},...e.locked===!0?{locked:!0}:{}}}function Qo(e,t){return typeof e=="boolean"?{[t]:e}:{}}function rf(e,t,n,r){return e===void 0?{}:typeof e=="number"&&Number.isFinite(e)&&e>=0?{[n]:e}:(r.push({severity:"error",code:"invalid-value",message:`Expected milliseconds into the clip (0 or more) for ${n}, got ${JSON.stringify(e)}`,nodeId:t,prop:n}),{})}function tn(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 rn(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 s=Fy(e);return s!==void 0?s:(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 Fy(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.startsWith("="))return _t(e.slice(1))}function Ie(e,t,n,r){return e===void 0?{}:{[n]:Ee(e,t,n,0,r)}}function nn(e,t,n,r){return e===void 0?{}:typeof e=="string"?{[n]:e.startsWith("=")?_t(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 yt(e,t){return typeof e=="string"?{[t]:e}:{}}function q_(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),me(o)&&o.children.forEach(r)};r(e)}function et(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}var By=1500,uf=5e3,Vy=1200,Hy=800,Uy=600,zy=800,jy={letter:30,word:80,children:100},ki=.04,Si=.85,cf=1.06,ad=[.2,0,0,1],dd=[.4,0,1,1],ud=[.4,0,.2,1],Ky=[.34,1.56,.64,1],W_={out:ad,in:dd,inout:ud,linear:null,spring:Ky};function lf(e,t){let n=e.motion?.[t],r=n?.w!==void 0||n?.h!==void 0?X_(e,t,n):void 0,o=en(n),s=o?{tempo:o}:{},i=fl(n,e.assets);if(!n||!Ln(e).has(t))return{page:t,length:ft(n?.length,o,uf),beats:[],camera:!1,steps:[],...r?{size:r}:{},...s,clips:i};let a=Ut(e),d=[],c=[],l,p=new Map;for(let[b,w]of n.lines.entries()){if(a.get(w.id)!==t||w.camera!==!0&&w.enter===void 0&&w.exit===void 0&&w.emphasis===void 0)continue;let k=z(e.root,w.id);if(!k)continue;let _=G=>G===void 0?void 0:p.get(G),M;w.at!==void 0?M=ft(w.at,o,0):w.with!==void 0&&_(w.with)?M=_(w.with).start:w.after!==void 0&&_(w.after)?M=_(w.after).end:w.together===!0?M=l?.start??0:M=l?.end??0,M+=ft(w.delay,o,0);let R;if(w.on!==void 0&&o){let G=al(M,w.on,o);G!==M&&(R=M),M=G}w.step===!0&&c.push(M);let B=w.camera===!0?"camera":w.enter!==void 0?"enter":w.exit!==void 0?"exit":"emphasis",D=w.enter??w.exit??w.emphasis,V=Y_(w,D,o),T=B==="camera"||B==="emphasis"?void 0:J_(w,k),O=T===void 0?1:Math.max(1,Gy(k,T)),j=O>1&&T!==void 0?ft(w.stagger,o,jy[T]):0,$=M+(O-1)*j+V,P=w.ease??(B==="enter"?"out":B==="exit"?"in":"inout");d.push({index:b,line:w,kind:B,...R===void 0?{}:{asked:R},...D===void 0?{}:{effect:D},start:M,end:$,duration:V,ease:P,pieces:O,stagger:j,...T===void 0||O===1?{}:{split:T}});let C=$;if(B==="enter"&&w.hold!==void 0&&w.enter!=="count"){let G=$+ft(w.hold,o,0);C=G+V,d.push({index:b,line:w,kind:"exit",...D===void 0?{}:{effect:D},start:G,end:C,duration:V,ease:"in",pieces:1,stagger:0})}l={start:M,end:C},w.camera!==!0&&p.set(w.id,l)}let m=Math.max(0,...d.map(b=>b.end)),g=ft(n.length,o,d.length===0?uf:m+By);return{page:t,length:g,beats:d,camera:d.some(b=>b.kind==="camera"),steps:c,...r?{size:r}:{},...s,clips:i}}function X_(e,t,n){let r=n.w,o=n.h;if(r!==void 0&&o!==void 0)return{w:r,h:o};let s=z(e.root,t),i=s&&"w"in s&&typeof s.w=="number"?s.w:void 0,a=s&&"h"in s&&typeof s.h=="number"?s.h:void 0;if(r!==void 0)return{w:r,h:i&&a?Math.round(r*a/i):r};if(o!==void 0)return{w:i&&a?Math.round(o*i/a):o,h:o}}function Y_(e,t,n){return t==="cut"?0:e.duration!==void 0?ft(e.duration,n,si):e.camera===!0?zy:e.emphasis!==void 0?Uy:t==="count"?Vy:t==="draw"?Hy:si}function J_(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&&te(t).length>0)return"children"}function Gy(e,t){return t==="children"?te(e).length:e.type!=="text"?1:t==="word"?ff(ir(e.content)).length:qy(ir(e.content)).length}function ff(e){return e.split(/\s+/).filter(t=>t!=="")}function qy(e){return[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(e)].map(n=>n.segment).filter(n=>n.trim()!=="")}function cd(e,t){if(t<=0)return 0;if(t>=1)return 1;let n=W_[e];return n===null?t:Z_(n,t)}function Z_(e,t){let[n,r,o,s]=e,i=(l,p,m)=>3*l*m*(1-m)**2+3*p*m*m*(1-m)+m**3,a=0,d=1,c=t;for(let l=0;l<40;l++){c=(a+d)/2;let p=i(n,o,c);if(Math.abs(p-t)<1e-7)break;p<t?a=c:d=c}return i(r,s,c)}function pf(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(",",""),s=o.includes(".")?o.split(".")[1].length:0;return{before:e.slice(0,t.index),value:Number(o),decimals:s,grouping:r,after:e.slice(t.index+n.length)}}function hf(e,t){let n=Math.abs(t).toFixed(e.decimals),[r,o]=n.split("."),s=e.grouping===""?r:r.replace(/\B(?=(\d{3})+(?!\d))/g,e.grouping),i=t<0&&Number(n)!==0?"-":"";return`${e.before}${i}${s}${o===void 0?"":`.${o}`}${e.after}`}var Wy=1200,Xy=3.5;function Yy(e){return Math.max(Wy,Math.round(ff(e).length/Xy*1e3))}function mf(e){let t=[];for(let n of Object.keys(e.motion??{})){let r=e.motion?.[n];if(!Nr(r)||!Ln(e).has(n))continue;let o=lf(e,n);t.push(...Q_(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 ${Qs(i.start)}, after the video ends at ${Qs(o.length)}`,nodeId:i.line.id});let s=new Map;for(let i of o.beats)if(i.kind==="enter"&&!s.has(i.line.id))s.set(i.line.id,{from:i.start,to:o.length});else if(i.kind==="exit"){let a=s.get(i.line.id);s.set(i.line.id,{from:a?.from??0,to:i.start})}for(let[i,{from:a,to:d}]of s){let c=z(e.root,i);if(c?.type!=="text")continue;let l=ir(c.content),p=Yy(l);d-a<p&&t.push({severity:"warning",code:"video-text-brief",message:`motion ${n}: ${i} is on screen for ${Qs(d-a)}; "${eE(l)}" takes about ${p} ms to read`,nodeId:i})}}return t}function Q_(e,t,n){let r=e.motion?.[t]?.music,o=n.clips[0];if(!r||!o)return[];let s=(m,g)=>({severity:"warning",code:m,message:`motion ${t}: ${g}`,nodeId:t}),i=m=>`${(m/1e3).toFixed(2)} s`,a=e.assets[r.asset];if(!a)return[s("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(!a.type.startsWith("audio/"))return[s("music-not-audio",`music ${r.asset} is ${a.type}, not a sound`)];let d=[],c=o.from;a.ms!==void 0&&c>=a.ms?d.push(s("music-from-past-end",`from=${c} is past the end of ${r.asset}, which is ${i(a.ms)} long`)):a.ms!==void 0&&!o.loop&&a.ms-c<n.length-dl&&d.push(s("music-short",`${r.asset} runs out at ${i(a.ms-c)} and the video at ${i(n.length)}: add loop, or set length=`));let l=a.ms!==void 0&&a.ms>0?a.bytes*8/a.ms:void 0,p=2*(n.length+c)*ul/1e3;return l!==void 0&&l>cl?d.push(s("audio-heavy",`${r.asset} is ${Math.round(l)} kbps: re-encode it as a 128 kbps MP3 or M4A, about 1 MB a minute`)):a.bytes>p&&d.push(s("audio-heavy",`${r.asset} is ${(a.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 eE(e){return e.length>40?`${e.slice(0,37)}\u2026`:e}function es(e){let t=e.trim();if(t===""||t==="none")return{shadows:[]};let n=[];for(let r of tE(t)){let o=nE(r.trim()),s=o.filter(b=>b.toLowerCase()==="inset").length;if(s>1)return{error:`"${r.trim()}" says inset more than once`};let i=o[0]?.toLowerCase()==="inset",a=o[o.length-1]?.toLowerCase()==="inset";if(s===1&&!i&&!a)return{error:`"${r.trim()}" needs inset first or last, as CSS writes it`};s===1&&(o=i?o.slice(1):o.slice(0,-1));let d=[],c=[];for(let b of o){let w=/^(-?\d*\.?\d+)(px)?$/.exec(b);w&&c.length===0?d.push(Number(w[1])):c.push(b)}if(d.length<2||d.length>4)return{error:`"${r.trim()}" needs x, y, then optional blur and spread`};if(c.length!==1)return{error:`"${r.trim()}" needs one colour after its numbers`};let[l=0,p=0,m=0,g=0]=d;if(m<0)return{error:"A shadow cannot have a negative blur"};n.push({x:l,y:p,blur:m,spread:g,colour:c[0],...s?{inset:!0}:{}})}return{shadows:n}}function tE(e){let t=[],n=0,r=0;for(let o=0;o<e.length;o+=1){let s=e[o];s==="("?n+=1:s===")"?n=Math.max(0,n-1):s===","&&n===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}function nE(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 ld=["video/mp4","video/webm"];function xf(e){return ld.includes(e.type)}function gf(e,t){return e.end===void 0?t:t===void 0?e.end:Math.min(e.end,t)}function yf(e,t){let n=e.start??0,r=gf(e,t),o=e.poster??n;return r===void 0?Math.max(o,n):rE(o,n,Jy(n,r))}function bf(e,t,n){let r=e.start??0,o=gf(e,t),s=Math.max(n,0);if(o===void 0||o<=r)return r+s;let i=o-r;return s<i?r+s:e.loop===!0?r+s%i:Jy(r,o)}function Jy(e,t){return Math.max(e,t-1)}function rE(e,t,n){return Math.min(Math.max(e,t),n)}var vf=["x","y","w","h","left","right","top","bottom","cx","cy"];function Gr(e){return vf.includes(e)}var wf=["parent","prev","next","self","root"];function kf(e){return wf.includes(e)}var pt=class extends Error{position;constructor(t,n){super(t),this.position=n,this.name="ExprSyntaxError"}},e0=/[A-Za-z_]/,Sf=/[A-Za-z0-9_]/;function _f(e){let t=[],n=0,r=()=>{if(!e0.test(e[n]??""))throw new pt(`Expected a name at position ${n}`,n);let i=n;for(;n<e.length&&Sf.test(e[n]??"");)n++;return e.slice(i,n)},o=()=>{if(!Sf.test(e[n]??""))throw new pt(`Expected a name at position ${n}`,n);let i=n;for(;n<e.length&&Sf.test(e[n]??"");)n++;return e.slice(i,n)},s=()=>{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 a=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(a,n),c=Number(d);if(!Number.isFinite(c))throw new pt(`Bad number "${d}"`,a);e[n]==="%"?(n++,t.push({type:"percent",value:c})):t.push({type:"number",value:c});continue}if(i==="$"){n++,t.push({type:"token",name:r()});continue}if(i==="@"){n++,t.push({type:"ref",path:s()});continue}if(e0.test(i)){t.push({type:"word",path:s()});continue}if("+-*/()".includes(i)){n++,t.push({type:"op",value:i});continue}throw new pt(`Unexpected character "${i}" at position ${n}`,n)}return t.push({type:"eof"}),t}var lE={"+":1,"-":1,"*":2,"/":2};function tt(e){try{let t=_f(e),n=new Ef(t),r=n.parseBinary(0);return n.expectEof(),{ok:!0,ast:r}}catch(t){if(t instanceof pt)return{ok:!1,message:t.message};throw t}}var Ef=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 pt("Unexpected trailing input",this.index)}parseBinary(t){let n=this.parseUnary();for(;;){let r=this.peek();if(r.type!=="op"||!fE(r.value))break;let o=lE[r.value];if(o<t)break;this.next();let s=this.parseBinary(o+1);n={kind:"binary",op:r.value,left:n,right:s}}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 pt(`@${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||!kf(n))throw new pt(`Unknown name "${t.path.join(".")}". Use $token for a token or @id.edge for a node.`,this.index);if(r===void 0||!Gr(r)||o.length>0)throw new pt(`${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 pt("Missing closing parenthesis",this.index);return n}throw new pt(`Unexpected "${t.value}"`,this.index)}case"eof":throw new pt("Unexpected end of expression",this.index)}}};function fE(e){return e==="+"||e==="-"||e==="*"||e==="/"}var t0={"+":1,"-":1,"*":2,"/":2},n0=3,pE=4;function hE(e){return e.kind==="binary"?t0[e.op]??1:e.kind==="unary"?n0:pE}function qr(e){return fd(e,0)}function fd(e,t){let n=mE(e);return hE(e)<t?`(${n})`:n}function mE(e){switch(e.kind){case"number":return K(e.value);case"percent":return`${K(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}${fd(e.operand,n0)}`;case"binary":{let t=t0[e.op]??1;return`${fd(e.left,t)} ${e.op} ${fd(e.right,t+1)}`}}}function Mf(e){return e.slice(0,-1).join(".")}function gn(e,t){switch(e.kind){case"nodeRef":{let n=e.path[e.path.length-1],r=t(Mf(e.path));return n===void 0||r===void 0?e:{kind:"nodeRef",path:[...r.split("."),n]}}case"unary":return{...e,operand:gn(e.operand,t)};case"binary":return{...e,left:gn(e.left,t),right:gn(e.right,t)};default:return e}}function on(e){let t=new Set,n=new Set,r=o=>{switch(o.kind){case"nodeRef":t.add(Mf(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 nt(e,t){return`${e} ${t}`}function Cf(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 pd(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 Af(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 $f(e,t,n){let r=p=>{let m=[];for(let g=n.parentOf.get(p);g!==void 0;g=n.parentOf.get(g))m.push(g);return m},o=r(e),s=r(t),i=new Set(s),a=o.find(p=>i.has(p)),d=p=>a===void 0?p:p.slice(0,p.indexOf(a)),c=new Map([[e,1]]),l=(p,m)=>{let g=(c.get(p)??0)+m;g===0?c.delete(p):c.set(p,g)};for(let p of d(o))l(p,1);for(let p of d(s))l(p,-1);return c}function Of(e){switch(e){case"right":case"bottom":return 1;case"cx":case"cy":return .5;default:return 0}}function hd(e){if(e==="x"||e==="w"||e==="x1"||e==="x2")return"w";if(e==="y"||e==="h"||e==="y1"||e==="y2")return"h"}function Wr(e){let t=new Map,n=new Map,r=new Map,o=new Map,s=new Map,i=[];de(e.root,(p,m)=>{if(t.has(p.id)||t.set(p.id,p),i.push(p),m){n.set(p.id,m.id);let g=s.get(m.id)??[],b=m.type==="instance"?[m.id,...g]:g;b.length>0&&s.set(p.id,b)}me(p)&&p.children.forEach((g,b)=>{let w=p.children[b-1],k=p.children[b+1];w&&r.set(g.id,w.id),k&&o.set(g.id,k.id)})});let a=new Map;for(let p of i){let m=n.get(p.id);for(;m!==void 0;){let g=t.get(m);if(!g||!Ne(g))break;m=n.get(m)}m!==void 0&&a.set(p.id,m)}let d=new Map,c=new Map,l=p=>{if(me(p)){if(!Ne(p)){let m=r0(p);m.forEach((g,b)=>{let w=m[b-1],k=m[b+1];w&&d.set(g.id,w.id),k&&c.set(g.id,k.id)})}for(let m of p.children)l(m)}};return l(e.root),{rootId:e.root.id,byId:t,parentOf:n,prevOf:r,nextOf:o,layoutParentOf:a,layoutPrevOf:d,layoutNextOf:c,scopeOf:s,order:i}}function r0(e){let t=[];for(let n of e.children)me(n)&&Ne(n)?t.push(...r0(n)):t.push(n);return t}function ts(e,t,n){if(e.kind==="relRef"){let s=xE(e.word,t,n);return s===void 0?{ok:!1,message:`${t} has no ${e.word}`}:{ok:!0,nodeId:s,edge:e.edge}}let r=e.path[e.path.length-1]??"",o=e.path.slice(0,-1).join(".");if(!Gr(r))return{ok:!1,message:`"${r}" is not an edge of @${o}`};for(let s of n.scopeOf.get(t)??[]){let i=`${s}.${o}`;if(n.byId.has(i))return{ok:!0,nodeId:i,edge:r};let a=n.byId.get(s);if(a?.type==="instance"&&a.component===o)return{ok:!0,nodeId:s,edge:r}}return n.byId.has(o)?{ok:!0,nodeId:o,edge:r}:{ok:!1,message:`No node @${o}`}}function xE(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)}}var i0=[["start","x1","y1"],["end","x2","y2"]];function In(e){return gE(Wr(e))}function gE(e){let t=new Map;for(let n of e.order){if(n.type!=="connector")continue;let r={},o={},s={};for(let[i,a,d]of i0){let c=Tf(n[a],n.id,e),l=Tf(n[d],n.id,e),p=new Set([...c,...l]),[m]=p;if(p.size===1&&c.length>0&&l.length>0&&m!==void 0){r[i]=m;let g=o0(n[a]),b=o0(n[d]),w=yE(g,b);w!==void 0&&(o[i]=w);let k=w==="x"?g:w==="y"?b:void 0;(k==="left"||k==="right"||k==="top"||k==="bottom")&&(s[i]=k)}}(r.start!==void 0||r.end!==void 0)&&t.set(n.id,{...r,sides:o,named:s})}return t}function a0(e){let t=[];for(let n of e.order){if(n.type!=="connector")continue;let r=s0(n.id,e),o=new Set;for(let[,s,i]of i0)for(let a of[s,i])for(let d of Tf(n[a],n.id,e)){if(d===n.id||o.has(d))continue;let c=e.byId.get(d)?.type;if(c==="group"||c==="canvas"){o.add(d),t.push({severity:"warning",code:"connector-no-box",message:`${n.id} follows @${d}, a ${c} with no box of its own, which reads as 0 \u2014 attach to a shape inside it`,nodeId:n.id,prop:a});continue}s0(d,e)!==r&&(o.add(d),t.push({severity:"warning",code:"connector-other-page",message:`${n.id} follows @${d}, which is on another page, so the line leaves its own \u2014 attach to a node on the same page`,nodeId:n.id,prop:a}))}}return t}function o0(e){if(!ve(e))return;let t=tt(e.expr);if(!t.ok)return;let n=r=>{switch(r.kind){case"nodeRef":{let o=r.path[r.path.length-1];return o!==void 0&&Gr(o)?o:void 0}case"relRef":return r.edge;case"unary":return n(r.operand);case"binary":return n(r.left)??n(r.right);case"number":case"token":case"percent":return}};return n(t.ast)}function yE(e,t){let n=e==="left"||e==="right",r=t==="top"||t==="bottom";if(n&&!r)return"x";if(r&&!n)return"y"}function Tf(e,t,n){if(!ve(e))return[];let r=tt(e.expr);if(!r.ok)return[];let o=[],s=i=>{switch(i.kind){case"nodeRef":case"relRef":{if(i.kind==="relRef"&&(i.word==="self"||i.word==="parent"))return;let a=ts(i,t,n);a.ok&&!o.includes(a.nodeId)&&o.push(a.nodeId);return}case"unary":s(i.operand);return;case"binary":s(i.left),s(i.right);return;case"number":case"token":case"percent":return}};return s(r.ast),o}function s0(e,t){let n=e;for(;n!==void 0;){let r=t.parentOf.get(n);if(r===t.rootId)return t.byId.get(n)?.type==="frame"?n:void 0;n=r}}function Pe(e){let t=[...Gs(e.root),...Jl(e.root)],n=Wr(e),r=d0(n),o=new Set;u0(r,t),c0(r,e,n,o,t),t.push(...a0(n));let s=wE(r);kE(r,s,t);let i=SE(r,s,e,n,o,t);return{nodes:EE(e.root,i,r,t),problems:t}}function Xr(e){let t=Wr(e),n=d0(t),r=[];u0(n,r),c0(n,e,t,new Set,r);let o=new Map;for(let s of n.values())for(let i of s.deps){let a=o.get(i),d={nodeId:s.nodeId,prop:s.prop};a?a.push(d):o.set(i,[d])}return o}function d0(e){let t=new Map;for(let n of e.order){n.type==="connector"&&bE(n.id,t);let r=n;for(let o of Vt(n)){let s=r[o]??vE(n,o,e);s!==void 0&&t.set(nt(n.id,o),{nodeId:n.id,prop:o,value:s,deps:[]})}}return t}function bE(e,t){let n={x:["x1","x2",Math.min],y:["y1","y2",Math.min],w:["x1","x2",(r,o)=>Math.abs(o-r)],h:["y1","y2",(r,o)=>Math.abs(o-r)]};for(let[r,[o,s,i]]of Object.entries(n))t.set(nt(e,r),{nodeId:e,prop:r,value:0,deps:[nt(e,o),nt(e,s)],derive:a=>i(a(o),a(s))})}function vE(e,t,n){if(!(e.type!=="instance"||t!=="w"&&t!=="h")&&n.byId.get(e.component)?.type==="frame")return _t(`@${e.component}.${t}`)}function u0(e,t){for(let n of e.values()){if(!ve(n.value))continue;let r=tt(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 c0(e,t,n,r,o){for(let s of e.values()){if(!s.ast||s.derive)continue;let i=new Set,a=d=>{switch(d.kind){case"number":return;case"token":{let c=Ze(t)[d.name];typeof c!="number"&&o.push({severity:"error",code:c===void 0?"unknown-token":"token-not-a-number",message:c===void 0?`Unknown token $${d.name}`:`Token $${d.name} is not a number`,nodeId:s.nodeId,prop:s.prop});return}case"percent":{let c=hd(s.prop);if(!c)return;let l=n.layoutParentOf.get(s.nodeId),p=l===void 0?void 0:nt(l,c);if(p===void 0||!e.has(p)){o.push({severity:"error",code:"percent-without-parent",message:`${s.nodeId}.${s.prop} uses a percentage but has no parent to measure against`,nodeId:s.nodeId,prop:s.prop});return}i.add(p);return}case"nodeRef":case"relRef":{let c=ts(d,s.nodeId,n);if(!c.ok){r.add(d),o.push({severity:"error",code:"unknown-reference",message:c.message,nodeId:s.nodeId,prop:s.prop});return}let l=m=>{e.has(m)&&i.add(m)},p=Af(c.edge);if(!p){for(let m of Cf(c.edge))l(nt(c.nodeId,m));return}for(let m of $f(c.nodeId,s.nodeId,n).keys())l(nt(m,p));Of(c.edge)!==0&&l(nt(c.nodeId,p==="x"?"w":"h"));return}case"unary":a(d.operand);return;case"binary":a(d.left),a(d.right);return}};a(s.ast),s.deps=[...i]}}function wE(e){let t=new Map,n=new Map;for(let[s,i]of e){t.set(s,i.deps.length);for(let a of i.deps){let d=n.get(a);d?d.push(s):n.set(a,[s])}}let r=[];for(let[s,i]of t)i===0&&r.push(s);let o=[];for(let s=0;s<r.length;s++){let i=r[s];o.push(i);for(let a of n.get(i)??[]){let d=(t.get(a)??0)-1;t.set(a,d),d===0&&r.push(a)}}return o}function kE(e,t,n){if(t.length===e.size)return;let r=new Set(t);for(let[o,s]of e)r.has(o)||n.push({severity:"error",code:"cycle",message:`${s.nodeId}.${s.prop} is part of a dependency cycle`,nodeId:s.nodeId,prop:s.prop})}function SE(e,t,n,r,o,s){let i=new Map,a=(d,c)=>i.get(nt(d,c))??0;for(let d of t){let c=e.get(d);if(c){if(c.derive){i.set(d,c.derive(l=>a(c.nodeId,l)));continue}if(!ve(c.value)){i.set(d,c.value);continue}if(!c.ast){i.set(d,0);continue}i.set(d,l0(c.ast,c,n,r,o,s,a))}}return i}function l0(e,t,n,r,o,s,i){let a=d=>l0(d,t,n,r,o,s,i);switch(e.kind){case"number":return e.value;case"token":{let d=Ze(n)[e.name];return typeof d=="number"?d:0}case"percent":{let d=hd(t.prop);if(!d)return e.value/100;let c=r.layoutParentOf.get(t.nodeId);return c===void 0?0:e.value/100*i(c,d)}case"nodeRef":case"relRef":{if(o.has(e))return 0;let d=ts(e,t.nodeId,r);if(!d.ok)return 0;let c=Af(d.edge);if(!c)return pd(d.edge,i(d.nodeId,"x"),i(d.nodeId,"y"),i(d.nodeId,"w"),i(d.nodeId,"h"));let l=Of(d.edge)*i(d.nodeId,c==="x"?"w":"h");for(let[p,m]of $f(d.nodeId,t.nodeId,r))l+=m*i(p,c);return l}case"unary":{let d=a(e.operand);return e.op==="-"?-d:d}case"binary":{let d=a(e.left),c=a(e.right);if(e.op==="/"&&c===0)return s.push({severity:"error",code:"divide-by-zero",message:`${t.nodeId}.${t.prop} divides by zero`,nodeId:t.nodeId,prop:t.prop}),0;let l=_E(e.op,d,c);return Number.isFinite(l)?l:(s.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 _E(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n}}function EE(e,t,n,r){let o=new Map,s=(a,d)=>t.get(nt(a,d))??0,i=(a,d,c)=>{let l=s(a.id,"x"),p=s(a.id,"y"),m=s(a.id,"w"),g=s(a.id,"h"),b={};for(let _ of Vt(a)){let M=nt(a.id,_);n.has(M)&&(b[_]=t.get(M)??0)}(m<0||g<0)&&r.push({severity:"warning",code:"negative-size",message:`${a.id} resolved to a negative size`,nodeId:a.id});let w=d+l,k=c+p;if(o.set(a.id,{id:a.id,type:a.type,x:l,y:p,w:m,h:g,left:l,top:p,right:l+m,bottom:p+g,cx:l+m/2,cy:p+g/2,absX:w,absY:k,values:b}),me(a))for(let _ of a.children)i(_,w,k)};return i(e,0,0),o}function md(e){if(!ve(e))return{kind:"literal",value:e};let t=tt(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 f0="round";function Pt(e){if(e.kind==="frame")return;let t=e.stroke,n=e.strokeWidth??0;if(t===void 0||!(n>0))return;let r=e.dash??[];return e.kind==="text"?{paint:t,width:n,dash:r,align:"center",cap:"butt",join:f0}:{paint:t,width:n,dash:r,align:e.kind==="connector"?"center":e.strokeAlign??"center",cap:e.cap??"butt",join:e.kind==="vector"?e.join:"miter"}}function Lf(e){if(e.mask!==void 0)return{contours:e.mask.contours,rule:e.mask.rule};let t=n=>Be(n,r=>({x:e.x+r.x,y:e.y+r.y}));switch(e.kind){case"text":case"connector":return;case"vector":return{contours:e.contours,rule:e.rule};case"ellipse":return e.w>0&&e.h>0?{contours:t(Vr(e.w,e.h)),rule:"nonzero"}:void 0;case"rect":case"image":case"border":case"frame":return e.w>0&&e.h>0?{contours:t(Dn(e.w,e.h,e.radii)),rule:"nonzero"}:void 0}}function gd(e,t){if(t.align==="center"||e.mask!==void 0||e.kind!=="rect"&&e.kind!=="ellipse"&&e.kind!=="image"&&e.kind!=="border")return;let n=(t.align==="inside"?-t.width:t.width)/2,r=e.w+n*2,o=e.h+n*2;if(!(r>0&&o>0))return;let s=e.kind==="ellipse"?{tl:0,tr:0,br:0,bl:0}:{tl:xd(e.radii.tl,n),tr:xd(e.radii.tr,n),br:xd(e.radii.br,n),bl:xd(e.radii.bl,n)};return{x:e.x-n,y:e.y-n,w:r,h:o,radii:s}}function xd(e,t){return e<=0?0:Math.max(0,e+t)}function Pf(e,t){return t.align!=="center"&&t.dash.length>0&&gd(e,t)===void 0}function Df(e){let t=[];for(let n of e)for(let r=0;r<zt(n);r+=1){let o=dr(jt(n,r),1);for(let s=1;s<o.length;s+=1)if(t.push([o[s-1],o[s]]),t.length>ME)return!1}for(let n=0;n<t.length;n+=1)for(let r=n+1;r<t.length;r+=1)if(CE(t[n],t[r]))return!0;return!1}var ME=600;function CE(e,t){let n=(d,c,l)=>(c.x-d.x)*(l.y-d.y)-(c.y-d.y)*(l.x-d.x),r=n(t[0],t[1],e[0]),o=n(t[0],t[1],e[1]),s=n(e[0],e[1],t[0]),i=n(e[0],e[1],t[1]),a=1e-9;return(r>a&&o<-a||r<-a&&o>a)&&(s>a&&i<-a||s<-a&&i>a)}function Nf(e){return e.width*2*4+1}function _i(e,t,n){let r=t+1,o=e.reduce((d,c)=>d+c,0);if(e.length===0||!(o>0)||t*n/o>AE)return{array:[r,r],offset:r*(1-n)};let s=t*n,i=[],a=0;for(let d=0;a<s;d+=1){let c=e[d%e.length],l=Math.min(c,s-a);i.push(l),a+=l}return i.length%2===1?i.push(r):i.length>0?i[i.length-1]=i[i.length-1]+r:i.push(0,r),{array:i,offset:0}}var AE=2e3;var h0="system-ui, -apple-system, Segoe UI, Roboto, sans-serif",yd=16,bd=400,m0=1.2,vd="#0F172A";function Fn(){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 Rf(e,t){if(e===void 0)return h0;let n=t[e];return n?n.fallback?`${p0(n.family)}, ${n.fallback}`:p0(n.family):e}function p0(e){return/^[A-Za-z][A-Za-z0-9 -]*$/.test(e)?e:JSON.stringify(e)}function If(e,t,n,r){let o={family:Rf(t.font,n),size:t.size,weight:t.weight,italic:t.italic,underline:!1,strike:!1,fill:r(t.fill),letterSpacing:t.letterSpacing},s=typeof e=="string"?[e]:e,i=[];for(let a of s){if(typeof a=="string"){a.length>0&&i.push({text:a,style:o});continue}let d=a;d.text.length!==0&&i.push({text:d.text,style:{family:d.font===void 0?o.family:Rf(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&&Qt(d.link)?{link:d.link}:{}}})}return i}function $E(e,t){let n=[];for(let r of e)for(let o of r.text.split(/(\n)/))if(o!==""){if(o===`
44
+ `){let s=n[n.length-1];s&&!s.hardBreak?n[n.length-1]={...s,hardBreak:!0}:n.push({text:"",style:r.style,w:0,hardBreak:!0,glued:!1});continue}for(let s of o.match(/\S+\s*|\s+/g)??[]){let i=n[n.length-1];n.push({text:s,style:r.style,w:t.advance(s,r.style),hardBreak:!1,glued:i!==void 0&&!i.hardBreak&&/\S$/.test(i.text)&&/^\S/.test(s)})}}return n}function OE(e,t,n){let r=[...e.text],o=[],s="";for(let i of r){let a=s+i;if(s!==""&&n.advance(a,e.style)>t){o.push({text:s,style:e.style,w:n.advance(s,e.style),hardBreak:!1,glued:o.length===0&&e.glued}),s=i;continue}s=a}return s!==""&&o.push({text:s,style:e.style,w:n.advance(s,e.style),hardBreak:e.hardBreak,glued:o.length===0&&e.glued}),o.length>0?o:[e]}function x0(e,t){let{width:n,measure:r}=t,o=$E(r.itemize?e.flatMap(c=>r.itemize?.(c)??[c]):e,r);if(o.length===0){let c=e[0]?.style,l=c?t.lineHeight*c.size:0;return{lines:c?[LE(c,t.lineHeight)]:[],width:0,height:l}}let s=[],i=[],a=0,d=()=>{s.push(i),i=[],a=0};for(let c=0;c<o.length;){let l=c+1;for(;o[l]?.glued;)l+=1;let p=o.slice(c,l);c=l,p.length>1&&i.length>0&&a+TE(p,r)>n&&d();for(let m of p){let g=i.length===0&&m.w>n&&n>0?OE(m,n,r):[m];for(let b of g){let w=b.text.trimEnd(),k=w===b.text?b.w:r.advance(w,b.style);i.length>0&&a+k>n&&d(),i.push(b),a+=b.w,b.hardBreak&&d()}}}return i.length>0&&s.push(i),PE(s,t)}function TE(e,t){let n=e[e.length-1],r=n.text.trimEnd(),o=r===n.text?n.w:t.advance(r,n.style);return e.slice(0,-1).reduce((s,i)=>s+i.w,0)+o}function LE(e,t){let n=t*e.size;return{y:0,h:n,baseline:n*.8,w:0,spans:[],style:e}}function PE(e,t){let n=[],r=0,o=0;return e.forEach((s,i)=>{let a=s.map(O=>O.style.size),d=Math.max(...a,0),c=t.lineHeight*d,l=s.map(O=>t.measure.metrics(O.style)),p=Math.max(...l.map(O=>O.ascent),0),m=Math.max(...l.map(O=>O.descent),0),g=r+(c-(p+m))/2+p,b=DE(s,t.measure),w=b.reduce((O,j)=>O+j.w,0);o=Math.max(o,w);let k=i===e.length-1||(s[s.length-1]?.hardBreak??!1),_=b.filter((O,j)=>j>0&&!O.glued).length,M=t.align==="justify"&&!k&&_>0,R=Math.max(0,t.width-w),B=t.align==="center"?R/2:t.align==="right"?R:0,D=M?R/_:0,V=[],T=B;b.forEach((O,j)=>{V.push({text:O.text,style:O.style,x:T,w:O.w});let $=b[j+1];T+=O.w+($&&!$.glued?D:0)}),n.push({y:r,h:c,baseline:g,w,spans:NE(V,M)}),r+=c}),{lines:n,width:o,height:r}}function DE(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 NE(e,t){if(t)return[...e];let n=[];for(let r of e){let o=n[n.length-1];if(o&&g0(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 g0(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 Ff(e,t,n,r,o,s){let i={size:t.size??yd,weight:t.weight??bd,lineHeight:t.lineHeight??m0,letterSpacing:t.letterSpacing??0,italic:e.italic??!1,font:typeof e.font=="string"?e.font:void 0,fill:typeof e.fill=="string"?e.fill:vd},a=If(e.content,i,r,o),d=If(" ",i,r,o).map(c=>({...c,text:""}));return x0(a.length>0?a:d,{width:n,align:e.align??"left",lineHeight:i.lineHeight,measure:s})}function Bf(e,t,n){let r=t-n;return e.valign==="middle"?r/2:e.valign==="bottom"?r:0}function Hf(e){let t=lr({x:e.x,y:e.y,w:e.w,h:e.h},e.rotation),n=Kt(e.mask.contours);if(!n)return t;let r=Vf(t,n),o={...r,w:Math.max(0,r.w),h:Math.max(0,r.h)},s=Zr(e);if(!(s>0))return o;let i=Math.min(o.w>0?o.x:1/0,n.x-s),a=Math.min(o.h>0?o.y:1/0,n.y-s),d=Math.max(o.x+o.w,n.x+n.w+s),c=Math.max(o.y+o.h,n.y+n.h+s);return{x:i,y:a,w:d-i,h:c-a}}var Mi=250;function ns(e){return e!==void 0&&e>0?Math.ceil(e*1.5):0}function Uf(e,t){let n=e.indexOf(t);if(n<=0||t.backdrop===void 0)return[];let r=t.backdrop.page,o=0;if(r!==void 0)for(let s=n-1;s>=0;s-=1){let i=e[s];if(i.id===r&&i.kind==="frame"){o=s;break}}return e.slice(o,n).map(s=>{if(s.backdrop===void 0)return s;let{backdrop:i,...a}=s;return a})}function zf(e){return e.lines.filter(t=>t.spans.length>0)}function rs(e){switch(e.kind){case"text":{let t=zf(e),n=Math.max(e.w,...t.map(s=>s.w)),r=Math.max(e.y+e.h,...t.map(s=>s.y+s.h)),o=Zr(e);return{x:e.x-o,y:e.y-o,w:n+o*2,h:r-e.y+o*2}}case"connector":{let t=Ga(e.strokeWidth)/2+e.strokeWidth;return{x:e.x-t,y:e.y-t,w:e.w+t*2,h:e.h+t*2}}case"vector":{let t=Kt(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":case"image":case"border":{let t=Zr(e);return{x:e.x-t,y:e.y-t,w:e.w+t*2,h:e.h+t*2}}case"frame":return{x:e.x,y:e.y,w:e.w,h:e.h}}}function Zr(e){if(e.kind==="frame"||e.stroke===void 0)return 0;let t=e.strokeWidth??0;if(!(t>0))return 0;let n=e.kind==="text"||e.kind==="connector"?void 0:e.strokeAlign;return n==="inside"?0:n==="outside"?t:t/2}function Sd(e,t,n){let r=e.x,o=e.y,s=e.x+e.w,i=e.y+e.h;for(let d of t){if(d.inset)continue;let c=d.spread+d.blur;r=Math.min(r,e.x+d.x-c),o=Math.min(o,e.y+d.y-c),s=Math.max(s,e.x+e.w+d.x+c),i=Math.max(i,e.y+e.h+d.y+c)}let a=ns(n);return{x:r-a,y:o-a,w:s-r+a*2,h:i-o+a*2}}var w0="vd-paint-";var Ci="#CBD5E1",k0="#FFFFFF";function Ai(e,t,n={}){let r=[...t.problems],o=[],s=[],i=n.measure??Fn(),a=E0(Ze(e),r,e,n.resolveAsset),d=a.paint,c=new Map,l=lt(e.root),p=Ye(e.root),m=T=>{if(!st(T))return{};let O=p.links.get(T.id);if(O===void 0)return{};let j=VE(e,t,O);return j?{mask:j}:(r.push({severity:"warning",code:"mask-empty",message:`${T.id}: its mask ${O} has no area, so it is drawn unmasked \u2014 give the shape a size`,nodeId:T.id,prop:"mask"}),{})},g,b=new Map,w=new Map,k=new Map,_=new Map;de(e.root,(T,O)=>{if(O&&w.set(T.id,O.id),"hidden"in T&&T.hidden===!0)return!1;let j=O?c.get(O.id):void 0,$=t.nodes.get(T.id);if(!$||p.shapes.has(T.id)){c.set(T.id,j);return}let P=T.type==="frame"?T:T.type==="instance"?l.get(T.component):void 0;if(T.type==="instance"&&!P){c.set(T.id,j);return}let C=P&&T.type==="instance"?t.nodes.get(P.id):$,G=b0(C?.values.blur,T.id,"blur",r);G>0&&k.set(T.id,G);let ee=b0(C?.values.backdrop,T.id,"backdrop",r);if(ee>0&&_.set(T.id,ee),P){T.type==="frame"&&T.skip===!0&&O!==e.root&&r.push({severity:"warning",code:"skip-not-a-page",message:`${T.id}: skip only applies to a page, a frame at the top level`,nodeId:T.id,prop:"skip"});let oe={x:$.absX,y:$.absY,w:Math.max(0,$.w),h:Math.max(0,$.h)},Se=T.type==="frame"?$:t.nodes.get(P.id),be=$o(Se?.values??{},oe.w,oe.h);c.set(T.id,P.clip===!0?T.id:j),P.clip===!0&&s.push({id:T.id,...oe,...Jt(be)?{}:{radii:be},parent:j}),o.push({kind:"frame",id:T.id,...oe,background:d(P.background,T.id,"background",oe,oe),radii:be,clip:j,blend:P.blend??"normal",shadows:mr(P.shadow,T.id,Ze(e),r),rotation:0});let v=d(P.stroke,T.id,"stroke",oe),N=Se?.values.strokeWidth??0;v!==void 0&&N>0&&b.set(T.id,{kind:"border",id:T.id,...oe,radii:be,stroke:v,strokeWidth:N,...Jr(P,T.id,r,!0),...P.cap===void 0?{}:{cap:P.cap},clip:j,blend:"normal",shadows:[],rotation:0});return}if(c.set(T.id,j),T.type==="text"){o.push(S0(T,$,e,i,r,j,d));return}if(T.type==="video"){let oe=wd($),Se=JE(T,e,n,r);o.push({kind:"image",id:T.id,...oe,href:Se.href,fit:T.fit??"fill",radii:$o($.values,oe.w,oe.h),opacity:Yr($.values.opacity??1),...y0(T,$.values,oe,d,r),clip:j,blend:T.blend??"normal",shadows:mr(T.shadow,T.id,Ze(e),r),rotation:$.values.rotation??0,...Se.video===void 0?{}:{video:Se.video},...Se.href===void 0&&Se.video?.clip===void 0?{}:m(T)});return}if(T.type==="image"){let oe=wd($),Se=ZE(T,e,n.resolveAsset,r);o.push({kind:"image",id:T.id,...oe,href:Se,fit:T.fit??"fill",radii:$o($.values,oe.w,oe.h),opacity:Yr($.values.opacity??1),...y0(T,$.values,oe,d,r),clip:j,blend:T.blend??"normal",shadows:mr(T.shadow,T.id,Ze(e),r),rotation:$.values.rotation??0,...Se===void 0?{}:m(T)});return}if(T.type==="ellipse"){let oe=wd($);o.push({kind:"ellipse",id:T.id,...oe,fill:d(T.fill,T.id,"fill",oe,oe)??Ci,stroke:d(T.stroke,T.id,"stroke",oe),strokeWidth:$.values.strokeWidth??0,...Jr(T,T.id,r,!0),...T.cap===void 0?{}:{cap:T.cap},opacity:Yr($.values.opacity??1),clip:j,blend:T.blend??"normal",shadows:mr(T.shadow,T.id,Ze(e),r),rotation:$.values.rotation??0});return}if(T.type==="connector"){g??=In(e),o.push(qE(T,$,g.get(T.id)?.sides??{},r,j,d,mr(T.shadow,T.id,Ze(e),r)));return}if(T.type==="vector"){o.push(GE(T,$,r,j,d,mr(T.shadow,T.id,Ze(e),r)));return}if(T.type!=="rect")return;let fe=wd($);o.push({kind:"rect",id:T.id,...fe,fill:d(T.fill,T.id,"fill",fe,fe)??Ci,stroke:d(T.stroke,T.id,"stroke",fe),strokeWidth:$.values.strokeWidth??0,...Jr(T,T.id,r,!0),...T.cap===void 0?{}:{cap:T.cap},radii:$o($.values,fe.w,fe.h),opacity:Yr($.values.opacity??1),clip:j,blend:T.blend??"normal",shadows:mr(T.shadow,T.id,Ze(e),r),rotation:$.values.rotation??0})}),b.size>0&&FE(o,b,w),(k.size>0||_.size>0)&&BE(o,{blurs:k,backdrops:_,parents:w,root:e.root.id}),IE(o,T=>w.get(T)===e.root.id,r);let M=t.nodes.get(e.root.id),R=e.root.w!==void 0&&e.root.h!==void 0,B=R?{x:0,y:0,width:Math.max(0,M?.w??0),height:Math.max(0,M?.h??0)}:HE(o,s),D={x:B.x,y:B.y,w:B.width,h:B.height},V=d(e.root.background,e.root.id,"background",D,D);return{...B,background:R?V??k0:V,items:o,clips:s,gradients:a.gradients,problems:r}}function Jr(e,t,n,r){let o=Al(e.dash);e.dash!==void 0&&o.length===0&&n.push({severity:"error",code:"invalid-dash",message:`${t}: dash ${JSON.stringify(e.dash)} is not a dash array like "6 4", so the stroke is solid`,nodeId:t,prop:"dash"});let s=e.strokeAlign,i;return(s==="inside"||s==="outside")&&(r?i=s:e.stroke!==void 0&&n.push({severity:"warning",code:"stroke-align-open",message:`${t}: an ${s} stroke needs a closed path, so it is drawn centred \u2014 close every contour with Z, or set strokeAlign=center`,nodeId:t,prop:"strokeAlign"})),{...o.length===0?{}:{dash:o},...i===void 0?{}:{strokeAlign:i}}}function y0(e,t,n,r,o){let s=r(e.stroke,e.id,"stroke",n),i=t.strokeWidth??0;return s===void 0||!(i>0)?{}:{stroke:s,strokeWidth:i,...Jr(e,e.id,o,!0),...e.cap===void 0?{}:{cap:e.cap}}}function RE(e,t,n,r,o){let s=r(e.stroke,e.id,"stroke",n),i=t.strokeWidth??0;if(s===void 0||!(i>0))return{};let{dash:a}=Jr(e,e.id,o,!1);return{stroke:s,strokeWidth:i,...a===void 0?{}:{dash:a}}}function IE(e,t,n){let r=(o,s,i)=>{n.push({severity:"warning",code:s,message:`${o}: ${i}`,nodeId:o,prop:"strokeAlign"})};for(let o of e){let s=Pt(o);if(!s||(o.kind==="border"&&s.align!=="inside"&&t(o.id)&&r(o.id,"stroke-page-edge",`the page's own edge cuts off its ${s.align==="outside"?"outside":"centred"} border in every export \u2014 use strokeAlign=inside`),s.align==="center"))continue;Pf(o,s)&&r(o.id,"stroke-align-dash",`a dashed ${s.align} stroke on a path or a mask is cut along the outline, so its dashes' ends are not exact \u2014 use strokeAlign=center for exact dashes`);let i=o.mask?.contours??(o.kind==="vector"?o.contours:void 0);i&&Df(i)&&r(o.id,"stroke-align-overlap",`its outline crosses itself, so an ${s.align} stroke draws across the fill \u2014 make a clean outline with merge union first, or use strokeAlign=center`)}}function FE(e,t,n){let r=new Map;e.forEach((i,a)=>{for(let d=i.id;d!==void 0;d=n.get(d))t.has(d)&&r.set(d,a)});let o=i=>{let a=0;for(let d=n.get(i);d!==void 0;d=n.get(d))a+=1;return a},s=[...t.values()].map(i=>({border:i,after:r.get(i.id)??-1,depth:o(i.id)})).filter(i=>i.after>=0).sort((i,a)=>a.after-i.after||i.depth-a.depth);for(let{border:i,after:a}of s)e.splice(a+1,0,i)}function b0(e,t,n,r){return e===void 0||e===0?0:e>0?e>Mi?(r.push({severity:"warning",code:"invalid-blur",message:`${t}: ${n} ${String(e)} is more than ${Mi}, so it is drawn at ${Mi}`,nodeId:t,prop:n}),Mi):e:(r.push({severity:"warning",code:"invalid-blur",message:`${t}: ${n} ${String(e)} is not a blur, so it is drawn unblurred \u2014 write 0 or more`,nodeId:t,prop:n}),0)}function v0(e){return Math.sqrt(e.reduce((t,n)=>t+n*n,0))}function BE(e,t){let{blurs:n,backdrops:r,parents:o,root:s}=t,i=new Map;for(let a of e)a.kind==="frame"&&i.set(a.id,a);e.forEach((a,d)=>{let c=a.kind==="frame"||a.kind==="border",l=c?0:n.get(a.id)??0,p=[];for(let R=c?a.id:o.get(a.id);R!==void 0;R=o.get(R)){let B=i.get(R);B&&(n.get(R)??0)>0&&p.push(B)}let m=p.every(R=>R.clip===a.clip),g=v0(m?[l,...p.map(R=>n.get(R.id)??0)]:[l]),b=p[p.length-1],w=m||b===void 0?void 0:{id:b.id,blur:v0(p.map(R=>n.get(R.id)??0)),clip:b.clip,x:b.x,y:b.y,w:b.w,h:b.h},k=r.get(a.id)??0,_=k>0&&(a.kind==="rect"||a.kind==="ellipse"||a.kind==="vector"||a.kind==="frame");if(!(g>0)&&!w&&!_)return;let M;for(let R=a.id;R!==void 0;R=o.get(R))o.get(R)===s&&i.has(R)&&(M=R);e[d]={...a,...g>0?{blur:g}:{},...w?{veil:w}:{},..._?{backdrop:{blur:k,page:M}}:{}}})}function VE(e,t,n){let r=z(e.root,n),o=t.nodes.get(n);if(!r||!o)return;let s=bi(r,{x:o.absX,y:o.absY,w:o.w,h:o.h},o.values),i=s?Kt(s.contours):void 0;if(!(!s||!i||!(i.w>0)||!(i.h>0)))return{id:n,d:ze(s.contours),contours:s.contours,rule:s.rule}}function jf(e,t,n,r,o={}){let s=z(e.root,n.id),i=t.nodes.get(n.id);if(s?.type!=="text"||!i)return;let a=[],d=E0(Ze(e),a,e,o.resolveAsset);return{...S0({...s,content:r},i,e,o.measure??Fn(),a,n.clip,d.paint),...n.blur===void 0?{}:{blur:n.blur},...n.veil===void 0?{}:{veil:n.veil}}}function HE(e,t){let n=new Map;for(let a of t){let d=a.parent===void 0?void 0:n.get(a.parent);n.set(a.id,d?Vf(a,d):a)}let r=1/0,o=1/0,s=-1/0,i=-1/0;for(let a of e){let d=a.kind==="text"&&zf(a).length>0?Math.max(a.h,a.height):a.h,c=a.clip===void 0?void 0:n.get(a.clip),l=a.kind==="connector"?rs(a):{x:a.x,y:a.y,w:a.w,h:d},p=lr(Sd(l,a.shadows,a.blur),a.rotation,Re(a)),m=c?Vf(p,c):p;m.w<=0||m.h<=0||(r=Math.min(r,m.x),o=Math.min(o,m.y),s=Math.max(s,m.x+m.w),i=Math.max(i,m.y+m.h))}return Number.isFinite(r)?{x:r,y:o,width:s-r,height:i-o}:{x:0,y:0,width:0,height:0}}function Vf(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 S0(e,t,n,r,o,s,i){let a=Math.max(0,t.w),d=Math.max(0,t.h),c={x:t.absX,y:t.absY,w:a,h:d},l=Ff(e,t.values,a,n.fonts,g=>i(g,e.id,"fill",c)??vd,r);!l.lines.every(g=>g.spans.length===0)&&l.height>d+.5&&o.push({severity:"warning",code:"text-overflow",message:`${e.id} needs ${Math.ceil(l.height)}px but its height is ${Math.round(d)}px`,nodeId:e.id,prop:"h"}),UE(e,n,o);let m=t.absY+Bf(e,d,l.height);return{kind:"text",id:e.id,x:t.absX,y:t.absY,w:a,h:d,clip:s,blend:e.blend??"normal",shadows:mr(e.shadow,e.id,Ze(n),o),rotation:t.values.rotation??0,opacity:Yr(t.values.opacity??1),...RE(e,t.values,c,i,o),height:l.height,lines:l.lines.map(g=>({y:m+g.y,h:g.h,baseline:m+g.baseline,w:g.w,spans:g.spans.map(b=>({text:b.text,x:t.absX+b.x,y:m+g.baseline,w:b.w,style:b.style})),...g.style?{style:g.style}:{}}))}}function UE(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=Qt(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"&&!zE(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 zE(e,t){let n=!1;return de(e.root,r=>{if(n)return!1;r.id===t&&r.type==="frame"&&(n=!0)}),n}var Ei=new Map,jE=512;function KE(e){let t=Ei.get(e);if(t)return t;let n=ar(e);return Ei.size>=jE&&Ei.delete(Ei.keys().next().value),Ei.set(e,n),n}function GE(e,t,n,r,o,s){let i=Math.max(0,t.w),a=Math.max(0,t.h),d={x:t.absX,y:t.absY,w:i,h:a},{contours:c,error:l}=KE(e.d);l!==void 0&&n.push({severity:"error",code:"bad-path",message:`${e.id}: ${l}`,nodeId:e.id,prop:"d"}),e.view!==void 0&&Ka(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 p=Be(c,Fr(Ir(e.view,i,a),d));return{kind:"vector",id:e.id,...d,d:ze(p),contours:p,fill:o(e.fill,e.id,"fill",d,WE(d,Kt(p)))??Ci,stroke:o(e.stroke,e.id,"stroke",d),strokeWidth:t.values.strokeWidth??0,...Jr(e,e.id,n,c.length>0&&c.every(m=>m.closed)),opacity:Yr(t.values.opacity??1),rule:e.rule??"nonzero",cap:e.cap??"butt",join:e.join??"miter",clip:r,blend:e.blend??"normal",shadows:s,rotation:t.values.rotation??0}}function qE(e,t,n,r,o,s,i){let a=t.absX-t.x,d=t.absY-t.y,c={x1:a+(t.values.x1??0),y1:d+(t.values.y1??0),x2:a+(t.values.x2??0),y2:d+(t.values.y2??0)},l=fi(c),p=Math.max(0,t.values.strokeWidth??li),m=e.route??"straight",g=e.start??"none",b=e.end??"none",w=_l(c,m,g,b,p,n),k=[w.route],{dash:_}=Jr(e,e.id,r,!1);return{kind:"connector",id:e.id,...l,...c,route:m,sides:n,start:g,end:b,d:ze(k),contours:k,filled:{d:ze(w.filled),contours:w.filled},lined:{d:ze(w.lined),contours:w.lined},stroke:s(e.stroke,e.id,"stroke",l)??ci,strokeWidth:p,..._===void 0?{}:{dash:_},opacity:Yr(t.values.opacity??1),cap:e.cap??"butt",clip:o,blend:e.blend??"normal",shadows:i,rotation:0}}function _0(e,t,n,r,o){if(e===void 0)return;if(ve(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 s=t[e];if(s===void 0)return e;if(typeof s=="string")return s;o.push({severity:"error",code:"token-not-a-colour",message:`Token $${e} is a number, not a colour`,nodeId:n,prop:r})}function WE(e,t){if(!t)return e;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 wd(e){return{x:e.absX,y:e.absY,w:Math.max(0,e.w),h:Math.max(0,e.h)}}function E0(e,t,n,r){let o=[],s=[],i=new Map,a=(m,g,b)=>{let w=[...i.keys()].filter(_=>_.startsWith(`${g}\0${b}\0`)).length,k=`${w0}${g}-${b}${w===0?"":`-${w+1}`}`;return i.set(m,k),k},d=(m,g,b)=>{t.some(k=>k.code==="invalid-paint"&&k.nodeId===m&&k.message===b)||t.push({severity:"error",code:"invalid-paint",message:b,nodeId:m,prop:g})},c=(m,g,b,w)=>{let k=wi(m);if("error"in k)return d(g,b,`${g}: ${k.error}`);if(k.kind==="solid")return m;let _=`${g}\0${b}\0${m}`,M=i.get(_);if(M!==void 0)return`url(#${M})`;let R=a(_,g,b),B=Zl(k.stops).map(D=>({offset:D.at,colour:M0(D.colour,e,g,b,t)}));return o.push(YE(k,R,w,XE(B))),`url(#${R})`},l=(m,g,b,w)=>{let k=n.assets[m.asset];if(!k){t.push({severity:"warning",code:"fill-asset-missing",message:`${g}: ${b} names image ${JSON.stringify(m.asset)}, which is not one of the document's assets, so that layer is not drawn \u2014 add the picture with vd_add_asset, or take the layer out`,nodeId:g,prop:b});return}let _=r?.(k,m.asset);if(_===void 0){t.push({severity:"warning",code:"unresolved-asset",message:`The bytes for asset "${m.asset}" are not available here`,nodeId:g,prop:b});return}return{kind:"image",href:_,fit:m.fit,...w}};return{paint:(m,g,b,w,k)=>{let _=_0(m,e,g,b,t);if(_===void 0)return;if(/url\(/i.test(_))return d(g,b,`${g}: a paint is a colour or a gradient, not ${JSON.stringify(_)}`);let M=mn(_);if(M.length===1&&!vi(_))return c(_,g,b,w);if(k===void 0)return d(g,b,`${g}: ${b} takes one colour or gradient, not ${M.length>1?"a list of paints":"a picture"}; only a shape's fill and a frame's background take layers`);let R=[];for(let O of M){let j=e[O],$=typeof j=="string"?j:O;if(/url\(/i.test($)){d(g,b,`${g}: a paint is a colour or a gradient, not ${JSON.stringify($)}`);continue}for(let P of mn($)){let C=Xo(P);if("error"in C){d(g,b,`${g}: ${C.error}`);continue}let G=C.kind==="image"?l(C,g,b,w):(ee=>ee===void 0?void 0:{kind:"paint",paint:ee})(c(P,g,b,w));G&&R.push(G)}}if(R.length===0)return;let B=R[0];if(R.length===1&&B.kind==="paint")return B.paint;let D=`${g}\0${b}\0${_}\0layers`,V=i.get(D);if(V!==void 0)return`url(#${V})`;let T=a(D,g,b);return s.push({id:T,kind:"layers",...k,layers:[...R].reverse()}),`url(#${T})`},get gradients(){return[...o,...s]}}}function mr(e,t,n,r){let o=_0(e,n,t,"shadow",r);if(o===void 0)return[];let s=es(o);return"error"in s?(r.push({severity:"error",code:"invalid-shadow",message:`${t}: ${s.error}`,nodeId:t,prop:"shadow"}),[]):s.shadows.map(i=>({...i,colour:M0(i.colour,n,t,"shadow",r)}))}function XE(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 M0(e,t,n,r,o){let s=t[e];return s===void 0?e:typeof s=="string"&&!rd(s)?s:(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 YE(e,t,n,r){if(e.kind==="linear"){let c=e.angle*Math.PI/180,l=Math.sin(c),p=-Math.cos(c),m=(Math.abs(n.w*l)+Math.abs(n.h*p))/2,g=n.x+n.w/2,b=n.y+n.h/2;return{id:t,kind:"linear",x1:kd(g-l*m),y1:kd(b-p*m),x2:kd(g+l*m),y2:kd(b+p*m),stops:r}}let o=n.x+n.w*e.cx,s=n.y+n.h*e.cy,i={x:Math.max(o-n.x,n.x+n.w-o),y:Math.max(s-n.y,n.y+n.h-s)};if(e.shape==="circle"||i.x===0||i.y===0){let c=Math.hypot(i.x,i.y);return{id:t,kind:"radial",cx:o,cy:s,rx:c,ry:c,stops:r}}let a=i.x/i.y,d=Math.hypot(i.x/a,i.y);return{id:t,kind:"radial",cx:o,cy:s,rx:d*a,ry:d,stops:r}}function kd(e){return Math.round(e*1e6)/1e6}function Yr(e){return Math.min(Math.max(e,0),1)}function JE(e,t,n,r){let o=ve(e.src)?void 0:e.src,s=o===void 0?void 0:t.assets[o];if(!s||o===void 0)return r.push({severity:"warning",code:"missing-asset",message:`No clip for ${JSON.stringify(o??e.src)} yet: a video slot waiting for one`,nodeId:e.id,prop:"src"}),{href:void 0};if(!xf(s))return r.push({severity:"error",code:"not-a-video",message:`${e.id}: src=${o} is ${s.type}, not a clip \u2014 a video plays ${ld.join(" or ")}; use an image for a picture`,nodeId:e.id,prop:"src"}),{href:void 0};s.bytes>26214400&&r.push({severity:"warning",code:"large-video",message:`${e.id}: clip ${o} is ${Math.round(s.bytes/1048576)} MB, and every save and every read of this document carries it \u2014 trim it, or keep it under 25 MB`,nodeId:e.id,prop:"src"});let i={...e.start===void 0?{}:{start:e.start},...e.end===void 0?{}:{end:e.end},...e.poster===void 0?{}:{poster:e.poster},...e.loop===void 0?{}:{loop:e.loop}},a=yf(i,s.ms),d=n.resolveAsset?.(s,o),c=n.resolveFrame?.(s,o,a);return d===void 0&&c===void 0&&r.push({severity:"warning",code:"unresolved-clip",message:`The frames of clip "${o}" are not available here, so it draws as a placeholder`,nodeId:e.id,prop:"src"}),{href:c,video:{asset:o,clip:d,at:a,...e.start===void 0?{}:{start:e.start},...e.end===void 0?{}:{end:e.end},loop:e.loop===!0,muted:e.muted===!0,...s.ms===void 0?{}:{ms:s.ms}}}}function ZE(e,t,n,r){let o=ve(e.src)?void 0:e.src,s=o===void 0?void 0:t.assets[o];if(!s){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?.(s,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 QE(e,t){let n=new Map,r=(o,s)=>{n.set(o,[...n.get(o)??[],s])};for(let o of e.beats){if(o.kind==="camera")continue;let s=o.kind;if(o.split==="children"){let i=z(t.root,o.line.id);(i&&"children"in i?i.children:[]).forEach((d,c)=>{r(d.id,{beat:o,kind:s,start:o.start+c*o.stagger})})}else if(o.split!==void 0)for(let i=0;i<o.pieces;i+=1)r(o.line.id,{beat:o,kind:s,start:o.start+i*o.stagger,piece:i});else r(o.line.id,{beat:o,kind:s,start:o.start})}for(let o of n.values())o.sort((s,i)=>s.start-i.start);return n}function eM(e,t){let n=t.nodes.get(e.page);return n?Math.min(n.w,n.h):1e3}function C0(e,t,n,r,o){let s=e[0]?.kind==="enter",i,a,d;for(let c of e){if(c.start>t)break;let l=c.beat.effect,p=c.beat.duration,m=p<=0?1:Math.min(1,(t-c.start)/p),g=m>=1;if(c.kind==="emphasis"){if(s||g){i=void 0;continue}let M=1+(cf-1)*Math.sin(Math.PI*cd(c.beat.ease,m));i=_d(n,M,M,"centre",1);continue}if(g){s=c.kind==="exit",i=void 0,a=void 0,d=void 0;continue}let b=cd(c.beat.ease,m),w=c.kind==="enter"?b:1-b,k=O0(c.kind==="enter"?b:1-b);s=!1,a=void 0,d=void 0;let _=c.beat.line.from;switch(l){case"cut":i=void 0;break;case"fade":i=A0(k);break;case"rise":case"drop":{let M=l==="rise"?1:-1;i={sx:1,sy:1,tx:0,ty:c.kind==="enter"?M*r*(1-b):-M*r*b,opacity:k};break}case"pop":{let M=Si+(1-Si)*w;i=_d(n,M,M,"centre",k);break}case"grow":{let M=typeof _=="string"?_:"bottom",R=Math.max(0,w);i=M==="left"||M==="right"?_d(n,R,1,M,1):_d(n,1,R,M,1);break}case"wipe":{let M=typeof _=="string"?_:"left";a=c.kind==="enter"?T0(n,M,w):tM(n,M,b),i=void 0;break}case"count":{let M=o.text===void 0?void 0:pf(o.text);if(!M){i=A0(k);break}let R=typeof _=="number"?_:0;d=hf(M,R+(M.value-R)*b),i=void 0;break}case"draw":i={sx:1,sy:1,tx:0,ty:0,opacity:1,trace:w,fillOpacity:O0((w-.75)/.25)};break;case"pulse":case void 0:i=void 0;break}}return{hidden:s,pose:i,...a?{reveal:a}:{},...d===void 0?{}:{text:d}}}function A0(e){return{sx:1,sy:1,tx:0,ty:0,opacity:e}}function _d(e,t,n,r,o){let s=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:s*(1-t),ty:i*(1-n),opacity:o}}function T0(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 tM(e,t,n){return T0(e,{left:"right",right:"left",top:"bottom",bottom:"top"}[t],1-n)}function $0(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 O0(e){return e<0?0:e>1?1:e}function nM(e,t){let n=new Map;de(t.root,(o,s)=>{s&&n.set(o.id,s.id)});let r=new Map;for(let o of e.items){let s=o.kind==="frame"?{x:o.x,y:o.y,w:o.w,h:o.h}:rs(o);for(let i=o.id;i!==void 0;i=n.get(i)){let a=r.get(i);if(r.set(i,a?rM(a,s):s),i===t.root.id)break}}return{parents:n,boxes:r}}function rM(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 Kf(e,t,n,r){let o=oM(e,t,n,r),s=QE(t,r.doc);if(s.size===0)return o;let{parents:i,boxes:a}=nM(o,r.doc),d=ki*eM(t,r.resolution),c=r.options?.measure??Fn(),l=new Map,p=new Map;for(let[b,w]of s){let k=a.get(b)??{x:0,y:0,w:0,h:0},_=z(r.doc.root,b),M=_?.type==="text"?ir(_.content):void 0,R=w.filter(D=>D.piece===void 0),B=w.find(D=>D.piece!==void 0);if(R.length>0&&l.set(b,C0(R,n,k,d,{...M===void 0?{}:{text:M}})),B&&(B.beat.split==="word"||B.beat.split==="letter")){let D=[];for(let V=0;V<B.beat.pieces;V+=1){let T=w.filter(O=>O.piece===V);D.push(C0(T,n,k,d,{}))}D.some(V=>V.hidden||V.pose!==void 0)&&p.set(b,{split:B.beat.split,moments:D})}}let m=[...o.clips],g=[];for(let b of o.items){let w=[],k;for(let D=b.id;D!==void 0;D=i.get(D)){let V=l.get(D);V&&(w.unshift(V),V.reveal&&!k&&(k={id:D,box:V.reveal}))}if(w.some(D=>D.hidden))continue;let _;for(let D of w)D.pose&&(_=_?$0(_,D.pose):D.pose);let M=b,R=l.get(b.id)?.text;if(R!==void 0&&b.kind==="text"&&(M=jf(r.doc,r.resolution,b,R,r.options)??b),k){let D=`${k.id}~wipe${b.clip===void 0?"":`~${b.clip}`}`;m.some(V=>V.id===D)||m.push({id:D,...k.box,parent:b.clip}),M={...M,clip:D}}let B=p.get(b.id);if(B&&M.kind==="text"){L0(M,B.split,c).forEach((D,V)=>{let T=B.moments[V];if(!T||T.hidden)return;let O=T.pose&&_?$0(_,T.pose):T.pose??_;g.push({...D,part:V,...O?{pose:O}:{}})});continue}g.push(_&&!sM(_)?{...M,pose:_}:M)}return{...o,items:g,clips:m}}function oM(e,t,n,r){if(!e.items.some(d=>d.kind==="image"&&d.video!==void 0))return e;let o=z(r.doc.root,t.page);if(!o)return e;let s=new Set;de(o,d=>{d.type==="video"&&s.add(d.id)});let i=r.options?.resolveFrame,a=e.items.map(d=>{if(d.kind!=="image"||d.video===void 0||!s.has(d.id))return d;let c=d.video,l=bf(c,c.ms,n);if(l===c.at)return d;let p=r.doc.assets[c.asset],m=p===void 0?void 0:i?.(p,c.asset,l);return{...d,href:m??d.href,video:{...c,at:l}}});return{...e,items:a}}function sM(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 L0(e,t,n=Fn()){let r=[],o=new Intl.Segmenter(void 0,{granularity:"grapheme"}),s=!1;for(let i of e.lines){s=!1;for(let a of i.spans){let d=0,c=t==="word"?a.text.split(/(\s+)/).filter(l=>l!==""):[...o.segment(a.text)].map(l=>l.segment);for(let l of c){if(l.trim()==="")s=!1;else{(t==="letter"||!s)&&r.push([]);let m=a.x+n.advance(a.text.slice(0,d),a.style);r.at(-1).push({...a,text:l,x:m,w:n.advance(l,a.style)}),s=!0}d+=l.length}}}return r.map(i=>({...e,lines:e.lines.map(a=>({...a,spans:i.filter(d=>d.y===a.baseline)})).filter(a=>a.spans.length>0)}))}var gr="vd-clip-";function Gf(e){return aM(e,"")}function aM(e,t){let n=e.parent===void 0?"":` clip-path="url(#${ne(t+gr+e.parent)})"`;return`<clipPath id="${ne(t+gr+e.id)}"${n}>${qt(e,e.radii)}</clipPath>`}function qt(e,t,n=[],r=[]){let o=r.map(i=>`${i} `).join(""),s=n.length===0?"":` ${n.join(" ")}`;if(t===void 0||!Ad(t)){let i=t!==void 0&&!Jt(t)?` rx="${K(t.tl)}"`:"";return`<rect ${o}x="${K(e.x)}" y="${K(e.y)}" width="${K(e.w)}" height="${K(e.h)}"${i}${s}/>`}return`<path ${o}d="${Cd(e,t)}"${s}/>`}function Cd(e,t){return ze(Be(Dn(e.w,e.h,t),n=>({x:e.x+n.x,y:e.y+n.y})))}function Ad(e){return!Jt(e)&&!Vc(e)}function qf(e){return dM(e,"")}function dM(e,t){if(e.kind==="layers")return uM(e,t);let n=e.stops.map(o=>`<stop offset="${K(o.offset)}" stop-color="${ne(o.colour)}"${o.opacity===void 0?"":` stop-opacity="${K(o.opacity)}"`}/>`).join(""),r=ne(t+e.id);return e.kind==="linear"?`<linearGradient id="${r}" gradientUnits="userSpaceOnUse" x1="${K(e.x1)}" y1="${K(e.y1)}" x2="${K(e.x2)}" y2="${K(e.y2)}">${n}</linearGradient>`:`<radialGradient id="${r}" gradientUnits="userSpaceOnUse" cx="0" cy="0" r="1" gradientTransform="matrix(${K(e.rx)} 0 0 ${K(e.ry)} ${K(e.cx)} ${K(e.cy)})">${n}</radialGradient>`}function uM(e,t){let n=`x="${K(e.x)}" y="${K(e.y)}" width="${K(e.w)}" height="${K(e.h)}"`,r=e.layers.map(o=>{if(o.kind==="paint"){let s=sn(o.paint,{ids:!1,prefix:t});return`<rect ${n} fill="${ne(s)}"/>`}return`<image href="${ne(o.href)}" x="${K(o.x)}" y="${K(o.y)}" width="${K(o.w)}" height="${K(o.h)}" preserveAspectRatio="${P0[o.fit]}"/>`}).join("");return`<pattern id="${ne(t+e.id)}" patternUnits="userSpaceOnUse" ${n} viewBox="${K(e.x)} ${K(e.y)} ${K(e.w)} ${K(e.h)}">${r}</pattern>`}var P0={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"},cM="#94A3B8";function Bn(e,t){let n=e.clip===void 0?[]:[`clip-path="url(#${ne(t+gr+e.clip)})"`];return e.rotation!==0&&n.push(`transform="${os(e)}"`),eo(e)&&n.push(`filter="url(#${ne(t+Qr+e.id)})"`),e.blend!=="normal"&&n.push(`style="mix-blend-mode:${e.blend}"`),n}var Qr="vd-shadow-";function eo(e){return e.shadows.length>0||(e.blur??0)>0}function Wf(e,t="all"){return fM(e,t,"")}var lM=20;function fM(e,t,n){let r=e.mask===void 0?rs(e):Hf({...e,mask:e.mask}),o=t==="insets"?[]:e.shadows.filter(m=>!m.inset),s=t==="drops"?[]:e.shadows.filter(m=>m.inset),i=t==="all"?e.blur??0:0,a=Sd(r,o,i);for(let m of s){let g=Math.abs(m.x)+Math.abs(m.y)+ns(m.blur)+Math.abs(m.spread);a=pM(a,{x:r.x-g,y:r.y-g,w:r.w+g*2,h:r.h+g*2})}let d=2,c=[];o.forEach((m,g)=>{let b=`s${g}`,w="SourceAlpha";m.spread!==0&&(c.push(`<feMorphology in="${w}" operator="${m.spread>0?"dilate":"erode"}" radius="${K(Math.abs(m.spread))}" result="${b}m"/>`),w=`${b}m`),m.blur>0&&(c.push(`<feGaussianBlur in="${w}" stdDeviation="${K(m.blur/2)}" result="${b}b"/>`),w=`${b}b`),c.push(`<feOffset in="${w}" dx="${K(m.x)}" dy="${K(m.y)}" result="${b}o"/>`,`<feFlood flood-color="${ne(m.colour)}" result="${b}c"/>`,`<feComposite in="${b}c" in2="${b}o" operator="in" result="${b}"/>`)}),s.length>0&&c.push(`<feComponentTransfer in="SourceAlpha" result="solid"><feFuncA type="linear" slope="${lM}"/></feComponentTransfer>`),s.forEach((m,g)=>{let b=`i${g}`,w="solid";m.spread!==0&&(c.push(`<feMorphology in="${w}" operator="${m.spread>0?"erode":"dilate"}" radius="${K(Math.abs(m.spread))}" result="${b}m"/>`),w=`${b}m`),c.push(`<feComponentTransfer in="${w}" result="${b}n"><feFuncA type="table" tableValues="1 0"/></feComponentTransfer>`),w=`${b}n`,m.blur>0&&(c.push(`<feGaussianBlur in="${w}" stdDeviation="${K(m.blur/2)}" result="${b}b"/>`),w=`${b}b`),c.push(`<feOffset in="${w}" dx="${K(m.x)}" dy="${K(m.y)}" result="${b}o"/>`,`<feFlood flood-color="${ne(m.colour)}" result="${b}c"/>`,`<feComposite in="${b}c" in2="${b}o" operator="in" result="${b}k"/>`,`<feComposite in="${b}k" in2="solid" operator="in" result="${b}"/>`)});let l=[...o.map((m,g)=>`<feMergeNode in="s${o.length-1-g}"/>`),...t==="all"?['<feMergeNode in="SourceGraphic"/>']:[],...s.map((m,g)=>`<feMergeNode in="i${s.length-1-g}"/>`)].join(""),p=i>0?`<feMerge result="layer">${l}</feMerge><feGaussianBlur in="layer" stdDeviation="${K(i/2)}"/>`:`<feMerge>${l}</feMerge>`;return`<filter id="${ne(n+Qr+e.id)}" filterUnits="userSpaceOnUse" x="${K(a.x-d)}" y="${K(a.y-d)}" width="${K(a.w+d*2)}" height="${K(a.h+d*2)}" color-interpolation-filters="sRGB">`+c.join("")+p+"</filter>"}function pM(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}}var $i="vd-veil-";function Xf(e){let t=new Map;for(let n of e)n.veil&&t.set(n.veil.id,n.veil);return[...t.values()]}function Yf(e){return hM(e,"")}function hM(e,t){let n=ns(e.blur)+2;return`<filter id="${ne(t+$i+e.id)}" filterUnits="userSpaceOnUse" x="${K(e.x-n)}" y="${K(e.y-n)}" width="${K(e.w+n*2)}" height="${K(e.h+n*2)}" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation="${K(e.blur/2)}"/></filter>`}var D0="vd-backdrop-";function Jf(e,t){return mM(e,t,{ids:!1,prefix:""})}function mM(e,t,n){let r=t.backdrop;if(r===void 0)return"";let o={ids:!1,prefix:n.prefix},s=Uf(e.items,t).map(w=>N0(w,o)).filter(w=>w!=="");if(r.page===void 0&&e.background!==void 0&&s.unshift(`<rect x="${K(e.x)}" y="${K(e.y)}" width="${K(e.width)}" height="${K(e.height)}" fill="${ne(sn(e.background,n))}"/>`),s.length===0)return"";let i=xM(t);if(i==="")return"";let a=ne(n.prefix+D0+t.id),d=t.pose,c=lr({x:t.x,y:t.y,w:t.w,h:t.h},t.rotation,Re({x:t.x,y:t.y,w:t.w,h:t.h})),l=d?{x:d.sx*c.x+d.tx,y:d.sy*c.y+d.ty,w:d.sx*c.w,h:d.sy*c.h}:c,p=ns(r.blur)+2,m=`<filter id="${a}-blur" filterUnits="userSpaceOnUse" x="${K(l.x-p)}" y="${K(l.y-p)}" width="${K(l.w+p*2)}" height="${K(l.h+p*2)}" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation="${K(r.blur/2)}"/></filter>`,g=[];t.clip!==void 0&&g.push(`clip-path="url(#${ne(n.prefix+gr+t.clip)})"`);let b=("opacity"in t?t.opacity:1)*(d?.opacity??1);return b<1&&g.push(`opacity="${K(b)}"`),`<g${g.length===0?"":` ${g.join(" ")}`}><defs><clipPath id="${a}">${i}</clipPath>${m}</defs><g clip-path="url(#${a})" filter="url(#${a}-blur)">${s.join("")}</g></g>`}function xM(e){let t=e.rotation===0?"":os(e),r=[e.pose?Oi(e.pose):"",t].filter(s=>s!=="").join(" "),o=r===""?[]:[`transform="${r}"`];switch(e.kind){case"rect":case"frame":return qt(e,e.radii,o);case"ellipse":return Ed(e,o);case"vector":return e.d===""?"":`<path d="${ne(e.d)}"${e.rule==="evenodd"?' clip-rule="evenodd"':""}${o.length===0?"":` ${o.join(" ")}`}/>`;case"image":case"text":case"border":case"connector":return""}}function os(e){return`rotate(${K(e.rotation)} ${K(e.x+e.w/2)} ${K(e.y+e.h/2)})`}function $d(e){return e.rotation!==0&&e.clip!==void 0&&e.mask===void 0}function N0(e,t){if(e.veil!==void 0){let{veil:n,...r}=e,o=N0(r,t);if(o==="")return"";let s=[`filter="url(#${ne(t.prefix+$i+n.id)})"`];return n.clip!==void 0&&s.push(`clip-path="url(#${ne(t.prefix+gr+n.clip)})"`),`<g ${s.join(" ")}>${o}</g>`}if(e.pose!==void 0)return gM(e,e.pose,t);if(e.mask!==void 0)return R0(e,t);if($d(e)){let n=[`clip-path="url(#${ne(t.prefix+gr+e.clip)})"`];e.blend!=="normal"&&n.push(`style="mix-blend-mode:${e.blend}"`);let r=Md({...e,clip:void 0,blend:"normal"},t);return r===""?"":`<g ${n.join(" ")}>${r}</g>`}return Md(e,t)}function gM(e,t,n){let r=Md({...e,clip:void 0,blend:"normal",shadows:e.shadows},n);if(r==="")return"";let o=[];e.clip!==void 0&&o.push(`clip-path="url(#${ne(n.prefix+gr+e.clip)})"`),t.opacity<1&&o.push(`opacity="${K(t.opacity)}"`),e.blend!=="normal"&&o.push(`style="mix-blend-mode:${e.blend}"`);let s=t.sx===1&&t.sy===1&&t.tx===0&&t.ty===0?r:`<g transform="${Oi(t)}">${r}</g>`;return o.length===0?s:`<g ${o.join(" ")}>${s}</g>`}function Oi(e){return`matrix(${K(e.sx)} 0 0 ${K(e.sy)} ${K(e.tx)} ${K(e.ty)})`}var ss="vd-mask-";function R0(e,t){let n=Md(Od(e),{...t,ids:!1});if(n==="")return"";let r=[];t.ids&&r.push(`id="${ne(e.id)}"`),e.clip!==void 0&&r.push(`clip-path="url(#${ne(t.prefix+gr+e.clip)})"`),eo(e)&&r.push(`filter="url(#${ne(t.prefix+Qr+e.id)})"`),"opacity"in e&&e.opacity<1&&r.push(`opacity="${K(e.opacity)}"`),e.blend!=="normal"&&r.push(`style="mix-blend-mode:${e.blend}"`);let o=r.length===0?"<g>":`<g ${r.join(" ")}>`,s=I0(e,t.prefix);return`${o}<g clip-path="url(#${ne(t.prefix+ss+e.id)})">${n}</g>${s===""?"":`<g>${s}</g>`}</g>`}function Od(e){let t=F0(e),n={..."opacity"in t?{...t,opacity:1}:t,clip:void 0,blend:"normal",shadows:[]};if(n.kind!=="image")return n;let{stroke:r,strokeWidth:o,...s}=n;return r===void 0&&o===void 0?n:s}function Zf(e){return I0(e,"")}function I0(e,t){let n=Pt(e),r=e.mask;if(!n||r===void 0)return"";let o=ne(r.d);if(n.align==="center")return`<path d="${o}" fill="none" ${xr(e,n,t,!1).join(" ")}/>`;let s=xr(e,n,t,!0).join(" ");if(n.align==="inside")return`<path d="${o}" fill="none" ${s} clip-path="url(#${ne(t+ss+e.id)})"/>`;let i=ne(t+rp+e.id);return`<clipPath id="${i}">${z0(r.contours,n)}</clipPath><path d="${o}" fill="none" ${s} clip-path="url(#${i})"/>`}function Qf(e){return yM(e,"")}function yM(e,t){let n=e.mask;if(n===void 0)return"";let r=n.rule==="evenodd"?' clip-rule="evenodd"':"";return`<clipPath id="${ne(t+ss+e.id)}"><path d="${ne(n.d)}"${r}/></clipPath>`}function F0(e){let{mask:t,...n}=e;return t===void 0?e:n}function Md(e,t){if(e.mask!==void 0)return R0(e,t);if(as(e))return MM(e,t);switch(e.kind){case"border":return kM(e,t);case"connector":return EM(e,t);case"ellipse":return SM(e,t);case"frame":return bM(e,t);case"image":return B0(e,t);case"rect":return wM(e,t);case"text":return AM(e,t);case"vector":return _M(e,t)}}function sn(e,t){return/url\(/i.test(e)&&!e.startsWith("url(#")?"none":t.prefix!==""&&e.startsWith("url(#")?`url(#${t.prefix}${e.slice(5)}`:e}function bM(e,t){return qt(e,e.radii,[`fill="${e.background===void 0?"none":ne(sn(e.background,t))}"`,...Bn(e,t.prefix)],t.ids?[`id="${ne(e.id)}"`]:[])}function B0(e,t,n=!1){let r=t.ids?[`id="${ne(e.id)}"`]:[],o=n?[]:Bn(e,t.prefix);if(e.href===void 0&&e.video?.clip!==void 0){let d=e.opacity<1?[`opacity="${K(e.opacity)}"`]:[],c=[...r,...d,...o];return`<g${c.length===0?"":` ${c.join(" ")}`}>${Td(e,t.prefix)}</g>`}if(e.href===void 0)return qt(e,e.radii,['fill="none"',`stroke="${ne(cM)}"`,'stroke-width="1"','stroke-dasharray="4 4"',...o],r);let s=[`x="${K(e.x)}"`,`y="${K(e.y)}"`,`width="${K(e.w)}"`,`height="${K(e.h)}"`,`href="${ne(e.href)}"`,`preserveAspectRatio="${P0[e.fit]}"`],i=e.opacity<1?[`opacity="${K(e.opacity)}"`]:[];if(Jt(e.radii))return`<image ${[...r,...s,...i,...o].join(" ")}/>`;let a=ne(t.prefix+is+e.id);return`${n?"<g>":`<g ${[...r,...i,...o].join(" ")}>`}<clipPath id="${a}">${qt(e,e.radii)}</clipPath><image ${[...s,`clip-path="url(#${a})"`].join(" ")}/></g>`}function Td(e,t=""){let n=[`x="${K(e.x)}"`,`y="${K(e.y)}"`,`width="${K(e.w)}"`,`height="${K(e.h)}"`],r=ne(t+is+e.id),o=Jt(e.radii),s=`width:100%;height:100%;display:block;object-fit:${vM[e.fit]}`;return(o?"":`<clipPath id="${r}">${qt(e,e.radii)}</clipPath>`)+`<foreignObject ${[...n,...o?[]:[`clip-path="url(#${r})"`]].join(" ")}><video xmlns="http://www.w3.org/1999/xhtml" data-vd-video="${ne(e.id)}" src="${ne(e.video?.clip??"")}" muted="" playsinline="" preload="auto" style="${s}"></video></foreignObject>`}var vM={cover:"cover",contain:"contain",fill:"fill"},is="vd-round-";function wM(e,t){return qt(e,e.radii,[...ep(e,t),...V0(e,t),...Bn(e,t.prefix)],t.ids?[`id="${ne(e.id)}"`]:[])}function kM(e,t){let n=Pt(e);return n?qt(e,e.radii,['fill="none"',...xr(e,n,t.prefix,!1),...Bn(e,t.prefix)]):""}function V0(e,t){let n=Pt(e);return n?xr(e,n,t.prefix,!1).slice(2):[]}function ep(e,t){let n=[`fill="${ne(sn(e.fill,t))}"`];return e.stroke!==void 0&&e.strokeWidth>0&&n.push(`stroke="${ne(sn(e.stroke,t))}"`,`stroke-width="${K(e.strokeWidth)}"`),e.opacity<1&&n.push(`opacity="${K(e.opacity)}"`),n}function SM(e,t){let n=[];return t.ids&&n.push(`id="${ne(e.id)}"`),n.push(`cx="${K(e.x+e.w/2)}"`,`cy="${K(e.y+e.h/2)}"`,`rx="${K(e.w/2)}"`,`ry="${K(e.h/2)}"`,...ep(e,t),...V0(e,t),...Bn(e,t.prefix)),`<ellipse ${n.join(" ")}/>`}function _M(e,t){if(e.d==="")return"";let n=[];t.ids&&n.push(`id="${ne(e.id)}"`),n.push(`d="${ne(e.d)}"`,...ep(e,t)),n.push(...np(e,e.dash??[]));let r=e.pose?.fillOpacity;return r!==void 0&&r<1&&n.push(`fill-opacity="${K(r)}"`),e.rule!=="nonzero"&&n.push(`fill-rule="${e.rule}"`),e.cap!=="butt"&&n.push(`stroke-linecap="${e.cap}"`),e.join!=="miter"&&n.push(`stroke-linejoin="${e.join}"`),e.paintOrder!==void 0&&n.push(`paint-order="${e.paintOrder}"`),n.push(...Bn(e,t.prefix)),`<path ${n.join(" ")}/>`}function EM(e,t){let n=H0(e,t.prefix);if(n==="")return"";let r=[];return t.ids&&r.push(`id="${ne(e.id)}"`),e.opacity<1&&r.push(`opacity="${K(e.opacity)}"`),r.push(...Bn(e,t.prefix)),`<g ${r.join(" ")}>${n}</g>`}function tp(e){return H0(e,"")}function H0(e,t){if(!(e.strokeWidth>0))return"";let n=ne(sn(e.stroke,{ids:!1,prefix:t})),r=K(e.strokeWidth),o=e.pose?.trace,s=[`d="${ne(e.d)}"`,'fill="none"',`stroke="${n}"`,`stroke-width="${r}"`,...np(e,e.dash??[])];e.cap!=="butt"&&s.push(`stroke-linecap="${e.cap}"`);let i=[`<path ${s.join(" ")}/>`];return(d=>{d&&(e.filled.d!==""&&i.push(`<path d="${ne(e.filled.d)}" fill="${n}"/>`),e.lined.d!==""&&i.push(`<path d="${ne(e.lined.d)}" fill="none" stroke="${n}" stroke-width="${r}"/>`))})(o===void 0||o>=1),i.join("")}function np(e,t){let n=e.kind==="vector"||e.kind==="connector",r=n?e.pose?.trace:void 0;if(r!==void 0&&n&&e.stroke!==void 0){let o=_i(t,ui(e.contours),r),s=[`stroke-dasharray="${o.array.map(K).join(" ")}"`];return(o.offset!==0||t.length===0)&&s.push(`stroke-dashoffset="${K(o.offset)}"`),s}return t.length===0?[]:[`stroke-dasharray="${t.map(K).join(" ")}"`]}function xr(e,t,n,r){let o=[`stroke="${ne(sn(t.paint,{ids:!1,prefix:n}))}"`,`stroke-width="${K(t.width*(r?2:1))}"`,...np(e,t.dash)];return t.cap!=="butt"&&o.push(`stroke-linecap="${t.cap}"`),t.join!=="miter"&&o.push(`stroke-linejoin="${t.join}"`),o}var rp="vd-stroke-";function as(e){if(e.mask!==void 0)return!1;let t=Pt(e);return!t||e.kind==="text"?!1:e.kind==="image"||t.align!=="center"}function MM(e,t){let n=[];return t.ids&&e.kind!=="border"&&n.push(`id="${ne(e.id)}"`),"opacity"in e&&e.opacity<1&&n.push(`opacity="${K(e.opacity)}"`),n.push(...Bn(e,t.prefix)),`${n.length===0?"<g>":`<g ${n.join(" ")}>`}${U0(e,t.prefix)}</g>`}function op(e){return U0(e,"")}function U0(e,t){let n=Pt(e),r={ids:!1,prefix:t},o="",s="",i=p=>{switch(e.kind){case"ellipse":s=Ed(e,p);return;case"vector":s=e.d===""?"":`<path d="${ne(e.d)}" ${p.join(" ")}/>`;return;case"rect":case"image":case"border":s=qt(e,e.radii,p);return;case"frame":case"text":return}};switch(e.kind){case"rect":o=qt(e,e.radii,[`fill="${ne(sn(e.fill,r))}"`]);break;case"ellipse":o=Ed(e,[`fill="${ne(sn(e.fill,r))}"`]);break;case"vector":{let p=[`fill="${ne(sn(e.fill,r))}"`],m=e.pose?.fillOpacity;m!==void 0&&m<1&&p.push(`fill-opacity="${K(m)}"`),e.rule!=="nonzero"&&p.push(`fill-rule="${e.rule}"`),o=e.d===""?"":`<path d="${ne(e.d)}" ${p.join(" ")}/>`;break}case"image":o=B0({...e,opacity:1,clip:void 0,rotation:0,shadows:[],blend:"normal"},r,!0);break;case"border":case"frame":case"text":break}if(!n)return o;if(n.align==="center")return i(['fill="none"',...xr(e,n,t,!1)]),o+s;let a=gd(e,n);if(a){let p=['fill="none"',...xr(e,n,t,!1)],m=e.kind==="ellipse"?Ed(a,p):qt(a,a.radii,p);return o+m}let d=Lf(e);if(!d)return o;let c=ne(t+rp+e.id);i(['fill="none"',...xr(e,n,t,!0),`clip-path="url(#${c})"`]);let l=n.align==="inside"?`<path d="${ne(ze(d.contours))}"${d.rule==="evenodd"?' clip-rule="evenodd"':""}/>`:z0(d.contours,n);return`${o}<clipPath id="${c}">${l}</clipPath>${s}`}function z0(e,t){let n=CM(e),r=Nf(t),o=n.x-r,s=n.y-r,i=n.x+n.w+r,a=n.y+n.h+r,d=`M${K(o)} ${K(s)}H${K(i)}V${K(a)}H${K(o)}Z`;return`<path d="${ne(d+ze(e))}" clip-rule="evenodd"/>`}function CM(e){let t=1/0,n=1/0,r=-1/0,o=-1/0;for(let s of e)for(let i of s.anchors)for(let a of[i,i.in,i.out])a&&(t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x),o=Math.max(o,a.y));return Number.isFinite(t)?{x:t,y:n,w:r-t,h:o-n}:{x:0,y:0,w:0,h:0}}function Ed(e,t){return`<ellipse cx="${K(e.x+e.w/2)}" cy="${K(e.y+e.h/2)}" rx="${K(e.w/2)}" ry="${K(e.h/2)}" ${t.join(" ")}/>`}function AM(e,t){if(e.lines.every(s=>s.spans.length===0))return"";let n=[];t.ids&&n.push(`id="${ne(e.id)}"`),n.push('xml:space="preserve"'),e.opacity<1&&n.push(`opacity="${K(e.opacity)}"`);let r=Pt(e);r&&n.push(...xr(e,r,t.prefix,!1),'paint-order="stroke"'),n.push(...Bn(e,t.prefix));let o=[];for(let s of e.lines)for(let i of s.spans)i.text!==""&&o.push($M(i,t));return`<text ${n.join(" ")}>${o.join("")}</text>`}function $M(e,t){let r=`<tspan ${[`x="${K(e.x)}"`,`y="${K(e.y)}"`,...OM(e.style,t)].join(" ")}>${TM(e.text)}</tspan>`;return e.style.link===void 0?r:`<a href="${ne(e.style.link)}">${r}</a>`}function OM(e,t){let n=[`font-family="${ne(e.family)}"`,`font-size="${K(e.size)}"`,`fill="${ne(sn(e.fill,t))}"`];e.weight!==400&&n.push(`font-weight="${K(e.weight)}"`),e.italic&&n.push('font-style="italic"'),e.letterSpacing!==0&&n.push(`letter-spacing="${K(e.letterSpacing)}"`);let r=[e.underline?"underline":"",e.strike?"line-through":""].filter(Boolean).join(" ");return r&&n.push(`text-decoration="${r}"`),n}function TM(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ne(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var NM=.8,RM=.2;function sp(e,t){let r=e.createElement("canvas").getContext("2d"),o=Fn(),s=new Map,i=new Map,a=new Set;function d(l){return`${l.italic?"italic ":""}${l.weight} ${l.size}px ${l.family}`}function c(){s.clear(),i.clear()}return{advance(l,p){if(!r)return o.advance(l,p);let m=d(p),g=`${m}\0${p.letterSpacing}\0${l}`,b=s.get(g);if(b!==void 0)return b;r.font=m;let w=r.measureText(l).width+p.letterSpacing*[...l].length;return s.set(g,w),w},metrics(l){if(!r)return o.metrics(l);let p=d(l),m=i.get(p);if(m)return m;r.font=p;let g=r.measureText("Hxg"),b=g.fontBoundingBoxAscent??l.size*NM,w=g.fontBoundingBoxDescent??l.size*RM,k={ascent:b,descent:w,lineGap:0};return i.set(p,k),k},load(l,p){let m=e.fonts;if(!m||typeof FontFace!="function")return!1;let g=!1;for(let b of Object.values(l.fonts))for(let w of IM(b)){let k=`${b.family}\0${w.src}\0${w.weight??400}\0${w.style??"normal"}`;if(a.has(k))continue;a.add(k);let _=w.src.startsWith("data:")?void 0:p?.(w.src),M={weight:String(w.weight??400),style:w.style??"normal"},R=B=>{let D=new FontFace(b.family,typeof B=="string"?`url(${B})`:FM(B),M);m.add(D),D.load().then(()=>{c(),t?.()},()=>{m.delete(D)})};_===void 0?R(w.src):(g=!0,_.then(R,()=>{}))}return g},invalidate:c,destroy(){c(),a.clear()}}}function IM(e){return(e.faces??[]).flatMap(t=>t.src===void 0?[]:[{...t,src:t.src}])}function FM(e){return e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}var Ld={x:0,y:0,zoom:1},K0=.02,G0=64;function ds(e){return Number.isFinite(e)?Math.min(Math.max(e,K0),G0):1}function Pd(e,t){return{x:(t.x-e.x)/e.zoom,y:(t.y-e.y)/e.zoom}}function ip(e,t){return{x:t.x*e.zoom+e.x,y:t.y*e.zoom+e.y}}function Ti(e,t,n){let r=ds(e.zoom*n),o=Pd(e,t);return{zoom:r,x:t.x-o.x*r,y:t.y-o.y*r}}function yn(e,t,n){return{...e,x:e.x+t,y:e.y+n}}function ap(e){return`translate(${e.x} ${e.y}) scale(${e.zoom})`}function bn(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 Ld;let o=ds(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 le="http://www.w3.org/2000/svg",q0="vd-viewer-styles",W0=`
45
45
  .vd-viewer {
46
46
  position: relative;
47
47
  overflow: hidden;
@@ -140,7 +140,7 @@ ${Kn}`);return t===-1?-1:t+1}function Zv(e){let t=new Set;for(let n of e.matchAl
140
140
  .vd-viewer--interacting .vd-viewer__page {
141
141
  filter: none;
142
142
  }
143
- `;function ah(e){if(e.getElementById(sh))return;let t=e.createElement("style");t.id=sh,t.textContent=ih,e.head.appendChild(t)}function lh(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 uh(e,t,n,r,o){return t?j0(e,t,n,r,o):z0(e,n,r)}function z0(e,t,n){let r=Nl(e,n);return{measurer:r,update:o=>{r.load(o,t)},afterPaint:()=>{},destroy:()=>r.destroy()}}var dh=new WeakMap;function j0(e,t,n,r,o){let s,i,d,l=()=>{if(!s)throw new Error("canvasFonts: update() before measuring");return s};return{measurer:{advance:(p,m)=>l().measurer.advance(p,m),metrics:p=>l().measurer.metrics(p),itemize:p=>l().measurer.itemize(p)},update(p){s&&p.fonts===i||(d?.(),s?.dispose(),s=t.forDocument(p,{...n?{loader:n}:{},...o?{asset:o}:{}}),i=p.fonts,d=s.onChange(r))},afterPaint(){let p=e.fonts;if(!s||!p||typeof FontFace!="function")return;let m=dh.get(e);m||dh.set(e,m=new Set);for(let y of s.usedFaces()){if(m.has(y.id))continue;m.add(y.id);let v=new FontFace(y.id,K0(y.bytes),{weight:String(y.weight),style:y.style});p.add(v),v.load().catch(()=>p.delete(v))}},destroy(){d?.(),s?.dispose(),s=void 0}}}function K0(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}var G0=.01,q0=.004,fh=40,W0=16;function ki(e,t){ah(e.ownerDocument);let n=t.document,r=B=>uh(e.ownerDocument,B,t.loadFont,()=>{q(n)},lh(t.resolveAsset)),o=r(t.fonts),s={advance:(B,W)=>o.measurer.advance(B,W),metrics:B=>o.measurer.metrics(B),itemize:B=>o.measurer.itemize?.(B)??[B]};o.update(n);let i=Ne(n),d=()=>t.resolveAsset?{measure:s,resolveAsset:t.resolveAsset}:{measure:s},l=zo(n,i,d()),f=t.camera??bi,p=t.interactive??!0,m=t.wheel??"always";e.classList.add("vd-viewer"),t.surface&&(e.style.background=t.surface);let y=e.ownerDocument.createElementNS(ve,"svg");y.setAttribute("class","vd-viewer__surface"),y.setAttribute("width","100%"),y.setAttribute("height","100%");let v=e.ownerDocument.createElementNS(ve,"g");v.setAttribute("class","vd-viewer__camera"),v.style.isolation="isolate",y.appendChild(v);let C=e.ownerDocument.createElementNS(ve,"defs");v.appendChild(C);let S=e.ownerDocument.createElementNS(ve,"rect");S.setAttribute("class","vd-viewer__page"),v.appendChild(S),e.appendChild(y);let g=new Map,L=null;function A(){let B=t.sample;return L&&B?B(l,L.timeline,L.t,{doc:n,resolution:i,options:d()}):l}function I(){v.setAttribute("transform",Rl(f))}function U(B=!0){let W=A();R(W);let xe=l.background!==void 0;pe(S,"x",String(l.x)),pe(S,"y",String(l.y)),pe(S,"width",String(xe?l.width:0)),pe(S,"height",String(xe?l.height:0)),Me(S,"fill",l.background??null);let ge=new Set,De=S;for(let me of W.items){let We=me.part===void 0?me.id:`${me.id}\0${me.part}`;ge.add(We);let Oe=g.get(We);(!Oe||Oe.tagName!==ch(me))&&(Oe?.remove(),Oe=e.ownerDocument.createElementNS(ve,ch(me)),Oe.setAttribute("data-vd-id",me.id),g.set(We,Oe)),J0(Oe,me),De.nextSibling!==Oe&&v.insertBefore(Oe,De.nextSibling),De=Oe}for(let[me,We]of g)ge.has(me)||(We.remove(),g.delete(me));o.afterPaint(),B&&t.onSceneChange?.(l,n)}let j=new Map;function R(B){let W=[...B.gradients.map(Tl),...[...new Map(B.items.filter(me=>me.shadows.length>0).map(me=>[me.id,me])).values()].map(me=>Ll(me)),...B.clips.map(Ol)],xe=new Set(W);for(let[me,We]of j)xe.has(me)||(We.remove(),j.delete(me));let ge=W.filter(me=>!j.has(me));if(ge.length===0)return;[...new DOMParser().parseFromString(`<svg xmlns="${ve}">${ge.join("")}</svg>`,"image/svg+xml").documentElement.children].forEach((me,We)=>{let Oe=e.ownerDocument.importNode(me,!0);C.appendChild(Oe),j.set(ge[We],Oe)})}function q(B){n=B,o.update(n),i=Ne(n),l=zo(n,i,d()),U()}function $(B){let W=e.getBoundingClientRect();return{x:B.clientX-W.left,y:B.clientY-W.top}}let V=0,b=0;function D(){e.classList.add("vd-viewer--interacting"),b&&clearTimeout(b),b=setTimeout(()=>{b=0,e.classList.remove("vd-viewer--interacting")},180)}function T(){V&&(cancelAnimationFrame(V),V=0),I(),t.onCameraChange?.(f)}function G(B){f=B,T()}function Y(B){f=B,D(),!V&&(V=requestAnimationFrame(()=>{V=0,I(),t.onCameraChange?.(f)}))}let re=null,E=null,k=!1,O=p&&m==="always",P=new Map,K=null,Z=()=>{let[B,W]=[...P.values()];return!B||!W?null:{mid:{x:(B.x+W.x)/2,y:(B.y+W.y)/2},distance:Math.hypot(B.x-W.x,B.y-W.y)}},z=B=>{let W=P.get(B.pointerId);if(!W)return;let xe=$(B);if(P.set(B.pointerId,xe),P.size===1){Y(It(f,xe.x-W.x,xe.y-W.y));return}let ge=Z();if(K&&ge){let De=It(f,ge.mid.x-K.mid.x,ge.mid.y-K.mid.y);Y(K.distance>0?jo(De,ge.mid,ge.distance/K.distance):De)}K=ge},ce=B=>{P.delete(B.pointerId)&&(e.hasPointerCapture(B.pointerId)&&e.releasePointerCapture(B.pointerId),K=Z())},Ee=B=>{if(m==="modifier"&&!B.ctrlKey&&!B.metaKey)return;B.preventDefault();let W=$(B),xe=B.deltaMode===1?W0:B.deltaMode===2?e.clientHeight||800:1,ge=B.deltaX*xe,De=B.deltaY*xe;if(B.ctrlKey||B.metaKey){let me=B.ctrlKey?G0:q0,We=Math.max(-fh,Math.min(fh,De));Y(jo(f,W,Math.exp(-We*me)));return}if(B.shiftKey&&ge===0){Y(It(f,-De,0));return}Y(It(f,-ge,-De))},Ae=B=>{if(B.pointerType==="touch"){if(!O)return;B.preventDefault(),P.set(B.pointerId,$(B)),e.setPointerCapture(B.pointerId),K=Z();return}(B.button===1||B.button===0&&k)&&(B.preventDefault(),re=B.pointerId,E=$(B),e.setPointerCapture(B.pointerId))},Ce=B=>{if(B.pointerType==="touch"){z(B);return}if(re!==B.pointerId||!E)return;let W=$(B);Y(It(f,W.x-E.x,W.y-E.y)),E=W},ot=B=>{if(B.pointerType==="touch"){ce(B);return}re===B.pointerId&&(re=null,E=null,e.hasPointerCapture(B.pointerId)&&e.releasePointerCapture(B.pointerId))},ee=B=>{B.code==="Space"&&(k=!0)},ae=B=>{B.code==="Space"&&(k=!1)};O&&(e.style.touchAction="none"),p&&(e.addEventListener("wheel",Ee,{passive:!1}),e.addEventListener("pointerdown",Ae),e.addEventListener("pointermove",Ce),e.addEventListener("pointerup",ot),e.addEventListener("pointercancel",ot),e.ownerDocument.addEventListener("keydown",ee),e.ownerDocument.addEventListener("keyup",ae)),I(),U();let ie={element:e,surface:y,update:q,getDocument:()=>n,getScene:()=>l,setTime(B){B===null&&L===null||(L=B,U(!1))},getTime:()=>L,getResolution:()=>i,getMeasurer:()=>s,setFonts(B){o.destroy(),o=r(B),q(n)},getCamera:()=>f,setCamera:G,zoomBy(B,W){let xe=e.getBoundingClientRect(),ge=W??{x:xe.width/2,y:xe.height/2};G(jo(f,ge,B))},fitToContent(B=32){let W=e.getBoundingClientRect();G(Rt({x:l.x,y:l.y,width:l.width,height:l.height},{width:W.width||l.width,height:W.height||l.height},B))},screenToDocument:B=>wi(f,B),documentToScreen:B=>Il(f,B),pointerPoint:$,hitTest(B,W){for(let xe=l.items.length-1;xe>=0;xe--){let ge=l.items[xe];if(ge&&aw(ge,B,iw/f.zoom)&&(!W||W(ge.id)))return ge.id}return null},linkAt(B,W){for(let xe=l.items.length-1;xe>=0;xe--){let ge=l.items[xe];if(ge?.kind!=="text"||W&&!W(ge.id))continue;let De=ge.rotation===0?B:at(B,{x:ge.x+ge.w/2,y:ge.y+ge.h/2},-ge.rotation);for(let me of ge.lines){if(De.y<me.y||De.y>me.y+me.h)continue;let We=me.spans.find(Oe=>De.x>=Oe.x&&De.x<=Oe.x+Oe.w);if(We)return We.style.link}}},itemOf:B=>l.items.find(W=>W.id===B),elementOf:B=>g.get(B),destroy(){p&&(e.removeEventListener("wheel",Ee),e.removeEventListener("pointerdown",Ae),e.removeEventListener("pointermove",Ce),e.removeEventListener("pointerup",ot),e.removeEventListener("pointercancel",ot),e.ownerDocument.removeEventListener("keydown",ee),e.ownerDocument.removeEventListener("keyup",ae)),V&&cancelAnimationFrame(V),b&&clearTimeout(b),V=0,b=0,o.destroy(),e.classList.remove("vd-viewer--interacting"),y.remove(),g.clear(),e.classList.remove("vd-viewer")}};return t.autoFit&&ie.fitToContent(),ie}var X0="vd-clip-";function Y0(e){return X0+e}function mh(e){return`url(#${Y0(e)})`}function ch(e){return Dl(e)||e.pose!==void 0?"g":Fl(e)}function Fl(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 J0(e,t){if(e.tagName!=="g"){ph(e,t);return}Me(e,"clip-path",t.clip===void 0?null:mh(t.clip)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend;let n=t.pose;Me(e,"opacity",n&&n.opacity<1?String(n.opacity):null);let r=e.firstElementChild;if((!r||r.tagName!==Fl(t))&&(r?.remove(),r=e.ownerDocument.createElementNS(ve,Fl(t)),e.appendChild(r)),ph(r,{...t,clip:void 0,blend:"normal"}),n){let o=t.rotation===0?"":` ${vi(t)}`;pe(r,"transform",`${Pl(n)}${o}`),t.kind==="vector"&&Z0(r,t)}}function Z0(e,t){let n=t.pose?.trace;if(n!==void 0&&t.stroke!==void 0){let o=Vs(t.contours)+1;pe(e,"stroke-dasharray",`${o} ${o}`),pe(e,"stroke-dashoffset",String(o*(1-n)))}let r=t.pose?.fillOpacity;Me(e,"fill-opacity",r!==void 0&&r<1?String(r):null)}function ph(e,t){switch(Me(e,"clip-path",t.clip===void 0?null:mh(t.clip)),Me(e,"transform",t.rotation===0?null:vi(t)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend,e.style.filter=t.shadows.length>0?`url(#${yi}${t.id})`:"",t.kind){case"ellipse":ow(e,t);return;case"frame":Q0(e,t);return;case"image":ew(e,t);return;case"rect":rw(e,t);return;case"text":nw(e,t);return;case"vector":sw(e,t);return}}function Q0(e,t){pe(e,"class","vd-viewer__page"),pe(e,"x",String(t.x)),pe(e,"y",String(t.y)),pe(e,"width",String(t.w)),pe(e,"height",String(t.h)),Me(e,"fill",t.background??null)}function ew(e,t){if(pe(e,"x",String(t.x)),pe(e,"y",String(t.y)),pe(e,"width",String(t.w)),pe(e,"height",String(t.h)),Me(e,"opacity",t.opacity<1?String(t.opacity):null),t.href===void 0){pe(e,"class","vd-viewer__missing"),Me(e,"rx",t.radius>0?String(t.radius):null);return}pe(e,"href",t.href),pe(e,"preserveAspectRatio",tw[t.fit])}var tw={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"};function nw(e,t){Me(e,"opacity",t.opacity<1?String(t.opacity):null),pe(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(ve,"tspan"));n.forEach((o,s)=>{let i=e.childNodes[s];i.textContent!==o.text&&(i.textContent=o.text),pe(i,"x",String(o.x)),pe(i,"y",String(o.y)),pe(i,"font-family",o.style.family),pe(i,"font-size",String(o.style.size)),pe(i,"fill",o.style.fill),Me(i,"font-weight",o.style.weight===400?null:String(o.style.weight)),Me(i,"font-style",o.style.italic?"italic":null),Me(i,"letter-spacing",o.style.letterSpacing===0?null:String(o.style.letterSpacing)),Me(i,"data-vd-link",o.style.link??null);let d=[o.style.underline?"underline":"",o.style.strike?"line-through":""].filter(Boolean).join(" ");Me(i,"text-decoration",d===""?null:d)})}function rw(e,t){Me(e,"class",null),pe(e,"x",String(t.x)),pe(e,"y",String(t.y)),pe(e,"width",String(t.w)),pe(e,"height",String(t.h)),pe(e,"fill",t.fill),Me(e,"rx",t.radius>0?String(t.radius):null),Me(e,"stroke",t.stroke??null),Me(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),Me(e,"opacity",t.opacity<1?String(t.opacity):null)}function hh(e,t){pe(e,"fill",t.fill),Me(e,"stroke",t.stroke??null),Me(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),Me(e,"opacity",t.opacity<1?String(t.opacity):null)}function ow(e,t){pe(e,"cx",String(t.x+t.w/2)),pe(e,"cy",String(t.y+t.h/2)),pe(e,"rx",String(t.w/2)),pe(e,"ry",String(t.h/2)),hh(e,t)}function sw(e,t){pe(e,"d",t.d),hh(e,t),Me(e,"fill-rule",t.rule==="nonzero"?null:t.rule),Me(e,"stroke-linecap",t.cap==="butt"?null:t.cap),Me(e,"stroke-linejoin",t.join==="miter"?null:t.join)}function pe(e,t,n){e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Me(e,t,n){n===null?e.hasAttribute(t)&&e.removeAttribute(t):pe(e,t,n)}var iw=4;function aw(e,t,n){let r=e.rotation===0?t:at(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 s=e.stroke!==void 0?e.strokeWidth/2:0,i=e.w/2+s,d=e.h/2+s;if(i<=0||d<=0)return!1;let l=(r.x-(e.x+e.w/2))/i,f=(r.y-(e.y+e.h/2))/d;return l*l+f*f<=1}if(e.kind==="vector"){let s=e.stroke!==void 0&&e.strokeWidth>0;return _d(e.contours,r,{fill:e.fill!=="none",rule:e.rule,reach:(s?e.strokeWidth/2:0)+n})}return o}var DC=Bl(ei),PC=Bl(ti),dw=Bl(ni);function Bl(e){return`cubic-bezier(${e.join(", ")})`}function Hl(e,t){let n=e.root.id;if(n===t)return e;let r=o=>{if(!ye(o))return o;let s=pt(o.expr);return!s.ok||!Zt(s.ast).nodes.includes(n)?o:{expr:Gn(Nt(s.ast,i=>i===n?t:void 0))}};return{...e,root:{...xh(e.root,r),id:t}}}function xh(e,t){let n=e,r={};for(let[o,s]of Object.entries(n)){if(o==="children"&&Array.isArray(s)){r[o]=s.map(i=>xh(i,t));continue}r[o]=t(s)}return r}var Vl=["nw","n","ne","e","se","s","sw","w"],qo=["nw","ne","se","sw"];function _i(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 Tr(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 zl(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 Go=1;function en(e,t,n,r){let{x:o,y:s,w:i,h:d}=e;if(t.includes("w")){let l=o+i;o=Math.min(o+n,l-Go),i=l-o}if(t.includes("e")&&(i=Math.max(Go,i+n)),t.includes("n")){let l=s+d;s=Math.min(s+r,l-Go),d=l-s}return t.includes("s")&&(d=Math.max(Go,d+r)),{x:o,y:s,w:i,h:d}}function Wn(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 Si(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 bt(e){if(e.length===0)return null;let t=1/0,n=1/0,r=-1/0,o=-1/0;for(let s of e)t=Math.min(t,s.x),n=Math.min(n,s.y),r=Math.max(r,s.x+s.w),o=Math.max(o,s.y+s.h);return{x:t,y:n,w:r-t,h:o-n}}function jl(e,t){return e.x<t.x+t.w&&e.x+e.w>t.x&&e.y<t.y+t.h&&e.y+e.h>t.y}function Et(e,t,n){return t>=e.x&&t<=e.x+e.w&&n>=e.y&&n<=e.y+e.h}var Lr=7,Ul=15,Ko=9;function Kl(e){let t=[],n=Ul/2;for(let d of qo){let{u:l,v:f}=Tr(d);t.push({handle:d,rect:{x:e.x+e.w*l-n,y:e.y+e.h*f-n,w:Ul,h:Ul}})}let r=n,o=Math.max(0,e.w-r*2),s=Math.max(0,e.h-r*2),i=Ko/2;return t.push({handle:"n",rect:{x:e.x+r,y:e.y-i,w:o,h:Ko}},{handle:"s",rect:{x:e.x+r,y:e.y+e.h-i,w:o,h:Ko}},{handle:"w",rect:{x:e.x-i,y:e.y+r,w:Ko,h:s}},{handle:"e",rect:{x:e.x+e.w-i,y:e.y+r,w:Ko,h:s}}),t}function Re(e,t){let n=[],r=o=>{if(n.push(o.id),o.id===t)return!0;for(let s of ne(o))if(r(s))return!0;return n.pop(),!1};return r(e)?n:[]}function Ei(e,t,n){let r=Re(t.root,e);if(r.length===0)return e;let o=n!==null&&r.includes(n)?n:cw(r,t),s=r.indexOf(o);if(s===-1)return e;let i=r.indexOf(n??"")+1;for(let d=Math.max(i,1);d<s+1;d+=1)if(F(t.root,r[d])?.type==="instance")return r[d];return r[s+1]??e}function cw(e,t){for(let n=e.length-2;n>=0;n-=1){let r=e[n];if(F(t.root,r)?.type==="frame")return r}return t.root.id}function gh(e,t){let n=e.map(o=>Re(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 s=n[0]?.[o];if(s===void 0||n.some(i=>i[o]!==s||o===i.length-1))break;r=s}return r}function Xn(e,t){let n=F(t.root,e);if(!n)return[];let r=[],o=s=>{if($e(s)){for(let i of ne(s))o(i);return}r.push(s.id)};return o(n),r}function Yn(e,t,n){let r=F(t.root,e);if(!r)return;if(!$e(r)){let i=n.nodes.get(e);return i?Wo(i):void 0}let o=[],s=i=>{if(!(i.id!==e&&"hidden"in i&&i.hidden===!0)){if(i.id!==e&&!$e(i)){let d=Yn(i.id,t,n);d&&o.push(d);return}for(let d of ne(i))s(d)}};return s(r),bt(o)??void 0}function Wo(e){let t={x:e.absX,y:e.absY,w:e.w,h:e.h},n=e.values.rotation??0;return n===0?t:Io(t,n)}function Xo(e,t,n){return t.flatMap(r=>{let o=Yn(r,e,n);return o?[{id:r,frame:o}]:[]})}function Gl(e,t){let n=t.filter(m=>m!==e.root.id&&F(e.root,m));if(n.length<2)return null;let r=gh(n,e),o=F(e.root,r);if(!o)return null;let s=ne(o),i=new Set(n.map(m=>Ei(m,e,r))),d=s.filter(m=>i.has(m.id));if(d.length<2)return null;let l=s.findIndex(m=>m.id===d[d.length-1]?.id),f=gn(e.root,"group"),p=[{op:"insert",parent:r,index:l+1,node:sd({id:f,children:[]})}];return d.forEach((m,y)=>{p.push({op:"move",id:m.id,parent:f,index:y})}),{ops:p,groupId:f}}function ql(e,t){let n=F(e.root,t);if(!n||!$e(n))return[];let r=Re(e.root,t),o=r[r.length-2];if(o===void 0)return[];let s=F(e.root,o);if(!s)return[];let i=ne(s).findIndex(l=>l.id===t);if(i===-1)return[];let d=ne(n).map((l,f)=>({op:"move",id:l.id,parent:o,index:i+f}));return d.push({op:"remove",id:t}),d}function Wl(e,t,n){let r=new Map;for(let s of t){let i=Re(e.root,s),d=i[i.length-2];if(d===void 0)continue;let l=r.get(d)??new Set;l.add(s),r.set(d,l)}let o=[];for(let[s,i]of r){let d=F(e.root,s);if(!d)continue;let l=ne(d).map(f=>f.id);o.push(...mw(s,l,pw(l,i,n)))}return o}function pw(e,t,n){if(n==="front"||n==="back"){let i=e.filter(l=>t.has(l)),d=e.filter(l=>!t.has(l));return n==="front"?[...d,...i]:[...i,...d]}let r=n==="forward"?1:-1,o=[...e],s=o.flatMap((i,d)=>t.has(i)?[d]:[]);r===1&&s.reverse();for(let i of s){let d=i+r,l=o[d];l===void 0||t.has(l)||(o[d]=o[i],o[i]=l)}return o}function mw(e,t,n){let r=[...t],o=[];for(let s=0;s<n.length;s+=1){let i=n[s];i===void 0||r[s]===i||(r.splice(r.indexOf(i),1),r.splice(s,0,i),o.push({op:"move",id:i,parent:e,index:s}))}return o}function Xl(e,t,n){let r=t.w===0?1:n.w/t.w,o=t.h===0?1:n.h/t.h,s=new Map;for(let[i,d]of e)s.set(i,{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 s}function Dr(e,t){let n=[];for(let r of t){if(!F(e.root,r.nodeId))continue;let o=te(r.to);te(r.from)!==o&&n.push({op:"set",id:r.nodeId,prop:r.prop,value:o})}return n}function te(e){return Math.round(e*100)/100}function Pr(e,t,n,r){let o=new Set,s=[];for(let l of t)l.op==="set"&&(o.add(nt(l.id,l.prop)),s.push({nodeId:l.id,prop:l.prop}));if(s.length===0)return[];let i=[],d=new Set;for(let l of s)for(let f of n.get(nt(l.nodeId,l.prop))??[]){let p=nt(f.nodeId,f.prop);if(o.has(p)||d.has(p)||!F(e.root,f.nodeId))continue;let m=r.nodes.get(f.nodeId)?.values[f.prop];m!==void 0&&(d.add(p),i.push({op:"set",id:f.nodeId,prop:f.prop,value:te(m)}))}return i}function Yl(e,t,n,r={x:0,y:0}){let o=[],s=new Set,i=e;for(;;){let d=[],l=Ne(i);for(let[f,p]of t){let m=n.get(f),y=F(i.root,p),v=l.nodes.get(p);if(!(!m||!y||!v))for(let C of Ct(y)){let S=nt(p,C);if(s.has(S))continue;let g=m[C],L=v.values[C];if(g===void 0||L===void 0)continue;let A=g+(C==="x"?r.x:C==="y"?r.y:0);te(A)!==te(L)&&(s.add(S),d.push({op:"set",id:p,prop:C,value:te(A)}))}}if(d.length===0)return o;o.push(...d),i=_e(i,d).document}}function Nr(e,t,n=new Set){let r=Ne(e),o=Ne(t),s=[],i=hw(t.root);for(let[d,l]of o.nodes){if(n.has(d)||i.has(d))continue;let f=r.nodes.get(d),p=F(t.root,d);if(!(!f||!p))for(let m of Ct(p)){let y=f.values[m],v=l.values[m];y===void 0||v===void 0||te(y)!==te(v)&&s.push({op:"set",id:d,prop:m,value:te(y)})}}return s}function hw(e){let t=new Set;return oe(e,n=>{if(n.type==="instance"){for(let r of n.children)oe(r,o=>{t.add(o.id)});return!1}}),t}function Ci(e,t,n){let r=new Set,o=[];for(let s of t)s.op==="set"&&s.prop==="view"&&r.add(s.id);for(let s of t){if(s.op!=="set"||s.prop!=="w"&&s.prop!=="h"||r.has(s.id))continue;let i=F(e.root,s.id);if(i?.type!=="vector"||i.view!==void 0)continue;let d=n(s.id);d&&(r.add(s.id),o.push({op:"set",id:s.id,prop:"view",value:zn({x:0,y:0,w:d.w,h:d.h})}))}return o.length===0?[...t]:[...o,...t]}var xw=200,gw=100,yw=3,vw=.5;function Ve(e,t){return At(e.root,t)!==void 0}function tn(e,t){let n=F(e.root,t);return n?.type==="frame"&&n.component===!0}function Yo(e,t){if(t.length===0)return!1;let n=new Set;for(let r of t){if(r===e.root.id||Ve(e,r))return!1;let o=F(e.root,r);if(!o)return!1;let s=Fe(e.root,r);if(o.type==="frame"&&(o.component===!0||s?.id===e.root.id))return!1;n.add(s?.id)}return n.size===1}function Jl(e,t,n){if(!Yo(e,t))return null;let r=Fe(e.root,t[0]);if(!r)return null;let o=r.children.filter(A=>t.includes(A.id)),s=o.length===1?o[0]:void 0,i=xn(e.root),d,l,f;if(s?.type==="frame"){let A=n.nodes.get(s.id);yh(s.id,s.children,i);let{name:I,hidden:U,locked:j}=s,R={...s};for(let $ of["x","y","w","h","name","hidden","locked"])delete R[$];d={...R,id:Ir(`${s.id}.main`,i),x:0,y:0,w:te(A?.w??0),h:te(A?.h??0),component:!0},l={type:"instance",id:s.id,...I===void 0?{}:{name:I},component:d.id,x:s.x,y:s.y,...s.w===d.w?{}:{w:s.w},...s.h===d.h?{}:{h:s.h},...U===void 0?{}:{hidden:U},...j===void 0?{}:{locked:j},children:[]};let q=$=>$===s.id?d.id:void 0;d={...d,children:d.children.map($=>wh($,q))},f=s.children}else{let A=bw(o,n);if(!A)return null;let I=ww(e,r.id,n),U=te(A.x-I.x),j=te(A.y-I.y),R=s&&$e(s)?s:void 0,q=R?R.id:Ir("component",i),$=R?ne(R):o;yh(q,$,i),d={type:"frame",id:Ir(`${q}.main`,i),x:0,y:0,w:te(A.w),h:te(A.h),component:!0,children:$.map(V=>kh(V,U,j))},l={type:"instance",id:q,...R?.name===void 0?{}:{name:R.name},component:d.id,x:U,y:j,...R?.type==="group"&&R.hidden!==void 0?{hidden:R.hidden}:{},...R?.type==="group"&&R.locked!==void 0?{locked:R.locked}:{},children:[]},f=$}let p=Jo(e,n);d={...d,x:p.x,y:p.y};let m=new Set;for(let A of f)oe(A,I=>{m.add(I.id)});let y=new Set(o.map(A=>A.id));for(let A of o)oe(A,I=>{y.add(I.id)});let v=Math.min(...o.map(A=>r.children.indexOf(A))),C=[...o.map(A=>({op:"remove",id:A.id})),{op:"insert",parent:r.id,index:v,node:l},{op:"insert",parent:e.root.id,index:e.root.children.length,node:d}],S=A=>m.has(A)&&A!==l.id?Mt(l.id,A):void 0;C.push(...kw(e,A=>!y.has(A.id),S)),C.push(..._w(e,S));let g=[],L=_e(e,C).document;for(let A=0;A<yw;A+=1){let I=Ne(L),U=[];for(let j of m){let R=n.nodes.get(j),q=I.nodes.get(Mt(l.id,j)),$=F(L.root,j);if(!R||!q||!$||$e($))continue;let V=$,b={x:R.absX-q.absX,y:R.absY-q.absY,w:R.w-q.w,h:R.h-q.h};for(let D of["x","y","w","h"]){if(Math.abs(b[D])<vw||V[D]===void 0)continue;let T=D==="x"?q.x:D==="y"?q.y:q[D];U.push({op:"set",id:j,prop:D,value:te(T+b[D])}),g.includes(`${j}.${D}`)||g.push(`${j}.${D}`)}}if(U.length===0)break;C.push(...U),L=_e(L,U).document}return{ops:C,componentId:d.id,instanceId:l.id,flattened:g}}function Mi(e,t,n){let r=F(e.root,t);if(r?.type!=="instance"||Ve(e,t))return null;let o=Fe(e.root,t);if(!o)return null;let s=Ye(e.root).get(r.component),i=n.nodes.get(t),d=new Set;for(let m of r.children)oe(m,y=>{d.add(y.id)});let l=m=>m===r.component?t:d.has(Mt(t,m))?Mt(t,m):void 0,f={type:"frame",id:t,...r.name===void 0?{}:{name:r.name},x:r.x,y:r.y,w:r.w??te(i?.w??0),h:r.h??te(i?.h??0),...s?.background===void 0?{}:{background:s.background},...s?.clip===void 0?{}:{clip:s.clip},...s?.blend===void 0?{}:{blend:s.blend},...s?.shadow===void 0?{}:{shadow:s.shadow},...r.hidden===void 0?{}:{hidden:r.hidden},...r.locked===void 0?{}:{locked:r.locked},children:r.children.map(m=>vh(m,r,l))},p=o.children.findIndex(m=>m.id===t);return[{op:"remove",id:t},{op:"insert",parent:o.id,index:p,node:f}]}function vh(e,t,n){let r={...e};for(let[o,s]of Object.entries(r))ye(s)&&(r[o]=$i(s.expr,n)??s);if(e.type==="instance"){let o=e.id.slice(t.id.length+1),s={...e.overrides};for(let[d,l]of Object.entries(t.overrides??{})){if(!d.startsWith(`${o}.`))continue;let f=d.slice(o.length+1);s[f]={...s[f],...l}}let i={...r};return delete i.overrides,{...i,...Object.keys(s).length===0?{}:{overrides:s},children:[]}}return fe(e)&&(r.children=e.children.map(o=>vh(o,t,n))),r}function Zl(e,t,n){let r=F(e.root,t);if(r?.type!=="instance"||r.overrides===void 0)return[];if(n===void 0)return[{op:"set",id:t,prop:"overrides",value:void 0}];let o=n.startsWith(`${t}.`)?n.slice(t.length+1):n;if(r.overrides[o]===void 0)return[];let s={...r.overrides};return delete s[o],[{op:"set",id:t,prop:"overrides",value:Object.keys(s).length===0?void 0:s}]}function bh(e,t,n){let r=nd(e.root,t);return r===void 0||!td(e.root,n,r)}function Ql(e,t,n){let r=F(e.root,t),o=Ye(e.root),s=r?.type==="instance"?o.get(r.component):void 0,i=o.get(n);if(r?.type!=="instance"||!i||r.component===n)return[];if(!bh(e,t,n))return[];let d=new Map;s&&eu(s.children,i.children,d);let l={};for(let[f,p]of Object.entries(r.overrides??{})){let m=F(i,f)?f:Eh(f,d);F(i,m)&&(l[m]=p)}return[{op:"set",id:t,prop:"component",value:n},{op:"set",id:t,prop:"overrides",value:Object.keys(l).length===0?void 0:l}]}function eu(e,t,n){e.forEach((r,o)=>{let s=t[o];!s||s.type!==r.type||(n.set(r.id,s.id),!(r.type==="instance"||s.type==="instance")&&eu(ne(r),ne(s),n))})}function tu(e,t,n,r){if(!tn(e,t))return null;let o=F(e.root,n);if(!o||!fe(o)||o.type==="instance"||Ve(e,n))return null;let s=Ir(t.replace(/\.main$/,""),xn(e.root)),i={type:"instance",id:s,component:t,x:te(r.x),y:te(r.y),children:[]};return{ops:[{op:"insert",parent:n,index:o.children.length,node:i}],id:s}}function Ai(e,t){return t.reduce((n,r)=>n+Ut(e.root,r).length,0)}function nu(e,t,n){let r=[],o=e,s=new Set(t);for(let i=0;i<t.length+1;i+=1){let d=Ut(o.root).filter(l=>s.has(l.component)&&!Re(o.root,l.id).some(f=>s.has(f)));if(d.length===0)break;for(let l of d){let f=Mi(o,l.id,n);f&&(r.push(...f),o=_e(o,f).document)}}for(let i of t)r.push({op:"remove",id:i});return r}function Jo(e,t){let n=e.root.children.flatMap(i=>{let d=t.nodes.get(i.id);return!d||$e(i)?[]:[{node:i,x:d.absX,y:d.absY,w:d.w,h:d.h}]}),r=n.filter(i=>i.node.type==="frame"&&i.node.component===!0);if(r.length>0){let i=Math.max(...r.map(l=>l.x+l.w)),d=Math.min(...r.map(l=>l.y));return{x:te(i+gw),y:te(d)}}if(n.length===0)return{x:0,y:0};let o=Math.min(...n.map(i=>i.x)),s=Math.max(...n.map(i=>i.y+i.h));return{x:te(o),y:te(s+xw)}}function yh(e,t,n){for(let r of t)oe(r,o=>{n.add(Mt(e,o.id))})}function wh(e,t){let n={...e};for(let[r,o]of Object.entries(e))ye(o)&&(n[r]=$i(o.expr,t)??o);return e.type==="instance"||!fe(e)?n:{...n,children:e.children.map(r=>wh(r,t))}}function Ir(e,t){let n=e;for(let r=2;t.has(n);r+=1)n=`${e}.${r}`;return t.add(n),n}function bw(e,t){let n=1/0,r=1/0,o=-1/0,s=-1/0;for(let i of e)oe(i,d=>{if("hidden"in d&&d.hidden===!0)return!1;if($e(d))return;let l=t.nodes.get(d.id);return l&&(n=Math.min(n,l.absX),r=Math.min(r,l.absY),o=Math.max(o,l.absX+l.w),s=Math.max(s,l.absY+l.h)),!1});return Number.isFinite(n)?{x:n,y:r,w:o-n,h:s-r}:null}function ww(e,t,n){let r=Re(e.root,t);for(let o=r.length-1;o>=0;o-=1){let s=F(e.root,r[o]);if(!s||$e(s))continue;let i=n.nodes.get(s.id);return i?{x:i.absX,y:i.absY}:{x:0,y:0}}return{x:0,y:0}}function kh(e,t,n){if($e(e))return{...e,children:ne(e).map(o=>kh(o,t,n))};let r={...e};return typeof r.x=="number"&&(r.x=te(r.x-t)),typeof r.y=="number"&&(r.y=te(r.y-n)),r}function kw(e,t,n){let r=[];return oe(e.root,o=>{if(o.type==="instance"||!t(o))return!1;for(let[s,i]of Object.entries(o)){if(!ye(i))continue;let d=$i(i.expr,n);d&&r.push({op:"set",id:o.id,prop:s,value:d})}}),r}function $i(e,t){let n=pt(e);if(n.ok&&Zt(n.ast).nodes.some(r=>t(r)!==void 0))return{expr:Gn(Nt(n.ast,t))}}function _w(e,t){let n=[];for(let[r,o]of Object.entries(e.motion??{})){let s=!1,i=o.lines.map(d=>{let l=t(d.id),f=d.after===void 0?void 0:t(d.after),p=d.with===void 0?void 0:t(d.with);return l===void 0&&f===void 0&&p===void 0?d:(s=!0,{...d,...l===void 0?{}:{id:l},...f===void 0?{}:{after:f},...p===void 0?{}:{with:p}})});if(s){let d={...o,lines:i};n.push({op:"setMotion",page:r,value:d})}}return n}function _h(e,t,n){let r=Ye(e.root),o=xn(e.root),s=new Map,i=new Map,d=new Map,l=[];for(let m of t){let y=r.get(m.id);if(y&&Sw(y,m)){s.set(m.id,m.id);continue}if(y&&n(m.id)){s.set(m.id,m.id);let S=new Map;eu(m.children,y.children,S);let g=new Set;for(let L of y.children)oe(L,A=>{g.add(A.id)});for(let[L,A]of[...S])(g.has(L)||L===A)&&S.delete(L);i.set(m.id,S),d.set(m.id,g);continue}let v=o.has(m.id)?Ir(m.id,o):m.id;o.add(v),s.set(m.id,v);let C=new Map;for(let S of m.children)oe(S,g=>(o.has(g.id)?C.set(g.id,Ir(g.id,o)):o.add(g.id),g.type==="instance"?!1:void 0));i.set(m.id,C),l.push(m)}let f=[],p=e;for(let m of l){let y={...Sh(m,i.get(m.id)??new Map,s,i),id:s.get(m.id)??m.id,component:!0},v=Jo(p,Ne(p)),C={op:"insert",parent:p.root.id,index:p.root.children.length,node:{...y,x:v.x,y:v.y}};f.push(C),p=_e(p,[C]).document}return{ops:f,component:s,keys:i,parts:d}}function Oi(e,t){if(e.type==="instance"){let n=t.keys.get(e.component),r=t.parts?.get(e.component),o=Object.entries(e.overrides??{}).map(([i,d])=>[n===void 0?i:Eh(i,n),d]).filter(([i])=>r===void 0||r.has(i)),s={...e,component:t.component.get(e.component)??e.component,overrides:Object.fromEntries(o),children:[]};return o.length===0&&delete s.overrides,s}return fe(e)?{...e,children:e.children.map(n=>Oi(n,t))}:e}function Sh(e,t,n,r){let o={...e,id:t.get(e.id)??e.id};if(t.size>0)for(let[i,d]of Object.entries(e)){if(!ye(d))continue;let l=$i(d.expr,f=>t.get(f));l&&(o[i]=l)}let s=o;return s.type==="instance"?Oi(s,{component:n,keys:r}):fe(s)?{...s,children:s.children.map(i=>Sh(i,t,n,r))}:s}function Eh(e,t){let n=t.get(e);if(n!==void 0)return n;for(let[r,o]of t)if(e.startsWith(`${r}.`))return`${o}${e.slice(r.length)}`;return e}function Sw(e,t){return Fs({...e,x:0,y:0})===Fs({...t,x:0,y:0})}function Mh(e,t,n,r,o){if(o===0)return en(e,t,n,r);let s=at({x:n,y:r},{x:0,y:0},-o),i=en(e,t,s.x,s.y),d=ct(e),l=ct(i),f={x:d.x-l.x,y:d.y-l.y},p=at(f,{x:0,y:0},o);return{...i,x:i.x+f.x-p.x,y:i.y+f.y-p.y}}function Ch(e,t){return Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI}function Ah(e,t,n,r,o){let s=Ch(e,n)-Ch(e,t);return o?Math.round((r+s)/o)*o-r:s}function $h(e,t,n){return e.map(r=>{let o=ct(r.frame),s=at(o,t,n);return{id:r.id,frame:{...r.frame,x:s.x-r.frame.w/2,y:s.y-r.frame.h/2},rotation:Ro(r.rotation+n)}})}function Oh(e,t,n,r){let o=n.w===0?1:r.w/n.w,s=n.h===0?1:r.h/n.h,i=t*Math.PI/180,d=Math.cos(i),l=Math.sin(i),f=e.w*Math.hypot(o*d,s*l),p=e.h*Math.hypot(o*l,s*d),m=ct(e),y=r.x+(m.x-n.x)*o,v=r.y+(m.y-n.y)*s;return{x:y-f/2,y:v-p/2,w:f,h:p}}function Ge(e,t){return`${e}:${t}`}function Di(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 Th(e){let t=e.split(":"),n=t[2],r=Di(t.slice(0,2).join(":"));if(!(!r||n!=="in"&&n!=="out"))return{...r,side:n}}function ou(e,t){let n=Di(t);return n?e[n.contour]?.anchors[n.index]:void 0}function su(e,t){let n=[];for(let r of t){let o=Di(r);o&&e[o.contour]?.anchors[o.index]&&n.push(Ge(o.contour,o.index))}return n}function iu(e){return e.flatMap((t,n)=>t.anchors.map((r,o)=>Ge(n,o)))}function ru(e,t,n,r){return e.map((o,s)=>s===t?{...o,anchors:o.anchors.map((i,d)=>d===n?r:i)}:o)}var Zo=(e,t,n)=>({x:e.x+t,y:e.y+n});function Pi(e,t,n,r){return e.map((o,s)=>({...o,anchors:o.anchors.map((i,d)=>t.has(Ge(s,d))?Dt(Zo(i,n,r),i.in&&Zo(i.in,n,r),i.out&&Zo(i.out,n,r)):i)}))}function Ti(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,s=Math.hypot(t,n),i=Math.hypot(r,o);return s===0||i===0?!1:(t*r+n*o)/(s*i)<-.995}function Li(e,t,n,r,o,s){let i=e[t]?.anchors[n];if(!i)return[...e];let l=i[r==="in"?"out":"in"];if(s.smooth&&!s.breakSmooth&&l){let p=Math.hypot(l.x-i.x,l.y-i.y),m=o.x-i.x,y=o.y-i.y,v=Math.hypot(m,y);v>0&&(l={x:i.x-m/v*p,y:i.y-y/v*p})}let f=r==="in"?Dt(i,o,l):Dt(i,l,o);return ru(e,t,n,f)}function Lh(e,t){let n=Di(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 ru(e,n.contour,n.index,Dt(o));let s=r.anchors.length,i=n.index>0?r.anchors[n.index-1]:r.closed?r.anchors[s-1]:void 0,d=n.index<s-1?r.anchors[n.index+1]:r.closed?r.anchors[0]:void 0;if(!i&&!d)return[...e];let l=i??o,f=d??o,p=f.x-l.x,m=f.y-l.y,y=Math.hypot(p,m);if(y===0)return[...e];p/=y,m/=y;let v=i?Math.hypot(o.x-i.x,o.y-i.y)/3:0,C=d?Math.hypot(d.x-o.x,d.y-o.y)/3:0,S=i?{x:o.x-p*v,y:o.y-m*v}:void 0,g=d?{x:o.x+p*C,y:o.y+m*C}:void 0;return ru(e,n.contour,n.index,Dt(o,S,g))}function Dh(e,t){let n=[];return e.forEach((r,o)=>{let s=r.anchors.filter((i,d)=>!t.has(Ge(o,d)));s.length>=2&&n.push({closed:r.closed,anchors:s})}),n}function Ph(e,t,n,r,o,s,i){let d=e[t];if(!d)return[...e];let l=d.anchors.length,f=(n+1)%l;if(i)return Pi(e,new Set([Ge(t,n),Ge(t,f)]),o,s);let p=Math.min(.85,Math.max(.15,r)),m=1/(3*(1-p)*p),y=d.anchors[n],v=d.anchors[f],C=Zo(y.out??y,o*m,s*m),S=Zo(v.in??v,o*m,s*m),g=Li(e,t,n,"out",C,{smooth:Ti(y),breakSmooth:!1});return g=Li(g,t,f,"in",S,{smooth:Ti(v),breakSmooth:!1}),g}function Nh(e,t){return e.map((n,r)=>n.closed||n.anchors.length<2?n:t.size===0||t.has(Ge(r,0))&&t.has(Ge(r,n.anchors.length-1))?{...n,closed:!0}:n)}function au(e,t){let n=[],r=new Set,o=(s,i,d)=>{let l=e[s]?.anchors[i],f=l?.[d],p=`${Ge(s,i)}:${d}`;!l||!f||r.has(p)||(r.add(p),n.push({key:p,at:f,anchor:l}))};return e.forEach((s,i)=>{let d=s.anchors.length;s.anchors.forEach((l,f)=>{if(!t.has(Ge(i,f)))return;o(i,f,"in"),o(i,f,"out");let p=f>0?f-1:s.closed?d-1:-1,m=f<d-1?f+1:s.closed?0:-1;p>=0&&o(i,p,"out"),m>=0&&o(i,m,"in")})}),n}function Qo(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),s=n*Math.cos(o)+r*Math.sin(o);return{x:e.x+Math.cos(o)*s,y:e.y+Math.sin(o)*s}}function Ih(e){return{closed:e.closed,anchors:[...e.anchors].reverse().map(t=>Dt(t,t.out,t.in))}}function du(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 Ni(e,t){if(Fh(e))return Mw(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 Ew(n,r,e.type)}finally{n.close()}}async function Ew(e,t,n){let r=Math.max(1,Math.round(e.width*t)),o=Math.max(1,Math.round(e.height*t)),s=document.createElement("canvas");s.width=r,s.height=o;let i=s.getContext("2d");if(!i)return null;i.drawImage(e,0,0,r,o);let d=n==="image/png"?"image/png":"image/webp",l=await new Promise(f=>{s.toBlob(f,d,.9)});return l?{bytes:new Uint8Array(await l.arrayBuffer()),type:l.type||d,width:r,height:o}:null}function Rh(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 Fh(e){return e.type==="image/svg+xml"||/\.svg$/i.test(e.name??"")}var Cw=1024;function Bh(e){let t=/<svg\b[^>]*>/i.exec(e)?.[0];if(t===void 0)return null;let n=f=>new RegExp(`\\s${f}\\s*=\\s*["']([^"']*)["']`,"i").exec(t)?.[1],r=f=>{let p=/^\s*([\d.]+)\s*(px)?\s*$/i.exec(f??""),m=p===null?NaN:Number(p[1]);return m>0?m:void 0},o=r(n("width")),s=r(n("height"));if(o!==void 0&&s!==void 0)return{width:o,height:s};let i=(n("viewBox")??"").trim().split(/[\s,]+/).map(Number),[,,d=NaN,l=NaN]=i;return i.length===4&&d>0&&l>0?o!==void 0?{width:o,height:o*l/d}:s!==void 0?{width:s*d/l,height:s}:{width:d,height:l}:null}async function Mw(e,t){let n=await e.text(),r=Bh(n);if(r===null)return null;let o=Math.min(t,Cw)/Math.max(r.width,r.height),s=Math.max(1,Math.round(r.width*o)),i=Math.max(1,Math.round(r.height*o)),d=n.replace(/<svg\b[^>]*>/i,f=>f.replace(/\s(width|height)\s*=\s*["'][^"']*["']/gi,"").replace(/^<svg/i,`<svg width="${s}" height="${i}"`)),l=URL.createObjectURL(new Blob([d],{type:"image/svg+xml"}));try{let f=new Image;f.src=l,await f.decode();let p=document.createElement("canvas");p.width=s,p.height=i;let m=p.getContext("2d");if(!m)return null;m.drawImage(f,0,0,s,i);let y=await new Promise(v=>{p.toBlob(v,"image/png")});return y?{bytes:new Uint8Array(await y.arrayBuffer()),type:"image/png",width:s,height:i}:null}catch{return null}finally{URL.revokeObjectURL(l)}}function Ii(e){let t=Kt(e);return e.root.children.filter(n=>t.has(n.id)&&Hn(e.motion?.[n.id])).map(n=>n.id)}function Ri(e,t,n){let r=Ii(e);if(r.length===0)return null;let o=yt(e);for(let s of t){let i=o.get(s);if(i!==void 0&&r.includes(i))return i}return n!==null&&r.includes(n)?n:r[0]??null}var Aw=1e3/30;var $w=/\.(?:mp3|m4a|aac|wav|ogg|oga|opus|flac|webm)$/i;function Hh(e){return e.type.startsWith("audio/")||e.type===""&&$w.test(e.name)}var Ow=new Set(["loop","step","together"]);function Uh(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)||Ow.has(o))&&(o=`track-${o}`),e.assets[o]===void 0)return o;for(let s=2;;s+=1)if(e.assets[`${o}-${s}`]===void 0)return`${o}-${s}`}function Vh(e,t,n,r){let o=e.motion?.[t]??{lines:[]},s=o.music,i={asset:n};if(s&&s.asset===n)i=s;else if(s){let d={...s,asset:n};delete d.from,i=d}return[{op:"setAsset",name:n,value:r},{op:"setMotion",page:t,value:{...o,music:i}}]}var Tw={left:"x",hcenter:"x",right:"x",top:"y",vcenter:"y",bottom:"y"};function Fi(e){return Tw[e]}function Lw(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 lu(e,t,n){let r=Fi(n),o=new Map;for(let s of e){let i=r==="x"?s.frame.w:s.frame.h,d=r==="x"?s.frame.x:s.frame.y;o.set(s.id,Lw(n,t,i)-d)}return o}var zh=[{key:"nw",sx:0,sy:0},{key:"ne",sx:1,sy:0},{key:"se",sx:1,sy:1},{key:"sw",sx:0,sy:1}],Dw={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 zh.map(({key:s,sx:i,sy:d})=>({id:`radius:${s}`,at:{x:e.x+(i===0?o:e.w-o),y:e.y+(d===0?o:e.h-o)}}))},valueAt(e,t,n){let r=Nw(t);if(!r)return 0;let o=e.x+(r.sx===0?0:e.w),s=e.y+(r.sy===0?0:e.h),i=Math.max(0,r.sx===0?n.x-o:o-n.x),d=Math.max(0,r.sy===0?n.y-s:s-n.y);return Math.min((i+d)/2,this.max(e))},max(e){return Math.max(0,Math.min(e.w,e.h)/2)}},Pw={canvas:[],frame:[],group:[],rect:[Dw]};function es(e){return Pw[e.type]??[]}function Bi(e,t){let n=t.split(":")[0];return es(e).find(r=>r.id===n)}function Nw(e){let t=e.split(":")[1];return zh.find(n=>n.key===t)}var uu=[["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 fu=[["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 cu=[["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 pu=[["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 mu=[["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 hu=[["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 xu=[["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 gu=[["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 yu=[["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 vu=[["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 bu=[["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 wu=[["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 ku=[["circle",{cx:"15",cy:"9",r:"7"}],["circle",{cx:"9",cy:"15",r:"7"}]];var _u=[["path",{d:"M20 6 9 17l-5-5"}]];var Su=[["path",{d:"m6 9 6 6 6-6"}]];var Eu=[["path",{d:"m9 18 6-6-6-6"}]];var Cu=[["circle",{cx:"12",cy:"12",r:"10"}]];var Mu=[["path",{d:"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z"}],["path",{d:"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z"}],["path",{d:"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z"}],["path",{d:"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z"}]];var Au=[["path",{d:"M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41l-7.59-7.59a2.41 2.41 0 0 0-3.41 0Z"}]];var $u=[["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 Ou=[["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 Tu=[["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 Lu=[["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 Du=[["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 Pu=[["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 Nu=[["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 Iu=[["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 Hi=[["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 Ru=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}]];var Fu=[["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 Bu=[["path",{d:"M5 12h14"}]];var Hu=[["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 Uu=[["path",{d:"m18 8 4 4-4 4"}],["path",{d:"M2 12h20"}],["path",{d:"m6 8-4 4 4 4"}]];var Vu=[["path",{d:"M12 2v20"}],["path",{d:"m8 18 4 4 4-4"}],["path",{d:"m8 6 4-4 4 4"}]];var zu=[["path",{d:"M9 18V5l12-2v13"}],["circle",{cx:"6",cy:"18",r:"3"}],["circle",{cx:"18",cy:"16",r:"3"}]];var ju=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"}]];var Ku=[["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 Gu=[["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 qu=[["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 Wu=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];var Xu=[["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 Yu=[["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 Ju=[["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 Zu=[["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 Qu=[["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 ef=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];var Ui=[["path",{d:"M21 5H3"}],["path",{d:"M21 12H9"}],["path",{d:"M21 19H7"}]];var Vi=[["path",{d:"M21 5H3"}],["path",{d:"M17 12H7"}],["path",{d:"M19 19H5"}]];var zi=[["path",{d:"M3 5h18"}],["path",{d:"M3 12h18"}],["path",{d:"M3 19h18"}]];var ts=[["path",{d:"M21 5H3"}],["path",{d:"M15 12H3"}],["path",{d:"M17 19H3"}]];var tf=[["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 nf=[["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 rf=[["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 of=[["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 sf=[["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 af=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var ns=e=>e.replace(/\b(?:CmdOrCtrl|CommandOrControl)\b/g,"Ctrl");function jh(e,t){let r=e.ownerDocument.createElement("div");r.className="vd-chrome",r.setAttribute("role","toolbar"),r.setAttribute("aria-label","Canvas tools"),r.innerHTML=Iw(t),e.appendChild(r);let o=new Map;for(let p of r.querySelectorAll("[data-tool]"))o.set(p.dataset.tool,p);let s=r.querySelector('[data-act="undo"]'),i=r.querySelector('[data-act="redo"]'),d=r.querySelector('[data-act="zoom"]'),l=p=>{let m=p.target?.closest("button");if(!m)return;p.stopPropagation();let y=m.dataset.tool;if(y){t.onTool(y);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=p=>p.stopPropagation();return r.addEventListener("click",l),r.addEventListener("pointerdown",f),{element:r,setTool(p){for(let[m,y]of o)y.setAttribute("aria-pressed",String(m===p))},setHistory(p,m){s&&(s.disabled=!p),i&&(i.disabled=!m)},setZoom(p){d&&(d.textContent=`${Math.round(p*100)}%`)},destroy(){r.removeEventListener("click",l),r.removeEventListener("pointerdown",f),r.remove()}}}function Iw(e){let t=e.formatKeys??ns;return[nn({tool:"select",label:"Select",hint:"V",icon:"select"}),nn({tool:"frame",label:"Frame",hint:"F",icon:"frame"}),nn({tool:"rect",label:"Rectangle",hint:"R",icon:"rect"}),nn({tool:"ellipse",label:"Ellipse",hint:"O",icon:"ellipse"}),nn({tool:"pen",label:"Pen",hint:"P",icon:"pen"}),nn({tool:"text",label:"Text",hint:"T",icon:"text"}),'<span class="vd-chrome__divider"></span>',nn({act:"undo",label:"Undo",hint:t("CmdOrCtrl+Z"),icon:"undo"}),nn({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>',nn({act:"play",label:"Play",hint:e.playHint,icon:"play"})]:[]].join("")}function nn(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}">`+rt(e.icon)+"</button>"}var Rw={select:Hu,frame:Du,rect:ef,ellipse:Cu,pen:Ku,vector:Zu,text:tf,undo:nf,redo:Xu,"align-left":gu,"align-hcenter":cu,"align-right":mu,"align-top":xu,"align-vcenter":fu,"align-bottom":pu,"distribute-h":hu,"distribute-v":yu,group:Pu,component:Mu,instance:Au,image:Nu,eye:Ou,"eye-off":Tu,lock:Ru,unlock:Hi,chevron:Eu,"text-left":ts,"text-center":Vi,"text-right":Ui,"text-justify":zi,"text-top":wu,"text-middle":vu,"text-bottom":bu,unlink:rf,rotate:Yu,opacity:$u,radius:Qu,blend:ku,plus:Wu,minus:Bu,close:af,"chevron-down":Su,check:_u,link:Iu,"font-size":uu,"line-height":Vu,"letter-spacing":Uu,eyedropper:Gu,document:Lu,play:qu,pause:ju,scan:Ju,music:zu,metronome:Fu,sound:of,"sound-off":sf};function rt(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">${Rw[e].map(([n,r])=>{let o=Object.entries(r).filter(([s])=>s!=="key").map(([s,i])=>` ${s}="${String(i)}"`).join("");return`<${n}${o} vector-effect="non-scaling-stroke"/>`}).join("")}</svg>`}var df="clipboard";function rs(e,t){let n=new Set(t),r=[];return oe(e.root,o=>{if(o.id!==e.root.id&&n.has(o.id))return r.push(o),!1}),r}function Kh(e,t){let n={};for(let s of e)oe(s,i=>{for(let[d,l]of Object.entries(i)){if(ye(l)){let f=pt(l.expr);if(!f.ok)continue;for(let p of Zt(f.ast).tokens){let m=t[p];m!==void 0&&(n[p]=m)}continue}typeof l=="string"&&o(l),d==="shadow"&&typeof l=="string"&&r(l)}for(let d of qh(i.content))o(d)});return n;function r(s){let i=t[s],l=Mr(typeof i=="string"?i:s);if(!("error"in l))for(let f of l.shadows)o(f.colour)}function o(s){for(let i of si(s)){let d=t[i];if(d!==void 0&&(n[i]=d,!(typeof d!="string"||d===s)))for(let l of si(d)){let f=t[l];f!==void 0&&l!==i&&(n[l]=f)}}}}function Fw(e,t){let n={};for(let r of e)oe(r,o=>{if(o.type!=="image"||typeof o.src!="string")return;let s=t[o.src];s!==void 0&&(n[o.src]=s)});return n}function Gh(e,t){let n={},r=o=>{if(typeof o!="string")return;let s=t[o];s!==void 0&&(n[o]=s)};for(let o of e)oe(o,s=>{let i=s;r(i.font);for(let d of qh(i.content,"font"))r(d)});return n}function qh(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 lf(e,t,n){let r=rs(e,t);if(r.length===0)return null;let o=Bw(e,r),s=[...r,...o],i={};for(let f of r)oe(f,p=>{let m=n.nodes.get(p.id)?.values;m&&Object.keys(m).length>0&&(i[p.id]=m)});let d={version:e.version,kind:e.kind,tokens:Kh(s,e.tokens),fonts:Gh(s,e.fonts),assets:Fw(s,e.assets),root:{...e.root,children:s}},l=JSON.parse(yd(d));return l[df]={resolved:i,...o.length===0?{}:{components:o.map(f=>f.id)}},JSON.stringify(l,null,2)}function Bw(e,t){let n=Ye(e.root),r=new Set(t.map(i=>i.id)),o=new Map,s=i=>{oe(i,d=>{if(d.type!=="instance")return;let l=n.get(d.component);return l&&!r.has(l.id)&&!o.has(l.id)&&(o.set(l.id,l),s(l)),!1})};return t.forEach(s),[...o.values()]}function uf(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}=el(t),o=n[df],s=typeof o=="object"&&o!==null?o:{},i=s.resolved??{},d=Array.isArray(s.components)?new Set(s.components.filter(p=>typeof p=="string")):new Set,l=r.root.children.filter(p=>p.type==="frame"&&d.has(p.id)),f=r.root.children.filter(p=>!d.has(p.id));return f.length===0?null:{nodes:f,...l.length===0?{}:{components:l},tokens:r.tokens,fonts:r.fonts,resolved:typeof i=="object"&&i!==null?i:{}}}function ff(e,t){let n=xn(t.root),r=new Map;for(let i of e.nodes)oe(i,d=>{let l=Hw(d.id,n);return n.add(l),r.set(d.id,l),d.type==="instance"?!1:void 0});let o=i=>n.has(i),s={...e.tokens,...t.tokens};return{nodes:e.nodes.map(i=>Wh(i,{payload:e,remap:r,exists:o,tokens:s})),remap:r}}function Hw(e,t){let n=e.lastIndexOf("."),r=n===-1?"":e.slice(n+1),o=/^[0-9]+$/.test(r)?e.slice(0,n):e,s=1;for(let i of t){if(!i.startsWith(`${o}.`))continue;let d=Number(i.slice(o.length+1));Number.isInteger(d)&&d>=s&&(s=d+1)}return`${o}.${s}`}function Wh(e,t){let n=e,r={};for(let[o,s]of Object.entries(n))o==="id"||o==="children"||(r[o]=ye(s)?Uw(s.expr,e.id,o,t):s);return r.id=t.remap.get(e.id)??e.id,e.type==="instance"?r.children=[]:fe(e)&&(r.children=ne(e).map(o=>Wh(o,t))),r}function Uw(e,t,n,r){let o={expr:e},s=pt(e);if(!s.ok)return o;let i=Zt(s.ast).nodes.some(p=>r.remap.has(p)),d=i?Nt(s.ast,p=>r.remap.get(p)):s.ast,l=Zt(d);if(l.nodes.some(p=>!r.exists(p))||l.tokens.some(p=>r.tokens[p]===void 0)){let p=r.payload.resolved[t]?.[n];return p===void 0?o:p}return i?{expr:Gn(d)}:o}var rn="#ffffff",kn="#0b0d0c",Qh="#c6ff3d",Vw="#ffb224";var Xh=new Map;function qe(e,t={}){let n=t.badge??"none",r=e==="resize"?ex(t.angle??0):e==="rotate"?jw(t.angle??0):0,o=`${e}:${r}:${n}`,s=Xh.get(o);if(s!==void 0)return s;let{at:i,fallback:d}=zw[e],l=qw(Kw(e,r,n),i[0],i[1],d);return Xh.set(o,l),l}var Yh=[2,2],Rr=[12,12],zw={arrow:{at:Yh,fallback:"default"},radius:{at:Yh,fallback:"default"},resize:{at:Rr,fallback:"ew-resize"},rotate:{at:Rr,fallback:"crosshair"},crosshair:{at:Rr,fallback:"crosshair"},grab:{at:Rr,fallback:"grab"},grabbing:{at:Rr,fallback:"grabbing"},text:{at:Rr,fallback:"text"}};function jw(e){let t=(e%360+360)%360;return Math.round(t/15)*15%360}function ex(e){let t=(e%180+180)%180;return Math.round(t/15)*15%180}function Kw(e,t,n){switch(e){case"arrow":return tx(n);case"resize":return Ww(t,n);case"rotate":return Xw(t);case"crosshair":return Jw();case"grab":return Zh(!1);case"grabbing":return Zh(!0);case"radius":return Zw(n);case"text":return Yw()}}function Gw(e){return`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">${e}</svg>`}function qw(e,t,n,r){return`url("data:image/svg+xml,${encodeURIComponent(Gw(e))}") ${t} ${n}, ${r}`}var Jh="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 tx(e){return`<path d="${Jh}" fill="${rn}" stroke="${rn}" stroke-width="3" stroke-linejoin="round"/><path d="${Jh}" fill="${kn}"/>`+nx(e)}function Ww(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,s)=>n.map(i=>`<path d="${i}" stroke="${s}" stroke-width="${o}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+r(3.6,rn)+r(1.6,kn)+"</g>"+nx(t)}function Xw(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(s=>`<path d="${s}" stroke="${o}" stroke-width="${r}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+n(3.6,rn)+n(1.6,kn)+"</g>"}function Yw(){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,rn)+t(1.5,kn)+"</g>"}function Jw(){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="${rn}" stroke-width="3"/><path d="${e}" stroke="${kn}" stroke-width="1.2"/></g>`}function Zh(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="${rn}" stroke-width="3.4"/><path d="${t}" stroke="${kn}" stroke-width="1.5"/></g>`}function Zw(e){return tx("none")+Qw(e)}function Qw(e){return`<g><rect x="17.5" y="17.5" width="14" height="14" rx="4.5" fill="${rn}"/><rect x="18.7" y="18.7" width="11.6" height="11.6" rx="3.4" fill="${e==="none"?Qh:Vw}"/><path d="M21.6 27.9 V25.4 A3.8 3.8 0 0 1 25.4 21.6 H27.9" fill="none" stroke="${kn}" stroke-width="1.5" stroke-linecap="round"/></g>`}function nx(e){return e==="none"?"":`<g><rect x="18.5" y="18.5" width="13" height="13" rx="4" fill="${rn}"/><rect x="19.6" y="19.6" width="10.8" height="10.8" rx="3" fill="${Qh}"/><text x="25" y="28.4" text-anchor="middle" fill="${kn}" font-family="ui-sans-serif, system-ui, -apple-system, Helvetica, sans-serif" font-size="10" font-weight="700">${e==="token"?"$":"\u0192"}</text></g>`}var cf=6,on=.01,mt={dx:0,dy:0,guides:[],measures:[]},ji=["lo","mid","hi"];function pf(e,t,n){let r=[],o=(s,i)=>{let d=t.nodes.get(s);d&&r.push({id:s,frame:Wo(d),isPage:i})};return e.root.w!==void 0&&e.root.h!==void 0&&o(e.root.id,!0),oe(e.root,s=>{if(n.has(s.id)||"hidden"in s&&s.hidden===!0)return!1;if(s.id!==e.root.id){if(s.type==="instance"){o(s.id,!1);return}if(s.type==="frame"){o(s.id,!0);return}fe(s)||o(s.id,!1)}}),r}function mf(e,t,n){if(n<=0||t.length===0)return mt;let r=Fr("x",e,t,n,ji,!0),o=Fr("y",e,t,n,ji,!0);return xf(e,t,r,o)}function Ki(e,t,n,r){if(r<=0||n.length===0)return mt;let o=t.includes("w")?["lo"]:t.includes("e")?["hi"]:[],s=t.includes("n")?["lo"]:t.includes("s")?["hi"]:[],i=Fr("x",e,n,r,o,!1),d=Fr("y",e,n,r,s,!1);return xf(e,n,i,d)}function hf(e,t,n){let r={x:e.x,y:e.y,w:0,h:0};if(n<=0||t.length===0)return mt;let o=Fr("x",r,t,n,["lo"],!1),s=Fr("y",r,t,n,["lo"],!1);return xf(r,t,o,s)}function Fr(e,t,n,r,o,s){let i={axis:e,delta:0,kind:"none"};if(o.length===0)return i;let d=ek(e,t,n,r,o),l=s?nk(e,t,n,r):null;return d&&l?Math.abs(l.delta)<Math.abs(d.delta)-on?{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}:i}function ek(e,t,n,r,o){let s=null;for(let i of n)for(let d of ji){let l=ke(i.frame,e,d);for(let f of o){let p=l-ke(t,e,f);if(Math.abs(p)>r)continue;let m=f==="mid"&&d==="mid";(s===null||tk(p,m,s))&&(s={at:l,delta:p,centred:m})}}return s?{at:s.at,delta:s.delta}:null}function tk(e,t,n){let r=Math.abs(e),o=Math.abs(n.delta);return r<o-on?!0:r>o+on?!1:t&&!n.centred}function nk(e,t,n,r){let o=rx(e,t,n);if(o.length<2)return null;let s=ox(t,e),i=ke(t,e,"lo"),d=[];for(let f of rk(o,e))for(let p of o)d.push({delta:ke(p,e,"hi")+f-i,gap:f}),d.push({delta:ke(p,e,"lo")-f-s-i,gap:f});for(let f=0;f+1<o.length;f+=1){let p=o[f],m=o[f+1];if(!p||!m)continue;let y=ke(m,e,"lo")-ke(p,e,"hi")-s;y<=on||d.push({delta:ke(p,e,"hi")+y/2-i,gap:y/2})}let l=null;for(let f of d)Math.abs(f.delta)>r||(l===null||Math.abs(f.delta)<Math.abs(l.delta)-on)&&(l=f);return l}function rx(e,t,n){let r=gf(e);return n.filter(o=>!o.isPage&&ik(o.frame,t,r)).map(o=>o.frame).sort((o,s)=>ke(o,e,"lo")-ke(s,e,"lo"))}function rk(e,t){let n=[];for(let r=0;r+1<e.length;r+=1){let o=e[r],s=e[r+1];if(!o||!s)continue;let i=ke(s,t,"lo")-ke(o,t,"hi");i<=on||n.some(d=>Math.abs(d-i)<on)||n.push(i)}return n}function xf(e,t,n,r){let o={...e,x:e.x+n.delta,y:e.y+r.delta},s=[],i=[];for(let d of[n,r]){if(d.kind==="align"&&d.at!==void 0){let l=ok(d.axis,d.at,o,t);l&&s.push(l)}d.kind==="space"&&d.gap!==void 0&&i.push(...sk(d.axis,d.gap,o,t))}return{dx:n.delta,dy:r.delta,guides:s,measures:i}}function ok(e,t,n,r){let o=gf(e),s=ke(n,o,"lo"),i=ke(n,o,"hi"),d=!1;for(let l of r)ji.some(f=>ak(ke(l.frame,e,f),t))&&(d=!0,s=Math.min(s,ke(l.frame,o,"lo")),i=Math.max(i,ke(l.frame,o,"hi")));return d?{axis:e,at:t,from:s,to:i}:null}function sk(e,t,n,r){let o=gf(e),s=[...rx(e,n,r),n].sort((d,l)=>ke(d,e,"lo")-ke(l,e,"lo")),i=[];for(let d=0;d+1<s.length;d+=1){let l=s[d],f=s[d+1];if(!l||!f)continue;let p=ke(f,e,"lo")-ke(l,e,"hi");if(Math.abs(p-t)>on)continue;let m=Math.max(ke(l,o,"lo"),ke(f,o,"lo")),y=Math.min(ke(l,o,"hi"),ke(f,o,"hi"));i.push({axis:e,at:(m+y)/2,from:ke(l,e,"hi"),to:ke(f,e,"lo"),label:dk(p)})}return i}function gf(e){return e==="x"?"y":"x"}function ox(e,t){return t==="x"?e.w:e.h}function ke(e,t,n){let r=t==="x"?e.x:e.y,o=ox(e,t);return n==="lo"?r:n==="hi"?r+o:r+o/2}function ik(e,t,n){return ke(e,n,"lo")<ke(t,n,"hi")&&ke(e,n,"hi")>ke(t,n,"lo")}function ak(e,t){return Math.abs(e-t)<on}function dk(e){return String(Math.round(e*100)/100)}var os=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 sx=1,lk=48,uk=.06,fk=.5;function ix(e){return Math.max(lk,Math.min(e.width,e.height)*uk)}function yf(e,t){let n=new Set(t),r=[];for(let o of e.root.children)(n.has(o.id)||ax(o,n))&&r.push(o.id);return r}function ax(e,t){for(let n of ne(e))if(t.has(n.id)||ax(n,t))return!0;return!1}function Gi(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)),s=Math.max(...t.map(i=>i.y+i.h));return{x:n,y:r,w:o-n,h:s-r}}function qi(e,t){let n=ix(t),r={width:Math.max(1,t.width-n*2),height:Math.max(1,t.height-n*2)},o=Or(Math.min(r.width/e.w,r.height/e.h,sx));return{zoom:o,x:t.width/2-(e.x+e.w/2)*o,y:t.height/2-(e.y+e.h/2)*o}}function vf(e,t,n){let r=qi(e,t);return ck(e,t,n)&&n.zoom>=r.zoom*fk?null:r}function ck(e,t,n){let r=e.x*n.zoom+n.x,o=e.y*n.zoom+n.y,s=(e.x+e.w)*n.zoom+n.x,i=(e.y+e.h)*n.zoom+n.y;return r>=0&&o>=0&&s<=t.width&&i<=t.height}function dx(e,t,n,r){let o=Math.exp(Math.log(e.zoom)+(Math.log(t.zoom)-Math.log(e.zoom))*n),s={x:r.width/2,y:r.height/2},i={x:(s.x-e.x)/e.zoom,y:(s.y-e.y)/e.zoom},d={x:(s.x-t.x)/t.zoom,y:(s.y-t.y)/t.zoom},l={x:i.x+(d.x-i.x)*n,y:i.y+(d.y-i.y)*n};return{zoom:o,x:s.x-l.x*o,y:s.y-l.y*o}}function lx(e){return 1-(1-e)**3}function pk(e){return!("separator"in e)}function bf(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"},...ux(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}),r.push(...mk(e.components));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 s of e.bound)r.push({id:`detach:${s.prop}`,label:`Detach ${s.prop}`,hint:s.source})}return r.push(...ux(e)),r.push(...n),r.push({separator:!0},{id:"delete",label:hk(e),keys:"Delete"}),r}function mk(e){if(!e)return[];let t=[];return e.create&&t.push({id:"createComponent",label:"Create component",keys:"CmdOrCtrl+Alt+K"}),e.instance&&t.push({id:"goToComponent",label:"Go to component"},{id:"resetOverrides",label:"Reset overrides",disabled:e.overrides===0},{id:"detachInstance",label:"Detach instance",keys:"CmdOrCtrl+Alt+B"}),e.part&&t.push({id:"goToComponent",label:"Go to component"},{id:"resetOverrides",label:"Reset this part",disabled:e.overrides===0}),e.component&&t.push({id:"placeInstance",label:"Place instance"}),t.length===0?[]:[{separator:!0},...t]}function hk(e){let t=e.components;return t?.part?"Hide on this instance":t&&t.uses>0?`Delete and detach ${t.uses} ${t.uses===1?"use":"uses"}`:"Delete"}var xk=4;function ux(e){let t=(e.locksHere??[]).slice(0,xk).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 Wi(e,t){let n=e.ownerDocument,r=t.formatKeys??ns,o=n.createElement("div");o.className="vd-menu",o.setAttribute("role","menu"),o.hidden=!0,e.appendChild(o);let s=!1,i=[],d=-1;function l(g){o.replaceChildren(),i=[];for(let L of g){if(!pk(L)){let j=n.createElement("div");j.className="vd-menu__separator",o.appendChild(j);continue}let A=n.createElement("button");A.type="button",A.className="vd-menu__item",A.dataset.command=L.id,A.disabled=L.disabled===!0,A.setAttribute("role","menuitem");let I=n.createElement("span");I.textContent=L.label,A.appendChild(I);let U=L.hint??(L.keys===void 0?void 0:r(L.keys));if(U!==void 0){let j=n.createElement("span");j.className="vd-menu__hint",j.textContent=U,A.appendChild(j)}o.appendChild(A),A.disabled||i.push(A)}}function f(g){o.style.left=`${g.x}px`,o.style.top=`${g.y}px`;let L=e.getBoundingClientRect(),A=t.bounds?.()??L,I=o.getBoundingClientRect();if(I.width===0&&I.height===0)return;let U=L.left+g.x+I.width-A.right,j=L.top+g.y+I.height-A.bottom;U>0&&(o.style.left=`${Math.max(A.left-L.left,g.x-I.width)}px`),j>0&&(o.style.top=`${Math.max(A.top-L.top,g.y-I.height)}px`)}function p(g){i.length!==0&&(d=(g+i.length)%i.length,i[d]?.focus())}let m=g=>{let L=g.target?.closest("button");if(!L||L.disabled)return;g.stopPropagation();let A=L.dataset.command;S(),A&&t.onCommand(A)},y=g=>g.stopPropagation(),v=g=>{g.key==="ArrowDown"?(g.preventDefault(),p(d+1)):g.key==="ArrowUp"?(g.preventDefault(),p(d-1)):g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),S(),t.returnFocus?t.returnFocus():e.focus())},C=g=>{s&&(g.target instanceof Node&&o.contains(g.target)||S())};function S(){s&&(s=!1,d=-1,o.hidden=!0,n.removeEventListener("pointerdown",C,!0),n.removeEventListener("wheel",C,!0))}return o.addEventListener("click",m),o.addEventListener("pointerdown",y),o.addEventListener("keydown",v),{element:o,get isOpen(){return s},open(g,L){l(L),o.hidden=!1,s=!0,f(g),n.addEventListener("pointerdown",C,!0),n.addEventListener("wheel",C,!0),p(0)},close:S,destroy(){S(),o.removeEventListener("click",m),o.removeEventListener("pointerdown",y),o.removeEventListener("keydown",v),o.remove()}}}var Br=2,fx=1.5,cx=1.5,px=1.5,kx={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},mx=3.6,gk=22,Xi=14,Yi=15,wf=4,hx=15,xx=23,ss=7,yk=3.5,Ji=12,vk=4.5,Zi=16,ht=18,kf=9,_f=6.1,gx="Drop or double-click",bk=6.4,yx=16,_n=3,vx=5,wk=11,bx=6,wx=6.4;function _x(e,t){let n=e.ownerDocument,r=n.createElementNS(ve,"svg");r.setAttribute("class","vd-editor__overlay"),e.appendChild(r);let o=[],s=[],i=[],d=[],l=[],f=null,p=null,m=[],y=[];function v(E){let k=t({x:E.x,y:E.y}),O=t({x:E.x+E.w,y:E.y+E.h});return{x:k.x,y:k.y,w:O.x-k.x,h:O.y-k.y}}function C(E){for(;r.firstChild;)r.removeChild(r.firstChild);o=[],s=[],i=[],d=[],l=[],f=null,p=null,m=[],y=(E.pageLabels??[]).flatMap(O=>b(O));let k=E.turn&&E.turn.angle!==0?{angle:E.turn.angle,centre:t(E.turn.centre)}:null;for(let O of E.slots??[])T(O);E.presence&&G(E.presence);for(let O of E.highlight)Y("vd-editor__highlight",Ur(v(O),Br),Br);E.lockHint&&D(E.lockHint),E.hover&&Y("vd-editor__hover",Hr(v(E.hover)),cx);for(let O of E.parked)Y("vd-editor__parked",Hr(v(O)),cx);for(let O of E.members)Y("vd-editor__member",Ur(v(O),fx),fx);E.lead&&Y("vd-editor__lead",Hr(v(E.lead)),Br);for(let O of E.guides)q(O);for(let O of E.measures)$(O);if(S(k,()=>{for(let O of E.textSelection)r.appendChild(re("vd-editor__text-selection",v(O)))}),E.box&&j(E.box),E.caret&&S(k,()=>A(E.caret)),d=E.rings.map(I),i=E.spacers.map(U),E.badge&&E.box){let O=v(E.box.frame),P=f?Math.max(...[{x:O.x,y:O.y},{x:O.x+O.w,y:O.y},{x:O.x,y:O.y+O.h},{x:O.x+O.w,y:O.y+O.h}].map(K=>at(K,f.centre,f.angle).y)):O.y+O.h;V(E.badge,{x:O.x+O.w/2,y:P+kf+ht/2})}if(E.draft){let O=v(E.draft);if(E.draftEllipse){let P=n.createElementNS(ve,"ellipse");P.setAttribute("class","vd-editor__draft"),P.setAttribute("cx",String(O.x+O.w/2)),P.setAttribute("cy",String(O.y+O.h/2)),P.setAttribute("rx",String(Math.abs(O.w)/2)),P.setAttribute("ry",String(Math.abs(O.h)/2)),r.appendChild(P)}else r.appendChild(re("vd-editor__draft",O))}E.marquee&&r.appendChild(re("vd-editor__marquee",v(E.marquee))),E.path&&(p=k,S(k,()=>L(E.path)))}function S(E,k){if(!E){k();return}let O=r.childNodes.length;k();let P=n.createElementNS(ve,"g");for(P.setAttribute("transform",`rotate(${E.angle} ${E.centre.x} ${E.centre.y})`);r.childNodes.length>O;)P.insertBefore(r.childNodes[r.childNodes.length-1],P.firstChild);r.appendChild(P)}function g(E,k){return k?at(E,k.centre,-k.angle):E}function L(E){let k=n.createElementNS(ve,"path");if(k.setAttribute("class","vd-editor__path"),k.setAttribute("d",Gt(qt(E.contours,t))),r.appendChild(k),E.pending){let P=t(E.pending.from),K=t(E.pending.to),Z=E.pending.c1?t(E.pending.c1):P,z=n.createElementNS(ve,"path");z.setAttribute("class","vd-editor__pending"),z.setAttribute("d",`M${P.x} ${P.y} C${Z.x} ${Z.y} ${K.x} ${K.y} ${K.x} ${K.y}`),r.appendChild(z)}for(let P of E.handles){let K=t(P.at),Z=t(P.anchor),z=n.createElementNS(ve,"line");z.setAttribute("class","vd-editor__arm"),z.setAttribute("x1",String(Z.x)),z.setAttribute("y1",String(Z.y)),z.setAttribute("x2",String(K.x)),z.setAttribute("y2",String(K.y)),r.appendChild(z)}for(let P of E.handles){let K=t(P.at),Z=n.createElementNS(ve,"circle");Z.setAttribute("class","vd-editor__knob"),Z.setAttribute("cx",String(K.x)),Z.setAttribute("cy",String(K.y)),Z.setAttribute("r",String(yk)),r.appendChild(Z)}for(let P of E.anchors){let K=t(P.at),Z=re(P.selected?"vd-editor__anchor vd-editor__anchor--on":"vd-editor__anchor",{x:Math.round(K.x-ss/2)+.5,y:Math.round(K.y-ss/2)+.5,w:ss,h:ss});Z.setAttribute("data-key",P.key),r.appendChild(Z)}if(E.closeAt){let P=t(E.closeAt),K=n.createElementNS(ve,"circle");K.setAttribute("class","vd-editor__close"),K.setAttribute("cx",String(P.x)),K.setAttribute("cy",String(P.y)),K.setAttribute("r",String(ss)),r.appendChild(K)}let O=P=>({x:P.x-Ji/2,y:P.y-Ji/2,w:Ji,h:Ji});l=[...[...E.handles].reverse().map(P=>({kind:"handle",key:P.key,rect:O(t(P.at))})),...[...E.anchors].reverse().map(P=>({kind:"anchor",key:P.key,rect:O(t(P.at))}))]}function A(E){let k=t({x:E.x,y:E.y}),O=t({x:E.x,y:E.y+E.h}),P=n.createElementNS(ve,"line");P.setAttribute("class","vd-editor__caret");let K=Math.round(k.x)+.5;P.setAttribute("x1",String(K)),P.setAttribute("y1",String(k.y)),P.setAttribute("x2",String(K)),P.setAttribute("y2",String(O.y)),E.fill!==void 0&&!E.fill.startsWith("url(")&&(P.style.stroke=E.fill),r.appendChild(P)}function I(E){let k=t(E.at),O=n.createElementNS(ve,"circle");return O.setAttribute("class","vd-editor__ring"),O.setAttribute("cx",String(k.x)),O.setAttribute("cy",String(k.y)),O.setAttribute("r",String(vk)),r.appendChild(O),{id:E.id,rect:{x:k.x-Zi/2,y:k.y-Zi/2,w:Zi,h:Zi}}}function U(E){let k=t(E.at),O=E.axis==="x"?wf:Yi,P=E.axis==="x"?Yi:wf,K=re("vd-editor__spacer",{x:k.x-O/2,y:k.y-P/2,w:O,h:P});K.setAttribute("rx",String(wf/2)),r.appendChild(K),E.label!==null&&V(E.label,E.axis==="x"?{x:k.x,y:k.y-Yi/2-kf-ht/2}:{x:k.x+Yi/2+kf+ht,y:k.y});let Z=E.axis==="x"?hx:xx,z=E.axis==="x"?xx:hx;return{id:E.id,rect:{x:k.x-Z/2,y:k.y-z/2,w:Z,h:z}}}function j(E){let k=v(E.frame),O=E.rotation??0;f=O===0?null:{angle:O,centre:{x:k.x+k.w/2,y:k.y+k.h/2}},S(f,()=>R(E,k)),E.handles&&E.rotatable&&(m=qo.map(P=>{let{u:K,v:Z}=Tr(P);return{handle:P,at:{x:k.x+k.w*K,y:k.y+k.h*Z}}}))}function R(E,k){if(Y("vd-editor__outline",Ur(k,Br),Br),!!E.handles){o=Kl(k).map(O=>({...O,bound:E.boundHandles.has(O.handle)}));for(let O of qo){let{u:P,v:K}=Tr(O),Z={x:k.x+k.w*P-Lr/2,y:k.y+k.h*K-Lr/2,w:Lr,h:Lr};r.appendChild(re("vd-editor__halo",Ur(Z,px+1))),r.appendChild(re("vd-editor__handle",Z))}s=E.adjusters.map(O=>{let P=t(O.at),K=n.createElementNS(ve,"circle");K.setAttribute("class","vd-editor__halo"),K.setAttribute("cx",String(P.x)),K.setAttribute("cy",String(P.y)),K.setAttribute("r",String(mx+px/2+.5)),r.appendChild(K);let Z=n.createElementNS(ve,"circle");return Z.setAttribute("class","vd-editor__adjuster"),Z.setAttribute("cx",String(P.x)),Z.setAttribute("cy",String(P.y)),Z.setAttribute("r",String(mx)),r.appendChild(Z),{id:O.id,bound:O.bound,rect:{x:P.x-Xi/2,y:P.y-Xi/2,w:Xi,h:Xi}}})}}function q(E){let k=t(E.axis==="x"?{x:E.at,y:E.from}:{x:E.from,y:E.at}),O=t(E.axis==="x"?{x:E.at,y:E.to}:{x:E.to,y:E.at}),P=n.createElementNS(ve,"line");P.setAttribute("class","vd-editor__guide"),P.setAttribute("x1",String(Le(k.x))),P.setAttribute("y1",String(Le(k.y))),P.setAttribute("x2",String(Le(O.x))),P.setAttribute("y2",String(Le(O.y))),r.appendChild(P)}function $(E){let k=t(E.axis==="x"?{x:E.from,y:E.at}:{x:E.at,y:E.from}),O=t(E.axis==="x"?{x:E.to,y:E.at}:{x:E.at,y:E.to}),P=n.createElementNS(ve,"path");P.setAttribute("class","vd-editor__measure"),P.setAttribute("d",E.axis==="x"?`M${Le(k.x)} ${Le(k.y)-_n} V${Le(k.y)+_n} M${Le(k.x)} ${Le(k.y)} H${Le(O.x)} M${Le(O.x)} ${Le(O.y)-_n} V${Le(O.y)+_n}`:`M${Le(k.x)-_n} ${Le(k.y)} H${Le(k.x)+_n} M${Le(k.x)} ${Le(k.y)} V${Le(O.y)} M${Le(O.x)-_n} ${Le(O.y)} H${Le(O.x)+_n}`),r.appendChild(P);let K=n.createElementNS(ve,"text");K.setAttribute("class","vd-editor__measure-text"),K.setAttribute("x",String((k.x+O.x)/2)),K.setAttribute("y",String((k.y+O.y)/2-(E.axis==="x"?vx:0))),E.axis==="y"&&K.setAttribute("dx",String(vx)),K.textContent=E.label,r.appendChild(K)}function V(E,k){let O=Math.max(34,E.length*_f+14),P=k.x-O/2,K=k.y-ht/2,Z=re("vd-editor__badge",{x:P,y:K,w:O,h:ht});Z.setAttribute("rx",String(ht/2)),r.appendChild(Z);let z=n.createElementNS(ve,"text");z.setAttribute("class","vd-editor__badge-text"),z.setAttribute("x",String(P+O/2)),z.setAttribute("y",String(K+ht/2)),z.textContent=E,r.appendChild(z)}function b(E){let k=v(E.frame),O=Math.floor(k.w/wx);if(O<3)return[];let P=E.label.length>O?`${E.label.slice(0,O-1)}\u2026`:E.label;E.component&&r.appendChild(re("vd-editor__component-outline",Hr(k)));let K=n.createElementNS(ve,"text");K.setAttribute("class",`vd-editor__page-label vd-editor__page-label--${E.state}${E.component?" vd-editor__page-label--component":""}`),K.setAttribute("x",String(k.x)),K.setAttribute("y",String(k.y-bx)),K.textContent=P,r.appendChild(K);let Z=Math.min(k.w,P.length*wx+4),z=wk+6;return[{id:E.id,rect:{x:k.x,y:k.y-bx-z+3,w:Z,h:z}}]}function D(E){let k=Hr(v(E.frame));r.appendChild(re("vd-editor__lock",k));let O=`${E.label} \xB7 locked`,P=O.length*_f+14,K=k.y+4,Z=re("vd-editor__lock-tag",{x:k.x+4,y:K,w:P,h:ht});Z.setAttribute("rx","4"),r.appendChild(Z);let z=n.createElementNS(ve,"text");z.setAttribute("class","vd-editor__lock-text"),z.setAttribute("x",String(k.x+4+P/2)),z.setAttribute("y",String(K+ht/2)),z.textContent=O,r.appendChild(z)}function T(E){let k=Hr(v(E.frame)),O=re(E.target?"vd-editor__slot vd-editor__slot--target":"vd-editor__slot",k);O.setAttribute("rx","3"),r.appendChild(O);let P=z=>z.length*bk+16<=k.w,K=[];k.h>=20&&P(E.label)&&K.push([E.label,"vd-editor__slot-label"]),K.length>0&&k.h>=48&&P(gx)&&K.push([gx,"vd-editor__slot-hint"]);let Z=k.y+k.h/2-(K.length-1)*yx/2;K.forEach(([z,ce],Ee)=>{let Ae=n.createElementNS(ve,"text");Ae.setAttribute("class",ce),Ae.setAttribute("x",String(k.x+k.w/2)),Ae.setAttribute("y",String(Z+Ee*yx)),Ae.textContent=z,r.appendChild(Ae)})}function G(E){let k=E.frames.map(ce=>Ur(v(ce),Br));for(let ce of k)r.appendChild(re("vd-editor__presence",ce));let O=k[0];if(!O||!E.label)return;let P=Math.max(34,E.label.length*_f+14),K=O.y-ht-3<0?O.y+3:O.y-ht-3,Z=re("vd-editor__presence-tag",{x:O.x,y:K,w:P,h:ht});Z.setAttribute("rx","4"),r.appendChild(Z);let z=n.createElementNS(ve,"text");z.setAttribute("class","vd-editor__presence-text"),z.setAttribute("x",String(O.x+P/2)),z.setAttribute("y",String(K+ht/2)),z.textContent=E.label,r.appendChild(z)}function Y(E,k,O){let K=E==="vd-editor__highlight"?"vd-editor__halo vd-editor__halo--highlight":E==="vd-editor__hover"||E==="vd-editor__member"?"vd-editor__halo vd-editor__halo--quiet":"vd-editor__halo";r.appendChild(re(K,Ur(k,O+1))),r.appendChild(re(E,k))}function re(E,k){let O=n.createElementNS(ve,"rect");return O.setAttribute("class",E),O.setAttribute("x",String(k.x)),O.setAttribute("y",String(k.y)),O.setAttribute("width",String(Math.max(0,k.w))),O.setAttribute("height",String(Math.max(0,k.h))),O}return{element:r,render:C,hitHandle(E){let k=g(E,f);for(let O of o)if(Et(O.rect,k.x,k.y))return{handle:O.handle,bound:O.bound};return null},hitAdjuster(E){let k=g(E,f);for(let O of s)if(Et(O.rect,k.x,k.y))return{id:O.id,bound:O.bound};return null},hitSpacer(E){return Sf(i,E)},hitPath(E){let k=g(E,p),O=l.find(P=>Et(P.rect,k.x,k.y));return O?{kind:O.kind,key:O.key}:null},hitRotate(E){let k=g(E,f),O=o.length===0?null:m;if(!O)return null;for(let P of O){let K=Math.hypot(k.x-P.at.x,k.y-P.at.y);if(K<Lr/2+2||K>gk)continue;let{u:Z,v:z}=Tr(P.handle);if((k.x-P.at.x)*(Z*2-1)+(k.y-P.at.y)*(z*2-1)>0)return P.handle}return null},hitRing(E){return Sf(d,E)},hitPageLabel(E){return Sf(y,E)},pageLabelRect(E){return y.find(k=>k.id===E)?.rect??null},destroy(){r.remove(),o=[],s=[],i=[],d=[]}}}function Sf(e,t){for(let n of e)if(Et(n.rect,t.x,t.y))return n.id;return null}function Le(e){return Math.round(e)+.5}function Hr(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 Ur(e,t){let n=t/2;return{x:e.x-n,y:e.y-n,w:e.w+t,h:e.h+t}}function Sx(e,t){let n=[];return oe(e.root,r=>{if(t.has(r.id))return!1;r.type!=="image"||ye(r.src)||e.assets[r.src]===void 0&&n.push({id:r.id,src:r.src,label:r.name??r.src})}),n}function Cf(e){if(e.length<2)return null;let t=Ef("x",e),n=Ef("y",e);return n.length===1&&t.length===e.length?Ex("x",e,t):t.length===1&&n.length===e.length?Ex("y",e,n):n.length>=2&&t.length>=2?kk(e,t,n):null}function Ef(e,t){let n=[...t].sort((o,s)=>Vr(o.frame,e)-Vr(s.frame,e)),r=[];for(let o of n){let s=r[r.length-1];if(s&&Vr(o.frame,e)<s.hi-.01){r[r.length-1]={lo:s.lo,hi:Math.max(s.hi,ea(o.frame,e)),from:Math.min(s.from,Vr(o.frame,Qi(e))),to:Math.max(s.to,ea(o.frame,Qi(e))),members:[...s.members,o.id]};continue}r.push({lo:Vr(o.frame,e),hi:ea(o.frame,e),from:Vr(o.frame,Qi(e)),to:ea(o.frame,Qi(e)),members:[o.id]})}return r}function Ex(e,t,n){return{kind:"run",items:t,series:[ta(e,n)],order:n.flatMap(r=>r.members)}}function kk(e,t,n){if(t.length*n.length!==e.length)return null;let r=[];for(let o of n)for(let s of t){let i=o.members.filter(d=>s.members.includes(d));if(i.length!==1||i[0]===void 0)return null;r.push(i[0])}return{kind:"grid",items:e,series:[ta("x",t),ta("y",n)],order:r}}function ta(e,t){let n=[];for(let r=0;r+1<t.length;r+=1){let o=t[r],s=t[r+1];!o||!s||n.push(s.lo-o.hi)}return{axis:e,tracks:t,gaps:n}}function Ft(e,t){return e.series.find(n=>n.axis===t)}function Mf(e){let t=e[0];return t===void 0?!1:e.every(n=>Math.abs(n-t)<.01)}function Af(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 s=n.tracks[o],i=n.tracks[o+1],d=n.gaps[o];if(!s||!i||d===void 0)continue;let l=(s.hi+i.lo)/2,f=r?r.tracks.map(p=>(p.lo+p.hi)/2):[(Math.max(s.from,i.from)+Math.min(s.to,i.to))/2];for(let p of f)t.push({id:Cx(n.axis,o),axis:n.axis,index:o,gap:d,at:n.axis==="x"?{x:l,y:p}:{x:p,y:l}})}}return t}function Cx(e,t){return`${e}:${t}`}function na(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 $f(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 ra(e,t,n){let r=Ft(e,t);return r?oa(r,n):new Map}function oa(e,t){let n=new Map,r=e.tracks[0];if(!r)return n;let o=r.hi;for(let s=1;s<e.tracks.length;s+=1){let i=e.tracks[s];if(!i)continue;let d=o+t;for(let l of i.members)n.set(l,d-i.lo);o=d+(i.hi-i.lo)}return n}function Of(e,t){return ta(t,Ef(t,e))}function Tf(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((s,i)=>s+(i.hi-i.lo),0);return(r.hi-n.lo-o)/(t.length-1)}function Lf(e,t){let n=_k(e),r=0,o=1/0;for(let s=0;s<n.length;s+=1){let i=n[s];if(!i)continue;let d=Math.hypot(i.x-t.x,i.y-t.y);d<o&&(o=d,r=s)}return r}function _k(e){if(e.kind==="grid"){let n=Ft(e,"x")?.tracks??[];return(Ft(e,"y")?.tracks??[]).flatMap(o=>n.map(s=>({x:(s.lo+s.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 Df(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 Pf(e,t){let n=new Map(e.items.map(d=>[d.id,d.frame])),r=new Map;if(e.kind==="grid"){let d=Ft(e,"x")?.tracks??[],l=Ft(e,"y")?.tracks??[];return t.forEach((f,p)=>{let m=d[p%d.length],y=l[Math.floor(p/d.length)];m&&y&&r.set(f,{x:m.lo,y:y.lo})}),r}let o=e.series[0],s=o?.tracks[0];if(!o||!s)return r;let i=s.lo;return t.forEach((d,l)=>{let f=n.get(d);if(!f)return;let p=o.axis==="x"?f.w:f.h;r.set(d,o.axis==="x"?{x:i,y:f.y}:{x:f.x,y:i}),i+=p+(o.gaps[l]??0)}),r}function Nf(e,t,n){let r=new Map,o=e.items.find(l=>l.id===t),s=e.items.find(l=>l.id===n);if(!o||!s||t===n)return r;let i=e.kind==="grid"?["x","y"]:[e.series[0]?.axis??"x"],d=(l,f)=>({x:i.includes("x")?f.frame.x:l.frame.x,y:i.includes("y")?f.frame.y:l.frame.y});return r.set(t,d(o,s)),r.set(n,d(s,o)),r}function Qi(e){return e==="x"?"y":"x"}function Vr(e,t){return t==="x"?e.x:e.y}function ea(e,t){return t==="x"?e.x+e.w:e.y+e.h}var Mx="vd-editor-styles",Ax=`
143
+ `;function X0(e){if(e.getElementById(q0))return;let t=e.createElement("style");t.id=q0,t.textContent=W0,e.head.appendChild(t)}function J0(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 Z0(e,t,n,r,o){return t?VM(e,t,n,r,o):BM(e,n,r)}function BM(e,t,n){let r=sp(e,n);return{measurer:r,update:o=>{r.load(o,t)},afterPaint:()=>{},destroy:()=>r.destroy()}}var Y0=new WeakMap;function VM(e,t,n,r,o){let s,i,a,d=()=>{if(!s)throw new Error("canvasFonts: update() before measuring");return s};return{measurer:{advance:(l,p)=>d().measurer.advance(l,p),metrics:l=>d().measurer.metrics(l),itemize:l=>d().measurer.itemize(l)},update(l){s&&l.fonts===i||(a?.(),s?.dispose(),s=t.forDocument(l,{...n?{loader:n}:{},...o?{asset:o}:{}}),i=l.fonts,a=s.onChange(r))},afterPaint(){let l=e.fonts;if(!s||!l||typeof FontFace!="function")return;let p=Y0.get(e);p||Y0.set(e,p=new Set);for(let m of s.usedFaces()){if(p.has(m.id))continue;p.add(m.id);let g=new FontFace(m.id,HM(m.bytes),{weight:String(m.weight),style:m.style});l.add(g),g.load().catch(()=>l.delete(g))}},destroy(){a?.(),s?.dispose(),s=void 0}}}function HM(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}var UM=.01,zM=.004,Q0=40,jM=16;function Rd(e,t){X0(e.ownerDocument);let n=t.document,r=H=>Z0(e.ownerDocument,H,t.loadFont,()=>{T(n)},J0(t.resolveAsset)),o=r(t.fonts),s={advance:(H,J)=>o.measurer.advance(H,J),metrics:H=>o.measurer.metrics(H),itemize:H=>o.measurer.itemize?.(H)??[H]};o.update(n);let i=Pe(n),a=()=>t.resolveAsset?{measure:s,resolveAsset:t.resolveAsset}:{measure:s},d=Ai(n,i,a()),c=t.camera??Ld,l=t.interactive??!0,p=t.wheel??"always";e.classList.add("vd-viewer"),t.surface&&(e.style.background=t.surface);let m=e.ownerDocument.createElementNS(le,"svg");m.setAttribute("class","vd-viewer__surface"),m.setAttribute("width","100%"),m.setAttribute("height","100%");let g=e.ownerDocument.createElementNS(le,"g");g.setAttribute("class","vd-viewer__camera"),g.style.isolation="isolate",m.appendChild(g);let b=e.ownerDocument.createElementNS(le,"defs");g.appendChild(b);let w=e.ownerDocument.createElementNS(le,"rect");w.setAttribute("class","vd-viewer__page"),g.appendChild(w),e.appendChild(m);let k=new Map,_=null;function M(){let H=t.sample;return _&&H?H(d,_.timeline,_.t,{doc:n,resolution:i,options:a()}):d}function R(){g.setAttribute("transform",ap(c))}function B(H=!0){let J=M();V(J);let Oe=d.background!==void 0;Me(w,"x",String(d.x)),Me(w,"y",String(d.y)),Me(w,"width",String(Oe?d.width:0)),Me(w,"height",String(Oe?d.height:0)),we(w,"fill",d.background??null);let se=new Set,ke=w;for(let ye of J.items){if(ye.backdrop!==void 0){let Os=tb(ye.id);se.add(Os);let At=k.get(Os);At||(At=e.ownerDocument.createElementNS(le,"g"),At.setAttribute("data-vd-id",ye.id),k.set(Os,At)),Pi(At,Jf(J,ye)),ke.nextSibling!==At&&g.insertBefore(At,ke.nextSibling),ke=At}let Ge=ye.kind==="border"?eb(ye.id):ye.part===void 0?ye.id:`${ye.id}\0${ye.part}`;se.add(Ge);let Ue=k.get(Ge);(!Ue||Ue.tagName!==Nd(ye))&&(Ue?.remove(),Ue=e.ownerDocument.createElementNS(le,Nd(ye)),Ue.setAttribute("data-vd-id",ye.id),k.set(Ge,Ue)),sb(Ue,ye),ke.nextSibling!==Ue&&g.insertBefore(Ue,ke.nextSibling),ke=Ue}for(let[ye,Ge]of k)se.has(ye)||(Ge.remove(),k.delete(ye));YM(g,J),o.afterPaint(),H&&t.onSceneChange?.(d,n)}let D=new Map;function V(H){let J=[...H.gradients.map(qf),...[...new Map(H.items.filter(eo).map(ye=>[ye.id,ye])).values()].map(ye=>Wf(ye)),...Xf(H.items).map(Yf),...H.clips.map(Gf),...H.items.filter(ye=>ye.mask!==void 0).map(Qf)],Oe=new Set(J);for(let[ye,Ge]of D)Oe.has(ye)||(Ge.remove(),D.delete(ye));let se=J.filter(ye=>!D.has(ye));if(se.length===0)return;[...new DOMParser().parseFromString(`<svg xmlns="${le}">${se.join("")}</svg>`,"image/svg+xml").documentElement.children].forEach((ye,Ge)=>{let Ue=e.ownerDocument.importNode(ye,!0);b.appendChild(Ue),D.set(se[Ge],Ue)})}function T(H){n=H,o.update(n),i=Pe(n),d=Ai(n,i,a()),B()}function O(H){let J=e.getBoundingClientRect();return{x:H.clientX-J.left,y:H.clientY-J.top}}let j=0,$=0;function P(){e.classList.add("vd-viewer--interacting"),$&&clearTimeout($),$=setTimeout(()=>{$=0,e.classList.remove("vd-viewer--interacting")},180)}function C(){j&&(cancelAnimationFrame(j),j=0),R(),t.onCameraChange?.(c)}function G(H){c=H,C()}function ee(H){c=H,P(),!j&&(j=requestAnimationFrame(()=>{j=0,R(),t.onCameraChange?.(c)}))}let fe=null,oe=null,Se=!1,be=l&&p==="always",v=new Map,N=null,I=()=>{let[H,J]=[...v.values()];return!H||!J?null:{mid:{x:(H.x+J.x)/2,y:(H.y+J.y)/2},distance:Math.hypot(H.x-J.x,H.y-J.y)}},F=H=>{let J=v.get(H.pointerId);if(!J)return;let Oe=O(H);if(v.set(H.pointerId,Oe),v.size===1){ee(yn(c,Oe.x-J.x,Oe.y-J.y));return}let se=I();if(N&&se){let ke=yn(c,se.mid.x-N.mid.x,se.mid.y-N.mid.y);ee(N.distance>0?Ti(ke,se.mid,se.distance/N.distance):ke)}N=se},q=H=>{v.delete(H.pointerId)&&(e.hasPointerCapture(H.pointerId)&&e.releasePointerCapture(H.pointerId),N=I())},Y=H=>{if(p==="modifier"&&!H.ctrlKey&&!H.metaKey)return;H.preventDefault();let J=O(H),Oe=H.deltaMode===1?jM:H.deltaMode===2?e.clientHeight||800:1,se=H.deltaX*Oe,ke=H.deltaY*Oe;if(H.ctrlKey||H.metaKey){let ye=H.ctrlKey?UM:zM,Ge=Math.max(-Q0,Math.min(Q0,ke));ee(Ti(c,J,Math.exp(-Ge*ye)));return}if(H.shiftKey&&se===0){ee(yn(c,-ke,0));return}ee(yn(c,-se,-ke))},Q=H=>{if(H.pointerType==="touch"){if(!be)return;H.preventDefault(),v.set(H.pointerId,O(H)),e.setPointerCapture(H.pointerId),N=I();return}(H.button===1||H.button===0&&Se)&&(H.preventDefault(),fe=H.pointerId,oe=O(H),e.setPointerCapture(H.pointerId))},Te=H=>{if(H.pointerType==="touch"){F(H);return}if(fe!==H.pointerId||!oe)return;let J=O(H);ee(yn(c,J.x-oe.x,J.y-oe.y)),oe=J},Ct=H=>{if(H.pointerType==="touch"){q(H);return}fe===H.pointerId&&(fe=null,oe=null,e.hasPointerCapture(H.pointerId)&&e.releasePointerCapture(H.pointerId))},_e=H=>{H.code==="Space"&&(Se=!0)},Rt=H=>{H.code==="Space"&&(Se=!1)};be&&(e.style.touchAction="none"),l&&(e.addEventListener("wheel",Y,{passive:!1}),e.addEventListener("pointerdown",Q),e.addEventListener("pointermove",Te),e.addEventListener("pointerup",Ct),e.addEventListener("pointercancel",Ct),e.ownerDocument.addEventListener("keydown",_e),e.ownerDocument.addEventListener("keyup",Rt)),R(),B();let ae={element:e,surface:m,update:T,getDocument:()=>n,getScene:()=>d,setTime(H){H===null&&_===null||(_=H,B(!1))},getTime:()=>_,getResolution:()=>i,getMeasurer:()=>s,setFonts(H){o.destroy(),o=r(H),T(n)},getCamera:()=>c,setCamera:G,zoomBy(H,J){let Oe=e.getBoundingClientRect(),se=J??{x:Oe.width/2,y:Oe.height/2};G(Ti(c,se,H))},fitToContent(H=32){let J=e.getBoundingClientRect();G(bn({x:d.x,y:d.y,width:d.width,height:d.height},{width:J.width||d.width,height:J.height||d.height},H))},screenToDocument:H=>Pd(c,H),documentToScreen:H=>ip(c,H),pointerPoint:O,hitTest(H,J){for(let Oe=d.items.length-1;Oe>=0;Oe--){let se=d.items[Oe];if(se&&iC(se,H,sC/c.zoom)&&(!J||J(se.id)))return se.id}return null},linkAt(H,J){for(let Oe=d.items.length-1;Oe>=0;Oe--){let se=d.items[Oe];if(se?.kind!=="text"||J&&!J(se.id))continue;let ke=se.rotation===0?H:je(H,{x:se.x+se.w/2,y:se.y+se.h/2},-se.rotation);for(let ye of se.lines){if(ke.y<ye.y||ke.y>ye.y+ye.h)continue;let Ge=ye.spans.find(Ue=>ke.x>=Ue.x&&ke.x<=Ue.x+Ue.w);if(Ge)return Ge.style.link}}},itemOf:H=>d.items.find(J=>J.id===H),elementOf:H=>k.get(H),elementsOf:H=>[k.get(tb(H)),k.get(H),k.get(eb(H))].filter(J=>J!==void 0),destroy(){l&&(e.removeEventListener("wheel",Y),e.removeEventListener("pointerdown",Q),e.removeEventListener("pointermove",Te),e.removeEventListener("pointerup",Ct),e.removeEventListener("pointercancel",Ct),e.ownerDocument.removeEventListener("keydown",_e),e.ownerDocument.removeEventListener("keyup",Rt)),j&&cancelAnimationFrame(j),$&&clearTimeout($),j=0,$=0,o.destroy(),e.classList.remove("vd-viewer--interacting"),m.remove(),k.clear(),e.classList.remove("vd-viewer")}};return t.autoFit&&ae.fitToContent(),ae}function eb(e){return`${e}\0border`}function tb(e){return`${e}\0backdrop`}var KM="vd-clip-";function GM(e){return KM+e}function Dd(e){return`url(#${GM(e)})`}function Nd(e){return e.veil!==void 0||ob(e)?"g":Li(e)}function qM(e){let{veil:t,...n}=e;return t===void 0?e:n}function ob(e){return $d(e)||e.pose!==void 0}function us(e){return Ad(e)?"path":"rect"}function Li(e){if(e.mask!==void 0||as(e))return"g";switch(e.kind){case"border":return us(e.radii);case"connector":return"g";case"ellipse":return"ellipse";case"frame":return us(e.radii);case"image":return e.href===void 0&&e.video?.clip!==void 0?"g":e.href===void 0?us(e.radii):Jt(e.radii)?"image":"g";case"rect":return us(e.radii);case"text":return"text";case"vector":return"path"}}function sb(e,t){if(t.veil!==void 0){we(e,"clip-path",t.veil.clip===void 0?null:Dd(t.veil.clip)),e.style.filter=`url(#${$i}${t.veil.id})`;let o=qM(t),s=e.firstElementChild;(!s||s.tagName!==Nd(o)||e.childElementCount!==1)&&(e.replaceChildren(),s=e.ownerDocument.createElementNS(le,Nd(o)),e.appendChild(s)),sb(s,o);return}if(!ob(t)){dp(e,t);return}we(e,"clip-path",t.clip===void 0?null:Dd(t.clip)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend;let n=t.pose;we(e,"opacity",n&&n.opacity<1?String(n.opacity):null);let r=e.firstElementChild;if((!r||r.tagName!==Li(t))&&(r?.remove(),r=e.ownerDocument.createElementNS(le,Li(t)),e.appendChild(r)),dp(r,{...t,clip:void 0,blend:"normal"}),n){let o=t.rotation===0||t.mask!==void 0?"":` ${os(t)}`;Me(r,"transform",`${Oi(n)}${o}`),t.kind==="vector"&&WM(r,t)}}function WM(e,t){if(as(t))return;let n=t.pose?.trace;if(n!==void 0&&t.stroke!==void 0){let o=t.dash??[],s=_i(o,ui(t.contours),n);Me(e,"stroke-dasharray",s.array.join(" ")),we(e,"stroke-dashoffset",s.offset!==0||o.length===0?String(s.offset):null)}let r=t.pose?.fillOpacity;we(e,"fill-opacity",r!==void 0&&r<1?String(r):null)}function dp(e,t){if(t.mask!==void 0){XM(e,t);return}if(we(e,"clip-path",t.clip===void 0?null:Dd(t.clip)),we(e,"transform",t.rotation===0?null:os(t)),e.style.mixBlendMode=t.blend==="normal"?"":t.blend,e.style.filter=eo(t)?`url(#${Qr}${t.id})`:"",as(t)){let n="opacity"in t?t.opacity:1;we(e,"opacity",n<1?String(n):null),Pi(e,op(t));return}switch(t.kind){case"border":JM(e,t);return;case"connector":we(e,"opacity",t.opacity<1?String(t.opacity):null),Pi(e,tp(t));return;case"ellipse":rC(e,t);return;case"frame":ZM(e,t);return;case"image":QM(e,t);return;case"rect":nC(e,t);return;case"text":tC(e,t);return;case"vector":oC(e,t);return}}function XM(e,t){we(e,"clip-path",t.clip===void 0?null:Dd(t.clip)),we(e,"transform",null),e.style.mixBlendMode=t.blend==="normal"?"":t.blend,e.style.filter=eo(t)?`url(#${Qr}${t.id})`:"";let n="opacity"in t?t.opacity:1;we(e,"opacity",n<1?String(n):null);let r=e.ownerDocument,o=e.firstElementChild;(o?.tagName!=="g"||e.childElementCount!==1)&&(e.replaceChildren(),o=r.createElementNS(le,"g"),e.appendChild(o)),Me(o,"clip-path",`url(#${ss}${t.id})`);let s=Od(t),i=o.firstElementChild;i?.tagName!==Li(s)&&(i?.remove(),i=r.createElementNS(le,Li(s)),o.appendChild(i)),dp(i,s);let a=Zf(t),d=o.nextElementSibling;if(a===""){d?.remove();return}d||(d=r.createElementNS(le,"g"),e.appendChild(d)),Pi(d,a)}var nb=new WeakMap;function YM(e,t){let n=new Map;for(let r of t.items)r.kind==="image"&&r.video?.clip!==void 0&&r.href===void 0&&n.set(r.id,r.video.at/1e3);if(n.size!==0)for(let r of e.querySelectorAll("video[data-vd-video]")){let o=n.get(r.getAttribute("data-vd-video")??"");if(o===void 0)continue;let s=r;if(s.muted=!0,!(Math.abs(s.currentTime-o)<1/60))try{s.currentTime=o}catch{}}}function Pi(e,t){let n=nb.get(e);if(n?.markup===t&&n.first===e.firstChild&&n.last===e.lastChild)return;let r=new DOMParser().parseFromString(`<svg xmlns="${le}">${t}</svg>`,"image/svg+xml"),o=e.ownerDocument;e.replaceChildren(...[...r.documentElement.children].map(s=>o.importNode(s,!0))),nb.set(e,{markup:t,first:e.firstChild,last:e.lastChild})}function JM(e,t){we(e,"class",null),Di(e,t,t.radii),Me(e,"fill","none"),up(e,t)}function up(e,t){let n=Pt(t);we(e,"stroke",n?.paint??null),we(e,"stroke-width",n?String(n.width):null),t.kind==="vector"&&t.pose?.trace!==void 0||(we(e,"stroke-dasharray",n&&n.dash.length>0?n.dash.join(" "):null),we(e,"stroke-dashoffset",null)),we(e,"stroke-linecap",n&&n.cap!=="butt"?n.cap:null),we(e,"stroke-linejoin",n&&n.join!=="miter"?n.join:null)}function ZM(e,t){Me(e,"class","vd-viewer__page"),Di(e,t,t.radii),we(e,"fill",t.background??null)}function QM(e,t){if(we(e,"opacity",t.opacity<1?String(t.opacity):null),t.href===void 0&&t.video?.clip!==void 0){Pi(e,Td(t));return}if(t.href===void 0){Me(e,"class","vd-viewer__missing"),Di(e,t,t.radii);return}if(e.tagName!=="g"){rb(e,t);return}let n=e.ownerDocument,r=e.firstElementChild;r?.tagName!=="clipPath"&&(e.replaceChildren(),r=n.createElementNS(le,"clipPath"),e.appendChild(r)),Me(r,"id",is+t.id);let o=r.firstElementChild;o?.tagName!==us(t.radii)&&(o?.remove(),o=n.createElementNS(le,us(t.radii)),r.appendChild(o)),Di(o,t,t.radii);let s=r.nextElementSibling;s?.tagName!=="image"&&(s?.remove(),s=n.createElementNS(le,"image"),e.appendChild(s)),rb(s,t),Me(s,"clip-path",`url(#${is}${t.id})`)}function rb(e,t){Me(e,"x",String(t.x)),Me(e,"y",String(t.y)),Me(e,"width",String(t.w)),Me(e,"height",String(t.h)),Me(e,"href",t.href??""),Me(e,"preserveAspectRatio",eC[t.fit])}function Di(e,t,n){if(e.tagName==="path"){Me(e,"d",Cd(t,n));return}Me(e,"x",String(t.x)),Me(e,"y",String(t.y)),Me(e,"width",String(t.w)),Me(e,"height",String(t.h)),we(e,"rx",Jt(n)?null:String(n.tl))}var eC={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"};function tC(e,t){we(e,"opacity",t.opacity<1?String(t.opacity):null),Me(e,"xml:space","preserve"),up(e,t),we(e,"paint-order",Pt(t)?"stroke":null);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(le,"tspan"));n.forEach((o,s)=>{let i=e.childNodes[s];i.textContent!==o.text&&(i.textContent=o.text),Me(i,"x",String(o.x)),Me(i,"y",String(o.y)),Me(i,"font-family",o.style.family),Me(i,"font-size",String(o.style.size)),Me(i,"fill",o.style.fill),we(i,"font-weight",o.style.weight===400?null:String(o.style.weight)),we(i,"font-style",o.style.italic?"italic":null),we(i,"letter-spacing",o.style.letterSpacing===0?null:String(o.style.letterSpacing)),we(i,"data-vd-link",o.style.link??null);let a=[o.style.underline?"underline":"",o.style.strike?"line-through":""].filter(Boolean).join(" ");we(i,"text-decoration",a===""?null:a)})}function nC(e,t){we(e,"class",null),Di(e,t,t.radii),cp(e,t)}function cp(e,t){if(Me(e,"fill",t.fill),we(e,"stroke",t.stroke??null),we(e,"stroke-width",t.stroke&&t.strokeWidth>0?String(t.strokeWidth):null),we(e,"opacity",t.opacity<1?String(t.opacity):null),t.kind==="vector"){if(t.pose?.trace===void 0){let n=t.stroke!==void 0?t.dash??[]:[];we(e,"stroke-dasharray",n.length>0?n.join(" "):null),we(e,"stroke-dashoffset",null)}return}up(e,t)}function rC(e,t){Me(e,"cx",String(t.x+t.w/2)),Me(e,"cy",String(t.y+t.h/2)),Me(e,"rx",String(t.w/2)),Me(e,"ry",String(t.h/2)),cp(e,t)}function oC(e,t){Me(e,"d",t.d),cp(e,t),we(e,"fill-rule",t.rule==="nonzero"?null:t.rule),we(e,"stroke-linecap",t.cap==="butt"?null:t.cap),we(e,"stroke-linejoin",t.join==="miter"?null:t.join)}function Me(e,t,n){e.getAttribute(t)!==n&&e.setAttribute(t,n)}function we(e,t,n){n===null?e.hasAttribute(t)&&e.removeAttribute(t):Me(e,t,n)}var sC=4;function iC(e,t,n){if(e.mask!==void 0&&!Br(e.mask.contours,t,{fill:!0,rule:e.mask.rule,reach:n}))return!1;let r=e.rotation===0?t:je(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==="border")return!1;if(e.kind==="ellipse"){let s=Zr(e),i=e.w/2+s,a=e.h/2+s;if(i<=0||a<=0)return!1;let d=(r.x-(e.x+e.w/2))/i,c=(r.y-(e.y+e.h/2))/a;return d*d+c*c<=1}if(e.kind==="connector"){let s=e.strokeWidth/2+n;return Br(e.contours,r,{fill:!1,rule:"nonzero",reach:s})||Br(e.filled.contours,r,{fill:!0,rule:"nonzero",reach:n})||Br(e.lined.contours,r,{fill:!1,rule:"nonzero",reach:s})}if(e.kind==="vector"){let s=e.stroke!==void 0&&e.strokeWidth>0;return Br(e.contours,r,{fill:e.fill!=="none",rule:e.rule,reach:(s?Zr(e):0)+n})}return o}var MN=lp(ad),CN=lp(dd),aC=lp(ud);function lp(e){return`cubic-bezier(${e.join(", ")})`}function fp(e,t){let n=e.root.id;if(n===t)return e;let r=o=>{if(!ve(o))return o;let s=tt(o.expr);return!s.ok||!on(s.ast).nodes.includes(n)?o:{expr:qr(gn(s.ast,i=>i===n?t:void 0))}};return{...e,root:{...ib(e.root,r),id:t}}}function ib(e,t){let n=e,r={};for(let[o,s]of Object.entries(n)){if(o==="children"&&Array.isArray(s)){r[o]=s.map(i=>ib(i,t));continue}r[o]=t(s)}return r}var hp=["nw","n","ne","e","se","s","sw","w"],Ii=["nw","ne","se","sw"];function Id(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 cs(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 mp(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 Ri=1;function Vn(e,t,n,r){let{x:o,y:s,w:i,h:a}=e;if(t.includes("w")){let d=o+i;o=Math.min(o+n,d-Ri),i=d-o}if(t.includes("e")&&(i=Math.max(Ri,i+n)),t.includes("n")){let d=s+a;s=Math.min(s+r,d-Ri),a=d-s}return t.includes("s")&&(a=Math.max(Ri,a+r)),{x:o,y:s,w:i,h:a}}function to(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 Fd(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 Wt(e){if(e.length===0)return null;let t=1/0,n=1/0,r=-1/0,o=-1/0;for(let s of e)t=Math.min(t,s.x),n=Math.min(n,s.y),r=Math.max(r,s.x+s.w),o=Math.max(o,s.y+s.h);return{x:t,y:n,w:r-t,h:o-n}}function xp(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 Mt(e,t,n){return t>=e.x&&t<=e.x+e.w&&n>=e.y&&n<=e.y+e.h}var ls=7,pp=15,Ni=9;function gp(e){let t=[],n=pp/2;for(let a of Ii){let{u:d,v:c}=cs(a);t.push({handle:a,rect:{x:e.x+e.w*d-n,y:e.y+e.h*c-n,w:pp,h:pp}})}let r=n,o=Math.max(0,e.w-r*2),s=Math.max(0,e.h-r*2),i=Ni/2;return t.push({handle:"n",rect:{x:e.x+r,y:e.y-i,w:o,h:Ni}},{handle:"s",rect:{x:e.x+r,y:e.y+e.h-i,w:o,h:Ni}},{handle:"w",rect:{x:e.x-i,y:e.y+r,w:Ni,h:s}},{handle:"e",rect:{x:e.x+e.w-i,y:e.y+r,w:Ni,h:s}}),t}function Ke(e,t){let n=[],r=o=>{if(n.push(o.id),o.id===t)return!0;for(let s of te(o))if(r(s))return!0;return n.pop(),!1};return r(e)?n:[]}function Bd(e,t,n){let r=Ke(t.root,e);if(r.length===0)return e;let o=n!==null&&r.includes(n)?n:lC(r,t),s=r.indexOf(o);if(s===-1)return e;let i=r.indexOf(n??"")+1;for(let a=Math.max(i,1);a<s+1;a+=1)if(z(t.root,r[a])?.type==="instance")return r[a];return r[s+1]??e}function lC(e,t){for(let n=e.length-2;n>=0;n-=1){let r=e[n];if(z(t.root,r)?.type==="frame")return r}return t.root.id}function ab(e,t){let n=e.map(o=>Ke(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 s=n[0]?.[o];if(s===void 0||n.some(i=>i[o]!==s||o===i.length-1))break;r=s}return r}function no(e,t){let n=z(t.root,e);if(!n)return[];let r=[],o=s=>{if(Ne(s)){for(let i of te(s))o(i);return}r.push(s.id)};return o(n),r}function ro(e,t,n){let r=z(t.root,e);if(!r)return;if(!Ne(r)){let i=n.nodes.get(e);return i?Fi(i):void 0}let o=[],s=i=>{if(!(i.id!==e&&"hidden"in i&&i.hidden===!0)){if(i.id!==e&&!Ne(i)){let a=ro(i.id,t,n);a&&o.push(a);return}for(let a of te(i))s(a)}};return s(r),Wt(o)??void 0}function Fi(e){let t={x:e.absX,y:e.absY,w:e.w,h:e.h},n=e.values.rotation??0;return n===0?t:lr(t,n)}function Bi(e,t,n){return t.flatMap(r=>{let o=ro(r,e,n);return o?[{id:r,frame:o}]:[]})}function yp(e,t){let n=t.filter(p=>p!==e.root.id&&z(e.root,p));if(n.length<2)return null;let r=ab(n,e),o=z(e.root,r);if(!o)return null;let s=te(o),i=new Set(n.map(p=>Bd(p,e,r))),a=s.filter(p=>i.has(p.id));if(a.length<2)return null;let d=s.findIndex(p=>p.id===a[a.length-1]?.id),c=pn(e.root,"group"),l=[{op:"insert",parent:r,index:d+1,node:nl({id:c,children:[]})}];return a.forEach((p,m)=>{l.push({op:"move",id:p.id,parent:c,index:m})}),{ops:l,groupId:c}}function bp(e,t){let n=z(e.root,t);if(!n||!Ne(n))return[];let r=Ke(e.root,t),o=r[r.length-2];if(o===void 0)return[];let s=z(e.root,o);if(!s)return[];let i=te(s).findIndex(d=>d.id===t);if(i===-1)return[];let a=te(n).map((d,c)=>({op:"move",id:d.id,parent:o,index:i+c}));return a.push({op:"remove",id:t}),a}function vp(e,t,n){let r=new Map;for(let s of t){let i=Ke(e.root,s),a=i[i.length-2];if(a===void 0)continue;let d=r.get(a)??new Set;d.add(s),r.set(a,d)}let o=[];for(let[s,i]of r){let a=z(e.root,s);if(!a)continue;let d=te(a).map(c=>c.id);o.push(...pC(s,d,fC(d,i,n)))}return o}function fC(e,t,n){if(n==="front"||n==="back"){let i=e.filter(d=>t.has(d)),a=e.filter(d=>!t.has(d));return n==="front"?[...a,...i]:[...i,...a]}let r=n==="forward"?1:-1,o=[...e],s=o.flatMap((i,a)=>t.has(i)?[a]:[]);r===1&&s.reverse();for(let i of s){let a=i+r,d=o[a];d===void 0||t.has(d)||(o[a]=o[i],o[i]=d)}return o}function pC(e,t,n){let r=[...t],o=[];for(let s=0;s<n.length;s+=1){let i=n[s];i===void 0||r[s]===i||(r.splice(r.indexOf(i),1),r.splice(s,0,i),o.push({op:"move",id:i,parent:e,index:s}))}return o}function wp(e,t,n){let r=t.w===0?1:n.w/t.w,o=t.h===0?1:n.h/t.h,s=new Map;for(let[i,a]of e)s.set(i,{x:n.x+(a.x-t.x)*r,y:n.y+(a.y-t.y)*o,w:a.w*r,h:a.h*o});return s}function oo(e,t){let n=[];for(let r of gC(e,t)){if(!z(e.root,r.nodeId))continue;let o=Z(r.to);Z(r.from)===o&&r.whole!==!0||n.push({op:"set",id:r.nodeId,prop:r.prop,value:o})}return n}var hC=new Set(["x","y","w","h"]),mC=new WeakMap,xC=new WeakMap;function db(e,t,n){let r=e.get(t);if(r!==void 0)return r;let o=n(t);return e.set(t,o),o}function gC(e,t){let n=t.filter(a=>hC.has(a.prop)&&z(e.root,a.nodeId)?.type==="connector");if(n.length===0)return t;let r=db(mC,e,Pe),o=db(xC,e,In),s=new Set(t.map(a=>a.nodeId)),i=t.filter(a=>!n.includes(a));for(let a of new Set(n.map(d=>d.nodeId))){let d=r.nodes.get(a);if(!d)continue;let c=(w,k)=>n.find(_=>_.nodeId===a&&_.prop===w)?.to??k,l=c("x",d.x),p=c("y",d.y),m=d.w===0?1:c("w",d.w)/d.w,g=d.h===0?1:c("h",d.h)/d.h,b=o.get(a);for(let[w,k,_]of[["start","x1","y1"],["end","x2","y2"]]){let M=b?.[w];if(M!==void 0&&s.has(M))continue;let R=d.values[k]??0,B=d.values[_]??0,D=l+(R-d.x)*m,V=p+(B-d.y)*g;Z(D)===Z(R)&&Z(V)===Z(B)||i.push({nodeId:a,prop:k,from:R,to:D,whole:!0},{nodeId:a,prop:_,from:B,to:V,whole:!0})}}return i}function ub(e,t,n){return Sl.includes(n)&&z(e.root,t)?.type==="connector"}function Z(e){return Math.round(e*100)/100}function fs(e,t,n,r){let o=new Set,s=[];for(let d of t)d.op==="set"&&(o.add(nt(d.id,d.prop)),s.push({nodeId:d.id,prop:d.prop}));if(s.length===0)return[];let i=[],a=new Set;for(let d of s)for(let c of n.get(nt(d.nodeId,d.prop))??[]){let l=nt(c.nodeId,c.prop);if(o.has(l)||a.has(l)||!z(e.root,c.nodeId)||ub(e,c.nodeId,c.prop))continue;let p=r.nodes.get(c.nodeId)?.values[c.prop];p!==void 0&&(a.add(l),i.push({op:"set",id:c.nodeId,prop:c.prop,value:Z(p)}))}return i}function kp(e,t,n,r={x:0,y:0}){let o=[],s=new Set,i=e;for(;;){let a=[],d=Pe(i);for(let[c,l]of t){let p=n.get(c),m=z(i.root,l),g=d.nodes.get(l);if(!(!p||!m||!g))for(let b of Vt(m)){let w=nt(l,b);if(s.has(w))continue;let k=p[b],_=g.values[b];if(k===void 0||_===void 0)continue;let M=b==="x"||b==="x1"||b==="x2"?r.x:0,R=b==="y"||b==="y1"||b==="y2"?r.y:0,B=k+M+R;Z(B)!==Z(_)&&(s.add(w),a.push({op:"set",id:l,prop:b,value:Z(B)}))}}if(a.length===0)return o;o.push(...a),i=Ae(i,a).document}}function ps(e,t,n=new Set){let r=Pe(e),o=Pe(t),s=[],i=yC(t.root);for(let[a,d]of o.nodes){if(n.has(a)||i.has(a))continue;let c=r.nodes.get(a),l=z(t.root,a);if(!(!c||!l))for(let p of Vt(l)){if(ub(t,a,p))continue;let m=c.values[p],g=d.values[p];m===void 0||g===void 0||Z(m)!==Z(g)&&s.push({op:"set",id:a,prop:p,value:Z(m)})}}return s}function yC(e){let t=new Set;return de(e,n=>{if(n.type==="instance"){for(let r of n.children)de(r,o=>{t.add(o.id)});return!1}}),t}function Vd(e,t,n){let r=new Set,o=[];for(let s of t)s.op==="set"&&s.prop==="view"&&r.add(s.id);for(let s of t){if(s.op!=="set"||s.prop!=="w"&&s.prop!=="h"||r.has(s.id))continue;let i=z(e.root,s.id);if(i?.type!=="vector"||i.view!==void 0)continue;let a=n(s.id);a&&(r.add(s.id),o.push({op:"set",id:s.id,prop:"view",value:Pn({x:0,y:0,w:a.w,h:a.h})}))}return o.length===0?[...t]:[...o,...t]}var bC=200,vC=100,wC=3,kC=.5;function Je(e,t){return Lt(e.root,t)!==void 0}function Hn(e,t){let n=z(e.root,t);return n?.type==="frame"&&n.component===!0}function Vi(e,t){if(t.length===0)return!1;let n=new Set;for(let r of t){if(r===e.root.id||Je(e,r))return!1;let o=z(e.root,r);if(!o)return!1;let s=Le(e.root,r);if(o.type==="frame"&&(o.component===!0||s?.id===e.root.id))return!1;n.add(s?.id)}return n.size===1}function Sp(e,t,n){if(!Vi(e,t))return null;let r=Le(e.root,t[0]);if(!r)return null;let o=r.children.filter(M=>t.includes(M.id)),s=o.length===1?o[0]:void 0,i=cr(e.root),a,d,c;if(s?.type==="frame"){let M=n.nodes.get(s.id);cb(s.id,s.children,i);let{name:R,hidden:B,locked:D}=s,V={...s};for(let O of["x","y","w","h","name","hidden","locked"])delete V[O];a={...V,id:hs(`${s.id}.main`,i),x:0,y:0,w:Z(M?.w??0),h:Z(M?.h??0),component:!0},d={type:"instance",id:s.id,...R===void 0?{}:{name:R},component:a.id,x:s.x,y:s.y,...s.w===a.w?{}:{w:s.w},...s.h===a.h?{}:{h:s.h},...B===void 0?{}:{hidden:B},...D===void 0?{}:{locked:D},children:[]};let T=O=>O===s.id?a.id:void 0;a={...a,children:a.children.map(O=>pb(O,T))},c=s.children}else{let M=SC(o,n);if(!M)return null;let R=_C(e,r.id,n),B=Z(M.x-R.x),D=Z(M.y-R.y),V=s&&Ne(s)?s:void 0,T=V?V.id:hs("component",i),O=V?te(V):o;cb(T,O,i),a={type:"frame",id:hs(`${T}.main`,i),x:0,y:0,w:Z(M.w),h:Z(M.h),component:!0,children:O.map(j=>hb(j,B,D))},d={type:"instance",id:T,...V?.name===void 0?{}:{name:V.name},component:a.id,x:B,y:D,...V?.type==="group"&&V.hidden!==void 0?{hidden:V.hidden}:{},...V?.type==="group"&&V.locked!==void 0?{locked:V.locked}:{},children:[]},c=O}let l=Hi(e,n);a={...a,x:l.x,y:l.y};let p=new Set;for(let M of c)de(M,R=>{p.add(R.id)});let m=new Set(o.map(M=>M.id));for(let M of o)de(M,R=>{m.add(R.id)});let g=Math.min(...o.map(M=>r.children.indexOf(M))),b=[...o.map(M=>({op:"remove",id:M.id})),{op:"insert",parent:r.id,index:g,node:d},{op:"insert",parent:e.root.id,index:e.root.children.length,node:a}],w=M=>p.has(M)&&M!==d.id?Ht(d.id,M):void 0;b.push(...EC(e,M=>!m.has(M.id),w)),b.push(...MC(e,w));let k=[],_=Ae(e,b).document;for(let M=0;M<wC;M+=1){let R=Pe(_),B=[];for(let D of p){let V=n.nodes.get(D),T=R.nodes.get(Ht(d.id,D)),O=z(_.root,D);if(!V||!T||!O||Ne(O))continue;let j=O,$={x:V.absX-T.absX,y:V.absY-T.absY,w:V.w-T.w,h:V.h-T.h};for(let P of["x","y","w","h"]){if(Math.abs($[P])<kC||j[P]===void 0)continue;let C=P==="x"?T.x:P==="y"?T.y:T[P];B.push({op:"set",id:D,prop:P,value:Z(C+$[P])}),k.includes(`${D}.${P}`)||k.push(`${D}.${P}`)}}if(B.length===0)break;b.push(...B),_=Ae(_,B).document}return{ops:b,componentId:a.id,instanceId:d.id,flattened:k}}function Hd(e,t,n){let r=z(e.root,t);if(r?.type!=="instance"||Je(e,t))return null;let o=Le(e.root,t);if(!o)return null;let s=lt(e.root).get(r.component),i=n.nodes.get(t),a=new Set;for(let p of r.children)de(p,m=>{a.add(m.id)});let d=p=>p===r.component?t:a.has(Ht(t,p))?Ht(t,p):void 0,c={type:"frame",id:t,...r.name===void 0?{}:{name:r.name},x:r.x,y:r.y,w:r.w??Z(i?.w??0),h:r.h??Z(i?.h??0),...s?.background===void 0?{}:{background:s.background},...s?.clip===void 0?{}:{clip:s.clip},...s?.blend===void 0?{}:{blend:s.blend},...s?.shadow===void 0?{}:{shadow:s.shadow},...s?.blur===void 0?{}:{blur:s.blur},...s?.backdrop===void 0?{}:{backdrop:s.backdrop},...r.hidden===void 0?{}:{hidden:r.hidden},...r.locked===void 0?{}:{locked:r.locked},children:r.children.map(p=>lb(p,r,d))},l=o.children.findIndex(p=>p.id===t);return[{op:"remove",id:t},{op:"insert",parent:o.id,index:l,node:c}]}function lb(e,t,n){let r={...e};for(let[o,s]of Object.entries(r))ve(s)&&(r[o]=zd(s.expr,n)??s);if(e.type==="instance"){let o=e.id.slice(t.id.length+1),s={...e.overrides};for(let[a,d]of Object.entries(t.overrides??{})){if(!a.startsWith(`${o}.`))continue;let c=a.slice(o.length+1);s[c]={...s[c],...d}}let i={...r};return delete i.overrides,{...i,...Object.keys(s).length===0?{}:{overrides:s},children:[]}}return me(e)&&(r.children=e.children.map(o=>lb(o,t,n))),r}function _p(e,t,n){let r=z(e.root,t);if(r?.type!=="instance"||r.overrides===void 0)return[];if(n===void 0)return[{op:"set",id:t,prop:"overrides",value:void 0}];let o=n.startsWith(`${t}.`)?n.slice(t.length+1):n;if(r.overrides[o]===void 0)return[];let s={...r.overrides};return delete s[o],[{op:"set",id:t,prop:"overrides",value:Object.keys(s).length===0?void 0:s}]}function fb(e,t,n){let r=Zc(e.root,t);return r===void 0||!Jc(e.root,n,r)}function Ep(e,t,n){let r=z(e.root,t),o=lt(e.root),s=r?.type==="instance"?o.get(r.component):void 0,i=o.get(n);if(r?.type!=="instance"||!i||r.component===n)return[];if(!fb(e,t,n))return[];let a=new Map;s&&Mp(s.children,i.children,a);let d={};for(let[c,l]of Object.entries(r.overrides??{})){let p=z(i,c)?c:gb(c,a);z(i,p)&&(d[p]=l)}return[{op:"set",id:t,prop:"component",value:n},{op:"set",id:t,prop:"overrides",value:Object.keys(d).length===0?void 0:d}]}function Mp(e,t,n){e.forEach((r,o)=>{let s=t[o];!s||s.type!==r.type||(n.set(r.id,s.id),!(r.type==="instance"||s.type==="instance")&&Mp(te(r),te(s),n))})}function Cp(e,t,n,r){if(!Hn(e,t))return null;let o=z(e.root,n);if(!o||!me(o)||o.type==="instance"||Je(e,n))return null;let s=hs(t.replace(/\.main$/,""),cr(e.root)),i={type:"instance",id:s,component:t,x:Z(r.x),y:Z(r.y),children:[]};return{ops:[{op:"insert",parent:n,index:o.children.length,node:i}],id:s}}function Ud(e,t){return t.reduce((n,r)=>n+An(e.root,r).length,0)}function Ap(e,t,n){let r=[],o=e,s=new Set(t);for(let i=0;i<t.length+1;i+=1){let a=An(o.root).filter(d=>s.has(d.component)&&!Ke(o.root,d.id).some(c=>s.has(c)));if(a.length===0)break;for(let d of a){let c=Hd(o,d.id,n);c&&(r.push(...c),o=Ae(o,c).document)}}for(let i of t)r.push({op:"remove",id:i});return r}function Hi(e,t){let n=e.root.children.flatMap(i=>{let a=t.nodes.get(i.id);return!a||Ne(i)?[]:[{node:i,x:a.absX,y:a.absY,w:a.w,h:a.h}]}),r=n.filter(i=>i.node.type==="frame"&&i.node.component===!0);if(r.length>0){let i=Math.max(...r.map(d=>d.x+d.w)),a=Math.min(...r.map(d=>d.y));return{x:Z(i+vC),y:Z(a)}}if(n.length===0)return{x:0,y:0};let o=Math.min(...n.map(i=>i.x)),s=Math.max(...n.map(i=>i.y+i.h));return{x:Z(o),y:Z(s+bC)}}function cb(e,t,n){for(let r of t)de(r,o=>{n.add(Ht(e,o.id))})}function pb(e,t){let n={...e};for(let[r,o]of Object.entries(e))ve(o)&&(n[r]=zd(o.expr,t)??o);return e.type==="instance"||!me(e)?n:{...n,children:e.children.map(r=>pb(r,t))}}function hs(e,t){let n=e;for(let r=2;t.has(n);r+=1)n=`${e}.${r}`;return t.add(n),n}function SC(e,t){let n=1/0,r=1/0,o=-1/0,s=-1/0;for(let i of e)de(i,a=>{if("hidden"in a&&a.hidden===!0)return!1;if(Ne(a))return;let d=t.nodes.get(a.id);return d&&(n=Math.min(n,d.absX),r=Math.min(r,d.absY),o=Math.max(o,d.absX+d.w),s=Math.max(s,d.absY+d.h)),!1});return Number.isFinite(n)?{x:n,y:r,w:o-n,h:s-r}:null}function _C(e,t,n){let r=Ke(e.root,t);for(let o=r.length-1;o>=0;o-=1){let s=z(e.root,r[o]);if(!s||Ne(s))continue;let i=n.nodes.get(s.id);return i?{x:i.absX,y:i.absY}:{x:0,y:0}}return{x:0,y:0}}function hb(e,t,n){if(Ne(e))return{...e,children:te(e).map(o=>hb(o,t,n))};let r={...e};return typeof r.x=="number"&&(r.x=Z(r.x-t)),typeof r.y=="number"&&(r.y=Z(r.y-n)),r}function EC(e,t,n){let r=[];return de(e.root,o=>{if(o.type==="instance"||!t(o))return!1;for(let[s,i]of Object.entries(o)){if(!ve(i))continue;let a=zd(i.expr,n);a&&r.push({op:"set",id:o.id,prop:s,value:a})}}),r}function zd(e,t){let n=tt(e);if(n.ok&&on(n.ast).nodes.some(r=>t(r)!==void 0))return{expr:qr(gn(n.ast,t))}}function MC(e,t){let n=[];for(let[r,o]of Object.entries(e.motion??{})){let s=!1,i=o.lines.map(a=>{let d=t(a.id),c=a.after===void 0?void 0:t(a.after),l=a.with===void 0?void 0:t(a.with);return d===void 0&&c===void 0&&l===void 0?a:(s=!0,{...a,...d===void 0?{}:{id:d},...c===void 0?{}:{after:c},...l===void 0?{}:{with:l}})});if(s){let a={...o,lines:i};n.push({op:"setMotion",page:r,value:a})}}return n}function mb(e,t,n){let r=lt(e.root),o=cr(e.root),s=new Map,i=new Map,a=new Map,d=[];for(let p of t){let m=r.get(p.id);if(m&&CC(m,p)){s.set(p.id,p.id);continue}if(m&&n(p.id)){s.set(p.id,p.id);let w=new Map;Mp(p.children,m.children,w);let k=new Set;for(let _ of m.children)de(_,M=>{k.add(M.id)});for(let[_,M]of[...w])(k.has(_)||_===M)&&w.delete(_);i.set(p.id,w),a.set(p.id,k);continue}let g=o.has(p.id)?hs(p.id,o):p.id;o.add(g),s.set(p.id,g);let b=new Map;for(let w of p.children)de(w,k=>(o.has(k.id)?b.set(k.id,hs(k.id,o)):o.add(k.id),k.type==="instance"?!1:void 0));i.set(p.id,b),d.push(p)}let c=[],l=e;for(let p of d){let m={...xb(p,i.get(p.id)??new Map,s,i),id:s.get(p.id)??p.id,component:!0},g=Hi(l,Pe(l)),b={op:"insert",parent:l.root.id,index:l.root.children.length,node:{...m,x:g.x,y:g.y}};c.push(b),l=Ae(l,[b]).document}return{ops:c,component:s,keys:i,parts:a}}function jd(e,t){if(e.type==="instance"){let n=t.keys.get(e.component),r=t.parts?.get(e.component),o=Object.entries(e.overrides??{}).map(([i,a])=>[n===void 0?i:gb(i,n),a]).filter(([i])=>r===void 0||r.has(i)),s={...e,component:t.component.get(e.component)??e.component,overrides:Object.fromEntries(o),children:[]};return o.length===0&&delete s.overrides,s}return me(e)?{...e,children:e.children.map(n=>jd(n,t))}:e}function xb(e,t,n,r){let o={...e,id:t.get(e.id)??e.id};if(t.size>0)for(let[i,a]of Object.entries(e)){if(!ve(a))continue;let d=zd(a.expr,c=>t.get(c));d&&(o[i]=d)}let s=o;return s.type==="instance"?jd(s,{component:n,keys:r}):me(s)?{...s,children:s.children.map(i=>xb(i,t,n,r))}:s}function gb(e,t){let n=t.get(e);if(n!==void 0)return n;for(let[r,o]of t)if(e.startsWith(`${r}.`))return`${o}${e.slice(r.length)}`;return e}function CC(e,t){return Ua({...e,x:0,y:0})===Ua({...t,x:0,y:0})}function bb(e,t,n,r,o){if(o===0)return Vn(e,t,n,r);let s=je({x:n,y:r},{x:0,y:0},-o),i=Vn(e,t,s.x,s.y),a=Re(e),d=Re(i),c={x:a.x-d.x,y:a.y-d.y},l=je(c,{x:0,y:0},o);return{...i,x:i.x+c.x-l.x,y:i.y+c.y-l.y}}function yb(e,t){return Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI}function vb(e,t,n,r,o){let s=yb(e,n)-yb(e,t);return o?Math.round((r+s)/o)*o-r:s}function wb(e,t,n){return e.map(r=>{let o=Re(r.frame),s=je(o,t,n);return{id:r.id,frame:{...r.frame,x:s.x-r.frame.w/2,y:s.y-r.frame.h/2},rotation:Wo(r.rotation+n)}})}function Kd(e,t,n,r){let o=n.w===0?1:r.w/n.w,s=n.h===0?1:r.h/n.h,i=t*Math.PI/180,a=Math.cos(i),d=Math.sin(i),c=e.w*Math.hypot(o*a,s*d),l=e.h*Math.hypot(o*d,s*a),p=Re(e),m=r.x+(p.x-n.x)*o,g=r.y+(p.y-n.y)*s;return{x:m-c/2,y:g-l/2,w:c,h:l}}function it(e,t){return`${e}:${t}`}function Wd(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 kb(e){let t=e.split(":"),n=t[2],r=Wd(t.slice(0,2).join(":"));if(!(!r||n!=="in"&&n!=="out"))return{...r,side:n}}function Op(e,t){let n=Wd(t);return n?e[n.contour]?.anchors[n.index]:void 0}function Tp(e,t){let n=[];for(let r of t){let o=Wd(r);o&&e[o.contour]?.anchors[o.index]&&n.push(it(o.contour,o.index))}return n}function Lp(e){return e.flatMap((t,n)=>t.anchors.map((r,o)=>it(n,o)))}function $p(e,t,n,r){return e.map((o,s)=>s===t?{...o,anchors:o.anchors.map((i,a)=>a===n?r:i)}:o)}var Ui=(e,t,n)=>({x:e.x+t,y:e.y+n});function Xd(e,t,n,r){return e.map((o,s)=>({...o,anchors:o.anchors.map((i,a)=>t.has(it(s,a))?fn(Ui(i,n,r),i.in&&Ui(i.in,n,r),i.out&&Ui(i.out,n,r)):i)}))}function Gd(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,s=Math.hypot(t,n),i=Math.hypot(r,o);return s===0||i===0?!1:(t*r+n*o)/(s*i)<-.995}function qd(e,t,n,r,o,s){let i=e[t]?.anchors[n];if(!i)return[...e];let d=i[r==="in"?"out":"in"];if(s.smooth&&!s.breakSmooth&&d){let l=Math.hypot(d.x-i.x,d.y-i.y),p=o.x-i.x,m=o.y-i.y,g=Math.hypot(p,m);g>0&&(d={x:i.x-p/g*l,y:i.y-m/g*l})}let c=r==="in"?fn(i,o,d):fn(i,d,o);return $p(e,t,n,c)}function Sb(e,t){let n=Wd(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 $p(e,n.contour,n.index,fn(o));let s=r.anchors.length,i=n.index>0?r.anchors[n.index-1]:r.closed?r.anchors[s-1]:void 0,a=n.index<s-1?r.anchors[n.index+1]:r.closed?r.anchors[0]:void 0;if(!i&&!a)return[...e];let d=i??o,c=a??o,l=c.x-d.x,p=c.y-d.y,m=Math.hypot(l,p);if(m===0)return[...e];l/=m,p/=m;let g=i?Math.hypot(o.x-i.x,o.y-i.y)/3:0,b=a?Math.hypot(a.x-o.x,a.y-o.y)/3:0,w=i?{x:o.x-l*g,y:o.y-p*g}:void 0,k=a?{x:o.x+l*b,y:o.y+p*b}:void 0;return $p(e,n.contour,n.index,fn(o,w,k))}function _b(e,t){let n=[];return e.forEach((r,o)=>{let s=r.anchors.filter((i,a)=>!t.has(it(o,a)));s.length>=2&&n.push({closed:r.closed,anchors:s})}),n}function Eb(e,t,n,r,o,s,i){let a=e[t];if(!a)return[...e];let d=a.anchors.length,c=(n+1)%d;if(i)return Xd(e,new Set([it(t,n),it(t,c)]),o,s);let l=Math.min(.85,Math.max(.15,r)),p=1/(3*(1-l)*l),m=a.anchors[n],g=a.anchors[c],b=Ui(m.out??m,o*p,s*p),w=Ui(g.in??g,o*p,s*p),k=qd(e,t,n,"out",b,{smooth:Gd(m),breakSmooth:!1});return k=qd(k,t,c,"in",w,{smooth:Gd(g),breakSmooth:!1}),k}function Mb(e,t){return e.map((n,r)=>n.closed||n.anchors.length<2?n:t.size===0||t.has(it(r,0))&&t.has(it(r,n.anchors.length-1))?{...n,closed:!0}:n)}function Pp(e,t){let n=[],r=new Set,o=(s,i,a)=>{let d=e[s]?.anchors[i],c=d?.[a],l=`${it(s,i)}:${a}`;!d||!c||r.has(l)||(r.add(l),n.push({key:l,at:c,anchor:d}))};return e.forEach((s,i)=>{let a=s.anchors.length;s.anchors.forEach((d,c)=>{if(!t.has(it(i,c)))return;o(i,c,"in"),o(i,c,"out");let l=c>0?c-1:s.closed?a-1:-1,p=c<a-1?c+1:s.closed?0:-1;l>=0&&o(i,l,"out"),p>=0&&o(i,p,"in")})}),n}function zi(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),s=n*Math.cos(o)+r*Math.sin(o);return{x:e.x+Math.cos(o)*s,y:e.y+Math.sin(o)*s}}function Cb(e){return{closed:e.closed,anchors:[...e.anchors].reverse().map(t=>fn(t,t.out,t.in))}}var Ab=new Set(["video/mp4","video/webm"]),AC=/\.(mp4|m4v|webm)$/i;function $b(e){return Ab.has(e.type)||e.type===""&&AC.test(e.name)}function Ob(e){return Ab.has(e.type)?e.type:/\.webm$/i.test(e.name)?"video/webm":"video/mp4"}function Tb(e,t=5e3){let n=URL.createObjectURL(e),r=document.createElement("video");return r.muted=!0,r.preload="metadata",new Promise(o=>{let s=a=>{clearTimeout(i),r.removeAttribute("src"),r.load(),URL.revokeObjectURL(n),o(a)},i=setTimeout(()=>s(null),t);r.addEventListener("loadedmetadata",()=>{if(!(r.videoWidth>0&&r.videoHeight>0)){s(null);return}let a=Number.isFinite(r.duration)?Math.round(r.duration*1e3):void 0;s({width:r.videoWidth,height:r.videoHeight,...a===void 0||a<=0?{}:{ms:a}})}),r.addEventListener("error",()=>s(null)),r.src=n})}function Dp(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 Yd(e,t){if(Lb(e))return TC(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 $C(n,r,e.type)}finally{n.close()}}async function $C(e,t,n){let r=Math.max(1,Math.round(e.width*t)),o=Math.max(1,Math.round(e.height*t)),s=document.createElement("canvas");s.width=r,s.height=o;let i=s.getContext("2d");if(!i)return null;i.drawImage(e,0,0,r,o);let a=n==="image/png"?"image/png":"image/webp",d=await new Promise(c=>{s.toBlob(c,a,.9)});return d?{bytes:new Uint8Array(await d.arrayBuffer()),type:d.type||a,width:r,height:o}:null}function Np(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 Lb(e){return e.type==="image/svg+xml"||/\.svg$/i.test(e.name??"")}var OC=1024;function Pb(e){let t=/<svg\b[^>]*>/i.exec(e)?.[0];if(t===void 0)return null;let n=c=>new RegExp(`\\s${c}\\s*=\\s*["']([^"']*)["']`,"i").exec(t)?.[1],r=c=>{let l=/^\s*([\d.]+)\s*(px)?\s*$/i.exec(c??""),p=l===null?NaN:Number(l[1]);return p>0?p:void 0},o=r(n("width")),s=r(n("height"));if(o!==void 0&&s!==void 0)return{width:o,height:s};let i=(n("viewBox")??"").trim().split(/[\s,]+/).map(Number),[,,a=NaN,d=NaN]=i;return i.length===4&&a>0&&d>0?o!==void 0?{width:o,height:o*d/a}:s!==void 0?{width:s*a/d,height:s}:{width:a,height:d}:null}async function TC(e,t){let n=await e.text(),r=Pb(n);if(r===null)return null;let o=Math.min(t,OC)/Math.max(r.width,r.height),s=Math.max(1,Math.round(r.width*o)),i=Math.max(1,Math.round(r.height*o)),a=n.replace(/<svg\b[^>]*>/i,c=>c.replace(/\s(width|height)\s*=\s*["'][^"']*["']/gi,"").replace(/^<svg/i,`<svg width="${s}" height="${i}"`)),d=URL.createObjectURL(new Blob([a],{type:"image/svg+xml"}));try{let c=new Image;c.src=d,await c.decode();let l=document.createElement("canvas");l.width=s,l.height=i;let p=l.getContext("2d");if(!p)return null;p.drawImage(c,0,0,s,i);let m=await new Promise(g=>{l.toBlob(g,"image/png")});return m?{bytes:new Uint8Array(await m.arrayBuffer()),type:"image/png",width:s,height:i}:null}catch{return null}finally{URL.revokeObjectURL(d)}}function Jd(e){let t=Ln(e);return e.root.children.filter(n=>t.has(n.id)&&Nr(e.motion?.[n.id])).map(n=>n.id)}function Zd(e,t,n){let r=Jd(e);if(r.length===0)return null;let o=Ut(e);for(let s of t){let i=o.get(s);if(i!==void 0&&r.includes(i))return i}return n!==null&&r.includes(n)?n:r[0]??null}var LC=1e3/30;var PC=/\.(?:mp3|m4a|aac|wav|ogg|oga|opus|flac|webm)$/i;function Db(e){return e.type.startsWith("audio/")||e.type===""&&PC.test(e.name)}var DC=new Set(["loop","step","together"]);function Nb(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)||DC.has(o))&&(o=`track-${o}`),e.assets[o]===void 0)return o;for(let s=2;;s+=1)if(e.assets[`${o}-${s}`]===void 0)return`${o}-${s}`}function Rb(e,t,n,r){let o=e.motion?.[t]??{lines:[]},s=o.music,i={asset:n};if(s&&s.asset===n)i=s;else if(s){let a={...s,asset:n};delete a.from,i=a}return[{op:"setAsset",name:n,value:r},{op:"setMotion",page:t,value:{...o,music:i}}]}var NC={left:"x",hcenter:"x",right:"x",top:"y",vcenter:"y",bottom:"y"};function Qd(e){return NC[e]}function RC(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 Rp(e,t,n){let r=Qd(n),o=new Map;for(let s of e){let i=r==="x"?s.frame.w:s.frame.h,a=r==="x"?s.frame.x:s.frame.y;o.set(s.id,RC(n,t,i)-a)}return o}var Ip=24,Fb=[{key:"nw",sx:0,sy:0,prop:"radiusTL"},{key:"ne",sx:1,sy:0,prop:"radiusTR"},{key:"se",sx:1,sy:1,prop:"radiusBR"},{key:"sw",sx:0,sy:1,prop:"radiusBL"}],IC={id:"radius",props:["radius",...Bt],handles(e,t,n,r){let o=this.max(t),s=Ao(Zn(n),t.w,t.h),i=zs(e);return Fb.map(({key:a,sx:d,sy:c,prop:l})=>{let p=Hc(s,l),m=Math.min(Math.max(p,r),Math.max(o,r));return{id:`radius:${a}`,prop:i?l:"radius",at:{x:t.x+(d===0?m:t.w-m),y:t.y+(c===0?m:t.h-m)}}})},propOf(e,t,n){let r=Ib(t);return r&&(n||zs(e))?r.prop:"radius"},valueAt(e,t,n){let r=Ib(t);if(!r)return 0;let o=e.x+(r.sx===0?0:e.w),s=e.y+(r.sy===0?0:e.h),i=Math.max(0,r.sx===0?n.x-o:o-n.x),a=Math.max(0,r.sy===0?n.y-s:s-n.y);return Math.min((i+a)/2,this.max(e))},max(e){return Math.max(0,Math.min(e.w,e.h)/2)}},FC={canvas:[],frame:[],group:[],rect:[IC]};function ji(e){return FC[e.type]??[]}function eu(e,t){let n=t.split(":")[0];return ji(e).find(r=>r.id===n)}function Ib(e){let t=e.split(":")[1];return Fb.find(n=>n.key===t)}var Fp=[["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 Bp=[["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 Vp=[["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 Hp=[["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 Up=[["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 zp=[["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 jp=[["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 Kp=[["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 Gp=[["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 qp=[["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 Wp=[["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 Xp=[["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 Yp=[["circle",{cx:"15",cy:"9",r:"7"}],["circle",{cx:"9",cy:"15",r:"7"}]];var Jp=[["path",{d:"M20 6 9 17l-5-5"}]];var Zp=[["path",{d:"m6 9 6 6 6-6"}]];var Qp=[["path",{d:"m9 18 6-6-6-6"}]];var eh=[["path",{d:"m18 15-6-6-6 6"}]];var th=[["path",{d:"M10.1 2.182a10 10 0 0 1 3.8 0"}],["path",{d:"M13.9 21.818a10 10 0 0 1-3.8 0"}],["path",{d:"M17.609 3.721a10 10 0 0 1 2.69 2.7"}],["path",{d:"M2.182 13.9a10 10 0 0 1 0-3.8"}],["path",{d:"M20.279 17.609a10 10 0 0 1-2.7 2.69"}],["path",{d:"M21.818 10.1a10 10 0 0 1 0 3.8"}],["path",{d:"M3.721 6.391a10 10 0 0 1 2.7-2.69"}],["path",{d:"M6.391 20.279a10 10 0 0 1-2.69-2.7"}]];var nh=[["circle",{cx:"12",cy:"12",r:"10"}]];var rh=[["path",{d:"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z"}],["path",{d:"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z"}],["path",{d:"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z"}],["path",{d:"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z"}]];var oh=[["path",{d:"M6 2v14a2 2 0 0 0 2 2h14"}],["path",{d:"M18 22V8a2 2 0 0 0-2-2H2"}]];var sh=[["path",{d:"M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41l-7.59-7.59a2.41 2.41 0 0 0-3.41 0Z"}]];var ih=[["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 ah=[["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 dh=[["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 uh=[["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 ch=[["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 lh=[["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 fh=[["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 ph=[["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 tu=[["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 hh=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}]];var mh=[["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 xh=[["path",{d:"M5 12h14"}]];var gh=[["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 yh=[["path",{d:"m18 8 4 4-4 4"}],["path",{d:"M2 12h20"}],["path",{d:"m6 8-4 4 4 4"}]];var bh=[["path",{d:"M13 5H19V11"}],["path",{d:"M19 5L5 19"}]];var vh=[["path",{d:"M12 2v20"}],["path",{d:"m8 18 4 4 4-4"}],["path",{d:"m8 6 4-4 4 4"}]];var wh=[["path",{d:"M9 18V5l12-2v13"}],["circle",{cx:"6",cy:"18",r:"3"}],["circle",{cx:"18",cy:"16",r:"3"}]];var kh=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"}]];var Sh=[["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 _h=[["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 Eh=[["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 Mh=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];var Ch=[["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 Ah=[["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 $h=[["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 Oh=[["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"}]];var Th=[["path",{d:"M22 2 2 22"}]];var Lh=[["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 Ph=[["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 Dh=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];var Nh=[["path",{d:"M16 12v2a2 2 0 0 1-2 2H9a1 1 0 0 0-1 1v3a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V10a2 2 0 0 0-2-2h0"}],["path",{d:"M4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v3a1 1 0 0 1-1 1h-5a2 2 0 0 0-2 2v2"}]];var Rh=[["path",{d:"M10 22a2 2 0 0 1-2-2"}],["path",{d:"M14 2a2 2 0 0 1 2 2"}],["path",{d:"M16 22h-2"}],["path",{d:"M2 10V8"}],["path",{d:"M2 4a2 2 0 0 1 2-2"}],["path",{d:"M20 8a2 2 0 0 1 2 2"}],["path",{d:"M22 14v2"}],["path",{d:"M22 20a2 2 0 0 1-2 2"}],["path",{d:"M4 16a2 2 0 0 1-2-2"}],["path",{d:"M8 10a2 2 0 0 1 2-2h5a1 1 0 0 1 1 1v5a2 2 0 0 1-2 2H9a1 1 0 0 1-1-1z"}],["path",{d:"M8 2h2"}]];var Ih=[["path",{d:"M10 22a2 2 0 0 1-2-2"}],["path",{d:"M16 22h-2"}],["path",{d:"M16 4a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h3a1 1 0 0 0 1-1v-5a2 2 0 0 1 2-2h5a1 1 0 0 0 1-1z"}],["path",{d:"M20 8a2 2 0 0 1 2 2"}],["path",{d:"M22 14v2"}],["path",{d:"M22 20a2 2 0 0 1-2 2"}]];var Fh=[["path",{d:"M4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v3a1 1 0 0 0 1 1h3a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2v-3a1 1 0 0 0-1-1z"}]];var nu=[["path",{d:"M21 5H3"}],["path",{d:"M21 12H9"}],["path",{d:"M21 19H7"}]];var ru=[["path",{d:"M21 5H3"}],["path",{d:"M17 12H7"}],["path",{d:"M19 19H5"}]];var ou=[["path",{d:"M3 5h18"}],["path",{d:"M3 12h18"}],["path",{d:"M3 19h18"}]];var Ki=[["path",{d:"M21 5H3"}],["path",{d:"M15 12H3"}],["path",{d:"M17 19H3"}]];var su=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}],["path",{d:"M12 9v4"}],["path",{d:"M12 17h.01"}]];var Bh=[["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 Vh=[["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 Hh=[["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 Uh=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"}]];var zh=[["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 jh=[["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 Kh=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var so=e=>e.replace(/\b(?:CmdOrCtrl|CommandOrControl)\b/g,"Ctrl");function Bb(e,t){let r=e.ownerDocument.createElement("div");r.className="vd-chrome",r.setAttribute("role","toolbar"),r.setAttribute("aria-label","Canvas tools"),r.innerHTML=BC(t),e.appendChild(r);let o=new Map;for(let l of r.querySelectorAll("[data-tool]"))o.set(l.dataset.tool,l);let s=r.querySelector('[data-act="undo"]'),i=r.querySelector('[data-act="redo"]'),a=r.querySelector('[data-act="zoom"]'),d=l=>{let p=l.target?.closest("button");if(!p)return;l.stopPropagation();let m=p.dataset.tool;if(m){t.onTool(m);return}switch(p.dataset.act){case"undo":t.onUndo();return;case"redo":t.onRedo();return;case"zoom":t.onZoomReset();return;case"play":t.onPlay?.();return}},c=l=>l.stopPropagation();return r.addEventListener("click",d),r.addEventListener("pointerdown",c),{element:r,setTool(l){for(let[p,m]of o)m.setAttribute("aria-pressed",String(p===l))},setHistory(l,p){s&&(s.disabled=!l),i&&(i.disabled=!p)},setZoom(l){a&&(a.textContent=`${Math.round(l*100)}%`)},destroy(){r.removeEventListener("click",d),r.removeEventListener("pointerdown",c),r.remove()}}}function BC(e){let t=e.formatKeys??so;return[vn({tool:"select",label:"Select",hint:"V",icon:"select"}),vn({tool:"frame",label:"Frame",hint:"F",icon:"frame"}),vn({tool:"rect",label:"Rectangle",hint:"R",icon:"rect"}),vn({tool:"ellipse",label:"Ellipse",hint:"O",icon:"ellipse"}),vn({tool:"line",label:"Line",hint:"L",icon:"line"}),vn({tool:"pen",label:"Pen",hint:"P",icon:"pen"}),vn({tool:"text",label:"Text",hint:"T",icon:"text"}),'<span class="vd-chrome__divider"></span>',vn({act:"undo",label:"Undo",hint:t("CmdOrCtrl+Z"),icon:"undo"}),vn({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>',vn({act:"play",label:"Play",hint:e.playHint,icon:"play"})]:[]].join("")}function vn(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}">`+bt(e.icon)+"</button>"}var VC={select:gh,frame:ch,rect:Dh,ellipse:nh,pen:Sh,line:Th,connector:bh,vector:Lh,text:Bh,undo:Vh,redo:Ch,"align-left":Kp,"align-hcenter":Vp,"align-right":Up,"align-top":jp,"align-vcenter":Bp,"align-bottom":Hp,"distribute-h":zp,"distribute-v":Gp,group:lh,component:rh,instance:sh,image:fh,video:Uh,eye:ah,"eye-off":dh,lock:hh,unlock:tu,chevron:Qp,"text-left":Ki,"text-center":ru,"text-right":nu,"text-justify":ou,"text-top":Xp,"text-middle":qp,"text-bottom":Wp,unlink:Hh,rotate:Ah,opacity:ih,radius:Ph,corners:Oh,blend:Yp,plus:Mh,minus:xh,close:Kh,"chevron-down":Zp,"chevron-up":eh,alert:su,check:Jp,link:ph,"font-size":Fp,"line-height":vh,"letter-spacing":yh,eyedropper:_h,document:uh,play:Eh,pause:kh,scan:$h,music:wh,metronome:mh,sound:zh,"sound-off":jh,union:Fh,subtract:Ih,intersect:Rh,exclude:Nh,mask:th,crop:oh};function bt(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">${VC[e].map(([n,r])=>{let o=Object.entries(r).filter(([s])=>s!=="key").map(([s,i])=>` ${s}="${String(i)}"`).join("");return`<${n}${o} vector-effect="non-scaling-stroke"/>`}).join("")}</svg>`}function Vb(e,t){let n=t.filter(a=>a!==e.root.id).flatMap(a=>z(e.root,a)??[]),r=n.filter(st),o=n.filter(yi);if(n.length!==2||r.length!==1||o.length!==1)return{ok:!1,why:"Select one image or video and one rect, ellipse or vector to mask it."};let s=r[0],i=o[0];return Lt(e.root,s.id)||Lt(e.root,i.id)?{ok:!1,why:"Parts of an instance cannot be masked here. Mask them in the component."}:fr(e.root,s.id)!==fr(e.root,i.id)?{ok:!1,why:"The image and the shape are on different pages. Move one across first."}:{ok:!0,pair:{image:s.id,shape:i.id}}}function Hb(e){return[{op:"set",id:e.image,prop:"mask",value:e.shape}]}function Ub(e,t){let n=Ye(e.root).links,r=new Set,o=s=>{st(s)&&s.mask!==void 0&&r.add(s.id);for(let[i,a]of n)a===s.id&&r.add(i);for(let i of te(s))o(i)};for(let s of t){let i=z(e.root,s);i&&s!==e.root.id&&o(i)}return[...r]}function Gh(e){return e.map(t=>({op:"set",id:t,prop:"mask",value:void 0}))}function qh(e,t,n=null){let r=Ye(e.root).links,o=new Set(t),s=[];for(let i of t){if(i===n)continue;let a=r.get(i);a===void 0||o.has(a)||(o.add(a),s.push(a))}return s}function ms(e,t){let n=Ye(e.root).links,r=new Set,o=[],s=a=>{r.add(a.id),n.has(a.id)&&o.push(a.id);for(let d of te(a))s(d)};for(let a of t){let d=z(e.root,a);d&&a!==e.root.id&&s(d)}let i=[];for(let a of o){let d=n.get(a);r.has(d)||i.includes(d)||i.push(d)}return i}function zb(e,t){return nd(e.root,t)}var Wh="clipboard";function Gi(e,t){let n=new Set(t),r=[];return de(e.root,o=>{if(o.id!==e.root.id&&n.has(o.id))return r.push(o),!1}),r}function jb(e,t){let n={};for(let s of e)de(s,i=>{for(let[a,d]of Object.entries(i)){if(ve(d)){let c=tt(d.expr);if(!c.ok)continue;for(let l of on(c.ast).tokens){let p=t[l];p!==void 0&&(n[l]=p)}continue}typeof d=="string"&&o(d),a==="shadow"&&typeof d=="string"&&r(d)}for(let a of Gb(i.content))o(a)});return n;function r(s){let i=t[s],d=es(typeof i=="string"?i:s);if(!("error"in d))for(let c of d.shadows)o(c.colour)}function o(s){for(let i of od(s)){let a=t[i];if(a!==void 0&&(n[i]=a,!(typeof a!="string"||a===s)))for(let d of od(a)){let c=t[d];c!==void 0&&d!==i&&(n[d]=c)}}}}function HC(e,t,n={}){let r={};for(let o of e)de(o,s=>{for(let i of sd(s,n)){let a=t[i];a!==void 0&&(r[i]=a)}});return r}function Kb(e,t){let n={},r=o=>{if(typeof o!="string")return;let s=t[o];s!==void 0&&(n[o]=s)};for(let o of e)de(o,s=>{let i=s;r(i.font);for(let a of Gb(i.content,"font"))r(a)});return n}function Gb(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 Xh(e,t,n){let r=Gi(e,[...t,...ms(e,t)]);if(r.length===0)return null;let o=UC(e,r),s=[...r,...o],i={};for(let c of r)de(c,l=>{let p=n.nodes.get(l.id)?.values;p&&Object.keys(p).length>0&&(i[l.id]=p)});let a={version:e.version,kind:e.kind,tokens:jb(s,e.tokens),fonts:Kb(s,e.fonts),assets:HC(s,e.assets,e.tokens),root:{...e.root,children:s}},d=JSON.parse(xl(a));return d[Wh]={resolved:i,...o.length===0?{}:{components:o.map(c=>c.id)}},JSON.stringify(d,null,2)}function UC(e,t){let n=lt(e.root),r=new Set(t.map(i=>i.id)),o=new Map,s=i=>{de(i,a=>{if(a.type!=="instance")return;let d=n.get(a.component);return d&&!r.has(d.id)&&!o.has(d.id)&&(o.set(d.id,d),s(d)),!1})};return t.forEach(s),[...o.values()]}function Yh(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}=sf(t),o=n[Wh],s=typeof o=="object"&&o!==null?o:{},i=s.resolved??{},a=Array.isArray(s.components)?new Set(s.components.filter(l=>typeof l=="string")):new Set,d=r.root.children.filter(l=>l.type==="frame"&&a.has(l.id)),c=r.root.children.filter(l=>!a.has(l.id));return c.length===0?null:{nodes:c,...d.length===0?{}:{components:d},tokens:r.tokens,fonts:r.fonts,resolved:typeof i=="object"&&i!==null?i:{}}}function Jh(e,t){let n=cr(t.root),r=new Map;for(let i of e.nodes)de(i,a=>{let d=zC(a.id,n);return n.add(d),r.set(a.id,d),a.type==="instance"?!1:void 0});let o=i=>n.has(i),s={...e.tokens,...t.tokens};return{nodes:e.nodes.map(i=>qb(i,{payload:e,remap:r,exists:o,tokens:s})),remap:r}}function zC(e,t){let n=e.lastIndexOf("."),r=n===-1?"":e.slice(n+1),o=/^[0-9]+$/.test(r)?e.slice(0,n):e,s=1;for(let i of t){if(!i.startsWith(`${o}.`))continue;let a=Number(i.slice(o.length+1));Number.isInteger(a)&&a>=s&&(s=a+1)}return`${o}.${s}`}function qb(e,t){let n=e,r={};for(let[o,s]of Object.entries(n))o==="id"||o==="children"||(r[o]=ve(s)?jC(s.expr,e.id,o,t):s);if(st(e)&&typeof e.mask=="string"){let o=t.remap.get(e.mask)??e.mask;t.remap.has(e.mask)||t.exists(o)?r.mask=o:delete r.mask}return r.id=t.remap.get(e.id)??e.id,e.type==="instance"?r.children=[]:me(e)&&(r.children=te(e).map(o=>qb(o,t))),r}function jC(e,t,n,r){let o={expr:e},s=tt(e);if(!s.ok)return o;let i=on(s.ast).nodes.some(l=>r.remap.has(l)),a=i?gn(s.ast,l=>r.remap.get(l)):s.ast,d=on(a);if(d.nodes.some(l=>!r.exists(l))||d.tokens.some(l=>r.tokens[l]===void 0)){let l=r.payload.resolved[t]?.[n];return l===void 0?o:l}return i?{expr:qr(a)}:o}var Un="#ffffff",yr="#0b0d0c",Zb="#c6ff3d",KC="#ffb224";var Wb=new Map;function at(e,t={}){let n=t.badge??"none",r=e==="resize"?Qb(t.angle??0):e==="rotate"?qC(t.angle??0):0,o=`${e}:${r}:${n}`,s=Wb.get(o);if(s!==void 0)return s;let{at:i,fallback:a}=GC[e],d=YC(WC(e,r,n),i[0],i[1],a);return Wb.set(o,d),d}var Xb=[2,2],xs=[12,12],GC={arrow:{at:Xb,fallback:"default"},radius:{at:Xb,fallback:"default"},resize:{at:xs,fallback:"ew-resize"},rotate:{at:xs,fallback:"crosshair"},crosshair:{at:xs,fallback:"crosshair"},grab:{at:xs,fallback:"grab"},grabbing:{at:xs,fallback:"grabbing"},text:{at:xs,fallback:"text"}};function qC(e){let t=(e%360+360)%360;return Math.round(t/15)*15%360}function Qb(e){let t=(e%180+180)%180;return Math.round(t/15)*15%180}function WC(e,t,n){switch(e){case"arrow":return ev(n);case"resize":return JC(t,n);case"rotate":return ZC(t);case"crosshair":return e2();case"grab":return Jb(!1);case"grabbing":return Jb(!0);case"radius":return t2(n);case"text":return QC()}}function XC(e){return`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">${e}</svg>`}function YC(e,t,n,r){return`url("data:image/svg+xml,${encodeURIComponent(XC(e))}") ${t} ${n}, ${r}`}var Yb="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 ev(e){return`<path d="${Yb}" fill="${Un}" stroke="${Un}" stroke-width="3" stroke-linejoin="round"/><path d="${Yb}" fill="${yr}"/>`+tv(e)}function JC(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,s)=>n.map(i=>`<path d="${i}" stroke="${s}" stroke-width="${o}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+r(3.6,Un)+r(1.6,yr)+"</g>"+tv(t)}function ZC(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(s=>`<path d="${s}" stroke="${o}" stroke-width="${r}"/>`).join("");return`<g transform="rotate(${e} 12 12)" fill="none" stroke-linecap="round" stroke-linejoin="round">`+n(3.6,Un)+n(1.6,yr)+"</g>"}function QC(){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,Un)+t(1.5,yr)+"</g>"}function e2(){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="${Un}" stroke-width="3"/><path d="${e}" stroke="${yr}" stroke-width="1.2"/></g>`}function Jb(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="${Un}" stroke-width="3.4"/><path d="${t}" stroke="${yr}" stroke-width="1.5"/></g>`}function t2(e){return ev("none")+n2(e)}function n2(e){return`<g><rect x="17.5" y="17.5" width="14" height="14" rx="4.5" fill="${Un}"/><rect x="18.7" y="18.7" width="11.6" height="11.6" rx="3.4" fill="${e==="none"?Zb:KC}"/><path d="M21.6 27.9 V25.4 A3.8 3.8 0 0 1 25.4 21.6 H27.9" fill="none" stroke="${yr}" stroke-width="1.5" stroke-linecap="round"/></g>`}function tv(e){return e==="none"?"":`<g><rect x="18.5" y="18.5" width="13" height="13" rx="4" fill="${Un}"/><rect x="19.6" y="19.6" width="10.8" height="10.8" rx="3" fill="${Zb}"/><text x="25" y="28.4" text-anchor="middle" fill="${yr}" font-family="ui-sans-serif, system-ui, -apple-system, Helvetica, sans-serif" font-size="10" font-weight="700">${e==="token"?"$":"\u0192"}</text></g>`}var Zh=6,zn=.01,dt={dx:0,dy:0,guides:[],measures:[]},iu=["lo","mid","hi"];function Qh(e,t,n){let r=[],o=(s,i)=>{let a=t.nodes.get(s);a&&r.push({id:s,frame:Fi(a),isPage:i})};return e.root.w!==void 0&&e.root.h!==void 0&&o(e.root.id,!0),de(e.root,s=>{if(n.has(s.id)||"hidden"in s&&s.hidden===!0)return!1;if(s.id!==e.root.id){if(s.type==="instance"){o(s.id,!1);return}if(s.type==="frame"){o(s.id,!0);return}me(s)||o(s.id,!1)}}),r}function em(e,t,n){if(n<=0||t.length===0)return dt;let r=gs("x",e,t,n,iu,!0),o=gs("y",e,t,n,iu,!0);return tm(e,t,r,o)}function au(e,t,n,r){if(r<=0||n.length===0)return dt;let o=t.includes("w")?["lo"]:t.includes("e")?["hi"]:[],s=t.includes("n")?["lo"]:t.includes("s")?["hi"]:[],i=gs("x",e,n,r,o,!1),a=gs("y",e,n,r,s,!1);return tm(e,n,i,a)}function du(e,t,n){let r={x:e.x,y:e.y,w:0,h:0};if(n<=0||t.length===0)return dt;let o=gs("x",r,t,n,["lo"],!1),s=gs("y",r,t,n,["lo"],!1);return tm(r,t,o,s)}function gs(e,t,n,r,o,s){let i={axis:e,delta:0,kind:"none"};if(o.length===0)return i;let a=r2(e,t,n,r,o),d=s?s2(e,t,n,r):null;return a&&d?Math.abs(d.delta)<Math.abs(a.delta)-zn?{axis:e,delta:d.delta,kind:"space",gap:d.gap}:{axis:e,delta:a.delta,kind:"align",at:a.at}:a?{axis:e,delta:a.delta,kind:"align",at:a.at}:d?{axis:e,delta:d.delta,kind:"space",gap:d.gap}:i}function r2(e,t,n,r,o){let s=null;for(let i of n)for(let a of iu){let d=$e(i.frame,e,a);for(let c of o){let l=d-$e(t,e,c);if(Math.abs(l)>r)continue;let p=c==="mid"&&a==="mid";(s===null||o2(l,p,s))&&(s={at:d,delta:l,centred:p})}}return s?{at:s.at,delta:s.delta}:null}function o2(e,t,n){let r=Math.abs(e),o=Math.abs(n.delta);return r<o-zn?!0:r>o+zn?!1:t&&!n.centred}function s2(e,t,n,r){let o=nv(e,t,n);if(o.length<2)return null;let s=rv(t,e),i=$e(t,e,"lo"),a=[];for(let c of i2(o,e))for(let l of o)a.push({delta:$e(l,e,"hi")+c-i,gap:c}),a.push({delta:$e(l,e,"lo")-c-s-i,gap:c});for(let c=0;c+1<o.length;c+=1){let l=o[c],p=o[c+1];if(!l||!p)continue;let m=$e(p,e,"lo")-$e(l,e,"hi")-s;m<=zn||a.push({delta:$e(l,e,"hi")+m/2-i,gap:m/2})}let d=null;for(let c of a)Math.abs(c.delta)>r||(d===null||Math.abs(c.delta)<Math.abs(d.delta)-zn)&&(d=c);return d}function nv(e,t,n){let r=nm(e);return n.filter(o=>!o.isPage&&u2(o.frame,t,r)).map(o=>o.frame).sort((o,s)=>$e(o,e,"lo")-$e(s,e,"lo"))}function i2(e,t){let n=[];for(let r=0;r+1<e.length;r+=1){let o=e[r],s=e[r+1];if(!o||!s)continue;let i=$e(s,t,"lo")-$e(o,t,"hi");i<=zn||n.some(a=>Math.abs(a-i)<zn)||n.push(i)}return n}function tm(e,t,n,r){let o={...e,x:e.x+n.delta,y:e.y+r.delta},s=[],i=[];for(let a of[n,r]){if(a.kind==="align"&&a.at!==void 0){let d=a2(a.axis,a.at,o,t);d&&s.push(d)}a.kind==="space"&&a.gap!==void 0&&i.push(...d2(a.axis,a.gap,o,t))}return{dx:n.delta,dy:r.delta,guides:s,measures:i}}function a2(e,t,n,r){let o=nm(e),s=$e(n,o,"lo"),i=$e(n,o,"hi"),a=!1;for(let d of r)iu.some(c=>c2($e(d.frame,e,c),t))&&(a=!0,s=Math.min(s,$e(d.frame,o,"lo")),i=Math.max(i,$e(d.frame,o,"hi")));return a?{axis:e,at:t,from:s,to:i}:null}function d2(e,t,n,r){let o=nm(e),s=[...nv(e,n,r),n].sort((a,d)=>$e(a,e,"lo")-$e(d,e,"lo")),i=[];for(let a=0;a+1<s.length;a+=1){let d=s[a],c=s[a+1];if(!d||!c)continue;let l=$e(c,e,"lo")-$e(d,e,"hi");if(Math.abs(l-t)>zn)continue;let p=Math.max($e(d,o,"lo"),$e(c,o,"lo")),m=Math.min($e(d,o,"hi"),$e(c,o,"hi"));i.push({axis:e,at:(p+m)/2,from:$e(d,e,"hi"),to:$e(c,e,"lo"),label:l2(l)})}return i}function nm(e){return e==="x"?"y":"x"}function rv(e,t){return t==="x"?e.w:e.h}function $e(e,t,n){let r=t==="x"?e.x:e.y,o=rv(e,t);return n==="lo"?r:n==="hi"?r+o:r+o/2}function u2(e,t,n){return $e(e,n,"lo")<$e(t,n,"hi")&&$e(e,n,"hi")>$e(t,n,"lo")}function c2(e,t){return Math.abs(e-t)<zn}function l2(e){return String(Math.round(e*100)/100)}var qi=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 ov=1,f2=48,p2=.06,h2=.5;function sv(e){return Math.max(f2,Math.min(e.width,e.height)*p2)}function rm(e,t){let n=new Set(t),r=[];for(let o of e.root.children)(n.has(o.id)||iv(o,n))&&r.push(o.id);return r}function iv(e,t){for(let n of te(e))if(t.has(n.id)||iv(n,t))return!0;return!1}function uu(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)),s=Math.max(...t.map(i=>i.y+i.h));return{x:n,y:r,w:o-n,h:s-r}}function cu(e,t){let n=sv(t),r={width:Math.max(1,t.width-n*2),height:Math.max(1,t.height-n*2)},o=ds(Math.min(r.width/e.w,r.height/e.h,ov));return{zoom:o,x:t.width/2-(e.x+e.w/2)*o,y:t.height/2-(e.y+e.h/2)*o}}function om(e,t,n){let r=cu(e,t);return m2(e,t,n)&&n.zoom>=r.zoom*h2?null:r}function m2(e,t,n){let r=e.x*n.zoom+n.x,o=e.y*n.zoom+n.y,s=(e.x+e.w)*n.zoom+n.x,i=(e.y+e.h)*n.zoom+n.y;return r>=0&&o>=0&&s<=t.width&&i<=t.height}function av(e,t,n,r){let o=Math.exp(Math.log(e.zoom)+(Math.log(t.zoom)-Math.log(e.zoom))*n),s={x:r.width/2,y:r.height/2},i={x:(s.x-e.x)/e.zoom,y:(s.y-e.y)/e.zoom},a={x:(s.x-t.x)/t.zoom,y:(s.y-t.y)/t.zoom},d={x:i.x+(a.x-i.x)*n,y:i.y+(a.y-i.y)*n};return{zoom:o,x:s.x-d.x*o,y:s.y-d.y*o}}function dv(e){return 1-(1-e)**3}function lu(e){let t=e.nodeId??"A shape";switch(e.code){case"merge-too-few":return"Select two or more shapes to merge them.";case"merge-not-a-shape":return e.message.includes(" is text")?`${t} is text. Only rects, ellipses and vectors merge.`:`${t} is not a shape. Only rects, ellipses and vectors merge.`;case"merge-stroke-only":return e.message.includes("paints nothing")?`${t} paints nothing. Merge works on filled areas.`:`${t} is only a stroke. Merge works on filled areas.`;case"merge-hidden":return`${t} is hidden. Show it to merge it.`;case"merge-in-instance":return"Parts of an instance cannot merge. Merge them in the component.";case"merge-across-frames":return"These are on different pages or frames, so they cannot merge.";case"unknown-reference":return`${t} is no longer in the document.`;default:return`${e.message}.`}}function x2(e){return!("separator"in e)}function sm(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"},...uv(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.mask?.crop&&e.count===1&&r.push({id:"crop",label:"Crop image",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}),r.push(...y2(e)),r.push(...g2(e)),r.push(...b2(e.components));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 s of e.bound)r.push({id:`detach:${s.prop}`,label:`Detach ${s.prop}`,hint:s.source})}return r.push(...uv(e)),r.push(...n),r.push({separator:!0},{id:"delete",label:v2(e),keys:"Delete"}),r}function g2(e){let t=e.mask;if(!t)return[];let n=[];return t.offer&&n.push({id:"mask",label:"Mask with shape",keys:"CmdOrCtrl+Alt+M",disabled:!t.can}),t.release&&n.push({id:"releaseMask",label:"Release mask",keys:"CmdOrCtrl+Alt+M"}),n.length===0?[]:[...n,{separator:!0}]}function y2(e){if(e.mergeable===void 0||e.count<2)return[];let t=!e.mergeable;return[{separator:!0},{id:"merge:union",label:"Union selection",keys:"Alt+Shift+U",disabled:t},{id:"merge:subtract",label:"Subtract selection",keys:"Alt+Shift+S",disabled:t},{id:"merge:intersect",label:"Intersect selection",keys:"Alt+Shift+I",disabled:t},{id:"merge:exclude",label:"Exclude selection",keys:"Alt+Shift+X",disabled:t}]}function b2(e){if(!e)return[];let t=[];return e.create&&t.push({id:"createComponent",label:"Create component",keys:"CmdOrCtrl+Alt+K"}),e.instance&&t.push({id:"goToComponent",label:"Go to component"},{id:"resetOverrides",label:"Reset overrides",disabled:e.overrides===0},{id:"detachInstance",label:"Detach instance",keys:"CmdOrCtrl+Alt+B"}),e.part&&t.push({id:"goToComponent",label:"Go to component"},{id:"resetOverrides",label:"Reset this part",disabled:e.overrides===0}),e.component&&t.push({id:"placeInstance",label:"Place instance"}),t.length===0?[]:[{separator:!0},...t]}function v2(e){let t=e.components;return t?.part?"Hide on this instance":t&&t.uses>0?`Delete and detach ${t.uses} ${t.uses===1?"use":"uses"}`:"Delete"}var w2=4;function uv(e){let t=(e.locksHere??[]).slice(0,w2).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 fu(e,t){let n=e.ownerDocument,r=t.formatKeys??so,o=n.createElement("div");o.className="vd-menu",o.setAttribute("role","menu"),o.hidden=!0,e.appendChild(o);let s=!1,i=[],a=-1;function d(k){o.replaceChildren(),i=[];for(let _ of k){if(!x2(_)){let D=n.createElement("div");D.className="vd-menu__separator",o.appendChild(D);continue}let M=n.createElement("button");M.type="button",M.className="vd-menu__item",M.dataset.command=_.id,M.disabled=_.disabled===!0,M.setAttribute("role","menuitem");let R=n.createElement("span");R.textContent=_.label,M.appendChild(R);let B=_.hint??(_.keys===void 0?void 0:r(_.keys));if(B!==void 0){let D=n.createElement("span");D.className="vd-menu__hint",D.textContent=B,M.appendChild(D)}o.appendChild(M),M.disabled||i.push(M)}}function c(k){o.style.left=`${k.x}px`,o.style.top=`${k.y}px`;let _=e.getBoundingClientRect(),M=t.bounds?.()??_,R=o.getBoundingClientRect();if(R.width===0&&R.height===0)return;let B=_.left+k.x+R.width-M.right,D=_.top+k.y+R.height-M.bottom;B>0&&(o.style.left=`${Math.max(M.left-_.left,k.x-R.width)}px`),D>0&&(o.style.top=`${Math.max(M.top-_.top,k.y-R.height)}px`)}function l(k){i.length!==0&&(a=(k+i.length)%i.length,i[a]?.focus())}let p=k=>{let _=k.target?.closest("button");if(!_||_.disabled)return;k.stopPropagation();let M=_.dataset.command;w(),M&&t.onCommand(M)},m=k=>k.stopPropagation(),g=k=>{k.key==="ArrowDown"?(k.preventDefault(),l(a+1)):k.key==="ArrowUp"?(k.preventDefault(),l(a-1)):k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),w(),t.returnFocus?t.returnFocus():e.focus())},b=k=>{s&&(k.target instanceof Node&&o.contains(k.target)||w())};function w(){s&&(s=!1,a=-1,o.hidden=!0,n.removeEventListener("pointerdown",b,!0),n.removeEventListener("wheel",b,!0))}return o.addEventListener("click",p),o.addEventListener("pointerdown",m),o.addEventListener("keydown",g),{element:o,get isOpen(){return s},open(k,_){d(_),o.hidden=!1,s=!0,c(k),n.addEventListener("pointerdown",b,!0),n.addEventListener("wheel",b,!0),l(0)},close:w,destroy(){w(),o.removeEventListener("click",p),o.removeEventListener("pointerdown",m),o.removeEventListener("keydown",g),o.remove()}}}var ys=2,cv=1.5,im=1.5,lv=1.5,wv={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},fv=3.6,k2=22,pu=14,hu=15,am=4,pv=15,hv=23,io=7,mv=3.5,br=12,S2=4.5,mu=16,Dt=18,dm=9,um=6.1,xv="Drop or double-click",_2=6.4,gv=16,vr=3,yv=5,E2=11,bv=6,vv=6.4;function kv(e,t){let n=e.ownerDocument,r=n.createElementNS(le,"svg");r.setAttribute("class","vd-editor__overlay"),e.appendChild(r);let o=[],s=[],i=[],a=[],d=[],c=[],l=null,p=null,m=[],g=[];function b(v){let N=t({x:v.x,y:v.y}),I=t({x:v.x+v.w,y:v.y+v.h});return{x:N.x,y:N.y,w:I.x-N.x,h:I.y-N.y}}function w(v){for(;r.firstChild;)r.removeChild(r.firstChild);o=[],s=[],i=[],a=[],d=[],c=[],l=null,p=null,m=[],g=(v.pageLabels??[]).flatMap(I=>G(I));let N=v.turn&&v.turn.angle!==0?{angle:v.turn.angle,centre:t(v.turn.centre)}:null;for(let I of v.slots??[])fe(I);v.presence&&oe(v.presence);for(let I of v.highlight)Se("vd-editor__highlight",bs(b(I),ys),ys);if(v.lockHint&&ee(v.lockHint),v.hover&&Se("vd-editor__hover",ao(b(v.hover)),im),v.hoverLine){let I=n.createElementNS(le,"path");I.setAttribute("class","vd-editor__hover"),I.setAttribute("d",ze(Be(v.hoverLine,t))),r.appendChild(I)}for(let I of v.parked)Se("vd-editor__parked",ao(b(I)),im);for(let I of v.members)Se("vd-editor__member",bs(b(I),cv),cv);v.lead&&Se("vd-editor__lead",ao(b(v.lead)),ys);for(let I of v.guides)$(I);for(let I of v.measures)P(I);_(N,()=>{for(let I of v.textSelection)r.appendChild(be("vd-editor__text-selection",b(I)))});for(let I of v.masks??[])R(I);if(v.box&&O(v.box),v.caret&&_(N,()=>D(v.caret)),a=v.rings.map(V),i=v.spacers.map(T),v.badge&&v.box){let I=b(v.box.frame),F=l?Math.max(...[{x:I.x,y:I.y},{x:I.x+I.w,y:I.y},{x:I.x,y:I.y+I.h},{x:I.x+I.w,y:I.y+I.h}].map(q=>je(q,l.centre,l.angle).y)):I.y+I.h;C(v.badge,{x:I.x+I.w/2,y:F+dm+Dt/2})}if(v.draft){let I=b(v.draft);if(v.draftEllipse){let F=n.createElementNS(le,"ellipse");F.setAttribute("class","vd-editor__draft"),F.setAttribute("cx",String(I.x+I.w/2)),F.setAttribute("cy",String(I.y+I.h/2)),F.setAttribute("rx",String(Math.abs(I.w)/2)),F.setAttribute("ry",String(Math.abs(I.h)/2)),r.appendChild(F)}else r.appendChild(be("vd-editor__draft",I))}v.marquee&&r.appendChild(be("vd-editor__marquee",b(v.marquee))),v.path&&(p=N,_(N,()=>B(v.path))),v.line&&k(v.line)}function k(v){v.target&&Se("vd-editor__hover",ao(b(v.target)),im);let N=t(v.from),I=t(v.to);if(v.draft){let q=n.createElementNS(le,"line");q.setAttribute("class","vd-editor__path"),q.setAttribute("x1",String(N.x)),q.setAttribute("y1",String(N.y)),q.setAttribute("x2",String(I.x)),q.setAttribute("y2",String(I.y)),r.appendChild(q)}for(let q of v.anchors){let Y=t(q),Q=n.createElementNS(le,"circle");Q.setAttribute("class","vd-editor__anchor"),Q.setAttribute("cx",String(Y.x)),Q.setAttribute("cy",String(Y.y)),Q.setAttribute("r",String(mv)),r.appendChild(Q)}if(v.chosen){let q=t(v.chosen),Y=n.createElementNS(le,"circle");Y.setAttribute("class","vd-editor__close"),Y.setAttribute("cx",String(q.x)),Y.setAttribute("cy",String(q.y)),Y.setAttribute("r",String(io)),r.appendChild(Y)}let F=[["start",N,v.attached.start],["end",I,v.attached.end]];for(let[q,Y,Q]of F){let Te=n.createElementNS(le,"circle");Te.setAttribute("class",Q?"vd-editor__anchor vd-editor__anchor--on":"vd-editor__anchor"),Te.setAttribute("cx",String(Y.x)),Te.setAttribute("cy",String(Y.y)),Te.setAttribute("r",String(io/2+1)),Te.setAttribute("data-end",q),r.appendChild(Te)}c=F.map(([q,Y])=>({end:q,rect:{x:Y.x-br/2,y:Y.y-br/2,w:br,h:br}})).reverse()}function _(v,N){if(!v){N();return}let I=r.childNodes.length;N();let F=n.createElementNS(le,"g");for(F.setAttribute("transform",`rotate(${v.angle} ${v.centre.x} ${v.centre.y})`);r.childNodes.length>I;)F.insertBefore(r.childNodes[r.childNodes.length-1],F.firstChild);r.appendChild(F)}function M(v,N){return N?je(v,N.centre,-N.angle):v}function R(v){if(v.ghost){let q=b(v.ghost.frame),Y=n.createElementNS(le,"image");Y.setAttribute("class","vd-editor__ghost"),Y.setAttribute("x",String(q.x)),Y.setAttribute("y",String(q.y)),Y.setAttribute("width",String(Math.max(0,q.w))),Y.setAttribute("height",String(Math.max(0,q.h))),Y.setAttribute("href",v.ghost.href),Y.setAttribute("preserveAspectRatio",v.ghost.aspect),v.ghost.rotation!==0&&Y.setAttribute("transform",`rotate(${v.ghost.rotation} ${q.x+q.w/2} ${q.y+q.h/2})`),r.appendChild(Y)}let N=ze(Be(v.contours,t)),I=n.createElementNS(le,"path");I.setAttribute("class","vd-editor__mask-halo"),I.setAttribute("d",N),r.appendChild(I);let F=n.createElementNS(le,"path");F.setAttribute("class",v.cropping?"vd-editor__mask vd-editor__mask--crop":"vd-editor__mask"),F.setAttribute("d",N),r.appendChild(F)}function B(v){let N=n.createElementNS(le,"path");if(N.setAttribute("class","vd-editor__path"),N.setAttribute("d",ze(Be(v.contours,t))),r.appendChild(N),v.pending){let F=t(v.pending.from),q=t(v.pending.to),Y=v.pending.c1?t(v.pending.c1):F,Q=n.createElementNS(le,"path");Q.setAttribute("class","vd-editor__pending"),Q.setAttribute("d",`M${F.x} ${F.y} C${Y.x} ${Y.y} ${q.x} ${q.y} ${q.x} ${q.y}`),r.appendChild(Q)}for(let F of v.handles){let q=t(F.at),Y=t(F.anchor),Q=n.createElementNS(le,"line");Q.setAttribute("class","vd-editor__arm"),Q.setAttribute("x1",String(Y.x)),Q.setAttribute("y1",String(Y.y)),Q.setAttribute("x2",String(q.x)),Q.setAttribute("y2",String(q.y)),r.appendChild(Q)}for(let F of v.handles){let q=t(F.at),Y=n.createElementNS(le,"circle");Y.setAttribute("class","vd-editor__knob"),Y.setAttribute("cx",String(q.x)),Y.setAttribute("cy",String(q.y)),Y.setAttribute("r",String(mv)),r.appendChild(Y)}for(let F of v.anchors){let q=t(F.at),Y=be(F.selected?"vd-editor__anchor vd-editor__anchor--on":"vd-editor__anchor",{x:Math.round(q.x-io/2)+.5,y:Math.round(q.y-io/2)+.5,w:io,h:io});Y.setAttribute("data-key",F.key),r.appendChild(Y)}if(v.closeAt){let F=t(v.closeAt),q=n.createElementNS(le,"circle");q.setAttribute("class","vd-editor__close"),q.setAttribute("cx",String(F.x)),q.setAttribute("cy",String(F.y)),q.setAttribute("r",String(io)),r.appendChild(q)}let I=F=>({x:F.x-br/2,y:F.y-br/2,w:br,h:br});d=[...[...v.handles].reverse().map(F=>({kind:"handle",key:F.key,rect:I(t(F.at))})),...[...v.anchors].reverse().map(F=>({kind:"anchor",key:F.key,rect:I(t(F.at))}))]}function D(v){let N=t({x:v.x,y:v.y}),I=t({x:v.x,y:v.y+v.h}),F=n.createElementNS(le,"line");F.setAttribute("class","vd-editor__caret");let q=Math.round(N.x)+.5;F.setAttribute("x1",String(q)),F.setAttribute("y1",String(N.y)),F.setAttribute("x2",String(q)),F.setAttribute("y2",String(I.y)),v.fill!==void 0&&!v.fill.startsWith("url(")&&(F.style.stroke=v.fill),r.appendChild(F)}function V(v){let N=t(v.at),I=n.createElementNS(le,"circle");return I.setAttribute("class","vd-editor__ring"),I.setAttribute("cx",String(N.x)),I.setAttribute("cy",String(N.y)),I.setAttribute("r",String(S2)),r.appendChild(I),{id:v.id,rect:{x:N.x-mu/2,y:N.y-mu/2,w:mu,h:mu}}}function T(v){let N=t(v.at),I=v.axis==="x"?am:hu,F=v.axis==="x"?hu:am,q=be("vd-editor__spacer",{x:N.x-I/2,y:N.y-F/2,w:I,h:F});q.setAttribute("rx",String(am/2)),r.appendChild(q),v.label!==null&&C(v.label,v.axis==="x"?{x:N.x,y:N.y-hu/2-dm-Dt/2}:{x:N.x+hu/2+dm+Dt,y:N.y});let Y=v.axis==="x"?pv:hv,Q=v.axis==="x"?hv:pv;return{id:v.id,rect:{x:N.x-Y/2,y:N.y-Q/2,w:Y,h:Q}}}function O(v){let N=b(v.frame),I=v.rotation??0;l=I===0?null:{angle:I,centre:{x:N.x+N.w/2,y:N.y+N.h/2}},_(l,()=>j(v,N)),v.handles&&v.rotatable&&(m=Ii.map(F=>{let{u:q,v:Y}=cs(F);return{handle:F,at:{x:N.x+N.w*q,y:N.y+N.h*Y}}}))}function j(v,N){if(Se("vd-editor__outline",bs(N,ys),ys),!!v.handles){o=gp(N).map(I=>({...I,bound:v.boundHandles.has(I.handle)}));for(let I of Ii){let{u:F,v:q}=cs(I),Y={x:N.x+N.w*F-ls/2,y:N.y+N.h*q-ls/2,w:ls,h:ls};r.appendChild(be("vd-editor__halo",bs(Y,lv+1))),r.appendChild(be("vd-editor__handle",Y))}s=v.adjusters.map(I=>{let F=t(I.at),q=n.createElementNS(le,"circle");q.setAttribute("class","vd-editor__halo"),q.setAttribute("cx",String(F.x)),q.setAttribute("cy",String(F.y)),q.setAttribute("r",String(fv+lv/2+.5)),r.appendChild(q);let Y=n.createElementNS(le,"circle");return Y.setAttribute("class","vd-editor__adjuster"),Y.setAttribute("cx",String(F.x)),Y.setAttribute("cy",String(F.y)),Y.setAttribute("r",String(fv)),r.appendChild(Y),{id:I.id,bound:I.bound,rect:{x:F.x-pu/2,y:F.y-pu/2,w:pu,h:pu}}})}}function $(v){let N=t(v.axis==="x"?{x:v.at,y:v.from}:{x:v.from,y:v.at}),I=t(v.axis==="x"?{x:v.at,y:v.to}:{x:v.to,y:v.at}),F=n.createElementNS(le,"line");F.setAttribute("class","vd-editor__guide"),F.setAttribute("x1",String(Ve(N.x))),F.setAttribute("y1",String(Ve(N.y))),F.setAttribute("x2",String(Ve(I.x))),F.setAttribute("y2",String(Ve(I.y))),r.appendChild(F)}function P(v){let N=t(v.axis==="x"?{x:v.from,y:v.at}:{x:v.at,y:v.from}),I=t(v.axis==="x"?{x:v.to,y:v.at}:{x:v.at,y:v.to}),F=n.createElementNS(le,"path");F.setAttribute("class","vd-editor__measure"),F.setAttribute("d",v.axis==="x"?`M${Ve(N.x)} ${Ve(N.y)-vr} V${Ve(N.y)+vr} M${Ve(N.x)} ${Ve(N.y)} H${Ve(I.x)} M${Ve(I.x)} ${Ve(I.y)-vr} V${Ve(I.y)+vr}`:`M${Ve(N.x)-vr} ${Ve(N.y)} H${Ve(N.x)+vr} M${Ve(N.x)} ${Ve(N.y)} V${Ve(I.y)} M${Ve(I.x)-vr} ${Ve(I.y)} H${Ve(I.x)+vr}`),r.appendChild(F);let q=n.createElementNS(le,"text");q.setAttribute("class","vd-editor__measure-text"),q.setAttribute("x",String((N.x+I.x)/2)),q.setAttribute("y",String((N.y+I.y)/2-(v.axis==="x"?yv:0))),v.axis==="y"&&q.setAttribute("dx",String(yv)),q.textContent=v.label,r.appendChild(q)}function C(v,N){let I=Math.max(34,v.length*um+14),F=N.x-I/2,q=N.y-Dt/2,Y=be("vd-editor__badge",{x:F,y:q,w:I,h:Dt});Y.setAttribute("rx",String(Dt/2)),r.appendChild(Y);let Q=n.createElementNS(le,"text");Q.setAttribute("class","vd-editor__badge-text"),Q.setAttribute("x",String(F+I/2)),Q.setAttribute("y",String(q+Dt/2)),Q.textContent=v,r.appendChild(Q)}function G(v){let N=b(v.frame),I=Math.floor(N.w/vv);if(I<3)return[];let F=v.label.length>I?`${v.label.slice(0,I-1)}\u2026`:v.label;v.component&&r.appendChild(be("vd-editor__component-outline",ao(N)));let q=n.createElementNS(le,"text");q.setAttribute("class",`vd-editor__page-label vd-editor__page-label--${v.state}${v.component?" vd-editor__page-label--component":""}`),q.setAttribute("x",String(N.x)),q.setAttribute("y",String(N.y-bv)),q.textContent=F,r.appendChild(q);let Y=Math.min(N.w,F.length*vv+4),Q=E2+6;return[{id:v.id,rect:{x:N.x,y:N.y-bv-Q+3,w:Y,h:Q}}]}function ee(v){let N=ao(b(v.frame));r.appendChild(be("vd-editor__lock",N));let I=`${v.label} \xB7 locked`,F=I.length*um+14,q=N.y+4,Y=be("vd-editor__lock-tag",{x:N.x+4,y:q,w:F,h:Dt});Y.setAttribute("rx","4"),r.appendChild(Y);let Q=n.createElementNS(le,"text");Q.setAttribute("class","vd-editor__lock-text"),Q.setAttribute("x",String(N.x+4+F/2)),Q.setAttribute("y",String(q+Dt/2)),Q.textContent=I,r.appendChild(Q)}function fe(v){let N=ao(b(v.frame)),I=be(v.target?"vd-editor__slot vd-editor__slot--target":"vd-editor__slot",N);I.setAttribute("rx","3"),r.appendChild(I);let F=Q=>Q.length*_2+16<=N.w,q=[];N.h>=20&&F(v.label)&&q.push([v.label,"vd-editor__slot-label"]),q.length>0&&N.h>=48&&F(xv)&&q.push([xv,"vd-editor__slot-hint"]);let Y=N.y+N.h/2-(q.length-1)*gv/2;q.forEach(([Q,Te],Ct)=>{let _e=n.createElementNS(le,"text");_e.setAttribute("class",Te),_e.setAttribute("x",String(N.x+N.w/2)),_e.setAttribute("y",String(Y+Ct*gv)),_e.textContent=Q,r.appendChild(_e)})}function oe(v){let N=v.frames.map(Te=>bs(b(Te),ys));for(let Te of N)r.appendChild(be("vd-editor__presence",Te));let I=N[0];if(!I||!v.label)return;let F=Math.max(34,v.label.length*um+14),q=I.y-Dt-3<0?I.y+3:I.y-Dt-3,Y=be("vd-editor__presence-tag",{x:I.x,y:q,w:F,h:Dt});Y.setAttribute("rx","4"),r.appendChild(Y);let Q=n.createElementNS(le,"text");Q.setAttribute("class","vd-editor__presence-text"),Q.setAttribute("x",String(I.x+F/2)),Q.setAttribute("y",String(q+Dt/2)),Q.textContent=v.label,r.appendChild(Q)}function Se(v,N,I){let q=v==="vd-editor__highlight"?"vd-editor__halo vd-editor__halo--highlight":v==="vd-editor__hover"||v==="vd-editor__member"?"vd-editor__halo vd-editor__halo--quiet":"vd-editor__halo";r.appendChild(be(q,bs(N,I+1))),r.appendChild(be(v,N))}function be(v,N){let I=n.createElementNS(le,"rect");return I.setAttribute("class",v),I.setAttribute("x",String(N.x)),I.setAttribute("y",String(N.y)),I.setAttribute("width",String(Math.max(0,N.w))),I.setAttribute("height",String(Math.max(0,N.h))),I}return{element:r,render:w,hitHandle(v){let N=M(v,l);for(let I of o)if(Mt(I.rect,N.x,N.y))return{handle:I.handle,bound:I.bound};return null},hitAdjuster(v){let N=M(v,l);for(let I of s)if(Mt(I.rect,N.x,N.y))return{id:I.id,bound:I.bound};return null},hitSpacer(v){return cm(i,v)},hitPath(v){let N=M(v,p),I=d.find(F=>Mt(F.rect,N.x,N.y));return I?{kind:I.kind,key:I.key}:null},hitLineEnd(v){return c.find(N=>Mt(N.rect,v.x,v.y))?.end??null},hitRotate(v){let N=M(v,l),I=o.length===0?null:m;if(!I)return null;for(let F of I){let q=Math.hypot(N.x-F.at.x,N.y-F.at.y);if(q<ls/2+2||q>k2)continue;let{u:Y,v:Q}=cs(F.handle);if((N.x-F.at.x)*(Y*2-1)+(N.y-F.at.y)*(Q*2-1)>0)return F.handle}return null},hitRing(v){return cm(a,v)},hitPageLabel(v){return cm(g,v)},pageLabelRect(v){return g.find(N=>N.id===v)?.rect??null},destroy(){r.remove(),o=[],s=[],i=[],a=[]}}}function cm(e,t){for(let n of e)if(Mt(n.rect,t.x,t.y))return n.id;return null}function Ve(e){return Math.round(e)+.5}function ao(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 bs(e,t){let n=t/2;return{x:e.x-n,y:e.y-n,w:e.w+t,h:e.h+t}}function Sv(e,t){let n=[];return de(e.root,r=>{if(t.has(r.id))return!1;r.type!=="image"||ve(r.src)||e.assets[r.src]===void 0&&n.push({id:r.id,src:r.src,label:r.name??r.src})}),n}function fm(e){if(e.length<2)return null;let t=lm("x",e),n=lm("y",e);return n.length===1&&t.length===e.length?_v("x",e,t):t.length===1&&n.length===e.length?_v("y",e,n):n.length>=2&&t.length>=2?M2(e,t,n):null}function lm(e,t){let n=[...t].sort((o,s)=>vs(o.frame,e)-vs(s.frame,e)),r=[];for(let o of n){let s=r[r.length-1];if(s&&vs(o.frame,e)<s.hi-.01){r[r.length-1]={lo:s.lo,hi:Math.max(s.hi,gu(o.frame,e)),from:Math.min(s.from,vs(o.frame,xu(e))),to:Math.max(s.to,gu(o.frame,xu(e))),members:[...s.members,o.id]};continue}r.push({lo:vs(o.frame,e),hi:gu(o.frame,e),from:vs(o.frame,xu(e)),to:gu(o.frame,xu(e)),members:[o.id]})}return r}function _v(e,t,n){return{kind:"run",items:t,series:[yu(e,n)],order:n.flatMap(r=>r.members)}}function M2(e,t,n){if(t.length*n.length!==e.length)return null;let r=[];for(let o of n)for(let s of t){let i=o.members.filter(a=>s.members.includes(a));if(i.length!==1||i[0]===void 0)return null;r.push(i[0])}return{kind:"grid",items:e,series:[yu("x",t),yu("y",n)],order:r}}function yu(e,t){let n=[];for(let r=0;r+1<t.length;r+=1){let o=t[r],s=t[r+1];!o||!s||n.push(s.lo-o.hi)}return{axis:e,tracks:t,gaps:n}}function wn(e,t){return e.series.find(n=>n.axis===t)}function pm(e){let t=e[0];return t===void 0?!1:e.every(n=>Math.abs(n-t)<.01)}function hm(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 s=n.tracks[o],i=n.tracks[o+1],a=n.gaps[o];if(!s||!i||a===void 0)continue;let d=(s.hi+i.lo)/2,c=r?r.tracks.map(l=>(l.lo+l.hi)/2):[(Math.max(s.from,i.from)+Math.min(s.to,i.to))/2];for(let l of c)t.push({id:Ev(n.axis,o),axis:n.axis,index:o,gap:a,at:n.axis==="x"?{x:d,y:l}:{x:l,y:d}})}}return t}function Ev(e,t){return`${e}:${t}`}function bu(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 mm(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 vu(e,t,n){let r=wn(e,t);return r?wu(r,n):new Map}function wu(e,t){let n=new Map,r=e.tracks[0];if(!r)return n;let o=r.hi;for(let s=1;s<e.tracks.length;s+=1){let i=e.tracks[s];if(!i)continue;let a=o+t;for(let d of i.members)n.set(d,a-i.lo);o=a+(i.hi-i.lo)}return n}function xm(e,t){return yu(t,lm(t,e))}function gm(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((s,i)=>s+(i.hi-i.lo),0);return(r.hi-n.lo-o)/(t.length-1)}function ym(e,t){let n=C2(e),r=0,o=1/0;for(let s=0;s<n.length;s+=1){let i=n[s];if(!i)continue;let a=Math.hypot(i.x-t.x,i.y-t.y);a<o&&(o=a,r=s)}return r}function C2(e){if(e.kind==="grid"){let n=wn(e,"x")?.tracks??[];return(wn(e,"y")?.tracks??[]).flatMap(o=>n.map(s=>({x:(s.lo+s.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 bm(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 vm(e,t){let n=new Map(e.items.map(a=>[a.id,a.frame])),r=new Map;if(e.kind==="grid"){let a=wn(e,"x")?.tracks??[],d=wn(e,"y")?.tracks??[];return t.forEach((c,l)=>{let p=a[l%a.length],m=d[Math.floor(l/a.length)];p&&m&&r.set(c,{x:p.lo,y:m.lo})}),r}let o=e.series[0],s=o?.tracks[0];if(!o||!s)return r;let i=s.lo;return t.forEach((a,d)=>{let c=n.get(a);if(!c)return;let l=o.axis==="x"?c.w:c.h;r.set(a,o.axis==="x"?{x:i,y:c.y}:{x:c.x,y:i}),i+=l+(o.gaps[d]??0)}),r}function wm(e,t,n){let r=new Map,o=e.items.find(d=>d.id===t),s=e.items.find(d=>d.id===n);if(!o||!s||t===n)return r;let i=e.kind==="grid"?["x","y"]:[e.series[0]?.axis??"x"],a=(d,c)=>({x:i.includes("x")?c.frame.x:d.frame.x,y:i.includes("y")?c.frame.y:d.frame.y});return r.set(t,a(o,s)),r.set(n,a(s,o)),r}function xu(e){return e==="x"?"y":"x"}function vs(e,t){return t==="x"?e.x:e.y}function gu(e,t){return t==="x"?e.x+e.w:e.y+e.h}var Mv="vd-editor-styles",Cv=`
144
144
  .vd-editor {
145
145
  position: relative;
146
146
  width: 100%;
@@ -255,6 +255,37 @@ ${Kn}`);return t===-1?-1:t+1}function Zv(e){let t=new Set;for(let n of e.matchAl
255
255
  shape-rendering: crispEdges;
256
256
  }
257
257
 
258
+ /* --- masks ---------------------------------------------------------------- */
259
+
260
+ /* The shape cutting a selected image (ROADMAP.md G2). It draws nothing, so
261
+ this outline is the only sight of it: dashed, as a parked node is, because
262
+ it is not what the handles act on. Solid while cropping, when the picture
263
+ is being framed against it. */
264
+ .vd-editor__mask {
265
+ fill: none;
266
+ stroke: var(--vd-selection, var(--vd-accent, #3b82f6));
267
+ stroke-width: 1.5;
268
+ stroke-dasharray: 4 3;
269
+ }
270
+
271
+ /* Under the dashes, in the halo's colour, so the outline reads on a white page
272
+ in the dark theme and a dark page in the light one. */
273
+ .vd-editor__mask-halo {
274
+ fill: none;
275
+ stroke: var(--vd-selection-halo, #fff);
276
+ stroke-width: 3.5;
277
+ }
278
+
279
+ .vd-editor__mask--crop {
280
+ stroke-width: 2;
281
+ stroke-dasharray: none;
282
+ }
283
+
284
+ /* The rest of the picture while cropping: there to place, not to read. */
285
+ .vd-editor__ghost {
286
+ opacity: 0.35;
287
+ }
288
+
258
289
  /* --- paths: point mode and the pen ---------------------------------------- */
259
290
 
260
291
  .vd-editor__path {
@@ -675,6 +706,12 @@ ${Kn}`);return t===-1?-1:t+1}function Zv(e){let t=new Set;for(let n of e.matchAl
675
706
  opacity: 0.55;
676
707
  }
677
708
 
709
+ /* A mask (ROADMAP.md G2): listed under the image it cuts, and quieter than a
710
+ layer that draws, since it draws nothing. */
711
+ .vd-layers__row[data-mask='true'] .vd-layers__label {
712
+ opacity: 0.7;
713
+ }
714
+
678
715
  /* A part this instance changes: a small dot, the way Figma marks an override. */
679
716
  .vd-layers__dot {
680
717
  flex: 0 0 6px;
@@ -1475,6 +1512,17 @@ ${Kn}`);return t===-1?-1:t+1}function Zv(e){let t=new Set;for(let n of e.matchAl
1475
1512
  outline-offset: 1px;
1476
1513
  }
1477
1514
 
1515
+ /* A multi-selection's effects that differ (G9): said, not a button, so it does not take hover. */
1516
+ .vd-inspector__empty.vd-effect__mixed:hover {
1517
+ border-style: dashed;
1518
+ color: var(--vd-muted, rgb(0 0 0 / 0.55));
1519
+ }
1520
+
1521
+ /* An effect's type sits closer to its values than to the effect above it (G9). */
1522
+ .vd-inspector__list > .vd-effect__type:not(:first-child) {
1523
+ margin-top: 6px;
1524
+ }
1525
+
1478
1526
  /* A list inside a section \u2014 shadows, stops \u2014 under a line naming it. */
1479
1527
  .vd-inspector__list {
1480
1528
  display: flex;
@@ -1510,6 +1558,56 @@ ${Kn}`);return t===-1?-1:t+1}function Zv(e){let t=new Set;for(let n of e.matchAl
1510
1558
  height: 14px;
1511
1559
  }
1512
1560
 
1561
+ /*
1562
+ * The corners: the one Radius field across the row, and when the corners are
1563
+ * independent a field per corner beneath it, on the panel's own two columns so
1564
+ * every edge lines up with the rows above.
1565
+ */
1566
+ .vd-inspector__corners {
1567
+ display: grid;
1568
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
1569
+ gap: 8px;
1570
+ min-width: 0;
1571
+ }
1572
+
1573
+ /* Independent corners: a button inside the field at its end, pressed while open. */
1574
+ .vd-inspector__icon-button.vd-field__toggle {
1575
+ width: 20px;
1576
+ height: 20px;
1577
+ margin-right: -4px;
1578
+ border-radius: 4px;
1579
+ }
1580
+
1581
+ .vd-field__toggle svg {
1582
+ width: 14px;
1583
+ height: 14px;
1584
+ }
1585
+
1586
+ .vd-inspector__icon-button.vd-field__toggle:hover:not(:disabled) {
1587
+ background: var(--vd-rule, rgb(0 0 0 / 0.08));
1588
+ color: var(--vd-ink, #1a1a1f);
1589
+ }
1590
+
1591
+ /* Pressed is chosen, as a switch that is on is: Ink in light, lime in dark. */
1592
+ .vd-inspector__icon-button.vd-field__toggle[aria-pressed='true'],
1593
+ .vd-inspector__icon-button.vd-field__toggle[aria-pressed='true']:hover:not(:disabled) {
1594
+ background: var(--vd-chosen, var(--vd-ink, #1a1a1f));
1595
+ color: var(--vd-on-chosen, #ffffff);
1596
+ }
1597
+
1598
+ /* Each corner's mark is the radius mark turned to its corner; Lucide draws it top-right. */
1599
+ .vd-inspector__corner--tl .vd-field__prefix--icon svg {
1600
+ transform: rotate(-90deg);
1601
+ }
1602
+
1603
+ .vd-inspector__corner--br .vd-field__prefix--icon svg {
1604
+ transform: rotate(90deg);
1605
+ }
1606
+
1607
+ .vd-inspector__corner--bl .vd-field__prefix--icon svg {
1608
+ transform: rotate(180deg);
1609
+ }
1610
+
1513
1611
  .vd-inspector__note {
1514
1612
  margin: 0 0 8px;
1515
1613
  line-height: 1.5;
@@ -1742,10 +1840,14 @@ p.vd-inspector__subhead {
1742
1840
  cursor: default;
1743
1841
  }
1744
1842
 
1745
- .vd-inspector__button:hover {
1843
+ .vd-inspector__button:hover:not(:disabled) {
1746
1844
  background: var(--vd-input-bg, rgb(0 0 0 / 0.06));
1747
1845
  }
1748
1846
 
1847
+ .vd-inspector__button:disabled {
1848
+ opacity: 0.35;
1849
+ }
1850
+
1749
1851
  /*
1750
1852
  * Six alignments spread across the row. With three or more selected, the two
1751
1853
  * distributions follow after a gap, because "even out the gaps" is a
@@ -1766,6 +1868,19 @@ p.vd-inspector__subhead {
1766
1868
  margin-left: 8px;
1767
1869
  }
1768
1870
 
1871
+ /*
1872
+ * Merge's four marks across the whole row, each centred in a quarter, as the
1873
+ * Align row fills its width: no half of the row is left empty. Group and
1874
+ * Delete are the panel's ordinary 8px below.
1875
+ */
1876
+ .vd-inspector__merge {
1877
+ display: grid;
1878
+ grid-template-columns: repeat(4, minmax(0, 1fr));
1879
+ justify-items: center;
1880
+ gap: 8px;
1881
+ margin-bottom: 8px;
1882
+ }
1883
+
1769
1884
  .vd-inspector__icon-button {
1770
1885
  display: inline-flex;
1771
1886
  align-items: center;
@@ -1803,6 +1918,9 @@ p.vd-inspector__subhead {
1803
1918
  display: flex;
1804
1919
  flex-wrap: wrap;
1805
1920
  align-items: center;
1921
+ /* Lines pack to the top: a row grown by its neighbour's error message
1922
+ stretches this field too, and centring its one line would drop the box. */
1923
+ align-content: flex-start;
1806
1924
  min-width: 0;
1807
1925
  margin: 0;
1808
1926
  }
@@ -1966,6 +2084,21 @@ p.vd-inspector__subhead {
1966
2084
  display: inline-flex;
1967
2085
  }
1968
2086
 
2087
+ /* An attached connector end (G5): Detach is the row's one control, always shown. */
2088
+ .vd-field__detach--shown {
2089
+ display: inline-flex;
2090
+ }
2091
+
2092
+ /* What an attached end follows, read rather than typed: the input's type, ellipsed. */
2093
+ .vd-field__value {
2094
+ flex: 1 1 0;
2095
+ min-width: 0;
2096
+ overflow: hidden;
2097
+ font-size: 11.5px;
2098
+ text-overflow: ellipsis;
2099
+ white-space: nowrap;
2100
+ }
2101
+
1969
2102
  .vd-field__detach:hover {
1970
2103
  background: var(--vd-rule, rgb(0 0 0 / 0.06));
1971
2104
  color: var(--vd-ink, #1a1a1f);
@@ -1992,6 +2125,81 @@ p.vd-inspector__subhead {
1992
2125
  line-height: 1.4;
1993
2126
  }
1994
2127
 
2128
+ /*
2129
+ * A picture layer's fit, inside its row after the name: "photo \xB7 Cover". The
2130
+ * dropdown sheds its own box, so the row reads as one entry, as a gradient's
2131
+ * summary does; it keeps its focus ring, being its own Tab stop.
2132
+ */
2133
+ .vd-layer__fit {
2134
+ position: relative;
2135
+ flex: 0 0 auto;
2136
+ display: flex;
2137
+ flex-wrap: nowrap;
2138
+ align-items: center;
2139
+ font-family: var(--vd-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
2140
+ font-size: 11.5px;
2141
+ }
2142
+
2143
+ .vd-layer__fit::before {
2144
+ content: '\xB7';
2145
+ margin-right: 6px;
2146
+ color: var(--vd-muted, rgb(0 0 0 / 0.55));
2147
+ }
2148
+
2149
+ .vd-layer__fit > .vd-select {
2150
+ flex: 0 0 auto;
2151
+ width: auto;
2152
+ height: 20px;
2153
+ gap: 2px;
2154
+ padding: 0 2px 0 4px;
2155
+ border-color: transparent;
2156
+ border-radius: 4px;
2157
+ background: transparent;
2158
+ }
2159
+
2160
+ .vd-layer__fit > .vd-select:hover {
2161
+ background: var(--vd-input-bg, rgb(0 0 0 / 0.05));
2162
+ }
2163
+
2164
+ .vd-layer__fit > .vd-select:focus-visible {
2165
+ border-color: var(--vd-accent, #3b82f6);
2166
+ }
2167
+
2168
+ .vd-layer__fit > .vd-listbox {
2169
+ left: auto;
2170
+ right: 0;
2171
+ min-width: 96px;
2172
+ }
2173
+
2174
+ /*
2175
+ * A picture layer naming a picture the document lacks (\`fill-asset-missing\`):
2176
+ * a warning mark where the swatch was, and the name muted, since the layer is
2177
+ * not drawn. The row's tooltip says why and what to do.
2178
+ */
2179
+ .vd-layer__missing {
2180
+ display: none;
2181
+ flex: 0 0 auto;
2182
+ color: var(--vd-warning, #b7791f);
2183
+ }
2184
+
2185
+ .vd-layer__missing svg {
2186
+ width: 16px;
2187
+ height: 16px;
2188
+ }
2189
+
2190
+ .vd-field--missing .vd-layer__missing {
2191
+ display: inline-flex;
2192
+ }
2193
+
2194
+ .vd-field--missing .vd-field__swatch {
2195
+ display: none;
2196
+ }
2197
+
2198
+ .vd-field--missing .vd-field__input {
2199
+ color: var(--vd-muted, rgb(0 0 0 / 0.55));
2200
+ text-decoration: line-through;
2201
+ }
2202
+
1995
2203
  /* A dropdown: our button and list, not the operating system's menu. */
1996
2204
  .vd-select {
1997
2205
  width: 100%;
@@ -2883,15 +3091,15 @@ button.vd-field__swatch:focus-visible {
2883
3091
  background: rgb(255 255 255 / 0.09);
2884
3092
  color: #fff;
2885
3093
  }
2886
- `;function Jn(e){if(e.getElementById(Mx))return;let t=e.createElement("style");t.id=Mx,t.textContent=Ax,e.head.appendChild(t)}var Sn=["font","size","weight","italic","underline","strike","fill","letterSpacing","link"];function Bt(e){return typeof e=="string"?e===""?[]:[{text:e}]:e.flatMap(t=>typeof t=="string"?t===""?[]:[{text:t}]:t.text===""?[]:[t])}function Qn(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function er(e){return Qn(e).length}function Zn(e){let t={};for(let n of Sn){let r=e[n];r!==void 0&&(t[n]=r)}return t}function Tx(e,t){return Sn.every(n=>e[n]===t[n])}function Sk(e,t){let n={text:e};for(let r of Sn){let o=t[r];o!==void 0&&(n[r]=o)}return n}function is(e){let t=Bt(e),n=[];for(let o of t){let s=n[n.length-1];if(s&&Tx(Zn(s),Zn(o))){n[n.length-1]={...s,text:s.text+o.text};continue}n.push(o)}if(n.length===0)return"";let r=n[0];return n.length===1&&$x(r)?r.text:n.map(o=>$x(o)?o.text:o)}function $x(e){return Sn.every(t=>e[t]===void 0)}function If(e,t,n){let[r,o]=ia(t,n,er(e)),s=[],i=0;for(let d of Bt(e)){let l=i+d.text.length,f=Math.max(r,i),p=Math.min(o,l);p>f&&s.push({...d,text:d.text.slice(f-i,p-i)}),i=l}return is(s)}function zr(e,t,n,r,o){let s=er(e),[i,d]=ia(t,n,s),l=o??tr(e,i),f=[],p=0,m=!1,y=()=>{m||r===""||(f.push(Sk(r,l)),m=!0)};for(let v of Bt(e)){let C=p+v.text.length,S=Math.min(i,C);S>p&&f.push({...v,text:v.text.slice(0,S-p)}),i>=p&&i<=C&&y();let g=Math.max(d,p);C>g&&f.push({...v,text:v.text.slice(g-p)}),p=C}return y(),is(f)}function tr(e,t){let n=Bt(e);if(n.length===0)return{};let r=0,o=n[0];for(let s of n){let i=r+s.text.length;if(t>r&&t<=i)return Zn(s);if(t<=r)return Zn(o);o=s,r=i}return Zn(o)}function sa(e,t,n,r){let[o,s]=ia(t,n,er(e));if(o===s)return is(e);let i=Object.keys(r),d=[],l=0;for(let f of Bt(e)){let p=l+f.text.length;for(let[m,y,v]of Ek(l,p,o,s)){if(y<=m)continue;let C=f.text.slice(m-l,y-l);if(!v){d.push({...f,text:C});continue}let S={...f,text:C};for(let g of i)r[g]===void 0?delete S[g]:S[g]=r[g];d.push(S)}l=p}return is(d)}function Ek(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 Rf(e,t,n){let[r,o]=ia(t,n,er(e));if(r===o)return tr(e,r);let s,i=0;for(let d of Bt(e)){let l=i+d.text.length;if(Math.min(l,o)>Math.max(i,r)){let f=Zn(d);if(!s)s=f;else{let p={};for(let m of Sn)s[m]===f[m]&&s[m]!==void 0&&(p[m]=s[m]);s=p}}i=l}return s??{}}function ia(e,t,n){let r=Ox(Math.min(e,t),n),o=Ox(Math.max(e,t),n);return[r,o]}function Ox(e,t){return Math.max(0,Math.min(Math.round(e),t))}function jr(e,t){let n=[],r=0;return e.lines.forEach((o,s)=>{let i=o.spans.map(p=>p.text).join(""),d=i===""?s===0?r:Ck(t,r):Mk(t,i,r),l=d+i.length,f=s===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 Ck(e,t){let n=e.indexOf(`
2887
- `,t);return n===-1?t:n+1}function Mk(e,t,n){let r=e.indexOf(t,n);return r===-1?n:r}function aa(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 da(e,t,n,r){let o=jr(e,t),s=aa(o,n),i=e.lines[s],d=o[s];if(!i||!d)return{x:0,y:0,h:0,line:0};let l=Math.max(0,Math.min(n-d.start,Dx(i))),f=(Ak(i,l)??i.style)?.fill;return{x:Ff(i,l,r),y:i.y,h:i.h,line:s,...f!==void 0?{fill:f}:{}}}function Ak(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 as(e,t,n,r){let o=jr(e,t);if(e.lines.length===0)return 0;let s=e.lines.findIndex(l=>n.y<l.y+l.h);s===-1&&(s=e.lines.length-1);let i=e.lines[s];return o[s].start+Lx(i,n.x,r)}function Lx(e,t,n){let r=0,o=1/0,s=0,i=(d,l)=>{let f=Math.abs(l-t);f<o&&(o=f,r=d)};i(0,e.spans[0]?.x??0);for(let d of e.spans){for(let l of Uf(d.text))l!==0&&i(s+l,d.x+n.advance(d.text.slice(0,l),d.style));s+=d.text.length}return r}function Ff(e,t,n){let r=0,o=e.spans[0]?.x??0;for(let s of e.spans){if(t<=r)return s.x;if(t>=r+s.text.length){o=s.x+s.w,r+=s.text.length;continue}return s.x+n.advance(s.text.slice(0,t-r),s.style)}return o}function Dx(e){return e.spans.reduce((t,n)=>t+n.text.length,0)}function Bf(e,t,n,r,o){let s=Math.min(n,r),i=Math.max(n,r);if(s===i)return[];let d=jr(e,t),l=[];return e.lines.forEach((f,p)=>{let m=d[p];if(!m)return;let y=Math.max(s,m.start),v=Math.min(i,m.end);if(v<=y)return;let C=Dx(f),S=Ff(f,Math.min(y-m.start,C),o),g=Ff(f,Math.min(v-m.start,C),o),L=Math.max(g-S,v>m.end-1&&v>y?4:0);L>0&&l.push({x:S,y:f.y,w:L,h:f.h})}),l}function Hf(e,t,n,r,o){let s=jr(e,t),d=aa(s,n)+r,l=e.lines[d],f=s[d];if(!l||!f)return r===-1?0:t.length;let p=da(e,t,n,o);return Math.min(f.start+Lx(l,p.x,o),f.end)}function Uf(e){let t=[0];for(let{index:n,segment:r}of $k.segment(e))t.push(n+r.length);return t}var $k=new Intl.Segmenter(void 0,{granularity:"grapheme"});function la(e,t){let n=0;for(let r of Uf(e)){if(r>=t)break;n=r}return n}function Vf(e,t){for(let n of Uf(e))if(n>t)return n;return e.length}function Px(e,t){return t>=e.length?e.length:la(e,t+1)}var Ok=/[\p{L}\p{N}_]/u;function zf(e,t){let n=Math.max(0,Math.min(t,e.length)),r=d=>Ok.test(e[d]??""),o=n;if(!r(o)&&o>0&&r(o-1)&&(o-=1),!r(o))return{from:n,to:n};let s=o,i=o;for(;s>0&&r(s-1);)s-=1;for(;i<e.length&&r(i);)i+=1;return{from:s,to:i}}function ua(e,t,n){let r=jr(e,t),o=r[aa(r,n)];return o?{from:o.start,to:o.end}:{from:0,to:t.length}}var Tk=700,Lk=400,Dk=600,Nx=1,Pk=1,Bx=700;function jf(e){let t=0,n=0,r=null,o=!1,s=0,i=!1,d=0,l=0;function f(){return Qn(e.content())}function p(b){let D=f();return Px(D,Math.max(0,Math.min(Math.round(b),D.length)))}function m(){return{from:Math.min(t,n),to:Math.max(t,n)}}function y(b,D=b){let T=t!==b||n!==D;t=p(b),n=p(D),T&&v(),r=null,e.invalidate()}function v(){o=!1,s&&(clearTimeout(s),s=0)}function C(){s&&clearTimeout(s),s=setTimeout(v,Bx)}function S(b,D){e.write(b,o,D),o=!0,C()}function g(b,D){let{from:T,to:G}=m(),Y=r??void 0;S(zr(e.content(),T,G,b,Y),D),t=n=T+b.length,r=null,e.invalidate()}function L(b,D){b!==D&&(S(zr(e.content(),b,D,""),"Delete text"),t=n=Math.min(b,D),e.invalidate())}function A(b,D){let{from:T,to:G}=m();if(T!==G){L(T,G);return}let Y=f();if(b===-1){if(T===0)return;let E=D?Rx(Y,T):la(Y,T);L(E,T);return}if(T>=Y.length)return;let re=D?Fx(Y,T):Vf(Y,T);L(T,re)}function I(b,D){let T=f();return D?b===-1?Rx(T,n):Fx(T,n):b===-1?la(T,n):Vf(T,n)}let U=b=>b.weight??e.base().weight,j=b=>b.italic??e.base().italic,R=b=>U(b)>=Dk;function q(b){let{from:D,to:T}=m();if(r||D===T)return b(r??tr(e.content(),D));let G=0;for(let Y of Bt(e.content())){let re=G+Y.text.length;if(Math.min(re,T)>Math.max(G,D)&&!b(Y))return!1;G=re}return!0}function $(b,D,T,G){let Y=D({});return q(D)?{[b]:Y?G:void 0}:{[b]:Y?void 0:T}}function V(b,D){let T=k=>Math.max(Pk,(k.size??e.base().size)+b),{from:G,to:Y}=m();if(G===Y){D({size:T(r??tr(e.content(),G))});return}let re=e.content(),E=0;for(let k of Bt(e.content())){let O=E+k.text.length,P=Math.max(E,G),K=Math.min(O,Y);K>P&&(re=sa(re,P,K,{size:T(k)})),E=O}v(),S(re,"Format text"),v(),e.invalidate()}return{id:e.id,getSelection:()=>({anchor:t,head:n}),setSelection(b,D){y(b,D??b)},caret(){return da(e.layout(),f(),n,e.measure())},highlight(){let{from:b,to:D}=m();return Bf(e.layout(),f(),b,D,e.measure())},pointTo(b,D){let T=as(e.layout(),f(),b,e.measure());y(D?t:T,T)},selectWordAt(b){let D=as(e.layout(),f(),b,e.measure()),T=zf(f(),D);y(T.from,T.to)},selectLineAt(b){let D=as(e.layout(),f(),b,e.measure()),T=ua(e.layout(),f(),D);y(T.from,T.to)},selectAll(){y(0,f().length)},format(b){let{from:D,to:T}=m();if(D===T){r={...tr(e.content(),D),...b},e.invalidate();return}v(),S(sa(e.content(),D,T,b),"Format text"),v(),e.invalidate()},activeMark(){if(r)return r;let{from:b,to:D}=m();return Rf(e.content(),b,D)},composing:()=>i,handleKey(b){if(i)return!1;let D=b.metaKey||b.ctrlKey,T=b.altKey||b.ctrlKey&&!b.metaKey;if(D&&b.shiftKey&&!b.altKey&&(b.code==="Period"||b.code==="Comma"))return V(b.code==="Period"?Nx:-Nx,G=>this.format(G)),!0;switch(b.key){case"Escape":return e.close("escape"),!0;case"ArrowLeft":case"ArrowRight":{let G=b.key==="ArrowLeft"?-1:1,{from:Y,to:re}=m();if(!b.shiftKey&&Y!==re)y(G===-1?Y:re);else{let E=b.metaKey?Ix(e,f(),n,G):I(G,T);y(b.shiftKey?t:E,E)}return!0}case"ArrowUp":case"ArrowDown":{let G=b.key==="ArrowUp"?-1:1,Y=D?G===-1?0:f().length:Hf(e.layout(),f(),n,G,e.measure());return y(b.shiftKey?t:Y,Y),!0}case"PageUp":case"PageDown":{let G=b.key==="PageUp"?0:f().length;return y(b.shiftKey?t:G,G),!0}case"Home":case"End":{let G=Ix(e,f(),n,b.key==="Home"?-1:1);return y(b.shiftKey?t:G,G),!0}case"Backspace":return A(-1,T||D),!0;case"Delete":return A(1,T||D),!0;case"Enter":return D?e.close("done"):g(`
2888
- `,"Type text"),!0;case"Tab":return!1;case"a":case"A":return D?(y(0,f().length),!0):!1;case"b":case"B":return D?(this.format($("weight",R,Tk,Lk)),!0):!1;case"i":case"I":return D?(this.format($("italic",j,!0,!1)),!0):!1;case"u":case"U":return D?(this.format({underline:this.activeMark().underline===!0?void 0:!0}),!0):!1;case"x":case"X":return!D||!b.shiftKey||b.altKey?!1:(this.format({strike:this.activeMark().strike===!0?void 0:!0}),!0);default:return!1}},handleInput(b){if(!i)switch(b.inputType){case"insertText":case"insertReplacementText":case"insertFromPaste":case"insertFromDrop":case"insertFromYank":g(Nk(b),"Type text");return;case"insertParagraph":case"insertLineBreak":g(`
2889
- `,"Type text");return;case"deleteContentBackward":case"deleteWordBackward":A(-1,b.inputType==="deleteWordBackward");return;case"deleteContentForward":case"deleteWordForward":A(1,b.inputType==="deleteWordForward");return;case"deleteByCut":case"deleteByDrag":{let{from:D,to:T}=m();L(D,T);return}default:return}},handleCompositionStart(){i=!0;let{from:b,to:D}=m();d=b,l=D,v()},handleCompositionUpdate(b){S(zr(e.content(),d,l,b),"Type text"),l=d+b.length,t=n=l,e.invalidate()},handleCompositionEnd(b){S(zr(e.content(),d,l,b),"Type text"),i=!1,l=d+b.length,t=n=l,v(),e.invalidate()},breakBurst:v,destroy(){v()}}}function Nk(e){return typeof e.data=="string"?e.data:e.dataTransfer?.getData("text/plain")??""}function Ix(e,t,n,r){let o=ua(e.layout(),t,n);return r===-1?o.from:o.to}var fa=/[\p{L}\p{N}_]/u;function Rx(e,t){let n=t;for(;n>0&&!fa.test(e[n-1]??"");)n-=1;for(;n>0&&fa.test(e[n-1]??"");)n-=1;return n}function Fx(e,t){let n=t;for(;n<e.length&&!fa.test(e[n]??"");)n+=1;for(;n<e.length&&fa.test(e[n]??"");)n+=1;return n}function Kf(e){return er(e)===0}var Gf={v:"select",f:"frame",r:"rect",o:"ellipse",p:"pen",t:"text"};var qf="host:",Hx="#ffffff",Ux={w:1920,h:1080},Ik=100,ca=20,Rk=15,Vx=1,zx=10,jx=2,Fk=32,Bk={ne:0,se:90,sw:180,nw:270,n:0,e:90,s:180,w:270},Kx={w:240,h:28},Hk={text:"Add text",frame:"Add page",rect:"Draw rectangle",ellipse:"Draw ellipse"};function Uk(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 Vk={KeyA:"left",KeyD:"right",KeyW:"top",KeyS:"bottom",KeyH:"hcenter",KeyV:"vcenter"},zk={KeyH:"x",KeyV:"y"},Gx={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},jk={left:"Align left",hcenter:"Align horizontal centres",right:"Align right",top:"Align top",vcenter:"Align vertical centres",bottom:"Align bottom"},Wf=null,Kk=220,qx={lock:!0,hide:!0},ma="application/x-vdesign-component",Gk=["x","y","w","h"],qk={front:"Bring to front",forward:"Bring forward",backward:"Send backward",back:"Send to back"},Wk=11,En=2,Xk=10;function Yf(e,t){Jn(e.ownerDocument),e.classList.add("vd-editor"),e.hasAttribute("tabindex")||(e.tabIndex=0);let n=t.document,r=[],o=t.tool??"select",s=null,i=null,d=null,l={ids:[],label:null},f=null,p=[],m=!1,y=new Set,v=null,C=!1,S=!1,g=null,L={...qx,...t.features},A=null,I=new os,U=0,j=null,R={dx:0,dy:0},q=null,$=new Map,V=e.ownerDocument.createElement("div");V.style.position="absolute",V.style.inset="0",e.appendChild(V),e.style.touchAction="none";let b=ki(V,{sample:$l,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:(a,u)=>{u===n&&xe("scene",{scene:a,document:u})},onCameraChange:a=>{T?.setZoom(a.zoom),de(),xe("camera",a),!(U>0)&&(me(),xe("navigate",a))}}),D=_x(e,a=>b.documentToScreen(a)),T=t.chrome===!1?null:jh(e,{onTool:un,onUndo:ro,onRedo:oo,onZoomReset:()=>b.fitToContent(),onPlay:t.onPlay,playHint:t.playHint,formatKeys:t.formatKeys}),G=t.chrome===!1?null:Wi(e,{onCommand:cy,...t.formatKeys?{formatKeys:t.formatKeys}:{}}),Y=n,re=n,E=[],k=null,O=[],P=null,K=null,Z=new Map,z=null,ce=null,Ee=null,Ae=[],Ce=mt,ot=null,ee=null,ae=null,ie=null,B=!1,W=e.ownerDocument.createElement("textarea");W.className="vd-editor__input",W.setAttribute("aria-hidden","true"),W.tabIndex=-1,W.autocapitalize="off",W.autocomplete="off",W.spellcheck=!1,e.appendChild(W);function xe(a,u){let c=$.get(a);if(c)for(let h of c)h(u)}function ge(a,u){let c=$.get(a)??new Set;return c.add(u),$.set(a,c),()=>c.delete(u)}function De(a){U+=1;try{a()}finally{U-=1}}function me(){j!==null&&(e.ownerDocument.defaultView?.cancelAnimationFrame(j),j=null)}function We(a){let u=b.linkAt(a),c=u===void 0?void 0:_t(u);return c?c.kind==="url"?t.onOpenLink?(t.onOpenLink(c.url),!0):!1:F(n.root,c.id)?(le([c.id]),Oe([c.id]),!0):!1:!1}function Oe(a,u={}){if(k!==null)return q={target:a,options:u},!1;let c=xg(a);if(!c)return!1;let h=e.getBoundingClientRect(),x=h.width>0&&h.height>0,w=x?{width:h.width,height:h.height-mg(h)}:{width:c.w+96,height:c.h+96},_=u.fit==="always"?qi(c,w):vf(c,w,b.getCamera());if(!_)return!1;me(),u.by==="person"&&xe("navigate",_);let M=e.ownerDocument.defaultView,N=M?.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;if(u.animate===!1||N||!x||!M?.requestAnimationFrame)return De(()=>b.setCamera(_)),!0;let H=b.getCamera(),X=M.performance.now();R={dx:0,dy:0};let J=be=>{let Q=Math.min(1,Math.max(0,(be-X)/Kk)),we=Q===1?_:dx(H,_,lx(Q),w);De(()=>b.setCamera(It(we,R.dx,R.dy))),j=Q===1?null:M.requestAnimationFrame(J)};return j=M.requestAnimationFrame(J),!0}function mg(a){let u=T?.element.getBoundingClientRect();return!u||u.height===0?0:Math.max(0,a.bottom-u.top)}function hg(a,u){j!==null&&(R={dx:R.dx+a,dy:R.dy+u}),De(()=>b.setCamera(It(b.getCamera(),a,u)))}function fs(){if(q===null||k!==null)return;let{target:a,options:u}=q;q=null,Oe(a,u)}function xg(a){if(a==="content"){let c=b.getScene();return Gi([{x:c.x,y:c.y,w:c.width,h:c.height}])}let u=[];for(let c of yf(n,a)){let h=He(c);h&&u.push(h)}return Gi(u)}function dt(a){return b.getResolution().nodes.get(a)}function sn(a){let u=dt(a);return u?{x:u.x,y:u.y,w:u.w,h:u.h}:void 0}function He(a){return Yn(a,n,b.getResolution())}function Cn(a){let u=dt(a);return u?{x:u.absX,y:u.absY,w:u.w,h:u.h}:void 0}function Mn(a){return dt(a)?.values.rotation??0}function sc(){let a=Wr();if(a.length===0)return null;for(let u of a){let c=F(n.root,u);if(!c||!fl.includes(c.type))return null}return a}function nr(a,u=new Set){let c=b.getResolution(),h=null;return oe(n.root,x=>{if(u.has(x.id)||!Ht(x.id)||x.type==="instance")return!1;if(x.type!=="frame")return;let w=c.nodes.get(x.id);if(!w)return!1;let _={x:w.absX,y:w.absY,w:w.w,h:w.h};if(!Et(_,a.x,a.y))return!1;h=x.id}),h}function an(a){let u=dt(a);return u?{x:u.absX,y:u.absY}:{x:0,y:0}}function lt(){return A?.of!==n&&(A={of:n,hidden:Cs(n.root),locked:Ms(n.root)}),A}function Ht(a){let{hidden:u,locked:c}=lt();return!u.has(a)&&!c.has(a)}function he(){return r.filter(Ht)}function Gr(a){let u=b.hitTest(a,h=>!lt().locked.has(h));if(u===null)return null;let c=g===null||Re(n.root,u).includes(g);return Ei(u,n,c?g:null)}function gg(){return Xo(n,he(),b.getResolution())}function qr(){return he().length<2?null:Cf(gg())}function cs(a){let u=[];for(let c of a)for(let h of Xn(c,n)){let x=sn(h);x&&u.push({member:c,node:h,frame:x})}return u}function ps(a,u){let c=F(n.root,a);if(!c)return"literal";let h=c[u];return h===void 0?"literal":ui(h).kind}function yg(a){let u=F(n.root,a),c={};if(!u)return c;let h=[...Gk,...es(u).map(x=>x.prop)];for(let x of h)c[x]=ps(a,x);return c}function ic(a,u){let c="none";for(let h of a){let x=ba(h,u);if(x==="expression")return"expression";x==="token"&&(c="token")}return c}function ba(a,u){let c="none";for(let h of u){let x=ps(a,h);if(x==="complex")return"expression";x==="token"&&(c="token")}return c}let Qe=null;function ue(a,u){if(a.length===0)return;let c=Ks(n,Ci(n,a,sn)),h=_e(n,c);n=h.document,Qe?(Sa(Qe.started,Qe.label,c,h.inverse),Qe.started=!0):I.push({label:u,ops:c,inverse:h.inverse}),ms(c,u)}function vg(a){Qe={label:a,started:!1}}function ac(){Qe=null}function dc(a,u){a.length!==0&&(n=_e(n,a).document,ms(a,u))}function ms(a,u){s=null,ce=null,Ee=null,b.update(n),T?.setHistory(I.canUndo,I.canRedo),de(),xe("change",{document:n,ops:a,label:u}),xe("problems",wa())}function wa(){return[...b.getScene().problems,...ll(n)]}function le(a){let u=a.filter(h=>h!==n.root.id&&F(n.root,h)),c=u.length!==r.length||u.some((h,x)=>r[x]!==h);r=[...u],ae&&(u.length!==1||u[0]!==ae.id)&&(ae=null),c&&(G?.close(),Ee=null,xe("selection",r)),de()}function bg(a,u){let c=F(n.root,a);if(!c)return[];let h=b.getCamera().zoom;if(Math.min(u.w,u.h)*h<24)return[];let x=Wk/h,w=dt(a);return es(c).flatMap(_=>{let M=w?.values[_.prop]??0,N=ps(a,_.prop)!=="literal";return _.handles(u,M,x).map(H=>({id:H.id,at:H.at,bound:N}))})}function wg(){let a=[];for(let H of he()){let X=He(H);X&&a.push(X)}let u=bt(a);if(!u)return null;let c=he().length===1?he()[0]:void 0,h=c===void 0?void 0:F(n.root,c),x=c===void 0||!h||fe(h),w=new Set,_=Wr();for(let H of Vl){let X=_i(H);_.some(J=>X.some(be=>ps(J,be)!=="literal"))&&w.add(H)}let M=!x&&c!==void 0?Mn(c):0,N=M!==0&&c!==void 0?Cn(c):void 0;return{frame:N??u,...N?{rotation:M}:{},rotatable:sc()!==null,handles:ee===null,boundHandles:w,adjusters:ee!==null||x||c===void 0||N?[]:bg(c,u)}}function Wr(){return[...new Set(he().flatMap(a=>Xn(a,n)))]}function kg(a){if(!a)return null;if(k?.kind==="adjust")return`r ${te(P??k.from)}`;if(k?.kind==="rotate")return`${te(K??0)}\xB0`;if(!k&&ce&&he().length===1){let u=dt(he()[0])?.values[ce.prop]??0;return`r ${te(u)}`}return k?.kind==="move"?`${te(a.frame.x)}, ${te(a.frame.y)}`:`${te(a.frame.w)} \xD7 ${te(a.frame.h)}`}function _g(){let u=k!==null&&k.kind!=="space"&&k.kind!=="reorder"?null:qr();if(!u)return{spacers:[],rings:[],lead:null};let c=k?.kind==="space"?k.spacer:null;return{spacers:Af(u).map(h=>({id:h.id,axis:h.axis,at:h.at,label:h.id===(c??Ee)?String(te(h.gap)):null})),rings:$f(u).map(h=>({id:h.id,at:h.at})),lead:k?.kind==="reorder"?He(k.id)??null:null}}function de(){if(!S)return;let a=Kg(),u=a?null:wg(),c=s!==null&&!r.includes(s)&&!k?He(s)??null:null,h={...kx,..._g(),hover:c,members:he().length>1?he().flatMap(x=>He(x)??[]):[],box:u,badge:kg(u),caret:lc(),textSelection:uc(),draft:k?.kind==="create"?Wn(k.origin,k.current):null,draftEllipse:k?.kind==="create"&&o==="ellipse",marquee:k?.kind==="marquee"?Wn(k.origin,k.current):null,guides:k?Ce.guides:[],measures:k?Ce.measures:[],presence:l.ids.length===0?null:{frames:l.ids.flatMap(x=>He(x)??[]),label:l.label},highlight:rs(n,p).flatMap(x=>He(x.id)??[]),slots:Sy(),parked:r.filter(x=>!Ht(x)).flatMap(x=>He(x)??[]),lockHint:Mg(),path:a,turn:Ag(),pageLabels:Eg()};D.render(h)}let hs=null;function Sg(a){hs?.of!==n&&(hs={of:n,counts:new Map});let u=hs.counts.get(a);return u===void 0&&(u=Ai(n,[a]),hs.counts.set(a,u)),u}function Eg(){if(i)return[];let a=b.getResolution().nodes;return n.root.children.flatMap(u=>{if(u.type!=="frame")return[];let c=a.get(u.id);if(!c)return[];let h=Wo(c),x=u.name,w=typeof x=="string"&&x!==""?x:u.id,_=r.includes(u.id)?"selected":s===u.id?"hover":"idle";if(u.component!==!0)return[{id:u.id,frame:h,label:w,state:_}];let M=Sg(u.id);return[{id:u.id,frame:h,label:`\u25C6 ${w} \xB7 ${M} ${M===1?"use":"uses"}`,state:_,component:!0}]})}function Cg(a){let u=D.pageLabelRect(a),c=F(n.root,a);if(!u||!c)return;let h=c.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=a,x.setAttribute("aria-label",`Name of ${a}`),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 w=!1,_=M=>{if(w)return;w=!0;let N=x.value.trim();x.remove(),i=null,M&&N!==(typeof h=="string"?h:"")&&up(a,"name",N===""?void 0:N,"Rename"),de(),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)),i=x,e.appendChild(x),de(),x.focus(),x.select()}function Mg(){if(d===null||k||!lt().locked.has(d))return null;let a=He(d);return a?{frame:a,label:d}:null}function xs(a){let u=b.itemOf(a);if(u?.kind!=="text")return null;let c=u.lines[0]?.y??u.y,h={lines:u.lines.map(x=>({y:x.y-c,h:x.h,baseline:x.baseline-c,w:x.w,spans:x.spans.map(w=>({text:w.text,style:w.style,x:w.x-u.x,w:w.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:c}}function ka(){return o==="text"?"text":o!=="select"?"crosshair":"arrow"}function lc(){if(!ee)return null;let a=xs(ee.id);if(!a)return null;let u=ee.caret();return{x:a.item.x+u.x,y:a.top+u.y,h:u.h,...u.fill!==void 0?{fill:u.fill}:{}}}function uc(){if(!ee)return[];let a=xs(ee.id);return a?ee.highlight().map(u=>({x:a.item.x+u.x,y:a.top+u.y,w:u.w,h:u.h})):[]}function _a(a){if(!ee)return null;let u=xs(ee.id);if(!u)return null;let c=Xr(ee.id,a);return{x:c.x-u.item.x,y:c.y-u.top}}function Xr(a,u){let c=Mn(a),h=c===0?void 0:Cn(a);return h?at(u,ct(h),-c):u}function Ag(){let a=ee?.id??ae?.id;if(a===void 0)return null;let u=Mn(a),c=u===0?void 0:Cn(a);return c?{angle:u,centre:ct(c)}:null}function $g(a){let u=F(n.root,a);if(!u||u.type!=="text"||typeof u.h!="number")return[];let c=b.itemOf(a);if(c?.kind!=="text")return[];let h=te(Math.ceil(c.height));return h>u.h?[{op:"set",id:a,prop:"h",value:h}]:[]}function Og(a,u,c,h){let x=Qe?Qe.started:c,w=Qe?.label??h;Qe&&(Qe.started=!0);let _=[{op:"set",id:a,prop:"content",value:u}],M=_e(n,_);n=M.document,b.update(n);let N=$g(a);if(N.length===0){Sa(x,w,_,M.inverse),ms(_,w);return}let H=_e(n,N);n=H.document,b.update(n);let X=[..._,...N];Sa(x,w,X,[...H.inverse,...M.inverse]),ms(X,w)}function Sa(a,u,c,h){let x={label:u,ops:c,inverse:h};a&&I.amend(x)||I.push(x)}function Yr(a,u){let c=F(n.root,a);if(!c||c.type!=="text"||ee?.id===a)return;An("done"),un("select"),le([a]),ee=jf({id:a,content:()=>{let x=F(n.root,a);return x?.type==="text"?x.content:""},base:()=>{let x=F(n.root,a);return{weight:dt(a)?.values.weight??ci,italic:x?.type==="text"&&x.italic===!0,size:dt(a)?.values.size??fi}},layout:()=>xs(a)?.layout??{lines:[],width:0,height:0},measure:()=>b.getMeasurer(),write:(x,w,_)=>Og(a,x,w,_),invalidate:()=>{de(),fc(),xe("selection",r)},close:x=>An(x)});let h=u?_a(u):null;h?ee.pointTo(h,!1):ee.selectAll(),e.classList.add("vd-editor--editing"),W.value="",W.focus({preventScroll:!0}),de(),fc()}function An(a){let u=ee;if(!u)return;ee=null,B=!1,u.destroy(),e.classList.remove("vd-editor--editing","vd-editor--typing"),xe("selection",r);let c=F(n.root,u.id);c?.type==="text"&&Kf(c.content)&&!Ve(n,u.id)&&(ue([{op:"remove",id:u.id}],"Remove empty text"),le([])),e.ownerDocument.activeElement===W&&e.focus({preventScroll:!0}),de()}function fc(){let a=lc();if(!a)return;let u=b.documentToScreen({x:a.x,y:a.y});W.style.left=`${Math.round(u.x)}px`,W.style.top=`${Math.round(u.y)}px`}let rr=0;function cc(){e.classList.add("vd-editor--typing"),rr&&clearTimeout(rr),rr=setTimeout(()=>{rr=0,e.classList.remove("vd-editor--typing")},520)}function Ea(a){return pc(Y,a,Z,z)}function pc(a,u,c,h){let x=Dr(a,u);return x.length>0&&h?[...x,...Pr(a,x,c,h)]:x}function mc(){let a=new Map;for(let u of he())for(let c of Xn(u,n)){let h=sn(c);h&&a.set(c,h)}return a}function hc(a,u,c){let h=[];for(let[x,w]of a)h.push({nodeId:x,prop:"x",from:w.x,to:w.x+u}),h.push({nodeId:x,prop:"y",from:w.y,to:w.y+c});return h}function $n(a){Ca(Ea(a))}function Ca(a,u=a){let c=x=>{let w=z?.nodes.get(x);return w?{x:0,y:0,w:w.w,h:w.h}:void 0},h=Ci(Y,a,c);O=Ci(Y,u,c),b.update(h.length>0?_e(Y,h).document:Y),de()}function xc(){let a=bt(he().flatMap(h=>He(h)??[]));if(!a)return null;let u=new Map,c=new Map;for(let h of Wr()){let x=Cn(h),w=sn(h);!x||!w||(u.set(h,x),c.set(h,{x:x.x-w.x,y:x.y-w.y}))}return u.size===0?null:{bounds:a,frames:u,offsets:c}}function gc(a,u){let c=Xl(a.frames,a.bounds,u),h=[];for(let[x,w]of c){let _=a.frames.get(x),M=a.offsets.get(x);if(!_||!M)continue;let N=Mn(x),H=N===0?w:Oh(_,N,a.bounds,u);h.push({nodeId:x,prop:"x",from:_.x-M.x,to:H.x-M.x},{nodeId:x,prop:"y",from:_.y-M.y,to:H.y-M.y},{nodeId:x,prop:"w",from:_.w,to:H.w},{nodeId:x,prop:"h",from:_.h,to:H.h})}return h}function Tg(a,u){let c=sc();if(!c)return!1;let h=he().length===1&&c.length===1?c[0]:void 0,x=bt(he().flatMap(M=>He(M)??[])),w=h!==void 0?Cn(h):x;if(!w)return!1;let _=c.flatMap(M=>{let N=Cn(M),H=sn(M);return!N||!H?[]:[{id:M,frame:N,rotation:Mn(M),offset:{x:N.x-H.x,y:N.y-H.y}}]});return _.length===0?!1:(gt(u),ut({kind:"rotate",pointerId:u,origin:a,centre:ct(w),targets:_}),!0)}function Lg(a,u,c){let h=xc();return h?(gt(c),ut({kind:"scale",pointerId:c,origin:a,handle:u,...h}),!0):!1}function Dg(a){let u=xc();if(!u)return;let c=Dr(n,gc(u,a));if(c.length===0)return;let h=a.w!==u.bounds.w||a.h!==u.bounds.h;ue([...c,...Pr(n,c,qn(n),Ne(n))],h?"Resize":"Move")}function Pg(a,u,c){let h=na(a),x=qr();if(!h||!x)return!1;let w=Ft(x,h.axis)?.gaps[h.index],_=cs(he());return w===void 0||_.length===0?!1:(gt(c),ut({kind:"space",pointerId:c,origin:u,axis:h.axis,spacer:a,layout:x,gap:w,parts:_}),!0)}function Ng(a,u){let c=a.axis==="x"?u.x-a.origin.x:u.y-a.origin.y,h=Math.max(0,a.gap+c);$n(Ma(a.parts,a.axis,ra(a.layout,a.axis,h)))}function Ig(a,u){let c=qr(),h=c?Ft(c,a):void 0;if(!c||!h||h.gaps.length===0)return;let x=Dr(n,Ma(cs(he()),a,ra(c,a,Math.max(0,u))));x.length!==0&&ue([...x,...Pr(n,x,qn(n),Ne(n))],"Spacing")}function Rg(a){let u=qr(),c=u?Ft(u,a)?.gaps:void 0;return!c||c.length===0?null:Mf(c)?c[0]??null:"mixed"}function Ma(a,u,c){return a.map(h=>{let x=u==="x"?h.frame.x:h.frame.y;return{nodeId:h.node,prop:u,from:x,to:x+(c.get(h.member)??0)}})}function Fg(a,u,c){let h=qr();if(!h||!h.order.includes(a))return!1;let x=cs(he()),w=h.items.find(_=>_.id===a)?.frame;return x.length===0||!w?!1:(gt(c),ut({kind:"reorder",pointerId:c,id:a,layout:h,parts:x,grab:{x:u.x-w.x,y:u.y-w.y},to:h.order.indexOf(a),swap:!1}),!0)}function Bg(a,u,c){a.to=Lf(a.layout,u),a.swap=c;let h=Hg(a),x=new Map(h);x.set(a.id,{x:u.x-a.grab.x,y:u.y-a.grab.y}),Ca(Ea(yc(a,x)),Ea(yc(a,h)))}function Hg(a){let u=a.layout.order.indexOf(a.id);if(u===-1||a.to===u)return new Map;if(a.swap){let c=a.layout.order[a.to];return c===void 0?new Map:Nf(a.layout,a.id,c)}return Pf(a.layout,Df(a.layout.order,u,a.to))}function yc(a,u){let c=new Map(a.layout.items.map(x=>[x.id,x.frame])),h=[];for(let x of a.parts){let w=u.get(x.member),_=c.get(x.member);!w||!_||h.push({nodeId:x.node,prop:"x",from:x.frame.x,to:x.frame.x+(w.x-_.x)},{nodeId:x.node,prop:"y",from:x.frame.y,to:x.frame.y+(w.y-_.y)})}return h}function ut(a,u=[],c=n){re=c,E=u,Y=n,k=a,O=[],Z=qn(n),z=Ne(n),Ce=mt,Ae=Ug(a)?pf(n,z,Vg(a)):[]}function Ug(a){return a.kind==="move"||a.kind==="resize"||a.kind==="scale"||a.kind==="create"}function Vg(a){return a.kind==="move"||a.kind==="scale"?new Set(he()):a.kind==="resize"?new Set([a.id]):new Set}function Jr(a){return a.metaKey||a.ctrlKey?0:cf/b.getCamera().zoom}function dn(a){let u=[...E,...O];k=null,O=[],E=[],P=null,K=null,Ce=mt,n=re,b.update(n),ue(u,a),de()}function zg(){let a=O.length>0?_e(Y,O).document:Y,u=new Set(he().flatMap(x=>vc(x,a))),c=[];for(let x of he()){if(Ve(a,x)||tn(a,x))continue;let w=F(a.root,x),_=Fe(a.root,x);if(!w||!_)continue;let M=He(x);if(!M)continue;let N={x:M.x+M.w/2,y:M.y+M.h/2},H=nr(N,u)??n.root.id;if(H===_.id)continue;let X=F(a.root,H);if(!X||!fe(X))continue;c.push({op:"move",id:x,parent:H,index:ne(X).length});let J={x:an(_.id).x-an(H).x,y:an(_.id).y-an(H).y};if(!(J.x===0&&J.y===0))for(let be of Xn(x,a)){let Q=sn(be);Q&&(c.push({op:"set",id:be,prop:"x",value:te(Q.x+J.x)}),c.push({op:"set",id:be,prop:"y",value:te(Q.y+J.y)}))}}if(c.length===0)return[];let h=_e(a,c).document;return[...c,...Nr(a,h,u)]}function vc(a,u){let c=F(u.root,a);if(!c)return[];let h=[];return oe(c,x=>{h.push(x.id)}),h}function Aa(){if(!k)return;k=null,O=[],P=null,K=null,Ce=mt;let a=E.length>0;n=re,E=[],a&&le(r.filter(u=>F(n.root,u))),b.update(n),de()}let jg=5,gs=8;function bc(a,u=n,c=b.getResolution()){let h=F(u.root,a),x=c.nodes.get(a);if(h?.type!=="vector"||!x)return;let w={x:x.absX,y:x.absY,w:Math.max(0,x.w),h:Math.max(0,x.h)};return{node:h,view:Co(h.view,w.w,w.h),box:w}}function Zr(a,u=n,c=b.getResolution()){let h=bc(a,u,c);if(h)return qt(Eo(h.node.d).contours,Mo(h.view,h.box))}function ln(a,u,c,h=n,x=b.getResolution()){let w=bc(a,h,x);if(!w)return[];let{node:_,view:M,box:N}=w,H=qt(u,wd(M,N)),X=[],J=(wt,lr,Hy)=>{lr!==Hy&&X.push({op:"set",id:a,prop:wt,value:lr})};J("d",Gt(H),_.d);let be=[_.x,_.y,_.w,_.h].every(wt=>typeof wt=="number"),Q=Vn(H),we=Vn(u);if(!c||!be||!Q||!we)return X;let Ie=N.x-_.x,Xe=N.y-_.y;return J("view",zn(Q),_.view),J("x",te(we.x-Ie),_.x),J("y",te(we.y-Xe),_.y),J("w",te(we.w),_.w),J("h",te(we.h),_.h),X}function On(a){return F(n.root,a)?.type!=="vector"||!Ht(a)?!1:(ee&&An("done"),ie&&ys(),le([a]),ae={id:a,picked:new Set},o!=="select"&&un("select"),xt(null),de(),!0)}function Qr(){ae&&(ae=null,de())}function Kg(){if(ie){let c=ie.contours[ie.contour],h=c?.anchors??[],x=h[h.length-1],w=h[0],_=ie.hover,M=_!==null&&w!==void 0&&h.length>=2&&!c?.closed&&eo(w,_)<=gs;return{contours:ie.contours,anchors:h.map((N,H)=>({key:Ge(ie?.contour??0,H),at:N,selected:H===h.length-1})),handles:x?au(ie.contours,new Set([Ge(ie.contour,h.length-1)])):[],pending:x&&_&&!ie.dragging&&!c?.closed?{from:x,...x.out?{c1:x.out}:{},to:_}:null,closeAt:M?w:null}}if(!ae)return null;let a=Zr(ae.id);if(!a)return null;let u=new Set(su(a,ae.picked));return{contours:a,anchors:a.flatMap((c,h)=>c.anchors.map((x,w)=>({key:Ge(h,w),at:x,selected:u.has(Ge(h,w))}))),handles:au(a,u)}}function eo(a,u){return Math.hypot(a.x-u.x,a.y-u.y)*b.getCamera().zoom}function Gg(a,u,c,h){if(!ae)return!1;let x=ae.id,w=Zr(x);if(!w)return ae=null,!1;a.preventDefault(),gt(a.pointerId);let _=D.hitPath(u);if(_?.kind==="handle"){let N=Th(_.key),H=N?w[N.contour]?.anchors[N.index]:void 0;if(N&&H)return ut({kind:"pathHandle",pointerId:a.pointerId,id:x,start:w,contour:N.contour,index:N.index,side:N.side,smooth:Ti(H),last:w}),!0}if(_?.kind==="anchor")return a.altKey?(ae.picked=new Set([_.key]),ue(ln(x,Lh(w,_.key),!1),"Convert point"),!0):(a.shiftKey?ae.picked.has(_.key)?ae.picked.delete(_.key):ae.picked.add(_.key):ae.picked.has(_.key)||(ae.picked=new Set([_.key])),ut({kind:"points",pointerId:a.pointerId,id:x,origin:c,start:w,keys:new Set(ae.picked),lead:_.key,moved:!1,last:w}),de(),!0);let M=Sd(w,c);if(M&&M.distance*b.getCamera().zoom<=jg){if(h>=2){let J=Ed(w,M.contour,M.segment,M.t);return ae.picked=new Set([Ge(M.contour,M.segment+1)]),ue(ln(x,J,!1),"Add point"),!0}let N=w[M.contour],H=N.anchors[M.segment],X=N.anchors[(M.segment+1)%N.anchors.length];return ut({kind:"segment",pointerId:a.pointerId,id:x,origin:c,start:w,contour:M.contour,segment:M.segment,t:M.t,straight:!H?.out&&!X?.in,last:w}),!0}return ut({kind:"pointMarquee",pointerId:a.pointerId,origin:c,current:c,additive:a.shiftKey}),!0}function qg(a,u,c,h){let x=ou(a.start,a.lead);if(!x||h===0)return{dx:u,dy:c};let w=x.x+u,_=x.y+c,M=h,N=h,H=u,X=c;return a.start.forEach((J,be)=>J.anchors.forEach((Q,we)=>{a.keys.has(Ge(be,we))||(Math.abs(Q.x-w)<M&&(M=Math.abs(Q.x-w),H=Q.x-x.x),Math.abs(Q.y-_)<N&&(N=Math.abs(Q.y-_),X=Q.y-x.y))})),{dx:H,dy:X}}function Wg(a,u){if(!k)return!1;let c=(h,x)=>{z&&Ca(ln(x,h,!1,Y,z))};switch(k.kind){case"points":{let h=u;a.shiftKey&&(h=Qo(k.origin,u));let x={dx:h.x-k.origin.x,dy:h.y-k.origin.y};if(!k.moved&&Math.hypot(x.dx,x.dy)*b.getCamera().zoom<En)return!0;k.moved=!0;let{dx:w,dy:_}=a.shiftKey?x:qg(k,x.dx,x.dy,Jr(a));return k.last=Pi(k.start,k.keys,w,_),c(k.last,k.id),!0}case"pathHandle":{let h=k.start[k.contour]?.anchors[k.index],x=a.shiftKey&&h?Qo(h,u):u;return k.last=Li(k.start,k.contour,k.index,k.side,x,{smooth:k.smooth,breakSmooth:a.altKey}),c(k.last,k.id),!0}case"segment":return k.last=Ph(k.start,k.contour,k.segment,k.t,u.x-k.origin.x,u.y-k.origin.y,k.straight),c(k.last,k.id),!0;case"pointMarquee":return k.current=u,de(),!0;default:return!1}}function Xg(a){if(!k)return!1;switch(k.kind){case"points":case"pathHandle":case"segment":{let u=k.kind!=="points"||k.moved,c=k.kind==="points"?k.keys.size===1?"Move point":"Move points":k.kind==="pathHandle"?"Adjust curve":"Reshape";return O=u&&z?ln(k.id,k.last,!0,Y,z):[],dn(c),!0}case"pointMarquee":{let u=Wn(k.origin,k.current),c=k.additive;if(k=null,Ce=mt,!ae)return!0;let h=b.getCamera().zoom;if(u.w*h<En&&u.h*h<En){if(b.hitTest(a)===ae.id)ae.picked=new Set;else{Qr();let _=Gr(a);le(_===null?[]:[_])}return de(),!0}let x=Zr(ae.id)??[],w=iu(x).filter(_=>{let M=ou(x,_);return M!==void 0&&Et(u,M.x,M.y)});return ae.picked=new Set(c?[...ae.picked,...w]:w),de(),!0}default:return!1}}function Yg(a){if(!ae)return!1;let u=ae.id,c=a.metaKey||a.ctrlKey;if(a.key==="Escape"||a.key==="Enter"&&!c)return a.preventDefault(),k?Aa():Qr(),!0;let h=Zr(u);if(!h)return!1;let x=new Set(su(h,ae.picked));if(a.key==="Delete"||a.key==="Backspace"){if(a.preventDefault(),x.size===0)return!0;let M=Dh(h,x);return ae.picked=new Set,M.length===0?(Qr(),ar(),!0):(ue(ln(u,M,!0),x.size===1?"Delete point":"Delete points"),!0)}let w=a.shiftKey?zx:Vx,_=Gx[a.key];return _&&!c?(a.preventDefault(),x.size>0&&ue(ln(u,Pi(h,x,_[0]*w,_[1]*w),!0),"Nudge points"),!0):c&&a.key.toLowerCase()==="a"?(a.preventDefault(),ae.picked=new Set(iu(h)),de(),!0):c&&!a.shiftKey&&a.code==="KeyJ"?(a.preventDefault(),ue(ln(u,Nh(h,x),!0),"Close path"),!0):!1}function Jg(a,u){if(a.preventDefault(),gt(a.pointerId),!ie){ie=Zg(u)??{contours:[{closed:!1,anchors:[{x:u.x,y:u.y}]}],contour:0,target:null,hover:null,dragging:null};let _=ie.contours[ie.contour];ie.dragging={pointerId:a.pointerId,index:_.anchors.length-1,origin:u},de();return}let c=ie.contours[ie.contour],h=c.anchors[0],x=c.anchors[c.anchors.length-1];if(h&&c.anchors.length>=2&&eo(h,u)<=gs){ie.contours[ie.contour]={...c,closed:!0},ie.dragging={pointerId:a.pointerId,index:0,origin:h},de();return}let w=a.shiftKey&&x?Qo(x,u):u;ie.contours[ie.contour]={...c,anchors:[...c.anchors,{x:w.x,y:w.y}]},ie.dragging={pointerId:a.pointerId,index:c.anchors.length,origin:w},de()}function Zg(a){let u=r.length===1?r[0]:null;if(u===null||!Ht(u))return null;let c=Zr(u);if(!c)return null;for(let h=0;h<c.length;h+=1){let x=c[h];if(x.closed||x.anchors.length<1)continue;let w=x.anchors[0],_=x.anchors[x.anchors.length-1],M=eo(_,a)<=gs,N=!M&&eo(w,a)<=gs;if(!M&&!N)continue;let H=[...c];return N&&(H[h]=Ih(x)),{contours:H,contour:h,target:u,hover:null,dragging:null}}return null}function Qg(a,u){if(!ie)return;let c=ie.dragging;if(!c||c.pointerId!==a.pointerId){let N=ie.contours[ie.contour],H=N?.anchors[N.anchors.length-1];ie.hover=a.shiftKey&&H?Qo(H,u):u,de();return}if(eo(c.origin,u)<En)return;let h=ie.contours[ie.contour],x=h.anchors[c.index];if(!x)return;let w={x:2*x.x-u.x,y:2*x.y-u.y},_=a.altKey?x.in:w,M=[...h.anchors];M[c.index]={x:x.x,y:x.y,..._?{in:_}:{},out:u},ie.contours[ie.contour]={...h,anchors:M},de()}function ey(a){!ie?.dragging||ie.dragging.pointerId!==a.pointerId||(Ka(a.pointerId),ie.dragging=null,ie.contours[ie.contour]?.closed?ys():de())}function ys(){if(!ie)return;let a=ie;ie=null;let u=a.contours[a.contour];if(!u||u.anchors.length<2){de();return}if(a.target!==null){ue(ln(a.target,a.contours,!0),"Extend path"),un("select"),On(a.target);return}let c=Vn(a.contours),h=u.anchors[0];if(!c)return;let x=dr(nr(h)??g??n.root.id),w=F(n.root,x)??n.root,_=an(x),M=qt(a.contours,H=>({x:H.x-c.x,y:H.y-c.y})),N=gn(n.root,"path");ue([{op:"insert",parent:x,index:ne(w).length,node:Is({id:N,x:te(c.x-_.x),y:te(c.y-_.y),w:te(c.w),h:te(c.h),view:zn({x:0,y:0,w:c.w,h:c.h}),d:Gt(M),fill:"none",stroke:t.defaultStroke??"#1f2937",strokeWidth:2,cap:"round",join:"round"})}],"Draw path"),un("select"),On(N)}function $a(a=he()){let u=[],c=[];for(let h of a){let x=F(n.root,h),w=Fe(n.root,h),_=dt(h);if(!x||!w||!_||x.type!=="rect"&&x.type!=="ellipse"||Ve(n,h))continue;let M=Math.max(0,_.w),N=Math.max(0,_.h),H=x.type==="rect"?Cd(M,N,_.values.radius??0):Md(M,N),X=Is({id:h,...x.name===void 0?{}:{name:x.name},x:x.x,y:x.y,w:x.w,h:x.h,view:zn({x:0,y:0,w:M,h:N}),d:Gt(H),...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}:{}}),J=w.children.findIndex(be=>be.id===h);u.push({op:"remove",id:h},{op:"insert",parent:w.id,index:J,node:X}),c.push(h)}c.length!==0&&(ue(u,c.length===1?"Convert to vector":`Convert ${c.length} to vector`),le(c),c.length===1&&On(c[0]))}function wc(){return he().filter(a=>{let u=F(n.root,a)?.type;return u==="rect"||u==="ellipse"}).length}let ty=450,kc=4,to={x:0,y:0,at:0,count:0};function ny(a){let u=Date.now(),h=Math.abs(a.x-to.x)<=kc&&Math.abs(a.y-to.y)<=kc&&u-to.at<=ty?to.count+1:1;return to={x:a.x,y:a.y,at:u,count:h},h}let _c=a=>{if(C=a.pointerType==="touch",C){y.add(a.pointerId),v=y.size===1?{pointerId:a.pointerId,screen:b.pointerPoint(a)}:null;return}if(a.button!==0||m)return;let u=b.pointerPoint(a),c=b.screenToDocument(u);ot=c;let h=ny(u);if(ee){let N=_a(c),H=b.itemOf(ee.id),X=Xr(ee.id,c);if(N&&H&&Et(H,X.x,X.y)){a.preventDefault(),gt(a.pointerId),B=!0,h>=3?ee.selectLineAt(N):h===2?ee.selectWordAt(N):ee.pointTo(N,a.shiftKey),W.focus({preventScroll:!0}),de();return}An("blur")}if(e.focus({preventScroll:!0}),o==="select"&&(a.metaKey||a.ctrlKey)&&We(c)){a.preventDefault();return}if(o==="pen"){Jg(a,c);return}if(ae&&o==="select"&&Gg(a,u,Xr(ae.id,c),h))return;if(o!=="select"){a.preventDefault(),gt(a.pointerId),ut({kind:"create",pointerId:a.pointerId,origin:c,current:c}),de();return}let x=he().length===1?he()[0]:null;if(x!==null){let N=F(n.root,x),H=D.hitAdjuster(u),X=N&&H?Bi(N,H.id):void 0,J=X?He(x):void 0;if(X&&J&&H){a.preventDefault(),gt(a.pointerId),ut({kind:"adjust",pointerId:a.pointerId,id:x,adjuster:X,handleId:H.id,frame:J,from:dt(x)?.values[X.prop]??0});return}let be=N&&!fe(N)?D.hitHandle(u):null,Q=be?sn(x):void 0,we=Q?Cn(x):void 0;if(be&&Q&&we){a.preventDefault(),gt(a.pointerId),ut({kind:"resize",pointerId:a.pointerId,origin:c,id:x,handle:be.handle,frame:Q,offset:{x:we.x-Q.x,y:we.y-Q.y},rotation:Mn(x)});return}}let w=he().length>0?D.hitHandle(u):null;if(w&&Lg(c,w.handle,a.pointerId)){a.preventDefault();return}let _=D.hitPageLabel(u);if(_!==null){if(a.preventDefault(),g=null,a.shiftKey){le(r.includes(_)?r.filter(N=>N!==_):[...r,_]);return}if(r.includes(_)||le([_]),h===2){Cg(_);return}Sc(c,a.pointerId,a.altKey);return}if(he().length>0&&D.hitRotate(u)!==null&&Tg(c,a.pointerId)){a.preventDefault();return}if(he().length>1){let N=D.hitRing(u);if(N!==null&&Fg(N,c,a.pointerId)){a.preventDefault();return}let H=D.hitSpacer(u);if(H!==null&&Pg(H,c,a.pointerId)){a.preventDefault();return}}let M=Gr(c);if(M===null){a.preventDefault(),gt(a.pointerId),g=null,a.shiftKey||le([]),ut({kind:"marquee",pointerId:a.pointerId,origin:c,current:c});return}g!==null&&!Re(n.root,M).includes(g)&&(g=null),a.shiftKey?le(r.includes(M)?r.filter(N=>N!==M):[...r,M]):r.includes(M)||le([M]),Sc(c,a.pointerId,a.altKey)&&a.preventDefault()};function ry(a){ee&&An("blur");let u=Gr(b.screenToDocument(a));u!==null&&g!==null&&!Re(n.root,u).includes(g)&&(g=null),u===null&&(g=null),le(u===null?[]:[u])}function Sc(a,u,c){let h=n,x=[];if(c){let _=Zc({x:0,y:0});_&&(x=_.ops,n=_e(n,x).document,b.update(n),le(_.ids))}let w=mc();return w.size===0?(n=h,b.update(n),!1):(gt(u),ut({kind:"move",pointerId:u,origin:a,frames:w,bounds:bt(he().flatMap(_=>He(_)??[]))},x,h),!0)}let Ec=a=>{let u=b.pointerPoint(a);if(a.pointerType==="touch"){v?.pointerId===a.pointerId&&Math.hypot(v.screen.x-u.x,v.screen.y-u.y)>Xk&&(v=null);return}if(ot=b.screenToDocument(u),B&&ee){let h=_a(ot);h&&ee.pointTo(h,!0);return}if(ie&&o==="pen"){Qg(a,ot);return}if(!k){py(u);return}if(k.pointerId!==a.pointerId)return;let c=ot;if(!Wg(a,ae?Xr(ae.id,c):c))switch(k.kind){case"move":{let h=c.x-k.origin.x,x=c.y-k.origin.y;if(k.bounds){let w={...k.bounds,x:k.bounds.x+h,y:k.bounds.y+x};Ce=mf(w,Ae,Jr(a)),h+=Ce.dx,x+=Ce.dy}$n(hc(k.frames,h,x));return}case"resize":{let{id:h,handle:x,frame:w,origin:_,offset:M,rotation:N}=k,H=c.x-_.x,X=c.y-_.y;if(N!==0){Ce=mt;let Q=Mh(w,x,H,X,N);$n(Si(w,Q).map(we=>({nodeId:h,prop:we,from:w[we],to:Q[we]})));return}let J=en(w,x,H,X);Ce=Ki({...J,x:J.x+M.x,y:J.y+M.y},x,Ae,Jr(a)),H+=Ce.dx,X+=Ce.dy;let be=en(w,x,H,X);$n(Si(w,be).map(Q=>({nodeId:h,prop:Q,from:w[Q],to:be[Q]})));return}case"scale":{let{handle:h,bounds:x,origin:w,frames:_,offsets:M}=k,N=c.x-w.x,H=c.y-w.y,X=en(x,h,N,H);Ce=Ki(X,h,Ae,Jr(a)),N+=Ce.dx,H+=Ce.dy,$n(gc({bounds:x,frames:_,offsets:M},en(x,h,N,H)));return}case"space":Ng(k,c);return;case"reorder":Bg(k,c,a.metaKey||a.ctrlKey);return;case"rotate":{let{centre:h,origin:x,targets:w}=k,_=w[0],M=Ah(h,x,c,_?.rotation??0,a.shiftKey?Rk:void 0);K=Ro((_?.rotation??0)+M);let N=[],H=w.length===1;for(let X of $h(w,h,M)){let J=w.find(be=>be.id===X.id);J&&(N.push({nodeId:X.id,prop:"rotation",from:J.rotation,to:X.rotation}),!H&&N.push({nodeId:X.id,prop:"x",from:J.frame.x-J.offset.x,to:te(X.frame.x-J.offset.x)},{nodeId:X.id,prop:"y",from:J.frame.y-J.offset.y,to:te(X.frame.y-J.offset.y)}))}$n(N);return}case"adjust":{let h=k.adjuster.valueAt(k.frame,k.handleId,c);P=h,$n([{nodeId:k.id,prop:k.adjuster.prop,from:k.from,to:h}]);return}case"create":{Ce=hf(c,Ae,Jr(a));let h={x:c.x+Ce.dx,y:c.y+Ce.dy};k.current=a.shiftKey&&o!=="text"?Uk(k.origin,h):h,de();return}case"marquee":{k.current=c,de();return}}},vs=a=>{if(a.pointerType==="touch"){if(y.delete(a.pointerId),v?.pointerId!==a.pointerId)return;v=null,a.type==="pointerup"&&ry(b.pointerPoint(a));return}if(B){B=!1,Ka(a.pointerId),W.focus({preventScroll:!0});return}if(ie){ey(a);return}if(!k||k.pointerId!==a.pointerId)return;Ka(a.pointerId);let u=b.screenToDocument(b.pointerPoint(a));if(!Xg(ae?Xr(ae.id,u):u))switch(k.kind){case"create":{let c=Wn(k.origin,k.current),h=o==="text"?"text":o==="frame"?"frame":o==="ellipse"?"ellipse":"rect";k=null,Ce=mt,de();let x=c.w<En||c.h<En;if(x&&h!=="text")return;let w=x?{x:c.x,y:c.y,w:Kx.w,h:Kx.h}:c,_=dr(nr({x:w.x,y:w.y})??g??n.root.id),M=F(n.root,_)??n.root,N=an(_),H={x:Math.round(w.x-N.x),y:Math.round(w.y-N.y),w:Math.round(w.w),h:Math.round(w.h)},X=gn(n.root,h);ue([{op:"insert",parent:_,index:ne(M).length,node:h==="text"?dd({...H,id:X,content:""}):h==="frame"?Ns({...H,id:X,background:Hx,children:[]}):h==="ellipse"?od({...H,id:X,fill:t.defaultFill??"#3b82f6"}):ad({...H,id:X,fill:t.defaultFill??"#3b82f6"})}],Hk[h]),le([X]),un("select"),h==="text"&&Yr(X);return}case"marquee":{let c=Wn(k.origin,k.current),h=a.shiftKey;if(k=null,Ce=mt,c.w>=En||c.h>=En){let x=By(c);le(h?[...new Set([...r,...x])]:x)}de();return}case"move":{let c=zg();c.length>0&&(O=[...O,...c]),dn(E.length>0?"Duplicate":"Move");return}case"resize":dn("Resize");return;case"scale":dn(r.length===1?"Resize group":`Resize ${r.length} elements`);return;case"space":dn("Spacing");return;case"reorder":dn(k.swap?"Swap":"Reorder");return;case"adjust":dn("Corner radius");return;case"rotate":dn("Rotate");return}},bs=null;function oy(a,u,c){let h=mc();if(h.size===0)return;let x=pc(n,hc(h,a,u),qn(n),Ne(n));if(x.length===0)return;let w="Nudge",_=r.join(`
2890
- `),M=c&&bs!==null&&bs.selection===_&&I.top===bs.entry;Qe===null?(Qe={label:w,started:M},ue(x,w),ac()):ue(x,w),bs=I.top?{entry:I.top,selection:_}:null}function Cc(){b.fitToContent()}function Mc(){b.setCamera({...b.getCamera(),zoom:1})}function sy(){let a=bt(r.flatMap(c=>He(c)??[]));if(!a)return;let u=e.getBoundingClientRect();b.setCamera(Rt({x:a.x,y:a.y,width:a.w,height:a.h},{width:u.width||a.w,height:u.height||a.h},Fk))}function Ac(a,u){if((a.metaKey||a.ctrlKey)&&!a.altKey){let h=a.code==="Equal"?jx:a.code==="Minus"?1/jx:null;return h!==null?(a.preventDefault(),b.zoomBy(h),!0):a.code==="Digit0"&&!a.shiftKey?(a.preventDefault(),Mc(),!0):!1}return u||!a.shiftKey||a.altKey?!1:a.code==="Digit1"?(a.preventDefault(),Cc(),!0):a.code==="Digit2"?r.length===0?!1:(a.preventDefault(),sy(),!0):!1}function $c(a){return a.ctrlKey&&!a.metaKey&&!a.altKey&&!a.shiftKey&&a.key.toLowerCase()==="y"}function Oc(a){return Re(n.root,a).slice(0,-1).reverse().find(c=>{let h=F(n.root,c);return h!==void 0&&no(h)})??null}function iy(){if(r.length!==1)return!1;let a=F(n.root,r[0]);if(!a||!(no(a)||a.type==="frame"))return!1;let u=ne(a).map(c=>c.id).filter(Ht);return u.length===0?!1:(no(a)&&Fa(a.id),le(u),!0)}function ay(){let a=r[0];if(a===void 0)return!1;let u=Fe(n.root,a);return!u||u.id===n.root.id?!1:u.id===g?(Ba(),!0):(g=Oc(u.id),le([u.id]),!0)}function dy(a){let u=a===1?r[r.length-1]:r[0];if(u===void 0)return!1;let c=Fe(n.root,u);if(!c)return!1;let h=ne(c).map(_=>_.id).filter(_=>_===u||Ht(_)),x=h.indexOf(u),w=h[(x+a+h.length)%h.length];return w!==void 0&&le([w]),!0}let Tc=a=>{if(pa(a.target))return;if(ee){let x=(a.metaKey||a.ctrlKey)&&a.key.toLowerCase()==="z";if(x||$c(a)){a.preventDefault(),ee.breakBurst(),a.shiftKey||!x?oo():ro();return}Ac(a,!0);return}if(ie&&(a.key==="Enter"||a.key==="Escape")){a.preventDefault(),ys();return}if(Yg(a))return;if((a.metaKey||a.ctrlKey)&&a.shiftKey&&a.code==="KeyO"){if(wc()===0)return;a.preventDefault(),$a();return}if(a.key==="Enter"&&a.shiftKey&&!ds(a)){ay()&&a.preventDefault();return}if(a.key==="Enter"&&!ds(a)&&r.length===1){let x=r[0];if(F(n.root,x)?.type==="vector"&&On(x)){a.preventDefault();return}}if(a.key==="Enter"&&!ds(a)&&r.length===1){let x=r[0];if(F(n.root,x)?.type==="text"){a.preventDefault(),Yr(x);return}}if(a.key==="Enter"&&!ds(a)){iy()&&a.preventDefault();return}if(a.key==="Tab"&&!ds(a)){dy(a.shiftKey?-1:1)&&a.preventDefault();return}if(a.code==="Space"&&!m){m=!0,et(qe("grab"));return}let u=a.metaKey||a.ctrlKey;if(u&&a.key.toLowerCase()==="z"){a.preventDefault(),a.shiftKey?oo():ro();return}if($c(a)){a.preventDefault(),oo();return}if(Ac(a,!1))return;if(u&&a.shiftKey&&!a.altKey&&a.code==="KeyL"){if(!L.lock||r.length===0)return;a.preventDefault(),ir(r,"locked");return}if(u&&a.shiftKey&&!a.altKey&&a.code==="KeyH"){if(!L.hide||r.length===0)return;a.preventDefault(),ir(r,"hidden");return}if(u&&a.altKey&&!a.shiftKey&&a.code==="KeyK"){if(!Yo(n,r))return;a.preventDefault(),Va();return}if(u&&a.altKey&&!a.shiftKey&&a.code==="KeyB"){if(!r.some(x=>F(n.root,x)?.type==="instance"))return;a.preventDefault(),za();return}if(u&&a.key.toLowerCase()==="g"){a.preventDefault(),a.shiftKey?Ia():Na();return}if(u&&a.key.toLowerCase()==="a"){a.preventDefault(),Ha();return}if(u&&!a.altKey&&a.key.toLowerCase()==="d"){a.preventDefault(),Da();return}if(a.altKey){let x=Vk[a.code];if(x&&!u){a.preventDefault(),Wc(x);return}let w=zk[a.code];if(w&&a.ctrlKey){a.preventDefault(),Yc(w);return}}if(a.key==="]"||a.key==="["){if(r.length===0)return;a.preventDefault();let x=a.key==="]";Ra(u?x?"front":"back":x?"forward":"backward");return}if(a.key==="Escape"){k?Aa():g!==null?Ba():le([]);return}if(a.key==="Delete"||a.key==="Backspace"){if(r.length===0)return;a.preventDefault(),ar();return}let c=Gx[a.key];if(c&&!u&&!a.altKey){if(r.length===0||(a.preventDefault(),k||ie))return;let x=a.shiftKey?zx:Vx;oy(c[0]*x,c[1]*x,a.repeat);return}let h=u||a.altKey?void 0:Gf[a.key.toLowerCase()];h&&un(h)};function Lc(){if(!ee)return null;let a=F(n.root,ee.id);if(a?.type!=="text")return null;let{anchor:u,head:c}=ee.getSelection();return u===c?null:Qn(If(a.content,u,c))}let Dc=a=>{if(pa(a.target))return;let u=Lc()??or();u!==null&&(a.preventDefault(),a.clipboardData?.setData("text/plain",u))},Pc=a=>{if(pa(a.target))return;let u=Lc();if(u!==null&&ee){a.preventDefault(),a.clipboardData?.setData("text/plain",u);let{anchor:h,head:x}=ee.getSelection();ee.breakBurst(),ee.setSelection(h,x),ee.handleInput({inputType:"deleteByCut",data:null});return}let c=or();c!==null&&(a.preventDefault(),a.clipboardData?.setData("text/plain",c),ar())},Nc=a=>{if(pa(a.target))return;a.preventDefault();let u=du(a.clipboardData);if(u&&!ee){let h=Ey();h?La(h,u):ep(u,ot??void 0);return}let c=a.clipboardData?.getData("text/plain")||void 0;if(ee&&c!==void 0){ee.handleInput({inputType:"insertFromPaste",data:c});return}Ta(c)},Ic=a=>{a.code==="Space"&&(m=!1,et(qe(ka())))},Rc=a=>{if(!G)return;a.preventDefault(),k&&Aa();let u=b.pointerPoint(a),c=b.screenToDocument(u),h=Gr(c),x=ly(c),w=b.hitTest(c),_=w!==null&&r.some(N=>Re(n.root,w).includes(N));h===null?_||le([]):r.includes(h)||le([h]);let M=(t.menuExtras?.(r)??[]).map(N=>"separator"in N?N:{...N,id:`${qf}${N.id}`});G.open(u,bf(uy(x),M))};function ly(a){let{locked:u}=lt(),c=[];for(let h of[...b.getScene().items].reverse()){if(!u.has(h.id)||!b.hitTest(a,w=>w===h.id))continue;let x=so(n.root,h.id,"locked");x!==void 0&&!c.includes(x)&&c.push(x)}return c}function uy(a=[]){let u=r.length===1?F(n.root,r[0]):void 0,c=[];if(u){let h=u;for(let x of Ct(u)){let w=h[x];w===void 0||!ye(w)||ui(w).kind!=="literal"&&c.push({prop:x,source:`=${w.expr}`})}}return{count:r.length,hasGroup:r.some(h=>{let x=F(n.root,h);return x!==void 0&&$e(x)}),canPaste:Wf!==null,isText:r.length===1&&F(n.root,r[0])?.type==="text",isVector:he().length===1&&F(n.root,he()[0])?.type==="vector",convertible:wc(),bound:c,lock:L.lock?r.every(h=>lt().locked.has(h))?"unlock":"lock":null,hide:L.hide?r.every(h=>lt().hidden.has(h))?"show":"hide":null,locksHere:a,anyLocked:Ua("locked").length>0,hiddenCount:Ua("hidden").length,components:fy()}}function fy(){let a=r.length===1?r[0]:void 0,u=a===void 0?void 0:ip(a),c=u===void 0?void 0:F(n.root,u),h=0;if(a!==void 0&&u!==void 0&&c?.type==="instance"){let x=c.overrides??{};h=a===u?Object.keys(x).length:x[a.slice(u.length+1)]===void 0?0:1}return{create:Yo(n,r),instance:c?.type==="instance"&&a===u,part:u!==void 0&&a!==u,component:a!==void 0&&tn(n,a),overrides:h,uses:Ai(n,r.filter(x=>tn(n,x)))}}function cy(a){if(e.focus({preventScroll:!0}),a.startsWith(qf)){t.onMenuCommand?.(a.slice(qf.length),[...r]);return}if(a.startsWith("unlock:")){sr([a.slice(7)],"locked",!1);return}if(a.startsWith("detach:")){let u=a.slice(7),c=r[0];c!==void 0&&fp(c,u);return}switch(a){case"copy":or();return;case"cut":Qc();return;case"editText":{let u=r[0];u!==void 0&&Yr(u);return}case"editPoints":{let u=r[0];u!==void 0&&On(u);return}case"toVector":return $a();case"duplicate":return Da();case"paste":return Ta();case"group":return Na();case"ungroup":return Ia();case"createComponent":Va();return;case"detachInstance":return za();case"goToComponent":{let u=r[0];u!==void 0&&dp(u);return}case"resetOverrides":{let u=r[0];u!==void 0&&ap(u);return}case"placeInstance":{let u=r[0];u!==void 0&&ja(u);return}case"front":case"forward":case"backward":case"back":return Ra(a);case"delete":return ar();case"selectAll":return Ha();case"toggleLock":return ir(r,"locked");case"toggleHidden":return ir(r,"hidden");case"unlockAll":return Ss("locked");case"showAll":return Ss("hidden");case"fit":return Cc();case"zoom100":return Mc()}}let Fc=a=>{if(C||o!=="select"||m||ae)return;let u=b.screenToDocument(b.pointerPoint(a)),c=b.hitTest(u,M=>!lt().locked.has(M));if(c===null)return;let h=_s().find(M=>M.id===c);if(h){a.preventDefault(),Cy(h);return}let x=F(n.root,c);if(x?.type==="text"){a.preventDefault(),Yr(c,u);return}if(x?.type==="vector"){a.preventDefault(),On(c);return}let w=Re(n.root,c),_=g===null?1:w.indexOf(g)+1;for(let M=Math.max(_,1);M<w.length;M+=1){let N=w[M];if(N===void 0)break;let H=F(n.root,N);if(!(!H||!no(H))){a.preventDefault(),Fa(N),le([w[M+1]??N]);return}}},Bc=a=>Array.from(a.dataTransfer?.types??[]).includes("Files"),Hc=()=>t.importImage!==void 0||t.importAudio!==void 0,Uc=a=>Array.from(a.dataTransfer?.types??[]).includes(ma),Vc=a=>{if(Uc(a)){a.preventDefault(),a.dataTransfer&&(a.dataTransfer.dropEffect="copy");return}if(!Bc(a)||!Hc())return;a.preventDefault(),a.dataTransfer&&(a.dataTransfer.dropEffect="copy");let u=b.screenToDocument(b.pointerPoint(a)),c=np(u)?.id??null;c!==f&&(f=c,de())},zc=a=>{a.relatedTarget instanceof Node&&e.contains(a.relatedTarget)||f!==null&&(f=null,de())},jc=a=>{if(Uc(a)){a.preventDefault();let _=a.dataTransfer?.getData(ma)??"";e.focus({preventScroll:!0}),ja(_,b.screenToDocument(b.pointerPoint(a)));return}if(!Bc(a)||!Hc())return;a.preventDefault();let u=b.screenToDocument(b.pointerPoint(a)),c=np(u);f=null,de();let h=Array.from(a.dataTransfer?.files??[]),x=h.find(Hh);if(x&&t.importAudio){let _=nr(u),M=_===null?void 0:yt(n).get(_),N=Ii(n),H=M!==void 0&&N.includes(M)?M:Ri(n,r,null)??M??null;H!==null&&tp(x,H);return}if(!t.importImage)return;let w=h.find(_=>_.type.startsWith("image/"));w&&(c?La(c,w):ep(w,u))},Kc=()=>{ot=null,d=null,!k&&(s===null&&ce===null&&Ee===null||(s=null,ce=null,Ee=null,de()))};function Gc(){let a=he().length===1?he()[0]:void 0,u=a===void 0?void 0:F(n.root,a);return a!==void 0&&u&&!fe(u)?Mn(a):0}function py(a){if(m){et(qe("grab"));return}if(ae){xt(null),et(qe("arrow"));return}if(o!=="select"){xt(null),Oa(null),ws(null),et(qe(o==="text"?"text":"crosshair"));return}let u=he().length===1?he()[0]:null;if(u!==null){let w=D.hitAdjuster(a);if(w){let _=F(n.root,u),M=_?Bi(_,w.id):void 0;xt(null),Oa(M?{id:w.id,prop:M.prop}:null),et(qe("radius",{badge:M?ba(u,[M.prop]):"none"}));return}Oa(null)}if(he().length>0){let w=D.hitHandle(a);if(w){xt(null);let N=_i(w.handle);et(qe("resize",{angle:zl(w.handle)+Gc(),badge:ic(Wr(),N)}));return}let _=D.hitPageLabel(a);if(_!==null){xt(_),et(qe("arrow"));return}let M=D.hitRotate(a);if(M!==null){xt(null),et(qe("rotate",{angle:Bk[M]+Gc()}));return}}let c=D.hitPageLabel(a);if(c!==null){d=null,xt(c),et(qe("arrow"));return}if(he().length>1){if(D.hitRing(a)!==null){xt(null),ws(null),et(qe("grab"));return}let _=D.hitSpacer(a),M=_===null?null:na(_);if(_!==null&&M){xt(null),ws(_),et(qe("resize",{angle:M.axis==="x"?0:90,badge:ic(Wr(),[M.axis])}));return}ws(null)}let h=b.screenToDocument(a),x=Gr(h);d=my(h,x),xt(x),de(),et(qe("arrow",{badge:x===null?"none":ba(x,["x","y"])}))}function my(a,u){let c=b.hitTest(a);if(c===null||!lt().locked.has(c))return null;let h=so(n.root,c,"locked");return h===void 0?null:u===null||Re(n.root,h).includes(u)?h:null}function xt(a){s!==a&&(s=a,de())}function Oa(a){ce?.id!==a?.id&&(ce=a,de())}function ws(a){Ee!==a&&(Ee=a,de())}function et(a){e.style.cursor!==a&&(e.style.cursor=a)}function un(a){o!==a&&(o=a,ie&&a!=="pen"&&ys(),a!=="select"&&Qr(),T?.setTool(o),a!=="select"&&xt(null),et(qe(ka())),xe("tool",o))}function hy(a){if(a.length===0)return null;if(a.length>1)return bt(a.map(h=>h.frame))??null;let u=a[0],c=Fe(n.root,u.id);return c?Yn(c.id,n,b.getResolution())??null:null}function qc(a,u,c){let h=Dr(n,Ma(cs(r),a,u));h.length!==0&&ue([...h,...Pr(n,h,qn(n),Ne(n))],c)}function Wc(a){let u=Xo(n,r,b.getResolution()),c=hy(u);c&&qc(Fi(a),lu(u,c,a),jk[a])}function Xc(a){let u=Xo(n,r,b.getResolution());if(u.length<3)return null;let c=Of(u,a),h=Tf(c);return h===null?null:{gap:h,series:c}}function Yc(a){let u=Xc(a);u&&qc(a,oa(u.series,u.gap),a==="x"?"Distribute horizontally":"Distribute vertically")}function xy(){let a=rs(n,r);if(a.length===0)return null;let u=b.getResolution(),c={};for(let h of a)oe(h,x=>{let w=u.nodes.get(x.id)?.values;w&&(c[x.id]=w)});return{nodes:a,tokens:n.tokens,fonts:n.fonts,resolved:c}}function gy(a){return new Map(Object.entries(a.resolved))}function yy(a){let u=Object.entries(a.tokens).filter(([c])=>n.tokens[c]===void 0).map(([c,h])=>({op:"setToken",name:c,value:h}));for(let[c,h]of Object.entries(a.fonts))n.fonts[c]===void 0&&u.push({op:"setFont",name:c,family:h});return u}function Jc(a,u,c){let h=yy(a),x=h.length>0?_e(n,h).document:n,w=_h(x,a.components??[],J=>sp(`This file already has a component called ${J}, and it is not the same as the one you copied. Use the one in this file? Cancel brings yours in beside it as a separate component.`));w.ops.length>0&&(h.push(...w.ops),x=_e(x,w.ops).document);let _=ff(a,x),M=_.remap,N=_.nodes.map(J=>Oi(J,w));if(N.length===0)return null;N.forEach((J,be)=>{let Q=a.nodes[be];if(!Q)return;let we=u(Q,be,x),Ie={op:"insert",parent:we.parent,index:we.index,node:J};h.push(Ie),x=_e(x,[Ie]).document});let H=Yl(x,M,gy(a),c);H.length>0&&(x=_e(x,H).document);let X=vy(N);return{ops:[...h,...H,...Nr(n,x)],ids:[...M.values()].filter(J=>X.has(J))}}function vy(a){let u=new Set;for(let c of a)u.add(c.id);return u}function Zc(a){let u=xy();return u?Jc(u,(c,h,x)=>{let w=Fe(x.root,c.id)??x.root,_=ne(w).findIndex(M=>M.id===c.id);return{parent:w.id,index:_===-1?ne(w).length:_+1}},a):null}function or(){let a=lf(n,r,b.getResolution());return a!==null&&(Wf=a),a}function Qc(){if(r.some(u=>Ve(n,u)))return or();let a=or();return a!==null&&ar(),a}function by(a){let u=[];for(let c of a.nodes){let h=a.resolved[c.id];if(!h)continue;let{x,y:w,w:_,h:M}=h;x===void 0||w===void 0||_===void 0||M===void 0||u.push({x,y:w,w:_,h:M})}return bt(u)??null}function Ta(a,u){let c=uf(a??Wf??"");if(!c)return;let h=u??ot,x=by(c),w=wy(c),_=N=>Jc(c,(H,X,J)=>({parent:N,index:ne(F(J.root,N)??J.root).length}),ky(c,N,x,h)),M=_(w);M&&w!==ks()&&_y(M.ops)&&(M=_(ks())),M&&(ue(M.ops,M.ids.length===1?"Paste":`Paste ${M.ids.length} elements`),le(M.ids))}function ks(){return dr(g??n.root.id)}function wy(a){if(a.nodes.some(x=>x.type==="frame"&&x.component===!0))return n.root.id;if(g!==null||r.length===0)return ks();let u=new Set(a.nodes.map(x=>x.id)),c=r.length===1?F(n.root,r[0]):void 0;if(c?.type==="frame"&&!u.has(c.id))return dr(c.id);let h=new Set(r.map(x=>Fe(n.root,x)?.id??n.root.id));return h.size!==1?ks():dr([...h][0])}function ky(a,u,c,h){let x={x:ca,y:ca};if(!c)return x;let w={x:c.x+c.w/2,y:c.y+c.h/2},_=u===n.root.id?void 0:dt(u);return _?h!==null&&h.x>=_.absX&&h.x<=_.absX+_.w&&h.y>=_.absY&&h.y<=_.absY+_.h?{x:h.x-_.absX-w.x,y:h.y-_.absY-w.y}:a.nodes.some(X=>Fe(n.root,X.id)?.id===u)?x:c.x>=0&&c.y>=0&&c.x+c.w<=_.w&&c.y+c.h<=_.h?{x:0,y:0}:{x:_.w/2-w.x,y:_.h/2-w.y}:h?{x:h.x-w.x,y:h.y-w.y}:x}function _y(a){let u=c=>ao(c).filter(h=>h.code==="component-cycle").length;return u(_e(n,a).document.root)>u(n.root)}async function ep(a,u){let c=t.importImage;if(!c)return;let h=await Ni(a,t.maxImageEdge??2560);if(!h)return;let x=await c(new File([h.bytes],a.name,{type:h.type}));if(!x)return;let w=dr((u?nr(u):void 0)??g??n.root.id),_=F(n.root,w)??n.root,M=an(w),N=b.getResolution().nodes.get(w),{w:H,h:X}=Rh(h.width,h.height,N?.w&&N.w>0?N.w:h.width,N?.h&&N.h>0?N.h:h.height),J=u??ot,be=Math.round((J?J.x-H/2:M.x)-M.x),Q=Math.round((J?J.y-X/2:M.y)-M.y),we=My(n,a.name),Ie=gn(n.root,"image");ue([{op:"setAsset",name:we,value:x},{op:"insert",parent:w,index:ne(_).length,node:id({id:Ie,x:be,y:Q,w:H,h:X,src:we,fit:"cover"})}],"Place image"),le([Ie])}async function tp(a,u){let c=t.importAudio;if(!c)return!1;let h=await c(a);return h?(ue(Vh(n,u,Uh(n,u,a.name),h),"Add music"),!0):!1}function _s(){return t.importImage?Sx(n,lt().hidden):[]}function Sy(){return _s().flatMap(a=>{let u=He(a.id);return u?[{frame:u,label:a.label,target:a.id===f}]:[]})}function np(a){return _s().filter(c=>{let h=He(c.id);return h!==void 0&&Et(h,a.x,a.y)}).at(-1)??null}function Ey(){return r.length!==1?null:_s().find(a=>a.id===r[0])??null}async function La(a,u){let c=t.importImage;if(!c)return;let h=await Ni(u,t.maxImageEdge??2560);if(!h)return;let x=await c(new File([h.bytes],u.name,{type:h.type}));!x||n.assets[a.src]!==void 0||(ue([{op:"setAsset",name:a.src,value:x}],"Add image"),le([a.id]))}function Cy(a){let u=e.ownerDocument.createElement("input");u.type="file",u.accept="image/*",u.addEventListener("change",()=>{let c=u.files?.[0];c&&La(a,c)}),u.click()}function My(a,u){let c=u.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"image";if(a.assets[c]===void 0)return c;for(let h=2;;h+=1){let x=`${c}-${h}`;if(a.assets[x]===void 0)return x}}function Da(){if(r.some(u=>Ve(n,u)))return;let a=Zc(Ay());a&&(ue(a.ops,a.ids.length===1?"Duplicate":`Duplicate ${a.ids.length} elements`),le(a.ids))}function Ay(){let a={x:ca,y:ca},u=r.length===1?r[0]:void 0;if(u===void 0||!tn(n,u))return a;let c=b.getResolution(),h=c.nodes.get(u);if(!h)return a;let x=Jo(n,c);return{x:x.x-h.absX,y:x.y-h.absY}}function Pa(a,u){if(a.length===0)return;let c=_e(n,a).document;ue([...a,...Nr(n,c)],u)}function Na(){if(r.some(u=>Ve(n,u)))return;let a=Gl(n,r);a&&(Pa(a.ops,"Group"),le([a.groupId]))}function Ia(){let a=r.filter(x=>{let w=F(n.root,x);return w!==void 0&&$e(w)&&!Ve(n,x)});if(a.length===0)return;let u=n,c=[],h=[];for(let x of a){let w=F(u.root,x);w&&h.push(...ne(w).map(M=>M.id));let _=ql(u,x);_.length!==0&&(c.push(..._),u=_e(u,_).document)}g!==null&&a.includes(g)&&(g=null),Pa(c,a.length===1?"Ungroup":`Ungroup ${a.length} groups`),le(h)}function Ra(a){r.some(u=>Ve(n,u))||Pa(Wl(n,r,a),qk[a])}function $y(a,u,c){let h=F(n.root,u);if(!h||!fe(h))return;let x=new Set(Re(n.root,u));if(h.type==="instance"||Ve(n,u)||u!==n.root.id&&a.some(Q=>tn(n,Q)))return;let w=a.filter(Q=>Q!==n.root.id&&F(n.root,Q)&&!x.has(Q)&&!Ve(n,Q));if(w.length===0)return;let _=new Set(w),M=ne(h).filter(Q=>!_.has(Q.id))[c]?.id,N=[],H=n;for(let Q of w){let we=ne(F(H.root,u)??H.root).filter(wt=>wt.id!==Q),Ie=M===void 0?-1:we.findIndex(wt=>wt.id===M),Xe={op:"move",id:Q,parent:u,index:Ie===-1?we.length:Ie};N.push(Xe),H=_e(H,[Xe]).document}if(w.every(Q=>Ty(n,H,Q)))return;let X=new Set(w.filter(Q=>Fe(n.root,Q)?.id!==u).flatMap(Q=>vc(Q,H))),J=[];for(let Q of w){let we=rp(n,Q),Ie=rp(H,Q),Xe={x:we.x-Ie.x,y:we.y-Ie.y};if(!(Xe.x===0&&Xe.y===0))for(let wt of Xn(Q,H)){let lr=sn(wt);lr&&(J.push({op:"set",id:wt,prop:"x",value:te(lr.x+Xe.x)}),J.push({op:"set",id:wt,prop:"y",value:te(lr.y+Xe.y)}))}}let be=_e(H,J).document;ue([...N,...J,...Nr(n,be,X)],w.length===1?`Move ${w[0]}`:`Move ${w.length} layers`)}function Oy(a={}){let u=n.root.children,c=u.filter(Ie=>Ie.type==="frame"&&Ie.component!==!0),h=c.find(Ie=>Ie.id===a.after),x=b.getResolution(),w=h?x.nodes.get(h.id):void 0,_=w&&w.w>0?w.w:Ux.w,M=w&&w.h>0?w.h:Ux.h,N=null,H=-1/0;for(let Ie of c.length>0?c:u){let Xe=x.nodes.get(Ie.id);!Xe||Xe.absX+Xe.w<=H||(H=Xe.absX+Xe.w,N={x:H+Ik,y:Xe.absY})}let X=N??{x:0,y:0},J=h??c[c.length-1],be=J?u.indexOf(J)+1:u.length,Q=gn(n.root,"frame"),we=h?.type==="frame"?h.background:void 0;return ue([{op:"insert",parent:n.root.id,index:be,node:Ns({id:Q,x:te(X.x),y:te(X.y),w:te(_),h:te(M),background:we??Hx,children:[]})}],"Add frame"),le([Q]),Q}function Ty(a,u,c){let h=Fe(a.root,c),x=Fe(u.root,c);return h?.id===x?.id&&h?.children.findIndex(w=>w.id===c)===x?.children.findIndex(w=>w.id===c)}function rp(a,u){let c=Re(a.root,u).slice(0,-1).reverse(),h=Ne(a);for(let x of c){let w=F(a.root,x);if(!w||$e(w))continue;let _=h.nodes.get(x);return _?{x:_.absX,y:_.absY}:{x:0,y:0}}return{x:0,y:0}}function Fa(a){let u=F(n.root,a);!u||!no(u)||(g=a,de())}function Ba(){if(g===null)return;let a=g;g=Oc(a),le([a])}function Ha(){let a=F(n.root,g??n.root.id)??n.root;le(ne(a).map(u=>u.id).filter(Ht))}let Ly={locked:["Lock","Unlock"],hidden:["Hide","Show"]};function op(a){return a==="locked"?lt().locked:lt().hidden}function sr(a,u,c){let h=a.filter(_=>_!==n.root.id&&F(n.root,_)),x=c?h.filter(_=>!op(u).has(_)):[...new Set(h.flatMap(_=>{let M=so(n.root,_,u);return M===void 0?[]:[M]}))];if(x.length===0)return;let w=Ly[u][c?0:1];ue(x.map(_=>({op:"set",id:_,prop:u,value:c?!0:void 0})),x.length===1?`${w} ${x[0]}`:`${w} ${x.length} layers`)}function ir(a,u){a.length!==0&&sr(a,u,!a.every(c=>op(u).has(c)))}function Ua(a){let u=[];return oe(n.root,c=>{c[a]===!0&&u.push(c.id)}),u}function Ss(a){let u=Ua(a);if(u.length===0)return;let c=a==="locked"?"Unlock all":"Show all";ue(u.map(h=>({op:"set",id:h,prop:a,value:void 0})),c)}function Dy(a){L={...qx,...a},G?.close()}function ar(){let a=r.filter(M=>M!==n.root.id),u=a.filter(M=>Ve(n,M)),c=a.filter(M=>!Ve(n,M)),h=c.filter(M=>tn(n,M)),x=Ai(n,h);if(x>0){let N=`${h.length===1?h[0]:`${h.length} components`} is used in ${x} ${x===1?"place":"places"}. Delete it and detach ${x===1?"that instance":"those instances"}? Each keeps what it shows.`;if(!sp(N))return}let w=[...u.map(M=>({op:"set",id:M,prop:"hidden",value:!0})),...h.length>0?nu(n,h,b.getResolution()):[],...c.filter(M=>!h.includes(M)).map(M=>({op:"remove",id:M}))];if(w.length===0)return;let _=a.length;le([]),ue(w,_===1?"Delete element":`Delete ${_} elements`)}function sp(a){if(t.confirm)return t.confirm(a);let u=e.ownerDocument.defaultView;return typeof u?.confirm=="function"?u.confirm(a):!0}function no(a){return $e(a)||a.type==="instance"}function dr(a){let u=Re(n.root,a),c=u.findIndex(h=>F(n.root,h)?.type==="instance");return c<=0?a:u[c-1]}function Va(a=r){let u=Jl(n,a,b.getResolution());return u?(g=null,ue(u.ops,"Create component"),le([u.instanceId]),u.flattened.length>0&&xe("notice",{message:`Made ${u.componentId}. ${u.flattened.length===1?"One position":`${u.flattened.length} positions`} measured from the page became numbers so the page looks the same: ${u.flattened.join(", ")}.`}),u.instanceId):null}function za(a=r){let u=a.filter(w=>F(n.root,w)?.type==="instance"),c=[],h=n,x=b.getResolution();for(let w of u){let _=Mi(h,w,x);_&&(c.push(..._),h=_e(h,_).document)}c.length!==0&&(g!==null&&u.includes(g)&&(g=null),ue(c,u.length===1?"Detach instance":`Detach ${u.length} instances`),le(u.filter(w=>F(n.root,w)!==void 0)))}function ip(a){return F(n.root,a)?.type==="instance"&&!Ve(n,a)?a:At(n.root,a)?.instance.id}function ap(a,u){let c=ip(a);if(c===void 0)return;let h=u??(c===a?void 0:a);ue(Zl(n,c,h),h===void 0?"Reset overrides":"Reset part")}function Py(a,u){ue(Ql(n,a,u),`Swap to ${u}`)}function dp(a){let u=F(n.root,a),c=u?.type==="instance"?u:Za(n.root,a);if(c?.type!=="instance")return;let h=F(n.root,c.component);h&&(g=null,le([h.id]),Oe([h.id]))}function ja(a,u){let c=F(n.root,a);if(c?.type!=="frame"||c.component!==!0)return null;let h=u??Ny(),x=nr(h)??n.root.id,w=an(x),_=dt(a),M=tu(n,a,x,{x:Math.round(h.x-w.x-(_?.w??0)/2),y:Math.round(h.y-w.y-(_?.h??0)/2)});return M?(ue(M.ops,`Place ${a}`),le([M.id]),M.id):null}function Ny(){let a=e.getBoundingClientRect();return b.screenToDocument({x:a.width/2,y:a.height/2})}function ro(){Qe=null;let a=I.undo();a&&dc(a.ops,`Undo ${a.entry.label}`),lp()}function oo(){Qe=null;let a=I.redo();a&&dc(a.ops,`Redo ${a.entry.label}`),lp()}function lp(){if(!ee)return;let{anchor:a,head:u}=ee.getSelection();ee.setSelection(a,u)}function Iy(a){if(!I.isTail(a))return!1;for(let u=a.length;u>0;u-=1)ro();return!0}function up(a,u,c,h){let x=F(n.root,a);if(!x)return;let w=x[u];Yk(w,c)||ue([{op:"set",id:a,prop:u,value:c}],h??`Set ${u}`)}function Ry(a,u){let c=n.brand?.theme==="dark"?n.themes?.dark:void 0;if(c!==void 0&&a in c){if(c[a]===u)return;ue([{op:"setTheme",value:{...n.themes,dark:{...c,[a]:u}}}],`Set $${a} in dark`);return}n.tokens[a]!==u&&ue([{op:"setToken",name:a,value:u}],`Set $${a}`)}function Fy(a){a in n.tokens&&ue([{op:"setToken",name:a,value:void 0}],`Remove $${a}`)}function fp(a,u){let c=dt(a)?.values[u];c!==void 0&&ue([{op:"set",id:a,prop:u,value:te(c)}],`Detach ${u}`)}function By(a){let u=F(n.root,g??n.root.id)??n.root,c=[];for(let h of ne(u)){if(!Ht(h.id))continue;let x=He(h.id);x&&jl(x,a)&&c.push(h.id)}return c}function gt(a){typeof e.setPointerCapture=="function"&&e.setPointerCapture(a)}function Ka(a){e.hasPointerCapture?.(a)&&e.releasePointerCapture(a)}let cp=a=>{ee&&(cc(),ee.handleKey(a)&&(a.preventDefault(),a.stopPropagation()))},pp=a=>{ee&&(a.preventDefault(),cc(),ee.handleInput(a))},mp=()=>ee?.handleCompositionStart(),hp=a=>ee?.handleCompositionUpdate(a.data??""),xp=a=>ee?.handleCompositionEnd(a.data??""),gp=a=>{if(!e.ownerDocument.hasFocus())return;let u=a.relatedTarget;u instanceof Element&&u.closest("[data-vd-keeps-text]")||An("blur")};return W.addEventListener("keydown",cp),W.addEventListener("beforeinput",pp),W.addEventListener("compositionstart",mp),W.addEventListener("compositionupdate",hp),W.addEventListener("compositionend",xp),W.addEventListener("blur",gp),e.addEventListener("pointerdown",_c),e.addEventListener("pointermove",Ec),e.addEventListener("pointerup",vs),e.addEventListener("pointercancel",vs),e.addEventListener("pointerup",fs),e.addEventListener("pointercancel",fs),e.addEventListener("pointerleave",Kc),e.addEventListener("dblclick",Fc),e.addEventListener("contextmenu",Rc),e.addEventListener("keydown",Tc),e.addEventListener("keyup",Ic),e.addEventListener("copy",Dc),e.addEventListener("cut",Pc),e.addEventListener("paste",Nc),e.addEventListener("dragover",Vc),e.addEventListener("dragleave",zc),e.addEventListener("drop",jc),S=!0,T?.setTool(o),T?.setHistory(!1,!1),T?.setZoom(b.getCamera().zoom),et(qe(ka())),t.autoFit&&!t.camera&&De(()=>b.fitToContent()),t.history&&(I.restore(t.history),T?.setHistory(I.canUndo,I.canRedo)),t.selection&&t.selection.length>0&&le(t.selection),de(),{element:e,viewer:b,getDocument:()=>n,update(a){n=a,b.update(n),le(r),de(),xe("problems",wa())},applyOps:(a,u)=>ue(a,u??"Apply changes"),setDocument:(a,u)=>ue(Od(n,Hl(a,n.root.id)),u??"Replace document"),getSelection:()=>r,setSelection:le,selectAll:Ha,deleteSelection:ar,lock:a=>sr(a??r,"locked",!0),unlock:a=>sr(a??r,"locked",!1),toggleLock:a=>ir(a??r,"locked"),unlockAll:()=>Ss("locked"),hide:a=>sr(a??r,"hidden",!0),show:a=>sr(a??r,"hidden",!1),toggleHidden:a=>ir(a??r,"hidden"),showAll:()=>Ss("hidden"),isLocked:a=>lt().locked.has(a),isHidden:a=>lt().hidden.has(a),setFeatures:Dy,getFeatures:()=>L,moveLayers:$y,addFrame:Oy,copy:or,cut:Qc,paste:Ta,duplicate:Da,group:Na,ungroup:Ia,reorder:Ra,scaleSelection:Dg,getSpacing:Rg,setSpacing:Ig,align:Wc,distribute:Yc,canDistribute:a=>Xc(a)!==null,editText:Yr,endTextEditing:()=>An("done"),getEditingText:()=>ee?.id??null,formatText:a=>ee?.format(a),getTextFormat:()=>ee?.activeMark()??{},getTextSelectionRects:uc,getTextRange:()=>{if(!ee)return null;let{anchor:a,head:u}=ee.getSelection();return{from:Math.min(a,u),to:Math.max(a,u)}},createComponent:Va,detachInstance:za,resetOverrides:ap,swapComponent:Py,goToComponent:dp,placeInstance:ja,getEnteredGroup:()=>g,enterGroup:Fa,exitGroup:Ba,getTool:()=>o,editPoints:On,stopEditingPoints:Qr,getPointEditing:()=>ae?.id??null,convertToVector:a=>$a(a),setTool:un,beginEdit:vg,endEdit:ac,undo:ro,redo:oo,canUndo:()=>I.canUndo,canRedo:()=>I.canRedo,getHistory:()=>I.snapshot(),setProperty:up,fontFamilies:()=>{let a=new Map;for(let u of t.fonts?.faces()??[]){let c=a.get(u.family)??{weights:new Set,italic:!1};c.weights.add(u.weight),u.style==="italic"?c.italic=!0:(c.css===void 0||u.weight===400)&&(c.css=u.id),a.set(u.family,c)}return[...a.entries()].sort(([u],[c])=>u.localeCompare(c)).map(([u,c])=>({family:u,weights:[...c.weights].sort((h,x)=>h-x),italic:c.italic,...c.css===void 0?{}:{css:c.css}}))},assetUrl:a=>{let u=n.assets[a];return u?t.resolveAsset?.(u,a):void 0},addMusic:tp,canAddMusic:()=>t.importAudio!==void 0,setToken:Ry,removeToken:Fy,bindingsOf:yg,unbind:fp,getResolution:()=>b.getResolution(),getCamera:()=>b.getCamera(),getProblems:wa,on:ge,reveal:Oe,panBy:hg,setPresence(a,u){l={ids:[...a],label:u??null},de()},setHighlight(a){a.length===0&&p.length===0||(p=[...a],de())},isHistoryTail:a=>I.isTail(a),undoTail:Iy,historyTop:()=>I.top,destroy(){me(),e.removeEventListener("pointerup",fs),e.removeEventListener("pointercancel",fs),e.removeEventListener("pointerdown",_c),e.removeEventListener("pointermove",Ec),e.removeEventListener("pointerup",vs),e.removeEventListener("pointercancel",vs),e.removeEventListener("pointerleave",Kc),W.removeEventListener("keydown",cp),W.removeEventListener("beforeinput",pp),W.removeEventListener("compositionstart",mp),W.removeEventListener("compositionupdate",hp),W.removeEventListener("compositionend",xp),W.removeEventListener("blur",gp),W.remove(),rr&&clearTimeout(rr),e.removeEventListener("dblclick",Fc),e.removeEventListener("contextmenu",Rc),e.removeEventListener("copy",Dc),e.removeEventListener("cut",Pc),e.removeEventListener("paste",Nc),e.removeEventListener("dragover",Vc),e.removeEventListener("dragleave",zc),e.removeEventListener("drop",jc),e.removeEventListener("keydown",Tc),e.removeEventListener("keyup",Ic),G?.destroy(),T?.destroy(),D.destroy(),b.destroy(),V.remove(),$.clear(),e.style.cursor="",e.classList.remove("vd-editor")}}}function Yk(e,t){return e===t?!0:ye(e)&&ye(t)?e.expr===t.expr:!1}function ds(e){return e.metaKey||e.ctrlKey||e.altKey}function pa(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 IO=new Set(Sn);function Qf(e){return e.map(t=>({value:t,label:`${t.charAt(0).toUpperCase()}${t.slice(1)}`}))}var e1=[{value:"nonzero",label:"Non-zero"},{value:"evenodd",label:"Even-odd"}].filter(e=>Ln.includes(e.value)),t1=Qf(Dn),n1=Qf(pn),r1=Qf(Pn),o1=[{value:"left",label:"Left",icon:rt("text-left")},{value:"center",label:"Centre",icon:rt("text-center")},{value:"right",label:"Right",icon:rt("text-right")},{value:"justify",label:"Justify",icon:rt("text-justify")}].filter(e=>fn.includes(e.value)),s1=[{value:"top",label:"Top",icon:rt("text-top")},{value:"middle",label:"Middle",icon:rt("text-middle")},{value:"bottom",label:"Bottom",icon:rt("text-bottom")}].filter(e=>cn.includes(e.value)),Jf={prop:"x",label:"X",kind:"number",prefix:"X"},Zf={prop:"y",label:"Y",kind:"number",prefix:"Y"},xa={prop:"w",label:"W",kind:"number",prefix:"W"},ga={prop:"h",label:"H",kind:"number",prefix:"H"},i1={prop:"rotation",label:"Rotation",kind:"number",icon:"rotate",fallback:"0"},a1={prop:"opacity",label:"Opacity",kind:"number",icon:"opacity",percent:!0,fallback:"100%"},Xx={prop:"radius",label:"Radius",kind:"number",icon:"radius",span:"wide",fallback:"0"},ls={heading:"Position",props:[Jf,Zf,xa,ga,i1,a1]},ha={prop:"fill",label:"Fill",kind:"colour"},Jx={prop:"stroke",label:"Stroke",kind:"colour",span:"half"},Zx={prop:"strokeWidth",label:"Stroke width",kind:"number",prefix:"Width",fallback:"1"},Qx={present:"stroke",empty:"No stroke",add:{stroke:"#000000",strokeWidth:1},clear:["stroke","strokeWidth","cap","join"]},Yx={heading:"Stroke",props:[Jx,Zx],optional:Qx},RO={instance:[{heading:"Instance",props:[Jf,Zf,xa,ga]}],frame:[{heading:"Frame",props:[Jf,Zf,xa,ga,{prop:"clip",label:"Clip content",kind:"toggle"}]},{heading:"Fill",props:[{prop:"background",label:"Fill",kind:"colour"}]}],canvas:[{heading:"Canvas",props:[xa,ga,{prop:"background",label:"Fill",kind:"colour"}]}],text:[ls,{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:o1,span:"half"},{prop:"valign",label:"Vertical",kind:"segmented",options:s1,span:"half"}]},{heading:"Fill",props:[ha]},{heading:"Link",props:[{prop:"content",label:"Link",kind:"link",icon:"link"}]}],rect:[{heading:"Position",props:[...ls.props,Xx]},{heading:"Fill",props:[ha]},Yx],ellipse:[ls,{heading:"Fill",props:[ha]},Yx],image:[{heading:"Position",props:[...ls.props,Xx]},{heading:"Image",props:[{prop:"fit",label:"Fit",kind:"select",options:n1,prefix:"Fit"}]}],vector:[ls,{heading:"Fill",props:[{...ha,span:"half"},{prop:"rule",label:"Fill rule",kind:"select",options:e1,prefix:"Rule",span:"half"}]},{heading:"Stroke",props:[Jx,Zx,{prop:"cap",label:"Cap",kind:"select",options:t1,prefix:"Cap",span:"half"},{prop:"join",label:"Join",kind:"select",options:r1,prefix:"Join",span:"half"}],optional:Qx}]};var FO=Tn.map(e=>({value:e,label:e.split("-").map((t,n)=>n===0?t.charAt(0).toUpperCase()+t.slice(1):t).join(" ")}));function eg(e){let t=e,n=new Map,r=typeof URL.createObjectURL=="function"&&typeof URL.revokeObjectURL=="function";return{resolve(o){let s=n.get(o.hash);if(s!==void 0)return s;let i=t.get(o.hash);if(i===void 0)return;if(!r)return jd(o.type,i);let d;try{d=Gd(i)}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[s,i]of n)o.has(s)||(URL.revokeObjectURL(i),n.delete(s))},destroy(){for(let o of n.values())URL.revokeObjectURL(o);n.clear(),t=new Map}}}var ec="0.5.5",tg="https://cdn.jsdelivr.net/npm/@getv.design/embed@0.5.5/fonts/";var g1=Symbol.for(`vdesign.embed.documents@${ec}`),ng=globalThis[g1]??=new WeakMap,y1=/^Line (\d+): /;function nc(e){let t=y1.exec(e.message);return{...t?{line:Number(t[1])}:{},code:e.code,message:e.message,severity:e.severity}}function tc(e){if(typeof e!="string")return va(Lo("").document,new Map,[{code:"not-text",message:`parse() takes .vd text, not ${e===null?"null":typeof e}.`,severity:"error"}]);let t=v1(e);if(t.vd===void 0)return va(Lo("").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}=Ud(t.vd),o=Lo(n),s=o.problems.map(nc).map(i=>i.line===void 0?i:{...i,line:i.line+t.offset});return va(o.document,r,s)}function v1(e){if(!Qd(e))return{vd:e,offset:0};let t=Zd(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(`
2891
- `).length-1;return{vd:t,offset:l+(e[d]===`
3094
+ `;function uo(e){if(e.getElementById(Mv))return;let t=e.createElement("style");t.id=Mv,t.textContent=Cv,e.head.appendChild(t)}var wr=["font","size","weight","italic","underline","strike","fill","letterSpacing","link"];function kn(e){return typeof e=="string"?e===""?[]:[{text:e}]:e.flatMap(t=>typeof t=="string"?t===""?[]:[{text:t}]:t.text===""?[]:[t])}function lo(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function fo(e){return lo(e).length}function co(e){let t={};for(let n of wr){let r=e[n];r!==void 0&&(t[n]=r)}return t}function Ov(e,t){return wr.every(n=>e[n]===t[n])}function A2(e,t){let n={text:e};for(let r of wr){let o=t[r];o!==void 0&&(n[r]=o)}return n}function Wi(e){let t=kn(e),n=[];for(let o of t){let s=n[n.length-1];if(s&&Ov(co(s),co(o))){n[n.length-1]={...s,text:s.text+o.text};continue}n.push(o)}if(n.length===0)return"";let r=n[0];return n.length===1&&Av(r)?r.text:n.map(o=>Av(o)?o.text:o)}function Av(e){return wr.every(t=>e[t]===void 0)}function km(e,t,n){let[r,o]=Su(t,n,fo(e)),s=[],i=0;for(let a of kn(e)){let d=i+a.text.length,c=Math.max(r,i),l=Math.min(o,d);l>c&&s.push({...a,text:a.text.slice(c-i,l-i)}),i=d}return Wi(s)}function ws(e,t,n,r,o){let s=fo(e),[i,a]=Su(t,n,s),d=o??po(e,i),c=[],l=0,p=!1,m=()=>{p||r===""||(c.push(A2(r,d)),p=!0)};for(let g of kn(e)){let b=l+g.text.length,w=Math.min(i,b);w>l&&c.push({...g,text:g.text.slice(0,w-l)}),i>=l&&i<=b&&m();let k=Math.max(a,l);b>k&&c.push({...g,text:g.text.slice(k-l)}),l=b}return m(),Wi(c)}function po(e,t){let n=kn(e);if(n.length===0)return{};let r=0,o=n[0];for(let s of n){let i=r+s.text.length;if(t>r&&t<=i)return co(s);if(t<=r)return co(o);o=s,r=i}return co(o)}function ku(e,t,n,r){let[o,s]=Su(t,n,fo(e));if(o===s)return Wi(e);let i=Object.keys(r),a=[],d=0;for(let c of kn(e)){let l=d+c.text.length;for(let[p,m,g]of $2(d,l,o,s)){if(m<=p)continue;let b=c.text.slice(p-d,m-d);if(!g){a.push({...c,text:b});continue}let w={...c,text:b};for(let k of i)r[k]===void 0?delete w[k]:w[k]=r[k];a.push(w)}d=l}return Wi(a)}function $2(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 Sm(e,t,n){let[r,o]=Su(t,n,fo(e));if(r===o)return po(e,r);let s,i=0;for(let a of kn(e)){let d=i+a.text.length;if(Math.min(d,o)>Math.max(i,r)){let c=co(a);if(!s)s=c;else{let l={};for(let p of wr)s[p]===c[p]&&s[p]!==void 0&&(l[p]=s[p]);s=l}}i=d}return s??{}}function Su(e,t,n){let r=$v(Math.min(e,t),n),o=$v(Math.max(e,t),n);return[r,o]}function $v(e,t){return Math.max(0,Math.min(Math.round(e),t))}function ks(e,t){let n=[],r=0;return e.lines.forEach((o,s)=>{let i=o.spans.map(l=>l.text).join(""),a=i===""?s===0?r:O2(t,r):T2(t,i,r),d=a+i.length,c=s===e.lines.length-1;n.push({start:a,end:c?t.length:d}),r=d}),n.length===0&&n.push({start:0,end:t.length}),n}function O2(e,t){let n=e.indexOf(`
3095
+ `,t);return n===-1?t:n+1}function T2(e,t,n){let r=e.indexOf(t,n);return r===-1?n:r}function _u(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 Eu(e,t,n,r){let o=ks(e,t),s=_u(o,n),i=e.lines[s],a=o[s];if(!i||!a)return{x:0,y:0,h:0,line:0};let d=Math.max(0,Math.min(n-a.start,Lv(i))),c=(L2(i,d)??i.style)?.fill;return{x:_m(i,d,r),y:i.y,h:i.h,line:s,...c!==void 0?{fill:c}:{}}}function L2(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 Xi(e,t,n,r){let o=ks(e,t);if(e.lines.length===0)return 0;let s=e.lines.findIndex(d=>n.y<d.y+d.h);s===-1&&(s=e.lines.length-1);let i=e.lines[s];return o[s].start+Tv(i,n.x,r)}function Tv(e,t,n){let r=0,o=1/0,s=0,i=(a,d)=>{let c=Math.abs(d-t);c<o&&(o=c,r=a)};i(0,e.spans[0]?.x??0);for(let a of e.spans){for(let d of Cm(a.text))d!==0&&i(s+d,a.x+n.advance(a.text.slice(0,d),a.style));s+=a.text.length}return r}function _m(e,t,n){let r=0,o=e.spans[0]?.x??0;for(let s of e.spans){if(t<=r)return s.x;if(t>=r+s.text.length){o=s.x+s.w,r+=s.text.length;continue}return s.x+n.advance(s.text.slice(0,t-r),s.style)}return o}function Lv(e){return e.spans.reduce((t,n)=>t+n.text.length,0)}function Em(e,t,n,r,o){let s=Math.min(n,r),i=Math.max(n,r);if(s===i)return[];let a=ks(e,t),d=[];return e.lines.forEach((c,l)=>{let p=a[l];if(!p)return;let m=Math.max(s,p.start),g=Math.min(i,p.end);if(g<=m)return;let b=Lv(c),w=_m(c,Math.min(m-p.start,b),o),k=_m(c,Math.min(g-p.start,b),o),_=Math.max(k-w,g>p.end-1&&g>m?4:0);_>0&&d.push({x:w,y:c.y,w:_,h:c.h})}),d}function Mm(e,t,n,r,o){let s=ks(e,t),a=_u(s,n)+r,d=e.lines[a],c=s[a];if(!d||!c)return r===-1?0:t.length;let l=Eu(e,t,n,o);return Math.min(c.start+Tv(d,l.x,o),c.end)}function Cm(e){let t=[0];for(let{index:n,segment:r}of P2.segment(e))t.push(n+r.length);return t}var P2=new Intl.Segmenter(void 0,{granularity:"grapheme"});function Mu(e,t){let n=0;for(let r of Cm(e)){if(r>=t)break;n=r}return n}function Am(e,t){for(let n of Cm(e))if(n>t)return n;return e.length}function Pv(e,t){return t>=e.length?e.length:Mu(e,t+1)}var D2=/[\p{L}\p{N}_]/u;function $m(e,t){let n=Math.max(0,Math.min(t,e.length)),r=a=>D2.test(e[a]??""),o=n;if(!r(o)&&o>0&&r(o-1)&&(o-=1),!r(o))return{from:n,to:n};let s=o,i=o;for(;s>0&&r(s-1);)s-=1;for(;i<e.length&&r(i);)i+=1;return{from:s,to:i}}function Cu(e,t,n){let r=ks(e,t),o=r[_u(r,n)];return o?{from:o.start,to:o.end}:{from:0,to:t.length}}var N2=700,R2=400,I2=600,Dv=1,F2=1,Fv=700;function Om(e){let t=0,n=0,r=null,o=!1,s=0,i=!1,a=0,d=0;function c(){return lo(e.content())}function l($){let P=c();return Pv(P,Math.max(0,Math.min(Math.round($),P.length)))}function p(){return{from:Math.min(t,n),to:Math.max(t,n)}}function m($,P=$){let C=t!==$||n!==P;t=l($),n=l(P),C&&g(),r=null,e.invalidate()}function g(){o=!1,s&&(clearTimeout(s),s=0)}function b(){s&&clearTimeout(s),s=setTimeout(g,Fv)}function w($,P){e.write($,o,P),o=!0,b()}function k($,P){let{from:C,to:G}=p(),ee=r??void 0;w(ws(e.content(),C,G,$,ee),P),t=n=C+$.length,r=null,e.invalidate()}function _($,P){$!==P&&(w(ws(e.content(),$,P,""),"Delete text"),t=n=Math.min($,P),e.invalidate())}function M($,P){let{from:C,to:G}=p();if(C!==G){_(C,G);return}let ee=c();if($===-1){if(C===0)return;let oe=P?Rv(ee,C):Mu(ee,C);_(oe,C);return}if(C>=ee.length)return;let fe=P?Iv(ee,C):Am(ee,C);_(C,fe)}function R($,P){let C=c();return P?$===-1?Rv(C,n):Iv(C,n):$===-1?Mu(C,n):Am(C,n)}let B=$=>$.weight??e.base().weight,D=$=>$.italic??e.base().italic,V=$=>B($)>=I2;function T($){let{from:P,to:C}=p();if(r||P===C)return $(r??po(e.content(),P));let G=0;for(let ee of kn(e.content())){let fe=G+ee.text.length;if(Math.min(fe,C)>Math.max(G,P)&&!$(ee))return!1;G=fe}return!0}function O($,P,C,G){let ee=P({});return T(P)?{[$]:ee?G:void 0}:{[$]:ee?void 0:C}}function j($,P){let C=Se=>Math.max(F2,(Se.size??e.base().size)+$),{from:G,to:ee}=p();if(G===ee){P({size:C(r??po(e.content(),G))});return}let fe=e.content(),oe=0;for(let Se of kn(e.content())){let be=oe+Se.text.length,v=Math.max(oe,G),N=Math.min(be,ee);N>v&&(fe=ku(fe,v,N,{size:C(Se)})),oe=be}g(),w(fe,"Format text"),g(),e.invalidate()}return{id:e.id,getSelection:()=>({anchor:t,head:n}),setSelection($,P){m($,P??$)},caret(){return Eu(e.layout(),c(),n,e.measure())},highlight(){let{from:$,to:P}=p();return Em(e.layout(),c(),$,P,e.measure())},pointTo($,P){let C=Xi(e.layout(),c(),$,e.measure());m(P?t:C,C)},selectWordAt($){let P=Xi(e.layout(),c(),$,e.measure()),C=$m(c(),P);m(C.from,C.to)},selectLineAt($){let P=Xi(e.layout(),c(),$,e.measure()),C=Cu(e.layout(),c(),P);m(C.from,C.to)},selectAll(){m(0,c().length)},format($){let{from:P,to:C}=p();if(P===C){r={...po(e.content(),P),...$},e.invalidate();return}g(),w(ku(e.content(),P,C,$),"Format text"),g(),e.invalidate()},activeMark(){if(r)return r;let{from:$,to:P}=p();return Sm(e.content(),$,P)},composing:()=>i,handleKey($){if(i)return!1;let P=$.metaKey||$.ctrlKey,C=$.altKey||$.ctrlKey&&!$.metaKey;if(P&&$.shiftKey&&!$.altKey&&($.code==="Period"||$.code==="Comma"))return j($.code==="Period"?Dv:-Dv,G=>this.format(G)),!0;switch($.key){case"Escape":return e.close("escape"),!0;case"ArrowLeft":case"ArrowRight":{let G=$.key==="ArrowLeft"?-1:1,{from:ee,to:fe}=p();if(!$.shiftKey&&ee!==fe)m(G===-1?ee:fe);else{let oe=$.metaKey?Nv(e,c(),n,G):R(G,C);m($.shiftKey?t:oe,oe)}return!0}case"ArrowUp":case"ArrowDown":{let G=$.key==="ArrowUp"?-1:1,ee=P?G===-1?0:c().length:Mm(e.layout(),c(),n,G,e.measure());return m($.shiftKey?t:ee,ee),!0}case"PageUp":case"PageDown":{let G=$.key==="PageUp"?0:c().length;return m($.shiftKey?t:G,G),!0}case"Home":case"End":{let G=Nv(e,c(),n,$.key==="Home"?-1:1);return m($.shiftKey?t:G,G),!0}case"Backspace":return M(-1,C||P),!0;case"Delete":return M(1,C||P),!0;case"Enter":return P?e.close("done"):k(`
3096
+ `,"Type text"),!0;case"Tab":return!1;case"a":case"A":return P?(m(0,c().length),!0):!1;case"b":case"B":return P?(this.format(O("weight",V,N2,R2)),!0):!1;case"i":case"I":return P?(this.format(O("italic",D,!0,!1)),!0):!1;case"u":case"U":return P?(this.format({underline:this.activeMark().underline===!0?void 0:!0}),!0):!1;case"x":case"X":return!P||!$.shiftKey||$.altKey?!1:(this.format({strike:this.activeMark().strike===!0?void 0:!0}),!0);default:return!1}},handleInput($){if(!i)switch($.inputType){case"insertText":case"insertReplacementText":case"insertFromPaste":case"insertFromDrop":case"insertFromYank":k(B2($),"Type text");return;case"insertParagraph":case"insertLineBreak":k(`
3097
+ `,"Type text");return;case"deleteContentBackward":case"deleteWordBackward":M(-1,$.inputType==="deleteWordBackward");return;case"deleteContentForward":case"deleteWordForward":M(1,$.inputType==="deleteWordForward");return;case"deleteByCut":case"deleteByDrag":{let{from:P,to:C}=p();_(P,C);return}default:return}},handleCompositionStart(){i=!0;let{from:$,to:P}=p();a=$,d=P,g()},handleCompositionUpdate($){w(ws(e.content(),a,d,$),"Type text"),d=a+$.length,t=n=d,e.invalidate()},handleCompositionEnd($){w(ws(e.content(),a,d,$),"Type text"),i=!1,d=a+$.length,t=n=d,g(),e.invalidate()},breakBurst:g,destroy(){g()}}}function B2(e){return typeof e.data=="string"?e.data:e.dataTransfer?.getData("text/plain")??""}function Nv(e,t,n,r){let o=Cu(e.layout(),t,n);return r===-1?o.from:o.to}var Au=/[\p{L}\p{N}_]/u;function Rv(e,t){let n=t;for(;n>0&&!Au.test(e[n-1]??"");)n-=1;for(;n>0&&Au.test(e[n-1]??"");)n-=1;return n}function Iv(e,t){let n=t;for(;n<e.length&&!Au.test(e[n]??"");)n+=1;for(;n<e.length&&Au.test(e[n]??"");)n+=1;return n}function Tm(e){return fo(e)===0}var Bv=10;function $u(e,t){let n=t.x+t.w/2,r=t.y+t.h/2;return[{id:e,side:"left",at:{x:t.x,y:r}},{id:e,side:"right",at:{x:t.x+t.w,y:r}},{id:e,side:"top",at:{x:n,y:t.y}},{id:e,side:"bottom",at:{x:n,y:t.y+t.h}}]}function Vv(e,t,n,r){let o=a=>Math.hypot(a.at.x-e.x,a.at.y-e.y),s=a=>a.reduce((d,c)=>d===null||o(c)<o(d)?c:d,null);if(t)return s($u(t.id,t.box));let i=n.flatMap(({id:a,box:d})=>$u(a,d).filter(c=>o(c)<=r));return s(i)}function V2(e){switch(e){case"left":return["left","cy"];case"right":return["right","cy"];case"top":return["cx","top"];case"bottom":return["cx","bottom"]}}function Ou(e,t,n,r){let[o,s]=e==="start"?["x1","y1"]:["x2","y2"];if(t){let[i,a]=V2(t.side);return{[o]:_t(`@${t.id}.${i}`),[s]:_t(`@${t.id}.${a}`)}}return{[o]:Math.round((n.x-r.x)*100)/100,[s]:Math.round((n.y-r.y)*100)/100}}function Hv(e,t){let n=t.x-e.x,r=t.y-e.y,o=Math.hypot(n,r);if(o===0)return t;let s=Math.PI/4,i=Math.round(Math.atan2(r,n)/s)*s;return{x:e.x+Math.cos(i)*o,y:e.y+Math.sin(i)*o}}var Lm={v:"select",f:"frame",r:"rect",o:"ellipse",l:"line",p:"pen",t:"text"};var Pm="host:",Uv="#ffffff",zv={w:1920,h:1080},H2=100,Tu=20,U2=15,jv=1,Kv=10,Gv=2,z2=32,j2={ne:0,se:90,sw:180,nw:270,n:0,e:90,s:180,w:270},qv={w:240,h:28},K2={text:"Add text",frame:"Add page",rect:"Draw rectangle",ellipse:"Draw ellipse"};function G2(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 q2={KeyA:"left",KeyD:"right",KeyW:"top",KeyS:"bottom",KeyH:"hcenter",KeyV:"vcenter"},W2={KeyH:"x",KeyV:"y"},X2={KeyU:"union",KeyS:"subtract",KeyI:"intersect",KeyX:"exclude"},Wv={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},Y2={left:"Align left",hcenter:"Align horizontal centres",right:"Align right",top:"Align top",vcenter:"Align vertical centres",bottom:"Align bottom"},Dm=null,J2=220,Xv={lock:!0,hide:!0},Pu="application/x-vdesign-component",Z2=new Set(["x","y","w","h","rotation"]),Q2={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"},eA=["x","y","w","h"],tA={front:"Bring to front",forward:"Bring forward",backward:"Send backward",back:"Send to back"},nA=11,jn=2,rA={metaKey:!1,ctrlKey:!1},oA=10;function Rm(e,t){uo(e.ownerDocument),e.classList.add("vd-editor"),e.hasAttribute("tabindex")||(e.tabIndex=0);let n=t.document,r=[],o=t.tool??"select",s=null,i=null,a=null,d=null,c={ids:[],label:null},l=null,p=[],m=!1,g=new Set,b=null,w=!1,k=!1,_=null,M=null,R={...Xv,...t.features},B=null,D=new qi,V=0,T=null,O={dx:0,dy:0},j=null,$=new Map,P=e.ownerDocument.createElement("div");P.style.position="absolute",P.style.inset="0",e.appendChild(P),e.style.touchAction="none";let C=Rd(P,{sample:Kf,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:(u,f)=>{f===n&&ke("scene",{scene:u,document:f})},onCameraChange:u=>{ee?.setZoom(u.zoom),ce(),ke("camera",u),!(V>0)&&(Ue(),ke("navigate",u))}}),G=kv(e,u=>C.documentToScreen(u)),ee=t.chrome===!1?null:Bb(e,{onTool:Mn,onUndo:Vs,onRedo:Hs,onZoomReset:()=>C.fitToContent(),onPlay:t.onPlay,playHint:t.playHint,formatKeys:t.formatKeys}),fe=t.chrome===!1?null:fu(e,{onCommand:i1,...t.formatKeys?{formatKeys:t.formatKeys}:{}}),oe=n,Se=n,be=[],v=null,N=[],I=null,F=null,q=new Map,Y=null,Q=null,Te=null,Ct=[],_e=dt,Rt=null,ae=null,H=null,J=null,Oe=!1,se=e.ownerDocument.createElement("textarea");se.className="vd-editor__input",se.setAttribute("aria-hidden","true"),se.tabIndex=-1,se.autocapitalize="off",se.autocomplete="off",se.spellcheck=!1,e.appendChild(se);function ke(u,f){let h=$.get(u);if(h)for(let x of h)x(f)}function ye(u,f){let h=$.get(u)??new Set;return h.add(f),$.set(u,h),()=>h.delete(f)}function Ge(u){V+=1;try{u()}finally{V-=1}}function Ue(){T!==null&&(e.ownerDocument.defaultView?.cancelAnimationFrame(T),T=null)}function Os(u){let f=C.linkAt(u),h=f===void 0?void 0:Qt(f);return h?h.kind==="url"?t.onOpenLink?(t.onOpenLink(h.url),!0):!1:z(n.root,h.id)?(he([h.id]),At([h.id]),!0):!1:!1}function At(u,f={}){if(v!==null)return j={target:u,options:f},!1;let h=ek(u);if(!h)return!1;let x=e.getBoundingClientRect(),y=x.width>0&&x.height>0,S=y?{width:x.width,height:x.height-Zw(x)}:{width:h.w+96,height:h.h+96},E=f.fit==="always"?cu(h,S):om(h,S,C.getCamera());if(!E)return!1;Ue(),f.by==="person"&&ke("navigate",E);let A=e.ownerDocument.defaultView,L=A?.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;if(f.animate===!1||L||!y||!A?.requestAnimationFrame)return Ge(()=>C.setCamera(E)),!0;let U=C.getCamera(),W=A.performance.now();O={dx:0,dy:0};let X=ie=>{let re=Math.min(1,Math.max(0,(ie-W)/J2)),xe=re===1?E:av(U,E,dv(re),S);Ge(()=>C.setCamera(yn(xe,O.dx,O.dy))),T=re===1?null:A.requestAnimationFrame(X)};return T=A.requestAnimationFrame(X),!0}function Zw(u){let f=ee?.element.getBoundingClientRect();return!f||f.height===0?0:Math.max(0,u.bottom-f.top)}function Qw(u,f){T!==null&&(O={dx:O.dx+u,dy:O.dy+f}),Ge(()=>C.setCamera(yn(C.getCamera(),u,f)))}function da(){if(j===null||v!==null)return;let{target:u,options:f}=j;j=null,At(u,f)}function ek(u){if(u==="content"){let h=C.getScene();return uu([{x:h.x,y:h.y,w:h.width,h:h.height}])}let f=[];for(let h of rm(n,u)){let x=qe(h);x&&f.push(x)}return uu(f)}function wt(u){return C.getResolution().nodes.get(u)}function an(u){let f=wt(u);return f?{x:f.x,y:f.y,w:f.w,h:f.h}:void 0}function qe(u){return ro(u,n,C.getResolution())}function kt(u){let f=wt(u);return f?{x:f.absX,y:f.absY,w:f.w,h:f.h}:void 0}function Wn(u){return wt(u)?.values.rotation??0}function ox(){let u=Ls();if(u.length===0)return null;for(let f of u){let h=z(n.root,f);if(!h||!Yl.includes(h.type))return null}return u}function Xn(u,f=new Set){let h=C.getResolution(),x=null;return de(n.root,y=>{if(f.has(y.id)||!It(y.id)||y.type==="instance")return!1;if(y.type!=="frame")return;let S=h.nodes.get(y.id);if(!S)return!1;let E={x:S.absX,y:S.absY,w:S.w,h:S.h};if(!Mt(E,u.x,u.y))return!1;x=y.id}),x}function Yt(u){let f=wt(u);return f?{x:f.absX,y:f.absY}:{x:0,y:0}}function $t(){return B?.of!==n&&(B={of:n,hidden:Oa(n.root),locked:Ta(n.root)}),B}function It(u){let{hidden:f,locked:h}=$t();return!f.has(u)&&!h.has(u)}function ge(){return r.filter(It)}function yo(u){let f=C.hitTest(u,x=>!$t().locked.has(x));if(f===null)return null;let h=_===null||Ke(n.root,f).includes(_);return Bd(f,n,h?_:null)}function tk(){return Bi(n,ge(),C.getResolution())}function Ts(){return ge().length<2?null:fm(tk())}function ua(u){let f=[];for(let h of u)for(let x of no(h,n)){let y=an(x);y&&f.push({member:h,node:x,frame:y})}return f}function ca(u,f){let h=z(n.root,u);if(!h)return"literal";let x=h[f];return x===void 0?"literal":md(x).kind}function nk(u){let f=z(n.root,u),h={};if(!f)return h;let x=[...eA,...ji(f).flatMap(y=>y.props)];for(let y of x)h[y]=ca(u,y);return h}function sx(u,f){let h="none";for(let x of u){let y=ac(x,f);if(y==="expression")return"expression";y==="token"&&(h="token")}return h}function ac(u,f){let h="none";for(let x of f){let y=ca(u,x);if(y==="complex")return"expression";y==="token"&&(h="token")}return h}let ht=null;function pe(u,f){if(u.length===0)return;let h=Vo(n,Vd(n,u,an)),x=Ae(n,h);n=x.document,ht?(fc(ht.started,ht.label,h,x.inverse),ht.started=!0):D.push({label:f,ops:h,inverse:x.inverse}),la(h,f)}function rk(u){ht={label:u,started:!1}}function ix(){ht=null}function ax(u,f){u.length!==0&&(n=Ae(n,u).document,la(u,f))}function la(u,f){s=null,Q=null,Te=null,C.update(n),ee?.setHistory(D.canUndo,D.canRedo),ce(),ke("change",{document:n,ops:u,label:f}),ke("problems",dc())}function dc(){return[...C.getScene().problems,...mf(n)]}function he(u){let f=u.filter(x=>x!==n.root.id&&z(n.root,x)),h=f.length!==r.length||f.some((x,y)=>r[y]!==x);r=[...f],H&&(f.length!==1||f[0]!==H.id)&&(H=null),M!==null&&(f.length!==1||f[0]!==M)&&(M=null),h&&(fe?.close(),Te=null,ke("selection",r)),ce()}function ok(u,f){let h=z(n.root,u);if(!h)return[];let x=C.getCamera().zoom;if(Math.min(f.w,f.h)*x<Ip)return[];let y=nA/x,S=wt(u);return ji(h).flatMap(E=>E.handles(h,f,S?.values??{},y).map(A=>({id:A.id,at:A.at,bound:ca(u,A.prop)!=="literal"})))}function dx(u,f){let h=wt(u)?.values??{};return h[f]??(f==="radius"?0:h.radius??0)}function sk(){let u=[];for(let U of ge()){let W=qe(U);W&&u.push(W)}let f=Wt(u);if(!f)return null;let h=ge().length===1?ge()[0]:void 0,x=h===void 0?void 0:z(n.root,h),y=h===void 0||!x||me(x),S=new Set,E=Ls();for(let U of hp){let W=Id(U);E.some(X=>W.some(ie=>ca(X,ie)!=="literal"))&&S.add(U)}let A=!y&&h!==void 0?Wn(h):0,L=A!==0&&h!==void 0?kt(h):void 0;return{frame:L??f,...L?{rotation:A}:{},rotatable:ox()!==null,handles:ae===null&&x?.type!=="connector",boundHandles:S,adjusters:ae!==null||y||h===void 0||L?[]:ok(h,f)}}function Ls(){return[...new Set(ge().flatMap(u=>no(u,n)))]}function ik(u){return u?v?.kind==="adjust"?`r ${Z(I??v.from)}`:v?.kind==="rotate"?`${Z(F??0)}\xB0`:!v&&Q&&ge().length===1?`r ${Z(dx(ge()[0],Q.prop))}`:v?.kind==="move"?`${Z(u.frame.x)}, ${Z(u.frame.y)}`:`${Z(u.frame.w)} \xD7 ${Z(u.frame.h)}`:null}function ak(){let f=v!==null&&v.kind!=="space"&&v.kind!=="reorder"?null:Ts();if(!f)return{spacers:[],rings:[],lead:null};let h=v?.kind==="space"?v.spacer:null;return{spacers:hm(f).map(x=>({id:x.id,axis:x.axis,at:x.at,label:x.id===(h??Te)?String(Z(x.gap)):null})),rings:mm(f).map(x=>({id:x.id,at:x.at})),lead:v?.kind==="reorder"?qe(v.id)??null:null}}function dk(u){let f=[];return de(n.root,(h,x)=>{if(h.id===u||!It(h.id))return!1;if(h.type==="canvas"||h.type==="group"||h.type==="connector"||h.type==="frame"&&x?.id===n.root.id)return;let y=kt(h.id);return y&&f.push({id:h.id,box:y}),h.type==="instance"?!1:void 0}),f}function fa(u,f,h){if(h.metaKey||h.ctrlKey)return null;let x=dk(f),y=C.hitTest(u,A=>A!==f&&It(A)),S=y===null?null:uk(y,x),E=S===null?null:x.find(A=>A.id===S)??null;return Vv(u,E,x,Bv/C.getCamera().zoom)}function uk(u,f){if(f.some(x=>x.id===u))return u;let h=Ba(n.root,u);return h!==void 0&&f.some(x=>x.id===h.id)?h.id:null}function ux(u,f,h){return h.shiftKey?(_e=dt,Hv(f,u)):(_e=du(u,Ct,wo(h)),{x:u.x+_e.dx,y:u.y+_e.dy})}function ck(u,f,h,x){let y=Le(oe.root,u),S=y?Yt(y.id):{x:0,y:0};return Object.entries(Ou(f,h,x,S)).map(([E,A])=>({op:"set",id:u,prop:E,value:A}))}function lk(u,f,h){if(z(n.root,u)?.type!=="connector"||Je(n,u))return!1;let y=G.hitLineEnd(f),S=C.itemOf(u);if(y===null||S?.kind!=="connector")return!1;let E=y==="start"?{x:S.x1,y:S.y1}:{x:S.x2,y:S.y2},A=y==="start"?{x:S.x2,y:S.y2}:{x:S.x1,y:S.y1};return St(h),mt({kind:"end",pointerId:h,id:u,end:y,fixed:A,current:E,anchor:null}),ce(),!0}function fk(u,f,h,x){if(ko(u,f)<jn*2||h!==null&&x!==null&&h.id===x.id&&h.side===x.side)return;let y=Jn(Xn(u)??_??n.root.id),S=z(n.root,y)??n.root,E=Yt(y),A=pn(n.root,"line");pe([{op:"insert",parent:y,index:te(S).length,node:el({id:A,...Ou("start",h,u,E),...Ou("end",x,f,E),...t.defaultStroke===void 0?{}:{stroke:t.defaultStroke}})}],"Draw line"),he([A]),Mn("select")}function pk(){if(v?.kind==="line"){let y=v.to??null;return{from:v.origin,to:v.current,draft:!0,attached:{start:v.from!==null,end:v.to!==null},anchors:y?uc(y.id):[],chosen:y?.at??null,target:y?kt(y.id)??null:null}}if(o==="line"&&!v&&i)return{from:i.at,to:i.at,draft:!1,attached:{start:!1,end:!1},anchors:uc(i.id),chosen:i.at,target:kt(i.id)??null};let u=ge().length===1?ge()[0]:void 0;if(u===void 0||ae)return null;let f=C.itemOf(u);if(f?.kind!=="connector")return null;let h=v?.kind==="end"?v.anchor:null,x=In(n).get(u);return{from:{x:f.x1,y:f.y1},to:{x:f.x2,y:f.y2},draft:!1,attached:{start:x?.start!==void 0,end:x?.end!==void 0},anchors:h?uc(h.id):[],chosen:h?.at??null,target:h?kt(h.id)??null:null}}function hk(){let u=ge().length===1?ge()[0]:void 0;return u!==void 0&&z(n.root,u)?.type==="connector"}function uc(u){let f=kt(u);return f?$u(u,f).map(h=>h.at):[]}function ce(){if(!k)return;let u=Rk(),f=u||hk()?null:sk(),h=s!==null&&!r.includes(s)&&!v?s:null,x=h===null?void 0:C.itemOf(h),y=x?.kind==="connector"?x.contours:null,S=h!==null&&y===null?qe(h)??null:null,E={...wv,...ak(),hover:S,members:ge().length>1?ge().flatMap(A=>qe(A)??[]):[],box:f,badge:ik(f),caret:cx(),textSelection:lx(),draft:v?.kind==="create"?to(v.origin,v.current):null,draftEllipse:v?.kind==="create"&&o==="ellipse",marquee:v?.kind==="marquee"?to(v.origin,v.current):null,guides:v?_e.guides:[],measures:v?_e.measures:[],presence:c.ids.length===0?null:{frames:c.ids.flatMap(A=>qe(A)??[]),label:c.label},highlight:Gi(n,p).flatMap(A=>qe(A.id)??[]),slots:b1(),masks:Wk(),parked:r.filter(A=>!It(A)).flatMap(A=>qe(A)??[]),lockHint:yk(),path:u,turn:bk(),pageLabels:xk(),line:pk(),hoverLine:y};G.render(E)}let pa=null;function mk(u){pa?.of!==n&&(pa={of:n,counts:new Map});let f=pa.counts.get(u);return f===void 0&&(f=Ud(n,[u]),pa.counts.set(u,f)),f}function xk(){if(a)return[];let u=C.getResolution().nodes;return n.root.children.flatMap(f=>{if(f.type!=="frame")return[];let h=u.get(f.id);if(!h)return[];let x=Fi(h),y=f.name,S=typeof y=="string"&&y!==""?y:f.id,E=r.includes(f.id)?"selected":s===f.id?"hover":"idle";if(f.component!==!0)return[{id:f.id,frame:x,label:S,state:E}];let A=mk(f.id);return[{id:f.id,frame:x,label:`\u25C6 ${S} \xB7 ${A} ${A===1?"use":"uses"}`,state:E,component:!0}]})}function gk(u){let f=G.pageLabelRect(u),h=z(n.root,u);if(!f||!h)return;let x=h.name,y=e.ownerDocument.createElement("input");y.className="vd-editor__rename",y.type="text",y.spellcheck=!1,y.value=typeof x=="string"&&x!==""?x:"",y.placeholder=u,y.setAttribute("aria-label",`Name of ${u}`),y.style.left=`${f.x-4}px`,y.style.top=`${f.y-2}px`,y.style.width=`${Math.max(120,f.w+40)}px`;let S=!1,E=A=>{if(S)return;S=!0;let L=y.value.trim();y.remove(),a=null,A&&L!==(typeof x=="string"?x:"")&&pg(u,"name",L===""?void 0:L,"Rename"),ce(),e.focus({preventScroll:!0})};y.addEventListener("keydown",A=>{A.stopPropagation(),A.key==="Enter"?(A.preventDefault(),E(!0)):A.key==="Escape"&&(A.preventDefault(),E(!1))}),y.addEventListener("pointerdown",A=>A.stopPropagation()),y.addEventListener("blur",()=>E(!0)),a=y,e.appendChild(y),ce(),y.focus(),y.select()}function yk(){if(d===null||v||!$t().locked.has(d))return null;let u=qe(d);return u?{frame:u,label:d}:null}function ha(u){let f=C.itemOf(u);if(f?.kind!=="text")return null;let h=f.lines[0]?.y??f.y,x={lines:f.lines.map(y=>({y:y.y-h,h:y.h,baseline:y.baseline-h,w:y.w,spans:y.spans.map(S=>({text:S.text,style:S.style,x:S.x-f.x,w:S.w})),...y.style?{style:y.style}:{}})),width:Math.max(0,...f.lines.map(y=>y.w)),height:f.height};return{item:f,layout:x,top:h}}function cc(){return o==="text"?"text":o!=="select"?"crosshair":"arrow"}function cx(){if(!ae)return null;let u=ha(ae.id);if(!u)return null;let f=ae.caret();return{x:u.item.x+f.x,y:u.top+f.y,h:f.h,...f.fill!==void 0?{fill:f.fill}:{}}}function lx(){if(!ae)return[];let u=ha(ae.id);return u?ae.highlight().map(f=>({x:u.item.x+f.x,y:u.top+f.y,w:f.w,h:f.h})):[]}function lc(u){if(!ae)return null;let f=ha(ae.id);if(!f)return null;let h=bo(ae.id,u);return{x:h.x-f.item.x,y:h.y-f.top}}function bo(u,f){let h=Wn(u),x=h===0?void 0:kt(u);return x?je(f,Re(x),-h):f}function bk(){let u=ae?.id??H?.id;if(u===void 0)return null;let f=Wn(u),h=f===0?void 0:kt(u);return h?{angle:f,centre:Re(h)}:null}function vk(u){let f=z(n.root,u);if(!f||f.type!=="text"||typeof f.h!="number")return[];let h=C.itemOf(u);if(h?.kind!=="text")return[];let x=Z(Math.ceil(h.height));return x>f.h?[{op:"set",id:u,prop:"h",value:x}]:[]}function wk(u,f,h,x){let y=ht?ht.started:h,S=ht?.label??x;ht&&(ht.started=!0);let E=[{op:"set",id:u,prop:"content",value:f}],A=Ae(n,E);n=A.document,C.update(n);let L=vk(u);if(L.length===0){fc(y,S,E,A.inverse),la(E,S);return}let U=Ae(n,L);n=U.document,C.update(n);let W=[...E,...L];fc(y,S,W,[...U.inverse,...A.inverse]),la(W,S)}function fc(u,f,h,x){let y={label:f,ops:h,inverse:x};u&&D.amend(y)||D.push(y)}function Ps(u,f){let h=z(n.root,u);if(!h||h.type!=="text"||ae?.id===u)return;_r("done"),Mn("select"),he([u]),ae=Om({id:u,content:()=>{let y=z(n.root,u);return y?.type==="text"?y.content:""},base:()=>{let y=z(n.root,u);return{weight:wt(u)?.values.weight??bd,italic:y?.type==="text"&&y.italic===!0,size:wt(u)?.values.size??yd}},layout:()=>ha(u)?.layout??{lines:[],width:0,height:0},measure:()=>C.getMeasurer(),write:(y,S,E)=>wk(u,y,S,E),invalidate:()=>{ce(),fx(),ke("selection",r)},close:y=>_r(y)});let x=f?lc(f):null;x?ae.pointTo(x,!1):ae.selectAll(),e.classList.add("vd-editor--editing"),se.value="",se.focus({preventScroll:!0}),ce(),fx()}function _r(u){let f=ae;if(!f)return;ae=null,Oe=!1,f.destroy(),e.classList.remove("vd-editor--editing","vd-editor--typing"),ke("selection",r);let h=z(n.root,f.id);h?.type==="text"&&Tm(h.content)&&!Je(n,f.id)&&(pe([{op:"remove",id:f.id}],"Remove empty text"),he([])),e.ownerDocument.activeElement===se&&e.focus({preventScroll:!0}),ce()}function fx(){let u=cx();if(!u)return;let f=C.documentToScreen({x:u.x,y:u.y});se.style.left=`${Math.round(f.x)}px`,se.style.top=`${Math.round(f.y)}px`}let vo=0;function px(){e.classList.add("vd-editor--typing"),vo&&clearTimeout(vo),vo=setTimeout(()=>{vo=0,e.classList.remove("vd-editor--typing")},520)}function pc(u){return hx(oe,u,q,Y)}function hx(u,f,h,x){let y=oo(u,f);return y.length>0&&x?[...y,...fs(u,y,h,x)]:y}function mx(){let u=new Map;for(let f of ge())for(let h of no(f,n)){let x=an(h);x&&u.set(h,x)}for(let f of Ds([...u.keys()])){let h=an(f);h&&u.set(f,h)}return u}function xx(u,f,h,x,y){if(u.length===0)return[];let S={...f,x:f.x+x.x,y:f.y+x.y},E={...h,x:h.x+x.x,y:h.y+x.y},A=Re(S),L=Re(E);return u.flatMap(U=>{let W=je(Re(U.page),A,-y),X={x:W.x-U.page.w/2,y:W.y-U.page.h/2,w:U.page.w,h:U.page.h},ie=Kd(X,U.rotation-y,S,E),re=je(Re(ie),L,y),xe=re.x-ie.w/2-U.offset.x,ue=re.y-ie.h/2-U.offset.y;return[{nodeId:U.id,prop:"x",from:U.page.x-U.offset.x,to:Z(xe)},{nodeId:U.id,prop:"y",from:U.page.y-U.offset.y,to:Z(ue)},{nodeId:U.id,prop:"w",from:U.page.w,to:Z(ie.w)},{nodeId:U.id,prop:"h",from:U.page.h,to:Z(ie.h)}]})}function Ds(u){return qh(n,u,M)}function gx(u,f,h){let x=[];for(let[y,S]of u)x.push({nodeId:y,prop:"x",from:S.x,to:S.x+f}),x.push({nodeId:y,prop:"y",from:S.y,to:S.y+h});return x}function Er(u){ma(Sa(pc(u),oe))}function ma(u,f=u){let h=y=>{let S=Y?.nodes.get(y);return S?{x:0,y:0,w:S.w,h:S.h}:void 0},x=Vd(oe,u,h);N=Vd(oe,f,h),C.update(x.length>0?Ae(oe,x).document:oe),ce()}function yx(){let u=Wt(ge().flatMap(y=>qe(y)??[]));if(!u)return null;let f=new Map,h=new Map,x=Ls();for(let y of[...x,...Ds(x)]){let S=kt(y),E=an(y);!S||!E||(f.set(y,S),h.set(y,{x:S.x-E.x,y:S.y-E.y}))}return f.size===0?null:{bounds:u,frames:f,offsets:h}}function bx(u,f){let h=wp(u.frames,u.bounds,f),x=[];for(let[y,S]of h){let E=u.frames.get(y),A=u.offsets.get(y);if(!E||!A)continue;let L=Wn(y),U=L===0?S:Kd(E,L,u.bounds,f);x.push({nodeId:y,prop:"x",from:E.x-A.x,to:U.x-A.x},{nodeId:y,prop:"y",from:E.y-A.y,to:U.y-A.y},{nodeId:y,prop:"w",from:E.w,to:U.w},{nodeId:y,prop:"h",from:E.h,to:U.h})}return x}function kk(u,f){let h=ox();if(!h)return!1;let x=ge().length===1&&h.length===1?h[0]:void 0,y=Wt(ge().flatMap(L=>qe(L)??[])),S=x!==void 0?kt(x):y;if(!S)return!1;let E=new Set(Ds(h)),A=[...h,...E].flatMap(L=>{let U=kt(L),W=an(L);return!U||!W?[]:[{id:L,frame:U,rotation:Wn(L),offset:{x:U.x-W.x,y:U.y-W.y},...E.has(L)?{follower:!0}:{}}]});return A.length===0?!1:(St(f),mt({kind:"rotate",pointerId:f,origin:u,centre:Re(S),targets:A}),!0)}function Sk(u,f,h){let x=yx();return x?(St(h),mt({kind:"scale",pointerId:h,origin:u,handle:f,...x}),!0):!1}function _k(u){let f=yx();if(!f)return;let h=oo(n,bx(f,u));if(h.length===0)return;let x=u.w!==f.bounds.w||u.h!==f.bounds.h;pe([...h,...fs(n,h,Xr(n),Pe(n))],x?"Resize":"Move")}function Ek(u,f,h){let x=bu(u),y=Ts();if(!x||!y)return!1;let S=wn(y,x.axis)?.gaps[x.index],E=ua(ge());return S===void 0||E.length===0?!1:(St(h),mt({kind:"space",pointerId:h,origin:f,axis:x.axis,spacer:u,layout:y,gap:S,parts:E}),!0)}function Mk(u,f){let h=u.axis==="x"?f.x-u.origin.x:f.y-u.origin.y,x=Math.max(0,u.gap+h);Er(hc(u.parts,u.axis,vu(u.layout,u.axis,x)))}function Ck(u,f){let h=Ts(),x=h?wn(h,u):void 0;if(!h||!x||x.gaps.length===0)return;let y=Sa(oo(n,hc(ua(ge()),u,vu(h,u,Math.max(0,f)))));y.length!==0&&pe([...y,...fs(n,y,Xr(n),Pe(n))],"Spacing")}function Ak(u){let f=Ts(),h=f?wn(f,u)?.gaps:void 0;return!h||h.length===0?null:pm(h)?h[0]??null:"mixed"}function hc(u,f,h){return u.map(x=>{let y=f==="x"?x.frame.x:x.frame.y;return{nodeId:x.node,prop:f,from:y,to:y+(h.get(x.member)??0)}})}function $k(u,f,h){let x=Ts();if(!x||!x.order.includes(u))return!1;let y=ua(ge()),S=x.items.find(E=>E.id===u)?.frame;return y.length===0||!S?!1:(St(h),mt({kind:"reorder",pointerId:h,id:u,layout:x,parts:y,grab:{x:f.x-S.x,y:f.y-S.y},to:x.order.indexOf(u),swap:!1}),!0)}function Ok(u,f,h){u.to=ym(u.layout,f),u.swap=h;let x=Tk(u),y=new Map(x);y.set(u.id,{x:f.x-u.grab.x,y:f.y-u.grab.y}),ma(pc(vx(u,y)),pc(vx(u,x)))}function Tk(u){let f=u.layout.order.indexOf(u.id);if(f===-1||u.to===f)return new Map;if(u.swap){let h=u.layout.order[u.to];return h===void 0?new Map:wm(u.layout,u.id,h)}return vm(u.layout,bm(u.layout.order,f,u.to))}function vx(u,f){let h=new Map(u.layout.items.map(y=>[y.id,y.frame])),x=[];for(let y of u.parts){let S=f.get(y.member),E=h.get(y.member);!S||!E||x.push({nodeId:y.node,prop:"x",from:y.frame.x,to:y.frame.x+(S.x-E.x)},{nodeId:y.node,prop:"y",from:y.frame.y,to:y.frame.y+(S.y-E.y)})}return x}function mt(u,f=[],h=n){Se=h,be=f,oe=n,v=u,N=[],q=Xr(n),Y=Pe(n),_e=dt,Ct=Lk(u)?Qh(n,Y,Pk(u)):[]}function Lk(u){return u.kind==="move"||u.kind==="resize"||u.kind==="scale"||u.kind==="create"||u.kind==="line"||u.kind==="end"}function Pk(u){return u.kind==="move"||u.kind==="scale"?new Set(ge()):u.kind==="resize"||u.kind==="end"?new Set([u.id]):new Set}function wo(u){return u.metaKey||u.ctrlKey?0:Zh/C.getCamera().zoom}function En(u){let f=[...be,...N];v=null,N=[],be=[],I=null,F=null,_e=dt,n=Se,C.update(n),pe(f,u),ce()}function Dk(){let u=N.length>0?Ae(oe,N).document:oe,f=Ds(ge()),h=new Set([...ge(),...f].flatMap(L=>wx(L,u))),x=[],y=new Map,S=(L,U,W)=>{let X=z(u.root,U);if(!X||!me(X))return;y.set(L,U),x.push({op:"move",id:L,parent:U,index:te(X).length});let ie={x:Yt(W).x-Yt(U).x,y:Yt(W).y-Yt(U).y};if(!(ie.x===0&&ie.y===0))for(let re of no(L,u)){let xe=an(re);xe&&(x.push({op:"set",id:re,prop:"x",value:Z(xe.x+ie.x)}),x.push({op:"set",id:re,prop:"y",value:Z(xe.y+ie.y)}))}};for(let L of ge()){if(Je(u,L)||Hn(u,L))continue;let U=z(u.root,L),W=Le(u.root,L);if(!U||!W)continue;let X=qe(L);if(!X)continue;let ie={x:X.x+X.w/2,y:X.y+X.h/2},re=Xn(ie,h)??n.root.id;re!==W.id&&S(L,re,W.id)}let E=Ye(u.root).links;for(let L of f){let U=[...E].find(([ie,re])=>re===L&&y.has(ie))?.[0],W=U===void 0?void 0:y.get(U),X=Le(u.root,L);W===void 0||!X||X.id===W||S(L,W,X.id)}if(x.length===0)return[];let A=Ae(u,x).document;return[...x,...ps(u,A,h)]}function wx(u,f){let h=z(f.root,u);if(!h)return[];let x=[];return de(h,y=>{x.push(y.id)}),x}function mc(){if(!v)return;v=null,N=[],I=null,F=null,_e=dt;let u=be.length>0;n=Se,be=[],u&&he(r.filter(f=>z(n.root,f))),C.update(n),ce()}let Nk=5,xa=8;function kx(u,f=n,h=C.getResolution()){let x=z(f.root,u),y=h.nodes.get(u);if(x?.type!=="vector"||!y)return;let S={x:y.absX,y:y.absY,w:Math.max(0,y.w),h:Math.max(0,y.h)};return{node:x,view:Ir(x.view,S.w,S.h),box:S}}function Ns(u,f=n,h=C.getResolution()){let x=kx(u,f,h);if(x)return Be(ar(x.node.d).contours,Fr(x.view,x.box))}function Yn(u,f,h,x=n,y=C.getResolution()){let S=kx(u,x,y);if(!S)return[];let{node:E,view:A,box:L}=S,U=Be(f,bl(A,L)),W=[],X=(We,Ot,Tt)=>{Ot!==Tt&&W.push({op:"set",id:u,prop:We,value:Ot})};X("d",ze(U),E.d);let ie=[E.x,E.y,E.w,E.h].every(We=>typeof We=="number"),re=Kt(U),xe=Kt(f);if(!h||!ie||!re||!xe)return W;let ue=L.x-E.x,De=L.y-E.y;return X("view",Pn(re),E.view),X("x",Z(xe.x-ue),E.x),X("y",Z(xe.y-De),E.y),X("w",Z(xe.w),E.w),X("h",Z(xe.h),E.h),W}function Mr(u){return z(n.root,u)?.type!=="vector"||!It(u)?!1:(ae&&_r("done"),J&&ga(),he([u]),H={id:u,picked:new Set},o!=="select"&&Mn("select"),Ft(null),ce(),!0)}function Rs(){H&&(H=null,ce())}function Rk(){if(J){let h=J.contours[J.contour],x=h?.anchors??[],y=x[x.length-1],S=x[0],E=J.hover,A=E!==null&&S!==void 0&&x.length>=2&&!h?.closed&&ko(S,E)<=xa;return{contours:J.contours,anchors:x.map((L,U)=>({key:it(J?.contour??0,U),at:L,selected:U===x.length-1})),handles:y?Pp(J.contours,new Set([it(J.contour,x.length-1)])):[],pending:y&&E&&!J.dragging&&!h?.closed?{from:y,...y.out?{c1:y.out}:{},to:E}:null,closeAt:A?S:null}}if(!H)return null;let u=Ns(H.id);if(!u)return null;let f=new Set(Tp(u,H.picked));return{contours:u,anchors:u.flatMap((h,x)=>h.anchors.map((y,S)=>({key:it(x,S),at:y,selected:f.has(it(x,S))}))),handles:Pp(u,f)}}function ko(u,f){return Math.hypot(u.x-f.x,u.y-f.y)*C.getCamera().zoom}function Ik(u,f,h,x){if(!H)return!1;let y=H.id,S=Ns(y);if(!S)return H=null,!1;u.preventDefault(),St(u.pointerId);let E=G.hitPath(f);if(E?.kind==="handle"){let L=kb(E.key),U=L?S[L.contour]?.anchors[L.index]:void 0;if(L&&U)return mt({kind:"pathHandle",pointerId:u.pointerId,id:y,start:S,contour:L.contour,index:L.index,side:L.side,smooth:Gd(U),last:S}),!0}if(E?.kind==="anchor")return u.altKey?(H.picked=new Set([E.key]),pe(Yn(y,Sb(S,E.key),!1),"Convert point"),!0):(u.shiftKey?H.picked.has(E.key)?H.picked.delete(E.key):H.picked.add(E.key):H.picked.has(E.key)||(H.picked=new Set([E.key])),mt({kind:"points",pointerId:u.pointerId,id:y,origin:h,start:S,keys:new Set(H.picked),lead:E.key,moved:!1,last:S}),ce(),!0);let A=vl(S,h);if(A&&A.distance*C.getCamera().zoom<=Nk){if(x>=2){let X=wl(S,A.contour,A.segment,A.t);return H.picked=new Set([it(A.contour,A.segment+1)]),pe(Yn(y,X,!1),"Add point"),!0}let L=S[A.contour],U=L.anchors[A.segment],W=L.anchors[(A.segment+1)%L.anchors.length];return mt({kind:"segment",pointerId:u.pointerId,id:y,origin:h,start:S,contour:A.contour,segment:A.segment,t:A.t,straight:!U?.out&&!W?.in,last:S}),!0}return mt({kind:"pointMarquee",pointerId:u.pointerId,origin:h,current:h,additive:u.shiftKey}),!0}function Fk(u,f,h,x){let y=Op(u.start,u.lead);if(!y||x===0)return{dx:f,dy:h};let S=y.x+f,E=y.y+h,A=x,L=x,U=f,W=h;return u.start.forEach((X,ie)=>X.anchors.forEach((re,xe)=>{u.keys.has(it(ie,xe))||(Math.abs(re.x-S)<A&&(A=Math.abs(re.x-S),U=re.x-y.x),Math.abs(re.y-E)<L&&(L=Math.abs(re.y-E),W=re.y-y.y))})),{dx:U,dy:W}}function Bk(u,f){if(!v)return!1;let h=(x,y)=>{Y&&ma(Yn(y,x,!1,oe,Y))};switch(v.kind){case"points":{let x=f;u.shiftKey&&(x=zi(v.origin,f));let y={dx:x.x-v.origin.x,dy:x.y-v.origin.y};if(!v.moved&&Math.hypot(y.dx,y.dy)*C.getCamera().zoom<jn)return!0;v.moved=!0;let{dx:S,dy:E}=u.shiftKey?y:Fk(v,y.dx,y.dy,wo(u));return v.last=Xd(v.start,v.keys,S,E),h(v.last,v.id),!0}case"pathHandle":{let x=v.start[v.contour]?.anchors[v.index],y=u.shiftKey&&x?zi(x,f):f;return v.last=qd(v.start,v.contour,v.index,v.side,y,{smooth:v.smooth,breakSmooth:u.altKey}),h(v.last,v.id),!0}case"segment":return v.last=Eb(v.start,v.contour,v.segment,v.t,f.x-v.origin.x,f.y-v.origin.y,v.straight),h(v.last,v.id),!0;case"pointMarquee":return v.current=f,ce(),!0;default:return!1}}function Vk(u){if(!v)return!1;switch(v.kind){case"points":case"pathHandle":case"segment":{let f=v.kind!=="points"||v.moved,h=v.kind==="points"?v.keys.size===1?"Move point":"Move points":v.kind==="pathHandle"?"Adjust curve":"Reshape";return N=f&&Y?Yn(v.id,v.last,!0,oe,Y):[],En(h),!0}case"pointMarquee":{let f=to(v.origin,v.current),h=v.additive;if(v=null,_e=dt,!H)return!0;let x=C.getCamera().zoom;if(f.w*x<jn&&f.h*x<jn){if(C.hitTest(u)===H.id)H.picked=new Set;else{Rs();let E=yo(u);he(E===null?[]:[E])}return ce(),!0}let y=Ns(H.id)??[],S=Lp(y).filter(E=>{let A=Op(y,E);return A!==void 0&&Mt(f,A.x,A.y)});return H.picked=new Set(h?[...H.picked,...S]:S),ce(),!0}default:return!1}}function Hk(u){if(!H)return!1;let f=H.id,h=u.metaKey||u.ctrlKey;if(u.key==="Escape"||u.key==="Enter"&&!h)return u.preventDefault(),v?mc():Rs(),!0;let x=Ns(f);if(!x)return!1;let y=new Set(Tp(x,H.picked));if(u.key==="Delete"||u.key==="Backspace"){if(u.preventDefault(),y.size===0)return!0;let A=_b(x,y);return H.picked=new Set,A.length===0?(Rs(),Mo(),!0):(pe(Yn(f,A,!0),y.size===1?"Delete point":"Delete points"),!0)}let S=u.shiftKey?Kv:jv,E=Wv[u.key];return E&&!h?(u.preventDefault(),y.size>0&&pe(Yn(f,Xd(x,y,E[0]*S,E[1]*S),!0),"Nudge points"),!0):h&&u.key.toLowerCase()==="a"?(u.preventDefault(),H.picked=new Set(Lp(x)),ce(),!0):h&&!u.shiftKey&&u.code==="KeyJ"?(u.preventDefault(),pe(Yn(f,Mb(x,y),!0),"Close path"),!0):!1}function Uk(u,f){if(u.preventDefault(),St(u.pointerId),!J){J=zk(f)??{contours:[{closed:!1,anchors:[{x:f.x,y:f.y}]}],contour:0,target:null,hover:null,dragging:null};let E=J.contours[J.contour];J.dragging={pointerId:u.pointerId,index:E.anchors.length-1,origin:f},ce();return}let h=J.contours[J.contour],x=h.anchors[0],y=h.anchors[h.anchors.length-1];if(x&&h.anchors.length>=2&&ko(x,f)<=xa){J.contours[J.contour]={...h,closed:!0},J.dragging={pointerId:u.pointerId,index:0,origin:x},ce();return}let S=u.shiftKey&&y?zi(y,f):f;J.contours[J.contour]={...h,anchors:[...h.anchors,{x:S.x,y:S.y}]},J.dragging={pointerId:u.pointerId,index:h.anchors.length,origin:S},ce()}function zk(u){let f=r.length===1?r[0]:null;if(f===null||!It(f))return null;let h=Ns(f);if(!h)return null;for(let x=0;x<h.length;x+=1){let y=h[x];if(y.closed||y.anchors.length<1)continue;let S=y.anchors[0],E=y.anchors[y.anchors.length-1],A=ko(E,u)<=xa,L=!A&&ko(S,u)<=xa;if(!A&&!L)continue;let U=[...h];return L&&(U[x]=Cb(y)),{contours:U,contour:x,target:f,hover:null,dragging:null}}return null}function jk(u,f){if(!J)return;let h=J.dragging;if(!h||h.pointerId!==u.pointerId){let L=J.contours[J.contour],U=L?.anchors[L.anchors.length-1];J.hover=u.shiftKey&&U?zi(U,f):f,ce();return}if(ko(h.origin,f)<jn)return;let x=J.contours[J.contour],y=x.anchors[h.index];if(!y)return;let S={x:2*y.x-f.x,y:2*y.y-f.y},E=u.altKey?y.in:S,A=[...x.anchors];A[h.index]={x:y.x,y:y.y,...E?{in:E}:{},out:f},J.contours[J.contour]={...x,anchors:A},ce()}function Kk(u){!J?.dragging||J.dragging.pointerId!==u.pointerId||(Bc(u.pointerId),J.dragging=null,J.contours[J.contour]?.closed?ga():ce())}function ga(){if(!J)return;let u=J;J=null;let f=u.contours[u.contour];if(!f||f.anchors.length<2){ce();return}if(u.target!==null){pe(Yn(u.target,u.contours,!0),"Extend path"),Mn("select"),Mr(u.target);return}let h=Kt(u.contours),x=f.anchors[0];if(!h)return;let y=Jn(Xn(x)??_??n.root.id),S=z(n.root,y)??n.root,E=Yt(y),A=Be(u.contours,U=>({x:U.x-h.x,y:U.y-h.y})),L=pn(n.root,"path");pe([{op:"insert",parent:y,index:te(S).length,node:To({id:L,x:Z(h.x-E.x),y:Z(h.y-E.y),w:Z(h.w),h:Z(h.h),view:Pn({x:0,y:0,w:h.w,h:h.h}),d:ze(A),fill:"none",stroke:t.defaultStroke??"#1f2937",strokeWidth:2,cap:"round",join:"round"})}],"Draw path"),Mn("select"),Mr(L)}function xc(u=ge()){let f=[],h=[];for(let x of u){let y=z(n.root,x),S=Le(n.root,x),E=wt(x);if(!y||!S||!E||y.type!=="rect"&&y.type!=="ellipse"||Je(n,x))continue;let A=Math.max(0,E.w),L=Math.max(0,E.h),U=y.type==="rect"?Dn(A,L,Zn(E.values)):Vr(A,L),W=To({id:x,...y.name===void 0?{}:{name:y.name},x:y.x,y:y.y,w:y.w,h:y.h,view:Pn({x:0,y:0,w:A,h:L}),d:ze(U),...y.fill===void 0?{}:{fill:y.fill},...y.stroke===void 0?{}:{stroke:y.stroke},...y.strokeWidth===void 0?{}:{strokeWidth:y.strokeWidth},...y.dash===void 0?{}:{dash:y.dash},...y.strokeAlign===void 0?{}:{strokeAlign:y.strokeAlign},...y.cap===void 0?{}:{cap:y.cap},...y.opacity===void 0?{}:{opacity:y.opacity},...y.hidden?{hidden:!0}:{},...y.locked?{locked:!0}:{}}),X=S.children.findIndex(ie=>ie.id===x);f.push({op:"remove",id:x},{op:"insert",parent:S.id,index:X,node:W}),h.push(x)}h.length!==0&&(pe(f,h.length===1?"Convert to vector":`Convert ${h.length} to vector`),he(h),h.length===1&&Mr(h[0]))}function gc(){return r.filter(u=>u!==n.root.id)}function yc(u=gc()){return Jo(n,u)}function Sx(u=gc()){return t.merge!==void 0&&yc(u)===void 0}function bc(u,f=gc()){if(!t.merge)return null;let h;try{h=t.merge(n,{verb:u,ids:f})}catch(x){h={ok:!1,...Zo(x)}}return h.ok?(_=null,pe(h.ops,`${Yo[u]} ${f.length} shapes`),he([h.id]),h.id):(ke("notice",{message:lu(h)}),null)}function Is(u=r){return Vb(n,u)}function vc(u=r){let f=Is(u);return f.ok?(pe(Hb(f.pair),"Mask with shape"),he([f.pair.image]),!0):(ke("notice",{message:f.why}),!1)}function ya(u=r){return Ub(n,u)}function wc(u=r){let f=ya(u);return f.length===0?!1:(M!==null&&f.includes(M)&&(M=null),pe(Gh(f),f.length===1?"Release mask":"Release masks"),!0)}function ba(u){return!Ye(n.root).links.has(u)||!It(u)?!1:(he([u]),M=u,ce(),ke("selection",r),!0)}function kc(){return M===null?!1:(M=null,ce(),ke("selection",r),!0)}function Gk(){let u=r.flatMap(y=>z(n.root,y)??[]),f=u.length===2&&u.some(st),h=ya(),x=r.length===1?r[0]:null;return{offer:f&&!(h.length>0&&!Is().ok),can:Is().ok,release:h.length>0,crop:x!==null&&M!==x&&Ye(n.root).links.has(x)}}function qk(){let u=Is(),f=ya(),h=u.ok?z(n.root,u.pair.image):void 0,x=u.ok&&h!==void 0&&st(h)&&h.mask===u.pair.shape;u.ok&&!x?vc():f.length>0?wc():u.ok||ke("notice",{message:u.why})}function Wk(){let u=C.getScene(),f=[],h=new Set;for(let x of u.items){let y=x.mask;if(y===void 0||!r.includes(x.id)&&!r.includes(y.id))continue;let S=`${x.id}\0${y.id}`;if(h.has(S))continue;h.add(S);let E=M===x.id,A=E&&x.kind==="image"&&x.href!==void 0?{href:x.href,frame:{x:x.x,y:x.y,w:x.w,h:x.h},rotation:x.rotation,aspect:Q2[x.fit]}:void 0;f.push({contours:y.contours,cropping:E,...A===void 0?{}:{ghost:A}})}return f}function _x(){return ge().filter(u=>{let f=z(n.root,u)?.type;return f==="rect"||f==="ellipse"}).length}let Xk=450,Ex=4,Fs={x:0,y:0,at:0,count:0};function Yk(u){let f=Date.now(),x=Math.abs(u.x-Fs.x)<=Ex&&Math.abs(u.y-Fs.y)<=Ex&&f-Fs.at<=Xk?Fs.count+1:1;return Fs={x:u.x,y:u.y,at:f,count:x},x}let Mx=u=>{if(w=u.pointerType==="touch",w){g.add(u.pointerId),b=g.size===1?{pointerId:u.pointerId,screen:C.pointerPoint(u)}:null;return}if(u.button!==0||m)return;let f=C.pointerPoint(u),h=C.screenToDocument(f);Rt=h;let x=Yk(f);if(ae){let L=lc(h),U=C.itemOf(ae.id),W=bo(ae.id,h);if(L&&U&&Mt(U,W.x,W.y)){u.preventDefault(),St(u.pointerId),Oe=!0,x>=3?ae.selectLineAt(L):x===2?ae.selectWordAt(L):ae.pointTo(L,u.shiftKey),se.focus({preventScroll:!0}),ce();return}_r("blur")}if(e.focus({preventScroll:!0}),o==="select"&&(u.metaKey||u.ctrlKey)&&Os(h)){u.preventDefault();return}if(o==="pen"){Uk(u,h);return}if(H&&o==="select"&&Ik(u,f,bo(H.id,h),x))return;if(o==="line"){u.preventDefault(),St(u.pointerId);let L=fa(h,null,u),U=L?.at??h;mt({kind:"line",pointerId:u.pointerId,origin:U,from:L,current:U,to:null}),ce();return}if(o!=="select"){u.preventDefault(),St(u.pointerId),mt({kind:"create",pointerId:u.pointerId,origin:h,current:h}),ce();return}let y=ge().length===1?ge()[0]:null;if(y!==null&&lk(y,f,u.pointerId)){u.preventDefault();return}if(y!==null){let L=z(n.root,y),U=G.hitAdjuster(f),W=L&&U?eu(L,U.id):void 0,X=W?qe(y):void 0;if(L&&W&&X&&U){u.preventDefault(),St(u.pointerId);let ue=W.propOf(L,U.id,u.altKey);mt({kind:"adjust",pointerId:u.pointerId,id:y,adjuster:W,handleId:U.id,prop:ue,frame:X,from:dx(y,ue)});return}let ie=L&&!me(L)?G.hitHandle(f):null,re=ie?an(y):void 0,xe=re?kt(y):void 0;if(ie&&re&&xe){u.preventDefault(),St(u.pointerId),mt({kind:"resize",pointerId:u.pointerId,origin:h,id:y,handle:ie.handle,frame:re,offset:{x:xe.x-re.x,y:xe.y-re.y},rotation:Wn(y),riders:Ds([y]).flatMap(ue=>{let De=kt(ue),We=an(ue);return!De||!We?[]:[{id:ue,page:De,offset:{x:De.x-We.x,y:De.y-We.y},rotation:Wn(ue)}]})});return}}let S=ge().length>0?G.hitHandle(f):null;if(S&&Sk(h,S.handle,u.pointerId)){u.preventDefault();return}let E=G.hitPageLabel(f);if(E!==null){if(u.preventDefault(),_=null,u.shiftKey){he(r.includes(E)?r.filter(L=>L!==E):[...r,E]);return}if(r.includes(E)||he([E]),x===2){gk(E);return}Sc(h,u.pointerId,u.altKey);return}if(ge().length>0&&G.hitRotate(f)!==null&&kk(h,u.pointerId)){u.preventDefault();return}if(ge().length>1){let L=G.hitRing(f);if(L!==null&&$k(L,h,u.pointerId)){u.preventDefault();return}let U=G.hitSpacer(f);if(U!==null&&Ek(U,h,u.pointerId)){u.preventDefault();return}}if(M!==null&&!u.shiftKey){let L=kt(M),U=bo(M,h);if(L&&Mt(L,U.x,U.y)){Sc(h,u.pointerId,!1)&&u.preventDefault();return}}let A=yo(h);if(A===null){u.preventDefault(),St(u.pointerId),_=null,u.shiftKey||he([]),mt({kind:"marquee",pointerId:u.pointerId,origin:h,current:h});return}_!==null&&!Ke(n.root,A).includes(_)&&(_=null),u.shiftKey?he(r.includes(A)?r.filter(L=>L!==A):[...r,A]):r.includes(A)||he([A]),Sc(h,u.pointerId,u.altKey)&&u.preventDefault()};function Jk(u){ae&&_r("blur");let f=yo(C.screenToDocument(u));f!==null&&_!==null&&!Ke(n.root,f).includes(_)&&(_=null),f===null&&(_=null),he(f===null?[]:[f])}function Sc(u,f,h){let x=n,y=[];if(h){let E=eg({x:0,y:0});E&&(y=E.ops,n=Ae(n,y).document,C.update(n),he(E.ids))}let S=mx();return S.size===0?(n=x,C.update(n),!1):(St(f),mt({kind:"move",pointerId:f,origin:u,frames:S,bounds:Wt(ge().flatMap(E=>qe(E)??[]))},y,x),!0)}let Cx=u=>{let f=C.pointerPoint(u);if(u.pointerType==="touch"){b?.pointerId===u.pointerId&&Math.hypot(b.screen.x-f.x,b.screen.y-f.y)>oA&&(b=null);return}if(Rt=C.screenToDocument(f),Oe&&ae){let x=lc(Rt);x&&ae.pointTo(x,!0);return}if(J&&o==="pen"){jk(u,Rt);return}if(!v){a1(f);return}if(v.pointerId!==u.pointerId)return;let h=Rt;if(!Bk(u,H?bo(H.id,h):h))switch(v.kind){case"move":{let x=h.x-v.origin.x,y=h.y-v.origin.y;if(v.bounds){let S={...v.bounds,x:v.bounds.x+x,y:v.bounds.y+y};_e=em(S,Ct,wo(u)),x+=_e.dx,y+=_e.dy}Er(gx(v.frames,x,y));return}case"resize":{let{id:x,handle:y,frame:S,origin:E,offset:A,rotation:L}=v,U=h.x-E.x,W=h.y-E.y;if(L!==0){_e=dt;let re=bb(S,y,U,W,L);Er([...Fd(S,re).map(xe=>({nodeId:x,prop:xe,from:S[xe],to:re[xe]})),...xx(v.riders,S,re,A,L)]);return}let X=Vn(S,y,U,W);_e=au({...X,x:X.x+A.x,y:X.y+A.y},y,Ct,wo(u)),U+=_e.dx,W+=_e.dy;let ie=Vn(S,y,U,W);Er([...Fd(S,ie).map(re=>({nodeId:x,prop:re,from:S[re],to:ie[re]})),...xx(v.riders,S,ie,A,0)]);return}case"scale":{let{handle:x,bounds:y,origin:S,frames:E,offsets:A}=v,L=h.x-S.x,U=h.y-S.y,W=Vn(y,x,L,U);_e=au(W,x,Ct,wo(u)),L+=_e.dx,U+=_e.dy,Er(bx({bounds:y,frames:E,offsets:A},Vn(y,x,L,U)));return}case"space":Mk(v,h);return;case"reorder":Ok(v,h,u.metaKey||u.ctrlKey);return;case"rotate":{let{centre:x,origin:y,targets:S}=v,E=S[0],A=vb(x,y,h,E?.rotation??0,u.shiftKey?U2:void 0);F=Wo((E?.rotation??0)+A);let L=[],U=S.filter(W=>W.follower!==!0).length===1;for(let W of wb(S,x,A)){let X=S.find(ie=>ie.id===W.id);X&&(L.push({nodeId:W.id,prop:"rotation",from:X.rotation,to:W.rotation}),!(U&&X.follower!==!0)&&L.push({nodeId:W.id,prop:"x",from:X.frame.x-X.offset.x,to:Z(W.frame.x-X.offset.x)},{nodeId:W.id,prop:"y",from:X.frame.y-X.offset.y,to:Z(W.frame.y-X.offset.y)}))}Er(L);return}case"adjust":{let x=v.adjuster.valueAt(v.frame,v.handleId,h);I=x,Er([{nodeId:v.id,prop:v.prop,from:v.from,to:x}]);return}case"line":{v.to=fa(h,null,u),v.to&&(_e=dt),v.current=v.to?.at??ux(h,v.origin,u),ce();return}case"end":{v.anchor=fa(h,v.id,u),v.anchor&&(_e=dt),v.current=v.anchor?.at??ux(h,v.fixed,u),ma(ck(v.id,v.end,v.anchor,v.current));return}case"create":{_e=du(h,Ct,wo(u));let x={x:h.x+_e.dx,y:h.y+_e.dy};v.current=u.shiftKey&&o!=="text"?G2(v.origin,x):x,ce();return}case"marquee":{v.current=h,ce();return}}},va=u=>{if(u.pointerType==="touch"){if(g.delete(u.pointerId),b?.pointerId!==u.pointerId)return;b=null,u.type==="pointerup"&&Jk(C.pointerPoint(u));return}if(Oe){Oe=!1,Bc(u.pointerId),se.focus({preventScroll:!0});return}if(J){Kk(u);return}if(!v||v.pointerId!==u.pointerId)return;Bc(u.pointerId);let f=C.screenToDocument(C.pointerPoint(u));if(!Vk(H?bo(H.id,f):f))switch(v.kind){case"line":{let{origin:h,current:x,from:y,to:S}=v;v=null,_e=dt,ce(),fk(h,x,y,S);return}case"end":En(v.anchor?"Attach end":"Move end");return;case"create":{let h=to(v.origin,v.current),x=o==="text"?"text":o==="frame"?"frame":o==="ellipse"?"ellipse":"rect";v=null,_e=dt,ce();let y=h.w<jn||h.h<jn;if(y&&x!=="text")return;let S=y?{x:h.x,y:h.y,w:qv.w,h:qv.h}:h,E=Jn(Xn({x:S.x,y:S.y})??_??n.root.id),A=z(n.root,E)??n.root,L=Yt(E),U={x:Math.round(S.x-L.x),y:Math.round(S.y-L.y),w:Math.round(S.w),h:Math.round(S.h)},W=pn(n.root,x);pe([{op:"insert",parent:E,index:te(A).length,node:x==="text"?il({...U,id:W,content:""}):x==="frame"?Va({...U,id:W,background:Uv,children:[]}):x==="ellipse"?tl({...U,id:W,fill:t.defaultFill??"#3b82f6"}):sl({...U,id:W,fill:t.defaultFill??"#3b82f6"})}],K2[x]),he([W]),Mn("select"),x==="text"&&Ps(W);return}case"marquee":{let h=to(v.origin,v.current),x=u.shiftKey;if(v=null,_e=dt,h.w>=jn||h.h>=jn){let y=R1(h);he(x?[...new Set([...r,...y])]:y)}ce();return}case"move":{let h=Dk();h.length>0&&(N=[...N,...h]),En(be.length>0?"Duplicate":"Move");return}case"resize":En("Resize");return;case"scale":En(r.length===1?"Resize group":`Resize ${r.length} elements`);return;case"space":En("Spacing");return;case"reorder":En(v.swap?"Swap":"Reorder");return;case"adjust":En("Corner radius");return;case"rotate":En("Rotate");return}},wa=null;function Zk(u,f,h){let x=mx();if(x.size===0)return;let y=hx(n,gx(x,u,f),Xr(n),Pe(n));if(y.length===0)return;let S="Nudge",E=r.join(`
3098
+ `),A=h&&wa!==null&&wa.selection===E&&D.top===wa.entry;ht===null?(ht={label:S,started:A},pe(y,S),ix()):pe(y,S),wa=D.top?{entry:D.top,selection:E}:null}function Ax(){C.fitToContent()}function $x(){C.setCamera({...C.getCamera(),zoom:1})}function Qk(){let u=Wt(r.flatMap(h=>qe(h)??[]));if(!u)return;let f=e.getBoundingClientRect();C.setCamera(bn({x:u.x,y:u.y,width:u.w,height:u.h},{width:f.width||u.w,height:f.height||u.h},z2))}function Ox(u,f){if((u.metaKey||u.ctrlKey)&&!u.altKey){let x=u.code==="Equal"?Gv:u.code==="Minus"?1/Gv:null;return x!==null?(u.preventDefault(),C.zoomBy(x),!0):u.code==="Digit0"&&!u.shiftKey?(u.preventDefault(),$x(),!0):!1}return f||!u.shiftKey||u.altKey?!1:u.code==="Digit1"?(u.preventDefault(),Ax(),!0):u.code==="Digit2"?r.length===0?!1:(u.preventDefault(),Qk(),!0):!1}function Tx(u){return u.ctrlKey&&!u.metaKey&&!u.altKey&&!u.shiftKey&&u.key.toLowerCase()==="y"}function Lx(u){return Ke(n.root,u).slice(0,-1).reverse().find(h=>{let x=z(n.root,h);return x!==void 0&&Bs(x)})??null}function e1(){if(r.length!==1)return!1;let u=z(n.root,r[0]);if(!u||!(Bs(u)||u.type==="frame"))return!1;let f=te(u).map(h=>h.id).filter(It);return f.length===0?!1:(Bs(u)&&Lc(u.id),he(f),!0)}function t1(){let u=r[0];if(u===void 0)return!1;let f=Le(n.root,u);return!f||f.id===n.root.id?!1:f.id===_?(Pc(),!0):(_=Lx(f.id),he([f.id]),!0)}function n1(u){let f=u===1?r[r.length-1]:r[0];if(f===void 0)return!1;let h=Le(n.root,f);if(!h)return!1;let x=te(h).map(E=>E.id).filter(E=>E===f||It(E)),y=x.indexOf(f),S=x[(y+u+x.length)%x.length];return S!==void 0&&he([S]),!0}let Px=u=>{if(Lu(u.target))return;if(ae){let y=(u.metaKey||u.ctrlKey)&&u.key.toLowerCase()==="z";if(y||Tx(u)){u.preventDefault(),ae.breakBurst(),u.shiftKey||!y?Hs():Vs();return}Ox(u,!0);return}if(J&&(u.key==="Enter"||u.key==="Escape")){u.preventDefault(),ga();return}if(Hk(u))return;if((u.metaKey||u.ctrlKey)&&u.shiftKey&&u.code==="KeyO"){if(_x()===0)return;u.preventDefault(),xc();return}if(u.key==="Enter"&&u.shiftKey&&!Ss(u)){t1()&&u.preventDefault();return}if(u.key==="Enter"&&!Ss(u)&&r.length===1){let y=r[0];if(z(n.root,y)?.type==="vector"&&Mr(y)){u.preventDefault();return}}if(u.key==="Enter"&&!Ss(u)&&r.length===1){let y=r[0];if(z(n.root,y)?.type==="text"){u.preventDefault(),Ps(y);return}}if(u.key==="Enter"&&!Ss(u)){if(kc()){u.preventDefault();return}let y=r.length===1?r[0]:null;if(y!==null&&ba(y)){u.preventDefault();return}}if(u.key==="Enter"&&!Ss(u)){e1()&&u.preventDefault();return}if(u.key==="Tab"&&!Ss(u)){n1(u.shiftKey?-1:1)&&u.preventDefault();return}if(u.code==="Space"&&!m){m=!0,xt(at("grab"));return}let f=u.metaKey||u.ctrlKey;if(f&&u.key.toLowerCase()==="z"){u.preventDefault(),u.shiftKey?Hs():Vs();return}if(Tx(u)){u.preventDefault(),Hs();return}if(Ox(u,!1))return;if(f&&u.shiftKey&&!u.altKey&&u.code==="KeyL"){if(!R.lock||r.length===0)return;u.preventDefault(),Eo(r,"locked");return}if(f&&u.shiftKey&&!u.altKey&&u.code==="KeyH"){if(!R.hide||r.length===0)return;u.preventDefault(),Eo(r,"hidden");return}if(f&&u.altKey&&!u.shiftKey&&u.code==="KeyK"){if(!Vi(n,r))return;u.preventDefault(),Rc();return}if(f&&u.altKey&&!u.shiftKey&&u.code==="KeyM"&&!u.getModifierState("AltGraph")){if(r.length===0)return;u.preventDefault(),qk();return}if(f&&u.altKey&&!u.shiftKey&&u.code==="KeyB"){if(!r.some(y=>z(n.root,y)?.type==="instance"))return;u.preventDefault(),Ic();return}if(f&&u.key.toLowerCase()==="g"){u.preventDefault(),u.shiftKey?Oc():$c();return}if(f&&u.key.toLowerCase()==="a"){u.preventDefault(),Dc();return}if(f&&!u.altKey&&u.key.toLowerCase()==="d"){u.preventDefault(),Cc();return}if(u.altKey){let y=u.shiftKey&&!f?X2[u.code]:void 0;if(y&&t.merge){u.preventDefault();let A=yc();A?ke("notice",{message:lu(A)}):bc(y);return}let S=q2[u.code];if(S&&!f){u.preventDefault(),Yx(S);return}let E=W2[u.code];if(E&&u.ctrlKey){u.preventDefault(),Zx(E);return}}if(u.key==="]"||u.key==="["){if(r.length===0)return;u.preventDefault();let y=u.key==="]";Tc(f?y?"front":"back":y?"forward":"backward");return}if(u.key==="Escape"){if(v)mc();else{if(kc())return;_!==null?Pc():he([])}return}if(u.key==="Delete"||u.key==="Backspace"){if(r.length===0)return;u.preventDefault(),Mo();return}let h=Wv[u.key];if(h&&!f&&!u.altKey){if(r.length===0||(u.preventDefault(),v||J))return;let y=u.shiftKey?Kv:jv;Zk(h[0]*y,h[1]*y,u.repeat);return}let x=f||u.altKey?void 0:Lm[u.key.toLowerCase()];x&&Mn(x)};function Dx(){if(!ae)return null;let u=z(n.root,ae.id);if(u?.type!=="text")return null;let{anchor:f,head:h}=ae.getSelection();return f===h?null:lo(km(u.content,f,h))}let Nx=u=>{if(Lu(u.target))return;let f=Dx()??So();f!==null&&(u.preventDefault(),u.clipboardData?.setData("text/plain",f))},Rx=u=>{if(Lu(u.target))return;let f=Dx();if(f!==null&&ae){u.preventDefault(),u.clipboardData?.setData("text/plain",f);let{anchor:x,head:y}=ae.getSelection();ae.breakBurst(),ae.setSelection(x,y),ae.handleInput({inputType:"deleteByCut",data:null});return}let h=So();h!==null&&(u.preventDefault(),u.clipboardData?.setData("text/plain",h),Mo())},Ix=u=>{if(Lu(u.target))return;u.preventDefault();let f=Dp(u.clipboardData);if(f&&!ae){let x=w1();x?Mc(x,f):ng(f,Rt??void 0);return}let h=u.clipboardData?.getData("text/plain")||void 0;if(ae&&h!==void 0){ae.handleInput({inputType:"insertFromPaste",data:h});return}Ec(h)},Fx=u=>{u.code==="Space"&&(m=!1,xt(at(cc())))},Bx=u=>{if(!fe)return;u.preventDefault(),v&&mc();let f=C.pointerPoint(u),h=C.screenToDocument(f),x=yo(h),y=r1(h),S=C.hitTest(h),E=S!==null&&r.some(L=>Ke(n.root,S).includes(L));x===null?E||he([]):r.includes(x)||he([x]);let A=(t.menuExtras?.(r)??[]).map(L=>"separator"in L?L:{...L,id:`${Pm}${L.id}`});fe.open(f,sm(o1(y),A))};function r1(u){let{locked:f}=$t(),h=[];for(let x of[...C.getScene().items].reverse()){if(!f.has(x.id)||!C.hitTest(u,S=>S===x.id))continue;let y=js(n.root,x.id,"locked");y!==void 0&&!h.includes(y)&&h.push(y)}return h}function o1(u=[]){let f=r.length===1?z(n.root,r[0]):void 0,h=[];if(f){let x=f;for(let y of Vt(f)){let S=x[y];S===void 0||!ve(S)||md(S).kind!=="literal"&&h.push({prop:y,source:`=${S.expr}`})}}return{count:r.length,hasGroup:r.some(x=>{let y=z(n.root,x);return y!==void 0&&Ne(y)}),canPaste:Dm!==null,isText:r.length===1&&z(n.root,r[0])?.type==="text",isVector:ge().length===1&&z(n.root,ge()[0])?.type==="vector",convertible:_x(),...t.merge===void 0?{}:{mergeable:Sx()},mask:Gk(),bound:h,lock:R.lock?r.every(x=>$t().locked.has(x))?"unlock":"lock":null,hide:R.hide?r.every(x=>$t().hidden.has(x))?"show":"hide":null,locksHere:u,anyLocked:Nc("locked").length>0,hiddenCount:Nc("hidden").length,components:s1()}}function s1(){let u=r.length===1?r[0]:void 0,f=u===void 0?void 0:ug(u),h=f===void 0?void 0:z(n.root,f),x=0;if(u!==void 0&&f!==void 0&&h?.type==="instance"){let y=h.overrides??{};x=u===f?Object.keys(y).length:y[u.slice(f.length+1)]===void 0?0:1}return{create:Vi(n,r),instance:h?.type==="instance"&&u===f,part:f!==void 0&&u!==f,component:u!==void 0&&Hn(n,u),overrides:x,uses:Ud(n,r.filter(y=>Hn(n,y)))}}function i1(u){if(e.focus({preventScroll:!0}),u.startsWith(Pm)){t.onMenuCommand?.(u.slice(Pm.length),[...r]);return}if(u.startsWith("unlock:")){_o([u.slice(7)],"locked",!1);return}if(u.startsWith("detach:")){let f=u.slice(7),h=r[0];h!==void 0&&hg(h,f);return}switch(u){case"copy":So();return;case"cut":tg();return;case"editText":{let f=r[0];f!==void 0&&Ps(f);return}case"editPoints":{let f=r[0];f!==void 0&&Mr(f);return}case"toVector":return xc();case"mask":vc();return;case"releaseMask":wc();return;case"crop":r.length===1&&ba(r[0]);return;case"merge:union":case"merge:subtract":case"merge:intersect":case"merge:exclude":bc(u.slice(6));return;case"duplicate":return Cc();case"paste":return Ec();case"group":return $c();case"ungroup":return Oc();case"createComponent":Rc();return;case"detachInstance":return Ic();case"goToComponent":{let f=r[0];f!==void 0&&lg(f);return}case"resetOverrides":{let f=r[0];f!==void 0&&cg(f);return}case"placeInstance":{let f=r[0];f!==void 0&&Fc(f);return}case"front":case"forward":case"backward":case"back":return Tc(u);case"delete":return Mo();case"selectAll":return Dc();case"toggleLock":return Eo(r,"locked");case"toggleHidden":return Eo(r,"hidden");case"unlockAll":return Ma("locked");case"showAll":return Ma("hidden");case"fit":return Ax();case"zoom100":return $x()}}let Vx=u=>{if(w||o!=="select"||m||H)return;let f=C.screenToDocument(C.pointerPoint(u)),h=C.hitTest(f,A=>!$t().locked.has(A));if(h===null)return;let x=Ea().find(A=>A.id===h);if(x){u.preventDefault(),k1(x);return}let y=z(n.root,h);if(y?.type==="text"){u.preventDefault(),Ps(h,f);return}if(y?.type==="vector"){u.preventDefault(),Mr(h);return}if(yo(f)===h&&ba(h)){u.preventDefault();return}let S=Ke(n.root,h),E=_===null?1:S.indexOf(_)+1;for(let A=Math.max(E,1);A<S.length;A+=1){let L=S[A];if(L===void 0)break;let U=z(n.root,L);if(!(!U||!Bs(U))){u.preventDefault(),Lc(L),he([S[A+1]??L]);return}}},Hx=u=>Array.from(u.dataTransfer?.types??[]).includes("Files"),Ux=()=>t.importImage!==void 0||t.importAudio!==void 0||t.importVideo!==void 0,zx=u=>Array.from(u.dataTransfer?.types??[]).includes(Pu),jx=u=>{if(zx(u)){u.preventDefault(),u.dataTransfer&&(u.dataTransfer.dropEffect="copy");return}if(!Hx(u)||!Ux())return;u.preventDefault(),u.dataTransfer&&(u.dataTransfer.dropEffect="copy");let f=C.screenToDocument(C.pointerPoint(u)),h=og(f)?.id??null;h!==l&&(l=h,ce())},Kx=u=>{u.relatedTarget instanceof Node&&e.contains(u.relatedTarget)||l!==null&&(l=null,ce())},Gx=u=>{if(zx(u)){u.preventDefault();let A=u.dataTransfer?.getData(Pu)??"";e.focus({preventScroll:!0}),Fc(A,C.screenToDocument(C.pointerPoint(u)));return}if(!Hx(u)||!Ux())return;u.preventDefault();let f=C.screenToDocument(C.pointerPoint(u)),h=og(f);l=null,ce();let x=Array.from(u.dataTransfer?.files??[]),y=x.find(Db);if(y&&t.importAudio){let A=Xn(f),L=A===null?void 0:Ut(n).get(A),U=Jd(n),W=L!==void 0&&U.includes(L)?L:Zd(n,r,null)??L??null;W!==null&&rg(y,W);return}let S=x.find($b);if(S&&t.importVideo){y1(S,f,v1(f));return}if(!t.importImage)return;let E=x.find(A=>A.type.startsWith("image/"));E&&(h?Mc(h,E):ng(E,f))},qx=()=>{Rt=null,d=null,!v&&(s===null&&Q===null&&Te===null||(s=null,Q=null,Te=null,ce()))};function Wx(){let u=ge().length===1?ge()[0]:void 0,f=u===void 0?void 0:z(n.root,u);return u!==void 0&&f&&!me(f)?Wn(u):0}function a1(u){if(m){xt(at("grab"));return}if(H){Ft(null),xt(at("arrow"));return}if(o!=="select"){if(Ft(null),_c(null),ka(null),xt(at(o==="text"?"text":"crosshair")),o==="line"||i!==null){let S=o==="line"?fa(C.screenToDocument(u),null,rA):null;(S?.at.x!==i?.at.x||S?.at.y!==i?.at.y)&&(i=S,ce())}return}let f=ge().length===1?ge()[0]:null;if(f!==null){let S=G.hitAdjuster(u);if(S){let E=z(n.root,f),A=E?eu(E,S.id):void 0;Ft(null);let L=A&&E?A.propOf(E,S.id,!1):void 0;_c(L===void 0?null:{id:S.id,prop:L}),xt(at("radius",{badge:L===void 0?"none":ac(f,[L])}));return}_c(null)}if(ge().length>0){let S=G.hitHandle(u);if(S){Ft(null);let L=Id(S.handle);xt(at("resize",{angle:mp(S.handle)+Wx(),badge:sx(Ls(),L)}));return}let E=G.hitPageLabel(u);if(E!==null){Ft(E),xt(at("arrow"));return}let A=G.hitRotate(u);if(A!==null){Ft(null),xt(at("rotate",{angle:j2[A]+Wx()}));return}}let h=G.hitPageLabel(u);if(h!==null){d=null,Ft(h),xt(at("arrow"));return}if(ge().length>1){if(G.hitRing(u)!==null){Ft(null),ka(null),xt(at("grab"));return}let E=G.hitSpacer(u),A=E===null?null:bu(E);if(E!==null&&A){Ft(null),ka(E),xt(at("resize",{angle:A.axis==="x"?0:90,badge:sx(Ls(),[A.axis])}));return}ka(null)}let x=C.screenToDocument(u),y=yo(x);d=d1(x,y),Ft(y),ce(),xt(at("arrow",{badge:y===null?"none":ac(y,["x","y"])}))}function d1(u,f){let h=C.hitTest(u);if(h===null||!$t().locked.has(h))return null;let x=js(n.root,h,"locked");return x===void 0?null:f===null||Ke(n.root,x).includes(f)?x:null}function Ft(u){s!==u&&(s=u,ce())}function _c(u){Q?.id!==u?.id&&(Q=u,ce())}function ka(u){Te!==u&&(Te=u,ce())}function xt(u){e.style.cursor!==u&&(e.style.cursor=u)}function Mn(u){o!==u&&(o=u,J&&u!=="pen"&&ga(),u!=="select"&&Rs(),ee?.setTool(o),u!=="select"&&Ft(null),xt(at(cc())),ke("tool",o))}function u1(u){if(u.length===0)return null;if(u.length>1)return Wt(u.map(x=>x.frame))??null;let f=u[0],h=Le(n.root,f.id);return h?ro(h.id,n,C.getResolution())??null:null}function Xx(u,f,h){let x=Sa(oo(n,hc(ua(r),u,f)));x.length!==0&&pe([...x,...fs(n,x,Xr(n),Pe(n))],h)}function Sa(u,f=n){if(u.length===0)return[...u];let h=Ye(f.root).links;if(h.size===0)return[...u];let x=new Set(u.flatMap(A=>A.op==="set"?[A.id]:[])),y=Pe(f),S=Pe(Ae(f,u).document),E=[];for(let[A,L]of h){if(A===M||!x.has(A)||x.has(L))continue;let U=y.nodes.get(A),W=S.nodes.get(A),X=y.nodes.get(L);if(!U||!W||!X)continue;let ie={x:U.absX,y:U.absY,w:U.w,h:U.h},re={x:W.absX,y:W.absY,w:W.w,h:W.h},xe=U.values.rotation??0,ue=W.values.rotation??0;if(ie.x===re.x&&ie.y===re.y&&ie.w===re.w&&ie.h===re.h&&xe===ue)continue;let We={x:X.absX,y:X.absY,w:X.w,h:X.h},Ot={x:X.absX-X.x,y:X.absY-X.y},Tt=X.values.rotation??0,Co=je(Re(We),Re(ie),-xe),I1={x:Co.x-We.w/2,y:Co.y-We.h/2,w:We.w,h:We.h},Us=Kd(I1,Tt-xe,ie,re),wg=je(Re(Us),Re(re),ue);E.push({nodeId:L,prop:"x",from:X.x,to:Z(wg.x-Us.w/2-Ot.x)},{nodeId:L,prop:"y",from:X.y,to:Z(wg.y-Us.h/2-Ot.y)},{nodeId:L,prop:"w",from:X.w,to:Z(Us.w)},{nodeId:L,prop:"h",from:X.h,to:Z(Us.h)}),ue!==xe&&E.push({nodeId:L,prop:"rotation",from:Tt,to:Wo(Tt+ue-xe)})}return E.length===0?[...u]:[...u,...oo(f,E)]}function Yx(u){let f=Bi(n,r,C.getResolution()),h=u1(f);h&&Xx(Qd(u),Rp(f,h,u),Y2[u])}function Jx(u){let f=Bi(n,r,C.getResolution());if(f.length<3)return null;let h=xm(f,u),x=gm(h);return x===null?null:{gap:x,series:h}}function Zx(u){let f=Jx(u);f&&Xx(u,wu(f.series,f.gap),u==="x"?"Distribute horizontally":"Distribute vertically")}function c1(){let u=Gi(n,[...r,...ms(n,r)]);if(u.length===0)return null;let f=C.getResolution(),h={};for(let x of u)de(x,y=>{let S=f.nodes.get(y.id)?.values;S&&(h[y.id]=S)});return{nodes:u,tokens:n.tokens,fonts:n.fonts,resolved:h}}function l1(u){return new Map(Object.entries(u.resolved))}function f1(u){let f=Object.entries(u.tokens).filter(([h])=>n.tokens[h]===void 0).map(([h,x])=>({op:"setToken",name:h,value:x}));for(let[h,x]of Object.entries(u.fonts))n.fonts[h]===void 0&&f.push({op:"setFont",name:h,family:x});return f}function Qx(u,f,h){let x=f1(u),y=x.length>0?Ae(n,x).document:n,S=mb(y,u.components??[],ie=>dg(`This file already has a component called ${ie}, and it is not the same as the one you copied. Use the one in this file? Cancel brings yours in beside it as a separate component.`));S.ops.length>0&&(x.push(...S.ops),y=Ae(y,S.ops).document);let E=Jh(u,y),A=E.remap,L=E.nodes.map(ie=>jd(ie,S));if(L.length===0)return null;L.forEach((ie,re)=>{let xe=u.nodes[re];if(!xe)return;let ue=f(xe,re,y),De={op:"insert",parent:ue.parent,index:ue.index,node:ie};x.push(De),y=Ae(y,[De]).document});let U=kp(y,A,l1(u),h);U.length>0&&(y=Ae(y,U).document);let W=p1(L),X=Ye(y.root).shapes;return{ops:[...x,...U,...ps(n,y)],ids:[...A.values()].filter(ie=>W.has(ie)&&!X.has(ie))}}function p1(u){let f=new Set;for(let h of u)f.add(h.id);return f}function eg(u){let f=c1();return f?Qx(f,(h,x,y)=>{let S=Le(y.root,h.id)??y.root,E=te(S).findIndex(A=>A.id===h.id);return{parent:S.id,index:E===-1?te(S).length:E+1}},u):null}function So(){let u=Xh(n,r,C.getResolution());return u!==null&&(Dm=u),u}function tg(){if(r.some(f=>Je(n,f)))return So();let u=So();return u!==null&&(r=[...r,...ms(n,r)],Mo()),u}function h1(u){let f=[];for(let h of u.nodes){let x=u.resolved[h.id];if(!x)continue;let{x1:y,y1:S,x2:E,y2:A}=x,L=y!==void 0&&S!==void 0&&E!==void 0&&A!==void 0?fi({x1:y,y1:S,x2:E,y2:A}):x,{x:U,y:W,w:X,h:ie}=L;U===void 0||W===void 0||X===void 0||ie===void 0||f.push({x:U,y:W,w:X,h:ie})}return Wt(f)??null}function Ec(u,f){let h=Yh(u??Dm??"");if(!h)return;let x=f??Rt,y=h1(h),S=m1(h),E=L=>Qx(h,(U,W,X)=>({parent:L,index:te(z(X.root,L)??X.root).length}),x1(h,L,y,x)),A=E(S);A&&S!==_a()&&g1(A.ops)&&(A=E(_a())),A&&(pe(A.ops,A.ids.length===1?"Paste":`Paste ${A.ids.length} elements`),he(A.ids))}function _a(){return Jn(_??n.root.id)}function m1(u){if(u.nodes.some(y=>y.type==="frame"&&y.component===!0))return n.root.id;if(_!==null||r.length===0)return _a();let f=new Set(u.nodes.map(y=>y.id)),h=r.length===1?z(n.root,r[0]):void 0;if(h?.type==="frame"&&!f.has(h.id))return Jn(h.id);let x=new Set(r.map(y=>Le(n.root,y)?.id??n.root.id));return x.size!==1?_a():Jn([...x][0])}function x1(u,f,h,x){let y={x:Tu,y:Tu};if(!h)return y;let S={x:h.x+h.w/2,y:h.y+h.h/2},E=f===n.root.id?void 0:wt(f);return E?x!==null&&x.x>=E.absX&&x.x<=E.absX+E.w&&x.y>=E.absY&&x.y<=E.absY+E.h?{x:x.x-E.absX-S.x,y:x.y-E.absY-S.y}:u.nodes.some(W=>Le(n.root,W.id)?.id===f)?y:h.x>=0&&h.y>=0&&h.x+h.w<=E.w&&h.y+h.h<=E.h?{x:0,y:0}:{x:E.w/2-S.x,y:E.h/2-S.y}:x?{x:x.x-S.x,y:x.y-S.y}:y}function g1(u){let f=h=>Gs(h).filter(x=>x.code==="component-cycle").length;return f(Ae(n,u).document.root)>f(n.root)}async function ng(u,f){let h=t.importImage;if(!h)return;let x=await Yd(u,t.maxImageEdge??2560);if(!x)return;let y=await h(new File([x.bytes],u.name,{type:x.type}));if(!y)return;let S=Jn((f?Xn(f):void 0)??_??n.root.id),E=z(n.root,S)??n.root,A=Yt(S),L=C.getResolution().nodes.get(S),{w:U,h:W}=Np(x.width,x.height,L?.w&&L.w>0?L.w:x.width,L?.h&&L.h>0?L.h:x.height),X=f??Rt,ie=Math.round((X?X.x-U/2:A.x)-A.x),re=Math.round((X?X.y-W/2:A.y)-A.y),xe=sg(n,u.name),ue=pn(n.root,"image");pe([{op:"setAsset",name:xe,value:y},{op:"insert",parent:S,index:te(E).length,node:ol({id:ue,x:ie,y:re,w:U,h:W,src:xe,fit:"cover"})}],"Place image"),he([ue])}async function y1(u,f,h){let x=t.importVideo;if(!x)return;let y=await Tb(u),S=u.type===""?new File([u],u.name,{type:Ob(u)}):u,E=await x(S,y?.ms);if(!E)return;if(h){pe([{op:"setAsset",name:h.src,value:E}],"Place video"),he([h.id]);return}let A=sg(n,u.name),L=Jn(Xn(f)??_??n.root.id),U=z(n.root,L)??n.root,W=Yt(L),X=C.getResolution().nodes.get(L),ie=y?.width??1920,re=y?.height??1080,{w:xe,h:ue}=Np(ie,re,X?.w&&X.w>0?X.w:ie,X?.h&&X.h>0?X.h:re),De=pn(n.root,"video");pe([{op:"setAsset",name:A,value:E},{op:"insert",parent:L,index:te(U).length,node:rl({id:De,x:Math.round(f.x-xe/2-W.x),y:Math.round(f.y-ue/2-W.y),w:xe,h:ue,src:A,fit:"cover",muted:!0})}],"Place video"),he([De])}async function rg(u,f){let h=t.importAudio;if(!h)return!1;let x=await h(u);return x?(pe(Rb(n,f,Nb(n,f,u.name),x),"Add music"),!0):!1}function Ea(){return t.importImage?Sv(n,$t().hidden):[]}function b1(){return Ea().flatMap(u=>{let f=qe(u.id);return f?[{frame:f,label:u.label,target:u.id===l}]:[]})}function v1(u){let f=null;return de(n.root,h=>{if(h.type!=="video"||typeof h.src!="string"||h.src===""||n.assets[h.src]!==void 0)return;let x=qe(h.id);x!==void 0&&Mt(x,u.x,u.y)&&(f=h)}),f}function og(u){return Ea().filter(h=>{let x=qe(h.id);return x!==void 0&&Mt(x,u.x,u.y)}).at(-1)??null}function w1(){return r.length!==1?null:Ea().find(u=>u.id===r[0])??null}async function Mc(u,f){let h=t.importImage;if(!h)return;let x=await Yd(f,t.maxImageEdge??2560);if(!x)return;let y=await h(new File([x.bytes],f.name,{type:x.type}));!y||n.assets[u.src]!==void 0||(pe([{op:"setAsset",name:u.src,value:y}],"Add image"),he([u.id]))}function k1(u){let f=e.ownerDocument.createElement("input");f.type="file",f.accept="image/*",f.addEventListener("change",()=>{let h=f.files?.[0];h&&Mc(u,h)}),f.click()}function sg(u,f){let h=f.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"image";if(u.assets[h]===void 0)return h;for(let x=2;;x+=1){let y=`${h}-${x}`;if(u.assets[y]===void 0)return y}}function Cc(){if(r.some(f=>Je(n,f)))return;let u=eg(S1());u&&(pe(u.ops,u.ids.length===1?"Duplicate":`Duplicate ${u.ids.length} elements`),he(u.ids))}function S1(){let u={x:Tu,y:Tu},f=r.length===1?r[0]:void 0;if(f===void 0||!Hn(n,f))return u;let h=C.getResolution(),x=h.nodes.get(f);if(!x)return u;let y=Hi(n,h);return{x:y.x-x.absX,y:y.y-x.absY}}function Ac(u,f){if(u.length===0)return;let h=Ae(n,u).document;pe([...u,...ps(n,h)],f)}function $c(){if(r.some(f=>Je(n,f)))return;let u=yp(n,r);u&&(Ac(u.ops,"Group"),he([u.groupId]))}function Oc(){let u=r.filter(y=>{let S=z(n.root,y);return S!==void 0&&Ne(S)&&!Je(n,y)});if(u.length===0)return;let f=n,h=[],x=[];for(let y of u){let S=z(f.root,y);S&&x.push(...te(S).map(A=>A.id));let E=bp(f,y);E.length!==0&&(h.push(...E),f=Ae(f,E).document)}_!==null&&u.includes(_)&&(_=null),Ac(h,u.length===1?"Ungroup":`Ungroup ${u.length} groups`),he(x)}function Tc(u){r.some(f=>Je(n,f))||Ac(vp(n,r,u),tA[u])}function _1(u,f,h){let x=z(n.root,f);if(!x||!me(x))return;let y=new Set(Ke(n.root,f));if(x.type==="instance"||Je(n,f)||f!==n.root.id&&u.some(ue=>Hn(n,ue)))return;let S=u.filter(ue=>ue!==n.root.id&&z(n.root,ue)&&!y.has(ue)&&!Je(n,ue)),E=fr(n.root,f),A=[...S,...qh(n,S).filter(ue=>fr(n.root,ue)!==E&&!y.has(ue))];if(A.length===0)return;let L=new Set(A),U=te(x).filter(ue=>!L.has(ue.id))[h]?.id,W=[],X=n;for(let ue of A){let De=te(z(X.root,f)??X.root).filter(Tt=>Tt.id!==ue),We=U===void 0?-1:De.findIndex(Tt=>Tt.id===U),Ot={op:"move",id:ue,parent:f,index:We===-1?De.length:We};W.push(Ot),X=Ae(X,[Ot]).document}if(A.every(ue=>M1(n,X,ue)))return;let ie=new Set(A.filter(ue=>Le(n.root,ue)?.id!==f).flatMap(ue=>wx(ue,X))),re=[];for(let ue of A){let De=ig(n,ue),We=ig(X,ue),Ot={x:De.x-We.x,y:De.y-We.y};if(!(Ot.x===0&&Ot.y===0))for(let Tt of no(ue,X)){let Co=an(Tt);Co&&(re.push({op:"set",id:Tt,prop:"x",value:Z(Co.x+Ot.x)}),re.push({op:"set",id:Tt,prop:"y",value:Z(Co.y+Ot.y)}))}}let xe=Ae(X,re).document;pe([...W,...re,...ps(n,xe,ie)],A.length===1?`Move ${A[0]}`:`Move ${A.length} layers`)}function E1(u={}){let f=n.root.children,h=f.filter(ue=>ue.type==="frame"&&ue.component!==!0),x=h.find(ue=>ue.id===u.after),y=C.getResolution(),S=x?y.nodes.get(x.id):void 0,E=S&&S.w>0?S.w:zv.w,A=S&&S.h>0?S.h:zv.h,L=null,U=-1/0;for(let ue of h.length>0?h:f){let De=y.nodes.get(ue.id);!De||De.absX+De.w<=U||(U=De.absX+De.w,L={x:U+H2,y:De.absY})}let W=L??{x:0,y:0},X=x??h[h.length-1],ie=X?f.indexOf(X)+1:f.length,re=pn(n.root,"frame"),xe=x?.type==="frame"?x.background:void 0;return pe([{op:"insert",parent:n.root.id,index:ie,node:Va({id:re,x:Z(W.x),y:Z(W.y),w:Z(E),h:Z(A),background:xe??Uv,children:[]})}],"Add frame"),he([re]),re}function M1(u,f,h){let x=Le(u.root,h),y=Le(f.root,h);return x?.id===y?.id&&x?.children.findIndex(S=>S.id===h)===y?.children.findIndex(S=>S.id===h)}function ig(u,f){let h=Ke(u.root,f).slice(0,-1).reverse(),x=Pe(u);for(let y of h){let S=z(u.root,y);if(!S||Ne(S))continue;let E=x.nodes.get(y);return E?{x:E.absX,y:E.absY}:{x:0,y:0}}return{x:0,y:0}}function Lc(u){let f=z(n.root,u);!f||!Bs(f)||(_=u,ce())}function Pc(){if(_===null)return;let u=_;_=Lx(u),he([u])}function Dc(){let u=z(n.root,_??n.root.id)??n.root,f=Ye(n.root).shapes;he(te(u).map(h=>h.id).filter(h=>It(h)&&!f.has(h)))}let C1={locked:["Lock","Unlock"],hidden:["Hide","Show"]};function ag(u){return u==="locked"?$t().locked:$t().hidden}function _o(u,f,h){let x=u.filter(E=>E!==n.root.id&&z(n.root,E)),y=h?x.filter(E=>!ag(f).has(E)):[...new Set(x.flatMap(E=>{let A=js(n.root,E,f);return A===void 0?[]:[A]}))];if(y.length===0)return;let S=C1[f][h?0:1];pe(y.map(E=>({op:"set",id:E,prop:f,value:h?!0:void 0})),y.length===1?`${S} ${y[0]}`:`${S} ${y.length} layers`)}function Eo(u,f){u.length!==0&&_o(u,f,!u.every(h=>ag(f).has(h)))}function Nc(u){let f=[];return de(n.root,h=>{h[u]===!0&&f.push(h.id)}),f}function Ma(u){let f=Nc(u);if(f.length===0)return;let h=u==="locked"?"Unlock all":"Show all";pe(f.map(x=>({op:"set",id:x,prop:u,value:void 0})),h)}function A1(u){R={...Xv,...u},fe?.close()}function Mo(){let u=r.filter(L=>L!==n.root.id),f=u.filter(L=>Je(n,L)),h=u.filter(L=>!Je(n,L)),x=h.filter(L=>Hn(n,L)),y=Ud(n,x);if(y>0){let U=`${x.length===1?x[0]:`${x.length} components`} is used in ${y} ${y===1?"place":"places"}. Delete it and detach ${y===1?"that instance":"those instances"}? Each keeps what it shows.`;if(!dg(U))return}let S=h.filter(L=>!x.includes(L)),E=[...f.map(L=>({op:"set",id:L,prop:"hidden",value:!0})),...x.length>0?Ap(n,x,C.getResolution()):[],...Gh(zb(n,S)),...O1(S),...S.map(L=>({op:"remove",id:L}))];if(E.length===0)return;let A=u.length;he([]),pe(E,A===1?"Delete element":`Delete ${A} elements`)}function $1(u,f){if(z(n.root,u)?.type!=="connector")return;let x=wt(u)?.values??{},[y,S]=f==="start"?["x1","y1"]:["x2","y2"];pe([{op:"set",id:u,prop:y,value:Z(x[y]??0)},{op:"set",id:u,prop:S,value:Z(x[S]??0)}],"Detach end")}function O1(u){let f=new Set;for(let x of u){let y=z(n.root,x);y&&de(y,S=>{f.add(S.id)})}let h=[];for(let[x,y]of In(n)){if(f.has(x))continue;let S=wt(x)?.values??{};for(let[E,A,L]of[["start","x1","y1"],["end","x2","y2"]]){let U=y[E];U===void 0||!f.has(U)||h.push({op:"set",id:x,prop:A,value:Z(S[A]??0)},{op:"set",id:x,prop:L,value:Z(S[L]??0)})}}return h}function dg(u){if(t.confirm)return t.confirm(u);let f=e.ownerDocument.defaultView;return typeof f?.confirm=="function"?f.confirm(u):!0}function Bs(u){return Ne(u)||u.type==="instance"}function Jn(u){let f=Ke(n.root,u),h=f.findIndex(x=>z(n.root,x)?.type==="instance");return h<=0?u:f[h-1]}function Rc(u=r){let f=Sp(n,[...u,...ms(n,u)],C.getResolution());return f?(_=null,pe(f.ops,"Create component"),he([f.instanceId]),f.flattened.length>0&&ke("notice",{message:`Made ${f.componentId}. ${f.flattened.length===1?"One position":`${f.flattened.length} positions`} measured from the page became numbers so the page looks the same: ${f.flattened.join(", ")}.`}),f.instanceId):null}function Ic(u=r){let f=u.filter(S=>z(n.root,S)?.type==="instance"),h=[],x=n,y=C.getResolution();for(let S of f){let E=Hd(x,S,y);E&&(h.push(...E),x=Ae(x,E).document)}h.length!==0&&(_!==null&&f.includes(_)&&(_=null),pe(h,f.length===1?"Detach instance":`Detach ${f.length} instances`),he(f.filter(S=>z(n.root,S)!==void 0)))}function ug(u){return z(n.root,u)?.type==="instance"&&!Je(n,u)?u:Lt(n.root,u)?.instance.id}function cg(u,f){let h=ug(u);if(h===void 0)return;let x=f??(h===u?void 0:u);pe(_p(n,h,x),x===void 0?"Reset overrides":"Reset part")}function T1(u,f){pe(Ep(n,u,f),`Swap to ${f}`)}function lg(u){let f=z(n.root,u),h=f?.type==="instance"?f:Ba(n.root,u);if(h?.type!=="instance")return;let x=z(n.root,h.component);x&&(_=null,he([x.id]),At([x.id]))}function Fc(u,f){let h=z(n.root,u);if(h?.type!=="frame"||h.component!==!0)return null;let x=f??L1(),y=Xn(x)??n.root.id,S=Yt(y),E=wt(u),A=Cp(n,u,y,{x:Math.round(x.x-S.x-(E?.w??0)/2),y:Math.round(x.y-S.y-(E?.h??0)/2)});return A?(pe(A.ops,`Place ${u}`),he([A.id]),A.id):null}function L1(){let u=e.getBoundingClientRect();return C.screenToDocument({x:u.width/2,y:u.height/2})}function Vs(){ht=null;let u=D.undo();u&&ax(u.ops,`Undo ${u.entry.label}`),fg()}function Hs(){ht=null;let u=D.redo();u&&ax(u.ops,`Redo ${u.entry.label}`),fg()}function fg(){if(!ae)return;let{anchor:u,head:f}=ae.getSelection();ae.setSelection(u,f)}function P1(u){if(!D.isTail(u))return!1;for(let f=u.length;f>0;f-=1)Vs();return!0}function pg(u,f,h,x){let y=z(n.root,u);if(!y)return;let S=y[f];if(sA(S,h))return;let E={op:"set",id:u,prop:f,value:h},A=st(y)&&Z2.has(f);pe(A?Sa([E]):[E],x??`Set ${f}`)}function D1(u,f){let h=n.brand?.theme==="dark"?n.themes?.dark:void 0;if(h!==void 0&&u in h){if(h[u]===f)return;pe([{op:"setTheme",value:{...n.themes,dark:{...h,[u]:f}}}],`Set $${u} in dark`);return}n.tokens[u]!==f&&pe([{op:"setToken",name:u,value:f}],`Set $${u}`)}function N1(u){u in n.tokens&&pe([{op:"setToken",name:u,value:void 0}],`Remove $${u}`)}function hg(u,f){let h=wt(u)?.values[f];h!==void 0&&pe([{op:"set",id:u,prop:f,value:Z(h)}],`Detach ${f}`)}function R1(u){let f=z(n.root,_??n.root.id)??n.root,h=[],x=Ye(n.root).shapes;for(let y of te(f)){if(!It(y.id)||x.has(y.id))continue;let S=qe(y.id);S&&xp(S,u)&&h.push(y.id)}return h}function St(u){typeof e.setPointerCapture=="function"&&e.setPointerCapture(u)}function Bc(u){e.hasPointerCapture?.(u)&&e.releasePointerCapture(u)}let mg=u=>{ae&&(px(),ae.handleKey(u)&&(u.preventDefault(),u.stopPropagation()))},xg=u=>{ae&&(u.preventDefault(),px(),ae.handleInput(u))},gg=()=>ae?.handleCompositionStart(),yg=u=>ae?.handleCompositionUpdate(u.data??""),bg=u=>ae?.handleCompositionEnd(u.data??""),vg=u=>{if(!e.ownerDocument.hasFocus())return;let f=u.relatedTarget;f instanceof Element&&f.closest("[data-vd-keeps-text]")||_r("blur")};return se.addEventListener("keydown",mg),se.addEventListener("beforeinput",xg),se.addEventListener("compositionstart",gg),se.addEventListener("compositionupdate",yg),se.addEventListener("compositionend",bg),se.addEventListener("blur",vg),e.addEventListener("pointerdown",Mx),e.addEventListener("pointermove",Cx),e.addEventListener("pointerup",va),e.addEventListener("pointercancel",va),e.addEventListener("pointerup",da),e.addEventListener("pointercancel",da),e.addEventListener("pointerleave",qx),e.addEventListener("dblclick",Vx),e.addEventListener("contextmenu",Bx),e.addEventListener("keydown",Px),e.addEventListener("keyup",Fx),e.addEventListener("copy",Nx),e.addEventListener("cut",Rx),e.addEventListener("paste",Ix),e.addEventListener("dragover",jx),e.addEventListener("dragleave",Kx),e.addEventListener("drop",Gx),k=!0,ee?.setTool(o),ee?.setHistory(!1,!1),ee?.setZoom(C.getCamera().zoom),xt(at(cc())),t.autoFit&&!t.camera&&Ge(()=>C.fitToContent()),t.history&&(D.restore(t.history),ee?.setHistory(D.canUndo,D.canRedo)),t.selection&&t.selection.length>0&&he(t.selection),ce(),{element:e,viewer:C,getDocument:()=>n,update(u){n=u,C.update(n),he(r),ce(),ke("problems",dc())},applyOps:(u,f)=>pe(u,f??"Apply changes"),setDocument:(u,f)=>pe(Cl(n,fp(u,n.root.id)),f??"Replace document"),getSelection:()=>r,setSelection:he,selectAll:Dc,deleteSelection:Mo,detachEnd:$1,lock:u=>_o(u??r,"locked",!0),unlock:u=>_o(u??r,"locked",!1),toggleLock:u=>Eo(u??r,"locked"),unlockAll:()=>Ma("locked"),hide:u=>_o(u??r,"hidden",!0),show:u=>_o(u??r,"hidden",!1),toggleHidden:u=>Eo(u??r,"hidden"),showAll:()=>Ma("hidden"),isLocked:u=>$t().locked.has(u),isHidden:u=>$t().hidden.has(u),setFeatures:A1,getFeatures:()=>R,moveLayers:_1,addFrame:E1,copy:So,cut:tg,paste:Ec,duplicate:Cc,group:$c,ungroup:Oc,reorder:Tc,scaleSelection:_k,getSpacing:Ak,setSpacing:Ck,align:Yx,distribute:Zx,canDistribute:u=>Jx(u)!==null,editText:Ps,endTextEditing:()=>_r("done"),getEditingText:()=>ae?.id??null,formatText:u=>ae?.format(u),getTextFormat:()=>ae?.activeMark()??{},getTextSelectionRects:lx,getTextRange:()=>{if(!ae)return null;let{anchor:u,head:f}=ae.getSelection();return{from:Math.min(u,f),to:Math.max(u,f)}},createComponent:Rc,detachInstance:Ic,resetOverrides:cg,swapComponent:T1,goToComponent:lg,placeInstance:Fc,getEnteredGroup:()=>_,enterGroup:Lc,exitGroup:Pc,getTool:()=>o,editPoints:Mr,stopEditingPoints:Rs,getPointEditing:()=>H?.id??null,convertToVector:u=>xc(u),merge:(u,f)=>bc(u,f),canMerge:u=>Sx(u),offersMerge:()=>t.merge!==void 0,mergeRefusal:()=>yc(),formatKeys:u=>(t.formatKeys??so)(u),mask:u=>vc(u),maskRefusal:u=>{let f=Is(u);return f.ok?void 0:f.why},maskedIn:u=>ya(u),releaseMask:u=>wc(u),crop:u=>ba(u),stopCropping:()=>{kc()},getCropping:()=>M,setTool:Mn,beginEdit:rk,endEdit:ix,undo:Vs,redo:Hs,canUndo:()=>D.canUndo,canRedo:()=>D.canRedo,getHistory:()=>D.snapshot(),setProperty:pg,fontFamilies:()=>{let u=new Map;for(let f of t.fonts?.faces()??[]){let h=u.get(f.family)??{weights:new Set,italic:!1};h.weights.add(f.weight),f.style==="italic"?h.italic=!0:(h.css===void 0||f.weight===400)&&(h.css=f.id),u.set(f.family,h)}return[...u.entries()].sort(([f],[h])=>f.localeCompare(h)).map(([f,h])=>({family:f,weights:[...h.weights].sort((x,y)=>x-y),italic:h.italic,...h.css===void 0?{}:{css:h.css}}))},assetUrl:u=>{let f=n.assets[u];return f?t.resolveAsset?.(f,u):void 0},addMusic:rg,canAddMusic:()=>t.importAudio!==void 0,setToken:D1,removeToken:N1,bindingsOf:nk,unbind:hg,getResolution:()=>C.getResolution(),getCamera:()=>C.getCamera(),getProblems:dc,on:ye,reveal:At,panBy:Qw,setPresence(u,f){c={ids:[...u],label:f??null},ce()},setHighlight(u){u.length===0&&p.length===0||(p=[...u],ce())},isHistoryTail:u=>D.isTail(u),undoTail:P1,historyTop:()=>D.top,destroy(){Ue(),e.removeEventListener("pointerup",da),e.removeEventListener("pointercancel",da),e.removeEventListener("pointerdown",Mx),e.removeEventListener("pointermove",Cx),e.removeEventListener("pointerup",va),e.removeEventListener("pointercancel",va),e.removeEventListener("pointerleave",qx),se.removeEventListener("keydown",mg),se.removeEventListener("beforeinput",xg),se.removeEventListener("compositionstart",gg),se.removeEventListener("compositionupdate",yg),se.removeEventListener("compositionend",bg),se.removeEventListener("blur",vg),se.remove(),vo&&clearTimeout(vo),e.removeEventListener("dblclick",Vx),e.removeEventListener("contextmenu",Bx),e.removeEventListener("copy",Nx),e.removeEventListener("cut",Rx),e.removeEventListener("paste",Ix),e.removeEventListener("dragover",jx),e.removeEventListener("dragleave",Kx),e.removeEventListener("drop",Gx),e.removeEventListener("keydown",Px),e.removeEventListener("keyup",Fx),fe?.destroy(),ee?.destroy(),G.destroy(),C.destroy(),P.remove(),$.clear(),e.style.cursor="",e.classList.remove("vd-editor")}}}function sA(e,t){return e===t?!0:ve(e)&&ve(t)?e.expr===t.expr:!1}function Ss(e){return e.metaKey||e.ctrlKey||e.altKey}function Lu(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 m4=new Set(wr);function Ji(e){return e.map(t=>({value:t,label:`${t.charAt(0).toUpperCase()}${t.slice(1)}`}))}var uA=[{value:"nonzero",label:"Non-zero"},{value:"evenodd",label:"Even-odd"}].filter(e=>Ar.includes(e.value)),cA=Ji(tr),Yv=Ji(Zt),lA=Ji($r),fA=[{value:"left",label:"Left",icon:bt("text-left")},{value:"center",label:"Centre",icon:bt("text-center")},{value:"right",label:"Right",icon:bt("text-right")},{value:"justify",label:"Justify",icon:bt("text-justify")}].filter(e=>Qn.includes(e.value)),pA=[{value:"top",label:"Top",icon:bt("text-top")},{value:"middle",label:"Middle",icon:bt("text-middle")},{value:"bottom",label:"Bottom",icon:bt("text-bottom")}].filter(e=>er.includes(e.value)),Im={prop:"x",label:"X",kind:"number",prefix:"X"},Fm={prop:"y",label:"Y",kind:"number",prefix:"Y"},Ru={prop:"w",label:"W",kind:"number",prefix:"W"},Iu={prop:"h",label:"H",kind:"number",prefix:"H"},hA={prop:"rotation",label:"Rotation",kind:"number",icon:"rotate",fallback:"0"},Zv={prop:"opacity",label:"Opacity",kind:"number",icon:"opacity",percent:!0,fallback:"100%"},Du={prop:"radius",label:"Radius",kind:"radius",icon:"radius",span:"wide",fallback:"0"};var _s={heading:"Position",props:[Im,Fm,Ru,Iu,hA,Zv]},Nu={prop:"fill",label:"Fill",kind:"colour"},Fu={prop:"stroke",label:"Stroke",kind:"colour",span:"half"},Bu={prop:"strokeWidth",label:"Stroke width",kind:"number",prefix:"Width",fallback:"0"},Bm={present:"stroke",empty:"No stroke",add:{stroke:"#000000",strokeWidth:1},clear:["stroke","strokeWidth","dash","strokeAlign","cap","join"]},mA=[{value:"center",label:"Centre"},{value:"inside",label:"Inside"},{value:"outside",label:"Outside"}].filter(e=>Ur.includes(e.value)),Qv={prop:"strokeAlign",label:"Stroke position",kind:"select",options:mA,prefix:"Align",span:"half"},Vu={prop:"dash",label:"Dash",kind:"dash",prefix:"Dash",fallback:"Solid",span:"half"},Vm={prop:"cap",label:"Cap",kind:"select",options:cA,prefix:"Cap",span:"half"},xA={prop:"join",label:"Join",kind:"select",options:lA,prefix:"Join",span:"half"},Yi={heading:"Stroke",props:[Fu,Bu,Qv,Vu,Vm],optional:Bm},Jv=Ji(ur),gA=[{heading:"Line",props:[{prop:"start",label:"From",kind:"attachment",prefix:"From"},{prop:"x1",label:"From X",kind:"number",prefix:"X1"},{prop:"y1",label:"From Y",kind:"number",prefix:"Y1"},{prop:"end",label:"To",kind:"attachment",prefix:"To"},{prop:"x2",label:"To X",kind:"number",prefix:"X2"},{prop:"y2",label:"To Y",kind:"number",prefix:"Y2"},{prop:"route",label:"Route",kind:"select",options:Ji(Hr),prefix:"Route",span:"half"},{...Zv,span:"half"},{prop:"start",label:"Start head",kind:"select",options:Jv,prefix:"Start",span:"half"},{prop:"end",label:"End head",kind:"select",options:Jv,prefix:"End",span:"half"}]},{heading:"Stroke",props:[{...Fu,fallback:ci},{...Bu,fallback:String(li)},Vu,Vm]}],x4={instance:[{heading:"Instance",props:[Im,Fm,Ru,Iu]}],connector:gA,frame:[{heading:"Frame",props:[Im,Fm,Ru,Iu,Du,{prop:"clip",label:"Clip content",kind:"toggle"}]},{heading:"Fill",props:[{prop:"background",label:"Fill",kind:"colour"}]},Yi],canvas:[{heading:"Canvas",props:[Ru,Iu,{prop:"background",label:"Fill",kind:"colour"}]}],text:[_s,{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:fA,span:"half"},{prop:"valign",label:"Vertical",kind:"segmented",options:pA,span:"half"}]},{heading:"Fill",props:[Nu]},{heading:"Stroke",props:[Fu,Bu,Vu],optional:Bm},{heading:"Link",props:[{prop:"content",label:"Link",kind:"link",icon:"link"}]}],rect:[{heading:"Position",props:[..._s.props,Du]},{heading:"Fill",props:[Nu]},Yi],ellipse:[_s,{heading:"Fill",props:[Nu]},Yi],image:[{heading:"Position",props:[..._s.props,Du]},{heading:"Image",props:[{prop:"fit",label:"Fit",kind:"select",options:Yv,prefix:"Fit"}]},Yi],video:[{heading:"Position",props:[..._s.props,Du]},{heading:"Video",props:[{prop:"fit",label:"Fit",kind:"select",options:Yv,prefix:"Fit"},{prop:"poster",label:"Poster frame (ms)",kind:"number",prefix:"Poster",fallback:"Start"},{prop:"start",label:"Trim start (ms)",kind:"number",prefix:"In",fallback:"0"},{prop:"end",label:"Trim end (ms)",kind:"number",prefix:"Out",fallback:"End"},{prop:"muted",label:"Muted",kind:"toggle",span:"half"},{prop:"loop",label:"Loop",kind:"toggle",span:"half"}]},Yi],vector:[_s,{heading:"Fill",props:[{...Nu,span:"half"},{prop:"rule",label:"Fill rule",kind:"select",options:uA,prefix:"Rule",span:"half"}]},{heading:"Stroke",props:[Fu,Bu,Qv,Vu,Vm,xA],optional:Bm}]};var g4=Cr.map(e=>({value:e,label:e.split("-").map((t,n)=>n===0?t.charAt(0).toUpperCase()+t.slice(1):t).join(" ")}));function Hu(e,t,n){let r=0;return e<n.left?r|=1:e>n.right&&(r|=2),t<n.top?r|=4:t>n.bottom&&(r|=8),r}function Yu(e,t){let[[n,r],[o,s]]=e,i=Hu(n,r,t),a=Hu(o,s,t);for(;;)if(i|a){if(i&a)return!1;{let{top:d,right:c,bottom:l,left:p}=t,m,g,b=a>i?a:i;b&8?(m=n+(o-n)*(l-r)/(s-r),g=l):b&4?(m=n+(o-n)*(d-r)/(s-r),g=d):b&2?(g=r+(s-r)*(c-n)/(o-n),m=c):b&1&&(g=r+(s-r)*(p-n)/(o-n),m=p),b==i?(n=m,r=g,i=Hu(n,r,t)):(o=m,s=g,a=Hu(o,s,t))}}else return!0}function Gu(e,t){return e.left<=t.right&&t.left<=e.right&&e.top<=t.bottom&&t.top<=e.bottom}function Cs(e,t){return e?{top:Math.min(e.top,t.top),right:Math.max(e.right,t.right),bottom:Math.max(e.bottom,t.bottom),left:Math.min(e.left,t.left)}:t}function Hm(e,t){return e?{top:Math.min(e.top,t[1]),right:Math.max(e.right,t[0]),bottom:Math.max(e.bottom,t[1]),left:Math.min(e.left,t[0])}:{top:t[1],right:t[0],bottom:t[1],left:t[0]}}function Zi(e){return Math.max(e.right-e.left,e.bottom-e.top)}function Qi(e,t){return{top:e[1]-t,right:e[0]+t,bottom:e[1]+t,left:e[0]-t}}function CA(e,t){return{top:e.top-t,right:e.right+t,bottom:e.bottom+t,left:e.left-t}}var ta=class e{constructor(t,n,r=16){this.boundingBox=t,this.depth=n,this.innerNodeCapacity=r,this.subtrees=null,this.pairs=[]}insert(t,n){if(!Gu(t,this.boundingBox))return!1;if(this.subtrees){for(let r=0;r<this.subtrees.length;r++)this.subtrees[r].insert(t,n);return!0}if(this.depth>0&&this.pairs.length>=this.innerNodeCapacity){this.ensureSubtrees();for(let r=0;r<this.pairs.length;r++){let[o,s]=this.pairs[r];for(let i=0;i<this.subtrees.length;i++)this.subtrees[i].insert(o,s)}this.pairs.length=0;for(let r=0;r<this.subtrees.length;r++)this.subtrees[r].insert(t,n);return!0}return this.pairs.push([t,n]),!0}find(t,n=new Set){if(!Gu(t,this.boundingBox))return n;for(let r=0;r<this.pairs.length;r++){let[o,s]=this.pairs[r];Gu(t,o)&&n.add(s)}if(this.subtrees)for(let r=0;r<this.subtrees.length;r++)this.subtrees[r].find(t,n);return n}findOnLineSegment(t,n=new Set){if(!Yu(t,this.boundingBox))return n;for(let[r,o]of this.pairs)Yu(t,r)&&n.add(o);if(this.subtrees)for(let r of this.subtrees)r.findOnLineSegment(t,n);return n}ensureSubtrees(){if(this.subtrees)return;let{top:t,right:n,bottom:r,left:o}=this.boundingBox,s=(this.boundingBox.left+this.boundingBox.right)/2,i=(this.boundingBox.top+this.boundingBox.bottom)/2;this.subtrees=[new e({top:t,right:s,bottom:i,left:o},this.depth-1,this.innerNodeCapacity),new e({top:t,right:n,bottom:i,left:s},this.depth-1,this.innerNodeCapacity),new e({top:i,right:s,bottom:r,left:o},this.depth-1,this.innerNodeCapacity),new e({top:i,right:n,bottom:r,left:s},this.depth-1,this.innerNodeCapacity)]}},ew=typeof process<"u"&&process.env.PATH_BOOL_DEV_ASSERTS;ew==="1"||ew==="0"||typeof process<"u"&&process.env.NODE_ENV;var bw=128,jm=1024,ea=2e4,AA=6,kr=1e-10,tw=1e-16,$A=1e-12,OA=.001,Xt={point:1e-6,linear:1e-4,param:1e-8,collinear:Number.MIN_VALUE*64},TA=50;function LA(e){let t=Number.isFinite(e)&&e>0?Math.min(1,e/TA):1;return{point:Xt.point*t,linear:Xt.linear*t,param:Xt.param,collinear:Xt.collinear}}var Uu=1e-12;function PA(e){let t=e[1],n=e[2],r=e[3],o=e[4],s=-t[0]+3*n[0]-3*r[0]+o[0],i=-t[1]+3*n[1]-3*r[1]+o[1],a=3*t[0]-6*n[0]+3*r[0],d=3*t[1]-6*n[1]+3*r[1],c=-3*t[0]+3*n[0],l=-3*t[1]+3*n[1],p=i*a-s*d,m=s*l-i*c,g=(-3*s*s*l*l+6*s*i*c*l+4*s*a*d*l-4*s*d*d*c-3*i*i*c*c-4*i*a*a*l+4*i*a*d*c)/(s*s*d*d-2*s*i*a*d+i*i*a*a);if(g<0)return null;let b=(m/p+Math.sqrt(g))/2,w=(m/p-Math.sqrt(g))/2;return Uu<=b&&b<=1-Uu&&Uu<=w&&w<=1-Uu?[b,w]:null}var nw=typeof Float32Array<"u"?Float32Array:Array;function DA(e,t){if(e===t){var n=t[1];e[1]=t[2],e[2]=n}else e[0]=t[0],e[1]=t[2],e[2]=t[1],e[3]=t[3];return e}function vw(e,t){var n=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=n,e[2]=-n,e[3]=r,e}function NA(e,t,n){var r=t[0],o=t[1],s=t[2],i=t[3],a=t[4],d=t[5],c=n[0],l=n[1],p=n[2],m=n[3],g=n[4],b=n[5];return e[0]=r*c+s*l,e[1]=o*c+i*l,e[2]=r*p+s*m,e[3]=o*p+i*m,e[4]=r*g+s*b+a,e[5]=o*g+i*b+d,e}function RA(e,t,n){var r=t[0],o=t[1],s=t[2],i=t[3],a=t[4],d=t[5],c=Math.sin(n),l=Math.cos(n);return e[0]=r*l+s*c,e[1]=o*l+i*c,e[2]=r*-c+s*l,e[3]=o*-c+i*l,e[4]=a,e[5]=d,e}function IA(e,t,n){var r=t[0],o=t[1],s=t[2],i=t[3],a=t[4],d=t[5],c=n[0],l=n[1];return e[0]=r*c,e[1]=o*c,e[2]=s*l,e[3]=i*l,e[4]=a,e[5]=d,e}function FA(e,t){var n=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=n,e[2]=-n,e[3]=r,e[4]=0,e[5]=0,e}function BA(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=t[0],e[5]=t[1],e}var VA=NA;function HA(){var e=new nw(2);return nw!=Float32Array&&(e[0]=0,e[1]=0),e}function Km(e,t,n){return e[0]=t,e[1]=n,e}function na(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e}function UA(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e}function Ju(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e}function zA(e){var t=e[0],n=e[1];return t*t+n*n}function rw(e,t){var n=t[0],r=t[1],o=n*n+r*r;return o>0&&(o=1/Math.sqrt(o)),e[0]=t[0]*o,e[1]=t[1]*o,e}function Ms(e,t){return e[0]*t[0]+e[1]*t[1]}function He(e,t,n,r){var o=t[0],s=t[1];return e[0]=o+r*(n[0]-o),e[1]=s+r*(n[1]-s),e}function Zu(e,t,n){var r=t[0],o=t[1];return e[0]=n[0]*r+n[2]*o,e[1]=n[1]*r+n[3]*o,e}function zu(e,t,n){var r=t[0],o=t[1];return e[0]=n[0]*r+n[2]*o+n[4],e[1]=n[1]*r+n[3]*o+n[5],e}function jA(e,t,n,r){var o=t[0]-n[0],s=t[1]-n[1],i=Math.sin(r),a=Math.cos(r);return e[0]=o*a-s*i+n[0],e[1]=o*i+s*a+n[1],e}var Kn=UA,ow=zA;(function(){var e=HA();return function(t,n,r,o,s,i){var a,d;for(n||(n=2),r||(r=0),o?d=Math.min(o*n+r,t.length):d=t.length,a=r;a<d;a+=n)e[0]=t[a],e[1]=t[a+1],s(e,e,i),t[a]=e[0],t[a+1]=e[1];return t}})();var Qu=2*Math.PI;function KA(e,t,n,r,o){return(e-t)/(n-t)*(o-r)+r}function ct(e,t,n){return e+(t-e)*n}function Gn(e){return e/180*Math.PI}function sw(e,t){return Math.atan2(e[0]*t[1]-e[1]*t[0],Ms(e,t))}function Ce(){return[0,0]}function ut(e,t,n=0){return Math.abs(e[0]-t[0])<=n&&Math.abs(e[1]-t[1])<=n}function ww(){return new Float64Array([1,0,0,1])}function iw(){return new Float64Array([1,0,0,1,0,0])}function ec(e){return Number.isFinite(e)}function aw([e,t]){return Number.isFinite(e)&&Number.isFinite(t)}function kw(e){if(!Number.isFinite(e))return 0;let t=(e%360+360)%360;return t>180&&(t-=360),t}function ho(e,t,n,r){let o=n[0]-t[0],s=n[1]-t[1],i=o*o+s*s;if(i<=r*r){let d=e[0]-t[0],c=e[1]-t[1];return Math.hypot(d,c)}return Math.abs((e[0]-t[0])*s-(e[1]-t[1])*o)/Math.sqrt(i)}function As(e,t=kr){let n=e[1],r=_n(e),o=r[0]-n[0],s=r[1]-n[1],i=o*o+s*s<=t*t;switch(e[0]){case"L":return!0;case"Q":return ho(e[2],n,r,t)<=t;case"C":return ho(e[2],n,r,t)<=t&&ho(e[3],n,r,t)<=t;case"A":return i||!Number.isFinite(e[2])||!Number.isFinite(e[3])||Math.abs(e[2])<=t||Math.abs(e[3])<=t}}function GA(e,t){let n=e[1],r=_n(e);if(e[0]==="A")return!ec(e[2])||!ec(e[3])||Math.abs(e[2])<=kr||Math.abs(e[3])<=kr?["L",n,r]:mo(e);if(e[0]!=="C"&&e[0]!=="Q")return e;let o=r[0]-n[0],s=r[1]-n[1],i=o*o+s*s;if(o===0&&s===0){if(e[0]==="Q")return["L",n,r];let p=b=>(b[0]-n[0])**2+(b[1]-n[1])**2,[m,g]=p(e[2])>=p(e[3])?[e[2],e[3]]:[e[3],e[2]];return ho(g,n,m,kr)<=kr?["L",n,r]:e}if(i<=t*t)return e;let a=p=>((p[0]-n[0])*o+(p[1]-n[1])*s)/i,d=t/Math.sqrt(i);if(e[0]==="Q"){if(ho(e[2],n,r,t)>t)return e;let p=a(e[2]);return p<-d||p>1+d?e:["L",n,r]}if(ho(e[2],n,r,t)>t||ho(e[3],n,r,t)>t)return e;let c=a(e[2]),l=a(e[3]);return c<-d||l-c<-d||l>1+d?e:["L",n,r]}function mo(e){let t=Math.abs(e[2]),n=Math.abs(e[3]),r=e[4];return t<n&&([t,n]=[n,t],r+=90),t===n?r=0:r=(kw(r)%180+180)%180,["A",e[1],t,n,r,e[5],e[6],e[7]]}function tc(e){return e[1]}function _n(e){switch(e[0]){case"L":return e[2];case"C":return e[4];case"Q":return e[3];case"A":return e[7]}}function ra(e){switch(e[0]){case"L":return["L",e[2],e[1]];case"C":return["C",e[4],e[3],e[2],e[1]];case"Q":return["Q",e[3],e[2],e[1]];case"A":return["A",e[7],e[2],e[3],e[4],e[5],!e[6],e[1]]}}var xo=(()=>{let e=Ce(),t=ww(),n=Ce(),r=Ce();return function([s,i,a,d,c,l,p,m]){if(!aw(i)||!aw(m)||(c=kw(c),!ec(a)||!ec(d)||Math.abs(a)<=kr||Math.abs(d)<=kr))return null;vw(t,-Gn(c)),Kn(e,i,m),Ju(e,e,.5),Zu(e,e,t);let g=a*a,b=d*d,w=e[0]*e[0],k=e[1]*e[1];a=Math.abs(a),d=Math.abs(d);let _=w/g+k/b;if(_>1){let C=Math.sqrt(_);a*=C,d*=C;let G=Math.abs(_);g*=G,b*=G}let M=l===p?-1:1,R=g*k+b*w;if(R===0)return null;let B=g*b-g*k-b*w,D=Math.max(0,B/R),V=Math.sqrt(D),T=M*V*(a*e[1]/d),O=M*V*(-d*e[0]/a);DA(t,t),na(n,i,m),Ju(n,n,.5),Zu(r,[T,O],t),na(r,r,n);let j=[(e[0]-T)/a,(e[1]-O)/d],$=sw([1,0],j),P=sw(j,[(-e[0]-T)/a,(-e[1]-O)/d]);return!p&&P>0?P-=Qu:p&&P<0&&(P+=Qu),{center:[r[0],r[1]],theta1:$,deltaTheta:P,rx:a,ry:d,phi:c}}})(),dw=(()=>{let e=Ce(),t=Ce(),n=ww();return function({center:o,theta1:s,deltaTheta:i,rx:a,ry:d,phi:c}){vw(n,Gn(c)),Km(e,a*Math.cos(s),d*Math.sin(s)),Zu(e,e,n),na(e,e,o),Km(t,a*Math.cos(s+i),d*Math.sin(s+i)),Zu(t,t,n),na(t,t,o);let l=Math.abs(i)>Math.PI,p=i>0;return["A",[e[0],e[1]],a,d,c,l,p,[t[0],t[1]]]}})(),nc=(()=>{let e=Ce(),t=Ce(),n=Ce(),r=Ce(),o=Ce(),s=Ce();return function(a,d,c){if(As(a))return He(s,a[1],_n(a),d),c[0]=s[0],c[1]=s[1],c;switch(a[0]){case"L":He(s,a[1],a[2],d);break;case"C":He(e,a[1],a[2],d),He(t,a[2],a[3],d),He(n,a[3],a[4],d),He(r,e,t,d),He(o,t,n,d),He(s,r,o,d);break;case"Q":He(e,a[1],a[2],d),He(t,a[2],a[3],d),He(s,e,t,d);break;case"A":{let l=xo(a);if(!l){He(s,a[1],a[7],d);break}let{deltaTheta:p,phi:m,theta1:g,rx:b,ry:w,center:k}=l,_=g+d*p;Km(s,b*Math.cos(_),w*Math.sin(_)),jA(s,s,[0,0],Gn(m)),na(s,s,k);break}}return c[0]=s[0],c[1]=s[1],c}})(),Sn=(()=>{let e=Ce();return function(n,r){return nc(n,r,e),[e[0],e[1]]}})(),Sw=(()=>{let e=Ce();return function(n,r,o){if(As(n)){let s=n[1],i=_n(n);return o[0]=i[0]-s[0],o[1]=i[1]-s[1],o}switch(n[0]){case"Q":{let s=n[1],i=n[2],a=n[3],d=i[0]-s[0],c=i[1]-s[1],l=a[0]-i[0],p=a[1]-i[1];return o[0]=2*((1-r)*d+r*l),o[1]=2*((1-r)*c+r*p),o}case"C":{let s=n[1],i=n[2],a=n[3],d=n[4],c=i[0]-s[0],l=i[1]-s[1],p=a[0]-i[0],m=a[1]-i[1],g=d[0]-a[0],b=d[1]-a[1],w=1-r;return o[0]=3*(w*w*c+2*w*r*p+r*r*g),o[1]=3*(w*w*l+2*w*r*m+r*r*b),o}case"A":{let s=xo(mo(n));if(!s)return o[0]=n[7][0]-n[1][0],o[1]=n[7][1]-n[1][1],o;let{deltaTheta:i,phi:a,theta1:d,rx:c,ry:l}=s,p=d+r*i,m=Math.cos(Gn(a)),g=Math.sin(Gn(a)),b=-c*Math.sin(p)*i,w=l*Math.cos(p)*i;return e[0]=m*b-g*w,e[1]=g*b+m*w,o[0]=e[0],o[1]=e[1],o}}}})(),Xm=(()=>{let e=iw(),t=iw();return function(r,o=Math.PI/2){let s=xo(mo(r));if(!s)return[["L",r[1],r[7]]];let{center:i,theta1:a,deltaTheta:d,rx:c,ry:l,phi:p}=s,m=Math.ceil(Math.abs(d)/o);BA(e,i),RA(e,e,Gn(p)),IA(e,e,[c,l]);let g=[],b=d/m,w=4/3*Math.tan(b/4),k=Math.sin(b),_=Math.cos(b);for(let M=0;M<m;M++){let R=[1,0],B=[1,w],D=[_+w*k,k-w*_],V=[_,k];FA(t,a+M*b),VA(t,e,t),zu(R,R,t),zu(B,B,t),zu(D,D,t),zu(V,V,t),g.push(["C",R,B,D,V])}return g}})();function qA(e,t,n,r,o){let s=ct(e,t,o),i=ct(t,n,o),a=ct(n,r,o),d=ct(s,i,o),c=ct(i,a,o);return ct(d,c,o)}function uw(e,t,n,r){let o=Math.min(e,r),s=Math.max(e,r);function i(m){if(!(0<m&&m<1))return;let g=qA(e,t,n,r,m);o=Math.min(o,g),s=Math.max(s,g)}let a=3*(-e+3*t-3*n+r),d=6*(e-2*t+n),c=3*(t-e);if(Math.abs(a)<=1e-12*Math.max(Math.abs(d),Math.abs(c)))return d!==0&&i(-c/d),[o,s];let l=d*d-4*a*c;if(l<0)return[o,s];let p=-.5*(d+(d<0?-1:1)*Math.sqrt(l));return i(p/a),p!==0&&i(c/p),[o,s]}function WA(e,t,n,r){let o=ct(e,t,r),s=ct(t,n,r);return ct(o,s,r)}function cw(e,t,n){let r=Math.min(e,n),o=Math.max(e,n),s=e-2*t+n;if(s===0)return[r,o];let i=(e-t)/s;if(0<=i&&i<=1){let a=WA(e,t,n,i);r=Math.min(r,a),o=Math.max(o,a)}return[r,o]}function XA(e,t,n){let r=Math.min(t,n),o=Math.max(t,n);return e+Qu*Math.ceil((r-e)/Qu)<=o}function Nt(e){if(As(e)){let t=e[1],n=_n(e);return{top:Math.min(t[1],n[1]),right:Math.max(t[0],n[0]),bottom:Math.max(t[1],n[1]),left:Math.min(t[0],n[0])}}switch(e[0]){case"L":return{top:Math.min(e[1][1],e[2][1]),right:Math.max(e[1][0],e[2][0]),bottom:Math.max(e[1][1],e[2][1]),left:Math.min(e[1][0],e[2][0])};case"C":{let[t,n]=uw(e[1][0],e[2][0],e[3][0],e[4][0]),[r,o]=uw(e[1][1],e[2][1],e[3][1],e[4][1]);return{top:r,right:n,bottom:o,left:t}}case"Q":{let[t,n]=cw(e[1][0],e[2][0],e[3][0]),[r,o]=cw(e[1][1],e[2][1],e[3][1]);return{top:r,right:n,bottom:o,left:t}}case"A":{let t=xo(mo(e));if(!t)return Hm(Qi(e[1],0),e[7]);let{theta1:n,deltaTheta:r,phi:o,center:s,rx:i,ry:a}=t;if(o===0||i===a){let l=n+r,p=Hm(Qi(e[1],0),e[7]),m=Gn(o),g=[[Math.PI-m,[s[0]-i,s[1]]],[-Math.PI/2-m,[s[0],s[1]-a]],[-m,[s[0]+i,s[1]]],[Math.PI/2-m,[s[0],s[1]+a]]];for(let[b,w]of g)XA(b,n,l)&&(p=Hm(p,w));return CA(p,1e-11)}let d=Xm(e,Math.PI/16),c=null;for(let l of d)c=Cs(c,Nt(l));return c||Qi(e[1],0)}}}function Gm(e,t){let n=e[1],r=e[2],o=He(Ce(),n,r,t);return[["L",n,o],["L",o,r]]}function qu(e,t){let n=e[1],r=e[2],o=e[3],s=e[4],i=He(Ce(),n,r,t),a=He(Ce(),r,o,t),d=He(Ce(),o,s,t),c=He(Ce(),i,a,t),l=He(Ce(),a,d,t),p=He(Ce(),c,l,t);return[["C",n,i,c,p],["C",p,l,d,s]]}function YA(e,t){let n=e[1],r=e[2],o=e[3],s=He(Ce(),n,r,t),i=He(Ce(),r,o,t),a=He(Ce(),s,i,t);return[["Q",n,s,a],["Q",a,i,o]]}function JA(e,t){let n=xo(mo(e));if(!n)return Gm(["L",e[1],e[7]],t);let r=n.deltaTheta*t;return[dw({...n,deltaTheta:r}),dw({...n,theta1:n.theta1+r,deltaTheta:n.deltaTheta-r})]}function Ym(e,t){if(As(e))return Gm(["L",e[1],_n(e)],t);switch(e[0]){case"L":return Gm(e,t);case"C":return qu(e,t);case"Q":return YA(e,t);case"A":return JA(e,t)}}function qm([[e,t],[n,r]],[[o,s],[i,a]],d){let c=n-e,l=o-i,p=o-e,m=r-t,g=s-a,b=s-t,w=c*g-m*l;if(Math.abs(w)<d.collinear)return null;let k=(p*g-b*l)/w,_=(c*b-m*p)/w;return-d.param<=k&&k<=1+d.param&&-d.param<=_&&_<=1+d.param?[k,_]:null}function ZA(e,t,n){return!!qm(e,t,n)}function Es(e){let[t,n]=Ym(e.seg,.5),r=(e.startParam+e.endParam)/2;return[{seg:t,startParam:e.startParam,endParam:r,boundingBox:Nt(t)},{seg:n,startParam:r,endParam:e.endParam,boundingBox:Nt(n)}]}function lw(e){switch(e[0]){case"L":return[e[1],e[2]];case"C":return[e[1],e[4]];case"Q":return[e[1],e[3]];case"A":return[e[1],e[7]]}}function QA({seg:e,boundingBox:t},{seg:n,boundingBox:r},o){return e[0]==="L"?n[0]==="L"?ZA([e[1],e[2]],[n[1],n[2]],o):Yu([e[1],e[2]],r):n[0]==="L"?Yu([n[1],n[2]],t):Gu(t,r)}function rc(e,t,n){let r=e[0];if(t[0]!==r)return!1;switch(r){case"L":return ut(e[1],t[1],n)&&ut(e[2],t[2],n);case"C":return ut(e[1],t[1],n)&&ut(e[2],t[2],n)&&ut(e[3],t[3],n)&&ut(e[4],t[4],n);case"Q":return ut(e[1],t[1],n)&&ut(e[2],t[2],n)&&ut(e[3],t[3],n);case"A":return ut(e[1],t[1],n)&&Math.abs(e[2]-t[2])<n&&Math.abs(e[3]-t[3])<n&&(Math.abs(e[2]-e[3])<n||Math.abs(e[4]-t[4])<n)&&e[5]===t[5]&&e[6]===t[6]&&ut(e[7],t[7],n)}}function e$(e,t,n){let r=Kn([0,0],e[1],e[0]),o=Kn([0,0],t[1],t[0]);rw(r,r),rw(o,o);let s=Math.abs(Ms(r,o));return Math.abs(s-1)<n}var t$=(()=>{let e=Ce(),t=Ce(),n=Ce(),r=Ce(),o=Ce(),s=Ce();return function(a,d){Kn(e,a[1],a[0]),Kn(t,d[1],d[0]),Ju(e,e,1/ow(e)),Ju(t,t,1/ow(t));let c=[];Kn(n,d[0],a[0]);let l=Ms(n,e);l>=0&&l<=1&&c.push([l,0]),Kn(r,d[1],a[0]);let p=Ms(r,e);p>=0&&p<=1&&c.push([p,1]),Kn(o,a[0],d[0]);let m=Ms(o,t);m>=0&&m<=1&&c.push([0,m]),Kn(s,a[1],d[0]);let g=Ms(s,t);return g>=0&&g<=1&&c.push([1,g]),c}})(),fw=8;function n$(e,t,n,r,o){for(let s=1;s<fw;s++){let i=s/fw,a=Sn(e,ct(n.t0,r.t0,i)),d=Sn(t,ct(n.t1,r.t1,i));if(Math.hypot(a[0]-d[0],a[1]-d[1])>o.point)return!1}return!0}var Um=2*Math.PI;function r$(e,t,n){if(e[0]!=="A"||t[0]!=="A")return null;let r=xo(mo(e)),o=xo(mo(t));if(!r||!o||Math.abs(r.center[0]-o.center[0])>n.point||Math.abs(r.center[1]-o.center[1])>n.point||Math.abs(r.rx-o.rx)>n.point||Math.abs(r.ry-o.ry)>n.point)return null;let s=Math.max(r.rx,r.ry);if(!(s>0))return null;let i=n.point/s;if(Math.abs(r.rx-r.ry)>n.point){let M=Math.abs(((r.phi-o.phi)%180+180)%180);if(Math.min(M,180-M)>i*180/Math.PI)return null}if(Math.abs(r.deltaTheta)<i||Math.abs(o.deltaTheta)<i)return null;let a=Gn(r.phi),d=Gn(o.phi),c=(M,R)=>{let B=M.theta1+R,D=M.theta1+M.deltaTheta+R;return B<=D?[B,D]:[D,B]},[l,p]=c(r,a),[m,g]=c(o,d),b=(M,R,B)=>{let D=(B-R-M.theta1)/M.deltaTheta;return D<0?0:D>1?1:D},w=[],k=Math.floor((l-g)/Um),_=Math.ceil((p-m)/Um);for(let M=k;M<=_;M++){let R=M*Um,B=Math.max(l,m+R),D=Math.min(p,g+R);if(!(D<B-i)){if(D-B<=i){let V=(B+D)/2;w.push([b(r,a,V),b(o,d,V-R)]);continue}w.push([b(r,a,B),b(o,d,B-R)]),w.push([b(r,a,D),b(o,d,D-R)])}}return w}function pw(e){switch(e[0]){case"L":return e[2];case"C":return e[4];case"Q":return e[3];case"A":return e[7]}}function o$(e,t,n){return e[0]!==t[0]||!ut(e[1],pw(t),n.point)||!ut(pw(e),t[1],n.point)?!1:rc(e,ra(t),n.point)}var hw=16;function s$(e,t,n,r){if(n.length<2)return null;let o=n[0],s=n[n.length-1],i=s.t0-o.t0,a=s.t1-o.t1;if(Math.abs(i)<r.param||Math.abs(a)<r.param)return null;let d=a/i;if(!Number.isFinite(d))return null;let c=B=>o.t1+(B-o.t0)*d,l=B=>o.t0+(B-o.t1)/d,p=l(0),m=l(1),g=Math.max(0,Math.min(p,m)),b=Math.min(1,Math.max(p,m));if(!(b>g))return null;let w=B=>B<0?0:B>1?1:B,k=B=>B<r.param?0:B>1-r.param?1:B;g=k(g),b=k(b);let _=[[g,k(w(c(g)))],[b,k(w(c(b)))]],M=Sn(e,_[0][0]),R=Sn(e,_[1][0]);if(Math.hypot(M[0]-R[0],M[1]-R[1])<=r.point)return null;for(let B=0;B<=hw;B++){let D=B/hw,V=Sn(e,ct(_[0][0],_[1][0],D)),T=Sn(t,ct(_[0][1],_[1][1],D));if(Math.hypot(V[0]-T[0],V[1]-T[1])>r.point)return null}return _}function i$(e,t,n,r){if(n.length<=1)return n.map(a=>[a.t0,a.t1]);let o=[...n].sort((a,d)=>a.t0-d.t0),s=[[o[0]]];for(let a=1;a<o.length;a++){let d=s[s.length-1],c=d[d.length-1];n$(e,t,c,o[a],r)?d.push(o[a]):s.push([o[a]])}let i=e[0]===t[0];return s.flatMap(a=>{let d=i?s$(e,t,a,r):null;return d||[d$(e,t,a)]})}var a$=40,ju=(Math.sqrt(5)-1)/2;function d$(e,t,n){let r=n[0];for(let b of n)b.gap<r.gap&&(r=b);if(n.length<2)return[r.t0,r.t1];let o=n[0],s=n[n.length-1],i=b=>{let w=ct(o.t0,s.t0,b),k=ct(o.t1,s.t1,b),_=Sn(e,w),M=Sn(t,k);return{t0:w,t1:k,gap:Math.hypot(_[0]-M[0],_[1]-M[1])}},a=0,d=1,c=d-ju*(d-a),l=a+ju*(d-a),p=i(c),m=i(l);for(let b=0;b<a$;b++)p.gap<m.gap?(d=l,l=c,m=p,c=d-ju*(d-a),p=i(c)):(a=c,c=l,p=m,l=a+ju*(d-a),m=i(l));let g=p.gap<m.gap?p:m;return g.gap<r.gap?[g.t0,g.t1]:[r.t0,r.t1]}function u$(e,t,n){let r=e,o=t;if(r[0]==="L"&&o[0]==="L"){let m=[r[1],r[2]],g=[o[1],o[2]];if(e$(m,g,n.collinear))return t$(m,g);let b=qm(m,g,n);return b?[b]:[]}let s=r$(r,o,n);if(s)return s;let i=[[{seg:r,startParam:0,endParam:1,boundingBox:Nt(r)},{seg:o,startParam:0,endParam:1,boundingBox:Nt(o)}]],a=[];function d(m,g){let b=Sn(e,m),w=Sn(t,g);a.push({t0:m,t1:g,gap:Math.hypot(b[0]-w[0],b[1]-w[1])})}function c(m,g){let b=lw(m.seg),w=lw(g.seg),k=qm(b,w,n);k&&d(ct(m.startParam,m.endParam,k[0]),ct(g.startParam,g.endParam,k[1]))}function l(m){return As(m.seg,kr)||Zi(m.boundingBox)<=n.linear||m.endParam-m.startParam<n.param}let p=0;for(;i.length;){if(p++>bw){for(let[b,w]of i)c(b,w);break}let m=[],g=!1;for(let[b,w]of i){if(rc(b.seg,w.seg,n.point)){d(b.startParam,w.startParam),d(b.endParam,w.endParam);continue}if(o$(b.seg,w.seg,n)){d(b.startParam,w.endParam),d(b.endParam,w.startParam);continue}let k=l(b),_=l(w);if(k&&_)c(b,w);else{let M,R;if(!k&&!_){let B=Zi(b.boundingBox),D=Zi(w.boundingBox);B>D?(M=Es(b),R=[w]):D>B?(M=[b],R=Es(w)):(M=Es(b),R=Es(w))}else M=k?[b]:Es(b),R=_?[w]:Es(w);for(let B of M){for(let D of R)if(QA(B,D,n)&&(m.push([B,D]),m.length>=ea)){g=!0;break}if(m.length>=ea)break}}if(m.length>=ea)break}if(g){for(let[b,w]of i)c(b,w);break}i=m}return i$(e,t,a,n)}var mw=Object.hasOwn;function qn(e){let t=new WeakMap;return(n,...r)=>{if(t.has(n))return t.get(n);{let o=e(n,...r);return t.set(n,o),o}}}function*c$(e,t){let n=0;for(let r of e)yield t(r,n++)}var zm=2*Math.PI,l$=8,_w=8,vt;(function(e){e[e.Union=0]="Union",e[e.Difference=1]="Difference",e[e.Intersection=2]="Intersection",e[e.Exclusion=3]="Exclusion",e[e.Division=4]="Division",e[e.Fracture=5]="Fracture"})(vt||(vt={}));var go;(function(e){e[e.NonZero=0]="NonZero",e[e.EvenOdd=1]="EvenOdd"})(go||(go={}));function f$(e){return e.values().next().value}function p$(e,t){let n=new Array(e).fill(!1);return n[t]=!0,n}function h$(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function m$(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Ku(e,t){for(let n=0;n<t.length;n++)t[n]&&(e[n]=!0)}function xw(e,t,n){let[,r,o]=e,s=n?-1:1;for(let i=0;i<t.length;i++)t[i]&&(r.windings[i]+=s,o.windings[i]-=s)}function Ew(){let e=0;return qn(()=>e++)}function x$(e,t){return n=>({seg:n,parents:p$(e,t)})}function g$(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r.seg[0]!=="C")continue;let o=PA(r.seg);if(!o)continue;o[0]>o[1]&&o.reverse();let[s,i]=o;if(Math.abs(s-i)<Xt.param){let[a,d]=qu(r.seg,s);e[n]={seg:a,parents:r.parents},e.push({seg:d,parents:r.parents})}else{let[a,d]=qu(r.seg,s),[c,l]=qu(d,(i-s)/(1-s));e[n]={seg:a,parents:r.parents},e.push({seg:c,parents:r.parents},{seg:l,parents:r.parents})}}}function y$(e,t){let n=e.map(c=>({...c,boundingBox:Nt(c.seg)})),r=n.reduce((c,{boundingBox:l})=>Cs(c,l),null);if(!r)return{edges:[],totalBoundingBox:null};let o=new ta(r,l$),s={};function i(c,l){mw(s,c)||(s[c]=[]),s[c].push(l)}let a=0;for(let c=0;c<n.length;c++){let l=n[c],p=o.find(l.boundingBox);for(let m of p){if(a>=ea)break;let g=e[m],b=u$(l.seg,g.seg,t);for(let[w,k]of b)i(c,w),i(m,k);a++}if(o.insert(l.boundingBox,c),a>=ea)break}let d=[];for(let c=0;c<n.length;c++){let l=n[c];if(!mw(s,c)){d.push(l);continue}let p=s[c];p.sort((b,w)=>b-w),p.length+1>jm&&(p.length=Math.max(0,jm-1));let m=l.seg,g=0;for(let b=0;b<p.length;b++){let w=p[b];if(w>1-Xt.param)break;let k=(w-g)/(1-g);if(g=w,k<Xt.param||k>1-Xt.param)continue;let[_,M]=Ym(m,k);d.push({seg:_,boundingBox:Nt(_),parents:l.parents}),m=M}d.push({seg:m,boundingBox:Nt(m),parents:l.parents})}return{edges:d,totalBoundingBox:r}}function b$(e,t,n){let r=new ta(t,_w),o=[];function s(g){let b=Qi(g,n.point),w=r.find(b);if(w.size)return f$(w);{let k={point:g,outgoingEdges:[]};return r.insert(b,k),o.push(k),k}}let i=Ew(),a=new Map;function d(g,b){return a.get(g)?.get(b)}function c(g,b){let w=a.get(g);w||(w=new Map,a.set(g,w));let k=w.get(b);return k||(k=[],w.set(b,k)),k}let l=e.flatMap(g=>{let b=tc(g.seg),w=_n(g.seg);if(ut(b,w,n.point))switch(g.seg[0]){case"L":return[];case"C":if(ut(g.seg[1],g.seg[2],n.point)&&ut(g.seg[3],g.seg[4],n.point))return[];break;case"Q":if(ut(g.seg[1],g.seg[2],n.point))return[];break;case"A":return[]}let k=s(b),_=s(w),M=i(k),R=i(_),B=d(M,R);if(B){let O=B.find(j=>rc(j[0].seg,g.seg,n.point));if(O)return xw(O,g.parents,!1),Ku(O[1].parents,g.parents),Ku(O[2].parents,g.parents),[]}let D=d(R,M);if(D){let O=ra(g.seg),j=D.find($=>rc($[0].seg,O,n.point));if(j)return xw(j,g.parents,!0),Ku(j[1].parents,g.parents),Ku(j[2].parents,g.parents),[]}let V={...g,parents:g.parents.slice(),incidentVertices:[k,_],directionFlag:!1,windings:g.parents.map(O=>O?1:0),twin:null},T={...g,parents:g.parents.slice(),incidentVertices:[_,k],directionFlag:!0,windings:g.parents.map(O=>O?-1:0),twin:V};return V.twin=T,k.outgoingEdges.push(V),_.outgoingEdges.push(T),c(M,R).push([g,V,T]),[V,T]});for(let g of l)for(let b=0;b<g.parents.length;b++)g.parents[b]=g.windings[b]!==0;let p=g=>g.windings.some(b=>b!==0),m=l.filter(p);for(let g of o)g.outgoingEdges=g.outgoingEdges.filter(p);return{edges:m,vertices:o.filter(g=>g.outgoingEdges.length)}}function Wu(e){return e.outgoingEdges.length}function v$({vertices:e}){let t=[],n=[],r=0,o=qn(p=>{let m={outgoingEdges:[]};return n.push(m),m}),s=Ew(),i=new Map;function a(p,m){return i.get(p)?.get(m)}function d(p,m,g){let b=i.get(p);b||(b=new Map,i.set(p,b)),b.set(m,g)}let c=new WeakSet;for(let p of e){if(Wu(p)===2)continue;let m=o(p);for(let g of p.outgoingEdges){let b=[],w=g;for(;h$(w.parents,g.parents)&&w.directionFlag===g.directionFlag&&m$(w.windings,g.windings)&&Wu(w.incidentVertices[1])===2;){b.push(w.seg),c.add(w.incidentVertices[1]);let[T,O]=w.incidentVertices[1].outgoingEdges;w=T.twin===w?O:T}b.push(w.seg);let k=o(w.incidentVertices[1]),_=s(g),M=s(w),R=s(w.twin),B=s(g.twin),D=a(R,B)??null,V={segments:b,parents:g.parents,incidentVertices:[m,k],directionFlag:g.directionFlag,windings:g.windings,twin:D,id:r++};D&&(D.twin=V),d(_,M,V),m.outgoingEdges.push(V),t.push(V)}}let l=[];for(let p of e){if(Wu(p)!==2||c.has(p))continue;let m=p.outgoingEdges[0],g={segments:[],parents:m.parents,directionFlag:m.directionFlag,windings:m.windings};do{g.segments.push(m.seg),c.add(m.incidentVertices[0]);let[b,w]=m.incidentVertices[1].outgoingEdges;m=b.twin===m?w:b}while(m.incidentVertices[0]!==p);l.push(g)}return{edges:t,vertices:n,cycles:l}}function w$(e,t){function n(i){let a=new WeakSet,d=new WeakMap;function c(l,p,m){if(d.has(l))return d.get(l);d.set(l,m);let g=1/0;for(let b of l.outgoingEdges)b.parents[i]&&b!==p&&(g=Math.min(g,c(b.incidentVertices[1],b.twin,m+1)));return g<=m&&a.add(l),g}for(let l of e.edges)l.parents[i]&&c(l.incidentVertices[0],null,0);return a}let r=[];for(let i=0;i<t;i++)r.push(n(i));function o(i){return r.some(a=>a.has(i))}function s(i){for(let a=0;a<t;a++)if(i.parents[a]&&r[a].has(i.incidentVertices[0])&&r[a].has(i.incidentVertices[1]))return!0;return!1}e.vertices=e.vertices.filter(o);for(let i of e.vertices)i.outgoingEdges=i.outgoingEdges.filter(s);e.edges=e.edges.filter(s)}var Mw=(()=>{let e=Ce();return function({directionFlag:n,segments:r}){return Sw(r[0],n?1:0,e),Math.hypot(e[0],e[1])}})(),gw=(()=>{let e=Ce(),t=Ce(),n=Ce();return function(o,s=0){let{directionFlag:i,segments:a}=o,d=a[0],l=i?1:0;if(s>0){let _=Mw(o),M=_>0?Math.min(OA,s/_):Xt.param;l=i?1-M:M}if(Sw(d,l,n),i&&(n[0]=-n[0],n[1]=-n[1]),n[0]*n[0]+n[1]*n[1]>=tw)return Math.atan2(n[1],n[0]);nc(d,l,e);let m=Xt.param;for(let _=0;_<AA;_++){let M=i?Math.max(0,l-m):Math.min(1,l+m);nc(d,M,t);let R=t[0]-e[0],B=t[1]-e[1];if(R*R+B*B>=tw)return Math.atan2(B,R);m*=2}let g=tc(d),b=_n(d),w=b[0]-g[0],k=b[1]-g[1];return i&&(w=-w,k=-k),Math.atan2(k,w)}})();function k$({vertices:e}){for(let t of e){if(Wu(t)>2){let n=new WeakMap,r=1/0;for(let i of t.outgoingEdges){let a=Mw(i);a>0&&(r=Math.min(r,a))}let o=Number.isFinite(r)?Xt.param*r:Xt.param,s=new WeakMap;for(let i of t.outgoingEdges){let a=gw(i);n.set(i,a),s.set(i,S$(gw(i,o)-a))}t.outgoingEdges.sort((i,a)=>{let d=s.get(i),c=s.get(a),l=Math.max($A,Math.abs(d),Math.abs(c)),p=n.get(i)-n.get(a);return Math.abs(p)>l?p:d-c})}for(let n=0;n<t.outgoingEdges.length;n++)t.outgoingEdges[n].indexInVertex=n}}function S$(e){return((e+Math.PI)%zm+zm)%zm-Math.PI}function _$(e){let{outgoingEdges:t}=e.incidentVertices[1],n=e.twin?.indexInVertex;return t[(n+1)%t.length]}var Cw=qn(e=>e.incidentEdges.flatMap(t=>{let r=[],o=Ce();for(let s of t.segments)for(let i=0;i<64;i++){let a=i/64,d=t.directionFlag?1-a:a;nc(s,d,o),r.push([o[0],o[1]])}return r}));function Aw(e,t,n){let r=e>=n,o=t<n;return r===o}function Wm(e,t,n){return Aw(e[1],t[1],n[1])?KA(n[1],e[1],t[1],e[0],t[0])>=n[0]:!1}function E$(e,t){if(e.length<=2)return 0;let n=e[e.length-1],r=0;for(let o of e)Wm(n,o,t)&&(r+=o[1]>n[1]?-1:1),n=o;return r}var M$=qn(e=>{let t=Cw(e),n=0;for(let r=0;r<t.length;r++){let o=t[r],s=t[(r+1)%t.length];n+=o[0]*s[1]-s[0]*o[1]}return n/2}),C$=qn(e=>{let t=Cw(e);for(let n=0;n<t.length;n++){let r=t[n],o=t[(n+1)%t.length],s=t[(n+2)%t.length],i=[(r[0]+o[0]+s[0])/3,(r[1]+o[1]+s[1])/3],a=E$(t,i);if(a!==0)return{winding:a,point:i}}});function A$({edges:e,cycles:t}){let n=[],r=new WeakMap;for(let d of e){if(r.has(d))continue;let c={incidentEdges:[],flags:[]},l=d;do{let p=r.get(l.twin)??null,m={segments:l.segments,parents:l.parents,incidentVertex:c,directionFlag:l.directionFlag,windings:l.windings,twin:p};p&&(p.twin=m),r.set(l,m),c.incidentEdges.push(m),l=_$(l)}while(l!==d);n.push(c)}for(let d of t){let c={incidentEdges:[],flags:[]},l={segments:d.segments,parents:d.parents,incidentVertex:c,directionFlag:d.directionFlag,windings:d.windings,twin:null},p={incidentEdges:[],flags:[]},m={segments:[...d.segments].reverse(),parents:d.parents,incidentVertex:p,directionFlag:!d.directionFlag,windings:d.windings.map(g=>-g),twin:l};l.twin=m,c.incidentEdges.push(l),p.incidentEdges.push(m),n.push(c,p)}let o=d=>M$(d)>0,s=[],i=new WeakSet,a=new WeakSet;for(let d of n){if(i.has(d))continue;let c=[],l=[],p=g=>{i.has(g)||c.push(g),i.add(g);for(let b of g.incidentEdges){if(a.has(b))continue;let{twin:w}=b;l.push(b,w),a.add(b),a.add(w),p(w.incidentVertex)}};p(d);let m=c.find(o);s.push({vertices:c,edges:l,outerFace:m})}return s}function Xu(e,t){return Aw(e.top,e.bottom,t[1])&&e.right>=t[0]}function $$(e,t,n,r=Nt(e)){if(!Xu(r,t))return 0;let o=[{boundingBox:r,seg:e}],s=0,i=0;for(;o.length>0;){if(i++>bw||o.length>jm){for(let{seg:d}of o)Wm(tc(d),_n(d),t)&&s++;break}let a=[];for(let{boundingBox:d,seg:c}of o)if(As(c)||Zi(d)<n.linear)Wm(tc(c),_n(c),t)&&s++;else{let l=Ym(c,.5),p=Nt(l[0]);Xu(p,t)&&a.push({boundingBox:p,seg:l[0]});let m=Nt(l[1]);Xu(m,t)&&a.push({boundingBox:m,seg:l[1]})}o=a}return s}var O$=qn(e=>{for(let t of e.vertices)if(t!==e.outerFace)return C$(t).point}),$w=qn(e=>e.incidentEdges.flatMap(t=>t.segments.map(n=>({seg:n,boundingBox:Nt(n)})))),Ow=qn(e=>{let t=null;for(let{boundingBox:n}of $w(e))t=Cs(t,n);return t}),T$=qn(e=>{let t=null;for(let n of e.vertices)n!==e.outerFace&&(t=Cs(t,Ow(n)));return t});function Tw(e,t,n){return t[0]>=e.left-n.point&&t[0]<=e.right+n.point&&t[1]>=e.top-n.point&&t[1]<=e.bottom+n.point}function L$({top:e,right:t,bottom:n,left:r}){return(t-r)*(n-e)}function P$(e,t,n){for(let r of e.vertices){if(r===e.outerFace||!Tw(Ow(r),t,n))continue;let o=0;for(let{seg:s,boundingBox:i}of $w(r))Xu(i,t)&&(o+=$$(s,t,n,i));if(o%2===1)return r}return null}function D$(e,t){if(e.length===0)return[];let n=null,r=e.map((a,d)=>{let c=O$(a),l=T$(a);return n=Cs(n,l),{index:d,component:a,interiorPoint:c,boundingBox:l,area:L$(l)}}),o=new WeakMap;for(let a of e)o.set(a,{component:a,outgoingEdges:new Map});let s=new ta(n,_w);for(let a of r)s.insert(a.boundingBox,a.index);let i=[];for(let a of r){let d=a.interiorPoint,c=Qi(d,t.point),l=s.find(c),p=null,m=null;for(let w of l){if(w===a.index)continue;let k=r[w];if(!Tw(k.boundingBox,d,t))continue;let _=P$(k.component,d,t);_&&(!p||k.area<p.area)&&(p=k,m=_)}let g=o.get(a.component);if(!p||!m){i.push(g);continue}let b=o.get(p.component);b.outgoingEdges.has(m)?b.outgoingEdges.get(m).push(g):b.outgoingEdges.set(m,[g])}return i}function N$(e,t){switch(t){case go.NonZero:return e!==0;case go.EvenOdd:return e%2!==0}}function R$(e,t){let n=t.length;function r(o,s){let i=new WeakSet;function a(d,c){if(!i.has(d)){i.add(d),d.flags=c.map((l,p)=>N$(l,t[p]));for(let l of d.incidentEdges){let p=l.twin,m=c.slice();for(let g=0;g<n;g++)m[g]+=l.windings[g];a(p.incidentVertex,m)}if(o.outgoingEdges.has(d)){let l=o.outgoingEdges.get(d);for(let p of l)r(p,c)}}}a(o.component.outerFace,s)}for(let o of e)r(o,new Array(n).fill(0))}function*I$(e,t){function*n(r){for(let o of r.component.vertices)t(o)&&(yield o);for(let o of r.outgoingEdges.values())for(let s of o)yield*n(s)}for(let r of e)yield*n(r)}function*yw(e){function t(o){return e.has(o.incidentVertex)===e.has(o.twin.incidentVertex)}let n=new WeakMap;for(let o of e){let s=o.incidentEdges[o.incidentEdges.length-1];for(let i of o.incidentEdges)n.set(s,i),s=i}let r=new WeakSet;for(let o of e)for(let s of o.incidentEdges){if(t(s)||r.has(s))continue;let i=s;do for(i.directionFlag?yield*c$(i.segments,ra):yield*i.segments,r.add(i),i=n.get(i);t(i);)i=n.get(i.twin);while(i!==s)}}function Lw(e,t){let n=[],r=[];function o(s){for(let i of s.component.vertices){if(!t(i)||i===s.component.outerFace)continue;let a=[];for(let d of i.incidentEdges)d.directionFlag?a.push(...d.segments.map(ra)):a.push(...d.segments);if(s.outgoingEdges.has(i))for(let d of s.outgoingEdges.get(i)){let{outerFace:c}=d.component;for(let l of c.incidentEdges)l.directionFlag?a.push(...l.segments.map(ra)):a.push(...l.segments)}n.push(i),r.push(a)}for(let i of s.outgoingEdges.values())for(let a of i)o(a)}for(let s of e)o(s);return{faces:n,paths:r}}function F$(e,t){return Lw(e,t).paths}function B$(e,t){function n(r){for(let[o,s]of r.outgoingEdges){if(t.has(o))for(let i of s){let{outerFace:a}=i.component;t.add(a)}for(let i of s)n(i)}}for(let r of e)n(r)}var V$={[vt.Union]:e=>e.some(Boolean),[vt.Difference]:e=>e[0]&&!e.slice(1).some(Boolean),[vt.Intersection]:e=>e.every(Boolean),[vt.Exclusion]:e=>e.reduce((t,n)=>t+(n?1:0),0)%2===1,[vt.Division]:e=>e[0],[vt.Fracture]:e=>e.some(Boolean)},oa=class{constructor(t){let n=t.length,r=t.flatMap(({path:m},g)=>m.map(x$(n,g))),o=null;for(let{seg:m}of r)o=Cs(o,Nt(m));let s=LA(o?Zi(o):0);for(let m of r)m.seg=GA(m.seg,s.point);g$(r);let{edges:i,totalBoundingBox:a}=y$(r,s);if(!a){this.nestingTrees=[];return}let d=b$(i,a,s),c=v$(d);w$(c,n),k$(c);let l=A$(c),p=D$(l,s);R$(p,t.map(({fillRule:m})=>m)),this.nestingTrees=p}get(t){let n=r=>V$[t](r.flags);switch(t){case vt.Division:case vt.Fracture:return F$(this.nestingTrees,n);default:{let r=new Set(I$(this.nestingTrees,n));return[[...yw(r)]]}}}getFaces(){return this.getRegions().paths}buildShape(t){let{faces:n}=this.getRegions(),r=new Set;for(let o of t){let s=n[o];s&&r.add(s)}return B$(this.nestingTrees,r),[...yw(r)]}getRegions(){return this.regions??(this.regions=Lw(this.nestingTrees,t=>t.flags.some(Boolean)))}};var Pw={union:vt.Union,subtract:vt.Difference,intersect:vt.Intersection,exclude:vt.Exclusion},sa=.001,H$=.01;function Dw(e,t){let n=t.map(s=>({path:G$(s.contours.filter(i=>!K$(i))),fillRule:s.evenOdd?go.EvenOdd:go.NonZero})),r=s=>s.path.length===0;if(e==="intersect"&&n.some(r))return[];if(e==="subtract"&&r(n[0]))return[];let o=n.filter(s=>!r(s));return o.length===0?[]:z$(e,o).flatMap(q$).map(W$).filter(X$)}var U$=[.001,.003,.007];function z$(e,t){try{return new oa([...t]).get(Pw[e])}catch(n){for(let r of U$){let o=t.map((s,i)=>({fillRule:s.fillRule,path:i===0?s.path:j$(s.path,r*i,r*i*.618)}));try{return new oa(o).get(Pw[e])}catch{}}throw n}}function j$(e,t,n){let r=o=>[o[0]+t,o[1]+n];return e.map(o=>o[0]==="L"?["L",r(o[1]),r(o[2])]:o[0]==="C"?["C",r(o[1]),r(o[2]),r(o[3]),r(o[4])]:o[0]==="Q"?["Q",r(o[1]),r(o[2]),r(o[3])]:["A",r(o[1]),o[2],o[3],o[4],o[5],o[6],r(o[7])])}function K$(e){let t=[],n=zt(e);for(let i=0;i<n;i+=1)t.push(...dr(jt(e,i),.1));!e.closed&&e.anchors.length>0&&t.push(e.anchors[0]);let r=t[0];if(!r)return!0;let o=r;for(let i of t)Math.hypot(i.x-r.x,i.y-r.y)>Math.hypot(o.x-r.x,o.y-r.y)&&(o=i);let s=Math.hypot(o.x-r.x,o.y-r.y);return s<=sa?!0:t.every(i=>Math.abs((o.x-r.x)*(i.y-r.y)-(o.y-r.y)*(i.x-r.x))/s<=sa)}function G$(e){let t=[];for(let n of e){let r=zt(n);if(r!==0){for(let o=0;o<r;o+=1){let[s,i,a,d]=jt(n,o);ja(n,o)?oc(s,d)||t.push(["L",Sr(s),Sr(d)]):t.push(["C",Sr(s),Sr(i),Sr(a),Sr(d)])}if(!n.closed){let o=n.anchors[0],s=n.anchors[n.anchors.length-1];oc(o,s)||t.push(["L",Sr(s),Sr(o)])}}}return t}function Sr(e){return[e.x,e.y]}function q$(e){let t=[],n,r=()=>{n&&n.anchors.length>1&&t.push({closed:!0,anchors:n.anchors}),n=void 0};for(let o of e)for(let s of Nw(o)){let[i,a,d,c]=s;if(n){let g=n.anchors[n.anchors.length-1];oc(g,i)||r()}n||(n={anchors:[{x:i.x,y:i.y}],start:i});let l=a===void 0||d===void 0,p=n.anchors,m=p[p.length-1];if(l||(p[p.length-1]={...m,out:a}),oc(c,n.start)&&p.length>1){l||(p[0]={...p[0],in:d}),r();continue}p.push(l?{x:c.x,y:c.y}:{x:c.x,y:c.y,in:d})}return r(),t}function Nw(e){let t=n=>({x:n[0],y:n[1]});if(e[0]==="L")return[[t(e[1]),void 0,void 0,t(e[2])]];if(e[0]==="C")return[[t(e[1]),t(e[2]),t(e[3]),t(e[4])]];if(e[0]==="Q"){let[n,r,o]=[t(e[1]),t(e[2]),t(e[3])];return[[n,{x:n.x+(r.x-n.x)*2/3,y:n.y+(r.y-n.y)*2/3},{x:o.x+(r.x-o.x)*2/3,y:o.y+(r.y-o.y)*2/3},o]]}return Xm(e).flatMap(Nw)}function W$(e){let t=[...e.anchors],n=!0;for(;n&&t.length>3;){n=!1;for(let r=0;r<t.length;r+=1){if(!e.closed&&(r===0||r===t.length-1))continue;let o=t[(r-1+t.length)%t.length],s=t[r],i=t[(r+1)%t.length];if(o.out||s.in||s.out||i.in)continue;let a=(s.x-o.x)*(i.y-s.y)-(s.y-o.y)*(i.x-s.x),d=(s.x-o.x)*(i.x-s.x)+(s.y-o.y)*(i.y-s.y),c=Math.hypot(i.x-o.x,i.y-o.y);if(d>=0&&Math.abs(a)<=sa*Math.max(c,1)){t.splice(r,1),n=!0;break}}}return{closed:e.closed,anchors:t}}function X$(e){if(e.anchors.length<2)return!1;let t=[],n=zt(e);for(let o=0;o<n;o+=1)t.push(...dr(jt(e,o),.1));let r=0;for(let o=0;o<t.length;o+=1){let s=t[o],i=t[(o+1)%t.length];r+=s.x*i.y-i.x*s.y}return Math.abs(r/2)>=H$}function oc(e,t){return Math.abs(e.x-t.x)<=sa&&Math.abs(e.y-t.y)<=sa}function Jm(e,t){let n=bi(e,{x:t.x,y:t.y,w:t.w,h:t.h},t.values);return n===void 0?void 0:{contours:n.contours,evenOdd:n.rule==="evenodd"}}var Y$=["name","fill","stroke","strokeWidth","dash","strokeAlign","opacity","cap","join","blend","shadow","blur","backdrop","hidden","locked"];function ia(e){return Math.round(e*100)/100}var Rw=e=>Math.floor(e*100+1e-9)/100,Iw=e=>Math.ceil(e*100-1e-9)/100;function Zm(e,t){let n=Jo(e,t.ids,t.as);if(n)return{ok:!1,...n};try{return J$(e,t)}catch(r){return{ok:!1,...Zo(r)}}}function J$(e,t){let n=Pe(e),r=ef(e,t.ids),o=z(e.root,r[0]),s=Le(e.root,o.id);if(!s)return{ok:!1,code:"unknown-reference",message:`No node ${o.id}`};let i=[];for(let P of r){let C=z(e.root,P),G=n.nodes.get(P),ee=G&&Jm(C,G);if(!ee)return{ok:!1,code:"merge-not-a-shape",message:`${P} has no outline`,nodeId:P};i.push(ee)}let a=Dw(t.verb,i),d=Kt(a);if(a.length===0||!d||d.w<=0||d.h<=0)return{ok:!1,code:"merge-empty",message:`${Yo[t.verb]} of ${r.join(", ")} leaves nothing${t.verb==="intersect"?": the shapes do not all overlap":""}; nothing was changed`};let c=Rw(d.x),l=Rw(d.y),p=Math.max(.01,ia(Iw(d.x+d.w)-c)),m=Math.max(.01,ia(Iw(d.y+d.h)-l)),g=ze(Be(a,P=>({x:P.x-c,y:P.y-l}))),b=o,w={};for(let P of Y$)b[P]!==void 0&&(w[P]=b[P]);let k=r.some(P=>z(e.root,P)?.locked===!0),_=t.as??o.id,M=To({...w,...k?{locked:!0}:{},id:_,x:c,y:l,w:p,h:m,view:Pn({x:0,y:0,w:p,h:m}),d:g,...a.length>1?{rule:"evenodd"}:{}}),R=s.children.findIndex(P=>P.id===o.id),B=Z$(e,r,s.id),D=[...r.map(P=>({op:"remove",id:P})),...B.map(P=>({op:"remove",id:P})),{op:"insert",parent:s.id,index:R,node:M},...Q$(e,o.id,_)],V=[];de(e.root,P=>{st(P)&&P.mask!==void 0&&P.mask!==_&&r.includes(P.mask)&&V.push({op:"set",id:P.id,prop:"mask",value:_})});let T=[...Vo(e,[...D,...V])],O=Ae(e,T).document,j=new Set([...r,_]),$=new Set([...r.filter(P=>P!==_),...B]);return{ok:!0,id:_,ops:[...T,...eO(n,O,j,$)]}}function Z$(e,t,n){let r=new Set(t),o=[],s=i=>{if(r.has(i.id))return!0;if(!me(i))return!1;let a=i.children.length>0;for(let d of i.children)s(d)||(a=!1);return a&&i.type==="group"&&i.id!==n?(o.push(i.id),!0):!1};return s(e.root),o.filter(i=>{let a=Le(e.root,i);for(;a;){if(o.includes(a.id))return!1;a=Le(e.root,a.id)}return!0})}function Q$(e,t,n){if(t===n||!e.motion)return[];let r=[];for(let[o,s]of Object.entries(e.motion)){if(!s.lines.some(a=>a.id===t||a.after===t))continue;let i=s.lines.map(a=>({...a,...a.id===t?{id:n}:{},...a.after===t?{after:n}:{}}));r.push({op:"setMotion",page:o,value:{...s,lines:i}})}return r}function eO(e,t,n,r){let o=Pe(t),s=[];for(let[i,a]of o.nodes){if(n.has(i))continue;let d=e.nodes.get(i),c=z(t.root,i);if(!d||!c||nO(t,i))continue;let l=c;for(let p of Vt(c)){let m=d.values[p],g=a.values[p];m===void 0||g===void 0||ia(m)===ia(g)&&!tO(l[p],r)||s.push({op:"set",id:i,prop:p,value:ia(m)})}}return s}function tO(e,t){if(!ve(e))return!1;let n=tt(e.expr);return n.ok&&on(n.ast).nodes.some(r=>t.has(r))}function nO(e,t){let n=Le(e.root,t);for(;n;){if(n.type==="instance")return!0;n=Le(e.root,n.id)}return!1}function Fw(e){let t=e,n=new Map,r=typeof URL.createObjectURL=="function"&&typeof URL.revokeObjectURL=="function";return{resolve(o){let s=n.get(o.hash);if(s!==void 0)return s;let i=t.get(o.hash);if(i===void 0)return;if(!r)return Ul(o.type,i);let a;try{a=jl(i)}catch{return}let d=URL.createObjectURL(new Blob([a],{type:o.type}));return n.set(o.hash,d),d},replace(o){t=o;for(let[s,i]of n)o.has(s)||(URL.revokeObjectURL(i),n.delete(s))},destroy(){for(let o of n.values())URL.revokeObjectURL(o);n.clear(),t=new Map}}}var Qm="0.6.1",Bw="https://cdn.jsdelivr.net/npm/@getv.design/embed@0.6.1/fonts/";var rO=Symbol.for(`vdesign.embed.documents@${Qm}`),Vw=globalThis[rO]??=new WeakMap,oO=/^Line (\d+): /;function tx(e){let t=oO.exec(e.message);return{...t?{line:Number(t[1])}:{},code:e.code,message:e.message,severity:e.severity}}function ex(e){if(typeof e!="string")return ic(gi("").document,new Map,[{code:"not-text",message:`parse() takes .vd text, not ${e===null?"null":typeof e}.`,severity:"error"}]);let t=sO(e);if(t.vd===void 0)return ic(gi("").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}=Bl(t.vd),o=gi(n),s=o.problems.map(tx).map(i=>i.line===void 0?i:{...i,line:i.line+t.offset});return ic(o.document,r,s)}function sO(e){if(!nf(e))return{vd:e,offset:0};let t=tf(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 a=e.indexOf(">",n)+1,d=e.slice(0,a).split(`
3099
+ `).length-1;return{vd:t,offset:d+(e[a]===`
2892
3100
  `?1:0)}}let s=o+9,i=e.slice(0,s).split(`
2893
3101
  `).length-1;return{vd:t,offset:i+(e[s]===`
2894
- `?1:0)}}function va(e,t,n){let r=Object.freeze({});return ng.set(r,{document:e,blocks:t,problems:n}),{document:r,problems:n}}function rg(e,t,n){return va(e,t,[...n]).document}function ya(e){let t=ng.get(e);if(!t)throw new TypeError("Not a vDesign document: pass .vd text or what parse() returned.");return t}async function og(e){if(typeof e=="string")return ya(tc(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 ya(tc(await t.text()).document)}return b1(e)?ya(tc(await e.text()).document):ya(e)}function b1(e){let t=e;return typeof t.text=="function"&&typeof t.size=="number"}function Kr(e){return e.root.children.filter(t=>t.type==="frame"&&t.hidden!==!0&&t.component!==!0)}function sg(e,t){let n=Kr(e),r=typeof t=="number"?n[t]:n.find(o=>o.id===t);if(!r){let o=n.map(s=>s.id).join(", ")||"none";throw new RangeError(`No page ${JSON.stringify(t)} in this document; its pages: ${o}.`)}return r}var rc=["page","content","none"],ig=24;function us(e){let t=e.getBoundingClientRect();return{width:t.width,height:t.height}}function ag(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 dg(e,t,n,r){if(n==="none")return;let o=n==="page"?ag(e,r):void 0;if(!o){e.fitToContent(ig);return}let s=us(t);e.setCamera(Rt(o,{width:s.width||o.width,height:s.height||o.height},ig))}function lg(e,t,n){let r=e.getCamera(),o=us(t),s={x:(o.width/2-r.x)/r.zoom,y:(o.height/2-r.y)/r.zoom},i;for(let d of Kr(e.getDocument())){let l=ag(e,d.id);if(!l)continue;let f=Math.max(l.x-s.x,0,s.x-(l.x+l.width)),p=Math.max(l.y-s.y,0,s.y-(l.y+l.height)),m=Math.hypot(f,p);(!i||m<i.distance)&&(i={id:d.id,distance:m})}return i?.id??n}function ug(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 oc=Symbol.for("vdesign.embed.handover");function fg(e){return e[oc]}var cg=["exact","browser"],pg=["change"],w1=250;async function TL(e,t,n={}){let r=n.fit??"page";if(!rc.includes(r))throw new TypeError(`edit: fit must be one of ${rc.join(", ")}; got ${String(r)}.`);let o=n.fonts??"exact";if(!cg.includes(o))throw new TypeError(`edit: fonts must be one of ${cg.join(", ")}; got ${String(o)}.`);let s=o==="exact"?ug(n.fontBase,tg,e.ownerDocument.baseURI):void 0,i=fg(n),d=await og(t),l=i?.page!==void 0&&Kr(d.document).some(z=>z.id===i.page)?i.page:n.page===void 0?Kr(d.document)[0]?.id:sg(d.document,n.page).id,f=i?.exact&&s?await k1(s,d.document):void 0,p=e.ownerDocument,m=p.defaultView,y=new Map(d.blocks),v=eg(y),C=p.createElement("div");C.className="vd-embed vd-embed--edit",C.style.position="relative",C.style.width="100%",C.style.height="100%",e.appendChild(C);let S=z=>{n.onLink?n.onLink(z):m?.open(z,"_blank","noopener,noreferrer")},g;try{g=Yf(C,{document:d.document,chrome:n.toolbar??!0,interactive:n.interactive??!0,wheel:"modifier",resolveAsset:z=>v.resolve(z),importImage:D,onOpenLink:S,...n.surface?{surface:n.surface}:{},...i?{camera:i.camera}:{},...f?{fonts:f.library}:{}})}catch(z){throw C.remove(),v.destroy(),z}let L=new Set,A=!1,I=!1,U=0,j=i===void 0,R,q,$,V;function b(z){return $?.of!==z&&($={of:z,text:Vd(Hd(z),y)}),$.text}async function D(z){if(A||!z.type.startsWith("image/"))return null;let ce=new Uint8Array(await z.arrayBuffer()),Ee=await zd(ce);return A?null:(y.has(Ee)||y.set(Ee,Kd(ce)),{type:z.type,hash:Ee,bytes:ce.length})}function T(){U+=1;try{dg(g.viewer,C,r,l)}finally{U-=1}}let G=g.on("navigate",()=>{U===0&&(j=!1)}),Y=g.on("change",({document:z})=>{let ce={text:()=>b(z)};for(let Ee of[...L])Ee(ce);f&&P()}),re=us(C),E=m&&"ResizeObserver"in m?new m.ResizeObserver(()=>{let z=us(C);z.width===re.width&&z.height===re.height||(re=z,j&&T())}):void 0;E?.observe(C),i||T(),!f&&o==="exact"&&O();function k(){return q??=(async()=>{if(s)try{let{exactFontsAt:z}=await import("./chunks/fonts.js");return z(s)}catch{return}})(),q}async function O(){let z=await k();if(!(A||!z)){for(;;){let ce=g.getDocument(),Ee=await z.ensure(ce);if(A||Ee.length>0)return;if(g.getDocument()===ce)break}f=z,g.viewer.setFonts(z.library)}}function P(){R!==void 0&&clearTimeout(R),R=setTimeout(()=>{R=void 0;let z=f;A||!z||z.ensure(g.getDocument()).then(ce=>{A||f!==z||ce.length===0||(f=void 0,g.viewer.setFonts(void 0))})},w1)}function K(){A||(A=!0,R!==void 0&&clearTimeout(R),Y(),G(),E?.disconnect(),g.destroy(),v.destroy(),C.remove(),L.clear())}let Z={getText:()=>b(g.getDocument()),getDocument(){let z=g.getDocument();return V?.of!==z&&(V={of:z,document:rg(z,new Map(y),g.getProblems().map(nc))}),V.document},on(z,ce){if(!pg.includes(z))throw new TypeError(`edit: on() takes one of ${pg.join(", ")}; got ${String(z)}.`);return L.add(ce),()=>{L.delete(ce)}},undo(){A||g.undo()},redo(){A||g.redo()},async view(){if(A)throw new Error("edit: this editor was destroyed.");if(I)throw new Error("edit: view() is already opening a view.");I=!0,C.inert=!0;try{g.endTextEditing();let{view:z}=await import("./view.js");if(A)throw new Error("edit: this editor was destroyed.");l=lg(g.viewer,C,l);let ce={camera:g.viewer.getCamera(),page:l,exact:f!==void 0},Ee=g.getDocument(),Ae=await z(e,Z.getDocument(),{..._1(n),[oc]:ce});if(A)throw Ae.destroy(),new Error("edit: this editor was destroyed.");let Ce=g.getDocument()===Ee?void 0:Z.getDocument();return K(),Ce&&await Ae.load(Ce),Ae}finally{I=!1,C.inert=!1}},destroy:K};return Z}async function k1(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 _1(e){let{toolbar:t,...n}=e;return n}export{TL as edit,ec as version};
3102
+ `?1:0)}}function ic(e,t,n){let r=Object.freeze({});return Vw.set(r,{document:e,blocks:t,problems:n}),{document:r,problems:n}}function Hw(e,t,n){return ic(e,t,[...n]).document}function sc(e){let t=Vw.get(e);if(!t)throw new TypeError("Not a vDesign document: pass .vd text or what parse() returned.");return t}async function Uw(e){if(typeof e=="string")return sc(ex(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 sc(ex(await t.text()).document)}return iO(e)?sc(ex(await e.text()).document):sc(e)}function iO(e){let t=e;return typeof t.text=="function"&&typeof t.size=="number"}function $s(e){return e.root.children.filter(t=>t.type==="frame"&&t.hidden!==!0&&t.component!==!0)}function zw(e,t){let n=$s(e),r=typeof t=="number"?n[t]:n.find(o=>o.id===t);if(!r){let o=n.map(s=>s.id).join(", ")||"none";throw new RangeError(`No page ${JSON.stringify(t)} in this document; its pages: ${o}.`)}return r}var nx=["page","content","none"],jw=24;function aa(e){let t=e.getBoundingClientRect();return{width:t.width,height:t.height}}function Kw(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 Gw(e,t,n,r){if(n==="none")return;let o=n==="page"?Kw(e,r):void 0;if(!o){e.fitToContent(jw);return}let s=aa(t);e.setCamera(bn(o,{width:s.width||o.width,height:s.height||o.height},jw))}function qw(e,t,n){let r=e.getCamera(),o=aa(t),s={x:(o.width/2-r.x)/r.zoom,y:(o.height/2-r.y)/r.zoom},i;for(let a of $s(e.getDocument())){let d=Kw(e,a.id);if(!d)continue;let c=Math.max(d.x-s.x,0,s.x-(d.x+d.width)),l=Math.max(d.y-s.y,0,s.y-(d.y+d.height)),p=Math.hypot(c,l);(!i||p<i.distance)&&(i={id:a.id,distance:p})}return i?.id??n}function Ww(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 rx=Symbol.for("vdesign.embed.handover");function Xw(e){return e[rx]}var Yw=["exact","browser"],Jw=["change"],aO=250;async function EV(e,t,n={}){let r=n.fit??"page";if(!nx.includes(r))throw new TypeError(`edit: fit must be one of ${nx.join(", ")}; got ${String(r)}.`);let o=n.fonts??"exact";if(!Yw.includes(o))throw new TypeError(`edit: fonts must be one of ${Yw.join(", ")}; got ${String(o)}.`);let s=o==="exact"?Ww(n.fontBase,Bw,e.ownerDocument.baseURI):void 0,i=Xw(n),a=await Uw(t),d=i?.page!==void 0&&$s(a.document).some(F=>F.id===i.page)?i.page:n.page===void 0?$s(a.document)[0]?.id:zw(a.document,n.page).id,c=i?.exact&&s?await dO(s,a.document):void 0,l=e.ownerDocument,p=l.defaultView,m=new Map(a.blocks),g=Fw(m),b=l.createElement("div");b.className="vd-embed vd-embed--edit",b.style.position="relative",b.style.width="100%",b.style.height="100%",e.appendChild(b);let w=F=>{n.onLink?n.onLink(F):p?.open(F,"_blank","noopener,noreferrer")},k;try{k=Rm(b,{document:a.document,chrome:n.toolbar??!0,interactive:n.interactive??!0,wheel:"modifier",resolveAsset:F=>g.resolve(F),importImage:P,merge:Zm,onOpenLink:w,...n.surface?{surface:n.surface}:{},...i?{camera:i.camera}:{},...c?{fonts:c.library}:{}})}catch(F){throw b.remove(),g.destroy(),F}let _=new Set,M=!1,R=!1,B=0,D=i===void 0,V,T,O,j;function $(F){return O?.of!==F&&(O={of:F,text:Vl(Fl(F),m)}),O.text}async function P(F){if(M||!F.type.startsWith("image/"))return null;let q=new Uint8Array(await F.arrayBuffer()),Y=await Hl(q);return M?null:(m.has(Y)||m.set(Y,zl(q)),{type:F.type,hash:Y,bytes:q.length})}function C(){B+=1;try{Gw(k.viewer,b,r,d)}finally{B-=1}}let G=k.on("navigate",()=>{B===0&&(D=!1)}),ee=k.on("change",({document:F})=>{let q={text:()=>$(F)};for(let Y of[..._])Y(q);c&&v()}),fe=aa(b),oe=p&&"ResizeObserver"in p?new p.ResizeObserver(()=>{let F=aa(b);F.width===fe.width&&F.height===fe.height||(fe=F,D&&C())}):void 0;oe?.observe(b),i||C(),!c&&o==="exact"&&be();function Se(){return T??=(async()=>{if(s)try{let{exactFontsAt:F}=await import("./chunks/fonts.js");return F(s)}catch{return}})(),T}async function be(){let F=await Se();if(!(M||!F)){for(;;){let q=k.getDocument(),Y=await F.ensure(q);if(M||Y.length>0)return;if(k.getDocument()===q)break}c=F,k.viewer.setFonts(F.library)}}function v(){V!==void 0&&clearTimeout(V),V=setTimeout(()=>{V=void 0;let F=c;M||!F||F.ensure(k.getDocument()).then(q=>{M||c!==F||q.length===0||(c=void 0,k.viewer.setFonts(void 0))})},aO)}function N(){M||(M=!0,V!==void 0&&clearTimeout(V),ee(),G(),oe?.disconnect(),k.destroy(),g.destroy(),b.remove(),_.clear())}let I={getText:()=>$(k.getDocument()),getDocument(){let F=k.getDocument();return j?.of!==F&&(j={of:F,document:Hw(F,new Map(m),k.getProblems().map(tx))}),j.document},on(F,q){if(!Jw.includes(F))throw new TypeError(`edit: on() takes one of ${Jw.join(", ")}; got ${String(F)}.`);return _.add(q),()=>{_.delete(q)}},undo(){M||k.undo()},redo(){M||k.redo()},async view(){if(M)throw new Error("edit: this editor was destroyed.");if(R)throw new Error("edit: view() is already opening a view.");R=!0,b.inert=!0;try{k.endTextEditing();let{view:F}=await import("./view.js");if(M)throw new Error("edit: this editor was destroyed.");d=qw(k.viewer,b,d);let q={camera:k.viewer.getCamera(),page:d,exact:c!==void 0},Y=k.getDocument(),Q=await F(e,I.getDocument(),{...uO(n),[rx]:q});if(M)throw Q.destroy(),new Error("edit: this editor was destroyed.");let Te=k.getDocument()===Y?void 0:I.getDocument();return N(),Te&&await Q.load(Te),Q}finally{R=!1,b.inert=!1}},destroy:N};return I}async function dO(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 uO(e){let{toolbar:t,...n}=e;return n}export{EV as edit,Qm as version};
2895
3103
  /*! Bundled license information:
2896
3104
 
2897
3105
  lucide/dist/esm/icons/a-large-small.mjs:
@@ -2910,8 +3118,11 @@ lucide/dist/esm/icons/blend.mjs:
2910
3118
  lucide/dist/esm/icons/check.mjs:
2911
3119
  lucide/dist/esm/icons/chevron-down.mjs:
2912
3120
  lucide/dist/esm/icons/chevron-right.mjs:
3121
+ lucide/dist/esm/icons/chevron-up.mjs:
3122
+ lucide/dist/esm/icons/circle-dashed.mjs:
2913
3123
  lucide/dist/esm/icons/circle.mjs:
2914
3124
  lucide/dist/esm/icons/component.mjs:
3125
+ lucide/dist/esm/icons/crop.mjs:
2915
3126
  lucide/dist/esm/icons/diamond.mjs:
2916
3127
  lucide/dist/esm/icons/droplet.mjs:
2917
3128
  lucide/dist/esm/icons/eye.mjs:
@@ -2927,6 +3138,7 @@ lucide/dist/esm/icons/metronome.mjs:
2927
3138
  lucide/dist/esm/icons/minus.mjs:
2928
3139
  lucide/dist/esm/icons/mouse-pointer-2.mjs:
2929
3140
  lucide/dist/esm/icons/move-horizontal.mjs:
3141
+ lucide/dist/esm/icons/move-up-right.mjs:
2930
3142
  lucide/dist/esm/icons/move-vertical.mjs:
2931
3143
  lucide/dist/esm/icons/music.mjs:
2932
3144
  lucide/dist/esm/icons/pause.mjs:
@@ -2937,16 +3149,24 @@ lucide/dist/esm/icons/plus.mjs:
2937
3149
  lucide/dist/esm/icons/redo-2.mjs:
2938
3150
  lucide/dist/esm/icons/rotate-cw.mjs:
2939
3151
  lucide/dist/esm/icons/scan-eye.mjs:
3152
+ lucide/dist/esm/icons/scan.mjs:
3153
+ lucide/dist/esm/icons/slash.mjs:
2940
3154
  lucide/dist/esm/icons/spline.mjs:
2941
3155
  lucide/dist/esm/icons/square-round-corner.mjs:
2942
3156
  lucide/dist/esm/icons/square.mjs:
3157
+ lucide/dist/esm/icons/squares-exclude.mjs:
3158
+ lucide/dist/esm/icons/squares-intersect.mjs:
3159
+ lucide/dist/esm/icons/squares-subtract.mjs:
3160
+ lucide/dist/esm/icons/squares-unite.mjs:
2943
3161
  lucide/dist/esm/icons/text-align-end.mjs:
2944
3162
  lucide/dist/esm/icons/text-align-center.mjs:
2945
3163
  lucide/dist/esm/icons/text-align-justify.mjs:
2946
3164
  lucide/dist/esm/icons/text-align-start.mjs:
3165
+ lucide/dist/esm/icons/triangle-alert.mjs:
2947
3166
  lucide/dist/esm/icons/type.mjs:
2948
3167
  lucide/dist/esm/icons/undo-2.mjs:
2949
3168
  lucide/dist/esm/icons/unlink.mjs:
3169
+ lucide/dist/esm/icons/video.mjs:
2950
3170
  lucide/dist/esm/icons/volume-2.mjs:
2951
3171
  lucide/dist/esm/icons/volume-x.mjs:
2952
3172
  lucide/dist/esm/icons/x.mjs: