@getv.design/embed 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.txt +41 -2
- package/dist/auto.js +2 -2
- package/dist/chunks/{chunk-ODPS4XJH.js → chunk-7P37TP37.js} +2 -2
- package/dist/chunks/{chunk-OQJPNBNN.js → chunk-FXERLAK5.js} +2 -2
- package/dist/chunks/chunk-P42KFNKD.js +10 -0
- package/dist/chunks/{chunk-NAQCHPKZ.js → chunk-RSOCS6S4.js} +2 -2
- package/dist/chunks/{chunk-OM66E7BL.js → chunk-UN7F6SH4.js} +1 -1
- package/dist/chunks/chunk-VTEBIFPH.js +2 -0
- package/dist/chunks/fonts.js +2 -2
- package/dist/cli.js +19 -19
- package/dist/edit.js +257 -35
- 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 +3 -3
- package/edit.css +209 -1
- package/package.json +1 -1
- package/dist/chunks/chunk-FMTYD7LD.js +0 -10
- package/dist/chunks/chunk-OE3F27L6.js +0 -2
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*! @getv.design/embed v0.5.2. Free to use under the vDesign Embed Licence. © 2026 vDesign. https://getv.design/docs/licence/ */
|
|
2
|
-
var Fe=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],we=["left","center","right","justify"],$e=["top","middle","bottom"],ve=["cover","contain","fill"],Be=["nonzero","evenodd"],Ue=["butt","round","square"],We=["miter","round","bevel"],Wt=["canvas","frame","group","instance"];function ze(e){return Wt.includes(e)}function P(e){return ze(e.type)}function ke(e){return e.type==="group"}function V(e){return P(e)?e.children:[]}var zt={canvas:["w","h"],ellipse:["x","y","w","h","rotation","strokeWidth","opacity"],frame:["x","y","w","h"],group:[],instance:["x","y","w","h"],image:["x","y","w","h","rotation","radius","opacity"],rect:["x","y","w","h","rotation","strokeWidth","radius","opacity"],text:["x","y","w","h","rotation","size","weight","lineHeight","letterSpacing","opacity"],vector:["x","y","w","h","rotation","strokeWidth","opacity"]};function Xe(e){return zt[e.type]}function R(e,n,t){if(n(e,t)!==!1&&P(e))for(let r of e.children)R(r,n,e)}function W(e,n){let t;return R(e,r=>{if(t)return!1;r.id===n&&(t=r)}),t}function Y(e){let n=e.trim();if(n.startsWith("#")){let r=n.slice(1);return r===""?void 0:{kind:"frame",id:r}}let t;try{t=new URL(n)}catch{return}if(!(t.protocol!=="https:"&&t.protocol!=="mailto:"))return{kind:"url",url:n}}var ue="--- payload base64 ---",Qr="sha256-";function Xt(e){let n=oo(e);return n===-1?{head:e,payload:""}:{head:e.slice(0,n),payload:e.slice(n+ue.length)}}function eo(e){let{head:n,payload:t}=Xt(e);return{head:n,blocks:Jt(t)}}function Jt(e){let n=new Map;for(let t of e.split(`
|
|
3
|
-
`)){let r=t.indexOf(" ");if(r===-1)continue;let o=t.slice(0,r);o.startsWith(Qr)&&n.set(o,t.slice(r+1).trim())}return n}function no(e,n){return`data:${e};base64,${n}`}function to(e){let n=e.toBase64;if(typeof n=="function")return n.call(e);let t="";for(let r=0;r<e.length;r+=32768)t+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(t)}function ro(e){let n=Uint8Array.fromBase64;if(typeof n=="function")return n(e);let t=atob(e),r=new Uint8Array(t.length);for(let o=0;o<t.length;o+=1)r[o]=t.charCodeAt(o);return r}function oo(e){if(e.startsWith(ue))return 0;let n=e.indexOf(`
|
|
4
|
-
${ue}`);return n===-1?-1:n+1}function q(e){return{expr:e}}function B(e){return typeof e=="object"&&e!==null&&typeof e.expr=="string"}var Fn=["light","dark"],Bn=["must","should"],Je=["no-gradient","contrast","font-only","logo-min"];var Gt=["role","logo","rule","guide","review"];function Ge(e){return Gt.includes(e)}function He(e="",n=1){return{slug:e,version:n,changes:[],sources:[],roles:{},logos:{},rules:{},guides:{},review:[]}}function Un(e){let n=/^([a-z0-9][a-z0-9-]*)(?:@(\d+))?$/.exec(e);if(!n)return;let t=n[2]===void 0?1:Number(n[2]);if(!(!Number.isSafeInteger(t)||t<1))return{slug:n[1],version:t}}var io=8,so=new Set(["type","id","children","component","overrides"]);function ae(e){return!so.has(e)}function Ye(e,n){return`${e}.${n}`}function ce(e){let n=new Map,t=r=>{if(r.type!=="instance"){r.type==="frame"&&r.component===!0&&n.set(r.id,r);for(let o of V(r))t(o)}};return t(e),n}function Ke(e,n){let t=[],r=o=>{if(o.type==="instance"){(n===void 0||o.component===n)&&t.push(o);return}for(let i of V(o))r(i)};return r(e),t}function Z(e){let n=e;for(let t=0;t<io;t+=1){let r=ce(n),o=Ht(n,r);if(o===n)return n;n=o}return n}var Wn=new WeakMap;function Ht(e,n){if(e.type==="instance"){let o=n.get(e.component)??null;if(Wn.has(e)&&Wn.get(e)===o)return e;let i=Kt(e,n,new Set),s=Jn(i,e.children)?e:{...e,children:i};return Wn.set(s,o),s}if(!P(e))return e;let t=!1,r=e.children.map(o=>{let i=Ht(o,n);return i!==o&&(t=!0),i});return t?{...e,children:r}:e}function Kt(e,n,t){let r=n.get(e.component);if(!r||t.has(r.id))return[];let o=new Set(t).add(r.id),i=r.children.map(s=>zn(s,e.id,n,o));return uo(i,e.id,e.overrides)}function zn(e,n,t,r){let o=Ye(n,e.id);if(e.type==="instance"){let i={...e,id:o};return{...i,children:Kt(i,t,r)}}if(e.type==="frame"){let i={...e};return delete i.component,{...i,id:o,children:e.children.map(s=>zn(s,n,t,r))}}return P(e)?{...e,id:o,children:e.children.map(i=>zn(i,n,t,r))}:{...e,id:o}}function uo(e,n,t){if(t===void 0)return[...e];let r=new Map;for(let[i,s]of Object.entries(t))r.set(Ye(n,i),s);let o=i=>{let s=r.get(i.id),u=i;if(s){let a={...i};for(let[c,d]of Object.entries(s))ae(c)&&(a[c]=d);u=a}return P(u)?{...u,children:u.children.map(o)}:u};return e.map(o)}function Gn(e){let n=[],t=ce(e);for(let i of Ke(e)){let s=t.get(i.component);if(!s){n.push({severity:"error",code:"missing-component",message:`${i.id} places ${i.component}, which is not a component \u2014 mark a frame with component, or point component= at one`,nodeId:i.id});continue}if(Xn(s,s.id,t,new Set)){n.push({severity:"error",code:"component-cycle",message:`${s.id} holds an instance of itself, so ${i.id} cannot be drawn`,nodeId:i.id});continue}for(let u of Object.keys(i.overrides??{}))W(i,Ye(i.id,u))||n.push({severity:"warning",code:"orphaned-override",message:`${i.id} overrides ${u}, which ${s.id} no longer has`,nodeId:i.id})}for(let[i]of t)e.type==="canvas"&&e.children.some(s=>s.id===i)||n.push({severity:"warning",code:"component-not-top-level",message:`${i} is a component inside another frame \u2014 keep components in the row below the pages, at the top level`,nodeId:i});let r=new Map,o=i=>{r.set(i.id,(r.get(i.id)??0)+1);for(let s of V(i))o(s)};o(e);for(let i of Ke(e))for(let s of i.children){let u=a=>{(r.get(a.id)??0)>1&&n.push({severity:"error",code:"duplicate-id",message:`${a.id} is both a node and a part of ${i.id} \u2014 rename one`,nodeId:a.id});for(let c of V(a))u(c)};u(s)}return n}function Xn(e,n,t,r){return V(e).some(o=>{if(o.type==="instance"){if(o.component===n)return!0;if(r.has(o.component))return!1;r.add(o.component);let i=t.get(o.component);return i!==void 0&&Xn(i,n,t,r)}return Xn(o,n,t,r)})}function qe(e){return ce(e).size>0||Ke(e).length>0}function Jn(e,n){if(e===n)return!0;if(typeof e!="object"||typeof n!="object"||e===null||n===null)return!1;if(Array.isArray(e)||Array.isArray(n))return Array.isArray(e)&&Array.isArray(n)&&e.length===n.length&&e.every((i,s)=>Jn(i,n[s]));let t=e,r=n,o=new Set([...Object.keys(t),...Object.keys(r)]);for(let i of o)if(!Jn(t[i],r[i]))return!1;return!0}var Ee=["design","brand"],de="design",Yt=new WeakMap;function F(e){let n=e.brand?.theme==="dark"?e.themes?.dark:void 0;if(n===void 0)return e.tokens;let t=Yt.get(e);if(t!==void 0)return t;let r={...e.tokens,...n};return Yt.set(e,r),r}var qt=4,Zt=5,Hn=6,Ze=[1,2,3,4,5,6],Qe=Hn;function H(e){return e.root!==void 0&&qe(e.root)?Hn:e.kind==="brand"||e.brand!==void 0||e.themes!==void 0||ao(e.fonts)?Zt:qt}function ao(e){return Object.values(e??{}).some(n=>(n.faces??[]).some(t=>t.asset!==void 0))}var Q="doc";function Se(e){return{type:"canvas",...e}}function en(e={}){let n=e.kind??de,t=fe(e.themes),r=Z(e.root??Se({id:Q,children:[]}));return{version:H({kind:n,root:r,...e.fonts===void 0?{}:{fonts:e.fonts},...e.brand===void 0?{}:{brand:e.brand},...t===void 0?{}:{themes:t}}),kind:n,...e.title===void 0?{}:{title:e.title},tokens:e.tokens??{},fonts:e.fonts??{},assets:e.assets??{},...e.motion===void 0||Object.keys(e.motion).length===0?{}:{motion:e.motion},...e.brand===void 0?{}:{brand:e.brand},...t===void 0?{}:{themes:t},root:r}}function fe(e){let n=e?.dark;return n===void 0||Object.keys(n).length===0?void 0:{dark:n}}var nn=["beat","bar"];var co=/^(\d+(?:\.\d+)?)(beats?|bars?)$/;function le(e){let n=co.exec(e);if(!n)return;let t=Number(n[1]);if(Number.isFinite(t))return{count:t,unit:n[2].startsWith("bar")?"bar":"beat"}}function pe(e,n){return`${String(Math.round(e*1e6)/1e6)}${n}${e===1?"":"s"}`}function he(e){return typeof e=="string"&&le(e)!==void 0}function ee(e){let n=e?.bpm;if(n===void 0)return;let t=e?.meter??4,r=6e4/n;return{bpm:n,meter:t,beat:r,bar:r*t}}function Oe(e,n,t){if(e===void 0)return t;if(typeof e=="number")return e;let r=le(e);return!r||!n?t:r.count*(r.unit==="bar"?n.bar:n.beat)}var Me=36e5;var tn=["cut","fade","push","slide"],rn=["cut","fade","rise","drop","pop","wipe","grow","count","draw"],me=["cut","fade","rise","drop","pop"],on=["pulse"],sn=["out","in","inout","linear","spring"],un=["word","letter"],ne=["left","right","top","bottom"],Qt=400,Te=1e4,an=18e4,te=7680;function ge(e){let n=e.trim();return n==="back"?{kind:"back"}:n==="next"?{kind:"next"}:Y(n)}function Ae(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 cn(e){return e.camera===!0||e.enter!==void 0||e.exit!==void 0||e.emphasis!==void 0||e.go!==void 0}var lo=["camera","emphasis","from","by","stagger","hold","at","after","with","on","ease","pad"];function er(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(n=>lo.some(t=>n[t]!==void 0)||n.enter!==void 0&&!me.includes(n.enter)||n.exit!==void 0&&!me.includes(n.exit))}function dn(e){let n=e.motion;if(!n)return[];let t=e.root.children.map(o=>o.id).filter(o=>o in n),r=Object.keys(n).filter(o=>!t.includes(o)).sort();return[...t,...r]}function fn(e){return new Set(e.root.children.filter(n=>n.type==="frame"&&n.component!==!0).map(n=>n.id))}function ln(e){let n=new Map;for(let t of e.root.children)t.type!=="frame"||t.component===!0||R(t,r=>{n.set(r.id,t.id)});return n}function po(e){let n=new Set;return R(e,t=>{n.add(t.id)}),n}function Ne(e,n){let t=e.motion;if(!t)return[];let r=[],o=fn(e),i=ln(e),s=po(e.root),u=(a,c)=>{let d=n?.(a,c);return d===void 0?"":`Line ${d}: `};for(let a of dn(e)){let c=t[a];if(!c)continue;if(!o.has(a)){r.push({severity:"warning",code:"motion-not-a-page",message:`${u(a)}motion ${a}: ${a} is not a page (a top-level frame), so none of it plays`,nodeId:a});continue}let d=new Set;for(let f of c.lines){let p=u(a,f.id);for(let k of["after","with"]){let l=f[k];l!==void 0&&!d.has(l)&&r.push({severity:"warning",code:"motion-anchor-missing",message:`${p}motion ${a}: ${k}=${l} names no line above, so it starts after the line above instead`,nodeId:f.id})}f.camera!==!0&&d.add(f.id);let m=s.has(f.id)?W(e.root,f.id):void 0;m&&r.push(...ho(f,m,p,a)),s.has(f.id)?i.get(f.id)!==a&&r.push({severity:"warning",code:"motion-wrong-page",message:`${p}motion ${a}: ${f.id} is not on ${a}, so Play skips it`,nodeId:f.id}):r.push({severity:"warning",code:"unknown-reference",message:`${p}motion ${a}: no node ${f.id}`,nodeId:f.id});let x=f.go===void 0?void 0:ge(f.go);x?.kind==="frame"&&!yo(e,x.id)&&r.push({severity:"warning",code:"unknown-reference",message:`${p}motion ${a}: go=#${x.id} names no frame`,nodeId:f.id})}}return r}function ho(e,n,t,r){let o=[],i=(u,a)=>{o.push({severity:"warning",code:u,message:`${t}motion ${r}: ${a}`,nodeId:n.id})};if(e.camera===!0)return o;let s=e.enter??e.exit;return s==="count"&&(n.type!=="text"||!/\d/.test(pn(n.content)))&&i("count-no-number",`${n.id} has no number to count, so it fades in instead`),s==="draw"&&!go(n)&&i("draw-no-stroke",`${n.id} has no stroked vector to draw, so it fades in instead`),e.by!==void 0&&n.type!=="text"?i("by-not-text",`by=${e.by} splits text, and ${n.id} is a ${n.type}`):e.by!==void 0&&n.type==="text"&&mo(n)&&i("by-rotated",`${n.id} is rotated, so by=${e.by} enters it whole`),e.stagger!==void 0&&e.by===void 0&&V(n).length===0&&i("stagger-no-children",`${n.id} has no children to stagger: split a text with by=word`),o}function mo(e){let n=e.rotation;return n!==void 0&&n!==0}function go(e){let n=!1;return R(e,t=>(t.type==="vector"&&t.stroke!==void 0&&(n=!0),n?!1:void 0)),n}function pn(e){return typeof e=="string"?e:e.map(n=>typeof n=="string"?n:n.text).join("")}function yo(e,n){let t=!1;return R(e.root,r=>{if(t)return!1;r.id===n&&(t=r.type==="frame")}),t}function y(e){if(!Number.isFinite(e))return"0";let n=Math.round(e*1e4)/1e4,t=Object.is(n,-0)?0:n;return Math.abs(t)>=1e21?t.toFixed(0):String(t)}var xo={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function Kn(e){let n=[],t,r=0,o=0,i=0,s=0,u,a,c=wo(e),d=()=>(t||(t={anchors:[{x:r,y:o}],closed:!1},n.push(t)),t.anchors[t.anchors.length-1]),f=(k,l)=>{d(),t?.anchors.push({x:k,y:l}),r=k,o=l},p=(k,l,O,M)=>{d().out=k,t?.anchors.push({x:O,y:M,in:l}),r=O,o=M},m="",x=!0;for(;c.more();){let k=c.command();if(k!==void 0)m=k,x=!0;else if(m===""||m.toUpperCase()==="Z")return{contours:hn(n),error:`Expected a command at ${c.at()}`};let l=m.toUpperCase(),O=m!==l,M=xo[l];if(M===void 0)return{contours:hn(n),error:`Unknown command ${m}`};if(l==="Z"){t&&(t.closed=!0),t=void 0,r=i,o=s,u=void 0,a=void 0,m="";continue}let T=l==="A"?c.arc():c.numbers(M);if(T===void 0)return{contours:hn(n),error:`${m} expects ${M} numbers at ${c.at()}`};let A=O?r:0,N=O?o:0,$=E=>T[E];switch(l){case"M":x&&(t={anchors:[{x:A+$(0),y:N+$(1)}],closed:!1},n.push(t),r=i=A+$(0),o=s=N+$(1),m=O?"l":"L"),u=a=void 0;break;case"L":f(A+$(0),N+$(1)),u=a=void 0;break;case"H":f(A+$(0),o),u=a=void 0;break;case"V":f(r,N+$(0)),u=a=void 0;break;case"C":{let E={x:A+$(2),y:N+$(3)};p({x:A+$(0),y:N+$(1)},E,A+$(4),N+$(5)),u=E,a=void 0;break}case"S":{let E=u?{x:2*r-u.x,y:2*o-u.y}:{x:r,y:o},h={x:A+$(0),y:N+$(1)};p(E,h,A+$(2),N+$(3)),u=h,a=void 0;break}case"Q":case"T":{let E=l==="Q"?{x:A+$(0),y:N+$(1)}:a?{x:2*r-a.x,y:2*o-a.y}:{x:r,y:o},h=l==="Q"?A+$(2):A+$(0),w=l==="Q"?N+$(3):N+$(1),b={x:r+2/3*(E.x-r),y:o+2/3*(E.y-o)},S={x:h+2/3*(E.x-h),y:w+2/3*(E.y-w)};p(b,S,h,w),a=E,u=void 0;break}case"A":{let E=A+$(5),h=N+$(6);for(let[w,b,S]of $o(r,o,$(0),$(1),$(2),$(3)!==0,$(4)!==0,E,h))p(w,b,S.x,S.y);(r!==E||o!==h)&&f(E,h),u=a=void 0;break}}x=!1}return{contours:hn(n)}}function hn(e){return e.map(n=>{let t=[...n.anchors];if(n.closed&&t.length>1){let r=t[0],o=t[t.length-1];Ie(r,o)&&(t.pop(),t[0]={...r,...o.in?{in:o.in}:{}})}return{anchors:t.map(bo),closed:n.closed}})}function bo(e){let n={x:e.x,y:e.y};return e.in&&!Ie(e.in,e)&&(n.in=e.in),e.out&&!Ie(e.out,e)&&(n.out=e.out),n}function Ie(e,n,t=1e-6){return Math.abs(e.x-n.x)<t&&Math.abs(e.y-n.y)<t}function wo(e){let n=0,t=()=>{for(;n<e.length&&/[\s,]/.test(e[n]);)n+=1},r=()=>{t();let i=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(n));if(i)return n+=i[0].length,Number(i[0])},o=()=>{t();let i=e[n];if(!(i!=="0"&&i!=="1"))return n+=1,Number(i)};return{more(){return t(),n<e.length},command(){t();let i=e[n];if(/[a-zA-Z]/.test(i))return n+=1,i},numbers(i){let s=[];for(let u=0;u<i;u+=1){let a=r();if(a===void 0)return;s.push(a)}return s},arc(){let i=this.numbers(3),s=o(),u=o(),a=this.numbers(2);if(!(!i||s===void 0||u===void 0||!a))return[...i,s,u,...a]},at(){return n}}}function $o(e,n,t,r,o,i,s,u,a){let c=Math.abs(t),d=Math.abs(r);if(c===0||d===0||e===u&&n===a)return[];let f=o*Math.PI/180,p=Math.cos(f),m=Math.sin(f),x=(e-u)/2,k=(n-a)/2,l=p*x+m*k,O=-m*x+p*k,M=l*l/(c*c)+O*O/(d*d);M>1&&(c*=Math.sqrt(M),d*=Math.sqrt(M));let T=c*c*d*d-c*c*O*O-d*d*l*l,A=c*c*O*O+d*d*l*l,N=(i===s?-1:1)*Math.sqrt(Math.max(0,T/A)),$=N*c*O/d,E=-N*d*l/c,h=p*$-m*E+(e+u)/2,w=m*$+p*E+(n+a)/2,b=(_,K,ie,se)=>{let xe=_*ie+K*se,Ve=Math.hypot(_,K)*Math.hypot(ie,se),be=Math.acos(Math.min(1,Math.max(-1,xe/Ve)));return _*se-K*ie<0?-be:be},S=b(1,0,(l-$)/c,(O-E)/d),g=b((l-$)/c,(O-E)/d,(-l-$)/c,(-O-E)/d);!s&&g>0&&(g-=2*Math.PI),s&&g<0&&(g+=2*Math.PI);let v=Math.max(1,Math.ceil(Math.abs(g)/(Math.PI/2)-1e-9)),C=g/v,U=4/3*Math.tan(C/4),Ce=_=>({x:h+c*Math.cos(_)*p-d*Math.sin(_)*m,y:w+c*Math.cos(_)*m+d*Math.sin(_)*p}),Bt=_=>({x:-c*Math.sin(_)*p-d*Math.cos(_)*m,y:-c*Math.sin(_)*m+d*Math.cos(_)*p}),Ut=[];for(let _=0;_<v;_+=1){let K=S+_*C,ie=K+C,se=Ce(K),xe=_===v-1?{x:u,y:a}:Ce(ie),Ve=Bt(K),be=Bt(ie);Ut.push([{x:se.x+U*Ve.x,y:se.y+U*Ve.y},{x:xe.x-U*be.x,y:xe.y-U*be.y},xe])}return Ut}function Yn(e){let n=[],t=r=>`${y(r.x)} ${y(r.y)}`;for(let r of e){let{anchors:o}=r,i=o[0];if(!i)continue;n.push(`M${t(i)}`);let s=_e(r);for(let u=0;u<s;u+=1){let a=o[u],c=o[(u+1)%o.length],d=r.closed&&u===o.length-1;!a.out&&!c.in?d||n.push(`L${t(c)}`):n.push(`C${t(a.out??a)} ${t(c.in??c)} ${t(c)}`)}r.closed&&n.push("Z")}return n.join(" ")}function _e(e){let n=e.anchors.length;return n<2?0:e.closed?n:n-1}function mn(e,n){let t=e.anchors[n],r=e.anchors[(n+1)%e.anchors.length];return[{x:t.x,y:t.y},t.out??{x:t.x,y:t.y},r.in??{x:r.x,y:r.y},{x:r.x,y:r.y}]}function qn(e,n){let[t,r,o,i]=e,s=1-n,u=s*s*s,a=3*s*s*n,c=3*s*n*n,d=n*n*n;return{x:u*t.x+a*r.x+c*o.x+d*i.x,y:u*t.y+a*r.y+c*o.y+d*i.y}}function Zn(e,n){return e.map(t=>({closed:t.closed,anchors:t.anchors.map(r=>{let o=n(r);return{x:o.x,y:o.y,...r.in?{in:n(r.in)}:{},...r.out?{out:n(r.out)}:{}}})}))}function Qn(e){let n=1/0,t=1/0,r=-1/0,o=-1/0,i=s=>{n=Math.min(n,s.x),t=Math.min(t,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y)};for(let s of e){for(let a of s.anchors)i(a);let u=_e(s);for(let a=0;a<u;a+=1){let c=mn(s,a);for(let d of vo(c))i(qn(c,d))}}if(n!==1/0)return{x:n,y:t,w:r-n,h:o-t}}function vo(e){let[n,t,r,o]=e,i=[];for(let s of["x","y"]){let u=-n[s]+3*t[s]-3*r[s]+o[s],a=2*(n[s]-2*t[s]+r[s]),c=t[s]-n[s];if(Math.abs(u)<1e-12){Math.abs(a)>1e-12&&i.push(-c/a);continue}let d=a*a-4*u*c;if(d<0)continue;let f=Math.sqrt(d);i.push((-a+f)/(2*u),(-a-f)/(2*u))}return i.filter(s=>s>0&&s<1)}function gn(e){if(e===void 0)return;let n=e.trim().split(/[\s,]+/).map(Number);if(n.length!==4||n.some(s=>!Number.isFinite(s)))return;let[t,r,o,i]=n;return{x:t,y:r,w:o,h:i}}function et(e,n,t){return gn(e)??{x:0,y:0,w:n,h:t}}function nt(e,n){let t=e.w===0?1:n.w/e.w,r=e.h===0?1:n.h/e.h;return o=>({x:n.x+(o.x-e.x)*t,y:n.y+(o.y-e.y)*r})}function tt(e,n=.5){let[t,r,o,i]=e;if(Ie(t,r)&&Ie(o,i))return[t,i];let u=Math.hypot(r.x-t.x,r.y-t.y)+Math.hypot(o.x-r.x,o.y-r.y)+Math.hypot(i.x-o.x,i.y-o.y),a=Math.min(256,Math.max(4,Math.ceil(Math.sqrt(u/n)))),c=[];for(let d=0;d<=a;d+=1)c.push(qn(e,d/a));return c}function yn(e){let n=0;for(let t of e)for(let r=0;r<_e(t);r+=1){let o=tt(mn(t,r),.25);for(let i=1;i<o.length;i+=1){let s=o[i-1],u=o[i];n+=Math.hypot(u.x-s.x,u.y-s.y)}}return n}function ko(e,n,t){let r=0,o=0;for(let i of e){let s=Eo(i);if(s.length!==0){if(t.reach>0){let u=i.closed?s.length:s.length-1;for(let a=0;a<u;a+=1){let c=s[a],d=s[(a+1)%s.length];if(So(n,c,d)<=t.reach)return!0}if(s.length===1&&Math.hypot(n.x-s[0].x,n.y-s[0].y)<=t.reach)return!0}if(t.fill)for(let u=0;u<s.length;u+=1){let a=s[u],c=s[(u+1)%s.length];a.y<=n.y!=c.y<=n.y&&a.x+(n.y-a.y)/(c.y-a.y)*(c.x-a.x)>n.x&&(o+=1,r+=c.y>a.y?1:-1)}}}return t.fill?t.rule==="evenodd"?o%2===1:r!==0:!1}function Eo(e){let n=e.anchors[0];if(!n)return[];let t=[{x:n.x,y:n.y}],r=_e(e);for(let o=0;o<r;o+=1)t.push(...tt(mn(e,o)).slice(1));return e.closed&&t.length>1&&t.pop(),t}function So(e,n,t){let r=t.x-n.x,o=t.y-n.y,i=r*r+o*o,s=i===0?0:Math.max(0,Math.min(1,((e.x-n.x)*r+(e.y-n.y)*o)/i));return Math.hypot(e.x-(n.x+s*r),e.y-(n.y+s*o))}var xn={canvas:[["name","string"],["w","numberValue"],["h","numberValue"],["background","stringValue"]],frame:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["background","stringValue"],["clip","boolean"],["skip","boolean"],["component","boolean"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],group:[["name","string"],["hidden","boolean"],["locked","boolean"]],instance:[["name","string"],["component","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["hidden","boolean"],["locked","boolean"]],ellipse:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],vector:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["view","string"],["d","string"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["opacity","numberValue"],["rule","fillRule"],["cap","lineCap"],["join","lineJoin"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],rect:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["fill","stringValue"],["stroke","stringValue"],["strokeWidth","numberValue"],["radius","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],image:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["src","stringValue"],["fit","imageFit"],["radius","numberValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]],text:[["name","string"],["x","numberValue"],["y","numberValue"],["w","numberValue"],["h","numberValue"],["rotation","numberValue"],["font","stringValue"],["size","numberValue"],["weight","numberValue"],["lineHeight","numberValue"],["letterSpacing","numberValue"],["align","align"],["valign","valign"],["italic","boolean"],["fill","stringValue"],["opacity","numberValue"],["blend","blendMode"],["shadow","stringValue"],["hidden","boolean"],["locked","boolean"]]},bn=[["font","string"],["size","number"],["weight","number"],["italic","boolean"],["underline","boolean"],["strike","boolean"],["fill","string"],["letterSpacing","number"],["link","string"]];var wn=[["enter","pageEffect"],["duration","number"],["scroll","boolean"],["length","time"],["w","number"],["h","number"],["bpm","number"],["meter","number"]],Pe=[["enter","nodeEffect"],["exit","nodeEffect"],["emphasis","emphasisEffect"],["from","from"],["by","piece"],["stagger","time"],["duration","time"],["hold","time"],["delay","time"],["at","time"],["after","string"],["with","string"],["step","boolean"],["together","boolean"],["on","on"],["ease","ease"],["pad","number"],["go","string"]],$n=[["from","number"],["volume","number"],["fadein","time"],["fadeout","time"],["loop","boolean"]],rt=Object.keys(xn);function vn(e){return rt.includes(e)}function kn(e,n){return xn[e].find(([t])=>t===n)?.[1]}function ot(e){for(let n of rt){if(n==="canvas"||n==="instance")continue;let t=kn(n,e);if(t!==void 0)return t}}var it="override";function L(e,n){if(n==="boolean")return e===""||e==="true"?{value:!0}:e==="false"?{value:!1}:{error:`Expected true or false, got ${e}`};if(e.startsWith('"')){let r=z(e);return r===void 0?{error:`Malformed quoted string ${e}`}:rr(r,n,e)}if(Lo(e)){if(!Po(n))return{error:Ro(e,n)};let r=ur(e).trim();return r===""?{error:"Empty expression"}:{value:q(r)}}return n==="numberValue"&&ir.test(e)?{value:q(e)}:rr(e,n,e)}var ir=/^-?\d+(?:\.\d+)?%$/;function Po(e){return e==="numberValue"||e==="stringValue"}function Ro(e,n){return n==="number"?`Expected a plain number, not an expression, got ${e}`:n==="string"&&/^\$\w+$/.test(e)?`Expected a literal, got ${e} \u2014 name a token without the $: ${e.slice(1)}`:`Expected a literal, not an expression, got ${e} \u2014 quote it if you meant the text`}function sr(e,n){let t=/^(-?\d+(?:\.\d+)?)([A-Za-z]+)$/.exec(e);return t?/^(?:beats?|bars?)$/.test(t[2])?" \u2014 beats and bars count motion times on a page with bpm=; this is milliseconds":t[2]==="s"&&n==="number"?` \u2014 durations are milliseconds: ${Number(t[1])*1e3}`:/^(?:px|pt|deg|ms)$/.test(t[2])?` \u2014 drop the unit: ${t[1]}`:" \u2014 units are not supported: use a number, a percentage like (100%), or an expression":n==="number"?ir.test(e)?" \u2014 a percentage is not allowed here":"":/^-[$@(]/.test(e)?` \u2014 wrap an expression in parentheses: (${e})`:/^-?[A-Za-z_]\w*(?:\.\w+)+$/.test(e)?` \u2014 wrap an expression in parentheses: (${e})`:""}function rr(e,n,t){switch(n){case"numberValue":case"number":{let r=Number(e);return Number.isFinite(r)&&e.trim()!==""?{value:r}:{error:`Expected a number, got ${t}${sr(e,n)}`}}case"align":return we.includes(e)?{value:e}:{error:`Expected one of ${we.join(", ")}, got ${t}`};case"valign":return $e.includes(e)?{value:e}:{error:`Expected one of ${$e.join(", ")}, got ${t}`};case"fontStyle":return e==="normal"||e==="italic"?{value:e}:{error:`Expected normal or italic, got ${t}`};case"imageFit":return ve.includes(e)?{value:e}:{error:`Expected one of ${ve.join(", ")}, got ${t}`};case"fillRule":return J(Be,e,t);case"lineCap":return J(Ue,e,t);case"lineJoin":return J(We,e,t);case"blendMode":return J(Fe,e,t);case"pageEffect":return J(tn,e,t);case"nodeEffect":return J(rn,e,t);case"emphasisEffect":return J(on,e,t);case"ease":return J(sn,e,t);case"piece":return J(un,e,t);case"time":{let r=le(e);if(r)return{value:pe(r.count,r.unit)};let o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{value:o}:{error:`Expected milliseconds or beats, got ${t}${Do(e)}`}}case"on":return nn.includes(e)?{value:e}:e==="downbeat"?{error:`Expected beat or bar, got ${t} \u2014 write on=bar: a bar starts on its downbeat`}:e==="beats"||e==="bars"?{error:`Expected beat or bar, got ${t} \u2014 write on=${e.slice(0,-1)}`}:{error:`Expected beat or bar, got ${t}`};case"from":{if(ne.includes(e))return{value:e};let r=Number(e);return Number.isFinite(r)&&e.trim()!==""?{value:r}:{error:`Expected a number or one of ${ne.join(", ")}, got ${t}`}}default:return{value:e}}}function Do(e){let n=/^(beat|bar|b)[:\s#]?(\d+(?:\.\d+)?)$/.exec(e);if(n){let r=n[1]==="bar"?"bar":"beat",o=Number(n[2]);return` \u2014 write ${pe(Math.max(0,o-1),r)} (counted from the start: ${r} ${o}'s ${r==="bar"?"downbeat":"start"})`}let t=/^(\d+(?:\.\d+)?)\s*(b|bt|beat|bars?|beats?)$/.exec(e);if(t){let r=t[2]?.startsWith("bar")?"bar":"beat";return` \u2014 write ${pe(Number(t[1]),r)} (counted from the start)`}return sr(e,"number")}function J(e,n,t){return e.includes(n)?{value:n}:{error:`Expected one of ${e.join(", ")}, got ${t}`}}function Lo(e){return/^[$@(]/.test(e)}function z(e){try{let n=JSON.parse(e);return typeof n=="string"?n:void 0}catch{return}}function ur(e){if(!e.startsWith("("))return e;let n=0;for(let t=0;t<e.length;t+=1){let r=e[t];if(r==="(")n+=1;else if(r===")"&&(n-=1,n===0))return t===e.length-1?e.slice(1,-1):e}return e}function ar(e){let n=[],t="",r=0,o=!1;for(let i=0;i<e.length;i+=1){let s=e[i];if(o){t+=s,s==="\\"?(t+=e[i+1]??"",i+=1):s==='"'&&(o=!1);continue}if(s==='"'){o=!0,t+=s;continue}if(s==="("?r+=1:s===")"&&(r=Math.max(0,r-1)),r===0&&/\s/.test(s)){t!==""&&n.push(t),t="";continue}t+=s}return t!==""&&n.push(t),n}function En(e,n,t){let r=t===void 0?void 0:D(t);if(r?.value===void 0||!or(e[n]??""))return;let o=n;for(;o<e.length&&or(e[o]??"");)o+=1;let i=[ur(r.value),...e.slice(n,o)].join(" ");return{end:o,message:`${r.key}: an expression with spaces needs parentheses \u2014 write ${r.key}=(${i})`}}function or(e){return!e.includes("=")&&/^(?:[-+*/]|-?\d+(?:\.\d+)?%?|[$@][\w.]*|[A-Za-z_]\w*(?:\.\w+)+|\(.*|.*\))$/.test(e)}function D(e){let n=e.indexOf("=");return n===-1?{key:e,value:void 0}:{key:e.slice(0,n),value:e.slice(n+1)}}function st(e,n){let t,r=0,o,i=[],s=[],u={},a={},c={},d={},f=[],p=!1,m=!1,x,k=(h,w,b)=>{n.push({severity:"warning",code:w,message:`Line ${h}: ${b}`})},l=(h,w,b)=>{e(h.number,"invalid-brand",`${w} ${b} is written twice \u2014 keep one`)},O=h=>{if(t){e(h.number,"invalid-brand",`A document has one brand line; the first is on line ${r}`);return}let w=h.words[1]===void 0?void 0:Un(h.words[1]);if(!w){e(h.number,"invalid-brand","Expected brand <slug>@<version>, e.g. brand ember@3 \u2014 a slug is lower case, digits and dashes");return}let b=h.words.slice(2).includes("strict"),S=G({...h,words:h.words.filter((v,C)=>C<2||v!=="strict")},2,["id","theme"],e),g=S.theme;g!==void 0&&!Fn.includes(g)&&e(h.number,"invalid-brand",`theme= is light or dark, got ${g}`),t={...w,...S.id===void 0?{}:{id:S.id},...g==="dark"||g==="light"?{theme:g}:{},...b?{strict:!0}:{}},r=h.number,x={kind:"brand"}},M=h=>{let w=h.words[0];if(w==="summary"){let b=Sn(h,1);b===void 0?e(h.number,"invalid-brand",'Expected summary "\u2026"'):o=b;return}if(w==="change"){let b=Number(h.words[1]),S=h.words[2]===void 0?void 0:lr(h.words[2]);if(!Number.isSafeInteger(b)||b<1||S===void 0){e(h.number,"invalid-brand",'Expected change <version> "<what changed>" at=<date>');return}let g=G(h,3,["at"],e);i.push({version:b,note:S,...g.at===void 0?{}:{at:g.at}});return}if(w==="source"){let b=h.words[1];if(b===void 0||b.includes("=")){e(h.number,"invalid-brand","Expected source <kind> key=value\u2026, e.g. source site url=\u2026");return}s.push({kind:b,props:G(h,2,void 0,e)});return}if(w==="rule"){N(h);return}if(w==="banned"){let b=Sn(h,1);if(b===void 0){e(h.number,"invalid-brand",'Expected banned "\u2026"');return}(d.voice??={entries:[]}).entries.push({kind:"banned",text:b});return}e(h.number,"invalid-brand",`"${w}" is not a line of the brand block \u2014 it holds summary, change and source, and in a design rule and banned`)},T=h=>{let w=h.words[1];if(w===void 0||w.includes("=")){e(h.number,"invalid-role","Expected role <name> light=<token or colour> dark=\u2026");return}let b=G(h,2,["light","dark"],e),S=b.light;if(S===void 0){e(h.number,"invalid-role",`role ${w} needs light=`);return}if(Object.prototype.hasOwnProperty.call(u,w))return l(h,"role",w);let g=b.dark;u[w]={light:cr(S),...g===void 0?{}:{dark:cr(g)}}},A=h=>{let w=h.words[1];if(w===void 0||w.includes("=")){e(h.number,"invalid-logo","Expected logo <id> asset=<name> min=<px> clear=<fraction>");return}let b=G(h,2,["asset","min","clear"],e),S=b.asset;if(S===void 0){e(h.number,"invalid-logo",`logo ${w} needs asset=`);return}let g={asset:S};for(let v of["min","clear"]){let C=b[v];if(C===void 0)continue;let U=Number(C);if(!Number.isFinite(U)||U<0){e(h.number,"invalid-logo",`logo ${w}: ${v} must be a number, got ${C}`);continue}g[v]=U}if(Object.prototype.hasOwnProperty.call(a,w))return l(h,"logo",w);a[w]=g},N=h=>{let w=h.words[1],b=h.words[2],S=h.words[3],g=S?.startsWith('"')===!0?z(S):void 0;if(w===void 0||w.includes("=")){e(h.number,"invalid-rule",'Expected rule <id> must|should "<what it asks>" check=\u2026');return}if(b===void 0||!Bn.includes(b)){e(h.number,"invalid-rule",`rule ${w}: the second word is must or should`);return}if(g===void 0){e(h.number,"invalid-rule",`rule ${w} needs its words, quoted: rule ${w} ${b} "\u2026"`);return}let{check:v,...C}=G(h,4,void 0,e);if(v!==void 0&&!Je.includes(v)&&k(h.number,"unknown-check",`rule ${w}: this build has no check "${v}", so it is kept as words only \u2014 the checks are ${Je.join(", ")}`),Object.prototype.hasOwnProperty.call(c,w))return l(h,"rule",w);c[w]={level:b,text:g,...v===void 0?{}:{check:v},...Object.keys(C).length===0?{}:{params:C}}},$=(h,w)=>{let b=h.words[0];if(b.startsWith('"')){let S=Sn(h,0);S===void 0?e(h.number,"invalid-guide",`Could not read ${h.text}`):w.push({kind:"line",text:S});return}if(b==="banned"||b==="avoid"){let S=Sn(h,1);S===void 0?e(h.number,"invalid-guide",`Expected ${b} "\u2026"`):w.push({kind:b,text:S});return}if(b==="rewrite"){let S=G(h,1,["from","to"],e),g=S.from,v=S.to;if(g===void 0||v===void 0){e(h.number,"invalid-guide",'Expected rewrite from="\u2026" to="\u2026"');return}w.push({kind:"rewrite",from:g,to:v});return}if(b==="ref"||b==="approved"||b==="rejected"){let S=G(h,1,["asset","note"],e),g=S.asset;if(g===void 0){e(h.number,"invalid-guide",`Expected ${b} asset=<name> note="\u2026"`);return}let v=S.note;w.push({kind:b,asset:g,...v===void 0?{}:{note:v}});return}e(h.number,"invalid-guide",`"${b}" is not a guide line \u2014 a guide holds quoted lines, banned, avoid, rewrite, ref, approved and rejected`)},E=h=>{let w=h.words[0];if(w.includes("=")||w.startsWith('"')){e(h.number,"invalid-review",'Expected <what>.<id> from=\u2026 note="\u2026", e.g. role.muted from=site');return}let b=G(h,1,["from","note"],e);f.push({target:w,...b.from===void 0?{}:{from:b.from},...b.note===void 0?{}:{note:b.note}})};return{take(h){if(h.indent>0)return x?(x.kind==="brand"?M(h):x.kind==="guide"?$(h,x.entries):E(h),!0):!1;x=void 0;let w=h.words[0];if(w!=="brand"&&!Ge(w))return!1;switch(m=!0,w){case"brand":O(h);break;case"role":T(h);break;case"logo":A(h);break;case"rule":N(h);break;case"guide":{let b=h.words[1];if(b===void 0||b.includes("=")||h.words.length>2){e(h.number,"invalid-guide","Expected guide <id> on its own line, e.g. guide voice"),x={kind:"guide",id:"",entries:[]};break}if(Object.prototype.hasOwnProperty.call(d,b)){l(h,"guide",b),x={kind:"guide",id:"",entries:[]};break}let S=[];d[b]={entries:S},x={kind:"guide",id:b,entries:S};break}case"review":h.words.length>1&&e(h.number,"invalid-review","review is a block: its items go on the lines under it"),p=!0,x={kind:"review"};break}return!0},finish(){if(!m)return{header:!1,review:!1};let h=t??He();return{brand:{slug:h.slug,version:h.version,...t?.id===void 0?{}:{id:t.id},...t?.theme===void 0?{}:{theme:t.theme},...t?.strict===!0?{strict:!0}:{},...o===void 0?{}:{summary:o},changes:i,sources:s,roles:u,logos:a,rules:c,guides:d,review:f},header:t!==void 0,review:p}}}}function G(e,n,t,r){let o={};for(let i of e.words.slice(n)){let{key:s,value:u}=D(i);if(u===void 0){r(e.number,"invalid-brand",`A stray word "${i}" \u2014 expected key=value`);continue}if(t!==void 0&&!t.includes(s)){r(e.number,"invalid-brand",`"${s}" is not allowed here; this line takes ${t.join(", ")}`);continue}o[s]=lr(u)}return o}function Sn(e,n){if(e.words.length!==n+1)return;let t=e.words[n];return t.startsWith('"')?z(t):void 0}function lr(e){return e.startsWith('"')?z(e)??e:e}function cr(e){return e.startsWith("$")?e.slice(1):e}var Co=new Set(["exit","delay","step","together","go","at","after","with"]),hr=["at","after","with","together","step"],Vo=new Set(["pad","duration","delay","ease","on",...hr]);function ut(e){if(e==="at"||e==="length")return an;if(e==="w"||e==="h")return te;if(e==="duration"||e==="delay"||e==="stagger"||e==="hold")return Te;if(e==="pad")return te}function at(e,n){let t=e.words[1];if(t===void 0||t.includes("=")){n(e.number,"invalid-motion","Expected motion <page>, e.g. motion intro enter=fade");return}let r={};for(let i of e.words.slice(2)){let{key:s,value:u}=D(i),a=wn.find(([d])=>d===s)?.[1];if(a===void 0){let d=Co.has(s)?` \u2014 ${s} goes on a node's line, under the header`:"";n(e.number,"invalid-motion",`motion ${t} has no "${s}"${d}`,t);continue}let c=L(u??"",a);"error"in c?n(e.number,"invalid-motion",`${s}: ${Jo(s,u)??c.error}`,t):s==="bpm"&&!zo(c.value)?n(e.number,"invalid-motion",`bpm: expected ${20} to ${300} beats a minute, got ${u??""}`,t):s==="meter"&&!Xo(c.value)?n(e.number,"invalid-motion",`meter: expected a whole number of beats in a bar, 1 to ${16}, got ${u??""}`,t):c.value!==!1&&(r[s]=c.value)}let o=ee({...r,lines:[]});for(let[i]of wn){let s=r[i];if(s===void 0||ut(i)===void 0)continue;let u=ft(i,s,o,t);u!==void 0&&(n(e.number,"invalid-motion",u,t),delete r[i])}return{page:t,number:e.number,head:r,lines:[],where:new Map,taken:new Map,numbers:[]}}function ct(e,n,t){if(n.words[0]==="music"&&!(n.words[1]??"").includes("=")){Bo(e,n,t);return}let r=n.words[0]==="camera"&&n.words[1]!==void 0&&!n.words[1].includes("="),o=r?n.words.slice(1):n.words,i=o[0];if(n.indent!==1){t(n.number,"invalid-motion","A motion line sits one level under its page");return}if(i.includes("=")){t(n.number,"invalid-motion",`Expected a node id first, got ${i}`);return}if(i===e.page&&!r){t(n.number,"invalid-motion",`${i} is the page: its transition goes on the header (motion ${i} enter=fade)`,i);return}let s=r?{id:i,camera:!0}:{id:i},u=!0;for(let d of o.slice(1)){let{key:f,value:p}=D(d),m=Pe.find(([l])=>l===f)?.[1];if(m===void 0){t(n.number,"invalid-motion",`A motion line has no "${f}"${Go(f)}`,i),u=!1;continue}if(r&&!Vo.has(f)){t(n.number,"invalid-motion",`A camera line moves the shot and says only pad=, duration=, delay=, ease= and when: not ${f}=`,i),u=!1;continue}let x=L(p??"",m),k="error"in x||ut(f)===void 0?void 0:ft(f,x.value,ee(mr(e)),e.page);"error"in x?(t(n.number,"invalid-motion",`${f}: ${x.error}`,i),u=!1):k!==void 0?(t(n.number,"invalid-motion",`${i}: ${k}`,i),u=!1):f==="on"&&e.head.bpm===void 0?(t(n.number,"invalid-motion",`${i}: on=${String(x.value)} needs a tempo \u2014 motion ${e.page} bpm=120`,i),u=!1):f==="go"&&ge(x.value)===void 0?(t(n.number,"invalid-motion",`go: expected #<page>, back, next, or an https: or mailto: link, got ${p??""}`,i),u=!1):x.value!==!1&&(s[f]=x.value)}s.enter!==void 0&&s.exit!==void 0&&(t(n.number,"invalid-motion",`${i} either enters or exits on one line \u2014 write a second line for the other`,i),u=!1),s.emphasis!==void 0&&(s.enter!==void 0||s.exit!==void 0)&&(t(n.number,"invalid-motion",`${i} either ${s.enter!==void 0?"enters":"exits"} or is stressed on one line \u2014 write a second line for emphasis=`,i),u=!1);let a=hr.filter(d=>s[d]!==void 0);if(s.step===!0&&s.together===!0?(t(n.number,"invalid-motion",`${i} waits for a step or starts together with the line above, not both`,i),u=!1):a.length>1?(t(n.number,"invalid-motion",`${i} says when it starts twice (${a.join(", ")}): keep one`,i),u=!1):s.on!==void 0&&(s.with!==void 0||s.together===!0)&&(t(n.number,"invalid-motion",`${i} starts with another line (${s.with===void 0?"together":"with="}), so on= could only pull it apart: keep one`,i),u=!1),u){let d=Ho(s);d!==void 0&&(t(n.number,"invalid-motion",`${i}: ${d}`,i),u=!1)}if(!u)return;let c=Wo(s);if(!cn(c)){t(n.number,"invalid-motion",`${i} says nothing: give it enter=, exit=, emphasis= or go=`,i);return}if(r){e.where.has(i)||e.where.set(i,n.number),e.lines.push(c),e.numbers.push(n.number);return}for(let d of["enter","exit","emphasis","go"]){if(c[d]===void 0)continue;let f=e.taken.get(`${i} ${d}`);if(f!==void 0){let p=d==="go"?"has a go=":d==="enter"?"enters":d==="exit"?"exits":"has an emphasis=";t(n.number,"invalid-motion",`${i} already ${p} on line ${f}`,i);return}}for(let d of["enter","exit","emphasis","go"])c[d]!==void 0&&e.taken.set(`${i} ${d}`,n.number);e.where.has(i)||e.where.set(i,n.number),e.lines.push(c),e.numbers.push(n.number)}function dt(e){let n={...e.head.enter===void 0?{}:{enter:e.head.enter},...e.head.duration===void 0?{}:{duration:e.head.duration},...e.head.scroll===!0?{scroll:!0}:{},...e.head.length===void 0?{}:{length:e.head.length},...e.head.w===void 0?{}:{w:e.head.w},...e.head.h===void 0?{}:{h:e.head.h},...e.head.bpm===void 0?{}:{bpm:e.head.bpm},...e.head.meter===void 0?{}:{meter:e.head.meter},...e.music===void 0?{}:{music:e.music},lines:e.lines};return Ae(n)?void 0:n}var Fo=new Set(["loop","step","together"]);function Bo(e,n,t){let r=n.words[1];if(n.indent!==1){t(n.number,"invalid-motion","A motion line sits one level under its page");return}if(r===void 0){t(n.number,"invalid-motion","Expected music <asset>, e.g. music bed fadeout=1500");return}if(Fo.has(r)){t(n.number,"invalid-motion",`music names its track first: music <asset> ${r}`);return}if(e.musicLine!==void 0){t(n.number,"invalid-motion",`motion ${e.page} already has music on line ${e.musicLine}: a page has one track`);return}let o={asset:r},i=ee(mr(e)),s=!0,u=c=>{t(n.number,"invalid-motion",`music ${r}: ${c}`),s=!1};for(let c of n.words.slice(2)){let{key:d,value:f}=D(c),p=$n.find(([x])=>x===d)?.[1];if(p===void 0){u(`the music line has no "${d}"${Uo(d)}`);continue}if(d==="from"&&f!==void 0&&/\d(?:beats?|bars?)$/.test(f)){u(`from= is where in the track to begin, in milliseconds, not ${f}`);continue}let m=L(f??"",p);if("error"in m){u(`${d}: ${m.error}`);continue}if(d==="from"&&!pr(m.value,0,Me)){u(`from: expected 0 to ${Me} milliseconds, got ${f??""}`);continue}if(d==="volume"&&!pr(m.value,0,1)){u(`volume: expected 0 to 1, got ${f??""}`);continue}if(d==="fadein"||d==="fadeout"){let x=ft(d,m.value,i,e.page);if(x!==void 0){u(x);continue}}m.value!==!1&&(o[d]=m.value)}if(!s)return;let a={asset:r};for(let[c]of $n)o[c]!==void 0&&(a[c]=o[c]);e.music=a,e.musicLine=n.number}function pr(e,n,t){return typeof e=="number"&&e>=n&&e<=t}function Uo(e){return e==="fade"?" \u2014 write fadein= and fadeout=":e==="fade-in"||e==="fadeIn"||e==="fade_in"?" \u2014 write fadein=":e==="fade-out"||e==="fadeOut"||e==="fade_out"?" \u2014 write fadeout=":e==="start"||e==="offset"||e==="seek"?" \u2014 write from= (where in the track to begin, in milliseconds)":e==="gain"||e==="level"?" \u2014 write volume= (0 to 1)":e==="at"||e==="delay"||e==="after"||e==="with"?": the music starts with the video; from= picks where in the track":": it takes from=, volume=, fadein=, fadeout= and loop"}function Wo(e){let n=e.camera===!0?{id:e.id,camera:!0}:{id:e.id};for(let[t]of Pe)e[t]!==void 0&&(n[t]=e[t]);return n}function mr(e){let{bpm:n,meter:t}=e.head;return{...n===void 0?{}:{bpm:n},...t===void 0?{}:{meter:t},lines:[]}}function ft(e,n,t,r){if(he(n)&&!t)return`${n} needs a tempo \u2014 motion ${r} bpm=120`;let o=typeof n=="number"||he(n)?Oe(n,t):void 0,i=ut(e)??Te;if(o!==void 0&&o>=(e==="w"||e==="h"?16:0)&&o<=i)return;let u=String(n),a=he(n)&&o!==void 0?` (${Math.round(o)} ms)`:"";return e==="w"||e==="h"?`${e}: expected 16 to ${te} pixels, got ${u}`:e==="pad"?`pad: expected 0 to ${te}, got ${u}`:`${e}: expected 0 to ${i} milliseconds, got ${u}${a}`}function zo(e){return typeof e=="number"&&e>=20&&e<=300}function Xo(e){return typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=16}function Jo(e,n){if(e==="meter"&&n!==void 0&&/^\d+\/\d+$/.test(n))return`Expected beats in a bar, got ${n} \u2014 meter is beats per bar: meter=${n.split("/")[0]??""}`;if(e==="duration"&&n!==void 0&&/\d(?:beats?|bars?)$/.test(n))return`Expected milliseconds, got ${n} \u2014 the page transition is milliseconds; beats are for the lines`}function Go(e){return e==="emphasise"||e==="emphasize"?" \u2014 write emphasis=pulse":e==="easing"?" \u2014 write ease=":e==="split"?" \u2014 write by=word or by=letter":e==="start"?" \u2014 write at= (milliseconds), after= or with=":""}function Ho(e){let n=e.enter,t=e.exit,r=n??t,o=e.from;if(t==="count")return"count only enters: it runs a number up to its written value";if(o!==void 0)if(r==="count"){if(typeof o!="number")return"from= on count is the number it starts at, e.g. from=0"}else if(r==="wipe"||r==="grow"){if(typeof o=="number")return`from= on ${r} is a side: ${ne.join(", ")}`}else return"from= goes with count (a number), or wipe and grow (a side)";if(e.by!==void 0&&r!==void 0&&!me.includes(r))return`by= splits a text for ${me.join(", ")}, not ${r}`;if(e.by!==void 0&&r===void 0)return"by= goes with enter= or exit=";if(e.stagger!==void 0&&r===void 0)return"stagger= goes with enter= or exit=";if(e.hold!==void 0&&n===void 0)return"hold= goes with enter=: how long to stay before leaving the way it came"}function lt(e){return(n,t,r,o)=>{e.push({severity:"error",code:t,message:`Line ${n}: ${r}`,...o===void 0?{}:{nodeId:o}})}}function pt(e){let n=[],t=e.split(`
|
|
5
|
-
`);for(let r=0;r<t.length;r+=1){let o=t[r],i=o.trim();if(i===ue)break;if(i===""||i.startsWith("```"))continue;let s=o.length-o.trimStart().length;n.push({number:r+1,indent:Math.floor(s/2),text:i,words:ar(i)})}return n}function ht(e){let n=[],t=[],r,o=()=>{r&&r.runs.length>0&&(r.props.content=yr(r.runs)),r=void 0},i=s=>{for(o();n.length>0&&n[n.length-1].indent>=s;)Zo(n.pop())};return{push(s){let u=s.words[0];if(u.startsWith('"')&&r&&s.indent>r.indent){let f=gr(s,e);return f!==void 0&&r.runs.push(f),!0}if(u===it){i(s.indent);let f=n[n.length-1];return!f||f.type!=="instance"?(e(s.number,"invalid-override","An override line must sit inside an instance"),!0):(r=qo(f,s,e),!0)}if(u.startsWith('"')){let f=n[n.length-1];if(!f||f.type!=="text")return e(s.number,"invalid-content","A quoted line must sit inside a text node"),!0;let p=gr(s,e);return p!==void 0&&f.runs.push(p),!0}if(!vn(u))return!1;i(s.indent);let a=s.words[1];if(a===void 0||a.includes("="))return e(s.number,"missing-id",`A ${u} needs an id`),!0;let c=Yo(u,a,s.words.slice(2),s,e),d=n[n.length-1];return d?.type==="instance"?e(s.number,"invalid-override",`${d.record.id} takes its contents from its component \u2014 change the component, or write an override line`,a):d?d.children.push(c.record):t.push(c.record),n.push(c),!0},finish(){return i(0),t}}}function Yo(e,n,t,r,o){let i={type:e,id:n},s=[];for(let u=0;u<t.length;u+=1){let{key:a,value:c}=D(t[u]),d=kn(e,a);if(d===void 0){let p=En(t,u,t[u-1]);p?(o(r.number,"invalid-value",p.message,n),u=p.end-1):o(r.number,"invalid-value",`${e} has no property "${a}"`,n);continue}let f=L(c??"",d);"error"in f?o(r.number,"invalid-value",`${a}: ${f.error}`,n):i[a]=f.value}return ze(e)&&(i.children=s),e==="text"&&(i.content=""),{indent:r.indent,type:e,record:i,children:s,runs:[]}}function qo(e,n,t){let r=e.record.id,o=n.words[1];if(o===void 0||o.includes("=")){t(n.number,"invalid-override","An override names the part it changes, e.g. override item.title fill=accent",r);return}let i=e.record.overrides??={},s=i[o]??={},u=n.words.slice(2);for(let a=0;a<u.length;a+=1){let{key:c,value:d}=D(u[a]),f=ae(c)?ot(c):void 0;if(f===void 0){let m=En(u,a,u[a-1]);m?(t(n.number,"invalid-value",m.message,r),a=m.end-1):c==="content"?t(n.number,"invalid-value","Write the text as quoted lines under the override",r):t(n.number,"invalid-value",`An override cannot set "${c}"`,r);continue}let p=L(d??"",f);"error"in p?t(n.number,"invalid-value",`${c}: ${p.error}`,r):s[c]=p.value}return{indent:n.indent,props:s,runs:[]}}function Zo(e){if(e.type==="text"&&(e.record.content=yr(e.runs)),e.type==="instance"){let n=e.record.overrides;for(let[t,r]of Object.entries(n??{}))Object.keys(r).length===0&&delete n?.[t];n&&Object.keys(n).length===0&&delete e.record.overrides}}function yr(e){if(e.length===0)return"";let n=e[0];return e.length===1&&typeof n=="string"?n:[...e]}function gr(e,n){let t=z(e.words[0]);if(t===void 0){n(e.number,"invalid-run","Malformed quoted string");return}if(e.words.length===1)return t;let r={text:t};for(let o of e.words.slice(1)){let{key:i,value:s}=D(o),u=bn.find(([c])=>c===i);if(!u){n(e.number,"invalid-run",`A run has no mark "${i}"`);continue}let a=L(s??"",u[1]);"error"in a?n(e.number,"invalid-run",`${i}: ${a.error}`):r[i]=a.value}return r}function Qo(e){let n=[],t=lt(n),r=de,o,i=!1,s={},u={},a={},c=ht(t),d=st(t,n),f,p={},m=!1,x=!1,k={},l=new Map,O,M=!1,T=()=>{if(!O)return;let g=O;O=void 0;let v=l.get(g.page);if(v!==void 0){t(g.number,"invalid-motion",`motion ${g.page} is written twice \u2014 put its lines in the block on line ${v}`,g.page);return}l.set(g.page,g.number);for(let[U,Ce]of g.where)l.set(`${g.page} ${U}`,Ce);let C=dt(g);C&&(k[g.page]=C)};for(let g of pt(e)){let v=g.words[0];if(O&&g.indent>0){ct(O,g,t);continue}if(!(M&&g.indent>0)){if(M=!1,T(),v==="motion"&&g.indent===0){f=void 0,O=at(g,t),M=O===void 0;continue}if(d.take(g)){f=void 0;continue}if(v==="version"){i=!0,ti(g,n);continue}if(v==="kind"&&g.indent===0){r=ri(g,n);continue}if(v==="title"&&g.indent===0){o=xr(g,t);continue}if(v==="theme"&&g.indent===0){f=void 0,m=!0,x&&t(g.number,"invalid-theme","theme dark is written twice \u2014 keep one block"),x=!0,(g.words[1]!=="dark"||g.words.length>2)&&t(g.number,"invalid-theme","Expected theme dark on its own line, with the tokens that differ indented under it");continue}if(v.startsWith("$")){if(f=void 0,m&&g.indent>0){mt(g,p,t);continue}m=!1,mt(g,s,t);continue}if(g.indent===0)m=!1;else if(m){t(g.number,"invalid-theme","A theme block holds only $name = value lines");continue}if(v==="asset"&&g.indent===0){f=void 0,oi(g,a,t);continue}if(v==="font"&&g.indent===0){f=si(g,u,t);continue}if((v==="fallback"||v==="face")&&f){ai(v,g,f,t);continue}f=void 0,!c.push(g)&&t(g.number,"unknown-node-type",`Unknown statement "${v}"`)}}T();let A=ni(d.finish(),r,n),N=fe({dark:p}),$={...A===void 0?{}:{brand:A},...N===void 0?{}:{themes:N}},E=ei(c.finish(),n),h=Object.keys(k).length===0?{}:{motion:k},w=(g,v)=>l.get(v===void 0?g:`${g} ${v}`);if(!E){i||n.push({severity:"error",code:"invalid-document",message:"No nodes found"});let g=Se({id:Q,children:[]}),v=en({kind:r,...o===void 0?{}:{title:o},tokens:s,fonts:u,assets:a,...h,...$,root:g});return n.push(...Ne(v,w)),{document:v,problems:n}}let b=Z(E),S={version:H({kind:r,fonts:u,...$,root:b}),kind:r,...o===void 0?{}:{title:o},tokens:s,fonts:u,assets:a,...h,...$,root:b};return n.push(...Ne(S,w)),{document:S,problems:n}}function ei(e,n){let t=e[0];if(t!==void 0){if(e.length===1&&t.type==="canvas")return t;for(let r of e){if(r.type!=="canvas")continue;let o=r.id;n.push({severity:"error",code:"invalid-document",message:"A canvas must be the only top-level node",...typeof o=="string"?{nodeId:o}:{}})}return{type:"canvas",id:Q,children:[...e]}}}function ni(e,n,t){let r=e.brand;if(!r)return;e.header||t.push({severity:"error",code:"invalid-brand",message:"A brand needs its brand line first, e.g. brand ember@1"});let o=Object.entries(r.guides).filter(([s,u])=>s!=="voice"||u.entries.some(a=>a.kind!=="banned")),i=Object.keys(r.roles).length+Object.keys(r.logos).length+o.length+r.review.length;return n!=="brand"&&i>0&&t.push({severity:"warning",code:"brand-only",message:"Roles, logos, guides and review define a brand, and are read in a kind brand document"}),r}function ti(e,n){Ze.includes(Number(e.words[1]))||n.push({severity:"warning",code:"version-mismatch",message:`Line ${e.number}: expected version ${Qe} or older, got ${e.words[1]??"nothing"}`})}function ri(e,n){let t=e.words[1];return t!==void 0&&Ee.includes(t)?t:(n.push({severity:"error",code:"unknown-kind",message:`Line ${e.number}: unknown kind "${t??"nothing"}" \u2014 this build reads ${Ee.join(", ")}`}),de)}function xr(e,n){let t=e.words.slice(1).join(" ").trim();if(t===""){n(e.number,"invalid-value",'title needs a name, e.g. title "Pitch deck"');return}let r=t.startsWith('"')?z(t):t;if(r===void 0){n(e.number,"invalid-value",`Could not read the title ${t}`);return}return r.trim()===""?void 0:r}function mt(e,n,t){let{name:r,value:o}=gt(e.words);if(r===void 0||o===void 0){t(e.number,"invalid-token","Expected $name = value");return}if(!o.startsWith('"')&&/\s/.test(o)){t(e.number,"invalid-token",`$${r}: expected one value, got "${o}". Quote it if the value has spaces; there are no comments.`);return}let i=L(o,"stringValue");if("error"in i){t(e.number,"invalid-token",`$${r}: ${i.error}`);return}if(typeof i.value!="string"){t(e.number,"invalid-token",`$${r} may not be an expression`);return}n[r]=br(i.value,o)}function br(e,n){let t=Number(e);return n.startsWith('"')||!Number.isFinite(t)||e.trim()===""?e:t}function gt(e){let n=e[0],t=i=>i.startsWith("$")?i.slice(1):i;if(e[1]==="=")return{name:t(n),value:e.slice(2).join(" ")||void 0};let{key:r,value:o}=D(n);return o!==void 0?{name:t(r),value:o}:{name:t(n)}}function oi(e,n,t){let r=e.words.slice(1),o=r[0],i=r[1]==="=",s=o===void 0?void 0:D(o),u=s?.key,a=i?r[2]:s?.value,c=r.slice(i?3:1);if(u===void 0||u===""||a===void 0){t(e.number,"invalid-asset","Expected asset <name> = <type> hash=\u2026 bytes=\u2026");return}let d={};for(let x of c){let{key:k,value:l}=D(x);if(l===void 0){t(e.number,"invalid-asset",`Asset "${u}" has a stray word "${x}"`);continue}d[k]=ii(l)}let f=d.hash,p=Number(d.bytes);if(f===void 0||!Number.isFinite(p)){t(e.number,"invalid-asset",`Asset "${u}" needs a hash and a bytes count`);return}let m=d.ms===void 0?void 0:Number(d.ms);if(m!==void 0&&!(Number.isFinite(m)&&m>=0)){t(e.number,"invalid-asset",`Asset "${u}": ms is the track's length, in milliseconds`);return}n[u]={type:a,hash:f,bytes:p,...m===void 0?{}:{ms:m},...d.credit===void 0?{}:{credit:d.credit},...d.source===void 0?{}:{source:d.source},...d.license===void 0?{}:{license:d.license}}}function ii(e){return e.startsWith('"')?z(e)??e:e}function si(e,n,t){let{name:r,value:o}=gt(e.words.slice(1));if(r===void 0||o===void 0){t(e.number,"invalid-font","Expected font <name> = <family>");return}let i=L(o,"string"),s={family:"error"in i?o:i.value};return n[r]=s,{family:s,faces:[]}}var ui=/^[A-Za-z_][\w-]*$/;function ai(e,n,t,r){if(e==="fallback"){let u=L(n.words.slice(1).join(" "),"string");"error"in u?r(n.number,"invalid-font",`fallback: ${u.error}`):t.family.fallback=u.value;return}let o=n.words[1];if(o===void 0){r(n.number,"invalid-font-face","A face needs a src, or asset=");return}let i=o.startsWith("asset=")?o.slice(6):void 0,s={};if(i!==void 0){if(!ui.test(i)){r(n.number,"invalid-font-face",`asset=${i}: not an asset name`);return}s.asset=i}else{let u=L(o,"string");s.src="error"in u?o:u.value}for(let u of n.words.slice(2)){let{key:a,value:c}=D(u);if(a!=="weight"&&a!=="style"){r(n.number,"invalid-font-face",`A face has no property "${a}"`);continue}let d=L(c??"",a==="weight"?"number":"fontStyle");"error"in d?r(n.number,"invalid-font-face",`${a}: ${d.error}`):s[a]=d.value}t.faces.push(s),t.family.faces=t.faces}var $r="https://getv.design/ns/vd",aa=`<metadata><vd:document xmlns:vd="${$r}" version="1"><![CDATA[
|
|
6
|
-
`;var pi=/<vd:document\b[^>]*>([\s\S]*?)<\/vd:document\s*>/;function hi(e){let n=pi.exec(e);if(!n)return;let t=n[1]??"",r="",o=t;for(;;){let i=o.indexOf("<![CDATA[");if(i===-1){r+=wr(o);break}r+=wr(o.slice(0,i));let s=o.indexOf("]]>",i);if(s===-1){r+=o.slice(i+9);break}r+=o.slice(i+9,s),o=o.slice(s+3)}return`${r.replace(/^\n/,"").replace(/\n$/,"")}
|
|
7
|
-
`}function mi(e){return/^\uFEFF?\s*</.test(e)}function wr(e){return e.replace(/&(lt|gt|quot|apos|amp|#\d+|#x[0-9a-fA-F]+);/g,(n,t)=>{switch(t){case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";case"amp":return"&";default:{let r=t.startsWith("#x")?parseInt(t.slice(2),16):parseInt(t.slice(1),10);return Number.isFinite(r)&&r<=1114111?String.fromCodePoint(r):n}}})}var vr=.04,kr=.85;var ki=[.2,0,0,1],Ei=[.4,0,1,1],Si=[.4,0,.2,1];function An(e){return/^\s*(linear|radial|conic|repeating-[a-z]+)-gradient\s*\(/i.test(e)}function yt(e){let n=e.trim(),t=/^([a-z-]+)-gradient\s*\(([\s\S]*)\)$/i.exec(n);if(!t)return An(n)?{error:'A gradient needs its closing ")"'}:{kind:"solid",colour:n};let r=t[1].toLowerCase(),o=Oi(t[2]).map(i=>i.trim());if(o.some(i=>i===""))return{error:"A gradient has an empty argument"};if(r==="linear"){let i=Ti(o[0]),s=Sr(i===void 0?o:o.slice(1));return"error"in s?s:{kind:"linear",angle:i??180,stops:s.stops}}if(r==="radial"){let i=Ni(o[0]);if(i&&"error"in i)return i;let s=Sr(i?o.slice(1):o);return"error"in s?s:{kind:"radial",shape:i?.shape??"ellipse",cx:i?.cx??.5,cy:i?.cy??.5,stops:s.stops}}return{error:`${r}-gradient is not supported; use linear-gradient or radial-gradient`}}function xt(e){let n=e.map(r=>r.at);n[0]===void 0&&(n[0]=0),n[n.length-1]===void 0&&(n[n.length-1]=1);let t=0;for(let r=0;r<n.length;r+=1){let o=n[r];o!==void 0&&(t=Math.max(t,o),n[r]=t)}for(let r=1;r<n.length;r+=1){if(n[r]!==void 0)continue;let o=r-1,i=r;for(;n[i]===void 0;)i+=1;let s=n[o],u=n[i];for(let a=r;a<i;a+=1)n[a]=s+(u-s)*(a-o)/(i-o);r=i}return e.map((r,o)=>({colour:r.colour,at:n[o]}))}function Oi(e){let n=[],t=0,r=0;for(let o=0;o<e.length;o+=1){let i=e[o];i==="("?t+=1:i===")"?t=Math.max(0,t-1):i===","&&t===0&&(n.push(e.slice(r,o)),r=o+1)}return n.push(e.slice(r)),n}var Mi={top:[0,-1],bottom:[0,1],left:[-1,0],right:[1,0]};function Ti(e){let n=/^(-?\d*\.?\d+)(deg|turn|rad)$/i.exec(e);if(n){let i=Number(n[1]),s=n[2].toLowerCase();return s==="turn"?i*360:s==="rad"?i*180/Math.PI:i}let t=/^to\s+([a-z]+)(?:\s+([a-z]+))?$/i.exec(e);if(!t)return;let r=0,o=0;for(let i of[t[1],t[2]]){if(i===void 0)continue;let s=Mi[i.toLowerCase()];if(!s)return;r+=s[0],o+=s[1]}return(Math.atan2(r,-o)*180/Math.PI+360)%360}var Ai={left:0,top:0,center:.5,right:1,bottom:1};function Ni(e){let n=/^(circle|ellipse)?\s*(?:at\s+(\S+)(?:\s+(\S+))?)?$/i.exec(e);if(!n||n[1]===void 0&&n[2]===void 0)return;let t=n[1]?.toLowerCase();if(n[2]===void 0)return t?{shape:t}:void 0;let r=Er(n[2]),o=n[3]===void 0?.5:Er(n[3]);return r===void 0||o===void 0?{error:`A radial centre is two percentages or keywords, not "${e}"`}:{...t?{shape:t}:{},cx:r,cy:o}}function Er(e){let n=Ai[e.toLowerCase()];if(n!==void 0)return n;let t=/^(-?\d*\.?\d+)%$/.exec(e);return t?Number(t[1])/100:void 0}function Sr(e){if(e.length<2)return{error:"A gradient needs at least two colours"};let n=[];for(let t of e){let r=/^([\s\S]*?\S)\s+(-?\d*\.?\d+)%$/.exec(t);if(r&&Ii(r[1]))n.push({colour:r[1],at:Number(r[2])/100});else{if(/\s/.test(t.replace(/\([^)]*\)/g,"")))return{error:`"${t}" is not a colour with an optional percentage`};n.push({colour:t})}}return{stops:n}}function Ii(e){let n=0;for(let t of e)if(t==="("&&(n+=1),t===")"&&(n-=1),n<0)return!1;return n===0}function bt(e){let n=e.trim();if(n===""||n==="none")return{shadows:[]};let t=[];for(let r of _i(n)){let o=Pi(r.trim());if(o.includes("inset"))return{error:"Inner shadows (inset) are not supported yet"};let i=[],s=[];for(let f of o){let p=/^(-?\d*\.?\d+)(px)?$/.exec(f);p&&s.length===0?i.push(Number(p[1])):s.push(f)}if(i.length<2||i.length>4)return{error:`"${r.trim()}" needs x, y, then optional blur and spread`};if(s.length!==1)return{error:`"${r.trim()}" needs one colour after its numbers`};let[u=0,a=0,c=0,d=0]=i;if(c<0)return{error:"A shadow cannot have a negative blur"};t.push({x:u,y:a,blur:c,spread:d,colour:s[0]})}return{shadows:t}}function _i(e){let n=[],t=0,r=0;for(let o=0;o<e.length;o+=1){let i=e[o];i==="("?t+=1:i===")"?t=Math.max(0,t-1):i===","&&t===0&&(n.push(e.slice(r,o)),r=o+1)}return n.push(e.slice(r)),n}function Pi(e){let n=[],t=0,r="";for(let o of e){if(o==="("&&(t+=1),o===")"&&(t=Math.max(0,t-1)),/\s/.test(o)&&t===0){r!==""&&n.push(r),r="";continue}r+=o}return r!==""&&n.push(r),n}function Nn(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function Or(e,n,t){if(t===0)return e;let r=t*Math.PI/180,o=Math.cos(r),i=Math.sin(r),s=e.x-n.x,u=e.y-n.y;return{x:n.x+s*o-u*i,y:n.y+s*i+u*o}}function wt(e,n,t=Nn(e)){if(n%360===0)return e;let r=[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}].map(a=>Or(a,t,n)),o=r.map(a=>a.x),i=r.map(a=>a.y),s=Math.min(...o),u=Math.min(...i);return{x:s,y:u,w:Math.max(...o)-s,h:Math.max(...i)-u}}var Tr="system-ui, -apple-system, Segoe UI, Roboto, sans-serif",Ar=16,Nr=400,Ir=1.2,In="#0F172A";function _n(){return{advance(e,n){return e.length*(n.size*.5+n.letterSpacing)},metrics(e){return{ascent:e.size*.8,descent:e.size*.2,lineGap:0}}}}function $t(e,n){if(e===void 0)return Tr;let t=n[e];return t?t.fallback?`${Mr(t.family)}, ${t.fallback}`:Mr(t.family):e}function Mr(e){return/^[A-Za-z][A-Za-z0-9 -]*$/.test(e)?e:JSON.stringify(e)}function vt(e,n,t,r){let o={family:$t(n.font,t),size:n.size,weight:n.weight,italic:n.italic,underline:!1,strike:!1,fill:r(n.fill),letterSpacing:n.letterSpacing},i=typeof e=="string"?[e]:e,s=[];for(let u of i){if(typeof u=="string"){u.length>0&&s.push({text:u,style:o});continue}let a=u;a.text.length!==0&&s.push({text:a.text,style:{family:a.font===void 0?o.family:$t(a.font,t),size:a.size??o.size,weight:a.weight??o.weight,italic:a.italic??o.italic,underline:a.underline??!1,strike:a.strike??!1,fill:a.fill===void 0?o.fill:r(a.fill),letterSpacing:a.letterSpacing??o.letterSpacing,...a.link!==void 0&&Y(a.link)?{link:a.link}:{}}})}return s}function Ci(e,n){let t=[];for(let r of e)for(let o of r.text.split(/(\n)/))if(o!==""){if(o===`
|
|
8
|
-
`){let i=t[t.length-1];i&&!i.hardBreak?t[t.length-1]={...i,hardBreak:!0}:t.push({text:"",style:r.style,w:0,hardBreak:!0});continue}for(let i of o.match(/\S+\s*|\s+/g)??[])t.push({text:i,style:r.style,w:n.advance(i,r.style),hardBreak:!1})}return t}function Vi(e,n,t){let r=[...e.text],o=[],i="";for(let s of r){let u=i+s;if(i!==""&&t.advance(u,e.style)>n){o.push({text:i,style:e.style,w:t.advance(i,e.style),hardBreak:!1}),i=s;continue}i=u}return i!==""&&o.push({text:i,style:e.style,w:t.advance(i,e.style),hardBreak:e.hardBreak}),o.length>0?o:[e]}function _r(e,n){let{width:t,measure:r}=n,o=Ci(r.itemize?e.flatMap(c=>r.itemize?.(c)??[c]):e,r);if(o.length===0){let c=e[0]?.style,d=c?n.lineHeight*c.size:0;return{lines:c?[Fi(c,n.lineHeight)]:[],width:0,height:d}}let i=[],s=[],u=0,a=()=>{i.push(s),s=[],u=0};for(let c of o){let d=s.length===0&&c.w>t&&t>0?Vi(c,t,r):[c];for(let f of d){let p=f.text.trimEnd(),m=p===f.text?f.w:r.advance(p,f.style);s.length>0&&u+m>t&&a(),s.push(f),u+=f.w,f.hardBreak&&a()}}return s.length>0&&i.push(s),Bi(i,n)}function Fi(e,n){let t=n*e.size;return{y:0,h:t,baseline:t*.8,w:0,spans:[],style:e}}function Bi(e,n){let t=[],r=0,o=0;return e.forEach((i,s)=>{let u=i.map(E=>E.style.size),a=Math.max(...u,0),c=n.lineHeight*a,d=i.map(E=>n.measure.metrics(E.style)),f=Math.max(...d.map(E=>E.ascent),0),p=Math.max(...d.map(E=>E.descent),0),m=r+(c-(f+p))/2+f,x=Ui(i,n.measure),k=x.reduce((E,h)=>E+h.w,0);o=Math.max(o,k);let l=s===e.length-1||(i[i.length-1]?.hardBreak??!1),O=n.align==="justify"&&!l&&x.length>1,M=Math.max(0,n.width-k),T=n.align==="center"?M/2:n.align==="right"?M:0,A=O?M/(x.length-1):0,N=[],$=T;x.forEach((E,h)=>{N.push({text:E.text,style:E.style,x:$,w:E.w}),$+=E.w+(h<x.length-1?A:0)}),t.push({y:r,h:c,baseline:m,w:k,spans:Wi(N,O)}),r+=c}),{lines:t,width:o,height:r}}function Ui(e,n){let t=[...e];for(;t.length>0;){let r=t[t.length-1],o=r.text.trimEnd();if(o===r.text)break;if(o===""){t.pop();continue}t[t.length-1]={...r,text:o,w:n.advance(o,r.style)};break}return t}function Wi(e,n){if(n)return[...e];let t=[];for(let r of e){let o=t[t.length-1];if(o&&Pr(o.style,r.style)&&Math.abs(o.x+o.w-r.x)<.01){t[t.length-1]={...o,text:o.text+r.text,w:o.w+r.w};continue}t.push(r)}return t}function Pr(e,n){return e.family===n.family&&e.size===n.size&&e.weight===n.weight&&e.italic===n.italic&&e.underline===n.underline&&e.strike===n.strike&&e.fill===n.fill&&e.letterSpacing===n.letterSpacing&&e.link===n.link}function kt(e,n,t,r,o,i){let s={size:n.size??Ar,weight:n.weight??Nr,lineHeight:n.lineHeight??Ir,letterSpacing:n.letterSpacing??0,italic:e.italic??!1,font:typeof e.font=="string"?e.font:void 0,fill:typeof e.fill=="string"?e.fill:In},u=vt(e.content,s,r,o),a=vt(" ",s,r,o).map(c=>({...c,text:""}));return _r(u.length>0?u:a,{width:t,align:e.align??"left",lineHeight:s.lineHeight,measure:i})}function Et(e,n,t){let r=n-t;return e.valign==="middle"?r/2:e.valign==="bottom"?r:0}var Rr=["x","y","w","h","left","right","top","bottom","cx","cy"];function Re(e){return Rr.includes(e)}var Dr=["parent","prev","next","self","root"];function St(e){return Dr.includes(e)}var j=class extends Error{position;constructor(n,t){super(n),this.position=t,this.name="ExprSyntaxError"}},Lr=/[A-Za-z_]/,Ot=/[A-Za-z0-9_]/;function Mt(e){let n=[],t=0,r=()=>{if(!Lr.test(e[t]??""))throw new j(`Expected a name at position ${t}`,t);let s=t;for(;t<e.length&&Ot.test(e[t]??"");)t++;return e.slice(s,t)},o=()=>{if(!Ot.test(e[t]??""))throw new j(`Expected a name at position ${t}`,t);let s=t;for(;t<e.length&&Ot.test(e[t]??"");)t++;return e.slice(s,t)},i=()=>{let s=[r()];for(;e[t]===".";)t++,s.push(o());return s};for(;t<e.length;){let s=e[t]??"";if(/\s/.test(s)){t++;continue}if(/[0-9]/.test(s)){let u=t;for(;t<e.length&&/[0-9]/.test(e[t]??"");)t++;if(e[t]==="."&&/[0-9]/.test(e[t+1]??""))for(t++;t<e.length&&/[0-9]/.test(e[t]??"");)t++;let a=e.slice(u,t),c=Number(a);if(!Number.isFinite(c))throw new j(`Bad number "${a}"`,u);e[t]==="%"?(t++,n.push({type:"percent",value:c})):n.push({type:"number",value:c});continue}if(s==="$"){t++,n.push({type:"token",name:r()});continue}if(s==="@"){t++,n.push({type:"ref",path:i()});continue}if(Lr.test(s)){n.push({type:"word",path:i()});continue}if("+-*/()".includes(s)){t++,n.push({type:"op",value:s});continue}throw new j(`Unexpected character "${s}" at position ${t}`,t)}return n.push({type:"eof"}),n}var zi={"+":1,"-":1,"*":2,"/":2};function Pn(e){try{let n=Mt(e),t=new Tt(n),r=t.parseBinary(0);return t.expectEof(),{ok:!0,ast:r}}catch(n){if(n instanceof j)return{ok:!1,message:n.message};throw n}}var Tt=class{tokens;index=0;constructor(n){this.tokens=n}peek(){return this.tokens[this.index]??{type:"eof"}}next(){let n=this.peek();return this.index++,n}expectEof(){if(this.peek().type!=="eof")throw new j("Unexpected trailing input",this.index)}parseBinary(n){let t=this.parseUnary();for(;;){let r=this.peek();if(r.type!=="op"||!Xi(r.value))break;let o=zi[r.value];if(o<n)break;this.next();let i=this.parseBinary(o+1);t={kind:"binary",op:r.value,left:t,right:i}}return t}parseUnary(){let n=this.peek();return n.type==="op"&&(n.value==="-"||n.value==="+")?(this.next(),{kind:"unary",op:n.value,operand:this.parseUnary()}):this.parsePrimary()}parsePrimary(){let n=this.next();switch(n.type){case"number":return{kind:"number",value:n.value};case"percent":return{kind:"percent",value:n.value};case"token":return{kind:"token",name:n.name};case"ref":{if(n.path.length<2)throw new j(`@${n.path.join(".")} needs an edge, for example @${n.path.join(".")}.right`,this.index);return{kind:"nodeRef",path:n.path}}case"word":{let[t,r,...o]=n.path;if(t===void 0||!St(t))throw new j(`Unknown name "${n.path.join(".")}". Use $token for a token or @id.edge for a node.`,this.index);if(r===void 0||!Re(r)||o.length>0)throw new j(`${t} needs an edge, for example ${t}.w`,this.index);return{kind:"relRef",word:t,edge:r}}case"op":{if(n.value==="("){let t=this.parseBinary(0),r=this.next();if(r.type!=="op"||r.value!==")")throw new j("Missing closing parenthesis",this.index);return t}throw new j(`Unexpected "${n.value}"`,this.index)}case"eof":throw new j("Unexpected end of expression",this.index)}}};function Xi(e){return e==="+"||e==="-"||e==="*"||e==="/"}function X(e,n){return`${e} ${n}`}function At(e){switch(e){case"x":case"left":return["x"];case"y":case"top":return["y"];case"w":return["w"];case"h":return["h"];case"right":case"cx":return["x","w"];case"bottom":case"cy":return["y","h"]}}function Nt(e,n,t,r,o){switch(e){case"x":case"left":return n;case"y":case"top":return t;case"w":return r;case"h":return o;case"right":return n+r;case"bottom":return t+o;case"cx":return n+r/2;case"cy":return t+o/2}}function It(e){switch(e){case"x":case"left":case"right":case"cx":return"x";case"y":case"top":case"bottom":case"cy":return"y";case"w":case"h":return}}function _t(e,n,t){let r=f=>{let p=[];for(let m=t.parentOf.get(f);m!==void 0;m=t.parentOf.get(m))p.push(m);return p},o=r(e),i=r(n),s=new Set(i),u=o.find(f=>s.has(f)),a=f=>u===void 0?f:f.slice(0,f.indexOf(u)),c=new Map([[e,1]]),d=(f,p)=>{let m=(c.get(f)??0)+p;m===0?c.delete(f):c.set(f,m)};for(let f of a(o))d(f,1);for(let f of a(i))d(f,-1);return c}function Pt(e){switch(e){case"right":case"bottom":return 1;case"cx":case"cy":return .5;default:return 0}}function Rn(e){if(e==="x"||e==="w")return"w";if(e==="y"||e==="h")return"h"}function Rt(e){let n=new Map,t=new Map,r=new Map,o=new Map,i=new Map,s=[];R(e.root,(f,p)=>{if(n.has(f.id)||n.set(f.id,f),s.push(f),p){t.set(f.id,p.id);let m=i.get(p.id)??[],x=p.type==="instance"?[p.id,...m]:m;x.length>0&&i.set(f.id,x)}P(f)&&f.children.forEach((m,x)=>{let k=f.children[x-1],l=f.children[x+1];k&&r.set(m.id,k.id),l&&o.set(m.id,l.id)})});let u=new Map;for(let f of s){let p=t.get(f.id);for(;p!==void 0;){let m=n.get(p);if(!m||!ke(m))break;p=t.get(p)}p!==void 0&&u.set(f.id,p)}let a=new Map,c=new Map,d=f=>{if(P(f)){if(!ke(f)){let p=jr(f);p.forEach((m,x)=>{let k=p[x-1],l=p[x+1];k&&a.set(m.id,k.id),l&&c.set(m.id,l.id)})}for(let p of f.children)d(p)}};return d(e.root),{rootId:e.root.id,byId:n,parentOf:t,prevOf:r,nextOf:o,layoutParentOf:u,layoutPrevOf:a,layoutNextOf:c,scopeOf:i,order:s}}function jr(e){let n=[];for(let t of e.children)P(t)&&ke(t)?n.push(...jr(t)):n.push(t);return n}function Dn(e,n,t){if(e.kind==="relRef"){let i=Ji(e.word,n,t);return i===void 0?{ok:!1,message:`${n} has no ${e.word}`}:{ok:!0,nodeId:i,edge:e.edge}}let r=e.path[e.path.length-1]??"",o=e.path.slice(0,-1).join(".");if(!Re(r))return{ok:!1,message:`"${r}" is not an edge of @${o}`};for(let i of t.scopeOf.get(n)??[]){let s=`${i}.${o}`;if(t.byId.has(s))return{ok:!0,nodeId:s,edge:r};let u=t.byId.get(i);if(u?.type==="instance"&&u.component===o)return{ok:!0,nodeId:i,edge:r}}return t.byId.has(o)?{ok:!0,nodeId:o,edge:r}:{ok:!1,message:`No node @${o}`}}function Ji(e,n,t){switch(e){case"self":return n;case"root":return t.rootId;case"parent":return t.layoutParentOf.get(n);case"prev":return t.layoutPrevOf.get(n);case"next":return t.layoutNextOf.get(n)}}function Dt(e){let n=[...Gn(e.root)],t=Rt(e),r=Gi(t),o=new Set;Ki(r,n),Yi(r,e,t,o,n);let i=qi(r);Zi(r,i,n);let s=Qi(r,i,e,t,o,n);return{nodes:ns(e.root,s,r,n),problems:n}}function Gi(e){let n=new Map;for(let t of e.order){let r=t;for(let o of Xe(t)){let i=r[o]??Hi(t,o,e);i!==void 0&&n.set(X(t.id,o),{nodeId:t.id,prop:o,value:i,deps:[]})}}return n}function Hi(e,n,t){if(!(e.type!=="instance"||n!=="w"&&n!=="h")&&t.byId.get(e.component)?.type==="frame")return q(`@${e.component}.${n}`)}function Ki(e,n){for(let t of e.values()){if(!B(t.value))continue;let r=Pn(t.value.expr);if(r.ok){t.ast=r.ast;continue}n.push({severity:"error",code:"expression-syntax",message:r.message,nodeId:t.nodeId,prop:t.prop})}}function Yi(e,n,t,r,o){for(let i of e.values()){if(!i.ast)continue;let s=new Set,u=a=>{switch(a.kind){case"number":return;case"token":{let c=F(n)[a.name];typeof c!="number"&&o.push({severity:"error",code:c===void 0?"unknown-token":"token-not-a-number",message:c===void 0?`Unknown token $${a.name}`:`Token $${a.name} is not a number`,nodeId:i.nodeId,prop:i.prop});return}case"percent":{let c=Rn(i.prop);if(!c)return;let d=t.layoutParentOf.get(i.nodeId),f=d===void 0?void 0:X(d,c);if(f===void 0||!e.has(f)){o.push({severity:"error",code:"percent-without-parent",message:`${i.nodeId}.${i.prop} uses a percentage but has no parent to measure against`,nodeId:i.nodeId,prop:i.prop});return}s.add(f);return}case"nodeRef":case"relRef":{let c=Dn(a,i.nodeId,t);if(!c.ok){r.add(a),o.push({severity:"error",code:"unknown-reference",message:c.message,nodeId:i.nodeId,prop:i.prop});return}let d=p=>{e.has(p)&&s.add(p)},f=It(c.edge);if(!f){for(let p of At(c.edge))d(X(c.nodeId,p));return}for(let p of _t(c.nodeId,i.nodeId,t).keys())d(X(p,f));Pt(c.edge)!==0&&d(X(c.nodeId,f==="x"?"w":"h"));return}case"unary":u(a.operand);return;case"binary":u(a.left),u(a.right);return}};u(i.ast),i.deps=[...s]}}function qi(e){let n=new Map,t=new Map;for(let[i,s]of e){n.set(i,s.deps.length);for(let u of s.deps){let a=t.get(u);a?a.push(i):t.set(u,[i])}}let r=[];for(let[i,s]of n)s===0&&r.push(i);let o=[];for(let i=0;i<r.length;i++){let s=r[i];o.push(s);for(let u of t.get(s)??[]){let a=(n.get(u)??0)-1;n.set(u,a),a===0&&r.push(u)}}return o}function Zi(e,n,t){if(n.length===e.size)return;let r=new Set(n);for(let[o,i]of e)r.has(o)||t.push({severity:"error",code:"cycle",message:`${i.nodeId}.${i.prop} is part of a dependency cycle`,nodeId:i.nodeId,prop:i.prop})}function Qi(e,n,t,r,o,i){let s=new Map,u=(a,c)=>s.get(X(a,c))??0;for(let a of n){let c=e.get(a);if(c){if(!B(c.value)){s.set(a,c.value);continue}if(!c.ast){s.set(a,0);continue}s.set(a,Cr(c.ast,c,t,r,o,i,u))}}return s}function Cr(e,n,t,r,o,i,s){let u=a=>Cr(a,n,t,r,o,i,s);switch(e.kind){case"number":return e.value;case"token":{let a=F(t)[e.name];return typeof a=="number"?a:0}case"percent":{let a=Rn(n.prop);if(!a)return e.value/100;let c=r.layoutParentOf.get(n.nodeId);return c===void 0?0:e.value/100*s(c,a)}case"nodeRef":case"relRef":{if(o.has(e))return 0;let a=Dn(e,n.nodeId,r);if(!a.ok)return 0;let c=It(a.edge);if(!c)return Nt(a.edge,s(a.nodeId,"x"),s(a.nodeId,"y"),s(a.nodeId,"w"),s(a.nodeId,"h"));let d=Pt(a.edge)*s(a.nodeId,c==="x"?"w":"h");for(let[f,p]of _t(a.nodeId,n.nodeId,r))d+=p*s(f,c);return d}case"unary":{let a=u(e.operand);return e.op==="-"?-a:a}case"binary":{let a=u(e.left),c=u(e.right);if(e.op==="/"&&c===0)return i.push({severity:"error",code:"divide-by-zero",message:`${n.nodeId}.${n.prop} divides by zero`,nodeId:n.nodeId,prop:n.prop}),0;let d=es(e.op,a,c);return Number.isFinite(d)?d:(i.push({severity:"error",code:"not-a-number",message:`${n.nodeId}.${n.prop} did not produce a finite number`,nodeId:n.nodeId,prop:n.prop}),0)}}}function es(e,n,t){switch(e){case"+":return n+t;case"-":return n-t;case"*":return n*t;case"/":return n/t}}function ns(e,n,t,r){let o=new Map,i=(u,a)=>n.get(X(u,a))??0,s=(u,a,c)=>{let d=i(u.id,"x"),f=i(u.id,"y"),p=i(u.id,"w"),m=i(u.id,"h"),x={};for(let O of Xe(u)){let M=X(u.id,O);t.has(M)&&(x[O]=n.get(M)??0)}(p<0||m<0)&&r.push({severity:"warning",code:"negative-size",message:`${u.id} resolved to a negative size`,nodeId:u.id});let k=a+d,l=c+f;if(o.set(u.id,{id:u.id,type:u.type,x:d,y:f,w:p,h:m,left:d,top:f,right:d+p,bottom:f+m,cx:d+p/2,cy:f+m/2,absX:k,absY:l,values:x}),P(u))for(let O of u.children)s(O,k,l)};return s(e,0,0),o}function Lt(e){return e.lines.filter(n=>n.spans.length>0)}function Cn(e){switch(e.kind){case"text":{let n=Lt(e),t=Math.max(e.w,...n.map(o=>o.w)),r=Math.max(e.y+e.h,...n.map(o=>o.y+o.h));return{x:e.x,y:e.y,w:t,h:r-e.y}}case"vector":{let n=Qn(e.contours)??{x:e.x,y:e.y,w:e.w,h:e.h},t=e.stroke!==void 0?e.strokeWidth*2:0;return{x:n.x-t,y:n.y-t,w:n.w+t*2,h:n.h+t*2}}case"rect":case"ellipse":{let n=e.stroke!==void 0?e.strokeWidth/2:0;return{x:e.x-n,y:e.y-n,w:e.w+n*2,h:e.h+n*2}}case"frame":case"image":return{x:e.x,y:e.y,w:e.w,h:e.h}}}function Vn(e,n){let t=e.x,r=e.y,o=e.x+e.w,i=e.y+e.h;for(let s of n){let u=s.spread+s.blur;t=Math.min(t,e.x+s.x-u),r=Math.min(r,e.y+s.y-u),o=Math.max(o,e.x+e.w+s.x+u),i=Math.max(i,e.y+e.h+s.y+u)}return{x:t,y:r,w:o-t,h:i-r}}var Br="vd-paint-";var jn="#CBD5E1",Ur="#FFFFFF";function Wr(e,n,t={}){let r=[...n.problems],o=[],i=[],s=t.measure??_n(),u=cs(F(e),r),a=u.paint,c=new Map,d=ce(e.root);R(e.root,(l,O)=>{if("hidden"in l&&l.hidden===!0)return!1;let M=O?c.get(O.id):void 0,T=n.nodes.get(l.id);if(!T){c.set(l.id,M);return}let A=l.type==="frame"?l:l.type==="instance"?d.get(l.component):void 0;if(l.type==="instance"&&!A){c.set(l.id,M);return}if(A){l.type==="frame"&&l.skip===!0&&O!==e.root&&r.push({severity:"warning",code:"skip-not-a-page",message:`${l.id}: skip only applies to a page, a frame at the top level`,nodeId:l.id,prop:"skip"});let $={x:T.absX,y:T.absY,w:Math.max(0,T.w),h:Math.max(0,T.h)};c.set(l.id,A.clip===!0?l.id:M),A.clip===!0&&i.push({id:l.id,...$,parent:M}),o.push({kind:"frame",id:l.id,...$,background:a(A.background,l.id,"background",$),clip:M,blend:A.blend??"normal",shadows:ye(A.shadow,l.id,F(e),r),rotation:0});return}if(c.set(l.id,M),l.type==="text"){o.push(rs(l,T,e,s,r,M,a));return}if(l.type==="image"){o.push({kind:"image",id:l.id,x:T.absX,y:T.absY,w:Math.max(0,T.w),h:Math.max(0,T.h),href:ls(l,e,t.resolveAsset,r),fit:l.fit??"fill",radius:Math.max(0,T.values.radius??0),opacity:Le(T.values.opacity??1),clip:M,blend:l.blend??"normal",shadows:ye(l.shadow,l.id,F(e),r),rotation:T.values.rotation??0});return}if(l.type==="ellipse"){let $=Fr(T);o.push({kind:"ellipse",id:l.id,...$,fill:a(l.fill,l.id,"fill",$)??jn,stroke:a(l.stroke,l.id,"stroke",$),strokeWidth:T.values.strokeWidth??0,opacity:Le(T.values.opacity??1),clip:M,blend:l.blend??"normal",shadows:ye(l.shadow,l.id,F(e),r),rotation:T.values.rotation??0});return}if(l.type==="vector"){o.push(as(l,T,r,M,a,ye(l.shadow,l.id,F(e),r)));return}if(l.type!=="rect")return;let N=Fr(T);o.push({kind:"rect",id:l.id,...N,fill:a(l.fill,l.id,"fill",N)??jn,stroke:a(l.stroke,l.id,"stroke",N),strokeWidth:T.values.strokeWidth??0,radius:Math.max(0,T.values.radius??0),opacity:Le(T.values.opacity??1),clip:M,blend:l.blend??"normal",shadows:ye(l.shadow,l.id,F(e),r),rotation:T.values.rotation??0})});let f=n.nodes.get(e.root.id),p=e.root.w!==void 0&&e.root.h!==void 0,m=p?{x:0,y:0,width:Math.max(0,f?.w??0),height:Math.max(0,f?.h??0)}:ts(o,i),x={x:m.x,y:m.y,w:m.width,h:m.height},k=a(e.root.background,e.root.id,"background",x);return{...m,background:p?k??Ur:k,items:o,clips:i,gradients:u.gradients,problems:r}}function ts(e,n){let t=new Map;for(let u of n){let a=u.parent===void 0?void 0:t.get(u.parent);t.set(u.id,a?Vr(u,a):u)}let r=1/0,o=1/0,i=-1/0,s=-1/0;for(let u of e){let a=u.kind==="text"&&Lt(u).length>0?Math.max(u.h,u.height):u.h,c=u.clip===void 0?void 0:t.get(u.clip),d=wt(Vn({x:u.x,y:u.y,w:u.w,h:a},u.shadows),u.rotation,Nn(u)),f=c?Vr(d,c):d;f.w<=0||f.h<=0||(r=Math.min(r,f.x),o=Math.min(o,f.y),i=Math.max(i,f.x+f.w),s=Math.max(s,f.y+f.h))}return Number.isFinite(r)?{x:r,y:o,width:i-r,height:s-o}:{x:0,y:0,width:0,height:0}}function Vr(e,n){let t=Math.max(e.x,n.x),r=Math.max(e.y,n.y);return{x:t,y:r,w:Math.min(e.x+e.w,n.x+n.w)-t,h:Math.min(e.y+e.h,n.y+n.h)-r}}function jt(e,n={}){return Wr(e,Dt(e),n)}function rs(e,n,t,r,o,i,s){let u=Math.max(0,n.w),a=Math.max(0,n.h),c={x:n.absX,y:n.absY,w:u,h:a},d=kt(e,n.values,u,t.fonts,m=>s(m,e.id,"fill",c)??In,r);!d.lines.every(m=>m.spans.length===0)&&d.height>a+.5&&o.push({severity:"warning",code:"text-overflow",message:`${e.id} needs ${Math.ceil(d.height)}px but its height is ${Math.round(a)}px`,nodeId:e.id,prop:"h"}),os(e,t,o);let p=n.absY+Et(e,a,d.height);return{kind:"text",id:e.id,x:n.absX,y:n.absY,w:u,h:a,clip:i,blend:e.blend??"normal",shadows:ye(e.shadow,e.id,F(t),o),rotation:n.values.rotation??0,opacity:Le(n.values.opacity??1),height:d.height,lines:d.lines.map(m=>({y:p+m.y,h:m.h,baseline:p+m.baseline,w:m.w,spans:m.spans.map(x=>({text:x.text,x:n.absX+x.x,y:p+m.baseline,w:x.w,style:x.style})),...m.style?{style:m.style}:{}}))}}function os(e,n,t){if(typeof e.content!="string")for(let r of e.content){if(typeof r=="string"||r.link===void 0)continue;let o=Y(r.link);if(!o){t.push({severity:"warning",code:"invalid-link",message:`${e.id}: links go to https:, mailto: or #<frame>, not ${JSON.stringify(r.link)}`,nodeId:e.id,prop:"content"});continue}o.kind==="frame"&&!is(n,o.id)&&t.push({severity:"warning",code:"link-target-missing",message:`${e.id}: links to #${o.id}, which is not a frame`,nodeId:e.id,prop:"content"})}}function is(e,n){let t=!1;return R(e.root,r=>{if(t)return!1;r.id===n&&r.type==="frame"&&(t=!0)}),t}var De=new Map,ss=512;function us(e){let n=De.get(e);if(n)return n;let t=Kn(e);return De.size>=ss&&De.delete(De.keys().next().value),De.set(e,t),t}function as(e,n,t,r,o,i){let s=Math.max(0,n.w),u=Math.max(0,n.h),a={x:n.absX,y:n.absY,w:s,h:u},{contours:c,error:d}=us(e.d);d!==void 0&&t.push({severity:"error",code:"bad-path",message:`${e.id}: ${d}`,nodeId:e.id,prop:"d"}),e.view!==void 0&&gn(e.view)===void 0&&t.push({severity:"warning",code:"bad-view",message:`${e.id}: view must be four numbers, like "0 0 24 24"`,nodeId:e.id,prop:"view"});let f=Zn(c,nt(et(e.view,s,u),a));return{kind:"vector",id:e.id,...a,d:Yn(f),contours:f,fill:o(e.fill,e.id,"fill",a)??jn,stroke:o(e.stroke,e.id,"stroke",a),strokeWidth:n.values.strokeWidth??0,opacity:Le(n.values.opacity??1),rule:e.rule??"nonzero",cap:e.cap??"butt",join:e.join??"miter",clip:r,blend:e.blend??"normal",shadows:i,rotation:n.values.rotation??0}}function zr(e,n,t,r,o){if(e===void 0)return;if(B(e)){o.push({severity:"warning",code:"expression-not-supported",message:`Expressions are not supported for ${r} yet; grammar v0 is numeric only`,nodeId:t,prop:r});return}let i=n[e];if(i===void 0)return e;if(typeof i=="string")return i;o.push({severity:"error",code:"token-not-a-colour",message:`Token $${e} is a number, not a colour`,nodeId:t,prop:r})}function Fr(e){return{x:e.absX,y:e.absY,w:Math.max(0,e.w),h:Math.max(0,e.h)}}function cs(e,n){let t=[],r=new Map;return{paint:(i,s,u,a)=>{let c=zr(i,e,s,u,n);if(c===void 0)return;if(/url\(/i.test(c)){n.push({severity:"error",code:"invalid-paint",message:`${s}: a paint is a colour or a gradient, not ${JSON.stringify(c)}`,nodeId:s,prop:u});return}let d=yt(c);if("error"in d){n.push({severity:"error",code:"invalid-paint",message:`${s}: ${d.error}`,nodeId:s,prop:u});return}if(d.kind==="solid")return c;let f=`${s}\0${u}\0${c}`,p=r.get(f);if(p!==void 0)return`url(#${p})`;let m=[...r.keys()].filter(l=>l.startsWith(`${s}\0${u}\0`)).length,x=`${Br}${s}-${u}${m===0?"":`-${m+1}`}`;r.set(f,x);let k=xt(d.stops).map(l=>({offset:l.at,colour:Xr(l.colour,e,s,u,n)}));return t.push(fs(d,x,a,ds(k))),`url(#${x})`},gradients:t}}function ye(e,n,t,r){let o=zr(e,t,n,"shadow",r);if(o===void 0)return[];let i=bt(o);return"error"in i?(r.push({severity:"error",code:"invalid-shadow",message:`${n}: ${i.error}`,nodeId:n,prop:"shadow"}),[]):i.shadows.map(s=>({...s,colour:Xr(s.colour,t,n,"shadow",r)}))}function ds(e){return e.map((n,t)=>{if(n.colour.trim().toLowerCase()!=="transparent")return n;let r=[e[t-1],e[t+1]].find(o=>o!==void 0&&o.colour.trim().toLowerCase()!=="transparent");return r===void 0?n:{offset:n.offset,colour:r.colour,opacity:0}})}function Xr(e,n,t,r,o){let i=n[e];return i===void 0?e:typeof i=="string"&&!An(i)?i:(o.push({severity:"error",code:"invalid-paint",message:`${t}: a gradient stop names $${e}, which is not a colour`,nodeId:t,prop:r}),"transparent")}function fs(e,n,t,r){if(e.kind==="linear"){let c=e.angle*Math.PI/180,d=Math.sin(c),f=-Math.cos(c),p=(Math.abs(t.w*d)+Math.abs(t.h*f))/2,m=t.x+t.w/2,x=t.y+t.h/2;return{id:n,kind:"linear",x1:Ln(m-d*p),y1:Ln(x-f*p),x2:Ln(m+d*p),y2:Ln(x+f*p),stops:r}}let o=t.x+t.w*e.cx,i=t.y+t.h*e.cy,s={x:Math.max(o-t.x,t.x+t.w-o),y:Math.max(i-t.y,t.y+t.h-i)};if(e.shape==="circle"||s.x===0||s.y===0){let c=Math.hypot(s.x,s.y);return{id:n,kind:"radial",cx:o,cy:i,rx:c,ry:c,stops:r}}let u=s.x/s.y,a=Math.hypot(s.x/u,s.y);return{id:n,kind:"radial",cx:o,cy:i,rx:a*u,ry:a,stops:r}}function Ln(e){return Math.round(e*1e6)/1e6}function Le(e){return Math.min(Math.max(e,0),1)}function ls(e,n,t,r){let o=B(e.src)?void 0:e.src,i=o===void 0?void 0:n.assets[o];if(!i){r.push({severity:"warning",code:"missing-asset",message:`No picture for ${JSON.stringify(o??e.src)} yet: an image slot waiting for one`,nodeId:e.id,prop:"src"});return}let s=t?.(i,o);return s===void 0&&r.push({severity:"warning",code:"unresolved-asset",message:`The bytes for asset "${o}" are not available here`,nodeId:e.id,prop:"src"}),s}var je="vd-clip-";function Vt(e,n={}){let t=n.indent??" ",r={ids:n.ids??!0,prefix:n.idPrefix??""},o=y(e.width),i=y(e.height),s=`${y(e.x)} ${y(e.y)} ${o} ${i}`,u=[`<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${i}" viewBox="${s}">`],a=e.items.filter(c=>c.shadows.length>0);if(e.clips.length>0||e.gradients.length>0||a.length>0){u.push(`${t}<defs>`);for(let c of e.clips)u.push(t+t+Jr(c,r.prefix));for(let c of e.gradients)u.push(t+t+Gr(c,r.prefix));for(let c of a)u.push(t+t+Hr(c,n.shadowsOnly,r.prefix));u.push(`${t}</defs>`)}e.background!==void 0&&u.push(`${t}<rect x="${y(e.x)}" y="${y(e.y)}" width="${o}" height="${i}" fill="${I(oe(e.background,r))}"/>`);for(let c of e.items){let d=xs(c,r);d!==""&&u.push(t+d)}return u.push("</svg>"),`${u.join(`
|
|
9
|
-
`)}
|
|
10
|
-
`}function ps(e){return Jr(e,"")}function Jr(e,n){let t=e.parent===void 0?"":` clip-path="url(#${I(n+je+e.parent)})"`;return`<clipPath id="${I(n+je+e.id)}"${t}><rect x="${y(e.x)}" y="${y(e.y)}" width="${y(e.w)}" height="${y(e.h)}"/></clipPath>`}function hs(e){return Gr(e,"")}function Gr(e,n){let t=e.stops.map(o=>`<stop offset="${y(o.offset)}" stop-color="${I(o.colour)}"${o.opacity===void 0?"":` stop-opacity="${y(o.opacity)}"`}/>`).join(""),r=I(n+e.id);return e.kind==="linear"?`<linearGradient id="${r}" gradientUnits="userSpaceOnUse" x1="${y(e.x1)}" y1="${y(e.y1)}" x2="${y(e.x2)}" y2="${y(e.y2)}">${t}</linearGradient>`:`<radialGradient id="${r}" gradientUnits="userSpaceOnUse" cx="0" cy="0" r="1" gradientTransform="matrix(${y(e.rx)} 0 0 ${y(e.ry)} ${y(e.cx)} ${y(e.cy)})">${t}</radialGradient>`}var ms={cover:"xMidYMid slice",contain:"xMidYMid meet",fill:"none"},gs="#94A3B8";function re(e,n){let t=e.clip===void 0?[]:[`clip-path="url(#${I(n+je+e.clip)})"`];return e.rotation!==0&&t.push(`transform="${Kr(e)}"`),e.shadows.length>0&&t.push(`filter="url(#${I(n+Ft+e.id)})"`),e.blend!=="normal"&&t.push(`style="mix-blend-mode:${e.blend}"`),t}var Ft="vd-shadow-";function ys(e,n=!1){return Hr(e,n,"")}function Hr(e,n,t){let r=Vn(Cn(e),e.shadows),o=2,i=[];e.shadows.forEach((u,a)=>{let c=`s${a}`,d="SourceAlpha";u.spread!==0&&(i.push(`<feMorphology in="${d}" operator="${u.spread>0?"dilate":"erode"}" radius="${y(Math.abs(u.spread))}" result="${c}m"/>`),d=`${c}m`),u.blur>0&&(i.push(`<feGaussianBlur in="${d}" stdDeviation="${y(u.blur/2)}" result="${c}b"/>`),d=`${c}b`),i.push(`<feOffset in="${d}" dx="${y(u.x)}" dy="${y(u.y)}" result="${c}o"/>`,`<feFlood flood-color="${I(u.colour)}" result="${c}c"/>`,`<feComposite in="${c}c" in2="${c}o" operator="in" result="${c}"/>`)});let s=e.shadows.map((u,a)=>`<feMergeNode in="s${e.shadows.length-1-a}"/>`).join("");return`<filter id="${I(t+Ft+e.id)}" filterUnits="userSpaceOnUse" x="${y(r.x-o)}" y="${y(r.y-o)}" width="${y(r.w+o*2)}" height="${y(r.h+o*2)}" color-interpolation-filters="sRGB">`+i.join("")+`<feMerge>${s}${n?"":'<feMergeNode in="SourceGraphic"/>'}</feMerge></filter>`}function Kr(e){return`rotate(${y(e.rotation)} ${y(e.x+e.w/2)} ${y(e.y+e.h/2)})`}function Yr(e){return e.rotation!==0&&e.clip!==void 0}function xs(e,n){if(e.pose!==void 0)return bs(e,e.pose,n);if(Yr(e)){let t=[`clip-path="url(#${I(n.prefix+je+e.clip)})"`];e.blend!=="normal"&&t.push(`style="mix-blend-mode:${e.blend}"`);let r=Ct({...e,clip:void 0,blend:"normal"},n);return r===""?"":`<g ${t.join(" ")}>${r}</g>`}return Ct(e,n)}function bs(e,n,t){let r=Ct({...e,clip:void 0,blend:"normal",shadows:e.shadows},t);if(r==="")return"";let o=[];e.clip!==void 0&&o.push(`clip-path="url(#${I(t.prefix+je+e.clip)})"`),n.opacity<1&&o.push(`opacity="${y(n.opacity)}"`),e.blend!=="normal"&&o.push(`style="mix-blend-mode:${e.blend}"`);let i=n.sx===1&&n.sy===1&&n.tx===0&&n.ty===0?r:`<g transform="${qr(n)}">${r}</g>`;return o.length===0?i:`<g ${o.join(" ")}>${i}</g>`}function qr(e){return`matrix(${y(e.sx)} 0 0 ${y(e.sy)} ${y(e.tx)} ${y(e.ty)})`}function Ct(e,n){switch(e.kind){case"ellipse":return ks(e,n);case"frame":return ws(e,n);case"image":return $s(e,n);case"rect":return vs(e,n);case"text":return Ss(e,n);case"vector":return Es(e,n)}}function oe(e,n){return/url\(/i.test(e)&&!e.startsWith("url(#")?"none":n.prefix!==""&&e.startsWith("url(#")?`url(#${n.prefix}${e.slice(5)}`:e}function ws(e,n){let t=[];return n.ids&&t.push(`id="${I(e.id)}"`),t.push(`x="${y(e.x)}"`,`y="${y(e.y)}"`,`width="${y(e.w)}"`,`height="${y(e.h)}"`,`fill="${e.background===void 0?"none":I(oe(e.background,n))}"`,...re(e,n.prefix)),`<rect ${t.join(" ")}/>`}function $s(e,n){let t=[];return n.ids&&t.push(`id="${I(e.id)}"`),t.push(`x="${y(e.x)}"`,`y="${y(e.y)}"`,`width="${y(e.w)}"`,`height="${y(e.h)}"`),e.href===void 0?(e.radius>0&&t.push(`rx="${y(e.radius)}"`),t.push('fill="none"',`stroke="${I(gs)}"`,'stroke-width="1"','stroke-dasharray="4 4"',...re(e,n.prefix)),`<rect ${t.join(" ")}/>`):(t.push(`href="${I(e.href)}"`,`preserveAspectRatio="${ms[e.fit]}"`),e.opacity<1&&t.push(`opacity="${y(e.opacity)}"`),t.push(...re(e,n.prefix)),`<image ${t.join(" ")}/>`)}function vs(e,n){let t=[];return n.ids&&t.push(`id="${I(e.id)}"`),t.push(`x="${y(e.x)}"`,`y="${y(e.y)}"`,`width="${y(e.w)}"`,`height="${y(e.h)}"`),e.radius>0&&t.push(`rx="${y(e.radius)}"`),t.push(`fill="${I(oe(e.fill,n))}"`),e.stroke!==void 0&&e.strokeWidth>0&&t.push(`stroke="${I(oe(e.stroke,n))}"`,`stroke-width="${y(e.strokeWidth)}"`),e.opacity<1&&t.push(`opacity="${y(e.opacity)}"`),t.push(...re(e,n.prefix)),`<rect ${t.join(" ")}/>`}function Zr(e,n){let t=[`fill="${I(oe(e.fill,n))}"`];return e.stroke!==void 0&&e.strokeWidth>0&&t.push(`stroke="${I(oe(e.stroke,n))}"`,`stroke-width="${y(e.strokeWidth)}"`),e.opacity<1&&t.push(`opacity="${y(e.opacity)}"`),t}function ks(e,n){let t=[];return n.ids&&t.push(`id="${I(e.id)}"`),t.push(`cx="${y(e.x+e.w/2)}"`,`cy="${y(e.y+e.h/2)}"`,`rx="${y(e.w/2)}"`,`ry="${y(e.h/2)}"`,...Zr(e,n),...re(e,n.prefix)),`<ellipse ${t.join(" ")}/>`}function Es(e,n){if(e.d==="")return"";let t=[];n.ids&&t.push(`id="${I(e.id)}"`),t.push(`d="${I(e.d)}"`,...Zr(e,n));let r=e.pose?.trace;if(r!==void 0&&e.stroke!==void 0){let i=y(yn(e.contours)+1);t.push(`stroke-dasharray="${i} ${i}"`,`stroke-dashoffset="${y((yn(e.contours)+1)*(1-r))}"`)}let o=e.pose?.fillOpacity;return o!==void 0&&o<1&&t.push(`fill-opacity="${y(o)}"`),e.rule!=="nonzero"&&t.push(`fill-rule="${e.rule}"`),e.cap!=="butt"&&t.push(`stroke-linecap="${e.cap}"`),e.join!=="miter"&&t.push(`stroke-linejoin="${e.join}"`),t.push(...re(e,n.prefix)),`<path ${t.join(" ")}/>`}function Ss(e,n){if(e.lines.every(o=>o.spans.length===0))return"";let t=[];n.ids&&t.push(`id="${I(e.id)}"`),t.push('xml:space="preserve"'),e.opacity<1&&t.push(`opacity="${y(e.opacity)}"`),t.push(...re(e,n.prefix));let r=[];for(let o of e.lines)for(let i of o.spans)i.text!==""&&r.push(Os(i,n));return`<text ${t.join(" ")}>${r.join("")}</text>`}function Os(e,n){let r=`<tspan ${[`x="${y(e.x)}"`,`y="${y(e.y)}"`,...Ms(e.style,n)].join(" ")}>${Ts(e.text)}</tspan>`;return e.style.link===void 0?r:`<a href="${I(e.style.link)}">${r}</a>`}function Ms(e,n){let t=[`font-family="${I(e.family)}"`,`font-size="${y(e.size)}"`,`fill="${I(oe(e.fill,n))}"`];e.weight!==400&&t.push(`font-weight="${y(e.weight)}"`),e.italic&&t.push('font-style="italic"'),e.letterSpacing!==0&&t.push(`letter-spacing="${y(e.letterSpacing)}"`);let r=[e.underline?"underline":"",e.strike?"line-through":""].filter(Boolean).join(" ");return r&&t.push(`text-decoration="${r}"`),t}function Ts(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function I(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Lf(e,n={}){let{resolveAsset:t,measure:r,...o}=n;return Vt(jt(e,{...t?{resolveAsset:t}:{},...r?{measure:r}:{}}),o)}export{R as a,W as b,Y as c,ee as d,Oe as e,Qt as f,ge as g,er as h,fn as i,ln as j,yn as k,ko as l,eo as m,no as n,to as o,ro as p,Qo as q,hi as r,mi as s,vr as t,kr as u,ki as v,Ei as w,Si as x,Or as y,Dt as z,_n as A,Wr as B,jt as C,Vt as D,ps as E,hs as F,Ft as G,ys as H,Kr as I,Yr as J,qr as K,Lf as L};
|