@johnoscott/isometric-engine 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/iso-remotion.js CHANGED
@@ -237,7 +237,7 @@ ${e.css}`),o=cc(s);Rs(o,"font-family",n.sans.replace(/"/g,""));let t=(a,d)=>{let
237
237
  ${o}`}:{},from:n.index+n[0].length})}return e}var wl=new WeakMap;function Wc(s,e){let r=wl.get(s)??new Map;wl.set(s,r);let n=r.get(e);if(!n){r.set(e,n=new Map);let i=s.variants?.[e],o=ra(s.svg);if(i!==void 0)for(let[t,[a,d]]of ra(i)){let c=o.get(t);c&&s.looks?.[t.split(`
238
238
  `)[0]]?.includes(e)&&s.svg.slice(...c)!==i.slice(a,d)&&n.set(t,i.slice(a,d))}}return n}function Gc(s,e,r,n){let i=[];for(let o of s.looks?.[e]??[]){let t=vt(n[o]??0),a=t>0?Wc(s,o).get(`${e}
239
239
  ${r}`):void 0;a!==void 0&&i.push([a,t])}return i.length?{own:vt(1-i.reduce((o,[,t])=>o+t,0)),looks:i}:void 0}var Jc=(s,e)=>(e.own>0?`<g opacity="${as(e.own)}">${s}</g>`:"")+e.looks.map(([r,n])=>`<g opacity="${as(n)}">${r}</g>`).join("");function Hc(s,e){let r="",n=0;for(let[i,[o,t]]of[...ra(s.svg)].sort((a,d)=>a[1][0]-d[1][0])){let[a,d]=i.split(`
240
- `),c=Object.hasOwn(e,a)?Gc(s,a,d,e[a]):void 0;c&&(r+=s.svg.slice(n,o)+Jc(s.svg.slice(o,t),c),n=t)}return r+s.svg.slice(n)}function vl(s,e){if(Uc(e))return s.rendered.svg;let r=e.variants?Hc(s.rendered,e.variants):s.rendered.svg,n=l=>Object.hasOwn(s.rendered.paths,l)?s.rendered.paths[l]:void 0,i=0,o="",t="",a=0,d,c=r.replace(/<(\/?)([a-zA-Z]+)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|([^<]+)/g,(l,f,m,h,y,g)=>{if(g!==void 0)return d?.w.typed===void 0?l:Bc(g,d.w.typed);if(f)return i--,d&&i===d.at&&(d=void 0),i===1&&(o=""),l;let k=i;y||i++;let u={};for(let[,b,x]of h.matchAll(/([\w:-]+)="([^"]*)"/g))u[b]=x;if(k===0){if(!e.camera)return l;u.viewBox=e.camera.map(ze).join(" ")}else if(k===1)if(o=m==="g"&&u.class?.startsWith("g-")?u.class.slice(2):"",Yc.has(o)&&e.marks&&e.marks.opacity!==1)u.opacity=as(e.marks.opacity);else return l;else if(k===2&&u["data-part"]!==void 0){let b=u["data-route"]===void 0?"item":"route",x=Ol(u["data-route"]??u["data-item"]??""),$=Zc(e,b,x,u["data-part"],n);if(!$)return l;for(let[P,T]of Object.entries($.attrs))u[P]=bl(T);if($.clip){let P=`${s.id}-mc${a++}`;t+=`<clipPath id="${P}"><polygon points="${$.clip.map(T=>T.join(",")).join(" ")}"/></clipPath>`,u["clip-path"]=`url(#${P})`}if(!y&&($.path||$.typed!==void 0)&&(d={at:k,w:$}),!Object.keys($.attrs).length&&!$.clip)return l}else if(d?.w.path&&m==="path"&&u.class?.split(" ")[0]==="flow"){let b=d.w.path;b.d!==void 0&&(u.d=b.d),b.style!==void 0&&(u.style=b.style),b.head||delete u["marker-end"]}else return l;return`<${m}${Object.entries(u).map(([b,x])=>` ${b}="${x}"`).join("")}${y?"/":""}>`});t&&(c=c.replace(/<defs>|<defs\/>/,l=>l==="<defs/>"?`<defs>${t}</defs>`:l+t));let p=Vc(e,n,s.rendered.inks);return p.length&&(c=c.replace('<g class="g-anim">',l=>l+p.map(([f,m])=>`<${f}${Object.entries(m).map(([h,y])=>` ${h}="${bl(y)}"`).join("")}/>`).join(""))),c}var Ol=s=>s.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&amp;/g,"&");function Al(s,e){if(!e)return s;let[r,n,i,o]=e,t=s[2]/s[3],a=i-r,d=o-n;a/d<t?a=d*t:d=a/t,a=Math.min(a,s[2]),d=Math.min(d,s[3]);let c=(r+i)/2,p=(n+o)/2,l=Math.max(s[0],Math.min(s[0]+s[2]-a,c-a/2)),f=Math.max(s[1],Math.min(s[1]+s[3]-d,p-d/2));return[l,f,a,d]}var Xc=["linear","ease","ease-in","ease-out","ease-in-out","settle","bounce"],Ml=["extend","clamp","wrap","identity"];function ct(s,e){if(typeof s=="number")return Number.isFinite(s)?s:void 0;if(typeof s!="string")return;let r=/^(-?\d+(?:\.\d+)?)(ms|s|f)?$/.exec(s.trim());if(!r)return;let n=Number(r[1]);return r[2]==="s"?n*1e3:r[2]==="f"?e?n/e*1e3:void 0:n}function la(s,e){let r=e===!0?{}:e,n=r.base??2600,i=r.perChar??40,o=r.min??5600,t=r.max??12500;return Math.max(o,Math.min(t,n+(s?.text??"").length*i))}var _s=(s,e,r,n)=>i=>{if(i<=0)return 0;if(i>=1)return 1;let o=(d,c,p)=>3*d*p*(1-p)**2+3*c*p*p*(1-p)+p**3,t=0,a=1;for(let d=0;d<50;d++){let c=(t+a)/2;o(s,r,c)<i?t=c:a=c}return o(e,n,(t+a)/2)},Qc=s=>{if(s<=0)return 0;if(s>=1)return 1;let e=7.5625,r=2.75;return s<1/r?e*s*s:s<2/r?e*(s-1.5/r)**2+.75:s<2.5/r?e*(s-2.25/r)**2+.9375:e*(s-2.625/r)**2+.984375},ef={linear:s=>s,ease:_s(.25,.1,.25,1),"ease-in":_s(.42,0,1,1),"ease-out":_s(0,0,.58,1),"ease-in-out":_s(.42,0,.58,1),settle:_s(.16,.84,.3,1),bounce:Qc};function jn(s,e={}){let r=e.mass??1,n=e.stiffness??100,i=e.damping??10,o=Math.max(0,s)/1e3,t=Math.sqrt(n/r),a=i/(2*Math.sqrt(n*r)),d;if(a<1){let c=t*Math.sqrt(1-a*a);d=1-Math.exp(-a*t*o)*(Math.cos(c*o)+a*t/c*Math.sin(c*o))}else d=1-Math.exp(-t*o)*(1+t*o);return e.overshootClamping?Math.min(1,d):d}function Yt(s,e,r="ease-in-out"){let n=s??r;return typeof n=="string"?ef[n]:"bezier"in n?_s(...n.bezier):i=>i<=0?0:i>=1?1:jn(i*e,n.spring)}function Rn(s,e,r){let n=s.times.map(l=>ct(l,r)),i=s.values,o=n.length;if(o===1)return i[0];let t=(l,f)=>{if(l==="clamp")return f?i[0]:i[o-1];if(l==="identity")return e;if(l==="wrap"){let m=n[o-1]-n[0];return Rn({...s,extrapolateLeft:"clamp",extrapolateRight:"clamp"},n[0]+((e-n[0])%m+m)%m,r)}};if(e<n[0]){let l=t(s.extrapolateLeft??"extend",!0);if(l!==void 0)return l}if(e>n[o-1]){let l=t(s.extrapolateRight??"extend",!1);if(l!==void 0)return l}let a=0;for(;a<o-2&&e>=n[a+1];)a++;let d=n[a+1]-n[a],c=(e-n[a])/d,p=c<0||c>1?c:Yt(s.easing,d,"linear")(c);return i[a]+(i[a+1]-i[a])*p}var oa=["sequence","series","layers","assemble","disassemble","travel","pulse","ants","draw","type","move","lift","focus","highlight","camera"],Nl={morph:"the 2D morph is a later version's",diff:"diffs are a later version's",switch:"a look is a beat's: its variants"},Ot=["from","duration","easing"],hr={sequence:[],series:[],layers:[],assemble:Ot,disassemble:Ot,travel:[...Ot,"each","hold","loop"],pulse:[...Ot,"loop"],ants:[...Ot,"speed","dash"],draw:[...Ot,"by","stagger"],type:Ot,move:["from","x","y","scale","opacity"],lift:[...Ot,"by","stagger","to","opacity"],focus:[...Ot,"fade"],highlight:[...Ot,"fade"],camera:Ot},tf=["name","from","offset","duration","loop","playbackRate","trimBefore","say","show","hide","focus","highlight","levels","variants","enter","ants","children","layers","series"],Te=s=>!!s&&typeof s=="object"&&!Array.isArray(s);function zl(s){let e=[],r=(u,b,x)=>{e.push({severity:"error",path:u,message:b,...x?{hint:x}:{}})},n=(u,b,x)=>{for(let $ of Object.keys(u))if(!b.includes($)){let P=Ye($,b);r(`${x}/${$}`,`unknown key "${$}"`,P?`did you mean "${P}"?`:void 0)}};if(!Te(s))return r("","a motion document is a map"),e;n(s,["isomotion","fps","seed","ambient","series","layers","markers"],""),s.isomotion!==1&&r("/isomotion","isomotion is 1");let i=typeof s.fps=="number"&&s.fps>0?s.fps:void 0;s.fps!==void 0&&i===void 0&&r("/fps","fps is a number over 0"),s.seed!==void 0&&!Number.isInteger(s.seed)&&r("/seed","seed is a whole number"),s.ambient!==void 0&&s.ambient!=="on"&&s.ambient!=="off"&&r("/ambient",'ambient is "on" or "off"');let o=(u,b,x={})=>{if(u===void 0)return;if(typeof u=="string"&&/f$/.test(u)&&i===void 0){r(b,`"${u}" is in frames: the document needs its fps`);return}let $=ct(u,i);$===void 0?r(b,`${JSON.stringify(u)} isn't a time (ms, "1.2s", "450ms", "30f")`):$<0&&!x.negative&&r(b,"a time can't be negative")},t=(u,b,x)=>{if(u!==void 0&&!b.includes(u)){let $=typeof u=="string"?Ye(u,b):void 0;r(x,`${JSON.stringify(u)} isn't one of ${b.join(", ")}`,$?`did you mean "${$}"?`:void 0)}},a=(u,b,x={})=>{u!==void 0&&(typeof u!="number"||!Number.isFinite(u)||x.min!==void 0&&u<x.min||x.max!==void 0&&u>x.max||x.over!==void 0&&u<=x.over)&&r(b,`${JSON.stringify(u)} isn't a number${x.over!==void 0?` over ${x.over}`:x.min!==void 0?` from ${x.min}${x.max!==void 0?` to ${x.max}`:""}`:""}`)},d=(u,b)=>{if(u!==void 0){if(!Array.isArray(u)){r(b,"a list of ids");return}u.forEach((x,$)=>{typeof x!="string"&&r(`${b}/${$}`,"an id")})}},c=(u,b,x=[])=>{if(!Te(u)){r(b,"a spring is a map");return}n(u,["mass","damping","stiffness","overshootClamping",...x],b);for(let $ of["mass","damping","stiffness"])a(u[$],`${b}/${$}`,{over:0});u.overshootClamping!==void 0&&typeof u.overshootClamping!="boolean"&&r(`${b}/overshootClamping`,"true or false")},p=(u,b)=>{if(u!==void 0){if(typeof u=="string"){t(u,Xc,b);return}if(Te(u)&&"bezier"in u){n(u,["bezier"],b),(!Array.isArray(u.bezier)||u.bezier.length!==4||u.bezier.some(x=>typeof x!="number"))&&r(`${b}/bezier`,"four numbers");return}if(Te(u)&&"spring"in u){n(u,["spring"],b),c(u.spring,`${b}/spring`);return}r(b,"an easing is a name, { bezier: [a, b, c, d] } or { spring: { \u2026 } }")}},l=(u,b)=>{if(u===void 0)return;if(!Te(u)){r(b,"a curve is { times, values }");return}n(u,["times","values","easing","extrapolateLeft","extrapolateRight"],b);let x=u.times,$=u.values;if(!Array.isArray(x)||!x.length)r(`${b}/times`,"a list of times");else{x.forEach((T,M)=>o(T,`${b}/times/${M}`,{negative:!0}));let P=x.map(T=>ct(T,i));for(let T=1;T<P.length;T++)P[T]!==void 0&&P[T-1]!==void 0&&P[T]<=P[T-1]&&r(`${b}/times/${T}`,"times go up")}!Array.isArray($)||$.some(P=>typeof P!="number")?r(`${b}/values`,"a list of numbers"):Array.isArray(x)&&$.length!==x.length&&r(`${b}/values`,`${$.length} values for ${x.length} times`),p(u.easing,`${b}/easing`),t(u.extrapolateLeft,Ml,`${b}/extrapolateLeft`),t(u.extrapolateRight,Ml,`${b}/extrapolateRight`)},f=(u,b)=>{if(u!==void 0){if(!Te(u)){r(b,"focus is { lit: [ids] }");return}n(u,["lit","scope","level","always"],b),u.lit===void 0&&r(`${b}/lit`,"what is lit"),d(u.lit,`${b}/lit`),d(u.always,`${b}/always`),t(u.scope,["all","links"],`${b}/scope`),a(u.level,`${b}/level`,{min:0,max:1})}},m=(u,b)=>{u!==void 0&&typeof u!="string"&&r(b,"text")},h=new Map;function y(u,b,x){if(!Te(u)){r(b,"a sequence is a map");return}if(n(u,tf,b),u.name!==void 0&&(typeof u.name!="string"||!/^[A-Za-z][\w-]*$/.test(u.name)?r(`${b}/name`,"a name is letters, digits, - and _, from a letter"):h.has(u.name)?r(`${b}/name`,`"${u.name}" is already a name (${h.get(u.name)})`):h.set(u.name,b)),x&&u.from!==void 0&&r(`${b}/from`,"in a series a sequence follows the one before","offset moves it"),!x&&u.offset!==void 0&&r(`${b}/offset`,"offset is for a series","use from"),o(u.from,`${b}/from`),o(u.offset,`${b}/offset`,{negative:!0}),o(u.trimBefore,`${b}/trimBefore`),Te(u.duration)){n(u.duration,["read"],`${b}/duration`);let $=u.duration.read;if($!==!0&&!Te($))r(`${b}/duration/read`,"true, or { base, perChar, min, max }");else if(Te($)){n($,["base","perChar","min","max"],`${b}/duration/read`);for(let P of["base","perChar","min","max"])a($[P],`${b}/duration/read/${P}`,{min:0})}}else o(u.duration,`${b}/duration`);if(u.loop!==void 0&&typeof u.loop!="boolean"&&!(Number.isInteger(u.loop)&&u.loop>=1)&&r(`${b}/loop`,"true, false, or how many times"),a(u.playbackRate,`${b}/playbackRate`,{over:0}),u.say!==void 0)if(!Te(u.say))r(`${b}/say`,"say is a map");else{let $=u.say;n($,["chapter","title","text","code","facts","color"],`${b}/say`);for(let P of["chapter","title","text","code","color"])m($[P],`${b}/say/${P}`);$.facts!==void 0&&(!Array.isArray($.facts)||$.facts.some(P=>!Array.isArray(P)||P.length!==2||P.some(T=>typeof T!="string")))&&r(`${b}/say/facts`,"a list of [name, value]")}for(let $ of["show","hide","highlight"])d(u[$],`${b}/${$}`);if(f(u.focus,`${b}/focus`),u.levels!==void 0)if(!Te(u.levels))r(`${b}/levels`,"levels is a map: an id, and how much of it");else for(let[$,P]of Object.entries(u.levels))a(P,`${b}/levels/${$}`,{min:0,max:1});if(u.variants!==void 0)if(!Te(u.variants))r(`${b}/variants`,"variants is a map: an id, and the name of its look");else for(let[$,P]of Object.entries(u.variants))typeof P!="string"&&r(`${b}/variants/${$}`,`a look's name, or "" for its own`);u.enter!==void 0&&(Te(u.enter)?(n(u.enter,["fade","easing"],`${b}/enter`),u.enter.fade===void 0&&r(`${b}/enter/fade`,"how long the fade is"),o(u.enter.fade,`${b}/enter/fade`),p(u.enter.easing,`${b}/enter/easing`)):r(`${b}/enter`,"enter is { fade }")),u.ants!==void 0&&typeof u.ants!="boolean"&&d(u.ants,`${b}/ants`);for(let $ of["children","layers"])u[$]!==void 0&&k(u[$],`${b}/${$}`);u.series!==void 0&&g(u.series,`${b}/series`)}function g(u,b){if(!Array.isArray(u)){r(b,"a series is a list");return}u.forEach((x,$)=>{let P=`${b}/${$}`;if(!Te(x)||Object.keys(x).length!==1||!("sequence"in x||"transition"in x)){r(P,"a series holds sequences and transitions");return}if("sequence"in x){y(x.sequence,`${P}/sequence`,!0);return}let T=x.transition,M=`${P}/transition`,B=E=>Te(u[E])&&"sequence"in u[E];if((!B($-1)||!B($+1))&&r(M,"a transition is between two sequences"),!Te(T)){r(M,"a transition is { presentation, timing }");return}n(T,["presentation","timing"],M),T.presentation===void 0?r(`${M}/presentation`,"a presentation"):t(T.presentation,["fade","none"],`${M}/presentation`),Te(T.timing)?"linear"in T.timing?(n(T.timing,["linear"],`${M}/timing`),o(T.timing.linear,`${M}/timing/linear`)):"spring"in T.timing?(n(T.timing,["spring"],`${M}/timing`),c(T.timing.spring,`${M}/timing/spring`,["duration"]),Te(T.timing.spring)&&o(T.timing.spring.duration,`${M}/timing/spring/duration`)):r(`${M}/timing`,"a timing is { linear } or { spring }"):r(`${M}/timing`,"a timing is { linear } or { spring }")})}function k(u,b){if(!Array.isArray(u)){r(b,"a list");return}u.forEach((x,$)=>{let P=`${b}/${$}`;if(!Te(x)){r(P,"a map");return}let T=oa.filter(D=>D in x);if(T.length!==1){let D=Object.keys(x).find(S=>S in Nl),v=Object.keys(x)[0],O=v?Ye(v,oa):void 0;r(P,D?`${D}: ${Nl[D]}`:T.length?`one of ${T.join(", ")}, not several`:`one of ${oa.join(", ")}`,!D&&!T.length&&O?`did you mean "${O}"?`:void 0);return}let M=T[0],B=x[M],E=`${P}/${M}`;n(x,[M,...hr[M]],P),hr[M].includes("from")&&o(x.from,`${P}/from`),hr[M].includes("duration")&&(o(x.duration,`${P}/duration`),p(x.easing,`${P}/easing`));for(let D of["each","hold","stagger","fade"])hr[M].includes(D)&&o(x[D],`${P}/${D}`);if(hr[M].includes("loop")&&x.loop!==void 0&&typeof x.loop!="boolean"&&r(`${P}/loop`,"true or false"),M==="sequence")y(B,E,!1);else if(M==="series")g(B,E);else if(M==="layers")k(B,E);else if(M==="assemble"||M==="disassemble")Te(B)?(t(B.style,M==="assemble"?kl:xl,`${E}/style`),t(B.order,$l,`${E}/order`),B.duration!==void 0&&r(`${E}/duration`,"its length is beside it","duration is the node's")):r(E,`${M} is a map (its options)`);else if(M==="travel")!Array.isArray(B)||!B.length?r(E,"a list of connectors"):B.forEach((D,v)=>{Array.isArray(D)?d(D,`${E}/${v}`):typeof D!="string"&&r(`${E}/${v}`,"a connector, or a list of them at once")});else if(M==="ants")B!==!0&&d(B,E),a(x.speed,`${P}/speed`),x.dash!==void 0&&(!Array.isArray(x.dash)||x.dash.length!==2||x.dash.some(D=>typeof D!="number"||D<=0))&&r(`${P}/dash`,"two numbers over 0: on, off");else if(M==="move"){typeof B!="string"&&r(E,"an id");for(let D of["x","y","scale","opacity"])l(x[D],`${P}/${D}`)}else if(M==="focus")f(B,E);else if(M==="camera"){if(B!=="fit")if(!Te(B))r(E,'"fit", or { focus, zoom, margin }');else{n(B,["focus","zoom","margin"],E),a(B.zoom,`${E}/zoom`,{over:0}),a(B.margin,`${E}/margin`);let D=B.focus;typeof D=="string"||Array.isArray(D)&&(D.every(v=>typeof v=="string")||D.length===4&&D.every(v=>typeof v=="number"))||r(`${E}/focus`,"an id, some ids, or a box [x, y, w, h]")}}else d(B,E);M==="draw"&&t(x.by,["stroke","grow"],`${P}/by`),M==="lift"&&(x.by===void 0&&r(`${P}/by`,"how far apart"),a(x.by,`${P}/by`),t(x.to,["up","down"],`${P}/to`),l(x.opacity,`${P}/opacity`))})}if(s.series!==void 0&&g(s.series,"/series"),s.layers!==void 0&&k(s.layers,"/layers"),s.markers!==void 0)if(!Te(s.markers))r("/markers","markers is a map");else for(let[u,b]of Object.entries(s.markers))if(typeof b=="string"&&/^[A-Za-z][\w-]*([+-].+)?$/.test(b)){let x=/^([A-Za-z][\w-]*?)(?:([+-])(\d.*))?$/.exec(b);if(x&&(h.has(x[1])?x[1]:void 0))x[3]!==void 0&&o(x[3],`/markers/${u}`);else if(!h.has(b)){let T=Ye(x?.[1]??b,h.keys());r(`/markers/${u}`,`no sequence is named "${x?.[1]??b}"`,T?`did you mean "${T}"?`:void 0)}}else o(b,`/markers/${u}`);return e}var ft=s=>Math.round(s*100)/100||0,We=s=>Math.round(s*1e4)/1e4||0,gt=s=>Math.max(0,Math.min(1,s)),Cs=(s,e,r)=>s+(e-s)*r,sf=250,pa=class{items=new Map;labels=new Map;routes=new Map;tokens=[];pulses=[];outlines=[];variants={};marks=1;at(e,r){let n=e.get(r);return n||e.set(r,n={}),n}item(e,r){let n=this.at(this.items,e);r.opacity!==void 0&&(n.opacity=(n.opacity??1)*r.opacity),r.dx&&(n.dx=(n.dx??0)+r.dx),r.dy&&(n.dy=(n.dy??0)+r.dy),r.scale!==void 0&&(n.scale=(n.scale??1)*r.scale,n.about=r.about??n.about),r.clip&&(n.clip=r.clip)}label(e,r){let n=this.at(this.labels,e);r.opacity!==void 0&&(n.opacity=(n.opacity??1)*r.opacity),r.dx&&(n.dx=(n.dx??0)+r.dx),r.dy&&(n.dy=(n.dy??0)+r.dy),r.typed!==void 0&&(n.typed=Math.min(n.typed??1,r.typed))}route(e,r){let n=this.at(this.routes,e);r.opacity!==void 0&&(n.opacity=(n.opacity??1)*r.opacity),r.drawn!==void 0&&r.drawn<(n.drawn??1)&&(n.drawn=r.drawn,n.by=r.by),r.ants&&(n.ants=r.ants)}add(e){for(let[r,n]of Object.entries(e.items??{}))this.item(r,n);for(let[r,n]of Object.entries(e.labels??{}))this.label(r,n);for(let[r,n]of Object.entries(e.routes??{}))this.route(r,n);e.marks&&(this.marks*=e.marks.opacity),this.tokens.push(...e.tokens??[]),this.pulses.push(...e.pulses??[])}state(e){let r={},n=(p,l)=>{let f={};for(let[m,h]of p){let y=l(h);Object.keys(y).length&&(f[m]=y)}return f},i=p=>Object.keys(p).length>0,o=p=>p===void 0||We(p)>=1?{}:{opacity:We(Math.max(0,p))},t=p=>({...ft(p.dx??0)?{dx:ft(p.dx)}:{},...ft(p.dy??0)?{dy:ft(p.dy)}:{}}),a=n(this.items,p=>({...o(p.opacity),...t(p),...p.scale!==void 0&&We(p.scale)!==1?{scale:We(p.scale),...p.about?{about:p.about}:{}}:{},...p.clip?{clip:p.clip}:{}})),d=n(this.labels,p=>({...o(p.opacity),...p.typed!==void 0&&p.typed<1?{typed:We(p.typed)}:{},...t(p)})),c=n(this.routes,p=>{let l=p.opacity!==void 0&&We(p.opacity)<=0,f=p.drawn!==void 0&&p.drawn<1;return{...o(p.opacity),...f?{drawn:We(p.drawn),...p.by?{by:p.by}:{}}:{},...p.ants&&!l&&!f?{ants:p.ants}:{}}});return i(a)&&(r.items=a),i(d)&&(r.labels=d),i(c)&&(r.routes=c),We(this.marks)<1&&(r.marks={opacity:We(this.marks)}),this.tokens.length&&(r.tokens=this.tokens),this.pulses.length&&(r.pulses=this.pulses),this.outlines.length&&(r.outlines=this.outlines),i(this.variants)&&(r.variants=this.variants),e&&(r.camera=e),r}};function rf(s){let e=In(s.raw),r=s.rendered.looks,n=na(s),i=Object.keys(n.notes).filter(o=>n.notes[o]===void 0);return{model:n,kinds:Object.fromEntries(s.routes.map(o=>[o.id,o.kind])),outlines:Object.fromEntries(s.layout.items.map(o=>[o.id,Xe(o.box).map(t=>[ft(t[0]),ft(t[1])])])),...r&&Object.keys(r).length?{looks:r}:{},...e?{ants:e}:{},...i.length?{free:i}:{}}}function _n(s,e,r={}){let n="model"in s?s:rf(s),i=n.free?{...n.model,notes:{...n.model.notes,...Object.fromEntries(n.free.map(w=>[w,void 0]))}}:n.model,o=zl(e),t=e.fps,a=n.ants,d=()=>({ok:!1,diags:o,duration:0,beats:[],markers:{},ambient:"on",loops:!1,at:()=>({}),cues:()=>{},beatAt:()=>{},startOf:()=>{}});if(o.length)return d();let c=(w,z,_)=>{o.push({severity:"error",path:w,message:z,..._?{hint:_}:{}})},p=(w,z)=>w===void 0?z:ct(w,t),l=new Map(i.pieces.map(w=>[w.id,w])),f=new Set(i.routes.map(w=>w.id)),m=new Set(Object.keys(i.notes)),h=new Map(Object.entries(n.kinds)),y=[...l.keys(),...f,...m],g=new Set(y),k=new Map;for(let[w,z]of Object.entries(i.notes))z!==void 0&&k.set(z,[...k.get(z)??[],w]);let u={any:g,thing:new Set(l.keys()),route:f},b={any:"thing, connector or note",thing:"thing",route:"connector"},x=(w,z,_="any")=>{if(!u[_].has(w)){let U=Ye(w,u[_]);c(z,`no ${b[_]} "${w}" in this drawing`,U?`did you mean "${U}"?`:void 0)}},$=(w,z,_="any")=>w?.forEach((U,V)=>x(U,`${z}/${V}`,_)),P=new Map(Object.entries(n.outlines)),T=new Map;function M(w,z){let _="from"in w?p(w.from,0):0,U="duration"in w?p(w.duration,NaN):NaN,V=Number.isFinite(U);if("sequence"in w){let J=w.sequence;return p(J.from,0)+v(J,`${z}/sequence`)}if("series"in w)return O(w.series,`${z}/series`).end;if("layers"in w)return Math.max(0,...w.layers.map((J,F)=>M(J,`${z}/layers/${F}`)));if("assemble"in w||"disassemble"in w){let J="assemble"in w?"assemble":"disassemble",F="assemble"in w?w.assemble:w.disassemble,oe=T.get(w);return oe||T.set(w,oe=Sl(i,J,{seed:e.seed??1,...F,...V?{duration:U}:{}})),_+oe.duration}return"draw"in w?_+(V?U:400)+Math.max(0,w.draw.length-1)*p(w.stagger,0):"lift"in w?_+Math.max(V?U:750,...w.opacity?.times.map(J=>ct(J,t))??[])+Math.max(0,w.lift.length-1)*p(w.stagger,0):V?_+U:"travel"in w?w.loop?_:_+w.travel.length*p(w.each,1150):"pulse"in w?w.loop?_:_+1500:"type"in w?_+400:"camera"in w?_+900:"move"in w?_+Math.max(0,...[w.x,w.y,w.scale,w.opacity].flatMap(J=>J?.times.map(F=>ct(F,t))??[])):_}let B=(w,z)=>Math.max(0,...(w.children??[]).map((_,U)=>M(_,`${z}/children/${U}`)),...(w.layers??[]).map((_,U)=>M(_,`${z}/layers/${U}`)),w.series?O(w.series,`${z}/series`).end:0),E=new Map;function D(w,z){let _=E.get(w);if(_!==void 0)return _;let U;return w.duration!==void 0&&typeof w.duration=="object"?U=la(w.say,w.duration.read):U=w.duration!==void 0?p(w.duration,0):B(w,z),w.duration===void 0&&U<=0&&w.say&&(U=la(w.say,!0)),U<=0&&c(`${z}/duration`,"how long is it? (nothing in it says)"),E.set(w,U),U}let v=(w,z)=>{let _=D(w,z),U=w.playbackRate??1;return w.loop===!0?_/U:(typeof w.loop=="number"?_*w.loop:_)/U};function O(w,z){let _=[],U=0,V;return w.forEach((J,F)=>{if("transition"in J){let me=J.transition,Se=me.timing,Ie=me.presentation==="none"?0:ca(Se,t);V={t:me,length:Ie};return}let oe=J.sequence,pe=`${z}/${F}/sequence`,he=v(oe,pe),we=Math.max(0,U+p(oe.offset,0)-(V?.length??0));V&&_.length&&V.length>Math.min(_[_.length-1].end-_[_.length-1].start,he)&&c(`${z}/${F-1}/transition/timing`,"a transition is no longer than either side of it"),_.push({s:oe,path:pe,start:we,end:we+he,...V?{into:V}:{}}),U=we+he,V=void 0}),{list:_,end:Math.max(0,..._.map(J=>J.end))}}let S=O(e.series??[],"/series"),N=Math.max(0,...(e.layers??[]).map((w,z)=>M(w,`/layers/${z}`))),I=Math.max(S.end,N);I<=0&&!o.length&&c("","a motion document has a series, or layers, that last");let L=new Map,X=[],j=i.viewBox,A=(w,z,_)=>{let U=_!==void 0?1/_:Math.max((w.w+z*2)/j[2],(w.h+z*2)/j[3]);return[w.x+w.w/2-j[2]*U/2,w.y+w.h/2-j[3]*U/2,j[2]*U,j[3]*U]};function R(w,z,_){let U=V=>_?{at:_.at+V/_.rate,rate:_.rate}:void 0;if("sequence"in w){K(w.sequence,`${z}/sequence`,U(p(w.sequence.from,0)),!1);return}if("series"in w){for(let V of O(w.series,`${z}/series`).list)K(V.s,V.path,U(V.start),!1);return}if("layers"in w){w.layers.forEach((V,J)=>R(V,`${z}/layers/${J}`,_));return}if("travel"in w)w.travel.forEach((V,J)=>(Array.isArray(V)?V:[V]).forEach((F,oe)=>x(F.split(":")[0],`${z}/travel/${J}${Array.isArray(V)?`/${oe}`:""}`,"route")));else if("pulse"in w)$(w.pulse,`${z}/pulse`,"thing");else if("ants"in w)w.ants!==!0&&$(w.ants,`${z}/ants`,"route");else if("draw"in w)$(w.draw,`${z}/draw`,"route");else if("type"in w)$(w.type,`${z}/type`);else if("move"in w)x(w.move,`${z}/move`,"thing");else if("lift"in w)$(w.lift,`${z}/lift`,"thing");else if("focus"in w)C(w.focus,`${z}/focus`);else if("highlight"in w)$(w.highlight,`${z}/highlight`,"thing");else if("camera"in w){let V=w.camera,J=p(w.duration,900);if(!_){c(`${z}/camera`,"a camera can't be in a loop");return}let F=j;if(V!=="fit"){let oe=V.focus;if(Array.isArray(oe)&&typeof oe[0]=="number")F=A({x:oe[0],y:oe[1],w:oe[2],h:oe[3]},V.margin??0,V.zoom);else{let pe=typeof oe=="string"?[oe]:oe;pe.forEach((we,me)=>x(we,`${z}/camera/focus${typeof oe=="string"?"":`/${me}`}`,"thing"));let he=pe.map(we=>l.get(we)?.bbox).filter(we=>!!we);if(he.length){let we=Math.min(...he.map(Se=>Se.x)),me=Math.min(...he.map(Se=>Se.y));F=A({x:we,y:me,w:Math.max(...he.map(Se=>Se.x+Se.w))-we,h:Math.max(...he.map(Se=>Se.y+Se.h))-me},V.margin??40,V.zoom)}}}X.push({at:_.at+p(w.from,0)/_.rate,over:J/_.rate,ease:Yt(w.easing,J,"settle"),to:F})}}let C=(w,z)=>{w&&($(w.lit,`${z}/lit`),$(w.always,`${z}/always`))};function K(w,z,_,U){if(w.name!==void 0&&_&&L.set(w.name,_.at),!U)for(let F of["show","hide","say","enter","focus","highlight","levels","variants","ants"])w[F]!==void 0&&c(`${z}/${F}`,`${F} is for a sequence of the document's own series`,F==="focus"||F==="highlight"||F==="ants"?`here, a child: { ${F}: \u2026 }`:void 0);$(w.show,`${z}/show`),$(w.hide,`${z}/hide`),$(w.highlight,`${z}/highlight`,"thing"),C(w.focus,`${z}/focus`);for(let F of Object.keys(w.levels??{}))F!=="*"&&x(F,`${z}/levels/${F}`);for(let[F,oe]of Object.entries(w.variants??{})){x(F,`${z}/variants/${F}`,"thing");let pe=n.looks?.[F]??[];if(l.has(F)&&oe!==""&&!pe.includes(oe)){let he=Ye(oe,pe);c(`${z}/variants/${F}`,pe.length?`${F} has no look "${oe}" (it has ${pe.join(", ")})`:`${F} declares no looks (variants: in the diagram)`,he?`did you mean "${he}"?`:void 0)}}Array.isArray(w.ants)&&$(w.ants,`${z}/ants`,"route");let V=w.playbackRate??1,J=_&&!w.loop?{at:_.at-p(w.trimBefore,0)/(_.rate*V),rate:_.rate*V}:void 0;if((w.children??[]).forEach((F,oe)=>R(F,`${z}/children/${oe}`,J)),(w.layers??[]).forEach((F,oe)=>R(F,`${z}/layers/${oe}`,J)),w.series)for(let F of O(w.series,`${z}/series`).list)K(F.s,F.path,J&&{at:J.at+F.start/J.rate,rate:J.rate},!1)}for(let w of S.list)K(w.s,w.path,{at:w.start,rate:1},!0);(e.layers??[]).forEach((w,z)=>R(w,`/layers/${z}`,{at:0,rate:1})),X.sort((w,z)=>w.at-z.at);let W={};for(let[w,z]of Object.entries(e.markers??{})){let _=ct(z,t);if(_!==void 0){W[w]=_;continue}let U=String(z),V=[...L.keys()].filter(oe=>U===oe||U.startsWith(oe+"+")||U.startsWith(oe+"-")).sort((oe,pe)=>pe.length-oe.length)[0];if(V===void 0){c(`/markers/${w}`,`"${U}" isn't a moment of this document`);continue}let J=U.slice(V.length),F=J?ct(J.slice(1),t):0;if(F===void 0){c(`/markers/${w}`,`"${J}" isn't a time`);continue}W[w]=L.get(V)+(J[0]==="-"?-F:F)}if(o.length)return d();let ae=S.list.map((w,z)=>({name:w.s.name??`beat-${z+1}`,index:z,start:w.start,end:w.end,...w.s.say?{say:w.s.say}:{}})),ee=new Map;for(let w of S.list){for(let z of w.s.show??[])ee.has(z)||ee.set(z,!1);for(let z of w.s.hide??[])ee.has(z)||ee.set(z,!0)}let G=[new Map(ee)];for(let w of S.list){let z=new Map(G[G.length-1]);for(let _ of w.s.show??[])z.set(_,!0);for(let _ of w.s.hide??[])z.set(_,!1);G.push(z)}let fe=[new Map];for(let w of S.list){let z=new Map(fe[fe.length-1]);for(let[_,U]of Object.entries(w.s.variants??{}))z.set(_,U);fe.push(z)}let le=(w,z)=>!w||w.lit.includes(z)||w.always?.includes(z)||w.scope==="links"&&l.has(z)?1:w.level??.12,q=(w,z)=>{let _=w<0?void 0:S.list[w].s.levels;return _?_[z]??_["*"]??1:1},Q=(w,z)=>(G[w+1].get(z)===!1?0:1)*(w<0?1:le(S.list[w].s.focus,z))*q(w,z),Ae=(w,z)=>{let _=i.notes[z];if(_===void 0)return Q(w,z);let U=w<0?void 0:S.list[w].s.levels?.[z];return Q(w,_)*(G[w+1].get(z)===!1?0:1)*(U??1)},Me=w=>{let z=-1;for(let _=0;_<S.list.length;_++)S.list[_].start<=w&&(z=_);return z},Ue=(w,z)=>{let _=S.list[w],U=z-_.start;if(_.into&&_.into.length>0)return fa(_.into.t.timing,U,_.into.length);let V=_.s.enter;if(!V)return 1;let J=p(V.fade,0);return J<=0?1:Yt(V.easing,J,"ease")(gt(U/J))};function mt(w,z,_,U,V){if("sequence"in w){let pe=w.sequence,he=p(pe.from,0);gr(pe,z-he,_-he,ql(pe,U-he),V);return}if("series"in w){for(let pe of O(w.series,"").list)gr(pe.s,z-pe.start,_-pe.start,pe.end-pe.start,V);return}if("layers"in w){for(let pe of w.layers)mt(pe,z,_,U,V);return}let J=p("from"in w?w.from:void 0,0),F=z-J;if("assemble"in w||"disassemble"in w){V.sum.add(T.get(w).at(F));return}if("draw"in w){let pe=Math.max(1,p(w.duration,400)),he=p(w.stagger,0),we=Yt(w.easing,pe,"ease-out");w.draw.forEach((me,Se)=>{let Ie=we(gt((F-Se*he)/pe));Ie<=0?(V.sum.route(me,{opacity:0,drawn:0}),V.sum.label(me,{opacity:0})):Ie<1&&(V.sum.route(me,{drawn:Ie,...w.by?{by:w.by}:{}}),V.sum.label(me,{opacity:Ie}))});return}if("type"in w){let pe=p(w.duration,400),he=Yt(w.easing,pe,"linear")(gt(F/Math.max(1,pe)));if(he<1)for(let we of w.type)V.sum.label(we,he<=0?{opacity:0}:{typed:he});return}if("move"in w){let pe=Ie=>Ie?Rn(Ie,F,t):void 0,he=pe(w.x)??0,we=pe(w.y)??0,me=pe(w.scale),Se=pe(w.opacity);V.sum.item(w.move,{dx:he,dy:we,...me===void 0?{}:{scale:me,about:l.get(w.move).foot},...Se===void 0?{}:{opacity:gt(Se)}});for(let Ie of[w.move,...k.get(w.move)??[]])V.sum.label(Ie,{dx:he,dy:we,...Se===void 0?{}:{opacity:gt(Se)}});return}if("lift"in w){let pe=p(w.stagger,0),he=Math.max(1,p(w.duration,750)),we=Yt(w.easing,he,"ease-out"),me=w.to==="down",Se=w.lift.length;w.lift.forEach((Ie,_t)=>{let ne=F-(me?Se-1-_t:_t)*pe,Oe=we(gt(ne/he)),Le=(_t+1)*w.by*(me?Oe:-Oe),De=w.opacity?gt(Rn(w.opacity,ne,t)):1;if(!(!Le&&De>=1)){V.sum.item(Ie,{dy:Le,opacity:De});for(let Wt of[Ie,...k.get(Ie)??[]])V.sum.label(Wt,{dy:Le,opacity:De})}});return}if("camera"in w)return;let oe=w.duration===void 0?Math.max(0,U-J):p(w.duration,0);if(!(F<0||F>oe)){if("focus"in w||"highlight"in w){let pe=Math.max(1,p(w.fade,sf)),he=gt(Math.min(F/pe,w.duration===void 0?1:(oe-F)/pe)),we=Yt(w.easing,pe,"linear")(he);if("focus"in w)Dl(w.focus,we,V.sum);else for(let me of w.highlight)V.shown(me)&&ka(me,we,V.sum);return}if("ants"in w){qn(w.ants===!0?[...f]:w.ants,V,w.speed,w.dash);return}if("pulse"in w){let he=w.loop?us(_-J,1500,V)/1500:F/Math.max(1,w.duration===void 0?1500:oe);if(he<0||he>=1)return;for(let we of w.pulse)if(V.shown(we)){let me=l.get(we),Se=me.bbox.w*.5*(.7+he*.6);V.sum.pulses.push({x:ft(me.foot[0]),y:ft(me.foot[1]),rx:ft(Se),ry:ft(Se*.58),opacity:We(1-he)})}return}if("travel"in w){let pe=p(w.each,1150),he=p(w.hold,w.loop?700:0),we=w.travel.length*pe+he,me=w.loop?us(_-J,we,V):F,Se=Math.floor(me/pe);if(Se>=w.travel.length)return;let Ie=(me-Se*pe)/pe,_t=Yt(w.easing,pe,"ease-in-out")(Ie),ne=w.travel[Se];for(let Oe of Array.isArray(ne)?ne:[ne]){let[Le,De]=Oe.split(":");V.shown(Le)&&V.sum.tokens.push({route:Le,at:We((De??h.get(Le))==="blocked"?Ds(Ie):_t),...De?{kind:De}:{}})}}}}let Ds=w=>w<.7?w/.7:1-(w-.7)/.3*.25,us=(w,z,_)=>_.off?0:(w%z+z)%z,ka=(w,z,_)=>{We(z)>0&&P.has(w)&&_.outlines.push({id:w,points:P.get(w),...We(z)<1?{opacity:We(z)}:{}})},Dl=(w,z,_)=>{for(let U of y){let V=m.has(U)&&!w.lit.includes(U)&&!w.always?.includes(U)?i.notes[U]:void 0,J=Cs(1,le(w,V??U),z);J>=1||(l.has(U)?(_.item(U,{opacity:J}),_.label(U,{opacity:J})):f.has(U)?(_.route(U,{opacity:J}),_.label(U,{opacity:J})):_.label(U,{opacity:J}))}},qn=(w,z,_=ul,U)=>{for(let V of w){let J=hl(h.get(V)??"",{dash:U,kinds:r.kinds,still:r.still});if(!J)continue;let F=J[0]+J[1],oe=us(_*z.A/1e3,F,z);z.sum.route(V,{ants:{dash:J,offset:ft(oe)}})}},ql=(w,z)=>w.loop===!0?Math.max(0,z):v(w,"");function gr(w,z,_,U,V){if(z<0||z>U||z===U&&U<I&&U>0&&w.loop)return;let J=w.playbackRate??1,F=D(w,""),oe=p(w.trimBefore,0),pe=w.loop&&F>0?z*J%F:z*J,he=pe+oe,we=_*J+oe;for(let me of w.children??[])mt(me,he,we,F+oe,V);for(let me of w.layers??[])mt(me,he,we,F+oe,V);if(w.series)for(let me of O(w.series,"").list)gr(me.s,he-me.start,we-me.start,me.end-me.start,V)}function Bl(w,z={}){let _=Math.max(0,Math.min(I,Number.isFinite(w)?w:0)),U=z.ambient==="off"||e.ambient==="off"&&z.ambient===void 0,V=typeof z.ambient=="number"?z.ambient:_,J=new pa,F=Me(_),oe=F<0?1:Ue(F,_),pe=(ne,Oe)=>F<0?Oe(-1,ne):oe>=1?Oe(F,ne):Cs(Oe(F-1,ne),Oe(F,ne),oe),he=ne=>(F<0?G[0]:G[F+1]).get(ne)!==!1;if(ee.size||S.list.some(ne=>ne.s.focus||ne.s.levels))for(let ne of y){let Oe=pe(ne,m.has(ne)?Ae:Q);Oe>=1||(l.has(ne)&&J.item(ne,{opacity:Oe}),f.has(ne)&&J.route(ne,{opacity:Oe}),J.label(ne,{opacity:Oe}))}if(F>=0)for(let ne of fe[fe.length-1].keys()){let Oe=fe[F].get(ne)??"",Le=fe[F+1].get(ne)??"",De={};Oe&&oe<1&&(De[Oe]=We(1-oe)),Le&&(De[Le]=We((De[Le]??0)+oe));for(let Wt of Object.keys(De))De[Wt]<=0&&delete De[Wt];Object.keys(De).length&&(J.variants[ne]=De)}if(F>=0){let ne=new Set(S.list[F].s.highlight??[]),Oe=new Set(F>0&&oe<1?S.list[F-1].s.highlight??[]:[]);for(let Le of new Set([...Oe,...ne]))ka(Le,Cs(Oe.has(Le)?1:0,ne.has(Le)?1:0,oe),J)}let we={sum:J,shown:he,off:U,A:V},me=F>=0?S.list[F].s.ants:void 0,Se=me===void 0?a:void 0;me?qn(me===!0?[...f]:me,we):Se&&qn(Se.ids??[...f],we,Se.speed,Se.dash),S.list.forEach((ne,Oe)=>{_>=ne.start&&(_<ne.end||Oe===F&&_<=ne.end)&&gr(ne.s,_-ne.start,V-ne.start,ne.end-ne.start,we)});for(let ne of e.layers??[])mt(ne,_,V,I,we);let Ie;for(let ne of X){if(ne.at>_)break;let Oe=ne.over<=0?1:ne.ease(gt((_-ne.at)/ne.over)),Le=Ie??j;if(Oe>=1){Ie=ne.to;continue}let De=Le[2],Wt=ne.to[2],wr=Math.exp(Cs(Math.log(De),Math.log(Wt),Oe)),$a=Math.abs(Wt-De)<1e-6?Oe:(wr-De)/(Wt-De),Fl=Cs(Le[0]+Le[2]/2,ne.to[0]+ne.to[2]/2,$a),Zl=Cs(Le[1]+Le[3]/2,ne.to[1]+ne.to[3]/2,$a),Sa=wr*j[3]/j[2];Ie=[Fl-wr/2,Zl-Sa/2,wr,Sa]}let _t=Ie?.map(ft);return J.state(_t&&_t.some((ne,Oe)=>Math.abs(ne-j[Oe])>.005)?_t:void 0)}let br=w=>{if(!w||typeof w!="object")return!1;if(Array.isArray(w))return w.some(br);let z=w;return z.ants!==void 0&&z.ants!==!1||z.loop===!0&&("travel"in z||"pulse"in z)?!0:Object.values(z).some(br)},Kl=a!==void 0||br(e.series)||br(e.layers),xa=w=>{let z=Me(Math.max(0,Math.min(I,w)));return z<0?void 0:ae[z]};return{ok:!0,diags:o,duration:I,beats:ae,markers:W,ambient:e.ambient??"on",loops:Kl,at:Bl,beatAt:xa,startOf:w=>L.get(w)??ae.find(z=>z.name===w)?.start,cues(w){let z=xa(w);if(!z)return;let _=Math.max(0,Math.min(I,w));return{beat:z.name,index:z.index,of:ae.length,progress:We(gt((_-z.start)/Math.max(1,z.end-z.start))),...z.say?{say:z.say,...z.say.chapter!==void 0?{chapter:z.say.chapter}:{},...z.say.color!==void 0?{color:z.say.color}:{}}:{}}}}}var ca=(s,e)=>"linear"in s?ct(s.linear,e)??0:ct(s.spring.duration,e)??nf(s.spring);function fa(s,e,r){return r<=0||e>=r?1:"spring"in s?gt(jn(e,{...s.spring,overshootClamping:!0})/jn(r,{...s.spring,overshootClamping:!0})):gt(e/r)}function nf(s){let e=s.mass??1,r=s.stiffness??100,n=s.damping??10,i=Math.sqrt(r/e),o=Math.min(1,n/(2*Math.sqrt(r*e)));return Math.ceil(Math.log(200)/(o*i)*1e3*(o>=1?1.6:1))}function Il(s){let{steps:e,vis:r}=s.steps,n=s.rendered.viewBox,i=!1,o=na(s),t=new Set([...o.pieces.map(p=>p.id),...o.routes.map(p=>p.id),...Object.keys(o.notes)]),a=p=>t.has(p),d=Object.keys(o.notes).filter(p=>o.notes[p]===void 0),c=e.map((p,l)=>{let f=[],m=[];for(let[u,b]of Object.entries(r))(l===0?!b.includes(!0):b[l-1]&&!b[l])?m.push(u):l>0&&b[l]&&!b[l-1]&&f.push(u);let h=[],y=u=>`${u.route}:${u.kind}`;p.phases.length&&h.push({travel:p.phases.map(u=>u.length===1?y(u[0]):u.map(y)),each:1150,hold:700,loop:!0});let g=(s.raw.steps??[])[l]?.pulse?.filter(u=>s.layout.byId.has(u))??[];if(g.length&&h.push({pulse:g,loop:!0}),p.focus){let[u,b,x,$]=Al(n,p.focus).map(ft);h.push({camera:{focus:[u,b,x,$]},duration:900,easing:"ease-in-out"}),i=!0}else i&&(h.push({camera:"fit",duration:900,easing:"ease-in-out"}),i=!1);let k={name:`step-${p.n}`,duration:p.duration,say:{title:p.heading,...p.caption?{text:p.caption}:{},...p.command?{code:p.command}:{}}};return f.length&&(k.show=f),m.length&&(k.hide=m),k.focus=s.raw.dim==="all"?{lit:p.lit.filter(a),scope:"all",level:.14}:{lit:p.lit.filter(a),scope:"links",level:.12,...d.length?{always:d}:{}},h.length&&(k.children=h),{sequence:k}});return{isomotion:1,...c.length?{series:c}:{}}}function El(s,e){let r={};for(let n of s.layout.items){let i=(n.region??n.node)?.variants;i&&(r[n.id]=Object.keys(i))}Object.keys(r).length&&(s.rendered.looks=r,s.rendered.variants=Object.fromEntries([...new Set(Object.values(r).flat())].map(n=>[n,On({scene:s.raw,routes:s.routes,steps:s.steps,theme:e,id:s.raw.id,gridStep:s.grid.step??s.grid.snap??1,layout:{...s.layout,items:s.layout.items.map(i=>{let o=(i.region??i.node)?.variants?.[n];return o?i.region?{...i,region:{...i.region,...o,deco:void 0}}:{...i,node:{...i.node,...o}}:i})}}).svg])))}var Tl=s=>af+Mo(s)+of+Bo(),af=`
240
+ `),c=Object.hasOwn(e,a)?Gc(s,a,d,e[a]):void 0;c&&(r+=s.svg.slice(n,o)+Jc(s.svg.slice(o,t),c),n=t)}return r+s.svg.slice(n)}function vl(s,e){if(Uc(e))return s.rendered.svg;let r=e.variants?Hc(s.rendered,e.variants):s.rendered.svg,n=l=>Object.hasOwn(s.rendered.paths,l)?s.rendered.paths[l]:void 0,i=0,o="",t="",a=0,d,c=r.replace(/<(\/?)([a-zA-Z]+)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|([^<]+)/g,(l,f,m,h,y,g)=>{if(g!==void 0)return d?.w.typed===void 0?l:Bc(g,d.w.typed);if(f)return i--,d&&i===d.at&&(d=void 0),i===1&&(o=""),l;let k=i;y||i++;let u={};for(let[,b,x]of h.matchAll(/([\w:-]+)="([^"]*)"/g))u[b]=x;if(k===0){if(!e.camera)return l;u.viewBox=e.camera.map(ze).join(" ")}else if(k===1)if(o=m==="g"&&u.class?.startsWith("g-")?u.class.slice(2):"",Yc.has(o)&&e.marks&&e.marks.opacity!==1)u.opacity=as(e.marks.opacity);else return l;else if(k===2&&u["data-part"]!==void 0){let b=u["data-route"]===void 0?"item":"route",x=Ol(u["data-route"]??u["data-item"]??""),$=Zc(e,b,x,u["data-part"],n);if(!$)return l;for(let[P,T]of Object.entries($.attrs))u[P]=bl(T);if($.clip){let P=`${s.id}-mc${a++}`;t+=`<clipPath id="${P}"><polygon points="${$.clip.map(T=>T.join(",")).join(" ")}"/></clipPath>`,u["clip-path"]=`url(#${P})`}if(!y&&($.path||$.typed!==void 0)&&(d={at:k,w:$}),!Object.keys($.attrs).length&&!$.clip)return l}else if(d?.w.path&&m==="path"&&u.class?.split(" ")[0]==="flow"){let b=d.w.path;b.d!==void 0&&(u.d=b.d),b.style!==void 0&&(u.style=b.style),b.head||delete u["marker-end"]}else return l;return`<${m}${Object.entries(u).map(([b,x])=>` ${b}="${x}"`).join("")}${y?"/":""}>`});t&&(c=c.replace(/<defs>|<defs\/>/,l=>l==="<defs/>"?`<defs>${t}</defs>`:l+t));let p=Vc(e,n,s.rendered.inks);return p.length&&(c=c.replace('<g class="g-anim">',l=>l+p.map(([f,m])=>`<${f}${Object.entries(m).map(([h,y])=>` ${h}="${bl(y)}"`).join("")}/>`).join(""))),c}var Ol=s=>s.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&amp;/g,"&");function Al(s,e){if(!e)return s;let[r,n,i,o]=e,t=s[2]/s[3],a=i-r,d=o-n;a/d<t?a=d*t:d=a/t,a=Math.min(a,s[2]),d=Math.min(d,s[3]);let c=(r+i)/2,p=(n+o)/2,l=Math.max(s[0],Math.min(s[0]+s[2]-a,c-a/2)),f=Math.max(s[1],Math.min(s[1]+s[3]-d,p-d/2));return[l,f,a,d]}var Xc=["linear","ease","ease-in","ease-out","ease-in-out","settle","bounce"],Ml=["extend","clamp","wrap","identity"];function ct(s,e){if(typeof s=="number")return Number.isFinite(s)?s:void 0;if(typeof s!="string")return;let r=/^(-?\d+(?:\.\d+)?)(ms|s|f)?$/.exec(s.trim());if(!r)return;let n=Number(r[1]);return r[2]==="s"?n*1e3:r[2]==="f"?e?n/e*1e3:void 0:n}function la(s,e){let r=e===!0?{}:e,n=r.base??2600,i=r.perChar??40,o=r.min??5600,t=r.max??12500;return Math.max(o,Math.min(t,n+(s?.text??"").length*i))}var _s=(s,e,r,n)=>i=>{if(i<=0)return 0;if(i>=1)return 1;let o=(d,c,p)=>3*d*p*(1-p)**2+3*c*p*p*(1-p)+p**3,t=0,a=1;for(let d=0;d<50;d++){let c=(t+a)/2;o(s,r,c)<i?t=c:a=c}return o(e,n,(t+a)/2)},Qc=s=>{if(s<=0)return 0;if(s>=1)return 1;let e=7.5625,r=2.75;return s<1/r?e*s*s:s<2/r?e*(s-1.5/r)**2+.75:s<2.5/r?e*(s-2.25/r)**2+.9375:e*(s-2.625/r)**2+.984375},ef={linear:s=>s,ease:_s(.25,.1,.25,1),"ease-in":_s(.42,0,1,1),"ease-out":_s(0,0,.58,1),"ease-in-out":_s(.42,0,.58,1),settle:_s(.16,.84,.3,1),bounce:Qc};function jn(s,e={}){let r=e.mass??1,n=e.stiffness??100,i=e.damping??10,o=Math.max(0,s)/1e3,t=Math.sqrt(n/r),a=i/(2*Math.sqrt(n*r)),d;if(a<1){let c=t*Math.sqrt(1-a*a);d=1-Math.exp(-a*t*o)*(Math.cos(c*o)+a*t/c*Math.sin(c*o))}else d=1-Math.exp(-t*o)*(1+t*o);return e.overshootClamping?Math.min(1,d):d}function Yt(s,e,r="ease-in-out"){let n=s??r;return typeof n=="string"?ef[n]:"bezier"in n?_s(...n.bezier):i=>i<=0?0:i>=1?1:jn(i*e,n.spring)}function Rn(s,e,r){let n=s.times.map(l=>ct(l,r)),i=s.values,o=n.length;if(o===1)return i[0];let t=(l,f)=>{if(l==="clamp")return f?i[0]:i[o-1];if(l==="identity")return e;if(l==="wrap"){let m=n[o-1]-n[0];return Rn({...s,extrapolateLeft:"clamp",extrapolateRight:"clamp"},n[0]+((e-n[0])%m+m)%m,r)}};if(e<n[0]){let l=t(s.extrapolateLeft??"extend",!0);if(l!==void 0)return l}if(e>n[o-1]){let l=t(s.extrapolateRight??"extend",!1);if(l!==void 0)return l}let a=0;for(;a<o-2&&e>=n[a+1];)a++;let d=n[a+1]-n[a],c=(e-n[a])/d,p=c<0||c>1?c:Yt(s.easing,d,"linear")(c);return i[a]+(i[a+1]-i[a])*p}var oa=["sequence","series","layers","assemble","disassemble","travel","pulse","ants","draw","type","move","lift","focus","highlight","camera"],Nl={morph:"the 2D morph is a later version's",diff:"diffs are a later version's",switch:"a look is a beat's: its variants"},Ot=["from","duration","easing"],hr={sequence:[],series:[],layers:[],assemble:Ot,disassemble:Ot,travel:[...Ot,"each","hold","loop"],pulse:[...Ot,"loop"],ants:[...Ot,"speed","dash"],draw:[...Ot,"by","stagger"],type:Ot,move:["from","x","y","scale","opacity"],lift:[...Ot,"by","stagger","to","opacity"],focus:[...Ot,"fade"],highlight:[...Ot,"fade"],camera:Ot},tf=["name","from","offset","duration","loop","playbackRate","trimBefore","say","show","hide","focus","highlight","levels","variants","enter","ants","children","layers","series"],Te=s=>!!s&&typeof s=="object"&&!Array.isArray(s);function zl(s){let e=[],r=(u,b,x)=>{e.push({severity:"error",path:u,message:b,...x?{hint:x}:{}})},n=(u,b,x)=>{for(let $ of Object.keys(u))if(!b.includes($)){let P=Ye($,b);r(`${x}/${$}`,`unknown key "${$}"`,P?`did you mean "${P}"?`:void 0)}};if(!Te(s))return r("","a motion document is a map"),e;n(s,["isomotion","fps","seed","ambient","series","layers","markers"],""),s.isomotion!==1&&r("/isomotion","isomotion is 1");let i=typeof s.fps=="number"&&s.fps>0?s.fps:void 0;s.fps!==void 0&&i===void 0&&r("/fps","fps is a number over 0"),s.seed!==void 0&&!Number.isInteger(s.seed)&&r("/seed","seed is a whole number"),s.ambient!==void 0&&s.ambient!=="on"&&s.ambient!=="off"&&r("/ambient",'ambient is "on" or "off"');let o=(u,b,x={})=>{if(u===void 0)return;if(typeof u=="string"&&/f$/.test(u)&&i===void 0){r(b,`"${u}" is in frames: the document needs its fps`);return}let $=ct(u,i);$===void 0?r(b,`${JSON.stringify(u)} isn't a time (ms, "1.2s", "450ms", "30f")`):$<0&&!x.negative&&r(b,"a time can't be negative")},t=(u,b,x)=>{if(u!==void 0&&!b.includes(u)){let $=typeof u=="string"?Ye(u,b):void 0;r(x,`${JSON.stringify(u)} isn't one of ${b.join(", ")}`,$?`did you mean "${$}"?`:void 0)}},a=(u,b,x={})=>{u!==void 0&&(typeof u!="number"||!Number.isFinite(u)||x.min!==void 0&&u<x.min||x.max!==void 0&&u>x.max||x.over!==void 0&&u<=x.over)&&r(b,`${JSON.stringify(u)} isn't a number${x.over!==void 0?` over ${x.over}`:x.min!==void 0?` from ${x.min}${x.max!==void 0?` to ${x.max}`:""}`:""}`)},d=(u,b)=>{if(u!==void 0){if(!Array.isArray(u)){r(b,"a list of ids");return}u.forEach((x,$)=>{typeof x!="string"&&r(`${b}/${$}`,"an id")})}},c=(u,b,x=[])=>{if(!Te(u)){r(b,"a spring is a map");return}n(u,["mass","damping","stiffness","overshootClamping",...x],b);for(let $ of["mass","damping","stiffness"])a(u[$],`${b}/${$}`,{over:0});u.overshootClamping!==void 0&&typeof u.overshootClamping!="boolean"&&r(`${b}/overshootClamping`,"true or false")},p=(u,b)=>{if(u!==void 0){if(typeof u=="string"){t(u,Xc,b);return}if(Te(u)&&"bezier"in u){n(u,["bezier"],b),(!Array.isArray(u.bezier)||u.bezier.length!==4||u.bezier.some(x=>typeof x!="number"))&&r(`${b}/bezier`,"four numbers");return}if(Te(u)&&"spring"in u){n(u,["spring"],b),c(u.spring,`${b}/spring`);return}r(b,"an easing is a name, { bezier: [a, b, c, d] } or { spring: { \u2026 } }")}},l=(u,b)=>{if(u===void 0)return;if(!Te(u)){r(b,"a curve is { times, values }");return}n(u,["times","values","easing","extrapolateLeft","extrapolateRight"],b);let x=u.times,$=u.values;if(!Array.isArray(x)||!x.length)r(`${b}/times`,"a list of times");else{x.forEach((T,M)=>o(T,`${b}/times/${M}`,{negative:!0}));let P=x.map(T=>ct(T,i));for(let T=1;T<P.length;T++)P[T]!==void 0&&P[T-1]!==void 0&&P[T]<=P[T-1]&&r(`${b}/times/${T}`,"times go up")}!Array.isArray($)||$.some(P=>typeof P!="number")?r(`${b}/values`,"a list of numbers"):Array.isArray(x)&&$.length!==x.length&&r(`${b}/values`,`${$.length} values for ${x.length} times`),p(u.easing,`${b}/easing`),t(u.extrapolateLeft,Ml,`${b}/extrapolateLeft`),t(u.extrapolateRight,Ml,`${b}/extrapolateRight`)},f=(u,b)=>{if(u!==void 0){if(!Te(u)){r(b,"focus is { lit: [ids] }");return}n(u,["lit","scope","level","always"],b),u.lit===void 0&&r(`${b}/lit`,"what is lit"),d(u.lit,`${b}/lit`),d(u.always,`${b}/always`),t(u.scope,["all","links"],`${b}/scope`),a(u.level,`${b}/level`,{min:0,max:1})}},m=(u,b)=>{u!==void 0&&typeof u!="string"&&r(b,"text")},h=new Map;function y(u,b,x){if(!Te(u)){r(b,"a sequence is a map");return}if(n(u,tf,b),u.name!==void 0&&(typeof u.name!="string"||!/^[A-Za-z][\w-]*$/.test(u.name)?r(`${b}/name`,"a name is letters, digits, - and _, from a letter"):h.has(u.name)?r(`${b}/name`,`"${u.name}" is already a name (${h.get(u.name)})`):h.set(u.name,b)),x&&u.from!==void 0&&r(`${b}/from`,"in a series a sequence follows the one before","offset moves it"),!x&&u.offset!==void 0&&r(`${b}/offset`,"offset is for a series","use from"),o(u.from,`${b}/from`),o(u.offset,`${b}/offset`,{negative:!0}),o(u.trimBefore,`${b}/trimBefore`),Te(u.duration)){n(u.duration,["read"],`${b}/duration`);let $=u.duration.read;if($!==!0&&!Te($))r(`${b}/duration/read`,"true, or { base, perChar, min, max }");else if(Te($)){n($,["base","perChar","min","max"],`${b}/duration/read`);for(let P of["base","perChar","min","max"])a($[P],`${b}/duration/read/${P}`,{min:0})}}else o(u.duration,`${b}/duration`);if(u.loop!==void 0&&typeof u.loop!="boolean"&&!(Number.isInteger(u.loop)&&u.loop>=1)&&r(`${b}/loop`,"true, false, or how many times"),a(u.playbackRate,`${b}/playbackRate`,{over:0}),u.say!==void 0)if(!Te(u.say))r(`${b}/say`,"say is a map");else{let $=u.say;n($,["chapter","title","text","code","facts","color"],`${b}/say`);for(let P of["chapter","title","text","code","color"])m($[P],`${b}/say/${P}`);$.facts!==void 0&&(!Array.isArray($.facts)||$.facts.some(P=>!Array.isArray(P)||P.length!==2||P.some(T=>typeof T!="string")))&&r(`${b}/say/facts`,"a list of [name, value]")}for(let $ of["show","hide","highlight"])d(u[$],`${b}/${$}`);if(f(u.focus,`${b}/focus`),u.levels!==void 0)if(!Te(u.levels))r(`${b}/levels`,"levels is a map: an id, and how much of it");else for(let[$,P]of Object.entries(u.levels))a(P,`${b}/levels/${$}`,{min:0,max:1});if(u.variants!==void 0)if(!Te(u.variants))r(`${b}/variants`,"variants is a map: an id, and the name of its look");else for(let[$,P]of Object.entries(u.variants))typeof P!="string"&&r(`${b}/variants/${$}`,`a look's name, or "" for its own`);u.enter!==void 0&&(Te(u.enter)?(n(u.enter,["fade","easing"],`${b}/enter`),u.enter.fade===void 0&&r(`${b}/enter/fade`,"how long the fade is"),o(u.enter.fade,`${b}/enter/fade`),p(u.enter.easing,`${b}/enter/easing`)):r(`${b}/enter`,"enter is { fade }")),u.ants!==void 0&&typeof u.ants!="boolean"&&d(u.ants,`${b}/ants`);for(let $ of["children","layers"])u[$]!==void 0&&k(u[$],`${b}/${$}`);u.series!==void 0&&g(u.series,`${b}/series`)}function g(u,b){if(!Array.isArray(u)){r(b,"a series is a list");return}u.forEach((x,$)=>{let P=`${b}/${$}`;if(!Te(x)||Object.keys(x).length!==1||!("sequence"in x||"transition"in x)){r(P,"a series holds sequences and transitions");return}if("sequence"in x){y(x.sequence,`${P}/sequence`,!0);return}let T=x.transition,M=`${P}/transition`,B=E=>Te(u[E])&&"sequence"in u[E];if((!B($-1)||!B($+1))&&r(M,"a transition is between two sequences"),!Te(T)){r(M,"a transition is { presentation, timing }");return}n(T,["presentation","timing"],M),T.presentation===void 0?r(`${M}/presentation`,"a presentation"):t(T.presentation,["fade","none"],`${M}/presentation`),Te(T.timing)?"linear"in T.timing?(n(T.timing,["linear"],`${M}/timing`),o(T.timing.linear,`${M}/timing/linear`)):"spring"in T.timing?(n(T.timing,["spring"],`${M}/timing`),c(T.timing.spring,`${M}/timing/spring`,["duration"]),Te(T.timing.spring)&&o(T.timing.spring.duration,`${M}/timing/spring/duration`)):r(`${M}/timing`,"a timing is { linear } or { spring }"):r(`${M}/timing`,"a timing is { linear } or { spring }")})}function k(u,b){if(!Array.isArray(u)){r(b,"a list");return}u.forEach((x,$)=>{let P=`${b}/${$}`;if(!Te(x)){r(P,"a map");return}let T=oa.filter(D=>D in x);if(T.length!==1){let D=Object.keys(x).find(S=>S in Nl),v=Object.keys(x)[0],O=v?Ye(v,oa):void 0;r(P,D?`${D}: ${Nl[D]}`:T.length?`one of ${T.join(", ")}, not several`:`one of ${oa.join(", ")}`,!D&&!T.length&&O?`did you mean "${O}"?`:void 0);return}let M=T[0],B=x[M],E=`${P}/${M}`;n(x,[M,...hr[M]],P),hr[M].includes("from")&&o(x.from,`${P}/from`),hr[M].includes("duration")&&(o(x.duration,`${P}/duration`),p(x.easing,`${P}/easing`));for(let D of["each","hold","stagger","fade"])hr[M].includes(D)&&o(x[D],`${P}/${D}`);if(hr[M].includes("loop")&&x.loop!==void 0&&typeof x.loop!="boolean"&&r(`${P}/loop`,"true or false"),M==="sequence")y(B,E,!1);else if(M==="series")g(B,E);else if(M==="layers")k(B,E);else if(M==="assemble"||M==="disassemble")Te(B)?(t(B.style,M==="assemble"?kl:xl,`${E}/style`),t(B.order,$l,`${E}/order`),B.duration!==void 0&&r(`${E}/duration`,"its length is beside it","duration is the node's")):r(E,`${M} is a map (its options)`);else if(M==="travel")!Array.isArray(B)||!B.length?r(E,"a list of connectors"):B.forEach((D,v)=>{Array.isArray(D)?d(D,`${E}/${v}`):typeof D!="string"&&r(`${E}/${v}`,"a connector, or a list of them at once")});else if(M==="ants")B!==!0&&d(B,E),a(x.speed,`${P}/speed`),x.dash!==void 0&&(!Array.isArray(x.dash)||x.dash.length!==2||x.dash.some(D=>typeof D!="number"||D<=0))&&r(`${P}/dash`,"two numbers over 0: on, off");else if(M==="move"){typeof B!="string"&&r(E,"an id");for(let D of["x","y","scale","opacity"])l(x[D],`${P}/${D}`)}else if(M==="focus")f(B,E);else if(M==="camera"){if(B!=="fit")if(!Te(B))r(E,'"fit", or { focus, zoom, margin }');else{n(B,["focus","zoom","margin"],E),a(B.zoom,`${E}/zoom`,{over:0}),a(B.margin,`${E}/margin`);let D=B.focus;typeof D=="string"||Array.isArray(D)&&(D.every(v=>typeof v=="string")||D.length===4&&D.every(v=>typeof v=="number"))||r(`${E}/focus`,"an id, some ids, or a box [x, y, w, h]")}}else d(B,E);M==="draw"&&t(x.by,["stroke","grow"],`${P}/by`),M==="lift"&&(x.by===void 0&&r(`${P}/by`,"how far apart"),a(x.by,`${P}/by`),t(x.to,["up","down"],`${P}/to`),l(x.opacity,`${P}/opacity`))})}if(s.series!==void 0&&g(s.series,"/series"),s.layers!==void 0&&k(s.layers,"/layers"),s.markers!==void 0)if(!Te(s.markers))r("/markers","markers is a map");else for(let[u,b]of Object.entries(s.markers))if(typeof b=="string"&&/^[A-Za-z][\w-]*([+-].+)?$/.test(b)){let x=/^([A-Za-z][\w-]*?)(?:([+-])(\d.*))?$/.exec(b);if(x&&(h.has(x[1])?x[1]:void 0))x[3]!==void 0&&o(x[3],`/markers/${u}`);else if(!h.has(b)){let T=Ye(x?.[1]??b,h.keys());r(`/markers/${u}`,`no sequence is named "${x?.[1]??b}"`,T?`did you mean "${T}"?`:void 0)}}else o(b,`/markers/${u}`);return e}var ft=s=>Math.round(s*100)/100||0,We=s=>Math.round(s*1e4)/1e4||0,gt=s=>Math.max(0,Math.min(1,s)),Cs=(s,e,r)=>s+(e-s)*r,sf=250,pa=class{items=new Map;labels=new Map;routes=new Map;tokens=[];pulses=[];outlines=[];variants={};marks=1;at(e,r){let n=e.get(r);return n||e.set(r,n={}),n}item(e,r){let n=this.at(this.items,e);r.opacity!==void 0&&(n.opacity=(n.opacity??1)*r.opacity),r.dx&&(n.dx=(n.dx??0)+r.dx),r.dy&&(n.dy=(n.dy??0)+r.dy),r.scale!==void 0&&(n.scale=(n.scale??1)*r.scale,n.about=r.about??n.about),r.clip&&(n.clip=r.clip)}label(e,r){let n=this.at(this.labels,e);r.opacity!==void 0&&(n.opacity=(n.opacity??1)*r.opacity),r.dx&&(n.dx=(n.dx??0)+r.dx),r.dy&&(n.dy=(n.dy??0)+r.dy),r.typed!==void 0&&(n.typed=Math.min(n.typed??1,r.typed))}route(e,r){let n=this.at(this.routes,e);r.opacity!==void 0&&(n.opacity=(n.opacity??1)*r.opacity),r.drawn!==void 0&&r.drawn<(n.drawn??1)&&(n.drawn=r.drawn,n.by=r.by),r.ants&&(n.ants=r.ants)}add(e){for(let[r,n]of Object.entries(e.items??{}))this.item(r,n);for(let[r,n]of Object.entries(e.labels??{}))this.label(r,n);for(let[r,n]of Object.entries(e.routes??{}))this.route(r,n);e.marks&&(this.marks*=e.marks.opacity),this.tokens.push(...e.tokens??[]),this.pulses.push(...e.pulses??[])}state(e){let r={},n=(p,l)=>{let f={};for(let[m,h]of p){let y=l(h);Object.keys(y).length&&(f[m]=y)}return f},i=p=>Object.keys(p).length>0,o=p=>p===void 0||We(p)>=1?{}:{opacity:We(Math.max(0,p))},t=p=>({...ft(p.dx??0)?{dx:ft(p.dx)}:{},...ft(p.dy??0)?{dy:ft(p.dy)}:{}}),a=n(this.items,p=>({...o(p.opacity),...t(p),...p.scale!==void 0&&We(p.scale)!==1?{scale:We(p.scale),...p.about?{about:p.about}:{}}:{},...p.clip?{clip:p.clip}:{}})),d=n(this.labels,p=>({...o(p.opacity),...p.typed!==void 0&&p.typed<1?{typed:We(p.typed)}:{},...t(p)})),c=n(this.routes,p=>{let l=p.opacity!==void 0&&We(p.opacity)<=0,f=p.drawn!==void 0&&p.drawn<1;return{...o(p.opacity),...f?{drawn:We(p.drawn),...p.by?{by:p.by}:{}}:{},...p.ants&&!l&&!f?{ants:p.ants}:{}}});return i(a)&&(r.items=a),i(d)&&(r.labels=d),i(c)&&(r.routes=c),We(this.marks)<1&&(r.marks={opacity:We(this.marks)}),this.tokens.length&&(r.tokens=this.tokens),this.pulses.length&&(r.pulses=this.pulses),this.outlines.length&&(r.outlines=this.outlines),i(this.variants)&&(r.variants=this.variants),e&&(r.camera=e),r}};function rf(s){let e=In(s.raw),r=s.rendered.looks,n=na(s),i=Object.keys(n.notes).filter(o=>n.notes[o]===void 0);return{model:n,kinds:Object.fromEntries(s.routes.map(o=>[o.id,o.kind])),outlines:Object.fromEntries(s.layout.items.map(o=>[o.id,Xe(o.box).map(t=>[ft(t[0]),ft(t[1])])])),...r&&Object.keys(r).length?{looks:r}:{},...e?{ants:e}:{},...i.length?{free:i}:{}}}function _n(s,e,r={}){let n="model"in s?s:rf(s),i=n.free?{...n.model,notes:{...n.model.notes,...Object.fromEntries(n.free.map(w=>[w,void 0]))}}:n.model,o=zl(e),t=e.fps,a=n.ants,d=()=>({ok:!1,diags:o,duration:0,beats:[],markers:{},ambient:"on",loops:!1,at:()=>({}),cues:()=>{},beatAt:()=>{},startOf:()=>{}});if(o.length)return d();let c=(w,z,_)=>{o.push({severity:"error",path:w,message:z,..._?{hint:_}:{}})},p=(w,z)=>w===void 0?z:ct(w,t),l=new Map(i.pieces.map(w=>[w.id,w])),f=new Set(i.routes.map(w=>w.id)),m=new Set(Object.keys(i.notes)),h=new Map(Object.entries(n.kinds)),y=[...l.keys(),...f,...m],g=new Set(y),k=new Map;for(let[w,z]of Object.entries(i.notes))z!==void 0&&k.set(z,[...k.get(z)??[],w]);let u={any:g,thing:new Set(l.keys()),route:f},b={any:"thing, connector or note",thing:"thing",route:"connector"},x=(w,z,_="any")=>{if(!u[_].has(w)){let U=Ye(w,u[_]);c(z,`no ${b[_]} "${w}" in this drawing`,U?`did you mean "${U}"?`:void 0)}},$=(w,z,_="any")=>w?.forEach((U,V)=>x(U,`${z}/${V}`,_)),P=new Map(Object.entries(n.outlines)),T=new Map;function M(w,z){let _="from"in w?p(w.from,0):0,U="duration"in w?p(w.duration,NaN):NaN,V=Number.isFinite(U);if("sequence"in w){let J=w.sequence;return p(J.from,0)+v(J,`${z}/sequence`)}if("series"in w)return O(w.series,`${z}/series`).end;if("layers"in w)return Math.max(0,...w.layers.map((J,F)=>M(J,`${z}/layers/${F}`)));if("assemble"in w||"disassemble"in w){let J="assemble"in w?"assemble":"disassemble",F="assemble"in w?w.assemble:w.disassemble,oe=T.get(w);return oe||T.set(w,oe=Sl(i,J,{seed:e.seed??1,...F,...V?{duration:U}:{}})),_+oe.duration}return"draw"in w?_+(V?U:400)+Math.max(0,w.draw.length-1)*p(w.stagger,0):"lift"in w?_+Math.max(V?U:750,...w.opacity?.times.map(J=>ct(J,t))??[])+Math.max(0,w.lift.length-1)*p(w.stagger,0):V?_+U:"travel"in w?w.loop?_:_+w.travel.length*p(w.each,1150):"pulse"in w?w.loop?_:_+1500:"type"in w?_+400:"camera"in w?_+900:"move"in w?_+Math.max(0,...[w.x,w.y,w.scale,w.opacity].flatMap(J=>J?.times.map(F=>ct(F,t))??[])):_}let B=(w,z)=>Math.max(0,...(w.children??[]).map((_,U)=>M(_,`${z}/children/${U}`)),...(w.layers??[]).map((_,U)=>M(_,`${z}/layers/${U}`)),w.series?O(w.series,`${z}/series`).end:0),E=new Map;function D(w,z){let _=E.get(w);if(_!==void 0)return _;let U;return w.duration!==void 0&&typeof w.duration=="object"?U=la(w.say,w.duration.read):U=w.duration!==void 0?p(w.duration,0):B(w,z),w.duration===void 0&&U<=0&&w.say&&(U=la(w.say,!0)),U<=0&&c(`${z}/duration`,"how long is it? (nothing in it says)"),E.set(w,U),U}let v=(w,z)=>{let _=D(w,z),U=w.playbackRate??1;return w.loop===!0?_/U:(typeof w.loop=="number"?_*w.loop:_)/U};function O(w,z){let _=[],U=0,V;return w.forEach((J,F)=>{if("transition"in J){let me=J.transition,Se=me.timing,Ie=me.presentation==="none"?0:ca(Se,t);V={t:me,length:Ie};return}let oe=J.sequence,pe=`${z}/${F}/sequence`,he=v(oe,pe),we=Math.max(0,U+p(oe.offset,0)-(V?.length??0));V&&_.length&&V.length>Math.min(_[_.length-1].end-_[_.length-1].start,he)&&c(`${z}/${F-1}/transition/timing`,"a transition is no longer than either side of it"),_.push({s:oe,path:pe,start:we,end:we+he,...V?{into:V}:{}}),U=we+he,V=void 0}),{list:_,end:Math.max(0,..._.map(J=>J.end))}}let S=O(e.series??[],"/series"),N=Math.max(0,...(e.layers??[]).map((w,z)=>M(w,`/layers/${z}`))),I=Math.max(S.end,N);I<=0&&!o.length&&c("","a motion document has a series, or layers, that last");let L=new Map,X=[],j=i.viewBox,A=(w,z,_)=>{let U=_!==void 0?1/_:Math.max((w.w+z*2)/j[2],(w.h+z*2)/j[3]);return[w.x+w.w/2-j[2]*U/2,w.y+w.h/2-j[3]*U/2,j[2]*U,j[3]*U]};function R(w,z,_){let U=V=>_?{at:_.at+V/_.rate,rate:_.rate}:void 0;if("sequence"in w){K(w.sequence,`${z}/sequence`,U(p(w.sequence.from,0)),!1);return}if("series"in w){for(let V of O(w.series,`${z}/series`).list)K(V.s,V.path,U(V.start),!1);return}if("layers"in w){w.layers.forEach((V,J)=>R(V,`${z}/layers/${J}`,_));return}if("assemble"in w||"disassemble"in w){M(w,z);return}if("travel"in w)w.travel.forEach((V,J)=>(Array.isArray(V)?V:[V]).forEach((F,oe)=>x(F.split(":")[0],`${z}/travel/${J}${Array.isArray(V)?`/${oe}`:""}`,"route")));else if("pulse"in w)$(w.pulse,`${z}/pulse`,"thing");else if("ants"in w)w.ants!==!0&&$(w.ants,`${z}/ants`,"route");else if("draw"in w)$(w.draw,`${z}/draw`,"route");else if("type"in w)$(w.type,`${z}/type`);else if("move"in w)x(w.move,`${z}/move`,"thing");else if("lift"in w)$(w.lift,`${z}/lift`,"thing");else if("focus"in w)C(w.focus,`${z}/focus`);else if("highlight"in w)$(w.highlight,`${z}/highlight`,"thing");else if("camera"in w){let V=w.camera,J=p(w.duration,900);if(!_){c(`${z}/camera`,"a camera can't be in a loop");return}let F=j;if(V!=="fit"){let oe=V.focus;if(Array.isArray(oe)&&typeof oe[0]=="number")F=A({x:oe[0],y:oe[1],w:oe[2],h:oe[3]},V.margin??0,V.zoom);else{let pe=typeof oe=="string"?[oe]:oe;pe.forEach((we,me)=>x(we,`${z}/camera/focus${typeof oe=="string"?"":`/${me}`}`,"thing"));let he=pe.map(we=>l.get(we)?.bbox).filter(we=>!!we);if(he.length){let we=Math.min(...he.map(Se=>Se.x)),me=Math.min(...he.map(Se=>Se.y));F=A({x:we,y:me,w:Math.max(...he.map(Se=>Se.x+Se.w))-we,h:Math.max(...he.map(Se=>Se.y+Se.h))-me},V.margin??40,V.zoom)}}}X.push({at:_.at+p(w.from,0)/_.rate,over:J/_.rate,ease:Yt(w.easing,J,"settle"),to:F})}}let C=(w,z)=>{w&&($(w.lit,`${z}/lit`),$(w.always,`${z}/always`))};function K(w,z,_,U){if(w.name!==void 0&&_&&L.set(w.name,_.at),!U)for(let F of["show","hide","say","enter","focus","highlight","levels","variants","ants"])w[F]!==void 0&&c(`${z}/${F}`,`${F} is for a sequence of the document's own series`,F==="focus"||F==="highlight"||F==="ants"?`here, a child: { ${F}: \u2026 }`:void 0);$(w.show,`${z}/show`),$(w.hide,`${z}/hide`),$(w.highlight,`${z}/highlight`,"thing"),C(w.focus,`${z}/focus`);for(let F of Object.keys(w.levels??{}))F!=="*"&&x(F,`${z}/levels/${F}`);for(let[F,oe]of Object.entries(w.variants??{})){x(F,`${z}/variants/${F}`,"thing");let pe=n.looks?.[F]??[];if(l.has(F)&&oe!==""&&!pe.includes(oe)){let he=Ye(oe,pe);c(`${z}/variants/${F}`,pe.length?`${F} has no look "${oe}" (it has ${pe.join(", ")})`:`${F} declares no looks (variants: in the diagram)`,he?`did you mean "${he}"?`:void 0)}}Array.isArray(w.ants)&&$(w.ants,`${z}/ants`,"route");let V=w.playbackRate??1,J=_&&!w.loop?{at:_.at-p(w.trimBefore,0)/(_.rate*V),rate:_.rate*V}:void 0;if((w.children??[]).forEach((F,oe)=>R(F,`${z}/children/${oe}`,J)),(w.layers??[]).forEach((F,oe)=>R(F,`${z}/layers/${oe}`,J)),w.series)for(let F of O(w.series,`${z}/series`).list)K(F.s,F.path,J&&{at:J.at+F.start/J.rate,rate:J.rate},!1)}for(let w of S.list)K(w.s,w.path,{at:w.start,rate:1},!0);(e.layers??[]).forEach((w,z)=>R(w,`/layers/${z}`,{at:0,rate:1})),X.sort((w,z)=>w.at-z.at);let W={};for(let[w,z]of Object.entries(e.markers??{})){let _=ct(z,t);if(_!==void 0){W[w]=_;continue}let U=String(z),V=[...L.keys()].filter(oe=>U===oe||U.startsWith(oe+"+")||U.startsWith(oe+"-")).sort((oe,pe)=>pe.length-oe.length)[0];if(V===void 0){c(`/markers/${w}`,`"${U}" isn't a moment of this document`);continue}let J=U.slice(V.length),F=J?ct(J.slice(1),t):0;if(F===void 0){c(`/markers/${w}`,`"${J}" isn't a time`);continue}W[w]=L.get(V)+(J[0]==="-"?-F:F)}if(o.length)return d();let ae=S.list.map((w,z)=>({name:w.s.name??`beat-${z+1}`,index:z,start:w.start,end:w.end,...w.s.say?{say:w.s.say}:{}})),ee=new Map;for(let w of S.list){for(let z of w.s.show??[])ee.has(z)||ee.set(z,!1);for(let z of w.s.hide??[])ee.has(z)||ee.set(z,!0)}let G=[new Map(ee)];for(let w of S.list){let z=new Map(G[G.length-1]);for(let _ of w.s.show??[])z.set(_,!0);for(let _ of w.s.hide??[])z.set(_,!1);G.push(z)}let fe=[new Map];for(let w of S.list){let z=new Map(fe[fe.length-1]);for(let[_,U]of Object.entries(w.s.variants??{}))z.set(_,U);fe.push(z)}let le=(w,z)=>!w||w.lit.includes(z)||w.always?.includes(z)||w.scope==="links"&&l.has(z)?1:w.level??.12,q=(w,z)=>{let _=w<0?void 0:S.list[w].s.levels;return _?_[z]??_["*"]??1:1},Q=(w,z)=>(G[w+1].get(z)===!1?0:1)*(w<0?1:le(S.list[w].s.focus,z))*q(w,z),Ae=(w,z)=>{let _=i.notes[z];if(_===void 0)return Q(w,z);let U=w<0?void 0:S.list[w].s.levels?.[z];return Q(w,_)*(G[w+1].get(z)===!1?0:1)*(U??1)},Me=w=>{let z=-1;for(let _=0;_<S.list.length;_++)S.list[_].start<=w&&(z=_);return z},Ue=(w,z)=>{let _=S.list[w],U=z-_.start;if(_.into&&_.into.length>0)return fa(_.into.t.timing,U,_.into.length);let V=_.s.enter;if(!V)return 1;let J=p(V.fade,0);return J<=0?1:Yt(V.easing,J,"ease")(gt(U/J))};function mt(w,z,_,U,V){if("sequence"in w){let pe=w.sequence,he=p(pe.from,0);gr(pe,z-he,_-he,ql(pe,U-he),V);return}if("series"in w){for(let pe of O(w.series,"").list)gr(pe.s,z-pe.start,_-pe.start,pe.end-pe.start,V);return}if("layers"in w){for(let pe of w.layers)mt(pe,z,_,U,V);return}let J=p("from"in w?w.from:void 0,0),F=z-J;if("assemble"in w||"disassemble"in w){V.sum.add(T.get(w).at(F));return}if("draw"in w){let pe=Math.max(1,p(w.duration,400)),he=p(w.stagger,0),we=Yt(w.easing,pe,"ease-out");w.draw.forEach((me,Se)=>{let Ie=we(gt((F-Se*he)/pe));Ie<=0?(V.sum.route(me,{opacity:0,drawn:0}),V.sum.label(me,{opacity:0})):Ie<1&&(V.sum.route(me,{drawn:Ie,...w.by?{by:w.by}:{}}),V.sum.label(me,{opacity:Ie}))});return}if("type"in w){let pe=p(w.duration,400),he=Yt(w.easing,pe,"linear")(gt(F/Math.max(1,pe)));if(he<1)for(let we of w.type)V.sum.label(we,he<=0?{opacity:0}:{typed:he});return}if("move"in w){let pe=Ie=>Ie?Rn(Ie,F,t):void 0,he=pe(w.x)??0,we=pe(w.y)??0,me=pe(w.scale),Se=pe(w.opacity);V.sum.item(w.move,{dx:he,dy:we,...me===void 0?{}:{scale:me,about:l.get(w.move).foot},...Se===void 0?{}:{opacity:gt(Se)}});for(let Ie of[w.move,...k.get(w.move)??[]])V.sum.label(Ie,{dx:he,dy:we,...Se===void 0?{}:{opacity:gt(Se)}});return}if("lift"in w){let pe=p(w.stagger,0),he=Math.max(1,p(w.duration,750)),we=Yt(w.easing,he,"ease-out"),me=w.to==="down",Se=w.lift.length;w.lift.forEach((Ie,_t)=>{let ne=F-(me?Se-1-_t:_t)*pe,Oe=we(gt(ne/he)),Le=(_t+1)*w.by*(me?Oe:-Oe),De=w.opacity?gt(Rn(w.opacity,ne,t)):1;if(!(!Le&&De>=1)){V.sum.item(Ie,{dy:Le,opacity:De});for(let Wt of[Ie,...k.get(Ie)??[]])V.sum.label(Wt,{dy:Le,opacity:De})}});return}if("camera"in w)return;let oe=w.duration===void 0?Math.max(0,U-J):p(w.duration,0);if(!(F<0||F>oe)){if("focus"in w||"highlight"in w){let pe=Math.max(1,p(w.fade,sf)),he=gt(Math.min(F/pe,w.duration===void 0?1:(oe-F)/pe)),we=Yt(w.easing,pe,"linear")(he);if("focus"in w)Dl(w.focus,we,V.sum);else for(let me of w.highlight)V.shown(me)&&ka(me,we,V.sum);return}if("ants"in w){qn(w.ants===!0?[...f]:w.ants,V,w.speed,w.dash);return}if("pulse"in w){let he=w.loop?us(_-J,1500,V)/1500:F/Math.max(1,w.duration===void 0?1500:oe);if(he<0||he>=1)return;for(let we of w.pulse)if(V.shown(we)){let me=l.get(we),Se=me.bbox.w*.5*(.7+he*.6);V.sum.pulses.push({x:ft(me.foot[0]),y:ft(me.foot[1]),rx:ft(Se),ry:ft(Se*.58),opacity:We(1-he)})}return}if("travel"in w){let pe=p(w.each,1150),he=p(w.hold,w.loop?700:0),we=w.travel.length*pe+he,me=w.loop?us(_-J,we,V):F,Se=Math.floor(me/pe);if(Se>=w.travel.length)return;let Ie=(me-Se*pe)/pe,_t=Yt(w.easing,pe,"ease-in-out")(Ie),ne=w.travel[Se];for(let Oe of Array.isArray(ne)?ne:[ne]){let[Le,De]=Oe.split(":");V.shown(Le)&&V.sum.tokens.push({route:Le,at:We((De??h.get(Le))==="blocked"?Ds(Ie):_t),...De?{kind:De}:{}})}}}}let Ds=w=>w<.7?w/.7:1-(w-.7)/.3*.25,us=(w,z,_)=>_.off?0:(w%z+z)%z,ka=(w,z,_)=>{We(z)>0&&P.has(w)&&_.outlines.push({id:w,points:P.get(w),...We(z)<1?{opacity:We(z)}:{}})},Dl=(w,z,_)=>{for(let U of y){let V=m.has(U)&&!w.lit.includes(U)&&!w.always?.includes(U)?i.notes[U]:void 0,J=Cs(1,le(w,V??U),z);J>=1||(l.has(U)?(_.item(U,{opacity:J}),_.label(U,{opacity:J})):f.has(U)?(_.route(U,{opacity:J}),_.label(U,{opacity:J})):_.label(U,{opacity:J}))}},qn=(w,z,_=ul,U)=>{for(let V of w){let J=hl(h.get(V)??"",{dash:U,kinds:r.kinds,still:r.still});if(!J)continue;let F=J[0]+J[1],oe=us(_*z.A/1e3,F,z);z.sum.route(V,{ants:{dash:J,offset:ft(oe)}})}},ql=(w,z)=>w.loop===!0?Math.max(0,z):v(w,"");function gr(w,z,_,U,V){if(z<0||z>U||z===U&&U<I&&U>0&&w.loop)return;let J=w.playbackRate??1,F=D(w,""),oe=p(w.trimBefore,0),pe=w.loop&&F>0?z*J%F:z*J,he=pe+oe,we=_*J+oe;for(let me of w.children??[])mt(me,he,we,F+oe,V);for(let me of w.layers??[])mt(me,he,we,F+oe,V);if(w.series)for(let me of O(w.series,"").list)gr(me.s,he-me.start,we-me.start,me.end-me.start,V)}function Bl(w,z={}){let _=Math.max(0,Math.min(I,Number.isFinite(w)?w:0)),U=z.ambient==="off"||e.ambient==="off"&&z.ambient===void 0,V=typeof z.ambient=="number"?z.ambient:_,J=new pa,F=Me(_),oe=F<0?1:Ue(F,_),pe=(ne,Oe)=>F<0?Oe(-1,ne):oe>=1?Oe(F,ne):Cs(Oe(F-1,ne),Oe(F,ne),oe),he=ne=>(F<0?G[0]:G[F+1]).get(ne)!==!1;if(ee.size||S.list.some(ne=>ne.s.focus||ne.s.levels))for(let ne of y){let Oe=pe(ne,m.has(ne)?Ae:Q);Oe>=1||(l.has(ne)&&J.item(ne,{opacity:Oe}),f.has(ne)&&J.route(ne,{opacity:Oe}),J.label(ne,{opacity:Oe}))}if(F>=0)for(let ne of fe[fe.length-1].keys()){let Oe=fe[F].get(ne)??"",Le=fe[F+1].get(ne)??"",De={};Oe&&oe<1&&(De[Oe]=We(1-oe)),Le&&(De[Le]=We((De[Le]??0)+oe));for(let Wt of Object.keys(De))De[Wt]<=0&&delete De[Wt];Object.keys(De).length&&(J.variants[ne]=De)}if(F>=0){let ne=new Set(S.list[F].s.highlight??[]),Oe=new Set(F>0&&oe<1?S.list[F-1].s.highlight??[]:[]);for(let Le of new Set([...Oe,...ne]))ka(Le,Cs(Oe.has(Le)?1:0,ne.has(Le)?1:0,oe),J)}let we={sum:J,shown:he,off:U,A:V},me=F>=0?S.list[F].s.ants:void 0,Se=me===void 0?a:void 0;me?qn(me===!0?[...f]:me,we):Se&&qn(Se.ids??[...f],we,Se.speed,Se.dash),S.list.forEach((ne,Oe)=>{_>=ne.start&&(_<ne.end||Oe===F&&_<=ne.end)&&gr(ne.s,_-ne.start,V-ne.start,ne.end-ne.start,we)});for(let ne of e.layers??[])mt(ne,_,V,I,we);let Ie;for(let ne of X){if(ne.at>_)break;let Oe=ne.over<=0?1:ne.ease(gt((_-ne.at)/ne.over)),Le=Ie??j;if(Oe>=1){Ie=ne.to;continue}let De=Le[2],Wt=ne.to[2],wr=Math.exp(Cs(Math.log(De),Math.log(Wt),Oe)),$a=Math.abs(Wt-De)<1e-6?Oe:(wr-De)/(Wt-De),Fl=Cs(Le[0]+Le[2]/2,ne.to[0]+ne.to[2]/2,$a),Zl=Cs(Le[1]+Le[3]/2,ne.to[1]+ne.to[3]/2,$a),Sa=wr*j[3]/j[2];Ie=[Fl-wr/2,Zl-Sa/2,wr,Sa]}let _t=Ie?.map(ft);return J.state(_t&&_t.some((ne,Oe)=>Math.abs(ne-j[Oe])>.005)?_t:void 0)}let br=w=>{if(!w||typeof w!="object")return!1;if(Array.isArray(w))return w.some(br);let z=w;return z.ants!==void 0&&z.ants!==!1||z.loop===!0&&("travel"in z||"pulse"in z)?!0:Object.values(z).some(br)},Kl=a!==void 0||br(e.series)||br(e.layers),xa=w=>{let z=Me(Math.max(0,Math.min(I,w)));return z<0?void 0:ae[z]};return{ok:!0,diags:o,duration:I,beats:ae,markers:W,ambient:e.ambient??"on",loops:Kl,at:Bl,beatAt:xa,startOf:w=>L.get(w)??ae.find(z=>z.name===w)?.start,cues(w){let z=xa(w);if(!z)return;let _=Math.max(0,Math.min(I,w));return{beat:z.name,index:z.index,of:ae.length,progress:We(gt((_-z.start)/Math.max(1,z.end-z.start))),...z.say?{say:z.say,...z.say.chapter!==void 0?{chapter:z.say.chapter}:{},...z.say.color!==void 0?{color:z.say.color}:{}}:{}}}}}var ca=(s,e)=>"linear"in s?ct(s.linear,e)??0:ct(s.spring.duration,e)??nf(s.spring);function fa(s,e,r){return r<=0||e>=r?1:"spring"in s?gt(jn(e,{...s.spring,overshootClamping:!0})/jn(r,{...s.spring,overshootClamping:!0})):gt(e/r)}function nf(s){let e=s.mass??1,r=s.stiffness??100,n=s.damping??10,i=Math.sqrt(r/e),o=Math.min(1,n/(2*Math.sqrt(r*e)));return Math.ceil(Math.log(200)/(o*i)*1e3*(o>=1?1.6:1))}function Il(s){let{steps:e,vis:r}=s.steps,n=s.rendered.viewBox,i=!1,o=na(s),t=new Set([...o.pieces.map(p=>p.id),...o.routes.map(p=>p.id),...Object.keys(o.notes)]),a=p=>t.has(p),d=Object.keys(o.notes).filter(p=>o.notes[p]===void 0),c=e.map((p,l)=>{let f=[],m=[];for(let[u,b]of Object.entries(r))(l===0?!b.includes(!0):b[l-1]&&!b[l])?m.push(u):l>0&&b[l]&&!b[l-1]&&f.push(u);let h=[],y=u=>`${u.route}:${u.kind}`;p.phases.length&&h.push({travel:p.phases.map(u=>u.length===1?y(u[0]):u.map(y)),each:1150,hold:700,loop:!0});let g=(s.raw.steps??[])[l]?.pulse?.filter(u=>s.layout.byId.has(u))??[];if(g.length&&h.push({pulse:g,loop:!0}),p.focus){let[u,b,x,$]=Al(n,p.focus).map(ft);h.push({camera:{focus:[u,b,x,$]},duration:900,easing:"ease-in-out"}),i=!0}else i&&(h.push({camera:"fit",duration:900,easing:"ease-in-out"}),i=!1);let k={name:`step-${p.n}`,duration:p.duration,say:{title:p.heading,...p.caption?{text:p.caption}:{},...p.command?{code:p.command}:{}}};return f.length&&(k.show=f),m.length&&(k.hide=m),k.focus=s.raw.dim==="all"?{lit:p.lit.filter(a),scope:"all",level:.14}:{lit:p.lit.filter(a),scope:"links",level:.12,...d.length?{always:d}:{}},h.length&&(k.children=h),{sequence:k}});return{isomotion:1,...c.length?{series:c}:{}}}function El(s,e){let r={};for(let n of s.layout.items){let i=(n.region??n.node)?.variants;i&&(r[n.id]=Object.keys(i))}Object.keys(r).length&&(s.rendered.looks=r,s.rendered.variants=Object.fromEntries([...new Set(Object.values(r).flat())].map(n=>[n,On({scene:s.raw,routes:s.routes,steps:s.steps,theme:e,id:s.raw.id,gridStep:s.grid.step??s.grid.snap??1,layout:{...s.layout,items:s.layout.items.map(i=>{let o=(i.region??i.node)?.variants?.[n];return o?i.region?{...i,region:{...i.region,...o,deco:void 0}}:{...i,node:{...i.node,...o}}:i})}}).svg])))}var Tl=s=>af+Mo(s)+of+Bo(),af=`
241
241
  /* blocks: hue per role, lightness per face and theme */
242
242
  .blk .top{fill:hsl(var(--h) var(--s) var(--l-top))}
243
243
  .blk .lft{fill:hsl(var(--h) var(--s) var(--l-left))}