@getv.design/embed 0.3.1 → 0.3.2
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/LICENSE +2 -2
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.txt +1 -1
- package/dist/auto.js +2 -2
- package/dist/chunks/{chunk-JIHH634P.js → chunk-4O7TKIQJ.js} +1 -1
- package/dist/chunks/chunk-LJWWEZ4W.js +2 -0
- package/dist/chunks/{chunk-JWI4TIMM.js → chunk-M76WR2LQ.js} +2 -2
- package/dist/chunks/{chunk-UAVO4POT.js → chunk-QH553HXY.js} +2 -2
- package/dist/chunks/{chunk-H7KHX34X.js → chunk-RMZR36ZE.js} +1 -1
- package/dist/chunks/{chunk-P57LNVS3.js → chunk-YWFEB275.js} +2 -2
- package/dist/chunks/fonts.js +2 -2
- package/dist/cli.js +2 -2
- package/dist/edit.js +2 -2
- package/dist/index.js +2 -2
- package/dist/markdown-it.js +2 -2
- package/dist/markdown.js +2 -2
- package/dist/marked.js +2 -2
- package/dist/rehype.js +2 -2
- package/dist/static.js +2 -2
- package/dist/view.js +2 -2
- package/package.json +2 -2
- package/dist/chunks/chunk-ACHGJ7UR.js +0 -2
package/dist/edit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.3.
|
|
1
|
+
/*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
2
|
function zt(e){return{expr:e}}function be(e){return typeof e=="object"&&e!==null&&typeof e.expr=="string"}var mn=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],jt=["left","center","right","justify"],qt=["top","middle","bottom"],Kt=["cover","contain","fill"],hn=["nonzero","evenodd"],xn=["butt","round","square"],gn=["miter","round","bevel"],Lu=["canvas","frame","group"];function Xo(e){return Lu.includes(e)}function ye(e){return Xo(e.type)}function Oe(e){return e.type==="group"}function re(e){return ye(e)?e.children:[]}var Ou={canvas:["w","h"],ellipse:["x","y","w","h","rotation","strokeWidth","opacity"],frame:["x","y","w","h"],group:[],image:["x","y","w","h","rotation","radius","opacity"],rect:["x","y","w","h","rotation","strokeWidth","radius","opacity"],text:["x","y","w","h","rotation","size","weight","lineHeight","letterSpacing","opacity"],vector:["x","y","w","h","rotation","strokeWidth","opacity"]};function yt(e){return Ou[e.type]}function se(e,t,n){if(t(e,n)!==!1&&ye(e))for(let r of e.children)se(r,t,e)}function U(e,t){let n;return se(e,r=>{if(n)return!1;r.id===t&&(n=r)}),n}function ct(e,t){let n;return se(e,(r,o)=>{r.id===t&&o&&(n=o)}),n}function Yo(e){return Du(e,"hidden")}function Jo(e){return Du(e,"locked")}function Du(e,t){let n=new Set,r=(o,a)=>{let i=a||o[t]===!0;i&&n.add(o.id);for(let l of re(o))r(l,i)};return r(e,!1),n}function Rr(e,t,n){let r,o=(a,i)=>{let l=i??(a[n]===!0?a.id:void 0);return a.id===t?(r=l,!0):re(a).some(d=>o(d,l))};return o(e,void 0),r}var yn=["design"],Gt="design";var Fr=[1,2,3,4],vt="doc";function Vn(e){return{type:"canvas",...e}}function Ui(e){return{type:"ellipse",...e}}function Zo(e){return{type:"frame",...e}}function Vi(e){return{type:"group",...e}}function zi(e){return{type:"image",...e}}function ji(e){return{type:"rect",...e}}function qi(e){return{type:"text",...e}}function Qo(e){return{type:"vector",...e}}function Br(e={}){return{version:4,kind:e.kind??Gt,...e.title===void 0?{}:{title:e.title},tokens:e.tokens??{},fonts:e.fonts??{},assets:e.assets??{},...e.motion===void 0||Object.keys(e.motion).length===0?{}:{motion:e.motion},root:e.root??Vn({id:vt,children:[]})}}function ea(e){let t=new Set;return se(e,n=>{t.add(n.id)}),t}function Wt(e,t){let n=ea(e),r=0;for(let o of n){if(!o.startsWith(`${t}.`))continue;let a=Number(o.slice(t.length+1));Number.isInteger(a)&&a>r&&(r=a)}return`${t}.${r+1}`}function pt(e){let t=e.trim();if(t.startsWith("#")){let r=t.slice(1);return r===""?void 0:{kind:"frame",id:r}}let n;try{n=new URL(t)}catch{return}if(!(n.protocol!=="https:"&&n.protocol!=="mailto:"))return{kind:"url",url:t}}var Hr=["beat","bar"];var px=/^(\d+(?:\.\d+)?)(beats?|bars?)$/;function vn(e){let t=px.exec(e);if(!t)return;let n=Number(t[1]);if(Number.isFinite(n))return{count:n,unit:t[2].startsWith("bar")?"bar":"beat"}}function bn(e,t){return`${String(Math.round(e*1e6)/1e6)}${t}${e===1?"":"s"}`}function wn(e){return typeof e=="string"&&vn(e)!==void 0}function mt(e){let t=e?.bpm;if(t===void 0)return;let n=e?.meter??4,r=6e4/t;return{bpm:t,meter:n,beat:r,bar:r*n}}function Ve(e,t,n){if(e===void 0)return n;if(typeof e=="number")return e;let r=vn(e);return!r||!t?n:r.count*(r.unit==="bar"?t.bar:t.beat)}function Ki(e,t,n){let r=t==="bar"?n.bar:n.beat,o=Math.ceil((e-1)/r);return Math.max(0,o)*r}function Ur(e){return`${Math.round(e)} ms`}var zn=36e5;var Gi=50,Wi=16e3,Xi=320,Vr=["from","volume","fadein","fadeout","loop"];function Yi(e,t){return e===t?!0:e===void 0||t===void 0?!1:e.asset===t.asset&&Vr.every(n=>e[n]===t[n])}function Ji(e,t){let n=e?.music;if(!n)return[];let r=mt(e),o=t[n.asset]?.ms,a=Ve(n.fadeout,r);return[{asset:n.asset,at:0,from:n.from??0,volume:n.volume??1,fadeIn:Ve(n.fadein,r,0),...a===void 0?{}:{fadeOut:a},loop:n.loop===!0,...o===void 0?{}:{sourceMs:o}}]}var qn=["cut","fade","push","slide"],zr=["cut","fade","rise","drop","pop","wipe","grow","count","draw"],jn=["cut","fade","rise","drop","pop"],jr=["pulse"],qr=["out","in","inout","linear","spring"],Kr=["word","letter"],Xt=["left","right","top","bottom"],Gr=400,bt=1e4,Yt=18e4,wt=7680;function Mt(e){let t=e.trim();return t==="back"?{kind:"back"}:t==="next"?{kind:"next"}:pt(t)}function At(e){return e===void 0||e.enter===void 0&&e.duration===void 0&&e.scroll!==!0&&e.length===void 0&&e.w===void 0&&e.h===void 0&&e.bpm===void 0&&e.meter===void 0&&e.music===void 0&&e.lines.length===0}function Kn(e){return e.camera===!0||e.enter!==void 0||e.exit!==void 0||e.emphasis!==void 0||e.go!==void 0}var mx=["id","camera","enter","exit","emphasis","from","by","stagger","duration","hold","delay","at","after","with","step","together","on","ease","pad","go"],hx=["camera","emphasis","from","by","stagger","hold","at","after","with","on","ease","pad"];function kn(e){return e===void 0?!1:e.length!==void 0||e.w!==void 0||e.h!==void 0||e.bpm!==void 0||e.meter!==void 0||e.music!==void 0?!0:e.lines.some(t=>hx.some(n=>t[n]!==void 0)||t.enter!==void 0&&!jn.includes(t.enter)||t.exit!==void 0&&!jn.includes(t.exit))}function ta(e,t){return e===t?!0:e===void 0||t===void 0||e.enter!==t.enter||e.duration!==t.duration||e.length!==t.length||e.w!==t.w||e.h!==t.h||e.bpm!==t.bpm||e.meter!==t.meter||!Yi(e.music,t.music)||e.scroll===!0!=(t.scroll===!0)||e.lines.length!==t.lines.length?!1:e.lines.every((n,r)=>{let o=t.lines[r];return mx.every(a=>n[a]===o[a])})}function Gn(e){let t=e.motion;if(!t)return[];let n=e.root.children.map(o=>o.id).filter(o=>o in t),r=Object.keys(t).filter(o=>!n.includes(o)).sort();return[...n,...r]}function $t(e){return new Set(e.root.children.filter(t=>t.type==="frame").map(t=>t.id))}function lt(e){let t=new Map;for(let n of e.root.children)n.type==="frame"&&se(n,r=>{t.set(r.id,n.id)});return t}function Zi(e){let t=new Set;return se(e,n=>{t.add(n.id)}),t}function Wn(e,t){let n=e.motion;if(!n)return[];let r=[],o=$t(e),a=lt(e),i=Zi(e.root),l=(d,u)=>{let p=t?.(d,u);return p===void 0?"":`Line ${p}: `};for(let d of Gn(e)){let u=n[d];if(!u)continue;if(!o.has(d)){r.push({severity:"warning",code:"motion-not-a-page",message:`${l(d)}motion ${d}: ${d} is not a page (a top-level frame), so none of it plays`,nodeId:d});continue}let p=new Set;for(let x of u.lines){let y=l(d,x.id);for(let v of["after","with"]){let w=x[v];w!==void 0&&!p.has(w)&&r.push({severity:"warning",code:"motion-anchor-missing",message:`${y}motion ${d}: ${v}=${w} names no line above, so it starts after the line above instead`,nodeId:x.id})}x.camera!==!0&&p.add(x.id);let k=i.has(x.id)?U(e.root,x.id):void 0;k&&r.push(...xx(x,k,y,d)),i.has(x.id)?a.get(x.id)!==d&&r.push({severity:"warning",code:"motion-wrong-page",message:`${y}motion ${d}: ${x.id} is not on ${d}, so Play skips it`,nodeId:x.id}):r.push({severity:"warning",code:"unknown-reference",message:`${y}motion ${d}: no node ${x.id}`,nodeId:x.id});let M=x.go===void 0?void 0:Mt(x.go);M?.kind==="frame"&&!vx(e,M.id)&&r.push({severity:"warning",code:"unknown-reference",message:`${y}motion ${d}: go=#${M.id} names no frame`,nodeId:x.id})}}return r}function xx(e,t,n,r){let o=[],a=(l,d)=>{o.push({severity:"warning",code:l,message:`${n}motion ${r}: ${d}`,nodeId:t.id})};if(e.camera===!0)return o;let i=e.enter??e.exit;return i==="count"&&(t.type!=="text"||!/\d/.test(Jt(t.content)))&&a("count-no-number",`${t.id} has no number to count, so it fades in instead`),i==="draw"&&!yx(t)&&a("draw-no-stroke",`${t.id} has no stroked vector to draw, so it fades in instead`),e.by!==void 0&&t.type!=="text"?a("by-not-text",`by=${e.by} splits text, and ${t.id} is a ${t.type}`):e.by!==void 0&&t.type==="text"&&gx(t)&&a("by-rotated",`${t.id} is rotated, so by=${e.by} enters it whole`),e.stagger!==void 0&&e.by===void 0&&re(t).length===0&&a("stagger-no-children",`${t.id} has no children to stagger: split a text with by=word`),o}function gx(e){let t=e.rotation;return t!==void 0&&t!==0}function yx(e){let t=!1;return se(e,n=>(n.type==="vector"&&n.stroke!==void 0&&(t=!0),t?!1:void 0)),t}function Jt(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function vx(e,t){let n=!1;return se(e.root,r=>{if(n)return!1;r.id===t&&(n=r.type==="frame")}),n}function Pu(e,t){let n=t.motion;if(!n||!e.motion)return n;let r=lt(e),o=lt(t),a=Zi(e.root),i=Zi(t.root),l=x=>a.has(x)&&!i.has(x),d=!1,u={},p=[];for(let[x,y]of Object.entries(n)){if(l(x)){d=!0;continue}let k=[];for(let v of y.lines){let w=v,D=v.go===void 0?void 0:Mt(v.go);if(D?.kind==="frame"&&l(D.id)){let A=wx(v);w=Kn(A)?A:void 0,d=!0}if(w&&(w.after!==void 0&&l(w.after)||w.with!==void 0&&l(w.with))&&(w=bx(w,l),d=!0),w&&l(v.id))w=void 0,d=!0;else if(w&&r.get(v.id)===x&&o.get(v.id)!==x){let A=o.get(v.id);A!==void 0&&p.push([A,w]),w=void 0,d=!0}w&&k.push(w)}let M={...y,lines:k};At(M)||(u[x]=M)}for(let[x,y]of p){let k=u[x]??{lines:[]};u[x]={...k,lines:[...k.lines,y]}}return d?Object.keys(u).length===0?void 0:u:n}function bx(e,t){let n={...e};return e.after!==void 0&&t(e.after)&&delete n.after,e.with!==void 0&&t(e.with)&&delete n.with,n}function wx(e){let t={...e};return delete t.go,t}function Qi(e,t){let n={...e};return t===void 0||Object.keys(t).length===0?delete n.motion:n.motion=t,n}function es(e,t){let n=Pu(e,t);if(n===t.motion)return[];let r=new Set([...Object.keys(t.motion??{}),...Object.keys(n??{})]),o=[];for(let a of r){let i=n?.[a];ta(t.motion?.[a],i)||o.push({op:"setMotion",page:a,value:i})}return o}var kx={canvas:["type","id","name","w","h","background","children"],frame:["type","id","name","x","y","w","h","background","clip","skip","blend","shadow","hidden","locked","children"],ellipse:["type","id","name","x","y","w","h","rotation","fill","stroke","strokeWidth","opacity","blend","shadow","hidden","locked"],group:["type","id","name","hidden","locked","children"],image:["type","id","name","x","y","w","h","rotation","src","fit","radius","opacity","blend","shadow","hidden","locked"],rect:["type","id","name","x","y","w","h","rotation","fill","stroke","strokeWidth","radius","opacity","blend","shadow","hidden","locked"],text:["type","id","name","x","y","w","h","rotation","content","font","size","weight","lineHeight","letterSpacing","align","valign","italic","fill","opacity","blend","shadow","hidden","locked"],vector:["type","id","name","x","y","w","h","rotation","view","d","fill","stroke","strokeWidth","opacity","rule","cap","join","blend","shadow","hidden","locked"]},_x=["text","font","size","weight","italic","underline","strike","fill","letterSpacing","link"],Sx=["family","fallback","faces"],Ex=["src","weight","style"],De=" ";function ts(e){let t=["{",`${De}"version": ${J(e.version)},`,`${De}"kind": ${JSON.stringify(e.kind)},`,...e.title===void 0?[]:[`${De}"title": ${JSON.stringify(e.title)},`],`${De}"tokens": ${Mx(e.tokens,De)},`];return Object.keys(e.fonts).length>0&&t.push(`${De}"fonts": ${Ax(e.fonts,De)},`),e.motion!==void 0&&t.push(`${De}"motion": ${Cx(e,De)},`),t.push(`${De}"root": ${Iu(e.root,De)}`,"}"),`${t.join(`
|
|
3
3
|
`)}
|
|
4
4
|
`}function Cx(e,t){let n=t+De,r=Gn(e).map(o=>`${n}${JSON.stringify(o)}: ${JSON.stringify(e.motion?.[o])}`).join(`,
|
|
@@ -2788,7 +2788,7 @@ button.vd-field__swatch:focus-visible {
|
|
|
2788
2788
|
}
|
|
2789
2789
|
`;function gr(e){if(e.getElementById(mm))return;let t=e.createElement("style");t.id=mm,t.textContent=hm,e.head.appendChild(t)}var on=["font","size","weight","italic","underline","strike","fill","letterSpacing","link"];function Pn(e){return typeof e=="string"?e===""?[]:[{text:e}]:e.flatMap(t=>typeof t=="string"?t===""?[]:[{text:t}]:t.text===""?[]:[t])}function In(e){return typeof e=="string"?e:e.map(t=>typeof t=="string"?t:t.text).join("")}function Nn(e){return In(e).length}function Dn(e){let t={};for(let n of on){let r=e[n];r!==void 0&&(t[n]=r)}return t}function ym(e,t){return on.every(n=>e[n]===t[n])}function w0(e,t){let n={text:e};for(let r of on){let o=t[r];o!==void 0&&(n[r]=o)}return n}function Oo(e){let t=Pn(e),n=[];for(let o of t){let a=n[n.length-1];if(a&&ym(Dn(a),Dn(o))){n[n.length-1]={...a,text:a.text+o.text};continue}n.push(o)}if(n.length===0)return"";let r=n[0];return n.length===1&&xm(r)?r.text:n.map(o=>xm(o)?o.text:o)}function xm(e){return on.every(t=>e[t]===void 0)}function lf(e,t,n){let[r,o]=di(t,n,Nn(e)),a=[],i=0;for(let l of Pn(e)){let d=i+l.text.length,u=Math.max(r,i),p=Math.min(o,d);p>u&&a.push({...l,text:l.text.slice(u-i,p-i)}),i=d}return Oo(a)}function yr(e,t,n,r,o){let a=Nn(e),[i,l]=di(t,n,a),d=o??Do(e,i),u=[],p=0,x=!1,y=()=>{x||r===""||(u.push(w0(r,d)),x=!0)};for(let k of Pn(e)){let M=p+k.text.length,v=Math.min(i,M);v>p&&u.push({...k,text:k.text.slice(0,v-p)}),i>=p&&i<=M&&y();let w=Math.max(l,p);M>w&&u.push({...k,text:k.text.slice(w-p)}),p=M}return y(),Oo(u)}function Do(e,t){let n=Pn(e);if(n.length===0)return{};let r=0,o=n[0];for(let a of n){let i=r+a.text.length;if(t>r&&t<=i)return Dn(a);if(t<=r)return Dn(o);o=a,r=i}return Dn(o)}function df(e,t,n,r){let[o,a]=di(t,n,Nn(e));if(o===a)return Oo(e);let i=Object.keys(r),l=[],d=0;for(let u of Pn(e)){let p=d+u.text.length;for(let[x,y,k]of k0(d,p,o,a)){if(y<=x)continue;let M=u.text.slice(x-d,y-d);if(!k){l.push({...u,text:M});continue}let v={...u,text:M};for(let w of i)r[w]===void 0?delete v[w]:v[w]=r[w];l.push(v)}d=p}return Oo(l)}function k0(e,t,n,r){return[[e,Math.min(t,n),!1],[Math.max(e,n),Math.min(t,r),!0],[Math.max(e,r),t,!1]]}function ff(e,t,n){let[r,o]=di(t,n,Nn(e));if(r===o)return Do(e,r);let a,i=0;for(let l of Pn(e)){let d=i+l.text.length;if(Math.min(d,o)>Math.max(i,r)){let u=Dn(l);if(!a)a=u;else{let p={};for(let x of on)a[x]===u[x]&&a[x]!==void 0&&(p[x]=a[x]);a=p}}i=d}return a??{}}function di(e,t,n){let r=gm(Math.min(e,t),n),o=gm(Math.max(e,t),n);return[r,o]}function gm(e,t){return Math.max(0,Math.min(Math.round(e),t))}function vr(e,t){let n=[],r=0;return e.lines.forEach((o,a)=>{let i=o.spans.map(p=>p.text).join(""),l=i===""?r:_0(t,i,r),d=l+i.length,u=a===e.lines.length-1;n.push({start:l,end:u?t.length:d}),r=d}),n.length===0&&n.push({start:0,end:t.length}),n}function _0(e,t,n){let r=e.indexOf(t,n);return r===-1?n:r}function fi(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if(t<=r.end)return n}return Math.max(0,e.length-1)}function ui(e,t,n,r){let o=vr(e,t),a=fi(o,n),i=e.lines[a],l=o[a];if(!i||!l)return{x:0,y:0,h:0,line:0};let d=Math.max(0,Math.min(n-l.start,bm(i))),u=(S0(i,d)??i.style)?.fill;return{x:uf(i,d,r),y:i.y,h:i.h,line:a,...u!==void 0?{fill:u}:{}}}function S0(e,t){let n=0;for(let r of e.spans)if(n+=[...r.text].length,t<=n)return r.style;return e.spans[e.spans.length-1]?.style}function Po(e,t,n,r){let o=vr(e,t);if(e.lines.length===0)return 0;let a=e.lines.findIndex(d=>n.y<d.y+d.h);a===-1&&(a=e.lines.length-1);let i=e.lines[a];return o[a].start+vm(i,n.x,r)}function vm(e,t,n){let r=0,o=1/0,a=0,i=(l,d)=>{let u=Math.abs(d-t);u<o&&(o=u,r=l)};i(0,e.spans[0]?.x??0);for(let l of e.spans){let d=[...l.text],u=0;d.forEach((p,x)=>{u=n.advance(d.slice(0,x+1).join(""),l.style),i(a+x+1,l.x+u)}),a+=d.length}return r}function uf(e,t,n){let r=0,o=e.spans[0]?.x??0;for(let a of e.spans){let i=[...a.text];if(t<=r)return a.x;if(t>=r+i.length){o=a.x+a.w,r+=i.length;continue}let l=i.slice(0,t-r).join("");return a.x+n.advance(l,a.style)}return o}function bm(e){return e.spans.reduce((t,n)=>t+[...n.text].length,0)}function cf(e,t,n,r,o){let a=Math.min(n,r),i=Math.max(n,r);if(a===i)return[];let l=vr(e,t),d=[];return e.lines.forEach((u,p)=>{let x=l[p];if(!x)return;let y=Math.max(a,x.start),k=Math.min(i,x.end);if(k<=y)return;let M=bm(u),v=uf(u,Math.min(y-x.start,M),o),w=uf(u,Math.min(k-x.start,M),o),D=Math.max(w-v,k>x.end-1&&k>y?4:0);D>0&&d.push({x:v,y:u.y,w:D,h:u.h})}),d}function pf(e,t,n,r,o){let a=vr(e,t),l=fi(a,n)+r,d=e.lines[l],u=a[l];if(!d||!u)return r===-1?0:t.length;let p=ui(e,t,n,o);return Math.min(u.start+vm(d,p.x,o),u.end)}var E0=/[\p{L}\p{N}_]/u;function mf(e,t){let n=Math.max(0,Math.min(t,e.length)),r=l=>E0.test(e[l]??""),o=n;if(!r(o)&&o>0&&r(o-1)&&(o-=1),!r(o))return{from:n,to:n};let a=o,i=o;for(;a>0&&r(a-1);)a-=1;for(;i<e.length&&r(i);)i+=1;return{from:a,to:i}}function ci(e,t,n){let r=vr(e,t),o=r[fi(r,n)];return o?{from:o.start,to:o.end}:{from:0,to:t.length}}var Sm=700;function hf(e){let t=0,n=0,r=null,o=!1,a=0,i=!1,l=0,d=0;function u(){return In(e.content())}function p(E){return Math.max(0,Math.min(Math.round(E),u().length))}function x(){return{from:Math.min(t,n),to:Math.max(t,n)}}function y(E,T=E){let P=t!==E||n!==T;t=p(E),n=p(T),P&&k(),r=null,e.invalidate()}function k(){o=!1,a&&(clearTimeout(a),a=0)}function M(){a&&clearTimeout(a),a=setTimeout(k,Sm)}function v(E,T){e.write(E,o,T),o=!0,M()}function w(E,T){let{from:P,to:V}=x(),X=r??void 0;v(yr(e.content(),P,V,E,X),T),t=n=P+E.length,r=null,e.invalidate()}function D(E,T){E!==T&&(v(yr(e.content(),E,T,""),"Delete text"),t=n=Math.min(E,T),e.invalidate())}function A(E,T){let{from:P,to:V}=x();if(P!==V){D(P,V);return}let X=u();if(E===-1){if(P===0)return;let I=T?km(X,P):P-1;D(I,P);return}if(P>=X.length)return;let te=T?_m(X,P):P+1;D(P,te)}function H(E,T){let P=u();return T?E===-1?km(P,n):_m(P,n):p(n+E)}return{id:e.id,getSelection:()=>({anchor:t,head:n}),setSelection(E,T){y(E,T??E)},caret(){return ui(e.layout(),u(),n,e.measure())},highlight(){let{from:E,to:T}=x();return cf(e.layout(),u(),E,T,e.measure())},pointTo(E,T){let P=Po(e.layout(),u(),E,e.measure());y(T?t:P,P)},selectWordAt(E){let T=Po(e.layout(),u(),E,e.measure()),P=mf(u(),T);y(P.from,P.to)},selectLineAt(E){let T=Po(e.layout(),u(),E,e.measure()),P=ci(e.layout(),u(),T);y(P.from,P.to)},selectAll(){y(0,u().length)},format(E){let{from:T,to:P}=x();if(T===P){r={...Do(e.content(),T),...E},e.invalidate();return}k(),v(df(e.content(),T,P,E),"Format text"),k(),e.invalidate()},activeMark(){if(r)return r;let{from:E,to:T}=x();return ff(e.content(),E,T)},composing:()=>i,handleKey(E){if(i)return!1;let T=E.metaKey||E.ctrlKey,P=E.altKey||E.ctrlKey&&!E.metaKey;switch(E.key){case"Escape":return e.close("escape"),!0;case"ArrowLeft":case"ArrowRight":{let V=E.key==="ArrowLeft"?-1:1,{from:X,to:te}=x();if(!E.shiftKey&&X!==te)y(V===-1?X:te);else{let I=T?wm(e,u(),n,V):H(V,P);y(E.shiftKey?t:I,I)}return!0}case"ArrowUp":case"ArrowDown":{let V=E.key==="ArrowUp"?-1:1,X=T?V===-1?0:u().length:pf(e.layout(),u(),n,V,e.measure());return y(E.shiftKey?t:X,X),!0}case"Home":case"End":{let V=wm(e,u(),n,E.key==="Home"?-1:1);return y(E.shiftKey?t:V,V),!0}case"Backspace":return A(-1,P||T),!0;case"Delete":return A(1,P||T),!0;case"Enter":return T?e.close("done"):w(`
|
|
2790
2790
|
`,"Type text"),!0;case"Tab":return!1;case"a":case"A":return T?(y(0,u().length),!0):!1;case"b":case"B":{if(!T)return!1;let V=this.activeMark().weight===700;return this.format({weight:V?void 0:700}),!0}case"i":case"I":return T?(this.format({italic:this.activeMark().italic===!0?void 0:!0}),!0):!1;case"u":case"U":return T?(this.format({underline:this.activeMark().underline===!0?void 0:!0}),!0):!1;default:return!1}},handleInput(E){if(!i)switch(E.inputType){case"insertText":case"insertReplacementText":case"insertFromPaste":case"insertFromDrop":case"insertFromYank":w(C0(E),"Type text");return;case"insertParagraph":case"insertLineBreak":w(`
|
|
2791
|
-
`,"Type text");return;case"deleteContentBackward":case"deleteWordBackward":A(-1,E.inputType==="deleteWordBackward");return;case"deleteContentForward":case"deleteWordForward":A(1,E.inputType==="deleteWordForward");return;case"deleteByCut":case"deleteByDrag":{let{from:T,to:P}=x();D(T,P);return}default:return}},handleCompositionStart(){i=!0;let{from:E,to:T}=x();l=E,d=T,k()},handleCompositionUpdate(E){v(yr(e.content(),l,d,E),"Type text"),d=l+E.length,t=n=d,e.invalidate()},handleCompositionEnd(E){v(yr(e.content(),l,d,E),"Type text"),i=!1,d=l+E.length,t=n=d,k(),e.invalidate()},breakBurst:k,destroy(){k()}}}function C0(e){return typeof e.data=="string"?e.data:e.dataTransfer?.getData("text/plain")??""}function wm(e,t,n,r){let o=ci(e.layout(),t,n);return r===-1?o.from:o.to}var pi=/[\p{L}\p{N}_]/u;function km(e,t){let n=t;for(;n>0&&!pi.test(e[n-1]??"");)n-=1;for(;n>0&&pi.test(e[n-1]??"");)n-=1;return n}function _m(e,t){let n=t;for(;n<e.length&&!pi.test(e[n]??"");)n+=1;for(;n<e.length&&pi.test(e[n]??"");)n+=1;return n}function xf(e){return Nn(e)===0}var gf={v:"select",f:"frame",r:"rect",o:"ellipse",p:"pen",t:"text"};function br(e,t){let n=[];for(let r of t){if(!U(e.root,r.nodeId))continue;let o=ee(r.to);ee(r.from)!==o&&n.push({op:"set",id:r.nodeId,prop:r.prop,value:o})}return n}function ee(e){return Math.round(e*100)/100}function wr(e,t,n,r){let o=new Set,a=[];for(let d of t)d.op==="set"&&(o.add(Ke(d.id,d.prop)),a.push({nodeId:d.id,prop:d.prop}));if(a.length===0)return[];let i=[],l=new Set;for(let d of a)for(let u of n.get(Ke(d.nodeId,d.prop))??[]){let p=Ke(u.nodeId,u.prop);if(o.has(p)||l.has(p)||!U(e.root,u.nodeId))continue;let x=r.nodes.get(u.nodeId)?.values[u.prop];x!==void 0&&(l.add(p),i.push({op:"set",id:u.nodeId,prop:u.prop,value:ee(x)}))}return i}function yf(e,t,n,r={x:0,y:0}){let o=[],a=new Set,i=e;for(;;){let l=[],d=Ne(i);for(let[u,p]of t){let x=n.get(u),y=U(i.root,p),k=d.nodes.get(p);if(!(!x||!y||!k))for(let M of yt(y)){let v=Ke(p,M);if(a.has(v))continue;let w=x[M],D=k.values[M];if(w===void 0||D===void 0)continue;let A=w+(M==="x"?r.x:M==="y"?r.y:0);ee(A)!==ee(D)&&(a.add(v),l.push({op:"set",id:p,prop:M,value:ee(A)}))}}if(l.length===0)return o;o.push(...l),i=Ae(i,l).document}}function kr(e,t,n=new Set){let r=Ne(e),o=Ne(t),a=[];for(let[i,l]of o.nodes){if(n.has(i))continue;let d=r.nodes.get(i),u=U(t.root,i);if(!(!d||!u))for(let p of yt(u)){let x=d.values[p],y=l.values[p];x===void 0||y===void 0||ee(x)!==ee(y)&&a.push({op:"set",id:i,prop:p,value:ee(x)})}}return a}function mi(e,t,n){let r=new Set,o=[];for(let a of t)a.op==="set"&&a.prop==="view"&&r.add(a.id);for(let a of t){if(a.op!=="set"||a.prop!=="w"&&a.prop!=="h"||r.has(a.id))continue;let i=U(e.root,a.id);if(i?.type!=="vector"||i.view!==void 0)continue;let l=n(a.id);l&&(r.add(a.id),o.push({op:"set",id:a.id,prop:"view",value:En({x:0,y:0,w:l.w,h:l.h})}))}return o.length===0?[...t]:[...o,...t]}var vf="host:",Em="#ffffff",Cm={w:1920,h:1080},M0=100,hi=20,A0=15,$0={ne:0,se:90,sw:180,nw:270,n:0,e:90,s:180,w:270},Mm={w:240,h:28},T0={text:"Add text",frame:"Add page",rect:"Draw rectangle",ellipse:"Draw ellipse"};function L0(e,t){let n=t.x-e.x,r=t.y-e.y,o=Math.max(Math.abs(n),Math.abs(r));return{x:e.x+Math.sign(n||1)*o,y:e.y+Math.sign(r||1)*o}}var O0={KeyA:"left",KeyD:"right",KeyW:"top",KeyS:"bottom",KeyH:"hcenter",KeyV:"vcenter"},D0={KeyH:"x",KeyV:"y"},P0={left:"Align left",hcenter:"Align horizontal centres",right:"Align right",top:"Align top",vcenter:"Align vertical centres",bottom:"Align bottom"},bf=null,I0=220,Am={lock:!0,hide:!0},N0=["x","y","w","h"],R0={front:"Bring to front",forward:"Bring forward",backward:"Send backward",back:"Send to back"},F0=11,an=2,B0=10;function kf(e,t){gr(e.ownerDocument),e.classList.add("vd-editor"),e.hasAttribute("tabindex")||(e.tabIndex=0);let n=t.document,r=[],o=t.tool??"select",a=null,i=null,l=null,d={ids:[],label:null},u=null,p=[],x=!1,y=new Set,k=null,M=!1,v=!1,w=null,D={...Am,...t.features},A=null,H=new $o,E=0,T=null,P={dx:0,dy:0},V=null,X=new Map,te=e.ownerDocument.createElement("div");te.style.position="absolute",te.style.inset="0",e.appendChild(te),e.style.touchAction="none";let I=La(te,{sample:fl,document:n,...t.camera?{camera:t.camera}:{},...t.surface?{surface:t.surface}:{},...t.interactive===void 0?{}:{interactive:t.interactive},...t.wheel?{wheel:t.wheel}:{},...t.resolveAsset?{resolveAsset:t.resolveAsset}:{},...t.fonts?{fonts:t.fonts}:{},onSceneChange:(s,f)=>{f===n&&de("scene",{scene:s,document:f})},onCameraChange:s=>{we?.setZoom(s.zoom),Q(),de("camera",s),!(E>0)&&(ae(),de("navigate",s))}}),fe=fm(e,s=>I.documentToScreen(s)),we=t.chrome===!1?null:Tp(e,{onTool:Vt,onUndo:Nr,onRedo:Wo,onZoomReset:()=>I.fitToContent(),onPlay:t.onPlay,playHint:t.playHint,formatKeys:t.formatKeys}),Se=t.chrome===!1?null:Za(e,{onCommand:jh,...t.formatKeys?{formatKeys:t.formatKeys}:{}}),me=n,ue=n,S=[],g=null,$=[],L=null,B=null,q=new Map,F=null,ne=null,ke=null,Me=[],_e=ot,We=null,G=null,Z=null,Y=null,N=!1,z=e.ownerDocument.createElement("textarea");z.className="vd-editor__input",z.setAttribute("aria-hidden","true"),z.tabIndex=-1,z.autocapitalize="off",z.autocomplete="off",z.spellcheck=!1,e.appendChild(z);function de(s,f){let c=X.get(s);if(c)for(let m of c)m(f)}function le(s,f){let c=X.get(s)??new Set;return c.add(f),X.set(s,c),()=>c.delete(f)}function Te(s){E+=1;try{s()}finally{E-=1}}function ae(){T!==null&&(e.ownerDocument.defaultView?.cancelAnimationFrame(T),T=null)}function Be(s){let f=I.linkAt(s),c=f===void 0?void 0:pt(f);return c?c.kind==="url"?t.onOpenLink?(t.onOpenLink(c.url),!0):!1:U(n.root,c.id)?(ce([c.id]),Le([c.id]),!0):!1:!1}function Le(s,f={}){if(g!==null)return V={target:s,options:f},!1;let c=eh(s);if(!c)return!1;let m=e.getBoundingClientRect(),h=m.width>0&&m.height>0,b=h?{width:m.width,height:m.height-Zm(m)}:{width:c.w+96,height:c.h+96},_=f.fit==="always"?Ja(c,b):jd(c,b,I.getCamera());if(!_)return!1;ae(),f.by==="person"&&de("navigate",_);let C=e.ownerDocument.defaultView,O=C?.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;if(f.animate===!1||O||!h||!C?.requestAnimationFrame)return Te(()=>I.setCamera(_)),!0;let R=I.getCamera(),j=C.performance.now();P={dx:0,dy:0};let W=xe=>{let K=Math.min(1,Math.max(0,(xe-j)/I0)),ve=K===1?_:Xp(R,_,Yp(K),b);Te(()=>I.setCamera(St(ve,P.dx,P.dy))),T=K===1?null:C.requestAnimationFrame(W)};return T=C.requestAnimationFrame(W),!0}function Zm(s){let f=we?.element.getBoundingClientRect();return!f||f.height===0?0:Math.max(0,s.bottom-f.top)}function Qm(s,f){T!==null&&(P={dx:P.dx+s,dy:P.dy+f}),Te(()=>I.setCamera(St(I.getCamera(),s,f)))}function Ro(){if(V===null||g!==null)return;let{target:s,options:f}=V;V=null,Le(s,f)}function eh(s){if(s==="content"){let c=I.getScene();return Ya([{x:c.x,y:c.y,w:c.width,h:c.height}])}let f=[];for(let c of zd(n,s)){let m=Ie(c);m&&f.push(m)}return Ya(f)}function Ct(s){return I.getResolution().nodes.get(s)}function Bt(s){let f=Ct(s);return f?{x:f.x,y:f.y,w:f.w,h:f.h}:void 0}function Ie(s){return On(s,n,I.getResolution())}function sn(s){let f=Ct(s);return f?{x:f.absX,y:f.absY,w:f.w,h:f.h}:void 0}function ln(s){return Ct(s)?.values.rotation??0}function Lf(){let s=Mr();if(s.length===0)return null;for(let f of s){let c=U(n.root,f);if(!c||!Ks.includes(c.type))return null}return s}function Sr(s,f=new Set){let c=I.getResolution(),m=null;return se(n.root,h=>{if(f.has(h.id)||!fn(h.id))return!1;if(h.type!=="frame")return;let b=c.nodes.get(h.id);if(!b)return!1;let _={x:b.absX,y:b.absY,w:b.w,h:b.h};if(!gt(_,s.x,s.y))return!1;m=h.id}),m}function dn(s){let f=Ct(s);return f?{x:f.absX,y:f.absY}:{x:0,y:0}}function Qe(){return A?.of!==n&&(A={of:n,hidden:Yo(n.root),locked:Jo(n.root)}),A}function fn(s){let{hidden:f,locked:c}=Qe();return!f.has(s)&&!c.has(s)}function ie(){return r.filter(fn)}function Er(s){let f=I.hitTest(s,m=>!Qe().locked.has(m));if(f===null)return null;let c=w===null||je(n.root,f).includes(w);return Ga(f,n,c?w:null)}function th(){return Ao(n,ie(),I.getResolution())}function Cr(){return ie().length<2?null:Jd(th())}function Fo(s){let f=[];for(let c of s)for(let m of Ln(c,n)){let h=Bt(m);h&&f.push({member:c,node:m,frame:h})}return f}function Bo(s,f){let c=U(n.root,s);if(!c)return"literal";let m=c[f];return m===void 0?"literal":wa(m).kind}function nh(s){let f=U(n.root,s),c={};if(!f)return c;let m=[...N0,..._o(f).map(h=>h.prop)];for(let h of m)c[h]=Bo(s,h);return c}function Of(s,f){let c="none";for(let m of s){let h=bi(m,f);if(h==="expression")return"expression";h==="token"&&(c="token")}return c}function bi(s,f){let c="none";for(let m of f){let h=Bo(s,m);if(h==="complex")return"expression";h==="token"&&(c="token")}return c}let et=null;function he(s,f){if(s.length===0)return;let c=da(n,mi(n,s,Bt)),m=Ae(n,c);n=m.document,et?(Si(et.started,et.label,c,m.inverse),et.started=!0):H.push({label:f,ops:c,inverse:m.inverse}),Ho(c,f)}function rh(s){et={label:s,started:!1}}function oh(){et=null}function Df(s,f){s.length!==0&&(n=Ae(n,s).document,Ho(s,f))}function Ho(s,f){a=null,ne=null,ke=null,I.update(n),we?.setHistory(H.canUndo,H.canRedo),Q(),de("change",{document:n,ops:s,label:f}),de("problems",wi())}function wi(){return[...I.getScene().problems,...js(n)]}function ce(s){let f=s.filter(m=>m!==n.root.id&&U(n.root,m)),c=f.length!==r.length||f.some((m,h)=>r[h]!==m);r=[...f],Z&&(f.length!==1||f[0]!==Z.id)&&(Z=null),c&&(Se?.close(),ke=null,de("selection",r)),Q()}function ah(s,f){let c=U(n.root,s);if(!c)return[];let m=I.getCamera().zoom;if(Math.min(f.w,f.h)*m<24)return[];let h=F0/m,b=Ct(s);return _o(c).flatMap(_=>{let C=b?.values[_.prop]??0,O=Bo(s,_.prop)!=="literal";return _.handles(f,C,h).map(R=>({id:R.id,at:R.at,bound:O}))})}function ih(){let s=[];for(let R of ie()){let j=Ie(R);j&&s.push(j)}let f=xt(s);if(!f)return null;let c=ie().length===1?ie()[0]:void 0,m=c===void 0?void 0:U(n.root,c),h=c===void 0||!m||ye(m),b=new Set,_=Mr();for(let R of _l){let j=Oa(R);_.some(W=>j.some(xe=>Bo(W,xe)!=="literal"))&&b.add(R)}let C=!h&&c!==void 0?ln(c):0,O=C!==0&&c!==void 0?sn(c):void 0;return{frame:O??f,...O?{rotation:C}:{},rotatable:Lf()!==null,handles:G===null,boundHandles:b,adjusters:G!==null||h||c===void 0||O?[]:ah(c,f)}}function Mr(){return[...new Set(ie().flatMap(s=>Ln(s,n)))]}function sh(s){if(!s)return null;if(g?.kind==="adjust")return`r ${ee(L??g.from)}`;if(g?.kind==="rotate")return`${ee(B??0)}\xB0`;if(!g&&ne&&ie().length===1){let f=Ct(ie()[0])?.values[ne.prop]??0;return`r ${ee(f)}`}return g?.kind==="move"?`${ee(s.frame.x)}, ${ee(s.frame.y)}`:`${ee(s.frame.w)} \xD7 ${ee(s.frame.h)}`}function lh(){let f=g!==null&&g.kind!=="space"&&g.kind!=="reorder"?null:Cr();if(!f)return{spacers:[],rings:[],lead:null};let c=g?.kind==="space"?g.spacer:null;return{spacers:Qd(f).map(m=>({id:m.id,axis:m.axis,at:m.at,label:m.id===(c??ke)?String(ee(m.gap)):null})),rings:ef(f).map(m=>({id:m.id,at:m.at})),lead:g?.kind==="reorder"?Ie(g.id)??null:null}}function Q(){if(!v)return;let s=$h(),f=s?null:ih(),c=a!==null&&!r.includes(a)&&!g?Ie(a)??null:null,m={...dm,...lh(),hover:c,members:ie().length>1?ie().flatMap(h=>Ie(h)??[]):[],box:f,badge:sh(f),caret:Pf(),textSelection:If(),draft:g?.kind==="create"?Tn(g.origin,g.current):null,draftEllipse:g?.kind==="create"&&o==="ellipse",marquee:g?.kind==="marquee"?Tn(g.origin,g.current):null,guides:g?_e.guides:[],measures:g?_e.measures:[],presence:d.ids.length===0?null:{frames:d.ids.flatMap(h=>Ie(h)??[]),label:d.label},highlight:Co(n,p).flatMap(h=>Ie(h.id)??[]),slots:Qh(),parked:r.filter(h=>!fn(h)).flatMap(h=>Ie(h)??[]),lockHint:uh(),path:s,turn:ch(),pageLabels:dh()};fe.render(m)}function dh(){if(i)return[];let s=I.getResolution().nodes;return n.root.children.flatMap(f=>{if(f.type!=="frame")return[];let c=s.get(f.id);if(!c)return[];let m=Mo(c),h=f.name;return[{id:f.id,frame:m,label:typeof h=="string"&&h!==""?h:f.id,state:r.includes(f.id)?"selected":a===f.id?"hover":"idle"}]})}function fh(s){let f=fe.pageLabelRect(s),c=U(n.root,s);if(!f||!c)return;let m=c.name,h=e.ownerDocument.createElement("input");h.className="vd-editor__rename",h.type="text",h.spellcheck=!1,h.value=typeof m=="string"&&m!==""?m:"",h.placeholder=s,h.setAttribute("aria-label",`Name of ${s}`),h.style.left=`${f.x-4}px`,h.style.top=`${f.y-2}px`,h.style.width=`${Math.max(120,f.w+40)}px`;let b=!1,_=C=>{if(b)return;b=!0;let O=h.value.trim();h.remove(),i=null,C&&O!==(typeof m=="string"?m:"")&&_u(s,"name",O===""?void 0:O,"Rename"),Q(),e.focus({preventScroll:!0})};h.addEventListener("keydown",C=>{C.stopPropagation(),C.key==="Enter"?(C.preventDefault(),_(!0)):C.key==="Escape"&&(C.preventDefault(),_(!1))}),h.addEventListener("pointerdown",C=>C.stopPropagation()),h.addEventListener("blur",()=>_(!0)),i=h,e.appendChild(h),Q(),h.focus(),h.select()}function uh(){if(l===null||g||!Qe().locked.has(l))return null;let s=Ie(l);return s?{frame:s,label:l}:null}function Uo(s){let f=I.itemOf(s);if(f?.kind!=="text")return null;let c=f.lines[0]?.y??f.y,m={lines:f.lines.map(h=>({y:h.y-c,h:h.h,baseline:h.baseline-c,w:h.w,spans:h.spans.map(b=>({text:b.text,style:b.style,x:b.x-f.x,w:b.w})),...h.style?{style:h.style}:{}})),width:Math.max(0,...f.lines.map(h=>h.w)),height:f.height};return{item:f,layout:m,top:c}}function ki(){return o==="text"?"text":o!=="select"?"crosshair":"arrow"}function Pf(){if(!G)return null;let s=Uo(G.id);if(!s)return null;let f=G.caret();return{x:s.item.x+f.x,y:s.top+f.y,h:f.h,...f.fill!==void 0?{fill:f.fill}:{}}}function If(){if(!G)return[];let s=Uo(G.id);return s?G.highlight().map(f=>({x:s.item.x+f.x,y:s.top+f.y,w:f.w,h:f.h})):[]}function _i(s){if(!G)return null;let f=Uo(G.id);if(!f)return null;let c=Ar(G.id,s);return{x:c.x-f.item.x,y:c.y-f.top}}function Ar(s,f){let c=ln(s),m=c===0?void 0:sn(s);return m?Ze(f,rt(m),-c):f}function ch(){let s=G?.id??Z?.id;if(s===void 0)return null;let f=ln(s),c=f===0?void 0:sn(s);return c?{angle:f,centre:rt(c)}:null}function ph(s){let f=U(n.root,s);if(!f||f.type!=="text"||typeof f.h!="number")return[];let c=I.itemOf(s);if(c?.kind!=="text")return[];let m=ee(Math.ceil(c.height));return m>f.h?[{op:"set",id:s,prop:"h",value:m}]:[]}function mh(s,f,c,m){let h=et?et.started:c,b=et?.label??m;et&&(et.started=!0);let _=[{op:"set",id:s,prop:"content",value:f}],C=Ae(n,_);n=C.document,I.update(n);let O=ph(s);if(O.length===0){Si(h,b,_,C.inverse),Ho(_,b);return}let R=Ae(n,O);n=R.document,I.update(n);let j=[..._,...O];Si(h,b,j,[...R.inverse,...C.inverse]),Ho(j,b)}function Si(s,f,c,m){let h={label:f,ops:c,inverse:m};s&&H.amend(h)||H.push(h)}function $r(s,f){let c=U(n.root,s);if(!c||c.type!=="text"||G?.id===s)return;un("done"),Vt("select"),ce([s]),G=hf({id:s,content:()=>{let h=U(n.root,s);return h?.type==="text"?h.content:""},layout:()=>Uo(s)?.layout??{lines:[],width:0,height:0},measure:()=>I.getMeasurer(),write:(h,b,_)=>mh(s,h,b,_),invalidate:()=>{Q(),Nf(),de("selection",r)},close:h=>un(h)});let m=f?_i(f):null;m?G.pointTo(m,!1):G.selectAll(),e.classList.add("vd-editor--editing"),z.value="",z.focus({preventScroll:!0}),Q(),Nf()}function un(s){let f=G;if(!f)return;G=null,N=!1,f.destroy(),e.classList.remove("vd-editor--editing","vd-editor--typing"),de("selection",r);let c=U(n.root,f.id);c?.type==="text"&&xf(c.content)&&(he([{op:"remove",id:f.id}],"Remove empty text"),ce([])),e.ownerDocument.activeElement===z&&e.focus({preventScroll:!0}),Q()}function Nf(){let s=Pf();if(!s)return;let f=I.documentToScreen({x:s.x,y:s.y});z.style.left=`${Math.round(f.x)}px`,z.style.top=`${Math.round(f.y)}px`}let Rn=0;function Rf(){e.classList.add("vd-editor--typing"),Rn&&clearTimeout(Rn),Rn=setTimeout(()=>{Rn=0,e.classList.remove("vd-editor--typing")},520)}function Ei(s){let f=br(me,s);return f.length>0&&F?[...f,...wr(me,f,q,F)]:f}function cn(s){Ci(Ei(s))}function Ci(s,f=s){let c=h=>{let b=F?.nodes.get(h);return b?{x:0,y:0,w:b.w,h:b.h}:void 0},m=mi(me,s,c);$=mi(me,f,c),I.update(m.length>0?Ae(me,m).document:me),Q()}function Ff(){let s=xt(ie().flatMap(m=>Ie(m)??[]));if(!s)return null;let f=new Map,c=new Map;for(let m of Mr()){let h=sn(m),b=Bt(m);!h||!b||(f.set(m,h),c.set(m,{x:h.x-b.x,y:h.y-b.y}))}return f.size===0?null:{bounds:s,frames:f,offsets:c}}function Bf(s,f){let c=Nd(s.frames,s.bounds,f),m=[];for(let[h,b]of c){let _=s.frames.get(h),C=s.offsets.get(h);if(!_||!C)continue;let O=ln(h),R=O===0?b:yp(_,O,s.bounds,f);m.push({nodeId:h,prop:"x",from:_.x-C.x,to:R.x-C.x},{nodeId:h,prop:"y",from:_.y-C.y,to:R.y-C.y},{nodeId:h,prop:"w",from:_.w,to:R.w},{nodeId:h,prop:"h",from:_.h,to:R.h})}return m}function hh(s,f){let c=Lf();if(!c)return!1;let m=ie().length===1&&c.length===1?c[0]:void 0,h=xt(ie().flatMap(C=>Ie(C)??[])),b=m!==void 0?sn(m):h;if(!b)return!1;let _=c.flatMap(C=>{let O=sn(C),R=Bt(C);return!O||!R?[]:[{id:C,frame:O,rotation:ln(C),offset:{x:O.x-R.x,y:O.y-R.y}}]});return _.length===0?!1:(st(f),tt({kind:"rotate",pointerId:f,origin:s,centre:rt(b),targets:_}),!0)}function xh(s,f,c){let m=Ff();return m?(st(c),tt({kind:"scale",pointerId:c,origin:s,handle:f,...m}),!0):!1}function gh(s){let f=Ff();if(!f)return;let c=br(n,Bf(f,s));if(c.length===0)return;let m=s.w!==f.bounds.w||s.h!==f.bounds.h;he([...c,...wr(n,c,ir(n),Ne(n))],m?"Resize":"Move")}function yh(s,f,c){let m=ii(s),h=Cr();if(!m||!h)return!1;let b=Et(h,m.axis)?.gaps[m.index],_=Fo(ie());return b===void 0||_.length===0?!1:(st(c),tt({kind:"space",pointerId:c,origin:f,axis:m.axis,spacer:s,layout:h,gap:b,parts:_}),!0)}function vh(s,f){let c=s.axis==="x"?f.x-s.origin.x:f.y-s.origin.y,m=Math.max(0,s.gap+c);cn(Mi(s.parts,s.axis,si(s.layout,s.axis,m)))}function bh(s,f){let c=Cr(),m=c?Et(c,s):void 0;if(!c||!m||m.gaps.length===0)return;let h=br(n,Mi(Fo(ie()),s,si(c,s,Math.max(0,f))));h.length!==0&&he([...h,...wr(n,h,ir(n),Ne(n))],"Spacing")}function wh(s){let f=Cr(),c=f?Et(f,s)?.gaps:void 0;return!c||c.length===0?null:Zd(c)?c[0]??null:"mixed"}function Mi(s,f,c){return s.map(m=>{let h=f==="x"?m.frame.x:m.frame.y;return{nodeId:m.node,prop:f,from:h,to:h+(c.get(m.member)??0)}})}function kh(s,f,c){let m=Cr();if(!m||!m.order.includes(s))return!1;let h=Fo(ie()),b=m.items.find(_=>_.id===s)?.frame;return h.length===0||!b?!1:(st(c),tt({kind:"reorder",pointerId:c,id:s,layout:m,parts:h,grab:{x:f.x-b.x,y:f.y-b.y},to:m.order.indexOf(s),swap:!1}),!0)}function _h(s,f,c){s.to=rf(s.layout,f),s.swap=c;let m=Sh(s),h=new Map(m);h.set(s.id,{x:f.x-s.grab.x,y:f.y-s.grab.y}),Ci(Ei(Hf(s,h)),Ei(Hf(s,m)))}function Sh(s){let f=s.layout.order.indexOf(s.id);if(f===-1||s.to===f)return new Map;if(s.swap){let c=s.layout.order[s.to];return c===void 0?new Map:sf(s.layout,s.id,c)}return af(s.layout,of(s.layout.order,f,s.to))}function Hf(s,f){let c=new Map(s.layout.items.map(h=>[h.id,h.frame])),m=[];for(let h of s.parts){let b=f.get(h.member),_=c.get(h.member);!b||!_||m.push({nodeId:h.node,prop:"x",from:h.frame.x,to:h.frame.x+(b.x-_.x)},{nodeId:h.node,prop:"y",from:h.frame.y,to:h.frame.y+(b.y-_.y)})}return m}function tt(s,f=[],c=n){ue=c,S=f,me=n,g=s,$=[],q=ir(n),F=Ne(n),_e=ot,Me=Eh(s)?Fd(n,F,Ch(s)):[]}function Eh(s){return s.kind==="move"||s.kind==="resize"||s.kind==="scale"||s.kind==="create"}function Ch(s){return s.kind==="move"||s.kind==="scale"?new Set(ie()):s.kind==="resize"?new Set([s.id]):new Set}function Tr(s){return s.metaKey||s.ctrlKey?0:Rd/I.getCamera().zoom}function Ht(s){let f=[...S,...$];g=null,$=[],S=[],L=null,B=null,_e=ot,n=ue,I.update(n),he(f,s),Q()}function Mh(){let s=$.length>0?Ae(me,$).document:me,f=new Set(ie().flatMap(h=>Uf(h,s))),c=[];for(let h of ie()){let b=U(s.root,h),_=ct(s.root,h);if(!b||!_)continue;let C=Ie(h);if(!C)continue;let O={x:C.x+C.w/2,y:C.y+C.h/2},R=Sr(O,f)??n.root.id;if(R===_.id)continue;let j=U(s.root,R);if(!j||!ye(j))continue;c.push({op:"move",id:h,parent:R,index:re(j).length});let W={x:dn(_.id).x-dn(R).x,y:dn(_.id).y-dn(R).y};if(!(W.x===0&&W.y===0))for(let xe of Ln(h,s)){let K=Bt(xe);K&&(c.push({op:"set",id:xe,prop:"x",value:ee(K.x+W.x)}),c.push({op:"set",id:xe,prop:"y",value:ee(K.y+W.y)}))}}if(c.length===0)return[];let m=Ae(s,c).document;return[...c,...kr(s,m,f)]}function Uf(s,f){let c=U(f.root,s);if(!c)return[];let m=[];return se(c,h=>{m.push(h.id)}),m}function Ai(){if(!g)return;g=null,$=[],L=null,B=null,_e=ot;let s=S.length>0;n=ue,S=[],s&&ce(r.filter(f=>U(n.root,f))),I.update(n),Q()}let Ah=5,Vo=8;function Vf(s,f=n,c=I.getResolution()){let m=U(f.root,s),h=c.nodes.get(s);if(m?.type!=="vector"||!h)return;let b={x:h.absX,y:h.absY,w:Math.max(0,h.w),h:Math.max(0,h.h)};return{node:m,view:Jr(m.view,b.w,b.h),box:b}}function Lr(s,f=n,c=I.getResolution()){let m=Vf(s,f,c);if(m)return Lt(Yr(m.node.d).contours,Zr(m.view,m.box))}function Ut(s,f,c,m=n,h=I.getResolution()){let b=Vf(s,m,h);if(!b)return[];let{node:_,view:C,box:O}=b,R=Lt(f,ns(C,O)),j=[],W=(ut,Un,cx)=>{Un!==cx&&j.push({op:"set",id:s,prop:ut,value:Un})};W("d",Tt(R),_.d);let xe=[_.x,_.y,_.w,_.h].every(ut=>typeof ut=="number"),K=Sn(R),ve=Sn(f);if(!c||!xe||!K||!ve)return j;let He=O.x-_.x,Ue=O.y-_.y;return W("view",En(K),_.view),W("x",ee(ve.x-He),_.x),W("y",ee(ve.y-Ue),_.y),W("w",ee(ve.w),_.w),W("h",ee(ve.h),_.h),j}function pn(s){return U(n.root,s)?.type!=="vector"||!fn(s)?!1:(G&&un("done"),Y&&zo(),ce([s]),Z={id:s,picked:new Set},o!=="select"&&Vt("select"),it(null),Q(),!0)}function Or(){Z&&(Z=null,Q())}function $h(){if(Y){let c=Y.contours[Y.contour],m=c?.anchors??[],h=m[m.length-1],b=m[0],_=Y.hover,C=_!==null&&b!==void 0&&m.length>=2&&!c?.closed&&Dr(b,_)<=Vo;return{contours:Y.contours,anchors:m.map((O,R)=>({key:Re(Y?.contour??0,R),at:O,selected:R===m.length-1})),handles:h?Ll(Y.contours,new Set([Re(Y.contour,m.length-1)])):[],pending:h&&_&&!Y.dragging&&!c?.closed?{from:h,...h.out?{c1:h.out}:{},to:_}:null,closeAt:C?b:null}}if(!Z)return null;let s=Lr(Z.id);if(!s)return null;let f=new Set($l(s,Z.picked));return{contours:s,anchors:s.flatMap((c,m)=>c.anchors.map((h,b)=>({key:Re(m,b),at:h,selected:f.has(Re(m,b))}))),handles:Ll(s,f)}}function Dr(s,f){return Math.hypot(s.x-f.x,s.y-f.y)*I.getCamera().zoom}function Th(s,f,c,m){if(!Z)return!1;let h=Z.id,b=Lr(h);if(!b)return Z=null,!1;s.preventDefault(),st(s.pointerId);let _=fe.hitPath(f);if(_?.kind==="handle"){let O=vp(_.key),R=O?b[O.contour]?.anchors[O.index]:void 0;if(O&&R)return tt({kind:"pathHandle",pointerId:s.pointerId,id:h,start:b,contour:O.contour,index:O.index,side:O.side,smooth:Pa(R),last:b}),!0}if(_?.kind==="anchor")return s.altKey?(Z.picked=new Set([_.key]),he(Ut(h,bp(b,_.key),!1),"Convert point"),!0):(s.shiftKey?Z.picked.has(_.key)?Z.picked.delete(_.key):Z.picked.add(_.key):Z.picked.has(_.key)||(Z.picked=new Set([_.key])),tt({kind:"points",pointerId:s.pointerId,id:h,origin:c,start:b,keys:new Set(Z.picked),lead:_.key,moved:!1,last:b}),Q(),!0);let C=as(b,c);if(C&&C.distance*I.getCamera().zoom<=Ah){if(m>=2){let W=is(b,C.contour,C.segment,C.t);return Z.picked=new Set([Re(C.contour,C.segment+1)]),he(Ut(h,W,!1),"Add point"),!0}let O=b[C.contour],R=O.anchors[C.segment],j=O.anchors[(C.segment+1)%O.anchors.length];return tt({kind:"segment",pointerId:s.pointerId,id:h,origin:c,start:b,contour:C.contour,segment:C.segment,t:C.t,straight:!R?.out&&!j?.in,last:b}),!0}return tt({kind:"pointMarquee",pointerId:s.pointerId,origin:c,current:c,additive:s.shiftKey}),!0}function Lh(s,f,c,m){let h=Al(s.start,s.lead);if(!h||m===0)return{dx:f,dy:c};let b=h.x+f,_=h.y+c,C=m,O=m,R=f,j=c;return s.start.forEach((W,xe)=>W.anchors.forEach((K,ve)=>{s.keys.has(Re(xe,ve))||(Math.abs(K.x-b)<C&&(C=Math.abs(K.x-b),R=K.x-h.x),Math.abs(K.y-_)<O&&(O=Math.abs(K.y-_),j=K.y-h.y))})),{dx:R,dy:j}}function Oh(s,f){if(!g)return!1;let c=(m,h)=>{F&&Ci(Ut(h,m,!1,me,F))};switch(g.kind){case"points":{let m=f;s.shiftKey&&(m=ko(g.origin,f));let h={dx:m.x-g.origin.x,dy:m.y-g.origin.y};if(!g.moved&&Math.hypot(h.dx,h.dy)*I.getCamera().zoom<an)return!0;g.moved=!0;let{dx:b,dy:_}=s.shiftKey?h:Lh(g,h.dx,h.dy,Tr(s));return g.last=Ra(g.start,g.keys,b,_),c(g.last,g.id),!0}case"pathHandle":{let m=g.start[g.contour]?.anchors[g.index],h=s.shiftKey&&m?ko(m,f):f;return g.last=Ia(g.start,g.contour,g.index,g.side,h,{smooth:g.smooth,breakSmooth:s.altKey}),c(g.last,g.id),!0}case"segment":return g.last=kp(g.start,g.contour,g.segment,g.t,f.x-g.origin.x,f.y-g.origin.y,g.straight),c(g.last,g.id),!0;case"pointMarquee":return g.current=f,Q(),!0;default:return!1}}function Dh(s){if(!g)return!1;switch(g.kind){case"points":case"pathHandle":case"segment":{let f=g.kind!=="points"||g.moved,c=g.kind==="points"?g.keys.size===1?"Move point":"Move points":g.kind==="pathHandle"?"Adjust curve":"Reshape";return $=f&&F?Ut(g.id,g.last,!0,me,F):[],Ht(c),!0}case"pointMarquee":{let f=Tn(g.origin,g.current),c=g.additive;if(g=null,_e=ot,!Z)return!0;let m=I.getCamera().zoom;if(f.w*m<an&&f.h*m<an){if(I.hitTest(s)===Z.id)Z.picked=new Set;else{Or();let _=Er(s);ce(_===null?[]:[_])}return Q(),!0}let h=Lr(Z.id)??[],b=Tl(h).filter(_=>{let C=Al(h,_);return C!==void 0&>(f,C.x,C.y)});return Z.picked=new Set(c?[...Z.picked,...b]:b),Q(),!0}default:return!1}}function Ph(s){if(!Z)return!1;let f=Z.id,c=s.metaKey||s.ctrlKey;if(s.key==="Escape"||s.key==="Enter"&&!c)return s.preventDefault(),g?Ai():Or(),!0;let m=Lr(f);if(!m)return!1;let h=new Set($l(m,Z.picked));if(s.key==="Delete"||s.key==="Backspace"){if(s.preventDefault(),h.size===0)return!0;let O=wp(m,h);return Z.picked=new Set,O.length===0?(Or(),Hn(),!0):(he(Ut(f,O,!0),h.size===1?"Delete point":"Delete points"),!0)}let b=s.shiftKey?10:1,C={ArrowLeft:[-b,0],ArrowRight:[b,0],ArrowUp:[0,-b],ArrowDown:[0,b]}[s.key];return C&&!c?(s.preventDefault(),h.size>0&&he(Ut(f,Ra(m,h,C[0],C[1]),!0),"Nudge points"),!0):c&&s.key.toLowerCase()==="a"?(s.preventDefault(),Z.picked=new Set(Tl(m)),Q(),!0):c&&!s.shiftKey&&s.code==="KeyJ"?(s.preventDefault(),he(Ut(f,_p(m,h),!0),"Close path"),!0):!1}function Ih(s,f){if(s.preventDefault(),st(s.pointerId),!Y){Y=Nh(f)??{contours:[{closed:!1,anchors:[{x:f.x,y:f.y}]}],contour:0,target:null,hover:null,dragging:null};let _=Y.contours[Y.contour];Y.dragging={pointerId:s.pointerId,index:_.anchors.length-1,origin:f},Q();return}let c=Y.contours[Y.contour],m=c.anchors[0],h=c.anchors[c.anchors.length-1];if(m&&c.anchors.length>=2&&Dr(m,f)<=Vo){Y.contours[Y.contour]={...c,closed:!0},Y.dragging={pointerId:s.pointerId,index:0,origin:m},Q();return}let b=s.shiftKey&&h?ko(h,f):f;Y.contours[Y.contour]={...c,anchors:[...c.anchors,{x:b.x,y:b.y}]},Y.dragging={pointerId:s.pointerId,index:c.anchors.length,origin:b},Q()}function Nh(s){let f=r.length===1?r[0]:null;if(f===null||!fn(f))return null;let c=Lr(f);if(!c)return null;for(let m=0;m<c.length;m+=1){let h=c[m];if(h.closed||h.anchors.length<1)continue;let b=h.anchors[0],_=h.anchors[h.anchors.length-1],C=Dr(_,s)<=Vo,O=!C&&Dr(b,s)<=Vo;if(!C&&!O)continue;let R=[...c];return O&&(R[m]=Sp(h)),{contours:R,contour:m,target:f,hover:null,dragging:null}}return null}function Rh(s,f){if(!Y)return;let c=Y.dragging;if(!c||c.pointerId!==s.pointerId){let O=Y.contours[Y.contour],R=O?.anchors[O.anchors.length-1];Y.hover=s.shiftKey&&R?ko(R,f):f,Q();return}if(Dr(c.origin,f)<an)return;let m=Y.contours[Y.contour],h=m.anchors[c.index];if(!h)return;let b={x:2*h.x-f.x,y:2*h.y-f.y},_=s.altKey?h.in:b,C=[...m.anchors];C[c.index]={x:h.x,y:h.y,..._?{in:_}:{},out:f},Y.contours[Y.contour]={...m,anchors:C},Q()}function Fh(s){!Y?.dragging||Y.dragging.pointerId!==s.pointerId||(Hi(s.pointerId),Y.dragging=null,Y.contours[Y.contour]?.closed?zo():Q())}function zo(){if(!Y)return;let s=Y;Y=null;let f=s.contours[s.contour];if(!f||f.anchors.length<2){Q();return}if(s.target!==null){he(Ut(s.target,s.contours,!0),"Extend path"),Vt("select"),pn(s.target);return}let c=Sn(s.contours),m=f.anchors[0];if(!c)return;let h=Sr(m)??w??n.root.id,b=U(n.root,h)??n.root,_=dn(h),C=Lt(s.contours,R=>({x:R.x-c.x,y:R.y-c.y})),O=Wt(n.root,"path");he([{op:"insert",parent:h,index:re(b).length,node:Qo({id:O,x:ee(c.x-_.x),y:ee(c.y-_.y),w:ee(c.w),h:ee(c.h),view:En({x:0,y:0,w:c.w,h:c.h}),d:Tt(C),fill:"none",stroke:t.defaultStroke??"#1f2937",strokeWidth:2,cap:"round",join:"round"})}],"Draw path"),Vt("select"),pn(O)}function $i(s=ie()){let f=[],c=[];for(let m of s){let h=U(n.root,m),b=ct(n.root,m),_=Ct(m);if(!h||!b||!_||h.type!=="rect"&&h.type!=="ellipse")continue;let C=Math.max(0,_.w),O=Math.max(0,_.h),R=h.type==="rect"?ss(C,O,_.values.radius??0):ls(C,O),j=Qo({id:m,...h.name===void 0?{}:{name:h.name},x:h.x,y:h.y,w:h.w,h:h.h,view:En({x:0,y:0,w:C,h:O}),d:Tt(R),...h.fill===void 0?{}:{fill:h.fill},...h.stroke===void 0?{}:{stroke:h.stroke},...h.strokeWidth===void 0?{}:{strokeWidth:h.strokeWidth},...h.opacity===void 0?{}:{opacity:h.opacity},...h.hidden?{hidden:!0}:{},...h.locked?{locked:!0}:{}}),W=b.children.findIndex(xe=>xe.id===m);f.push({op:"remove",id:m},{op:"insert",parent:b.id,index:W,node:j}),c.push(m)}c.length!==0&&(he(f,c.length===1?"Convert to vector":`Convert ${c.length} to vector`),ce(c),c.length===1&&pn(c[0]))}function zf(){return ie().filter(s=>{let f=U(n.root,s)?.type;return f==="rect"||f==="ellipse"}).length}let Bh=450,jf=4,Pr={x:0,y:0,at:0,count:0};function Hh(s){let f=Date.now(),m=Math.abs(s.x-Pr.x)<=jf&&Math.abs(s.y-Pr.y)<=jf&&f-Pr.at<=Bh?Pr.count+1:1;return Pr={x:s.x,y:s.y,at:f,count:m},m}let qf=s=>{if(M=s.pointerType==="touch",M){y.add(s.pointerId),k=y.size===1?{pointerId:s.pointerId,screen:I.pointerPoint(s)}:null;return}if(s.button!==0||x)return;let f=I.pointerPoint(s),c=I.screenToDocument(f);We=c;let m=Hh(f);if(G){let O=_i(c),R=I.itemOf(G.id),j=Ar(G.id,c);if(O&&R&>(R,j.x,j.y)){s.preventDefault(),st(s.pointerId),N=!0,m>=3?G.selectLineAt(O):m===2?G.selectWordAt(O):G.pointTo(O,s.shiftKey),z.focus({preventScroll:!0}),Q();return}un("blur")}if(e.focus({preventScroll:!0}),o==="select"&&(s.metaKey||s.ctrlKey)&&Be(c)){s.preventDefault();return}if(o==="pen"){Ih(s,c);return}if(Z&&o==="select"&&Th(s,f,Ar(Z.id,c),m))return;if(o!=="select"){s.preventDefault(),st(s.pointerId),tt({kind:"create",pointerId:s.pointerId,origin:c,current:c}),Q();return}let h=ie().length===1?ie()[0]:null;if(h!==null){let O=U(n.root,h),R=fe.hitAdjuster(f),j=O&&R?Va(O,R.id):void 0,W=j?Ie(h):void 0;if(j&&W&&R){s.preventDefault(),st(s.pointerId),tt({kind:"adjust",pointerId:s.pointerId,id:h,adjuster:j,handleId:R.id,frame:W,from:Ct(h)?.values[j.prop]??0});return}let xe=O&&!ye(O)?fe.hitHandle(f):null,K=xe?Bt(h):void 0,ve=K?sn(h):void 0;if(xe&&K&&ve){s.preventDefault(),st(s.pointerId),tt({kind:"resize",pointerId:s.pointerId,origin:c,id:h,handle:xe.handle,frame:K,offset:{x:ve.x-K.x,y:ve.y-K.y},rotation:ln(h)});return}}let b=ie().length>0?fe.hitHandle(f):null;if(b&&xh(c,b.handle,s.pointerId)){s.preventDefault();return}let _=fe.hitPageLabel(f);if(_!==null){if(s.preventDefault(),w=null,s.shiftKey){ce(r.includes(_)?r.filter(O=>O!==_):[...r,_]);return}if(r.includes(_)||ce([_]),m===2){fh(_);return}Kf(c,s.pointerId,s.altKey);return}if(ie().length>0&&fe.hitRotate(f)!==null&&hh(c,s.pointerId)){s.preventDefault();return}if(ie().length>1){let O=fe.hitRing(f);if(O!==null&&kh(O,c,s.pointerId)){s.preventDefault();return}let R=fe.hitSpacer(f);if(R!==null&&yh(R,c,s.pointerId)){s.preventDefault();return}}let C=Er(c);if(C===null){s.preventDefault(),st(s.pointerId),w=null,s.shiftKey||ce([]),tt({kind:"marquee",pointerId:s.pointerId,origin:c,current:c});return}w!==null&&!je(n.root,C).includes(w)&&(w=null),s.shiftKey?ce(r.includes(C)?r.filter(O=>O!==C):[...r,C]):r.includes(C)||ce([C]),Kf(c,s.pointerId,s.altKey)&&s.preventDefault()};function Uh(s){G&&un("blur");let f=Er(I.screenToDocument(s));f!==null&&w!==null&&!je(n.root,f).includes(w)&&(w=null),f===null&&(w=null),ce(f===null?[]:[f])}function Kf(s,f,c){let m=n,h=[];if(c){let _=mu({x:0,y:0});_&&(h=_.ops,n=Ae(n,h).document,I.update(n),ce(_.ids))}let b=new Map;for(let _ of ie())for(let C of Ln(_,n)){let O=Bt(C);O&&b.set(C,O)}return b.size===0?(n=m,I.update(n),!1):(st(f),tt({kind:"move",pointerId:f,origin:s,frames:b,bounds:xt(ie().flatMap(_=>Ie(_)??[]))},h,m),!0)}let Gf=s=>{let f=I.pointerPoint(s);if(s.pointerType==="touch"){k?.pointerId===s.pointerId&&Math.hypot(k.screen.x-f.x,k.screen.y-f.y)>B0&&(k=null);return}if(We=I.screenToDocument(f),N&&G){let m=_i(We);m&&G.pointTo(m,!0);return}if(Y&&o==="pen"){Rh(s,We);return}if(!g){qh(f);return}if(g.pointerId!==s.pointerId)return;let c=We;if(!Oh(s,Z?Ar(Z.id,c):c))switch(g.kind){case"move":{let m=c.x-g.origin.x,h=c.y-g.origin.y;if(g.bounds){let _={...g.bounds,x:g.bounds.x+m,y:g.bounds.y+h};_e=Bd(_,Me,Tr(s)),m+=_e.dx,h+=_e.dy}let b=[];for(let[_,C]of g.frames)b.push({nodeId:_,prop:"x",from:C.x,to:C.x+m}),b.push({nodeId:_,prop:"y",from:C.y,to:C.y+h});cn(b);return}case"resize":{let{id:m,handle:h,frame:b,origin:_,offset:C,rotation:O}=g,R=c.x-_.x,j=c.y-_.y;if(O!==0){_e=ot;let K=hp(b,h,R,j,O);cn(Da(b,K).map(ve=>({nodeId:m,prop:ve,from:b[ve],to:K[ve]})));return}let W=It(b,h,R,j);_e=Xa({...W,x:W.x+C.x,y:W.y+C.y},h,Me,Tr(s)),R+=_e.dx,j+=_e.dy;let xe=It(b,h,R,j);cn(Da(b,xe).map(K=>({nodeId:m,prop:K,from:b[K],to:xe[K]})));return}case"scale":{let{handle:m,bounds:h,origin:b,frames:_,offsets:C}=g,O=c.x-b.x,R=c.y-b.y,j=It(h,m,O,R);_e=Xa(j,m,Me,Tr(s)),O+=_e.dx,R+=_e.dy,cn(Bf({bounds:h,frames:_,offsets:C},It(h,m,O,R)));return}case"space":vh(g,c);return;case"reorder":_h(g,c,s.metaKey||s.ctrlKey);return;case"rotate":{let{centre:m,origin:h,targets:b}=g,_=b[0],C=xp(m,h,c,_?.rotation??0,s.shiftKey?A0:void 0);B=lo((_?.rotation??0)+C);let O=[],R=b.length===1;for(let j of gp(b,m,C)){let W=b.find(xe=>xe.id===j.id);W&&(O.push({nodeId:j.id,prop:"rotation",from:W.rotation,to:j.rotation}),!R&&O.push({nodeId:j.id,prop:"x",from:W.frame.x-W.offset.x,to:ee(j.frame.x-W.offset.x)},{nodeId:j.id,prop:"y",from:W.frame.y-W.offset.y,to:ee(j.frame.y-W.offset.y)}))}cn(O);return}case"adjust":{let m=g.adjuster.valueAt(g.frame,g.handleId,c);L=m,cn([{nodeId:g.id,prop:g.adjuster.prop,from:g.from,to:m}]);return}case"create":{_e=Hd(c,Me,Tr(s));let m={x:c.x+_e.dx,y:c.y+_e.dy};g.current=s.shiftKey&&o!=="text"?L0(g.origin,m):m,Q();return}case"marquee":{g.current=c,Q();return}}},jo=s=>{if(s.pointerType==="touch"){if(y.delete(s.pointerId),k?.pointerId!==s.pointerId)return;k=null,s.type==="pointerup"&&Uh(I.pointerPoint(s));return}if(N){N=!1,Hi(s.pointerId),z.focus({preventScroll:!0});return}if(Y){Fh(s);return}if(!g||g.pointerId!==s.pointerId)return;Hi(s.pointerId);let f=I.screenToDocument(I.pointerPoint(s));if(!Dh(Z?Ar(Z.id,f):f))switch(g.kind){case"create":{let c=Tn(g.origin,g.current),m=o==="text"?"text":o==="frame"?"frame":o==="ellipse"?"ellipse":"rect";g=null,_e=ot,Q();let h=c.w<an||c.h<an;if(h&&m!=="text")return;let b=h?{x:c.x,y:c.y,w:Mm.w,h:Mm.h}:c,_=Sr({x:b.x,y:b.y})??w??n.root.id,C=U(n.root,_)??n.root,O=dn(_),R={x:Math.round(b.x-O.x),y:Math.round(b.y-O.y),w:Math.round(b.w),h:Math.round(b.h)},j=Wt(n.root,m);he([{op:"insert",parent:_,index:re(C).length,node:m==="text"?qi({...R,id:j,content:""}):m==="frame"?Zo({...R,id:j,background:Em,children:[]}):m==="ellipse"?Ui({...R,id:j,fill:t.defaultFill??"#3b82f6"}):ji({...R,id:j,fill:t.defaultFill??"#3b82f6"})}],T0[m]),ce([j]),Vt("select"),m==="text"&&$r(j);return}case"marquee":{let c=Tn(g.origin,g.current),m=s.shiftKey;if(g=null,_e=ot,c.w>=an||c.h>=an){let h=ux(c);ce(m?[...new Set([...r,...h])]:h)}Q();return}case"move":{let c=Mh();c.length>0&&($=[...$,...c]),Ht(S.length>0?"Duplicate":"Move");return}case"resize":Ht("Resize");return;case"scale":Ht(r.length===1?"Resize group":`Resize ${r.length} elements`);return;case"space":Ht("Spacing");return;case"reorder":Ht(g.swap?"Swap":"Reorder");return;case"adjust":Ht("Corner radius");return;case"rotate":Ht("Rotate");return}},Wf=s=>{if(xi(s.target))return;if(G){if(!((s.metaKey||s.ctrlKey)&&s.key.toLowerCase()==="z"))return;s.preventDefault(),G.breakBurst(),s.shiftKey?Wo():Nr();return}if(Y&&(s.key==="Enter"||s.key==="Escape")){s.preventDefault(),zo();return}if(Ph(s))return;if((s.metaKey||s.ctrlKey)&&s.shiftKey&&s.code==="KeyO"){if(zf()===0)return;s.preventDefault(),$i();return}if(s.key==="Enter"&&!$m(s)&&r.length===1){let m=r[0];if(U(n.root,m)?.type==="vector"&&pn(m)){s.preventDefault();return}}if(s.key==="Enter"&&!$m(s)&&r.length===1){let m=r[0];if(U(n.root,m)?.type==="text"){s.preventDefault(),$r(m);return}}if(s.code==="Space"&&!x){x=!0,qe(Fe("grab"));return}let f=s.metaKey||s.ctrlKey;if(f&&s.key.toLowerCase()==="z"){s.preventDefault(),s.shiftKey?Wo():Nr();return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyL"){if(!D.lock||r.length===0)return;s.preventDefault(),Bn(r,"locked");return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyH"){if(!D.hide||r.length===0)return;s.preventDefault(),Bn(r,"hidden");return}if(f&&s.key.toLowerCase()==="g"){s.preventDefault(),s.shiftKey?Ni():Ii();return}if(f&&s.key.toLowerCase()==="a"){s.preventDefault(),Fi();return}if(f&&!s.altKey&&s.key.toLowerCase()==="d"){s.preventDefault(),Di();return}if(s.altKey){let m=O0[s.code];if(m&&!f){s.preventDefault(),fu(m);return}let h=D0[s.code];if(h&&s.ctrlKey){s.preventDefault(),cu(h);return}}if(s.key==="]"||s.key==="["){if(r.length===0)return;s.preventDefault();let m=s.key==="]";Ri(f?m?"front":"back":m?"forward":"backward");return}if(s.key==="Escape"){g?Ai():w!==null?wu():ce([]);return}if(s.key==="Delete"||s.key==="Backspace"){if(r.length===0)return;s.preventDefault(),Hn();return}let c=f||s.altKey?void 0:gf[s.key.toLowerCase()];c&&Vt(c)};function Xf(){if(!G)return null;let s=U(n.root,G.id);if(s?.type!=="text")return null;let{anchor:f,head:c}=G.getSelection();return f===c?null:In(lf(s.content,f,c))}let Yf=s=>{if(xi(s.target))return;let f=Xf()??Ir();f!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",f))},Jf=s=>{if(xi(s.target))return;let f=Xf();if(f!==null&&G){s.preventDefault(),s.clipboardData?.setData("text/plain",f);let{anchor:m,head:h}=G.getSelection();G.breakBurst(),G.setSelection(m,h),G.handleInput({inputType:"deleteByCut",data:null});return}let c=Ir();c!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",c),Hn())},Zf=s=>{if(xi(s.target))return;s.preventDefault();let f=Ol(s.clipboardData);if(f&&!G){let m=ex();m?Oi(m,f):xu(f,We??void 0);return}let c=s.clipboardData?.getData("text/plain")||void 0;if(G&&c!==void 0){G.handleInput({inputType:"insertFromPaste",data:c});return}Li(c)},Qf=s=>{s.code==="Space"&&(x=!1,qe(Fe(ki())))},eu=s=>{if(!Se)return;s.preventDefault(),g&&Ai();let f=I.pointerPoint(s),c=I.screenToDocument(f),m=Er(c),h=Vh(c),b=I.hitTest(c),_=b!==null&&r.some(O=>je(n.root,b).includes(O));m===null?_||ce([]):r.includes(m)||ce([m]);let C=(t.menuExtras?.(r)??[]).map(O=>"separator"in O?O:{...O,id:`${vf}${O.id}`});Se.open(f,qd(zh(h),C))};function Vh(s){let{locked:f}=Qe(),c=[];for(let m of[...I.getScene().items].reverse()){if(!f.has(m.id)||!I.hitTest(s,b=>b===m.id))continue;let h=Rr(n.root,m.id,"locked");h!==void 0&&!c.includes(h)&&c.push(h)}return c}function zh(s=[]){let f=r.length===1?U(n.root,r[0]):void 0,c=[];if(f){let m=f;for(let h of yt(f)){let b=m[h];b===void 0||!be(b)||wa(b).kind!=="literal"&&c.push({prop:h,source:`=${b.expr}`})}}return{count:r.length,hasGroup:r.some(m=>{let h=U(n.root,m);return h!==void 0&&Oe(h)}),canPaste:bf!==null,isText:r.length===1&&U(n.root,r[0])?.type==="text",isVector:ie().length===1&&U(n.root,ie()[0])?.type==="vector",convertible:zf(),bound:c,lock:D.lock?r.every(m=>Qe().locked.has(m))?"unlock":"lock":null,hide:D.hide?r.every(m=>Qe().hidden.has(m))?"show":"hide":null,locksHere:s,anyLocked:Bi("locked").length>0,hiddenCount:Bi("hidden").length}}function jh(s){if(e.focus({preventScroll:!0}),s.startsWith(vf)){t.onMenuCommand?.(s.slice(vf.length),[...r]);return}if(s.startsWith("unlock:")){Fn([s.slice(7)],"locked",!1);return}if(s.startsWith("detach:")){let f=s.slice(7),c=r[0];c!==void 0&&Su(c,f);return}switch(s){case"copy":Ir();return;case"cut":hu();return;case"editText":{let f=r[0];f!==void 0&&$r(f);return}case"editPoints":{let f=r[0];f!==void 0&&pn(f);return}case"toVector":return $i();case"duplicate":return Di();case"paste":return Li();case"group":return Ii();case"ungroup":return Ni();case"front":case"forward":case"backward":case"back":return Ri(s);case"delete":return Hn();case"selectAll":return Fi();case"toggleLock":return Bn(r,"locked");case"toggleHidden":return Bn(r,"hidden");case"unlockAll":return Go("locked");case"showAll":return Go("hidden");case"fit":return I.fitToContent();case"zoom100":return I.setCamera({...I.getCamera(),zoom:1})}}let tu=s=>{if(M||o!=="select"||x||Z)return;let f=I.screenToDocument(I.pointerPoint(s)),c=I.hitTest(f,C=>!Qe().locked.has(C));if(c===null)return;let m=Ko().find(C=>C.id===c);if(m){s.preventDefault(),tx(m);return}let h=U(n.root,c);if(h?.type==="text"){s.preventDefault(),$r(c,f);return}if(h?.type==="vector"){s.preventDefault(),pn(c);return}let b=je(n.root,c),_=w===null?1:b.indexOf(w)+1;for(let C=Math.max(_,1);C<b.length;C+=1){let O=b[C];if(O===void 0)break;let R=U(n.root,O);if(!(!R||!Oe(R))){s.preventDefault(),bu(O),ce([b[C+1]??O]);return}}},nu=s=>Array.from(s.dataTransfer?.types??[]).includes("Files"),ru=()=>t.importImage!==void 0||t.importAudio!==void 0,ou=s=>{if(!nu(s)||!ru())return;s.preventDefault(),s.dataTransfer&&(s.dataTransfer.dropEffect="copy");let f=I.screenToDocument(I.pointerPoint(s)),c=yu(f)?.id??null;c!==u&&(u=c,Q())},au=s=>{s.relatedTarget instanceof Node&&e.contains(s.relatedTarget)||u!==null&&(u=null,Q())},iu=s=>{if(!nu(s)||!ru())return;s.preventDefault();let f=I.screenToDocument(I.pointerPoint(s)),c=yu(f);u=null,Q();let m=Array.from(s.dataTransfer?.files??[]),h=m.find(Cp);if(h&&t.importAudio){let _=Sr(f),C=_===null?void 0:lt(n).get(_),O=Ba(n),R=C!==void 0&&O.includes(C)?C:Ha(n,r,null)??C??null;R!==null&&gu(h,R);return}if(!t.importImage)return;let b=m.find(_=>_.type.startsWith("image/"));b&&(c?Oi(c,b):xu(b,f))},su=()=>{We=null,l=null,!g&&(a===null&&ne===null&&ke===null||(a=null,ne=null,ke=null,Q()))};function lu(){let s=ie().length===1?ie()[0]:void 0,f=s===void 0?void 0:U(n.root,s);return s!==void 0&&f&&!ye(f)?ln(s):0}function qh(s){if(x){qe(Fe("grab"));return}if(Z){it(null),qe(Fe("arrow"));return}if(o!=="select"){it(null),Ti(null),qo(null),qe(Fe(o==="text"?"text":"crosshair"));return}let f=ie().length===1?ie()[0]:null;if(f!==null){let b=fe.hitAdjuster(s);if(b){let _=U(n.root,f),C=_?Va(_,b.id):void 0;it(null),Ti(C?{id:b.id,prop:C.prop}:null),qe(Fe("radius",{badge:C?bi(f,[C.prop]):"none"}));return}Ti(null)}if(ie().length>0){let b=fe.hitHandle(s);if(b){it(null);let O=Oa(b.handle);qe(Fe("resize",{angle:Sl(b.handle)+lu(),badge:Of(Mr(),O)}));return}let _=fe.hitPageLabel(s);if(_!==null){it(_),qe(Fe("arrow"));return}let C=fe.hitRotate(s);if(C!==null){it(null),qe(Fe("rotate",{angle:$0[C]+lu()}));return}}let c=fe.hitPageLabel(s);if(c!==null){l=null,it(c),qe(Fe("arrow"));return}if(ie().length>1){if(fe.hitRing(s)!==null){it(null),qo(null),qe(Fe("grab"));return}let _=fe.hitSpacer(s),C=_===null?null:ii(_);if(_!==null&&C){it(null),qo(_),qe(Fe("resize",{angle:C.axis==="x"?0:90,badge:Of(Mr(),[C.axis])}));return}qo(null)}let m=I.screenToDocument(s),h=Er(m);l=Kh(m,h),it(h),Q(),qe(Fe("arrow",{badge:h===null?"none":bi(h,["x","y"])}))}function Kh(s,f){let c=I.hitTest(s);if(c===null||!Qe().locked.has(c))return null;let m=Rr(n.root,c,"locked");return m===void 0?null:f===null||je(n.root,m).includes(f)?m:null}function it(s){a!==s&&(a=s,Q())}function Ti(s){ne?.id!==s?.id&&(ne=s,Q())}function qo(s){ke!==s&&(ke=s,Q())}function qe(s){e.style.cursor!==s&&(e.style.cursor=s)}function Vt(s){o!==s&&(o=s,Y&&s!=="pen"&&zo(),s!=="select"&&Or(),we?.setTool(o),s!=="select"&&it(null),qe(Fe(ki())),de("tool",o))}function Gh(s){if(s.length===0)return null;if(s.length>1)return xt(s.map(m=>m.frame))??null;let f=s[0],c=ct(n.root,f.id);return c?On(c.id,n,I.getResolution())??null:null}function du(s,f,c){let m=br(n,Mi(Fo(r),s,f));m.length!==0&&he([...m,...wr(n,m,ir(n),Ne(n))],c)}function fu(s){let f=Ao(n,r,I.getResolution()),c=Gh(f);c&&du(Ua(s),Dl(f,c,s),P0[s])}function uu(s){let f=Ao(n,r,I.getResolution());if(f.length<3)return null;let c=tf(f,s),m=nf(c);return m===null?null:{gap:m,series:c}}function cu(s){let f=uu(s);f&&du(s,li(f.series,f.gap),s==="x"?"Distribute horizontally":"Distribute vertically")}function Wh(){let s=Co(n,r);if(s.length===0)return null;let f=I.getResolution(),c={};for(let m of s)se(m,h=>{let b=f.nodes.get(h.id)?.values;b&&(c[h.id]=b)});return{nodes:s,tokens:n.tokens,fonts:n.fonts,resolved:c}}function Xh(s){return new Map(Object.entries(s.resolved))}function Yh(s){let f=Object.entries(s.tokens).filter(([c])=>n.tokens[c]===void 0).map(([c,m])=>({op:"setToken",name:c,value:m}));for(let[c,m]of Object.entries(s.fonts))n.fonts[c]===void 0&&f.push({op:"setFont",name:c,family:m});return f}function pu(s,f,c){let{nodes:m,remap:h}=Od(s,n);if(m.length===0)return null;let b=Yh(s),_=b.length>0?Ae(n,b).document:n;m.forEach((R,j)=>{let W=s.nodes[j];if(!W)return;let xe=f(W,j,_),K={op:"insert",parent:xe.parent,index:xe.index,node:R};b.push(K),_=Ae(_,[K]).document});let C=yf(_,h,Xh(s),c);C.length>0&&(_=Ae(_,C).document);let O=Jh(m);return{ops:[...b,...C,...kr(n,_)],ids:[...h.values()].filter(R=>O.has(R))}}function Jh(s){let f=new Set;for(let c of s)f.add(c.id);return f}function mu(s){let f=Wh();return f?pu(f,(c,m,h)=>{let b=ct(h.root,c.id)??h.root,_=re(b).findIndex(C=>C.id===c.id);return{parent:b.id,index:_===-1?re(b).length:_+1}},s):null}function Ir(){let s=Td(n,r,I.getResolution());return s!==null&&(bf=s),s}function hu(){let s=Ir();return s!==null&&Hn(),s}function Zh(s){let f=[];for(let c of s.nodes){let m=s.resolved[c.id];if(!m)continue;let{x:h,y:b,w:_,h:C}=m;h===void 0||b===void 0||_===void 0||C===void 0||f.push({x:h,y:b,w:_,h:C})}return xt(f)??null}function Li(s,f){let c=Ld(s??bf??"");if(!c)return;let m=f??We,h=Zh(c),b=m&&h?{x:m.x-(h.x+h.w/2),y:m.y-(h.y+h.h/2)}:{x:hi,y:hi},_=w??n.root.id,C=pu(c,(O,R,j)=>({parent:_,index:re(U(j.root,_)??j.root).length}),b);C&&(he(C.ops,C.ids.length===1?"Paste":`Paste ${C.ids.length} elements`),ce(C.ids))}async function xu(s,f){let c=t.importImage;if(!c)return;let m=await Fa(s,t.maxImageEdge??2560);if(!m)return;let h=await c(new File([m.bytes],s.name,{type:m.type}));if(!h)return;let b=(f?Sr(f):void 0)??w??n.root.id,_=U(n.root,b)??n.root,C=dn(b),O=I.getResolution().nodes.get(b),{w:R,h:j}=Ep(m.width,m.height,O?.w&&O.w>0?O.w:m.width,O?.h&&O.h>0?O.h:m.height),W=f??We,xe=Math.round((W?W.x-R/2:C.x)-C.x),K=Math.round((W?W.y-j/2:C.y)-C.y),ve=nx(n,s.name),He=Wt(n.root,"image");he([{op:"setAsset",name:ve,value:h},{op:"insert",parent:b,index:re(_).length,node:zi({id:He,x:xe,y:K,w:R,h:j,src:ve,fit:"cover"})}],"Place image"),ce([He])}async function gu(s,f){let c=t.importAudio;if(!c)return!1;let m=await c(s);return m?(he(Ap(n,f,Mp(n,f,s.name),m),"Add music"),!0):!1}function Ko(){return t.importImage?um(n,Qe().hidden):[]}function Qh(){return Ko().flatMap(s=>{let f=Ie(s.id);return f?[{frame:f,label:s.label,target:s.id===u}]:[]})}function yu(s){return Ko().filter(c=>{let m=Ie(c.id);return m!==void 0&>(m,s.x,s.y)}).at(-1)??null}function ex(){return r.length!==1?null:Ko().find(s=>s.id===r[0])??null}async function Oi(s,f){let c=t.importImage;if(!c)return;let m=await Fa(f,t.maxImageEdge??2560);if(!m)return;let h=await c(new File([m.bytes],f.name,{type:m.type}));!h||n.assets[s.src]!==void 0||(he([{op:"setAsset",name:s.src,value:h}],"Add image"),ce([s.id]))}function tx(s){let f=e.ownerDocument.createElement("input");f.type="file",f.accept="image/*",f.addEventListener("change",()=>{let c=f.files?.[0];c&&Oi(s,c)}),f.click()}function nx(s,f){let c=f.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"image";if(s.assets[c]===void 0)return c;for(let m=2;;m+=1){let h=`${c}-${m}`;if(s.assets[h]===void 0)return h}}function Di(){let s=mu({x:hi,y:hi});s&&(he(s.ops,s.ids.length===1?"Duplicate":`Duplicate ${s.ids.length} elements`),ce(s.ids))}function Pi(s,f){if(s.length===0)return;let c=Ae(n,s).document;he([...s,...kr(n,c)],f)}function Ii(){let s=Dd(n,r);s&&(Pi(s.ops,"Group"),ce([s.groupId]))}function Ni(){let s=r.filter(h=>{let b=U(n.root,h);return b!==void 0&&Oe(b)});if(s.length===0)return;let f=n,c=[],m=[];for(let h of s){let b=U(f.root,h);b&&m.push(...re(b).map(C=>C.id));let _=Pd(f,h);_.length!==0&&(c.push(..._),f=Ae(f,_).document)}w!==null&&s.includes(w)&&(w=null),Pi(c,s.length===1?"Ungroup":`Ungroup ${s.length} groups`),ce(m)}function Ri(s){Pi(Id(n,r,s),R0[s])}function rx(s,f,c){let m=U(n.root,f);if(!m||!ye(m))return;let h=new Set(je(n.root,f)),b=s.filter(K=>K!==n.root.id&&U(n.root,K)&&!h.has(K));if(b.length===0)return;let _=new Set(b),C=re(m).filter(K=>!_.has(K.id))[c]?.id,O=[],R=n;for(let K of b){let ve=re(U(R.root,f)??R.root).filter(ut=>ut.id!==K),He=C===void 0?-1:ve.findIndex(ut=>ut.id===C),Ue={op:"move",id:K,parent:f,index:He===-1?ve.length:He};O.push(Ue),R=Ae(R,[Ue]).document}if(b.every(K=>ax(n,R,K)))return;let j=new Set(b.filter(K=>ct(n.root,K)?.id!==f).flatMap(K=>Uf(K,R))),W=[];for(let K of b){let ve=vu(n,K),He=vu(R,K),Ue={x:ve.x-He.x,y:ve.y-He.y};if(!(Ue.x===0&&Ue.y===0))for(let ut of Ln(K,R)){let Un=Bt(ut);Un&&(W.push({op:"set",id:ut,prop:"x",value:ee(Un.x+Ue.x)}),W.push({op:"set",id:ut,prop:"y",value:ee(Un.y+Ue.y)}))}}let xe=Ae(R,W).document;he([...O,...W,...kr(n,xe,j)],b.length===1?`Move ${b[0]}`:`Move ${b.length} layers`)}function ox(s={}){let f=n.root.children,c=f.filter(He=>He.type==="frame"),m=c.find(He=>He.id===s.after),h=I.getResolution(),b=m?h.nodes.get(m.id):void 0,_=b&&b.w>0?b.w:Cm.w,C=b&&b.h>0?b.h:Cm.h,O=null,R=-1/0;for(let He of c.length>0?c:f){let Ue=h.nodes.get(He.id);!Ue||Ue.absX+Ue.w<=R||(R=Ue.absX+Ue.w,O={x:R+M0,y:Ue.absY})}let j=O??{x:0,y:0},W=m??c[c.length-1],xe=W?f.indexOf(W)+1:f.length,K=Wt(n.root,"frame"),ve=m?.type==="frame"?m.background:void 0;return he([{op:"insert",parent:n.root.id,index:xe,node:Zo({id:K,x:ee(j.x),y:ee(j.y),w:ee(_),h:ee(C),background:ve??Em,children:[]})}],"Add frame"),ce([K]),K}function ax(s,f,c){let m=ct(s.root,c),h=ct(f.root,c);return m?.id===h?.id&&m?.children.findIndex(b=>b.id===c)===h?.children.findIndex(b=>b.id===c)}function vu(s,f){let c=je(s.root,f).slice(0,-1).reverse(),m=Ne(s);for(let h of c){let b=U(s.root,h);if(!b||Oe(b))continue;let _=m.nodes.get(h);return _?{x:_.absX,y:_.absY}:{x:0,y:0}}return{x:0,y:0}}function bu(s){let f=U(n.root,s);!f||!Oe(f)||(w=s,Q())}function wu(){if(w===null)return;let s=w;w=je(n.root,s).slice(0,-1).reverse().find(c=>{let m=U(n.root,c);return m!==void 0&&Oe(m)})??null,ce([s])}function Fi(){let s=U(n.root,w??n.root.id)??n.root;ce(re(s).map(f=>f.id).filter(fn))}let ix={locked:["Lock","Unlock"],hidden:["Hide","Show"]};function ku(s){return s==="locked"?Qe().locked:Qe().hidden}function Fn(s,f,c){let m=s.filter(_=>_!==n.root.id&&U(n.root,_)),h=c?m.filter(_=>!ku(f).has(_)):[...new Set(m.flatMap(_=>{let C=Rr(n.root,_,f);return C===void 0?[]:[C]}))];if(h.length===0)return;let b=ix[f][c?0:1];he(h.map(_=>({op:"set",id:_,prop:f,value:c?!0:void 0})),h.length===1?`${b} ${h[0]}`:`${b} ${h.length} layers`)}function Bn(s,f){s.length!==0&&Fn(s,f,!s.every(c=>ku(f).has(c)))}function Bi(s){let f=[];return se(n.root,c=>{c[s]===!0&&f.push(c.id)}),f}function Go(s){let f=Bi(s);if(f.length===0)return;let c=s==="locked"?"Unlock all":"Show all";he(f.map(m=>({op:"set",id:m,prop:s,value:void 0})),c)}function sx(s){D={...Am,...s},Se?.close()}function Hn(){let s=r.filter(c=>c!==n.root.id).map(c=>({op:"remove",id:c}));if(s.length===0)return;let f=s.length;ce([]),he(s,f===1?"Delete element":`Delete ${f} elements`)}function Nr(){et=null;let s=H.undo();s&&Df(s.ops,`Undo ${s.entry.label}`)}function Wo(){et=null;let s=H.redo();s&&Df(s.ops,`Redo ${s.entry.label}`)}function lx(s){if(!H.isTail(s))return!1;for(let f=s.length;f>0;f-=1)Nr();return!0}function _u(s,f,c,m){let h=U(n.root,s);if(!h)return;let b=h[f];H0(b,c)||he([{op:"set",id:s,prop:f,value:c}],m??`Set ${f}`)}function dx(s,f){n.tokens[s]!==f&&he([{op:"setToken",name:s,value:f}],`Set $${s}`)}function fx(s){s in n.tokens&&he([{op:"setToken",name:s,value:void 0}],`Remove $${s}`)}function Su(s,f){let c=Ct(s)?.values[f];c!==void 0&&he([{op:"set",id:s,prop:f,value:ee(c)}],`Detach ${f}`)}function ux(s){let f=U(n.root,w??n.root.id)??n.root,c=[];for(let m of re(f)){if(!fn(m.id))continue;let h=Ie(m.id);h&&El(h,s)&&c.push(m.id)}return c}function st(s){typeof e.setPointerCapture=="function"&&e.setPointerCapture(s)}function Hi(s){e.hasPointerCapture?.(s)&&e.releasePointerCapture(s)}let Eu=s=>{G&&(Rf(),G.handleKey(s)&&(s.preventDefault(),s.stopPropagation()))},Cu=s=>{G&&(s.preventDefault(),Rf(),G.handleInput(s))},Mu=()=>G?.handleCompositionStart(),Au=s=>G?.handleCompositionUpdate(s.data??""),$u=s=>G?.handleCompositionEnd(s.data??""),Tu=s=>{if(!e.ownerDocument.hasFocus())return;let f=s.relatedTarget;f instanceof Element&&f.closest("[data-vd-keeps-text]")||un("blur")};return z.addEventListener("keydown",Eu),z.addEventListener("beforeinput",Cu),z.addEventListener("compositionstart",Mu),z.addEventListener("compositionupdate",Au),z.addEventListener("compositionend",$u),z.addEventListener("blur",Tu),e.addEventListener("pointerdown",qf),e.addEventListener("pointermove",Gf),e.addEventListener("pointerup",jo),e.addEventListener("pointercancel",jo),e.addEventListener("pointerup",Ro),e.addEventListener("pointercancel",Ro),e.addEventListener("pointerleave",su),e.addEventListener("dblclick",tu),e.addEventListener("contextmenu",eu),e.addEventListener("keydown",Wf),e.addEventListener("keyup",Qf),e.addEventListener("copy",Yf),e.addEventListener("cut",Jf),e.addEventListener("paste",Zf),e.addEventListener("dragover",ou),e.addEventListener("dragleave",au),e.addEventListener("drop",iu),v=!0,we?.setTool(o),we?.setHistory(!1,!1),we?.setZoom(I.getCamera().zoom),qe(Fe(ki())),t.autoFit&&!t.camera&&Te(()=>I.fitToContent()),t.history&&(H.restore(t.history),we?.setHistory(H.canUndo,H.canRedo)),t.selection&&t.selection.length>0&&ce(t.selection),Q(),{element:e,viewer:I,getDocument:()=>n,update(s){n=s,I.update(n),ce(r),Q(),de("problems",wi())},applyOps:(s,f)=>he(s,f??"Apply changes"),setDocument:(s,f)=>he(us(n,wl(s,n.root.id)),f??"Replace document"),getSelection:()=>r,setSelection:ce,selectAll:Fi,deleteSelection:Hn,lock:s=>Fn(s??r,"locked",!0),unlock:s=>Fn(s??r,"locked",!1),toggleLock:s=>Bn(s??r,"locked"),unlockAll:()=>Go("locked"),hide:s=>Fn(s??r,"hidden",!0),show:s=>Fn(s??r,"hidden",!1),toggleHidden:s=>Bn(s??r,"hidden"),showAll:()=>Go("hidden"),isLocked:s=>Qe().locked.has(s),isHidden:s=>Qe().hidden.has(s),setFeatures:sx,getFeatures:()=>D,moveLayers:rx,addFrame:ox,copy:Ir,cut:hu,paste:Li,duplicate:Di,group:Ii,ungroup:Ni,reorder:Ri,scaleSelection:gh,getSpacing:wh,setSpacing:bh,align:fu,distribute:cu,canDistribute:s=>uu(s)!==null,editText:$r,endTextEditing:()=>un("done"),getEditingText:()=>G?.id??null,formatText:s=>G?.format(s),getTextFormat:()=>G?.activeMark()??{},getTextSelectionRects:If,getTextRange:()=>{if(!G)return null;let{anchor:s,head:f}=G.getSelection();return{from:Math.min(s,f),to:Math.max(s,f)}},getEnteredGroup:()=>w,enterGroup:bu,exitGroup:wu,getTool:()=>o,editPoints:pn,stopEditingPoints:Or,getPointEditing:()=>Z?.id??null,convertToVector:s=>$i(s),setTool:Vt,beginEdit:rh,endEdit:oh,undo:Nr,redo:Wo,canUndo:()=>H.canUndo,canRedo:()=>H.canRedo,getHistory:()=>H.snapshot(),setProperty:_u,fontFamilies:()=>{let s=new Map;for(let f of t.fonts?.faces()??[]){let c=s.get(f.family)??{weights:new Set,italic:!1};c.weights.add(f.weight),f.style==="italic"?c.italic=!0:(c.css===void 0||f.weight===400)&&(c.css=f.id),s.set(f.family,c)}return[...s.entries()].sort(([f],[c])=>f.localeCompare(c)).map(([f,c])=>({family:f,weights:[...c.weights].sort((m,h)=>m-h),italic:c.italic,...c.css===void 0?{}:{css:c.css}}))},assetUrl:s=>{let f=n.assets[s];return f?t.resolveAsset?.(f,s):void 0},addMusic:gu,canAddMusic:()=>t.importAudio!==void 0,setToken:dx,removeToken:fx,bindingsOf:nh,unbind:Su,getResolution:()=>I.getResolution(),getCamera:()=>I.getCamera(),getProblems:wi,on:le,reveal:Le,panBy:Qm,setPresence(s,f){d={ids:[...s],label:f??null},Q()},setHighlight(s){s.length===0&&p.length===0||(p=[...s],Q())},isHistoryTail:s=>H.isTail(s),undoTail:lx,historyTop:()=>H.top,destroy(){ae(),e.removeEventListener("pointerup",Ro),e.removeEventListener("pointercancel",Ro),e.removeEventListener("pointerdown",qf),e.removeEventListener("pointermove",Gf),e.removeEventListener("pointerup",jo),e.removeEventListener("pointercancel",jo),e.removeEventListener("pointerleave",su),z.removeEventListener("keydown",Eu),z.removeEventListener("beforeinput",Cu),z.removeEventListener("compositionstart",Mu),z.removeEventListener("compositionupdate",Au),z.removeEventListener("compositionend",$u),z.removeEventListener("blur",Tu),z.remove(),Rn&&clearTimeout(Rn),e.removeEventListener("dblclick",tu),e.removeEventListener("contextmenu",eu),e.removeEventListener("copy",Yf),e.removeEventListener("cut",Jf),e.removeEventListener("paste",Zf),e.removeEventListener("dragover",ou),e.removeEventListener("dragleave",au),e.removeEventListener("drop",iu),e.removeEventListener("keydown",Wf),e.removeEventListener("keyup",Qf),Se?.destroy(),we?.destroy(),fe.destroy(),I.destroy(),te.remove(),X.clear(),e.style.cursor="",e.classList.remove("vd-editor")}}}function H0(e,t){return e===t?!0:be(e)&&be(t)?e.expr===t.expr:!1}function $m(e){return e.metaKey||e.ctrlKey||e.altKey}function xi(e){if(!(e instanceof HTMLElement)||e.classList.contains("vd-editor__input"))return!1;let t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||e.isContentEditable}var HM=new Set(on);function Ef(e){return e.map(t=>({value:t,label:`${t.charAt(0).toUpperCase()}${t.slice(1)}`}))}var z0=[{value:"nonzero",label:"Non-zero"},{value:"evenodd",label:"Even-odd"}].filter(e=>hn.includes(e.value)),j0=Ef(xn),q0=Ef(Kt),K0=Ef(gn),G0=[{value:"left",label:"Left",icon:Ge("text-left")},{value:"center",label:"Centre",icon:Ge("text-center")},{value:"right",label:"Right",icon:Ge("text-right")},{value:"justify",label:"Justify",icon:Ge("text-justify")}].filter(e=>jt.includes(e.value)),W0=[{value:"top",label:"Top",icon:Ge("text-top")},{value:"middle",label:"Middle",icon:Ge("text-middle")},{value:"bottom",label:"Bottom",icon:Ge("text-bottom")}].filter(e=>qt.includes(e.value)),Dm={prop:"x",label:"X",kind:"number",prefix:"X"},Pm={prop:"y",label:"Y",kind:"number",prefix:"Y"},_f={prop:"w",label:"W",kind:"number",prefix:"W"},Sf={prop:"h",label:"H",kind:"number",prefix:"H"},X0={prop:"rotation",label:"Rotation",kind:"number",icon:"rotate",fallback:"0"},Y0={prop:"opacity",label:"Opacity",kind:"number",icon:"opacity",percent:!0,fallback:"100%"},Lm={prop:"radius",label:"Radius",kind:"number",icon:"radius",span:"wide",fallback:"0"},Io={heading:"Position",props:[Dm,Pm,_f,Sf,X0,Y0]},gi={prop:"fill",label:"Fill",kind:"colour"},Im={prop:"stroke",label:"Stroke",kind:"colour",span:"half"},Nm={prop:"strokeWidth",label:"Stroke width",kind:"number",prefix:"Width",fallback:"1"},Rm={present:"stroke",empty:"No stroke",add:{stroke:"#000000",strokeWidth:1},clear:["stroke","strokeWidth","cap","join"]},Om={heading:"Stroke",props:[Im,Nm],optional:Rm},UM={frame:[{heading:"Frame",props:[Dm,Pm,_f,Sf,{prop:"clip",label:"Clip content",kind:"toggle"}]},{heading:"Fill",props:[{prop:"background",label:"Fill",kind:"colour"}]}],canvas:[{heading:"Canvas",props:[_f,Sf,{prop:"background",label:"Fill",kind:"colour"}]}],text:[Io,{heading:"Text",props:[{prop:"font",label:"Font",kind:"font",fallback:"Default"},{prop:"weight",label:"Style",kind:"style",span:"half"},{prop:"size",label:"Size",kind:"number",icon:"font-size",fallback:"16"},{prop:"lineHeight",label:"Line height",kind:"number",icon:"line-height",fallback:"Auto"},{prop:"letterSpacing",label:"Letter spacing",kind:"number",icon:"letter-spacing",fallback:"0"},{prop:"align",label:"Align",kind:"segmented",options:G0,span:"half"},{prop:"valign",label:"Vertical",kind:"segmented",options:W0,span:"half"}]},{heading:"Fill",props:[gi]},{heading:"Link",props:[{prop:"content",label:"Link",kind:"link",icon:"link"}]}],rect:[{heading:"Position",props:[...Io.props,Lm]},{heading:"Fill",props:[gi]},Om],ellipse:[Io,{heading:"Fill",props:[gi]},Om],image:[{heading:"Position",props:[...Io.props,Lm]},{heading:"Image",props:[{prop:"fit",label:"Fit",kind:"select",options:q0,prefix:"Fit"}]}],vector:[Io,{heading:"Fill",props:[{...gi,span:"half"},{prop:"rule",label:"Fill rule",kind:"select",options:z0,prefix:"Rule",span:"half"}]},{heading:"Stroke",props:[Im,Nm,{prop:"cap",label:"Cap",kind:"select",options:j0,prefix:"Cap",span:"half"},{prop:"join",label:"Join",kind:"select",options:K0,prefix:"Join",span:"half"}],optional:Rm}]};var VM=mn.map(e=>({value:e,label:e.split("-").map((t,n)=>n===0?t.charAt(0).toUpperCase()+t.slice(1):t).join(" ")}));function Fm(e){let t=e,n=new Map,r=typeof URL.createObjectURL=="function"&&typeof URL.revokeObjectURL=="function";return{resolve(o){let a=n.get(o.hash);if(a!==void 0)return a;let i=t.get(o.hash);if(i===void 0)return;if(!r)return Es(o.type,i);let l;try{l=Ms(i)}catch{return}let d=URL.createObjectURL(new Blob([l],{type:o.type}));return n.set(o.hash,d),d},replace(o){t=o;for(let[a,i]of n)o.has(a)||(URL.revokeObjectURL(i),n.delete(a))},destroy(){for(let o of n.values())URL.revokeObjectURL(o);n.clear(),t=new Map}}}var Cf="0.3.1",Bm="https://cdn.jsdelivr.net/npm/@getv.design/embed@0.3.1/fonts/";var ib=Symbol.for(`vdesign.embed.documents@${Cf}`),Hm=globalThis[ib]??=new WeakMap,sb=/^Line (\d+): /;function Af(e){let t=sb.exec(e.message);return{...t?{line:Number(t[1])}:{},code:e.code,message:e.message,severity:e.severity}}function Mf(e){if(typeof e!="string")return vi(ro("").document,new Map,[{code:"not-text",message:`parse() takes .vd text, not ${e===null?"null":typeof e}.`,severity:"error"}]);let t=lb(e);if(t.vd===void 0)return vi(ro("").document,new Map,[{code:"not-vd",message:"This SVG carries no vDesign document: only a .vd.svg exported from vDesign does.",severity:"error"}]);let{head:n,blocks:r}=ks(t.vd),o=ro(n),a=o.problems.map(Af).map(i=>i.line===void 0?i:{...i,line:i.line+t.offset});return vi(o.document,r,a)}function lb(e){if(!Ds(e))return{vd:e,offset:0};let t=Os(e);if(t===void 0)return{vd:void 0,offset:0};let n=e.indexOf("<vd:document"),r=e.indexOf("</vd:document",n),o=e.indexOf("<![CDATA[",n);if(o===-1||r!==-1&&o>r){let l=e.indexOf(">",n)+1,d=e.slice(0,l).split(`
|
|
2791
|
+
`,"Type text");return;case"deleteContentBackward":case"deleteWordBackward":A(-1,E.inputType==="deleteWordBackward");return;case"deleteContentForward":case"deleteWordForward":A(1,E.inputType==="deleteWordForward");return;case"deleteByCut":case"deleteByDrag":{let{from:T,to:P}=x();D(T,P);return}default:return}},handleCompositionStart(){i=!0;let{from:E,to:T}=x();l=E,d=T,k()},handleCompositionUpdate(E){v(yr(e.content(),l,d,E),"Type text"),d=l+E.length,t=n=d,e.invalidate()},handleCompositionEnd(E){v(yr(e.content(),l,d,E),"Type text"),i=!1,d=l+E.length,t=n=d,k(),e.invalidate()},breakBurst:k,destroy(){k()}}}function C0(e){return typeof e.data=="string"?e.data:e.dataTransfer?.getData("text/plain")??""}function wm(e,t,n,r){let o=ci(e.layout(),t,n);return r===-1?o.from:o.to}var pi=/[\p{L}\p{N}_]/u;function km(e,t){let n=t;for(;n>0&&!pi.test(e[n-1]??"");)n-=1;for(;n>0&&pi.test(e[n-1]??"");)n-=1;return n}function _m(e,t){let n=t;for(;n<e.length&&!pi.test(e[n]??"");)n+=1;for(;n<e.length&&pi.test(e[n]??"");)n+=1;return n}function xf(e){return Nn(e)===0}var gf={v:"select",f:"frame",r:"rect",o:"ellipse",p:"pen",t:"text"};function br(e,t){let n=[];for(let r of t){if(!U(e.root,r.nodeId))continue;let o=ee(r.to);ee(r.from)!==o&&n.push({op:"set",id:r.nodeId,prop:r.prop,value:o})}return n}function ee(e){return Math.round(e*100)/100}function wr(e,t,n,r){let o=new Set,a=[];for(let d of t)d.op==="set"&&(o.add(Ke(d.id,d.prop)),a.push({nodeId:d.id,prop:d.prop}));if(a.length===0)return[];let i=[],l=new Set;for(let d of a)for(let u of n.get(Ke(d.nodeId,d.prop))??[]){let p=Ke(u.nodeId,u.prop);if(o.has(p)||l.has(p)||!U(e.root,u.nodeId))continue;let x=r.nodes.get(u.nodeId)?.values[u.prop];x!==void 0&&(l.add(p),i.push({op:"set",id:u.nodeId,prop:u.prop,value:ee(x)}))}return i}function yf(e,t,n,r={x:0,y:0}){let o=[],a=new Set,i=e;for(;;){let l=[],d=Ne(i);for(let[u,p]of t){let x=n.get(u),y=U(i.root,p),k=d.nodes.get(p);if(!(!x||!y||!k))for(let M of yt(y)){let v=Ke(p,M);if(a.has(v))continue;let w=x[M],D=k.values[M];if(w===void 0||D===void 0)continue;let A=w+(M==="x"?r.x:M==="y"?r.y:0);ee(A)!==ee(D)&&(a.add(v),l.push({op:"set",id:p,prop:M,value:ee(A)}))}}if(l.length===0)return o;o.push(...l),i=Ae(i,l).document}}function kr(e,t,n=new Set){let r=Ne(e),o=Ne(t),a=[];for(let[i,l]of o.nodes){if(n.has(i))continue;let d=r.nodes.get(i),u=U(t.root,i);if(!(!d||!u))for(let p of yt(u)){let x=d.values[p],y=l.values[p];x===void 0||y===void 0||ee(x)!==ee(y)&&a.push({op:"set",id:i,prop:p,value:ee(x)})}}return a}function mi(e,t,n){let r=new Set,o=[];for(let a of t)a.op==="set"&&a.prop==="view"&&r.add(a.id);for(let a of t){if(a.op!=="set"||a.prop!=="w"&&a.prop!=="h"||r.has(a.id))continue;let i=U(e.root,a.id);if(i?.type!=="vector"||i.view!==void 0)continue;let l=n(a.id);l&&(r.add(a.id),o.push({op:"set",id:a.id,prop:"view",value:En({x:0,y:0,w:l.w,h:l.h})}))}return o.length===0?[...t]:[...o,...t]}var vf="host:",Em="#ffffff",Cm={w:1920,h:1080},M0=100,hi=20,A0=15,$0={ne:0,se:90,sw:180,nw:270,n:0,e:90,s:180,w:270},Mm={w:240,h:28},T0={text:"Add text",frame:"Add page",rect:"Draw rectangle",ellipse:"Draw ellipse"};function L0(e,t){let n=t.x-e.x,r=t.y-e.y,o=Math.max(Math.abs(n),Math.abs(r));return{x:e.x+Math.sign(n||1)*o,y:e.y+Math.sign(r||1)*o}}var O0={KeyA:"left",KeyD:"right",KeyW:"top",KeyS:"bottom",KeyH:"hcenter",KeyV:"vcenter"},D0={KeyH:"x",KeyV:"y"},P0={left:"Align left",hcenter:"Align horizontal centres",right:"Align right",top:"Align top",vcenter:"Align vertical centres",bottom:"Align bottom"},bf=null,I0=220,Am={lock:!0,hide:!0},N0=["x","y","w","h"],R0={front:"Bring to front",forward:"Bring forward",backward:"Send backward",back:"Send to back"},F0=11,an=2,B0=10;function kf(e,t){gr(e.ownerDocument),e.classList.add("vd-editor"),e.hasAttribute("tabindex")||(e.tabIndex=0);let n=t.document,r=[],o=t.tool??"select",a=null,i=null,l=null,d={ids:[],label:null},u=null,p=[],x=!1,y=new Set,k=null,M=!1,v=!1,w=null,D={...Am,...t.features},A=null,H=new $o,E=0,T=null,P={dx:0,dy:0},V=null,X=new Map,te=e.ownerDocument.createElement("div");te.style.position="absolute",te.style.inset="0",e.appendChild(te),e.style.touchAction="none";let I=La(te,{sample:fl,document:n,...t.camera?{camera:t.camera}:{},...t.surface?{surface:t.surface}:{},...t.interactive===void 0?{}:{interactive:t.interactive},...t.wheel?{wheel:t.wheel}:{},...t.resolveAsset?{resolveAsset:t.resolveAsset}:{},...t.fonts?{fonts:t.fonts}:{},onSceneChange:(s,f)=>{f===n&&de("scene",{scene:s,document:f})},onCameraChange:s=>{we?.setZoom(s.zoom),Q(),de("camera",s),!(E>0)&&(ae(),de("navigate",s))}}),fe=fm(e,s=>I.documentToScreen(s)),we=t.chrome===!1?null:Tp(e,{onTool:Vt,onUndo:Nr,onRedo:Wo,onZoomReset:()=>I.fitToContent(),onPlay:t.onPlay,playHint:t.playHint,formatKeys:t.formatKeys}),Se=t.chrome===!1?null:Za(e,{onCommand:jh,...t.formatKeys?{formatKeys:t.formatKeys}:{}}),me=n,ue=n,S=[],g=null,$=[],L=null,B=null,q=new Map,F=null,ne=null,ke=null,Me=[],_e=ot,We=null,G=null,Z=null,Y=null,N=!1,z=e.ownerDocument.createElement("textarea");z.className="vd-editor__input",z.setAttribute("aria-hidden","true"),z.tabIndex=-1,z.autocapitalize="off",z.autocomplete="off",z.spellcheck=!1,e.appendChild(z);function de(s,f){let c=X.get(s);if(c)for(let m of c)m(f)}function le(s,f){let c=X.get(s)??new Set;return c.add(f),X.set(s,c),()=>c.delete(f)}function Te(s){E+=1;try{s()}finally{E-=1}}function ae(){T!==null&&(e.ownerDocument.defaultView?.cancelAnimationFrame(T),T=null)}function Be(s){let f=I.linkAt(s),c=f===void 0?void 0:pt(f);return c?c.kind==="url"?t.onOpenLink?(t.onOpenLink(c.url),!0):!1:U(n.root,c.id)?(ce([c.id]),Le([c.id]),!0):!1:!1}function Le(s,f={}){if(g!==null)return V={target:s,options:f},!1;let c=eh(s);if(!c)return!1;let m=e.getBoundingClientRect(),h=m.width>0&&m.height>0,b=h?{width:m.width,height:m.height-Zm(m)}:{width:c.w+96,height:c.h+96},_=f.fit==="always"?Ja(c,b):jd(c,b,I.getCamera());if(!_)return!1;ae(),f.by==="person"&&de("navigate",_);let C=e.ownerDocument.defaultView,O=C?.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1;if(f.animate===!1||O||!h||!C?.requestAnimationFrame)return Te(()=>I.setCamera(_)),!0;let R=I.getCamera(),j=C.performance.now();P={dx:0,dy:0};let W=xe=>{let K=Math.min(1,Math.max(0,(xe-j)/I0)),ve=K===1?_:Xp(R,_,Yp(K),b);Te(()=>I.setCamera(St(ve,P.dx,P.dy))),T=K===1?null:C.requestAnimationFrame(W)};return T=C.requestAnimationFrame(W),!0}function Zm(s){let f=we?.element.getBoundingClientRect();return!f||f.height===0?0:Math.max(0,s.bottom-f.top)}function Qm(s,f){T!==null&&(P={dx:P.dx+s,dy:P.dy+f}),Te(()=>I.setCamera(St(I.getCamera(),s,f)))}function Ro(){if(V===null||g!==null)return;let{target:s,options:f}=V;V=null,Le(s,f)}function eh(s){if(s==="content"){let c=I.getScene();return Ya([{x:c.x,y:c.y,w:c.width,h:c.height}])}let f=[];for(let c of zd(n,s)){let m=Ie(c);m&&f.push(m)}return Ya(f)}function Ct(s){return I.getResolution().nodes.get(s)}function Bt(s){let f=Ct(s);return f?{x:f.x,y:f.y,w:f.w,h:f.h}:void 0}function Ie(s){return On(s,n,I.getResolution())}function sn(s){let f=Ct(s);return f?{x:f.absX,y:f.absY,w:f.w,h:f.h}:void 0}function ln(s){return Ct(s)?.values.rotation??0}function Lf(){let s=Mr();if(s.length===0)return null;for(let f of s){let c=U(n.root,f);if(!c||!Ks.includes(c.type))return null}return s}function Sr(s,f=new Set){let c=I.getResolution(),m=null;return se(n.root,h=>{if(f.has(h.id)||!fn(h.id))return!1;if(h.type!=="frame")return;let b=c.nodes.get(h.id);if(!b)return!1;let _={x:b.absX,y:b.absY,w:b.w,h:b.h};if(!gt(_,s.x,s.y))return!1;m=h.id}),m}function dn(s){let f=Ct(s);return f?{x:f.absX,y:f.absY}:{x:0,y:0}}function Qe(){return A?.of!==n&&(A={of:n,hidden:Yo(n.root),locked:Jo(n.root)}),A}function fn(s){let{hidden:f,locked:c}=Qe();return!f.has(s)&&!c.has(s)}function ie(){return r.filter(fn)}function Er(s){let f=I.hitTest(s,m=>!Qe().locked.has(m));if(f===null)return null;let c=w===null||je(n.root,f).includes(w);return Ga(f,n,c?w:null)}function th(){return Ao(n,ie(),I.getResolution())}function Cr(){return ie().length<2?null:Jd(th())}function Fo(s){let f=[];for(let c of s)for(let m of Ln(c,n)){let h=Bt(m);h&&f.push({member:c,node:m,frame:h})}return f}function Bo(s,f){let c=U(n.root,s);if(!c)return"literal";let m=c[f];return m===void 0?"literal":wa(m).kind}function nh(s){let f=U(n.root,s),c={};if(!f)return c;let m=[...N0,..._o(f).map(h=>h.prop)];for(let h of m)c[h]=Bo(s,h);return c}function Of(s,f){let c="none";for(let m of s){let h=bi(m,f);if(h==="expression")return"expression";h==="token"&&(c="token")}return c}function bi(s,f){let c="none";for(let m of f){let h=Bo(s,m);if(h==="complex")return"expression";h==="token"&&(c="token")}return c}let et=null;function he(s,f){if(s.length===0)return;let c=da(n,mi(n,s,Bt)),m=Ae(n,c);n=m.document,et?(Si(et.started,et.label,c,m.inverse),et.started=!0):H.push({label:f,ops:c,inverse:m.inverse}),Ho(c,f)}function rh(s){et={label:s,started:!1}}function oh(){et=null}function Df(s,f){s.length!==0&&(n=Ae(n,s).document,Ho(s,f))}function Ho(s,f){a=null,ne=null,ke=null,I.update(n),we?.setHistory(H.canUndo,H.canRedo),Q(),de("change",{document:n,ops:s,label:f}),de("problems",wi())}function wi(){return[...I.getScene().problems,...js(n)]}function ce(s){let f=s.filter(m=>m!==n.root.id&&U(n.root,m)),c=f.length!==r.length||f.some((m,h)=>r[h]!==m);r=[...f],Z&&(f.length!==1||f[0]!==Z.id)&&(Z=null),c&&(Se?.close(),ke=null,de("selection",r)),Q()}function ah(s,f){let c=U(n.root,s);if(!c)return[];let m=I.getCamera().zoom;if(Math.min(f.w,f.h)*m<24)return[];let h=F0/m,b=Ct(s);return _o(c).flatMap(_=>{let C=b?.values[_.prop]??0,O=Bo(s,_.prop)!=="literal";return _.handles(f,C,h).map(R=>({id:R.id,at:R.at,bound:O}))})}function ih(){let s=[];for(let R of ie()){let j=Ie(R);j&&s.push(j)}let f=xt(s);if(!f)return null;let c=ie().length===1?ie()[0]:void 0,m=c===void 0?void 0:U(n.root,c),h=c===void 0||!m||ye(m),b=new Set,_=Mr();for(let R of _l){let j=Oa(R);_.some(W=>j.some(xe=>Bo(W,xe)!=="literal"))&&b.add(R)}let C=!h&&c!==void 0?ln(c):0,O=C!==0&&c!==void 0?sn(c):void 0;return{frame:O??f,...O?{rotation:C}:{},rotatable:Lf()!==null,handles:G===null,boundHandles:b,adjusters:G!==null||h||c===void 0||O?[]:ah(c,f)}}function Mr(){return[...new Set(ie().flatMap(s=>Ln(s,n)))]}function sh(s){if(!s)return null;if(g?.kind==="adjust")return`r ${ee(L??g.from)}`;if(g?.kind==="rotate")return`${ee(B??0)}\xB0`;if(!g&&ne&&ie().length===1){let f=Ct(ie()[0])?.values[ne.prop]??0;return`r ${ee(f)}`}return g?.kind==="move"?`${ee(s.frame.x)}, ${ee(s.frame.y)}`:`${ee(s.frame.w)} \xD7 ${ee(s.frame.h)}`}function lh(){let f=g!==null&&g.kind!=="space"&&g.kind!=="reorder"?null:Cr();if(!f)return{spacers:[],rings:[],lead:null};let c=g?.kind==="space"?g.spacer:null;return{spacers:Qd(f).map(m=>({id:m.id,axis:m.axis,at:m.at,label:m.id===(c??ke)?String(ee(m.gap)):null})),rings:ef(f).map(m=>({id:m.id,at:m.at})),lead:g?.kind==="reorder"?Ie(g.id)??null:null}}function Q(){if(!v)return;let s=$h(),f=s?null:ih(),c=a!==null&&!r.includes(a)&&!g?Ie(a)??null:null,m={...dm,...lh(),hover:c,members:ie().length>1?ie().flatMap(h=>Ie(h)??[]):[],box:f,badge:sh(f),caret:Pf(),textSelection:If(),draft:g?.kind==="create"?Tn(g.origin,g.current):null,draftEllipse:g?.kind==="create"&&o==="ellipse",marquee:g?.kind==="marquee"?Tn(g.origin,g.current):null,guides:g?_e.guides:[],measures:g?_e.measures:[],presence:d.ids.length===0?null:{frames:d.ids.flatMap(h=>Ie(h)??[]),label:d.label},highlight:Co(n,p).flatMap(h=>Ie(h.id)??[]),slots:Qh(),parked:r.filter(h=>!fn(h)).flatMap(h=>Ie(h)??[]),lockHint:uh(),path:s,turn:ch(),pageLabels:dh()};fe.render(m)}function dh(){if(i)return[];let s=I.getResolution().nodes;return n.root.children.flatMap(f=>{if(f.type!=="frame")return[];let c=s.get(f.id);if(!c)return[];let m=Mo(c),h=f.name;return[{id:f.id,frame:m,label:typeof h=="string"&&h!==""?h:f.id,state:r.includes(f.id)?"selected":a===f.id?"hover":"idle"}]})}function fh(s){let f=fe.pageLabelRect(s),c=U(n.root,s);if(!f||!c)return;let m=c.name,h=e.ownerDocument.createElement("input");h.className="vd-editor__rename",h.type="text",h.spellcheck=!1,h.value=typeof m=="string"&&m!==""?m:"",h.placeholder=s,h.setAttribute("aria-label",`Name of ${s}`),h.style.left=`${f.x-4}px`,h.style.top=`${f.y-2}px`,h.style.width=`${Math.max(120,f.w+40)}px`;let b=!1,_=C=>{if(b)return;b=!0;let O=h.value.trim();h.remove(),i=null,C&&O!==(typeof m=="string"?m:"")&&_u(s,"name",O===""?void 0:O,"Rename"),Q(),e.focus({preventScroll:!0})};h.addEventListener("keydown",C=>{C.stopPropagation(),C.key==="Enter"?(C.preventDefault(),_(!0)):C.key==="Escape"&&(C.preventDefault(),_(!1))}),h.addEventListener("pointerdown",C=>C.stopPropagation()),h.addEventListener("blur",()=>_(!0)),i=h,e.appendChild(h),Q(),h.focus(),h.select()}function uh(){if(l===null||g||!Qe().locked.has(l))return null;let s=Ie(l);return s?{frame:s,label:l}:null}function Uo(s){let f=I.itemOf(s);if(f?.kind!=="text")return null;let c=f.lines[0]?.y??f.y,m={lines:f.lines.map(h=>({y:h.y-c,h:h.h,baseline:h.baseline-c,w:h.w,spans:h.spans.map(b=>({text:b.text,style:b.style,x:b.x-f.x,w:b.w})),...h.style?{style:h.style}:{}})),width:Math.max(0,...f.lines.map(h=>h.w)),height:f.height};return{item:f,layout:m,top:c}}function ki(){return o==="text"?"text":o!=="select"?"crosshair":"arrow"}function Pf(){if(!G)return null;let s=Uo(G.id);if(!s)return null;let f=G.caret();return{x:s.item.x+f.x,y:s.top+f.y,h:f.h,...f.fill!==void 0?{fill:f.fill}:{}}}function If(){if(!G)return[];let s=Uo(G.id);return s?G.highlight().map(f=>({x:s.item.x+f.x,y:s.top+f.y,w:f.w,h:f.h})):[]}function _i(s){if(!G)return null;let f=Uo(G.id);if(!f)return null;let c=Ar(G.id,s);return{x:c.x-f.item.x,y:c.y-f.top}}function Ar(s,f){let c=ln(s),m=c===0?void 0:sn(s);return m?Ze(f,rt(m),-c):f}function ch(){let s=G?.id??Z?.id;if(s===void 0)return null;let f=ln(s),c=f===0?void 0:sn(s);return c?{angle:f,centre:rt(c)}:null}function ph(s){let f=U(n.root,s);if(!f||f.type!=="text"||typeof f.h!="number")return[];let c=I.itemOf(s);if(c?.kind!=="text")return[];let m=ee(Math.ceil(c.height));return m>f.h?[{op:"set",id:s,prop:"h",value:m}]:[]}function mh(s,f,c,m){let h=et?et.started:c,b=et?.label??m;et&&(et.started=!0);let _=[{op:"set",id:s,prop:"content",value:f}],C=Ae(n,_);n=C.document,I.update(n);let O=ph(s);if(O.length===0){Si(h,b,_,C.inverse),Ho(_,b);return}let R=Ae(n,O);n=R.document,I.update(n);let j=[..._,...O];Si(h,b,j,[...R.inverse,...C.inverse]),Ho(j,b)}function Si(s,f,c,m){let h={label:f,ops:c,inverse:m};s&&H.amend(h)||H.push(h)}function $r(s,f){let c=U(n.root,s);if(!c||c.type!=="text"||G?.id===s)return;un("done"),Vt("select"),ce([s]),G=hf({id:s,content:()=>{let h=U(n.root,s);return h?.type==="text"?h.content:""},layout:()=>Uo(s)?.layout??{lines:[],width:0,height:0},measure:()=>I.getMeasurer(),write:(h,b,_)=>mh(s,h,b,_),invalidate:()=>{Q(),Nf(),de("selection",r)},close:h=>un(h)});let m=f?_i(f):null;m?G.pointTo(m,!1):G.selectAll(),e.classList.add("vd-editor--editing"),z.value="",z.focus({preventScroll:!0}),Q(),Nf()}function un(s){let f=G;if(!f)return;G=null,N=!1,f.destroy(),e.classList.remove("vd-editor--editing","vd-editor--typing"),de("selection",r);let c=U(n.root,f.id);c?.type==="text"&&xf(c.content)&&(he([{op:"remove",id:f.id}],"Remove empty text"),ce([])),e.ownerDocument.activeElement===z&&e.focus({preventScroll:!0}),Q()}function Nf(){let s=Pf();if(!s)return;let f=I.documentToScreen({x:s.x,y:s.y});z.style.left=`${Math.round(f.x)}px`,z.style.top=`${Math.round(f.y)}px`}let Rn=0;function Rf(){e.classList.add("vd-editor--typing"),Rn&&clearTimeout(Rn),Rn=setTimeout(()=>{Rn=0,e.classList.remove("vd-editor--typing")},520)}function Ei(s){let f=br(me,s);return f.length>0&&F?[...f,...wr(me,f,q,F)]:f}function cn(s){Ci(Ei(s))}function Ci(s,f=s){let c=h=>{let b=F?.nodes.get(h);return b?{x:0,y:0,w:b.w,h:b.h}:void 0},m=mi(me,s,c);$=mi(me,f,c),I.update(m.length>0?Ae(me,m).document:me),Q()}function Ff(){let s=xt(ie().flatMap(m=>Ie(m)??[]));if(!s)return null;let f=new Map,c=new Map;for(let m of Mr()){let h=sn(m),b=Bt(m);!h||!b||(f.set(m,h),c.set(m,{x:h.x-b.x,y:h.y-b.y}))}return f.size===0?null:{bounds:s,frames:f,offsets:c}}function Bf(s,f){let c=Nd(s.frames,s.bounds,f),m=[];for(let[h,b]of c){let _=s.frames.get(h),C=s.offsets.get(h);if(!_||!C)continue;let O=ln(h),R=O===0?b:yp(_,O,s.bounds,f);m.push({nodeId:h,prop:"x",from:_.x-C.x,to:R.x-C.x},{nodeId:h,prop:"y",from:_.y-C.y,to:R.y-C.y},{nodeId:h,prop:"w",from:_.w,to:R.w},{nodeId:h,prop:"h",from:_.h,to:R.h})}return m}function hh(s,f){let c=Lf();if(!c)return!1;let m=ie().length===1&&c.length===1?c[0]:void 0,h=xt(ie().flatMap(C=>Ie(C)??[])),b=m!==void 0?sn(m):h;if(!b)return!1;let _=c.flatMap(C=>{let O=sn(C),R=Bt(C);return!O||!R?[]:[{id:C,frame:O,rotation:ln(C),offset:{x:O.x-R.x,y:O.y-R.y}}]});return _.length===0?!1:(st(f),tt({kind:"rotate",pointerId:f,origin:s,centre:rt(b),targets:_}),!0)}function xh(s,f,c){let m=Ff();return m?(st(c),tt({kind:"scale",pointerId:c,origin:s,handle:f,...m}),!0):!1}function gh(s){let f=Ff();if(!f)return;let c=br(n,Bf(f,s));if(c.length===0)return;let m=s.w!==f.bounds.w||s.h!==f.bounds.h;he([...c,...wr(n,c,ir(n),Ne(n))],m?"Resize":"Move")}function yh(s,f,c){let m=ii(s),h=Cr();if(!m||!h)return!1;let b=Et(h,m.axis)?.gaps[m.index],_=Fo(ie());return b===void 0||_.length===0?!1:(st(c),tt({kind:"space",pointerId:c,origin:f,axis:m.axis,spacer:s,layout:h,gap:b,parts:_}),!0)}function vh(s,f){let c=s.axis==="x"?f.x-s.origin.x:f.y-s.origin.y,m=Math.max(0,s.gap+c);cn(Mi(s.parts,s.axis,si(s.layout,s.axis,m)))}function bh(s,f){let c=Cr(),m=c?Et(c,s):void 0;if(!c||!m||m.gaps.length===0)return;let h=br(n,Mi(Fo(ie()),s,si(c,s,Math.max(0,f))));h.length!==0&&he([...h,...wr(n,h,ir(n),Ne(n))],"Spacing")}function wh(s){let f=Cr(),c=f?Et(f,s)?.gaps:void 0;return!c||c.length===0?null:Zd(c)?c[0]??null:"mixed"}function Mi(s,f,c){return s.map(m=>{let h=f==="x"?m.frame.x:m.frame.y;return{nodeId:m.node,prop:f,from:h,to:h+(c.get(m.member)??0)}})}function kh(s,f,c){let m=Cr();if(!m||!m.order.includes(s))return!1;let h=Fo(ie()),b=m.items.find(_=>_.id===s)?.frame;return h.length===0||!b?!1:(st(c),tt({kind:"reorder",pointerId:c,id:s,layout:m,parts:h,grab:{x:f.x-b.x,y:f.y-b.y},to:m.order.indexOf(s),swap:!1}),!0)}function _h(s,f,c){s.to=rf(s.layout,f),s.swap=c;let m=Sh(s),h=new Map(m);h.set(s.id,{x:f.x-s.grab.x,y:f.y-s.grab.y}),Ci(Ei(Hf(s,h)),Ei(Hf(s,m)))}function Sh(s){let f=s.layout.order.indexOf(s.id);if(f===-1||s.to===f)return new Map;if(s.swap){let c=s.layout.order[s.to];return c===void 0?new Map:sf(s.layout,s.id,c)}return af(s.layout,of(s.layout.order,f,s.to))}function Hf(s,f){let c=new Map(s.layout.items.map(h=>[h.id,h.frame])),m=[];for(let h of s.parts){let b=f.get(h.member),_=c.get(h.member);!b||!_||m.push({nodeId:h.node,prop:"x",from:h.frame.x,to:h.frame.x+(b.x-_.x)},{nodeId:h.node,prop:"y",from:h.frame.y,to:h.frame.y+(b.y-_.y)})}return m}function tt(s,f=[],c=n){ue=c,S=f,me=n,g=s,$=[],q=ir(n),F=Ne(n),_e=ot,Me=Eh(s)?Fd(n,F,Ch(s)):[]}function Eh(s){return s.kind==="move"||s.kind==="resize"||s.kind==="scale"||s.kind==="create"}function Ch(s){return s.kind==="move"||s.kind==="scale"?new Set(ie()):s.kind==="resize"?new Set([s.id]):new Set}function Tr(s){return s.metaKey||s.ctrlKey?0:Rd/I.getCamera().zoom}function Ht(s){let f=[...S,...$];g=null,$=[],S=[],L=null,B=null,_e=ot,n=ue,I.update(n),he(f,s),Q()}function Mh(){let s=$.length>0?Ae(me,$).document:me,f=new Set(ie().flatMap(h=>Uf(h,s))),c=[];for(let h of ie()){let b=U(s.root,h),_=ct(s.root,h);if(!b||!_)continue;let C=Ie(h);if(!C)continue;let O={x:C.x+C.w/2,y:C.y+C.h/2},R=Sr(O,f)??n.root.id;if(R===_.id)continue;let j=U(s.root,R);if(!j||!ye(j))continue;c.push({op:"move",id:h,parent:R,index:re(j).length});let W={x:dn(_.id).x-dn(R).x,y:dn(_.id).y-dn(R).y};if(!(W.x===0&&W.y===0))for(let xe of Ln(h,s)){let K=Bt(xe);K&&(c.push({op:"set",id:xe,prop:"x",value:ee(K.x+W.x)}),c.push({op:"set",id:xe,prop:"y",value:ee(K.y+W.y)}))}}if(c.length===0)return[];let m=Ae(s,c).document;return[...c,...kr(s,m,f)]}function Uf(s,f){let c=U(f.root,s);if(!c)return[];let m=[];return se(c,h=>{m.push(h.id)}),m}function Ai(){if(!g)return;g=null,$=[],L=null,B=null,_e=ot;let s=S.length>0;n=ue,S=[],s&&ce(r.filter(f=>U(n.root,f))),I.update(n),Q()}let Ah=5,Vo=8;function Vf(s,f=n,c=I.getResolution()){let m=U(f.root,s),h=c.nodes.get(s);if(m?.type!=="vector"||!h)return;let b={x:h.absX,y:h.absY,w:Math.max(0,h.w),h:Math.max(0,h.h)};return{node:m,view:Jr(m.view,b.w,b.h),box:b}}function Lr(s,f=n,c=I.getResolution()){let m=Vf(s,f,c);if(m)return Lt(Yr(m.node.d).contours,Zr(m.view,m.box))}function Ut(s,f,c,m=n,h=I.getResolution()){let b=Vf(s,m,h);if(!b)return[];let{node:_,view:C,box:O}=b,R=Lt(f,ns(C,O)),j=[],W=(ut,Un,cx)=>{Un!==cx&&j.push({op:"set",id:s,prop:ut,value:Un})};W("d",Tt(R),_.d);let xe=[_.x,_.y,_.w,_.h].every(ut=>typeof ut=="number"),K=Sn(R),ve=Sn(f);if(!c||!xe||!K||!ve)return j;let He=O.x-_.x,Ue=O.y-_.y;return W("view",En(K),_.view),W("x",ee(ve.x-He),_.x),W("y",ee(ve.y-Ue),_.y),W("w",ee(ve.w),_.w),W("h",ee(ve.h),_.h),j}function pn(s){return U(n.root,s)?.type!=="vector"||!fn(s)?!1:(G&&un("done"),Y&&zo(),ce([s]),Z={id:s,picked:new Set},o!=="select"&&Vt("select"),it(null),Q(),!0)}function Or(){Z&&(Z=null,Q())}function $h(){if(Y){let c=Y.contours[Y.contour],m=c?.anchors??[],h=m[m.length-1],b=m[0],_=Y.hover,C=_!==null&&b!==void 0&&m.length>=2&&!c?.closed&&Dr(b,_)<=Vo;return{contours:Y.contours,anchors:m.map((O,R)=>({key:Re(Y?.contour??0,R),at:O,selected:R===m.length-1})),handles:h?Ll(Y.contours,new Set([Re(Y.contour,m.length-1)])):[],pending:h&&_&&!Y.dragging&&!c?.closed?{from:h,...h.out?{c1:h.out}:{},to:_}:null,closeAt:C?b:null}}if(!Z)return null;let s=Lr(Z.id);if(!s)return null;let f=new Set($l(s,Z.picked));return{contours:s,anchors:s.flatMap((c,m)=>c.anchors.map((h,b)=>({key:Re(m,b),at:h,selected:f.has(Re(m,b))}))),handles:Ll(s,f)}}function Dr(s,f){return Math.hypot(s.x-f.x,s.y-f.y)*I.getCamera().zoom}function Th(s,f,c,m){if(!Z)return!1;let h=Z.id,b=Lr(h);if(!b)return Z=null,!1;s.preventDefault(),st(s.pointerId);let _=fe.hitPath(f);if(_?.kind==="handle"){let O=vp(_.key),R=O?b[O.contour]?.anchors[O.index]:void 0;if(O&&R)return tt({kind:"pathHandle",pointerId:s.pointerId,id:h,start:b,contour:O.contour,index:O.index,side:O.side,smooth:Pa(R),last:b}),!0}if(_?.kind==="anchor")return s.altKey?(Z.picked=new Set([_.key]),he(Ut(h,bp(b,_.key),!1),"Convert point"),!0):(s.shiftKey?Z.picked.has(_.key)?Z.picked.delete(_.key):Z.picked.add(_.key):Z.picked.has(_.key)||(Z.picked=new Set([_.key])),tt({kind:"points",pointerId:s.pointerId,id:h,origin:c,start:b,keys:new Set(Z.picked),lead:_.key,moved:!1,last:b}),Q(),!0);let C=as(b,c);if(C&&C.distance*I.getCamera().zoom<=Ah){if(m>=2){let W=is(b,C.contour,C.segment,C.t);return Z.picked=new Set([Re(C.contour,C.segment+1)]),he(Ut(h,W,!1),"Add point"),!0}let O=b[C.contour],R=O.anchors[C.segment],j=O.anchors[(C.segment+1)%O.anchors.length];return tt({kind:"segment",pointerId:s.pointerId,id:h,origin:c,start:b,contour:C.contour,segment:C.segment,t:C.t,straight:!R?.out&&!j?.in,last:b}),!0}return tt({kind:"pointMarquee",pointerId:s.pointerId,origin:c,current:c,additive:s.shiftKey}),!0}function Lh(s,f,c,m){let h=Al(s.start,s.lead);if(!h||m===0)return{dx:f,dy:c};let b=h.x+f,_=h.y+c,C=m,O=m,R=f,j=c;return s.start.forEach((W,xe)=>W.anchors.forEach((K,ve)=>{s.keys.has(Re(xe,ve))||(Math.abs(K.x-b)<C&&(C=Math.abs(K.x-b),R=K.x-h.x),Math.abs(K.y-_)<O&&(O=Math.abs(K.y-_),j=K.y-h.y))})),{dx:R,dy:j}}function Oh(s,f){if(!g)return!1;let c=(m,h)=>{F&&Ci(Ut(h,m,!1,me,F))};switch(g.kind){case"points":{let m=f;s.shiftKey&&(m=ko(g.origin,f));let h={dx:m.x-g.origin.x,dy:m.y-g.origin.y};if(!g.moved&&Math.hypot(h.dx,h.dy)*I.getCamera().zoom<an)return!0;g.moved=!0;let{dx:b,dy:_}=s.shiftKey?h:Lh(g,h.dx,h.dy,Tr(s));return g.last=Ra(g.start,g.keys,b,_),c(g.last,g.id),!0}case"pathHandle":{let m=g.start[g.contour]?.anchors[g.index],h=s.shiftKey&&m?ko(m,f):f;return g.last=Ia(g.start,g.contour,g.index,g.side,h,{smooth:g.smooth,breakSmooth:s.altKey}),c(g.last,g.id),!0}case"segment":return g.last=kp(g.start,g.contour,g.segment,g.t,f.x-g.origin.x,f.y-g.origin.y,g.straight),c(g.last,g.id),!0;case"pointMarquee":return g.current=f,Q(),!0;default:return!1}}function Dh(s){if(!g)return!1;switch(g.kind){case"points":case"pathHandle":case"segment":{let f=g.kind!=="points"||g.moved,c=g.kind==="points"?g.keys.size===1?"Move point":"Move points":g.kind==="pathHandle"?"Adjust curve":"Reshape";return $=f&&F?Ut(g.id,g.last,!0,me,F):[],Ht(c),!0}case"pointMarquee":{let f=Tn(g.origin,g.current),c=g.additive;if(g=null,_e=ot,!Z)return!0;let m=I.getCamera().zoom;if(f.w*m<an&&f.h*m<an){if(I.hitTest(s)===Z.id)Z.picked=new Set;else{Or();let _=Er(s);ce(_===null?[]:[_])}return Q(),!0}let h=Lr(Z.id)??[],b=Tl(h).filter(_=>{let C=Al(h,_);return C!==void 0&>(f,C.x,C.y)});return Z.picked=new Set(c?[...Z.picked,...b]:b),Q(),!0}default:return!1}}function Ph(s){if(!Z)return!1;let f=Z.id,c=s.metaKey||s.ctrlKey;if(s.key==="Escape"||s.key==="Enter"&&!c)return s.preventDefault(),g?Ai():Or(),!0;let m=Lr(f);if(!m)return!1;let h=new Set($l(m,Z.picked));if(s.key==="Delete"||s.key==="Backspace"){if(s.preventDefault(),h.size===0)return!0;let O=wp(m,h);return Z.picked=new Set,O.length===0?(Or(),Hn(),!0):(he(Ut(f,O,!0),h.size===1?"Delete point":"Delete points"),!0)}let b=s.shiftKey?10:1,C={ArrowLeft:[-b,0],ArrowRight:[b,0],ArrowUp:[0,-b],ArrowDown:[0,b]}[s.key];return C&&!c?(s.preventDefault(),h.size>0&&he(Ut(f,Ra(m,h,C[0],C[1]),!0),"Nudge points"),!0):c&&s.key.toLowerCase()==="a"?(s.preventDefault(),Z.picked=new Set(Tl(m)),Q(),!0):c&&!s.shiftKey&&s.code==="KeyJ"?(s.preventDefault(),he(Ut(f,_p(m,h),!0),"Close path"),!0):!1}function Ih(s,f){if(s.preventDefault(),st(s.pointerId),!Y){Y=Nh(f)??{contours:[{closed:!1,anchors:[{x:f.x,y:f.y}]}],contour:0,target:null,hover:null,dragging:null};let _=Y.contours[Y.contour];Y.dragging={pointerId:s.pointerId,index:_.anchors.length-1,origin:f},Q();return}let c=Y.contours[Y.contour],m=c.anchors[0],h=c.anchors[c.anchors.length-1];if(m&&c.anchors.length>=2&&Dr(m,f)<=Vo){Y.contours[Y.contour]={...c,closed:!0},Y.dragging={pointerId:s.pointerId,index:0,origin:m},Q();return}let b=s.shiftKey&&h?ko(h,f):f;Y.contours[Y.contour]={...c,anchors:[...c.anchors,{x:b.x,y:b.y}]},Y.dragging={pointerId:s.pointerId,index:c.anchors.length,origin:b},Q()}function Nh(s){let f=r.length===1?r[0]:null;if(f===null||!fn(f))return null;let c=Lr(f);if(!c)return null;for(let m=0;m<c.length;m+=1){let h=c[m];if(h.closed||h.anchors.length<1)continue;let b=h.anchors[0],_=h.anchors[h.anchors.length-1],C=Dr(_,s)<=Vo,O=!C&&Dr(b,s)<=Vo;if(!C&&!O)continue;let R=[...c];return O&&(R[m]=Sp(h)),{contours:R,contour:m,target:f,hover:null,dragging:null}}return null}function Rh(s,f){if(!Y)return;let c=Y.dragging;if(!c||c.pointerId!==s.pointerId){let O=Y.contours[Y.contour],R=O?.anchors[O.anchors.length-1];Y.hover=s.shiftKey&&R?ko(R,f):f,Q();return}if(Dr(c.origin,f)<an)return;let m=Y.contours[Y.contour],h=m.anchors[c.index];if(!h)return;let b={x:2*h.x-f.x,y:2*h.y-f.y},_=s.altKey?h.in:b,C=[...m.anchors];C[c.index]={x:h.x,y:h.y,..._?{in:_}:{},out:f},Y.contours[Y.contour]={...m,anchors:C},Q()}function Fh(s){!Y?.dragging||Y.dragging.pointerId!==s.pointerId||(Hi(s.pointerId),Y.dragging=null,Y.contours[Y.contour]?.closed?zo():Q())}function zo(){if(!Y)return;let s=Y;Y=null;let f=s.contours[s.contour];if(!f||f.anchors.length<2){Q();return}if(s.target!==null){he(Ut(s.target,s.contours,!0),"Extend path"),Vt("select"),pn(s.target);return}let c=Sn(s.contours),m=f.anchors[0];if(!c)return;let h=Sr(m)??w??n.root.id,b=U(n.root,h)??n.root,_=dn(h),C=Lt(s.contours,R=>({x:R.x-c.x,y:R.y-c.y})),O=Wt(n.root,"path");he([{op:"insert",parent:h,index:re(b).length,node:Qo({id:O,x:ee(c.x-_.x),y:ee(c.y-_.y),w:ee(c.w),h:ee(c.h),view:En({x:0,y:0,w:c.w,h:c.h}),d:Tt(C),fill:"none",stroke:t.defaultStroke??"#1f2937",strokeWidth:2,cap:"round",join:"round"})}],"Draw path"),Vt("select"),pn(O)}function $i(s=ie()){let f=[],c=[];for(let m of s){let h=U(n.root,m),b=ct(n.root,m),_=Ct(m);if(!h||!b||!_||h.type!=="rect"&&h.type!=="ellipse")continue;let C=Math.max(0,_.w),O=Math.max(0,_.h),R=h.type==="rect"?ss(C,O,_.values.radius??0):ls(C,O),j=Qo({id:m,...h.name===void 0?{}:{name:h.name},x:h.x,y:h.y,w:h.w,h:h.h,view:En({x:0,y:0,w:C,h:O}),d:Tt(R),...h.fill===void 0?{}:{fill:h.fill},...h.stroke===void 0?{}:{stroke:h.stroke},...h.strokeWidth===void 0?{}:{strokeWidth:h.strokeWidth},...h.opacity===void 0?{}:{opacity:h.opacity},...h.hidden?{hidden:!0}:{},...h.locked?{locked:!0}:{}}),W=b.children.findIndex(xe=>xe.id===m);f.push({op:"remove",id:m},{op:"insert",parent:b.id,index:W,node:j}),c.push(m)}c.length!==0&&(he(f,c.length===1?"Convert to vector":`Convert ${c.length} to vector`),ce(c),c.length===1&&pn(c[0]))}function zf(){return ie().filter(s=>{let f=U(n.root,s)?.type;return f==="rect"||f==="ellipse"}).length}let Bh=450,jf=4,Pr={x:0,y:0,at:0,count:0};function Hh(s){let f=Date.now(),m=Math.abs(s.x-Pr.x)<=jf&&Math.abs(s.y-Pr.y)<=jf&&f-Pr.at<=Bh?Pr.count+1:1;return Pr={x:s.x,y:s.y,at:f,count:m},m}let qf=s=>{if(M=s.pointerType==="touch",M){y.add(s.pointerId),k=y.size===1?{pointerId:s.pointerId,screen:I.pointerPoint(s)}:null;return}if(s.button!==0||x)return;let f=I.pointerPoint(s),c=I.screenToDocument(f);We=c;let m=Hh(f);if(G){let O=_i(c),R=I.itemOf(G.id),j=Ar(G.id,c);if(O&&R&>(R,j.x,j.y)){s.preventDefault(),st(s.pointerId),N=!0,m>=3?G.selectLineAt(O):m===2?G.selectWordAt(O):G.pointTo(O,s.shiftKey),z.focus({preventScroll:!0}),Q();return}un("blur")}if(e.focus({preventScroll:!0}),o==="select"&&(s.metaKey||s.ctrlKey)&&Be(c)){s.preventDefault();return}if(o==="pen"){Ih(s,c);return}if(Z&&o==="select"&&Th(s,f,Ar(Z.id,c),m))return;if(o!=="select"){s.preventDefault(),st(s.pointerId),tt({kind:"create",pointerId:s.pointerId,origin:c,current:c}),Q();return}let h=ie().length===1?ie()[0]:null;if(h!==null){let O=U(n.root,h),R=fe.hitAdjuster(f),j=O&&R?Va(O,R.id):void 0,W=j?Ie(h):void 0;if(j&&W&&R){s.preventDefault(),st(s.pointerId),tt({kind:"adjust",pointerId:s.pointerId,id:h,adjuster:j,handleId:R.id,frame:W,from:Ct(h)?.values[j.prop]??0});return}let xe=O&&!ye(O)?fe.hitHandle(f):null,K=xe?Bt(h):void 0,ve=K?sn(h):void 0;if(xe&&K&&ve){s.preventDefault(),st(s.pointerId),tt({kind:"resize",pointerId:s.pointerId,origin:c,id:h,handle:xe.handle,frame:K,offset:{x:ve.x-K.x,y:ve.y-K.y},rotation:ln(h)});return}}let b=ie().length>0?fe.hitHandle(f):null;if(b&&xh(c,b.handle,s.pointerId)){s.preventDefault();return}let _=fe.hitPageLabel(f);if(_!==null){if(s.preventDefault(),w=null,s.shiftKey){ce(r.includes(_)?r.filter(O=>O!==_):[...r,_]);return}if(r.includes(_)||ce([_]),m===2){fh(_);return}Kf(c,s.pointerId,s.altKey);return}if(ie().length>0&&fe.hitRotate(f)!==null&&hh(c,s.pointerId)){s.preventDefault();return}if(ie().length>1){let O=fe.hitRing(f);if(O!==null&&kh(O,c,s.pointerId)){s.preventDefault();return}let R=fe.hitSpacer(f);if(R!==null&&yh(R,c,s.pointerId)){s.preventDefault();return}}let C=Er(c);if(C===null){s.preventDefault(),st(s.pointerId),w=null,s.shiftKey||ce([]),tt({kind:"marquee",pointerId:s.pointerId,origin:c,current:c});return}w!==null&&!je(n.root,C).includes(w)&&(w=null),s.shiftKey?ce(r.includes(C)?r.filter(O=>O!==C):[...r,C]):r.includes(C)||ce([C]),Kf(c,s.pointerId,s.altKey)&&s.preventDefault()};function Uh(s){G&&un("blur");let f=Er(I.screenToDocument(s));f!==null&&w!==null&&!je(n.root,f).includes(w)&&(w=null),f===null&&(w=null),ce(f===null?[]:[f])}function Kf(s,f,c){let m=n,h=[];if(c){let _=mu({x:0,y:0});_&&(h=_.ops,n=Ae(n,h).document,I.update(n),ce(_.ids))}let b=new Map;for(let _ of ie())for(let C of Ln(_,n)){let O=Bt(C);O&&b.set(C,O)}return b.size===0?(n=m,I.update(n),!1):(st(f),tt({kind:"move",pointerId:f,origin:s,frames:b,bounds:xt(ie().flatMap(_=>Ie(_)??[]))},h,m),!0)}let Gf=s=>{let f=I.pointerPoint(s);if(s.pointerType==="touch"){k?.pointerId===s.pointerId&&Math.hypot(k.screen.x-f.x,k.screen.y-f.y)>B0&&(k=null);return}if(We=I.screenToDocument(f),N&&G){let m=_i(We);m&&G.pointTo(m,!0);return}if(Y&&o==="pen"){Rh(s,We);return}if(!g){qh(f);return}if(g.pointerId!==s.pointerId)return;let c=We;if(!Oh(s,Z?Ar(Z.id,c):c))switch(g.kind){case"move":{let m=c.x-g.origin.x,h=c.y-g.origin.y;if(g.bounds){let _={...g.bounds,x:g.bounds.x+m,y:g.bounds.y+h};_e=Bd(_,Me,Tr(s)),m+=_e.dx,h+=_e.dy}let b=[];for(let[_,C]of g.frames)b.push({nodeId:_,prop:"x",from:C.x,to:C.x+m}),b.push({nodeId:_,prop:"y",from:C.y,to:C.y+h});cn(b);return}case"resize":{let{id:m,handle:h,frame:b,origin:_,offset:C,rotation:O}=g,R=c.x-_.x,j=c.y-_.y;if(O!==0){_e=ot;let K=hp(b,h,R,j,O);cn(Da(b,K).map(ve=>({nodeId:m,prop:ve,from:b[ve],to:K[ve]})));return}let W=It(b,h,R,j);_e=Xa({...W,x:W.x+C.x,y:W.y+C.y},h,Me,Tr(s)),R+=_e.dx,j+=_e.dy;let xe=It(b,h,R,j);cn(Da(b,xe).map(K=>({nodeId:m,prop:K,from:b[K],to:xe[K]})));return}case"scale":{let{handle:m,bounds:h,origin:b,frames:_,offsets:C}=g,O=c.x-b.x,R=c.y-b.y,j=It(h,m,O,R);_e=Xa(j,m,Me,Tr(s)),O+=_e.dx,R+=_e.dy,cn(Bf({bounds:h,frames:_,offsets:C},It(h,m,O,R)));return}case"space":vh(g,c);return;case"reorder":_h(g,c,s.metaKey||s.ctrlKey);return;case"rotate":{let{centre:m,origin:h,targets:b}=g,_=b[0],C=xp(m,h,c,_?.rotation??0,s.shiftKey?A0:void 0);B=lo((_?.rotation??0)+C);let O=[],R=b.length===1;for(let j of gp(b,m,C)){let W=b.find(xe=>xe.id===j.id);W&&(O.push({nodeId:j.id,prop:"rotation",from:W.rotation,to:j.rotation}),!R&&O.push({nodeId:j.id,prop:"x",from:W.frame.x-W.offset.x,to:ee(j.frame.x-W.offset.x)},{nodeId:j.id,prop:"y",from:W.frame.y-W.offset.y,to:ee(j.frame.y-W.offset.y)}))}cn(O);return}case"adjust":{let m=g.adjuster.valueAt(g.frame,g.handleId,c);L=m,cn([{nodeId:g.id,prop:g.adjuster.prop,from:g.from,to:m}]);return}case"create":{_e=Hd(c,Me,Tr(s));let m={x:c.x+_e.dx,y:c.y+_e.dy};g.current=s.shiftKey&&o!=="text"?L0(g.origin,m):m,Q();return}case"marquee":{g.current=c,Q();return}}},jo=s=>{if(s.pointerType==="touch"){if(y.delete(s.pointerId),k?.pointerId!==s.pointerId)return;k=null,s.type==="pointerup"&&Uh(I.pointerPoint(s));return}if(N){N=!1,Hi(s.pointerId),z.focus({preventScroll:!0});return}if(Y){Fh(s);return}if(!g||g.pointerId!==s.pointerId)return;Hi(s.pointerId);let f=I.screenToDocument(I.pointerPoint(s));if(!Dh(Z?Ar(Z.id,f):f))switch(g.kind){case"create":{let c=Tn(g.origin,g.current),m=o==="text"?"text":o==="frame"?"frame":o==="ellipse"?"ellipse":"rect";g=null,_e=ot,Q();let h=c.w<an||c.h<an;if(h&&m!=="text")return;let b=h?{x:c.x,y:c.y,w:Mm.w,h:Mm.h}:c,_=Sr({x:b.x,y:b.y})??w??n.root.id,C=U(n.root,_)??n.root,O=dn(_),R={x:Math.round(b.x-O.x),y:Math.round(b.y-O.y),w:Math.round(b.w),h:Math.round(b.h)},j=Wt(n.root,m);he([{op:"insert",parent:_,index:re(C).length,node:m==="text"?qi({...R,id:j,content:""}):m==="frame"?Zo({...R,id:j,background:Em,children:[]}):m==="ellipse"?Ui({...R,id:j,fill:t.defaultFill??"#3b82f6"}):ji({...R,id:j,fill:t.defaultFill??"#3b82f6"})}],T0[m]),ce([j]),Vt("select"),m==="text"&&$r(j);return}case"marquee":{let c=Tn(g.origin,g.current),m=s.shiftKey;if(g=null,_e=ot,c.w>=an||c.h>=an){let h=ux(c);ce(m?[...new Set([...r,...h])]:h)}Q();return}case"move":{let c=Mh();c.length>0&&($=[...$,...c]),Ht(S.length>0?"Duplicate":"Move");return}case"resize":Ht("Resize");return;case"scale":Ht(r.length===1?"Resize group":`Resize ${r.length} elements`);return;case"space":Ht("Spacing");return;case"reorder":Ht(g.swap?"Swap":"Reorder");return;case"adjust":Ht("Corner radius");return;case"rotate":Ht("Rotate");return}},Wf=s=>{if(xi(s.target))return;if(G){if(!((s.metaKey||s.ctrlKey)&&s.key.toLowerCase()==="z"))return;s.preventDefault(),G.breakBurst(),s.shiftKey?Wo():Nr();return}if(Y&&(s.key==="Enter"||s.key==="Escape")){s.preventDefault(),zo();return}if(Ph(s))return;if((s.metaKey||s.ctrlKey)&&s.shiftKey&&s.code==="KeyO"){if(zf()===0)return;s.preventDefault(),$i();return}if(s.key==="Enter"&&!$m(s)&&r.length===1){let m=r[0];if(U(n.root,m)?.type==="vector"&&pn(m)){s.preventDefault();return}}if(s.key==="Enter"&&!$m(s)&&r.length===1){let m=r[0];if(U(n.root,m)?.type==="text"){s.preventDefault(),$r(m);return}}if(s.code==="Space"&&!x){x=!0,qe(Fe("grab"));return}let f=s.metaKey||s.ctrlKey;if(f&&s.key.toLowerCase()==="z"){s.preventDefault(),s.shiftKey?Wo():Nr();return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyL"){if(!D.lock||r.length===0)return;s.preventDefault(),Bn(r,"locked");return}if(f&&s.shiftKey&&!s.altKey&&s.code==="KeyH"){if(!D.hide||r.length===0)return;s.preventDefault(),Bn(r,"hidden");return}if(f&&s.key.toLowerCase()==="g"){s.preventDefault(),s.shiftKey?Ni():Ii();return}if(f&&s.key.toLowerCase()==="a"){s.preventDefault(),Fi();return}if(f&&!s.altKey&&s.key.toLowerCase()==="d"){s.preventDefault(),Di();return}if(s.altKey){let m=O0[s.code];if(m&&!f){s.preventDefault(),fu(m);return}let h=D0[s.code];if(h&&s.ctrlKey){s.preventDefault(),cu(h);return}}if(s.key==="]"||s.key==="["){if(r.length===0)return;s.preventDefault();let m=s.key==="]";Ri(f?m?"front":"back":m?"forward":"backward");return}if(s.key==="Escape"){g?Ai():w!==null?wu():ce([]);return}if(s.key==="Delete"||s.key==="Backspace"){if(r.length===0)return;s.preventDefault(),Hn();return}let c=f||s.altKey?void 0:gf[s.key.toLowerCase()];c&&Vt(c)};function Xf(){if(!G)return null;let s=U(n.root,G.id);if(s?.type!=="text")return null;let{anchor:f,head:c}=G.getSelection();return f===c?null:In(lf(s.content,f,c))}let Yf=s=>{if(xi(s.target))return;let f=Xf()??Ir();f!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",f))},Jf=s=>{if(xi(s.target))return;let f=Xf();if(f!==null&&G){s.preventDefault(),s.clipboardData?.setData("text/plain",f);let{anchor:m,head:h}=G.getSelection();G.breakBurst(),G.setSelection(m,h),G.handleInput({inputType:"deleteByCut",data:null});return}let c=Ir();c!==null&&(s.preventDefault(),s.clipboardData?.setData("text/plain",c),Hn())},Zf=s=>{if(xi(s.target))return;s.preventDefault();let f=Ol(s.clipboardData);if(f&&!G){let m=ex();m?Oi(m,f):xu(f,We??void 0);return}let c=s.clipboardData?.getData("text/plain")||void 0;if(G&&c!==void 0){G.handleInput({inputType:"insertFromPaste",data:c});return}Li(c)},Qf=s=>{s.code==="Space"&&(x=!1,qe(Fe(ki())))},eu=s=>{if(!Se)return;s.preventDefault(),g&&Ai();let f=I.pointerPoint(s),c=I.screenToDocument(f),m=Er(c),h=Vh(c),b=I.hitTest(c),_=b!==null&&r.some(O=>je(n.root,b).includes(O));m===null?_||ce([]):r.includes(m)||ce([m]);let C=(t.menuExtras?.(r)??[]).map(O=>"separator"in O?O:{...O,id:`${vf}${O.id}`});Se.open(f,qd(zh(h),C))};function Vh(s){let{locked:f}=Qe(),c=[];for(let m of[...I.getScene().items].reverse()){if(!f.has(m.id)||!I.hitTest(s,b=>b===m.id))continue;let h=Rr(n.root,m.id,"locked");h!==void 0&&!c.includes(h)&&c.push(h)}return c}function zh(s=[]){let f=r.length===1?U(n.root,r[0]):void 0,c=[];if(f){let m=f;for(let h of yt(f)){let b=m[h];b===void 0||!be(b)||wa(b).kind!=="literal"&&c.push({prop:h,source:`=${b.expr}`})}}return{count:r.length,hasGroup:r.some(m=>{let h=U(n.root,m);return h!==void 0&&Oe(h)}),canPaste:bf!==null,isText:r.length===1&&U(n.root,r[0])?.type==="text",isVector:ie().length===1&&U(n.root,ie()[0])?.type==="vector",convertible:zf(),bound:c,lock:D.lock?r.every(m=>Qe().locked.has(m))?"unlock":"lock":null,hide:D.hide?r.every(m=>Qe().hidden.has(m))?"show":"hide":null,locksHere:s,anyLocked:Bi("locked").length>0,hiddenCount:Bi("hidden").length}}function jh(s){if(e.focus({preventScroll:!0}),s.startsWith(vf)){t.onMenuCommand?.(s.slice(vf.length),[...r]);return}if(s.startsWith("unlock:")){Fn([s.slice(7)],"locked",!1);return}if(s.startsWith("detach:")){let f=s.slice(7),c=r[0];c!==void 0&&Su(c,f);return}switch(s){case"copy":Ir();return;case"cut":hu();return;case"editText":{let f=r[0];f!==void 0&&$r(f);return}case"editPoints":{let f=r[0];f!==void 0&&pn(f);return}case"toVector":return $i();case"duplicate":return Di();case"paste":return Li();case"group":return Ii();case"ungroup":return Ni();case"front":case"forward":case"backward":case"back":return Ri(s);case"delete":return Hn();case"selectAll":return Fi();case"toggleLock":return Bn(r,"locked");case"toggleHidden":return Bn(r,"hidden");case"unlockAll":return Go("locked");case"showAll":return Go("hidden");case"fit":return I.fitToContent();case"zoom100":return I.setCamera({...I.getCamera(),zoom:1})}}let tu=s=>{if(M||o!=="select"||x||Z)return;let f=I.screenToDocument(I.pointerPoint(s)),c=I.hitTest(f,C=>!Qe().locked.has(C));if(c===null)return;let m=Ko().find(C=>C.id===c);if(m){s.preventDefault(),tx(m);return}let h=U(n.root,c);if(h?.type==="text"){s.preventDefault(),$r(c,f);return}if(h?.type==="vector"){s.preventDefault(),pn(c);return}let b=je(n.root,c),_=w===null?1:b.indexOf(w)+1;for(let C=Math.max(_,1);C<b.length;C+=1){let O=b[C];if(O===void 0)break;let R=U(n.root,O);if(!(!R||!Oe(R))){s.preventDefault(),bu(O),ce([b[C+1]??O]);return}}},nu=s=>Array.from(s.dataTransfer?.types??[]).includes("Files"),ru=()=>t.importImage!==void 0||t.importAudio!==void 0,ou=s=>{if(!nu(s)||!ru())return;s.preventDefault(),s.dataTransfer&&(s.dataTransfer.dropEffect="copy");let f=I.screenToDocument(I.pointerPoint(s)),c=yu(f)?.id??null;c!==u&&(u=c,Q())},au=s=>{s.relatedTarget instanceof Node&&e.contains(s.relatedTarget)||u!==null&&(u=null,Q())},iu=s=>{if(!nu(s)||!ru())return;s.preventDefault();let f=I.screenToDocument(I.pointerPoint(s)),c=yu(f);u=null,Q();let m=Array.from(s.dataTransfer?.files??[]),h=m.find(Cp);if(h&&t.importAudio){let _=Sr(f),C=_===null?void 0:lt(n).get(_),O=Ba(n),R=C!==void 0&&O.includes(C)?C:Ha(n,r,null)??C??null;R!==null&&gu(h,R);return}if(!t.importImage)return;let b=m.find(_=>_.type.startsWith("image/"));b&&(c?Oi(c,b):xu(b,f))},su=()=>{We=null,l=null,!g&&(a===null&&ne===null&&ke===null||(a=null,ne=null,ke=null,Q()))};function lu(){let s=ie().length===1?ie()[0]:void 0,f=s===void 0?void 0:U(n.root,s);return s!==void 0&&f&&!ye(f)?ln(s):0}function qh(s){if(x){qe(Fe("grab"));return}if(Z){it(null),qe(Fe("arrow"));return}if(o!=="select"){it(null),Ti(null),qo(null),qe(Fe(o==="text"?"text":"crosshair"));return}let f=ie().length===1?ie()[0]:null;if(f!==null){let b=fe.hitAdjuster(s);if(b){let _=U(n.root,f),C=_?Va(_,b.id):void 0;it(null),Ti(C?{id:b.id,prop:C.prop}:null),qe(Fe("radius",{badge:C?bi(f,[C.prop]):"none"}));return}Ti(null)}if(ie().length>0){let b=fe.hitHandle(s);if(b){it(null);let O=Oa(b.handle);qe(Fe("resize",{angle:Sl(b.handle)+lu(),badge:Of(Mr(),O)}));return}let _=fe.hitPageLabel(s);if(_!==null){it(_),qe(Fe("arrow"));return}let C=fe.hitRotate(s);if(C!==null){it(null),qe(Fe("rotate",{angle:$0[C]+lu()}));return}}let c=fe.hitPageLabel(s);if(c!==null){l=null,it(c),qe(Fe("arrow"));return}if(ie().length>1){if(fe.hitRing(s)!==null){it(null),qo(null),qe(Fe("grab"));return}let _=fe.hitSpacer(s),C=_===null?null:ii(_);if(_!==null&&C){it(null),qo(_),qe(Fe("resize",{angle:C.axis==="x"?0:90,badge:Of(Mr(),[C.axis])}));return}qo(null)}let m=I.screenToDocument(s),h=Er(m);l=Kh(m,h),it(h),Q(),qe(Fe("arrow",{badge:h===null?"none":bi(h,["x","y"])}))}function Kh(s,f){let c=I.hitTest(s);if(c===null||!Qe().locked.has(c))return null;let m=Rr(n.root,c,"locked");return m===void 0?null:f===null||je(n.root,m).includes(f)?m:null}function it(s){a!==s&&(a=s,Q())}function Ti(s){ne?.id!==s?.id&&(ne=s,Q())}function qo(s){ke!==s&&(ke=s,Q())}function qe(s){e.style.cursor!==s&&(e.style.cursor=s)}function Vt(s){o!==s&&(o=s,Y&&s!=="pen"&&zo(),s!=="select"&&Or(),we?.setTool(o),s!=="select"&&it(null),qe(Fe(ki())),de("tool",o))}function Gh(s){if(s.length===0)return null;if(s.length>1)return xt(s.map(m=>m.frame))??null;let f=s[0],c=ct(n.root,f.id);return c?On(c.id,n,I.getResolution())??null:null}function du(s,f,c){let m=br(n,Mi(Fo(r),s,f));m.length!==0&&he([...m,...wr(n,m,ir(n),Ne(n))],c)}function fu(s){let f=Ao(n,r,I.getResolution()),c=Gh(f);c&&du(Ua(s),Dl(f,c,s),P0[s])}function uu(s){let f=Ao(n,r,I.getResolution());if(f.length<3)return null;let c=tf(f,s),m=nf(c);return m===null?null:{gap:m,series:c}}function cu(s){let f=uu(s);f&&du(s,li(f.series,f.gap),s==="x"?"Distribute horizontally":"Distribute vertically")}function Wh(){let s=Co(n,r);if(s.length===0)return null;let f=I.getResolution(),c={};for(let m of s)se(m,h=>{let b=f.nodes.get(h.id)?.values;b&&(c[h.id]=b)});return{nodes:s,tokens:n.tokens,fonts:n.fonts,resolved:c}}function Xh(s){return new Map(Object.entries(s.resolved))}function Yh(s){let f=Object.entries(s.tokens).filter(([c])=>n.tokens[c]===void 0).map(([c,m])=>({op:"setToken",name:c,value:m}));for(let[c,m]of Object.entries(s.fonts))n.fonts[c]===void 0&&f.push({op:"setFont",name:c,family:m});return f}function pu(s,f,c){let{nodes:m,remap:h}=Od(s,n);if(m.length===0)return null;let b=Yh(s),_=b.length>0?Ae(n,b).document:n;m.forEach((R,j)=>{let W=s.nodes[j];if(!W)return;let xe=f(W,j,_),K={op:"insert",parent:xe.parent,index:xe.index,node:R};b.push(K),_=Ae(_,[K]).document});let C=yf(_,h,Xh(s),c);C.length>0&&(_=Ae(_,C).document);let O=Jh(m);return{ops:[...b,...C,...kr(n,_)],ids:[...h.values()].filter(R=>O.has(R))}}function Jh(s){let f=new Set;for(let c of s)f.add(c.id);return f}function mu(s){let f=Wh();return f?pu(f,(c,m,h)=>{let b=ct(h.root,c.id)??h.root,_=re(b).findIndex(C=>C.id===c.id);return{parent:b.id,index:_===-1?re(b).length:_+1}},s):null}function Ir(){let s=Td(n,r,I.getResolution());return s!==null&&(bf=s),s}function hu(){let s=Ir();return s!==null&&Hn(),s}function Zh(s){let f=[];for(let c of s.nodes){let m=s.resolved[c.id];if(!m)continue;let{x:h,y:b,w:_,h:C}=m;h===void 0||b===void 0||_===void 0||C===void 0||f.push({x:h,y:b,w:_,h:C})}return xt(f)??null}function Li(s,f){let c=Ld(s??bf??"");if(!c)return;let m=f??We,h=Zh(c),b=m&&h?{x:m.x-(h.x+h.w/2),y:m.y-(h.y+h.h/2)}:{x:hi,y:hi},_=w??n.root.id,C=pu(c,(O,R,j)=>({parent:_,index:re(U(j.root,_)??j.root).length}),b);C&&(he(C.ops,C.ids.length===1?"Paste":`Paste ${C.ids.length} elements`),ce(C.ids))}async function xu(s,f){let c=t.importImage;if(!c)return;let m=await Fa(s,t.maxImageEdge??2560);if(!m)return;let h=await c(new File([m.bytes],s.name,{type:m.type}));if(!h)return;let b=(f?Sr(f):void 0)??w??n.root.id,_=U(n.root,b)??n.root,C=dn(b),O=I.getResolution().nodes.get(b),{w:R,h:j}=Ep(m.width,m.height,O?.w&&O.w>0?O.w:m.width,O?.h&&O.h>0?O.h:m.height),W=f??We,xe=Math.round((W?W.x-R/2:C.x)-C.x),K=Math.round((W?W.y-j/2:C.y)-C.y),ve=nx(n,s.name),He=Wt(n.root,"image");he([{op:"setAsset",name:ve,value:h},{op:"insert",parent:b,index:re(_).length,node:zi({id:He,x:xe,y:K,w:R,h:j,src:ve,fit:"cover"})}],"Place image"),ce([He])}async function gu(s,f){let c=t.importAudio;if(!c)return!1;let m=await c(s);return m?(he(Ap(n,f,Mp(n,f,s.name),m),"Add music"),!0):!1}function Ko(){return t.importImage?um(n,Qe().hidden):[]}function Qh(){return Ko().flatMap(s=>{let f=Ie(s.id);return f?[{frame:f,label:s.label,target:s.id===u}]:[]})}function yu(s){return Ko().filter(c=>{let m=Ie(c.id);return m!==void 0&>(m,s.x,s.y)}).at(-1)??null}function ex(){return r.length!==1?null:Ko().find(s=>s.id===r[0])??null}async function Oi(s,f){let c=t.importImage;if(!c)return;let m=await Fa(f,t.maxImageEdge??2560);if(!m)return;let h=await c(new File([m.bytes],f.name,{type:m.type}));!h||n.assets[s.src]!==void 0||(he([{op:"setAsset",name:s.src,value:h}],"Add image"),ce([s.id]))}function tx(s){let f=e.ownerDocument.createElement("input");f.type="file",f.accept="image/*",f.addEventListener("change",()=>{let c=f.files?.[0];c&&Oi(s,c)}),f.click()}function nx(s,f){let c=f.replace(/\.[^.]+$/,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"image";if(s.assets[c]===void 0)return c;for(let m=2;;m+=1){let h=`${c}-${m}`;if(s.assets[h]===void 0)return h}}function Di(){let s=mu({x:hi,y:hi});s&&(he(s.ops,s.ids.length===1?"Duplicate":`Duplicate ${s.ids.length} elements`),ce(s.ids))}function Pi(s,f){if(s.length===0)return;let c=Ae(n,s).document;he([...s,...kr(n,c)],f)}function Ii(){let s=Dd(n,r);s&&(Pi(s.ops,"Group"),ce([s.groupId]))}function Ni(){let s=r.filter(h=>{let b=U(n.root,h);return b!==void 0&&Oe(b)});if(s.length===0)return;let f=n,c=[],m=[];for(let h of s){let b=U(f.root,h);b&&m.push(...re(b).map(C=>C.id));let _=Pd(f,h);_.length!==0&&(c.push(..._),f=Ae(f,_).document)}w!==null&&s.includes(w)&&(w=null),Pi(c,s.length===1?"Ungroup":`Ungroup ${s.length} groups`),ce(m)}function Ri(s){Pi(Id(n,r,s),R0[s])}function rx(s,f,c){let m=U(n.root,f);if(!m||!ye(m))return;let h=new Set(je(n.root,f)),b=s.filter(K=>K!==n.root.id&&U(n.root,K)&&!h.has(K));if(b.length===0)return;let _=new Set(b),C=re(m).filter(K=>!_.has(K.id))[c]?.id,O=[],R=n;for(let K of b){let ve=re(U(R.root,f)??R.root).filter(ut=>ut.id!==K),He=C===void 0?-1:ve.findIndex(ut=>ut.id===C),Ue={op:"move",id:K,parent:f,index:He===-1?ve.length:He};O.push(Ue),R=Ae(R,[Ue]).document}if(b.every(K=>ax(n,R,K)))return;let j=new Set(b.filter(K=>ct(n.root,K)?.id!==f).flatMap(K=>Uf(K,R))),W=[];for(let K of b){let ve=vu(n,K),He=vu(R,K),Ue={x:ve.x-He.x,y:ve.y-He.y};if(!(Ue.x===0&&Ue.y===0))for(let ut of Ln(K,R)){let Un=Bt(ut);Un&&(W.push({op:"set",id:ut,prop:"x",value:ee(Un.x+Ue.x)}),W.push({op:"set",id:ut,prop:"y",value:ee(Un.y+Ue.y)}))}}let xe=Ae(R,W).document;he([...O,...W,...kr(n,xe,j)],b.length===1?`Move ${b[0]}`:`Move ${b.length} layers`)}function ox(s={}){let f=n.root.children,c=f.filter(He=>He.type==="frame"),m=c.find(He=>He.id===s.after),h=I.getResolution(),b=m?h.nodes.get(m.id):void 0,_=b&&b.w>0?b.w:Cm.w,C=b&&b.h>0?b.h:Cm.h,O=null,R=-1/0;for(let He of c.length>0?c:f){let Ue=h.nodes.get(He.id);!Ue||Ue.absX+Ue.w<=R||(R=Ue.absX+Ue.w,O={x:R+M0,y:Ue.absY})}let j=O??{x:0,y:0},W=m??c[c.length-1],xe=W?f.indexOf(W)+1:f.length,K=Wt(n.root,"frame"),ve=m?.type==="frame"?m.background:void 0;return he([{op:"insert",parent:n.root.id,index:xe,node:Zo({id:K,x:ee(j.x),y:ee(j.y),w:ee(_),h:ee(C),background:ve??Em,children:[]})}],"Add frame"),ce([K]),K}function ax(s,f,c){let m=ct(s.root,c),h=ct(f.root,c);return m?.id===h?.id&&m?.children.findIndex(b=>b.id===c)===h?.children.findIndex(b=>b.id===c)}function vu(s,f){let c=je(s.root,f).slice(0,-1).reverse(),m=Ne(s);for(let h of c){let b=U(s.root,h);if(!b||Oe(b))continue;let _=m.nodes.get(h);return _?{x:_.absX,y:_.absY}:{x:0,y:0}}return{x:0,y:0}}function bu(s){let f=U(n.root,s);!f||!Oe(f)||(w=s,Q())}function wu(){if(w===null)return;let s=w;w=je(n.root,s).slice(0,-1).reverse().find(c=>{let m=U(n.root,c);return m!==void 0&&Oe(m)})??null,ce([s])}function Fi(){let s=U(n.root,w??n.root.id)??n.root;ce(re(s).map(f=>f.id).filter(fn))}let ix={locked:["Lock","Unlock"],hidden:["Hide","Show"]};function ku(s){return s==="locked"?Qe().locked:Qe().hidden}function Fn(s,f,c){let m=s.filter(_=>_!==n.root.id&&U(n.root,_)),h=c?m.filter(_=>!ku(f).has(_)):[...new Set(m.flatMap(_=>{let C=Rr(n.root,_,f);return C===void 0?[]:[C]}))];if(h.length===0)return;let b=ix[f][c?0:1];he(h.map(_=>({op:"set",id:_,prop:f,value:c?!0:void 0})),h.length===1?`${b} ${h[0]}`:`${b} ${h.length} layers`)}function Bn(s,f){s.length!==0&&Fn(s,f,!s.every(c=>ku(f).has(c)))}function Bi(s){let f=[];return se(n.root,c=>{c[s]===!0&&f.push(c.id)}),f}function Go(s){let f=Bi(s);if(f.length===0)return;let c=s==="locked"?"Unlock all":"Show all";he(f.map(m=>({op:"set",id:m,prop:s,value:void 0})),c)}function sx(s){D={...Am,...s},Se?.close()}function Hn(){let s=r.filter(c=>c!==n.root.id).map(c=>({op:"remove",id:c}));if(s.length===0)return;let f=s.length;ce([]),he(s,f===1?"Delete element":`Delete ${f} elements`)}function Nr(){et=null;let s=H.undo();s&&Df(s.ops,`Undo ${s.entry.label}`)}function Wo(){et=null;let s=H.redo();s&&Df(s.ops,`Redo ${s.entry.label}`)}function lx(s){if(!H.isTail(s))return!1;for(let f=s.length;f>0;f-=1)Nr();return!0}function _u(s,f,c,m){let h=U(n.root,s);if(!h)return;let b=h[f];H0(b,c)||he([{op:"set",id:s,prop:f,value:c}],m??`Set ${f}`)}function dx(s,f){n.tokens[s]!==f&&he([{op:"setToken",name:s,value:f}],`Set $${s}`)}function fx(s){s in n.tokens&&he([{op:"setToken",name:s,value:void 0}],`Remove $${s}`)}function Su(s,f){let c=Ct(s)?.values[f];c!==void 0&&he([{op:"set",id:s,prop:f,value:ee(c)}],`Detach ${f}`)}function ux(s){let f=U(n.root,w??n.root.id)??n.root,c=[];for(let m of re(f)){if(!fn(m.id))continue;let h=Ie(m.id);h&&El(h,s)&&c.push(m.id)}return c}function st(s){typeof e.setPointerCapture=="function"&&e.setPointerCapture(s)}function Hi(s){e.hasPointerCapture?.(s)&&e.releasePointerCapture(s)}let Eu=s=>{G&&(Rf(),G.handleKey(s)&&(s.preventDefault(),s.stopPropagation()))},Cu=s=>{G&&(s.preventDefault(),Rf(),G.handleInput(s))},Mu=()=>G?.handleCompositionStart(),Au=s=>G?.handleCompositionUpdate(s.data??""),$u=s=>G?.handleCompositionEnd(s.data??""),Tu=s=>{if(!e.ownerDocument.hasFocus())return;let f=s.relatedTarget;f instanceof Element&&f.closest("[data-vd-keeps-text]")||un("blur")};return z.addEventListener("keydown",Eu),z.addEventListener("beforeinput",Cu),z.addEventListener("compositionstart",Mu),z.addEventListener("compositionupdate",Au),z.addEventListener("compositionend",$u),z.addEventListener("blur",Tu),e.addEventListener("pointerdown",qf),e.addEventListener("pointermove",Gf),e.addEventListener("pointerup",jo),e.addEventListener("pointercancel",jo),e.addEventListener("pointerup",Ro),e.addEventListener("pointercancel",Ro),e.addEventListener("pointerleave",su),e.addEventListener("dblclick",tu),e.addEventListener("contextmenu",eu),e.addEventListener("keydown",Wf),e.addEventListener("keyup",Qf),e.addEventListener("copy",Yf),e.addEventListener("cut",Jf),e.addEventListener("paste",Zf),e.addEventListener("dragover",ou),e.addEventListener("dragleave",au),e.addEventListener("drop",iu),v=!0,we?.setTool(o),we?.setHistory(!1,!1),we?.setZoom(I.getCamera().zoom),qe(Fe(ki())),t.autoFit&&!t.camera&&Te(()=>I.fitToContent()),t.history&&(H.restore(t.history),we?.setHistory(H.canUndo,H.canRedo)),t.selection&&t.selection.length>0&&ce(t.selection),Q(),{element:e,viewer:I,getDocument:()=>n,update(s){n=s,I.update(n),ce(r),Q(),de("problems",wi())},applyOps:(s,f)=>he(s,f??"Apply changes"),setDocument:(s,f)=>he(us(n,wl(s,n.root.id)),f??"Replace document"),getSelection:()=>r,setSelection:ce,selectAll:Fi,deleteSelection:Hn,lock:s=>Fn(s??r,"locked",!0),unlock:s=>Fn(s??r,"locked",!1),toggleLock:s=>Bn(s??r,"locked"),unlockAll:()=>Go("locked"),hide:s=>Fn(s??r,"hidden",!0),show:s=>Fn(s??r,"hidden",!1),toggleHidden:s=>Bn(s??r,"hidden"),showAll:()=>Go("hidden"),isLocked:s=>Qe().locked.has(s),isHidden:s=>Qe().hidden.has(s),setFeatures:sx,getFeatures:()=>D,moveLayers:rx,addFrame:ox,copy:Ir,cut:hu,paste:Li,duplicate:Di,group:Ii,ungroup:Ni,reorder:Ri,scaleSelection:gh,getSpacing:wh,setSpacing:bh,align:fu,distribute:cu,canDistribute:s=>uu(s)!==null,editText:$r,endTextEditing:()=>un("done"),getEditingText:()=>G?.id??null,formatText:s=>G?.format(s),getTextFormat:()=>G?.activeMark()??{},getTextSelectionRects:If,getTextRange:()=>{if(!G)return null;let{anchor:s,head:f}=G.getSelection();return{from:Math.min(s,f),to:Math.max(s,f)}},getEnteredGroup:()=>w,enterGroup:bu,exitGroup:wu,getTool:()=>o,editPoints:pn,stopEditingPoints:Or,getPointEditing:()=>Z?.id??null,convertToVector:s=>$i(s),setTool:Vt,beginEdit:rh,endEdit:oh,undo:Nr,redo:Wo,canUndo:()=>H.canUndo,canRedo:()=>H.canRedo,getHistory:()=>H.snapshot(),setProperty:_u,fontFamilies:()=>{let s=new Map;for(let f of t.fonts?.faces()??[]){let c=s.get(f.family)??{weights:new Set,italic:!1};c.weights.add(f.weight),f.style==="italic"?c.italic=!0:(c.css===void 0||f.weight===400)&&(c.css=f.id),s.set(f.family,c)}return[...s.entries()].sort(([f],[c])=>f.localeCompare(c)).map(([f,c])=>({family:f,weights:[...c.weights].sort((m,h)=>m-h),italic:c.italic,...c.css===void 0?{}:{css:c.css}}))},assetUrl:s=>{let f=n.assets[s];return f?t.resolveAsset?.(f,s):void 0},addMusic:gu,canAddMusic:()=>t.importAudio!==void 0,setToken:dx,removeToken:fx,bindingsOf:nh,unbind:Su,getResolution:()=>I.getResolution(),getCamera:()=>I.getCamera(),getProblems:wi,on:le,reveal:Le,panBy:Qm,setPresence(s,f){d={ids:[...s],label:f??null},Q()},setHighlight(s){s.length===0&&p.length===0||(p=[...s],Q())},isHistoryTail:s=>H.isTail(s),undoTail:lx,historyTop:()=>H.top,destroy(){ae(),e.removeEventListener("pointerup",Ro),e.removeEventListener("pointercancel",Ro),e.removeEventListener("pointerdown",qf),e.removeEventListener("pointermove",Gf),e.removeEventListener("pointerup",jo),e.removeEventListener("pointercancel",jo),e.removeEventListener("pointerleave",su),z.removeEventListener("keydown",Eu),z.removeEventListener("beforeinput",Cu),z.removeEventListener("compositionstart",Mu),z.removeEventListener("compositionupdate",Au),z.removeEventListener("compositionend",$u),z.removeEventListener("blur",Tu),z.remove(),Rn&&clearTimeout(Rn),e.removeEventListener("dblclick",tu),e.removeEventListener("contextmenu",eu),e.removeEventListener("copy",Yf),e.removeEventListener("cut",Jf),e.removeEventListener("paste",Zf),e.removeEventListener("dragover",ou),e.removeEventListener("dragleave",au),e.removeEventListener("drop",iu),e.removeEventListener("keydown",Wf),e.removeEventListener("keyup",Qf),Se?.destroy(),we?.destroy(),fe.destroy(),I.destroy(),te.remove(),X.clear(),e.style.cursor="",e.classList.remove("vd-editor")}}}function H0(e,t){return e===t?!0:be(e)&&be(t)?e.expr===t.expr:!1}function $m(e){return e.metaKey||e.ctrlKey||e.altKey}function xi(e){if(!(e instanceof HTMLElement)||e.classList.contains("vd-editor__input"))return!1;let t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||e.isContentEditable}var HM=new Set(on);function Ef(e){return e.map(t=>({value:t,label:`${t.charAt(0).toUpperCase()}${t.slice(1)}`}))}var z0=[{value:"nonzero",label:"Non-zero"},{value:"evenodd",label:"Even-odd"}].filter(e=>hn.includes(e.value)),j0=Ef(xn),q0=Ef(Kt),K0=Ef(gn),G0=[{value:"left",label:"Left",icon:Ge("text-left")},{value:"center",label:"Centre",icon:Ge("text-center")},{value:"right",label:"Right",icon:Ge("text-right")},{value:"justify",label:"Justify",icon:Ge("text-justify")}].filter(e=>jt.includes(e.value)),W0=[{value:"top",label:"Top",icon:Ge("text-top")},{value:"middle",label:"Middle",icon:Ge("text-middle")},{value:"bottom",label:"Bottom",icon:Ge("text-bottom")}].filter(e=>qt.includes(e.value)),Dm={prop:"x",label:"X",kind:"number",prefix:"X"},Pm={prop:"y",label:"Y",kind:"number",prefix:"Y"},_f={prop:"w",label:"W",kind:"number",prefix:"W"},Sf={prop:"h",label:"H",kind:"number",prefix:"H"},X0={prop:"rotation",label:"Rotation",kind:"number",icon:"rotate",fallback:"0"},Y0={prop:"opacity",label:"Opacity",kind:"number",icon:"opacity",percent:!0,fallback:"100%"},Lm={prop:"radius",label:"Radius",kind:"number",icon:"radius",span:"wide",fallback:"0"},Io={heading:"Position",props:[Dm,Pm,_f,Sf,X0,Y0]},gi={prop:"fill",label:"Fill",kind:"colour"},Im={prop:"stroke",label:"Stroke",kind:"colour",span:"half"},Nm={prop:"strokeWidth",label:"Stroke width",kind:"number",prefix:"Width",fallback:"1"},Rm={present:"stroke",empty:"No stroke",add:{stroke:"#000000",strokeWidth:1},clear:["stroke","strokeWidth","cap","join"]},Om={heading:"Stroke",props:[Im,Nm],optional:Rm},UM={frame:[{heading:"Frame",props:[Dm,Pm,_f,Sf,{prop:"clip",label:"Clip content",kind:"toggle"}]},{heading:"Fill",props:[{prop:"background",label:"Fill",kind:"colour"}]}],canvas:[{heading:"Canvas",props:[_f,Sf,{prop:"background",label:"Fill",kind:"colour"}]}],text:[Io,{heading:"Text",props:[{prop:"font",label:"Font",kind:"font",fallback:"Default"},{prop:"weight",label:"Style",kind:"style",span:"half"},{prop:"size",label:"Size",kind:"number",icon:"font-size",fallback:"16"},{prop:"lineHeight",label:"Line height",kind:"number",icon:"line-height",fallback:"Auto"},{prop:"letterSpacing",label:"Letter spacing",kind:"number",icon:"letter-spacing",fallback:"0"},{prop:"align",label:"Align",kind:"segmented",options:G0,span:"half"},{prop:"valign",label:"Vertical",kind:"segmented",options:W0,span:"half"}]},{heading:"Fill",props:[gi]},{heading:"Link",props:[{prop:"content",label:"Link",kind:"link",icon:"link"}]}],rect:[{heading:"Position",props:[...Io.props,Lm]},{heading:"Fill",props:[gi]},Om],ellipse:[Io,{heading:"Fill",props:[gi]},Om],image:[{heading:"Position",props:[...Io.props,Lm]},{heading:"Image",props:[{prop:"fit",label:"Fit",kind:"select",options:q0,prefix:"Fit"}]}],vector:[Io,{heading:"Fill",props:[{...gi,span:"half"},{prop:"rule",label:"Fill rule",kind:"select",options:z0,prefix:"Rule",span:"half"}]},{heading:"Stroke",props:[Im,Nm,{prop:"cap",label:"Cap",kind:"select",options:j0,prefix:"Cap",span:"half"},{prop:"join",label:"Join",kind:"select",options:K0,prefix:"Join",span:"half"}],optional:Rm}]};var VM=mn.map(e=>({value:e,label:e.split("-").map((t,n)=>n===0?t.charAt(0).toUpperCase()+t.slice(1):t).join(" ")}));function Fm(e){let t=e,n=new Map,r=typeof URL.createObjectURL=="function"&&typeof URL.revokeObjectURL=="function";return{resolve(o){let a=n.get(o.hash);if(a!==void 0)return a;let i=t.get(o.hash);if(i===void 0)return;if(!r)return Es(o.type,i);let l;try{l=Ms(i)}catch{return}let d=URL.createObjectURL(new Blob([l],{type:o.type}));return n.set(o.hash,d),d},replace(o){t=o;for(let[a,i]of n)o.has(a)||(URL.revokeObjectURL(i),n.delete(a))},destroy(){for(let o of n.values())URL.revokeObjectURL(o);n.clear(),t=new Map}}}var Cf="0.3.2",Bm="https://cdn.jsdelivr.net/npm/@getv.design/embed@0.3.2/fonts/";var ib=Symbol.for(`vdesign.embed.documents@${Cf}`),Hm=globalThis[ib]??=new WeakMap,sb=/^Line (\d+): /;function Af(e){let t=sb.exec(e.message);return{...t?{line:Number(t[1])}:{},code:e.code,message:e.message,severity:e.severity}}function Mf(e){if(typeof e!="string")return vi(ro("").document,new Map,[{code:"not-text",message:`parse() takes .vd text, not ${e===null?"null":typeof e}.`,severity:"error"}]);let t=lb(e);if(t.vd===void 0)return vi(ro("").document,new Map,[{code:"not-vd",message:"This SVG carries no vDesign document: only a .vd.svg exported from vDesign does.",severity:"error"}]);let{head:n,blocks:r}=ks(t.vd),o=ro(n),a=o.problems.map(Af).map(i=>i.line===void 0?i:{...i,line:i.line+t.offset});return vi(o.document,r,a)}function lb(e){if(!Ds(e))return{vd:e,offset:0};let t=Os(e);if(t===void 0)return{vd:void 0,offset:0};let n=e.indexOf("<vd:document"),r=e.indexOf("</vd:document",n),o=e.indexOf("<![CDATA[",n);if(o===-1||r!==-1&&o>r){let l=e.indexOf(">",n)+1,d=e.slice(0,l).split(`
|
|
2792
2792
|
`).length-1;return{vd:t,offset:d+(e[l]===`
|
|
2793
2793
|
`?1:0)}}let a=o+9,i=e.slice(0,a).split(`
|
|
2794
2794
|
`).length-1;return{vd:t,offset:i+(e[a]===`
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.3.
|
|
2
|
-
import{a as y}from"./chunks/chunk-
|
|
1
|
+
/*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
|
+
import{a as y}from"./chunks/chunk-LJWWEZ4W.js";import"./chunks/chunk-RMZR36ZE.js";var d=["view","edit","play"];async function l(a,i,e){let o=e?.mode;if(!d.includes(o))throw new TypeError(`mount: mode must be one of ${d.join(", ")}; got ${String(o)}.`);if(o==="edit"){let{edit:t}=await import("./edit.js");return t(a,i,e)}let{view:s}=await import("./view.js"),n=await s(a,i,e);if(o==="view")return n;let r;try{r=await n.play(e.page===void 0?{}:{page:e.page})}catch(t){throw n.destroy(),t}return{goTo:t=>r.goTo(t),destroy(){r.destroy(),n.destroy()}}}export{l as mount,y as version};
|
package/dist/markdown-it.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.3.
|
|
2
|
-
import{a as f,b as p,d as u}from"./chunks/chunk-
|
|
1
|
+
/*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
|
+
import{a as f,b as p,d as u}from"./chunks/chunk-M76WR2LQ.js";import{e as F}from"./chunks/chunk-YWFEB275.js";import"./chunks/chunk-QH553HXY.js";import"./chunks/chunk-4O7TKIQJ.js";import"./chunks/chunk-LJWWEZ4W.js";import"./chunks/chunk-RMZR36ZE.js";function I(l,t={}){let o=l.renderer.rules,s=o.fence,i=new WeakMap;o.fence=(n,c,k,d,g)=>{let e=n[c];if(!e||!p(e.info))return s?s(n,c,k,d,g):"";let r=t.idPrefix;r||(r=i.get(n)??f(),i.set(n,r));let{resolveSrc:a,...w}=t;return u(e.content,e.info,{...w,idPrefix:r,...e.attrs?{attributes:e.attrs}:{},...a?{resolveSrc:m=>a(m,d)}:{}})}}var b=I;export{F as createRenderer,b as default,I as vdesignMarkdownIt};
|
package/dist/markdown.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.3.
|
|
2
|
-
import{a as b,b as c,c as d,d as e}from"./chunks/chunk-
|
|
1
|
+
/*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
|
+
import{a as b,b as c,c as d,d as e}from"./chunks/chunk-M76WR2LQ.js";import{e as a}from"./chunks/chunk-YWFEB275.js";import"./chunks/chunk-QH553HXY.js";import"./chunks/chunk-4O7TKIQJ.js";import"./chunks/chunk-LJWWEZ4W.js";import"./chunks/chunk-RMZR36ZE.js";export{b as createFenceIds,a as createRenderer,c as isVdFence,d as parseInfo,e as renderFence};
|
package/dist/marked.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.3.
|
|
2
|
-
import{a as t,b as i,d as o}from"./chunks/chunk-
|
|
1
|
+
/*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
|
+
import{a as t,b as i,d as o}from"./chunks/chunk-M76WR2LQ.js";import{e as f}from"./chunks/chunk-YWFEB275.js";import"./chunks/chunk-QH553HXY.js";import"./chunks/chunk-4O7TKIQJ.js";import"./chunks/chunk-LJWWEZ4W.js";import"./chunks/chunk-RMZR36ZE.js";function p(r={}){let s=r.idPrefix??t();return{renderer:{code(e,d){let c=typeof e=="string"?e:e.text,n=typeof e=="string"?d:e.lang;return i(n)?o(c,n??"vd",{...r,idPrefix:s}):!1}}}}var a=p;export{f as createRenderer,a as default,p as vdesignMarked};
|
package/dist/rehype.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.3.
|
|
2
|
-
import{a as h,d as m}from"./chunks/chunk-
|
|
1
|
+
/*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
|
+
import{a as h,d as m}from"./chunks/chunk-M76WR2LQ.js";import{e as g}from"./chunks/chunk-YWFEB275.js";import"./chunks/chunk-QH553HXY.js";import"./chunks/chunk-4O7TKIQJ.js";import"./chunks/chunk-LJWWEZ4W.js";import"./chunks/chunk-RMZR36ZE.js";function x(e={}){let n,i=()=>e.renderer?Promise.resolve(e.renderer):n??=g({fonts:e.fonts??"exact",...e.fontBase===void 0?{}:{fontBase:e.fontBase}});return async(t,r)=>{let s=r?.path??r?.history?.at(-1);if(e.include&&!e.include(s))return;let o=[];if(v(t,(d,l,a)=>{if(d.type!=="element"||d.tagName!=="pre"||!l)return;let c=d.children?.find(p=>p.type==="element");c?.tagName!=="code"||!F(c)||o.push({parent:l,index:a,code:c})}),o.length===0)return;let u=await i(),f={...e};for(let d of["resolveSrc","fonts","fontBase","include"])delete f[d];let N=e.idPrefix??h(),R=e.resolveSrc??k;for(let{parent:d,index:l,code:a}of o){let c=typeof a.data?.meta=="string"?a.data.meta:"",p=m(y(a),`vd ${c}`,{...f,renderer:u,idPrefix:N,resolveSrc:H=>R(H,s)});d.children[l]={type:"raw",value:p}}}}var B=x;function F(e){let n=e.properties?.className;return(Array.isArray(n)?n:typeof n=="string"?n.split(/\s+/):[]).some(t=>t==="language-vd"||t==="language-vdesign")}function y(e){return e.type==="text"?e.value??"":(e.children??[]).map(y).join("")}function v(e,n,i,t=0){n(e,i,t),e.children?.forEach((r,s)=>v(r,n,e,s))}function k(e,n){let i=globalThis,t=i.process?.getBuiltinModule?.("node:fs"),r=i.process?.getBuiltinModule?.("node:path"),s=i.process?.cwd?.();if(!t||!r||s===void 0||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.includes("\\")||!/\.vd(\.svg)?$/i.test(e))return;let o=n===void 0?s:r.dirname(r.resolve(s,n));try{let u=t.realpathSync(r.resolve(o,e)),f=t.realpathSync(s);return u.startsWith(f+r.sep)?t.readFileSync(u,"utf8"):void 0}catch{return}}export{B as default,x as rehypeVdesign};
|
package/dist/static.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.3.
|
|
2
|
-
import{a as b,b as c,c as d,d as e,e as f,f as g}from"./chunks/chunk-
|
|
1
|
+
/*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
|
+
import{a as b,b as c,c as d,d as e,e as f,f as g}from"./chunks/chunk-YWFEB275.js";import"./chunks/chunk-QH553HXY.js";import"./chunks/chunk-4O7TKIQJ.js";import{a}from"./chunks/chunk-LJWWEZ4W.js";import"./chunks/chunk-RMZR36ZE.js";export{g as approximateRenderer,f as createRenderer,d as designOf,e as outline,b as parse,c as renderSvg,a as version};
|
package/dist/view.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.3.
|
|
2
|
-
import{c as Ct,e as Ye,f as de,g as Ae,h as It,i as Ne}from"./chunks/chunk-
|
|
1
|
+
/*! @getv.design/embed v0.3.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
|
+
import{c as Ct,e as Ye,f as de,g as Ae,h as It,i as Ne}from"./chunks/chunk-QH553HXY.js";import{A as At,B as Ke,E as Mt,F as Tt,G as Ot,H as _t,I as We,J as Lt,K as Pt,a as ft,b as ut,c as De,d as pt,e as Be,f as He,g as ht,h as je,i as mt,j as gt,k as yt,l as wt,n as xt,p as vt,t as Ue,u as bt,v as Et,w as St,x as kt,y as Ge,z as Fe}from"./chunks/chunk-4O7TKIQJ.js";import{a as yn,b as lt}from"./chunks/chunk-LJWWEZ4W.js";import"./chunks/chunk-RMZR36ZE.js";var wn=.8,xn=.2;function qe(e,t){let r=e.createElement("canvas").getContext("2d"),n=At(),p=new Map,a=new Map,y=new Set;function u(l){return`${l.italic?"italic ":""}${l.weight} ${l.size}px ${l.family}`}function g(){p.clear(),a.clear()}return{advance(l,w){if(!r)return n.advance(l,w);let b=u(w),A=`${b}\0${w.letterSpacing}\0${l}`,L=p.get(A);if(L!==void 0)return L;r.font=b;let x=r.measureText(l).width+w.letterSpacing*[...l].length;return p.set(A,x),x},metrics(l){if(!r)return n.metrics(l);let w=u(l),b=a.get(w);if(b)return b;r.font=w;let A=r.measureText("Hxg"),L=A.fontBoundingBoxAscent??l.size*wn,x=A.fontBoundingBoxDescent??l.size*xn,V={ascent:L,descent:x,lineGap:0};return a.set(w,V),V},load(l,w){let b=e.fonts;if(!b||typeof FontFace!="function")return!1;let A=!1;for(let L of Object.values(l.fonts))for(let x of vn(L)){let V=`${L.family}\0${x.src}\0${x.weight??400}\0${x.style??"normal"}`;if(y.has(V))continue;y.add(V);let _=x.src.startsWith("data:")?void 0:w?.(x.src),M={weight:String(x.weight??400),style:x.style??"normal"},H=Q=>{let R=new FontFace(L.family,typeof Q=="string"?`url(${Q})`:bn(Q),M);b.add(R),R.load().then(()=>{g(),t?.()},()=>{b.delete(R)})};_===void 0?H(x.src):(A=!0,_.then(H,()=>{}))}return A},invalidate:g,destroy(){g(),y.clear()}}}function vn(e){return e.faces??[]}function bn(e){return e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}var ze={x:0,y:0,zoom:1},Dt=.02,Ft=64;function Me(e){return Number.isFinite(e)?Math.min(Math.max(e,Dt),Ft):1}function $e(e,t){return{x:(t.x-e.x)/e.zoom,y:(t.y-e.y)/e.zoom}}function Ze(e,t){return{x:t.x*e.zoom+e.x,y:t.y*e.zoom+e.y}}function Te(e,t,o){let r=Me(e.zoom*o),n=$e(e,t);return{zoom:r,x:t.x-n.x*r,y:t.y-n.y*r}}function ye(e,t,o){return{...e,x:e.x+t,y:e.y+o}}function Xe(e){return`translate(${e.x} ${e.y}) scale(${e.zoom})`}function le(e,t,o){let r={width:Math.max(1,t.width-o*2),height:Math.max(1,t.height-o*2)};if(e.width<=0||e.height<=0)return ze;let n=Me(Math.min(r.width/e.width,r.height/e.height));return{zoom:n,x:(t.width-e.width*n)/2-(e.x??0)*n,y:(t.height-e.height*n)/2-(e.y??0)*n}}var ne="http://www.w3.org/2000/svg",Nt="vd-viewer-styles",zt=`
|
|
3
3
|
.vd-viewer {
|
|
4
4
|
position: relative;
|
|
5
5
|
overflow: hidden;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getv.design/embed",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Render, present and edit vDesign (.vd) documents in any web page. Free to use.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": {
|
|
7
|
-
"name": "
|
|
7
|
+
"name": "vDesign",
|
|
8
8
|
"email": "sagar@getv.design"
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://getv.design/docs/embed/",
|